From 20ad19fdc5d6b3cb41224cb2c23cc3d671c75eb0 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sun, 26 Feb 2023 00:58:16 +0100 Subject: [PATCH] Fix main IO for plugins with aux but no main IO This would otherwise check and interact with the wrong buffers. --- src/wrapper/clap/wrapper.rs | 15 +++++++-------- src/wrapper/vst3/wrapper.rs | 9 +++++++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/wrapper/clap/wrapper.rs b/src/wrapper/clap/wrapper.rs index e4ec06aa..db158333 100644 --- a/src/wrapper/clap/wrapper.rs +++ b/src/wrapper/clap/wrapper.rs @@ -1928,14 +1928,10 @@ impl Wrapper

{ // Before doing anything, clear out any auxiliary outputs since they may contain // uninitialized data when the host assumes that we'll always write something there let current_audio_io_layout = wrapper.current_audio_io_layout.load(); - let (aux_input_start_idx, aux_output_start_idx) = { - let has_main_input = current_audio_io_layout.main_input_channels.is_some(); - let has_main_output = current_audio_io_layout.main_output_channels.is_some(); - ( - if has_main_input { 1 } else { 0 }, - if has_main_output { 1 } else { 0 }, - ) - }; + let has_main_input = current_audio_io_layout.main_input_channels.is_some(); + let has_main_output = current_audio_io_layout.main_output_channels.is_some(); + let aux_input_start_idx = if has_main_input { 1 } else { 0 }; + let aux_output_start_idx = if has_main_output { 1 } else { 0 }; if process.audio_outputs_count > 0 && !process.audio_outputs.is_null() { for output_idx in aux_output_start_idx..process.audio_outputs_count as usize { let host_output = process.audio_outputs.add(output_idx); @@ -2034,6 +2030,7 @@ impl Wrapper

{ && !process.audio_outputs.is_null() && !(*process.audio_outputs).data32.is_null() && !output_slices.is_empty() + && has_main_output { let audio_outputs = &*process.audio_outputs; let num_output_channels = audio_outputs.channel_count as usize; @@ -2073,6 +2070,8 @@ impl Wrapper

{ && process.audio_inputs_count > 0 && !process.audio_inputs.is_null() && !(*process.audio_inputs).data32.is_null() + && has_main_input + && has_main_output { // We currently don't support sidechain inputs let audio_outputs = &*process.audio_outputs; diff --git a/src/wrapper/vst3/wrapper.rs b/src/wrapper/vst3/wrapper.rs index 963e2bb1..bb4c10e3 100644 --- a/src/wrapper/vst3/wrapper.rs +++ b/src/wrapper/vst3/wrapper.rs @@ -1025,6 +1025,7 @@ impl IAudioProcessor for Wrapper

{ // uninitialized data when the host assumes that we'll always write something there let current_audio_io_layout = self.inner.current_audio_io_layout.load(); let has_main_input = current_audio_io_layout.main_input_channels.is_some(); + let has_main_output = current_audio_io_layout.main_output_channels.is_some(); if !data.outputs.is_null() { // HACK: Bitwig requires VST3 plugins to always have a main output. We'll however // still use this variable here to maintain consistency between the backends. @@ -1300,7 +1301,7 @@ impl IAudioProcessor for Wrapper

{ // Buffers for zero-channel plugins like note effects should always be allowed buffer_is_valid = output_slices.is_empty(); - if !data.outputs.is_null() { + if !data.outputs.is_null() && has_main_output { let num_output_channels = (*data.outputs).num_channels as usize; // This ensures that we never feed dangling slices to the wrapped plugin buffer_is_valid = num_output_channels == output_slices.len(); @@ -1334,7 +1335,11 @@ impl IAudioProcessor for Wrapper

{ // Some hosts process data in place, in which case we don't need to do any copying // ourselves. If the pointers do not alias, then we'll do the copy here and then the // plugin can just do normal in place processing. - if !data.outputs.is_null() && !data.inputs.is_null() { + if !data.outputs.is_null() + && !data.inputs.is_null() + && has_main_input + && has_main_output + { let num_output_channels = (*data.outputs).num_channels as usize; let num_input_channels = (*data.inputs).num_channels as usize; nih_debug_assert!(