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/notehead.ts DELETED
@@ -1,158 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- // MIT License
3
-
4
- import { ElementStyle } from './element';
5
- import { Note, NoteStruct } from './note';
6
- import { Stave } from './stave';
7
- import { Stem } from './stem';
8
- import { Category } from './typeguard';
9
- import { defined, log } from './util';
10
-
11
- // eslint-disable-next-line
12
- function L(...args: any[]) {
13
- if (NoteHead.DEBUG) log('VexFlow.NoteHead', args);
14
- }
15
-
16
- export interface NoteHeadStruct extends NoteStruct {
17
- line?: number;
18
- slashed?: boolean;
19
- style?: ElementStyle;
20
- customGlyphCode?: string;
21
- stemDirection?: number;
22
- displaced?: boolean;
23
- noteType?: string;
24
- x?: number;
25
- y?: number;
26
- index?: number;
27
- }
28
-
29
- /**
30
- * `NoteHeads` are typically not manipulated
31
- * directly, but used internally in `StaveNote`.
32
- *
33
- * See `tests/notehead_tests.ts` for usage examples.
34
- */
35
- export class NoteHead extends Note {
36
- /** To enable logging for this class. Set `VexFlow.NoteHead.DEBUG` to `true`. */
37
- static DEBUG: boolean = false;
38
-
39
- static get CATEGORY(): string {
40
- return Category.NoteHead;
41
- }
42
-
43
- protected customGlyph: boolean = false;
44
- protected displaced: boolean;
45
- protected stemDirection: number;
46
-
47
- protected line: number;
48
- protected index?: number;
49
- protected slashed: boolean;
50
-
51
- // map notehead SMuFL codes to the corresponding SMuFL code with ledger line
52
- protected ledger: Record<string, string> = {
53
- '\ue4e3' /*restWhole*/: '\ue4f4' /*restWholeLegerLine*/,
54
- '\ue4e4' /*restHalf*/: '\ue4f5' /*restHalfLegerLine*/,
55
- };
56
-
57
- constructor(noteStruct: NoteHeadStruct) {
58
- super(noteStruct);
59
-
60
- this.index = noteStruct.index;
61
- this.x = noteStruct.x || 0;
62
- this.y = noteStruct.y || 0;
63
- if (noteStruct.noteType) this.noteType = noteStruct.noteType;
64
- this.displaced = noteStruct.displaced || false;
65
- this.stemDirection = noteStruct.stemDirection || Stem.UP;
66
- this.line = noteStruct.line || 0;
67
-
68
- // Get glyph code based on duration and note type. This could be
69
- // regular notes, rests, or other custom codes.
70
- this.glyphProps = Note.getGlyphProps(this.duration, this.noteType);
71
- defined(
72
- this.glyphProps,
73
- 'BadArguments',
74
- `No glyph found for duration '${this.duration}' and type '${this.noteType}'`
75
- );
76
-
77
- // Swap out the glyph with ledger lines
78
- if ((this.line > 5 || this.line < 0) && this.ledger[this.glyphProps.codeHead]) {
79
- this.glyphProps.codeHead = this.ledger[this.glyphProps.codeHead];
80
- }
81
- this.text = this.glyphProps.codeHead;
82
- if (noteStruct.customGlyphCode) {
83
- this.customGlyph = true;
84
- this.text = noteStruct.customGlyphCode;
85
- }
86
-
87
- this.setStyle(noteStruct.style);
88
- this.slashed = noteStruct.slashed || false;
89
-
90
- this.renderOptions = {
91
- ...this.renderOptions,
92
- };
93
- }
94
- /** Get the width of the notehead. */
95
- getWidth(): number {
96
- return this.width;
97
- }
98
-
99
- /** Determine if the notehead is displaced. */
100
- isDisplaced(): boolean {
101
- return this.displaced === true;
102
- }
103
-
104
- /** Get the stave line the notehead is placed on. */
105
- getLine(): number {
106
- return this.line;
107
- }
108
-
109
- /** Set the stave line the notehead is placed on. */
110
- setLine(line: number): this {
111
- this.line = line;
112
- return this;
113
- }
114
-
115
- /** Get the canvas `x` coordinate position of the notehead. */
116
- getAbsoluteX(): number {
117
- // If the note has not been preformatted, then get the static x value
118
- // Otherwise, it's been formatted and we should use it's x value relative
119
- // to its tick context
120
- const x = !this.preFormatted ? this.x : super.getAbsoluteX();
121
-
122
- // For a more natural displaced notehead, we adjust the displacement amount
123
- // by half the stem width in order to maintain a slight overlap with the stem
124
- const displacementStemAdjustment = Stem.WIDTH / 2;
125
-
126
- return x + (this.displaced ? (this.width - displacementStemAdjustment) * this.stemDirection : 0);
127
- }
128
-
129
- /** Set notehead to a provided `stave`. */
130
- setStave(stave: Stave): this {
131
- const line = this.getLine();
132
-
133
- this.stave = stave;
134
- if (this.stave) {
135
- this.setY(this.stave.getYForNote(line));
136
- this.setContext(this.stave.getContext());
137
- }
138
- return this;
139
- }
140
-
141
- /** Pre-render formatting. */
142
- preFormat(): this {
143
- if (this.preFormatted) return this;
144
-
145
- this.preFormatted = true;
146
- return this;
147
- }
148
-
149
- /** Draw the notehead. */
150
- draw(): void {
151
- const ctx = this.checkContext();
152
- this.setRendered();
153
-
154
- L("Drawing note head '", this.noteType, this.duration, "' at", this.x, this.y);
155
- this.x = this.getAbsoluteX();
156
- this.renderText(ctx, 0, 0);
157
- }
158
- }
@@ -1,88 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- // @author: Taehoon Moon 2016
3
- //
4
- // ## Description
5
- //
6
- // This file implements `NoteSubGroup` which is used to format and
7
- // render notes as a `Modifier`
8
- // ex) ClefNote, TimeSigNote and BarNote.
9
-
10
- import { Formatter } from './formatter';
11
- import { Modifier } from './modifier';
12
- import { ModifierContextState } from './modifiercontext';
13
- import { Note } from './note';
14
- import { RenderContext } from './rendercontext';
15
- import { Tables } from './tables';
16
- import { Category } from './typeguard';
17
- import { Voice } from './voice';
18
-
19
- export class NoteSubGroup extends Modifier {
20
- static get CATEGORY(): string {
21
- return Category.NoteSubGroup;
22
- }
23
-
24
- // Arrange groups inside a `ModifierContext`
25
- static format(groups: NoteSubGroup[], state: ModifierContextState): boolean {
26
- if (!groups || groups.length === 0) return false;
27
-
28
- let width = 0;
29
- for (let i = 0; i < groups.length; ++i) {
30
- const group = groups[i];
31
- group.preFormat();
32
- width += group.getWidth();
33
- }
34
-
35
- state.leftShift += width;
36
- return true;
37
- }
38
-
39
- protected subNotes: Note[];
40
- protected preFormatted: boolean = false;
41
- protected formatter: Formatter;
42
- protected voice: Voice;
43
-
44
- constructor(subNotes: Note[]) {
45
- super();
46
-
47
- this.position = Modifier.Position.LEFT;
48
- this.subNotes = subNotes;
49
- this.subNotes.forEach((subNote) => {
50
- subNote.setIgnoreTicks(false);
51
- });
52
- this.width = 0;
53
-
54
- this.formatter = new Formatter();
55
- this.voice = new Voice({
56
- numBeats: 4,
57
- beatValue: 4,
58
- resolution: Tables.RESOLUTION,
59
- }).setStrict(false);
60
-
61
- this.voice.addTickables(this.subNotes);
62
- }
63
-
64
- preFormat(): void {
65
- if (this.preFormatted) return;
66
-
67
- this.formatter.joinVoices([this.voice]).format([this.voice], 0);
68
- this.setWidth(this.formatter.getMinTotalWidth());
69
- this.preFormatted = true;
70
- }
71
-
72
- setWidth(width: number): this {
73
- this.width = width;
74
- return this;
75
- }
76
-
77
- getWidth(): number {
78
- return this.width;
79
- }
80
-
81
- draw(): void {
82
- const ctx: RenderContext = this.checkContext();
83
- const note = this.checkAttachedNote();
84
- this.setRendered();
85
- this.alignSubNotesWithNote(this.subNotes, note); // Modifier function
86
- this.subNotes.forEach((subNote) => subNote.setContext(ctx).drawWithStyle());
87
- }
88
- }
package/src/ornament.ts DELETED
@@ -1,301 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- // @author Cyril Silverman
3
- // MIT License
4
-
5
- import { getBottomY, getInitialOffset, getTopY } from './articulation';
6
- import { Element } from './element';
7
- import { Metrics } from './metrics';
8
- import { Modifier, ModifierPosition } from './modifier';
9
- import { ModifierContextState } from './modifiercontext';
10
- import { Note } from './note';
11
- import { Stem } from './stem';
12
- import { StemmableNote } from './stemmablenote';
13
- import { Tables } from './tables';
14
- import { Category } from './typeguard';
15
- import { log } from './util';
16
-
17
- // eslint-disable-next-line
18
- function L(...args: any[]) {
19
- if (Ornament.DEBUG) log('VexFlow.Ornament', args);
20
- }
21
-
22
- /**
23
- * Ornament implements ornaments as modifiers that can be
24
- * attached to notes. The complete list of ornaments is available in
25
- * `tables.ts` under `VexFlow.ornamentCodes`.
26
- *
27
- * See `tests/ornament_tests.ts` for usage examples.
28
- */
29
- export class Ornament extends Modifier {
30
- /** To enable logging for this class. Set `VexFlow.Ornament.DEBUG` to `true`. */
31
- static DEBUG: boolean = false;
32
-
33
- /** Ornaments category string. */
34
- static get CATEGORY(): string {
35
- return Category.Ornament;
36
- }
37
- static get minPadding(): number {
38
- return Metrics.get('NoteHead.minPadding');
39
- }
40
-
41
- protected ornamentAlignWithNoteHead: string[] | boolean;
42
- protected type: string;
43
-
44
- protected delayed: boolean;
45
- protected adjustForStemDirection: boolean;
46
- public renderOptions: {
47
- accidentalUpperPadding: number;
48
- accidentalLowerPadding: number;
49
- };
50
- protected accidentalUpper?: Element;
51
- protected accidentalLower?: Element;
52
- protected delayXShift?: number;
53
-
54
- /** Arrange ornaments inside `ModifierContext` */
55
- static format(ornaments: Ornament[], state: ModifierContextState): boolean {
56
- if (!ornaments || ornaments.length === 0) return false;
57
-
58
- let width = 0; // width is used by ornaments, which are always centered on the note head
59
- let rightShift = state.rightShift; // jazz ornaments calculate r/l shift separately
60
- let leftShift = state.leftShift;
61
-
62
- for (let i = 0; i < ornaments.length; ++i) {
63
- const ornament = ornaments[i];
64
- const increment = 2;
65
-
66
- if (ornament.position === ModifierPosition.RIGHT) {
67
- ornament.xShift += rightShift + 2;
68
- rightShift += ornament.width + Ornament.minPadding;
69
- } else if (ornament.position === ModifierPosition.LEFT) {
70
- ornament.xShift -= leftShift + ornament.width + 2;
71
- leftShift += ornament.width + Ornament.minPadding;
72
- } else if (ornament.position === ModifierPosition.ABOVE) {
73
- width = Math.max(ornament.getWidth(), width);
74
- const note = ornament.getNote() as StemmableNote;
75
- let curTop = note.getLineNumber(true) + state.topTextLine;
76
- const stem = note.getStem();
77
- if (stem && note.getStemDirection() === Stem.UP) {
78
- curTop += Math.abs(stem.getHeight()) / Tables.STAVE_LINE_DISTANCE;
79
- }
80
- const numLines = note.getStave()?.getNumLines() ?? 0;
81
- // make sure that the ornaments stay above the staff
82
- if (curTop < numLines) state.topTextLine += numLines - curTop;
83
- ornament.setTextLine(state.topTextLine);
84
- state.topTextLine += increment;
85
- } else {
86
- width = Math.max(ornament.getWidth(), width);
87
- ornament.setTextLine(state.textLine);
88
- state.textLine += increment;
89
- }
90
- }
91
-
92
- // Note: 'legit' ornaments don't consider other modifiers when calculating their
93
- // X position, but jazz ornaments sometimes need to.
94
- state.leftShift = leftShift + width / 2;
95
- state.rightShift = rightShift + width / 2;
96
- return true;
97
- }
98
-
99
- /**
100
- * ornamentNoteTransition means the jazz ornament represents an effect from one note to another,
101
- * these are generally on the top of the staff.
102
- */
103
- static get ornamentNoteTransition(): string[] {
104
- return ['flip', 'jazzTurn', 'smear'];
105
- }
106
-
107
- /**
108
- * ornamentAttack indicates something that happens in the attach, placed before the note and
109
- * any accidentals
110
- */
111
- static get ornamentAttack(): string[] {
112
- return ['scoop'];
113
- }
114
-
115
- /**
116
- * The ornament is aligned based on the note head, but without regard to whether the
117
- * stem goes up or down.
118
- */
119
- static get ornamentAlignWithNoteHead(): string[] {
120
- return ['doit', 'fall', 'fallLong', 'doitLong', 'scoop'];
121
- }
122
-
123
- /**
124
- * An ornament that happens on the release of the note, generally placed after the
125
- * note and overlapping the next beat/measure..
126
- */
127
- static get ornamentRelease(): string[] {
128
- return ['doit', 'fall', 'fallLong', 'doitLong', 'jazzTurn', 'smear', 'flip'];
129
- }
130
-
131
- static get ornamentLeft(): string[] {
132
- return ['scoop'];
133
- }
134
-
135
- static get ornamentRight(): string[] {
136
- return ['doit', 'fall', 'fallLong', 'doitLong'];
137
- }
138
-
139
- static get ornamentYShift(): string[] {
140
- return ['fallLong'];
141
- }
142
-
143
- /** ornamentArticulation goes above/below the note based on space availablity */
144
- static get ornamentArticulation(): string[] {
145
- return ['bend', 'plungerClosed', 'plungerOpen'];
146
- }
147
-
148
- /**
149
- * Create a new ornament of type `type`, which is an entry in
150
- * `VexFlow.ornamentCodes` in `tables.ts`.
151
- */
152
- constructor(type: string) {
153
- super();
154
-
155
- // Default position ABOVE
156
- this.position = ModifierPosition.ABOVE;
157
- if (Ornament.ornamentRight.indexOf(type) >= 0) {
158
- this.position = ModifierPosition.RIGHT;
159
- }
160
- if (Ornament.ornamentLeft.indexOf(type) >= 0) {
161
- this.position = ModifierPosition.LEFT;
162
- }
163
- this.type = type;
164
- this.delayed = false;
165
-
166
- this.renderOptions = {
167
- accidentalLowerPadding: 3,
168
- accidentalUpperPadding: 3,
169
- };
170
-
171
- // some jazz ornaments are above or below depending on stem direction.
172
- this.adjustForStemDirection = false;
173
-
174
- this.ornamentAlignWithNoteHead = Ornament.ornamentAlignWithNoteHead.indexOf(this.type) >= 0;
175
-
176
- // Is this a jazz ornament that goes between this note and the next note.
177
- if (Ornament.ornamentNoteTransition.indexOf(this.type) >= 0) {
178
- this.delayed = true;
179
- }
180
-
181
- this.text = Tables.ornamentCodes(this.type);
182
- }
183
-
184
- /** Set note attached to ornament. */
185
- setNote(note: Note): this {
186
- super.setNote(note);
187
- // articulations above/below the line can be stacked.
188
- if (Ornament.ornamentArticulation.indexOf(this.type) >= 0) {
189
- // Unfortunately we don't know the stem direction. So we base it
190
- // on the line number, but also allow it to be overridden.
191
- if (note.getLineNumber() >= 3) {
192
- this.position = Modifier.Position.ABOVE;
193
- } else {
194
- this.position = Modifier.Position.BELOW;
195
- }
196
- }
197
- return this;
198
- }
199
-
200
- /** Set whether the ornament is to be delayed. */
201
- setDelayed(delayed: boolean): this {
202
- this.delayed = delayed;
203
- return this;
204
- }
205
-
206
- /** Set the upper accidental for the ornament. */
207
- setUpperAccidental(accid: string): this {
208
- this.accidentalUpper = new Element();
209
- this.accidentalUpper.setText(Tables.accidentalCodes(accid));
210
- return this;
211
- }
212
-
213
- /** Set the lower accidental for the ornament. */
214
- setLowerAccidental(accid: string): this {
215
- this.accidentalLower = new Element();
216
- this.accidentalLower.setText(Tables.accidentalCodes(accid));
217
- return this;
218
- }
219
-
220
- /** Render ornament in position next to note. */
221
- draw(): void {
222
- const ctx = this.checkContext();
223
- const note = this.checkAttachedNote() as StemmableNote;
224
- this.setRendered();
225
-
226
- const stave = note.checkStave();
227
-
228
- this.applyStyle();
229
- ctx.openGroup('ornament', this.getAttribute('id'));
230
-
231
- // Get initial coordinates for the modifier position
232
- const start = note.getModifierStartXY(this.position, this.index);
233
- let glyphX = start.x;
234
-
235
- const staffSpace = stave.getSpacingBetweenLines();
236
- const initialOffset = getInitialOffset(note, this.position);
237
-
238
- // If the ornament is aligned with the note head, don't consider the stave y
239
- // but use the 'natural' modifier y
240
- let glyphY = this.ornamentAlignWithNoteHead ? start.y : 0;
241
- if (this.position === ModifierPosition.ABOVE) {
242
- glyphY = getTopY(note, this.textLine) - (this.textLine + initialOffset) * staffSpace;
243
- }
244
- if (this.position === ModifierPosition.BELOW) {
245
- glyphY = getBottomY(note, this.textLine) + (this.textLine + initialOffset + 1.5) * staffSpace;
246
- }
247
-
248
- // Ajdust x position if ornament is delayed
249
- if (this.delayed) {
250
- let delayXShift = 0;
251
- const startX = note.getTickContext().getX();
252
- if (this.delayXShift !== undefined) {
253
- delayXShift = this.delayXShift;
254
- } else {
255
- const tickables = note.getVoice().getTickables();
256
- const index = tickables.indexOf(note);
257
- const nextContext = index + 1 < tickables.length ? tickables[index + 1].checkTickContext() : undefined;
258
- if (nextContext) {
259
- delayXShift += (nextContext.getX() - startX) * 0.5;
260
- } else {
261
- delayXShift += (stave.getX() + stave.getWidth() - glyphX) * 0.5;
262
- }
263
- this.delayXShift = delayXShift;
264
- }
265
- glyphX += delayXShift;
266
- }
267
-
268
- L('Rendering ornament: ', this.text.charCodeAt(0), glyphX, glyphY);
269
- if (this.accidentalLower) {
270
- this.accidentalLower.renderText(
271
- ctx,
272
- glyphX + this.xShift - this.accidentalLower.getWidth() * 0.5,
273
- glyphY + this.yShift - this.accidentalLower.getTextMetrics().actualBoundingBoxDescent
274
- );
275
- glyphY -= this.accidentalLower.getHeight() + this.renderOptions.accidentalLowerPadding;
276
- }
277
-
278
- // ornament requires yShift
279
- if (Ornament.ornamentYShift.indexOf(this.type) >= 0) {
280
- this.yShift += this.getHeight();
281
- }
282
-
283
- this.x =
284
- glyphX -
285
- (this.position === ModifierPosition.ABOVE || this.position === ModifierPosition.BELOW ? this.width * 0.5 : 0);
286
- this.y = glyphY;
287
-
288
- this.renderText(ctx, 0, 0);
289
-
290
- if (this.accidentalUpper) {
291
- glyphY -= this.getHeight() + this.renderOptions.accidentalUpperPadding;
292
- this.accidentalUpper.renderText(
293
- ctx,
294
- glyphX + this.xShift - this.accidentalUpper.getWidth() * 0.5,
295
- glyphY + this.yShift - this.accidentalUpper.getTextMetrics().actualBoundingBoxDescent
296
- );
297
- }
298
- ctx.closeGroup();
299
- this.restoreStyle();
300
- }
301
- }
@@ -1,89 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- // @author Rodrigo Vilar
3
- // MIT License
4
-
5
- import { Modifier, ModifierPosition } from './modifier';
6
- import { ModifierContextState } from './modifiercontext';
7
- import { Note } from './note';
8
- import { Category } from './typeguard';
9
-
10
- /** Parenthesis implements parenthesis modifiers for notes. */
11
- export class Parenthesis extends Modifier {
12
- static get CATEGORY(): string {
13
- return Category.Parenthesis;
14
- }
15
-
16
- /** Add parentheses to the notes. */
17
- static buildAndAttach(notes: Note[]): void {
18
- for (const note of notes) {
19
- for (let i = 0; i < note.keys.length; i++) {
20
- note.addModifier(new Parenthesis(ModifierPosition.LEFT), i);
21
- note.addModifier(new Parenthesis(ModifierPosition.RIGHT), i);
22
- }
23
- }
24
- }
25
-
26
- /** Arrange parentheses inside a ModifierContext. */
27
- static format(parentheses: Parenthesis[], state: ModifierContextState): boolean {
28
- if (!parentheses || parentheses.length === 0) return false;
29
-
30
- let xWidthL = 0;
31
- let xWidthR = 0;
32
-
33
- for (let i = 0; i < parentheses.length; ++i) {
34
- const parenthesis = parentheses[i];
35
- const note = parenthesis.getNote();
36
- const pos = parenthesis.getPosition();
37
- const index = parenthesis.checkIndex();
38
-
39
- let shift = 0;
40
-
41
- if (pos === ModifierPosition.RIGHT) {
42
- shift = note.getRightParenthesisPx(index);
43
- xWidthR = xWidthR > shift + parenthesis.width ? xWidthR : shift + parenthesis.width;
44
- }
45
- if (pos === ModifierPosition.LEFT) {
46
- shift = note.getLeftParenthesisPx(index) + parenthesis.width;
47
- xWidthL = xWidthL > shift + parenthesis.width ? xWidthL : shift + parenthesis.width;
48
- }
49
- parenthesis.setXShift(shift);
50
- }
51
- state.leftShift += xWidthL;
52
- state.rightShift += xWidthR;
53
-
54
- return true;
55
- }
56
-
57
- /**
58
- * Constructor
59
- *
60
- * @param position Modifier.Position.LEFT (default) or Modifier.Position.RIGHT
61
- */
62
- constructor(position: ModifierPosition) {
63
- super();
64
-
65
- this.position = position ?? Modifier.Position.LEFT;
66
- if (this.position === Modifier.Position.RIGHT) {
67
- this.text = '\uE0F6'; /*noteheadParenthesisRight*/
68
- } else if (this.position === Modifier.Position.LEFT) {
69
- this.text = '\uE0F5'; /*noteheadParenthesisLeft*/
70
- }
71
- }
72
-
73
- /** Set the associated note. */
74
- setNote(note: Note): this {
75
- this.note = note;
76
- this.setFont(note.getFont());
77
- return this;
78
- }
79
-
80
- /** Render the parenthesis. */
81
- draw(): void {
82
- const ctx = this.checkContext();
83
- const note = this.checkAttachedNote();
84
- this.setRendered();
85
-
86
- const start = note.getModifierStartXY(this.position, this.index, { forceFlagRight: true });
87
- this.renderText(ctx, start.x, start.y);
88
- }
89
- }