vexflow 5.5.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 +692 -309
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +551 -253
- 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 +6 -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/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_repertoire_tests.js +1 -1
- package/build/esm/tests/demos/electric.js +1 -3
- 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/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 +146 -4
- package/build/esm/tests/node/svg-export-tests.mjs +50 -21
- package/build/esm/tests/scores/electric.js +3 -4
- package/build/esm/tests/scores/kesh.js +1 -1
- package/build/esm/tests/scores/saints.js +10 -8
- package/build/esm/tests/scores/sumer.js +3 -1
- 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 +8 -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/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 +8 -0
- package/package.json +1 -1
- package/tests/demos/electric.ts +1 -3
- package/tests/demos/electric.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/scores/electric.js +6 -4
- package/tests/scores/electric.webp +0 -0
- package/tests/scores/falseta.webp +0 -0
- package/tests/scores/kesh.js +1 -2
- package/tests/scores/kesh.webp +0 -0
- package/tests/scores/saints.js +11 -8
- package/tests/scores/saints.webp +0 -0
- package/tests/scores/sumer.js +8 -3
- package/tests/scores/sumer.webp +0 -0
|
@@ -11,7 +11,8 @@ import assert from 'node:assert/strict';
|
|
|
11
11
|
import { readFile } from 'node:fs/promises';
|
|
12
12
|
import { test } from 'node:test';
|
|
13
13
|
import puppeteer from 'puppeteer';
|
|
14
|
-
import {
|
|
14
|
+
import { tabEndingStudy } from '../engraving/continuous-studies.mjs';
|
|
15
|
+
import { leadSheetStudy, publicationStudy } from '../engraving/publication-studies.mjs';
|
|
15
16
|
test('publication views, pagination and portable printing', (t) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
17
|
const browser = yield puppeteer.launch({ headless: true, args: process.env.CI ? ['--no-sandbox'] : [] });
|
|
17
18
|
try {
|
|
@@ -104,8 +105,141 @@ test('publication views, pagination and portable printing', (t) => __awaiter(voi
|
|
|
104
105
|
}
|
|
105
106
|
}));
|
|
106
107
|
}
|
|
108
|
+
yield t.test('structured chords and rhythmic tab retain written dots in independent parts', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
109
|
+
const samples = yield page.evaluate(() => {
|
|
110
|
+
const keys = ['c/4', 'e/4'];
|
|
111
|
+
const positions = [
|
|
112
|
+
{ str: 1, fret: 12 },
|
|
113
|
+
{ str: 2, fret: 10 },
|
|
114
|
+
];
|
|
115
|
+
const source = {
|
|
116
|
+
staves: ['stave', 'tab'].map((kind) => ({
|
|
117
|
+
id: kind,
|
|
118
|
+
kind,
|
|
119
|
+
time: '13/16',
|
|
120
|
+
measures: [
|
|
121
|
+
{
|
|
122
|
+
voices: [
|
|
123
|
+
{
|
|
124
|
+
notes: [1, 2].map((dots) => (Object.assign({ id: kind + dots }, (kind === 'tab'
|
|
125
|
+
? { tab: { duration: 'q', positions, dots }, drawStem: true }
|
|
126
|
+
: { note: { duration: 'q', keys, dots } })))),
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
})),
|
|
132
|
+
};
|
|
133
|
+
const host = document.querySelector('aside');
|
|
134
|
+
host.replaceChildren();
|
|
135
|
+
host.id = 'dot-score';
|
|
136
|
+
const factory = new VexFlow.Factory({ renderer: { elementId: host.id, width: 500, height: 330 } });
|
|
137
|
+
const screen = factory.EasyScore().compose(source);
|
|
138
|
+
factory.draw();
|
|
139
|
+
const countDots = (group) => [...group.querySelectorAll('text')].filter((el) => el.textContent === VexFlow.Glyphs.augmentationDot).length;
|
|
140
|
+
return source.staves.flatMap(({ id }) => {
|
|
141
|
+
const book = new VexFlow.Publication(source).render(document.querySelector('main'), { staves: [id] });
|
|
142
|
+
const svg = book.pages[0].svg;
|
|
143
|
+
const events = JSON.parse(svg.querySelector('metadata').textContent).events;
|
|
144
|
+
return events.map((event) => ({
|
|
145
|
+
id: event.id,
|
|
146
|
+
ticks: screen.getNote(event.id).getTicks().toString(),
|
|
147
|
+
partTicks: event.ticks,
|
|
148
|
+
screenDots: countDots(host.querySelector('#vf-' + event.id)),
|
|
149
|
+
partDots: countDots(svg.querySelector('[data-vf-id="vf-' + event.id + '"]')),
|
|
150
|
+
}));
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
assert.deepEqual(samples, [
|
|
154
|
+
{ id: 'stave1', ticks: '6144/1', partTicks: '6144/1', screenDots: 2, partDots: 2 },
|
|
155
|
+
{ id: 'stave2', ticks: '7168/1', partTicks: '7168/1', screenDots: 4, partDots: 4 },
|
|
156
|
+
{ id: 'tab1', ticks: '6144/1', partTicks: '6144/1', screenDots: 1, partDots: 1 },
|
|
157
|
+
{ id: 'tab2', ticks: '7168/1', partTicks: '7168/1', screenDots: 2, partDots: 2 },
|
|
158
|
+
]);
|
|
159
|
+
}));
|
|
160
|
+
yield t.test('an extracted tab part prints the tied string and the ending across its own system break', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
161
|
+
const source = tabEndingStudy();
|
|
162
|
+
source.staves.unshift({
|
|
163
|
+
id: 'melody',
|
|
164
|
+
time: '1/4',
|
|
165
|
+
measures: [1, 2].map(() => ({ voices: [{ notes: 'C4/q' }] })),
|
|
166
|
+
});
|
|
167
|
+
const result = yield page.evaluate((source) => {
|
|
168
|
+
const book = new VexFlow.Publication(source).render(document.querySelector('main'), {
|
|
169
|
+
staves: ['guitar'],
|
|
170
|
+
systemBreaks: [2],
|
|
171
|
+
});
|
|
172
|
+
const svg = book.pages[0].svg;
|
|
173
|
+
const meta = JSON.parse(svg.querySelector('metadata').textContent);
|
|
174
|
+
return {
|
|
175
|
+
diagnostics: book.diagnostics,
|
|
176
|
+
staves: meta.staves,
|
|
177
|
+
spans: meta.spans,
|
|
178
|
+
systems: [...svg.querySelectorAll('[data-system]')].map((g) => ({
|
|
179
|
+
endings: [...g.querySelectorAll('text')].filter((e) => e.textContent === '1.').length,
|
|
180
|
+
curves: [...g.querySelectorAll('path')].filter((e) => /Q/i.test(e.getAttribute('d'))).length,
|
|
181
|
+
})),
|
|
182
|
+
};
|
|
183
|
+
}, source);
|
|
184
|
+
assert.deepEqual(result.diagnostics, []);
|
|
185
|
+
assert.deepEqual(result.staves, ['guitar']);
|
|
186
|
+
assert.deepEqual(result.systems, [
|
|
187
|
+
{ endings: 1, curves: 1 },
|
|
188
|
+
{ endings: 0, curves: 1 },
|
|
189
|
+
]);
|
|
190
|
+
assert.deepEqual(result.spans.filter((s) => s.id === 'hold'), [
|
|
191
|
+
{ id: 'hold', kind: 'tie', part: 'first', strings: [2], from: 'tab0' },
|
|
192
|
+
{ id: 'hold', kind: 'tie', part: 'last', strings: [2], to: 'tab1' },
|
|
193
|
+
]);
|
|
194
|
+
assert.deepEqual(result.spans.filter((s) => s.id === 'ending').map((s) => s.part), ['first', 'last']);
|
|
195
|
+
}));
|
|
196
|
+
yield t.test('lead sheet marks stay on their notes through reflow and part extraction', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
197
|
+
yield page.addScriptTag({ content: 'window.leadSheetStudy=' + leadSheetStudy });
|
|
198
|
+
const result = yield page.evaluate(() => {
|
|
199
|
+
const source = leadSheetStudy();
|
|
200
|
+
const host = document.querySelector('aside');
|
|
201
|
+
host.replaceChildren();
|
|
202
|
+
host.id = 'lead-score';
|
|
203
|
+
const factory = new VexFlow.Factory({ renderer: { elementId: host.id, width: 800, height: 1200 } });
|
|
204
|
+
const score = factory.EasyScore().compose(source);
|
|
205
|
+
const read = (svg) => {
|
|
206
|
+
const anchor = (id) => svg.querySelector('#vf-' + id + ', [data-vf-id="vf-' + id + '"]');
|
|
207
|
+
const marks = (id) => Array.from(anchor(id).querySelectorAll('.vf-annotation text'), (t) => t.textContent);
|
|
208
|
+
const bars = [...svg.querySelectorAll('.vf-stavebarline')].map((el) => Array.from(el.querySelectorAll('rect[stroke="none"]'), (r) => Number(r.getAttribute('width'))));
|
|
209
|
+
return {
|
|
210
|
+
opening: marks('a0'),
|
|
211
|
+
second: marks('a3'),
|
|
212
|
+
meterSigns: svg.querySelectorAll('.vf-timesignature').length,
|
|
213
|
+
double: bars.filter((w) => w.join() === '1,1').length,
|
|
214
|
+
final: bars.filter((w) => w.join() === '1,3').length,
|
|
215
|
+
beams: svg.querySelectorAll('.vf-beam').length,
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
const samples = [760, 270].map((width) => {
|
|
219
|
+
factory.getContext().clear();
|
|
220
|
+
score.sheet.setWidth(width);
|
|
221
|
+
factory.draw({ retain: true });
|
|
222
|
+
return { rows: score.sheet.getRows().length, drawing: read(host) };
|
|
223
|
+
});
|
|
224
|
+
const beamSizes = [...new Set(score.notes[0][0][0].map((n) => n.getBeam()))].map((b) => b.getNotes().length);
|
|
225
|
+
const book = new VexFlow.Publication(source).render(document.querySelector('main'), {
|
|
226
|
+
staves: ['lead'],
|
|
227
|
+
systemBreaks: [2],
|
|
228
|
+
paper: 'A4',
|
|
229
|
+
});
|
|
230
|
+
return { samples, beamSizes, printed: read(book.pages[0].svg), diagnostics: book.diagnostics };
|
|
231
|
+
});
|
|
232
|
+
const drawing = { opening: ['Cmaj7', 'Day'], second: ['light'], meterSigns: 0, double: 1, final: 1, beams: 4 };
|
|
233
|
+
assert.deepEqual(result.samples, [
|
|
234
|
+
{ rows: 1, drawing },
|
|
235
|
+
{ rows: 2, drawing },
|
|
236
|
+
]);
|
|
237
|
+
assert.deepEqual(result.beamSizes, [3, 3]);
|
|
238
|
+
assert.deepEqual(result.printed, drawing);
|
|
239
|
+
assert.deepEqual(result.diagnostics, []);
|
|
240
|
+
}));
|
|
107
241
|
yield t.test('a fingering and its transparent hit area stay with the printed note', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
108
|
-
const
|
|
242
|
+
const printed = yield page.evaluate(() => {
|
|
109
243
|
const measures = Array.from({ length: 6 }, (_, i) => ({
|
|
110
244
|
voices: [{ notes: i === 5 ? 'C5/w[id="fingered",fingerings="4.left"]' : 'G4/w' }],
|
|
111
245
|
}));
|
|
@@ -114,9 +248,17 @@ test('publication views, pagination and portable printing', (t) => __awaiter(voi
|
|
|
114
248
|
systemBreaks: [2, 3, 4, 5, 6],
|
|
115
249
|
});
|
|
116
250
|
const note = book.pages.map((p) => p.svg.querySelector('[data-vf-id="vf-fingered"]')).find(Boolean);
|
|
117
|
-
|
|
251
|
+
const digit = Array.from(note.querySelectorAll('text'))
|
|
252
|
+
.find((el) => el.textContent === '4')
|
|
253
|
+
.getBoundingClientRect();
|
|
254
|
+
const head = note.querySelector('.vf-notehead text').getBoundingClientRect();
|
|
255
|
+
return {
|
|
256
|
+
system: note.closest('[data-system]').getAttribute('data-system'),
|
|
257
|
+
clear: digit.right < head.left,
|
|
258
|
+
aligned: digit.top < head.bottom && head.top < digit.bottom,
|
|
259
|
+
};
|
|
118
260
|
});
|
|
119
|
-
assert.
|
|
261
|
+
assert.deepEqual(printed, { system: '6', clear: true, aligned: true });
|
|
120
262
|
}));
|
|
121
263
|
yield t.test('pagination reserves running text at the final page scale', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
122
264
|
const result = yield page.evaluate(() => {
|
|
@@ -99,36 +99,65 @@ test('portable SVG paths retain score geometry and render with fonts and styles
|
|
|
99
99
|
missingError: true,
|
|
100
100
|
italicError: true,
|
|
101
101
|
});
|
|
102
|
-
for (const [
|
|
103
|
-
['
|
|
104
|
-
['
|
|
102
|
+
for (const [music, text] of [
|
|
103
|
+
['Bravura', 'Academico'],
|
|
104
|
+
['Petaluma', 'Academico'],
|
|
105
|
+
['Petaluma', 'Petaluma Script'],
|
|
105
106
|
]) {
|
|
106
107
|
const drawings = yield page.evaluate(({ music, text }) => {
|
|
107
108
|
document.querySelector('#score').replaceChildren();
|
|
108
109
|
VexFlow.setFonts(music, text);
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
const
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
]
|
|
120
|
-
|
|
110
|
+
const factory = new VexFlow.Factory({ renderer: { elementId: 'score', width: 620, height: 240 } });
|
|
111
|
+
const context = factory.getContext();
|
|
112
|
+
const score = factory.EasyScore();
|
|
113
|
+
const notes = score.notes('(C#5 E5 G5)/q, B4, A4, B4/q/r');
|
|
114
|
+
const system = factory.System({ x: 15, y: 60, width: 580 });
|
|
115
|
+
const stave = system
|
|
116
|
+
.addStave({ voices: [score.voice(notes)] })
|
|
117
|
+
.addClef('treble')
|
|
118
|
+
.addKeySignature('D')
|
|
119
|
+
.addTimeSignature('4/4');
|
|
120
|
+
notes[1].addModifier(factory.ChordSymbol().addText('G').addGlyphOrText('b9', {
|
|
121
|
+
symbolModifier: VexFlow.ChordSymbol.symbolModifiers.SUPERSCRIPT,
|
|
122
|
+
}));
|
|
123
|
+
system.getPhraseLayout().addVerse(stave, [
|
|
124
|
+
{ note: notes[0], text: 'Chanté' },
|
|
125
|
+
{ note: notes[1], text: 'dolce' },
|
|
126
|
+
]);
|
|
127
|
+
factory.draw();
|
|
121
128
|
context.setFont(`${text},Academico`, '14pt').fillText('Andante — AV', 20, 28);
|
|
122
|
-
context.setFont(`${text},Academico`, '12pt').fillText('Sing clearly', 200, 195);
|
|
123
129
|
const before = context.toSVG();
|
|
124
130
|
const after = context.toSVG(window.outlineFonts);
|
|
125
|
-
const originalBounds = Array.from(context.svg.querySelectorAll('text')).map((node) => {
|
|
126
|
-
const { x, y, width, height } = node.getBBox();
|
|
127
|
-
return { x, y, width, height };
|
|
128
|
-
});
|
|
129
131
|
const clone = new DOMParser().parseFromString(after, 'image/svg+xml').documentElement;
|
|
130
|
-
|
|
132
|
+
const regularFace = (family) => window.outlineFonts.find((face) => face.family === family && !face.weight).font;
|
|
133
|
+
const letters = regularFace(text);
|
|
134
|
+
const symbols = regularFace(music);
|
|
135
|
+
const verifyRole = (selector, expected) => {
|
|
136
|
+
const live = context.svg.querySelectorAll(selector + ' text');
|
|
137
|
+
const paths = clone.querySelectorAll(selector + ' path');
|
|
138
|
+
return (live.length === expected.length &&
|
|
139
|
+
paths.length === expected.length &&
|
|
140
|
+
expected.every((outline, i) => paths[i].getAttribute('d') ===
|
|
141
|
+
outline(Number(live[i].getAttribute('x')), Number(live[i].getAttribute('y')))));
|
|
142
|
+
};
|
|
143
|
+
const outline = (word, pt) => (x, y) => letters.getPath(word, x, y, VexFlow.Font.convertSizeToPixelValue(pt)).toPathData(5);
|
|
144
|
+
const raisedNinth = (x, y) => {
|
|
145
|
+
const flat = VexFlow.Glyphs.csymAccidentalFlat;
|
|
146
|
+
const size = VexFlow.Font.convertSizeToPixelValue(8.4);
|
|
147
|
+
return (symbols.getPath(flat, x, y, size).toPathData(5) +
|
|
148
|
+
outline('9', 8.4)(x + symbols.getAdvanceWidth(flat, size), y));
|
|
149
|
+
};
|
|
150
|
+
return {
|
|
151
|
+
before,
|
|
152
|
+
after,
|
|
153
|
+
glyphs: context.svg.querySelectorAll('text').length,
|
|
154
|
+
paths: clone.querySelectorAll('path').length,
|
|
155
|
+
chords: verifyRole('.vf-chordsymbol', [outline('G', 14), raisedNinth]),
|
|
156
|
+
lyrics: verifyRole('.vf-annotation', [outline('Chanté', 12), outline('dolce', 12)]),
|
|
157
|
+
};
|
|
131
158
|
}, { music, text });
|
|
159
|
+
assert.ok(drawings.chords, `chord outlines in ${music} and ${text}`);
|
|
160
|
+
assert.ok(drawings.lyrics, `verse outlines in ${text}`);
|
|
132
161
|
assert.ok(drawings.glyphs > 10);
|
|
133
162
|
assert.ok(drawings.paths >= drawings.glyphs);
|
|
134
163
|
assert.doesNotMatch(drawings.after, /<text\b|@font-face|<use\b/);
|
|
@@ -68,14 +68,13 @@
|
|
|
68
68
|
])
|
|
69
69
|
upper(m, i).addModifier(score.make.fingering({ number, position: 'left' }));
|
|
70
70
|
const tap = (i) => c.getNote('tab-7-0-' + i);
|
|
71
|
-
|
|
71
|
+
upper(7, 1).addModifier(score.make.annotation({ text: 'T', vJustify: 'top', font: { size: 11, weight: 'bold' } }));
|
|
72
|
+
tap(1).addModifier(score.make.annotation({ text: 'T', vJustify: 'top' }).setFont('Arial', 11, 'bold'));
|
|
72
73
|
for (const [i, text] of [
|
|
73
74
|
[1, 'P'],
|
|
74
75
|
[2, 'H'],
|
|
75
76
|
])
|
|
76
|
-
score.make
|
|
77
|
-
.tabTie({ firstNote: tap(i), lastNote: tap(i + 1), firstIndexes: [0], lastIndexes: [0] }, text)
|
|
78
|
-
.setFont('Arial', 10, 'bold');
|
|
77
|
+
score.make.tabTie({ firstNote: tap(i), lastNote: tap(i + 1), firstIndexes: [0], lastIndexes: [0] }, text);
|
|
79
78
|
tap(3).addModifier(score.make.vibrato());
|
|
80
79
|
},
|
|
81
80
|
};
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
function fiddleMarks({ chord, cut }, note, builder) {
|
|
33
33
|
const f = builder.getFactory();
|
|
34
34
|
if (chord)
|
|
35
|
-
note.addModifier(f.ChordSymbol(
|
|
35
|
+
note.addModifier(f.ChordSymbol().addText(chord));
|
|
36
36
|
if (cut) {
|
|
37
37
|
const grace = f.GraceNote({ keys: [cut], duration: '8', slash: true });
|
|
38
38
|
note.addModifier(f.GraceNoteGroup({ notes: [grace], slur: true }));
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
const choices = ['Reharmonized', 'Traditional'];
|
|
7
7
|
const control = 'Harmony';
|
|
8
8
|
const focus = 'v6-0';
|
|
9
|
-
const fonts = ['Petaluma', '
|
|
9
|
+
const fonts = ['Petaluma', 'Academico'];
|
|
10
10
|
const bars = [
|
|
11
11
|
['C4/q, E4, F4', 'Oh when the', '', ''],
|
|
12
12
|
['G4/w', 'saints', 'C', 'C:6/9'],
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
['G4/w', 'in', 'C', 'Dm:11'],
|
|
15
15
|
['B4/q/r, C4/q, E4, F4', '_ Oh when the', 'C', 'G:13'],
|
|
16
16
|
['G4/q, E4, C4, E4', 'saints go march- ing', 'C', 'C:maj9'],
|
|
17
|
-
['D4/w', '', 'G:7', 'Am:11'],
|
|
17
|
+
['D4/w', 'in', 'G:7', 'Am:11'],
|
|
18
18
|
['D4/w', '', 'G:7', 'D:9'],
|
|
19
19
|
['B4/q/r, E4/q, E4, D4', '_ Oh Lord I', 'G:7', 'G:13'],
|
|
20
20
|
['C4/h, C4/q, E4', 'want to be', 'C', 'Gm:13'],
|
|
@@ -23,11 +23,10 @@
|
|
|
23
23
|
['B4/q/r, C4/q, E4, F4', '_ Oh when the', 'F', 'Fm:maj7'],
|
|
24
24
|
['G4/h, E4/q, C4', 'saints go march-', 'C', 'Em:7'],
|
|
25
25
|
['D4/w', 'ing', 'G:7', 'Db:7b9'],
|
|
26
|
-
['C4/w', '', 'C', 'C:6/9'],
|
|
26
|
+
['C4/w', 'in', 'C', 'C:6/9'],
|
|
27
27
|
['C4/q', '', '', ''],
|
|
28
28
|
];
|
|
29
29
|
function create(VF, score, choice) {
|
|
30
|
-
const lyricSize = 15;
|
|
31
30
|
const measures = bars.map(([music], m) => ({
|
|
32
31
|
span: m === 0 ? '3/4' : m === 16 ? '1/4' : undefined,
|
|
33
32
|
voices: [
|
|
@@ -39,7 +38,8 @@
|
|
|
39
38
|
},
|
|
40
39
|
],
|
|
41
40
|
}));
|
|
42
|
-
const
|
|
41
|
+
const heldBars = [6, 15];
|
|
42
|
+
const spans = heldBars.flatMap((m) => ['lyric', 'tie'].map((kind) => (Object.assign({ id: kind + m, kind, from: 'v' + m + '-0', to: 'v' + (m + 1) + '-0' }, (kind === 'lyric' ? { syllableId: 'held-in-' + m } : {})))));
|
|
43
43
|
return {
|
|
44
44
|
spec: { staves: [{ id: 'Voice', time: '4/4', measures }], continuous: { spans } },
|
|
45
45
|
decorate(composition) {
|
|
@@ -56,9 +56,11 @@
|
|
|
56
56
|
.split(' ')
|
|
57
57
|
.flatMap((text, i) => text && text !== '_' ? [{ text, note: composition.getNote('v' + m + '-' + i) }] : []);
|
|
58
58
|
if (syllables.length) {
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
const words = composition.systems[m].getPhraseLayout().addVerse(composition.staves[m][0], syllables, {
|
|
60
|
+
baselineSpaces: 7.5,
|
|
61
|
+
});
|
|
62
|
+
if (heldBars.includes(m))
|
|
63
|
+
words[0].setAttribute('id', 'held-in-' + m);
|
|
62
64
|
}
|
|
63
65
|
});
|
|
64
66
|
},
|
|
@@ -115,7 +115,9 @@
|
|
|
115
115
|
note(23).addModifier(score.make.articulation({ type: 'a@a', position: 'above' }));
|
|
116
116
|
}
|
|
117
117
|
for (const { m, staff, syllables } of verses) {
|
|
118
|
-
c.
|
|
118
|
+
const stave = c.staves[m][staff];
|
|
119
|
+
const words = c.systems[m].getPhraseLayout().addVerse(stave, syllables.map(([id, text]) => ({ note: c.getNote(id), text })), { baselineSpaces: 7.75 });
|
|
120
|
+
words.forEach((word) => word.setConnectorPadding(stave.space(0.2)));
|
|
119
121
|
}
|
|
120
122
|
},
|
|
121
123
|
};
|
|
@@ -3,6 +3,7 @@ import { VexFlowTests } from './vexflow_test_helpers.js';
|
|
|
3
3
|
import { Dot } from '../src/dot.js';
|
|
4
4
|
import { Formatter } from '../src/formatter.js';
|
|
5
5
|
import { Metrics } from '../src/metrics.js';
|
|
6
|
+
import { ModifierPosition } from '../src/modifier.js';
|
|
6
7
|
import { Stave } from '../src/stave.js';
|
|
7
8
|
import { TabNote } from '../src/tabnote.js';
|
|
8
9
|
import { TabStave } from '../src/tabstave.js';
|
|
@@ -15,6 +16,7 @@ const TabNoteTests = {
|
|
|
15
16
|
QUnit.test('TabStave Line', tabStaveLine);
|
|
16
17
|
QUnit.test('Width', width);
|
|
17
18
|
const run = VexFlowTests.runTests;
|
|
19
|
+
run('Fret size and string clearance', fretClearance, undefined, ['Bravura']);
|
|
18
20
|
run('TabNote Draw', draw);
|
|
19
21
|
run('TabNote Stems Up', drawStemsUp);
|
|
20
22
|
run('TabNote Stems Down', drawStemsDown);
|
|
@@ -61,6 +63,47 @@ function width(assert) {
|
|
|
61
63
|
});
|
|
62
64
|
assert.throws(() => note.getWidth(), /UnformattedNote/, 'Unformatted note should have no width');
|
|
63
65
|
}
|
|
66
|
+
function fretClearance({ assert, elementId }, contextBuilder) {
|
|
67
|
+
const ctx = contextBuilder(elementId, 280, 140);
|
|
68
|
+
const stave = new TabStave(10, 10, 260).addTabGlyph().setContext(ctx).drawWithStyle();
|
|
69
|
+
const positions = [0, 12, 10, 15, 13, 11].map((fret, i) => ({ str: i + 1, fret }));
|
|
70
|
+
class TestChord extends TabNote {
|
|
71
|
+
get frets() {
|
|
72
|
+
return this.fretElement;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const chord = new TestChord({ duration: 'q', positions });
|
|
76
|
+
const small = new TestChord({ duration: 'q', positions }).setFontSize(9);
|
|
77
|
+
const gaps = [];
|
|
78
|
+
const clearRect = ctx.clearRect.bind(ctx);
|
|
79
|
+
ctx.clearRect = (x, y, w, h) => {
|
|
80
|
+
gaps.push({ left: x, right: x + w, centerY: y + h / 2 });
|
|
81
|
+
return clearRect(x, y, w, h);
|
|
82
|
+
};
|
|
83
|
+
Formatter.FormatAndDraw(ctx, stave, [chord, small]);
|
|
84
|
+
assert.equal(gaps.length, positions.length * 2, 'Each fret clears its own string');
|
|
85
|
+
assert.ok(chord.getWidth() > small.getWidth(), 'Formatting reserves the measured fret width');
|
|
86
|
+
for (const [index, note] of [chord, small].entries()) {
|
|
87
|
+
let previousBottom = -Infinity;
|
|
88
|
+
const leftAnchor = note.getModifierStartXY(ModifierPosition.LEFT, 0).x;
|
|
89
|
+
const rightAnchor = note.getModifierStartXY(ModifierPosition.RIGHT, 0).x;
|
|
90
|
+
assert.equal(note.getModifierStartXY(ModifierPosition.ABOVE, 0).x, note.getStemX());
|
|
91
|
+
for (const [i, fret] of note.frets.entries()) {
|
|
92
|
+
const ink = fret.getTextMetrics();
|
|
93
|
+
const { left, right, centerY } = gaps[index * positions.length + i];
|
|
94
|
+
assert.ok(leftAnchor <= left + 0.01 && rightAnchor >= right - 0.01, 'Side markings clear every string gap');
|
|
95
|
+
const x = note.getAbsoluteX() - fret.getWidth() / 2;
|
|
96
|
+
const baseline = note.getYs()[i] + fret.getYShift();
|
|
97
|
+
const top = baseline - ink.actualBoundingBoxAscent;
|
|
98
|
+
const bottom = baseline + ink.actualBoundingBoxDescent;
|
|
99
|
+
assert.equal(fret.fontSizeInPoints, index === 0 ? 11 : 9);
|
|
100
|
+
assert.ok(Math.abs((bottom + top) / 2 - centerY) < 0.01, 'Ink centers on the cleared string');
|
|
101
|
+
assert.ok(x - ink.actualBoundingBoxLeft >= left + 1 && x + ink.actualBoundingBoxRight <= right - 1);
|
|
102
|
+
assert.ok(top >= previousBottom + 2, 'Adjacent strings have at least two pixels of clear space');
|
|
103
|
+
previousBottom = bottom;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
64
107
|
function draw(options, contextBuilder) {
|
|
65
108
|
const ctx = contextBuilder(options.elementId, 600, 140);
|
|
66
109
|
ctx.font = '10pt Arial';
|
|
@@ -280,6 +280,7 @@ VexFlowTests.FONT_STACKS = {
|
|
|
280
280
|
Leipzig: ['Leipzig', 'Academico'],
|
|
281
281
|
MuseJazz: ['MuseJazz', 'MuseJazz Text'],
|
|
282
282
|
Petaluma: ['Petaluma', 'Petaluma Script'],
|
|
283
|
+
'Petaluma with Academico': ['Petaluma', 'Academico'],
|
|
283
284
|
Sebastian: ['Sebastian', 'Nepomuk'],
|
|
284
285
|
};
|
|
285
286
|
VexFlowTests.NEXT_TEST_ID = 0;
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { example as e, number, select, setup, staff, text } from './helpers.mjs';
|
|
2
2
|
const group = 'Marks & expression';
|
|
3
3
|
export const expression = [
|
|
4
|
-
e('annotations', 'Lyrics & annotations', group, 'Align lyrics below notes or annotations above them.', 'Annotation',
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
e('annotations', 'Lyrics & annotations', group, 'Align lyrics below notes or annotations above them.', 'Annotation', `${setup}
|
|
5
|
+
|
|
6
|
+
const notes = score.notes('C5/q, E5, G5, C6');
|
|
7
|
+
const system = factory.System({ x: 30, y: 65, width: width - 60 });
|
|
8
|
+
const stave = system.addStave({ voices: [score.voice(notes)] }).addClef('treble');
|
|
9
|
+
|
|
10
|
+
// Give each sung word a note. The verse shares a baseline and uses the score's lyric size.
|
|
11
|
+
const words = params.words.trim().split(/\\s+/).filter(Boolean).slice(0, notes.length);
|
|
12
|
+
if (words.length) {
|
|
13
|
+
const verse = words.map((text, i) => ({ text, note: notes[i] }));
|
|
14
|
+
system.getPhraseLayout().addVerse(stave, verse, { side: params.position === 'top' ? 'above' : 'below' });
|
|
15
|
+
}
|
|
16
|
+
factory.draw();`, [text('words', 'Words', 'One two three four'), select('position', 'Position', 'bottom', ['bottom', 'top'])]),
|
|
8
17
|
e('chord-symbols', 'Chord symbols', group, 'Build harmonic labels from text, accidentals, and superscripts.', 'ChordSymbol', staff("score.notes('C5/h, G4')", `// Build the label in reading order. Raise the flat ninth on the second symbol.
|
|
9
18
|
notes[0].addModifier(factory.ChordSymbol().addText(params.root).addGlyphOrText('maj7'), 0);
|
|
10
19
|
notes[1].addModifier(factory.ChordSymbol().addText('G').addGlyphOrText('7').addGlyphOrText('b9', { symbolModifier: VF.ChordSymbol.symbolModifiers.SUPERSCRIPT }), 0);`), [text('root', 'Root', 'C')]),
|
|
@@ -31,7 +40,8 @@ const sub = { symbolModifier: VF.ChordSymbol.symbolModifiers.SUBSCRIPT };
|
|
|
31
40
|
.addStave({ voices: [voice] }).addClef('treble');
|
|
32
41
|
});
|
|
33
42
|
factory.draw();
|
|
34
|
-
|
|
43
|
+
// Match the captions to the score’s selected text face.
|
|
44
|
+
ctx.setFont(VF.getTextFonts().join(','), 10);
|
|
35
45
|
ctx.fillText('Default: none', 30, 22);
|
|
36
46
|
ctx.fillText('Opt-in: auto', 30, 172);
|
|
37
47
|
// Inspect the complete chord's ink bounds, including both script rows.
|
|
@@ -44,7 +54,7 @@ if (params.bounds === 'yes') {
|
|
|
44
54
|
ctx.restore();
|
|
45
55
|
}`, [
|
|
46
56
|
text('root', 'Root', 'A'),
|
|
47
|
-
number('size', 'Font size (pt)',
|
|
57
|
+
number('size', 'Font size (pt)', 14, 10, 28),
|
|
48
58
|
select('bounds', 'Chord bounds', 'no', ['no', 'yes']),
|
|
49
59
|
], 'Auto supports regular Academico/Bravura and Petaluma Script/Petaluma. Other font combinations keep the default layout. Set the chord font before formatting.'),
|
|
50
60
|
e('dynamics', 'Dynamics', group, 'From pianissimo to fortissimo, draw music-font dynamic marks.', 'TextDynamics', `${setup}
|
|
@@ -36,8 +36,8 @@ const fan = guitar.rasgueado(
|
|
|
36
36
|
roll: i === 6,
|
|
37
37
|
}))
|
|
38
38
|
);
|
|
39
|
-
//
|
|
40
|
-
const logicalWidth = Math.max(width,
|
|
39
|
+
// Give the arrows, 11 pt finger labels, and chord grips room before scaling this single bar to a phone.
|
|
40
|
+
const logicalWidth = Math.max(width, 520);
|
|
41
41
|
const spec = {
|
|
42
42
|
sheet: { width: logicalWidth - 32, x: 16, y: 35 },
|
|
43
43
|
continuous: {},
|
|
@@ -74,6 +74,8 @@ export declare class ContinuousLayout {
|
|
|
74
74
|
private readonly splitChords;
|
|
75
75
|
private readonly spelledSpans;
|
|
76
76
|
private readonly options;
|
|
77
|
+
/** A leading tab fret needs room for the incoming tie after the repeated clef. */
|
|
78
|
+
private readonly tabTiePadding;
|
|
77
79
|
private readonly arrivals;
|
|
78
80
|
constructor(score: EasyScoreComposition, spec: EasyScoreCompositionSpec, starts: State[][], ends: State[][], placed?: Set<Accidental>);
|
|
79
81
|
/** Only undecorated, wholly resting measures can disappear into a numbered rest. */
|
|
@@ -94,6 +96,8 @@ export declare class ContinuousLayout {
|
|
|
94
96
|
private alignStaves;
|
|
95
97
|
/** Reconcile staff envelopes across all measures in a row, then translate the entire solved row once. */
|
|
96
98
|
private layoutRow;
|
|
99
|
+
/** Carry the source syllable's distance from its top staff line to each continuation. */
|
|
100
|
+
private lyricBaseline;
|
|
97
101
|
/** Keep continuation hooks and labels on the correct end when a span crosses a row. */
|
|
98
102
|
private addFragment;
|
|
99
103
|
/** Add labels, connectors and numbered rests after all native positions have settled. */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Annotation } from './annotation';
|
|
1
2
|
import { Bounds } from './boundingbox';
|
|
2
3
|
import { Element } from './element';
|
|
3
4
|
import { Note } from './note';
|
|
@@ -6,12 +7,14 @@ import { Stave } from './stave';
|
|
|
6
7
|
export type ContinuousSpanKind = 'tie' | 'slur' | 'crescendo' | 'diminuendo' | 'pedal' | 'lyric' | 'hyphen' | 'volta' | 'ottava' | 'trill' | 'tuplet' | 'palmMute';
|
|
7
8
|
export interface ContinuousSpan {
|
|
8
9
|
kind: ContinuousSpanKind;
|
|
10
|
+
/** One-based string of a tab tie. Defaults to the string of the selected chord position. */
|
|
11
|
+
string?: number;
|
|
9
12
|
/** Required for palmMute. String numbers are one-based. */
|
|
10
13
|
strings?: readonly number[];
|
|
11
14
|
id: string;
|
|
12
15
|
from: string;
|
|
13
16
|
to: string;
|
|
14
|
-
/** Optional chord-head indices
|
|
17
|
+
/** Optional zero-based chord-head indices. On a tab tie these index the positions arrays. */
|
|
15
18
|
fromHead?: number;
|
|
16
19
|
toHead?: number;
|
|
17
20
|
side?: 'above' | 'below';
|
|
@@ -19,6 +22,8 @@ export interface ContinuousSpan {
|
|
|
19
22
|
text?: string;
|
|
20
23
|
/** Optional type size for this label, in points. Measured before system breaks are chosen. */
|
|
21
24
|
labelFontSize?: number;
|
|
25
|
+
/** For a lyric extender, take the baseline and ink edge from this Annotation on the source note. */
|
|
26
|
+
syllableId?: string;
|
|
22
27
|
}
|
|
23
28
|
export interface SpanAnchor {
|
|
24
29
|
measure: number;
|
|
@@ -30,6 +35,7 @@ export interface ResolvedSpan {
|
|
|
30
35
|
first: SpanAnchor;
|
|
31
36
|
last: SpanAnchor;
|
|
32
37
|
label?: Element;
|
|
38
|
+
syllable?: Annotation;
|
|
33
39
|
}
|
|
34
40
|
export interface SpanFragment {
|
|
35
41
|
id: string;
|
|
@@ -42,7 +48,7 @@ export interface SpanFragment {
|
|
|
42
48
|
y2: number;
|
|
43
49
|
/** Fraction of the drawn span used to interpolate the aperture across a system break. */
|
|
44
50
|
progress: [number, number];
|
|
45
|
-
/** String numbers covered by a palm-mute fragment. */
|
|
51
|
+
/** String numbers covered by a tab tie or palm-mute fragment. */
|
|
46
52
|
strings?: readonly number[];
|
|
47
53
|
/** Authored TAB endpoints appear on the fragments containing them. */
|
|
48
54
|
from?: string;
|
|
@@ -6,6 +6,7 @@ import { GraceNoteStruct } from '../gracenote';
|
|
|
6
6
|
import { Note } from '../note';
|
|
7
7
|
import { Sheet, SheetOptions } from '../sheet';
|
|
8
8
|
import { Stave, StaveOptions } from '../stave';
|
|
9
|
+
import { BarlineType } from '../stavebarline';
|
|
9
10
|
import { StaveNoteStruct } from '../stavenote';
|
|
10
11
|
import { System, SystemOptions } from '../system';
|
|
11
12
|
import { TabNoteStruct } from '../tabnote';
|
|
@@ -18,6 +19,8 @@ export interface EasyScoreStaffState {
|
|
|
18
19
|
clef?: string;
|
|
19
20
|
key?: string;
|
|
20
21
|
time?: string;
|
|
22
|
+
/** Hide or reveal the meter sign while preserving the meter used for timing and beaming. */
|
|
23
|
+
showTimeSignature?: boolean;
|
|
21
24
|
}
|
|
22
25
|
/** Explicit signs survive key-aware generation, including cautionaries and microtones. */
|
|
23
26
|
interface GracePitchSpec extends GraceNoteStruct {
|
|
@@ -59,6 +62,16 @@ export interface EasyScoreVoiceSpec {
|
|
|
59
62
|
}[];
|
|
60
63
|
autoBeam?: boolean | EasyScoreAutoBeamOptions;
|
|
61
64
|
}
|
|
65
|
+
/** A written mark anchored by note ID on its owning staff and measure. */
|
|
66
|
+
interface LeadMark {
|
|
67
|
+
note: string;
|
|
68
|
+
text: string;
|
|
69
|
+
}
|
|
70
|
+
/** A lyric connector stays within its verse and measure. */
|
|
71
|
+
interface LyricMark extends LeadMark {
|
|
72
|
+
hyphenAfter?: boolean;
|
|
73
|
+
extendTo?: string;
|
|
74
|
+
}
|
|
62
75
|
/** span is the actual duration of a pickup; time remains its displayed meter. */
|
|
63
76
|
export interface EasyScoreMeasureSpec extends EasyScoreStaffState {
|
|
64
77
|
instrument?: {
|
|
@@ -67,6 +80,12 @@ export interface EasyScoreMeasureSpec extends EasyScoreStaffState {
|
|
|
67
80
|
};
|
|
68
81
|
voices: readonly EasyScoreVoiceSpec[];
|
|
69
82
|
span?: VoiceTime | string;
|
|
83
|
+
/** The barline drawn at this measure's right edge. */
|
|
84
|
+
endBarline?: BarlineType;
|
|
85
|
+
/** Literal chord names sharing a lane above their notes. */
|
|
86
|
+
chords?: readonly LeadMark[];
|
|
87
|
+
/** Each ordered list of syllables forms a separate lyric lane. */
|
|
88
|
+
verses?: readonly (readonly LyricMark[])[];
|
|
70
89
|
}
|
|
71
90
|
/** Staves have aligned measure arrays. Missing or uneven measures are errors. */
|
|
72
91
|
export interface EasyScoreStaveSpec extends EasyScoreStaffState {
|
|
@@ -12,6 +12,8 @@ export interface FretDiagramSpec {
|
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
14
|
export declare class FretDiagram extends Element {
|
|
15
|
+
/** The registry and font metrics both use the diagram category. */
|
|
16
|
+
static get CATEGORY(): string;
|
|
15
17
|
private readonly frets;
|
|
16
18
|
private readonly first;
|
|
17
19
|
private readonly rows;
|