OSMDOptions.ts 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import { DrawingParametersEnum, ColoringModes } from "../MusicalScore/Graphical/DrawingParameters";
  2. /** Possible options for the OpenSheetMusicDisplay constructor and osmd.setOptions(). None are mandatory.
  3. * Note that after using setOptions(), you have to call osmd.render() again to make changes visible.
  4. * Example: osmd.setOptions({defaultColorRest: "#AAAAAA", drawSubtitle: false}); osmd.render();
  5. */
  6. export interface IOSMDOptions {
  7. /** Whether to let Vexflow align rests to preceding or following notes (Vexflow option). Default false (0).
  8. * This can naturally reduce collisions of rest notes with other notes.
  9. * Auto mode (2) only aligns rests when there are multiple voices in a measure, and at least once at the same x-coordinate.
  10. * Auto is the recommended setting, and would be default, if it couldn't in rare cases deteriorate rest placement for existing users.
  11. * The on mode (1) always aligns rests, also changing their position when there is no simultaneous note at the same x-coordinate, which is nonstandard.
  12. */
  13. alignRests?: AlignRestOption | number;
  14. /** Whether to automatically create beams for notes that don't have beams set in XML. */
  15. autoBeam?: boolean;
  16. /** Options for autoBeaming like whether to beam over rests. See AutoBeamOptions interface. */
  17. autoBeamOptions?: AutoBeamOptions;
  18. /** Automatically resize score with canvas size. Default is true. */
  19. autoResize?: boolean;
  20. /** Render Backend, will be SVG if given undefined, SVG or svg, otherwise Canvas. */
  21. backend?: string;
  22. /** Defines the mode that is used for coloring: XML (0), Boomwhacker(1), CustomColorSet (2). Default XML.
  23. * If coloringMode.CustomColorSet (2) is chosen, a coloringSetCustom parameter must be added.
  24. */
  25. coloringMode?: ColoringModes;
  26. /** Set of 8 colors for automatic coloring of 7 notes from C to B + rest note in HTML form (e.g. "#00ff00" for green). */
  27. coloringSetCustom?: string[];
  28. /** Whether to enable coloring noteheads and stems, depending on coloringMode. */
  29. coloringEnabled?: boolean;
  30. /** Whether to color the stems of notes the same as their noteheads */
  31. colorStemsLikeNoteheads?: boolean;
  32. /** Default color for a note head (without stem). Default black (undefined).
  33. * Only considered before loading a sample, not before render.
  34. * To change the color after loading a sample and before render, use note(.sourceNote).NoteheadColor.
  35. * The format is Vexflow format, either "#rrggbb" or "#rrggbbtt" where <tt> is transparency. All hex values.
  36. * E.g., a half-transparent red would be "#FF000080", invisible would be "#00000000" or "#12345600".
  37. */
  38. defaultColorNotehead?: string;
  39. /** Default color for a note stem. Default black (undefined). */
  40. defaultColorStem?: string;
  41. /** Default color for rests. Default black (undefined). */
  42. defaultColorRest?: string;
  43. /** Default color for Labels like title or lyrics. Default black (undefined). */
  44. defaultColorLabel?: string;
  45. /** Default color for labels in the title. Overrides defaultColorLabel for title labels like composer. Default black (undefined). */
  46. defaultColorTitle?: string;
  47. /** Default font used for text and labels, e.g. title or lyrics. Default Times New Roman
  48. * Note that OSMD originally always used Times New Roman, so things like layout and spacing may still be optimized for it.
  49. * Valid options are CSS font families available in the browser used for rendering, e.g. Times New Roman, Helvetica.
  50. */
  51. defaultFontFamily?: string;
  52. /** Don't show/load cursor. Will override disableCursor in drawingParameters. */
  53. disableCursor?: boolean;
  54. /** Follow Cursor: Scroll the page when cursor.next() is called and the cursor moves into a new system outside of the current view frame. */
  55. followCursor?: boolean;
  56. /** Broad Parameters like compact or preview mode. */
  57. drawingParameters?: string | DrawingParametersEnum;
  58. /** Whether to draw credits (title, subtitle, composer, lyricist) (in future: copyright etc., see <credit>). */
  59. drawCredits?: boolean;
  60. /** Whether to draw the title of the piece. If false, disables drawing Subtitle as well. */
  61. drawTitle?: boolean;
  62. /** Whether to draw the subtitle of the piece. If true, enables drawing Title as well. */
  63. drawSubtitle?: boolean;
  64. /** Whether to draw the composer name (top right of the score). */
  65. drawComposer?: boolean;
  66. /** Whether to draw the lyricist's name, if given (top left of the score). */
  67. drawLyricist?: boolean;
  68. /** Whether to draw part (instrument) names. */
  69. drawPartNames?: boolean;
  70. /** Whether to draw part (instrument) name abbreviations each system after the first. Only draws if drawPartNames. Default true. */
  71. drawPartAbbreviations?: boolean;
  72. /** Whether to draw measure numbers (labels). Default true.
  73. * Draws a measure number label at first measure, system start measure, and every [measureNumberInterval] measures.
  74. * See the [measureNumberInterval] option, default is 2.
  75. */
  76. drawMeasureNumbers?: boolean;
  77. /** The interval of measure numbers to draw, i.e. it draws the measure number above the beginning label every x measures. Default 2. */
  78. measureNumberInterval?: number;
  79. /** Whether to draw fingerings (only left to the note for now). Default true (unless solo part). */
  80. drawFingerings?: boolean;
  81. /** Where to draw fingerings (left, right, above, below, auto).
  82. * Default left. Auto, above, below experimental (potential collisions because bounding box not correct)
  83. */
  84. fingeringPosition?: string;
  85. /** For above/below fingerings, whether to draw them directly above/below notes (default), or above/below staffline. */
  86. fingeringInsideStafflines?: boolean;
  87. /** Whether to draw lyrics (and their extensions and dashes). */
  88. drawLyrics?: boolean;
  89. /** Whether to calculate extra slurs with bezier curves not covered by Vexflow slurs. Default true. */
  90. drawSlurs?: boolean;
  91. /** Only draw measure n to m, where m is the number you specify. */
  92. drawUpToMeasureNumber?: number;
  93. /** Only draw measure n to m, where n is the number you specify. */
  94. drawFromMeasureNumber?: number;
  95. /** Whether to set the wanted stem direction by xml (default) or automatically. */
  96. setWantedStemDirectionByXml?: boolean;
  97. /** Whether tuplets are labeled with ratio (e.g. 5:2 instead of 5 for quintuplets). Default false. */
  98. tupletsRatioed?: boolean;
  99. /** Whether all tuplets should be bracketed (e.g. |--5--| instead of 5). Default false.
  100. * If false, only tuplets given as bracketed in XML (bracket="yes") will be bracketed.
  101. */
  102. tupletsBracketed?: boolean;
  103. /** Whether all triplets should be bracketed. Overrides tupletsBracketed for triplets.
  104. * If false, only triplets given as bracketed in XML (bracket="yes") will be bracketed.
  105. * (Bracketing all triplets can be cluttering)
  106. */
  107. tripletsBracketed?: boolean;
  108. /** Whether to draw hidden/invisible notes (print-object="no" in XML). Default false. Not yet supported. */ // TODO
  109. drawHiddenNotes?: boolean;
  110. }
  111. export enum AlignRestOption {
  112. Never = 0, // false should also work
  113. Always = 1, // true should also work
  114. Auto = 2
  115. }
  116. /** Handles [[IOSMDOptions]], e.g. returning default options with OSMDOptionsStandard() */
  117. export class OSMDOptions {
  118. /** Returns the default options for OSMD.
  119. * These are e.g. used if no options are given in the [[OpenSheetMusicDisplay]] constructor.
  120. */
  121. public static OSMDOptionsStandard(): IOSMDOptions {
  122. return {
  123. autoResize: true,
  124. backend: "svg",
  125. drawingParameters: DrawingParametersEnum.default,
  126. };
  127. }
  128. }
  129. export interface AutoBeamOptions {
  130. /** Whether to extend beams over rests. Default false. */
  131. beam_rests?: boolean;
  132. /** Whether to extend beams only over rests that are in the middle of a potential beam. Default false. */
  133. beam_middle_rests_only?: boolean;
  134. /** Whether to maintain stem direction of autoBeamed notes. Discouraged, reduces beams. Default false. */
  135. maintain_stem_directions?: boolean;
  136. /** Groups of notes (fractions) to beam within a measure.
  137. * List of fractions, each fraction being [nominator, denominator].
  138. * E.g. [[3,4],[1,4]] will beam the first 3 quarters of a measure, then the last quarter.
  139. */
  140. groups?: [number[]];
  141. }