Skip to main content

SoundList

Struct SoundList 

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

Play Sounds sequentially one after the other.

Only after a Sound has returned NextSample::Finished will the next Sound start playing.

If an Error is returned from a Sound it is dropped and the error is propagated to the caller. Calling next_sound again would continue with the next Sound in the list.

Implementations§

Source§

impl SoundList

Source

pub fn new() -> Self

Create a new empty SoundList.

Source

pub fn add(&mut self, sound: Box<dyn Sound>)

Add a Sound to be played after any existing sounds have Finished.

Source

pub fn insert(&mut self, index: usize, sound: Box<dyn Sound>)

Inserts a sound at position index, shifting all elements after it to the right.

Panics

Panics if index > len.

Source

pub fn clear(&mut self)

Stop all sounds including the currently playing one.

Source

pub fn len(&self) -> usize

Returns the number of sounds currently in the list.

Trait Implementations§

Source§

impl AddSound for SoundList

Source§

fn add(&mut self, sound: Box<dyn Sound>)

Add a sound to be played. When or how the sound is played is implementation specific.
Source§

impl ClearSounds for SoundList

Source§

fn clear(&mut self)

Clear all sounds currently playing or scheduled to play.
Source§

impl Debug for SoundList

Source§

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

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

impl Default for SoundList

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<SoundList> for Vec<Box<dyn Sound>>

Source§

fn from(list: SoundList) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Box<dyn Sound>>> for SoundList

Source§

fn from(sounds: Vec<Box<dyn Sound>>) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<Box<dyn Sound>> for SoundList

Source§

fn from_iter<T: IntoIterator<Item = Box<dyn Sound>>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl Sound for SoundList

Source§

fn channel_count(&self) -> u16

Returns the number of channels.
Source§

fn sample_rate(&self) -> u32

Returns the number of samples per second for each channel for this sound (e.g. 48,000).
Source§

fn on_start_of_batch(&mut self)

Called whenever a new batch of audio samples is requested by the backend. Read more
Source§

fn next_sample(&mut self) -> Result<NextSample, Error>

Retrieve the next sample or notification if something has changed. The first sample is for the first channel and the second is the for second and so on until channel_count and then wraps back to the first channel. If any NextSample variant besides Sample is returned then the following NextSample::Sample is for the first channel. If a Sound has returned Paused it is expected that the consumer will call next_sample again in the future. If a Sound has returned Finished it is not expected for the consumer to call next_sample again but if called Finished will normally be returned again. After Finished has been returned, channel_count() and sample_rate() may return different values without MetadataChanged being returned. Read more
Source§

fn next_frame(&mut self) -> Result<Vec<i16>, Result<NextSample, Error>>

Returns the next sample for all channels. Read more
Source§

fn append_next_frame_to( &mut self, samples: &mut Vec<i16>, ) -> Result<(), Result<NextSample, Error>>

Same as next_frame but samples are appended into an existing Vec. Read more
Source§

fn into_memory_sound(self) -> Result<MemorySound, Error>
where Self: Sized,

Read the entire sound into memory. MemorySound can be cloned for efficient reuse. See MemorySound::from_sound.
Source§

fn loop_from_memory(self) -> Result<MemorySound, Error>
where Self: Sized,

Read the entire sound into memory and loop indefinitely. Read more
Source§

fn controllable(self) -> (Controllable<Self>, Controller<Self>)
where Self: Sized,

Allow this sound to be controlled after it has started playing with a Controller. Read more
Source§

fn with_async_completion_notifier( self, ) -> (AsyncCompletionNotifier<Self>, Receiver<()>)
where Self: Sized,

Get notified via a tokio::sync::oneshot::Receiver when this sound has Finished.
Source§

fn with_completion_notifier(self) -> (CompletionNotifier<Self>, Receiver<()>)
where Self: Sized,

Get notified via a std::sync::mpsc::Receiver when this sound has Finished.
Source§

fn with_adjustable_volume(self) -> AdjustableVolume<Self>
where Self: Sized,

Allow the volume of the sound to be adjustable with set_volume.
Source§

fn with_adjustable_volume_of( self, volume_adjustment: f32, ) -> AdjustableVolume<Self>
where Self: Sized,

Allow the volume of the sound to be adjustable with set_volume and set the initial volume adjustment.
Source§

fn with_adjustable_speed(self) -> AdjustableSpeed<Self>
where Self: Sized,

Allow the speed of the sound to be adjustable with set_speed. Read more
Source§

fn with_adjustable_speed_of( self, speed_adjustment: f32, ) -> AdjustableSpeed<Self>
where Self: Sized,

Allow the speed of the sound to be adjustable with set_speed and set the initial speed adjustment. Read more
Source§

fn pausable(self) -> Pausable<Self>
where Self: Sized,

Allow for the sound to be pausable with set_paused. Starts unpaused.
Source§

fn paused(self) -> Pausable<Self>
where Self: Sized,

Allow for the sound to be pausable with set_paused. Starts paused.
Source§

fn stoppable(self) -> Stoppable<Self>
where Self: Sized,

Allow for the sound to be stoppable with set_stopped. A stopped sound returns Finished.
Source§

fn finish_after(self, duration: Duration) -> FinishAfter<Self>
where Self: Sized,

Play the first duration of the sound, then finish even if samples remain. Read more
Source§

fn skip(&mut self, duration: Duration) -> Result<bool, Error>

Skip the next duration of samples. Read more

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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

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.