EngravingRules.ts 37 KB

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