Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added shift as sustain behaviour for MidiKeyboardComponent #485

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 27 additions & 2 deletions modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp
Expand Up @@ -708,6 +708,18 @@ void MidiKeyboardComponent::updateNoteUnderMouse (const MouseEvent& e, bool isDo

void MidiKeyboardComponent::updateNoteUnderMouse (Point<float> pos, bool isDown, int fingerNum)
{
if (sustainPressed)
{
for (int i=0; i < mouseDownNotes.size(); ++i)
{
if (mouseDownNotes.getUnchecked (i) < 0)
{
fingerNum = i;
break;
}
}
}

float mousePositionVelocity = 0.0f;
auto newNote = xyToNote (pos, mousePositionVelocity);
auto oldNote = mouseOverNotes.getUnchecked (fingerNum);
Expand All @@ -725,7 +737,7 @@ void MidiKeyboardComponent::updateNoteUnderMouse (Point<float> pos, bool isDown,
{
if (newNote != oldNoteDown)
{
if (oldNoteDown >= 0)
if (oldNoteDown >= 0 && sustainPressed == false)
{
mouseDownNotes.set (fingerNum, -1);

Expand All @@ -740,7 +752,7 @@ void MidiKeyboardComponent::updateNoteUnderMouse (Point<float> pos, bool isDown,
}
}
}
else if (oldNoteDown >= 0)
else if (oldNoteDown >= 0 && sustainPressed == false)
{
mouseDownNotes.set (fingerNum, -1);

Expand Down Expand Up @@ -784,6 +796,9 @@ void MidiKeyboardComponent::mouseDown (const MouseEvent& e)

void MidiKeyboardComponent::mouseUp (const MouseEvent& e)
{
if (sustainPressed)
return;

updateNoteUnderMouse (e, false);
shouldCheckMousePos = false;

Expand Down Expand Up @@ -815,6 +830,16 @@ void MidiKeyboardComponent::mouseWheelMove (const MouseEvent&, const MouseWheelD

void MidiKeyboardComponent::timerCallback()
{
if (ModifierKeys::getCurrentModifiers().isShiftDown())
{
sustainPressed = true;
}
else if (sustainPressed)
{
sustainPressed = false;
resetAnyKeysInUse();
}

if (shouldCheckState)
{
shouldCheckState = false;
Expand Down
1 change: 1 addition & 0 deletions modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.h
Expand Up @@ -410,6 +410,7 @@ class JUCE_API MidiKeyboardComponent : public Component,

Array<int> mouseOverNotes, mouseDownNotes;
BigInteger keysPressed, keysCurrentlyDrawnDown;
bool sustainPressed = false;
bool shouldCheckState = false;

int rangeStart = 0, rangeEnd = 127;
Expand Down