pub trait GraphModule: Send + Sync {
Show 14 methods
// Required methods
fn port_spec(&self) -> &PortSpec;
fn tick(&mut self, inputs: &PortValues, outputs: &mut PortValues);
fn reset(&mut self);
fn set_sample_rate(&mut self, sample_rate: f64);
// Provided methods
fn process_block(
&mut self,
inputs: &BlockPortValues,
outputs: &mut BlockPortValues,
frames: usize,
) { ... }
fn breaks_feedback_cycle(&self) -> bool { ... }
fn params(&self) -> &[ParamDef] { ... }
fn get_param(&self, _id: ParamId) -> Option<f64> { ... }
fn set_param(&mut self, _id: ParamId, _value: f64) { ... }
fn type_id(&self) -> &'static str { ... }
fn serialize_state(&self) -> Option<Value> { ... }
fn deserialize_state(&mut self, _state: &Value) -> Result<(), String> { ... }
fn introspect(&self) -> Option<&dyn ModuleIntrospection> { ... }
fn introspect_mut(&mut self) -> Option<&mut dyn ModuleIntrospection> { ... }
}Expand description
Type-erased module interface for graph-based patching
Required Methods§
Sourcefn tick(&mut self, inputs: &PortValues, outputs: &mut PortValues)
fn tick(&mut self, inputs: &PortValues, outputs: &mut PortValues)
Process one sample given port values
Sourcefn set_sample_rate(&mut self, sample_rate: f64)
fn set_sample_rate(&mut self, sample_rate: f64)
Set sample rate
Provided Methods§
Sourcefn process_block(
&mut self,
inputs: &BlockPortValues,
outputs: &mut BlockPortValues,
frames: usize,
)
fn process_block( &mut self, inputs: &BlockPortValues, outputs: &mut BlockPortValues, frames: usize, )
Process a block of samples (optional optimization).
The default drives tick frame-by-frame. It reuses a single input and
output PortValues across the whole block (via
BlockPortValues::frame_into/set_frame_ref), so
it does not allocate per frame — only once per call to warm the reused buffers.
For the graph engine, prefer Patch::tick_block,
which is fully allocation-free after compile.
Sourcefn breaks_feedback_cycle(&self) -> bool
fn breaks_feedback_cycle(&self) -> bool
Whether this module breaks a feedback cycle in the patch graph.
The graph normally rejects any cable cycle with PatchError::CycleDetected.
A module that returns true (delay-style modules such as UnitDelay and
DelayLine) is treated as a one-sample delay boundary: Patch::compile excludes
the edges feeding into it from the topological sort, so a loop routed through it
compiles. At runtime such a module reads its inputs from the previous tick’s output
buffers, giving the classic single-sample feedback delay. Cycles that contain no
cycle-breaker still fail to compile.
Sourcefn params(&self) -> &[ParamDef]
fn params(&self) -> &[ParamDef]
Get parameter definitions for UI binding.
Most built-in modules do not use this API. Nearly all of them expose their
controllable quantities as input ports (see port_spec) —
e.g. a VCO’s frequency, an SVF’s cutoff, or an ADSR’s stage times are all input
ports driven by cables or their default values — and leave this method at its
empty default. The authoritative way to discover and drive parameters for GUIs is
the ModuleIntrospection API (available with the alloc feature), not this
trait-default no-op. It remains here only for the handful of modules whose
parameters are genuinely not ports.
Sourcefn get_param(&self, _id: ParamId) -> Option<f64>
fn get_param(&self, _id: ParamId) -> Option<f64>
Get a parameter value.
Defaults to None. See params: most modules surface their state
through input ports and ModuleIntrospection, not through this method.
Sourcefn set_param(&mut self, _id: ParamId, _value: f64)
fn set_param(&mut self, _id: ParamId, _value: f64)
Set a parameter value.
Defaults to a no-op. See params: most modules surface their state
through input ports and ModuleIntrospection, not through this method.
Sourcefn serialize_state(&self) -> Option<Value>
Available on crate feature alloc only.
fn serialize_state(&self) -> Option<Value>
alloc only.Serialize module state (alloc feature only)
Sourcefn deserialize_state(&mut self, _state: &Value) -> Result<(), String>
Available on crate feature alloc only.
fn deserialize_state(&mut self, _state: &Value) -> Result<(), String>
alloc only.Deserialize module state (alloc feature only)
Sourcefn introspect(&self) -> Option<&dyn ModuleIntrospection>
Available on crate feature alloc only.
fn introspect(&self) -> Option<&dyn ModuleIntrospection>
alloc only.Downcast this module to its ModuleIntrospection view, if it exposes one.
A Box<dyn GraphModule> (as stored inside a Patch) cannot
otherwise reach the module’s ModuleIntrospection impl, so this hook bridges the two
trait objects. It returns None by default; modules with genuine internal (non-port)
parameters override it — typically via impl_introspect! —
to return Some(self). Parameters that are input ports are discovered and driven
through the port system instead (see Patch::param_infos),
so most modules leave this at the default.
Gated on alloc because ModuleIntrospection (and its Vec/String payloads) live
in the alloc tier; pure no_std builds never see this method.
Sourcefn introspect_mut(&mut self) -> Option<&mut dyn ModuleIntrospection>
Available on crate feature alloc only.
fn introspect_mut(&mut self) -> Option<&mut dyn ModuleIntrospection>
alloc only.Mutable companion to introspect, used to set internal parameters.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl GraphModule for Adsr
impl GraphModule for AnalogVco
impl GraphModule for Arpeggiator
impl GraphModule for Attenuverter
impl GraphModule for BernoulliGate
impl GraphModule for Bitcrusher
impl GraphModule for ChordMemory
impl GraphModule for Chorus
impl GraphModule for Clock
impl GraphModule for Comparator
impl GraphModule for Compressor
impl GraphModule for Crossfader
impl GraphModule for Crosstalk
impl GraphModule for DelayLine
impl GraphModule for DiodeLadderFilter
impl GraphModule for Distortion
impl GraphModule for Ducker
impl GraphModule for EnvelopeFollower
impl GraphModule for Euclidean
impl GraphModule for ExternalInput
alloc only.impl GraphModule for ExternalOutput
alloc only.impl GraphModule for Flanger
impl GraphModule for FormantOsc
impl GraphModule for Granular
impl GraphModule for GroundLoop
impl GraphModule for KarplusStrong
impl GraphModule for Lfo
impl GraphModule for Limiter
impl GraphModule for LogicAnd
impl GraphModule for LogicNot
impl GraphModule for LogicOr
impl GraphModule for LogicXor
impl GraphModule for Max
impl GraphModule for MidSideDecode
impl GraphModule for MidSideEncode
impl GraphModule for Min
impl GraphModule for Mixer
impl GraphModule for Multiple
impl GraphModule for NoiseGate
impl GraphModule for NoiseGenerator
impl GraphModule for Offset
impl GraphModule for OscInput
std only.