EngravingRules.ts 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  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 { AutoBeamOptions, AlignRestOption, FillEmptyMeasuresWithWholeRests } from "../../OpenSheetMusicDisplay/OSMDOptions";
  7. import { ColoringModes as ColoringMode } from "./DrawingParameters";
  8. import { Dictionary } from "typescript-collections";
  9. import { FontStyles } from "../../Common/Enums";
  10. import { NoteEnum } from "../../Common/DataObjects/Pitch";
  11. import { ChordSymbolEnum } from "../../MusicalScore/VoiceData/ChordSymbolContainer";
  12. export class EngravingRules {
  13. /** A unit of distance. 1.0 is the distance between lines of a stave for OSMD, which is 10 pixels in Vexflow. */
  14. public static unit: number = 1.0;
  15. public SamplingUnit: number;
  16. public StaccatoShorteningFactor: number;
  17. /** Height (size) of the sheet title. */
  18. public SheetTitleHeight: number;
  19. public SheetSubtitleHeight: number;
  20. public SheetMinimumDistanceBetweenTitleAndSubtitle: number;
  21. public SheetComposerHeight: number;
  22. public SheetAuthorHeight: number;
  23. public CompactMode: boolean;
  24. public PagePlacementEnum: PagePlacementEnum;
  25. public PageHeight: number;
  26. public PageTopMargin: number;
  27. public PageTopMarginNarrow: number;
  28. public PageBottomMargin: number;
  29. public PageBottomExtraWhiteSpace: number; // experimental. extra white space that wil be added below the sheet
  30. public PageLeftMargin: number;
  31. public PageRightMargin: number;
  32. public TitleTopDistance: number;
  33. public TitleBottomDistance: number;
  34. public SystemLeftMargin: number;
  35. public SystemRightMargin: number;
  36. public SystemLabelsRightMargin: number;
  37. public SystemComposerDistance: number;
  38. public InstrumentLabelTextHeight: number;
  39. public MinimumDistanceBetweenSystems: number;
  40. public MinSkyBottomDistBetweenSystems: number;
  41. public LastSystemMaxScalingFactor: number;
  42. public StaffDistance: number;
  43. public BetweenStaffDistance: number;
  44. public StaffHeight: number;
  45. public TabStaffInterlineHeight: number;
  46. public BetweenStaffLinesDistance: number;
  47. /** Whether to automatically beam notes that don't already have beams in XML. */
  48. public AutoBeamNotes: boolean;
  49. /** Options for autoBeaming like whether to beam over rests. See AutoBeamOptions interface. */
  50. public AutoBeamOptions: AutoBeamOptions;
  51. public BeamWidth: number;
  52. public BeamSpaceWidth: number;
  53. public BeamForwardLength: number;
  54. public ClefLeftMargin: number;
  55. public ClefRightMargin: number;
  56. public PercussionOneLineCutoff: number;
  57. public PercussionForceVoicesOneLineCutoff: number;
  58. public BetweenKeySymbolsDistance: number;
  59. public KeyRightMargin: number;
  60. public RhythmRightMargin: number;
  61. public ShowRhythmAgainAfterPartEndOrFinalBarline: boolean;
  62. public InStaffClefScalingFactor: number;
  63. public DistanceBetweenNaturalAndSymbolWhenCancelling: number;
  64. public NoteHelperLinesOffset: number;
  65. public MeasureLeftMargin: number;
  66. public MeasureRightMargin: number;
  67. public DistanceBetweenLastInstructionAndRepetitionBarline: number;
  68. public ArpeggioDistance: number;
  69. public IdealStemLength: number;
  70. public StemNoteHeadBorderYOffset: number;
  71. public StemWidth: number;
  72. public StemMargin: number;
  73. public StemMinLength: number;
  74. public StemMaxLength: number;
  75. public BeamSlopeMaxAngle: number;
  76. public StemMinAllowedDistanceBetweenNoteHeadAndBeamLine: number;
  77. public SetWantedStemDirectionByXml: boolean;
  78. public GraceNoteScalingFactor: number;
  79. public GraceNoteXOffset: number;
  80. public WedgeOpeningLength: number;
  81. public WedgeMeasureEndOpeningLength: number;
  82. public WedgeMeasureBeginOpeningLength: number;
  83. public WedgePlacementAboveY: number;
  84. public WedgePlacementBelowY: number;
  85. public WedgeHorizontalMargin: number;
  86. public WedgeVerticalMargin: number;
  87. public DistanceOffsetBetweenTwoHorizontallyCrossedWedges: number;
  88. public WedgeMinLength: number;
  89. public DistanceBetweenAdjacentDynamics: number;
  90. public TempoChangeMeasureValidity: number;
  91. public TempoContinousFactor: number;
  92. public StaccatoScalingFactor: number;
  93. public BetweenDotsDistance: number;
  94. public OrnamentAccidentalScalingFactor: number;
  95. public ChordSymbolTextHeight: number;
  96. public ChordSymbolXSpacing: number;
  97. public ChordSymbolYOffset: number;
  98. public ChordSymbolLabelTexts: Dictionary<ChordSymbolEnum, string>;
  99. public MeasureNumberLabelHeight: number;
  100. public MeasureNumberLabelOffset: number;
  101. public MeasureNumberLabelXOffset: number;
  102. /** Whether tuplets should display ratio (3:2 instead of 3 for triplet). Default false. */
  103. public TupletsRatioed: boolean;
  104. /** Whether all tuplets should be bracketed (e.g. |--5--| instead of 5). Default false.
  105. * If false, only tuplets given as bracketed in XML (bracket="yes") will be bracketed.
  106. * (If not given in XML, bracketing is implementation-dependent according to standard)
  107. */
  108. public TupletsBracketed: boolean;
  109. /** Whether all triplets should be bracketed. Overrides tupletsBracketed for triplets.
  110. * If false, only triplets given as bracketed in XML (bracket="yes") will be bracketed.
  111. * (Bracketing all triplets can be cluttering)
  112. */
  113. public TripletsBracketed: boolean;
  114. public TupletNumberLabelHeight: number;
  115. public TupletNumberYOffset: number;
  116. public LabelMarginBorderFactor: number;
  117. public TupletVerticalLineLength: number;
  118. public TupletNumbersInTabs: boolean;
  119. public RepetitionEndingLabelHeight: number;
  120. public RepetitionEndingLabelXOffset: number;
  121. public RepetitionEndingLabelYOffset: number;
  122. public RepetitionEndingLineYLowerOffset: number;
  123. public RepetitionEndingLineYUpperOffset: number;
  124. public VoltaOffset: number;
  125. /** Default alignment of lyrics.
  126. * Left alignments will extend text to the right of the bounding box,
  127. * which facilitates spacing by extending measure width.
  128. */
  129. public LyricsAlignmentStandard: TextAlignmentEnum;
  130. public LyricsHeight: number;
  131. public LyricsYOffsetToStaffHeight: number;
  132. public VerticalBetweenLyricsDistance: number;
  133. public HorizontalBetweenLyricsDistance: number;
  134. public BetweenSyllableMaximumDistance: number;
  135. public BetweenSyllableMinimumDistance: number;
  136. public LyricOverlapAllowedIntoNextMeasure: number;
  137. public MinimumDistanceBetweenDashes: number;
  138. public MaximumLyricsElongationFactor: number;
  139. public BezierCurveStepSize: number;
  140. public TPower3: number[];
  141. public OneMinusTPower3: number[];
  142. public FactorOne: number[];
  143. public FactorTwo: number[];
  144. public TieGhostObjectWidth: number;
  145. public TieYPositionOffsetFactor: number;
  146. public MinimumNeededXspaceForTieGhostObject: number;
  147. public TieHeightMinimum: number;
  148. public TieHeightMaximum: number;
  149. public TieHeightInterpolationK: number;
  150. public TieHeightInterpolationD: number;
  151. public SlurNoteHeadYOffset: number;
  152. public SlurStemXOffset: number;
  153. public SlurSlopeMaxAngle: number;
  154. public SlurTangentMinAngle: number;
  155. public SlurTangentMaxAngle: number;
  156. public SlursStartingAtSameStaffEntryYOffset: number;
  157. public InstantaneousTempoTextHeight: number;
  158. public ContinuousDynamicTextHeight: number;
  159. public MoodTextHeight: number;
  160. public UnknownTextHeight: number;
  161. public ContinuousTempoTextHeight: number;
  162. public VexFlowDefaultNotationFontScale: number;
  163. public VexFlowDefaultTabFontScale: number;
  164. public StaffLineWidth: number;
  165. public StaffLineColor: string;
  166. public LedgerLineWidth: number;
  167. public LedgerLineStrokeStyle: string;
  168. public LedgerLineColorDefault: string;
  169. public WedgeLineWidth: number;
  170. public TupletLineWidth: number;
  171. public LyricUnderscoreLineWidth: number;
  172. public SystemThinLineWidth: number;
  173. public SystemBoldLineWidth: number;
  174. public SystemRepetitionEndingLineWidth: number;
  175. public SystemDotWidth: number;
  176. public MultipleRestMeasureDefaultWidth: number;
  177. public DistanceBetweenVerticalSystemLines: number;
  178. public DistanceBetweenDotAndLine: number;
  179. public OctaveShiftLineWidth: number;
  180. public OctaveShiftVerticalLineLength: number;
  181. public GraceLineWidth: number;
  182. public MinimumStaffLineDistance: number;
  183. public MinSkyBottomDistBetweenStaves: number;
  184. public MinimumCrossedBeamDifferenceMargin: number;
  185. public VoiceSpacingMultiplierVexflow: number;
  186. public VoiceSpacingAddendVexflow: number;
  187. public DisplacedNoteMargin: number;
  188. public MinNoteDistance: number;
  189. public SubMeasureXSpacingThreshold: number;
  190. public MeasureDynamicsMaxScalingFactor: number;
  191. public WholeRestXShiftVexflow: number;
  192. public MetronomeMarksDrawn: boolean;
  193. public MetronomeMarkXShift: number;
  194. public MetronomeMarkYShift: number;
  195. public SoftmaxFactorVexFlow: number;
  196. public MaxInstructionsConstValue: number;
  197. public NoteDistances: number[] = [1.0, 1.0, 1.3, 1.6, 2.0, 2.5, 3.0, 4.0];
  198. public NoteDistancesScalingFactors: number[] = [1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0];
  199. public DurationDistanceDict: {[_: number]: number; } = {};
  200. public DurationScalingDistanceDict: {[_: number]: number; } = {};
  201. public AlignRests: number; // 0 = false, 1 = true, 2 = auto
  202. public FillEmptyMeasuresWithWholeRest: FillEmptyMeasuresWithWholeRests | number;
  203. public ArpeggiosGoAcrossVoices: boolean;
  204. public RenderArpeggios: boolean;
  205. public RenderSlurs: boolean;
  206. public ColoringMode: ColoringMode;
  207. public ColoringEnabled: boolean;
  208. public ColorStemsLikeNoteheads: boolean;
  209. public ColorFlags: boolean;
  210. public ColorBeams: boolean;
  211. public ColoringSetCurrent: Dictionary<NoteEnum|number, string>;
  212. public DefaultColorNotehead: string;
  213. public DefaultColorRest: string;
  214. public DefaultColorStem: string;
  215. public DefaultColorLabel: string;
  216. public DefaultColorTitle: string;
  217. public DefaultFontFamily: string;
  218. public DefaultFontStyle: FontStyles;
  219. public DefaultVexFlowNoteFont: string;
  220. public MaxMeasureToDrawIndex: number;
  221. public MinMeasureToDrawIndex: number;
  222. /** Whether to render a label for the composer of the piece at the top of the sheet. */
  223. public RenderComposer: boolean;
  224. public RenderTitle: boolean;
  225. public RenderSubtitle: boolean;
  226. public RenderLyricist: boolean;
  227. public RenderPartNames: boolean;
  228. public RenderPartAbbreviations: boolean;
  229. public RenderFingerings: boolean;
  230. public RenderMeasureNumbers: boolean;
  231. public RenderMeasureNumbersOnlyAtSystemStart: boolean;
  232. public RenderLyrics: boolean;
  233. public RenderMultipleRestMeasures: boolean;
  234. public AutoGenerateMutipleRestMeasuresFromRestMeasures: boolean;
  235. public RenderTimeSignatures: boolean;
  236. public DynamicExpressionMaxDistance: number;
  237. public DynamicExpressionSpacer: number;
  238. /** Position of fingering label in relation to corresponding note (left, right supported, above, below experimental) */
  239. public FingeringPosition: PlacementEnum;
  240. public FingeringInsideStafflines: boolean;
  241. public FingeringLabelFontHeight: number;
  242. public FingeringOffsetX: number;
  243. public NewSystemAtXMLNewSystemAttribute: boolean;
  244. public NewPageAtXMLNewPageAttribute: boolean;
  245. public PageFormat: PageFormat;
  246. public PageBackgroundColor: string; // vexflow-color-string (#FFFFFF). Default undefined/transparent.
  247. public RenderSingleHorizontalStaffline: boolean;
  248. public RestoreCursorAfterRerender: boolean;
  249. public StretchLastSystemLine: boolean;
  250. public SpacingBetweenTextLines: number;
  251. public static FixStafflineBoundingBox: boolean; // TODO temporary workaround
  252. constructor() {
  253. // global variables
  254. this.SamplingUnit = EngravingRules.unit * 3;
  255. // Page Label Variables
  256. this.SheetTitleHeight = 4.0;
  257. this.SheetSubtitleHeight = 2.0;
  258. this.SheetMinimumDistanceBetweenTitleAndSubtitle = 1.0;
  259. this.SheetComposerHeight = 2.0;
  260. this.SheetAuthorHeight = 2.0;
  261. // Staff sizing Variables
  262. this.CompactMode = false;
  263. this.PagePlacementEnum = PagePlacementEnum.Down;
  264. this.PageHeight = 100001.0;
  265. this.PageTopMargin = 5.0;
  266. this.PageTopMarginNarrow = 0.0; // for compact mode
  267. this.PageBottomMargin = 5.0;
  268. this.PageBottomExtraWhiteSpace = 0.0; // experimental.
  269. this.PageLeftMargin = 5.0;
  270. this.PageRightMargin = 5.0;
  271. this.TitleTopDistance = 9.0;
  272. this.TitleBottomDistance = 1.0;
  273. this.StaffDistance = 7.0;
  274. this.BetweenStaffDistance = 5.0;
  275. this.MinimumStaffLineDistance = 4.0;
  276. this.MinSkyBottomDistBetweenStaves = 1.0; // default. compacttight mode sets it to 1.0 (as well).
  277. // System Sizing and Label Variables
  278. this.StaffHeight = 4.0;
  279. this.TabStaffInterlineHeight = 1.1111;
  280. this.BetweenStaffLinesDistance = EngravingRules.unit;
  281. this.SystemLeftMargin = 0.0;
  282. this.SystemRightMargin = 0.0;
  283. this.SystemLabelsRightMargin = 2.0;
  284. this.SystemComposerDistance = 2.0;
  285. this.InstrumentLabelTextHeight = 2;
  286. this.MinimumDistanceBetweenSystems = 7.0;
  287. this.MinSkyBottomDistBetweenSystems = 5.0;
  288. this.LastSystemMaxScalingFactor = 1.4;
  289. // autoBeam options
  290. this.AutoBeamNotes = false;
  291. this.AutoBeamOptions = {
  292. beam_middle_rests_only: false,
  293. beam_rests: false,
  294. maintain_stem_directions: false
  295. };
  296. // Beam Sizing Variables
  297. this.BeamWidth = EngravingRules.unit / 2.0;
  298. this.BeamSpaceWidth = EngravingRules.unit / 3.0;
  299. this.BeamForwardLength = 1.25 * EngravingRules.unit;
  300. // Beam Sizing Variables
  301. this.ClefLeftMargin = 0.5;
  302. this.ClefRightMargin = 0.75;
  303. this.PercussionOneLineCutoff = 3;
  304. this.PercussionForceVoicesOneLineCutoff = 1;
  305. this.BetweenKeySymbolsDistance = 0.2;
  306. this.KeyRightMargin = 0.75;
  307. this.RhythmRightMargin = 1.25;
  308. this.ShowRhythmAgainAfterPartEndOrFinalBarline = true;
  309. this.InStaffClefScalingFactor = 0.8;
  310. this.DistanceBetweenNaturalAndSymbolWhenCancelling = 0.4;
  311. // Beam Sizing Variables
  312. this.NoteHelperLinesOffset = 0.25;
  313. this.MeasureLeftMargin = 0.7;
  314. this.MeasureRightMargin = 0.0;
  315. this.DistanceBetweenLastInstructionAndRepetitionBarline = 1.0;
  316. this.ArpeggioDistance = 0.6;
  317. // Stems Variables
  318. this.StaccatoShorteningFactor = 2;
  319. this.IdealStemLength = 3.0;
  320. this.StemNoteHeadBorderYOffset = 0.2;
  321. this.StemMargin = 0.2;
  322. this.StemMinLength = 2.5;
  323. this.StemMaxLength = 4.5;
  324. this.BeamSlopeMaxAngle = 10.0;
  325. this.StemMinAllowedDistanceBetweenNoteHeadAndBeamLine = 1.0;
  326. this.SetWantedStemDirectionByXml = true;
  327. // also see stemwidth further below
  328. // GraceNote Variables
  329. this.GraceNoteScalingFactor = 0.6;
  330. this.GraceNoteXOffset = 0.2;
  331. // Wedge Variables
  332. this.WedgeOpeningLength = 1.2;
  333. this.WedgeMeasureEndOpeningLength = 0.75;
  334. this.WedgeMeasureBeginOpeningLength = 0.75;
  335. this.WedgePlacementAboveY = -1.5;
  336. this.WedgePlacementBelowY = 1.5;
  337. this.WedgeHorizontalMargin = 0.6;
  338. this.WedgeVerticalMargin = 0.5;
  339. this.DistanceOffsetBetweenTwoHorizontallyCrossedWedges = 0.3;
  340. this.WedgeMinLength = 2.0;
  341. this.DistanceBetweenAdjacentDynamics = 0.75;
  342. // Tempo Variables
  343. this.TempoChangeMeasureValidity = 4;
  344. this.TempoContinousFactor = 0.7;
  345. // various
  346. this.StaccatoScalingFactor = 0.8;
  347. this.BetweenDotsDistance = 0.8;
  348. this.OrnamentAccidentalScalingFactor = 0.65;
  349. this.ChordSymbolTextHeight = 2.0;
  350. this.ChordSymbolXSpacing = 1.0;
  351. this.ChordSymbolYOffset = 2.0;
  352. this.ChordSymbolLabelTexts = new Dictionary<ChordSymbolEnum, string>();
  353. this.resetChordSymbolLabelTexts(this.ChordSymbolLabelTexts);
  354. // Tuplets, MeasureNumber and TupletNumber Labels
  355. this.MeasureNumberLabelHeight = 1.5 * EngravingRules.unit;
  356. this.MeasureNumberLabelOffset = 2;
  357. this.MeasureNumberLabelXOffset = -0.5;
  358. this.TupletsRatioed = false;
  359. this.TupletsBracketed = false;
  360. this.TripletsBracketed = false; // special setting for triplets, overrides tuplet setting (for triplets only)
  361. this.TupletNumberLabelHeight = 1.5 * EngravingRules.unit;
  362. this.TupletNumberYOffset = 0.5;
  363. this.LabelMarginBorderFactor = 0.1;
  364. this.TupletVerticalLineLength = 0.5;
  365. this.TupletNumbersInTabs = false; // disabled by default, nonstandard in tabs, at least how we show them in non-tabs.
  366. // Slur and Tie variables
  367. this.BezierCurveStepSize = 1000;
  368. this.calculateCurveParametersArrays();
  369. this.TieGhostObjectWidth = 0.75;
  370. this.TieYPositionOffsetFactor = 0.3;
  371. this.MinimumNeededXspaceForTieGhostObject = 1.0;
  372. this.TieHeightMinimum = 0.28;
  373. this.TieHeightMaximum = 1.2;
  374. this.TieHeightInterpolationK = 0.0288;
  375. this.TieHeightInterpolationD = 0.136;
  376. this.SlurNoteHeadYOffset = 0.5;
  377. this.SlurStemXOffset = 0.3;
  378. this.SlurSlopeMaxAngle = 15.0;
  379. this.SlurTangentMinAngle = 30.0;
  380. this.SlurTangentMaxAngle = 80.0;
  381. this.SlursStartingAtSameStaffEntryYOffset = 0.8;
  382. // Repetitions
  383. this.RepetitionEndingLabelHeight = 2.0;
  384. this.RepetitionEndingLabelXOffset = 0.5;
  385. this.RepetitionEndingLabelYOffset = 0.3;
  386. this.RepetitionEndingLineYLowerOffset = 0.5;
  387. this.RepetitionEndingLineYUpperOffset = 0.3;
  388. this.VoltaOffset = 2.5;
  389. // Lyrics
  390. this.LyricsAlignmentStandard = TextAlignmentEnum.LeftBottom; // CenterBottom and LeftBottom tested, spacing-optimized
  391. this.LyricsHeight = 2.0; // actually size of lyrics
  392. this.LyricsYOffsetToStaffHeight = 0.0; // distance between lyrics and staff. could partly be even lower/dynamic
  393. this.VerticalBetweenLyricsDistance = 0.5;
  394. this.HorizontalBetweenLyricsDistance = 0.2;
  395. this.BetweenSyllableMaximumDistance = 10.0;
  396. this.BetweenSyllableMinimumDistance = 0.5; // + 1.0 for CenterAlignment added in lyrics spacing
  397. this.LyricOverlapAllowedIntoNextMeasure = 3.4; // optimal for dashed last lyric, see Land der Berge
  398. this.MinimumDistanceBetweenDashes = 10;
  399. this.MaximumLyricsElongationFactor = 2.5;
  400. // expressions variables
  401. this.InstantaneousTempoTextHeight = 2.3;
  402. this.ContinuousDynamicTextHeight = 2.3;
  403. this.MoodTextHeight = 2.3;
  404. this.UnknownTextHeight = 2.0;
  405. this.ContinuousTempoTextHeight = 2.3;
  406. this.DynamicExpressionMaxDistance = 2;
  407. this.DynamicExpressionSpacer = 0.5;
  408. // Line Widths
  409. this.VexFlowDefaultNotationFontScale = 39; // scales notes, including rests. default value 39 in Vexflow.
  410. this.VexFlowDefaultTabFontScale = 39;
  411. this.StemWidth = 0.15; // originally 0.13. vexflow default 0.15. should probably be adjusted when increasing vexFlowDefaultNotationFontScale,
  412. this.StaffLineWidth = 0.10; // originally 0.12, but this will be pixels in Vexflow (*10).
  413. this.StaffLineColor = undefined; // if undefined, vexflow default (grey). not a width, but affects visual line clarity.
  414. this.LedgerLineWidth = 1; // vexflow units (pixels). if not undefined, the vexflow default will be overwritten
  415. this.LedgerLineStrokeStyle = undefined; // if not undefined, the vexflow default will be overwritten
  416. this.LedgerLineColorDefault = "#000000"; // black, previously grey by default
  417. this.WedgeLineWidth = 0.12;
  418. this.TupletLineWidth = 0.12;
  419. this.LyricUnderscoreLineWidth = 0.12;
  420. this.SystemThinLineWidth = 0.12;
  421. this.SystemBoldLineWidth = EngravingRules.unit / 2.0;
  422. this.SystemRepetitionEndingLineWidth = 0.12;
  423. this.SystemDotWidth = EngravingRules.unit / 5.0;
  424. this.DistanceBetweenVerticalSystemLines = 0.35;
  425. this.DistanceBetweenDotAndLine = 0.7;
  426. this.OctaveShiftLineWidth = 0.12;
  427. this.OctaveShiftVerticalLineLength = EngravingRules.unit;
  428. this.GraceLineWidth = this.StaffLineWidth * this.GraceNoteScalingFactor;
  429. this.MultipleRestMeasureDefaultWidth = 4;
  430. // Line Widths
  431. this.MinimumCrossedBeamDifferenceMargin = 0.0001;
  432. // xSpacing Variables
  433. this.VoiceSpacingMultiplierVexflow = 0.85;
  434. this.VoiceSpacingAddendVexflow = 3.0;
  435. this.DisplacedNoteMargin = 0.1;
  436. this.MinNoteDistance = 2.0;
  437. this.SubMeasureXSpacingThreshold = 35;
  438. this.MeasureDynamicsMaxScalingFactor = 2.5;
  439. this.WholeRestXShiftVexflow = -1.5; // VexFlow draws rest notes too far to the right
  440. this.MetronomeMarksDrawn = true;
  441. this.MetronomeMarkXShift = -6; // our unit, is taken * unitInPixels
  442. this.MetronomeMarkYShift = -0.5;
  443. this.SoftmaxFactorVexFlow = 15; // only applies to Vexflow 3.x. 15 seems like the sweet spot. Vexflow default is 100.
  444. // if too high, score gets too big, especially half notes. with half note quarter quarter, the quarters get squeezed.
  445. // if too low, smaller notes aren't positioned correctly.
  446. // Render options (whether to render specific or invisible elements)
  447. this.AlignRests = AlignRestOption.Never; // 0 = false, 1 = true, 2 = auto
  448. this.FillEmptyMeasuresWithWholeRest = FillEmptyMeasuresWithWholeRests.No;
  449. this.ArpeggiosGoAcrossVoices = false; // safe option, as otherwise arpeggios will always go across all voices in Vexflow, which is often unwanted
  450. this.RenderArpeggios = true;
  451. this.RenderSlurs = true;
  452. this.ColoringMode = ColoringMode.XML;
  453. this.ColoringEnabled = true;
  454. this.ColorStemsLikeNoteheads = false;
  455. this.ColorBeams = true;
  456. this.ColorFlags = true;
  457. this.DefaultColorNotehead = "#000000"; // black. undefined is only black if a note's color hasn't been changed before.
  458. this.DefaultColorRest = this.DefaultColorNotehead;
  459. this.DefaultColorStem = this.DefaultColorNotehead;
  460. this.DefaultColorLabel = this.DefaultColorNotehead;
  461. this.DefaultColorTitle = this.DefaultColorNotehead;
  462. this.DefaultFontFamily = "Times New Roman"; // what OSMD was initially optimized for
  463. this.DefaultFontStyle = FontStyles.Regular;
  464. this.DefaultVexFlowNoteFont = "gonville"; // was the default vexflow font up to vexflow 1.2.93, now it's Bravura, which is more cursive/bold
  465. this.MaxMeasureToDrawIndex = Number.MAX_VALUE;
  466. this.MinMeasureToDrawIndex = 0;
  467. this.RenderComposer = true;
  468. this.RenderTitle = true;
  469. this.RenderSubtitle = true;
  470. this.RenderLyricist = true;
  471. this.RenderPartNames = true;
  472. this.RenderPartAbbreviations = true;
  473. this.RenderFingerings = true;
  474. this.RenderMeasureNumbers = true;
  475. this.RenderMeasureNumbersOnlyAtSystemStart = false;
  476. this.RenderLyrics = true;
  477. this.RenderMultipleRestMeasures = true;
  478. this.AutoGenerateMutipleRestMeasuresFromRestMeasures = true;
  479. this.RenderTimeSignatures = true;
  480. this.FingeringPosition = PlacementEnum.Left; // easier to get bounding box, and safer for vertical layout
  481. this.FingeringInsideStafflines = false;
  482. this.FingeringLabelFontHeight = 1.7;
  483. this.FingeringOffsetX = 0.0;
  484. this.NewSystemAtXMLNewSystemAttribute = false;
  485. this.NewPageAtXMLNewPageAttribute = false;
  486. this.RestoreCursorAfterRerender = true;
  487. this.StretchLastSystemLine = false;
  488. EngravingRules.FixStafflineBoundingBox = false; // TODO temporary workaround
  489. this.PageFormat = PageFormat.UndefinedPageFormat; // default: undefined / 'infinite' height page, using the canvas'/container's width and height
  490. this.PageBackgroundColor = undefined; // default: transparent. half-transparent white: #FFFFFF88"
  491. this.RenderSingleHorizontalStaffline = false;
  492. this.SpacingBetweenTextLines = 0;
  493. this.populateDictionaries();
  494. try {
  495. this.MaxInstructionsConstValue = this.ClefLeftMargin + this.ClefRightMargin + this.KeyRightMargin + this.RhythmRightMargin + 11;
  496. //if (FontInfo.Info) {
  497. // this.maxInstructionsConstValue += FontInfo.Info.getBoundingBox(MusicSymbol.G_CLEF).width
  498. // + FontInfo.Info.getBoundingBox(MusicSymbol.FOUR).width
  499. // + 7 * FontInfo.Info.getBoundingBox(MusicSymbol.SHARP).width;
  500. //}
  501. } catch (ex) {
  502. log.info("EngravingRules()", ex);
  503. }
  504. }
  505. public setChordSymbolLabelText(key: ChordSymbolEnum, value: string): void {
  506. this.ChordSymbolLabelTexts.setValue(key, value);
  507. }
  508. public resetChordSymbolLabelTexts(chordtexts: Dictionary<ChordSymbolEnum, string>): Dictionary<ChordSymbolEnum, string> {
  509. chordtexts.setValue(ChordSymbolEnum.minor, "m");
  510. chordtexts.setValue(ChordSymbolEnum.augmented, "aug");
  511. chordtexts.setValue(ChordSymbolEnum.diminished, "dim");
  512. chordtexts.setValue(ChordSymbolEnum.dominant, "7");
  513. chordtexts.setValue(ChordSymbolEnum.majorseventh, "maj7");
  514. chordtexts.setValue(ChordSymbolEnum.minorseventh, "m7");
  515. chordtexts.setValue(ChordSymbolEnum.diminishedseventh, "dim7");
  516. chordtexts.setValue(ChordSymbolEnum.augmentedseventh, "aug7");
  517. chordtexts.setValue(ChordSymbolEnum.halfdiminished, "m7b5");
  518. chordtexts.setValue(ChordSymbolEnum.majorminor, "m(maj7)");
  519. chordtexts.setValue(ChordSymbolEnum.majorsixth, "maj6");
  520. chordtexts.setValue(ChordSymbolEnum.minorsixth, "m6");
  521. chordtexts.setValue(ChordSymbolEnum.dominantninth, "9");
  522. chordtexts.setValue(ChordSymbolEnum.majorninth, "maj9");
  523. chordtexts.setValue(ChordSymbolEnum.minorninth, "m9");
  524. chordtexts.setValue(ChordSymbolEnum.dominant11th, "11");
  525. chordtexts.setValue(ChordSymbolEnum.major11th, "maj11");
  526. chordtexts.setValue(ChordSymbolEnum.minor11th, "m11");
  527. chordtexts.setValue(ChordSymbolEnum.dominant13th, "13");
  528. chordtexts.setValue(ChordSymbolEnum.major13th, "maj13");
  529. chordtexts.setValue(ChordSymbolEnum.minor13th, "m13");
  530. chordtexts.setValue(ChordSymbolEnum.suspendedsecond, "sus2");
  531. chordtexts.setValue(ChordSymbolEnum.suspendedfourth, "sus4");
  532. chordtexts.setValue(ChordSymbolEnum.power, "5");
  533. return chordtexts;
  534. }
  535. /**
  536. * This method maps NoteDurations to Distances and DistancesScalingFactors.
  537. */
  538. private populateDictionaries(): void {
  539. for (let i: number = 0; i < this.NoteDistances.length; i++) {
  540. switch (i) {
  541. case 0:
  542. this.DurationDistanceDict[0.015625] = this.NoteDistances[i];
  543. this.DurationScalingDistanceDict[0.015625] = this.NoteDistancesScalingFactors[i];
  544. break;
  545. case 1:
  546. this.DurationDistanceDict[0.03125] = this.NoteDistances[i];
  547. this.DurationScalingDistanceDict[0.03125] = this.NoteDistancesScalingFactors[i];
  548. break;
  549. case 2:
  550. this.DurationDistanceDict[0.0625] = this.NoteDistances[i];
  551. this.DurationScalingDistanceDict[0.0625] = this.NoteDistancesScalingFactors[i];
  552. break;
  553. case 3:
  554. this.DurationDistanceDict[0.125] = this.NoteDistances[i];
  555. this.DurationScalingDistanceDict[0.125] = this.NoteDistancesScalingFactors[i];
  556. break;
  557. case 4:
  558. this.DurationDistanceDict[0.25] = this.NoteDistances[i];
  559. this.DurationScalingDistanceDict[0.25] = this.NoteDistancesScalingFactors[i];
  560. break;
  561. case 5:
  562. this.DurationDistanceDict[0.5] = this.NoteDistances[i];
  563. this.DurationScalingDistanceDict[0.5] = this.NoteDistancesScalingFactors[i];
  564. break;
  565. case 6:
  566. this.DurationDistanceDict[1.0] = this.NoteDistances[i];
  567. this.DurationScalingDistanceDict[1.0] = this.NoteDistancesScalingFactors[i];
  568. break;
  569. case 7:
  570. this.DurationDistanceDict[2.0] = this.NoteDistances[i];
  571. this.DurationScalingDistanceDict[2.0] = this.NoteDistancesScalingFactors[i];
  572. break;
  573. default:
  574. // FIXME
  575. }
  576. }
  577. }
  578. /**
  579. * Calculate Curve-independend factors, to be used later in the Slur- and TieCurvePoints calculation
  580. */
  581. private calculateCurveParametersArrays(): void {
  582. this.TPower3 = new Array(this.BezierCurveStepSize);
  583. this.OneMinusTPower3 = new Array(this.BezierCurveStepSize);
  584. this.FactorOne = new Array(this.BezierCurveStepSize);
  585. this.FactorTwo = new Array(this.BezierCurveStepSize);
  586. for (let i: number = 0; i < this.BezierCurveStepSize; i++) {
  587. const t: number = i / this.BezierCurveStepSize;
  588. this.TPower3[i] = Math.pow(t, 3);
  589. this.OneMinusTPower3[i] = Math.pow((1 - t), 3);
  590. this.FactorOne[i] = 3 * Math.pow((1 - t), 2) * t;
  591. this.FactorTwo[i] = 3 * (1 - t) * Math.pow(t, 2);
  592. }
  593. }
  594. }
  595. // TODO maybe this should be moved to OSMDOptions. Also see OpenSheetMusicDisplay.PageFormatStandards
  596. export class PageFormat {
  597. constructor(width: number, height: number, idString: string = "noIdStringGiven") {
  598. this.width = width;
  599. this.height = height;
  600. this.idString = idString;
  601. }
  602. public width: number;
  603. public height: number;
  604. public idString: string;
  605. public get aspectRatio(): number {
  606. if (!this.IsUndefined) {
  607. return this.width / this.height;
  608. } else {
  609. return 0; // infinite page height
  610. }
  611. }
  612. /** Undefined page format: use default page format. */
  613. public get IsUndefined(): boolean {
  614. return this.width === undefined || this.height === undefined || this.height === 0 || this.width === 0;
  615. }
  616. public static get UndefinedPageFormat(): PageFormat {
  617. return new PageFormat(0, 0);
  618. }
  619. public Equals(otherPageFormat: PageFormat): boolean {
  620. if (!otherPageFormat) {
  621. return false;
  622. }
  623. return otherPageFormat.width === this.width && otherPageFormat.height === this.height;
  624. }
  625. }