pub struct MIDI { /* private fields */ }
Expand description
Structural representation of MIDI.
Can represent a file or a real-time performance.
Examples
Load a Song
use apres::MIDI;
// Create a MIDI from a file
match MIDI::from_path("/path/to/file.mid") {
Ok(midi) => {
}
Err(_) => {
}
}
Create a new MIDI
use apres::MIDI;
// Create an empty MIDI file.
let midi = MIDI::new();
Creating a song
use apres::MIDI;
use apres::MIDIEvent::{NoteOff, NoteOn};
// Create an empty MIDI file.
let mut midi = MIDI::new();
// Press midi note 64 (Middle E) on the first track (0) at the first position (0 ticks)
midi.insert_event(0, 0, NoteOn(64, 100, 100));
// Release midi note 64 (Middle E) on the first track (0) one beat later (120 ticks)
midi.push_event(0, 120, NoteOn(64, 100, 100));
// Save it to a file
midi.save("beep.mid");
Implementations
sourceimpl MIDI
impl MIDI
sourcepub fn from_path(file_path: &str) -> Result<MIDI, ApresError>
pub fn from_path(file_path: &str) -> Result<MIDI, ApresError>
Construct a new MIDI from a .mid file
sourcepub fn get_event_position(&self, event_id: u64) -> Option<&(usize, usize)>
pub fn get_event_position(&self, event_id: u64) -> Option<&(usize, usize)>
Get the track and tick of an event, given its id
sourcepub fn get_tracks(&self) -> Vec<Vec<(usize, u64)>>
pub fn get_tracks(&self) -> Vec<Vec<(usize, u64)>>
Get a list of tracks, each populated by lists of event ids. Each list in each track represents a ‘tick’, so it could be empty
pub fn count_tracks(&self) -> usize
pub fn count_events(&self) -> usize
pub fn get_track_length(&self, track: usize) -> usize
pub fn set_format(&mut self, new_format: u16)
pub fn get_format(&self) -> u16
sourcepub fn move_event(&mut self, new_track: usize, new_tick: usize, event_id: u64)
pub fn move_event(&mut self, new_track: usize, new_tick: usize, event_id: u64)
Change the track or position of an event, given it id in the MIDI
sourcepub fn insert_event(&mut self, track: usize, tick: usize, event: MIDIEvent) -> u64
pub fn insert_event(&mut self, track: usize, tick: usize, event: MIDIEvent) -> u64
Insert an event into the track
sourcepub fn push_event(&mut self, track: usize, wait: usize, event: MIDIEvent) -> u64
pub fn push_event(&mut self, track: usize, wait: usize, event: MIDIEvent) -> u64
Insert an event after the latest event in the track
pub fn get_event(&self, event_id: u64) -> Option<MIDIEvent>
pub fn replace_event(
&mut self,
event_id: u64,
new_midi_event: MIDIEvent
) -> Result<(), ApresError>
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for MIDI
impl Send for MIDI
impl Sync for MIDI
impl Unpin for MIDI
impl UnwindSafe for MIDI
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more