From 0cb26b5b4c4eb39bc2fd3b7c15f3bb128596de53 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Wed, 23 Mar 2022 15:49:34 +0100 Subject: [PATCH] Don't process audio for bypassed plugins --- src/wrapper/clap/wrapper.rs | 15 +++++++++++---- src/wrapper/vst3/wrapper.rs | 20 +++++++++++++------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/wrapper/clap/wrapper.rs b/src/wrapper/clap/wrapper.rs index a57a1b25..5922fec8 100644 --- a/src/wrapper/clap/wrapper.rs +++ b/src/wrapper/clap/wrapper.rs @@ -1170,10 +1170,17 @@ impl Wrapper

{ } } - let mut plugin = wrapper.plugin.write(); - let mut context = wrapper.make_process_context(transport); - let result = plugin.process(&mut output_buffer, &mut context); - wrapper.last_process_status.store(result); + // Only process audio if the plugin is not currently bypassed + let result = if !wrapper.bypass_state.load(Ordering::Relaxed) { + let mut plugin = wrapper.plugin.write(); + let mut context = wrapper.make_process_context(transport); + let result = plugin.process(&mut output_buffer, &mut context); + wrapper.last_process_status.store(result); + result + } else { + wrapper.last_process_status.store(ProcessStatus::Normal); + ProcessStatus::Normal + }; let clap_result = match result { ProcessStatus::Error(err) => { diff --git a/src/wrapper/vst3/wrapper.rs b/src/wrapper/vst3/wrapper.rs index 4b8d6d4f..2ac76984 100644 --- a/src/wrapper/vst3/wrapper.rs +++ b/src/wrapper/vst3/wrapper.rs @@ -921,15 +921,21 @@ impl IAudioProcessor for Wrapper

{ let mut plugin = self.inner.plugin.write(); let mut context = self.inner.make_process_context(transport); - let result = plugin.process(&mut output_buffer, &mut context); - self.inner.last_process_status.store(result); - match result { - ProcessStatus::Error(err) => { - nih_debug_assert_failure!("Process error: {}", err); + // Only process audio if the plugin isn't bypassed + if !self.inner.bypass_state.load(Ordering::Relaxed) { + let result = plugin.process(&mut output_buffer, &mut context); + self.inner.last_process_status.store(result); + match result { + ProcessStatus::Error(err) => { + nih_debug_assert_failure!("Process error: {}", err); - return kResultFalse; + return kResultFalse; + } + _ => kResultOk, } - _ => kResultOk, + } else { + self.inner.last_process_status.store(ProcessStatus::Normal); + kResultOk } };