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.