vexflow 5.3.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 +4189 -772
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +4323 -906
- 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/alternatingtremolo.js +68 -0
- package/build/esm/src/annotation.js +19 -3
- package/build/esm/src/articulation.js +5 -1
- package/build/esm/src/beam.js +13 -0
- package/build/esm/src/bend.js +57 -6
- 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 +21 -2
- package/build/esm/src/easyscore/composition.js +13 -2
- package/build/esm/src/easyscore/policies.js +6 -3
- package/build/esm/src/engravinggeometry.js +8 -1
- package/build/esm/src/factory.js +16 -4
- package/build/esm/src/font.js +9 -1
- package/build/esm/src/fretdiagram.js +77 -0
- package/build/esm/src/guitargesture.js +33 -0
- package/build/esm/src/guitarmodifiers.js +26 -0
- package/build/esm/src/index.js +8 -0
- package/build/esm/src/instrumentprofile.js +123 -0
- package/build/esm/src/keysignature.js +23 -1
- package/build/esm/src/notationspelling.js +73 -0
- package/build/esm/src/note.js +3 -0
- package/build/esm/src/ornament.js +5 -0
- 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/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 +6 -1
- package/build/esm/src/stavetie.js +27 -2
- 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/timesignature.js +15 -6
- package/build/esm/src/tuplet.js +1 -0
- package/build/esm/src/version.js +3 -3
- package/build/esm/src/vexflow.js +16 -0
- package/build/esm/src/voice.js +7 -3
- 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/specialist-studies.mjs +347 -0
- package/build/esm/tests/engraving/studies.mjs +88 -0
- package/build/esm/tests/node/continuous-score-tests.mjs +282 -0
- package/build/esm/tests/node/instrument-profile-tests.mjs +224 -0
- package/build/esm/tests/node/phrase-layout-tests.mjs +281 -0
- package/build/esm/tests/node/publication-tests.mjs +219 -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/types/src/alternatingtremolo.d.ts +13 -0
- package/build/types/src/annotation.d.ts +9 -0
- package/build/types/src/articulation.d.ts +3 -0
- package/build/types/src/beam.d.ts +2 -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 +11 -0
- package/build/types/src/easyscore/composition.d.ts +8 -0
- package/build/types/src/easyscore/policies.d.ts +1 -1
- package/build/types/src/fretdiagram.d.ts +23 -0
- 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 +10 -0
- package/build/types/src/instrumentprofile.d.ts +124 -0
- package/build/types/src/keysignature.d.ts +9 -0
- package/build/types/src/notationspelling.d.ts +25 -0
- package/build/types/src/note.d.ts +15 -0
- package/build/types/src/ornament.d.ts +3 -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/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/stavetie.d.ts +5 -0
- 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/timesignature.d.ts +4 -0
- package/build/types/src/vexflow.d.ts +16 -0
- package/build/types/src/voice.d.ts +2 -0
- package/changelog/CHANGELOG.md +8 -0
- package/package.json +9 -2
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { Accidental } from './accidental.js';
|
|
2
|
+
import { measureEngraving } from './engravinggeometry.js';
|
|
3
|
+
import { Fraction } from './fraction.js';
|
|
4
|
+
import { StaveNote } from './stavenote.js';
|
|
5
|
+
import { Tables } from './tables.js';
|
|
6
|
+
import { TabNote } from './tabnote.js';
|
|
7
|
+
import { RuntimeError } from './util.js';
|
|
8
|
+
const signs = {
|
|
9
|
+
'#': 'sharp',
|
|
10
|
+
'##': 'double sharp',
|
|
11
|
+
b: 'flat',
|
|
12
|
+
bb: 'double flat',
|
|
13
|
+
n: 'natural',
|
|
14
|
+
'+': 'quarter sharp',
|
|
15
|
+
d: 'quarter flat',
|
|
16
|
+
o: 'sori',
|
|
17
|
+
k: 'koron',
|
|
18
|
+
};
|
|
19
|
+
const lengths = {
|
|
20
|
+
'1/1': 'whole',
|
|
21
|
+
'1/2': 'half',
|
|
22
|
+
'1/4': 'quarter',
|
|
23
|
+
'1/8': 'eighth',
|
|
24
|
+
'1/16': 'sixteenth',
|
|
25
|
+
'3/4': 'dotted half',
|
|
26
|
+
'3/8': 'dotted quarter',
|
|
27
|
+
'3/16': 'dotted eighth',
|
|
28
|
+
};
|
|
29
|
+
function spokenPitch(key, sign) {
|
|
30
|
+
var _a, _b;
|
|
31
|
+
const [name, octave] = key.split('/');
|
|
32
|
+
const accidental = (_a = sign === null || sign === void 0 ? void 0 : sign.type) !== null && _a !== void 0 ? _a : name.slice(1).toLowerCase();
|
|
33
|
+
return [name[0].toUpperCase(), (_b = signs[accidental]) !== null && _b !== void 0 ? _b : accidental, octave].filter(Boolean).join(' ');
|
|
34
|
+
}
|
|
35
|
+
function describe(note) {
|
|
36
|
+
if (note.isRest())
|
|
37
|
+
return '';
|
|
38
|
+
const marks = note.notation.map((n) => n.label);
|
|
39
|
+
if (note instanceof TabNote) {
|
|
40
|
+
const positions = note.getPositions().map((p) => 'string ' + p.str + ' fret ' + p.fret);
|
|
41
|
+
return [...positions, ...note.notation.filter((n) => n.kind !== 'tuning').map((n) => n.label)].join(', ');
|
|
42
|
+
}
|
|
43
|
+
const unpitched = note.notation.filter((entry) => entry.kind === 'unpitched');
|
|
44
|
+
if (unpitched.some((entry) => entry.index === undefined))
|
|
45
|
+
return marks.join(', ');
|
|
46
|
+
const accidentals = note.getModifiers().filter((m) => m instanceof Accidental);
|
|
47
|
+
return [
|
|
48
|
+
...note.getKeys().flatMap((key, i) => unpitched.some((entry) => entry.index === i)
|
|
49
|
+
? []
|
|
50
|
+
: [
|
|
51
|
+
spokenPitch(key, accidentals.find((a) => a.getIndex() === i)),
|
|
52
|
+
]),
|
|
53
|
+
...marks,
|
|
54
|
+
].join(', ');
|
|
55
|
+
}
|
|
56
|
+
function noteRegion(note, diagnostics) {
|
|
57
|
+
if (note instanceof StaveNote) {
|
|
58
|
+
const measured = measureEngraving(note);
|
|
59
|
+
diagnostics.push(...measured.diagnostics);
|
|
60
|
+
return measured.ink;
|
|
61
|
+
}
|
|
62
|
+
const ys = note.getYs();
|
|
63
|
+
const half = note.checkStave().getSpacingBetweenLines() / 2;
|
|
64
|
+
return {
|
|
65
|
+
x: note.getAbsoluteX() - note.getWidth() / 2,
|
|
66
|
+
y: Math.min(...ys) - half,
|
|
67
|
+
w: note.getWidth(),
|
|
68
|
+
h: Math.max(...ys) - Math.min(...ys) + 2 * half,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export class ScoreNavigation {
|
|
72
|
+
constructor(score, staves, sources = {}) {
|
|
73
|
+
var _a, _b, _c, _d, _e, _f;
|
|
74
|
+
const regions = [], diagnostics = [];
|
|
75
|
+
const events = [];
|
|
76
|
+
const sourceFor = (id) => (Object.prototype.hasOwnProperty.call(sources, id) ? sources[id] : undefined);
|
|
77
|
+
const seen = new Set();
|
|
78
|
+
const layout = score.sheet.getContinuousLayout();
|
|
79
|
+
const muteLabels = new Map();
|
|
80
|
+
for (const fragment of (_a = layout === null || layout === void 0 ? void 0 : layout.fragments) !== null && _a !== void 0 ? _a : []) {
|
|
81
|
+
if (!fragment.strings)
|
|
82
|
+
continue;
|
|
83
|
+
const strings = (fragment.strings.length === 1 ? 'string ' : 'strings ') + fragment.strings.join(', ');
|
|
84
|
+
for (const [id, text] of [
|
|
85
|
+
[fragment.from, 'Begin palm mute on '],
|
|
86
|
+
[fragment.to, 'Last palm-muted attack on '],
|
|
87
|
+
]) {
|
|
88
|
+
if (id)
|
|
89
|
+
muteLabels.set(id, [...((_b = muteLabels.get(id)) !== null && _b !== void 0 ? _b : []), text + strings]);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
for (const [measure, staffNotes] of score.notes.entries()) {
|
|
93
|
+
if (staffNotes.length !== staves.length)
|
|
94
|
+
throw new RuntimeError('BadArguments', 'Pass the staves in composition order.');
|
|
95
|
+
const ordered = [];
|
|
96
|
+
for (const [index, voices] of staffNotes.entries()) {
|
|
97
|
+
const staff = staves[index];
|
|
98
|
+
for (const [voice, notes] of voices.entries()) {
|
|
99
|
+
const clock = new Fraction(0, 1);
|
|
100
|
+
for (const note of notes) {
|
|
101
|
+
if (note.shouldIgnoreTicks())
|
|
102
|
+
continue;
|
|
103
|
+
const time = clock.clone();
|
|
104
|
+
clock.add(note.getTicks());
|
|
105
|
+
if (!(note instanceof StaveNote || note instanceof TabNote))
|
|
106
|
+
continue;
|
|
107
|
+
const id = note.getAttribute('id');
|
|
108
|
+
if (seen.has(id))
|
|
109
|
+
throw new RuntimeError('DuplicateID', 'Duplicate score event: ' + id);
|
|
110
|
+
seen.add(id);
|
|
111
|
+
const onset = time.clone().divide(Tables.RESOLUTION).simplify().toString();
|
|
112
|
+
const duration = note.getTicks().clone().divide(Tables.RESOLUTION).simplify().toString();
|
|
113
|
+
const length = (_c = lengths[duration]) !== null && _c !== void 0 ? _c : duration + ' of a whole';
|
|
114
|
+
const label = [
|
|
115
|
+
`Measure ${measure + 1}`,
|
|
116
|
+
staff.name || staff.id,
|
|
117
|
+
`voice ${voice + 1}`,
|
|
118
|
+
describe(note),
|
|
119
|
+
length + (note.isRest() ? ' rest' : ' note'),
|
|
120
|
+
...((_d = muteLabels.get(id)) !== null && _d !== void 0 ? _d : []),
|
|
121
|
+
]
|
|
122
|
+
.filter(Boolean)
|
|
123
|
+
.join(', ');
|
|
124
|
+
ordered.push({
|
|
125
|
+
time,
|
|
126
|
+
event: {
|
|
127
|
+
id,
|
|
128
|
+
source: sourceFor(id),
|
|
129
|
+
staff: staff.id,
|
|
130
|
+
measure: measure + 1,
|
|
131
|
+
voice: voice + 1,
|
|
132
|
+
onset,
|
|
133
|
+
duration,
|
|
134
|
+
label,
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
if (layout === null || layout === void 0 ? void 0 : layout.hidden.has(note))
|
|
138
|
+
continue;
|
|
139
|
+
const box = noteRegion(note, diagnostics);
|
|
140
|
+
if (box)
|
|
141
|
+
regions.push({ id, source: sourceFor(id), kind: 'event', x: box.x, y: box.y, w: box.w, h: box.h });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
ordered.sort((a, b) => (a.time.equals(b.time) ? 0 : a.time.lessThan(b.time) ? -1 : 1));
|
|
146
|
+
events.push(...ordered.map((entry) => entry.event));
|
|
147
|
+
}
|
|
148
|
+
for (const fragment of (_e = layout === null || layout === void 0 ? void 0 : layout.fragments) !== null && _e !== void 0 ? _e : []) {
|
|
149
|
+
if (seen.has(fragment.id))
|
|
150
|
+
throw new RuntimeError('DuplicateID', 'Span shares a score event ID: ' + fragment.id);
|
|
151
|
+
const pad = Math.max(fragment.space, Math.abs((_f = fragment.rise) !== null && _f !== void 0 ? _f : 0));
|
|
152
|
+
regions.push(Object.assign(Object.assign({ id: fragment.id, row: fragment.row }, (fragment.strings && { strings: [...fragment.strings] })), { source: sourceFor(fragment.id), kind: 'span', x: Math.min(fragment.x1, fragment.x2), y: Math.min(fragment.y1, fragment.y2) - pad, w: Math.abs(fragment.x2 - fragment.x1), h: Math.abs(fragment.y2 - fragment.y1) + 2 * pad }));
|
|
153
|
+
}
|
|
154
|
+
this.events = events;
|
|
155
|
+
this.regions = regions;
|
|
156
|
+
this.diagnostics = diagnostics;
|
|
157
|
+
}
|
|
158
|
+
hitTest(x, y) {
|
|
159
|
+
if (!Number.isFinite(x) || !Number.isFinite(y))
|
|
160
|
+
return undefined;
|
|
161
|
+
let best;
|
|
162
|
+
for (const r of this.regions) {
|
|
163
|
+
if (x < r.x || x > r.x + r.w || y < r.y || y > r.y + r.h)
|
|
164
|
+
continue;
|
|
165
|
+
if (!best ||
|
|
166
|
+
(best.kind === 'span' && r.kind === 'event') ||
|
|
167
|
+
(best.kind === r.kind && r.w * r.h < best.w * best.h))
|
|
168
|
+
best = r;
|
|
169
|
+
}
|
|
170
|
+
return best;
|
|
171
|
+
}
|
|
172
|
+
}
|
package/build/esm/src/sheet.js
CHANGED
|
@@ -4,6 +4,13 @@ import { StaveNote } from './stavenote.js';
|
|
|
4
4
|
import { StemmableNote } from './stemmablenote.js';
|
|
5
5
|
import { RuntimeError } from './util.js';
|
|
6
6
|
export class Sheet {
|
|
7
|
+
setContinuousLayout(layout) {
|
|
8
|
+
this.continuous = layout;
|
|
9
|
+
return this;
|
|
10
|
+
}
|
|
11
|
+
getContinuousLayout() {
|
|
12
|
+
return this.continuous;
|
|
13
|
+
}
|
|
7
14
|
constructor(options) {
|
|
8
15
|
this.systems = [];
|
|
9
16
|
this.rows = [];
|
|
@@ -38,6 +45,10 @@ export class Sheet {
|
|
|
38
45
|
return last ? last.y + last.height : this.options.y;
|
|
39
46
|
}
|
|
40
47
|
format() {
|
|
48
|
+
if (this.continuous) {
|
|
49
|
+
this.rows = this.continuous.format(this.options);
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
41
52
|
const widths = this.measureSystems();
|
|
42
53
|
this.rows = [];
|
|
43
54
|
let y = this.options.y;
|
|
@@ -74,8 +85,9 @@ export class Sheet {
|
|
|
74
85
|
return groups;
|
|
75
86
|
}
|
|
76
87
|
verticalBounds(system) {
|
|
77
|
-
|
|
78
|
-
let
|
|
88
|
+
const envelope = system.getBoundingBox();
|
|
89
|
+
let top = Math.min(0, envelope.y);
|
|
90
|
+
let bottom = envelope.y + envelope.h;
|
|
79
91
|
for (const voice of system.getVoices()) {
|
|
80
92
|
for (const note of voice.getTickables()) {
|
|
81
93
|
if (note instanceof StaveNote || note instanceof ClefNote) {
|
package/build/esm/src/stave.js
CHANGED
|
@@ -15,21 +15,27 @@ import { TimeSignature } from './timesignature.js';
|
|
|
15
15
|
import { isBarline } from './typeguard.js';
|
|
16
16
|
import { RuntimeError } from './util.js';
|
|
17
17
|
const SORT_ORDER_BEG_MODIFIERS = {
|
|
18
|
-
[Barline
|
|
19
|
-
[Clef
|
|
20
|
-
[KeySignature
|
|
21
|
-
[TimeSignature
|
|
18
|
+
["Barline"]: 0,
|
|
19
|
+
["Clef"]: 1,
|
|
20
|
+
["KeySignature"]: 2,
|
|
21
|
+
["TimeSignature"]: 3,
|
|
22
22
|
};
|
|
23
23
|
const SORT_ORDER_END_MODIFIERS = {
|
|
24
|
-
[TimeSignature
|
|
25
|
-
[KeySignature
|
|
26
|
-
[Barline
|
|
27
|
-
[Clef
|
|
24
|
+
["TimeSignature"]: 0,
|
|
25
|
+
["KeySignature"]: 1,
|
|
26
|
+
["Barline"]: 2,
|
|
27
|
+
["Clef"]: 3,
|
|
28
28
|
};
|
|
29
29
|
export class Stave extends Element {
|
|
30
30
|
static get CATEGORY() {
|
|
31
31
|
return "Stave";
|
|
32
32
|
}
|
|
33
|
+
setBoundaryModifiers(modifiers) {
|
|
34
|
+
this.boundaryModifiers = modifiers;
|
|
35
|
+
for (const mark of modifiers)
|
|
36
|
+
mark.setStave(this);
|
|
37
|
+
this.formatted = false;
|
|
38
|
+
}
|
|
33
39
|
static get defaultPadding() {
|
|
34
40
|
return Metrics.get('Stave.padding') + Metrics.get('Stave.endPaddingMax');
|
|
35
41
|
}
|
|
@@ -39,6 +45,7 @@ export class Stave extends Element {
|
|
|
39
45
|
constructor(x, y, width, options) {
|
|
40
46
|
var _a;
|
|
41
47
|
super();
|
|
48
|
+
this.boundaryModifiers = [];
|
|
42
49
|
this.x = x;
|
|
43
50
|
this.y = y;
|
|
44
51
|
this.width = width;
|
|
@@ -49,7 +56,7 @@ export class Stave extends Element {
|
|
|
49
56
|
this.measure = 0;
|
|
50
57
|
this.clef = (_a = options === null || options === void 0 ? void 0 : options.clef) !== null && _a !== void 0 ? _a : 'treble';
|
|
51
58
|
this.endClef = undefined;
|
|
52
|
-
this.options = Object.assign({ clef: 'treble', verticalBarWidth: 10, numLines: 5, leftBar: true, rightBar: true, spacingBetweenLinesPx: Tables.STAVE_LINE_DISTANCE, spaceAboveStaffLn: 4, spaceBelowStaffLn: 4, topTextPosition: 1, bottomTextPosition: 4, lineConfig: [] }, options);
|
|
59
|
+
this.options = Object.assign({ clef: 'treble', barlineSpan: null, verticalBarWidth: 10, numLines: 5, leftBar: true, rightBar: true, spacingBetweenLinesPx: Tables.STAVE_LINE_DISTANCE, spaceAboveStaffLn: 4, spaceBelowStaffLn: 4, topTextPosition: 1, bottomTextPosition: 4, lineConfig: [] }, options);
|
|
53
60
|
this.bounds = { x: this.x, y: this.y, w: this.width, h: 0 };
|
|
54
61
|
this.defaultLedgerLineStyle = { lineWidth: 2 };
|
|
55
62
|
this.resetLines();
|
|
@@ -106,6 +113,15 @@ export class Stave extends Element {
|
|
|
106
113
|
this.resetLines();
|
|
107
114
|
return this;
|
|
108
115
|
}
|
|
116
|
+
getBarlineBounds() {
|
|
117
|
+
var _a;
|
|
118
|
+
const span = this.options.barlineSpan;
|
|
119
|
+
if (!span)
|
|
120
|
+
return { topY: this.getTopLineTopY(), botY: this.getBottomLineBottomY() };
|
|
121
|
+
if (!Number.isFinite(span.top) || !Number.isFinite(span.bottom) || span.top >= span.bottom)
|
|
122
|
+
throw new RuntimeError('StaveConfigError', 'Barline endpoints must increase from top to bottom.');
|
|
123
|
+
return { topY: this.getYForLine(span.top), botY: this.getYForLine(span.bottom) + ((_a = this.getStyle().lineWidth) !== null && _a !== void 0 ? _a : 1) };
|
|
124
|
+
}
|
|
109
125
|
getTopLineTopY() {
|
|
110
126
|
return this.getYForLine(0);
|
|
111
127
|
}
|
|
@@ -285,7 +301,8 @@ export class Stave extends Element {
|
|
|
285
301
|
return this;
|
|
286
302
|
}
|
|
287
303
|
getEndClef() {
|
|
288
|
-
|
|
304
|
+
const courtesy = this.boundaryModifiers.find((m) => m instanceof Clef && m.getPosition() === StaveModifierPosition.END);
|
|
305
|
+
return courtesy instanceof Clef ? courtesy.getType() : this.endClef;
|
|
289
306
|
}
|
|
290
307
|
setKeySignature(keySpec, cancelKeySpec, position) {
|
|
291
308
|
if (position === undefined) {
|
|
@@ -355,19 +372,20 @@ export class Stave extends Element {
|
|
|
355
372
|
return this;
|
|
356
373
|
}
|
|
357
374
|
getModifiers(position, category) {
|
|
375
|
+
const modifiers = this.boundaryModifiers.length ? this.modifiers.concat(this.boundaryModifiers) : this.modifiers;
|
|
358
376
|
const noPosition = position === undefined;
|
|
359
377
|
const noCategory = category === undefined;
|
|
360
378
|
if (noPosition && noCategory) {
|
|
361
|
-
return
|
|
379
|
+
return modifiers;
|
|
362
380
|
}
|
|
363
381
|
else if (noPosition) {
|
|
364
|
-
return
|
|
382
|
+
return modifiers.filter((m) => category === m.getCategory());
|
|
365
383
|
}
|
|
366
384
|
else if (noCategory) {
|
|
367
|
-
return
|
|
385
|
+
return modifiers.filter((m) => position === m.getPosition());
|
|
368
386
|
}
|
|
369
387
|
else {
|
|
370
|
-
return
|
|
388
|
+
return modifiers.filter((m) => position === m.getPosition() && category === m.getCategory());
|
|
371
389
|
}
|
|
372
390
|
}
|
|
373
391
|
sortByCategory(items, order) {
|
|
@@ -482,8 +500,7 @@ export class Stave extends Element {
|
|
|
482
500
|
}
|
|
483
501
|
this.drawPointerRect();
|
|
484
502
|
ctx.closeGroup();
|
|
485
|
-
for (
|
|
486
|
-
const modifier = this.modifiers[i];
|
|
503
|
+
for (const modifier of this.getModifiers()) {
|
|
487
504
|
modifier.setContext(ctx);
|
|
488
505
|
modifier.setStave(this);
|
|
489
506
|
modifier.drawWithStyle();
|
|
@@ -154,8 +154,7 @@ export class Barline extends StaveModifier {
|
|
|
154
154
|
}
|
|
155
155
|
drawVerticalBar(stave, x, doubleBar) {
|
|
156
156
|
const staveCtx = stave.checkContext();
|
|
157
|
-
const topY = stave.
|
|
158
|
-
const botY = stave.getBottomLineBottomY();
|
|
157
|
+
const { topY, botY } = stave.getBarlineBounds();
|
|
159
158
|
if (doubleBar) {
|
|
160
159
|
staveCtx.fillRect(x - 3, topY, 1, botY - topY);
|
|
161
160
|
}
|
|
@@ -163,8 +162,7 @@ export class Barline extends StaveModifier {
|
|
|
163
162
|
}
|
|
164
163
|
drawVerticalEndBar(stave, x) {
|
|
165
164
|
const staveCtx = stave.checkContext();
|
|
166
|
-
const topY = stave.
|
|
167
|
-
const botY = stave.getBottomLineBottomY();
|
|
165
|
+
const { topY, botY } = stave.getBarlineBounds();
|
|
168
166
|
staveCtx.fillRect(x - 5, topY, 1, botY - topY);
|
|
169
167
|
staveCtx.fillRect(x - 2, topY, 3, botY - topY);
|
|
170
168
|
}
|
|
@@ -198,8 +196,7 @@ export class Barline extends StaveModifier {
|
|
|
198
196
|
}
|
|
199
197
|
drawRepeatBar(stave, x, begin) {
|
|
200
198
|
const staveCtx = stave.checkContext();
|
|
201
|
-
const topY = stave.
|
|
202
|
-
const botY = stave.getBottomLineBottomY();
|
|
199
|
+
const { topY, botY } = stave.getBarlineBounds();
|
|
203
200
|
let xShift = 3;
|
|
204
201
|
if (!begin) {
|
|
205
202
|
xShift = -5;
|
|
@@ -223,7 +220,8 @@ export class Barline extends StaveModifier {
|
|
|
223
220
|
xShift -= 4;
|
|
224
221
|
}
|
|
225
222
|
const dotX = x + xShift + dotRadius / 2;
|
|
226
|
-
|
|
223
|
+
const span = stave.options.barlineSpan;
|
|
224
|
+
let yOffset = (span ? span.bottom - span.top : stave.getNumLines() - 1) * stave.getSpacingBetweenLines();
|
|
227
225
|
yOffset = yOffset / 2 - stave.getSpacingBetweenLines() / 2;
|
|
228
226
|
let dotY = topY + yOffset + dotRadius / 2;
|
|
229
227
|
staveCtx.beginPath();
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BoundingBox } from './boundingbox.js';
|
|
1
2
|
import { Element } from './element.js';
|
|
2
3
|
import { Modifier } from './modifier.js';
|
|
3
4
|
import { RuntimeError } from './util.js';
|
|
@@ -32,6 +33,8 @@ export class StaveHairpin extends Element {
|
|
|
32
33
|
}
|
|
33
34
|
constructor(notes, type) {
|
|
34
35
|
super();
|
|
36
|
+
this.layoutLeft = 0;
|
|
37
|
+
this.layoutRight = 0;
|
|
35
38
|
this.setNotes(notes);
|
|
36
39
|
this.hairpin = type;
|
|
37
40
|
this.position = Modifier.Position.BELOW;
|
|
@@ -63,27 +66,62 @@ export class StaveHairpin extends Element {
|
|
|
63
66
|
this.lastNote = notes.lastNote;
|
|
64
67
|
return this;
|
|
65
68
|
}
|
|
69
|
+
getNotes() {
|
|
70
|
+
return [this.firstNote, this.lastNote];
|
|
71
|
+
}
|
|
72
|
+
setLayoutBaseline(y, left = 0, right = 0) {
|
|
73
|
+
this.layoutBaseline = y;
|
|
74
|
+
this.layoutLeft = left;
|
|
75
|
+
this.layoutRight = right;
|
|
76
|
+
}
|
|
77
|
+
parameters() {
|
|
78
|
+
const first = this.firstNote, last = this.lastNote;
|
|
79
|
+
if (!first || !last)
|
|
80
|
+
throw new RuntimeError('NoNote', 'Notes required to draw');
|
|
81
|
+
return {
|
|
82
|
+
firstX: first.getModifierStartXY(this.position, 0).x,
|
|
83
|
+
lastX: last.getModifierStartXY(this.position, 0).x,
|
|
84
|
+
firstY: first.checkStave().getY() + first.checkStave().getHeight(),
|
|
85
|
+
lastY: last.checkStave().getY() + last.checkStave().getHeight(),
|
|
86
|
+
staffHeight: first.checkStave().getHeight(),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
edges(params) {
|
|
90
|
+
const { yShift, height, leftShiftPx, rightShiftPx } = this.renderOptions;
|
|
91
|
+
const above = this.position === Modifier.Position.ABOVE;
|
|
92
|
+
const top = this.layoutBaseline === undefined
|
|
93
|
+
? params.firstY + (above ? 10 - params.staffHeight - yShift : 20 + yShift)
|
|
94
|
+
: this.layoutBaseline - height / 2 + (above ? -yShift : yShift);
|
|
95
|
+
return {
|
|
96
|
+
top,
|
|
97
|
+
left: params.firstX + leftShiftPx + this.layoutLeft,
|
|
98
|
+
right: params.lastX + rightShiftPx - this.layoutRight,
|
|
99
|
+
height,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
getLayoutEdges() {
|
|
103
|
+
return this.edges(this.parameters());
|
|
104
|
+
}
|
|
105
|
+
getBoundingBox() {
|
|
106
|
+
var _a;
|
|
107
|
+
const { top, left, right, height } = this.getLayoutEdges();
|
|
108
|
+
const pad = ((_a = this.getStyle().lineWidth) !== null && _a !== void 0 ? _a : 1) / 2;
|
|
109
|
+
return new BoundingBox(Math.min(left, right) - pad, Math.min(top, top + height) - pad, Math.abs(right - left) + 2 * pad, Math.abs(height) + 2 * pad);
|
|
110
|
+
}
|
|
66
111
|
renderHairpin(params) {
|
|
67
112
|
const ctx = this.checkContext();
|
|
68
|
-
|
|
69
|
-
let yShift = params.firstY;
|
|
70
|
-
if (this.position === Modifier.Position.ABOVE) {
|
|
71
|
-
dis = -dis + 30;
|
|
72
|
-
yShift = params.firstY - params.staffHeight;
|
|
73
|
-
}
|
|
74
|
-
const leftShiftPx = this.renderOptions.leftShiftPx;
|
|
75
|
-
const rightShiftPx = this.renderOptions.rightShiftPx;
|
|
113
|
+
const { top, left, right, height } = this.edges(params);
|
|
76
114
|
ctx.beginPath();
|
|
77
115
|
switch (this.hairpin) {
|
|
78
116
|
case StaveHairpin.type.CRESC:
|
|
79
|
-
ctx.moveTo(
|
|
80
|
-
ctx.lineTo(
|
|
81
|
-
ctx.lineTo(
|
|
117
|
+
ctx.moveTo(right, top);
|
|
118
|
+
ctx.lineTo(left, top + height / 2);
|
|
119
|
+
ctx.lineTo(right, top + height);
|
|
82
120
|
break;
|
|
83
121
|
case StaveHairpin.type.DECRESC:
|
|
84
|
-
ctx.moveTo(
|
|
85
|
-
ctx.lineTo(
|
|
86
|
-
ctx.lineTo(
|
|
122
|
+
ctx.moveTo(left, top);
|
|
123
|
+
ctx.lineTo(right, top + height / 2);
|
|
124
|
+
ctx.lineTo(left, top + height);
|
|
87
125
|
break;
|
|
88
126
|
default:
|
|
89
127
|
break;
|
|
@@ -94,19 +132,7 @@ export class StaveHairpin extends Element {
|
|
|
94
132
|
draw() {
|
|
95
133
|
this.checkContext();
|
|
96
134
|
this.setRendered();
|
|
97
|
-
|
|
98
|
-
const lastNote = this.lastNote;
|
|
99
|
-
if (!firstNote || !lastNote)
|
|
100
|
-
throw new RuntimeError('NoNote', 'Notes required to draw');
|
|
101
|
-
const start = firstNote.getModifierStartXY(this.position, 0);
|
|
102
|
-
const end = lastNote.getModifierStartXY(this.position, 0);
|
|
103
|
-
this.renderHairpin({
|
|
104
|
-
firstX: start.x,
|
|
105
|
-
lastX: end.x,
|
|
106
|
-
firstY: firstNote.checkStave().getY() + firstNote.checkStave().getHeight(),
|
|
107
|
-
lastY: lastNote.checkStave().getY() + lastNote.checkStave().getHeight(),
|
|
108
|
-
staffHeight: firstNote.checkStave().getHeight(),
|
|
109
|
-
});
|
|
135
|
+
this.renderHairpin(this.parameters());
|
|
110
136
|
}
|
|
111
137
|
}
|
|
112
138
|
StaveHairpin.type = {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BoundingBox } from './boundingbox.js';
|
|
2
2
|
import { Glyphs } from './glyphs.js';
|
|
3
|
+
import { attachGuitarGestures } from './guitarmodifiers.js';
|
|
3
4
|
import { Metrics } from './metrics.js';
|
|
4
5
|
import { Modifier } from './modifier.js';
|
|
5
6
|
import { Note } from './note.js';
|
|
@@ -275,6 +276,8 @@ export class StaveNote extends StemmableNote {
|
|
|
275
276
|
else {
|
|
276
277
|
this.setStemDirection((_e = noteStruct.stemDirection) !== null && _e !== void 0 ? _e : Stem.UP);
|
|
277
278
|
}
|
|
279
|
+
if (this.notation.length)
|
|
280
|
+
attachGuitarGestures(this);
|
|
278
281
|
}
|
|
279
282
|
reset() {
|
|
280
283
|
super.reset();
|
|
@@ -872,7 +875,9 @@ export class StaveNote extends StemmableNote {
|
|
|
872
875
|
}
|
|
873
876
|
L('Rendering ', this.isChord() ? 'chord :' : 'note :', this.keys);
|
|
874
877
|
const clsAttribute = this.getAttribute('class');
|
|
875
|
-
ctx.openGroup('stavenote' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
|
|
878
|
+
const group = ctx.openGroup('stavenote' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
|
|
879
|
+
if (this.notation.length)
|
|
880
|
+
group === null || group === void 0 ? void 0 : group.setAttribute('aria-label', this.notation.map((entry) => entry.label).join(', '));
|
|
876
881
|
this.drawLedgerLines();
|
|
877
882
|
if (shouldRenderStem)
|
|
878
883
|
this.drawStem();
|
|
@@ -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
|
export class StaveTie extends Element {
|
|
5
6
|
static get CATEGORY() {
|
|
@@ -7,6 +8,7 @@ export class StaveTie extends Element {
|
|
|
7
8
|
}
|
|
8
9
|
constructor(notes, text = '') {
|
|
9
10
|
super();
|
|
11
|
+
this.layoutRise = 0;
|
|
10
12
|
this.setNotes(notes);
|
|
11
13
|
this.text = text;
|
|
12
14
|
this.renderOptions = {
|
|
@@ -81,8 +83,8 @@ export class StaveTie extends Element {
|
|
|
81
83
|
if (isNaN(firstY) || isNaN(lastY)) {
|
|
82
84
|
throw new RuntimeError('BadArguments', 'Bad indexes for tie rendering.');
|
|
83
85
|
}
|
|
84
|
-
const topControlPointY = (firstY + lastY) / 2 + cp1 * params.direction;
|
|
85
|
-
const bottomControlPointY = (firstY + lastY) / 2 + cp2 * params.direction;
|
|
86
|
+
const topControlPointY = (firstY + lastY) / 2 + (cp1 + this.layoutRise) * params.direction;
|
|
87
|
+
const bottomControlPointY = (firstY + lastY) / 2 + (cp2 + this.layoutRise) * params.direction;
|
|
86
88
|
yield {
|
|
87
89
|
x1: params.firstX + firstXShift,
|
|
88
90
|
x2: params.lastX + lastXShift,
|
|
@@ -94,6 +96,29 @@ export class StaveTie extends Element {
|
|
|
94
96
|
};
|
|
95
97
|
}
|
|
96
98
|
}
|
|
99
|
+
setLayoutRise(rise) {
|
|
100
|
+
this.layoutRise = rise;
|
|
101
|
+
}
|
|
102
|
+
hasManualControls() {
|
|
103
|
+
const { cp1, cp2, cp1Short, cp2Short } = this.renderOptions;
|
|
104
|
+
return cp1 !== 8 || cp2 !== 12 || cp1Short !== 2 || cp2Short !== 8;
|
|
105
|
+
}
|
|
106
|
+
getRouteParts() {
|
|
107
|
+
this.synchronizeIndexes();
|
|
108
|
+
const ribbons = this.tieCurves({
|
|
109
|
+
firstX: this.getFirstX(),
|
|
110
|
+
lastX: this.getLastX(),
|
|
111
|
+
firstYs: this.getFirstYs(),
|
|
112
|
+
lastYs: this.getLastYs(),
|
|
113
|
+
direction: this.getDirection(),
|
|
114
|
+
});
|
|
115
|
+
const parts = [];
|
|
116
|
+
for (const r of ribbons) {
|
|
117
|
+
const start = { x: r.x1, y: r.firstY }, end = { x: r.x2, y: r.lastY };
|
|
118
|
+
parts.push(...ribbonParts([start, { x: r.cpX, y: r.topControlPointY }, end], [start, { x: r.cpX, y: r.bottomControlPointY }, end]));
|
|
119
|
+
}
|
|
120
|
+
return parts;
|
|
121
|
+
}
|
|
97
122
|
getRibbonBounds() {
|
|
98
123
|
this.synchronizeIndexes();
|
|
99
124
|
const curves = this.tieCurves({
|
package/build/esm/src/strokes.js
CHANGED
package/build/esm/src/system.js
CHANGED
|
@@ -2,6 +2,7 @@ import { BoundingBox } from './boundingbox.js';
|
|
|
2
2
|
import { Element } from './element.js';
|
|
3
3
|
import { Formatter } from './formatter.js';
|
|
4
4
|
import { Note } from './note.js';
|
|
5
|
+
import { PhraseLayout } from './phraselayout.js';
|
|
5
6
|
import { Stave } from './stave.js';
|
|
6
7
|
import { RuntimeError } from './util.js';
|
|
7
8
|
export class System extends Element {
|
|
@@ -103,7 +104,13 @@ export class System extends Element {
|
|
|
103
104
|
this.partVoices.push(voice);
|
|
104
105
|
});
|
|
105
106
|
}
|
|
106
|
-
|
|
107
|
+
getPhraseLayout() {
|
|
108
|
+
var _a;
|
|
109
|
+
return ((_a = this.phrase) !== null && _a !== void 0 ? _a : (this.phrase = new PhraseLayout()));
|
|
110
|
+
}
|
|
111
|
+
format(row) {
|
|
112
|
+
var _a, _b, _c, _d;
|
|
113
|
+
(_a = this.phrase) === null || _a === void 0 ? void 0 : _a.resetPlacement();
|
|
107
114
|
const optionsDetails = this.options.details;
|
|
108
115
|
let justifyWidth = 0;
|
|
109
116
|
const formatter = new Formatter(optionsDetails);
|
|
@@ -113,6 +120,8 @@ export class System extends Element {
|
|
|
113
120
|
const debugNoteMetricsYs = [];
|
|
114
121
|
this.partStaves.forEach((part, index) => {
|
|
115
122
|
y = y + part.space(this.partStaveInfos[index].spaceAbove);
|
|
123
|
+
if (row === null || row === void 0 ? void 0 : row.staffOffsets)
|
|
124
|
+
y = this.options.y + row.staffOffsets[index];
|
|
116
125
|
part.setY(y);
|
|
117
126
|
y = y + part.space(this.partStaveInfos[index].spaceBelow);
|
|
118
127
|
y = y + part.space(this.options.spaceBetweenStaves);
|
|
@@ -133,7 +142,7 @@ export class System extends Element {
|
|
|
133
142
|
this.partStaves.forEach((part) => part.setNoteStartX(startX));
|
|
134
143
|
if (this.options.autoWidth && this.partVoices.length > 0) {
|
|
135
144
|
justifyWidth = formatter.preCalculateMinTotalWidth(this.partVoices);
|
|
136
|
-
this.options.width = justifyWidth + Stave.rightPadding + (startX - this.options.x);
|
|
145
|
+
this.options.width = justifyWidth + Stave.rightPadding + (startX - this.options.x) + ((_b = row === null || row === void 0 ? void 0 : row.endPadding) !== null && _b !== void 0 ? _b : 0);
|
|
137
146
|
this.partStaves.forEach((part) => {
|
|
138
147
|
part.setWidth(this.options.width);
|
|
139
148
|
});
|
|
@@ -144,6 +153,8 @@ export class System extends Element {
|
|
|
144
153
|
: this.options.width - (startX - this.options.x) - Stave.defaultPadding;
|
|
145
154
|
}
|
|
146
155
|
if (this.partVoices.length > 0) {
|
|
156
|
+
if (!this.options.autoWidth)
|
|
157
|
+
justifyWidth -= (_c = row === null || row === void 0 ? void 0 : row.endPadding) !== null && _c !== void 0 ? _c : 0;
|
|
147
158
|
formatter.format(this.partVoices, this.options.noJustification ? 0 : justifyWidth, this.options.formatOptions);
|
|
148
159
|
}
|
|
149
160
|
formatter.postFormat();
|
|
@@ -154,17 +165,21 @@ export class System extends Element {
|
|
|
154
165
|
this.debugNoteMetricsYs = debugNoteMetricsYs;
|
|
155
166
|
this.lastY = y;
|
|
156
167
|
Stave.formatBegModifiers(this.partStaves);
|
|
168
|
+
(_d = this.phrase) === null || _d === void 0 ? void 0 : _d.format(this.partStaves, this.partVoices);
|
|
157
169
|
}
|
|
158
170
|
getBoundingBox() {
|
|
159
|
-
var _a;
|
|
160
|
-
|
|
171
|
+
var _a, _b;
|
|
172
|
+
const box = new BoundingBox(this.options.x, this.options.y, this.options.width, ((_a = this.lastY) !== null && _a !== void 0 ? _a : 0) - this.options.y);
|
|
173
|
+
return ((_b = this.phrase) === null || _b === void 0 ? void 0 : _b.bounds) ? box.mergeWith(this.phrase.bounds) : box;
|
|
161
174
|
}
|
|
162
175
|
draw() {
|
|
176
|
+
var _a;
|
|
163
177
|
const ctx = this.checkContext();
|
|
164
178
|
if (!this.formatter || !this.startX || !this.lastY || !this.debugNoteMetricsYs) {
|
|
165
179
|
throw new RuntimeError('NoFormatter', 'format() must be called before draw()');
|
|
166
180
|
}
|
|
167
181
|
this.setRendered();
|
|
182
|
+
(_a = this.phrase) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
|
168
183
|
if (this.options.debugFormatter) {
|
|
169
184
|
Formatter.plotDebugging(ctx, this.formatter, this.startX, this.options.y, this.lastY);
|
|
170
185
|
}
|