forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webmidi.d.ts
196 lines (166 loc) · 5.74 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
// Type definitions for Web MIDI API
// Project: http://www.w3.org/TR/webmidi/
// Definitions by: six a <https://github.com/lostfictions>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
interface Navigator {
/**
* When invoked, returns a Promise object representing a request for access to MIDI
* devices on the user's system.
*/
requestMIDIAccess(options?: WebMidi.MIDIOptions) : Promise<WebMidi.MIDIAccess>;
}
declare namespace WebMidi {
export 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.
*/
export type MIDIInputMap = Map<string, MIDIInput>;
/**
* This is a maplike interface whose value is a MIDIOutput instance and key is its
* ID.
*/
export type MIDIOutputMap = Map<string, MIDIOutput>;
export 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;
/**
* This attribute informs the user whether system exclusive support is enabled on
* this MIDIAccess.
*/
sysexEnabled : boolean;
}
export type MIDIPortType = "input" | "output";
export type MIDIPortDeviceState = "disconnected" | "connected";
export type MIDIPortConnectionState = "open" | "closed" | "pending";
export 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;
/**
* The system name of the port.
*/
name? : string;
/**
* A descriptor property to distinguish whether the port is an input or an output
* port.
*/
type : MIDIPortType;
/**
* The version of the port.
*/
version? : string;
/**
* 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;
/**
* 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>;
}
export interface MIDIInput extends MIDIPort {
onmidimessage : (e : MIDIMessageEvent) => void;
}
export interface MIDIOutput extends MIDIPort {
/**
* 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[], 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;
}
export 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;
}
export 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;
}
export interface MIDIConnectionEvent extends Event {
/**
* The port that has been connected or disconnected.
*/
port : MIDIPort;
}
export interface MIDIConnectionEventInit extends EventInit {
/**
* The port that has been connected or disconnected.
*/
port : MIDIPort;
}
}