Audacity 3.2.0
MeterToolBar.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 MeterToolBar.cpp
6
7 Dominic Mazzoni
8 Leland Lucius
9
10 See MeterToolBar.h for details
11
12*******************************************************************//*******************************************************************/
18
19
20
21#include "MeterToolBar.h"
22
23// For compilers that support precompilation, includes "wx/wx.h".
24#include <wx/wxprec.h>
25
26#include <wx/setup.h> // for wxUSE_* macros
27
28#ifndef WX_PRECOMP
29#include <wx/event.h>
30#include <wx/intl.h>
31#include <wx/tooltip.h>
32#endif
33
34#include <wx/gbsizer.h>
35
36#include "AllThemeResources.h"
37#include "ToolManager.h"
38#include "../ProjectAudioIO.h"
39#include "../widgets/MeterPanel.h"
40
42
46
47BEGIN_EVENT_TABLE( MeterToolBar, ToolBar )
48 EVT_SIZE( MeterToolBar::OnSize )
50
51//Standard constructor
53: ToolBar(project, type, XO("Combined Meter"), wxT("CombinedMeter"), true)
54{
55 if( mType == RecordMeterBarID ){
56 mWhichMeters = kWithRecordMeter;
57 mLabel = XO("Recording Meter");
58 mSection = wxT("RecordMeter");
59 } else if( mType == PlayMeterBarID ){
60 mWhichMeters = kWithPlayMeter;
61 mLabel = XO("Playback Meter");
62 mSection = wxT("PlayMeter");
63 } else {
64 mWhichMeters = kWithPlayMeter | kWithRecordMeter;
65 }
66 mSizer = NULL;
67 mPlayMeter = NULL;
68 mRecordMeter = NULL;
69}
70
72{
73}
74
76{
77 return MeterToolBars{
78 Get(project, true),
79 Get(project, false)
80 };
81}
82
84{
85 return ConstMeterToolBars{
86 Get(project, true),
87 Get(project, false)
88 };
89}
90
91MeterToolBar & MeterToolBar::Get(AudacityProject &project, bool forPlayMeterToolBar)
92{
93 auto& toolManager = ToolManager::Get(project);
94 auto toolBarID = forPlayMeterToolBar ? PlayMeterBarID : RecordMeterBarID;
95
96 return *static_cast<MeterToolBar*>(toolManager.GetToolBar(toolBarID));
97}
98
99const MeterToolBar & MeterToolBar::Get(const AudacityProject &project, bool forPlayMeterToolBar)
100{
101 return Get( const_cast<AudacityProject&>( project ), forPlayMeterToolBar );
102}
103
104void MeterToolBar::Create(wxWindow * parent)
105{
106 ToolBar::Create(parent);
107
108 UpdatePrefs();
109
110 // Simulate a size event to set initial meter placement/size
111 wxSizeEvent dummy;
112 OnSize(dummy);
113}
114
116{
117 MeterPanel::State playState{ false }, recordState{ false };
118
119 auto &projectAudioIO = ProjectAudioIO::Get( mProject );
120 if (mPlayMeter &&
121 projectAudioIO.GetPlaybackMeter() == mPlayMeter->GetMeter())
122 {
123 playState = mPlayMeter->SaveState();
124 projectAudioIO.SetPlaybackMeter( nullptr );
125 }
126
127 if (mRecordMeter &&
128 projectAudioIO.GetCaptureMeter() == mRecordMeter->GetMeter())
129 {
130 recordState = mRecordMeter->SaveState();
131 projectAudioIO.SetCaptureMeter( nullptr );
132 }
133
135
136 mPlayMeter->RestoreState(playState);
137 if( playState.mSaved ){
138 projectAudioIO.SetPlaybackMeter( mPlayMeter->GetMeter() );
139 }
140 mRecordMeter->RestoreState(recordState);
141 if( recordState.mSaved ){
142 projectAudioIO.SetCaptureMeter( mRecordMeter->GetMeter() );
143 }
144}
145
147{
148 SetBackgroundColour( theTheme.Colour( clrMedium ) );
149 Add((mSizer = safenew wxGridBagSizer()), 1, wxEXPAND);
150
152 //JKC: Record on left, playback on right. Left to right flow
153 //(maybe we should do it differently for Arabic language :-) )
155 this,
156 wxID_ANY,
157 true,
158 wxDefaultPosition,
159 wxSize( 260, 28 ) );
160 /* i18n-hint: (noun) The meter that shows the loudness of the audio being recorded.*/
161 mRecordMeter->SetName( XO("Record Meter"));
162 /* i18n-hint: (noun) The meter that shows the loudness of the audio being recorded.
163 This is the name used in screen reader software, where having 'Meter' first
164 apparently is helpful to partially sighted people. */
165 mRecordMeter->SetLabel( XO("Meter-Record") );
166 mSizer->Add( mRecordMeter, wxGBPosition( 0, 0 ), wxDefaultSpan, wxEXPAND );
167 }
168
171 this,
172 wxID_ANY,
173 false,
174 wxDefaultPosition,
175 wxSize( 260, 28 ) );
176 /* i18n-hint: (noun) The meter that shows the loudness of the audio playing.*/
177 mPlayMeter->SetName( XO("Play Meter"));
178 /* i18n-hint: (noun) The meter that shows the loudness of the audio playing.
179 This is the name used in screen reader software, where having 'Meter' first
180 apparently is helpful to partially sighted people. */
181 mPlayMeter->SetLabel( XO("Meter-Play"));
182 mSizer->Add( mPlayMeter, wxGBPosition( (mWhichMeters & kWithRecordMeter)?1:0, 0 ), wxDefaultSpan, wxEXPAND );
183 }
184
186}
187
189{
191
192 // Set label to pull in language change
193 SetLabel(XO("Meter"));
194
195 // Give base class a chance
197}
198
200{
201 if ( mPlayMeter )
203
204 if ( mRecordMeter )
206}
207
209{
210#if wxUSE_TOOLTIPS
211 if( mPlayMeter )
212 mPlayMeter->SetToolTip( XO("Playback Level") );
213 if( mRecordMeter )
214 mRecordMeter->SetToolTip( XO("Recording Level") );
215#endif
216}
217
218void MeterToolBar::OnSize( wxSizeEvent & event) //WXUNUSED(event) )
219{
220 event.Skip();
221 int width, height;
222
223 // We can be resized before populating...protect against it
224 if( !mSizer ) {
225 return;
226 }
227
228 // Update the layout
229 Layout();
230
231 // Get the usable area
232 wxSize sz = GetSizer()->GetSize();
233 width = sz.x; height = sz.y;
234
235 int nMeters =
236 ((mRecordMeter ==NULL) ? 0:1) +
237 ((mPlayMeter ==NULL) ? 0:1);
238
239 bool bHorizontal = ( width > height );
240 bool bEndToEnd = ( nMeters > 1 ) && wxMin( width, height ) < (60 * nMeters);
241
242 // Default location for second meter
243 wxGBPosition pos( 0, 0 );
244 // If 2 meters, share the height or width.
245 if( nMeters > 1 ){
246 if( bHorizontal ^ bEndToEnd ){
247 height /= nMeters;
248 pos = wxGBPosition( 1, 0 );
249 } else {
250 width /= nMeters;
251 pos = wxGBPosition( 0, 1 );
252 }
253 }
254
255 if( mRecordMeter ) {
256 mRecordMeter->SetMinSize( wxSize( width, height ));
257 }
258 if( mPlayMeter ) {
259 mPlayMeter->SetMinSize( wxSize( width, height));
260 mSizer->SetItemPosition( mPlayMeter, pos );
261 }
262
263 // And make it happen
264 Layout();
265 Fit();
266}
267
268bool MeterToolBar::Expose( bool show )
269{
270 auto &projectAudioIO = ProjectAudioIO::Get( mProject );
271 if( show ) {
272 if( mPlayMeter ) {
273 projectAudioIO.SetPlaybackMeter( mPlayMeter->GetMeter() );
274 }
275
276 if( mRecordMeter ) {
277 projectAudioIO.SetCaptureMeter( mRecordMeter->GetMeter() );
278 }
279 } else {
280 if( mPlayMeter &&
281 projectAudioIO.GetPlaybackMeter() == mPlayMeter->GetMeter() ) {
282 projectAudioIO.SetPlaybackMeter( nullptr );
283 }
284
285 if( mRecordMeter &&
286 projectAudioIO.GetCaptureMeter() == mRecordMeter->GetMeter() ) {
287 projectAudioIO.SetCaptureMeter( nullptr );
288 }
289 }
290
291 return ToolBar::Expose( show );
292}
293
294// The meter's sizing code does not take account of the resizer
295// Hence after docking we need to enlarge the bar (using fit)
296// so that the resizer can be reached.
297void MeterToolBar::SetDocked(ToolDock *dock, bool pushed) {
298 ToolBar::SetDocked(dock, pushed);
299 Fit();
300}
301
303{
306}
307
309{
312}
313
315{
316 if (adj < 0) {
317 mPlayMeter->Decrease(-adj);
318 }
319 else {
320 mPlayMeter->Increase(adj);
321 }
322
324}
325
327{
328 if (adj < 0) {
329 mRecordMeter->Decrease(-adj);
330 }
331 else {
333 }
334
336}
337
339 []( AudacityProject &project ){
340 return ToolBar::Holder{
341 safenew MeterToolBar{ project, RecordMeterBarID } }; }
342};
344 []( AudacityProject &project ){
345 return ToolBar::Holder{
346 safenew MeterToolBar{ project, PlayMeterBarID } }; }
347};
349 []( AudacityProject &project ){
350 return ToolBar::Holder{
351 safenew MeterToolBar{ project, MeterBarID } }; }
352};
353
354#include "ToolManager.h"
355
356namespace {
358 /* i18n-hint: Clicking this menu item shows the toolbar
359 with the recording level meters */
360 RecordMeterBarID, wxT("ShowRecordMeterTB"), XXO("&Recording Meter Toolbar"),
361 {}, { MeterBarID }
362};
364 /* i18n-hint: Clicking this menu item shows the toolbar
365 with the playback level meter */
366 PlayMeterBarID, wxT("ShowPlayMeterTB"), XXO("&Playback Meter Toolbar"),
367 {}, { MeterBarID }
368};
369//AttachedToolBarMenuItem sAttachment3{
370// /* --i18nhint: Clicking this menu item shows the toolbar
371// which has sound level meters */
372// MeterBarID, wxT("ShowMeterTB"), XXO("Co&mbined Meter Toolbar"),
373// { Registry::OrderingHint::After, "ShowPlayMeterTB" },
374// { PlayMeterBarID, RecordMeterBarID }
375//};
376}
END_EVENT_TABLE()
#define XXO(s)
Definition: Internat.h:44
#define XO(s)
Definition: Internat.h:31
#define safenew
Definition: MemoryX.h:10
static RegisteredToolbarFactory factory2
static RegisteredToolbarFactory factory3
IMPLEMENT_CLASS(MeterToolBar, ToolBar)
static RegisteredToolbarFactory factory1
std::vector< std::reference_wrapper< const MeterToolBar > > ConstMeterToolBars
Definition: MeterToolBar.h:31
std::vector< std::reference_wrapper< MeterToolBar > > MeterToolBars
Definition: MeterToolBar.h:30
const int kWithRecordMeter
Definition: MeterToolBar.h:34
const int kWithPlayMeter
Definition: MeterToolBar.h:35
THEME_API Theme theTheme
Definition: Theme.cpp:82
@ RecordMeterBarID
Definition: ToolBar.h:75
@ PlayMeterBarID
Definition: ToolBar.h:76
@ MeterBarID
Definition: ToolBar.h:74
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
AudioIO uses this to send sample buffers for real-time display updates.
Definition: Meter.h:16
std::shared_ptr< Meter > GetMeter() const
MeterPanel is a panel that paints the meter used for monitoring or playback.
Definition: MeterPanel.h:104
bool ShowDialog()
Definition: MeterPanel.cpp:936
void Decrease(float steps)
Definition: MeterPanel.cpp:962
void Increase(float steps)
Definition: MeterPanel.cpp:951
void UpdateSliderControl()
Definition: MeterPanel.cpp:492
State SaveState()
void RestoreState(const State &state)
A ToolBar that holds the VU Meter.
Definition: MeterToolBar.h:37
virtual ~MeterToolBar()
void UpdatePrefs() override
void AdjustOutputGain(int adj)
void RegenerateTooltips() override
void ShowInputGainDialog()
static MeterToolBars GetToolBars(AudacityProject &project)
void ShowOutputGainDialog()
void OnSize(wxSizeEvent &event)
void AdjustInputGain(int adj)
void ReCreateButtons() override
void Create(wxWindow *parent) override
void Populate() override
MeterPanel * mPlayMeter
Definition: MeterToolBar.h:81
MeterPanel * mRecordMeter
Definition: MeterToolBar.h:82
void UpdateControls()
static MeterToolBar & Get(AudacityProject &project, bool forPlayMeterToolBar)
virtual void SetDocked(ToolDock *dock, bool pushed) override
bool Expose(bool show) override
wxGridBagSizer * mSizer
Definition: MeterToolBar.h:80
static ProjectAudioIO & Get(AudacityProject &project)
wxColour & Colour(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:247
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:686
virtual void SetDocked(ToolDock *dock, bool pushed)
Definition: ToolBar.cpp:638
virtual void ReCreateButtons()
Definition: ToolBar.cpp:516
void SetLabel(const wxString &label) override
Definition: ToolBar.cpp:398
virtual bool Expose(bool show=true)
Definition: ToolBar.cpp:444
wxBoxSizer * GetSizer()
Definition: ToolBar.cpp:678
void UpdatePrefs() override
Definition: ToolBar.cpp:605
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:475
wxWindowPtr< ToolBar > Holder
Definition: ToolBar.h:102
A dynamic panel where a ToolBar can be docked.
Definition: ToolDock.h:290
static ToolManager & Get(AudacityProject &project)
void SetToolTip(const TranslatableString &toolTip)
void SetName(const TranslatableString &name)
void SetLabel(const TranslatableString &label)
AttachedToolBarMenuItem sAttachment2
AttachedToolBarMenuItem sAttachment1