diff --git a/src/notation/inotationinteraction.h b/src/notation/inotationinteraction.h index 44b9033adbb73..790467d2e0d8e 100644 --- a/src/notation/inotationinteraction.h +++ b/src/notation/inotationinteraction.h @@ -44,11 +44,11 @@ class INotationInteraction virtual INotationNoteInputPtr noteInput() const = 0; // Shadow note - virtual bool showShadowNote(const muse::PointF& pos) = 0; + virtual void showShadowNote(const muse::PointF& pos) = 0; virtual void showShadowNoteForMidiPitch(const uint8_t note) = 0; virtual void hideShadowNote() = 0; virtual muse::RectF shadowNoteRect() const = 0; - virtual muse::async::Channel pianoKeyboardShadowNoteChanged() const = 0; + virtual muse::async::Channel shadowNoteChanged() const = 0; // Visibility virtual void toggleVisible() = 0; diff --git a/src/notation/internal/notationinteraction.cpp b/src/notation/internal/notationinteraction.cpp index c9f2a1161dacd..dba27ef289a6f 100644 --- a/src/notation/internal/notationinteraction.cpp +++ b/src/notation/internal/notationinteraction.cpp @@ -328,20 +328,18 @@ INotationNoteInputPtr NotationInteraction::noteInput() const return m_noteInput; } -bool NotationInteraction::showShadowNote(const PointF& pos) +void NotationInteraction::showShadowNote(const PointF& pos) { const mu::engraving::InputState& inputState = score()->inputState(); mu::engraving::ShadowNote& shadowNote = *score()->shadowNote(); mu::engraving::Position position; if (!score()->getPosition(&position, pos, inputState.voice())) { - shadowNote.setVisible(false); - return false; + hideShadowNote(); + return; } updateShadowNoteProperties(position); - - return true; } void NotationInteraction::showShadowNoteForMidiPitch(const uint8_t key) @@ -357,11 +355,12 @@ void NotationInteraction::showShadowNoteForMidiPitch(const uint8_t key) staff_idx_t staffIdx = inputState.track() / VOICES; const Staff* inputStaff = score()->staff(staffIdx); const Fraction tick = inputSegment->tick(); - const double mag = inputStaff->staffMag(tick); + const double mag = inputStaff->staffMag(tick); double lineDist = inputStaff->staffType(tick)->lineDistance().val() * (inputStaff->isTabStaff(tick) ? 1 : .5) * mag * score()->style().spatium(); + int rLine = 0; if (inputStaff->isDrumStaff(tick)) { // different behavior? ignoring for now @@ -376,9 +375,6 @@ void NotationInteraction::showShadowNoteForMidiPitch(const uint8_t key) int line = octave * 7 + mu::engraving::pitch2step(key); ClefType clef = inputStaff->clef(tick); rLine = mu::engraving::relStep(line, clef); - - shadowNote.setStaffIdx(staffIdx); - shadowNote.setLineIndex(rLine); } double xPos = inputSegment->canvasPos().x(); @@ -388,8 +384,6 @@ void NotationInteraction::showShadowNoteForMidiPitch(const uint8_t key) Position position = { inputSegment, staffIdx, rLine, mu::engraving::INVALID_FRET_INDEX, p }; updateShadowNoteProperties(position); - - m_pianoKeyboardShadowNoteChanged.send(true); } void NotationInteraction::updateShadowNoteProperties(Position& position) @@ -466,14 +460,15 @@ void NotationInteraction::updateShadowNoteProperties(Position& position) } score()->renderer()->layoutItem(&shadowNote); - shadowNote.setPos(position.pos); + + m_shadowNoteChanged.send(true); } void NotationInteraction::hideShadowNote() { score()->shadowNote()->setVisible(false); - m_pianoKeyboardShadowNoteChanged.send(false); + m_shadowNoteChanged.send(false); } RectF NotationInteraction::shadowNoteRect() const @@ -497,9 +492,9 @@ RectF NotationInteraction::shadowNoteRect() const return rect; } -muse::async::Channel NotationInteraction::pianoKeyboardShadowNoteChanged() const +muse::async::Channel NotationInteraction::shadowNoteChanged() const { - return m_pianoKeyboardShadowNoteChanged; + return m_shadowNoteChanged; } void NotationInteraction::toggleVisible() diff --git a/src/notation/internal/notationinteraction.h b/src/notation/internal/notationinteraction.h index fb6fe8be437fb..1b330475f1acf 100644 --- a/src/notation/internal/notationinteraction.h +++ b/src/notation/internal/notationinteraction.h @@ -64,11 +64,11 @@ class NotationInteraction : public INotationInteraction, public muse::Injectable INotationNoteInputPtr noteInput() const override; // Shadow note - bool showShadowNote(const muse::PointF& pos) override; + void showShadowNote(const muse::PointF& pos) override; void showShadowNoteForMidiPitch(const uint8_t note) override; void hideShadowNote() override; muse::RectF shadowNoteRect() const override; - muse::async::Channel pianoKeyboardShadowNoteChanged() const override; + muse::async::Channel shadowNoteChanged() const override; // Visibility void toggleVisible() override; @@ -449,7 +449,7 @@ class NotationInteraction : public INotationInteraction, public muse::Injectable DropData m_dropData; muse::async::Notification m_dropChanged; - muse::async::Channel m_pianoKeyboardShadowNoteChanged; + muse::async::Channel m_shadowNoteChanged; muse::async::Channel m_scoreConfigChanged; engraving::BspTree m_droppableTree; diff --git a/src/notation/tests/mocks/controlledviewmock.h b/src/notation/tests/mocks/controlledviewmock.h index 05fb28c729dcf..1a199542d42ed 100644 --- a/src/notation/tests/mocks/controlledviewmock.h +++ b/src/notation/tests/mocks/controlledviewmock.h @@ -50,7 +50,6 @@ class ControlledViewMock : public IControlledView MOCK_METHOD(muse::RectF, fromLogical, (const muse::RectF&), (const, override)); MOCK_METHOD(bool, isNoteEnterMode, (), (const, override)); - MOCK_METHOD(void, showShadowNote, (const muse::PointF&), (override)); MOCK_METHOD(void, showContextMenu, (const ElementType&, const QPointF&), (override)); MOCK_METHOD(void, hideContextMenu, (), (override)); diff --git a/src/notation/tests/mocks/notationinteractionmock.h b/src/notation/tests/mocks/notationinteractionmock.h index 8613c9ea6abac..9feb539eb70e7 100644 --- a/src/notation/tests/mocks/notationinteractionmock.h +++ b/src/notation/tests/mocks/notationinteractionmock.h @@ -32,11 +32,11 @@ class NotationInteractionMock : public INotationInteraction public: MOCK_METHOD(INotationNoteInputPtr, noteInput, (), (const, override)); - MOCK_METHOD(bool, showShadowNote, (const muse::PointF&), (override)); + MOCK_METHOD(void, showShadowNote, (const muse::PointF&), (override)); MOCK_METHOD(void, showShadowNoteForMidiPitch, (const uint8_t), (override)); MOCK_METHOD(void, hideShadowNote, (), (override)); MOCK_METHOD(muse::RectF, shadowNoteRect, (), (const, override)); - MOCK_METHOD(muse::async::Channel, pianoKeyboardShadowNoteChanged, (), (const, override)); + MOCK_METHOD(muse::async::Channel, shadowNoteChanged, (), (const, override)); MOCK_METHOD(void, toggleVisible, (), (override)); diff --git a/src/notation/view/abstractnotationpaintview.cpp b/src/notation/view/abstractnotationpaintview.cpp index 9983092e1c2f9..6787c353c3aa3 100644 --- a/src/notation/view/abstractnotationpaintview.cpp +++ b/src/notation/view/abstractnotationpaintview.cpp @@ -277,7 +277,7 @@ void AbstractNotationPaintView::onLoadNotation(INotationPtr) } }); - interaction->pianoKeyboardShadowNoteChanged().onReceive(this, [this](bool visible) { + interaction->shadowNoteChanged().onReceive(this, [this](bool visible) { if (m_shadowNoteRect.isValid()) { scheduleRedraw(m_shadowNoteRect); @@ -514,31 +514,6 @@ bool AbstractNotationPaintView::isNoteEnterMode() const return notationNoteInput() ? notationNoteInput()->isNoteInputMode() : false; } -void AbstractNotationPaintView::showShadowNote(const PointF& pos) -{ - TRACEFUNC; - - bool visible = notationInteraction()->showShadowNote(pos); - - if (m_shadowNoteRect.isValid()) { - scheduleRedraw(m_shadowNoteRect); - - if (!visible) { - m_shadowNoteRect = RectF(); - return; - } - } - - RectF shadowNoteRect = fromLogical(notationInteraction()->shadowNoteRect()); - - if (shadowNoteRect.isValid()) { - compensateFloatPart(shadowNoteRect); - scheduleRedraw(shadowNoteRect); - } - - m_shadowNoteRect = shadowNoteRect; -} - void AbstractNotationPaintView::showContextMenu(const ElementType& elementType, const QPointF& pos) { TRACEFUNC; diff --git a/src/notation/view/abstractnotationpaintview.h b/src/notation/view/abstractnotationpaintview.h index 03b8ad85382e8..570fa4abf2081 100644 --- a/src/notation/view/abstractnotationpaintview.h +++ b/src/notation/view/abstractnotationpaintview.h @@ -114,7 +114,6 @@ class AbstractNotationPaintView : public muse::uicomponents::QuickPaintedView, p Q_INVOKABLE void pinchToZoom(qreal scaleFactor, const QPointF& pos); bool isNoteEnterMode() const override; - void showShadowNote(const muse::PointF& pos) override; void showContextMenu(const ElementType& elementType, const QPointF& pos) override; void hideContextMenu() override; diff --git a/src/notation/view/notationviewinputcontroller.cpp b/src/notation/view/notationviewinputcontroller.cpp index ca06a3b27df43..d7ff7c7bd80cb 100644 --- a/src/notation/view/notationviewinputcontroller.cpp +++ b/src/notation/view/notationviewinputcontroller.cpp @@ -979,7 +979,7 @@ void NotationViewInputController::hoverMoveEvent(QHoverEvent* event) return; } - m_view->showShadowNote(pos); + viewInteraction()->showShadowNote(pos); } bool NotationViewInputController::shortcutOverrideEvent(QKeyEvent* event) diff --git a/src/notation/view/notationviewinputcontroller.h b/src/notation/view/notationviewinputcontroller.h index 57a5b49be6f87..a319785eb2ea1 100644 --- a/src/notation/view/notationviewinputcontroller.h +++ b/src/notation/view/notationviewinputcontroller.h @@ -68,7 +68,6 @@ class IControlledView virtual muse::RectF fromLogical(const muse::RectF& r) const = 0; virtual bool isNoteEnterMode() const = 0; - virtual void showShadowNote(const muse::PointF& pos) = 0; virtual void showContextMenu(const ElementType& elementType, const QPointF& pos) = 0; virtual void hideContextMenu() = 0; diff --git a/src/notation/view/pianokeyboard/pianokeyboardcontroller.cpp b/src/notation/view/pianokeyboard/pianokeyboardcontroller.cpp index 727e21bd6cb80..368309627ccfe 100644 --- a/src/notation/view/pianokeyboard/pianokeyboardcontroller.cpp +++ b/src/notation/view/pianokeyboard/pianokeyboardcontroller.cpp @@ -94,10 +94,12 @@ void PianoKeyboardController::setHoveredKey(std::optional key) return; } - if (notation && notation->interaction()->noteInput()->isNoteInputMode() && key.has_value()) { - notation->interaction()->showShadowNoteForMidiPitch(key.value()); - } else { - notation->interaction()->hideShadowNote(); + if (notation && notation->interaction()->noteInput()->isNoteInputMode()) { + if (key.has_value()) { + notation->interaction()->showShadowNoteForMidiPitch(key.value()); + } else { + notation->interaction()->hideShadowNote(); + } } m_hoveredKey = key; diff --git a/src/notation/view/pianokeyboard/pianokeyboardview.cpp b/src/notation/view/pianokeyboard/pianokeyboardview.cpp index 81db18ec1fe3d..63e9e53d629bc 100644 --- a/src/notation/view/pianokeyboard/pianokeyboardview.cpp +++ b/src/notation/view/pianokeyboard/pianokeyboardview.cpp @@ -566,8 +566,7 @@ void PianoKeyboardView::hoverMoveEvent(QHoverEvent* event) m_controller->setHoveredKey(keyAt(event->position())); } -void PianoKeyboardView::hoverLeaveEvent(QHoverEvent* event) +void PianoKeyboardView::hoverLeaveEvent(QHoverEvent*) { m_controller->setHoveredKey(std::nullopt); - event->accept(); }