From 2af3f844164bcf2113acffc895cd509a7571a35c Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Thu, 7 Apr 2022 17:39:34 +0200 Subject: [PATCH] Rename State to PluginState Now that it is part of the public API. --- src/context.rs | 6 +++--- src/prelude.rs | 2 +- src/wrapper/clap/context.rs | 4 ++-- src/wrapper/clap/wrapper.rs | 10 +++++----- src/wrapper/state.rs | 16 ++++++++-------- src/wrapper/vst3/context.rs | 6 +++--- src/wrapper/vst3/inner.rs | 10 +++++----- 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/context.rs b/src/context.rs index 2ca80dd8..b934f0f1 100644 --- a/src/context.rs +++ b/src/context.rs @@ -3,7 +3,7 @@ use crate::param::internals::ParamPtr; use crate::param::Param; use crate::plugin::NoteEvent; -use crate::wrapper::state::State; +use crate::wrapper::state::PluginState; // TODO: ProcessContext for parameter automation and sending events @@ -83,13 +83,13 @@ pub trait GuiContext: Send + Sync + 'static { /// Serialize the plugin's current state to a serde-serializable object. Useful for implementing /// preset handling within a plugin's GUI. - fn get_state(&self) -> State; + fn get_state(&self) -> PluginState; /// Restore the state from a previously serialized state object. This will block the GUI thread /// until the state has been restored and a parameter value rescan has been requested from the /// host. If the plugin is currently processing audio, then the parameter values will be /// restored at the end of the current processing cycle. - fn set_state(&self, state: State); + fn set_state(&self, state: PluginState); } /// Information about the plugin's transport. Depending on the plugin API and the host not all diff --git a/src/prelude.rs b/src/prelude.rs index d95eea57..f7fef544 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -22,4 +22,4 @@ pub use crate::plugin::{ BufferConfig, BusConfig, ClapPlugin, Editor, NoteEvent, ParentWindowHandle, Plugin, ProcessStatus, Vst3Plugin, }; -pub use crate::wrapper::state::State; +pub use crate::wrapper::state::PluginState; diff --git a/src/wrapper/clap/context.rs b/src/wrapper/clap/context.rs index 5ca8cede..a06f7ea4 100644 --- a/src/wrapper/clap/context.rs +++ b/src/wrapper/clap/context.rs @@ -80,11 +80,11 @@ impl GuiContext for WrapperGuiContext

{ } } - fn get_state(&self) -> crate::wrapper::state::State { + fn get_state(&self) -> crate::wrapper::state::PluginState { self.wrapper.get_state_object() } - fn set_state(&self, state: crate::wrapper::state::State) { + fn set_state(&self, state: crate::wrapper::state::PluginState) { self.wrapper.set_state_object(state) } } diff --git a/src/wrapper/clap/wrapper.rs b/src/wrapper/clap/wrapper.rs index 3dca09bb..200b720c 100644 --- a/src/wrapper/clap/wrapper.rs +++ b/src/wrapper/clap/wrapper.rs @@ -75,7 +75,7 @@ use crate::plugin::{ BufferConfig, BusConfig, ClapPlugin, Editor, NoteEvent, ParentWindowHandle, ProcessStatus, }; use crate::util::permit_alloc; -use crate::wrapper::state::{self, State}; +use crate::wrapper::state::{self, PluginState}; use crate::wrapper::util::{hash_param_id, process_wrapper, strlcpy}; /// How many output parameter changes we can store in our output parameter change queue. Storing @@ -139,9 +139,9 @@ pub struct Wrapper { /// In other words, the GUI thread acts as a sender and then as a receiver, while the audio /// thread acts as a receiver and then as a sender. That way deallocation can happen on the GUI /// thread. All of this happens without any blocking on the audio thread. - updated_state_sender: channel::Sender, + updated_state_sender: channel::Sender, /// The receiver belonging to [`new_state_sender`][Self::new_state_sender]. - updated_state_receiver: channel::Receiver, + updated_state_receiver: channel::Receiver, /// Needs to be boxed because the plugin object is supposed to contain a static reference to /// this. @@ -928,7 +928,7 @@ impl Wrapper

{ /// Get the plugin's state object, may be called by the plugin's GUI as part of its own preset /// management. The wrapper doesn't use these functions and serializes and deserializes directly /// the JSON in the relevant plugin API methods instead. - pub fn get_state_object(&self) -> State { + pub fn get_state_object(&self) -> PluginState { unsafe { state::serialize_object( self.params.clone(), @@ -941,7 +941,7 @@ impl Wrapper

{ /// Update the plugin's internal state, called by the plugin itself from the GUI thread. To /// prevent corrupting data and changing parameters during processing the actual state is only /// updated at the end of the audio processing cycle. - pub fn set_state_object(&self, mut state: State) { + pub fn set_state_object(&self, mut state: PluginState) { // Use a loop and timeouts to handle the super rare edge case when this function gets called // between a process call and the host disabling the plugin loop { diff --git a/src/wrapper/state.rs b/src/wrapper/state.rs index 8b0b53df..6edda71d 100644 --- a/src/wrapper/state.rs +++ b/src/wrapper/state.rs @@ -24,7 +24,7 @@ pub enum ParamValue { /// A plugin's state so it can be restored at a later point. This object can be serialized and /// deserialized using serde. #[derive(Debug, Clone, Serialize, Deserialize)] -pub struct State { +pub struct PluginState { /// The plugin's parameter values. These are stored unnormalized. This mean sthe old values will /// 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. @@ -44,7 +44,7 @@ pub(crate) unsafe fn serialize_object( plugin_params: Arc, param_by_hash: &HashMap, param_id_to_hash: &HashMap, -) -> State { +) -> PluginState { // We'll serialize parmaeter values as a simple `string_param_id: display_value` map. let params: HashMap<_, _> = param_id_to_hash .iter() @@ -78,7 +78,7 @@ pub(crate) unsafe fn serialize_object( // storing things like sample data. let fields = plugin_params.serialize_fields(); - State { params, fields } + PluginState { params, fields } } /// Serialize a plugin's state to a vector containing JSON data. This can (and should) be shared @@ -92,14 +92,14 @@ pub(crate) unsafe fn serialize_json( serde_json::to_vec(&plugin_state) } -/// Deserialize a plugin's state from a [`State`] object. This is used to allow the plugin to do its -/// own internal preset management. Returns `false` and logs an error if the state could not be -/// deserialized. +/// Deserialize a plugin's state from a [`PluginState`] object. This is used to allow the plugin to +/// do its own internal preset management. Returns `false` and logs an error if the state could not +/// be deserialized. /// /// Make sure to reinitialize plugin after deserializing the state so it can react to the new /// parameter values. The smoothers have already been reset by this function. pub(crate) unsafe fn deserialize_object( - state: &State, + state: &PluginState, plugin_params: Arc, param_by_hash: &HashMap, param_id_to_hash: &HashMap, @@ -162,7 +162,7 @@ pub(crate) unsafe fn deserialize_json( param_id_to_hash: &HashMap, current_buffer_config: Option<&BufferConfig>, ) -> bool { - let state: State = match serde_json::from_slice(state) { + let state: PluginState = match serde_json::from_slice(state) { Ok(s) => s, Err(err) => { nih_debug_assert_failure!("Error while deserializing state: {}", err); diff --git a/src/wrapper/vst3/context.rs b/src/wrapper/vst3/context.rs index a84c0f2b..20e3d920 100644 --- a/src/wrapper/vst3/context.rs +++ b/src/wrapper/vst3/context.rs @@ -9,7 +9,7 @@ use crate::context::{GuiContext, ProcessContext, Transport}; use crate::event_loop::EventLoop; use crate::param::internals::ParamPtr; use crate::plugin::{NoteEvent, Vst3Plugin}; -use crate::wrapper::state::State; +use crate::wrapper::state::PluginState; /// A [`GuiContext`] implementation for the wrapper. This is passed to the plugin in /// [`Editor::spawn()`][crate::prelude::Editor::spawn()] so it can interact with the rest of the plugin and @@ -89,11 +89,11 @@ impl GuiContext for WrapperGuiContext

{ } } - fn get_state(&self) -> State { + fn get_state(&self) -> PluginState { self.inner.get_state_object() } - fn set_state(&self, state: State) { + fn set_state(&self, state: PluginState) { self.inner.set_state_object(state) } } diff --git a/src/wrapper/vst3/inner.rs b/src/wrapper/vst3/inner.rs index 35c6e4ed..94eef9dd 100644 --- a/src/wrapper/vst3/inner.rs +++ b/src/wrapper/vst3/inner.rs @@ -21,7 +21,7 @@ use crate::event_loop::{EventLoop, MainThreadExecutor, OsEventLoop}; use crate::param::internals::{ParamPtr, Params}; use crate::param::ParamFlags; use crate::plugin::{BufferConfig, BusConfig, Editor, NoteEvent, ProcessStatus, Vst3Plugin}; -use crate::wrapper::state::{self, State}; +use crate::wrapper::state::{self, PluginState}; use crate::wrapper::util::{hash_param_id, process_wrapper}; /// The actual wrapper bits. We need this as an `Arc` so we can safely use our event loop API. @@ -91,9 +91,9 @@ pub(crate) struct WrapperInner { /// In other words, the GUI thread acts as a sender and then as a receiver, while the audio /// thread acts as a receiver and then as a sender. That way deallocation can happen on the GUI /// thread. All of this happens without any blocking on the audio thread. - pub updated_state_sender: channel::Sender, + pub updated_state_sender: channel::Sender, /// The receiver belonging to [`new_state_sender`][Self::new_state_sender]. - pub updated_state_receiver: channel::Receiver, + pub updated_state_receiver: channel::Receiver, /// The keys from `param_map` in a stable order. pub param_hashes: Vec, @@ -324,7 +324,7 @@ impl WrapperInner

{ /// Get the plugin's state object, may be called by the plugin's GUI as part of its own preset /// management. The wrapper doesn't use these functions and serializes and deserializes directly /// the JSON in the relevant plugin API methods instead. - pub fn get_state_object(&self) -> State { + pub fn get_state_object(&self) -> PluginState { unsafe { state::serialize_object( self.params.clone(), @@ -337,7 +337,7 @@ impl WrapperInner

{ /// Update the plugin's internal state, called by the plugin itself from the GUI thread. To /// prevent corrupting data and changing parameters during processing the actual state is only /// updated at the end of the audio processing cycle. - pub fn set_state_object(&self, mut state: State) { + pub fn set_state_object(&self, mut state: PluginState) { // Use a loop and timeouts to handle the super rare edge case when this function gets called // between a process call and the host disabling the plugin loop {