Skip to main content

endless_rs/
patch.rs

1//! The `Patch` trait — the safe Rust API for Endless effects.
2
3use crate::types::{ActionId, Color, ParamId, ParameterMetadata};
4
5/// Trait implemented by Endless effect patches.
6///
7/// All methods have default (no-op) implementations so you only need to
8/// override the ones your effect requires. At minimum you'll want
9/// [`process_audio`](Patch::process_audio).
10pub trait Patch {
11    /// Called once at patch load time.
12    fn init(&mut self) {}
13
14    /// Called once to provide the external working buffer.
15    ///
16    /// This buffer lives in external RAM with higher access latency.
17    /// The slice length is [`WORKING_BUFFER_SIZE`](crate::WORKING_BUFFER_SIZE).
18    fn set_working_buffer(&mut self, _buffer: &'static mut [f32]) {}
19
20    /// Process audio buffers in-place. Called repeatedly from the audio thread.
21    ///
22    /// `left` and `right` are guaranteed to have equal length. Keep output
23    /// samples in the range `(-1.0, 1.0)` to avoid digital clipping.
24    ///
25    /// The return value is passed back to the firmware (typically `0.0`).
26    fn process_audio(&mut self, _left: &mut [f32], _right: &mut [f32]) -> f32 {
27        0.0
28    }
29
30    /// Return metadata for the given parameter.
31    fn param_metadata(&self, _param: ParamId) -> ParameterMetadata {
32        ParameterMetadata::default()
33    }
34
35    /// Called when a knob value changes. Runs on the audio thread.
36    fn set_param(&mut self, _param: ParamId, _value: f32) {}
37
38    /// Called when a foot-switch action fires.
39    fn handle_action(&mut self, _action: ActionId) {}
40
41    /// Return the current LED color.
42    fn state_led_color(&self) -> Color {
43        Color::DimWhite
44    }
45}