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 : #pragma once
24 :
25 : #include <QPixmap>
26 : #include <QDate>
27 : #include <string>
28 :
29 : #include "global/containers.h"
30 :
31 : #include "engraving/types/constants.h"
32 : #include "engraving/dom/articulation.h"
33 : #include "engraving/dom/chord.h"
34 : #include "engraving/dom/durationtype.h"
35 : #include "engraving/dom/engravingitem.h"
36 : #include "engraving/dom/guitarbend.h"
37 : #include "engraving/dom/hairpin.h"
38 : #include "engraving/dom/hook.h"
39 : #include "engraving/dom/key.h"
40 : #include "engraving/dom/measure.h"
41 : #include "engraving/dom/mscore.h"
42 : #include "engraving/dom/note.h"
43 : #include "engraving/dom/ottava.h"
44 : #include "engraving/dom/page.h"
45 : #include "engraving/dom/rest.h"
46 : #include "engraving/dom/slur.h"
47 : #include "engraving/dom/stem.h"
48 : #include "engraving/dom/system.h"
49 : #include "engraving/dom/timesig.h"
50 : #include "engraving/types/types.h"
51 :
52 : namespace mu::notation {
53 : using Page = mu::engraving::Page;
54 : using System = mu::engraving::System;
55 : using EngravingItem = mu::engraving::EngravingItem;
56 : using ElementType = mu::engraving::ElementType;
57 : using Note = mu::engraving::Note;
58 : using Measure = mu::engraving::Measure;
59 : using DurationType = mu::engraving::DurationType;
60 : using Duration = mu::engraving::TDuration;
61 : using SelectType = mu::engraving::SelectType;
62 : using SymbolId = mu::engraving::SymId;
63 : using Key = mu::engraving::Key;
64 : using KeyMode = mu::engraving::KeyMode;
65 : using TimeSigType = mu::engraving::TimeSigType;
66 : using TimeSignature = mu::engraving::TimeSig;
67 : using NoteHead = mu::engraving::NoteHead;
68 : using TransposeMode = mu::engraving::TransposeMode;
69 : using TransposeDirection = mu::engraving::TransposeDirection;
70 : using Fraction = mu::engraving::Fraction;
71 : using Chord = mu::engraving::Chord;
72 : using ChordRest = mu::engraving::ChordRest;
73 : using Articulation = mu::engraving::Articulation;
74 : using SlurSegment = mu::engraving::SlurSegment;
75 : using Rest = mu::engraving::Rest;
76 : using Stem = mu::engraving::Stem;
77 : using Hook = mu::engraving::Hook;
78 : using Fraction = mu::engraving::Fraction;
79 : using AccidentalType = mu::engraving::AccidentalType;
80 : using OttavaType = mu::engraving::OttavaType;
81 : using HairpinType = mu::engraving::HairpinType;
82 : using TextBase = mu::engraving::TextBase;
83 : using GraceNoteType = mu::engraving::NoteType;
84 : using BeamMode = mu::engraving::BeamMode;
85 : using LayoutBreakType = mu::engraving::LayoutBreakType;
86 : using Interval = mu::engraving::Interval;
87 : using BracketType = mu::engraving::BracketType;
88 : using Segment = mu::engraving::Segment;
89 : using TextStyleType = mu::engraving::TextStyleType;
90 : using PageList = std::vector<Page*>;
91 : using voice_idx_t = mu::engraving::voice_idx_t;
92 : using track_idx_t = mu::engraving::track_idx_t;
93 : using staff_idx_t = mu::engraving::staff_idx_t;
94 : using GuitarBendType = mu::engraving::GuitarBendType;
95 : using Pid = mu::engraving::Pid;
96 : using VoiceAssignment = mu::engraving::VoiceAssignment;
97 : using TupletNumberType = mu::engraving::TupletNumberType;
98 : using TupletBracketType = mu::engraving::TupletBracketType;
99 : using TupletSelectedDuration = mu::engraving::TupletSelectedDuration;
100 : using OrnamentType = mu::engraving::OrnamentType;
101 :
102 : enum class DragMode : unsigned char
103 : {
104 : BothXY = 0,
105 : OnlyX,
106 : OnlyY
107 : };
108 :
109 : enum class MoveDirection : unsigned char
110 : {
111 : Undefined = 0,
112 : Left,
113 : Right,
114 : Up,
115 : Down
116 : };
117 :
118 : enum class SelectionTarget : unsigned char
119 : {
120 : Undefined = 0,
121 : FirstItem,
122 : LastItem,
123 : NextItem,
124 : PrevItem,
125 : NextSegment,
126 : PrevSegment,
127 : NextChord,
128 : PrevChord,
129 : NextMeasure,
130 : PrevMeasure,
131 : NextTrack,
132 : PrevTrack,
133 : NextFrame,
134 : PrevFrame,
135 : NextSystem,
136 : PrevSystem,
137 : AboveStaff,
138 : BelowStaff,
139 : UpNoteInChord,
140 : DownNoteInChord,
141 : TopNoteInChord,
142 : BottomNoteInChord,
143 : TopStaff,
144 : EmptyTrailingMeasure,
145 : Similar,
146 : SimilarInStaff,
147 : SimilarInRange,
148 : NotesInChord,
149 : All,
150 : Section,
151 : // Expand to ...
152 : BeginSystem,
153 : EndSystem,
154 : BeginScore,
155 : EndScore,
156 : };
157 :
158 : enum PlayMode {
159 : NoPlay, PlayNote, PlayChord
160 : };
161 :
162 : enum class MoveSelectionType : unsigned char
163 : {
164 : Undefined = 0,
165 : EngravingItem,
166 : Chord,
167 : Measure,
168 : Track,
169 : Frame,
170 : System,
171 : String // TAB Staff
172 : };
173 :
174 : enum class AddRemoveSystemLockType : signed char
175 : {
176 : AfterEachSystem = -1,
177 : None = 0,
178 : MeasuresInterval
179 : };
180 :
181 : enum class BoxType : unsigned char
182 : {
183 : Unknown,
184 : Vertical,
185 : Horizontal,
186 : Measure,
187 : Text,
188 : Fret
189 : };
190 :
191 : enum class AddBoxesTarget : unsigned char {
192 : AfterSelection,
193 : BeforeSelection,
194 : AtStartOfScore,
195 : AtEndOfScore
196 : };
197 :
198 : enum class NoteName : unsigned char
199 : {
200 : C = 0,
201 : D,
202 : E,
203 : F,
204 : G,
205 : A,
206 : B
207 : };
208 :
209 : enum class PastingType : unsigned char {
210 : Default,
211 : Half,
212 : Double,
213 : Special
214 : };
215 :
216 : struct FilterElementsOptions
217 : {
218 : ElementType elementType = ElementType::INVALID;
219 : int staffStart = -1;
220 : int staffEnd = -1;
221 : int voice = -1;
222 : const mu::engraving::System* system = nullptr;
223 : Fraction durationTicks{ -1, 1 };
224 : Fraction beat{ 0, 0 };
225 : const mu::engraving::Measure* measure = nullptr;
226 :
227 : bool bySubtype = false;
228 : int subtype = -1;
229 :
230 : bool isValid() const
231 : {
232 : return elementType != ElementType::INVALID;
233 : }
234 :
235 0 : virtual ~FilterElementsOptions() = default;
236 : };
237 :
238 : struct FilterNotesOptions : FilterElementsOptions
239 : {
240 : int pitch = -1;
241 : int string = mu::engraving::INVALID_STRING_INDEX;
242 : int tpc = mu::engraving::Tpc::TPC_INVALID;
243 : mu::engraving::NoteHeadGroup notehead = mu::engraving::NoteHeadGroup::HEAD_INVALID;
244 : mu::engraving::TDuration durationType = mu::engraving::TDuration();
245 : mu::engraving::NoteType noteType = mu::engraving::NoteType::INVALID;
246 : };
247 :
248 : struct TransposeOptions
249 : {
250 : TransposeMode mode = TransposeMode::UNKNOWN;
251 : TransposeDirection direction = TransposeDirection::UNKNOWN;
252 : Key key = Key::C;
253 : int interval = 0;
254 : bool needTransposeKeys = false;
255 : bool needTransposeChordNames = false;
256 : bool needTransposeDoubleSharpsFlats = false;
257 : };
258 :
259 : enum class ChangeDurationMode : unsigned char
260 : {
261 : Double,
262 : Halve,
263 : DoubleDotted,
264 : HalveDotted,
265 : };
266 :
267 : enum class ScoreConfigType : unsigned char
268 : {
269 : ShowInvisibleElements,
270 : ShowUnprintableElements,
271 : ShowFrames,
272 : ShowPageMargins,
273 : ShowSoundFlags,
274 : MarkIrregularMeasures
275 : };
276 :
277 : struct ScoreConfig
278 : {
279 : std::map<ScoreConfigType, bool> config = {
280 : { ScoreConfigType::ShowInvisibleElements, false },
281 : { ScoreConfigType::ShowUnprintableElements, false },
282 : { ScoreConfigType::ShowFrames, false },
283 : { ScoreConfigType::ShowPageMargins, false },
284 : { ScoreConfigType::ShowSoundFlags, false },
285 : { ScoreConfigType::MarkIrregularMeasures, false },
286 : };
287 :
288 0 : bool isShown(ScoreConfigType type) const
289 : {
290 0 : auto it = config.find(type);
291 0 : if (it != config.end()) {
292 0 : return it->second;
293 : }
294 0 : return false;
295 : }
296 :
297 0 : void setShown(ScoreConfigType type, bool show)
298 : {
299 0 : config[type] = show;
300 0 : }
301 :
302 0 : bool operator==(const ScoreConfig& other) const
303 : {
304 0 : return config == other.config;
305 : }
306 : };
307 :
308 : enum class BracketsType : unsigned char
309 : {
310 : Brackets,
311 : Braces,
312 : Parentheses
313 : };
314 :
315 : static constexpr int MAX_FRET = 14;
316 :
317 0 : constexpr bool isNotesIntervalValid(int interval)
318 : {
319 0 : return interval >= mu::engraving::MIN_NOTES_INTERVAL && interval <= mu::engraving::MAX_NOTES_INTERVAL
320 0 : && interval != 0 && interval != -1;
321 : }
322 :
323 0 : constexpr bool isVoiceIndexValid(voice_idx_t voiceIndex)
324 : {
325 0 : return voiceIndex < mu::engraving::MAX_VOICES;
326 : }
327 :
328 0 : inline bool isVerticalBoxTextStyle(TextStyleType type)
329 : {
330 : static const std::set<TextStyleType> types {
331 : TextStyleType::TITLE,
332 : TextStyleType::SUBTITLE,
333 : TextStyleType::COMPOSER,
334 : TextStyleType::LYRICIST,
335 : TextStyleType::INSTRUMENT_EXCERPT,
336 0 : };
337 :
338 0 : return muse::contains(types, type);
339 : }
340 :
341 : static const mu::engraving::ElementTypeSet NOTE_REST_TYPES {
342 : mu::engraving::ElementType::NOTE,
343 : mu::engraving::ElementType::REST,
344 : };
345 : }
|