From d7acd6573ad1122e10ae85fee09d4884c83779c3 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Tue, 29 Nov 2022 20:48:47 +0100 Subject: [PATCH] Only set parameter values on safe mode when needed Otherwise this resets the filters every time. --- plugins/diopser/src/editor/safe_mode.rs | 49 ++++++++++++------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/plugins/diopser/src/editor/safe_mode.rs b/plugins/diopser/src/editor/safe_mode.rs index 8d24da39..b0d70ffa 100644 --- a/plugins/diopser/src/editor/safe_mode.rs +++ b/plugins/diopser/src/editor/safe_mode.rs @@ -146,33 +146,32 @@ impl SafeModeClamper { /// CLamp the parameter values to the restricted range when enabling safe mode. This assumes /// there's no active automation gesture for these parameters. fn restrict_range(&self, cx: &mut EventContext) { - cx.emit(ParamEvent::BeginSetParameter(&self.params.filter_stages).upcast()); - cx.emit( - ParamEvent::SetParameter( - &self.params.filter_stages, - self.params.filter_stages.unmodulated_plain_value().clamp( - params::FILTER_STAGES_RESTRICTED_MIN, - params::FILTER_STAGES_RESTRICTED_MAX, - ), - ) - .upcast(), + let filter_stages = self.params.filter_stages.unmodulated_plain_value(); + let clamped_filter_stages = filter_stages.clamp( + params::FILTER_STAGES_RESTRICTED_MIN, + params::FILTER_STAGES_RESTRICTED_MAX, ); - cx.emit(ParamEvent::EndSetParameter(&self.params.filter_stages).upcast()); + if clamped_filter_stages != filter_stages { + cx.emit(ParamEvent::BeginSetParameter(&self.params.filter_stages).upcast()); + cx.emit( + ParamEvent::SetParameter(&self.params.filter_stages, clamped_filter_stages) + .upcast(), + ); + cx.emit(ParamEvent::EndSetParameter(&self.params.filter_stages).upcast()); + } - cx.emit(ParamEvent::BeginSetParameter(&self.params.filter_frequency).upcast()); - cx.emit( - ParamEvent::SetParameter( - &self.params.filter_frequency, - self.params - .filter_frequency - .unmodulated_plain_value() - .clamp( - params::FILTER_FREQUENCY_RESTRICTED_MIN, - params::FILTER_FREQUENCY_RESTRICTED_MAX, - ), - ) - .upcast(), + let filter_frequency = self.params.filter_frequency.unmodulated_plain_value(); + let clamped_filter_frequency = filter_frequency.clamp( + params::FILTER_FREQUENCY_RESTRICTED_MIN, + params::FILTER_FREQUENCY_RESTRICTED_MAX, ); - cx.emit(ParamEvent::EndSetParameter(&self.params.filter_frequency).upcast()); + if clamped_filter_frequency != filter_frequency { + cx.emit(ParamEvent::BeginSetParameter(&self.params.filter_frequency).upcast()); + cx.emit( + ParamEvent::SetParameter(&self.params.filter_frequency, clamped_filter_frequency) + .upcast(), + ); + cx.emit(ParamEvent::EndSetParameter(&self.params.filter_frequency).upcast()); + } } }