pub struct PluginContext<P = dyn Params>where
P: ?Sized,{ /* 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 authorsDerefto&Pand 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> PluginContext<P>where
P: ?Sized,
impl<P> PluginContext<P>where
P: ?Sized,
Sourcepub fn new(bridge: Arc<dyn EditorBridge>, params: Arc<P>) -> PluginContext<P>
pub fn new(bridge: Arc<dyn EditorBridge>, params: Arc<P>) -> PluginContext<P>
Build a typed context from any EditorBridge implementor and
the plugin’s typed param store.
Sourcepub fn bridge(&self) -> &Arc<dyn EditorBridge>
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.
Sourcepub fn params(&self) -> &Arc<P>
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).
Sourcepub fn with_params<Q>(&self, params: Arc<Q>) -> PluginContext<Q>where
Q: ?Sized,
pub fn with_params<Q>(&self, params: Arc<Q>) -> PluginContext<Q>where
Q: ?Sized,
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.
pub fn begin_edit(&self, id: impl Into<u32>)
pub fn set_param(&self, id: impl Into<u32>, normalized: f64)
pub fn end_edit(&self, id: impl Into<u32>)
Sourcepub fn automate(&self, id: impl Into<u32>, normalized: f64)
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.
pub fn request_resize(&self, w: u32, h: u32) -> bool
pub fn format_param(&self, id: impl Into<u32>) -> String
Sourcepub fn format_param_into(&self, id: impl Into<u32>, out: &mut String)
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.
pub fn get_meter(&self, id: impl Into<u32>) -> f32
pub fn get_state(&self) -> Vec<u8> ⓘ
pub fn set_state(&self, data: Vec<u8>)
pub fn transport(&self) -> Option<TransportInfo>
Source§impl PluginContext
impl PluginContext
Sourcepub fn from_closures(
bridge: ClosureBridge,
params: Arc<dyn Params>,
) -> PluginContext
pub fn from_closures( bridge: ClosureBridge, params: Arc<dyn Params>, ) -> PluginContext
Build a dyn-erased context from a ClosureBridge. Convenience
for format wrappers that compose state inline via closures.
Source§impl<P> PluginContext<P>where
P: Params + 'static,
impl<P> PluginContext<P>where
P: Params + 'static,
Sourcepub fn dyn_erase(self) -> PluginContext
pub fn dyn_erase(self) -> PluginContext
Drop the typed <P> and return the dyn-erased context that
crosses the Editor::open trait-object boundary.
Trait Implementations§
Source§impl<P> Clone for PluginContext<P>where
P: ?Sized,
impl<P> Clone for PluginContext<P>where
P: ?Sized,
Source§fn clone(&self) -> PluginContext<P>
fn clone(&self) -> PluginContext<P>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<P> Deref for PluginContext<P>where
P: ?Sized,
Plugin authors read parameter fields directly via Deref:
state.gain.read(), state.bypass.value(). The state
here is &PluginContext<MyParams> and Deref::Target = MyParams.
impl<P> Deref for PluginContext<P>where
P: ?Sized,
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§impl<P> PluginContextReadF32 for PluginContext<P>where
P: ?Sized,
impl<P> PluginContextReadF32 for PluginContext<P>where
P: ?Sized,
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>
impl<P> Sync for PluginContext<P>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<State, Message> IntoBoot<State, Message> for State
impl<State, Message> IntoBoot<State, Message> for State
Source§fn into_boot(self) -> (State, Task<Message>)
fn into_boot(self) -> (State, Task<Message>)
Application.