OSMDOptions.ts 7.4 KB

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