MuseScore Plugins  3.5
Plugins API for MuseScore
mscore.h
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 const int MAX_HEADERS = 3;
83 static const int MAX_FOOTERS = 3;
84 
85 static constexpr qreal INCH = 25.4;
86 static constexpr qreal PPI = 72.0; // printer points per inch
87 static constexpr qreal DPI_F = 5;
88 static constexpr qreal DPI = 72.0 * DPI_F;
89 static constexpr qreal SPATIUM20 = 5.0 * (DPI / 72.0);
90 static constexpr qreal DPMM = DPI / INCH;
91 
92 static constexpr int MAX_STAVES = 4;
93 
94 static const int SHADOW_NOTE_LIGHT = 135;
95 
96 static const char mimeSymbolFormat[] = "application/musescore/symbol";
97 static const char mimeSymbolListFormat[] = "application/musescore/symbollist";
98 static const char mimeStaffListFormat[] = "application/musescore/stafflist";
99 
100 static const int VISUAL_STRING_NONE = -100; // no ordinal for the visual repres. of string (topmost in TAB
101  // varies according to visual order and presence of bass strings)
102 static const int STRING_NONE = -1; // no ordinal for a physical string (0 = topmost in instrument)
103 static const int FRET_NONE = -1; // no ordinal for a fret
104 
105 //---------------------------------------------------------
106 // BracketType
107 // System Brackets
108 //---------------------------------------------------------
109 
110 enum class BracketType : signed char {
111  NORMAL, BRACE, SQUARE, LINE, NO_BRACKET = -1
112  };
113 
114 //---------------------------------------------------------
115 // PlaceText
116 //---------------------------------------------------------
117 
118 enum class PlaceText : char {
119  AUTO, ABOVE, BELOW, LEFT
120  };
121 
122 //---------------------------------------------------------
123 // TransposeDirection
124 //---------------------------------------------------------
125 
126 enum class TransposeDirection : char {
127  UP, DOWN, CLOSEST
128  };
129 
130 //---------------------------------------------------------
131 // TransposeMode
132 //---------------------------------------------------------
133 
134 enum class TransposeMode : char {
135  TO_KEY, BY_INTERVAL, DIATONICALLY
136  };
137 
138 //---------------------------------------------------------
139 // SelectType
140 //---------------------------------------------------------
141 
142 enum class SelectType : char {
143  SINGLE, RANGE, ADD
144  };
145 
146 //---------------------------------------------------------
147 // AccidentalVal
148 //---------------------------------------------------------
149 
150 enum class AccidentalVal : signed char {
151  SHARP3 = 3,
152  SHARP2 = 2,
153  SHARP = 1,
154  NATURAL = 0,
155  FLAT = -1,
156  FLAT2 = -2,
157  FLAT3 = -3,
158  MIN = FLAT3,
159  MAX = SHARP3
160  };
161 
162 //---------------------------------------------------------
163 // KeySigNaturals (positions of naturals in key sig. changes)
164 //---------------------------------------------------------
165 
166 enum class KeySigNatural : char {
167  NONE = 0, // no naturals, except for change to CMaj/Amin
168  BEFORE = 1, // naturals before accidentals
169  AFTER = 2 // naturals after accidentals (but always before if going sharps <=> flats)
170  };
171 
172 //---------------------------------------------------------
173 // UpDownMode
174 //---------------------------------------------------------
175 
176 enum class UpDownMode : char {
177  CHROMATIC, OCTAVE, DIATONIC
178  };
179 
180 //---------------------------------------------------------
181 // StaffGroup
182 //---------------------------------------------------------
183 
184 enum class StaffGroup : char {
185  STANDARD, PERCUSSION, TAB
186  };
187 const int STAFF_GROUP_MAX = int(StaffGroup::TAB) + 1; // out of enum to avoid compiler complains about not handled switch cases
188 
189 //---------------------------------------------------------
190 // BarLineType
191 //---------------------------------------------------------
192 
193 enum class BarLineType {
194  NORMAL = 1,
195  SINGLE = BarLineType::NORMAL,
196  DOUBLE = 2,
197  START_REPEAT = 4,
198  LEFT_REPEAT = BarLineType::START_REPEAT,
199  END_REPEAT = 8,
200  RIGHT_REPEAT = BarLineType::END_REPEAT,
201  BROKEN = 0x10,
202  DASHED = BarLineType::BROKEN,
203  END = 0x20,
204  FINAL = BarLineType::END,
205  END_START_REPEAT = 0x40,
206  LEFT_RIGHT_REPEAT= BarLineType::END_START_REPEAT,
207  DOTTED = 0x80,
208  REVERSE_END = 0x100,
209  REVERSE_FINALE = BarLineType::REVERSE_END,
210  HEAVY = 0x200,
211  DOUBLE_HEAVY = 0x400,
212  };
213 
214 constexpr BarLineType operator| (BarLineType t1, BarLineType t2) {
215  return static_cast<BarLineType>(static_cast<int>(t1) | static_cast<int>(t2));
216  }
217 constexpr bool operator& (BarLineType t1, BarLineType t2) {
218  return static_cast<int>(t1) & static_cast<int>(t2);
219  }
220 
221 
222 // Icon() subtypes
223 enum class IconType : signed char {
224  NONE = -1,
227  SBEAM, MBEAM, NBEAM, BEAM32, BEAM64, AUTOBEAM,
228  FBEAM1, FBEAM2,
229  VFRAME, HFRAME, TFRAME, FFRAME, MEASURE,
230  BRACKETS, PARENTHESES, BRACES,
231  };
232 
233 //---------------------------------------------------------
234 // MScoreError
235 //---------------------------------------------------------
236 
237 enum MsError {
238  MS_NO_ERROR,
239  NO_NOTE_SELECTED,
240  NO_CHORD_REST_SELECTED,
241  NO_LYRICS_SELECTED,
242  NO_NOTE_REST_SELECTED,
243  NO_FLIPPABLE_SELECTED,
244  NO_STAFF_SELECTED,
245  NO_NOTE_FIGUREDBASS_SELECTED,
246  CANNOT_INSERT_TUPLET,
247  CANNOT_SPLIT_TUPLET,
248  CANNOT_SPLIT_MEASURE_FIRST_BEAT,
249  CANNOT_SPLIT_MEASURE_TUPLET,
250  NO_DEST,
251  DEST_TUPLET,
252  TUPLET_CROSSES_BAR,
253  DEST_LOCAL_TIME_SIGNATURE,
254  DEST_TREMOLO,
255  NO_MIME,
256  DEST_NO_CR,
257  CANNOT_CHANGE_LOCAL_TIMESIG,
258  };
259 
261 struct MScoreError {
262  MsError no;
263  const char* group;
264  const char* txt;
265  };
266 
267 //---------------------------------------------------------
268 // MPaintDevice
270 //---------------------------------------------------------
271 
272 class MPaintDevice : public QPaintDevice {
273 
274  protected:
275  virtual int metric(PaintDeviceMetric m) const;
276 
277  public:
278  MPaintDevice() : QPaintDevice() {}
279  virtual QPaintEngine* paintEngine() const;
280  virtual ~MPaintDevice() {}
281  };
282 
283 //---------------------------------------------------------
284 // MScore
285 // MuseScore application object
286 //---------------------------------------------------------
287 
288 class MScore {
289  Q_GADGET
290  static MStyle _baseStyle; // buildin initial style
291  static MStyle _defaultStyle; // buildin modified by preferences
292  static MStyle* _defaultStyleForParts;
293 
294  static QString _globalShare;
295  static int _hRaster, _vRaster;
296  static bool _verticalOrientation;
297 
298  static MPaintDevice* _paintDevice;
299 
300  public:
301  enum class DirectionH : char { AUTO, LEFT, RIGHT };
302  enum class OrnamentStyle : char { DEFAULT, BAROQUE };
303  Q_ENUM(DirectionH);
304  Q_ENUM(OrnamentStyle);
305 
306  static MsError _error;
307  static std::vector<MScoreError> errorList;
308 
309  static void init();
310 
311  static const MStyle& baseStyle() { return _baseStyle; }
312  static MStyle& defaultStyle() { return _defaultStyle; }
313  static const MStyle* defaultStyleForParts() { return _defaultStyleForParts; }
314 
315  static bool readDefaultStyle(QString file);
316  static void setDefaultStyle(const MStyle& s) { _defaultStyle = s; }
317  static void defaultStyleForPartsHasChanged();
318 
319  static const QString& globalShare() { return _globalShare; }
320  static qreal hRaster() { return _hRaster; }
321  static qreal vRaster() { return _vRaster; }
322  static void setHRaster(int val) { _hRaster = val; }
323  static void setVRaster(int val) { _vRaster = val; }
324  static void setNudgeStep(qreal val) { nudgeStep = val; }
325  static void setNudgeStep10(qreal val) { nudgeStep10 = val; }
326  static void setNudgeStep50(qreal val) { nudgeStep50 = val; }
327 
328  static bool verticalOrientation() { return _verticalOrientation; }
329  static void setVerticalOrientation(bool val) { _verticalOrientation = val; }
330 
331  static QColor selectColor[VOICES];
332  static QColor defaultColor;
333  static QColor dropColor;
334  static QColor layoutBreakColor;
335  static QColor frameMarginColor;
336  static QColor bgColor;
337  static bool warnPitchRange;
338  static int pedalEventsMinTicks;
339 
340  static bool harmonyPlayDisableCompatibility;
341  static bool harmonyPlayDisableNew;
342  static bool playRepeats;
343  static bool panPlayback;
344  static int playbackSpeedIncrement;
345  static qreal nudgeStep;
346  static qreal nudgeStep10;
347  static qreal nudgeStep50;
348  static int defaultPlayDuration;
349  static QString lastError;
350 
351 // #ifndef NDEBUG
352  static bool noHorizontalStretch;
353  static bool noVerticalStretch;
354  static bool showSegmentShapes;
355  static bool showSkylines;
356  static bool showMeasureShapes;
357  static bool showBoundingRect;
358  static bool showSystemBoundingRect;
359  static bool showCorruptedMeasures;
360  static bool useFallbackFont;
361 // #endif
362  static bool debugMode;
363  static bool testMode;
364 
365  static int division;
366  static int sampleRate;
367  static int mtcType;
368  static Sequencer* seq;
369 
370  static bool saveTemplateMode;
371  static bool noGui;
372 
373  static bool noExcerpts;
374  static bool noImages;
375 
376  static bool pdfPrinting;
377  static bool svgPrinting;
378  static double pixelRatio;
379 
380  static qreal verticalPageGap;
381  static qreal horizontalPageGapEven;
382  static qreal horizontalPageGapOdd;
383 
384  static MPaintDevice* paintDevice();
385 
386  static void setError(MsError e) { _error = e; }
387  static const char* errorMessage();
388  static const char* errorGroup();
389  };
390 
391 //---------------------------------------------------------
392 // center
393 //---------------------------------------------------------
394 
395 inline static qreal center(qreal x1, qreal x2)
396  {
397  return (x1 + (x2 - x1) * .5);
398  }
399 
400 //---------------------------------------------------------
401 // limit
402 //---------------------------------------------------------
403 
404 inline static int limit(int val, int min, int max)
405  {
406  if (val > max)
407  return max;
408  if (val < min)
409  return min;
410  return val;
411  }
412 } // namespace Ms
413 
414 Q_DECLARE_METATYPE(Ms::BarLineType);
415 
416 #endif
Alias for BeginBarLine | StartRepeatBarLine | BarLine | EndBarLine
Definition: cursor.cpp:30
Definition: mscore.h:288
OrnamentStyle
Definition: mscore.h:302
DirectionH
Definition: mscore.h:301