Permalink
Browse files

persist midi config in localStorage

  • Loading branch information...
wizgrav committed Dec 31, 2017
1 parent 71f71d2 commit 13d02566defb947456a6dbb496f5e460057db775
Showing with 33 additions and 15 deletions.
  1. +1 −1 index.css
  2. +21 −6 tool/main.js
  3. +11 −8 tool/tool.html
View
@@ -71,7 +71,7 @@ button {
button.disabled {
background-color: #000;
color: white;
opacity:0.66;
opacity:0.5;
}
button:hover {
background-color: white;
View
@@ -136,7 +136,8 @@ var TRACK = getParameterByName("track");
function getChunk(s) {
var v = document.querySelector("div." + s + " input[type=text]").value;
var c = document.querySelector("div." + s + " input[type=checkbox]").checked;
if ( v ) localStorage.setItem("clubber-tool-"+s, v); else localStorage.removeItem("clubber-tool-"+s);
if ( v ) localStorage.setItem("clubber-tool-"+s, v); else localStorage.removeItem("clubber-tool-"+s);
midiConfig[["red", "green", "blue", "alpha"].indexOf(s)].enabled = c;
return v && c ? v : "0.0";
}
@@ -389,7 +390,7 @@ var midiConfig = [
{dev: null, channel: 0, ctrl: 0, min: 0, max: 127, id: 0}
];
function setMidi(el, id) {
function setMidi(el, id, pres) {
var da = [null];
var sa = [
"Setup midi controller output for this field",
@@ -405,12 +406,15 @@ function setMidi(el, id) {
sa.push(i + ") " + d.name);
});
var mc = midiConfig[id];
var res = prompt(sa.join("\n"), [mc.id, mc.channel, mc.ctrl, mc.min, mc.max].join(" ") );
var res = pres || prompt(sa.join("\n"), [mc.id, mc.channel, mc.ctrl, mc.min, mc.max].join(" ") );
var ra = res ? res.split(" ") : [0];
var parentClass = el.parentNode.classList.value;
el.textContent = "MIDI";
el.classList.add("disabled");
localStorage.removeItem("midi-" + parentClass);
if(!ra.length || ra[0] == "0") {
mc.dev = null;
return;
@@ -428,12 +432,23 @@ function setMidi(el, id) {
mc.max = ra[4] ? parseInt(ra[4]) : mc.max;
el.textContent = mc.ctrl;
el.title = ["Device" + mc.dev.name, "Channel: " + mc.channel, "Ctrl: " + mc.ctrl].join(", ");
el.title = [
"DEV: " + mc.dev.name,
"CHAN: " + mc.channel,
"CTRL: " + mc.ctrl,
"RANGE: " + mc.min + " - " + mc.max
].join(", ");
el.classList.remove("disabled");
localStorage.setItem("midi-" + parentClass, [mc.id, mc.channel, mc.ctrl, mc.min, mc.max].join(" "));
}, false);
}
["red", "green", "blue", "alpha"].forEach(function (s, i) {
var ms = localStorage.getItem("midi-"+s);
if(ms) { setMidi(document.querySelector("#editor > div."+s+" > button"), i, ms); }
});
function render(time) {
currentTime = time;
window.requestAnimationFrame(render);
@@ -454,7 +469,7 @@ function render(time) {
return minVal * (1 - val) + maxVal * val;
}
if(mc.dev) {
if(mc.dev && mc.enabled) {
mc.dev.send([176 + mc.channel, mc.ctrl, midiMix(mc.min, mc.max, uniforms.iClubber[i])]);
}
uniforms.iMusic.set( modFn.internal.bands[i], 4 * i);
View
@@ -93,7 +93,9 @@
height:1.6vh;
position:absolute;
right:0;
top:0.66vh;
top: 0;
bottom: 0;
margin:auto;
}
input[type=number] {
@@ -105,16 +107,17 @@
#editor > div > button {
z-index: 1;
height: 2vh;
font-size: 1.5vh;
width: 4vh;
height: 1.8vh;
font-size: 1.2vh;
width: 3.33vh;
position: absolute;
right: 2vh;
background-color: grey;
top: 0.1vh;
top: 0;
padding: 0;
border-radius: 0.66vh;
border-radius: 0.33vh;
border: none;
bottom: 0;
margin: auto;
}
#editor div.red input[type=text]{
@@ -336,7 +339,7 @@
<div class="blue">
<div></div>
<input type="text" onkeyup="if(event.keyCode == 13) reMod()" />
<input type="checkbox" onchange="reloadAll()" checked/>
<input type="checkbox" onchange="reMod()" checked/>
<button title="midi out" class="midi disabled" onclick="setMidi(this, 2)">MIDI</button>
</div>
<div class="alpha">

0 comments on commit 13d0256

Please sign in to comment.