Skip to content
/ midly Public

A feature-complete MIDI parser and writer focused on speed.

License

Notifications You must be signed in to change notification settings

kovaxis/midly

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Midly

Midly is a MIDI parser and writer designed for efficiency and completeness, making as few allocations as possible and using multiple threads to parse and write MIDI tracks in parallel.

The behaviour of the parser is also configurable through crate features. See the crate-level documentation for the available features and no_std support.

Getting started

First add the following line to your Cargo.toml file, under the [dependencies] section:

midly = "0.5"

Then use the Smf type in the crate root:

// Load bytes first
let data = std::fs::read("Pi.mid").unwrap();

// Parse the raw bytes
let mut smf = midly::Smf::parse(&data).unwrap();

// Use the information
println!("midi file has {} tracks!", smf.tracks.len());

// Modify the file
smf.header.format = midly::Format::Sequential;

// Save it back
smf.save("PiRewritten.mid").unwrap();

Or use the LiveEvent type to parse individual MIDI events:

use midly::{live::LiveEvent, MidiMessage};

fn on_midi(event: &[u8]) {
    let event = LiveEvent::parse(event).unwrap();
    match event {
        LiveEvent::Midi { channel, message } => match message {
            MidiMessage::NoteOn { key, vel } => {
                println!("hit note {} on channel {}", key, channel);
            }
            _ => {}
        },
        _ => {}
    }
}

Most types to be imported are on the crate root and are documented in-place. Check the crate documentation for more information.

About

A feature-complete MIDI parser and writer focused on speed.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages