Created
February 2, 2017 22:14
-
-
Save eeropic/9fefe0b0c328f27838b81c586dff70d1 to your computer and use it in GitHub Desktop.
no description yet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var log = console.log.bind(console); | |
var data, cmd, channel, type, note, velocity; | |
if (navigator.requestMIDIAccess){ | |
navigator.requestMIDIAccess({ | |
sysex: false | |
}).then(onMIDISuccess, onMIDIFailure); | |
} else { | |
alert("No MIDI support in your browser."); | |
} | |
function onMIDISuccess(midiAccess) { | |
midi = midiAccess; | |
var inputs = midi.inputs.values(); | |
for (var input = inputs.next(); input && !input.done; input = inputs.next()) { | |
if(input.value.id==1757342049){ | |
input.value.onmidimessage = onMIDIMessage; | |
console.log('jees') | |
} | |
listInputs(input); | |
} | |
var outputs = midi.outputs.values(); | |
for (var output = outputs.next(); output && !output.done; output = outputs.next()) { | |
listOutputs(output); | |
} | |
midi.onstatechange = onStateChange; | |
inputPort = midi.inputs.get(-1686312560); | |
outputPort = midi.outputs.get(789053814); | |
/* | |
Input port input -1686312560 Apple Inc. IAC Driver Bus 1 | |
Output port output 789053814 Apple Inc. IAC Driver Bus 1 | |
Input port input 1757342049 Apple Inc. IAC Driver IAC Bus 2 | |
*/ | |
} | |
function onMIDIMessage(event) { | |
console.log(event.data) | |
data = event.data, | |
cmd = data[0] >> 4, | |
channel = data[0] & 0xf, | |
type = data[0] & 0xf0, | |
note = data[1], | |
velocity = data[2]; | |
// note off: 128, cmd: 8 - note on: 144, cmd: 9 | |
// pressure / tilt on - pressure: 176, cmd 11: | |
// bend: 224, cmd: 14 | |
//console.log(cmd,channel,type,note,velocity) | |
pathName='c'+note; | |
var item=project.activeLayer.children[pathName]; | |
if(item==null){ | |
test=new Path(); | |
test.add([note*5,127]) | |
test.add([note*5,velocity]) | |
test.strokeColor="red" | |
test.strokeWidth=2; | |
test.name=pathName; | |
} | |
if(item!=null){ | |
item.segments[0].point.x=note*5; | |
item.segments[0].point.y=127; | |
item.segments[1].point.x=note*5; | |
item.segments[1].point.y=127-velocity; | |
} | |
switch (type) { | |
case 144: | |
noteOn(channel, note, velocity); | |
console.log('noteon'); | |
break; | |
case 128: | |
noteOff(channel, note, velocity); | |
console.log('noteoff'); | |
break; | |
} | |
} | |
function onStateChange(event) { | |
var port = event.port, state = port.state, name = port.name, type = port.type; | |
if (type == "input") console.log("name", name, "port", port, "state", state); | |
if (type == "output") console.log("name", name, "port", port, "state", state); | |
} | |
function listInputs(inputs) {var input = inputs.value;log("Input port " +input.type, input.id,input.manufacturer,input.name,input.version);} | |
function listOutputs(outputs) {var output = outputs.value;log("Output port " +output.type, output.id, output.manufacturer, output.name, output.version);} | |
function onMIDIFailure(e) {log("No access to MIDI devs or your browser doesn't WebMIDI" + e);} | |
currentChord=[]; | |
keysDown=0; | |
function noteOn(midiChannel, midiNote, velocity) { | |
//var message = [144,midiNote,velocity]; | |
//outputPort.send(message); | |
} | |
function noteOff(midiChannel, midiNote, velocity) { | |
//var message = [128,midiNote,velocity]; | |
//outputPort.send(message); | |
} | |
function onFrame(){ | |
} | |
function onKeyDown(event){ | |
if(event.key=="r"){ | |
for(var i=0;i<87;i++){ | |
outputPort.send([176,i,Math.floor(Math.random()*127)]); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment