Audacity  3.0.3
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 
18 #include "MixerToolBar.h"
19 
20 #include "ToolManager.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/app.h>
27 #include <wx/choice.h>
28 #include <wx/event.h>
29 #include <wx/intl.h>
30 #include <wx/settings.h>
31 #include <wx/sizer.h>
32 #include <wx/statbmp.h>
33 #include <wx/tooltip.h>
34 #endif
35 
36 #include "../AColor.h"
37 #include "../AllThemeResources.h"
38 #include "../AudioIO.h"
39 #include "../ImageManipulation.h"
40 #include "../KeyboardCapture.h"
41 #include "Prefs.h"
42 #include "../widgets/ASlider.h"
43 #include "../widgets/Grabber.h"
44 
46 
50 
51 BEGIN_EVENT_TABLE(MixerToolBar, ToolBar)
52  EVT_PAINT(MixerToolBar::OnPaint)
53  EVT_SLIDER(wxID_ANY, MixerToolBar::SetMixer)
54  EVT_CHOICE(wxID_ANY, MixerToolBar::SetMixer)
55  EVT_COMMAND(wxID_ANY, EVT_CAPTURE_KEY, MixerToolBar::OnCaptureKey)
57 
58 //Standard constructor
60 : ToolBar(project, MixerBarID, XO("Mixer"), wxT("Mixer"), true)
61 {
62  mInputSliderVolume = 0.0;
63  mOutputSliderVolume = 0.0;
64  mEnabled = true;
65 }
66 
68 {
69 }
70 
72 {
73  auto &toolManager = ToolManager::Get( project );
74  return *static_cast<MixerToolBar*>( toolManager.GetToolBar(MixerBarID) );
75 }
76 
78 {
79  return Get( const_cast<AudacityProject&>( project )) ;
80 }
81 
82 void MixerToolBar::Create(wxWindow *parent)
83 {
84  ToolBar::Create(parent);
85  UpdatePrefs();
86 }
87 
89 {
90  SetBackgroundColour( theTheme.Colour( clrMedium ) );
91  // Recording icon and slider
93  wxID_ANY,
94  theTheme.Bitmap(bmpMic)), 0, wxALIGN_CENTER);
95  mInputSlider = safenew ASlider(this, wxID_ANY, XO("Recording Volume"),
96  wxDefaultPosition, wxSize(130, 25),
97  ASlider::Options{}.Line( 0.1f ).Page( 2.0f ));
98  Add(mInputSlider, 1, wxALIGN_CENTER);
99  mInputSlider->SetSizeHints(wxSize(75, 25), wxSize(1000, 25));
100 
101  // Playback icon and slider
103  wxID_ANY,
104  theTheme.Bitmap(bmpSpeaker)), 0, wxALIGN_CENTER);
105  mOutputSlider = safenew ASlider(this, wxID_ANY, XO("Playback Volume"),
106  wxDefaultPosition, wxSize(130, 25),
107  ASlider::Options{}.Line( 0.1f ).Page( 2.0f ));
108  Add(mOutputSlider, 1, wxALIGN_CENTER);
109  mOutputSlider->SetSizeHints(wxSize(75, 25), wxSize(1000, 25));
110 
111  // this bit taken from SelectionBar::Populate()
112  mInputSlider->Bind(wxEVT_SET_FOCUS,
114  this);
115  mInputSlider->Bind(wxEVT_KILL_FOCUS,
117  this);
118  mOutputSlider->Bind(wxEVT_SET_FOCUS,
120  this);
121  mOutputSlider->Bind(wxEVT_KILL_FOCUS,
123  this);
124  // Show or hide the input slider based on whether it works
125  auto gAudioIO = AudioIO::Get();
126  mInputSlider->Enable(mEnabled && gAudioIO->InputMixerWorks());
128 
129  UpdateControls();
130 
131  // Add a little space
132  Add(2, -1);
133 
134  // Listen for capture events
135  wxTheApp->Bind(EVT_AUDIOIO_CAPTURE,
137  this);
138 }
139 
140 void MixerToolBar::OnAudioCapture(wxCommandEvent & event)
141 {
142  event.Skip();
143 
145  if ((AudacityProject *) event.GetEventObject() != p)
146  {
147  mEnabled = !event.GetInt();
150  }
151 }
152 
153 //Also from SelectionBar;
154 void MixerToolBar::OnFocus(wxFocusEvent &event)
155 {
156  KeyboardCapture::OnFocus( *this, event );
157 }
158 
159 void MixerToolBar::OnCaptureKey(wxCommandEvent &event)
160 {
161  wxKeyEvent *kevent = (wxKeyEvent *)event.GetEventObject();
162  int keyCode = kevent->GetKeyCode();
163 
164  // Pass LEFT/RIGHT/UP/DOWN/PAGEUP/PAGEDOWN through for input/output sliders
165  if (FindFocus() == mInputSlider && (keyCode == WXK_LEFT || keyCode == WXK_RIGHT
166  || keyCode == WXK_UP || keyCode == WXK_DOWN
167  || keyCode == WXK_PAGEUP || keyCode == WXK_PAGEDOWN)) {
168  return;
169  }
170  if (FindFocus() == mOutputSlider && (keyCode == WXK_LEFT || keyCode == WXK_RIGHT
171  || keyCode == WXK_UP || keyCode == WXK_DOWN
172  || keyCode == WXK_PAGEUP || keyCode == WXK_PAGEDOWN)) {
173  return;
174  }
175 
176  event.Skip();
177 
178  return;
179 }
180 
182 {
183 #if USE_PORTMIXER
184  float inputVolume;
185  float playbackVolume;
186  int inputSource;
187 
188  // Reset the selected source
189  auto gAudioIO = AudioIO::Get();
190  gAudioIO->GetMixer(&inputSource, &inputVolume, &playbackVolume);
191 
192  // Show or hide the input slider based on whether it works
193  mInputSlider->Enable(mEnabled && gAudioIO->InputMixerWorks());
194  Layout();
195 
196 // This code is from before the mixer toolbar was resizable.
197 // Now that it is resizable we trust the user to resize the mixer toolbar themselves.
198 #if 0
199  wxSize oldSize( GetSize() );
200  // Layout the toolbar
201  Layout();
202  // Resize the toolbar to fit the contents
203  //Fit();
204  // And make that size the minimum
205  wxSize newMinSize( wxWindow::GetSizer()->GetMinSize() );
206  SetMinSize( newMinSize );
207  // IF size must increase, do so.
208  if( newMinSize.x > oldSize.x ){
209  SetSize( newMinSize );
210  // Notify someone that we've changed our size
211  Updated();
212  }
213  // ELSE preserve original size.
214  else
215  SetSize( oldSize );
216 #endif
217 #endif
218 
219  // Set label to pull in language change
220  SetLabel(XO("Mixer"));
221 
223 
224  // Give base class a chance
226 }
227 
229 {
230 #if USE_PORTMIXER
231  float inputVolume;
232  float playbackVolume;
233  int inputSource;
234 
235  // Show or hide the input slider based on whether it works
236  auto gAudioIO = AudioIO::Get();
237  mInputSlider->Enable(mEnabled && gAudioIO->InputMixerWorks());
238 
239  gAudioIO->GetMixer(&inputSource, &inputVolume, &playbackVolume);
240 
241  if (mOutputSlider->Get() != playbackVolume) {
242  mOutputSlider->Set(playbackVolume);
243  mOutputSliderVolume = playbackVolume;
244  SetToolTips();
245  }
246 
247  if (mInputSlider->Get() != inputVolume) {
248  mInputSlider->Set(inputVolume);
249  mInputSliderVolume = inputVolume;
250  SetToolTips();
251  }
252 #endif // USE_PORTMIXER
253 }
254 
255 void MixerToolBar::SetMixer(wxCommandEvent & WXUNUSED(event))
256 {
257 #if USE_PORTMIXER
258  float inputVolume = mInputSlider->Get();
259  float outputVolume = mOutputSlider->Get();
260  float oldIn, oldOut;
261  int inputSource;
262 
263  auto gAudioIO = AudioIO::Get();
264  gAudioIO->GetMixer(&inputSource, &oldIn, &oldOut);
265  gAudioIO->SetMixer(inputSource, inputVolume, outputVolume);
266  mOutputSliderVolume = outputVolume;
267  mInputSliderVolume = inputVolume;
268  SetToolTips();
269 #endif // USE_PORTMIXER
270 }
271 
273 {
275  wxCommandEvent e;
276  SetMixer(e);
277  UpdateControls();
278 }
279 
281 {
283  wxCommandEvent e;
284  SetMixer(e);
285  UpdateControls();
286 }
287 
289 {
290  if (adj < 0) {
291  mOutputSlider->Decrease(-adj);
292  }
293  else {
294  mOutputSlider->Increase(adj);
295  }
296  wxCommandEvent e;
297  SetMixer(e);
298  UpdateControls();
299 }
300 
302 {
303  if (adj < 0) {
304  mInputSlider->Decrease(-adj);
305  }
306  else {
307  mInputSlider->Increase(adj);
308  }
309  wxCommandEvent e;
310  SetMixer(e);
311  UpdateControls();
312 }
313 
315 {
316  if (mInputSlider->IsEnabled()) {
317  mInputSlider->SetToolTipTemplate(XO("Recording Volume: %.2f"));
318  }
319  else {
320  mInputSlider->SetToolTipTemplate(XO("Recording Volume (Unavailable; use system mixer.)"));
321  }
322 
323  if (mOutputSlider->IsEnabled()) {
325  ? XO("Playback Volume: %.2f (emulated)")
326  : XO("Playback Volume: %.2f"));
327 
329  }
330  else {
331  mOutputSlider->SetToolTipTemplate(XO("Playback Volume (Unavailable; use system mixer.)"));
332  }
333 }
334 
336  []( AudacityProject &project ){
337  return ToolBar::Holder{ safenew MixerToolBar{ project } }; }
338 };
339 
340 namespace {
342  /* i18n-hint: Clicking this menu item shows the toolbar
343  with the mixer */
344  MixerBarID, wxT("ShowMixerTB"), XXO("Mi&xer Toolbar")
345 };
346 }
MixerToolBar::OnAudioCapture
void OnAudioCapture(wxCommandEvent &event)
Definition: MixerToolBar.cpp:140
ASlider::Get
float Get(bool convert=true)
Definition: ASlider.cpp:1742
ToolManager.h
MixerToolBar::OnFocus
void OnFocus(wxFocusEvent &event)
Definition: MixerToolBar.cpp:154
anonymous_namespace{MixerToolBar.cpp}::sAttachment
AttachedToolBarMenuItem sAttachment
Definition: MixerToolBar.cpp:341
MixerToolBar::UpdatePrefs
void UpdatePrefs() override
Definition: MixerToolBar.cpp:181
MixerToolBar::UpdateControls
void UpdateControls()
Definition: MixerToolBar.cpp:228
MixerToolBar
A ToolBar that provides the record and playback volume settings.
Definition: MixerToolBar.h:22
EVT_COMMAND
EVT_COMMAND(wxID_ANY, EVT_FREQUENCYTEXTCTRL_UPDATED, LabelDialog::OnFreqUpdate) LabelDialog
Definition: LabelDialog.cpp:92
MixerToolBar::OnCaptureKey
void OnCaptureKey(wxCommandEvent &event)
Definition: MixerToolBar.cpp:159
MixerToolBar::mOutputSliderVolume
float mOutputSliderVolume
Definition: MixerToolBar.h:61
ASlider::Set
void Set(float value)
Definition: ASlider.cpp:1747
ToolBar::mProject
AudacityProject & mProject
Definition: ToolBar.h:235
MixerToolBar::SetToolTips
void SetToolTips()
Definition: MixerToolBar.cpp:314
ToolBar::SetLabel
void SetLabel(const wxString &label) override
Definition: ToolBar.cpp:398
ToolManager::Get
static ToolManager & Get(AudacityProject &project)
Definition: ToolManager.cpp:356
AStaticBitmap
A widget for bitmaps which ignores the erase event for flicker-free use.
Definition: Grabber.h:150
XO
#define XO(s)
Definition: Internat.h:31
ASlider::IsEnabled
bool IsEnabled() const
Definition: ASlider.cpp:1784
ToolBar::Holder
wxWindowPtr< ToolBar > Holder
Definition: ToolBar.h:102
ASlider::Options
Definition: ASlider.h:238
ASlider::Enable
bool Enable(bool enable=true) override
Definition: ASlider.cpp:1772
MixerToolBar::mOutputSlider
ASlider * mOutputSlider
Definition: MixerToolBar.h:69
MixerToolBar::mEnabled
bool mEnabled
Definition: MixerToolBar.h:70
AttachedToolBarMenuItem
Definition: ToolManager.h:224
ThemeBase::Bitmap
wxBitmap & Bitmap(int iIndex)
Definition: Theme.cpp:1216
MixerToolBar::RegenerateTooltips
void RegenerateTooltips() override
Definition: MixerToolBar.h:57
XXO
#define XXO(s)
Definition: Internat.h:44
MixerToolBar::Get
static MixerToolBar & Get(AudacityProject &project)
Definition: MixerToolBar.cpp:71
ASlider::SetToolTipTemplate
void SetToolTipTemplate(const TranslatableString &tip)
Definition: ASlider.cpp:1737
MixerToolBar::mInputSlider
ASlider * mInputSlider
Definition: MixerToolBar.h:68
MixerBarID
@ MixerBarID
Definition: ToolBar.h:77
factory
static RegisteredToolbarFactory factory
Definition: MixerToolBar.cpp:335
ToolBar::OnPaint
void OnPaint(wxPaintEvent &event)
Definition: ToolBar.cpp:937
ToolBar::UpdatePrefs
void UpdatePrefs() override
Definition: ToolBar.cpp:605
AudioIO::OutputMixerEmulated
bool OutputMixerEmulated()
Find out if the output level control is being emulated via software attenuation.
Definition: AudioIO.cpp:1276
ASlider::Increase
void Increase(float steps)
Definition: ASlider.cpp:1752
format
int format
Definition: ExportPCM.cpp:56
MixerToolBar::~MixerToolBar
virtual ~MixerToolBar()
Definition: MixerToolBar.cpp:67
MixerToolBar.h
ToolBar::Create
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:475
MixerToolBar::AdjustInputGain
void AdjustInputGain(int adj)
Definition: MixerToolBar.cpp:301
MixerToolBar::AdjustOutputGain
void AdjustOutputGain(int adj)
Definition: MixerToolBar.cpp:288
RegisteredToolbarFactory
Definition: ToolBar.h:261
ASlider
ASlider is a custom slider, allowing for a slicker look and feel.
Definition: ASlider.h:234
ASlider::Options::Line
Options & Line(float l)
Definition: ASlider.h:257
IMPLEMENT_CLASS
IMPLEMENT_CLASS(MixerToolBar, ToolBar)
MixerToolBar::SetMixer
void SetMixer(wxCommandEvent &event)
Definition: MixerToolBar.cpp:255
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
MixerToolBar::Create
void Create(wxWindow *parent) override
Definition: MixerToolBar.cpp:82
MixerToolBar::ShowOutputGainDialog
void ShowOutputGainDialog()
Definition: MixerToolBar.cpp:272
KeyboardCapture::OnFocus
void OnFocus(wxWindow &window, wxFocusEvent &event)
a function useful to implement a focus event handler The window releases the keyboard if the event is...
Definition: KeyboardCapture.cpp:95
ToolBar
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed.
Definition: ToolBar.h:98
ThemeBase::Colour
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1197
MixerToolBar::ShowInputGainDialog
void ShowInputGainDialog()
Definition: MixerToolBar.cpp:280
MixerToolBar::Populate
void Populate() override
Definition: MixerToolBar.cpp:88
theTheme
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:203
Prefs.h
ToolBar::Updated
void Updated()
Definition: ToolBar.cpp:661
AudioIO::Get
static AudioIO * Get()
Definition: AudioIO.cpp:606
safenew
#define safenew
Definition: MemoryX.h:10
Mixer
Functions for doing the mixdown of the tracks.
Definition: Mix.h:76
END_EVENT_TABLE
END_EVENT_TABLE()
ASlider::Decrease
void Decrease(float steps)
Definition: ASlider.cpp:1757
ToolBar::Add
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:686
MixerToolBar::mInputSliderVolume
float mInputSliderVolume
Definition: MixerToolBar.h:57
ASlider::ShowDialog
bool ShowDialog(wxPoint pos=wxPoint(-1, -1))
Definition: ASlider.cpp:1762