Skip to main content

Channel

Struct Channel 

Source
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

Source

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 to 1.0 if None.
  • master_volume - Optional initial master volume value. Defaults to 1.0 if None.
Source

pub fn set_gain(&self, gain: f32)

Sets the gain value for this channel.

The gain value is atomically updated and will be read by the audio processing thread on the next sample cycle.

§Arguments
  • gain - The new gain value. Must be positive (> 0.0).
§Panics

Panics if gain is negative or zero.

Source

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.

Source

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.

Source

pub fn set_bass(&self, bass: f32)

Sets the bass level for the tone stack.

The input value is expected to be normalized in the range 0.0-1.0.

§Arguments
  • bass - The bass level (0.0-1.0).
§Panics

Panics if the scaled value is not between 0.0 and 1.0.

Source

pub fn set_middle(&self, middle: f32)

Sets the middle level for the tone stack.

The input value is expected to be normalized in the range 0.0-1.0.

§Arguments
  • middle - The middle level (0.0-1.0).
§Panics

Panics if the value is not between 0.0 and 1.0.

Source

pub fn set_treble(&self, treble: f32)

Sets the treble level for the tone stack.

The input value is expected to be normalized in the range 0.0-1.0.

§Arguments
  • treble - The treble level (0.0-1.0).
§Panics

Panics if the value is not between 0.0 and 1.0.

Source

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.

Source

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.

Source

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.

Source

pub fn set_name(&mut self, name: String)

Sets the name of the Channel

§Arguments
  • name - The name
Source

pub fn name(&self) -> &String

Returns the name of the channel.

Source

pub fn id(&self) -> u32

Returns the unique identifier of the channel.

Source

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.

Source

pub fn restore_effect_chain(&mut self, effects: Vec<Box<dyn Effect>>)

Sets the effect chain to a new given chain of effects

Source

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.

Source

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
Source

pub fn next_effect_id(&self) -> u32

Returns the next available unique identifier for an effect in this channel’s effect chain.

Source

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.

Source

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
Source

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 modify
  • param — Parameter name string (e.g., "threshold", "level")
  • value — New parameter value as f32
§Returns
  • Ok(()) — Parameter updated successfully
  • Err(String) — Error if:
    • Effect with given ID not found
    • Parameter name not recognised by the effect

Trait Implementations§

Source§

impl From<&Channel> for ChannelDto

Source§

fn from(channel: &Channel) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Any for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

§

fn type_name(&self) -> &'static str

§

impl<T> AnySync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,