MuseScore  3.4
Music composition and notation
mscore.h
Go to the documentation of this file.
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.01"
22 static constexpr int MSCVERSION = 301;
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 
65 
66 class MStyle;
67 class Sequencer;
68 
69 enum class HairpinType : signed char;
70 
71 #ifndef VOICES
72 #define VOICES 4
73 #endif
74 
75 inline int staff2track(int staffIdx) { return staffIdx << 2; }
76 inline int track2staff(int voice) { return voice >> 2; }
77 inline int track2voice(int track) { return track & 3; }
78 inline int trackZeroVoice(int track) { return track & ~3; }
79 
80 static const int MAX_TAGS = 32;
81 
82 static constexpr qreal INCH = 25.4;
83 static constexpr qreal PPI = 72.0; // printer points per inch
84 static constexpr qreal DPI_F = 5;
85 static constexpr qreal DPI = 72.0 * DPI_F;
86 static constexpr qreal SPATIUM20 = 5.0 * (DPI / 72.0);
87 static constexpr qreal DPMM = DPI / INCH;
88 
89 static constexpr int MAX_STAVES = 4;
90 
91 static const int SHADOW_NOTE_LIGHT = 135;
92 
93 static const char mimeSymbolFormat[] = "application/musescore/symbol";
94 static const char mimeSymbolListFormat[] = "application/musescore/symbollist";
95 static const char mimeStaffListFormat[] = "application/musescore/stafflist";
96 
97 static const int VISUAL_STRING_NONE = -100; // no ordinal for the visual repres. of string (topmost in TAB
98  // varies according to visual order and presence of bass strings)
99 static const int STRING_NONE = -1; // no ordinal for a physical string (0 = topmost in instrument)
100 static const int FRET_NONE = -1; // no ordinal for a fret
101 
102 //---------------------------------------------------------
103 // BracketType
104 // System Brackets
105 //---------------------------------------------------------
106 
107 enum class BracketType : signed char {
109  };
110 
111 //---------------------------------------------------------
112 // PlaceText
113 //---------------------------------------------------------
114 
115 enum class PlaceText : char {
116  AUTO, ABOVE, BELOW, LEFT
117  };
118 
119 //---------------------------------------------------------
120 // TransposeDirection
121 //---------------------------------------------------------
122 
123 enum class TransposeDirection : char {
124  UP, DOWN, CLOSEST
125  };
126 
127 //---------------------------------------------------------
128 // TransposeMode
129 //---------------------------------------------------------
130 
131 enum class TransposeMode : char {
133  };
134 
135 //---------------------------------------------------------
136 // SelectType
137 //---------------------------------------------------------
138 
139 enum class SelectType : char {
140  SINGLE, RANGE, ADD
141  };
142 
143 //---------------------------------------------------------
144 // AccidentalVal
145 //---------------------------------------------------------
146 
147 enum class AccidentalVal : signed char {
148  SHARP2 = 2,
149  SHARP = 1,
150  NATURAL = 0,
151  FLAT = -1,
152  FLAT2 = -2
153  };
154 
155 //---------------------------------------------------------
156 // KeySigNaturals (positions of naturals in key sig. changes)
157 //---------------------------------------------------------
158 
159 enum class KeySigNatural : char {
160  NONE = 0, // no naturals, except for change to CMaj/Amin
161  BEFORE = 1, // naturals before accidentals
162  AFTER = 2 // naturals after accidentals (but always before if going sharps <=> flats)
163  };
164 
165 //---------------------------------------------------------
166 // UpDownMode
167 //---------------------------------------------------------
168 
169 enum class UpDownMode : char {
171  };
172 
173 //---------------------------------------------------------
174 // StaffGroup
175 //---------------------------------------------------------
176 
177 enum class StaffGroup : char {
179  };
180 const int STAFF_GROUP_MAX = int(StaffGroup::TAB) + 1; // out of enum to avoid compiler complains about not handled switch cases
181 
182 enum class NoteHeadScheme : char {
183  HEAD_NORMAL = 0,
186  HEAD_SOLFEGE,
193  };
194 
195 //---------------------------------------------------------
196 // BarLineType
197 //---------------------------------------------------------
198 
199 enum class BarLineType {
200  NORMAL = 1,
201  DOUBLE = 2,
202  START_REPEAT = 4,
203  END_REPEAT = 8,
204  BROKEN = 0x10,
205  END = 0x20,
206  END_START_REPEAT = 0x40,
207  DOTTED = 0x80
208  };
209 
211  return static_cast<BarLineType>(static_cast<int>(t1) | static_cast<int>(t2));
212  }
213 constexpr bool operator& (BarLineType t1, BarLineType t2) {
214  return static_cast<int>(t1) & static_cast<int>(t2);
215  }
216 
217 
218 // Icon() subtypes
219 enum class IconType : signed char {
220  NONE = -1,
224  FBEAM1, FBEAM2,
227  };
228 
229 //---------------------------------------------------------
230 // MScoreError
231 //---------------------------------------------------------
232 
233 enum MsError {
254  };
255 
257 struct MScoreError {
259  const char* group;
260  const char* txt;
261  };
262 
263 //---------------------------------------------------------
264 // MPaintDevice
266 //---------------------------------------------------------
267 
268 class MPaintDevice : public QPaintDevice {
269 
270  protected:
271  virtual int metric(PaintDeviceMetric m) const;
272 
273  public:
274  MPaintDevice() : QPaintDevice() {}
275  virtual QPaintEngine* paintEngine() const;
276  virtual ~MPaintDevice() {}
277  };
278 
279 //---------------------------------------------------------
280 // MScore
281 // MuseScore application object
282 //---------------------------------------------------------
283 
284 class MScore {
285  Q_GADGET
286  static MStyle _baseStyle; // buildin initial style
287  static MStyle _defaultStyle; // buildin modified by preferences
289 
290  static QString _globalShare;
291  static int _hRaster, _vRaster;
292  static bool _verticalOrientation;
293 
295 
296  public:
297  enum class DirectionH : char { AUTO, LEFT, RIGHT };
298  enum class OrnamentStyle : char { DEFAULT, BAROQUE };
299  Q_ENUM(DirectionH);
300  Q_ENUM(OrnamentStyle);
301 
302  static MsError _error;
303  static std::vector<MScoreError> errorList;
304 
305  static void init();
306 
307  static const MStyle& baseStyle() { return _baseStyle; }
308  static MStyle& defaultStyle() { return _defaultStyle; }
309  static const MStyle* defaultStyleForParts() { return _defaultStyleForParts; }
310 
311  static bool readDefaultStyle(QString file);
312  static void setDefaultStyle(const MStyle& s) { _defaultStyle = s; }
313  static void defaultStyleForPartsHasChanged();
314 
315  static const QString& globalShare() { return _globalShare; }
316  static qreal hRaster() { return _hRaster; }
317  static qreal vRaster() { return _vRaster; }
318  static void setHRaster(int val) { _hRaster = val; }
319  static void setVRaster(int val) { _vRaster = val; }
320  static void setNudgeStep(qreal val) { nudgeStep = val; }
321  static void setNudgeStep10(qreal val) { nudgeStep10 = val; }
322  static void setNudgeStep50(qreal val) { nudgeStep50 = val; }
323 
324  static bool verticalOrientation() { return _verticalOrientation; }
325  static void setVerticalOrientation(bool val) { _verticalOrientation = val; }
326 
327  static QColor selectColor[VOICES];
328  static QColor defaultColor;
329  static QColor dropColor;
330  static QColor layoutBreakColor;
331  static QColor frameMarginColor;
332  static QColor bgColor;
333  static bool warnPitchRange;
334 
335  static bool playRepeats;
336  static bool panPlayback;
337  static qreal nudgeStep;
338  static qreal nudgeStep10;
339  static qreal nudgeStep50;
341  static QString lastError;
342 
343 // #ifndef NDEBUG
344  static bool noHorizontalStretch;
345  static bool noVerticalStretch;
346  static bool showSegmentShapes;
347  static bool showSkylines;
348  static bool showMeasureShapes;
349  static bool showBoundingRect;
352  static bool useFallbackFont;
353 // #endif
354  static bool debugMode;
355  static bool testMode;
356 
357  static int division;
358  static int sampleRate;
359  static int mtcType;
360  static Sequencer* seq;
361 
362  static bool saveTemplateMode;
363  static bool noGui;
364 
365  static bool noExcerpts;
366  static bool noImages;
367 
368  static bool pdfPrinting;
369  static bool svgPrinting;
370  static double pixelRatio;
371 
372  static qreal verticalPageGap;
373  static qreal horizontalPageGapEven;
374  static qreal horizontalPageGapOdd;
375 
376  static MPaintDevice* paintDevice();
377 
378  static void setError(MsError e) { _error = e; }
379  static const char* errorMessage();
380  static const char* errorGroup();
381  };
382 
383 //---------------------------------------------------------
384 // center
385 //---------------------------------------------------------
386 
387 inline static qreal center(qreal x1, qreal x2)
388  {
389  return (x1 + (x2 - x1) * .5);
390  }
391 
392 //---------------------------------------------------------
393 // limit
394 //---------------------------------------------------------
395 
396 inline static int limit(int val, int min, int max)
397  {
398  if (val > max)
399  return max;
400  if (val < min)
401  return min;
402  return val;
403  }
404 } // namespace Ms
405 
406 Q_DECLARE_METATYPE(Ms::BarLineType);
407 
408 #endif
DirectionH
Definition: mscore.h:297
static MStyle * _defaultStyleForParts
Definition: mscore.h:288
Definition: mscore.h:239
static bool showCorruptedMeasures
Definition: mscore.h:351
static bool noHorizontalStretch
Definition: mscore.h:344
int track2staff(int voice)
Definition: mscore.h:76
static QString _globalShare
Definition: mscore.h:290
HairpinType
Definition: hairpin.h:27
OrnamentStyle
Definition: mscore.h:298
Definition: mscore.h:244
AccidentalVal
Definition: mscore.h:147
static int defaultPlayDuration
Definition: mscore.h:340
static qreal verticalPageGap
Definition: mscore.h:372
Definition: mscore.h:236
virtual ~MPaintDevice()
Definition: mscore.h:276
MsError no
Definition: mscore.h:258
static bool useFallbackFont
Definition: mscore.h:352
static QColor dropColor
Definition: mscore.h:329
static bool showSkylines
Definition: mscore.h:347
static MsError _error
Definition: mscore.h:299
static std::vector< MScoreError > errorList
Definition: mscore.h:303
SelectType
Definition: mscore.h:139
constexpr ArticulationShowIn operator|(ArticulationShowIn a1, ArticulationShowIn a2)
Definition: articulation.h:45
int trackZeroVoice(int track)
Definition: mscore.h:78
static MStyle _defaultStyle
Definition: mscore.h:287
int staff2track(int staffIdx)
Definition: mscore.h:75
static bool showMeasureShapes
Definition: mscore.h:348
static bool testMode
Definition: mscore.h:355
NoteHeadScheme
Definition: mscore.h:182
Definition: sequencer.h:26
Definition: mscore.h:241
static bool pdfPrinting
Definition: mscore.h:368
StaffGroup
Definition: mscore.h:177
Definition: mscore.h:237
Definition: mscore.h:250
Definition: mscore.h:243
static bool showBoundingRect
Definition: mscore.h:349
static QColor bgColor
Definition: mscore.h:332
static MStyle & defaultStyle()
Definition: mscore.h:308
static bool svgPrinting
Definition: mscore.h:369
static qreal hRaster()
Definition: mscore.h:316
Definition: mscore.h:247
IconType
Definition: mscore.h:219
static void setVRaster(int val)
Definition: mscore.h:319
static int mtcType
Definition: mscore.h:359
int track2voice(int track)
Definition: mscore.h:77
Definition: mscore.h:240
static bool showSegmentShapes
Definition: mscore.h:346
constexpr bool operator &(ArticulationShowIn a1, ArticulationShowIn a2)
Definition: articulation.h:48
static QColor defaultColor
Definition: mscore.h:328
static void setHRaster(int val)
Definition: mscore.h:318
static Sequencer * seq
Definition: mscore.h:360
static bool noImages
Definition: mscore.h:366
static bool saveTemplateMode
Definition: mscore.h:362
#define VOICES
Definition: mscore.h:72
static qreal vRaster()
Definition: mscore.h:317
static void setDefaultStyle(const MStyle &s)
Definition: mscore.h:312
static int _vRaster
Definition: mscore.h:291
Definition: mscore.h:257
const int STAFF_GROUP_MAX
Definition: mscore.h:180
static double pixelRatio
Definition: mscore.h:370
static void setNudgeStep10(qreal val)
Definition: mscore.h:321
static QColor layoutBreakColor
Definition: mscore.h:330
static void setVerticalOrientation(bool val)
Definition: mscore.h:325
Definition: mscore.h:235
static qreal nudgeStep
Definition: mscore.h:337
Definition: aeolus.cpp:26
static bool _verticalOrientation
Definition: mscore.h:292
static const MStyle & baseStyle()
Definition: mscore.h:307
const char * group
Definition: mscore.h:259
static bool playRepeats
Definition: mscore.h:335
static qreal horizontalPageGapEven
Definition: mscore.h:373
KeySigNatural
Definition: mscore.h:159
Definition: mscore.h:251
Definition: mscore.h:284
static void setError(MsError e)
Definition: mscore.h:378
UpDownMode
Definition: mscore.h:169
static bool verticalOrientation()
Definition: mscore.h:324
static int division
Definition: mscore.h:357
static const QString & globalShare()
Definition: mscore.h:315
Definition: mscore.h:238
static int sampleRate
Definition: mscore.h:358
static qreal nudgeStep10
Definition: mscore.h:338
Definition: mscore.h:252
static QColor frameMarginColor
Definition: mscore.h:331
BracketType
Definition: mscore.h:107
static QString lastError
Definition: mscore.h:341
MPaintDevice()
Definition: mscore.h:274
static Q_GADGET MStyle _baseStyle
Definition: mscore.h:286
Definition: mscore.h:242
static bool noExcerpts
Definition: mscore.h:365
Definition: mscore.h:246
Definition: mscore.h:253
Definition: mscore.h:245
static bool debugMode
Definition: mscore.h:354
MsError
Definition: mscore.h:233
static qreal nudgeStep50
Definition: mscore.h:339
static bool panPlayback
Definition: mscore.h:336
Definition: mscore.h:234
PlaceText
Definition: mscore.h:115
static qreal horizontalPageGapOdd
Definition: mscore.h:374
TransposeDirection
Definition: mscore.h:123
const char * txt
Definition: mscore.h:260
Definition: mscore.h:248
static bool warnPitchRange
Definition: mscore.h:333
static void setNudgeStep(qreal val)
Definition: mscore.h:320
static void setNudgeStep50(qreal val)
Definition: mscore.h:322
Definition: mscore.h:268
static MPaintDevice * _paintDevice
Definition: mscore.h:294
static bool showSystemBoundingRect
Definition: mscore.h:350
Definition: mscore.h:249
static const MStyle * defaultStyleForParts()
Definition: mscore.h:309
static bool noVerticalStretch
Definition: mscore.h:345
BarLineType
Definition: mscore.h:199
Definition: style.h:1293
static bool noGui
Definition: mscore.h:363
TransposeMode
Definition: mscore.h:131
QErrorMessage * errorMessage
Definition: musescore.cpp:217