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/tooltip.h>
27#endif
28
29#include "../AdornedRulerPanel.h"
30#include "AllThemeResources.h"
31#include "ImageManipulation.h"
32#include "Prefs.h"
33#include "UndoManager.h"
34#include "../widgets/AButton.h"
35#include "../tracks/ui/Scrubbing.h"
36
38
42
43BEGIN_EVENT_TABLE( ScrubbingToolBar, ToolBar )
47 ScrubbingToolBar::OnButton )
48EVT_IDLE( ScrubbingToolBar::OnIdle )
50
52{
53 return wxT("Scrub");
54}
55
56//Standard constructor
58: ToolBar(project, XO("Scrub"), ID())
59{
60}
61
63{
64}
65
67{
68 return false;
69}
70
72{
73 auto &toolManager = ToolManager::Get( project );
74 return *static_cast<ScrubbingToolBar*>(toolManager.GetToolBar(ID()));
75}
76
78{
79 return Get( const_cast<AudacityProject&>( project )) ;
80}
81
82void ScrubbingToolBar::Create(wxWindow * parent)
83{
84 ToolBar::Create(parent);
86}
87
92(ScrubbingToolBar *pBar,
93 teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled,
94 int id,
96 bool toggle)
97{
98 AButton *&r = pBar->mButtons[id];
99
101 (pBar,
102 bmpRecoloredUpSmall, bmpRecoloredDownSmall, bmpRecoloredUpHiliteSmall, bmpRecoloredHiliteSmall,
103 eEnabledUp, eEnabledDown, eDisabled,
104 wxWindowID(id),
105 wxDefaultPosition,
106 toggle,
107 theTheme.ImageSize( bmpRecoloredUpSmall ));
108
109 r->SetLabel(label);
110 // JKC: Unlike ControlToolBar, does not have a focus rect. Shouldn't it?
111 // r->SetFocusRect( r->GetRect().Deflate( 4, 4 ) );
112
113 pBar->Add( r, 0, wxALIGN_CENTER );
114
115 return r;
116}
117
119{
120 SetBackgroundColour( theTheme.Colour( clrMedium ) );
122
123 /* Buttons */
124 AddButton(this, bmpScrub, bmpScrub, bmpScrubDisabled, STBScrubID,
125 XO("Scrub"), true);
126 AddButton(this, bmpSeek, bmpSeek, bmpSeekDisabled, STBSeekID,
127 XO("Seek"), true);
128 AddButton(this, bmpToggleScrubRuler, bmpToggleScrubRuler, bmpToggleScrubRuler,
130 XO("Scrub Ruler"), true);
131
132
134}
135
137{
139
140 // Set label to pull in language change
141 SetLabel(XO("Scrubbing"));
142
143 // Give base class a chance
145}
146
148{
149 DoRegenerateTooltips( true );
150}
151
153{
154#if wxUSE_TOOLTIPS
155 auto fn = [&](
156 AButton &button, const TranslatableString &label, const CommandID &cmd)
157 {
158 ComponentInterfaceSymbol command{ cmd, label };
159 ToolBar::SetButtonToolTip( mProject, button, &command, 1u );
160 };
161
162 auto project = &mProject;
163 if (project) {
164 auto &scrubber = Scrubber::Get( *project );
165
166 const auto scrubButton = mButtons[STBScrubID];
167 const auto seekButton = mButtons[STBSeekID];
168
170 bool scrubs = scrubber.Scrubs();
171 if (force || mLastScrub != scrubs) {
172 label = (
173 scrubs
174 /* i18n-hint: These commands assist the user in finding a sound by ear. ...
175 "Scrubbing" is variable-speed playback, ...
176 "Seeking" is normal speed playback but with skips
177 */
178 ? XO("Stop Scrubbing")
179 /* i18n-hint: These commands assist the user in finding a sound by ear. ...
180 "Scrubbing" is variable-speed playback, ...
181 "Seeking" is normal speed playback but with skips
182 */
183 : XO("Start Scrubbing")
184 );
185 fn(*scrubButton, label, wxT("Scrub"));
186 }
187 mLastScrub = scrubs;
188
189 bool seeks = scrubber.Seeks();
190 if (force || mLastSeek != seeks) {
191 label = (
192 seeks
193 /* i18n-hint: These commands assist the user in finding a sound by ear. ...
194 "Scrubbing" is variable-speed playback, ...
195 "Seeking" is normal speed playback but with skips
196 */
197 ? XO("Stop Seeking")
198 /* i18n-hint: These commands assist the user in finding a sound by ear. ...
199 "Scrubbing" is variable-speed playback, ...
200 "Seeking" is normal speed playback but with skips
201 */
202 : XO("Start Seeking")
203 );
204 fn(*seekButton, label, wxT("Seek"));
205 }
206 mLastSeek = seeks;
207
208 bool showingRuler = AdornedRulerPanel::Get( *project ).ShowingScrubRuler();
209 if (force || mLastRuler != showingRuler) {
210 label = (
211 showingRuler
212 ? XO("Hide Scrub Ruler")
213 : XO("Show Scrub Ruler")
214 );
215 fn(*mButtons[STBRulerID], label, wxT("ToggleScrubRuler"));
216 }
217 mLastRuler = showingRuler;
218 }
219#endif
220}
221
222void ScrubbingToolBar::OnButton(wxCommandEvent &event)
223{
225 if (!p) return;
226 auto &scrubber = Scrubber::Get( *p );
227
228 int id = event.GetId();
229
230 switch (id) {
231 case STBScrubID:
232 scrubber.OnScrub(*p);
233 break;
234 case STBSeekID:
235 scrubber.OnSeek(*p);
236 break;
237 case STBRulerID:
238 scrubber.OnToggleScrubRuler(*p);
239 break;
240 default:
241 wxASSERT(false);
242 }
243
245}
246
248{
249 const auto scrubButton = mButtons[STBScrubID];
250 const auto seekButton = mButtons[STBSeekID];
251
253
254 auto &scrubber = Scrubber::Get( *p );
255 const auto canScrub = scrubber.CanScrub();
256
257 if (scrubber.Scrubs()) {
258 scrubButton->PushDown();
259 scrubButton->Enable();
260 }
261 else {
262 scrubButton->PopUp();
263 if (canScrub)
264 scrubButton->Enable();
265 else
266 scrubButton->Disable();
267 }
268
269 if (scrubber.Seeks()) {
270 seekButton->PushDown();
271 seekButton->Enable();
272 }
273 else {
274 seekButton->PopUp();
275 if (canScrub)
276 seekButton->Enable();
277 else
278 seekButton->Disable();
279 }
280
281 const auto barButton = mButtons[STBRulerID];
282 barButton->Enable();
284 barButton->PushDown();
285 else
286 barButton->PopUp();
287 DoRegenerateTooltips( false );
288 scrubber.CheckMenuItems();
289}
290
291void ScrubbingToolBar::OnIdle( wxIdleEvent &evt )
292{
293 evt.Skip();
295}
296
300};
301
302namespace {
304 /* i18n-hint: Clicking this menu item shows the toolbar
305 that enables Scrub or Seek playback and Scrub Ruler */
306 ScrubbingToolBar::ID(), wxT("ShowScrubbingTB"), XXO("Scru&b Toolbar")
307};
308}
309
wxEVT_COMMAND_BUTTON_CLICKED
wxT("CloseDown"))
END_EVENT_TABLE()
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
int teBmps
#define safenew
Definition: MemoryX.h:10
static RegisteredToolbarFactory factory
EVT_COMMAND_RANGE(STBFirstButton, STBFirstButton+STBNumButtons - 1, wxEVT_COMMAND_BUTTON_CLICKED, ScrubbingToolBar::OnButton) Identifier ScrubbingToolBar
Methods for ScrubbingToolBar.
IMPLEMENT_CLASS(ScrubbingToolBar, ToolBar)
@ STBFirstButton
@ STBNumButtons
@ STBRulerID
@ STBSeekID
@ STBScrubID
TranslatableString label
Definition: TagsEditor.cpp:165
const auto project
THEME_API Theme theTheme
Definition: Theme.cpp:82
int id
static const auto fn
A wxButton with mouse-over behaviour.
Definition: AButton.h:104
void Enable()
Definition: AButton.cpp:551
void SetLabel(const TranslatableString &label)
Definition: AButton.cpp:189
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:90
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
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)
bool ShownByDefault() const override
Whether the toolbar should be shown by default. Default implementation returns true.
ScrubbingToolBar(AudacityProject &project)
static Identifier ID()
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:74
AudacityProject & mProject
Definition: ToolBar.h:248
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:709
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:875
void SetLabel(const wxString &label) override
Definition: ToolBar.cpp:408
static void MakeButtonBackgroundsSmall()
Definition: ToolBar.cpp:837
void UpdatePrefs() override
Definition: ToolBar.cpp:622
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:492
wxWindowPtr< ToolBar > Holder
Definition: ToolBar.h:78
static void SetButtonToolTip(AudacityProject &project, AButton &button, const ComponentInterfaceSymbol commands[], size_t nCommands)
Definition: ToolBar.cpp:970
static ToolManager & Get(AudacityProject &project)
Holds a msgid for the translation catalog; may also bind format arguments.