vexflow 5.0.0-alpha.2 → 5.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/build/cjs/vexflow-bravura.js +2 -2
  2. package/build/cjs/vexflow-bravura.js.map +1 -1
  3. package/build/cjs/vexflow-core.js +2 -2
  4. package/build/cjs/vexflow-core.js.map +1 -1
  5. package/build/cjs/vexflow-debug-with-tests.js +4 -4
  6. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  7. package/build/cjs/vexflow-debug.js +4 -4
  8. package/build/cjs/vexflow-debug.js.map +1 -1
  9. package/build/cjs/vexflow.js +2 -2
  10. package/build/cjs/vexflow.js.map +1 -1
  11. package/build/esm/src/version.js +3 -3
  12. package/package.json +1 -3
  13. package/entry/vexflow-bravura.ts +0 -25
  14. package/entry/vexflow-core.ts +0 -16
  15. package/entry/vexflow-debug-with-tests.ts +0 -64
  16. package/entry/vexflow-debug.ts +0 -54
  17. package/entry/vexflow.ts +0 -47
  18. package/src/accidental.ts +0 -570
  19. package/src/annotation.ts +0 -294
  20. package/src/articulation.ts +0 -383
  21. package/src/barnote.ts +0 -95
  22. package/src/beam.ts +0 -999
  23. package/src/bend.ts +0 -268
  24. package/src/boundingbox.ts +0 -108
  25. package/src/canvascontext.ts +0 -348
  26. package/src/chordsymbol.ts +0 -473
  27. package/src/clef.ts +0 -164
  28. package/src/clefnote.ts +0 -50
  29. package/src/crescendo.ts +0 -132
  30. package/src/curve.ts +0 -195
  31. package/src/dot.ts +0 -171
  32. package/src/easyscore.ts +0 -538
  33. package/src/element.ts +0 -692
  34. package/src/factory.ts +0 -694
  35. package/src/font.ts +0 -343
  36. package/src/fonts/academico.ts +0 -2
  37. package/src/fonts/academicobold.ts +0 -2
  38. package/src/fonts/bravura.ts +0 -2
  39. package/src/fonts/gonville.ts +0 -2
  40. package/src/fonts/petaluma.ts +0 -2
  41. package/src/fonts/petalumascript.ts +0 -2
  42. package/src/formatter.ts +0 -1107
  43. package/src/fraction.ts +0 -245
  44. package/src/frethandfinger.ts +0 -180
  45. package/src/ghostnote.ts +0 -75
  46. package/src/glyphnote.ts +0 -68
  47. package/src/glyphs.ts +0 -5880
  48. package/src/gracenote.ts +0 -146
  49. package/src/gracenotegroup.ts +0 -194
  50. package/src/gracetabnote.ts +0 -30
  51. package/src/index.ts +0 -90
  52. package/src/keymanager.ts +0 -153
  53. package/src/keysignature.ts +0 -272
  54. package/src/keysignote.ts +0 -46
  55. package/src/metrics.ts +0 -222
  56. package/src/modifier.ts +0 -216
  57. package/src/modifiercontext.ts +0 -177
  58. package/src/multimeasurerest.ts +0 -229
  59. package/src/music.ts +0 -443
  60. package/src/note.ts +0 -690
  61. package/src/notehead.ts +0 -158
  62. package/src/notesubgroup.ts +0 -88
  63. package/src/ornament.ts +0 -301
  64. package/src/parenthesis.ts +0 -89
  65. package/src/parser.ts +0 -263
  66. package/src/pedalmarking.ts +0 -273
  67. package/src/registry.ts +0 -146
  68. package/src/rendercontext.ts +0 -98
  69. package/src/renderer.ts +0 -166
  70. package/src/repeatnote.ts +0 -25
  71. package/src/stave.ts +0 -885
  72. package/src/stavebarline.ts +0 -231
  73. package/src/staveconnector.ts +0 -281
  74. package/src/stavehairpin.ts +0 -209
  75. package/src/staveline.ts +0 -343
  76. package/src/stavemodifier.ts +0 -93
  77. package/src/stavenote.ts +0 -1230
  78. package/src/staverepetition.ts +0 -148
  79. package/src/stavesection.ts +0 -54
  80. package/src/stavetempo.ts +0 -162
  81. package/src/stavetext.ts +0 -69
  82. package/src/stavetie.ts +0 -235
  83. package/src/stavevolta.ts +0 -66
  84. package/src/stem.ts +0 -225
  85. package/src/stemmablenote.ts +0 -248
  86. package/src/stringnumber.ts +0 -286
  87. package/src/strokes.ts +0 -214
  88. package/src/svgcontext.ts +0 -639
  89. package/src/system.ts +0 -327
  90. package/src/tables.ts +0 -796
  91. package/src/tabnote.ts +0 -449
  92. package/src/tabslide.ts +0 -115
  93. package/src/tabstave.ts +0 -31
  94. package/src/tabtie.ts +0 -44
  95. package/src/textbracket.ts +0 -231
  96. package/src/textdynamics.ts +0 -101
  97. package/src/textnote.ts +0 -175
  98. package/src/tickable.ts +0 -374
  99. package/src/tickcontext.ts +0 -280
  100. package/src/timesignature.ts +0 -229
  101. package/src/timesignote.ts +0 -45
  102. package/src/tremolo.ts +0 -51
  103. package/src/tuning.ts +0 -90
  104. package/src/tuplet.ts +0 -349
  105. package/src/typeguard.ts +0 -136
  106. package/src/util.ts +0 -169
  107. package/src/version.ts +0 -4
  108. package/src/vexflow.ts +0 -378
  109. package/src/vibrato.ts +0 -99
  110. package/src/vibratobracket.ts +0 -81
  111. package/src/voice.ts +0 -302
  112. package/src/web.ts +0 -35
package/src/vexflow.ts DELETED
@@ -1,378 +0,0 @@
1
- import { Accidental } from './accidental';
2
- import { Annotation, AnnotationHorizontalJustify, AnnotationVerticalJustify } from './annotation';
3
- import { Articulation } from './articulation';
4
- import { BarNote } from './barnote';
5
- import { Beam } from './beam';
6
- import { Bend } from './bend';
7
- import { BoundingBox } from './boundingbox';
8
- import { CanvasContext } from './canvascontext';
9
- import { ChordSymbol, ChordSymbolHorizontalJustify, ChordSymbolVerticalJustify, SymbolModifiers } from './chordsymbol';
10
- import { Clef } from './clef';
11
- import { ClefNote } from './clefnote';
12
- import { Crescendo } from './crescendo';
13
- import { Curve, CurvePosition } from './curve';
14
- import { Dot } from './dot';
15
- import { EasyScore } from './easyscore';
16
- import { Element } from './element';
17
- import { Factory } from './factory';
18
- import { Font, FontStyle, FontWeight } from './font';
19
- import { Formatter } from './formatter';
20
- import { Fraction } from './fraction';
21
- import { FretHandFinger } from './frethandfinger';
22
- import { GhostNote } from './ghostnote';
23
- import { GlyphNote } from './glyphnote';
24
- import { Glyphs } from './glyphs';
25
- import { GraceNote } from './gracenote';
26
- import { GraceNoteGroup } from './gracenotegroup';
27
- import { GraceTabNote } from './gracetabnote';
28
- import { KeyManager } from './keymanager';
29
- import { KeySignature } from './keysignature';
30
- import { KeySigNote } from './keysignote';
31
- import { Metrics, MetricsDefaults } from './metrics';
32
- import { Modifier, ModifierPosition } from './modifier';
33
- import { ModifierContext } from './modifiercontext';
34
- import { MultiMeasureRest } from './multimeasurerest';
35
- import { Music } from './music';
36
- import { Note } from './note';
37
- import { NoteHead } from './notehead';
38
- import { NoteSubGroup } from './notesubgroup';
39
- import { Ornament } from './ornament';
40
- import { Parenthesis } from './parenthesis';
41
- import { Parser } from './parser';
42
- import { PedalMarking } from './pedalmarking';
43
- import { Registry } from './registry';
44
- import { RenderContext } from './rendercontext';
45
- import { Renderer, RendererBackends, RendererLineEndType } from './renderer';
46
- import { RepeatNote } from './repeatnote';
47
- import { Stave } from './stave';
48
- import { Barline, BarlineType } from './stavebarline';
49
- import { StaveConnector } from './staveconnector';
50
- import { StaveHairpin } from './stavehairpin';
51
- import { StaveLine } from './staveline';
52
- import { StaveModifier, StaveModifierPosition } from './stavemodifier';
53
- import { StaveNote } from './stavenote';
54
- import { Repetition } from './staverepetition';
55
- import { StaveTempo } from './stavetempo';
56
- import { StaveText } from './stavetext';
57
- import { StaveTie } from './stavetie';
58
- import { Volta, VoltaType } from './stavevolta';
59
- import { Stem } from './stem';
60
- import { StringNumber } from './stringnumber';
61
- import { Stroke } from './strokes';
62
- import { SVGContext } from './svgcontext';
63
- import { System } from './system';
64
- import { Tables } from './tables';
65
- import { TabNote } from './tabnote';
66
- import { TabSlide } from './tabslide';
67
- import { TabStave } from './tabstave';
68
- import { TabTie } from './tabtie';
69
- import { TextBracket, TextBracketPosition } from './textbracket';
70
- import { TextDynamics } from './textdynamics';
71
- import { TextJustification, TextNote } from './textnote';
72
- import { TickContext } from './tickcontext';
73
- import { TimeSignature } from './timesignature';
74
- import { TimeSigNote } from './timesignote';
75
- import { Tremolo } from './tremolo';
76
- import { Tuning } from './tuning';
77
- import { Tuplet } from './tuplet';
78
- import { RuntimeError } from './util';
79
- import { DATE, ID, VERSION } from './version';
80
- import { Vibrato } from './vibrato';
81
- import { VibratoBracket } from './vibratobracket';
82
- import { Voice, VoiceMode, VoiceTime } from './voice';
83
-
84
- export class VexFlow {
85
- // VERSION, ID, and DATE are imported from version.ts.
86
- // INFO is set by the entry file in vexflow/entry/.
87
- static BUILD = {
88
- // version number.
89
- VERSION: VERSION,
90
- // git commit ID that this library was built from.
91
- ID: ID,
92
- // The date when this library was compiled.
93
- DATE: DATE,
94
- // Which build is this? vexflow, vexflow-bravura, vexflow-core, etc.
95
- INFO: '',
96
- };
97
-
98
- static Accidental = Accidental;
99
- static Annotation = Annotation;
100
- static Articulation = Articulation;
101
- static Barline = Barline;
102
- static BarNote = BarNote;
103
- static Beam = Beam;
104
- static Bend = Bend;
105
- static BoundingBox = BoundingBox;
106
- static CanvasContext = CanvasContext;
107
- static ChordSymbol = ChordSymbol;
108
- static Clef = Clef;
109
- static ClefNote = ClefNote;
110
- static Crescendo = Crescendo;
111
- static Curve = Curve;
112
- static Dot = Dot;
113
- static EasyScore = EasyScore;
114
- static Element = Element;
115
- static Factory = Factory;
116
- static Font = Font;
117
- static Formatter = Formatter;
118
- static Fraction = Fraction;
119
- static FretHandFinger = FretHandFinger;
120
- static GhostNote = GhostNote;
121
- static GlyphNote = GlyphNote;
122
- static GraceNote = GraceNote;
123
- static GraceNoteGroup = GraceNoteGroup;
124
- static GraceTabNote = GraceTabNote;
125
- static KeyManager = KeyManager;
126
- static KeySignature = KeySignature;
127
- static KeySigNote = KeySigNote;
128
- static Modifier = Modifier;
129
- static ModifierContext = ModifierContext;
130
- static MultiMeasureRest = MultiMeasureRest;
131
- static Music = Music;
132
- static Note = Note;
133
- static NoteHead = NoteHead;
134
- static NoteSubGroup = NoteSubGroup;
135
- static Ornament = Ornament;
136
- static Parenthesis = Parenthesis;
137
- static Parser = Parser;
138
- static PedalMarking = PedalMarking;
139
- static Registry = Registry;
140
- static RenderContext = RenderContext;
141
- static Renderer = Renderer;
142
- static RepeatNote = RepeatNote;
143
- static Repetition = Repetition;
144
- static Stave = Stave;
145
- static StaveConnector = StaveConnector;
146
- static StaveHairpin = StaveHairpin;
147
- static StaveLine = StaveLine;
148
- static StaveModifier = StaveModifier;
149
- static StaveNote = StaveNote;
150
- static StaveTempo = StaveTempo;
151
- static StaveText = StaveText;
152
- static StaveTie = StaveTie;
153
- static Stem = Stem;
154
- static StringNumber = StringNumber;
155
- static Stroke = Stroke;
156
- static SVGContext = SVGContext;
157
- static System = System;
158
- static TabNote = TabNote;
159
- static TabSlide = TabSlide;
160
- static TabStave = TabStave;
161
- static TabTie = TabTie;
162
- static TextBracket = TextBracket;
163
- static TextDynamics = TextDynamics;
164
- static TextNote = TextNote;
165
- static TickContext = TickContext;
166
- static TimeSignature = TimeSignature;
167
- static TimeSigNote = TimeSigNote;
168
- static Tremolo = Tremolo;
169
- static Tuning = Tuning;
170
- static Tuplet = Tuplet;
171
- static Vibrato = Vibrato;
172
- static VibratoBracket = VibratoBracket;
173
- static Voice = Voice;
174
- static Volta = Volta;
175
-
176
- static RuntimeError = RuntimeError;
177
-
178
- static Test = undefined; // Set by vexflow_test_helpers.ts in the debug version of this library.
179
-
180
- // Exported Enums.
181
- // Sorted by the module / file they are exported from.
182
- static AnnotationHorizontalJustify = AnnotationHorizontalJustify;
183
- static AnnotationVerticalJustify = AnnotationVerticalJustify;
184
- static ChordSymbolHorizontalJustify = ChordSymbolHorizontalJustify;
185
- static ChordSymbolVerticalJustify = ChordSymbolVerticalJustify;
186
- static SymbolModifiers = SymbolModifiers;
187
- static CurvePosition = CurvePosition;
188
- static FontWeight = FontWeight;
189
- static FontStyle = FontStyle;
190
- static Glyphs = Glyphs;
191
- static ModifierPosition = ModifierPosition;
192
- static RendererBackends = RendererBackends;
193
- static RendererLineEndType = RendererLineEndType;
194
- static BarlineType = BarlineType;
195
- static StaveModifierPosition = StaveModifierPosition;
196
- static VoltaType = VoltaType;
197
- static TextBracketPosition = TextBracketPosition;
198
- static TextJustification = TextJustification;
199
- static VoiceMode = VoiceMode;
200
-
201
- /**
202
- * Load the fonts that are used by your app.
203
- *
204
- * Call this if you are using `vexflow-core.js` to take advantage of lazy loading for fonts.
205
- *
206
- * If you are using `vexflow.js` or `vexflow-bravura.js`, this method is unnecessary, since
207
- * they already call loadFonts(...) and setFonts(...) for you.
208
- *
209
- * If `fontNames` is undefined, all fonts in Font.FILES will be loaded.
210
- * This is useful for debugging, but not recommended for production because it will load lots of fonts.
211
- *
212
- * For example, on the `flow.html` test page, you could call:
213
- * `await VexFlow.loadFonts();`
214
- *
215
- * Alternatively, you may load web fonts with a stylesheet link (e.g., from Google Fonts),
216
- * and a @font-face { font-family: ... } rule in your CSS.
217
- *
218
- * Customize `Font.HOST_URL` and `Font.FILES` to load different fonts for your app.
219
- */
220
- static async loadFonts(...fontNames: string[]): Promise<void> {
221
- if (!fontNames) {
222
- fontNames = Object.keys(Font.FILES);
223
- }
224
-
225
- const fontLoadPromises: Promise<FontFace>[] = [];
226
- for (const fontName of fontNames) {
227
- fontLoadPromises.push(Font.load(fontName));
228
- }
229
-
230
- await Promise.all(fontLoadPromises);
231
- }
232
-
233
- /**
234
- * Call this if you are using `vexflow-core.js` to take advantage of lazy loading for fonts.
235
- *
236
- * `vexflow.js` and `vexflow-bravura.js` already call setFonts('Bravura', 'Academico'), so you only
237
- * need to call this when switching fonts.
238
- *
239
- * Example:
240
- * ```
241
- * await VexFlow.loadFonts('Bravura', 'Academico', 'Petaluma', 'Petaluma Script');
242
- * VexFlow.setFonts('Bravura', 'Academico');
243
- * ... render a score in Bravura ...
244
- * VexFlow.setFonts('Petaluma', 'Petaluma Script');
245
- * ... render a score in Petaluma...
246
- * ```
247
- * See `demos/fonts/` for more examples.
248
- */
249
- static setFonts(...fontNames: string[]): void {
250
- // Convert the array of font names into an array of Font objects.
251
- MetricsDefaults.fontFamily = fontNames.join(',');
252
- }
253
-
254
- static getFonts(): string[] {
255
- return Metrics.get('fontFamily').split(',');
256
- }
257
-
258
- static get RENDER_PRECISION_PLACES(): number {
259
- return Tables.RENDER_PRECISION_PLACES;
260
- }
261
-
262
- static set RENDER_PRECISION_PLACES(precision: number) {
263
- Tables.RENDER_PRECISION_PLACES = precision;
264
- }
265
-
266
- static get SOFTMAX_FACTOR(): number {
267
- return Tables.SOFTMAX_FACTOR;
268
- }
269
-
270
- static set SOFTMAX_FACTOR(factor: number) {
271
- Tables.SOFTMAX_FACTOR = factor;
272
- }
273
-
274
- static get UNISON(): boolean {
275
- return Tables.UNISON;
276
- }
277
-
278
- static set UNISON(unison: boolean) {
279
- Tables.UNISON = unison;
280
- }
281
-
282
- static get NOTATION_FONT_SCALE(): number {
283
- return Tables.NOTATION_FONT_SCALE;
284
- }
285
-
286
- static set NOTATION_FONT_SCALE(value: number) {
287
- Tables.NOTATION_FONT_SCALE = value;
288
- }
289
-
290
- static get TABLATURE_FONT_SCALE(): number {
291
- return Tables.TABLATURE_FONT_SCALE;
292
- }
293
-
294
- static set TABLATURE_FONT_SCALE(value: number) {
295
- Tables.TABLATURE_FONT_SCALE = value;
296
- }
297
-
298
- static get RESOLUTION(): number {
299
- return Tables.RESOLUTION;
300
- }
301
-
302
- static set RESOLUTION(value: number) {
303
- Tables.RESOLUTION = value;
304
- }
305
-
306
- static get SLASH_NOTEHEAD_WIDTH(): number {
307
- return Tables.SLASH_NOTEHEAD_WIDTH;
308
- }
309
-
310
- static set SLASH_NOTEHEAD_WIDTH(value: number) {
311
- Tables.SLASH_NOTEHEAD_WIDTH = value;
312
- }
313
-
314
- static get STAVE_LINE_DISTANCE(): number {
315
- return Tables.STAVE_LINE_DISTANCE;
316
- }
317
-
318
- static set STAVE_LINE_DISTANCE(value: number) {
319
- Tables.STAVE_LINE_DISTANCE = value;
320
- }
321
-
322
- static get STAVE_LINE_THICKNESS(): number {
323
- return Tables.STAVE_LINE_THICKNESS;
324
- }
325
-
326
- static set STAVE_LINE_THICKNESS(value: number) {
327
- Tables.STAVE_LINE_THICKNESS = value;
328
- }
329
-
330
- static get STEM_HEIGHT(): number {
331
- return Tables.STEM_HEIGHT;
332
- }
333
-
334
- static set STEM_HEIGHT(value: number) {
335
- Tables.STEM_HEIGHT = value;
336
- }
337
-
338
- static get STEM_WIDTH(): number {
339
- return Tables.STEM_WIDTH;
340
- }
341
-
342
- static set STEM_WIDTH(value: number) {
343
- Tables.STEM_WIDTH = value;
344
- }
345
-
346
- static get TIME4_4(): VoiceTime {
347
- return Tables.TIME4_4;
348
- }
349
-
350
- static get unicode(): Record<string, string> {
351
- return Tables.unicode;
352
- }
353
-
354
- static keySignature(spec: string): { type: string; line: number }[] {
355
- return Tables.keySignature(spec);
356
- }
357
-
358
- static hasKeySignature(spec: string): boolean {
359
- return Tables.hasKeySignature(spec);
360
- }
361
-
362
- static getKeySignatures(): Record<string, { acc?: string; num: number }> {
363
- return Tables.getKeySignatures();
364
- }
365
-
366
- static clefProperties(clef: string): { lineShift: number } {
367
- return Tables.clefProperties(clef);
368
- }
369
-
370
- // eslint-disable-next-line
371
- static keyProperties(key: string, clef?: string, params?: any): any {
372
- return Tables.keyProperties(key, clef, params);
373
- }
374
-
375
- static durationToTicks(duration: string): number {
376
- return Tables.durationToTicks(duration);
377
- }
378
- }
package/src/vibrato.ts DELETED
@@ -1,99 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- // MIT License
3
-
4
- import { Bend } from './bend';
5
- import { Modifier } from './modifier';
6
- import { ModifierContext, ModifierContextState } from './modifiercontext';
7
- import { Tables } from './tables';
8
- import { Category } from './typeguard';
9
-
10
- export interface VibratoRenderOptions {
11
- code: number;
12
- width: number;
13
- }
14
-
15
- /** `Vibrato` implements diverse vibratos. */
16
- export class Vibrato extends Modifier {
17
- static get CATEGORY(): string {
18
- return Category.Vibrato;
19
- }
20
-
21
- protected renderOptions: VibratoRenderOptions;
22
-
23
- /** Arrange vibratos inside a `ModifierContext`. */
24
- static format(vibratos: Vibrato[], state: ModifierContextState, context: ModifierContext): boolean {
25
- if (!vibratos || vibratos.length === 0) return false;
26
-
27
- // Vibratos are always on top.
28
- let textLine = state.topTextLine;
29
- let width = 0;
30
- let shift = state.rightShift - 7;
31
-
32
- // If there's a bend, drop the text line
33
- const bends = context.getMembers(Bend.CATEGORY) as Bend[];
34
- if (bends && bends.length > 0) {
35
- const bendHeight =
36
- bends.map((bb) => bb.getTextHeight()).reduce((a, b) => (a > b ? a : b)) / Tables.STAVE_LINE_DISTANCE;
37
- textLine = textLine - (bendHeight + 1);
38
- } else {
39
- state.topTextLine += 1;
40
- }
41
-
42
- // Format Vibratos
43
- for (let i = 0; i < vibratos.length; ++i) {
44
- const vibrato = vibratos[i];
45
- vibrato.setXShift(shift);
46
- vibrato.setTextLine(textLine);
47
- width += vibrato.getWidth();
48
- shift += width;
49
- }
50
-
51
- state.rightShift += width;
52
- return true;
53
- }
54
-
55
- constructor() {
56
- super();
57
-
58
- this.position = Modifier.Position.RIGHT;
59
- this.renderOptions = {
60
- code: 0xeab0,
61
- width: 20,
62
- };
63
-
64
- this.setVibratoWidth(this.renderOptions.width);
65
- }
66
-
67
- /** Set vibrato width in pixels. */
68
- setVibratoWidth(width: number): this {
69
- this.renderOptions.width = width;
70
- this.text = String.fromCodePoint(this.renderOptions.code);
71
-
72
- const items = Math.round(this.renderOptions.width / this.getWidth());
73
- for (let i = 1; i < items; i++) {
74
- this.text += String.fromCodePoint(this.renderOptions.code);
75
- }
76
-
77
- return this;
78
- }
79
-
80
- /** Set vibrato code. */
81
- setVibratoCode(code: number): this {
82
- this.renderOptions.code = code;
83
- return this.setVibratoWidth(this.renderOptions.width);
84
- }
85
-
86
- /** Draw the vibrato on the rendering context. */
87
- draw(): void {
88
- const ctx = this.checkContext();
89
- const note = this.checkAttachedNote();
90
- this.setRendered();
91
-
92
- const start = note.getModifierStartXY(Modifier.Position.RIGHT, this.index);
93
-
94
- const vx = start.x;
95
- const vy = note.getYForTopText(this.textLine) + 5;
96
-
97
- this.renderText(ctx, vx, vy);
98
- }
99
- }
@@ -1,81 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- // @author Balazs Forian-Szabo
3
- // MIT License
4
-
5
- import { Element } from './element';
6
- import { Note } from './note';
7
- import { Category } from './typeguard';
8
- import { log } from './util';
9
- import { Vibrato } from './vibrato';
10
-
11
- // eslint-disable-next-line
12
- function L(...args: any[]) {
13
- if (VibratoBracket.DEBUG) log('VexFlow.VibratoBracket', args);
14
- }
15
-
16
- /** `VibratoBracket` renders vibrato effect between two notes. */
17
- export class VibratoBracket extends Element {
18
- /** To enable logging for this class. Set `VexFlow.VibratoBracket.DEBUG` to `true`. */
19
- static DEBUG: boolean = false;
20
-
21
- static get CATEGORY(): string {
22
- return Category.VibratoBracket;
23
- }
24
-
25
- protected line: number;
26
- protected vibrato = new Vibrato();
27
-
28
- protected start?: Note;
29
- protected stop?: Note;
30
-
31
- /**
32
- * Either the stop or start note must be set, or both of them.
33
- * An undefined value for the start or stop note indicates that the vibrato
34
- * is drawn from the beginning or until the end of the stave accordingly.
35
- */
36
- constructor(bracketData: { stop?: Note | null; start?: Note | null }) {
37
- super();
38
-
39
- if (bracketData.start) this.start = bracketData.start;
40
- if (bracketData.stop) this.stop = bracketData.stop;
41
-
42
- this.line = 1;
43
- }
44
-
45
- /** Set line position of the vibrato bracket. */
46
- setLine(line: number): this {
47
- this.line = line;
48
- return this;
49
- }
50
-
51
- /** Set vibrato code. */
52
- setVibratoCode(code: number): this {
53
- this.vibrato.setVibratoCode(code);
54
- return this;
55
- }
56
-
57
- /** Draw the vibrato bracket on the rendering context. */
58
- draw(): void {
59
- const ctx = this.checkContext();
60
- this.setRendered();
61
- const y: number =
62
- (this.start && this.start.checkStave().getYForTopText(this.line)) ||
63
- (this.stop && this.stop.checkStave().getYForTopText(this.line)) ||
64
- 0;
65
- // If start note is not set then vibrato will be drawn
66
- // from the beginning of the stave
67
- const startX: number =
68
- (this.start && this.start.getAbsoluteX()) || (this.stop && this.stop.checkStave().getTieStartX()) || 0;
69
- // If stop note is not set then vibrato will be drawn
70
- // until the end of the stave
71
- const stopX: number =
72
- (this.stop && this.stop.getAbsoluteX() - this.stop.getWidth() - 5) ||
73
- (this.start && this.start.checkStave().getTieEndX() - 10) ||
74
- 0;
75
-
76
- this.vibrato.setVibratoWidth(stopX - startX);
77
-
78
- L('Rendering VibratoBracket: startX:', startX, 'stopX:', stopX, 'y:', y);
79
- this.vibrato.renderText(ctx, startX, y);
80
- }
81
- }