Audacity  2.2.2
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"))
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, 0, wxALIGN_CENTER);
85 
86  // Playback icon and slider
88  wxID_ANY,
89  theTheme.Bitmap(bmpSpeaker)), 0, wxALIGN_CENTER);
90  mOutputSlider = safenew ASlider(this, wxID_ANY, _("Playback Volume"),
91  wxDefaultPosition, wxSize(130, 25),
92  ASlider::Options{}.Line( 0.1f ).Page( 2.0f ));
93  Add(mOutputSlider, 0, wxALIGN_CENTER);
94 
95  // this bit taken from SelectionBar::Populate()
96  mInputSlider->Bind(wxEVT_SET_FOCUS,
98  this);
99  mInputSlider->Bind(wxEVT_KILL_FOCUS,
101  this);
102  mOutputSlider->Bind(wxEVT_SET_FOCUS,
104  this);
105  mOutputSlider->Bind(wxEVT_KILL_FOCUS,
107  this);
108  // Show or hide the input slider based on whether it works
110 
111  UpdateControls();
112 
113  // Add a little space
114  Add(2, -1);
115 }
116 
117 //Also from SelectionBar;
118 void MixerToolBar::OnFocus(wxFocusEvent &event)
119 {
120  if (event.GetEventType() == wxEVT_KILL_FOCUS) {
122  }
123  else {
125  }
126 
127  Refresh(false);
128 
129  event.Skip();
130 }
131 
132 void MixerToolBar::OnCaptureKey(wxCommandEvent &event)
133 {
134  wxKeyEvent *kevent = (wxKeyEvent *)event.GetEventObject();
135  int keyCode = kevent->GetKeyCode();
136 
137  // Pass LEFT/RIGHT/UP/DOWN/PAGEUP/PAGEDOWN through for input/output sliders
138  if (FindFocus() == mInputSlider && (keyCode == WXK_LEFT || keyCode == WXK_RIGHT
139  || keyCode == WXK_UP || keyCode == WXK_DOWN
140  || keyCode == WXK_PAGEUP || keyCode == WXK_PAGEDOWN)) {
141  return;
142  }
143  if (FindFocus() == mOutputSlider && (keyCode == WXK_LEFT || keyCode == WXK_RIGHT
144  || keyCode == WXK_UP || keyCode == WXK_DOWN
145  || keyCode == WXK_PAGEUP || keyCode == WXK_PAGEDOWN)) {
146  return;
147  }
148 
149  event.Skip();
150 
151  return;
152 }
153 
155 {
156 #if USE_PORTMIXER
157  float inputVolume;
158  float playbackVolume;
159  int inputSource;
160 
161  // Reset the selected source
162  gAudioIO->GetMixer(&inputSource, &inputVolume, &playbackVolume);
163 
164  // Show or hide the input slider based on whether it works
166 
167  // Layout the toolbar
168  Layout();
169 
170  // Resize the toolbar to fit the contents
171  Fit();
172 
173  // And make that size the minimum
174  SetMinSize( wxWindow::GetSizer()->GetMinSize() );
175  SetSize( GetMinSize() );
176 
177  // Notify someone that we've changed our size
178  Updated();
179 #endif
180 
181  // Set label to pull in language change
182  SetLabel(_("Mixer"));
183 
185 
186  // Give base class a chance
188 }
189 
191 {
192 #if USE_PORTMIXER
193  float inputVolume;
194  float playbackVolume;
195  int inputSource;
196 
197  // Show or hide the input slider based on whether it works
199 
200  gAudioIO->GetMixer(&inputSource, &inputVolume, &playbackVolume);
201 
202  if (mOutputSlider->Get() != playbackVolume) {
203  mOutputSlider->Set(playbackVolume);
204  mOutputSliderVolume = playbackVolume;
205  SetToolTips();
206  }
207 
208  if (mInputSlider->Get() != inputVolume) {
209  mInputSlider->Set(inputVolume);
210  mInputSliderVolume = inputVolume;
211  SetToolTips();
212  }
213 #endif // USE_PORTMIXER
214 }
215 
216 void MixerToolBar::SetMixer(wxCommandEvent & WXUNUSED(event))
217 {
218 #if USE_PORTMIXER
219  float inputVolume = mInputSlider->Get();
220  float outputVolume = mOutputSlider->Get();
221  float oldIn, oldOut;
222  int inputSource;
223 
224  gAudioIO->GetMixer(&inputSource, &oldIn, &oldOut);
225  gAudioIO->SetMixer(inputSource, inputVolume, outputVolume);
226  mOutputSliderVolume = outputVolume;
227  mInputSliderVolume = inputVolume;
228  SetToolTips();
229 #endif // USE_PORTMIXER
230 }
231 
233 {
235  wxCommandEvent e;
236  SetMixer(e);
237  UpdateControls();
238 }
239 
241 {
243  wxCommandEvent e;
244  SetMixer(e);
245  UpdateControls();
246 }
247 
249 {
250  if (adj < 0) {
251  mOutputSlider->Decrease(-adj);
252  }
253  else {
254  mOutputSlider->Increase(adj);
255  }
256  wxCommandEvent e;
257  SetMixer(e);
258  UpdateControls();
259 }
260 
262 {
263  if (adj < 0) {
264  mInputSlider->Decrease(-adj);
265  }
266  else {
267  mInputSlider->Increase(adj);
268  }
269  wxCommandEvent e;
270  SetMixer(e);
271  UpdateControls();
272 }
273 
275 {
276  if (mInputSlider->IsEnabled()) {
277  mInputSlider->SetToolTipTemplate(_("Recording Volume: %.2f"));
278  }
279  else {
280  mInputSlider->SetToolTipTemplate(_("Recording Volume (Unavailable; use system mixer.)"));
281  }
282 
283  if (mOutputSlider->IsEnabled()) {
284  wxString format;
286  format = _("Playback Volume: %s (emulated)");
287  else
288  format = _("Playback Volume: %s");
289 
291  wxString::Format( format, "%.2f" ) );
292  }
293  else {
294  mOutputSlider->SetToolTipTemplate(_("Playback Volume (Unavailable; use system mixer.)"));
295  }
296 }
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:1393
EVT_COMMAND(wxID_ANY, EVT_FREQUENCYTEXTCTRL_UPDATED, LabelDialog::OnFreqUpdate) LabelDialog
Definition: LabelDialog.cpp:89
virtual void UpdatePrefs()
Definition: ToolBar.cpp:539
void AdjustInputGain(int adj)
void SetLabel(const wxString &label) override
Definition: ToolBar.cpp:378
ASlider * mInputSlider
Definition: MixerToolBar.h:64
static void CaptureKeyboard(wxWindow *handler)
Definition: Project.cpp:5961
float mInputSliderVolume
Definition: MixerToolBar.h:53
float Get(bool convert=true)
Definition: ASlider.cpp:1567
bool IsEnabled() const
Definition: ASlider.cpp:1609
void OnCaptureKey(wxCommandEvent &event)
float mOutputSliderVolume
Definition: MixerToolBar.h:57
void SetToolTipTemplate(const wxString &tip)
Definition: ASlider.cpp:1562
ASlider * mOutputSlider
Definition: MixerToolBar.h:65
void UpdatePrefs() override
bool InputMixerWorks()
Find out if the input hardware level control is available.
Definition: AudioIO.cpp:1388
#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:1357
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:615
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:442
void RegenerateTooltips() override
Definition: MixerToolBar.h:53
virtual ~MixerToolBar()
void Set(float value)
Definition: ASlider.cpp:1572
void ShowInputGainDialog()
Options & Line(float l)
Definition: ASlider.h:267
bool Enable(bool enable=true) override
Definition: ASlider.cpp:1597
void Updated()
Definition: ToolBar.cpp:596
void SetMixer(wxCommandEvent &event)
static void ReleaseKeyboard(wxWindow *handler)
Definition: Project.cpp:5972
void SetMixer(int inputSource)
Definition: AudioIO.cpp:1325
_("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:1587
AudioIO * gAudioIO
Definition: AudioIO.cpp:482
void Create(wxWindow *parent) override
ASlider is a custom slider, allowing for a slicker look and feel.
Definition: ASlider.h:243
void Increase(float steps)
Definition: ASlider.cpp:1577
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)
void Decrease(float steps)
Definition: ASlider.cpp:1582