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,449 @@
|
|
|
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 { execFileSync } from 'node:child_process';
|
|
12
|
+
import { readFileSync } from 'node:fs';
|
|
13
|
+
import test from 'node:test';
|
|
14
|
+
import { createCanvas, registerFont } from 'canvas';
|
|
15
|
+
import puppeteer from 'puppeteer';
|
|
16
|
+
import { compositionInput, excerpt, loadScore, saveScore } from '../engraving/score-persistence.mjs';
|
|
17
|
+
import { passageView } from '../engraving/score-layout.mjs';
|
|
18
|
+
const VF = await import(new URL('../../build/esm/entry/vexflow-core.js', import.meta.url));
|
|
19
|
+
const passage = JSON.parse(readFileSync(new URL('../engraving/m1-passage.json', import.meta.url)));
|
|
20
|
+
for (const family of ['Bravura', 'Petaluma', 'Academico']) {
|
|
21
|
+
const name = family.toLowerCase();
|
|
22
|
+
registerFont(new URL(`../../node_modules/@vexflow-fonts/${name}/${name}.otf`, import.meta.url).pathname, { family });
|
|
23
|
+
}
|
|
24
|
+
VF.Element.setTextMeasurementCanvas(createCanvas(1, 1));
|
|
25
|
+
function factory(engraving) {
|
|
26
|
+
const canvas = createCanvas(800, 720);
|
|
27
|
+
const f = new VF.Factory({ renderer: { elementId: null }, engraving }).setContext(new VF.CanvasContext(canvas.getContext('2d')));
|
|
28
|
+
return { f, canvas };
|
|
29
|
+
}
|
|
30
|
+
function profile(family, options = {}) {
|
|
31
|
+
const metadata = JSON.parse(readFileSync(new URL(`../../node_modules/@vexflow-fonts/${family.toLowerCase()}/metadata.json`, import.meta.url)));
|
|
32
|
+
return new VF.EngravingProfile(Object.assign({ musicFont: family, metadata }, options));
|
|
33
|
+
}
|
|
34
|
+
function measured(element) {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
const result = VF.measureEngraving(element);
|
|
37
|
+
assert.deepEqual(result.diagnostics, [], element.getCategory());
|
|
38
|
+
assert.ok(((_a = result.ink) === null || _a === void 0 ? void 0 : _a.w) > 0 && ((_b = result.ink) === null || _b === void 0 ? void 0 : _b.h) > 0, element.getCategory());
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
function engravingScene(policy) {
|
|
42
|
+
const { f, canvas } = factory(policy);
|
|
43
|
+
const es = f.EasyScore();
|
|
44
|
+
const notes = es.notes('G4/16, B4/16, (D5 E5)/8, E4/q', { stem: 'up' });
|
|
45
|
+
const beam = f.Beam({ notes: notes.slice(0, 2) });
|
|
46
|
+
const group = f
|
|
47
|
+
.GraceNoteGroup({
|
|
48
|
+
notes: ['c/5', 'a/4'].map((key) => f.GraceNote({ keys: [key], duration: '16', slash: true })),
|
|
49
|
+
slur: true,
|
|
50
|
+
})
|
|
51
|
+
.beamNotes();
|
|
52
|
+
notes[2].addModifier(group, 0);
|
|
53
|
+
for (const type of ['a.', 'a>'])
|
|
54
|
+
notes[3].addModifier(f.Articulation({ type, position: 'below' }), 0);
|
|
55
|
+
const curve = f.Curve({ from: notes[0], to: notes[2], options: { openingDirection: 'down' } });
|
|
56
|
+
const system = f.System({ width: 450, y: 65 });
|
|
57
|
+
system.addStave({ voices: [es.voice(notes, { mode: 'soft' })] });
|
|
58
|
+
const snapshot = () => [beam, ...notes, curve].map(measured);
|
|
59
|
+
return { f, canvas, notes, system, beam, snapshot };
|
|
60
|
+
}
|
|
61
|
+
test('geometry is available before draw and repeats across measure, draw and wide/narrow/wide', () => {
|
|
62
|
+
const policy = profile('Bravura');
|
|
63
|
+
const scene = engravingScene(policy);
|
|
64
|
+
scene.system.format();
|
|
65
|
+
const baseline = scene.snapshot();
|
|
66
|
+
assert.ok(!scene.notes[0].isRendered());
|
|
67
|
+
assert.deepEqual(scene.snapshot(), baseline);
|
|
68
|
+
scene.f.draw({ retain: true });
|
|
69
|
+
assert.deepEqual(scene.snapshot(), baseline);
|
|
70
|
+
scene.system.setWidth(255).format();
|
|
71
|
+
assert.notDeepEqual(scene.snapshot(), baseline);
|
|
72
|
+
scene.system.setWidth(450).format();
|
|
73
|
+
const fresh = engravingScene(policy);
|
|
74
|
+
fresh.system.format();
|
|
75
|
+
assert.deepEqual(scene.snapshot(), fresh.snapshot());
|
|
76
|
+
assert.deepEqual(scene.snapshot(), baseline);
|
|
77
|
+
});
|
|
78
|
+
test('two live scores independently consume glyph metrics, anchors and beam policy', () => {
|
|
79
|
+
const a = engravingScene(profile('Bravura'));
|
|
80
|
+
const b = engravingScene(profile('Petaluma', { beamThickness: 0.7, clearance: 0.5 }));
|
|
81
|
+
a.system.format();
|
|
82
|
+
const original = a.snapshot();
|
|
83
|
+
b.system.format();
|
|
84
|
+
b.f.draw({ retain: true });
|
|
85
|
+
assert.deepEqual(a.snapshot(), original);
|
|
86
|
+
assert.equal(a.notes[0].noteHeads[0].fontInfo.family, 'Bravura');
|
|
87
|
+
assert.equal(b.notes[0].noteHeads[0].fontInfo.family, 'Petaluma');
|
|
88
|
+
assert.equal(a.beam.renderOptions.beamWidth, 5);
|
|
89
|
+
assert.equal(b.beam.renderOptions.beamWidth, 7);
|
|
90
|
+
assert.notEqual(b.notes[0].getHeadInk()[0].w, a.notes[0].getHeadInk()[0].w);
|
|
91
|
+
const glyph = VF.VexFlow.Glyphs.noteheadBlack;
|
|
92
|
+
assert.deepEqual(profile('Petaluma').stemAnchor(glyph, 'up'), [1.336, 0.288]);
|
|
93
|
+
for (const metadata of [
|
|
94
|
+
undefined,
|
|
95
|
+
{},
|
|
96
|
+
{
|
|
97
|
+
fontName: 'Petaluma',
|
|
98
|
+
engravingDefaults: { beamThickness: Infinity },
|
|
99
|
+
glyphsWithAnchors: { noteheadBlack: { stemUpSE: [0, NaN] } },
|
|
100
|
+
},
|
|
101
|
+
]) {
|
|
102
|
+
const fallback = new VF.EngravingProfile({ musicFont: 'Petaluma', metadata });
|
|
103
|
+
assert.equal(fallback.stemAnchor(glyph, 'up'), undefined);
|
|
104
|
+
assert.equal(fallback.beamThickness, 0.5);
|
|
105
|
+
const scene = engravingScene(fallback);
|
|
106
|
+
scene.system.format();
|
|
107
|
+
scene.snapshot();
|
|
108
|
+
}
|
|
109
|
+
assert.throws(() => profile('Bravura', { beamThickness: NaN }), RangeError);
|
|
110
|
+
});
|
|
111
|
+
test('beam clears a head whose attack falls strictly between its stems', () => {
|
|
112
|
+
const build = (peerKey) => {
|
|
113
|
+
const { f } = factory();
|
|
114
|
+
const es = f.EasyScore(), notes = es.notes('C4/8, C4/8', { stem: 'up' });
|
|
115
|
+
const others = ['b/4', peerKey, 'b/4'].map((key, i) => f.StaveNote({ keys: [key], duration: ['16r', '16', '8r'][i], stemDirection: -1 }));
|
|
116
|
+
const beam = f.Beam({ notes });
|
|
117
|
+
const system = f.System({ width: 360, y: 50 });
|
|
118
|
+
system.addStave({ voices: [es.voice(notes, { mode: 'soft' }), es.voice(others, { mode: 'soft' })] });
|
|
119
|
+
system.format();
|
|
120
|
+
return { strip: measured(beam).ink, obstacle: others[1].getHeadInk()[0] };
|
|
121
|
+
};
|
|
122
|
+
const control = build('g/5'), actual = build('c/5');
|
|
123
|
+
assert.ok(actual.obstacle.x > actual.strip.x && actual.obstacle.x + actual.obstacle.w < actual.strip.x + actual.strip.w);
|
|
124
|
+
assert.ok(control.strip.y < actual.obstacle.y + actual.obstacle.h && control.strip.y + control.strip.h > actual.obstacle.y);
|
|
125
|
+
assert.ok(actual.strip.y >= actual.obstacle.y + actual.obstacle.h);
|
|
126
|
+
});
|
|
127
|
+
test('lyrics and cross-staff stems consume the pre-draw coordinates', () => {
|
|
128
|
+
const { f } = factory(), es = f.EasyScore();
|
|
129
|
+
const notes = es.notes('G4/8, C5/8', { stem: 'down' });
|
|
130
|
+
const system = f.System({ width: 330, y: 10 });
|
|
131
|
+
const top = system.addStave({ voices: [es.voice(notes, { mode: 'soft' })] });
|
|
132
|
+
const bottom = system.addStave({ voices: [] });
|
|
133
|
+
notes[1].setStave(bottom);
|
|
134
|
+
const beam = f.Beam({ notes });
|
|
135
|
+
const lyrics = notes.map((n, i) => {
|
|
136
|
+
const mark = f.Annotation({ text: ['sum', 'mer'][i], vJustify: 'bottom' });
|
|
137
|
+
n.addModifier(mark, 0);
|
|
138
|
+
return mark;
|
|
139
|
+
});
|
|
140
|
+
system.format();
|
|
141
|
+
const obstacle = measured(beam);
|
|
142
|
+
assert.equal(notes[0].getStave(), top);
|
|
143
|
+
assert.equal(notes[1].getStave(), bottom);
|
|
144
|
+
for (const [i, n] of notes.entries())
|
|
145
|
+
assert.equal(obstacle.anchors['stem' + i].y, measured(n).anchors.stemTip.y + VF.Stem.WIDTH / 2);
|
|
146
|
+
function placeLyricRow() {
|
|
147
|
+
const extension = (element) => (lyrics.includes(element) ? { parts: [], anchors: {} } : undefined);
|
|
148
|
+
const obstacles = [beam, ...notes].map((element) => VF.measureEngraving(element, { extension }).layout);
|
|
149
|
+
const baseline = Math.max(...obstacles.map((box) => box.y + box.h)) +
|
|
150
|
+
top.getSpacingBetweenLines() +
|
|
151
|
+
Math.max(...lyrics.map((mark) => mark.getTextMetrics().actualBoundingBoxAscent));
|
|
152
|
+
lyrics.forEach((mark) => mark.setTextBaseline(baseline));
|
|
153
|
+
return baseline;
|
|
154
|
+
}
|
|
155
|
+
const baseline = placeLyricRow();
|
|
156
|
+
assert.equal(placeLyricRow(), baseline);
|
|
157
|
+
assert.deepEqual(lyrics.map((mark) => measured(mark).anchors.baseline.y), [baseline, baseline]);
|
|
158
|
+
});
|
|
159
|
+
test('unsupported children and overflow are attributed to their source', () => {
|
|
160
|
+
const scene = engravingScene();
|
|
161
|
+
scene.system.format();
|
|
162
|
+
const n = scene.notes[0], extra = new VF.Modifier().setAttribute('id', 'extension');
|
|
163
|
+
n.addModifier(extra, 0);
|
|
164
|
+
const d = VF.measureEngraving(n, { viewport: { x: 0, y: 0, w: 1, h: 1 } });
|
|
165
|
+
assert.deepEqual(d.diagnostics.map(({ code, sourceId }) => [code, sourceId]), [
|
|
166
|
+
['UnsupportedGeometry', 'extension'],
|
|
167
|
+
['LayoutOverflow', n.getAttribute('id')],
|
|
168
|
+
]);
|
|
169
|
+
const custom = VF.measureEngraving(extra, {
|
|
170
|
+
extension: () => ({ parts: [{ x: 3, y: 5, w: 8, h: 6 }], anchors: {} }),
|
|
171
|
+
paddingPx: 2,
|
|
172
|
+
});
|
|
173
|
+
assert.deepEqual(Object.assign({}, custom.layout), { x: 1, y: 3, w: 12, h: 10 });
|
|
174
|
+
const invalid = VF.measureEngraving(extra, {
|
|
175
|
+
extension: () => ({ parts: [], anchors: { tip: { x: Infinity, y: 0 } } }),
|
|
176
|
+
});
|
|
177
|
+
assert.deepEqual(invalid.diagnostics, [
|
|
178
|
+
{ code: 'InvalidGeometry', phase: 'measure', severity: 'error', sourceId: 'extension' },
|
|
179
|
+
]);
|
|
180
|
+
assert.equal(VF.measureEngraving(new VF.StaveNote({ keys: ['c/4'], duration: 'q' })).diagnostics[0].code, 'UnformattedGeometry');
|
|
181
|
+
});
|
|
182
|
+
for (const format of ['logical', 'easyscore']) {
|
|
183
|
+
test(format + ' full passage and excerpt reload in a fresh process, render and reflow', () => {
|
|
184
|
+
for (const source of [passage, excerpt(passage, 'm3')]) {
|
|
185
|
+
const wire = saveScore(source, format);
|
|
186
|
+
const moduleURL = new URL('../engraving/score-persistence.mjs', import.meta.url);
|
|
187
|
+
const loaded = JSON.parse(execFileSync(process.execPath, [
|
|
188
|
+
'--input-type=module',
|
|
189
|
+
'-e',
|
|
190
|
+
`import {loadScore} from ${JSON.stringify(moduleURL.href)}; import {readFileSync} from 'node:fs'; console.log(JSON.stringify(loadScore(readFileSync(0,'utf8'))));`,
|
|
191
|
+
], { input: wire }));
|
|
192
|
+
assert.deepEqual(loaded, source);
|
|
193
|
+
const { f, canvas } = factory(), view = passageView(VF, f, loaded);
|
|
194
|
+
const { composition, dynamics } = view;
|
|
195
|
+
const wide = view.draw(720), pixels = canvas.toBuffer('image/png');
|
|
196
|
+
assert.equal(wide.rows.length, 1);
|
|
197
|
+
assert.equal(wide.fragments.length, 1);
|
|
198
|
+
const narrow = view.draw(250);
|
|
199
|
+
if (loaded.measures.length === 3) {
|
|
200
|
+
assert.deepEqual(narrow.rows.at(-1), [2]);
|
|
201
|
+
assert.equal(narrow.fragments.length, 2);
|
|
202
|
+
assert.equal(narrow.fragments[0].release, false);
|
|
203
|
+
assert.equal(narrow.fragments[1].depress, false);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
assert.deepEqual(loaded.staves.map((s) => [s.key, s.time]), [
|
|
207
|
+
['G', '4/4'],
|
|
208
|
+
['G', '4/4'],
|
|
209
|
+
]);
|
|
210
|
+
assert.equal(narrow.fragments[0].depress, false);
|
|
211
|
+
}
|
|
212
|
+
assert.equal(narrow.fragments.at(-1).x2, composition.getNote('u3b').getAbsoluteX());
|
|
213
|
+
assert.equal(narrow.fragments.at(-1).release, true);
|
|
214
|
+
assert.equal(dynamics[0].owner, composition.getNote('u3b'));
|
|
215
|
+
assert.equal(dynamics[0].glyph.getYShift(), dynamics[0].owner.checkStave().getSpacingBetweenLines());
|
|
216
|
+
for (const [i, bar] of loaded.measures.entries())
|
|
217
|
+
for (const [j, staff] of loaded.staves.entries()) {
|
|
218
|
+
const native = composition.voices[i][j][0];
|
|
219
|
+
let elapsed = 0;
|
|
220
|
+
native.getTickables().forEach((note, k) => {
|
|
221
|
+
const event = bar.voices[staff.voice][k];
|
|
222
|
+
assert.equal(note, composition.getNote(event.id));
|
|
223
|
+
assert.deepEqual(note.getKeys(), [event.pitch]);
|
|
224
|
+
const frac = (s) => s.split('/').reduce((a, b) => a / b);
|
|
225
|
+
assert.equal(elapsed, frac(event.at));
|
|
226
|
+
const duration = note.getTicks().value() / VF.VexFlow.RESOLUTION;
|
|
227
|
+
assert.equal(duration, frac(event.duration));
|
|
228
|
+
elapsed += duration;
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
assert.deepEqual(view.draw(720), wide);
|
|
232
|
+
assert.deepEqual(canvas.toBuffer('image/png'), pixels);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
test('refs follow a bar insertion and incomplete files report the offending object', () => {
|
|
237
|
+
const edited = structuredClone(passage), bar = structuredClone(passage.measures[0]);
|
|
238
|
+
bar.id = 'insert';
|
|
239
|
+
bar.voices.soprano[0].id = 'new-u';
|
|
240
|
+
bar.voices.bass[0].id = 'new-l';
|
|
241
|
+
edited.measures.splice(2, 0, bar);
|
|
242
|
+
for (const format of ['logical', 'easyscore']) {
|
|
243
|
+
const loaded = loadScore(saveScore(edited, format));
|
|
244
|
+
assert.deepEqual(excerpt(loaded, 'm3'), excerpt(passage, 'm3'));
|
|
245
|
+
const view = passageView(VF, factory().f, loaded);
|
|
246
|
+
const rendered = view.draw(720);
|
|
247
|
+
assert.equal(rendered.fragments.at(-1).x2, view.composition.getNote('u3b').getAbsoluteX());
|
|
248
|
+
const bad = structuredClone(passage);
|
|
249
|
+
bad.marks[0].end.measure = 'missing';
|
|
250
|
+
assert.throws(() => saveScore(bad, format), (e) => e.diagnostic.code === 'DanglingAnchor' && e.diagnostic.sourceId === 'p1');
|
|
251
|
+
const native = structuredClone(passage);
|
|
252
|
+
class CustomBeat extends VF.GhostNote {
|
|
253
|
+
}
|
|
254
|
+
native.measures[0].voices.bass[0] = new CustomBeat('w').setAttribute('id', 'live');
|
|
255
|
+
assert.throws(() => saveScore(native, format), (e) => e.diagnostic.code === 'UnsupportedInput' && e.diagnostic.sourceId === 'live');
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
test('measured ink encloses the drawn parts for both stem directions and fonts', () => {
|
|
259
|
+
for (const family of ['Bravura', 'Petaluma'])
|
|
260
|
+
for (const direction of [VF.Stem.UP, VF.Stem.DOWN]) {
|
|
261
|
+
const { f, canvas } = factory(profile(family));
|
|
262
|
+
const notes = [['d/6', 'e/6'], ['f/4']].map((keys) => f.StaveNote({ keys, duration: '16', stemDirection: direction }));
|
|
263
|
+
const system = f.System({ width: 400, y: 120 });
|
|
264
|
+
notes[0].addModifier(f.Articulation({ type: 'a.', position: direction === 1 ? 'above' : 'below' }), 0);
|
|
265
|
+
system.addStave({ voices: [f.EasyScore().voice(notes, { mode: 'soft' })] });
|
|
266
|
+
system.format();
|
|
267
|
+
for (const element of [
|
|
268
|
+
...notes,
|
|
269
|
+
f.Curve({ from: notes[0], to: notes[1], options: { openingDirection: 'up' } }),
|
|
270
|
+
]) {
|
|
271
|
+
const { ink } = measured(element), ctx = canvas.getContext('2d');
|
|
272
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
273
|
+
element.drawWithStyle();
|
|
274
|
+
const { data } = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
|
275
|
+
let count = 0;
|
|
276
|
+
for (let i = 3; i < data.length; i += 4)
|
|
277
|
+
if (data[i] > 100) {
|
|
278
|
+
const x = ((i - 3) / 4) % canvas.width, y = Math.floor((i - 3) / 4 / canvas.width);
|
|
279
|
+
assert.ok(x >= Math.floor(ink.x) - 1 &&
|
|
280
|
+
y >= Math.floor(ink.y) - 1 &&
|
|
281
|
+
x <= Math.ceil(ink.x + ink.w) + 1 &&
|
|
282
|
+
y <= Math.ceil(ink.y + ink.h) + 1, `${family} ${element.getCategory()} pixel ${x},${y} outside ${JSON.stringify(ink)}`);
|
|
283
|
+
count++;
|
|
284
|
+
}
|
|
285
|
+
assert.ok(count > 10);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
test('browser SVG keeps one rehearsal mark, the dynamic and the pedal through reflow', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
290
|
+
const browser = yield puppeteer.launch({ headless: true, args: process.env.CI ? ['--no-sandbox'] : [] });
|
|
291
|
+
try {
|
|
292
|
+
const page = yield browser.newPage();
|
|
293
|
+
yield page.setContent('<style>body {background:white}</style><div id="score"></div>');
|
|
294
|
+
yield page.addScriptTag({ path: new URL('../../build/cjs/vexflow-debug.js', import.meta.url).pathname });
|
|
295
|
+
yield page.addScriptTag({
|
|
296
|
+
content: `const durations = new Map([['1/1','w'],['1/2','h']]); const compositionInput = ${compositionInput}; const passageView = ${passageView};`,
|
|
297
|
+
});
|
|
298
|
+
const snapshots = yield page.evaluate((score) => __awaiter(void 0, void 0, void 0, function* () {
|
|
299
|
+
yield document.fonts.ready;
|
|
300
|
+
const f = new VexFlow.Factory({
|
|
301
|
+
renderer: { elementId: 'score', width: 800, height: 700 },
|
|
302
|
+
engraving: new VexFlow.EngravingProfile({ musicFont: 'Petaluma' }),
|
|
303
|
+
});
|
|
304
|
+
const view = passageView({ VexFlow }, f, score);
|
|
305
|
+
return [720, 250, 720].map((width) => {
|
|
306
|
+
const rendering = view.draw(width);
|
|
307
|
+
const nodes = [...document.querySelectorAll('#score svg text')];
|
|
308
|
+
const boxes = nodes.map((node) => {
|
|
309
|
+
const b = node.getBBox();
|
|
310
|
+
return [node.textContent, b.x, b.y, b.width, b.height];
|
|
311
|
+
});
|
|
312
|
+
const head = view.composition.getNote('u3b');
|
|
313
|
+
const mark = view.dynamics[0].glyph;
|
|
314
|
+
return {
|
|
315
|
+
rendering,
|
|
316
|
+
boxes,
|
|
317
|
+
owner: head.getAttribute('id'),
|
|
318
|
+
baseline: VexFlow.measureEngraving(mark).anchors.baseline.y,
|
|
319
|
+
dynamic: boxes.filter((b) => b[0] === VexFlow.Glyphs.dynamicPiano),
|
|
320
|
+
rehearsal: boxes.filter((b) => b[0] === 'B'),
|
|
321
|
+
};
|
|
322
|
+
});
|
|
323
|
+
}), passage);
|
|
324
|
+
const [wide, narrow, restored] = snapshots;
|
|
325
|
+
assert.deepEqual(restored, wide);
|
|
326
|
+
assert.equal(narrow.rendering.fragments.length, 2);
|
|
327
|
+
for (const s of snapshots) {
|
|
328
|
+
assert.equal(s.owner, 'u3b');
|
|
329
|
+
assert.equal(s.rehearsal.length, 1);
|
|
330
|
+
assert.equal(s.dynamic.length, 1);
|
|
331
|
+
assert.ok(s.dynamic[0][3] > 0 && s.rehearsal[0][3] > 0);
|
|
332
|
+
assert.ok(s.dynamic[0][2] < s.baseline && s.dynamic[0][2] + s.dynamic[0][4] >= s.baseline);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
finally {
|
|
336
|
+
yield browser.close();
|
|
337
|
+
}
|
|
338
|
+
}));
|
|
339
|
+
test('contour beams preserve membership, minimum stems, beamlet overrides and endpoints across widths', () => {
|
|
340
|
+
for (const width of [190, 340, 790]) {
|
|
341
|
+
for (const stem of ['up', 'down']) {
|
|
342
|
+
const { f } = factory(), es = f.EasyScore();
|
|
343
|
+
const notes = es.notes('G4/8, A4/16, B4/8, C4/8', { stem });
|
|
344
|
+
const beam = f.Beam({ notes });
|
|
345
|
+
beam.renderOptions.contourSlope = true;
|
|
346
|
+
beam.setPartialBeamSideAt(1, 'R');
|
|
347
|
+
const sys = f.System({ width, y: 60 });
|
|
348
|
+
sys.addStave({ voices: [es.voice(notes, { mode: 'soft' })] });
|
|
349
|
+
sys.format();
|
|
350
|
+
measured(beam);
|
|
351
|
+
assert.deepEqual(beam.getNotes(), notes);
|
|
352
|
+
const first = notes[0], last = notes.at(-1);
|
|
353
|
+
assert.ok(beam.slope * (last.getYs()[0] - first.getYs()[0]) >= -1e-7);
|
|
354
|
+
for (const n of notes) {
|
|
355
|
+
const tip = n.getStemExtents().topY;
|
|
356
|
+
const expected = beam.getBeamYToDraw() + beam.slope * (n.getStemX() - first.getStemX());
|
|
357
|
+
assert.ok(Math.abs(tip - expected) < 1e-6);
|
|
358
|
+
assert.ok(Math.abs(tip - n.getYs()[0]) >= n.getStemMinimumLength() - 1);
|
|
359
|
+
}
|
|
360
|
+
const [beamlet] = beam.getBeamLines('8');
|
|
361
|
+
assert.equal(beamlet.end - beamlet.start, beam.renderOptions.partialBeamLength);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
test('before and after grace groups on two staves clear their hosts at the start of a system', () => {
|
|
366
|
+
const { f } = factory(), es = f.EasyScore();
|
|
367
|
+
const sys = f.System({ width: 650 });
|
|
368
|
+
const groups = [];
|
|
369
|
+
for (const key of ['c/5', 'e/4']) {
|
|
370
|
+
const host = f.StaveNote({ keys: [key], duration: 'w' });
|
|
371
|
+
const sides = [VF.Modifier.Position.LEFT, VF.Modifier.Position.RIGHT].map((side, i) => {
|
|
372
|
+
const grace = f
|
|
373
|
+
.GraceNoteGroup({
|
|
374
|
+
notes: Array.from({ length: i + 1 }, () => f.GraceNote({ keys: [key], duration: '16', slash: true })),
|
|
375
|
+
slur: true,
|
|
376
|
+
})
|
|
377
|
+
.setPosition(side);
|
|
378
|
+
if (i)
|
|
379
|
+
grace.beamNotes();
|
|
380
|
+
host.addModifier(grace, 0);
|
|
381
|
+
return grace;
|
|
382
|
+
});
|
|
383
|
+
sys.addStave({ voices: [es.voice([host])] });
|
|
384
|
+
groups.push({ host, sides });
|
|
385
|
+
}
|
|
386
|
+
sys.format();
|
|
387
|
+
for (const { host, sides: [before, after], } of groups) {
|
|
388
|
+
measured(before);
|
|
389
|
+
measured(after);
|
|
390
|
+
const [head] = host.getHeadInk();
|
|
391
|
+
const pre = before.getGraceNotes().at(-1).getHeadInk()[0];
|
|
392
|
+
const post = after.getGraceNotes()[0].getHeadInk()[0];
|
|
393
|
+
assert.ok(pre.x + pre.w < head.x);
|
|
394
|
+
assert.ok(post.x > head.x + head.w);
|
|
395
|
+
assert.ok(pre.x >= host.checkStave().getX());
|
|
396
|
+
for (const [group, offset] of [
|
|
397
|
+
[before, 0],
|
|
398
|
+
[after, host.getGlyphWidth()],
|
|
399
|
+
]) {
|
|
400
|
+
const slur = group.getLayoutElements().at(-1);
|
|
401
|
+
const start = slur.getFirstX() + slur.renderOptions.firstXShift - slur.renderOptions.tieSpacing;
|
|
402
|
+
assert.ok(Math.abs(start - host.getNoteHeadBeginX() - offset) < 1e-7);
|
|
403
|
+
}
|
|
404
|
+
assert.equal(after.getGraceNotes()[0].getStave(), host.getStave());
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
test('four voice columns avoid heads and rests, preserve distinct attacks and repeat for reversed voice input', () => {
|
|
408
|
+
function passage(reverse) {
|
|
409
|
+
const { f } = factory(), es = f.EasyScore();
|
|
410
|
+
const entries = ['F5/q, G5/q', 'E5/8, C5/8, D5/q', 'D5/q, E5/q', 'B4/q/r, B4/q'].map((input, i) => {
|
|
411
|
+
const notes = es.notes(input, { stem: i % 2 ? 'down' : 'up' });
|
|
412
|
+
if (i === 0)
|
|
413
|
+
VF.Dot.buildAndAttach([notes[0]]);
|
|
414
|
+
if (i === 2)
|
|
415
|
+
notes[0].addModifier(new VF.Accidental('#'), 0);
|
|
416
|
+
return { notes, voice: es.voice(notes, { mode: 'soft' }) };
|
|
417
|
+
});
|
|
418
|
+
const sys = f.System({ width: 490 });
|
|
419
|
+
const voices = entries.map((e) => e.voice);
|
|
420
|
+
sys.addStave({ voices: reverse ? voices.reverse() : voices });
|
|
421
|
+
sys.format();
|
|
422
|
+
const boxes = entries.flatMap((e) => e.notes.flatMap((n) => [...n.getHeadInk(), ...n.getModifiers().map((m) => m.getInkBounds())]));
|
|
423
|
+
for (const [i, a] of boxes.entries())
|
|
424
|
+
for (const b of boxes.slice(i + 1))
|
|
425
|
+
assert.ok(a.x + a.w <= b.x + 1 || b.x + b.w <= a.x + 1 || a.y + a.h <= b.y + 1 || b.y + b.h <= a.y + 1, 'voice head, rest, dot or sign overlapped');
|
|
426
|
+
return entries.map((e) => e.notes.map((n) => [n.getNoteHeadBeginX(), n.getYs()[0]]));
|
|
427
|
+
}
|
|
428
|
+
assert.deepEqual(passage(true), passage(false));
|
|
429
|
+
});
|
|
430
|
+
test('bracket and label clear upper and lower ornament signs before drawing and after resize', () => {
|
|
431
|
+
for (const [position, location] of [
|
|
432
|
+
[VF.Modifier.Position.ABOVE, 1],
|
|
433
|
+
[VF.Modifier.Position.BELOW, -1],
|
|
434
|
+
]) {
|
|
435
|
+
const { f } = factory(), es = f.EasyScore();
|
|
436
|
+
const notes = es.notes('G4/8, A4/8, B4/8');
|
|
437
|
+
const mark = new VF.Ornament('turn').setPosition(position).setUpperAccidental('#').setLowerAccidental('b');
|
|
438
|
+
notes[1].addModifier(mark, 0);
|
|
439
|
+
const tuplet = f.Tuplet({ notes, options: { bracketed: true, location } });
|
|
440
|
+
const system = f.System({ width: 430, y: 80 });
|
|
441
|
+
system.addStave({ voices: [es.voice(notes, { mode: 'soft' })] });
|
|
442
|
+
for (const width of [430, 260, 430]) {
|
|
443
|
+
system.setWidth(width).format();
|
|
444
|
+
const bracket = measured(tuplet).ink, sign = measured(mark).ink;
|
|
445
|
+
const gap = location === 1 ? sign.y - bracket.y - bracket.h : bracket.y - sign.y - sign.h;
|
|
446
|
+
assert.ok(gap >= 2, 'Bracket clears nearest auxiliary accidental by at least two pixels');
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
});
|
|
@@ -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
|
+
}));
|