summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfalkTX <falktx@gmail.com>2018-08-04 04:38:36 +0200
committerfalkTX <falktx@gmail.com>2018-08-04 04:38:36 +0200
commit5f65434e573abb86d9ee05a441024579e91892c4 (patch)
tree7c37a4e3b3f8c1ff9f858cfbb42f8944b886fb79
parentc2b9c40333a7b5e066dcb8d60fa023373b639324 (diff)
Implement triggers in all formats; Allow VST to use param outputs
-rw-r--r--distrho/DistrhoPlugin.hpp7
-rw-r--r--distrho/src/DistrhoPluginJack.cpp19
-rw-r--r--distrho/src/DistrhoPluginLADSPA+DSSI.cpp32
-rw-r--r--distrho/src/DistrhoPluginLV2.cpp24
-rw-r--r--distrho/src/DistrhoPluginLV2export.cpp4
-rw-r--r--distrho/src/DistrhoPluginVST.cpp94
6 files changed, 135 insertions, 45 deletions
diff --git a/distrho/DistrhoPlugin.hpp b/distrho/DistrhoPlugin.hpp
index cbafc47c..2fb9ec6f 100644
--- a/distrho/DistrhoPlugin.hpp
+++ b/distrho/DistrhoPlugin.hpp
@@ -90,8 +90,11 @@ static const uint32_t kParameterIsLogarithmic = 0x08;
static const uint32_t kParameterIsOutput = 0x10;
/**
- Parameter value is a trigger.
- @note Cannot be used for output parameters
+ Parameter value is a trigger.@n
+ This means the value resets back to its default after each process/run call.@n
+ Cannot be used for output parameters.
+
+ @note Only officially supported under LV2. For other formats DPF simulates the behaviour.
*/
static const uint32_t kParameterIsTrigger = 0x20 | kParameterIsBoolean;
diff --git a/distrho/src/DistrhoPluginJack.cpp b/distrho/src/DistrhoPluginJack.cpp
index dfa60fb0..1d0a8c37 100644
--- a/distrho/src/DistrhoPluginJack.cpp
+++ b/distrho/src/DistrhoPluginJack.cpp
@@ -430,6 +430,8 @@ protected:
#if DISTRHO_PLUGIN_WANT_MIDI_OUTPUT
fPortMidiOutBuffer = nullptr;
#endif
+
+ updateParameterTriggers();
}
void jackShutdown()
@@ -474,6 +476,23 @@ protected:
}
#endif
+ // NOTE: no trigger support for JACK, simulate it here
+ void updateParameterTriggers()
+ {
+ float defValue;
+
+ for (uint32_t i=0, count=fPlugin.getParameterCount(); i < count; ++i)
+ {
+ if ((fPlugin.getParameterHints(i) & kParameterIsTrigger) != kParameterIsTrigger)
+ continue;
+
+ defValue = fPlugin.getParameterRanges(i).def;
+
+ if (d_isNotEqual(defValue, fPlugin.getParameterValue(i)))
+ fPlugin.setParameterValue(i, defValue);
+ }
+ }
+
// -------------------------------------------------------------------
private:
diff --git a/distrho/src/DistrhoPluginLADSPA+DSSI.cpp b/distrho/src/DistrhoPluginLADSPA+DSSI.cpp
index 40049f28..4ac645bd 100644
--- a/distrho/src/DistrhoPluginLADSPA+DSSI.cpp
+++ b/distrho/src/DistrhoPluginLADSPA+DSSI.cpp
@@ -175,7 +175,7 @@ public:
{
// pre-roll
if (sampleCount == 0)
- return updateParameterOutputs();
+ return updateParameterOutputsAndTriggers();
// Check for updated parameters
float curValue;
@@ -272,7 +272,7 @@ public:
fPlugin.run(fPortAudioIns, fPortAudioOuts, sampleCount);
#endif
- updateParameterOutputs();
+ updateParameterOutputsAndTriggers();
#if defined(DISTRHO_PLUGIN_TARGET_DSSI) && ! DISTRHO_PLUGIN_WANT_MIDI_INPUT
return; // unused
@@ -375,17 +375,33 @@ private:
// -------------------------------------------------------------------
- void updateParameterOutputs()
+ void updateParameterOutputsAndTriggers()
{
+ float value;
+
for (uint32_t i=0, count=fPlugin.getParameterCount(); i < count; ++i)
{
- if (! fPlugin.isParameterOutput(i))
- continue;
+ if (fPlugin.isParameterOutput(i))
+ {
+ value = fLastControlValues[i] = fPlugin.getParameterValue(i);
- fLastControlValues[i] = fPlugin.getParameterValue(i);
+ if (fPortControls[i] != nullptr)
+ *fPortControls[i] = value;
+ }
+ else if ((fPlugin.getParameterHints(i) & kParameterIsTrigger) == kParameterIsTrigger)
+ {
+ // NOTE: no trigger support in LADSPA control ports, simulate it here
+ const float value = fPlugin.getParameterRanges(i).def;
- if (fPortControls[i] != nullptr)
- *fPortControls[i] = fLastControlValues[i];
+ if (d_isEqual(value, fPlugin.getParameterValue(i)))
+ continue;
+
+ fLastControlValues[i] = value;
+ fPlugin.setParameterValue(i, value);
+
+ if (fPortControls[i] != nullptr)
+ *fPortControls[i] = value;
+ }
}
#if DISTRHO_PLUGIN_WANT_LATENCY
diff --git a/distrho/src/DistrhoPluginLV2.cpp b/distrho/src/DistrhoPluginLV2.cpp
index 9edcf8fd..41f2d7c1 100644
--- a/distrho/src/DistrhoPluginLV2.cpp
+++ b/distrho/src/DistrhoPluginLV2.cpp
@@ -524,9 +524,7 @@ public:
fLastControlValues[i] = curValue;
if (fPlugin.getParameterDesignation(i) == kParameterDesignationBypass)
- {
curValue = 1.0f - curValue;
- }
fPlugin.setParameterValue(i, curValue);
}
@@ -609,7 +607,7 @@ public:
#endif
}
- updateParameterOutputs();
+ updateParameterOutputsAndTriggers();
#if DISTRHO_PLUGIN_WANT_STATE && DISTRHO_PLUGIN_HAS_UI
fEventsOutData.initIfNeeded(fURIDs.atomSequence);
@@ -1032,17 +1030,23 @@ private:
}
#endif
- void updateParameterOutputs()
+ void updateParameterOutputsAndTriggers()
{
+ float curValue;
+
for (uint32_t i=0, count=fPlugin.getParameterCount(); i < count; ++i)
{
- if (! fPlugin.isParameterOutput(i))
- continue;
-
- fLastControlValues[i] = fPlugin.getParameterValue(i);
+ if (fPlugin.isParameterOutput(i))
+ {
+ curValue = fLastControlValues[i] = fPlugin.getParameterValue(i);
- if (fPortControls[i] != nullptr)
- *fPortControls[i] = fLastControlValues[i];
+ if (fPortControls[i] != nullptr)
+ *fPortControls[i] = curValue;
+ }
+ else if ((fPlugin.getParameterHints(i) & kParameterIsTrigger) == kParameterIsTrigger)
+ {
+ // NOTE: host is responsible for auto-updating control port buffers
+ }
}
#if DISTRHO_PLUGIN_WANT_LATENCY
diff --git a/distrho/src/DistrhoPluginLV2export.cpp b/distrho/src/DistrhoPluginLV2export.cpp
index 0511add7..2d001731 100644
--- a/distrho/src/DistrhoPluginLV2export.cpp
+++ b/distrho/src/DistrhoPluginLV2export.cpp
@@ -522,7 +522,11 @@ void lv2_generate_ttl(const char* const basename)
const uint32_t hints(plugin.getParameterHints(i));
if (hints & kParameterIsBoolean)
+ {
+ if ((hints & kParameterIsTrigger) == kParameterIsTrigger)
+ pluginString += " lv2:portProperty <" LV2_PORT_PROPS__trigger "> ;\n";
pluginString += " lv2:portProperty lv2:toggled ;\n";
+ }
if (hints & kParameterIsInteger)
pluginString += " lv2:portProperty lv2:integer ;\n";
if (hints & kParameterIsLogarithmic)
diff --git a/distrho/src/DistrhoPluginVST.cpp b/distrho/src/DistrhoPluginVST.cpp
index 7c6ad521..c7a39557 100644
--- a/distrho/src/DistrhoPluginVST.cpp
+++ b/distrho/src/DistrhoPluginVST.cpp
@@ -94,17 +94,16 @@ void snprintf_iparam(char* const dst, const int32_t value, const size_t size)
dst[size-1] = '\0';
}
-#if DISTRHO_PLUGIN_HAS_UI
// -----------------------------------------------------------------------
-class UiHelper
+class ParameterCheckHelper
{
public:
- UiHelper()
+ ParameterCheckHelper()
: parameterChecks(nullptr),
parameterValues(nullptr) {}
- virtual ~UiHelper()
+ virtual ~ParameterCheckHelper()
{
if (parameterChecks != nullptr)
{
@@ -121,17 +120,18 @@ public:
bool* parameterChecks;
float* parameterValues;
-# if DISTRHO_PLUGIN_WANT_STATE
+#if DISTRHO_PLUGIN_WANT_STATE
virtual void setStateFromUI(const char* const newKey, const char* const newValue) = 0;
-# endif
+#endif
};
+#if DISTRHO_PLUGIN_HAS_UI
// -----------------------------------------------------------------------
class UIVst
{
public:
- UIVst(const audioMasterCallback audioMaster, AEffect* const effect, UiHelper* const uiHelper, PluginExporter* const plugin, const intptr_t winId)
+ UIVst(const audioMasterCallback audioMaster, AEffect* const effect, ParameterCheckHelper* const uiHelper, PluginExporter* const plugin, const intptr_t winId)
: fAudioMaster(audioMaster),
fEffect(effect),
fUiHelper(uiHelper),
@@ -306,7 +306,7 @@ private:
// Vst stuff
const audioMasterCallback fAudioMaster;
AEffect* const fEffect;
- UiHelper* const fUiHelper;
+ ParameterCheckHelper* const fUiHelper;
PluginExporter* const fPlugin;
// Plugin UI
@@ -349,11 +349,7 @@ private:
// -----------------------------------------------------------------------
-#if DISTRHO_PLUGIN_HAS_UI
-class PluginVst : public UiHelper
-#else
-class PluginVst
-#endif
+class PluginVst : public ParameterCheckHelper
{
public:
PluginVst(const audioMasterCallback audioMaster, AEffect* const effect)
@@ -383,7 +379,7 @@ public:
for (uint32_t i=0; i < paramCount; ++i)
{
parameterChecks[i] = false;
- parameterValues[i] = 0.0f;
+ parameterValues[i] = NAN;
}
}
# if DISTRHO_OS_MAC
@@ -823,7 +819,10 @@ public:
void vst_processReplacing(const float** const inputs, float** const outputs, const int32_t sampleFrames)
{
if (sampleFrames <= 0)
+ {
+ updateParameterOutputsAndTriggers();
return;
+ }
if (! fPlugin.isActive())
{
@@ -882,16 +881,7 @@ public:
fPlugin.run(inputs, outputs, sampleFrames);
#endif
-#if DISTRHO_PLUGIN_HAS_UI
- if (fVstUI == nullptr)
- return;
-
- for (uint32_t i=0, count=fPlugin.getParameterCount(); i < count; ++i)
- {
- if (fPlugin.isParameterOutput(i))
- setParameterValueFromPlugin(i, fPlugin.getParameterValue(i));
- }
-#endif
+ updateParameterOutputsAndTriggers();
}
// -------------------------------------------------------------------
@@ -947,6 +937,56 @@ private:
// -------------------------------------------------------------------
// functions called from the plugin side, RT no block
+ void updateParameterOutputsAndTriggers()
+ {
+ float curValue;
+
+ for (uint32_t i=0, count=fPlugin.getParameterCount(); i < count; ++i)
+ {
+ if (fPlugin.isParameterOutput(i))
+ {
+ // NOTE: no output parameter support in VST, simulate it here
+ curValue = fPlugin.getParameterValue(i);
+
+ if (d_isEqual(curValue, parameterValues[i]))
+ continue;
+
+#if DISTRHO_PLUGIN_HAS_UI
+ if (fVstUI != nullptr)
+ setParameterValueFromPlugin(i, curValue);
+ else
+#endif
+ parameterValues[i] = curValue;
+
+#ifndef DPF_VST_SHOW_PARAMETER_OUTPUTS
+ // skip automating parameter outputs from plugin if we disable them on VST
+ continue;
+#endif
+ }
+ else if ((fPlugin.getParameterHints(i) & kParameterIsTrigger) == kParameterIsTrigger)
+ {
+ // NOTE: no trigger support in VST parameters, simulate it here
+ curValue = fPlugin.getParameterValue(i);
+
+ if (d_isEqual(curValue, fPlugin.getParameterRanges(i).def))
+ continue;
+
+#if DISTRHO_PLUGIN_HAS_UI
+ if (fVstUI != nullptr)
+ setParameterValueFromPlugin(i, curValue);
+#endif
+ fPlugin.setParameterValue(i, curValue);
+ }
+ else
+ {
+ continue;
+ }
+
+ const ParameterRanges& ranges(fPlugin.getParameterRanges(i));
+ hostCallback(audioMasterAutomate, i, 0, nullptr, ranges.getNormalizedValue(curValue));
+ }
+ }
+
#if DISTRHO_PLUGIN_HAS_UI
void setParameterValueFromPlugin(const uint32_t index, const float realValue)
{
@@ -1282,7 +1322,10 @@ const AEffect* VSTPluginMain(audioMasterCallback audioMaster)
effect->version = plugin->getVersion();
#endif
- // VST doesn't support parameter outputs, hide them
+ // VST doesn't support parameter outputs. we can fake them, but it is a hack. Disabled by default.
+#ifdef DPF_VST_SHOW_PARAMETER_OUTPUTS
+ const int numParams = plugin->getParameterCount();
+#else
int numParams = 0;
bool outputsReached = false;
@@ -1297,6 +1340,7 @@ const AEffect* VSTPluginMain(audioMasterCallback audioMaster)
}
outputsReached = true;
}
+#endif
// plugin fields
effect->numParams = numParams;