Skip to content

Commit

Permalink
dummy parameter test
Browse files Browse the repository at this point in the history
  • Loading branch information
JoepVanlier committed Dec 15, 2024
1 parent 300e2f2 commit c7b6d12
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
5 changes: 5 additions & 0 deletions plugin/parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
#include "parameter.h"
#include <cmath>

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),
Expand Down
7 changes: 7 additions & 0 deletions plugin/parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
#include "ysfx.h"
#include <juce_audio_processors/juce_audio_processors.h>

// 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);
Expand Down
14 changes: 12 additions & 2 deletions plugin/processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,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<ManualUndoPointUpdater> m_manualUndoPointUpdater;

Expand Down Expand Up @@ -233,7 +234,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()));
Expand Down Expand Up @@ -1035,6 +1040,11 @@ void YsfxProcessor::Impl::DeferredUpdateHostDisplay::handleAsyncUpdate()

void YsfxProcessor::Impl::ManualUndoPointUpdater::handleAsyncUpdate()
{
JUCE_ASSERT_MESSAGE_THREAD

float r = static_cast<float>(rand()) / static_cast <float>(RAND_MAX);
m_dummy->setValueNotifyingHost(r);

m_impl->m_self->updateHostDisplay(ChangeDetails().withNonParameterStateChanged(true));
}

Expand Down

0 comments on commit c7b6d12

Please sign in to comment.