Audacity  2.3.1
MixerToolBar.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  MixerToolBar.cpp
6 
7  Dominic Mazzoni
8 
9 *******************************************************************//*******************************************************************/
15 
16 
17 #include "../Audacity.h"
18 
19 // For compilers that support precompilation, includes "wx/wx.h".
20 #include <wx/wxprec.h>
21 
22 #ifndef WX_PRECOMP
23 #include <wx/choice.h>
24 #include <wx/event.h>
25 #include <wx/intl.h>
26 #include <wx/settings.h>
27 #include <wx/sizer.h>
28 #include <wx/statbmp.h>
29 #include <wx/tooltip.h>
30 #endif
31 
32 #include "MixerToolBar.h"
33 
34 #include "../AColor.h"
35 #include "../AllThemeResources.h"
36 #include "../AudioIO.h"
37 #include "../ImageManipulation.h"
38 #include "../Prefs.h"
39 #include "../Project.h"
40 #include "../Theme.h"
41 #include "../widgets/ASlider.h"
42 #include "../widgets/Grabber.h"
43 
45 
49 
50 BEGIN_EVENT_TABLE(MixerToolBar, ToolBar)
51  EVT_PAINT(MixerToolBar::OnPaint)
52  EVT_SLIDER(wxID_ANY, MixerToolBar::SetMixer)
53  EVT_CHOICE(wxID_ANY, MixerToolBar::SetMixer)
54  EVT_COMMAND(wxID_ANY, EVT_CAPTURE_KEY, MixerToolBar::OnCaptureKey)
56 
57 //Standard contructor
59 : ToolBar(MixerBarID, _("Mixer"), wxT("Mixer"), true)
60 {
61  mInputSliderVolume = 0.0;
62  mOutputSliderVolume = 0.0;
63 }
64 
66 {
67 }
68 
69 void MixerToolBar::Create(wxWindow *parent)
70 {
71  ToolBar::Create(parent);
72 }
73 
75 {
76  SetBackgroundColour( theTheme.Colour( clrMedium ) );
77  // Recording icon and slider
79  wxID_ANY,
80  theTheme.Bitmap(bmpMic)), 0, wxALIGN_CENTER);
81  mInputSlider = safenew ASlider(this, wxID_ANY, _("Recording Volume"),
82  wxDefaultPosition, wxSize(130, 25),
83  ASlider::Options{}.Line( 0.1f ).Page( 2.0f ));
84  Add(mInputSlider, 1, wxALIGN_CENTER);
85  mInputSlider->SetSizeHints(wxSize(75, 25), wxSize(1000, 25));
86 
87  // Playback icon and slider
89  wxID_ANY,
90  theTheme.Bitmap(bmpSpeaker)), 0, wxALIGN_CENTER);
91  mOutputSlider = safenew ASlider(this, wxID_ANY, _("Playback Volume"),
92  wxDefaultPosition, wxSize(130, 25),
93  ASlider::Options{}.Line( 0.1f ).Page( 2.0f ));
94  Add(mOutputSlider, 1, wxALIGN_CENTER);
95  mOutputSlider->SetSizeHints(wxSize(75, 25), wxSize(1000, 25));
96 
97  // this bit taken from SelectionBar::Populate()
98  mInputSlider->Bind(wxEVT_SET_FOCUS,
100  this);
101  mInputSlider->Bind(wxEVT_KILL_FOCUS,
103  this);
104  mOutputSlider->Bind(wxEVT_SET_FOCUS,
106  this);
107  mOutputSlider->Bind(wxEVT_KILL_FOCUS,
109  this);
110  // Show or hide the input slider based on whether it works
112 
113  UpdateControls();
114 
115  // Add a little space
116  Add(2, -1);
117 }
118 
119 //Also from SelectionBar;
120 void MixerToolBar::OnFocus(wxFocusEvent &event)
121 {
122  if (event.GetEventType() == wxEVT_KILL_FOCUS) {
124  }
125  else {
127  }
128 
129  Refresh(false);
130 
131  event.Skip();
132 }
133 
134 void MixerToolBar::OnCaptureKey(wxCommandEvent &event)
135 {
136  wxKeyEvent *kevent = (wxKeyEvent *)event.GetEventObject();
137  int keyCode = kevent->GetKeyCode();
138 
139  // Pass LEFT/RIGHT/UP/DOWN/PAGEUP/PAGEDOWN through for input/output sliders
140  if (FindFocus() == mInputSlider && (keyCode == WXK_LEFT || keyCode == WXK_RIGHT
141  || keyCode == WXK_UP || keyCode == WXK_DOWN
142  || keyCode == WXK_PAGEUP || keyCode == WXK_PAGEDOWN)) {
143  return;
144  }
145  if (FindFocus() == mOutputSlider && (keyCode == WXK_LEFT || keyCode == WXK_RIGHT
146  || keyCode == WXK_UP || keyCode == WXK_DOWN
147  || keyCode == WXK_PAGEUP || keyCode == WXK_PAGEDOWN)) {
148  return;
149  }
150 
151  event.Skip();
152 
153  return;
154 }
155 
157 {
158 #if USE_PORTMIXER
159  float inputVolume;
160  float playbackVolume;
161  int inputSource;
162 
163  // Reset the selected source
164  gAudioIO->GetMixer(&inputSource, &inputVolume, &playbackVolume);
165 
166  // Show or hide the input slider based on whether it works
168  Layout();
169 
170 // This code is from before the mixer toolbar was resizable.
171 // Now that it is resizable we trust the user to resize the mixer toolbar themselves.
172 #if 0
173  wxSize oldSize( GetSize() );
174  // Layout the toolbar
175  Layout();
176  // Resize the toolbar to fit the contents
177  //Fit();
178  // And make that size the minimum
179  wxSize newMinSize( wxWindow::GetSizer()->GetMinSize() );
180  SetMinSize( newMinSize );
181  // IF size must increase, do so.
182  if( newMinSize.x > oldSize.x ){
183  SetSize( newMinSize );
184  // Notify someone that we've changed our size
185  Updated();
186  }
187  // ELSE preserve original size.
188  else
189  SetSize( oldSize );
190 #endif
191 #endif
192 
193  // Set label to pull in language change
194  SetLabel(_("Mixer"));
195 
197 
198  // Give base class a chance
200 }
201 
203 {
204 #if USE_PORTMIXER
205  float inputVolume;
206  float playbackVolume;
207  int inputSource;
208 
209  // Show or hide the input slider based on whether it works
211 
212  gAudioIO->GetMixer(&inputSource, &inputVolume, &playbackVolume);
213 
214  if (mOutputSlider->Get() != playbackVolume) {
215  mOutputSlider->Set(playbackVolume);
216  mOutputSliderVolume = playbackVolume;
217  SetToolTips();
218  }
219 
220  if (mInputSlider->Get() != inputVolume) {
221  mInputSlider->Set(inputVolume);
222  mInputSliderVolume = inputVolume;
223  SetToolTips();
224  }
225 #endif // USE_PORTMIXER
226 }
227 
228 void MixerToolBar::SetMixer(wxCommandEvent & WXUNUSED(event))
229 {
230 #if USE_PORTMIXER
231  float inputVolume = mInputSlider->Get();
232  float outputVolume = mOutputSlider->Get();
233  float oldIn, oldOut;
234  int inputSource;
235 
236  gAudioIO->GetMixer(&inputSource, &oldIn, &oldOut);
237  gAudioIO->SetMixer(inputSource, inputVolume, outputVolume);
238  mOutputSliderVolume = outputVolume;
239  mInputSliderVolume = inputVolume;
240  SetToolTips();
241 #endif // USE_PORTMIXER
242 }
243 
245 {
247  wxCommandEvent e;
248  SetMixer(e);
249  UpdateControls();
250 }
251 
253 {
255  wxCommandEvent e;
256  SetMixer(e);
257  UpdateControls();
258 }
259 
261 {
262  if (adj < 0) {
263  mOutputSlider->Decrease(-adj);
264  }
265  else {
266  mOutputSlider->Increase(adj);
267  }
268  wxCommandEvent e;
269  SetMixer(e);
270  UpdateControls();
271 }
272 
274 {
275  if (adj < 0) {
276  mInputSlider->Decrease(-adj);
277  }
278  else {
279  mInputSlider->Increase(adj);
280  }
281  wxCommandEvent e;
282  SetMixer(e);
283  UpdateControls();
284 }
285 
287 {
288  if (mInputSlider->IsEnabled()) {
289  mInputSlider->SetToolTipTemplate(_("Recording Volume: %.2f"));
290  }
291  else {
292  mInputSlider->SetToolTipTemplate(_("Recording Volume (Unavailable; use system mixer.)"));
293  }
294 
295  if (mOutputSlider->IsEnabled()) {
296  wxString format;
298  format = _("Playback Volume: %s (emulated)");
299  else
300  format = _("Playback Volume: %s");
301 
303  wxString::Format( format, "%.2f" ) );
304  }
305  else {
306  mOutputSlider->SetToolTipTemplate(_("Playback Volume (Unavailable; use system mixer.)"));
307  }
308 }
void Populate() override
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:209
bool OutputMixerEmulated()
Find out if the output level control is being emulated via software attenuation.
Definition: AudioIO.cpp:1213
virtual void UpdatePrefs()
Definition: ToolBar.cpp:556
void AdjustInputGain(int adj)
void SetLabel(const wxString &label) override
Definition: ToolBar.cpp:381
ASlider * mInputSlider
Definition: MixerToolBar.h:66
static void CaptureKeyboard(wxWindow *handler)
Definition: Project.cpp:5336
float mInputSliderVolume
Definition: MixerToolBar.h:55
float Get(bool convert=true)
Definition: ASlider.cpp:1591
bool IsEnabled() const
Definition: ASlider.cpp:1633
void OnCaptureKey(wxCommandEvent &event)
float mOutputSliderVolume
Definition: MixerToolBar.h:59
void SetToolTipTemplate(const wxString &tip)
Definition: ASlider.cpp:1586
ASlider * mOutputSlider
Definition: MixerToolBar.h:67
void UpdatePrefs() override
bool InputMixerWorks()
Find out if the input hardware level control is available.
Definition: AudioIO.cpp:1208
#define safenew
Definition: Audacity.h:230
Options & Page(float p)
Definition: ASlider.h:268
wxBitmap & Bitmap(int iIndex)
Definition: Theme.cpp:1244
IMPLEMENT_CLASS(MixerToolBar, ToolBar)
void GetMixer(int *inputSource, float *inputVolume, float *playbackVolume)
Definition: AudioIO.cpp:1177
int format
Definition: ExportPCM.cpp:56
void AdjustOutputGain(int adj)
void ShowOutputGainDialog()
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:631
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:445
void RegenerateTooltips() override
Definition: MixerToolBar.h:55
virtual ~MixerToolBar()
void Set(float value)
Definition: ASlider.cpp:1596
void ShowInputGainDialog()
Options & Line(float l)
Definition: ASlider.h:267
bool Enable(bool enable=true) override
Definition: ASlider.cpp:1621
void Updated()
Definition: ToolBar.cpp:612
void SetMixer(wxCommandEvent &event)
static void ReleaseKeyboard(wxWindow *handler)
Definition: Project.cpp:5347
void SetMixer(int inputSource)
Definition: AudioIO.cpp:1147
_("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 UpdateControls()
bool ShowDialog(wxPoint pos=wxPoint(-1,-1))
Definition: ASlider.cpp:1611
AudioIO * gAudioIO
Definition: AudioIO.cpp:491
void Create(wxWindow *parent) override
ASlider is a custom slider, allowing for a slicker look and feel.
Definition: ASlider.h:243
A widget for bitmaps which ignores the erase event for flicker-free use.
Definition: Grabber.h:148
void Increase(float steps)
Definition: ASlider.cpp:1601
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1225
END_EVENT_TABLE()
Functions for doing the mixdown of the tracks.
Definition: Mix.h:80
A ToolBar that provides the record and playback volume settings.
Definition: MixerToolBar.h:25
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed...
Definition: ToolBar.h:87
void SetToolTips()
void OnFocus(wxFocusEvent &event)
EVT_COMMAND(OnTogglePinnedStateID, wxEVT_COMMAND_BUTTON_CLICKED, AdornedRulerPanel::OnTogglePinnedState) class AdornedRulerPanel
void Decrease(float steps)
Definition: ASlider.cpp:1606