1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-03 09:29:30 +02:00

Send event, so that DeviceManager does not depend on DeviceToolBar...

... freeing it and DevicePrefs from cycles
This commit is contained in:
Paul Licameli 2019-06-04 16:20:39 -04:00
parent ccc49f8ccf
commit 7ef5ebc97a
4 changed files with 22 additions and 7 deletions

View File

@ -38,7 +38,8 @@
#include "AudioIOBase.h" #include "AudioIOBase.h"
#include "DeviceChange.h" // for HAVE_DEVICE_CHANGE #include "DeviceChange.h" // for HAVE_DEVICE_CHANGE
#include "toolbars/DeviceToolBar.h"
wxDEFINE_EVENT(EVT_RESCANNED_DEVICES, wxCommandEvent);
DeviceManager DeviceManager::dm; DeviceManager DeviceManager::dm;
@ -299,13 +300,11 @@ void DeviceManager::Rescan()
} }
// If this was not an initial scan update each device toolbar. // 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 ) {
if (m_inited) { wxCommandEvent e{ EVT_RESCANNED_DEVICES };
for ( auto pProject : AllProjects{} ) { wxTheApp->ProcessEvent( e );
auto &dt = DeviceToolBar::Get( *pProject );
dt.RefillCombos();
}
} }
m_inited = true; m_inited = true;
mRescanTime = std::chrono::steady_clock::now(); mRescanTime = std::chrono::steady_clock::now();
} }

View File

@ -23,12 +23,17 @@
#include <chrono> #include <chrono>
#include <vector> #include <vector>
#include <wx/event.h> // to declare a custom event type
#include <wx/string.h> // member variables #include <wx/string.h> // member variables
#if defined(EXPERIMENTAL_DEVICE_CHANGE_HANDLER) #if defined(EXPERIMENTAL_DEVICE_CHANGE_HANDLER)
#include "DeviceChange.h" #include "DeviceChange.h"
#endif #endif
// Event sent to the application
wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API,
EVT_RESCANNED_DEVICES, wxCommandEvent);
typedef struct DeviceSourceMap { typedef struct DeviceSourceMap {
int deviceIndex; int deviceIndex;
int sourceIndex; int sourceIndex;

View File

@ -75,6 +75,8 @@ static int DeviceToolbarPrefsID()
DeviceToolBar::DeviceToolBar() DeviceToolBar::DeviceToolBar()
: ToolBar(DeviceBarID, _("Device"), wxT("Device"), true) : ToolBar(DeviceBarID, _("Device"), wxT("Device"), true)
{ {
wxTheApp->Bind( EVT_RESCANNED_DEVICES,
&DeviceToolBar::OnRescannedDevices, this );
} }
DeviceToolBar::~DeviceToolBar() DeviceToolBar::~DeviceToolBar()
@ -628,6 +630,13 @@ void DeviceToolBar::FillHostDevices()
// The setting of the Device is left up to OnChoice // 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. //return 1 if host changed, 0 otherwise.
int DeviceToolBar::ChangeHost() int DeviceToolBar::ChangeHost()
{ {

View File

@ -59,6 +59,8 @@ class DeviceToolBar final : public ToolBar {
void RefillCombos(); void RefillCombos();
private: private:
void OnRescannedDevices( wxCommandEvent& );
int ChangeHost(); int ChangeHost();
void ChangeDevice(bool isInput); void ChangeDevice(bool isInput);
void FillHosts(); void FillHosts();