/* globals Tone, nx */ //nexusUI setup nx.showLabels = true; nx.colorize("accent", "#D76767"); nx.colorize("fill", "#fff"); // nx.colorize("border", "#000"); var Interface = {}; $(function(){ var topbar = $("
").attr("id", "TopBar"); $("body").prepend(topbar); $("
") .attr("id", "Homepage") .attr("title", "github") .html("Tone.js") .appendTo(topbar); $("
") .attr("id", "Examples") .attr("title", "examples") .html("examples") .appendTo(topbar); //get the master output if (Tone && Tone.Master){ var meter = new Tone.Meter(2); Tone.Master.connect(meter); var meterElement = $("
").attr("id", "Meter").appendTo(topbar); var leftLevel = $("
").addClass("Level") .attr("id", "Left") .appendTo(meterElement); var rightLevel = $("
").addClass("Level") .attr("id", "Right") .appendTo(meterElement); function update(){ requestAnimationFrame(update); var leftHeight = 100 - Math.max(Math.min(Math.abs(meter.getDb(0)), 100), 0); var rightHeight = 100 - Math.max(Math.min(Math.abs(meter.getDb(1)), 100), 0); leftLevel.height(leftHeight + "%"); rightLevel.height(rightHeight + "%"); } update(); } }); $(window).resize(function(){ for (var name in nx.widgets){ var widg = nx.widgets[name]; widg.init(); } }); Interface._updateList = []; Interface.update = function(){ requestAnimationFrame(Interface.update); for (var i = 0; i < Interface._updateList.length; i++){ Interface._updateList[i](); } }; Interface.update(); Interface.getElement = function(el){ if (typeof el === "string"){ return $("#"+el); } else { return $(el); } }; Interface.Rack = function(id, name, collapsible){ var element = Interface.getElement(id); element.addClass("Rack"); var title = $("
").addClass("Title").text(name); element.prepend(title); title.on("click touch", function(){ element.toggleClass("Expanded"); }); if (collapsible){ element.addClass("Collapsible"); } return { close : function(){ element.removeClass("Expanded"); }, open : function(){ element.addClass("Expanded"); } }; }; Interface.Group = function(containerID, name){ var container = Interface.getElement(containerID); var element = container.addClass("Group"); $("
").text(name).appendTo(element).attr("id", "Label"); return element; }; Interface.Toggle = function(container, callback){ var toggle = nx.add("toggle", { parent : container }); toggle.on("value", function(val){ callback(val === 1); }); }; Interface.DropDown = function(container, node, parameter, options, label){ var element = $("
").appendTo(Interface.getElement(container)) .addClass("DropDown"); label = label || parameter; $("
").appendTo(element) .text(label) .attr("id", "Label"); var selectList = $("").appendTo(element); for (var i = 0; i < options.length; i++){ $("