Created
April 19, 2015 17:19
-
-
Save uiur/3238fcfba2aa35a86270 to your computer and use it in GitHub Desktop.
MIDIコントローラ寿司回転
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
'use strict' | |
let state = { | |
deg: 0, | |
active: false | |
} | |
function requestMIDI () { | |
return navigator.requestMIDIAccess() | |
.then(function (midi) { | |
let traktor | |
for (let input of midi.inputs.values()) { | |
traktor = input | |
} | |
return traktor | |
}).catch(function (err) { | |
throw err | |
}) | |
} | |
setTimeout(function () { | |
requestMIDI().then(function (midi) { | |
let image = document.querySelector('.image') | |
midi.onmidimessage = function (e) { | |
console.log(e) | |
if (e.data[0] === 176 && e.data[1] === 2) { | |
let delta = e.data[2] === 1 ? 1 : -1 | |
state.deg += delta * 6 | |
} | |
if (e.data[0] === 176 && e.data[1] === 3) { | |
state.active = !state.active | |
} | |
window.requestAnimationFrame(function () { | |
let style = 'rotate(' + state.deg + 'deg)' | |
if (state.active) { | |
style += ' scale(0.9)' | |
} | |
image.style.transform = style | |
}) | |
console.log(state) | |
} | |
}).catch(function (e) { | |
throw e | |
}) | |
}, 100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
左右のshiftキーを同時押ししてMIDIモードを発動させる