From 88fa4e0e561502dfab4d52f34741b2fb03711fba Mon Sep 17 00:00:00 2001 From: jules Date: Sun, 16 Mar 2008 11:54:33 +0000 Subject: [PATCH] --- .../special/juce_MidiKeyboardComponent.cpp | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/juce_appframework/gui/components/special/juce_MidiKeyboardComponent.cpp b/src/juce_appframework/gui/components/special/juce_MidiKeyboardComponent.cpp index aa015712b9..28b057e8dc 100644 --- a/src/juce_appframework/gui/components/special/juce_MidiKeyboardComponent.cpp +++ b/src/juce_appframework/gui/components/special/juce_MidiKeyboardComponent.cpp @@ -280,14 +280,32 @@ int MidiKeyboardComponent::xyToNote (int x, int y) int MidiKeyboardComponent::remappedXYToNote (int x, int y) const { - const int noteX = x % roundFloatToInt (keyWidth * 7.0f); - const int octaveStart = 12 * ((x - noteX) / roundFloatToInt (keyWidth * 7.0f)); - if (y < blackNoteLength) { - for (int i = 0; i < 5; ++i) + for (int octaveStart = 12 * (rangeStart / 12); octaveStart < rangeEnd; octaveStart += 12) { - const int note = rangeStart + octaveStart + blackNotes [i]; + for (int i = 0; i < 5; ++i) + { + const int note = octaveStart + blackNotes [i]; + + if (note >= rangeStart && note <= rangeEnd) + { + int kx, kw; + getKeyPos (note, kx, kw); + kx += xOffset; + + if (x >= kx && x < kx + kw) + return note; + } + } + } + } + + for (int octaveStart = 12 * (rangeStart / 12); octaveStart < rangeEnd; octaveStart += 12) + { + for (int i = 0; i < 7; ++i) + { + const int note = octaveStart + whiteNotes [i]; if (note >= rangeStart && note <= rangeEnd) { @@ -301,21 +319,6 @@ int MidiKeyboardComponent::remappedXYToNote (int x, int y) const } } - for (int i = 0; i < 7; ++i) - { - const int note = rangeStart + octaveStart + whiteNotes [i]; - - if (note >= rangeStart && note <= rangeEnd) - { - int kx, kw; - getKeyPos (note, kx, kw); - kx += xOffset; - - if (x >= kx && x < kx + kw) - return note; - } - } - return -1; }