MidiKeyboardComponent::resetAnyKeysInUse issue


#1

Hi Jules,

I’ve found an issue in MidiKeyboardComponent::resetAnyKeysInUse implementation.
This is called when focusLost is called on a MidiKeyboardComponent.

The issue is that it send an all note off while it should only send note off for note on triggered by the mouse down.
Because of this, it currently sends note off for events which may have been displayed because of a MIDI keyboard.

Could you please fix this ?

Thanks,


#2

Something like this?

[code]void MidiKeyboardComponent::resetAnyKeysInUse()
{
if (keysPressed.countNumberOfSetBits() > 0 || mouseDownNotes.size() > 0)
{
for (int i = mouseDownNotes.size(); --i >= 0;)
{
if (mouseDownNotes[i] || keysPressed[i])
state.noteOff (midiChannel, i);

        mouseDownNotes.set (i, -1);
        mouseOverNotes.set (i, -1);
    }

    keysPressed.clear();
}

}
[/code]


#3

There was a typo in the noteOff which is the note played not the finder index as well as the mouseDownNotes[i] check (-1 not 0)
So maybe this.

void MidiKeyboardComponent::resetAnyKeysInUse()
{
  if (keysPressed.countNumberOfSetBits() > 0 || mouseDownNotes.size() > 0)
  {
    for (int i = mouseDownNotes.size(); --i >= 0;)
    {
      if (mouseDownNotes[i] >= 0 || keysPressed[i])
        state.noteOff (midiChannel, mouseDownNotes[i]);

      mouseDownNotes.set (i, -1);
      mouseOverNotes.set (i, -1);
    }

    keysPressed.clear();
  }
}

#4

Thanks, yes, my original code was all wrong (and I don’t think your suggestion’s correct either) - I’ll have a proper look at it…