Audacity 3.2.0
TimeSignatureToolBar.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/**********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 TimeSignatureToolBar.cpp
7
8 Dmitry Vedenko
9
10*******************************************************************/
11
13
14#include <algorithm>
15#include <cassert>
16
17#include <wx/sizer.h>
18#include <wx/spinctrl.h>
19#include <wx/combobox.h>
20
21#include "ToolManager.h"
22
23
24#include "widgets/BasicMenu.h"
26
27#include "Prefs.h"
28#include "Project.h"
29#include "ViewInfo.h"
30
31#include "AllThemeResources.h"
32#include "AudioIO.h"
33
35#include "wxArrayStringEx.h"
36
37#include "ProjectHistory.h"
38#include "UndoManager.h"
39
40#include "SpinControl.h"
41
42#if wxUSE_ACCESSIBILITY
43#include "WindowAccessible.h"
44#endif
45
47
48BEGIN_EVENT_TABLE(TimeSignatureToolBar, ToolBar)
51
53{
54 return wxT("TimeSignature");
55}
56
58 : ToolBar(project, XO("Time Signature"), ID())
59 , mTimeSignatureChangedSubscription(ProjectTimeSignature::Get(mProject).Subscribe(
60 [this](auto settings)
61 {
62 if (mTempoControl)
63 mTempoControl->SetValue(settings.newTempo);
64
66 mUpperSignatureControl->SetValue(
67 settings.newUpperTimeSignature);
68
70 mLowerSignatureControl->SetValue(
71 wxString::Format("%d", settings.newLowerTimeSignature));
72 }))
73 , mPlaybackStateChangedSubscription(AudioIO::Get()->Subscribe(*this, &TimeSignatureToolBar::OnAudioIOEvent))
74{
75}
76
78
80{
81 return true;
82}
83
85{
86 return BotDockID;
87}
88
90{
91 auto &toolManager = ToolManager::Get( project );
92 return *static_cast<TimeSignatureToolBar*>(toolManager.GetToolBar(ID()));
93}
94
96{
97 return Get( const_cast<AudacityProject&>( project )) ;
98}
99
100void TimeSignatureToolBar::Create(wxWindow* parent)
101{
102 ToolBar::Create(parent);
103 UpdatePrefs();
104}
105
107{
108#ifndef __WXGTK__
109 const auto tempoSigSize = wxSize(60, -1);
110 auto timeSigSize = wxSize(50, -1);
111#else
112 const auto tempoSigSize = wxSize(60, -1);
113 auto timeSigSize = wxSize(60, -1);
114#endif
115
116 auto& projectTimeSignature = ProjectTimeSignature::Get(mProject);
117
118 SetBackgroundColour( theTheme.Colour( clrMedium ) );
119
120 auto sizer = safenew wxFlexGridSizer(2, 5, 1);
121 Add(sizer, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 5);
122
123 AddTitle(XO("Tempo"), sizer);
124 AddTitle(XO("Time Signature"), sizer);
125
127 this, wxID_ANY, projectTimeSignature.GetTempo(), 1.0, 999.0, 1.0, true,
128 wxDefaultPosition, tempoSigSize);
129
130 mTempoControl->SetName(XO("Tempo"));
131
132 sizer->Add(mTempoControl, 0, wxEXPAND | wxRIGHT, 5);
133
134 auto tempoSizer = safenew wxBoxSizer(wxHORIZONTAL);
135 sizer->Add(tempoSizer, 0, wxEXPAND | wxRIGHT, 5);
136
138 this, wxID_ANY, projectTimeSignature.GetUpperTimeSignature(), 1.0, 128.0, 1.0, false,
139 wxDefaultPosition, timeSigSize);
140
141 mUpperSignatureControl->SetName(XO("Upper Time Signature"));
142
143 tempoSizer->Add(mUpperSignatureControl, 0, wxEXPAND | wxRIGHT, 5);
144
145 AddTitle(
146 Verbatim(L"/"), tempoSizer, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5, 1.5);
147
148 timeSigSize.y = mUpperSignatureControl->GetSize().y;
149
150 mLowerSignatureControl = safenew wxComboBox(
151 this, wxID_ANY,
152 wxString::Format(
153 "%d", ProjectTimeSignature::Get(mProject).GetLowerTimeSignature()),
154 wxDefaultPosition, timeSigSize,
155 wxArrayStringEx { L"2", L"4", L"8", L"16", L"32", L"64" },
156 wxCB_READONLY);
157
158 mLowerSignatureControl->SetName(XO("Lower Time Signature").Translation());
159
160 tempoSizer->Add(mLowerSignatureControl, 0, wxEXPAND | wxRIGHT, 5);
161
162 mTempoControl->Bind(
163 wxEVT_SPINCTRL,
164 [this](auto)
165 {
166 const auto tempo = mTempoControl->GetValue();
167
169
171 XO("Tempo Changed"), XO("Tempo Changed"), UndoPush::CONSOLIDATE);
172 });
173
175 wxEVT_SPINCTRL,
176 [this](auto)
177 {
178 const auto upper = int(mUpperSignatureControl->GetValue());
179
181
183 XO("Upper Time Signature Changed"),
184 XO("Upper Time Signature Changed"), UndoPush::CONSOLIDATE);
185 });
186
188 wxEVT_COMBOBOX,
189 [this](auto)
190 {
191 long value;
192
193 if (!mLowerSignatureControl->GetValue().ToLong(&value))
194 return;
195
197
199 XO("Lower Time Signature Changed"),
200 XO("Lower Time Signature Changed"), UndoPush::CONSOLIDATE);
201 });
202
203#if wxUSE_ACCESSIBILITY
205 mUpperSignatureControl->SetAccessible(
207 mLowerSignatureControl->SetAccessible(
209#endif
210
212 Fit();
213 Layout();
214}
215
217{
218 // Set label to pull in language change
219 SetLabel(XO("Time Signature"));
220
222 // Give base class a chance
224}
225
227{
228}
229
230void TimeSignatureToolBar::OnSize(wxSizeEvent& evt)
231{
232 Refresh( true );
233
234 evt.Skip();
235}
236
238{
239 switch(event.type)
240 {
243 {
244 if(mTempoControl)
245 mTempoControl->Enable(!event.on);
246 } break;
247 default: break;
248 }
249}
250
251
253 const TranslatableString& Title, wxSizer* pSizer, int flags, int border,
254 double fontMultiplier)
255{
256 const auto translated = Title.Translation();
257
258 auStaticText* pTitle = safenew auStaticText(this, translated);
259
260 pTitle->SetBackgroundColour(theTheme.Colour(clrMedium));
261 pTitle->SetForegroundColour(theTheme.Colour(clrTrackPanelText));
262 pTitle->ScaleFont(fontMultiplier);
263
264 pSizer->Add(pTitle, 0, flags, border);
265}
266
270} };
271
272namespace {
274 /* i18n-hint: Clicking this menu item shows the toolbar
275 for selecting a time range of audio */
276 TimeSignatureToolBar::ID(), wxT("ShowTimeSignatureTB"), XXO("Time Signature Toolbar")
277};
278
279// Undo/redo handling of time signature changes
280// DV: where should this really go?
281
283{
285 : mTempo { ProjectTimeSignature::Get(project).GetTempo() }
286 , mUpper { ProjectTimeSignature::Get(project).GetUpperTimeSignature() }
287 , mLower { ProjectTimeSignature::Get(project).GetLowerTimeSignature() }
288 {
289 }
291 {
292 auto& timeSignature = ProjectTimeSignature::Get(project);
293
294 timeSignature.SetTempo(mTempo);
295 timeSignature.SetUpperTimeSignature(mUpper);
296 timeSignature.SetLowerTimeSignature(mLower);
297 }
298
299 double mTempo;
302};
303
305 [](AudacityProject& project) -> std::shared_ptr<UndoStateExtension>
306 { return std::make_shared<TimeSignatureRestorer>(project); }
307};
308}
309
wxT("CloseDown"))
Abstractions of menus and their items.
END_EVENT_TABLE()
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
#define safenew
Definition: MemoryX.h:10
const auto project
THEME_API Theme theTheme
Definition: Theme.cpp:82
IMPLEMENT_CLASS(TimeSignatureToolBar, ToolBar)
static RegisteredToolbarFactory factory
static Settings & settings()
Definition: TrackInfo.cpp:51
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
static AudioIO * Get()
Definition: AudioIO.cpp:126
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
static ProjectHistory & Get(AudacityProject &project)
void SetUpperTimeSignature(int upperTimeSignature)
void SetLowerTimeSignature(int lowerTimeSignature)
void SetTempo(double tempo)
static ProjectTimeSignature & Get(AudacityProject &project)
wxColour & Colour(int iIndex)
DockID DefaultDockID() const override
Which dock the toolbar defaults into. Default implementation chooses the top dock.
wxWeakRef< wxComboBox > mLowerSignatureControl
bool ShownByDefault() const override
Whether the toolbar should be shown by default. Default implementation returns true.
void AddTitle(const TranslatableString &Title, wxSizer *pSizer, int flags=wxEXPAND|wxRIGHT, int border=5, double fontMultiplier=1.0)
wxWeakRef< SpinControl > mTempoControl
void Create(wxWindow *parent) override
void RegenerateTooltips() override
static Identifier ID()
static TimeSignatureToolBar & Get(AudacityProject &project)
virtual ~TimeSignatureToolBar()
void OnAudioIOEvent(const AudioIOEvent &event)
TimeSignatureToolBar(AudacityProject &project)
void OnSize(wxSizeEvent &evt)
wxWeakRef< SpinControl > mUpperSignatureControl
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed.
Definition: ToolBar.h:73
AudacityProject & mProject
Definition: ToolBar.h:247
DockID
Identifies one of the docking areas for toolbars.
Definition: ToolBar.h:91
@ BotDockID
Definition: ToolBar.h:93
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:709
void SetLabel(const wxString &label) override
Definition: ToolBar.cpp:408
void UpdatePrefs() override
Definition: ToolBar.cpp:622
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:492
wxWindowPtr< ToolBar > Holder
Definition: ToolBar.h:77
static ToolManager & Get(AudacityProject &project)
Holds a msgid for the translation catalog; may also bind format arguments.
Base class for extra information attached to undo/redo states.
Definition: UndoManager.h:83
An alternative to using wxWindowAccessible, which in wxWidgets 3.1.1 contained GetParent() which was ...
is like wxStaticText, except it can be themed. wxStaticText can't be.
Definition: auStaticText.h:20
void ScaleFont(double scale)
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:202
bool on
Definition: AudioIO.h:68
enum AudioIOEvent::Type type
Typically statically constructed.
Definition: UndoManager.h:102
void RestoreUndoRedoState(AudacityProject &project) override
Modify the project when undoing or redoing to some state in history.