From 7feb8006efc96712b336e69ff87add827ec04987 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sun, 30 Jan 2022 02:04:35 +0100 Subject: [PATCH] Persist the bypass parameter --- src/wrapper/state.rs | 1 + src/wrapper/vst3.rs | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/wrapper/state.rs b/src/wrapper/state.rs index db37f22e..3b366885 100644 --- a/src/wrapper/state.rs +++ b/src/wrapper/state.rs @@ -25,6 +25,7 @@ use std::collections::HashMap; pub(crate) enum ParamValue { F32(f32), I32(i32), + Bool(bool), } /// A plugin's state so it can be restored at a later point. diff --git a/src/wrapper/vst3.rs b/src/wrapper/vst3.rs index 3c3e733d..efddd4db 100644 --- a/src/wrapper/vst3.rs +++ b/src/wrapper/vst3.rs @@ -341,6 +341,20 @@ impl IComponent for Wrapper<'_, P> { }; for (param_id_str, param_value) in state.params { + // Handle the bypass parameter separately + if param_id_str == BYPASS_PARAM_ID { + match param_value { + ParamValue::Bool(b) => self.bypass_state.set(b), + _ => nih_debug_assert_failure!( + "Invalid serialized value {:?} for parameter {} ({:?})", + param_value, + param_id_str, + param_id_str, + ), + }; + continue; + } + let param_ptr = match self .param_hash_to_id .get(param_id_str.as_str()) @@ -376,7 +390,7 @@ impl IComponent for Wrapper<'_, P> { let state = state.upgrade().unwrap(); // We'll serialize parmaeter values as a simple `string_param_id: display_value` map. - let params = self + let mut params: HashMap<_, _> = self .param_id_to_hash .iter() .filter_map(|(hash, param_id_str)| { @@ -388,6 +402,13 @@ impl IComponent for Wrapper<'_, P> { ParamPtr::IntParam(p) => (param_id_str.to_string(), ParamValue::I32((*p).value)), }) .collect(); + + // Don't forget about the bypass parameter + params.insert( + BYPASS_PARAM_ID.to_string(), + ParamValue::Bool(self.bypass_state.get()), + ); + let plugin_state = State { params }; match serde_json::to_vec(&plugin_state) {