vexflow 5.0.0-alpha.2 → 5.0.0-alpha.4
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 +528 -492
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +460 -452
- 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 +22 -28
- package/build/esm/src/beam.js +24 -42
- package/build/esm/src/clefnote.js +6 -1
- package/build/esm/src/element.js +83 -101
- package/build/esm/src/fonts/gonville.js +1 -1
- package/build/esm/src/formatter.js +9 -17
- package/build/esm/src/fraction.js +15 -22
- package/build/esm/src/glyphnote.js +3 -2
- package/build/esm/src/metrics.js +3 -0
- package/build/esm/src/modifier.js +6 -21
- package/build/esm/src/multimeasurerest.js +16 -25
- package/build/esm/src/note.js +7 -0
- package/build/esm/src/registry.js +5 -19
- package/build/esm/src/stave.js +4 -6
- package/build/esm/src/stavenote.js +26 -40
- package/build/esm/src/stavetempo.js +4 -11
- package/build/esm/src/stavetie.js +82 -36
- package/build/esm/src/svgcontext.js +5 -12
- package/build/esm/src/tickable.js +13 -26
- package/build/esm/src/tickcontext.js +20 -2
- package/build/esm/src/version.js +3 -3
- package/build/esm/src/vibrato.js +6 -1
- package/build/esm/tests/clef_tests.js +5 -1
- package/build/esm/tests/glyphnote_tests.js +6 -0
- package/build/esm/tests/stavetie_tests.js +29 -0
- package/build/esm/tests/tabstave_tests.js +1 -0
- package/build/esm/tests/vexflow_test_helpers.js +25 -39
- package/build/types/src/accidental.d.ts +19 -1
- package/build/types/src/annotation.d.ts +1 -1
- package/build/types/src/beam.d.ts +12 -1
- package/build/types/src/clefnote.d.ts +2 -0
- package/build/types/src/element.d.ts +13 -3
- package/build/types/src/fonts/gonville.d.ts +1 -1
- package/build/types/src/formatter.d.ts +5 -3
- package/build/types/src/fraction.d.ts +12 -7
- package/build/types/src/modifier.d.ts +2 -1
- package/build/types/src/multimeasurerest.d.ts +4 -1
- package/build/types/src/note.d.ts +2 -0
- package/build/types/src/registry.d.ts +1 -1
- package/build/types/src/stavenote.d.ts +2 -1
- package/build/types/src/stavetempo.d.ts +3 -3
- package/build/types/src/stavetie.d.ts +39 -2
- package/build/types/src/svgcontext.d.ts +1 -1
- package/build/types/src/tickable.d.ts +2 -1
- package/build/types/src/tickcontext.d.ts +30 -0
- package/package.json +2 -4
- package/tests/flow.html +2 -2
- 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/tickable.ts
DELETED
|
@@ -1,374 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
|
|
2
|
-
// MIT License
|
|
3
|
-
|
|
4
|
-
import { Element } from './element';
|
|
5
|
-
import { Fraction } from './fraction';
|
|
6
|
-
import { Modifier } from './modifier';
|
|
7
|
-
import { ModifierContext } from './modifiercontext';
|
|
8
|
-
import { Stave } from './stave';
|
|
9
|
-
import { Tables } from './tables';
|
|
10
|
-
import { TickContext } from './tickcontext';
|
|
11
|
-
import { Tuplet } from './tuplet';
|
|
12
|
-
import { Category } from './typeguard';
|
|
13
|
-
import { defined, RuntimeError } from './util';
|
|
14
|
-
import { Voice } from './voice';
|
|
15
|
-
|
|
16
|
-
/** Formatter metrics interface */
|
|
17
|
-
export interface FormatterMetrics {
|
|
18
|
-
duration: string;
|
|
19
|
-
freedom: {
|
|
20
|
-
left: number;
|
|
21
|
-
right: number;
|
|
22
|
-
};
|
|
23
|
-
iterations: number;
|
|
24
|
-
space: {
|
|
25
|
-
used: number;
|
|
26
|
-
mean: number;
|
|
27
|
-
deviation: number;
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Tickable represents a element that sit on a score and
|
|
33
|
-
* has a duration, i.e., Tickables occupy space in the musical rendering dimension.
|
|
34
|
-
*/
|
|
35
|
-
export abstract class Tickable extends Element {
|
|
36
|
-
static get CATEGORY(): string {
|
|
37
|
-
return Category.Tickable;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
protected ignoreTicks: boolean;
|
|
41
|
-
protected tupletStack: Tuplet[];
|
|
42
|
-
protected tuplet?: Tuplet;
|
|
43
|
-
protected ticks: Fraction;
|
|
44
|
-
protected centerXShift: number;
|
|
45
|
-
protected voice?: Voice;
|
|
46
|
-
protected modifierContext?: ModifierContext;
|
|
47
|
-
protected tickContext?: TickContext;
|
|
48
|
-
protected modifiers: Modifier[];
|
|
49
|
-
protected tickMultiplier: Fraction;
|
|
50
|
-
protected formatterMetrics: FormatterMetrics;
|
|
51
|
-
protected intrinsicTicks: number;
|
|
52
|
-
protected alignCenter: boolean;
|
|
53
|
-
|
|
54
|
-
#preFormatted: boolean = false;
|
|
55
|
-
#postFormatted: boolean = false;
|
|
56
|
-
|
|
57
|
-
constructor() {
|
|
58
|
-
super();
|
|
59
|
-
|
|
60
|
-
// These properties represent the duration of
|
|
61
|
-
// this tickable element.
|
|
62
|
-
this.ticks = new Fraction(0, 1); // Fractional value of ticks
|
|
63
|
-
this.intrinsicTicks = 0; // Floating point value of ticks
|
|
64
|
-
this.tickMultiplier = new Fraction(1, 1);
|
|
65
|
-
|
|
66
|
-
this.modifiers = [];
|
|
67
|
-
this.tupletStack = [];
|
|
68
|
-
|
|
69
|
-
this.alignCenter = false;
|
|
70
|
-
this.centerXShift = 0; // Shift from tick context if center aligned
|
|
71
|
-
|
|
72
|
-
// This flag tells the formatter to ignore this tickable during
|
|
73
|
-
// formatting and justification. It is set by tickables such as BarNote.
|
|
74
|
-
this.ignoreTicks = false;
|
|
75
|
-
|
|
76
|
-
// This is a space for an external formatting class or function to maintain
|
|
77
|
-
// metrics.
|
|
78
|
-
this.formatterMetrics = {
|
|
79
|
-
// The freedom of a tickable is the distance it can move without colliding
|
|
80
|
-
// with neighboring elements. A formatter can set these values during its
|
|
81
|
-
// formatting pass, which a different formatter can then use to fine tune.
|
|
82
|
-
freedom: { left: 0, right: 0 },
|
|
83
|
-
|
|
84
|
-
// The simplified rational duration of this tick as a string. It can be
|
|
85
|
-
// used as an index to a map or hashtable.
|
|
86
|
-
duration: '',
|
|
87
|
-
|
|
88
|
-
// The number of formatting iterations undergone.
|
|
89
|
-
iterations: 0,
|
|
90
|
-
|
|
91
|
-
// The space in pixels allocated by this formatter, along with the mean space
|
|
92
|
-
// for tickables of this duration, and the deviation from the mean.
|
|
93
|
-
space: {
|
|
94
|
-
used: 0,
|
|
95
|
-
mean: 0,
|
|
96
|
-
deviation: 0,
|
|
97
|
-
},
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/** Reset the Tickable, this function will be overloaded. */
|
|
102
|
-
reset(): this {
|
|
103
|
-
return this;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/** Return the ticks. */
|
|
107
|
-
getTicks(): Fraction {
|
|
108
|
-
return this.ticks;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/** Check if it ignores the ticks. */
|
|
112
|
-
shouldIgnoreTicks(): boolean {
|
|
113
|
-
return this.ignoreTicks;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/** Ignore the ticks. */
|
|
117
|
-
setIgnoreTicks(flag: boolean): this {
|
|
118
|
-
this.ignoreTicks = flag;
|
|
119
|
-
return this;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/** Get width of note. Used by the formatter for positioning. */
|
|
123
|
-
getWidth(): number {
|
|
124
|
-
if (!this.#preFormatted) {
|
|
125
|
-
throw new RuntimeError('UnformattedNote', "Can't call GetWidth on an unformatted note.");
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return this.width + (this.modifierContext ? this.modifierContext.getWidth() : 0);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/** Get `x` position of this tick context. */
|
|
132
|
-
getX(): number {
|
|
133
|
-
const tickContext = this.checkTickContext(`Can't getX() without a TickContext.`);
|
|
134
|
-
return tickContext.getX() + this.xShift;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/** Return the formatterMetrics. */
|
|
138
|
-
getFormatterMetrics(): FormatterMetrics {
|
|
139
|
-
return this.formatterMetrics;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/** Return the center `x` shift. */
|
|
143
|
-
getCenterXShift(): number {
|
|
144
|
-
if (this.isCenterAligned()) {
|
|
145
|
-
return this.centerXShift;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return 0;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/** Set the center `x` shift. */
|
|
152
|
-
setCenterXShift(centerXShift: number): this {
|
|
153
|
-
this.centerXShift = centerXShift;
|
|
154
|
-
return this;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// Check if tickable is center aligned. */
|
|
158
|
-
isCenterAligned(): boolean {
|
|
159
|
-
return this.alignCenter;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// Set/unset center alignment. */
|
|
163
|
-
setCenterAlignment(alignCenter: boolean): this {
|
|
164
|
-
this.alignCenter = alignCenter;
|
|
165
|
-
return this;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Return the associated voice. Every tickable must be associated with a voice.
|
|
170
|
-
* This allows formatters and preFormatter to associate them with the right modifierContexts.
|
|
171
|
-
*/
|
|
172
|
-
getVoice(): Voice {
|
|
173
|
-
return defined(this.voice, 'NoVoice', 'Tickable has no voice.');
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/** Set the associated voice. */
|
|
177
|
-
setVoice(voice: Voice): void {
|
|
178
|
-
this.voice = voice;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/** Get the tuplet. */
|
|
182
|
-
getTuplet(): Tuplet | undefined {
|
|
183
|
-
return this.tuplet;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/** Return a list of Tuplets. */
|
|
187
|
-
getTupletStack(): Tuplet[] {
|
|
188
|
-
return this.tupletStack;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Reset the specific Tuplet (if this is not provided, all tuplets are reset).
|
|
193
|
-
* Remove any prior tuplets from the tick calculation and
|
|
194
|
-
* reset the intrinsic tick value.
|
|
195
|
-
*/
|
|
196
|
-
resetTuplet(tuplet?: Tuplet): this {
|
|
197
|
-
let noteCount;
|
|
198
|
-
let notesOccupied;
|
|
199
|
-
if (tuplet) {
|
|
200
|
-
const i = this.tupletStack.indexOf(tuplet);
|
|
201
|
-
if (i !== -1) {
|
|
202
|
-
this.tupletStack.splice(i, 1);
|
|
203
|
-
noteCount = tuplet.getNoteCount();
|
|
204
|
-
notesOccupied = tuplet.getNotesOccupied();
|
|
205
|
-
|
|
206
|
-
// Revert old multiplier by inverting numerator & denom.:
|
|
207
|
-
this.applyTickMultiplier(noteCount, notesOccupied);
|
|
208
|
-
}
|
|
209
|
-
return this;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
while (this.tupletStack.length) {
|
|
213
|
-
tuplet = this.tupletStack.pop() as Tuplet;
|
|
214
|
-
noteCount = tuplet.getNoteCount();
|
|
215
|
-
notesOccupied = tuplet.getNotesOccupied();
|
|
216
|
-
|
|
217
|
-
// Revert old multiplier by inverting numerator & denom.:
|
|
218
|
-
this.applyTickMultiplier(noteCount, notesOccupied);
|
|
219
|
-
}
|
|
220
|
-
return this;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/** Attach to new tuplet. */
|
|
224
|
-
setTuplet(tuplet: Tuplet): this {
|
|
225
|
-
if (tuplet) {
|
|
226
|
-
this.tupletStack.push(tuplet);
|
|
227
|
-
|
|
228
|
-
const noteCount = tuplet.getNoteCount();
|
|
229
|
-
const notesOccupied = tuplet.getNotesOccupied();
|
|
230
|
-
|
|
231
|
-
this.applyTickMultiplier(notesOccupied, noteCount);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
this.tuplet = tuplet;
|
|
235
|
-
|
|
236
|
-
return this;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Add self to the provided ModifierContext `mc`.
|
|
241
|
-
* If this tickable has modifiers, set modifierContext.
|
|
242
|
-
* @returns this
|
|
243
|
-
*/
|
|
244
|
-
addToModifierContext(mc: ModifierContext): this {
|
|
245
|
-
this.modifierContext = mc;
|
|
246
|
-
for (let i = 0; i < this.modifiers.length; ++i) {
|
|
247
|
-
this.modifierContext.addMember(this.modifiers[i]);
|
|
248
|
-
}
|
|
249
|
-
this.modifierContext.addMember(this);
|
|
250
|
-
this.#preFormatted = false;
|
|
251
|
-
return this;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Optional, if tickable has modifiers, associate a Modifier.
|
|
256
|
-
* @param mod the modifier
|
|
257
|
-
*/
|
|
258
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
259
|
-
addModifier(modifier: Modifier, index: number = 0): this {
|
|
260
|
-
this.modifiers.push(modifier);
|
|
261
|
-
this.#preFormatted = false;
|
|
262
|
-
return this;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/** Get the list of associated modifiers. */
|
|
266
|
-
getModifiers(): Modifier[] {
|
|
267
|
-
return this.modifiers;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/** Set the Tick Context. */
|
|
271
|
-
setTickContext(tc: TickContext): void {
|
|
272
|
-
this.tickContext = tc;
|
|
273
|
-
this.#preFormatted = false;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
checkTickContext(message = 'Tickable has no tick context.'): TickContext {
|
|
277
|
-
return defined(this.tickContext, 'NoTickContext', message);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/** Preformat the Tickable. */
|
|
281
|
-
preFormat(): void {
|
|
282
|
-
if (this.#preFormatted) return;
|
|
283
|
-
|
|
284
|
-
this.width = 0;
|
|
285
|
-
if (this.modifierContext) {
|
|
286
|
-
this.modifierContext.preFormat();
|
|
287
|
-
this.width += this.modifierContext.getWidth();
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/** Set preformatted status. */
|
|
292
|
-
set preFormatted(value: boolean) {
|
|
293
|
-
this.#preFormatted = value;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
get preFormatted(): boolean {
|
|
297
|
-
return this.#preFormatted;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/** Postformat the Tickable. */
|
|
301
|
-
postFormat(): this {
|
|
302
|
-
if (this.#postFormatted) return this;
|
|
303
|
-
this.#postFormatted = true;
|
|
304
|
-
return this;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
/** Set postformatted status. */
|
|
308
|
-
set postFormatted(value: boolean) {
|
|
309
|
-
this.#postFormatted = value;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
get postFormatted(): boolean {
|
|
313
|
-
return this.#postFormatted;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/** Return the intrinsic ticks. */
|
|
317
|
-
getIntrinsicTicks(): number {
|
|
318
|
-
return this.intrinsicTicks;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/** Set the intrinsic ticks. */
|
|
322
|
-
setIntrinsicTicks(intrinsicTicks: number): void {
|
|
323
|
-
this.intrinsicTicks = intrinsicTicks;
|
|
324
|
-
this.ticks = this.tickMultiplier.clone().multiply(this.intrinsicTicks);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/** Get the tick multiplier. */
|
|
328
|
-
getTickMultiplier(): Fraction {
|
|
329
|
-
return this.tickMultiplier;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
/** Apply a tick multiplier. */
|
|
333
|
-
applyTickMultiplier(numerator: number, denominator: number): void {
|
|
334
|
-
this.tickMultiplier.multiply(numerator, denominator);
|
|
335
|
-
this.ticks = this.tickMultiplier.clone().multiply(this.intrinsicTicks);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
/** Set the duration. */
|
|
339
|
-
setDuration(duration: Fraction): void {
|
|
340
|
-
const ticks = duration.numerator * (Tables.RESOLUTION / duration.denominator);
|
|
341
|
-
this.ticks = this.tickMultiplier.clone().multiply(ticks);
|
|
342
|
-
this.intrinsicTicks = this.ticks.value();
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
getAbsoluteX(): number {
|
|
346
|
-
const tickContext = this.checkTickContext(`Can't getAbsoluteX() without a TickContext.`);
|
|
347
|
-
return tickContext.getX();
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
/** Attach this note to a modifier context. */
|
|
351
|
-
setModifierContext(mc?: ModifierContext): this {
|
|
352
|
-
this.modifierContext = mc;
|
|
353
|
-
return this;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
/** Get `ModifierContext`. */
|
|
357
|
-
getModifierContext(): ModifierContext | undefined {
|
|
358
|
-
return this.modifierContext;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
/** Check and get `ModifierContext`. */
|
|
362
|
-
checkModifierContext(): ModifierContext {
|
|
363
|
-
return defined(this.modifierContext, 'NoModifierContext', 'No modifier context attached to this tickable.');
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
/** Get the target stave. */
|
|
367
|
-
abstract getStave(): Stave | undefined;
|
|
368
|
-
|
|
369
|
-
/** Set the target stave. */
|
|
370
|
-
abstract setStave(stave: Stave): this;
|
|
371
|
-
|
|
372
|
-
// eslint-disable-next-line
|
|
373
|
-
abstract getMetrics(): any;
|
|
374
|
-
}
|
package/src/tickcontext.ts
DELETED
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
|
|
2
|
-
//
|
|
3
|
-
// ## Description
|
|
4
|
-
// A formatter for abstract tickable objects, such as notes, chords,
|
|
5
|
-
// tabs, etc.
|
|
6
|
-
|
|
7
|
-
import { Fraction } from './fraction';
|
|
8
|
-
import { NoteMetrics } from './note';
|
|
9
|
-
import { Tickable } from './tickable';
|
|
10
|
-
import { RuntimeError } from './util';
|
|
11
|
-
|
|
12
|
-
export interface TickContextMetrics extends NoteMetrics {
|
|
13
|
-
totalLeftPx: number;
|
|
14
|
-
totalRightPx: number;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface TickContextOptions {
|
|
18
|
-
tickID: number;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* TickContext formats abstract tickable objects, such as notes, chords, tabs, etc.
|
|
23
|
-
*/
|
|
24
|
-
export class TickContext {
|
|
25
|
-
protected readonly tickID: number;
|
|
26
|
-
protected readonly tickables: Tickable[];
|
|
27
|
-
protected readonly tickablesByVoice: Record<string, Tickable>;
|
|
28
|
-
protected currentTick: Fraction;
|
|
29
|
-
protected maxTicks: Fraction;
|
|
30
|
-
protected padding: number;
|
|
31
|
-
protected xBase: number;
|
|
32
|
-
protected x: number;
|
|
33
|
-
protected xOffset: number;
|
|
34
|
-
protected notePx: number;
|
|
35
|
-
protected glyphPx: number;
|
|
36
|
-
protected leftDisplacedHeadPx: number;
|
|
37
|
-
protected rightDisplacedHeadPx: number;
|
|
38
|
-
protected modLeftPx: number;
|
|
39
|
-
protected modRightPx: number;
|
|
40
|
-
protected totalLeftPx: number;
|
|
41
|
-
protected totalRightPx: number;
|
|
42
|
-
protected maxTickable?: Tickable;
|
|
43
|
-
protected minTicks?: Fraction;
|
|
44
|
-
protected minTickable?: Tickable;
|
|
45
|
-
tContexts: TickContext[];
|
|
46
|
-
|
|
47
|
-
protected preFormatted: boolean = false;
|
|
48
|
-
protected postFormatted: boolean = false;
|
|
49
|
-
protected width: number;
|
|
50
|
-
protected formatterMetrics: { freedom: { left: number; right: number } };
|
|
51
|
-
|
|
52
|
-
static getNextContext(tContext: TickContext): TickContext | undefined {
|
|
53
|
-
const contexts = tContext.tContexts;
|
|
54
|
-
const index = contexts.indexOf(tContext);
|
|
55
|
-
|
|
56
|
-
if (index + 1 < contexts.length) return contexts[index + 1];
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
constructor(options?: TickContextOptions) {
|
|
60
|
-
this.tickID = options && options.tickID ? options.tickID : 0;
|
|
61
|
-
this.currentTick = new Fraction(0, 1);
|
|
62
|
-
|
|
63
|
-
this.maxTicks = new Fraction(0, 1);
|
|
64
|
-
this.maxTickable = undefined; // Biggest tickable
|
|
65
|
-
this.minTicks = undefined; // this can remian null if all tickables have ignoreTicks
|
|
66
|
-
this.minTickable = undefined;
|
|
67
|
-
|
|
68
|
-
this.padding = 1; // padding on each side (width += padding * 2)
|
|
69
|
-
this.x = 0;
|
|
70
|
-
this.xBase = 0; // base x position without xOffset
|
|
71
|
-
this.xOffset = 0; // xBase and xOffset are an alternative way to describe x (x = xB + xO)
|
|
72
|
-
this.tickables = []; // Notes, tabs, chords, lyrics.
|
|
73
|
-
this.tickablesByVoice = {}; // Tickables indexed by voice number
|
|
74
|
-
|
|
75
|
-
// Formatting metrics
|
|
76
|
-
this.notePx = 0; // width of widest note in this context
|
|
77
|
-
this.glyphPx = 0; // width of glyph (note head)
|
|
78
|
-
this.leftDisplacedHeadPx = 0; // Extra left pixels for displaced notes
|
|
79
|
-
this.rightDisplacedHeadPx = 0; // Extra right pixels for displaced notes
|
|
80
|
-
this.modLeftPx = 0; // Left modifier pixels
|
|
81
|
-
this.modRightPx = 0; // Right modifier pixels
|
|
82
|
-
this.totalLeftPx = 0; // Total left pixels
|
|
83
|
-
this.totalRightPx = 0; // Total right pixels
|
|
84
|
-
this.tContexts = []; // Parent array of tick contexts
|
|
85
|
-
|
|
86
|
-
this.width = 0;
|
|
87
|
-
this.formatterMetrics = {
|
|
88
|
-
// The freedom of a tickcontext is the distance it can move without colliding
|
|
89
|
-
// with neighboring elements. A formatter can set these values during its
|
|
90
|
-
// formatting pass, which a different formatter can then use to fine tune.
|
|
91
|
-
freedom: { left: 0, right: 0 },
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
getTickID(): number {
|
|
96
|
-
return this.tickID;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
getX(): number {
|
|
100
|
-
return this.x;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
setX(x: number): this {
|
|
104
|
-
this.x = x;
|
|
105
|
-
this.xBase = x;
|
|
106
|
-
this.xOffset = 0;
|
|
107
|
-
return this;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
getXBase(): number {
|
|
111
|
-
return this.xBase;
|
|
112
|
-
} // use of xBase and xOffset is optional, avoids offset creep
|
|
113
|
-
|
|
114
|
-
setXBase(xBase: number): void {
|
|
115
|
-
this.xBase = xBase;
|
|
116
|
-
this.x = xBase + this.xOffset;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
getXOffset(): number {
|
|
120
|
-
return this.xOffset;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
setXOffset(xOffset: number): void {
|
|
124
|
-
this.xOffset = xOffset;
|
|
125
|
-
this.x = this.xBase + xOffset;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
getWidth(): number {
|
|
129
|
-
return this.width + this.padding * 2;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
setPadding(padding: number): this {
|
|
133
|
-
this.padding = padding;
|
|
134
|
-
return this;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
getMaxTicks(): Fraction {
|
|
138
|
-
return this.maxTicks;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
getMinTicks(): Fraction | undefined {
|
|
142
|
-
return this.minTicks;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
getMaxTickable(): Tickable | undefined {
|
|
146
|
-
return this.maxTickable;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
getMinTickable(): Tickable | undefined {
|
|
150
|
-
return this.minTickable;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
getTickables(): Tickable[] {
|
|
154
|
-
return this.tickables;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Introduced on 2020-04-17 as getTickablesForVoice(voiceIndex).
|
|
159
|
-
* https://github.com/0xfe/vexflow/blame/dc97b0cc5bb93171c0038638c34362dc958222ca/src/tickcontext.js#L63
|
|
160
|
-
* Renamed on 2021-08-05 to getTickableForVoice(voiceIndex). Method renamed to singular, since it returns one Tickable.
|
|
161
|
-
*/
|
|
162
|
-
getTickableForVoice(voiceIndex: number): Tickable {
|
|
163
|
-
return this.tickablesByVoice[voiceIndex];
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
getTickablesByVoice(): Record<string, Tickable> {
|
|
167
|
-
return this.tickablesByVoice;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
getCenterAlignedTickables(): Tickable[] {
|
|
171
|
-
return this.tickables.filter((tickable) => tickable.isCenterAligned());
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/** Gets widths context, note and left/right modifiers for formatting. */
|
|
175
|
-
getMetrics(): TickContextMetrics {
|
|
176
|
-
const {
|
|
177
|
-
width,
|
|
178
|
-
glyphPx,
|
|
179
|
-
notePx,
|
|
180
|
-
leftDisplacedHeadPx,
|
|
181
|
-
rightDisplacedHeadPx,
|
|
182
|
-
modLeftPx,
|
|
183
|
-
modRightPx,
|
|
184
|
-
totalLeftPx,
|
|
185
|
-
totalRightPx,
|
|
186
|
-
} = this;
|
|
187
|
-
return {
|
|
188
|
-
width, // Width of largest tickable in context
|
|
189
|
-
glyphPx, // Width of largest glyph (note head)
|
|
190
|
-
notePx, // Width of notehead + stem
|
|
191
|
-
leftDisplacedHeadPx, // Left modifiers
|
|
192
|
-
rightDisplacedHeadPx, // Right modifiers
|
|
193
|
-
modLeftPx,
|
|
194
|
-
modRightPx,
|
|
195
|
-
totalLeftPx,
|
|
196
|
-
totalRightPx,
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
getCurrentTick(): Fraction {
|
|
201
|
-
return this.currentTick;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
setCurrentTick(tick: Fraction): void {
|
|
205
|
-
this.currentTick = tick;
|
|
206
|
-
this.preFormatted = false;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
addTickable(tickable: Tickable, voiceIndex?: number): this {
|
|
210
|
-
if (!tickable) {
|
|
211
|
-
throw new RuntimeError('BadArgument', 'Invalid tickable added.');
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (!tickable.shouldIgnoreTicks()) {
|
|
215
|
-
const ticks = tickable.getTicks();
|
|
216
|
-
|
|
217
|
-
if (ticks.greaterThan(this.maxTicks)) {
|
|
218
|
-
this.maxTicks = ticks.clone();
|
|
219
|
-
this.maxTickable = tickable;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (this.minTicks === undefined) {
|
|
223
|
-
this.minTicks = ticks.clone();
|
|
224
|
-
this.minTickable = tickable;
|
|
225
|
-
} else if (ticks.lessThan(this.minTicks)) {
|
|
226
|
-
this.minTicks = ticks.clone();
|
|
227
|
-
this.minTickable = tickable;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
tickable.setTickContext(this);
|
|
232
|
-
this.tickables.push(tickable);
|
|
233
|
-
this.tickablesByVoice[voiceIndex ?? 0] = tickable;
|
|
234
|
-
this.preFormatted = false;
|
|
235
|
-
return this;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
preFormat(): this {
|
|
239
|
-
if (this.preFormatted) return this;
|
|
240
|
-
|
|
241
|
-
for (let i = 0; i < this.tickables.length; ++i) {
|
|
242
|
-
const tickable = this.tickables[i];
|
|
243
|
-
tickable.preFormat();
|
|
244
|
-
const metrics = tickable.getMetrics();
|
|
245
|
-
|
|
246
|
-
// Maintain max displaced head pixels from all tickables in the context
|
|
247
|
-
this.leftDisplacedHeadPx = Math.max(this.leftDisplacedHeadPx, metrics.leftDisplacedHeadPx);
|
|
248
|
-
this.rightDisplacedHeadPx = Math.max(this.rightDisplacedHeadPx, metrics.rightDisplacedHeadPx);
|
|
249
|
-
|
|
250
|
-
// Maintain the widest note for all tickables in the context
|
|
251
|
-
this.notePx = Math.max(this.notePx, metrics.notePx);
|
|
252
|
-
|
|
253
|
-
// Maintain the widest note head
|
|
254
|
-
this.glyphPx = Math.max(this.glyphPx, metrics.glyphWidth ?? 0);
|
|
255
|
-
|
|
256
|
-
// Total modifier shift
|
|
257
|
-
this.modLeftPx = Math.max(this.modLeftPx, metrics.modLeftPx);
|
|
258
|
-
this.modRightPx = Math.max(this.modRightPx, metrics.modRightPx);
|
|
259
|
-
|
|
260
|
-
// Total shift
|
|
261
|
-
this.totalLeftPx = Math.max(this.totalLeftPx, metrics.modLeftPx + metrics.leftDisplacedHeadPx);
|
|
262
|
-
this.totalRightPx = Math.max(this.totalRightPx, metrics.modRightPx + metrics.rightDisplacedHeadPx);
|
|
263
|
-
|
|
264
|
-
// Recalculate the tick context total width
|
|
265
|
-
this.width = this.notePx + this.totalLeftPx + this.totalRightPx;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
return this;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
postFormat(): this {
|
|
272
|
-
if (this.postFormatted) return this;
|
|
273
|
-
this.postFormatted = true;
|
|
274
|
-
return this;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
getFormatterMetrics(): { freedom: { left: number; right: number } } {
|
|
278
|
-
return this.formatterMetrics;
|
|
279
|
-
}
|
|
280
|
-
}
|