MidiKeyboardComponent question


#1

hi jules, since i’m using the MidiKeyboardComponent a lot, and i need to specialize it to let it be in sync with a midi grid:
mainly it paints white/black keys with different widths (regardless of setKeyWidth calls), so doing a conversion function from mouse position to note/beat is quite cpu consuming cause i have to keep track of the painted midi keyboard widths offsets.
so i need it to paint and behave a little different, but all members are private

:open_mouth:

could they be promoted to protected ?


#2

Which bits do you need? Or could there be a more generic way of adding what you’re trying to do? Maybe a virtual function to calculate the positions?


#3

well i’ve got something like this:

you notice the midi grid ?i have to subtract these offset to the row height (10px)in order to keep it in sync with the midi keys width (15px):

const int noteAdjustOffsetAtFiftheenPixelsKeyWidth [12] = { /*C*/0, /*C#*/1, /*D*/1, /*D#*/1, /*E*/1, /*F*/1, /*F#*/2, /*G*/1, /*G#*/2, /*A*/1, /*A#*/2, /*B*/1 };

obviously it looks in sync only with the passed sizes.
would be cool if there was a virtual function that let you organize keys the width you want.

hope you understand what i mean… (i basically need to give the midi keys a special width, so i can draw the grid rows at a fixed height)


#4

Would it be enough to make getKeyPos a virtual method so you could do your own version?


#5

yes thanx that would do the job :slight_smile:
obviously you should pass also the key width selected (so i can guess how many pixels an octave will eat up).


#6

ok, try the tip now…


#7

cd Projects/juce svn up cd build/linux make && make CONFIG=Release

…the power of repository based source code…

:smiley: yay!


#8

well, rangeStart - rangeEnd - xOffset are private :slight_smile:
i think that

jassert (midiNoteNumber >= rangeStart && midiNoteNumber <= rangeEnd); midiNoteNumber -= rangeStart;

should be done by the component before calling the getKeyPosition function (so don’t rely on checks made by the subclassed component).
also, doing -xOffset should be avoided from that function (i shouldn’t know the x offset, nor touch it directly), and rather done outside the call.


#9

You’re quite right, there were a bunch of things wrong with that. Try it now.


#10

ok the changes to getKeyPosition are now working good.

other thing: if i want to subclass

then octaveNumForMiddleC is private, and there is not getter method…


#11

ok, I’ve added an accessor for the octave number


#12

mighty jules … thanks and praises :slight_smile:


#13