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
impl MidiEvents
Sourcepub fn new(chunks: &[Chunk]) -> Self
pub fn new(chunks: &[Chunk]) -> Self
Creates a new MidiEvents collection from the given chunks.
§Arguments
chunks- The repeat structure chunks for the music.
Sourcepub fn add_midi_event(&mut self, tick: AccumTick, m: MidiSrc)
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.
Sourcepub fn add_tempo(&mut self, tick: AccumTick, tempo: TempoValue)
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.
Sourcepub fn cycles_by_accum_tick(
&self,
sampling_rate: u32,
ticks_per_quarter: u32,
) -> Store<AccumTick, (TempoValue, u64), ()>
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.
Sourcepub fn accum_tick_to_cycle(
cycles_by_tick: &Store<AccumTick, (TempoValue, u64), ()>,
tick: AccumTick,
sampling_rate: u32,
ticks_per_quarter: u32,
) -> u64
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.
Sourcepub fn tick_to_cycle(
tick: u32,
sampling_rate: u32,
tempo: u16,
ticks_per_quarter: u32,
) -> u64
pub fn tick_to_cycle( tick: u32, sampling_rate: u32, tempo: u16, ticks_per_quarter: u32, ) -> u64
Sourcepub fn to_play_data(
self,
cycles_by_tick: Store<AccumTick, (TempoValue, u64), ()>,
sampling_rate: u32,
ticks_per_quarter: u32,
) -> PlayData
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
impl Clone for MidiEvents
Source§fn clone(&self) -> MidiEvents
fn clone(&self) -> MidiEvents
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more