vexflow 5.0.0-alpha.2 → 5.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/build/cjs/vexflow-bravura.js +2 -2
  2. package/build/cjs/vexflow-bravura.js.map +1 -1
  3. package/build/cjs/vexflow-core.js +2 -2
  4. package/build/cjs/vexflow-core.js.map +1 -1
  5. package/build/cjs/vexflow-debug-with-tests.js +528 -492
  6. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  7. package/build/cjs/vexflow-debug.js +460 -452
  8. package/build/cjs/vexflow-debug.js.map +1 -1
  9. package/build/cjs/vexflow.js +2 -2
  10. package/build/cjs/vexflow.js.map +1 -1
  11. package/build/esm/src/accidental.js +22 -28
  12. package/build/esm/src/beam.js +24 -42
  13. package/build/esm/src/clefnote.js +6 -1
  14. package/build/esm/src/element.js +83 -101
  15. package/build/esm/src/fonts/gonville.js +1 -1
  16. package/build/esm/src/formatter.js +9 -17
  17. package/build/esm/src/fraction.js +15 -22
  18. package/build/esm/src/glyphnote.js +3 -2
  19. package/build/esm/src/metrics.js +3 -0
  20. package/build/esm/src/modifier.js +6 -21
  21. package/build/esm/src/multimeasurerest.js +16 -25
  22. package/build/esm/src/note.js +7 -0
  23. package/build/esm/src/registry.js +5 -19
  24. package/build/esm/src/stave.js +4 -6
  25. package/build/esm/src/stavenote.js +26 -40
  26. package/build/esm/src/stavetempo.js +4 -11
  27. package/build/esm/src/stavetie.js +82 -36
  28. package/build/esm/src/svgcontext.js +5 -12
  29. package/build/esm/src/tickable.js +13 -26
  30. package/build/esm/src/tickcontext.js +20 -2
  31. package/build/esm/src/version.js +3 -3
  32. package/build/esm/src/vibrato.js +6 -1
  33. package/build/esm/tests/clef_tests.js +5 -1
  34. package/build/esm/tests/glyphnote_tests.js +6 -0
  35. package/build/esm/tests/stavetie_tests.js +29 -0
  36. package/build/esm/tests/tabstave_tests.js +1 -0
  37. package/build/esm/tests/vexflow_test_helpers.js +25 -39
  38. package/build/types/src/accidental.d.ts +19 -1
  39. package/build/types/src/annotation.d.ts +1 -1
  40. package/build/types/src/beam.d.ts +12 -1
  41. package/build/types/src/clefnote.d.ts +2 -0
  42. package/build/types/src/element.d.ts +13 -3
  43. package/build/types/src/fonts/gonville.d.ts +1 -1
  44. package/build/types/src/formatter.d.ts +5 -3
  45. package/build/types/src/fraction.d.ts +12 -7
  46. package/build/types/src/modifier.d.ts +2 -1
  47. package/build/types/src/multimeasurerest.d.ts +4 -1
  48. package/build/types/src/note.d.ts +2 -0
  49. package/build/types/src/registry.d.ts +1 -1
  50. package/build/types/src/stavenote.d.ts +2 -1
  51. package/build/types/src/stavetempo.d.ts +3 -3
  52. package/build/types/src/stavetie.d.ts +39 -2
  53. package/build/types/src/svgcontext.d.ts +1 -1
  54. package/build/types/src/tickable.d.ts +2 -1
  55. package/build/types/src/tickcontext.d.ts +30 -0
  56. package/package.json +2 -4
  57. package/tests/flow.html +2 -2
  58. package/entry/vexflow-bravura.ts +0 -25
  59. package/entry/vexflow-core.ts +0 -16
  60. package/entry/vexflow-debug-with-tests.ts +0 -64
  61. package/entry/vexflow-debug.ts +0 -54
  62. package/entry/vexflow.ts +0 -47
  63. package/src/accidental.ts +0 -570
  64. package/src/annotation.ts +0 -294
  65. package/src/articulation.ts +0 -383
  66. package/src/barnote.ts +0 -95
  67. package/src/beam.ts +0 -999
  68. package/src/bend.ts +0 -268
  69. package/src/boundingbox.ts +0 -108
  70. package/src/canvascontext.ts +0 -348
  71. package/src/chordsymbol.ts +0 -473
  72. package/src/clef.ts +0 -164
  73. package/src/clefnote.ts +0 -50
  74. package/src/crescendo.ts +0 -132
  75. package/src/curve.ts +0 -195
  76. package/src/dot.ts +0 -171
  77. package/src/easyscore.ts +0 -538
  78. package/src/element.ts +0 -692
  79. package/src/factory.ts +0 -694
  80. package/src/font.ts +0 -343
  81. package/src/fonts/academico.ts +0 -2
  82. package/src/fonts/academicobold.ts +0 -2
  83. package/src/fonts/bravura.ts +0 -2
  84. package/src/fonts/gonville.ts +0 -2
  85. package/src/fonts/petaluma.ts +0 -2
  86. package/src/fonts/petalumascript.ts +0 -2
  87. package/src/formatter.ts +0 -1107
  88. package/src/fraction.ts +0 -245
  89. package/src/frethandfinger.ts +0 -180
  90. package/src/ghostnote.ts +0 -75
  91. package/src/glyphnote.ts +0 -68
  92. package/src/glyphs.ts +0 -5880
  93. package/src/gracenote.ts +0 -146
  94. package/src/gracenotegroup.ts +0 -194
  95. package/src/gracetabnote.ts +0 -30
  96. package/src/index.ts +0 -90
  97. package/src/keymanager.ts +0 -153
  98. package/src/keysignature.ts +0 -272
  99. package/src/keysignote.ts +0 -46
  100. package/src/metrics.ts +0 -222
  101. package/src/modifier.ts +0 -216
  102. package/src/modifiercontext.ts +0 -177
  103. package/src/multimeasurerest.ts +0 -229
  104. package/src/music.ts +0 -443
  105. package/src/note.ts +0 -690
  106. package/src/notehead.ts +0 -158
  107. package/src/notesubgroup.ts +0 -88
  108. package/src/ornament.ts +0 -301
  109. package/src/parenthesis.ts +0 -89
  110. package/src/parser.ts +0 -263
  111. package/src/pedalmarking.ts +0 -273
  112. package/src/registry.ts +0 -146
  113. package/src/rendercontext.ts +0 -98
  114. package/src/renderer.ts +0 -166
  115. package/src/repeatnote.ts +0 -25
  116. package/src/stave.ts +0 -885
  117. package/src/stavebarline.ts +0 -231
  118. package/src/staveconnector.ts +0 -281
  119. package/src/stavehairpin.ts +0 -209
  120. package/src/staveline.ts +0 -343
  121. package/src/stavemodifier.ts +0 -93
  122. package/src/stavenote.ts +0 -1230
  123. package/src/staverepetition.ts +0 -148
  124. package/src/stavesection.ts +0 -54
  125. package/src/stavetempo.ts +0 -162
  126. package/src/stavetext.ts +0 -69
  127. package/src/stavetie.ts +0 -235
  128. package/src/stavevolta.ts +0 -66
  129. package/src/stem.ts +0 -225
  130. package/src/stemmablenote.ts +0 -248
  131. package/src/stringnumber.ts +0 -286
  132. package/src/strokes.ts +0 -214
  133. package/src/svgcontext.ts +0 -639
  134. package/src/system.ts +0 -327
  135. package/src/tables.ts +0 -796
  136. package/src/tabnote.ts +0 -449
  137. package/src/tabslide.ts +0 -115
  138. package/src/tabstave.ts +0 -31
  139. package/src/tabtie.ts +0 -44
  140. package/src/textbracket.ts +0 -231
  141. package/src/textdynamics.ts +0 -101
  142. package/src/textnote.ts +0 -175
  143. package/src/tickable.ts +0 -374
  144. package/src/tickcontext.ts +0 -280
  145. package/src/timesignature.ts +0 -229
  146. package/src/timesignote.ts +0 -45
  147. package/src/tremolo.ts +0 -51
  148. package/src/tuning.ts +0 -90
  149. package/src/tuplet.ts +0 -349
  150. package/src/typeguard.ts +0 -136
  151. package/src/util.ts +0 -169
  152. package/src/version.ts +0 -4
  153. package/src/vexflow.ts +0 -378
  154. package/src/vibrato.ts +0 -99
  155. package/src/vibratobracket.ts +0 -81
  156. package/src/voice.ts +0 -302
  157. package/src/web.ts +0 -35
package/src/tables.ts DELETED
@@ -1,796 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
-
3
- import { ArticulationStruct } from './articulation';
4
- import { Fraction } from './fraction';
5
- import { Glyphs } from './glyphs';
6
- import { GlyphProps, KeyProps } from './note';
7
- import { RuntimeError } from './util';
8
-
9
- const RESOLUTION = 16384;
10
-
11
- /**
12
- * Map duration numbers to 'ticks', the unit of duration used throughout VexFlow.
13
- * For example, a quarter note is 4, so it maps to RESOLUTION / 4 = 4096 ticks.
14
- */
15
- const durations: Record<string, number> = {
16
- '1/2': RESOLUTION * 2,
17
- 1: RESOLUTION / 1,
18
- 2: RESOLUTION / 2,
19
- 4: RESOLUTION / 4,
20
- 8: RESOLUTION / 8,
21
- 16: RESOLUTION / 16,
22
- 32: RESOLUTION / 32,
23
- 64: RESOLUTION / 64,
24
- 128: RESOLUTION / 128,
25
- 256: RESOLUTION / 256,
26
- };
27
-
28
- const durationAliases: Record<string, string> = {
29
- w: '1',
30
- h: '2',
31
- q: '4',
32
-
33
- // This is the default duration used to render bars (BarNote). Bars no longer
34
- // consume ticks, so this should be a no-op.
35
- // TODO(0xfe): This needs to be cleaned up.
36
- b: '256',
37
- };
38
-
39
- const keySignatures: Record<string, { accidental?: string; num: number }> = {
40
- C: { num: 0 },
41
- Am: { num: 0 },
42
- F: { accidental: 'b', num: 1 },
43
- Dm: { accidental: 'b', num: 1 },
44
- Bb: { accidental: 'b', num: 2 },
45
- Gm: { accidental: 'b', num: 2 },
46
- Eb: { accidental: 'b', num: 3 },
47
- Cm: { accidental: 'b', num: 3 },
48
- Ab: { accidental: 'b', num: 4 },
49
- Fm: { accidental: 'b', num: 4 },
50
- Db: { accidental: 'b', num: 5 },
51
- Bbm: { accidental: 'b', num: 5 },
52
- Gb: { accidental: 'b', num: 6 },
53
- Ebm: { accidental: 'b', num: 6 },
54
- Cb: { accidental: 'b', num: 7 },
55
- Abm: { accidental: 'b', num: 7 },
56
- G: { accidental: '#', num: 1 },
57
- Em: { accidental: '#', num: 1 },
58
- D: { accidental: '#', num: 2 },
59
- Bm: { accidental: '#', num: 2 },
60
- A: { accidental: '#', num: 3 },
61
- 'F#m': { accidental: '#', num: 3 },
62
- E: { accidental: '#', num: 4 },
63
- 'C#m': { accidental: '#', num: 4 },
64
- B: { accidental: '#', num: 5 },
65
- 'G#m': { accidental: '#', num: 5 },
66
- 'F#': { accidental: '#', num: 6 },
67
- 'D#m': { accidental: '#', num: 6 },
68
- 'C#': { accidental: '#', num: 7 },
69
- 'A#m': { accidental: '#', num: 7 },
70
- };
71
-
72
- const clefs: Record<string, { lineShift: number }> = {
73
- treble: { lineShift: 0 },
74
- bass: { lineShift: 6 },
75
- tenor: { lineShift: 4 },
76
- alto: { lineShift: 3 },
77
- soprano: { lineShift: 1 },
78
- percussion: { lineShift: 0 },
79
- 'mezzo-soprano': { lineShift: 2 },
80
- 'baritone-c': { lineShift: 5 },
81
- 'baritone-f': { lineShift: 5 },
82
- subbass: { lineShift: 7 },
83
- french: { lineShift: -1 },
84
- };
85
-
86
- const notesInfo: Record<
87
- string,
88
- {
89
- index: number;
90
- intVal?: number;
91
- }
92
- > = {
93
- C: { index: 0, intVal: 0 },
94
- CN: { index: 0, intVal: 0 },
95
- 'C#': { index: 0, intVal: 1 },
96
- 'C##': { index: 0, intVal: 2 },
97
- CB: { index: 0, intVal: 11 },
98
- CBB: { index: 0, intVal: 10 },
99
- D: { index: 1, intVal: 2 },
100
- DN: { index: 1, intVal: 2 },
101
- 'D#': { index: 1, intVal: 3 },
102
- 'D##': { index: 1, intVal: 4 },
103
- DB: { index: 1, intVal: 1 },
104
- DBB: { index: 1, intVal: 0 },
105
- E: { index: 2, intVal: 4 },
106
- EN: { index: 2, intVal: 4 },
107
- 'E#': { index: 2, intVal: 5 },
108
- 'E##': { index: 2, intVal: 6 },
109
- EB: { index: 2, intVal: 3 },
110
- EBB: { index: 2, intVal: 2 },
111
- F: { index: 3, intVal: 5 },
112
- FN: { index: 3, intVal: 5 },
113
- 'F#': { index: 3, intVal: 6 },
114
- 'F##': { index: 3, intVal: 7 },
115
- FB: { index: 3, intVal: 4 },
116
- FBB: { index: 3, intVal: 3 },
117
- G: { index: 4, intVal: 7 },
118
- GN: { index: 4, intVal: 7 },
119
- 'G#': { index: 4, intVal: 8 },
120
- 'G##': { index: 4, intVal: 9 },
121
- GB: { index: 4, intVal: 6 },
122
- GBB: { index: 4, intVal: 5 },
123
- A: { index: 5, intVal: 9 },
124
- AN: { index: 5, intVal: 9 },
125
- 'A#': { index: 5, intVal: 10 },
126
- 'A##': { index: 5, intVal: 11 },
127
- AB: { index: 5, intVal: 8 },
128
- ABB: { index: 5, intVal: 7 },
129
- B: { index: 6, intVal: 11 },
130
- BN: { index: 6, intVal: 11 },
131
- 'B#': { index: 6, intVal: 12 },
132
- 'B##': { index: 6, intVal: 13 },
133
- BB: { index: 6, intVal: 10 },
134
- BBB: { index: 6, intVal: 9 },
135
- R: { index: 6 }, // Rest
136
- X: { index: 6 },
137
- };
138
-
139
- const validNoteTypes: Record<string, { name: string }> = {
140
- n: { name: 'note' },
141
- r: { name: 'rest' },
142
- h: { name: 'harmonic' },
143
- m: { name: 'muted' },
144
- s: { name: 'slash' },
145
- g: { name: 'ghost' },
146
- d: { name: 'diamond' },
147
- x: { name: 'x' },
148
- ci: { name: 'circled' },
149
- cx: { name: 'circle x' },
150
- sf: { name: 'slashed' },
151
- sb: { name: 'slashed backward' },
152
- sq: { name: 'square' },
153
- tu: { name: 'triangle up' },
154
- td: { name: 'triangle down' },
155
- };
156
-
157
- const accidentals: Record<string, string> = {
158
- '#': Glyphs.accidentalSharp,
159
- '##': Glyphs.accidentalDoubleSharp,
160
- b: Glyphs.accidentalFlat,
161
- bb: Glyphs.accidentalDoubleFlat,
162
- n: Glyphs.accidentalNatural,
163
- '{': Glyphs.accidentalParensLeft,
164
- '}': Glyphs.accidentalParensRight,
165
- db: Glyphs.accidentalThreeQuarterTonesFlatZimmermann,
166
- d: Glyphs.accidentalQuarterToneFlatStein,
167
- '++': Glyphs.accidentalThreeQuarterTonesSharpStein,
168
- '+': Glyphs.accidentalQuarterToneSharpStein,
169
- '+-': Glyphs.accidentalKucukMucennebSharp,
170
- bs: Glyphs.accidentalBakiyeFlat,
171
- bss: Glyphs.accidentalBuyukMucennebFlat,
172
- o: Glyphs.accidentalSori,
173
- k: Glyphs.accidentalKoron,
174
- bbs: Glyphs.accidentalBuyukMucennebSharp,
175
- '++-': Glyphs.accidentalBuyukMucennebSharp,
176
- ashs: Glyphs.accidentalBuyukMucennebSharp,
177
- afhf: Glyphs.accidentalBuyukMucennebSharp,
178
- };
179
-
180
- // Helps determine the layout of accidentals.
181
- const accidentalColumns: Record<number, { [name: string]: number[] }> = {
182
- 1: {
183
- a: [1],
184
- b: [1],
185
- },
186
- 2: {
187
- a: [1, 2],
188
- },
189
- 3: {
190
- a: [1, 3, 2],
191
- b: [1, 2, 1],
192
- secondOnBottom: [1, 2, 3],
193
- },
194
- 4: {
195
- a: [1, 3, 4, 2],
196
- b: [1, 2, 3, 1],
197
- spacedOutTetrachord: [1, 2, 1, 2],
198
- },
199
- 5: {
200
- a: [1, 3, 5, 4, 2],
201
- b: [1, 2, 4, 3, 1],
202
- spacedOutPentachord: [1, 2, 3, 2, 1],
203
- verySpacedOutPentachord: [1, 2, 1, 2, 1],
204
- },
205
- 6: {
206
- a: [1, 3, 5, 6, 4, 2],
207
- b: [1, 2, 4, 5, 3, 1],
208
- spacedOutHexachord: [1, 3, 2, 1, 3, 2],
209
- verySpacedOutHexachord: [1, 2, 1, 2, 1, 2],
210
- },
211
- };
212
-
213
- const articulations: Record<string, ArticulationStruct> = {
214
- 'a.': { code: Glyphs.augmentationDot, betweenLines: true }, // Staccato
215
- av: {
216
- aboveCode: Glyphs.articStaccatissimoAbove,
217
- belowCode: Glyphs.articStaccatissimoBelow,
218
- betweenLines: true,
219
- }, // Staccatissimo
220
- 'a>': {
221
- aboveCode: Glyphs.articAccentAbove,
222
- belowCode: Glyphs.articAccentBelow,
223
- betweenLines: true,
224
- }, // Accent
225
- 'a-': {
226
- aboveCode: Glyphs.articTenutoAbove,
227
- belowCode: Glyphs.articTenutoBelow,
228
- betweenLines: true,
229
- }, // Tenuto
230
- 'a^': {
231
- aboveCode: Glyphs.articMarcatoAbove,
232
- belowCode: Glyphs.articMarcatoBelow,
233
- betweenLines: false,
234
- }, // Marcato
235
- 'a+': { code: Glyphs.pluckedLeftHandPizzicato, betweenLines: false }, // Left hand pizzicato
236
- ao: {
237
- aboveCode: Glyphs.pluckedSnapPizzicatoAbove,
238
- belowCode: Glyphs.pluckedSnapPizzicatoBelow,
239
- betweenLines: false,
240
- }, // Snap pizzicato
241
- ah: { code: Glyphs.stringsHarmonic, betweenLines: false }, // Natural harmonic or open note
242
- 'a@': { aboveCode: Glyphs.fermataAbove, belowCode: Glyphs.fermataBelow, betweenLines: false }, // Fermata
243
- 'a@a': { code: Glyphs.fermataAbove, betweenLines: false }, // Fermata above staff
244
- 'a@u': { code: Glyphs.fermataBelow, betweenLines: false }, // Fermata below staff
245
- 'a@s': { aboveCode: Glyphs.fermataShortAbove, belowCode: Glyphs.fermataShortBelow, betweenLines: false }, // Fermata short
246
- 'a@as': { code: Glyphs.fermataShortAbove, betweenLines: false }, // Fermata short above staff
247
- 'a@us': { code: Glyphs.fermataShortBelow, betweenLines: false }, // Fermata short below staff
248
- 'a@l': { aboveCode: Glyphs.fermataLongAbove, belowCode: Glyphs.fermataLongBelow, betweenLines: false }, // Fermata long
249
- 'a@al': { code: Glyphs.fermataLongAbove, betweenLines: false }, // Fermata long above staff
250
- 'a@ul': { code: Glyphs.fermataLongBelow, betweenLines: false }, // Fermata long below staff
251
- 'a@vl': {
252
- aboveCode: Glyphs.fermataVeryLongAbove,
253
- belowCode: Glyphs.fermataVeryLongBelow,
254
- betweenLines: false,
255
- }, // Fermata very long
256
- 'a@avl': { code: Glyphs.fermataVeryLongAbove, betweenLines: false }, // Fermata very long above staff
257
- 'a@uvl': { code: Glyphs.fermataVeryLongBelow, betweenLines: false }, // Fermata very long below staff
258
- 'a|': { code: Glyphs.stringsUpBow, betweenLines: false }, // Bow up - up stroke
259
- am: { code: Glyphs.stringsDownBow, betweenLines: false }, // Bow down - down stroke
260
- 'a,': { code: Glyphs.pictChokeCymbal, betweenLines: false }, // Choked
261
- };
262
-
263
- const ornaments: Record<string, string> = {
264
- mordent: Glyphs.ornamentShortTrill,
265
- mordentInverted: Glyphs.ornamentMordent,
266
- turn: Glyphs.ornamentTurn,
267
- turnInverted: Glyphs.ornamentTurnSlash,
268
- tr: Glyphs.ornamentTrill,
269
- upprall: Glyphs.ornamentPrecompSlideTrillDAnglebert,
270
- downprall: Glyphs.ornamentPrecompDoubleCadenceUpperPrefix,
271
- prallup: Glyphs.ornamentPrecompTrillSuffixDandrieu,
272
- pralldown: Glyphs.ornamentPrecompTrillLowerSuffix,
273
- upmordent: Glyphs.ornamentPrecompSlideTrillBach,
274
- downmordent: Glyphs.ornamentPrecompDoubleCadenceUpperPrefixTurn,
275
- lineprall: Glyphs.ornamentPrecompAppoggTrill,
276
- prallprall: Glyphs.ornamentTremblement,
277
- scoop: Glyphs.brassScoop,
278
- doit: Glyphs.brassDoitMedium,
279
- fall: Glyphs.brassFallLipShort,
280
- doitLong: Glyphs.brassLiftMedium,
281
- fallLong: Glyphs.brassFallRoughMedium,
282
- bend: Glyphs.brassBend,
283
- plungerClosed: Glyphs.brassMuteClosed,
284
- plungerOpen: Glyphs.brassMuteOpen,
285
- flip: Glyphs.brassFlip,
286
- jazzTurn: Glyphs.brassJazzTurn,
287
- smear: Glyphs.brassSmear,
288
- };
289
-
290
- export class Tables {
291
- static UNISON = true;
292
- static SOFTMAX_FACTOR = 10;
293
- static STEM_WIDTH = 1.5;
294
- static STEM_HEIGHT = 35;
295
- static STAVE_LINE_THICKNESS = 1;
296
- static RENDER_PRECISION_PLACES = 3;
297
- static RESOLUTION = RESOLUTION;
298
-
299
- // 1/2, 1, 2, 4, 8, 16, 32, 64, 128
300
- // NOTE: There is no 256 here! However, there are other mentions of 256 in this file.
301
- // For example, in durations has a 256 key, and sanitizeDuration() can return 256.
302
- // The sanitizeDuration() bit may need to be removed by 0xfe.
303
- static durationCodes: Record<string, Partial<GlyphProps>> = {
304
- '1/2': {
305
- stem: false,
306
- },
307
-
308
- 1: {
309
- stem: false,
310
- },
311
-
312
- 2: {
313
- stem: true,
314
- },
315
-
316
- 4: {
317
- stem: true,
318
- },
319
-
320
- 8: {
321
- stem: true,
322
- beamCount: 1,
323
- stemBeamExtension: 0,
324
- codeFlagUp: Glyphs.flag8thUp,
325
- },
326
-
327
- 16: {
328
- beamCount: 2,
329
- stemBeamExtension: 0,
330
- stem: true,
331
- codeFlagUp: Glyphs.flag16thUp,
332
- },
333
-
334
- 32: {
335
- beamCount: 3,
336
- stemBeamExtension: 7.5,
337
- stem: true,
338
- codeFlagUp: Glyphs.flag32ndUp,
339
- },
340
-
341
- 64: {
342
- beamCount: 4,
343
- stemBeamExtension: 15,
344
- stem: true,
345
- codeFlagUp: Glyphs.flag64thUp,
346
- },
347
-
348
- 128: {
349
- beamCount: 5,
350
- stemBeamExtension: 22.5,
351
- stem: true,
352
- codeFlagUp: Glyphs.flag128thUp,
353
- },
354
- };
355
-
356
- static NOTATION_FONT_SCALE = 39;
357
- static TABLATURE_FONT_SCALE = 39;
358
-
359
- static SLASH_NOTEHEAD_WIDTH = 15;
360
- static STAVE_LINE_DISTANCE = 10;
361
-
362
- // HACK:
363
- // Since text origins are positioned at the baseline, we must
364
- // compensate for the ascender of the text. Of course, 1 staff space is
365
- // a very poor approximation.
366
- //
367
- // This will be deprecated in the future. This is a temporary solution until
368
- // we have more robust text metrics.
369
- static TEXT_HEIGHT_OFFSET_HACK = 1;
370
-
371
- static clefProperties(clef: string): { lineShift: number } {
372
- if (!clef || !(clef in clefs)) throw new RuntimeError('BadArgument', 'Invalid clef: ' + clef);
373
- return clefs[clef];
374
- }
375
-
376
- /**
377
- * @param keyOctaveGlyph a string in the format "key/octave" (e.g., "c/5") or "key/octave/custom-note-head-code" (e.g., "g/5/t3").
378
- * @param clef
379
- * @param params a struct with one option, `octaveShift` for clef ottavation (0 = default; 1 = 8va; -1 = 8vb, etc.).
380
- * @returns properties for the specified note.
381
- */
382
-
383
- static keyProperties(
384
- keyOctaveGlyph: string,
385
- clef: string = 'treble',
386
- type: string = 'N',
387
- params?: { octaveShift?: number }
388
- ): KeyProps {
389
- let options = { octaveShift: 0, duration: '4' };
390
- if (typeof params === 'object') {
391
- options = { ...options, ...params };
392
- }
393
- const duration = Tables.sanitizeDuration(options.duration);
394
-
395
- const pieces = keyOctaveGlyph.split('/');
396
- if (pieces.length < 2) {
397
- throw new RuntimeError(
398
- 'BadArguments',
399
- `First argument must be note/octave or note/octave/glyph-code: ${keyOctaveGlyph}`
400
- );
401
- }
402
-
403
- const key = pieces[0].toUpperCase();
404
- type = type.toUpperCase();
405
- const value = notesInfo[key];
406
- if (!value) throw new RuntimeError('BadArguments', 'Invalid key name: ' + key);
407
- let octave = parseInt(pieces[1], 10);
408
-
409
- // .octaveShift is the shift to compensate for clef 8va/8vb.
410
- octave -= options.octaveShift;
411
-
412
- const baseIndex = octave * 7 - 4 * 7;
413
- let line = (baseIndex + value.index) / 2;
414
- line += Tables.clefProperties(clef).lineShift;
415
-
416
- // Integer value for note arithmetic.
417
- const intValue = typeof value.intVal !== 'undefined' ? octave * 12 + value.intVal : undefined;
418
-
419
- // If the user specified a glyph, overwrite the glyph code.
420
- let code = '';
421
- let glyphName = 'N';
422
- if (pieces.length > 2 && pieces[2]) {
423
- glyphName = pieces[2].toUpperCase();
424
- } else if (type !== 'N') {
425
- glyphName = type;
426
- } else glyphName = key;
427
- code = this.codeNoteHead(glyphName, duration);
428
-
429
- return {
430
- key,
431
- octave,
432
- line,
433
- intValue,
434
- code,
435
- displaced: false,
436
- };
437
- }
438
-
439
- static integerToNote(integer?: number): string {
440
- if (typeof integer === 'undefined' || integer < 0 || integer > 11) {
441
- throw new RuntimeError('BadArguments', `integerToNote() requires an integer in the range [0, 11]: ${integer}`);
442
- }
443
-
444
- const table: Record<number, string> = {
445
- 0: 'C',
446
- 1: 'C#',
447
- 2: 'D',
448
- 3: 'D#',
449
- 4: 'E',
450
- 5: 'F',
451
- 6: 'F#',
452
- 7: 'G',
453
- 8: 'G#',
454
- 9: 'A',
455
- 10: 'A#',
456
- 11: 'B',
457
- };
458
-
459
- const noteValue = table[integer];
460
- if (!noteValue) {
461
- throw new RuntimeError('BadArguments', `Unknown note value for integer: ${integer}`);
462
- }
463
-
464
- return noteValue;
465
- }
466
-
467
- // Used by annotation.ts and bend.ts. Clearly this implementation only works for the default font size.
468
- // TODO: The actual width depends on the font family, size, weight, style.
469
- static textWidth(text: string): number {
470
- return 7 * text.toString().length;
471
- }
472
-
473
- static articulationCodes(artic: string): ArticulationStruct {
474
- return articulations[artic];
475
- }
476
-
477
- static accidentalCodes(accidental: string): string {
478
- return accidentals[accidental] ?? accidental;
479
- }
480
-
481
- static accidentalColumnsTable = accidentalColumns;
482
-
483
- static ornamentCodes(ornament: string): string {
484
- return ornaments[ornament] ?? ornament;
485
- }
486
-
487
- static keySignature(spec: string): { type: string; line: number }[] {
488
- const keySpec = keySignatures[spec];
489
-
490
- if (!keySpec) {
491
- throw new RuntimeError('BadKeySignature', `Bad key signature spec: '${spec}'`);
492
- }
493
-
494
- if (!keySpec.accidental) {
495
- return [];
496
- }
497
-
498
- const accidentalList: Record<string, number[]> = {
499
- b: [2, 0.5, 2.5, 1, 3, 1.5, 3.5],
500
- '#': [0, 1.5, -0.5, 1, 2.5, 0.5, 2],
501
- };
502
-
503
- const notes = accidentalList[keySpec.accidental];
504
-
505
- const accList = [];
506
- for (let i = 0; i < keySpec.num; ++i) {
507
- const line = notes[i];
508
- accList.push({ type: keySpec.accidental, line });
509
- }
510
-
511
- return accList;
512
- }
513
-
514
- static getKeySignatures(): Record<string, { accidental?: string; num: number }> {
515
- return keySignatures;
516
- }
517
-
518
- static hasKeySignature(spec: string): boolean {
519
- return spec in keySignatures;
520
- }
521
-
522
- // TODO: Should these be moved to glyphs.ts? We could have a non-SMuFL section....
523
- static unicode = {
524
- // ♯ accidental sharp
525
- sharp: '\u266f',
526
- // ♭ accidental flat
527
- flat: '\u266d',
528
- // ♮ accidental natural
529
- natural: '\u266e',
530
- // △ major seventh
531
- triangle: '\u25b3',
532
- // ø half-diminished
533
- 'o-with-slash': '\u00f8',
534
- // ° diminished
535
- degrees: '\u00b0',
536
- // ○ diminished
537
- circle: '\u25cb',
538
- };
539
-
540
- /**
541
- * Convert duration aliases to the number based duration.
542
- * If the input isn't an alias, simply return the input.
543
- * @param duration
544
- * @returns Example: 'q' -> '4', '8' -> '8'
545
- */
546
- static sanitizeDuration(duration: string): string {
547
- const durationNumber: string = durationAliases[duration];
548
- if (durationNumber !== undefined) {
549
- duration = durationNumber;
550
- }
551
- if (durations[duration] === undefined) {
552
- throw new RuntimeError('BadArguments', `The provided duration is not valid: ${duration}`);
553
- }
554
- return duration;
555
- }
556
-
557
- /** Convert the `duration` to a fraction. */
558
- static durationToFraction(duration: string): Fraction {
559
- return new Fraction().parse(Tables.sanitizeDuration(duration));
560
- }
561
-
562
- /** Convert the `duration` to a number. */
563
- static durationToNumber(duration: string): number {
564
- return Tables.durationToFraction(duration).value();
565
- }
566
-
567
- /* Convert the `duration` to total ticks. */
568
- static durationToTicks(duration: string): number {
569
- duration = Tables.sanitizeDuration(duration);
570
- const ticks = durations[duration];
571
- if (ticks === undefined) {
572
- throw new RuntimeError('InvalidDuration');
573
- }
574
- return ticks;
575
- }
576
-
577
- static codeNoteHead(type: string, duration: string): string {
578
- switch (type) {
579
- /* Diamond */
580
- case 'D0':
581
- return Glyphs.noteheadDiamondWhole;
582
- case 'D1':
583
- return Glyphs.noteheadDiamondHalf;
584
- case 'D2':
585
- return Glyphs.noteheadDiamondBlack;
586
- case 'D3':
587
- return Glyphs.noteheadDiamondBlack;
588
-
589
- /* Triangle */
590
- case 'T0':
591
- return Glyphs.noteheadTriangleUpWhole;
592
- case 'T1':
593
- return Glyphs.noteheadTriangleUpHalf;
594
- case 'T2':
595
- return Glyphs.noteheadTriangleUpBlack;
596
- case 'T3':
597
- return Glyphs.noteheadTriangleUpBlack;
598
-
599
- /* Cross */
600
- case 'X0':
601
- return Glyphs.noteheadXWhole;
602
- case 'X1':
603
- return Glyphs.noteheadXHalf;
604
- case 'X2':
605
- return Glyphs.noteheadXBlack;
606
- case 'X3':
607
- return Glyphs.noteheadCircleX;
608
-
609
- /* Square */
610
- case 'S1':
611
- return Glyphs.noteheadSquareWhite;
612
- case 'S2':
613
- return Glyphs.noteheadSquareBlack;
614
-
615
- /* Rectangle */
616
- case 'R1':
617
- return Glyphs.noteheadSquareWhite; // no smufl code
618
- case 'R2':
619
- return Glyphs.noteheadSquareWhite; // no smufl code
620
-
621
- case 'DO':
622
- return Glyphs.noteheadTriangleUpBlack;
623
- case 'RE':
624
- return Glyphs.noteheadMoonBlack;
625
- case 'MI':
626
- return Glyphs.noteheadDiamondBlack;
627
- case 'FA':
628
- return Glyphs.noteheadTriangleLeftBlack;
629
- case 'FAUP':
630
- return Glyphs.noteheadTriangleRightBlack;
631
- case 'SO':
632
- return Glyphs.noteheadBlack;
633
- case 'LA':
634
- return Glyphs.noteheadSquareBlack;
635
- case 'TI':
636
- return Glyphs.noteheadTriangleRoundDownBlack;
637
-
638
- case 'DI': // Diamond
639
- case 'H': // Harmonics
640
- switch (duration) {
641
- case '1/2':
642
- return Glyphs.noteheadDiamondDoubleWhole;
643
- case '1':
644
- return Glyphs.noteheadDiamondWhole;
645
- case '2':
646
- return Glyphs.noteheadDiamondHalf;
647
- default:
648
- return Glyphs.noteheadDiamondBlack;
649
- }
650
- case 'X':
651
- case 'M': // Muted
652
- switch (duration) {
653
- case '1/2':
654
- return Glyphs.noteheadXDoubleWhole;
655
- case '1':
656
- return Glyphs.noteheadXWhole;
657
- case '2':
658
- return Glyphs.noteheadXHalf;
659
- default:
660
- return Glyphs.noteheadXBlack;
661
- }
662
- case 'CX':
663
- switch (duration) {
664
- case '1/2':
665
- return Glyphs.noteheadCircleXDoubleWhole;
666
- case '1':
667
- return Glyphs.noteheadCircleXWhole;
668
- case '2':
669
- return Glyphs.noteheadCircleXHalf;
670
- default:
671
- return Glyphs.noteheadCircleX;
672
- }
673
- case 'CI':
674
- switch (duration) {
675
- case '1/2':
676
- return Glyphs.noteheadCircledDoubleWhole;
677
- case '1':
678
- return Glyphs.noteheadCircledWhole;
679
- case '2':
680
- return Glyphs.noteheadCircledHalf;
681
- default:
682
- return Glyphs.noteheadCircledBlack;
683
- }
684
- case 'SQ':
685
- switch (duration) {
686
- case '1/2':
687
- return Glyphs.noteheadDoubleWholeSquare;
688
- case '1':
689
- return Glyphs.noteheadSquareWhite;
690
- case '2':
691
- return Glyphs.noteheadSquareWhite;
692
- default:
693
- return Glyphs.noteheadSquareBlack;
694
- }
695
- case 'TU':
696
- switch (duration) {
697
- case '1/2':
698
- return Glyphs.noteheadTriangleUpDoubleWhole;
699
- case '1':
700
- return Glyphs.noteheadTriangleUpWhole;
701
- case '2':
702
- return Glyphs.noteheadTriangleUpHalf;
703
- default:
704
- return Glyphs.noteheadTriangleUpBlack;
705
- }
706
- case 'TD':
707
- switch (duration) {
708
- case '1/2':
709
- return Glyphs.noteheadTriangleDownDoubleWhole;
710
- case '1':
711
- return Glyphs.noteheadTriangleDownWhole;
712
- case '2':
713
- return Glyphs.noteheadTriangleDownHalf;
714
- default:
715
- return Glyphs.noteheadTriangleDownBlack;
716
- }
717
- case 'SF':
718
- switch (duration) {
719
- case '1/2':
720
- return Glyphs.noteheadSlashedDoubleWhole1;
721
- case '1':
722
- return Glyphs.noteheadSlashedWhole1;
723
- case '2':
724
- return Glyphs.noteheadSlashedHalf1;
725
- default:
726
- return Glyphs.noteheadSlashedBlack1;
727
- }
728
- case 'SB':
729
- switch (duration) {
730
- case '1/2':
731
- return Glyphs.noteheadSlashedDoubleWhole2;
732
- case '1':
733
- return Glyphs.noteheadSlashedWhole2;
734
- case '2':
735
- return Glyphs.noteheadSlashedHalf2;
736
- default:
737
- return Glyphs.noteheadSlashedBlack2;
738
- }
739
- case 'R':
740
- switch (duration) {
741
- case '1/2':
742
- return Glyphs.restDoubleWhole;
743
- case '1':
744
- return Glyphs.restWhole;
745
- case '2':
746
- return Glyphs.restHalf;
747
- case '4':
748
- return Glyphs.restQuarter;
749
- case '8':
750
- return Glyphs.rest8th;
751
- case '16':
752
- return Glyphs.rest16th;
753
- case '32':
754
- return Glyphs.rest32nd;
755
- case '64':
756
- return Glyphs.rest64th;
757
- case '128':
758
- return Glyphs.rest128th;
759
- }
760
- break;
761
- case 'S':
762
- switch (duration) {
763
- case '1/2':
764
- return Glyphs.noteheadSlashWhiteDoubleWhole;
765
- case '1':
766
- return Glyphs.noteheadSlashWhiteWhole;
767
- case '2':
768
- return Glyphs.noteheadSlashWhiteHalf;
769
- default:
770
- return Glyphs.noteheadSlashVerticalEnds;
771
- }
772
- default:
773
- switch (duration) {
774
- case '1/2':
775
- return Glyphs.noteheadDoubleWhole;
776
- case '1':
777
- return Glyphs.noteheadWhole;
778
- case '2':
779
- return Glyphs.noteheadHalf;
780
- default:
781
- return Glyphs.noteheadBlack;
782
- }
783
- }
784
- return Glyphs.null;
785
- }
786
-
787
- /* The list of valid note types. Used by note.ts during parseNoteStruct(). */
788
- static validTypes = validNoteTypes;
789
-
790
- // Default time signature.
791
- static TIME4_4 = {
792
- numBeats: 4,
793
- beatValue: 4,
794
- resolution: RESOLUTION,
795
- };
796
- }