grimmdude / MidiPlayerJS

♬ MIDI parser & player engine for browser or Node. As a parser converts MIDI events into JSON. Works well with single or multitrack MIDI files.
https://grimmdude.com/MidiPlayerJS/
MIT License
357 stars 52 forks source link

No Way To Tell What Instrument Is Playing in Note On Event #51

Closed sylv256 closed 4 years ago

sylv256 commented 5 years ago

There's no way to know exactly what instrument is playing when the Note on event fires. Because of this, if there are drums or some form of instrument in the song, you cannot specify which instrument to play.

grimmdude commented 4 years ago

Hi @TehcJS ,

If the MIDI file specifies a Program Change meta event on a track it will be emitted during playback. The value 0 to 127 represents the instrument.

{
    track: 1,
    delta: 0,
    tick: 0,
    byteIndex: 7,
    name: 'Program Change',
    channel: 1,
    value: 1
}

MIDI instrument codes: http://www.ccarh.org/courses/253/handout/gminstruments/

sylv256 commented 4 years ago

Thank you! I didn't see this in the documentation. I'll probably make a pull request adding that to the docs if it's not already there.