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 16, 2024
1 parent 5b5c3d7 commit db27dc0
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 58 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
25 changes: 10 additions & 15 deletions src/notation/internal/notationinteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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();
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -497,9 +492,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
10 changes: 6 additions & 4 deletions src/notation/view/pianokeyboard/pianokeyboardcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,12 @@ void PianoKeyboardController::setHoveredKey(std::optional<piano_key_t> 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;
Expand Down
3 changes: 1 addition & 2 deletions src/notation/view/pianokeyboard/pianokeyboardview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit db27dc0

Please sign in to comment.