EngravingRules.ts 56 KB

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