Skip to content

Commit

Permalink
Navigation - check if a previous selection exists before restoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mathesoncalum committed Nov 27, 2024
1 parent b790329 commit fda3727
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/notation/internal/notationactioncontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,11 @@ INotationMidiInputPtr NotationActionController::currentNotationMidiInput() const
return notation->midiInput();
}

mu::engraving::Score* NotationActionController::currentNotationScore() const
{
return currentNotationElements() ? currentNotationElements()->msScore() : nullptr;
}

INotationStylePtr NotationActionController::currentNotationStyle() const
{
auto notation = currentNotation();
Expand Down Expand Up @@ -751,7 +756,7 @@ void NotationActionController::padNote(const Pad& pad)
startNoteInputIfNeed();

noteInput->padNote(pad);
if (currentNotationElements()->msScore()->inputState().usingNoteEntryMethod(engraving::NoteEntryMethod::RHYTHM)) {
if (currentNotationScore()->inputState().usingNoteEntryMethod(engraving::NoteEntryMethod::RHYTHM)) {
playSelectedElement();
}
}
Expand Down Expand Up @@ -968,7 +973,9 @@ void NotationActionController::move(MoveDirection direction, bool quickly)
return;
}

if (interaction->selection()->isNone()) {
const bool previousSelectionExists = currentNotationScore() && currentNotationScore()->selection().currentCR();
if (interaction->selection()->isNone() && previousSelectionExists) {
// Try to restore the previous selection...
interaction->moveSelection(direction, MoveSelectionType::EngravingItem);
playSelectedElement(true);
return;
Expand All @@ -991,6 +998,8 @@ void NotationActionController::move(MoveDirection direction, bool quickly)
}
interaction->moveSelection(direction, MoveSelectionType::String);
return;
} else if (interaction->selection()->isNone()) {
interaction->selectFirstElement(false);
} else {
interaction->movePitch(direction, quickly ? PitchMode::OCTAVE : PitchMode::CHROMATIC);
}
Expand Down Expand Up @@ -1038,6 +1047,9 @@ void NotationActionController::move(MoveDirection direction, bool quickly)
if (selectedElement && selectedElement->isTextBase()) {
interaction->nudge(direction, quickly);
} else {
if (interaction->selection()->isNone()) {
interaction->selectFirstElement(false);
}
interaction->moveSelection(direction, quickly ? MoveSelectionType::Measure : MoveSelectionType::Chord);
playChord = true;
}
Expand Down Expand Up @@ -1231,7 +1243,7 @@ void NotationActionController::addFret(int num)
}

interaction->addFret(num);
playSelectedElement(currentNotationElements()->msScore()->playChord());
playSelectedElement(currentNotationScore()->playChord());
}

void NotationActionController::insertClef(mu::engraving::ClefType type)
Expand Down Expand Up @@ -1991,9 +2003,8 @@ void NotationActionController::playSelectedElement(bool playChord)

playbackController()->playElements({ element });

mu::engraving::Score* score = currentNotationElements()->msScore();
score->setPlayChord(false);
score->setPlayNote(false);
currentNotationScore()->setPlayChord(false);
currentNotationScore()->setPlayNote(false);
}

void NotationActionController::startNoteInputIfNeed()
Expand Down Expand Up @@ -2092,7 +2103,7 @@ bool NotationActionController::isStandardStaff() const

bool NotationActionController::isTablatureStaff() const
{
return isNotEditingElement() && currentNotationElements()->msScore()->inputState().staffGroup() == mu::engraving::StaffGroup::TAB;
return isNotEditingElement() && currentNotationScore()->inputState().staffGroup() == mu::engraving::StaffGroup::TAB;
}

bool NotationActionController::isEditingElement() const
Expand Down
2 changes: 2 additions & 0 deletions src/notation/internal/notationactioncontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class NotationActionController : public muse::actions::Actionable, public muse::
INotationUndoStackPtr currentNotationUndoStack() const;
INotationMidiInputPtr currentNotationMidiInput() const;

mu::engraving::Score* currentNotationScore() const;

void toggleNoteInput();
void toggleNoteInputMethod(NoteInputMethod method);
void toggleNoteInputInsert();
Expand Down

0 comments on commit fda3727

Please sign in to comment.