pub struct Channel { /* private fields */ }Expand description
Represents an audio channel with atomic gain, master volume, and tone stack parameters.
Channel uses [AtomicF32] for lock-free updates of audio parameters from
the UI thread while the audio processing thread reads them without waiting.
This enables low-latency parameter changes without interrupting audio playback.
The tone stack provides equalization controls for bass (low frequencies), middle (mid-range frequencies), and treble (high frequencies), allowing fine-tuning of the audio signal’s frequency response. These parameters are also updated atomically for low-latency changes.
Effect chain is the chain of effects where the signal is put through. Effects are applied in the order they are added to the chain.
The Channel struct provides methods to add and remove effects from the chain, allowing dynamic modification of the audio processing pipeline.
Next effect_id is the unique identifier given to the next created effect in the chain.
Gain and volume are validated to be positive values (> 0.0); attempting to set a negative or zero value will panic.
Tone stack values are validated to be between 0.0 and 1.0; attempting to set a value outside this range will panic.
Implementations§
Source§impl Channel
impl Channel
Sourcepub fn new(
id: u32,
name: String,
gain: Option<f32>,
volume: Option<f32>,
) -> Self
pub fn new( id: u32, name: String, gain: Option<f32>, volume: Option<f32>, ) -> Self
Creates a new Channel with the given name and optional gain/master volume values.
If gain or master_volume are not provided, they default to 1.0.
The tone stack parameters (bass, middle, treble) are initialized to 1.0.
The effect chain is initialized as an empty vector, and the next effect ID starts at 0.
§Arguments
name- A human-readable name for the channel (e.g., “Main”, “Overdrive”).gain- Optional initial gain value. Defaults to1.0ifNone.master_volume- Optional initial master volume value. Defaults to1.0ifNone.
Sourcepub fn gain(&self) -> Arc<AtomicF32>
pub fn gain(&self) -> Arc<AtomicF32>
Returns a cloned Arc to the atomic gain value.
Allows independent threads to share and read/write the gain parameter without contention.
Sourcepub fn set_tone_stack(&self, tone_stack: ToneStackDto)
pub fn set_tone_stack(&self, tone_stack: ToneStackDto)
Sets the tone stack parameters from a ToneStackDto.
The bass, middle, and treble values in the DTO should be between 0.0 and 1.0.
§Arguments
tone_stack- The tone stack data transfer object containing the new values.
§Panics
Panics if any value is outside the valid range.
Sourcepub fn set_middle(&self, middle: f32)
pub fn set_middle(&self, middle: f32)
Sourcepub fn set_treble(&self, treble: f32)
pub fn set_treble(&self, treble: f32)
Sourcepub fn tone_stack(&self) -> Arc<ToneStack>
pub fn tone_stack(&self) -> Arc<ToneStack>
Returns a cloned Arc to the tone stack.
Allows independent threads to access the tone stack parameters for audio processing.
Sourcepub fn set_volume(&self, volume: f32)
pub fn set_volume(&self, volume: f32)
Sets the volume for this channel.
#Arguments
volume- The volume level (must be positive)
§Panics
Panics if the volume is negative.
Sourcepub fn volume(&self) -> Arc<AtomicF32>
pub fn volume(&self) -> Arc<AtomicF32>
Returns a cloned Arc to the atomic volume value.
Allows independent threads to share and read/write the volume parameter without contention.
Sourcepub fn effect_chain(&self) -> Arc<Mutex<Vec<Box<dyn Effect>>>>
pub fn effect_chain(&self) -> Arc<Mutex<Vec<Box<dyn Effect>>>>
Returns an Arc<Mutex<Vec<Box<dyn Effect>>>> representing the effect chain for this channel.
Sourcepub fn restore_effect_chain(&mut self, effects: Vec<Box<dyn Effect>>)
pub fn restore_effect_chain(&mut self, effects: Vec<Box<dyn Effect>>)
Sets the effect chain to a new given chain of effects
Sourcepub fn add_effect_to_chain(&mut self, effect: Box<dyn Effect>)
pub fn add_effect_to_chain(&mut self, effect: Box<dyn Effect>)
Adds an effect, capturing its shared atomic handles so commands can reach them after the chain has been moved to the audio thread.
No downcasting — every effect self-reports its parameters via
Effect::f32_params.
Sourcepub fn remove_effect_from_chain(&mut self, effect_id: u32)
pub fn remove_effect_from_chain(&mut self, effect_id: u32)
Removes an effect from the channel’s effect chain by its unique identifier.
If the effect is found and removed, an informational message is logged. If the effect is not found, an error message is logged.
§Arguments
effect_id- The unique identifier of the effect to remove from the chain
Sourcepub fn next_effect_id(&self) -> u32
pub fn next_effect_id(&self) -> u32
Returns the next available unique identifier for an effect in this channel’s effect chain.
Sourcepub fn used_cabinet_ir_profiles(&self) -> HashSet<String>
pub fn used_cabinet_ir_profiles(&self) -> HashSet<String>
Returns the set of cabinet IR file names referenced by this channel.
This reads mirrored effect metadata from effect_handles and therefore
does not touch the real-time effect_chain mutex.
Sourcepub fn toggle_effect(&self, effect_id: u32) -> Result<bool, String>
pub fn toggle_effect(&self, effect_id: u32) -> Result<bool, String>
Toggles the active state of an effect.
Enables or disables audio processing for a specific effect in this channel’s effect chain. The change takes effect immediately on the audio thread (lock-free).
§Arguments
effect_id— Unique identifier of the effect to toggle
§Returns
Ok(bool)— The new active state (true= now active,false= now bypassed)Err(String)— Error message if effect ID not found in this channel
Sourcepub fn set_effect_param(
&self,
effect_id: u32,
param: &str,
value: impl Into<ParamInput>,
) -> Result<(), String>
pub fn set_effect_param( &self, effect_id: u32, param: &str, value: impl Into<ParamInput>, ) -> Result<(), String>
§Sets a Named Float32 and Uint32 Parameter on an Effect
Generic parameter update mechanism for effect settings. Parameters are identified
by string names and stored as lock-free atomics (Arc<AtomicF32>).
§Lock-Free Operation
Uses Ordering::Relaxed atomic store — no synchronisation overhead:
- Write happens immediately on the calling thread
- Audio thread reads the updated value on next sample
- No locks or condition variables
§Parameter Discovery
Parameters are exposed via Effect::f32_params() and Effect::u32_params which returns a HashMap.
§Arguments
effect_id— ID of the effect to modifyparam— Parameter name string (e.g.,"threshold","level")value— New parameter value asf32
§Returns
Ok(())— Parameter updated successfullyErr(String)— Error if:- Effect with given ID not found
- Parameter name not recognised by the effect