Browse Source

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
pull/44/head
Patrick Desaulniers Filipe Coelho <falktx@falktx.com> 7 years ago
parent
commit
70cec6a9d0
1 changed files with 62 additions and 1 deletions
  1. +62
    -1
      distrho/src/DistrhoPluginVST.cpp

+ 62
- 1
distrho/src/DistrhoPluginVST.cpp View File

@@ -82,6 +82,12 @@ void snprintf_param(char* const dst, const float value, const size_t size)
dst[size-1] = '\0'; 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 #if DISTRHO_PLUGIN_HAS_UI
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------


@@ -445,7 +451,26 @@ public:
case effGetParamDisplay: case effGetParamDisplay:
if (ptr != nullptr && index < static_cast<int32_t>(fPlugin.getParameterCount())) 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; return 1;
} }
break; break;
@@ -1058,7 +1083,43 @@ static intptr_t vst_dispatcherCallback(AEffect* effect, int32_t opcode, int32_t
return 1; return 1;
} }
return 0; 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: case effGetPlugCategory:
#if DISTRHO_PLUGIN_IS_SYNTH #if DISTRHO_PLUGIN_IS_SYNTH
return kPlugCategSynth; return kPlugCategSynth;


Loading…
Cancel
Save