forked from tenacityteam/tenacity-legacy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMeterToolBar.cpp
297 lines (244 loc) · 8.39 KB
/
MeterToolBar.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/**********************************************************************
Audacity: A Digital Audio Editor
MeterToolBar.cpp
Dominic Mazzoni
Leland Lucius
See MeterToolBar.h for details
*******************************************************************//*!
\class MeterToolBar
\brief A ToolBar that holds the VU Meter
*//*******************************************************************/
#include "MeterToolBar.h"
// For compilers that support precompilation, includes "wx/wx.h".
#include <wx/wxprec.h>
#include <wx/setup.h> // for wxUSE_* macros
#ifndef WX_PRECOMP
#include <wx/event.h>
#include <wx/intl.h>
#include <wx/tooltip.h>
#endif
#include <wx/gbsizer.h>
#include "../AllThemeResources.h"
#include "../ProjectAudioIO.h"
#include "../widgets/Meter.h"
IMPLEMENT_CLASS(MeterToolBar, ToolBar);
////////////////////////////////////////////////////////////
/// Methods for MeterToolBar
////////////////////////////////////////////////////////////
BEGIN_EVENT_TABLE( MeterToolBar, ToolBar )
EVT_SIZE( MeterToolBar::OnSize )
END_EVENT_TABLE()
//Standard constructor
MeterToolBar::MeterToolBar(AudacityProject &project, int type)
: ToolBar(project, type, XO("Combined Meter"), wxT("CombinedMeter"), true)
{
if( mType == RecordMeterBarID ){
mWhichMeters = kWithRecordMeter;
mLabel = XO("Recording Meter");
mSection = wxT("RecordMeter");
} else if( mType == PlayMeterBarID ){
mWhichMeters = kWithPlayMeter;
mLabel = XO("Playback Meter");
mSection = wxT("PlayMeter");
} else {
mWhichMeters = kWithPlayMeter | kWithRecordMeter;
}
mSizer = NULL;
mPlayMeter = NULL;
mRecordMeter = NULL;
}
MeterToolBar::~MeterToolBar()
{
}
void MeterToolBar::Create(wxWindow * parent)
{
ToolBar::Create(parent);
UpdatePrefs();
// Simulate a size event to set initial meter placement/size
wxSizeEvent dummy;
OnSize(dummy);
}
void MeterToolBar::ReCreateButtons()
{
MeterPanel::State playState{ false }, recordState{ false };
auto &projectAudioIO = ProjectAudioIO::Get( mProject );
if (mPlayMeter && projectAudioIO.GetPlaybackMeter() == mPlayMeter)
{
playState = mPlayMeter->SaveState();
projectAudioIO.SetPlaybackMeter( nullptr );
}
if (mRecordMeter && projectAudioIO.GetCaptureMeter() == mRecordMeter)
{
recordState = mRecordMeter->SaveState();
projectAudioIO.SetCaptureMeter( nullptr );
}
ToolBar::ReCreateButtons();
mPlayMeter->RestoreState(playState);
if( playState.mSaved ){
projectAudioIO.SetPlaybackMeter( mPlayMeter );
}
mRecordMeter->RestoreState(recordState);
if( recordState.mSaved ){
projectAudioIO.SetCaptureMeter( mRecordMeter );
}
}
void MeterToolBar::Populate()
{
SetBackgroundColour( theTheme.Colour( clrMedium ) );
Add((mSizer = safenew wxGridBagSizer()), 1, wxEXPAND);
if( mWhichMeters & kWithRecordMeter ){
//JKC: Record on left, playback on right. Left to right flow
//(maybe we should do it differently for Arabic language :-) )
mRecordMeter = safenew MeterPanel( &mProject,
this,
wxID_ANY,
true,
wxDefaultPosition,
wxSize( 260, 28 ) );
/* i18n-hint: (noun) The meter that shows the loudness of the audio being recorded.*/
mRecordMeter->SetName( XO("Record Meter"));
/* i18n-hint: (noun) The meter that shows the loudness of the audio being recorded.
This is the name used in screen reader software, where having 'Meter' first
apparently is helpful to partially sighted people. */
mRecordMeter->SetLabel( XO("Meter-Record") );
mSizer->Add( mRecordMeter, wxGBPosition( 0, 0 ), wxDefaultSpan, wxEXPAND );
}
if( mWhichMeters & kWithPlayMeter ){
mPlayMeter = safenew MeterPanel( &mProject,
this,
wxID_ANY,
false,
wxDefaultPosition,
wxSize( 260, 28 ) );
/* i18n-hint: (noun) The meter that shows the loudness of the audio playing.*/
mPlayMeter->SetName( XO("Play Meter"));
/* i18n-hint: (noun) The meter that shows the loudness of the audio playing.
This is the name used in screen reader software, where having 'Meter' first
apparently is helpful to partially sighted people. */
mPlayMeter->SetLabel( XO("Meter-Play"));
mSizer->Add( mPlayMeter, wxGBPosition( (mWhichMeters & kWithRecordMeter)?1:0, 0 ), wxDefaultSpan, wxEXPAND );
}
RegenerateTooltips();
}
void MeterToolBar::UpdatePrefs()
{
RegenerateTooltips();
// Set label to pull in language change
SetLabel(XO("Meter"));
// Give base class a chance
ToolBar::UpdatePrefs();
}
void MeterToolBar::RegenerateTooltips()
{
#if wxUSE_TOOLTIPS
if( mPlayMeter )
mPlayMeter->SetToolTip( XO("Playback Level") );
if( mRecordMeter )
mRecordMeter->SetToolTip( XO("Recording Level") );
#endif
}
void MeterToolBar::OnSize( wxSizeEvent & event) //WXUNUSED(event) )
{
event.Skip();
int width, height;
// We can be resized before populating...protect against it
if( !mSizer ) {
return;
}
// Update the layout
Layout();
// Get the usable area
wxSize sz = GetSizer()->GetSize();
width = sz.x; height = sz.y;
int nMeters =
((mRecordMeter ==NULL) ? 0:1) +
((mPlayMeter ==NULL) ? 0:1);
bool bHorizontal = ( width > height );
bool bEndToEnd = ( nMeters > 1 ) && wxMin( width, height ) < (60 * nMeters);
// Default location for second meter
wxGBPosition pos( 0, 0 );
// If 2 meters, share the height or width.
if( nMeters > 1 ){
if( bHorizontal ^ bEndToEnd ){
height /= nMeters;
pos = wxGBPosition( 1, 0 );
} else {
width /= nMeters;
pos = wxGBPosition( 0, 1 );
}
}
if( mRecordMeter ) {
mRecordMeter->SetMinSize( wxSize( width, height ));
}
if( mPlayMeter ) {
mPlayMeter->SetMinSize( wxSize( width, height));
mSizer->SetItemPosition( mPlayMeter, pos );
}
// And make it happen
Layout();
Fit();
}
bool MeterToolBar::Expose( bool show )
{
auto &projectAudioIO = ProjectAudioIO::Get( mProject );
if( show ) {
if( mPlayMeter ) {
projectAudioIO.SetPlaybackMeter( mPlayMeter );
}
if( mRecordMeter ) {
projectAudioIO.SetCaptureMeter( mRecordMeter );
}
} else {
if( mPlayMeter && projectAudioIO.GetPlaybackMeter() == mPlayMeter ) {
projectAudioIO.SetPlaybackMeter( nullptr );
}
if( mRecordMeter && projectAudioIO.GetCaptureMeter() == mRecordMeter ) {
projectAudioIO.SetCaptureMeter( nullptr );
}
}
return ToolBar::Expose( show );
}
// The meter's sizing code does not take account of the resizer
// Hence after docking we need to enlarge the bar (using fit)
// so that the resizer can be reached.
void MeterToolBar::SetDocked(ToolDock *dock, bool pushed) {
ToolBar::SetDocked(dock, pushed);
Fit();
}
static RegisteredToolbarFactory factory1{ RecordMeterBarID,
[]( AudacityProject &project ){
return ToolBar::Holder{
safenew MeterToolBar{ project, RecordMeterBarID } }; }
};
static RegisteredToolbarFactory factory2{ PlayMeterBarID,
[]( AudacityProject &project ){
return ToolBar::Holder{
safenew MeterToolBar{ project, PlayMeterBarID } }; }
};
static RegisteredToolbarFactory factory3{ MeterBarID,
[]( AudacityProject &project ){
return ToolBar::Holder{
safenew MeterToolBar{ project, MeterBarID } }; }
};
#include "ToolManager.h"
namespace {
AttachedToolBarMenuItem sAttachment1{
/* i18n-hint: Clicking this menu item shows the toolbar
with the recording level meters */
RecordMeterBarID, wxT("ShowRecordMeterTB"), XXO("&Recording Meter Toolbar"),
{}, { MeterBarID }
};
AttachedToolBarMenuItem sAttachment2{
/* i18n-hint: Clicking this menu item shows the toolbar
with the playback level meter */
PlayMeterBarID, wxT("ShowPlayMeterTB"), XXO("&Playback Meter Toolbar"),
{}, { MeterBarID }
};
//AttachedToolBarMenuItem sAttachment3{
// /* --i18nhint: Clicking this menu item shows the toolbar
// which has sound level meters */
// MeterBarID, wxT("ShowMeterTB"), XXO("Co&mbined Meter Toolbar"),
// { Registry::OrderingHint::After, "ShowPlayMeterTB" },
// { PlayMeterBarID, RecordMeterBarID }
//};
}