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,159 @@
|
|
|
1
|
+
import { Element } from './element.js';
|
|
2
|
+
import { Glyphs } from './glyphs.js';
|
|
3
|
+
import { ribbonParts } from './phraseribbon.js';
|
|
4
|
+
import { Tables } from './tables.js';
|
|
5
|
+
export function spanLabel(spec) {
|
|
6
|
+
var _a, _b;
|
|
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
|
+
if (!text)
|
|
9
|
+
return;
|
|
10
|
+
return new Element(spec.kind === 'trill' ? 'Ornament' : 'Annotation').setText(text);
|
|
11
|
+
}
|
|
12
|
+
export function spanAbove(span) {
|
|
13
|
+
return span.side ? span.side === 'above' : ['slur', 'volta', 'ottava', 'trill', 'tuplet'].includes(span.kind);
|
|
14
|
+
}
|
|
15
|
+
export function continuationPitch(anchor, stave, index = 0) {
|
|
16
|
+
const source = anchor.note.checkStave(), key = anchor.note.getKeys()[index];
|
|
17
|
+
const offset = (anchor.note.getYs()[index] - source.getYForLine(0)) / source.space(1);
|
|
18
|
+
const clefShift = Tables.keyProperties(key, source.getClef()).line - Tables.keyProperties(key, stave.getClef()).line;
|
|
19
|
+
return stave.getYForLine(0) + stave.space(offset + clefShift);
|
|
20
|
+
}
|
|
21
|
+
function controls(f) {
|
|
22
|
+
var _a;
|
|
23
|
+
const lift = (f.above ? -1 : 1) * ((_a = f.rise) !== null && _a !== void 0 ? _a : Math.min(f.space * (f.kind === 'tie' ? 0.85 : 1.5), (f.x2 - f.x1) * 0.18));
|
|
24
|
+
return {
|
|
25
|
+
dx: (f.x2 - f.x1) / 3,
|
|
26
|
+
a: f.y1 + lift * (f.part === 'first' || f.part === 'single' ? 1 : 0.35),
|
|
27
|
+
b: f.y2 + lift * (f.part === 'last' || f.part === 'single' ? 1 : 0.35),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export function fitSpan(f, obstacles) {
|
|
31
|
+
const thickness = (f.above ? -1 : 1) * f.space * 0.22;
|
|
32
|
+
const initial = Math.min(f.space * (f.kind === 'tie' ? 0.85 : 1.5), (f.x2 - f.x1) * 0.18);
|
|
33
|
+
let best = initial, cost = Infinity;
|
|
34
|
+
for (let step = 0; step <= (f.kind === 'tie' ? 6 : 20); step++) {
|
|
35
|
+
f.rise = initial + step * f.space * 0.4;
|
|
36
|
+
const { dx, a, b } = controls(f);
|
|
37
|
+
const left = { x: f.x1, y: f.y1 }, right = { x: f.x2, y: f.y2 };
|
|
38
|
+
const cps = f.kind === 'tie'
|
|
39
|
+
? [{ x: (f.x1 + f.x2) / 2, y: (a + b) / 2 }]
|
|
40
|
+
: [
|
|
41
|
+
{ x: f.x1 + dx, y: a },
|
|
42
|
+
{ x: f.x2 - dx, y: b },
|
|
43
|
+
];
|
|
44
|
+
const parts = ribbonParts([left, ...cps, right], [left, ...cps.map((p) => (Object.assign(Object.assign({}, p), { y: p.y + thickness }))), right], f.space * 0.15);
|
|
45
|
+
const hits = parts.filter((p) => obstacles.some((o) => p.x < o.x + o.w && o.x < p.x + p.w && p.y < o.y + o.h && o.y < p.y + p.h)).length;
|
|
46
|
+
if (hits < cost) {
|
|
47
|
+
best = f.rise;
|
|
48
|
+
cost = hits;
|
|
49
|
+
}
|
|
50
|
+
if (!hits)
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
f.rise = best;
|
|
54
|
+
return cost === 0;
|
|
55
|
+
}
|
|
56
|
+
export function drawSpan(ctx, f, label) {
|
|
57
|
+
const { kind, space, x1, x2, y1, y2, above } = f;
|
|
58
|
+
const start = f.part === 'single' || f.part === 'first', end = f.part === 'single' || f.part === 'last';
|
|
59
|
+
const sign = above ? -1 : 1;
|
|
60
|
+
const line = (a, b, c, d) => {
|
|
61
|
+
ctx.beginPath();
|
|
62
|
+
ctx.moveTo(a, b);
|
|
63
|
+
ctx.lineTo(c, d);
|
|
64
|
+
ctx.stroke();
|
|
65
|
+
};
|
|
66
|
+
ctx.save();
|
|
67
|
+
try {
|
|
68
|
+
if (kind === 'slur' || kind === 'tie') {
|
|
69
|
+
const { dx, a, b } = controls(f);
|
|
70
|
+
ctx.beginPath();
|
|
71
|
+
ctx.moveTo(x1, y1);
|
|
72
|
+
if (kind === 'tie') {
|
|
73
|
+
const x = (x1 + x2) / 2, y = (a + b) / 2;
|
|
74
|
+
ctx.quadraticCurveTo(x, y, x2, y2);
|
|
75
|
+
ctx.quadraticCurveTo(x, y + sign * space * 0.22, x1, y1);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
ctx.bezierCurveTo(x1 + dx, a, x2 - dx, b, x2, y2);
|
|
79
|
+
ctx.bezierCurveTo(x2 - dx, b + sign * space * 0.22, x1 + dx, a + sign * space * 0.22, x1, y1);
|
|
80
|
+
}
|
|
81
|
+
ctx.closePath();
|
|
82
|
+
ctx.fill();
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (kind === 'crescendo' || kind === 'diminuendo') {
|
|
86
|
+
const [left, right] = f.progress.map((t) => space * 0.55 * (kind === 'crescendo' ? t : 1 - t));
|
|
87
|
+
line(x1, y1 - left, x2, y2 - right);
|
|
88
|
+
line(x1, y1 + left, x2, y2 + right);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (kind === 'tuplet') {
|
|
92
|
+
const mid = (x1 + x2) / 2, width = start && label ? label.getWidth() : 0, y = y1 + sign * space * 0.5;
|
|
93
|
+
if (start && label)
|
|
94
|
+
label.renderText(ctx, mid - width / 2, y1);
|
|
95
|
+
if (width) {
|
|
96
|
+
line(x1, y, mid - width / 2 - 2, y);
|
|
97
|
+
line(mid + width / 2 + 2, y, x2, y);
|
|
98
|
+
}
|
|
99
|
+
else
|
|
100
|
+
line(x1, y, x2, y);
|
|
101
|
+
if (start)
|
|
102
|
+
line(x1, y, x1, y - sign * space * 0.65);
|
|
103
|
+
if (end)
|
|
104
|
+
line(x2, y, x2, y - sign * space * 0.65);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const hasLabel = label && start;
|
|
108
|
+
if (hasLabel)
|
|
109
|
+
label.renderText(ctx, x1, y1);
|
|
110
|
+
const left = hasLabel ? x1 + label.getWidth() + space * 0.35 : x1;
|
|
111
|
+
if (kind === 'hyphen') {
|
|
112
|
+
if (x2 - left >= space * 0.5) {
|
|
113
|
+
const mid = (left + x2) / 2;
|
|
114
|
+
line(mid - space * 0.25, y1 - space * 0.35, mid + space * 0.25, y1 - space * 0.35);
|
|
115
|
+
}
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (kind === 'lyric') {
|
|
119
|
+
if (x2 > left)
|
|
120
|
+
line(left, y1 + 1, x2, y2 + 1);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (kind === 'trill') {
|
|
124
|
+
const period = space * 0.65;
|
|
125
|
+
ctx.beginPath();
|
|
126
|
+
ctx.moveTo(left, y1 - 3);
|
|
127
|
+
for (let x = left; x < x2;) {
|
|
128
|
+
const stop = Math.min(x + period, x2), d = stop - x;
|
|
129
|
+
ctx.bezierCurveTo(x + d / 3, y1 - space * 0.8, x + (2 * d) / 3, y1 + space * 0.2, stop, y1 - 3);
|
|
130
|
+
x = stop;
|
|
131
|
+
}
|
|
132
|
+
ctx.stroke();
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (kind === 'ottava' || kind === 'palmMute')
|
|
136
|
+
ctx.setLineDash([space * 0.45, space * 0.35]);
|
|
137
|
+
const y = kind === 'ottava' ? y1 - space * 0.5 : kind === 'volta' ? y1 - space * 1.35 : y1;
|
|
138
|
+
if (x2 > left)
|
|
139
|
+
line(kind === 'volta' ? x1 : left, y, x2, y);
|
|
140
|
+
ctx.setLineDash([]);
|
|
141
|
+
if (kind === 'pedal') {
|
|
142
|
+
if (start)
|
|
143
|
+
line(x1, y, x1, y - space * 0.8);
|
|
144
|
+
if (end)
|
|
145
|
+
line(x2, y, x2, y - space * 0.8);
|
|
146
|
+
}
|
|
147
|
+
else if (kind === 'volta') {
|
|
148
|
+
if (start)
|
|
149
|
+
line(x1, y, x1, y + space * 0.65);
|
|
150
|
+
if (end)
|
|
151
|
+
line(x2, y, x2, y + space * 0.65);
|
|
152
|
+
}
|
|
153
|
+
else if ((kind === 'ottava' || kind === 'palmMute') && end)
|
|
154
|
+
line(x2, y, x2, y - sign * space * 0.6);
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
ctx.restore();
|
|
158
|
+
}
|
|
159
|
+
}
|
package/build/esm/src/curve.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BoundingBox } from './boundingbox.js';
|
|
2
2
|
import { Element } from './element.js';
|
|
3
|
+
import { ribbonParts } from './phraseribbon.js';
|
|
3
4
|
import { RuntimeError } from './util.js';
|
|
4
5
|
function bezierExtrema(p0, p1, p2, p3) {
|
|
5
6
|
const values = [p0, p3];
|
|
@@ -46,12 +47,29 @@ export class Curve extends Element {
|
|
|
46
47
|
}
|
|
47
48
|
constructor(from, to, options) {
|
|
48
49
|
super();
|
|
49
|
-
this.
|
|
50
|
+
this.layoutRise = 0;
|
|
51
|
+
this.renderOptions = Object.assign({ thickness: 2, xShift: 0, yShift: 10, position: 'auto', positionEnd: 'auto', invert: false, cps: [
|
|
50
52
|
{ x: 0, y: 10 },
|
|
51
53
|
{ x: 0, y: 10 },
|
|
52
54
|
], openingDirection: 'auto' }, options);
|
|
55
|
+
this.authoredControls = (options === null || options === void 0 ? void 0 : options.cps) !== undefined;
|
|
53
56
|
this.setNotes(from, to);
|
|
54
57
|
}
|
|
58
|
+
setLayoutRise(rise) {
|
|
59
|
+
this.layoutRise = rise;
|
|
60
|
+
}
|
|
61
|
+
hasManualControls() {
|
|
62
|
+
return this.authoredControls || this.renderOptions.cps.some((p) => p.x !== 0 || p.y !== 10);
|
|
63
|
+
}
|
|
64
|
+
getNotes() {
|
|
65
|
+
return { firstNote: this.from, lastNote: this.to };
|
|
66
|
+
}
|
|
67
|
+
getRouteParts() {
|
|
68
|
+
var _a, _b;
|
|
69
|
+
const { first, last, cps, thicknessCps } = this.getBezierPoints(this.getRenderParams());
|
|
70
|
+
const outer = [first, ...cps, last];
|
|
71
|
+
return ribbonParts(outer, ((_a = this.style) === null || _a === void 0 ? void 0 : _a.lineDash) ? outer : [first, ...thicknessCps.reverse(), last], ((_b = this.getStyle().lineWidth) !== null && _b !== void 0 ? _b : 1) / 2);
|
|
72
|
+
}
|
|
55
73
|
setNotes(from, to) {
|
|
56
74
|
if (!from && !to) {
|
|
57
75
|
throw new RuntimeError('BadArguments', 'Curve needs to have either `from` or `to` set.');
|
|
@@ -72,8 +90,9 @@ export class Curve extends Element {
|
|
|
72
90
|
const lastY = params.lastY + yShift;
|
|
73
91
|
const thickness = this.renderOptions.thickness;
|
|
74
92
|
const cps = this.renderOptions.cps;
|
|
75
|
-
const { x: cp0x, y:
|
|
76
|
-
const { x: cp1x, y:
|
|
93
|
+
const { x: cp0x, y: y0 } = cps[0];
|
|
94
|
+
const { x: cp1x, y: y1 } = cps[1];
|
|
95
|
+
const cp0y = y0 + this.layoutRise, cp1y = y1 + this.layoutRise;
|
|
77
96
|
const controlPointSpacing = (lastX - firstX) / (cps.length + 2);
|
|
78
97
|
return {
|
|
79
98
|
first: { x: firstX, y: firstY },
|
|
@@ -105,60 +124,30 @@ export class Curve extends Element {
|
|
|
105
124
|
getRenderParams() {
|
|
106
125
|
const firstNote = this.from;
|
|
107
126
|
const lastNote = this.to;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
let
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
endMetric = 'baseY';
|
|
126
|
-
}
|
|
127
|
-
else if (positionEnd === CurvePosition.NEAR_TOP) {
|
|
128
|
-
endMetric = 'topY';
|
|
129
|
-
}
|
|
130
|
-
if (firstNote) {
|
|
131
|
-
firstX = firstNote.getTieRightX();
|
|
132
|
-
stemDirection = firstNote.getStemDirection();
|
|
133
|
-
firstY = firstNote.getStemExtents()[metric];
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
const stave = lastNote.checkStave();
|
|
137
|
-
firstX = stave.getTieStartX();
|
|
138
|
-
firstY = lastNote.getStemExtents()[metric];
|
|
139
|
-
}
|
|
140
|
-
if (lastNote) {
|
|
141
|
-
lastX = lastNote.getTieLeftX();
|
|
142
|
-
stemDirection = lastNote.getStemDirection();
|
|
143
|
-
lastY = lastNote.getStemExtents()[endMetric];
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
const stave = firstNote.checkStave();
|
|
147
|
-
lastX = stave.getTieEndX();
|
|
148
|
-
lastY = firstNote.getStemExtents()[endMetric];
|
|
149
|
-
}
|
|
150
|
-
if (this.renderOptions.openingDirection === 'up') {
|
|
151
|
-
stemDirection = 1;
|
|
152
|
-
}
|
|
153
|
-
if (this.renderOptions.openingDirection === 'down') {
|
|
154
|
-
stemDirection = -1;
|
|
127
|
+
const start = firstNote !== null && firstNote !== void 0 ? firstNote : lastNote;
|
|
128
|
+
const end = lastNote !== null && lastNote !== void 0 ? lastNote : firstNote;
|
|
129
|
+
const { openingDirection, invert } = this.renderOptions;
|
|
130
|
+
let direction = end.getStemDirection();
|
|
131
|
+
if (openingDirection === 'up')
|
|
132
|
+
direction = 1;
|
|
133
|
+
if (openingDirection === 'down')
|
|
134
|
+
direction = -1;
|
|
135
|
+
if (invert)
|
|
136
|
+
direction *= -1;
|
|
137
|
+
function endpointY(note, position) {
|
|
138
|
+
const extents = note.getStemExtents();
|
|
139
|
+
const onStemSide = direction === -note.getStemDirection();
|
|
140
|
+
const useTip = position === CurvePosition.NEAR_TOP ||
|
|
141
|
+
position === 'nearTop' ||
|
|
142
|
+
(position === 'auto' && openingDirection !== 'auto' && onStemSide);
|
|
143
|
+
return useTip ? extents.topY : extents.baseY;
|
|
155
144
|
}
|
|
156
145
|
return {
|
|
157
|
-
firstX,
|
|
158
|
-
lastX,
|
|
159
|
-
firstY,
|
|
160
|
-
lastY,
|
|
161
|
-
direction
|
|
146
|
+
firstX: firstNote ? firstNote.getTieRightX() : end.checkStave().getTieStartX(),
|
|
147
|
+
lastX: lastNote ? lastNote.getTieLeftX() : start.checkStave().getTieEndX(),
|
|
148
|
+
firstY: endpointY(start, this.renderOptions.position),
|
|
149
|
+
lastY: endpointY(end, this.renderOptions.positionEnd),
|
|
150
|
+
direction,
|
|
162
151
|
};
|
|
163
152
|
}
|
|
164
153
|
getBoundingBox() {
|
|
@@ -174,6 +163,10 @@ export class Curve extends Element {
|
|
|
174
163
|
const minY = Math.min(...ys);
|
|
175
164
|
return new BoundingBox(minX, minY, Math.max(...xs) - minX, Math.max(...ys) - minY);
|
|
176
165
|
}
|
|
166
|
+
getAnchors() {
|
|
167
|
+
const { first, last } = this.getBezierPoints(this.getRenderParams());
|
|
168
|
+
return { start: first, end: last };
|
|
169
|
+
}
|
|
177
170
|
draw() {
|
|
178
171
|
this.checkContext();
|
|
179
172
|
this.setRendered();
|
package/build/esm/src/dot.js
CHANGED
|
@@ -82,7 +82,7 @@ export class Dot extends Modifier {
|
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
if (note.isRest()) {
|
|
85
|
-
dot.dotShiftY
|
|
85
|
+
dot.dotShiftY = dot.restShiftY - halfShiftY;
|
|
86
86
|
}
|
|
87
87
|
else {
|
|
88
88
|
dot.dotShiftY = -halfShiftY;
|
|
@@ -99,6 +99,7 @@ export class Dot extends Modifier {
|
|
|
99
99
|
}
|
|
100
100
|
constructor() {
|
|
101
101
|
super();
|
|
102
|
+
this.restShiftY = 0;
|
|
102
103
|
this.position = Modifier.Position.RIGHT;
|
|
103
104
|
this.setText(Glyphs.augmentationDot);
|
|
104
105
|
this.dotShiftY = 0;
|
|
@@ -109,13 +110,12 @@ export class Dot extends Modifier {
|
|
|
109
110
|
return this;
|
|
110
111
|
}
|
|
111
112
|
setDotShiftY(y) {
|
|
113
|
+
this.restShiftY = y;
|
|
112
114
|
this.dotShiftY = y;
|
|
113
115
|
return this;
|
|
114
116
|
}
|
|
115
|
-
|
|
116
|
-
const ctx = this.checkContext();
|
|
117
|
+
positionGlyph() {
|
|
117
118
|
const note = this.checkAttachedNote();
|
|
118
|
-
this.setRendered();
|
|
119
119
|
const stave = note.checkStave();
|
|
120
120
|
const lineSpace = stave.getSpacingBetweenLines();
|
|
121
121
|
const start = note.getModifierStartXY(this.position, this.index, { forceFlagRight: true });
|
|
@@ -124,6 +124,15 @@ export class Dot extends Modifier {
|
|
|
124
124
|
}
|
|
125
125
|
this.x = start.x;
|
|
126
126
|
this.y = start.y + this.dotShiftY * lineSpace;
|
|
127
|
+
}
|
|
128
|
+
getInkBounds() {
|
|
129
|
+
this.positionGlyph();
|
|
130
|
+
return this.getTextInk(this.x, this.y);
|
|
131
|
+
}
|
|
132
|
+
draw() {
|
|
133
|
+
const ctx = this.checkContext();
|
|
134
|
+
this.positionGlyph();
|
|
135
|
+
this.setRendered();
|
|
127
136
|
this.renderText(ctx, 0, 0);
|
|
128
137
|
}
|
|
129
138
|
}
|
|
@@ -1,11 +1,44 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { ContinuousLayout } from '../continuouslayout.js';
|
|
1
13
|
import { Factory } from '../factory.js';
|
|
2
14
|
import { Fraction } from '../fraction.js';
|
|
15
|
+
import { Modifier } from '../modifier.js';
|
|
3
16
|
import { Note } from '../note.js';
|
|
4
17
|
import { StemmableNote } from '../stemmablenote.js';
|
|
5
18
|
import { Tickable } from '../tickable.js';
|
|
6
19
|
import { RuntimeError } from '../util.js';
|
|
7
20
|
import { Voice } from '../voice.js';
|
|
8
21
|
import { applyCompositionAccidentals } from './policies.js';
|
|
22
|
+
function buildGraceGroup(score, { side, notes, slur, beam }) {
|
|
23
|
+
if (!['before', 'after'].includes(side) || !notes.length)
|
|
24
|
+
invalid('Expected a nonempty before or after grace group.');
|
|
25
|
+
const children = notes.map((_a) => {
|
|
26
|
+
var { accidentals } = _a, spec = __rest(_a, ["accidentals"]);
|
|
27
|
+
const child = score.make.graceNote(spec);
|
|
28
|
+
for (const { index, type, cautionary } of accidentals !== null && accidentals !== void 0 ? accidentals : []) {
|
|
29
|
+
const mark = score.make.accidental({ type });
|
|
30
|
+
if (cautionary)
|
|
31
|
+
mark.setAsCautionary();
|
|
32
|
+
score.attach(child, mark, index);
|
|
33
|
+
}
|
|
34
|
+
return child;
|
|
35
|
+
});
|
|
36
|
+
const group = score.make.graceNoteGroup({ notes: children, slur });
|
|
37
|
+
group.setPosition(side === 'after' ? Modifier.Position.RIGHT : Modifier.Position.LEFT);
|
|
38
|
+
if (beam)
|
|
39
|
+
group.beamNotes();
|
|
40
|
+
return group;
|
|
41
|
+
}
|
|
9
42
|
function invalid(message) {
|
|
10
43
|
throw new RuntimeError('BadComposition', message);
|
|
11
44
|
}
|
|
@@ -63,6 +96,9 @@ function buildVoice(score, spec, initial, display) {
|
|
|
63
96
|
const note = 'tab' in item
|
|
64
97
|
? score.make.tabNote(item.tab, item.drawStem)
|
|
65
98
|
: score.make.note('note' in item ? item.note : item);
|
|
99
|
+
if ('grace' in item && item.grace) {
|
|
100
|
+
score.attach(note, buildGraceGroup(score, item.grace), 0);
|
|
101
|
+
}
|
|
66
102
|
if ('id' in item && item.id !== undefined)
|
|
67
103
|
note.setAttribute('id', item.id);
|
|
68
104
|
if ('stave' in item && item.stave)
|
|
@@ -203,6 +239,10 @@ export function compose(score, spec) {
|
|
|
203
239
|
invalid('All staves need the same number of measures.');
|
|
204
240
|
if (spec.accidentals && !['literal', 'key-aware'].includes(spec.accidentals))
|
|
205
241
|
invalid('Unknown accidental policy.');
|
|
242
|
+
if (spec.graceAccidentals && !['explicit', 'ordered'].includes(spec.graceAccidentals))
|
|
243
|
+
invalid('Unknown grace accidental policy.');
|
|
244
|
+
if (spec.graceAccidentals === 'ordered' && spec.accidentals !== 'key-aware')
|
|
245
|
+
invalid('Ordered grace accidentals require key-aware accidentals.');
|
|
206
246
|
if (spec.signatures && !['changes', 'every-measure'].includes(spec.signatures))
|
|
207
247
|
invalid('Unknown signature policy.');
|
|
208
248
|
if (spec.crossMeasureSpans && !['reject', 'manual'].includes(spec.crossMeasureSpans))
|
|
@@ -234,7 +274,7 @@ export function compose(score, spec) {
|
|
|
234
274
|
getElement: (id) => score.getElement(id),
|
|
235
275
|
getNote: (id) => score.getNote(id),
|
|
236
276
|
};
|
|
237
|
-
if (spec.signatures !== 'every-measure')
|
|
277
|
+
if (!spec.continuous && spec.signatures !== 'every-measure')
|
|
238
278
|
result.diagnostics.push({
|
|
239
279
|
code: 'SignaturePolicy',
|
|
240
280
|
message: 'Signatures appear at the first measure and explicit changes. Sheet does not repeat them at wrapped row starts.',
|
|
@@ -247,8 +287,15 @@ export function compose(score, spec) {
|
|
|
247
287
|
time: (_c = stave.time) !== null && _c !== void 0 ? _c : '4/4',
|
|
248
288
|
});
|
|
249
289
|
});
|
|
290
|
+
const starts = [], ends = [];
|
|
291
|
+
const placed = spec.continuous ? new Set() : undefined;
|
|
250
292
|
const noteMeasures = new Map();
|
|
251
293
|
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
|
+
}));
|
|
252
299
|
const system = result.sheet.addSystem(spec.system);
|
|
253
300
|
result.systems.push(system);
|
|
254
301
|
const parts = spec.staves.map((staff, staffIndex) => {
|
|
@@ -272,13 +319,16 @@ export function compose(score, spec) {
|
|
|
272
319
|
});
|
|
273
320
|
if (spec.accidentals === 'key-aware') {
|
|
274
321
|
const generated = new Set(policies.flatMap((policy) => [...policy.generated]));
|
|
275
|
-
policies.forEach((policy, staffIndex) => applyCompositionAccidentals(score, voices.flat(), policy.key, policy.changes, generated, staves[staffIndex]));
|
|
322
|
+
policies.forEach((policy, staffIndex) => applyCompositionAccidentals(score, voices.flat(), policy.key, policy.changes, generated, staves[staffIndex], spec.graceAccidentals === 'ordered', placed));
|
|
276
323
|
}
|
|
324
|
+
ends.push(states.slice());
|
|
277
325
|
result.staves.push(staves);
|
|
278
326
|
result.voices.push(voices);
|
|
279
327
|
result.notes.push(notes);
|
|
280
328
|
}
|
|
281
329
|
result.spans = buildSpans(score, spec, noteMeasures, result.diagnostics);
|
|
330
|
+
if (spec.continuous)
|
|
331
|
+
result.sheet.setContinuousLayout(new ContinuousLayout(result, spec, starts, ends, placed));
|
|
282
332
|
return result;
|
|
283
333
|
});
|
|
284
334
|
}
|
|
@@ -1,9 +1,32 @@
|
|
|
1
1
|
import { Accidental } from '../accidental.js';
|
|
2
2
|
import { Fraction } from '../fraction.js';
|
|
3
|
+
import { GraceNoteGroup } from '../gracenotegroup.js';
|
|
4
|
+
import { Modifier } from '../modifier.js';
|
|
3
5
|
import { Music } from '../music.js';
|
|
4
6
|
import { StaveNote } from '../stavenote.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
function orderedAttacks(hosts, includeGrace) {
|
|
8
|
+
const attacks = new Map([[0, hosts.filter((note) => !note.isRest())]]);
|
|
9
|
+
if (includeGrace)
|
|
10
|
+
for (const host of hosts) {
|
|
11
|
+
for (const group of host.getModifiers()) {
|
|
12
|
+
if (!(group instanceof GraceNoteGroup))
|
|
13
|
+
continue;
|
|
14
|
+
const notes = group.getGraceNotes();
|
|
15
|
+
notes.forEach((note, i) => {
|
|
16
|
+
var _a;
|
|
17
|
+
if (!(note instanceof StaveNote) || note.isRest())
|
|
18
|
+
return;
|
|
19
|
+
const offset = group.getPosition() === Modifier.Position.RIGHT ? i + 1 : i - notes.length;
|
|
20
|
+
const simultaneous = (_a = attacks.get(offset)) !== null && _a !== void 0 ? _a : [];
|
|
21
|
+
simultaneous.push(note);
|
|
22
|
+
attacks.set(offset, simultaneous);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return [...attacks.entries()].sort(([a], [b]) => a - b).map(([, notes]) => notes);
|
|
27
|
+
}
|
|
28
|
+
export function applyCompositionAccidentals(score, voices, key, changes, generated, stave, includeGrace = false, placed) {
|
|
29
|
+
var _a;
|
|
7
30
|
const music = new Music();
|
|
8
31
|
let scale = music.createScaleMap(key);
|
|
9
32
|
const state = new Map();
|
|
@@ -15,7 +38,7 @@ export function applyCompositionAccidentals(score, voices, key, changes, generat
|
|
|
15
38
|
continue;
|
|
16
39
|
const id = at.clone().simplify().toString();
|
|
17
40
|
const group = (_a = positions.get(id)) !== null && _a !== void 0 ? _a : { at: at.clone(), notes: [] };
|
|
18
|
-
if (note instanceof StaveNote &&
|
|
41
|
+
if (note instanceof StaveNote && note.getStave() === stave)
|
|
19
42
|
group.notes.push(note);
|
|
20
43
|
positions.set(id, group);
|
|
21
44
|
at.add(note.getTicks());
|
|
@@ -28,18 +51,23 @@ export function applyCompositionAccidentals(score, voices, key, changes, generat
|
|
|
28
51
|
scale = music.createScaleMap(changes[changeIndex++].key);
|
|
29
52
|
state.clear();
|
|
30
53
|
}
|
|
54
|
+
for (const notes of orderedAttacks(group.notes, includeGrace))
|
|
55
|
+
applyAttack(notes);
|
|
56
|
+
}
|
|
57
|
+
function applyAttack(notes) {
|
|
58
|
+
var _a;
|
|
31
59
|
const simultaneous = new Map();
|
|
32
|
-
for (const note of
|
|
60
|
+
for (const note of notes)
|
|
33
61
|
for (const written of note.getKeys()) {
|
|
34
62
|
const [name, octave] = written.split('/');
|
|
35
63
|
const parts = music.getNoteParts(name);
|
|
36
64
|
const id = `${parts.root}/${octave}`;
|
|
37
|
-
const values = (
|
|
65
|
+
const values = (_a = simultaneous.get(id)) !== null && _a !== void 0 ? _a : new Set();
|
|
38
66
|
values.add(parts.accidental || 'n');
|
|
39
67
|
simultaneous.set(id, values);
|
|
40
68
|
}
|
|
41
69
|
const updates = new Map();
|
|
42
|
-
for (const note of
|
|
70
|
+
for (const note of notes) {
|
|
43
71
|
note.getKeys().forEach((written, index) => {
|
|
44
72
|
var _a, _b, _c, _d;
|
|
45
73
|
const [name, octave] = written.split('/');
|
|
@@ -56,8 +84,11 @@ export function applyCompositionAccidentals(score, voices, key, changes, generat
|
|
|
56
84
|
if (!explicit.includes(mark))
|
|
57
85
|
note.getModifiers().splice(note.getModifiers().indexOf(mark), 1);
|
|
58
86
|
}
|
|
59
|
-
if (!explicit.length && (previous !== pitch || ((_c = (_b = simultaneous.get(id)) === null || _b === void 0 ? void 0 : _b.size) !== null && _c !== void 0 ? _c : 0) > 1))
|
|
60
|
-
|
|
87
|
+
if (!explicit.length && (previous !== pitch || ((_c = (_b = simultaneous.get(id)) === null || _b === void 0 ? void 0 : _b.size) !== null && _c !== void 0 ? _c : 0) > 1)) {
|
|
88
|
+
const mark = score.make.accidental({ type: accidental });
|
|
89
|
+
score.attach(note, mark, index);
|
|
90
|
+
placed === null || placed === void 0 ? void 0 : placed.add(mark);
|
|
91
|
+
}
|
|
61
92
|
const value = explicit.some((mark) => !Music.accidentals.includes(mark.type)) ? 'microtonal' : pitch;
|
|
62
93
|
const values = (_d = updates.get(id)) !== null && _d !== void 0 ? _d : new Set();
|
|
63
94
|
values.add(value);
|
package/build/esm/src/element.js
CHANGED
|
@@ -225,6 +225,10 @@ export class Element {
|
|
|
225
225
|
(_c = this.idListeners) === null || _c === void 0 ? void 0 : _c.forEach((listener) => listener.changed());
|
|
226
226
|
return this;
|
|
227
227
|
}
|
|
228
|
+
getTextInk(x, y) {
|
|
229
|
+
const m = this.textMetrics;
|
|
230
|
+
return new BoundingBox(x + this.xShift - m.actualBoundingBoxLeft, y + this.yShift - m.actualBoundingBoxAscent, m.actualBoundingBoxLeft + m.actualBoundingBoxRight, m.actualBoundingBoxAscent + m.actualBoundingBoxDescent);
|
|
231
|
+
}
|
|
228
232
|
getBoundingBox() {
|
|
229
233
|
return new BoundingBox(this.x + this.xShift, this.y + this.yShift - this.textMetrics.actualBoundingBoxAscent, this.width, this.height);
|
|
230
234
|
}
|