From 45b1d009deb663e6ae27fbb092a1886e77d0653f Mon Sep 17 00:00:00 2001 From: Damien Zammit Date: Sun, 29 Oct 2017 12:54:07 +1100 Subject: ZamVerb: Use state to swap out convolver for new one --- plugins/ZamVerb/DistrhoPluginInfo.h | 2 +- plugins/ZamVerb/ZamVerbPlugin.cpp | 55 +++++++++++++++++++++++++++++-------- plugins/ZamVerb/ZamVerbPlugin.hpp | 10 +++++-- plugins/ZamVerb/ZamVerbUI.cpp | 4 +++ plugins/ZamVerb/ZamVerbUI.hpp | 1 + 5 files changed, 56 insertions(+), 16 deletions(-) diff --git a/plugins/ZamVerb/DistrhoPluginInfo.h b/plugins/ZamVerb/DistrhoPluginInfo.h index 3e0dc8d..590d0b8 100644 --- a/plugins/ZamVerb/DistrhoPluginInfo.h +++ b/plugins/ZamVerb/DistrhoPluginInfo.h @@ -29,7 +29,7 @@ #define DISTRHO_PLUGIN_WANT_LATENCY 0 #define DISTRHO_PLUGIN_WANT_PROGRAMS 1 -#define DISTRHO_PLUGIN_WANT_STATE 0 +#define DISTRHO_PLUGIN_WANT_STATE 1 #define DISTRHO_PLUGIN_WANT_TIMEPOS 0 #define DISTRHO_PLUGIN_URI "urn:zamaudio:ZamVerb" diff --git a/plugins/ZamVerb/ZamVerbPlugin.cpp b/plugins/ZamVerb/ZamVerbPlugin.cpp index e4383d0..ff3ca30 100644 --- a/plugins/ZamVerb/ZamVerbPlugin.cpp +++ b/plugins/ZamVerb/ZamVerbPlugin.cpp @@ -22,11 +22,16 @@ START_NAMESPACE_DISTRHO // ----------------------------------------------------------------------- ZamVerbPlugin::ZamVerbPlugin() - : Plugin(paramCount, 1, 0) // 1 program, 0 states + : Plugin(paramCount, 1, 1) // 1 program, 1 states { - clv = new LV2convolv(); - clv->clv_configure("convolution.ir.preset", "0"); - clv->clv_initialize(getSampleRate(), 2, 2, getBufferSize()); + swap = 0; + clv[swap] = new LV2convolv(); + clv[swap]->clv_configure("convolution.ir.preset", "0"); + clv[swap]->clv_initialize(getSampleRate(), 2, 2, getBufferSize()); + + clv[1] = new LV2convolv(); + clv[1]->clv_configure("convolution.ir.preset", "0"); + clv[1]->clv_initialize(getSampleRate(), 2, 2, getBufferSize()); // Extra buffer for outputs since plugin can work in place tmpouts = (float **)malloc (2 * sizeof(float*)); @@ -52,7 +57,8 @@ ZamVerbPlugin::~ZamVerbPlugin() free(tmpins[1]); free(tmpins); - delete clv; + delete clv[0]; + delete clv[1]; } // ----------------------------------------------------------------------- @@ -157,26 +163,51 @@ void ZamVerbPlugin::loadProgram(uint32_t index) void ZamVerbPlugin::activate() { +} +String ZamVerbPlugin::getState(const char*) const +{ + return String(""); +} + + +void ZamVerbPlugin::initState(unsigned int index, String& key, String& defval) +{ + if (index == 0) { + key = "reload"; + } + defval = ""; +} + +void ZamVerbPlugin::setState(const char* key, const char*) +{ + uint8_t other = (swap == 0) ? 1 : 0; + char preset[2] = { '\0' }; + + if (strcmp(key, "reload") == 0) { + snprintf(preset, 2, "%d", (int)room); + clv[other]->clv_release(); + clv[other]->clv_configure("convolution.ir.preset", preset); + clv[other]->clv_initialize(getSampleRate(), 2, 2, getBufferSize()); + swap = other; + } } void ZamVerbPlugin::run(const float** inputs, float** outputs, uint32_t frames) { uint32_t i; int nprocessed; - char preset[2] = { '\0' }; - if ((int)room_old != (int)room) { - snprintf(preset, 2, "%d", (int)room); - clv->clv_release(); - clv->clv_configure("convolution.ir.preset", preset); - clv->clv_initialize(getSampleRate(), 2, 2, frames); + uint32_t bufsize = getBufferSize(); + if ( ((int)room_old != (int)room) || (bufsize_old != bufsize) ) { + setState("reload", ""); + bufsize_old = bufsize; room_old = room; } assert(frames < 8192); memcpy(tmpins[0], inputs[0], frames * sizeof(float)); memcpy(tmpins[1], inputs[1], frames * sizeof(float)); - nprocessed = clv->clv_convolve(tmpins, tmpouts, 2, 2, frames, from_dB(-16.)); + nprocessed = clv[swap]->clv_convolve(tmpins, tmpouts, 2, 2, frames, from_dB(-16.)); if (nprocessed <= 0) { memcpy(outputs[0], inputs[0], frames * sizeof(float)); memcpy(outputs[1], inputs[1], frames * sizeof(float)); diff --git a/plugins/ZamVerb/ZamVerbPlugin.hpp b/plugins/ZamVerb/ZamVerbPlugin.hpp index d114fe1..f110bdb 100644 --- a/plugins/ZamVerb/ZamVerbPlugin.hpp +++ b/plugins/ZamVerb/ZamVerbPlugin.hpp @@ -68,7 +68,7 @@ protected: uint32_t getVersion() const noexcept override { - return d_version(3, 8, 0); + return d_version(3, 9, 0); } int64_t getUniqueId() const noexcept override @@ -88,7 +88,9 @@ protected: float getParameterValue(uint32_t index) const override; void setParameterValue(uint32_t index, float value) override; void loadProgram(uint32_t index) override; - + void setState(const char *key, const char *index) override; + String getState(const char* key) const override; + void initState(unsigned int index, String& key, String& defval) override; // ------------------------------------------------------------------- // Process @@ -112,7 +114,9 @@ protected: void activate() override; void run(const float** inputs, float** outputs, uint32_t frames) override; - LV2convolv *clv; + LV2convolv *clv[2]; + uint8_t swap; + uint32_t bufsize_old; // ------------------------------------------------------------------- float **tmpouts; diff --git a/plugins/ZamVerb/ZamVerbUI.cpp b/plugins/ZamVerb/ZamVerbUI.cpp index 7ac445d..1695007 100644 --- a/plugins/ZamVerb/ZamVerbUI.cpp +++ b/plugins/ZamVerb/ZamVerbUI.cpp @@ -100,6 +100,10 @@ void ZamVerbUI::programLoaded(uint32_t index) fSliderNotch->setValue(0.0f); } +void ZamVerbUI::stateChanged(const char*, const char*) +{ +} + // ----------------------------------------------------------------------- // Widget Callbacks diff --git a/plugins/ZamVerb/ZamVerbUI.hpp b/plugins/ZamVerb/ZamVerbUI.hpp index 8cbe72c..e3234f9 100644 --- a/plugins/ZamVerb/ZamVerbUI.hpp +++ b/plugins/ZamVerb/ZamVerbUI.hpp @@ -43,6 +43,7 @@ protected: void parameterChanged(uint32_t index, float value) override; void programLoaded(uint32_t index) override; + void stateChanged(const char*, const char*) override; // ------------------------------------------------------------------- // Widget Callbacks -- cgit v1.2.3