Skip to main content

AudioHandle

Struct AudioHandle 

Source
pub struct AudioHandle { /* private fields */ }
Expand description

A running audio stream driving a Plugin.

Dropping the handle stops playback (the underlying device stream is released). While it lives, the plugin keeps running on the audio thread; use Self::lock to send MIDI or change parameters from your control thread.

Implementations§

Source§

impl AudioHandle

Source

pub fn lock(&self) -> MutexGuard<'_, Plugin>

Lock the running plugin to send MIDI, change parameters, etc.

Recovers automatically if the audio thread previously panicked while holding the lock (poisoned mutex), so control calls keep working.

Source

pub fn try_lock(&self) -> Option<MutexGuard<'_, Plugin>>

Try to lock the plugin without blocking, returning None if the audio callback currently holds the lock (it is held for the duration of each process_audio call).

Use this on a UI/render thread for best-effort, per-frame reads (VU meters, output-MIDI drain, parameter sync): skipping a frame when the audio thread is mid-block is invisible, and it keeps the UI thread from stalling on the (unfair) mutex — which otherwise shows up as input lag.

Source

pub fn send_midi(&self, event: MidiEvent) -> bool

Queue a MIDI event for the plugin without locking the audio thread.

The event is pushed onto a lock-free ring and applied at the start of the next audio block. Prefer this over lock().send_midi_event(..) on a UI thread — it never blocks on the audio mutex. Returns false if the ring is full (the event is dropped).

Source

pub fn set_parameter(&self, id: u32, value: f64) -> bool

Queue a normalized parameter change (0.0..=1.0) without locking the audio thread. Applied at the start of the next block. Returns false if the ring is full.

Source

pub fn midi_panic(&self) -> bool

Queue an all-notes-off “panic” (CC 123/120/121 on every channel) without locking the audio thread. Returns false if the ring is full.

Source

pub fn output_levels(&self) -> AudioLevels

Read the latest per-channel output peak levels without locking the audio thread.

Each channel reports the maximum peak observed since the previous call (the read resets the accumulator), so polling at UI frame rate never misses a transient between frames. rms is not tracked on this path and is reported as 0; peak_hold mirrors peak (drive your own ballistics, e.g. crate::audio::PeakMeter, from the peak).

Source

pub fn drain_output_midi(&self) -> Vec<MidiEvent>

Drain MIDI the plugin emitted during processing (arpeggiators, MPE, …) without locking the audio thread. Returns the events queued since the last call.

Source

pub fn drain_parameter_changes(&self) -> Vec<(u32, f64)>

Drain parameter changes the plugin made through its own editor without locking the audio thread. Returns (id, normalized_value) pairs queued since the last call.

Source

pub fn plugin(&self) -> Arc<Mutex<Plugin>>

A shared handle to the plugin, e.g. to move into another thread.

Source

pub fn stop(self)

Stop playback now (equivalent to dropping the handle).

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
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<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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.

Source§

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

Source§

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.