Read/write standard MIDI files.
What it does
- Read MIDI files
- Check MIDI file structure (using strictMode)
- Write MIDI files (still experimental)
What it doesn't do
- Playing MIDI files. It's the role of the MIDIPlayer project.
// Your variable with your MIDI file as an ArrayBuffer or UInt8Array instancevar anyBuffer;// Creating the MIDIFile instancevar midiFile = anyBuffer;// Reading headersmidiFileheader; // 0, 1 or 2midiFileheader; // n// Time divisionifmidiFileheader === MIDIFileHeaderTICKS_PER_BEATmidiFileheader;elsemidiFileheader;midiFileheader;// MIDI events retrievervar events = midiFile;events0subtype; // type of [MIDI event]()events0playTime; // time in ms at wich the event must be playedevents0param1; // first parameterevents0param2; // second one// Lyrics retrievervar lyrics = midiFile;if lyricslengthlyrics0playTime; // Time at wich the text must be displayedlyrics0text; // The text content to be displayed// Reading whole track events and filtering them yourselfvar events = midiFile;events;// Or for a single trackvar trackEventsChunk = midiFiletracks0;var events = MIDIEvents;var event;whileevent = eventsnext// Printing meta events containing text onlyifeventtype === MIDIEventsEVENT_META && eventtextconsole;
Unit tests are using mocha and NodeJS. Install them and run the following command:
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).
- ArrayBuffer, DataView or their polyfills
- 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.