EngravingRules.ts 39 KB

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