New assert in KeyboardComponentBase::getRectangleForKey

Hi guys,

Since updating to juce, I get some assert
jassert (note >= rangeStart && note <= rangeEnd);
I display the whole keyboard hence KeyboardComponentBase::paint
call the whole range
**for** ( **int** octaveBase = 0; octaveBase < 128; octaveBase += 12)
so when I’m at octaveBase of 120 then the
drawWhiteKey (octaveBase + noteNum, g, getRectangleForKey (octaveBase + noteNum));
call getRectangleForKey for value > 128

Thanks !

Q&D fix

void KeyboardComponentBase::paint (Graphics& g)
{
    drawKeyboardBackground (g, getLocalBounds().toFloat());

    for (int octaveBase = 12 * (rangeStart / 12); octaveBase <= rangeEnd; octaveBase += 12)
    {
        for (auto noteNum : whiteNotes)
          if (octaveBase + noteNum >= rangeStart && octaveBase + noteNum <= rangeEnd)
            drawWhiteKey (octaveBase + noteNum, g, getRectangleForKey (octaveBase + noteNum));

        for (auto noteNum : blackNotes)
          if (octaveBase + noteNum >= rangeStart && octaveBase + noteNum <= rangeEnd)
              drawBlackKey (octaveBase + noteNum, g, getRectangleForKey (octaveBase + noteNum));
    }
}

but the best is to probably rewrite it

tagging @ed95 as it is his code

Thanks for reporting. Should be fixed here:

1 Like