forked from djipco/webmidi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebmidi.d.ts
1620 lines (1488 loc) · 60 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 WebMidi.js (available since v2.3.0)
// Project: <https://github.com/djipco/webmidi>
// Definitions by: mmmveggies <https://www.github.com/mmmveggies>
// Largely copied from original JSDoc comments
/** All Input events extend this base event. */
export interface InputEventBase<T extends keyof InputEvents> {
/** The Input that triggered the event. */
target: Input
/** The raw MIDI message as an array of 8 bit values. */
data: Uint8Array
/** The time when the event occurred (in milliseconds) */
timestamp: number
/** The type of event that occured. */
type: T
}
/** All Input events that relate to a specific channel extend this event. */
export interface InputEventChannelBase<T extends keyof InputEvents> extends InputEventBase<T> {
/** The channel where the event occurred (between 1 and 16). */
channel: number
}
/** The controller `name` and `number` information. */
export interface IEventController {
/** The usual name or function of the controller. */
name: string
/** The number of the controller. */
number: number
}
/** The note information for a given event. */
export interface IEventNote {
/** The MIDI note number. */
number: number
/** The usual note name (C, C#, D, D#, etc.). */
name: string
/** The octave (between -2 and 8). */
octave: number
}
/** Parameter describing 1-16 midi channels, "all" means all */
export type IMidiChannel = number | number[] | "all"
/**
* A description of a note, used in method parameters.
* Strings can be name with octaves e.g. "A#5" and numbers
* are midi ints e.g. middle C is 60
*/
export type INoteParam = number | string | Array<number | string>
/** Event emitted when a system active sensing MIDI message has been received. */
export type InputEventActivesensing = InputEventBase<"activesensing">
/**
* Event emitted when a channel-wide aftertouch MIDI message has been received on a specific
* device and channel.
*/
export interface InputEventChannelaftertouch extends InputEventChannelBase<"channelaftertouch"> {
/** The aftertouch value received (between 0 and 1). */
value: number
}
/**
* Event emitted when a channel mode MIDI message has been received on a
* specific device and channel.
*/
export interface InputEventChannelmode extends InputEventChannelBase<"channelmode"> {
/** The controller `name` and `number` information. */
controller: IEventController
/** The value received (between 0 and 127). */
value: number
}
/** Event emitted when a system timing clock MIDI message has been received. */
export type InputEventClock = InputEventBase<"clock">
/** Event emitted when a system continue MIDI message has been received. */
export type InputEventContinue = InputEventBase<"continue">
/**
* Event emitted when a control change MIDI message has been received
* on a specific device and channel.
*/
export interface InputEventControlchange extends InputEventChannelBase<"controlchange"> {
/** The controller `name` and `number` information. */
controller: IEventController
/** The value received (between 0 and 127). */
value: number
}
/** Event emitted when a key-specific aftertouch MIDI message has been received on a specific
device and channel. */
export interface InputEventKeyaftertouch extends InputEventChannelBase<"keyaftertouch"> {
/** The note information for a given event. */
note: IEventNote
/** The aftertouch amount (between 0 and 1). */
value: number
}
/**
* Event emitted when a MIDI message is received.
* This should be used primarily for debugging purposes.
*/
export type InputEventMidimessage = InputEventBase<"midimessage">
/**
* Event emitted when a note off MIDI message has been received on a
* specific device and channel.
*/
export interface InputEventNoteoff extends InputEventChannelBase<"noteoff"> {
/** The note information for a given event. */
note: IEventNote
/** The release velocity (between 0 and 1). */
velocity: number
/** The attack velocity expressed as a 7-bit integer (between 0 and 127). */
rawVelocity: number
}
/**
* Event emitted when a note on MIDI message has been received on a
* specific device and channel.
*/
export interface InputEventNoteon extends InputEventChannelBase<"noteon"> {
/** The note information for a given event. */
note: IEventNote
/** The attack velocity (between 0 and 1). */
velocity: number
/** The attack velocity expressed as a 7-bit integer (between 0 and 127). */
rawVelocity: number
}
/**
* Event emitted when a pitch bend MIDI message has been received on a
* specific device and channel.
*/
export interface InputEventPitchbend extends InputEventChannelBase<"pitchbend"> {
/** The pitch bend value received (between -1 and 1). */
value: number
}
/**
* Event emitted when a program change MIDI message has been received on a
* specific device and channel.
*/
export interface InputEventProgramchange extends InputEventChannelBase<"programchange"> {
/** The value received (between 0 and 127). */
value: number
}
/** Event emitted when a system reset MIDI message has been received. */
export type InputEventReset = InputEventBase<"reset">
/** Event emitted when a system song position pointer MIDI message has been received. */
export type InputEventSongposition = InputEventBase<"songposition">
/** Event emitted when a system song select MIDI message has been received. */
export interface InputEventSongselect extends InputEventBase<"songselect"> {
/** Song (or sequence) number to select. */
song: string
}
/** Event emitted when a system start MIDI message has been received. */
export type InputEventStart = InputEventBase<"start">
/** Event emitted when a system stop MIDI message has been received. */
export type InputEventStop = InputEventBase<"stop">
/**
* Event emitted when a system exclusive MIDI message has been received.
* You should note that, to receive `sysex` events,
* you must call the `WebMidi.enable()` method with a second parameter set to `true`:
*
* WebMidi.enable(function(err) {
* if (err) {
* console.log("WebMidi could not be enabled.");
* }
* var input = WebMidi.inputs[0];
* input.addListener("sysex", "all", function (e) {
* console.log(e);
* });
* }, true);
**/
export type InputEventSysex = InputEventBase<"sysex">
/** Event emitted when a system MIDI time code quarter frame message has been received. */
export type InputEventTimecode = InputEventBase<"timecode">
/** Event emitted when a system tune request MIDI message has been received. */
export type InputEventTuningrequest = InputEventBase<"tuningrequest">
/**
* Event emitted when an unknown system MIDI message has been received.
* It could be, for example, one of the undefined/reserved messages.
*/
export type InputEventUnknownsystemmessage = InputEventBase<"unknownsystemmessage">
/** All events one can listen to on an `Input`. */
export interface InputEvents {
activesensing: InputEventActivesensing
channelaftertouch: InputEventChannelaftertouch
channelmode: InputEventChannelmode
clock: InputEventClock
continue: InputEventContinue
controlchange: InputEventControlchange
keyaftertouch: InputEventKeyaftertouch
midimessage: InputEventMidimessage
noteoff: InputEventNoteoff
noteon: InputEventNoteon
pitchbend: InputEventPitchbend
programchange: InputEventProgramchange
reset: InputEventReset
songposition: InputEventSongposition
songselect: InputEventSongselect
start: InputEventStart
stop: InputEventStop
sysex: InputEventSysex
timecode: InputEventTimecode
tuningrequest: InputEventTuningrequest
unknownsystemmessage: InputEventUnknownsystemmessage
}
/**
* Generic description of a MIDI port
*/
export interface MidiPort<T extends "input" | "output" = "input" | "output"> {
/** Status of the MIDI port's connection */
readonly connection: "pending" | "open" | "closed"
/**
* ID string of the MIDI port. The ID is host-specific.
* Do not expect the same ID on different platforms.
* For example, Google Chrome and the Jazz-Plugin report
* completely different IDs for the same port.
*/
readonly id: string
/**
* Name of the manufacturer of the device that makes this port available.
*/
readonly manufacturer: string
/** Name of the MIDI port */
readonly name: string
/** State of the MIDI port */
readonly state: "connected" | "disconnected"
/** Type of the MIDI port */
readonly type: T
}
/**
* List of valid MIDI channel messages and matching hexadecimal values.
*/
export interface MidiChannelMessages {
noteoff: 0x8
noteon: 0x9
keyaftertouch: 0xA
controlchange: 0xB
channelmode: 0xB
programchange: 0xC
channelaftertouch: 0xD
pitchbend: 0xE
}
/**
* Event emitted when a MIDI port becomes available. This event is typically fired whenever a
* MIDI device is plugged in. Please note that it may fire several times if a device possesses
* multiple input/output ports.
*/
export interface WebMidiEventConnected {
/** The timestamp when the event occurred (in milliseconds since the epoch) */
timestamp: number
/** The type of event that occurred */
type: "connected"
/** The actual `Input` or `Output` object associated to the event. */
port: Input | Output
}
/**
* Event emitted when a MIDI port becomes unavailable. This event is typically fired whenever a
* MIDI device is unplugged. Please note that it may fire several times if a device possesses
* multiple input/output ports.
*/
export interface WebMidiEventDisconnected {
/** The timestamp when the event occurred (in milliseconds since the epoch) */
timestamp: number
/** The type of event that occurred */
type: "disconnected"
/** An generic object containing details about the port that triggered the event. */
port: MidiPort
}
/** All possible events that `WebMidi` itself can be set up to listen for */
export interface WebMidiEvents {
connected: WebMidiEventConnected
disconnected: WebMidiEventDisconnected
}
/**
* List of valid MIDI registered parameters and their matching pair of hexadecimal
* values. MIDI registered parameters extend the original list of control change messages.
* Currently, there are only a limited number of them.
*/
export interface MidiRegisteredParameters {
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]
}
/**
* List of MIDI channel mode messages as defined in the official MIDI
* specification.
*/
export interface MidiChannelModeMessages {
allsoundoff: 120
resetallcontrollers: 121
localcontrol: 122
allnotesoff: 123
omnimodeoff: 124
omnimodeon: 125
monomodeon: 126
polymodeon: 127
}
/**
* List of MIDI control change messages
*
* Valid MIDI registered parameters and their matching pair of hexadecimal
* values. MIDI registered parameters extend the original list of control change messages.
* Currently, there are only a limited number of them.
*/
export interface MidiControlChangeMessages {
bankselectcoarse: 0
modulationwheelcoarse: 1
breathcontrollercoarse: 2
footcontrollercoarse: 4
portamentotimecoarse: 5
dataentrycoarse: 6
volumecoarse: 7
balancecoarse: 8
pancoarse: 10
expressioncoarse: 11
effectcontrol1coarse: 12
effectcontrol2coarse: 13
generalpurposeslider1: 16
generalpurposeslider2: 17
generalpurposeslider3: 18
generalpurposeslider4: 19
bankselectfine: 32
modulationwheelfine: 33
breathcontrollerfine: 34
footcontrollerfine: 36
portamentotimefine: 37
dataentryfine: 38
volumefine: 39
balancefine: 40
panfine: 42
expressionfine: 43
effectcontrol1fine: 44
effectcontrol2fine: 45
holdpedal: 64
portamento: 65
sustenutopedal: 66
softpedal: 67
legatopedal: 68
hold2pedal: 69
soundvariation: 70
resonance: 71
soundreleasetime: 72
soundattacktime: 73
brightness: 74
soundcontrol6: 75
soundcontrol7: 76
soundcontrol8: 77
soundcontrol9: 78
soundcontrol10: 79
generalpurposebutton1: 80
generalpurposebutton2: 81
generalpurposebutton3: 82
generalpurposebutton4: 83
reverblevel: 91
tremololevel: 92
choruslevel: 93
celestelevel: 94
phaserlevel: 95
databuttonincrement: 96
databuttondecrement: 97
nonregisteredparametercoarse: 98
nonregisteredparameterfine: 99
registeredparametercoarse: 100
registeredparameterfine: 101
}
/**
* List of valid MIDI system messages and matching hexadecimal values.
*
* Note: values 249 and 253 are actually dispatched by the Web MIDI API but I do not know what
* they are used for. They are not part of the online
* [MIDI 1.0 spec](http://www.midi.org/techspecs/midimessages.php).
*/
export interface MidiSystemMessages {
// System common messages
sysex: 0xF0
timecode: 0xF1
songposition: 0xF2
songselect: 0xF3
tuningrequest: 0xF6
/** never actually received - simply ends a sysex */
sysexend: 0xF7
// System real-time messages
clock: 0xF8
start: 0xFA
continue: 0xFB
stop: 0xFC
activesensing: 0xFE
reset: 0xFF
// Custom WebMidi.js messages
midimessage: 0
unknownsystemmessage: -1
}
/**
* All `Output` methods that have an `options` parameter
* derive from this base interface
*/
export interface OutputBaseOptions {
/**
* This value can be one of two things.
* If the value is a string starting with the + sign and followed by a number,
* the request will be delayed by the specified number (in milliseconds).
* Otherwise, the value is considered a timestamp and the request will
* be scheduled at that timestamp.
*
* The `DOMHighResTimeStamp` value is relative to the navigation start of the document.
* To retrieve the current time, you can use `WebMidi.time`.
* If time is not present or is set to a time in the past,
* the request is to be sent as soon as possible.
*/
time?: DOMHighResTimeStamp | string
}
/**
* The `Input` object represents a MIDI input port on the host system.
* This object is created by the MIDI subsystem and cannot be instantiated directly.
* You will find all available `Input` objects in the `WebMidi.inputs` array.
*/
export interface Input extends MidiPort<"input"> {
/**
* Adds an event listener to the Input that will trigger a function
* callback when the specified event happens.
* The events that are dispatched can be channel-specific or Input-wide.
*
* Channel-specific MIDI events:
* noteoff, noteon, keyaftertouch, controlchange, channelmode,
* programchange, channelaftertouch, pitchbend
*
* Input-wide MIDI events:
* sysex, timecode, songposition, songselect, tuningrequest,
* clock, start, continue, stop, activesensing, reset,
* midimessage, unknownsystemmessage
*
* For device-wide events, the channel parameter will be silently ignored.
* You can simply use `undefined` in that case.
*
* If you want to view all incoming MIDI traffic,
* you can listen to the input-wide `"midimessage"` event.
* This event is dispatched for every single message that is received on that input.
*
* @param type - The type of the event.
* @param channel - The MIDI channel to listen on (integer between 1 and 16).
* You can also specify an array of channel numbers or the value "all"
* (or leave it undefined for input-wide events).
* @param listener A callback function to execute when the specified event is detected.
* @returns the WebMidi object so methods can be chained.
*/
addListener<T extends keyof InputEvents>(
type: T,
channel: IMidiChannel | undefined,
listener: (event: InputEvents[T]) => void
): Input
/** Alias for `addListener` */
on<T extends keyof InputEvents>(
type: T,
channel: IMidiChannel | undefined,
listener: (event: InputEvents[T]) => void
): Input
/**
* Returns the name of a control change message matching the specified number.
* If no match is found, the function returns `undefined`.
* @param number The number of the control change message.
* @returns The matching control change name or `undefined`.
* @throws {RangeError} The control change number must be between 0 and 119.
*/
getCcNameByNumber(number: number): string | undefined
/**
* Returns the channel mode name matching the specified number.
* If no match is found, the function returns undefined.
* @param number The number of the channel mode message.
* @returns The matching channel mode message's name or `undefined`.
* @throws {RangeError} The channel mode number must be between 120 and 127.
*/
getChannelModeByNumber(number: number): string | undefined
/**
* Checks if the specified event type is already defined to
* trigger the listener function on the specified channel(s).
* If more than one channel is specified, the function will
* return true only if all channels have the listener defined.
*
* For device-wide events (sysex, start, etc.), the channel parameter
* is silently ignored. We suggest you use `undefined` in such cases.
* @param type The type of event.
* @param channel The MIDI channel to check on (between 1 and 16).
* You can also specify an array of channel numbers or the string "all".
* @param listener The callback function to check for.
* @returns Boolean value indicating whether or not the channel(s)
* already have this listener defined.
*/
hasListener<T extends keyof InputEvents>(
type: T,
channel: IMidiChannel,
listener: (event: InputEvents[T]) => void
): boolean
/**
* Removes the specified listener from the specified channel(s).
* If the `listener` parameter is left undefined,
* all listeners for the specified type will be removed from all channels.
* If the `channel` is also omitted,
* all listeners of the specified type will be removed from all channels.
* If no parameters are defined, all listeners attached to any channel of the Input will be removed.
*
* For device-wide events (sysex, start, etc.), the channel parameter is silently ignored.
* You can use `undefined` in such cases.
* @param type The type of event.
* @param channel The MIDI channel to check on (between 1 and 16).
* You can also specify an array of channel numbers or the string "all".
* @param listener The callback function to check for.
* @returns The `Input` object for easy method chaining.
*/
removeListener<T extends keyof InputEvents>(
type?: T,
channel?: IMidiChannel,
listener?: (event: InputEvents[T]) => void
): Input
}
/**
* The Output object represents a MIDI output port on the host system.
* This object is created by the MIDI subsystem and cannot be instantiated directly.
* You will find all available `Output` objects in the `WebMidi.outputs` array.
*/
export interface Output extends MidiPort<"output"> {
/**
* Decrements the specified MIDI registered parameter by 1. For more specific MIDI usage
* information, check out [RP-18](http://dev.midi.org/techspecs/rp18.php) regarding the usage of
* increment and decrement controllers.
*
* >Unless you are very familiar with the MIDI standard you probably should favour one of the
* >simpler to use functions such as: `setPitchbendRange()`, `setModulationRange()`,
* >`setMasterTuning()`, etc.
*
*
* See `WebMidi.MIDI_REGISTER_PARAMETERS` for a full list of parameter names that can be used.
*
* @param parameter A string identifying the parameter's name (see above) or a
* two-position array specifying the two control bytes (0x65, 0x64) that identify the registered
* parameter.
* @param channel The MIDI channel number (between 1 and 16) or an
* array of channel numbers. If the special value "all" is used, the message will be sent to all
* 16 channels.
* @param options
*
* @throws Error The specified parameter is not available.
*
* @returns Returns the `Output` object so methods can be chained.
*/
decrementRegisteredParameter(
parameter: keyof MidiRegisteredParameters | [number, number],
channel?: IMidiChannel,
options?: OutputBaseOptions
): Output
/**
* Increments the specified MIDI registered parameter by 1. For more specific MIDI usage
* information, check out [RP-18](http://dev.midi.org/techspecs/rp18.php) regarding the usage of
* increment and decrement controllers.
*
* >Unless you are very familiar with the MIDI standard you probably should favour one of the
* >simpler to use functions such as: `setPitchbendRange()`, `setModulationRange()`,
* >`setMasterTuning()`, etc.
*
*
* See `WebMidi.MIDI_REGISTER_PARAMETERS` for a full list of parameter names that can be used.
*
* @param parameter A string identifying the parameter's name (see above) or a
* two-position array specifying the two control bytes (0x65, 0x64) that identify the registered
* parameter.
* @param channel The MIDI channel number (between 1 and 16) or an
* array of channel numbers. If the special value "all" is used, the message will be sent to all
* 16 channels.
* @param options
*
* @throws Error The specified parameter is not available.
*
* @returns {Output} Returns the `Output` object so methods can be chained.
*/
incrementRegisteredParameter(
parameter: keyof MidiRegisteredParameters | [number, number],
channel?: IMidiChannel,
options?: OutputBaseOptions
): Output
/**
* Requests the playback of a single note or multiple notes on the specified channel(s). You can
* delay the execution of the **note on** command by using the `time` property of the `options`
* parameter (milliseconds).
*
* If no duration is specified in the `options`, the note will play until a matching **note off**
* is sent. If a duration is specified, a **note off** will be automatically sent after said
* duration.
*
* Note: As per the MIDI standard, a **note on** event with a velocity of `0` is considered to be
* a **note off**.
*
* @param note The note(s) you wish to play. The notes can be specified in
* one of two ways. The first way is by using the MIDI note number (an integer between 0 and 127).
* The second way is by using the note name followed by the octave (C3, G#4, F-1, Db7). The octave
* range should be between -2 and 8. The lowest note is C-2 (MIDI note number 0) and the highest
* note is G8 (MIDI note number 127). It is also possible to specify an array of note numbers
* and/or names.
*
* @param channel The MIDI channel number (between `1` and `16`) or an
* array of channel numbers. If the special value **all** is used (default), the message will be
* sent to all 16 channels.
*
* @param options
*
* @return Returns the `Output` object so methods can be chained.
*/
playNote(
note: INoteParam,
channel?: IMidiChannel,
options?: OutputBaseOptions & {
/**
* The number of milliseconds (integer) to wait before sending a matching **note off** event.
* If left undefined, only a **note on** message is sent.
*/
duration?: number
/**
* Controls whether the attack and release velocities are set using integers between
* `0` and `127` (`true`) or a decimal number between `0` and `1` (`false`, default).
*/
rawVelocity?: boolean
/**
* The velocity at which to release the note (between `0`
* and `1`). If the `rawVelocity` option is `true`, the value should be specified as an integer
* between `0` and `127`. An invalid velocity value will silently trigger the default of `0.5`.
* This is only used with the **note off** event triggered when `options.duration` is set.
*/
release?: number
/**
* The velocity at which to play the note (between `0` and
* `1`). If the `rawVelocity` option is `true`, the value should be specified as an integer
* between `0` and `127`. An invalid velocity value will silently trigger the default of `0.5`.
*/
velocity?: number
}
): Output
/**
* Sends a MIDI message on the MIDI output port, at the scheduled timestamp.
*
* Unless, you are familiar with the details of the MIDI message format, you should not use this
* method directly. Instead, use one of the simpler helper methods: `playNote()`, `stopNote()`,
* `sendControlChange()`, `sendSystemMessage()`, etc.
*
* Details on the format of MIDI messages are available in the
* [summary of MIDI messages](http://www.midi.org/techspecs/midimessages.php) of the
* MIDI Manufacturers Association.
*
* @param status The MIDI status byte of the message (128-255).
* @param data An array of uints for the message. The number of data bytes varies
* depending on the status byte. It is perfectly legal to send no data for some message types (use
* undefined or an empty array in this case). Each byte must be between 0 and 255.
* @param timestamp The timestamp at which to send the message. You can
* use `WebMidi.time` to retrieve the current timestamp. To send immediately, leave blank or use
* 0.
*
* @throws {RangeError} The status byte must be an integer between 128 (0x80) and 255 (0xFF).
* @throws {RangeError} Data bytes must be integers between 0 (0x00) and 255 (0x7F).
*
* @return Returns the `Output` object so methods can be chained.
*/
send(
status: number,
data?: number[],
timestamp?: DOMHighResTimeStamp
): Output
/**
* Sends an *Active Sensing* real-time message. This tells the device connected to this port that
* the connection is still good. Active sensing messages should be sent every 300 ms if there was
* no other activity on the MIDI port.
*
* @param options
*
* @return Returns the `Output` object so methods can be chained.
*/
sendActiveSensing(options?: OutputBaseOptions): Output
/**
* Sends a MIDI `channel aftertouch` message to the specified channel(s). For key-specific
* aftertouch, you should instead use `sendKeyAftertouch()`.
*
* @param pressure The pressure level (between 0 and 1). An invalid pressure value
* will silently trigger the default behaviour.
* @param channel The MIDI channel number (between 1 and 16) or
* an array of channel numbers. If the special value "all" is used, the message will be sent to
* all 16 channels.
* @param options
*
* @return Returns the `Output` object so methods can be chained.
*/
sendChannelAftertouch(
pressure?: number,
channel?: IMidiChannel,
options?: OutputBaseOptions
): Output
/**
* Sends a MIDI `channel mode` message to the specified channel(s). The channel mode message to send can be specified
* numerically or by using one of `WebMidi.MIDI_CHANNEL_MODE_MESSAGES`
*
* It should be noted that, per the MIDI specification, only `localcontrol` and `monomodeon` may require a value
* that's not zero. For that reason, the `value` parameter is optional and defaults to 0.
*
* @param command The numerical identifier of the channel mode message (integer between 120-127) or
* its name as a string.
* @param value The value to send (integer between 0-127).
* @param channel The MIDI channel number (between 1 and 16) or an array of channel
* numbers. If the special value "all" is used, the message will be sent to all 16 channels.
* @param options
*
* @throws {TypeError} Invalid channel mode message name.
* @throws {RangeError} Channel mode controller numbers must be between 120 and 127.
* @throws {RangeError} Value must be an integer between 0 and 127.
*
* @return Returns the `Output` object so methods can be chained.
*/
sendChannelMode(
command: keyof MidiChannelModeMessages | number,
value?: number,
channel?: IMidiChannel,
options?: OutputBaseOptions
): Output
/**
* Sends a *MIDI Clock* real-time message. According to the standard, there are 24 MIDI Clocks
* for every quarter note.
*
* @param options
*
* @return Returns the `Output` object so methods can be chained.
*/
sendClock(options?: OutputBaseOptions): Output
/**
* Sends a *Continue* real-time message. This resumes song playback where it was previously
* stopped or where it was last cued with a song position message. To start playback from the
* start, use the `sendStart()` function.
*
* @param options
*
* @return Returns the `WebMidi` object so methods can be chained.
*/
sendContinue(options?: OutputBaseOptions): Output
/**
* Sends a MIDI `control change` message to the specified channel(s) at the scheduled time. The
* control change message to send can be specified numerically or by using one of `WebMidi.MIDI_CONTROL_CHANGE_MESSAGE`
*
* Note: as you can see above, not all control change message have a matching common name. This
* does not mean you cannot use the others. It simply means you will need to use their number
* instead of their name.
*
* To view a list of all available `control change` messages, please consult "Table 3 - Control
* Change Messages" from the
* [MIDI Messages](https://www.midi.org/specifications/item/table-3-control-change-messages-data-bytes-2)
* specification.
*
* @param controller The MIDI controller number (0-119) or name.
* @param value The value to send (0-127).
* @param channel The MIDI channel number (between 1 and 16) or an
* array of channel numbers. If the special value "all" is used, the message will be sent to all
* 16 channels.
* @param options
*
* @throws {RangeError} Controller numbers must be between 0 and 119.
* @throws {RangeError} Value must be between 0 and 127.
*
* @return Returns the `Output` object so methods can be chained.
*/
sendControlChange(
controller: keyof MidiControlChangeMessages | number,
value?: number,
channel?: IMidiChannel,
options?: OutputBaseOptions
): Output
/**
* Sends a MIDI `key aftertouch` message to the specified channel(s) at the scheduled time. This
* is a key-specific aftertouch. For a channel-wide aftertouch message, use
* `WebMidi.sendChannelAftertouch()`
*
* @param note The note for which you are sending an aftertouch value. The
* notes can be specified in one of two ways. The first way is by using the MIDI note number (an
* integer between 0 and 127). The second way is by using the note name followed by the octave
* (C3, G#4, F-1, Db7). The octave range should be between -2 and 8. The lowest note is C-2 (MIDI
* note number 0) and the highest note is G8 (MIDI note number 127). It is also possible to use
* an array of note names and/or numbers.
* @param channel The MIDI channel number (between 1 and 16) or an
* array of channel numbers. If the special value "all" is used, the message will be sent to all
* 16 channels.
* @param pressure The pressure level to send (between 0 and 1).
* @param options
*
* @throws {RangeError} The channel must be between 1 and 16.
*
* @return Returns the `Output` object so methods can be chained.
*/
sendKeyAftertouch(
note: INoteParam,
channel?: IMidiChannel,
pressure?: number,
options?: OutputBaseOptions
): Output
/**
* Sends a MIDI `pitch bend` message to the specified channel(s) at the scheduled time.
*
* @param bend The intensity level of the bend (between -1 and 1). A value of zero means
* no bend.
* @param channel The MIDI channel number (between 1 and 16) or an
* array of channel numbers. If the special value "all" is used, the message will be sent to all
* 16 channels.
* @param options
*
* @throws {RangeError} Pitch bend value must be between -1 and 1.
*
* @return Returns the `Output` object so methods can be chained.
*/
sendPitchBend(
bend: number,
channel?: IMidiChannel,
options?: OutputBaseOptions
): Output
/**
* Sends a MIDI `program change` message to the specified channel(s) at the scheduled time.
*
* @param program The MIDI patch (program) number (0-127)
* @param channel The MIDI channel number (between 1 and 16) or an
* array of channel numbers. If the special value "all" is used, the message will be sent to all
* 16 channels.
* @param options
*
* @throws {RangeError} Program numbers must be between 0 and 127.
*
* @return Returns the `Output` object so methods can be chained.
*/
sendProgramChange(
program: number,
channel?: IMidiChannel,
options?: OutputBaseOptions
): Output
/**
* Sends *Reset* real-time message. This tells the device connected to this port that is should
* reset itself to a default state.
*
* @param options
*
* @return Returns the `Output` object so methods can be chained.
*/
sendReset(options?: OutputBaseOptions): Output
/**
* Sends a *Song Position* MIDI message. The value is expressed in MIDI beats (between 0 and
* 16383) which are 16th note. Position 0 is always the start of the song.
*
* @param value The MIDI beat to cue to (int between 0 and 16383).
* @param options
*
* @return Returns the `Output` object so methods can be chained.
*/
sendSongPosition(
value: number,
options?: OutputBaseOptions
): Output
/**
* Sends a *Song Select* MIDI message. Beware that some devices will display position 0 as
* position 1 for user-friendlyness.
*
* @param value The number of the song to select (integer between 0 and 127).
*
* @param options
*
* @throws The song number must be between 0 and 127.
*
* @return Returns the `Output` object so methods can be chained.
*/
sendSongSelect(
value: number,
options?: OutputBaseOptions
): Output
/**
* Sends a *Start* real-time message. A MIDI Start message starts the playback of the current
* song at beat 0. To start playback elsewhere in the song, use the `sendContinue()` function.
*
* @param options
*
* @return Returns the `Output` object so methods can be chained.
*/
sendStart(options?: OutputBaseOptions): Output
/**
* Sends a *Stop* real-time message. This tells the device connected to this port to stop playback
* immediately (or at the scheduled time).
*
* @param options
*
* @return Returns the `Output` object so methods can be chained.
*/
sendStop(options?: OutputBaseOptions): Output
/**
* Sends a MIDI *system exclusive* (sysex) message. The generated message will automatically be
* prepended with the *sysex* byte (0xF0) and terminated with the *end of sysex* byte (0xF7).
*
* To use the `sendSysex()` method, system exclusive message support must have been enabled. To
* do so, you must pass `true` as the second parameter to `WebMidi.enable()`:
*
* WebMidi.enable(function (err) {
* if (err) {
* console.warn(err);
* } else {
* console.log("Sysex is enabled!");
* }
* }, true);
*
* Note that, depending on browser, version and platform, it may be necessary to serve the page
* over HTTPS to enable sysex support.
*