From 39ef5130e9a02c3107832586b9871cb30e0b646c Mon Sep 17 00:00:00 2001 From: jules Date: Fri, 28 Jun 2013 15:20:51 +0100 Subject: [PATCH] Added MidiKeyboardComponent::mouseUpOnKey() method. --- .../midi/juce_MidiKeyboardState.h | 2 -- .../gui/juce_MidiKeyboardComponent.cpp | 30 +++++++++---------- .../gui/juce_MidiKeyboardComponent.h | 14 ++++----- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/modules/juce_audio_basics/midi/juce_MidiKeyboardState.h b/modules/juce_audio_basics/midi/juce_MidiKeyboardState.h index 17112371ff..229a72fa4e 100644 --- a/modules/juce_audio_basics/midi/juce_MidiKeyboardState.h +++ b/modules/juce_audio_basics/midi/juce_MidiKeyboardState.h @@ -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); diff --git a/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp b/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp index e583c76ad0..33a72d6fe9 100644 --- a/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp +++ b/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp @@ -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) diff --git a/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.h b/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.h index c725b8f1be..5e1dc29447 100644 --- a/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.h +++ b/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.h @@ -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 keyPresses; Array keyPressNotes; - int keyMappingOctave; - int octaveNumForMiddleC; + int keyMappingOctave, octaveNumForMiddleC; static const uint8 whiteNotes[]; static const uint8 blackNotes[];