Audacity 3.2.0
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
50BEGIN_EVENT_TABLE( ScrubbingToolBar, ToolBar )
54 ScrubbingToolBar::OnButton )
55EVT_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
79void ScrubbingToolBar::Create(wxWindow * parent)
80{
81 ToolBar::Create(parent);
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,
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
219void 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
288void ScrubbingToolBar::OnIdle( wxIdleEvent &evt )
289{
290 evt.Skip();
292}
293
295 []( AudacityProject &project ){
296 return ToolBar::Holder{ safenew ScrubbingToolBar{ project } }; }
297};
298
299namespace {
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
wxEVT_COMMAND_BUTTON_CLICKED
END_EVENT_TABLE()
int teBmps
#define XXO(s)
Definition: Internat.h:44
#define XO(s)
Definition: Internat.h:31
#define safenew
Definition: MemoryX.h:10
EVT_COMMAND_RANGE(STBFirstButton, STBFirstButton+STBNumButtons - 1, wxEVT_COMMAND_BUTTON_CLICKED, ScrubbingToolBar::OnButton) ScrubbingToolBar
Methods for ScrubbingToolBar.
static RegisteredToolbarFactory factory
IMPLEMENT_CLASS(ScrubbingToolBar, ToolBar)
@ STBFirstButton
@ STBNumButtons
@ STBRulerID
@ STBSeekID
@ STBScrubID
TranslatableString label
Definition: TagsEditor.cpp:163
THEME_API Theme theTheme
Definition: Theme.cpp:82
@ ScrubbingBarID
Definition: ToolBar.h:80
int id
static const auto fn
A wxButton with mouse-over behaviour.
Definition: AButton.h:25
void Enable()
Definition: AButton.cpp:571
void SetLabel(const TranslatableString &label)
Definition: AButton.cpp:274
bool ShowingScrubRuler() const
static AdornedRulerPanel & Get(AudacityProject &project)
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
static Scrubber & Get(AudacityProject &project)
Definition: Scrubbing.cpp:202
static AButton * AddButton(ScrubbingToolBar *pBar, teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled, int id, const TranslatableString &label, bool toggle=false)
AButton * mButtons[STBNumButtons]
void RegenerateTooltips() override
virtual ~ScrubbingToolBar()
void Create(wxWindow *parent) override
void OnButton(wxCommandEvent &event)
void Populate() override
void EnableDisableButtons() override
void UpdatePrefs() override
static ScrubbingToolBar & Get(AudacityProject &project)
void DoRegenerateTooltips(bool force)
void OnIdle(wxIdleEvent &evt)
wxColour & Colour(int iIndex)
wxSize ImageSize(int iIndex)
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed.
Definition: ToolBar.h:98
AudacityProject & mProject
Definition: ToolBar.h:235
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:686
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
void SetLabel(const wxString &label) override
Definition: ToolBar.cpp:398
static void MakeButtonBackgroundsSmall()
Definition: ToolBar.cpp:802
void UpdatePrefs() override
Definition: ToolBar.cpp:605
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:475
wxWindowPtr< ToolBar > Holder
Definition: ToolBar.h:102
static void SetButtonToolTip(AudacityProject &project, AButton &button, const ComponentInterfaceSymbol commands[], size_t nCommands)
Definition: ToolBar.cpp:898
static ToolManager & Get(AudacityProject &project)
Holds a msgid for the translation catalog; may also bind format arguments.