Audacity  3.0.3
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 
16 
17 #include "ScrubbingToolBar.h"
18 #include "ToolManager.h"
19 
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include <wx/wxprec.h>
22 
23 #include <wx/setup.h> // for wxUSE_* macros
24 
25 #ifndef WX_PRECOMP
26 #include <wx/event.h>
27 #include <wx/image.h>
28 #include <wx/intl.h>
29 #include <wx/sizer.h>
30 #include <wx/tooltip.h>
31 #endif
32 
33 #include "../AdornedRulerPanel.h"
34 #include "AllThemeResources.h"
35 #include "ImageManipulation.h"
36 #include "Prefs.h"
37 #include "../UndoManager.h"
38 #include "../widgets/AButton.h"
39 #include "../tracks/ui/Scrubbing.h"
40 
42 
43 //const int BUTTON_WIDTH = 27;
44 //const int SEPARATOR_WIDTH = 14;
45 
49 
50 BEGIN_EVENT_TABLE( ScrubbingToolBar, ToolBar )
54  ScrubbingToolBar::OnButton )
55 EVT_IDLE( ScrubbingToolBar::OnIdle )
57 
58 //Standard constructor
60 : ToolBar(project, ScrubbingBarID, XO("Scrub"), wxT("Scrub"))
61 {
62 }
63 
65 {
66 }
67 
69 {
70  auto &toolManager = ToolManager::Get( project );
71  return *static_cast<ScrubbingToolBar*>( toolManager.GetToolBar(ScrubbingBarID) );
72 }
73 
75 {
76  return Get( const_cast<AudacityProject&>( project )) ;
77 }
78 
79 void ScrubbingToolBar::Create(wxWindow * parent)
80 {
81  ToolBar::Create(parent);
82  UpdatePrefs();
83 }
84 
89 (ScrubbingToolBar *pBar,
90  teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled,
91  int id,
93  bool toggle)
94 {
95  AButton *&r = pBar->mButtons[id];
96 
98  (pBar,
99  bmpRecoloredUpSmall, bmpRecoloredDownSmall, bmpRecoloredUpHiliteSmall, bmpRecoloredHiliteSmall,
100  eEnabledUp, eEnabledDown, eDisabled,
101  wxWindowID(id),
102  wxDefaultPosition,
103  toggle,
104  theTheme.ImageSize( bmpRecoloredUpSmall ));
105 
106  r->SetLabel(label);
107  // JKC: Unlike ControlToolBar, does not have a focus rect. Shouldn't it?
108  // r->SetFocusRect( r->GetRect().Deflate( 4, 4 ) );
109 
110  pBar->Add( r, 0, wxALIGN_CENTER );
111 
112  return r;
113 }
114 
116 {
117  SetBackgroundColour( theTheme.Colour( clrMedium ) );
119 
120  /* Buttons */
121  AddButton(this, bmpScrub, bmpScrub, bmpScrubDisabled, STBScrubID,
122  XO("Scrub"), true);
123  AddButton(this, bmpSeek, bmpSeek, bmpSeekDisabled, STBSeekID,
124  XO("Seek"), true);
125  AddButton(this, bmpToggleScrubRuler, bmpToggleScrubRuler, bmpToggleScrubRuler,
126  STBRulerID,
127  XO("Scrub Ruler"), true);
128 
129 
131 }
132 
134 {
136 
137  // Set label to pull in language change
138  SetLabel(XO("Scrubbing"));
139 
140  // Give base class a chance
142 }
143 
145 {
146  DoRegenerateTooltips( true );
147 }
148 
150 {
151 #if wxUSE_TOOLTIPS
152  auto fn = [&](
153  AButton &button, const TranslatableString &label, const CommandID &cmd)
154  {
155  ComponentInterfaceSymbol command{ cmd, label };
156  ToolBar::SetButtonToolTip( mProject, button, &command, 1u );
157  };
158 
159  auto project = &mProject;
160  if (project) {
161  auto &scrubber = Scrubber::Get( *project );
162 
163  const auto scrubButton = mButtons[STBScrubID];
164  const auto seekButton = mButtons[STBSeekID];
165 
167  bool scrubs = scrubber.Scrubs();
168  if (force || mLastScrub != scrubs) {
169  label = (
170  scrubs
171  /* i18n-hint: These commands assist the user in finding a sound by ear. ...
172  "Scrubbing" is variable-speed playback, ...
173  "Seeking" is normal speed playback but with skips
174  */
175  ? XO("Stop Scrubbing")
176  /* i18n-hint: These commands assist the user in finding a sound by ear. ...
177  "Scrubbing" is variable-speed playback, ...
178  "Seeking" is normal speed playback but with skips
179  */
180  : XO("Start Scrubbing")
181  );
182  fn(*scrubButton, label, wxT("Scrub"));
183  }
184  mLastScrub = scrubs;
185 
186  bool seeks = scrubber.Seeks();
187  if (force || mLastSeek != seeks) {
188  label = (
189  seeks
190  /* i18n-hint: These commands assist the user in finding a sound by ear. ...
191  "Scrubbing" is variable-speed playback, ...
192  "Seeking" is normal speed playback but with skips
193  */
194  ? XO("Stop Seeking")
195  /* i18n-hint: These commands assist the user in finding a sound by ear. ...
196  "Scrubbing" is variable-speed playback, ...
197  "Seeking" is normal speed playback but with skips
198  */
199  : XO("Start Seeking")
200  );
201  fn(*seekButton, label, wxT("Seek"));
202  }
203  mLastSeek = seeks;
204 
205  bool showingRuler = AdornedRulerPanel::Get( *project ).ShowingScrubRuler();
206  if (force || mLastRuler != showingRuler) {
207  label = (
208  showingRuler
209  ? XO("Hide Scrub Ruler")
210  : XO("Show Scrub Ruler")
211  );
212  fn(*mButtons[STBRulerID], label, wxT("ToggleScrubRuler"));
213  }
214  mLastRuler = showingRuler;
215  }
216 #endif
217 }
218 
219 void ScrubbingToolBar::OnButton(wxCommandEvent &event)
220 {
222  if (!p) return;
223  auto &scrubber = Scrubber::Get( *p );
224 
225  int id = event.GetId();
226 
227  switch (id) {
228  case STBScrubID:
229  scrubber.OnScrub(*p);
230  break;
231  case STBSeekID:
232  scrubber.OnSeek(*p);
233  break;
234  case STBRulerID:
235  scrubber.OnToggleScrubRuler(*p);
236  break;
237  default:
238  wxASSERT(false);
239  }
240 
242 }
243 
245 {
246  const auto scrubButton = mButtons[STBScrubID];
247  const auto seekButton = mButtons[STBSeekID];
248 
250 
251  auto &scrubber = Scrubber::Get( *p );
252  const auto canScrub = scrubber.CanScrub();
253 
254  if (scrubber.Scrubs()) {
255  scrubButton->PushDown();
256  scrubButton->Enable();
257  }
258  else {
259  scrubButton->PopUp();
260  if (canScrub)
261  scrubButton->Enable();
262  else
263  scrubButton->Disable();
264  }
265 
266  if (scrubber.Seeks()) {
267  seekButton->PushDown();
268  seekButton->Enable();
269  }
270  else {
271  seekButton->PopUp();
272  if (canScrub)
273  seekButton->Enable();
274  else
275  seekButton->Disable();
276  }
277 
278  const auto barButton = mButtons[STBRulerID];
279  barButton->Enable();
281  barButton->PushDown();
282  else
283  barButton->PopUp();
284  DoRegenerateTooltips( false );
285  scrubber.CheckMenuItems();
286 }
287 
288 void ScrubbingToolBar::OnIdle( wxIdleEvent &evt )
289 {
290  evt.Skip();
292 }
293 
295  []( AudacityProject &project ){
296  return ToolBar::Holder{ safenew ScrubbingToolBar{ project } }; }
297 };
298 
299 namespace {
301  /* i18n-hint: Clicking this menu item shows the toolbar
302  that enables Scrub or Seek playback and Scrub Ruler */
303  ScrubbingBarID, wxT("ShowScrubbingTB"), XXO("Scru&b Toolbar")
304 };
305 }
306 
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
AButton::SetLabel
void SetLabel(const TranslatableString &label)
Definition: AButton.cpp:274
teBmps
int teBmps
Definition: ImageManipulation.h:48
ToolManager.h
Scrubber::Get
static Scrubber & Get(AudacityProject &project)
Definition: Scrubbing.cpp:201
ScrubbingToolBar::OnIdle
void OnIdle(wxIdleEvent &evt)
Definition: ScrubbingToolBar.cpp:288
fn
static const auto fn
Definition: WaveformView.cpp:1108
AllThemeResources.h
ScrubbingToolBar::Populate
void Populate() override
Definition: ScrubbingToolBar.cpp:115
AButton
A wxButton with mouse-over behaviour.
Definition: AButton.h:25
ToolBar::mProject
AudacityProject & mProject
Definition: ToolBar.h:235
ToolBar::SetLabel
void SetLabel(const wxString &label) override
Definition: ToolBar.cpp:398
ToolManager::Get
static ToolManager & Get(AudacityProject &project)
Definition: ToolManager.cpp:356
EVT_COMMAND_RANGE
EVT_COMMAND_RANGE(STBFirstButton, STBFirstButton+STBNumButtons - 1, wxEVT_COMMAND_BUTTON_CLICKED, ScrubbingToolBar::OnButton) ScrubbingToolBar
Methods for ScrubbingToolBar.
Definition: ScrubbingToolBar.cpp:51
ScrubbingToolBar::mLastRuler
bool mLastRuler
Definition: ScrubbingToolBar.h:87
XO
#define XO(s)
Definition: Internat.h:31
ScrubbingToolBar::Create
void Create(wxWindow *parent) override
Definition: ScrubbingToolBar.cpp:79
ThemeBase::ImageSize
wxSize ImageSize(int iIndex)
Definition: Theme.cpp:1224
STBFirstButton
@ STBFirstButton
Definition: ScrubbingToolBar.h:36
ToolBar::Holder
wxWindowPtr< ToolBar > Holder
Definition: ToolBar.h:102
AttachedToolBarMenuItem
Definition: ToolManager.h:224
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
ScrubbingToolBar.h
wxEVT_COMMAND_BUTTON_CLICKED
wxEVT_COMMAND_BUTTON_CLICKED
Definition: AdornedRulerPanel.cpp:494
ScrubbingToolBar::mButtons
AButton * mButtons[STBNumButtons]
Definition: ScrubbingToolBar.h:69
AdornedRulerPanel::Get
static AdornedRulerPanel & Get(AudacityProject &project)
Definition: AdornedRulerPanel.cpp:899
XXO
#define XXO(s)
Definition: Internat.h:44
AButton::Enable
void Enable()
Definition: AButton.cpp:571
label
TranslatableString label
Definition: Tags.cpp:756
ScrubbingToolBar::mLastScrub
bool mLastScrub
Definition: ScrubbingToolBar.h:85
ScrubbingToolBar::AddButton
static AButton * AddButton(ScrubbingToolBar *pBar, teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled, int id, const TranslatableString &label, bool toggle=false)
Definition: ScrubbingToolBar.cpp:89
ToolBar::SetButtonToolTip
static void SetButtonToolTip(AudacityProject &project, AButton &button, const ComponentInterfaceSymbol commands[], size_t nCommands)
Definition: ToolBar.cpp:898
ScrubbingBarID
@ ScrubbingBarID
Definition: ToolBar.h:80
STBScrubID
@ STBScrubID
Definition: ScrubbingToolBar.h:31
ScrubbingToolBar::RegenerateTooltips
void RegenerateTooltips() override
Definition: ScrubbingToolBar.cpp:144
STBSeekID
@ STBSeekID
Definition: ScrubbingToolBar.h:32
AdornedRulerPanel::ShowingScrubRuler
bool ShowingScrubRuler() const
Definition: AdornedRulerPanel.cpp:2277
ToolBar::UpdatePrefs
void UpdatePrefs() override
Definition: ToolBar.cpp:605
anonymous_namespace{ScrubbingToolBar.cpp}::sAttachment
AttachedToolBarMenuItem sAttachment
Definition: ScrubbingToolBar.cpp:300
ToolBar::Create
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:475
ScrubbingToolBar::UpdatePrefs
void UpdatePrefs() override
Definition: ScrubbingToolBar.cpp:133
theTheme
THEME_API Theme theTheme
Definition: Theme.cpp:79
STBRulerID
@ STBRulerID
Definition: ScrubbingToolBar.h:33
id
int id
Definition: WaveTrackControls.cpp:577
RegisteredToolbarFactory
Definition: ToolBar.h:261
TaggedIdentifier< CommandIdTag, false >
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
factory
static RegisteredToolbarFactory factory
Definition: ScrubbingToolBar.cpp:294
ToolBar::MakeButtonBackgroundsSmall
static void MakeButtonBackgroundsSmall()
Definition: ToolBar.cpp:802
ScrubbingToolBar::EnableDisableButtons
void EnableDisableButtons() override
Definition: ScrubbingToolBar.cpp:244
ToolBar
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed.
Definition: ToolBar.h:98
ThemeBase::Colour
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1189
ToolBar::MakeButton
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:840
ScrubbingToolBar::Get
static ScrubbingToolBar & Get(AudacityProject &project)
Definition: ScrubbingToolBar.cpp:68
Prefs.h
ScrubbingToolBar::DoRegenerateTooltips
void DoRegenerateTooltips(bool force)
Definition: ScrubbingToolBar.cpp:149
safenew
#define safenew
Definition: MemoryX.h:10
ScrubbingToolBar::~ScrubbingToolBar
virtual ~ScrubbingToolBar()
Definition: ScrubbingToolBar.cpp:64
IMPLEMENT_CLASS
IMPLEMENT_CLASS(ScrubbingToolBar, ToolBar)
END_EVENT_TABLE
END_EVENT_TABLE()
ToolBar::Add
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:686
ImageManipulation.h
STBNumButtons
@ STBNumButtons
Definition: ScrubbingToolBar.h:35
ScrubbingToolBar
Definition: ScrubbingToolBar.h:39
ScrubbingToolBar::OnButton
void OnButton(wxCommandEvent &event)
Definition: ScrubbingToolBar.cpp:219
ScrubbingToolBar::mLastSeek
bool mLastSeek
Definition: ScrubbingToolBar.h:86