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.
- package/README.md +2 -0
- package/build/cjs/vexflow-bravura.js +2 -2
- package/build/cjs/vexflow-bravura.js.map +1 -1
- package/build/cjs/vexflow-core.js +2 -2
- package/build/cjs/vexflow-core.js.map +1 -1
- package/build/cjs/vexflow-debug-with-tests.js +4189 -772
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +4323 -906
- package/build/cjs/vexflow-debug.js.map +1 -1
- package/build/cjs/vexflow.js +2 -2
- package/build/cjs/vexflow.js.map +1 -1
- package/build/esm/src/alternatingtremolo.js +68 -0
- package/build/esm/src/annotation.js +19 -3
- package/build/esm/src/articulation.js +5 -1
- package/build/esm/src/beam.js +13 -0
- package/build/esm/src/bend.js +57 -6
- package/build/esm/src/clef.js +3 -0
- package/build/esm/src/continuouslayout.js +681 -0
- package/build/esm/src/continuousspan.js +159 -0
- package/build/esm/src/curve.js +21 -2
- package/build/esm/src/easyscore/composition.js +13 -2
- package/build/esm/src/easyscore/policies.js +6 -3
- package/build/esm/src/engravinggeometry.js +8 -1
- package/build/esm/src/factory.js +16 -4
- package/build/esm/src/font.js +9 -1
- package/build/esm/src/fretdiagram.js +77 -0
- package/build/esm/src/guitargesture.js +33 -0
- package/build/esm/src/guitarmodifiers.js +26 -0
- package/build/esm/src/index.js +8 -0
- package/build/esm/src/instrumentprofile.js +123 -0
- package/build/esm/src/keysignature.js +23 -1
- package/build/esm/src/notationspelling.js +73 -0
- package/build/esm/src/note.js +3 -0
- package/build/esm/src/ornament.js +5 -0
- package/build/esm/src/pagebreaks.js +58 -0
- package/build/esm/src/pedalmarking.js +39 -17
- package/build/esm/src/phraselayout.js +503 -0
- package/build/esm/src/phraseribbon.js +28 -0
- package/build/esm/src/publication.js +402 -0
- package/build/esm/src/publicationview.js +114 -0
- package/build/esm/src/scorenavigation.js +172 -0
- package/build/esm/src/sheet.js +14 -2
- package/build/esm/src/stave.js +33 -16
- package/build/esm/src/stavebarline.js +5 -7
- package/build/esm/src/staveconnector.js +1 -0
- package/build/esm/src/stavehairpin.js +53 -27
- package/build/esm/src/stavenote.js +6 -1
- package/build/esm/src/stavetie.js +27 -2
- package/build/esm/src/strokes.js +4 -0
- package/build/esm/src/system.js +19 -4
- package/build/esm/src/systembreaks.js +42 -0
- package/build/esm/src/tabnote.js +6 -1
- package/build/esm/src/textbracket.js +24 -5
- package/build/esm/src/timesignature.js +15 -6
- package/build/esm/src/tuplet.js +1 -0
- package/build/esm/src/version.js +3 -3
- package/build/esm/src/vexflow.js +16 -0
- package/build/esm/src/voice.js +7 -3
- package/build/esm/tests/engraving/continuous-studies.mjs +140 -0
- package/build/esm/tests/engraving/instrument-studies.mjs +273 -0
- package/build/esm/tests/engraving/phrase-studies.mjs +63 -0
- package/build/esm/tests/engraving/publication-studies.mjs +87 -0
- package/build/esm/tests/engraving/specialist-studies.mjs +347 -0
- package/build/esm/tests/engraving/studies.mjs +88 -0
- package/build/esm/tests/node/continuous-score-tests.mjs +282 -0
- package/build/esm/tests/node/instrument-profile-tests.mjs +224 -0
- package/build/esm/tests/node/phrase-layout-tests.mjs +281 -0
- package/build/esm/tests/node/publication-tests.mjs +219 -0
- package/build/esm/tools/easyscore-structure.mjs +1 -1
- package/build/esm/tools/explorer/catalog/entries.mjs +2 -1
- package/build/esm/tools/explorer/catalog/expression.mjs +14 -9
- package/build/esm/tools/explorer/catalog/guitar.mjs +238 -0
- package/build/esm/tools/explorer/catalog/layout.mjs +8 -6
- package/build/esm/tools/explorer/catalog/notes.mjs +16 -14
- package/build/esm/tools/explorer/catalog/staves.mjs +12 -6
- package/build/esm/tools/explorer/catalog/strings.mjs +10 -7
- package/build/types/src/alternatingtremolo.d.ts +13 -0
- package/build/types/src/annotation.d.ts +9 -0
- package/build/types/src/articulation.d.ts +3 -0
- package/build/types/src/beam.d.ts +2 -0
- package/build/types/src/bend.d.ts +8 -0
- package/build/types/src/clef.d.ts +3 -0
- package/build/types/src/continuouslayout.d.ts +103 -0
- package/build/types/src/continuousspan.d.ts +60 -0
- package/build/types/src/curve.d.ts +11 -0
- package/build/types/src/easyscore/composition.d.ts +8 -0
- package/build/types/src/easyscore/policies.d.ts +1 -1
- package/build/types/src/fretdiagram.d.ts +23 -0
- package/build/types/src/guitargesture.d.ts +26 -0
- package/build/types/src/guitarmodifiers.d.ts +3 -0
- package/build/types/src/index.d.ts +10 -0
- package/build/types/src/instrumentprofile.d.ts +124 -0
- package/build/types/src/keysignature.d.ts +9 -0
- package/build/types/src/notationspelling.d.ts +25 -0
- package/build/types/src/note.d.ts +15 -0
- package/build/types/src/ornament.d.ts +3 -1
- package/build/types/src/pagebreaks.d.ts +26 -0
- package/build/types/src/pedalmarking.d.ts +9 -0
- package/build/types/src/phraselayout.d.ts +87 -0
- package/build/types/src/phraseribbon.d.ts +7 -0
- package/build/types/src/publication.d.ts +61 -0
- package/build/types/src/publicationview.d.ts +27 -0
- package/build/types/src/scorenavigation.d.ts +33 -0
- package/build/types/src/sheet.d.ts +5 -0
- package/build/types/src/stave.d.ts +13 -0
- package/build/types/src/stavehairpin.d.ts +18 -0
- package/build/types/src/stavetie.d.ts +5 -0
- package/build/types/src/system.d.ts +8 -1
- package/build/types/src/systembreaks.d.ts +9 -0
- package/build/types/src/textbracket.d.ts +7 -0
- package/build/types/src/timesignature.d.ts +4 -0
- package/build/types/src/vexflow.d.ts +16 -0
- package/build/types/src/voice.d.ts +2 -0
- package/changelog/CHANGELOG.md +8 -0
- package/package.json +9 -2
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import assert from 'node:assert/strict';
|
|
11
|
+
import test from 'node:test';
|
|
12
|
+
import { readFile } from 'node:fs/promises';
|
|
13
|
+
import puppeteer from 'puppeteer';
|
|
14
|
+
import { createCanvas, registerFont } from 'canvas';
|
|
15
|
+
import { makeContinuousStudy } from '../engraving/continuous-studies.mjs';
|
|
16
|
+
const VF = await import(new URL('../../build/esm/entry/vexflow-core.js', import.meta.url));
|
|
17
|
+
for (const family of ['Bravura', 'Academico']) {
|
|
18
|
+
const name = family.toLowerCase();
|
|
19
|
+
registerFont(new URL('../../node_modules/@vexflow-fonts/' + name + '/' + name + '.otf', import.meta.url).pathname, {
|
|
20
|
+
family,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
VF.Element.setTextMeasurementCanvas(createCanvas(1, 1));
|
|
24
|
+
function factory() {
|
|
25
|
+
const canvas = createCanvas(960, 1100), ctx = canvas.getContext('2d');
|
|
26
|
+
const f = new VF.Factory({ renderer: { elementId: null, width: 960, height: 1100 } }).setContext(new VF.CanvasContext(ctx));
|
|
27
|
+
return { f, ctx, canvas };
|
|
28
|
+
}
|
|
29
|
+
function scene(kind, width, mode) {
|
|
30
|
+
const { f, ctx, canvas } = factory(), c = makeContinuousStudy(VF, f, kind, width, mode), l = c.sheet.getContinuousLayout();
|
|
31
|
+
const frame = (w) => {
|
|
32
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
33
|
+
c.sheet.setWidth(w);
|
|
34
|
+
f.draw({ retain: true });
|
|
35
|
+
return {
|
|
36
|
+
rows: l.rows.map((r) => ({ m: r.measures, v: r.visibleStaves, w: r.width, h: r.height, rest: r.restGroups })),
|
|
37
|
+
fragments: structuredClone(l.fragments),
|
|
38
|
+
diagnostics: structuredClone(l.diagnostics),
|
|
39
|
+
pixels: canvas.toBuffer(),
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
return { f, c, l, frame };
|
|
43
|
+
}
|
|
44
|
+
test('vocal phrase retains IDs; three fragments reunite at the original width with identical pixels', () => {
|
|
45
|
+
const { c, l, frame } = scene('choir', 740), head = c.getNote('v00');
|
|
46
|
+
const wide = frame(740);
|
|
47
|
+
assert.equal(wide.rows.length, 1);
|
|
48
|
+
const narrow = frame(260);
|
|
49
|
+
assert.deepEqual(narrow.rows.map((r) => r.m), [
|
|
50
|
+
[1, 2],
|
|
51
|
+
[3, 4],
|
|
52
|
+
[5, 6],
|
|
53
|
+
]);
|
|
54
|
+
for (const id of ['sung-word', 'phrase'])
|
|
55
|
+
assert.deepEqual(l.fragments.filter((f) => f.id === id).map((f) => f.part), ['first', 'middle', 'last']);
|
|
56
|
+
const endSigns = c.staves[1][0].getModifiers(VF.StaveModifier.Position.END, VF.KeySignature.CATEGORY);
|
|
57
|
+
assert.equal(endSigns.length, 1);
|
|
58
|
+
assert.deepEqual(narrow.diagnostics, []);
|
|
59
|
+
assert.equal(head, c.getNote('v00'));
|
|
60
|
+
assert.deepEqual(frame(740), wide);
|
|
61
|
+
assert.equal(c.staves[1][0].getModifiers(VF.StaveModifier.Position.END, VF.KeySignature.CATEGORY).length, 0);
|
|
62
|
+
});
|
|
63
|
+
test('balanced width avoids the greedy last-measure row on the same seven measures', () => {
|
|
64
|
+
const greedy = scene('breaks', 415, 'greedy').frame(415), balanced = scene('breaks', 415, 'balanced').frame(415);
|
|
65
|
+
assert.deepEqual(greedy.rows.map((r) => r.m.length), [6, 1]);
|
|
66
|
+
assert.deepEqual(balanced.rows.map((r) => r.m.length), [3, 4]);
|
|
67
|
+
assert.deepEqual(balanced.rows.flatMap((r) => r.m), greedy.rows.flatMap((r) => r.m));
|
|
68
|
+
});
|
|
69
|
+
test('grand-staff drawing preserves cross-staff stem joins and wedge aperture across redraw', () => {
|
|
70
|
+
const { c, frame } = scene('keyboard', 490);
|
|
71
|
+
const wide = frame(490), n = c.getNote('cross'), staff = c.staves[0][1], beam = n.getBeam();
|
|
72
|
+
assert.equal(n.getStave(), staff);
|
|
73
|
+
assert.ok(beam.getStripBounds().every((b) => Number.isFinite(b.y)));
|
|
74
|
+
const parts = wide.fragments.filter((f) => f.kind === 'crescendo');
|
|
75
|
+
assert.deepEqual(parts.map((f) => f.part), ['first', 'last']);
|
|
76
|
+
assert.equal(parts[0].progress[1], parts[1].progress[0]);
|
|
77
|
+
assert.equal(parts[0].progress[0], 0);
|
|
78
|
+
assert.equal(parts[1].progress[1], 1);
|
|
79
|
+
assert.deepEqual(c.staves[0].map((s) => s.getY()), c.staves[1].map((s) => s.getY()));
|
|
80
|
+
frame(300);
|
|
81
|
+
assert.deepEqual(frame(490), wide);
|
|
82
|
+
assert.equal(n.getStave(), staff);
|
|
83
|
+
});
|
|
84
|
+
test('silent staves return with their names and a compressed run retains its measure identities', () => {
|
|
85
|
+
const { c, frame } = scene('ensemble', 430);
|
|
86
|
+
const { rows, diagnostics } = frame(430);
|
|
87
|
+
assert.deepEqual(diagnostics, []);
|
|
88
|
+
assert.deepEqual(rows.map((r) => r.v), [['fl'], ['fl', 'vc']]);
|
|
89
|
+
assert.deepEqual(rows[0].rest, [[2, 3, 4]]);
|
|
90
|
+
assert.equal(c.notes.length, 6);
|
|
91
|
+
assert.ok(c.notes[2][1][0][0].isRest());
|
|
92
|
+
assert.equal(c.staves[4][1].getModifiers()[0].getType(), VF.Barline.type.REPEAT_BEGIN);
|
|
93
|
+
assert.equal(c.staves[5][0].getModifiers()[1].getType(), VF.Barline.type.REPEAT_END);
|
|
94
|
+
});
|
|
95
|
+
function spec(count, continuous, notes = (i) => [{ id: 'n' + i, note: { keys: ['c/5'], duration: 'w' } }]) {
|
|
96
|
+
return {
|
|
97
|
+
staves: [{ id: 'staff', measures: Array.from({ length: count }, (_, i) => ({ voices: [{ notes: notes(i) }] })) }],
|
|
98
|
+
continuous,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
test('hard keeps overflow together and forced breaks win over spare space', () => {
|
|
102
|
+
const { f } = factory();
|
|
103
|
+
const c = f.EasyScore().compose(spec(4, {
|
|
104
|
+
boundaries: [
|
|
105
|
+
{ measure: 2, breakBefore: 'keep' },
|
|
106
|
+
{ measure: 3, breakBefore: 'force' },
|
|
107
|
+
{ measure: 4, breakBefore: 'keep' },
|
|
108
|
+
],
|
|
109
|
+
}));
|
|
110
|
+
const l = c.sheet.getContinuousLayout();
|
|
111
|
+
c.sheet.setWidth(12).format();
|
|
112
|
+
assert.deepEqual(l.rows.map((r) => r.measures), [
|
|
113
|
+
[1, 2],
|
|
114
|
+
[3, 4],
|
|
115
|
+
]);
|
|
116
|
+
assert.deepEqual(l.diagnostics.map((d) => d.code), ['RowOverflow', 'RowOverflow']);
|
|
117
|
+
assert.ok(l.rows.every((r) => r.overflow > 0));
|
|
118
|
+
c.sheet.setWidth(800).format();
|
|
119
|
+
assert.deepEqual(l.rows.map((r) => r.measures), [
|
|
120
|
+
[1, 2],
|
|
121
|
+
[3, 4],
|
|
122
|
+
]);
|
|
123
|
+
assert.deepEqual(l.diagnostics, []);
|
|
124
|
+
});
|
|
125
|
+
test('span families retain the source anchors and continuous parameter at first, middle and final fragments', () => {
|
|
126
|
+
for (const kind of [
|
|
127
|
+
'tie',
|
|
128
|
+
'slur',
|
|
129
|
+
'crescendo',
|
|
130
|
+
'diminuendo',
|
|
131
|
+
'pedal',
|
|
132
|
+
'lyric',
|
|
133
|
+
'hyphen',
|
|
134
|
+
'volta',
|
|
135
|
+
'ottava',
|
|
136
|
+
'trill',
|
|
137
|
+
'tuplet',
|
|
138
|
+
]) {
|
|
139
|
+
const { f } = factory(), c = f.EasyScore().compose(spec(3, {
|
|
140
|
+
spans: [{ id: 's', kind, from: 'n0', to: 'n2' }],
|
|
141
|
+
boundaries: [
|
|
142
|
+
{ measure: 2, breakBefore: 'force' },
|
|
143
|
+
{ measure: 3, breakBefore: 'force' },
|
|
144
|
+
],
|
|
145
|
+
}));
|
|
146
|
+
f.draw({ retain: true });
|
|
147
|
+
const l = c.sheet.getContinuousLayout(), fs = l.fragments;
|
|
148
|
+
assert.deepEqual(l.diagnostics, [], kind);
|
|
149
|
+
assert.deepEqual(fs.map((f) => f.part), ['first', 'middle', 'last'], kind);
|
|
150
|
+
assert.ok(fs.every((f) => f.id === 's' && f.x1 < f.x2 && Number.isFinite(f.y1 + f.y2)));
|
|
151
|
+
for (let i = 1; i < fs.length; i++)
|
|
152
|
+
assert.equal(fs[i - 1].progress[1], fs[i].progress[0]);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
test('boundary key, clef and meter move together; explicit signs survive and returned tied accidentals reflow', () => {
|
|
156
|
+
const { f } = factory(), es = f.EasyScore();
|
|
157
|
+
const s = spec(2, { spans: [{ id: 'tie', kind: 'tie', from: 'n0', to: 'n1' }] }, (i) => [
|
|
158
|
+
{ id: 'n' + i, note: { keys: ['f#/4'], duration: 'w' } },
|
|
159
|
+
]);
|
|
160
|
+
s.accidentals = 'key-aware';
|
|
161
|
+
const c = es.compose(s), n = c.getNote('n1'), l = c.sheet.getContinuousLayout();
|
|
162
|
+
const mods = () => n.getModifiers().filter((m) => m instanceof VF.Accidental);
|
|
163
|
+
c.sheet.setWidth(680).format();
|
|
164
|
+
assert.equal(mods().length, 0);
|
|
165
|
+
c.sheet.setWidth(128).format();
|
|
166
|
+
assert.equal(l.rows.length, 2);
|
|
167
|
+
assert.equal(mods().length, 1);
|
|
168
|
+
const explicit = f.Accidental({ type: 'n' }).setAsCautionary();
|
|
169
|
+
n.addModifier(explicit, 0);
|
|
170
|
+
c.sheet.setWidth(680).format();
|
|
171
|
+
assert.deepEqual(mods(), [explicit]);
|
|
172
|
+
const other = factory().f.EasyScore();
|
|
173
|
+
const boundary = spec(2, {});
|
|
174
|
+
boundary.staves[0].measures[0].key = 'D';
|
|
175
|
+
Object.assign(boundary.staves[0].measures[1], { key: 'F', clef: 'bass', time: '2/2' });
|
|
176
|
+
const b = other.compose(boundary);
|
|
177
|
+
b.sheet.setWidth(145).format();
|
|
178
|
+
const signs = (pos) => b.staves[0][0].getModifiers(pos).map((m) => m.getCategory());
|
|
179
|
+
for (const cat of [VF.Clef.CATEGORY, VF.KeySignature.CATEGORY, VF.TimeSignature.CATEGORY])
|
|
180
|
+
assert.ok(signs(VF.StaveModifier.Position.END).includes(cat), cat);
|
|
181
|
+
b.sheet.setWidth(800).format();
|
|
182
|
+
assert.deepEqual(signs(VF.StaveModifier.Position.END), [VF.Barline.CATEGORY]);
|
|
183
|
+
});
|
|
184
|
+
test('structural marks interrupt rest compression; navigation targets and span heads validate atomically', () => {
|
|
185
|
+
const { f } = factory(), es = f.EasyScore(), rest = () => [{ note: { keys: ['b/4'], duration: 'wr' } }];
|
|
186
|
+
const c = es.compose(spec(7, {
|
|
187
|
+
compressRests: true,
|
|
188
|
+
boundaries: [
|
|
189
|
+
{ measure: 4, navigation: { kind: 'segno', id: 'sign' } },
|
|
190
|
+
{ measure: 7, navigation: { kind: 'dalSegno', target: 'sign' } },
|
|
191
|
+
],
|
|
192
|
+
}, rest));
|
|
193
|
+
c.sheet.setWidth(850).format();
|
|
194
|
+
assert.deepEqual(c.sheet.getContinuousLayout().rows.flatMap((r) => r.restGroups), [
|
|
195
|
+
[2, 3],
|
|
196
|
+
[5, 6],
|
|
197
|
+
]);
|
|
198
|
+
for (const config of [
|
|
199
|
+
{ spans: [{ id: 's', kind: 'tie', from: 'n0', to: 'n1', toHead: 5 }] },
|
|
200
|
+
{ boundaries: [{ measure: 1, navigation: { kind: 'toCoda', target: 'missing' } }] },
|
|
201
|
+
{ boundaries: [{ measure: 3 }] },
|
|
202
|
+
]) {
|
|
203
|
+
const fresh = factory().f.EasyScore();
|
|
204
|
+
assert.throws(() => fresh.compose(spec(2, config)));
|
|
205
|
+
assert.equal(fresh.getElement('n0'), undefined);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
test('the shared stem and arpeggio follow the two native heads at each width', () => {
|
|
209
|
+
const { c, frame } = scene('chord', 375);
|
|
210
|
+
const wide = frame(375);
|
|
211
|
+
assert.deepEqual(wide.diagnostics, []);
|
|
212
|
+
const top = c.getNote('rh00'), bottom = c.getNote('lh00'), stroke = top.getModifiers().find((m) => m instanceof VF.Stroke);
|
|
213
|
+
assert.equal(top.getStemX(), bottom.getStemX());
|
|
214
|
+
const ink = stroke.getBoundingBox();
|
|
215
|
+
assert.ok(ink.y <= top.getYs()[0] && ink.y + ink.h >= bottom.getYs()[0]);
|
|
216
|
+
frame(160);
|
|
217
|
+
assert.deepEqual(frame(375), wide);
|
|
218
|
+
});
|
|
219
|
+
test('instrument changes survive hiding and reflow and the new full name reserves row-start width', () => {
|
|
220
|
+
const s = spec(3, { boundaries: [{ measure: 2, breakBefore: 'force' }] });
|
|
221
|
+
s.staves[0].name = 'Flute';
|
|
222
|
+
s.staves[0].shortName = 'Fl.';
|
|
223
|
+
s.staves[0].measures[1].instrument = { name: 'Bass clarinet in B-flat', shortName: 'B. cl.' };
|
|
224
|
+
const c = factory().f.EasyScore().compose(s);
|
|
225
|
+
c.sheet.setWidth(165).format();
|
|
226
|
+
assert.ok(c.staves[1][0].getX() > c.staves[0][0].getX() + 30);
|
|
227
|
+
assert.ok(c.staves[2][0].getX() < c.staves[1][0].getX());
|
|
228
|
+
});
|
|
229
|
+
test('choir, piano and ensemble reflow in browser SVG and Canvas with two font pairs', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
230
|
+
const browser = yield puppeteer.launch({ headless: true, args: process.env.CI ? ['--no-sandbox'] : [] });
|
|
231
|
+
try {
|
|
232
|
+
const page = yield browser.newPage();
|
|
233
|
+
yield page.setContent('<body></body>');
|
|
234
|
+
yield page.addScriptTag({ path: new URL('../../build/cjs/vexflow-debug.js', import.meta.url).pathname });
|
|
235
|
+
yield page.addScriptTag({ content: 'window.makeContinuousStudy=' + makeContinuousStudy.toString() });
|
|
236
|
+
for (const family of ['Bravura', 'Academico', 'Petaluma', 'Petaluma Script']) {
|
|
237
|
+
const name = family.toLowerCase().replaceAll(' ', '');
|
|
238
|
+
const data = yield readFile(new URL('../../node_modules/@vexflow-fonts/' + name + '/' + name + '.woff2', import.meta.url));
|
|
239
|
+
yield page.evaluate((family, data) => __awaiter(void 0, void 0, void 0, function* () { return document.fonts.add(yield new FontFace(family, 'url(data:font/woff2;base64,' + data + ')').load()); }), family, data.toString('base64'));
|
|
240
|
+
}
|
|
241
|
+
for (const backend of ['svg', 'canvas'])
|
|
242
|
+
for (const kind of ['choir', 'keyboard', 'ensemble'])
|
|
243
|
+
for (const family of ['Bravura', 'Petaluma']) {
|
|
244
|
+
const output = yield page.evaluate(({ backend, kind, family }) => {
|
|
245
|
+
const VF = window.VexFlow;
|
|
246
|
+
VF.setFonts(family, family === 'Bravura' ? 'Academico' : 'Petaluma Script');
|
|
247
|
+
const target = document.createElement(backend === 'svg' ? 'div' : 'canvas');
|
|
248
|
+
target.id = 'study';
|
|
249
|
+
document.body.replaceChildren(target);
|
|
250
|
+
const f = new VF.Factory({ renderer: { elementId: 'study', width: 850, height: 1200 } });
|
|
251
|
+
const c = window.makeContinuousStudy(VF, f, kind, 740), layout = c.sheet.getContinuousLayout();
|
|
252
|
+
return [740, 270, 740].map((w) => {
|
|
253
|
+
f.getContext().clear();
|
|
254
|
+
c.sheet.setWidth(w);
|
|
255
|
+
f.draw({ retain: true });
|
|
256
|
+
const geometry = layout.rows.map((r) => [r.measures, r.visibleStaves, r.height, r.width]);
|
|
257
|
+
const drawn = backend === 'svg'
|
|
258
|
+
? target.querySelectorAll('path,text').length > 0
|
|
259
|
+
: target
|
|
260
|
+
.getContext('2d')
|
|
261
|
+
.getImageData(0, 0, 850, 1200)
|
|
262
|
+
.data.some((v, i) => i % 4 === 3 && v > 0);
|
|
263
|
+
return {
|
|
264
|
+
geometry,
|
|
265
|
+
fragments: structuredClone(layout.fragments),
|
|
266
|
+
diagnostics: structuredClone(layout.diagnostics),
|
|
267
|
+
drawn,
|
|
268
|
+
};
|
|
269
|
+
});
|
|
270
|
+
}, { backend, kind, family });
|
|
271
|
+
assert.deepEqual(output[0], output[2], backend + ' ' + kind + ' ' + family);
|
|
272
|
+
assert.notDeepEqual(output[0].geometry, output[1].geometry);
|
|
273
|
+
for (const frame of output) {
|
|
274
|
+
assert.ok(frame.drawn);
|
|
275
|
+
assert.deepEqual(frame.diagnostics, [], backend + ' ' + kind + ' ' + family);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
finally {
|
|
280
|
+
yield browser.close();
|
|
281
|
+
}
|
|
282
|
+
}));
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import assert from 'node:assert/strict';
|
|
11
|
+
import { test } from 'node:test';
|
|
12
|
+
import puppeteer from 'puppeteer';
|
|
13
|
+
import { makeInstrumentStudy } from '../engraving/instrument-studies.mjs';
|
|
14
|
+
test('instrument studies and score construction', (t) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const browser = yield puppeteer.launch({ headless: true, args: process.env.CI ? ['--no-sandbox'] : [] });
|
|
16
|
+
try {
|
|
17
|
+
const page = yield browser.newPage();
|
|
18
|
+
yield page.setContent('<main id="music"></main>');
|
|
19
|
+
yield page.addScriptTag({ path: 'build/cjs/vexflow-debug.js' });
|
|
20
|
+
yield page.addScriptTag({ content: 'window.makeStudy=' + makeInstrumentStudy });
|
|
21
|
+
yield page.evaluate(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
const VF = window.VexFlow;
|
|
23
|
+
yield VF.loadFonts('Bravura', 'Academico');
|
|
24
|
+
VF.setFonts('Bravura', 'Academico');
|
|
25
|
+
window.study = (kind) => {
|
|
26
|
+
document.querySelector('main').replaceChildren();
|
|
27
|
+
const f = new VF.Factory({
|
|
28
|
+
renderer: { elementId: 'music', width: 710, height: 530, backend: VF.Renderer.Backends.SVG },
|
|
29
|
+
});
|
|
30
|
+
return makeStudy(VF, f, kind);
|
|
31
|
+
};
|
|
32
|
+
}));
|
|
33
|
+
yield t.test('percussion keeps mixed head identities and stems in native notes, compositions and exported parts', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
const result = yield page.evaluate(() => {
|
|
35
|
+
const VF = VexFlow, kit = new VF.PercussionMap();
|
|
36
|
+
const attack = kit.note(['snare', 'hat'], 'q');
|
|
37
|
+
const native = new VF.StaveNote(attack);
|
|
38
|
+
const { notes } = study('kit');
|
|
39
|
+
const name = document.getElementById('vf-' + notes[2].getAttribute('id')).getAttribute('aria-label');
|
|
40
|
+
const source = {
|
|
41
|
+
staves: [
|
|
42
|
+
{
|
|
43
|
+
id: 'drums',
|
|
44
|
+
clef: 'percussion',
|
|
45
|
+
measures: [
|
|
46
|
+
{
|
|
47
|
+
voices: [
|
|
48
|
+
{ notes: [{ id: 'backbeat', note: attack }, kit.note(['kick'], 'q'), kit.note(['hat'], 'h')] },
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
continuous: {},
|
|
55
|
+
};
|
|
56
|
+
const result = new VF.Publication(source).render(document.querySelector('main'), { staves: ['drums'] });
|
|
57
|
+
const metadata = JSON.parse(result.pages[0].svg.querySelector('metadata').textContent);
|
|
58
|
+
const side = study('line').notes;
|
|
59
|
+
return {
|
|
60
|
+
name,
|
|
61
|
+
positions: native.getKeyProps().map((p) => p.line),
|
|
62
|
+
different: native.noteHeads[0].getText() !== native.noteHeads[1].getText(),
|
|
63
|
+
exported: metadata.events.find((e) => e.id === 'backbeat').notation,
|
|
64
|
+
kick: kit.note(['kick'], 'q').stemDirection,
|
|
65
|
+
override: kit.note(['kick'], 'q', 'up').stemDirection,
|
|
66
|
+
barHeight: side[0].checkStave().getBarlineBounds().botY - side[0].checkStave().getBarlineBounds().topY,
|
|
67
|
+
side: side.every((n) => n.getYs()[0] === n.checkStave().getYForLine(2)),
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
assert.deepEqual(result.positions, [3.5, 5.5]);
|
|
71
|
+
assert.equal(result.different, true);
|
|
72
|
+
assert.equal(result.side, true);
|
|
73
|
+
assert.equal(result.barHeight, 21);
|
|
74
|
+
assert.equal(result.kick, -1);
|
|
75
|
+
assert.equal(result.override, 1);
|
|
76
|
+
assert.equal(result.name, 'Snare drum, Closed hi-hat');
|
|
77
|
+
assert.deepEqual(result.exported.map((e) => [e.id, e.index]), [
|
|
78
|
+
['snare', 0],
|
|
79
|
+
['hat', 1],
|
|
80
|
+
]);
|
|
81
|
+
}));
|
|
82
|
+
yield t.test('tremolo divides written duration while retaining strokes, and rejects unrelated endpoints', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
+
const data = yield page.evaluate(() => {
|
|
84
|
+
const VF = VexFlow, { notes } = study('techniques');
|
|
85
|
+
const bad = new VF.AlternatingTremolo(notes[0], notes[2], 3);
|
|
86
|
+
let rejected = false;
|
|
87
|
+
try {
|
|
88
|
+
bad.draw();
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
rejected = e.code === 'BadArguments';
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
written: notes[0].getDuration(),
|
|
95
|
+
total: (notes[0].getTicks().value() + notes[1].getTicks().value()) / VF.RESOLUTION,
|
|
96
|
+
strokes: document.querySelectorAll('.vf-alternating-tremolo path').length,
|
|
97
|
+
rejected,
|
|
98
|
+
identities: notes.slice(2).flatMap((n) => n.notation.map((e) => e.id)),
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
assert.equal(data.written, 'h');
|
|
102
|
+
assert.equal(data.total, 0.5);
|
|
103
|
+
assert.equal(data.strokes, 3);
|
|
104
|
+
assert.equal(data.rejected, true);
|
|
105
|
+
assert.deepEqual(data.identities, ['harmonic', 'down-bow', 'pedal', 'finger-2', 'breath', 'sons-etouffes']);
|
|
106
|
+
}));
|
|
107
|
+
yield t.test('tuning and capo preserve displayed frets, and the diagram encodes open, muted and barred strings', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
108
|
+
const result = yield page.evaluate(() => {
|
|
109
|
+
const VF = VexFlow;
|
|
110
|
+
const { notes } = study('guitar');
|
|
111
|
+
const frame = document.querySelector('.vf-fret-diagram');
|
|
112
|
+
const guitar = new VF.FrettedInstrument('dropd', 2);
|
|
113
|
+
const pair = guitar.attack([
|
|
114
|
+
{ str: 6, fret: 0 },
|
|
115
|
+
{ str: 2, fret: 3 },
|
|
116
|
+
], 'q');
|
|
117
|
+
return {
|
|
118
|
+
keys: pair.note.keys,
|
|
119
|
+
frets: pair.tab.positions.map((p) => p.fret),
|
|
120
|
+
first: notes[0].getKeys()[0],
|
|
121
|
+
frame: frame.getAttribute('aria-label'),
|
|
122
|
+
ink: frame.getBBox().width,
|
|
123
|
+
bends: document.querySelectorAll('.vf-tabnote').length,
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
assert.deepEqual(result.keys, ['E/3', 'E/5']);
|
|
127
|
+
assert.deepEqual(result.frets, [0, 3]);
|
|
128
|
+
assert.equal(result.first, 'E/3');
|
|
129
|
+
assert.ok(result.ink > 30);
|
|
130
|
+
assert.match(result.frame, /x, 0, 2, 2, 2, 0, barre at fret 2/);
|
|
131
|
+
assert.ok(result.bends >= 4);
|
|
132
|
+
}));
|
|
133
|
+
yield t.test('two microtonal conventions preserve order, cancellation and octave-specific memory', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
134
|
+
const data = yield page.evaluate(() => {
|
|
135
|
+
const VF = VexFlow;
|
|
136
|
+
study('micro');
|
|
137
|
+
const signatures = [...document.querySelectorAll('.vf-keysignature')].map((g) => g.textContent).filter(Boolean);
|
|
138
|
+
const state = new VF.WrittenAccidentalState({ g: 'o' });
|
|
139
|
+
const sequence = [
|
|
140
|
+
state.sign('g/4', 'o'),
|
|
141
|
+
state.sign('g/4', 'n'),
|
|
142
|
+
state.sign('g/5', 'o'),
|
|
143
|
+
state.sign('g/4', 'n', true),
|
|
144
|
+
];
|
|
145
|
+
state.reset();
|
|
146
|
+
sequence.push(state.sign('g/4', 'o'));
|
|
147
|
+
return {
|
|
148
|
+
sequence,
|
|
149
|
+
signatures,
|
|
150
|
+
expected: [
|
|
151
|
+
VF.Glyphs.accidentalQuarterToneFlatStein + VF.Glyphs.accidentalQuarterToneSharpStein,
|
|
152
|
+
VF.Glyphs.accidentalKoron + VF.Glyphs.accidentalSori,
|
|
153
|
+
],
|
|
154
|
+
};
|
|
155
|
+
});
|
|
156
|
+
assert.deepEqual(data.sequence, [null, 'n', null, 'n', null]);
|
|
157
|
+
assert.deepEqual(data.signatures, data.expected);
|
|
158
|
+
}));
|
|
159
|
+
yield t.test('shared onsets stay aligned across staff-local barlines; a free cadenza permits a shorter sounding voice', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
160
|
+
const data = yield page.evaluate(() => {
|
|
161
|
+
const { notes, bars, freeVoices } = study('meter');
|
|
162
|
+
return {
|
|
163
|
+
shared: notes.slice(0, 6).map((n, i) => n.getAbsoluteX() - notes[i + 6].getAbsoluteX()),
|
|
164
|
+
bars: bars.map(({ bar, before, after }) => bar.getX() > before.getAbsoluteX() && bar.getX() < after.getAbsoluteX()),
|
|
165
|
+
free: freeVoices.map((v) => v.getTicksUsed().value()),
|
|
166
|
+
silent: freeVoices[1].getTickables().at(-1) instanceof VexFlow.GhostNote,
|
|
167
|
+
};
|
|
168
|
+
});
|
|
169
|
+
assert.deepEqual(data.shared, [0, 0, 0, 0, 0, 0]);
|
|
170
|
+
assert.deepEqual(data.bars, [true, true, true]);
|
|
171
|
+
assert.equal(data.free[0], data.free[1]);
|
|
172
|
+
assert.equal(data.silent, true);
|
|
173
|
+
}));
|
|
174
|
+
yield t.test('pitch, key and rhythm changes are opt-in and preserve explicit spelling', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
175
|
+
const data = yield page.evaluate(() => {
|
|
176
|
+
const VF = VexFlow, S = VF.NotationSpelling;
|
|
177
|
+
const invalid = (fn) => {
|
|
178
|
+
try {
|
|
179
|
+
fn();
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
catch (e) {
|
|
183
|
+
return e.code === 'BadArguments';
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
const source = ['b/4', 'db/5'];
|
|
187
|
+
const lead = study('lead').notes;
|
|
188
|
+
return {
|
|
189
|
+
source,
|
|
190
|
+
pitches: source.map((k) => S.transpose(k, 2, 1)),
|
|
191
|
+
enharmonic: S.transpose('c/4', 1, 1),
|
|
192
|
+
key: S.transposeKey('Fm', 2, 1),
|
|
193
|
+
parts: S.rhythm(48, 40, [80, 64, 80]),
|
|
194
|
+
rests: S.rhythm(10, 24, [16, 32], true),
|
|
195
|
+
lead: lead.flatMap((n) => n.notation).length,
|
|
196
|
+
pickup: study('spelling').notes.map((n) => n.getDuration()),
|
|
197
|
+
rejected: [
|
|
198
|
+
invalid(() => new VF.PercussionMap().note(['missing'], 'q')),
|
|
199
|
+
invalid(() => new VF.FrettedInstrument().attack([{ str: 1, fret: -1 }], 'q')),
|
|
200
|
+
invalid(() => new VF.FretDiagram({ frets: ['x', 9] })),
|
|
201
|
+
invalid(() => S.transpose('c/4', 9, 0)),
|
|
202
|
+
invalid(() => S.rhythm(1, 0)),
|
|
203
|
+
],
|
|
204
|
+
};
|
|
205
|
+
});
|
|
206
|
+
assert.deepEqual(data.source, ['b/4', 'db/5']);
|
|
207
|
+
assert.deepEqual(data.pitches, ['c#/5', 'eb/5']);
|
|
208
|
+
assert.equal(data.enharmonic, 'db/4');
|
|
209
|
+
assert.equal(data.key, 'Gm');
|
|
210
|
+
assert.deepEqual(data.parts.map((p) => [p.start, p.duration, p.tieNext]), [
|
|
211
|
+
[48, '4', true],
|
|
212
|
+
[64, '4', true],
|
|
213
|
+
[80, '8', false],
|
|
214
|
+
]);
|
|
215
|
+
assert.ok(data.rests.every((r) => !r.tieNext));
|
|
216
|
+
assert.equal(data.lead, 4);
|
|
217
|
+
assert.equal(data.pickup.length, 5);
|
|
218
|
+
assert.ok(data.rejected.every(Boolean));
|
|
219
|
+
}));
|
|
220
|
+
}
|
|
221
|
+
finally {
|
|
222
|
+
yield browser.close();
|
|
223
|
+
}
|
|
224
|
+
}));
|