Browse Source

A couple of minor graphical tweaks to MidiKeyboardComponent.

tags/2021-05-28
jules 9 years ago
parent
commit
15812950c6
2 changed files with 27 additions and 16 deletions
  1. +26
    -15
      modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp
  2. +1
    -1
      modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.h

+ 26
- 15
modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp View File

@@ -79,7 +79,7 @@ MidiKeyboardComponent::MidiKeyboardComponent (MidiKeyboardState& s, Orientation
addChildComponent (scrollDown = new MidiKeyboardUpDownButton (*this, -1));
addChildComponent (scrollUp = new MidiKeyboardUpDownButton (*this, 1));
// initialise with a default set of querty key-mappings..
// initialise with a default set of qwerty key-mappings..
const char* const keymap = "awsedftgyhujkolp;";
for (int i = 0; keymap[i] != 0; ++i)
@@ -104,8 +104,13 @@ MidiKeyboardComponent::~MidiKeyboardComponent()
//==============================================================================
void MidiKeyboardComponent::setKeyWidth (const float widthInPixels)
{
keyWidth = widthInPixels;
resized();
jassert (widthInPixels > 0);
if (keyWidth != widthInPixels) // Prevent infinite recursion if the width is being computed in a 'resized()' call-back
{
keyWidth = widthInPixels;
resized();
}
}
void MidiKeyboardComponent::setOrientation (const Orientation newOrientation)
@@ -382,14 +387,18 @@ void MidiKeyboardComponent::paint (Graphics& g)
x += w;
const Colour shadowCol (findColour (shadowColourId));
g.setGradientFill (ColourGradient (shadowCol, x1, y1, shadowCol.withAlpha (0.0f), x2, y2, false));
switch (orientation)
if (! shadowCol.isTransparent())
{
case horizontalKeyboard: g.fillRect (0, 0, x, 5); break;
case verticalKeyboardFacingLeft: g.fillRect (width - 5, 0, 5, x); break;
case verticalKeyboardFacingRight: g.fillRect (0, 0, 5, x); break;
default: break;
g.setGradientFill (ColourGradient (shadowCol, x1, y1, shadowCol.withAlpha (0.0f), x2, y2, false));
switch (orientation)
{
case horizontalKeyboard: g.fillRect (0, 0, x, 5); break;
case verticalKeyboardFacingLeft: g.fillRect (width - 5, 0, 5, x); break;
case verticalKeyboardFacingRight: g.fillRect (0, 0, 5, x); break;
default: break;
}
}
g.setColour (lineColour);
@@ -449,14 +458,16 @@ void MidiKeyboardComponent::drawWhiteNote (int midiNoteNumber,
if (text.isNotEmpty())
{
const float fontHeight = jmin (12.0f, keyWidth * 0.9f);
g.setColour (textColour);
g.setFont (Font (jmin (12.0f, keyWidth * 0.9f)).withHorizontalScale (0.8f));
g.setFont (Font (fontHeight).withHorizontalScale (0.8f));
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;
case horizontalKeyboard: g.drawText (text, x + 1, y, w - 1, h - 2, Justification::centredBottom, false); break;
case verticalKeyboardFacingLeft: g.drawText (text, x + 2, y + 2, w - 4, h - 4, Justification::centredLeft, false); break;
case verticalKeyboardFacingRight: g.drawText (text, x + 2, y + 2, w - 4, h - 4, Justification::centredRight, false); break;
default: break;
}
}
@@ -524,10 +535,10 @@ void MidiKeyboardComponent::setOctaveForMiddleC (const int octaveNum)
String MidiKeyboardComponent::getWhiteNoteText (const int midiNoteNumber)
{
if (keyWidth > 11.0f && midiNoteNumber % 12 == 0)
if (midiNoteNumber % 12 == 0)
return MidiMessage::getMidiNoteName (midiNoteNumber, true, true, octaveNumForMiddleC);
return String::empty;
return String();
}
void MidiKeyboardComponent::drawUpDownButton (Graphics& g, int w, int h,


+ 1
- 1
modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.h View File

@@ -35,7 +35,7 @@
notes by calling the noteOn() and noteOff() methods of its MidiKeyboardState object.
Another feature is that the computer keyboard can also be used to play notes. By
default it maps the top two rows of a standard querty keyboard to the notes, but
default it maps the top two rows of a standard qwerty keyboard to the notes, but
these can be remapped if needed. It will only respond to keypresses when it has
the keyboard focus, so to disable this feature you can call setWantsKeyboardFocus (false).


Loading…
Cancel
Save