1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-12 06:37:52 +02:00

Free DeviceManager and DevicePrefs from cycles

This commit is contained in:
Paul Licameli 2019-06-10 21:56:10 -04:00
commit 8f3cd8436a
8 changed files with 36 additions and 15 deletions

View File

@ -586,7 +586,7 @@ public:
* Does quite a bit of housekeeping, including switching off monitoring,
* flushing recording buffers out to wave tracks, and applies latency
* correction to recorded tracks if necessary */
void StopStream();
void StopStream() override;
/** \brief Move the playback / recording position of the current stream
* by the specified amount from where it is now */
void SeekStream(double seconds) { mSeek = seconds; }

View File

@ -96,6 +96,8 @@ AudioIOBase *AudioIOBase::Get()
return ugAudioIO.get();
}
AudioIOBase::~AudioIOBase() = default;
void AudioIOBase::SetMixer(int inputSource)
{
#if defined(USE_PORTMIXER)

View File

@ -111,6 +111,8 @@ class AudioIOBase /* not final */
public:
static AudioIOBase *Get();
virtual ~AudioIOBase();
void SetCaptureMeter(AudacityProject *project, MeterPanelBase *meter);
void SetPlaybackMeter(AudacityProject *project, MeterPanelBase *meter);
@ -211,6 +213,8 @@ public:
/** \brief Find out if playback / recording is currently paused */
bool IsPaused() const;
virtual void StopStream() = 0;
/** \brief Returns true if audio i/o is busy starting, stopping, playing,
* or recording.
*

View File

@ -35,10 +35,11 @@
#include "Project.h"
#include "AudioIO.h"
#include "AudioIOBase.h"
#include "DeviceChange.h" // for HAVE_DEVICE_CHANGE
#include "toolbars/DeviceToolBar.h"
wxDEFINE_EVENT(EVT_RESCANNED_DEVICES, wxCommandEvent);
DeviceManager DeviceManager::dm;
@ -259,7 +260,7 @@ void DeviceManager::Rescan()
if (m_inited) {
// check to see if there is a stream open - can happen if monitoring,
// but otherwise Rescan() should not be available to the user.
auto gAudioIO = AudioIO::Get();
auto gAudioIO = AudioIOBase::Get();
if (gAudioIO) {
if (gAudioIO->IsMonitoring())
{
@ -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();
}

View File

@ -23,12 +23,17 @@
#include <chrono>
#include <vector>
#include <wx/event.h> // to declare a custom event type
#include <wx/string.h> // 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;

View File

@ -34,7 +34,7 @@
#include <wx/treebook.h>
#include "../AudioIO.h"
#include "../AudioIOBase.h"
#include "../Prefs.h"
#include "../ShuttleGui.h"
@ -814,7 +814,7 @@ void PrefsDialog::OnOK(wxCommandEvent & WXUNUSED(event))
SavePreferredPage();
#if USE_PORTMIXER
auto gAudioIO = AudioIO::Get();
auto gAudioIO = AudioIOBase::Get();
if (gAudioIO) {
// We cannot have opened this dialog if gAudioIO->IsAudioTokenActive(),
// per the setting of AudioIONotBusyFlag and AudioIOBusyFlag in

View File

@ -39,7 +39,7 @@
#include "../AColor.h"
#include "../AllThemeResources.h"
#include "../AudioIO.h"
#include "../AudioIOBase.h"
#include "../ImageManipulation.h"
#include "../KeyboardCapture.h"
#include "../Prefs.h"
@ -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()
@ -341,7 +343,7 @@ void DeviceToolBar::UpdateSelectedPrefs( int id )
void DeviceToolBar::EnableDisableButtons()
{
auto gAudioIO = AudioIO::Get();
auto gAudioIO = AudioIOBase::Get();
if (gAudioIO) {
// we allow changes when monitoring, but not when recording
bool audioStreamActive = gAudioIO->IsStreamActive() && !gAudioIO->IsMonitoring();
@ -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()
{
@ -776,7 +785,7 @@ void DeviceToolBar::OnChoice(wxCommandEvent &event)
ChangeDevice(false);
}
auto gAudioIO = AudioIO::Get();
auto gAudioIO = AudioIOBase::Get();
if (gAudioIO) {
// We cannot have gotten here if gAudioIO->IsAudioTokenActive(),
// per the setting of AudioIONotBusyFlag and AudioIOBusyFlag in

View File

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