From e9e67c07742e27e5ce5c76a4ec56db464132c004 Mon Sep 17 00:00:00 2001 From: Joep Vanlier Date: Sun, 8 Dec 2024 14:56:28 +0100 Subject: [PATCH] dummy parameter test --- plugin/parameter.cpp | 5 +++++ plugin/parameter.h | 7 +++++++ plugin/processor.cpp | 14 ++++++++++++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/plugin/parameter.cpp b/plugin/parameter.cpp index 6189812f..e0309ce2 100644 --- a/plugin/parameter.cpp +++ b/plugin/parameter.cpp @@ -17,6 +17,11 @@ #include "parameter.h" +DummyParameter::DummyParameter(void) : AudioParameterFloat("__state_change_parameter__", "Internal state change", 0.0f, 1.0f, 0.5f) {}; +bool DummyParameter::isAutomatable(void) const { + return false; +}; + YsfxParameter::YsfxParameter(ysfx_t *fx, int sliderIndex) : RangedAudioParameter( "slider" + juce::String(sliderIndex + 1), diff --git a/plugin/parameter.h b/plugin/parameter.h index 42708cbf..a7cef570 100644 --- a/plugin/parameter.h +++ b/plugin/parameter.h @@ -19,6 +19,13 @@ #include "ysfx.h" #include +// Dummy parameter to force state saving +class DummyParameter final : public juce::AudioParameterFloat { + public: + explicit DummyParameter(); + bool isAutomatable() const override; +}; + class YsfxParameter final : public juce::RangedAudioParameter { public: explicit YsfxParameter(ysfx_t *fx, int sliderIndex); diff --git a/plugin/processor.cpp b/plugin/processor.cpp index 8c469514..ac63da5b 100644 --- a/plugin/processor.cpp +++ b/plugin/processor.cpp @@ -123,13 +123,14 @@ struct YsfxProcessor::Impl : public juce::AudioProcessorListener { class ManualUndoPointUpdater : public juce::AsyncUpdater { public: - explicit ManualUndoPointUpdater(Impl *impl) : m_impl{impl} {} + explicit ManualUndoPointUpdater(Impl *impl, DummyParameter* dummy) : m_impl{impl}, m_dummy{dummy} {} protected: void handleAsyncUpdate() override; private: Impl *m_impl = nullptr; + DummyParameter* m_dummy = nullptr; }; std::unique_ptr m_manualUndoPointUpdater; @@ -232,7 +233,11 @@ YsfxProcessor::YsfxProcessor() m_impl->m_deferredUpdateHostDisplay.reset(new Impl::DeferredUpdateHostDisplay(m_impl.get())); /// - m_impl->m_manualUndoPointUpdater.reset(new Impl::ManualUndoPointUpdater(m_impl.get())); + // Unfortunately, some DAWs ignore dirty flags for the state chunk. That's why we introduce + // a dummy variable that forces serialization when the JSFX requests for the state to be stored. + DummyParameter* dummy = new DummyParameter(); + addParameter(dummy); + m_impl->m_manualUndoPointUpdater.reset(new Impl::ManualUndoPointUpdater(m_impl.get(), dummy)); /// m_impl->m_background.reset(new Impl::Background(m_impl.get())); @@ -1024,6 +1029,11 @@ void YsfxProcessor::Impl::DeferredUpdateHostDisplay::handleAsyncUpdate() void YsfxProcessor::Impl::ManualUndoPointUpdater::handleAsyncUpdate() { + JUCE_ASSERT_MESSAGE_THREAD + + float r = static_cast(rand()) / static_cast (RAND_MAX); + m_dummy->setValueNotifyingHost(r); + m_impl->m_self->updateHostDisplay(ChangeDetails().withNonParameterStateChanged(true)); }