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 
42 #include "../Experimental.h"
43 
45 
46 //const int BUTTON_WIDTH = 27;
47 //const int SEPARATOR_WIDTH = 14;
48 
52 
53 BEGIN_EVENT_TABLE( ScrubbingToolBar, ToolBar )
55  STBFirstButton + STBNumButtons - 1,
56  wxEVT_COMMAND_BUTTON_CLICKED,
57  ScrubbingToolBar::OnButton )
59 
60 //Standard contructor
62 : ToolBar(ScrubbingBarID, _("Scrub"), wxT("Scrub"))
63 {
64 }
65 
67 {
68 }
69 
70 void ScrubbingToolBar::Create(wxWindow * parent)
71 {
72  ToolBar::Create(parent);
73 }
74 
80  teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled,
81  int id,
82  const wxChar *label,
83  bool toggle)
84 {
85  AButton *&r = pBar->mButtons[id];
86 
88  (pBar,
89  bmpRecoloredUpSmall, bmpRecoloredDownSmall, bmpRecoloredUpHiliteSmall, bmpRecoloredHiliteSmall,
90  eEnabledUp, eEnabledDown, eDisabled,
91  wxWindowID(id),
92  wxDefaultPosition,
93  toggle,
94  theTheme.ImageSize( bmpRecoloredUpSmall ));
95 
96  r->SetLabel(label);
97  // JKC: Unlike ControlToolBar, does not have a focus rect. Shouldn't it?
98  // r->SetFocusRect( r->GetRect().Deflate( 4, 4 ) );
99 
100  pBar->Add( r, 0, wxALIGN_CENTER );
101 
102  return r;
103 }
104 
106 {
107  SetBackgroundColour( theTheme.Colour( clrMedium ) );
109 
110  /* Buttons */
111  AddButton(this, bmpScrub, bmpScrub, bmpScrubDisabled, STBScrubID,
112  _("Scrub"), true);
113  AddButton(this, bmpSeek, bmpSeek, bmpSeekDisabled, STBSeekID,
114  _("Seek"), true);
115  AddButton(this, bmpToggleScrubRuler, bmpToggleScrubRuler, bmpToggleScrubRuler,
116  STBRulerID,
117  _("Scrub Ruler"), true);
118 
119 
121 }
122 
124 {
126 
127  // Set label to pull in language change
128  SetLabel(_("Scrubbing"));
129 
130  // Give base class a chance
132 }
133 
135 {
136 #if wxUSE_TOOLTIPS
137  auto fn = [&]
138  (AButton &button, const wxString &label, const wxString &command)
139  {
140  LocalizedCommandNameVector commands( 1u, { label, command } );
141  ToolBar::SetButtonToolTip(button, commands);
142  };
143 
144  auto project = GetActiveProject();
145  if (project) {
146  auto &scrubber = project->GetScrubber();
147 
148  const auto scrubButton = mButtons[STBScrubID];
149  const auto seekButton = mButtons[STBSeekID];
150 
151  wxString label;
152  label = (
153  scrubber.Scrubs()
154  /* i18n-hint: These commands assist the user in finding a sound by ear. ...
155  "Scrubbing" is variable-speed playback, ...
156  "Seeking" is normal speed playback but with skips
157  */
158  ? _("Stop Scrubbing")
159  : _("Start Scrubbing")
160  );
161  fn(*scrubButton, label, wxT("Scrub"));
162 
163  label = (
164  scrubber.Seeks()
165  /* i18n-hint: These commands assist the user in finding a sound by ear. ...
166  "Scrubbing" is variable-speed playback, ...
167  "Seeking" is normal speed playback but with skips
168  */
169  ? _("Stop Seeking")
170  : _("Start Seeking")
171  );
172  fn(*seekButton, label, wxT("Seek"));
173 
174  label = (
175  project->GetRulerPanel()->ShowingScrubRuler()
176  ? _("Hide Scrub Ruler")
177  : _("Show Scrub Ruler")
178  );
179  fn(*mButtons[STBRulerID], label, wxT("ToggleScrubRuler"));
180  }
181 #endif
182 }
183 
184 void ScrubbingToolBar::OnButton(wxCommandEvent &event)
185 {
187  if (!p) return;
188  auto &scrubber = p->GetScrubber();
189 
190  int id = event.GetId();
191 
192  switch (id) {
193  case STBScrubID:
194  scrubber.OnScrub(*p);
195  break;
196  case STBSeekID:
197  scrubber.OnSeek(*p);
198  break;
199  case STBRulerID:
200  scrubber.OnToggleScrubRuler(*p);
201  break;
202  default:
203  wxASSERT(false);
204  }
205 
207 }
208 
210 {
211  const auto scrubButton = mButtons[STBScrubID];
212  scrubButton->SetEnabled(true);
213  const auto seekButton = mButtons[STBSeekID];
214  seekButton->SetEnabled(true);
215 
217  if (!p) return;
218 
219  auto &scrubber = p->GetScrubber();
220  const auto canScrub = scrubber.CanScrub();
221 
222  if (scrubber.Scrubs()) {
223  scrubButton->PushDown();
224  scrubButton->Enable();
225  }
226  else {
227  scrubButton->PopUp();
228  if (canScrub)
229  scrubButton->Enable();
230  else
231  scrubButton->Disable();
232  }
233 
234  if (scrubber.Seeks()) {
235  seekButton->PushDown();
236  seekButton->Enable();
237  }
238  else {
239  seekButton->PopUp();
240  if (canScrub)
241  seekButton->Enable();
242  else
243  seekButton->Disable();
244  }
245 
246  const auto barButton = mButtons[STBRulerID];
247  barButton->Enable();
248  if (p->GetRulerPanel()->ShowingScrubRuler())
249  barButton->PushDown();
250  else
251  barButton->PopUp();
253  scrubber.CheckMenuItems();
254 }
EVT_COMMAND_RANGE(STBFirstButton, STBFirstButton+STBNumButtons-1, wxEVT_COMMAND_BUTTON_CLICKED, ScrubbingToolBar::OnButton) ScrubbingToolBar
Methods for ScrubbingToolBar.
void MakeButtonBackgroundsSmall()
Definition: ToolBar.cpp:732
bool ShowingScrubRuler() const
Definition: Ruler.h:363
void Populate() override
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:209
virtual void UpdatePrefs()
Definition: ToolBar.cpp:540
Scrubber & GetScrubber()
Definition: Project.h:785
void OnButton(wxCommandEvent &event)
static void SetButtonToolTip(AButton &button, const LocalizedCommandNameVector &commands)
Definition: ToolBar.cpp:828
wxString label
Definition: Tags.cpp:727
virtual ~ScrubbingToolBar()
int teBmps
Definition: Theme.h:28
AButton * mButtons[STBNumButtons]
wxSize ImageSize(int iIndex)
Definition: Theme.cpp:1240
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:770
void UpdatePrefs() override
void Create(wxWindow *parent) override
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:158
AdornedRulerPanel * GetRulerPanel()
Definition: Project.cpp:1408
void SetEnabled(bool state)
Definition: AButton.h:97
std::vector< LocalizedCommandName > LocalizedCommandNameVector
Definition: ToolBar.h:160
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:616
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:443
void RegenerateTooltips() override
bool CanScrub() const
Definition: Scrubbing.cpp:985
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
void SetLabel(const wxString &label)
Definition: ToolBar.cpp:379
void Enable()
Definition: AButton.cpp:495
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:300
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:1208
void EnableDisableButtons() override
END_EVENT_TABLE()
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:27