MidiKeyboardComponent for multi channel note display

I’m developing a multichannel midi note display.
I can display different channel/colours using a derived MidiKeyboardComponent::drawWhiteNote override. This works fine until the same note is played together on two channels.
The problem comes when a note is held on one channel and the same note-on from a different channel is played. The second note-on message does not result in the base class method MidiKeyboardComponent::drawWhiteKey() getting called for the second note-on.
It is as though MidiKeyboardComponent and/or MidiKeyboardState are not truly multi channel.
Can anyone confirm this?
What would be the solution for my use case?

The problem is in the timer callback where the need for repaint is determined.
The isOn state is determined for any/all channels so that if a particular note is held on one channel then that note changes on another channel will not result in a repaint.
This is not compatible with a multichannel coloured display where the colour changes depending on what combination of channels is playing on the same note.
I think I will have to refactor MidiKeyboardComponent to acheive this…

Here’s the piece of library code for reference:

void MidiKeyboardComponent::timerCallback()
    if (noPendingUpdates.exchange (true))

    for (auto i = getRangeStart(); i <= getRangeEnd(); ++i)
        const auto isOn = state.isNoteOnForChannels (midiInChannelMask, i);

        if (keysCurrentlyDrawnDown[i] != isOn)
            keysCurrentlyDrawnDown.setBit (i, isOn);
            repaintNote (i);

While I have nothing specific to offer, I do remember there was another discussion on this recently.

1 Like