Skip to content

Commit

Permalink
Add Plugin::isDummyInstance() method, useful for some plugins
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed Nov 5, 2021
1 parent 0f31c24 commit ad05572
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 4 deletions.
8 changes: 8 additions & 0 deletions distrho/DistrhoPlugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,14 @@ class Plugin
*/
const char* getBundlePath() const noexcept;

/**
Check if this plugin instance is a "dummy" one used for plugin meta-data/information export.@n
When true no processing will be done, the plugin is created only to extract information.@n
In DPF, LADSPA/DSSI, VST2 and VST3 formats create one global instance per plugin binary
while LV2 creates one when generating turtle meta-data.
*/
bool isDummyInstance() const noexcept;

#if DISTRHO_PLUGIN_WANT_TIMEPOS
/**
Get the current host transport time position.@n
Expand Down
6 changes: 6 additions & 0 deletions distrho/src/DistrhoPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ START_NAMESPACE_DISTRHO
uint32_t d_nextBufferSize = 0;
double d_nextSampleRate = 0.0;
const char* d_nextBundlePath = nullptr;
bool d_nextPluginIsDummy = false;
bool d_nextCanRequestParameterValueChanges = false;

/* ------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -106,6 +107,11 @@ const char* Plugin::getBundlePath() const noexcept
return pData->bundlePath;
}

bool Plugin::isDummyInstance() const noexcept
{
return pData->isDummy;
}

#if DISTRHO_PLUGIN_WANT_TIMEPOS
const TimePosition& Plugin::getTimePosition() const noexcept
{
Expand Down
11 changes: 7 additions & 4 deletions distrho/src/DistrhoPluginInternal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ static const uint32_t kMaxMidiEvents = 512;
extern uint32_t d_nextBufferSize;
extern double d_nextSampleRate;
extern const char* d_nextBundlePath;
extern bool d_nextPluginIsDummy;
extern bool d_nextCanRequestParameterValueChanges;

// -----------------------------------------------------------------------
Expand Down Expand Up @@ -84,6 +85,8 @@ static void fillInPredefinedPortGroupData(const uint32_t groupId, PortGroup& por
// Plugin private data

struct Plugin::PrivateData {
const bool canRequestParameterValueChanges;
const bool isDummy;
bool isProcessing;

#if DISTRHO_PLUGIN_NUM_INPUTS+DISTRHO_PLUGIN_NUM_OUTPUTS > 0
Expand Down Expand Up @@ -124,10 +127,11 @@ struct Plugin::PrivateData {
uint32_t bufferSize;
double sampleRate;
char* bundlePath;
bool canRequestParameterValueChanges;

PrivateData() noexcept
: isProcessing(false),
: canRequestParameterValueChanges(d_nextCanRequestParameterValueChanges),
isDummy(d_nextPluginIsDummy),
isProcessing(false),
#if DISTRHO_PLUGIN_NUM_INPUTS+DISTRHO_PLUGIN_NUM_OUTPUTS > 0
audioPorts(nullptr),
#endif
Expand All @@ -153,8 +157,7 @@ struct Plugin::PrivateData {
requestParameterValueChangeCallbackFunc(nullptr),
bufferSize(d_nextBufferSize),
sampleRate(d_nextSampleRate),
bundlePath(d_nextBundlePath != nullptr ? strdup(d_nextBundlePath) : nullptr),
canRequestParameterValueChanges(d_nextCanRequestParameterValueChanges)
bundlePath(d_nextBundlePath != nullptr ? strdup(d_nextBundlePath) : nullptr)
{
DISTRHO_SAFE_ASSERT(bufferSize != 0);
DISTRHO_SAFE_ASSERT(d_isNotZero(sampleRate));
Expand Down
2 changes: 2 additions & 0 deletions distrho/src/DistrhoPluginLADSPA+DSSI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,9 +553,11 @@ static const struct DescriptorInitializer
// Create dummy plugin to get data from
d_nextBufferSize = 512;
d_nextSampleRate = 44100.0;
d_nextPluginIsDummy = true;
const PluginExporter plugin(nullptr, nullptr, nullptr);
d_nextBufferSize = 0;
d_nextSampleRate = 0.0;
d_nextPluginIsDummy = false;

// Get port count, init
ulong port = 0;
Expand Down
2 changes: 2 additions & 0 deletions distrho/src/DistrhoPluginLV2export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,11 @@ void lv2_generate_ttl(const char* const basename)
// Dummy plugin to get data from
d_nextBufferSize = 512;
d_nextSampleRate = 44100.0;
d_nextPluginIsDummy = true;
PluginExporter plugin(nullptr, nullptr, nullptr);
d_nextBufferSize = 0;
d_nextSampleRate = 0.0;
d_nextPluginIsDummy = false;

const String pluginDLL(basename);
const String pluginTTL(pluginDLL + ".ttl");
Expand Down
2 changes: 2 additions & 0 deletions distrho/src/DistrhoPluginVST2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,7 @@ static intptr_t vst_dispatcherCallback(AEffect* effect, int32_t opcode, int32_t
// set valid but dummy values
d_nextBufferSize = 512;
d_nextSampleRate = 44100.0;
d_nextPluginIsDummy = true;
d_nextCanRequestParameterValueChanges = true;
}

Expand All @@ -1417,6 +1418,7 @@ static intptr_t vst_dispatcherCallback(AEffect* effect, int32_t opcode, int32_t
// unset
d_nextBufferSize = 0;
d_nextSampleRate = 0.0;
d_nextPluginIsDummy = false;
d_nextCanRequestParameterValueChanges = false;

*(PluginExporter**)ptr = &plugin;
Expand Down
2 changes: 2 additions & 0 deletions distrho/src/DistrhoPluginVST3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3544,10 +3544,12 @@ static const PluginExporter& _getPluginInfo()
{
d_nextBufferSize = 512;
d_nextSampleRate = 44100.0;
d_nextPluginIsDummy = true;
d_nextCanRequestParameterValueChanges = true;
static const PluginExporter gPluginInfo(nullptr, nullptr, nullptr);
d_nextBufferSize = 0;
d_nextSampleRate = 0.0;
d_nextPluginIsDummy = false;
d_nextCanRequestParameterValueChanges = false;

return gPluginInfo;
Expand Down

0 comments on commit ad05572

Please sign in to comment.