text: !function(){function isEmpty(a){return"undefined"==typeof a?!0:null===a?!0:!("number"!=typeof a||!isNaN(a))}function isNumber(a){return!("number"!=typeof a||isNaN(a))}function isInteger(a){return isNumber(a)?Number.isInteger(a):!1}function isString(a){return"string"==typeof a}function isBoolean(a){return"boolean"==typeof a}function isFunction(a){return"function"==typeof a&&!a.hasOwnProperty("meta")}function isPromise(a){return isObject(a)?a.constructor===Promise?!0:void 0:!1}function isObject(a){return"object"==typeof a&&null!==a}function isSingleVal(a){return!(isArray(a)||isDtmObj(a)||isFunction(a)||isEmpty(a))}function isArray(a){return Array.isArray(a)||isFloat32Array(a)}function isFloat32Array(a){var b=!1;return isEmpty(a)||"Float32Array"===a.constructor.name&&a.length>0&&(b=!0),b}function isNumArray(a){var b=!1;return isArray(a)&&!isFloat32Array(a)&&a.length>0&&(b=a.every(function(a){return isNumber(a)})),b}function isNumOrFloat32Array(a){return isNumArray(a)||isFloat32Array(a)}function isMixedArray(a){return!(!isArray(a)||isStringArray(a)||isBoolArray(a)||isNumOrFloat32Array(a)||isNestedArray(a)||isNestedWithDtmArray(a))}function isNestedArray(a){var b=!1;return isArray(a)&&(b=a.some(function(a){return isArray(a)})),b}function isNestedWithDtmArray(a){var b=!1;return isArray(a)&&(b=a.some(function(a){return isDtmArray(a)})),b}function getMaxArrayDepth(a){if(isArray(a)){var b=1,c=[];return a.forEach(function(a){isArray(a)&&c.push(getMaxArrayDepth(a))}),c.length>0&&(b+=Math.max.apply(this,c)),b}return 0}function getMaxDtmArrayDepth(a){if(isDtmArray(a)){var b=1,c=[];return a.forEach(function(a){isDtmArray(a)&&c.push(getMaxDtmArrayDepth(a))}),c.length>0&&(b+=Math.max.apply(this,c)),b}return 0}function getMaxDepth(a){if(isArray(a)||isDtmArray(a)){var b=1,c=[];return a.forEach(function(a){(isArray(a)||isDtmArray(a))&&c.push(getMaxDepth(a))}),c.length>0&&(b+=Math.max.apply(this,c)),b}return 0}function isDtmObj(a){return isObject(a)||"function"==typeof a?a.hasOwnProperty("meta"):!1}function isDtmArray(a){return(isObject(a)||"function"==typeof a)&&a.hasOwnProperty("meta")?"dtm.array"===a.meta.type||"dtm.generator"===a.meta.type:!1}function isNestedDtmArray(a){return isDtmArray(a)?a.every(function(a){return isDtmArray(a)}):!1}function isNumDtmArray(a){return isDtmArray(a)&&isNumOrFloat32Array(a.get())}function isNestedNumDtmArray(a){return isNestedDtmArray(a)&&a.get().every(function(a){return isNumDtmArray(a)})}function isStringArray(a){var b=!1;return isArray(a)&&(b=a.every(function(a){return isString(a)})),b}function isBoolArray(a){var b=!1;return isArray(a)&&(b=a.every(function(a){return isBoolean(a)})),b}function hasMissingValues(a){return a.some(function(a){return isEmpty(a)})}function arrayCompare(){}function objCompare(a,b){var c=!1;return isFunction(a)&&isFunction(b)?a.toString()===b.toString():isObject(a)&&isObject(b)?JSON.stringify(a)===JSON.stringify(b):c}function argsToArray(a){for(var b=[],c=0;c<a.length;c++)b[c]=a[c];return b}function argsForEach(a,b){argsToArray(a).forEach(function(){b.apply(this,arguments)})}function argIsSingleArray(a){return!(1!==a.length||!isArray(a[0]))}function argsAreSingleVals(a){var b=!1;if(!argIsSingleArray(a)){var c=argsToArray(a);b=c.every(function(a){return isSingleVal(a)})}return b}function toFloat32Array(a){if(isNumber(a))return new Float32Array([a]);if(!isDtmObj(a)){if(isNumOrFloat32Array(a)){if(isFloat32Array(a))return a;var b=new Float32Array(a.length);return a.forEach(function(a,c){b[c]=a}),b}return null}if(isDtmArray(a)){if(isNumArray(a.get()))return new Float32Array(a.get());if(isFloat32Array(a.get()))return a.get();if(isNestedWithDtmArray(a.get()))return toFloat32Array(a.get("next"))}else if("dtm.model"===a.meta.type)return new Float32Array(a.get())}function fromFloat32Array(a){return Array.prototype.slice.call(a)}function Float32Concat(a,b){var c=a.length,d=new Float32Array(c+b.length);return d.set(a),d.set(b,c),d}function concat(a,b){return isFloat32Array(a)||isFloat32Array(b)?(isNumber(a)&&(a=new Float32Array([a])),isNumber(b)&&(b=new Float32Array([b])),Float32Concat(a,b)):a.concat(b)}function Float32Splice(a,b){var c=new Float32Array(a.length-b),d=Array.prototype.slice.call(a);return c.set(d.splice(b)),c}function splice(a,b){return isArray(a)?a.splice(b):isFloat32Array(a)?Float32Splice(a,b):void 0}function truncateDigits(a){var b=10;return Math.round(a*Math.pow(10,b))/Math.pow(10,b)}function Float32Map(a,b){var c=new Float32Array(a.length);return a.forEach(function(a,d){c[d]=b(a)}),c}function deferCallback(a,b){var c=0;return isNumber(b)&&b>0&&(c=b),isFunction(a)?function(){var b=arguments;setTimeout(function(){a.apply(this,b)},c)}:void 0}function cloneArray(a){return isArray(a)||isFloat32Array(a)?a.slice(0):void 0}function objForEach(a,b){var c=[];if("object"==typeof a){for(var d in a)a.hasOwnProperty(d)&&"function"==typeof b&&c.push(b(a[d],d));return c}}function numProperties(a){var b=0;return isObject(a)&&objForEach(a,function(){b++}),b}function loadBuffer(a){var b={};return actx.decodeAudioData(a,function(a){b=a}),b}function getMin(a){return isNumOrFloat32Array(a)?Math.min.apply(this,a):void 0}function getMax(a){return isNumOrFloat32Array(a)?Math.max.apply(this,a):void 0}function mean(a){return isNumOrFloat32Array(a)?sum(a)/a.length:void 0}function mode(a){var b=unique(a),c=0,d=0,e=null,f=countBy(a);return b.forEach(function(a){d=f[a],d>c&&(e=a,c=d)}),e}function median(a){var b=a.sort(),c=a.length;return c%2===0?(b[c/2-1]+b[c/2])/2:b[Math.floor(c/2)]}function midrange(a){var b=getMax(a),c=getMin(a);return(b+c)/2}function sum(a){return a.reduce(function(a,b){return a+b})}function variance(a){var b=mean(a),c=[];return a.forEach(function(a,d){c[d]=Math.pow(b-a,2)}),sum(c)/(a.length-1)}function std(a){return Math.sqrt(variance(a))}function pvar(a){var b=mean(a),c=[];return a.forEach(function(a,d){c[d]=Math.pow(b-a,2)}),mean(c)}function pstd(a){return Math.sqrt(pvar(a))}function rms(a){var b=[];return a.forEach(function(a,c){b[c]=Math.pow(a,2)}),Math.sqrt(mean(b))}function unique(a){var b=[];return a.forEach(function(a){-1===b.indexOf(a)&&b.push(a)}),b}function histo(a){var b=[],c=cloneArray(a),d=countBy(a);return c.forEach(function(a,c){b[c]=d[a]}),b}function countBy(a){var b={};return a.forEach(function(a){b.hasOwnProperty(a)?b[a]++:b[a]=1}),b}function listClasses(a){return unique(a).sort()}function uniformity(a){return listClasses(a).length/a.length}function intersection(a,b){return a.filter(function(a){return-1!==b.indexOf(a)})}function rescale(a,b,c,d){d=d||!1;var e=a*(c-b)+b;return d&&(e=Math.round(e)),e}function expCurve(a,b){return b=1>=b?1.000001:b,(Math.exp(a*Math.log(b))-1)/(b-1)}function logCurve(a,b){return b=1>=b?1.000001:b,Math.log(a*(b-1)+1)/Math.log(b)}function mtof(a){return 440*Math.pow(2,(a-69)/12)}function ftom(a){return 12*Math.log2(a/440)+69}function pq(a,b,c){var d={0:["do","d"],1:["di","ra"],2:["re","r"],3:["ri","me"],4:["mi","m","fe"],5:["fa","f"],6:["fi","se"],7:["sol","s"],8:["si","le"],9:["la","l"],10:["li","te"],11:["ti","t","de"]},e=[];isNumOrFloat32Array(b)?e=b:isStringArray(b)?b.forEach(function(a){objForEach(d,function(b,c){b.indexOf(a.toLowerCase())>-1&&e.push(parseInt(c))})}):isArray(b)||(e=[0,1,2,3,4,5,6,7,8,9,10,11]),isEmpty(c)&&(c=!1);var f=a%12,g=a-f,h=Math.floor(f/12*e.length),i=0;return c||(i=a%1),g+e[h]+i}function mod(a,b){return(a%b+b)%b}function randi(a,b){var c,d;return isNumber(a)||isNumber(b)?isNumber(a)&&!isNumber(b)?(c=0,d=a):isNumber(a)&&isNumber(b)&&(c=a,d=b):(c=0,d=1),Math.floor(Math.random()*(d-c)+c)}function random(a,b){var c,d;return isNumber(a)||isNumber(b)?isNumber(a)&&!isNumber(b)?(c=0,d=a):isNumber(a)&&isNumber(b)&&(c=a,d=b):(c=0,d=1),Math.random()*(d-c)+c}function clone(a){return Object.assign({},a)}function jsonp(a){var b="jsonp_callback_"+Math.round(1e5*Math.random());window[b]=function(a){delete window[b],document.body.removeChild(c);var d=Object.keys(a);d.forEach(function(b){"response"!==b&&console.log(a[b])})};var c=document.createElement("script");c.src=a+(a.indexOf("?")>=0?"&":"?")+"callback="+b,document.body.appendChild(c)}function ajaxGet(a){var b=new XMLHttpRequest;b.open("GET",a,!0),b.setRequestHeader("Accept","text/xml"),b.setRequestHeader("Content-Type","application/html"),b.setRequestHeader("Access-Control-Allow-Origin","*"),b.setRequestHeader("Access-Control-Allow-Methods","GET, POST, PUT"),b.setRequestHeader("Access-Control-Allow-Headers","X-Requested-With");var c=a.split(".").pop();switch(c){case"txt":case"csv":break;case"json":break;case"wav":case"aif":case"aiff":case"ogg":case"mp3":b.responseType="arraybuffer";break;case"html":b.responseType="document";break;default:b.responseType="blob"}b.onreadystatechange=function(){4==b.readyState&&200==b.status&&console.log(b.response)},b.send()}function morphFixed(a,b,c){isNumber(c)||(c=.5);var d=[];return a.forEach(function(a,e){d[e]=(b[e]-a)*c+a}),d}var params={isLogging:!0},dtm={version:"0.0.5",log:function(a){params.isLogging&&console.log(arguments.callee.caller.name?arguments.callee.caller.name+": "+a:a)},modelColl:[],modelCallers:{},clocks:[],params:{},get:function(a){switch(a){case"models":return dtm.modelColl;case"modelNames":var b=[];return dtm.modelColl.forEach(function(a){b.push(a.get("name"))}),b;default:return null}},wa:{isOn:!0,useOfflineContext:!1},startWebAudio:function(){dtm.wa.isOn=!0,dtm.wa.actx=new(window.AudioContext||window.webkitAudioContext),dtm.wa.now=function(){return dtm.wa.actx.currentTime},dtm.wa.out=function(){return dtm.wa.actx.destination},dtm.wa.clMult=.01,dtm.wa.clockBuf=dtm.wa.actx.createBuffer(1,Math.round(dtm.wa.actx.sampleRate*dtm.wa.clMult),dtm.wa.actx.sampleRate),dtm.wa.makeNoise=function(a){var b=dtm.wa.actx;a=a||4192;var c=b.createBuffer(1,a,dtm.wa.actx.sampleRate),d=c.getChannelData(0);return dtm.gen("range",a).get().forEach(function(a){d[a]=random(-1,1)}),c},dtm.wa.makeIr=function(a){var b=dtm.wa.actx,c=Math.round(a*dtm.wa.actx.sampleRate)||dtm.wa.actx.sampleRate,d=b.createBuffer(2,c,dtm.wa.actx.sampleRate),e=d.getChannelData(0),f=d.getChannelData(1),g=10;return dtm.gen("range",c).get().forEach(function(a){e[a]=rescale(expCurve(random(0,1)*(c-a)/c,g),-1,1),f[a]=rescale(expCurve(random(0,1)*(c-a)/c,g),-1,1)}),d},dtm.wa.buffs={verbIr:dtm.wa.makeIr(2)}},oscParams:{isOpen:!1,port:null},startOsc:function(){dtm.osc.isOn=!0,dtm.osc.start()},"export":function(){objForEach(dtm,function(a,b){isEmpty(window[b])&&(window[b]=a)})}};this.dtm=dtm,dtm.loadData=function(a,b){return new Promise(function(c,d){var e=new XMLHttpRequest;e.open("GET",a,!0);var f=a.split(".").pop();switch(f){case"txt":case"csv":break;case"json":e.responseType="json";break;case"wav":case"aif":case"aiff":case"ogg":case"mp3":e.responseType="arraybuffer";break;default:e.responseType="blob"}e.onreadystatechange=function(){4==e.readyState&&200==e.status?("undefined"!=typeof b&&b(e.response),c(e.response)):d(e.status)},e.send()})},dtm.loadAudio=function(a,b){return new Promise(function(c){var d=new XMLHttpRequest;d.open("GET",a,!0),d.responseType="arraybuffer",d.onreadystatechange=function(){4==d.readyState&&200==d.status&&actx.decodeAudioData(d.response,function(a){c(a),"undefined"!=typeof b&&b(a)})},d.send()})},Float32Array.prototype.forEach||(Float32Array.prototype.forEach=function(a,b){var c,d;if(null==this)throw new TypeError(" this is null or not defined");var e=Object(this),f=e.length>>>0;if("function"!=typeof a)throw new TypeError(a+" is not a function");for(arguments.length>1&&(c=b),d=0;f>d;){var g;d in e&&(g=e[d],a.call(c,g,d,e)),d++}}),Float32Array.prototype.some||(Float32Array.prototype.some=function(a){"use strict";if(null==this)throw new TypeError("Array.prototype.some called on null or undefined");if("function"!=typeof a)throw new TypeError;for(var b=Object(this),c=b.length>>>0,d=arguments.length>=2?arguments[1]:void 0,e=0;c>e;e++)if(e in b&&a.call(d,b[e],e,b))return!0;return!1}),Float32Array.prototype.map||(Float32Array.prototype.map=function(a,b){var c,d,e;if(null==this)throw new TypeError(" this is null or not defined");var f=Object(this),g=f.length>>>0;if("function"!=typeof a)throw new TypeError(a+" is not a function");for(arguments.length>1&&(c=b),d=new Array(g),e=0;g>e;){var h,i;e in f&&(h=f[e],i=a.call(c,h,e,f),d[e]=i),e++}return d}),Float32Array.prototype.every||(Float32Array.prototype.every=function(a,b){"use strict";var c,d;if(null==this)throw new TypeError("this is null or not defined");var e=Object(this),f=e.length>>>0;if("function"!=typeof a)throw new TypeError;for(arguments.length>1&&(c=b),d=0;f>d;){var g;if(d in e){g=e[d];var h=a.call(c,g,d,e);if(!h)return!1}d++}return!0}),dtm.util={},dtm.util.isEmpty=isEmpty,dtm.util.isNumber=isNumber,dtm.util.isInteger=isInteger,dtm.util.isString=isString,dtm.util.isBoolean=isBoolean,dtm.util.isFunction=isFunction,dtm.util.isPromise=isPromise,dtm.util.isObject=isObject,dtm.util.isSingleVal=isSingleVal,dtm.util.isArray=isArray,dtm.util.isFloat32Array=isFloat32Array,dtm.util.isNumArray=isNumArray,dtm.util.isNumOrFloat32Array=isNumOrFloat32Array,dtm.util.isMixedArray=isMixedArray,dtm.util.isStringArray=isStringArray,dtm.util.isBoolArray=isBoolArray,dtm.util.isNestedArray=isNestedArray,dtm.util.isNestedWithDtmArray=isNestedWithDtmArray,dtm.util.isDtmObj=isDtmObj,dtm.util.isDtmArray=isDtmArray,dtm.util.isNestedDtmArray=isNestedDtmArray,dtm.util.isNumDtmArray=isNumDtmArray,dtm.util.isNestedNumDtmArray=isNestedNumDtmArray,dtm.util.argIsSingleArray=argIsSingleArray,dtm.util.argsAreSingleVals=argsAreSingleVals,dtm.util.getMaxArrayDepth=getMaxArrayDepth,dtm.util.getMaxDtmArrayDepth=getMaxDtmArrayDepth,dtm.util.getMaxDepth=getMaxDepth,dtm.util.hasMissingValues=hasMissingValues,dtm.util.numProperties=numProperties,dtm.util.getMin=getMin,dtm.util.getMax=getMax,dtm.util.mean=mean,dtm.util.mode=mode,dtm.util.midrange=midrange,dtm.util.sum=sum,dtm.util.variance=variance,dtm.util.pvar=pvar,dtm.util.std=std,dtm.util.pstd=pstd,dtm.util.rms=rms,dtm.util.unique=unique,dtm.util.histo=histo,dtm.util.countBy=countBy,dtm.util.listClasses=listClasses,dtm.util.uniformity=uniformity,dtm.util.intersection=intersection,dtm.util.argsToArray=argsToArray,dtm.util.toFloat32Array=toFloat32Array,dtm.util.fromFloat32Array=fromFloat32Array,dtm.util.Float32Concat=Float32Concat,dtm.util.concat=concat,dtm.util.Float32splice=Float32Splice,dtm.util.splice=splice,dtm.util.argsForEach=argsForEach,dtm.util.objForEach=objForEach,dtm.util.Float32Map=Float32Map,dtm.util.truncateDigits=truncateDigits,dtm.util.deferCallback=deferCallback,dtm.util.cloneArray=cloneArray,dtm.osc={type:"dtm.osc",oscPort:null,isOn:!1,isOpen:!1,callbacks:[],start:function(){return"undefined"==typeof osc||dtm.osc.isOpen?dtm.osc.isOpen&&dtm.log("OSC port is already open"):(dtm.osc.isOpen=!0,dtm.log("opening OSC port"),dtm.osc.oscPort=new osc.WebSocketPort({url:"ws://localhost:8081"}),dtm.osc.oscPort.open(),dtm.osc.oscPort.listen(),dtm.osc.oscPort.on("ready",function(){dtm.osc.oscPort.on("message",function(a){switch(a.address){case"/test":}}),dtm.osc.oscPort.on("error",function(a){throw new Error(a)})})),dtm.osc},stop:function(){return dtm.osc.oscPort&&dtm.osc.oscPort.close(1e3),dtm.osc.isOpen=!1,dtm.osc},on:function(a,b){return dtm.osc.oscPort.on("message",function(c){"/"!==a[0]&&(a="/".concat(a)),c.address==a&&b(c.args)}),dtm.osc},send:function(a,b){return"/"!==a[0]&&a.unshift("/"),b.constructor!==Array&&(b=[b]),dtm.osc.oscPort.send({address:a,args:b}),dtm.osc},clear:function(){dtm.osc.callbacks=[]}},dtm.osc.close=dtm.osc.stop,dtm.analyzer={},dtm.anal=dtm.analyzer,dtm.generator=function(){function a(a){return f[a].indexOf(e.type)>-1}function b(){function b(a,b,c){for(var d=new Float32Array(a),e=(c-b)/(a-1),f=0;a>f;f++)d[f]=b+e*f;return d}function f(a,b,c,d,e,f){for(var g=new Float32Array(a),h=0;a>h;h++){var i=mod(h/(a-1)+f/e,1),j=Math.sin(2*Math.PI*i*e)*d;j=(j+1)/2*(c-b)+b,g[h]=j}return g}function g(a,b,c,d,e,f){for(var g=new Float32Array(a),h=0;a>h;h++){var i=mod(h/(a-1)+f,1),j=Math.cos(2*Math.PI*i*e)*d;j=(j+1)/2*(c-b)+b,g[h]=j}return g}function h(a,b,c,d,e){for(var f=new Float32Array(a),g=0;a>g;g++){var h=Math.random()*(c-b)+b;f[g]=e?Math.floor(h)*d:h*d}return f}function i(a,b){var c;c=isNumber(b)?new Float32Array(a):new Array(a);for(var e=0;a>e;e++)c[e]=isNumOrFloat32Array(b)?toFloat32Array(b):isDtmArray(b)?b.parent(d):b;return c}function j(a,b,c){isNumber(c)||0!==c||(c=1);var e=Math.floor((b-a)/c)+1;d.len=e;for(var f=new Float32Array,g=0;e>g;g++)f[g]=a+c*g;return f}function k(a,b,c){isNumber(c)&&0!==c||(c=1),c=b>=a?Math.abs(c):-Math.abs(c);for(var d=Math.ceil(Math.abs(b-a)/Math.abs(c)),e=new Float32Array(d),f=0;d>f;f++)e[f]=a+f*c;return e}function l(a,b){var c=a.map(function(a){return mod(a+b,12)});return dtm.transform.sort(c)}function m(a,b){var c=null,d={chromatic:{names:["chromatic","chr"],values:[0,1,2,3,4,5,6,7,8,9,10,11]},major:{names:["major","maj"],values:[0,2,4,5,7,9,11]},minor:{names:["minor","min"],values:[0,2,3,5,7,8,10]},wholetone:{names:["wholetone","whole","wt"],values:[0,2,4,6,8,10]},majpenta:{names:["penta","pent","majpenta"],values:[0,2,4,7,9]}};return objForEach(d,function(d){-1!==d.names.indexOf(a.toLowerCase())&&(c=new Float32Array(l(d.values,b)))}),c?c:new Float32Array}function n(a){var b=new Float32Array(a);if(b[0]=1,a>1){b[1]=1;for(var c=2;a>c;c++)b[c]=b[c-1]+b[c-2]}return b}d.val=[];var o;switch((a("noMinMaxDir")||a("random"))&&(o=dtm.transform.sort([e.min,e.max])),e.type){case"line":case"saw":d.val=b(d.len,e.min,e.max);break;case"rise":d.val=b(d.len,o[0],o[1]);break;case"decay":case"fall":d.val=b(d.len,o[1],o[0]);break;case"adsr":case"ADSR":break;case"sin":case"sine":d.val=f(d.len,e.min,e.max,e.amp,e.cycle,c.phase);break;case"cos":case"cosine":d.val=g(d.len,e.min,e.max,e.amp,e.cycle,0);break;case"tri":case"triangle":break;case"harm":case"harmonic":break;case"rand":case"random":d.val=h(d.len,o[0],o[1],1,!1);break;case"noise":d.val=h(d.len,o[0],o[1],e.amp,!1);break;case"randi":d.val=h(d.len,o[0],o[1],1,!0);break;case"range":d.val=k(c.start,c.end,c.interval);break;case"seq":d.val=j(e.min,e.max);break;case"scale":d.val=m(c.scale,c.transpose);break;case"fibonacci":d.val=n(d.len);break;case"zeros":case"zeroes":d.val=i(d.len,0);break;case"ones":d.val=i(d.len,1);break;case"const":d.val=i(d.len,e["const"]);break;case"string":case"str":case"s":case"characters":case"character":case"chars":case"char":case"c":d.val=e.string.split("")}d.len=d.val.length}var c={type:null,min:0,max:1,start:0,end:1,interval:null,scale:"chromatic",transpose:0,amp:1,cycle:1,phase:0,"const":0,string:"",pack:!1,typed:!0},d=dtm.array(),e=d.meta.getParams();objForEach(c,function(a,b){e[b]=a}),d.meta={type:"dtm.generator"};var f={all:["line","saw","rise","decay","fall","invSaw","adsr","ADSR","seq","sequence","series","range","scale","mode","chord","fibonacci","noise","random","rand","randi","gauss","gaussian","gaussCurve","normal","sin","sine","cos","cosine","tri","triangle","zeros","zeroes","ones","constant","constants","const","consts","repeat","string","str","s","text","split","character","characters","chars","char","c"],oscil:["sin","sine","cos","cosine","tri","triangle","saw","invSaw","noise","square","sq","harm","harmonic"],"const":["zeros","zeroes","ones","constant","constants","const","consts"],envelope:["rise","decay","fall","ahr"],sequence:[],noLength:["string","str","s","character","characters","chars","char","c","range","seq","scale","mode","chord"],noRange:[],noMinMax:[],noMinMaxDir:["rise","decay","fall","noise"],random:["random","rand","randi"],string:["string","split","str","s","character","characters","chars","char","c","text"]};return d.type=function(a){return isString(a)&&f.all.indexOf(a)>-1&&(e.type=a),b(),d},d.size=function(a){if(isString(a)&&"a"===a[0])return e.autolen=!0,d;var c=parseInt(a);return!isNaN(c)&&c>0&&(d.len=c),b(),d},d.min=function(a){var c=parseFloat(a);return isNaN(c)||(e.min=c),b(),d},d.max=function(a){var c=parseFloat(a);return isNaN(c)||(e.max=c),b(),d},d.start=function(a){return isNumber(a)&&(c.start=a),b(),d},d.end=function(a){return isNumber(a)&&(c.end=a),b(),d},d.interval=function(a){return isNumber(a)&&(c.interval=a),b(),d},d.amp=function(a){var c=parseFloat(a);return isNaN(c)||(e.amp=c),b(),d},d.cycle=function(a){var c=parseFloat(a);return isNaN(c)||(e.cycle=c),b(),d},d.freq=d.cycle,d.phase=function(a){return isNumber(a)&&(c.phase=a),b(),d},d.offset=d.phase,d["const"]=function(a){return isSingleVal(a)&&(e["const"]=a),b(),d},d.transpose=function(a){return isInteger(a)?c.transpose=a:isDtmArray(a)&&(c.transpose=a.get(0)),b(),d},d.len=8,arguments.length>=1&&(isObject(arguments[0])?isArray(arguments[0])||objForEach(arguments[0],function(a){e.hasOwnProperty(a)&&(e[a]=arguments[0][a])}):isString(arguments[0])&&d.type(arguments[0]),isObject(arguments[1])&&(isArray(arguments[1])||objForEach(arguments[1],function(a){e.hasOwnProperty(a)&&(e[a]=arguments[1][a])}))),arguments.length<=2&&(a("oscil")?(e.min=-1,e.max=1):(e.min=0,e.max=1)),a("envelope")&&(d.len=128),a("random")?(d.len=1,e.min=0,e.max="randi"===e.type?2:1,2===arguments.length&&isNumber(arguments[1])?e.max=arguments[1]:3===arguments.length&&(isNumber(arguments[1])&&(e.min=arguments[1]),isNumber(arguments[2])&&(e.max=arguments[2]))):a("oscil")?(d.len=4096,arguments.length>=3&&(isArray(arguments[2])?1===arguments[2].length?d.amp(arguments[2][0]):2===arguments[2].length&&(e.min=arguments[2][0],e.max=arguments[2][1]):d.amp(arguments[2])),3===arguments.length&&(e.min=-1,e.max=1,d.amp(arguments[2])),4===arguments.length&&(isArray(arguments[3])?2===arguments[3].length&&(d.min(arguments[3][0]),d.max(arguments[3][1])):(e.min=-1,e.max=1,d.cycle(arguments[3])))):arguments.length>=2&&(a("string")?isString(arguments[1])?(e.string=arguments[1],e.typed=!1):e.string=String(arguments[1]):"range"===e.type?isNumArray(arguments[1])?(1===arguments[1].length?(d.start(0),d.end(arguments[1][0])):arguments[1].length>=2&&(d.start(arguments[1][0]),d.end(arguments[1][1])),3===arguments[1].length&&d.interval(arguments[1][2])):(2===arguments.length&&isNumber(arguments[1])?(d.start(0),d.end(arguments[1])):arguments.length>=3&&(isNumber(arguments[1])&&d.start(arguments[1]),isNumber(arguments[2])&&d.end(arguments[2])),4===arguments.length&&d.interval(arguments[3])):"seq"===e.type?(e.min=arguments[1],e.max=arguments[2]):"scale"===e.type?(isString(arguments[1])&&(c.scale=arguments[1]),isInteger(arguments[2])&&(c.transpose=arguments[2])):a("const")?isEmpty(arguments[1])||(e["const"]=arguments[1],d.len=1):(d.size(arguments[1]),arguments.length>=3&&(isArray(arguments[2])?1===arguments[2].length?d.max(arguments[2][0]):2===arguments[2].length&&(d.min(arguments[2][0]),d.max(arguments[2][1])):(3===arguments.length&&(d.min(0),d.max(arguments[2]),d.amp(1)),arguments.length>=4&&(d.min(arguments[2]),d.max(arguments[3])))))),b(),d},dtm.g=dtm.gen=dtm.generator;var generators=["line","rise","decay","fall","seq","sequence","series","range","noise","random","rand","randi","gaussian","gaussCurve","gauss","normal","zeros","zeroes","ones","constant","constants","const","consts","repeat","string","str","sin","sine","cos","cosine","tri","triangle","saw","fibonacci","decay","scale"];generators.forEach(function(a){dtm[a]=function(){var b=[a].concat(argsToArray(arguments));return dtm.generator.apply(this,b)}}),dtm.transform={normalize:function(a,b,c){if(isNumOrFloat32Array(a)){isNumber(b)||(b=getMin(a)),isNumber(c)||(c=getMax(a));var d=1;return c===b?b>0&&1>=b?b=0:b>1&&(b-=1):d=c-b,a.map(function(a){return(a-b)/d})}},rescale:function(a,b,c,d,e){var f=dtm.transform.normalize(a,d,e),g=[];return f.forEach(function(a,d){g[d]=truncateDigits(rescale(a,b,c))}),g},expCurve:function(a,b){b=b||1;var c=[];return a.forEach(function(a,d){c[d]=expCurve(a,b)}),c},logCurve:function(a,b){b=b||1;var c=[];return a.forEach(function(a,d){c[d]=logCurve(a,b)}),c},fit:function(a,b,c){c=c||"linear",b=1>b?1:Math.round(b);var d=null;if(isNumArray(a))d=new Array(b);else{if(!isFloat32Array(a))return null;d=new Float32Array(b)}var e=0,f=b/a.length,g=a.length-1,h=b-1,i=g*h+1;switch("linear"===c&&i>104857600&&(c="step"),c){default:case"linear":var j=null;isNumArray(a)?j=new Array(i):isFloat32Array(a)&&(j=new Float32Array(i));for(var k=0,l=0;g>l;l++)for(e=0;h>e;e++)j[k]=a[l]+(a[l+1]-a[l])*(e/h),k++;j[k]=a[l];for(var m=0;h>m;m++)d[m]=j[m*g];d[m]=j[i-1];break;case"step":case"hold":for(e=0;b>e;e++)d[e]=a[Math.floor(e/f)];break;case"zeros":case"zeroes":var n=-1;for(e=0;b>e;e++)n!==Math.floor(e/f)?(n=Math.floor(e/f),d[e]=a[n]):d[e]=0;break;case"decay":break;case"cos":case"cosine":if(a.length>=b)d=dtm.transform.fit(a,b,"linear");else for(var e=0,o=0;o<a.length-1;o++)for(var p=o*Math.ceil(b/(a.length-1)),q=a[o],r=(o+1)*Math.ceil(b/(a.length-1)),s=a[o+1],m=p;r>m;m++){var t=(m-p)/(r-1-p),u=(1-Math.cos(t*Math.PI))/2;d[e]=q*(1-u)+s*u,e++}break;case"cubic":if(a.length>=b)d=dtm.transform.fit(a,b,"linear");else for(var e=0,o=0;o<a.length-1;o++){var p=o*Math.ceil(b/(a.length-1)),q=a[o],r=(o+1)*Math.ceil(b/(a.length-1)),s=a[o+1],v=0,w=q,x=s,y=0;0===o?(v=a[a.length-1],y=a[o+2]):o===a.length-2?(v=a[o-1],y=a[0]):(v=a[o-1],y=a[o+2]);for(var z=y-x-v+w,A=v-w-z,B=x-v,C=w,m=p;r>m;m++){var D=(m-p)/(r-1-p),u=D*D;d[e]=z*D*u+A*u+B*D+C,e++}}break;case"pad":}return d},stretch:function(a,b,c){isString(c)||(c="linear");var d=Math.round(a.length*b);return 0==d&&(d=1),dtm.transform.fit(a,d,c)},ola:function(a,b,c,d,e){isNumber(b)?0>b&&(b=1):b=1,isNumber(c)&&(c=Math.round(c),c>a.length?c=a.length:1>c&&(c=1)),isNumber(d)?(d=Math.round(d),1>d&&(d=1)):d=c,isString(e)||(e="hamming");for(var f=(dtm.gen("zeros",Math.round(a.length*b)),0);f<(a.length-c)/d;f++);},limit:function(a,b,c){var d=[];return a.forEach(function(a,e){var f=a;b>f&&(f=b),f>c&&(f=c),d[e]=f}),d},fitSum:function(a,b,c){isBoolean(c)||(c=!1);var d=sum(a);0===d&&(a=dtm.transform.add(a,1e-6),d=sum(a)),c&&(b=Math.round(b));var e=dtm.transform.mult(a,1/d*b);if(c&&(e=dtm.transform.round(e),sum(e)!==b)){var f=1,g=sum(e)-b,h=0>g;if(h)for(;0>g;)e[mod(a.length-f,a.length)]++,g++,f++;else for(;g>0;)e[a.length-f]>0?(e[mod(a.length-f,a.length)]--,g--,f++):f++}return e},add:function(a,b,c){var d=null;if(isArray(a)?d=new Array(a.length):isFloat32Array(a)&&(d=new Float32Array(a.length)),isEmpty(b)&&(b=1),isString(c)||(c="step"),isNumber(b))a.forEach(function(a,c){d[c]=a+b});else if(isNumOrFloat32Array(b)){a.length>b.length?b=dtm.transform.fit(b,a.length,c):a.length<b.length&&(a=dtm.transform.fit(a,b.length,c));for(var e=0;e<a.length;e++)d[e]=a[e]+b[e]}return d},subtract:function(a,b,c){var d=null;if(isArray(a)?d=new Array(a.length):isFloat32Array(a)&&(d=new Float32Array(a.length)),isEmpty(b)&&(b=1),isString(c)||(c="step"),isNumber(b))a.forEach(function(a,c){d[c]=a+b});else if(isNumOrFloat32Array(b)){a.length>b.length?b=dtm.transform.fit(b,a.length,c):a.length<b.length&&(a=dtm.transform.fit(a,b.length,c));for(var e=0;e<a.length;e++)d[e]=a[e]-b[e]}return d},mult:function(a,b,c){var d=null;if(isArray(a)?d=new Array(a.length):isFloat32Array(a)&&(d=new Float32Array(a.length)),isEmpty(b)&&(b=1),isString(c)||(c="step"),isNumber(b))a.forEach(function(a,c){d[c]=a*b});else if(isNumOrFloat32Array(b)){a.length>b.length?b=dtm.transform.fit(b,a.length,c):a.length<b.length&&(a=dtm.transform.fit(a,b.length,c));for(var e=0;e<a.length;e++)d[e]=a[e]*b[e]}return d},pow:function(a,b,c){var d=null;if(isArray(a)?d=new Array(a.length):isFloat32Array(a)&&(d=new Float32Array(a.length)),isEmpty(b)&&(b=1),isString(c)||(c="step"),isNumber(b))a.forEach(function(a,c){d[c]=Math.pow(a,b)});else if(isNumOrFloat32Array(b)){a.length>b.length?b=dtm.transform.fit(b,a.length,c):a.length<b.length&&(a=dtm.transform.fit(a,b.length,c));for(var e=0;e<a.length;e++)d[e]=Math.pow(a[e],b[e])}return d},powof:function(a,b,c){var d=null;if(isArray(a)?d=new Array(a.length):isFloat32Array(a)&&(d=new Float32Array(a.length)),isEmpty(b)&&(b=1),isString(c)||(c="step"),isNumber(b))a.forEach(function(a,c){d[c]=Math.pow(b,a)});else if(isNumOrFloat32Array(b)){a.length>b.length?b=dtm.transform.fit(b,a.length,c):a.length<b.length&&(a=dtm.transform.fit(a,b.length,c));for(var e=0;e<a.length;e++)d[e]=Math.pow(b[e],a[e])}return d},round:function(a,b){var c=null;return isArray(a)?c=new Array(a.length):isFloat32Array(a)&&(c=new Float32Array(a.length)),a.forEach(isNumber(b)?function(a,d){c[d]=Math.round(a/b)*b}:function(a,b){c[b]=Math.round(a)}),c},floor:function(a){var b=null;return isArray(a)?b=new Array(a.length):isFloat32Array(a)&&(b=new Float32Array(a.length)),a.forEach(function(a,c){b[c]=Math.floor(a)}),b},ceil:function(a){var b=null;return isArray(a)?b=new Array(a.length):isFloat32Array(a)&&(b=new Float32Array(a.length)),a.forEach(function(a,c){b[c]=Math.ceil(a)}),b},hwr:function(a){var b=null;return isArray(a)?b=new Array(a.length):isFloat32Array(a)&&(b=new Float32Array(a.length)),a.forEach(function(a,c){b[c]=0>a?0:a}),b},fwr:function(a){var b=null;return isArray(a)?b=new Array(a.length):isFloat32Array(a)&&(b=new Float32Array(a.length)),a.forEach(function(a,c){b[c]=0>a?Math.abs(a):a}),b},mod:function(a,b){var c=null;return isArray(a)?c=new Array(a.length):isFloat32Array(a)&&(c=new Float32Array(a.length)),a.forEach(function(a,d){c[d]=mod(a,b)}),c},removeZeros:function(a){for(var b=[],c=0;c<a.length;c++)0!==a[c]&&b.push(a[c]);return isArray(a)?b:isFloat32Array(a)?toFloat32Array(b):void 0},diff:function(a){for(var b=[],c=1;c<a.length;c++)b.push(a[c]-a[c-1]);return isArray(a)?b:isFloat32Array(a)?toFloat32Array(b):void 0},reverse:function(a){for(var b=[],c=a.length-1;c>=0;--c)b.push(a[c]);return isArray(a)?b:isFloat32Array(a)?toFloat32Array(b):void 0},invert:function(a,b){isNumber(b)||(b=mean(a));var c=[];return a.forEach(function(a,d){c[d]=b-(a-b)}),isArray(a)?c:isFloat32Array(a)?toFloat32Array(c):void 0},shuffle:function(a){for(var b=a.length-1;b>=1;b--){var c=Math.round(Math.random()*b),d=a[c];a[c]=a[b],a[b]=d}return a},sort:function(a){var b=a.sort(function(a,b){return a>b?1:b>a?-1:0});return isFloat32Array(a)?toFloat32Array(b):b},repeat:function(a,b){var c=[];(!isInteger(b)||1>b)&&(b=1);for(var d=0;b>d;d++)c=concat(c,a);return c},truncate:function(a,b,c){var d=[];if(isEmpty(c))for(var e=0;e<a.length-b;e++)d[e]=a[e];else for(var f=0;f<a.length-(b+c);f++)d[f]=a[b+f];return d},getBlock:function(a,b,c){for(var d=[],e=0,f=0;c>f;f++)e=mod(f+b,a.length),d[f]=a[e];return d},window:function(a,b){switch(b){case"rect":case"rectangle":case"rectangular":return a}var c=0,d=null;isArray(a)?d=new Array(a.length):isFloat32Array(a)&&(d=new Float32Array(a.length));for(var e=0;e<a.length;e++)switch(c=e/(a.length-1),b){case"tri":case"triangle":case"triangular":d[e]=a[e]*(1-Math.abs(2*c-1));break;case"hamm":case"hamming":var f=.54,g=.46;d[e]=a[e]*(f-g*Math.cos(2*Math.PI*c));break;case"rect":case"rectangle":case"rectangular":default:d[e]=a[e]}return d},shift:function(a,b){for(var c=[],d=0;d<a.length;d++){var e=mod(d+b,a.length);c[d]=a[e]}return c},morph:function(a,b,c,d){isNumber(c)||(c=.5);var e=a.length,f=b.length,g=Math.round((f-e)*c+e);return morphFixed(dtm.transform.fit(a,g,d),dtm.transform.fit(b,g),c)},interleave:function(){},notesToBeats:function(a,b){var c=[],d=0;return a.forEach(function(a){for(var e=b/a,f=0;e>f;f++)c[d]=0===f?1:0,d++}),c},beatsToNotes:function(a,b){for(var c=[],d=1,e=0;e<a.length-1;e++)0!==a[e+1]?(c.push(b/d),d=1):d++;return c.push(b/d),c},intervalsToBeats:function(a){var b=[],c=0;return a.forEach(function(a){for(var d=0;a>d;d++)b[c]=0===d?1:0,c++}),b},beatsToIntervals:function(a){for(var b=[],c=1,d=0;d<a.length-1;d++)0!==a[d+1]?(b.push(c),c=1):c++;return b.push(c),b},beatsToIndices:function(a){for(var b=[],c=0;c<a.length;c++)0!==a[c]&&b.push(c);return b},indicesToBeats:function(a,b){if(a=dtm.transform.sort(a),isNumber(b))d=b;else for(var c=0,d=1;a[a.length-1]>=d;)d=Math.pow(2,++c);for(var e=dtm.gen("const",0).size(d).get(),f=0;f<a.length&&!(a[f]>=b);f++)e[a[f]]=1;return e},calcBeatsOffset:function(a,b){for(var c=[],d=0,e=!1,f=!1,g=0;g<a.length;g++)1!==a[g]||f?1!==b[g]||e||(f=!0):e=!0,e?1===b[g]?(c.push(d),e=f=!1,d=0):d++:f&&(1===a[g]?(c.push(d),e=f=!1,d=0):d--);return c},applyOffsetToBeats:function(a,b){for(var c=dtm.gen("zeroes",a.length).get(),d=0,e=0;e<a.length;e++)1===a[e]&&(c[e+b[d]]=1,d++);
  return c},lreModulation:function(a,b){for(var c=[],d=0,e=0,f=0;f<a.length;f++)c[f]=0,0!==a[f]&&d++;for(var g=a.length/d,h=[],i=0;i<a.length;i++)if(0!==a[i]){var j=i-g*e;h.push(Math.round(g*e+j*(b-.5)*2)),e++}for(var k=0;k<h.length;k++){var l=h[k];0>l?l=0:l>=a.length&&(l=a.length-1),c[l]=1}return c},pitchQuantize:function(a,b,c){var d=[];return a.forEach(function(a,e){d[e]=pq(a,b,c)}),d},unique:function(a){return unique(a)},classId:function(a){var b=[],c=listClasses(a).sort(),d={};return c.forEach(function(a,b){d[a]=b}),a.forEach(function(a,c){b[c]=d[a]}),b},stringify:function(a){var b=[];return a.forEach(function(a,c){b[c]=a.toString()}),b},tonumber:function(a){var b=[];return a.forEach(function(a,c){b[c]=isString(a)?parseFloat(a):isBoolean(a)?a?1:0:0/0}),b},mtof:function(a){var b;return b=isFloat32Array(a)?new Float32Array(a.length):new Array(a.length),a.forEach(function(a,c){b[c]=mtof(a)}),b},ftom:function(a){var b;return b=isFloat32Array(a)?new Float32Array(a.length):new Array(a.length),a.forEach(function(a,c){b[c]=ftom(a)}),b},split:function(a,b){isString(b)||(b="");var c=[];return isArray(a)&&a.forEach(function(a){isNumber(a)&&(a=a.toString()),c=c.concat(a.split(b))}),c},convolve:function(){}},dtm.transform.ntob=dtm.transform.notesToBeats,dtm.transform.bton=dtm.transform.beatsToNotes,dtm.transform.itob=dtm.transform.intervalsToBeats,dtm.transform.btoi=dtm.transform.beatsToIntervals,dtm.transform.abs=dtm.transform.fwr,dtm.transform.randomize=dtm.transform.shuffle,dtm.tr=dtm.transform,dtm.array=function(){function a(a){b.type=isNumber(a[0])?typeof a[0]:isObject(a[0])?"collection":typeof a[0]}var b={name:"",type:null,len:null,autolen:!1,value:[],original:null,normalized:null,classes:null,numClasses:null,index:0,step:1,parent:null,hash:"",processed:0},c=function(){return c.clone()};return c.meta={type:"dtm.array",getParams:function(){return b},addParams:function(a){objForEach(a,function(a,c){b[c]=a})},setOriginal:function(a){b.original=a}},c.val=[],c.len=0,c.get=function(a){if(isNumber(a))return c.val[mod(a,c.len)];if(isNumArray(a)||isDtmArray(a)&&isNumArray(a.get())){var d=isDtmArray(a)?a.get():a,e=[];return d.forEach(function(a){e.push(c.val[mod(a,c.len)])}),e}if(!isString(a))return c.val;switch(a){case"getters":case"help":case"?":return"name|key, type, len|length, min|minimum, max|maximum, extent|minmax|range, mean|avg|average, mode, median, midrange, std, pstd, var|variance, pvar, rms, cur|current|now, next, pver|previous, rand|random, idx|index, hop|step|stepSize, loc|location|relative, block (with 1|2 following numbers), blockNext, original, normal|normalize|normalized, sort|sorted, uniq|unique|uniques, classes, classID, string|stringify, numClasses|numUniques, unif|uniformity, histo|histogram".split(", ");case"methods":case"functions":return Object.keys(c);case"name":case"key":case"label":return b.name;case"names":case"keys":case"labels":return isNestedWithDtmArray(c.val)?c.val.map(function(a){return a.get("name")}):b.name;case"type":return isNumArray(c.val)?"number":isFloat32Array(c.val)?"Float32Array":isStringArray(c.val)?"string":isNestedWithDtmArray(c.val)?"nested":"mixed";case"parent":return b.parent;case"len":case"length":return c.len;case"size":return isNestedDtmArray(c)?{row:c.val[0].get("len"),col:c.len}:c.len;case"autolen":return b.autolen;case"hash":return b.hash;case"processed":return b.processed;case"nested":return c.val.map(function(a){return isDtmArray(a)?a.get():a});case"row":if(isInteger(arguments[1])&&isNestedWithDtmArray(c.val)){var f=arguments[1],e=[];return c.val.forEach(function(a){e.push(a.get(f))}),isNumArray(e)&&(e=toFloat32Array(e)),e}break;case"minimum":case"min":return getMin(c.val);case"maximum":case"max":return getMax(c.val);case"extent":case"minmax":case"range":return[getMin(c.val),getMax(c.val)];case"mean":case"average":case"avg":return mean(c.val);case"mode":return mode(c.val);case"median":return median(c.val);case"midrange":return midrange(c.val);case"standardDeviation":case"std":return std(c.val);case"pstd":return pstd(c.val);case"variance":case"var":return variance(c.val);case"populationVariance":case"pvar":return pvar(c.val);case"sumAll":case"sum":return sum(c.val);case"rms":return rms(c.val);case"pdf":break;case"current":case"curr":case"cur":case"now":case"moment":return c.val[b.index];case"next":return isEmpty(arguments[1])?(b.index=mod(b.index+b.step,c.len),c.val[b.index]):isNumber(arguments[1])&&arguments[1]>=1?(b.index=mod(b.index+b.step,c.len),i=dtm.transform.getBlock(c.val,b.index,arguments[1]),dtm.array(i)):c;case"prev":case"previous":return b.index=mod(b.index-b.step,c.len),c.val[b.index];case"palindrome":break;case"rand":case"random":return b.index=randi(0,c.len),c.val[b.index];case"urn":break;case"index":case"idx":return b.index;case"hop":case"hopSize":case"step":case"stepSize":return b.step;case"relative":case"location":case"loc":break;case"block":var g,h,i;return isArray(arguments[1])?(g=arguments[1][0],h=arguments[1][1],i=dtm.transform.getBlock(c.val,g,h),dtm.array(i)):isNumber(arguments[1])&&isNumber(arguments[2])?(g=arguments[1],h=arguments[2],i=dtm.transform.getBlock(c.val,g,h),dtm.array(i)):c.val;case"blockNext":return b.index=mod(b.index+b.step,c.len),i=dtm.transform.getBlock(c.val,b.index,arguments[1]),dtm.array(i);case"original":return b.original;case"normal":case"normalize":case"normalized":return isEmpty(b.normalized)&&(b.normalized=dtm.transform.normalize(c.val)),isInteger(arguments[1])?b.normalized[mod(arguments[1],c.len)]:b.normalized;case"sorted":case"sort":return dtm.transform.sort(c.val);case"uniques":case"unique":case"uniq":return dtm.transform.unique(c.val);case"classes":return listClasses(c.val);case"classID":case"classId":return dtm.transform.classId(c.val);case"string":case"stringify":return dtm.transform.stringify(c.val);case"numClasses":case"numUniques":case"numUniqs":return listClasses(c.val).length;case"unif":case"uniformity":return uniformity(c.val);case"histogram":case"histo":return histo(c.val);case"distribution":case"dist":return[];default:return b.hasOwnProperty(a)?b[a]:c.val}},c.col=function(a){if(isNestedDtmArray(c)){if(isString(a)){var b;return c.val.forEach(function(c){c.get("name")===a&&(b=c)}),isEmpty(b)&&(b=c),b.clone()}return c.get(a).clone()}return c.set(c.get(a)).label(c.get("name"))},c.column=c.col,c.row=function(a){return c.set(c.get("row",a))},c.transp=function(){if(isNestedDtmArray(c)){for(var a=[],b=0;c.val.some(function(a){return b<a.get("len")});)a.push(c.get("row",b)),b++;return c.set(a)}return c.block(1)},c.set=function(){if(0===arguments.length)return c;if(argsAreSingleVals(arguments)){var d=argsToArray(arguments);c.val=isNumArray(d)?new Float32Array(d):d}else 1===arguments.length?isNumber(arguments[0])?c.val=toFloat32Array(arguments[0]):isNumArray(arguments[0])?c.val=toFloat32Array(arguments[0]):isNestedArray(arguments[0])?(c.val=new Array(arguments[0].length),arguments[0].forEach(function(a,b){c.val[b]=dtm.array(a).parent(c)})):isNestedWithDtmArray(arguments[0])?(c.val=arguments[0],c.val.forEach(function(a){isDtmArray(a)&&a.parent(c)})):isDtmArray(arguments[0])?c.val=arguments[0].get():isNestedDtmArray(arguments[0])?(c.val=arguments[0].get(),c.val.forEach(function(a){a.parent(c)})):isString(arguments[0])?(c.val=[arguments[0]],a(c.val)):c.val=arguments[0]:(c.val=new Array(arguments.length),argsForEach(arguments,function(a,b){c.val[b]=isDtmArray(a)?a:dtm.array(a),c.val[b].parent(c)}));return isEmpty(b.original)?b.original=c.val:b.processed++,c.len=c.val.length,b.index=c.len-1,c},c.label=function(a){return isString(a)&&(b.name=a),c},c.valuetype=function(a){return isString(a)&&(b.type=a),c},c.step=function(a){return isInteger(a)&&a>0&&(b.step=a),c},c.index=function(a){return isNumber(a)&&(b.index=mod(Math.round(a),c.len)),c},c.clone=function(){var a=[];a=isNestedWithDtmArray(c.val)?c.val.map(function(a){return a.clone()}):c.val;var d=dtm.array(a).label(b.name);return d.meta.setOriginal(b.original),d.index(b.index),d.step(b.step),"string"===b.type&&(d.classes=b.classes),d},c.parent=function(a){return isDtmArray(a)&&(b.parent=a),c},c.nest=function(){return isDtmArray(c.val)||(c.set([dtm.array(c.val)]),c.val[0].parent(c)),c},c.unnest=function(){var a=[];return c.val.forEach(function(b){isDtmArray(b)&&(a=concat(a,b.get()))}),isNumArray(a)&&(a=toFloat32Array(a)),c.set(a)},c.flatten=c.ub=c.unblock=c.unnest,c.morph=function(a,b,d){return isArray(a)||isDtmArray(a)&&(a=a.get()),isNumber(b)||(b=.5),isNumArray(c.val)&&isNumArray(a)&&c.set(dtm.transform.morph(c.val,a,b,d)),c},c.reset=function(){return c.set(b.original)},c.residue=function(){return c.set(dtm.transform.subtract(b.original,c.val))},c.res=c.residue,c.flush=function(){return c.set([])},c.clear=c.flush,c.normalize=function(a,b){if(isNestedDtmArray(c))return c.map(function(c){return c.normalize(a,b)});var d,e,f;return isNumber(a)&&isNumber(b)?(d=a,e=b):(isNumOrFloat32Array(a)?f=a:isDtmArray(a)&&isNumOrFloat32Array(a.get())&&(f=a.get()),isNumOrFloat32Array(f)&&(2===f.length?(d=f[0],e=f[1]):f.length>2&&(d=getMin(f),e=getMax(f)))),c.set(dtm.transform.normalize(c.val,d,e))},c.n=c.normalize,c.scale=function(a,b,d,e){if(isNestedDtmArray(c))return c.map(function(c){return c.scale(a,b,d,e)});var f,g,h,i;if(isNumber(a))f=a;else if(isNumArray(a))a.length>=2&&(f=a[0],g=a[1]),a.length>2&&(f=getMin(a),g=getMax(a));else{if(!isDtmArray(a)||!isNumOrFloat32Array(a.get()))return c;2===a.get("len")?(f=a.get(0),g=a.get(1)):a.get("len")>2&&(f=a.get("min"),g=a.get("max"))}return isNumber(b)?g=b:isNumArray(b)&&2===b.length&&(h=b[0],i=b[1]),isNumber(d)?h=d:isNumArray(d)&&2===d.length&&(h=d[0],i=d[1]),isNumber(e)&&(i=e),c.set(dtm.transform.rescale(c.val,f,g,h,i))},c.r=c.range=c.sc=c.scale,c.limit=function(a,b){return isNumOrFloat32Array(c.val)?(a=a||0,b=b||1,c.set(dtm.transform.limit(c.get(),a,b))):c},c.clip=c.limit,c.expcurve=function(a,b,d){isEmpty(b)&&(b=c.get("min")),isEmpty(d)&&(d=c.get("max"));var e=dtm.transform.expCurve(c.get("normalized"),a);return c.set(dtm.transform.rescale(e,b,d))},c.expc=c.expcurve,c.logcurve=function(a,b,d){isEmpty(b)&&(b=c.get("min")),isEmpty(d)&&(d=c.get("max"));var e=dtm.transform.logCurve(c.get("normalized"),a);return c.set(dtm.transform.rescale(e,b,d))},c.logc=c.logcurve,c.curve=function(){return c},c.fit=function(a,b){return isNestedDtmArray(c)?c.map(function(c){return c.fit(a,b)}):c.set(dtm.transform.fit(c.val,a,b))},c.f=c.fit,c.stretch=function(a,b){return isNestedDtmArray(c)?c.map(function(c){return c.stretch(a,b)}):c.set(dtm.transform.stretch(c.val,a,b))},c.str=c.stretch,c.summarize=function(){return c},c.sum=function(){if(isNestedWithDtmArray(c.val)){var a=0;c.val.forEach(function(b){b.get("len")>a&&(a=b.get("len"))});for(var b=new Float32Array(a),d=0;a>d;d++)c.val.forEach(function(a){d<a.get("len")&&isNumber(a.get(d))&&(b[d]+=a.get(d))});return c.set(b)}var e=c.val.reduce(function(a,b){return a+b});return c.set(e)},c.fitsum=function(a,b){return c.set(dtm.transform.fitSum(c.val,a,b))},c.add=function(a,b){if(isString(b)||(b="step"),isNestedNumDtmArray(c))return c.map(function(b){return b.add(isNestedNumDtmArray(a)?a.get("next"):a)});if(isNumDtmArray(a))a=a.get();else if(isNestedNumDtmArray(a)){var d=[];return a.forEach(function(){d.push(c.get())}),c.set(d),c.map(function(b){return b.add(a.get("next"))})}return c.set(dtm.transform.add(c.val,a,b))},c.subtract=function(a,b){if(isString(b)||(b="step"),isNestedNumDtmArray(c))return c.map(function(b){return b.add(isNestedNumDtmArray(a)?a.get("next"):a)});if(isNumDtmArray(a))a=a.get();else if(isNestedNumDtmArray(a)){var d=[];return a.forEach(function(){d.push(c.get())}),c.set(d),c.map(function(b){return b.add(a.get("next"))})}return c.set(dtm.transform.subtract(c.val,a,b))},c.mult=function(a,b){if(isString(b)||(b="step"),isNestedNumDtmArray(c))return c.map(function(b){return b.mult(isNestedNumDtmArray(a)?a.get("next"):a)});if(isNumDtmArray(a))a=a.get();else if(isNestedNumDtmArray(a)){var d=[];return a.forEach(function(){d.push(c.get())}),c.set(d),c.map(function(b){return b.mult(a.get("next"))})}return c.set(dtm.transform.mult(c.val,a,b))},c.dot=c.mult,c.pow=function(a,b){return isDtmArray(a)&&(a=a.get()),c.set(dtm.transform.pow(c.val,a,b))},c.powof=function(a,b){return isDtmArray(a)&&(a=a.get()),c.set(dtm.transform.powof(c.val,a,b))},c.map=function(a){return c.set(fromFloat32Array(c.val).map(a))},c.foreach=function(a){return c.val.forEach(a),c},c.forEach=c.foreach,c.filter=function(a){return c.set(c.val.filter(a))},c.reduce=function(a){return c.set(c.val.reduce(a))},c.some=function(a){return c.val.some(a)},c.every=function(a){return c.val.every(a)},c.subarray=function(){return c},c.match=function(){return c},c.replace=function(a,b){return isSingleVal(b)?isSingleVal(a)?c.set(c.val.map(function(c){return c===a?b:c})):isArray(a)?c.set(c.val.map(function(c){return a.some(function(a){return a===c})?b:c})):isDtmArray(a)?c.set(c.val.map(function(c){return a.get().some(function(a){return a===c})?b:c})):isFunction(a)?c.set(c.val.map(function(c){return a(c)?b:c})):void 0:c},c.replaceat=function(){return c},c.select=function(){var a,b=[];return argsAreSingleVals(arguments)?a=argsToArray(arguments):isNumOrFloat32Array(arguments[0])?a=arguments[0]:isDtmArray(arguments[0])&&isNumOrFloat32Array(arguments[0].get())&&(a=arguments[0].get()),isNumOrFloat32Array(a)?(a.forEach(function(a){b.push(c.val[mod(a,c.len)])}),c.set(b)):c},c.sel=c.select,c.sort=function(){return c.set(dtm.transform.sort(c.val))},c.concat=function(a){return isEmpty(a)&&(a=[]),c.val=isDtmArray(a)?concat(c.val,a.get()):concat(c.val,a),c.set(c.val)},c.append=c.concat,c.repeat=function(a){return isDtmArray(a)&&1===a.get("len")&&(a=a.get(0)),isInteger(a)||(a=1),c.set(dtm.transform.repeat(c.val,a))},c.rep=c.repeat,c.fitrep=function(a,b){return isDtmArray(a)&&1===a.get("len")&&(a=a.get(0)),isInteger(a)||(a=1),isString(b)||(b="step"),c.set(dtm.transform.fit(dtm.transform.repeat(c.val,a),c.len,b))},c.frep=c.fitrep,c.pad=function(a,b){for(var d=[],e=0;b>e;e++)d.push(a);return c.concat(d)},c.truncate=function(a,b){return c.set(dtm.transform.truncate(c.val,a,b))},c.slice=c.truncate,c.block=function(a,b,d){!isInteger(a)||1>a?a=1:a>c.len&&(a=c.len),(!isInteger(b)||1>b)&&(b=a),isEmpty(d)&&(d="rectangular");for(var e=[],f=Math.floor((c.len-a)/b)+1,g=0;f>g;g++)e[g]=dtm.array(c.val.slice(g*b,g*b+a)).window(d).parent(c);return c.set(e)},c.nest=c.b=c.block,c.ola=function(a){if((!isInteger(a)||1>a)&&(a=1),isNestedWithDtmArray(c.val)){var b=a*(c.len-1)+c.val[0].get("len"),d=new Array(b);return d.fill(0),c.val.forEach(function(b,c){b.foreach(function(b,e){d[c*a+e]+=b})}),c.set(d)}return c},c.window=function(a){return c.set(dtm.transform.window(c.val,a))},c.shift=function(a){return c.set(dtm.transform.shift(c.val,a))},c.mirror=function(){return c.concat(dtm.transform.reverse(c.val))},c.mir=c.mirror,c.reverse=function(){return c.set(dtm.transform.reverse(c.val))},c.rev=c.reverse,c.invert=function(a){return c.set(dtm.transform.invert(c.val,a))},c.inv=c.invert,c.shuffle=function(){return c.set(dtm.transform.shuffle(c.val))},c.randomize=c.shuffle,c.blockShuffle=function(){return c},c.reorder=function(){var a;if(isDtmArray(arguments[0])?a=toFloat32Array(arguments[0]):argsAreSingleVals(arguments)?a=argsToArray(arguments):argIsSingleArray(arguments)&&(a=arguments[0]),isNumOrFloat32Array(a)){var b=new Array(a.length);a.forEach(function(a,d){b[d]=c.get(a)})}return c.set(b)},c.order=c.reorder,c.queue=function(a){return isNumber(a)?(c.val.push(a),c.val.shift()):isFloat32Array(a)?(c.val=Float32Concat(c.val,a),c.val=c.val.splice(a.length)):isArray(a)?isFloat32Array(c.val)?(c.val=Float32Concat(c.val,a),c.val=Float32Splice(c.val,a.length)):(c.val=c.val.concat(a),c.val=c.val.splice(a.length)):isDtmArray(a)&&(c.val=c.val.concat(a.get()),c.val=c.val.splice(a.get("len"))),c.set(c.val)},c.fifo=c.queue,c.round=function(a){return c.set(dtm.transform.round(c.val,a))},c.floor=function(){return c.set(dtm.transform.floor(c.val))},c.ceil=function(){return c.set(dtm.transform.ceil(c.val))},c.hwr=function(){return c.set(dtm.transform.hwr(c.val))},c.fwr=function(){return c.set(dtm.transform.fwr(c.val))},c.abs=c.fwr,c.modulo=function(a){return c.set(dtm.transform.mod(c.val,a))},c.mod=c.modulo,c.diff=function(a,b){(!isInteger(a)||1>a)&&(a=1);for(var d=0;a>d;d++)c.val=dtm.transform.diff(c.val);if(isSingleVal(b))for(var d=0;a>d;d++)c.val=concat(c.val,b);return c.set(c.val)},c.removezeros=function(){return c.set(dtm.transform.removeZeros(c.val))},c.histogram=function(){return b.type="string",c.set(toFloat32Array(histo(c.val)))},c.unique=function(){return c.set(dtm.transform.unique(c.val))},c.classify=function(){return c.set(dtm.transform.classId(c.val))},c.stringify=function(){return c.set(dtm.transform.stringify(c.val))},c.tonumber=function(){return c.set(toFloat32Array(dtm.transform.tonumber(c.val)))},c.toFloat32=function(){return isNumArray(c.val)&&c.set(toFloat32Array(c.val)),c},c.morethan=function(){return c},c.lessthan=function(){return c},c.split=function(a){return c.set(dtm.transform.split(c.val,a))},c.pitchquantize=function(a){return isNestedDtmArray(c)?c.map(function(b){return b.pitchquantize(a)}):(isEmpty(a)?a=dtm.gen("range",12).get():isDtmArray(a)&&isNumOrFloat32Array(a.get())?a=a.get():isNumOrFloat32Array(a),c.set(dtm.transform.pitchQuantize(c.val,a)))},c.mtof=function(){return c.set(dtm.transform.mtof(c.val))},c.ftom=function(){return c.set(dtm.transform.ftom(c.val))},c.notesToBeats=function(a){return a=a||4,c.set(dtm.transform.notesToBeats(c.val,a))},c.beatsToNotes=function(a){return a=a||4,c.set(dtm.transform.beatsToNotes(c.val,a))},c.intervalsToBeats=function(){return c.set(dtm.transform.intervalsToBeats(c.val))},c.beatsToIntervals=function(){return c.set(dtm.transform.beatsToIntervals(c.val))},c.beatsToIndices=function(){return c.set(dtm.transform.beatsToIndices(c.val))},c.indicesToBeats=function(a){return c.set(dtm.transform.indicesToBeats(c.val,a))},c.histo=c.histogram,c.uniq=c.unique,c["class"]=c.classify,c.tostring=c.stringify,c.tonum=c.tonumber,c.mt=c.morethan,c.lt=c.lessthan,c.pq=c.pitchquantize,c.ntob=c.notesToBeats,c.bton=c.beatsToNotes,c.itob=c.intervalsToBeats,c.btoi=c.beatsToIntervals,c.btoid=c.beatsToIndices,c.idtob=c.indicesToBeats,c.type=function(){return c},c.size=function(){return c},c.set.apply(this,arguments),c},dtm.a=dtm.array,dtm.parser={type:"dtm.parser",csvToJson:function(a){for(var b=a.split("\n"),c=[],d=b[0].split(","),e=1;e<b.length;e++){var f={},g=b[e].split(",");if(g.length>1){for(var h=0;h<d.length;h++){var i=g[h];isNaN(i)||(i=Number.parseFloat(i)),f[d[h]]=i}c.push(f)}}return c},csvToCols:function(a){var b=a.indexOf("\n")>-1?"\n":"\r",c=a.split(b),d=c[0].split(","),e={};d.forEach(function(a,b){d[b]=a.trim(),e[d[b]]=[]});for(var f=1;f<c.length;f++){var g=c[f].split(",");if(g.length>1)for(var h=0;h<d.length;h++){var i=g[h];i=isNaN(i)?i.trim():parseFloat(i),e[d[h]].push(i)}}return e},valueTypes:function(a){var b=[];return a.forEach(function(a){var c=parseFloat(a);b.push(isNaN(c)?"string":a.indexOf(".")>-1?"float":"int")}),b},getSize:function(a){var b=numProperties(a[0]),c=numProperties(a);return[b,c]}},dtm.data=function(input,fn){if(isString(input)){var url=input;return new Promise(function(resolve){var ext=url.split(".").pop();if("jsonp"===ext){var cbName="jsonp_callback_"+Math.round(1e5*Math.random());window[cbName]=function(a){delete window[cbName],document.body.removeChild(script);var b=Object.keys(a);b.forEach(function(b){"response"!==b&&(params.coll=a[b],params.keys=Object.keys(params.coll[0]),setArrays(),setTypes(),setSize(),resolve(data))}),"undefined"!=typeof cb&&cb(data)};var script=document.createElement("script");script.src=url+(url.indexOf("?")>=0?"&":"?")+"callback="+cbName,document.body.appendChild(script)}else{var xhr=new XMLHttpRequest;switch(xhr.open("GET",url,!0),ext){case"txt":case"csv":break;case"json":break;case"wav":case"aif":case"aiff":case"ogg":case"mp3":xhr.responseType="arraybuffer";break;case"png":case"jpg":case"jpeg":xhr.responseType="blob"}xhr.onreadystatechange=function(){if(4==xhr.readyState&&200==xhr.status)if("arraybuffer"===xhr.responseType)dtm.wa.isOn&&dtm.wa.actx.decodeAudioData(xhr.response,function(a){for(var b=dtm.array(),c=[],d=0;d<a.numberOfChannels;d++){var e=a.getChannelData(d);c.push(dtm.array(Array.prototype.slice.call(e)).label("ch_"+d).parent(b))}"undefined"!=typeof fn&&fn(b.set(c)),resolve(b.set(c))});else if("blob"===xhr.responseType){var img=new Image;img.onload=function(){var a=document.createElement("canvas");a.width=img.width,a.height=img.height;var b=a.getContext("2d");b.drawImage(img,0,0);for(var c=[],d=b.getImageData(0,0,img.width,img.height).data,e=0;e<img.width;e++)c.push(d.filter(function(a,b){return b%(4*img.width)===e}));console.log(c)},img.src=window.URL.createObjectURL(xhr.response)}else{var keys=[];if("csv"===ext){var data=dtm.array(),arrays=[];objForEach(dtm.parser.csvToCols(xhr.response),function(a,b){var c=dtm.array(a).label(b).parent(data);arrays.push(c)})}else if("json"===ext){var res=xhr.responseText;try{res=JSON.parse(res)}catch(e){try{res=eval(res)}catch(e){console.log("Could not parse the JSON file. Maybe the format is not right.")}}if(url.indexOf("wunderground")>-1){var obj=JSON.parse(xhr.response);params.coll=obj[Object.keys(obj)[1]],params.coll.constructor===Array?keys=Object.keys(params.coll[0]):(keys=Object.keys(params.coll),params.coll=[params.coll])}else{var second=res[Object.keys(res)[0]];keys=Object.keys(second.constructor===Array?second[0]:second),params.coll=res}}else params.coll=second;"undefined"!=typeof fn&&fn(data.set(arrays)),resolve(data.set(arrays))}},xhr.send()}})}var elem_files=input,fileType=null,reader=new FileReader;return elem_files[0].name.match(/.+\.json/gi)?fileType="json":elem_files[0].name.match(/.+\.csv/gi)&&(fileType="csv"),reader.readAsText(elem_files[0]),new Promise(function(a){reader.onload=function(b){if("json"===fileType)a(JSON.parse(b.target.result));else if("csv"===fileType){var c=dtm.array(),d=[];objForEach(dtm.parser.csvToCols(b.target.result),function(a,b){var e=dtm.array(a).label(b).parent(c);d.push(e)}),"undefined"!=typeof fn&&fn(c.set(d)),a(c.set(d))}}})},dtm.load=dtm.data,dtm.clock=function(a,b,c){function d(){return f.sync?1/(dtm.master.get("clock").get("bpm")/60*f.subDiv/4):1/(f.bpm/60*f.subDiv/4)}function e(){return f.sync?dtm.master.get("clock").get("bpm")/60*f.subDiv/4:f.bpm/60*f.subDiv/4}var f={source:"animationFrame",name:null,isOn:!1,sync:!0,isMaster:!1,bpm:120,interval:{base:dtm.array([[.5]])},subDiv:2,random:0,swing:.5,current:0,previous:0,reported:0,resolution:480,beat:0,prevBeat:-1,lookahead:.1,offset:0,requestId:null,autoStart:!0,time:[4,4]},g={type:"dtm.clock",interval:1,beat:0,list:[],prev:0,callbacks:[]},h=0,i=null,j=null;g.get=function(a){switch(a){case"bpm":case"tempo":return f.sync?dtm.master.get("clock").get("bpm"):f.bpm;case"subdiv":case"subDiv":case"div":return f.subDiv;case"time":return f.subDiv;case"dur":case"interval":return d();case"freq":return e();case"sync":case"synced":return f.sync;case"lookahead":case"la":return f.lookahead;case"isOn":case"isPlaying":return f.isOn;case"source":return f.source;case"beat":return f.beat;case"cur":case"current":return f.current;case"prev":case"previous":return f.previous;case"rep":case"reported":return f.reported;default:return g}},g.set=function(a,b,c){return isFunction(a)?g.callback(a):g.bpm(a),isEmpty(b)||g.subdiv(b),isBoolean(c)&&(f.autoStart=c),g},g.sync=function(a){return isBoolean(a)||(a=!0),f.sync=a,g},g.bpm=function(a){return isNumber(a)?(f.bpm=a,f.sync=!1):isBoolean(a)?f.sync=a:"sync"==a&&(f.sync=!0),g},g.tempo=g.bpm,g.subdiv=function(a){if(isNumber(a))f.subDiv=a;else if(isString(a)){a=a.split("/");try{a=Math.round(parseFloat(a[1])/parseFloat(a[0]))}catch(b){return g}f.subDiv=a}return g},g.div=g.subdiv,g.time=function(a){return isNumber(a)&&0!==a&&(f.subDiv=1/a),g},g.interval=function(){function a(a,b){return isInteger(b)||(b=3),isNumber(a)||(isNumArray(a)||isNestedArray(a)||isNestedWithDtmArray(a)||isNumOrFloat32Array(a)||isNumDtmArray(a)||isNestedNumDtmArray(a))&&getMaxDepth(a)<=b}function b(a){return 1===a.length?b(a[0]):isNestedNumDtmArray(a)?a:isNestedWithDtmArray(a)?dtm.array.apply(this,a):isNumDtmArray(a)?a().block(1):isNestedArray(a)?dtm.array(a):isNumOrFloat32Array(a)?dtm.array(a).block(1):dtm.array([toFloat32Array(a)])}var c=2;if(isFunction(arguments[0])){var d=arguments[0](f.interval.base,g);f.interval.base=a(d,c)?b(d):f.interval.base}else{var e=argsToArray(arguments);f.interval.base=a(e)?b(e):param}return f.sync=!1,f.subDiv=1,g},g.dur=g["int"]=g.interval,g.setTime=function(a){return isArray(a)?g.params.time=a:isString(a)&&(g.params.time=a.split("/")),g},g.meter=g.setTime,g.setMaster=function(a){return f.isMaster=a,g},g.lookahead=function(a){return isNumber(a)&&a>=0&&(f.lookahead=a),g},g.la=g.lookahead,g.add=function(a,b){var c=!1;return isString(b)?(g.callbacks.forEach(function(a){a.name==b&&(dtm.log("clock.add(): identical function exists in the callback list"),c=!0)}),c||(dtm.log("adding a new callback function to clock"),g.callbacks.push(a))):(g.callbacks.forEach(function(){}),c||(dtm.log("adding a new callback function to clock"),g.callbacks.push(a))),g},g.cb=g.callback=g.call=g.register=g.reg=g.add,g.remove=function(a){if(isFunction(a)){dtm.log("removing a calblack function");for(var b=g.callbacks.length;b>=0;b--)objCompare(g.callbacks[b],a)&&g.callbacks.splice(b,1)}else if(isString(a)){dtm.log("removing a calblack function: "+a);for(var b=g.callbacks.length;b>=0;b--)g.callbacks[b].name==a&&g.callbacks.splice(b,1)}return g},g.del=g["delete"]=g.rem=g.remove,g.modify=function(a,b){if(isFunction(a))dtm.log("modifying the callback: "+a.name),g.remove(a.name),g.add(a);else if(isString(a))if(dtm.log("modifying the callback: "+a),g.remove(a),""==b.name){var c=new Function("return function "+a+b.toString().slice(8))();g.add(c)}else g.add(b);return g},g.replace=g.mod=g.modify,g.start=function(){return"animationFrame"===f.source&&window.requestAnimationFrame(g.tick),dtm.log(f.isMaster?"starting the master clock":"starting a clock"),f.isOn!==!0&&(f.isOn=!0,g.tick(),f.isMaster||dtm.clocks.push(g)),g},g.run=g.play=g.start;var k;return g.tick=function(a){if(!f.isOn)return g;var b=1;return f.sync||f.isMaster?f.sync&&!f.isMaster||f.isMaster&&("webAudio"===f.source?(i=dtm.wa.actx,k=i.createBufferSource(),j=dtm.wa.clockBuf,k.buffer=j,k.connect(i.destination),b=f.bpm/60*(f.subDiv/4),k.playbackRate.value=b*dtm.wa.clMult,k.playbackRate.value+=k.playbackRate.value*f.random*Math.round(2*Math.random()-1),k.playbackRate.value*=g.beat%2==0?(1-f.swing)/.5:f.swing/.5,k.start(i.currentTime+1e-7),k.onended=function(){h+=1/b;var a=i.currentTime-h;g.tick(a)},g.callbacks.forEach(function(a){a(g)}),g.beat=(g.beat+1)%(f.subDiv*g.params.time[0]/g.params.time[1])):"animationFrame"===f.source&&(f.reported=Math.round(a/1e3*f.bpm/60*f.resolution),f.reported!==f.current&&(f.current%f.resolution>f.reported%f.resolution&&(f.beat=Math.round((f.current-f.offset)/f.resolution)),g.callbacks.forEach(function(a){a(g)}),f.current=f.reported),f.requestId=window.requestAnimationFrame(g.tick))):"webAudio"===f.source?(i=dtm.wa.actx,k=i.createBufferSource(),j=dtm.wa.clockBuf,k.buffer=j,k.connect(i.destination()),b=f.bpm/60*(f.subDiv/4),k.playbackRate.value=b*dtm.wa.clMult,k.playbackRate.value+=k.playbackRate.value*f.random*Math.round(2*Math.random()-1),k.playbackRate.value*=g.beat%2==0?(1-f.swing)/.5:f.swing/.5,k.start(i.currentTime+1e-7),k.onended=function(){h+=1/b,g.tick()},g.callbacks.forEach(function(a){a(g)}),g.beat=(g.beat+1)%(f.subDiv*g.params.time[0]/g.params.time[1])):"animationFrame"===f.source&&(f.reported=Math.round(a/1e3*f.bpm/60*f.resolution*f.subDiv/4),f.reported!==f.current&&(f.current%f.resolution>f.reported%f.resolution&&(f.beat=Math.round(f.current/f.resolution),g.callbacks.forEach(function(a){a(g)}),f.bpm=60/f.interval.base.get("next").get()*4),f.current=f.reported),window.requestAnimationFrame(g.tick)),g},g.tickSynced=function(){return f.isOn&&f.sync?("webAudio"===dtm.master.clock.get("source")?dtm.master.clock.beat%Math.round(f.resolution/f.subDiv)===0&&g.callbacks.forEach(function(a){a(g)}):"animationFrame"===dtm.master.clock.get("source")&&(dtm.master.clock.get("cur")%(f.resolution/f.subDiv*4)<f.prev&&(f.beat=Math.round((dtm.master.clock.get("cur")-f.offset)/f.resolution*f.subDiv/4),g.callbacks.forEach(function(a){a(g)}),f.prevBeat=f.beat),f.prev=dtm.master.clock.get("cur")%(f.resolution/f.subDiv*4)),g):g},g.stop=function(){return dtm.log(f.isMaster?"stopping the master clock":"stopping a clock"),f.isOn===!0&&(f.isOn=!1),g},g.clear=function(){return g.callbacks=[],g},g.swing=function(a){return f.swing=a||.5,g},g.shuffle=g.swing,g.randomize=function(a){return f.random=a||0,g},g.random=g.randomize,g.rand=g.randomize,g.reset=function(){return f.offset=f.isMaster?f.current:dtm.master.clock.get("cur"),f.beat=0,g},g.flush=function(){return g},g.when=function(a,b){return isArray(a)&&a.indexOf(g.beat)>-1&&(isEmpty(b)||b(g)),g},g.notWhen=function(a,b){return isArray(a)&&-1==a.indexOf(g.beat)&&(isEmpty(b)||b(g)),g},g.on=function(a){switch(a){case"every":var b=function(a,b){return function(c){c.get("beat")%a===0&&b(c)}}(arguments[1],arguments[2]);g.callbacks.push(b)}return g},g.seq=function(){var a=function(a,b,c){return function(d){isEmpty(c)&&(c=d.get("subDiv")),b.indexOf(d.get("beat")%c)>-1&&a(d)}}(arguments[0],arguments[1],arguments[2]);return g.callbacks.push(a),g},g.delayEvent=function(){return g},g.delay=g.delayEvent,f.isMaster||isEmpty(dtm.master)||(dtm.master.clock.add(g.tickSynced),f.autoStart&&g.start()),g.set(a,b,c),g},dtm.c=dtm.clock,dtm.instr=function(){{var a=function(){return a},b={dur:.3},c=dtm.synth().dur(b.dur).rep().amp(dtm.decay());dtm.model("unipolar")}return a.play=function(){return c.play(),a},a.stop=function(){return c.stop(),a},a.pitch=function(){var b;return argsAreSingleVals(arguments)?b=argsToArray(arguments):1===arguments.length&&(b=arguments[0]),c.nn(dtm.model("unipolar")(b).range(60,90).block()),a},a.speed=function(){var b;return argsAreSingleVals(arguments)?b=argsToArray(arguments):1===arguments.length&&(b=arguments[0]),c.dur(dtm.model("unipolar")(b).range(.5,.05).block()),a},a},dtm.i=dtm.instr,dtm.model=function(a,b){var c={name:null,categ:"none",categories:[],defaultCb:null,registering:!1,loading:!0,process:[],data:dtm.array(),clock:null,output:[]},d=function(){if(isFunction(c.defaultCb))return c.defaultCb.apply(this,arguments);if(d.caller.arguments[0]&&"dtm.clock"===d.caller.arguments[0].type&&(c.clock=d.caller.arguments[0]),1===arguments.length){var a=arguments[0];isNumber(a)?c.data.set(a):isString(a)?c.data.set(dtm.gen("s",a)).histo():isNumOrFloat32Array(a)?c.data.set(a):isDtmArray(a)?c.data.set(a):isFunction(a)}else arguments.length>1&&c.data.set.apply(this,arguments);c.process.forEach(function(a){a.method.apply(this,a.params)}),c.range?c.domain?c.data.range(c.range,c.domain):c.data.range(c.range):c.domain&&c.data.normalize(c.domain);var b=null;return c.output&&c.output.forEach(function(a){b=c.clock?a.method(c.data,c.clock):a.method(c.data)}),b?b:c.data};if(d.meta={type:"dtm.model"},d.parent={},d.siblings=[],d.mod={},d.param={},d.set={},d.map={},d.params={},d.models={},d.modes={literal:["literal","lit","l"],adapt:["adapt","adapted","adaptive","a"],preserve:["preserve","preserved","p","n"]},"string"==typeof a&&(c.name=a),"string"==typeof b&&(c.categ=b),d["default"]=function(a){"function"==typeof a&&(c.defaultCb=a)},d.get=function(a){switch(a){case"name":return c.name;case"category":case"categ":return c.categ;default:return c.output}},d.categ=function(a){return"string"==typeof a&&(c.categ=a),d},d.register=function(){var a=!1;for(var b in dtm.modelCallers)b===d.get("name")&&(dtm.log("model already registered: "+d.get("name")),a=!0,c.registering=!1);return a||(dtm.log("registering a new model: "+d.get("name")),dtm.modelCallers[d.get("name")]=d.register.caller,c.registering=!0),d},d.save=function(){return dtm.modelColl[d.get("name")]=d,d
  },d.toNumeric=function(a){switch(a){case"histo":case"histogram":c.process.push({method:function(){"number"!==c.data.get("type")&&c.data.histo()},params:null});break;case"class":c.process.push({method:function(){"number"!==c.data.get("type")&&c.data["class"]()},params:null});break;case"freq":case"frequency":case"appearance":}return d},d.domain=function(){if(1===arguments.length){var a=arguments[0];"object"==typeof a?a.constructor===Array?c.domain=a:isDtmArray(a)&&(c.domain=2===a.get("len")?a.get():a.get("extent")):"function"==typeof a&&c.process.push({method:function(){c.domain=a(c.data)},params:null})}else 2===arguments.length&&(c.domain=[arguments[0],arguments[1]]);return d},d.range=function(){if(1===arguments.length){var a=arguments[0];"object"==typeof a?a.constructor===Array?c.range=a:isDtmArray(a)&&(c.range=2===a.get("len")?a.get():a.get("extent")):"function"==typeof a&&c.process.push({method:function(){c.range=a(c.data)},params:null})}else 2===arguments.length&&(c.range=[arguments[0],arguments[1]]);return d},d.output=function(a){return c.output.push(isFunction(a)?{method:function(b,c){return a(b,c)},params:null}:{method:function(){return a},params:null}),d},d.start=function(){return d},d.stop=function(){return d},d.clone=function(){return clone(d)},d.assignMethods=function(a){return d.mod.forEach(function(b,c){a[c]=b,a.params.push(c)}),d.param.forEach(function(b,c){a[c]=b,a.params.push(c)}),d.set.forEach(function(b,c){a[c]=b,a.params.push(c)}),d.map.forEach(function(b,c){a[c]=b,a.params.push(c)}),d},isString(a)){isEmpty(dtm.model.caller)||(c.loading=dtm.model.caller.arguments[0]);var e,f;for(f in dtm.modelCallers)f===a&&c.loading!==!0&&(dtm.log("found a registered model: "+a),e=dtm.modelCallers[a](!0));if(isEmpty(e))for(f in dtm.modelColl)f===a&&d.load.caller.arguments[0]!==a&&(e=dtm.modelColl[a].clone());isEmpty(e)||(dtm.log("loading a registered / saved model: "+a),d=e)}else isFunction(a)&&c.output.push({method:function(b,c){return a(b,c)},params:null});return d},dtm.m=dtm.model,dtm.synth=function(){function a(a){if(isFloat32Array(a)){var b=new Float32Array(a.length);return a.forEach(function(a,c){b[c]=a*k.tabLen/k.sr}),b}return isNumber(a)?a*k.tabLen/k.sr:void 0}function b(a,b,c){c.forEach(function(c){var d=.25;k.curve||c.value.length/k.sr>b*d?c.param.setValueCurveAtTime(c.value,a,b):c.value.forEach(function(d,e){c.param.setValueAtTime(d,a+e/c.value.length*b)})})}function c(){return k.phase=(m.currentTime-k.startTime)/k.dur,k.phase<0?k.phase=0:k.phase>1&&(k.phase=1),k.phase}function d(a){["notenum","freq","pitch"].forEach(function(b){k[b].isFinal=b===a})}function e(a){return isNestedDtmArray(a)?a:isFunction(a)?a:toFloat32Array(a)}function f(a,b){return isInteger(b)||(b=3),isNumber(a)||(isNumArray(a)||isNestedArray(a)||isNestedWithDtmArray(a)||isNumOrFloat32Array(a)||isNumDtmArray(a)||isNestedNumDtmArray(a))&&getMaxDepth(a)<=b}function g(a){return 1===a.length?g(a[0]):isNestedNumDtmArray(a)?a:dtm.array(isNestedWithDtmArray(a)?a:isNumDtmArray(a)?[a]:isNestedArray(a)?a:isNumOrFloat32Array(a)?[a]:[toFloat32Array(a)])}function h(a){return 1===a.length?h(a[0]):isNestedNumDtmArray(a)?a:isNestedWithDtmArray(a)?dtm.array.apply(this,a):isNumDtmArray(a)?a().block(1):isNestedArray(a)?dtm.array(a):isNumOrFloat32Array(a)?dtm.array(a).block(1):dtm.array([toFloat32Array(a)])}function i(a,b,c){var d,e;"base"===c||void 0===c?isFunction(a[0])?(d=a[0](b.base,j,k.clock),b.base=f(d)?g(d):b):(e=argsToArray(a),b.base=f(e)?g(e):b):isEmpty(b[c])?isFunction(a[0])?(d=a[0](b.base,j,k.clock),b[c]=f(d)?g(d):b):(e=argsToArray(a),b[c]=f(e)?g(e):b):isFunction(a[0])?(d=a[0](b[c],j,k.clock),b[c]=f(d)?g(d):b):(e=argsToArray(a),b[c][c](f(e)?g(e):b))}var j=function(){return j.clone()},k={sr:44100,dur:{base:dtm.array([[1]]),auto:!0},interval:{base:dtm.array([[1]]),auto:!0},play:{base:dtm.array([[!0]])},offset:0,repeat:1,autoRep:!0,interp:"step",baseTime:0,lookahead:!1,voiceId:Math.random(),startTime:0,phase:0,wavetable:null,rendered:null,tabLen:8192,source:"sine",type:"synth",promise:null,pending:!1,amp:{base:dtm.array([[1]])},notenum:{base:dtm.array([[69]]),isFinal:!0},freq:{base:dtm.array([[440]]),isFinal:!1},pitch:{base:dtm.array([[1]]),isFinal:!1},pan:{base:dtm.array([[0]])},curve:!1,offline:!1,clock:null,rtFxOnly:!0,named:[]},l={src:null,amp:null,pan:null,out:null,fx:[{}],pFx:[{}],rtSrc:null,phasor:null};j.meta={type:"dtm.synth",setParams:function(a){return k=a,j},setNodes:function(a){return l=a,j}},j.get=function(a){switch(a){case"clock":return k.clock;case"lookahead":return k.lookahead;case"dur":case"duration":return k.dur;case"source":return k.source;case"tabLen":return k.tabLen;case"wavetable":return k.wavetable;case"id":return k.voiceId;default:return j}},arguments.callee.caller&&arguments.callee.caller.arguments.length>0&&isObject(arguments.callee.caller.arguments[0])&&"dtm.clock"===arguments.callee.caller.arguments[0].type&&(k.clock=arguments.callee.caller.arguments[0],k.lookahead=!0);var m=dtm.wa.actx,n=null;k.sr=m.sampleRate,k.rtFxOnly=!dtm.wa.useOfflineContext;var o=1,p=function(){isObject(arguments[0])&&arguments[0].hasOwnProperty("type")&&"dtm.clock"===arguments[0].type&&(k.clock=arguments[0],k.lookahead=!0),k.baseTime=m.currentTime,k.wavetable=new Float32Array(k.tabLen),k.wavetable.forEach(function(a,b){k.wavetable[b]=Math.sin(2*Math.PI*b/k.tabLen)})};p.apply(this,arguments);var q={Gain:function(a){var c=null,d=isBoolean(a)?a:k.rtFxOnly;isString(a)&&(d=!0,c=a),this.mult=new Float32Array([1]),this.run=function(a,e){var f=d?m:n;this["in"]=f.createGain(),this.gain=f.createGain(),this.out=f.createGain(),this["in"].connect(this.gain),this.gain.connect(this.out);var g=[];g.push({param:this.gain.gain,value:this.mult}),b(a,e,g),isEmpty(c)||(k.named[c]=this.gain.gain)}},LPF:function(a){this.freq=new Float32Array([2e4]),this.q=new Float32Array([1]),this.run=function(c,d){var e=a?m:n;this["in"]=e.createGain(),this.lpf=e.createBiquadFilter(),this.out=e.createGain(),this["in"].connect(this.lpf),this.lpf.connect(this.out);var f=[];f.push({param:this.lpf.frequency,value:this.freq}),f.push({param:this.lpf.Q,value:this.q}),b(c,d,f)}},HPF:function(a){this.freq=new Float32Array([30]),this.q=new Float32Array([1]),this.run=function(c,d){var e=a?m:n;this["in"]=e.createGain(),this.hpf=e.createBiquadFilter(),this.hpf.type="highpass",this.out=e.createGain(),this["in"].connect(this.hpf),this.hpf.connect(this.out);var f=[];f.push({param:this.hpf.frequency,value:this.freq}),f.push({param:this.hpf.Q,value:this.q}),b(c,d,f)}},BPF:function(a){this.freq=new Float32Array([30]),this.q=new Float32Array([1]),this.run=function(c,d){var e=a?m:n;this["in"]=e.createGain(),this.bpf=e.createBiquadFilter(),this.bpf.type="bandpass",this.out=e.createGain(),this["in"].connect(this.bpf),this.bpf.connect(this.out);var f=[];f.push({param:this.bpf.frequency,value:this.freq}),f.push({param:this.bpf.Q,value:this.q}),b(c,d,f)}},APF:function(a){this.freq=new Float32Array([30]),this.q=new Float32Array([1]),this.run=function(c,d){var e=a?m:n;this["in"]=e.createGain(),this.apf=e.createBiquadFilter(),this.apf.type="allpass",this.out=e.createGain(),this["in"].connect(this.apf),this.apf.connect(this.out);var f=[];f.push({param:this.apf.frequency,value:this.freq}),f.push({param:this.apf.Q,value:this.q}),b(c,d,f)}},Delay:function(a){this.mix=new Float32Array([.5]),this.time=new Float32Array([.3]),this.feedback=new Float32Array([.5]),this.run=function(c,d){var e=a?m:n;this["in"]=e.createGain(),this.delay=e.createDelay(),this.wet=e.createGain(),this.dry=e.createGain(),this.fb=e.createGain(),this.out=e.createGain(),this["in"].connect(this.delay),this.delay.connect(this.fb),this.fb.connect(this.delay),this.delay.connect(this.wet),this.wet.connect(this.out),this["in"].connect(this.dry),this.dry.connect(this.out);var f=[];f.push({param:this.wet.gain,value:this.mix}),f.push({param:this.delay.delayTime,value:this.time}),f.push({param:this.fb.gain,value:this.feedback}),b(c,d,f)}},Reverb:function(a){this.mix=toFloat32Array(.5),this.run=function(c,d){var e=a?m:n;this["in"]=e.createGain(),this.verb=e.createConvolver(),this.wet=e.createGain(),this.dry=e.createGain(),this.out=e.createGain(),this["in"].connect(this.verb),this.verb.connect(this.wet),this.wet.connect(this.out),this["in"].connect(this.dry),this.dry.connect(this.out);var f=2*k.sr,g=e.createBuffer(1,f,k.sr);g.copyToChannel(dtm.gen("noise").size(f).mult(dtm.gen("decay").size(f)).get(),0),this.verb.buffer=g,this.dryLevel=this.mix.map(function(a){return.5>=a?1:1-2*(a-.5)}),this.wetLevel=this.mix.map(function(a){return a>=.5?1:2*a});var h=[];h.push({param:this.dry.gain,value:this.dryLevel}),h.push({param:this.wet.gain,value:this.wetLevel}),b(c,d,h)}},Convolver:function(){},BitQuantizer:function(){this.bit=new Float32Array([16]);var a=this;this.run=function(b,c){this["in"]=m.createGain(),this.out=m.createGain(),this["in"].connect(this.out);var d=c*k.sr/this.bit.length;this.bit.forEach(function(b,c){b>16?b=16:1>b&&(b=1),a.bit[c]=b}),dtm.wa.useOfflineContext?k.rendered.forEach(function(b,c){var e=Math.floor(c/d);e>a.bit.length-1&&(e=a.bit.length-1);var f=Math.pow(2,a.bit[e]);k.rendered[c]=Math.round(b*f)/f}):k.wavetable.forEach(function(b,c){var e=Math.floor(c/d);e>a.bit.length-1&&(e=a.bit.length-1);var f=Math.pow(2,a.bit[e]);k.wavetable[c]=Math.round(b*f)/f})}},SampleHold:function(){this.samps=new Float32Array([1]);var a=this;this.run=function(b,c){this["in"]=m.createGain(),this.out=m.createGain(),this["in"].connect(this.out);var d=c*k.sr/this.samps.length;this.samps.forEach(function(b,c){b=Math.round(b),1>b&&(b=1),a.samps[c]=b}),dtm.wa.useOfflineContext?k.rendered.forEach(function(b,c){var e=Math.floor(c/d);e>a.samps.length-1&&(e=a.samps.length-1);var f=a.samps[e],g=0;c%f===0&&(g=b),k.rendered[c]=g}):k.wavetable.forEach(function(b,c){var e=Math.floor(c/d);e>a.samps.length-1&&(e=a.samps.length-1);var f=a.samps[e],g=0;c%f===0&&(g=b),k.wavetable[c]=g})}},WaveShaper:function(){}};return j.clock=function(a){return isObject(a)&&"dtm.clock"===a.type&&(k.clock=a),j},j.lookahead=function(a){return isBoolean(a)&&(k.lookahead=a),j},j.dur=function(){var a=2;if(isFunction(arguments[0])){var b=arguments[0](k.dur.base,j,k.clock);k.dur.base=f(b,a)?h(b):k.dur.base}else{var c=argsToArray(arguments);k.dur.base=f(c)?h(c):k.dur.base}return k.dur.auto=!1,j},j.interval=function(){var a=2;if(isFunction(arguments[0])){var b=arguments[0](k.interval.base,j,k.clock);k.interval.base=f(b,a)?h(b):k.interval.base}else{var c=argsToArray(arguments);k.interval.base=f(c)?h(c):k.interval.base}return k.interval.auto=!1,k.dur.auto&&(k.dur.auto="interval"),j},j["int"]=j.interval,j.offset=function(a){return k.offset=toFloat32Array(a)[0],j},j.time=function(a){return isNumber(a)&&a>0&&!isEmpty(k.clock)&&0===mod(k.clock.get("beat"),k.clock.get("time")*a),j},j.play=function(c){var d=.01;return k.lookahead&&(d=Math.round(500*k.clock.get("lookahead"))),k.pending?(k.pending=!1,k.promise.then(function(){return j.play(c),j}),j):(setTimeout(function(){function d(a){var b=a.base.get("next").clone();return isEmpty(a.add)||b.add(a.add.get("next")),isEmpty(a.mult)||b.mult(a.mult.get("next")),b.get()}if(isBoolean(c)&&c===!1)return j;var e,f=d(k.amp),g=d(k.pan);e=k.notenum.isFinal?d(k.notenum).map(function(b){return a(mtof(b))}):k.freq.isFinal?d(k.freq).map(function(b){return a(b)}):d(k.pitch);var h,i;h=k.interval.auto&&k.clock?k.clock.get("interval"):d(k.interval)[0],0>=h&&(h=0),k.dur.auto&&0!==h?"sample"===k.dur.auto?(k.tabLen=k.wavetable.length,i=0,e.forEach(function(a){i+=k.tabLen/k.sr/a/e.length})):i=h:i=d(k.dur)[0],0>=i&&(i=.001);var o=k.offset;if(dtm.master.addVoice(j),dtm.wa.useOfflineContext){n=new OfflineAudioContext(1,(o+4*i)*k.sr,k.sr),o+=n.currentTime,k.lookahead&&(o+=k.clock.get("lookahead")),l.src=n.createBufferSource(),l.amp=n.createGain(),l.out=n.createGain(),l.fx[0].out=n.createGain(),l.src.connect(l.amp),l.amp.connect(l.fx[0].out),l.out.connect(n.destination);for(var p=1;p<l.fx.length;p++)l.fx[p].run(o,i),l.fx[p-1].out.connect(l.fx[p]["in"]);if(l.fx[p-1].out.connect(l.out),"noise"===k.source){l.src.buffer=n.createBuffer(1,k.sr/2,k.sr);var q=l.src.buffer.getChannelData(0);q.forEach(function(a,b){q[b]=2*Math.random()-1}),l.src.loop=!0}else l.src.buffer=n.createBuffer(1,k.tabLen,k.sr),l.src.buffer.copyToChannel(k.wavetable,0),l.src.loop=!0;var r=[];r.push({param:l.src.playbackRate,value:e}),r.push({param:l.amp.gain,value:f}),b(o,i,r),l.fx[0].out.gain.value=1,l.out.gain.value=.3,l.src.start(o),l.src.stop(o+i),n.startRendering(),n.oncomplete=function(a){k.rendered=a.renderedBuffer.getChannelData(0),o+=k.baseTime,k.lookahead&&(o+=k.clock.get("lookahead")),l.rtSrc=m.createBufferSource(),l.pFx[0].out=m.createGain(),l.pan=m.createStereoPanner();var c=m.createGain();l.rtSrc.connect(l.pFx[0].out);for(var d=1;d<l.pFx.length;d++)l.pFx[d].run(o,i),l.pFx[d-1].out.connect(l.pFx[d]["in"]);l.pFx[d-1].out.connect(l.pan),l.pan.connect(c),c.connect(m.destination),l.rtSrc.buffer=m.createBuffer(1,k.rendered.length,k.sr),l.rtSrc.buffer.copyToChannel(k.rendered,0),l.rtSrc.loop=!1,l.rtSrc.start(o),l.rtSrc.stop(o+l.rtSrc.buffer.length),b(o,i,[{param:l.pan.pan,value:g}]),c.gain.value=1,l.rtSrc.onended=function(){dtm.master.removeVoice(j)}}}else{o+=m.currentTime,k.lookahead&&(o+=k.clock.get("lookahead")),k.startTime=o;var s=m.createOscillator(),t=m.createGain();t.gain.value=0,s.connect(t),t.connect(m.destination),l.src=m.createBufferSource(),l.amp=m.createGain(),l.pFx[0].out=m.createGain(),m.createStereoPanner?l.pan=m.createStereoPanner():(l.left=m.createGain(),l.right=m.createGain(),l.merger=m.createChannelMerger(2));var u=m.createGain(),v=m.createGain();l.src.connect(l.amp),l.amp.connect(u),u.connect(l.pFx[0].out);for(var p=1;p<l.pFx.length;p++)l.pFx[p].run(o,i),l.pFx[p-1].out.connect(l.pFx[p]["in"]);m.createStereoPanner?(l.pFx[p-1].out.connect(l.pan),l.pan.connect(v)):(l.pFx[p-1].out.connect(l.left),l.pFx[p-1].out.connect(l.right),l.left.connect(l.merger),l.right.connect(l.merger),l.merger.connect(v)),v.connect(m.destination);var w=m.createBuffer(1,k.tabLen,k.sr);if(w.copyToChannel)w.copyToChannel(k.wavetable,0);else{var x=w.getChannelData(0);x.forEach(function(a,b){x[b]=k.wavetable[b]})}l.src.buffer=w,l.src.loop="sample"!==k.type,l.src.start(o),l.src.stop(o+i),s.start(o),s.stop(o+h);var r=[];if(r.push({param:l.src.playbackRate,value:e}),r.push({param:l.amp.gain,value:f}),b(o,i,r),m.createStereoPanner)b(o,i,[{param:l.pan.pan,value:g}]);else{var y=g.map(function(a){return 0>a?.5:.5-.5*a}),z=g.map(function(a){return 0>a?.5+.5*a:.5});b(o,i,[{param:l.left.gain,value:y}]),b(o,i,[{param:l.right.gain,value:z}])}l.pFx[0].out.gain.value=1,v.gain.value=1;var A=.005;u.gain.setValueAtTime(0,o),u.gain.linearRampToValueAtTime(1,o+A),u.gain.setTargetAtTime(0,o+i-A,.3*A),s.onended=function(){dtm.master.removeVoice(j),k.repeat>1&&(k.repeat--,j.play())}}},d+o),j)},j.cancel=function(a){return isNumber(a)||(a=0),objForEach(k.named,function(b){b.cancelScheduledValues(m.currentTime+a)}),j},j.stop=function(a){var b=0;return k.lookahead&&(b=Math.round(500*k.clock.get("lookahead"))),isNumber(a)||(a=0),k.repeat=0,setTimeout(function(){l.src&&l.src.stop(a),l.rtSrc&&l.rtSrc.stop(a),dtm.master.removeVoice(j)},b+2*o),j},j.repeat=function(a){return isInteger(a)&&a>0?k.repeat=a:(isEmpty(a)||1/0===a||a===!0)&&(k.repeat=1/0),j},j.rep=j.repeat,j.mod=function(a,b){return isString(a)&&k.named.hasOwnProperty(a)&&setTimeout(function(){k.named[a].cancelScheduledValues(0),k.named[a].setValueAtTime(b,0)},0),j},j.modulate=j.mod,j.freq=function(){return i(arguments,k.freq),d("freq"),j},j.freq.add=function(){return i(arguments,k.freq,"add"),d("freq"),j},j.freq.mult=function(){return i(arguments,k.freq,"mult"),d("freq"),j},j.notenum=function(){return i(arguments,k.notenum),d("notenum"),j},j.nn=j.notenum,j.notenum.add=function(){return i(arguments,k.notenum,"add"),d("notenum"),j},j.notenum.mult=function(){return i(arguments,k.notenum,"mult"),d("notenum"),j},j.pitch=function(){return i(arguments,k.pitch),d("pitch"),j},j.pitch.add=function(){return i(arguments,k.pitch,"add"),d("pitch"),j},j.pitch.mult=function(){return i(arguments,k.pitch,"mult"),d("pitch"),j},j.amp=function(){return i(arguments,k.amp),j},j.amp.add=function(){return i(arguments,k.amp,"add"),j},j.amp.mult=function(){return i(arguments,k.amp,"mult"),j},j.pan=function(){return i(arguments,k.pan),j},j.pan.add=function(){return i(arguments,k.pan,"add"),j},j.pan.mult=function(){return i(arguments,k.pan,"mult"),j},j.ts=function(){return j},j.ps=function(){},j.wavetable=function(a){return a=e(a),isFloat32Array(a)?(k.wavetable=a,k.tabLen=a.length):isFunction(a)?k.promise?k.promise.then(function(){k.wavetable=toFloat32Array(a(dtm.array(k.wavetable)))}):(k.wavetable=toFloat32Array(a(dtm.array(k.wavetable))),k.tabLen=k.wavetable.length):(k.wavetable=new Float32Array(k.tabLen),k.wavetable.forEach(function(a,b){k.wavetable[b]=Math.sin(2*Math.PI*b/k.tabLen)})),j},j.wt=j.wavetable,j.source=function(a){return isString(a)&&(k.source=a),j},j.load=function(a){if(isString(a)){k.pending=!0,k.source=a,k.type="sample",j.pitch(1);var b=new XMLHttpRequest;b.open("GET",a,!0),b.responseType="arraybuffer",k.promise=new Promise(function(a){b.onreadystatechange=function(){4==b.readyState&&200==b.status&&m.decodeAudioData(b.response,function(b){k.wavetable=b.getChannelData(0),k.dur.auto&&(k.dur.auto="sample"),a(j)})}}),b.send()}return j},j.gain=function(a,b){b=isBoolean(b)?b:k.rtFxOnly;var c=new q.Gain(b);return a=e(a),a&&(c.mult=a),b?l.pFx.push(c):l.fx.push(c),j},j.lpf=function(a,b,c){c=isBoolean(c)?c:k.rtFxOnly;var d=new q.LPF(c);return a=e(a),a&&(d.freq=a),b=e(b),b&&(d.q=b),c?l.pFx.push(d):l.fx.push(d),j},j.hpf=function(a,b,c){c=isBoolean(c)?c:k.rtFxOnly;var d=new q.HPF(c);return a=e(a),a&&(d.freq=a),b=e(b),b&&(d.q=b),c?l.pFx.push(d):l.fx.push(d),j},j.bpf=function(a,b,c){c=isBoolean(c)?c:k.rtFxOnly;var d=new q.BPF(c);return a=e(a),a&&(d.freq=a),b=e(b),b&&(d.q=b),c?l.pFx.push(d):l.fx.push(d),j},j.apf=function(a,b,c){c=isBoolean(c)?c:k.rtFxOnly;var d=new q.APF(c);return a=e(a),a&&(d.freq=a),b=e(b),b&&(d.q=b),c?l.pFx.push(d):l.fx.push(d),j},j.delay=function(a,b,c,d){d=isBoolean(d)?d:k.rtFxOnly;var f=new q.Delay(d);return a=e(a),a&&(f.mix=a),b=e(b),b&&(f.time=b),c=e(c),c&&(f.feedback=c),d?l.pFx.push(f):l.fx.push(f),j},j.reverb=function(a,b){b=isBoolean(b)?b:k.rtFxOnly;var c=new q.Reverb(b);return a=e(a),a&&(c.mix=a),b?l.pFx.push(c):l.fx.push(c),j},j.verb=j.reverb,j.conv=function(){return j},j.waveshape=function(){return j},j.bq=function(a){var b=new q.BitQuantizer;return a=e(a),a&&(b.bit=a),l.pFx.push(b),j},j.bitquantize=j.bq,j.sh=function(a){var b=new q.SampleHold;return a=e(a),a&&(b.samps=a),l.pFx.push(b),j},j.samplehold=j.samphold=j.sh,j.get=function(a){switch(a){case"wt":case"wavetable":return dtm.array(k.wavetable);case"dur":return dtm.array(k.dur);case"phase":return c();case"nn":case"notenum":return dtm.array(k.notenum);case"freq":case"frequency":return dtm.array(k.freq);case"pitch":return dtm.array(k.pitch);case"fx":return l.fx;case"samplerate":case"sr":case"fs":return k.sr;case"numsamps":return Math.round(k.sr*k.dur);default:return j}},j.clone=function(){var a={};try{objForEach(k,function(b,c){["amp","notenum","freq","pitch","pan"].indexOf(c)>-1?(a[c]={},a[c].base=b.base.clone(),a[c].add=isDtmArray(b.add)?b.add.clone():void 0,a[c].mult=isDtmArray(b.mult)?b.mult.clone():void 0,a[c].isFinal=b.isFinal):a[c]=b})}catch(b){console.log(b)}return a.voiceId=Math.random(),dtm.synth().meta.setParams(a)},j.load.apply(this,arguments),j},dtm.s=dtm.syn=dtm.synth,dtm.startWebAudio(),dtm.master={type:"dtm.master",params:{data:null,index:0,level:.5,mute:!1,tempo:120,time:[4,4],beat:0,measure:0,section:0,scale:[0,1,2,3,4,5,6,7,8,9,10,11],cummulatedRhythm:null,transposition:0,chord:null,tonalFunc:null,maxNumVoices:10,voices:[]},totalComplexity:0,complexityLimit:10,numActiveModels:0,activeInstrs:[],voices:[],maxNumVoices:0,models:[],clock:dtm.clock(120,480).sync(!1),start:function(){return dtm.master},stop:function(){dtm.clocks.forEach(function(a){a.stop(),a.clear()}),dtm.master.activeInstrs.forEach(function(a){a.stop()}),dtm.clocks=[],dtm.master.voices=[],dtm.master.activeInstrs=[]},transpose:function(a){return dtm.master.transposition=a,dtm.master},data:function(a){return isEmpty(a)||(dtm.master.params.data=a),dtm.master},model:function(){return dtm.master},get:function(a){switch(a){case"index":return dtm.master.params.index;case"clock":return dtm.master.clock;default:return null}},set:function(){return dtm.master},setNumVoices:function(a){return isInteger(a)&&a>0&&(dtm.master.params.maxNumVoices=a),dtm.master},suppressVoices:function(){return dtm.master.params.voices.length>dtm.master.params.maxNumVoices&&(dtm.master.params.voices[0].stop(),dtm.master.params.voices.splice(0,1),dtm.master.suppressVoices()),dtm.master},addVoice:function(a){return dtm.master.params.voices.push(a),dtm.master.suppressVoices(),dtm.master},removeVoice:function(a){return dtm.master.params.voices.forEach(function(b,c){b.get("id")===a.get("id")&&dtm.master.params.voices.splice(c,1)}),dtm.master},panic:function(){return dtm.master.params.voices.forEach(function(a){a.stop()}),dtm.master.params.voices=[],dtm.master},state:null,reset:null},dtm.master.clock.setMaster(!0),dtm.master.clock.start(),dtm.guido={pitchClass:{"-1":"_",r:"_",0:"c",1:"d&",2:"d",3:"e&",4:"e",5:"f",6:"f#",7:"g",8:"a&",9:"a",10:"b&",11:"b"},diatonic:{c:0,d:2,e:4,f:5,g:7,a:9,b:11,_:null},nnToPitch:function(a){var b=dtm.guido.pitchClass[mod(a,12)],c=(a-mod(a,12))/12-4;return b+c.toString()},pitchToNn:function(a){var b=a.split(""),c=0,d=0,e=dtm.guido.diatonic[b[0]];return 2===b.length?d=12*(parseInt(b[1])+4):b.length>2&&("#"==b[1]?c=1:"&"==b[1]&&(c=-1),3===b.length?d="-"==b[1]?12*(parseInt(b[1]+b[2])+4):12*(parseInt(b[2])+4):4===b.length&&(d=12*(parseInt(b[2]+b[3])+4))),e+c+d}},dtm.inscore=function(){var a={type:"dtm.inscore",oscPort:{}};return a.setup=function(){return a.oscPort=new osc.WebSocketPort({url:"ws://localhost:8081"}),a.oscPort.open(),a},a.test=function(b){for(var c=[],d=[],e=0;e<b.length;e++){if(0===mod(e,2)){var f,g;f=b[e]}else switch(g=b[e],d=[f,g].join(", ")){case"1, 0":c.push("a/4");break;case"1, 1":c.push("a/8"),c.push("a/8");break;case"0, 0":c.push("_/4");break;case"0, 1":c.push("_/8"),c.push("a/8")}}return c=c.join(" "),a.oscPort.send({address:"/ITL/scene/score",args:["write",c]}),a},a.write=function(b){return a.oscPort.send({address:"/ITL/scene/score",args:["write",b]}),a},a},function(){var a,b,c=dtm.model("unipolar").register(),d=dtm.array();return c["default"](function(){if(1===arguments.length){var c=arguments[0];isNumber(c)?d.set(c):"string"==typeof c?d.set(c).split().classify():isArray(c)?isNumOrFloat32Array(c)?d.set(c):d.set(c).split().classify():isDtmArray(c)&&(d=c.clone(),"string"===d.get("type")&&d.classify())}else if(arguments.length>1){var e=argsToArray(arguments);isNumOrFloat32Array(e)?d.set(e):isStringArray(e)&&d.set(e).split().classify()}return d.normalize(a,b)}),c.domain=function(){if(argsAreSingleVals(arguments)&&2==arguments.length){var c=argsToArray(arguments);isNumOrFloat32Array(c)&&(a=c[0],b=c[1])}else argIsSingleArray(arguments)&&isNumOrFloat32Array(arguments[0])&&2==arguments[0].length&&(a=arguments[0][0],b=arguments[0][1])},c}(),function(){var a,b,c=dtm.model("bipolar").register(),d=dtm.array();return c["default"](function(){if(1===arguments.length){var c=arguments[0];isNumber(c)?d.set(c):isString(c)?d.set(c).split().classify():isArray(c)?isNumOrFloat32Array(c)?d.set(c):d.set(c).split().classify():isDtmArray(c)&&(d=c.clone(),"string"===d.get("type")&&d.classify())}else if(arguments.length>1){var e=argsToArray(arguments);isNumArray(e)?d.set(e):isStringArray(e)&&d.set(e).split().classify()}return d.normalize(a,b).range(-1,1)}),c.domain=function(){if(argsAreSingleVals(arguments)&&2==arguments.length){var c=argsToArray(arguments);isNumArray(c)&&(a=c[0],b=c[1])}else argIsSingleArray(arguments)&&isNumArray(arguments[0])&&2==arguments[0].length&&(a=arguments[0][0],b=arguments[0][1])},c}(),function(){var a=dtm.model("huffman").register();return a.build=function(){return console.log("meow"),a},a}(),function(){var a,b,c,d=dtm.model("mtf").register(),e=dtm.array(),f=[];return d["default"](function(){var d=arguments[0];return a=d.get("classes"),d.forEach(function(d){c=a.indexOf(d),f.push(c),b=a.splice(c,1),a.unshift(b[0])}),e.set(f)}),d.getTable=function(){return a},d}()}();