vexflow 5.0.0-alpha.2 → 5.0.0-alpha.3
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/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 +4 -4
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +4 -4
- 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/version.js +3 -3
- package/package.json +1 -3
- package/entry/vexflow-bravura.ts +0 -25
- package/entry/vexflow-core.ts +0 -16
- package/entry/vexflow-debug-with-tests.ts +0 -64
- package/entry/vexflow-debug.ts +0 -54
- package/entry/vexflow.ts +0 -47
- package/src/accidental.ts +0 -570
- package/src/annotation.ts +0 -294
- package/src/articulation.ts +0 -383
- package/src/barnote.ts +0 -95
- package/src/beam.ts +0 -999
- package/src/bend.ts +0 -268
- package/src/boundingbox.ts +0 -108
- package/src/canvascontext.ts +0 -348
- package/src/chordsymbol.ts +0 -473
- package/src/clef.ts +0 -164
- package/src/clefnote.ts +0 -50
- package/src/crescendo.ts +0 -132
- package/src/curve.ts +0 -195
- package/src/dot.ts +0 -171
- package/src/easyscore.ts +0 -538
- package/src/element.ts +0 -692
- package/src/factory.ts +0 -694
- package/src/font.ts +0 -343
- package/src/fonts/academico.ts +0 -2
- package/src/fonts/academicobold.ts +0 -2
- package/src/fonts/bravura.ts +0 -2
- package/src/fonts/gonville.ts +0 -2
- package/src/fonts/petaluma.ts +0 -2
- package/src/fonts/petalumascript.ts +0 -2
- package/src/formatter.ts +0 -1107
- package/src/fraction.ts +0 -245
- package/src/frethandfinger.ts +0 -180
- package/src/ghostnote.ts +0 -75
- package/src/glyphnote.ts +0 -68
- package/src/glyphs.ts +0 -5880
- package/src/gracenote.ts +0 -146
- package/src/gracenotegroup.ts +0 -194
- package/src/gracetabnote.ts +0 -30
- package/src/index.ts +0 -90
- package/src/keymanager.ts +0 -153
- package/src/keysignature.ts +0 -272
- package/src/keysignote.ts +0 -46
- package/src/metrics.ts +0 -222
- package/src/modifier.ts +0 -216
- package/src/modifiercontext.ts +0 -177
- package/src/multimeasurerest.ts +0 -229
- package/src/music.ts +0 -443
- package/src/note.ts +0 -690
- package/src/notehead.ts +0 -158
- package/src/notesubgroup.ts +0 -88
- package/src/ornament.ts +0 -301
- package/src/parenthesis.ts +0 -89
- package/src/parser.ts +0 -263
- package/src/pedalmarking.ts +0 -273
- package/src/registry.ts +0 -146
- package/src/rendercontext.ts +0 -98
- package/src/renderer.ts +0 -166
- package/src/repeatnote.ts +0 -25
- package/src/stave.ts +0 -885
- package/src/stavebarline.ts +0 -231
- package/src/staveconnector.ts +0 -281
- package/src/stavehairpin.ts +0 -209
- package/src/staveline.ts +0 -343
- package/src/stavemodifier.ts +0 -93
- package/src/stavenote.ts +0 -1230
- package/src/staverepetition.ts +0 -148
- package/src/stavesection.ts +0 -54
- package/src/stavetempo.ts +0 -162
- package/src/stavetext.ts +0 -69
- package/src/stavetie.ts +0 -235
- package/src/stavevolta.ts +0 -66
- package/src/stem.ts +0 -225
- package/src/stemmablenote.ts +0 -248
- package/src/stringnumber.ts +0 -286
- package/src/strokes.ts +0 -214
- package/src/svgcontext.ts +0 -639
- package/src/system.ts +0 -327
- package/src/tables.ts +0 -796
- package/src/tabnote.ts +0 -449
- package/src/tabslide.ts +0 -115
- package/src/tabstave.ts +0 -31
- package/src/tabtie.ts +0 -44
- package/src/textbracket.ts +0 -231
- package/src/textdynamics.ts +0 -101
- package/src/textnote.ts +0 -175
- package/src/tickable.ts +0 -374
- package/src/tickcontext.ts +0 -280
- package/src/timesignature.ts +0 -229
- package/src/timesignote.ts +0 -45
- package/src/tremolo.ts +0 -51
- package/src/tuning.ts +0 -90
- package/src/tuplet.ts +0 -349
- package/src/typeguard.ts +0 -136
- package/src/util.ts +0 -169
- package/src/version.ts +0 -4
- package/src/vexflow.ts +0 -378
- package/src/vibrato.ts +0 -99
- package/src/vibratobracket.ts +0 -81
- package/src/voice.ts +0 -302
- package/src/web.ts +0 -35
package/src/system.ts
DELETED
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
|
|
2
|
-
// MIT License
|
|
3
|
-
|
|
4
|
-
import { BoundingBox } from './boundingbox';
|
|
5
|
-
import { Element } from './element';
|
|
6
|
-
import { Factory } from './factory';
|
|
7
|
-
import { FormatParams, Formatter, FormatterOptions } from './formatter';
|
|
8
|
-
import { Note } from './note';
|
|
9
|
-
import { RenderContext } from './rendercontext';
|
|
10
|
-
import { Stave, StaveOptions } from './stave';
|
|
11
|
-
import { StaveConnector, StaveConnectorType } from './staveconnector';
|
|
12
|
-
import { Category } from './typeguard';
|
|
13
|
-
import { RuntimeError } from './util';
|
|
14
|
-
import { Voice } from './voice';
|
|
15
|
-
|
|
16
|
-
export interface SystemFormatterOptions extends FormatterOptions {
|
|
17
|
-
alpha?: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface SystemStave {
|
|
21
|
-
voices: Voice[];
|
|
22
|
-
stave?: Stave;
|
|
23
|
-
noJustification?: boolean;
|
|
24
|
-
options?: StaveOptions;
|
|
25
|
-
spaceAbove?: number;
|
|
26
|
-
spaceBelow?: number;
|
|
27
|
-
debugNoteMetrics?: boolean;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
interface StaveInfo {
|
|
31
|
-
noJustification: boolean;
|
|
32
|
-
options: StaveOptions;
|
|
33
|
-
spaceAbove: number;
|
|
34
|
-
spaceBelow: number;
|
|
35
|
-
debugNoteMetrics: boolean;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Formatting for systems created/drawn from factory:
|
|
40
|
-
*
|
|
41
|
-
* If width is provided, the system will use the specified width.
|
|
42
|
-
*
|
|
43
|
-
* If noJustification flag is 'true', there is no justification between voices
|
|
44
|
-
* Otherwise, autoWidth defaults to true.
|
|
45
|
-
*
|
|
46
|
-
* If autowidth is true, the system uses format.preCalculateMinWidth
|
|
47
|
-
* for the width of all voices, and default stave padding
|
|
48
|
-
*/
|
|
49
|
-
export interface SystemOptions {
|
|
50
|
-
factory?: Factory;
|
|
51
|
-
noPadding?: boolean;
|
|
52
|
-
debugFormatter?: boolean;
|
|
53
|
-
spaceBetweenStaves?: number;
|
|
54
|
-
formatIterations?: number;
|
|
55
|
-
autoWidth?: boolean;
|
|
56
|
-
x?: number;
|
|
57
|
-
width?: number;
|
|
58
|
-
y?: number;
|
|
59
|
-
details?: SystemFormatterOptions;
|
|
60
|
-
formatOptions?: FormatParams;
|
|
61
|
-
noJustification?: boolean;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* System implements a musical system, which is a collection of staves,
|
|
66
|
-
* each which can have one or more voices. All voices across all staves in
|
|
67
|
-
* the system are formatted together.
|
|
68
|
-
*/
|
|
69
|
-
export class System extends Element {
|
|
70
|
-
static get CATEGORY(): string {
|
|
71
|
-
return Category.System;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
protected options!: Required<SystemOptions>;
|
|
75
|
-
protected factory!: Factory;
|
|
76
|
-
protected formatter?: Formatter;
|
|
77
|
-
protected startX?: number;
|
|
78
|
-
protected lastY?: number;
|
|
79
|
-
protected partStaves: Stave[];
|
|
80
|
-
protected partStaveInfos: StaveInfo[];
|
|
81
|
-
protected partVoices: Voice[];
|
|
82
|
-
protected connector?: StaveConnector;
|
|
83
|
-
protected debugNoteMetricsYs?: { y: number; stave: Stave }[];
|
|
84
|
-
|
|
85
|
-
constructor(params: SystemOptions = {}) {
|
|
86
|
-
super();
|
|
87
|
-
this.setOptions(params);
|
|
88
|
-
this.partStaves = [];
|
|
89
|
-
this.partStaveInfos = [];
|
|
90
|
-
this.partVoices = [];
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/** Set formatting options. */
|
|
94
|
-
setOptions(options: SystemOptions = {}): void {
|
|
95
|
-
if (!options.factory) {
|
|
96
|
-
throw new RuntimeError('NoFactory', 'System.setOptions(options) requires a factory.');
|
|
97
|
-
}
|
|
98
|
-
this.factory = options.factory;
|
|
99
|
-
this.options = {
|
|
100
|
-
factory: this.factory,
|
|
101
|
-
x: 10,
|
|
102
|
-
y: 10,
|
|
103
|
-
width: 500,
|
|
104
|
-
spaceBetweenStaves: 12, // stave spaces
|
|
105
|
-
autoWidth: false,
|
|
106
|
-
noJustification: false,
|
|
107
|
-
debugFormatter: false,
|
|
108
|
-
formatIterations: 0, // number of formatter tuning steps
|
|
109
|
-
noPadding: false,
|
|
110
|
-
...options,
|
|
111
|
-
details: {
|
|
112
|
-
alpha: 0.5, // formatter tuner learning/shifting rate
|
|
113
|
-
...options.details,
|
|
114
|
-
},
|
|
115
|
-
formatOptions: {
|
|
116
|
-
...options.formatOptions,
|
|
117
|
-
},
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
if (this.options.noJustification === false && typeof options.width === 'undefined') {
|
|
121
|
-
this.options.autoWidth = true;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** Get origin X. */
|
|
126
|
-
getX(): number {
|
|
127
|
-
return this.options.x;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/** Set origin X. */
|
|
131
|
-
setX(x: number): this {
|
|
132
|
-
this.options.x = x;
|
|
133
|
-
this.partStaves.forEach((s) => {
|
|
134
|
-
s.setX(x);
|
|
135
|
-
});
|
|
136
|
-
return this;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/** Get origin y. */
|
|
140
|
-
getY(): number {
|
|
141
|
-
return this.options.y;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/** Set origin y. */
|
|
145
|
-
setY(y: number): this {
|
|
146
|
-
this.options.y = y;
|
|
147
|
-
this.partStaves.forEach((s) => {
|
|
148
|
-
s.setY(y);
|
|
149
|
-
});
|
|
150
|
-
return this;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/** Get associated staves. */
|
|
154
|
-
getStaves(): Stave[] {
|
|
155
|
-
return this.partStaves;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/** Get associated voices. */
|
|
159
|
-
getVoices(): Voice[] {
|
|
160
|
-
return this.partVoices;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/** Set associated context. */
|
|
164
|
-
setContext(context: RenderContext): this {
|
|
165
|
-
super.setContext(context);
|
|
166
|
-
this.factory.setContext(context);
|
|
167
|
-
return this;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Add connector between staves.
|
|
172
|
-
* @param type see {@link StaveConnector.typeString}
|
|
173
|
-
*/
|
|
174
|
-
addConnector(type: StaveConnectorType = 'double'): StaveConnector {
|
|
175
|
-
this.connector = this.factory.StaveConnector({
|
|
176
|
-
topStave: this.partStaves[0],
|
|
177
|
-
bottomStave: this.partStaves[this.partStaves.length - 1],
|
|
178
|
-
type,
|
|
179
|
-
});
|
|
180
|
-
return this.connector;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Add a stave to the system.
|
|
185
|
-
*
|
|
186
|
-
* Example (one voice):
|
|
187
|
-
*
|
|
188
|
-
* `system.addStave({voices: [score.voice(score.notes('C#5/q, B4, A4, G#4'))]});`
|
|
189
|
-
*
|
|
190
|
-
* Example (two voices):
|
|
191
|
-
*
|
|
192
|
-
* `system.addStave({voices: [`
|
|
193
|
-
* `score.voice(score.notes('C#5/q, B4, A4, G#4', {stem: 'up'})),`
|
|
194
|
-
* `score.voice(score.notes('C#4/h, C#4', {stem: 'down'}))`
|
|
195
|
-
* `]});`
|
|
196
|
-
*/
|
|
197
|
-
addStave(params: SystemStave): Stave {
|
|
198
|
-
const staveOptions: StaveOptions = { leftBar: false, ...params.options };
|
|
199
|
-
|
|
200
|
-
const stave =
|
|
201
|
-
params.stave ??
|
|
202
|
-
this.factory.Stave({ x: this.options.x, y: this.options.y, width: this.options.width, options: staveOptions });
|
|
203
|
-
|
|
204
|
-
const p = {
|
|
205
|
-
spaceAbove: 0, // stave spaces
|
|
206
|
-
spaceBelow: 0, // stave spaces
|
|
207
|
-
debugNoteMetrics: false,
|
|
208
|
-
noJustification: false,
|
|
209
|
-
...params,
|
|
210
|
-
options: staveOptions, // this needs to go after ...params, so we can override the options field.
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
const ctx = this.getContext();
|
|
214
|
-
p.voices.forEach((voice) => {
|
|
215
|
-
voice
|
|
216
|
-
.setContext(ctx)
|
|
217
|
-
.setStave(stave)
|
|
218
|
-
.getTickables()
|
|
219
|
-
.forEach((tickable) => tickable.setStave(stave));
|
|
220
|
-
this.partVoices.push(voice);
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
this.partStaves.push(stave);
|
|
224
|
-
this.partStaveInfos.push(p);
|
|
225
|
-
return stave;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Add voices to the system with stave already assigned.
|
|
230
|
-
*/
|
|
231
|
-
addVoices(voices: Voice[]) {
|
|
232
|
-
const ctx = this.getContext();
|
|
233
|
-
voices.forEach((voice) => {
|
|
234
|
-
voice.setContext(ctx);
|
|
235
|
-
this.partVoices.push(voice);
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/** Format the system. */
|
|
240
|
-
format(): void {
|
|
241
|
-
const optionsDetails = this.options.details;
|
|
242
|
-
let justifyWidth = 0;
|
|
243
|
-
const formatter = new Formatter(optionsDetails);
|
|
244
|
-
this.formatter = formatter;
|
|
245
|
-
|
|
246
|
-
let y = this.options.y;
|
|
247
|
-
let startX = 0;
|
|
248
|
-
const debugNoteMetricsYs: { y: number; stave: Stave }[] = [];
|
|
249
|
-
|
|
250
|
-
this.partStaves.forEach((part, index) => {
|
|
251
|
-
y = y + part.space(this.partStaveInfos[index].spaceAbove);
|
|
252
|
-
part.setY(y);
|
|
253
|
-
y = y + part.space(this.partStaveInfos[index].spaceBelow);
|
|
254
|
-
y = y + part.space(this.options.spaceBetweenStaves);
|
|
255
|
-
if (this.partStaveInfos[index].debugNoteMetrics) {
|
|
256
|
-
debugNoteMetricsYs.push({ y, stave: part });
|
|
257
|
-
y += 15;
|
|
258
|
-
}
|
|
259
|
-
startX = Math.max(startX, part.getNoteStartX());
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
// Re-assign Stave to update y position
|
|
263
|
-
this.partVoices.forEach((voice) => {
|
|
264
|
-
voice.getTickables().forEach((tickable) => {
|
|
265
|
-
const stave = tickable.getStave();
|
|
266
|
-
if (stave) tickable.setStave(stave);
|
|
267
|
-
});
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
// Join the voices
|
|
271
|
-
formatter.joinVoices(this.partVoices);
|
|
272
|
-
|
|
273
|
-
// Update the start position of all staves.
|
|
274
|
-
this.partStaves.forEach((part) => part.setNoteStartX(startX));
|
|
275
|
-
if (this.options.autoWidth && this.partVoices.length > 0) {
|
|
276
|
-
justifyWidth = formatter.preCalculateMinTotalWidth(this.partVoices);
|
|
277
|
-
this.options.width = justifyWidth + Stave.rightPadding + (startX - this.options.x);
|
|
278
|
-
this.partStaves.forEach((part) => {
|
|
279
|
-
part.setWidth(this.options.width);
|
|
280
|
-
});
|
|
281
|
-
} else {
|
|
282
|
-
justifyWidth = this.options.noPadding
|
|
283
|
-
? this.options.width - (startX - this.options.x)
|
|
284
|
-
: this.options.width - (startX - this.options.x) - Stave.defaultPadding;
|
|
285
|
-
}
|
|
286
|
-
if (this.partVoices.length > 0) {
|
|
287
|
-
formatter.format(this.partVoices, this.options.noJustification ? 0 : justifyWidth, this.options.formatOptions);
|
|
288
|
-
}
|
|
289
|
-
formatter.postFormat();
|
|
290
|
-
|
|
291
|
-
for (let i = 0; i < this.options.formatIterations; i++) {
|
|
292
|
-
formatter.tune(optionsDetails);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
this.startX = startX;
|
|
296
|
-
this.debugNoteMetricsYs = debugNoteMetricsYs;
|
|
297
|
-
this.lastY = y;
|
|
298
|
-
Stave.formatBegModifiers(this.partStaves);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
/** Get the boundingBox. */
|
|
302
|
-
getBoundingBox(): BoundingBox {
|
|
303
|
-
return new BoundingBox(this.options.x, this.options.y, this.options.width, (this.lastY ?? 0) - this.options.y);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
/** Render the system. */
|
|
307
|
-
draw(): void {
|
|
308
|
-
// Render debugging information, if requested.
|
|
309
|
-
const ctx = this.checkContext();
|
|
310
|
-
if (!this.formatter || !this.startX || !this.lastY || !this.debugNoteMetricsYs) {
|
|
311
|
-
throw new RuntimeError('NoFormatter', 'format() must be called before draw()');
|
|
312
|
-
}
|
|
313
|
-
this.setRendered();
|
|
314
|
-
|
|
315
|
-
if (this.options.debugFormatter) {
|
|
316
|
-
Formatter.plotDebugging(ctx, this.formatter, this.startX, this.options.y, this.lastY);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
this.debugNoteMetricsYs.forEach((d) => {
|
|
320
|
-
this.partVoices.forEach((voice) => {
|
|
321
|
-
voice.getTickables().forEach((tickable) => {
|
|
322
|
-
if (tickable.getStave() === d.stave) Note.plotMetrics(ctx, tickable, d.y);
|
|
323
|
-
});
|
|
324
|
-
});
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
}
|