From 4c2dba0822f77bc4f9a2c9710ce351633e1e0319 Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 20 Oct 2021 19:20:01 +0100 Subject: [PATCH] VST3 Client: Ensure that all programs can be selected via parameter in hosts Hosts such as REAPER normalise the program parameter value by dividing the program value by the step count, rather than going via the parameter's toNormalized function. To be compatible, we should use the same scaling technique. At time of writing, the coversion process is detailed under the heading "Conversion of normalized values" on this page: https://developer.steinberg.help/display/VST/Parameters+and+Automation --- .../VST3/juce_VST3_Wrapper.cpp | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp b/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp index 2263c6aaca..89ccf074f1 100644 --- a/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp @@ -824,20 +824,17 @@ public: bool setNormalized (Vst::ParamValue v) override { - auto programValue = roundToInt (toPlain (v)); + const auto programValue = getProgramValueFromNormalised (v); - if (isPositiveAndBelow (programValue, owner.getNumPrograms())) - { - if (programValue != owner.getCurrentProgram()) - owner.setCurrentProgram (programValue); + if (programValue != owner.getCurrentProgram()) + owner.setCurrentProgram (programValue); - if (valueNormalized != v) - { - valueNormalized = v; - changed(); + if (valueNormalized != v) + { + valueNormalized = v; + changed(); - return true; - } + return true; } return false; @@ -870,8 +867,13 @@ public: return String (CharPointer_UTF16 (reinterpret_cast (text))); } - Vst::ParamValue toPlain (Vst::ParamValue v) const override { return v * (info.stepCount + 1); } - Vst::ParamValue toNormalized (Vst::ParamValue v) const override { return v / (info.stepCount + 1); } + Steinberg::int32 getProgramValueFromNormalised (Vst::ParamValue v) const + { + return jmin (info.stepCount, (Steinberg::int32) (v * (info.stepCount + 1))); + } + + Vst::ParamValue toPlain (Vst::ParamValue v) const override { return getProgramValueFromNormalised (v); } + Vst::ParamValue toNormalized (Vst::ParamValue v) const override { return v / info.stepCount; } private: AudioProcessor& owner;