Browse Source

Added MidiKeyboardComponent::mouseUpOnKey() method.

tags/2021-05-28
jules 12 years ago
parent
commit
39ef5130e9
3 changed files with 21 additions and 25 deletions
  1. +0
    -2
      modules/juce_audio_basics/midi/juce_MidiKeyboardState.h
  2. +15
    -15
      modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp
  3. +6
    -8
      modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.h

+ 0
- 2
modules/juce_audio_basics/midi/juce_MidiKeyboardState.h View File

@@ -180,13 +180,11 @@ public:
//==============================================================================
/** Registers a listener for callbacks when keys go up or down.
@see removeListener
*/
void addListener (MidiKeyboardStateListener* listener);
/** Deregisters a listener.
@see addListener
*/
void removeListener (MidiKeyboardStateListener* listener);


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

@@ -60,13 +60,13 @@ private:
};
//==============================================================================
MidiKeyboardComponent::MidiKeyboardComponent (MidiKeyboardState& state_,
const Orientation orientation_)
: state (state_),
MidiKeyboardComponent::MidiKeyboardComponent (MidiKeyboardState& s,
const Orientation o)
: state (s),
xOffset (0),
blackNoteLength (1),
keyWidth (16.0f),
orientation (orientation_),
orientation (o),
midiChannel (1),
midiInChannelMask (0xffff),
velocity (1.0f),
@@ -539,8 +539,8 @@ String MidiKeyboardComponent::getWhiteNoteText (const int midiNoteNumber)
}
void MidiKeyboardComponent::drawUpDownButton (Graphics& g, int w, int h,
const bool isMouseOver_,
const bool isButtonDown,
const bool mouseOver,
const bool buttonDown,
const bool movesOctavesUp)
{
g.fillAll (findColour (upDownButtonBackgroundColourId));
@@ -560,7 +560,7 @@ void MidiKeyboardComponent::drawUpDownButton (Graphics& g, int w, int h,
path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * angle, 0.5f, 0.5f));
g.setColour (findColour (upDownButtonArrowColourId)
.withAlpha (isButtonDown ? 1.0f : (isMouseOver_ ? 0.6f : 0.4f)));
.withAlpha (buttonDown ? 1.0f : (mouseOver ? 0.6f : 0.4f)));
g.fillPath (path, path.getTransformToScaleToFit (1.0f, 1.0f, w - 2.0f, h - 2.0f, true));
}
@@ -754,14 +754,9 @@ void MidiKeyboardComponent::mouseDrag (const MouseEvent& e)
updateNoteUnderMouse (e, true);
}
bool MidiKeyboardComponent::mouseDownOnKey (int /*midiNoteNumber*/, const MouseEvent&)
{
return true;
}
void MidiKeyboardComponent::mouseDraggedToKey (int /*midiNoteNumber*/, const MouseEvent&)
{
}
bool MidiKeyboardComponent::mouseDownOnKey (int, const MouseEvent&) { return true; }
void MidiKeyboardComponent::mouseDraggedToKey (int, const MouseEvent&) {}
void MidiKeyboardComponent::mouseUpOnKey (int, const MouseEvent&) {}
void MidiKeyboardComponent::mouseDown (const MouseEvent& e)
{
@@ -779,6 +774,11 @@ void MidiKeyboardComponent::mouseUp (const MouseEvent& e)
{
updateNoteUnderMouse (e, false);
shouldCheckMousePos = false;
float mousePositionVelocity;
const int note = xyToNote (e.getPosition(), mousePositionVelocity);
if (note >= 0)
mouseUpOnKey (note, e);
}
void MidiKeyboardComponent::mouseEnter (const MouseEvent& e)


+ 6
- 8
modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.h View File

@@ -146,13 +146,11 @@ public:
int highestNote);
/** Returns the first note in the available range.
@see setAvailableRange
*/
int getRangeStart() const noexcept { return rangeStart; }
/** Returns the last note in the available range.
@see setAvailableRange
*/
int getRangeEnd() const noexcept { return rangeEnd; }
@@ -166,7 +164,6 @@ public:
void setLowestVisibleKey (int noteNumber);
/** Returns the number of the first key shown in the component.
@see setLowestVisibleKey
*/
int getLowestVisibleKey() const noexcept { return (int) firstKey; }
@@ -211,7 +208,6 @@ public:
//==============================================================================
/** Deletes all key-mappings.
@see setKeyPressForNote
*/
void clearKeyMappings();
@@ -228,7 +224,6 @@ public:
int midiNoteOffsetFromC);
/** Removes any key-mappings for a given note.
For a description of what the note number means, see setKeyPressForNote().
*/
void removeKeyPressForNote (int midiNoteOffsetFromC);
@@ -349,11 +344,15 @@ protected:
virtual bool mouseDownOnKey (int midiNoteNumber, const MouseEvent& e);
/** Callback when the mouse is dragged from one key onto another.
@see mouseDownOnKey
*/
virtual void mouseDraggedToKey (int midiNoteNumber, const MouseEvent& e);
/** Callback when the mouse is released from a key.
@see mouseDownOnKey
*/
virtual void mouseUpOnKey (int midiNoteNumber, const MouseEvent& e);
/** Calculates the positon of a given midi-note.
This can be overridden to create layouts with custom key-widths.
@@ -390,8 +389,7 @@ private:
Array <KeyPress> keyPresses;
Array <int> keyPressNotes;
int keyMappingOctave;
int octaveNumForMiddleC;
int keyMappingOctave, octaveNumForMiddleC;
static const uint8 whiteNotes[];
static const uint8 blackNotes[];


Loading…
Cancel
Save