forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webmidi.d.ts
131 lines (113 loc) · 3.52 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
// Type definitions for Web MIDI API
// Project: http://www.w3.org/TR/webmidi/
// Definitions by: Toshiya Nakakura <https://github.com/nakakura>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../es6-promise/es6-promise.d.ts" />
interface Navigator {
/**
* When invoked, returns a Promise object representing a request for access to MIDI devices on the user's system.
* @param options settings that may be provided to the requestMIDIAccess request.
*/
requestMIDIAccess (options?: WebMidi.MidiOptions): Promise<WebMidi.MIDIAccess>;
}
declare module WebMidi{
/**
* optional settings that may be provided to the requestMIDIAccess request.
*/
export interface MidiOptions{
sysex: boolean;
}
export interface IteratorItem<S>{
value: S;
done: boolean;
}
export interface Iterator<S>{
next(): IteratorItem<S>;
}
interface Tuple2<A,B> {
fst: A
snd: B
}
/**
* This type is used to represent all the currently available MIDI input ports as a MapClass-like interface
*/
export interface MIDIInputMap{
size: number;
keys: ()=>Iterator<string>;
entries: ()=>Iterator<Tuple2<string, MIDIInput>>;
values(): Iterator<MIDIInput>;
get(key: string): MIDIInput;
has(key: string): boolean;
}
/**
* This type is used to represent all the currently available MIDI output ports as a MapClass-like interface.
*/
export interface MIDIOutputMap{
size: number;
keys: ()=>Iterator<string>;
entries: ()=>Iterator<Tuple2<string, MIDIOutput>>;
values(): Iterator<MIDIOutput>;
get(key: string): MIDIOutput;
has(key: string): boolean;
}
/**
* This interface provides the methods to list MIDI input and output devices, and obtain access to an individual device.
*/
export interface MIDIAccess extends EventTarget{
inputs: MIDIInputMap;
outputs: MIDIOutputMap;
onconnect: (event: MIDIConnectionEvent)=>void;
ondisconnect: (event: MIDIConnectionEvent)=>void;
sysexEnabled: boolean;
}
/**
* This interface represents a MIDI input or output port.
*/
export enum MIDIPortType{
input,
output
}
/**
* This interface represents a MIDI input or output port.
*/
export interface MIDIPort extends EventTarget {
id: string;
manufacture?: string;
name?: string;
type: MIDIPortType;
version?: string;
ondisconnect: Function;
}
/**
* Interface for midi inputs
*/
export interface MIDIInput{
onmidimessage: (event: MIDIMessageEvent)=>void;
}
/**
* Interface for midi outputs
*/
export interface MIDIOutput{
send(data: Array<number>, timestamp?: number): void;
}
/**
* An event object implementing this interface is passed to a MIDIInput's onmidimessage handler when MIDI messages are received.
*/
export interface MIDIMessageEvent extends Event{
receivedTime: number;
data: Uint8Array;
}
export interface MIDIMessageEventInit{
receivedTime: number;
data: Uint8Array;
}
/**
* An event object implementing this interface is passed to a MIDIAccess' ondisconnect handler
*/
export interface MIDIConnectionEvent extends Event{
port: MIDIPort;
}
export interface MIDIConnectionEventInit{
port: MIDIPort;
}
}