DPF

DISTRHO Plugin Framework
Log | Files | Refs | Submodules | README | LICENSE

commit 70cec6a9d0222b32abdcaec02cd7b01378c4d78b
parent 6a26ce4147345dd1949595204a1a4242cbd4e34c
Author: Patrick Desaulniers <desaulniers.patrick@carrefour.cegepvicto.ca>
Date:   Sun, 11 Mar 2018 07:36:07 -0400

Set VST parameter hints where useful (#39)

* Set VST parameter hints where useful

* Set proper vst parameter display depending on hints

* Add support for kVstParameterCanRamp

* Use good flag for kVstParameterCanRamp

* Don't force on/off text + minor changes

* Prefer bool flag and zero-init parameter properties

* Misc changes

* Consider params that are both int and bool in ParamDisplay

* Round int parameters properly in ParamDisplay

* Refactor if/else in ParamDisplay

Diffstat:
Mdistrho/src/DistrhoPluginVST.cpp | 63++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 62 insertions(+), 1 deletion(-)

diff --git a/distrho/src/DistrhoPluginVST.cpp b/distrho/src/DistrhoPluginVST.cpp @@ -82,6 +82,12 @@ void snprintf_param(char* const dst, const float value, const size_t size) dst[size-1] = '\0'; } +void snprintf_iparam(char* const dst, const int32_t value, const size_t size) +{ + std::snprintf(dst, size-1, "%d", value); + dst[size-1] = '\0'; +} + #if DISTRHO_PLUGIN_HAS_UI // ----------------------------------------------------------------------- @@ -445,7 +451,26 @@ public: case effGetParamDisplay: if (ptr != nullptr && index < static_cast<int32_t>(fPlugin.getParameterCount())) { - DISTRHO_NAMESPACE::snprintf_param((char*)ptr, fPlugin.getParameterValue(index), 24); + const uint32_t hints = fPlugin.getParameterHints(index); + float value = fPlugin.getParameterValue(index); + + if (hints & kParameterIsBoolean) + { + const ParameterRanges& ranges(fPlugin.getParameterRanges(index)); + const float midRange = ranges.min + (ranges.max - ranges.min) / 2.0f; + + value = value > midRange ? ranges.max : ranges.min; + } + + if (hints & kParameterIsInteger) + { + DISTRHO_NAMESPACE::snprintf_iparam((char*)ptr, (int32_t)std::round(value), 24); + } + else + { + DISTRHO_NAMESPACE::snprintf_param((char*)ptr, value, 24); + } + return 1; } break; @@ -1058,7 +1083,43 @@ static intptr_t vst_dispatcherCallback(AEffect* effect, int32_t opcode, int32_t return 1; } return 0; + + case effGetParameterProperties: + if (ptr != nullptr && index < static_cast<int32_t>(plugin.getParameterCount())) + { + if (VstParameterProperties* const properties = (VstParameterProperties*)ptr) + { + memset(properties, 0, sizeof(VstParameterProperties)); + + const uint32_t hints = plugin.getParameterHints(index); + if (hints & kParameterIsOutput) + return 1; + + if (hints & kParameterIsBoolean) + { + properties->flags |= kVstParameterIsSwitch; + } + + if (hints & kParameterIsInteger) + { + properties->flags |= kVstParameterUsesIntegerMinMax; + const ParameterRanges& ranges(plugin.getParameterRanges(index)); + + properties->minInteger = static_cast<int32_t>(ranges.min); + properties->maxInteger = static_cast<int32_t>(ranges.max); + } + + if (hints & kParameterIsLogarithmic) + { + properties->flags |= kVstParameterCanRamp; + } + + return 1; + } + } + return 0; + case effGetPlugCategory: #if DISTRHO_PLUGIN_IS_SYNTH return kPlugCategSynth;