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