diff --git a/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp b/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp index 754bc89760..8859ced47e 100644 --- a/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp +++ b/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp @@ -752,7 +752,6 @@ void MidiKeyboardComponent::updateNoteUnderMouse (Point pos, bool isDown, void MidiKeyboardComponent::mouseMove (const MouseEvent& e) { updateNoteUnderMouse (e, false); - shouldCheckMousePos = false; } void MidiKeyboardComponent::mouseDrag (const MouseEvent& e) @@ -760,14 +759,12 @@ void MidiKeyboardComponent::mouseDrag (const MouseEvent& e) float mousePositionVelocity; auto newNote = xyToNote (e.position, mousePositionVelocity); - if (newNote >= 0) - mouseDraggedToKey (newNote, e); - - updateNoteUnderMouse (e, true); + if (newNote >= 0 && mouseDraggedToKey (newNote, e)) + updateNoteUnderMouse (e, true); } bool MidiKeyboardComponent::mouseDownOnKey (int, const MouseEvent&) { return true; } -void MidiKeyboardComponent::mouseDraggedToKey (int, const MouseEvent&) {} +bool MidiKeyboardComponent::mouseDraggedToKey (int, const MouseEvent&) { return true; } void MidiKeyboardComponent::mouseUpOnKey (int, const MouseEvent&) {} void MidiKeyboardComponent::mouseDown (const MouseEvent& e) @@ -776,16 +773,12 @@ void MidiKeyboardComponent::mouseDown (const MouseEvent& e) auto newNote = xyToNote (e.position, mousePositionVelocity); if (newNote >= 0 && mouseDownOnKey (newNote, e)) - { updateNoteUnderMouse (e, true); - shouldCheckMousePos = true; - } } void MidiKeyboardComponent::mouseUp (const MouseEvent& e) { updateNoteUnderMouse (e, false); - shouldCheckMousePos = false; float mousePositionVelocity; auto note = xyToNote (e.position, mousePositionVelocity); @@ -830,13 +823,6 @@ void MidiKeyboardComponent::timerCallback() } } } - - if (shouldCheckMousePos) - { - for (auto& ms : Desktop::getInstance().getMouseSources()) - if (ms.getComponentUnderMouse() == this || isParentOf (ms.getComponentUnderMouse())) - updateNoteUnderMouse (getLocalPoint (nullptr, ms.getScreenPosition()), ms.isDragging(), ms.getIndex()); - } } //============================================================================== diff --git a/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.h b/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.h index f08610af0c..6a76002fbb 100644 --- a/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.h +++ b/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.h @@ -370,9 +370,13 @@ protected: virtual bool mouseDownOnKey (int midiNoteNumber, const MouseEvent& e); /** Callback when the mouse is dragged from one key onto another. + + Return true if you want the drag to trigger the new note, or false if you + want to handle it yourself and not have the note played. + @see mouseDownOnKey */ - virtual void mouseDraggedToKey (int midiNoteNumber, const MouseEvent& e); + virtual bool mouseDraggedToKey (int midiNoteNumber, const MouseEvent& e); /** Callback when the mouse is released from a key. @see mouseDownOnKey @@ -414,7 +418,7 @@ private: int rangeStart = 0, rangeEnd = 127; float firstKey = 12 * 4.0f; - bool canScroll = true, useMousePositionForVelocity = true, shouldCheckMousePos = false; + bool canScroll = true, useMousePositionForVelocity = true; std::unique_ptr