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/stavevolta.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
|
|
2
|
-
// @author: Larry Kuhns 2011
|
|
3
|
-
|
|
4
|
-
import { Stave } from './stave';
|
|
5
|
-
import { StaveModifier } from './stavemodifier';
|
|
6
|
-
import { Category } from './typeguard';
|
|
7
|
-
|
|
8
|
-
export enum VoltaType {
|
|
9
|
-
NONE = 1,
|
|
10
|
-
BEGIN = 2,
|
|
11
|
-
MID = 3,
|
|
12
|
-
END = 4,
|
|
13
|
-
BEGIN_END = 5,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export class Volta extends StaveModifier {
|
|
17
|
-
static get CATEGORY(): string {
|
|
18
|
-
return Category.Volta;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
static get type(): typeof VoltaType {
|
|
22
|
-
return VoltaType;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
protected type: number;
|
|
26
|
-
|
|
27
|
-
constructor(type: number, label: string, x: number, yShift: number) {
|
|
28
|
-
super();
|
|
29
|
-
this.type = type;
|
|
30
|
-
this.x = x;
|
|
31
|
-
this.yShift = yShift;
|
|
32
|
-
this.text = label;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
draw(stave: Stave, x: number): this {
|
|
36
|
-
const ctx = stave.checkContext();
|
|
37
|
-
this.setRendered();
|
|
38
|
-
|
|
39
|
-
let width = stave.getWidth() - x; // don't include x (offset) for width
|
|
40
|
-
const topY = stave.getYForTopText(stave.getNumLines()) + this.yShift;
|
|
41
|
-
const vertHeight = 1.5 * stave.getSpacingBetweenLines();
|
|
42
|
-
switch (this.type) {
|
|
43
|
-
case VoltaType.BEGIN:
|
|
44
|
-
ctx.fillRect(this.x + x, topY, 1, vertHeight);
|
|
45
|
-
break;
|
|
46
|
-
case VoltaType.END:
|
|
47
|
-
width -= 5;
|
|
48
|
-
ctx.fillRect(this.x + x + width, topY, 1, vertHeight);
|
|
49
|
-
break;
|
|
50
|
-
case VoltaType.BEGIN_END:
|
|
51
|
-
width -= 3;
|
|
52
|
-
ctx.fillRect(this.x + x, topY, 1, vertHeight);
|
|
53
|
-
ctx.fillRect(this.x + x + width, topY, 1, vertHeight);
|
|
54
|
-
break;
|
|
55
|
-
default:
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
// If the beginning of a volta, draw measure number
|
|
59
|
-
if (this.type === VoltaType.BEGIN || this.type === VoltaType.BEGIN_END) {
|
|
60
|
-
this.renderText(ctx, x + 5, topY - this.yShift + 15);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
ctx.fillRect(this.x + x, topY, width, 1);
|
|
64
|
-
return this;
|
|
65
|
-
}
|
|
66
|
-
}
|
package/src/stem.ts
DELETED
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
|
|
2
|
-
//
|
|
3
|
-
// ## Description
|
|
4
|
-
// This file implements the `Stem` object. Generally this object is handled
|
|
5
|
-
// by its parent `StemmableNote`.
|
|
6
|
-
|
|
7
|
-
import { BoundingBox } from './boundingbox';
|
|
8
|
-
import { Element } from './element';
|
|
9
|
-
import { Metrics } from './metrics';
|
|
10
|
-
import { Tables } from './tables';
|
|
11
|
-
import { Category } from './typeguard';
|
|
12
|
-
import { log, RuntimeError } from './util';
|
|
13
|
-
|
|
14
|
-
// eslint-disable-next-line
|
|
15
|
-
function L(...args: any[]) {
|
|
16
|
-
if (Stem.DEBUG) log('VexFlow.Stem', args);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface StemOptions {
|
|
20
|
-
stemDownYBaseOffset?: number;
|
|
21
|
-
stemUpYBaseOffset?: number;
|
|
22
|
-
stemDownYOffset?: number;
|
|
23
|
-
stemUpYOffset?: number;
|
|
24
|
-
stemletHeight?: number;
|
|
25
|
-
isStemlet?: boolean;
|
|
26
|
-
hide?: boolean;
|
|
27
|
-
stemDirection?: number;
|
|
28
|
-
stemExtension?: number;
|
|
29
|
-
yBottom?: number;
|
|
30
|
-
yTop?: number;
|
|
31
|
-
xEnd?: number;
|
|
32
|
-
xBegin?: number;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export class Stem extends Element {
|
|
36
|
-
/** To enable logging for this class. Set `VexFlow.Stem.DEBUG` to `true`. */
|
|
37
|
-
static DEBUG: boolean = false;
|
|
38
|
-
|
|
39
|
-
static get CATEGORY(): string {
|
|
40
|
-
return Category.Stem;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Stem directions
|
|
44
|
-
static get UP(): number {
|
|
45
|
-
return 1;
|
|
46
|
-
}
|
|
47
|
-
static get DOWN(): number {
|
|
48
|
-
return -1;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Theme
|
|
52
|
-
static get WIDTH(): number {
|
|
53
|
-
return Tables.STEM_WIDTH;
|
|
54
|
-
}
|
|
55
|
-
static get HEIGHT(): number {
|
|
56
|
-
return Tables.STEM_HEIGHT;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
protected hide: boolean;
|
|
60
|
-
protected isStemlet: boolean;
|
|
61
|
-
protected stemletHeight: number;
|
|
62
|
-
protected xBegin: number;
|
|
63
|
-
protected xEnd: number;
|
|
64
|
-
protected yTop: number;
|
|
65
|
-
protected stemUpYOffset: number = 0;
|
|
66
|
-
protected yBottom: number;
|
|
67
|
-
protected stemDownYOffset: number = 0;
|
|
68
|
-
protected stemUpYBaseOffset: number = 0;
|
|
69
|
-
protected stemDownYBaseOffset: number = 0;
|
|
70
|
-
protected stemDirection: number;
|
|
71
|
-
protected stemExtension: number;
|
|
72
|
-
protected renderHeightAdjustment: number;
|
|
73
|
-
|
|
74
|
-
constructor(options?: StemOptions) {
|
|
75
|
-
super();
|
|
76
|
-
|
|
77
|
-
// Default notehead x bounds
|
|
78
|
-
this.xBegin = options?.xBegin ?? 0;
|
|
79
|
-
this.xEnd = options?.xEnd ?? 0;
|
|
80
|
-
|
|
81
|
-
// Y bounds for top/bottom most notehead
|
|
82
|
-
this.yTop = options?.yTop ?? 0;
|
|
83
|
-
this.yBottom = options?.yBottom ?? 0;
|
|
84
|
-
|
|
85
|
-
// Stem top extension
|
|
86
|
-
this.stemExtension = options?.stemExtension ?? 0;
|
|
87
|
-
|
|
88
|
-
// Direction of the stem
|
|
89
|
-
this.stemDirection = options?.stemDirection ?? 0;
|
|
90
|
-
|
|
91
|
-
// Flag to override all draw calls
|
|
92
|
-
this.hide = options?.hide || false;
|
|
93
|
-
|
|
94
|
-
this.isStemlet = options?.isStemlet || false;
|
|
95
|
-
this.stemletHeight = options?.stemletHeight ?? 0;
|
|
96
|
-
|
|
97
|
-
// Use to adjust the rendered height without affecting
|
|
98
|
-
// the results of `.getExtents()`
|
|
99
|
-
this.renderHeightAdjustment = 0;
|
|
100
|
-
this.setOptions(options);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
setOptions(options?: StemOptions): void {
|
|
104
|
-
// Changing where the stem meets the head
|
|
105
|
-
this.stemUpYOffset = options?.stemUpYOffset ?? 0;
|
|
106
|
-
this.stemDownYOffset = options?.stemDownYOffset ?? 0;
|
|
107
|
-
this.stemUpYBaseOffset = options?.stemUpYBaseOffset ?? 0;
|
|
108
|
-
this.stemDownYBaseOffset = options?.stemDownYBaseOffset ?? 0;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Set the x bounds for the default notehead
|
|
112
|
-
setNoteHeadXBounds(xBegin: number, xEnd: number): this {
|
|
113
|
-
this.xBegin = xBegin;
|
|
114
|
-
this.xEnd = xEnd;
|
|
115
|
-
return this;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Set the direction of the stem in relation to the noteheads
|
|
119
|
-
setDirection(direction: number): void {
|
|
120
|
-
this.stemDirection = direction;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Set the extension for the stem, generally for flags or beams
|
|
124
|
-
setExtension(ext: number): void {
|
|
125
|
-
this.stemExtension = ext;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
getExtension(): number {
|
|
129
|
-
return this.stemExtension;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// The the y bounds for the top and bottom noteheads
|
|
133
|
-
setYBounds(yTop: number, yBottom: number): void {
|
|
134
|
-
this.yTop = yTop;
|
|
135
|
-
this.yBottom = yBottom;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Gets the entire height for the stem
|
|
139
|
-
getHeight(): number {
|
|
140
|
-
const yOffset = this.stemDirection === Stem.UP ? this.stemUpYOffset : this.stemDownYOffset;
|
|
141
|
-
const unsignedHeight = this.yBottom - this.yTop + (Stem.HEIGHT - yOffset + this.stemExtension); // parentheses just for grouping.
|
|
142
|
-
return unsignedHeight * this.stemDirection;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
getBoundingBox(): BoundingBox {
|
|
146
|
-
throw new RuntimeError('NotImplemented', 'getBoundingBox() not implemented.');
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Get the y coordinates for the very base of the stem to the top of
|
|
150
|
-
// the extension
|
|
151
|
-
getExtents(): { topY: number; baseY: number } {
|
|
152
|
-
const isStemUp = this.stemDirection === Stem.UP;
|
|
153
|
-
const ys = [this.yTop, this.yBottom];
|
|
154
|
-
const stemHeight = Stem.HEIGHT + this.stemExtension;
|
|
155
|
-
|
|
156
|
-
const innerMostNoteheadY = (isStemUp ? Math.min : Math.max)(...ys);
|
|
157
|
-
const outerMostNoteheadY = (isStemUp ? Math.max : Math.min)(...ys);
|
|
158
|
-
const stemTipY = innerMostNoteheadY + stemHeight * -this.stemDirection;
|
|
159
|
-
|
|
160
|
-
return { topY: stemTipY, baseY: outerMostNoteheadY };
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
setVisibility(isVisible: boolean): this {
|
|
164
|
-
this.hide = !isVisible;
|
|
165
|
-
return this;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
setStemlet(isStemlet: boolean, stemletHeight: number): this {
|
|
169
|
-
this.isStemlet = isStemlet;
|
|
170
|
-
this.stemletHeight = stemletHeight;
|
|
171
|
-
return this;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
adjustHeightForFlag(): void {
|
|
175
|
-
this.renderHeightAdjustment = Metrics.get('Stem.heightAdjustmentForFlag', -3);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
adjustHeightForBeam(): void {
|
|
179
|
-
this.renderHeightAdjustment = -Stem.WIDTH / 2;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// Render the stem onto the canvas
|
|
183
|
-
draw(): void {
|
|
184
|
-
this.setRendered();
|
|
185
|
-
if (this.hide) return;
|
|
186
|
-
const ctx = this.checkContext();
|
|
187
|
-
|
|
188
|
-
let stemX;
|
|
189
|
-
let stemY;
|
|
190
|
-
const stemDirection = this.stemDirection;
|
|
191
|
-
|
|
192
|
-
let yBaseOffset: number = 0;
|
|
193
|
-
if (stemDirection === Stem.DOWN) {
|
|
194
|
-
// Down stems are rendered to the left of the head.
|
|
195
|
-
stemX = this.xBegin;
|
|
196
|
-
stemY = this.yTop + this.stemDownYOffset;
|
|
197
|
-
yBaseOffset = this.stemDownYBaseOffset;
|
|
198
|
-
} else {
|
|
199
|
-
// Up stems are rendered to the right of the head.
|
|
200
|
-
stemX = this.xEnd;
|
|
201
|
-
stemY = this.yBottom - this.stemUpYOffset;
|
|
202
|
-
yBaseOffset = this.stemUpYBaseOffset;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
const stemHeight = this.getHeight();
|
|
206
|
-
|
|
207
|
-
L('Rendering stem - ', 'Top Y: ', this.yTop, 'Bottom Y: ', this.yBottom);
|
|
208
|
-
|
|
209
|
-
// The offset from the stem's base which is required fo satisfy the stemlet height
|
|
210
|
-
const stemletYOffset = this.isStemlet ? stemHeight - this.stemletHeight * this.stemDirection : 0;
|
|
211
|
-
|
|
212
|
-
// Draw the stem
|
|
213
|
-
ctx.save();
|
|
214
|
-
this.applyStyle();
|
|
215
|
-
ctx.openGroup('stem', this.getAttribute('id'));
|
|
216
|
-
ctx.beginPath();
|
|
217
|
-
ctx.setLineWidth(Stem.WIDTH);
|
|
218
|
-
ctx.moveTo(stemX, stemY - stemletYOffset + yBaseOffset);
|
|
219
|
-
ctx.lineTo(stemX, stemY - stemHeight - this.renderHeightAdjustment * stemDirection);
|
|
220
|
-
ctx.stroke();
|
|
221
|
-
ctx.closeGroup();
|
|
222
|
-
this.restoreStyle();
|
|
223
|
-
ctx.restore();
|
|
224
|
-
}
|
|
225
|
-
}
|
package/src/stemmablenote.ts
DELETED
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
|
|
2
|
-
//
|
|
3
|
-
// ## Description
|
|
4
|
-
// `StemmableNote` is an abstract interface for notes with optional stems.
|
|
5
|
-
// Examples of stemmable notes are `StaveNote` and `TabNote`
|
|
6
|
-
|
|
7
|
-
import { Element, ElementStyle } from './element';
|
|
8
|
-
import { Glyphs } from './glyphs';
|
|
9
|
-
import { GlyphProps, Note, NoteStruct } from './note';
|
|
10
|
-
import { Stem, StemOptions } from './stem';
|
|
11
|
-
import { Tables } from './tables';
|
|
12
|
-
import { Category } from './typeguard';
|
|
13
|
-
import { RuntimeError } from './util';
|
|
14
|
-
|
|
15
|
-
export abstract class StemmableNote extends Note {
|
|
16
|
-
static get CATEGORY(): string {
|
|
17
|
-
return Category.StemmableNote;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
stemDirection?: number;
|
|
21
|
-
stem?: Stem;
|
|
22
|
-
|
|
23
|
-
protected flag = new Element();
|
|
24
|
-
protected flagStyle: ElementStyle = {};
|
|
25
|
-
protected stemExtensionOverride?: number;
|
|
26
|
-
|
|
27
|
-
constructor(noteStruct: NoteStruct) {
|
|
28
|
-
super(noteStruct);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Get and set the note's `Stem`
|
|
32
|
-
getStem(): Stem | undefined {
|
|
33
|
-
return this.stem;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
checkStem(): Stem {
|
|
37
|
-
if (!this.stem) {
|
|
38
|
-
throw new RuntimeError('NoStem', 'No stem attached to instance');
|
|
39
|
-
}
|
|
40
|
-
return this.stem;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
setStem(stem: Stem): this {
|
|
44
|
-
this.stem = stem;
|
|
45
|
-
this.addChildElement(stem);
|
|
46
|
-
return this;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Builds and sets a new stem
|
|
50
|
-
buildStem(): this {
|
|
51
|
-
const stem = new Stem();
|
|
52
|
-
this.setStem(stem);
|
|
53
|
-
return this;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
buildFlag(): void {
|
|
57
|
-
const { glyphProps } = this;
|
|
58
|
-
|
|
59
|
-
if (this.hasFlag()) {
|
|
60
|
-
const flagCode =
|
|
61
|
-
// codeFlagDown = codeFlagUp + 1
|
|
62
|
-
// if codeFlagUp is undefined, codePoint will be 0
|
|
63
|
-
this.getStemDirection() === Stem.DOWN
|
|
64
|
-
? String.fromCodePoint((glyphProps.codeFlagUp?.codePointAt(0) ?? -1) + 1)
|
|
65
|
-
: glyphProps.codeFlagUp ?? Glyphs.null;
|
|
66
|
-
|
|
67
|
-
this.flag.setText(flagCode);
|
|
68
|
-
this.flag.fontInfo = this.fontInfo;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Get the custom glyph associated with the outer note head on the base of the stem.
|
|
73
|
-
getBaseCustomNoteHeadGlyphProps(): GlyphProps {
|
|
74
|
-
if (this.getStemDirection() === Stem.DOWN) {
|
|
75
|
-
return this.customGlyphs[this.customGlyphs.length - 1];
|
|
76
|
-
} else {
|
|
77
|
-
return this.customGlyphs[0];
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Get the full length of stem
|
|
82
|
-
getStemLength(): number {
|
|
83
|
-
return Stem.HEIGHT + this.getStemExtension();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Get the number of beams for this duration
|
|
87
|
-
getBeamCount(): number {
|
|
88
|
-
const glyphProps = this.getGlyphProps();
|
|
89
|
-
|
|
90
|
-
if (glyphProps) {
|
|
91
|
-
return glyphProps.beamCount;
|
|
92
|
-
} else {
|
|
93
|
-
return 0;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Get the minimum length of stem
|
|
98
|
-
getStemMinimumLength(): number {
|
|
99
|
-
const frac = Tables.durationToFraction(this.duration);
|
|
100
|
-
const beamIsUndefined = this.beam === undefined;
|
|
101
|
-
let length = frac.value() <= 1 ? 0 : 20;
|
|
102
|
-
// if note is flagged, cannot shorten beam
|
|
103
|
-
switch (this.duration) {
|
|
104
|
-
case '8':
|
|
105
|
-
case '16':
|
|
106
|
-
length = beamIsUndefined ? 35 : 25;
|
|
107
|
-
break;
|
|
108
|
-
case '32':
|
|
109
|
-
length = beamIsUndefined ? 45 : 35;
|
|
110
|
-
break;
|
|
111
|
-
case '64':
|
|
112
|
-
length = beamIsUndefined ? 50 : 40;
|
|
113
|
-
break;
|
|
114
|
-
case '128':
|
|
115
|
-
length = beamIsUndefined ? 55 : 45;
|
|
116
|
-
break;
|
|
117
|
-
default:
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
return length;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Get/set the direction of the stem
|
|
124
|
-
getStemDirection(): number {
|
|
125
|
-
if (!this.stemDirection) throw new RuntimeError('NoStem', 'No stem attached to this note.');
|
|
126
|
-
return this.stemDirection;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
setStemDirection(direction?: number): this {
|
|
130
|
-
if (!direction) direction = Stem.UP;
|
|
131
|
-
if (direction !== Stem.UP && direction !== Stem.DOWN) {
|
|
132
|
-
throw new RuntimeError('BadArgument', `Invalid stem direction: ${direction}`);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
this.stemDirection = direction;
|
|
136
|
-
|
|
137
|
-
// Reset and reformat everything. Flag has to be built before calling getStemExtension.
|
|
138
|
-
this.reset();
|
|
139
|
-
if (this.hasFlag()) {
|
|
140
|
-
this.buildFlag();
|
|
141
|
-
}
|
|
142
|
-
this.beam = undefined;
|
|
143
|
-
|
|
144
|
-
if (this.stem) {
|
|
145
|
-
this.stem.setDirection(direction);
|
|
146
|
-
this.stem.setExtension(this.getStemExtension());
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (this.preFormatted) {
|
|
150
|
-
this.preFormat();
|
|
151
|
-
}
|
|
152
|
-
return this;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Get the `x` coordinate of the stem
|
|
156
|
-
getStemX(): number {
|
|
157
|
-
const xBegin = this.getAbsoluteX() + this.xShift;
|
|
158
|
-
const xEnd = this.getAbsoluteX() + this.xShift + this.getGlyphWidth();
|
|
159
|
-
const stemX = this.stemDirection === Stem.DOWN ? xBegin : xEnd;
|
|
160
|
-
return stemX;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// Get the `x` coordinate for the center of the glyph.
|
|
164
|
-
// Used for `TabNote` stems and stemlets over rests
|
|
165
|
-
getCenterGlyphX(): number {
|
|
166
|
-
return this.getAbsoluteX() + this.xShift + this.getGlyphWidth() / 2;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Get the stem extension for the current duration
|
|
170
|
-
getStemExtension(): number {
|
|
171
|
-
const glyphProps = this.getGlyphProps();
|
|
172
|
-
const flagHeight = this.flag.getHeight();
|
|
173
|
-
const scale = this.getFontScale();
|
|
174
|
-
|
|
175
|
-
if (this.stemExtensionOverride !== undefined) {
|
|
176
|
-
return this.stemExtensionOverride;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// Use stemBeamExtension with beams
|
|
180
|
-
if (this.beam) {
|
|
181
|
-
return glyphProps.stemBeamExtension * scale;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// If the flag is longer than the stem, extend the stem by the difference.
|
|
185
|
-
return flagHeight > Stem.HEIGHT * scale ? flagHeight - Stem.HEIGHT * scale : 0;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// Set the stem length to a specific. Will override the default length.
|
|
189
|
-
setStemLength(height: number): this {
|
|
190
|
-
this.stemExtensionOverride = height - Stem.HEIGHT;
|
|
191
|
-
return this;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// Get the top and bottom `y` values of the stem.
|
|
195
|
-
getStemExtents(): { topY: number; baseY: number } {
|
|
196
|
-
if (!this.stem) throw new RuntimeError('NoStem', 'No stem attached to this note.');
|
|
197
|
-
return this.stem.getExtents();
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/** Gets the `y` value for the top modifiers at a specific `textLine`. */
|
|
201
|
-
getYForTopText(textLine: number): number {
|
|
202
|
-
const stave = this.checkStave();
|
|
203
|
-
if (this.hasStem()) {
|
|
204
|
-
const extents = this.getStemExtents();
|
|
205
|
-
if (!extents) throw new RuntimeError('InvalidState', 'Stem does not have extents.');
|
|
206
|
-
|
|
207
|
-
return Math.min(
|
|
208
|
-
stave.getYForTopText(textLine),
|
|
209
|
-
extents.topY - this.renderOptions.annotationSpacing * (textLine + 1)
|
|
210
|
-
);
|
|
211
|
-
} else {
|
|
212
|
-
return stave.getYForTopText(textLine);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/** Gets the `y` value for the bottom modifiers at a specific `textLine`. */
|
|
217
|
-
getYForBottomText(textLine: number): number {
|
|
218
|
-
const stave = this.checkStave();
|
|
219
|
-
if (this.hasStem()) {
|
|
220
|
-
const extents = this.getStemExtents();
|
|
221
|
-
if (!extents) throw new RuntimeError('InvalidState', 'Stem does not have extents.');
|
|
222
|
-
|
|
223
|
-
return Math.max(stave.getYForTopText(textLine), extents.baseY + this.renderOptions.annotationSpacing * textLine);
|
|
224
|
-
} else {
|
|
225
|
-
return stave.getYForBottomText(textLine);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
hasFlag(): boolean {
|
|
230
|
-
return this.glyphProps.codeFlagUp !== undefined && !this.beam && !this.isRest();
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/** Post formats the note. */
|
|
234
|
-
postFormat(): this {
|
|
235
|
-
this.beam?.postFormat();
|
|
236
|
-
this.postFormatted = true;
|
|
237
|
-
return this;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/** Renders the stem onto the canvas. */
|
|
241
|
-
drawStem(stemOptions: StemOptions): void {
|
|
242
|
-
this.checkContext();
|
|
243
|
-
this.setRendered();
|
|
244
|
-
|
|
245
|
-
this.setStem(new Stem(stemOptions));
|
|
246
|
-
this.stem?.setContext(this.getContext()).draw();
|
|
247
|
-
}
|
|
248
|
-
}
|