truce_core/plugin.rs
1use crate::buffer::AudioBuffer;
2use crate::bus::BusLayout;
3use crate::editor::Editor;
4use crate::events::EventList;
5use crate::info::PluginInfo;
6use crate::process::{ProcessContext, ProcessStatus};
7
8/// The core trait that all plugins implement.
9pub trait Plugin: Send + 'static {
10 /// Static metadata about the plugin.
11 ///
12 /// Use `plugin_info!()` for zero-boilerplate (reads from truce.toml
13 /// + Cargo.toml). Requires `truce-build` in `[build-dependencies]`.
14 fn info() -> PluginInfo
15 where
16 Self: Sized;
17
18 /// Supported bus layouts. The host picks one.
19 fn bus_layouts() -> Vec<BusLayout>
20 where
21 Self: Sized,
22 {
23 vec![BusLayout::stereo()]
24 }
25
26 /// Called once after construction. Not real-time safe.
27 fn init(&mut self) {}
28
29 /// Called when sample rate or max block size changes.
30 /// Reset filters, delay lines, etc. Not real-time safe.
31 fn reset(&mut self, sample_rate: f64, max_block_size: usize);
32
33 /// Real-time audio processing.
34 fn process(
35 &mut self,
36 buffer: &mut AudioBuffer,
37 events: &EventList,
38 context: &mut ProcessContext,
39 ) -> ProcessStatus;
40
41 /// Save extra state beyond parameter values.
42 fn save_state(&self) -> Option<Vec<u8>> {
43 None
44 }
45
46 /// Restore extra state.
47 fn load_state(&mut self, _data: &[u8]) {}
48
49 /// GUI editor. Return None for headless plugins.
50 fn editor(&mut self) -> Option<Box<dyn Editor>> {
51 None
52 }
53
54 /// Processing latency in samples. Host uses this for delay compensation.
55 /// Return 0 if the plugin adds no latency (default).
56 fn latency(&self) -> u32 {
57 0
58 }
59
60 /// Tail time in samples. Return u32::MAX for infinite tail.
61 /// Return 0 for no tail (default).
62 fn tail(&self) -> u32 {
63 0
64 }
65
66 /// Read a meter value by ID (0.0–1.0). Called by the GUI at ~60fps.
67 /// Override to expose level meters, gain reduction, etc.
68 fn get_meter(&self, _meter_id: u32) -> f32 {
69 0.0
70 }
71}