Persist the bypass parameter
This commit is contained in:
parent
16238f1e00
commit
7feb8006ef
2 changed files with 23 additions and 1 deletions
|
@ -25,6 +25,7 @@ use std::collections::HashMap;
|
||||||
pub(crate) enum ParamValue {
|
pub(crate) enum ParamValue {
|
||||||
F32(f32),
|
F32(f32),
|
||||||
I32(i32),
|
I32(i32),
|
||||||
|
Bool(bool),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A plugin's state so it can be restored at a later point.
|
/// A plugin's state so it can be restored at a later point.
|
||||||
|
|
|
@ -341,6 +341,20 @@ impl<P: Plugin> IComponent for Wrapper<'_, P> {
|
||||||
};
|
};
|
||||||
|
|
||||||
for (param_id_str, param_value) in state.params {
|
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
|
let param_ptr = match self
|
||||||
.param_hash_to_id
|
.param_hash_to_id
|
||||||
.get(param_id_str.as_str())
|
.get(param_id_str.as_str())
|
||||||
|
@ -376,7 +390,7 @@ impl<P: Plugin> IComponent for Wrapper<'_, P> {
|
||||||
let state = state.upgrade().unwrap();
|
let state = state.upgrade().unwrap();
|
||||||
|
|
||||||
// We'll serialize parmaeter values as a simple `string_param_id: display_value` map.
|
// 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
|
.param_id_to_hash
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(hash, param_id_str)| {
|
.filter_map(|(hash, param_id_str)| {
|
||||||
|
@ -388,6 +402,13 @@ impl<P: Plugin> IComponent for Wrapper<'_, P> {
|
||||||
ParamPtr::IntParam(p) => (param_id_str.to_string(), ParamValue::I32((*p).value)),
|
ParamPtr::IntParam(p) => (param_id_str.to_string(), ParamValue::I32((*p).value)),
|
||||||
})
|
})
|
||||||
.collect();
|
.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 };
|
let plugin_state = State { params };
|
||||||
|
|
||||||
match serde_json::to_vec(&plugin_state) {
|
match serde_json::to_vec(&plugin_state) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue