pub trait Effect:
AudioProcessor
+ Send
+ Sync {
// Required methods
fn id(&self) -> u32;
fn name(&self) -> &str;
fn get_color(&self) -> String;
fn to_dto(&self) -> EffectDto;
fn active_flag(&self) -> Arc<AtomicBool>;
// Provided methods
fn is_active(&self) -> bool { ... }
fn set_active(&self, active: bool) { ... }
fn f32_params(&self) -> HashMap<&'static str, Arc<AtomicF32>> { ... }
fn u32_params(&self) -> HashMap<&'static str, Arc<AtomicU32>> { ... }
fn process_if_active(&mut self, sample: f32) -> f32 { ... }
}Expand description
A trait defining the shared behavior for audio effects within the signal chain.
The Effect trait extends AudioProcessor, providing metadata and state management
(such as enabling or bypassing the effect) in addition to the core signal processing
capabilities.
§Requirements
Types implementing Effect must also implement AudioProcessor, which provides the
primary process method used for manipulating audio samples.
Required Methods§
Sourcefn name(&self) -> &str
fn name(&self) -> &str
Returns the human-readable name of the effect (e.g., “Overdrive”, “Delay”).
Sourcefn get_color(&self) -> String
fn get_color(&self) -> String
Returns a color code (hex) associated with this effect for UI representation.
Sourcefn to_dto(&self) -> EffectDto
fn to_dto(&self) -> EffectDto
Converts this effect into its serialisable EffectDto representation.
Each concrete effect type returns the correct variant of the tagged union, carrying its own specific parameters alongside the shared fields.
Sourcefn active_flag(&self) -> Arc<AtomicBool>
fn active_flag(&self) -> Arc<AtomicBool>
Returns the shared Arc<AtomicBool> that drives process_if_active.
Command handlers write to it; the audio thread reads it lock-free.
Provided Methods§
Sourcefn is_active(&self) -> bool
fn is_active(&self) -> bool
Returns true if the effect is currently enabled and processing audio.
If false, the effect should ideally be bypassed to save CPU or maintain
signal transparency.
Sourcefn set_active(&self, active: bool)
fn set_active(&self, active: bool)
Sets whether the effect is active or bypassed.
active-trueto enable the effect,falseto bypass it.
Sourcefn f32_params(&self) -> HashMap<&'static str, Arc<AtomicF32>>
fn f32_params(&self) -> HashMap<&'static str, Arc<AtomicF32>>
Returns named f32 parameter Arcs shared with the audio thread. Defaults to an empty map — override for effects with extra parameters.
Implementing this is the only change required to make a new effect’s parameters controllable from commands — no downcasting anywhere.
Sourcefn u32_params(&self) -> HashMap<&'static str, Arc<AtomicU32>>
fn u32_params(&self) -> HashMap<&'static str, Arc<AtomicU32>>
Returns named u32 parameter Arcs shared with the audio thread. Defaults to an empty map — override for effects with extra parameters.
Implementing this is the only change required to make a new effect’s parameters controllable from commands — no downcasting anywhere.
Sourcefn process_if_active(&mut self, sample: f32) -> f32
fn process_if_active(&mut self, sample: f32) -> f32
Processes a single audio sample only if the effect is currently active.
This is the primary entry point for a signal chain. If is_active
returns true, the sample is passed to the underlying process method.
Otherwise, the input sample is returned unchanged (unity gain bypass).
§Parameters
sample: The input floating-point audio sample
§Returns
The processed sample if active, or the original sample if bypassed.