1
0
Fork 0

Rename State to PluginState

Now that it is part of the public API.
This commit is contained in:
Robbert van der Helm 2022-04-07 17:39:34 +02:00
parent 84bac0a47c
commit 2af3f84416
7 changed files with 27 additions and 27 deletions

View file

@ -3,7 +3,7 @@
use crate::param::internals::ParamPtr; use crate::param::internals::ParamPtr;
use crate::param::Param; use crate::param::Param;
use crate::plugin::NoteEvent; use crate::plugin::NoteEvent;
use crate::wrapper::state::State; use crate::wrapper::state::PluginState;
// TODO: ProcessContext for parameter automation and sending events // 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 /// Serialize the plugin's current state to a serde-serializable object. Useful for implementing
/// preset handling within a plugin's GUI. /// 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 /// 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 /// 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 /// host. If the plugin is currently processing audio, then the parameter values will be
/// restored at the end of the current processing cycle. /// 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 /// Information about the plugin's transport. Depending on the plugin API and the host not all

View file

@ -22,4 +22,4 @@ pub use crate::plugin::{
BufferConfig, BusConfig, ClapPlugin, Editor, NoteEvent, ParentWindowHandle, Plugin, BufferConfig, BusConfig, ClapPlugin, Editor, NoteEvent, ParentWindowHandle, Plugin,
ProcessStatus, Vst3Plugin, ProcessStatus, Vst3Plugin,
}; };
pub use crate::wrapper::state::State; pub use crate::wrapper::state::PluginState;

View file

@ -80,11 +80,11 @@ impl<P: ClapPlugin> GuiContext for WrapperGuiContext<P> {
} }
} }
fn get_state(&self) -> crate::wrapper::state::State { fn get_state(&self) -> crate::wrapper::state::PluginState {
self.wrapper.get_state_object() 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) self.wrapper.set_state_object(state)
} }
} }

View file

@ -75,7 +75,7 @@ use crate::plugin::{
BufferConfig, BusConfig, ClapPlugin, Editor, NoteEvent, ParentWindowHandle, ProcessStatus, BufferConfig, BusConfig, ClapPlugin, Editor, NoteEvent, ParentWindowHandle, ProcessStatus,
}; };
use crate::util::permit_alloc; 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}; 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 /// How many output parameter changes we can store in our output parameter change queue. Storing
@ -139,9 +139,9 @@ pub struct Wrapper<P: ClapPlugin> {
/// In other words, the GUI thread acts as a sender and then as a receiver, while the audio /// 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 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. /// thread. All of this happens without any blocking on the audio thread.
updated_state_sender: channel::Sender<State>, updated_state_sender: channel::Sender<PluginState>,
/// The receiver belonging to [`new_state_sender`][Self::new_state_sender]. /// The receiver belonging to [`new_state_sender`][Self::new_state_sender].
updated_state_receiver: channel::Receiver<State>, updated_state_receiver: channel::Receiver<PluginState>,
/// Needs to be boxed because the plugin object is supposed to contain a static reference to /// Needs to be boxed because the plugin object is supposed to contain a static reference to
/// this. /// this.
@ -928,7 +928,7 @@ impl<P: ClapPlugin> Wrapper<P> {
/// Get the plugin's state object, may be called by the plugin's GUI as part of its own preset /// 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 /// management. The wrapper doesn't use these functions and serializes and deserializes directly
/// the JSON in the relevant plugin API methods instead. /// the JSON in the relevant plugin API methods instead.
pub fn get_state_object(&self) -> State { pub fn get_state_object(&self) -> PluginState {
unsafe { unsafe {
state::serialize_object( state::serialize_object(
self.params.clone(), self.params.clone(),
@ -941,7 +941,7 @@ impl<P: ClapPlugin> Wrapper<P> {
/// Update the plugin's internal state, called by the plugin itself from the GUI thread. To /// 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 /// prevent corrupting data and changing parameters during processing the actual state is only
/// updated at the end of the audio processing cycle. /// 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 // 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 // between a process call and the host disabling the plugin
loop { loop {

View file

@ -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 /// A plugin's state so it can be restored at a later point. This object can be serialized and
/// deserialized using serde. /// deserialized using serde.
#[derive(Debug, Clone, Serialize, Deserialize)] #[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 /// 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 /// 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. /// parmaeter automation though, depending on how the host impelments that.
@ -44,7 +44,7 @@ pub(crate) unsafe fn serialize_object(
plugin_params: Arc<dyn Params>, plugin_params: Arc<dyn Params>,
param_by_hash: &HashMap<u32, ParamPtr>, param_by_hash: &HashMap<u32, ParamPtr>,
param_id_to_hash: &HashMap<String, u32>, param_id_to_hash: &HashMap<String, u32>,
) -> State { ) -> PluginState {
// 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: HashMap<_, _> = param_id_to_hash let params: HashMap<_, _> = param_id_to_hash
.iter() .iter()
@ -78,7 +78,7 @@ pub(crate) unsafe fn serialize_object(
// storing things like sample data. // storing things like sample data.
let fields = plugin_params.serialize_fields(); 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 /// 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) 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 /// Deserialize a plugin's state from a [`PluginState`] object. This is used to allow the plugin to
/// own internal preset management. Returns `false` and logs an error if the state could not be /// do its own internal preset management. Returns `false` and logs an error if the state could not
/// deserialized. /// be deserialized.
/// ///
/// Make sure to reinitialize plugin after deserializing the state so it can react to the new /// 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. /// parameter values. The smoothers have already been reset by this function.
pub(crate) unsafe fn deserialize_object( pub(crate) unsafe fn deserialize_object(
state: &State, state: &PluginState,
plugin_params: Arc<dyn Params>, plugin_params: Arc<dyn Params>,
param_by_hash: &HashMap<u32, ParamPtr>, param_by_hash: &HashMap<u32, ParamPtr>,
param_id_to_hash: &HashMap<String, u32>, param_id_to_hash: &HashMap<String, u32>,
@ -162,7 +162,7 @@ pub(crate) unsafe fn deserialize_json(
param_id_to_hash: &HashMap<String, u32>, param_id_to_hash: &HashMap<String, u32>,
current_buffer_config: Option<&BufferConfig>, current_buffer_config: Option<&BufferConfig>,
) -> bool { ) -> bool {
let state: State = match serde_json::from_slice(state) { let state: PluginState = match serde_json::from_slice(state) {
Ok(s) => s, Ok(s) => s,
Err(err) => { Err(err) => {
nih_debug_assert_failure!("Error while deserializing state: {}", err); nih_debug_assert_failure!("Error while deserializing state: {}", err);

View file

@ -9,7 +9,7 @@ use crate::context::{GuiContext, ProcessContext, Transport};
use crate::event_loop::EventLoop; use crate::event_loop::EventLoop;
use crate::param::internals::ParamPtr; use crate::param::internals::ParamPtr;
use crate::plugin::{NoteEvent, Vst3Plugin}; 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 /// 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 /// [`Editor::spawn()`][crate::prelude::Editor::spawn()] so it can interact with the rest of the plugin and
@ -89,11 +89,11 @@ impl<P: Vst3Plugin> GuiContext for WrapperGuiContext<P> {
} }
} }
fn get_state(&self) -> State { fn get_state(&self) -> PluginState {
self.inner.get_state_object() self.inner.get_state_object()
} }
fn set_state(&self, state: State) { fn set_state(&self, state: PluginState) {
self.inner.set_state_object(state) self.inner.set_state_object(state)
} }
} }

View file

@ -21,7 +21,7 @@ use crate::event_loop::{EventLoop, MainThreadExecutor, OsEventLoop};
use crate::param::internals::{ParamPtr, Params}; use crate::param::internals::{ParamPtr, Params};
use crate::param::ParamFlags; use crate::param::ParamFlags;
use crate::plugin::{BufferConfig, BusConfig, Editor, NoteEvent, ProcessStatus, Vst3Plugin}; 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}; use crate::wrapper::util::{hash_param_id, process_wrapper};
/// The actual wrapper bits. We need this as an `Arc<T>` so we can safely use our event loop API. /// The actual wrapper bits. We need this as an `Arc<T>` so we can safely use our event loop API.
@ -91,9 +91,9 @@ pub(crate) struct WrapperInner<P: Vst3Plugin> {
/// In other words, the GUI thread acts as a sender and then as a receiver, while the audio /// 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 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. /// thread. All of this happens without any blocking on the audio thread.
pub updated_state_sender: channel::Sender<State>, pub updated_state_sender: channel::Sender<PluginState>,
/// The receiver belonging to [`new_state_sender`][Self::new_state_sender]. /// The receiver belonging to [`new_state_sender`][Self::new_state_sender].
pub updated_state_receiver: channel::Receiver<State>, pub updated_state_receiver: channel::Receiver<PluginState>,
/// The keys from `param_map` in a stable order. /// The keys from `param_map` in a stable order.
pub param_hashes: Vec<u32>, pub param_hashes: Vec<u32>,
@ -324,7 +324,7 @@ impl<P: Vst3Plugin> WrapperInner<P> {
/// Get the plugin's state object, may be called by the plugin's GUI as part of its own preset /// 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 /// management. The wrapper doesn't use these functions and serializes and deserializes directly
/// the JSON in the relevant plugin API methods instead. /// the JSON in the relevant plugin API methods instead.
pub fn get_state_object(&self) -> State { pub fn get_state_object(&self) -> PluginState {
unsafe { unsafe {
state::serialize_object( state::serialize_object(
self.params.clone(), self.params.clone(),
@ -337,7 +337,7 @@ impl<P: Vst3Plugin> WrapperInner<P> {
/// Update the plugin's internal state, called by the plugin itself from the GUI thread. To /// 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 /// prevent corrupting data and changing parameters during processing the actual state is only
/// updated at the end of the audio processing cycle. /// 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 // 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 // between a process call and the host disabling the plugin
loop { loop {