RawMidi

Struct RawMidi 

Source
pub struct RawMidi {
    pub chunks: Vec<ParsedChunk>,
}
Expand description

An entire MIDI file as a raw sequence of parsed chunks

Fields§

§chunks: Vec<ParsedChunk>

All raw chunks as ParsedChunks

Implementations§

Source§

impl RawMidi

Source

pub fn try_from_midi_stream<STREAM>( stream: STREAM, ) -> Result<Self, ChunkParseError>
where STREAM: MidiStream,

Constructs a new MIDI instance from a stream of MIDI bytes

Examples found in repository?
examples/chunk_read.rs (line 10)
5fn main() {
6    let data = "test/test.mid"
7        .get_midi_bytes()
8        .expect("Get `run.midi` file and stream bytes");
9
10    let midi = RawMidi::try_from_midi_stream(data).expect("Parse data as a MIDI stream");
11    let sanitized_midi: Midi = midi
12        .check_into_midi()
13        .expect("Upgrade into sanitized format");
14
15    println!("Header: {:?}", sanitized_midi.header);
16    for chunk in sanitized_midi.tracks.iter() {
17        println!("Track: {chunk:?}");
18    }
19}
More examples
Hide additional examples
examples/copy.rs (line 15)
9fn main() {
10    let mut output = File::create("test/test_run.mid").expect("Create new output file");
11    let data = "test/run.mid"
12        .get_midi_bytes()
13        .expect("Get `run.midi` file and stream bytes");
14
15    let midi: Midi = RawMidi::try_from_midi_stream(data)
16        .expect("Parse data as a MIDI stream")
17        .check_into_midi()
18        .expect("Sanitize MIDI into formatted MIDI");
19
20    output
21        .write_all(&midi.to_midi_bytes())
22        .expect("Failed to write bytes");
23}
Source

pub fn check_into_midi(self) -> Result<Midi, MidiSanitizerError>

Attempts to upgrade a RawMidi stream into a sanitized Midi struct. This means there must be a single starting header and only track chunks afterwards

Examples found in repository?
examples/chunk_read.rs (line 12)
5fn main() {
6    let data = "test/test.mid"
7        .get_midi_bytes()
8        .expect("Get `run.midi` file and stream bytes");
9
10    let midi = RawMidi::try_from_midi_stream(data).expect("Parse data as a MIDI stream");
11    let sanitized_midi: Midi = midi
12        .check_into_midi()
13        .expect("Upgrade into sanitized format");
14
15    println!("Header: {:?}", sanitized_midi.header);
16    for chunk in sanitized_midi.tracks.iter() {
17        println!("Track: {chunk:?}");
18    }
19}
More examples
Hide additional examples
examples/copy.rs (line 17)
9fn main() {
10    let mut output = File::create("test/test_run.mid").expect("Create new output file");
11    let data = "test/run.mid"
12        .get_midi_bytes()
13        .expect("Get `run.midi` file and stream bytes");
14
15    let midi: Midi = RawMidi::try_from_midi_stream(data)
16        .expect("Parse data as a MIDI stream")
17        .check_into_midi()
18        .expect("Sanitize MIDI into formatted MIDI");
19
20    output
21        .write_all(&midi.to_midi_bytes())
22        .expect("Failed to write bytes");
23}

Trait Implementations§

Source§

impl Clone for RawMidi

Source§

fn clone(&self) -> RawMidi

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RawMidi

Source§

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

Formats the value using the given formatter. Read more
Source§

impl MidiWriteable for RawMidi

Source§

fn to_midi_bytes(self) -> Vec<u8>

Converts the data to a MIDI format byte sequence
Source§

impl PartialEq for RawMidi

Source§

fn eq(&self, other: &RawMidi) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<RawMidi> for Midi

Source§

type Error = MidiSanitizerError

The type returned in the event of a conversion error.
Source§

fn try_from(value: RawMidi) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<STREAM> TryFrom<StreamWrapper<STREAM>> for RawMidi
where STREAM: MidiStream,

Source§

type Error = ChunkParseError

The type returned in the event of a conversion error.
Source§

fn try_from(value: StreamWrapper<STREAM>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl StructuralPartialEq for RawMidi

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.