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
package/src/gracenote.ts DELETED
@@ -1,146 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
-
3
- import { StaveNote, StaveNoteStruct } from './stavenote';
4
- import { Stem } from './stem';
5
- import { Tables } from './tables';
6
- import { Category } from './typeguard';
7
- import { RuntimeError } from './util';
8
-
9
- export interface GraceNoteStruct extends StaveNoteStruct {
10
- slash?: boolean;
11
- }
12
-
13
- export class GraceNote extends StaveNote {
14
- static get CATEGORY(): string {
15
- return Category.GraceNote;
16
- }
17
-
18
- static get LEDGER_LINE_OFFSET(): number {
19
- return 2;
20
- }
21
-
22
- protected slash: boolean;
23
- protected slur: boolean;
24
-
25
- constructor(noteStruct: GraceNoteStruct) {
26
- super({
27
- strokePx: GraceNote.LEDGER_LINE_OFFSET,
28
- ...noteStruct,
29
- });
30
-
31
- this.slash = noteStruct.slash || false;
32
- this.slur = true;
33
-
34
- this.buildNoteHeads();
35
-
36
- this.width = 3;
37
- }
38
-
39
- getStemExtension(): number {
40
- if (this.stemExtensionOverride) {
41
- return this.stemExtensionOverride;
42
- }
43
-
44
- let ret = super.getStemExtension();
45
- ret = Stem.HEIGHT * this.getFontScale() - Stem.HEIGHT + ret;
46
- return ret;
47
- }
48
-
49
- draw(): void {
50
- super.draw();
51
- this.setRendered();
52
- const stem = this.stem;
53
- if (this.slash && stem) {
54
- const scale = this.getFontScale();
55
-
56
- let slashBBox = undefined;
57
- const beam = this.beam;
58
- if (beam) {
59
- // FIXME: should render slash after beam?
60
- if (!beam.postFormatted) {
61
- beam.postFormat();
62
- }
63
-
64
- slashBBox = this.calcBeamedNotesSlashBBox(8 * scale, 8 * scale, {
65
- stem: 6 * scale,
66
- beam: 5 * scale,
67
- });
68
- } else {
69
- const stemDirection = this.getStemDirection();
70
- const noteHeadBounds = this.getNoteHeadBounds();
71
- const noteHeadWidth = this.noteHeads[0].getWidth();
72
- const x = stemDirection === Stem.DOWN ? this.getAbsoluteX() : this.getAbsoluteX() + noteHeadWidth;
73
- const defaultOffsetY = (Tables.STEM_HEIGHT * scale) / 2;
74
- const y =
75
- stemDirection === Stem.DOWN ? noteHeadBounds.yBottom + defaultOffsetY : noteHeadBounds.yTop - defaultOffsetY;
76
-
77
- if (stemDirection === Stem.DOWN) {
78
- slashBBox = {
79
- x1: x - noteHeadWidth,
80
- y1: y - noteHeadWidth,
81
- x2: x + noteHeadWidth,
82
- y2: y + noteHeadWidth,
83
- };
84
- } else {
85
- slashBBox = {
86
- x1: x - noteHeadWidth,
87
- y1: y + noteHeadWidth,
88
- x2: x + noteHeadWidth,
89
- y2: y - noteHeadWidth,
90
- };
91
- }
92
- }
93
-
94
- // FIXME: avoid staff lines, ledger lines or others.
95
-
96
- const ctx = this.checkContext();
97
- ctx.save();
98
- ctx.setLineWidth(1 * scale); // FIXME: use more appropriate value.
99
- ctx.beginPath();
100
- ctx.moveTo(slashBBox.x1, slashBBox.y1);
101
- ctx.lineTo(slashBBox.x2, slashBBox.y2);
102
- ctx.closePath();
103
- ctx.stroke();
104
- ctx.restore();
105
- }
106
- }
107
-
108
- calcBeamedNotesSlashBBox(
109
- slashStemOffset: number,
110
- slashBeamOffset: number,
111
- protrusions: { beam: number; stem: number }
112
- ): Record<string, number> {
113
- const beam = this.beam;
114
- if (!beam) throw new RuntimeError('NoBeam', "Can't calculate without a beam.");
115
-
116
- const beamSlope = beam.slope;
117
- const isBeamEndNote = beam.notes[beam.notes.length - 1] === this;
118
- const scaleX = isBeamEndNote ? -1 : 1;
119
- const beamAngle = Math.atan(beamSlope * scaleX);
120
-
121
- // slash line intersecting point on beam.
122
- const iPointOnBeam = {
123
- dx: Math.cos(beamAngle) * slashBeamOffset,
124
- dy: Math.sin(beamAngle) * slashBeamOffset,
125
- };
126
-
127
- slashStemOffset *= this.getStemDirection();
128
- const slashAngle = Math.atan((iPointOnBeam.dy - slashStemOffset) / iPointOnBeam.dx);
129
- const protrusionStemDeltaX = Math.cos(slashAngle) * protrusions.stem * scaleX;
130
- const protrusionStemDeltaY = Math.sin(slashAngle) * protrusions.stem;
131
- const protrusionBeamDeltaX = Math.cos(slashAngle) * protrusions.beam * scaleX;
132
- const protrusionBeamDeltaY = Math.sin(slashAngle) * protrusions.beam;
133
-
134
- const stemX = this.getStemX();
135
- const stem0X = beam.notes[0].getStemX();
136
- const stemY = beam.getBeamYToDraw() + (stemX - stem0X) * beamSlope;
137
-
138
- const ret = {
139
- x1: stemX - protrusionStemDeltaX,
140
- y1: stemY + slashStemOffset - protrusionStemDeltaY,
141
- x2: stemX + iPointOnBeam.dx * scaleX + protrusionBeamDeltaX,
142
- y2: stemY + iPointOnBeam.dy + protrusionBeamDeltaY,
143
- };
144
- return ret;
145
- }
146
- }
@@ -1,194 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- //
3
- // ## Description
4
- //
5
- // This file implements `GraceNoteGroup` which is used to format and
6
- // render grace notes.
7
-
8
- import { Beam } from './beam';
9
- import { Formatter } from './formatter';
10
- import { Modifier } from './modifier';
11
- import { ModifierContextState } from './modifiercontext';
12
- import { Note } from './note';
13
- import { RenderContext } from './rendercontext';
14
- import { StaveNote } from './stavenote';
15
- import { StaveTie } from './stavetie';
16
- import { StemmableNote } from './stemmablenote';
17
- import { Tables } from './tables';
18
- import { TabTie } from './tabtie';
19
- import { Category, isStaveNote } from './typeguard';
20
- import { log } from './util';
21
- import { Voice } from './voice';
22
-
23
- // To enable logging for this class. Set `GraceNoteGroup.DEBUG` to `true`.
24
- // eslint-disable-next-line
25
- function L(...args: any) {
26
- if (GraceNoteGroup.DEBUG) log('VexFlow.GraceNoteGroup', args);
27
- }
28
-
29
- /** GraceNoteGroup is used to format and render grace notes. */
30
- export class GraceNoteGroup extends Modifier {
31
- static DEBUG: boolean = false;
32
-
33
- static get CATEGORY(): string {
34
- return Category.GraceNoteGroup;
35
- }
36
-
37
- protected readonly voice: Voice;
38
- protected readonly graceNotes: StemmableNote[];
39
- protected readonly showSlur?: boolean;
40
-
41
- protected preFormatted: boolean = false;
42
- protected formatter?: Formatter;
43
- public renderOptions: { slurYShift: number };
44
- protected slur?: StaveTie | TabTie;
45
- protected beams: Beam[];
46
-
47
- /** Arranges groups inside a `ModifierContext`. */
48
- static format(gracenoteGroups: GraceNoteGroup[], state: ModifierContextState): boolean {
49
- const groupSpacingStave = 4;
50
- const groupSpacingTab = 0;
51
-
52
- if (!gracenoteGroups || gracenoteGroups.length === 0) return false;
53
-
54
- const groupList = [];
55
- let prevNote = null;
56
- let shiftL = 0;
57
-
58
- for (let i = 0; i < gracenoteGroups.length; ++i) {
59
- const gracenoteGroup = gracenoteGroups[i];
60
- const note = gracenoteGroup.getNote();
61
- const isStavenote = isStaveNote(note);
62
- const spacing = isStavenote ? groupSpacingStave : groupSpacingTab;
63
-
64
- if (isStavenote && note !== prevNote) {
65
- // Iterate through all notes to get the displaced pixels
66
- for (let n = 0; n < note.keys.length; ++n) {
67
- shiftL = Math.max(note.getLeftDisplacedHeadPx(), shiftL);
68
- }
69
- prevNote = note;
70
- }
71
-
72
- groupList.push({ shift: shiftL, gracenoteGroup, spacing });
73
- }
74
-
75
- // If first note left shift in case it is displaced
76
- let groupShift = groupList[0].shift;
77
- let formatWidth;
78
- for (let i = 0; i < groupList.length; ++i) {
79
- const gracenoteGroup = groupList[i].gracenoteGroup;
80
- gracenoteGroup.preFormat();
81
- formatWidth = gracenoteGroup.getWidth() + groupList[i].spacing;
82
- groupShift = Math.max(formatWidth, groupShift);
83
- }
84
-
85
- for (let i = 0; i < groupList.length; ++i) {
86
- const gracenoteGroup = groupList[i].gracenoteGroup;
87
- formatWidth = gracenoteGroup.getWidth() + groupList[i].spacing;
88
- gracenoteGroup.setSpacingFromNextModifier(
89
- groupShift - Math.min(formatWidth, groupShift) + StaveNote.minNoteheadPadding
90
- );
91
- }
92
-
93
- state.leftShift += groupShift;
94
- return true;
95
- }
96
-
97
- //** `GraceNoteGroup` inherits from `Modifier` and is placed inside a `ModifierContext`. */
98
- constructor(graceNotes: StemmableNote[], showSlur?: boolean) {
99
- super();
100
-
101
- this.position = Modifier.Position.LEFT;
102
- this.graceNotes = graceNotes;
103
- this.width = 0;
104
-
105
- this.showSlur = showSlur;
106
- this.slur = undefined;
107
-
108
- this.voice = new Voice({
109
- numBeats: 4,
110
- beatValue: 4,
111
- resolution: Tables.RESOLUTION,
112
- }).setStrict(false);
113
-
114
- this.renderOptions = {
115
- slurYShift: 0,
116
- };
117
-
118
- this.beams = [];
119
-
120
- this.voice.addTickables(this.graceNotes);
121
-
122
- return this;
123
- }
124
-
125
- preFormat(): void {
126
- if (this.preFormatted) return;
127
-
128
- if (!this.formatter) {
129
- this.formatter = new Formatter();
130
- }
131
- this.formatter.joinVoices([this.voice]).format([this.voice], 0, {});
132
- this.setWidth(this.formatter.getMinTotalWidth());
133
- this.preFormatted = true;
134
- }
135
-
136
- beamNotes(graceNotes?: StemmableNote[]): this {
137
- graceNotes = graceNotes || this.graceNotes;
138
- if (graceNotes.length > 1) {
139
- const beam = new Beam(graceNotes);
140
-
141
- beam.renderOptions.beamWidth = 3;
142
- beam.renderOptions.partialBeamLength = 4;
143
-
144
- this.beams.push(beam);
145
- }
146
-
147
- return this;
148
- }
149
-
150
- setWidth(width: number): this {
151
- this.width = width;
152
- return this;
153
- }
154
-
155
- getWidth(): number {
156
- return this.width + StaveNote.minNoteheadPadding;
157
- }
158
-
159
- getGraceNotes(): Note[] {
160
- return this.graceNotes;
161
- }
162
-
163
- draw(): void {
164
- const ctx: RenderContext = this.checkContext();
165
- const note = this.checkAttachedNote();
166
- this.setRendered();
167
-
168
- L('Drawing grace note group for:', note);
169
-
170
- this.alignSubNotesWithNote(this.getGraceNotes(), note); // Modifier function
171
-
172
- // Draw grace notes.
173
- this.graceNotes.forEach((graceNote) => graceNote.setContext(ctx).draw());
174
- // Draw beams.
175
- this.beams.forEach((beam) => beam.setContext(ctx).draw());
176
-
177
- if (this.showSlur) {
178
- // Create and draw slur.
179
- const isStavenote = isStaveNote(note);
180
- const TieClass = isStavenote ? StaveTie : TabTie;
181
-
182
- this.slur = new TieClass({
183
- lastNote: this.graceNotes[0],
184
- firstNote: note,
185
- firstIndexes: [0],
186
- lastIndexes: [0],
187
- });
188
-
189
- this.slur.renderOptions.cp2 = 12;
190
- this.slur.renderOptions.yShift = (isStavenote ? 7 : 5) + this.renderOptions.slurYShift;
191
- this.slur.setContext(ctx).draw();
192
- }
193
- }
194
- }
@@ -1,30 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- // @author Balazs Forian-Szabo
3
- //
4
- // ## Description
5
- //
6
- // A basic implementation of grace notes
7
- // to be rendered on a tab stave.
8
- //
9
- // See `tests/gracetabnote_tests.ts` for usage examples.
10
-
11
- import { TabNote, TabNoteStruct } from './tabnote';
12
- import { Category } from './typeguard';
13
-
14
- export class GraceTabNote extends TabNote {
15
- static get CATEGORY(): string {
16
- return Category.GraceTabNote;
17
- }
18
-
19
- constructor(noteStruct: TabNoteStruct) {
20
- super(noteStruct, false);
21
-
22
- this.renderOptions = {
23
- ...this.renderOptions,
24
- // vertical shift from stave line
25
- yShift: 0.3,
26
- };
27
-
28
- this.updateWidth();
29
- }
30
- }
package/src/index.ts DELETED
@@ -1,90 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- // MIT License
3
-
4
- export * from './accidental';
5
- export * from './annotation';
6
- export * from './articulation';
7
- export * from './barnote';
8
- export * from './beam';
9
- export * from './bend';
10
- export * from './boundingbox';
11
- export * from './canvascontext';
12
- export * from './chordsymbol';
13
- export * from './clef';
14
- export * from './clefnote';
15
- export * from './crescendo';
16
- export * from './curve';
17
- export * from './dot';
18
- export * from './easyscore';
19
- export * from './element';
20
- export * from './factory';
21
- export * from './font';
22
- // Do not export './fonts/*' because they are used by the entry/* files.
23
- export * from './formatter';
24
- export * from './fraction';
25
- export * from './frethandfinger';
26
- export * from './ghostnote';
27
- export * from './glyphnote';
28
- export * from './gracenote';
29
- export * from './gracenotegroup';
30
- export * from './gracetabnote';
31
- export * from './keymanager';
32
- export * from './keysignature';
33
- export * from './keysignote';
34
- export * from './modifier';
35
- export * from './modifiercontext';
36
- export * from './multimeasurerest';
37
- export * from './music';
38
- export * from './note';
39
- export * from './notehead';
40
- export * from './notesubgroup';
41
- export * from './ornament';
42
- export * from './parenthesis';
43
- export * from './parser';
44
- export * from './pedalmarking';
45
- export * from './registry';
46
- export * from './rendercontext';
47
- export * from './renderer';
48
- export * from './repeatnote';
49
- export * from './stave';
50
- export * from './stavebarline';
51
- export * from './staveconnector';
52
- export * from './stavehairpin';
53
- export * from './staveline';
54
- export * from './stavemodifier';
55
- export * from './stavenote';
56
- export * from './staverepetition';
57
- export * from './stavesection';
58
- export * from './stavetempo';
59
- export * from './stavetext';
60
- export * from './stavetie';
61
- export * from './stavevolta';
62
- export * from './stem';
63
- export * from './stemmablenote';
64
- export * from './stringnumber';
65
- export * from './strokes';
66
- export * from './svgcontext';
67
- export * from './system';
68
- // Do not export './tables' because it is internal. Its public API is accessible via VexFlow.*.
69
- export * from './tabnote';
70
- export * from './tabslide';
71
- export * from './tabstave';
72
- export * from './tabtie';
73
- export * from './textbracket';
74
- export * from './textdynamics';
75
- export * from './textnote';
76
- export * from './tickable';
77
- export * from './tickcontext';
78
- export * from './timesignature';
79
- export * from './timesignote';
80
- export * from './tremolo';
81
- export * from './tuning';
82
- export * from './tuplet';
83
- export * from './typeguard';
84
- export * from './util';
85
- // Do not export './version'. It is accessible via VexFlow.BUILD.
86
- export * from './vexflow';
87
- export * from './vibrato';
88
- export * from './vibratobracket';
89
- export * from './voice';
90
- export * from './web';
package/src/keymanager.ts DELETED
@@ -1,153 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- //
3
- // ## Description
4
- //
5
- // This class implements diatonic key management.
6
-
7
- import { KeyParts, Music } from './music';
8
- import { RuntimeError } from './util';
9
-
10
- export class KeyManager {
11
- protected music: Music;
12
- // all attributes below are initialised in setKey which calls reset in the constructor
13
- protected keyParts!: KeyParts;
14
- protected keyString!: string;
15
- protected key!: string;
16
- protected scale!: number[];
17
- protected scaleMap!: Record<string, string>;
18
- protected scaleMapByValue!: Record<number, string>;
19
- protected originalScaleMapByValue!: Record<number, string>;
20
-
21
- constructor(key: string) {
22
- this.music = new Music();
23
- this.setKey(key);
24
- }
25
-
26
- setKey(key: string): this {
27
- this.key = key;
28
- this.reset();
29
- return this;
30
- }
31
-
32
- getKey(): string {
33
- return this.key;
34
- }
35
-
36
- reset(): this {
37
- this.keyParts = this.music.getKeyParts(this.key);
38
-
39
- this.keyString = this.keyParts.root;
40
- if (this.keyParts.accidental) this.keyString += this.keyParts.accidental;
41
-
42
- const isSupportedType = Music.scaleTypes[this.keyParts.type];
43
- if (!isSupportedType) {
44
- throw new RuntimeError('BadArguments', `Unsupported key type: ${this.key}`);
45
- }
46
-
47
- this.scale = this.music.getScaleTones(
48
- this.music.getNoteValue(this.keyString),
49
- Music.scaleTypes[this.keyParts.type]
50
- );
51
-
52
- this.scaleMap = {};
53
- this.scaleMapByValue = {};
54
- this.originalScaleMapByValue = {};
55
-
56
- const noteLocation = Music.rootIndexes[this.keyParts.root];
57
-
58
- for (let i = 0; i < Music.roots.length; ++i) {
59
- const index = (noteLocation + i) % Music.roots.length;
60
- const rootName = Music.roots[index];
61
-
62
- const noteName = this.music.getRelativeNoteName(rootName, this.scale[i]);
63
- this.scaleMap[rootName] = noteName;
64
- this.scaleMapByValue[this.scale[i]] = noteName;
65
- this.originalScaleMapByValue[this.scale[i]] = noteName;
66
- }
67
-
68
- return this;
69
- }
70
-
71
- getAccidental(key: string): {
72
- note: string;
73
- accidental?: string;
74
- change?: boolean;
75
- } {
76
- const root = this.music.getKeyParts(key).root;
77
- const parts = this.music.getNoteParts(this.scaleMap[root]);
78
-
79
- return {
80
- note: this.scaleMap[root],
81
- accidental: parts.accidental,
82
- };
83
- }
84
-
85
- selectNote(note: string): {
86
- note: string;
87
- accidental?: string;
88
- change: boolean;
89
- } {
90
- note = note.toLowerCase();
91
- const parts = this.music.getNoteParts(note);
92
-
93
- // First look for matching note in our altered scale
94
- const scaleNote = this.scaleMap[parts.root];
95
- const modparts = this.music.getNoteParts(scaleNote);
96
-
97
- if (scaleNote === note) {
98
- return {
99
- note: scaleNote,
100
- accidental: parts.accidental,
101
- change: false,
102
- };
103
- }
104
-
105
- // Then search for a note of equivalent value in our altered scale
106
- const valueNote = this.scaleMapByValue[this.music.getNoteValue(note)];
107
- if (valueNote !== undefined) {
108
- return {
109
- note: valueNote,
110
- accidental: this.music.getNoteParts(valueNote).accidental,
111
- change: false,
112
- };
113
- }
114
-
115
- // Then search for a note of equivalent value in the original scale
116
- const originalValueNote = this.originalScaleMapByValue[this.music.getNoteValue(note)];
117
- if (originalValueNote !== undefined) {
118
- this.scaleMap[modparts.root] = originalValueNote;
119
- delete this.scaleMapByValue[this.music.getNoteValue(scaleNote)];
120
- this.scaleMapByValue[this.music.getNoteValue(note)] = originalValueNote;
121
- return {
122
- note: originalValueNote,
123
- accidental: this.music.getNoteParts(originalValueNote).accidental,
124
- change: true,
125
- };
126
- }
127
-
128
- // Then try to unmodify a currently modified note.
129
- if (modparts.root === note) {
130
- delete this.scaleMapByValue[this.music.getNoteValue(this.scaleMap[parts.root])];
131
- this.scaleMapByValue[this.music.getNoteValue(modparts.root)] = modparts.root;
132
- this.scaleMap[modparts.root] = modparts.root;
133
- return {
134
- note: modparts.root,
135
- accidental: undefined,
136
- change: true,
137
- };
138
- }
139
-
140
- // Last resort -- shitshoot
141
- delete this.scaleMapByValue[this.music.getNoteValue(this.scaleMap[parts.root])];
142
- this.scaleMapByValue[this.music.getNoteValue(note)] = note;
143
-
144
- delete this.scaleMap[modparts.root];
145
- this.scaleMap[modparts.root] = note;
146
-
147
- return {
148
- note,
149
- accidental: parts.accidental,
150
- change: true,
151
- };
152
- }
153
- }