Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
DeviceToolBar Class Referencefinal

A toobar to allow easier changing of input and output devices . More...

#include <DeviceToolBar.h>

Inheritance diagram for DeviceToolBar:
[legend]
Collaboration diagram for DeviceToolBar:
[legend]

Public Member Functions

 DeviceToolBar (AudacityProject &project)
 
virtual ~DeviceToolBar ()
 
void Create (wxWindow *parent) override
 
void UpdatePrefs () override
 
void UpdateSelectedPrefs (int) override
 
void DeinitChildren ()
 
void Populate () override
 
void Repaint (wxDC *WXUNUSED(dc)) override
 
void EnableDisableButtons () override
 
void OnFocus (wxFocusEvent &event)
 
void OnCaptureKey (wxCommandEvent &event)
 
void OnChoice (wxCommandEvent &event)
 
int GetInitialWidth () override
 
int GetMinToolbarWidth () override
 
void ShowInputDialog ()
 
void ShowOutputDialog ()
 
void ShowHostDialog ()
 
void ShowChannelsDialog ()
 
- Public Member Functions inherited from ToolBar
 ToolBar (AudacityProject &project, int type, const TranslatableString &label, const wxString &section, bool resizable=false)
 
virtual ~ToolBar ()
 
bool AcceptsFocus () const override
 
virtual void SetToDefaultSize ()
 
virtual void Create (wxWindow *parent)
 
virtual void EnableDisableButtons ()=0
 
virtual void ReCreateButtons ()
 
void UpdatePrefs () override
 
virtual void RegenerateTooltips ()=0
 
int GetType ()
 
TranslatableString GetTitle ()
 
TranslatableString GetLabel ()
 
wxString GetSection ()
 
ToolDockGetDock ()
 
void SetLabel (const TranslatableString &label)
 
virtual void SetDocked (ToolDock *dock, bool pushed)
 
virtual bool Expose (bool show=true)
 
bool IsResizable () const
 
bool IsVisible () const
 
bool IsDocked () const
 
bool IsPositioned ()
 
void SetVisible (bool bVisible)
 
void SetPositioned ()
 
virtual int GetInitialWidth ()
 Resizable toolbars should implement these. More...
 
virtual int GetMinToolbarWidth ()
 
virtual wxSize GetDockedSize ()
 
wxSize GetSmartDockedSize ()
 
virtual void ResizingDone ()
 
- Public Member Functions inherited from wxPanelWrapper
 wxPanelWrapper ()
 
 wxPanelWrapper (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const TranslatableString &name=XO("Panel"))
 
bool Create (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const TranslatableString &name=XO("Panel"))
 
void SetLabel (const TranslatableString &label)
 
void SetName (const TranslatableString &name)
 
void SetToolTip (const TranslatableString &toolTip)
 
void SetName ()
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxPanel >
 wxTabTraversalWrapper (Args &&... args)
 
 wxTabTraversalWrapper (const wxTabTraversalWrapper &)=delete
 
 wxTabTraversalWrapper (wxTabTraversalWrapper &&)=delete
 
wxTabTraversalWrapperoperator= (const wxTabTraversalWrapper &)=delete
 
wxTabTraversalWrapperoperator= (wxTabTraversalWrapper &&)=delete
 

Static Public Member Functions

static DeviceToolBarGet (AudacityProject &project)
 
static const DeviceToolBarGet (const AudacityProject &project)
 
- Static Public Member Functions inherited from ToolBar
static AButtonMakeButton (wxWindow *parent, teBmps eUp, teBmps eDown, teBmps eHilite, teBmps eDownHi, teBmps eStandardUp, teBmps eStandardDown, teBmps eDisabled, wxWindowID id, wxPoint placement, bool processdownevents, wxSize size)
 
static AButtonMakeButton (ToolBar *parent, teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled, int id, bool processdownevents, const TranslatableString &label)
 
static void MakeAlternateImages (AButton &button, int idx, teBmps eUp, teBmps eDown, teBmps eHilite, teBmps eDownHi, teBmps eStandardUp, teBmps eStandardDown, teBmps eDisabled, wxSize size)
 
static void SetButtonToolTip (AudacityProject &project, AButton &button, const ComponentInterfaceSymbol commands[], size_t nCommands)
 
static void MakeButtonBackgroundsSmall ()
 
static void MakeButtonBackgroundsLarge ()
 

Private Member Functions

void OnRescannedDevices (DeviceChangeMessage)
 
int ChangeHost ()
 
void ChangeDevice (bool isInput)
 
void RefillCombos ()
 
void FillHosts ()
 
void FillHostDevices ()
 
void FillInputChannels ()
 
void SetDevices (const DeviceSourceMap *in, const DeviceSourceMap *out)
 
void SetNames ()
 
void RegenerateTooltips () override
 
void ShowComboDialog (wxChoice *combo, const TranslatableString &title)
 

Private Attributes

wxChoice * mInput
 
wxChoice * mOutput
 
wxChoice * mInputChannels
 
wxChoice * mHost
 
Observer::Subscription mSubscription
 

Additional Inherited Members

- Public Types inherited from ToolBar
using Holder = wxWindowPtr< ToolBar >
 
- Protected Member Functions inherited from ToolBar
void SetButton (bool down, AButton *button)
 
wxBoxSizer * GetSizer ()
 
void Add (wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
 
void Add (wxSizer *sizer, int proportion=0, int flag=0, int border=0, wxObject *userData=NULL)
 
void Add (int width, int height, int proportion=0, int flag=0, int border=0, wxObject *userData=NULL)
 
void AddSpacer (int size=14)
 
void AddStretchSpacer (int prop=1)
 
void Detach (wxWindow *window)
 
void Detach (wxSizer *sizer)
 
void Updated ()
 
int GetResizeGrabberWidth ()
 Returns the width in pixels of the resizer element. More...
 
virtual void Populate ()=0
 
virtual void Repaint (wxDC *dc)=0
 
void OnErase (wxEraseEvent &event)
 
void OnPaint (wxPaintEvent &event)
 
void OnMouseEvents (wxMouseEvent &event)
 
virtual void UpdateSelectedPrefs (int id)
 
 PrefsListener ()
 
virtual ~PrefsListener ()
 
virtual void UpdatePrefs ()=0
 
- Static Protected Member Functions inherited from ToolBar
static void MakeMacRecoloredImage (teBmps eBmpOut, teBmps eBmpIn)
 
static void MakeMacRecoloredImageSize (teBmps eBmpOut, teBmps eBmpIn, const wxSize &size)
 
static void MakeRecoloredImage (teBmps eBmpOut, teBmps eBmpIn)
 
static void MakeRecoloredImageSize (teBmps eBmpOut, teBmps eBmpIn, const wxSize &size)
 
- Static Protected Member Functions inherited from PrefsListener
static void Broadcast (int id=0)
 Call this static function to notify all PrefsListener objects. More...
 
- Protected Attributes inherited from ToolBar
AudacityProjectmProject
 
TranslatableString mLabel
 
wxString mSection
 
int mType
 

Detailed Description

A toobar to allow easier changing of input and output devices .

Definition at line 27 of file DeviceToolBar.h.

Constructor & Destructor Documentation

◆ DeviceToolBar()

DeviceToolBar::DeviceToolBar ( AudacityProject project)

Definition at line 77 of file DeviceToolBar.cpp.

78: ToolBar( project, DeviceBarID, XO("Device"), wxT("Device"), true )
79{
82}
#define XO(s)
Definition: Internat.h:31
@ DeviceBarID
Definition: ToolBar.h:80
static DeviceManager * Instance()
Gets the singleton instance.
Observer::Subscription mSubscription
Definition: DeviceToolBar.h:80
void OnRescannedDevices(DeviceChangeMessage)
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
Definition: Observer.h:199
ToolBar(AudacityProject &project, int type, const TranslatableString &label, const wxString &section, bool resizable=false)
Definition: ToolBar.cpp:330

References DeviceManager::Instance(), mSubscription, OnRescannedDevices(), and Observer::Publisher< Message, NotifyAll >::Subscribe().

Here is the call graph for this function:

◆ ~DeviceToolBar()

DeviceToolBar::~DeviceToolBar ( )
virtual

Definition at line 84 of file DeviceToolBar.cpp.

85{
86}

Member Function Documentation

◆ ChangeDevice()

void DeviceToolBar::ChangeDevice ( bool  isInput)
private

Definition at line 613 of file DeviceToolBar.cpp.

614{
615 int newIndex = -1;
616 wxChoice *combo = isInput ? mInput :mOutput;
617 size_t i;
618
619 int selectionIndex = combo->GetSelection();
620 auto host = AudioIOHost.Read();
621 const std::vector<DeviceSourceMap> &maps = isInput ? DeviceManager::Instance()->GetInputDeviceMaps()
623
624 // Find device indices for input and output
625 if (selectionIndex >= 0 ) {
626 wxString newDevice = combo->GetStringSelection();
627 for (i = 0; i < maps.size(); ++i) {
628 wxString name;
629 name = MakeDeviceSourceString(&maps[i]);
630 if (name == newDevice && maps[i].hostString == host) {
631 newIndex = i;
632 }
633 }
634 }
635
636 if (newIndex < 0) {
637 wxLogDebug(wxT("DeviceToolBar::OnChoice(): couldn't find device indices"));
638 return;
639 }
640
641 SetDevices(isInput ? &maps[newIndex] : NULL,
642 isInput ? NULL : &maps[newIndex]);
643}
StringSetting AudioIOHost
wxString MakeDeviceSourceString(const DeviceSourceMap *map)
const TranslatableString name
Definition: Distortion.cpp:82
const std::vector< DeviceSourceMap > & GetInputDeviceMaps()
const std::vector< DeviceSourceMap > & GetOutputDeviceMaps()
wxChoice * mOutput
Definition: DeviceToolBar.h:76
void SetDevices(const DeviceSourceMap *in, const DeviceSourceMap *out)
wxChoice * mInput
Definition: DeviceToolBar.h:75
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:200

References AudioIOHost, DeviceManager::GetInputDeviceMaps(), DeviceManager::GetOutputDeviceMaps(), DeviceManager::Instance(), MakeDeviceSourceString(), mInput, mOutput, name, Setting< T >::Read(), and SetDevices().

Referenced by OnChoice().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ChangeHost()

int DeviceToolBar::ChangeHost ( )
private

Definition at line 566 of file DeviceToolBar.cpp.

567{
568 int hostSelectionIndex;
569 hostSelectionIndex = mHost->GetSelection();
570
571 auto oldHost = AudioIOHost.Read();
572 wxString newHost = hostSelectionIndex >= 0 ? mHost->GetString(hostSelectionIndex) :
573 oldHost;
574
575 if (oldHost == newHost)
576 return 0;
577
578 //change the host and switch to correct devices.
579 AudioIOHost.Write(newHost);
580 gPrefs->Flush();
581
582 // populate the devices
584
585 return 1;
586}
FileConfig * gPrefs
Definition: Prefs.cpp:71
wxChoice * mHost
Definition: DeviceToolBar.h:78
void FillHostDevices()
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:143
bool Write(const T &value)
Write value to config and return true if successful.
Definition: Prefs.h:252

References AudioIOHost, FillHostDevices(), FileConfig::Flush(), gPrefs, mHost, Setting< T >::Read(), and Setting< T >::Write().

Referenced by OnChoice().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Create()

void DeviceToolBar::Create ( wxWindow *  parent)
overridevirtual

Reimplemented from ToolBar.

Definition at line 99 of file DeviceToolBar.cpp.

100{
101 ToolBar::Create(parent);
102
103 // Simulate a size event to set initial meter placement/size
104 wxSizeEvent event(GetSize(), GetId());
105 event.SetEventObject(this);
106 GetEventHandler()->ProcessEvent(event);
107}
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:475

References ToolBar::Create().

Here is the call graph for this function:

◆ DeinitChildren()

void DeviceToolBar::DeinitChildren ( )

Definition at line 109 of file DeviceToolBar.cpp.

110{
111 mInput = NULL;
112 mOutput = NULL;
113 mInputChannels = NULL;
114 mHost = NULL;
115}
wxChoice * mInputChannels
Definition: DeviceToolBar.h:77

References mHost, mInput, mInputChannels, and mOutput.

Referenced by Populate().

Here is the caller graph for this function:

◆ EnableDisableButtons()

void DeviceToolBar::EnableDisableButtons ( )
overridevirtual

Implements ToolBar.

Definition at line 347 of file DeviceToolBar.cpp.

348{
349 auto gAudioIO = AudioIOBase::Get();
350 if (gAudioIO) {
351 // we allow changes when monitoring, but not when recording
352 bool audioStreamActive = gAudioIO->IsStreamActive() && !gAudioIO->IsMonitoring();
353
354 // Here we should relinquish focus
355 if (audioStreamActive) {
356 wxWindow *focus = wxWindow::FindFocus();
357 if (focus == mHost || focus == mInput || focus == mOutput || focus == mInputChannels)
358 TrackPanel::Get( mProject ).SetFocus();
359 }
360
361 mHost->Enable(!audioStreamActive);
362 mInput->Enable(!audioStreamActive);
363 mOutput->Enable(!audioStreamActive);
364 mInputChannels->Enable(!audioStreamActive);
365 }
366}
static AudioIOBase * Get()
Definition: AudioIOBase.cpp:91
AudacityProject & mProject
Definition: ToolBar.h:247
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:230

References AudioIOBase::Get(), TrackPanel::Get(), mHost, mInput, mInputChannels, mOutput, and ToolBar::mProject.

Here is the call graph for this function:

◆ FillHostDevices()

void DeviceToolBar::FillHostDevices ( )
private

Definition at line 429 of file DeviceToolBar.cpp.

430{
431 const std::vector<DeviceSourceMap> &inMaps = DeviceManager::Instance()->GetInputDeviceMaps();
432 const std::vector<DeviceSourceMap> &outMaps = DeviceManager::Instance()->GetOutputDeviceMaps();
433
434 //read what is in the prefs
435 auto host = AudioIOHost.Read();
436 int foundHostIndex = -1;
437
438 // if the host is not in the hosts combo then we rescanned.
439 // set it to blank so we search for another host.
440 if (mHost->FindString(host) == wxNOT_FOUND) {
441 host = wxT("");
442 }
443
444 for (auto & device : outMaps) {
445 if (device.hostString == host) {
446 foundHostIndex = device.hostIndex;
447 break;
448 }
449 }
450
451 if (foundHostIndex == -1) {
452 for (auto & device : inMaps) {
453 if (device.hostString == host) {
454 foundHostIndex = device.hostIndex;
455 break;
456 }
457 }
458 }
459
460 // If no host was found based on the prefs device host, load the first available one
461 if (foundHostIndex == -1) {
462 if (outMaps.size()) {
463 foundHostIndex = outMaps[0].hostIndex;
464 }
465 else if (inMaps.size()) {
466 foundHostIndex = inMaps[0].hostIndex;
467 }
468 }
469
470 // Make sure in/out are clear in case no host was found
471 mInput->Clear();
472 mOutput->Clear();
473
474 // If we still have no host it means no devices, in which case do nothing.
475 if (foundHostIndex == -1) {
476 return;
477 }
478
479 // Repopulate the Input/Output device list available to the user
480 for (auto & device : inMaps) {
481 if (foundHostIndex == device.hostIndex) {
482 mInput->Append(MakeDeviceSourceString(&device));
483 if (host.empty()) {
484 host = device.hostString;
485 AudioIOHost.Write(host);
486 mHost->SetStringSelection(host);
487 }
488 }
489 }
490 mInput->Enable(mInput->GetCount() ? true : false);
491
492 mInput->SetMinSize(wxSize(50, wxDefaultCoord));
493
494 for (auto & device : outMaps) {
495 if (foundHostIndex == device.hostIndex) {
496 mOutput->Append(MakeDeviceSourceString(&device));
497 if (host.empty()) {
498 host = device.hostString;
499 AudioIOHost.Write(host);
500 gPrefs->Flush();
501 mHost->SetStringSelection(host);
502 }
503 }
504 }
505 mOutput->Enable(mOutput->GetCount() ? true : false);
506
507 mOutput->SetMinSize(wxSize(50, wxDefaultCoord));
508
509 // The setting of the Device is left up to OnChoice
510}

References AudioIOHost, FileConfig::Flush(), DeviceManager::GetInputDeviceMaps(), DeviceManager::GetOutputDeviceMaps(), gPrefs, DeviceManager::Instance(), MakeDeviceSourceString(), mHost, mInput, mOutput, Setting< T >::Read(), and Setting< T >::Write().

Referenced by ChangeHost(), RefillCombos(), and UpdatePrefs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FillHosts()

void DeviceToolBar::FillHosts ( )
private

Definition at line 398 of file DeviceToolBar.cpp.

399{
400 const std::vector<DeviceSourceMap> &inMaps = DeviceManager::Instance()->GetInputDeviceMaps();
401 const std::vector<DeviceSourceMap> &outMaps = DeviceManager::Instance()->GetOutputDeviceMaps();
402
403 wxArrayString hosts;
404
405 // go over our lists add the host to the list if it isn't there yet
406
407 for (auto & device : inMaps) {
408 if (!make_iterator_range(hosts).contains(device.hostString)) {
409 hosts.push_back(device.hostString);
410 }
411 }
412
413 for (auto & device : outMaps) {
414 if (!make_iterator_range(hosts).contains(device.hostString)) {
415 hosts.push_back(device.hostString);
416 }
417 }
418
419 mHost->Clear();
420 mHost->Append(hosts);
421
422 if (hosts.size() == 0) {
423 mHost->Enable(false);
424 }
425
426 mHost->SetMinSize(wxSize(50, wxDefaultCoord));
427}
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
Definition: MemoryX.h:423

References DeviceManager::GetInputDeviceMaps(), DeviceManager::GetOutputDeviceMaps(), DeviceManager::Instance(), make_iterator_range(), and mHost.

Referenced by RefillCombos().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FillInputChannels()

void DeviceToolBar::FillInputChannels ( )
private

Definition at line 512 of file DeviceToolBar.cpp.

513{
514 const std::vector<DeviceSourceMap> &inMaps = DeviceManager::Instance()->GetInputDeviceMaps();
515 auto host = AudioIOHost.Read();
516 auto device = AudioIORecordingDevice.Read();
517 auto source = AudioIORecordingSource.Read();
518 long newChannels;
519
520 auto oldChannels = AudioIORecordChannels.Read();
521 mInputChannels->Clear();
522 for (auto & dev: inMaps) {
523 if (source == dev.sourceString &&
524 device == dev.deviceString &&
525 host == dev.hostString) {
526
527 // add one selection for each channel of this source
528 for (size_t j = 0; j < (unsigned int) dev.numChannels; j++) {
529 wxString name;
530
531 if (j == 0) {
532 name = _("1 (Mono) Recording Channel");
533 }
534 else if (j == 1) {
535 name = _("2 (Stereo) Recording Channels");
536 }
537 else {
538 name = wxString::Format(wxT("%d"), (int) j + 1);
539 }
540 mInputChannels->Append(name);
541 }
542 newChannels = dev.numChannels;
543 if (oldChannels <= newChannels && oldChannels >= 1) {
544 newChannels = oldChannels;
545 }
546 if (newChannels >= 1) {
547 mInputChannels->SetSelection(newChannels - 1);
548 }
549 AudioIORecordChannels.Write(newChannels);
550 break;
551 }
552 }
553 mInputChannels->Enable(mInputChannels->GetCount() ? true : false);
554
555 mInputChannels->SetMinSize(wxSize(50, wxDefaultCoord));
556}
StringSetting AudioIORecordingSource
StringSetting AudioIORecordingDevice
IntSetting AudioIORecordChannels
#define _(s)
Definition: Internat.h:75

References _, AudioIOHost, AudioIORecordChannels, AudioIORecordingDevice, AudioIORecordingSource, DeviceManager::GetInputDeviceMaps(), DeviceManager::Instance(), mInputChannels, name, Setting< T >::Read(), and Setting< T >::Write().

Referenced by RefillCombos(), SetDevices(), and UpdatePrefs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Get() [1/2]

DeviceToolBar & DeviceToolBar::Get ( AudacityProject project)
static

Definition at line 88 of file DeviceToolBar.cpp.

89{
90 auto &toolManager = ToolManager::Get( project );
91 return *static_cast<DeviceToolBar*>( toolManager.GetToolBar(DeviceBarID) );
92}
A toobar to allow easier changing of input and output devices .
Definition: DeviceToolBar.h:27
static ToolManager & Get(AudacityProject &project)

References DeviceBarID, and ToolManager::Get().

Referenced by Get(), ExtraActions::Handler::OnAudioHost(), ExtraActions::Handler::OnInputChannels(), ExtraActions::Handler::OnInputDevice(), and ExtraActions::Handler::OnOutputDevice().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Get() [2/2]

const DeviceToolBar & DeviceToolBar::Get ( const AudacityProject project)
static

Definition at line 94 of file DeviceToolBar.cpp.

95{
96 return Get( const_cast<AudacityProject&>( project )) ;
97}
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 DeviceToolBar & Get(AudacityProject &project)

References Get().

Here is the call graph for this function:

◆ GetInitialWidth()

int DeviceToolBar::GetInitialWidth ( )
inlineoverridevirtual

When the prefs don't exist this value is used. 883 takes a complete row in the default initial size of Audacity.

Reimplemented from ToolBar.

Definition at line 53 of file DeviceToolBar.h.

53{ return 883; }

◆ GetMinToolbarWidth()

int DeviceToolBar::GetMinToolbarWidth ( )
inlineoverridevirtual

Reimplemented from ToolBar.

Definition at line 54 of file DeviceToolBar.h.

54{ return 350; }

◆ OnCaptureKey()

void DeviceToolBar::OnCaptureKey ( wxCommandEvent &  event)

Definition at line 221 of file DeviceToolBar.cpp.

222{
223 wxKeyEvent *kevent = (wxKeyEvent *)event.GetEventObject();
224 int keyCode = kevent->GetKeyCode();
225
226 // Pass UP/DOWN/LEFT/RIGHT through for input/output choice
227 if (FindFocus() == mInput && (keyCode == WXK_LEFT || keyCode == WXK_RIGHT
228 || keyCode == WXK_UP || keyCode == WXK_DOWN)) {
229 return;
230 }
231
232 if (FindFocus() == mOutput && (keyCode == WXK_LEFT || keyCode == WXK_RIGHT
233 || keyCode == WXK_UP || keyCode == WXK_DOWN)) {
234 return;
235 }
236 event.Skip();
237
238 return;
239}

References mInput, and mOutput.

◆ OnChoice()

void DeviceToolBar::OnChoice ( wxCommandEvent &  event)

Definition at line 645 of file DeviceToolBar.cpp.

646{
647 wxObject *eventObject = event.GetEventObject();
648 //if we've changed hosts, we've handled the device switching already.
649 if (eventObject == mHost) {
650 ChangeHost();
651 } else if (eventObject == mInputChannels) {
652 int channelsSelectionIndex = mInputChannels->GetSelection();
653 if (channelsSelectionIndex >= 0)
654 AudioIORecordChannels.Write(channelsSelectionIndex + 1);
655 } else if (eventObject == mInput) {
656 ChangeDevice(true);
657 }
658 else if (eventObject == mOutput) {
659 ChangeDevice(false);
660 }
661
662 auto gAudioIO = AudioIOBase::Get();
663 if (gAudioIO) {
664 // We cannot have gotten here if gAudioIO->IsAudioTokenActive(),
665 // per the setting of AudioIONotBusyFlag and AudioIOBusyFlag in
666 // AudacityProject::GetUpdateFlags().
667 // However, we can have an invalid audio token (so IsAudioTokenActive()
668 // is false), but be monitoring.
669 // If monitoring, have to stop the stream, so HandleDeviceChange() can work.
670 // We could disable the Preferences command while monitoring, i.e.,
671 // set AudioIONotBusyFlag/AudioIOBusyFlag according to monitoring, as well.
672 // Instead allow it because unlike recording, for example, monitoring
673 // is not clearly something that should prohibit changing device.
674 // TODO: We *could* be smarter in this method and call HandleDeviceChange()
675 // only when the device choices actually changed. True of lots of prefs!
676 // As is, we always stop monitoring before handling the device change.
677 if (gAudioIO->IsMonitoring())
678 {
679 gAudioIO->StopStream();
680 while (gAudioIO->IsBusy()) {
681 using namespace std::chrono;
682 std::this_thread::sleep_for(100ms);
683 }
684 }
685 gAudioIO->HandleDeviceChange();
686 }
687
689}
int DeviceToolbarPrefsID()
Methods for DeviceToolBar.
void ChangeDevice(bool isInput)
static void Broadcast(int id=0)
Call this static function to notify all PrefsListener objects.
Definition: Prefs.cpp:98

References AudioIORecordChannels, PrefsListener::Broadcast(), ChangeDevice(), ChangeHost(), DeviceToolbarPrefsID(), AudioIOBase::Get(), mHost, mInput, mInputChannels, mOutput, and Setting< T >::Write().

Referenced by ShowComboDialog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnFocus()

void DeviceToolBar::OnFocus ( wxFocusEvent &  event)

Definition at line 216 of file DeviceToolBar.cpp.

217{
218 KeyboardCapture::OnFocus( *this, event );
219}
void OnFocus(wxWindow &window, wxFocusEvent &event)
a function useful to implement a focus event handler The window releases the keyboard if the event is...

References KeyboardCapture::OnFocus().

Referenced by Populate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnRescannedDevices()

void DeviceToolBar::OnRescannedDevices ( DeviceChangeMessage  m)
private

Definition at line 558 of file DeviceToolBar.cpp.

559{
560 // Hosts may have disappeared or appeared so a complete repopulate is needed.
562 RefillCombos();
563}

References RefillCombos(), and Rescan.

Referenced by DeviceToolBar().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Populate()

void DeviceToolBar::Populate ( )
overridevirtual

Implements ToolBar.

Definition at line 117 of file DeviceToolBar.cpp.

118{
119 SetBackgroundColour( theTheme.Colour( clrMedium ) );
121
122 // Hosts
123 mHost = safenew wxChoice(this,
124 wxID_ANY,
125 wxDefaultPosition,
126 wxDefaultSize);
127#if wxUSE_ACCESSIBILITY
128 // so that name can be set on a standard control
129 mHost->SetAccessible(safenew WindowAccessible(mHost));
130#endif
131 Add(mHost, 15, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 1);
132
133 // Input device
135 wxID_ANY,
136 theTheme.Bitmap(bmpMic)), 0, wxALIGN_CENTER_VERTICAL);
137 mInput = safenew wxChoice(this,
138 wxID_ANY,
139 wxDefaultPosition,
140 wxDefaultSize);
141#if wxUSE_ACCESSIBILITY
142 // so that name can be set on a standard control
143 mInput->SetAccessible(safenew WindowAccessible(mInput));
144#endif
145 Add(mInput, 30, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 1);
146
147 // Input channels
148 mInputChannels = safenew wxChoice(this,
149 wxID_ANY,
150 wxDefaultPosition,
151 wxDefaultSize);
152#if wxUSE_ACCESSIBILITY
153 // so that name can be set on a standard control
155#endif
156 Add(mInputChannels, 20, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 1);
157
158 // Output device
160 wxID_ANY,
161 theTheme.Bitmap(bmpSpeaker)), 0, wxALIGN_CENTER_VERTICAL);
162 mOutput = safenew wxChoice(this,
163 wxID_ANY,
164 wxDefaultPosition,
165 wxDefaultSize);
166#if wxUSE_ACCESSIBILITY
167 // so that name can be set on a standard control
168 mOutput->SetAccessible(safenew WindowAccessible(mOutput));
169#endif
170 Add(mOutput, 30, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 1);
171
172#if defined(__WXGTK3__)
173 // Nothing special
174#elif defined(__WXGTK__)
175 // Scale the font to fit inside (hopefully)
176 wxFont font = mHost->GetFont();
177 font.Scale((double) toolbarSingle / mHost->GetSize().GetHeight());
178
179 // Set it
180 mHost->SetFont(font);
181 mInput->SetFont(font);
182 mInputChannels->SetFont(font);
183 mOutput->SetFont(font);
184#endif
185
186 mHost->Bind(wxEVT_SET_FOCUS,
188 this);
189 mHost->Bind(wxEVT_KILL_FOCUS,
191 this);
192 mOutput->Bind(wxEVT_SET_FOCUS,
194 this);
195 mOutput->Bind(wxEVT_KILL_FOCUS,
197 this);
198 mInput->Bind(wxEVT_SET_FOCUS,
200 this);
201 mInput->Bind(wxEVT_KILL_FOCUS,
203 this);
204 mInputChannels->Bind(wxEVT_SET_FOCUS,
206 this);
207 mInputChannels->Bind(wxEVT_KILL_FOCUS,
209 this);
210
211 SetNames();
212
213 RefillCombos();
214}
#define safenew
Definition: MemoryX.h:10
THEME_API Theme theTheme
Definition: Theme.cpp:82
#define toolbarSingle
Definition: ToolBar.h:59
A widget for bitmaps which ignores the erase event for flicker-free use.
Definition: Grabber.h:150
void OnFocus(wxFocusEvent &event)
wxColour & Colour(int iIndex)
wxBitmap & Bitmap(int iIndex)
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:686
An alternative to using wxWindowAccessible, which in wxWidgets 3.1.1 contained GetParent() which was ...

References ToolBar::Add(), ThemeBase::Bitmap(), ThemeBase::Colour(), DeinitChildren(), mHost, mInput, mInputChannels, mOutput, OnFocus(), RefillCombos(), safenew, SetNames(), theTheme, and toolbarSingle.

Here is the call graph for this function:

◆ RefillCombos()

void DeviceToolBar::RefillCombos ( )
private

Definition at line 389 of file DeviceToolBar.cpp.

390{
391 FillHosts();
394 // make the device display selection reflect the prefs if they exist
395 UpdatePrefs();
396}
void FillInputChannels()
void UpdatePrefs() override

References FillHostDevices(), FillHosts(), FillInputChannels(), and UpdatePrefs().

Referenced by OnRescannedDevices(), and Populate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RegenerateTooltips()

void DeviceToolBar::RegenerateTooltips ( )
overrideprivatevirtual

Implements ToolBar.

Definition at line 378 of file DeviceToolBar.cpp.

379{
380#if wxUSE_TOOLTIPS
381 SetNames();
382 mOutput->SetToolTip(mOutput->GetName() + wxT(" - ") + mOutput->GetStringSelection());
383 mInput->SetToolTip(mInput->GetName() + wxT(" - ") + mInput->GetStringSelection());
384 mHost->SetToolTip(mHost->GetName() + wxT(" - ") + mHost->GetStringSelection());
385 mInputChannels->SetToolTip(mInputChannels->GetName() + wxT(" - ") + mInputChannels->GetStringSelection());
386#endif
387}

References mHost, mInput, mInputChannels, mOutput, and SetNames().

Referenced by UpdatePrefs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Repaint()

void DeviceToolBar::Repaint ( wxDC *  WXUNUSEDdc)
inlineoverride

Definition at line 44 of file DeviceToolBar.h.

44{};

◆ SetDevices()

void DeviceToolBar::SetDevices ( const DeviceSourceMap in,
const DeviceSourceMap out 
)
private

Definition at line 588 of file DeviceToolBar.cpp.

589{
590 if (in) {
593 if (in->totalSources >= 1)
595 else
597 gPrefs->Flush();
598
600 }
601
602 if (out) {
604 if (out->totalSources >= 1) {
606 } else {
608 }
609 gPrefs->Flush();
610 }
611}
StringSetting AudioIOPlaybackSource
StringSetting AudioIOPlaybackDevice
IntSetting AudioIORecordingSourceIndex
bool Reset()
Reset to the default value.
Definition: Prefs.h:277
wxString sourceString
Definition: DeviceManager.h:34
wxString deviceString
Definition: DeviceManager.h:35

References AudioIOPlaybackDevice, AudioIOPlaybackSource, AudioIORecordingDevice, AudioIORecordingSource, AudioIORecordingSourceIndex, DeviceSourceMap::deviceString, FillInputChannels(), FileConfig::Flush(), gPrefs, Setting< T >::Reset(), DeviceSourceMap::sourceIndex, DeviceSourceMap::sourceString, DeviceSourceMap::totalSources, and Setting< T >::Write().

Referenced by ChangeDevice(), and UpdatePrefs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetNames()

void DeviceToolBar::SetNames ( )
private

Definition at line 368 of file DeviceToolBar.cpp.

369{
370 /* i18n-hint: (noun) It's the device used for playback.*/
371 mOutput->SetName(_("Playback Device"));
372 /* i18n-hint: (noun) It's the device used for recording.*/
373 mInput->SetName(_("Recording Device"));
374 mHost->SetName(_("Audio Host"));
375 mInputChannels->SetName(_("Recording Channels"));
376}

References _, mHost, mInput, mInputChannels, and mOutput.

Referenced by Populate(), and RegenerateTooltips().

Here is the caller graph for this function:

◆ ShowChannelsDialog()

void DeviceToolBar::ShowChannelsDialog ( )

Definition at line 703 of file DeviceToolBar.cpp.

704{
705 ShowComboDialog(mInputChannels, XO("Select Recording Channels"));
706}
void ShowComboDialog(wxChoice *combo, const TranslatableString &title)

References mInputChannels, ShowComboDialog(), and XO.

Here is the call graph for this function:

◆ ShowComboDialog()

void DeviceToolBar::ShowComboDialog ( wxChoice *  combo,
const TranslatableString title 
)
private

Definition at line 708 of file DeviceToolBar.cpp.

709{
710 if (!combo || combo->GetCount() == 0) {
711 AudacityMessageBox( XO("Device information is not available.") );
712 return;
713 }
714
715#if USE_PORTMIXER
716 wxArrayStringEx inputSources = combo->GetStrings();
717
718 wxDialogWrapper dlg(nullptr, wxID_ANY, title);
719 dlg.SetName();
720 ShuttleGui S(&dlg, eIsCreating);
721 wxChoice *c;
722
723 S.StartVerticalLay(true);
724 {
725 S.StartHorizontalLay(wxCENTER, false);
726 {
727 c = S.AddChoice( Verbatim( combo->GetName() ),
728 transform_container<TranslatableStrings>( inputSources, Verbatim ),
729 combo->GetSelection());
730 c->SetMinSize(c->GetBestSize());
731 }
732 S.EndHorizontalLay();
733 }
734 S.EndVerticalLay();
735 S.AddStandardButtons();
736
737 dlg.GetSizer()->SetSizeHints(&dlg);
738 dlg.Center();
739
740 if (dlg.ShowModal() == wxID_OK)
741 {
742 wxCommandEvent dummyEvent;
743 dummyEvent.SetEventObject(combo);
744 // SetSelection() doesn't send an event, so we call OnChoice explicitly
745 combo->SetSelection(c->GetSelection());
746 OnChoice(dummyEvent);
747 }
748#endif
749}
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
static const auto title
@ eIsCreating
Definition: ShuttleGui.h:39
#define S(N)
Definition: ToChars.cpp:64
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
void OnChoice(wxCommandEvent &event)
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:628
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.

References AudacityMessageBox(), eIsCreating, OnChoice(), S, wxDialogWrapper::SetName(), title, Verbatim(), and XO.

Referenced by ShowChannelsDialog(), ShowHostDialog(), ShowInputDialog(), and ShowOutputDialog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ShowHostDialog()

void DeviceToolBar::ShowHostDialog ( )

Definition at line 699 of file DeviceToolBar.cpp.

700{
701 ShowComboDialog(mHost, XO("Select Audio Host"));
702}

References mHost, ShowComboDialog(), and XO.

Here is the call graph for this function:

◆ ShowInputDialog()

void DeviceToolBar::ShowInputDialog ( )

Definition at line 691 of file DeviceToolBar.cpp.

692{
693 ShowComboDialog(mInput, XO("Select Recording Device"));
694}

References mInput, ShowComboDialog(), and XO.

Here is the call graph for this function:

◆ ShowOutputDialog()

void DeviceToolBar::ShowOutputDialog ( )

Definition at line 695 of file DeviceToolBar.cpp.

696{
697 ShowComboDialog(mOutput, XO("Select Playback Device"));
698}

References mOutput, ShowComboDialog(), and XO.

Here is the call graph for this function:

◆ UpdatePrefs()

void DeviceToolBar::UpdatePrefs ( )
overridevirtual

Implements PrefsListener.

Definition at line 241 of file DeviceToolBar.cpp.

242{
243 wxString desc;
244 const std::vector<DeviceSourceMap> &inMaps = DeviceManager::Instance()->GetInputDeviceMaps();
245 const std::vector<DeviceSourceMap> &outMaps = DeviceManager::Instance()->GetOutputDeviceMaps();
246
247
248 int hostSelectionIndex = mHost->GetSelection();
249 wxString oldHost = hostSelectionIndex >= 0 ? mHost->GetString(hostSelectionIndex) :
250 wxString{};
251 auto hostName = AudioIOHost.Read();
252
253 // if the prefs host name doesn't match the one displayed, it changed
254 // in another project's DeviceToolBar, so we need to repopulate everything.
255 if (oldHost != hostName)
257
258 auto devName = AudioIORecordingDevice.Read();
259 auto sourceName = AudioIORecordingSource.Read();
260 if (sourceName.empty())
261 desc = devName;
262 else
263 desc = devName + wxT(": ") + sourceName;
264
265 if (mInput->GetStringSelection() != desc &&
266 mInput->FindString(desc) != wxNOT_FOUND) {
267 mInput->SetStringSelection(desc);
269 } else if (mInput->GetStringSelection() != desc && mInput->GetCount()) {
270 for (size_t i = 0; i < inMaps.size(); i++) {
271 if (inMaps[i].hostString == hostName &&
272 MakeDeviceSourceString(&inMaps[i]) == mInput->GetString(0)) {
273 // use the default. It should exist but check just in case, falling back on the 0 index.
274 DeviceSourceMap *defaultMap = DeviceManager::Instance()->GetDefaultInputDevice(inMaps[i].hostIndex);
275 if (defaultMap) {
276 mInput->SetStringSelection(MakeDeviceSourceString(defaultMap));
277 SetDevices(defaultMap, NULL);
278 } else {
279 //use the first item (0th index) if we have no familiar devices
280 mInput->SetSelection(0);
281 SetDevices(&inMaps[i], NULL);
282 }
283 break;
284 }
285 }
286 }
287
288 devName = AudioIOPlaybackDevice.Read();
289 sourceName = AudioIOPlaybackSource.Read();
290 if (sourceName.empty())
291 desc = devName;
292 else
293 desc = devName + wxT(": ") + sourceName;
294
295 if (mOutput->GetStringSelection() != desc &&
296 mOutput->FindString(desc) != wxNOT_FOUND) {
297 mOutput->SetStringSelection(desc);
298 } else if (mOutput->GetStringSelection() != desc &&
299 mOutput->GetCount()) {
300 for (size_t i = 0; i < outMaps.size(); i++) {
301 if (outMaps[i].hostString == hostName &&
302 MakeDeviceSourceString(&outMaps[i]) == mOutput->GetString(0)) {
303 // use the default. It should exist but check just in case, falling back on the 0 index.
304 DeviceSourceMap *defaultMap = DeviceManager::Instance()->GetDefaultOutputDevice(outMaps[i].hostIndex);
305 if (defaultMap) {
306 mOutput->SetStringSelection(MakeDeviceSourceString(defaultMap));
307 SetDevices(NULL, defaultMap);
308 } else {
309 //use the first item (0th index) if we have no familiar devices
310 mOutput->SetSelection(0);
311 SetDevices(NULL, &outMaps[i]);
312 }
313 break;
314 }
315 }
316 }
317
318 long oldChannels;
319 oldChannels = mInputChannels->GetSelection() + 1;
320 auto newChannels = AudioIORecordChannels.ReadWithDefault(0);
321 if (newChannels > 0 && oldChannels != newChannels)
322 mInputChannels->SetSelection(newChannels - 1);
323
324 if (!hostName.empty() && mHost->GetStringSelection() != hostName)
325 mHost->SetStringSelection(hostName);
326
328
329 // Set label to pull in language change
330 SetLabel(XO("Device"));
331
332 // Give base class a chance
334
335 Layout();
336 Refresh();
337}
const TranslatableString desc
Definition: ExportPCM.cpp:58
DeviceSourceMap * GetDefaultInputDevice(int hostIndex)
DeviceSourceMap * GetDefaultOutputDevice(int hostIndex)
void RegenerateTooltips() override
bool ReadWithDefault(T *pVar, const T &defaultValue) const
overload of ReadWithDefault returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:206
void SetLabel(const wxString &label) override
Definition: ToolBar.cpp:398
void UpdatePrefs() override
Definition: ToolBar.cpp:605

References AudioIOHost, AudioIOPlaybackDevice, AudioIOPlaybackSource, AudioIORecordChannels, AudioIORecordingDevice, AudioIORecordingSource, desc, FillHostDevices(), FillInputChannels(), DeviceManager::GetDefaultInputDevice(), DeviceManager::GetDefaultOutputDevice(), DeviceManager::GetInputDeviceMaps(), DeviceManager::GetOutputDeviceMaps(), DeviceManager::Instance(), MakeDeviceSourceString(), mHost, mInput, mInputChannels, mOutput, Setting< T >::Read(), Setting< T >::ReadWithDefault(), RegenerateTooltips(), SetDevices(), ToolBar::SetLabel(), ToolBar::UpdatePrefs(), and XO.

Referenced by RefillCombos(), and UpdateSelectedPrefs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateSelectedPrefs()

void DeviceToolBar::UpdateSelectedPrefs ( int  id)
overridevirtual

Reimplemented from PrefsListener.

Definition at line 339 of file DeviceToolBar.cpp.

340{
341 if (id == DeviceToolbarPrefsID())
342 UpdatePrefs();
344}
virtual void UpdateSelectedPrefs(int id)
Definition: Prefs.cpp:128

References DeviceToolbarPrefsID(), UpdatePrefs(), and PrefsListener::UpdateSelectedPrefs().

Here is the call graph for this function:

Member Data Documentation

◆ mHost

wxChoice* DeviceToolBar::mHost
private

◆ mInput

wxChoice* DeviceToolBar::mInput
private

◆ mInputChannels

wxChoice* DeviceToolBar::mInputChannels
private

◆ mOutput

wxChoice* DeviceToolBar::mOutput
private

◆ mSubscription

Observer::Subscription DeviceToolBar::mSubscription
private

Definition at line 80 of file DeviceToolBar.h.

Referenced by DeviceToolBar().


The documentation for this class was generated from the following files: