mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-25 02:04:23 +00:00
Fixed a few minor problems with the MidiKeyboardComponent
This commit is contained in:
parent
eee868ae02
commit
4869c0a202
2 changed files with 24 additions and 27 deletions
|
|
@ -152,10 +152,9 @@ void MidiKeyboardComponent::setLowestVisibleKeyFloat (float noteNumber)
|
|||
firstKey = noteNumber;
|
||||
|
||||
if (hasMoved)
|
||||
{
|
||||
sendChangeMessage();
|
||||
resized();
|
||||
}
|
||||
|
||||
resized();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -458,14 +457,13 @@ void MidiKeyboardComponent::drawWhiteNote (int midiNoteNumber,
|
|||
g.setColour (textColour);
|
||||
g.setFont (Font (jmin (12.0f, keyWidth * 0.9f)).withHorizontalScale (0.8f));
|
||||
|
||||
Justification justification (Justification::centredBottom);
|
||||
|
||||
if (orientation == verticalKeyboardFacingLeft)
|
||||
justification = Justification::centredLeft;
|
||||
else if (orientation == verticalKeyboardFacingRight)
|
||||
justification = Justification::centredRight;
|
||||
|
||||
g.drawFittedText (text, x + 2, y + 2, w - 4, h - 4, justification, 1);
|
||||
switch (orientation)
|
||||
{
|
||||
case horizontalKeyboard: g.drawFittedText (text, x + 1, y, w - 1, h - 2, Justification::centredBottom, 1); break;
|
||||
case verticalKeyboardFacingLeft: g.drawFittedText (text, x + 2, y + 2, w - 4, h - 4, Justification::centredLeft, 1); break;
|
||||
case verticalKeyboardFacingRight: g.drawFittedText (text, x + 2, y + 2, w - 4, h - 4, Justification::centredRight, 1); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
g.setColour (lineColour);
|
||||
|
|
@ -531,7 +529,7 @@ void MidiKeyboardComponent::setOctaveForMiddleC (const int octaveNum)
|
|||
|
||||
String MidiKeyboardComponent::getWhiteNoteText (const int midiNoteNumber)
|
||||
{
|
||||
if (keyWidth > 14.0f && midiNoteNumber % 12 == 0)
|
||||
if (keyWidth > 11.0f && midiNoteNumber % 12 == 0)
|
||||
return MidiMessage::getMidiNoteName (midiNoteNumber, true, true, octaveNumForMiddleC);
|
||||
|
||||
return String::empty;
|
||||
|
|
@ -594,31 +592,29 @@ void MidiKeyboardComponent::resized()
|
|||
}
|
||||
}
|
||||
|
||||
const bool showScrollButtons = canScroll && (((int) firstKey) > rangeStart || kx2 > w + xOffset * 2);
|
||||
|
||||
scrollDown->setVisible (showScrollButtons);
|
||||
scrollUp->setVisible (showScrollButtons);
|
||||
scrollDown->setVisible (canScroll && firstKey > (float) rangeStart);
|
||||
|
||||
xOffset = 0;
|
||||
|
||||
if (showScrollButtons)
|
||||
if (canScroll)
|
||||
{
|
||||
const int scrollButtonW = jmin (12, w / 2);
|
||||
Rectangle<int> r (getLocalBounds());
|
||||
|
||||
if (orientation == horizontalKeyboard)
|
||||
{
|
||||
scrollDown->setBounds (0, 0, scrollButtonW, getHeight());
|
||||
scrollUp->setBounds (getWidth() - scrollButtonW, 0, scrollButtonW, getHeight());
|
||||
scrollDown->setBounds (r.removeFromLeft (scrollButtonW));
|
||||
scrollUp ->setBounds (r.removeFromRight (scrollButtonW));
|
||||
}
|
||||
else if (orientation == verticalKeyboardFacingLeft)
|
||||
{
|
||||
scrollDown->setBounds (0, 0, getWidth(), scrollButtonW);
|
||||
scrollUp->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
|
||||
scrollDown->setBounds (r.removeFromTop (scrollButtonW));
|
||||
scrollUp ->setBounds (r.removeFromBottom (scrollButtonW));
|
||||
}
|
||||
else
|
||||
{
|
||||
scrollDown->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
|
||||
scrollUp->setBounds (0, 0, getWidth(), scrollButtonW);
|
||||
scrollDown->setBounds (r.removeFromBottom (scrollButtonW));
|
||||
scrollUp ->setBounds (r.removeFromTop (scrollButtonW));
|
||||
}
|
||||
|
||||
int endOfLastKey, kw;
|
||||
|
|
@ -626,7 +622,7 @@ void MidiKeyboardComponent::resized()
|
|||
endOfLastKey += kw;
|
||||
|
||||
float mousePositionVelocity;
|
||||
const int spaceAvailable = w - scrollButtonW * 2;
|
||||
const int spaceAvailable = w;
|
||||
const int lastStartKey = remappedXYToNote (Point<int> (endOfLastKey - spaceAvailable, 0), mousePositionVelocity) + 1;
|
||||
|
||||
if (lastStartKey >= 0 && ((int) firstKey) > lastStartKey)
|
||||
|
|
@ -636,14 +632,16 @@ void MidiKeyboardComponent::resized()
|
|||
}
|
||||
|
||||
int newOffset = 0;
|
||||
getKeyPos (((int) firstKey), newOffset, kw);
|
||||
xOffset = newOffset - scrollButtonW;
|
||||
getKeyPos ((int) firstKey, newOffset, kw);
|
||||
xOffset = newOffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
firstKey = (float) rangeStart;
|
||||
}
|
||||
|
||||
getKeyPos (rangeEnd, kx2, kw2);
|
||||
scrollUp->setVisible (canScroll && kx2 > w);
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,6 @@ class JUCE_API MidiKeyboardComponent : public Component,
|
|||
public:
|
||||
//==============================================================================
|
||||
/** The direction of the keyboard.
|
||||
|
||||
@see setOrientation
|
||||
*/
|
||||
enum Orientation
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue