-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathindex.d.ts
400 lines (350 loc) · 11.3 KB
/
index.d.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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
declare module "midi-player-js" {
namespace MidiInternal {
interface Event {
name:
| "Sequence Number"
| "Text Event"
| "Copyright Notice"
| "Sequence/Track Name"
| "Instrument Name"
| "Lyric"
| "Marker"
| "Cue Point"
| "Device Name"
| "MIDI Channel Prefix"
| "MIDI Port"
| "End of Track"
| "Set Tempo"
| "SMTPE Offset"
| "Time Signature"
| "Key Signature"
| "Sequencer-Specific Meta-event"
| "Sysex"
| "Note off"
| "Note on"
| "Polyphonic Key Pressure"
| "Controller Change"
| "Program Change"
| "Channel Key Pressure"
| "Pitch Bend"
| string;
track: number;
tick: number;
byteIndex: number;
string?: string;
data?: number;
tempo?: number;
running?: boolean;
noteNumber?: number;
noteName?: string;
note?: string;
velocity?: number;
channel?: number;
pressure?: number;
/**
* Controller change number
*/
number?: number;
/**
* Controller change value
*/
value?: number;
}
type PlayerEventType =
| "midiEvent"
| "endOfFile"
| "playing"
| "fileLoaded";
class Track {
/**
* The events parsed out of a track
*
* @type {Event[]}
* @memberof Track
*/
events: Event[];
/**
* Resets all stateful track information used during playback.
*
* @returns {this}
* @memberof Track
*/
reset(): this;
/**
* Sets this track to be enabled during playback.
* @return {this}
*/
enable(): this;
/**
* Sets this track to be disabled during playback.
* @return {this}
*/
disable(): this;
/**
* Sets the track event index to the nearest event to the given tick.
* @param {number} tick
* @return {this}
*/
setEventIndexByTick(tick: number): this;
/**
* Gets byte located at pointer position.
* @return {number}
*/
getCurrentByte(): number;
/**
* Gets count of delta bytes and current pointer position.
* @return {number}
*/
getDeltaByteCount(): number;
/**
* Get delta value at current pointer position.
* @return {number}
*/
getDelta(): number;
/**
* Handles event within a given track starting at specified index
* @param {number} currentTick
* @param {boolean} dryRun - If true events will be parsed and returned regardless of time.
*/
handleEvent(currentTick: number, dryRun?: boolean): void;
/**
* Get string data from event.
* @param {number} eventStartIndex
* @return {string}
*/
getStringData(eventStartIndex: number): string;
/**
* Parses event into JSON and advances pointer for the track
* @return {object}
*/
parseEvent(): Event;
/**
* Returns true if pointer has reached the end of the track.
* @param {boolean}
*/
endOfTrack(): boolean;
}
class Player {
constructor(callback?: Function);
/**
* Disables a track from playing.
*
* @param {number} trackNumber
* @returns {this}
* @memberof Player
*/
disableTrack(trackNumber: number): this;
/**
* Enables a track for playing.
*
* @param {number} trackNumber Track to enable.
* @returns {this}
*/
enableTrack(trackNumber: number): this;
/**
* Returns true if the player pointer has reached the end of the loaded MIDI file.
*
* Used in two ways:
*
* 1. If playing result is based on loaded JSON events.
* 2. If parsing (dryRun) it's based on the actual buffer length vs bytes processed.
*
* @returns {boolean}
* @memberof Player
*/
endOfFile(): boolean;
/**
* Number of events played up to this point.
*
* @returns {number}
* @memberof Player
*/
eventsPlayed(): number;
/**
* Parses file for necessary information and does a dry run to calculate
* total length. Populates this.events & this.totalTicks.
*/
fileLoaded(): this;
/**
* Loads quarter note division of loaded MIDI file.
*/
private getDivision(): this;
/**
* Loads MIDI file format for loaded file.
*/
private getFormat(): this;
/**
* Parses out tracks, places them in this.tracks and initializes this.pointers.
*/
private getTracks(): this;
getCurrentTick(): number;
/**
* Gets an array of events grouped by track.
*
* @returns {Event[]}
*/
getEvents(): Event[];
/**
* Get the size of the file.
*
* @returns {number} Size in bytes.
*/
getFilesize(): number;
/**
* Gets remaining percent of playback.
*/
getSongPercentRemaining(): number;
/**
* Gets remaining number of seconds in playback.
*/
getSongTimeRemaining(): number;
/**
* Gets song duration in seconds.
*/
getSongTime(): number;
/**
* Gets total number of events in the loaded MIDI file.
*/
getTotalEvents(): number;
/**
* Gets total number of ticks in the loaded MIDI file.
*/
getTotalTicks(): number;
/**
* Returns whether player is playing.
*/
isPlaying(): boolean;
/**
* Load an array buffer into the player.
*
* @param arrayBuffer Buffer to load.
*/
loadArrayBuffer(arrayBuffer: ArrayBuffer): this;
/**
* Load a data URI into the player.
*
* @param dataUri The URI to load.
*/
loadDataUri(dataUri: string): this;
/**
* Load a file into the player (Node.js only).
*
* @param {string} path Path to load.
* @returns {this}
*/
loadFile(path: string): this;
/**
* Subscribes events to listeners
*
* @param {PlayerEventType} playerEvent
* @param {Function} fn Callback
* @returns {this}
*/
on(playerEvent: PlayerEventType, fn: Function): this;
/**
* Pauses playback if playing.
*
* @returns {this}
*/
pause(): this;
/**
* Start playing loaded MIDI file if not already playing.
*
* @returns {this}
*/
play(): this;
/**
* The main play loop.
* @param dryRun Indicates whether or not this is being called simply for parsing purposes. Disregards timing if so.
*/
playLoop(dryRun?: boolean): void;
/**
* Resets play pointers for all tracks.
*
* @returns {this}
*/
resetTracks(): this;
/**
* Setter for startTime.
* @param {number} - UTC timestamp
*/
setStartTime(startTime: number): void;
/**
* Skips player pointer to specified percentage.
* @param {number} - Percent value in integer format.
* @return {this}
*/
skipToPercent(percent: number): this;
/**
* Skips player pointer to specified seconds.
* @param {number} - Seconds to skip to.
* @return {this}
*/
skipToSeconds(seconds: number): this;
/**
* Skips player pointer to specified tick.
* @param {number} - Tick to skip to.
* @return {this}
*/
skipToTick(tick: number): this;
/**
* Stops playback if playing.
* @return {Player}
*/
stop(): this;
/**
* Broadcasts event to trigger subscribed callbacks.
* @param {string} - Name of event.
* @param {any} - Data to be passed to subscriber callback.
* @return {Player}
*/
triggerPlayerEvent(playerEvent: string, data: any): this;
/**
* The tracks of the file.
*/
tracks: Track[] | undefined;
/**
* Song tempo
*
* @type {number}
*/
tempo: number;
/**
* Ticks per quarter note.
* @type {number}
*/
division: number;
/**
* Current tick
*/
tick: number;
/**
* MIDI File format.
*
* MIDI files come in 3 variations:
* - Format 0 which contains a single track.
* - Format 1 which contains one or more simultaneous tracks
* (i.e. all tracks are to be played simultaneously).
* - Format 2 which contains one or more independent tracks.
*/
format: number;
/**
* An array of the instrument numbers requested by Program Change.
*
* @type {number[]}
* @memberof Player
*/
instruments: number[];
}
}
interface MidiPlayerInterface {
Player: typeof MidiInternal.Player;
}
const MidiPlayer: MidiPlayerInterface;
namespace MidiPlayer {
export type Event = MidiInternal.Event;
export type Player = MidiInternal.Player;
export type Track = MidiInternal.Track;
}
export = MidiPlayer;
}