-
Notifications
You must be signed in to change notification settings - Fork 666
/
flow.ts
314 lines (307 loc) · 10.7 KB
/
flow.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
import { Accidental } from './accidental';
import { Annotation } from './annotation';
import { Articulation } from './articulation';
import { BarNote } from './barnote';
import { Beam } from './beam';
import { Bend } from './bend';
import { BoundingBox } from './boundingbox';
import { BoundingBoxComputation } from './boundingboxcomputation';
import { CanvasContext } from './canvascontext';
import { ChordSymbol } from './chordsymbol';
import { Clef } from './clef';
import { ClefNote } from './clefnote';
import { Crescendo } from './crescendo';
import { Curve } from './curve';
import { Dot } from './dot';
import { EasyScore } from './easyscore';
import { Element } from './element';
import { Factory } from './factory';
import { Font, FontModule } from './font';
import { Formatter } from './formatter';
import { Fraction } from './fraction';
import { FretHandFinger } from './frethandfinger';
import { GhostNote } from './ghostnote';
import { Glyph } from './glyph';
import { GlyphNote } from './glyphnote';
import { GraceNote } from './gracenote';
import { GraceNoteGroup } from './gracenotegroup';
import { GraceTabNote } from './gracetabnote';
import { KeyManager } from './keymanager';
import { KeySignature } from './keysignature';
import { KeySigNote } from './keysignote';
import { Modifier, ModifierPosition } from './modifier';
import { ModifierContext } from './modifiercontext';
import { MultiMeasureRest } from './multimeasurerest';
import { Music } from './music';
import { Note } from './note';
import { NoteHead } from './notehead';
import { NoteSubGroup } from './notesubgroup';
import { Ornament } from './ornament';
import { Parenthesis } from './parenthesis';
import { Parser } from './parser';
import { PedalMarking } from './pedalmarking';
import { Registry } from './registry';
import { RenderContext } from './rendercontext';
import { Renderer } from './renderer';
import { RepeatNote } from './repeatnote';
import { Stave } from './stave';
import { Barline, BarlineType } from './stavebarline';
import { StaveConnector } from './staveconnector';
import { StaveHairpin } from './stavehairpin';
import { StaveLine } from './staveline';
import { StaveModifier } from './stavemodifier';
import { StaveNote } from './stavenote';
import { Repetition } from './staverepetition';
import { StaveTempo } from './stavetempo';
import { StaveText } from './stavetext';
import { StaveTie } from './stavetie';
import { Volta } from './stavevolta';
import { Stem } from './stem';
import { StringNumber } from './stringnumber';
import { Stroke } from './strokes';
import { SVGContext } from './svgcontext';
import { System } from './system';
import { Tables } from './tables';
import { TabNote } from './tabnote';
import { TabSlide } from './tabslide';
import { TabStave } from './tabstave';
import { TabTie } from './tabtie';
import { TextBracket } from './textbracket';
import { TextDynamics } from './textdynamics';
import { TextFormatter } from './textformatter';
import { TextNote } from './textnote';
import { TickContext } from './tickcontext';
import { TimeSignature } from './timesignature';
import { TimeSigNote } from './timesignote';
import { Tremolo } from './tremolo';
import { Tuning } from './tuning';
import { Tuplet } from './tuplet';
import { DATE, ID, VERSION } from './version';
import { Vibrato } from './vibrato';
import { VibratoBracket } from './vibratobracket';
import { Voice } from './voice';
export class Flow {
static get BUILD() {
return {
/** version number. */
VERSION: VERSION,
/** git commit ID that this library was built from. */
ID: ID,
/** The date when this library was compiled. */
DATE: DATE,
};
}
static Accidental = Accidental;
static Annotation = Annotation;
static Articulation = Articulation;
static Barline = Barline;
static BarNote = BarNote;
static Beam = Beam;
static Bend = Bend;
static BoundingBox = BoundingBox;
static BoundingBoxComputation = BoundingBoxComputation;
static CanvasContext = CanvasContext;
static ChordSymbol = ChordSymbol;
static Clef = Clef;
static ClefNote = ClefNote;
static Crescendo = Crescendo;
static Curve = Curve;
static Dot = Dot;
static EasyScore = EasyScore;
static Element = Element;
static Factory = Factory;
static get Flow() {
// This (circular reference) provides a handy shortcut for importing VexFlow via `require()`.
// For example:
// const Vex = require('vexflow');
// const { Flow, Stave, StaveNote, Formatter, Renderer } = Vex.Flow;
return Flow;
}
static Font = Font;
static Formatter = Formatter;
static Fraction = Fraction;
static FretHandFinger = FretHandFinger;
static GhostNote = GhostNote;
static Glyph = Glyph;
static GlyphNote = GlyphNote;
static GraceNote = GraceNote;
static GraceNoteGroup = GraceNoteGroup;
static GraceTabNote = GraceTabNote;
static KeyManager = KeyManager;
static KeySignature = KeySignature;
static KeySigNote = KeySigNote;
static Modifier = Modifier;
static ModifierContext = ModifierContext;
static MultiMeasureRest = MultiMeasureRest;
static Music = Music;
static Note = Note;
static NoteHead = NoteHead;
static NoteSubGroup = NoteSubGroup;
static Ornament = Ornament;
static Parenthesis = Parenthesis;
static Parser = Parser;
static PedalMarking = PedalMarking;
static Registry = Registry;
static RenderContext = RenderContext;
static Renderer = Renderer;
static RepeatNote = RepeatNote;
static Repetition = Repetition;
static Stave = Stave;
static StaveConnector = StaveConnector;
static StaveHairpin = StaveHairpin;
static StaveLine = StaveLine;
static StaveModifier = StaveModifier;
static StaveNote = StaveNote;
static StaveTempo = StaveTempo;
static StaveText = StaveText;
static StaveTie = StaveTie;
static Stem = Stem;
static StringNumber = StringNumber;
static Stroke = Stroke;
static SVGContext = SVGContext;
static System = System;
static TabNote = TabNote;
static TabSlide = TabSlide;
static TabStave = TabStave;
static TabTie = TabTie;
static TextBracket = TextBracket;
static TextDynamics = TextDynamics;
static TextFormatter = TextFormatter;
static TextNote = TextNote;
static TickContext = TickContext;
static TimeSignature = TimeSignature;
static TimeSigNote = TimeSigNote;
static Tremolo = Tremolo;
static Tuning = Tuning;
static Tuplet = Tuplet;
static Vibrato = Vibrato;
static VibratoBracket = VibratoBracket;
static Voice = Voice;
static Volta = Volta;
// enums need to be exported too!
static BarlineType = BarlineType;
static ModifierPosition = ModifierPosition;
// ... more to come ...
/**
* Examples:
* ```
* Vex.Flow.setMusicFont('Petaluma');
* Vex.Flow.setMusicFont('Bravura', 'Gonville');
* ```
*
* **CASE 1**: You are using `vexflow.js`, which includes all music fonts (Bravura, Gonville, Petaluma, Custom).
* In this case, calling this method is optional, since VexFlow already defaults to a music font stack of:
* 'Bravura', 'Gonville', 'Custom'.
*
* **CASE 2**: You are using `vexflow-bravura.js` or `vexflow-petaluma.js` or `vexflow-gonville.js`,
* which includes a single music font. Calling this method is unnecessary.
*
* **CASE 3**: You are using the light weight `vexflow-core.js` to take advantage of lazy loading for fonts.
* In this case, the default music font stack is empty.
* Example:
* ```
* await Vex.Flow.fetchMusicFont('Petaluma');
* Vex.Flow.setMusicFont('Petaluma');
* ... (do VexFlow stuff) ...
* ```
* See `demos/fonts/` for more examples.
*
* @returns an array of Font objects corresponding to the provided `fontNames`.
*/
static setMusicFont(...fontNames: string[]): Font[] {
// Convert the array of font names into an array of Font objects.
const fonts = fontNames.map((fontName) => Font.load(fontName));
Tables.MUSIC_FONT_STACK = fonts;
Glyph.MUSIC_FONT_STACK = fonts.slice();
Glyph.CURRENT_CACHE_KEY = fontNames.join(',');
return fonts;
}
/**
* Used with vexflow-core which supports dynamic font loading.
*/
// eslint-disable-next-line
static async fetchMusicFont(fontName: string, fontModuleOrPath?: string | FontModule): Promise<void> {
// The default implementation does nothing.
// See vexflow-core.ts for the implementation that vexflow-core.js uses.
}
static getMusicFont(): string[] {
const fonts = Tables.MUSIC_FONT_STACK;
return fonts.map((font) => font.getName());
}
static get NOTATION_FONT_SCALE(): number {
return Tables.NOTATION_FONT_SCALE;
}
static set NOTATION_FONT_SCALE(value: number) {
Tables.NOTATION_FONT_SCALE = value;
}
static get TABLATURE_FONT_SCALE(): number {
return Tables.TABLATURE_FONT_SCALE;
}
static set TABLATURE_FONT_SCALE(value: number) {
Tables.TABLATURE_FONT_SCALE = value;
}
static get RESOLUTION(): number {
return Tables.RESOLUTION;
}
static set RESOLUTION(value: number) {
Tables.RESOLUTION = value;
}
static get SLASH_NOTEHEAD_WIDTH(): number {
return Tables.SLASH_NOTEHEAD_WIDTH;
}
static set SLASH_NOTEHEAD_WIDTH(value: number) {
Tables.SLASH_NOTEHEAD_WIDTH = value;
}
static get STAVE_LINE_DISTANCE(): number {
return Tables.STAVE_LINE_DISTANCE;
}
static set STAVE_LINE_DISTANCE(value: number) {
Tables.STAVE_LINE_DISTANCE = value;
}
static get STAVE_LINE_THICKNESS(): number {
return Tables.STAVE_LINE_THICKNESS;
}
static set STAVE_LINE_THICKNESS(value: number) {
Tables.STAVE_LINE_THICKNESS = value;
}
static get STEM_HEIGHT(): number {
return Tables.STEM_HEIGHT;
}
static set STEM_HEIGHT(value: number) {
Tables.STEM_HEIGHT = value;
}
static get STEM_WIDTH(): number {
return Tables.STEM_WIDTH;
}
static set STEM_WIDTH(value: number) {
Tables.STEM_WIDTH = value;
}
static get TIME4_4(): { num_beats: number; beat_value: number; resolution: number } {
return Tables.TIME4_4;
}
static get accidentalMap(): Record<string, { code: string; parenRightPaddingAdjustment: number }> {
return Tables.accidentalMap;
}
static get unicode(): Record<string, string> {
return Tables.unicode;
}
static keySignature(spec: string): { type: string; line: number }[] {
return Tables.keySignature(spec);
}
static hasKeySignature(spec: string): boolean {
return Tables.hasKeySignature(spec);
}
static getKeySignatures(): Record<string, { acc?: string; num: number }> {
return Tables.getKeySignatures();
}
static clefProperties(clef: string): { line_shift: number } {
return Tables.clefProperties(clef);
}
// eslint-disable-next-line
static keyProperties(key: string, clef?: string, params?: any): any {
return Tables.keyProperties(key, clef, params);
}
static durationToTicks(duration: string): number {
return Tables.durationToTicks(duration);
}
}