truce_core/export.rs
1use std::sync::Arc;
2
3use crate::plugin::Plugin;
4use truce_params::Params;
5
6/// Unified export trait for all plugin formats.
7///
8/// Implement this once on your plugin type. All format wrappers
9/// (CLAP, VST3, AU, standalone) use this to construct your plugin
10/// and access its parameters.
11///
12/// ```ignore
13/// impl PluginExport for MyPlugin {
14/// type Params = MyParams;
15/// fn create() -> Self { Self::new() }
16/// fn params(&self) -> &MyParams { &self.params }
17/// fn params_mut(&mut self) -> &mut MyParams { &mut self.params }
18/// }
19/// ```
20pub trait PluginExport: Plugin + Sized {
21 type Params: Params;
22
23 /// Construct a new instance of the plugin.
24 fn create() -> Self;
25
26 /// Immutable access to the parameter struct.
27 fn params(&self) -> &Self::Params;
28
29 /// Mutable access to the parameter struct.
30 fn params_mut(&mut self) -> &mut Self::Params;
31
32 /// Get a shared `Arc` reference to the parameter struct.
33 ///
34 /// Used by format wrappers to pass params to GUI closures without
35 /// raw pointers. The Arc is cloned (cheap ref-count bump), not the
36 /// params themselves.
37 fn params_arc(&self) -> Arc<Self::Params>;
38}