-
-
Save livacengiz/8ede7b31a36ce2f1cfdaeabb50bcd1f1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// | |
// defino mis variables | |
let cc = Array(128).fill(0) | |
let notes = Array(128).fill(0) | |
let lastCc = 0 | |
let lastNote = 0 | |
let lastOctave = 0 | |
let lastRelNote = 0 | |
// | |
// declaro un handler de eventos midi | |
const midiHandler = (e) => { | |
const m = e.data | |
// extraigo el tipo de midi channel message | |
const type = m[0] & 0xF0 | |
if(type===0x90){ | |
// note on | |
lastNote = m[1] | |
// guardo la ultima nota relativa (C:0, C#:1,...B:11) | |
lastRelNote = lastNote % 12 | |
lastOctave = lastNote / 12 | |
notes[lastNote] = m[2] | |
}else if(type===0x80){ | |
// note off | |
// podria ejecutar algo en el note off, pero no me interesa | |
}else if(type===0xB0){ | |
// control change | |
lastCc = m[1] | |
cc[lastCc] = m[2] | |
} | |
} | |
// | |
// pido acceso a los dispositivos midi | |
// y seteo el handler anterior a cada input midi | |
navigator.requestMIDIAccess().then(ma => { | |
for (var input of ma.inputs.values()) | |
input.onmidimessage = midiHandler | |
}) | |
// | |
// cambio de shape segun la ultima nota (relativa) tocada (+3, minimo: triangulo) | |
// y rotacion por rueda de modulacion | |
shape(()=>(lastRelNote+3)).rotate(()=>cc[1]/128.0*3.14*2).out() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment