vexflow 5.3.0 → 5.4.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 (115) hide show
  1. package/README.md +2 -0
  2. package/build/cjs/vexflow-bravura.js +2 -2
  3. package/build/cjs/vexflow-bravura.js.map +1 -1
  4. package/build/cjs/vexflow-core.js +2 -2
  5. package/build/cjs/vexflow-core.js.map +1 -1
  6. package/build/cjs/vexflow-debug-with-tests.js +4189 -772
  7. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  8. package/build/cjs/vexflow-debug.js +4323 -906
  9. package/build/cjs/vexflow-debug.js.map +1 -1
  10. package/build/cjs/vexflow.js +2 -2
  11. package/build/cjs/vexflow.js.map +1 -1
  12. package/build/esm/src/alternatingtremolo.js +68 -0
  13. package/build/esm/src/annotation.js +19 -3
  14. package/build/esm/src/articulation.js +5 -1
  15. package/build/esm/src/beam.js +13 -0
  16. package/build/esm/src/bend.js +57 -6
  17. package/build/esm/src/clef.js +3 -0
  18. package/build/esm/src/continuouslayout.js +681 -0
  19. package/build/esm/src/continuousspan.js +159 -0
  20. package/build/esm/src/curve.js +21 -2
  21. package/build/esm/src/easyscore/composition.js +13 -2
  22. package/build/esm/src/easyscore/policies.js +6 -3
  23. package/build/esm/src/engravinggeometry.js +8 -1
  24. package/build/esm/src/factory.js +16 -4
  25. package/build/esm/src/font.js +9 -1
  26. package/build/esm/src/fretdiagram.js +77 -0
  27. package/build/esm/src/guitargesture.js +33 -0
  28. package/build/esm/src/guitarmodifiers.js +26 -0
  29. package/build/esm/src/index.js +8 -0
  30. package/build/esm/src/instrumentprofile.js +123 -0
  31. package/build/esm/src/keysignature.js +23 -1
  32. package/build/esm/src/notationspelling.js +73 -0
  33. package/build/esm/src/note.js +3 -0
  34. package/build/esm/src/ornament.js +5 -0
  35. package/build/esm/src/pagebreaks.js +58 -0
  36. package/build/esm/src/pedalmarking.js +39 -17
  37. package/build/esm/src/phraselayout.js +503 -0
  38. package/build/esm/src/phraseribbon.js +28 -0
  39. package/build/esm/src/publication.js +402 -0
  40. package/build/esm/src/publicationview.js +114 -0
  41. package/build/esm/src/scorenavigation.js +172 -0
  42. package/build/esm/src/sheet.js +14 -2
  43. package/build/esm/src/stave.js +33 -16
  44. package/build/esm/src/stavebarline.js +5 -7
  45. package/build/esm/src/staveconnector.js +1 -0
  46. package/build/esm/src/stavehairpin.js +53 -27
  47. package/build/esm/src/stavenote.js +6 -1
  48. package/build/esm/src/stavetie.js +27 -2
  49. package/build/esm/src/strokes.js +4 -0
  50. package/build/esm/src/system.js +19 -4
  51. package/build/esm/src/systembreaks.js +42 -0
  52. package/build/esm/src/tabnote.js +6 -1
  53. package/build/esm/src/textbracket.js +24 -5
  54. package/build/esm/src/timesignature.js +15 -6
  55. package/build/esm/src/tuplet.js +1 -0
  56. package/build/esm/src/version.js +3 -3
  57. package/build/esm/src/vexflow.js +16 -0
  58. package/build/esm/src/voice.js +7 -3
  59. package/build/esm/tests/engraving/continuous-studies.mjs +140 -0
  60. package/build/esm/tests/engraving/instrument-studies.mjs +273 -0
  61. package/build/esm/tests/engraving/phrase-studies.mjs +63 -0
  62. package/build/esm/tests/engraving/publication-studies.mjs +87 -0
  63. package/build/esm/tests/engraving/specialist-studies.mjs +347 -0
  64. package/build/esm/tests/engraving/studies.mjs +88 -0
  65. package/build/esm/tests/node/continuous-score-tests.mjs +282 -0
  66. package/build/esm/tests/node/instrument-profile-tests.mjs +224 -0
  67. package/build/esm/tests/node/phrase-layout-tests.mjs +281 -0
  68. package/build/esm/tests/node/publication-tests.mjs +219 -0
  69. package/build/esm/tools/easyscore-structure.mjs +1 -1
  70. package/build/esm/tools/explorer/catalog/entries.mjs +2 -1
  71. package/build/esm/tools/explorer/catalog/expression.mjs +14 -9
  72. package/build/esm/tools/explorer/catalog/guitar.mjs +238 -0
  73. package/build/esm/tools/explorer/catalog/layout.mjs +8 -6
  74. package/build/esm/tools/explorer/catalog/notes.mjs +16 -14
  75. package/build/esm/tools/explorer/catalog/staves.mjs +12 -6
  76. package/build/esm/tools/explorer/catalog/strings.mjs +10 -7
  77. package/build/types/src/alternatingtremolo.d.ts +13 -0
  78. package/build/types/src/annotation.d.ts +9 -0
  79. package/build/types/src/articulation.d.ts +3 -0
  80. package/build/types/src/beam.d.ts +2 -0
  81. package/build/types/src/bend.d.ts +8 -0
  82. package/build/types/src/clef.d.ts +3 -0
  83. package/build/types/src/continuouslayout.d.ts +103 -0
  84. package/build/types/src/continuousspan.d.ts +60 -0
  85. package/build/types/src/curve.d.ts +11 -0
  86. package/build/types/src/easyscore/composition.d.ts +8 -0
  87. package/build/types/src/easyscore/policies.d.ts +1 -1
  88. package/build/types/src/fretdiagram.d.ts +23 -0
  89. package/build/types/src/guitargesture.d.ts +26 -0
  90. package/build/types/src/guitarmodifiers.d.ts +3 -0
  91. package/build/types/src/index.d.ts +10 -0
  92. package/build/types/src/instrumentprofile.d.ts +124 -0
  93. package/build/types/src/keysignature.d.ts +9 -0
  94. package/build/types/src/notationspelling.d.ts +25 -0
  95. package/build/types/src/note.d.ts +15 -0
  96. package/build/types/src/ornament.d.ts +3 -1
  97. package/build/types/src/pagebreaks.d.ts +26 -0
  98. package/build/types/src/pedalmarking.d.ts +9 -0
  99. package/build/types/src/phraselayout.d.ts +87 -0
  100. package/build/types/src/phraseribbon.d.ts +7 -0
  101. package/build/types/src/publication.d.ts +61 -0
  102. package/build/types/src/publicationview.d.ts +27 -0
  103. package/build/types/src/scorenavigation.d.ts +33 -0
  104. package/build/types/src/sheet.d.ts +5 -0
  105. package/build/types/src/stave.d.ts +13 -0
  106. package/build/types/src/stavehairpin.d.ts +18 -0
  107. package/build/types/src/stavetie.d.ts +5 -0
  108. package/build/types/src/system.d.ts +8 -1
  109. package/build/types/src/systembreaks.d.ts +9 -0
  110. package/build/types/src/textbracket.d.ts +7 -0
  111. package/build/types/src/timesignature.d.ts +4 -0
  112. package/build/types/src/vexflow.d.ts +16 -0
  113. package/build/types/src/voice.d.ts +2 -0
  114. package/changelog/CHANGELOG.md +8 -0
  115. package/package.json +9 -2
@@ -0,0 +1,347 @@
1
+ export function registerSpecialistStudies() {
2
+ const VF = globalThis.VexFlow;
3
+ const width = 800;
4
+ const voice = (f, notes) => f.EasyScore().voice(notes, { mode: 'soft' });
5
+ const note = (f, keys, duration, options = {}) => f.StaveNote(Object.assign({ keys, duration }, options));
6
+ const label = (f, n, text, vJustify = 'top') => n.addModifier(f.Annotation({ text, vJustify }), 0);
7
+ const system = (f, x, y, w) => f.System({ x, y, width: w, spaceBetweenStaves: 12 });
8
+ function timeline(notes) {
9
+ const times = [0];
10
+ for (const n of notes)
11
+ times.push(times.at(-1) + n.getTicks().value() / (VF.RESOLUTION / 16));
12
+ return times;
13
+ }
14
+ function pair(f, tuning, strings, duration, stem = 1) {
15
+ const positions = strings.map(([str, fret]) => ({ str, fret }));
16
+ const keys = positions.map(({ str, fret }) => fret === 'X' ? tuning.getNoteForFret(0, str) + '/x' : tuning.getNoteForFret(fret, str));
17
+ return {
18
+ staff: note(f, keys, duration, { stemDirection: stem }),
19
+ tab: f.TabNote({ positions, duration, stemDirection: stem }, true),
20
+ };
21
+ }
22
+ function rest(f, duration) {
23
+ return { staff: note(f, ['b/4'], duration + 'r'), tab: f.GhostNote({ duration }) };
24
+ }
25
+ function guitarBar(f, x, y, w, parts, meter, clef = true, tabSpaceAbove = 0) {
26
+ const sys = system(f, x, y, w);
27
+ const staffVoices = parts.map((p) => voice(f, p.map((e) => e.staff)));
28
+ VF.Accidental.applyAccidentals(staffVoices, 'C');
29
+ const staff = sys.addStave({ voices: staffVoices });
30
+ const tab = sys.addStave({
31
+ stave: f.TabStave({ x, y, width: w }),
32
+ spaceAbove: tabSpaceAbove,
33
+ voices: parts.map((p) => voice(f, p.map((e) => e.tab))),
34
+ });
35
+ if (clef) {
36
+ staff.addClef('treble');
37
+ tab.addTabGlyph();
38
+ }
39
+ if (meter)
40
+ staff.addTimeSignature(meter);
41
+ }
42
+ function beamPair(f, events) {
43
+ for (const view of ['staff', 'tab'])
44
+ f.Beam({ notes: events.map((e) => e[view]) });
45
+ }
46
+ function checkPair(test, events, expected) {
47
+ for (const view of ['staff', 'tab']) {
48
+ test.assert.deepEqual(timeline(events.map((e) => e[view])), expected, view + ' onset and end times');
49
+ }
50
+ for (const event of events) {
51
+ test.assert.equal(event.staff.checkTickContext().getX(), event.tab.checkTickContext().getX(), 'Shared rhythmic column');
52
+ }
53
+ }
54
+ function flamenco(f, test) {
55
+ const tuning = new VF.Tuning('standard');
56
+ const grip = [
57
+ [4, 2],
58
+ [3, 1],
59
+ [2, 0],
60
+ [1, 0],
61
+ ];
62
+ const events = ['16', '16', '16', '16', 'q', 'q', 'q'].map((d) => pair(f, tuning, grip, d));
63
+ const marks = ['a', 'm', 'i', 'i', 'i + golpe', 'p', ''];
64
+ events.forEach((e, i) => {
65
+ if (marks[i])
66
+ label(f, e.staff, marks[i]);
67
+ const type = i === 6 ? VF.Stroke.Type.RASGUEADO_DOWN : i === 3 ? VF.Stroke.Type.BRUSH_UP : VF.Stroke.Type.BRUSH_DOWN;
68
+ for (const n of [e.staff, e.tab])
69
+ n.addModifier(new VF.Stroke(type), 0);
70
+ });
71
+ events[4].staff.addModifier(f.Articulation({ type: 'a>', position: 'above' }));
72
+ beamPair(f, events.slice(0, 4));
73
+ guitarBar(f, 18, 43, 764, [events], '4/4');
74
+ f.draw();
75
+ checkPair(test, events, [0, 1, 2, 3, 4, 8, 12, 16]);
76
+ test.assert.deepEqual(events[4].tab.getPositions().map((p) => p.str), [4, 3, 2, 1], 'Four struck strings on the golpe beat');
77
+ }
78
+ function bossa(f, test) {
79
+ const tuning = new VF.Tuning('standard');
80
+ const chord = [
81
+ [3, 0],
82
+ [2, 1],
83
+ [1, 0],
84
+ ];
85
+ const upper = [
86
+ [rest(f, '8'), pair(f, tuning, chord, '8'), rest(f, '8'), pair(f, tuning, chord, '8')],
87
+ [
88
+ pair(f, tuning, chord, '8'),
89
+ pair(f, tuning, [
90
+ [3, 'X'],
91
+ [2, 'X'],
92
+ [1, 'X'],
93
+ ], '8'),
94
+ rest(f, '8'),
95
+ pair(f, tuning, chord, '8'),
96
+ ],
97
+ ];
98
+ const bass = [
99
+ [pair(f, tuning, [[5, 0]], 'h', -1)],
100
+ [pair(f, tuning, [[6, 0]], 'q', -1), pair(f, tuning, [[5, 0]], 'q', -1)],
101
+ ];
102
+ guitarBar(f, 18, 25, 400, [upper[0], bass[0]], '2/4', true, 3);
103
+ guitarBar(f, 418, 25, 364, [upper[1], bass[1]], null, false, 3);
104
+ const first = upper[0][3], last = upper[1][0], indices = [0, 1, 2];
105
+ f.StaveTie({
106
+ from: first.staff,
107
+ to: last.staff,
108
+ firstIndexes: indices,
109
+ lastIndexes: indices,
110
+ options: { direction: -1 },
111
+ });
112
+ f.TabTie({ firstNote: first.tab, lastNote: last.tab, firstIndexes: indices, lastIndexes: indices });
113
+ f.draw();
114
+ for (const line of upper)
115
+ checkPair(test, line, [0, 2, 4, 6, 8]);
116
+ checkPair(test, bass[0], [0, 8]);
117
+ checkPair(test, bass[1], [0, 4, 8]);
118
+ test.assert.deepEqual(first.tab.getPositions(), last.tab.getPositions(), 'Barline tie retains the same strings and frets');
119
+ test.assert.ok(upper[1][1].tab.getPositions().every((p) => p.fret === 'X'), 'Three muted strings share the second attack');
120
+ }
121
+ function metal(f, test) {
122
+ const tuning = new VF.Tuning('dropd');
123
+ const bass = Array.from({ length: 4 }, () => pair(f, tuning, [[6, 0]], '8', -1));
124
+ const ring = pair(f, tuning, [
125
+ [3, 2],
126
+ [2, 3],
127
+ ], 'h');
128
+ label(f, ring.staff, 'let ring');
129
+ label(f, bass[0].tab, 'P.M. ⑥', 'bottom');
130
+ beamPair(f, bass.slice(0, 2));
131
+ beamPair(f, bass.slice(2));
132
+ guitarBar(f, 18, 30, 764, [[ring], bass], '2/4', true, 6);
133
+ const lead = [7, 12, 7, 10].map((fret) => pair(f, tuning, [[1, fret]], '16'));
134
+ label(f, lead[1].staff, 'T');
135
+ beamPair(f, lead);
136
+ for (const [a, b, letter] of [
137
+ [1, 2, 'P'],
138
+ [2, 3, 'H'],
139
+ ]) {
140
+ f.TabTie({ firstNote: lead[a].tab, lastNote: lead[b].tab, firstIndexes: [0], lastIndexes: [0] }, letter);
141
+ }
142
+ const bend = pair(f, tuning, [
143
+ [3, 7],
144
+ [2, 5],
145
+ ], 'q');
146
+ bend.tab.addModifier(new VF.Bend([
147
+ { type: VF.Bend.UP, text: 'full' },
148
+ { type: VF.Bend.DOWN, text: '' },
149
+ ]), 0);
150
+ const tail = [pair(f, tuning, [[6, 0]], '8', -1), rest(f, '8'), rest(f, 'q')];
151
+ label(f, tail[0].tab, 'P.M. ⑥ ends', 'bottom');
152
+ guitarBar(f, 18, 466, 764, [[...lead, bend], tail], '2/4', true, 7);
153
+ f.draw();
154
+ checkPair(test, bass, [0, 2, 4, 6, 8]);
155
+ checkPair(test, [ring], [0, 8]);
156
+ checkPair(test, [...lead, bend], [0, 1, 2, 3, 4, 8]);
157
+ checkPair(test, tail, [0, 2, 4, 8]);
158
+ const mark = bend.tab.getModifiers().find((m) => m instanceof VF.Bend);
159
+ test.assert.equal(bend.tab.getPositions()[mark.getIndex()].str, 3, 'Only string three changes pitch');
160
+ }
161
+ function contemporary(f, test) {
162
+ const groups = [];
163
+ for (const [i, pitches] of [
164
+ ['c/5', 'd/5', 'e/5', 'f/5'],
165
+ ['f/5', 'e/5', 'd/5', 'c/5'],
166
+ ].entries()) {
167
+ const x = i ? 418 : 18;
168
+ const sys = system(f, x, 38, i ? 364 : 400);
169
+ const pulse = pitches.map((k) => note(f, [k], '16'));
170
+ const cluster = note(f, ['c/5', 'd/5', 'e/5', 'f/5'], 'q');
171
+ const reply = [note(f, ['b/4'], 'qr'), note(f, ['g/4'], 'q')];
172
+ f.Beam({ notes: pulse });
173
+ label(f, pulse[0], i ? 'rit.' : 'accel.');
174
+ const top = sys.addStave({ voices: [voice(f, [...pulse, cluster])] });
175
+ const lower = sys.addStave({ voices: [voice(f, reply)] });
176
+ if (!i)
177
+ for (const staff of [top, lower])
178
+ staff.addClef('treble').addTimeSignature('2/4');
179
+ groups.push({ pulse, cluster, reply });
180
+ }
181
+ f.draw();
182
+ for (const { pulse, cluster, reply } of groups) {
183
+ test.assert.deepEqual(timeline([...pulse, cluster]), [0, 1, 2, 3, 4, 8], 'Beam occupies one quarter');
184
+ test.assert.equal(cluster.checkTickContext().getX(), reply[1].checkTickContext().getX(), 'Both players meet on beat two');
185
+ test.assert.deepEqual(cluster.getKeys(), ['c/5', 'd/5', 'e/5', 'f/5'], 'White-key cluster bounds and contents');
186
+ }
187
+ }
188
+ function ensemble(f, test) {
189
+ const flute = [
190
+ ['c/5', 'q'],
191
+ ['d/5', 'q'],
192
+ ['e/5', 'q'],
193
+ ['g/5', 'h'],
194
+ ['f/5', 'q'],
195
+ ];
196
+ const cello = [
197
+ ['c/3', 'h'],
198
+ ['g/3', 'q'],
199
+ ['f/3', 'q'],
200
+ ['e/3', 'h'],
201
+ ];
202
+ const after = [
203
+ [
204
+ ['e/5', 'q'],
205
+ ['d/5', 'q'],
206
+ ],
207
+ [['c/3', 'h']],
208
+ ];
209
+ const clefs = ['treble', 'bass'];
210
+ const make = (events, i) => events.map(([k, d]) => note(f, [k], d, { clef: clefs[i] }));
211
+ const full = [make(flute, 0), make(cello, 1)];
212
+ const cue = after.map(make);
213
+ const first = system(f, 83, 12, 699), second = system(f, 83, 242, 699);
214
+ const staves = full.map((ns, i) => first
215
+ .addStave({ voices: [voice(f, ns)] })
216
+ .addClef(clefs[i])
217
+ .addTimeSignature(i ? '2/4' : '3/4'));
218
+ const names = ['Flute', 'Cello'];
219
+ staves.forEach((s, i) => s.setStaveText(names[i], VF.Modifier.Position.LEFT));
220
+ first.addConnector('singleLeft');
221
+ cue.forEach((ns, i) => {
222
+ const s = second
223
+ .addStave({ voices: [voice(f, ns)] })
224
+ .addClef(clefs[i])
225
+ .addTimeSignature('2/4');
226
+ s.setStaveText(names[i], VF.Modifier.Position.LEFT);
227
+ if (!i)
228
+ s.setSection('B', 0);
229
+ });
230
+ second.addConnector('singleLeft');
231
+ const parts = [];
232
+ for (const [i, bars] of [
233
+ [flute.slice(0, 3), flute.slice(3), after[0]],
234
+ [cello.slice(0, 1), cello.slice(1, 3), cello.slice(3), after[1]],
235
+ ].entries()) {
236
+ const length = 699 / bars.length, parsed = [];
237
+ bars.forEach((bar, j) => {
238
+ const ns = make(bar, i);
239
+ const s = system(f, 83 + j * length, 480 + i * 118, length).addStave({ voices: [voice(f, ns)] });
240
+ if (!j)
241
+ s.addClef(clefs[i])
242
+ .addTimeSignature(i ? '2/4' : '3/4')
243
+ .setStaveText(names[i] + ' part', VF.Modifier.Position.LEFT);
244
+ if (j === bars.length - 1) {
245
+ if (!i)
246
+ s.addTimeSignature('2/4');
247
+ s.setSection('B', 0);
248
+ }
249
+ parsed.push(...ns);
250
+ });
251
+ parts.push(parsed);
252
+ }
253
+ f.draw();
254
+ for (const [staff, indices] of [
255
+ [0, [3]],
256
+ [1, [1, 3]],
257
+ ]) {
258
+ for (const j of indices)
259
+ new VF.Barline(VF.Barline.type.SINGLE)
260
+ .setStave(staves[staff])
261
+ .setX(full[staff][j].getAbsoluteX() - 12)
262
+ .draw();
263
+ }
264
+ test.assert.deepEqual(timeline(full[0]), [0, 4, 8, 12, 20, 24], 'Flute local bars occupy six quarters');
265
+ test.assert.deepEqual(timeline(full[1]), [0, 8, 12, 16, 24], 'Cello local bars occupy the same six quarters');
266
+ for (const [a, b] of [
267
+ [0, 0],
268
+ [2, 1],
269
+ [3, 2],
270
+ ])
271
+ test.assert.equal(full[0][a].checkTickContext().getX(), full[1][b].checkTickContext().getX(), 'Coincident score attacks align');
272
+ for (const [i, ns] of parts.entries()) {
273
+ const signature = (n) => [n.getKeys(), n.getTicks().value()];
274
+ test.assert.deepEqual(ns.map(signature), [...full[i], ...cue[i]].map(signature), 'Extracted part preserves pitches and durations');
275
+ }
276
+ }
277
+ const studies = [
278
+ [
279
+ 'Four strokes and a golpe',
280
+ flamenco,
281
+ 312,
282
+ 'Flamenco guitar · tangos pulse',
283
+ 'On beat 1, play a–m–i bass to treble, then return with i. Accent beat 2 with a simultaneous golpe. Beat 4 is a free roll.',
284
+ 'The arrow points along the strings on the page. a = ring, m = middle, i = index, p = thumb.',
285
+ ],
286
+ [
287
+ 'Bass under an anticipation',
288
+ bossa,
289
+ 342,
290
+ 'Brazilian violão · bossa nova in 2/4',
291
+ 'Hold A through both offbeat chords. Carry the last chord over the barline. Mute the three upper strings on the next offbeat.',
292
+ 'Read the bass stems down and chords up. X is a struck, muted string. The tie adds no new attack.',
293
+ ],
294
+ [
295
+ 'Pedal string and unison bend',
296
+ metal,
297
+ 847,
298
+ 'Electric guitar · Drop D',
299
+ 'Mute only string 6 through the first attack of line two. Tap fret 12, pull to 7, hammer to 10.',
300
+ 'At the final chord, bend string 3 up a whole tone to the stationary E on string 2, then release.',
301
+ ],
302
+ [
303
+ 'Converging on beat two',
304
+ contemporary,
305
+ 279,
306
+ 'Piano and flute · metered contemporary notation',
307
+ 'The piano fans four attacks faster in bar 1 and slower in bar 2. Each group lasts one beat. Strike the white keys C5–F5 together on beat 2.',
308
+ 'Flute enters with the cluster both times. The control uses ordinary beams, tempo words and a written-out chord.',
309
+ ],
310
+ [
311
+ 'Local bars and a common cue',
312
+ ensemble,
313
+ 718,
314
+ 'Flute and cello · conductor score and separate parts',
315
+ 'In the score, count two flute bars of 3/4 against three cello bars of 2/4. Hold flute G across the last cello barline.',
316
+ 'At B both enter in 2/4. Below the two score systems, follow the same cue in the individual flute and cello parts.',
317
+ ],
318
+ ];
319
+ QUnit.module('M8 reference scores');
320
+ for (const [title, draw, height, subtitle, target, legend] of studies) {
321
+ VF.Test.runTests(title, (test) => {
322
+ const f = VF.Test.makeFactory(test, width, height);
323
+ draw(f, test);
324
+ const root = document.getElementById(test.elementId);
325
+ const svg = root.querySelector('svg');
326
+ const ink = svg.getBBox();
327
+ const left = Math.min(0, Math.floor(ink.x) - 4);
328
+ const top = Math.min(0, Math.floor(ink.y) - 4);
329
+ const w = Math.max(width, Math.ceil(ink.x + ink.width) + 4) - left;
330
+ const h = Math.max(height, Math.ceil(ink.y + ink.height) + 4) - top;
331
+ svg.setAttribute('viewBox', [left, top, w, h].join(' '));
332
+ svg.style.height = Math.ceil((h * width) / w) + 'px';
333
+ const heading = document.createElement('header');
334
+ heading.style.cssText = 'font:16px Arial,sans-serif;padding:16px 18px 0;color:#222';
335
+ const name = document.createElement('strong');
336
+ name.style.cssText = 'display:block;font-size:22px;margin-bottom:4px';
337
+ name.textContent = title;
338
+ heading.append(name, subtitle);
339
+ root.prepend(heading);
340
+ const reading = document.createElement('footer');
341
+ reading.style.cssText =
342
+ 'box-sizing:border-box;width:800px;padding:7px 18px 16px;font:15px/1.45 Arial,sans-serif;color:#222';
343
+ reading.append(target, document.createElement('br'), legend);
344
+ root.append(reading);
345
+ });
346
+ }
347
+ }
@@ -276,4 +276,92 @@ export function registerStudies() {
276
276
  x,
277
277
  });
278
278
  });
279
+ QUnit.module('M3 studies');
280
+ for (const [kind, name] of [
281
+ ['choir', 'Two verses over a skipped attack'],
282
+ ['piano', 'Slur, crescendo, ottava and pedal'],
283
+ ]) {
284
+ VF.Test.runTests(name, (options) => {
285
+ var _a, _b;
286
+ const f = VF.Test.makeFactory(options, 670, 330);
287
+ const { layout } = globalThis.makePhraseStudy(VF, f, kind);
288
+ f.draw();
289
+ const diagnostics = (_a = layout === null || layout === void 0 ? void 0 : layout.diagnostics) !== null && _a !== void 0 ? _a : [];
290
+ options.assert.deepEqual(diagnostics, [], 'No unresolved phrase collisions');
291
+ document.getElementById(options.elementId).dataset.measurement = JSON.stringify({
292
+ diagnostics,
293
+ passes: (_b = layout === null || layout === void 0 ? void 0 : layout.passes) !== null && _b !== void 0 ? _b : 0,
294
+ });
295
+ });
296
+ }
297
+ QUnit.module('M4 studies');
298
+ for (const [kind, width, height, mode, name] of [
299
+ ['choir', 740, 220, 'balanced', 'Vocal phrase on a wide system'],
300
+ ['choir', 260, 540, 'balanced', 'Vocal phrase across narrow systems'],
301
+ ['keyboard', 490, 640, 'balanced', 'Grand staff with beam, wedge and pedal'],
302
+ ['chord', 375, 300, 'balanced', 'Split chord and arpeggio on two staves'],
303
+ ['ensemble', 430, 510, 'balanced', 'Silent and returning ensemble staves'],
304
+ ['breaks', 415, 305, 'greedy', 'Greedy breaks on a short melody'],
305
+ ['breaks', 415, 305, 'balanced', 'Balanced breaks on the same melody'],
306
+ ]) {
307
+ VF.Test.runTests(name, (options) => {
308
+ var _a, _b, _c;
309
+ const f = VF.Test.makeFactory(options, width + 32, height);
310
+ const c = globalThis.makeContinuousStudy(VF, f, kind, width, mode);
311
+ f.draw();
312
+ const layout = (_b = (_a = c.sheet).getContinuousLayout) === null || _b === void 0 ? void 0 : _b.call(_a);
313
+ options.assert.ok(c.sheet.getRows().length > 0, 'At least one formatted row');
314
+ document.getElementById(options.elementId).dataset.measurement = JSON.stringify({
315
+ rows: c.sheet.getRows().map((r) => [r.systems.length, r.width, r.height]),
316
+ spans: (_c = layout === null || layout === void 0 ? void 0 : layout.fragments.map((f) => [f.id, f.part, f.x1, f.y1, f.x2, f.y2])) !== null && _c !== void 0 ? _c : [],
317
+ });
318
+ });
319
+ }
320
+ QUnit.module('M5 studies');
321
+ for (const paper of ['A4', 'Letter'])
322
+ for (const part of [false, true]) {
323
+ VF.Test.runTests((part ? 'Cello part' : 'Chamber score') + ' on ' + paper, (test) => {
324
+ const root = document.getElementById(test.elementId);
325
+ const { source, options } = globalThis.publicationStudy(part, paper);
326
+ if (VF.Publication) {
327
+ const result = new VF.Publication(source).render(root, options);
328
+ test.assert.deepEqual(result.diagnostics, [], 'No engraving or page overflow');
329
+ root.style.cssText = 'display:flex;align-items:flex-start;gap:5px;background:white;width:max-content';
330
+ for (const page of result.pages)
331
+ page.svg.style.cssText = 'width:300px;height:auto;border:1px solid #aaa';
332
+ root.dataset.measurement = JSON.stringify({ pages: result.pages.map((p) => p.systems) });
333
+ }
334
+ else {
335
+ const factory = VF.Test.makeFactory(test, 950, part ? 350 : 600);
336
+ if (part) {
337
+ source.staves = source.staves.filter((s) => s.id === 'vc');
338
+ source.continuous.groups = [];
339
+ source.continuous.spans = source.continuous.spans.filter((s) => s.id === 'cello-swell');
340
+ }
341
+ source.sheet = { width: 925, x: 10, y: 5 };
342
+ factory.EasyScore().compose(source);
343
+ factory.draw();
344
+ test.assert.ok(root.querySelector('svg'), 'Continuous reference rendered');
345
+ }
346
+ });
347
+ }
348
+ QUnit.module('M6 studies');
349
+ for (const [kind, name] of Object.entries({
350
+ kit: 'Kit groove and instrument legend',
351
+ line: 'One-line side drum',
352
+ lead: 'Harbor song over a repeated turnaround',
353
+ guitar: 'Drop D with a second-fret capo',
354
+ techniques: 'Alternating chords and playing instructions',
355
+ micro: 'Quarter tones and Persian accidentals',
356
+ spelling: 'Clarinet pickup across the bar',
357
+ meter: 'Three against two and a cadenza',
358
+ })) {
359
+ VF.Test.runTests(name, (test) => {
360
+ const factory = VF.Test.makeFactory(test, 710, { kit: 305, line: 152, lead: 345, guitar: 303, techniques: 307, micro: 280, spelling: 166, meter: 556 }[kind]);
361
+ const { notes } = globalThis.makeInstrumentStudy(VF, factory, kind);
362
+ const attacks = notes.map((n) => [n.getNoteHeadBeginX(), n.getTicks().value()]);
363
+ test.assert.ok(attacks.length && attacks.flat().every(Number.isFinite), 'Every attack has a position and duration');
364
+ document.getElementById(test.elementId).dataset.measurement = JSON.stringify({ attacks });
365
+ });
366
+ }
279
367
  }