Question is about how to handle multiple Note On commands with same key (note) on same channel (but maybe with different velocities).
The specifications are clear about this in some respect.
For instance, for each Note On command, there must be a respective Note Off at some point.
So if there was more than one Note On for C4 note, there must be just as many Note Off for C4 note.
The specs also say it is up to device such as synthesizer how it interprets multiple Note On commands with same key/note.
It might start same C4 note on multiple channels according to velocities, or ignore them as the key was considered pressed after first Note On so it was already playing the C4 note.
Ignoring is easy, so first Note On C4 will start note, rest Note On C4 commands are ignored, and first Note Off C4 will turn the note off, other Note Off C4 commands are ignored as there was no note playing any more. Or should the further Note On C4 update the velocity for example?
But what if synthesizer does support multiple Note On commands, say I am making a device that has polyphony of 8 square wave oscillators?
Should the first Note Off be respective to first Note On command like a FIFO or ring buffer, or should the first Note Off actually turn off the last received Note On in a LIFO / stack fasion?
Now that I think of it, this really should not happen in real life with real MIDI keyboard. Human pressing the keys must release a key before pressing it again.
So no more than one Note On is transmitted, unless someone pulls the MIDI plug during Note Off transmission.
In some occasions where two keyboards are merged or half of the keyboard is being transposed to overlap with the other half this might happen.
The specification also says:
[…] The transmitter, however, must send a corresponding Note Off message for every Note On sent. If the transmitter were to send only one Note Off message, and if the receiver in fact assigned the two Note On messages to different voices, then one note would linger.
This implies that there must be a 1:1 relationship between Note-Off messages and voices. It says nothing about FIFO or LIFO, but for practical purposes, only FIFO appears to make sense.
There is a case where two Note-On messages might accidentally happen: two notes are played not at the same time, but directly after the other, i.e., the second Note-On is sent directly after the first Note-Off. Now these two messages can have the same timestamp, so some stupid playback program gets their order wrong and sends the second Note-On directly before the first Note-Off. In this case, FIFO would be the only correct choice.
GS devices have a parameter that affects Note-On messages:
Address: 40 1x 14
Parameter: ASSIGN MODE
0 = SINGLE, 1 = LIMITED-MULTI, 2 = FULL-MULTI
Single : If the same note is played multiple times in succession, the previously-sounding note will be completely silenced, and then the new note will be sounded.
LimitedMulti : If the same note is played multiple times in succession, the previously-sounding note will be continued to a certain extent even after the new note is sounded. (Default setting)
FullMulti : If the same note is played multiple times in succession, the previously-sounding note(s) will continue sounding for their natural length even after the new note is sounded.
ASSIGN MODE is the parameter that determines how voice assignment will be handled when sounds overlap on identical note numbers in the same channel (i.e., repeatedly struck notes). This is initialized to a mode suitable for each Part, so for general purposes there is no need to change this.
But it says nothing about Note Off either.