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

Add rawEventCode key to eventJson #68

Closed MoyuScript closed 4 years ago

MoyuScript commented 4 years ago

When i use player.play() and handle midi event. I need to handle 'Note on' and 'Note off' event only, and send them to Jazz-midi to play.

if (event.name === 'Note on') {
  doSomething();
}

But it can't be played fluently if i use a complex MIDI file. So i add 'rawEventCode' to 'eventJson', it's now can be played fluently.

if (0x80 <= ev.rawEventCode && ev.rawEventCode <= 0x9f) {
  // Note on and Note off
  port.send(ev.rawEventCode, ev.noteNumber, ev.velocity);
} else if (0xc0 <= ev.rawEventCode && ev.rawEventCode <= 0xcf) {
   // Program Change
  port.send(ev.rawEventCode, ev.value);
 }