midifile
Read/write standard MIDI files.
MIDIFile uses the MIDIEvents project
and is part of the MIDIPlayer one.
You can also check this Karaoke Player built
on top of those libraries.
What it does
- Read MIDI files
- Check MIDI file structure (using strictMode)
- Write MIDI files (still experimental)
What it doesn't do
Usage
var anyBuffer;
var midiFile = new MIDIFile(anyBuffer);
midiFile.header.getFormat();
midiFile.header.getTracksCount();
if(midiFile.header.getTimeDivision() === MIDIFile.Header.TICKS_PER_BEAT) {
midiFile.header.getTicksPerBeat();
} else {
midiFile.header.getSMPTEFrames();
midiFile.header.getTicksPerFrame();
}
var events = midiFile.getMidiEvents();
events[0].subtype;
events[0].playTime;
events[0].param1;
events[0].param2;
var lyrics = midiFile.getLyrics();
if ( lyrics.length ) {
lyrics[0].playTime;
lyrics[0].text;
}
var events = midiFile.getTrackEvents(0);
events.forEach(console.log.bind(console));
var trackEventsChunk = midiFile.tracks[0].getTrackContent();
var events = MIDIEvents.createParser(trackEventsChunk);
var event;
while(event = events.next()) {
if(event.type === MIDIEvents.EVENT_META && event.text) {
console.log('Text meta: '+event.text);
}
}
Testing
Unit tests are using mocha and NodeJS. Install them and run the following command:
mocha tests/*.mocha.js
Why ArrayBuffers ?
ArrayBuffer instances are the best way to manage binary data like MIDI files.
Why not streams ?
The Standard MIDI files format isn't streamable by nature. If you want to stream
MIDI file contents, you should consider transforming your files in another
format (plain linearized MIDI events should do the job).
Requirements
- ArrayBuffer, DataView or their polyfills
Contributing
- Feel free to PR
- If you find a MIDI File the library can't read an if it's under a free, PR
the file in the sounds folder and add tests for him. I'll work on it asap.
License
MIT