int MidiKeyboardComponent::xyToNote (const Point<int>& pos, float& mousePositionVelocity) { if (! reallyContains (pos, false)) return -1; Point<int> p (pos); if (orientation != horizontalKeyboard) { p = Point<int> (p.getY(), p.getX()); if (orientation == verticalKeyboardFacingLeft) p = Point<int> (p.getX(), getWidth() - p.getY()); else p = Point<int> (getHeight() - p.getX(), p.getY()); } return remappedXYToNote (p + Point<int> (xOffset, 0), mousePositionVelocity); }
int MidiKeyboardComponent::xyToNote (Point<float> pos, float& mousePositionVelocity) { if (! reallyContains (pos.toInt(), false)) return -1; auto p = pos; if (orientation != horizontalKeyboard) { p = { p.y, p.x }; if (orientation == verticalKeyboardFacingLeft) p = { p.x, getWidth() - p.y }; else p = { getHeight() - p.x, p.y }; } return remappedXYToNote (p + Point<float> (xOffset, 0), mousePositionVelocity); }
void MidiKeyboardComponent::resized() { int w = getWidth(); int h = getHeight(); if (w > 0 && h > 0) { if (orientation != horizontalKeyboard) std::swap (w, h); blackNoteLength = roundToInt (h * 0.7f); int kx2, kw2; getKeyPos (rangeEnd, kx2, kw2); kx2 += kw2; if (firstKey != rangeStart) { int kx1, kw1; getKeyPos (rangeStart, kx1, kw1); if (kx2 - kx1 <= w) { firstKey = rangeStart; sendChangeMessage(); repaint(); } } const bool showScrollButtons = canScroll && (firstKey > rangeStart || kx2 > w + xOffset * 2); scrollDown->setVisible (showScrollButtons); scrollUp->setVisible (showScrollButtons); xOffset = 0; if (showScrollButtons) { const int scrollButtonW = jmin (12, w / 2); if (orientation == horizontalKeyboard) { scrollDown->setBounds (0, 0, scrollButtonW, getHeight()); scrollUp->setBounds (getWidth() - scrollButtonW, 0, scrollButtonW, getHeight()); } else if (orientation == verticalKeyboardFacingLeft) { scrollDown->setBounds (0, 0, getWidth(), scrollButtonW); scrollUp->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW); } else if (orientation == verticalKeyboardFacingRight) { scrollDown->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW); scrollUp->setBounds (0, 0, getWidth(), scrollButtonW); } int endOfLastKey, kw; getKeyPos (rangeEnd, endOfLastKey, kw); endOfLastKey += kw; float mousePositionVelocity; const int spaceAvailable = w - scrollButtonW * 2; const int lastStartKey = remappedXYToNote (Point<int> (endOfLastKey - spaceAvailable, 0), mousePositionVelocity) + 1; if (lastStartKey >= 0 && firstKey > lastStartKey) { firstKey = jlimit (rangeStart, rangeEnd, lastStartKey); sendChangeMessage(); } int newOffset = 0; getKeyPos (firstKey, newOffset, kw); xOffset = newOffset - scrollButtonW; } else { firstKey = rangeStart; } timerCallback(); repaint(); } }
void MidiKeyboardComponent::resized() { auto w = getWidth(); auto h = getHeight(); if (w > 0 && h > 0) { if (orientation != horizontalKeyboard) std::swap (w, h); auto kx2 = getKeyPos (rangeEnd).getEnd(); if ((int) firstKey != rangeStart) { auto kx1 = getKeyPos (rangeStart).getStart(); if (kx2 - kx1 <= w) { firstKey = (float) rangeStart; sendChangeMessage(); repaint(); } } scrollDown->setVisible (canScroll && firstKey > (float) rangeStart); xOffset = 0; if (canScroll) { auto scrollButtonW = jmin (scrollButtonWidth, w / 2); auto r = getLocalBounds(); if (orientation == horizontalKeyboard) { scrollDown->setBounds (r.removeFromLeft (scrollButtonW)); scrollUp ->setBounds (r.removeFromRight (scrollButtonW)); } else if (orientation == verticalKeyboardFacingLeft) { scrollDown->setBounds (r.removeFromTop (scrollButtonW)); scrollUp ->setBounds (r.removeFromBottom (scrollButtonW)); } else { scrollDown->setBounds (r.removeFromBottom (scrollButtonW)); scrollUp ->setBounds (r.removeFromTop (scrollButtonW)); } auto endOfLastKey = getKeyPos (rangeEnd).getEnd(); float mousePositionVelocity; auto spaceAvailable = w; auto lastStartKey = remappedXYToNote ({ endOfLastKey - spaceAvailable, 0 }, mousePositionVelocity) + 1; if (lastStartKey >= 0 && ((int) firstKey) > lastStartKey) { firstKey = (float) jlimit (rangeStart, rangeEnd, lastStartKey); sendChangeMessage(); } xOffset = getKeyPos ((int) firstKey).getStart(); } else { firstKey = (float) rangeStart; } scrollUp->setVisible (canScroll && getKeyPos (rangeEnd).getStart() > w); repaint(); } }