From a51cb9f8dbade84554227c8f7f126a13e7791f15 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 26 Sep 2021 22:32:17 +0100 Subject: [PATCH] VST3: trigger restart component for preset and latency changes Signed-off-by: falkTX --- distrho/src/DistrhoPluginVST3.cpp | 31 +++++++++++++++++++++++++++++-- examples/Latency/Makefile | 5 +++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/distrho/src/DistrhoPluginVST3.cpp b/distrho/src/DistrhoPluginVST3.cpp index edd156d3..1d9e5c77 100644 --- a/distrho/src/DistrhoPluginVST3.cpp +++ b/distrho/src/DistrhoPluginVST3.cpp @@ -63,8 +63,7 @@ * - set factory sub_categories * - set factory email (needs new DPF API, useful for LV2 as well) * - do something with get_controller_class_id and set_io_mode? - * - call component handler restart with params-changed flag after changing program (doesnt seem to be needed..?) - * - call component handler restart with latency-changed flag when latency changes + * - replace dpf_message_create with host-side message creation */ START_NAMESPACE_DISTRHO @@ -334,6 +333,9 @@ public: #if DISTRHO_PLUGIN_HAS_UI , fChangedParameterValues(nullptr) #endif +#if DISTRHO_PLUGIN_WANT_LATENCY + , fLastKnownLatency(fPlugin.getLatency()) +#endif #if DISTRHO_PLUGIN_WANT_MIDI_OUTPUT , fHostEventOutputHandle(nullptr) #endif @@ -1295,6 +1297,16 @@ public: { fCurrentProgram = std::round(value * fProgramCountMinusOne); fPlugin.loadProgram(fCurrentProgram); + + for (uint32_t i=0, count=fPlugin.getParameterCount(); i < count; ++i) + { + if (fPlugin.isParameterOutputOrTrigger(i)) + continue; + fParameterValues[i] = fPlugin.getParameterValue(i); + } + + if (fComponentHandler != nullptr) + v3_cpp_obj(fComponentHandler)->restart_component(fComponentHandler, V3_RESTART_PARAM_VALUES_CHANGED); } else #endif @@ -1518,6 +1530,9 @@ private: #if DISTRHO_PLUGIN_HAS_UI bool* fChangedParameterValues; #endif +#if DISTRHO_PLUGIN_WANT_LATENCY + uint32_t fLastKnownLatency; +#endif #if DISTRHO_PLUGIN_WANT_MIDI_INPUT MidiEvent fMidiEvents[kMaxMidiEvents]; # if DISTRHO_PLUGIN_HAS_UI @@ -1577,6 +1592,18 @@ private: requestParameterValueChange(i, curValue); } + +#if DISTRHO_PLUGIN_WANT_LATENCY + const uint32_t latency = fPlugin.getLatency(); + + if (fLastKnownLatency != latency) + { + fLastKnownLatency = latency; + + if (fComponentHandler != nullptr) + v3_cpp_obj(fComponentHandler)->restart_component(fComponentHandler, V3_RESTART_LATENCY_CHANGED); + } +#endif } // ---------------------------------------------------------------------------------------------------------------- diff --git a/examples/Latency/Makefile b/examples/Latency/Makefile index 4b0067b9..51e51564 100644 --- a/examples/Latency/Makefile +++ b/examples/Latency/Makefile @@ -24,8 +24,9 @@ include ../../Makefile.plugins.mk # Enable all possible plugin types TARGETS += ladspa -TARGETS += lv2_dsp -TARGETS += vst +TARGETS += lv2_sep +TARGETS += vst2 +TARGETS += vst3 all: $(TARGETS)