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 
44 
48 
49 BEGIN_EVENT_TABLE(MixerToolBar, ToolBar)
50  EVT_PAINT(MixerToolBar::OnPaint)
51  EVT_SLIDER(wxID_ANY, MixerToolBar::SetMixer)
52  EVT_CHOICE(wxID_ANY, MixerToolBar::SetMixer)
53  EVT_COMMAND(wxID_ANY, EVT_CAPTURE_KEY, MixerToolBar::OnCaptureKey)
55 
56 //Standard contructor
58 : ToolBar(MixerBarID, _("Mixer"), wxT("Mixer"))
59 {
60  mInputSliderVolume = 0.0;
61  mOutputSliderVolume = 0.0;
62 }
63 
65 {
66 }
67 
68 void MixerToolBar::Create(wxWindow *parent)
69 {
70  ToolBar::Create(parent);
71 }
72 
74 {
75  SetBackgroundColour( theTheme.Colour( clrMedium ) );
76  // Recording icon and slider
77  Add(safenew wxStaticBitmap(this,
78  wxID_ANY,
79  theTheme.Bitmap(bmpMic)), 0, wxALIGN_CENTER);
80  mInputSlider = safenew ASlider(this, wxID_ANY, _("Recording Volume"),
81  wxDefaultPosition, wxSize(130, 25));
82  mInputSlider->SetScroll(0.1f, 2.0f);
83  mInputSlider->SetName(_("Slider Recording"));
84  Add(mInputSlider, 0, wxALIGN_CENTER);
85 
86  // Playback icon and slider
87  Add(safenew wxStaticBitmap(this,
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  mOutputSlider->SetScroll(0.1f, 2.0f);
93  mOutputSlider->SetName(_("Slider Playback"));
94  Add(mOutputSlider, 0, wxALIGN_CENTER);
95 
96  // this bit taken from SelectionBar::Populate()
97  mInputSlider->Connect(wxEVT_SET_FOCUS,
98  wxFocusEventHandler(MixerToolBar::OnFocus),
99  NULL,
100  this);
101  mInputSlider->Connect(wxEVT_KILL_FOCUS,
102  wxFocusEventHandler(MixerToolBar::OnFocus),
103  NULL,
104  this);
105  mOutputSlider->Connect(wxEVT_SET_FOCUS,
106  wxFocusEventHandler(MixerToolBar::OnFocus),
107  NULL,
108  this);
109  mOutputSlider->Connect(wxEVT_KILL_FOCUS,
110  wxFocusEventHandler(MixerToolBar::OnFocus),
111  NULL,
112  this);
113  // Show or hide the input slider based on whether it works
115 
116  UpdateControls();
117 
118  // Add a little space
119  Add(2, -1);
120 }
121 
122 //Also from SelectionBar;
123 void MixerToolBar::OnFocus(wxFocusEvent &event)
124 {
125  if (event.GetEventType() == wxEVT_KILL_FOCUS) {
127  }
128  else {
130  }
131 
132  Refresh(false);
133 
134  event.Skip();
135 }
136 
137 void MixerToolBar::OnCaptureKey(wxCommandEvent &event)
138 {
139  wxKeyEvent *kevent = (wxKeyEvent *)event.GetEventObject();
140  int keyCode = kevent->GetKeyCode();
141 
142  // Pass LEFT/RIGHT/UP/DOWN/PAGEUP/PAGEDOWN through for input/output sliders
143  if (FindFocus() == mInputSlider && (keyCode == WXK_LEFT || keyCode == WXK_RIGHT
144  || keyCode == WXK_UP || keyCode == WXK_DOWN
145  || keyCode == WXK_PAGEUP || keyCode == WXK_PAGEDOWN)) {
146  return;
147  }
148  if (FindFocus() == mOutputSlider && (keyCode == WXK_LEFT || keyCode == WXK_RIGHT
149  || keyCode == WXK_UP || keyCode == WXK_DOWN
150  || keyCode == WXK_PAGEUP || keyCode == WXK_PAGEDOWN)) {
151  return;
152  }
153 
154  event.Skip();
155 
156  return;
157 }
158 
160 {
161 #if USE_PORTMIXER
162  float inputVolume;
163  float playbackVolume;
164  int inputSource;
165 
166  // Reset the selected source
167  gAudioIO->GetMixer(&inputSource, &inputVolume, &playbackVolume);
168 
169  // Show or hide the input slider based on whether it works
171 
172  // Layout the toolbar
173  Layout();
174 
175  // Resize the toolbar to fit the contents
176  Fit();
177 
178  // And make that size the minimum
179  SetMinSize( wxWindow::GetSizer()->GetMinSize() );
180  SetSize( GetMinSize() );
181 
182  // Notify someone that we've changed our size
183  Updated();
184 #endif
185 
186  // Set label to pull in language change
187  SetLabel(_("Mixer"));
188 
190 
191  // Give base class a chance
193 }
194 
196 {
197 #if USE_PORTMIXER
198  float inputVolume;
199  float playbackVolume;
200  int inputSource;
201 
202  // Show or hide the input slider based on whether it works
204 
205  gAudioIO->GetMixer(&inputSource, &inputVolume, &playbackVolume);
206 
207  if (mOutputSlider->Get() != playbackVolume) {
208  mOutputSlider->Set(playbackVolume);
209  mOutputSliderVolume = playbackVolume;
210  SetToolTips();
211  }
212 
213  if (mInputSlider->Get() != inputVolume) {
214  mInputSlider->Set(inputVolume);
215  mInputSliderVolume = inputVolume;
216  SetToolTips();
217  }
218 #endif // USE_PORTMIXER
219 }
220 
221 void MixerToolBar::SetMixer(wxCommandEvent & WXUNUSED(event))
222 {
223 #if USE_PORTMIXER
224  float inputVolume = mInputSlider->Get();
225  float outputVolume = mOutputSlider->Get();
226  float oldIn, oldOut;
227  int inputSource;
228 
229  gAudioIO->GetMixer(&inputSource, &oldIn, &oldOut);
230  gAudioIO->SetMixer(inputSource, inputVolume, outputVolume);
231  mOutputSliderVolume = outputVolume;
232  mInputSliderVolume = inputVolume;
233  SetToolTips();
234 #endif // USE_PORTMIXER
235 }
236 
238 {
240  wxCommandEvent e;
241  SetMixer(e);
242  UpdateControls();
243 }
244 
246 {
248  wxCommandEvent e;
249  SetMixer(e);
250  UpdateControls();
251 }
252 
254 {
255  if (adj < 0) {
256  mOutputSlider->Decrease(-adj);
257  }
258  else {
259  mOutputSlider->Increase(adj);
260  }
261  wxCommandEvent e;
262  SetMixer(e);
263  UpdateControls();
264 }
265 
267 {
268  if (adj < 0) {
269  mInputSlider->Decrease(-adj);
270  }
271  else {
272  mInputSlider->Increase(adj);
273  }
274  wxCommandEvent e;
275  SetMixer(e);
276  UpdateControls();
277 }
278 
280 {
281  if (mInputSlider->IsEnabled()) {
282  mInputSlider->SetToolTipTemplate(_("Recording Volume: %.2f"));
283  }
284  else {
285  mInputSlider->SetToolTipTemplate(_("Recording Volume (Unavailable; use system mixer.)"));
286  }
287 
288  if (mOutputSlider->IsEnabled()) {
289  wxString format;
291  format = _("Playback Volume: %s (emulated)");
292  else
293  format = _("Playback Volume: %s");
294 
296  wxString::Format( format, "%.2f" ) );
297  }
298  else {
299  mOutputSlider->SetToolTipTemplate(_("Playback Volume (Unavailable; use system mixer.)"));
300  }
301 }
void Populate() override
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:215
bool OutputMixerEmulated()
Find out if the output level control is being emulated via software attenuation.
Definition: AudioIO.cpp:1391
EVT_COMMAND(wxID_ANY, EVT_FREQUENCYTEXTCTRL_UPDATED, LabelDialog::OnFreqUpdate) LabelDialog
Definition: LabelDialog.cpp:88
virtual void UpdatePrefs()
Definition: ToolBar.cpp:540
void AdjustInputGain(int adj)
ASlider * mInputSlider
Definition: MixerToolBar.h:64
static void CaptureKeyboard(wxWindow *handler)
Definition: Project.cpp:5764
float mInputSliderVolume
Definition: MixerToolBar.h:53
float Get(bool convert=true)
Definition: ASlider.cpp:1703
bool IsEnabled() const
Definition: ASlider.cpp:1745
void OnCaptureKey(wxCommandEvent &event)
float mOutputSliderVolume
Definition: MixerToolBar.h:57
void SetToolTipTemplate(const wxString &tip)
Definition: ASlider.cpp:1698
ASlider * mOutputSlider
Definition: MixerToolBar.h:65
void UpdatePrefs() override
bool InputMixerWorks()
Find out if the input hardware level control is available.
Definition: AudioIO.cpp:1386
#define safenew
Definition: Audacity.h:223
wxBitmap & Bitmap(int iIndex)
Definition: Theme.cpp:1233
IMPLEMENT_CLASS(MixerToolBar, ToolBar)
void GetMixer(int *inputSource, float *inputVolume, float *playbackVolume)
Definition: AudioIO.cpp:1355
void SetScroll(float line, float page)
Definition: ASlider.cpp:1693
int format
Definition: ExportPCM.cpp:56
void AdjustOutputGain(int adj)
bool Enable(bool enable=true)
Definition: ASlider.cpp:1733
void ShowOutputGainDialog()
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:616
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:443
void RegenerateTooltips() override
Definition: MixerToolBar.h:53
virtual ~MixerToolBar()
void Set(float value)
Definition: ASlider.cpp:1708
void ShowInputGainDialog()
void Updated()
Definition: ToolBar.cpp:597
void SetMixer(wxCommandEvent &event)
_("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 &)
static void ReleaseKeyboard(wxWindow *handler)
Definition: Project.cpp:5775
void SetMixer(int inputSource)
Definition: AudioIO.cpp:1323
void UpdateControls()
bool ShowDialog(wxPoint pos=wxPoint(-1,-1))
Definition: ASlider.cpp:1723
AudioIO * gAudioIO
Definition: AudioIO.cpp:481
void SetLabel(const wxString &label)
Definition: ToolBar.cpp:379
void Create(wxWindow *parent) override
ASlider is a custom slider, allowing for a slicker look and feel.
Definition: ASlider.h:242
void Increase(float steps)
Definition: ASlider.cpp:1713
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1214
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:1718