vexflow 5.1.2 → 5.3.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 +7 -6
- 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 +5325 -1730
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +4228 -1545
- 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 +13 -3
- package/build/esm/src/articulation.js +51 -20
- package/build/esm/src/beam.js +170 -30
- package/build/esm/src/bend.js +24 -19
- package/build/esm/src/clef.js +3 -0
- package/build/esm/src/clefnote.js +5 -1
- package/build/esm/src/curve.js +27 -53
- package/build/esm/src/dot.js +14 -5
- package/build/esm/src/easyscore/composition.js +336 -0
- package/build/esm/src/easyscore/elementindex.js +81 -0
- package/build/esm/src/easyscore/elements.js +324 -0
- package/build/esm/src/easyscore/policies.js +97 -0
- package/build/esm/src/easyscore/rhythm.js +42 -0
- package/build/esm/src/easyscore.js +448 -26
- package/build/esm/src/element.js +17 -2
- package/build/esm/src/engravinggeometry.js +150 -0
- package/build/esm/src/engravingprofile.js +44 -0
- package/build/esm/src/factory.js +268 -64
- package/build/esm/src/formatter.js +40 -4
- package/build/esm/src/gracenote.js +43 -38
- package/build/esm/src/gracenotegroup.js +53 -56
- package/build/esm/src/index.js +2 -0
- package/build/esm/src/keysignature.js +10 -2
- package/build/esm/src/keysignote.js +2 -2
- package/build/esm/src/modifiercontext.js +11 -0
- package/build/esm/src/note.js +5 -0
- package/build/esm/src/notehead.js +11 -6
- package/build/esm/src/ornament.js +38 -18
- package/build/esm/src/parenthesis.js +1 -1
- package/build/esm/src/parser.js +6 -1
- package/build/esm/src/proportionalformatter.js +234 -0
- package/build/esm/src/registry.js +27 -0
- package/build/esm/src/sheet.js +20 -3
- package/build/esm/src/stave.js +9 -2
- package/build/esm/src/stavenote.js +140 -127
- package/build/esm/src/stavetie.js +39 -7
- package/build/esm/src/stem.js +26 -11
- package/build/esm/src/stemmablenote.js +6 -1
- package/build/esm/src/tickable.js +5 -0
- package/build/esm/src/tickcontext.js +19 -0
- package/build/esm/src/timesignature.js +5 -0
- package/build/esm/src/tuplet.js +60 -19
- package/build/esm/src/version.js +3 -3
- package/build/esm/src/vexflow.js +6 -1
- package/build/esm/tests/beam_tests.js +35 -0
- 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/easyscore_tests.js +40 -0
- package/build/esm/tests/easyscore_types.js +65 -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/studies.mjs +279 -0
- package/build/esm/tests/formatter_tests.js +51 -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/easyscore-rendering-tests.mjs +332 -0
- package/build/esm/tests/node/easyscore-tests.mjs +1024 -0
- package/build/esm/tests/node/engraving-layout-tests.mjs +449 -0
- package/build/esm/tests/node/local-engraving-tests.mjs +128 -0
- package/build/esm/tests/node/proportional-spacing-tests.mjs +278 -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-api-audit.mjs +58 -0
- package/build/esm/tools/easyscore-composition.mjs +62 -0
- package/build/esm/tools/easyscore-example.mjs +16 -0
- package/build/esm/tools/easyscore-families.mjs +61 -0
- package/build/esm/tools/easyscore-references-example.mjs +26 -0
- package/build/esm/tools/easyscore-rhythm.mjs +58 -0
- package/build/esm/tools/easyscore-structure.mjs +88 -0
- package/build/esm/tools/explorer/catalog/entries.mjs +6 -0
- package/build/esm/tools/explorer/catalog/expression.mjs +68 -0
- package/build/esm/tools/explorer/catalog/helpers.mjs +29 -0
- package/build/esm/tools/explorer/catalog/layout.mjs +109 -0
- package/build/esm/tools/explorer/catalog/notes.mjs +61 -0
- package/build/esm/tools/explorer/catalog/staves.mjs +85 -0
- package/build/esm/tools/explorer/catalog/strings.mjs +25 -0
- package/build/esm/tools/explorer/catalog.mjs +14 -0
- package/build/esm/tools/score-fixtures.mjs +23 -6
- package/build/types/src/accidental.d.ts +6 -0
- package/build/types/src/articulation.d.ts +12 -1
- package/build/types/src/beam.d.ts +16 -0
- package/build/types/src/clef.d.ts +2 -0
- package/build/types/src/curve.d.ts +9 -0
- package/build/types/src/dot.d.ts +5 -0
- package/build/types/src/easyscore/composition.d.ts +126 -0
- package/build/types/src/easyscore/elementindex.d.ts +30 -0
- package/build/types/src/easyscore/elements.d.ts +156 -0
- package/build/types/src/easyscore/policies.d.ts +12 -0
- package/build/types/src/easyscore/rhythm.d.ts +9 -0
- package/build/types/src/easyscore.d.ts +153 -11
- package/build/types/src/element.d.ts +7 -1
- 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 +97 -9
- package/build/types/src/formatter.d.ts +7 -1
- package/build/types/src/gracenote.d.ts +7 -0
- package/build/types/src/gracenotegroup.d.ts +7 -2
- package/build/types/src/index.d.ts +2 -0
- package/build/types/src/keysignature.d.ts +3 -0
- package/build/types/src/keysignote.d.ts +1 -1
- package/build/types/src/modifiercontext.d.ts +4 -0
- package/build/types/src/note.d.ts +2 -0
- package/build/types/src/notehead.d.ts +5 -0
- package/build/types/src/ornament.d.ts +7 -0
- package/build/types/src/parser.d.ts +5 -0
- package/build/types/src/proportionalformatter.d.ts +39 -0
- package/build/types/src/registry.d.ts +4 -0
- package/build/types/src/stave.d.ts +2 -0
- package/build/types/src/stavenote.d.ts +21 -3
- package/build/types/src/stavetie.d.ts +4 -0
- package/build/types/src/stem.d.ts +10 -1
- package/build/types/src/stemmablenote.d.ts +6 -1
- package/build/types/src/tickable.d.ts +2 -0
- package/build/types/src/tickcontext.d.ts +5 -0
- package/build/types/src/timesignature.d.ts +2 -0
- package/build/types/src/tuplet.d.ts +5 -48
- package/build/types/src/vexflow.d.ts +6 -1
- package/changelog/CHANGELOG.md +52 -0
- package/package.json +13 -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
package/build/esm/src/factory.js
CHANGED
|
@@ -3,41 +3,66 @@ import { Annotation, AnnotationHorizontalJustify, AnnotationVerticalJustify } fr
|
|
|
3
3
|
import { Articulation } from './articulation.js';
|
|
4
4
|
import { BarNote } from './barnote.js';
|
|
5
5
|
import { Beam } from './beam.js';
|
|
6
|
+
import { Bend } from './bend.js';
|
|
6
7
|
import { ChordSymbol } from './chordsymbol.js';
|
|
8
|
+
import { Clef } from './clef.js';
|
|
7
9
|
import { ClefNote } from './clefnote.js';
|
|
10
|
+
import { Crescendo } from './crescendo.js';
|
|
8
11
|
import { Curve } from './curve.js';
|
|
12
|
+
import { Dot } from './dot.js';
|
|
9
13
|
import { EasyScore } from './easyscore.js';
|
|
14
|
+
import { Element } from './element.js';
|
|
10
15
|
import { Formatter } from './formatter.js';
|
|
11
16
|
import { FretHandFinger } from './frethandfinger.js';
|
|
12
17
|
import { GhostNote } from './ghostnote.js';
|
|
13
18
|
import { GlyphNote } from './glyphnote.js';
|
|
14
19
|
import { GraceNote } from './gracenote.js';
|
|
15
20
|
import { GraceNoteGroup } from './gracenotegroup.js';
|
|
21
|
+
import { GraceTabNote } from './gracetabnote.js';
|
|
22
|
+
import { KeySignature } from './keysignature.js';
|
|
16
23
|
import { KeySigNote } from './keysignote.js';
|
|
24
|
+
import { Modifier } from './modifier.js';
|
|
17
25
|
import { ModifierContext } from './modifiercontext.js';
|
|
18
26
|
import { MultiMeasureRest } from './multimeasurerest.js';
|
|
27
|
+
import { Note } from './note.js';
|
|
19
28
|
import { NoteSubGroup } from './notesubgroup.js';
|
|
20
29
|
import { Ornament } from './ornament.js';
|
|
30
|
+
import { Parenthesis } from './parenthesis.js';
|
|
21
31
|
import { PedalMarking } from './pedalmarking.js';
|
|
32
|
+
import { Registry } from './registry.js';
|
|
22
33
|
import { Renderer } from './renderer.js';
|
|
23
34
|
import { RepeatNote } from './repeatnote.js';
|
|
24
35
|
import { Sheet } from './sheet.js';
|
|
25
36
|
import { Stave } from './stave.js';
|
|
37
|
+
import { Barline } from './stavebarline.js';
|
|
26
38
|
import { StaveConnector } from './staveconnector.js';
|
|
39
|
+
import { StaveHairpin } from './stavehairpin.js';
|
|
27
40
|
import { StaveLine } from './staveline.js';
|
|
41
|
+
import { StaveModifier } from './stavemodifier.js';
|
|
28
42
|
import { StaveNote } from './stavenote.js';
|
|
43
|
+
import { Repetition } from './staverepetition.js';
|
|
44
|
+
import { StaveSection } from './stavesection.js';
|
|
45
|
+
import { StaveTempo } from './stavetempo.js';
|
|
46
|
+
import { StaveText } from './stavetext.js';
|
|
29
47
|
import { StaveTie } from './stavetie.js';
|
|
48
|
+
import { Volta } from './stavevolta.js';
|
|
30
49
|
import { StringNumber } from './stringnumber.js';
|
|
50
|
+
import { Stroke } from './strokes.js';
|
|
31
51
|
import { System } from './system.js';
|
|
32
52
|
import { TabNote } from './tabnote.js';
|
|
53
|
+
import { TabSlide } from './tabslide.js';
|
|
33
54
|
import { TabStave } from './tabstave.js';
|
|
55
|
+
import { TabTie } from './tabtie.js';
|
|
34
56
|
import { TextBracket } from './textbracket.js';
|
|
35
57
|
import { TextDynamics } from './textdynamics.js';
|
|
36
58
|
import { TextNote } from './textnote.js';
|
|
37
59
|
import { TickContext } from './tickcontext.js';
|
|
60
|
+
import { TimeSignature } from './timesignature.js';
|
|
38
61
|
import { TimeSigNote } from './timesignote.js';
|
|
62
|
+
import { Tremolo } from './tremolo.js';
|
|
39
63
|
import { Tuplet } from './tuplet.js';
|
|
40
64
|
import { defined, log, RuntimeError } from './util.js';
|
|
65
|
+
import { Vibrato } from './vibrato.js';
|
|
41
66
|
import { VibratoBracket } from './vibratobracket.js';
|
|
42
67
|
import { Voice } from './voice.js';
|
|
43
68
|
import { isHTMLCanvas } from './web.js';
|
|
@@ -49,8 +74,83 @@ export class Factory {
|
|
|
49
74
|
static newFromElementId(elementId, width = 500, height = 200) {
|
|
50
75
|
return new Factory({ renderer: { elementId, width, height } });
|
|
51
76
|
}
|
|
77
|
+
static getGroup(note) {
|
|
78
|
+
return Factory.groups.get(note);
|
|
79
|
+
}
|
|
80
|
+
static getOwner(element) {
|
|
81
|
+
return Factory.owners.get(element);
|
|
82
|
+
}
|
|
83
|
+
own(element) {
|
|
84
|
+
const owner = Factory.owners.get(element);
|
|
85
|
+
if (owner === this)
|
|
86
|
+
return element;
|
|
87
|
+
if (owner)
|
|
88
|
+
throw new RuntimeError('BadArguments', 'Element belongs to another Factory.');
|
|
89
|
+
Factory.owners.set(element, this);
|
|
90
|
+
this.constructionScopes.forEach((scope) => scope.push(element));
|
|
91
|
+
return element;
|
|
92
|
+
}
|
|
93
|
+
adopt(element, role) {
|
|
94
|
+
const valid = (role === 'note' && element instanceof Note) ||
|
|
95
|
+
(role === 'modifier' && element instanceof Modifier) ||
|
|
96
|
+
(role === 'staveModifier' && element instanceof StaveModifier) ||
|
|
97
|
+
(role === 'drawable' &&
|
|
98
|
+
element instanceof Element &&
|
|
99
|
+
!(element instanceof Note) &&
|
|
100
|
+
!(element instanceof Modifier) &&
|
|
101
|
+
!(element instanceof Voice) &&
|
|
102
|
+
!(element instanceof Stave) &&
|
|
103
|
+
!(element instanceof StaveModifier) &&
|
|
104
|
+
!(element instanceof System));
|
|
105
|
+
if (!valid)
|
|
106
|
+
throw new RuntimeError('BadArguments', `Invalid adopted element role: ${role}`);
|
|
107
|
+
if (element instanceof Note && Factory.groups.has(element)) {
|
|
108
|
+
throw new RuntimeError('BadArguments', 'A grouped note cannot be queued independently.');
|
|
109
|
+
}
|
|
110
|
+
this.own(element);
|
|
111
|
+
if ((role === 'note' || role === 'drawable') && !this.renderQ.includes(element))
|
|
112
|
+
this.renderQ.push(element);
|
|
113
|
+
return element;
|
|
114
|
+
}
|
|
115
|
+
transaction(build) {
|
|
116
|
+
const snapshot = {
|
|
117
|
+
staves: this.staves.slice(),
|
|
118
|
+
voices: this.voices.slice(),
|
|
119
|
+
renderQ: this.renderQ.slice(),
|
|
120
|
+
systems: this.systems.slice(),
|
|
121
|
+
sheets: this.sheets.slice(),
|
|
122
|
+
stave: this.stave,
|
|
123
|
+
retained: this.retained,
|
|
124
|
+
};
|
|
125
|
+
const created = [];
|
|
126
|
+
const grouped = [];
|
|
127
|
+
this.constructionScopes.push(created);
|
|
128
|
+
this.groupScopes.push(grouped);
|
|
129
|
+
const run = () => {
|
|
130
|
+
try {
|
|
131
|
+
return build();
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
Object.assign(this, snapshot);
|
|
135
|
+
created.forEach((element) => Factory.owners.delete(element));
|
|
136
|
+
grouped
|
|
137
|
+
.slice()
|
|
138
|
+
.reverse()
|
|
139
|
+
.forEach((restore) => restore());
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
finally {
|
|
143
|
+
this.constructionScopes.pop();
|
|
144
|
+
this.groupScopes.pop();
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
const registry = Registry.getDefaultRegistry();
|
|
148
|
+
return registry ? registry.transaction(run) : run();
|
|
149
|
+
}
|
|
52
150
|
constructor(options = {}) {
|
|
53
151
|
this.retained = false;
|
|
152
|
+
this.constructionScopes = [];
|
|
153
|
+
this.groupScopes = [];
|
|
54
154
|
this.style = {};
|
|
55
155
|
L('New factory: ', options);
|
|
56
156
|
this.options = {
|
|
@@ -130,7 +230,7 @@ export class Factory {
|
|
|
130
230
|
this.staves.push(stave);
|
|
131
231
|
stave.setContext(this.context);
|
|
132
232
|
this.stave = stave;
|
|
133
|
-
return stave;
|
|
233
|
+
return this.own(stave);
|
|
134
234
|
}
|
|
135
235
|
TabStave(params) {
|
|
136
236
|
const staveSpace = this.options.stave.space;
|
|
@@ -139,15 +239,62 @@ export class Factory {
|
|
|
139
239
|
this.staves.push(stave);
|
|
140
240
|
stave.setContext(this.context);
|
|
141
241
|
this.stave = stave;
|
|
142
|
-
return stave;
|
|
242
|
+
return this.own(stave);
|
|
243
|
+
}
|
|
244
|
+
Bend(...args) {
|
|
245
|
+
return this.adopt(new Bend(...args).setContext(this.context), 'modifier');
|
|
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
|
+
}
|
|
252
|
+
Clef(...args) {
|
|
253
|
+
return this.adopt(this.musicGlyph(new Clef(...args)).setContext(this.context), 'staveModifier');
|
|
254
|
+
}
|
|
255
|
+
KeySignature(...args) {
|
|
256
|
+
return this.adopt(this.musicGlyph(new KeySignature(...args)).setContext(this.context), 'staveModifier');
|
|
257
|
+
}
|
|
258
|
+
TimeSignature(...args) {
|
|
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');
|
|
263
|
+
}
|
|
264
|
+
Barline(...args) {
|
|
265
|
+
return this.adopt(new Barline(...args).setContext(this.context), 'staveModifier');
|
|
266
|
+
}
|
|
267
|
+
Repetition(...args) {
|
|
268
|
+
return this.adopt(new Repetition(...args).setContext(this.context), 'staveModifier');
|
|
269
|
+
}
|
|
270
|
+
Volta(...args) {
|
|
271
|
+
return this.adopt(new Volta(...args).setContext(this.context), 'staveModifier');
|
|
272
|
+
}
|
|
273
|
+
StaveSection(...args) {
|
|
274
|
+
return this.adopt(new StaveSection(...args).setContext(this.context), 'staveModifier');
|
|
275
|
+
}
|
|
276
|
+
StaveTempo(...args) {
|
|
277
|
+
return this.adopt(new StaveTempo(...args).setContext(this.context), 'staveModifier');
|
|
278
|
+
}
|
|
279
|
+
StaveText(...args) {
|
|
280
|
+
return this.adopt(new StaveText(...args).setContext(this.context), 'staveModifier');
|
|
281
|
+
}
|
|
282
|
+
TabTie(...args) {
|
|
283
|
+
return this.adopt(new TabTie(...args).setContext(this.context), 'drawable');
|
|
284
|
+
}
|
|
285
|
+
TabSlide(...args) {
|
|
286
|
+
return this.adopt(new TabSlide(...args).setContext(this.context), 'drawable');
|
|
287
|
+
}
|
|
288
|
+
GraceTabNote(options) {
|
|
289
|
+
return this.own(new GraceTabNote(options).setContext(this.context));
|
|
143
290
|
}
|
|
144
291
|
StaveNote(noteStruct) {
|
|
145
|
-
const note = new StaveNote(noteStruct);
|
|
292
|
+
const note = new StaveNote(Object.assign({ engraving: this.options.engraving }, noteStruct));
|
|
146
293
|
if (this.stave)
|
|
147
294
|
note.setStave(this.stave);
|
|
148
295
|
note.setContext(this.context);
|
|
149
296
|
this.renderQ.push(note);
|
|
150
|
-
return note;
|
|
297
|
+
return this.own(note);
|
|
151
298
|
}
|
|
152
299
|
GlyphNote(glyph, noteStruct, options) {
|
|
153
300
|
const note = new GlyphNote(glyph, noteStruct, options);
|
|
@@ -155,7 +302,7 @@ export class Factory {
|
|
|
155
302
|
note.setStave(this.stave);
|
|
156
303
|
note.setContext(this.context);
|
|
157
304
|
this.renderQ.push(note);
|
|
158
|
-
return note;
|
|
305
|
+
return this.own(note);
|
|
159
306
|
}
|
|
160
307
|
RepeatNote(type, noteStruct, options) {
|
|
161
308
|
const note = new RepeatNote(type, noteStruct, options);
|
|
@@ -163,7 +310,7 @@ export class Factory {
|
|
|
163
310
|
note.setStave(this.stave);
|
|
164
311
|
note.setContext(this.context);
|
|
165
312
|
this.renderQ.push(note);
|
|
166
|
-
return note;
|
|
313
|
+
return this.own(note);
|
|
167
314
|
}
|
|
168
315
|
GhostNote(noteStruct) {
|
|
169
316
|
const ghostNote = new GhostNote(noteStruct);
|
|
@@ -171,7 +318,7 @@ export class Factory {
|
|
|
171
318
|
ghostNote.setStave(this.stave);
|
|
172
319
|
ghostNote.setContext(this.context);
|
|
173
320
|
this.renderQ.push(ghostNote);
|
|
174
|
-
return ghostNote;
|
|
321
|
+
return this.own(ghostNote);
|
|
175
322
|
}
|
|
176
323
|
TextNote(noteStruct) {
|
|
177
324
|
const textNote = new TextNote(noteStruct);
|
|
@@ -179,7 +326,7 @@ export class Factory {
|
|
|
179
326
|
textNote.setStave(this.stave);
|
|
180
327
|
textNote.setContext(this.context);
|
|
181
328
|
this.renderQ.push(textNote);
|
|
182
|
-
return textNote;
|
|
329
|
+
return this.own(textNote);
|
|
183
330
|
}
|
|
184
331
|
BarNote(params = {}) {
|
|
185
332
|
const barNote = new BarNote(params.type);
|
|
@@ -187,19 +334,16 @@ export class Factory {
|
|
|
187
334
|
barNote.setStave(this.stave);
|
|
188
335
|
barNote.setContext(this.context);
|
|
189
336
|
this.renderQ.push(barNote);
|
|
190
|
-
return barNote;
|
|
337
|
+
return this.own(barNote);
|
|
191
338
|
}
|
|
192
339
|
ClefNote(params) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
annotation: undefined,
|
|
196
|
-
} }, params);
|
|
197
|
-
const clefNote = new ClefNote(p.type, p.options.size, p.options.annotation);
|
|
340
|
+
var _a, _b, _c;
|
|
341
|
+
const clefNote = new ClefNote((_a = params === null || params === void 0 ? void 0 : params.type) !== null && _a !== void 0 ? _a : 'treble', (_b = params === null || params === void 0 ? void 0 : params.options) === null || _b === void 0 ? void 0 : _b.size, (_c = params === null || params === void 0 ? void 0 : params.options) === null || _c === void 0 ? void 0 : _c.annotation);
|
|
198
342
|
if (this.stave)
|
|
199
343
|
clefNote.setStave(this.stave);
|
|
200
344
|
clefNote.setContext(this.context);
|
|
201
345
|
this.renderQ.push(clefNote);
|
|
202
|
-
return clefNote;
|
|
346
|
+
return this.own(clefNote);
|
|
203
347
|
}
|
|
204
348
|
TimeSigNote(params) {
|
|
205
349
|
const p = Object.assign({ time: '4/4' }, params);
|
|
@@ -208,40 +352,38 @@ export class Factory {
|
|
|
208
352
|
timeSigNote.setStave(this.stave);
|
|
209
353
|
timeSigNote.setContext(this.context);
|
|
210
354
|
this.renderQ.push(timeSigNote);
|
|
211
|
-
return timeSigNote;
|
|
355
|
+
return this.own(timeSigNote);
|
|
212
356
|
}
|
|
213
357
|
KeySigNote(params) {
|
|
214
|
-
const keySigNote = new KeySigNote(params.key, params.cancelKey, params.alterKey);
|
|
358
|
+
const keySigNote = new KeySigNote(params.key, params.cancelKey, params.alterKey, params.clef);
|
|
215
359
|
if (this.stave)
|
|
216
360
|
keySigNote.setStave(this.stave);
|
|
217
361
|
keySigNote.setContext(this.context);
|
|
218
362
|
this.renderQ.push(keySigNote);
|
|
219
|
-
return keySigNote;
|
|
363
|
+
return this.own(keySigNote);
|
|
220
364
|
}
|
|
221
|
-
TabNote(noteStruct) {
|
|
222
|
-
const note = new TabNote(noteStruct);
|
|
365
|
+
TabNote(noteStruct, drawStem = false) {
|
|
366
|
+
const note = new TabNote(noteStruct, drawStem);
|
|
223
367
|
if (this.stave)
|
|
224
368
|
note.setStave(this.stave);
|
|
225
369
|
note.setContext(this.context);
|
|
226
370
|
this.renderQ.push(note);
|
|
227
|
-
return note;
|
|
371
|
+
return this.own(note);
|
|
228
372
|
}
|
|
229
373
|
GraceNote(noteStruct) {
|
|
230
|
-
const note = new GraceNote(noteStruct);
|
|
374
|
+
const note = new GraceNote(Object.assign({ engraving: this.options.engraving }, noteStruct));
|
|
231
375
|
if (this.stave)
|
|
232
376
|
note.setStave(this.stave);
|
|
233
377
|
note.setContext(this.context);
|
|
234
|
-
return note;
|
|
378
|
+
return this.own(note);
|
|
235
379
|
}
|
|
236
380
|
GraceNoteGroup(params) {
|
|
237
|
-
|
|
238
|
-
group.setContext(this.context);
|
|
239
|
-
return group;
|
|
381
|
+
return this.own(new GraceNoteGroup(params.notes, params.slur).setContext(this.context));
|
|
240
382
|
}
|
|
241
383
|
Accidental(params) {
|
|
242
|
-
const accid = new Accidental(params.type);
|
|
384
|
+
const accid = this.musicGlyph(new Accidental(params.type));
|
|
243
385
|
accid.setContext(this.context);
|
|
244
|
-
return accid;
|
|
386
|
+
return this.own(accid);
|
|
245
387
|
}
|
|
246
388
|
Annotation(params) {
|
|
247
389
|
const p = Object.assign({ text: 'p', hJustify: AnnotationHorizontalJustify.CENTER, vJustify: AnnotationVerticalJustify.BOTTOM }, params);
|
|
@@ -250,7 +392,7 @@ export class Factory {
|
|
|
250
392
|
annotation.setVerticalJustification(p.vJustify);
|
|
251
393
|
annotation.setFont(p.font);
|
|
252
394
|
annotation.setContext(this.context);
|
|
253
|
-
return annotation;
|
|
395
|
+
return this.own(annotation);
|
|
254
396
|
}
|
|
255
397
|
ChordSymbol(params) {
|
|
256
398
|
const p = Object.assign({ vJustify: 'top', hJustify: 'center' }, params);
|
|
@@ -267,17 +409,17 @@ export class Factory {
|
|
|
267
409
|
chordSymbol.setFontSize(p.fontSize);
|
|
268
410
|
}
|
|
269
411
|
chordSymbol.setContext(this.context);
|
|
270
|
-
return chordSymbol;
|
|
412
|
+
return this.own(chordSymbol);
|
|
271
413
|
}
|
|
272
414
|
Articulation(params) {
|
|
273
415
|
var _a;
|
|
274
|
-
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.'));
|
|
275
417
|
if ((params === null || params === void 0 ? void 0 : params.position) !== undefined)
|
|
276
418
|
articulation.setPosition(params.position);
|
|
277
419
|
if ((params === null || params === void 0 ? void 0 : params.betweenLines) !== undefined)
|
|
278
420
|
articulation.setBetweenLines(params.betweenLines);
|
|
279
421
|
articulation.setContext(this.context);
|
|
280
|
-
return articulation;
|
|
422
|
+
return this.own(articulation);
|
|
281
423
|
}
|
|
282
424
|
Ornament(type, params) {
|
|
283
425
|
const options = Object.assign({ type, accidental: '' }, params);
|
|
@@ -295,35 +437,29 @@ export class Factory {
|
|
|
295
437
|
ornament.setDelayed(options.delayed);
|
|
296
438
|
}
|
|
297
439
|
ornament.setContext(this.context);
|
|
298
|
-
return ornament;
|
|
440
|
+
return this.own(ornament);
|
|
299
441
|
}
|
|
300
442
|
TextDynamics(params) {
|
|
301
|
-
const
|
|
302
|
-
const text = new TextDynamics({
|
|
303
|
-
text: p.text,
|
|
304
|
-
line: p.line,
|
|
305
|
-
duration: p.duration,
|
|
306
|
-
dots: p.dots,
|
|
307
|
-
});
|
|
443
|
+
const text = new TextDynamics(Object.assign({ text: 'p', duration: 'q', dots: 0, line: 0 }, params));
|
|
308
444
|
if (this.stave)
|
|
309
445
|
text.setStave(this.stave);
|
|
310
446
|
text.setContext(this.context);
|
|
311
447
|
this.renderQ.push(text);
|
|
312
|
-
return text;
|
|
448
|
+
return this.own(text);
|
|
313
449
|
}
|
|
314
450
|
Fingering(params) {
|
|
315
451
|
const p = Object.assign({ number: '0', position: 'left' }, params);
|
|
316
452
|
const fingering = new FretHandFinger(p.number);
|
|
317
453
|
fingering.setPosition(p.position);
|
|
318
454
|
fingering.setContext(this.context);
|
|
319
|
-
return fingering;
|
|
455
|
+
return this.own(fingering);
|
|
320
456
|
}
|
|
321
457
|
StringNumber(params, drawCircle = true) {
|
|
322
458
|
const stringNumber = new StringNumber(params.number);
|
|
323
459
|
stringNumber.setPosition(params.position);
|
|
324
460
|
stringNumber.setContext(this.context);
|
|
325
461
|
stringNumber.setDrawCircle(drawCircle);
|
|
326
|
-
return stringNumber;
|
|
462
|
+
return this.own(stringNumber);
|
|
327
463
|
}
|
|
328
464
|
TickContext() {
|
|
329
465
|
return new TickContext();
|
|
@@ -336,19 +472,19 @@ export class Factory {
|
|
|
336
472
|
const multiMeasureRest = new MultiMeasureRest(numMeasures, params);
|
|
337
473
|
multiMeasureRest.setContext(this.context);
|
|
338
474
|
this.renderQ.push(multiMeasureRest);
|
|
339
|
-
return multiMeasureRest;
|
|
475
|
+
return this.own(multiMeasureRest);
|
|
340
476
|
}
|
|
341
477
|
Voice(params) {
|
|
342
478
|
const p = Object.assign({ time: '4/4' }, params);
|
|
343
479
|
const voice = new Voice(p.time);
|
|
344
480
|
this.voices.push(voice);
|
|
345
|
-
return voice;
|
|
481
|
+
return this.own(voice);
|
|
346
482
|
}
|
|
347
483
|
StaveConnector(params) {
|
|
348
484
|
const connector = new StaveConnector(params.topStave, params.bottomStave);
|
|
349
485
|
connector.setType(params.type).setContext(this.context);
|
|
350
486
|
this.renderQ.push(connector);
|
|
351
|
-
return connector;
|
|
487
|
+
return this.own(connector);
|
|
352
488
|
}
|
|
353
489
|
Formatter(options) {
|
|
354
490
|
return new Formatter(options);
|
|
@@ -357,7 +493,7 @@ export class Factory {
|
|
|
357
493
|
const p = Object.assign({ notes: [], options: {} }, params);
|
|
358
494
|
const tuplet = new Tuplet(p.notes, p.options).setContext(this.context);
|
|
359
495
|
this.renderQ.push(tuplet);
|
|
360
|
-
return tuplet;
|
|
496
|
+
return this.own(tuplet);
|
|
361
497
|
}
|
|
362
498
|
Beam(params) {
|
|
363
499
|
var _a, _b, _c, _d, _e;
|
|
@@ -369,12 +505,12 @@ export class Factory {
|
|
|
369
505
|
});
|
|
370
506
|
}
|
|
371
507
|
this.renderQ.push(beam);
|
|
372
|
-
return beam;
|
|
508
|
+
return this.own(beam);
|
|
373
509
|
}
|
|
374
510
|
Curve(params) {
|
|
375
511
|
const curve = new Curve(params.from, params.to, params.options).setContext(this.context);
|
|
376
512
|
this.renderQ.push(curve);
|
|
377
|
-
return curve;
|
|
513
|
+
return this.own(curve);
|
|
378
514
|
}
|
|
379
515
|
StaveTie(params) {
|
|
380
516
|
var _a;
|
|
@@ -388,7 +524,7 @@ export class Factory {
|
|
|
388
524
|
tie.setDirection(params.options.direction);
|
|
389
525
|
tie.setContext(this.context);
|
|
390
526
|
this.renderQ.push(tie);
|
|
391
|
-
return tie;
|
|
527
|
+
return this.own(tie);
|
|
392
528
|
}
|
|
393
529
|
StaveLine(params) {
|
|
394
530
|
var _a, _b;
|
|
@@ -404,20 +540,20 @@ export class Factory {
|
|
|
404
540
|
line.setFont(params.options.font);
|
|
405
541
|
line.setContext(this.context);
|
|
406
542
|
this.renderQ.push(line);
|
|
407
|
-
return line;
|
|
543
|
+
return this.own(line);
|
|
408
544
|
}
|
|
409
545
|
VibratoBracket(params) {
|
|
410
546
|
const vibratoBracket = new VibratoBracket({
|
|
411
547
|
start: params.from,
|
|
412
548
|
stop: params.to,
|
|
413
549
|
});
|
|
414
|
-
if (params.options.line)
|
|
550
|
+
if (params.options.line !== undefined)
|
|
415
551
|
vibratoBracket.setLine(params.options.line);
|
|
416
|
-
if (params.options.code)
|
|
552
|
+
if (params.options.code !== undefined)
|
|
417
553
|
vibratoBracket.setVibratoCode(params.options.code);
|
|
418
554
|
vibratoBracket.setContext(this.context);
|
|
419
555
|
this.renderQ.push(vibratoBracket);
|
|
420
|
-
return vibratoBracket;
|
|
556
|
+
return this.own(vibratoBracket);
|
|
421
557
|
}
|
|
422
558
|
TextBracket(params) {
|
|
423
559
|
const textBracket = new TextBracket({
|
|
@@ -427,23 +563,21 @@ export class Factory {
|
|
|
427
563
|
superscript: params.options.superscript,
|
|
428
564
|
position: params.options.position,
|
|
429
565
|
});
|
|
430
|
-
if (params.options.line)
|
|
566
|
+
if (params.options.line !== undefined)
|
|
431
567
|
textBracket.setLine(params.options.line);
|
|
432
568
|
if (params.options.font)
|
|
433
569
|
textBracket.setFont(params.options.font);
|
|
434
570
|
textBracket.setContext(this.context);
|
|
435
571
|
this.renderQ.push(textBracket);
|
|
436
|
-
return textBracket;
|
|
572
|
+
return this.own(textBracket);
|
|
437
573
|
}
|
|
438
574
|
System(params = {}) {
|
|
439
|
-
params
|
|
440
|
-
const system = new System(params).setContext(this.context);
|
|
575
|
+
const system = new System(Object.assign(Object.assign({}, params), { factory: this })).setContext(this.context);
|
|
441
576
|
this.systems.push(system);
|
|
442
|
-
return system;
|
|
577
|
+
return this.own(system);
|
|
443
578
|
}
|
|
444
579
|
EasyScore(options = {}) {
|
|
445
|
-
options
|
|
446
|
-
return new EasyScore(options);
|
|
580
|
+
return new EasyScore(Object.assign(Object.assign({}, options), { factory: this }));
|
|
447
581
|
}
|
|
448
582
|
PedalMarking(params) {
|
|
449
583
|
const p = Object.assign({ notes: [], options: {
|
|
@@ -453,14 +587,82 @@ export class Factory {
|
|
|
453
587
|
pedal.setType(PedalMarking.typeString[p.options.style]);
|
|
454
588
|
pedal.setContext(this.context);
|
|
455
589
|
this.renderQ.push(pedal);
|
|
456
|
-
return pedal;
|
|
590
|
+
return this.own(pedal);
|
|
457
591
|
}
|
|
458
592
|
NoteSubGroup(params) {
|
|
459
593
|
const p = Object.assign({ notes: [] }, params);
|
|
460
|
-
|
|
461
|
-
|
|
594
|
+
return this.own(new NoteSubGroup(p.notes).setContext(this.context));
|
|
595
|
+
}
|
|
596
|
+
groupNotes(notes, construct) {
|
|
597
|
+
if (!notes.length || new Set(notes).size !== notes.length) {
|
|
598
|
+
throw new RuntimeError('BadArguments', 'A note group needs distinct notes.');
|
|
599
|
+
}
|
|
600
|
+
notes.forEach((note) => {
|
|
601
|
+
const owner = Factory.getOwner(note);
|
|
602
|
+
if (owner && owner !== this)
|
|
603
|
+
throw new RuntimeError('BadArguments', 'Group note belongs to another Factory.');
|
|
604
|
+
if (Factory.groups.has(note))
|
|
605
|
+
throw new RuntimeError('BadArguments', 'Note already belongs to a group.');
|
|
606
|
+
let voice;
|
|
607
|
+
try {
|
|
608
|
+
voice = note.getVoice();
|
|
609
|
+
}
|
|
610
|
+
catch (error) {
|
|
611
|
+
if (!(error instanceof RuntimeError) || error.code !== 'NoVoice')
|
|
612
|
+
throw error;
|
|
613
|
+
}
|
|
614
|
+
if (voice)
|
|
615
|
+
throw new RuntimeError('BadArguments', 'A voiced note cannot be moved into a group.');
|
|
616
|
+
});
|
|
617
|
+
const ignored = notes.map((note) => note.shouldIgnoreTicks());
|
|
618
|
+
const restore = () => notes.forEach((note, index) => {
|
|
619
|
+
Factory.groups.delete(note);
|
|
620
|
+
note.clearVoice().setIgnoreTicks(ignored[index]);
|
|
621
|
+
});
|
|
622
|
+
let group;
|
|
623
|
+
try {
|
|
624
|
+
group = this.own(construct().setContext(this.context));
|
|
625
|
+
}
|
|
626
|
+
catch (error) {
|
|
627
|
+
restore();
|
|
628
|
+
throw error;
|
|
629
|
+
}
|
|
630
|
+
this.groupScopes.forEach((scope) => scope.push(restore));
|
|
631
|
+
notes.forEach((note) => {
|
|
632
|
+
this.own(note);
|
|
633
|
+
Factory.groups.set(note, group);
|
|
634
|
+
});
|
|
635
|
+
this.renderQ = this.renderQ.filter((element) => !notes.includes(element));
|
|
462
636
|
return group;
|
|
463
637
|
}
|
|
638
|
+
Dot(...args) {
|
|
639
|
+
return this.adopt(new Dot(...args).setContext(this.context), 'modifier');
|
|
640
|
+
}
|
|
641
|
+
Parenthesis(...args) {
|
|
642
|
+
return this.adopt(new Parenthesis(...args).setContext(this.context), 'modifier');
|
|
643
|
+
}
|
|
644
|
+
Stroke(...args) {
|
|
645
|
+
return this.adopt(new Stroke(...args).setContext(this.context), 'modifier');
|
|
646
|
+
}
|
|
647
|
+
Tremolo(...args) {
|
|
648
|
+
return this.adopt(new Tremolo(...args).setContext(this.context), 'modifier');
|
|
649
|
+
}
|
|
650
|
+
Vibrato(...args) {
|
|
651
|
+
return this.adopt(new Vibrato(...args).setContext(this.context), 'modifier');
|
|
652
|
+
}
|
|
653
|
+
Crescendo(...args) {
|
|
654
|
+
const note = new Crescendo(...args).setContext(this.context);
|
|
655
|
+
if (this.stave)
|
|
656
|
+
note.setStave(this.stave);
|
|
657
|
+
return this.adopt(note, 'note');
|
|
658
|
+
}
|
|
659
|
+
StaveHairpin(params) {
|
|
660
|
+
const notes = Object.assign(Object.assign({}, (params.from && { firstNote: params.from })), (params.to && { lastNote: params.to }));
|
|
661
|
+
const hairpin = new StaveHairpin(notes, params.type).setContext(this.context);
|
|
662
|
+
if (params.options)
|
|
663
|
+
hairpin.setRenderOptions(Object.assign(Object.assign({}, hairpin.renderOptions), params.options));
|
|
664
|
+
return this.adopt(hairpin, 'drawable');
|
|
665
|
+
}
|
|
464
666
|
draw(options = {}) {
|
|
465
667
|
var _a;
|
|
466
668
|
const ctx = this.context;
|
|
@@ -498,3 +700,5 @@ export class Factory {
|
|
|
498
700
|
}
|
|
499
701
|
}
|
|
500
702
|
Factory.DEBUG = false;
|
|
703
|
+
Factory.owners = new WeakMap();
|
|
704
|
+
Factory.groups = new WeakMap();
|