vexflow 5.0.0-beta.1 → 5.1.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 (127) hide show
  1. package/LICENSE +3 -3
  2. package/README.md +32 -50
  3. package/build/cjs/vexflow-bravura.js +2 -2
  4. package/build/cjs/vexflow-bravura.js.map +1 -1
  5. package/build/cjs/vexflow-core.js +2 -2
  6. package/build/cjs/vexflow-core.js.map +1 -1
  7. package/build/cjs/vexflow-debug-with-tests.js +3685 -1386
  8. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  9. package/build/cjs/vexflow-debug.js +2443 -980
  10. package/build/cjs/vexflow-debug.js.map +1 -1
  11. package/build/cjs/vexflow.js +2 -2
  12. package/build/cjs/vexflow.js.map +1 -1
  13. package/build/esm/src/accidental.js +1 -0
  14. package/build/esm/src/annotation.js +31 -8
  15. package/build/esm/src/beam.js +4 -2
  16. package/build/esm/src/chordsymbol.js +3 -1
  17. package/build/esm/src/clef.js +3 -1
  18. package/build/esm/src/curve.js +68 -11
  19. package/build/esm/src/easyscore.js +40 -1
  20. package/build/esm/src/element.js +42 -9
  21. package/build/esm/src/factory.js +46 -9
  22. package/build/esm/src/flag.js +3 -1
  23. package/build/esm/src/font.js +17 -0
  24. package/build/esm/src/formatter.js +34 -36
  25. package/build/esm/src/fraction.js +4 -1
  26. package/build/esm/src/glyphnote.js +3 -1
  27. package/build/esm/src/gracenotegroup.js +18 -1
  28. package/build/esm/src/index.js +2 -0
  29. package/build/esm/src/keysignature.js +3 -1
  30. package/build/esm/src/metrics.js +55 -1
  31. package/build/esm/src/modifiercontext.js +15 -1
  32. package/build/esm/src/note.js +2 -2
  33. package/build/esm/src/notehead.js +3 -1
  34. package/build/esm/src/ornament.js +3 -1
  35. package/build/esm/src/pedalmarking.js +44 -5
  36. package/build/esm/src/registry.js +16 -6
  37. package/build/esm/src/rendercontext.js +10 -0
  38. package/build/esm/src/sheet.js +117 -0
  39. package/build/esm/src/stave.js +13 -8
  40. package/build/esm/src/stavebarline.js +53 -1
  41. package/build/esm/src/staveline.js +2 -0
  42. package/build/esm/src/stavenote.js +54 -19
  43. package/build/esm/src/stavetie.js +3 -1
  44. package/build/esm/src/stem.js +2 -1
  45. package/build/esm/src/stemmablenote.js +9 -0
  46. package/build/esm/src/stringnumber.js +0 -1
  47. package/build/esm/src/strokes.js +10 -0
  48. package/build/esm/src/svgcontext.js +14 -4
  49. package/build/esm/src/svgexport.js +68 -0
  50. package/build/esm/src/system.js +14 -0
  51. package/build/esm/src/tables.js +69 -37
  52. package/build/esm/src/tabnote.js +20 -1
  53. package/build/esm/src/textbracket.js +5 -4
  54. package/build/esm/src/textdynamics.js +5 -0
  55. package/build/esm/src/textnote.js +3 -3
  56. package/build/esm/src/tickable.js +56 -22
  57. package/build/esm/src/timesignature.js +30 -9
  58. package/build/esm/src/timesignote.js +3 -1
  59. package/build/esm/src/tuning.js +2 -2
  60. package/build/esm/src/tuplet.js +79 -29
  61. package/build/esm/src/util.js +1 -0
  62. package/build/esm/src/version.js +3 -3
  63. package/build/esm/src/vexflow.js +14 -2
  64. package/build/esm/src/voice.js +44 -8
  65. package/build/esm/tests/accidental_tests.js +52 -0
  66. package/build/esm/tests/annotation_tests.js +38 -0
  67. package/build/esm/tests/articulation_tests.js +34 -0
  68. package/build/esm/tests/beam_tests.js +17 -0
  69. package/build/esm/tests/curve_tests.js +81 -0
  70. package/build/esm/tests/font_tests.js +32 -1
  71. package/build/esm/tests/formatter_tests.js +58 -23
  72. package/build/esm/tests/gracenote_tests.js +58 -0
  73. package/build/esm/tests/gracetabnote_tests.js +40 -0
  74. package/build/esm/tests/keysignature_tests.js +14 -3
  75. package/build/esm/tests/node/package-input-tests.mjs +149 -0
  76. package/build/esm/tests/node/render-metrics-tests.mjs +78 -0
  77. package/build/esm/tests/node/rendering-tests.mjs +75 -0
  78. package/build/esm/tests/node/sheet-tests.mjs +202 -0
  79. package/build/esm/tests/node/svg-export-tests.mjs +182 -0
  80. package/build/esm/tests/pedalmarking_tests.js +25 -0
  81. package/build/esm/tests/rests_tests.js +6 -0
  82. package/build/esm/tests/stave_tests.js +6 -3
  83. package/build/esm/tests/stavenote_tests.js +100 -55
  84. package/build/esm/tests/strokes_tests.js +19 -5
  85. package/build/esm/tests/timesignature_tests.js +19 -0
  86. package/build/esm/tests/tuplet_tests.js +273 -12
  87. package/build/esm/tests/unison_tests.js +13 -13
  88. package/build/esm/tests/voice_tests.js +34 -0
  89. package/build/esm/tools/render-metrics.mjs +49 -0
  90. package/build/esm/tools/score-fixtures.mjs +94 -0
  91. package/build/esm/tools/sheet-fixture.mjs +90 -0
  92. package/build/esm/tools/visual-regression.mjs +106 -0
  93. package/build/types/src/annotation.d.ts +17 -1
  94. package/build/types/src/curve.d.ts +24 -7
  95. package/build/types/src/easyscore.d.ts +8 -0
  96. package/build/types/src/element.d.ts +5 -0
  97. package/build/types/src/factory.d.ts +18 -1
  98. package/build/types/src/font.d.ts +2 -0
  99. package/build/types/src/formatter.d.ts +23 -14
  100. package/build/types/src/gracenotegroup.d.ts +5 -0
  101. package/build/types/src/index.d.ts +2 -0
  102. package/build/types/src/metrics.d.ts +2 -0
  103. package/build/types/src/modifiercontext.d.ts +4 -0
  104. package/build/types/src/pedalmarking.d.ts +4 -1
  105. package/build/types/src/registry.d.ts +2 -0
  106. package/build/types/src/rendercontext.d.ts +12 -0
  107. package/build/types/src/sheet.d.ts +49 -0
  108. package/build/types/src/stave.d.ts +4 -4
  109. package/build/types/src/stavebarline.d.ts +10 -0
  110. package/build/types/src/stavenote.d.ts +11 -0
  111. package/build/types/src/strokes.d.ts +4 -0
  112. package/build/types/src/svgcontext.d.ts +5 -0
  113. package/build/types/src/svgexport.d.ts +22 -0
  114. package/build/types/src/system.d.ts +4 -0
  115. package/build/types/src/tables.d.ts +9 -0
  116. package/build/types/src/tabnote.d.ts +4 -0
  117. package/build/types/src/textbracket.d.ts +1 -1
  118. package/build/types/src/textdynamics.d.ts +3 -0
  119. package/build/types/src/tickable.d.ts +27 -10
  120. package/build/types/src/timesignature.d.ts +4 -0
  121. package/build/types/src/tuplet.d.ts +8 -0
  122. package/build/types/src/util.d.ts +1 -0
  123. package/build/types/src/vexflow.d.ts +8 -1
  124. package/build/types/src/voice.d.ts +6 -0
  125. package/changelog/CHANGELOG.md +94 -0
  126. package/package.json +42 -26
  127. package/tests/flow.html +15 -7
@@ -1,22 +1,28 @@
1
1
  import { VexFlowTests } from './vexflow_test_helpers.js';
2
2
  import { Dot } from '../src/dot.js';
3
3
  import { Formatter } from '../src/formatter.js';
4
+ import { Glyphs } from '../src/glyphs.js';
4
5
  import { Stem } from '../src/stem.js';
5
6
  import { Tuplet } from '../src/tuplet.js';
6
7
  const TupletTests = {
7
8
  Start() {
8
9
  QUnit.module('Tuplet');
9
10
  const run = VexFlowTests.runTests;
11
+ run('Bounding Box Above', aboveBounding);
12
+ run('Bounding Box Below', belowBounding);
10
13
  run('Simple Tuplet', simple);
11
14
  run('Beamed Tuplet', beamed);
12
15
  run('Ratioed Tuplet', ratio);
16
+ run('Suffixed Tuplet', suffix);
13
17
  run('Bottom Tuplet', bottom);
14
18
  run('Bottom Ratioed Tuplet', bottomRatio);
19
+ run('Bottom Suffixed Tuplet', bottomSuffix);
15
20
  run('Awkward Tuplet', awkward);
16
21
  run('Complex Tuplet', complex);
17
22
  run('Mixed Stem Direction Tuplet', mixedTop);
18
23
  run('Mixed Stem Direction Bottom Tuplet', mixedBottom);
19
24
  run('Nested Tuplets', nested);
25
+ run('Nested Tuplets Only Tuplet Children', nestedChildren);
20
26
  run('Single Tuplets', single);
21
27
  },
22
28
  };
@@ -28,6 +34,143 @@ const setStemDirection = set('stemDirection');
28
34
  const setStemUp = setStemDirection(Stem.UP);
29
35
  const setStemDown = setStemDirection(Stem.DOWN);
30
36
  const setDurationToQuarterNote = set('duration')('4');
37
+ function aboveBounding(options) {
38
+ const f = VexFlowTests.makeFactory(options, 600);
39
+ const stave = f.Stave({ x: 10, y: 10 });
40
+ const notes = [
41
+ { keys: ['g/4'], duration: '4' },
42
+ { keys: ['a/4'], duration: '4' },
43
+ { keys: ['b/4'], duration: '4' },
44
+ { keys: ['g/4'], duration: '4' },
45
+ { keys: ['a/4'], duration: '4' },
46
+ { keys: ['b/4'], duration: '4' },
47
+ { keys: ['g/4'], duration: '4' },
48
+ { keys: ['a/4'], duration: '4' },
49
+ { keys: ['b/4'], duration: '4' },
50
+ { keys: ['g/4'], duration: '4' },
51
+ { keys: ['a/4'], duration: '4' },
52
+ { keys: ['b/4'], duration: '4' },
53
+ { keys: ['g/4'], duration: '4' },
54
+ { keys: ['a/4'], duration: '4' },
55
+ { keys: ['b/4'], duration: '4' },
56
+ { keys: ['g/4'], duration: '4' },
57
+ { keys: ['a/4'], duration: '4' },
58
+ { keys: ['b/4'], duration: '4' },
59
+ { keys: ['g/4'], duration: '4' },
60
+ { keys: ['a/4'], duration: '4' },
61
+ { keys: ['b/4'], duration: '4' },
62
+ ]
63
+ .map(setStemUp)
64
+ .map(f.StaveNote.bind(f));
65
+ const tuplet = f.Tuplet({ notes: notes.slice(0, 3), options: { notesOccupied: 2, numNotes: 3, bracketed: false } });
66
+ const ratioedTuplet = f.Tuplet({
67
+ notes: notes.slice(3, 6),
68
+ options: { notesOccupied: 2, numNotes: 3, bracketed: false, ratioed: true },
69
+ });
70
+ const suffixTuplet = f.Tuplet({
71
+ notes: notes.slice(6, 9),
72
+ options: { notesOccupied: 2, numNotes: 3, bracketed: false, suffix: Glyphs.metNoteQuarterUp },
73
+ });
74
+ const ratioedSuffixTuplet = f.Tuplet({
75
+ notes: notes.slice(9, 12),
76
+ options: { notesOccupied: 2, numNotes: 3, bracketed: false, suffix: Glyphs.metNoteQuarterUp, ratioed: true },
77
+ });
78
+ const bracketedTuplet = f.Tuplet({ notes: notes.slice(12, 15), options: { notesOccupied: 2, numNotes: 3 } });
79
+ const bracketedRatioedTuplet = f.Tuplet({
80
+ notes: notes.slice(15, 18),
81
+ options: { notesOccupied: 2, numNotes: 3, ratioed: true },
82
+ });
83
+ const bracketedRatioedSuffixTuplet = f.Tuplet({
84
+ notes: notes.slice(18),
85
+ options: { notesOccupied: 2, numNotes: 3, suffix: Glyphs.metNoteQuarterUp, ratioed: true },
86
+ });
87
+ const voice = f.Voice().setStrict(false).addTickables(notes);
88
+ new Formatter().joinVoices([voice]).formatToStave([voice], stave);
89
+ f.draw();
90
+ VexFlowTests.drawBoundingBox(f.getContext(), tuplet);
91
+ VexFlowTests.drawBoundingBox(f.getContext(), ratioedTuplet);
92
+ VexFlowTests.drawBoundingBox(f.getContext(), suffixTuplet);
93
+ VexFlowTests.drawBoundingBox(f.getContext(), ratioedSuffixTuplet);
94
+ VexFlowTests.drawBoundingBox(f.getContext(), bracketedTuplet);
95
+ VexFlowTests.drawBoundingBox(f.getContext(), bracketedRatioedTuplet);
96
+ VexFlowTests.drawBoundingBox(f.getContext(), bracketedRatioedSuffixTuplet);
97
+ options.assert.ok(true, 'Bounding Box Above Test');
98
+ }
99
+ function belowBounding(options) {
100
+ const f = VexFlowTests.makeFactory(options, 600);
101
+ const stave = f.Stave({ x: 10, y: 10 });
102
+ const notes = [
103
+ { keys: ['g/4'], duration: '4' },
104
+ { keys: ['a/4'], duration: '4' },
105
+ { keys: ['b/4'], duration: '4' },
106
+ { keys: ['g/4'], duration: '4' },
107
+ { keys: ['a/4'], duration: '4' },
108
+ { keys: ['b/4'], duration: '4' },
109
+ { keys: ['g/4'], duration: '4' },
110
+ { keys: ['a/4'], duration: '4' },
111
+ { keys: ['b/4'], duration: '4' },
112
+ { keys: ['g/4'], duration: '4' },
113
+ { keys: ['a/4'], duration: '4' },
114
+ { keys: ['b/4'], duration: '4' },
115
+ { keys: ['g/4'], duration: '4' },
116
+ { keys: ['a/4'], duration: '4' },
117
+ { keys: ['b/4'], duration: '4' },
118
+ { keys: ['g/4'], duration: '4' },
119
+ { keys: ['a/4'], duration: '4' },
120
+ { keys: ['b/4'], duration: '4' },
121
+ { keys: ['g/4'], duration: '4' },
122
+ { keys: ['a/4'], duration: '4' },
123
+ { keys: ['b/4'], duration: '4' },
124
+ ]
125
+ .map(setStemUp)
126
+ .map(f.StaveNote.bind(f));
127
+ const tuplet = f.Tuplet({
128
+ notes: notes.slice(0, 3),
129
+ options: { notesOccupied: 2, numNotes: 3, bracketed: false, location: -1 },
130
+ });
131
+ const ratioedTuplet = f.Tuplet({
132
+ notes: notes.slice(3, 6),
133
+ options: { notesOccupied: 2, numNotes: 3, bracketed: false, ratioed: true, location: -1 },
134
+ });
135
+ const suffixTuplet = f.Tuplet({
136
+ notes: notes.slice(6, 9),
137
+ options: { notesOccupied: 2, numNotes: 3, bracketed: false, suffix: Glyphs.metNoteQuarterUp, location: -1 },
138
+ });
139
+ const ratioedSuffixTuplet = f.Tuplet({
140
+ notes: notes.slice(9, 12),
141
+ options: {
142
+ notesOccupied: 2,
143
+ numNotes: 3,
144
+ bracketed: false,
145
+ suffix: Glyphs.metNoteQuarterUp,
146
+ ratioed: true,
147
+ location: -1,
148
+ },
149
+ });
150
+ const bracketedTuplet = f.Tuplet({
151
+ notes: notes.slice(12, 15),
152
+ options: { notesOccupied: 2, numNotes: 3, location: -1 },
153
+ });
154
+ const bracketedRatioedTuplet = f.Tuplet({
155
+ notes: notes.slice(15, 18),
156
+ options: { notesOccupied: 2, numNotes: 3, ratioed: true, location: -1 },
157
+ });
158
+ const bracketedRatioedSuffixTuplet = f.Tuplet({
159
+ notes: notes.slice(18),
160
+ options: { notesOccupied: 2, numNotes: 3, suffix: Glyphs.metNoteQuarterUp, ratioed: true, location: -1 },
161
+ });
162
+ const voice = f.Voice().setStrict(false).addTickables(notes);
163
+ new Formatter().joinVoices([voice]).formatToStave([voice], stave);
164
+ f.draw();
165
+ VexFlowTests.drawBoundingBox(f.getContext(), tuplet);
166
+ VexFlowTests.drawBoundingBox(f.getContext(), ratioedTuplet);
167
+ VexFlowTests.drawBoundingBox(f.getContext(), suffixTuplet);
168
+ VexFlowTests.drawBoundingBox(f.getContext(), ratioedSuffixTuplet);
169
+ VexFlowTests.drawBoundingBox(f.getContext(), bracketedTuplet);
170
+ VexFlowTests.drawBoundingBox(f.getContext(), bracketedRatioedTuplet);
171
+ VexFlowTests.drawBoundingBox(f.getContext(), bracketedRatioedSuffixTuplet);
172
+ options.assert.ok(true, 'Bounding Box Below Test');
173
+ }
31
174
  function simple(options) {
32
175
  const f = VexFlowTests.makeFactory(options);
33
176
  const stave = f.Stave({ x: 10, y: 10, width: 350 }).addTimeSignature('3/4');
@@ -114,6 +257,42 @@ function ratio(options) {
114
257
  f.draw();
115
258
  options.assert.ok(true, 'Ratioed Test');
116
259
  }
260
+ function suffix(options) {
261
+ const f = VexFlowTests.makeFactory(options);
262
+ const stave = f.Stave({ x: 10, y: 10, width: 350 }).addTimeSignature('4/4');
263
+ const notes = [
264
+ { keys: ['f/4'], duration: '4' },
265
+ { keys: ['a/4'], duration: '4' },
266
+ { keys: ['b/4'], duration: '4' },
267
+ { keys: ['g/4'], duration: '8' },
268
+ { keys: ['e/4'], duration: '8' },
269
+ { keys: ['g/4'], duration: '8' },
270
+ ]
271
+ .map(setStemUp)
272
+ .map(f.StaveNote.bind(f));
273
+ f.Beam({
274
+ notes: notes.slice(3, 6),
275
+ });
276
+ f.Tuplet({
277
+ notes: notes.slice(0, 3),
278
+ options: {
279
+ ratioed: true,
280
+ suffix: Glyphs.noteQuarterUp,
281
+ },
282
+ });
283
+ f.Tuplet({
284
+ notes: notes.slice(3, 6),
285
+ options: {
286
+ ratioed: true,
287
+ notesOccupied: 4,
288
+ suffix: Glyphs.note8thUp,
289
+ },
290
+ });
291
+ const voice = f.Voice().setStrict(true).addTickables(notes);
292
+ new Formatter().joinVoices([voice]).formatToStave([voice], stave);
293
+ f.draw();
294
+ options.assert.ok(true, 'Base Duration Test');
295
+ }
117
296
  function bottom(options) {
118
297
  const f = VexFlowTests.makeFactory(options, 350, 160);
119
298
  const stave = f.Stave({ x: 10, y: 10 }).addTimeSignature('3/4');
@@ -184,6 +363,46 @@ function bottomRatio(options) {
184
363
  f.draw();
185
364
  options.assert.ok(true, 'Bottom Ratioed Test');
186
365
  }
366
+ function bottomSuffix(options) {
367
+ const f = VexFlowTests.makeFactory(options, 350, 160);
368
+ const stave = f.Stave({ x: 10, y: 10 }).addTimeSignature('5/8');
369
+ const notes = [
370
+ { keys: ['f/4'], duration: '4' },
371
+ { keys: ['c/4'], duration: '4' },
372
+ { keys: ['d/4'], duration: '4' },
373
+ { keys: ['d/5'], duration: '8' },
374
+ { keys: ['g/5'], duration: '8' },
375
+ { keys: ['b/4'], duration: '8' },
376
+ ]
377
+ .map(setStemDown)
378
+ .map(f.StaveNote.bind(f));
379
+ f.Beam({
380
+ notes: notes.slice(3, 6),
381
+ });
382
+ f.Tuplet({
383
+ notes: notes.slice(0, 3),
384
+ options: {
385
+ location: Tuplet.LOCATION_BOTTOM,
386
+ ratioed: true,
387
+ suffix: Glyphs.metNoteQuarterUp,
388
+ },
389
+ });
390
+ f.Tuplet({
391
+ notes: notes.slice(3, 6),
392
+ options: {
393
+ location: Tuplet.LOCATION_BOTTOM,
394
+ notesOccupied: 1,
395
+ suffix: Glyphs.metNote8thUp,
396
+ },
397
+ });
398
+ const voice = f
399
+ .Voice({ time: { numBeats: 5, beatValue: 8 } })
400
+ .setStrict(true)
401
+ .addTickables(notes);
402
+ new Formatter().joinVoices([voice]).formatToStave([voice], stave);
403
+ f.draw();
404
+ options.assert.ok(true, 'Bottom Base Duration Test');
405
+ }
187
406
  function awkward(options) {
188
407
  const f = VexFlowTests.makeFactory(options, 370, 160);
189
408
  const stave = f.Stave({ x: 10, y: 10 });
@@ -369,6 +588,13 @@ function nested(options) {
369
588
  f.Beam({
370
589
  notes: notes.slice(2, 7),
371
590
  });
591
+ f.Tuplet({
592
+ notes: notes.slice(2, 7),
593
+ options: {
594
+ notesOccupied: 4,
595
+ numNotes: 5,
596
+ },
597
+ });
372
598
  f.Tuplet({
373
599
  notes: notes.slice(0, 7),
374
600
  options: {
@@ -376,17 +602,52 @@ function nested(options) {
376
602
  numNotes: 3,
377
603
  },
378
604
  });
605
+ const voice = f.Voice().setStrict(true).addTickables(notes);
606
+ new Formatter().joinVoices([voice]).formatToStave([voice], stave);
607
+ f.draw();
608
+ options.assert.ok(true, 'Nested Tuplets');
609
+ }
610
+ function nestedChildren(options) {
611
+ const f = VexFlowTests.makeFactory(options);
612
+ const stave = f.Stave({ x: 10, y: 10 }).addTimeSignature('4/4');
613
+ const notes = [
614
+ { keys: ['b/4'], duration: '4' },
615
+ { keys: ['a/4'], duration: '4' },
616
+ { keys: ['c/4'], duration: '4' },
617
+ { keys: ['g/4'], duration: '8' },
618
+ { keys: ['a/4'], duration: '8' },
619
+ { keys: ['f/4'], duration: '8' },
620
+ ]
621
+ .map(setStemUp)
622
+ .map(f.StaveNote.bind(f));
623
+ f.Beam({
624
+ notes: notes.slice(3),
625
+ });
626
+ f.Tuplet({
627
+ notes: notes.slice(0, 3),
628
+ options: {
629
+ notesOccupied: 2,
630
+ numNotes: 3,
631
+ },
632
+ });
379
633
  f.Tuplet({
380
- notes: notes.slice(2, 7),
634
+ notes: notes.slice(3),
635
+ options: {
636
+ notesOccupied: 2,
637
+ numNotes: 3,
638
+ },
639
+ });
640
+ f.Tuplet({
641
+ notes: notes.slice(),
381
642
  options: {
382
643
  notesOccupied: 4,
383
- numNotes: 5,
644
+ numNotes: 3,
384
645
  },
385
646
  });
386
647
  const voice = f.Voice().setStrict(true).addTickables(notes);
387
648
  new Formatter().joinVoices([voice]).formatToStave([voice], stave);
388
649
  f.draw();
389
- options.assert.ok(true, 'Nested Tuplets');
650
+ options.assert.ok(true, 'Nested Tuplets Only Tuplet Children');
390
651
  }
391
652
  function single(options) {
392
653
  const f = VexFlowTests.makeFactory(options);
@@ -405,15 +666,6 @@ function single(options) {
405
666
  f.Beam({
406
667
  notes: notes.slice(1, 4),
407
668
  });
408
- f.Tuplet({
409
- notes: notes.slice(0, -1),
410
- options: {
411
- numNotes: 4,
412
- notesOccupied: 3,
413
- ratioed: true,
414
- bracketed: true,
415
- },
416
- });
417
669
  f.Tuplet({
418
670
  notes: notes.slice(0, 1),
419
671
  options: {
@@ -438,6 +690,15 @@ function single(options) {
438
690
  bracketed: true,
439
691
  },
440
692
  });
693
+ f.Tuplet({
694
+ notes: notes.slice(0, -1),
695
+ options: {
696
+ numNotes: 4,
697
+ notesOccupied: 3,
698
+ ratioed: true,
699
+ bracketed: true,
700
+ },
701
+ });
441
702
  const voice = f
442
703
  .Voice({ time: { numBeats: 4, beatValue: 4 } })
443
704
  .setStrict(true)
@@ -26,22 +26,22 @@ const UnisonTests = {
26
26
  };
27
27
  function simple(options) {
28
28
  VexFlow.UNISON = options.params.unison;
29
- const vf = VexFlowTests.makeFactory(options, 500, 200);
30
- const score = vf.EasyScore();
31
- const system = vf.System({ y: 40, x: 10, width: 400 });
29
+ const factory = VexFlowTests.makeFactory(options, 500, 200);
30
+ const score = factory.EasyScore();
31
+ const system = factory.System({ y: 40, x: 10, width: 400 });
32
32
  system.addStave({
33
33
  voices: [score.voice(score.notes(options.params.voice1)), score.voice(score.notes(options.params.voice2))],
34
34
  });
35
35
  system.getStaves()[0].setClef('treble');
36
36
  system.getStaves()[0].setTimeSignature('4/4');
37
- vf.draw();
37
+ factory.draw();
38
38
  options.assert.expect(0);
39
39
  }
40
40
  function style(options) {
41
41
  VexFlow.UNISON = options.params.unison;
42
- const vf = VexFlowTests.makeFactory(options, 500, 200);
43
- const score = vf.EasyScore();
44
- const system = vf.System({ y: 40, x: 10, width: 400 });
42
+ const factory = VexFlowTests.makeFactory(options, 500, 200);
43
+ const score = factory.EasyScore();
44
+ const system = factory.System({ y: 40, x: 10, width: 400 });
45
45
  const notes1 = score.notes('e4/q, e4/q, e4/h');
46
46
  const notes2 = score.notes('e4/8, e4/8, e4/q, e4/h');
47
47
  notes1[2].setStyle({ fillStyle: 'blue', strokeStyle: 'blue' });
@@ -51,23 +51,23 @@ function style(options) {
51
51
  });
52
52
  system.getStaves()[0].setClef('treble');
53
53
  system.getStaves()[0].setTimeSignature('4/4');
54
- vf.draw();
54
+ factory.draw();
55
55
  options.assert.expect(0);
56
56
  }
57
57
  function breve(options) {
58
58
  VexFlow.UNISON = options.params.unison;
59
- const vf = VexFlowTests.makeFactory(options, 500, 200);
60
- const score = vf.EasyScore();
61
- const system = vf.System({ y: 40, x: 10, width: 400 });
59
+ const factory = VexFlowTests.makeFactory(options, 500, 200);
60
+ const score = factory.EasyScore();
61
+ const system = factory.System({ y: 40, x: 10, width: 400 });
62
62
  system.addStave({
63
63
  voices: [
64
- score.voice([vf.StaveNote({ keys: ['e/4'], duration: '1/2' })], { time: '8/4' }),
64
+ score.voice([factory.StaveNote({ keys: ['e/4'], duration: '1/2' })], { time: '8/4' }),
65
65
  score.voice(score.notes('e4/1, e4/1'), { time: '8/4' }),
66
66
  ],
67
67
  });
68
68
  system.getStaves()[0].setClef('treble');
69
69
  system.getStaves()[0].setTimeSignature('8/4');
70
- vf.draw();
70
+ factory.draw();
71
71
  options.assert.expect(0);
72
72
  }
73
73
  VexFlowTests.register(UnisonTests);
@@ -9,6 +9,7 @@ import { MockTickable } from './mocks.js';
9
9
  const VoiceTests = {
10
10
  Start() {
11
11
  QUnit.module('Voice');
12
+ QUnit.test('tupletDurationEdits', tupletDurationEdits);
12
13
  QUnit.test('Strict Test', strict);
13
14
  QUnit.test('Ignore Test', ignore);
14
15
  VexFlowTests.runTests('Full Voice Mode Test', full);
@@ -67,3 +68,36 @@ function full(options, contextBuilder) {
67
68
  }
68
69
  VexFlowTests.register(VoiceTests);
69
70
  export { VoiceTests };
71
+ function tupletDurationEdits(assert) {
72
+ const notes = Array.from({ length: 3 }, () => new StaveNote({ keys: ['c/4'], duration: '8' }));
73
+ const voice = new Voice('1/4').setStrict(false).addTickables(notes);
74
+ assert.equal(voice.getTicksUsed().value(), 6144);
75
+ const tuplet = new VexFlow.Tuplet(notes, { numNotes: 3, notesOccupied: 2 });
76
+ voice.setStrict(true);
77
+ assert.equal(voice.getTicksUsed().value(), 4096);
78
+ assert.ok(voice.isComplete());
79
+ tuplet.attach();
80
+ notes[0].addTuplet(tuplet);
81
+ assert.equal(voice.getTicksUsed().value(), 4096, 'Repeated attachment is harmless');
82
+ assert.equal(voice.getSmallestTickCount().value(), 4096 / 3);
83
+ assert.equal(voice.getResolutionMultiplier(), 3);
84
+ const nested = new VexFlow.Tuplet(notes, { numNotes: 3, notesOccupied: 2 });
85
+ assert.equal(voice.getTicksUsed().value(), (4096 * 2) / 3);
86
+ notes[0].setDuration(new VexFlow.Fraction(1, 4));
87
+ nested.detach();
88
+ tuplet.detach();
89
+ assert.equal(voice.getTicksUsed().value(), 8192, 'Duration edits retain their unscaled base');
90
+ assert.notOk(voice.isComplete());
91
+ tuplet.attach();
92
+ tuplet.setNotesOccupied(1);
93
+ assert.equal(voice.getTicksUsed().value(), 8192 / 3);
94
+ notes.forEach((note) => note.clearTuplets());
95
+ assert.equal(voice.getTicksUsed().value(), 8192);
96
+ const first = Array.from({ length: 3 }, () => new StaveNote({ keys: ['c/4'], duration: '8' }));
97
+ new VexFlow.Tuplet(first, { numNotes: 3, notesOccupied: 2 });
98
+ const strict = new Voice('1/4').addTickables(first);
99
+ assert.ok(strict.isComplete());
100
+ assert.throws(() => strict.addTickable(new StaveNote({ keys: ['c/4'], duration: '8' })), /Too many ticks/);
101
+ const other = new Voice('1/4').addTickables([new StaveNote({ keys: ['d/4'], duration: 'q' })]);
102
+ new Formatter().joinVoices([strict, other]).format([strict, other], 300);
103
+ }
@@ -0,0 +1,49 @@
1
+ export function analyzeLayout(boxes, viewport, tolerance = 0.5) {
2
+ const invalid = [];
3
+ const overflow = [];
4
+ const collisions = [];
5
+ const valid = [];
6
+ for (const box of boxes) {
7
+ if (![box.x, box.y, box.width, box.height].every(Number.isFinite) || box.width < 0 || box.height < 0) {
8
+ invalid.push(box.id);
9
+ continue;
10
+ }
11
+ valid.push(box);
12
+ const excess = Math.max(0, -box.x, -box.y, box.x + box.width - viewport.width, box.y + box.height - viewport.height);
13
+ if (excess > tolerance)
14
+ overflow.push({ id: box.id, excess });
15
+ }
16
+ for (let i = 0; i < valid.length; i++) {
17
+ const a = valid[i];
18
+ if (a.group === undefined)
19
+ continue;
20
+ for (let j = i + 1; j < valid.length; j++) {
21
+ const b = valid[j];
22
+ if (a.group !== b.group)
23
+ continue;
24
+ const width = Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x);
25
+ const height = Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y);
26
+ if (width > tolerance && height > tolerance)
27
+ collisions.push({ ids: [a.id, b.id], area: width * height });
28
+ }
29
+ }
30
+ return { invalid, overflow, collisions };
31
+ }
32
+ export function comparePixels(a, b, channelTolerance = 0) {
33
+ if (a.length !== b.length || a.length % 4)
34
+ throw new Error('RGBA buffers must have equal lengths.');
35
+ let changed = 0;
36
+ let maxDelta = 0;
37
+ const diff = new Uint8ClampedArray(a.length);
38
+ for (let i = 0; i < a.length; i += 4) {
39
+ let delta = 0;
40
+ for (let c = 0; c < 4; c++)
41
+ delta = Math.max(delta, Math.abs(a[i + c] - b[i + c]));
42
+ maxDelta = Math.max(maxDelta, delta);
43
+ const differs = delta > channelTolerance;
44
+ if (differs)
45
+ changed++;
46
+ diff.set(differs ? [224, 45, 87, 255] : [245, 247, 250, 255], i);
47
+ }
48
+ return { changed, ratio: a.length ? changed / (a.length / 4) : 0, maxDelta, diff };
49
+ }
@@ -0,0 +1,94 @@
1
+ export function renderScore({ kind = 'chorale', systems = 4, containerId = 'score' } = {}) {
2
+ var _a;
3
+ const VF = globalThis.VexFlow;
4
+ document.documentElement.style.cssText = 'background:white;color:black;color-scheme:light';
5
+ const container = document.getElementById(containerId);
6
+ container.replaceChildren();
7
+ const staffCount = kind === 'chamber' ? 3 : 2;
8
+ const systemHeight = staffCount * 150 + 40;
9
+ const renderer = new VF.Renderer(container, VF.Renderer.Backends.SVG);
10
+ renderer.resize(1100, systems * systemHeight);
11
+ const context = renderer.getContext();
12
+ const measures = [];
13
+ let noteCount = 0;
14
+ const start = performance.now();
15
+ const melody = ['c/5', 'd/5', 'e/5', 'g/5', 'a/5', 'g/5', 'e/5', 'd/5'];
16
+ for (let system = 0; system < systems; system++) {
17
+ for (let bar = 0; bar < 4; bar++) {
18
+ for (let staff = 0; staff < staffCount; staff++) {
19
+ const clef = staff === staffCount - 1 ? 'bass' : 'treble';
20
+ const stave = new VF.Stave(15 + bar * 267, system * systemHeight + staff * 150 + 35, 267);
21
+ if (bar === 0)
22
+ stave.addClef(clef).addTimeSignature('4/4');
23
+ const voices = [];
24
+ const beams = [];
25
+ const tuplets = [];
26
+ const ties = [];
27
+ const notes = [];
28
+ const count = kind === 'chorale' ? 4 : kind === 'piano' ? 8 : 12;
29
+ for (let beat = 0; beat < count; beat++) {
30
+ const key = clef === 'bass' ? ['c/3', 'g/2', 'a/2', 'f/2'][(bar + beat) % 4] : melody[(bar + beat) % 8];
31
+ const keys = kind === 'piano' && staff === 1 ? [key, 'e/3', 'g/3'] : [key];
32
+ const note = new VF.StaveNote({ keys, clef, duration: count === 4 ? 'q' : '8', stemDirection: 1 });
33
+ if (kind === 'chorale' && staff === 0) {
34
+ const lyric = new VF.Annotation(['Sing', 'with', 'gentle', 'voices'][beat]).setVerticalJustification(VF.Annotation.VerticalJustify.BOTTOM);
35
+ (_a = lyric.setTextBaseline) === null || _a === void 0 ? void 0 : _a.call(lyric, system * systemHeight + 162);
36
+ note.addModifier(lyric, 0);
37
+ }
38
+ notes.push(note);
39
+ }
40
+ if (kind === 'chamber') {
41
+ for (let i = 0; i < notes.length; i += 3) {
42
+ tuplets.push(new VF.Tuplet(notes.slice(i, i + 3), { numNotes: 3, notesOccupied: 2 }));
43
+ beams.push(new VF.Beam(notes.slice(i, i + 3)));
44
+ }
45
+ notes[0].addModifier(new VF.Ornament('tr'), 0);
46
+ }
47
+ else if (kind === 'piano') {
48
+ for (let i = 0; i < notes.length; i += 4)
49
+ beams.push(new VF.Beam(notes.slice(i, i + 4)));
50
+ }
51
+ voices.push(new VF.Voice('4/4').addTickables(notes));
52
+ noteCount += notes.length;
53
+ if (kind === 'chorale') {
54
+ const lower = [0, 1].map(() => new VF.StaveNote({ keys: [clef === 'bass' ? 'c/2' : 'g/4'], clef, duration: 'h', stemDirection: -1 }));
55
+ voices.push(new VF.Voice('4/4').addTickables(lower));
56
+ ties.push(new VF.StaveTie({
57
+ firstNote: lower[0],
58
+ lastNote: lower[1],
59
+ firstIndexes: [0],
60
+ lastIndexes: [0],
61
+ }).setDirection(-1));
62
+ noteCount += lower.length;
63
+ }
64
+ measures.push({ stave, voices, beams, tuplets, ties });
65
+ }
66
+ }
67
+ }
68
+ const constructed = performance.now();
69
+ for (const { stave, voices } of measures) {
70
+ voices.forEach((voice) => {
71
+ voice.setStave(stave);
72
+ voice.getTickables().forEach((note) => note.setStave(stave));
73
+ });
74
+ new VF.Formatter().joinVoices(voices).formatToStave(voices, stave);
75
+ }
76
+ const formatted = performance.now();
77
+ for (const { stave, voices, beams, tuplets, ties } of measures) {
78
+ stave.setContext(context).draw();
79
+ voices.forEach((voice) => voice.draw(context, stave));
80
+ [...beams, ...tuplets, ...ties].forEach((element) => element.setContext(context).draw());
81
+ }
82
+ const drawn = performance.now();
83
+ return {
84
+ kind,
85
+ systems,
86
+ staves: measures.length,
87
+ notes: noteCount,
88
+ constructionMs: constructed - start,
89
+ layoutMs: formatted - constructed,
90
+ drawMs: drawn - formatted,
91
+ totalMs: drawn - start,
92
+ svg: context.svg.outerHTML,
93
+ };
94
+ }