EngravingRules.ts 31 KB

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