From 9bdc8adf33d1232f01746ea2966d9cab965105cb Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Sun, 5 May 2024 10:05:22 +0200 Subject: [PATCH] Inform effects about changes in enabled model (#7237) Add the virtual method `Effect::onEnabledChanged` which can be overridden by effects so that they can react to state changes with regards to being enabled or bypassed. The call of this methods is connected to state changes of the enabled model in the constructor of `Effect`. Implement the method in `DualFilterEffect` by resetting the history of the two filters. This is done to prevent pops that have been reported in #4612. --- include/Effect.h | 2 ++ plugins/DualFilter/DualFilter.cpp | 5 +++++ plugins/DualFilter/DualFilter.h | 2 ++ src/core/Effect.cpp | 4 ++++ 4 files changed, 13 insertions(+) diff --git a/include/Effect.h b/include/Effect.h index 8b2ff81f0..7180e8275 100644 --- a/include/Effect.h +++ b/include/Effect.h @@ -208,6 +208,8 @@ protected: } void reinitSRC(); + virtual void onEnabledChanged() {} + private: EffectChain * m_parent; diff --git a/plugins/DualFilter/DualFilter.cpp b/plugins/DualFilter/DualFilter.cpp index 4e66db988..40afa342a 100644 --- a/plugins/DualFilter/DualFilter.cpp +++ b/plugins/DualFilter/DualFilter.cpp @@ -218,6 +218,11 @@ bool DualFilterEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames return isRunning(); } +void DualFilterEffect::onEnabledChanged() +{ + m_filter1->clearHistory(); + m_filter2->clearHistory(); +} diff --git a/plugins/DualFilter/DualFilter.h b/plugins/DualFilter/DualFilter.h index c179edbcc..29161039a 100644 --- a/plugins/DualFilter/DualFilter.h +++ b/plugins/DualFilter/DualFilter.h @@ -47,6 +47,8 @@ public: return &m_dfControls; } +protected: + void onEnabledChanged() override; private: DualFilterControls m_dfControls; diff --git a/src/core/Effect.cpp b/src/core/Effect.cpp index 7ede64e6b..aa6e56cd2 100644 --- a/src/core/Effect.cpp +++ b/src/core/Effect.cpp @@ -61,6 +61,10 @@ Effect::Effect( const Plugin::Descriptor * _desc, { m_autoQuitDisabled = true; } + + // Call the virtual method onEnabledChanged so that effects can react to changes, + // e.g. by resetting state. + connect(&m_enabledModel, &BoolModel::dataChanged, [this] { onEnabledChanged(); }); }