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,473 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- //
3
- // @author Aaron (@AaronDavidNewman)
4
- //
5
- // This implements chord symbols above/below a chord.
6
- // Chord symbols are modifiers that can be attached to notes.
7
- // They can contain multiple 'blocks' which represent text or
8
- // glyphs with various positioning options.
9
- //
10
- // See `tests/chordsymbol_tests.ts` for usage examples.
11
-
12
- import { BoundingBox } from './boundingbox';
13
- import { Element } from './element';
14
- import { Font } from './font';
15
- import { Glyphs } from './glyphs';
16
- import { Metrics } from './metrics';
17
- import { Modifier } from './modifier';
18
- import { ModifierContextState } from './modifiercontext';
19
- import { Note } from './note';
20
- import { StemmableNote } from './stemmablenote';
21
- import { Tables } from './tables';
22
- import { Category, isStemmableNote } from './typeguard';
23
- import { log } from './util';
24
-
25
- // To enable logging for this class. Set `VexFlow.ChordSymbol.DEBUG` to `true`.
26
- // eslint-disable-next-line
27
- function L(...args: any[]): void {
28
- if (ChordSymbol.DEBUG) log('VexFlow.ChordSymbol', args);
29
- }
30
-
31
- export class ChordSymbolBlock extends Element {
32
- symbolModifier: SymbolModifiers;
33
- vAlign: boolean;
34
-
35
- constructor(text: string, symbolModifier: SymbolModifiers, xShift: number, yShift: number, vAlign: boolean) {
36
- super();
37
- this.text = text;
38
- this.symbolModifier = symbolModifier;
39
- this.xShift = xShift;
40
- this.yShift = yShift;
41
- this.vAlign = vAlign;
42
- }
43
-
44
- isSuperscript(): boolean {
45
- return this.symbolModifier === SymbolModifiers.SUPERSCRIPT;
46
- }
47
-
48
- isSubscript(): boolean {
49
- return this.symbolModifier === SymbolModifiers.SUBSCRIPT;
50
- }
51
- }
52
-
53
- export enum ChordSymbolHorizontalJustify {
54
- LEFT = 1,
55
- CENTER = 2,
56
- RIGHT = 3,
57
- CENTER_STEM = 4,
58
- }
59
-
60
- export enum ChordSymbolVerticalJustify {
61
- TOP = 1,
62
- BOTTOM = 2,
63
- }
64
-
65
- export enum SymbolModifiers {
66
- NONE = 1,
67
- SUBSCRIPT = 2,
68
- SUPERSCRIPT = 3,
69
- }
70
-
71
- /**
72
- * ChordSymbol is a modifier that creates a chord symbol above/below a chord.
73
- * As a modifier, it is attached to an existing note.
74
- */
75
- export class ChordSymbol extends Modifier {
76
- static DEBUG: boolean = false;
77
-
78
- static get CATEGORY(): string {
79
- return Category.ChordSymbol;
80
- }
81
-
82
- // Chord symbols can be positioned and justified relative to the note.
83
- static readonly HorizontalJustify = ChordSymbolHorizontalJustify;
84
-
85
- static readonly HorizontalJustifyString: Record<string, ChordSymbolHorizontalJustify> = {
86
- left: ChordSymbolHorizontalJustify.LEFT,
87
- right: ChordSymbolHorizontalJustify.RIGHT,
88
- center: ChordSymbolHorizontalJustify.CENTER,
89
- centerStem: ChordSymbolHorizontalJustify.CENTER_STEM,
90
- };
91
-
92
- static readonly VerticalJustify = ChordSymbolVerticalJustify;
93
-
94
- static readonly VerticalJustifyString: Record<string, ChordSymbolVerticalJustify> = {
95
- top: ChordSymbolVerticalJustify.TOP,
96
- above: ChordSymbolVerticalJustify.TOP,
97
- below: ChordSymbolVerticalJustify.BOTTOM,
98
- bottom: ChordSymbolVerticalJustify.BOTTOM,
99
- };
100
-
101
- static get superSubRatio(): number {
102
- return Metrics.get('ChordSymbol.superSubRatio');
103
- }
104
-
105
- static get spacingBetweenBlocks(): number {
106
- return Metrics.get('ChordSymbol.spacing');
107
- }
108
-
109
- static get superscriptOffset(): number {
110
- return Metrics.get('ChordSymbol.superscriptOffset');
111
- }
112
-
113
- static get subscriptOffset(): number {
114
- return Metrics.get('ChordSymbol.subscriptOffset');
115
- }
116
-
117
- // Glyph data
118
- static readonly glyphs: Record<string, string> = {
119
- diminished: Glyphs.csymDiminished,
120
- dim: Glyphs.csymDiminished,
121
- halfDiminished: Glyphs.csymHalfDiminished,
122
- '+': Glyphs.csymAugmented,
123
- augmented: Glyphs.csymAugmented,
124
- majorSeventh: Glyphs.csymMajorSeventh,
125
- minor: Glyphs.csymMinor,
126
- '-': Glyphs.csymMinor,
127
- '(': '(', // Glyphs.csymParensLeftTall,
128
- leftParen: '(', // Glyphs.csymParensLeftTall,
129
- ')': ')', // Glyphs.csymParensRightTall,
130
- rightParen: ')', // Glyphs.csymParensRightTall,
131
- leftBracket: Glyphs.csymBracketLeftTall,
132
- rightBracket: Glyphs.csymBracketRightTall,
133
- leftParenTall: '(', // Glyphs.csymParensLeftVeryTall,
134
- rightParenTall: ')', // Glyphs.csymParensRightVeryTall,
135
- '/': Glyphs.csymDiagonalArrangementSlash,
136
- over: Glyphs.csymDiagonalArrangementSlash,
137
- '#': Glyphs.csymAccidentalSharp,
138
- b: Glyphs.csymAccidentalFlat,
139
- };
140
-
141
- static readonly symbolModifiers = SymbolModifiers;
142
-
143
- static get minPadding(): number {
144
- return Metrics.get('NoteHead.minPadding');
145
- }
146
-
147
- /**
148
- * Estimate the width of the whole chord symbol, based on the sum of the widths of the individual blocks.
149
- * Estimate how many lines above/below the staff we need.
150
- */
151
- static format(symbols: ChordSymbol[], state: ModifierContextState): boolean {
152
- if (!symbols || symbols.length === 0) return false;
153
-
154
- let width = 0;
155
- let leftWidth = 0;
156
- let rightWidth = 0;
157
- let maxLeftGlyphWidth = 0;
158
- let maxRightGlyphWidth = 0;
159
-
160
- for (const symbol of symbols) {
161
- const note: Note = symbol.checkAttachedNote();
162
- let lineSpaces = 1;
163
-
164
- for (let j = 0; j < symbol.symbolBlocks.length; ++j) {
165
- const block = symbol.symbolBlocks[j];
166
- const sup = block.isSuperscript();
167
- const sub = block.isSubscript();
168
- block.setXShift(width);
169
-
170
- // If there are super/subscripts, they extend beyond the line so
171
- // assume they take up 2 lines
172
- if (sup || sub) {
173
- lineSpaces = 2;
174
- }
175
-
176
- // If a subscript immediately follows a superscript block, try to
177
- // overlay them.
178
- if (sub && j > 0) {
179
- const prev = symbol.symbolBlocks[j - 1];
180
- if (prev.isSuperscript()) {
181
- // slide the symbol over so it lines up with superscript
182
- block.setXShift(width - prev.getWidth() - ChordSymbol.minPadding);
183
- block.vAlign = true;
184
- width +=
185
- -prev.getWidth() -
186
- ChordSymbol.minPadding +
187
- (prev.getWidth() > block.getWidth() ? prev.getWidth() - block.getWidth() : 0);
188
- }
189
- }
190
- width += block.getWidth() + ChordSymbol.minPadding;
191
- }
192
-
193
- if (symbol.getVertical() === ChordSymbolVerticalJustify.TOP) {
194
- symbol.setTextLine(state.topTextLine);
195
- state.topTextLine += lineSpaces;
196
- } else {
197
- symbol.setTextLine(state.textLine + 1);
198
- state.textLine += lineSpaces + 1;
199
- }
200
- if (symbol.getReportWidth()) {
201
- if (isStemmableNote(note)) {
202
- const glyphWidth = note.getGlyphWidth();
203
- if (symbol.getHorizontal() === ChordSymbolHorizontalJustify.RIGHT) {
204
- maxLeftGlyphWidth = Math.max(glyphWidth, maxLeftGlyphWidth);
205
- leftWidth = Math.max(leftWidth, width) + ChordSymbol.minPadding;
206
- } else if (symbol.getHorizontal() === ChordSymbolHorizontalJustify.LEFT) {
207
- maxRightGlyphWidth = Math.max(glyphWidth, maxRightGlyphWidth);
208
- rightWidth = Math.max(rightWidth, width);
209
- } else {
210
- leftWidth = Math.max(leftWidth, width / 2) + ChordSymbol.minPadding;
211
- rightWidth = Math.max(rightWidth, width / 2);
212
- maxLeftGlyphWidth = Math.max(glyphWidth / 2, maxLeftGlyphWidth);
213
- maxRightGlyphWidth = Math.max(glyphWidth / 2, maxRightGlyphWidth);
214
- }
215
- }
216
- symbol.width = width;
217
- }
218
- width = 0; // reset symbol width
219
- }
220
- const rightOverlap = Math.min(
221
- Math.max(rightWidth - maxRightGlyphWidth, 0),
222
- Math.max(rightWidth - state.rightShift, 0)
223
- );
224
- const leftOverlap = Math.min(Math.max(leftWidth - maxLeftGlyphWidth, 0), Math.max(leftWidth - state.leftShift, 0));
225
-
226
- state.leftShift += leftOverlap;
227
- state.rightShift += rightOverlap;
228
- return true;
229
- }
230
-
231
- protected symbolBlocks: ChordSymbolBlock[] = [];
232
- protected horizontal: number = ChordSymbolHorizontalJustify.LEFT;
233
- protected vertical: number = ChordSymbolVerticalJustify.TOP;
234
- protected reportWidth: boolean = true;
235
-
236
- constructor() {
237
- super();
238
- }
239
-
240
- /**
241
- * The offset is specified in `em`. Scale this value by the font size in pixels.
242
- */
243
- get superscriptOffset(): number {
244
- return ChordSymbol.superscriptOffset * Font.convertSizeToPixelValue(this.fontInfo.size);
245
- }
246
-
247
- get subscriptOffset(): number {
248
- return ChordSymbol.subscriptOffset * Font.convertSizeToPixelValue(this.fontInfo.size);
249
- }
250
- setReportWidth(value: boolean): this {
251
- this.reportWidth = value;
252
- return this;
253
- }
254
-
255
- getReportWidth(): boolean {
256
- return this.reportWidth;
257
- }
258
- /**
259
- * ChordSymbol allows multiple blocks so we can mix glyphs and font text.
260
- * Each block can have its own vertical orientation.
261
- */
262
- getSymbolBlock(
263
- params: Partial<{
264
- text: string;
265
- symbolModifier: SymbolModifiers;
266
- }> = {}
267
- ): ChordSymbolBlock {
268
- const symbolBlock = new ChordSymbolBlock(
269
- params.text ?? '',
270
- params.symbolModifier ?? SymbolModifiers.NONE,
271
- 0,
272
- 0,
273
- false
274
- );
275
-
276
- if (symbolBlock.isSubscript()) {
277
- symbolBlock.setYShift(this.subscriptOffset);
278
- }
279
- if (symbolBlock.isSuperscript()) {
280
- symbolBlock.setYShift(this.superscriptOffset);
281
- }
282
- if (symbolBlock.isSubscript() || symbolBlock.isSuperscript()) {
283
- const { family, size, weight, style } = this.fontInfo;
284
- const smallerFontSize = Font.scaleSize(size, ChordSymbol.superSubRatio);
285
- symbolBlock.setFont(family, smallerFontSize, weight, style);
286
- } else {
287
- symbolBlock.setFont(this.fontInfo);
288
- }
289
-
290
- return symbolBlock;
291
- }
292
-
293
- /** Add a symbol to this chord, could be text, glyph or line. */
294
- addSymbolBlock(
295
- parameters: Partial<{
296
- text: string;
297
- symbolModifier: SymbolModifiers;
298
- }>
299
- ): this {
300
- this.symbolBlocks.push(this.getSymbolBlock(parameters));
301
- return this;
302
- }
303
-
304
- // ### Convenience functions for creating different types of chord symbol parts.
305
-
306
- /** Add a text block. */
307
- addText(
308
- text: string,
309
- parameters: Partial<{
310
- symbolModifier: SymbolModifiers;
311
- }> = {}
312
- ): this {
313
- return this.addSymbolBlock({ ...parameters, text });
314
- }
315
-
316
- /** Add a text block with superscript modifier. */
317
- addTextSuperscript(text: string): this {
318
- const symbolModifier = SymbolModifiers.SUPERSCRIPT;
319
- return this.addSymbolBlock({ text, symbolModifier });
320
- }
321
-
322
- /** Add a text block with subscript modifier. */
323
- addTextSubscript(text: string): this {
324
- const symbolModifier = SymbolModifiers.SUBSCRIPT;
325
- return this.addSymbolBlock({ text, symbolModifier });
326
- }
327
-
328
- /** Add a glyph block with superscript modifier. */
329
- addGlyphSuperscript(glyph: string): this {
330
- return this.addTextSuperscript(ChordSymbol.glyphs[glyph]);
331
- }
332
-
333
- /** Add a glyph block. */
334
- addGlyph(
335
- glyph: string,
336
- params: Partial<{
337
- symbolModifier: SymbolModifiers;
338
- }> = {}
339
- ): this {
340
- return this.addText(ChordSymbol.glyphs[glyph], params);
341
- }
342
-
343
- /**
344
- * Add a glyph for each character in 'text'. If the glyph is not available, use text from the font.
345
- * e.g. `addGlyphOrText('(+5#11)')` will use text for the '5' and '11', and glyphs for everything else.
346
- */
347
- addGlyphOrText(
348
- text: string,
349
- params: Partial<{
350
- symbolModifier: SymbolModifiers;
351
- }> = {}
352
- ): this {
353
- let str = '';
354
- for (let i = 0; i < text.length; ++i) {
355
- const char = text[i];
356
- const glyph = ChordSymbol.glyphs[char];
357
- if (glyph) {
358
- str += glyph;
359
- } else {
360
- // Collect consecutive characters with no glyphs.
361
- str += char;
362
- }
363
- }
364
- if (str.length > 0) {
365
- this.addText(str, params);
366
- }
367
- return this;
368
- }
369
-
370
- /** Add a line of the given width, used as a continuation of the previous symbol in analysis, or lyrics, etc. */
371
- addLine(
372
- params: Partial<{
373
- symbolModifier: SymbolModifiers;
374
- }> = {}
375
- ): this {
376
- // Two csymMinor glyphs next to each other.
377
- return this.addText('\ue874\ue874' /*{csymMinor}{csymMinor}*/, params);
378
- }
379
-
380
- /** Set vertical position of text (above or below stave). */
381
- setVertical(vj: ChordSymbolVerticalJustify | string | number): this {
382
- this.vertical = typeof vj === 'string' ? ChordSymbol.VerticalJustifyString[vj] : vj;
383
- return this;
384
- }
385
-
386
- getVertical(): number {
387
- return this.vertical;
388
- }
389
-
390
- /** Set horizontal justification. */
391
- setHorizontal(hj: ChordSymbolHorizontalJustify | string | number): this {
392
- this.horizontal = typeof hj === 'string' ? ChordSymbol.HorizontalJustifyString[hj] : hj;
393
- return this;
394
- }
395
-
396
- getHorizontal(): number {
397
- return this.horizontal;
398
- }
399
-
400
- /** Render text and glyphs above/below the note. */
401
- draw(): void {
402
- const ctx = this.checkContext();
403
- const note = this.checkAttachedNote() as StemmableNote;
404
- this.setRendered();
405
-
406
- // We're changing context parameters. Save current state.
407
- ctx.save();
408
- this.applyStyle();
409
- ctx.openGroup('chordsymbol', this.getAttribute('id'));
410
-
411
- const start = note.getModifierStartXY(Modifier.Position.ABOVE, this.index);
412
- ctx.setFont(this.fontInfo);
413
-
414
- let y: number;
415
-
416
- // The position of the text varies based on whether or not the note
417
- // has a stem.
418
- const hasStem = note.hasStem();
419
- const stave = note.checkStave();
420
-
421
- if (this.vertical === ChordSymbolVerticalJustify.BOTTOM) {
422
- // HACK: We need to compensate for the text's height since its origin is bottom-right.
423
- y = stave.getYForBottomText(this.textLine + Tables.TEXT_HEIGHT_OFFSET_HACK);
424
- if (hasStem) {
425
- const stemExt = note.checkStem().getExtents();
426
- const spacing = stave.getSpacingBetweenLines();
427
- const stemBase = note.getStemDirection() === 1 ? stemExt.baseY : stemExt.topY;
428
- y = Math.max(y, stemBase + spacing * (this.textLine + 2));
429
- }
430
- } else {
431
- // (this.vertical === VerticalJustify.TOP)
432
- const topY = Math.min(...note.getYs());
433
- y = Math.min(stave.getYForTopText(this.textLine), topY - 10);
434
- if (hasStem) {
435
- const stemExt = note.checkStem().getExtents();
436
- const spacing = stave.getSpacingBetweenLines();
437
- y = Math.min(y, stemExt.topY - 5 - spacing * this.textLine);
438
- }
439
- }
440
-
441
- let x = start.x;
442
- if (this.horizontal === ChordSymbolHorizontalJustify.LEFT) {
443
- x = start.x;
444
- } else if (this.horizontal === ChordSymbolHorizontalJustify.RIGHT) {
445
- x = start.x + this.getWidth();
446
- } else if (this.horizontal === ChordSymbolHorizontalJustify.CENTER) {
447
- x = start.x - this.getWidth() / 2;
448
- } else {
449
- // HorizontalJustify.CENTER_STEM
450
- x = note.getStemX() - this.getWidth() / 2;
451
- }
452
- L('Rendering ChordSymbol: ', x, y);
453
-
454
- this.symbolBlocks.forEach((symbol) => {
455
- L('Rendering Text: ', symbol.getText(), x + symbol.getXShift(), y + symbol.getYShift());
456
- symbol.setX(x);
457
- symbol.setY(y);
458
- symbol.renderText(ctx, 0, 0);
459
- });
460
- ctx.closeGroup();
461
- this.restoreStyle();
462
- ctx.restore();
463
- }
464
-
465
- // Get the `BoundingBox` for the entire chord
466
- getBoundingBox(): BoundingBox {
467
- const boundingBox = this.symbolBlocks[0].getBoundingBox();
468
- for (let i = 1; i < this.symbolBlocks.length; i++) {
469
- boundingBox.mergeWith(this.symbolBlocks[i].getBoundingBox());
470
- }
471
- return boundingBox;
472
- }
473
- }
package/src/clef.ts DELETED
@@ -1,164 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- // MIT License
3
- // Co-author: Benjamin W. Bohl
4
-
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
- import { log } from './util';
11
-
12
- // eslint-disable-next-line
13
- function L(...args: any[]) {
14
- if (Clef.DEBUG) log('VexFlow.Clef', args);
15
- }
16
-
17
- /**
18
- * Clef implements various types of clefs that can be rendered on a stave.
19
- *
20
- * See `tests/clef_tests.ts` for usage examples.
21
- */
22
- export class Clef extends StaveModifier {
23
- /** To enable logging for this class, set `VexFlow.Clef.DEBUG` to `true`. */
24
- static DEBUG: boolean = false;
25
-
26
- static get CATEGORY(): string {
27
- return Category.Clef;
28
- }
29
-
30
- /**
31
- * The attribute `clef` must be a key from
32
- * `Clef.types`
33
- */
34
- code = Clef.types['treble'].code;
35
- line = Clef.types['treble'].line;
36
-
37
- protected size = 'default';
38
- protected type = 'treble';
39
-
40
- /**
41
- * Every clef name is associated with a glyph code from the font file
42
- * and a default stave line number.
43
- */
44
- static get types(): Record<string, { code: string; line: number }> {
45
- const { gClef, fClef, cClef, unpitchedPercussionClef1, sixStringTabClef } = Glyphs;
46
-
47
- return {
48
- treble: {
49
- code: gClef,
50
- line: 3,
51
- },
52
- bass: {
53
- code: fClef,
54
- line: 1,
55
- },
56
- alto: {
57
- code: cClef,
58
- line: 2,
59
- },
60
- tenor: {
61
- code: cClef,
62
- line: 1,
63
- },
64
- percussion: {
65
- code: unpitchedPercussionClef1,
66
- line: 2,
67
- },
68
- soprano: {
69
- code: cClef,
70
- line: 4,
71
- },
72
- 'mezzo-soprano': {
73
- code: cClef,
74
- line: 3,
75
- },
76
- 'baritone-c': {
77
- code: cClef,
78
- line: 0,
79
- },
80
- 'baritone-f': {
81
- code: fClef,
82
- line: 2,
83
- },
84
- subbass: {
85
- code: fClef,
86
- line: 0,
87
- },
88
- french: {
89
- code: gClef,
90
- line: 4,
91
- },
92
- tab: {
93
- code: sixStringTabClef,
94
- line: 2.5,
95
- },
96
- };
97
- }
98
-
99
- /** Create a new clef. */
100
- constructor(type: string, size?: string, annotation?: string) {
101
- super();
102
-
103
- this.setPosition(StaveModifierPosition.BEGIN);
104
- this.setType(type, size, annotation);
105
- L('Creating clef:', type);
106
- }
107
-
108
- /** Set clef type, size and annotation. */
109
- setType(type: string, size: string = 'default', annotation?: string): this {
110
- this.type = type;
111
- this.code = Clef.types[type].code;
112
- this.line = Clef.types[type].line;
113
- this.size = size ?? 'default';
114
-
115
- // If an annotation, such as 8va, is specified, add it to the Clef object.
116
- if (annotation === '8va') {
117
- if (this.code === Glyphs.gClef) {
118
- this.code = Glyphs.gClef8va;
119
- }
120
- if (this.code === Glyphs.fClef) {
121
- this.code = Glyphs.fClef8va;
122
- }
123
- }
124
- if (annotation === '8vb') {
125
- if (this.code === Glyphs.gClef) {
126
- this.code = Glyphs.gClef8vb;
127
- }
128
- if (this.code === Glyphs.fClef) {
129
- this.code = Glyphs.fClef8vb;
130
- }
131
- }
132
- this.text = this.code;
133
- this.fontInfo.size = Math.floor(Clef.getPoint(this.size));
134
-
135
- return this;
136
- }
137
-
138
- /** Get point for clefs. */
139
- static getPoint(size?: string): number {
140
- // for sizes other than 'default', clef is 2/3 of the default value
141
- return size === 'default' ? Metrics.get('fontSize') : (Metrics.get('fontSize') * 2) / 3;
142
- }
143
-
144
- /** Set associated stave. */
145
- setStave(stave: Stave): this {
146
- this.stave = stave;
147
- return this;
148
- }
149
-
150
- /** Render clef. */
151
- draw(): void {
152
- const stave = this.checkStave();
153
- const ctx = stave.checkContext();
154
- this.setRendered();
155
-
156
- this.applyStyle(ctx);
157
- ctx.openGroup('clef', this.getAttribute('id'));
158
-
159
- this.y = stave.getYForLine(this.line);
160
- this.renderText(ctx, 0, 0);
161
- ctx.closeGroup();
162
- this.restoreStyle(ctx);
163
- }
164
- }
package/src/clefnote.ts DELETED
@@ -1,50 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- // @author: Taehoon Moon 2014
3
- // MIT License
4
-
5
- import { Clef } from './clef';
6
- import { Note } from './note';
7
- import { Category } from './typeguard';
8
-
9
- /** ClefNote implements clef annotations in measures. */
10
- export class ClefNote extends Note {
11
- static get CATEGORY(): string {
12
- return Category.ClefNote;
13
- }
14
-
15
- protected clef!: Clef;
16
-
17
- constructor(type: string, size: string = 'default', annotation?: string) {
18
- super({ duration: 'b' });
19
- this.setType(type, size, annotation);
20
- this.ignoreTicks = true;
21
- }
22
-
23
- /** Set clef type, size and annotation. */
24
- setType(type: string, size: string, annotation?: string): this {
25
- this.clef = new Clef(type, size, annotation);
26
- this.setWidth(this.clef.getWidth());
27
-
28
- return this;
29
- }
30
-
31
- /** Get associated clef. */
32
- getClef(): Clef {
33
- return this.clef;
34
- }
35
-
36
- preFormat(): this {
37
- this.preFormatted = true;
38
- return this;
39
- }
40
-
41
- /** Render clef note. */
42
- draw(): void {
43
- const stave = this.checkStave();
44
- const ctx = this.checkContext();
45
-
46
- this.setRendered();
47
-
48
- this.clef.renderText(ctx, this.getAbsoluteX() - this.x, stave.getYForLine(this.clef.line));
49
- }
50
- }