EngravingRules.ts 43 KB

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