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
46
47BEGIN_EVENT_TABLE( ScrubbingToolBar, ToolBar )
51 ScrubbingToolBar::OnButton )
52EVT_IDLE( ScrubbingToolBar::OnIdle )
54
55//Standard constructor
57: ToolBar(project, ScrubbingBarID, XO("Scrub"), wxT("Scrub"))
58{
59}
60
62{
63}
64
66{
67 auto &toolManager = ToolManager::Get( project );
68 return *static_cast<ScrubbingToolBar*>( toolManager.GetToolBar(ScrubbingBarID) );
69}
70
72{
73 return Get( const_cast<AudacityProject&>( project )) ;
74}
75
76void ScrubbingToolBar::Create(wxWindow * parent)
77{
78 ToolBar::Create(parent);
80}
81
86(ScrubbingToolBar *pBar,
87 teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled,
88 int id,
90 bool toggle)
91{
92 AButton *&r = pBar->mButtons[id];
93
95 (pBar,
96 bmpRecoloredUpSmall, bmpRecoloredDownSmall, bmpRecoloredUpHiliteSmall, bmpRecoloredHiliteSmall,
97 eEnabledUp, eEnabledDown, eDisabled,
98 wxWindowID(id),
99 wxDefaultPosition,
100 toggle,
101 theTheme.ImageSize( bmpRecoloredUpSmall ));
102
103 r->SetLabel(label);
104 // JKC: Unlike ControlToolBar, does not have a focus rect. Shouldn't it?
105 // r->SetFocusRect( r->GetRect().Deflate( 4, 4 ) );
106
107 pBar->Add( r, 0, wxALIGN_CENTER );
108
109 return r;
110}
111
113{
114 SetBackgroundColour( theTheme.Colour( clrMedium ) );
116
117 /* Buttons */
118 AddButton(this, bmpScrub, bmpScrub, bmpScrubDisabled, STBScrubID,
119 XO("Scrub"), true);
120 AddButton(this, bmpSeek, bmpSeek, bmpSeekDisabled, STBSeekID,
121 XO("Seek"), true);
122 AddButton(this, bmpToggleScrubRuler, bmpToggleScrubRuler, bmpToggleScrubRuler,
124 XO("Scrub Ruler"), true);
125
126
128}
129
131{
133
134 // Set label to pull in language change
135 SetLabel(XO("Scrubbing"));
136
137 // Give base class a chance
139}
140
142{
143 DoRegenerateTooltips( true );
144}
145
147{
148#if wxUSE_TOOLTIPS
149 auto fn = [&](
150 AButton &button, const TranslatableString &label, const CommandID &cmd)
151 {
152 ComponentInterfaceSymbol command{ cmd, label };
153 ToolBar::SetButtonToolTip( mProject, button, &command, 1u );
154 };
155
156 auto project = &mProject;
157 if (project) {
158 auto &scrubber = Scrubber::Get( *project );
159
160 const auto scrubButton = mButtons[STBScrubID];
161 const auto seekButton = mButtons[STBSeekID];
162
164 bool scrubs = scrubber.Scrubs();
165 if (force || mLastScrub != scrubs) {
166 label = (
167 scrubs
168 /* i18n-hint: These commands assist the user in finding a sound by ear. ...
169 "Scrubbing" is variable-speed playback, ...
170 "Seeking" is normal speed playback but with skips
171 */
172 ? XO("Stop Scrubbing")
173 /* i18n-hint: These commands assist the user in finding a sound by ear. ...
174 "Scrubbing" is variable-speed playback, ...
175 "Seeking" is normal speed playback but with skips
176 */
177 : XO("Start Scrubbing")
178 );
179 fn(*scrubButton, label, wxT("Scrub"));
180 }
181 mLastScrub = scrubs;
182
183 bool seeks = scrubber.Seeks();
184 if (force || mLastSeek != seeks) {
185 label = (
186 seeks
187 /* i18n-hint: These commands assist the user in finding a sound by ear. ...
188 "Scrubbing" is variable-speed playback, ...
189 "Seeking" is normal speed playback but with skips
190 */
191 ? XO("Stop Seeking")
192 /* i18n-hint: These commands assist the user in finding a sound by ear. ...
193 "Scrubbing" is variable-speed playback, ...
194 "Seeking" is normal speed playback but with skips
195 */
196 : XO("Start Seeking")
197 );
198 fn(*seekButton, label, wxT("Seek"));
199 }
200 mLastSeek = seeks;
201
202 bool showingRuler = AdornedRulerPanel::Get( *project ).ShowingScrubRuler();
203 if (force || mLastRuler != showingRuler) {
204 label = (
205 showingRuler
206 ? XO("Hide Scrub Ruler")
207 : XO("Show Scrub Ruler")
208 );
209 fn(*mButtons[STBRulerID], label, wxT("ToggleScrubRuler"));
210 }
211 mLastRuler = showingRuler;
212 }
213#endif
214}
215
216void ScrubbingToolBar::OnButton(wxCommandEvent &event)
217{
219 if (!p) return;
220 auto &scrubber = Scrubber::Get( *p );
221
222 int id = event.GetId();
223
224 switch (id) {
225 case STBScrubID:
226 scrubber.OnScrub(*p);
227 break;
228 case STBSeekID:
229 scrubber.OnSeek(*p);
230 break;
231 case STBRulerID:
232 scrubber.OnToggleScrubRuler(*p);
233 break;
234 default:
235 wxASSERT(false);
236 }
237
239}
240
242{
243 const auto scrubButton = mButtons[STBScrubID];
244 const auto seekButton = mButtons[STBSeekID];
245
247
248 auto &scrubber = Scrubber::Get( *p );
249 const auto canScrub = scrubber.CanScrub();
250
251 if (scrubber.Scrubs()) {
252 scrubButton->PushDown();
253 scrubButton->Enable();
254 }
255 else {
256 scrubButton->PopUp();
257 if (canScrub)
258 scrubButton->Enable();
259 else
260 scrubButton->Disable();
261 }
262
263 if (scrubber.Seeks()) {
264 seekButton->PushDown();
265 seekButton->Enable();
266 }
267 else {
268 seekButton->PopUp();
269 if (canScrub)
270 seekButton->Enable();
271 else
272 seekButton->Disable();
273 }
274
275 const auto barButton = mButtons[STBRulerID];
276 barButton->Enable();
278 barButton->PushDown();
279 else
280 barButton->PopUp();
281 DoRegenerateTooltips( false );
282 scrubber.CheckMenuItems();
283}
284
285void ScrubbingToolBar::OnIdle( wxIdleEvent &evt )
286{
287 evt.Skip();
289}
290
292 []( AudacityProject &project ){
293 return ToolBar::Holder{ safenew ScrubbingToolBar{ project } }; }
294};
295
296namespace {
298 /* i18n-hint: Clicking this menu item shows the toolbar
299 that enables Scrub or Seek playback and Scrub Ruler */
300 ScrubbingBarID, wxT("ShowScrubbingTB"), XXO("Scru&b Toolbar")
301};
302}
303
wxEVT_COMMAND_BUTTON_CLICKED
wxT("CloseDown"))
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:79
int id
static const auto fn
A wxButton with mouse-over behaviour.
Definition: AButton.h:104
void Enable()
Definition: AButton.cpp:554
void SetLabel(const TranslatableString &label)
Definition: AButton.cpp:192
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:187
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:101
AudacityProject & mProject
Definition: ToolBar.h:251
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:695
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:861
void SetLabel(const wxString &label) override
Definition: ToolBar.cpp:407
static void MakeButtonBackgroundsSmall()
Definition: ToolBar.cpp:823
void UpdatePrefs() override
Definition: ToolBar.cpp:614
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:484
wxWindowPtr< ToolBar > Holder
Definition: ToolBar.h:105
static void SetButtonToolTip(AudacityProject &project, AButton &button, const ComponentInterfaceSymbol commands[], size_t nCommands)
Definition: ToolBar.cpp:956
static ToolManager & Get(AudacityProject &project)
Holds a msgid for the translation catalog; may also bind format arguments.