Browse Source

Report sample rate to LV2 UIs properly

Closes #559
tags/1.9.8
falkTX 8 years ago
parent
commit
25767ed93e
2 changed files with 60 additions and 16 deletions
  1. +34
    -12
      source/backend/plugin/CarlaPluginLV2.cpp
  2. +26
    -4
      source/bridges-ui/CarlaBridgeUI-LV2.cpp

+ 34
- 12
source/backend/plugin/CarlaPluginLV2.cpp View File

@@ -318,7 +318,7 @@ struct CarlaPluginLV2Options {
int minBufferSize;
int nominalBufferSize;
int sequenceSize;
double sampleRate;
float sampleRate;
int64_t transientWinId;
const char* windowTitle;
LV2_Options_Option opts[Count];
@@ -368,8 +368,8 @@ struct CarlaPluginLV2Options {
optSampleRate.context = LV2_OPTIONS_INSTANCE;
optSampleRate.subject = 0;
optSampleRate.key = kUridParamSampleRate;
optSampleRate.size = sizeof(double);
optSampleRate.type = kUridAtomDouble;
optSampleRate.size = sizeof(float);
optSampleRate.type = kUridAtomFloat;
optSampleRate.value = &sampleRate;

LV2_Options_Option& optTransientWinId(opts[TransientWinId]);
@@ -463,6 +463,11 @@ public:
const ScopedEnvVar _sev2("LD_PRELOAD", nullptr);
#endif

char sampleRateStr[32];
carla_zeroChars(sampleRateStr, 32);
std::snprintf(sampleRateStr, 31, "%f", kEngine->getSampleRate());
carla_setenv("CARLA_SAMPLE_RATE", sampleRateStr);

return CarlaPipeServer::startPipeServer(fFilename, fPluginURI, fUiURI, size);
}

@@ -3850,22 +3855,39 @@ public:
CARLA_ASSERT_INT(newSampleRate > 0.0, newSampleRate);
carla_debug("CarlaPluginLV2::sampleRateChanged(%g) - start", newSampleRate);

if (carla_isNotEqual(fLv2Options.sampleRate, newSampleRate))
const float sampleRatef = static_cast<float>(newSampleRate);

if (carla_isNotEqual(fLv2Options.sampleRate, sampleRatef))
{
fLv2Options.sampleRate = newSampleRate;
fLv2Options.sampleRate = sampleRatef;

if (fExt.options != nullptr && fExt.options->set != nullptr)
fExt.options->set(fHandle, &fLv2Options.opts[CarlaPluginLV2Options::SampleRate]);
{
LV2_Options_Option options[2];
carla_zeroStructs(options, 2);

LV2_Options_Option& optSampleRate(options[0]);
optSampleRate.context = LV2_OPTIONS_INSTANCE;
optSampleRate.subject = 0;
optSampleRate.key = kUridParamSampleRate;
optSampleRate.size = sizeof(float);
optSampleRate.type = kUridAtomFloat;
optSampleRate.value = &fLv2Options.sampleRate;

fExt.options->set(fHandle, options);
}
}

for (uint32_t k=0; k < pData->param.count; ++k)
{
if (pData->param.data[k].type == PARAMETER_INPUT && pData->param.special[k] == PARAMETER_SPECIAL_SAMPLE_RATE)
{
fParamBuffers[k] = static_cast<float>(newSampleRate);
pData->postponeRtEvent(kPluginPostRtEventParameterChange, static_cast<int32_t>(k), 1, fParamBuffers[k]);
break;
}
if (pData->param.data[k].type != PARAMETER_INPUT)
continue;
if (pData->param.special[k] != PARAMETER_SPECIAL_SAMPLE_RATE)
continue;

fParamBuffers[k] = sampleRatef;
pData->postponeRtEvent(kPluginPostRtEventParameterChange, static_cast<int32_t>(k), 1, fParamBuffers[k]);
break;
}

carla_debug("CarlaPluginLV2::sampleRateChanged(%g) - end", newSampleRate);


+ 26
- 4
source/bridges-ui/CarlaBridgeUI-LV2.cpp View File

@@ -122,7 +122,7 @@ struct Lv2PluginOptions {
Count
};

double sampleRate;
float sampleRate;
int64_t transientWinId;
const char* windowTitle;
LV2_Options_Option opts[Count];
@@ -136,8 +136,8 @@ struct Lv2PluginOptions {
optSampleRate.context = LV2_OPTIONS_INSTANCE;
optSampleRate.subject = 0;
optSampleRate.key = CARLA_URI_MAP_ID_PARAM_SAMPLE_RATE;
optSampleRate.size = sizeof(double);
optSampleRate.type = CARLA_URI_MAP_ID_ATOM_DOUBLE;
optSampleRate.size = sizeof(float);
optSampleRate.type = CARLA_URI_MAP_ID_ATOM_FLOAT;
optSampleRate.value = &sampleRate;

LV2_Options_Option& optTransientWinId(opts[TransientWinId]);
@@ -571,7 +571,29 @@ public:

delete[] fLv2Options.windowTitle;

fLv2Options.sampleRate = sampleRate;
const float sampleRatef = static_cast<float>(sampleRate);

if (carla_isNotEqual(fLv2Options.sampleRate, sampleRatef))
{
fLv2Options.sampleRate = sampleRatef;

if (fExt.options != nullptr && fExt.options->set != nullptr)
{
LV2_Options_Option options[2];
carla_zeroStructs(options, 2);

LV2_Options_Option& optSampleRate(options[0]);
optSampleRate.context = LV2_OPTIONS_INSTANCE;
optSampleRate.subject = 0;
optSampleRate.key = CARLA_URI_MAP_ID_PARAM_SAMPLE_RATE;
optSampleRate.size = sizeof(float);
optSampleRate.type = CARLA_URI_MAP_ID_ATOM_FLOAT;
optSampleRate.value = &fLv2Options.sampleRate;

fExt.options->set(fHandle, options);
}
}

fLv2Options.transientWinId = static_cast<int64_t>(transientWindowId);
fLv2Options.windowTitle = carla_strdup_safe(windowTitle);



Loading…
Cancel
Save