Skip to main content

PluginContext

Struct PluginContext 

Source
pub struct PluginContext<P: ?Sized = dyn Params> { /* private fields */ }
Expand description

Context passed to Editor::open. Carries:

  • An Arc<dyn EditorBridge> - the host-plugin protocol surface (begin/set/end edit, request_resize, get_state, transport, …).
  • An Arc<P> typed parameter store - plugin authors Deref to &P and read fields directly: state.gain.read().

The default P = dyn Params keeps the trait-object boundary (Editor::open(ctx: PluginContext)) one-typed; editor crates that want typed access (truce-egui, truce-slint, truce-iced) carry their own <P> and reconstitute PluginContext<P> internally via PluginContext::with_params using the Arc<P> they stored at editor construction.

Clone is two refcount bumps (bridge + params). Editors that need to hand the context to UI worker threads or animation timers clone freely.

Implementations§

Source§

impl<P: ?Sized> PluginContext<P>

Source

pub fn new(bridge: Arc<dyn EditorBridge>, params: Arc<P>) -> Self

Build a typed context from any EditorBridge implementor and the plugin’s typed param store.

Source

pub fn bridge(&self) -> &Arc<dyn EditorBridge>

Access the underlying bridge handle. Editors that want to clone the bridge into a worker thread without cloning the surrounding PluginContext use this.

Source

pub fn params(&self) -> &Arc<P>

Access the typed param store as an Arc. Use this when you need to capture the params in a 'static closure (e.g. an iced Subscription or a worker thread).

Source

pub fn with_params<Q: ?Sized>(&self, params: Arc<Q>) -> PluginContext<Q>

Replace the param-store generic parameter while reusing the same bridge. Used by editor crates that receive the dyn-erased PluginContext from Editor::open and want the typed PluginContext<P> for their UI closure.

Source

pub fn begin_edit(&self, id: impl Into<u32>)

Source

pub fn set_param(&self, id: impl Into<u32>, normalized: f64)

Source

pub fn end_edit(&self, id: impl Into<u32>)

Source

pub fn automate(&self, id: impl Into<u32>, normalized: f64)

Begin + set + end in one call. Use for click-to-toggle widgets and similar single-shot edits where the gesture and the value arrive together.

Source

pub fn request_resize(&self, w: u32, h: u32) -> bool

Source

pub fn format_param(&self, id: impl Into<u32>) -> String

Source

pub fn format_param_into(&self, id: impl Into<u32>, out: &mut String)

Format into a caller-owned buffer. See EditorBridge::format_param_into for the allocation trade-off - the caller’s buffer is reused, but bridges that don’t override the default impl still allocate internally.

Source

pub fn get_meter(&self, id: impl Into<u32>) -> f32

Source

pub fn get_state(&self) -> Vec<u8>

Source

pub fn set_state(&self, data: Vec<u8>)

Source

pub fn transport(&self) -> Option<TransportInfo>

Source§

impl PluginContext<dyn Params>

Source

pub fn from_closures(bridge: ClosureBridge, params: Arc<dyn Params>) -> Self

Build a dyn-erased context from a ClosureBridge. Convenience for format wrappers that compose state inline via closures.

Source§

impl<P: Params + 'static> PluginContext<P>

Source

pub fn dyn_erase(self) -> PluginContext<dyn Params>

Drop the typed <P> and return the dyn-erased context that crosses the Editor::open trait-object boundary.

Trait Implementations§

Source§

impl<P: ?Sized> Clone for PluginContext<P>

Source§

fn clone(&self) -> Self

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<P: ?Sized> Deref for PluginContext<P>

Plugin authors read parameter fields directly via Deref: state.gain.read(), state.bypass.value(). The state here is &PluginContext<MyParams> and Deref::Target = MyParams.

Source§

type Target = P

The resulting type after dereferencing.
Source§

fn deref(&self) -> &P

Dereferences the value.
Source§

impl<P: ?Sized> PluginContextReadF32 for PluginContext<P>

Source§

fn get_param(&self, id: impl Into<u32>) -> f32

Normalized [0, 1] value of the parameter, narrowed to f32.
Source§

fn get_param_plain(&self, id: impl Into<u32>) -> f32

Plain (denormalized) value of the parameter, narrowed to f32.
Source§

impl<P: ?Sized> PluginContextReadF64 for PluginContext<P>

Source§

fn get_param(&self, id: impl Into<u32>) -> f64

Normalized [0, 1] value of the parameter.
Source§

fn get_param_plain(&self, id: impl Into<u32>) -> f64

Plain (denormalized) value of the parameter.

Auto Trait Implementations§

§

impl<P> Freeze for PluginContext<P>
where P: ?Sized,

§

impl<P = dyn Params> !RefUnwindSafe for PluginContext<P>

§

impl<P> Send for PluginContext<P>
where P: Sync + Send + ?Sized,

§

impl<P> Sync for PluginContext<P>
where P: Sync + Send + ?Sized,

§

impl<P> Unpin for PluginContext<P>
where P: ?Sized,

§

impl<P> UnsafeUnpin for PluginContext<P>
where P: ?Sized,

§

impl<P = dyn Params> !UnwindSafe for PluginContext<P>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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> 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.