Skip to main content

StateContext

Enum StateContext 

Source
pub enum StateContext {
    Project,
    Preset {
        path: Option<String>,
    },
}
Expand description

Why a plugin is being handed a state blob.

VST3 lets a plugin ask where the state it is being given came from: the host attaches an IStreamAttributes list to the IBStream it passes to setState, and the plugin reads the PresetAttributes::kStateType key from it. The SDK ships Vst::Helpers::isProjectState() for exactly this — it answers “yes” only for StateType::kProject and “this came from a preset” for every other value — and plugins use the answer to decide what to restore (a preset should not, for instance, drag a project’s per-instance routing along with it).

Pass this to Plugin::load_state_with_context. Plugin::load_state uses StateContext::Project; Plugin::load_vstpreset and Plugin::load_preset use StateContext::Preset with the file they read.

Variants§

§

Project

The blob is part of a host session/project restore.

Tags the stream StateType::kProject — “the state is restored from a project loading or it is saved in a project”.

§

Preset

The blob came from a standalone preset file.

Tags the stream StateType::kTrackPreset. Of the three values the SDK defines, kProject is explicitly the project case and kDefault is narrower than it looks — “the state is restored from a preset (marked as default) or the host wants to store a default state of the plug-in” — so claiming it for a preset the user picked would tell the plugin this is its initialization patch. kTrackPreset (“the state is restored from a track preset”) is the SDK’s remaining preset-file value, and it is what makes Vst::Helpers::isProjectState() answer “came from a preset” rather than the “host doesn’t implement this” it returns when the attribute is missing entirely.

Fields

§path: Option<String>

Full path of the file the state was read from, when the caller knows it.

Published as PresetAttributes::kFilePathStringType (“full file path string (if available) where the preset comes from”); left off the stream when None.

Text rather than a PathBuf because it is published as a UTF-16 stream attribute and crosses the process-isolation boundary as JSON, neither of which can carry a non-UTF-8 path. StateContext::preset_from_path does the lossy conversion once, where it is visible.

Implementations§

Source§

impl StateContext

Source

pub fn preset() -> Self

A preset load whose source file is unknown (state handed over in memory, say).

Source

pub fn preset_from_path(path: impl AsRef<Path>) -> Self

A preset load from path, which the plugin will see as the stream’s file path.

Source

pub fn file_path(&self) -> Option<&Path>

The source file this state came from, when one is known.

Trait Implementations§

Source§

impl Clone for StateContext

Source§

fn clone(&self) -> StateContext

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StateContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for StateContext

Source§

fn default() -> StateContext

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for StateContext

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for StateContext

Source§

impl PartialEq for StateContext

Source§

fn eq(&self, other: &StateContext) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for StateContext

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for StateContext

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.