/* globals Tone, nx */ //nexusUI setup nx.showLabels = true; nx.colorize("accent", "#D76767"); nx.colorize("fill", "#fff"); var Interface = {}; $(function(){ var topbar = $("
").addClass("language-javascript Code");
element.append(codeContainer);
var code = $("#"+codeID);
var codeText = code.text();
var lines = codeText.split("\n");
//remove the same level of indentation for everyone
while(lines[1].charAt(0)==="\t"){
for (var i = 0; i < lines.length; i++){
var line = lines[i];
lines[i] = line.substr(1);
}
}
codeText = lines.join("\n");
codeContainer.text(codeText);
codeContainer.addClass("Code");
};
Interface.Knob = function(container, node, parameter, min, max, exp){
return Interface.ContinuousControl(container, "dial", node, parameter, min, max, exp);
};
Interface.Momentary = function(container, callback){
var button = nx.add("button", {
"parent" : container
});
button.on("press", function(val){
callback(val === 1);
});
};
Interface.AmplitudeEnvelope = function(container, node){
var element = $("#"+container);
var group = $("").addClass("Envelope")
.appendTo(element);
var attack = Interface.Knob(group[0], node, "attack", 0.001, 2, 2);
var decay = Interface.Knob(group[0], node, "decay", 0.0, 2, 2);
var sustain = Interface.Knob(group[0], node, "sustain", 0, 1, 2);
var release = Interface.Knob(group[0], node, "release", 0.001, 4, 2);
var labels = $("").attr("id", "Labels")
.appendTo(group);
$("").appendTo(labels).addClass("Label").text("attack");
$("").appendTo(labels).addClass("Label").text("decay");
$("").appendTo(labels).addClass("Label").text("sustain");
$("").appendTo(labels).addClass("Label").text("release");
return {
listen : function(){
attack.listen();
decay.listen();
release.listen();
sustain.listen();
}
};
};
Interface.Loading = function(containerID, callback){
var element = $("#"+containerID);
element.addClass("LoadingBar");
var loader = $("").appendTo(element)
.attr("id", "Loader");
Tone.Buffer.onprogress = function(percent){
loader.width((percent * 100) + "%");
};
Tone.Buffer.onload = function(){
element.css({
height: 0,
opacity : 0,
margin: 0
});
setTimeout(function(){
element.remove();
}, 500);
if (callback){
callback();
}
};
};
Interface.Range = function(containerID, callback){
var range = nx.add("range", {
"parent" : containerID
});
range.label = "";
range.on("*", callback);
return range;
};
Interface.Meter = function(container, node, label, units){
var meter = new Tone.Meter();
node.connect(meter);
var element = $("").appendTo("#"+container)
.addClass("Meter");
label = label || "";
units = units || "";
$("").appendTo(element)
.text(label)
.attr("id", "Label");
var value = $("").appendTo(element)
.attr("id", "Value");
$("").appendTo(element)
.text(units)
.attr("id", "Units");
function update(){
requestAnimationFrame(update);
value.text(meter.getValue().toFixed(3));
}
update();
};