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
|
@@ -224,7 +224,8 @@ export class Annotation extends Modifier {
|
|
|
224
224
|
const topY = Math.min(...note.getYs());
|
|
225
225
|
y = topY - (this.textLine + 1) * Tables.STAVE_LINE_DISTANCE;
|
|
226
226
|
if (hasStem && stemDirection === Stem.UP) {
|
|
227
|
-
|
|
227
|
+
if (!isTabNote(note) && stemExt.topY < stave.getTopLineTopY())
|
|
228
|
+
spacing = Tables.STAVE_LINE_DISTANCE;
|
|
228
229
|
y = Math.min(y, stemExt.topY - spacing * (this.textLine + 1));
|
|
229
230
|
}
|
|
230
231
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Accidental } from './accidental.js';
|
|
2
|
+
import { Annotation } from './annotation.js';
|
|
2
3
|
import { Clef } from './clef.js';
|
|
3
4
|
import { continuationPitch, drawSpan, fitSpan, spanAbove, spanLabel, } from './continuousspan.js';
|
|
4
5
|
import { Element } from './element.js';
|
|
@@ -20,6 +21,25 @@ import { RuntimeError } from './util.js';
|
|
|
20
21
|
function invalid(message) {
|
|
21
22
|
throw new RuntimeError('BadContinuousScore', message);
|
|
22
23
|
}
|
|
24
|
+
function resolveTabTie(span, first, last) {
|
|
25
|
+
var _a, _b, _c, _d, _e;
|
|
26
|
+
const start = first.getPositions();
|
|
27
|
+
const end = last.getPositions();
|
|
28
|
+
for (const head of [span.fromHead, span.toHead]) {
|
|
29
|
+
if (head !== undefined && (!Number.isInteger(head) || head < 0))
|
|
30
|
+
invalid('Invalid tab tie position index.');
|
|
31
|
+
}
|
|
32
|
+
const selected = span.fromHead === undefined && span.toHead !== undefined ? end[span.toHead] : start[(_a = span.fromHead) !== null && _a !== void 0 ? _a : 0];
|
|
33
|
+
const string = (_b = span.string) !== null && _b !== void 0 ? _b : selected === null || selected === void 0 ? void 0 : selected.str;
|
|
34
|
+
if (string === undefined || !Number.isInteger(string) || string < 1 || string > first.checkStave().getNumLines())
|
|
35
|
+
invalid('A tab tie needs a string on its staff.');
|
|
36
|
+
const fromHead = (_c = span.fromHead) !== null && _c !== void 0 ? _c : start.findIndex((p) => p.str === string);
|
|
37
|
+
const toHead = (_d = span.toHead) !== null && _d !== void 0 ? _d : end.findIndex((p) => p.str === string);
|
|
38
|
+
const from = start[fromHead], to = end[toHead];
|
|
39
|
+
if (!from || !to || from.str !== string || to.str !== string || String(from.fret) !== String(to.fret))
|
|
40
|
+
invalid('Tab tie endpoints must play the same string and fret.');
|
|
41
|
+
return Object.assign(Object.assign({}, span), { fromHead, toHead, string, side: (_e = span.side) !== null && _e !== void 0 ? _e : 'above' });
|
|
42
|
+
}
|
|
23
43
|
export class ContinuousLayout {
|
|
24
44
|
headerLabel(text, symbol = false) {
|
|
25
45
|
const key = (symbol ? 'glyph:' : 'text:') + text;
|
|
@@ -67,6 +87,7 @@ export class ContinuousLayout {
|
|
|
67
87
|
this.headerLabels = new Map();
|
|
68
88
|
this.splitChords = [];
|
|
69
89
|
this.spelledSpans = new Set();
|
|
90
|
+
this.tabTiePadding = new Map();
|
|
70
91
|
this.arrivals = new Map();
|
|
71
92
|
this.options = (_a = spec.continuous) !== null && _a !== void 0 ? _a : {};
|
|
72
93
|
for (const voice of score.voices.flat(2))
|
|
@@ -129,7 +150,7 @@ export class ContinuousLayout {
|
|
|
129
150
|
end.push(new Clef(next.clef, 'small'));
|
|
130
151
|
if (next.clef !== 'tab' && next.key !== current.key)
|
|
131
152
|
end.push(new KeySignature(next.key, current.key));
|
|
132
|
-
if (next.time !== current.time)
|
|
153
|
+
if (next.showTimeSignature && next.time !== current.time)
|
|
133
154
|
end.push(new TimeSignature(next.time));
|
|
134
155
|
}
|
|
135
156
|
end.forEach((m) => m.setPosition(Position.END));
|
|
@@ -201,6 +222,9 @@ export class ContinuousLayout {
|
|
|
201
222
|
!last ||
|
|
202
223
|
first.measure > last.measure)
|
|
203
224
|
invalid('Expected a unique span ID and ordered composition anchors.');
|
|
225
|
+
let spec = Object.assign({}, span);
|
|
226
|
+
if (span.string !== undefined && !(span.kind === 'tie' && first.note instanceof TabNote))
|
|
227
|
+
invalid('A string selector requires a tab tie.');
|
|
204
228
|
if (span.kind === 'palmMute') {
|
|
205
229
|
if (!(first.note instanceof TabNote) || !(last.note instanceof TabNote) || first.staff !== last.staff)
|
|
206
230
|
invalid('A palm mute needs two TAB anchors on the same staff.');
|
|
@@ -211,6 +235,18 @@ export class ContinuousLayout {
|
|
|
211
235
|
for (const note of [first.note, last.note])
|
|
212
236
|
if (!note.getPositions().some((p) => span.strings.includes(p.str)))
|
|
213
237
|
invalid('Each palm-mute anchor must play a targeted string.');
|
|
238
|
+
spec.strings = [...span.strings];
|
|
239
|
+
}
|
|
240
|
+
else if (first.note instanceof TabNote && last.note instanceof TabNote) {
|
|
241
|
+
if (first.staff !== last.staff || (span.kind !== 'tie' && span.kind !== 'volta'))
|
|
242
|
+
invalid('Tab ties and endings need anchors on the same tab staff.');
|
|
243
|
+
if (span.kind === 'tie') {
|
|
244
|
+
spec = resolveTabTie(span, first.note, last.note);
|
|
245
|
+
if (first.measure !== last.measure && onset(last.note).numerator === 0) {
|
|
246
|
+
const stave = last.note.checkStave();
|
|
247
|
+
this.tabTiePadding.set(stave, stave.space(1.5));
|
|
248
|
+
}
|
|
249
|
+
}
|
|
214
250
|
}
|
|
215
251
|
else {
|
|
216
252
|
if (!(first.note instanceof StaveNote) || !(last.note instanceof StaveNote))
|
|
@@ -224,7 +260,15 @@ export class ContinuousLayout {
|
|
|
224
260
|
}
|
|
225
261
|
if (first.measure === last.measure && onset(first.note).greaterThan(onset(last.note)))
|
|
226
262
|
invalid('Reversed span.');
|
|
227
|
-
if (span.
|
|
263
|
+
if (span.syllableId !== undefined &&
|
|
264
|
+
(typeof span.syllableId !== 'string' ||
|
|
265
|
+
span.syllableId.length === 0 ||
|
|
266
|
+
span.kind !== 'lyric' ||
|
|
267
|
+
first.staff !== last.staff ||
|
|
268
|
+
span.text !== undefined ||
|
|
269
|
+
span.labelFontSize !== undefined))
|
|
270
|
+
invalid('An anchored lyric extender needs a syllable ID and two notes on the same staff. Its annotation supplies the text and font.');
|
|
271
|
+
if (span.kind === 'tie' && first.note instanceof StaveNote && first.measure !== last.measure) {
|
|
228
272
|
const fi = (_k = span.fromHead) !== null && _k !== void 0 ? _k : 0, li = (_l = span.toHead) !== null && _l !== void 0 ? _l : 0;
|
|
229
273
|
if (first.note.getKeys()[fi].toLowerCase() !== last.note.getKeys()[li].toLowerCase())
|
|
230
274
|
invalid('Tied heads must have the same written pitch.');
|
|
@@ -238,7 +282,6 @@ export class ContinuousLayout {
|
|
|
238
282
|
}
|
|
239
283
|
}
|
|
240
284
|
seen.add(span.id);
|
|
241
|
-
const spec = span.kind === 'palmMute' ? Object.assign(Object.assign({}, span), { strings: [...span.strings] }) : Object.assign({}, span);
|
|
242
285
|
this.spans.push({ spec, first, last, label: spanLabel(spec) });
|
|
243
286
|
}
|
|
244
287
|
}
|
|
@@ -255,7 +298,12 @@ export class ContinuousLayout {
|
|
|
255
298
|
return false;
|
|
256
299
|
return this.score.notes[i]
|
|
257
300
|
.flat(2)
|
|
258
|
-
.every((n) => n instanceof StaveNote &&
|
|
301
|
+
.every((n) => n instanceof StaveNote &&
|
|
302
|
+
n.isRest() &&
|
|
303
|
+
n.restLine === undefined &&
|
|
304
|
+
!n.getModifiers().length &&
|
|
305
|
+
!n.getBeam() &&
|
|
306
|
+
!n.getTupletStack().length);
|
|
259
307
|
}
|
|
260
308
|
boundaryWidth(i, start, end) {
|
|
261
309
|
var _a;
|
|
@@ -270,7 +318,7 @@ export class ContinuousLayout {
|
|
|
270
318
|
return Math.max(...staves.map((s, j) => {
|
|
271
319
|
var _a, _b;
|
|
272
320
|
const marks = this.marks[i][j];
|
|
273
|
-
s.setBoundaryModifiers([...(start ? marks.start : []), ...(end ? marks.end : [])]);
|
|
321
|
+
s.setBoundaryModifiers([...(start ? marks.start : []), ...(end ? marks.end : [])], start ? this.tabTiePadding.get(s) : 0);
|
|
274
322
|
const bar = s.getModifiers(Position.END, Barline.CATEGORY)[0];
|
|
275
323
|
return Math.max(s.getX() + s.getWidth() - s.getNoteEndX(), -((_b = (_a = bar === null || bar === void 0 ? void 0 : bar.getLayoutMetrics()) === null || _a === void 0 ? void 0 : _a.xMin) !== null && _b !== void 0 ? _b : 0));
|
|
276
324
|
}));
|
|
@@ -334,7 +382,8 @@ export class ContinuousLayout {
|
|
|
334
382
|
const used = new Set();
|
|
335
383
|
for (let i = first; i <= last; i++) {
|
|
336
384
|
this.score.notes[i].flat(2).forEach((n) => {
|
|
337
|
-
if (n instanceof Note &&
|
|
385
|
+
if (n instanceof Note &&
|
|
386
|
+
(!(n instanceof StaveNote) || !n.isRest() || n.restLine !== undefined || n.getModifiers().length))
|
|
338
387
|
used.add(this.score.staves[i].indexOf(n.checkStave()));
|
|
339
388
|
});
|
|
340
389
|
}
|
|
@@ -362,6 +411,16 @@ export class ContinuousLayout {
|
|
|
362
411
|
}
|
|
363
412
|
format(options) {
|
|
364
413
|
var _a;
|
|
414
|
+
for (const span of this.spans) {
|
|
415
|
+
if (!span.spec.syllableId)
|
|
416
|
+
continue;
|
|
417
|
+
const matches = span.first.note
|
|
418
|
+
.getModifiers()
|
|
419
|
+
.filter((m) => m instanceof Annotation && m.getAttribute('id') === span.spec.syllableId);
|
|
420
|
+
if (matches.length !== 1)
|
|
421
|
+
invalid('Expected one lyric annotation on the source note: ' + span.spec.syllableId);
|
|
422
|
+
span.syllable = matches[0];
|
|
423
|
+
}
|
|
365
424
|
this.hidden.clear();
|
|
366
425
|
this.diagnostics.length = 0;
|
|
367
426
|
this.fragments.length = 0;
|
|
@@ -487,6 +546,14 @@ export class ContinuousLayout {
|
|
|
487
546
|
for (const s of spans) {
|
|
488
547
|
if (s.spec.kind === 'tie' || s.spec.kind === 'slur')
|
|
489
548
|
continue;
|
|
549
|
+
if (s.syllable) {
|
|
550
|
+
const stave = this.score.staves[first][s.first.staff];
|
|
551
|
+
const relativeY = this.lyricBaseline(s.syllable, stave) - stave.getY();
|
|
552
|
+
const bounds = ink[s.first.staff];
|
|
553
|
+
bounds.top = Math.min(bounds.top, relativeY);
|
|
554
|
+
bounds.bottom = Math.max(bounds.bottom, relativeY + 2);
|
|
555
|
+
continue;
|
|
556
|
+
}
|
|
490
557
|
const side = spanAbove(s.spec), staff = s.first.staff, key = staff + '-' + side;
|
|
491
558
|
const ends = (_a = laneEnds.get(key)) !== null && _a !== void 0 ? _a : [];
|
|
492
559
|
let lane = ends.findIndex((v) => v < s.first.measure);
|
|
@@ -554,8 +621,13 @@ export class ContinuousLayout {
|
|
|
554
621
|
}
|
|
555
622
|
return row;
|
|
556
623
|
}
|
|
624
|
+
lyricBaseline(word, stave) {
|
|
625
|
+
const source = word.checkAttachedNote().checkStave();
|
|
626
|
+
const spaces = (word.computeY().y + word.getYShift() - source.getYForLine(0)) / source.space(1);
|
|
627
|
+
return stave.getYForLine(0) + stave.space(spaces);
|
|
628
|
+
}
|
|
557
629
|
addFragment(s, units, row, baseline) {
|
|
558
|
-
var _a, _b;
|
|
630
|
+
var _a, _b, _c;
|
|
559
631
|
const first = units[0].first, last = units[units.length - 1].first;
|
|
560
632
|
const starts = s.first.measure >= first, ends = s.last.measure <= units[units.length - 1].last;
|
|
561
633
|
const { kind } = s.spec, above = spanAbove(s.spec);
|
|
@@ -564,19 +636,38 @@ export class ContinuousLayout {
|
|
|
564
636
|
let x1 = starts ? s.first.note.getAbsoluteX() : startStaff.getNoteStartX() + 2;
|
|
565
637
|
let x2 = ends ? s.last.note.getAbsoluteX() + s.last.note.getGlyphWidth() : endStaff.getNoteEndX() - 3;
|
|
566
638
|
let y1 = baseline, y2 = baseline;
|
|
639
|
+
if (s.syllable) {
|
|
640
|
+
y1 = y2 = this.lyricBaseline(s.syllable, startStaff);
|
|
641
|
+
if (starts) {
|
|
642
|
+
const ink = s.syllable.getTextInk(s.syllable.computeX().x, s.syllable.computeY().y);
|
|
643
|
+
x1 = ink.x + ink.w + space * 0.35;
|
|
644
|
+
}
|
|
645
|
+
if (ends)
|
|
646
|
+
x2 = s.last.note.getNoteHeadBeginX() + s.last.note.getGlyphWidth();
|
|
647
|
+
}
|
|
567
648
|
if (kind === 'tie' || kind === 'slur') {
|
|
568
649
|
if (starts)
|
|
569
650
|
x1 = s.first.note.getTieRightX();
|
|
570
651
|
if (ends)
|
|
571
652
|
x2 = s.last.note.getTieLeftX();
|
|
572
|
-
|
|
573
|
-
(starts
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
(ends ? s.last.note.
|
|
579
|
-
|
|
653
|
+
if (s.spec.string !== undefined) {
|
|
654
|
+
if (!starts)
|
|
655
|
+
x1 -= (_a = this.tabTiePadding.get(startStaff)) !== null && _a !== void 0 ? _a : 0;
|
|
656
|
+
const line = s.spec.string - 1;
|
|
657
|
+
const clearance = sign * space * 0.3;
|
|
658
|
+
y1 = (starts ? s.first.note.checkStave() : startStaff).getYForLine(line) + clearance;
|
|
659
|
+
y2 = (ends ? s.last.note.checkStave() : endStaff).getYForLine(line) + clearance;
|
|
660
|
+
}
|
|
661
|
+
else {
|
|
662
|
+
y1 =
|
|
663
|
+
(starts
|
|
664
|
+
? s.first.note.getYs()[(_b = s.spec.fromHead) !== null && _b !== void 0 ? _b : 0]
|
|
665
|
+
: continuationPitch(s.first, startStaff, s.spec.fromHead)) +
|
|
666
|
+
sign * space * (starts ? 0.5 : 1.1);
|
|
667
|
+
y2 =
|
|
668
|
+
(ends ? s.last.note.getYs()[(_c = s.spec.toHead) !== null && _c !== void 0 ? _c : 0] : continuationPitch(s.last, endStaff, s.spec.toHead)) +
|
|
669
|
+
sign * space * (ends ? 0.5 : 1.1);
|
|
670
|
+
}
|
|
580
671
|
}
|
|
581
672
|
if (kind === 'volta') {
|
|
582
673
|
x1 = starts ? this.score.staves[s.first.measure][s.first.staff].getX() + 1 : startStaff.getX() + 1;
|
|
@@ -595,7 +686,7 @@ export class ContinuousLayout {
|
|
|
595
686
|
const fragment = Object.assign(Object.assign({ id: s.spec.id, kind, row: this.rows.length, part: starts ? (ends ? 'single' : 'first') : ends ? 'last' : 'middle', x1,
|
|
596
687
|
x2,
|
|
597
688
|
y1,
|
|
598
|
-
y2, progress: [0, 1] }, (kind === 'palmMute' && Object.assign(Object.assign({ strings: s.spec.strings }, (starts && { from: s.spec.from })), (ends && { to: s.spec.to })))), { above,
|
|
689
|
+
y2, progress: [0, 1] }, ((kind === 'palmMute' || s.spec.string !== undefined) && Object.assign(Object.assign({ strings: s.spec.string !== undefined ? [s.spec.string] : s.spec.strings }, (starts && { from: s.spec.from })), (ends && { to: s.spec.to })))), { above,
|
|
599
690
|
space });
|
|
600
691
|
if (kind === 'tie' || kind === 'slur') {
|
|
601
692
|
const events = units.flatMap((u) => {
|
|
@@ -7,7 +7,12 @@ export function spanLabel(spec) {
|
|
|
7
7
|
const text = (_b = (_a = spec.text) !== null && _a !== void 0 ? _a : (spec.kind === 'palmMute' ? 'P.M. ' + spec.strings.join(',') : undefined)) !== null && _b !== void 0 ? _b : { volta: '1.', ottava: '8va', trill: Glyphs.ornamentTrill, tuplet: '3' }[spec.kind];
|
|
8
8
|
if (!text)
|
|
9
9
|
return;
|
|
10
|
-
|
|
10
|
+
let category = 'Annotation';
|
|
11
|
+
if (spec.kind === 'trill')
|
|
12
|
+
category = 'Ornament';
|
|
13
|
+
if (spec.kind === 'lyric' || spec.kind === 'hyphen')
|
|
14
|
+
category = 'Annotation.lyric';
|
|
15
|
+
const label = new Element(category).setText(text);
|
|
11
16
|
if (spec.labelFontSize !== undefined)
|
|
12
17
|
label.setFontSize(spec.labelFontSize);
|
|
13
18
|
return label;
|
|
@@ -10,10 +10,14 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import { ContinuousLayout } from '../continuouslayout.js';
|
|
13
|
+
import { Dot } from '../dot.js';
|
|
13
14
|
import { Factory } from '../factory.js';
|
|
14
15
|
import { Fraction } from '../fraction.js';
|
|
16
|
+
import { Metrics } from '../metrics.js';
|
|
15
17
|
import { Modifier } from '../modifier.js';
|
|
16
18
|
import { Note } from '../note.js';
|
|
19
|
+
import { BarlineType } from '../stavebarline.js';
|
|
20
|
+
import { StaveNote } from '../stavenote.js';
|
|
17
21
|
import { StemmableNote } from '../stemmablenote.js';
|
|
18
22
|
import { Tickable } from '../tickable.js';
|
|
19
23
|
import { RuntimeError } from '../util.js';
|
|
@@ -87,15 +91,20 @@ function buildVoice(score, spec, initial, display) {
|
|
|
87
91
|
notes.push(score.make.clefNote({ type: state.clef, options: { size: 'small' } }));
|
|
88
92
|
if (item.change.key)
|
|
89
93
|
notes.push(score.make.keySigNote({ key: state.key, cancelKey: previous.key, clef: state.clef }));
|
|
90
|
-
if (item.change.time)
|
|
94
|
+
if (state.showTimeSignature && (item.change.time || !previous.showTimeSignature))
|
|
91
95
|
notes.push(score.make.timeSigNote({ time: state.time }));
|
|
92
96
|
}
|
|
93
97
|
score.set({ clef: state.clef, time: state.time });
|
|
94
98
|
}
|
|
95
99
|
else {
|
|
96
|
-
const
|
|
100
|
+
const tab = 'tab' in item;
|
|
101
|
+
const note = tab
|
|
97
102
|
? score.make.tabNote(item.tab, item.drawStem)
|
|
98
103
|
: score.make.note('note' in item ? item.note : item);
|
|
104
|
+
if (!tab || item.drawStem) {
|
|
105
|
+
for (let i = 0; i < note.writtenDots; i++)
|
|
106
|
+
Dot.buildAndAttach([note], { all: !tab });
|
|
107
|
+
}
|
|
99
108
|
if ('grace' in item && item.grace) {
|
|
100
109
|
score.attach(note, buildGraceGroup(score, item.grace), 0);
|
|
101
110
|
}
|
|
@@ -141,7 +150,7 @@ function addSignatures(score, stave, state, previous) {
|
|
|
141
150
|
score.attachToStave(stave, score.make.clef(state.clef));
|
|
142
151
|
if (state.clef !== 'tab' && (!previous || previous.key !== state.key))
|
|
143
152
|
score.attachToStave(stave, score.make.keySignature(state.key, previous === null || previous === void 0 ? void 0 : previous.key));
|
|
144
|
-
if (!previous || previous.time !== state.time)
|
|
153
|
+
if (state.showTimeSignature && (!(previous === null || previous === void 0 ? void 0 : previous.showTimeSignature) || previous.time !== state.time))
|
|
145
154
|
score.attachToStave(stave, score.make.timeSignature(state.time));
|
|
146
155
|
}
|
|
147
156
|
function buildSpans(score, spec, measures, diagnostics) {
|
|
@@ -169,18 +178,68 @@ function buildSpans(score, spec, measures, diagnostics) {
|
|
|
169
178
|
return score.make.hairpin({ from, to, type: span.type, options: span.options });
|
|
170
179
|
});
|
|
171
180
|
}
|
|
172
|
-
function
|
|
181
|
+
function addLeadMarks(score, system, measure, voices) {
|
|
182
|
+
var _a, _b, _c, _d, _e;
|
|
183
|
+
if (!((_a = measure.chords) === null || _a === void 0 ? void 0 : _a.length) && !((_b = measure.verses) === null || _b === void 0 ? void 0 : _b.length))
|
|
184
|
+
return;
|
|
185
|
+
const members = new Set(voices.flat());
|
|
186
|
+
const anchor = (id) => {
|
|
187
|
+
const note = score.getNote(id);
|
|
188
|
+
if (!members.has(note))
|
|
189
|
+
invalid(`Lead mark anchor ${id} belongs to another staff or measure.`);
|
|
190
|
+
return note;
|
|
191
|
+
};
|
|
192
|
+
const chordLanes = new Map();
|
|
193
|
+
for (const chord of (_c = measure.chords) !== null && _c !== void 0 ? _c : []) {
|
|
194
|
+
const note = anchor(chord.note);
|
|
195
|
+
if (!chord.text)
|
|
196
|
+
invalid('A chord label needs text.');
|
|
197
|
+
const mark = score.make.annotation({ text: chord.text, vJustify: 'top', font: Metrics.getFontInfo('ChordSymbol') });
|
|
198
|
+
score.attach(note, mark);
|
|
199
|
+
if (note instanceof StaveNote) {
|
|
200
|
+
const stave = note.checkStave();
|
|
201
|
+
const lane = (_d = chordLanes.get(stave)) !== null && _d !== void 0 ? _d : [];
|
|
202
|
+
lane.push(mark);
|
|
203
|
+
chordLanes.set(stave, lane);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
for (const [stave, marks] of chordLanes)
|
|
207
|
+
system.getPhraseLayout().addLane(stave, marks, { side: 'above' });
|
|
208
|
+
const lyricAnchor = (id) => {
|
|
209
|
+
const note = anchor(id);
|
|
210
|
+
if (!(note instanceof StaveNote))
|
|
211
|
+
invalid('A lyric needs a pitched staff note.');
|
|
212
|
+
return note;
|
|
213
|
+
};
|
|
214
|
+
for (const verse of (_e = measure.verses) !== null && _e !== void 0 ? _e : []) {
|
|
215
|
+
if (!verse.length)
|
|
216
|
+
invalid('A verse needs at least one syllable.');
|
|
217
|
+
const syllables = verse.map(({ note, text, hyphenAfter, extendTo }) => ({
|
|
218
|
+
note: lyricAnchor(note),
|
|
219
|
+
text,
|
|
220
|
+
hyphenAfter,
|
|
221
|
+
extendTo: extendTo === undefined ? undefined : lyricAnchor(extendTo),
|
|
222
|
+
}));
|
|
223
|
+
system.getPhraseLayout().addVerse(syllables[0].note.checkStave(), syllables);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function measureState(measure, previous) {
|
|
173
227
|
var _a, _b, _c, _d;
|
|
174
|
-
|
|
175
|
-
const measure = staff.measures[index];
|
|
176
|
-
if (!measure.voices.length)
|
|
177
|
-
invalid('Every stave measure needs at least one voice.');
|
|
178
|
-
const state = {
|
|
228
|
+
return {
|
|
179
229
|
clef: (_a = measure.clef) !== null && _a !== void 0 ? _a : previous.clef,
|
|
180
230
|
key: (_b = measure.key) !== null && _b !== void 0 ? _b : previous.key,
|
|
181
231
|
time: (_c = measure.time) !== null && _c !== void 0 ? _c : previous.time,
|
|
232
|
+
showTimeSignature: (_d = measure.showTimeSignature) !== null && _d !== void 0 ? _d : previous.showTimeSignature,
|
|
182
233
|
};
|
|
183
|
-
|
|
234
|
+
}
|
|
235
|
+
function buildStaffMeasure(score, spec, staff, index, previous, tracking) {
|
|
236
|
+
var _a;
|
|
237
|
+
const assignments = new Map();
|
|
238
|
+
const measure = staff.measures[index];
|
|
239
|
+
if (!measure.voices.length)
|
|
240
|
+
invalid('Every stave measure needs at least one voice.');
|
|
241
|
+
const state = measureState(measure, previous);
|
|
242
|
+
const span = (_a = measure.span) !== null && _a !== void 0 ? _a : state.time;
|
|
184
243
|
const ticks = ticksFor(span);
|
|
185
244
|
const built = measure.voices.map((voice, voiceIndex) => buildVoice(score, voice, state, voiceIndex === 0));
|
|
186
245
|
const changes = stateChanges(built[0]);
|
|
@@ -216,6 +275,13 @@ function buildStaffMeasure(score, spec, staff, index, previous, tracking) {
|
|
|
216
275
|
const stave = staff.kind === 'tab'
|
|
217
276
|
? score.make.tabStave({ options: staff.options })
|
|
218
277
|
: score.make.stave({ options: Object.assign(Object.assign({}, staff.options), { clef: state.clef }) });
|
|
278
|
+
if (measure.endBarline !== undefined) {
|
|
279
|
+
if (!Number.isInteger(measure.endBarline) ||
|
|
280
|
+
!BarlineType[measure.endBarline] ||
|
|
281
|
+
measure.endBarline === BarlineType.REPEAT_BEGIN)
|
|
282
|
+
invalid('Invalid end barline.');
|
|
283
|
+
stave.setEndBarType(measure.endBarline);
|
|
284
|
+
}
|
|
219
285
|
addSignatures(score, stave, state, index && spec.signatures !== 'every-measure' ? previous : undefined);
|
|
220
286
|
return {
|
|
221
287
|
stave,
|
|
@@ -259,7 +325,7 @@ export function compose(score, spec) {
|
|
|
259
325
|
(spec.accidentals === 'key-aware' ||
|
|
260
326
|
spec.staves.some((stave) => stave.measures.some((measure) => measure.voices.some((voice) => { var _a; return voice.autoBeam || ((_a = voice.tuplets) === null || _a === void 0 ? void 0 : _a.length); })))))
|
|
261
327
|
invalid('Apply rhythm and accidental policies before adopting native inputs, or use typed note descriptions.');
|
|
262
|
-
const
|
|
328
|
+
const priorNative = new Map(nativeInputs.map((note) => [note, { stave: note.getStave(), modifiers: note.getModifiers().length }]));
|
|
263
329
|
const seen = new Set();
|
|
264
330
|
try {
|
|
265
331
|
return score.build(() => {
|
|
@@ -280,22 +346,19 @@ export function compose(score, spec) {
|
|
|
280
346
|
message: 'Signatures appear at the first measure and explicit changes. Sheet does not repeat them at wrapped row starts.',
|
|
281
347
|
});
|
|
282
348
|
const states = spec.staves.map((stave) => {
|
|
283
|
-
var _a, _b, _c;
|
|
349
|
+
var _a, _b, _c, _d;
|
|
284
350
|
return ({
|
|
285
351
|
clef: (_a = stave.clef) !== null && _a !== void 0 ? _a : (stave.kind === 'tab' ? 'tab' : 'treble'),
|
|
286
352
|
key: (_b = stave.key) !== null && _b !== void 0 ? _b : 'C',
|
|
287
353
|
time: (_c = stave.time) !== null && _c !== void 0 ? _c : '4/4',
|
|
354
|
+
showTimeSignature: (_d = stave.showTimeSignature) !== null && _d !== void 0 ? _d : true,
|
|
288
355
|
});
|
|
289
356
|
});
|
|
290
357
|
const starts = [], ends = [];
|
|
291
358
|
const placed = spec.continuous ? new Set() : undefined;
|
|
292
359
|
const noteMeasures = new Map();
|
|
293
360
|
for (let index = 0; index < count; index++) {
|
|
294
|
-
starts.push(spec.staves.map((staff, j) =>
|
|
295
|
-
var _a, _b, _c;
|
|
296
|
-
const m = staff.measures[index], p = states[j];
|
|
297
|
-
return { clef: (_a = m.clef) !== null && _a !== void 0 ? _a : p.clef, key: (_b = m.key) !== null && _b !== void 0 ? _b : p.key, time: (_c = m.time) !== null && _c !== void 0 ? _c : p.time };
|
|
298
|
-
}));
|
|
361
|
+
starts.push(spec.staves.map((staff, j) => measureState(staff.measures[index], states[j])));
|
|
299
362
|
const system = result.sheet.addSystem(spec.system);
|
|
300
363
|
result.systems.push(system);
|
|
301
364
|
const parts = spec.staves.map((staff, staffIndex) => {
|
|
@@ -321,6 +384,7 @@ export function compose(score, spec) {
|
|
|
321
384
|
const generated = new Set(policies.flatMap((policy) => [...policy.generated]));
|
|
322
385
|
policies.forEach((policy, staffIndex) => applyCompositionAccidentals(score, voices.flat(), policy.key, policy.changes, generated, staves[staffIndex], spec.graceAccidentals === 'ordered', placed));
|
|
323
386
|
}
|
|
387
|
+
spec.staves.forEach((staff, j) => addLeadMarks(score, system, staff.measures[index], notes[j]));
|
|
324
388
|
ends.push(states.slice());
|
|
325
389
|
result.staves.push(staves);
|
|
326
390
|
result.voices.push(voices);
|
|
@@ -336,7 +400,8 @@ export function compose(score, spec) {
|
|
|
336
400
|
for (const note of nativeInputs)
|
|
337
401
|
if (seen.has(note)) {
|
|
338
402
|
note.clearVoice();
|
|
339
|
-
const stave =
|
|
403
|
+
const { stave, modifiers } = priorNative.get(note);
|
|
404
|
+
note.getModifiers().splice(modifiers);
|
|
340
405
|
if (stave)
|
|
341
406
|
note.setStave(stave);
|
|
342
407
|
else
|
package/build/esm/src/factory.js
CHANGED
|
@@ -395,19 +395,12 @@ export class Factory {
|
|
|
395
395
|
return this.own(annotation);
|
|
396
396
|
}
|
|
397
397
|
ChordSymbol(params) {
|
|
398
|
+
var _a, _b, _c;
|
|
398
399
|
const p = Object.assign({ vJustify: 'top', hJustify: 'center' }, params);
|
|
399
400
|
const chordSymbol = new ChordSymbol();
|
|
400
401
|
chordSymbol.setHorizontal(p.hJustify);
|
|
401
402
|
chordSymbol.setVertical(p.vJustify);
|
|
402
|
-
|
|
403
|
-
if (typeof p.fontWeight === 'string')
|
|
404
|
-
chordSymbol.setFont(p.fontFamily, p.fontSize, p.fontWeight);
|
|
405
|
-
else
|
|
406
|
-
chordSymbol.setFont(p.fontFamily, p.fontSize, '');
|
|
407
|
-
}
|
|
408
|
-
else if (typeof p.fontSize === 'number') {
|
|
409
|
-
chordSymbol.setFontSize(p.fontSize);
|
|
410
|
-
}
|
|
403
|
+
chordSymbol.setFont((_a = p.fontFamily) !== null && _a !== void 0 ? _a : chordSymbol.fontInfo.family, (_b = p.fontSize) !== null && _b !== void 0 ? _b : chordSymbol.fontInfo.size, (_c = p.fontWeight) !== null && _c !== void 0 ? _c : chordSymbol.fontInfo.weight, chordSymbol.fontInfo.style);
|
|
411
404
|
chordSymbol.setContext(this.context);
|
|
412
405
|
return this.own(chordSymbol);
|
|
413
406
|
}
|
|
@@ -2,6 +2,9 @@ import { BoundingBox } from './boundingbox.js';
|
|
|
2
2
|
import { Element } from './element.js';
|
|
3
3
|
import { RuntimeError } from './util.js';
|
|
4
4
|
export class FretDiagram extends Element {
|
|
5
|
+
static get CATEGORY() {
|
|
6
|
+
return "FretDiagram";
|
|
7
|
+
}
|
|
5
8
|
constructor(spec) {
|
|
6
9
|
var _a, _b;
|
|
7
10
|
super();
|
|
@@ -42,9 +45,10 @@ export class FretDiagram extends Element {
|
|
|
42
45
|
ctx.save();
|
|
43
46
|
const group = ctx.openGroup('fret-diagram', this.getAttribute('id'));
|
|
44
47
|
group === null || group === void 0 ? void 0 : group.setAttribute('aria-label', 'Chord frame, low to high: ' + this.frets.join(', ') + (this.barre ? ', barre at fret ' + this.barre.fret : ''));
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
if (this.first > 1) {
|
|
49
|
+
ctx.setFont(this.fontInfo);
|
|
47
50
|
ctx.fillText(String(this.first), this.getX() + 2, top + 9);
|
|
51
|
+
}
|
|
48
52
|
for (let row = 0; row <= this.rows; row++) {
|
|
49
53
|
ctx.setLineWidth(row === 0 && this.first === 1 ? 2.5 : 1);
|
|
50
54
|
line(left, top + row * 11, right, top + row * 11);
|
|
@@ -5,7 +5,7 @@ import { StaveNote } from './stavenote.js';
|
|
|
5
5
|
import { StaveTie } from './stavetie.js';
|
|
6
6
|
import { Tables } from './tables.js';
|
|
7
7
|
import { TabTie } from './tabtie.js';
|
|
8
|
-
import { isStaveNote } from './typeguard.js';
|
|
8
|
+
import { isStaveNote, isTabNote } from './typeguard.js';
|
|
9
9
|
import { log } from './util.js';
|
|
10
10
|
import { Voice } from './voice.js';
|
|
11
11
|
function L(...args) {
|
|
@@ -94,12 +94,13 @@ export class GraceNoteGroup extends Modifier {
|
|
|
94
94
|
note.checkStave();
|
|
95
95
|
this.preFormat();
|
|
96
96
|
this.alignSubNotesWithNote(this.getGraceNotes(), note, this.position);
|
|
97
|
-
|
|
97
|
+
const fretOverhang = isTabNote(note) ? note.getLeftDisplacedHeadPx() : 0;
|
|
98
|
+
if (this.afterWidth || fretOverhang) {
|
|
98
99
|
for (const grace of this.graceNotes) {
|
|
99
100
|
const tick = grace.getTickContext();
|
|
100
101
|
tick.setXOffset(this.position === Modifier.Position.RIGHT
|
|
101
102
|
? note.getTickContext().getX() + this.afterOffset
|
|
102
|
-
: tick.getXOffset() + this.afterWidth);
|
|
103
|
+
: tick.getXOffset() + this.afterWidth - fretOverhang);
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
this.beams.forEach((beam) => beam.postFormat());
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Annotation } from './annotation.js';
|
|
2
2
|
import { Bend } from './bend.js';
|
|
3
|
+
import { Metrics } from './metrics.js';
|
|
3
4
|
import { Stroke } from './strokes.js';
|
|
4
5
|
import { isTabNote } from './typeguard.js';
|
|
5
6
|
import { RuntimeError } from './util.js';
|
|
@@ -14,7 +15,9 @@ export function attachGuitarGestures(note) {
|
|
|
14
15
|
const { stroke, bend } = entry;
|
|
15
16
|
if (stroke) {
|
|
16
17
|
note.addModifier(new Stroke(printedStroke(stroke), { allVoices: false }), 0);
|
|
17
|
-
note.addModifier(new Annotation(stroke.finger + (stroke.golpe ? ' + golpe' : ''))
|
|
18
|
+
note.addModifier(new Annotation(stroke.finger + (stroke.golpe ? ' + golpe' : ''))
|
|
19
|
+
.setFont(Metrics.getFontInfo('Annotation.guitarStroke'))
|
|
20
|
+
.setVerticalJustification(Annotation.VerticalJustify.TOP), 0);
|
|
18
21
|
}
|
|
19
22
|
if (bend && isTabNote(note)) {
|
|
20
23
|
const index = note.getPositions().findIndex((p) => p.str === bend.string);
|
package/build/esm/src/metrics.js
CHANGED
|
@@ -3,8 +3,12 @@ export class Metrics {
|
|
|
3
3
|
static clear(key) {
|
|
4
4
|
TextMetricsCache.clear();
|
|
5
5
|
if (key) {
|
|
6
|
-
this.cacheFont.
|
|
7
|
-
|
|
6
|
+
for (const cache of [this.cacheFont, this.cacheStyle]) {
|
|
7
|
+
for (const category of cache.keys()) {
|
|
8
|
+
if (category === key || category.startsWith(key + '.'))
|
|
9
|
+
cache.delete(category);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
8
12
|
}
|
|
9
13
|
else {
|
|
10
14
|
this.cacheFont.clear();
|
|
@@ -96,6 +100,12 @@ export const MetricsDefaults = {
|
|
|
96
100
|
Annotation: {
|
|
97
101
|
isText: true,
|
|
98
102
|
fontSize: 10,
|
|
103
|
+
guitarStroke: {
|
|
104
|
+
fontSize: 11,
|
|
105
|
+
},
|
|
106
|
+
lyric: {
|
|
107
|
+
fontSize: 12,
|
|
108
|
+
},
|
|
99
109
|
},
|
|
100
110
|
Bend: {
|
|
101
111
|
isText: true,
|
|
@@ -107,12 +117,16 @@ export const MetricsDefaults = {
|
|
|
107
117
|
},
|
|
108
118
|
ChordSymbol: {
|
|
109
119
|
isText: true,
|
|
110
|
-
fontSize:
|
|
120
|
+
fontSize: 14,
|
|
111
121
|
spacing: 0.05,
|
|
112
122
|
subscriptOffset: 0.2,
|
|
113
123
|
superscriptOffset: -0.4,
|
|
114
124
|
superSubRatio: 0.6,
|
|
115
125
|
},
|
|
126
|
+
FretDiagram: {
|
|
127
|
+
isText: true,
|
|
128
|
+
fontSize: 9,
|
|
129
|
+
},
|
|
116
130
|
FretHandFinger: {
|
|
117
131
|
isText: true,
|
|
118
132
|
fontSize: 9,
|
|
@@ -214,7 +228,7 @@ export const MetricsDefaults = {
|
|
|
214
228
|
Stroke: {
|
|
215
229
|
text: {
|
|
216
230
|
isText: true,
|
|
217
|
-
fontSize:
|
|
231
|
+
fontSize: 11,
|
|
218
232
|
fontStyle: 'italic',
|
|
219
233
|
fontWeight: 'bold',
|
|
220
234
|
},
|
|
@@ -222,7 +236,7 @@ export const MetricsDefaults = {
|
|
|
222
236
|
TabNote: {
|
|
223
237
|
text: {
|
|
224
238
|
isText: true,
|
|
225
|
-
fontSize:
|
|
239
|
+
fontSize: 11,
|
|
226
240
|
},
|
|
227
241
|
},
|
|
228
242
|
TabSlide: {
|
|
@@ -239,6 +253,11 @@ export const MetricsDefaults = {
|
|
|
239
253
|
TabTie: {
|
|
240
254
|
isText: true,
|
|
241
255
|
fontSize: 10,
|
|
256
|
+
techniqueLetter: {
|
|
257
|
+
fontFamily: 'Arial, Helvetica, sans-serif',
|
|
258
|
+
fontSize: 11,
|
|
259
|
+
fontWeight: 'bold',
|
|
260
|
+
},
|
|
242
261
|
},
|
|
243
262
|
TextBracket: {
|
|
244
263
|
isText: true,
|
package/build/esm/src/note.js
CHANGED
|
@@ -132,6 +132,7 @@ export class Note extends Tickable {
|
|
|
132
132
|
this.keys = noteStruct.keys || [];
|
|
133
133
|
this.keyProps = [];
|
|
134
134
|
this.duration = parsedNoteStruct.duration;
|
|
135
|
+
this.writtenDots = parsedNoteStruct.dots;
|
|
135
136
|
this.noteType = parsedNoteStruct.type;
|
|
136
137
|
this.customTypes = parsedNoteStruct.customTypes;
|
|
137
138
|
if (noteStruct.durationOverride) {
|