Duplicated MidikeyboardComponent triggers multiple notes on


#1

Hi everybody,

I have a iOS app with two MidiKeyboardComponents (arranged like a organ waterfall keyboard).

However, if I press a key on one keyboard, then another on the second keyboard, the first note will be retriggered, which is a bit annoying.

After a while of debugging I’ve tracked down the culprit to the handling of the key focus:

void MidiKeyboardComponent::focusLost (FocusChangeType)
{
    resetAnyKeysInUse();
}

The focus loss of the first keyboard when you press the second note causes the internal state to reset and trigger a new note the next time it checks for pressed keys.

Now the most nasty hack I can imagine is this:

void MidiKeyboardComponent::focusLost (FocusChangeType)
{
#if !JUCE_IOS
    resetAnyKeysInUse();
#endif
}

But I am sure there’s something more elaborate that could slip into the JUCE codebase.


#2

Have you tried giving each midi keyboard their own MidiKeyboardState, adding listeners to those states and using some logic to determine which MKC it came from in the handleNoteOn() handleNoteOff()


#3

Not sure how this could solve the problem, I think the fact that it’s resetting the note states on focus loss is not really suitable for multitouch displays and should be fixed in the component’s code itself.

I don’t fully understand why it’s there in the first place. The only scenario where this is useful is when you trigger notes per keypress and then change the focus by clicking somewhere else, which would result in stuck notes. However in this case, I’d suggest using a dedicated finger index for notes triggered by key presses in the midiDownNotes array and only reset the notes at this particular finger index.