Struct apres::MIDI [−][src]
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
impl MIDI
[src]
pub fn new() -> MIDI
[src]
Construct a new, empty MIDI
pub fn from_path(file_path: &str) -> Result<MIDI, ApresError>
[src]
Construct a new MIDI from a .mid file
pub fn save(&self, path: &str)
[src]
Save the MIDI Object to a file
pub fn get_event_position(&self, event_id: u64) -> Option<&(usize, usize)>
[src]
Get the track and tick of an event, given its id
pub fn get_tracks(&self) -> Vec<Vec<(usize, u64)>>
[src]
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
[src]
pub fn count_events(&self) -> usize
[src]
pub fn get_track_length(&self, track: usize) -> usize
[src]
pub fn set_ppqn(&mut self, new_ppqn: u16)
[src]
pub fn get_ppqn(&self) -> u16
[src]
pub fn set_format(&mut self, new_format: u16)
[src]
pub fn get_format(&self) -> u16
[src]
pub fn move_event(&mut self, new_track: usize, new_tick: usize, event_id: u64)
[src]
Change the track or position of an event, given it id in the MIDI
pub fn insert_event(
&mut self,
track: usize,
tick: usize,
event: MIDIEvent
) -> u64
[src]
&mut self,
track: usize,
tick: usize,
event: MIDIEvent
) -> u64
Insert an event into the track
pub fn push_event(&mut self, track: usize, wait: usize, event: MIDIEvent) -> u64
[src]
Insert an event after the latest event in the track
pub fn get_event(&self, event_id: u64) -> Option<MIDIEvent>
[src]
pub fn replace_event(
&mut self,
event_id: u64,
new_midi_event: MIDIEvent
) -> Result<(), ApresError>
[src]
&mut self,
event_id: u64,
new_midi_event: MIDIEvent
) -> Result<(), ApresError>
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
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,