-
Notifications
You must be signed in to change notification settings - Fork 286
Expand file tree
/
Copy pathEngravingSettings.ts
More file actions
2399 lines (2287 loc) · 83.3 KB
/
Copy pathEngravingSettings.ts
File metadata and controls
2399 lines (2287 loc) · 83.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { EngravingSettingsCloner } from '@coderline/alphatab/generated/EngravingSettingsCloner';
import { JsonHelper } from '@coderline/alphatab/io/JsonHelper';
import { Logger } from '@coderline/alphatab/Logger';
import { Duration } from '@coderline/alphatab/model/Duration';
import { MusicFontSymbol, MusicFontSymbolLookup } from '@coderline/alphatab/model/MusicFontSymbol';
import type { SmuflMetadata } from '@coderline/alphatab/SmuflMetadata';
/**
* @json
* @json_declaration
* @public
*/
export class EngravingStemInfo {
/**
* The top Y coordinate where the stem should start/end.
*/
public topY = 0;
/**
* The bottom Y coordinate where the stem should start/end.
*/
public bottomY = 0;
/**
* The x-coordinate of the stem.
*/
public x = 0;
}
/**
* This class holds all all spacing, thickness and scaling metrics
* related to engraving the music notation.
*
* @remarks
* While general layout settings are configurable via the display settings,
* these settings go deeper into how the individual music symbols are scaled and aligned targeting
* specification compliance with the Standard Music Font Layout (SMuFL).
*
* Unless specified differently the settings here are available {@since 1.7.0}
*
* If properties are marked with a SMuFl tag, it means that the values are part of the SMuFL specification
* and should be filled from the respective metadata files shipped with the fonts or aligned generally with the specification.
* Other properties are custom to alphaTab.
*
* In SmuFL Sizes and coordinates are expressed in "staff space" units which is 1/4 of the configured font size. In this data structure
* the values are converted to pixels.
*
* @json
* @json_declaration
* @cloneable
* @public
*/
export class EngravingSettings {
private static _bravuraDefaults?: EngravingSettings;
// NOTE: configurable in future?
/**
* @internal
*/
public static readonly GraceScale: number = 0.75;
/**
* A {@link EngravingSettings} copy filled with the settings of the Bravura font used by default in alphaTab.
*/
public static get bravuraDefaults() {
let bravuraDefaults = EngravingSettings._bravuraDefaults;
if (!bravuraDefaults) {
bravuraDefaults = new EngravingSettings();
bravuraDefaults.fillFromSmufl(EngravingSettings.bravuraMetadata);
EngravingSettings._bravuraDefaults = bravuraDefaults;
}
return EngravingSettingsCloner.clone(bravuraDefaults);
}
/**
* The font size of the music font in pixel.
*/
public musicFontSize = 0;
/**
* The staff space in pixel
* @smufl 1.4
*/
public oneStaffSpace = 0;
/**
* The staff space in pixel for tablature fonts. This is typically 1.5 of the standard staff space.
* @smufl 1.4
*/
public tabLineSpacing = 0;
/**
* The thickness of the line used for the shaft of an arrow
* @smufl 1.4
*/
public arrowShaftThickness = 0;
/**
* The default distance between multiple thin barlines when locked together, e.g. between two thin barlines making a double barline, measured from the right-hand edge of the left barline to the left-hand edge of the right barline.
* @smufl 1.4
*/
public barlineSeparation = 0;
/**
* The distance between the inner edge of the primary and outer edge of subsequent secondary beams
* @smufl 1.4
*/
public beamSpacing = 0;
/**
* The thickness of a beam
* @smufl 1.4
*/
public beamThickness = 0;
/**
* The thickness of the vertical line of a bracket grouping staves together
* @smufl 1.4
*/
public bracketThickness = 0;
/**
* The length of the dashes to be used in a dashed barline
* @smufl 1.4
*/
public dashedBarlineDashLength = 0;
/**
* The length of the gap between dashes in a dashed barline
*/
public dashedBarlineGapLength = 0;
/**
* The thickness of a dashed barline
* @smufl 1.4
*/
public dashedBarlineThickness = 0;
/**
* The thickness of a crescendo/diminuendo hairpin
* @smufl 1.4
*/
public hairpinThickness = 0;
/**
* The thickness of a leger line (normally somewhat thicker than a staff line)
* @smufl 1.4
*/
public legerLineThickness = 0;
/**
* The amount by which a leger line should extend either side of a notehead, scaled proportionally with the notehead's size, e.g. when scaled down as a grace note
* @smufl 1.4
*/
public legerLineExtension = 0;
/**
* The thickness of the dashed line used for an octave line
* @smufl 1.4
*/
public octaveLineThickness = 0;
/**
* The thickness of the line used for piano pedaling
* @smufl 1.4
*/
public pedalLineThickness = 0;
/**
* The default horizontal distance between the dots and the inner barline of a repeat barline, measured from the edge of the dots to the edge of the barline.
* @smufl 1.4
*/
public repeatBarlineDotSeparation = 0;
/**
* The thickness of the brackets drawn to indicate repeat endings
* @smufl 1.4
*/
public repeatEndingLineThickness = 0;
/**
* The thickness of the mid-point of a slur (i.e. its thickest point)
* @smufl 1.4
*/
public slurMidpointThickness = 0;
/**
* The thickness of each staff line
* @smufl 1.4
*/
public staffLineThickness = 0;
/**
* The thickness of a stem
* @smufl 1.4
*/
public stemThickness = 0;
/**
* The thickness of a thick barline, e.g. in a final barline or a repeat barline
* @smufl 1.4
*/
public thickBarlineThickness = 0;
/**
* The thickness of a dashed barline
* @smufl 1.4
*/
public thinBarlineThickness = 0;
/**
* The default distance between a pair of thin and thick barlines when locked together, e.g. between the thin and thick barlines making a final barline, or between the thick and thin barlines making a start repeat barline.
* @smufl 1.4
*/
public thinThickBarlineSeparation = 0;
/**
* The thickness of the mid-point of a tie
* @smufl 1.4
*/
public tieMidpointThickness = 0;
/**
* The thickness of the brackets drawn either side of tuplet numbers
* @smufl 1.4
*/
public tupletBracketThickness = 0;
/**
* Holds information about where to place upwards pointing stems on glyphs.
* @smufl 1.4
*/
public stemUp = new Map<MusicFontSymbol, EngravingStemInfo>();
/**
* Holds information about where to place downwards pointing stems on glyphs.
* @smufl 1.4
*/
public stemDown = new Map<MusicFontSymbol, EngravingStemInfo>();
/**
* Holds the x-coordinate offsets for glyphs which are drawn repeatedly (like vibrato waves).
* @smufl 1.4
*/
public repeatOffsetX = new Map<MusicFontSymbol, number>();
/**
* The standard stem length of a quarter note.
* @smufl 1.4
*/
public standardStemLength = 0;
/**
* The additional offsets stems need to have enough space for flags.
* @smufl 1.4
*/
public stemFlagOffsets: Map<Duration, number> = new Map<Duration, number>();
/**
* A lookup containing the offset from the visual top to the glyph center.
* The glyph center is the origin coordinate at which the glyph paths start when drawn on the alphabetic baseline.
* @smufl 1.4
*/
public glyphTop: Map<MusicFontSymbol, number> = new Map<MusicFontSymbol, number>();
/**
* A lookup containing the offset from the glyph center to the visual bottom of the glyph.
* The glyph center is the origin coordinate at which the glyph paths start when drawn on the alphabetic baseline.
* @smufl 1.4
*/
public glyphBottom: Map<MusicFontSymbol, number> = new Map<MusicFontSymbol, number>();
/**
* A lookup for the widths of the visual bounding box for the glyphs.
* @smufl 1.4
*/
public glyphWidths: Map<MusicFontSymbol, number> = new Map<MusicFontSymbol, number>();
/**
* A lookup for the heights of the visual bounding box for the glyphs.
* @smufl 1.4
*/
public glyphHeights: Map<MusicFontSymbol, number> = new Map<MusicFontSymbol, number>();
/**
* Checks whether a certain glyph is registered in the currently loaded engraving settings.
* @param symbol The symbol to check
* @returns true if the glyph is registered and available for use.
* @internal
*/
public hasSymbol(symbol: MusicFontSymbol): boolean {
return this.glyphWidths.get(symbol)! > 0 && this.glyphHeights.get(symbol)! > 0;
}
/**
* Fills the engraving settings from the provided smufl metdata.
* @param smufl The metadata shipped together with the SMuFL fonts.
* @param musicFontSize The font size to configure in alphaTab for the music font.
*/
public fillFromSmufl(smufl: SmuflMetadata, musicFontSize: number = 36) {
//
// base values
this.musicFontSize = musicFontSize;
this.oneStaffSpace = musicFontSize / 4;
// The industry practice is to give tab staves 1.5 of standard staff spacing
// With 1sp==9px we have 1.5sp==13.5px which always leads to some lines being
// blurry. Hence we round down to get a clean 13px. (condensed is better than a lot of white space)
this.tabLineSpacing = Math.floor(this.oneStaffSpace * 1.5);
//
// SmuFL Spec
this.arrowShaftThickness = smufl.engravingDefaults.arrowShaftThickness * this.oneStaffSpace;
this.barlineSeparation = smufl.engravingDefaults.barlineSeparation * this.oneStaffSpace;
this.beamSpacing = smufl.engravingDefaults.beamSpacing * this.oneStaffSpace;
this.beamThickness = smufl.engravingDefaults.beamThickness * this.oneStaffSpace;
this.bracketThickness = smufl.engravingDefaults.bracketThickness * this.oneStaffSpace;
this.dashedBarlineDashLength = smufl.engravingDefaults.dashedBarlineDashLength * this.oneStaffSpace;
this.dashedBarlineGapLength = smufl.engravingDefaults.dashedBarlineGapLength * this.oneStaffSpace;
this.dashedBarlineThickness = smufl.engravingDefaults.dashedBarlineThickness * this.oneStaffSpace;
this.hairpinThickness = smufl.engravingDefaults.hairpinThickness * this.oneStaffSpace;
this.legerLineExtension = smufl.engravingDefaults.legerLineExtension * this.oneStaffSpace;
this.legerLineThickness = smufl.engravingDefaults.legerLineThickness * this.oneStaffSpace;
// unused lyricLineThickness
this.octaveLineThickness = smufl.engravingDefaults.octaveLineThickness * this.oneStaffSpace;
this.pedalLineThickness = smufl.engravingDefaults.pedalLineThickness * this.oneStaffSpace;
this.repeatBarlineDotSeparation = smufl.engravingDefaults.repeatBarlineDotSeparation * this.oneStaffSpace;
this.repeatEndingLineThickness = smufl.engravingDefaults.repeatEndingLineThickness * this.oneStaffSpace;
// unused slurEndpointThickness
this.slurMidpointThickness = smufl.engravingDefaults.slurMidpointThickness * this.oneStaffSpace;
this.staffLineThickness = smufl.engravingDefaults.staffLineThickness * this.oneStaffSpace;
this.stemThickness = smufl.engravingDefaults.stemThickness * this.oneStaffSpace;
// unused subBracketThickness
// unused textEnclosureThickness
this.thickBarlineThickness = smufl.engravingDefaults.thickBarlineThickness * this.oneStaffSpace;
this.thinBarlineThickness = smufl.engravingDefaults.thinBarlineThickness * this.oneStaffSpace;
if (typeof smufl.engravingDefaults.thinThickBarlineSeparation === 'number') {
this.thinThickBarlineSeparation = smufl.engravingDefaults.thinThickBarlineSeparation! * this.oneStaffSpace;
} else {
this.thinThickBarlineSeparation = smufl.engravingDefaults.barlineSeparation * this.oneStaffSpace;
}
// unused tieEndpointThickness
this.tieMidpointThickness = smufl.engravingDefaults.tieMidpointThickness * this.oneStaffSpace;
this.tupletBracketThickness = smufl.engravingDefaults.tupletBracketThickness * this.oneStaffSpace;
const standardStemLength = 3 * this.oneStaffSpace;
this.standardStemLength = standardStemLength;
this.stemFlagOffsets.set(Duration.QuadrupleWhole, 0);
this.stemFlagOffsets.set(Duration.DoubleWhole, 0);
this.stemFlagOffsets.set(Duration.Whole, 0);
this.stemFlagOffsets.set(Duration.Half, 0);
this.stemFlagOffsets.set(Duration.Quarter, 0);
this.stemFlagOffsets.set(Duration.Eighth, 0);
this.stemFlagOffsets.set(Duration.Sixteenth, 0);
this.stemFlagOffsets.set(Duration.ThirtySecond, 0);
this.stemFlagOffsets.set(Duration.SixtyFourth, 0);
this.stemFlagOffsets.set(Duration.OneHundredTwentyEighth, 0);
this.stemFlagOffsets.set(Duration.TwoHundredFiftySixth, 0);
// Workaround for: https://github.com/w3c/smufl/issues/203
// There is no clear anchor for the height of flags on the stem side yet.
// These aproximations are tested with bravura
this.stemFlagHeight.set(Duration.QuadrupleWhole, 0);
this.stemFlagHeight.set(Duration.DoubleWhole, 0);
this.stemFlagHeight.set(Duration.Whole, 0);
this.stemFlagHeight.set(Duration.Half, 0);
this.stemFlagHeight.set(Duration.Quarter, 0);
this.stemFlagHeight.set(Duration.Eighth, 1 * this.oneStaffSpace);
this.stemFlagHeight.set(Duration.Sixteenth, 1.5 * this.oneStaffSpace);
this.stemFlagHeight.set(Duration.ThirtySecond, 2 * this.oneStaffSpace);
this.stemFlagHeight.set(Duration.SixtyFourth, 3 * this.oneStaffSpace);
this.stemFlagHeight.set(Duration.OneHundredTwentyEighth, 3.5 * this.oneStaffSpace);
this.stemFlagHeight.set(Duration.TwoHundredFiftySixth, 4.2 * this.oneStaffSpace);
for (const [g, v] of Object.entries(smufl.glyphsWithAnchors)) {
const symbol = EngravingSettings._smuflNameToMusicFontSymbol(g);
if (symbol) {
if (v.stemDownNW) {
const b = new EngravingStemInfo();
b.x = v.stemDownNW[0] * this.oneStaffSpace;
b.topY = v.stemDownNW[1] * this.oneStaffSpace;
if (v.stemDownSW) {
b.bottomY = v.stemDownSW[1] * this.oneStaffSpace;
} else {
b.bottomY = 0;
}
this.stemDown.set(symbol, b);
}
if (v.stemUpSE) {
const b = new EngravingStemInfo();
const bottomX = v.stemUpSE[0] * this.oneStaffSpace;
b.bottomY = v.stemUpSE[1] * this.oneStaffSpace;
if (v.stemUpNW) {
b.x = v.stemUpNW[0] * this.oneStaffSpace;
b.topY = v.stemUpNW[1] * this.oneStaffSpace;
} else {
b.x = bottomX - this.stemThickness;
b.topY = 0;
}
this.stemUp.set(symbol, b);
}
if (v.repeatOffset) {
this.repeatOffsetX.set(symbol, v.repeatOffset[0] * this.oneStaffSpace);
}
if (v.stemUpNW) {
const stemLength = v.stemUpNW[1] * this.oneStaffSpace;
switch (symbol) {
case MusicFontSymbol.Flag8thUp:
this.stemFlagOffsets.set(Duration.Eighth, stemLength);
break;
case MusicFontSymbol.Flag16thUp:
this.stemFlagOffsets.set(Duration.Sixteenth, stemLength);
break;
case MusicFontSymbol.Flag32ndUp:
this.stemFlagOffsets.set(Duration.ThirtySecond, stemLength);
break;
case MusicFontSymbol.Flag64thUp:
this.stemFlagOffsets.set(Duration.SixtyFourth, stemLength);
break;
case MusicFontSymbol.Flag128thUp:
this.stemFlagOffsets.set(Duration.OneHundredTwentyEighth, stemLength);
break;
case MusicFontSymbol.Flag256thUp:
this.stemFlagOffsets.set(Duration.TwoHundredFiftySixth, stemLength);
break;
}
}
}
}
const handledSymbols = new Set<MusicFontSymbol>();
const bBoxes = smufl.glyphBBoxes;
if (bBoxes) {
for (const [g, v] of Object.entries(bBoxes)) {
const symbol = EngravingSettings._smuflNameToMusicFontSymbol(g);
if (symbol) {
handledSymbols.add(symbol);
this.glyphTop.set(symbol, v.bBoxNE[1] * this.oneStaffSpace);
this.glyphBottom.set(symbol, v.bBoxSW[1] * this.oneStaffSpace);
this.glyphWidths.set(symbol, (v.bBoxNE[0] - v.bBoxSW[0]) * this.oneStaffSpace);
this.glyphHeights.set(symbol, (v.bBoxNE[1] - v.bBoxSW[1]) * this.oneStaffSpace);
}
}
}
// glyphBBoxes is optional, maybe we should rely on a text measuring of all glyphs for these values?
const ignoredSymbols = new Set<MusicFontSymbol>([
MusicFontSymbol.None,
MusicFontSymbol.Space,
MusicFontSymbol.NoteheadNull
]);
for (const symbol of MusicFontSymbolLookup.getAllMusicFontSymbols()) {
if (!handledSymbols.has(symbol)) {
if (!ignoredSymbols.has(symbol)) {
Logger.warning(
'SmuFL',
`The provided SmuFL font is missing the glyph ${MusicFontSymbol[symbol]} needed by alphaTab, the music notation might not show all details`
);
}
this.glyphTop.set(symbol, 0);
this.glyphBottom.set(symbol, 0);
this.glyphWidths.set(symbol, 0);
this.glyphHeights.set(symbol, 0);
}
}
//
// custom alphatab sizes
this.numberedBarRendererBarSize = this.staffLineThickness * 2;
this.numberedBarRendererBarSpacing = this.beamSpacing;
this.preNoteEffectPadding = 0.4 * this.oneStaffSpace;
this.postNoteEffectPadding = 0.2 * this.oneStaffSpace;
this.lineRangedGlyphDashGap = 0.5 * this.oneStaffSpace;
this.lineRangedGlyphDashSize = 1 * this.oneStaffSpace;
this.numberedDashGlyphPadding = 0.3 * this.oneStaffSpace;
this.numberedDashGlyphPadding = 0.3 * this.oneStaffSpace;
this.stringNumberCirclePadding = 0.3 * this.oneStaffSpace;
this.rowContainerPadding = Math.ceil(0.3 * this.oneStaffSpace);
this.rowContainerGap = Math.ceil(1 * this.oneStaffSpace);
this.onNoteEffectPadding = 0.2 * this.oneStaffSpace;
this.alternateEndingsPadding = 0.3 * this.oneStaffSpace;
this.sustainPedalLinePadding = 0.5 * this.oneStaffSpace;
this.tieHeight = 1.2 * this.oneStaffSpace;
this.beatTimerPadding = 0.22 * this.oneStaffSpace;
this.bendNoteHeadElementPadding = 0.22 * this.oneStaffSpace;
this.ghostParenthesisWidth = 0.6 * this.oneStaffSpace;
this.ghostParenthesisPadding = 0.3 * this.oneStaffSpace;
this.brokenBeamWidth = 1 * this.oneStaffSpace;
this.tabWhammyTextPadding = 0.4 * this.oneStaffSpace;
this.tabWhammyDashSize = 0.4 * this.oneStaffSpace;
this.tabBendDashSize = 0.4 * this.oneStaffSpace;
this.songBookWhammyDipHeight = 0.6 * this.oneStaffSpace;
this.tabWhammyPerHalfHeight = 0.6 * this.oneStaffSpace;
this.tabBendStaffPadding = 0.5 * this.oneStaffSpace;
this.tabBendPerValueHeight = 0.6 * this.oneStaffSpace;
this.tabBendLabelPadding = 0.3 * this.oneStaffSpace;
this.leftHandTabTieWidth = 2.2 * this.oneStaffSpace;
this.numberedDashGlyphWidth = 1.5 * this.oneStaffSpace;
this.deadSlappedLineWidth = 0.25 * this.oneStaffSpace;
this.simpleSlideWidth = 1.3 * this.oneStaffSpace;
this.simpleSlideHeight = 0.3 * this.oneStaffSpace;
this.chordDiagramPaddingX = Math.ceil(0.5 * this.oneStaffSpace);
this.chordDiagramPaddingY = Math.ceil(0.2 * this.oneStaffSpace);
this.chordDiagramStringSpacing = Math.ceil(1.1 * this.oneStaffSpace);
this.chordDiagramFretSpacing = Math.ceil(1.3 * this.oneStaffSpace);
this.chordDiagramNutHeight = Math.ceil(0.33 * this.oneStaffSpace);
this.chordDiagramFretHeight = Math.ceil(0.1 * this.oneStaffSpace);
this.chordDiagramLineWidth = Math.ceil(0.11 * this.oneStaffSpace);
this.tripletFeelBracketPadding = 0.2 * this.oneStaffSpace;
this.accidentalPadding = 0.1 * this.oneStaffSpace;
this.preBeatGlyphSpacing = 0.5 * this.oneStaffSpace;
this.multiVoiceDisplacedNoteHeadSpacing = 0.2 * this.oneStaffSpace;
this.tuningGlyphStringRowPadding = 0.2 * this.oneStaffSpace;
}
// some names are different due to technical restrictions (e.g. names beginning with digits)
/**
* @internal
*/
public static smuflNameToGlyphNameMapping: Map<string, string> = new Map<string, string>([
['4stringTabClef', 'FourStringTabClef'],
['6stringTabClef', 'SixStringTabClef']
]);
private static _smuflNameToMusicFontSymbol(g: string): MusicFontSymbol | undefined {
const name = EngravingSettings.smuflNameToGlyphNameMapping.has(g)
? EngravingSettings.smuflNameToGlyphNameMapping.get(g)!
: g.substring(0, 1).toUpperCase() + g.substring(1);
return JsonHelper.parseEnumExact<MusicFontSymbol>(name, MusicFontSymbol);
}
// Numbered Notation: SMuFL has no numbered notation yet
/**
* The size of the bars drawn in numbered notation to indicate the durations.
*/
public numberedBarRendererBarSize = 0;
/**
* The spacing between the bars drawn in numbered notation to indicate the durations.
*/
public numberedBarRendererBarSpacing = 0;
/**
* The padding minimum between the duration dashes.
*/
public numberedDashGlyphPadding = 0;
/**
* The width of the dashed drawn in numbered notation to indicate the durations.
*/
public numberedDashGlyphWidth = 0;
// Line Ranged Glyphs: smufl doesn's have any good reference for dashed lines on effects
/**
* The gap between dashes on line ranged glyphs (like let-ring)
*/
public lineRangedGlyphDashGap = 0;
/**
* The size between dashes on line ranged glyphs (like let-ring)
*/
public lineRangedGlyphDashSize = 0;
/**
* The padding between effects and glyphs placed before the note heads, e.g. accidentals or brushes
*/
public preNoteEffectPadding = 0;
/**
* The padding between effects and glyphs placed after the note heads, e.g. slides or bends
*/
public postNoteEffectPadding = 0;
/**
* The padding between effects and glyphs placed above/blow the note heads e.g. staccato
*/
public onNoteEffectPadding = 0;
/**
* The padding between the circles around string numbers.
*/
public stringNumberCirclePadding = 0;
/**
* The outer padding for glyphs arranged in a grid like fashion, like the tunings and chord diagrams.
*/
public rowContainerPadding = 0;
/**
* The innter gap for glyphs arranged in a grid like fashion, like the tunings and chord diagrams.
*/
public rowContainerGap = 0;
/**
* The padding used for aligning the alternate ending brackets and texts.
*/
public alternateEndingsPadding = 0;
/**
* The padding between the sustain pedal glyphs and lines.
*/
public sustainPedalLinePadding = 0;
/**
* The height of ties.
*/
public tieHeight = 0;
/**
* The padding between the border and text of beat timers.
*/
public beatTimerPadding = 0;
/**
* The additional padding applied to helper note heads shown on bends.
*/
public bendNoteHeadElementPadding = 0;
/**
* The width of the parenthesis shown on ghost notes and free time time signatures.
*/
public ghostParenthesisWidth = 0;
/**
* The padding between the parenthesis and wrapped elements on ghost notes and free time time signatures
*/
public ghostParenthesisPadding = 0;
/**
* The width of broken beams e.g. when combining a 32nd and 16th note
*/
public brokenBeamWidth = 0;
/**
* The padding between the text and whammy lines.
*/
public tabWhammyTextPadding = 0;
/**
* The height applied per half-note whammy.
*/
public tabWhammyPerHalfHeight = 0;
/**
* The size of the dashes on whammys (e.g. on holds)
*/
public tabWhammyDashSize = 0;
/**
* The height of simple dip whammys when using the songbook mode.
*/
public songBookWhammyDipHeight = 0;
/**
* The width of the lines drawn for dead slapped beats.
*/
public deadSlappedLineWidth = 0;
/**
* The width of ties drawn for left-hand-tapped notes.
*/
public leftHandTabTieWidth = 0;
/**
* The size of the dashes on bends (e.g. on holds)
*/
public tabBendDashSize = 0;
/**
* The additional padding between the staff and the point
* where bend values are calculated from.
*/
public tabBendStaffPadding = 0;
/**
* The height applied per quarter-note.
*/
public tabBendPerValueHeight = 0;
/**
* The padding applied between the line and text of bends.
*/
public tabBendLabelPadding = 0;
/**
* The width of simple slides like slide out down which do slide to a defined target note.
*/
public simpleSlideWidth = 0;
/**
* The height of simple slides like slide out down which do slide to a defined target note.
*/
public simpleSlideHeight = 0;
/**
* The horizontal padding applied to individual chord diagrams.
*/
public chordDiagramPaddingX = 0;
/**
* The vertical padding applied to individual chord diagrams.
*/
public chordDiagramPaddingY = 0;
/**
* The spacing between strings on chord diagrams.
*/
public chordDiagramStringSpacing = 0;
/**
* The spacing between frets on chord diagrams.
*/
public chordDiagramFretSpacing = 0;
/**
* The height of the nut on chord diagrams..
*/
public chordDiagramNutHeight = 0;
/**
* The height of the individual fret lines.
*/
public chordDiagramFretHeight = 0;
/**
* The width of all other lines drawn on chord diagrams.
*/
public chordDiagramLineWidth = 0;
/**
* The padding between the bracket lines and numbers of tuplets
*/
public tripletFeelBracketPadding = 0;
/**
* The horizontal padding between individual accidentals when multiple ones are applied.
*/
public accidentalPadding = 0;
/**
* The padding between glyphs shown before any beats e.g. clefs and time signatures
*/
public preBeatGlyphSpacing = 0;
/**
* The relative scale of the note drawn on tempo markers
*/
public tempoNoteScale = 0.7;
/**
* The scale of string numbers shown on tuning glyphs.
*/
public tuningGlyphCircleNumberScale = 0.7;
/**
* The scale factor applied to the width of the columns of string on tuning glyphs.
*/
public tuningGlyphStringColumnScale = 1.5;
/**
* The padding between rows of strings on tuning glyphs.
*/
public tuningGlyphStringRowPadding = 0;
/**
* The relative scale of any directions glyphs drawn like coda or segno.
*/
public directionsScale = 0.6;
/**
* The spacing between displaced displaced note heads
* in case of multi-voice note head overlaps.
*/
public multiVoiceDisplacedNoteHeadSpacing = 0;
/**
* Calculates the stem height for a note of the given duration.
* @param duration The duration to calculate the height respecting flag sizes.
* @param hasFlag True if we need to respect flags, false if we have beams.
* @returns The total stem height
*/
public getStemLength(duration: Duration, hasFlag: boolean) {
return this.standardStemLength + (hasFlag ? this.stemFlagOffsets.get(duration)! : 0);
}
/**
* The space needed by flags on the stem-side from top to bottom to place.
*/
public stemFlagHeight: Map<Duration, number> = new Map<Duration, number>();
// Idea: maybe we can encode and pack this large metadata into a more compact format (e.g. BSON or a custom binary blob?)
// This metadata below is updated automatically from the bravura_metadata.json via npm script
public static readonly bravuraMetadata: SmuflMetadata =
// begin bravura_alphatab_metadata
{
engravingDefaults: {
arrowShaftThickness: 0.16,
barlineSeparation: 0.4,
beamSpacing: 0.25,
beamThickness: 0.5,
bracketThickness: 0.5,
dashedBarlineDashLength: 0.5,
dashedBarlineGapLength: 0.25,
dashedBarlineThickness: 0.16,
hairpinThickness: 0.16,
legerLineExtension: 0.4,
legerLineThickness: 0.16,
lyricLineThickness: 0.16,
octaveLineThickness: 0.16,
pedalLineThickness: 0.16,
repeatBarlineDotSeparation: 0.16,
repeatEndingLineThickness: 0.16,
slurEndpointThickness: 0.1,
slurMidpointThickness: 0.22,
staffLineThickness: 0.13,
stemThickness: 0.12,
subBracketThickness: 0.16,
textEnclosureThickness: 0.16,
thickBarlineThickness: 0.5,
thinBarlineThickness: 0.16,
tieEndpointThickness: 0.1,
tieMidpointThickness: 0.22,
thinThickBarlineSeparation: 0.4,
tupletBracketThickness: 0.16
},
glyphBBoxes: {
FourStringTabClef: {
bBoxNE: [1.088, 2.016],
bBoxSW: [-0.012, -2.032]
},
SixStringTabClef: {
bBoxNE: [1.632, 3.056],
bBoxSW: [-0.012, -2.992]
},
accidentalDoubleFlat: {
bBoxNE: [1.644, 1.748],
bBoxSW: [0, -0.7]
},
accidentalDoubleSharp: {
bBoxNE: [0.988, 0.508],
bBoxSW: [0, -0.5]
},
accidentalFlat: {
bBoxNE: [0.904, 1.756],
bBoxSW: [0, -0.7]
},
accidentalNatural: {
bBoxNE: [0.672, 1.364],
bBoxSW: [0, -1.34]
},
accidentalQuarterToneFlatArrowUp: {
bBoxNE: [0.992, 2.316],
bBoxSW: [-0.168, -0.708]
},
accidentalQuarterToneSharpNaturalArrowUp: {
bBoxNE: [0.848, 2.188],
bBoxSW: [-0.104, -1.36]
},
accidentalSharp: {
bBoxNE: [0.996, 1.4],
bBoxSW: [0, -1.392]
},
accidentalThreeQuarterTonesSharpArrowUp: {
bBoxNE: [1.1, 2.12],
bBoxSW: [0, -1.388]
},
arrowheadBlackDown: {
bBoxNE: [0.912, 1.196],
bBoxSW: [0, 0]
},
arrowheadBlackUp: {
bBoxNE: [0.912, 1.196],
bBoxSW: [0, 0]
},
articAccentAbove: {
bBoxNE: [1.356, 0.98],
bBoxSW: [0, 0.004]
},
articAccentBelow: {
bBoxNE: [1.356, 0],
bBoxSW: [0, -0.976]
},
articMarcatoAbove: {
bBoxNE: [0.94, 1.012],
bBoxSW: [-0.004, -0.004]
},
articMarcatoBelow: {
bBoxNE: [0.94, 0],
bBoxSW: [-0.004, -1.016]
},
articStaccatoAbove: {
bBoxNE: [0.336, 0.336],
bBoxSW: [0, 0]
},
articStaccatoBelow: {
bBoxNE: [0.336, 0],
bBoxSW: [0, -0.336]
},
articTenutoAbove: {
bBoxNE: [1.352, 0.192],
bBoxSW: [-0.004, 0]
},
articTenutoBelow: {
bBoxNE: [1.352, 0],
bBoxSW: [-0.004, -0.192]
},
augmentationDot: {
bBoxNE: [0.4, 0.2],
bBoxSW: [0, -0.2]
},
brace: {
bBoxNE: [0.328, 3.988],
bBoxSW: [0.008, 0]
},
bracketBottom: {
bBoxNE: [1.876, 0],
bBoxSW: [0, -1.18]
},
bracketTop: {
bBoxNE: [1.876, 1.18],
bBoxSW: [0, 0]
},
buzzRoll: {
bBoxNE: [0.624, 0.464],
bBoxSW: [-0.62, -0.464]
},
cClef: {
bBoxNE: [2.796, 2.024],
bBoxSW: [0, -2.024]
},
cClef8vb: {
bBoxNE: [2.796, 2.024],
bBoxSW: [0, -2.964]
},
clef15: {
bBoxNE: [1.436, 1.02],
bBoxSW: [0, -0.012]
},
clef8: {
bBoxNE: [0.82, 0.988],
bBoxSW: [0, 0]
},
coda: {
bBoxNE: [3.82, 3.592],
bBoxSW: [-0.016, -0.632]
},
dynamicCrescendoHairpin: {
bBoxNE: [2.944, 1.424],
bBoxSW: [0.016, 0.372]
},
dynamicFF: {
bBoxNE: [2.44, 1.776],
bBoxSW: [-0.54, -0.608]
},
dynamicFFF: {
bBoxNE: [3.32, 1.776],
bBoxSW: [-0.62, -0.608]
},
dynamicFFFF: {
bBoxNE: [4.28, 1.776],
bBoxSW: [-0.62, -0.608]
},
dynamicFFFFF: {
bBoxNE: [5.24, 1.776],
bBoxSW: [-0.62, -0.608]
},
dynamicFFFFFF: {
bBoxNE: [6.2, 1.776],
bBoxSW: [-0.62, -0.608]
},
dynamicForte: {
bBoxNE: [1.456, 1.776],
bBoxSW: [-0.564, -0.608]
},
dynamicFortePiano: {
bBoxNE: [2.476, 1.776],
bBoxSW: [-0.564, -0.608]
},
dynamicForzando: {
bBoxNE: [1.988, 1.776],
bBoxSW: [-0.564, -0.608]
},
dynamicMF: {
bBoxNE: [3.272, 1.724],
bBoxSW: [-0.08, -0.66]
},
dynamicMP: {
bBoxNE: [3.3, 1.096],
bBoxSW: [-0.08, -0.568]
},
dynamicNiente: {
bBoxNE: [1.232, 1.096],