Skip to main content

rill_core_dsp/
algorithm.rs

1//! Re-exports `rill_core::Algorithm` and provides DSP-specific extensions.
2//!
3//! The base `Algorithm` trait lives in `rill_core`. This module re-exports it
4//! together with the DSP-specific `ParameterizedAlgorithm` abstraction.
5
6pub use rill_core::traits::algorithm::{
7    ActionContext, Algorithm, AlgorithmCategory, AlgorithmMetadata,
8};
9pub use rill_core::traits::ProcessResult;
10
11use rill_core::traits::ParamValue;
12use rill_core::Transcendental;
13
14/// An `Algorithm` with typed, settable parameters.
15///
16/// Extends the base `Algorithm` trait with the ability to get and set
17/// a typed parameter struct (`Params`) and to update individual parameters
18/// by name (for automation integration).
19pub trait ParameterizedAlgorithm<T: Transcendental>: Algorithm<T> {
20    /// The concrete parameter type for this algorithm.
21    type Params: Clone + Send + Sync;
22
23    /// Get a reference to the current parameters.
24    fn params(&self) -> &Self::Params;
25
26    /// Replace all parameters atomically.
27    ///
28    /// The implementation should recompute any derived coefficients.
29    fn set_params(&mut self, params: Self::Params);
30
31    /// Set a single parameter by name (for automation / scripting).
32    ///
33    /// Default: returns an error for any unrecognised name.
34    fn set_parameter(&mut self, name: &str, value: ParamValue) -> Result<(), &'static str> {
35        Err(format!("Parameter '{}' not supported", name).leak())
36    }
37}