vexflow 5.2.0 → 5.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/build/cjs/vexflow-bravura.js +2 -2
- package/build/cjs/vexflow-bravura.js.map +1 -1
- package/build/cjs/vexflow-core.js +2 -2
- package/build/cjs/vexflow-core.js.map +1 -1
- package/build/cjs/vexflow-debug-with-tests.js +6502 -1708
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +5622 -1618
- package/build/cjs/vexflow-debug.js.map +1 -1
- package/build/cjs/vexflow.js +2 -2
- package/build/cjs/vexflow.js.map +1 -1
- package/build/esm/src/accidental.js +10 -3
- package/build/esm/src/alternatingtremolo.js +68 -0
- package/build/esm/src/annotation.js +19 -3
- package/build/esm/src/articulation.js +28 -6
- package/build/esm/src/beam.js +171 -28
- package/build/esm/src/bend.js +79 -23
- package/build/esm/src/clef.js +3 -0
- package/build/esm/src/continuouslayout.js +681 -0
- package/build/esm/src/continuousspan.js +159 -0
- package/build/esm/src/curve.js +48 -55
- package/build/esm/src/dot.js +13 -4
- package/build/esm/src/easyscore/composition.js +52 -2
- package/build/esm/src/easyscore/policies.js +39 -8
- package/build/esm/src/element.js +4 -0
- package/build/esm/src/engravinggeometry.js +157 -0
- package/build/esm/src/engravingprofile.js +44 -0
- package/build/esm/src/factory.js +31 -11
- package/build/esm/src/font.js +9 -1
- package/build/esm/src/formatter.js +9 -1
- package/build/esm/src/fretdiagram.js +77 -0
- package/build/esm/src/gracenote.js +43 -38
- package/build/esm/src/gracenotegroup.js +53 -56
- package/build/esm/src/guitargesture.js +33 -0
- package/build/esm/src/guitarmodifiers.js +26 -0
- package/build/esm/src/index.js +10 -0
- package/build/esm/src/instrumentprofile.js +123 -0
- package/build/esm/src/keysignature.js +24 -2
- package/build/esm/src/modifiercontext.js +11 -0
- package/build/esm/src/notationspelling.js +73 -0
- package/build/esm/src/note.js +3 -0
- package/build/esm/src/notehead.js +11 -6
- package/build/esm/src/ornament.js +43 -18
- package/build/esm/src/pagebreaks.js +58 -0
- package/build/esm/src/pedalmarking.js +39 -17
- package/build/esm/src/phraselayout.js +503 -0
- package/build/esm/src/phraseribbon.js +28 -0
- package/build/esm/src/proportionalformatter.js +54 -6
- package/build/esm/src/publication.js +402 -0
- package/build/esm/src/publicationview.js +114 -0
- package/build/esm/src/scorenavigation.js +172 -0
- package/build/esm/src/sheet.js +14 -2
- package/build/esm/src/stave.js +33 -16
- package/build/esm/src/stavebarline.js +5 -7
- package/build/esm/src/staveconnector.js +1 -0
- package/build/esm/src/stavehairpin.js +53 -27
- package/build/esm/src/stavenote.js +134 -116
- package/build/esm/src/stavetie.js +66 -9
- package/build/esm/src/stem.js +26 -11
- package/build/esm/src/strokes.js +4 -0
- package/build/esm/src/system.js +19 -4
- package/build/esm/src/systembreaks.js +42 -0
- package/build/esm/src/tabnote.js +6 -1
- package/build/esm/src/textbracket.js +24 -5
- package/build/esm/src/tickcontext.js +19 -0
- package/build/esm/src/timesignature.js +20 -6
- package/build/esm/src/tuplet.js +58 -17
- package/build/esm/src/version.js +3 -3
- package/build/esm/src/vexflow.js +20 -0
- package/build/esm/src/voice.js +7 -3
- package/build/esm/tests/bend_tests.js +14 -1
- package/build/esm/tests/curve_tests.js +14 -4
- package/build/esm/tests/demo_repertoire_tests.js +27 -0
- package/build/esm/tests/demos/drums.js +54 -0
- package/build/esm/tests/demos/electric.js +63 -0
- package/build/esm/tests/demos/greensleeves.js +90 -0
- package/build/esm/tests/demos/joy.js +61 -0
- package/build/esm/tests/demos/kesh.js +80 -0
- package/build/esm/tests/demos/prelude.js +59 -0
- package/build/esm/tests/demos/quartertones.js +50 -0
- package/build/esm/tests/demos/saints.js +65 -0
- package/build/esm/tests/engraving/continuous-studies.mjs +140 -0
- package/build/esm/tests/engraving/instrument-studies.mjs +273 -0
- package/build/esm/tests/engraving/phrase-studies.mjs +63 -0
- package/build/esm/tests/engraving/publication-studies.mjs +87 -0
- package/build/esm/tests/engraving/score-layout.mjs +75 -0
- package/build/esm/tests/engraving/score-persistence.mjs +262 -0
- package/build/esm/tests/engraving/specialist-studies.mjs +347 -0
- package/build/esm/tests/engraving/studies.mjs +367 -0
- package/build/esm/tests/formatter_tests.js +10 -1
- package/build/esm/tests/index.js +1 -0
- package/build/esm/tests/node/audit-dependencies-tests.mjs +42 -0
- package/build/esm/tests/node/continuous-score-tests.mjs +282 -0
- package/build/esm/tests/node/easyscore-tests.mjs +71 -0
- package/build/esm/tests/node/engraving-layout-tests.mjs +449 -0
- package/build/esm/tests/node/instrument-profile-tests.mjs +224 -0
- package/build/esm/tests/node/local-engraving-tests.mjs +128 -0
- package/build/esm/tests/node/phrase-layout-tests.mjs +281 -0
- package/build/esm/tests/node/proportional-spacing-tests.mjs +64 -0
- package/build/esm/tests/node/publication-tests.mjs +219 -0
- package/build/esm/tests/node/rendering-tests.mjs +6 -2
- package/build/esm/tests/threevoice_tests.js +11 -1
- package/build/esm/tests/vexflow_test_helpers.js +19 -10
- package/build/esm/tools/audit-dependencies.mjs +61 -0
- package/build/esm/tools/easyscore-structure.mjs +1 -1
- package/build/esm/tools/explorer/catalog/entries.mjs +2 -1
- package/build/esm/tools/explorer/catalog/expression.mjs +14 -9
- package/build/esm/tools/explorer/catalog/guitar.mjs +238 -0
- package/build/esm/tools/explorer/catalog/layout.mjs +8 -6
- package/build/esm/tools/explorer/catalog/notes.mjs +16 -14
- package/build/esm/tools/explorer/catalog/staves.mjs +12 -6
- package/build/esm/tools/explorer/catalog/strings.mjs +10 -7
- package/build/esm/tools/score-fixtures.mjs +23 -6
- package/build/types/src/accidental.d.ts +4 -0
- package/build/types/src/alternatingtremolo.d.ts +13 -0
- package/build/types/src/annotation.d.ts +9 -0
- package/build/types/src/articulation.d.ts +9 -1
- package/build/types/src/beam.d.ts +16 -0
- package/build/types/src/bend.d.ts +8 -0
- package/build/types/src/clef.d.ts +3 -0
- package/build/types/src/continuouslayout.d.ts +103 -0
- package/build/types/src/continuousspan.d.ts +60 -0
- package/build/types/src/curve.d.ts +20 -0
- package/build/types/src/dot.d.ts +5 -0
- package/build/types/src/easyscore/composition.d.ts +27 -0
- package/build/types/src/easyscore/policies.d.ts +1 -1
- package/build/types/src/element.d.ts +2 -0
- package/build/types/src/engravinggeometry.d.ts +31 -0
- package/build/types/src/engravingprofile.d.ts +20 -0
- package/build/types/src/factory.d.ts +6 -1
- package/build/types/src/formatter.d.ts +3 -3
- package/build/types/src/fretdiagram.d.ts +23 -0
- package/build/types/src/gracenote.d.ts +7 -0
- package/build/types/src/gracenotegroup.d.ts +7 -2
- package/build/types/src/guitargesture.d.ts +26 -0
- package/build/types/src/guitarmodifiers.d.ts +3 -0
- package/build/types/src/index.d.ts +12 -0
- package/build/types/src/instrumentprofile.d.ts +124 -0
- package/build/types/src/keysignature.d.ts +9 -0
- package/build/types/src/modifiercontext.d.ts +4 -0
- package/build/types/src/notationspelling.d.ts +25 -0
- package/build/types/src/note.d.ts +15 -0
- package/build/types/src/notehead.d.ts +5 -0
- package/build/types/src/ornament.d.ts +10 -1
- package/build/types/src/pagebreaks.d.ts +26 -0
- package/build/types/src/pedalmarking.d.ts +9 -0
- package/build/types/src/phraselayout.d.ts +87 -0
- package/build/types/src/phraseribbon.d.ts +7 -0
- package/build/types/src/proportionalformatter.d.ts +11 -2
- package/build/types/src/publication.d.ts +61 -0
- package/build/types/src/publicationview.d.ts +27 -0
- package/build/types/src/scorenavigation.d.ts +33 -0
- package/build/types/src/sheet.d.ts +5 -0
- package/build/types/src/stave.d.ts +13 -0
- package/build/types/src/stavehairpin.d.ts +18 -0
- package/build/types/src/stavenote.d.ts +20 -2
- package/build/types/src/stavetie.d.ts +9 -0
- package/build/types/src/stem.d.ts +10 -1
- package/build/types/src/system.d.ts +8 -1
- package/build/types/src/systembreaks.d.ts +9 -0
- package/build/types/src/textbracket.d.ts +7 -0
- package/build/types/src/tickcontext.d.ts +5 -0
- package/build/types/src/timesignature.d.ts +6 -0
- package/build/types/src/tuplet.d.ts +5 -48
- package/build/types/src/vexflow.d.ts +20 -0
- package/build/types/src/voice.d.ts +2 -0
- package/changelog/CHANGELOG.md +25 -0
- package/package.json +15 -3
- package/tests/all.html +277 -0
- package/tests/demo_petzold_tests.ts +435 -0
- package/tests/demos/drums.ts +55 -0
- package/tests/demos/drums.webp +0 -0
- package/tests/demos/electric.ts +70 -0
- package/tests/demos/electric.webp +0 -0
- package/tests/demos/greensleeves.ts +97 -0
- package/tests/demos/greensleeves.webp +0 -0
- package/tests/demos/joy.ts +65 -0
- package/tests/demos/joy.webp +0 -0
- package/tests/demos/kesh.ts +86 -0
- package/tests/demos/kesh.webp +0 -0
- package/tests/demos/prelude.ts +65 -0
- package/tests/demos/prelude.webp +0 -0
- package/tests/demos/quartertones.ts +51 -0
- package/tests/demos/quartertones.webp +0 -0
- package/tests/demos/saints.ts +70 -0
- package/tests/demos/saints.webp +0 -0
- package/tests/flow.html +550 -239
- package/tests/fonts.css +493 -0
- package/tests/minuet.webp +0 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { Accidental } from './accidental.js';
|
|
2
|
+
import { Annotation } from './annotation.js';
|
|
3
|
+
import { Articulation } from './articulation.js';
|
|
4
|
+
import { Beam } from './beam.js';
|
|
5
|
+
import { BoundingBox } from './boundingbox.js';
|
|
6
|
+
import { Curve } from './curve.js';
|
|
7
|
+
import { Dot } from './dot.js';
|
|
8
|
+
import { GraceNote } from './gracenote.js';
|
|
9
|
+
import { GraceNoteGroup } from './gracenotegroup.js';
|
|
10
|
+
import { Ornament } from './ornament.js';
|
|
11
|
+
import { PedalMarking } from './pedalmarking.js';
|
|
12
|
+
import { StaveHairpin } from './stavehairpin.js';
|
|
13
|
+
import { StaveNote } from './stavenote.js';
|
|
14
|
+
import { StaveTie } from './stavetie.js';
|
|
15
|
+
import { Stem } from './stem.js';
|
|
16
|
+
import { TextBracket } from './textbracket.js';
|
|
17
|
+
import { Tuplet } from './tuplet.js';
|
|
18
|
+
import { RuntimeError } from './util.js';
|
|
19
|
+
function inflate(box, amount) {
|
|
20
|
+
return new BoundingBox(box.x - amount, box.y - amount, box.w + 2 * amount, box.h + 2 * amount);
|
|
21
|
+
}
|
|
22
|
+
function rectangle(x1, y1, x2, y2) {
|
|
23
|
+
return new BoundingBox(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x2 - x1), Math.abs(y2 - y1));
|
|
24
|
+
}
|
|
25
|
+
function noteShape(note) {
|
|
26
|
+
var _a, _b, _c;
|
|
27
|
+
if (note.renderOptions.draw === false)
|
|
28
|
+
return { parts: [], anchors: {} };
|
|
29
|
+
(_a = note.getBeam()) === null || _a === void 0 ? void 0 : _a.postFormat();
|
|
30
|
+
const parts = note.getHeadInk();
|
|
31
|
+
const anchors = {};
|
|
32
|
+
parts.forEach((box, i) => {
|
|
33
|
+
anchors[`head${i}`] = { x: box.x + box.w / 2, y: note.getYs()[i] };
|
|
34
|
+
});
|
|
35
|
+
const segment = note.getStemSegment();
|
|
36
|
+
if (segment) {
|
|
37
|
+
const { x, baseY, tipY } = segment;
|
|
38
|
+
parts.push(new BoundingBox(x - Stem.WIDTH / 2, Math.min(baseY, tipY), Stem.WIDTH, Math.abs(tipY - baseY)));
|
|
39
|
+
anchors.stemBase = { x, y: baseY };
|
|
40
|
+
anchors.stemTip = { x, y: tipY };
|
|
41
|
+
}
|
|
42
|
+
const flag = note.getFlagInk();
|
|
43
|
+
if (flag)
|
|
44
|
+
parts.push(flag);
|
|
45
|
+
const lineWidth = (_c = (_b = note.getLedgerLineStyle().lineWidth) !== null && _b !== void 0 ? _b : note.checkStave().getDefaultLedgerLineStyle().lineWidth) !== null && _c !== void 0 ? _c : 1;
|
|
46
|
+
for (const { x, y, width } of note.getLedgerLines())
|
|
47
|
+
parts.push(new BoundingBox(x, y - lineWidth / 2, width, lineWidth));
|
|
48
|
+
if (note instanceof GraceNote) {
|
|
49
|
+
const slash = note.getSlash();
|
|
50
|
+
if (slash)
|
|
51
|
+
parts.push(inflate(rectangle(slash.x1, slash.y1, slash.x2, slash.y2), note.getFontScale() / 2));
|
|
52
|
+
}
|
|
53
|
+
return { parts, anchors };
|
|
54
|
+
}
|
|
55
|
+
export function measureEngraving(element, options = {}) {
|
|
56
|
+
var _a;
|
|
57
|
+
const diagnostics = [];
|
|
58
|
+
const report = (owner, code) => {
|
|
59
|
+
diagnostics.push({
|
|
60
|
+
code,
|
|
61
|
+
phase: 'measure',
|
|
62
|
+
severity: code === 'LayoutOverflow' ? 'warning' : 'error',
|
|
63
|
+
sourceId: owner.getAttribute('id'),
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
function collect(owner) {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
const shape = { parts: [], anchors: {} };
|
|
69
|
+
const children = (elements) => {
|
|
70
|
+
for (const child of elements)
|
|
71
|
+
shape.parts.push(...collect(child).parts);
|
|
72
|
+
};
|
|
73
|
+
try {
|
|
74
|
+
const kind = Object.getPrototypeOf(owner).constructor;
|
|
75
|
+
const custom = (_a = options.extension) === null || _a === void 0 ? void 0 : _a.call(options, owner);
|
|
76
|
+
if (custom)
|
|
77
|
+
Object.assign(shape, custom);
|
|
78
|
+
else if (kind === StaveNote || kind === GraceNote) {
|
|
79
|
+
const note = owner;
|
|
80
|
+
Object.assign(shape, noteShape(note));
|
|
81
|
+
if (note.renderOptions.draw !== false)
|
|
82
|
+
children(note.getModifiers());
|
|
83
|
+
}
|
|
84
|
+
else if (kind === GraceNoteGroup)
|
|
85
|
+
children(owner.getLayoutElements());
|
|
86
|
+
else if (kind === Articulation) {
|
|
87
|
+
const box = owner.getInkBounds();
|
|
88
|
+
shape.parts.push(box);
|
|
89
|
+
shape.anchors.center = { x: box.x + box.w / 2, y: box.y + box.h / 2 };
|
|
90
|
+
}
|
|
91
|
+
else if (kind === Accidental || kind === Dot) {
|
|
92
|
+
shape.parts.push(owner.getInkBounds());
|
|
93
|
+
}
|
|
94
|
+
else if (kind === Tuplet ||
|
|
95
|
+
kind === Ornament ||
|
|
96
|
+
kind === PedalMarking ||
|
|
97
|
+
kind === StaveHairpin ||
|
|
98
|
+
kind === TextBracket) {
|
|
99
|
+
shape.parts.push(owner.getBoundingBox());
|
|
100
|
+
}
|
|
101
|
+
else if (kind === Beam) {
|
|
102
|
+
const beam = owner;
|
|
103
|
+
shape.parts.push(beam.getBoundingBox());
|
|
104
|
+
for (const [i, note] of beam.getNotes().entries())
|
|
105
|
+
shape.anchors[`stem${i}`] = { x: note.getStemX(), y: note.getStemExtents().topY };
|
|
106
|
+
}
|
|
107
|
+
else if (kind === Curve) {
|
|
108
|
+
const curve = owner;
|
|
109
|
+
shape.parts.push(inflate(curve.getBoundingBox(), ((_b = curve.getStyle().lineWidth) !== null && _b !== void 0 ? _b : 1) / 2));
|
|
110
|
+
shape.anchors = curve.getAnchors();
|
|
111
|
+
}
|
|
112
|
+
else if (kind === Annotation) {
|
|
113
|
+
const mark = owner;
|
|
114
|
+
const { x } = mark.computeX();
|
|
115
|
+
const { y } = mark.computeY();
|
|
116
|
+
shape.parts.push(mark.getTextInk(x, y));
|
|
117
|
+
shape.anchors.baseline = { x: x + mark.getXShift(), y: y + mark.getYShift() };
|
|
118
|
+
}
|
|
119
|
+
else if (kind === StaveTie && !owner.text)
|
|
120
|
+
shape.parts.push(owner.getRibbonBounds());
|
|
121
|
+
else
|
|
122
|
+
report(owner, 'UnsupportedGeometry');
|
|
123
|
+
const finiteBox = (b) => [b.x, b.y, b.w, b.h].every(Number.isFinite) && b.w >= 0 && b.h >= 0;
|
|
124
|
+
if (!shape.parts.every(finiteBox) ||
|
|
125
|
+
!Object.values(shape.anchors).every((p) => Number.isFinite(p.x) && Number.isFinite(p.y))) {
|
|
126
|
+
report(owner, 'InvalidGeometry');
|
|
127
|
+
return { parts: [], anchors: {} };
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
if (!(error instanceof RuntimeError))
|
|
132
|
+
throw error;
|
|
133
|
+
report(owner, 'UnformattedGeometry');
|
|
134
|
+
}
|
|
135
|
+
return shape;
|
|
136
|
+
}
|
|
137
|
+
const shape = collect(element);
|
|
138
|
+
const padding = (_a = options.paddingPx) !== null && _a !== void 0 ? _a : 0;
|
|
139
|
+
if (!Number.isFinite(padding) || padding < 0)
|
|
140
|
+
throw new RangeError('Expected finite nonnegative layout padding.');
|
|
141
|
+
let ink;
|
|
142
|
+
for (const part of shape.parts) {
|
|
143
|
+
const box = new BoundingBox(part.x, part.y, part.w, part.h);
|
|
144
|
+
ink = ink ? ink.mergeWith(box) : box;
|
|
145
|
+
}
|
|
146
|
+
const layout = ink && inflate(ink, padding);
|
|
147
|
+
if (ink && element instanceof GraceNoteGroup) {
|
|
148
|
+
shape.anchors.left = { x: ink.x, y: element.checkAttachedNote().getYs()[element.checkIndex()] };
|
|
149
|
+
shape.anchors.right = { x: ink.x + ink.w, y: shape.anchors.left.y };
|
|
150
|
+
}
|
|
151
|
+
const v = options.viewport;
|
|
152
|
+
if (v &&
|
|
153
|
+
layout &&
|
|
154
|
+
(layout.x < v.x || layout.y < v.y || layout.x + layout.w > v.x + v.w || layout.y + layout.h > v.y + v.h))
|
|
155
|
+
report(element, 'LayoutOverflow');
|
|
156
|
+
return Object.assign(Object.assign({}, shape), { ink, layout, diagnostics });
|
|
157
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Glyphs } from './glyphs.js';
|
|
2
|
+
function record(value) {
|
|
3
|
+
return value !== null && typeof value === 'object' ? value : {};
|
|
4
|
+
}
|
|
5
|
+
function distance(value, fallback, allowZero = false) {
|
|
6
|
+
return typeof value === 'number' && Number.isFinite(value) && (allowZero ? value >= 0 : value > 0) && value <= 16
|
|
7
|
+
? value
|
|
8
|
+
: fallback;
|
|
9
|
+
}
|
|
10
|
+
function readAnchor(value) {
|
|
11
|
+
if (!Array.isArray(value) || value.length !== 2 || !value.every((v) => Number.isFinite(v) && Math.abs(v) <= 16))
|
|
12
|
+
return;
|
|
13
|
+
return Object.freeze([value[0], value[1]]);
|
|
14
|
+
}
|
|
15
|
+
export class EngravingProfile {
|
|
16
|
+
constructor(options) {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
if (!options.musicFont.trim())
|
|
19
|
+
throw new RangeError('Expected a music font family.');
|
|
20
|
+
this.musicFont = options.musicFont;
|
|
21
|
+
const supplied = record(options.metadata);
|
|
22
|
+
const metadata = supplied.fontName === this.musicFont ? supplied : {};
|
|
23
|
+
this.beamThickness = (_a = options.beamThickness) !== null && _a !== void 0 ? _a : distance(record(metadata.engravingDefaults).beamThickness, 0.5);
|
|
24
|
+
this.clearance = (_b = options.clearance) !== null && _b !== void 0 ? _b : 0.25;
|
|
25
|
+
if (!Number.isFinite(distance(this.beamThickness, NaN)) || !Number.isFinite(distance(this.clearance, NaN, true)))
|
|
26
|
+
throw new RangeError('Invalid engraving distance in staff spaces.');
|
|
27
|
+
const anchors = {};
|
|
28
|
+
for (const [name, fields] of Object.entries(record(metadata.glyphsWithAnchors))) {
|
|
29
|
+
if (!Object.prototype.hasOwnProperty.call(Glyphs, name))
|
|
30
|
+
continue;
|
|
31
|
+
const glyph = Glyphs[name];
|
|
32
|
+
anchors[glyph] = Object.freeze({
|
|
33
|
+
up: readAnchor(record(fields).stemUpSE),
|
|
34
|
+
down: readAnchor(record(fields).stemDownNW),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
this.anchors = Object.freeze(anchors);
|
|
38
|
+
Object.freeze(this);
|
|
39
|
+
}
|
|
40
|
+
stemAnchor(glyph, direction) {
|
|
41
|
+
var _a;
|
|
42
|
+
return (_a = this.anchors[glyph]) === null || _a === void 0 ? void 0 : _a[direction];
|
|
43
|
+
}
|
|
44
|
+
}
|
package/build/esm/src/factory.js
CHANGED
|
@@ -244,14 +244,22 @@ export class Factory {
|
|
|
244
244
|
Bend(...args) {
|
|
245
245
|
return this.adopt(new Bend(...args).setContext(this.context), 'modifier');
|
|
246
246
|
}
|
|
247
|
+
musicGlyph(element) {
|
|
248
|
+
if (this.options.engraving)
|
|
249
|
+
element.setFont(Object.assign(Object.assign({}, element.fontInfo), { family: this.options.engraving.musicFont }));
|
|
250
|
+
return element;
|
|
251
|
+
}
|
|
247
252
|
Clef(...args) {
|
|
248
|
-
return this.adopt(new Clef(...args).setContext(this.context), 'staveModifier');
|
|
253
|
+
return this.adopt(this.musicGlyph(new Clef(...args)).setContext(this.context), 'staveModifier');
|
|
249
254
|
}
|
|
250
255
|
KeySignature(...args) {
|
|
251
|
-
return this.adopt(new KeySignature(...args).setContext(this.context), 'staveModifier');
|
|
256
|
+
return this.adopt(this.musicGlyph(new KeySignature(...args)).setContext(this.context), 'staveModifier');
|
|
252
257
|
}
|
|
253
258
|
TimeSignature(...args) {
|
|
254
|
-
|
|
259
|
+
const signature = new TimeSignature(...args);
|
|
260
|
+
if (this.options.engraving)
|
|
261
|
+
signature.setMusicFont(this.options.engraving.musicFont);
|
|
262
|
+
return this.adopt(signature.setContext(this.context), 'staveModifier');
|
|
255
263
|
}
|
|
256
264
|
Barline(...args) {
|
|
257
265
|
return this.adopt(new Barline(...args).setContext(this.context), 'staveModifier');
|
|
@@ -281,7 +289,7 @@ export class Factory {
|
|
|
281
289
|
return this.own(new GraceTabNote(options).setContext(this.context));
|
|
282
290
|
}
|
|
283
291
|
StaveNote(noteStruct) {
|
|
284
|
-
const note = new StaveNote(noteStruct);
|
|
292
|
+
const note = new StaveNote(Object.assign({ engraving: this.options.engraving }, noteStruct));
|
|
285
293
|
if (this.stave)
|
|
286
294
|
note.setStave(this.stave);
|
|
287
295
|
note.setContext(this.context);
|
|
@@ -363,7 +371,7 @@ export class Factory {
|
|
|
363
371
|
return this.own(note);
|
|
364
372
|
}
|
|
365
373
|
GraceNote(noteStruct) {
|
|
366
|
-
const note = new GraceNote(noteStruct);
|
|
374
|
+
const note = new GraceNote(Object.assign({ engraving: this.options.engraving }, noteStruct));
|
|
367
375
|
if (this.stave)
|
|
368
376
|
note.setStave(this.stave);
|
|
369
377
|
note.setContext(this.context);
|
|
@@ -373,7 +381,7 @@ export class Factory {
|
|
|
373
381
|
return this.own(new GraceNoteGroup(params.notes, params.slur).setContext(this.context));
|
|
374
382
|
}
|
|
375
383
|
Accidental(params) {
|
|
376
|
-
const accid = new Accidental(params.type);
|
|
384
|
+
const accid = this.musicGlyph(new Accidental(params.type));
|
|
377
385
|
accid.setContext(this.context);
|
|
378
386
|
return this.own(accid);
|
|
379
387
|
}
|
|
@@ -405,7 +413,7 @@ export class Factory {
|
|
|
405
413
|
}
|
|
406
414
|
Articulation(params) {
|
|
407
415
|
var _a;
|
|
408
|
-
const articulation = new Articulation((_a = params === null || params === void 0 ? void 0 : params.type) !== null && _a !== void 0 ? _a : 'a.');
|
|
416
|
+
const articulation = this.musicGlyph(new Articulation((_a = params === null || params === void 0 ? void 0 : params.type) !== null && _a !== void 0 ? _a : 'a.'));
|
|
409
417
|
if ((params === null || params === void 0 ? void 0 : params.position) !== undefined)
|
|
410
418
|
articulation.setPosition(params.position);
|
|
411
419
|
if ((params === null || params === void 0 ? void 0 : params.betweenLines) !== undefined)
|
|
@@ -674,13 +682,25 @@ export class Factory {
|
|
|
674
682
|
if (this.retained)
|
|
675
683
|
this.renderQ.forEach((element) => element.setRendered(false));
|
|
676
684
|
try {
|
|
677
|
-
this.
|
|
678
|
-
|
|
685
|
+
const layouts = this.sheets.flatMap((sheet) => { var _a; return (_a = sheet.getContinuousLayout()) !== null && _a !== void 0 ? _a : []; });
|
|
686
|
+
const hidden = new Set(layouts.flatMap((layout) => [...layout.hidden]));
|
|
687
|
+
this.staves.forEach((s) => {
|
|
688
|
+
if (!hidden.has(s))
|
|
689
|
+
s.setContext(ctx).drawWithStyle();
|
|
690
|
+
});
|
|
691
|
+
this.voices.forEach((v) => {
|
|
692
|
+
if (!hidden.has(v))
|
|
693
|
+
v.setContext(ctx).drawWithStyle();
|
|
694
|
+
});
|
|
679
695
|
this.renderQ.forEach((e) => {
|
|
680
|
-
if (!e.isRendered())
|
|
696
|
+
if (!hidden.has(e) && !e.isRendered())
|
|
681
697
|
e.setContext(ctx).drawWithStyle();
|
|
682
698
|
});
|
|
683
|
-
this.systems.forEach((s) =>
|
|
699
|
+
this.systems.forEach((s) => {
|
|
700
|
+
if (!hidden.has(s))
|
|
701
|
+
s.setContext(ctx).drawWithStyle();
|
|
702
|
+
});
|
|
703
|
+
layouts.forEach((layout) => layout.draw(ctx));
|
|
684
704
|
}
|
|
685
705
|
finally {
|
|
686
706
|
ctx.setDefaultStyle(defaults);
|
package/build/esm/src/font.js
CHANGED
|
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { Metrics } from './metrics.js';
|
|
11
11
|
import { TextMetricsCache } from './textmetricscache.js';
|
|
12
|
+
import { RuntimeError } from './util.js';
|
|
12
13
|
export var FontWeight;
|
|
13
14
|
(function (FontWeight) {
|
|
14
15
|
FontWeight["NORMAL"] = "normal";
|
|
@@ -187,7 +188,14 @@ export class Font {
|
|
|
187
188
|
}
|
|
188
189
|
fontFaceSet === null || fontFaceSet === void 0 ? void 0 : fontFaceSet.add(fontFace);
|
|
189
190
|
TextMetricsCache.clear();
|
|
190
|
-
return fontFaceLoadPromise
|
|
191
|
+
return fontFaceLoadPromise
|
|
192
|
+
.catch((cause) => {
|
|
193
|
+
throw new RuntimeError('FontLoadFailed', 'Could not load font "' +
|
|
194
|
+
fontName +
|
|
195
|
+
'". Check the font file, network response and CORS policy. ' +
|
|
196
|
+
String(cause));
|
|
197
|
+
})
|
|
198
|
+
.finally(() => TextMetricsCache.clear());
|
|
191
199
|
});
|
|
192
200
|
}
|
|
193
201
|
static getURLForFont(fontName) {
|
|
@@ -140,7 +140,7 @@ export class Formatter {
|
|
|
140
140
|
}
|
|
141
141
|
constructor(options) {
|
|
142
142
|
this.formatterOptions = Object.assign({ globalSoftmax: false, softmaxFactor: Tables.SOFTMAX_FACTOR, maxIterations: 5 }, options);
|
|
143
|
-
if ((options === null || options === void 0 ? void 0 : options.spacing) && options.spacing.mode
|
|
143
|
+
if ((options === null || options === void 0 ? void 0 : options.spacing) && !['proportional', 'optical'].includes(options.spacing.mode)) {
|
|
144
144
|
throw new RuntimeError('BadArgument', 'Unknown formatter spacing mode.');
|
|
145
145
|
}
|
|
146
146
|
this.justifyWidth = 0;
|
|
@@ -310,6 +310,7 @@ export class Formatter {
|
|
|
310
310
|
list: tickList.sort((a, b) => a - b),
|
|
311
311
|
resolutionMultiplier,
|
|
312
312
|
};
|
|
313
|
+
TickContext.linkTimeline(contexts.list.map((tick) => contexts.map[tick]));
|
|
313
314
|
this.tickContexts = contexts;
|
|
314
315
|
const contextArray = this.tickContexts.array;
|
|
315
316
|
contextArray.forEach((context) => {
|
|
@@ -611,8 +612,15 @@ export class Formatter {
|
|
|
611
612
|
return this;
|
|
612
613
|
}
|
|
613
614
|
format(voices, justifyWidth, options) {
|
|
615
|
+
var _a;
|
|
614
616
|
const opts = Object.assign({ alignRests: false }, options);
|
|
615
617
|
this.voices = voices;
|
|
618
|
+
for (const voice of voices) {
|
|
619
|
+
for (const tickable of voice.getTickables()) {
|
|
620
|
+
if (isNote(tickable))
|
|
621
|
+
(_a = tickable.getBeam()) === null || _a === void 0 ? void 0 : _a.resetLayout();
|
|
622
|
+
}
|
|
623
|
+
}
|
|
616
624
|
const softmaxFactor = this.formatterOptions.softmaxFactor;
|
|
617
625
|
if (softmaxFactor) {
|
|
618
626
|
this.voices.forEach((v) => v.setSoftmaxFactor(softmaxFactor));
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { BoundingBox } from './boundingbox.js';
|
|
2
|
+
import { Element } from './element.js';
|
|
3
|
+
import { RuntimeError } from './util.js';
|
|
4
|
+
export class FretDiagram extends Element {
|
|
5
|
+
constructor(spec) {
|
|
6
|
+
var _a, _b;
|
|
7
|
+
super();
|
|
8
|
+
this.frets = [...spec.frets];
|
|
9
|
+
this.first = (_a = spec.firstFret) !== null && _a !== void 0 ? _a : 1;
|
|
10
|
+
this.rows = (_b = spec.rows) !== null && _b !== void 0 ? _b : 4;
|
|
11
|
+
this.barre = spec.barre && Object.assign({}, spec.barre);
|
|
12
|
+
const visible = (n) => Number.isSafeInteger(n) && n >= this.first && n < this.first + this.rows;
|
|
13
|
+
if (this.frets.length < 2 ||
|
|
14
|
+
!Number.isSafeInteger(this.first) ||
|
|
15
|
+
this.first < 1 ||
|
|
16
|
+
!Number.isSafeInteger(this.rows) ||
|
|
17
|
+
this.rows < 1 ||
|
|
18
|
+
this.frets.some((n) => n !== 'x' && n !== 0 && !visible(n)))
|
|
19
|
+
throw new RuntimeError('BadArguments', 'Invalid chord frame or fret outside the displayed range.');
|
|
20
|
+
if (this.barre) {
|
|
21
|
+
const { from, to, fret } = this.barre;
|
|
22
|
+
if (![from, to].every((n) => Number.isSafeInteger(n) && n >= 1 && n <= this.frets.length) ||
|
|
23
|
+
from === to ||
|
|
24
|
+
!visible(fret))
|
|
25
|
+
throw new RuntimeError('BadArguments', 'Barre outside chord frame.');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
getBoundingBox() {
|
|
29
|
+
return new BoundingBox(this.getX(), this.getY(), 28 + (this.frets.length - 1) * 9, 17 + this.rows * 11);
|
|
30
|
+
}
|
|
31
|
+
draw() {
|
|
32
|
+
const ctx = this.checkContext();
|
|
33
|
+
const left = this.getX() + 22, top = this.getY() + 14;
|
|
34
|
+
const right = left + (this.frets.length - 1) * 9;
|
|
35
|
+
const fretY = (fret) => top + (fret - this.first + 0.5) * 11;
|
|
36
|
+
const line = (x1, y1, x2, y2) => {
|
|
37
|
+
ctx.beginPath();
|
|
38
|
+
ctx.moveTo(x1, y1);
|
|
39
|
+
ctx.lineTo(x2, y2);
|
|
40
|
+
ctx.stroke();
|
|
41
|
+
};
|
|
42
|
+
ctx.save();
|
|
43
|
+
const group = ctx.openGroup('fret-diagram', this.getAttribute('id'));
|
|
44
|
+
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
|
+
ctx.setFont('sans-serif', 9);
|
|
46
|
+
if (this.first > 1)
|
|
47
|
+
ctx.fillText(String(this.first), this.getX() + 2, top + 9);
|
|
48
|
+
for (let row = 0; row <= this.rows; row++) {
|
|
49
|
+
ctx.setLineWidth(row === 0 && this.first === 1 ? 2.5 : 1);
|
|
50
|
+
line(left, top + row * 11, right, top + row * 11);
|
|
51
|
+
}
|
|
52
|
+
this.frets.forEach((fret, i) => {
|
|
53
|
+
const x = left + i * 9;
|
|
54
|
+
line(x, top, x, top + this.rows * 11);
|
|
55
|
+
if (fret === 'x') {
|
|
56
|
+
line(x - 2.5, top - 8, x + 2.5, top - 3);
|
|
57
|
+
line(x + 2.5, top - 8, x - 2.5, top - 3);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
ctx.beginPath();
|
|
61
|
+
ctx.arc(x, fret ? fretY(fret) : top - 5.5, fret ? 3 : 2.5, 0, 2 * Math.PI, false);
|
|
62
|
+
if (fret)
|
|
63
|
+
ctx.fill();
|
|
64
|
+
else
|
|
65
|
+
ctx.stroke();
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
if (this.barre) {
|
|
69
|
+
const { from, to, fret } = this.barre;
|
|
70
|
+
ctx.setLineWidth(5);
|
|
71
|
+
line(right - (from - 1) * 9, fretY(fret), right - (to - 1) * 9, fretY(fret));
|
|
72
|
+
}
|
|
73
|
+
ctx.closeGroup();
|
|
74
|
+
ctx.restore();
|
|
75
|
+
this.setRendered();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -24,47 +24,52 @@ export class GraceNote extends StaveNote {
|
|
|
24
24
|
ret = Stem.HEIGHT * this.getFontScale() - Stem.HEIGHT + ret;
|
|
25
25
|
return ret;
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
27
|
+
getSlash() {
|
|
28
|
+
if (!this.slash || !this.stem)
|
|
29
|
+
return;
|
|
30
|
+
const scale = this.getFontScale();
|
|
31
|
+
let slashBBox = undefined;
|
|
32
|
+
const beam = this.beam;
|
|
33
|
+
if (beam) {
|
|
34
|
+
if (!beam.postFormatted) {
|
|
35
|
+
beam.postFormat();
|
|
36
|
+
}
|
|
37
|
+
slashBBox = this.calcBeamedNotesSlashBBox(8 * scale, 8 * scale, {
|
|
38
|
+
stem: 6 * scale,
|
|
39
|
+
beam: 5 * scale,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
const stemDirection = this.getStemDirection();
|
|
44
|
+
const noteHeadBounds = this.getNoteHeadBounds();
|
|
45
|
+
const noteHeadWidth = this.noteHeads[0].getWidth();
|
|
46
|
+
const x = stemDirection === Stem.DOWN ? this.getAbsoluteX() : this.getAbsoluteX() + noteHeadWidth;
|
|
47
|
+
const defaultOffsetY = (Tables.STEM_HEIGHT * scale) / 2;
|
|
48
|
+
const y = stemDirection === Stem.DOWN ? noteHeadBounds.yBottom + defaultOffsetY : noteHeadBounds.yTop - defaultOffsetY;
|
|
49
|
+
if (stemDirection === Stem.DOWN) {
|
|
50
|
+
slashBBox = {
|
|
51
|
+
x1: x - noteHeadWidth,
|
|
52
|
+
y1: y - noteHeadWidth,
|
|
53
|
+
x2: x + noteHeadWidth,
|
|
54
|
+
y2: y + noteHeadWidth,
|
|
55
|
+
};
|
|
43
56
|
}
|
|
44
57
|
else {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (stemDirection === Stem.DOWN) {
|
|
52
|
-
slashBBox = {
|
|
53
|
-
x1: x - noteHeadWidth,
|
|
54
|
-
y1: y - noteHeadWidth,
|
|
55
|
-
x2: x + noteHeadWidth,
|
|
56
|
-
y2: y + noteHeadWidth,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
slashBBox = {
|
|
61
|
-
x1: x - noteHeadWidth,
|
|
62
|
-
y1: y + noteHeadWidth,
|
|
63
|
-
x2: x + noteHeadWidth,
|
|
64
|
-
y2: y - noteHeadWidth,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
58
|
+
slashBBox = {
|
|
59
|
+
x1: x - noteHeadWidth,
|
|
60
|
+
y1: y + noteHeadWidth,
|
|
61
|
+
x2: x + noteHeadWidth,
|
|
62
|
+
y2: y - noteHeadWidth,
|
|
63
|
+
};
|
|
67
64
|
}
|
|
65
|
+
}
|
|
66
|
+
return { x1: slashBBox.x1, y1: slashBBox.y1, x2: slashBBox.x2, y2: slashBBox.y2 };
|
|
67
|
+
}
|
|
68
|
+
draw() {
|
|
69
|
+
super.draw();
|
|
70
|
+
const slashBBox = this.getSlash();
|
|
71
|
+
if (slashBBox) {
|
|
72
|
+
const scale = this.getFontScale();
|
|
68
73
|
const ctx = this.checkContext();
|
|
69
74
|
ctx.setLineWidth(1 * scale);
|
|
70
75
|
ctx.beginPath();
|
|
@@ -16,55 +16,32 @@ export class GraceNoteGroup extends Modifier {
|
|
|
16
16
|
static get CATEGORY() {
|
|
17
17
|
return "GraceNoteGroup";
|
|
18
18
|
}
|
|
19
|
-
static format(
|
|
20
|
-
|
|
21
|
-
const groupSpacingTab = 0;
|
|
22
|
-
if (!gracenoteGroups || gracenoteGroups.length === 0)
|
|
19
|
+
static format(groups, state) {
|
|
20
|
+
if (!(groups === null || groups === void 0 ? void 0 : groups.length))
|
|
23
21
|
return false;
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
groupList.push({ shift: shift, gracenoteGroup, spacing });
|
|
39
|
-
}
|
|
40
|
-
let groupShift = groupList[0].shift;
|
|
41
|
-
let formatWidth;
|
|
42
|
-
let right = false;
|
|
43
|
-
let left = false;
|
|
44
|
-
for (let i = 0; i < groupList.length; ++i) {
|
|
45
|
-
const gracenoteGroup = groupList[i].gracenoteGroup;
|
|
46
|
-
if (gracenoteGroup.position === Modifier.Position.RIGHT)
|
|
47
|
-
right = true;
|
|
48
|
-
else
|
|
49
|
-
left = true;
|
|
50
|
-
gracenoteGroup.preFormat();
|
|
51
|
-
formatWidth = gracenoteGroup.getWidth() + groupList[i].spacing;
|
|
52
|
-
groupShift = Math.max(formatWidth, groupShift);
|
|
53
|
-
}
|
|
54
|
-
for (let i = 0; i < groupList.length; ++i) {
|
|
55
|
-
const gracenoteGroup = groupList[i].gracenoteGroup;
|
|
56
|
-
formatWidth = gracenoteGroup.getWidth() + groupList[i].spacing;
|
|
57
|
-
gracenoteGroup.setSpacingFromNextModifier(groupShift - Math.min(formatWidth, groupShift) + StaveNote.minNoteheadPadding);
|
|
22
|
+
const entries = groups.map((group) => {
|
|
23
|
+
group.preFormat();
|
|
24
|
+
const note = group.getNote();
|
|
25
|
+
const width = group.getWidth() + (isStaveNote(note) ? 4 : 0);
|
|
26
|
+
return { group, note, width, after: group.position === Modifier.Position.RIGHT };
|
|
27
|
+
});
|
|
28
|
+
const afterWidth = Math.max(0, ...entries.filter((e) => e.after).map((e) => e.width));
|
|
29
|
+
const beforeWidth = Math.max(0, ...entries.filter((e) => !e.after).map((e) => Math.max(e.width, e.note.getLeftDisplacedHeadPx())));
|
|
30
|
+
for (const { group, width, after, note } of entries) {
|
|
31
|
+
group.afterWidth = afterWidth;
|
|
32
|
+
group.afterOffset =
|
|
33
|
+
note.getGlyphWidth() + note.getRightDisplacedHeadPx() + state.rightShift + StaveNote.minNoteheadPadding;
|
|
34
|
+
group.setSpacingFromNextModifier((after ? 0 : beforeWidth - width) + StaveNote.minNoteheadPadding);
|
|
58
35
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (left)
|
|
62
|
-
state.leftShift += groupShift;
|
|
36
|
+
state.leftShift += beforeWidth;
|
|
37
|
+
state.rightShift += afterWidth;
|
|
63
38
|
return true;
|
|
64
39
|
}
|
|
65
40
|
constructor(graceNotes, showSlur) {
|
|
66
41
|
super();
|
|
67
42
|
this.preFormatted = false;
|
|
43
|
+
this.afterWidth = 0;
|
|
44
|
+
this.afterOffset = 0;
|
|
68
45
|
this.position = Modifier.Position.LEFT;
|
|
69
46
|
this.graceNotes = graceNotes;
|
|
70
47
|
this.width = 0;
|
|
@@ -117,6 +94,14 @@ export class GraceNoteGroup extends Modifier {
|
|
|
117
94
|
note.checkStave();
|
|
118
95
|
this.preFormat();
|
|
119
96
|
this.alignSubNotesWithNote(this.getGraceNotes(), note, this.position);
|
|
97
|
+
if (this.afterWidth) {
|
|
98
|
+
for (const grace of this.graceNotes) {
|
|
99
|
+
const tick = grace.getTickContext();
|
|
100
|
+
tick.setXOffset(this.position === Modifier.Position.RIGHT
|
|
101
|
+
? note.getTickContext().getX() + this.afterOffset
|
|
102
|
+
: tick.getXOffset() + this.afterWidth);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
120
105
|
this.beams.forEach((beam) => beam.postFormat());
|
|
121
106
|
}
|
|
122
107
|
getBoundingBox() {
|
|
@@ -129,27 +114,39 @@ export class GraceNoteGroup extends Modifier {
|
|
|
129
114
|
}
|
|
130
115
|
return boundingBox;
|
|
131
116
|
}
|
|
132
|
-
|
|
133
|
-
|
|
117
|
+
getLayoutElements() {
|
|
118
|
+
var _a, _b;
|
|
134
119
|
const note = this.checkAttachedNote();
|
|
135
|
-
this.setRendered();
|
|
136
|
-
L('Drawing grace note group for:', note);
|
|
137
120
|
this.positionGraceNotes();
|
|
138
|
-
this.
|
|
139
|
-
this.beams.forEach((beam) => beam.setContext(ctx).drawWithStyle());
|
|
140
|
-
if (this.showSlur) {
|
|
121
|
+
if (this.showSlur && this.graceNotes.length) {
|
|
141
122
|
const isStavenote = isStaveNote(note);
|
|
142
123
|
const TieClass = isStavenote ? StaveTie : TabTie;
|
|
143
|
-
this.
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
124
|
+
const after = this.position === Modifier.Position.RIGHT;
|
|
125
|
+
const end = after ? this.graceNotes[this.graceNotes.length - 1] : this.graceNotes[0];
|
|
126
|
+
if (((_a = this.slur) === null || _a === void 0 ? void 0 : _a.getNotes().firstNote) !== note || ((_b = this.slur) === null || _b === void 0 ? void 0 : _b.getNotes().lastNote) !== end)
|
|
127
|
+
this.slur = new TieClass({
|
|
128
|
+
lastNote: end,
|
|
129
|
+
firstNote: note,
|
|
130
|
+
firstIndexes: [0],
|
|
131
|
+
lastIndexes: [0],
|
|
132
|
+
});
|
|
133
|
+
if (this.afterWidth && isStavenote) {
|
|
134
|
+
const hostEdge = note.getNoteHeadBeginX() + (after ? note.getGlyphWidth() : 0);
|
|
135
|
+
this.slur.renderOptions.firstXShift = hostEdge - note.getTieRightX();
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
this.slur.renderOptions.firstXShift = 0;
|
|
139
|
+
}
|
|
149
140
|
this.slur.renderOptions.cp2 = 12;
|
|
150
141
|
this.slur.renderOptions.yShift = (isStavenote ? 7 : 5) + this.renderOptions.slurYShift;
|
|
151
|
-
this.slur.setContext(ctx).drawWithStyle();
|
|
152
142
|
}
|
|
143
|
+
return [...this.graceNotes, ...this.beams, ...(this.slur ? [this.slur] : [])];
|
|
144
|
+
}
|
|
145
|
+
draw() {
|
|
146
|
+
const ctx = this.checkContext();
|
|
147
|
+
this.setRendered();
|
|
148
|
+
L('Drawing grace note group for:', this.checkAttachedNote());
|
|
149
|
+
this.getLayoutElements().forEach((element) => element.setContext(ctx).drawWithStyle());
|
|
153
150
|
}
|
|
154
151
|
}
|
|
155
152
|
GraceNoteGroup.DEBUG = false;
|