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/stringnumber.ts
DELETED
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
|
|
2
|
-
// @author Larry Kuhns
|
|
3
|
-
//
|
|
4
|
-
// This file implements the `StringNumber` class which renders string
|
|
5
|
-
// number annotations beside notes.
|
|
6
|
-
|
|
7
|
-
import { Metrics } from './metrics';
|
|
8
|
-
import { Modifier, ModifierPosition } from './modifier';
|
|
9
|
-
import { ModifierContextState } from './modifiercontext';
|
|
10
|
-
import { Note } from './note';
|
|
11
|
-
import { Renderer } from './renderer';
|
|
12
|
-
import { Stem } from './stem';
|
|
13
|
-
import { StemmableNote } from './stemmablenote';
|
|
14
|
-
import { Tables } from './tables';
|
|
15
|
-
import { Category, isStaveNote, isStemmableNote } from './typeguard';
|
|
16
|
-
import { RuntimeError } from './util';
|
|
17
|
-
|
|
18
|
-
export class StringNumber extends Modifier {
|
|
19
|
-
static get CATEGORY(): string {
|
|
20
|
-
return Category.StringNumber;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// ## Static Methods
|
|
24
|
-
// Arrange string numbers inside a `ModifierContext`
|
|
25
|
-
static format(nums: StringNumber[], state: ModifierContextState): boolean {
|
|
26
|
-
/**
|
|
27
|
-
* The modifier context's leftShift state.
|
|
28
|
-
*/
|
|
29
|
-
const leftShift = state.leftShift;
|
|
30
|
-
/**
|
|
31
|
-
* The modifier context's rightShift state.
|
|
32
|
-
*/
|
|
33
|
-
const rightShift = state.rightShift;
|
|
34
|
-
const numSpacing = 1;
|
|
35
|
-
|
|
36
|
-
if (!nums || nums.length === 0) return false;
|
|
37
|
-
|
|
38
|
-
const numsList = [];
|
|
39
|
-
let prevNote = null;
|
|
40
|
-
let extraXSpaceForDisplacedNotehead = 0;
|
|
41
|
-
let shiftRight = 0;
|
|
42
|
-
const modLines = 0;
|
|
43
|
-
|
|
44
|
-
for (let i = 0; i < nums.length; ++i) {
|
|
45
|
-
const num = nums[i];
|
|
46
|
-
const note = num.getNote();
|
|
47
|
-
const pos = num.getPosition();
|
|
48
|
-
if (!isStaveNote(note)) {
|
|
49
|
-
throw new RuntimeError('NoStaveNote');
|
|
50
|
-
}
|
|
51
|
-
const index = num.checkIndex();
|
|
52
|
-
const props = note.getKeyProps()[index];
|
|
53
|
-
const mc = note.getModifierContext();
|
|
54
|
-
const verticalSpaceNeeded = (num.radius * 2) / Tables.STAVE_LINE_DISTANCE + 0.5;
|
|
55
|
-
|
|
56
|
-
if (mc) {
|
|
57
|
-
if (pos === ModifierPosition.ABOVE) {
|
|
58
|
-
num.textLine = mc.getState().topTextLine;
|
|
59
|
-
state.topTextLine += verticalSpaceNeeded;
|
|
60
|
-
} else if (pos === ModifierPosition.BELOW) {
|
|
61
|
-
num.textLine = mc.getState().textLine;
|
|
62
|
-
state.textLine += verticalSpaceNeeded;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (note !== prevNote) {
|
|
67
|
-
for (let n = 0; n < note.keys.length; ++n) {
|
|
68
|
-
if (pos === Modifier.Position.LEFT) {
|
|
69
|
-
extraXSpaceForDisplacedNotehead = Math.max(note.getLeftDisplacedHeadPx(), extraXSpaceForDisplacedNotehead);
|
|
70
|
-
}
|
|
71
|
-
if (rightShift === 0) {
|
|
72
|
-
shiftRight = Math.max(note.getRightDisplacedHeadPx(), shiftRight);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
prevNote = note;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const glyphLine = modLines === 0 ? props.line : modLines;
|
|
79
|
-
|
|
80
|
-
numsList.push({
|
|
81
|
-
pos,
|
|
82
|
-
note,
|
|
83
|
-
num,
|
|
84
|
-
line: glyphLine,
|
|
85
|
-
shiftL: extraXSpaceForDisplacedNotehead,
|
|
86
|
-
shiftR: shiftRight,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Sort string numbers by line number.
|
|
91
|
-
numsList.sort((a, b) => b.line - a.line);
|
|
92
|
-
|
|
93
|
-
let numShiftR = 0;
|
|
94
|
-
let xWidthL = 0;
|
|
95
|
-
let xWidthR = 0;
|
|
96
|
-
let lastLine = null;
|
|
97
|
-
let lastNote = null;
|
|
98
|
-
for (let i = 0; i < numsList.length; ++i) {
|
|
99
|
-
const note = numsList[i].note;
|
|
100
|
-
const pos = numsList[i].pos;
|
|
101
|
-
const num = numsList[i].num;
|
|
102
|
-
const line = numsList[i].line;
|
|
103
|
-
const shiftR = numsList[i].shiftR;
|
|
104
|
-
// Reset the position of the string number every line.
|
|
105
|
-
if (line !== lastLine || note !== lastNote) {
|
|
106
|
-
numShiftR = rightShift + shiftR;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const numWidth = num.getWidth() + numSpacing;
|
|
110
|
-
let numXShift = 0;
|
|
111
|
-
if (pos === Modifier.Position.LEFT) {
|
|
112
|
-
num.setXShift(leftShift + extraXSpaceForDisplacedNotehead);
|
|
113
|
-
numXShift = numWidth; // spacing
|
|
114
|
-
xWidthL = Math.max(numXShift, xWidthL);
|
|
115
|
-
} else if (pos === Modifier.Position.RIGHT) {
|
|
116
|
-
num.setXShift(numShiftR);
|
|
117
|
-
numXShift += numWidth; // spacing
|
|
118
|
-
xWidthR = numXShift > xWidthR ? numXShift : xWidthR;
|
|
119
|
-
}
|
|
120
|
-
lastLine = line;
|
|
121
|
-
lastNote = note;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
state.leftShift += xWidthL;
|
|
125
|
-
state.rightShift += xWidthR;
|
|
126
|
-
return true;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
protected radius: number;
|
|
130
|
-
protected drawCircle: boolean;
|
|
131
|
-
protected lastNote?: Note;
|
|
132
|
-
protected stringNumber: string;
|
|
133
|
-
protected xOffset: number;
|
|
134
|
-
protected yOffset: number;
|
|
135
|
-
protected textLine: number;
|
|
136
|
-
protected stemOffset: number;
|
|
137
|
-
protected dashed: boolean;
|
|
138
|
-
protected leg: number;
|
|
139
|
-
|
|
140
|
-
constructor(number: string) {
|
|
141
|
-
super();
|
|
142
|
-
|
|
143
|
-
this.stringNumber = number;
|
|
144
|
-
this.position = Modifier.Position.ABOVE; // Default position above stem or note head
|
|
145
|
-
this.xShift = 0;
|
|
146
|
-
this.yShift = 0;
|
|
147
|
-
this.textLine = 0;
|
|
148
|
-
this.stemOffset = 0;
|
|
149
|
-
this.xOffset = 0; // Horizontal offset from default
|
|
150
|
-
this.yOffset = 0; // Vertical offset from default
|
|
151
|
-
this.dashed = true; // true - draw dashed extension false - no extension
|
|
152
|
-
this.leg = Renderer.LineEndType.NONE; // draw upward/downward leg at the of extension line
|
|
153
|
-
this.radius = 8;
|
|
154
|
-
this.drawCircle = true;
|
|
155
|
-
this.setWidth(this.radius * 2 + 4);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
setLineEndType(leg: number): this {
|
|
159
|
-
if (leg >= Renderer.LineEndType.NONE && leg <= Renderer.LineEndType.DOWN) {
|
|
160
|
-
this.leg = leg;
|
|
161
|
-
}
|
|
162
|
-
return this;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
setStringNumber(number: string): this {
|
|
166
|
-
this.stringNumber = number;
|
|
167
|
-
return this;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
setOffsetX(x: number): this {
|
|
171
|
-
this.xOffset = x;
|
|
172
|
-
return this;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
setOffsetY(y: number): this {
|
|
176
|
-
this.yOffset = y;
|
|
177
|
-
return this;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
setLastNote(note: Note): this {
|
|
181
|
-
this.lastNote = note;
|
|
182
|
-
return this;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
setDashed(dashed: boolean): this {
|
|
186
|
-
this.dashed = dashed;
|
|
187
|
-
return this;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
setDrawCircle(drawCircle: boolean): this {
|
|
191
|
-
this.drawCircle = drawCircle;
|
|
192
|
-
return this;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
draw(): void {
|
|
196
|
-
const ctx = this.checkContext();
|
|
197
|
-
const note = this.checkAttachedNote();
|
|
198
|
-
this.setRendered();
|
|
199
|
-
const start = note.getModifierStartXY(this.position, this.index);
|
|
200
|
-
const stemDirection = note.hasStem() ? note.getStemDirection() : Stem.UP;
|
|
201
|
-
let dotX = start.x + this.xShift + this.xOffset;
|
|
202
|
-
let stemExt: Record<string, number> = {};
|
|
203
|
-
if (note.hasStem()) {
|
|
204
|
-
stemExt = (note as StemmableNote).checkStem().getExtents();
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
let dotY = start.y + this.yShift + this.yOffset;
|
|
208
|
-
|
|
209
|
-
switch (this.position) {
|
|
210
|
-
case Modifier.Position.ABOVE:
|
|
211
|
-
{
|
|
212
|
-
const ys = note.getYs();
|
|
213
|
-
dotY = ys.reduce((a, b) => (a < b ? a : b));
|
|
214
|
-
if (note.hasStem() && stemDirection === Stem.UP) {
|
|
215
|
-
dotY = stemExt.topY + Metrics.get('StringNumber.stemPadding');
|
|
216
|
-
}
|
|
217
|
-
dotY -=
|
|
218
|
-
this.radius + Metrics.get('StringNumber.verticalPadding') + this.textLine * Tables.STAVE_LINE_DISTANCE;
|
|
219
|
-
}
|
|
220
|
-
break;
|
|
221
|
-
case Modifier.Position.BELOW:
|
|
222
|
-
{
|
|
223
|
-
const ys: number[] = note.getYs();
|
|
224
|
-
dotY = ys.reduce((a, b) => (a > b ? a : b));
|
|
225
|
-
if (note.hasStem() && stemDirection === Stem.DOWN) {
|
|
226
|
-
dotY = stemExt.topY - Metrics.get('StringNumber.stemPadding');
|
|
227
|
-
}
|
|
228
|
-
dotY +=
|
|
229
|
-
this.radius + Metrics.get('StringNumber.verticalPadding') + this.textLine * Tables.STAVE_LINE_DISTANCE;
|
|
230
|
-
}
|
|
231
|
-
break;
|
|
232
|
-
case Modifier.Position.LEFT:
|
|
233
|
-
dotX -= this.radius / 2 + Metrics.get('StringNumber.leftPadding');
|
|
234
|
-
break;
|
|
235
|
-
case Modifier.Position.RIGHT:
|
|
236
|
-
dotX += this.radius / 2 + Metrics.get('StringNumber.rightPadding');
|
|
237
|
-
break;
|
|
238
|
-
default:
|
|
239
|
-
throw new RuntimeError('InvalidPosition', `The position ${this.position} is invalid`);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
ctx.save();
|
|
243
|
-
if (this.drawCircle) {
|
|
244
|
-
ctx.beginPath();
|
|
245
|
-
ctx.arc(dotX, dotY, this.radius, 0, Math.PI * 2, false);
|
|
246
|
-
ctx.setLineWidth(1.5);
|
|
247
|
-
ctx.stroke();
|
|
248
|
-
}
|
|
249
|
-
ctx.setFont(this.fontInfo);
|
|
250
|
-
const x = dotX - ctx.measureText(this.stringNumber).width / 2;
|
|
251
|
-
ctx.fillText('' + this.stringNumber, x, dotY + 4.5);
|
|
252
|
-
|
|
253
|
-
const lastNote = this.lastNote;
|
|
254
|
-
if (isStemmableNote(lastNote)) {
|
|
255
|
-
// Only StemmableNote objects have getStemX().
|
|
256
|
-
const end = lastNote.getStemX() - note.getX() + 5;
|
|
257
|
-
ctx.setStrokeStyle('#000000');
|
|
258
|
-
ctx.setLineCap('round');
|
|
259
|
-
ctx.setLineWidth(0.6);
|
|
260
|
-
if (this.dashed) {
|
|
261
|
-
Renderer.drawDashedLine(ctx, dotX + 10, dotY, dotX + end, dotY, [3, 3]);
|
|
262
|
-
} else {
|
|
263
|
-
Renderer.drawDashedLine(ctx, dotX + 10, dotY, dotX + end, dotY, [3, 0]);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
let len;
|
|
267
|
-
let pattern;
|
|
268
|
-
switch (this.leg) {
|
|
269
|
-
case Renderer.LineEndType.UP:
|
|
270
|
-
len = -10;
|
|
271
|
-
pattern = this.dashed ? [3, 3] : [3, 0];
|
|
272
|
-
Renderer.drawDashedLine(ctx, dotX + end, dotY, dotX + end, dotY + len, pattern);
|
|
273
|
-
break;
|
|
274
|
-
case Renderer.LineEndType.DOWN:
|
|
275
|
-
len = 10;
|
|
276
|
-
pattern = this.dashed ? [3, 3] : [3, 0];
|
|
277
|
-
Renderer.drawDashedLine(ctx, dotX + end, dotY, dotX + end, dotY + len, pattern);
|
|
278
|
-
break;
|
|
279
|
-
default:
|
|
280
|
-
break;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
ctx.restore();
|
|
285
|
-
}
|
|
286
|
-
}
|
package/src/strokes.ts
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
|
|
2
|
-
// @author Larry Kuhns
|
|
3
|
-
//
|
|
4
|
-
// This file implements the `Stroke` class which renders chord strokes
|
|
5
|
-
// that can be arpeggiated, brushed, rasgueado, etc.
|
|
6
|
-
|
|
7
|
-
import { Element } from './element';
|
|
8
|
-
import { Glyphs } from './glyphs';
|
|
9
|
-
import { Metrics } from './metrics';
|
|
10
|
-
import { Modifier } from './modifier';
|
|
11
|
-
import { ModifierContextState } from './modifiercontext';
|
|
12
|
-
import { Note } from './note';
|
|
13
|
-
import { Category, isNote, isStaveNote, isTabNote } from './typeguard';
|
|
14
|
-
import { RuntimeError } from './util';
|
|
15
|
-
|
|
16
|
-
export class Stroke extends Modifier {
|
|
17
|
-
static get CATEGORY(): string {
|
|
18
|
-
return Category.Stroke;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
static readonly Type = {
|
|
22
|
-
BRUSH_DOWN: 1,
|
|
23
|
-
BRUSH_UP: 2,
|
|
24
|
-
ROLL_DOWN: 3, // Arpeggiated chord
|
|
25
|
-
ROLL_UP: 4, // Arpeggiated chord
|
|
26
|
-
RASGUEADO_DOWN: 5,
|
|
27
|
-
RASGUEADO_UP: 6,
|
|
28
|
-
ARPEGGIO_DIRECTIONLESS: 7, // Arpeggiated chord without upwards or downwards arrow
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
// Arrange strokes inside `ModifierContext`
|
|
32
|
-
static format(strokes: Stroke[], state: ModifierContextState): boolean {
|
|
33
|
-
const leftShift = state.leftShift;
|
|
34
|
-
const strokeSpacing = 5;
|
|
35
|
-
|
|
36
|
-
if (!strokes || strokes.length === 0) return false;
|
|
37
|
-
|
|
38
|
-
const strokeList = strokes.map((stroke) => {
|
|
39
|
-
const note = stroke.getNote();
|
|
40
|
-
const index = stroke.checkIndex();
|
|
41
|
-
if (isStaveNote(note)) {
|
|
42
|
-
// Only StaveNote objects have getKeyProps().
|
|
43
|
-
const { line } = note.getKeyProps()[index];
|
|
44
|
-
const shift = note.getLeftDisplacedHeadPx();
|
|
45
|
-
return { line, shift, stroke };
|
|
46
|
-
} else if (isTabNote(note)) {
|
|
47
|
-
// Only TabNote objects have getPositions().
|
|
48
|
-
const { str: string } = note.getPositions()[index];
|
|
49
|
-
return { line: string, shift: 0, stroke };
|
|
50
|
-
} else {
|
|
51
|
-
throw new RuntimeError('Internal', 'Unexpected instance.');
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const strokeShift = leftShift;
|
|
56
|
-
|
|
57
|
-
// There can only be one stroke .. if more than one, they overlay each other
|
|
58
|
-
const xShift = strokeList.reduce((xShift, { stroke, shift }) => {
|
|
59
|
-
stroke.setXShift(strokeShift + shift);
|
|
60
|
-
return Math.max(stroke.getWidth() + strokeSpacing, xShift);
|
|
61
|
-
}, 0);
|
|
62
|
-
|
|
63
|
-
state.leftShift += xShift;
|
|
64
|
-
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
protected options: { allVoices: boolean };
|
|
69
|
-
protected allVoices: boolean;
|
|
70
|
-
protected type: number;
|
|
71
|
-
protected noteEnd?: Note;
|
|
72
|
-
public renderOptions: {
|
|
73
|
-
fontScale: number;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
constructor(type: number, options?: { allVoices: boolean }) {
|
|
77
|
-
super();
|
|
78
|
-
|
|
79
|
-
this.options = { allVoices: true, ...options };
|
|
80
|
-
|
|
81
|
-
// multi voice - span stroke across all voices if true
|
|
82
|
-
this.allVoices = this.options.allVoices;
|
|
83
|
-
|
|
84
|
-
// multi voice - end note of stroke, set in draw()
|
|
85
|
-
this.type = type;
|
|
86
|
-
this.position = Modifier.Position.LEFT;
|
|
87
|
-
|
|
88
|
-
this.renderOptions = {
|
|
89
|
-
fontScale: Metrics.get('Stroke.fontSize'),
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
this.setXShift(0);
|
|
93
|
-
this.setWidth(10);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
getPosition(): number {
|
|
97
|
-
return this.position;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
addEndNote(note: Note): this {
|
|
101
|
-
this.noteEnd = note;
|
|
102
|
-
return this;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
draw(): void {
|
|
106
|
-
const ctx = this.checkContext();
|
|
107
|
-
const note = this.checkAttachedNote();
|
|
108
|
-
this.setRendered();
|
|
109
|
-
|
|
110
|
-
const start = note.getModifierStartXY(this.position, this.index);
|
|
111
|
-
let yPositions = note.getYs();
|
|
112
|
-
let topY = start.y;
|
|
113
|
-
let botY = start.y;
|
|
114
|
-
const x = start.x - 5;
|
|
115
|
-
const lineSpace = note.checkStave().getSpacingBetweenLines();
|
|
116
|
-
|
|
117
|
-
const notes = this.checkModifierContext().getMembers(note.getCategory());
|
|
118
|
-
for (let i = 0; i < notes.length; i++) {
|
|
119
|
-
const note = notes[i];
|
|
120
|
-
if (isNote(note)) {
|
|
121
|
-
// Only Note objects have getYs().
|
|
122
|
-
// note is an instance of either StaveNote or TabNote.
|
|
123
|
-
yPositions = note.getYs();
|
|
124
|
-
for (let n = 0; n < yPositions.length; n++) {
|
|
125
|
-
if (this.note === notes[i] || this.allVoices) {
|
|
126
|
-
topY = Math.min(topY, yPositions[n]);
|
|
127
|
-
botY = Math.max(botY, yPositions[n]);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
let arrow = '';
|
|
134
|
-
let arrowY = 0;
|
|
135
|
-
let textY = 0;
|
|
136
|
-
|
|
137
|
-
switch (this.type) {
|
|
138
|
-
case Stroke.Type.BRUSH_DOWN:
|
|
139
|
-
case Stroke.Type.ROLL_DOWN:
|
|
140
|
-
case Stroke.Type.RASGUEADO_DOWN:
|
|
141
|
-
arrow = Glyphs.arrowheadBlackUp;
|
|
142
|
-
arrowY = topY;
|
|
143
|
-
topY -= lineSpace / 2;
|
|
144
|
-
botY += lineSpace / 2;
|
|
145
|
-
break;
|
|
146
|
-
case Stroke.Type.BRUSH_UP:
|
|
147
|
-
case Stroke.Type.ROLL_UP:
|
|
148
|
-
case Stroke.Type.RASGUEADO_UP:
|
|
149
|
-
arrow = Glyphs.arrowheadBlackDown;
|
|
150
|
-
arrowY = botY + lineSpace;
|
|
151
|
-
topY -= lineSpace / 2;
|
|
152
|
-
break;
|
|
153
|
-
case Stroke.Type.ARPEGGIO_DIRECTIONLESS:
|
|
154
|
-
topY -= lineSpace / 2;
|
|
155
|
-
botY += lineSpace / 2;
|
|
156
|
-
break;
|
|
157
|
-
default:
|
|
158
|
-
throw new RuntimeError('InvalidType', `The stroke type ${this.type} does not exist`);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// Draw the stroke
|
|
162
|
-
if (this.type === Stroke.Type.BRUSH_DOWN || this.type === Stroke.Type.BRUSH_UP) {
|
|
163
|
-
ctx.fillRect(x + this.xShift, topY, 1, botY - topY);
|
|
164
|
-
} else {
|
|
165
|
-
// Select the wiggle glyph depending on the arrow direction
|
|
166
|
-
const lineGlyph = arrow === Glyphs.arrowheadBlackDown ? Glyphs.wiggleArpeggiatoDown : Glyphs.wiggleArpeggiatoUp;
|
|
167
|
-
let txt = '';
|
|
168
|
-
const el = new Element();
|
|
169
|
-
// add glyphs until the required length is achieved
|
|
170
|
-
while (el.getWidth() < botY - topY) {
|
|
171
|
-
txt += lineGlyph;
|
|
172
|
-
el.setText(txt);
|
|
173
|
-
}
|
|
174
|
-
if (
|
|
175
|
-
this.type === Stroke.Type.RASGUEADO_DOWN ||
|
|
176
|
-
this.type === Stroke.Type.ROLL_DOWN ||
|
|
177
|
-
this.type === Stroke.Type.ARPEGGIO_DIRECTIONLESS
|
|
178
|
-
) {
|
|
179
|
-
ctx.openRotation(90, x + this.xShift, topY);
|
|
180
|
-
el.renderText(ctx, x + this.xShift, topY - el.getTextMetrics().actualBoundingBoxDescent + el.getHeight() / 2);
|
|
181
|
-
ctx.closeRotation();
|
|
182
|
-
textY = topY + el.getWidth() + 5;
|
|
183
|
-
} else {
|
|
184
|
-
ctx.openRotation(-90, x + this.xShift, botY);
|
|
185
|
-
el.renderText(ctx, x + this.xShift, botY - el.getTextMetrics().actualBoundingBoxDescent + el.getHeight() / 2);
|
|
186
|
-
ctx.closeRotation();
|
|
187
|
-
textY = botY - el.getWidth() - 5;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// Draw the arrow head
|
|
192
|
-
if (arrowY !== 0) {
|
|
193
|
-
const el = new Element();
|
|
194
|
-
el.setText(arrow);
|
|
195
|
-
el.renderText(
|
|
196
|
-
ctx,
|
|
197
|
-
// Center the arrow head substracting its width / 2
|
|
198
|
-
x + this.xShift - el.getWidth() / 2,
|
|
199
|
-
arrowY
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// Draw the rasgueado "R"
|
|
204
|
-
if (this.type === Stroke.Type.RASGUEADO_DOWN || this.type === Stroke.Type.RASGUEADO_UP) {
|
|
205
|
-
const el = new Element('Stroke.text');
|
|
206
|
-
el.setText('R');
|
|
207
|
-
el.renderText(
|
|
208
|
-
ctx,
|
|
209
|
-
x + this.xShift - el.getWidth() / 2,
|
|
210
|
-
textY + (this.type === Stroke.Type.RASGUEADO_DOWN ? el.getHeight() : 0)
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|