Verovio
Source code documentation
vrvdef.h
1 // Name: vrvdef.h
3 // Author: Laurent Pugin
4 // Created: 2005
5 // Copyright (c) Authors and others. All rights reserved.
7 
8 #ifndef __VRV_DEF_H__
9 #define __VRV_DEF_H__
10 
11 #include <algorithm>
12 #include <functional>
13 #include <list>
14 #include <map>
15 #include <set>
16 #include <tuple>
17 #include <vector>
18 
19 //----------------------------------------------------------------------------
20 
21 #include "attdef.h"
22 
23 #define VRV_UNSET MEI_UNSET
24 
25 //----------------------------------------------------------------------------
26 
27 #define _USE_MATH_DEFINES // needed by Windows for math constants like "M_PI"
28 #include <math.h>
29 
30 // In case it is not defined before...
31 #ifndef M_PI
32 #define M_PI (3.14159265358979323846264338327950288)
33 #endif
34 
35 namespace vrv {
36 
37 //----------------------------------------------------------------------------
38 // Version
39 //----------------------------------------------------------------------------
40 
41 #define VERSION_MAJOR 5
42 #define VERSION_MINOR 2
43 #define VERSION_REVISION 0
44 // Adds "-dev" in the version number - should be set to false for releases
45 #define VERSION_DEV true
46 
47 //----------------------------------------------------------------------------
48 // Resource directory
49 //----------------------------------------------------------------------------
50 #ifdef RESOURCE_DIR
51 #define VRV_RESOURCE_DIR RESOURCE_DIR
52 #else
53 #define VRV_RESOURCE_DIR "/usr/local/share/verovio"
54 #endif
55 
56 //----------------------------------------------------------------------------
57 // Cast redefinition
58 //----------------------------------------------------------------------------
59 
60 // Can be changed between static and dynamic for debug purposes
61 #ifdef VRV_DYNAMIC_CAST
62 // To be used for all cases where type is cheched through Object::m_type
63 #define vrv_cast dynamic_cast
64 #else
65 #define vrv_cast static_cast
66 #endif
67 
68 //----------------------------------------------------------------------------
69 // Default MIDI values
70 //----------------------------------------------------------------------------
71 
72 #define MIDI_VELOCITY 90
73 #define MIDI_TEMPO 120
74 
75 #define UNACC_GRACENOTE_DUR 27 // in milliseconds
76 #define UNACC_GRACENOTE_FRACTION Fraction(1, 2048)
77 
78 //----------------------------------------------------------------------------
79 // Object defines
80 //----------------------------------------------------------------------------
81 
89 enum ClassId : uint16_t {
90  BOUNDING_BOX = 0, // Should not be instanciated as is
91  OBJECT, // Should not be instanciated as is
92  DEVICE_CONTEXT, // Should not be instanciated as is,
93  FLOATING_OBJECT,
94  FLOATING_POSITIONER,
95  FLOATING_CURVE_POSITIONER,
96  // Ids for ungrouped objects
97  ALIGNMENT,
98  ALIGNMENT_REFERENCE,
99  CLEF_ATTR,
100  COURSE,
101  DOC,
102  FACSIMILE,
103  FB,
104  GRPSYM,
105  GRACE_ALIGNER,
106  GRAPHIC,
107  INSTRDEF,
108  KEYSIG_ATTR,
109  LABEL,
110  LABELABBR,
111  LAYER,
112  MEASURE,
113  MEASURE_ALIGNER,
114  MENSUR_ATTR,
115  METERSIG_ATTR,
116  PAGE,
117  PAGES,
118  STAFF,
119  STAFF_ALIGNMENT,
120  STAFFGRP,
121  SURFACE,
122  SVG,
123  SYMBOLDEF,
124  SYMBOLTABLE,
125  SYSTEM,
126  SYSTEM_ALIGNER,
127  SYSTEM_ALIGNMENT,
128  TIMESTAMP_ALIGNER,
129  TUNING,
130  ZONE,
131  // Ids for EditorialElement child classes
132  EDITORIAL_ELEMENT,
133  ABBR,
134  ADD,
135  ANNOT,
136  APP,
137  CHOICE,
138  CORR,
139  DAMAGE,
140  DEL,
141  EXPAN,
142  LEM,
143  ORIG,
144  RDG,
145  REF,
146  REG,
147  RESTORE,
148  SIC,
149  SUBST,
150  SUPPLIED,
151  UNCLEAR,
152  EDITORIAL_ELEMENT_max,
153  // Ids for TextLayoutElement child classes
154  TEXT_LAYOUT_ELEMENT,
155  DIV,
156  // Ids for RunningElement child classes
157  RUNNING_ELEMENT,
158  PGFOOT,
159  PGHEAD,
160  RUNNING_ELEMENT_max,
161  TEXT_LAYOUT_ELEMENT_max,
162  // Ids for PageElement child classes
163  PAGE_ELEMENT,
164  PAGE_MILESTONE_END,
165  MDIV,
166  SCORE,
167  PAGE_ELEMENT_max,
168  // Ids for SystemElement child classes
169  SYSTEM_ELEMENT,
170  SYSTEM_MILESTONE_END,
171  ENDING,
172  EXPANSION,
173  PB,
174  SB,
175  SECTION,
176  SYSTEM_ELEMENT_max,
177  // Ids for ControlElement child classes
178  CONTROL_ELEMENT,
179  ANCHOREDTEXT,
180  ARPEG,
181  BEAMSPAN,
182  BRACKETSPAN,
183  BREATH,
184  CAESURA,
185  CPMARK,
186  DIR,
187  DYNAM,
188  FERMATA,
189  FING,
190  GLISS,
191  HAIRPIN,
192  HARM,
193  LV,
194  MORDENT,
195  MNUM,
196  ORNAM,
197  OCTAVE,
198  PEDAL,
199  PHRASE,
200  PITCHINFLECTION,
201  REH,
202  REPEATMARK,
203  SLUR,
204  TEMPO,
205  TIE,
206  TRILL,
207  TURN,
208  CONTROL_ELEMENT_max,
209  // Ids for LayerElement child classes
210  LAYER_ELEMENT,
211  ACCID,
212  ARTIC,
213  BARLINE,
214  BEAM,
215  BEATRPT,
216  BTREM,
217  CHORD,
218  CLEF,
219  CUSTOS,
220  DIVLINE,
221  DOT,
222  DOTS,
223  FLAG,
224  FTREM,
225  GENERIC_ELEMENT,
226  GRACEGRP,
227  HALFMRPT,
228  KEYSIG,
229  KEYACCID,
230  LIGATURE,
231  LIQUESCENT,
232  MENSUR,
233  METERSIG,
234  METERSIGGRP,
235  MREST,
236  MRPT,
237  MRPT2,
238  MSPACE,
239  MULTIREST,
240  MULTIRPT,
241  NC,
242  NOTE,
243  NEUME,
244  ORISCUS,
245  PLICA,
246  PROPORT,
247  QUILISMA,
248  REST,
249  SPACE,
250  STEM,
251  SYL,
252  SYLLABLE,
253  TABGRP,
254  TABDURSYM,
255  TIMESTAMP_ATTR,
256  TUPLET,
257  TUPLET_BRACKET,
258  TUPLET_NUM,
259  VERSE,
260  LAYER_ELEMENT_max,
261  // Ids for ScoreDefElement child classes
262  SCOREDEF_ELEMENT,
263  LAYERDEF,
264  SCOREDEF,
265  STAFFDEF,
266  SCOREDEF_ELEMENT_max,
267  // Ids for TextElement child classes
268  TEXT_ELEMENT,
269  FIG,
270  FIGURE,
271  LB,
272  NUM,
273  REND,
274  SYMBOL,
275  TEXT,
276  TEXT_ELEMENT_max,
277  //
278  BBOX_DEVICE_CONTEXT,
279  SVG_DEVICE_CONTEXT,
280  CUSTOM_DEVICE_CONTEXT,
281  //
282  UNSPECIFIED
283 };
284 
289 enum InterfaceId {
290  INTERFACE,
291  INTERFACE_ALT_SYM,
292  INTERFACE_AREA_POS,
293  INTERFACE_BOUNDARY,
294  INTERFACE_DURATION,
295  INTERFACE_LINKING,
296  INTERFACE_FACSIMILE,
297  INTERFACE_PITCH,
298  INTERFACE_PLIST,
299  INTERFACE_POSITION,
300  INTERFACE_SCOREDEF,
301  INTERFACE_TEXT_DIR,
302  INTERFACE_TIME_POINT,
303  INTERFACE_TIME_SPANNING
304 };
305 
306 //----------------------------------------------------------------------------
307 // Typedefs
308 //----------------------------------------------------------------------------
309 
310 class Alignment;
311 class Arpeg;
312 class ClassIdComparison;
313 class BeamElementCoord;
314 class BoundingBox;
315 class Comparison;
316 class CurveSpannedElement;
317 class DivLine;
318 class FloatingPositioner;
319 class FloatingCurvePositioner;
320 class GraceAligner;
321 class InterfaceComparison;
322 class LayerElement;
323 class LedgerLine;
324 class LinkingInterface;
325 class Liquescent;
326 class Nc;
327 class Note;
328 class Neume;
329 class Object;
330 class PlistInterface;
331 class Point;
332 class Staff;
333 class Option;
334 class TextElement;
335 class TimePointInterface;
336 class TimeSpanningInterface;
337 
338 typedef std::vector<Object *> ArrayOfObjects;
339 
340 typedef std::vector<const Object *> ArrayOfConstObjects;
341 
342 typedef std::list<Object *> ListOfObjects;
343 
344 typedef std::list<const Object *> ListOfConstObjects;
345 
346 typedef std::set<Object *> SetOfObjects;
347 
348 typedef std::set<const Object *> SetOfConstObjects;
349 
350 typedef std::vector<Note *> ChordNoteGroup;
351 
352 typedef std::vector<std::tuple<Alignment *, Alignment *, int>> ArrayOfAdjustmentTuples;
353 
354 typedef std::vector<std::tuple<Alignment *, Arpeg *, int, bool>> ArrayOfAlignmentArpegTuples;
355 
356 typedef std::vector<BeamElementCoord *> ArrayOfBeamElementCoords;
357 
358 typedef std::vector<std::pair<int, int>> ArrayOfIntPairs;
359 
360 typedef std::multimap<std::string, LinkingInterface *> MapOfLinkingInterfaceIDPairs;
361 
362 typedef std::map<std::string, Note *> MapOfNoteIDPairs;
363 
364 typedef std::vector<std::pair<PlistInterface *, std::string>> ArrayOfPlistInterfaceIDPairs;
365 
366 typedef std::vector<CurveSpannedElement *> ArrayOfCurveSpannedElements;
367 
368 typedef std::list<std::pair<Object *, data_MEASUREBEAT>> ListOfObjectBeatPairs;
369 
370 typedef std::list<std::pair<Object *, std::string>> ListOfObjectAttNamePairs;
371 
372 typedef std::list<std::pair<TimePointInterface *, ClassId>> ListOfPointingInterClassIdPairs;
373 
374 typedef std::list<std::pair<TimeSpanningInterface *, ClassId>> ListOfSpanningInterClassIdPairs;
375 
376 typedef std::list<std::pair<TimeSpanningInterface *, Object *>> ListOfSpanningInterOwnerPairs;
377 
378 typedef std::vector<FloatingPositioner *> ArrayOfFloatingPositioners;
379 
380 typedef std::vector<FloatingCurvePositioner *> ArrayOfFloatingCurvePositioners;
381 
382 typedef std::vector<BoundingBox *> ArrayOfBoundingBoxes;
383 
384 typedef std::vector<LedgerLine> ArrayOfLedgerLines;
385 
386 typedef std::vector<TextElement *> ArrayOfTextElements;
387 
388 typedef std::map<const Staff *, std::multiset<int>> MapOfNoteLocs;
389 
390 typedef std::map<const Staff *, std::set<int>> MapOfDotLocs;
391 
392 typedef std::map<std::string, Option *> MapOfStrOptions;
393 
394 typedef std::map<int, data_ACCIDENTAL_WRITTEN> MapOfOctavedPitchAccid;
395 
396 typedef std::map<int, GraceAligner *> MapOfIntGraceAligners;
397 
398 typedef std::vector<std::pair<std::u32string, bool>> ArrayOfStringDynamTypePairs;
399 
400 typedef std::map<ClassId, std::function<Object *(void)>> MapOfClassIdConstructors;
401 
402 typedef std::map<std::string, ClassId> MapOfStrClassIds;
403 
404 typedef std::vector<std::pair<LayerElement *, LayerElement *>> MeasureTieEndpoints;
405 
406 typedef bool (*NotePredicate)(const Note *);
407 
408 typedef std::vector<std::pair<LayerElement *, data_DURATION>> ArrayOfElementDurPairs;
409 
419 struct IntTree {
420  std::map<int, IntTree> child;
421 };
422 
423 typedef std::map<int, IntTree> IntTree_t;
424 
431 typedef std::map<int, bool> VerseN_t;
432 typedef std::map<int, VerseN_t> LayerN_VerserN_t;
433 typedef std::map<int, LayerN_VerserN_t> StaffN_LayerN_VerseN_t;
434 
435 //----------------------------------------------------------------------------
436 // Global defines
437 //----------------------------------------------------------------------------
438 
439 #define DEFINITION_FACTOR 10
440 
441 #define isIn(x, a, b) (((x) >= std::min((a), (b))) && ((x) <= std::max((a), (b))))
442 
449 enum FunctorCode { FUNCTOR_CONTINUE = 0, FUNCTOR_SIBLINGS, FUNCTOR_STOP };
450 
451 //----------------------------------------------------------------------------
452 // Maximum number of levels between parent and children for optimizing search
453 //----------------------------------------------------------------------------
454 
458 #define MAX_ACCID_DEPTH -1
459 
461 #define MAX_BEAM_DEPTH -1
462 
464 #define MAX_CHORD_DEPTH -1
465 
467 #define MAX_FTREM_DEPTH -1
468 
470 #define MAX_LIGATURE_DEPTH -1
471 
473 #define MAX_TABGRP_DEPTH -1
474 
476 #define MAX_TUPLET_DEPTH -1
477 
479 #define MAX_STAFFGRP_DEPTH -1
480 
482 #define MAX_NOTE_DEPTH -1
483 
484 //----------------------------------------------------------------------------
485 // Unicode music codepoints
486 //----------------------------------------------------------------------------
487 
488 #define UNICODE_FLAT U'\u266D' // ♭
489 #define UNICODE_NATURAL U'\u266E' // ♮
490 #define UNICODE_SHARP U'\u266F' // ♯
491 
492 #define UNICODE_UNDERTIE U'\u203F' // ‿
493 
494 #define UNICODE_DAL_SEGNO U'\U0001D109' // 𝄉
495 #define UNICODE_DA_CAPO U'\U0001D10A' // 𝄊
496 #define UNICODE_SEGNO U'\U0001D10B' // 𝄋
497 #define UNICODE_CODA U'\U0001D10C' // 𝄌
498 
499 #define UNICODE_DOUBLE_FLAT U'\U0001D12B' // 𝄫
500 #define UNICODE_DOUBLE_SHARP U'\U0001D12A' // 𝄪
501 
502 //----------------------------------------------------------------------------
503 // VerovioText codepoints
504 //----------------------------------------------------------------------------
505 
514 #define VRV_TEXT_HARM \
515  U"\u266D\u266E\u266F" \
516  U"\uE260\uE261\uE262\uE263\uE264" \
517  U"\uEA50\uEA51\uEA52\uEA53\uEA54\uEA55\uEA56\uEA57\uEA58\uEA59\uEA5A\uEA5B\uEA5C\uEA5D\uEA5E" \
518  U"\uEA5F\uEA60\uEA61\uEA62\uEA63\uEA64\uEA65\uEA66\uEA67" \
519  U"\uECC0"
520 
521 //----------------------------------------------------------------------------
522 // data.LINEWIDTHTERM factors
523 //----------------------------------------------------------------------------
524 
525 #define LINEWIDTHTERM_factor_narrow 1.0
526 #define LINEWIDTHTERM_factor_medium 2.0
527 #define LINEWIDTHTERM_factor_wide 4.0
528 
529 //----------------------------------------------------------------------------
530 // Types for editorial element
531 //----------------------------------------------------------------------------
532 
533 // the maximum is 255 (unsigned char)
534 enum EditorialLevel {
535  EDITORIAL_UNDEFINED = 0,
536  EDITORIAL_TOPLEVEL,
537  EDITORIAL_SCOREDEF,
538  EDITORIAL_STAFFGRP,
539  EDITORIAL_MEASURE,
540  EDITORIAL_STAFF,
541  EDITORIAL_LAYER,
542  EDITORIAL_NOTE,
543  EDITORIAL_TEXT,
544  EDITORIAL_FB,
545  EDITORIAL_RUNNING,
546 };
547 
548 //----------------------------------------------------------------------------
549 // Visibility for editorial and mdiv elements
550 //----------------------------------------------------------------------------
551 
552 enum VisibilityType { Hidden = 0, Visible };
553 
554 //----------------------------------------------------------------------------
555 // The used SMuFL glyph anchors
556 //----------------------------------------------------------------------------
557 
558 enum SMuFLGlyphAnchor {
559  SMUFL_stemDownNW = 0,
560  SMUFL_stemUpSE,
561  SMUFL_cutOutNE,
562  SMUFL_cutOutNW,
563  SMUFL_cutOutSE,
564  SMUFL_cutOutSW
565 };
566 
567 //----------------------------------------------------------------------------
568 // Spanning types for control events
569 //----------------------------------------------------------------------------
570 
571 enum { SPANNING_START_END = 0, SPANNING_START, SPANNING_END, SPANNING_MIDDLE };
572 
573 //----------------------------------------------------------------------------
574 // Types for layer element
575 //----------------------------------------------------------------------------
576 
582 enum ElementScoreDefRole { SCOREDEF_NONE = 0, SCOREDEF_SYSTEM, SCOREDEF_INTERMEDIATE, SCOREDEF_CAUTIONARY };
583 
584 //----------------------------------------------------------------------------
585 // Artic types
586 //----------------------------------------------------------------------------
587 
588 enum ArticType { ARTIC_INSIDE = 0, ARTIC_OUTSIDE };
589 
590 //----------------------------------------------------------------------------
591 // Visibility optimization
592 //----------------------------------------------------------------------------
593 
594 enum VisibilityOptimization { OPTIMIZATION_NONE = 0, OPTIMIZATION_HIDDEN, OPTIMIZATION_SHOW };
595 
596 //----------------------------------------------------------------------------
597 // Layout positions (3 x 3 grid)
598 //----------------------------------------------------------------------------
599 
600 enum {
601  POSITION_LEFT = 0,
602  POSITION_CENTER,
603  POSITION_RIGHT,
604 };
605 
606 enum {
607  POSITION_TOP = 0,
608  POSITION_MIDDLE = 3,
609  POSITION_BOTTOM = 6,
610 };
611 
612 //----------------------------------------------------------------------------
613 // Ligature shape bitfields
614 //----------------------------------------------------------------------------
615 
616 enum {
617  LIGATURE_DEFAULT = 0,
618  LIGATURE_STEM_LEFT_UP = 1,
619  LIGATURE_STEM_LEFT_DOWN = 2,
620  LIGATURE_STEM_RIGHT_UP = 4,
621  LIGATURE_STEM_RIGHT_DOWN = 8,
622  LIGATURE_OBLIQUE = 16,
623  LIGATURE_STACKED = 32
624 };
625 
626 //----------------------------------------------------------------------------
627 // Analytical markup bitfields
628 //----------------------------------------------------------------------------
629 
630 enum {
631  MARKUP_DEFAULT = 0,
632  MARKUP_ANALYTICAL_TIE = 1,
633  MARKUP_ANALYTICAL_FERMATA = 2,
634  MARKUP_GRACE_ATTRIBUTE = 4,
635  MARKUP_ARTIC_MULTIVAL = 8,
636  MARKUP_SCOREDEF_DEFINITIONS = 16
637 };
638 
639 //----------------------------------------------------------------------------
640 // Layout information
641 //----------------------------------------------------------------------------
642 
643 enum LayoutInformation { LAYOUT_NONE = 0, LAYOUT_ENCODED, LAYOUT_DONE };
644 
645 //----------------------------------------------------------------------------
646 // Bounding box access
647 //----------------------------------------------------------------------------
648 
649 enum Accessor { SELF = 0, CONTENT };
650 
651 //----------------------------------------------------------------------------
652 // Some keys
653 //----------------------------------------------------------------------------
654 
655 enum { KEY_LEFT = 37, KEY_UP = 38, KEY_RIGHT = 39, KEY_DOWN = 40 };
656 
657 //----------------------------------------------------------------------------
658 // Stem sameas drawing role
659 //----------------------------------------------------------------------------
660 
661 enum StemSameasDrawingRole { SAMEAS_NONE = 0, SAMEAS_UNSET, SAMEAS_PRIMARY, SAMEAS_SECONDARY };
662 
663 //----------------------------------------------------------------------------
664 // Smufl text font (selected font or fallback)
665 //----------------------------------------------------------------------------
666 
667 enum SmuflTextFont { SMUFL_NONE = 0, SMUFL_FONT_SELECTED, SMUFL_FONT_FALLBACK };
668 
669 //----------------------------------------------------------------------------
670 // Graphic ID type
671 //----------------------------------------------------------------------------
672 
673 enum GraphicID { PRIMARY = 0, SPANNING, SYMBOLREF };
674 
675 //----------------------------------------------------------------------------
676 // Measure type
677 //----------------------------------------------------------------------------
678 
679 enum MeasureType { MEASURED = 0, UNMEASURED, NEUMELINE };
680 
681 //----------------------------------------------------------------------------
682 // Focus status type
683 //----------------------------------------------------------------------------
684 
685 enum FocusStatusType { FOCUS_UNSET = 0, FOCUS_SET, FOCUS_USED };
686 
687 //----------------------------------------------------------------------------
688 // The score time unit (quarter note)
689 //----------------------------------------------------------------------------
690 
691 #define SCORE_TIME_UNIT 4
692 
693 //----------------------------------------------------------------------------
694 // Section representing a line in neon
695 //----------------------------------------------------------------------------
696 
697 #define NEUME_LINE_TYPE "neon-neume-line"
698 
699 //----------------------------------------------------------------------------
700 // Legacy Wolfgang defines
701 //----------------------------------------------------------------------------
702 
703 #define OCTAVE_OFFSET 4
704 
705 // in half staff spaces (but should be 6 in two-voice notation)
706 #define STANDARD_STEMLENGTH 7
707 #define STANDARD_STEMLENGTH_TAB 3
708 
709 //----------------------------------------------------------------------------
710 // Temporary - to be made an option?
711 //----------------------------------------------------------------------------
712 
713 #define TABLATURE_STAFF_RATIO 1.75
714 #define GERMAN_TAB_STAFF_RATIO 2.2
715 
716 #define SUPER_SCRIPT_FACTOR 0.58
717 #define SUPER_SCRIPT_POSITION -0.20 // lowered down from the midline
718 #define SUB_SCRIPT_POSITION -0.17 // lowered down from the baseline
719 
720 //----------------------------------------------------------------------------
721 // Neume notation note size to staff size ratio defines
722 //----------------------------------------------------------------------------
723 
724 #define NOTE_HEIGHT_TO_STAFF_SIZE_RATIO 2
725 #define NOTE_WIDTH_TO_STAFF_SIZE_RATIO 1.4
726 
727 } // namespace vrv
728 
729 #endif // __VRV_DEF_H__
vrv::IntTree
Generic int map recursive structure for storing hierachy of values For example, we want to process al...
Definition: vrvdef.h:419