mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-28 04:50:03 +00:00
add midi/midi.d.ts
This commit is contained in:
69
midi/midi-tests.ts
Normal file
69
midi/midi-tests.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
/// <reference path="midi.d.ts" />
|
||||
/// <reference path="../es6-promise/es6-promise.d.ts" />
|
||||
|
||||
if (navigator.requestMIDIAccess !== undefined) {
|
||||
navigator.requestMIDIAccess().then(onSuccessCallback, onErrorCallback);
|
||||
}
|
||||
|
||||
var onSuccessCallback = (item: Midi.MIDIAccess)=>{
|
||||
this._midiPort = item;
|
||||
|
||||
item.onconnect = (event: Midi.MIDIConnectionEvent)=>{
|
||||
console.log("onconnect");
|
||||
console.log(event);
|
||||
};
|
||||
|
||||
item.ondisconnect = (event: Midi.MIDIConnectionEvent)=>{
|
||||
console.log("ondisconnect");
|
||||
console.log(event);
|
||||
};
|
||||
|
||||
console.log("sysexenabled");
|
||||
console.log(item.sysexEnabled);
|
||||
|
||||
/*
|
||||
console.log(item.inputs.get("701435409"));
|
||||
console.log(item.inputs.has("701435409"));
|
||||
console.log(item.inputs.keys());
|
||||
console.log(item.inputs.keys().next());
|
||||
console.log(item.inputs.values());
|
||||
var inputs = this._midiPort.inputs.values();
|
||||
console.log(this._midiPort.inputs.entries().next());
|
||||
console.log(this._midiPort.inputs.entries().next().done);
|
||||
*/
|
||||
|
||||
var inputs = this._midiPort.inputs.values();
|
||||
|
||||
/*
|
||||
console.log(item.outputs.get("384570428"));
|
||||
console.log(item.outputs.has("384570428"));
|
||||
console.log(item.outputs.keys());
|
||||
console.log(item.outputs.keys().next());
|
||||
console.log(item.outputs.values());
|
||||
console.log(this._midiPort.outputs.entries().next());
|
||||
console.log(this._midiPort.outputs.entries().next().done);
|
||||
*/
|
||||
|
||||
for(var o = inputs.next(); !o.done; o = inputs.next()){
|
||||
this._inputs.push(o.value);
|
||||
console.log(o.value);
|
||||
}
|
||||
|
||||
var outputs = item.outputs.values();
|
||||
for(var op = outputs.next(); !op.done; op = outputs.next()){
|
||||
this._outputs.push(op.value);
|
||||
op.value.send([ 0x90, 0x45, 0x7f ] );
|
||||
}
|
||||
|
||||
for(var cnt = 0; cnt < this._inputs.length; cnt++){
|
||||
this._inputs[cnt].onmidimessage = (event: Midi.MIDIMessageEvent)=>{
|
||||
this.onMidiMessage(event.data);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
var onErrorCallback = (access: Error)=>{ };
|
||||
|
||||
var onMidiMessage = (event: Uint8Array)=>{
|
||||
console.log(event);
|
||||
};
|
||||
131
midi/midi.d.ts
vendored
Normal file
131
midi/midi.d.ts
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
// 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?: Midi.MidiOptions): Promise<Midi.MIDIAccess>;
|
||||
}
|
||||
|
||||
declare module Midi{
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user