I was just having a little look in MidiKeyboardState. This seems to keep a simple flag for each ‘on’ note, rather than a counter.
It looks like if two overlapping MIDI notes of identical MIDI note number are played, this may result in the second note off not responding. The sequence would be:
- First note on arrives, noteOnInternal() sets the note’s flag and calls handleNoteOn() on the listeners
- Second note on arrives (with same MIDI note number) - noteOnInternal() sets the note’s flag (which should already be set from the first note) and calls handleNoteOn() on the listeners
- First note off arrives - noteOffInternal() sees that the note’s flag is set, clears the flag and calls handleNoteOff() on the listeners
- Second note off arrives - noteOffInternal() sees that the note’s flag is not set and fails to call handleNoteOff() on the listeners
Admittedly this is from static code inspection rather than empirical evidence and this situation is impossible to get into with most MIDI controllers, but it could occur when merging MIDI streams or with multi-touch interfaces.
A listener could choose to ignore the second note on, but most good synths should allow multiple instances of the same MIDI note to be played.
