[REQUEST] MidiKeyboardComponent::getKeyboardWidth()

MidiKeyboardComponent has a getKeyWidth() but not a getKeyboardWidth() -- which means that the user needs to calculate the number of white keys and multiply by getKeyWidth() in order to set the component's bounds, which is a bit fiddly.


Well no, that wouldn't work. But you'd just need to call getKeyPosition (getRangeEnd()) to find the right-hand edge of the highest note shown. I could add a helper function that does the same thing, but in the meantime that's a pretty easy thing to do.

hmm It seems to work...

    void resized() override
        int w = (int)keyboardComponent.getKeyWidth() * (7 * 7 + 3), h = 50;
        keyboardComponent.setSize(w, h);
        keyboardComponent.setCentrePosition(getWidth() / 2, getHeight() / 2);

With your suggested workaround, I need:

        int k = keyboardComponent.getRangeEnd(),
            w = keyboardComponent.getKeyStartPosition(k+2), 
            h = 50;
        keyboardComponent.setSize(w, h);

It seems odd that I need k+2 not k+1.


I already added a getTotalKeyboardWidth() method


Why can't you just Component::getWidth()?