Skip to content

Commit

Permalink
NoteEntryMethod enum class for InputState
Browse files Browse the repository at this point in the history
  • Loading branch information
shoogle committed Aug 8, 2016
1 parent de9c2b5 commit 2d11c86
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
2 changes: 0 additions & 2 deletions libmscore/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2446,8 +2446,6 @@ void Score::cmd(const QAction* a)
changeAccidental(AccidentalType::FLAT);
else if (cmd == "flat2")
changeAccidental(AccidentalType::FLAT2);
else if (cmd == "note-input-repitch")
_is.setRepitchMode(a->isChecked());
else if (cmd == "flip")
cmdFlip();
else if (cmd == "stretch+")
Expand Down
12 changes: 6 additions & 6 deletions libmscore/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ void Score::cmdAddPitch(int step, bool addFlag, bool insert)
ClefType clef = staff(pos.staffIdx)->clef(pos.segment->tick());
pos.line = relStep(step, clef);

if (inputState().repitchMode())
if (inputState().usingNoteEntryMethod(NoteEntryMethod::REPITCH))
repitchNote(pos, !addFlag);
else
putNote(pos, !addFlag, insert);
Expand Down Expand Up @@ -1065,7 +1065,7 @@ Note* Score::addPitch(NoteVal& nval, bool addFlag)
if (!_is.cr())
return 0;
Fraction duration;
if (_is.repitchMode()) {
if (_is.usingNoteEntryMethod(NoteEntryMethod::REPITCH)) {
duration = _is.cr()->duration();
}
else {
Expand All @@ -1074,7 +1074,7 @@ Note* Score::addPitch(NoteVal& nval, bool addFlag)
Note* note = 0;
Note* firstTiedNote = 0;
Note* lastTiedNote = 0;
if (_is.repitchMode() && _is.cr()->isChord()) {
if (_is.usingNoteEntryMethod(NoteEntryMethod::REPITCH) && _is.cr()->isChord()) {
// repitch mode for MIDI input (where we are given a pitch) is handled here
// for keyboard input (where we are given a staff position), there is a separate function Score::repitchNote()
// the code is similar enough that it could possibly be refactored
Expand Down Expand Up @@ -1133,7 +1133,7 @@ Note* Score::addPitch(NoteVal& nval, bool addFlag)
}
select(lastTiedNote);
}
else if (!_is.repitchMode()) {
else if (!_is.usingNoteEntryMethod(NoteEntryMethod::REPITCH)) {
Segment* seg = setNoteRest(_is.segment(), track, nval, duration, stemDirection);
if (seg) {
note = toChord(seg->element(track))->upNote();
Expand Down Expand Up @@ -1164,7 +1164,7 @@ Note* Score::addPitch(NoteVal& nval, bool addFlag)
else
qDebug("addPitch: cannot find slur note");
}
if (_is.repitchMode()) {
if (_is.usingNoteEntryMethod(NoteEntryMethod::REPITCH)) {
// move cursor to next note, but skip tied notes (they were already repitched above)
ChordRest* next = lastTiedNote ? nextChordRest(lastTiedNote->chord()) : nextChordRest(_is.cr());
while (next && !next->isChord())
Expand All @@ -1189,7 +1189,7 @@ void Score::putNote(const QPointF& pos, bool replace, bool insert)
qDebug("cannot put note here, get position failed");
return;
}
if (inputState().repitchMode())
if (inputState().usingNoteEntryMethod(NoteEntryMethod::REPITCH))
repitchNote(p, replace);
else
putNote(p, replace, insert);
Expand Down
17 changes: 13 additions & 4 deletions libmscore/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ class Drumset;
class Segment;
class Score;

//---------------------------------------------------------
// NoteEntryMethod
//---------------------------------------------------------

enum class NoteEntryMethod : char {
STEPTIME, REPITCH, RHYTHM, REALTIME_AUTO, REALTIME_MANUAL
};

//---------------------------------------------------------
// InputState
//---------------------------------------------------------
Expand All @@ -39,11 +47,11 @@ class InputState {
Segment* _lastSegment { 0 };
Segment* _segment { 0 }; // current segment
int _string { VISUAL_STRING_NONE }; // visual string selected for input (TAB staves only)
bool _repitchMode { false };
bool _rest { false }; // rest mode
NoteType _noteType { NoteType::NORMAL };
Beam::Mode _beamMode { Beam::Mode::AUTO };
bool _noteEntryMode { false };
NoteEntryMethod _noteEntryMethod { NoteEntryMethod::STEPTIME };
Slur* _slur { 0 };

Segment* nextInputPos() const;
Expand Down Expand Up @@ -79,9 +87,6 @@ class InputState {
int string() const { return _string; }
void setString(int val) { _string = val; }

bool repitchMode() const { return _repitchMode; }
void setRepitchMode(bool val) { _repitchMode = val; }

StaffGroup staffGroup() const;

bool rest() const { return _rest; }
Expand All @@ -96,6 +101,10 @@ class InputState {
bool noteEntryMode() const { return _noteEntryMode; }
void setNoteEntryMode(bool v) { _noteEntryMode = v; }

NoteEntryMethod noteEntryMethod() const { return _noteEntryMethod; }
void setNoteEntryMethod(NoteEntryMethod m) { _noteEntryMethod = m; }
bool usingNoteEntryMethod(NoteEntryMethod m) const { return m == noteEntryMethod(); }

Slur* slur() const { return _slur; }
void setSlur(Slur* s) { _slur = s; }

Expand Down
3 changes: 3 additions & 0 deletions libmscore/score.h
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,9 @@ class Score : public QObject, public ScoreElement {

bool noteEntryMode() const { return inputState().noteEntryMode(); }
void setNoteEntryMode(bool val) { inputState().setNoteEntryMode(val); }
NoteEntryMethod noteEntryMethod() const { return inputState().noteEntryMethod(); }
void setNoteEntryMethod(NoteEntryMethod m) { inputState().setNoteEntryMethod(m); }
bool usingNoteEntryMethod(NoteEntryMethod m) { return inputState().usingNoteEntryMethod(m); }
int inputPos() const;
int inputTrack() const { return inputState().track(); }
const InputState& inputState() const { return _is; }
Expand Down
5 changes: 5 additions & 0 deletions mscore/musescore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3081,22 +3081,27 @@ void MuseScore::changeState(ScoreState val)
case STATE_NOTE_ENTRY_STAFF_PITCHED:
if (getAction("note-input-repitch")->isChecked()) {
showModeText(tr("Repitch input mode"));
cs->setNoteEntryMethod(NoteEntryMethod::REPITCH);
val = STATE_NOTE_ENTRY_METHOD_REPITCH;
}
else if (getAction("note-input-rhythm")->isChecked()) {
showModeText(tr("Rhythm input mode"));
cs->setNoteEntryMethod(NoteEntryMethod::RHYTHM);
val = STATE_NOTE_ENTRY_METHOD_RHYTHM;
}
else if (getAction("note-input-realtime-auto")->isChecked()) {
showModeText(tr("Realtime (automatic) note input mode"));
cs->setNoteEntryMethod(NoteEntryMethod::REALTIME_AUTO);
val = STATE_NOTE_ENTRY_METHOD_REALTIME_AUTO;
}
else if (getAction("note-input-realtime-manual")->isChecked()) {
showModeText(tr("Realtime (manual) note input mode"));
cs->setNoteEntryMethod(NoteEntryMethod::REALTIME_MANUAL);
val = STATE_NOTE_ENTRY_METHOD_REALTIME_MANUAL;
}
else {
showModeText(tr("Steptime note input mode"));
cs->setNoteEntryMethod(NoteEntryMethod::STEPTIME);
val = STATE_NOTE_ENTRY_METHOD_STEPTIME;
}
break;
Expand Down

0 comments on commit 2d11c86

Please sign in to comment.