From 17c04d174911c75728ccbac5bf4904b81ea6e009 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 4 Jun 2019 00:20:42 -0400 Subject: [PATCH] Separate an abstract base class from MeterPanel... ... to break its cycle with AudioIO --- src/AudioIOBase.cpp | 4 ++-- src/AudioIOBase.h | 12 ++++++------ src/ProjectAudioIO.cpp | 8 ++++---- src/ProjectAudioIO.h | 14 +++++++------- src/toolbars/ControlToolBar.cpp | 2 +- src/widgets/Meter.cpp | 6 +++++- src/widgets/Meter.h | 28 ++++++++++++++++++++++------ 7 files changed, 47 insertions(+), 27 deletions(-) diff --git a/src/AudioIOBase.cpp b/src/AudioIOBase.cpp index e4c803e58..f8e5b3fa1 100644 --- a/src/AudioIOBase.cpp +++ b/src/AudioIOBase.cpp @@ -306,7 +306,7 @@ void AudioIOBase::HandleDeviceChange() #endif // USE_PORTMIXER } -void AudioIOBase::SetCaptureMeter(AudacityProject *project, MeterPanel *meter) +void AudioIOBase::SetCaptureMeter(AudacityProject *project, MeterPanelBase *meter) { if (( mOwningProject ) && ( mOwningProject != project)) return; @@ -320,7 +320,7 @@ void AudioIOBase::SetCaptureMeter(AudacityProject *project, MeterPanel *meter) mInputMeter.Release(); } -void AudioIOBase::SetPlaybackMeter(AudacityProject *project, MeterPanel *meter) +void AudioIOBase::SetPlaybackMeter(AudacityProject *project, MeterPanelBase *meter) { if (( mOwningProject ) && ( mOwningProject != project)) return; diff --git a/src/AudioIOBase.h b/src/AudioIOBase.h index 604c74837..ad9432d7c 100644 --- a/src/AudioIOBase.h +++ b/src/AudioIOBase.h @@ -31,7 +31,7 @@ class AudioIOBase; class AudacityProject; class AudioIOListener; class BoundedEnvelope; -class MeterPanel; +class MeterPanelBase; using PRCrossfadeData = std::vector< std::vector < float > >; #define BAD_STREAM_TIME (-DBL_MAX) @@ -83,7 +83,7 @@ struct AudioIOStartStreamOptions {} AudacityProject *pProject{}; - MeterPanel *captureMeter{}, *playbackMeter{}; + MeterPanelBase *captureMeter{}, *playbackMeter{}; BoundedEnvelope *envelope; // for time warping AudioIOListener* listener; double rate; @@ -111,8 +111,8 @@ class AudioIOBase /* not final */ public: static AudioIOBase *Get(); - void SetCaptureMeter(AudacityProject *project, MeterPanel *meter); - void SetPlaybackMeter(AudacityProject *project, MeterPanel *meter); + void SetCaptureMeter(AudacityProject *project, MeterPanelBase *meter); + void SetPlaybackMeter(AudacityProject *project, MeterPanelBase *meter); /** \brief update state after changing what audio devices are selected * @@ -268,8 +268,8 @@ protected: PaStream *mPortStreamV19; - wxWeakRef mInputMeter{}; - wxWeakRef mOutputMeter{}; + wxWeakRef mInputMeter{}; + wxWeakRef mOutputMeter{}; #if USE_PORTMIXER PxMixer *mPortMixer; diff --git a/src/ProjectAudioIO.cpp b/src/ProjectAudioIO.cpp index af605f27d..9f541df7a 100644 --- a/src/ProjectAudioIO.cpp +++ b/src/ProjectAudioIO.cpp @@ -55,12 +55,12 @@ bool ProjectAudioIO::IsAudioActive() const gAudioIO->IsStreamActive(GetAudioIOToken()); } -MeterPanel *ProjectAudioIO::GetPlaybackMeter() +MeterPanelBase *ProjectAudioIO::GetPlaybackMeter() { return mPlaybackMeter; } -void ProjectAudioIO::SetPlaybackMeter(MeterPanel *playback) +void ProjectAudioIO::SetPlaybackMeter(MeterPanelBase *playback) { auto &project = mProject; mPlaybackMeter = playback; @@ -71,12 +71,12 @@ void ProjectAudioIO::SetPlaybackMeter(MeterPanel *playback) } } -MeterPanel *ProjectAudioIO::GetCaptureMeter() +MeterPanelBase *ProjectAudioIO::GetCaptureMeter() { return mCaptureMeter; } -void ProjectAudioIO::SetCaptureMeter(MeterPanel *capture) +void ProjectAudioIO::SetCaptureMeter(MeterPanelBase *capture) { auto &project = mProject; mCaptureMeter = capture; diff --git a/src/ProjectAudioIO.h b/src/ProjectAudioIO.h index b476822a1..5154a812f 100644 --- a/src/ProjectAudioIO.h +++ b/src/ProjectAudioIO.h @@ -14,7 +14,7 @@ Paul Licameli split from AudacityProject.h #include "ClientData.h" // to inherit class AudacityProject; -class MeterPanel; +class MeterPanelBase; ///\ brief Holds per-project state needed for interaction with AudioIO, /// including the audio stream token and pointers to meters @@ -32,17 +32,17 @@ public: bool IsAudioActive() const; void SetAudioIOToken(int token); - MeterPanel *GetPlaybackMeter(); - void SetPlaybackMeter(MeterPanel *playback); - MeterPanel *GetCaptureMeter(); - void SetCaptureMeter(MeterPanel *capture); + MeterPanelBase *GetPlaybackMeter(); + void SetPlaybackMeter(MeterPanelBase *playback); + MeterPanelBase *GetCaptureMeter(); + void SetCaptureMeter(MeterPanelBase *capture); private: AudacityProject &mProject; // Project owned meters - MeterPanel *mPlaybackMeter{}; - MeterPanel *mCaptureMeter{}; + MeterPanelBase *mPlaybackMeter{}; + MeterPanelBase *mCaptureMeter{}; int mAudioIOToken{ -1 }; }; diff --git a/src/toolbars/ControlToolBar.cpp b/src/toolbars/ControlToolBar.cpp index 959a981c9..438ba0556 100644 --- a/src/toolbars/ControlToolBar.cpp +++ b/src/toolbars/ControlToolBar.cpp @@ -893,7 +893,7 @@ void ControlToolBar::StopPlaying(bool stopStream /* = true*/) // also clean the MeterQueues if( project ) { auto &projectAudioIO = ProjectAudioIO::Get( *project ); - MeterPanel *meter = projectAudioIO.GetPlaybackMeter(); + auto meter = projectAudioIO.GetPlaybackMeter(); if( meter ) { meter->Clear(); } diff --git a/src/widgets/Meter.cpp b/src/widgets/Meter.cpp index 227dc462a..30bd6f153 100644 --- a/src/widgets/Meter.cpp +++ b/src/widgets/Meter.cpp @@ -292,7 +292,7 @@ MeterPanel::MeterPanel(AudacityProject *project, const wxSize& size /*= wxDefaultSize*/, Style style /*= HorizontalStereo*/, float fDecayRate /*= 60.0f*/) -: wxPanelWrapper(parent, id, pos, size, wxTAB_TRAVERSAL | wxNO_BORDER | wxWANTS_CHARS), +: MeterPanelBase(parent, id, pos, size, wxTAB_TRAVERSAL | wxNO_BORDER | wxWANTS_CHARS), mProject(project), mQueue(1024), mWidth(size.x), @@ -2151,6 +2151,10 @@ MeterAx::~MeterAx() { } +MeterPanelBase::~MeterPanelBase() +{ +} + // Performs the default action. childId is 0 (the action for this object) // or > 0 (the action for a child). // Return wxACC_NOT_SUPPORTED if there is no default action for this diff --git a/src/widgets/Meter.h b/src/widgets/Meter.h index f28bcc2d1..6108be1a5 100644 --- a/src/widgets/Meter.h +++ b/src/widgets/Meter.h @@ -87,11 +87,27 @@ class MeterUpdateQueue class MeterAx; +class MeterPanelBase /* not final */ + : public wxPanelWrapper +{ +public: + using wxPanelWrapper::wxPanelWrapper; + ~MeterPanelBase() override; + + virtual void Clear() = 0; + virtual void Reset(double sampleRate, bool resetClipping) = 0; + virtual void UpdateDisplay(unsigned numChannels, + int numFrames, float *sampleData) = 0; + virtual bool IsMeterDisabled() const = 0; + virtual float GetMaxPeak() const = 0; +private: +}; + /********************************************************************//** \brief MeterPanel is a panel that paints the meter used for monitoring or playback. ************************************************************************/ -class MeterPanel final : public wxPanelWrapper, private PrefsListener +class MeterPanel final : public MeterPanelBase, private PrefsListener { DECLARE_DYNAMIC_CLASS(MeterPanel) @@ -121,7 +137,7 @@ class MeterPanel final : public wxPanelWrapper, private PrefsListener void SetFocusFromKbd() override; - void Clear(); + void Clear() override; Style GetStyle() const { return mStyle; } Style GetDesiredStyle() const { return mDesiredStyle; } @@ -132,7 +148,7 @@ class MeterPanel final : public wxPanelWrapper, private PrefsListener * This method is thread-safe! Feel free to call from a * different thread (like from an audio I/O callback). */ - void Reset(double sampleRate, bool resetClipping); + void Reset(double sampleRate, bool resetClipping) override; /** \brief Update the meters with a block of audio data * @@ -157,7 +173,7 @@ class MeterPanel final : public wxPanelWrapper, private PrefsListener * The second overload is for ease of use in MixerBoard. */ void UpdateDisplay(unsigned numChannels, - int numFrames, float *sampleData); + int numFrames, float *sampleData) override; // Vaughan, 2010-11-29: This not currently used. See comments in MixerTrackCluster::UpdateMeter(). //void UpdateDisplay(int numChannels, int numFrames, @@ -171,9 +187,9 @@ class MeterPanel final : public wxPanelWrapper, private PrefsListener * This method is thread-safe! Feel free to call from a * different thread (like from an audio I/O callback). */ - bool IsMeterDisabled() const; + bool IsMeterDisabled() const override; - float GetMaxPeak() const; + float GetMaxPeak() const override; bool IsClipping() const;