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,231 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- //
3
- // @author: Larry Kuhns 2011
4
-
5
- import { Stave } from './stave';
6
- import { LayoutMetrics, StaveModifier, StaveModifierPosition } from './stavemodifier';
7
- import { Tables } from './tables';
8
- import { Category } from './typeguard';
9
-
10
- export enum BarlineType {
11
- SINGLE = 1,
12
- DOUBLE = 2,
13
- END = 3,
14
- REPEAT_BEGIN = 4,
15
- REPEAT_END = 5,
16
- REPEAT_BOTH = 6,
17
- NONE = 7,
18
- }
19
-
20
- export class Barline extends StaveModifier {
21
- static get CATEGORY(): string {
22
- return Category.Barline;
23
- }
24
-
25
- protected widths: Record<string, number>;
26
- protected paddings: Record<string, number>;
27
- protected layoutMetricsMap: Record<number, LayoutMetrics>;
28
-
29
- protected thickness: number;
30
- protected type!: BarlineType;
31
-
32
- static get type(): typeof BarlineType {
33
- return BarlineType;
34
- }
35
-
36
- static get typeString(): Record<string, BarlineType> {
37
- return {
38
- single: BarlineType.SINGLE,
39
- double: BarlineType.DOUBLE,
40
- end: BarlineType.END,
41
- repeatBegin: BarlineType.REPEAT_BEGIN,
42
- repeatEnd: BarlineType.REPEAT_END,
43
- repeatBoth: BarlineType.REPEAT_BOTH,
44
- none: BarlineType.NONE,
45
- };
46
- }
47
-
48
- constructor(type: BarlineType | string) {
49
- super();
50
- this.thickness = Tables.STAVE_LINE_THICKNESS;
51
-
52
- const TYPE = BarlineType;
53
- this.widths = {};
54
- this.widths[TYPE.SINGLE] = 5;
55
- this.widths[TYPE.DOUBLE] = 5;
56
- this.widths[TYPE.END] = 5;
57
- this.widths[TYPE.REPEAT_BEGIN] = 5;
58
- this.widths[TYPE.REPEAT_END] = 5;
59
- this.widths[TYPE.REPEAT_BOTH] = 5;
60
- this.widths[TYPE.NONE] = 5;
61
-
62
- this.paddings = {};
63
- this.paddings[TYPE.SINGLE] = 0;
64
- this.paddings[TYPE.DOUBLE] = 0;
65
- this.paddings[TYPE.END] = 0;
66
- this.paddings[TYPE.REPEAT_BEGIN] = 15;
67
- this.paddings[TYPE.REPEAT_END] = 15;
68
- this.paddings[TYPE.REPEAT_BOTH] = 15;
69
- this.paddings[TYPE.NONE] = 0;
70
-
71
- this.layoutMetricsMap = {};
72
- this.layoutMetricsMap[TYPE.SINGLE] = {
73
- xMin: 0,
74
- xMax: 1,
75
- paddingLeft: 5,
76
- paddingRight: 5,
77
- };
78
- this.layoutMetricsMap[TYPE.DOUBLE] = {
79
- xMin: -3,
80
- xMax: 1,
81
- paddingLeft: 5,
82
- paddingRight: 5,
83
- };
84
- this.layoutMetricsMap[TYPE.END] = {
85
- xMin: -5,
86
- xMax: 1,
87
- paddingLeft: 5,
88
- paddingRight: 5,
89
- };
90
- this.layoutMetricsMap[TYPE.REPEAT_END] = {
91
- xMin: -10,
92
- xMax: 1,
93
- paddingLeft: 5,
94
- paddingRight: 5,
95
- };
96
- this.layoutMetricsMap[TYPE.REPEAT_BEGIN] = {
97
- xMin: -2,
98
- xMax: 10,
99
- paddingLeft: 5,
100
- paddingRight: 5,
101
- };
102
- this.layoutMetricsMap[TYPE.REPEAT_BOTH] = {
103
- xMin: -10,
104
- xMax: 10,
105
- paddingLeft: 5,
106
- paddingRight: 5,
107
- };
108
- this.layoutMetricsMap[TYPE.NONE] = {
109
- xMin: 0,
110
- xMax: 0,
111
- paddingLeft: 5,
112
- paddingRight: 5,
113
- };
114
- this.setPosition(StaveModifierPosition.BEGIN);
115
- this.setType(type);
116
- }
117
-
118
- getType(): number {
119
- return this.type;
120
- }
121
-
122
- setType(type: string | number): this {
123
- this.type = typeof type === 'string' ? Barline.typeString[type] : type;
124
-
125
- this.setWidth(this.widths[this.type]);
126
- this.setPadding(this.paddings[this.type]);
127
- this.setLayoutMetrics(this.layoutMetricsMap[this.type]);
128
- return this;
129
- }
130
-
131
- // Draw barlines
132
- draw(stave: Stave): void {
133
- const ctx = stave.checkContext();
134
- this.setRendered();
135
-
136
- this.applyStyle(ctx);
137
- ctx.openGroup('stavebarline', this.getAttribute('id'));
138
- switch (this.type) {
139
- case BarlineType.SINGLE:
140
- this.drawVerticalBar(stave, this.x, false);
141
- break;
142
- case BarlineType.DOUBLE:
143
- this.drawVerticalBar(stave, this.x, true);
144
- break;
145
- case BarlineType.END:
146
- this.drawVerticalEndBar(stave, this.x);
147
- break;
148
- case BarlineType.REPEAT_BEGIN:
149
- // If the barline is shifted over (in front of clef/time/key)
150
- // Draw vertical bar at the beginning.
151
- this.drawRepeatBar(stave, this.x, true);
152
- if (stave.getX() !== this.x) {
153
- this.drawVerticalBar(stave, stave.getX());
154
- }
155
-
156
- break;
157
- case BarlineType.REPEAT_END:
158
- this.drawRepeatBar(stave, this.x, false);
159
- break;
160
- case BarlineType.REPEAT_BOTH:
161
- this.drawRepeatBar(stave, this.x, false);
162
- this.drawRepeatBar(stave, this.x, true);
163
- break;
164
- default:
165
- // Default is NONE, so nothing to draw
166
- break;
167
- }
168
- ctx.closeGroup();
169
- this.restoreStyle(ctx);
170
- }
171
-
172
- drawVerticalBar(stave: Stave, x: number, doubleBar?: boolean): void {
173
- const staveCtx = stave.checkContext();
174
- const topY = stave.getTopLineTopY();
175
- const botY = stave.getBottomLineBottomY();
176
- if (doubleBar) {
177
- staveCtx.fillRect(x - 3, topY, 1, botY - topY);
178
- }
179
- staveCtx.fillRect(x, topY, 1, botY - topY);
180
- }
181
-
182
- drawVerticalEndBar(stave: Stave, x: number): void {
183
- const staveCtx = stave.checkContext();
184
- const topY = stave.getTopLineTopY();
185
- const botY = stave.getBottomLineBottomY();
186
- staveCtx.fillRect(x - 5, topY, 1, botY - topY);
187
- staveCtx.fillRect(x - 2, topY, 3, botY - topY);
188
- }
189
-
190
- drawRepeatBar(stave: Stave, x: number, begin: boolean): void {
191
- const staveCtx = stave.checkContext();
192
-
193
- const topY = stave.getTopLineTopY();
194
- const botY = stave.getBottomLineBottomY();
195
- let xShift = 3;
196
-
197
- if (!begin) {
198
- xShift = -5;
199
- }
200
-
201
- staveCtx.fillRect(x + xShift, topY, 1, botY - topY);
202
- staveCtx.fillRect(x - 2, topY, 3, botY - topY);
203
-
204
- const dotRadius = 2;
205
-
206
- // Shift dots left or right
207
- if (begin) {
208
- xShift += 4;
209
- } else {
210
- xShift -= 4;
211
- }
212
-
213
- const dotX = x + xShift + dotRadius / 2;
214
-
215
- // calculate the y offset based on number of stave lines
216
- let yOffset = (stave.getNumLines() - 1) * stave.getSpacingBetweenLines();
217
- yOffset = yOffset / 2 - stave.getSpacingBetweenLines() / 2;
218
- let dotY = topY + yOffset + dotRadius / 2;
219
-
220
- // draw the top repeat dot
221
- staveCtx.beginPath();
222
- staveCtx.arc(dotX, dotY, dotRadius, 0, Math.PI * 2, false);
223
- staveCtx.fill();
224
-
225
- // draw the bottom repeat dot
226
- dotY += stave.getSpacingBetweenLines();
227
- staveCtx.beginPath();
228
- staveCtx.arc(dotX, dotY, dotRadius, 0, Math.PI * 2, false);
229
- staveCtx.fill();
230
- }
231
- }
@@ -1,281 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- // MIT License
3
-
4
- import { Element } from './element';
5
- import { Glyphs } from './glyphs';
6
- import { RenderContext } from './rendercontext';
7
- import { Stave } from './stave';
8
- import { Tables } from './tables';
9
- import { Category } from './typeguard';
10
- import { RuntimeError } from './util';
11
-
12
- function drawBoldDoubleLine(ctx: RenderContext, type: number, topX: number, topY: number, botY: number) {
13
- if (type !== StaveConnector.type.BOLD_DOUBLE_LEFT && type !== StaveConnector.type.BOLD_DOUBLE_RIGHT) {
14
- throw new RuntimeError('InvalidConnector', 'A REPEAT_BEGIN or REPEAT_END type must be provided.');
15
- }
16
-
17
- let xShift = 3;
18
- let variableWidth = 3.5; // Width for avoiding anti-aliasing width issues
19
- const thickLineOffset = 2; // For aesthetics
20
-
21
- if (type === StaveConnector.type.BOLD_DOUBLE_RIGHT) {
22
- xShift = -5; // Flips the side of the thin line
23
- variableWidth = 3;
24
- }
25
-
26
- // Thin line
27
- ctx.fillRect(topX + xShift, topY, 1, botY - topY);
28
- // Thick line
29
- ctx.fillRect(topX - thickLineOffset, topY, variableWidth, botY - topY);
30
- }
31
-
32
- /**
33
- * see {@link StaveConnector.type} & {@link StaveConnector.typeString}
34
- */
35
- export type StaveConnectorType =
36
- | 'singleRight'
37
- | 'singleLeft'
38
- | 'single'
39
- | 'double'
40
- | 'brace'
41
- | 'bracket'
42
- | 'boldDoubleLeft'
43
- | 'boldDoubleRight'
44
- | 'thinDouble'
45
- | 'none'
46
- | 0
47
- | 1
48
- | 2
49
- | 3
50
- | 4
51
- | 5
52
- | 6
53
- | 7
54
- | 8;
55
-
56
- /** StaveConnector implements the connector lines between staves of a system. */
57
- export class StaveConnector extends Element {
58
- static get CATEGORY(): string {
59
- return Category.StaveConnector;
60
- }
61
-
62
- /**
63
- * SINGLE_LEFT and SINGLE are the same value for compatibility
64
- * with older versions of vexflow which didn't have right sided
65
- * stave connectors.
66
- */
67
- static readonly type: Record<string, Exclude<StaveConnectorType, string>> = {
68
- SINGLE_RIGHT: 0,
69
- SINGLE_LEFT: 1,
70
- SINGLE: 1,
71
- DOUBLE: 2,
72
- BRACE: 3,
73
- BRACKET: 4,
74
- BOLD_DOUBLE_LEFT: 5,
75
- BOLD_DOUBLE_RIGHT: 6,
76
- THIN_DOUBLE: 7,
77
- NONE: 8,
78
- } as const;
79
-
80
- /**
81
- * Connector type:
82
- * * "singleRight"
83
- * * "singleLeft"
84
- * * "single"
85
- * * "double"
86
- * * "brace"
87
- * * "bracket"
88
- * * "boldDoubleLeft"
89
- * * "boldDoubleRight"
90
- * * "thinDouble"
91
- * * "none"
92
- */
93
- static readonly typeString: Record<Exclude<StaveConnectorType, number>, Exclude<StaveConnectorType, string>> = {
94
- singleRight: StaveConnector.type.SINGLE_RIGHT,
95
- singleLeft: StaveConnector.type.SINGLE_LEFT,
96
- single: StaveConnector.type.SINGLE,
97
- double: StaveConnector.type.DOUBLE,
98
- brace: StaveConnector.type.BRACE,
99
- bracket: StaveConnector.type.BRACKET,
100
- boldDoubleLeft: StaveConnector.type.BOLD_DOUBLE_LEFT,
101
- boldDoubleRight: StaveConnector.type.BOLD_DOUBLE_RIGHT,
102
- thinDouble: StaveConnector.type.THIN_DOUBLE,
103
- none: StaveConnector.type.NONE,
104
- } as const;
105
-
106
- protected texts: Element[];
107
-
108
- protected type: (typeof StaveConnector)['type'][keyof (typeof StaveConnector)['type']];
109
-
110
- readonly topStave: Stave;
111
- readonly bottomStave: Stave;
112
- readonly thickness: number;
113
-
114
- constructor(topStave: Stave, bottomStave: Stave) {
115
- super();
116
-
117
- this.thickness = Tables.STAVE_LINE_THICKNESS;
118
- this.topStave = topStave;
119
- this.bottomStave = bottomStave;
120
- this.type = StaveConnector.type.DOUBLE;
121
-
122
- // 1. Offset Bold Double Left to align with offset Repeat Begin bars
123
- // 2. Offset BRACE type not to overlap with another StaveConnector
124
- this.xShift = 0;
125
- this.texts = [];
126
- }
127
-
128
- /**
129
- * Set type.
130
- * @param type see {@link StaveConnector.type} & {@link StaveConnector.typeString}
131
- */
132
- setType(type: StaveConnectorType): this {
133
- const newType = typeof type === 'string' ? StaveConnector.typeString[type] : type;
134
-
135
- // Be certain that the type is a valid type:
136
- if (Object.values(StaveConnector.type).includes(newType)) {
137
- this.type = newType;
138
- }
139
-
140
- return this;
141
- }
142
-
143
- /**
144
- * Get type.
145
- * @returns number {@link StaveConnector.type}
146
- */
147
- getType(): number {
148
- return this.type;
149
- }
150
-
151
- /** Set optional associated Text. */
152
- setText(text: string, options: { shiftX?: number; shiftY?: number } = {}): this {
153
- const textElement = new Element('StaveConnector.text');
154
- textElement.setText(text);
155
- textElement.setXShift(options.shiftX ?? 0);
156
- textElement.setYShift(options.shiftY ?? 0);
157
- this.texts.push(textElement);
158
- return this;
159
- }
160
-
161
- /** Render connector and associated text. */
162
- draw(): void {
163
- const ctx = this.checkContext();
164
- this.setRendered();
165
-
166
- let topY = this.topStave.getYForLine(0);
167
- let botY = this.bottomStave.getYForLine(this.bottomStave.getNumLines() - 1) + this.thickness;
168
- let width = 3;
169
- let topX = this.topStave.getX();
170
-
171
- const isRightSidedConnector =
172
- this.type === StaveConnector.type.SINGLE_RIGHT ||
173
- this.type === StaveConnector.type.BOLD_DOUBLE_RIGHT ||
174
- this.type === StaveConnector.type.THIN_DOUBLE;
175
-
176
- if (isRightSidedConnector) {
177
- topX = this.topStave.getX() + this.topStave.getWidth();
178
- }
179
-
180
- let attachmentHeight = botY - topY;
181
- const element = new Element();
182
- switch (this.type) {
183
- case StaveConnector.type.SINGLE:
184
- width = 1;
185
- break;
186
- case StaveConnector.type.SINGLE_LEFT:
187
- width = 1;
188
- break;
189
- case StaveConnector.type.SINGLE_RIGHT:
190
- width = 1;
191
- break;
192
- case StaveConnector.type.DOUBLE:
193
- topX -= 5;
194
- topY -= this.thickness;
195
- attachmentHeight += 0.5;
196
- break;
197
- case StaveConnector.type.BRACE: {
198
- width = 12;
199
- // May need additional code to draw brace
200
- const x1 = this.topStave.getX() - 2 + this.xShift;
201
- const y1 = topY;
202
- const x3 = x1;
203
- const y3 = botY;
204
- const x2 = x1 - width;
205
- const y2 = y1 + attachmentHeight / 2.0;
206
- const cpx1 = x2 - 0.9 * width;
207
- const cpy1 = y1 + 0.2 * attachmentHeight;
208
- const cpx2 = x1 + 1.1 * width;
209
- const cpy2 = y2 - 0.135 * attachmentHeight;
210
- const cpx3 = cpx2;
211
- const cpy3 = y2 + 0.135 * attachmentHeight;
212
- const cpx4 = cpx1;
213
- const cpy4 = y3 - 0.2 * attachmentHeight;
214
- const cpx5 = x2 - width;
215
- const cpy5 = cpy4;
216
- const cpx6 = x1 + 0.4 * width;
217
- const cpy6 = y2 + 0.135 * attachmentHeight;
218
- const cpx7 = cpx6;
219
- const cpy7 = y2 - 0.135 * attachmentHeight;
220
- const cpx8 = cpx5;
221
- const cpy8 = cpy1;
222
- ctx.beginPath();
223
- ctx.moveTo(x1, y1);
224
- ctx.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, x2, y2);
225
- ctx.bezierCurveTo(cpx3, cpy3, cpx4, cpy4, x3, y3);
226
- ctx.bezierCurveTo(cpx5, cpy5, cpx6, cpy6, x2, y2);
227
- ctx.bezierCurveTo(cpx7, cpy7, cpx8, cpy8, x1, y1);
228
- ctx.fill();
229
- ctx.stroke();
230
- break;
231
- }
232
- case StaveConnector.type.BRACKET:
233
- topY -= 6;
234
- botY += 6;
235
- attachmentHeight = botY - topY;
236
- element.setText(Glyphs.bracketTop);
237
- element.renderText(ctx, topX - 5, topY);
238
- element.setText(Glyphs.bracketBottom);
239
- element.renderText(ctx, topX - 5, botY);
240
- topX -= 5;
241
- break;
242
- case StaveConnector.type.BOLD_DOUBLE_LEFT:
243
- drawBoldDoubleLine(ctx, this.type, topX + this.xShift, topY, botY - this.thickness);
244
- break;
245
- case StaveConnector.type.BOLD_DOUBLE_RIGHT:
246
- drawBoldDoubleLine(ctx, this.type, topX, topY, botY - this.thickness);
247
- break;
248
- case StaveConnector.type.THIN_DOUBLE:
249
- width = 1;
250
- attachmentHeight -= this.thickness;
251
- break;
252
- case StaveConnector.type.NONE:
253
- break;
254
- default:
255
- throw new RuntimeError('InvalidType', `The provided StaveConnector.type (${this.type}) is invalid.`);
256
- }
257
-
258
- if (
259
- this.type !== StaveConnector.type.BRACE &&
260
- this.type !== StaveConnector.type.BOLD_DOUBLE_LEFT &&
261
- this.type !== StaveConnector.type.BOLD_DOUBLE_RIGHT &&
262
- this.type !== StaveConnector.type.NONE
263
- ) {
264
- ctx.fillRect(topX, topY, width, attachmentHeight);
265
- }
266
-
267
- // If the connector is a thin double barline, draw the paralell line
268
- if (this.type === StaveConnector.type.THIN_DOUBLE) {
269
- ctx.fillRect(topX - 3, topY, width, attachmentHeight);
270
- }
271
-
272
- // Add stave connector text
273
- for (let i = 0; i < this.texts.length; i++) {
274
- const textElement = this.texts[i];
275
- const x = this.topStave.getX() - textElement.getWidth() - 24;
276
- const y = (this.topStave.getYForLine(0) + this.bottomStave.getBottomLineY()) / 2;
277
-
278
- textElement.renderText(ctx, x, y + 4);
279
- }
280
- }
281
- }
@@ -1,209 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- //
3
- // ## Description
4
- // @author Raffaele Viglianti, 2012 http://itisnotsound.wordpress.com/
5
- //
6
- // This class implements hairpins between notes.
7
- // Hairpins can be either crescendo or decrescendo.
8
-
9
- import { Element } from './element';
10
- import { Modifier } from './modifier';
11
- import { Note } from './note';
12
- import { RenderContext } from './rendercontext';
13
- import { Category } from './typeguard';
14
- import { RuntimeError } from './util';
15
-
16
- export interface StaveHairpinRenderOptions {
17
- rightShiftTicks?: number;
18
- leftShiftTicks?: number;
19
- leftShiftPx: number;
20
- rightShiftPx: number;
21
- height: number;
22
- yShift: number;
23
- }
24
-
25
- export class StaveHairpin extends Element {
26
- static get CATEGORY(): string {
27
- return Category.StaveHairpin;
28
- }
29
-
30
- protected hairpin: number;
31
-
32
- protected position: number;
33
- public renderOptions: StaveHairpinRenderOptions;
34
-
35
- // notes is initialized by the constructor via this.setNotes(notes).
36
- protected notes!: Record<string, Note>;
37
-
38
- protected firstNote?: Note;
39
- protected lastNote?: Note;
40
-
41
- static readonly type = {
42
- CRESC: 1,
43
- DECRESC: 2,
44
- };
45
-
46
- /* Helper function to convert ticks into pixels.
47
- * Requires a Formatter with voices joined and formatted (to
48
- * get pixels per tick)
49
- *
50
- * options is struct that has:
51
- *
52
- * {
53
- * height: px,
54
- * yShift: px, // vertical offset
55
- * leftShiftTicks: 0, // left horizontal offset expressed in ticks
56
- * rightShiftTicks: 0 // right horizontal offset expressed in ticks
57
- * }
58
- *
59
- **/
60
- static FormatByTicksAndDraw(
61
- ctx: RenderContext,
62
- formatter: { pixelsPerTick: number },
63
- notes: Record<string, Note>,
64
- type: number,
65
- position: number,
66
- options: StaveHairpinRenderOptions
67
- ): void {
68
- const ppt = formatter.pixelsPerTick;
69
-
70
- if (ppt === null) {
71
- throw new RuntimeError('BadArguments', 'A valid Formatter must be provide to draw offsets by ticks.');
72
- }
73
-
74
- const leftShiftPx = ppt * (options.leftShiftTicks ?? 0);
75
- const rightShiftPx = ppt * (options.rightShiftTicks ?? 0);
76
-
77
- const hairpinOptions = {
78
- height: options.height,
79
- yShift: options.yShift,
80
- leftShiftPx,
81
- rightShiftPx,
82
- rightShiftTicks: 0,
83
- leftShiftTicks: 0,
84
- };
85
-
86
- new StaveHairpin(
87
- {
88
- firstNote: notes.firstNote,
89
- lastNote: notes.lastNote,
90
- },
91
- type
92
- )
93
- .setContext(ctx)
94
- .setRenderOptions(hairpinOptions)
95
- .setPosition(position)
96
- .draw();
97
- }
98
-
99
- /**
100
- * Create a new hairpin from the specified notes.
101
- *
102
- * @param {!Object} notes The notes to tie up.
103
- * Notes is a struct that has:
104
- *
105
- * {
106
- * firstNote: Note,
107
- * lastNote: Note,
108
- * }
109
- * @param {!Object} type The type of hairpin
110
- */
111
- constructor(notes: Record<string, Note>, type: number) {
112
- super();
113
- this.setNotes(notes);
114
- this.hairpin = type;
115
- this.position = Modifier.Position.BELOW;
116
-
117
- this.renderOptions = {
118
- height: 10,
119
- yShift: 0, // vertical offset
120
- leftShiftPx: 0, // left horizontal offset
121
- rightShiftPx: 0, // right horizontal offset
122
- rightShiftTicks: 0,
123
- leftShiftTicks: 0,
124
- };
125
- }
126
-
127
- setPosition(position: number): this {
128
- if (position === Modifier.Position.ABOVE || position === Modifier.Position.BELOW) {
129
- this.position = position;
130
- }
131
- return this;
132
- }
133
-
134
- setRenderOptions(options: StaveHairpinRenderOptions): this {
135
- this.renderOptions = options;
136
- return this;
137
- }
138
-
139
- /**
140
- * Set the notes to attach this hairpin to.
141
- *
142
- * @param {!Object} notes The start and end notes.
143
- */
144
- setNotes(notes: Record<string, Note>): this {
145
- if (!notes.firstNote && !notes.lastNote) {
146
- throw new RuntimeError('BadArguments', 'Hairpin needs to have either firstNote or lastNote set.');
147
- }
148
-
149
- this.notes = notes;
150
- this.firstNote = notes.firstNote;
151
- this.lastNote = notes.lastNote;
152
- return this;
153
- }
154
-
155
- renderHairpin(params: { firstX: number; lastX: number; firstY: number; lastY: number; staffHeight: number }): void {
156
- const ctx = this.checkContext();
157
- let dis = this.renderOptions.yShift + 20;
158
- let yShift = params.firstY;
159
-
160
- if (this.position === Modifier.Position.ABOVE) {
161
- dis = -dis + 30;
162
- yShift = params.firstY - params.staffHeight;
163
- }
164
-
165
- const leftShiftPx = this.renderOptions.leftShiftPx;
166
- const rightShiftPx = this.renderOptions.rightShiftPx;
167
-
168
- ctx.beginPath();
169
-
170
- switch (this.hairpin) {
171
- case StaveHairpin.type.CRESC:
172
- ctx.moveTo(params.lastX + rightShiftPx, yShift + dis);
173
- ctx.lineTo(params.firstX + leftShiftPx, yShift + this.renderOptions.height / 2 + dis);
174
- ctx.lineTo(params.lastX + rightShiftPx, yShift + this.renderOptions.height + dis);
175
- break;
176
- case StaveHairpin.type.DECRESC:
177
- ctx.moveTo(params.firstX + leftShiftPx, yShift + dis);
178
- ctx.lineTo(params.lastX + rightShiftPx, yShift + this.renderOptions.height / 2 + dis);
179
- ctx.lineTo(params.firstX + leftShiftPx, yShift + this.renderOptions.height + dis);
180
- break;
181
- default:
182
- // Default is NONE, so nothing to draw
183
- break;
184
- }
185
-
186
- ctx.stroke();
187
- ctx.closePath();
188
- }
189
-
190
- draw(): void {
191
- this.checkContext();
192
- this.setRendered();
193
-
194
- const firstNote = this.firstNote;
195
- const lastNote = this.lastNote;
196
- if (!firstNote || !lastNote) throw new RuntimeError('NoNote', 'Notes required to draw');
197
-
198
- const start = firstNote.getModifierStartXY(this.position, 0);
199
- const end = lastNote.getModifierStartXY(this.position, 0);
200
-
201
- this.renderHairpin({
202
- firstX: start.x,
203
- lastX: end.x,
204
- firstY: firstNote.checkStave().getY() + firstNote.checkStave().getHeight(),
205
- lastY: lastNote.checkStave().getY() + lastNote.checkStave().getHeight(),
206
- staffHeight: firstNote.checkStave().getHeight(),
207
- });
208
- }
209
- }