vexflow 5.1.2 → 5.2.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 +2633 -415
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +2478 -382
- 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 +3 -0
- package/build/esm/src/articulation.js +27 -14
- package/build/esm/src/beam.js +12 -2
- package/build/esm/src/clef.js +3 -0
- package/build/esm/src/clefnote.js +5 -1
- package/build/esm/src/dot.js +1 -1
- package/build/esm/src/easyscore/composition.js +297 -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 +69 -0
- package/build/esm/src/easyscore/rhythm.js +42 -0
- package/build/esm/src/easyscore.js +448 -26
- package/build/esm/src/element.js +13 -2
- package/build/esm/src/factory.js +256 -60
- package/build/esm/src/formatter.js +32 -4
- package/build/esm/src/keysignature.js +9 -1
- package/build/esm/src/keysignote.js +2 -2
- package/build/esm/src/note.js +5 -0
- package/build/esm/src/parenthesis.js +1 -1
- package/build/esm/src/parser.js +6 -1
- package/build/esm/src/proportionalformatter.js +186 -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 +12 -12
- package/build/esm/src/stemmablenote.js +6 -1
- package/build/esm/src/tickable.js +5 -0
- package/build/esm/src/tuplet.js +3 -2
- package/build/esm/src/version.js +3 -3
- package/build/esm/src/vexflow.js +2 -1
- package/build/esm/tests/beam_tests.js +35 -0
- package/build/esm/tests/easyscore_tests.js +40 -0
- package/build/esm/tests/easyscore_types.js +65 -0
- package/build/esm/tests/formatter_tests.js +41 -0
- package/build/esm/tests/node/easyscore-rendering-tests.mjs +332 -0
- package/build/esm/tests/node/easyscore-tests.mjs +953 -0
- package/build/esm/tests/node/proportional-spacing-tests.mjs +214 -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/types/src/accidental.d.ts +2 -0
- package/build/types/src/articulation.d.ts +6 -0
- package/build/types/src/beam.d.ts +2 -0
- package/build/types/src/clef.d.ts +2 -0
- package/build/types/src/easyscore/composition.d.ts +107 -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 +5 -1
- package/build/types/src/factory.d.ts +91 -8
- package/build/types/src/formatter.d.ts +7 -1
- package/build/types/src/keysignature.d.ts +3 -0
- package/build/types/src/keysignote.d.ts +1 -1
- package/build/types/src/note.d.ts +2 -0
- package/build/types/src/parser.d.ts +5 -0
- package/build/types/src/proportionalformatter.d.ts +30 -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 +1 -1
- package/build/types/src/stemmablenote.d.ts +6 -1
- package/build/types/src/tickable.d.ts +2 -0
- package/build/types/src/vexflow.d.ts +2 -1
- package/changelog/CHANGELOG.md +35 -0
- package/package.json +7 -2
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,7 +239,46 @@ 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
|
+
Clef(...args) {
|
|
248
|
+
return this.adopt(new Clef(...args).setContext(this.context), 'staveModifier');
|
|
249
|
+
}
|
|
250
|
+
KeySignature(...args) {
|
|
251
|
+
return this.adopt(new KeySignature(...args).setContext(this.context), 'staveModifier');
|
|
252
|
+
}
|
|
253
|
+
TimeSignature(...args) {
|
|
254
|
+
return this.adopt(new TimeSignature(...args).setContext(this.context), 'staveModifier');
|
|
255
|
+
}
|
|
256
|
+
Barline(...args) {
|
|
257
|
+
return this.adopt(new Barline(...args).setContext(this.context), 'staveModifier');
|
|
258
|
+
}
|
|
259
|
+
Repetition(...args) {
|
|
260
|
+
return this.adopt(new Repetition(...args).setContext(this.context), 'staveModifier');
|
|
261
|
+
}
|
|
262
|
+
Volta(...args) {
|
|
263
|
+
return this.adopt(new Volta(...args).setContext(this.context), 'staveModifier');
|
|
264
|
+
}
|
|
265
|
+
StaveSection(...args) {
|
|
266
|
+
return this.adopt(new StaveSection(...args).setContext(this.context), 'staveModifier');
|
|
267
|
+
}
|
|
268
|
+
StaveTempo(...args) {
|
|
269
|
+
return this.adopt(new StaveTempo(...args).setContext(this.context), 'staveModifier');
|
|
270
|
+
}
|
|
271
|
+
StaveText(...args) {
|
|
272
|
+
return this.adopt(new StaveText(...args).setContext(this.context), 'staveModifier');
|
|
273
|
+
}
|
|
274
|
+
TabTie(...args) {
|
|
275
|
+
return this.adopt(new TabTie(...args).setContext(this.context), 'drawable');
|
|
276
|
+
}
|
|
277
|
+
TabSlide(...args) {
|
|
278
|
+
return this.adopt(new TabSlide(...args).setContext(this.context), 'drawable');
|
|
279
|
+
}
|
|
280
|
+
GraceTabNote(options) {
|
|
281
|
+
return this.own(new GraceTabNote(options).setContext(this.context));
|
|
143
282
|
}
|
|
144
283
|
StaveNote(noteStruct) {
|
|
145
284
|
const note = new StaveNote(noteStruct);
|
|
@@ -147,7 +286,7 @@ export class Factory {
|
|
|
147
286
|
note.setStave(this.stave);
|
|
148
287
|
note.setContext(this.context);
|
|
149
288
|
this.renderQ.push(note);
|
|
150
|
-
return note;
|
|
289
|
+
return this.own(note);
|
|
151
290
|
}
|
|
152
291
|
GlyphNote(glyph, noteStruct, options) {
|
|
153
292
|
const note = new GlyphNote(glyph, noteStruct, options);
|
|
@@ -155,7 +294,7 @@ export class Factory {
|
|
|
155
294
|
note.setStave(this.stave);
|
|
156
295
|
note.setContext(this.context);
|
|
157
296
|
this.renderQ.push(note);
|
|
158
|
-
return note;
|
|
297
|
+
return this.own(note);
|
|
159
298
|
}
|
|
160
299
|
RepeatNote(type, noteStruct, options) {
|
|
161
300
|
const note = new RepeatNote(type, noteStruct, options);
|
|
@@ -163,7 +302,7 @@ export class Factory {
|
|
|
163
302
|
note.setStave(this.stave);
|
|
164
303
|
note.setContext(this.context);
|
|
165
304
|
this.renderQ.push(note);
|
|
166
|
-
return note;
|
|
305
|
+
return this.own(note);
|
|
167
306
|
}
|
|
168
307
|
GhostNote(noteStruct) {
|
|
169
308
|
const ghostNote = new GhostNote(noteStruct);
|
|
@@ -171,7 +310,7 @@ export class Factory {
|
|
|
171
310
|
ghostNote.setStave(this.stave);
|
|
172
311
|
ghostNote.setContext(this.context);
|
|
173
312
|
this.renderQ.push(ghostNote);
|
|
174
|
-
return ghostNote;
|
|
313
|
+
return this.own(ghostNote);
|
|
175
314
|
}
|
|
176
315
|
TextNote(noteStruct) {
|
|
177
316
|
const textNote = new TextNote(noteStruct);
|
|
@@ -179,7 +318,7 @@ export class Factory {
|
|
|
179
318
|
textNote.setStave(this.stave);
|
|
180
319
|
textNote.setContext(this.context);
|
|
181
320
|
this.renderQ.push(textNote);
|
|
182
|
-
return textNote;
|
|
321
|
+
return this.own(textNote);
|
|
183
322
|
}
|
|
184
323
|
BarNote(params = {}) {
|
|
185
324
|
const barNote = new BarNote(params.type);
|
|
@@ -187,19 +326,16 @@ export class Factory {
|
|
|
187
326
|
barNote.setStave(this.stave);
|
|
188
327
|
barNote.setContext(this.context);
|
|
189
328
|
this.renderQ.push(barNote);
|
|
190
|
-
return barNote;
|
|
329
|
+
return this.own(barNote);
|
|
191
330
|
}
|
|
192
331
|
ClefNote(params) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
annotation: undefined,
|
|
196
|
-
} }, params);
|
|
197
|
-
const clefNote = new ClefNote(p.type, p.options.size, p.options.annotation);
|
|
332
|
+
var _a, _b, _c;
|
|
333
|
+
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
334
|
if (this.stave)
|
|
199
335
|
clefNote.setStave(this.stave);
|
|
200
336
|
clefNote.setContext(this.context);
|
|
201
337
|
this.renderQ.push(clefNote);
|
|
202
|
-
return clefNote;
|
|
338
|
+
return this.own(clefNote);
|
|
203
339
|
}
|
|
204
340
|
TimeSigNote(params) {
|
|
205
341
|
const p = Object.assign({ time: '4/4' }, params);
|
|
@@ -208,40 +344,38 @@ export class Factory {
|
|
|
208
344
|
timeSigNote.setStave(this.stave);
|
|
209
345
|
timeSigNote.setContext(this.context);
|
|
210
346
|
this.renderQ.push(timeSigNote);
|
|
211
|
-
return timeSigNote;
|
|
347
|
+
return this.own(timeSigNote);
|
|
212
348
|
}
|
|
213
349
|
KeySigNote(params) {
|
|
214
|
-
const keySigNote = new KeySigNote(params.key, params.cancelKey, params.alterKey);
|
|
350
|
+
const keySigNote = new KeySigNote(params.key, params.cancelKey, params.alterKey, params.clef);
|
|
215
351
|
if (this.stave)
|
|
216
352
|
keySigNote.setStave(this.stave);
|
|
217
353
|
keySigNote.setContext(this.context);
|
|
218
354
|
this.renderQ.push(keySigNote);
|
|
219
|
-
return keySigNote;
|
|
355
|
+
return this.own(keySigNote);
|
|
220
356
|
}
|
|
221
|
-
TabNote(noteStruct) {
|
|
222
|
-
const note = new TabNote(noteStruct);
|
|
357
|
+
TabNote(noteStruct, drawStem = false) {
|
|
358
|
+
const note = new TabNote(noteStruct, drawStem);
|
|
223
359
|
if (this.stave)
|
|
224
360
|
note.setStave(this.stave);
|
|
225
361
|
note.setContext(this.context);
|
|
226
362
|
this.renderQ.push(note);
|
|
227
|
-
return note;
|
|
363
|
+
return this.own(note);
|
|
228
364
|
}
|
|
229
365
|
GraceNote(noteStruct) {
|
|
230
366
|
const note = new GraceNote(noteStruct);
|
|
231
367
|
if (this.stave)
|
|
232
368
|
note.setStave(this.stave);
|
|
233
369
|
note.setContext(this.context);
|
|
234
|
-
return note;
|
|
370
|
+
return this.own(note);
|
|
235
371
|
}
|
|
236
372
|
GraceNoteGroup(params) {
|
|
237
|
-
|
|
238
|
-
group.setContext(this.context);
|
|
239
|
-
return group;
|
|
373
|
+
return this.own(new GraceNoteGroup(params.notes, params.slur).setContext(this.context));
|
|
240
374
|
}
|
|
241
375
|
Accidental(params) {
|
|
242
376
|
const accid = new Accidental(params.type);
|
|
243
377
|
accid.setContext(this.context);
|
|
244
|
-
return accid;
|
|
378
|
+
return this.own(accid);
|
|
245
379
|
}
|
|
246
380
|
Annotation(params) {
|
|
247
381
|
const p = Object.assign({ text: 'p', hJustify: AnnotationHorizontalJustify.CENTER, vJustify: AnnotationVerticalJustify.BOTTOM }, params);
|
|
@@ -250,7 +384,7 @@ export class Factory {
|
|
|
250
384
|
annotation.setVerticalJustification(p.vJustify);
|
|
251
385
|
annotation.setFont(p.font);
|
|
252
386
|
annotation.setContext(this.context);
|
|
253
|
-
return annotation;
|
|
387
|
+
return this.own(annotation);
|
|
254
388
|
}
|
|
255
389
|
ChordSymbol(params) {
|
|
256
390
|
const p = Object.assign({ vJustify: 'top', hJustify: 'center' }, params);
|
|
@@ -267,7 +401,7 @@ export class Factory {
|
|
|
267
401
|
chordSymbol.setFontSize(p.fontSize);
|
|
268
402
|
}
|
|
269
403
|
chordSymbol.setContext(this.context);
|
|
270
|
-
return chordSymbol;
|
|
404
|
+
return this.own(chordSymbol);
|
|
271
405
|
}
|
|
272
406
|
Articulation(params) {
|
|
273
407
|
var _a;
|
|
@@ -277,7 +411,7 @@ export class Factory {
|
|
|
277
411
|
if ((params === null || params === void 0 ? void 0 : params.betweenLines) !== undefined)
|
|
278
412
|
articulation.setBetweenLines(params.betweenLines);
|
|
279
413
|
articulation.setContext(this.context);
|
|
280
|
-
return articulation;
|
|
414
|
+
return this.own(articulation);
|
|
281
415
|
}
|
|
282
416
|
Ornament(type, params) {
|
|
283
417
|
const options = Object.assign({ type, accidental: '' }, params);
|
|
@@ -295,35 +429,29 @@ export class Factory {
|
|
|
295
429
|
ornament.setDelayed(options.delayed);
|
|
296
430
|
}
|
|
297
431
|
ornament.setContext(this.context);
|
|
298
|
-
return ornament;
|
|
432
|
+
return this.own(ornament);
|
|
299
433
|
}
|
|
300
434
|
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
|
-
});
|
|
435
|
+
const text = new TextDynamics(Object.assign({ text: 'p', duration: 'q', dots: 0, line: 0 }, params));
|
|
308
436
|
if (this.stave)
|
|
309
437
|
text.setStave(this.stave);
|
|
310
438
|
text.setContext(this.context);
|
|
311
439
|
this.renderQ.push(text);
|
|
312
|
-
return text;
|
|
440
|
+
return this.own(text);
|
|
313
441
|
}
|
|
314
442
|
Fingering(params) {
|
|
315
443
|
const p = Object.assign({ number: '0', position: 'left' }, params);
|
|
316
444
|
const fingering = new FretHandFinger(p.number);
|
|
317
445
|
fingering.setPosition(p.position);
|
|
318
446
|
fingering.setContext(this.context);
|
|
319
|
-
return fingering;
|
|
447
|
+
return this.own(fingering);
|
|
320
448
|
}
|
|
321
449
|
StringNumber(params, drawCircle = true) {
|
|
322
450
|
const stringNumber = new StringNumber(params.number);
|
|
323
451
|
stringNumber.setPosition(params.position);
|
|
324
452
|
stringNumber.setContext(this.context);
|
|
325
453
|
stringNumber.setDrawCircle(drawCircle);
|
|
326
|
-
return stringNumber;
|
|
454
|
+
return this.own(stringNumber);
|
|
327
455
|
}
|
|
328
456
|
TickContext() {
|
|
329
457
|
return new TickContext();
|
|
@@ -336,19 +464,19 @@ export class Factory {
|
|
|
336
464
|
const multiMeasureRest = new MultiMeasureRest(numMeasures, params);
|
|
337
465
|
multiMeasureRest.setContext(this.context);
|
|
338
466
|
this.renderQ.push(multiMeasureRest);
|
|
339
|
-
return multiMeasureRest;
|
|
467
|
+
return this.own(multiMeasureRest);
|
|
340
468
|
}
|
|
341
469
|
Voice(params) {
|
|
342
470
|
const p = Object.assign({ time: '4/4' }, params);
|
|
343
471
|
const voice = new Voice(p.time);
|
|
344
472
|
this.voices.push(voice);
|
|
345
|
-
return voice;
|
|
473
|
+
return this.own(voice);
|
|
346
474
|
}
|
|
347
475
|
StaveConnector(params) {
|
|
348
476
|
const connector = new StaveConnector(params.topStave, params.bottomStave);
|
|
349
477
|
connector.setType(params.type).setContext(this.context);
|
|
350
478
|
this.renderQ.push(connector);
|
|
351
|
-
return connector;
|
|
479
|
+
return this.own(connector);
|
|
352
480
|
}
|
|
353
481
|
Formatter(options) {
|
|
354
482
|
return new Formatter(options);
|
|
@@ -357,7 +485,7 @@ export class Factory {
|
|
|
357
485
|
const p = Object.assign({ notes: [], options: {} }, params);
|
|
358
486
|
const tuplet = new Tuplet(p.notes, p.options).setContext(this.context);
|
|
359
487
|
this.renderQ.push(tuplet);
|
|
360
|
-
return tuplet;
|
|
488
|
+
return this.own(tuplet);
|
|
361
489
|
}
|
|
362
490
|
Beam(params) {
|
|
363
491
|
var _a, _b, _c, _d, _e;
|
|
@@ -369,12 +497,12 @@ export class Factory {
|
|
|
369
497
|
});
|
|
370
498
|
}
|
|
371
499
|
this.renderQ.push(beam);
|
|
372
|
-
return beam;
|
|
500
|
+
return this.own(beam);
|
|
373
501
|
}
|
|
374
502
|
Curve(params) {
|
|
375
503
|
const curve = new Curve(params.from, params.to, params.options).setContext(this.context);
|
|
376
504
|
this.renderQ.push(curve);
|
|
377
|
-
return curve;
|
|
505
|
+
return this.own(curve);
|
|
378
506
|
}
|
|
379
507
|
StaveTie(params) {
|
|
380
508
|
var _a;
|
|
@@ -388,7 +516,7 @@ export class Factory {
|
|
|
388
516
|
tie.setDirection(params.options.direction);
|
|
389
517
|
tie.setContext(this.context);
|
|
390
518
|
this.renderQ.push(tie);
|
|
391
|
-
return tie;
|
|
519
|
+
return this.own(tie);
|
|
392
520
|
}
|
|
393
521
|
StaveLine(params) {
|
|
394
522
|
var _a, _b;
|
|
@@ -404,20 +532,20 @@ export class Factory {
|
|
|
404
532
|
line.setFont(params.options.font);
|
|
405
533
|
line.setContext(this.context);
|
|
406
534
|
this.renderQ.push(line);
|
|
407
|
-
return line;
|
|
535
|
+
return this.own(line);
|
|
408
536
|
}
|
|
409
537
|
VibratoBracket(params) {
|
|
410
538
|
const vibratoBracket = new VibratoBracket({
|
|
411
539
|
start: params.from,
|
|
412
540
|
stop: params.to,
|
|
413
541
|
});
|
|
414
|
-
if (params.options.line)
|
|
542
|
+
if (params.options.line !== undefined)
|
|
415
543
|
vibratoBracket.setLine(params.options.line);
|
|
416
|
-
if (params.options.code)
|
|
544
|
+
if (params.options.code !== undefined)
|
|
417
545
|
vibratoBracket.setVibratoCode(params.options.code);
|
|
418
546
|
vibratoBracket.setContext(this.context);
|
|
419
547
|
this.renderQ.push(vibratoBracket);
|
|
420
|
-
return vibratoBracket;
|
|
548
|
+
return this.own(vibratoBracket);
|
|
421
549
|
}
|
|
422
550
|
TextBracket(params) {
|
|
423
551
|
const textBracket = new TextBracket({
|
|
@@ -427,23 +555,21 @@ export class Factory {
|
|
|
427
555
|
superscript: params.options.superscript,
|
|
428
556
|
position: params.options.position,
|
|
429
557
|
});
|
|
430
|
-
if (params.options.line)
|
|
558
|
+
if (params.options.line !== undefined)
|
|
431
559
|
textBracket.setLine(params.options.line);
|
|
432
560
|
if (params.options.font)
|
|
433
561
|
textBracket.setFont(params.options.font);
|
|
434
562
|
textBracket.setContext(this.context);
|
|
435
563
|
this.renderQ.push(textBracket);
|
|
436
|
-
return textBracket;
|
|
564
|
+
return this.own(textBracket);
|
|
437
565
|
}
|
|
438
566
|
System(params = {}) {
|
|
439
|
-
params
|
|
440
|
-
const system = new System(params).setContext(this.context);
|
|
567
|
+
const system = new System(Object.assign(Object.assign({}, params), { factory: this })).setContext(this.context);
|
|
441
568
|
this.systems.push(system);
|
|
442
|
-
return system;
|
|
569
|
+
return this.own(system);
|
|
443
570
|
}
|
|
444
571
|
EasyScore(options = {}) {
|
|
445
|
-
options
|
|
446
|
-
return new EasyScore(options);
|
|
572
|
+
return new EasyScore(Object.assign(Object.assign({}, options), { factory: this }));
|
|
447
573
|
}
|
|
448
574
|
PedalMarking(params) {
|
|
449
575
|
const p = Object.assign({ notes: [], options: {
|
|
@@ -453,14 +579,82 @@ export class Factory {
|
|
|
453
579
|
pedal.setType(PedalMarking.typeString[p.options.style]);
|
|
454
580
|
pedal.setContext(this.context);
|
|
455
581
|
this.renderQ.push(pedal);
|
|
456
|
-
return pedal;
|
|
582
|
+
return this.own(pedal);
|
|
457
583
|
}
|
|
458
584
|
NoteSubGroup(params) {
|
|
459
585
|
const p = Object.assign({ notes: [] }, params);
|
|
460
|
-
|
|
461
|
-
|
|
586
|
+
return this.own(new NoteSubGroup(p.notes).setContext(this.context));
|
|
587
|
+
}
|
|
588
|
+
groupNotes(notes, construct) {
|
|
589
|
+
if (!notes.length || new Set(notes).size !== notes.length) {
|
|
590
|
+
throw new RuntimeError('BadArguments', 'A note group needs distinct notes.');
|
|
591
|
+
}
|
|
592
|
+
notes.forEach((note) => {
|
|
593
|
+
const owner = Factory.getOwner(note);
|
|
594
|
+
if (owner && owner !== this)
|
|
595
|
+
throw new RuntimeError('BadArguments', 'Group note belongs to another Factory.');
|
|
596
|
+
if (Factory.groups.has(note))
|
|
597
|
+
throw new RuntimeError('BadArguments', 'Note already belongs to a group.');
|
|
598
|
+
let voice;
|
|
599
|
+
try {
|
|
600
|
+
voice = note.getVoice();
|
|
601
|
+
}
|
|
602
|
+
catch (error) {
|
|
603
|
+
if (!(error instanceof RuntimeError) || error.code !== 'NoVoice')
|
|
604
|
+
throw error;
|
|
605
|
+
}
|
|
606
|
+
if (voice)
|
|
607
|
+
throw new RuntimeError('BadArguments', 'A voiced note cannot be moved into a group.');
|
|
608
|
+
});
|
|
609
|
+
const ignored = notes.map((note) => note.shouldIgnoreTicks());
|
|
610
|
+
const restore = () => notes.forEach((note, index) => {
|
|
611
|
+
Factory.groups.delete(note);
|
|
612
|
+
note.clearVoice().setIgnoreTicks(ignored[index]);
|
|
613
|
+
});
|
|
614
|
+
let group;
|
|
615
|
+
try {
|
|
616
|
+
group = this.own(construct().setContext(this.context));
|
|
617
|
+
}
|
|
618
|
+
catch (error) {
|
|
619
|
+
restore();
|
|
620
|
+
throw error;
|
|
621
|
+
}
|
|
622
|
+
this.groupScopes.forEach((scope) => scope.push(restore));
|
|
623
|
+
notes.forEach((note) => {
|
|
624
|
+
this.own(note);
|
|
625
|
+
Factory.groups.set(note, group);
|
|
626
|
+
});
|
|
627
|
+
this.renderQ = this.renderQ.filter((element) => !notes.includes(element));
|
|
462
628
|
return group;
|
|
463
629
|
}
|
|
630
|
+
Dot(...args) {
|
|
631
|
+
return this.adopt(new Dot(...args).setContext(this.context), 'modifier');
|
|
632
|
+
}
|
|
633
|
+
Parenthesis(...args) {
|
|
634
|
+
return this.adopt(new Parenthesis(...args).setContext(this.context), 'modifier');
|
|
635
|
+
}
|
|
636
|
+
Stroke(...args) {
|
|
637
|
+
return this.adopt(new Stroke(...args).setContext(this.context), 'modifier');
|
|
638
|
+
}
|
|
639
|
+
Tremolo(...args) {
|
|
640
|
+
return this.adopt(new Tremolo(...args).setContext(this.context), 'modifier');
|
|
641
|
+
}
|
|
642
|
+
Vibrato(...args) {
|
|
643
|
+
return this.adopt(new Vibrato(...args).setContext(this.context), 'modifier');
|
|
644
|
+
}
|
|
645
|
+
Crescendo(...args) {
|
|
646
|
+
const note = new Crescendo(...args).setContext(this.context);
|
|
647
|
+
if (this.stave)
|
|
648
|
+
note.setStave(this.stave);
|
|
649
|
+
return this.adopt(note, 'note');
|
|
650
|
+
}
|
|
651
|
+
StaveHairpin(params) {
|
|
652
|
+
const notes = Object.assign(Object.assign({}, (params.from && { firstNote: params.from })), (params.to && { lastNote: params.to }));
|
|
653
|
+
const hairpin = new StaveHairpin(notes, params.type).setContext(this.context);
|
|
654
|
+
if (params.options)
|
|
655
|
+
hairpin.setRenderOptions(Object.assign(Object.assign({}, hairpin.renderOptions), params.options));
|
|
656
|
+
return this.adopt(hairpin, 'drawable');
|
|
657
|
+
}
|
|
464
658
|
draw(options = {}) {
|
|
465
659
|
var _a;
|
|
466
660
|
const ctx = this.context;
|
|
@@ -498,3 +692,5 @@ export class Factory {
|
|
|
498
692
|
}
|
|
499
693
|
}
|
|
500
694
|
Factory.DEBUG = false;
|
|
695
|
+
Factory.owners = new WeakMap();
|
|
696
|
+
Factory.groups = new WeakMap();
|
|
@@ -2,6 +2,7 @@ import { Beam } from './beam.js';
|
|
|
2
2
|
import { Fraction } from './fraction.js';
|
|
3
3
|
import { Metrics } from './metrics.js';
|
|
4
4
|
import { ModifierContext } from './modifiercontext.js';
|
|
5
|
+
import { ProportionalFormatter } from './proportionalformatter.js';
|
|
5
6
|
import { Stave } from './stave.js';
|
|
6
7
|
import { StaveConnector } from './staveconnector.js';
|
|
7
8
|
import { Tables } from './tables.js';
|
|
@@ -139,6 +140,9 @@ export class Formatter {
|
|
|
139
140
|
}
|
|
140
141
|
constructor(options) {
|
|
141
142
|
this.formatterOptions = Object.assign({ globalSoftmax: false, softmaxFactor: Tables.SOFTMAX_FACTOR, maxIterations: 5 }, options);
|
|
143
|
+
if ((options === null || options === void 0 ? void 0 : options.spacing) && options.spacing.mode !== 'proportional') {
|
|
144
|
+
throw new RuntimeError('BadArgument', 'Unknown formatter spacing mode.');
|
|
145
|
+
}
|
|
142
146
|
this.justifyWidth = 0;
|
|
143
147
|
this.totalCost = 0;
|
|
144
148
|
this.totalShift = 0;
|
|
@@ -166,6 +170,12 @@ export class Formatter {
|
|
|
166
170
|
voices.forEach((voice) => Formatter.AlignRestsToNotes(voice.getTickables(), alignAllNotes));
|
|
167
171
|
}
|
|
168
172
|
preCalculateMinTotalWidth(voices) {
|
|
173
|
+
if (this.formatterOptions.spacing) {
|
|
174
|
+
this.createTickContexts(voices);
|
|
175
|
+
this.minTotalWidth = this.proportional.minimumWidth(this.formatterOptions.spacing);
|
|
176
|
+
this.hasMinTotalWidth = true;
|
|
177
|
+
return this.minTotalWidth;
|
|
178
|
+
}
|
|
169
179
|
const unalignedPadding = Metrics.get('Stave.unalignedNotePadding');
|
|
170
180
|
let unalignedCtxCount = 0;
|
|
171
181
|
let wsum = 0;
|
|
@@ -249,7 +259,8 @@ export class Formatter {
|
|
|
249
259
|
staveTickToContextMap[integerTicks] = newContext;
|
|
250
260
|
}
|
|
251
261
|
tickable.addToModifierContext(staveTickToContextMap[integerTicks]);
|
|
252
|
-
|
|
262
|
+
if (!this.formatterOptions.spacing || !tickable.shouldIgnoreTicks())
|
|
263
|
+
ticksUsed.add(tickable.getTicks());
|
|
253
264
|
});
|
|
254
265
|
});
|
|
255
266
|
this.modifierContexts.push({
|
|
@@ -260,6 +271,8 @@ export class Formatter {
|
|
|
260
271
|
}
|
|
261
272
|
createTickContexts(voices) {
|
|
262
273
|
if (voices.length === 0) {
|
|
274
|
+
if (this.formatterOptions.spacing)
|
|
275
|
+
throw new RuntimeError('BadArgument', 'No voices to format');
|
|
263
276
|
return {
|
|
264
277
|
map: {},
|
|
265
278
|
array: [],
|
|
@@ -267,6 +280,11 @@ export class Formatter {
|
|
|
267
280
|
resolutionMultiplier: 0,
|
|
268
281
|
};
|
|
269
282
|
}
|
|
283
|
+
if (this.formatterOptions.spacing) {
|
|
284
|
+
this.proportional = new ProportionalFormatter(voices, Formatter.getResolutionMultiplier(voices));
|
|
285
|
+
this.tickContexts = this.proportional.contexts;
|
|
286
|
+
return this.tickContexts;
|
|
287
|
+
}
|
|
270
288
|
const tickToContextMap = {};
|
|
271
289
|
const tickList = [];
|
|
272
290
|
const tickContexts = [];
|
|
@@ -312,6 +330,13 @@ export class Formatter {
|
|
|
312
330
|
if (voicesParam && stave) {
|
|
313
331
|
voicesParam.forEach((voice) => voice.setStave(stave).preFormat());
|
|
314
332
|
}
|
|
333
|
+
if (this.proportional && this.formatterOptions.spacing) {
|
|
334
|
+
const spacing = this.formatterOptions.spacing;
|
|
335
|
+
this.minTotalWidth = this.proportional.minimumWidth(spacing);
|
|
336
|
+
this.justifyWidth = this.proportional.format(spacing, justifyWidth);
|
|
337
|
+
this.hasMinTotalWidth = true;
|
|
338
|
+
return this.evaluate();
|
|
339
|
+
}
|
|
315
340
|
let x = 0;
|
|
316
341
|
let shift = 0;
|
|
317
342
|
this.minTotalWidth = 0;
|
|
@@ -539,6 +564,8 @@ export class Formatter {
|
|
|
539
564
|
}
|
|
540
565
|
tune(options) {
|
|
541
566
|
var _a;
|
|
567
|
+
if (this.proportional)
|
|
568
|
+
return this.totalCost;
|
|
542
569
|
const contexts = this.tickContexts;
|
|
543
570
|
if (!contexts) {
|
|
544
571
|
return 0;
|
|
@@ -572,9 +599,10 @@ export class Formatter {
|
|
|
572
599
|
this.modifierContexts.forEach((modifierContexts) => {
|
|
573
600
|
modifierContexts.array.forEach((mc) => mc.postFormat());
|
|
574
601
|
});
|
|
575
|
-
this.
|
|
576
|
-
this.tickContexts.
|
|
577
|
-
|
|
602
|
+
const contexts = this.proportional
|
|
603
|
+
? this.tickContexts.array
|
|
604
|
+
: this.tickContexts.list.map((tick) => this.tickContexts.map[tick]);
|
|
605
|
+
contexts.forEach((context) => context.postFormat());
|
|
578
606
|
return this;
|
|
579
607
|
}
|
|
580
608
|
joinVoices(voices) {
|