From 7ef5ebc97a90f024165efd1834a7e6df1a0ecad0 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 4 Jun 2019 16:20:39 -0400 Subject: [PATCH] Send event, so that DeviceManager does not depend on DeviceToolBar... ... freeing it and DevicePrefs from cycles --- src/DeviceManager.cpp | 13 ++++++------- src/DeviceManager.h | 5 +++++ src/toolbars/DeviceToolBar.cpp | 9 +++++++++ src/toolbars/DeviceToolBar.h | 2 ++ 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/DeviceManager.cpp b/src/DeviceManager.cpp index ff6a7ad3d..004d9d761 100644 --- a/src/DeviceManager.cpp +++ b/src/DeviceManager.cpp @@ -38,7 +38,8 @@ #include "AudioIOBase.h" #include "DeviceChange.h" // for HAVE_DEVICE_CHANGE -#include "toolbars/DeviceToolBar.h" + +wxDEFINE_EVENT(EVT_RESCANNED_DEVICES, wxCommandEvent); DeviceManager DeviceManager::dm; @@ -299,13 +300,11 @@ void DeviceManager::Rescan() } // If this was not an initial scan update each device toolbar. - // Hosts may have disappeared or appeared so a complete repopulate is needed. - if (m_inited) { - for ( auto pProject : AllProjects{} ) { - auto &dt = DeviceToolBar::Get( *pProject ); - dt.RefillCombos(); - } + if ( m_inited ) { + wxCommandEvent e{ EVT_RESCANNED_DEVICES }; + wxTheApp->ProcessEvent( e ); } + m_inited = true; mRescanTime = std::chrono::steady_clock::now(); } diff --git a/src/DeviceManager.h b/src/DeviceManager.h index 2016941b8..25b2a8dff 100644 --- a/src/DeviceManager.h +++ b/src/DeviceManager.h @@ -23,12 +23,17 @@ #include #include +#include // to declare a custom event type #include // member variables #if defined(EXPERIMENTAL_DEVICE_CHANGE_HANDLER) #include "DeviceChange.h" #endif +// Event sent to the application +wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API, + EVT_RESCANNED_DEVICES, wxCommandEvent); + typedef struct DeviceSourceMap { int deviceIndex; int sourceIndex; diff --git a/src/toolbars/DeviceToolBar.cpp b/src/toolbars/DeviceToolBar.cpp index 7d59d080c..25a4a7bad 100644 --- a/src/toolbars/DeviceToolBar.cpp +++ b/src/toolbars/DeviceToolBar.cpp @@ -75,6 +75,8 @@ static int DeviceToolbarPrefsID() DeviceToolBar::DeviceToolBar() : ToolBar(DeviceBarID, _("Device"), wxT("Device"), true) { + wxTheApp->Bind( EVT_RESCANNED_DEVICES, + &DeviceToolBar::OnRescannedDevices, this ); } DeviceToolBar::~DeviceToolBar() @@ -628,6 +630,13 @@ void DeviceToolBar::FillHostDevices() // The setting of the Device is left up to OnChoice } +void DeviceToolBar::OnRescannedDevices( wxCommandEvent &event ) +{ + event.Skip(); + // Hosts may have disappeared or appeared so a complete repopulate is needed. + RefillCombos(); +} + //return 1 if host changed, 0 otherwise. int DeviceToolBar::ChangeHost() { diff --git a/src/toolbars/DeviceToolBar.h b/src/toolbars/DeviceToolBar.h index f00881866..ab673c357 100644 --- a/src/toolbars/DeviceToolBar.h +++ b/src/toolbars/DeviceToolBar.h @@ -59,6 +59,8 @@ class DeviceToolBar final : public ToolBar { void RefillCombos(); private: + void OnRescannedDevices( wxCommandEvent& ); + int ChangeHost(); void ChangeDevice(bool isInput); void FillHosts();