Struct apres::MIDI[][src]

pub struct MIDI { /* fields omitted */ }
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

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]

Set Pulses Per Quarter Note

pub fn get_ppqn(&self) -> u16[src]

Get Pulses Per Quarter Note

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]

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]

Trait Implementations

impl Debug for MIDI[src]

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

Formats the value using the given formatter. Read more

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]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

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]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.