Audacity  2.2.2
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 #include "../Audacity.h"
21 
22 // For compilers that support precompilation, includes "wx/wx.h".
23 #include <wx/wxprec.h>
24 
25 #ifndef WX_PRECOMP
26 #include <wx/event.h>
27 #include <wx/intl.h>
28 #include <wx/tooltip.h>
29 #endif
30 
31 #include <wx/gbsizer.h>
32 
33 #include "MeterToolBar.h"
34 #include "../AllThemeResources.h"
35 #include "../AudioIO.h"
36 #include "../Project.h"
37 #include "../widgets/Meter.h"
38 
40 
44 
45 BEGIN_EVENT_TABLE( MeterToolBar, ToolBar )
46  EVT_SIZE( MeterToolBar::OnSize )
48 
49 //Standard contructor
51 : ToolBar(type, _("Combined Meter"), wxT("CombinedMeter"), true)
52 {
53  mProject = project;
54 
55  if( mType == RecordMeterBarID ){
56  mWhichMeters = kWithRecordMeter;
57  mLabel = _("Recording Meter");
58  mSection = wxT("RecordMeter");
59  } else if( mType == PlayMeterBarID ){
60  mWhichMeters = kWithPlayMeter;
61  mLabel = _("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 
75 void MeterToolBar::Create(wxWindow * parent)
76 {
77  ToolBar::Create(parent);
78 
79  // Simulate a size event to set initial meter placement/size
80  wxSizeEvent dummy;
81  OnSize(dummy);
82 }
83 
85 {
86  Meter::State playState{ false }, recordState{ false };
87 
89  {
90  playState = mPlayMeter->SaveState();
91  mProject->SetPlaybackMeter( NULL );
92  }
93 
95  {
96  recordState = mRecordMeter->SaveState();
97  mProject->SetCaptureMeter( NULL );
98  }
99 
101 
102  mPlayMeter->RestoreState(playState);
103  if( playState.mSaved ){
105  }
106  mRecordMeter->RestoreState(recordState);
107  if( recordState.mSaved ){
109  }
110 }
111 
113 {
114  SetBackgroundColour( theTheme.Colour( clrMedium ) );
115  wxASSERT(mProject); // to justify safenew
116  Add((mSizer = safenew wxGridBagSizer()), 1, wxEXPAND);
117 
119  //JKC: Record on left, playback on right. Left to right flow
120  //(maybe we should do it differently for Arabic language :-) )
122  this,
123  wxID_ANY,
124  true,
125  wxDefaultPosition,
126  wxSize( 260, 28 ) );
127  /* i18n-hint: (noun) The meter that shows the loudness of the audio being recorded.*/
128  mRecordMeter->SetName( _("Record Meter"));
129  /* i18n-hint: (noun) The meter that shows the loudness of the audio being recorded.
130  This is the name used in screen reader software, where having 'Meter' first
131  apparently is helpful to partially sighted people. */
132  mRecordMeter->SetLabel( _("Meter-Record") );
133  mSizer->Add( mRecordMeter, wxGBPosition( 0, 0 ), wxDefaultSpan, wxEXPAND );
134  }
135 
138  this,
139  wxID_ANY,
140  false,
141  wxDefaultPosition,
142  wxSize( 260, 28 ) );
143  /* i18n-hint: (noun) The meter that shows the loudness of the audio playing.*/
144  mPlayMeter->SetName( _("Play Meter"));
145  /* i18n-hint: (noun) The meter that shows the loudness of the audio playing.
146  This is the name used in screen reader software, where having 'Meter' first
147  apparently is helpful to partially sighted people. */
148  mPlayMeter->SetLabel( _("Meter-Play"));
149  mSizer->Add( mPlayMeter, wxGBPosition( (mWhichMeters & kWithRecordMeter)?1:0, 0 ), wxDefaultSpan, wxEXPAND );
150  }
151 
153 }
154 
156 {
157  if( mPlayMeter )
158  {
160  mPlayMeter->Refresh();
161  }
162 
163  if( mRecordMeter )
164  {
166  mRecordMeter->Refresh();
167  }
168 
170 
171  // Set label to pull in language change
172  SetLabel(_("Meter"));
173 
174  // Give base class a chance
176 
177 
178 }
179 
181 {
182 #if wxUSE_TOOLTIPS
183  if( mPlayMeter )
184  mPlayMeter->SetToolTip( _("Playback Level") );
185  if( mRecordMeter )
186  mRecordMeter->SetToolTip( _("Recording Level") );
187 #endif
188 }
189 
190 void MeterToolBar::OnSize( wxSizeEvent & event) //WXUNUSED(event) )
191 {
192  event.Skip();
193  int width, height;
194 
195  // We can be resized before populating...protect against it
196  if( !mSizer ) {
197  return;
198  }
199 
200  // Update the layout
201  Layout();
202 
203  // Get the usable area
204  wxSize sz = GetSizer()->GetSize();
205  width = sz.x; height = sz.y;
206 
207  int nMeters =
208  ((mRecordMeter ==NULL) ? 0:1) +
209  ((mPlayMeter ==NULL) ? 0:1);
210 
211  bool bHorizontal = ( width > height );
212  bool bEndToEnd = ( nMeters > 1 ) && wxMin( width, height ) < (60 * nMeters);
213 
214  // Default location for second meter
215  wxGBPosition pos( 0, 0 );
216  // If 2 meters, share the height or width.
217  if( nMeters > 1 ){
218  if( bHorizontal ^ bEndToEnd ){
219  height /= nMeters;
220  pos = wxGBPosition( 1, 0 );
221  } else {
222  width /= nMeters;
223  pos = wxGBPosition( 0, 1 );
224  }
225  }
226 
227  if( mRecordMeter ) {
228  mRecordMeter->SetMinSize( wxSize( width, height ));
229  }
230  if( mPlayMeter ) {
231  mPlayMeter->SetMinSize( wxSize( width, height));
232  mSizer->SetItemPosition( mPlayMeter, pos );
233  }
234 
235  // And make it happen
236  Layout();
237 }
238 
239 bool MeterToolBar::Expose( bool show )
240 {
241  if( show ) {
242  if( mPlayMeter ) {
244  }
245 
246  if( mRecordMeter ) {
248  }
249  } else {
251  mProject->SetPlaybackMeter( NULL );
252  }
253 
255  mProject->SetCaptureMeter( NULL );
256  }
257  }
258 
259  return ToolBar::Expose( show );
260 }
261 
263 {
264  const int tbs = toolbarSingle + toolbarGap;
265  wxSize sz = GetSize();
266  wxSize sz2 = GetMinSize();
267  sz.x = wxMax( sz.x, sz2.x );
268  sz.y = wxMax( sz.y, sz2.y );
269  // 50 is the size where we switch from expanded to compact.
270  if( sz.y < 50 )
271  sz.y = tbs-1;
272  else
273  sz.y = 2 * tbs -1;
274  return sz;
275 }
276 
A ToolBar that holds the VU Meter.
Definition: MeterToolBar.h:32
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:215
AudacityProject * mProject
Definition: MeterToolBar.h:58
virtual void UpdatePrefs()
Definition: ToolBar.cpp:540
Meter * GetPlaybackMeter()
Definition: Project.cpp:4874
void UpdatePrefs() override
void UpdatePrefs()
Definition: Meter.cpp:378
const int kWithRecordMeter
Definition: MeterToolBar.h:29
void SetCaptureMeter(Meter *capture)
Definition: Project.cpp:4893
wxBoxSizer * GetSizer()
Definition: ToolBar.cpp:608
virtual void ReCreateButtons()
Definition: ToolBar.cpp:464
VU Meter, for displaying recording/playback level.
Definition: Meter.h:88
#define toolbarGap
Definition: ToolBar.h:59
bool Expose(bool show) override
#define toolbarSingle
Definition: ToolBar.h:54
virtual bool Expose(bool show=true)
Definition: ToolBar.cpp:416
wxSize GetDockedSize() override
void RegenerateTooltips() override
void RestoreState(const State &state)
Definition: Meter.cpp:1871
#define safenew
Definition: Audacity.h:223
wxGridBagSizer * mSizer
Definition: MeterToolBar.h:60
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:161
virtual ~MeterToolBar()
void Create(wxWindow *parent) override
const int kWithPlayMeter
Definition: MeterToolBar.h:30
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:616
State SaveState()
Definition: Meter.cpp:1866
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:443
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
void ReCreateButtons() override
void OnSize(wxSizeEvent &event)
void SetLabel(const wxString &label)
Definition: ToolBar.cpp:379
Meter * GetCaptureMeter()
Definition: Project.cpp:4888
void Populate() override
void SetPlaybackMeter(Meter *playback)
Definition: Project.cpp:4879
Meter * mPlayMeter
Definition: MeterToolBar.h:61
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1214
END_EVENT_TABLE()
IMPLEMENT_CLASS(MeterToolBar, ToolBar)
Meter * mRecordMeter
Definition: MeterToolBar.h:62
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed...
Definition: ToolBar.h:87