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/tabnote.ts
DELETED
|
@@ -1,449 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
|
|
2
|
-
//
|
|
3
|
-
// ## Description
|
|
4
|
-
//
|
|
5
|
-
// The file implements notes for Tablature notation. This consists of one or
|
|
6
|
-
// more fret positions, and can either be drawn with or without stems.
|
|
7
|
-
//
|
|
8
|
-
// See `tests/tabnote_tests.ts` for usage examples.
|
|
9
|
-
|
|
10
|
-
import { Element } from './element';
|
|
11
|
-
import { Glyphs } from './glyphs';
|
|
12
|
-
import { Modifier } from './modifier';
|
|
13
|
-
import { Note } from './note';
|
|
14
|
-
import { Stave } from './stave';
|
|
15
|
-
import { StaveNoteStruct } from './stavenote';
|
|
16
|
-
import { Stem } from './stem';
|
|
17
|
-
import { StemmableNote } from './stemmablenote';
|
|
18
|
-
import { Category, isDot } from './typeguard';
|
|
19
|
-
import { defined, RuntimeError } from './util';
|
|
20
|
-
|
|
21
|
-
export interface TabNotePosition {
|
|
22
|
-
// For example, on a six stringed instrument, `str` ranges from 1 to 6.
|
|
23
|
-
str: number;
|
|
24
|
-
|
|
25
|
-
// fret: 'X' indicates an unused/muted string.
|
|
26
|
-
// fret: 3 indicates the third fret.
|
|
27
|
-
fret: number | string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface TabNoteStruct extends StaveNoteStruct {
|
|
31
|
-
positions: TabNotePosition[];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Gets the unused strings grouped together if consecutive.
|
|
36
|
-
* @param numLines The number of lines.
|
|
37
|
-
* @param stringsUsed An array of numbers representing which strings have fret positions.
|
|
38
|
-
* @returns
|
|
39
|
-
*/
|
|
40
|
-
function getUnusedStringGroups(numLines: number, stringsUsed: number[]): number[][] {
|
|
41
|
-
const stemThrough = [];
|
|
42
|
-
let group = [];
|
|
43
|
-
for (let string = 1; string <= numLines; string++) {
|
|
44
|
-
const isUsed = stringsUsed.indexOf(string) > -1;
|
|
45
|
-
|
|
46
|
-
if (!isUsed) {
|
|
47
|
-
group.push(string);
|
|
48
|
-
} else {
|
|
49
|
-
stemThrough.push(group);
|
|
50
|
-
group = [];
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
if (group.length > 0) stemThrough.push(group);
|
|
54
|
-
|
|
55
|
-
return stemThrough;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Gets groups of points that outline the partial stem lines
|
|
59
|
-
// between fret positions
|
|
60
|
-
//
|
|
61
|
-
// Parameters:
|
|
62
|
-
// * stemY - The `y` coordinate the stem is located on
|
|
63
|
-
// * unusedStrings - An array of groups of unused strings
|
|
64
|
-
// * stave - The stave to use for reference
|
|
65
|
-
// * stemDirection - The direction of the stem
|
|
66
|
-
function getPartialStemLines(stemY: number, unusedStrings: number[][], stave: Stave, stemDirection: number) {
|
|
67
|
-
const upStem = stemDirection !== 1;
|
|
68
|
-
const downStem = stemDirection !== -1;
|
|
69
|
-
|
|
70
|
-
const lineSpacing = stave.getSpacingBetweenLines();
|
|
71
|
-
const totalLines = stave.getNumLines();
|
|
72
|
-
|
|
73
|
-
const stemLines: number[][] = [];
|
|
74
|
-
|
|
75
|
-
unusedStrings.forEach((strings) => {
|
|
76
|
-
const containsLastString = strings.indexOf(totalLines) > -1;
|
|
77
|
-
const containsFirstString = strings.indexOf(1) > -1;
|
|
78
|
-
|
|
79
|
-
if ((upStem && containsFirstString) || (downStem && containsLastString)) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// If there's only one string in the group, push a duplicate value.
|
|
84
|
-
// We do this because we need 2 strings to convert into upper/lower y
|
|
85
|
-
// values.
|
|
86
|
-
if (strings.length === 1) {
|
|
87
|
-
strings.push(strings[0]);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const lineYs: number[] = [];
|
|
91
|
-
// Iterate through each group string and store it's y position
|
|
92
|
-
strings.forEach((string, index, strings) => {
|
|
93
|
-
const isTopBound = string === 1;
|
|
94
|
-
const isBottomBound = string === totalLines;
|
|
95
|
-
|
|
96
|
-
// Get the y value for the appropriate staff line,
|
|
97
|
-
// we adjust for a 0 index array, since string numbers are index 1
|
|
98
|
-
let y = stave.getYForLine(string - 1);
|
|
99
|
-
|
|
100
|
-
// Unless the string is the first or last, add padding to each side
|
|
101
|
-
// of the line
|
|
102
|
-
if (index === 0 && !isTopBound) {
|
|
103
|
-
y -= lineSpacing / 2 - 1;
|
|
104
|
-
} else if (index === strings.length - 1 && !isBottomBound) {
|
|
105
|
-
y += lineSpacing / 2 - 1;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Store the y value
|
|
109
|
-
lineYs.push(y);
|
|
110
|
-
|
|
111
|
-
// Store a subsequent y value connecting this group to the main
|
|
112
|
-
// stem above/below the stave if it's the top/bottom string
|
|
113
|
-
if (stemDirection === 1 && isTopBound) {
|
|
114
|
-
lineYs.push(stemY - 2);
|
|
115
|
-
} else if (stemDirection === -1 && isBottomBound) {
|
|
116
|
-
lineYs.push(stemY + 2);
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
// Add the sorted y values to the
|
|
121
|
-
stemLines.push(lineYs.sort((a, b) => a - b));
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
return stemLines;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export class TabNote extends StemmableNote {
|
|
128
|
-
static get CATEGORY(): string {
|
|
129
|
-
return Category.TabNote;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
protected ghost: boolean;
|
|
133
|
-
protected fretElement: Element[] = [];
|
|
134
|
-
protected positions: TabNotePosition[];
|
|
135
|
-
|
|
136
|
-
// Initialize the TabNote with a `noteStruct` full of properties
|
|
137
|
-
// and whether to `drawStem` when rendering the note
|
|
138
|
-
constructor(noteStruct: TabNoteStruct, drawStem: boolean = false) {
|
|
139
|
-
super(noteStruct);
|
|
140
|
-
|
|
141
|
-
this.ghost = false; // Renders parenthesis around notes
|
|
142
|
-
|
|
143
|
-
// Note properties
|
|
144
|
-
// The fret positions in the note. An array of `{ str: X, fret: X }`
|
|
145
|
-
this.positions = noteStruct.positions || [];
|
|
146
|
-
|
|
147
|
-
// Render Options
|
|
148
|
-
this.renderOptions = {
|
|
149
|
-
...this.renderOptions,
|
|
150
|
-
// Flag to draw a stem
|
|
151
|
-
drawStem,
|
|
152
|
-
// Flag to draw dot modifiers
|
|
153
|
-
drawDots: drawStem,
|
|
154
|
-
// Flag to extend the main stem through the stave and fret positions
|
|
155
|
-
drawStemThroughStave: false,
|
|
156
|
-
// vertical shift from stave line
|
|
157
|
-
yShift: 0,
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
this.glyphProps = Note.getGlyphProps(this.duration, this.noteType);
|
|
161
|
-
defined(
|
|
162
|
-
this.glyphProps,
|
|
163
|
-
'BadArguments',
|
|
164
|
-
`No glyph found for duration '${this.duration}' and type '${this.noteType}'`
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
this.buildStem();
|
|
168
|
-
|
|
169
|
-
if (noteStruct.stemDirection) {
|
|
170
|
-
this.setStemDirection(noteStruct.stemDirection);
|
|
171
|
-
} else {
|
|
172
|
-
this.setStemDirection(Stem.UP);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// Renders parenthesis around notes
|
|
176
|
-
this.ghost = false;
|
|
177
|
-
this.updateWidth();
|
|
178
|
-
}
|
|
179
|
-
// Return the number of the greatest string, which is the string lowest on the display
|
|
180
|
-
greatestString = (): number => {
|
|
181
|
-
return this.positions.map((x) => x.str).reduce((a, b) => (a > b ? a : b));
|
|
182
|
-
};
|
|
183
|
-
// Return the number of the least string, which is the string highest on the display
|
|
184
|
-
leastString = (): number => {
|
|
185
|
-
return this.positions.map((x) => x.str).reduce((a, b) => (a < b ? a : b));
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
reset(): this {
|
|
189
|
-
super.reset();
|
|
190
|
-
if (this.stave) this.setStave(this.stave);
|
|
191
|
-
return this;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// Set as ghost `TabNote`, surrounds the fret positions with parenthesis.
|
|
195
|
-
// Often used for indicating frets that are being bent to
|
|
196
|
-
setGhost(ghost: boolean): this {
|
|
197
|
-
this.ghost = ghost;
|
|
198
|
-
this.updateWidth();
|
|
199
|
-
return this;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// Determine if the note has a stem
|
|
203
|
-
hasStem(): boolean {
|
|
204
|
-
if (this.renderOptions.drawStem) return true;
|
|
205
|
-
return false;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// Get the default stem extension for the note
|
|
209
|
-
getStemExtension(): number {
|
|
210
|
-
if (this.stemExtensionOverride !== undefined) {
|
|
211
|
-
return this.stemExtensionOverride;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
return this.flag.getHeight() > Stem.HEIGHT ? this.flag.getHeight() - Stem.HEIGHT : 0;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
static tabToElement(fret: string): Element {
|
|
218
|
-
let el: Element;
|
|
219
|
-
|
|
220
|
-
if (fret.toUpperCase() === 'X') {
|
|
221
|
-
el = new Element('TabNote');
|
|
222
|
-
el.setText(Glyphs.accidentalDoubleSharp);
|
|
223
|
-
} else {
|
|
224
|
-
el = new Element('TabNote.text');
|
|
225
|
-
el.setText(fret);
|
|
226
|
-
el.setYShift(el.getHeight() / 2);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
return el;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// Calculate and store the width of the note
|
|
233
|
-
updateWidth(): void {
|
|
234
|
-
this.fretElement = [];
|
|
235
|
-
this.width = 0;
|
|
236
|
-
for (let i = 0; i < this.positions.length; ++i) {
|
|
237
|
-
let fret = this.positions[i].fret;
|
|
238
|
-
if (this.ghost) fret = '(' + fret + ')';
|
|
239
|
-
const el = TabNote.tabToElement(fret.toString());
|
|
240
|
-
this.fretElement.push(el);
|
|
241
|
-
this.width = Math.max(el.getWidth(), this.width);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// Set the `stave` to the note
|
|
246
|
-
setStave(stave: Stave): this {
|
|
247
|
-
super.setStave(stave);
|
|
248
|
-
const ctx = stave.getContext();
|
|
249
|
-
this.setContext(ctx);
|
|
250
|
-
|
|
251
|
-
// we subtract 1 from `line` because getYForLine expects a 0-based index,
|
|
252
|
-
// while the position.str is a 1-based index
|
|
253
|
-
const ys = this.positions.map(({ str: line }) => stave.getYForLine(Number(line) - 1));
|
|
254
|
-
|
|
255
|
-
this.setYs(ys);
|
|
256
|
-
|
|
257
|
-
if (this.stem) {
|
|
258
|
-
this.stem.setYBounds(this.getStemY(), this.getStemY());
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
return this;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// Get the fret positions for the note
|
|
265
|
-
getPositions(): TabNotePosition[] {
|
|
266
|
-
return this.positions;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// Get the default `x` and `y` coordinates for a modifier at a specific
|
|
270
|
-
// `position` at a fret position `index`
|
|
271
|
-
getModifierStartXY(position: number, index: number): { x: number; y: number } {
|
|
272
|
-
if (!this.preFormatted) {
|
|
273
|
-
throw new RuntimeError('UnformattedNote', "Can't call GetModifierStartXY on an unformatted note");
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
if (this.ys.length === 0) {
|
|
277
|
-
throw new RuntimeError('NoYValues', 'No Y-Values calculated for this note.');
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
let x = 0;
|
|
281
|
-
if (position === Modifier.Position.LEFT) {
|
|
282
|
-
x = -1 * 2; // FIXME: modifier padding, move to font file
|
|
283
|
-
} else if (position === Modifier.Position.RIGHT) {
|
|
284
|
-
x = this.width + 2; // FIXME: modifier padding, move to font file
|
|
285
|
-
} else if (position === Modifier.Position.BELOW || position === Modifier.Position.ABOVE) {
|
|
286
|
-
const noteGlyphWidth = this.width;
|
|
287
|
-
x = noteGlyphWidth / 2;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
return {
|
|
291
|
-
x: this.getAbsoluteX() + x,
|
|
292
|
-
y: this.ys[index],
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// Get the default line for rest
|
|
297
|
-
getLineForRest(): number {
|
|
298
|
-
return Number(this.positions[0].str);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
// Pre-render formatting
|
|
302
|
-
preFormat(): void {
|
|
303
|
-
if (this.preFormatted) return;
|
|
304
|
-
if (this.modifierContext) this.modifierContext.preFormat();
|
|
305
|
-
// width is already set during init()
|
|
306
|
-
this.preFormatted = true;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// Get the x position for the stem
|
|
310
|
-
getStemX(): number {
|
|
311
|
-
return this.getCenterGlyphX();
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
// Get the y position for the stem
|
|
315
|
-
getStemY(): number {
|
|
316
|
-
const numLines = this.checkStave().getNumLines();
|
|
317
|
-
|
|
318
|
-
// The decimal staff line amounts provide optimal spacing between the
|
|
319
|
-
// fret number and the stem
|
|
320
|
-
const stemUpLine = -0.5;
|
|
321
|
-
const stemDownLine = numLines - 0.5;
|
|
322
|
-
const stemStartLine = Stem.UP === this.stemDirection ? stemUpLine : stemDownLine;
|
|
323
|
-
|
|
324
|
-
return this.checkStave().getYForLine(stemStartLine);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
// Get the stem extents for the tabnote
|
|
328
|
-
getStemExtents(): { topY: number; baseY: number } {
|
|
329
|
-
return this.checkStem().getExtents();
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// Draw the fal onto the context
|
|
333
|
-
drawFlag(): void {
|
|
334
|
-
const {
|
|
335
|
-
beam,
|
|
336
|
-
glyphProps,
|
|
337
|
-
renderOptions: { drawStem },
|
|
338
|
-
} = this;
|
|
339
|
-
const context = this.checkContext();
|
|
340
|
-
|
|
341
|
-
const shouldDrawFlag = beam === undefined && drawStem;
|
|
342
|
-
|
|
343
|
-
// Now it's the flag's turn.
|
|
344
|
-
if (glyphProps.codeFlagUp && shouldDrawFlag) {
|
|
345
|
-
const flagX = this.getStemX();
|
|
346
|
-
const flagY =
|
|
347
|
-
this.getStemDirection() === Stem.DOWN
|
|
348
|
-
? // Down stems are below the note head and have flags on the right.
|
|
349
|
-
this.getStemY() - this.checkStem().getHeight() - this.getStemExtension()
|
|
350
|
-
: // Up stems are above the note head and have flags on the right.
|
|
351
|
-
this.getStemY() - this.checkStem().getHeight() + this.getStemExtension();
|
|
352
|
-
|
|
353
|
-
// Draw the Flag
|
|
354
|
-
this.applyStyle(context, this.flagStyle);
|
|
355
|
-
this.flag.renderText(context, flagX, flagY);
|
|
356
|
-
this.restoreStyle(context, this.flagStyle);
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
// Render the modifiers onto the context.
|
|
361
|
-
drawModifiers(): void {
|
|
362
|
-
this.modifiers.forEach((modifier) => {
|
|
363
|
-
// Only draw the dots if enabled.
|
|
364
|
-
if (isDot(modifier) && !this.renderOptions.drawDots) {
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
modifier.setContext(this.getContext());
|
|
369
|
-
modifier.drawWithStyle();
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// Render the stem extension through the fret positions
|
|
374
|
-
drawStemThrough(): void {
|
|
375
|
-
const stemX = this.getStemX();
|
|
376
|
-
const stemY = this.getStemY();
|
|
377
|
-
const ctx = this.checkContext();
|
|
378
|
-
|
|
379
|
-
const drawStem = this.renderOptions.drawStem;
|
|
380
|
-
const stemThrough = this.renderOptions.drawStemThroughStave;
|
|
381
|
-
if (drawStem && stemThrough) {
|
|
382
|
-
const numLines = this.checkStave().getNumLines();
|
|
383
|
-
const stringsUsed = this.positions.map((position) => Number(position.str));
|
|
384
|
-
|
|
385
|
-
const unusedStrings = getUnusedStringGroups(numLines, stringsUsed);
|
|
386
|
-
const stemLines = getPartialStemLines(stemY, unusedStrings, this.checkStave(), this.getStemDirection());
|
|
387
|
-
|
|
388
|
-
ctx.save();
|
|
389
|
-
ctx.setLineWidth(Stem.WIDTH);
|
|
390
|
-
stemLines.forEach((bounds) => {
|
|
391
|
-
if (bounds.length === 0) return;
|
|
392
|
-
|
|
393
|
-
ctx.beginPath();
|
|
394
|
-
ctx.moveTo(stemX, bounds[0]);
|
|
395
|
-
ctx.lineTo(stemX, bounds[bounds.length - 1]);
|
|
396
|
-
ctx.stroke();
|
|
397
|
-
ctx.closePath();
|
|
398
|
-
});
|
|
399
|
-
ctx.restore();
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
// Render the fret positions onto the context
|
|
404
|
-
drawPositions(): void {
|
|
405
|
-
const ctx = this.checkContext();
|
|
406
|
-
const x = this.getAbsoluteX();
|
|
407
|
-
const ys = this.ys;
|
|
408
|
-
for (let i = 0; i < this.positions.length; ++i) {
|
|
409
|
-
const y = ys[i] + this.renderOptions.yShift;
|
|
410
|
-
const el = this.fretElement[i];
|
|
411
|
-
|
|
412
|
-
// Center the fret text beneath the stem
|
|
413
|
-
const tabX = x - el.getWidth() / 2;
|
|
414
|
-
|
|
415
|
-
// FIXME: Magic numbers.
|
|
416
|
-
ctx.clearRect(tabX - 2, y - 3, el.getWidth() + 4, 6);
|
|
417
|
-
|
|
418
|
-
el.renderText(ctx, tabX, y);
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
// The main rendering function for the entire note.
|
|
423
|
-
draw(): void {
|
|
424
|
-
const ctx = this.checkContext();
|
|
425
|
-
|
|
426
|
-
if (this.ys.length === 0) {
|
|
427
|
-
throw new RuntimeError('NoYValues', "Can't draw note without Y values.");
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
this.setRendered();
|
|
431
|
-
const renderStem = this.beam === undefined && this.renderOptions.drawStem;
|
|
432
|
-
|
|
433
|
-
this.applyStyle();
|
|
434
|
-
ctx.openGroup('tabnote', this.getAttribute('id'));
|
|
435
|
-
this.drawPositions();
|
|
436
|
-
this.drawStemThrough();
|
|
437
|
-
|
|
438
|
-
if (this.stem && renderStem) {
|
|
439
|
-
const stemX = this.getStemX();
|
|
440
|
-
this.stem.setNoteHeadXBounds(stemX, stemX);
|
|
441
|
-
this.stem.setContext(ctx).draw();
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
this.drawFlag();
|
|
445
|
-
this.drawModifiers();
|
|
446
|
-
ctx.closeGroup();
|
|
447
|
-
this.restoreStyle();
|
|
448
|
-
}
|
|
449
|
-
}
|
package/src/tabslide.ts
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
|
|
2
|
-
// MIT License
|
|
3
|
-
//
|
|
4
|
-
// This class implements varies types of ties between contiguous notes. The
|
|
5
|
-
// ties include: regular ties, hammer ons, pull offs, and slides.
|
|
6
|
-
|
|
7
|
-
import { TieNotes } from './stavetie';
|
|
8
|
-
import { TabNote } from './tabnote';
|
|
9
|
-
import { TabTie } from './tabtie';
|
|
10
|
-
import { Category } from './typeguard';
|
|
11
|
-
import { RuntimeError } from './util';
|
|
12
|
-
|
|
13
|
-
export class TabSlide extends TabTie {
|
|
14
|
-
static get CATEGORY(): string {
|
|
15
|
-
return Category.TabSlide;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
static get SLIDE_UP(): number {
|
|
19
|
-
return 1;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
static get SLIDE_DOWN(): number {
|
|
23
|
-
return -1;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
static createSlideUp(notes: TieNotes): TabSlide {
|
|
27
|
-
return new TabSlide(notes, TabSlide.SLIDE_UP);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
static createSlideDown(notes: TieNotes): TabSlide {
|
|
31
|
-
return new TabSlide(notes, TabSlide.SLIDE_DOWN);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @param notes is a struct of the form:
|
|
36
|
-
* {
|
|
37
|
-
* firstNote: Note,
|
|
38
|
-
* lastNote: Note,
|
|
39
|
-
* firstIndexes: [n1, n2, n3],
|
|
40
|
-
* lastIndexes: [n1, n2, n3]
|
|
41
|
-
* }
|
|
42
|
-
* @param notes.firstNote the starting note of the slide
|
|
43
|
-
* @param notes.lastNote the ending note of the slide
|
|
44
|
-
* @param notes.firstIndexes specifies which string + fret positions of the TabNote are used in this slide. zero indexed.
|
|
45
|
-
* @param notes.lastIndexes currently unused. we assume it's the same as firstIndexes.
|
|
46
|
-
*
|
|
47
|
-
* @param direction TabSlide.SLIDE_UP or TabSlide.SLIDE_DOWN
|
|
48
|
-
*/
|
|
49
|
-
constructor(notes: TieNotes, direction?: number) {
|
|
50
|
-
super(notes, 'sl.');
|
|
51
|
-
|
|
52
|
-
// Determine the direction automatically if it is not provided.
|
|
53
|
-
if (!direction) {
|
|
54
|
-
let firstFret = (notes.firstNote as TabNote).getPositions()[0].fret;
|
|
55
|
-
if (typeof firstFret === 'string') {
|
|
56
|
-
firstFret = parseInt(firstFret, 10);
|
|
57
|
-
}
|
|
58
|
-
let lastFret = (notes.lastNote as TabNote).getPositions()[0].fret;
|
|
59
|
-
if (typeof lastFret === 'string') {
|
|
60
|
-
lastFret = parseInt(lastFret, 10);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// If either of the frets are 'X', parseInt() above will return NaN.
|
|
64
|
-
// Choose TabSlide.SLIDE_UP by default.
|
|
65
|
-
if (isNaN(firstFret) || isNaN(lastFret)) {
|
|
66
|
-
direction = TabSlide.SLIDE_UP;
|
|
67
|
-
} else {
|
|
68
|
-
direction = firstFret > lastFret ? TabSlide.SLIDE_DOWN : TabSlide.SLIDE_UP;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
this.direction = direction;
|
|
73
|
-
this.renderOptions.cp1 = 11;
|
|
74
|
-
this.renderOptions.cp2 = 14;
|
|
75
|
-
this.renderOptions.yShift = 0.5;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* @param params.firstX is specified in pixels.
|
|
80
|
-
* @param params.lastX is specified in pixels.
|
|
81
|
-
*/
|
|
82
|
-
renderTie(params: { direction: number; firstX: number; lastX: number; lastYs: number[]; firstYs: number[] }): void {
|
|
83
|
-
if (params.firstYs.length === 0 || params.lastYs.length === 0) {
|
|
84
|
-
throw new RuntimeError('BadArguments', 'No Y-values to render');
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const ctx = this.checkContext();
|
|
88
|
-
const firstX = params.firstX; // pixel units
|
|
89
|
-
const firstYs = params.firstYs;
|
|
90
|
-
const lastX = params.lastX; // pixel units
|
|
91
|
-
|
|
92
|
-
const direction = params.direction;
|
|
93
|
-
if (direction !== TabSlide.SLIDE_UP && direction !== TabSlide.SLIDE_DOWN) {
|
|
94
|
-
throw new RuntimeError('BadSlide', 'Invalid slide direction');
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// eslint-disable-next-line
|
|
98
|
-
const firstIndexes = this.notes.firstIndexes!;
|
|
99
|
-
for (let i = 0; i < firstIndexes.length; ++i) {
|
|
100
|
-
const slideY = firstYs[firstIndexes[i]] + this.renderOptions.yShift;
|
|
101
|
-
|
|
102
|
-
if (isNaN(slideY)) {
|
|
103
|
-
throw new RuntimeError('BadArguments', 'Bad indexes for slide rendering.');
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
ctx.beginPath();
|
|
107
|
-
ctx.moveTo(firstX, slideY + 3 * direction);
|
|
108
|
-
ctx.lineTo(lastX, slideY - 3 * direction);
|
|
109
|
-
ctx.closePath();
|
|
110
|
-
ctx.stroke();
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
this.setRendered();
|
|
114
|
-
}
|
|
115
|
-
}
|
package/src/tabstave.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
|
|
2
|
-
|
|
3
|
-
import { Stave, StaveOptions } from './stave';
|
|
4
|
-
import { Category } from './typeguard';
|
|
5
|
-
|
|
6
|
-
export class TabStave extends Stave {
|
|
7
|
-
static get CATEGORY(): string {
|
|
8
|
-
return Category.TabStave;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
constructor(x: number, y: number, width: number, options?: StaveOptions) {
|
|
12
|
-
const tabOptions = {
|
|
13
|
-
spacingBetweenLinesPx: 13,
|
|
14
|
-
numLines: 6,
|
|
15
|
-
topTextPosition: 1,
|
|
16
|
-
...options,
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
super(x, y, width, tabOptions);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
getYForGlyphs(): number {
|
|
23
|
-
return this.getYForLine(2.5);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Deprecated
|
|
27
|
-
addTabGlyph(): this {
|
|
28
|
-
this.addClef('tab');
|
|
29
|
-
return this;
|
|
30
|
-
}
|
|
31
|
-
}
|
package/src/tabtie.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
|
|
2
|
-
// MIT License
|
|
3
|
-
//
|
|
4
|
-
// ## Description
|
|
5
|
-
// This class implements varies types of ties between contiguous notes. The
|
|
6
|
-
// ties include: regular ties, hammer ons, pull offs, and slides.
|
|
7
|
-
|
|
8
|
-
import { StaveTie, TieNotes } from './stavetie';
|
|
9
|
-
import { Category } from './typeguard';
|
|
10
|
-
|
|
11
|
-
export class TabTie extends StaveTie {
|
|
12
|
-
static get CATEGORY(): string {
|
|
13
|
-
return Category.TabTie;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
static createHammeron(notes: TieNotes): TabTie {
|
|
17
|
-
return new TabTie(notes, 'H');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
static createPulloff(notes: TieNotes): TabTie {
|
|
21
|
-
return new TabTie(notes, 'P');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @param notes is a struct that has:
|
|
26
|
-
* {
|
|
27
|
-
* firstNote: Note,
|
|
28
|
-
* lastNote: Note,
|
|
29
|
-
* firstIndexes: [n1, n2, n3],
|
|
30
|
-
* lastIndexes: [n1, n2, n3]
|
|
31
|
-
* }
|
|
32
|
-
*
|
|
33
|
-
* @param text
|
|
34
|
-
*/
|
|
35
|
-
constructor(notes: TieNotes, text?: string) {
|
|
36
|
-
super(notes, text);
|
|
37
|
-
|
|
38
|
-
this.renderOptions.cp1 = 9;
|
|
39
|
-
this.renderOptions.cp2 = 11;
|
|
40
|
-
this.renderOptions.yShift = 3;
|
|
41
|
-
|
|
42
|
-
this.direction = -1; // Tab tie's are always face up.
|
|
43
|
-
}
|
|
44
|
-
}
|