EngravingRules.ts 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144
  1. import { PagePlacementEnum } from "./GraphicalMusicPage";
  2. //import {MusicSymbol} from "./MusicSymbol";
  3. import log from "loglevel";
  4. import { TextAlignmentEnum } from "../../Common/Enums/TextAlignment";
  5. import { PlacementEnum } from "../VoiceData/Expressions/AbstractExpression";
  6. import {
  7. AutoBeamOptions,
  8. AlignRestOption,
  9. FillEmptyMeasuresWithWholeRests,
  10. SkyBottomLineBatchCalculatorBackendType
  11. } from "../../OpenSheetMusicDisplay/OSMDOptions";
  12. import { ColoringModes as ColoringMode } from "./DrawingParameters";
  13. import { Dictionary } from "typescript-collections";
  14. import { FontStyles } from "../../Common/Enums";
  15. import { NoteEnum, AccidentalEnum } from "../../Common/DataObjects/Pitch";
  16. import { ChordSymbolEnum, CustomChord, DegreesInfo } from "../../MusicalScore/VoiceData/ChordSymbolContainer";
  17. import { GraphicalNote } from "./GraphicalNote";
  18. import { Note } from "../VoiceData/Note";
  19. /** Rendering and Engraving options, more fine-grained than [[IOSMDOptions]].
  20. * Not all of these options are meant to be modified by users of the library,
  21. * full support is only given for [[IOSMDOptions]].
  22. * Nevertheless, there are many useful options here,
  23. * like Render* to (not) render certain elements (e.g. osmd.rules.RenderRehearsalMarks = false)
  24. */
  25. export class EngravingRules {
  26. /** A unit of distance. 1.0 is the distance between lines of a stave for OSMD, which is 10 pixels in Vexflow. */
  27. public static unit: number = 1.0;
  28. public SamplingUnit: number;
  29. public StaccatoShorteningFactor: number;
  30. /** Height (size) of the sheet title. */
  31. public SheetTitleHeight: number;
  32. public SheetSubtitleHeight: number;
  33. public SheetMinimumDistanceBetweenTitleAndSubtitle: number;
  34. public SheetComposerHeight: number;
  35. public SheetAuthorHeight: number;
  36. public SheetCopyrightHeight: number;
  37. public SheetCopyrightMargin: number;
  38. public CompactMode: boolean;
  39. public PagePlacementEnum: PagePlacementEnum;
  40. public PageHeight: number;
  41. public PageTopMargin: number;
  42. public PageTopMarginNarrow: number;
  43. public PageBottomMargin: number;
  44. public PageLeftMargin: number;
  45. public PageRightMargin: number;
  46. public TitleTopDistance: number;
  47. public TitleBottomDistance: number;
  48. public SystemLeftMargin: number;
  49. public SystemRightMargin: number;
  50. public SystemLabelsRightMargin: number;
  51. public SystemComposerDistance: number;
  52. public InstrumentLabelTextHeight: number;
  53. public MinimumDistanceBetweenSystems: number;
  54. public MinSkyBottomDistBetweenSystems: number;
  55. public LastSystemMaxScalingFactor: number;
  56. public StaffDistance: number;
  57. public BetweenStaffDistance: number;
  58. public StaffHeight: number;
  59. public TabStaffInterlineHeight: number;
  60. public BetweenStaffLinesDistance: number;
  61. /** Whether to automatically beam notes that don't already have beams in XML. */
  62. public AutoBeamNotes: boolean;
  63. /** Options for autoBeaming like whether to beam over rests. See AutoBeamOptions interface. */
  64. public AutoBeamOptions: AutoBeamOptions;
  65. public AutoBeamTabs: boolean;
  66. public BeamWidth: number;
  67. public BeamSpaceWidth: number;
  68. public BeamForwardLength: number;
  69. public FlatBeams: boolean;
  70. public FlatBeamOffset: number;
  71. public FlatBeamOffsetPerBeam: number;
  72. public ClefLeftMargin: number;
  73. public ClefRightMargin: number;
  74. /** How many unique note positions a percussion score needs to have to not be rendered on one line. */
  75. public PercussionOneLineCutoff: number;
  76. public PercussionForceVoicesOneLineCutoff: number;
  77. public PercussionUseXMLDisplayStep: boolean;
  78. public PercussionXMLDisplayStepNoteValueShift: number;
  79. public PercussionOneLineXMLDisplayStepOctaveOffset: number;
  80. /** Makes the score position notes on the 2 cajon stafflines, and use 2 stafflines even if PercussionOneLineCutoff set.
  81. * Should only be set for cajon scores, as this will disable the PercussionOneLineCutoff.
  82. */
  83. public PercussionUseCajon2NoteSystem: boolean;
  84. public BetweenKeySymbolsDistance: number;
  85. public KeyRightMargin: number;
  86. public RhythmRightMargin: number;
  87. public ShowRhythmAgainAfterPartEndOrFinalBarline: boolean;
  88. public NewPartAndSystemAfterFinalBarline: boolean;
  89. public InStaffClefScalingFactor: number;
  90. public DistanceBetweenNaturalAndSymbolWhenCancelling: number;
  91. public NoteHelperLinesOffset: number;
  92. public MeasureLeftMargin: number;
  93. public MeasureRightMargin: number;
  94. public DistanceBetweenLastInstructionAndRepetitionBarline: number;
  95. public ArpeggioDistance: number;
  96. public IdealStemLength: number;
  97. public StemNoteHeadBorderYOffset: number;
  98. public StemWidth: number;
  99. public StemMargin: number;
  100. public StemMinLength: number;
  101. public StemMaxLength: number;
  102. public BeamSlopeMaxAngle: number;
  103. public StemMinAllowedDistanceBetweenNoteHeadAndBeamLine: number;
  104. public SetWantedStemDirectionByXml: boolean;
  105. public GraceNoteScalingFactor: number;
  106. public GraceNoteXOffset: number;
  107. public GraceNoteGroupXMargin: number;
  108. public WedgeOpeningLength: number;
  109. public WedgeMeasureEndOpeningLength: number;
  110. public WedgeMeasureBeginOpeningLength: number;
  111. public WedgePlacementAboveY: number;
  112. public WedgePlacementBelowY: number;
  113. public WedgeHorizontalMargin: number;
  114. public WedgeVerticalMargin: number;
  115. public DistanceOffsetBetweenTwoHorizontallyCrossedWedges: number;
  116. public WedgeMinLength: number;
  117. public WedgeEndDistanceBetweenTimestampsFactor: number;
  118. public SoftAccentWedgePadding: number;
  119. public SoftAccentSizeFactor: number;
  120. public DistanceBetweenAdjacentDynamics: number;
  121. public TempoChangeMeasureValidity: number;
  122. public TempoContinousFactor: number;
  123. public StaccatoScalingFactor: number;
  124. public BetweenDotsDistance: number;
  125. public OrnamentAccidentalScalingFactor: number;
  126. public ChordSymbolTextHeight: number;
  127. public ChordSymbolTextAlignment: TextAlignmentEnum;
  128. public ChordSymbolRelativeXOffset: number;
  129. /** Additional x-shift for short chord symbols (e.g. C, but not Eb/7), to appear more centered. */
  130. public ChordSymbolExtraXShiftForShortChordSymbols: number;
  131. /** Threshold width below which to apply ChordSymbolExtraXShiftForShortChordSymbols. */
  132. public ChordSymbolExtraXShiftWidthThreshold: number;
  133. public ChordSymbolXSpacing: number;
  134. public ChordOverlapAllowedIntoNextMeasure: number;
  135. public ChordSymbolYOffset: number;
  136. public ChordSymbolYPadding: number;
  137. public ChordSymbolYAlignment: boolean;
  138. public ChordSymbolYAlignmentScope: string;
  139. /** Offset to start of measure (barline) when chord symbol is on whole measure rest.
  140. * An offset of 0 would place the chord symbol directly above the barline, so the default is ~1.2.
  141. */
  142. public ChordSymbolWholeMeasureRestXOffset: number;
  143. public ChordSymbolWholeMeasureRestXOffsetMeasure1: number;
  144. public ChordSymbolLabelTexts: Dictionary<ChordSymbolEnum, string>;
  145. public ChordAccidentalTexts: Dictionary<AccidentalEnum, string>;
  146. public CustomChords: CustomChord[];
  147. /** Not always a symbol, can also be text (RepetitionInstruction). Keeping the name for backwards compatibility. */
  148. public RepetitionSymbolsYOffset: number;
  149. /** Adds a percent of the stave's width (e.g. 0.4 = 40%) to the x position of end instructions like Fine or D.C. al fine */
  150. public RepetitionEndInstructionXShiftAsPercentOfStaveWidth: number;
  151. public RehearsalMarkXOffset: number;
  152. public RehearsalMarkXOffsetDefault: number;
  153. public RehearsalMarkXOffsetSystemStartMeasure: number;
  154. public RehearsalMarkYOffset: number;
  155. public RehearsalMarkYOffsetDefault: number;
  156. public RehearsalMarkFontSize: number;
  157. public MeasureNumberLabelHeight: number;
  158. public MeasureNumberLabelOffset: number;
  159. public MeasureNumberLabelXOffset: number;
  160. /** Whether tuplets should display ratio (3:2 instead of 3 for triplet). Default false. */
  161. public TupletsRatioed: boolean;
  162. /** Whether tuplets (except triplets) should be bracketed (e.g. |--5--| instead of 5). Default false.
  163. * Note that this doesn't affect triplets (|--3--|), which have their own setting TripletsBracketed.
  164. * If false, only tuplets given as bracketed in XML (bracket="yes") will be bracketed.
  165. * (If not given in XML, bracketing is implementation-dependent according to standard)
  166. */
  167. public TupletsBracketed: boolean;
  168. /** Whether all triplets should be bracketed. Overrides tupletsBracketed for triplets.
  169. * If false, only triplets given as bracketed in XML (bracket="yes") will be bracketed.
  170. * (Bracketing all triplets can be cluttering)
  171. */
  172. public TripletsBracketed: boolean;
  173. /** Whether to bracket like the XML says when 'bracket="no"' or "yes" is given.
  174. * Otherwise, OSMD decides bracket usage.
  175. * Note that sometimes the XML doesn't have any 'bracket' value. */
  176. public TupletsBracketedUseXMLValue: boolean;
  177. public TupletNumberLabelHeight: number;
  178. public TupletNumberYOffset: number;
  179. public TupletNumberLimitConsecutiveRepetitions: boolean;
  180. public TupletNumberMaxConsecutiveRepetitions: number;
  181. public TupletNumberAlwaysDisableAfterFirstMax: boolean;
  182. /** Whether to use the <tuplet show-number="value"> value or to ignore it. */
  183. public TupletNumberUseShowNoneXMLValue: boolean;
  184. public LabelMarginBorderFactor: number;
  185. public TupletVerticalLineLength: number;
  186. public TupletNumbersInTabs: boolean;
  187. public TabBeamsRendered: boolean;
  188. public TabKeySignatureRendered: boolean;
  189. public TabTimeSignatureRendered: boolean;
  190. public TabFingeringsRendered: boolean;
  191. public RepetitionAllowFirstMeasureBeginningRepeatBarline: boolean;
  192. public RepetitionEndingLabelHeight: number;
  193. public RepetitionEndingLabelXOffset: number;
  194. public RepetitionEndingLabelYOffset: number;
  195. public RepetitionEndingLineYLowerOffset: number;
  196. public RepetitionEndingLineYUpperOffset: number;
  197. public VoltaOffset: number;
  198. /** Default alignment of lyrics.
  199. * Left alignments will extend text to the right of the bounding box,
  200. * which facilitates spacing by extending measure width.
  201. */
  202. public LyricsAlignmentStandard: TextAlignmentEnum;
  203. public LyricsHeight: number;
  204. public LyricsYOffsetToStaffHeight: number;
  205. public LyricsYMarginToBottomLine: number;
  206. /** Extra x-shift (to the right) for short lyrics to be better vertically aligned.
  207. * Also see ChordSymbolExtraXShiftForShortChordSymbols, same principle, same default value.
  208. */
  209. public LyricsExtraXShiftForShortLyrics: number;
  210. /** Threshold of the lyric entry's width below which the x-shift is applied. Default 1.4. */
  211. public LyricsExtraXShiftForShortLyricsWidthThreshold: number;
  212. /** Whether to enable x padding (to the right) for short notes, see LyricsXPaddingFactorForLongLyrics for the degree. */
  213. public LyricsUseXPaddingForShortNotes: boolean;
  214. /** How much spacing/padding should be added after notes with long lyrics on short notes
  215. * (>4 characters on <8th note),
  216. * so that the measure doesn't need to be elongated too much to avoid lyrics collisions.
  217. * Default 0.8 = 8 pixels */
  218. public LyricsXPaddingFactorForLongLyrics: number;
  219. /** How wide a text needs to be to trigger lyrics padding for short notes.
  220. * This is visual width, not number of characters, as e.g. 'zzz' is about as wide as 'iiii'.
  221. * Default 3.3.
  222. */
  223. public LyricsXPaddingWidthThreshold: number;
  224. public VerticalBetweenLyricsDistance: number;
  225. public HorizontalBetweenLyricsDistance: number;
  226. public BetweenSyllableMaximumDistance: number;
  227. public BetweenSyllableMinimumDistance: number;
  228. public LyricOverlapAllowedIntoNextMeasure: number;
  229. public MinimumDistanceBetweenDashes: number;
  230. public MaximumLyricsElongationFactor: number;
  231. public SlurPlacementFromXML: boolean;
  232. public SlurPlacementAtStems: boolean;
  233. public SlurPlacementUseSkyBottomLine: boolean;
  234. public BezierCurveStepSize: number;
  235. public TPower3: number[];
  236. public OneMinusTPower3: number[];
  237. public FactorOne: number[];
  238. public FactorTwo: number[];
  239. public TieGhostObjectWidth: number;
  240. public TieYPositionOffsetFactor: number;
  241. public MinimumNeededXspaceForTieGhostObject: number;
  242. public TieHeightMinimum: number;
  243. public TieHeightMaximum: number;
  244. public TieHeightInterpolationK: number;
  245. public TieHeightInterpolationD: number;
  246. public SlurNoteHeadYOffset: number;
  247. public SlurEndArticulationYOffset: number;
  248. public SlurStartArticulationYOffsetOfArticulation: number;
  249. public SlurStemXOffset: number;
  250. public SlurSlopeMaxAngle: number;
  251. public SlurTangentMinAngle: number;
  252. public SlurTangentMaxAngle: number;
  253. public SlurHeightFactor: number;
  254. public SlurHeightFlattenLongSlursFactorByWidth: number;
  255. public SlurHeightFlattenLongSlursFactorByAngle: number;
  256. public SlurHeightFlattenLongSlursCutoffAngle: number;
  257. public SlurHeightFlattenLongSlursCutoffWidth: number;
  258. public SlursStartingAtSameStaffEntryYOffset: number;
  259. public SlurMaximumYControlPointDistance: number;
  260. public GlissandoNoteOffset: number;
  261. public GlissandoStafflineStartMinimumWidth: number;
  262. public GlissandoStafflineStartYDistanceToNote: number;
  263. public GlissandoStafflineEndOffset: number;
  264. public GlissandoDefaultWidth: number;
  265. public TempoYSpacing: number;
  266. public InstantaneousTempoTextHeight: number;
  267. public ContinuousDynamicTextHeight: number;
  268. public MoodTextHeight: number;
  269. public UnknownTextHeight: number;
  270. public ContinuousTempoTextHeight: number;
  271. public VexFlowDefaultNotationFontScale: number;
  272. public VexFlowDefaultTabFontScale: number;
  273. public TremoloStrokeScale: number;
  274. public TremoloYSpacingScale: number;
  275. public TremoloBuzzRollThickness: number;
  276. public StaffLineWidth: number;
  277. public StaffLineColor: string;
  278. public LedgerLineWidth: number;
  279. public LedgerLineStrokeStyle: string;
  280. public LedgerLineColorDefault: string;
  281. public WedgeLineWidth: number;
  282. public TupletLineWidth: number;
  283. public LyricUnderscoreLineWidth: number;
  284. public SystemThinLineWidth: number;
  285. public SystemBoldLineWidth: number;
  286. public SystemRepetitionEndingLineWidth: number;
  287. public SystemDotWidth: number;
  288. public MultipleRestMeasureDefaultWidth: number;
  289. public MultipleRestMeasureAddKeySignature: boolean;
  290. /** Use the same measure width for all measures (experimental).
  291. * Note that this will use the largest width of all measures,
  292. * as Vexflow will mess up the layout with overlays if using less than minimum width.
  293. * See formatter.preCalculateMinTotalWidth()
  294. */
  295. public FixedMeasureWidth: boolean;
  296. /** Use a fixed width for all measures (experimental).
  297. * This is mostly for debugging or for when you already know how big the measures
  298. * in the target score are, because using a too low width will cause overlaps in Vexflow.
  299. */
  300. public FixedMeasureWidthFixedValue: number;
  301. public FixedMeasureWidthUseForPickupMeasures: boolean;
  302. public DistanceBetweenVerticalSystemLines: number;
  303. public DistanceBetweenDotAndLine: number;
  304. public RepeatEndStartPadding: number;
  305. public OctaveShiftLineWidth: number;
  306. public OctaveShiftVerticalLineLength: number;
  307. public OctaveShiftOnWholeMeasureNoteUntilEndOfMeasure: boolean;
  308. public GraceLineWidth: number;
  309. public MinimumStaffLineDistance: number;
  310. public MinSkyBottomDistBetweenStaves: number;
  311. public MinimumCrossedBeamDifferenceMargin: number;
  312. /** Maximum width of sheet / HTMLElement containing the score. Canvas is limited to 32767 in current browsers, though SVG isn't.
  313. * Setting this to > 32767 will break the canvas backend (no problem if you only use SVG).
  314. */
  315. public SheetMaximumWidth: number;
  316. public VoiceSpacingMultiplierVexflow: number;
  317. public VoiceSpacingAddendVexflow: number;
  318. public PickupMeasureWidthMultiplier: number;
  319. /** The spacing between a repetition that is followed by an implicit/pickup/incomplete measure.
  320. * (E.g. in a 4/4 time signature, a measure that repeats after the 3rd beat, continuing with a pickup measure)
  321. */
  322. public PickupMeasureRepetitionSpacing: number;
  323. /** Multiplier for PickupMeasureRepetitionSpacing if there is only one note in the pickup measure. This usually needs a lot more space. */
  324. public PickupMeasureSpacingSingleNoteAddend: number;
  325. public DisplacedNoteMargin: number;
  326. public MinNoteDistance: number;
  327. public SubMeasureXSpacingThreshold: number;
  328. public MeasureDynamicsMaxScalingFactor: number;
  329. public WholeRestXShiftVexflow: number;
  330. public MetronomeMarksDrawn: boolean;
  331. public MetronomeMarkXShift: number;
  332. public MetronomeMarkYShift: number;
  333. public SoftmaxFactorVexFlow: number;
  334. /** Stagger (x-shift) whole notes that are the same note, but in different voices (show 2 instead of 1). */
  335. public StaggerSameWholeNotes: boolean;
  336. public MaxInstructionsConstValue: number;
  337. public NoteDistances: number[] = [1.0, 1.0, 1.3, 1.6, 2.0, 2.5, 3.0, 4.0];
  338. public NoteDistancesScalingFactors: number[] = [1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0];
  339. public DurationDistanceDict: {[_: number]: number } = {};
  340. public DurationScalingDistanceDict: {[_: number]: number } = {};
  341. /** Whether to align rests. 0 = Never, 1 = Always, 2 = Auto.
  342. * Currently not recommended because rests are now positioned to avoid collisions with notes. */
  343. public AlignRests: AlignRestOption; // 0 = false, 1 = true, 2 = auto
  344. public RestCollisionYPadding: number;
  345. public FillEmptyMeasuresWithWholeRest: FillEmptyMeasuresWithWholeRests | number;
  346. public ArpeggiosGoAcrossVoices: boolean;
  347. public RenderArpeggios: boolean;
  348. public RenderSlurs: boolean;
  349. public RenderGlissandi: boolean;
  350. public ColoringMode: ColoringMode;
  351. public ColoringEnabled: boolean;
  352. public ColorStemsLikeNoteheads: boolean;
  353. public ColorFlags: boolean;
  354. public ColorBeams: boolean;
  355. public ColoringSetCurrent: Dictionary<NoteEnum|number, string>;
  356. /** Default color for all musical elements including key signature etc. Default undefined. */
  357. public DefaultColorMusic: string;
  358. public DefaultColorNotehead: string;
  359. public DefaultColorRest: string;
  360. public DefaultColorStem: string;
  361. public DefaultColorLabel: string;
  362. public DefaultColorLyrics: string;
  363. public DefaultColorChordSymbol: string;
  364. public DefaultColorTitle: string;
  365. public DefaultColorCursor: string;
  366. public DefaultFontFamily: string;
  367. public DefaultFontStyle: FontStyles;
  368. public DefaultVexFlowNoteFont: string;
  369. public MaxMeasureToDrawIndex: number;
  370. public MinMeasureToDrawIndex: number;
  371. public MaxPageToDrawNumber: number;
  372. public MaxSystemToDrawNumber: number;
  373. /** Whether to render a label for the composer of the piece at the top of the sheet. */
  374. public RenderComposer: boolean;
  375. public RenderTitle: boolean;
  376. public RenderSubtitle: boolean;
  377. public RenderLyricist: boolean;
  378. public RenderCopyright: boolean;
  379. public RenderPartNames: boolean;
  380. public RenderPartAbbreviations: boolean;
  381. public RenderFingerings: boolean;
  382. public RenderMeasureNumbers: boolean;
  383. public RenderMeasureNumbersOnlyAtSystemStart: boolean;
  384. public UseXMLMeasureNumbers: boolean;
  385. public RenderLyrics: boolean;
  386. public RenderChordSymbols: boolean;
  387. public RenderMultipleRestMeasures: boolean;
  388. public AutoGenerateMultipleRestMeasuresFromRestMeasures: boolean;
  389. public RenderRehearsalMarks: boolean;
  390. public RenderClefsAtBeginningOfStaffline: boolean;
  391. public RenderKeySignatures: boolean;
  392. public RenderTimeSignatures: boolean;
  393. public RenderPedals: boolean;
  394. public RenderWavyLines: boolean;
  395. public DynamicExpressionMaxDistance: number;
  396. public DynamicExpressionSpacer: number;
  397. public IgnoreRepeatedDynamics: boolean;
  398. public MpatMode: boolean;
  399. public ArticulationPlacementFromXML: boolean;
  400. /** Percent distance of breath marks to next note or end of staff, e.g. 0.8 = 80%. */
  401. public BreathMarkDistance: number;
  402. /** Where to draw fingerings (Above, Below, AboveOrBelow, Left, Right, or Auto).
  403. * Default AboveOrBelow. Auto experimental. */
  404. public FingeringPosition: PlacementEnum;
  405. public FingeringPositionFromXML: boolean;
  406. public FingeringPositionGrace: PlacementEnum;
  407. public FingeringInsideStafflines: boolean;
  408. public FingeringLabelFontHeight: number;
  409. public FingeringOffsetX: number;
  410. public FingeringOffsetY: number;
  411. public FingeringPaddingY: number;
  412. public FingeringTextSize: number;
  413. /** Whether to render string numbers in classical scores, i.e. not the string numbers in tabs, but e.g. for violin. */
  414. public RenderStringNumbersClassical: boolean;
  415. /** This is not for tabs, but for classical scores, especially violin. */
  416. public StringNumberOffsetY: number;
  417. public NewSystemAtXMLNewSystemAttribute: boolean;
  418. /** Whether to begin a new system when a page break is given in XML ('new-page="yes"'), but newPageFromXML is false.
  419. * Default false, because it can lead to nonsensical system breaks after a single measure,
  420. * as OSMD does a different layout than the original music program exported from.
  421. * */
  422. public NewSystemAtXMLNewPageAttribute: boolean;
  423. public NewPageAtXMLNewPageAttribute: boolean;
  424. public UseJustifiedBuilder: boolean;
  425. public PageFormat: PageFormat;
  426. public PageBackgroundColor: string; // vexflow-color-string (#FFFFFF). Default undefined/transparent.
  427. public PerformanceMode: boolean;
  428. public RenderSingleHorizontalStaffline: boolean;
  429. public RestoreCursorAfterRerender: boolean;
  430. public StretchLastSystemLine: boolean;
  431. /** Ignore brackets - e.g. `( )` - that were supposed to be around a note,
  432. * but were inserted as a words element in the MusicXML, which can't be matched to the note anymore,
  433. * and would otherwise just be placed somewhere else. See OSMD Issue 1251. */
  434. public IgnoreBracketsWords: boolean;
  435. public PlaceWordsInsideStafflineFromXml: boolean;
  436. public PlaceWordsInsideStafflineYOffset: number;
  437. // public PositionMarcatoCloseToNote: boolean;
  438. public SpacingBetweenTextLines: number;
  439. public NoteToGraphicalNoteMap: Dictionary<number, GraphicalNote>;
  440. // this is basically a WeakMap, except we save the id in the Note instead of using a WeakMap.
  441. public NoteToGraphicalNoteMapObjectCount: number = 0;
  442. /** How many times osmd.render() was already called on the currently loaded score.
  443. * Resets after osmd.load() (via osmd.reset()).
  444. * Can be relevant for transposition or generally informative.
  445. */
  446. public RenderCount: number = 0;
  447. /** The skyline and bottom-line batch calculation algorithm to use.
  448. * Note that this can be overridden if AlwaysSetPreferredSkyBottomLineBackendAutomatically is true (which is the default).
  449. */
  450. public PreferredSkyBottomLineBatchCalculatorBackend: SkyBottomLineBatchCalculatorBackendType;
  451. /** Whether to consider using WebGL in Firefox in EngravingRules.setPreferredSkyBottomLineBackendAutomatically() */
  452. public DisableWebGLInFirefox: boolean;
  453. /** Whether to consider using WebGL in Safari/iOS in EngravingRules.setPreferredSkyBottomLineBackendAutomatically() */
  454. public DisableWebGLInSafariAndIOS: boolean;
  455. /** The minimum number of measures in the sheet where the skyline and bottom-line batch calculation is enabled.
  456. * Batch is faster for medium to large size scores, but slower for very short scores.
  457. */
  458. public SkyBottomLineBatchMinMeasures: number;
  459. /** The minimum number of measures in the sheet where WebGL will be used. WebGL is slower for short scores, but much faster for large ones.
  460. * Note that WebGL is currently never used in Safari and Firefox, because it's always slower there.
  461. */
  462. public SkyBottomLineWebGLMinMeasures: number;
  463. /** Whether to always set preferred backend (WebGL or Plain) automatically, depending on browser and number of measures. */
  464. public AlwaysSetPreferredSkyBottomLineBackendAutomatically: boolean;
  465. // Playback section (these are not about "engraving", but EngravingRules are the one object that is available in most places in OSMD)
  466. public PlayAlreadyStartedNotesFromCursorPosition: boolean = false;
  467. /** The interval between current timer position and note timestamp beyond which notes are not played.
  468. * If you experience notes being skipped during playback, try increasing this interval slightly (e.g. 0.02 -> 0.03).
  469. */
  470. public PlaybackSkipNotesSafetyInterval: number = 0.02;
  471. /** Whether to use OSMD's default voice entry interaction listener that plays voice entry on click etc. */
  472. public UseDefaultVoiceInteractionListener: boolean = true;
  473. public LimitCursorPositionToCurrentMeasure: boolean = true;
  474. constructor() {
  475. this.loadDefaultValues();
  476. }
  477. public loadDefaultValues(): void {
  478. // global variables
  479. this.SamplingUnit = EngravingRules.unit * 3;
  480. // mpat specific settings
  481. this.MpatMode = true;
  482. // Page Label Variables
  483. this.SheetTitleHeight = 4.0;
  484. this.SheetSubtitleHeight = 2.0;
  485. this.SheetMinimumDistanceBetweenTitleAndSubtitle = 1.0;
  486. this.SheetComposerHeight = 2.0;
  487. this.SheetAuthorHeight = 2.0;
  488. this.SheetCopyrightHeight = 1.5;
  489. this.SheetCopyrightMargin = 2.0;
  490. // Staff sizing Variables
  491. this.CompactMode = false;
  492. this.PagePlacementEnum = PagePlacementEnum.Down;
  493. this.PageHeight = 100001.0;
  494. this.PageTopMargin = 5.0;
  495. this.PageTopMarginNarrow = 0.0; // for compact mode
  496. this.PageBottomMargin = 5.0;
  497. this.PageLeftMargin = 5.0;
  498. this.PageRightMargin = 5.0;
  499. this.TitleTopDistance = 5.0;
  500. this.TitleBottomDistance = 1.0;
  501. this.StaffDistance = 7.0;
  502. this.BetweenStaffDistance = 5.0;
  503. this.MinimumStaffLineDistance = 4.0;
  504. this.MinSkyBottomDistBetweenStaves = 1.0; // default. compacttight mode sets it to 1.0 (as well).
  505. // System Sizing and Label Variables
  506. this.StaffHeight = 4.0;
  507. this.TabStaffInterlineHeight = 1.1111;
  508. this.BetweenStaffLinesDistance = EngravingRules.unit;
  509. this.SystemLeftMargin = 0.0;
  510. this.SystemRightMargin = 0.0;
  511. this.SystemLabelsRightMargin = 2.0;
  512. this.SystemComposerDistance = 2.0;
  513. this.InstrumentLabelTextHeight = 2;
  514. this.MinimumDistanceBetweenSystems = 7.0;
  515. this.MinSkyBottomDistBetweenSystems = 5.0;
  516. this.LastSystemMaxScalingFactor = 1.4;
  517. // autoBeam options
  518. this.AutoBeamNotes = false;
  519. this.AutoBeamOptions = {
  520. beam_middle_rests_only: false,
  521. beam_rests: false,
  522. maintain_stem_directions: false
  523. };
  524. this.AutoBeamTabs = false;
  525. // Beam Sizing Variables
  526. this.BeamWidth = EngravingRules.unit / 2.0;
  527. this.BeamSpaceWidth = EngravingRules.unit / 3.0;
  528. this.BeamForwardLength = 1.25 * EngravingRules.unit;
  529. this.FlatBeams = false;
  530. this.FlatBeamOffset = 20;
  531. this.FlatBeamOffsetPerBeam = 10;
  532. // Beam Sizing Variables
  533. this.ClefLeftMargin = 0.5;
  534. this.ClefRightMargin = 0.75;
  535. this.PercussionOneLineCutoff = 3; // percussion parts with <3 unique note positions rendered on one line
  536. this.PercussionForceVoicesOneLineCutoff = 1;
  537. this.PercussionUseXMLDisplayStep = true;
  538. this.PercussionXMLDisplayStepNoteValueShift = 0;
  539. this.PercussionOneLineXMLDisplayStepOctaveOffset = 0;
  540. this.PercussionUseCajon2NoteSystem = false;
  541. this.BetweenKeySymbolsDistance = 0.2;
  542. this.KeyRightMargin = 0.75;
  543. this.RhythmRightMargin = 1.25;
  544. this.ShowRhythmAgainAfterPartEndOrFinalBarline = true;
  545. this.NewPartAndSystemAfterFinalBarline = false;
  546. this.InStaffClefScalingFactor = 0.8;
  547. this.DistanceBetweenNaturalAndSymbolWhenCancelling = 0.4;
  548. // Beam Sizing Variables
  549. this.NoteHelperLinesOffset = 0.25;
  550. this.MeasureLeftMargin = 0.7;
  551. this.MeasureRightMargin = 0.0;
  552. this.DistanceBetweenLastInstructionAndRepetitionBarline = 1.0;
  553. this.ArpeggioDistance = 0.6;
  554. // Stems Variables
  555. this.StaccatoShorteningFactor = 2;
  556. this.IdealStemLength = 3.0;
  557. this.StemNoteHeadBorderYOffset = 0.2;
  558. this.StemMargin = 0.2;
  559. this.StemMinLength = 2.5;
  560. this.StemMaxLength = 4.5;
  561. this.BeamSlopeMaxAngle = 10.0;
  562. this.StemMinAllowedDistanceBetweenNoteHeadAndBeamLine = 1.0;
  563. this.SetWantedStemDirectionByXml = true;
  564. // also see stemwidth further below
  565. // GraceNote Variables
  566. this.GraceNoteScalingFactor = 0.6;
  567. this.GraceNoteXOffset = 0.2;
  568. this.GraceNoteGroupXMargin = 0.0; // More than 0 leads to too much space in most cases.
  569. // see test_end_clef_measure. only potential 'tight' case: test_graceslash_simple
  570. // Wedge Variables
  571. this.WedgeOpeningLength = 1.2;
  572. this.WedgeMeasureEndOpeningLength = 0.75;
  573. this.WedgeMeasureBeginOpeningLength = 0.75;
  574. this.WedgePlacementAboveY = -1.5;
  575. this.WedgePlacementBelowY = 1.5;
  576. this.WedgeHorizontalMargin = 0.6;
  577. this.WedgeVerticalMargin = 0.5;
  578. this.DistanceOffsetBetweenTwoHorizontallyCrossedWedges = 0.3;
  579. this.WedgeMinLength = 2.0;
  580. this.WedgeEndDistanceBetweenTimestampsFactor = 1.75;
  581. this.SoftAccentWedgePadding = 0.4;
  582. this.SoftAccentSizeFactor = 0.6;
  583. this.DistanceBetweenAdjacentDynamics = 0.75;
  584. // Tempo Variables
  585. this.TempoChangeMeasureValidity = 4;
  586. this.TempoContinousFactor = 0.7;
  587. // various
  588. this.StaccatoScalingFactor = 0.8;
  589. this.BetweenDotsDistance = 0.8;
  590. this.OrnamentAccidentalScalingFactor = 0.65;
  591. this.ChordSymbolTextHeight = 2.0;
  592. this.ChordSymbolTextAlignment = TextAlignmentEnum.LeftBottom;
  593. this.ChordSymbolRelativeXOffset = -1.0;
  594. this.ChordSymbolExtraXShiftForShortChordSymbols = 0.3; // also see LyricsExtraXShiftForShortLyrics, same principle
  595. this.ChordSymbolExtraXShiftWidthThreshold = 2.0;
  596. this.ChordSymbolXSpacing = 1.0;
  597. this.ChordOverlapAllowedIntoNextMeasure = 0;
  598. this.ChordSymbolYOffset = 0.1;
  599. this.ChordSymbolYPadding = 0.0;
  600. this.ChordSymbolYAlignment = true;
  601. this.ChordSymbolYAlignmentScope = "staffline"; // "measure" or "staffline"
  602. this.ChordSymbolWholeMeasureRestXOffset = 0;
  603. this.ChordSymbolWholeMeasureRestXOffsetMeasure1 = -2.0;
  604. this.ChordAccidentalTexts = new Dictionary<AccidentalEnum, string>();
  605. this.resetChordAccidentalTexts(this.ChordAccidentalTexts, false);
  606. this.ChordSymbolLabelTexts = new Dictionary<ChordSymbolEnum, string>();
  607. this.resetChordSymbolLabelTexts(this.ChordSymbolLabelTexts);
  608. this.CustomChords = [];
  609. this.resetChordNames();
  610. this.RepetitionSymbolsYOffset = 0;
  611. this.RepetitionEndInstructionXShiftAsPercentOfStaveWidth = 0.4; // 40%
  612. this.RehearsalMarkXOffsetDefault = 10; // avoid collision with metronome number
  613. this.RehearsalMarkXOffset = 0; // user defined
  614. this.RehearsalMarkXOffsetSystemStartMeasure = -20; // good test: Haydn Concertante
  615. this.RehearsalMarkYOffsetDefault = -15;
  616. this.RehearsalMarkYOffset = 0; // user defined
  617. this.RehearsalMarkFontSize = 10; // vexflow default: 12, too big with chord symbols
  618. // Tuplets, MeasureNumber and TupletNumber Labels
  619. this.MeasureNumberLabelHeight = 1.5 * EngravingRules.unit;
  620. this.MeasureNumberLabelOffset = 2;
  621. this.MeasureNumberLabelXOffset = -0.5;
  622. this.TupletsRatioed = false;
  623. this.TupletsBracketed = false;
  624. this.TripletsBracketed = false; // special setting for triplets, overrides tuplet setting (for triplets only)
  625. this.TupletsBracketedUseXMLValue = true;
  626. this.TupletNumberLabelHeight = 1.5 * EngravingRules.unit;
  627. this.TupletNumberYOffset = 0.5;
  628. this.TupletNumberLimitConsecutiveRepetitions = true;
  629. this.TupletNumberMaxConsecutiveRepetitions = 2;
  630. this.TupletNumberAlwaysDisableAfterFirstMax = true;
  631. this.TupletNumberUseShowNoneXMLValue = true;
  632. this.LabelMarginBorderFactor = 0.1;
  633. this.TupletVerticalLineLength = 0.5;
  634. this.TupletNumbersInTabs = false; // disabled by default, nonstandard in tabs, at least how we show them in non-tabs.
  635. this.TabBeamsRendered = true;
  636. this.TabKeySignatureRendered = false; // standard not to render for tab scores
  637. this.TabTimeSignatureRendered = false; // standard not to render for tab scores
  638. this.TabFingeringsRendered = false; // tabs usually don't show fingering. This can also be duplicated when you have a classical+tab score.
  639. // Slur and Tie variables
  640. this.SlurPlacementFromXML = true;
  641. this.SlurPlacementAtStems = false;
  642. this.SlurPlacementUseSkyBottomLine = false;
  643. this.BezierCurveStepSize = 1000;
  644. this.calculateCurveParametersArrays();
  645. this.TieGhostObjectWidth = 0.75;
  646. this.TieYPositionOffsetFactor = 0.3;
  647. this.MinimumNeededXspaceForTieGhostObject = 1.0;
  648. this.TieHeightMinimum = 0.28;
  649. this.TieHeightMaximum = 1.2;
  650. this.TieHeightInterpolationK = 0.0288;
  651. this.TieHeightInterpolationD = 0.136;
  652. this.SlurNoteHeadYOffset = 0.5;
  653. this.SlurEndArticulationYOffset = 0.8;
  654. this.SlurStartArticulationYOffsetOfArticulation = 0.5;
  655. this.SlurStemXOffset = 0.3;
  656. this.SlurSlopeMaxAngle = 15.0;
  657. this.SlurTangentMinAngle = 30.0;
  658. this.SlurTangentMaxAngle = 80.0;
  659. this.SlurHeightFactor = 1; // 1 = 100% (standard height). 2 = 100% flattening of all slurs.
  660. this.SlurHeightFlattenLongSlursFactorByWidth = 0.24; // additional flattening for long slurs the longer they are.
  661. this.SlurHeightFlattenLongSlursFactorByAngle = 0.36; // when one of these factors is high, increasing the other has a very strong effect.
  662. this.SlurHeightFlattenLongSlursCutoffAngle = 47;
  663. this.SlurHeightFlattenLongSlursCutoffWidth = 16; // 15 ~ slur between measure's first notes in 4/4. 14 -> problem with test_slurs_highNotes
  664. this.SlursStartingAtSameStaffEntryYOffset = 0.8;
  665. //Maximum y difference between control points. Forces slurs to have less 'weight' either way in the x direction
  666. this.SlurMaximumYControlPointDistance = undefined;
  667. // Glissandi
  668. this.GlissandoNoteOffset = 0.5;
  669. this.GlissandoStafflineStartMinimumWidth = 1;
  670. this.GlissandoStafflineStartYDistanceToNote = 0.8; // just crossing the line above/below end note. should be similar to tab slide angle.
  671. this.GlissandoStafflineEndOffset = 1;
  672. this.GlissandoDefaultWidth = 0.1;
  673. // Repetitions
  674. this.RepetitionAllowFirstMeasureBeginningRepeatBarline = false;
  675. this.RepetitionEndingLabelHeight = 2.0;
  676. this.RepetitionEndingLabelXOffset = 0.5;
  677. this.RepetitionEndingLabelYOffset = 0.3;
  678. this.RepetitionEndingLineYLowerOffset = 0.5;
  679. this.RepetitionEndingLineYUpperOffset = 0.3;
  680. this.VoltaOffset = 2.5;
  681. // Lyrics
  682. this.LyricsAlignmentStandard = TextAlignmentEnum.LeftBottom; // CenterBottom and LeftBottom tested, spacing-optimized
  683. this.LyricsHeight = 2.0; // actually size of lyrics
  684. this.LyricsYOffsetToStaffHeight = 0.0; // distance between lyrics and staff. could partly be even lower/dynamic
  685. this.LyricsYMarginToBottomLine = 0.2;
  686. this.LyricsExtraXShiftForShortLyrics = 0.5; // also see ChordSymbolExtraXShiftForShortChordSymbols, same principle
  687. this.LyricsExtraXShiftForShortLyricsWidthThreshold = 1.4; // width of '+': 1.12, 'II': 1.33 (benefits from x-shift), 'III': 1.99 (doesn't benefit)
  688. this.LyricsUseXPaddingForShortNotes = true;
  689. this.LyricsXPaddingFactorForLongLyrics = 0.8;
  690. this.LyricsXPaddingWidthThreshold = 3.3;
  691. this.VerticalBetweenLyricsDistance = 0.5;
  692. this.HorizontalBetweenLyricsDistance = 0.2;
  693. this.BetweenSyllableMaximumDistance = 10.0;
  694. this.BetweenSyllableMinimumDistance = 0.5; // + 1.0 for CenterAlignment added in lyrics spacing
  695. this.LyricOverlapAllowedIntoNextMeasure = 3.4; // optimal for dashed last lyric, see Land der Berge
  696. this.MinimumDistanceBetweenDashes = 10;
  697. this.MaximumLyricsElongationFactor = 2.5;
  698. // expressions variables
  699. this.TempoYSpacing = 0.5; // note this is correlated with MetronomeMarkYShift: one-sided change can cause collisions
  700. this.InstantaneousTempoTextHeight = 2.3;
  701. this.ContinuousDynamicTextHeight = 2.3;
  702. this.MoodTextHeight = 2.3;
  703. this.UnknownTextHeight = 2.0;
  704. this.ContinuousTempoTextHeight = 2.3;
  705. this.DynamicExpressionMaxDistance = 2;
  706. this.DynamicExpressionSpacer = 0.5;
  707. this.IgnoreRepeatedDynamics = false;
  708. // Line Widths
  709. this.VexFlowDefaultNotationFontScale = 39; // scales notes, including rests. default value 39 in Vexflow.
  710. this.VexFlowDefaultTabFontScale = 39;
  711. this.TremoloStrokeScale = 1;
  712. this.TremoloYSpacingScale = 1;
  713. this.TremoloBuzzRollThickness = 0.25;
  714. this.StemWidth = 0.15; // originally 0.13. vexflow default 0.15. should probably be adjusted when increasing vexFlowDefaultNotationFontScale,
  715. this.StaffLineWidth = 0.10; // originally 0.12, but this will be pixels in Vexflow (*10).
  716. this.StaffLineColor = undefined; // if undefined, vexflow default (grey). not a width, but affects visual line clarity.
  717. this.LedgerLineWidth = 1; // vexflow units (pixels). if not undefined, the vexflow default will be overwritten
  718. this.LedgerLineStrokeStyle = undefined; // if not undefined, the vexflow default will be overwritten
  719. this.LedgerLineColorDefault = "#000000"; // black, previously grey by default
  720. this.WedgeLineWidth = 0.12;
  721. this.TupletLineWidth = 0.12;
  722. this.LyricUnderscoreLineWidth = 0.12;
  723. this.SystemThinLineWidth = 0.12;
  724. this.SystemBoldLineWidth = EngravingRules.unit / 2.0;
  725. this.SystemRepetitionEndingLineWidth = 0.12;
  726. this.SystemDotWidth = EngravingRules.unit / 2.0;
  727. this.DistanceBetweenVerticalSystemLines = 0.35;
  728. this.DistanceBetweenDotAndLine = 0.7;
  729. this.RepeatEndStartPadding = 2.0; // set to 0.0 to restore old padding/width with :||: measures
  730. this.OctaveShiftLineWidth = 0.12;
  731. this.OctaveShiftVerticalLineLength = EngravingRules.unit;
  732. this.OctaveShiftOnWholeMeasureNoteUntilEndOfMeasure = false;
  733. this.GraceLineWidth = this.StaffLineWidth * this.GraceNoteScalingFactor;
  734. this.MultipleRestMeasureDefaultWidth = 4;
  735. this.MultipleRestMeasureAddKeySignature = true;
  736. this.FixedMeasureWidth = false;
  737. this.FixedMeasureWidthFixedValue = undefined; // only set to a number x if the width should be always x
  738. this.FixedMeasureWidthUseForPickupMeasures = false;
  739. // Line Widths
  740. this.MinimumCrossedBeamDifferenceMargin = 0.0001;
  741. // Canvas is limited to 32767 in most browsers, though SVG isn't.
  742. this.SheetMaximumWidth = 32767;
  743. // xSpacing Variables
  744. this.VoiceSpacingMultiplierVexflow = 0.85;
  745. this.VoiceSpacingAddendVexflow = 3.0;
  746. this.PickupMeasureWidthMultiplier = 1.0;
  747. this.PickupMeasureRepetitionSpacing = 0.8;
  748. this.PickupMeasureSpacingSingleNoteAddend = 1.6;
  749. this.DisplacedNoteMargin = 0.1;
  750. this.MinNoteDistance = 2.0;
  751. this.SubMeasureXSpacingThreshold = 35;
  752. this.MeasureDynamicsMaxScalingFactor = 2.5;
  753. this.WholeRestXShiftVexflow = -1.5; // VexFlow draws rest notes too far to the right
  754. this.MetronomeMarksDrawn = true;
  755. this.MetronomeMarkXShift = -6; // our unit, is taken * unitInPixels
  756. this.MetronomeMarkYShift = -1.0; // note this is correlated with TempoYSpacing: one-sided change can cause collisions
  757. this.SoftmaxFactorVexFlow = 15; // only applies to Vexflow 3.x. 15 seems like the sweet spot. Vexflow default is 100.
  758. // if too high, score gets too big, especially half notes. with half note quarter quarter, the quarters get squeezed.
  759. // if too low, smaller notes aren't positioned correctly.
  760. this.StaggerSameWholeNotes = true;
  761. // Render options (whether to render specific or invisible elements)
  762. this.AlignRests = AlignRestOption.Never; // 0 = false, 1 = true, 2 = auto
  763. this.RestCollisionYPadding = 0.0; // 1.0 = half distance between staff lines (e.g. E to F). will be rounded to whole numbers.
  764. this.FillEmptyMeasuresWithWholeRest = FillEmptyMeasuresWithWholeRests.No;
  765. this.ArpeggiosGoAcrossVoices = false; // safe option, as otherwise arpeggios will always go across all voices in Vexflow, which is often unwanted
  766. this.RenderArpeggios = true;
  767. this.RenderSlurs = true;
  768. this.RenderGlissandi = true;
  769. this.ColoringMode = ColoringMode.XML;
  770. this.ColoringEnabled = true;
  771. this.ColorStemsLikeNoteheads = false;
  772. this.ColorBeams = true;
  773. this.ColorFlags = true;
  774. this.applyDefaultColorMusic("#000000"); // black. undefined is only black if a note's color hasn't been changed before.
  775. this.DefaultColorCursor = "#33e02f"; // green
  776. this.DefaultFontFamily = "Times New Roman"; // what OSMD was initially optimized for
  777. this.DefaultFontStyle = FontStyles.Regular;
  778. this.DefaultVexFlowNoteFont = "gonville"; // was the default vexflow font up to vexflow 1.2.93, now it's Bravura, which is more cursive/bold
  779. this.MaxMeasureToDrawIndex = Number.MAX_VALUE;
  780. this.MinMeasureToDrawIndex = 0;
  781. this.MaxSystemToDrawNumber = Number.MAX_VALUE;
  782. this.MaxPageToDrawNumber = Number.MAX_VALUE;
  783. this.RenderComposer = true;
  784. this.RenderTitle = true;
  785. this.RenderSubtitle = true;
  786. this.RenderLyricist = true;
  787. this.RenderCopyright = false;
  788. this.RenderPartNames = true;
  789. this.RenderPartAbbreviations = true;
  790. this.RenderFingerings = true;
  791. this.RenderMeasureNumbers = true;
  792. this.RenderMeasureNumbersOnlyAtSystemStart = false;
  793. this.UseXMLMeasureNumbers = true;
  794. this.RenderLyrics = true;
  795. this.RenderChordSymbols = true;
  796. this.RenderMultipleRestMeasures = true;
  797. this.AutoGenerateMultipleRestMeasuresFromRestMeasures = true;
  798. this.RenderRehearsalMarks = true;
  799. this.RenderClefsAtBeginningOfStaffline = true;
  800. this.RenderKeySignatures = true;
  801. this.RenderTimeSignatures = true;
  802. this.RenderPedals = true;
  803. this.RenderWavyLines = true;
  804. this.ArticulationPlacementFromXML = true;
  805. this.BreathMarkDistance = 0.8;
  806. this.FingeringPosition = PlacementEnum.AboveOrBelow; // AboveOrBelow = correct bounding boxes
  807. this.FingeringPositionFromXML = true;
  808. this.FingeringPositionGrace = PlacementEnum.Left;
  809. this.FingeringInsideStafflines = false;
  810. this.FingeringLabelFontHeight = 1.7;
  811. this.FingeringOffsetX = 0.0;
  812. this.FingeringOffsetY = 0.0;
  813. this.FingeringPaddingY = -0.2;
  814. this.FingeringTextSize = 1.5;
  815. this.RenderStringNumbersClassical = true;
  816. this.StringNumberOffsetY = 0.0;
  817. this.NewSystemAtXMLNewSystemAttribute = false;
  818. this.NewPageAtXMLNewPageAttribute = false;
  819. this.NewSystemAtXMLNewPageAttribute = false;
  820. this.RestoreCursorAfterRerender = true;
  821. this.StretchLastSystemLine = false;
  822. this.IgnoreBracketsWords = true;
  823. this.PlaceWordsInsideStafflineFromXml = false;
  824. this.PlaceWordsInsideStafflineYOffset = 0.9;
  825. // this.PositionMarcatoCloseToNote = true;
  826. this.UseJustifiedBuilder = true;
  827. this.PageFormat = PageFormat.UndefinedPageFormat; // default: undefined / 'infinite' height page, using the canvas'/container's width and height
  828. this.PageBackgroundColor = undefined; // default: transparent. half-transparent white: #FFFFFF88"
  829. this.PerformanceMode = false;
  830. this.RenderSingleHorizontalStaffline = false;
  831. this.SpacingBetweenTextLines = 0;
  832. this.NoteToGraphicalNoteMap = new Dictionary<number, GraphicalNote>();
  833. this.NoteToGraphicalNoteMapObjectCount = 0;
  834. this.SkyBottomLineBatchMinMeasures = 5;
  835. this.SkyBottomLineWebGLMinMeasures = 80;
  836. this.AlwaysSetPreferredSkyBottomLineBackendAutomatically = true;
  837. this.DisableWebGLInFirefox = true;
  838. this.DisableWebGLInSafariAndIOS = true;
  839. this.setPreferredSkyBottomLineBackendAutomatically();
  840. // this.populateDictionaries(); // these values aren't used currently
  841. try {
  842. this.MaxInstructionsConstValue = this.ClefLeftMargin + this.ClefRightMargin + this.KeyRightMargin + this.RhythmRightMargin + 11;
  843. //if (FontInfo.Info) {
  844. // this.maxInstructionsConstValue += FontInfo.Info.getBoundingBox(MusicSymbol.G_CLEF).width
  845. // + FontInfo.Info.getBoundingBox(MusicSymbol.FOUR).width
  846. // + 7 * FontInfo.Info.getBoundingBox(MusicSymbol.SHARP).width;
  847. //}
  848. } catch (ex) {
  849. log.info("EngravingRules()", ex);
  850. }
  851. // collect mpat-specific changes at the end
  852. if (this.MpatMode) {
  853. this.NewPartAndSystemAfterFinalBarline = true;
  854. }
  855. }
  856. public setPreferredSkyBottomLineBackendAutomatically(numberOfGraphicalMeasures: number = -1): void {
  857. let vendor: string = "";
  858. let userAgent: string = "";
  859. if (typeof globalThis === "object") { // it looks like globalThis can be undefined and cause build issues in es2017 (e.g. Android API 28), see #1299
  860. vendor = globalThis.navigator?.vendor ?? "";
  861. userAgent = globalThis.navigator?.userAgent ?? "";
  862. }
  863. let alwaysUsePlain: boolean = false;
  864. if (this.DisableWebGLInSafariAndIOS && (/apple/i).test(vendor)) { // doesn't apply to Chrome on MacOS
  865. alwaysUsePlain = true;
  866. } else if (this.DisableWebGLInFirefox && userAgent.includes("Firefox")) {
  867. alwaysUsePlain = true;
  868. }
  869. // In Safari (/iOS) and Firefox, the plain version is always faster (currently, Safari 15).
  870. // WebGL is faster for large scores in Chrome and Edge (both Chromium based). See #1158
  871. this.PreferredSkyBottomLineBatchCalculatorBackend = SkyBottomLineBatchCalculatorBackendType.Plain;
  872. if (!alwaysUsePlain) {
  873. if (numberOfGraphicalMeasures >= this.SkyBottomLineWebGLMinMeasures) {
  874. this.PreferredSkyBottomLineBatchCalculatorBackend = SkyBottomLineBatchCalculatorBackendType.WebGL;
  875. }
  876. }
  877. }
  878. /** Makes it so that all musical elements (including key/time signature)
  879. * are colored with the given color by default,
  880. * unless an element has a different color set (e.g. VoiceEntry.StemColor).
  881. */
  882. public applyDefaultColorMusic(color: string): void {
  883. this.DefaultColorMusic = color;
  884. this.DefaultColorNotehead = color;
  885. this.DefaultColorRest = color;
  886. this.DefaultColorStem = color;
  887. this.DefaultColorLabel = color;
  888. this.DefaultColorLyrics = color;
  889. this.DefaultColorTitle = color;
  890. this.LedgerLineColorDefault = color;
  891. }
  892. public addGraphicalNoteToNoteMap(note: Note, graphicalNote: GraphicalNote): void {
  893. note.NoteToGraphicalNoteObjectId = this.NoteToGraphicalNoteMapObjectCount;
  894. this.NoteToGraphicalNoteMap.setValue(note.NoteToGraphicalNoteObjectId, graphicalNote);
  895. this.NoteToGraphicalNoteMapObjectCount++;
  896. }
  897. /** Returns the GraphicalNote corresponding to (its) note. Also used by Cursor.GNotesUnderCursor().
  898. * We don't want to save a GraphicalNote reference in Note, see Note.NoteToGraphicalNoteObjectId.
  899. */
  900. public GNote(note: Note): GraphicalNote {
  901. return GraphicalNote.FromNote(note, this);
  902. }
  903. /** This should be done before a new sheet is loaded, not each re-render (otherwise the map would end empty). */
  904. public clearMusicSheetObjects(): void {
  905. this.NoteToGraphicalNoteMap = new Dictionary<number, GraphicalNote>();
  906. this.NoteToGraphicalNoteMapObjectCount = 0;
  907. }
  908. public resetChordAccidentalTexts(chordAccidentalTexts: Dictionary<AccidentalEnum, string>, useChordAccidentalsUnicode: boolean): void {
  909. chordAccidentalTexts.setValue(AccidentalEnum.SHARP, useChordAccidentalsUnicode ? "♯" : "#");
  910. chordAccidentalTexts.setValue(AccidentalEnum.FLAT, useChordAccidentalsUnicode ? "♭" : "b");
  911. chordAccidentalTexts.setValue(AccidentalEnum.DOUBLEFLAT, useChordAccidentalsUnicode ? "𝄫" : "bb");
  912. chordAccidentalTexts.setValue(AccidentalEnum.DOUBLESHARP, useChordAccidentalsUnicode ? "𝄪" : "x");
  913. }
  914. public setChordSymbolLabelText(key: ChordSymbolEnum, value: string): void {
  915. this.ChordSymbolLabelTexts.setValue(key, value);
  916. }
  917. public resetChordSymbolLabelTexts(chordtexts: Dictionary<ChordSymbolEnum, string>): Dictionary<ChordSymbolEnum, string> {
  918. chordtexts.setValue(ChordSymbolEnum.minor, "m");
  919. chordtexts.setValue(ChordSymbolEnum.augmented, "aug");
  920. chordtexts.setValue(ChordSymbolEnum.diminished, "dim");
  921. chordtexts.setValue(ChordSymbolEnum.dominant, "7");
  922. chordtexts.setValue(ChordSymbolEnum.majorseventh, "maj7");
  923. chordtexts.setValue(ChordSymbolEnum.minorseventh, "m7");
  924. chordtexts.setValue(ChordSymbolEnum.diminishedseventh, "dim7");
  925. chordtexts.setValue(ChordSymbolEnum.augmentedseventh, "aug7");
  926. chordtexts.setValue(ChordSymbolEnum.halfdiminished, `m7${this.ChordAccidentalTexts.getValue(AccidentalEnum.FLAT)}5`);
  927. chordtexts.setValue(ChordSymbolEnum.majorminor, "m(maj7)");
  928. chordtexts.setValue(ChordSymbolEnum.majorsixth, "maj6");
  929. chordtexts.setValue(ChordSymbolEnum.minorsixth, "m6");
  930. chordtexts.setValue(ChordSymbolEnum.dominantninth, "9");
  931. chordtexts.setValue(ChordSymbolEnum.majorninth, "maj9");
  932. chordtexts.setValue(ChordSymbolEnum.minorninth, "m9");
  933. chordtexts.setValue(ChordSymbolEnum.dominant11th, "11");
  934. chordtexts.setValue(ChordSymbolEnum.major11th, "maj11");
  935. chordtexts.setValue(ChordSymbolEnum.minor11th, "m11");
  936. chordtexts.setValue(ChordSymbolEnum.dominant13th, "13");
  937. chordtexts.setValue(ChordSymbolEnum.major13th, "maj13");
  938. chordtexts.setValue(ChordSymbolEnum.minor13th, "m13");
  939. chordtexts.setValue(ChordSymbolEnum.suspendedsecond, "sus2");
  940. chordtexts.setValue(ChordSymbolEnum.suspendedfourth, "sus4");
  941. chordtexts.setValue(ChordSymbolEnum.power, "5");
  942. chordtexts.setValue(ChordSymbolEnum.none, "N.C.");
  943. return chordtexts;
  944. }
  945. public addChordName(
  946. altName: string,
  947. chordKindText: string,
  948. adds: string[],
  949. alts: string[],
  950. subs: string[],
  951. ): void {
  952. if (ChordSymbolEnum[chordKindText] !== undefined) {
  953. const degrees: DegreesInfo = {
  954. adds,
  955. alts,
  956. subs,
  957. };
  958. this.CustomChords.push(CustomChord.createCustomChord(altName, ChordSymbolEnum[chordKindText], degrees));
  959. }
  960. }
  961. public renameChord(altName: string, newAltName: string): void {
  962. CustomChord.renameCustomChord(altName, newAltName, this.CustomChords);
  963. }
  964. public resetChordNames(): void {
  965. const sharp: string = this.ChordAccidentalTexts.getValue(AccidentalEnum.SHARP);
  966. const flat: string = this.ChordAccidentalTexts.getValue(AccidentalEnum.FLAT);
  967. // addChordName(alternateName, chordKindText, adds, alters, subtracts)
  968. this.addChordName("alt", "major", [`${sharp}5`, `${flat}9`, `${sharp}9`], [`${flat}5`], []);
  969. this.addChordName("7alt", "dominant", [`${sharp}5`, `${flat}9`, `${sharp}9`], [`${flat}5`], []);
  970. this.addChordName("7sus4", "dominant", ["4"], [], ["3"]);
  971. this.addChordName("7sus4", "suspendedfourth", ["7"], [], []);
  972. this.addChordName("9sus4", "dominantninth", ["4"], [], ["3"]);
  973. this.addChordName("9sus4", "suspendedfourth", ["9"], [], []);
  974. this.addChordName("11sus4", "dominant11th", ["4"], [], ["3"]);
  975. this.addChordName("11sus4", "suspendedfourth", ["11"], [], []);
  976. this.addChordName("13sus4", "dominant13th", ["4"], [], ["3"]);
  977. this.addChordName("13sus4", "suspendedfourth", ["13"], [], []);
  978. this.addChordName("7sus2", "dominant", ["2"], [], ["3"]);
  979. this.addChordName("7sus2", "suspendedsecond", ["7"], [], []);
  980. this.addChordName(`m7${flat}5`, "minorseventh", [], [`${flat}5`], []);
  981. this.addChordName("9sus2", "dominantninth", ["2"], [], ["3"]);
  982. this.addChordName("9sus2", "suspendedsecond", ["9"], [], []);
  983. this.addChordName("11sus2", "dominant11th", ["2"], [], ["3"]);
  984. this.addChordName("11sus2", "suspendedsecond", ["11"], [], []);
  985. this.addChordName("13sus2", "dominant13th", ["2"], [], ["3"]);
  986. this.addChordName("13sus2", "suspendedsecond", ["13"], [], []);
  987. this.addChordName("m(maj9)", "majorminor", ["9"], [], []);
  988. this.addChordName("m(maj11)", "majorminor", ["11"], [], []);
  989. this.addChordName("m(maj13)", "majorminor", ["13"], [], []);
  990. this.addChordName("69", "majorsixth", ["9"], [], []);
  991. this.addChordName("mi69", "minorsixth", ["9"], [], []);
  992. }
  993. /**
  994. * This method maps NoteDurations to Distances and DistancesScalingFactors.
  995. */
  996. // private populateDictionaries(): void {
  997. // for (let i: number = 0; i < this.NoteDistances.length; i++) {
  998. // switch (i) {
  999. // case 0:
  1000. // this.DurationDistanceDict[0.015625] = this.NoteDistances[i];
  1001. // this.DurationScalingDistanceDict[0.015625] = this.NoteDistancesScalingFactors[i];
  1002. // break;
  1003. // case 1:
  1004. // this.DurationDistanceDict[0.03125] = this.NoteDistances[i];
  1005. // this.DurationScalingDistanceDict[0.03125] = this.NoteDistancesScalingFactors[i];
  1006. // break;
  1007. // case 2:
  1008. // this.DurationDistanceDict[0.0625] = this.NoteDistances[i];
  1009. // this.DurationScalingDistanceDict[0.0625] = this.NoteDistancesScalingFactors[i];
  1010. // break;
  1011. // case 3:
  1012. // this.DurationDistanceDict[0.125] = this.NoteDistances[i];
  1013. // this.DurationScalingDistanceDict[0.125] = this.NoteDistancesScalingFactors[i];
  1014. // break;
  1015. // case 4:
  1016. // this.DurationDistanceDict[0.25] = this.NoteDistances[i];
  1017. // this.DurationScalingDistanceDict[0.25] = this.NoteDistancesScalingFactors[i];
  1018. // break;
  1019. // case 5:
  1020. // this.DurationDistanceDict[0.5] = this.NoteDistances[i];
  1021. // this.DurationScalingDistanceDict[0.5] = this.NoteDistancesScalingFactors[i];
  1022. // break;
  1023. // case 6:
  1024. // this.DurationDistanceDict[1.0] = this.NoteDistances[i];
  1025. // this.DurationScalingDistanceDict[1.0] = this.NoteDistancesScalingFactors[i];
  1026. // break;
  1027. // case 7:
  1028. // this.DurationDistanceDict[2.0] = this.NoteDistances[i];
  1029. // this.DurationScalingDistanceDict[2.0] = this.NoteDistancesScalingFactors[i];
  1030. // break;
  1031. // default:
  1032. // // FIXME
  1033. // }
  1034. // }
  1035. // }
  1036. /**
  1037. * Calculate Curve-independend factors, to be used later in the Slur- and TieCurvePoints calculation
  1038. */
  1039. private calculateCurveParametersArrays(): void {
  1040. this.TPower3 = new Array(this.BezierCurveStepSize);
  1041. this.OneMinusTPower3 = new Array(this.BezierCurveStepSize);
  1042. this.FactorOne = new Array(this.BezierCurveStepSize);
  1043. this.FactorTwo = new Array(this.BezierCurveStepSize);
  1044. for (let i: number = 0; i < this.BezierCurveStepSize; i++) {
  1045. const t: number = i / this.BezierCurveStepSize;
  1046. this.TPower3[i] = Math.pow(t, 3);
  1047. this.OneMinusTPower3[i] = Math.pow((1 - t), 3);
  1048. this.FactorOne[i] = 3 * Math.pow((1 - t), 2) * t;
  1049. this.FactorTwo[i] = 3 * (1 - t) * Math.pow(t, 2);
  1050. }
  1051. }
  1052. }
  1053. // TODO maybe this should be moved to OSMDOptions. Also see OpenSheetMusicDisplay.PageFormatStandards
  1054. export class PageFormat {
  1055. constructor(width: number, height: number, idString: string = "noIdStringGiven") {
  1056. this.width = width;
  1057. this.height = height;
  1058. this.idString = idString;
  1059. }
  1060. public width: number;
  1061. public height: number;
  1062. public idString: string;
  1063. public get aspectRatio(): number {
  1064. if (!this.IsUndefined) {
  1065. return this.width / this.height;
  1066. } else {
  1067. return 0; // infinite page height
  1068. }
  1069. }
  1070. /** Undefined page format: use default page format. */
  1071. public get IsUndefined(): boolean {
  1072. return this.width === undefined || this.height === undefined || this.height === 0 || this.width === 0;
  1073. }
  1074. public static get UndefinedPageFormat(): PageFormat {
  1075. return new PageFormat(0, 0);
  1076. }
  1077. public Equals(otherPageFormat: PageFormat): boolean {
  1078. if (!otherPageFormat) {
  1079. return false;
  1080. }
  1081. return otherPageFormat.width === this.width && otherPageFormat.height === this.height;
  1082. }
  1083. }