Little bug in midi/in/keyb zone lru


#1

"Monophonic MIDI keyboard note input, gate, velocity and release velocity, least recently used"

It works well, excepted for the "startNote", when it is still pressed and a higher note is released, it does not go back to it.


I think I spotted the issue in the MIDI code:

...
int n2 = 0;
for(j=0;j<attr_endNote-attr_startNote+1;j++){
   if (np[j]>np2) {
      np2=np[j];
      n2 = j;
   }
}
if (n2>0) {
...

n2 = 0 corresponds to the init value of n2, but it also corresponds to the startNote. A simple solution will be to use another init value, such as -1 and use if(n2>=0) instead of if(n2>0)

...
int n2 = -1;
for(j=0;j<attr_endNote-attr_startNote+1;j++){
   if (np[j]>np2) {
      np2=np[j];
      n2 = j;
   }
}
if (n2>=0) {
...