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 ()
 
bool ShownByDefault () const override
 Whether the toolbar should be shown by default. Default implementation returns true. More...
 
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, const TranslatableString &label, const Identifier &section, bool resizable=false)
 
virtual ~ToolBar ()
 
virtual bool ShownByDefault () const
 Whether the toolbar should be shown by default. Default implementation returns true. More...
 
virtual bool HideAfterReset () const
 Default implementation returns false. More...
 
virtual DockID DefaultDockID () const
 Which dock the toolbar defaults into. Default implementation chooses the top dock. More...
 
bool AcceptsFocus () const override
 
bool AcceptsFocusFromKeyboard () 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 GetIndex () const
 Get a value used for computing cascading positions of undocked bars. More...
 
void SetIndex (int index)
 Set a value used for computing cascading positions of undocked bars. More...
 
TranslatableString GetTitle ()
 
TranslatableString GetLabel ()
 
Identifier GetSection ()
 
ToolDockGetDock ()
 
void SetPreferredNeighbors (Identifier left, Identifier top={})
 
void SetLabel (const TranslatableString &label)
 
virtual void SetDocked (ToolDock *dock, bool pushed)
 
std::pair< Identifier, IdentifierPreferredNeighbors () const noexcept
 Defaults to (NoBarID, NoBarId) More...
 
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 Identifier ID ()
 
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
enum  DockID { TopDockID = 1 , BotDockID = 2 }
 Identifies one of the docking areas for toolbars. More...
 
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
 
Identifier mSection
 
int mIndex {0}
 

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 79 of file DeviceToolBar.cpp.

80: ToolBar( project, XO("Device"), ID(), true )
81{
84}
XO("Cut/Copy/Paste")
const auto project
static DeviceManager * Instance()
Gets the singleton instance.
Observer::Subscription mSubscription
Definition: DeviceToolBar.h:84
static Identifier ID()
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, const TranslatableString &label, const Identifier &section, bool resizable=false)
Definition: ToolBar.cpp:328

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 86 of file DeviceToolBar.cpp.

87{
88}

Member Function Documentation

◆ ChangeDevice()

void DeviceToolBar::ChangeDevice ( bool  isInput)
private

Definition at line 620 of file DeviceToolBar.cpp.

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

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

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 573 of file DeviceToolBar.cpp.

574{
575 int hostSelectionIndex;
576 hostSelectionIndex = mHost->GetSelection();
577
578 auto oldHost = AudioIOHost.Read();
579 wxString newHost = hostSelectionIndex >= 0 ? mHost->GetString(hostSelectionIndex) :
580 oldHost;
581
582 if (oldHost == newHost)
583 return 0;
584
585 //change the host and switch to correct devices.
586 AudioIOHost.Write(newHost);
587 gPrefs->Flush();
588
589 // populate the devices
591
592 return 1;
593}
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
wxChoice * mHost
Definition: DeviceToolBar.h:82
void FillHostDevices()
bool Write(const T &value)
Write value to config and return true if successful.
Definition: Prefs.h:259
virtual bool Flush() noexcept=0

References AudioIOHost, FillHostDevices(), audacity::BasicSettings::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 106 of file DeviceToolBar.cpp.

107{
108 ToolBar::Create(parent);
109
110 // Simulate a size event to set initial meter placement/size
111 wxSizeEvent event(GetSize(), GetId());
112 event.SetEventObject(this);
113 GetEventHandler()->ProcessEvent(event);
114}
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:492

References ToolBar::Create().

Here is the call graph for this function:

◆ DeinitChildren()

void DeviceToolBar::DeinitChildren ( )

Definition at line 116 of file DeviceToolBar.cpp.

117{
118 mInput = NULL;
119 mOutput = NULL;
120 mInputChannels = NULL;
121 mHost = NULL;
122}
wxChoice * mInputChannels
Definition: DeviceToolBar.h:81

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 354 of file DeviceToolBar.cpp.

355{
356 auto gAudioIO = AudioIOBase::Get();
357 if (gAudioIO) {
358 // we allow changes when monitoring, but not when recording
359 bool audioStreamActive = gAudioIO->IsStreamActive() && !gAudioIO->IsMonitoring();
360
361 // Here we should relinquish focus
362 if (audioStreamActive) {
363 wxWindow *focus = wxWindow::FindFocus();
364 if (focus == mHost || focus == mInput || focus == mOutput || focus == mInputChannels)
365 TrackPanel::Get( mProject ).SetFocus();
366 }
367
368 mHost->Enable(!audioStreamActive);
369 mInput->Enable(!audioStreamActive);
370 mOutput->Enable(!audioStreamActive);
371 mInputChannels->Enable(!audioStreamActive);
372 }
373}
static AudioIOBase * Get()
Definition: AudioIOBase.cpp:94
AudacityProject & mProject
Definition: ToolBar.h:248
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:233
std::unique_ptr< WindowPlacement > FindFocus()
Find the window that is accepting keyboard input, if any.
Definition: BasicUI.h:373

References BasicUI::FindFocus(), 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 436 of file DeviceToolBar.cpp.

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

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

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 405 of file DeviceToolBar.cpp.

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

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 519 of file DeviceToolBar.cpp.

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

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

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 95 of file DeviceToolBar.cpp.

96{
97 auto &toolManager = ToolManager::Get( project );
98 return *static_cast<DeviceToolBar*>(toolManager.GetToolBar(ID()));
99}
A toobar to allow easier changing of input and output devices .
Definition: DeviceToolBar.h:27
static ToolManager & Get(AudacityProject &project)

References ToolManager::Get(), ID(), and project.

Referenced by Get(), anonymous_namespace{DeviceToolBar.cpp}::OnAudioHost(), anonymous_namespace{DeviceToolBar.cpp}::OnInputChannels(), anonymous_namespace{DeviceToolBar.cpp}::OnInputDevice(), and anonymous_namespace{DeviceToolBar.cpp}::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 101 of file DeviceToolBar.cpp.

102{
103 return Get( const_cast<AudacityProject&>( project )) ;
104}
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
static DeviceToolBar & Get(AudacityProject &project)

References Get(), and project.

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 57 of file DeviceToolBar.h.

57{ return 883; }

◆ GetMinToolbarWidth()

int DeviceToolBar::GetMinToolbarWidth ( )
inlineoverridevirtual

Reimplemented from ToolBar.

Definition at line 58 of file DeviceToolBar.h.

58{ return 350; }

◆ ID()

Identifier DeviceToolBar::ID ( )
static

Definition at line 73 of file DeviceToolBar.cpp.

74{
75 return wxT("Device");
76}

References wxT().

Referenced by Get().

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

◆ OnCaptureKey()

void DeviceToolBar::OnCaptureKey ( wxCommandEvent &  event)

Definition at line 228 of file DeviceToolBar.cpp.

229{
230 wxKeyEvent *kevent = (wxKeyEvent *)event.GetEventObject();
231 int keyCode = kevent->GetKeyCode();
232
233 // Pass UP/DOWN/LEFT/RIGHT through for input/output choice
234 if (FindFocus() == mInput && (keyCode == WXK_LEFT || keyCode == WXK_RIGHT
235 || keyCode == WXK_UP || keyCode == WXK_DOWN)) {
236 return;
237 }
238
239 if (FindFocus() == mOutput && (keyCode == WXK_LEFT || keyCode == WXK_RIGHT
240 || keyCode == WXK_UP || keyCode == WXK_DOWN)) {
241 return;
242 }
243 event.Skip();
244
245 return;
246}

References BasicUI::FindFocus(), mInput, and mOutput.

Here is the call graph for this function:

◆ OnChoice()

void DeviceToolBar::OnChoice ( wxCommandEvent &  event)

Definition at line 652 of file DeviceToolBar.cpp.

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

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 223 of file DeviceToolBar.cpp.

224{
225 KeyboardCapture::OnFocus( *this, event );
226}
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 565 of file DeviceToolBar.cpp.

566{
567 // Hosts may have disappeared or appeared so a complete repopulate is needed.
569 RefillCombos();
570}

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 124 of file DeviceToolBar.cpp.

125{
126 SetBackgroundColour( theTheme.Colour( clrMedium ) );
128
129 // Hosts
130 mHost = safenew wxChoice(this,
131 wxID_ANY,
132 wxDefaultPosition,
133 wxDefaultSize);
134#if wxUSE_ACCESSIBILITY
135 // so that name can be set on a standard control
136 mHost->SetAccessible(safenew WindowAccessible(mHost));
137#endif
138 Add(mHost, 15, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 1);
139
140 // Input device
142 wxID_ANY,
143 theTheme.Bitmap(bmpMic)), 0, wxALIGN_CENTER_VERTICAL);
144 mInput = safenew wxChoice(this,
145 wxID_ANY,
146 wxDefaultPosition,
147 wxDefaultSize);
148#if wxUSE_ACCESSIBILITY
149 // so that name can be set on a standard control
150 mInput->SetAccessible(safenew WindowAccessible(mInput));
151#endif
152 Add(mInput, 30, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 1);
153
154 // Input channels
155 mInputChannels = safenew wxChoice(this,
156 wxID_ANY,
157 wxDefaultPosition,
158 wxDefaultSize);
159#if wxUSE_ACCESSIBILITY
160 // so that name can be set on a standard control
162#endif
163 Add(mInputChannels, 20, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 1);
164
165 // Output device
167 wxID_ANY,
168 theTheme.Bitmap(bmpSpeaker)), 0, wxALIGN_CENTER_VERTICAL);
169 mOutput = safenew wxChoice(this,
170 wxID_ANY,
171 wxDefaultPosition,
172 wxDefaultSize);
173#if wxUSE_ACCESSIBILITY
174 // so that name can be set on a standard control
175 mOutput->SetAccessible(safenew WindowAccessible(mOutput));
176#endif
177 Add(mOutput, 30, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 1);
178
179#if defined(__WXGTK3__)
180 // Nothing special
181#elif defined(__WXGTK__)
182 // Scale the font to fit inside (hopefully)
183 wxFont font = mHost->GetFont();
184 font.Scale((double) toolbarSingle / mHost->GetSize().GetHeight());
185
186 // Set it
187 mHost->SetFont(font);
188 mInput->SetFont(font);
189 mInputChannels->SetFont(font);
190 mOutput->SetFont(font);
191#endif
192
193 mHost->Bind(wxEVT_SET_FOCUS,
195 this);
196 mHost->Bind(wxEVT_KILL_FOCUS,
198 this);
199 mOutput->Bind(wxEVT_SET_FOCUS,
201 this);
202 mOutput->Bind(wxEVT_KILL_FOCUS,
204 this);
205 mInput->Bind(wxEVT_SET_FOCUS,
207 this);
208 mInput->Bind(wxEVT_KILL_FOCUS,
210 this);
211 mInputChannels->Bind(wxEVT_SET_FOCUS,
213 this);
214 mInputChannels->Bind(wxEVT_KILL_FOCUS,
216 this);
217
218 SetNames();
219
220 RefillCombos();
221}
#define safenew
Definition: MemoryX.h:9
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:155
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:709
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 396 of file DeviceToolBar.cpp.

397{
398 FillHosts();
401 // make the device display selection reflect the prefs if they exist
402 UpdatePrefs();
403}
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 385 of file DeviceToolBar.cpp.

386{
387#if wxUSE_TOOLTIPS
388 SetNames();
389 mOutput->SetToolTip(mOutput->GetName() + wxT(" - ") + mOutput->GetStringSelection());
390 mInput->SetToolTip(mInput->GetName() + wxT(" - ") + mInput->GetStringSelection());
391 mHost->SetToolTip(mHost->GetName() + wxT(" - ") + mHost->GetStringSelection());
392 mInputChannels->SetToolTip(mInputChannels->GetName() + wxT(" - ") + mInputChannels->GetStringSelection());
393#endif
394}

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

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 48 of file DeviceToolBar.h.

48{};

◆ SetDevices()

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

Definition at line 595 of file DeviceToolBar.cpp.

596{
597 if (in) {
600 if (in->totalSources >= 1)
602 else
604 gPrefs->Flush();
605
607 }
608
609 if (out) {
611 if (out->totalSources >= 1) {
613 } else {
615 }
616 gPrefs->Flush();
617 }
618}
StringSetting AudioIOPlaybackSource
StringSetting AudioIOPlaybackDevice
IntSetting AudioIORecordingSourceIndex
bool Reset()
Reset to the default value.
Definition: Prefs.h:284
wxString sourceString
Definition: DeviceManager.h:34
wxString deviceString
Definition: DeviceManager.h:35

References AudioIOPlaybackDevice, AudioIOPlaybackSource, AudioIORecordingDevice, AudioIORecordingSource, AudioIORecordingSourceIndex, DeviceSourceMap::deviceString, FillInputChannels(), audacity::BasicSettings::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 375 of file DeviceToolBar.cpp.

376{
377 /* i18n-hint: (noun) It's the device used for playback.*/
378 mOutput->SetName(_("Playback Device"));
379 /* i18n-hint: (noun) It's the device used for recording.*/
380 mInput->SetName(_("Recording Device"));
381 mHost->SetName(_("Audio Host"));
382 mInputChannels->SetName(_("Recording Channels"));
383}

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 710 of file DeviceToolBar.cpp.

711{
712 ShowComboDialog(mInputChannels, XO("Select Recording Channels"));
713}
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 715 of file DeviceToolBar.cpp.

716{
717 if (!combo || combo->GetCount() == 0) {
718 AudacityMessageBox( XO("Device information is not available.") );
719 return;
720 }
721
722#if USE_PORTMIXER
723 wxArrayStringEx inputSources = combo->GetStrings();
724
725 wxDialogWrapper dlg(nullptr, wxID_ANY, title);
726 dlg.SetName();
727 ShuttleGui S(&dlg, eIsCreating);
728 wxChoice *c;
729
730 S.StartVerticalLay(true);
731 {
732 S.StartHorizontalLay(wxCENTER, false);
733 {
734 c = S.AddChoice( Verbatim( combo->GetName() ),
735 transform_container<TranslatableStrings>( inputSources, Verbatim ),
736 combo->GetSelection());
737 c->SetMinSize(c->GetBestSize());
738 }
739 S.EndHorizontalLay();
740 }
741 S.EndVerticalLay();
742 S.AddStandardButtons();
743
744 dlg.GetSizer()->SetSizeHints(&dlg);
745 dlg.Center();
746
747 if (dlg.ShowModal() == wxID_OK)
748 {
749 wxCommandEvent dummyEvent;
750 dummyEvent.SetEventObject(combo);
751 // SetSelection() doesn't send an event, so we call OnChoice explicitly
752 combo->SetSelection(c->GetSelection());
753 OnChoice(dummyEvent);
754 }
755#endif
756}
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
static const auto title
@ eIsCreating
Definition: ShuttleGui.h:37
#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:640
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 706 of file DeviceToolBar.cpp.

707{
708 ShowComboDialog(mHost, XO("Select Audio Host"));
709}

References mHost, ShowComboDialog(), and XO().

Here is the call graph for this function:

◆ ShowInputDialog()

void DeviceToolBar::ShowInputDialog ( )

Definition at line 698 of file DeviceToolBar.cpp.

699{
700 ShowComboDialog(mInput, XO("Select Recording Device"));
701}

References mInput, ShowComboDialog(), and XO().

Here is the call graph for this function:

◆ ShownByDefault()

bool DeviceToolBar::ShownByDefault ( ) const
overridevirtual

Whether the toolbar should be shown by default. Default implementation returns true.

Reimplemented from ToolBar.

Definition at line 90 of file DeviceToolBar.cpp.

91{
92 return false;
93}

◆ ShowOutputDialog()

void DeviceToolBar::ShowOutputDialog ( )

Definition at line 702 of file DeviceToolBar.cpp.

703{
704 ShowComboDialog(mOutput, XO("Select Playback Device"));
705}

References mOutput, ShowComboDialog(), and XO().

Here is the call graph for this function:

◆ UpdatePrefs()

void DeviceToolBar::UpdatePrefs ( )
overridevirtual

Implements PrefsListener.

Definition at line 248 of file DeviceToolBar.cpp.

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

References AudioIOHost, AudioIOPlaybackDevice, AudioIOPlaybackSource, AudioIORecordChannels, AudioIORecordingDevice, AudioIORecordingSource, anonymous_namespace{ExportPCM.cpp}::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(), wxT(), 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 346 of file DeviceToolBar.cpp.

347{
348 if (id == DeviceToolbarPrefsID())
349 UpdatePrefs();
351}
virtual void UpdateSelectedPrefs(int id)
Definition: Prefs.cpp:158

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 84 of file DeviceToolBar.h.

Referenced by DeviceToolBar().


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