1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2011-2013 Werner Schweer and others
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2
9 // as published by the Free Software Foundation and appearing in
10 // the file LICENSE.GPL
11 //=============================================================================
12
13 #ifndef __MSCORE_H__
14 #define __MSCORE_H__
15
16 #include "config.h"
17 #include "style.h"
18
19 namespace Ms {
20
21 #define MSC_VERSION "3.02"
22 static constexpr int MSCVERSION = 302;
23
24 // History:
25 // 1.3 added staff->_barLineSpan
26 // 1.4 (Version 0.9)
27 // 1.5 save xoff/yoff in mm instead of pixel
28 // 1.6 save harmony base/root as tpc value
29 // 1.7 invert semantic of page fill limit
30 // 1.8 slur id, slur anchor in in Note
31 // 1.9 image size stored in mm instead of pixel (Versions 0.9.2 -0.9.3)
32 // 1.10 TextLine properties changed (Version 0.9.4)
33 // 1.11 Instrument name in part saved as TextC (Version 0.9.5)
34 // 1.12 use durationType, remove tickLen
35 // 1.13 Clefs: userOffset is not (mis)used for vertical layout position
36 // 1.14 save user modified beam position as spatium value (Versions 0.9.6 - 1.3)
37
38 // 1.15 save timesig inline; Lyrics "endTick" replaced by "ticks"
39 // 1.16 spanners (hairpin, trill etc.) are now inline and have no ticks anymore
40 // 1.17 new <Score> toplevel structure to support linked parts (excerpts)
41 // 1.18 save lyrics as subtype to chord/rest to allow them associated with
42 // grace notes
43 // 1.19 replace text style numbers by text style names; box margins are now
44 // used
45 // 1.20 instrument names are saved as html again
46 // 1.21 no cleflist anymore
47 // 1.22 timesig changed
48 // 1.23 measure property for actual length
49 // 1.24 default image size is spatium dependent
50 // - symbol numbers in TextLine() replaced by symbol names
51 // TextStyle: frameWidth, paddingWidth are now in Spatium units (instead of mm)
52
53 // 2.00 (Version 2.0)
54 // 2.01 save SlurSegment position relative to staff
55 // 2.02 save instrumentId, note slashes
56 // 2.03 save Box topGap, bottomGap in spatium units
57 // 2.04 added hideSystemBarLine flag to Staff
58 // 2.05 breath segment changed to use tick of following chord rather than preceding chord
59 // 2.06 Glissando moved from final chord to start note (Version 2.0.x)
60 //
61 // 2.07 irregular, breakMMrest, more style options, system divider, bass string for tab (3.0)
62
63 // 3.00 (Version 3.0 alpha)
64 // 3.01 -
65 // 3.02 Engraving improvements for 3.6
66
67
68 class MStyle;
69 class Sequencer;
70
71 enum class HairpinType : signed char;
72
73 #ifndef VOICES
74 #define VOICES 4
75 #endif
76
staff2track(int staffIdx)77 inline int staff2track(int staffIdx) { return staffIdx << 2; }
track2staff(int voice)78 inline int track2staff(int voice) { return voice >> 2; }
track2voice(int track)79 inline int track2voice(int track) { return track & 3; }
trackZeroVoice(int track)80 inline int trackZeroVoice(int track) { return track & ~3; }
81
82 static const int MAX_TAGS = 32;
83
84 static const int MAX_HEADERS = 3;
85 static const int MAX_FOOTERS = 3;
86
87 static constexpr qreal INCH = 25.4;
88 static constexpr qreal PPI = 72.0; // printer points per inch
89 static constexpr qreal DPI_F = 5;
90 static constexpr qreal DPI = 72.0 * DPI_F;
91 static constexpr qreal SPATIUM20 = 5.0 * (DPI / 72.0);
92 static constexpr qreal DPMM = DPI / INCH;
93
94 static constexpr int MAX_STAVES = 4;
95
96 static const int SHADOW_NOTE_LIGHT = 135;
97
98 static const char mimeSymbolFormat[] = "application/musescore/symbol";
99 static const char mimeSymbolListFormat[] = "application/musescore/symbollist";
100 static const char mimeStaffListFormat[] = "application/musescore/stafflist";
101
102 static const int VISUAL_STRING_NONE = -100; // no ordinal for the visual repres. of string (topmost in TAB
103 // varies according to visual order and presence of bass strings)
104 static const int STRING_NONE = -1; // no ordinal for a physical string (0 = topmost in instrument)
105 static const int FRET_NONE = -1; // no ordinal for a fret
106
107 //---------------------------------------------------------
108 // BracketType
109 // System Brackets
110 //---------------------------------------------------------
111
112 enum class BracketType : signed char {
113 NORMAL, BRACE, SQUARE, LINE, NO_BRACKET = -1
114 };
115
116 //---------------------------------------------------------
117 // PlaceText
118 //---------------------------------------------------------
119
120 enum class PlaceText : char {
121 AUTO, ABOVE, BELOW, LEFT
122 };
123
124 //---------------------------------------------------------
125 // TransposeDirection
126 //---------------------------------------------------------
127
128 enum class TransposeDirection : char {
129 UP, DOWN, CLOSEST
130 };
131
132 //---------------------------------------------------------
133 // TransposeMode
134 //---------------------------------------------------------
135
136 enum class TransposeMode : char {
137 TO_KEY, BY_INTERVAL, DIATONICALLY
138 };
139
140 //---------------------------------------------------------
141 // SelectType
142 //---------------------------------------------------------
143
144 enum class SelectType : char {
145 SINGLE, RANGE, ADD
146 };
147
148 //---------------------------------------------------------
149 // AccidentalVal
150 //---------------------------------------------------------
151
152 enum class AccidentalVal : signed char {
153 SHARP3 = 3,
154 SHARP2 = 2,
155 SHARP = 1,
156 NATURAL = 0,
157 FLAT = -1,
158 FLAT2 = -2,
159 FLAT3 = -3,
160 MIN = FLAT3,
161 MAX = SHARP3
162 };
163
164 //---------------------------------------------------------
165 // KeySigNaturals (positions of naturals in key sig. changes)
166 //---------------------------------------------------------
167
168 enum class KeySigNatural : char {
169 NONE = 0, // no naturals, except for change to CMaj/Amin
170 BEFORE = 1, // naturals before accidentals
171 AFTER = 2 // naturals after accidentals (but always before if going sharps <=> flats)
172 };
173
174 //---------------------------------------------------------
175 // UpDownMode
176 //---------------------------------------------------------
177
178 enum class UpDownMode : char {
179 CHROMATIC, OCTAVE, DIATONIC
180 };
181
182 //---------------------------------------------------------
183 // StaffGroup
184 //---------------------------------------------------------
185
186 enum class StaffGroup : char {
187 STANDARD, PERCUSSION, TAB
188 };
189 const int STAFF_GROUP_MAX = int(StaffGroup::TAB) + 1; // out of enum to avoid compiler complains about not handled switch cases
190
191 //---------------------------------------------------------
192 // BarLineType
193 //---------------------------------------------------------
194
195 enum class BarLineType {
196 NORMAL = 1,
197 SINGLE = BarLineType::NORMAL,
198 DOUBLE = 2,
199 START_REPEAT = 4,
200 LEFT_REPEAT = BarLineType::START_REPEAT,
201 END_REPEAT = 8,
202 RIGHT_REPEAT = BarLineType::END_REPEAT,
203 BROKEN = 0x10,
204 DASHED = BarLineType::BROKEN,
205 END = 0x20,
206 FINAL = BarLineType::END,
207 END_START_REPEAT = 0x40,
208 LEFT_RIGHT_REPEAT= BarLineType::END_START_REPEAT,
209 DOTTED = 0x80,
210 REVERSE_END = 0x100,
211 REVERSE_FINALE = BarLineType::REVERSE_END,
212 HEAVY = 0x200,
213 DOUBLE_HEAVY = 0x400,
214 };
215
216 constexpr BarLineType operator| (BarLineType t1, BarLineType t2) {
217 return static_cast<BarLineType>(static_cast<int>(t1) | static_cast<int>(t2));
218 }
219 constexpr bool operator& (BarLineType t1, BarLineType t2) {
220 return static_cast<int>(t1) & static_cast<int>(t2);
221 }
222
223
224 // Icon() subtypes
225 enum class IconType : signed char {
226 NONE = -1,
227 ACCIACCATURA, APPOGGIATURA, GRACE4, GRACE16, GRACE32,
228 GRACE8_AFTER, GRACE16_AFTER, GRACE32_AFTER,
229 SBEAM, MBEAM, NBEAM, BEAM32, BEAM64, AUTOBEAM,
230 FBEAM1, FBEAM2,
231 VFRAME, HFRAME, TFRAME, FFRAME, MEASURE,
232 BRACKETS, PARENTHESES, BRACES,
233 };
234
235 //---------------------------------------------------------
236 // MScoreError
237 //---------------------------------------------------------
238
239 enum MsError {
240 MS_NO_ERROR,
241 NO_NOTE_SELECTED,
242 NO_CHORD_REST_SELECTED,
243 NO_LYRICS_SELECTED,
244 NO_NOTE_REST_SELECTED,
245 NO_FLIPPABLE_SELECTED,
246 NO_STAFF_SELECTED,
247 NO_NOTE_FIGUREDBASS_SELECTED,
248 CANNOT_INSERT_TUPLET,
249 CANNOT_SPLIT_TUPLET,
250 CANNOT_SPLIT_MEASURE_FIRST_BEAT,
251 CANNOT_SPLIT_MEASURE_TUPLET,
252 NO_DEST,
253 DEST_TUPLET,
254 TUPLET_CROSSES_BAR,
255 DEST_LOCAL_TIME_SIGNATURE,
256 DEST_TREMOLO,
257 NO_MIME,
258 DEST_NO_CR,
259 CANNOT_CHANGE_LOCAL_TIMESIG,
260 };
261
262 /// \cond PLUGIN_API \private \endcond
263 struct MScoreError {
264 MsError no;
265 const char* group;
266 const char* txt;
267 };
268
269 //---------------------------------------------------------
270 // MPaintDevice
271 /// \cond PLUGIN_API \private \endcond
272 //---------------------------------------------------------
273
274 class MPaintDevice : public QPaintDevice {
275
276 protected:
277 virtual int metric(PaintDeviceMetric m) const;
278
279 public:
MPaintDevice()280 MPaintDevice() : QPaintDevice() {}
281 virtual QPaintEngine* paintEngine() const;
~MPaintDevice()282 virtual ~MPaintDevice() {}
283 };
284
285 //---------------------------------------------------------
286 // MScore
287 // MuseScore application object
288 //---------------------------------------------------------
289
290 class MScore {
291 Q_GADGET
292 static MStyle _baseStyle; // buildin initial style
293 static MStyle _defaultStyle; // buildin modified by preferences
294 static MStyle* _defaultStyleForParts;
295
296 static QString _globalShare;
297 static int _hRaster, _vRaster;
298 static bool _verticalOrientation;
299
300 static MPaintDevice* _paintDevice;
301
302 public:
303 enum class DirectionH : char { /**.\{*/ AUTO, LEFT, RIGHT /**\}*/ };
304 enum class OrnamentStyle : char { /**.\{*/ DEFAULT, BAROQUE /**\}*/ };
305 Q_ENUM(DirectionH);
306 Q_ENUM(OrnamentStyle);
307
308 static MsError _error;
309 static std::vector<MScoreError> errorList;
310
311 static void init();
312
baseStyle()313 static MStyle& baseStyle() { return _baseStyle; }
setBaseStyle(const MStyle & style)314 static void setBaseStyle(const MStyle& style) { _baseStyle = style; }
defaultStyle()315 static MStyle& defaultStyle() { return _defaultStyle; }
defaultStyleForParts()316 static const MStyle* defaultStyleForParts() { return _defaultStyleForParts; }
317
318 static bool readDefaultStyle(QString file);
setDefaultStyle(const MStyle & s)319 static void setDefaultStyle(const MStyle& s) { _defaultStyle = s; }
320 static void defaultStyleForPartsHasChanged();
321
globalShare()322 static const QString& globalShare() { return _globalShare; }
hRaster()323 static qreal hRaster() { return _hRaster; }
vRaster()324 static qreal vRaster() { return _vRaster; }
setHRaster(int val)325 static void setHRaster(int val) { _hRaster = val; }
setVRaster(int val)326 static void setVRaster(int val) { _vRaster = val; }
setNudgeStep(qreal val)327 static void setNudgeStep(qreal val) { nudgeStep = val; }
setNudgeStep10(qreal val)328 static void setNudgeStep10(qreal val) { nudgeStep10 = val; }
setNudgeStep50(qreal val)329 static void setNudgeStep50(qreal val) { nudgeStep50 = val; }
330
verticalOrientation()331 static bool verticalOrientation() { return _verticalOrientation; }
setVerticalOrientation(bool val)332 static void setVerticalOrientation(bool val) { _verticalOrientation = val; }
333
334 static QColor selectColor[VOICES];
335 static QColor defaultColor;
336 static QColor dropColor;
337 static QColor layoutBreakColor;
338 static QColor frameMarginColor;
339 static QColor bgColor;
340 static bool warnPitchRange;
341 static int pedalEventsMinTicks;
342
343 static bool harmonyPlayDisableCompatibility;
344 static bool harmonyPlayDisableNew;
345 static bool playRepeats;
346 static bool panPlayback;
347 static int playbackSpeedIncrement;
348 static qreal nudgeStep;
349 static qreal nudgeStep10;
350 static qreal nudgeStep50;
351 static int defaultPlayDuration;
352 static QString lastError;
353
354 // #ifndef NDEBUG
355 static bool noHorizontalStretch;
356 static bool noVerticalStretch;
357 static bool showSegmentShapes;
358 static bool showSkylines;
359 static bool showMeasureShapes;
360 static bool showBoundingRect;
361 static bool showSystemBoundingRect;
362 static bool showCorruptedMeasures;
363 static bool useFallbackFont;
364 // #endif
365 static bool debugMode;
366 static bool testMode;
367
368 static int division;
369 static int sampleRate;
370 static int mtcType;
371 static Sequencer* seq;
372
373 static bool saveTemplateMode;
374 static bool noGui;
375
376 static bool noExcerpts;
377 static bool noImages;
378
379 static bool pdfPrinting;
380 static bool svgPrinting;
381 static double pixelRatio;
382
383 static qreal verticalPageGap;
384 static qreal horizontalPageGapEven;
385 static qreal horizontalPageGapOdd;
386
387 static MPaintDevice* paintDevice();
388
setError(MsError e)389 static void setError(MsError e) { _error = e; }
390 static const char* errorMessage();
391 static const char* errorGroup();
392 };
393
394 //---------------------------------------------------------
395 // center
396 //---------------------------------------------------------
397
center(qreal x1,qreal x2)398 inline static qreal center(qreal x1, qreal x2)
399 {
400 return (x1 + (x2 - x1) * .5);
401 }
402
403 //---------------------------------------------------------
404 // limit
405 //---------------------------------------------------------
406
limit(int val,int min,int max)407 inline static int limit(int val, int min, int max)
408 {
409 if (val > max)
410 return max;
411 if (val < min)
412 return min;
413 return val;
414 }
415 } // namespace Ms
416
417 Q_DECLARE_METATYPE(Ms::BarLineType);
418
419 #endif
420