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.
Files changed (112) hide show
  1. package/build/cjs/vexflow-bravura.js +2 -2
  2. package/build/cjs/vexflow-bravura.js.map +1 -1
  3. package/build/cjs/vexflow-core.js +2 -2
  4. package/build/cjs/vexflow-core.js.map +1 -1
  5. package/build/cjs/vexflow-debug-with-tests.js +4 -4
  6. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  7. package/build/cjs/vexflow-debug.js +4 -4
  8. package/build/cjs/vexflow-debug.js.map +1 -1
  9. package/build/cjs/vexflow.js +2 -2
  10. package/build/cjs/vexflow.js.map +1 -1
  11. package/build/esm/src/version.js +3 -3
  12. package/package.json +1 -3
  13. package/entry/vexflow-bravura.ts +0 -25
  14. package/entry/vexflow-core.ts +0 -16
  15. package/entry/vexflow-debug-with-tests.ts +0 -64
  16. package/entry/vexflow-debug.ts +0 -54
  17. package/entry/vexflow.ts +0 -47
  18. package/src/accidental.ts +0 -570
  19. package/src/annotation.ts +0 -294
  20. package/src/articulation.ts +0 -383
  21. package/src/barnote.ts +0 -95
  22. package/src/beam.ts +0 -999
  23. package/src/bend.ts +0 -268
  24. package/src/boundingbox.ts +0 -108
  25. package/src/canvascontext.ts +0 -348
  26. package/src/chordsymbol.ts +0 -473
  27. package/src/clef.ts +0 -164
  28. package/src/clefnote.ts +0 -50
  29. package/src/crescendo.ts +0 -132
  30. package/src/curve.ts +0 -195
  31. package/src/dot.ts +0 -171
  32. package/src/easyscore.ts +0 -538
  33. package/src/element.ts +0 -692
  34. package/src/factory.ts +0 -694
  35. package/src/font.ts +0 -343
  36. package/src/fonts/academico.ts +0 -2
  37. package/src/fonts/academicobold.ts +0 -2
  38. package/src/fonts/bravura.ts +0 -2
  39. package/src/fonts/gonville.ts +0 -2
  40. package/src/fonts/petaluma.ts +0 -2
  41. package/src/fonts/petalumascript.ts +0 -2
  42. package/src/formatter.ts +0 -1107
  43. package/src/fraction.ts +0 -245
  44. package/src/frethandfinger.ts +0 -180
  45. package/src/ghostnote.ts +0 -75
  46. package/src/glyphnote.ts +0 -68
  47. package/src/glyphs.ts +0 -5880
  48. package/src/gracenote.ts +0 -146
  49. package/src/gracenotegroup.ts +0 -194
  50. package/src/gracetabnote.ts +0 -30
  51. package/src/index.ts +0 -90
  52. package/src/keymanager.ts +0 -153
  53. package/src/keysignature.ts +0 -272
  54. package/src/keysignote.ts +0 -46
  55. package/src/metrics.ts +0 -222
  56. package/src/modifier.ts +0 -216
  57. package/src/modifiercontext.ts +0 -177
  58. package/src/multimeasurerest.ts +0 -229
  59. package/src/music.ts +0 -443
  60. package/src/note.ts +0 -690
  61. package/src/notehead.ts +0 -158
  62. package/src/notesubgroup.ts +0 -88
  63. package/src/ornament.ts +0 -301
  64. package/src/parenthesis.ts +0 -89
  65. package/src/parser.ts +0 -263
  66. package/src/pedalmarking.ts +0 -273
  67. package/src/registry.ts +0 -146
  68. package/src/rendercontext.ts +0 -98
  69. package/src/renderer.ts +0 -166
  70. package/src/repeatnote.ts +0 -25
  71. package/src/stave.ts +0 -885
  72. package/src/stavebarline.ts +0 -231
  73. package/src/staveconnector.ts +0 -281
  74. package/src/stavehairpin.ts +0 -209
  75. package/src/staveline.ts +0 -343
  76. package/src/stavemodifier.ts +0 -93
  77. package/src/stavenote.ts +0 -1230
  78. package/src/staverepetition.ts +0 -148
  79. package/src/stavesection.ts +0 -54
  80. package/src/stavetempo.ts +0 -162
  81. package/src/stavetext.ts +0 -69
  82. package/src/stavetie.ts +0 -235
  83. package/src/stavevolta.ts +0 -66
  84. package/src/stem.ts +0 -225
  85. package/src/stemmablenote.ts +0 -248
  86. package/src/stringnumber.ts +0 -286
  87. package/src/strokes.ts +0 -214
  88. package/src/svgcontext.ts +0 -639
  89. package/src/system.ts +0 -327
  90. package/src/tables.ts +0 -796
  91. package/src/tabnote.ts +0 -449
  92. package/src/tabslide.ts +0 -115
  93. package/src/tabstave.ts +0 -31
  94. package/src/tabtie.ts +0 -44
  95. package/src/textbracket.ts +0 -231
  96. package/src/textdynamics.ts +0 -101
  97. package/src/textnote.ts +0 -175
  98. package/src/tickable.ts +0 -374
  99. package/src/tickcontext.ts +0 -280
  100. package/src/timesignature.ts +0 -229
  101. package/src/timesignote.ts +0 -45
  102. package/src/tremolo.ts +0 -51
  103. package/src/tuning.ts +0 -90
  104. package/src/tuplet.ts +0 -349
  105. package/src/typeguard.ts +0 -136
  106. package/src/util.ts +0 -169
  107. package/src/version.ts +0 -4
  108. package/src/vexflow.ts +0 -378
  109. package/src/vibrato.ts +0 -99
  110. package/src/vibratobracket.ts +0 -81
  111. package/src/voice.ts +0 -302
  112. package/src/web.ts +0 -35
package/src/note.ts DELETED
@@ -1,690 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- // MIT License
3
-
4
- import { Beam } from './beam';
5
- import { Fraction } from './fraction';
6
- import { Glyphs } from './glyphs';
7
- import { Metrics } from './metrics';
8
- import { Modifier } from './modifier';
9
- import { drawDot, RenderContext } from './rendercontext';
10
- import { Stave } from './stave';
11
- import { Stroke } from './strokes';
12
- import { Tables } from './tables';
13
- import { Tickable } from './tickable';
14
- import { TickContext } from './tickcontext';
15
- import { Category } from './typeguard';
16
- import { defined, RuntimeError } from './util';
17
- import { Voice } from './voice';
18
-
19
- export interface GlyphProps {
20
- codeHead: string;
21
- stemBeamExtension: number;
22
- stem: boolean;
23
- codeFlagUp?: string;
24
- beamCount: number;
25
- }
26
-
27
- export interface KeyProps {
28
- key: string;
29
- octave: number;
30
- line: number;
31
- intValue?: number;
32
- code?: string;
33
- displaced: boolean;
34
- }
35
-
36
- export interface NoteMetrics {
37
- /** The total width of the note (including modifiers). */
38
- width: number;
39
- glyphWidth?: number;
40
- /** The width of the note head only. */
41
- notePx: number;
42
- /** Start `X` for left modifiers. */
43
- modLeftPx: number;
44
- /** Start `X` for right modifiers. */
45
- modRightPx: number;
46
- /** Extra space on left of note. */
47
- leftDisplacedHeadPx: number;
48
- glyphPx: number;
49
- /** Extra space on right of note. */
50
- rightDisplacedHeadPx: number;
51
- }
52
-
53
- export interface NoteDuration {
54
- duration: string;
55
- dots: number;
56
- type: string;
57
- }
58
-
59
- export interface ParsedNote {
60
- duration: string;
61
- type: string;
62
- customTypes: string[];
63
- dots: number;
64
- ticks: number;
65
- }
66
-
67
- export interface NoteStruct {
68
- /** Array of pitches, e.g: `['c/4', 'e/4', 'g/4']` */
69
- keys?: string[];
70
- /** The time length (e.g., `q` for quarter, `h` for half, `8` for eighth etc.). */
71
- duration: string;
72
- line?: number;
73
- /** The number of dots, which affects the duration. */
74
- dots?: number;
75
- /** The note type (e.g., `r` for rest, `s` for slash notes, etc.). */
76
- type?: string;
77
- alignCenter?: boolean;
78
- durationOverride?: Fraction;
79
- }
80
-
81
- /**
82
- * Note implements an abstract interface for notes and chords that
83
- * are rendered on a stave. Notes have some common properties: All of them
84
- * have a value (e.g., pitch, fret, etc.) and a duration (quarter, half, etc.)
85
- *
86
- * Some notes have stems, heads, dots, etc. Most notational elements that
87
- * surround a note are called *modifiers*, and every note has an associated
88
- * array of them. All notes also have a rendering context and belong to a stave.
89
- */
90
- export abstract class Note extends Tickable {
91
- //////////////////////////////////////////////////////////////////////////////////////////////////
92
- // STATIC MEMBERS
93
-
94
- static get CATEGORY(): string {
95
- return Category.Note;
96
- }
97
-
98
- // Return a glyph given duration and type. The type can be a custom glyph code from customNoteHeads.
99
- // The default type is a regular note ('n').
100
- static getGlyphProps(duration: string, type: string = 'n'): GlyphProps {
101
- duration = Tables.sanitizeDuration(duration);
102
-
103
- // Lookup duration for default glyph head code
104
- let code = Tables.durationCodes[duration];
105
- if (code === undefined) {
106
- code = Tables.durationCodes['4'];
107
- }
108
-
109
- // Try and get the note head
110
- const codeNoteHead = Tables.codeNoteHead(type.toUpperCase(), duration);
111
- // Merge duration props for 'duration' with the note head properties.
112
- if (codeNoteHead !== Glyphs.null) {
113
- code = { ...code, codeHead: codeNoteHead };
114
- }
115
-
116
- return code as GlyphProps;
117
- }
118
-
119
- /** Debug helper. Displays various note metrics for the given note. */
120
- static plotMetrics(ctx: RenderContext, note: Tickable, yPos: number): void {
121
- const metrics = note.getMetrics();
122
- const xStart = note.getAbsoluteX() - metrics.modLeftPx - metrics.leftDisplacedHeadPx;
123
- const xPre1 = note.getAbsoluteX() - metrics.leftDisplacedHeadPx;
124
- const xAbs = note.getAbsoluteX();
125
- const xPost1 = note.getAbsoluteX() + metrics.notePx;
126
- const xPost2 = note.getAbsoluteX() + metrics.notePx + metrics.rightDisplacedHeadPx;
127
- const xEnd = note.getAbsoluteX() + metrics.notePx + metrics.rightDisplacedHeadPx + metrics.modRightPx;
128
- const xFreedomRight = xEnd + (note.getFormatterMetrics().freedom.right ?? 0);
129
-
130
- const xWidth = xEnd - xStart;
131
- ctx.save();
132
- ctx.setFont(Metrics.get('fontFamily'), 8);
133
- ctx.fillText(Math.round(xWidth) + 'px', xStart + note.getXShift(), yPos);
134
-
135
- const y = yPos + 7;
136
- function stroke(x1: number, x2: number, color: string, yy: number = y) {
137
- ctx.beginPath();
138
- ctx.setStrokeStyle(color);
139
- ctx.setFillStyle(color);
140
- ctx.setLineWidth(3);
141
- ctx.moveTo(x1 + note.getXShift(), yy);
142
- ctx.lineTo(x2 + note.getXShift(), yy);
143
- ctx.stroke();
144
- }
145
-
146
- stroke(xStart, xPre1, 'red');
147
- stroke(xPre1, xAbs, '#999');
148
- stroke(xAbs, xPost1, 'green');
149
- stroke(xPost1, xPost2, '#999');
150
- stroke(xPost2, xEnd, 'red');
151
- stroke(xEnd, xFreedomRight, '#DD0');
152
- stroke(xStart - note.getXShift(), xStart, '#BBB'); // Shift
153
- drawDot(ctx, xAbs + note.getXShift(), y, 'blue');
154
-
155
- const formatterMetrics = note.getFormatterMetrics();
156
- if (formatterMetrics.iterations > 0) {
157
- const spaceDeviation = formatterMetrics.space.deviation;
158
- const prefix = spaceDeviation >= 0 ? '+' : '';
159
- ctx.setFillStyle('red');
160
- ctx.fillText(prefix + Math.round(spaceDeviation), xAbs + note.getXShift(), yPos - 10);
161
- }
162
- ctx.restore();
163
- }
164
-
165
- protected static parseDuration(durationString?: string): NoteDuration | undefined {
166
- if (!durationString) {
167
- return undefined;
168
- }
169
- const regexp = /(\d*\/?\d+|[a-z])(d*)([nrhms]|$)/;
170
- const result = regexp.exec(durationString);
171
- if (!result) {
172
- return undefined;
173
- }
174
-
175
- const duration = result[1];
176
- const dots = result[2].length;
177
- const type = result[3] || 'n';
178
-
179
- return { duration, dots, type };
180
- }
181
-
182
- protected static parseNoteStruct(noteStruct: NoteStruct): ParsedNote | undefined {
183
- // Preserve backwards-compatibility
184
- const durationProps = Note.parseDuration(noteStruct.duration);
185
- if (!durationProps) {
186
- return undefined;
187
- }
188
-
189
- // If specified type is invalid, return undefined.
190
- let type = noteStruct.type;
191
- if (type && !Tables.validTypes[type]) {
192
- return undefined;
193
- }
194
-
195
- // If no type specified, check duration or custom types
196
- const customTypes: string[] = [];
197
- if (!type) {
198
- type = durationProps.type || 'n';
199
-
200
- // If we have keys, try and check if we've got a custom glyph
201
- if (noteStruct.keys !== undefined) {
202
- noteStruct.keys.forEach((k, i) => {
203
- const result = k.split('/');
204
- // We have a custom glyph specified after the note eg. /X2
205
- customTypes[i] = (result && result.length === 3 ? result[2] : type) as string;
206
- });
207
- }
208
- }
209
-
210
- // Calculate the tick duration of the note
211
- let ticks = Tables.durationToTicks(durationProps.duration);
212
- if (!ticks) {
213
- return undefined;
214
- }
215
-
216
- // Are there any dots?
217
- const dots = noteStruct.dots ? noteStruct.dots : durationProps.dots;
218
- if (typeof dots !== 'number') {
219
- return undefined;
220
- }
221
-
222
- // Add ticks as necessary depending on the numbr of dots
223
- let currentTicks = ticks;
224
- for (let i = 0; i < dots; i++) {
225
- if (currentTicks <= 1) return undefined;
226
-
227
- currentTicks = currentTicks / 2;
228
- ticks += currentTicks;
229
- }
230
-
231
- return {
232
- duration: durationProps.duration,
233
- type,
234
- customTypes,
235
- dots,
236
- ticks,
237
- };
238
- }
239
-
240
- //////////////////////////////////////////////////////////////////////////////////////////////////
241
- // INSTANCE MEMBERS
242
-
243
- glyphProps: GlyphProps;
244
- keys: string[];
245
- keyProps: KeyProps[];
246
-
247
- protected stave?: Stave;
248
- public renderOptions: {
249
- drawStemThroughStave?: boolean;
250
- draw?: boolean;
251
- drawDots?: boolean;
252
- drawStem?: boolean;
253
- yShift: number;
254
- extendLeft?: number;
255
- extendRight?: number;
256
- annotationSpacing: number;
257
- strokePx: number;
258
- };
259
- protected duration: string;
260
- protected leftDisplacedHeadPx: number;
261
- protected rightDisplacedHeadPx: number;
262
- protected noteType: string;
263
- protected customGlyphs: GlyphProps[];
264
- protected ys: number[];
265
- protected customTypes: string[];
266
- protected playNote?: Note;
267
- protected beam?: Beam;
268
-
269
- /**
270
- * Every note is a tickable, i.e., it can be mutated by the `Formatter` class for
271
- * positioning and layout.
272
- *
273
- * @param noteStruct To create a new note you need to provide a `noteStruct`.
274
- */
275
- constructor(noteStruct: NoteStruct) {
276
- super();
277
-
278
- if (!noteStruct) {
279
- throw new RuntimeError('BadArguments', 'Note must have valid initialization data to identify duration and type.');
280
- }
281
-
282
- /** Parses `noteStruct` and get note properties. */
283
- const parsedNoteStruct = Note.parseNoteStruct(noteStruct);
284
- if (!parsedNoteStruct) {
285
- throw new RuntimeError('BadArguments', `Invalid note initialization object: ${JSON.stringify(noteStruct)}`);
286
- }
287
-
288
- // Set note properties from parameters.
289
- this.keys = noteStruct.keys || [];
290
- // per-pitch properties
291
- this.keyProps = [];
292
-
293
- this.duration = parsedNoteStruct.duration;
294
- this.noteType = parsedNoteStruct.type;
295
- this.customTypes = parsedNoteStruct.customTypes;
296
-
297
- if (noteStruct.durationOverride) {
298
- // Custom duration
299
- this.setDuration(noteStruct.durationOverride);
300
- } else {
301
- // Default duration
302
- this.setIntrinsicTicks(parsedNoteStruct.ticks);
303
- }
304
-
305
- this.modifiers = [];
306
-
307
- // Get the glyph code for this note from the font.
308
- this.glyphProps = Note.getGlyphProps(this.duration, this.noteType);
309
- this.customGlyphs = this.customTypes.map((t) => Note.getGlyphProps(this.duration, t));
310
-
311
- // Note to play for audio players.
312
- this.playNote = undefined;
313
-
314
- // Positioning contexts used by the Formatter.
315
- this.ignoreTicks = false;
316
-
317
- // Positioning variables
318
- this.width = 0; // Width in pixels calculated after preFormat
319
- this.leftDisplacedHeadPx = 0; // Extra room on left for displaced note head
320
- this.rightDisplacedHeadPx = 0; // Extra room on right for displaced note head
321
- this.xShift = 0; // X shift from tick context X
322
- this.ys = []; // list of y coordinates for each note
323
- // we need to hold on to these for ties and beams.
324
-
325
- if (noteStruct.alignCenter) {
326
- this.setCenterAlignment(noteStruct.alignCenter);
327
- }
328
-
329
- // The render surface.
330
- this.renderOptions = {
331
- annotationSpacing: 5,
332
- strokePx: 1,
333
- yShift: 0,
334
- };
335
- }
336
-
337
- /**
338
- * Get the play note, which is arbitrary data that can be used by an
339
- * audio player.
340
- */
341
- getPlayNote(): Note | undefined {
342
- return this.playNote;
343
- }
344
-
345
- /**
346
- * Set the play note, which is arbitrary data that can be used by an
347
- * audio player.
348
- */
349
- setPlayNote(note: Note): this {
350
- this.playNote = note;
351
- return this;
352
- }
353
-
354
- /**
355
- * @returns true if this note is a type of rest.
356
- *
357
- * Rests don't have pitches, but take up space in the score.
358
- * Subclasses should override this default implementation.
359
- */
360
- isRest(): boolean {
361
- return false;
362
- }
363
-
364
- /** Add stroke. */
365
- addStroke(index: number, stroke: Stroke): this {
366
- stroke.setNote(this);
367
- stroke.setIndex(index);
368
- this.modifiers.push(stroke);
369
- this.preFormatted = false;
370
- return this;
371
- }
372
-
373
- /** Get the target stave. */
374
- getStave(): Stave | undefined {
375
- return this.stave;
376
- }
377
-
378
- /** Check and get the target stave. */
379
- checkStave(): Stave {
380
- return defined(this.stave, 'NoStave', 'No stave attached to instance.');
381
- }
382
-
383
- /** Set the target stave. */
384
- setStave(stave: Stave): this {
385
- this.stave = stave;
386
- this.setYs([stave.getYForLine(0)]); // Update Y values if the stave is changed.
387
- this.setContext(this.stave.getContext());
388
- return this;
389
- }
390
-
391
- /** Get spacing to the left of the notes. */
392
- getLeftDisplacedHeadPx(): number {
393
- return this.leftDisplacedHeadPx;
394
- }
395
-
396
- /** Get spacing to the right of the notes. */
397
- getRightDisplacedHeadPx(): number {
398
- return this.rightDisplacedHeadPx;
399
- }
400
-
401
- /** Set spacing to the left of the notes. */
402
- setLeftDisplacedHeadPx(x: number): this {
403
- this.leftDisplacedHeadPx = x;
404
- return this;
405
- }
406
-
407
- /** Set spacing to the right of the notes. */
408
- setRightDisplacedHeadPx(x: number): this {
409
- this.rightDisplacedHeadPx = x;
410
- return this;
411
- }
412
-
413
- /** True if this note has no duration (e.g., bar notes, spacers, etc.). */
414
- shouldIgnoreTicks(): boolean {
415
- return this.ignoreTicks;
416
- }
417
-
418
- /** Get the stave line number for the note. */
419
- // eslint-disable-next-line
420
- getLineNumber(isTopNote?: boolean): number {
421
- return 0;
422
- }
423
-
424
- /** Get the stave line number for rest. */
425
- getLineForRest(): number {
426
- return 0;
427
- }
428
-
429
- /** Get the glyph associated with this note. */
430
- getGlyphProps(): GlyphProps {
431
- return this.glyphProps;
432
- }
433
-
434
- /** Get the glyph width. */
435
- getGlyphWidth(): number {
436
- return 0;
437
- }
438
-
439
- /**
440
- * Set Y positions for this note. Each Y value is associated with
441
- * an individual pitch/key within the note/chord.
442
- */
443
- setYs(ys: number[]): this {
444
- this.ys = ys;
445
- return this;
446
- }
447
-
448
- /**
449
- * Get Y positions for this note. Each Y value is associated with
450
- * an individual pitch/key within the note/chord.
451
- */
452
- getYs(): number[] {
453
- if (this.ys.length === 0) {
454
- throw new RuntimeError('NoYValues', 'No Y-values calculated for this note.');
455
- }
456
-
457
- return this.ys;
458
- }
459
-
460
- /**
461
- * Get the Y position of the space above the stave onto which text can
462
- * be rendered.
463
- */
464
- getYForTopText(textLine: number): number {
465
- return this.checkStave().getYForTopText(textLine);
466
- }
467
-
468
- /** Return the voice that this note belongs in. */
469
- getVoice(): Voice {
470
- if (!this.voice) throw new RuntimeError('NoVoice', 'Note has no voice.');
471
- return this.voice;
472
- }
473
-
474
- /** Attach this note to `voice`. */
475
- setVoice(voice: Voice): this {
476
- this.voice = voice;
477
- this.preFormatted = false;
478
- return this;
479
- }
480
-
481
- /** Get the `TickContext` for this note. */
482
- getTickContext(): TickContext {
483
- return this.checkTickContext();
484
- }
485
-
486
- /** Set the `TickContext` for this note. */
487
- setTickContext(tc: TickContext): this {
488
- this.tickContext = tc;
489
- this.preFormatted = false;
490
- return this;
491
- }
492
-
493
- /** Accessor to duration. */
494
- getDuration(): string {
495
- return this.duration;
496
- }
497
-
498
- /** Accessor to isDotted. */
499
- isDotted(): boolean {
500
- return this.getModifiersByType(Category.Dot).length > 0;
501
- }
502
-
503
- /** Accessor to hasStem. */
504
- hasStem(): boolean {
505
- return false;
506
- }
507
-
508
- /** Accessor to note type. */
509
- getNoteType(): string {
510
- return this.noteType;
511
- }
512
-
513
- /** Get the beam. */
514
- getBeam(): Beam | undefined {
515
- return this.beam;
516
- }
517
-
518
- /** Check and get the beam. */
519
- checkBeam(): Beam {
520
- return defined(this.beam, 'NoBeam', 'No beam attached to instance');
521
- }
522
-
523
- /** Check it has a beam. */
524
- hasBeam(): boolean {
525
- return this.beam !== undefined;
526
- }
527
-
528
- /** Set the beam. */
529
- setBeam(beam: Beam): this {
530
- this.beam = beam;
531
- return this;
532
- }
533
-
534
- /**
535
- * Attach a modifier to this note.
536
- * @param modifier the Modifier to add.
537
- * @param index of the key to modify.
538
- * @returns this
539
- */
540
- addModifier(modifier: Modifier, index: number = 0): this {
541
- const signature = 'Note.addModifier(modifier: Modifier, index: number=0)';
542
- // Backwards compatibility with 3.0.9.
543
- if (typeof index === 'string') {
544
- index = parseInt(index);
545
- // eslint-disable-next-line
546
- console.warn(signature + ' expected a number for `index`, but received a string.');
547
- }
548
-
549
- // Some versions of VexFlow had the two parameters reversed.
550
- // Check here and throw an error if the argument types are not correct.
551
- if (typeof modifier !== 'object' || typeof index !== 'number') {
552
- throw new RuntimeError('WrongParams', 'Incorrect call signature. Use ' + signature + ' instead.');
553
- }
554
- modifier.setNote(this);
555
- modifier.setIndex(index);
556
- super.addModifier(modifier);
557
- return this;
558
- }
559
-
560
- /** Get all modifiers of a specific type in `this.modifiers`. */
561
- getModifiersByType(type: string): Modifier[] {
562
- return this.modifiers.filter((modifier) => modifier.getCategory() === type);
563
- }
564
-
565
- /** Get the coordinates for where modifiers begin. */
566
- // eslint-disable-next-line
567
- getModifierStartXY(position?: number, index?: number, options?: any): { x: number; y: number } {
568
- if (!this.preFormatted) {
569
- throw new RuntimeError('UnformattedNote', "Can't call GetModifierStartXY on an unformatted note");
570
- }
571
-
572
- return {
573
- x: this.getAbsoluteX(),
574
- y: this.ys[0],
575
- };
576
- }
577
-
578
- getRightParenthesisPx(index: number): number {
579
- const props = this.getKeyProps()[index];
580
- return props.displaced ? this.getRightDisplacedHeadPx() : 0;
581
- }
582
-
583
- getLeftParenthesisPx(index: number): number {
584
- const props = this.getKeyProps()[index];
585
- return props.displaced ? this.getLeftDisplacedHeadPx() - this.xShift : -this.xShift;
586
- }
587
-
588
- getFirstDotPx(): number {
589
- let px = this.getRightDisplacedHeadPx();
590
- const parentheses = this.checkModifierContext().getMembers('Parenthesis');
591
-
592
- // consider parentheses on noteheads, dots should be to the right of them
593
- if (parentheses.length !== 0) {
594
- px += parentheses[0].getWidth() + 1;
595
- }
596
- return px;
597
- }
598
-
599
- /** Get the metrics for this note. */
600
- getMetrics(): NoteMetrics {
601
- if (!this.preFormatted) {
602
- throw new RuntimeError('UnformattedNote', "Can't call getMetrics on an unformatted note.");
603
- }
604
-
605
- const modLeftPx = this.modifierContext ? this.modifierContext.getState().leftShift : 0;
606
- const modRightPx = this.modifierContext ? this.modifierContext.getState().rightShift : 0;
607
- const width = this.getWidth();
608
- const glyphWidth = this.getGlyphWidth();
609
- const notePx =
610
- width -
611
- modLeftPx - // subtract left modifiers
612
- modRightPx - // subtract right modifiers
613
- this.leftDisplacedHeadPx - // subtract left displaced head
614
- this.rightDisplacedHeadPx; // subtract right displaced head
615
-
616
- // NOTE: If you change this, remember to update MockTickable.getMetrics() in the tests/ directory.
617
- return {
618
- width,
619
- glyphWidth,
620
- notePx,
621
-
622
- // Modifier spacing.
623
- modLeftPx,
624
- modRightPx,
625
-
626
- // Displaced note head on left or right.
627
- leftDisplacedHeadPx: this.leftDisplacedHeadPx,
628
- rightDisplacedHeadPx: this.rightDisplacedHeadPx,
629
- glyphPx: 0,
630
- };
631
- }
632
-
633
- /**
634
- * Get the absolute `X` position of this note's tick context. This
635
- * excludes xShift, so you'll need to factor it in if you're
636
- * looking for the post-formatted x-position.
637
- */
638
- getAbsoluteX(): number {
639
- const tickContext = this.checkTickContext(`Can't getAbsoluteX() without a TickContext.`);
640
- // Position note to left edge of tick context.
641
- let x = tickContext.getX();
642
- if (this.stave) {
643
- x += this.stave.getNoteStartX() + Metrics.get('Stave.padding', 0);
644
- }
645
- if (this.isCenterAligned()) {
646
- x += this.getCenterXShift();
647
- }
648
- return x;
649
- }
650
-
651
- /** Get the direction of the stem. */
652
- getStemDirection(): number {
653
- throw new RuntimeError('NoStem', 'No stem attached to this note.');
654
- }
655
-
656
- /** Get the top and bottom `y` values of the stem. */
657
- getStemExtents(): Record<string, number> {
658
- throw new RuntimeError('NoStem', 'No stem attached to this note.');
659
- }
660
-
661
- /** Get the `x` coordinate to the right of the note. */
662
- getTieRightX(): number {
663
- let tieStartX = this.getAbsoluteX();
664
- const noteGlyphWidth = this.getGlyphWidth();
665
- tieStartX += noteGlyphWidth / 2;
666
- tieStartX += -this.width / 2 + this.width + 2;
667
-
668
- return tieStartX;
669
- }
670
-
671
- /** Get the `x` coordinate to the left of the note. */
672
- getTieLeftX(): number {
673
- let tieEndX = this.getAbsoluteX();
674
- const noteGlyphWidth = this.getGlyphWidth();
675
- tieEndX += noteGlyphWidth / 2;
676
- tieEndX -= this.width / 2 + 2;
677
-
678
- return tieEndX;
679
- }
680
-
681
- // Get the pitches in the note
682
- getKeys(): string[] {
683
- return this.keys;
684
- }
685
-
686
- // Get the properties for all the keys in the note
687
- getKeyProps(): KeyProps[] {
688
- return this.keyProps;
689
- }
690
- }