Serialize persistent fields for VST3 plugins
This commit is contained in:
parent
221e424f78
commit
486fc67a4b
|
@ -35,4 +35,8 @@ pub(crate) struct State {
|
|||
/// be recalled when when the parameter's range gets increased. Doing so may still mess with
|
||||
/// parmaeter automation though, depending on how the host impelments that.
|
||||
pub params: HashMap<String, ParamValue>,
|
||||
/// Arbitrary fields that should be persisted together with the plugin's parameters. Any field
|
||||
/// on the [Params] struct that's annotated with `#[persist = "stable_name"]` will be persisted
|
||||
/// this way.
|
||||
pub fields: HashMap<String, Vec<u8>>,
|
||||
}
|
||||
|
|
|
@ -381,6 +381,13 @@ impl<P: Plugin> IComponent for Wrapper<'_, P> {
|
|||
}
|
||||
}
|
||||
|
||||
// The plugin can also persist arbitrary fields alongside its parameters. This is useful for
|
||||
// storing things like sample data.
|
||||
self.plugin
|
||||
.borrow()
|
||||
.params()
|
||||
.deserialize_fields(&state.fields);
|
||||
|
||||
kResultOk
|
||||
}
|
||||
|
||||
|
@ -410,8 +417,11 @@ impl<P: Plugin> IComponent for Wrapper<'_, P> {
|
|||
ParamValue::Bool(self.bypass_state.get()),
|
||||
);
|
||||
|
||||
let plugin_state = State { params };
|
||||
// The plugin can also persist arbitrary fields alongside its parameters. This is useful for
|
||||
// storing things like sample data.
|
||||
let fields = self.plugin.borrow().params().serialize_fields();
|
||||
|
||||
let plugin_state = State { params, fields };
|
||||
match serde_json::to_vec(&plugin_state) {
|
||||
Ok(serialized) => {
|
||||
let mut num_bytes_written = 0;
|
||||
|
|
Loading…
Reference in a new issue