Browse Source

Fixed an issue overriding MidiKeyboardComponent::mouseDownOnKey

tags/2021-05-28
Tom Poole 6 years ago
parent
commit
1e021b6ed0
2 changed files with 9 additions and 19 deletions
  1. +3
    -17
      modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp
  2. +6
    -2
      modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.h

+ 3
- 17
modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp View File

@@ -752,7 +752,6 @@ void MidiKeyboardComponent::updateNoteUnderMouse (Point<float> 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());
}
}
//==============================================================================


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

@@ -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<Button> scrollDown, scrollUp;
Array<KeyPress> keyPresses;


Loading…
Cancel
Save