Loop

Struct Loop 

Source
pub struct Loop<S: SignalMut, F: Mut<S>> { /* private fields */ }
Expand description

Changes a signal according to a specified function, at specified times. These times are looped.

Although it is not undefined behavior to initialize an empty loop, doing so will lead to panics in other methods.

See the module docs for more information.

Implementations§

Source§

impl<K: Eq + Hash + Clone, D: Clone, F: Map<Input = D>> Loop<Polyphony<K, <F as Map>::Output>, NoteReader<K, D, F>>
where F::Output: Frequency + Stop + Done,

Source

pub fn new_note_reader( times: Vec<Time>, note_reader: NoteReader<K, D, F>, ) -> Self

Turns a NoteReader into a [MelodyLoop].

Source

pub fn new_melody(melody: Melody<K, D>, func: F) -> Self

Initializes a new [MelodyLoop] from a Melody.

The passed function builds signals from the given note data.

Source

pub const fn note_reader(&self) -> &NoteReader<K, D, F>

Returns a reference to the underlying NoteReader.

Source

pub fn note_reader_mut(&mut self) -> &mut NoteReader<K, D, F>

Returns a mutable reference to the underlying NoteReader.

Source§

impl<S: SignalMut, F: Mut<S>> Loop<S, F>

Source

pub fn new_seq(seq: Seq<S, F>) -> Self

Turns a sequence into a loop.

§Panics

This method panics if the sequence is empty.

Source

pub fn new(times: Vec<Time>, sgn: S, func: F) -> Self

Initializes a new loop.

§Panics

This method panics if the times vector is empty.

Source

pub const fn since(&self) -> Time

Time since last event.

Source

pub const fn index(&self) -> usize

The current event index.

This index should, as a runtime invariant, always be less than the length of the loop, unless the loop is empty.

Source

pub fn len(&self) -> usize

The number of events in the loop.

Source

pub fn is_empty(&self) -> bool

Whether there are no events in the loop.

Note that such a loop might cause other methods to panic.

Source

pub fn current_time(&self) -> Time

Returns the time for the current event.

§Panics

Panics if the loop is empty.

Source

pub const fn sgn(&self) -> &S

Returns a reference to the modified signal.

Source

pub fn sgn_mut(&mut self) -> &mut S

Returns a mutable reference to the modified signal.

Source

pub const fn func(&self) -> &F

Returns a reference to the function modifying the signal.

Source

pub fn func_mut(&mut self) -> &mut F

Returns a mutable reference to the function modifying the signal.

Source

pub fn skip(&mut self)

Skips to the next event and applies it, returns whether it was successful.

This can be used right after initializing a Loop so that the first event is applied immediately.

§Panics

Panics if the loop is empty.

Source

pub fn total_time(&self) -> Time

The total time this loop takes to complete.

This method is expensive, as it must add all the times together.

Source§

impl<S: Frequency> Loop<S, Arp>

Source

pub fn new_arp(times: Vec<Time>, sgn: S, notes: Vec<Freq>) -> Self

Initializes a new Arpeggio.

Note that the note being played by the signal won’t be updated until the first time interval transpires, unless you call Self::skip.

§Panics

This method panics if the times vector is empty.

Source

pub const fn arp(&self) -> &Arp

Returns a reference to the Arp.

Source

pub fn arp_mut(&mut self) -> &mut Arp

Returns a mutable reference to the Arp.

Source

pub fn notes(&self) -> &[Freq]

Returns a reference to the notes.

Source

pub fn notes_mut(&mut self) -> &mut [Freq]

Returns a mutable reference to the notes.

Trait Implementations§

Source§

impl<S: Clone + SignalMut, F: Clone + Mut<S>> Clone for Loop<S, F>

Source§

fn clone(&self) -> Loop<S, F>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<S: Debug + SignalMut, F: Debug + Mut<S>> Debug for Loop<S, F>

Source§

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

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

impl<S: SignalMut, F: Mut<S>> Signal for Loop<S, F>

Source§

type Sample = <S as Signal>::Sample

The type of sample generated by the signal.
Source§

fn get(&self) -> Self::Sample

Gets the next sample from the signal. Read more
Source§

fn _get(&self) -> Self::Sample

Currently, rust-analyzer trips up sometimes that get is called, confusing it with Array::get. This hack bypasses this.
Source§

impl<S: SignalMut, F: Mut<S>> SignalMut for Loop<S, F>

Source§

fn advance(&mut self)

Advances the state of the signal by a frame.
Source§

fn retrigger(&mut self)

Resets the signal to its initial state.
Source§

fn next(&mut self) -> Self::Sample

Gets the next sample and advances the state of the signal.

Auto Trait Implementations§

§

impl<S, F> Freeze for Loop<S, F>
where S: Freeze, F: Freeze,

§

impl<S, F> RefUnwindSafe for Loop<S, F>

§

impl<S, F> Send for Loop<S, F>
where S: Send, F: Send,

§

impl<S, F> Sync for Loop<S, F>
where S: Sync, F: Sync,

§

impl<S, F> Unpin for Loop<S, F>
where S: Unpin, F: Unpin,

§

impl<S, F> UnwindSafe for Loop<S, F>
where S: UnwindSafe, F: UnwindSafe,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V