midievents
midievents copied to clipboard
Converting Note-On at zero velocity to Note-Off
Feature request
https://github.com/nfroidure/midievents/blob/d3c1060b295c83dc4945d8c3439f2d06194b243e/src/midievents.js#L328-L332
The standard says that a value of 64 is recommended.
- For a keyboard which does not implement Velocity, the note will be turned on using 9n, kkkkkkk, 64 (40H) and may be turned off using 9n, 0kkkkkkk, 00000000 or 8n, 0kkkkkkk, 0xxxxxxx (a value of 64 [40H] is used for x).
- For a keyboard which incorporates Key On Velocity, but not Release Velocity the note is turned on using 9n 0kkkkkkk, 0vvvvvvv and may be turned off using 9n, 0kkkkkkk, 00000000 or 8n, 0kkkkkkk, 0xxxxxxx (a value of 64 (40H) is recommended for x).
In my opinion, however, converting events is not what a MIDI event decoder should do.
Feature description
-
A Note-On at zero velocity should either be converted to a Note-Off at a velocity of 64...
case MIDIEvents.EVENT_MIDI_NOTE_ON: event.param2 = stream.readUint8(); // If velocity is 0, it's a note off event in fact if (!event.param2) { event.subtype = MIDIEvents.EVENT_MIDI_NOTE_OFF; - event.param2 = 127; // Find a standard telling what to do here + event.param2 = 64; } return event;
-
...or be left unchanged.
case MIDIEvents.EVENT_MIDI_NOTE_ON: event.param2 = stream.readUint8(); - - // If velocity is 0, it's a note off event in fact - if (!event.param2) { - event.subtype = MIDIEvents.EVENT_MIDI_NOTE_OFF; - event.param2 = 127; // Find a standard telling what to do here - } return event;
Use cases
- Match the standard more closely.
- Probably no one wants to write out a Note-On and read back a Note-Off at maximum velocity.
@sjx233 to be honest, I wrote that lib to check out if I could create a .kar
player and I'm still surprised of how it became widely used.
Your issue sounds right, I'd definitely merge any PR fixing this, just can't tell when I'll have some time to spend on it.
I'm not very confident on its impact on the projects using it. Probably needs a major version.