vexflow 5.2.0 → 5.3.0

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 (114) 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 +2759 -1382
  6. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  7. package/build/cjs/vexflow-debug.js +1814 -1227
  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 +10 -3
  12. package/build/esm/src/articulation.js +24 -6
  13. package/build/esm/src/beam.js +158 -28
  14. package/build/esm/src/bend.js +24 -19
  15. package/build/esm/src/curve.js +27 -53
  16. package/build/esm/src/dot.js +13 -4
  17. package/build/esm/src/easyscore/composition.js +40 -1
  18. package/build/esm/src/easyscore/policies.js +34 -6
  19. package/build/esm/src/element.js +4 -0
  20. package/build/esm/src/engravinggeometry.js +150 -0
  21. package/build/esm/src/engravingprofile.js +44 -0
  22. package/build/esm/src/factory.js +15 -7
  23. package/build/esm/src/formatter.js +9 -1
  24. package/build/esm/src/gracenote.js +43 -38
  25. package/build/esm/src/gracenotegroup.js +53 -56
  26. package/build/esm/src/index.js +2 -0
  27. package/build/esm/src/keysignature.js +1 -1
  28. package/build/esm/src/modifiercontext.js +11 -0
  29. package/build/esm/src/notehead.js +11 -6
  30. package/build/esm/src/ornament.js +38 -18
  31. package/build/esm/src/proportionalformatter.js +54 -6
  32. package/build/esm/src/stavenote.js +128 -115
  33. package/build/esm/src/stavetie.js +39 -7
  34. package/build/esm/src/stem.js +26 -11
  35. package/build/esm/src/tickcontext.js +19 -0
  36. package/build/esm/src/timesignature.js +5 -0
  37. package/build/esm/src/tuplet.js +57 -17
  38. package/build/esm/src/version.js +3 -3
  39. package/build/esm/src/vexflow.js +4 -0
  40. package/build/esm/tests/bend_tests.js +14 -1
  41. package/build/esm/tests/curve_tests.js +14 -4
  42. package/build/esm/tests/demo_repertoire_tests.js +27 -0
  43. package/build/esm/tests/demos/drums.js +54 -0
  44. package/build/esm/tests/demos/electric.js +63 -0
  45. package/build/esm/tests/demos/greensleeves.js +90 -0
  46. package/build/esm/tests/demos/joy.js +61 -0
  47. package/build/esm/tests/demos/kesh.js +80 -0
  48. package/build/esm/tests/demos/prelude.js +59 -0
  49. package/build/esm/tests/demos/quartertones.js +50 -0
  50. package/build/esm/tests/demos/saints.js +65 -0
  51. package/build/esm/tests/engraving/score-layout.mjs +75 -0
  52. package/build/esm/tests/engraving/score-persistence.mjs +262 -0
  53. package/build/esm/tests/engraving/studies.mjs +279 -0
  54. package/build/esm/tests/formatter_tests.js +10 -1
  55. package/build/esm/tests/index.js +1 -0
  56. package/build/esm/tests/node/audit-dependencies-tests.mjs +42 -0
  57. package/build/esm/tests/node/easyscore-tests.mjs +71 -0
  58. package/build/esm/tests/node/engraving-layout-tests.mjs +449 -0
  59. package/build/esm/tests/node/local-engraving-tests.mjs +128 -0
  60. package/build/esm/tests/node/proportional-spacing-tests.mjs +64 -0
  61. package/build/esm/tests/node/rendering-tests.mjs +6 -2
  62. package/build/esm/tests/threevoice_tests.js +11 -1
  63. package/build/esm/tests/vexflow_test_helpers.js +19 -10
  64. package/build/esm/tools/audit-dependencies.mjs +61 -0
  65. package/build/esm/tools/score-fixtures.mjs +23 -6
  66. package/build/types/src/accidental.d.ts +4 -0
  67. package/build/types/src/articulation.d.ts +6 -1
  68. package/build/types/src/beam.d.ts +14 -0
  69. package/build/types/src/curve.d.ts +9 -0
  70. package/build/types/src/dot.d.ts +5 -0
  71. package/build/types/src/easyscore/composition.d.ts +19 -0
  72. package/build/types/src/easyscore/policies.d.ts +1 -1
  73. package/build/types/src/element.d.ts +2 -0
  74. package/build/types/src/engravinggeometry.d.ts +31 -0
  75. package/build/types/src/engravingprofile.d.ts +20 -0
  76. package/build/types/src/factory.d.ts +6 -1
  77. package/build/types/src/formatter.d.ts +3 -3
  78. package/build/types/src/gracenote.d.ts +7 -0
  79. package/build/types/src/gracenotegroup.d.ts +7 -2
  80. package/build/types/src/index.d.ts +2 -0
  81. package/build/types/src/modifiercontext.d.ts +4 -0
  82. package/build/types/src/notehead.d.ts +5 -0
  83. package/build/types/src/ornament.d.ts +7 -0
  84. package/build/types/src/proportionalformatter.d.ts +11 -2
  85. package/build/types/src/stavenote.d.ts +20 -2
  86. package/build/types/src/stavetie.d.ts +4 -0
  87. package/build/types/src/stem.d.ts +10 -1
  88. package/build/types/src/tickcontext.d.ts +5 -0
  89. package/build/types/src/timesignature.d.ts +2 -0
  90. package/build/types/src/tuplet.d.ts +5 -48
  91. package/build/types/src/vexflow.d.ts +4 -0
  92. package/changelog/CHANGELOG.md +17 -0
  93. package/package.json +7 -2
  94. package/tests/all.html +277 -0
  95. package/tests/demo_petzold_tests.ts +435 -0
  96. package/tests/demos/drums.ts +55 -0
  97. package/tests/demos/drums.webp +0 -0
  98. package/tests/demos/electric.ts +70 -0
  99. package/tests/demos/electric.webp +0 -0
  100. package/tests/demos/greensleeves.ts +97 -0
  101. package/tests/demos/greensleeves.webp +0 -0
  102. package/tests/demos/joy.ts +65 -0
  103. package/tests/demos/joy.webp +0 -0
  104. package/tests/demos/kesh.ts +86 -0
  105. package/tests/demos/kesh.webp +0 -0
  106. package/tests/demos/prelude.ts +65 -0
  107. package/tests/demos/prelude.webp +0 -0
  108. package/tests/demos/quartertones.ts +51 -0
  109. package/tests/demos/quartertones.webp +0 -0
  110. package/tests/demos/saints.ts +70 -0
  111. package/tests/demos/saints.webp +0 -0
  112. package/tests/flow.html +550 -239
  113. package/tests/fonts.css +493 -0
  114. package/tests/minuet.webp +0 -0
@@ -0,0 +1,435 @@
1
+ // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
+ // MIT License
3
+ //
4
+ // Demo - Petzold
5
+
6
+ import { concat, TestOptions, VexFlowTests } from './vexflow_test_helpers';
7
+
8
+ import { BarlineType, Factory, Registry, StaveNote } from '../src/index';
9
+
10
+ const DemoPetzoldTests = {
11
+ Start(): void {
12
+ QUnit.module('Demo - Petzold');
13
+ VexFlowTests.runTests('Minuet in G', minuetInG);
14
+ },
15
+ };
16
+
17
+ function minuetInG(options: TestOptions): void {
18
+ const registry = new Registry();
19
+ Registry.enableDefaultRegistry(registry);
20
+
21
+ // Retrieve the element from the registry and cast to StaveNote, so we can call .addModifier( ) later.
22
+ const id = (id: string) => registry.getElementById(id) as StaveNote;
23
+
24
+ const f: Factory = VexFlowTests.makeFactory(options, 1100, 900);
25
+ const score = f.EasyScore({ throwOnError: true });
26
+
27
+ // Bind these three functions so the code looks cleaner.
28
+ // Instead of score.voice(...), just call voice(...).
29
+ const voice = score.voice.bind(score);
30
+ const notes = score.notes.bind(score);
31
+ const beam = score.beam.bind(score);
32
+
33
+ let x = 120;
34
+ let y = 80;
35
+
36
+ function appendSystem(width: number) {
37
+ const system = f.System({ x, y, width, spaceBetweenStaves: 10 });
38
+ x += width;
39
+ return system;
40
+ }
41
+
42
+ score.set({ time: '3/4' });
43
+
44
+ /* Measure 1 */
45
+ let system = appendSystem(220);
46
+ system
47
+ .addStave({
48
+ voices: [
49
+ voice([notes('D5/q[id="m1a"]'), beam(notes('G4/8, A4, B4, C5', { stem: 'up' }))].reduce(concat)),
50
+ voice([f.TextDynamics({ text: 'p', duration: 'h', dots: 1, line: 9 })]),
51
+ ],
52
+ })
53
+ .addClef('treble')
54
+ .addKeySignature('G')
55
+ .addTimeSignature('3/4')
56
+ .setTempo({ name: 'Allegretto', duration: 'h', dots: 1, bpm: 66 }, -30);
57
+
58
+ system
59
+ .addStave({ voices: [voice(notes('(G3 B3 D4)/h, A3/q', { clef: 'bass' }))] })
60
+ .addClef('bass')
61
+ .addKeySignature('G')
62
+ .addTimeSignature('3/4');
63
+ system.addConnector('brace');
64
+ system.addConnector('singleRight');
65
+ system.addConnector('singleLeft');
66
+
67
+ id('m1a').addModifier(f.Fingering({ number: '5' }), 0);
68
+
69
+ /* Measure 2 */
70
+ system = appendSystem(150);
71
+ system.addStave({ voices: [voice(notes('D5/q[id="m2a"], G4[id="m2b"], G4[id="m2c"]'))] });
72
+ system.addStave({ voices: [voice(notes('B3/h.', { clef: 'bass' }))] });
73
+ system.addConnector('singleRight');
74
+
75
+ id('m2a').addModifier(f.Articulation({ type: 'a.', position: 'above' }), 0);
76
+ id('m2b').addModifier(f.Articulation({ type: 'a.', position: 'below' }), 0);
77
+ id('m2c').addModifier(f.Articulation({ type: 'a.', position: 'below' }), 0);
78
+
79
+ f.Curve({
80
+ from: id('m1a'),
81
+ to: id('m2a'),
82
+ options: {
83
+ cps: [
84
+ { x: 0, y: 40 },
85
+ { x: 0, y: 40 },
86
+ ],
87
+ },
88
+ });
89
+
90
+ /* Measure 3 */
91
+ system = appendSystem(150);
92
+ system.addStave({
93
+ voices: [voice([notes('E5/q[id="m3a"]'), beam(notes('C5/8, D5, E5, F5', { stem: 'down' }))].reduce(concat))],
94
+ });
95
+ id('m3a').addModifier(f.Fingering({ number: '3', position: 'above' }), 0);
96
+
97
+ system.addStave({ voices: [voice(notes('C4/h.', { clef: 'bass' }))] });
98
+ system.addConnector('singleRight');
99
+
100
+ /* Measure 4 */
101
+ system = appendSystem(150);
102
+ system.addStave({ voices: [voice(notes('G5/q[id="m4a"], G4[id="m4b"], G4[id="m4c"]'))] });
103
+
104
+ system.addStave({ voices: [voice(notes('B3/h.', { clef: 'bass' }))] });
105
+ system.addConnector('singleRight');
106
+
107
+ id('m4a').addModifier(f.Articulation({ type: 'a.', position: 'above' }), 0);
108
+ id('m4b').addModifier(f.Articulation({ type: 'a.', position: 'below' }), 0);
109
+ id('m4c').addModifier(f.Articulation({ type: 'a.', position: 'below' }), 0);
110
+
111
+ f.Curve({
112
+ from: id('m3a'),
113
+ to: id('m4a'),
114
+ options: {
115
+ cps: [
116
+ { x: 0, y: 20 },
117
+ { x: 0, y: 20 },
118
+ ],
119
+ },
120
+ });
121
+
122
+ /* Measure 5 */
123
+ system = appendSystem(150);
124
+ system.addStave({
125
+ voices: [voice([notes('C5/q[id="m5a"]'), beam(notes('D5/8, C5, B4, A4', { stem: 'down' }))].reduce(concat))],
126
+ });
127
+ id('m5a').addModifier(f.Fingering({ number: '4', position: 'above' }), 0);
128
+
129
+ system.addStave({ voices: [voice(notes('A3/h.', { clef: 'bass' }))] });
130
+ system.addConnector('singleRight');
131
+
132
+ /* Measure 6 */
133
+ system = appendSystem(150);
134
+ system.addStave({
135
+ voices: [voice([notes('B4/q'), beam(notes('C5/8, B4, A4, G4[id="m6a"]', { stem: 'up' }))].reduce(concat))],
136
+ });
137
+
138
+ system.addStave({ voices: [voice(notes('G3/h.', { clef: 'bass' }))] });
139
+ system.addConnector('singleRight');
140
+
141
+ f.Curve({
142
+ from: id('m5a'),
143
+ to: id('m6a'),
144
+ options: {
145
+ cps: [
146
+ { x: 0, y: 20 },
147
+ { x: 0, y: 20 },
148
+ ],
149
+ invert: true,
150
+ positionEnd: 'nearTop',
151
+ yShift: 20,
152
+ },
153
+ });
154
+
155
+ /* Measure 7 (New system) */
156
+ x = 20;
157
+ y += 230;
158
+
159
+ system = appendSystem(220);
160
+ system
161
+ .addStave({
162
+ voices: [
163
+ voice([notes('F4/q[id="m7a"]'), beam(notes('G4/8[id="m7b"], A4, B4, G4', { stem: 'up' }))].reduce(concat)),
164
+ ],
165
+ })
166
+ .addClef('treble')
167
+ .addKeySignature('G');
168
+
169
+ system
170
+ .addStave({ voices: [voice(notes('D4/q, B3[id="m7c"], G3', { clef: 'bass' }))] })
171
+ .addClef('bass')
172
+ .addKeySignature('G');
173
+ system.addConnector('brace');
174
+ system.addConnector('singleRight');
175
+ system.addConnector('singleLeft');
176
+
177
+ id('m7a').addModifier(f.Fingering({ number: '2', position: 'below' }), 0);
178
+ id('m7b').addModifier(f.Fingering({ number: '1' }), 0);
179
+ id('m7c').addModifier(f.Fingering({ number: '3', position: 'above' }), 0);
180
+
181
+ /* Measure 8 */
182
+ system = appendSystem(180);
183
+ const grace = f.GraceNote({ keys: ['d/3'], clef: 'bass', duration: '4', slash: false });
184
+
185
+ system.addStave({ voices: [voice(notes('A4/h.[id="m8c"]'))] });
186
+ system.addStave({
187
+ voices: [
188
+ score
189
+ .set({ clef: 'bass' })
190
+ .voice([notes('D4/q[id="m8a"]'), beam(notes('D3/8, C4, B3[id="m8b"], A3', { stem: 'down' }))].reduce(concat)),
191
+ ],
192
+ });
193
+ system.addConnector('singleRight');
194
+
195
+ id('m8b').addModifier(f.Fingering({ number: '1', position: 'above' }), 0);
196
+ id('m8c').addModifier(f.GraceNoteGroup({ notes: [grace] }), 0);
197
+
198
+ f.Curve({
199
+ from: id('m7a'),
200
+ to: id('m8c'),
201
+ options: {
202
+ cps: [
203
+ { x: 0, y: 20 },
204
+ { x: 0, y: 20 },
205
+ ],
206
+ invert: true,
207
+ position: 'nearTop',
208
+ positionEnd: 'nearTop',
209
+ },
210
+ });
211
+
212
+ f.StaveTie({ from: grace, to: id('m8c') });
213
+
214
+ /* Measure 9 */
215
+ system = appendSystem(180);
216
+ system.addStave({
217
+ voices: [
218
+ score
219
+ .set({ clef: 'treble' })
220
+ .voice([notes('D5/q[id="m9a"]'), beam(notes('G4/8, A4, B4, C5', { stem: 'up' }))].reduce(concat)),
221
+ ],
222
+ });
223
+
224
+ system.addStave({ voices: [voice(notes('B3/h, A3/q', { clef: 'bass' }))] });
225
+ system.addConnector('singleRight');
226
+
227
+ id('m9a').addModifier(f.Fingering({ number: '5' }), 0);
228
+
229
+ /* Measure 10 */
230
+ system = appendSystem(170);
231
+ system.addStave({ voices: [voice(notes('D5/q[id="m10a"], G4[id="m10b"], G4[id="m10c"]'))] });
232
+ system.addStave({ voices: [voice(notes('G3/q[id="m10d"], B3, G3', { clef: 'bass' }))] });
233
+ system.addConnector('singleRight');
234
+
235
+ id('m10a').addModifier(f.Articulation({ type: 'a.', position: 'above' }), 0);
236
+ id('m10b').addModifier(f.Articulation({ type: 'a.', position: 'below' }), 0);
237
+ id('m10c').addModifier(f.Articulation({ type: 'a.', position: 'below' }), 0);
238
+ id('m10d').addModifier(f.Fingering({ number: '4' }), 0);
239
+
240
+ f.Curve({
241
+ from: id('m9a'),
242
+ to: id('m10a'),
243
+ options: {
244
+ cps: [
245
+ { x: 0, y: 40 },
246
+ { x: 0, y: 40 },
247
+ ],
248
+ },
249
+ });
250
+
251
+ /* Measure 11 */
252
+ system = appendSystem(150);
253
+ system.addStave({
254
+ voices: [voice([notes('E5/q[id="m11a"]'), beam(notes('C5/8, D5, E5, F5', { stem: 'down' }))].reduce(concat))],
255
+ });
256
+ id('m11a').addModifier(f.Fingering({ number: '3', position: 'above' }), 0);
257
+
258
+ system.addStave({ voices: [voice(notes('C4/h.', { clef: 'bass' }))] });
259
+ system.addConnector('singleRight');
260
+
261
+ /* Measure 12 */
262
+ system = appendSystem(170);
263
+ system.addStave({ voices: [voice(notes('G5/q[id="m12a"], G4[id="m12b"], G4[id="m12c"]'))] });
264
+
265
+ system.addStave({
266
+ voices: [
267
+ score
268
+ .set({ clef: 'bass' })
269
+ .voice([notes('B3/q[id="m12d"]'), beam(notes('C4/8, B3, A3, G3[id="m12e"]', { stem: 'down' }))].reduce(concat)),
270
+ ],
271
+ });
272
+ system.addConnector('singleRight');
273
+
274
+ id('m12a').addModifier(f.Articulation({ type: 'a.', position: 'above' }), 0);
275
+ id('m12b').addModifier(f.Articulation({ type: 'a.', position: 'below' }), 0);
276
+ id('m12c').addModifier(f.Articulation({ type: 'a.', position: 'below' }), 0);
277
+
278
+ id('m12d').addModifier(f.Fingering({ number: '2', position: 'above' }), 0);
279
+ id('m12e').addModifier(f.Fingering({ number: '4', position: 'above' }), 0);
280
+
281
+ f.Curve({
282
+ from: id('m11a'),
283
+ to: id('m12a'),
284
+ options: {
285
+ cps: [
286
+ { x: 0, y: 20 },
287
+ { x: 0, y: 20 },
288
+ ],
289
+ },
290
+ });
291
+
292
+ /* Measure 13 (New system) */
293
+ x = 20;
294
+ y += 230;
295
+
296
+ system = appendSystem(220);
297
+ system
298
+ .addStave({
299
+ voices: [
300
+ score
301
+ .set({ clef: 'treble' })
302
+ .voice([notes('c5/q[id="m13a"]'), beam(notes('d5/8, c5, b4, a4', { stem: 'down' }))].reduce(concat)),
303
+ ],
304
+ })
305
+ .addClef('treble')
306
+ .addKeySignature('G');
307
+
308
+ system
309
+ .addStave({ voices: [voice(notes('a3/h[id="m13b"], f3/q[id="m13c"]', { clef: 'bass' }))] })
310
+ .addClef('bass')
311
+ .addKeySignature('G');
312
+
313
+ system.addConnector('brace');
314
+ system.addConnector('singleRight');
315
+ system.addConnector('singleLeft');
316
+
317
+ id('m13a').addModifier(f.Fingering({ number: '4', position: 'above' }), 0);
318
+ id('m13b').addModifier(f.Fingering({ number: '1' }), 0);
319
+ id('m13c').addModifier(f.Fingering({ number: '3', position: 'above' }), 0);
320
+
321
+ /* Measure 14 */
322
+ system = appendSystem(180);
323
+ system.addStave({
324
+ voices: [
325
+ score
326
+ .set({ clef: 'treble' })
327
+ .voice([notes('B4/q'), beam(notes('C5/8, b4, a4, g4', { stem: 'up' }))].reduce(concat)),
328
+ ],
329
+ });
330
+
331
+ system.addStave({ voices: [voice(notes('g3/h[id="m14a"], b3/q[id="m14b"]', { clef: 'bass' }))] });
332
+ system.addConnector('singleRight');
333
+
334
+ id('m14a').addModifier(f.Fingering({ number: '2' }), 0);
335
+ id('m14b').addModifier(f.Fingering({ number: '1' }), 0);
336
+
337
+ /* Measure 15 */
338
+ system = appendSystem(180);
339
+ system.addStave({
340
+ voices: [
341
+ score
342
+ .set({ clef: 'treble' })
343
+ .voice([notes('a4/q'), beam(notes('b4/8, a4, g4, f4[id="m15a"]', { stem: 'up' }))].reduce(concat)),
344
+ ],
345
+ });
346
+
347
+ system.addStave({ voices: [voice(notes('c4/q[id="m15b"], d4, d3', { clef: 'bass' }))] });
348
+ system.addConnector('singleRight');
349
+
350
+ id('m15a').addModifier(f.Fingering({ number: '2' }), 0);
351
+ id('m15b').addModifier(f.Fingering({ number: '2' }), 0);
352
+
353
+ /* Measure 16 */
354
+ system = appendSystem(130);
355
+ system
356
+ .addStave({
357
+ voices: [score.set({ clef: 'treble' }).voice([notes('g4/h.[id="m16a"]')].reduce(concat))],
358
+ })
359
+ .setEndBarType(BarlineType.REPEAT_END);
360
+
361
+ system
362
+ .addStave({ voices: [voice(notes('g3/h[id="m16b"], g2/q', { clef: 'bass' }))] })
363
+ .setEndBarType(BarlineType.REPEAT_END);
364
+ system.addConnector('boldDoubleRight');
365
+
366
+ id('m16a').addModifier(f.Fingering({ number: '1' }), 0);
367
+ id('m16b').addModifier(f.Fingering({ number: '1' }), 0);
368
+
369
+ f.Curve({
370
+ from: id('m13a'),
371
+ to: id('m16a'),
372
+ options: {
373
+ cps: [
374
+ { x: 0, y: 50 },
375
+ { x: 0, y: 20 },
376
+ ],
377
+ invert: true,
378
+ positionEnd: 'nearTop',
379
+ },
380
+ });
381
+
382
+ /* Measure 17 */
383
+ system = appendSystem(180);
384
+ system
385
+ .addStave({
386
+ voices: [
387
+ score
388
+ .set({ clef: 'treble' })
389
+ .voice([notes('b5/q[id="m17a"]'), beam(notes('g5/8, a5, b5, g5', { stem: 'down' }))].reduce(concat)),
390
+ voice([f.TextDynamics({ text: 'mf', duration: 'h', dots: 1, line: 10 })]),
391
+ ],
392
+ })
393
+ .setBegBarType(BarlineType.REPEAT_BEGIN);
394
+
395
+ system.addStave({ voices: [voice(notes('g3/h.', { clef: 'bass' }))] }).setBegBarType(BarlineType.REPEAT_BEGIN);
396
+
397
+ system.addConnector('boldDoubleLeft');
398
+ system.addConnector('singleRight');
399
+
400
+ id('m17a').addModifier(f.Fingering({ number: '5', position: 'above' }), 0);
401
+
402
+ /* Measure 18 */
403
+ system = appendSystem(180);
404
+ system.addStave({
405
+ voices: [
406
+ score
407
+ .set({ clef: 'treble' })
408
+ .voice([notes('a5/q[id="m18a"]'), beam(notes('d5/8, e5, f5, d5[id="m18b"]', { stem: 'down' }))].reduce(concat)),
409
+ ],
410
+ });
411
+
412
+ system.addStave({ voices: [voice(notes('f3/h.', { clef: 'bass' }))] });
413
+ system.addConnector('singleRight');
414
+
415
+ id('m18a').addModifier(f.Fingering({ number: '4', position: 'above' }), 0);
416
+
417
+ f.Curve({
418
+ from: id('m17a'),
419
+ to: id('m18b'),
420
+ options: {
421
+ cps: [
422
+ { x: 0, y: 20 },
423
+ { x: 0, y: 30 },
424
+ ],
425
+ },
426
+ });
427
+
428
+ /* Done */
429
+ f.draw();
430
+ Registry.disableDefaultRegistry();
431
+ options.assert.ok(true, 'Petzold Minuet in G');
432
+ }
433
+
434
+ VexFlowTests.register(DemoPetzoldTests);
435
+ export { DemoPetzoldTests };
@@ -0,0 +1,55 @@
1
+ // Pocket Change is an original drum-set groove with a two-beat triplet fill.
2
+ import { TestOptions, VexFlowTests } from '../vexflow_test_helpers';
3
+
4
+ import { BarlineType, Modifier, Stem } from '../../src/index';
5
+
6
+ /** The hands share an up-stem voice. The kick keeps its own down-stem rhythm beneath them. */
7
+ export function drums(options: TestOptions): void {
8
+ const f = VexFlowTests.makeFactory(options, 900, 350);
9
+ const score = f.EasyScore({ throwOnError: true });
10
+ const hat = 'g/5/x2';
11
+ const snare = 'c/5';
12
+ const hand = (...keys: string[]) => score.make.note({ keys, duration: '8', stemDirection: Stem.UP });
13
+ const kicks = [
14
+ 'F4/q, D4/q/r, F4/8, F4, D4/q/r',
15
+ 'F4/q., F4/8, F4/q, D4/q/r',
16
+ 'F4/q, D4/q/r, F4/8, F4, D4/q/r',
17
+ 'F4/q, D4/q/r, F4/q, F4',
18
+ ];
19
+ kicks.forEach((kick, i) => {
20
+ const fill = i === 3;
21
+ const hands = [hand(hat), hand(hat), hand(snare, hat), hand(hat)];
22
+ hands[2].addModifier(score.make.articulation({ type: 'accent', position: 'above' }));
23
+ score.beam(hands.slice());
24
+ if (fill) {
25
+ // Three strokes per quarter, descending from snare through the rack and floor toms.
26
+ for (const run of [
27
+ [snare, snare, 'e/5'],
28
+ ['d/5', 'a/4', 'a/4'],
29
+ ]) {
30
+ const triplet = run.map((drum) => hand(drum));
31
+ score.beam(triplet);
32
+ score.make.tuplet({ notes: triplet, options: { numNotes: 3, notesOccupied: 2 } });
33
+ hands.push(...triplet);
34
+ }
35
+ } else {
36
+ const answer = [hand(hat), hand(snare, hat), hand(snare, hat), hand(hat)];
37
+ // Parenthesize only the quiet snare head. The hi-hat still plays its ordinary eighth.
38
+ answer[1].addModifier(score.make.parenthesis(Modifier.Position.LEFT), 0);
39
+ answer[1].addModifier(score.make.parenthesis(Modifier.Position.RIGHT), 0);
40
+ answer[2].addModifier(score.make.articulation({ type: 'accent', position: 'above' }));
41
+ score.beam(answer);
42
+ hands.push(...answer);
43
+ }
44
+ const feet = score.notes(kick, { stem: 'down' });
45
+ if (i === 0 || i === 2) score.beam(feet.slice(2, 4));
46
+ const stave = f
47
+ .System({ x: 16 + (i % 2) * 432, y: 56 + Math.floor(i / 2) * 148, width: 432 })
48
+ .addStave({ voices: [score.voice(hands), score.voice(feet)] });
49
+ if (i % 2 === 0) stave.addClef('percussion');
50
+ if (i === 0) stave.addTimeSignature('4/4').setTempo({ name: 'In the pocket', duration: 'q', bpm: 92 }, -43);
51
+ if (fill) stave.setEndBarType(BarlineType.REPEAT_END);
52
+ });
53
+ f.draw();
54
+ options.assert.ok(true, 'Independent kick and hands finish together after the triplet fill');
55
+ }
Binary file
@@ -0,0 +1,70 @@
1
+ // High Wire is an original four-bar electric guitar étude in A minor pentatonic.
2
+ import { TestOptions, VexFlowTests } from '../vexflow_test_helpers';
3
+
4
+ import { BarlineType, Bend, Stem } from '../../src/index';
5
+
6
+ /** Keep the rhythmic stems below the tab so bends, legato marks and vibrato read above it. */
7
+ export function electric(options: TestOptions): void {
8
+ const f = VexFlowTests.makeFactory(options, 900, 380);
9
+ const score = f.EasyScore({ throwOnError: true });
10
+ const makeNote = (duration: string, ...frets: [number, number][]) =>
11
+ score.make.tabNote(
12
+ { duration, stemDirection: Stem.DOWN, positions: frets.map(([str, fret]) => ({ str, fret })) },
13
+ true
14
+ );
15
+ // A5 power chord, then a single-string call. The second bar answers with a bend up to E.
16
+ const bars = [
17
+ [
18
+ makeNote('q', [6, 5], [5, 7], [4, 7]),
19
+ makeNote('8', [3, 5]),
20
+ makeNote('8', [3, 7]),
21
+ makeNote('q', [2, 5]),
22
+ makeNote('q', [2, 8]),
23
+ ],
24
+ [makeNote('h', [3, 7]), makeNote('8', [3, 5]), makeNote('8', [3, 7]), makeNote('q', [4, 7])],
25
+ [5, 8, 12, 8, 5, 8, 12, 8].map((fret) => makeNote('8', [1, fret])),
26
+ [makeNote('q', [1, 5]), makeNote('8', [2, 8]), makeNote('8', [2, 5]), makeNote('h', [4, 7], [3, 9], [2, 10])],
27
+ ];
28
+ bars.forEach((notes, i) => {
29
+ const x = 16 + (i % 2) * 432;
30
+ const y = 35 + Math.floor(i / 2) * 176;
31
+ const stave = score.make.tabStave({ x, y, width: 432 });
32
+ if (i % 2 === 0) stave.addClef('tab');
33
+ if (i === 0) stave.addTimeSignature('4/4').setTempo({ duration: 'q', bpm: 96 }, -8);
34
+ if (i === 3) stave.setEndBarType(BarlineType.END);
35
+ const legato = (start: number, label: string) =>
36
+ score.make
37
+ .tabTie({ firstNote: notes[start], lastNote: notes[start + 1] }, label)
38
+ .setFont('Arial, Helvetica, sans-serif', 9, 'bold');
39
+ if (i === 0) {
40
+ score.beam(notes.slice(1, 3));
41
+ legato(1, 'H');
42
+ notes[4].addModifier(score.make.vibrato().setVibratoWidth(30));
43
+ } else if (i === 1) {
44
+ notes[0].addModifier(
45
+ score.make.bend([
46
+ { type: Bend.UP, text: 'Full' },
47
+ { type: Bend.DOWN, text: '' },
48
+ ])
49
+ );
50
+ score.beam(notes.slice(1, 3));
51
+ score.make.tabSlide({ firstNote: notes[1], lastNote: notes[2] });
52
+ } else if (i === 2) {
53
+ // Fret 12 is tapped by the picking hand. Pull off to 8, then to the held fret 5.
54
+ score.beam(notes.slice(0, 4));
55
+ score.beam(notes.slice(4));
56
+ for (const start of [0, 4]) {
57
+ legato(start, 'H');
58
+ legato(start + 1, 'T');
59
+ legato(start + 2, 'P');
60
+ }
61
+ legato(3, 'P');
62
+ } else {
63
+ score.beam(notes.slice(1, 3));
64
+ legato(1, 'P');
65
+ }
66
+ f.System({ x, y, width: 432 }).addStave({ stave, voices: [score.voice(notes)] });
67
+ });
68
+ f.draw();
69
+ options.assert.ok(true, 'Four bars of rhythmic tab with native guitar techniques');
70
+ }
Binary file
@@ -0,0 +1,97 @@
1
+ // The opening of Greensleeves in standard guitar tuning. Both staves share each pitch and duration.
2
+ import { TestOptions, VexFlowTests } from '../vexflow_test_helpers';
3
+
4
+ import { BarlineType, Stroke } from '../../src/index';
5
+
6
+ /** Written guitar pitches sound an octave lower. Each pair is [string, fret], counting from high E. */
7
+ const positions: Record<string, [number, number]> = {
8
+ E3: [6, 0],
9
+ F3: [6, 1],
10
+ G3: [6, 3],
11
+ A3: [5, 0],
12
+ B3: [5, 2],
13
+ C4: [5, 3],
14
+ D4: [4, 0],
15
+ E4: [4, 2],
16
+ F4: [4, 3],
17
+ G4: [3, 0],
18
+ 'G#4': [3, 1],
19
+ A4: [3, 2],
20
+ B4: [2, 0],
21
+ C5: [2, 1],
22
+ D5: [2, 3],
23
+ E5: [1, 0],
24
+ F5: [1, 1],
25
+ };
26
+
27
+ /** Pair the melody with first-position chord voicings under the same rhythmic columns. */
28
+ export function greensleeves(options: TestOptions): void {
29
+ const f = VexFlowTests.makeFactory(options, 900, 486);
30
+ const score = f.EasyScore({ throwOnError: true });
31
+ // Upright sans-serif chord names sit above the melody, including the slash bass in Dm/F.
32
+ const chordFont = { fontFamily: 'Arial, Helvetica, sans-serif', fontSize: 12 };
33
+ const bars = [
34
+ ['', 'A4/q'],
35
+ ['Am', 'A3+E4+A4+C5/h D5/q'],
36
+ ['C', 'C4+G4+C5+E5/q. F5/8 E5/q'],
37
+ ['G', 'G3+D4+G4+D5/h B4/q'],
38
+ ['Em', 'E3+B3+G4/q. A4/8 B4/q'],
39
+ ['Am', 'A3+E4+A4+C5/h A4/q'],
40
+ ['Dm/F', 'F3+D4+A4/q. G#4/8 A4/q'],
41
+ ['E', 'E3+E4+B4/h G#4/q'],
42
+ ['E5', 'E3+B3+E4/h'],
43
+ ];
44
+ bars.forEach(([chordName, bar], i) => {
45
+ const row = i >= 5 ? 1 : 0;
46
+ const width = row ? 218 : i === 0 ? 112 : 190;
47
+ const x = row ? 12 + (i - 5) * width : i === 0 ? 12 : 124 + (i - 1) * width;
48
+ const y = 28 + row * 230;
49
+ // Read each voicing low to high so chord indexes agree on the staff and tab.
50
+ const events = bar.split(' ').map((token) => {
51
+ const [chord, duration] = token.split('/');
52
+ return { pitches: chord.split('+'), duration };
53
+ });
54
+ const music = events.map(({ pitches, duration }) => {
55
+ const chord = pitches.length === 1 ? pitches[0] : `(${pitches.join(' ')})`;
56
+ return `${chord}/${duration}`;
57
+ });
58
+ const notes = score.notes(music.join(', '));
59
+ if (chordName) notes[0].addModifier(score.make.chordSymbol(chordFont).addText(chordName));
60
+ const tab = events.map(({ pitches, duration }) =>
61
+ score.make.tabNote({
62
+ positions: pitches.map((pitch) => {
63
+ const [str, fret] = positions[pitch];
64
+ return { str, fret };
65
+ }),
66
+ duration: duration.replace('.', ''),
67
+ dots: duration.includes('.') ? 1 : 0,
68
+ })
69
+ );
70
+ if (i === 1 || i === 5) {
71
+ notes[0].addModifier(score.make.fingering({ number: '1', position: 'left' }), 3);
72
+ notes[0].addModifier(score.make.fingering({ number: '2', position: 'left' }), 1);
73
+ }
74
+ if (i === 2 || i === 8) notes[0].addModifier(score.make.stroke(Stroke.Type.ARPEGGIO_DIRECTIONLESS));
75
+ if (i === 2 || i === 6) score.make.curve({ from: notes[1], to: notes[2] });
76
+ // The opening pickup and the shortened closing bar together fill a measure.
77
+ const time = i === 0 ? '1/4' : i === bars.length - 1 ? '2/4' : '3/4';
78
+ const system = f.System({ x, y, width, spaceBetweenStaves: 8 });
79
+ const stave = system.addStave({ voices: [score.voice(notes, { time })], options: { topTextPosition: 3.5 } });
80
+ const tablature = system.addStave({
81
+ stave: score.make.tabStave({ x, y, width }),
82
+ voices: [score.voice(tab, { time })],
83
+ });
84
+ if (i === 0 || i === 5) {
85
+ stave.addClef('treble', 'default', '8vb');
86
+ if (i === 0) stave.addTimeSignature('3/4');
87
+ tablature.addClef('tab');
88
+ system.addConnector('bracket');
89
+ }
90
+ if (i === bars.length - 1) {
91
+ stave.setEndBarType(BarlineType.END);
92
+ tablature.setEndBarType(BarlineType.END);
93
+ }
94
+ });
95
+ f.draw();
96
+ options.assert.ok(true, 'Chord melody and tab share the same rhythmic grid');
97
+ }
Binary file