vexflow 5.4.0 → 5.6.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/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 +1740 -372
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +565 -258
- 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/annotation.js +2 -1
- package/build/esm/src/continuouslayout.js +107 -16
- package/build/esm/src/continuousspan.js +9 -1
- package/build/esm/src/easyscore/composition.js +83 -18
- package/build/esm/src/factory.js +2 -9
- package/build/esm/src/formatter.js +1 -1
- package/build/esm/src/fretdiagram.js +6 -2
- package/build/esm/src/gracenotegroup.js +4 -3
- package/build/esm/src/guitarmodifiers.js +4 -1
- package/build/esm/src/metrics.js +24 -5
- package/build/esm/src/note.js +1 -0
- package/build/esm/src/notehead.js +21 -10
- package/build/esm/src/phraselayout.js +13 -5
- package/build/esm/src/publication.js +10 -5
- package/build/esm/src/publicationview.js +3 -2
- package/build/esm/src/stave.js +4 -2
- package/build/esm/src/stavenote.js +56 -13
- package/build/esm/src/stavesection.js +15 -10
- package/build/esm/src/stavetie.js +3 -2
- package/build/esm/src/strokes.js +1 -1
- package/build/esm/src/svgcontext.js +11 -3
- package/build/esm/src/tabnote.js +6 -8
- package/build/esm/src/tabtie.js +3 -0
- package/build/esm/src/version.js +3 -3
- package/build/esm/tests/chordsymbol_tests.js +4 -1
- package/build/esm/tests/demo_petzold_tests.js +26 -14
- package/build/esm/tests/demo_repertoire_tests.js +5 -1
- package/build/esm/tests/demos/ballade.js +15 -0
- package/build/esm/tests/demos/electric.js +1 -3
- package/build/esm/tests/demos/fugue.js +19 -0
- package/build/esm/tests/demos/greensleeves.js +1 -2
- package/build/esm/tests/demos/kesh.js +2 -3
- package/build/esm/tests/demos/saints.js +17 -5
- package/build/esm/tests/engraving/continuous-studies.mjs +24 -0
- package/build/esm/tests/engraving/publication-studies.mjs +30 -0
- package/build/esm/tests/font_tests.js +8 -0
- package/build/esm/tests/gracenote_tests.js +1 -1
- package/build/esm/tests/gracetabnote_tests.js +19 -3
- package/build/esm/tests/node/chord-kerning-tests.mjs +2 -2
- package/build/esm/tests/node/continuous-score-tests.mjs +157 -2
- package/build/esm/tests/node/easyscore-tests.mjs +38 -0
- package/build/esm/tests/node/engraving-layout-tests.mjs +33 -0
- package/build/esm/tests/node/instrument-profile-tests.mjs +40 -0
- package/build/esm/tests/node/local-engraving-tests.mjs +58 -0
- package/build/esm/tests/node/metrics-tests.mjs +2 -0
- package/build/esm/tests/node/phrase-layout-tests.mjs +58 -5
- package/build/esm/tests/node/publication-tests.mjs +158 -2
- package/build/esm/tests/node/svg-export-tests.mjs +50 -21
- package/build/esm/tests/scores/ballade.js +399 -0
- package/build/esm/tests/scores/drums.js +93 -0
- package/build/esm/tests/scores/electric.js +83 -0
- package/build/esm/tests/scores/falseta.js +46 -0
- package/build/esm/tests/scores/fugue.js +366 -0
- package/build/esm/tests/scores/guitar.js +32 -0
- package/build/esm/tests/scores/kesh.js +146 -0
- package/build/esm/tests/scores/prelude.js +84 -0
- package/build/esm/tests/scores/quartertones.js +78 -0
- package/build/esm/tests/scores/saints.js +70 -0
- package/build/esm/tests/scores/sumer.js +126 -0
- package/build/esm/tests/scores/viewer.js +162 -0
- package/build/esm/tests/tabnote_tests.js +43 -0
- package/build/esm/tests/vexflow_test_helpers.js +1 -0
- package/build/esm/tools/explorer/catalog/expression.mjs +16 -6
- package/build/esm/tools/explorer/catalog/guitar.mjs +2 -2
- package/build/types/src/continuouslayout.d.ts +4 -0
- package/build/types/src/continuousspan.d.ts +10 -2
- package/build/types/src/easyscore/composition.d.ts +19 -0
- package/build/types/src/fretdiagram.d.ts +2 -0
- package/build/types/src/instrumentprofile.d.ts +4 -0
- package/build/types/src/note.d.ts +2 -0
- package/build/types/src/notehead.d.ts +2 -0
- package/build/types/src/publication.d.ts +3 -1
- package/build/types/src/stave.d.ts +4 -2
- package/build/types/src/stavenote.d.ts +10 -0
- package/build/types/src/stavesection.d.ts +3 -0
- package/build/types/src/svgcontext.d.ts +2 -0
- package/build/types/src/typeguard.d.ts +1 -0
- package/changelog/CHANGELOG.md +16 -0
- package/package.json +4 -1
- package/tests/all.html +9 -0
- package/tests/demo_petzold_tests.ts +30 -16
- package/tests/demos/ballade.ts +36 -0
- package/tests/demos/ballade.webp +0 -0
- package/tests/demos/electric.ts +1 -3
- package/tests/demos/electric.webp +0 -0
- package/tests/demos/fugue.ts +27 -0
- package/tests/demos/fugue.webp +0 -0
- package/tests/demos/greensleeves.ts +1 -3
- package/tests/demos/greensleeves.webp +0 -0
- package/tests/demos/kesh.ts +2 -4
- package/tests/demos/kesh.webp +0 -0
- package/tests/demos/saints.ts +20 -7
- package/tests/demos/saints.webp +0 -0
- package/tests/flow.html +165 -52
- package/tests/minuet.webp +0 -0
- package/tests/scores/ballade.js +445 -0
- package/tests/scores/drums.js +101 -0
- package/tests/scores/drums.webp +0 -0
- package/tests/scores/electric.js +93 -0
- package/tests/scores/electric.webp +0 -0
- package/tests/scores/falseta.js +53 -0
- package/tests/scores/falseta.webp +0 -0
- package/tests/scores/fugue.js +433 -0
- package/tests/scores/guitar.js +34 -0
- package/tests/scores/index.html +48 -0
- package/tests/scores/kesh.js +171 -0
- package/tests/scores/kesh.webp +0 -0
- package/tests/scores/prelude.js +90 -0
- package/tests/scores/prelude.webp +0 -0
- package/tests/scores/quartertones.js +83 -0
- package/tests/scores/quartertones.webp +0 -0
- package/tests/scores/saints.js +85 -0
- package/tests/scores/saints.webp +0 -0
- package/tests/scores/sumer.js +139 -0
- package/tests/scores/sumer.webp +0 -0
- package/tests/scores/viewer.css +132 -0
- package/tests/scores/viewer.js +150 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { VexFlowTests } from './vexflow_test_helpers.js';
|
|
2
|
+
import { ballade } from './demos/ballade.js';
|
|
2
3
|
import { drums } from './demos/drums.js';
|
|
3
4
|
import { electric } from './demos/electric.js';
|
|
5
|
+
import { fugue } from './demos/fugue.js';
|
|
4
6
|
import { greensleeves } from './demos/greensleeves.js';
|
|
5
7
|
import { joy } from './demos/joy.js';
|
|
6
8
|
import { kesh } from './demos/kesh.js';
|
|
@@ -8,9 +10,11 @@ import { prelude } from './demos/prelude.js';
|
|
|
8
10
|
import { quartertones } from './demos/quartertones.js';
|
|
9
11
|
import { saints } from './demos/saints.js';
|
|
10
12
|
const repertoire = [
|
|
11
|
-
{ title: 'When the Saints Go Marching In', render: saints, fonts: ['Petaluma'] },
|
|
13
|
+
{ title: 'When the Saints Go Marching In', render: saints, fonts: ['Petaluma with Academico'] },
|
|
12
14
|
{ title: 'Greensleeves', render: greensleeves },
|
|
13
15
|
{ title: 'Prelude in C major', render: prelude },
|
|
16
|
+
{ title: 'Fugue No. 6 in D minor', render: fugue },
|
|
17
|
+
{ title: 'Ballade No. 3 in A-flat major', render: ballade },
|
|
14
18
|
{ title: 'The Kesh Jig', render: kesh },
|
|
15
19
|
{ title: 'Ode to Joy', render: joy },
|
|
16
20
|
{ title: 'High Wire', render: electric },
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { VexFlowTests } from '../vexflow_test_helpers.js';
|
|
2
|
+
import { Accidental, Factory, Fraction, PedalMarking, StaveHairpin, Stroke, TextDynamics, Tuplet, } from '../../src/index.js';
|
|
3
|
+
import '../scores/ballade.js';
|
|
4
|
+
export function ballade(options) {
|
|
5
|
+
const { draw, width, height } = globalThis.ChopinBallade;
|
|
6
|
+
const factory = VexFlowTests.makeFactory(options, width, Math.ceil(height));
|
|
7
|
+
const systems = draw({ Accidental, Factory, Fraction, PedalMarking, StaveHairpin, Stroke, TextDynamics, Tuplet }, factory);
|
|
8
|
+
options.assert.deepEqual(systems.map((system) => system.measures), [
|
|
9
|
+
[1, 2, 3, 4, 5, 6],
|
|
10
|
+
[7, 8, 9, 10, 11, 12],
|
|
11
|
+
[13, 14, 15, 16],
|
|
12
|
+
[17, 18, 19, 20],
|
|
13
|
+
[21, 22, 23, 24],
|
|
14
|
+
], 'All five systems retain the breaks of the printed page');
|
|
15
|
+
}
|
|
@@ -26,9 +26,7 @@ export function electric(options) {
|
|
|
26
26
|
stave.addTimeSignature('4/4').setTempo({ duration: 'q', bpm: 96 }, -8);
|
|
27
27
|
if (i === 3)
|
|
28
28
|
stave.setEndBarType(BarlineType.END);
|
|
29
|
-
const legato = (start, label) => score.make
|
|
30
|
-
.tabTie({ firstNote: notes[start], lastNote: notes[start + 1] }, label)
|
|
31
|
-
.setFont('Arial, Helvetica, sans-serif', 9, 'bold');
|
|
29
|
+
const legato = (start, label) => score.make.tabTie({ firstNote: notes[start], lastNote: notes[start + 1] }, label);
|
|
32
30
|
if (i === 0) {
|
|
33
31
|
score.beam(notes.slice(1, 3));
|
|
34
32
|
legato(1, 'H');
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { VexFlowTests } from '../vexflow_test_helpers.js';
|
|
2
|
+
import { Fraction, TextDynamics } from '../../src/index.js';
|
|
3
|
+
import '../scores/fugue.js';
|
|
4
|
+
export function fugue(options) {
|
|
5
|
+
const width = 1300;
|
|
6
|
+
const factory = VexFlowTests.makeFactory(options, width, 640);
|
|
7
|
+
const score = factory.EasyScore({ throwOnError: true, extensions: ['spacer', 'ornament', 'dynamic'] });
|
|
8
|
+
const notation = { Fraction, TextDynamics };
|
|
9
|
+
score.addCommitHook(globalThis.BachFugue.noteMarks(notation));
|
|
10
|
+
const music = globalThis.BachFugue.music(notation, 8);
|
|
11
|
+
music.system = Object.assign(Object.assign({}, music.system), { spaceBetweenStaves: 6 });
|
|
12
|
+
music.sheet = { x: 18, y: 18, width: width - 36, measurePadding: 18, rowGap: 18 };
|
|
13
|
+
const { sheet, systems, staves } = score.compose(music);
|
|
14
|
+
sheet.format();
|
|
15
|
+
factory.getContext().resize(width, Math.ceil(sheet.getHeight() + 24));
|
|
16
|
+
factory.draw();
|
|
17
|
+
options.assert.equal(systems.length, 8, 'Eight complete measures');
|
|
18
|
+
options.assert.ok(staves.every((pair) => pair.length === 2), 'Both hands share the grand staff throughout');
|
|
19
|
+
}
|
|
@@ -22,7 +22,6 @@ const positions = {
|
|
|
22
22
|
export function greensleeves(options) {
|
|
23
23
|
const f = VexFlowTests.makeFactory(options, 900, 486);
|
|
24
24
|
const score = f.EasyScore({ throwOnError: true });
|
|
25
|
-
const chordFont = { fontFamily: 'Arial, Helvetica, sans-serif', fontSize: 12 };
|
|
26
25
|
const bars = [
|
|
27
26
|
['', 'A4/q'],
|
|
28
27
|
['Am', 'A3+E4+A4+C5/h D5/q'],
|
|
@@ -49,7 +48,7 @@ export function greensleeves(options) {
|
|
|
49
48
|
});
|
|
50
49
|
const notes = score.notes(music.join(', '));
|
|
51
50
|
if (chordName)
|
|
52
|
-
notes[0].addModifier(score.make.chordSymbol(
|
|
51
|
+
notes[0].addModifier(score.make.chordSymbol().addText(chordName));
|
|
53
52
|
const tab = events.map(({ pitches, duration }) => score.make.tabNote({
|
|
54
53
|
positions: pitches.map((pitch) => {
|
|
55
54
|
const [str, fret] = positions[pitch];
|
|
@@ -4,7 +4,6 @@ export function kesh(options) {
|
|
|
4
4
|
const f = VexFlowTests.makeFactory(options, 900, 580);
|
|
5
5
|
const score = f.EasyScore({ throwOnError: true });
|
|
6
6
|
score.set({ time: '6/8' });
|
|
7
|
-
const chordFont = { fontFamily: 'Arial, Helvetica, sans-serif', fontSize: 12 };
|
|
8
7
|
const strains = [
|
|
9
8
|
[
|
|
10
9
|
['G4/q, G4/8', 'G4/8, A4, B4', 'G'],
|
|
@@ -44,9 +43,9 @@ export function kesh(options) {
|
|
|
44
43
|
score.beam(beat);
|
|
45
44
|
}
|
|
46
45
|
if (chord)
|
|
47
|
-
beats[0][0].addModifier(score.make.chordSymbol(
|
|
46
|
+
beats[0][0].addModifier(score.make.chordSymbol().addText(chord));
|
|
48
47
|
if (nextChord)
|
|
49
|
-
beats[1][0].addModifier(score.make.chordSymbol(
|
|
48
|
+
beats[1][0].addModifier(score.make.chordSymbol().addText(nextChord));
|
|
50
49
|
if (i === 0 || i === 4) {
|
|
51
50
|
const grace = score.make.graceNote({ keys: [part ? 'd/5' : 'b/4'], duration: '8', slash: true });
|
|
52
51
|
notes[1].addModifier(score.make.graceNoteGroup({ notes: [grace], slur: true }));
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { VexFlowTests } from '../vexflow_test_helpers.js';
|
|
2
2
|
import { BarlineType, ChordSymbol } from '../../src/index.js';
|
|
3
|
+
import { Metrics } from '../../src/metrics.js';
|
|
3
4
|
export function saints(options) {
|
|
4
5
|
const factory = VexFlowTests.makeFactory(options, 900, 540);
|
|
5
6
|
const score = factory.EasyScore({ throwOnError: true });
|
|
7
|
+
const lyricFont = Metrics.getFontInfo('Annotation.lyric');
|
|
8
|
+
const word = (text, rowY) => factory
|
|
9
|
+
.Annotation({ text, font: lyricFont, vJustify: 'bottom' })
|
|
10
|
+
.setTextBaseline(rowY + 116)
|
|
11
|
+
.setConnectorPadding(2);
|
|
6
12
|
const bars = [
|
|
7
13
|
['G4/w', 'saints', 'C:6/9'],
|
|
8
14
|
['B4/q/r, C4/q, E4, F4', '|go|march-|ing', 'Am:7'],
|
|
@@ -23,18 +29,23 @@ export function saints(options) {
|
|
|
23
29
|
];
|
|
24
30
|
const pickup = score.notes('C4/q, E4, F4');
|
|
25
31
|
const pickupLabels = ['Oh', 'when', 'the'];
|
|
26
|
-
pickup.forEach((note, i) => note.addModifier(
|
|
32
|
+
pickup.forEach((note, i) => note.addModifier(word(pickupLabels[i], 16)));
|
|
33
|
+
const pickupWidth = 210;
|
|
27
34
|
factory
|
|
28
|
-
.System({ x: 10, y: 16, width:
|
|
35
|
+
.System({ x: 10, y: 16, width: pickupWidth })
|
|
29
36
|
.addStave({ voices: [score.voice(pickup, { time: '3/4' })] })
|
|
30
37
|
.addClef('treble')
|
|
31
38
|
.addTimeSignature('4/4');
|
|
39
|
+
const openingWidths = [120, 212, 122, 212];
|
|
40
|
+
let x = 10 + pickupWidth;
|
|
32
41
|
let sustained;
|
|
33
42
|
bars.forEach(([music, words, harmony], i) => {
|
|
34
43
|
const row = Math.floor(i / 4);
|
|
35
44
|
const column = i % 4;
|
|
36
45
|
const y = 16 + row * 130;
|
|
37
|
-
|
|
46
|
+
if (column === 0 && row > 0)
|
|
47
|
+
x = 10;
|
|
48
|
+
const width = row === 0 ? openingWidths[column] : 219;
|
|
38
49
|
const notes = score.notes(music);
|
|
39
50
|
if (i === 5 || i === 14)
|
|
40
51
|
sustained = notes[0];
|
|
@@ -42,7 +53,7 @@ export function saints(options) {
|
|
|
42
53
|
score.make.tie({ from: sustained, to: notes[0] });
|
|
43
54
|
words.split('|').forEach((text, n) => {
|
|
44
55
|
if (text)
|
|
45
|
-
notes[n].addModifier(
|
|
56
|
+
notes[n].addModifier(word(text, y));
|
|
46
57
|
});
|
|
47
58
|
if (harmony) {
|
|
48
59
|
const [root, extension] = harmony.split(':');
|
|
@@ -53,8 +64,9 @@ export function saints(options) {
|
|
|
53
64
|
notes[0].addModifier(chord);
|
|
54
65
|
}
|
|
55
66
|
const stave = factory
|
|
56
|
-
.System({ x
|
|
67
|
+
.System({ x, y, width })
|
|
57
68
|
.addStave({ voices: [score.voice(notes, { time: i === 15 ? '1/4' : '4/4' })] });
|
|
69
|
+
x += width;
|
|
58
70
|
if (column === 0 && row > 0)
|
|
59
71
|
stave.addClef('treble');
|
|
60
72
|
if (i === bars.length - 1)
|
|
@@ -138,3 +138,27 @@ export function makeContinuousStudy(VF, factory, kind, width, mode = 'balanced')
|
|
|
138
138
|
result.getNote('v00').addModifier(factory.Annotation({ text: 'Sing' }), 0);
|
|
139
139
|
return result;
|
|
140
140
|
}
|
|
141
|
+
export function tabEndingStudy() {
|
|
142
|
+
const positions = [
|
|
143
|
+
{ str: 1, fret: 12 },
|
|
144
|
+
{ str: 2, fret: 10 },
|
|
145
|
+
];
|
|
146
|
+
return {
|
|
147
|
+
staves: [
|
|
148
|
+
{
|
|
149
|
+
id: 'guitar',
|
|
150
|
+
kind: 'tab',
|
|
151
|
+
time: '1/4',
|
|
152
|
+
measures: [positions, [...positions].reverse()].map((chord, i) => ({
|
|
153
|
+
voices: [{ notes: [{ id: 'tab' + i, tab: { duration: 'q', positions: chord } }] }],
|
|
154
|
+
})),
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
continuous: {
|
|
158
|
+
spans: [
|
|
159
|
+
{ id: 'hold', kind: 'tie', from: 'tab0', to: 'tab1', fromHead: 1 },
|
|
160
|
+
{ id: 'ending', kind: 'volta', from: 'tab0', to: 'tab1', text: '1.' },
|
|
161
|
+
],
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
}
|
|
@@ -85,3 +85,33 @@ export function publicationStudy(part, paper) {
|
|
|
85
85
|
: {}));
|
|
86
86
|
return { source, options };
|
|
87
87
|
}
|
|
88
|
+
export function leadSheetStudy() {
|
|
89
|
+
const measure = (id, pitches) => ({
|
|
90
|
+
voices: [
|
|
91
|
+
{
|
|
92
|
+
notes: pitches.map((key, i) => ({ id: id + i, note: { keys: [key], duration: '8' } })),
|
|
93
|
+
autoBeam: true,
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
});
|
|
97
|
+
const first = measure('a', ['c/4', 'd/4', 'e/4', 'g/4', 'a/4', 'g/4']);
|
|
98
|
+
const second = measure('b', ['e/4', 'f/4', 'g/4', 'f/4', 'e/4', 'c/4']);
|
|
99
|
+
first.chords = [{ note: 'a0', text: 'Cmaj7' }];
|
|
100
|
+
first.verses = [
|
|
101
|
+
[
|
|
102
|
+
{ note: 'a0', text: 'Day', hyphenAfter: true },
|
|
103
|
+
{ note: 'a3', text: 'light', extendTo: 'a5' },
|
|
104
|
+
],
|
|
105
|
+
];
|
|
106
|
+
first.endBarline = VexFlow.Barline.type.DOUBLE;
|
|
107
|
+
second.endBarline = VexFlow.Barline.type.END;
|
|
108
|
+
const lead = { id: 'lead', time: '6/8', showTimeSignature: false, measures: [first, second] };
|
|
109
|
+
const bass = {
|
|
110
|
+
id: 'bass',
|
|
111
|
+
clef: 'bass',
|
|
112
|
+
time: '6/8',
|
|
113
|
+
showTimeSignature: false,
|
|
114
|
+
measures: [0, 1].map(() => ({ voices: [{ notes: 'C3/q., G3/q.' }] })),
|
|
115
|
+
};
|
|
116
|
+
return { staves: [lead, bass], continuous: {} };
|
|
117
|
+
}
|
|
@@ -139,6 +139,14 @@ function textFontDefaults(assert) {
|
|
|
139
139
|
const previous = MetricsDefaults.Annotation.fontFamily;
|
|
140
140
|
try {
|
|
141
141
|
VexFlow.setFonts('Bravura', 'Academico');
|
|
142
|
+
const note = new VexFlow.TabNote({ positions: [{ str: 1, fret: 5 }], duration: 'q' });
|
|
143
|
+
const ends = { firstNote: note, lastNote: note };
|
|
144
|
+
assert.equal(new VexFlow.ChordSymbol().fontSizeInPoints, 14);
|
|
145
|
+
assert.equal(Metrics.getFontInfo('Annotation.lyric').size, 12);
|
|
146
|
+
assert.equal(new VexFlow.TabTie(ends, 'H').fontInfo.family.split(',')[0], 'Arial');
|
|
147
|
+
assert.equal(new VexFlow.StaveTie(ends, 'H').fontInfo.family.split(',')[0], 'Academico');
|
|
148
|
+
assert.equal(new VexFlow.TabTie(ends, 'hold').fontInfo.family.split(',')[0], 'Academico');
|
|
149
|
+
assert.equal(new Bend([{ type: Bend.UP, text: 'full' }]).fontInfo.family.split(',')[0], 'Academico');
|
|
142
150
|
const annotation = new VexFlow.Annotation('Sing with gentle voices');
|
|
143
151
|
const ctx = document.createElement('canvas').getContext('2d');
|
|
144
152
|
ctx.font = Font.toCSSString(annotation.fontInfo);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { VexFlow } from '../src/vexflow.js';
|
|
2
2
|
import { VexFlowTests } from './vexflow_test_helpers.js';
|
|
3
|
-
import { ModifierPosition } from '../src.js';
|
|
4
3
|
import { Accidental } from '../src/accidental.js';
|
|
5
4
|
import { Annotation } from '../src/annotation.js';
|
|
6
5
|
import { Articulation } from '../src/articulation.js';
|
|
@@ -8,6 +7,7 @@ import { Dot } from '../src/dot.js';
|
|
|
8
7
|
import { Formatter } from '../src/formatter.js';
|
|
9
8
|
import { GraceNote } from '../src/gracenote.js';
|
|
10
9
|
import { GraceNoteGroup } from '../src/gracenotegroup.js';
|
|
10
|
+
import { ModifierPosition } from '../src/modifier.js';
|
|
11
11
|
import { StaveNote } from '../src/stavenote.js';
|
|
12
12
|
const GraceNoteTests = {
|
|
13
13
|
Start() {
|
|
@@ -5,6 +5,7 @@ import { Formatter } from '../src/formatter.js';
|
|
|
5
5
|
import { GraceNoteGroup } from '../src/gracenotegroup.js';
|
|
6
6
|
import { GraceTabNote } from '../src/gracetabnote.js';
|
|
7
7
|
import { Metrics, MetricsDefaults } from '../src/metrics.js';
|
|
8
|
+
import { ModifierPosition } from '../src/modifier.js';
|
|
8
9
|
import { TabNote } from '../src/tabnote.js';
|
|
9
10
|
import { TabStave } from '../src/tabstave.js';
|
|
10
11
|
import { Voice } from '../src/voice.js';
|
|
@@ -13,6 +14,7 @@ const GraceTabNoteTests = {
|
|
|
13
14
|
QUnit.module('Grace Tab Notes');
|
|
14
15
|
QUnit.test('fretSizing', fretSizing);
|
|
15
16
|
const run = VexFlowTests.runTests;
|
|
17
|
+
run('Grace frets beside a two-digit host', graceClearance, undefined, ['Bravura']);
|
|
16
18
|
run('Grace Tab Note Simple', simple);
|
|
17
19
|
run('Grace Tab Note Slurred', slurred);
|
|
18
20
|
},
|
|
@@ -24,6 +26,19 @@ function setupContext(opts, ctxBuilder) {
|
|
|
24
26
|
const stave = new TabStave(10, 10, 350).addTabGlyph().setContext(context).drawWithStyle();
|
|
25
27
|
return { context, stave };
|
|
26
28
|
}
|
|
29
|
+
function graceClearance(options, contextBuilder) {
|
|
30
|
+
const { context, stave } = setupContext(options, contextBuilder);
|
|
31
|
+
const positions = [{ str: 2, fret: 12 }];
|
|
32
|
+
const host = new TabNote({ positions, duration: 'w' });
|
|
33
|
+
const before = new GraceTabNote({ positions: [{ str: 2, fret: 2 }], duration: '8' });
|
|
34
|
+
const after = new GraceTabNote({ positions, duration: '8' });
|
|
35
|
+
host.addModifier(new GraceNoteGroup([before]));
|
|
36
|
+
host.addModifier(new GraceNoteGroup([after]).setPosition(ModifierPosition.RIGHT));
|
|
37
|
+
Formatter.FormatAndDraw(context, stave, [host]);
|
|
38
|
+
const hostHalfWidth = TabNote.tabToElement('12').getWidth() / 2;
|
|
39
|
+
options.assert.ok(before.getAbsoluteX() + before.getWidth() / 2 + 2 <= host.getAbsoluteX() - hostHalfWidth);
|
|
40
|
+
options.assert.ok(after.getAbsoluteX() - after.getWidth() / 2 - 2 >= host.getAbsoluteX() + hostHalfWidth);
|
|
41
|
+
}
|
|
27
42
|
function simple(options, contextBuilder) {
|
|
28
43
|
const { context, stave } = setupContext(options, contextBuilder);
|
|
29
44
|
const note0 = tabNote({ positions: [{ str: 4, fret: 6 }], duration: '4' });
|
|
@@ -104,13 +119,14 @@ function fretSizing(assert) {
|
|
|
104
119
|
}
|
|
105
120
|
}
|
|
106
121
|
note.setFontSize(7).setGhost(true);
|
|
107
|
-
assert.equal(
|
|
122
|
+
assert.equal(note.getFrets()[0].fontSizeInPoints, 7);
|
|
108
123
|
note.setGhost(false).setFontSize();
|
|
109
|
-
|
|
124
|
+
const normalSize = Font.convertSizeToPointValue(Metrics.getFontInfo('TabNote.text').size);
|
|
125
|
+
assert.ok(Math.abs(note.getFrets()[0].fontSizeInPoints - normalSize * scale) < 0.001);
|
|
110
126
|
MetricsDefaults.GraceTabNote.fontScale = 1 / 3;
|
|
111
127
|
Metrics.clear('GraceTabNote');
|
|
112
128
|
const small = new InspectableGraceTabNote({ positions: [{ str: 2, fret: 12 }], duration: '8' });
|
|
113
|
-
assert.
|
|
129
|
+
assert.ok(Math.abs(small.getFrets()[0].fontSizeInPoints - normalSize / 3) < 0.001);
|
|
114
130
|
}
|
|
115
131
|
finally {
|
|
116
132
|
MetricsDefaults.GraceTabNote.fontScale = scale;
|
|
@@ -17,7 +17,7 @@ const sup = { symbolModifier: ChordSymbol.symbolModifiers.SUPERSCRIPT };
|
|
|
17
17
|
const sub = { symbolModifier: ChordSymbol.symbolModifiers.SUBSCRIPT };
|
|
18
18
|
const state = () => ({ leftShift: 0, rightShift: 0, topTextLine: 0, textLine: 0 });
|
|
19
19
|
const close = (a, b, tolerance = 0.04) => assert.ok(Math.abs(a - b) < tolerance, `${a} ≈ ${b}`);
|
|
20
|
-
function chord(mode = 'auto', family = 'Academico,Bravura', size =
|
|
20
|
+
function chord(mode = 'auto', family = 'Academico,Bravura', size = VF.Metrics.getFontInfo('ChordSymbol').size) {
|
|
21
21
|
const symbol = new ChordSymbol().setFont(family, size).setKerning(mode);
|
|
22
22
|
new StaveNote({ keys: ['c/5'], duration: 'q' }).addModifier(symbol, 0);
|
|
23
23
|
return symbol;
|
|
@@ -123,7 +123,7 @@ test('custom profiles are isolated and shift the following advance as well as in
|
|
|
123
123
|
musicFont: 'Bravura',
|
|
124
124
|
pairs: [{ left: 'A', right: Glyphs.csymDiminished, position: 'superscript', adjustmentEm: 0 }],
|
|
125
125
|
};
|
|
126
|
-
const make = () => diminished(chord()).addText('7');
|
|
126
|
+
const make = () => diminished(chord('auto', 'Academico,Bravura', 12)).addText('7');
|
|
127
127
|
const base = format(make().setKerningProfile(profile));
|
|
128
128
|
profile.pairs[0].adjustmentEm = -0.1;
|
|
129
129
|
const adjusted = format(make().setKerningProfile(profile));
|
|
@@ -12,7 +12,7 @@ import test from 'node:test';
|
|
|
12
12
|
import { readFile } from 'node:fs/promises';
|
|
13
13
|
import puppeteer from 'puppeteer';
|
|
14
14
|
import { createCanvas, registerFont } from 'canvas';
|
|
15
|
-
import { makeContinuousStudy } from '../engraving/continuous-studies.mjs';
|
|
15
|
+
import { makeContinuousStudy, tabEndingStudy } from '../engraving/continuous-studies.mjs';
|
|
16
16
|
const VF = await import(new URL('../../build/esm/entry/vexflow-core.js', import.meta.url));
|
|
17
17
|
for (const family of ['Bravura', 'Academico']) {
|
|
18
18
|
const name = family.toLowerCase();
|
|
@@ -98,6 +98,24 @@ function spec(count, continuous, notes = (i) => [{ id: 'n' + i, note: { keys: ['
|
|
|
98
98
|
continuous,
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
|
+
test('a lyric extender resolves a unique word on its source note during formatting', () => {
|
|
102
|
+
const span = { id: 'hold', kind: 'lyric', from: 'n0', to: 'n1', syllableId: 'word' };
|
|
103
|
+
const compose = (config) => factory()
|
|
104
|
+
.f.EasyScore()
|
|
105
|
+
.compose(spec(2, { spans: [config] }));
|
|
106
|
+
for (const invalid of [{ text: 'duplicate' }, { kind: 'tie' }, { syllableId: '' }]) {
|
|
107
|
+
assert.throws(() => compose(Object.assign(Object.assign({}, span), invalid)), /anchored lyric extender/);
|
|
108
|
+
}
|
|
109
|
+
const c = compose(span);
|
|
110
|
+
const format = () => c.sheet.setWidth(600).format();
|
|
111
|
+
assert.throws(format, /Expected one lyric annotation/);
|
|
112
|
+
const source = c.getNote('n0');
|
|
113
|
+
const word = () => new VF.Annotation('word').setAttribute('id', 'word');
|
|
114
|
+
source.addModifier(word());
|
|
115
|
+
format();
|
|
116
|
+
source.addModifier(word());
|
|
117
|
+
assert.throws(format, /Expected one lyric annotation/);
|
|
118
|
+
});
|
|
101
119
|
test('hard keeps overflow together and forced breaks win over spare space', () => {
|
|
102
120
|
const { f } = factory();
|
|
103
121
|
const c = f.EasyScore().compose(spec(4, {
|
|
@@ -152,6 +170,48 @@ test('span families retain the source anchors and continuous parameter at first,
|
|
|
152
170
|
assert.equal(fs[i - 1].progress[1], fs[i].progress[0]);
|
|
153
171
|
}
|
|
154
172
|
});
|
|
173
|
+
test('tab ties stay on the selected string through reflow and leave a visible incoming curve', () => {
|
|
174
|
+
for (const selectors of [{ string: 2 }, { fromHead: 1 }, { toHead: 0 }, { fromHead: 1, toHead: 0 }, {}]) {
|
|
175
|
+
const source = tabEndingStudy();
|
|
176
|
+
const tie = source.continuous.spans[0];
|
|
177
|
+
delete tie.fromHead;
|
|
178
|
+
Object.assign(tie, selectors);
|
|
179
|
+
const string = Object.keys(selectors).length ? 2 : 1;
|
|
180
|
+
const { f } = factory();
|
|
181
|
+
const score = f.EasyScore().compose(source);
|
|
182
|
+
const layout = score.sheet.getContinuousLayout();
|
|
183
|
+
function frame(width) {
|
|
184
|
+
score.sheet.setWidth(width);
|
|
185
|
+
f.draw({ retain: true });
|
|
186
|
+
assert.deepEqual(layout.diagnostics, []);
|
|
187
|
+
return structuredClone(layout.fragments);
|
|
188
|
+
}
|
|
189
|
+
const wide = frame(420);
|
|
190
|
+
assert.deepEqual(wide.map((f) => f.part), ['single', 'single']);
|
|
191
|
+
const narrow = frame(122);
|
|
192
|
+
for (const kind of ['tie', 'volta'])
|
|
193
|
+
assert.deepEqual(narrow.filter((f) => f.kind === kind).map((f) => f.part), ['first', 'last']);
|
|
194
|
+
for (const f of narrow.filter((f) => f.kind === 'tie')) {
|
|
195
|
+
const stave = score.staves[f.row][0];
|
|
196
|
+
assert.deepEqual(f.strings, [string]);
|
|
197
|
+
assert.ok(f.x2 - f.x1 >= stave.space(1), 'visible tie on each side of the break');
|
|
198
|
+
const line = stave.getYForLine(string - 1);
|
|
199
|
+
assert.ok(f.y1 < line && f.y1 > line - stave.space(0.5));
|
|
200
|
+
assert.equal(f.y1, f.y2);
|
|
201
|
+
}
|
|
202
|
+
assert.deepEqual(frame(420), wide);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
test('tab ties reject unmatched strings, frets and invalid chord positions before drawing', () => {
|
|
206
|
+
for (const selectors of [{ string: 7 }, { string: 3 }, { fromHead: -1 }, { toHead: 2 }, { fromHead: 1, toHead: 1 }]) {
|
|
207
|
+
const source = tabEndingStudy();
|
|
208
|
+
Object.assign(source.continuous.spans[0], selectors);
|
|
209
|
+
assert.throws(() => factory().f.EasyScore().compose(source), /tab tie/i);
|
|
210
|
+
}
|
|
211
|
+
const source = tabEndingStudy();
|
|
212
|
+
source.staves[0].measures[1].voices[0].notes[0].tab.positions[0] = { str: 2, fret: 11 };
|
|
213
|
+
assert.throws(() => factory().f.EasyScore().compose(source), /same string and fret/);
|
|
214
|
+
});
|
|
155
215
|
test('boundary key, clef and meter move together; explicit signs survive and returned tied accidentals reflow', () => {
|
|
156
216
|
const { f } = factory(), es = f.EasyScore();
|
|
157
217
|
const s = spec(2, { spans: [{ id: 'tie', kind: 'tie', from: 'n0', to: 'n1' }] }, (i) => [
|
|
@@ -181,6 +241,25 @@ test('boundary key, clef and meter move together; explicit signs survive and ret
|
|
|
181
241
|
b.sheet.setWidth(800).format();
|
|
182
242
|
assert.deepEqual(signs(VF.StaveModifier.Position.END), [VF.Barline.CATEGORY]);
|
|
183
243
|
});
|
|
244
|
+
test('an authored rest remains visible on a silent staff and breaks a compressed rest run', () => {
|
|
245
|
+
const measures = Array.from({ length: 3 }, (_, i) => ({
|
|
246
|
+
voices: [{ notes: [{ note: Object.assign({ keys: ['r/4'], duration: 'wr' }, (i === 1 && { restLine: 0 })) }] }],
|
|
247
|
+
}));
|
|
248
|
+
const source = { staves: [{ id: 'rest', measures }], continuous: { compressRests: true, hideEmptyStaves: true } };
|
|
249
|
+
const { f } = factory();
|
|
250
|
+
const score = f.EasyScore().compose(source);
|
|
251
|
+
score.sheet.format();
|
|
252
|
+
assert.deepEqual(score.sheet.getContinuousLayout().rows.flatMap((row) => row.restGroups), []);
|
|
253
|
+
const melody = spec(3, {}).staves[0];
|
|
254
|
+
const duet = factory()
|
|
255
|
+
.f.EasyScore()
|
|
256
|
+
.compose(Object.assign(Object.assign({}, source), { staves: [melody, ...source.staves] }));
|
|
257
|
+
duet.sheet.format();
|
|
258
|
+
assert.ok(duet.sheet
|
|
259
|
+
.getContinuousLayout()
|
|
260
|
+
.rows.find((row) => row.measures.includes(2))
|
|
261
|
+
.visibleStaves.includes('rest'));
|
|
262
|
+
});
|
|
184
263
|
test('structural marks interrupt rest compression; navigation targets and span heads validate atomically', () => {
|
|
185
264
|
const { f } = factory(), es = f.EasyScore(), rest = () => [{ note: { keys: ['b/4'], duration: 'wr' } }];
|
|
186
265
|
const c = es.compose(spec(7, {
|
|
@@ -226,7 +305,58 @@ test('instrument changes survive hiding and reflow and the new full name reserve
|
|
|
226
305
|
assert.ok(c.staves[1][0].getX() > c.staves[0][0].getX() + 30);
|
|
227
306
|
assert.ok(c.staves[2][0].getX() < c.staves[1][0].getX());
|
|
228
307
|
});
|
|
229
|
-
|
|
308
|
+
function renderSaints({ backend, space }) {
|
|
309
|
+
const VF = window.VexFlow;
|
|
310
|
+
VF.setFonts('Petaluma', 'Academico');
|
|
311
|
+
const target = document.createElement(backend === 'svg' ? 'div' : 'canvas');
|
|
312
|
+
target.id = 'saints';
|
|
313
|
+
document.body.replaceChildren(target);
|
|
314
|
+
const score = VF.EasyScore.create({ renderer: { elementId: target.id, width: 1100, height: 1800 } });
|
|
315
|
+
const edition = window.FeaturedScores.saints.create(VF, score, 'Reharmonized');
|
|
316
|
+
edition.spec.staves[0].options = { spacingBetweenLinesPx: space };
|
|
317
|
+
edition.spec.sheet = { width: 1000, x: 16, y: 42, rowGap: 26, measurePadding: 18 };
|
|
318
|
+
const music = score.compose(edition.spec);
|
|
319
|
+
edition.decorate(music);
|
|
320
|
+
const ctx = score.factory.getContext();
|
|
321
|
+
const drawText = ctx.fillText.bind(ctx);
|
|
322
|
+
let painted = [];
|
|
323
|
+
ctx.fillText = (text, x, y) => {
|
|
324
|
+
if (text === 'in')
|
|
325
|
+
painted.push(y);
|
|
326
|
+
return drawText(text, x, y);
|
|
327
|
+
};
|
|
328
|
+
return [1000, 356, 1000].map((width) => {
|
|
329
|
+
music.sheet.setWidth(width).format();
|
|
330
|
+
const { rows, fragments, diagnostics } = music.sheet.getContinuousLayout();
|
|
331
|
+
const words = music.notes.flat(3).flatMap((n) => n.getModifiers().filter((a) => a.phraseManaged));
|
|
332
|
+
const expected = words.filter((a) => a.text === 'in').map((a) => a.computeY().y);
|
|
333
|
+
const baselines = words.map((a) => a.computeY().y - a.checkAttachedNote().checkStave().getYForLine(0));
|
|
334
|
+
const extenders = fragments
|
|
335
|
+
.filter((f) => f.kind === 'lyric')
|
|
336
|
+
.map((f) => {
|
|
337
|
+
const spec = edition.spec.continuous.spans.find((s) => s.id === f.id);
|
|
338
|
+
const word = music
|
|
339
|
+
.getNote(spec.from)
|
|
340
|
+
.getModifiers()
|
|
341
|
+
.find((a) => a.getAttribute('id') === spec.syllableId);
|
|
342
|
+
const ink = word.getTextInk(word.computeX().x, word.computeY().y);
|
|
343
|
+
const staff = music.staves[rows[f.row].measures[0] - 1][0];
|
|
344
|
+
return { part: f.part, y: f.y1 - staff.getYForLine(0), gap: f.x1 - (ink.x + ink.w), length: f.x2 - f.x1 };
|
|
345
|
+
});
|
|
346
|
+
ctx.clear();
|
|
347
|
+
painted = [];
|
|
348
|
+
score.draw({ retain: true });
|
|
349
|
+
return {
|
|
350
|
+
bars: rows.map((r) => r.measures),
|
|
351
|
+
baselines,
|
|
352
|
+
extenders,
|
|
353
|
+
expected,
|
|
354
|
+
painted,
|
|
355
|
+
diagnostics: structuredClone(diagnostics),
|
|
356
|
+
};
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
test('Saints, choir, piano and ensemble reflow in browser SVG and Canvas with two font pairs', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
230
360
|
const browser = yield puppeteer.launch({ headless: true, args: process.env.CI ? ['--no-sandbox'] : [] });
|
|
231
361
|
try {
|
|
232
362
|
const page = yield browser.newPage();
|
|
@@ -238,6 +368,31 @@ test('choir, piano and ensemble reflow in browser SVG and Canvas with two font p
|
|
|
238
368
|
const data = yield readFile(new URL('../../node_modules/@vexflow-fonts/' + name + '/' + name + '.woff2', import.meta.url));
|
|
239
369
|
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
370
|
}
|
|
371
|
+
yield page.evaluate(() => {
|
|
372
|
+
window.FeaturedScores = {};
|
|
373
|
+
});
|
|
374
|
+
yield page.addScriptTag({ path: new URL('../scores/saints.js', import.meta.url).pathname });
|
|
375
|
+
for (const backend of ['svg', 'canvas']) {
|
|
376
|
+
for (const space of [9, 10]) {
|
|
377
|
+
const frames = yield page.evaluate(renderSaints, { backend, space });
|
|
378
|
+
assert.deepEqual(frames[2], frames[0], 'returning to page width restores all verse geometry');
|
|
379
|
+
assert.ok(frames[1].bars.length > frames[0].bars.length);
|
|
380
|
+
assert.ok(frames[1].extenders.some((f) => f.part === 'last'), 'a held syllable crosses a system break');
|
|
381
|
+
for (const frame of frames) {
|
|
382
|
+
assert.deepEqual(frame.diagnostics, []);
|
|
383
|
+
assert.equal(frame.expected.length, 4);
|
|
384
|
+
assert.deepEqual(frame.painted, frame.expected, 'each syllable is drawn once at its measured baseline');
|
|
385
|
+
for (const y of frame.baselines)
|
|
386
|
+
assert.ok(Math.abs(y - 7.5 * space) < 0.01);
|
|
387
|
+
for (const line of frame.extenders) {
|
|
388
|
+
assert.ok(Math.abs(line.y - 7.5 * space) < 0.01);
|
|
389
|
+
assert.ok(line.length > 0);
|
|
390
|
+
if (line.part === 'first' || line.part === 'single')
|
|
391
|
+
assert.ok(Math.abs(line.gap - 0.35 * space) < 0.01);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
241
396
|
for (const backend of ['svg', 'canvas'])
|
|
242
397
|
for (const kind of ['choir', 'keyboard', 'ensemble'])
|
|
243
398
|
for (const family of ['Bravura', 'Petaluma']) {
|
|
@@ -801,6 +801,44 @@ test('composition failures roll back IDs and queues and enforce shared staff sta
|
|
|
801
801
|
const result = score.compose({ staves: [{ id: 'a', measures: [{ voices: [{ notes: [native] }] }] }] });
|
|
802
802
|
assert.equal(result.notes[0][0][0][0], native);
|
|
803
803
|
});
|
|
804
|
+
test('hidden meter changes stay silent at courtesy breaks and can be revealed in the following bar', () => {
|
|
805
|
+
const score = create().compose({
|
|
806
|
+
staves: [
|
|
807
|
+
{
|
|
808
|
+
id: 'melody',
|
|
809
|
+
time: '2/4',
|
|
810
|
+
measures: [
|
|
811
|
+
{ voices: [{ notes: 'C4/h' }] },
|
|
812
|
+
{ time: '6/8', showTimeSignature: false, voices: [{ notes: 'D4/q., G4/q.' }] },
|
|
813
|
+
{ showTimeSignature: true, voices: [{ notes: 'F4/q., D4/q.' }] },
|
|
814
|
+
],
|
|
815
|
+
},
|
|
816
|
+
],
|
|
817
|
+
continuous: { boundaries: [{ measure: 2, breakBefore: 'force' }] },
|
|
818
|
+
});
|
|
819
|
+
score.sheet.format();
|
|
820
|
+
assert.deepEqual(score.staves.map(([s]) => s.getModifiers().filter((m) => m instanceof VF.TimeSignature).length), [1, 0, 1]);
|
|
821
|
+
});
|
|
822
|
+
test('invalid lead-mark anchors restore a caller-owned note and its original modifiers', () => {
|
|
823
|
+
const score = create();
|
|
824
|
+
const note = score.make.note({ keys: ['c/4'], duration: 'w' }).setAttribute('id', 'owned');
|
|
825
|
+
const existing = score.make.annotation({ text: 'dolce' });
|
|
826
|
+
score.attach(note, existing);
|
|
827
|
+
assert.throws(() => score.compose({
|
|
828
|
+
staves: [
|
|
829
|
+
{
|
|
830
|
+
id: 'melody',
|
|
831
|
+
measures: [
|
|
832
|
+
{ voices: [{ notes: [note] }], chords: [{ note: 'owned', text: 'C' }] },
|
|
833
|
+
{ voices: [{ notes: 'D4/w' }], verses: [[{ note: 'owned', text: 'wrong bar' }]] },
|
|
834
|
+
],
|
|
835
|
+
},
|
|
836
|
+
],
|
|
837
|
+
}), /another staff or measure/);
|
|
838
|
+
assert.deepEqual(note.getModifiers(), [existing]);
|
|
839
|
+
assert.equal(note.getStave(), undefined);
|
|
840
|
+
assert.throws(() => note.getVoice(), /No voice/i);
|
|
841
|
+
});
|
|
804
842
|
test('key-aware composition preserves literal pitches and explicit marks across rational onsets and key changes', () => {
|
|
805
843
|
const marks = (note) => note
|
|
806
844
|
.getModifiers()
|
|
@@ -108,6 +108,39 @@ test('two live scores independently consume glyph metrics, anchors and beam poli
|
|
|
108
108
|
}
|
|
109
109
|
assert.throws(() => profile('Bravura', { beamThickness: NaN }), RangeError);
|
|
110
110
|
});
|
|
111
|
+
test('default Bravura slash stems meet the published glyph anchors at normal and grace sizes', () => {
|
|
112
|
+
const reference = profile('Bravura');
|
|
113
|
+
const { f } = factory();
|
|
114
|
+
for (const make of [f.StaveNote.bind(f), f.GraceNote.bind(f)])
|
|
115
|
+
for (const duration of ['q', '8', 'h'])
|
|
116
|
+
for (const direction of [VF.Stem.UP, VF.Stem.DOWN]) {
|
|
117
|
+
const note = make({ keys: ['b/4'], duration, type: 's', stemDirection: direction });
|
|
118
|
+
const stave = f.Stave({ x: 10, y: 60, width: 240 });
|
|
119
|
+
VF.Formatter.FormatAndDraw(f.getContext(), stave, [note]);
|
|
120
|
+
const head = note.noteHeads[0];
|
|
121
|
+
const [x, y] = reference.stemAnchor(head.text, direction === VF.Stem.UP ? 'up' : 'down');
|
|
122
|
+
const space = head.fontSizeInPixels / 4;
|
|
123
|
+
const stem = note.getStem().getSegment();
|
|
124
|
+
assert.equal(stem.x, note.getNoteHeadBeginX() + head.getXShift() + x * space - (direction * VF.Stem.WIDTH) / 2);
|
|
125
|
+
assert.equal(stem.baseY, head.getY() - y * space);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
test('slash anchors follow the note font and respect explicit metadata', () => {
|
|
129
|
+
const { f } = factory();
|
|
130
|
+
const custom = new VF.EngravingProfile({
|
|
131
|
+
musicFont: 'Bravura',
|
|
132
|
+
metadata: { fontName: 'Bravura', glyphsWithAnchors: { noteheadSlashVerticalEnds: { stemUpSE: [1.25, 0.4] } } },
|
|
133
|
+
});
|
|
134
|
+
for (const [options, expectedY] of [
|
|
135
|
+
[{ engraving: custom }, 0.4],
|
|
136
|
+
[{ musicFont: 'Petaluma, Bravura' }, 0],
|
|
137
|
+
]) {
|
|
138
|
+
const note = f.StaveNote(Object.assign({ keys: ['b/4'], duration: 'q', type: 's', stemDirection: VF.Stem.UP }, options));
|
|
139
|
+
VF.Formatter.FormatAndDraw(f.getContext(), f.Stave({ x: 10, y: 60, width: 240 }), [note]);
|
|
140
|
+
const head = note.noteHeads[0];
|
|
141
|
+
assert.equal(note.getStem().getSegment().baseY, head.getY() - (expectedY * head.fontSizeInPixels) / 4);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
111
144
|
test('beam clears a head whose attack falls strictly between its stems', () => {
|
|
112
145
|
const build = (peerKey) => {
|
|
113
146
|
const { f } = factory();
|