Skip to content

Instantly share code, notes, and snippets.

@zz85
Last active December 10, 2016 08:02
Show Gist options
  • Save zz85/c6442a25e189584fce820364a9b6c83d to your computer and use it in GitHub Desktop.
Save zz85/c6442a25e189584fce820364a9b6c83d to your computer and use it in GitHub Desktop.
Christmas Lights for Novation Launchpad
<html>
<head>
</head>
<body>
<script>
// Christmas light hack for Web Audio Hack Day 2016
// with vanilla JS tested on chrome and the LaunchPad
let device;
let stop = 0;
navigator
.requestMIDIAccess()
.then((midiAccess) => {
console.log(midiAccess);
// find an output device
for (var output of midiAccess.outputs.values()) {
device = output;
console.log('Output device selected', device);
}
})
.catch((e) => {
console.log(e.stack);
});
// key == midi number
// v == velocity. For color codes see
// https://global.novationmusic.com/sites/default/files/novation/downloads/10529/launchpad-mk2-programmers-reference-guide_0.pdf
function color(key, v) {
device && device.send([0x90, key, v]); // note on
}
setInterval( () => {
if (stop) return;
for (let i = 0; i < 24; i++) {
color(Math.random() * 100 | 0, Math.random() * 128 | 0);
}
}, 150);
function clearAll() {
for (let i = 0; i < 100; i++) {
color(i, 0)
}
stop = 1;
}
function colorAll() {
stop = 0;
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment