commit d0179ed3080f3bf7d8b8098bf09e2a0e4d9bb295
parent a5bac8394001c1d3ae9a47da2a987c0532f01359
Author: falkTX <falktx@gmail.com>
Date: Fri, 18 Sep 2015 11:29:14 +0200
Fallback to maxBlockLength if host doesn't support nominal
Diffstat:
1 file changed, 36 insertions(+), 11 deletions(-)
diff --git a/distrho/src/DistrhoPluginLV2.cpp b/distrho/src/DistrhoPluginLV2.cpp
@@ -52,8 +52,9 @@ typedef std::map<const String, String> StringMap;
class PluginLv2
{
public:
- PluginLv2(const double sampleRate, const LV2_URID_Map* const uridMap, const LV2_Worker_Schedule* const worker)
- : fPortControls(nullptr),
+ PluginLv2(const double sampleRate, const LV2_URID_Map* const uridMap, const LV2_Worker_Schedule* const worker, const bool usingNominal)
+ : fUsingNominal(usingNominal),
+ fPortControls(nullptr),
fLastControlValues(nullptr),
fSampleRate(sampleRate),
#if DISTRHO_LV2_USE_EVENTS_IN || DISTRHO_LV2_USE_EVENTS_OUT
@@ -663,31 +664,39 @@ public:
{
if (options[i].key == fUridMap->map(fUridMap->handle, LV2_BUF_SIZE__nominalBlockLength))
{
- if (options[i].type == fUridMap->map(fUridMap->handle, LV2_ATOM__Int))
+ if (options[i].type == fURIDs.atomInt)
{
const int bufferSize(*(const int*)options[i].value);
fPlugin.setBufferSize(bufferSize);
- continue;
}
else
{
d_stderr("Host changed nominalBlockLength but with wrong value type");
- continue;
+ }
+ }
+ else if (options[i].key == fUridMap->map(fUridMap->handle, LV2_BUF_SIZE__maxBlockLength) && ! fUsingNominal)
+ {
+ if (options[i].type == fURIDs.atomInt)
+ {
+ const int bufferSize(*(const int*)options[i].value);
+ fPlugin.setBufferSize(bufferSize);
+ }
+ else
+ {
+ d_stderr("Host changed maxBlockLength but with wrong value type");
}
}
else if (options[i].key == fUridMap->map(fUridMap->handle, LV2_CORE__sampleRate))
{
- if (options[i].type == fUridMap->map(fUridMap->handle, LV2_ATOM__Double))
+ if (options[i].type == fURIDs.atomDouble)
{
const double sampleRate(*(const double*)options[i].value);
fSampleRate = sampleRate;
fPlugin.setSampleRate(sampleRate);
- continue;
}
else
{
d_stderr("Host changed sampleRate but with wrong value type");
- continue;
}
}
}
@@ -815,6 +824,7 @@ public:
private:
PluginExporter fPlugin;
+ const bool fUsingNominal; // if false use maxBlockLength
// LV2 ports
#if DISTRHO_PLUGIN_NUM_INPUTS > 0
@@ -1007,29 +1017,44 @@ static LV2_Handle lv2_instantiate(const LV2_Descriptor*, double sampleRate, cons
#endif
d_lastBufferSize = 0;
+ usingNominal = false;
for (int i=0; options[i].key != 0; ++i)
{
if (options[i].key == uridMap->map(uridMap->handle, LV2_BUF_SIZE__nominalBlockLength))
{
if (options[i].type == uridMap->map(uridMap->handle, LV2_ATOM__Int))
+ {
d_lastBufferSize = *(const int*)options[i].value;
+ usingNominal = true;
+ }
else
+ {
d_stderr("Host provides nominalBlockLength but has wrong value type");
-
+ }
break;
}
+
+ if (options[i].key == uridMap->map(uridMap->handle, LV2_BUF_SIZE__maxBlockLength))
+ {
+ if (options[i].type == uridMap->map(uridMap->handle, LV2_ATOM__Int))
+ d_lastBufferSize = *(const int*)options[i].value;
+ else
+ d_stderr("Host provides maxBlockLength but has wrong value type");
+
+ // no break, continue in case host supports nominalBlockLength
+ }
}
if (d_lastBufferSize == 0)
{
- d_stderr("Host does not provide nominalBlockLength option");
+ d_stderr("Host does not provide nominalBlockLength or maxBlockLength options");
d_lastBufferSize = 2048;
}
d_lastSampleRate = sampleRate;
- return new PluginLv2(sampleRate, uridMap, worker);
+ return new PluginLv2(sampleRate, uridMap, worker, usingNominal);
}
#define instancePtr ((PluginLv2*)instance)