Browse Source

Change VST2 dummy plugin to be pointer cleared on effClose

Signed-off-by: falkTX <falktx@falktx.com>
pull/321/head
falkTX 2 years ago
parent
commit
33dd907dba
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
2 changed files with 44 additions and 41 deletions
  1. +0
    -3
      distrho/src/DistrhoPluginInternal.hpp
  2. +44
    -38
      distrho/src/DistrhoPluginVST2.cpp

+ 0
- 3
distrho/src/DistrhoPluginInternal.hpp View File

@@ -954,9 +954,6 @@ private:
static const PortGroupWithId sFallbackPortGroup; static const PortGroupWithId sFallbackPortGroup;


DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PluginExporter) DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PluginExporter)
#ifndef DISTRHO_PLUGIN_TARGET_VST3 /* there is no way around this for VST3 */
DISTRHO_PREVENT_HEAP_ALLOCATION
#endif
}; };


// ----------------------------------------------------------------------- // -----------------------------------------------------------------------


+ 44
- 38
distrho/src/DistrhoPluginVST2.cpp View File

@@ -1386,33 +1386,38 @@ struct VstObject {
#define vstObjectPtr (VstObject*)effect->object #define vstObjectPtr (VstObject*)effect->object
#define pluginPtr (vstObjectPtr)->plugin #define pluginPtr (vstObjectPtr)->plugin


static ScopedPointer<PluginExporter> sPlugin;

static intptr_t vst_dispatcherCallback(AEffect* effect, int32_t opcode, int32_t index, intptr_t value, void* ptr, float opt) static intptr_t vst_dispatcherCallback(AEffect* effect, int32_t opcode, int32_t index, intptr_t value, void* ptr, float opt)
{ {
// first internal init // first internal init
const bool doInternalInit = (opcode == -1729 && index == 0xdead && value == 0xf00d); const bool doInternalInit = (opcode == -1729 && index == 0xdead && value == 0xf00d);


if (doInternalInit)
if (doInternalInit || opcode == effOpen)
{ {
// set valid but dummy values
d_nextBufferSize = 512;
d_nextSampleRate = 44100.0;
d_nextPluginIsDummy = true;
d_nextCanRequestParameterValueChanges = true;
}
if (sPlugin == nullptr)
{
// set valid but dummy values
d_nextBufferSize = 512;
d_nextSampleRate = 44100.0;
d_nextPluginIsDummy = true;
d_nextCanRequestParameterValueChanges = true;


// Create dummy plugin to get data from
static PluginExporter plugin(nullptr, nullptr, nullptr, nullptr);
// Create dummy plugin to get data from
sPlugin = new PluginExporter(nullptr, nullptr, nullptr, nullptr);


if (doInternalInit)
{
// unset
d_nextBufferSize = 0;
d_nextSampleRate = 0.0;
d_nextPluginIsDummy = false;
d_nextCanRequestParameterValueChanges = false;
// unset
d_nextBufferSize = 0;
d_nextSampleRate = 0.0;
d_nextPluginIsDummy = false;
d_nextCanRequestParameterValueChanges = false;
}


*(PluginExporter**)ptr = &plugin;
return 0;
if (doInternalInit)
{
*(PluginExporter**)ptr = sPlugin.get();
return 0;
}
} }


// handle base opcodes // handle base opcodes
@@ -1462,33 +1467,34 @@ static intptr_t vst_dispatcherCallback(AEffect* effect, int32_t opcode, int32_t
delete obj; delete obj;
#endif #endif


sPlugin = nullptr;
return 1; return 1;
} }
//delete effect; //delete effect;
return 0; return 0;


case effGetParamLabel: case effGetParamLabel:
if (ptr != nullptr && index < static_cast<int32_t>(plugin.getParameterCount()))
if (ptr != nullptr && index < static_cast<int32_t>(sPlugin->getParameterCount()))
{ {
DISTRHO_NAMESPACE::strncpy((char*)ptr, plugin.getParameterUnit(index), 8);
DISTRHO_NAMESPACE::strncpy((char*)ptr, sPlugin->getParameterUnit(index), 8);
return 1; return 1;
} }
return 0; return 0;


case effGetParamName: case effGetParamName:
if (ptr != nullptr && index < static_cast<int32_t>(plugin.getParameterCount()))
if (ptr != nullptr && index < static_cast<int32_t>(sPlugin->getParameterCount()))
{ {
const String& shortName(plugin.getParameterShortName(index));
const String& shortName(sPlugin->getParameterShortName(index));
if (shortName.isNotEmpty()) if (shortName.isNotEmpty())
DISTRHO_NAMESPACE::strncpy((char*)ptr, shortName, 16); DISTRHO_NAMESPACE::strncpy((char*)ptr, shortName, 16);
else else
DISTRHO_NAMESPACE::strncpy((char*)ptr, plugin.getParameterName(index), 16);
DISTRHO_NAMESPACE::strncpy((char*)ptr, sPlugin->getParameterName(index), 16);
return 1; return 1;
} }
return 0; return 0;


case effGetParameterProperties: case effGetParameterProperties:
if (ptr != nullptr && index < static_cast<int32_t>(plugin.getParameterCount()))
if (ptr != nullptr && index < static_cast<int32_t>(sPlugin->getParameterCount()))
{ {
if (VstParameterProperties* const properties = (VstParameterProperties*)ptr) if (VstParameterProperties* const properties = (VstParameterProperties*)ptr)
{ {
@@ -1496,19 +1502,19 @@ static intptr_t vst_dispatcherCallback(AEffect* effect, int32_t opcode, int32_t


// full name // full name
DISTRHO_NAMESPACE::strncpy(properties->label, DISTRHO_NAMESPACE::strncpy(properties->label,
plugin.getParameterName(index),
sPlugin->getParameterName(index),
sizeof(properties->label)); sizeof(properties->label));


// short name // short name
const String& shortName(plugin.getParameterShortName(index));
const String& shortName(sPlugin->getParameterShortName(index));


if (shortName.isNotEmpty()) if (shortName.isNotEmpty())
DISTRHO_NAMESPACE::strncpy(properties->shortLabel, DISTRHO_NAMESPACE::strncpy(properties->shortLabel,
plugin.getParameterShortName(index),
sPlugin->getParameterShortName(index),
sizeof(properties->shortLabel)); sizeof(properties->shortLabel));


// parameter hints // parameter hints
const uint32_t hints = plugin.getParameterHints(index);
const uint32_t hints = sPlugin->getParameterHints(index);


if (hints & kParameterIsOutput) if (hints & kParameterIsOutput)
return 1; return 1;
@@ -1520,7 +1526,7 @@ static intptr_t vst_dispatcherCallback(AEffect* effect, int32_t opcode, int32_t


if (hints & kParameterIsInteger) if (hints & kParameterIsInteger)
{ {
const ParameterRanges& ranges(plugin.getParameterRanges(index));
const ParameterRanges& ranges(sPlugin->getParameterRanges(index));
properties->flags |= kVstParameterUsesIntegerMinMax; properties->flags |= kVstParameterUsesIntegerMinMax;
properties->minInteger = static_cast<int32_t>(ranges.min); properties->minInteger = static_cast<int32_t>(ranges.min);
properties->maxInteger = static_cast<int32_t>(ranges.max); properties->maxInteger = static_cast<int32_t>(ranges.max);
@@ -1532,14 +1538,14 @@ static intptr_t vst_dispatcherCallback(AEffect* effect, int32_t opcode, int32_t
} }


// parameter group (category in vst) // parameter group (category in vst)
const uint32_t groupId = plugin.getParameterGroupId(index);
const uint32_t groupId = sPlugin->getParameterGroupId(index);


if (groupId != kPortGroupNone) if (groupId != kPortGroupNone)
{ {
// we can't use groupId directly, so use the index array where this group is stored in // we can't use groupId directly, so use the index array where this group is stored in
for (uint32_t i=0, count=plugin.getPortGroupCount(); i < count; ++i)
for (uint32_t i=0, count=sPlugin->getPortGroupCount(); i < count; ++i)
{ {
const PortGroupWithId& portGroup(plugin.getPortGroupByIndex(i));
const PortGroupWithId& portGroup(sPlugin->getPortGroupByIndex(i));


if (portGroup.groupId == groupId) if (portGroup.groupId == groupId)
{ {
@@ -1553,8 +1559,8 @@ static intptr_t vst_dispatcherCallback(AEffect* effect, int32_t opcode, int32_t


if (properties->category != 0) if (properties->category != 0)
{ {
for (uint32_t i=0, count=plugin.getParameterCount(); i < count; ++i)
if (plugin.getParameterGroupId(i) == groupId)
for (uint32_t i=0, count=sPlugin->getParameterCount(); i < count; ++i)
if (sPlugin->getParameterGroupId(i) == groupId)
++properties->numParametersInCategory; ++properties->numParametersInCategory;
} }
} }
@@ -1574,7 +1580,7 @@ static intptr_t vst_dispatcherCallback(AEffect* effect, int32_t opcode, int32_t
case effGetEffectName: case effGetEffectName:
if (char* const cptr = (char*)ptr) if (char* const cptr = (char*)ptr)
{ {
DISTRHO_NAMESPACE::strncpy(cptr, plugin.getName(), 32);
DISTRHO_NAMESPACE::strncpy(cptr, sPlugin->getName(), 32);
return 1; return 1;
} }
return 0; return 0;
@@ -1582,7 +1588,7 @@ static intptr_t vst_dispatcherCallback(AEffect* effect, int32_t opcode, int32_t
case effGetVendorString: case effGetVendorString:
if (char* const cptr = (char*)ptr) if (char* const cptr = (char*)ptr)
{ {
DISTRHO_NAMESPACE::strncpy(cptr, plugin.getMaker(), 32);
DISTRHO_NAMESPACE::strncpy(cptr, sPlugin->getMaker(), 32);
return 1; return 1;
} }
return 0; return 0;
@@ -1590,13 +1596,13 @@ static intptr_t vst_dispatcherCallback(AEffect* effect, int32_t opcode, int32_t
case effGetProductString: case effGetProductString:
if (char* const cptr = (char*)ptr) if (char* const cptr = (char*)ptr)
{ {
DISTRHO_NAMESPACE::strncpy(cptr, plugin.getLabel(), 32);
DISTRHO_NAMESPACE::strncpy(cptr, sPlugin->getLabel(), 32);
return 1; return 1;
} }
return 0; return 0;


case effGetVendorVersion: case effGetVendorVersion:
return plugin.getVersion();
return sPlugin->getVersion();


case effGetVstVersion: case effGetVstVersion:
return kVstVersion; return kVstVersion;


Loading…
Cancel
Save