Skip to content

Commit

Permalink
Proposed fix #297458: implement "apply input state" command
Browse files Browse the repository at this point in the history
Backport of musescore#5505
  • Loading branch information
MarcSabatella authored and Jojo-Schmitz committed Aug 16, 2023
1 parent 738ad58 commit 1971a5b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
42 changes: 42 additions & 0 deletions libmscore/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4161,6 +4161,47 @@ void Score::cmdToggleAutoplace(bool all)
}
}

// cmdApplyInputState
//---------------------------------------------------------

//---------------------------------------------------------
void Score::cmdApplyInputState()
{
if (!noteEntryMode())
return;

// get current note/rest
Element* e = selection().element();
if (!e)
return;
Note* n = nullptr;
ChordRest* cr = nullptr;
if (e->isNote()) {
n = toNote(e);
cr = n->chord();
}
else if (e->isRest()) {
cr = toRest(e);
}
if (!cr)
return;

// apply accidental state
AccidentalType acc = _is.accidentalType();
if (acc != AccidentalType::NONE && e->isNote()) {
Note* n = toNote(e);
n->setAccidentalType(acc);
_is.setAccidentalType(AccidentalType::NONE);
}

// apply duration
TDuration d = _is.duration();
if (cr->durationType() != d) {
changeCRlen(cr, d);
_is.moveToNextInputPos();
}
}

//---------------------------------------------------------
// cmd
//---------------------------------------------------------
Expand Down Expand Up @@ -4338,6 +4379,7 @@ void Score::cmd(const QAction* a, EditData& ed)
{ "relayout", [](Score* cs, EditData&){ cs->cmdRelayout(); }},
{ "toggle-autoplace", [](Score* cs, EditData&){ cs->cmdToggleAutoplace(false); }},
{ "autoplace-enabled", [](Score* cs, EditData&){ cs->cmdToggleAutoplace(true); }},
{ "apply-input-state", [](Score* cs, EditData&){ cs->cmdApplyInputState(); }},
};

for (const auto& c : cmdList) {
Expand Down
1 change: 1 addition & 0 deletions libmscore/score.h
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ class Score : public QObject, public ScoreElement {

void cmdRelayout();
void cmdToggleAutoplace(bool all);
void cmdApplyInputState();

bool playNote() const { return _updateState._playNote; }
void setPlayNote(bool v) { _updateState._playNote = v; }
Expand Down
7 changes: 7 additions & 0 deletions mscore/shortcut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3971,6 +3971,13 @@ Shortcut Shortcut::_sc[] = {
Icons::bug_ICON,
Qt::ApplicationShortcut
},
{
MsWidget::SCORE_TAB,
STATE_NOTE_ENTRY,
"apply-input-state",
QT_TRANSLATE_NOOP("action","Apply Input State"),
QT_TRANSLATE_NOOP("action","Apply input state")
},
{
MsWidget::MAIN_WINDOW,
STATE_ALL,
Expand Down

0 comments on commit 1971a5b

Please sign in to comment.