Skip to content

Commit

Permalink
Add from slice for loading midi
Browse files Browse the repository at this point in the history
  • Loading branch information
PikminGuts92 committed Feb 22, 2025
1 parent 1222d1b commit b1af385
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions core/grim_midi/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ impl MidiFile {
}

pub fn from_stream<T: std::io::Read>(mut stream: T) -> Option<MidiFile> {
// TODO: Use result w/ custom error
let mut mid_bytes = Vec::new();
stream.read_to_end(&mut mid_bytes).ok()?;

Self::from_stream(mid_bytes.as_slice())
}

pub fn from_slice(data: &[u8]) -> Option<MidiFile> {
// TODO: Use result w/ custom error
let mut mid = MidiFile::default();

// Load midi file using lib
let smf = Smf::parse(&mid_bytes).ok()?;
let smf = Smf::parse(&data).ok()?;

// TODO: Don't bother re-mapping and just re-export enum
mid.format = match &smf.header.format {
Expand Down

0 comments on commit b1af385

Please sign in to comment.