Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 :
23 : #ifndef MU_ENGRAVING_INPUT_H
24 : #define MU_ENGRAVING_INPUT_H
25 :
26 : #include <set>
27 :
28 : #include "accidental.h"
29 : #include "chord.h"
30 : #include "durationtype.h"
31 : #include "noteval.h"
32 :
33 : #include "../types/types.h"
34 :
35 : namespace mu::engraving {
36 : class ChordRest;
37 : class Drumset;
38 : class EngravingItem;
39 : class Note;
40 : class Score;
41 : class Segment;
42 : class Selection;
43 : class Slur;
44 : class Staff;
45 :
46 : // no ordinal for the visual repres. of string
47 : // (topmost in TAB varies according to visual order and presence of bass strings)
48 : static constexpr int VISUAL_INVALID_STRING_INDEX = -100;
49 :
50 : //---------------------------------------------------------
51 : // NoteEntryMethod
52 : //---------------------------------------------------------
53 :
54 : enum class NoteEntryMethod : char {
55 : UNKNOWN, DEFAULT, BY_NOTE_NAME, BY_DURATION, REPITCH, RHYTHM, REALTIME_AUTO, REALTIME_MANUAL, TIMEWISE
56 : };
57 :
58 : //---------------------------------------------------------
59 : // InputState
60 : //---------------------------------------------------------
61 :
62 : class InputState
63 : {
64 : public:
65 : bool isValid() const;
66 :
67 : ChordRest* cr() const;
68 :
69 : Fraction tick() const;
70 :
71 129 : void setDuration(const TDuration& d) { m_duration = d; }
72 210 : TDuration duration() const { return m_duration; }
73 : void setDots(int n);
74 0 : Fraction ticks() const { return m_duration.ticks(); }
75 :
76 2198 : Segment* segment() const { return m_segment; }
77 : void setSegment(Segment* s);
78 :
79 24 : Segment* lastSegment() const { return m_lastSegment; }
80 1431 : void setLastSegment(Segment* s) { m_lastSegment = s; }
81 :
82 : Staff* staff() const;
83 : staff_idx_t staffIdx() const;
84 :
85 : Drumset* drumset() const;
86 :
87 0 : int drumNote() const { return m_drumNote; }
88 30 : void setDrumNote(int v) { m_drumNote = v; }
89 :
90 : // Used in the input-by-duration mode
91 0 : const NoteValList& notes() const { return m_notes; }
92 4 : void setNotes(const NoteValList& v) { m_notes = v; }
93 :
94 49 : voice_idx_t voice() const { return m_track == muse::nidx ? 0 : (m_track % MAX_VOICES); }
95 : void setVoice(voice_idx_t v);
96 433 : track_idx_t track() const { return m_track; }
97 1593 : void setTrack(track_idx_t v) { m_prevTrack = m_track; m_track = v; }
98 0 : track_idx_t prevTrack() const { return m_prevTrack; }
99 :
100 1 : int string() const { return m_string; }
101 1 : void setString(int val) { m_string = val; }
102 :
103 : StaffGroup staffGroup() const;
104 :
105 29 : bool rest() const { return m_rest; }
106 29 : void setRest(bool v) { m_rest = v; }
107 :
108 : NoteType noteType() const { return m_noteType; }
109 2 : void setNoteType(NoteType t) { m_noteType = t; }
110 :
111 : BeamMode beamMode() const { return m_beamMode; }
112 2 : void setBeamMode(BeamMode m) { m_beamMode = m; }
113 :
114 291 : bool noteEntryMode() const { return m_noteEntryMode; }
115 32 : void setNoteEntryMode(bool v) { m_noteEntryMode = v; }
116 :
117 783 : NoteEntryMethod noteEntryMethod() const { return m_noteEntryMethod; }
118 15 : void setNoteEntryMethod(NoteEntryMethod m) { m_noteEntryMethod = m; }
119 636 : bool usingNoteEntryMethod(NoteEntryMethod m) const { return m == noteEntryMethod(); }
120 :
121 121 : AccidentalType accidentalType() const { return m_accidentalType; }
122 109 : void setAccidentalType(AccidentalType val) { m_accidentalType = val; }
123 :
124 140 : const std::set<SymId>& articulationIds() const { return m_articulationIds; }
125 4 : void setArticulationIds(const std::set<SymId>& ids) { m_articulationIds = ids; }
126 :
127 1308 : Slur* slur() const { return m_slur; }
128 0 : void setSlur(Slur* s) { m_slur = s; }
129 :
130 : void update(Selection& selection);
131 : void moveInputPos(EngravingItem* e);
132 : void moveToNextInputPos();
133 :
134 150 : bool beyondScore() const { return m_beyondScore; }
135 4 : void setBeyondScore(bool val) { m_beyondScore = val; }
136 :
137 : // TODO: unify with Selection::cr()?
138 : static Note* note(EngravingItem*);
139 : static ChordRest* chordRest(EngravingItem*);
140 :
141 : private:
142 :
143 : Segment* nextInputPos() const;
144 :
145 : track_idx_t m_track = 0;
146 : track_idx_t m_prevTrack = 0; // used for navigation
147 :
148 : int m_drumNote = -1;
149 : int m_string = VISUAL_INVALID_STRING_INDEX; // visual string selected for input (TAB staves only)
150 :
151 : NoteValList m_notes;
152 :
153 : Segment* m_lastSegment = nullptr;
154 : Segment* m_segment = nullptr; // current segment
155 :
156 : bool m_noteEntryMode = false;
157 : NoteEntryMethod m_noteEntryMethod = NoteEntryMethod::BY_NOTE_NAME;
158 :
159 : TDuration m_duration = DurationType::V_INVALID; // currently duration
160 : bool m_rest = false; // rest mode
161 :
162 : NoteType m_noteType = NoteType::NORMAL;
163 : BeamMode m_beamMode = BeamMode::AUTO;
164 :
165 : AccidentalType m_accidentalType = AccidentalType::NONE;
166 : Slur* m_slur = nullptr;
167 :
168 : std::set<SymId> m_articulationIds;
169 :
170 : bool m_beyondScore = false;
171 : };
172 : } // namespace mu::engraving
173 : #endif
|