mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
* Update webmidi typings * Add eventlistener overloads * Update 'type' field to string literal to allow for use as a discriminated union * Fix lint * Update comment * Fix lint & tests
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
const onFulfilled = (item: WebMidi.MIDIAccess) => {
|
|
const midiPort = item;
|
|
|
|
midiPort.onstatechange = event => {
|
|
console.log('onstatechange');
|
|
console.log(event);
|
|
};
|
|
midiPort.addEventListener('statechange', event => {
|
|
console.log(event.port);
|
|
});
|
|
|
|
console.log('sysexenabled');
|
|
console.log(item.sysexEnabled);
|
|
|
|
const outputs = item.outputs.values();
|
|
for (const op of outputs) {
|
|
op.send([0x90, 0x45, 0x7f]);
|
|
op.send(new Uint8Array([0x90, 0x45, 0x7f]));
|
|
}
|
|
|
|
const inputs = midiPort.inputs.values();
|
|
for (const input of inputs) {
|
|
input.onmidimessage = event => {
|
|
console.log(event.data);
|
|
};
|
|
input.addEventListener('midimessage', event => {
|
|
console.log(event.data);
|
|
});
|
|
}
|
|
|
|
const inputOrOutput = [...inputs, ...outputs][0];
|
|
if (inputOrOutput.type === 'output') {
|
|
// 'send' only available on outputs
|
|
inputOrOutput.send([12345]);
|
|
}
|
|
};
|
|
|
|
const onRejected = (e: Error) => {
|
|
console.error(e);
|
|
};
|
|
|
|
if (navigator.requestMIDIAccess !== undefined) {
|
|
navigator.requestMIDIAccess().then(onFulfilled, onRejected);
|
|
}
|