vexflow 5.2.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 +6502 -1708
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +5622 -1618
- 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/accidental.js +10 -3
- package/build/esm/src/alternatingtremolo.js +68 -0
- package/build/esm/src/annotation.js +19 -3
- package/build/esm/src/articulation.js +28 -6
- package/build/esm/src/beam.js +171 -28
- package/build/esm/src/bend.js +79 -23
- 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 +48 -55
- package/build/esm/src/dot.js +13 -4
- package/build/esm/src/easyscore/composition.js +52 -2
- package/build/esm/src/easyscore/policies.js +39 -8
- package/build/esm/src/element.js +4 -0
- package/build/esm/src/engravinggeometry.js +157 -0
- package/build/esm/src/engravingprofile.js +44 -0
- package/build/esm/src/factory.js +31 -11
- package/build/esm/src/font.js +9 -1
- package/build/esm/src/formatter.js +9 -1
- package/build/esm/src/fretdiagram.js +77 -0
- package/build/esm/src/gracenote.js +43 -38
- package/build/esm/src/gracenotegroup.js +53 -56
- package/build/esm/src/guitargesture.js +33 -0
- package/build/esm/src/guitarmodifiers.js +26 -0
- package/build/esm/src/index.js +10 -0
- package/build/esm/src/instrumentprofile.js +123 -0
- package/build/esm/src/keysignature.js +24 -2
- package/build/esm/src/modifiercontext.js +11 -0
- package/build/esm/src/notationspelling.js +73 -0
- package/build/esm/src/note.js +3 -0
- package/build/esm/src/notehead.js +11 -6
- package/build/esm/src/ornament.js +43 -18
- 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/proportionalformatter.js +54 -6
- 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 +134 -116
- package/build/esm/src/stavetie.js +66 -9
- package/build/esm/src/stem.js +26 -11
- 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/tickcontext.js +19 -0
- package/build/esm/src/timesignature.js +20 -6
- package/build/esm/src/tuplet.js +58 -17
- package/build/esm/src/version.js +3 -3
- package/build/esm/src/vexflow.js +20 -0
- package/build/esm/src/voice.js +7 -3
- package/build/esm/tests/bend_tests.js +14 -1
- package/build/esm/tests/curve_tests.js +14 -4
- package/build/esm/tests/demo_repertoire_tests.js +27 -0
- package/build/esm/tests/demos/drums.js +54 -0
- package/build/esm/tests/demos/electric.js +63 -0
- package/build/esm/tests/demos/greensleeves.js +90 -0
- package/build/esm/tests/demos/joy.js +61 -0
- package/build/esm/tests/demos/kesh.js +80 -0
- package/build/esm/tests/demos/prelude.js +59 -0
- package/build/esm/tests/demos/quartertones.js +50 -0
- package/build/esm/tests/demos/saints.js +65 -0
- 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/score-layout.mjs +75 -0
- package/build/esm/tests/engraving/score-persistence.mjs +262 -0
- package/build/esm/tests/engraving/specialist-studies.mjs +347 -0
- package/build/esm/tests/engraving/studies.mjs +367 -0
- package/build/esm/tests/formatter_tests.js +10 -1
- package/build/esm/tests/index.js +1 -0
- package/build/esm/tests/node/audit-dependencies-tests.mjs +42 -0
- package/build/esm/tests/node/continuous-score-tests.mjs +282 -0
- package/build/esm/tests/node/easyscore-tests.mjs +71 -0
- package/build/esm/tests/node/engraving-layout-tests.mjs +449 -0
- package/build/esm/tests/node/instrument-profile-tests.mjs +224 -0
- package/build/esm/tests/node/local-engraving-tests.mjs +128 -0
- package/build/esm/tests/node/phrase-layout-tests.mjs +281 -0
- package/build/esm/tests/node/proportional-spacing-tests.mjs +64 -0
- package/build/esm/tests/node/publication-tests.mjs +219 -0
- package/build/esm/tests/node/rendering-tests.mjs +6 -2
- package/build/esm/tests/threevoice_tests.js +11 -1
- package/build/esm/tests/vexflow_test_helpers.js +19 -10
- package/build/esm/tools/audit-dependencies.mjs +61 -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/esm/tools/score-fixtures.mjs +23 -6
- package/build/types/src/accidental.d.ts +4 -0
- 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 +9 -1
- package/build/types/src/beam.d.ts +16 -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 +20 -0
- package/build/types/src/dot.d.ts +5 -0
- package/build/types/src/easyscore/composition.d.ts +27 -0
- package/build/types/src/easyscore/policies.d.ts +1 -1
- package/build/types/src/element.d.ts +2 -0
- package/build/types/src/engravinggeometry.d.ts +31 -0
- package/build/types/src/engravingprofile.d.ts +20 -0
- package/build/types/src/factory.d.ts +6 -1
- package/build/types/src/formatter.d.ts +3 -3
- package/build/types/src/fretdiagram.d.ts +23 -0
- package/build/types/src/gracenote.d.ts +7 -0
- package/build/types/src/gracenotegroup.d.ts +7 -2
- 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 +12 -0
- package/build/types/src/instrumentprofile.d.ts +124 -0
- package/build/types/src/keysignature.d.ts +9 -0
- package/build/types/src/modifiercontext.d.ts +4 -0
- package/build/types/src/notationspelling.d.ts +25 -0
- package/build/types/src/note.d.ts +15 -0
- package/build/types/src/notehead.d.ts +5 -0
- package/build/types/src/ornament.d.ts +10 -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/proportionalformatter.d.ts +11 -2
- 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/stavenote.d.ts +20 -2
- package/build/types/src/stavetie.d.ts +9 -0
- package/build/types/src/stem.d.ts +10 -1
- 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/tickcontext.d.ts +5 -0
- package/build/types/src/timesignature.d.ts +6 -0
- package/build/types/src/tuplet.d.ts +5 -48
- package/build/types/src/vexflow.d.ts +20 -0
- package/build/types/src/voice.d.ts +2 -0
- package/changelog/CHANGELOG.md +25 -0
- package/package.json +15 -3
- package/tests/all.html +277 -0
- package/tests/demo_petzold_tests.ts +435 -0
- package/tests/demos/drums.ts +55 -0
- package/tests/demos/drums.webp +0 -0
- package/tests/demos/electric.ts +70 -0
- package/tests/demos/electric.webp +0 -0
- package/tests/demos/greensleeves.ts +97 -0
- package/tests/demos/greensleeves.webp +0 -0
- package/tests/demos/joy.ts +65 -0
- package/tests/demos/joy.webp +0 -0
- package/tests/demos/kesh.ts +86 -0
- package/tests/demos/kesh.webp +0 -0
- package/tests/demos/prelude.ts +65 -0
- package/tests/demos/prelude.webp +0 -0
- package/tests/demos/quartertones.ts +51 -0
- package/tests/demos/quartertones.webp +0 -0
- package/tests/demos/saints.ts +70 -0
- package/tests/demos/saints.webp +0 -0
- package/tests/flow.html +550 -239
- package/tests/fonts.css +493 -0
- package/tests/minuet.webp +0 -0
|
@@ -0,0 +1,128 @@
|
|
|
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 { readFile } from 'node:fs/promises';
|
|
12
|
+
import test from 'node:test';
|
|
13
|
+
import puppeteer from 'puppeteer';
|
|
14
|
+
function renderMatrix({ family, textFamily, backend, metadata }) {
|
|
15
|
+
var _a;
|
|
16
|
+
const VF = window.VexFlow;
|
|
17
|
+
VF.setFonts(family, textFamily);
|
|
18
|
+
const target = document.createElement(backend === 'SVG' ? 'div' : 'canvas');
|
|
19
|
+
target.id = 'matrix';
|
|
20
|
+
document.body.replaceChildren(target);
|
|
21
|
+
const factory = new VF.Factory({
|
|
22
|
+
renderer: { elementId: target.id, width: 850, height: 500 },
|
|
23
|
+
engraving: new VF.EngravingProfile({ musicFont: family, metadata }),
|
|
24
|
+
});
|
|
25
|
+
const score = factory.EasyScore();
|
|
26
|
+
const notes = ['w', 'h', 'q', '8'].flatMap((duration) => [1, -1].map((stemDirection) => factory.StaveNote({ keys: ['c#/6', 'c/6', 'cb/6'], duration, stemDirection })));
|
|
27
|
+
for (const note of notes) {
|
|
28
|
+
['#', 'n', 'b'].forEach((type, index) => note.addModifier(new VF.Accidental(type), index));
|
|
29
|
+
VF.Dot.buildAndAttach([note]);
|
|
30
|
+
}
|
|
31
|
+
const cue = factory.StaveNote({ keys: ['e/4'], duration: '8', stemDirection: -1 });
|
|
32
|
+
cue.setFontSize(cue.fontSizeInPoints * 0.75).reset();
|
|
33
|
+
const host = factory.StaveNote({ keys: ['e/4'], duration: 'q' });
|
|
34
|
+
const grace = factory.GraceNote({ keys: ['f/4'], duration: '16', slash: true });
|
|
35
|
+
host.addModifier(factory.GraceNoteGroup({ notes: [grace], slur: true }), 0);
|
|
36
|
+
const ornament = new VF.Ornament('turn').setUpperAccidental('#').setLowerAccidental('b').setDelayed(true);
|
|
37
|
+
cue.addModifier(ornament, 0);
|
|
38
|
+
const articulation = new VF.Articulation('a.').setPosition(VF.Modifier.Position.BELOW);
|
|
39
|
+
host.addModifier(articulation, 0);
|
|
40
|
+
const lyric = new VF.Annotation('dolce').setFont(textFamily, 12);
|
|
41
|
+
notes[0].addModifier(lyric, 0);
|
|
42
|
+
const tuplet = factory.Tuplet({
|
|
43
|
+
notes: [cue, host],
|
|
44
|
+
options: { numNotes: 3, notesOccupied: 2, ratioed: true, displayRatio: [6, 4], bracketed: true },
|
|
45
|
+
});
|
|
46
|
+
const systems = [];
|
|
47
|
+
for (const [i, passage] of [notes.slice(0, 4), notes.slice(4), [cue, host, score.notes('A4/q')[0]]].entries()) {
|
|
48
|
+
const system = factory.System({ width: 800, y: 30 + i * 145 });
|
|
49
|
+
system.addStave({ voices: [score.voice(passage, { mode: 'soft' })] });
|
|
50
|
+
systems.push(system);
|
|
51
|
+
}
|
|
52
|
+
systems.forEach((s) => s.format());
|
|
53
|
+
const snapshot = () => {
|
|
54
|
+
const measured = [...notes, cue, host, grace, ornament, tuplet].map((el) => VF.measureEngraving(el));
|
|
55
|
+
return { boxes: measured.map((m) => m.ink), diagnostics: measured.flatMap((m) => m.diagnostics) };
|
|
56
|
+
};
|
|
57
|
+
const before = snapshot();
|
|
58
|
+
factory.draw({ retain: true });
|
|
59
|
+
const after = snapshot();
|
|
60
|
+
const rows = notes.map((note) => {
|
|
61
|
+
const heads = note.getHeadInk();
|
|
62
|
+
const ledger = note.getLedgerLines().at(-1);
|
|
63
|
+
const signs = note
|
|
64
|
+
.getModifiers()
|
|
65
|
+
.filter((m) => m instanceof VF.Accidental)
|
|
66
|
+
.map((m) => m.getInkBounds());
|
|
67
|
+
const dot = note
|
|
68
|
+
.getModifiers()
|
|
69
|
+
.find((m) => m instanceof VF.Dot)
|
|
70
|
+
.getInkBounds();
|
|
71
|
+
return { heads, ledger, signs, dot, stem: note.getStemSegment(), family: note.noteHeads[0].fontInfo.family };
|
|
72
|
+
});
|
|
73
|
+
const sizes = [notes[0], cue, grace].map((note) => note.noteHeads[0].fontSizeInPoints);
|
|
74
|
+
const drawnLabel = backend === 'SVG' ? (_a = target.querySelector('.vf-tuplet text')) === null || _a === void 0 ? void 0 : _a.textContent : undefined;
|
|
75
|
+
const pixels = backend === 'SVG'
|
|
76
|
+
? target.querySelectorAll('svg text').length
|
|
77
|
+
: target
|
|
78
|
+
.getContext('2d')
|
|
79
|
+
.getImageData(0, 0, target.width, target.height)
|
|
80
|
+
.data.some((v, i, data) => i % 4 === 3 && v > 128 && data[i - 1] < 64);
|
|
81
|
+
return { before, after, rows, sizes, pixels, drawnLabel };
|
|
82
|
+
}
|
|
83
|
+
test('Bravura, Petaluma and metadata-free Leland render local parts at normal, cue and grace sizes', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
84
|
+
const browser = yield puppeteer.launch({ headless: true, args: process.env.CI ? ['--no-sandbox'] : [] });
|
|
85
|
+
try {
|
|
86
|
+
const page = yield browser.newPage();
|
|
87
|
+
yield page.setContent('<body></body>');
|
|
88
|
+
yield page.addScriptTag({ path: new URL('../../build/cjs/vexflow-debug.js', import.meta.url).pathname });
|
|
89
|
+
const file = (name, suffix) => new URL('../../node_modules/@vexflow-fonts/' + name + '/' + suffix, import.meta.url);
|
|
90
|
+
for (const family of ['Bravura', 'Petaluma', 'Leland', 'Academico', 'Petaluma Script']) {
|
|
91
|
+
const name = family.toLowerCase().replaceAll(' ', '');
|
|
92
|
+
const bytes = yield readFile(file(name, name + '.woff2'));
|
|
93
|
+
yield page.evaluate((family, data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
94
|
+
const face = new FontFace(family, 'url(data:font/woff2;base64,' + data + ')');
|
|
95
|
+
document.fonts.add(yield face.load());
|
|
96
|
+
}), family, bytes.toString('base64'));
|
|
97
|
+
}
|
|
98
|
+
for (const [family, textFamily] of [
|
|
99
|
+
['Bravura', 'Academico'],
|
|
100
|
+
['Petaluma', 'Petaluma Script'],
|
|
101
|
+
['Leland', 'Academico'],
|
|
102
|
+
]) {
|
|
103
|
+
const metadata = family === 'Leland' ? undefined : JSON.parse(yield readFile(file(family.toLowerCase(), 'metadata.json')));
|
|
104
|
+
for (const backend of ['SVG', 'Canvas']) {
|
|
105
|
+
const scene = yield page.evaluate(renderMatrix, { family, textFamily, metadata, backend });
|
|
106
|
+
assert.deepEqual(scene.before.diagnostics, [], family + ' ' + backend);
|
|
107
|
+
assert.deepEqual(scene.after, scene.before);
|
|
108
|
+
assert.ok(scene.pixels);
|
|
109
|
+
if (backend === 'SVG')
|
|
110
|
+
assert.equal(scene.drawnLabel, String.fromCharCode(0xe886, 0xe88a, 0xe884));
|
|
111
|
+
assert.ok(scene.sizes[0] > scene.sizes[1] && scene.sizes[0] > scene.sizes[2]);
|
|
112
|
+
for (const { heads, ledger, signs, dot, stem, family: used } of scene.rows) {
|
|
113
|
+
assert.equal(used, family);
|
|
114
|
+
assert.equal(new Set(heads.map((h) => h.x)).size, 3);
|
|
115
|
+
const left = Math.min(...heads.map((h) => h.x)), right = Math.max(...heads.map((h) => h.x + h.w));
|
|
116
|
+
assert.ok(ledger.x <= left && ledger.x + ledger.width >= right - 0.5, 'ledger encloses heads');
|
|
117
|
+
assert.ok(signs.every((s) => s.x + s.w <= left + 1), 'accidentals clear heads');
|
|
118
|
+
assert.ok(dot.x >= right - 1, 'dot clears heads');
|
|
119
|
+
if (stem)
|
|
120
|
+
assert.ok(heads.some((h) => h.x - 1 <= stem.x && stem.x <= h.x + h.w + 1), 'stem joins a head');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
yield browser.close();
|
|
127
|
+
}
|
|
128
|
+
}));
|
|
@@ -0,0 +1,281 @@
|
|
|
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 { createCanvas, registerFont } from 'canvas';
|
|
13
|
+
import { readFile } from 'node:fs/promises';
|
|
14
|
+
import puppeteer from 'puppeteer';
|
|
15
|
+
import { makePhraseStudy } from '../engraving/phrase-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 n = family.toLowerCase();
|
|
19
|
+
registerFont(new URL('../../node_modules/@vexflow-fonts/' + n + '/' + n + '.otf', import.meta.url).pathname, {
|
|
20
|
+
family,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
VF.Element.setTextMeasurementCanvas(createCanvas(1, 1));
|
|
24
|
+
function factory() {
|
|
25
|
+
return new VF.Factory({ renderer: { elementId: null } }).setContext(new VF.CanvasContext(createCanvas(720, 420).getContext('2d')));
|
|
26
|
+
}
|
|
27
|
+
function score(text = 'G4/q, A4/q, B4/q, A4/q, G4/q') {
|
|
28
|
+
const f = factory(), es = f.EasyScore(), notes = es.notes(text, { stem: 'down' });
|
|
29
|
+
const system = f.System({ width: 510, y: 30, spaceBetweenStaves: 4 });
|
|
30
|
+
const staff = system.addStave({ voices: [es.voice(notes, { mode: 'soft' })] });
|
|
31
|
+
return { f, notes, system, staff, layout: system.getPhraseLayout() };
|
|
32
|
+
}
|
|
33
|
+
function measured(mark) {
|
|
34
|
+
const g = VF.measureEngraving(mark);
|
|
35
|
+
assert.deepEqual(g.diagnostics, []);
|
|
36
|
+
return g;
|
|
37
|
+
}
|
|
38
|
+
function intersects(a, b) {
|
|
39
|
+
return a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h;
|
|
40
|
+
}
|
|
41
|
+
test('whole syllables, hyphens and extenders stay in their verses across retained reflow', () => {
|
|
42
|
+
const f = factory(), { layout, system, lyrics, notes, bass } = makePhraseStudy(VF.VexFlow, f, 'choir');
|
|
43
|
+
const inspect = () => {
|
|
44
|
+
const rows = lyrics.map((verse) => verse.map((mark) => measured(mark)));
|
|
45
|
+
const baselines = rows.map((row) => row[0].anchors.baseline.y);
|
|
46
|
+
rows.forEach((row, i) => assert.ok(row.every((g) => g.anchors.baseline.y === baselines[i])));
|
|
47
|
+
assert.ok(rows[0].every((a) => rows[1].every((b) => a.ink.y + a.ink.h < b.ink.y)));
|
|
48
|
+
const links = layout.getLyricConnectors();
|
|
49
|
+
assert.equal(links.length, 5);
|
|
50
|
+
const [hyphen, extender] = links;
|
|
51
|
+
assert.ok(hyphen.x > rows[0][0].ink.x + rows[0][0].ink.w && hyphen.x + hyphen.w < rows[0][1].ink.x);
|
|
52
|
+
assert.equal(extender.x + extender.w, notes[3].getNoteHeadBeginX() + notes[3].getGlyphWidth());
|
|
53
|
+
assert.ok(links.every((link) => rows.flat().every((g) => !intersects(link, g.ink))));
|
|
54
|
+
assert.ok(bass.getYForLine(0) > Math.max(...links.map((b) => b.y + b.h)));
|
|
55
|
+
assert.deepEqual(layout.diagnostics, []);
|
|
56
|
+
return { rows, links, gap: bass.getY(), bounds: layout.bounds };
|
|
57
|
+
};
|
|
58
|
+
system.format();
|
|
59
|
+
const wide = inspect();
|
|
60
|
+
f.draw({ retain: true });
|
|
61
|
+
assert.deepEqual(inspect(), wide);
|
|
62
|
+
system.setWidth(390).format();
|
|
63
|
+
assert.notDeepEqual(inspect(), wide);
|
|
64
|
+
system.setWidth(615).format();
|
|
65
|
+
assert.deepEqual(inspect(), wide);
|
|
66
|
+
});
|
|
67
|
+
test('a cubic slur clears internal accents while the wedge, pedal and ottava retain their anchors', () => {
|
|
68
|
+
const f = factory(), { system, layout, notes, slur, hairpin, octave, pedal, dynamics, bass } = makePhraseStudy(VF.VexFlow, f, 'piano');
|
|
69
|
+
for (const width of [615, 390, 615]) {
|
|
70
|
+
system.setWidth(width).format();
|
|
71
|
+
f.draw({ retain: true });
|
|
72
|
+
assert.deepEqual(layout.diagnostics, []);
|
|
73
|
+
const routed = slur.getRouteParts(), anchors = slur.getAnchors();
|
|
74
|
+
const accent = measured(notes[1].getModifiers()[0]).ink;
|
|
75
|
+
assert.ok(routed.every((b) => !intersects(b, accent)));
|
|
76
|
+
const ottava = measured(octave).ink;
|
|
77
|
+
assert.ok(ottava.y + ottava.h < Math.min(...routed.map((b) => b.y)));
|
|
78
|
+
const [p, forte] = dynamics.map((m) => measured(m).ink), wedge = measured(hairpin).ink;
|
|
79
|
+
assert.ok(p.x + p.w < wedge.x && wedge.x + wedge.w < forte.x);
|
|
80
|
+
assert.ok(measured(pedal).ink.y > bass.getYForLine(4));
|
|
81
|
+
slur.setLayoutRise(0);
|
|
82
|
+
assert.deepEqual(slur.getAnchors(), anchors);
|
|
83
|
+
assert.notDeepEqual(routed, slur.getRouteParts());
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
test('pinned verse and staff collisions name their owners and terminate', () => {
|
|
87
|
+
const { system, layout, notes, staff } = score();
|
|
88
|
+
const bottom = system.addStave({ voices: [] });
|
|
89
|
+
layout.lockStaffGap(bottom);
|
|
90
|
+
const ids = ['one', 'two'];
|
|
91
|
+
ids.forEach((id) => layout.addVerse(staff, [{ note: notes[0], text: 'word' }], { baselineSpaces: 7 })[0].setAttribute('id', id));
|
|
92
|
+
system.format();
|
|
93
|
+
assert.ok(layout.diagnostics.some((d) => d.code === 'PinnedCollision' && ids.every((id) => d.sources.includes(id))));
|
|
94
|
+
assert.ok(layout.diagnostics.some((d) => d.code === 'PinnedCollision' && d.sources.includes(bottom.getAttribute('id'))));
|
|
95
|
+
for (const m of notes[0].getModifiers())
|
|
96
|
+
assert.equal(measured(m).anchors.baseline.y, staff.getYForLine(7));
|
|
97
|
+
assert.equal(layout.passes, 1);
|
|
98
|
+
});
|
|
99
|
+
test('a restricted pass budget leaves finite repeatable evidence', () => {
|
|
100
|
+
const f = factory(), { system, layout } = makePhraseStudy(VF.VexFlow, f, 'choir');
|
|
101
|
+
layout.setPassLimit(1);
|
|
102
|
+
const inspect = () => {
|
|
103
|
+
system.format();
|
|
104
|
+
return { diagnostics: structuredClone(layout.diagnostics), bounds: layout.bounds, passes: layout.passes };
|
|
105
|
+
};
|
|
106
|
+
const first = inspect();
|
|
107
|
+
assert.equal(first.passes, 1);
|
|
108
|
+
assert.ok(first.diagnostics.some((d) => d.code === 'IterationLimit'));
|
|
109
|
+
assert.ok(Object.values(first.bounds).every(Number.isFinite));
|
|
110
|
+
assert.deepEqual(inspect(), first);
|
|
111
|
+
layout.setPassLimit(4);
|
|
112
|
+
system.format();
|
|
113
|
+
assert.deepEqual(layout.diagnostics, []);
|
|
114
|
+
});
|
|
115
|
+
test('whole Latin combining sequences and CJK keep their text, unsupported script and invalid anchors name the mark', () => {
|
|
116
|
+
const { f, system, layout, notes, staff } = score();
|
|
117
|
+
const texts = ['E\u0301', '歌', 'سلام'];
|
|
118
|
+
const marks = layout.addVerse(staff, texts.map((text, i) => ({ note: notes[i], text })));
|
|
119
|
+
const detached = f.Annotation({ text: 'detached' });
|
|
120
|
+
layout.addLane(staff, [detached]);
|
|
121
|
+
const truncated = f.StaveTie({ from: notes[3] });
|
|
122
|
+
layout.route(truncated);
|
|
123
|
+
system.format();
|
|
124
|
+
assert.deepEqual(marks.map((m) => m.text), texts);
|
|
125
|
+
assert.deepEqual(layout.diagnostics.filter((d) => d.code === 'UnsupportedScript').map((d) => d.sources), [[marks[2].getAttribute('id')]]);
|
|
126
|
+
for (const m of [detached, truncated])
|
|
127
|
+
assert.ok(layout.diagnostics.some((d) => d.code === 'InvalidAnchor' && d.sources.includes(m.getAttribute('id'))));
|
|
128
|
+
});
|
|
129
|
+
test('nested quadratic and cubic routes preserve tied chord indices, manual controls and crossing diagnostics', () => {
|
|
130
|
+
const { f, system, layout, notes } = score('(G4 B4)/q, (G4 B4)/q, (G4 B4)/q, (G4 B4)/q, (G4 B4)/q');
|
|
131
|
+
const tie = f.StaveTie({
|
|
132
|
+
from: notes[1],
|
|
133
|
+
to: notes[3],
|
|
134
|
+
firstIndexes: [1],
|
|
135
|
+
lastIndexes: [1],
|
|
136
|
+
options: { direction: -1 },
|
|
137
|
+
});
|
|
138
|
+
const slur = f.Curve({
|
|
139
|
+
from: notes[0],
|
|
140
|
+
to: notes[4],
|
|
141
|
+
options: {
|
|
142
|
+
openingDirection: 'down',
|
|
143
|
+
cps: [
|
|
144
|
+
{ x: 2, y: 39 },
|
|
145
|
+
{ x: 3, y: 43 },
|
|
146
|
+
],
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
system.format();
|
|
150
|
+
const manual = slur.getRouteParts();
|
|
151
|
+
layout.route(slur).route(tie);
|
|
152
|
+
system.format();
|
|
153
|
+
assert.deepEqual(slur.getRouteParts(), manual);
|
|
154
|
+
assert.deepEqual(tie.getNotes().firstIndexes, [1]);
|
|
155
|
+
assert.ok(tie.getRouteParts().length > 1);
|
|
156
|
+
assert.ok(!layout.diagnostics.some((d) => d.code === 'CrossingSpans'));
|
|
157
|
+
const cross = f.Curve({ from: notes[0], to: notes[2] });
|
|
158
|
+
layout.route(cross);
|
|
159
|
+
system.format();
|
|
160
|
+
assert.ok(layout.diagnostics.some((d) => d.code === 'CrossingSpans' && d.sources.includes(cross.getAttribute('id'))));
|
|
161
|
+
});
|
|
162
|
+
test('a rest clears ink anchored at an earlier attack and reports a collision when pinned', () => {
|
|
163
|
+
function restCase(pin) {
|
|
164
|
+
const { f, system, staff, layout, notes } = score('G4/q, B4/q/r, G4/q');
|
|
165
|
+
const [host, rest] = notes, obstruction = f.Annotation({ text: 'x' });
|
|
166
|
+
host.addModifier(obstruction, 0);
|
|
167
|
+
system.format();
|
|
168
|
+
const b = measured(rest).ink, a = measured(obstruction).ink;
|
|
169
|
+
obstruction.setXShift(a.x - b.x).setTextBaseline(obstruction.computeY().y + b.y - a.y);
|
|
170
|
+
assert.ok(rest.isRest());
|
|
171
|
+
const original = rest.getKeyLine(0);
|
|
172
|
+
if (pin)
|
|
173
|
+
layout.pin(rest);
|
|
174
|
+
system.format();
|
|
175
|
+
assert.equal(intersects(measured(rest).ink, measured(obstruction).ink), pin);
|
|
176
|
+
assert.equal(rest.getKeyLine(0) === original, pin);
|
|
177
|
+
assert.equal(layout.diagnostics.some((d) => d.code === 'PinnedCollision'), pin);
|
|
178
|
+
const line = rest.getKeyLine(0);
|
|
179
|
+
system.format();
|
|
180
|
+
assert.equal(rest.getKeyLine(0), line);
|
|
181
|
+
assert.equal(host.getStave(), staff);
|
|
182
|
+
}
|
|
183
|
+
restCase(false);
|
|
184
|
+
restCase(true);
|
|
185
|
+
});
|
|
186
|
+
test('staff separation refits cross-staff beams to the visible stem tips after resizing', () => {
|
|
187
|
+
const { f, system, staff, layout, notes } = score('G4/8, C5/8, G4/q');
|
|
188
|
+
const bottom = system.addStave({ voices: [] }).addClef('bass');
|
|
189
|
+
notes[1].setStave(bottom);
|
|
190
|
+
const beam = f.Beam({ notes: notes.slice(0, 2) });
|
|
191
|
+
layout.addVerse(staff, [{ note: notes[2], text: 'glow' }]);
|
|
192
|
+
const inspect = () => {
|
|
193
|
+
system.format();
|
|
194
|
+
assert.deepEqual(layout.diagnostics, []);
|
|
195
|
+
assert.ok(layout.passes >= 2 && layout.passes <= 4);
|
|
196
|
+
const geometry = measured(beam);
|
|
197
|
+
for (const [i, n] of notes.slice(0, 2).entries())
|
|
198
|
+
assert.equal(geometry.anchors['stem' + i].y, measured(n).anchors.stemTip.y + VF.Stem.WIDTH / 2);
|
|
199
|
+
return { beam: geometry.ink, stave: bottom.getY() };
|
|
200
|
+
};
|
|
201
|
+
const before = inspect();
|
|
202
|
+
system.setWidth(340);
|
|
203
|
+
assert.notDeepEqual(inspect(), before);
|
|
204
|
+
system.setWidth(510);
|
|
205
|
+
assert.deepEqual(inspect(), before);
|
|
206
|
+
});
|
|
207
|
+
test('clefs, key and time signatures follow the lower stave on each staff refit', () => {
|
|
208
|
+
const f = factory();
|
|
209
|
+
const { system, layout, bass } = makePhraseStudy(VF.VexFlow, f, 'choir');
|
|
210
|
+
bass.addKeySignature('E').addTimeSignature('6/8');
|
|
211
|
+
const key = bass.getModifiers().find((m) => m instanceof VF.KeySignature);
|
|
212
|
+
const meter = bass.getModifiers().find((m) => m instanceof VF.TimeSignature);
|
|
213
|
+
const inspect = () => {
|
|
214
|
+
system.format();
|
|
215
|
+
assert.deepEqual(layout.diagnostics, []);
|
|
216
|
+
return [...key.getInkParts(), meter.getInkBounds()].map((b) => b.y - bass.getY());
|
|
217
|
+
};
|
|
218
|
+
const initial = inspect();
|
|
219
|
+
assert.equal(initial.length, 5);
|
|
220
|
+
system.setY(system.getY() + 80);
|
|
221
|
+
assert.deepEqual(inspect(), initial);
|
|
222
|
+
});
|
|
223
|
+
test('choir and piano phrases render through SVG and Canvas with Bravura and Petaluma', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
224
|
+
const browser = yield puppeteer.launch({ headless: true, args: process.env.CI ? ['--no-sandbox'] : [] });
|
|
225
|
+
try {
|
|
226
|
+
const page = yield browser.newPage();
|
|
227
|
+
yield page.setContent('<body></body>');
|
|
228
|
+
yield page.addScriptTag({ path: new URL('../../build/cjs/vexflow-debug.js', import.meta.url).pathname });
|
|
229
|
+
yield page.addScriptTag({ content: 'window.makePhraseStudy = ' + makePhraseStudy.toString() });
|
|
230
|
+
for (const family of ['Bravura', 'Academico', 'Petaluma', 'Petaluma Script']) {
|
|
231
|
+
const name = family.toLowerCase().replaceAll(' ', '');
|
|
232
|
+
const data = yield readFile(new URL('../../node_modules/@vexflow-fonts/' + name + '/' + name + '.woff2', import.meta.url));
|
|
233
|
+
yield page.evaluate((family, base64) => __awaiter(void 0, void 0, void 0, function* () {
|
|
234
|
+
document.fonts.add(yield new FontFace(family, 'url(data:font/woff2;base64,' + base64 + ')').load());
|
|
235
|
+
}), family, data.toString('base64'));
|
|
236
|
+
}
|
|
237
|
+
for (const [family, textFamily] of [
|
|
238
|
+
['Bravura', 'Academico'],
|
|
239
|
+
['Petaluma', 'Petaluma Script'],
|
|
240
|
+
])
|
|
241
|
+
for (const kind of ['choir', 'piano'])
|
|
242
|
+
for (const backend of ['SVG', 'Canvas']) {
|
|
243
|
+
const result = yield page.evaluate(({ family, textFamily, kind, backend }) => {
|
|
244
|
+
var _a;
|
|
245
|
+
const VF = window.VexFlow;
|
|
246
|
+
VF.setFonts(family, textFamily);
|
|
247
|
+
const target = document.createElement(backend === 'SVG' ? 'div' : 'canvas');
|
|
248
|
+
target.id = 'phrase';
|
|
249
|
+
document.body.replaceChildren(target);
|
|
250
|
+
const f = new VF.Factory({ renderer: { elementId: 'phrase', width: 670, height: 380 } });
|
|
251
|
+
const { system, layout, lyrics } = window.makePhraseStudy(VF, f, kind);
|
|
252
|
+
const widths = [615, 390, 615];
|
|
253
|
+
const results = widths.map((w) => {
|
|
254
|
+
system.setWidth(w);
|
|
255
|
+
f.draw({ retain: true });
|
|
256
|
+
return {
|
|
257
|
+
diagnostics: structuredClone(layout.diagnostics),
|
|
258
|
+
bounds: layout.bounds,
|
|
259
|
+
connectors: layout.getLyricConnectors(),
|
|
260
|
+
};
|
|
261
|
+
});
|
|
262
|
+
const ink = backend === 'SVG'
|
|
263
|
+
? target.querySelectorAll('svg path').length > 0
|
|
264
|
+
: target
|
|
265
|
+
.getContext('2d')
|
|
266
|
+
.getImageData(0, 0, target.width, target.height)
|
|
267
|
+
.data.some((v, i) => i % 4 === 3 && v > 0);
|
|
268
|
+
return { results, ink, syllables: (_a = lyrics === null || lyrics === void 0 ? void 0 : lyrics.flat().length) !== null && _a !== void 0 ? _a : 0 };
|
|
269
|
+
}, { family, textFamily, kind, backend });
|
|
270
|
+
assert.ok(result.ink, family + ' ' + kind + ' ' + backend);
|
|
271
|
+
for (const row of result.results)
|
|
272
|
+
assert.deepEqual(row.diagnostics, [], family + ' ' + kind + ' ' + backend);
|
|
273
|
+
assert.deepEqual(result.results[0], result.results[2]);
|
|
274
|
+
assert.notDeepEqual(result.results[0], result.results[1]);
|
|
275
|
+
assert.equal(result.results[0].connectors.length, kind === 'choir' ? 5 : 0);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
finally {
|
|
279
|
+
yield browser.close();
|
|
280
|
+
}
|
|
281
|
+
}));
|
|
@@ -212,3 +212,67 @@ test('unsupported numeric ranges fail before producing infinite coordinates', ()
|
|
|
212
212
|
const v = voice();
|
|
213
213
|
assert.throws(() => proportional(Number.MAX_VALUE).joinVoices([v]).format([v]), /pixel range/);
|
|
214
214
|
});
|
|
215
|
+
test('optical spacing fits measured obstacles, then stretches rhythmic intervals without moving clefs into notes', () => {
|
|
216
|
+
const stave = new Stave(10, 50, 900);
|
|
217
|
+
const notes = ['q', 'q', '8', '16', '32', '64'].map((duration) => new StaveNote({ keys: ['c/5'], duration }).setStave(stave));
|
|
218
|
+
notes[0].addModifier(new VF.Annotation('crescendo'), 0);
|
|
219
|
+
notes[1].addModifier(new GraceNoteGroup(['d/5', 'e/5', 'f/5'].map((key) => new GraceNote({ keys: [key], duration: '16' }))), 0);
|
|
220
|
+
notes[2].addModifier(new VF.ChordSymbol().addText('Cmaj7/G'), 0);
|
|
221
|
+
notes[3].addModifier(new Accidental('##'), 0);
|
|
222
|
+
const clef = new ClefNote('bass', 'small').setStave(stave);
|
|
223
|
+
const v = new Voice('4/4').setStrict(false).addTickables([notes[0], clef, ...notes.slice(1)]);
|
|
224
|
+
const f = new Formatter({ spacing: { mode: 'optical' } }).joinVoices([v]);
|
|
225
|
+
const minimum = f.preCalculateMinTotalWidth([v]);
|
|
226
|
+
assert.throws(() => f.format([v], minimum - 1), /InsufficientOpticalSpace.*px width/);
|
|
227
|
+
f.format([v], minimum);
|
|
228
|
+
const tight = positions(v);
|
|
229
|
+
for (let i = 1; i < notes.length; ++i) {
|
|
230
|
+
const prev = notes[i - 1].getMetrics(), curr = notes[i].getMetrics();
|
|
231
|
+
assert.ok(tight[i] - curr.modLeftPx - curr.leftDisplacedHeadPx >=
|
|
232
|
+
tight[i - 1] + prev.notePx + prev.rightDisplacedHeadPx + prev.modRightPx + 2 - 1e-7);
|
|
233
|
+
}
|
|
234
|
+
assert.ok(clef.getAbsoluteX() + clef.getWidth() <= notes[1].getAbsoluteX());
|
|
235
|
+
f.format([v], minimum + 200);
|
|
236
|
+
const loose = positions(v);
|
|
237
|
+
const extra = (i) => loose[i] - loose[i - 1] - (tight[i] - tight[i - 1]);
|
|
238
|
+
close(extra(3) / extra(4), Math.sqrt(2));
|
|
239
|
+
f.tune();
|
|
240
|
+
assert.deepEqual(positions(v), loose);
|
|
241
|
+
});
|
|
242
|
+
test('nested 5:4 and 3:2 tuplets preserve every exact onset through reformat', () => {
|
|
243
|
+
const stave = new Stave(10, 50, 900);
|
|
244
|
+
const notes = Array.from({ length: 5 }, () => new StaveNote({ keys: ['c/5'], duration: '8' }).setStave(stave));
|
|
245
|
+
new Tuplet(notes, { numNotes: 5, notesOccupied: 4 });
|
|
246
|
+
new Tuplet(notes.slice(1, 4), { numNotes: 3, notesOccupied: 2 });
|
|
247
|
+
const v = new Voice('4/4').setStrict(false).addTickables(notes);
|
|
248
|
+
const f = proportional(200).joinVoices([v]).format([v]);
|
|
249
|
+
const expected = [0, 6, 10, 14, 18];
|
|
250
|
+
const elapsed = new VF.Fraction(0, 1);
|
|
251
|
+
for (const [i, n] of notes.entries()) {
|
|
252
|
+
assert.ok(elapsed.equals(new VF.Fraction(expected[i] * 4096, 15)));
|
|
253
|
+
elapsed.add(n.getTicks());
|
|
254
|
+
}
|
|
255
|
+
assert.ok(elapsed.equals(new VF.Fraction(24 * 4096, 15)));
|
|
256
|
+
onsets(v, expected.map((value) => (value * 200) / 15));
|
|
257
|
+
f.format([v], 1600);
|
|
258
|
+
onsets(v, expected.map((value) => (value * 200) / 15));
|
|
259
|
+
});
|
|
260
|
+
test('optical and exact policies expose different minima for a very short final attack', () => {
|
|
261
|
+
const makeVoice = () => voice(['h', 'q', '8', '16', '32', '64', '64']);
|
|
262
|
+
const run = (spacing) => {
|
|
263
|
+
const v = makeVoice();
|
|
264
|
+
const f = new Formatter(spacing ? { spacing } : {}).joinVoices([v]);
|
|
265
|
+
const minimum = f.preCalculateMinTotalWidth([v]);
|
|
266
|
+
f.format([v], minimum);
|
|
267
|
+
assert.ok(positions(v).every(Number.isFinite));
|
|
268
|
+
return minimum;
|
|
269
|
+
};
|
|
270
|
+
const optical = run({ mode: 'optical' });
|
|
271
|
+
const exact = run({ mode: 'proportional' });
|
|
272
|
+
const legacy = run();
|
|
273
|
+
assert.ok(optical < exact);
|
|
274
|
+
assert.ok(legacy > 0);
|
|
275
|
+
const constrained = new Formatter({ spacing: { mode: 'proportional' } });
|
|
276
|
+
const v = makeVoice();
|
|
277
|
+
assert.throws(() => constrained.joinVoices([v]).format([v], optical), /InsufficientProportionalSpace/);
|
|
278
|
+
});
|