Skip to main content

VoicePool

Struct VoicePool 

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

A polyphony-limited pool of voices that emits scheduled tones as voices finish or are stolen.

Implementations§

Source§

impl VoicePool

Source

pub fn new(polyphony_limit: usize) -> Result<Self, SoundBridgeError>

Builds a pool with the given polyphony limit, rejecting a limit of zero.

Source

pub fn polyphony_limit(&self) -> usize

Returns the maximum number of simultaneous voices.

Source

pub fn active_voice_count(&self) -> usize

Returns the number of currently active voices.

Source

pub fn voices(&self) -> &[Voice]

Returns the currently active voices.

Source

pub fn emitted(&self) -> &[ScheduledTone]

Returns the scheduled tones emitted but not yet drained.

Source

pub fn stolen_voice_count(&self) -> usize

Returns the running count of stolen voices.

Source

pub fn drain_emitted(&mut self) -> Vec<ScheduledTone>

Drains and returns the emitted scheduled tones, clearing the buffer.

Source

pub fn note_on(&mut self, voice: Voice, now: Duration)

Starts a new voice at now, retiring any same-key voice and stealing a voice if the polyphony limit is reached.

Source

pub fn note_off(&mut self, channel: u8, key: u8, now: Duration, sustain: bool)

Releases the most recent voice matching channel/key, holding it under the sustain pedal when sustain is set.

Source

pub fn release_channel_sustain(&mut self, channel: u8, now: Duration)

Releases all sustain-held voices on channel at now.

Source

pub fn transpose_channel_cents(&mut self, channel: u8, cents: f64)

Shifts the frequency of all non-released voices on channel by cents.

Source

pub fn reap_finished(&mut self, now: Duration)

Emits and removes voices whose release stage has completed by now.

Source

pub fn flush_all(&mut self, now: Duration)

Releases every remaining voice and emits all of them.

Trait Implementations§

Source§

impl Clone for VoicePool

Source§

fn clone(&self) -> VoicePool

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VoicePool

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for VoicePool

Source§

fn eq(&self, other: &VoicePool) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for VoicePool

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.