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  MeterPanel::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 
MeterPanel * mRecordMeter
Definition: MeterToolBar.h:62
A ToolBar that holds the VU Meter.
Definition: MeterToolBar.h:32
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:209
AudacityProject * mProject
Definition: MeterToolBar.h:58
virtual void UpdatePrefs()
Definition: ToolBar.cpp:535
void UpdatePrefs() override
void SetLabel(const wxString &label) override
Definition: ToolBar.cpp:374
const int kWithRecordMeter
Definition: MeterToolBar.h:29
wxBoxSizer * GetSizer()
Definition: ToolBar.cpp:603
virtual void ReCreateButtons()
Definition: ToolBar.cpp:459
MeterPanel * mPlayMeter
Definition: MeterToolBar.h:61
#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:411
wxSize GetDockedSize() override
void RegenerateTooltips() override
MeterPanel is a panel that paints the meter used for monitoring or playback.
Definition: Meter.h:97
#define safenew
Definition: Audacity.h:230
wxGridBagSizer * mSizer
Definition: MeterToolBar.h:60
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
virtual ~MeterToolBar()
MeterPanel * GetCaptureMeter()
Definition: Project.cpp:5097
void Create(wxWindow *parent) override
const int kWithPlayMeter
Definition: MeterToolBar.h:30
void UpdatePrefs()
Definition: Meter.cpp:340
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:611
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:438
void SetCaptureMeter(MeterPanel *capture)
Definition: Project.cpp:5102
void ReCreateButtons() override
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void OnSize(wxSizeEvent &event)
void RestoreState(const State &state)
Definition: Meter.cpp:1834
void Populate() override
MeterPanel * GetPlaybackMeter()
Definition: Project.cpp:5083
void SetPlaybackMeter(MeterPanel *playback)
Definition: Project.cpp:5088
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1225
END_EVENT_TABLE()
IMPLEMENT_CLASS(MeterToolBar, ToolBar)
State SaveState()
Definition: Meter.cpp:1829
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed...
Definition: ToolBar.h:87