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/modifier.ts
DELETED
|
@@ -1,216 +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 { ModifierContext } from './modifiercontext';
|
|
6
|
-
import { Note } from './note';
|
|
7
|
-
import { Category } from './typeguard';
|
|
8
|
-
import { defined, RuntimeError } from './util';
|
|
9
|
-
|
|
10
|
-
export enum ModifierPosition {
|
|
11
|
-
CENTER = 0,
|
|
12
|
-
LEFT = 1,
|
|
13
|
-
RIGHT = 2,
|
|
14
|
-
ABOVE = 3,
|
|
15
|
-
BELOW = 4,
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// To enable logging for this class. Set `VexFlow.Modifier.DEBUG` to `true`.
|
|
19
|
-
// function L(...args) { if (Modifier.DEBUG) log('VexFlow.Modifier', args); }
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* `Modifier` is an abstract interface for notational elements that modify
|
|
23
|
-
* a `Note`. Examples of modifiers are `Accidental`, `Annotation`, `Stroke`, etc.
|
|
24
|
-
*
|
|
25
|
-
* For a `Modifier` instance to be positioned correctly, it must be part of
|
|
26
|
-
* a `ModifierContext`. All modifiers in the same context are rendered relative to
|
|
27
|
-
* one another.
|
|
28
|
-
*
|
|
29
|
-
* Typically, all modifiers to a note are part of the same `ModifierContext` instance. Also,
|
|
30
|
-
* in multi-voice staves, all modifiers to notes on the same `tick` are part of the same
|
|
31
|
-
* `ModifierContext`. This ensures that multiple voices don't trample all over each other.
|
|
32
|
-
*/
|
|
33
|
-
export class Modifier extends Element {
|
|
34
|
-
/**
|
|
35
|
-
* Modifiers category string. Every modifier has a different category.
|
|
36
|
-
* The `ModifierContext` uses this to determine the type and order of the modifiers.
|
|
37
|
-
*/
|
|
38
|
-
static get CATEGORY(): string {
|
|
39
|
-
return Category.Modifier;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** Modifiers can be positioned almost anywhere, relative to a note. */
|
|
43
|
-
static get Position(): typeof ModifierPosition {
|
|
44
|
-
return ModifierPosition;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
static get PositionString(): Record<string, number> {
|
|
48
|
-
return {
|
|
49
|
-
center: ModifierPosition.CENTER,
|
|
50
|
-
above: ModifierPosition.ABOVE,
|
|
51
|
-
below: ModifierPosition.BELOW,
|
|
52
|
-
left: ModifierPosition.LEFT,
|
|
53
|
-
right: ModifierPosition.RIGHT,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Modifiers are attached to a note and an index. An index is a specific head in a chord.
|
|
58
|
-
protected note?: Note;
|
|
59
|
-
protected index?: number;
|
|
60
|
-
|
|
61
|
-
protected textLine: number;
|
|
62
|
-
protected position: ModifierPosition;
|
|
63
|
-
|
|
64
|
-
#spacingFromNextModifier: number;
|
|
65
|
-
#modifierContext?: ModifierContext;
|
|
66
|
-
|
|
67
|
-
constructor() {
|
|
68
|
-
super();
|
|
69
|
-
|
|
70
|
-
this.width = 0;
|
|
71
|
-
|
|
72
|
-
// The `textLine` is reserved space above or below a stave.
|
|
73
|
-
this.textLine = 0;
|
|
74
|
-
this.position = Modifier.Position.LEFT;
|
|
75
|
-
this.#spacingFromNextModifier = 0;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/** Called when position changes. */
|
|
79
|
-
protected reset(): void {
|
|
80
|
-
// DO NOTHING.
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/** Get attached note (`StaveNote`, `TabNote`, etc.) */
|
|
84
|
-
getNote(): Note {
|
|
85
|
-
return defined(this.note, 'NoNote', 'Modifier has no note.');
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Used in draw() to check and get the attached note (`StaveNote`, `TabNote`, etc.).
|
|
90
|
-
* Also verifies that the index is valid.
|
|
91
|
-
*/
|
|
92
|
-
checkAttachedNote(): Note {
|
|
93
|
-
const category = this.getCategory();
|
|
94
|
-
defined(this.index, 'NoIndex', `Can't draw ${category} without an index.`);
|
|
95
|
-
return defined(this.note, 'NoNote', `Can't draw ${category} without a note.`);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Set attached note.
|
|
100
|
-
* @param note (`StaveNote`, `TabNote`, etc.)
|
|
101
|
-
*/
|
|
102
|
-
setNote(note: Note): this {
|
|
103
|
-
this.note = note;
|
|
104
|
-
return this;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/** Get note index, which is a specific note in a chord. */
|
|
108
|
-
getIndex(): number | undefined {
|
|
109
|
-
return this.index;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/** Check and get note index, which is a specific note in a chord. */
|
|
113
|
-
checkIndex(): number {
|
|
114
|
-
return defined(this.index, 'NoIndex', 'Modifier has an invalid index.');
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/** Set note index, which is a specific note in a chord. */
|
|
118
|
-
setIndex(index: number): this {
|
|
119
|
-
this.index = index;
|
|
120
|
-
return this;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/** Get `ModifierContext`. */
|
|
124
|
-
getModifierContext(): ModifierContext | undefined {
|
|
125
|
-
return this.#modifierContext;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/** Check and get `ModifierContext`. */
|
|
129
|
-
checkModifierContext(): ModifierContext {
|
|
130
|
-
return defined(this.#modifierContext, 'NoModifierContext', 'Modifier Context Required');
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/** Every modifier must be part of a `ModifierContext`. */
|
|
134
|
-
setModifierContext(c: ModifierContext): this {
|
|
135
|
-
this.#modifierContext = c;
|
|
136
|
-
return this;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/** Get position. */
|
|
140
|
-
getPosition(): number {
|
|
141
|
-
return this.position;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Set position.
|
|
146
|
-
* @param position CENTER | LEFT | RIGHT | ABOVE | BELOW
|
|
147
|
-
*/
|
|
148
|
-
setPosition(position: string | number): this {
|
|
149
|
-
this.position = typeof position === 'string' ? Modifier.PositionString[position] : position;
|
|
150
|
-
this.reset();
|
|
151
|
-
return this;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/** Set the `textLine` for the modifier. */
|
|
155
|
-
setTextLine(line: number): this {
|
|
156
|
-
this.textLine = line;
|
|
157
|
-
return this;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/** Shift modifier down `y` pixels. Negative values shift up. */
|
|
161
|
-
setYShift(y: number): this {
|
|
162
|
-
this.yShift = y;
|
|
163
|
-
return this;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/** Set spacing from next modifier. */
|
|
167
|
-
setSpacingFromNextModifier(x: number): void {
|
|
168
|
-
this.#spacingFromNextModifier = x;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/** Get spacing from next modifier. */
|
|
172
|
-
getSpacingFromNextModifier(): number {
|
|
173
|
-
return this.#spacingFromNextModifier;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Shift modifier `x` pixels in the direction of the modifier. Negative values
|
|
178
|
-
* shift reverse.
|
|
179
|
-
*/
|
|
180
|
-
setXShift(x: number): this {
|
|
181
|
-
this.xShift = 0;
|
|
182
|
-
if (this.position === Modifier.Position.LEFT) {
|
|
183
|
-
this.xShift -= x;
|
|
184
|
-
} else {
|
|
185
|
-
this.xShift += x;
|
|
186
|
-
}
|
|
187
|
-
return this;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/** Get shift modifier `x` */
|
|
191
|
-
getXShift(): number {
|
|
192
|
-
return this.xShift;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/** Render the modifier onto the canvas. */
|
|
196
|
-
draw(): void {
|
|
197
|
-
this.checkContext();
|
|
198
|
-
throw new RuntimeError('NotImplemented', 'draw() not implemented for this modifier.');
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// aligns sub notes of NoteSubGroup (or GraceNoteGroup) to the main note with correct x-offset
|
|
202
|
-
alignSubNotesWithNote(subNotes: Note[], note: Note): void {
|
|
203
|
-
// Shift over the tick contexts of each note
|
|
204
|
-
const tickContext = note.getTickContext();
|
|
205
|
-
const metrics = tickContext.getMetrics();
|
|
206
|
-
const stave = note.getStave();
|
|
207
|
-
const subNoteXOffset =
|
|
208
|
-
tickContext.getX() - metrics.modLeftPx - metrics.modRightPx + this.getSpacingFromNextModifier();
|
|
209
|
-
|
|
210
|
-
subNotes.forEach((subNote) => {
|
|
211
|
-
const subTickContext = subNote.getTickContext();
|
|
212
|
-
if (stave) subNote.setStave(stave);
|
|
213
|
-
subTickContext.setXOffset(subNoteXOffset); // don't touch baseX to avoid shift each render
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
}
|
package/src/modifiercontext.ts
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
|
|
2
|
-
//
|
|
3
|
-
// ## Description
|
|
4
|
-
//
|
|
5
|
-
// This class implements various types of members to notes (e.g. bends,
|
|
6
|
-
// fingering positions etc.). The ModifierContext works with tickables
|
|
7
|
-
// that are at the same tick to ensure that they and their modifiers
|
|
8
|
-
// all have proper alignment. (Note that the ModifierContext also
|
|
9
|
-
// runs the spacing of the tickable).
|
|
10
|
-
//
|
|
11
|
-
// see https://github.com/0xfe/vexflow/wiki/How-Formatting-Works
|
|
12
|
-
|
|
13
|
-
import { Accidental } from './accidental';
|
|
14
|
-
import { Annotation } from './annotation';
|
|
15
|
-
import { Articulation } from './articulation';
|
|
16
|
-
import { Bend } from './bend';
|
|
17
|
-
import { ChordSymbol } from './chordsymbol';
|
|
18
|
-
import { Dot } from './dot';
|
|
19
|
-
import { FretHandFinger } from './frethandfinger';
|
|
20
|
-
import { GraceNoteGroup } from './gracenotegroup';
|
|
21
|
-
import { Modifier } from './modifier';
|
|
22
|
-
import { Note } from './note';
|
|
23
|
-
import { NoteSubGroup } from './notesubgroup';
|
|
24
|
-
import { Ornament } from './ornament';
|
|
25
|
-
import { Parenthesis } from './parenthesis';
|
|
26
|
-
import { StaveNote } from './stavenote';
|
|
27
|
-
import { StringNumber } from './stringnumber';
|
|
28
|
-
import { Stroke } from './strokes';
|
|
29
|
-
import { TabNote } from './tabnote';
|
|
30
|
-
import { Tickable } from './tickable';
|
|
31
|
-
import { Category } from './typeguard';
|
|
32
|
-
import { log, RuntimeError } from './util';
|
|
33
|
-
import { Vibrato } from './vibrato';
|
|
34
|
-
|
|
35
|
-
export interface ModifierContextState {
|
|
36
|
-
leftShift: number;
|
|
37
|
-
rightShift: number;
|
|
38
|
-
textLine: number;
|
|
39
|
-
topTextLine: number;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export interface ModifierContextMetrics {
|
|
43
|
-
width: number;
|
|
44
|
-
spacing: number;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export type ModifierContextMember = Tickable | Modifier | StaveNote | TabNote;
|
|
48
|
-
|
|
49
|
-
// To enable logging for this class. Set `VexFlow.ModifierContext.DEBUG` to `true`.
|
|
50
|
-
// eslint-disable-next-line
|
|
51
|
-
function L(...args: any[]) {
|
|
52
|
-
if (ModifierContext.DEBUG) log('VexFlow.ModifierContext', args);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export class ModifierContext {
|
|
56
|
-
static DEBUG: boolean = false;
|
|
57
|
-
|
|
58
|
-
// Formatting data.
|
|
59
|
-
protected state: ModifierContextState = {
|
|
60
|
-
leftShift: 0,
|
|
61
|
-
rightShift: 0,
|
|
62
|
-
textLine: 0,
|
|
63
|
-
topTextLine: 0,
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
// Current members -- a mapping of Category (string) to a list of Tickables, Modifiers,
|
|
67
|
-
// StaveNotes, TabNotes, etc.
|
|
68
|
-
protected members: Record<string, ModifierContextMember[]> = {};
|
|
69
|
-
|
|
70
|
-
protected preFormatted: boolean = false;
|
|
71
|
-
protected postFormatted: boolean = false;
|
|
72
|
-
protected formatted: boolean = false;
|
|
73
|
-
|
|
74
|
-
protected width: number = 0;
|
|
75
|
-
protected spacing: number = 0;
|
|
76
|
-
|
|
77
|
-
addModifier(member: ModifierContextMember): this {
|
|
78
|
-
L('addModifier is deprecated, use addMember instead.');
|
|
79
|
-
return this.addMember(member);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* this.members maps CATEGORY strings to arrays of Tickable | Modifier | StaveNote | TabNote.
|
|
84
|
-
* Here we add a new member to this.members, and create a new array if needed.
|
|
85
|
-
* @param member
|
|
86
|
-
* @returns this
|
|
87
|
-
*/
|
|
88
|
-
addMember(member: ModifierContextMember): this {
|
|
89
|
-
const category = member.getCategory();
|
|
90
|
-
if (!this.members[category]) {
|
|
91
|
-
this.members[category] = [];
|
|
92
|
-
}
|
|
93
|
-
this.members[category].push(member);
|
|
94
|
-
member.setModifierContext(this);
|
|
95
|
-
this.preFormatted = false;
|
|
96
|
-
return this;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* @deprecated
|
|
101
|
-
*/
|
|
102
|
-
getModifiers(category: string): ModifierContextMember[] {
|
|
103
|
-
L('getModifiers is deprecated, use getMembers instead.');
|
|
104
|
-
return this.getMembers(category);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
getMembers(category: string): ModifierContextMember[] {
|
|
108
|
-
return this.members[category] ?? [];
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Get the width of the entire
|
|
113
|
-
*/
|
|
114
|
-
getWidth(): number {
|
|
115
|
-
return this.width;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
getLeftShift(): number {
|
|
119
|
-
return this.state.leftShift;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
getRightShift(): number {
|
|
123
|
-
return this.state.rightShift;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
getState(): ModifierContextState {
|
|
127
|
-
return this.state;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
getMetrics(): ModifierContextMetrics {
|
|
131
|
-
if (!this.formatted) {
|
|
132
|
-
throw new RuntimeError('UnformattedMember', 'Unformatted member has no metrics.');
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return {
|
|
136
|
-
width: this.state.leftShift + this.state.rightShift + this.spacing,
|
|
137
|
-
spacing: this.spacing,
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
preFormat(): void {
|
|
142
|
-
if (this.preFormatted) return;
|
|
143
|
-
L('Preformatting ModifierContext');
|
|
144
|
-
|
|
145
|
-
const state = this.state;
|
|
146
|
-
const members = this.members;
|
|
147
|
-
|
|
148
|
-
// The ordering below determines when different members are formatted and rendered.
|
|
149
|
-
StaveNote.format(members[Category.StaveNote] as StaveNote[], state);
|
|
150
|
-
Parenthesis.format(members[Category.Parenthesis] as Parenthesis[], state);
|
|
151
|
-
Dot.format(members[Category.Dot] as Dot[], state);
|
|
152
|
-
FretHandFinger.format(members[Category.FretHandFinger] as FretHandFinger[], state);
|
|
153
|
-
Accidental.format(members[Category.Accidental] as Accidental[], state);
|
|
154
|
-
Stroke.format(members[Category.Stroke] as Stroke[], state);
|
|
155
|
-
GraceNoteGroup.format(members[Category.GraceNoteGroup] as GraceNoteGroup[], state);
|
|
156
|
-
NoteSubGroup.format(members[Category.NoteSubGroup] as NoteSubGroup[], state);
|
|
157
|
-
StringNumber.format(members[Category.StringNumber] as StringNumber[], state);
|
|
158
|
-
Articulation.format(members[Category.Articulation] as Articulation[], state);
|
|
159
|
-
Ornament.format(members[Category.Ornament] as Ornament[], state);
|
|
160
|
-
Annotation.format(members[Category.Annotation] as Annotation[], state);
|
|
161
|
-
ChordSymbol.format(members[Category.ChordSymbol] as ChordSymbol[], state);
|
|
162
|
-
Bend.format(members[Category.Bend] as Bend[], state);
|
|
163
|
-
Vibrato.format(members[Category.Vibrato] as Vibrato[], state, this);
|
|
164
|
-
|
|
165
|
-
// Update width of this member context
|
|
166
|
-
this.width = state.leftShift + state.rightShift;
|
|
167
|
-
this.preFormatted = true;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
postFormat(): void {
|
|
171
|
-
if (this.postFormatted) return;
|
|
172
|
-
L('Postformatting ModifierContext');
|
|
173
|
-
|
|
174
|
-
// If post-formatting is required for an element, add more lines below.
|
|
175
|
-
StaveNote.postFormat(this.getMembers(Category.StaveNote) as Note[]);
|
|
176
|
-
}
|
|
177
|
-
}
|
package/src/multimeasurerest.ts
DELETED
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
|
|
2
|
-
//
|
|
3
|
-
// This class implements multiple measure rests.
|
|
4
|
-
|
|
5
|
-
import { Element } from './element';
|
|
6
|
-
import { Glyphs } from './glyphs';
|
|
7
|
-
import { Metrics } from './metrics';
|
|
8
|
-
import { RenderContext } from './rendercontext';
|
|
9
|
-
import { Stave } from './stave';
|
|
10
|
-
import { StaveModifierPosition } from './stavemodifier';
|
|
11
|
-
import { Tables } from './tables';
|
|
12
|
-
import { Category, isBarline } from './typeguard';
|
|
13
|
-
import { defined } from './util';
|
|
14
|
-
|
|
15
|
-
export interface MultimeasureRestRenderOptions {
|
|
16
|
-
/** Extracted by Factory.MultiMeasureRest() and passed to the MultiMeasureRest constructor. */
|
|
17
|
-
numberOfMeasures: number;
|
|
18
|
-
|
|
19
|
-
/** Use rest symbols. Defaults to `false`, which renders a thick horizontal line with serifs at both ends. */
|
|
20
|
-
useSymbols?: boolean;
|
|
21
|
-
|
|
22
|
-
/** Horizontal spacing between rest symbol glyphs (if `useSymbols` is `true`).*/
|
|
23
|
-
symbolSpacing?: number;
|
|
24
|
-
|
|
25
|
-
/** Show the number of measures at the top. Defaults to `true`. */
|
|
26
|
-
showNumber?: boolean;
|
|
27
|
-
|
|
28
|
-
/** Vertical position of the "number of measures" text (measured in stave lines). Defaults to -0.5, which is above the stave. 6.5 is below the stave. */
|
|
29
|
-
numberLine?: number;
|
|
30
|
-
|
|
31
|
-
/** Font size of the "number of measures" text. */
|
|
32
|
-
numberGlyphPoint?: number;
|
|
33
|
-
|
|
34
|
-
/** Left padding from `stave.getX()`. */
|
|
35
|
-
paddingLeft?: number;
|
|
36
|
-
|
|
37
|
-
/** Right padding from `stave.getX() + stave.getWidth()` */
|
|
38
|
-
paddingRight?: number;
|
|
39
|
-
|
|
40
|
-
/** Vertical position of the rest line or symbols, expressed as stave lines. Default: 2. The top stave line is 1, and the bottom stave line is 5. */
|
|
41
|
-
line?: number;
|
|
42
|
-
|
|
43
|
-
/** Defaults to the number of vertical pixels between stave lines. Used for serif height or 2-bar / 4-bar symbol height. */
|
|
44
|
-
spacingBetweenLinesPx?: number;
|
|
45
|
-
|
|
46
|
-
/** Size of the semibreve (1-bar) rest symbol. Other symbols are scaled accordingly. */
|
|
47
|
-
semibreveRestGlyphScale?: number;
|
|
48
|
-
|
|
49
|
-
/** Thickness of the rest line. Used when `useSymbols` is false. Defaults to half the space between stave lines. */
|
|
50
|
-
lineThickness?: number;
|
|
51
|
-
|
|
52
|
-
/** Thickness of the rest line's serif. Used when `useSymbols` is false. */
|
|
53
|
-
serifThickness?: number;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export class MultiMeasureRest extends Element {
|
|
57
|
-
static get CATEGORY(): string {
|
|
58
|
-
return Category.MultiMeasureRest;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public renderOptions: Required<MultimeasureRestRenderOptions>;
|
|
62
|
-
protected xs = { left: NaN, right: NaN };
|
|
63
|
-
protected numberOfMeasures: number;
|
|
64
|
-
|
|
65
|
-
protected stave?: Stave;
|
|
66
|
-
|
|
67
|
-
#hasPaddingLeft = false;
|
|
68
|
-
#hasPaddingRight = false;
|
|
69
|
-
#hasLineThickness = false;
|
|
70
|
-
#hasSymbolSpacing = false;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
*
|
|
74
|
-
* @param numberOfMeasures Number of measures.
|
|
75
|
-
* @param options The options object.
|
|
76
|
-
*/
|
|
77
|
-
constructor(numberOfMeasures: number, options: MultimeasureRestRenderOptions) {
|
|
78
|
-
super();
|
|
79
|
-
const fontSize = options.numberGlyphPoint ?? Metrics.get('MultiMeasureRest.fontSize'); // same as TimeSignature.
|
|
80
|
-
this.fontInfo.size = fontSize;
|
|
81
|
-
|
|
82
|
-
this.numberOfMeasures = numberOfMeasures;
|
|
83
|
-
this.text = '';
|
|
84
|
-
const t = `${this.numberOfMeasures}`;
|
|
85
|
-
for (const digit of t) {
|
|
86
|
-
// 0xe080 is timeSig0. We calculate the code point for timeSigN to assemble the digits via SMuFL glyphs.
|
|
87
|
-
this.text += String.fromCodePoint(0xe080 + Number(digit));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Keep track of whether these four options were provided.
|
|
91
|
-
this.#hasPaddingLeft = typeof options.paddingLeft === 'number';
|
|
92
|
-
this.#hasPaddingRight = typeof options.paddingRight === 'number';
|
|
93
|
-
this.#hasLineThickness = typeof options.lineThickness === 'number';
|
|
94
|
-
this.#hasSymbolSpacing = typeof options.symbolSpacing === 'number';
|
|
95
|
-
|
|
96
|
-
this.renderOptions = {
|
|
97
|
-
useSymbols: false,
|
|
98
|
-
showNumber: true,
|
|
99
|
-
numberLine: -0.5,
|
|
100
|
-
numberGlyphPoint: fontSize,
|
|
101
|
-
line: 2,
|
|
102
|
-
spacingBetweenLinesPx: Tables.STAVE_LINE_DISTANCE, // same as Stave.
|
|
103
|
-
serifThickness: 2,
|
|
104
|
-
semibreveRestGlyphScale: Metrics.get('fontSize'), // same as NoteHead.
|
|
105
|
-
paddingLeft: 0,
|
|
106
|
-
paddingRight: 0,
|
|
107
|
-
lineThickness: 5,
|
|
108
|
-
symbolSpacing: 0,
|
|
109
|
-
...options,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
getXs(): { left: number; right: number } {
|
|
114
|
-
return this.xs;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
setStave(stave: Stave): this {
|
|
118
|
-
this.stave = stave;
|
|
119
|
-
return this;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
getStave(): Stave | undefined {
|
|
123
|
-
return this.stave;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
checkStave(): Stave {
|
|
127
|
-
return defined(this.stave, 'NoStave', 'No stave attached to instance.');
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
drawLine(stave: Stave, ctx: RenderContext, left: number, right: number): void {
|
|
131
|
-
const options = this.renderOptions;
|
|
132
|
-
|
|
133
|
-
const y = stave.getYForLine(options.line);
|
|
134
|
-
const padding = (right - left) * 0.1;
|
|
135
|
-
left += padding;
|
|
136
|
-
right -= padding;
|
|
137
|
-
let txt = '\ue4ef'; /*restHBarLeft*/
|
|
138
|
-
const el = new Element();
|
|
139
|
-
el.setText(txt);
|
|
140
|
-
// Add middle bars until the right padding is reached
|
|
141
|
-
for (let i = 1; (i + 2) * el.getWidth() + left <= right; i++) {
|
|
142
|
-
txt += '\ue4f0'; /*restHBarMiddle*/
|
|
143
|
-
}
|
|
144
|
-
txt += '\ue4f1'; /*restHBarRight*/
|
|
145
|
-
|
|
146
|
-
el.setText(txt);
|
|
147
|
-
el.renderText(ctx, left + (right - left) * 0.5 - el.getWidth() * 0.5, y);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
drawSymbols(stave: Stave, ctx: RenderContext, left: number, right: number): void {
|
|
151
|
-
const n4 = Math.floor(this.numberOfMeasures / 4);
|
|
152
|
-
const n = this.numberOfMeasures % 4;
|
|
153
|
-
const n2 = Math.floor(n / 2);
|
|
154
|
-
const n1 = n % 2;
|
|
155
|
-
|
|
156
|
-
const options = this.renderOptions;
|
|
157
|
-
|
|
158
|
-
const elMiddle = new Element();
|
|
159
|
-
let txt = '';
|
|
160
|
-
for (let i = 0; i < n4; ++i) {
|
|
161
|
-
txt += Glyphs.restLonga + ' ';
|
|
162
|
-
}
|
|
163
|
-
for (let i = 0; i < n2; ++i) {
|
|
164
|
-
txt += Glyphs.restDoubleWhole + ' ';
|
|
165
|
-
}
|
|
166
|
-
elMiddle.setText(txt);
|
|
167
|
-
const elTop = new Element();
|
|
168
|
-
txt = '';
|
|
169
|
-
for (let i = 0; i < n1; ++i) {
|
|
170
|
-
txt += Glyphs.restWhole + ' ';
|
|
171
|
-
}
|
|
172
|
-
elTop.setText(txt);
|
|
173
|
-
|
|
174
|
-
const width = elMiddle.getWidth() + elTop.getWidth();
|
|
175
|
-
let x = left + (right - left) * 0.5 - width * 0.5;
|
|
176
|
-
const line = options.line;
|
|
177
|
-
const yTop = stave.getYForLine(line - 1);
|
|
178
|
-
const yMiddle = stave.getYForLine(line);
|
|
179
|
-
|
|
180
|
-
elMiddle.renderText(ctx, x, yMiddle);
|
|
181
|
-
x += elMiddle.getWidth();
|
|
182
|
-
elTop.renderText(ctx, x, yTop);
|
|
183
|
-
x += elTop.getWidth();
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
draw(): void {
|
|
187
|
-
const ctx = this.checkContext();
|
|
188
|
-
this.setRendered();
|
|
189
|
-
|
|
190
|
-
const stave = this.checkStave();
|
|
191
|
-
|
|
192
|
-
let left = stave.getNoteStartX();
|
|
193
|
-
let right = stave.getNoteEndX();
|
|
194
|
-
|
|
195
|
-
// FIXME: getNoteStartX() returns x + 5(barline width)
|
|
196
|
-
// getNoteEndX() returns x + width(no barline width)
|
|
197
|
-
// See Stave constructor. How do we fix this?
|
|
198
|
-
// Here, we subtract the barline width.
|
|
199
|
-
const begModifiers = stave.getModifiers(StaveModifierPosition.BEGIN);
|
|
200
|
-
if (begModifiers.length === 1 && isBarline(begModifiers[0])) {
|
|
201
|
-
left -= begModifiers[0].getWidth();
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
const options = this.renderOptions;
|
|
205
|
-
if (this.#hasPaddingLeft) {
|
|
206
|
-
left = stave.getX() + options.paddingLeft;
|
|
207
|
-
}
|
|
208
|
-
if (this.#hasPaddingRight) {
|
|
209
|
-
right = stave.getX() + stave.getWidth() - options.paddingRight;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
this.xs.left = left;
|
|
213
|
-
this.xs.right = right;
|
|
214
|
-
|
|
215
|
-
if (options.useSymbols) {
|
|
216
|
-
this.drawSymbols(stave, ctx, left, right);
|
|
217
|
-
} else {
|
|
218
|
-
this.drawLine(stave, ctx, left, right);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
if (options.showNumber) {
|
|
222
|
-
this.renderText(
|
|
223
|
-
ctx,
|
|
224
|
-
left + (right - left) * 0.5 - this.width * 0.5,
|
|
225
|
-
stave.getYForLine(options.numberLine) - this.height * 0.5
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|