-
-
Notifications
You must be signed in to change notification settings - Fork 115
/
webmidi.d.ts
6607 lines (6317 loc) · 289 KB
/
webmidi.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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Type definitions for {{LIBRARY}} v{{VERSION}}
// Project: {{HOMEPAGE}}
// Definitions by: {{AUTHOR_NAME}} <{{AUTHOR_URL}}>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// The type definitions for the native 'Navigator' interface and 'WebMidiApi' namespace have been
// created by Toshiya Nakakura <https://github.com/nakakura>. I am copying them here until I figure
// out how to rename a TypeScript namespace upon import. The problem is that the original 'WebMidi'
// namespace collides with the 'WebMidi' object. So, I simply renamed the namespace to 'WebMidiApi'
// and adjusted the references accordingly.
interface Navigator {
/**
* When invoked, returns a Promise object representing a request for access to MIDI devices on the
* user's system.
*/
requestMIDIAccess(options?: WebMidiApi.MIDIOptions): Promise<WebMidiApi.MIDIAccess>;
}
declare namespace WebMidiApi {
interface MIDIOptions {
/**
* This member informs the system whether the ability to send and receive system
* exclusive messages is requested or allowed on a given MIDIAccess object.
*/
sysex: boolean;
}
/**
* This is a maplike interface whose value is a MIDIInput instance and key is its
* ID.
*/
type MIDIInputMap = Map<string, MIDIInput>;
/**
* This is a maplike interface whose value is a MIDIOutput instance and key is its
* ID.
*/
type MIDIOutputMap = Map<string, MIDIOutput>;
interface MIDIAccess extends EventTarget {
/**
* The MIDI input ports available to the system.
*/
inputs: MIDIInputMap;
/**
* The MIDI output ports available to the system.
*/
outputs: MIDIOutputMap;
/**
* The handler called when a new port is connected or an existing port changes the
* state attribute.
*/
onstatechange(e: MIDIConnectionEvent): void;
addEventListener(
type: 'statechange',
listener: (this: this, e: MIDIConnectionEvent) => any,
options?: boolean | AddEventListenerOptions,
): void;
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions,
): void;
/**
* This attribute informs the user whether system exclusive support is enabled on
* this MIDIAccess.
*/
sysexEnabled: boolean;
}
type MIDIPortType = 'input' | 'output';
type MIDIPortDeviceState = 'disconnected' | 'connected';
type MIDIPortConnectionState = 'open' | 'closed' | 'pending';
interface MIDIPort extends EventTarget {
/**
* A unique ID of the port. This can be used by developers to remember ports the
* user has chosen for their application.
*/
id: string;
/**
* The manufacturer of the port.
*/
manufacturer?: string | undefined;
/**
* The system name of the port.
*/
name?: string | undefined;
/**
* A descriptor property to distinguish whether the port is an input or an output
* port.
*/
type: MIDIPortType;
/**
* The version of the port.
*/
version?: string | undefined;
/**
* The state of the device.
*/
state: MIDIPortDeviceState;
/**
* The state of the connection to the device.
*/
connection: MIDIPortConnectionState;
/**
* The handler called when an existing port changes its state or connection
* attributes.
*/
onstatechange(e: MIDIConnectionEvent): void;
addEventListener(
type: 'statechange',
listener: (this: this, e: MIDIConnectionEvent) => any,
options?: boolean | AddEventListenerOptions,
): void;
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions,
): void;
/**
* Makes the MIDI device corresponding to the MIDIPort explicitly available. Note
* that this call is NOT required in order to use the MIDIPort - calling send() on
* a MIDIOutput or attaching a MIDIMessageEvent handler on a MIDIInputPort will
* cause an implicit open().
*
* When invoked, this method returns a Promise object representing a request for
* access to the given MIDI port on the user's system.
*/
open(): Promise<MIDIPort>;
/**
* Makes the MIDI device corresponding to the MIDIPort
* explicitly unavailable (subsequently changing the state from "open" to
* "connected"). Note that successful invocation of this method will result in MIDI
* messages no longer being delivered to MIDIMessageEvent handlers on a
* MIDIInputPort (although setting a new handler will cause an implicit open()).
*
* When invoked, this method returns a Promise object representing a request for
* access to the given MIDI port on the user's system. When the port has been
* closed (and therefore, in exclusive access systems, the port is available to
* other applications), the vended Promise is resolved. If the port is
* disconnected, the Promise is rejected.
*/
close(): Promise<MIDIPort>;
}
interface MIDIInput extends MIDIPort {
type: 'input';
onmidimessage(e: MIDIMessageEvent): void;
addEventListener(
type: 'midimessage',
listener: (this: this, e: MIDIMessageEvent) => any,
options?: boolean | AddEventListenerOptions,
): void;
addEventListener(
type: 'statechange',
listener: (this: this, e: MIDIConnectionEvent) => any,
options?: boolean | AddEventListenerOptions,
): void;
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions,
): void;
}
interface MIDIOutput extends MIDIPort {
type: 'output';
/**
* Enqueues the message to be sent to the corresponding MIDI port.
* @param data The data to be enqueued, with each sequence entry representing a single byte of data.
* @param timestamp The time at which to begin sending the data to the port. If timestamp is set
* to zero (or another time in the past), the data is to be sent as soon as
* possible.
*/
send(data: number[] | Uint8Array, timestamp?: number): void;
/**
* Clears any pending send data that has not yet been sent from the MIDIOutput 's
* queue. The implementation will need to ensure the MIDI stream is left in a good
* state, so if the output port is in the middle of a sysex message, a sysex
* termination byte (0xf7) should be sent.
*/
clear(): void;
}
interface MIDIMessageEvent extends Event {
/**
* A timestamp specifying when the event occurred.
*/
receivedTime: number;
/**
* A Uint8Array containing the MIDI data bytes of a single MIDI message.
*/
data: Uint8Array;
}
interface MIDIMessageEventInit extends EventInit {
/**
* A timestamp specifying when the event occurred.
*/
receivedTime: number;
/**
* A Uint8Array containing the MIDI data bytes of a single MIDI message.
*/
data: Uint8Array;
}
interface MIDIConnectionEvent extends Event {
/**
* The port that has been connected or disconnected.
*/
port: MIDIPort;
}
interface MIDIConnectionEventInit extends EventInit {
/**
* The port that has been connected or disconnected.
*/
port: MIDIPort;
}
}
/**
* The `EventEmitter` class provides methods to implement the _observable_ design pattern. This
* pattern allows one to _register_ a function to execute when a specific event is _emitted_ by the
* emitter.
*
* It is intended to be an abstract class meant to be extended by (or mixed into) other objects.
*/
export declare class EventEmitter {
/**
* Identifier (Symbol) to use when adding or removing a listener that should be triggered when any
* events occur.
*
* @type {Symbol}
*/
static get ANY_EVENT(): Symbol;
/**
* Creates a new `EventEmitter`object.
*
* @param {boolean} [eventsSuspended=false] Whether the `EventEmitter` is initially in a suspended
* state (i.e. not executing callbacks).
*/
constructor(eventsSuspended?: boolean);
/**
* An object containing a property for each event with at least one registered listener. Each
* event property contains an array of all the [`Listener`]{@link Listener} objects registered
* for the event.
*
* @type {Object}
* @readonly
*/
eventMap: any;
/**
* Whether or not the execution of callbacks is currently suspended for this emitter.
*
* @type {boolean}
*/
eventsSuspended: boolean;
/**
* Adds a listener for the specified event. It returns the [`Listener`]{@link Listener} object
* that was created and attached to the event.
*
* To attach a global listener that will be triggered for any events, use
* [`EventEmitter.ANY_EVENT`]{@link #ANY_EVENT} as the first parameter. Note that a global
* listener will also be triggered by non-registered events.
*
* @param {string|Symbol} event The event to listen to.
* @param {EventEmitterCallback} callback The callback function to execute when the event occurs.
* @param {Object} [options={}]
* @param {Object} [options.context=this] The value of `this` in the callback function.
* @param {boolean} [options.prepend=false] Whether the listener should be added at the beginning
* of the listeners array and thus executed first.
* @param {number} [options.duration=Infinity] The number of milliseconds before the listener
* automatically expires.
* @param {number} [options.remaining=Infinity] The number of times after which the callback
* should automatically be removed.
* @param {array} [options.arguments] An array of arguments which will be passed separately to the
* callback function. This array is stored in the [`arguments`]{@link Listener#arguments}
* property of the [`Listener`]{@link Listener} object and can be retrieved or modified as
* desired.
*
* @returns {Listener} The newly created [`Listener`]{@link Listener} object.
*
* @throws {TypeError} The `event` parameter must be a string or
* [`EventEmitter.ANY_EVENT`]{@link EventEmitter#ANY_EVENT}.
* @throws {TypeError} The `callback` parameter must be a function.
*/
addListener(event: string | Symbol, callback: EventEmitterCallback, options?: {
context?: any;
prepend?: boolean;
duration?: number;
remaining?: number;
arguments?: any[];
}): Listener | Listener[];
/**
* Adds a one-time listener for the specified event. The listener will be executed once and then
* destroyed. It returns the [`Listener`]{@link Listener} object that was created and attached
* to the event.
*
* To attach a global listener that will be triggered for any events, use
* [`EventEmitter.ANY_EVENT`]{@link EventEmitter#ANY_EVENT} as the first parameter. Note that a
* global listener will also be triggered by non-registered events.
*
* @param {string|Symbol} event The event to listen to
* @param {EventEmitterCallback} callback The callback function to execute when the event occurs
* @param {Object} [options={}]
* @param {Object} [options.context=this] The context to invoke the callback function in.
* @param {boolean} [options.prepend=false] Whether the listener should be added at the beginning
* of the listeners array and thus executed first.
* @param {number} [options.duration=Infinity] The number of milliseconds before the listener
* automatically expires.
* @param {array} [options.arguments] An array of arguments which will be passed separately to the
* callback function. This array is stored in the [`arguments`]{@link Listener#arguments}
* property of the [`Listener`]{@link Listener} object and can be retrieved or modified as
* desired.
*
* @returns {Listener} The newly created [`Listener`]{@link Listener} object.
*
* @throws {TypeError} The `event` parameter must be a string or
* [`EventEmitter.ANY_EVENT`]{@link EventEmitter#ANY_EVENT}.
* @throws {TypeError} The `callback` parameter must be a function.
*/
addOneTimeListener(event: string | Symbol, callback: EventEmitterCallback, options?: {
context?: any;
prepend?: boolean;
duration?: number;
arguments?: any[];
}): Listener | Listener[];
/**
* Returns `true` if the specified event has at least one registered listener. If no event is
* specified, the method returns `true` if any event has at least one listener registered (this
* includes global listeners registered to
* [`EventEmitter.ANY_EVENT`]{@link EventEmitter#ANY_EVENT}).
*
* Note: to specifically check for global listeners added with
* [`EventEmitter.ANY_EVENT`]{@link EventEmitter#ANY_EVENT}, use
* [`EventEmitter.ANY_EVENT`]{@link EventEmitter#ANY_EVENT} as the parameter.
*
* @param {string|Symbol} [event=(any event)] The event to check
* @param {function|Listener} [callback=(any callback)] The actual function that was added to the
* event or the {@link Listener} object returned by `addListener()`.
* @returns {boolean}
*/
hasListener(event?: string | Symbol, callback?: Function | Listener): boolean;
/**
* An array of all the unique event names for which the emitter has at least one registered
* listener.
*
* Note: this excludes global events registered with
* [`EventEmitter.ANY_EVENT`]{@link EventEmitter#ANY_EVENT} because they are not tied to a
* specific event.
*
* @type {string[]}
* @readonly
*/
get eventNames(): string[];
/**
* Returns an array of all the [`Listener`]{@link Listener} objects that have been registered for
* a specific event.
*
* Please note that global events (those added with
* [`EventEmitter.ANY_EVENT`]{@link EventEmitter#ANY_EVENT}) are not returned for "regular"
* events. To get the list of global listeners, specifically use
* [`EventEmitter.ANY_EVENT`]{@link EventEmitter#ANY_EVENT} as the parameter.
*
* @param {string|Symbol} event The event to get listeners for.
* @returns {Listener[]} An array of [`Listener`]{@link Listener} objects.
*/
getListeners(event: string | Symbol): Listener[];
/**
* Suspends execution of all callbacks functions registered for the specified event type.
*
* You can suspend execution of callbacks registered with
* [`EventEmitter.ANY_EVENT`]{@link EventEmitter#ANY_EVENT} by passing
* [`EventEmitter.ANY_EVENT`]{@link EventEmitter#ANY_EVENT} to `suspendEvent()`. Beware that this
* will not suspend all callbacks but only those registered with
* [`EventEmitter.ANY_EVENT`]{@link EventEmitter#ANY_EVENT}. While this may seem counter-intuitive
* at first glance, it allows the selective suspension of global listeners while leaving other
* listeners alone. If you truly want to suspends all callbacks for a specific
* [`EventEmitter`]{@link EventEmitter}, simply set its `eventsSuspended` property to `true`.
*
* @param {string|Symbol} event The event name (or `EventEmitter.ANY_EVENT`) for which to suspend
* execution of all callback functions.
*/
suspendEvent(event: string | Symbol): void;
/**
* Resumes execution of all suspended callback functions registered for the specified event type.
*
* You can resume execution of callbacks registered with
* [`EventEmitter.ANY_EVENT`]{@link EventEmitter#ANY_EVENT} by passing
* [`EventEmitter.ANY_EVENT`]{@link EventEmitter#ANY_EVENT} to `unsuspendEvent()`. Beware that
* this will not resume all callbacks but only those registered with
* [`EventEmitter.ANY_EVENT`]{@link EventEmitter#ANY_EVENT}. While this may seem
* counter-intuitive, it allows the selective unsuspension of global listeners while leaving other
* callbacks alone.
*
* @param {string|Symbol} event The event name (or `EventEmitter.ANY_EVENT`) for which to resume
* execution of all callback functions.
*/
unsuspendEvent(event: string | Symbol): void;
/**
* Returns the number of listeners registered for a specific event.
*
* Please note that global events (those added with
* [`EventEmitter.ANY_EVENT`]{@link EventEmitter#ANY_EVENT}) do not count towards the remaining
* number for a "regular" event. To get the number of global listeners, specifically use
* [`EventEmitter.ANY_EVENT`]{@link EventEmitter#ANY_EVENT} as the parameter.
*
* @param {string|Symbol} event The event which is usually a string but can also be the special
* [`EventEmitter.ANY_EVENT`]{@link EventEmitter#ANY_EVENT} symbol.
* @returns {number} An integer representing the number of listeners registered for the specified
* event.
*/
getListenerCount(event: string | Symbol): number;
/**
* Executes the callback function of all the [`Listener`]{@link Listener} objects registered for
* a given event. The callback functions are passed the additional arguments passed to `emit()`
* (if any) followed by the arguments present in the [`arguments`](Listener#arguments) property of
* the [`Listener`](Listener) object (if any).
*
* If the [`eventsSuspended`]{@link #eventsSuspended} property is `true` or the
* [`Listener.suspended`]{@link Listener#suspended} property is `true`, the callback functions
* will not be executed.
*
* This function returns an array containing the return values of each of the callbacks.
*
* It should be noted that the regular listeners are triggered first followed by the global
* listeners (those added with [`EventEmitter.ANY_EVENT`]{@link EventEmitter#ANY_EVENT}).
*
* @param {string} event The event
* @param {...*} args Arbitrary number of arguments to pass along to the callback functions
*
* @returns {Array} An array containing the return value of each of the executed listener
* functions.
*
* @throws {TypeError} The `event` parameter must be a string.
*/
emit(event: string, ...args: any[]): any[];
/**
* Removes all the listeners that match the specified criterias. If no parameters are passed, all
* listeners will be removed. If only the `event` parameter is passed, all listeners for that
* event will be removed. You can remove global listeners by using
* [`EventEmitter.ANY_EVENT`]{@link EventEmitter#ANY_EVENT} as the first parameter.
*
* To use more granular options, you must at least define the `event`. Then, you can specify the
* callback to match or one or more of the additional options.
*
* @param {string | Symbol} [event] The event name.
* @param {EventEmitterCallback} [callback] Only remove the listeners that match this exact
* callback function.
* @param {Object} [options]
* @param {*} [options.context] Only remove the listeners that have this exact context.
* @param {number} [options.remaining] Only remove the listener if it has exactly that many
* remaining times to be executed.
*/
removeListener(
event?: string | Symbol,
callback?: EventEmitterCallback,
options?: {
context?: any;
remaining?: number;
}
): void;
/**
* The `waitFor()` method is an async function which returns a promise. The promise is fulfilled
* when the specified event occurs. The event can be a regular event or
* [`EventEmitter.ANY_EVENT`]{@link EventEmitter#ANY_EVENT} (if you want to resolve as soon as any
* event is emitted).
*
* If the `duration` option is set, the promise will only be fulfilled if the event is emitted
* within the specified duration. If the event has not been fulfilled after the specified
* duration, the promise is rejected. This makes it super easy to wait for an event and timeout
* after a certain time if the event is not triggered.
*
* @param {string|Symbol} event The event to wait for
* @param {Object} [options={}]
* @param {number} [options.duration=Infinity] The number of milliseconds to wait before the
* promise is automatically rejected.
*/
waitFor(event: string | Symbol, options?: {
duration?: number;
}): Promise<any>;
/**
* The number of unique events that have registered listeners.
*
* Note: this excludes global events registered with
* [`EventEmitter.ANY_EVENT`]{@link EventEmitter#ANY_EVENT} because they are not tied to a
* specific event.
*
* @type {number}
* @readonly
*/
get eventCount(): number;
}
/**
* The `Listener` class represents a single event listener object. Such objects keep all relevant
* contextual information such as the event being listened to, the object the listener was attached
* to, the callback function and so on.
*
*/
export declare class Listener {
/**
* Creates a new `Listener` object
*
* @param {string|Symbol} event The event being listened to
* @param {EventEmitter} target The [`EventEmitter`]{@link EventEmitter} object that the listener
* is attached to.
* @param {EventEmitterCallback} callback The function to call when the listener is triggered
* @param {Object} [options={}]
* @param {Object} [options.context=target] The context to invoke the listener in (a.k.a. the
* value of `this` inside the callback function).
* @param {number} [options.remaining=Infinity] The remaining number of times after which the
* callback should automatically be removed.
* @param {array} [options.arguments] An array of arguments that will be passed separately to the
* callback function upon execution. The array is stored in the [`arguments`]{@link #arguments}
* property and can be retrieved or modified as desired.
*
* @throws {TypeError} The `event` parameter must be a string or
* [`EventEmitter.ANY_EVENT`]{@link EventEmitter#ANY_EVENT}.
* @throws {ReferenceError} The `target` parameter is mandatory.
* @throws {TypeError} The `callback` must be a function.
*/
constructor(event: string | Symbol, target: EventEmitter, callback: EventEmitterCallback, options?: {
context?: any;
remaining?: number;
arguments?: any[];
}, ...args: any[]);
/**
* An array of arguments to pass to the callback function upon execution.
* @type {array}
*/
arguments: any[];
/**
* The callback function to execute.
* @type {Function}
*/
callback: Function;
/**
* The context to execute the callback function in (a.k.a. the value of `this` inside the
* callback function)
* @type {Object}
*/
context: any;
/**
* The number of times the listener function was executed.
* @type {number}
*/
count: number;
/**
* The event name.
* @type {string}
*/
event: string;
/**
* The remaining number of times after which the callback should automatically be removed.
* @type {number}
*/
remaining: number;
/**
* Whether this listener is currently suspended or not.
* @type {boolean}
*/
suspended: boolean;
/**
* The object that the event is attached to (or that emitted the event).
* @type {EventEmitter}
*/
target: EventEmitter;
/**
* Removes the listener from its target.
*/
remove(): void;
}
/**
* The `Enumerations` class contains enumerations and arrays of elements used throughout the
* library. All properties are static and should be referenced using the class name. For example:
* `Enumerations.CHANNEL_MESSAGES`.
*
* @license Apache-2.0
* @since 3.0.0
*/
export class Enumerations {
/**
* Enumeration of all MIDI channel message names and their associated 4-bit numerical value:
*
* | Message Name | Hexadecimal | Decimal |
* |---------------------|-------------|---------|
* | `noteoff` | 0x8 | 8 |
* | `noteon` | 0x9 | 9 |
* | `keyaftertouch` | 0xA | 10 |
* | `controlchange` | 0xB | 11 |
* | `programchange` | 0xC | 12 |
* | `channelaftertouch` | 0xD | 13 |
* | `pitchbend` | 0xE | 14 |
*
* @enum {Object.<string, number>}
* @readonly
* @since 3.1
* @static
*/
static get CHANNEL_MESSAGES(): {
noteoff: number;
noteon: number;
keyaftertouch: number;
controlchange: number;
programchange: number;
channelaftertouch: number;
pitchbend: number;
};
/**
* A simple array of the 16 valid MIDI channel numbers (`1` to `16`):
*
* @type {number[]}
* @readonly
* @static
*/
static get CHANNEL_NUMBERS(): number[];
/**
* Enumeration of all MIDI channel mode message names and their associated numerical value:
*
*
* | Message Name | Hexadecimal | Decimal |
* |-----------------------|-------------|---------|
* | `allsoundoff` | 0x78 | 120 |
* | `resetallcontrollers` | 0x79 | 121 |
* | `localcontrol` | 0x7A | 122 |
* | `allnotesoff` | 0x7B | 123 |
* | `omnimodeoff` | 0x7C | 124 |
* | `omnimodeon` | 0x7D | 125 |
* | `monomodeon` | 0x7E | 126 |
* | `polymodeon` | 0x7F | 127 |
*
* @enum {Object.<string, number>}
* @readonly
* @static
*/
static get CHANNEL_MODE_MESSAGES(): {
allsoundoff: number;
resetallcontrollers: number;
localcontrol: number;
allnotesoff: number;
omnimodeoff: number;
omnimodeon: number;
monomodeon: number;
polymodeon: number;
};
/**
* An array of objects, ordered by control number, describing control change messages. Each object
* in the array can have up to 4 properties:
*
* * `number`: MIDI control number (0-127);
* * `event`: name of emitted event (eg: `bankselectcoarse`, `choruslevel`, etc) that can be
* listened to;
* * `description`: user-friendly description of the controller's purpose;
* * `position`: whether this controller's value should be considered an `msb` or `lsb` (if
* appropriate).
*
* Not all controllers have a predefined function. For those that don't, name is the word
* "controller" followed by the number (e.g. `controller112`).
*
* | Event name | Control Number |
* |--------------------------------|----------------|
* | `bankselectcoarse` | 0 |
* | `modulationwheelcoarse` | 1 |
* | `breathcontrollercoarse` | 2 |
* | `controller3` | 3 |
* | `footcontrollercoarse` | 4 |
* | `portamentotimecoarse` | 5 |
* | `dataentrycoarse` | 6 |
* | `volumecoarse` | 7 |
* | `balancecoarse` | 8 |
* | `controller9` | 9 |
* | `pancoarse` | 10 |
* | `expressioncoarse` | 11 |
* | `effectcontrol1coarse` | 12 |
* | `effectcontrol2coarse` | 13 |
* | `controller14` | 14 |
* | `controller15` | 15 |
* | `generalpurposecontroller1` | 16 |
* | `generalpurposecontroller2` | 17 |
* | `generalpurposecontroller3` | 18 |
* | `generalpurposecontroller4` | 19 |
* | `controller20` | 20 |
* | `controller21` | 21 |
* | `controller22` | 22 |
* | `controller23` | 23 |
* | `controller24` | 24 |
* | `controller25` | 25 |
* | `controller26` | 26 |
* | `controller27` | 27 |
* | `controller28` | 28 |
* | `controller29` | 29 |
* | `controller30` | 30 |
* | `controller31` | 31 |
* | `bankselectfine` | 32 |
* | `modulationwheelfine` | 33 |
* | `breathcontrollerfine` | 34 |
* | `controller35` | 35 |
* | `footcontrollerfine` | 36 |
* | `portamentotimefine` | 37 |
* | `dataentryfine` | 38 |
* | `channelvolumefine` | 39 |
* | `balancefine` | 40 |
* | `controller41` | 41 |
* | `panfine` | 42 |
* | `expressionfine` | 43 |
* | `effectcontrol1fine` | 44 |
* | `effectcontrol2fine` | 45 |
* | `controller46` | 46 |
* | `controller47` | 47 |
* | `controller48` | 48 |
* | `controller49` | 49 |
* | `controller50` | 50 |
* | `controller51` | 51 |
* | `controller52` | 52 |
* | `controller53` | 53 |
* | `controller54` | 54 |
* | `controller55` | 55 |
* | `controller56` | 56 |
* | `controller57` | 57 |
* | `controller58` | 58 |
* | `controller59` | 59 |
* | `controller60` | 60 |
* | `controller61` | 61 |
* | `controller62` | 62 |
* | `controller63` | 63 |
* | `damperpedal` | 64 |
* | `portamento` | 65 |
* | `sostenuto` | 66 |
* | `softpedal` | 67 |
* | `legatopedal` | 68 |
* | `hold2` | 69 |
* | `soundvariation` | 70 |
* | `resonance` | 71 |
* | `releasetime` | 72 |
* | `attacktime` | 73 |
* | `brightness` | 74 |
* | `decaytime` | 75 |
* | `vibratorate` | 76 |
* | `vibratodepth` | 77 |
* | `vibratodelay` | 78 |
* | `controller79` | 79 |
* | `generalpurposecontroller5` | 80 |
* | `generalpurposecontroller6` | 81 |
* | `generalpurposecontroller7` | 82 |
* | `generalpurposecontroller8` | 83 |
* | `portamentocontrol` | 84 |
* | `controller85` | 85 |
* | `controller86` | 86 |
* | `controller87` | 87 |
* | `highresolutionvelocityprefix` | 88 |
* | `controller89` | 89 |
* | `controller90` | 90 |
* | `effect1depth` | 91 |
* | `effect2depth` | 92 |
* | `effect3depth` | 93 |
* | `effect4depth` | 94 |
* | `effect5depth` | 95 |
* | `dataincrement` | 96 |
* | `datadecrement` | 97 |
* | `nonregisteredparameterfine` | 98 |
* | `nonregisteredparametercoarse` | 99 |
* | `nonregisteredparameterfine` | 100 |
* | `registeredparametercoarse` | 101 |
* | `controller102` | 102 |
* | `controller103` | 103 |
* | `controller104` | 104 |
* | `controller105` | 105 |
* | `controller106` | 106 |
* | `controller107` | 107 |
* | `controller108` | 108 |
* | `controller109` | 109 |
* | `controller110` | 110 |
* | `controller111` | 111 |
* | `controller112` | 112 |
* | `controller113` | 113 |
* | `controller114` | 114 |
* | `controller115` | 115 |
* | `controller116` | 116 |
* | `controller117` | 117 |
* | `controller118` | 118 |
* | `controller119` | 119 |
* | `allsoundoff` | 120 |
* | `resetallcontrollers` | 121 |
* | `localcontrol` | 122 |
* | `allnotesoff` | 123 |
* | `omnimodeoff` | 124 |
* | `omnimodeon` | 125 |
* | `monomodeon` | 126 |
* | `polymodeon` | 127 |
*
* @type {Object[]}
* @readonly
* @static
* @since 3.1
*/
static get CONTROL_CHANGE_MESSAGES():object[]
/**
* Enumeration of all MIDI registered parameters and their associated pair of numerical values.
* MIDI registered parameters extend the original list of control change messages. Currently,
* there are only a limited number of them:
*
*
* | Control Function | [LSB, MSB] |
* |------------------------------|--------------|
* | `pitchbendrange` | [0x00, 0x00] |
* | `channelfinetuning` | [0x00, 0x01] |
* | `channelcoarsetuning` | [0x00, 0x02] |
* | `tuningprogram` | [0x00, 0x03] |
* | `tuningbank` | [0x00, 0x04] |
* | `modulationrange` | [0x00, 0x05] |
* | `azimuthangle` | [0x3D, 0x00] |
* | `elevationangle` | [0x3D, 0x01] |
* | `gain` | [0x3D, 0x02] |
* | `distanceratio` | [0x3D, 0x03] |
* | `maximumdistance` | [0x3D, 0x04] |
* | `maximumdistancegain` | [0x3D, 0x05] |
* | `referencedistanceratio` | [0x3D, 0x06] |
* | `panspreadangle` | [0x3D, 0x07] |
* | `rollangle` | [0x3D, 0x08] |
*
* @enum {Object.<string, number[]>}
* @readonly
* @static
*/
static get REGISTERED_PARAMETERS(): {
pitchbendrange: number[];
channelfinetuning: number[];
channelcoarsetuning: number[];
tuningprogram: number[];
tuningbank: number[];
modulationrange: number[];
azimuthangle: number[];
elevationangle: number[];
gain: number[];
distanceratio: number[];
maximumdistance: number[];
maximumdistancegain: number[];
referencedistanceratio: number[];
panspreadangle: number[];
rollangle: number[];
};
/**
* Enumeration of all valid MIDI system messages and matching numerical values. WebMidi.js also
* uses two additional custom messages.
*
* **System Common Messages**
*
* | Function | Hexadecimal | Decimal |
* |------------------------|-------------|---------|
* | `sysex` | 0xF0 | 240 |
* | `timecode` | 0xF1 | 241 |
* | `songposition` | 0xF2 | 242 |
* | `songselect` | 0xF3 | 243 |
* | `tunerequest` | 0xF6 | 246 |
* | `sysexend` | 0xF7 | 247 |
*
* The `sysexend` message is never actually received. It simply ends a sysex stream.
*
* **System Real-Time Messages**
*
* | Function | Hexadecimal | Decimal |
* |------------------------|-------------|---------|
* | `clock` | 0xF8 | 248 |
* | `start` | 0xFA | 250 |
* | `continue` | 0xFB | 251 |
* | `stop` | 0xFC | 252 |
* | `activesensing` | 0xFE | 254 |
* | `reset` | 0xFF | 255 |
*
* Values 249 and 253 are relayed by the
* [Web MIDI API](https://developer.mozilla.org/en-US/docs/Web/API/Web_MIDI_API) but they do not
* serve any specific purpose. The
* [MIDI 1.0 spec](https://www.midi.org/specifications/item/table-1-summary-of-midi-message)
* simply states that they are undefined/reserved.
*
* **Custom WebMidi.js Messages**
*
* These two messages are mostly for internal use. They are not MIDI messages and cannot be sent
* or forwarded.
*
* | Function | Hexadecimal | Decimal |
* |------------------------|-------------|---------|
* | `midimessage` | | 0 |
* | `unknownsystemmessage` | | -1 |
*
* @enum {Object.<string, number>}
* @readonly
* @static
*/
static get SYSTEM_MESSAGES(): {
sysex: number;
timecode: number;
songposition: number;
songselect: number;
tunerequest: number;
tuningrequest: number;
sysexend: number;
clock: number;
start: number;
continue: number;
stop: number;
activesensing: number;
reset: number;
midimessage: number;
unknownsystemmessage: number;
};
/**
* Array of channel-specific event names that can be listened for. This includes channel mode
* events and RPN/NRPN events.
*
* @type {string[]}
* @readonly
*/
static get CHANNEL_EVENTS(): string[];
}
/**
* The `Forwarder` class allows the forwarding of MIDI messages to predetermined outputs. When you
* call its [`forward()`](#forward) method, it will send the specified [`Message`](Message) object
* to all the outputs listed in its [`destinations`](#destinations) property.
*
* If specific channels or message types have been defined in the [`channels`](#channels) or
* [`types`](#types) properties, only messages matching the channels/types will be forwarded.
*
* While it can be manually instantiated, you are more likely to come across a `Forwarder` object as
* the return value of the [`Input.addForwarder()`](Input#addForwarder) method.
*
* @license Apache-2.0
* @since 3.0.0
*/
export class Forwarder {
/**
* Creates a `Forwarder` object.
*
* @param {Output|Output[]} [destinations=\[\]] An [`Output`](Output) object, or an array of such
* objects, to forward the message to.