From 54371fb488b116b6b940e06f286b86b1818f6e4a Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Thu, 7 Apr 2022 14:12:02 +0200 Subject: [PATCH] Expose the State object So we can later allow plugins to save and restore state from their GUI this way. --- src/prelude.rs | 1 + src/wrapper.rs | 2 +- src/wrapper/state.rs | 13 +++++++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/prelude.rs b/src/prelude.rs index 0bfb7014..ed45786c 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -22,3 +22,4 @@ pub use super::plugin::{ BufferConfig, BusConfig, ClapPlugin, Editor, NoteEvent, ParentWindowHandle, Plugin, ProcessStatus, Vst3Plugin, }; +pub use super::wrapper::state::State; diff --git a/src/wrapper.rs b/src/wrapper.rs index f43089f4..0c74f31e 100644 --- a/src/wrapper.rs +++ b/src/wrapper.rs @@ -2,6 +2,6 @@ //! name of a type that implements `Plugin` to. The macro will handle the rest. pub mod clap; -pub(crate) mod state; +pub mod state; pub(crate) mod util; pub mod vst3; diff --git a/src/wrapper/state.rs b/src/wrapper/state.rs index 3deaf7bf..b686a465 100644 --- a/src/wrapper/state.rs +++ b/src/wrapper/state.rs @@ -1,4 +1,5 @@ -//! Utilities for saving a [crate::plugin::Plugin]'s state. +//! Utilities for saving a [crate::plugin::Plugin]'s state. The actual state object is also exposed +//! to plugins through the [`GuiContext`][crate::prelude::GuiContext]. use serde::{Deserialize, Serialize}; use std::collections::HashMap; @@ -8,18 +9,22 @@ use crate::param::internals::{ParamPtr, Params}; use crate::param::Param; use crate::plugin::BufferConfig; +// These state objects are also exposed directly to the plugin so it can do its own internal preset +// management + /// A plain, unnormalized value for a parameter. #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] -pub(crate) enum ParamValue { +pub enum ParamValue { F32(f32), I32(i32), Bool(bool), } -/// A plugin's state so it can be restored at a later point. +/// A plugin's state so it can be restored at a later point. This object can be serialized and +/// deserialized using serde. #[derive(Debug, Serialize, Deserialize)] -pub(crate) struct State { +pub struct State { /// 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.