Tonejs / Midi

Convert MIDI into Tone.js-friendly JSON
http://tonejs.github.io/Midi/
MIT License
888 stars 119 forks source link

Notes with Velocity of 0 is not always equivalent to Note off #174

Open yenyesorr opened 1 year ago

yenyesorr commented 1 year ago

Hi,

I am experimenting with ToneJS which internally uses MIDI-FILE to parse and write midi files.

I noticed certain notes were absent in the buffer but present in the midi file. The notes that are absent are the notes with a velocity of 0.

Currently it appears MIDI-FILE might be have a basic default interpretation of velocity of 0 (which is note_off). Instead of a note_off message, one popular convention is to use note_on with a velocity of 0. In this case the midi note number of the two successive notes remain the same.

However there are instances where there could be successive notes with velocity of 0 but with different midi note number.

It appears one of the uses of this information is for initiating and terminating portamento.

Required Change in Midi Parser:

Maybe when the midi note number changes, if MIDI-FILE does not flag these notes with velocity of 0 as note_off, it could probably appear without getting purged by ToneJS (Note: ToneJS does not have entries in the buffer for note_off messages)

Caveat : I am a sort of beginner to both ToneJS and MIDI and do not claim expertise in either. However I checked with certain folks that have better MIDI knowledge who have confirmed that midi note messages with velocity of 0 play an important role and should not be ignored or taken as default note_off interpretation always. It is upto the processing software/ instrument to process it correctly.

yenyesorr commented 1 year ago

One small correction to the above information.....

The midi note velocity 0 does not immediately have to follow same midi note with non 0 velocity......but can appear at the relevant delta time.

However, if a DIFFERENT midi note with velocity 0 appears without a preceding non 0 velocity, that note should not be treated as note_off as there was no corresponding note_on, but rather left to the processing software/ instrument to decide.

carter-thaxton commented 1 year ago

While parsing, midi-file does currently interpret velocity 0 noteOn events as noteOff, but it marks then with a byte9 boolean flag, which ToneJS could use to disambiguate these cases.

When writing, midi-file will also honor the byte9 flag to write a noteOff event using byte 0x9 with velocity 0, to support this common non-standard convention.