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

Construct a new, empty MIDI

Construct a new MIDI from a .mid file

Save the MIDI Object to a file

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

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

Set Pulses Per Quarter Note

Get Pulses Per Quarter Note

Change the track or position of an event, given it id in the MIDI

Insert an event into the track

Insert an event after the latest event in the track

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.