Only initialize VST2 audio buffers on activation

Ardour apparently always calls `effMainsChanged()` with a value argument
of 0 when unloading the plugin, regardless of whether it has actually
initialized audio processing before that point.
This commit is contained in:
Robbert van der Helm
2021-06-12 20:15:20 +02:00
parent 67e754feb5
commit 8a754b08cf
2 changed files with 23 additions and 9 deletions
+18 -8
View File
@@ -227,8 +227,16 @@ class DispatchDataConverter : public DefaultDataConverter {
break;
case effMainsChanged:
// At this point we'll set up our audio buffers since we (in
// theory) now know how large they need to be
return WantsAudioShmBufferConfig{};
// theory) now know how large they need to be. A value argument
// of 1 means that audio playback should be initialized.
// NOTE: Ardour unconditionally calls this with a value of 0
// unconditionally when unloading a plugin, even if it has
// never initialized audio playback
if (value == 1) {
return WantsAudioShmBufferConfig{};
} else {
return nullptr;
}
case effEditGetRect:
return WantsVstRect();
break;
@@ -367,12 +375,14 @@ class DispatchDataConverter : public DefaultDataConverter {
update_aeffect(plugin, updated_plugin);
} break;
case effMainsChanged: {
const auto& audio_buffer_config =
std::get<AudioShmBuffer::Config>(response.payload);
if (!process_buffers) {
process_buffers.emplace(audio_buffer_config);
} else {
process_buffers->resize(audio_buffer_config);
if (const auto* audio_buffer_config =
std::get_if<AudioShmBuffer::Config>(
&response.payload)) {
if (!process_buffers) {
process_buffers.emplace(*audio_buffer_config);
} else {
process_buffers->resize(*audio_buffer_config);
}
}
} break;
case effEditGetRect: {
+5 -1
View File
@@ -470,7 +470,11 @@ void Vst2Bridge::run() {
// the same buffers. We cannot use `Vst2Bridge::dispatch_wrapper()`
// for this because we need to directly return payload data that
// won't be visible to the plugin at all.
if (event.opcode == effMainsChanged) {
// NOTE: Ardour will call `effMainsChanged()` with a value of 1
// unconditionally when unloading a plugin, even when audio
// playback has never been initialized (and `effSetBlockSize`
// has never been called)
if (event.opcode == effMainsChanged && event.value == 1) {
// Returning another result this way is a bit ugly, but sadly
// optimizations have never made code nicer to read
return Vst2EventResult{.return_value = result.return_value,