EngravingRules.ts 36 KB

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