From 2d4ac47f158ea61d2bd6df4e0e0002f193945754 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Fri, 4 Nov 2022 18:32:35 +0100 Subject: [PATCH] Add a not yet used safe mode AtomicBool to Diopser This will limit the range of the filter stages parameter in the GUI. --- plugins/diopser/src/editor.rs | 7 +++++++ plugins/diopser/src/lib.rs | 7 +++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/plugins/diopser/src/editor.rs b/plugins/diopser/src/editor.rs index 8e6187e1..f2cbe9e9 100644 --- a/plugins/diopser/src/editor.rs +++ b/plugins/diopser/src/editor.rs @@ -18,6 +18,7 @@ use nih_plug::prelude::Editor; use nih_plug_vizia::vizia::prelude::*; use nih_plug_vizia::widgets::*; use nih_plug_vizia::{assets, create_vizia_editor, ViziaState, ViziaTheming}; +use std::sync::atomic::AtomicBool; use std::sync::Arc; use crate::DiopserParams; @@ -28,6 +29,10 @@ const POINT_SCALE: f32 = 0.75; #[derive(Lens)] struct Data { params: Arc, + + /// Whether the safe mode button is enabled. The number of filter stages is capped at 40 while + /// this is active. + safe_mode: Arc, } impl Model for Data {} @@ -49,6 +54,8 @@ pub(crate) fn create( Data { params: params.clone(), + + safe_mode: params.safe_mode.clone(), } .build(cx); diff --git a/plugins/diopser/src/lib.rs b/plugins/diopser/src/lib.rs index 5af64de8..6d1d9f44 100644 --- a/plugins/diopser/src/lib.rs +++ b/plugins/diopser/src/lib.rs @@ -72,14 +72,16 @@ pub struct Diopser { spectrum_output: Arc, } -// TODO: Some combinations of parameters can cause really loud resonance. We should limit the -// resonance and filter stages parameter ranges in the GUI until the user unlocks. #[derive(Params)] struct DiopserParams { /// The editor state, saved together with the parameter state so the custom scaling can be /// restored. #[persist = "editor-state"] editor_state: Arc, + /// If this option is enabled, then the filter stages parameter is limited to `[0, 40]`. This is + /// editor-only state, and doesn't affect host automation. + #[persist = "safe-mode"] + safe_mode: Arc, /// This plugin really doesn't need its own bypass parameter, but it's still useful to have a /// dedicated one so it can be shown in the GUI. This is linked to the host's bypass if the host @@ -149,6 +151,7 @@ impl DiopserParams { fn new(should_update_filters: Arc) -> Self { Self { editor_state: editor::default_state(), + safe_mode: Arc::new(AtomicBool::new(true)), bypass: BoolParam::new("Bypass", false).make_bypass(),