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