From 259d23ec570768abf698d52886ffdca705037dcd Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Wed, 22 Apr 2020 16:51:30 +0200 Subject: [PATCH] Add support for legacy plugins with only process() By emulating the behavior of `processReplacing()`. Not that there should still be any plugins around that don't support processReplacing. --- src/plugin/host-bridge.cpp | 2 +- src/plugin/host-bridge.h | 6 ++++-- src/wine-host/plugin-bridge.cpp | 20 ++++++++++++++++---- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/plugin/host-bridge.cpp b/src/plugin/host-bridge.cpp index 58d64dc7..8d20ca2c 100644 --- a/src/plugin/host-bridge.cpp +++ b/src/plugin/host-bridge.cpp @@ -357,7 +357,7 @@ void HostBridge::process_replacing(AEffect* /*plugin*/, const AudioBuffers request{input_buffers, sample_frames}; write_object(host_vst_process_replacing, request, process_buffer); - // /Write the results back to the `outputs` arrays + // Write the results back to the `outputs` arrays AudioBuffers response; response = read_object(host_vst_process_replacing, response, process_buffer); diff --git a/src/plugin/host-bridge.h b/src/plugin/host-bridge.h index cfca3ca0..a6fc02ed 100644 --- a/src/plugin/host-bridge.h +++ b/src/plugin/host-bridge.h @@ -78,8 +78,10 @@ class HostBridge { void* data, float option); /** - * Ask the VST plugin to process audio for us. This should also be used for - * the deprecated 'process' function. + * Ask the VST plugin to process audio for us. If the plugin somehow does + * not support `processReplacing()` and only supports the old `process()` + * function, then this will be handled implicitely in + * `PluginBridge::handle_process_replacing()`. */ void process_replacing(AEffect* plugin, float** inputs, diff --git a/src/wine-host/plugin-bridge.cpp b/src/wine-host/plugin-bridge.cpp index 73a47375..533b6b81 100644 --- a/src/wine-host/plugin-bridge.cpp +++ b/src/wine-host/plugin-bridge.cpp @@ -201,8 +201,6 @@ void PluginBridge::handle_dispatch() { request = read_object(host_vst_process_replacing, request, process_buffer); - // TODO: Check if the plugin doesn't support `processReplacing` and - // call the legacy `process` function instead // The process functions expect a `float**` for their inputs and // their outputs std::vector inputs; @@ -220,8 +218,22 @@ void PluginBridge::handle_dispatch() { outputs.push_back(buffer.data()); } - plugin->processReplacing(plugin, inputs.data(), outputs.data(), - request.sample_frames); + // Any plugin made in the last fifteen years or so should support + // `processReplacing`. In the off chance it does not we can just emulate + // this behavior ourselves. + if (plugin->processReplacing != nullptr) { + plugin->processReplacing(plugin, inputs.data(), outputs.data(), + request.sample_frames); + } else { + // If we zero out this buffer then the behavior is the same as + // `processReplacing`` + for (std::vector& buffer : output_buffers) { + std::fill(buffer.begin(), buffer.end(), 0.0); + } + + plugin->process(plugin, inputs.data(), outputs.data(), + request.sample_frames); + } AudioBuffers response{output_buffers, request.sample_frames}; write_object(host_vst_process_replacing, response, process_buffer);