[Feature Request] MidiKeyboardComponent


#1

Hi Guys,

 

Would be great if the display of up/down button to scroll the MidiKeyboardComponent and the actual scrolling would be dissociated.

Right now if I don't display the up/down button, the mousewheel won't move the keyboard range even if the available range is not display entirely.

 

Thanks !


#2

Are you sure that's the case?

Looking at the code, there's a canScroll boolean which turns the buttons off, but none of the mouse-wheel stuff checks it, so that should all work even without the buttons AFAICT (?)


#3

Yep, the culprit is actually line 635 of juce_MidiKeyboardComponent.cpp which won't allow to display another start than the minimum key in the range

 

in MidiKeyboardComponent::resized()

            firstKey = (float) rangeStart;


#4

Only checking for canScroll regarding scrollDown/scrollUp bounds and leaving the rest of the code in all cases fixes the issue FWIW.

 


#5

Bumpity bump :)


#6

If this was trivial, I'd have done it, but it looks a bit more hairy than that..

The position of the leftmost key is actually different when the buttons are missing, which is why it does that "firstKey = (float) rangeStart" stuff. Otherwise, if you created a keyboard and then turned off the buttons, I think it'd leave the  first key too far to the right?


#7

Well that's one of the weird stuff, if you put the display the buttons

the first note displayed is actually not the first note displayed, so it might be a bug no ?


#8

Sorry, don't understand what you mean?


#9


if you do that

mpMidiKeyboard->setScrollButtonsVisible(true);
mpMidiKeyboard->setAvailableRange(0, 127);
mpMidiKeyboard->setLowestVisibleKey(12);

 

The the first key you see ain't a C (MIDI key 12) as the scroll down button is on top of that C

You should'nt have to set a different lowVisibleKey depending on if you call setScrollButtonsVisible with true or false.


#10

I know this is an old issue, and @Jules said it wasn’t trivial to change, but it doesn’t seem like it should be rocket science either. I have a case where I want to use the keyboard along the side of a piano roll, and control the position of the keyboard based on scrolling the piano roll, without displaying the scroll buttons on the keyboard. I thought I had a work around by overriding drawUpDownButton and not drawing anything in there, but of course the buttons are still there, just invisible. lol… any chance you could make the setLowestVisibleKey work when the scroll buttons aren’t displayed?

edit: a co-worker suggested another approach, which I think should provide the same experience. ie. don’t externally scroll a 127 note keyboard, instead use setAvailableRange to dynamically adjust a static 24 note keyboard. I haven’t tested it yet, but I’ll post the results when I do.