Audacity  2.2.2
ScrubbingToolBar.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  ScrubbingToolBar.cpp
6 
7  Paul Licameli
8 
9  See ScrubbingToolBar.h for details
10 
11  *******************************************************************/
12 
13 // Much of this is imitative of EditToolBar. Should there be a common base
14 // class?
15 #include "../Audacity.h"
16 #include "ScrubbingToolBar.h"
17 
18 // For compilers that support precompilation, includes "wx/wx.h".
19 #include <wx/wxprec.h>
20 
21 #ifndef WX_PRECOMP
22 #include <wx/event.h>
23 #include <wx/image.h>
24 #include <wx/intl.h>
25 #include <wx/sizer.h>
26 #include <wx/tooltip.h>
27 #endif
28 
29 #include "../AllThemeResources.h"
30 #include "../AudioIO.h"
31 #include "../ImageManipulation.h"
32 #include "../Internat.h"
33 #include "../Prefs.h"
34 #include "../Project.h"
35 #include "../Theme.h"
36 #include "../Track.h"
37 #include "../UndoManager.h"
38 #include "../widgets/AButton.h"
39 #include "../widgets/Ruler.h"
40 #include "../tracks/ui/Scrubbing.h"
41 #include "../commands/CommandContext.h"
42 
43 #include "../Experimental.h"
44 
46 
47 //const int BUTTON_WIDTH = 27;
48 //const int SEPARATOR_WIDTH = 14;
49 
53 
54 BEGIN_EVENT_TABLE( ScrubbingToolBar, ToolBar )
56  STBFirstButton + STBNumButtons - 1,
57  wxEVT_COMMAND_BUTTON_CLICKED,
58  ScrubbingToolBar::OnButton )
60 
61 //Standard contructor
63 : ToolBar(ScrubbingBarID, _("Scrub"), wxT("Scrub"))
64 {
65 }
66 
68 {
69 }
70 
71 void ScrubbingToolBar::Create(wxWindow * parent)
72 {
73  ToolBar::Create(parent);
74 }
75 
81  teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled,
82  int id,
83  const wxChar *label,
84  bool toggle)
85 {
86  AButton *&r = pBar->mButtons[id];
87 
89  (pBar,
90  bmpRecoloredUpSmall, bmpRecoloredDownSmall, bmpRecoloredUpHiliteSmall, bmpRecoloredHiliteSmall,
91  eEnabledUp, eEnabledDown, eDisabled,
92  wxWindowID(id),
93  wxDefaultPosition,
94  toggle,
95  theTheme.ImageSize( bmpRecoloredUpSmall ));
96 
97  r->SetLabel(label);
98  // JKC: Unlike ControlToolBar, does not have a focus rect. Shouldn't it?
99  // r->SetFocusRect( r->GetRect().Deflate( 4, 4 ) );
100 
101  pBar->Add( r, 0, wxALIGN_CENTER );
102 
103  return r;
104 }
105 
107 {
108  SetBackgroundColour( theTheme.Colour( clrMedium ) );
110 
111  /* Buttons */
112  AddButton(this, bmpScrub, bmpScrub, bmpScrubDisabled, STBScrubID,
113  _("Scrub"), true);
114  AddButton(this, bmpSeek, bmpSeek, bmpSeekDisabled, STBSeekID,
115  _("Seek"), true);
116  AddButton(this, bmpToggleScrubRuler, bmpToggleScrubRuler, bmpToggleScrubRuler,
117  STBRulerID,
118  _("Scrub Ruler"), true);
119 
120 
122 }
123 
125 {
127 
128  // Set label to pull in language change
129  SetLabel(_("Scrubbing"));
130 
131  // Give base class a chance
133 }
134 
136 {
137 #if wxUSE_TOOLTIPS
138  auto fn = [&]
139  (AButton &button, const wxString &label, const wxString &cmd)
140  {
141  TranslatedInternalString command{ cmd, label };
142  ToolBar::SetButtonToolTip( button, &command, 1u );
143  };
144 
145  auto project = GetActiveProject();
146  if (project) {
147  auto &scrubber = project->GetScrubber();
148 
149  const auto scrubButton = mButtons[STBScrubID];
150  const auto seekButton = mButtons[STBSeekID];
151 
152  wxString label;
153  label = (
154  scrubber.Scrubs()
155  /* i18n-hint: These commands assist the user in finding a sound by ear. ...
156  "Scrubbing" is variable-speed playback, ...
157  "Seeking" is normal speed playback but with skips
158  */
159  ? _("Stop Scrubbing")
160  : _("Start Scrubbing")
161  );
162  fn(*scrubButton, label, wxT("Scrub"));
163 
164  label = (
165  scrubber.Seeks()
166  /* i18n-hint: These commands assist the user in finding a sound by ear. ...
167  "Scrubbing" is variable-speed playback, ...
168  "Seeking" is normal speed playback but with skips
169  */
170  ? _("Stop Seeking")
171  : _("Start Seeking")
172  );
173  fn(*seekButton, label, wxT("Seek"));
174 
175  label = (
176  project->GetRulerPanel()->ShowingScrubRuler()
177  ? _("Hide Scrub Ruler")
178  : _("Show Scrub Ruler")
179  );
180  fn(*mButtons[STBRulerID], label, wxT("ToggleScrubRuler"));
181  }
182 #endif
183 }
184 
185 void ScrubbingToolBar::OnButton(wxCommandEvent &event)
186 {
188  if (!p) return;
189  auto &scrubber = p->GetScrubber();
190 
191  int id = event.GetId();
192 
193  switch (id) {
194  case STBScrubID:
195  scrubber.OnScrub(*p);
196  break;
197  case STBSeekID:
198  scrubber.OnSeek(*p);
199  break;
200  case STBRulerID:
201  scrubber.OnToggleScrubRuler(*p);
202  break;
203  default:
204  wxASSERT(false);
205  }
206 
208 }
209 
211 {
212  const auto scrubButton = mButtons[STBScrubID];
213  scrubButton->SetEnabled(true);
214  const auto seekButton = mButtons[STBSeekID];
215  seekButton->SetEnabled(true);
216 
218  if (!p) return;
219 
220  auto &scrubber = p->GetScrubber();
221  const auto canScrub = scrubber.CanScrub();
222 
223  if (scrubber.Scrubs()) {
224  scrubButton->PushDown();
225  scrubButton->Enable();
226  }
227  else {
228  scrubButton->PopUp();
229  if (canScrub)
230  scrubButton->Enable();
231  else
232  scrubButton->Disable();
233  }
234 
235  if (scrubber.Seeks()) {
236  seekButton->PushDown();
237  seekButton->Enable();
238  }
239  else {
240  seekButton->PopUp();
241  if (canScrub)
242  seekButton->Enable();
243  else
244  seekButton->Disable();
245  }
246 
247  const auto barButton = mButtons[STBRulerID];
248  barButton->Enable();
249  if (p->GetRulerPanel()->ShowingScrubRuler())
250  barButton->PushDown();
251  else
252  barButton->PopUp();
254  scrubber.CheckMenuItems();
255 }
EVT_COMMAND_RANGE(STBFirstButton, STBFirstButton+STBNumButtons-1, wxEVT_COMMAND_BUTTON_CLICKED, ScrubbingToolBar::OnButton) ScrubbingToolBar
Methods for ScrubbingToolBar.
void MakeButtonBackgroundsSmall()
Definition: ToolBar.cpp:727
bool ShowingScrubRuler() const
Definition: Ruler.h:365
void Populate() override
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:209
virtual void UpdatePrefs()
Definition: ToolBar.cpp:535
void SetLabel(const wxString &label) override
Definition: ToolBar.cpp:374
Scrubber & GetScrubber()
Definition: Project.h:801
void OnButton(wxCommandEvent &event)
wxString label
Definition: Tags.cpp:727
virtual ~ScrubbingToolBar()
int teBmps
Definition: Theme.h:28
AButton * mButtons[STBNumButtons]
wxSize ImageSize(int iIndex)
Definition: Theme.cpp:1257
static AButton * MakeButton(wxWindow *parent, teBmps eUp, teBmps eDown, teBmps eHilite, teBmps eDownHi, teBmps eStandardUp, teBmps eStandardDown, teBmps eDisabled, wxWindowID id, wxPoint placement, bool processdownevents, wxSize size)
Definition: ToolBar.cpp:765
void UpdatePrefs() override
void Create(wxWindow *parent) override
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
AdornedRulerPanel * GetRulerPanel()
Definition: Project.cpp:1432
void SetEnabled(bool state)
Definition: AButton.h:98
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:611
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:438
void RegenerateTooltips() override
bool CanScrub() const
Definition: Scrubbing.cpp:986
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void Enable()
Definition: AButton.cpp:495
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
static AButton * AddButton(ScrubbingToolBar *pBar, teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled, int id, const wxChar *label, bool toggle=false)
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1225
void EnableDisableButtons() override
END_EVENT_TABLE()
static void SetButtonToolTip(AButton &button, const TranslatedInternalString commands[], size_t nCommands)
Definition: ToolBar.cpp:823
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed...
Definition: ToolBar.h:87
IMPLEMENT_CLASS(ScrubbingToolBar, ToolBar)
A wxButton with mouse-over behaviour.
Definition: AButton.h:28