1
0
Fork 0

Serialize persistent fields for VST3 plugins

This commit is contained in:
Robbert van der Helm 2022-01-30 17:09:18 +01:00
parent 221e424f78
commit 486fc67a4b
2 changed files with 15 additions and 1 deletions

View file

@ -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>>,
}

View file

@ -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;