diff --git a/src/wrapper/state.rs b/src/wrapper/state.rs index 3b366885..802c2c7b 100644 --- a/src/wrapper/state.rs +++ b/src/wrapper/state.rs @@ -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, + /// 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>, } diff --git a/src/wrapper/vst3.rs b/src/wrapper/vst3.rs index 3f881729..3b91259e 100644 --- a/src/wrapper/vst3.rs +++ b/src/wrapper/vst3.rs @@ -381,6 +381,13 @@ impl 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 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;