Skip to content

Commit

Permalink
show shadow note refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
22justinl committed Aug 15, 2024
1 parent 5b5c3d7 commit 7dc4c05
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 47 deletions.
4 changes: 2 additions & 2 deletions src/notation/inotationinteraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> pianoKeyboardShadowNoteChanged() const = 0;
virtual muse::async::Channel<bool> shadowNoteChanged() const = 0;

// Visibility
virtual void toggleVisible() = 0;
Expand Down
18 changes: 8 additions & 10 deletions src/notation/internal/notationinteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,20 +328,19 @@ 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)
Expand Down Expand Up @@ -388,8 +387,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)
Expand Down Expand Up @@ -466,14 +463,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
Expand All @@ -497,9 +495,9 @@ RectF NotationInteraction::shadowNoteRect() const
return rect;
}

muse::async::Channel<bool> NotationInteraction::pianoKeyboardShadowNoteChanged() const
muse::async::Channel<bool> NotationInteraction::shadowNoteChanged() const
{
return m_pianoKeyboardShadowNoteChanged;
return m_shadowNoteChanged;
}

void NotationInteraction::toggleVisible()
Expand Down
6 changes: 3 additions & 3 deletions src/notation/internal/notationinteraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> pianoKeyboardShadowNoteChanged() const override;
muse::async::Channel<bool> shadowNoteChanged() const override;

// Visibility
void toggleVisible() override;
Expand Down Expand Up @@ -449,7 +449,7 @@ class NotationInteraction : public INotationInteraction, public muse::Injectable
DropData m_dropData;
muse::async::Notification m_dropChanged;

muse::async::Channel<bool> m_pianoKeyboardShadowNoteChanged;
muse::async::Channel<bool> m_shadowNoteChanged;
muse::async::Channel<ScoreConfigType> m_scoreConfigChanged;

engraving::BspTree m_droppableTree;
Expand Down
1 change: 0 additions & 1 deletion src/notation/tests/mocks/controlledviewmock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions src/notation/tests/mocks/notationinteractionmock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>, pianoKeyboardShadowNoteChanged, (), (const, override));
MOCK_METHOD(muse::async::Channel<bool>, shadowNoteChanged, (), (const, override));

MOCK_METHOD(void, toggleVisible, (), (override));

Expand Down
27 changes: 1 addition & 26 deletions src/notation/view/abstractnotationpaintview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/notation/view/abstractnotationpaintview.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/notation/view/notationviewinputcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ void NotationViewInputController::hoverMoveEvent(QHoverEvent* event)
return;
}

m_view->showShadowNote(pos);
viewInteraction()->showShadowNote(pos);
}

bool NotationViewInputController::shortcutOverrideEvent(QKeyEvent* event)
Expand Down
1 change: 0 additions & 1 deletion src/notation/view/notationviewinputcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7dc4c05

Please sign in to comment.