-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmidi.js
More file actions
51 lines (44 loc) · 1.57 KB
/
Copy pathmidi.js
File metadata and controls
51 lines (44 loc) · 1.57 KB
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
var midiaccess
var midiin;
var midiout;
// Console Replacement
!function(o){console.old=console.log,console.log=function(){var n,e,t="";for(e=0;e<arguments.length;e++)t+='<span class="log-'+typeof(n=arguments[e])+'">',"object"==typeof n&&"object"==typeof JSON&&"function"==typeof JSON.stringify?t+=JSON.stringify(n):t+=n,t+="</span> ";y=o.innerHTML;y=t+"<br><br>"+y;o.innerHTML=y,console.old.apply(void 0,arguments)}}
(document.getElementById("logger"));
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
navigator.requestMIDIAccess({ sysex: true })
.then(onMIDISuccess, onMIDIFailure);
function onMIDISuccess(midiAccess) {
midiaccess = midiAccess;
midiAccess.onstatechange = function(e) {
// Print information about the (dis)connected MIDI controller
CheckMidiPorts();
};
CheckMidiPorts();
}
function onMIDIFailure() {
console.log('Could not access your MIDI devices. Either allow access or use a different browser (Chrome or FireFox)');
}
function CheckMidiPorts() {
console.log("Checking for midi devices");
midiin = null;
midiout = null;
for (var input of midiaccess.inputs.values()) {
if(input.name == "Bitfox USBMIDI"){
midiin = input;
input.onmidimessage = getMIDIMessage;
}
}
for (var output of midiaccess.outputs.values()) {
if(output.name == "Bitfox USBMIDI"){
midiout = output;
midialive = false;
}
}
if(midiout == null || midiin == null) {
console.log("No valid Bitfox USBMIDI Device found");
} else {
console.log("Valid Bitfox USBMIDI Device found");
}
}