parsing midi files is not as scary as it sounds. 🐔
A lightweight, minimal dependency MIDI file parser and binary writer designed for resource-constrained environments, making it great for WebAssembly applications.
Features
- Efficient MIDI Parsing: Parse MIDI chunks and their associated data with minimal overhead.
- Error Handling: Comprehensive error reporting for invalid or unsupported chunks.
- MIDI Format Writing: Serialize Parsed or Generating MIDI chunks back into MIDI format binary.
Getting Started
Installation
Add the following to your Cargo.toml:
[]
= "{whatever version you want}"
For serde support include the serde feature flag ;)
Example Usage
The following example demonstrates how to read and process MIDI chunks from a file:
let mut data = "path/to/midi/file.mid"
.get_midi_bytes
.expect;
let midi = try_from_midi_stream.expect;
for chunk in midi.chunks.iter
A RawMidi can also be sanitized and upgraded into a Midi struct that contains a single header and a subsequent list of tracks:
let sanitized: Midi = midi.check_into_midi.expect;
Writing a RawMidi or Midi to a file:
let mut output = create.unwrap;
// Works for `Midi` and `RawMidi` types!
output.write_all.unwrap
Core Concepts
Raw MIDI Chunk
A raw MIDI chunk consists of a 4-character ASCII type identifier and a 32-bit unsigned integer specifying the length of its data:
Parsed MIDI Chunk
Parsed chunks are categorized into meaningful types such as HeaderChunk and TrackChunk:
Header Chunk
The HeaderChunk struct stores essential MIDI metadata:
Contributions
Contributions are welcome! If you find a bug or have a feature request, feel free to open an issue or submit a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.