MidiEvents

Struct MidiEvents 

Source
pub struct MidiEvents {
    pub events: BTreeMap<AccumTick, Vec<MidiSrc>>,
    pub tempo_table: Store<AccumTick, TempoValue, ()>,
    pub chunks: Store<AccumTick, Chunk, ()>,
}
Expand description

Collection of MIDI events organized by accumulated tick position.

This structure represents the complete MIDI event timeline for a piece of music, including all repeats expanded into a linear sequence.

Fields§

§events: BTreeMap<AccumTick, Vec<MidiSrc>>

Map of accumulated tick positions to MIDI events occurring at that time.

§tempo_table: Store<AccumTick, TempoValue, ()>

Tempo changes indexed by accumulated tick position.

§chunks: Store<AccumTick, Chunk, ()>

Chunks representing the structure of repeats in the music.

Implementations§

Source§

impl MidiEvents

Source

pub fn new(chunks: &[Chunk]) -> Self

Creates a new MidiEvents collection from the given chunks.

§Arguments
  • chunks - The repeat structure chunks for the music.
Source

pub fn add_midi_event(&mut self, tick: AccumTick, m: MidiSrc)

Adds a MIDI event at the specified accumulated tick position.

If multiple events occur at the same tick, they are stored in a vector.

§Arguments
  • tick - The accumulated tick position.
  • m - The MIDI event to add.
Source

pub fn add_tempo(&mut self, tick: AccumTick, tempo: TempoValue)

Adds a tempo change at the specified accumulated tick position.

§Arguments
  • tick - The accumulated tick position.
  • tempo - The new tempo value.
Source

pub fn cycles_by_accum_tick( &self, sampling_rate: u32, ticks_per_quarter: u32, ) -> Store<AccumTick, (TempoValue, u64), ()>

Creates a mapping from accumulated ticks to audio cycles.

This is used to convert musical time (ticks) to audio time (cycles).

§Arguments
  • sampling_rate - The audio sampling rate (e.g., 48000 Hz).
  • ticks_per_quarter - The number of ticks per quarter note.
§Returns

A store mapping accumulated ticks to (tempo, cycle) pairs.

Source

pub fn accum_tick_to_cycle( cycles_by_tick: &Store<AccumTick, (TempoValue, u64), ()>, tick: AccumTick, sampling_rate: u32, ticks_per_quarter: u32, ) -> u64

Converts an accumulated tick position to an audio cycle number.

§Arguments
  • finder - A finder for looking up tempo changes.
  • tick - The accumulated tick position.
  • sampling_rate - The audio sampling rate.
  • ticks_per_quarter - The number of ticks per quarter note.
§Returns

The audio cycle number corresponding to the given tick.

Source

pub fn tick_to_cycle( tick: u32, sampling_rate: u32, tempo: u16, ticks_per_quarter: u32, ) -> u64

Converts a tick duration to audio cycles at a given tempo.

§Arguments
  • tick - The tick duration.
  • sampling_rate - The audio sampling rate.
  • tempo - The tempo in BPM.
  • ticks_per_quarter - The number of ticks per quarter note.
§Returns

The number of audio cycles.

Source

pub fn to_play_data( self, cycles_by_tick: Store<AccumTick, (TempoValue, u64), ()>, sampling_rate: u32, ticks_per_quarter: u32, ) -> PlayData

Converts this MidiEvents to PlayData for real-time playback.

This method transforms the tick-based event timeline into a cycle-based timeline suitable for audio playback.

§Arguments
  • cycles_by_tick - Mapping from ticks to cycles.
  • sampling_rate - The audio sampling rate.
  • ticks_per_quarter - The number of ticks per quarter note.
§Returns

A PlayData structure ready for real-time playback.

Trait Implementations§

Source§

impl Clone for MidiEvents

Source§

fn clone(&self) -> MidiEvents

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

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> Instrument for T

Source§

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

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

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.

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<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> OpaqueAttachment for T
where T: Send + Sync + 'static,