MIDI

Struct MIDI 

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

Source§

impl MIDI

Source

pub fn new() -> MIDI

Construct a new, empty MIDI

Source

pub fn from_path(file_path: &str) -> Result<MIDI, ApresError>

Construct a new MIDI from a .mid file

Source

pub fn save(&self, path: &str)

Save the MIDI Object to a file

Source

pub fn get_event_position(&self, event_id: u64) -> Option<&(usize, usize)>

Get the track and tick of an event, given its id

Source

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

Source

pub fn count_tracks(&self) -> usize

Source

pub fn count_events(&self) -> usize

Source

pub fn get_track_length(&self, track: usize) -> usize

Source

pub fn set_ppqn(&mut self, new_ppqn: u16)

Set Pulses Per Quarter Note

Source

pub fn get_ppqn(&self) -> u16

Get Pulses Per Quarter Note

Source

pub fn set_format(&mut self, new_format: u16)

Source

pub fn get_format(&self) -> u16

Source

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

Source

pub fn insert_event( &mut self, track: usize, tick: usize, event: MIDIEvent, ) -> u64

Insert an event into the track

Source

pub fn push_event(&mut self, track: usize, wait: usize, event: MIDIEvent) -> u64

Insert an event after the latest event in the track

Source

pub fn get_event(&self, event_id: u64) -> Option<MIDIEvent>

Source

pub fn replace_event( &mut self, event_id: u64, new_midi_event: MIDIEvent, ) -> Result<(), ApresError>

Trait Implementations§

Source§

impl Debug for MIDI

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for MIDI

§

impl RefUnwindSafe for MIDI

§

impl Send for MIDI

§

impl Sync for MIDI

§

impl Unpin for MIDI

§

impl UnwindSafe for MIDI

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.