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
@@ -1,148 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- // @author: Larry Kuhns 2011
3
-
4
- import { Glyphs } from './glyphs';
5
- import { Metrics } from './metrics';
6
- import { Stave } from './stave';
7
- import { StaveModifier } from './stavemodifier';
8
- import { Category } from './typeguard';
9
-
10
- export class Repetition extends StaveModifier {
11
- static get CATEGORY(): string {
12
- return Category.Repetition;
13
- }
14
-
15
- static readonly type = {
16
- NONE: 1, // no coda or segno
17
- CODA_LEFT: 2, // coda at beginning of stave
18
- CODA_RIGHT: 3, // coda at end of stave
19
- SEGNO_LEFT: 4, // segno at beginning of stave
20
- SEGNO_RIGHT: 5, // segno at end of stave
21
- DC: 6, // D.C. at end of stave
22
- DC_AL_CODA: 7, // D.C. al coda at end of stave
23
- DC_AL_FINE: 8, // D.C. al Fine end of stave
24
- DS: 9, // D.S. at end of stave
25
- DS_AL_CODA: 10, // D.S. al coda at end of stave
26
- DS_AL_FINE: 11, // D.S. al Fine at end of stave
27
- FINE: 12, // Fine at end of stave
28
- TO_CODA: 13, // To Coda at end of stave
29
- };
30
-
31
- protected symbolType: number;
32
-
33
- protected xShift: number;
34
- protected yShift: number;
35
-
36
- constructor(type: number, x: number, yShift: number) {
37
- super();
38
-
39
- this.symbolType = type;
40
- this.x = x;
41
- this.xShift = 0;
42
- this.yShift = yShift;
43
- }
44
-
45
- setShiftX(x: number): this {
46
- this.xShift = x;
47
- return this;
48
- }
49
-
50
- setShiftY(y: number): this {
51
- this.yShift = y;
52
- return this;
53
- }
54
-
55
- draw(stave: Stave, x: number): this {
56
- this.setRendered();
57
-
58
- switch (this.symbolType) {
59
- case Repetition.type.CODA_RIGHT:
60
- this.drawCodaFixed(stave, x + stave.getWidth());
61
- break;
62
- case Repetition.type.CODA_LEFT:
63
- this.drawSymbolText(stave, x, 'Coda', true);
64
- break;
65
- case Repetition.type.SEGNO_LEFT:
66
- this.drawSegnoFixed(stave, x);
67
- break;
68
- case Repetition.type.SEGNO_RIGHT:
69
- this.drawSegnoFixed(stave, x + stave.getWidth());
70
- break;
71
- case Repetition.type.DC:
72
- this.drawSymbolText(stave, x, 'D.C.', false);
73
- break;
74
- case Repetition.type.DC_AL_CODA:
75
- this.drawSymbolText(stave, x, 'D.C. al', true);
76
- break;
77
- case Repetition.type.DC_AL_FINE:
78
- this.drawSymbolText(stave, x, 'D.C. al Fine', false);
79
- break;
80
- case Repetition.type.DS:
81
- this.drawSymbolText(stave, x, 'D.S.', false);
82
- break;
83
- case Repetition.type.DS_AL_CODA:
84
- this.drawSymbolText(stave, x, 'D.S. al', true);
85
- break;
86
- case Repetition.type.DS_AL_FINE:
87
- this.drawSymbolText(stave, x, 'D.S. al Fine', false);
88
- break;
89
- case Repetition.type.FINE:
90
- this.drawSymbolText(stave, x, 'Fine', false);
91
- break;
92
- case Repetition.type.TO_CODA:
93
- this.drawSymbolText(stave, x, 'To', true);
94
- break;
95
- default:
96
- break;
97
- }
98
-
99
- return this;
100
- }
101
-
102
- drawCodaFixed(stave: Stave, x: number): this {
103
- const y = stave.getYForTopText(stave.getNumLines());
104
- this.text = Glyphs.coda;
105
- this.renderText(stave.checkContext(), x, y + Metrics.get('Repetition.coda.offsetY'));
106
- return this;
107
- }
108
-
109
- drawSegnoFixed(stave: Stave, x: number): this {
110
- const y = stave.getYForTopText(stave.getNumLines());
111
- this.text = Glyphs.segno;
112
- this.renderText(stave.checkContext(), x, y + Metrics.get('Repetition.segno.offsetY'));
113
- return this;
114
- }
115
-
116
- drawSymbolText(stave: Stave, x: number, text: string, drawCoda: boolean): this {
117
- const ctx = stave.checkContext();
118
- let textX = 0;
119
-
120
- this.text = text;
121
- if (drawCoda) {
122
- this.text += ' \ue048' /*coda*/;
123
- }
124
- this.setFont(Metrics.getFontInfo('Repetition.text'));
125
- switch (this.symbolType) {
126
- // To the left
127
- case Repetition.type.CODA_LEFT:
128
- // Offset Coda text to right of stave beginning
129
- textX = stave.getVerticalBarWidth();
130
- break;
131
- // To the right
132
- case Repetition.type.DC:
133
- case Repetition.type.DC_AL_FINE:
134
- case Repetition.type.DS:
135
- case Repetition.type.DS_AL_FINE:
136
- case Repetition.type.FINE:
137
- default:
138
- textX =
139
- x - (stave.getNoteStartX() - this.x) + stave.getWidth() - this.width - Metrics.get('Repetition.text.offsetX');
140
- }
141
-
142
- const y = stave.getYForTopText(stave.getNumLines()) + Metrics.get('Repetition.text.offsetY');
143
-
144
- this.renderText(ctx, textX, y);
145
-
146
- return this;
147
- }
148
- }
@@ -1,54 +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 class StaveSection extends StaveModifier {
9
- static get CATEGORY(): string {
10
- return Category.StaveSection;
11
- }
12
-
13
- protected drawRect: boolean;
14
-
15
- constructor(section: string, x: number, yShift: number, drawRect = true) {
16
- super();
17
-
18
- this.setStaveSection(section);
19
- this.x = x;
20
- this.yShift = yShift;
21
- this.drawRect = drawRect;
22
- }
23
-
24
- setStaveSection(section: string): this {
25
- this.text = section;
26
- return this;
27
- }
28
-
29
- draw(stave: Stave, xShift: number): this {
30
- const borderWidth = 2;
31
- const padding = 2;
32
- const ctx = stave.checkContext();
33
- this.setRendered();
34
-
35
- ctx.save();
36
- ctx.setLineWidth(borderWidth);
37
-
38
- const headroom = -1 * this.textMetrics.actualBoundingBoxDescent;
39
- const width = this.width + 2 * padding; // add left & right padding
40
- const height = this.height + 2 * padding; // add top & bottom padding
41
-
42
- // Seems to be a good default y
43
- const y = stave.getYForTopText(1.5) + this.yShift;
44
- const x = this.x + xShift;
45
- if (this.drawRect) {
46
- ctx.beginPath();
47
- ctx.rect(x, y - height + headroom, width, height);
48
- ctx.stroke();
49
- }
50
- this.renderText(ctx, xShift + padding, y - padding);
51
- ctx.restore();
52
- return this;
53
- }
54
- }
package/src/stavetempo.ts DELETED
@@ -1,162 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- // @author: Radosaw Eichler 2012
3
-
4
- import { Element } from './element';
5
- import { Glyphs } from './glyphs';
6
- import { Metrics } from './metrics';
7
- import { Stave } from './stave';
8
- import { StaveModifier, StaveModifierPosition } from './stavemodifier';
9
- import { Category } from './typeguard';
10
-
11
- export interface StaveTempoOptions {
12
- /** free text i.e.: 'Adagio', 'Andate grazioso', ... */
13
- name?: string;
14
- /**
15
- * Indicates whether or not to put the metronome mark in parentheses.
16
- * It is no if not specified.
17
- * */
18
- parenthesis?: boolean;
19
- /**
20
- * Indicates the graphical note type to use in a metronome mark.
21
- * see: `StaveTempo.#durationToCode`.
22
- */
23
- duration?: string;
24
- /**
25
- * Specifies the number of augmentation dots for a metronome mark note.
26
- */
27
- dots?: number;
28
- /**
29
- * Specifies the beats per minute associated with the metronome mark.
30
- * i.e.: 120, "c. 108", "132-144"
31
- */
32
- bpm?: number | string;
33
- /**
34
- * Indicates the graphical note type to use at the right of the equation
35
- * in a metronome mark.
36
- * see: `StaveTempo.#durationToCode`.
37
- */
38
- duration2?: string;
39
- /**
40
- * Specifies the number of augmentation dots for a metronome mark note
41
- * at the right of the equation.
42
- */
43
- dots2?: number;
44
- }
45
-
46
- export class StaveTempo extends StaveModifier {
47
- static get CATEGORY(): string {
48
- return Category.StaveTempo;
49
- }
50
- protected tempo: StaveTempoOptions;
51
-
52
- constructor(tempo: StaveTempoOptions, x: number, shiftY: number) {
53
- super();
54
-
55
- this.tempo = tempo;
56
- this.position = StaveModifierPosition.ABOVE;
57
- this.x = x;
58
- this.setXShift(10);
59
- this.setYShift(shiftY);
60
- }
61
-
62
- #durationToCode: Record<string, string> = {
63
- '1/4': Glyphs.metNoteDoubleWholeSquare,
64
- long: Glyphs.metNoteDoubleWholeSquare,
65
- '1/2': Glyphs.metNoteDoubleWhole,
66
- breve: Glyphs.metNoteDoubleWhole,
67
- 1: Glyphs.metNoteWhole,
68
- whole: Glyphs.metNoteWhole,
69
- w: Glyphs.metNoteWhole,
70
- 2: Glyphs.metNoteHalfUp,
71
- half: Glyphs.metNoteHalfUp,
72
- h: Glyphs.metNoteHalfUp,
73
- 4: Glyphs.metNoteQuarterUp,
74
- quarter: Glyphs.metNoteQuarterUp,
75
- q: Glyphs.metNoteQuarterUp,
76
- 8: Glyphs.metNote8thUp,
77
- eighth: Glyphs.metNote8thUp,
78
- 16: Glyphs.metNote16thUp,
79
- '16th': Glyphs.metNote16thUp,
80
- 32: Glyphs.metNote32ndUp,
81
- '32nd': Glyphs.metNote32ndUp,
82
- 64: Glyphs.metNote64thUp,
83
- '64th': Glyphs.metNote64thUp,
84
- 128: Glyphs.metNote128thUp,
85
- '128th': Glyphs.metNote128thUp,
86
- 256: Glyphs.metNote256thUp,
87
- '256th': Glyphs.metNote256thUp,
88
- 512: Glyphs.metNote512thUp,
89
- '512th': Glyphs.metNote512thUp,
90
- 1024: Glyphs.metNote1024thUp,
91
- '1024th': Glyphs.metNote1024thUp,
92
- };
93
-
94
- setTempo(tempo: StaveTempoOptions): this {
95
- this.tempo = tempo;
96
- return this;
97
- }
98
-
99
- draw(stave: Stave, shiftX: number): this {
100
- const ctx = stave.checkContext();
101
- this.setRendered();
102
-
103
- const { name, duration, dots, bpm, duration2, dots2, parenthesis } = this.tempo;
104
- let x = this.x + shiftX;
105
- const y = stave.getYForTopText(1);
106
- const el = new Element('StaveTempo.glyph');
107
- const elText = new Element('StaveTempo');
108
-
109
- if (name) {
110
- this.text = name;
111
- this.fontInfo = Metrics.getFontInfo('StaveTempo.name');
112
- this.renderText(ctx, shiftX, y);
113
- x += this.getWidth() + 3;
114
- }
115
-
116
- if ((name && duration) || parenthesis) {
117
- elText.setText('(');
118
- elText.renderText(ctx, x + this.xShift, y + this.yShift);
119
- x += elText.getWidth() + 3;
120
- }
121
-
122
- if (duration) {
123
- el.setText(this.#durationToCode[duration]);
124
- el.renderText(ctx, x + this.xShift, y + this.yShift);
125
- x += el.getWidth() + 3;
126
- if (dots) {
127
- // Draw dot
128
- el.setText(Glyphs.metAugmentationDot);
129
- for (let i = 0; i < dots; i++) {
130
- el.renderText(ctx, x + this.xShift, y + 2 + this.yShift);
131
- x += el.getWidth() + 3;
132
- }
133
- }
134
- elText.setText('=');
135
- elText.renderText(ctx, x + this.xShift, y + this.yShift);
136
- x += elText.getWidth() + 3;
137
- if (duration2) {
138
- el.setText(this.#durationToCode[duration2]);
139
- el.renderText(ctx, x + this.xShift, y + this.yShift);
140
- x += el.getWidth() + 3;
141
- if (dots2) {
142
- // Draw dot
143
- el.setText(Glyphs.metAugmentationDot);
144
- for (let i = 0; i < dots2; i++) {
145
- el.renderText(ctx, x + this.xShift, y + 2 + this.yShift);
146
- x += el.getWidth() + 3;
147
- }
148
- }
149
- } else if (bpm) {
150
- elText.setText('' + bpm);
151
- elText.renderText(ctx, x + this.xShift, y + this.yShift);
152
- x += elText.getWidth() + 3;
153
- }
154
- if (name || parenthesis) {
155
- elText.setText(')');
156
- elText.renderText(ctx, x + this.xShift, y + this.yShift);
157
- }
158
- }
159
-
160
- return this;
161
- }
162
- }
package/src/stavetext.ts DELETED
@@ -1,69 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- // @author: Taehoon Moon 2014
3
-
4
- import { Stave } from './stave';
5
- import { StaveModifier, StaveModifierPosition } from './stavemodifier';
6
- import { TextJustification, TextNote } from './textnote';
7
- import { Category } from './typeguard';
8
- import { RuntimeError } from './util';
9
-
10
- export class StaveText extends StaveModifier {
11
- static get CATEGORY(): string {
12
- return Category.StaveText;
13
- }
14
-
15
- protected justification: number;
16
-
17
- constructor(
18
- text: string,
19
- position: number,
20
- options: { shiftX?: number; shiftY?: number; justification?: number } = {}
21
- ) {
22
- super();
23
-
24
- this.setText(text);
25
- this.setXShift(options.shiftX ?? 0);
26
- this.setYShift(options.shiftY ?? 0);
27
- this.position = position;
28
- this.justification = options.justification ?? TextNote.Justification.CENTER;
29
- }
30
-
31
- draw(stave: Stave): this {
32
- const ctx = stave.checkContext();
33
- this.setRendered();
34
-
35
- let x;
36
- let y;
37
- switch (this.position) {
38
- case StaveModifierPosition.LEFT:
39
- case StaveModifierPosition.RIGHT:
40
- y = (stave.getYForLine(0) + stave.getBottomLineY()) / 2;
41
- if (this.position === StaveModifierPosition.LEFT) {
42
- x = stave.getX() - this.width - 24;
43
- } else {
44
- x = stave.getX() + stave.getWidth() + 24;
45
- }
46
- break;
47
- case StaveModifierPosition.ABOVE:
48
- case StaveModifierPosition.BELOW:
49
- x = stave.getX();
50
- if (this.justification === TextJustification.CENTER) {
51
- x += stave.getWidth() / 2 - this.width / 2;
52
- } else if (this.justification === TextJustification.RIGHT) {
53
- x += stave.getWidth() - this.width;
54
- }
55
-
56
- if (this.position === StaveModifierPosition.ABOVE) {
57
- y = stave.getYForTopText(2);
58
- } else {
59
- y = stave.getYForBottomText(2);
60
- }
61
- break;
62
- default:
63
- throw new RuntimeError('InvalidPosition', 'Value Must be in Modifier.Position.');
64
- }
65
-
66
- this.renderText(ctx, x, y + 4);
67
- return this;
68
- }
69
- }
package/src/stavetie.ts DELETED
@@ -1,235 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- //
3
- // This class implements varies types of ties between contiguous notes. The
4
- // ties include: regular ties, hammer ons, pull offs, and slides.
5
-
6
- import { Element } from './element';
7
- import { Note } from './note';
8
- import { Category } from './typeguard';
9
- import { RuntimeError } from './util';
10
-
11
- // For backwards compatibility with 3.0.9, firstNote and/or lastNote can be undefined or null.
12
- // We prefer undefined instead of null.
13
- // However, some of our test cases used to pass in null, so maybe there is client code relying on it.
14
- export interface TieNotes {
15
- firstNote?: Note | null;
16
- lastNote?: Note | null;
17
- firstIndexes?: number[];
18
- lastIndexes?: number[];
19
- }
20
-
21
- export class StaveTie extends Element {
22
- static get CATEGORY(): string {
23
- return Category.StaveTie;
24
- }
25
-
26
- public renderOptions: {
27
- cp2: number;
28
- lastXShift: number;
29
- tieSpacing: number;
30
- cp1: number;
31
- firstXShift: number;
32
- textShiftX: number;
33
- yShift: number;
34
- };
35
-
36
- // notes is initialized by the constructor via this.setNotes(notes).
37
- protected notes!: TieNotes;
38
-
39
- protected direction?: number;
40
-
41
- /**
42
- * @param notes is a struct that has:
43
- *
44
- * {
45
- * firstNote: Note,
46
- * lastNote: Note,
47
- * firstIndexes: [n1, n2, n3],
48
- * lastIndexes: [n1, n2, n3]
49
- * }
50
- *
51
- * @param text
52
- */
53
- constructor(notes: TieNotes, text = '') {
54
- super();
55
- this.setNotes(notes);
56
- this.text = text;
57
- this.renderOptions = {
58
- cp1: 8, // Curve control point 1
59
- cp2: 12, // Curve control point 2
60
- textShiftX: 0,
61
- firstXShift: 0,
62
- lastXShift: 0,
63
- yShift: 7,
64
- tieSpacing: 0,
65
- };
66
- }
67
-
68
- setDirection(direction: number): this {
69
- this.direction = direction;
70
- return this;
71
- }
72
-
73
- /**
74
- * Set the notes to attach this tie to.
75
- *
76
- * @param {!Object} notes The notes to tie up.
77
- */
78
- setNotes(notes: TieNotes): this {
79
- if (!notes.firstNote && !notes.lastNote) {
80
- throw new RuntimeError('BadArguments', 'Tie needs to have either firstNote or lastNote set.');
81
- }
82
-
83
- if (!notes.firstIndexes) {
84
- notes.firstIndexes = [0];
85
- }
86
- if (!notes.lastIndexes) {
87
- notes.lastIndexes = [0];
88
- }
89
-
90
- if (notes.firstIndexes.length !== notes.lastIndexes.length) {
91
- throw new RuntimeError('BadArguments', 'Tied notes must have same number of indexes.');
92
- }
93
-
94
- this.notes = notes;
95
- return this;
96
- }
97
-
98
- /**
99
- * @return {boolean} Returns true if this is a partial bar.
100
- */
101
- isPartial(): boolean {
102
- return !this.notes.firstNote || !this.notes.lastNote;
103
- }
104
-
105
- /**
106
- * @param params.firstX is specified in pixels.
107
- * @param params.lastX is specified in pixels.
108
- */
109
- renderTie(params: { direction: number; firstX: number; lastX: number; lastYs: number[]; firstYs: number[] }): void {
110
- if (params.firstYs.length === 0 || params.lastYs.length === 0) {
111
- throw new RuntimeError('BadArguments', 'No Y-values to render');
112
- }
113
-
114
- const ctx = this.checkContext();
115
- let cp1 = this.renderOptions.cp1;
116
- let cp2 = this.renderOptions.cp2;
117
-
118
- if (Math.abs(params.lastX - params.firstX) < 10) {
119
- cp1 = 2;
120
- cp2 = 8;
121
- }
122
-
123
- const firstXShift = this.renderOptions.firstXShift;
124
- const lastXShift = this.renderOptions.lastXShift;
125
- const yShift = this.renderOptions.yShift * params.direction;
126
-
127
- // setNotes(...) verified that firstIndexes and lastIndexes are not undefined.
128
- // As a result, we use the ! non-null assertion operator here.
129
- // eslint-disable-next-line
130
- const firstIndexes = this.notes.firstIndexes!;
131
- // eslint-disable-next-line
132
- const lastIndexes = this.notes.lastIndexes!;
133
- this.applyStyle();
134
- ctx.openGroup('stavetie', this.getAttribute('id'));
135
- for (let i = 0; i < firstIndexes.length; ++i) {
136
- const cpX = (params.lastX + lastXShift + (params.firstX + firstXShift)) / 2;
137
- // firstY and lastY are specified in pixels.
138
- const firstY = params.firstYs[firstIndexes[i]] + yShift;
139
- const lastY = params.lastYs[lastIndexes[i]] + yShift;
140
-
141
- if (isNaN(firstY) || isNaN(lastY)) {
142
- throw new RuntimeError('BadArguments', 'Bad indexes for tie rendering.');
143
- }
144
-
145
- const topControlPointY = (firstY + lastY) / 2 + cp1 * params.direction;
146
- const bottomControlPointY = (firstY + lastY) / 2 + cp2 * params.direction;
147
-
148
- ctx.beginPath();
149
- ctx.moveTo(params.firstX + firstXShift, firstY);
150
- ctx.quadraticCurveTo(cpX, topControlPointY, params.lastX + lastXShift, lastY);
151
- ctx.quadraticCurveTo(cpX, bottomControlPointY, params.firstX + firstXShift, firstY);
152
- ctx.closePath();
153
- ctx.fill();
154
- }
155
- ctx.closeGroup();
156
- this.restoreStyle();
157
- }
158
-
159
- /**
160
- * @param firstX specified in pixels
161
- * @param lastX specified in pixels
162
- */
163
- renderTieText(firstX: number, lastX: number): void {
164
- const ctx = this.checkContext();
165
- let centerX = (firstX + lastX) / 2;
166
- centerX -= ctx.measureText(this.text).width / 2;
167
- const stave = this.notes.firstNote?.checkStave() ?? this.notes.lastNote?.checkStave();
168
- if (stave) {
169
- ctx.save();
170
- ctx.setFont(this.fontInfo);
171
- ctx.fillText(this.text, centerX + this.renderOptions.textShiftX, stave.getYForTopText() - 1);
172
- ctx.restore();
173
- }
174
- }
175
-
176
- /**
177
- * Returns the TieNotes structure of the first and last note this tie connects.
178
- */
179
- getNotes(): TieNotes {
180
- return this.notes;
181
- }
182
-
183
- draw(): boolean {
184
- this.checkContext();
185
- this.setRendered();
186
-
187
- const firstNote = this.notes.firstNote;
188
- const lastNote = this.notes.lastNote;
189
-
190
- // Provide some default values so the compiler doesn't complain.
191
- // firstX and lastX are in pixels.
192
- let firstX = 0;
193
- let lastX = 0;
194
- let firstYs: number[] = [0];
195
- let lastYs: number[] = [0];
196
- let stemDirection = 0;
197
-
198
- if (firstNote) {
199
- firstX = firstNote.getTieRightX() + this.renderOptions.tieSpacing;
200
- stemDirection = firstNote.getStemDirection();
201
- firstYs = firstNote.getYs();
202
- } else if (lastNote) {
203
- const stave = lastNote.checkStave();
204
- firstX = stave.getTieStartX();
205
- firstYs = lastNote.getYs();
206
- this.notes.firstIndexes = this.notes.lastIndexes;
207
- }
208
-
209
- if (lastNote) {
210
- lastX = lastNote.getTieLeftX() + this.renderOptions.tieSpacing;
211
- stemDirection = lastNote.getStemDirection();
212
- lastYs = lastNote.getYs();
213
- } else if (firstNote) {
214
- const stave = firstNote.checkStave();
215
- lastX = stave.getTieEndX();
216
- lastYs = firstNote.getYs();
217
- this.notes.lastIndexes = this.notes.firstIndexes;
218
- }
219
-
220
- if (this.direction) {
221
- stemDirection = this.direction;
222
- }
223
-
224
- this.renderTie({
225
- firstX,
226
- lastX,
227
- firstYs,
228
- lastYs,
229
- direction: stemDirection,
230
- });
231
-
232
- this.renderTieText(firstX, lastX);
233
- return true;
234
- }
235
- }