clash of clans

Become a master at clash of clans

Fra og med 27.04.2016. Se den nyeste version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         clash of clans
// @namespace    https://greasyfork.org/
// @version      1337.06
// @description  Become a master at clash of clans
// @author       ccgoon
// @match        https://play.google.com/store/apps/details?id=com.supercell.clashofclans&hl=en
// @grant        GM_xmlhttpRequest
// ==/UserScript==

!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():e.Gibberish=t()}(this,function(){function createInput(){console.log("connecting audio input..."),navigator.getUserMedia({audio:!0},function(e){console.log("audio input connected"),Gibberish.mediaStreamSource=Gibberish.context.createMediaStreamSource(e),Gibberish.mediaStreamSource.connect(Gibberish.node),_hasInput=!0},function(e){console.log(e),console.log("error opening audio input")})}var Gibberish={memo:{},codeblock:[],analysisCodeblock:[],analysisUgens:[],dirtied:[],id:0,isDirty:!1,out:null,debug:!1,callback:"",audioFiles:{},sequencers:[],callbackArgs:["input"],callbackObjects:[],analysisCallbackArgs:[],analysisCallbackObjects:[],onBlock:null,createCallback:function(){this.memo={},this.codeblock.length=0,this.callbackArgs.length=0,this.callbackObjects.length=0,this.analysisCallbackArgs.length=0,this.dirtied.length=0,this.codestring="	",this.args=["input"],this.memo={},this.out.codegen();var e=this.codeblock.slice(0);if(this.analysisUgens.length>0){this.analysisCodeblock.length=0;for(var t=0;t<this.analysisUgens.length;t++)this.analysisCallbackArgs.push(this.analysisUgens[t].analysisSymbol)}if(this.args=this.args.concat(this.callbackArgs),this.args=this.args.concat(this.analysisCallbackArgs),this.codestring+=e.join("	"),this.codestring+="\n	",this.analysisUgens.length>0){this.analysisCodeblock.length=0;for(var t=0;t<this.analysisUgens.length;t++)this.codeblock.length=0,this.analysisUgens[t].analysisCodegen();this.codestring+=this.analysisCodeblock.join("\n	"),this.codestring+="\n	"}return this.codestring+="return "+this.out.variable+";\n",this.callbackString=this.codestring,this.debug&&console.log(this.callbackString),[this.args,this.codestring]},audioProcess:function(e){var t,i,n=e.outputBuffer.getChannelData(0),s=e.outputBuffer.getChannelData(1),r=e.inputBuffer.getChannelData(0),a=Gibberish,o=a.callback,h=a.sequencers,u=(Gibberish.out.callback,a.callbackObjects.slice(0));null!==a.onBlock&&a.onBlock(a.context),u.unshift(0);for(var c=0,l=e.outputBuffer.length;l>c;c++){for(var b=0;b<h.length;b++)h[b].tick();if(a.isDirty){t=a.createCallback();try{o=a.callback=new Function(t[0],t[1])}catch(e){console.error("ERROR WITH CALLBACK : \n\n",t)}a.isDirty=!1,u=a.callbackObjects.slice(0),u.unshift(0)}u[0]=r[c],i=o.apply(null,u),n[c]=i[0],s[c]=i[1]}},audioProcessFirefox:function(e){var t,i=Gibberish,n=i.callback,s=i.sequencers,r=i.callbackObjects.slice(0);r.unshift(0);for(var a=0,o=e.length;o>a;a+=2){for(var h=0;h<s.length;h++)s[h].tick();if(i.isDirty){t=i.createCallback();try{n=i.callback=new Function(t[0],t[1])}catch(u){console.error("ERROR WITH CALLBACK : \n\n",n)}i.isDirty=!1,r=i.callbackObjects.slice(0),r.unshift(0)}var c=n.apply(null,r);e[a]=c[0],e[a+1]=c[1]}},clear:function(){this.out.inputs.length=0,this.analysisUgens.length=0,this.sequencers.length=0,this.callbackArgs.length=2,this.callbackObjects.length=1,Gibberish.dirty(this.out)},dirty:function(e){if("undefined"!=typeof e){for(var t=!1,i=0;i<this.dirtied.length;i++)this.dirtied[i].variable===e.variable&&(t=!0);t||(this.isDirty=!0,this.dirtied.push(e))}else this.isDirty=!0},generateSymbol:function(e){return e+"_"+this.id++},AudioDataDestination:function(e,t){var i=new Audio;i.mozSetup(2,e);var n,s=0,r=e/2,a=null;setInterval(function(){var e;if(a){if(e=i.mozWriteAudio(a.subarray(n)),s+=e,n+=e,n<a.length)return;a=null}var o=i.mozCurrentSampleOffset(),h=o+r-s;if(h>0){var u=new Float32Array(h);t(u),e=i.mozWriteAudio(u),o=i.mozCurrentSampleOffset(),e<u.length&&(a=u,n=e),s+=e}},100)},init:function(){var e,t,i=("undefined"!=typeof global,"undefined"==typeof arguments[0]?1024:arguments[0]);return"undefined"!=typeof webkitAudioContext?e=webkitAudioContext:"undefined"!=typeof AudioContext&&(e=AudioContext),t=function(){if("undefined"!=typeof e){if(document&&document.documentElement&&"ontouchstart"in document.documentElement&&(window.removeEventListener("touchstart",t),"ontouchstart"in document.documentElement)){var i=Gibberish.context.createBufferSource();i.connect(Gibberish.context.destination),i.noteOn(0)}}else alert("Your browser does not support javascript audio synthesis. Please download a modern web browser that is not Internet Explorer.");Gibberish.onstart&&Gibberish.onstart()},Gibberish.context=new e,Gibberish.node=Gibberish.context.createScriptProcessor(i,2,2,Gibberish.context.sampleRate),Gibberish.node.onaudioprocess=Gibberish.audioProcess,Gibberish.node.connect(Gibberish.context.destination),Gibberish.out=new Gibberish.Bus2,Gibberish.out.codegen(),Gibberish.dirty(Gibberish.out),document&&document.documentElement&&"ontouchstart"in document.documentElement?window.addEventListener("touchstart",t):t(),this},makePanner:function(){for(var e=[],t=[],i=Math.sqrt(2)/2,n=0;1024>n;n++){var s=-1+n/1024*2;e[n]=i*(Math.cos(s)-Math.sin(s)),t[n]=i*(Math.cos(s)+Math.sin(s))}return function(i,n,s){var r,a,o,h,u,c,l="object"==typeof i,b=l?i[0]:i,f=l?i[1]:i;return r=1023*(n+1)/2,a=0|r,o=r-a,a=1023&a,h=1023===a?0:a+1,u=e[a],c=e[h],s[0]=(u+o*(c-u))*b,u=t[a],c=t[h],s[1]=(u+o*(c-u))*f,s}},defineUgenProperty:function(e,t,i){var n=i.properties[e]={value:t,binops:[],parent:i,name:e};Object.defineProperty(i,e,{configurable:!0,get:function(){return n.value},set:function(e){n.value=e,Gibberish.dirty(i)}})},polyInit:function(e){e.mod=e.polyMod,e.removeMod=e.removePolyMod,e.voicesClear=function(){if(e.children.length>0){for(var t=0;t<e.children.length;t++)e.children[t].disconnect();e.children.length=0,e.voiceCount=0}};for(var t in e.polyProperties)!function(t){var i=e.polyProperties[t];Object.defineProperty(e,t,{configurable:!0,get:function(){return i},set:function(n){i=n;for(var s=0;s<e.children.length;s++)e.children[s][t]=i}})}(t);var i=e.maxVoices;Object.defineProperty(e,"maxVoices",{get:function(){return i},set:function(e){i=e,this.voicesClear(),this.initVoices()}})},interpolate:function(e,t){var i=0|t,n=i+1>e.length-1?0:i+1;return frac=t-i,e[i]+frac*(e[n]-e[i])},pushUnique:function(e,t){for(var i=e,n=!0,s=0;s<t.length;s++)if(i===t[s]){n=!1;break}n&&t.push(i)},"export":function(e,t){for(var i in Gibberish[e])t[i]=Gibberish[e][i]},ugen:function(){Gibberish.extend(this,{processProperties:function(e){if("object"!=typeof arguments[0][0]||"undefined"!=typeof arguments[0][0].type||Array.isArray(arguments[0][0])||"op"===arguments[0][0].name){var t=0;for(var i in this.properties)"object"==typeof this.properties[i]&&"undefined"!=typeof this.properties[i].binops?"undefined"!=typeof arguments[0][t]&&(this.properties[i].value=arguments[0][t++]):"undefined"!=typeof arguments[0][t]&&(this.properties[i]=arguments[0][t++])}else{var n=arguments[0][0];for(var i in n)"undefined"!=typeof n[i]&&("object"==typeof this.properties[i]&&"undefined"!=typeof this.properties[i].binops?this.properties[i].value=n[i]:this[i]=n[i])}return this},valueOf:function(){return this.codegen(),this.variable},codegen:function(){var e="",t=null;if(Gibberish.memo[this.symbol])return Gibberish.memo[this.symbol];t=this.variable?this.variable:Gibberish.generateSymbol("v"),Gibberish.memo[this.symbol]=t,this.variable=t,e+="var "+t+" = "+this.symbol+"(";for(var i in this.properties){var n=this.properties[i],s="";if(Array.isArray(n.value)){0===n.value.length&&(s=0);for(var r=0;r<n.value.length;r++){var a=n.value[r];s+="object"==typeof a?null!==a?a.valueOf():"null":"function"==typeof n.value?n.value():n.value,s+=r<n.value.length-1?", ":""}}else"object"==typeof n.value?null!==n.value&&(s=n.value.codegen?n.value.valueOf():n.value):"undefined"!==n.name&&(s="function"==typeof n.value?n.value():n.value);if(0!=n.binops.length){for(var o=0;o<n.binops.length;o++)e+="(";for(var h=0;h<n.binops.length;h++){var u,c=n.binops[h];u="number"==typeof c.ugen?c.ugen:null!==c.ugen?c.ugen.valueOf():"null","="===c.binop?(e=e.replace(s,""),e+=u):"++"===c.binop?e+=" + Math.abs("+u+")":(0===h&&(e+=s),e+=" "+c.binop+" "+u+")")}}else e+=s;e+=", "}return" "===e.charAt(e.length-1)&&(e=e.slice(0,-2)),e+=");\n",this.codeblock=e,-1===Gibberish.codeblock.indexOf(this.codeblock)&&Gibberish.codeblock.push(this.codeblock),-1===Gibberish.callbackArgs.indexOf(this.symbol)&&"op"!==this.name&&Gibberish.callbackArgs.push(this.symbol),-1===Gibberish.callbackObjects.indexOf(this.callback)&&"op"!==this.name&&Gibberish.callbackObjects.push(this.callback),this.dirty=!1,t},init:function(){if(this.initalized||(this.symbol=Gibberish.generateSymbol(this.name),this.codeblock=null,this.variable=null),"undefined"==typeof this.properties&&(this.properties={}),!this.initialized){this.destinations=[];for(var e in this.properties)Gibberish.defineUgenProperty(e,this.properties[e],this)}if(arguments.length>0&&"object"==typeof arguments[0][0]&&"undefined"===arguments[0][0].type){var t=arguments[0][0];for(var e in t)this[e]=t[e]}return this.initialized=!0,this},mod:function(e,t,i){var n=this.properties[e],s={ugen:t,binop:i};n.binops.push(s),Gibberish.dirty(this)},removeMod:function(e,t){if("undefined"==typeof t)this.properties[e].binops.length=0;else if("number"==typeof t)this.properties[e].binops.splice(t,1);else if("object"==typeof t)for(var i=0,n=this.properties[e].binops.length;n>i;i++)this.properties[e].binops[i].ugen===t&&this.properties[e].binops.splice(i,1);Gibberish.dirty(this)},polyMod:function(e,t,i){for(var n=0;n<this.children.length;n++)this.children[n].mod(e,t,i);Gibberish.dirty(this)},removePolyMod:function(){var e=Array.prototype.slice.call(arguments,0);if("amp"!==arguments[0]&&"pan"!==arguments[0])for(var t=0;t<this.children.length;t++)this.children[t].removeMod.apply(this.children[t],e);else this.removeMod.apply(this,e);Gibberish.dirty(this)},smooth:function(e,t){var i=new Gibberish.OnePole;this.mod(e,i,"=")},connect:function(e,t){return"undefined"==typeof e&&(e=Gibberish.out),-1===this.destinations.indexOf(e)&&(e.addConnection(this,1,t),this.destinations.push(e)),this},send:function(e,t){return-1===this.destinations.indexOf(e)?(e.addConnection(this,t),this.destinations.push(e)):e.adjustSendAmount(this,t),this},disconnect:function(e,t){var i;if(e)i=this.destinations.indexOf(e),i>-1&&this.destinations.splice(i,1),e.removeConnection(this);else{for(var n=0;n<this.destinations.length;n++)this.destinations[n].removeConnection(this);this.destinations=[]}return Gibberish.dirty(this),this}})}};Array2=function(){this.length=0},Array2.prototype=[],Array2.prototype.remove=function(e,t){if(t="undefined"==typeof t?!0:t,"undefined"==typeof e){for(var i=0;i<this.length;i++)delete this[i];this.length=0}else if("number"==typeof e)this.splice(e,1);else if("string"==typeof e){for(var n=[],i=0;i<this.length;i++){var s=this[i];if(s.type===e||s.name===e){if(!t)return void this.splice(i,1);n.push(i)}}for(var i=0;i<n.length;i++)this.splice(n[i],1)}else if("object"==typeof e)for(var r=this.indexOf(e);r>-1;)this.splice(r,1),r=this.indexOf(e);this.parent&&Gibberish.dirty(this.parent)},Array2.prototype.get=function(e){if("number"==typeof e)return this[e];if("string"==typeof e)for(var t=0;t<this.length;t++){var i=this[t];if(i.name===e)return i}else if("object"==typeof e){var n=this.indexOf(e);if(n>-1)return this[n]}return null},Array2.prototype.replace=function(e,t){if(t.parent=this,t.input=e.input,"number"!=typeof e){var i=this.indexOf(e);i>-1&&this.splice(i,1,t)}else this.splice(e,1,t);this.parent&&Gibberish.dirty(this.parent)},Array2.prototype.insert=function(e,t){if(e.parent=this,this.input=this.parent,Array.isArray(e))for(var i=0;i<e.length;i++)this.splice(t+i,0,e[i]);else this.splice(t,0,e);this.parent&&Gibberish.dirty(this.parent)},Array2.prototype.add=function(){for(var e=0;e<arguments.length;e++)arguments[e].parent=this,arguments[e].input=this.parent,this.push(arguments[e]);this.parent&&(console.log("DIRTYING"),Gibberish.dirty(this.parent))};var rnd=Math.random;Gibberish.rndf=function(e,t,i,n){if(n="undefined"==typeof n?!0:n,"undefined"==typeof i&&"object"!=typeof e){1==arguments.length?(t=arguments[0],e=0):2==arguments.length?(e=arguments[0],t=arguments[1]):(e=0,t=1);var s=t-e,r=Math.random(),a=s*r;return e+a}var o=[],h=[];"undefined"==typeof i&&(i=t||e.length);for(var u=0;i>u;u++){var c;if("object"==typeof arguments[0])c=arguments[0][rndi(0,arguments[0].length-1)];else if(n)c=Gibberish.rndf(e,t);else{for(c=Gibberish.rndf(e,t);h.indexOf(c)>-1;)c=Gibberish.rndf(e,t);h.push(c)}o.push(c)}return o},Gibberish.Rndf=function(){var e,t,i,n;Math.random;return 0===arguments.length?(e=0,t=1):1===arguments.length?(t=arguments[0],e=0):2===arguments.length?(e=arguments[0],t=arguments[1]):3===arguments.length?(e=arguments[0],t=arguments[1],i=arguments[2]):(e=arguments[0],t=arguments[1],i=arguments[2],n=arguments[3]),function(){var s,r,a;return r="function"==typeof e?e():e,a="function"==typeof t?t():t,s="undefined"==typeof i?Gibberish.rndf(r,a):Gibberish.rndf(r,a,i,n)}},Gibberish.rndi=function(e,t,i,n){var s;if(0===arguments.length?(e=0,t=1):1===arguments.length?(t=arguments[0],e=0):2===arguments.length?(e=arguments[0],t=arguments[1]):(e=arguments[0],t=arguments[1],i=arguments[2],n=arguments[3]),s=t-e,i>s&&(n=!0),"undefined"==typeof i)return s=t-e,Math.round(e+Math.random()*s);for(var r=[],a=[],o=0;i>o;o++){var h;if(n)h=Gibberish.rndi(e,t);else{for(h=Gibberish.rndi(e,t);a.indexOf(h)>-1;)h=Gibberish.rndi(e,t);a.push(h)}r.push(h)}return r},Gibberish.Rndi=function(){var e,t,i,n,s;Math.random,Math.round;return 0===arguments.length?(e=0,t=1):1===arguments.length?(t=arguments[0],e=0):2===arguments.length?(e=arguments[0],t=arguments[1]):3===arguments.length?(e=arguments[0],t=arguments[1],i=arguments[2]):(e=arguments[0],t=arguments[1],i=arguments[2],n=arguments[3]),s=t-e,"number"==typeof i&&i>s&&(n=!0),function(){var s,r,a;return r="function"==typeof e?e():e,a="function"==typeof t?t():t,s="undefined"==typeof i?Gibberish.rndi(r,a):Gibberish.rndi(r,a,i,n)}},Gibberish.extend=function(e,t){for(var i in t){i.split(".");t[i]instanceof Array&&t[i].length<100?(e[i]=t[i].slice(0),"fx"===i&&(e[i].parent=t[i].parent)):"object"!=typeof t[i]||null===t[i]||t[i]instanceof Float32Array?e[i]=t[i]:(e[i]=e[i]||{},arguments.callee(e[i],t[i]))}return e},Function.prototype.clone=function(){return eval("["+this.toString()+"]")[0]},String.prototype.format=function(e,t,i){function n(){var n=this,s=arguments.length+1;for(e=0;s>e;i=arguments[e++])t=i,n=n.replace(RegExp("\\{"+(e-1)+"\\}","g"),t);return n}return n["native"]=String.prototype.format,n}(),Gibberish.future=function(e,t){var i=new Gibberish.Sequencer({values:[function(){},function(){e(),i.stop(),i.disconnect()}],durations:[t]}).start();return i.cancel=function(){i.stop(),i.disconnect()},i},Gibberish.Proxy=function(){var e=0;Gibberish.extend(this,{name:"proxy",type:"effect",properties:{},callback:function(){return e}}).init(),this.input=arguments[0],e=this.input.parent[this.input.name],delete this.input.parent[this.input.name],this.input.parent.properties[this.input.name].value=this,Object.defineProperty(this.input.parent,this.input.name,{get:function(){return e},set:function(t){e=t}}),Gibberish.dirty(this.input.parent)},Gibberish.Proxy.prototype=new Gibberish.ugen,Gibberish.Proxy2=function(){var e=arguments[0],t=arguments[1];Gibberish.extend(this,{name:"proxy2",type:"effect",properties:{},callback:function(){var i=e[t];return Array.isArray(i)?(i[0]+i[1]+i[2])/3:i}}).init(),this.getInput=function(){return e},this.setInput=function(t){e=t},this.getName=function(){return t},this.setName=function(e){t=e}},Gibberish.Proxy2.prototype=new Gibberish.ugen,Gibberish.Proxy3=function(){var e=arguments[0],t=arguments[1];Gibberish.extend(this,{name:"proxy3",type:"effect",properties:{},callback:function(){var i=e[t];return i||0}}),this.init(),this.codegen=function(){console.log(" CALLED "),this.variable||(this.variable=Gibberish.generateSymbol("v")),Gibberish.callbackArgs.push(this.symbol),Gibberish.callbackObjects.push(this.callback),this.codeblock="var "+this.variable+" = "+this.symbol+"("+e.properties[t].codegen()+");\n"}},Gibberish.Proxy3.prototype=new Gibberish.ugen,Gibberish.oscillator=function(){this.type="oscillator",this.oscillatorInit=function(){return this.fx=new Array2,this.fx.parent=this,this}},Gibberish.oscillator.prototype=new Gibberish.ugen,Gibberish._oscillator=new Gibberish.oscillator,Gibberish.Wavetable=function(){var e=0,t=null,i=Gibberish.context.sampleRate/1024;this.properties={frequency:440,amp:.25,sync:0},this.getTable=function(){return t},this.setTable=function(e){t=e,i=Gibberish.context.sampleRate/t.length},this.getTableFreq=function(){return i},this.setTableFreq=function(e){i=e},this.getPhase=function(){return e},this.setPhase=function(t){e=t},this.callback=function(n,s,r){var a,o,h,u,c;for(e+=n/i;e>=1024;)e-=1024;return a=0|e,o=e-a,a=1023&a,h=1023===a?0:a+1,u=t[a],c=t[h],(u+o*(c-u))*s}},Gibberish.Wavetable.prototype=Gibberish._oscillator,Gibberish.Table=function(e){this.__proto__=new Gibberish.Wavetable,this.name="table";var t=2*Math.PI;if("undefined"==typeof e){e=new Float32Array(1024);for(var i=1024;i--;)e[i]=Math.sin(i/1024*t)}this.setTable(e),this.init(),this.oscillatorInit()},Gibberish.asmSine=function(e,t,i){"use asm";var n=e.Math.sin;var s=0.0;var r=new e.Float32Array(i);var a=e.Math.floor;var o=0.0;function h(){var e=1024;var t=1024.0;var i=0.0;for(;e=e-1|0;){t=t-1.0;r[e>>2]=+n(+(t/1024.0)*6.2848)}o=44100.0/1024.0}function u(e,t,i){e=+e;t=+t;i=+i;var n=0.0,h=0,u=0,c=0.0,l=0.0,b=0.0;s=+(s+e/o);if(s>=1024.0)s=+(s-1024.0);n=+a(s);c=s-n;h=~~n;if((h|0)==(1024|0)){u=0}else{u=h+1|0}l=+r[h>>2];b=+r[u>>2];return+((l+c*(b-l))*t)}function c(e){e=e|0;return+r[e>>2]}return{init:h,gen:u,get:c}},Gibberish.asmSine2=function(){this.properties={frequency:440,amp:.5,sr:Gibberish.context.sampleRate},this.name="sine";var e=new ArrayBuffer(4096),t=Gibberish.asmSine(window,null,e);return t.init(),this.getTable=function(){return e},this.get=t.get,this.callback=t.gen,this.init(),this.oscillatorInit(),this.processProperties(arguments),this},Gibberish.asmSine2.prototype=Gibberish._oscillator,Gibberish.Sine=function(){this.__proto__=new Gibberish.Wavetable,this.name="sine";for(var e=2*Math.PI,t=new Float32Array(1024),i=1024;i--;)t[i]=Math.sin(i/1024*e);this.setTable(t),this.init(arguments),this.oscillatorInit(),this.processProperties(arguments)},Gibberish.Sine2=function(){this.__proto__=new Gibberish.Sine,this.name="sine2";var e=this.__proto__.callback,t=Gibberish.makePanner(),i=[0,0];this.callback=function(n,s,r){var a=e(n,s);return i=t(a,r,i)},this.init(),this.oscillatorInit(),Gibberish.defineUgenProperty("pan",0,this),this.processProperties(arguments)},Gibberish.Square=function(){this.__proto__=new Gibberish.Wavetable,this.name="square";for(var e=(2*Math.PI,new Float32Array(1024)),t=1024;t--;)e[t]=t/1024>.5?1:-1;this.setTable(e),this.init(arguments),this.oscillatorInit(),this.processProperties(arguments)},Gibberish.Saw=function(){this.__proto__=new Gibberish.Wavetable,this.name="saw";for(var e=new Float32Array(1024),t=1024;t--;)e[t]=4*((t/1024/2+.25)%.5-.25);this.setTable(e),this.init(arguments),this.oscillatorInit(),this.processProperties(arguments)},Gibberish.Saw2=function(){this.__proto__=new Gibberish.Saw,this.name="saw2";var e=this.__proto__.callback,t=Gibberish.makePanner(),i=[0,0];this.callback=function(n,s,r){var a=e(n,s);return i=t(a,r,i)},this.init(),Gibberish.defineUgenProperty("pan",0,this)},Gibberish.Triangle=function(){this.__proto__=new Gibberish.Wavetable,this.name="triangle";for(var e=new Float32Array(1024),t=Math.abs,i=1024;i--;)e[i]=1-4*t((i/1024+.25)%1-.5);this.setTable(e),this.init(arguments),this.oscillatorInit(),this.processProperties(arguments)},Gibberish.Triangle2=function(){this.__proto__=new Gibberish.Triangle,this.name="triangle2";var e=this.__proto__.callback,t=Gibberish.makePanner(),i=[0,0];this.callback=function(n,s,r){var a=e(n,s);return t(a,r,i)},this.init(),this.oscillatorInit(),Gibberish.defineUgenProperty("pan",0,this),this.processProperties(arguments)},Gibberish.Saw3=function(){var e=0,t=0,i=2.5,n=-1.5,s=0,r=Math.sin,a=11;pi_2=2*Math.PI,flip=0,signHistory=0,ignore=!1,sr=Gibberish.context.sampleRate,Gibberish.extend(this,{name:"saw",properties:{frequency:440,amp:.15,sync:0,sr:Gibberish.context.sampleRate},callback:function(o,h,u){var c=o/sr,l=.5-c,b=a*l*l*l*l,f=.376-.752*c,p=1-2*c,d=0;return t+=c,t-=t>1?2:0,e=.5*(e+r(pi_2*(t+e*b))),d=i*e+n*s,s=e,d+=f,d*=p,d*h}}),Object.defineProperty(this,"scale",{get:function(){return a},set:function(e){a=e}}),this.init(),this.oscillatorInit(),this.processProperties(arguments)},Gibberish.Saw3.prototype=Gibberish._oscillator,Gibberish.PWM=function(){var e=0,t=0,i=0,n=0,s=0,r=2.5,a=-1.5,o=Math.sin,h=11;pi_2=2*Math.PI,test=0,sr=Gibberish.context.sampleRate,Gibberish.extend(this,{name:"pwm",properties:{frequency:440,amp:.15,pulsewidth:.05,sr:Gibberish.context.sampleRate},callback:function(u,c,l){var b=u/sr,f=.5-b,p=h*f*f*f*f,d=1-2*b,g=0;return s+=b,s-=s>1?2:0,e=.5*(e+o(pi_2*(s+e*p))),t=.5*(t+o(pi_2*(s+t*p+l))),g=t-e,g=r*g+a*(i-n),i=e,n=t,g*d*c}}),Object.defineProperty(this,"scale",{get:function(){return h},set:function(e){h=e}}),this.init(),this.oscillatorInit(),this.processProperties(arguments)},Gibberish.PWM.prototype=Gibberish._oscillator,Gibberish.Noise=function(){var e=Math.random;Gibberish.extend(this,{name:"noise",properties:{amp:1},callback:function(t){return(2*e()-1)*t}}),this.init(),this.oscillatorInit(),this.processProperties(arguments)},Gibberish.Noise.prototype=Gibberish._oscillator,Gibberish.KarplusStrong=function(){var e=[0],t=0,i=Math.random,n=Gibberish.makePanner(),s=Gibberish.context.sampleRate,r=[0,0];Gibberish.extend(this,{name:"karplus_strong",frequency:0,properties:{blend:1,damping:0,amp:1,channels:2,pan:0,velocity:1},note:function(t,n){if("undefined"!=typeof t){var r=Math.floor(s/t);e.length=0;for(var a=0;r>a;a++)e[a]=2*i()-1;n&&(this.velocity=n),this.frequency=t}},callback:function(s,a,o,h,u,c){var l=e.shift(),b=i()>s?-1:1;a=a>0?a:0;var f=b*(l+t)*(.5-a/100);return t=f,e.push(f),f*=o*c,1===h?f:n(f,u,r)}}).init().oscillatorInit().processProperties(arguments)},Gibberish.KarplusStrong.prototype=Gibberish._oscillator,Gibberish.PolyKarplusStrong=function(){this.__proto__=new Gibberish.Bus2,Gibberish.extend(this,{name:"poly_karplus_strong",maxVoices:5,voiceCount:0,_frequency:0,polyProperties:{blend:1,damping:0,velocity:1},note:function(e,t){var i=this.children[this.voiceCount++];this.voiceCount>=this.maxVoices&&(this.voiceCount=0),i.note(e,t),this._frequency=e},initVoices:function(){for(var e=0;e<this.maxVoices;e++){var t={blend:this.blend,damping:this.damping,channels:2,amp:1},i=new Gibberish.KarplusStrong(t).connect(this);this.children.push(i)}}}),this.amp=1/this.maxVoices,this.children=[],"object"==typeof arguments[0]&&(this.maxVoices=arguments[0].maxVoices?arguments[0].maxVoices:this.maxVoices),Gibberish.polyInit(this),this.initVoices(),this.processProperties(arguments),this.initialized=!1,Gibberish._synth.oscillatorInit.call(this),Gibberish.dirty(this)},Gibberish.bus=function(){this.type="bus",this.inputCodegen=function(){var e,t=this.value.valueOf();return e=t+", "+this.amp,this.codeblock=e,e},this.addConnection=function(){var e=arguments[2],t={value:arguments[0],amp:arguments[1],codegen:this.inputCodegen,valueOf:function(){return this.codegen()}};"undefined"!=typeof e?this.inputs.splice(e,0,t):this.inputs.push(t),Gibberish.dirty(this)},this.removeConnection=function(e){for(var t=0;t<this.inputs.length;t++)if(this.inputs[t].value===e){this.inputs.splice(t,1),Gibberish.dirty(this);break}},this.adjustSendAmount=function(e,t){for(var i=0;i<this.inputs.length;i++)if(this.inputs[i].value===e){this.inputs[i].amp=t,Gibberish.dirty(this);break}},this.callback=function(){var e=arguments[arguments.length-2],t=arguments[arguments.length-1];output[0]=output[1]=0;for(var i=0;i<arguments.length-2;i+=2){var n="object"==typeof arguments[i],s=arguments[i+1];output[0]+=n?arguments[i][0]*s:arguments[i]*s,output[1]+=n?arguments[i][1]*s:arguments[i]*s}return output[0]*=e,output[1]*=e,panner(output,t,output)}},Gibberish.bus.prototype=new Gibberish.ugen,Gibberish._bus=new Gibberish.bus,Gibberish.Bus=function(){return Gibberish.extend(this,{name:"bus",properties:{inputs:[],amp:1},callback:function(){for(var e=0,t=arguments.length-1,i=arguments[t],n=0;t>n;n++)e+=arguments[n];return e*=i}}),this.init(),this.processProperties(arguments),this},Gibberish.Bus.prototype=Gibberish._bus,Gibberish.Bus2=function(){this.name="bus2",this.type="bus",this.properties={inputs:[],amp:1,pan:0};var e=[0,0],t=Gibberish.makePanner();this.callback=function(){var i=arguments,n=i.length,s=i[n-2],r=i[n-1];e[0]=e[1]=0;for(var a=0,o=n-2;o>a;a+=2){var h="object"==typeof i[a],u=i[a+1];e[0]+=h?i[a][0]*u||0:i[a]*u||0,e[1]+=h?i[a][1]*u||0:i[a]*u||0}return e[0]*=s,e[1]*=s,t(e,r,e)},this.show=function(){console.log(e,args)},this.getOutput=function(){return e},this.getArgs=function(){return args},this.init(arguments),this.processProperties(arguments)},Gibberish.Bus2.prototype=Gibberish._bus,Gibberish.envelope=function(){this.type="envelope"},Gibberish.envelope.prototype=new Gibberish.ugen,Gibberish._envelope=new Gibberish.envelope,Gibberish.ExponentialDecay=function(){var e=Math.pow,t=0,i=0;Gibberish.extend(this,{name:"ExponentialDecay",properties:{decay:.5,length:11050},callback:function(n,s){return t=e(n,i),i+=1/s,t},trigger:function(){i="number"==typeof arguments[0]?arguments[0]:0}}).init()},Gibberish.ExponentialDecay.prototype=Gibberish._envelope,Gibberish.Line=function(e,t,i,n){var s,r={name:"line",properties:{start:e||0,end:isNaN(t)?1:t,time:i||Gibberish.context.sampleRate,loops:n||!1},retrigger:function(e,t){a=0,this.start=s,this.end=e,this.time=t,o=(e-s)/t},getPhase:function(){return a},getIncr:function(){return o},getOut:function(){return s}},a=0,o=(t-e)/i;return this.callback=function(e,t,i,n){var r=(t-e)/i;return s=i>a?e+a++*r:t,a=s>=t&&n?0:a,s},this.setPhase=function(e){a=e},Gibberish.extend(this,r),this.init(),this},Gibberish.Line.prototype=Gibberish._envelope,Gibberish.Ease=function(e,t,i,n,s){var r=Math.sqrt,a=0,o=0;e=e||0,t=t||1,i=i||Gibberish.context.sampleRate,s=s||!1,n="undefined"==typeof n?1:n;var h={name:"ease",properties:{},retrigger:function(e,t){o=0,this.start=a,this.end=e,this.time=t},getPhase:function(){return o},getOut:function(){return a}};return this.callback=function(){var h=o++/i,u=n?1-r(1-h*h):r(1-(1-h)*(1-h));return a=i>o?e+u*(t-e):t,o=a>=t&&s?0:o,a},this.setPhase=function(e){o=e},this.setEase=function(e){n=e},Gibberish.extend(this,h),this.init(),this},Gibberish.Ease.prototype=Gibberish._envelope,Gibberish.Curve=function(e,t,i,n,s,r,a){var o=Math.sqrt,h=0,u=0;e=e||0,t=t||1,i=i||Gibberish.context.sampleRate,n=n||.94,s=s||.26,a=a||!1,r="undefined"==typeof r?1:r;var c={name:"curve",properties:{},retrigger:function(e,t){u=0,this.start=h,this.end=e,this.time=t,incr=(e-h)/t},getPhase:function(){return u},getOut:function(){return h}};return this.callback=function(){var c=u++/i,l=1-2*n,b=(o(n*n+l*c)-n)/l,f=(1-2*s)*(b*b)+2*s*b;return h=i>u?e+f*(t-e):t,r||(h=1-h),u=h>=t&&a?0:u,h},this.setPhase=function(e){u=e},Gibberish.extend(this,c),this.init(),this},Gibberish.Curve.prototype=Gibberish._envelope,Gibberish.Lines=function(e,t,i){var n,s=e[0],r=0,a=1,o=0,h=0,u=0,c=!1;"undefined"==typeof e&&(e=[0,1]),"undefined"==typeof t&&(t=[44100]),h=e[a],u=t[0],n=(h-e[0])/u,i=i||!1;var l={name:"lines",properties:{},retrigger:function(){r=0,s=e[0],u=t[0],h=e[1],a=1,o=0,n=(h-s)/u,c=!1},getPhase:function(){return r},getOut:function(){return s}};return l.run=l.retrigger,this.callback=function(){if(r>=u&&!c)if(a<e.length-1){var l=t[++o%t.length];u=r+l,h=e[++a%e.length],n=(h-s)/l}else i?(r=0,s=e[0],u=t[0],h=e[1],a=1,o=0,n=(h-s)/u):(c=!0,s=e[e.length-1]);else c||(s+=n,r++);return s},this.setPhase=function(e){r=e},Gibberish.extend(this,l),this.init(),this},Gibberish.Lines.prototype=Gibberish._envelope,Gibberish.AD=function(e,t){var i=0,n=0;Gibberish.extend(this,{name:"AD",properties:{attack:e||1e4,decay:t||1e4},run:function(){return n=0,i=0,this},callback:function(e,t){if(e=0>e?22050:e,t=0>t?22050:t,0===n){var s=1/e;i+=s,i>=1&&n++}else if(1===n){var s=1/t;i-=s,0>=i&&(i=0,n++)}return i},getState:function(){return n}}).init().processProperties(arguments)},Gibberish.AD.prototype=Gibberish._envelope,Gibberish.ADSR=function(e,t,i,n,s,r,a){var o={name:"adsr",type:"envelope",requireReleaseTrigger:"undefined"!=typeof a?a:!1,properties:{attack:isNaN(e)?1e4:e,decay:isNaN(t)?1e4:t,sustain:isNaN(i)?22050:i,release:isNaN(n)?1e4:n,attackLevel:s||1,sustainLevel:r||.5,releaseTrigger:0},run:function(){this.setPhase(0),this.setState(0)},stop:function(){this.releaseTrigger=1}};Gibberish.extend(this,o);var h=0,u=0,c=0,l=this;return this.callback=function(e,t,i,n,s,r,a){var o=0;return c=1===c?1:a,0===u?(o=h/e*s,++h/e>=1&&(u++,h=t)):1===u?(o=h/t*(s-r)+r,--h<=0&&(null!==i?(u+=1,h=i):(u+=2,h=n))):2===u?(o=r,l.requireReleaseTrigger&&c?(u++,h=n,l.releaseTrigger=0,c=0):h--<=0&&!l.requireReleaseTrigger&&(u++,h=n)):3===u&&(h--,o=h/n*r,0>=h&&u++),o},this.call=function(){return this.callback(this.attack,this.decay,this.sustain,this.release,this.attackLevel,this.sustainLevel,this.releaseTrigger)},this.getPhase=function(){return h},this.setPhase=function(e){h=e},this.setState=function(e){u=e,h=0},this.getState=function(){return u},this.init(),this},Gibberish.ADSR.prototype=Gibberish._envelope,Gibberish.ADR=function(e,t,i,n,s){var r={name:"adr",type:"envelope",properties:{attack:isNaN(e)?11025:e,decay:isNaN(t)?11025:t,release:isNaN(i)?22050:i,attackLevel:n||1,releaseLevel:s||.2},run:function(){this.setPhase(0),this.setState(0)}};Gibberish.extend(this,r);var a=0,o=0;return this.callback=function(e,t,i,n,s){var r=0;return 0===o?(r=a/e*n,++a/e===1&&(o++,a=t)):1===o?(r=a/t*(n-s)+s,--a<=0&&(o+=1,a=i)):2===o&&(a--,r=a/i*s,0>=a&&o++),r},this.setPhase=function(e){a=e},this.setState=function(e){o=e,a=0},this.getState=function(){return o},this.init(),this},Gibberish.ADR.prototype=Gibberish._envelope,Gibberish.analysis=function(){this.type="analysis",this.codegen=function(){if(Gibberish.memo[this.symbol])return Gibberish.memo[this.symbol];var e=this.variable?this.variable:Gibberish.generateSymbol("v");return Gibberish.memo[this.symbol]=e,this.variable=e,Gibberish.callbackArgs.push(this.symbol),Gibberish.callbackObjects.push(this.callback),this.codeblock="var "+this.variable+" = "+this.symbol+"();\n",-1===Gibberish.codeblock.indexOf(this.codeblock)&&Gibberish.codeblock.push(this.codeblock),this.variable},this.analysisCodegen=function(){var e=0;this.input.codegen?(e=this.input.codegen(),e.indexOf("op")>-1&&console.log("ANALYSIS BUG")):e=this.input.value?"undefined"!=typeof this.input.value.codegen?this.input.value.codegen():this.input.value:"null";var t=this.analysisSymbol+"("+e+",";for(var i in this.properties)"input"!==i&&(t+=this[i]+",");return t=t.slice(0,-1),t+=");",this.analysisCodeblock=t,-1===Gibberish.analysisCodeblock.indexOf(this.analysisCodeblock)&&Gibberish.analysisCodeblock.push(this.analysisCodeblock),-1===Gibberish.callbackObjects.indexOf(this.analysisCallback)&&Gibberish.callbackObjects.push(this.analysisCallback),t},this.remove=function(){Gibberish.analysisUgens.splice(Gibberish.analysisUgens.indexOf(this),1)},this.analysisInit=function(){this.analysisSymbol=Gibberish.generateSymbol(this.name),Gibberish.analysisUgens.push(this),Gibberish.dirty()}},Gibberish.analysis.prototype=new Gibberish.ugen,Gibberish._analysis=new Gibberish.analysis,Gibberish.Follow=function(){this.name="follow",this.properties={input:0,bufferSize:4410,mult:1,useAbsoluteValue:!0},this.storage=[];var e=Math.abs,t=[0],i=0,n=0,s=0;this.analysisCallback=function(r,a,o,h){"object"==typeof r&&(r=r[0]+r[1]),i+=h?e(r):r,i-=t[n],t[n]=h?e(r):r,n=(n+1)%a,t[n]=t[n]?t[n]:0,s=i/a*o},this.callback=this.getValue=function(){return s},this.init(),this.analysisInit(),this.processProperties(arguments);var r=(this.__lookupSetter__("bufferSize"),this.bufferSize);Object.defineProperty(this,"bufferSize",{get:function(){return r},set:function(e){r=e,i=0,t=[0],n=0}}),this.getStorage=function(){return this.storage;
}},Gibberish.Follow.prototype=Gibberish._analysis,Gibberish.SingleSampleDelay=function(){this.name="single_sample_delay",this.properties={input:arguments[0]||0,amp:arguments[1]||1};var e=0;this.analysisCallback=function(t,i){e=t},this.callback=function(){return e},this.getValue=function(){return e},this.init(),this.analysisInit(),this.processProperties(arguments)},Gibberish.SingleSampleDelay.prototype=Gibberish._analysis,Gibberish.Record=function(e,t,i){var n=new Float32Array(t),s=0,r=!1,a=this;Gibberish.extend(this,{name:"record",oncomplete:i,properties:{input:0,size:t||0},analysisCallback:function(e,t){r&&(n[s++]="object"==typeof e?e[0]+e[1]:e,s>=t&&(r=!1,a.remove()))},record:function(){return s=0,r=!0,this},getBuffer:function(){return n},getPhase:function(){return s},remove:function(){"undefined"!=typeof this.oncomplete&&this.oncomplete();for(var e=0;e<Gibberish.analysisUgens.length;e++){var t=Gibberish.analysisUgens[e];if(t===this)return Gibberish.callbackArgs.indexOf(this.analysisSymbol)>-1&&Gibberish.callbackArgs.splice(Gibberish.callbackArgs.indexOf(this.analysisSymbol),1),Gibberish.callbackObjects.indexOf(this.analysisCallback)>-1&&Gibberish.callbackObjects.splice(Gibberish.callbackObjects.indexOf(this.analysisCallback),1),void Gibberish.analysisUgens.splice(e,1)}}}),this.properties.input=e,this.init(),this.analysisInit(),Gibberish.dirty()},Gibberish.Record.prototype=Gibberish._analysis,Gibberish.effect=function(){this.type="effect"},Gibberish.effect.prototype=new Gibberish.ugen,Gibberish._effect=new Gibberish.effect,Gibberish.Distortion=function(){var e=Math.abs,t=Math.log,i=Math.LN2;Gibberish.extend(this,{name:"distortion",properties:{input:0,amount:50},callback:function(n,s){var r;return s=s>2?s:2,"number"==typeof n?(r=n*s,n=r/(1+e(r))/(t(s)/i)):(r=n[0]*s,n[0]=r/(1+e(r))/(t(s)/i),r=n[1]*s,n[1]=r/(1+e(r))/(t(s)/i)),n}}).init().processProperties(arguments)},Gibberish.Distortion.prototype=Gibberish._effect,Gibberish.Gain=function(){Gibberish.extend(this,{name:"gain",properties:{input:0,amount:1},callback:function(e,t){return"number"==typeof e?e*=t:(e[0]*=t,e[1]*=t),e}}).init().processProperties(arguments)},Gibberish.Gain.prototype=Gibberish._effect,Gibberish.Delay=function(){var e=[],t=0;e.push(new Float32Array(2*Gibberish.context.sampleRate)),e.push(new Float32Array(2*Gibberish.context.sampleRate)),Gibberish.extend(this,{name:"delay",properties:{input:0,time:22050,feedback:.5,wet:1,dry:1,rate:1},callback:function(i,n,s,r,a,o){var h="number"==typeof i?1:2,u=t++%88200;n/=o;var c=(u+(0|n))%88200;return 1===h?(e[0][c]=i+e[0][u]*s,i=i*a+e[0][u]*r):(e[0][c]=i[0]+e[0][u]*s,i[0]=i[0]*a+e[0][u]*r,e[1][c]=i[1]+e[1][u]*s,i[1]=i[1]*a+e[1][u]*r),i}});var i=Math.round(this.properties.time);Object.defineProperty(this,"time",{configurable:!0,get:function(){return i},set:function(e){i=Math.round(e),Gibberish.dirty(this)}}),this.init(),this.processProperties(arguments)},Gibberish.Delay.prototype=Gibberish._effect,Gibberish.Decimator=function(){var e=0,t=[],i=Math.pow,n=Math.floor;Gibberish.extend(this,{name:"decimator",properties:{input:0,bitDepth:16,sampleRate:1},callback:function(s,r,a){e+=a;var o="number"==typeof s?1:2;if(1===o){if(e>=1){var h=i(r,2);t[0]=n(s*h)/h,e-=1}s=t[0]}else{if(e>=1){var h=i(r,2);t[0]=n(s[0]*h)/h,t[1]=n(s[1]*h)/h,e-=1}s=t}return s}}).init().processProperties(arguments)},Gibberish.Decimator.prototype=Gibberish._effect,Gibberish.RingModulation=function(){var e=(new Gibberish.Sine).callback,t=[0,0];Gibberish.extend(this,{name:"ringmod",properties:{input:0,frequency:440,amp:.5,mix:.5},callback:function(i,n,s,r){var a="number"==typeof i?1:2,o=1===a?i:i[0],h=e(n,s);if(o=o*(1-r)+o*h*r,2===a){var u=i[1];return u=u*(1-r)+u*h*r,t[0]=o,t[1]=u,t}return o}}).init().processProperties(arguments)},Gibberish.RingModulation.prototype=Gibberish._effect,Gibberish.DCBlock=function(){var e=0,t=0;Gibberish.extend(this,{name:"dcblock",type:"effect",properties:{input:0},reset:function(){e=0,t=0},callback:function(i){var n=i-e+.9997*t;return e=i,t=n,n}}).init().processProperties(arguments)},Gibberish.DCBlock.prototype=Gibberish._effect,Gibberish.Tremolo=function(){var e=(new Gibberish.Sine).callback;Gibberish.extend(this,{name:"tremolo",type:"effect",properties:{input:0,frequency:2.5,amp:.5},callback:function(t,i,n){var s="number"==typeof t?1:2,r=e(i,n);return 1===s?t*=r:(t[0]*=r,t[1]*=r),t}}).init().processProperties(arguments)},Gibberish.Tremolo.prototype=Gibberish._effect,Gibberish.OnePole=function(){var e=0;Gibberish.extend(this,{name:"onepole",type:"effect",properties:{input:0,a0:.15,b1:.85},callback:function(t,i,n){var s=t*i+e*n;return e=s,s},smooth:function(t,i){this.input=i[t],e=this.input,i[t]=this,this.obj=i,this.property=t,this.oldSetter=i.__lookupSetter__(t),this.oldGetter=i.__lookupGetter__(t);var n=this;Object.defineProperty(i,t,{get:function(){return n.input},set:function(e){n.input=e}})},remove:function(){Object.defineProperty(this.obj,this.property,{get:this.oldGetter,set:this.oldSetter}),this.obj[this.property]=this.input}}).init().processProperties(arguments)},Gibberish.OnePole.prototype=Gibberish._effect,Gibberish.Filter24=function(){var e=[0,0,0,0],t=[0,0,0,0],i=[0,0],n=isNaN(arguments[0])?.1:arguments[0],s=isNaN(arguments[1])?3:arguments[1];_isLowPass="undefined"!=typeof arguments[2]?arguments[2]:!0,Gibberish.extend(this,{name:"filter24",properties:{input:0,cutoff:n,resonance:s,isLowPass:_isLowPass},callback:function(n,s,r,a){var o="number"==typeof n?1:2,h=1===o?n:n[0],u=e[3]*r;if(u=u>1?1:u,s=0>s?0:s,s=s>1?1:s,h-=u,e[0]=e[0]+(-e[0]+h)*s,e[1]=e[1]+(-e[1]+e[0])*s,e[2]=e[2]+(-e[2]+e[1])*s,e[3]=e[3]+(-e[3]+e[2])*s,h=a?e[3]:h-e[3],2===o){var c=n[1];return u=t[3]*r,u=u>1?1:u,c-=u,t[0]=t[0]+(-t[0]+c)*s,t[1]=t[1]+(-t[1]+t[0])*s,t[2]=t[2]+(-t[2]+t[1])*s,t[3]=t[3]+(-t[3]+t[2])*s,c=a?t[3]:c-t[3],i[0]=h,i[1]=c,i}return h}}).init().processProperties(arguments)},Gibberish.Filter24.prototype=Gibberish._effect,Gibberish.SVF=function(){var e=[0,0],t=[0,0],i=Math.PI,n=[0,0];Gibberish.extend(this,{name:"SVF",properties:{input:0,cutoff:440,Q:2,mode:0,sr:Gibberish.context.sampleRate},callback:function(s,r,a,o,h){var u="number"==typeof s?1:2,c=1===u?s:s[0],l=2*i*r/h;a=1/a;var b=t[0]+l*e[0],f=c-b-a*e[0],p=l*f+e[0],d=f+b;if(e[0]=p,t[0]=b,c=0===o?b:1===o?f:2===o?p:d,2===u){var g=s[1],b=t[1]+l*e[1],f=g-b-a*e[1],p=l*f+e[1],d=f+b;e[1]=p,t[1]=b,g=0===o?b:1===o?f:2===o?p:d,n[0]=c,n[1]=g}else n=c;return n}}).init().processProperties(arguments)},Gibberish.SVF.prototype=Gibberish._effect,Gibberish.Biquad=function(){var e=0,t=0,i=0,n=0,s=0,r=0,a=0,o=0,h=[0,0],u=.001639,c=.003278,l=.001639,b=-1.955777,f=.960601,p="LP",d=2e3,g=.5,m=Gibberish.context.sampleRate;Gibberish.extend(this,{name:"biquad",properties:{input:null},calculateCoefficients:function(){switch(p){case"LP":var e=2*Math.PI*d/m,t=Math.sin(e),i=Math.cos(e),n=t/(2*g);u=(1-i)/2,c=1-i,l=u,a0=1+n,b=-2*i,f=1-n;break;case"HP":var e=2*Math.PI*d/m,t=Math.sin(e),i=Math.cos(e),n=t/(2*g);u=(1+i)/2,c=-(1+i),l=u,a0=1+n,b=-2*i,f=1-n;break;case"BP":var e=2*Math.PI*d/m,t=Math.sin(e),i=Math.cos(e),s=Math.log(2)/2*g*e/t,n=t*(Math.exp(s)-Math.exp(-s))/2;u=n,c=0,l=-n,a0=1+n,b=-2*i,f=1-n;break;default:return}u/=a0,c/=a0,l/=a0,b/=a0,f/=a0},callback:function(p){var d=isNaN(p)?2:1,g=0,m=0,y=1===d?p:p[0];return g=u*y+c*e+l*t-b*i-f*n,t=e,e=y,n=i,i=g,2===d&&(inR=p[1],m=u*inR+c*s+l*r-b*a-f*o,r=s,s=inR,o=a,a=m,h[0]=g,h[1]=m),1===d?g:h}}).init(),Object.defineProperties(this,{mode:{get:function(){return p},set:function(e){p=e,this.calculateCoefficients()}},cutoff:{get:function(){return d},set:function(e){d=e,this.calculateCoefficients()}},Q:{get:function(){return g},set:function(e){g=e,this.calculateCoefficients()}}}),this.processProperties(arguments),this.calculateCoefficients()},Gibberish.Biquad.prototype=Gibberish._effect,Gibberish.Flanger=function(){var e=[new Float32Array(88200),new Float32Array(88200)],t=88200,i=(new Gibberish.Sine).callback,n=Gibberish.interpolate,s=-100,r=0;Gibberish.extend(this,{name:"flanger",properties:{input:0,rate:.25,feedback:0,amount:125,offset:125},callback:function(a,o,h,u,c){var l="number"==typeof a?1:2,b=s+i(o,.95*u);b>t?b-=t:0>b&&(b+=t);var f=n(e[0],b);return e[0][r]=1===l?a+f*h:a[0]+f*h,2===l?(a[0]+=f,f=n(e[1],b),e[1][r]=a[1]+f*h,a[1]+=f):a+=f,++r>=t&&(r=0),++s>=t&&(s=0),a}}).init().processProperties(arguments),s=-1*this.offset},Gibberish.Flanger.prototype=Gibberish._effect,Gibberish.Vibrato=function(){var e=[new Float32Array(88200),new Float32Array(88200)],t=88200,i=(new Gibberish.Sine).callback,n=Gibberish.interpolate,s=-100,r=0;Gibberish.extend(this,{name:"vibrato",properties:{input:0,rate:5,amount:.5,offset:125},callback:function(a,o,h,u){var c="number"==typeof a?1:2,l=s+i(o,h*u-1);l>t?l-=t:0>l&&(l+=t);var b=n(e[0],l);return e[0][r]=1===c?a:a[0],2===c?(a[0]=b,b=n(e[1],l),e[1][r]=a[1],a[1]=b):a=b,++r>=t&&(r=0),++s>=t&&(s=0),a}}).init().processProperties(arguments),s=-1*this.offset},Gibberish.Vibrato.prototype=Gibberish._effect,Gibberish.BufferShuffler=function(){var e=[new Float32Array(88200),new Float32Array(88200)],t=88200,i=0,n=0,s=0,r=0,a=0,o=Math.random,h=1,u=!1,c=!1,l=!1,b=Gibberish.interpolate,f=!1,p=1,d=!1,g=Gibberish.rndf,m=[0,0];Gibberish.extend(this,{name:"buffer_shuffler",properties:{input:0,chance:.25,rate:11025,length:22050,reverseChange:.5,pitchChance:.5,pitchMin:.25,pitchMax:2,wet:1,dry:0},callback:function(y,v,G,k,x,w,_,P,S,A){var R="number"==typeof y?1:2;a?++r%(k-400)===0&&(u=!1,c=!0,h=1,r=0):(e[0][n]=1===R?y:y[0],e[1][n]=1===R?y:y[1],n++,n%=t,d=0===n?1:d,s++,s%G==0&&o()<v&&(l=o()<x,a=!0,l||(i=n-k,0>i&&(i=t+i)),f=o()<w,f&&(p=g(_,P)),h=1,u=!0,c=!1)),i+=l?-1*p:p,0>i?i+=t:i>=t&&(i-=t);var q,M,C,O,I=b(e[0],i);return u?(h-=.0025,C=I*(1-h),q=1===R?C+y*h:C+y[0]*h,2===R&&(O=b(e[1],i),C=O*(1-h),M=1===R?q:C+y[1]*h),.0025>=h&&(u=!1)):c?(h-=.0025,C=I*h,q=1===R?C+y*h:C+y[0]*(1-h),2===R&&(O=b(e[1],i),C=O*h,M=C+y[1]*(1-h)),.0025>=h&&(c=!1,a=!1,l=!1,p=1,f=0)):1===R?q=a&&d?I*S+y*A:y:(O=b(e[1],i),q=a&&d?I*S+y[0]*A:y[0],M=a&&d?O*S+y[1]*A:y[1]),m=[q,M],1===R?q:m}}).init().processProperties(arguments)},Gibberish.BufferShuffler.prototype=Gibberish._effect,Gibberish.AllPass=function(e,t){var i=-1,n=new Float32Array(e||500),s=n.length;Gibberish.extend(this,{name:"allpass",properties:{input:0},callback:function(e){i=++i%s;var t=n[i],r=-1*e+t;return n[i]=e+.5*t,r}})},Gibberish.Comb=function(e){var t=new Float32Array(e||1200),i=t.length,n=0,s=0;Gibberish.extend(this,{name:"comb",properties:{input:0,feedback:.84,damping:.2},callback:function(e,r,a){var o=++n%i,h=t[o];return s=h*(1-a)+s*a,t[o]=e+s*r,h}})},Gibberish.Reverb=function(){var e={combCount:8,combTuning:[1116,1188,1277,1356,1422,1491,1557,1617],allPassCount:4,allPassTuning:[556,441,341,225],allPassFeedback:.5,fixedGain:.015,scaleDamping:.4,scaleRoom:.28,offsetRoom:.7,stereoSpread:23},t=.84,i=[],n=[],s=[0,0];Gibberish.extend(this,{name:"reverb",roomSize:.5,properties:{input:0,wet:.5,dry:.55,roomSize:.84,damping:.5},callback:function(e,t,r,a,o){for(var h="object"==typeof e?2:1,u=1===h?e:e[0]+e[1],c=.015*u,l=c,b=0;8>b;b++){var f=i[b](c,.98*a,.4*o);l+=f}for(var b=0;4>b;b++)l=n[b](l);return s[0]=s[1]=u*r+l*t,s}}).init().processProperties(arguments),this.setFeedback=function(e){t=e};for(var r=0;8>r;r++)i.push(new Gibberish.Comb(e.combTuning[r]).callback);for(var r=0;4>r;r++)n.push(new Gibberish.AllPass(e.allPassTuning[r],e.allPassFeedback).callback)},Gibberish.Reverb.prototype=Gibberish._effect,Gibberish.StereoReverb=function(){var e={combCount:8,combTuning:[1116,1188,1277,1356,1422,1491,1557,1617],allPassCount:4,allPassTuning:[556,441,341,225],allPassFeedback:.5,fixedGain:.015,scaleDamping:.4,scaleRoom:.28,offsetRoom:.7,stereoSpread:23},t=.84,i=[],n=[],s=[],r=[],a=[0,0];Gibberish.extend(this,{name:"reverb",roomSize:.5,properties:{input:0,wet:.5,dry:.55,roomSize:.84,damping:.5},callback:function(e,t,o,h,u){for(var c="object"==typeof e?2:1,l=e[0],b=1===c?l:e[1],f=outL=.015*l,p=outR=.015*b,d=0;8>d;d++)outL+=i[d](f,.98*h,.4*u),outR+=n[d](p,.98*h,.4*u);for(var d=0;4>d;d++)outL=s[d](outL),outR=r[d](outR);return a[0]=l*o+outL*t,a[1]=b*o+outR*t,a}}).init().processProperties(arguments),this.setFeedback=function(e){t=e};for(var o=0;8>o;o++)i.push(new Gibberish.Comb(e.combTuning[o]).callback),n.push(new Gibberish.Comb(e.combTuning[o]).callback);for(var o=0;4>o;o++)s.push(new Gibberish.AllPass(e.allPassTuning[o],e.allPassFeedback).callback),r.push(new Gibberish.AllPass(e.allPassTuning[o],e.allPassFeedback).callback)},Gibberish.StereoReverb.prototype=Gibberish._effect,Gibberish.Granulator=function(e){var t=[];buffer=null,interpolate=Gibberish.interpolate,panner=Gibberish.makePanner(),bufferLength=0,debug=0,write=0,self=this,out=[0,0],_out=[0,0],rndf=Gibberish.rndf,numberOfGrains=e.numberOfGrains||20,console.log("NUMBER OF GRAINS",numberOfGrains),Gibberish.extend(this,{name:"granulator",bufferLength:88200,reverse:!0,spread:.5,properties:{speed:1,speedMin:-0,speedMax:0,grainSize:1e3,position:.5,positionMin:0,positionMax:0,amp:.2,fade:.1,pan:0,shouldWrite:!1},setBuffer:function(e){buffer=e,bufferLength=e.length},callback:function(e,i,n,s,r,a,o,h,u,c,l){for(var b=0;b<numberOfGrains;b++){var f=t[b];if(f._speed>0){f.pos>f.end&&(f.pos=(o+rndf(r,a))*buffer.length,f.start=f.pos,f.end=f.start+s,f._speed=e+rndf(i,n),f._speed=f._speed<.1?.1:f._speed,f._speed=f._speed<.1&&f._speed>0?.1:f._speed,f._speed=f._speed>-.1&&f._speed<0?-.1:f._speed,f.fadeAmount=f._speed*(u*s),f.pan=rndf(-1*self.spread,self.spread));for(var p=f.pos;p>buffer.length;)p-=buffer.length;for(;0>p;)p+=buffer.length;var d=interpolate(buffer,p);d*=f.pos<f.fadeAmount+f.start?(f.pos-f.start)/f.fadeAmount:1,d*=f.pos>f.end-f.fadeAmount?(f.end-f.pos)/f.fadeAmount:1}else{f.pos<f.end&&(f.pos=(o+rndf(r,a))*buffer.length,f.start=f.pos,f.end=f.start-s,f._speed=e+rndf(i,n),f._speed=f._speed<.1&&f._speed>0?.1:f._speed,f._speed=f._speed>-.1&&f._speed<0?-.1:f._speed,f.fadeAmount=f._speed*(u*s));for(var p=f.pos;p>buffer.length;)p-=buffer.length;for(;0>p;)p+=buffer.length;var d=interpolate(buffer,p);d*=f.pos>f.start-f.fadeAmount?(f.start-f.pos)/f.fadeAmount:1,d*=f.pos<f.end+f.fadeAmount?(f.end-f.pos)/f.fadeAmount:1}_out=panner(d*h,f.pan,_out),out[0]+=_out[0],out[1]+=_out[1],f.pos+=f._speed}return panner(out,c,out)}}).init().processProperties(arguments);for(var i=0;i<numberOfGrains;i++)t[i]={pos:self.position+Gibberish.rndf(self.positionMin,self.positionMax),_speed:self.speed+Gibberish.rndf(self.speedMin,self.speedMax)},t[i].start=t[i].pos,t[i].end=t[i].pos+self.grainSize,t[i].fadeAmount=t[i]._speed*(self.fade*self.grainSize),t[i].pan=Gibberish.rndf(-1*self.spread,self.spread),console.log("GRAIN",i,"POS",t[i].pos,"SPEED",t[i]._speed);this.grains=t,"undefined"!=typeof e.buffer&&(buffer=e.buffer,bufferLength=buffer.length)},Gibberish.Granulator.prototype=Gibberish._effect,Gibberish.synth=function(){this.type="oscillator",this.oscillatorInit=function(){this.fx=new Array2,this.fx.parent=this}},Gibberish.synth.prototype=new Gibberish.ugen,Gibberish._synth=new Gibberish.synth,Gibberish.Synth=function(e){this.name="synth",this.properties={frequency:0,pulsewidth:.5,attack:22050,decay:22050,sustain:22050,release:22050,attackLevel:1,sustainLevel:.5,releaseTrigger:0,glide:.15,amp:.25,channels:2,pan:0,velocity:1,sr:Gibberish.context.sampleRate},this.note=function(n,s){if("undefined"!=typeof n){if(Array.isArray(arguments[0])){var r=arguments[0][0];s=arguments[0][1],n=r}if(0!==s){if("object"!=typeof this.frequency){if(t&&n===c&&e.requireReleaseTrigger)return this.releaseTrigger=1,void(c=null);this.frequency=c=n,this.releaseTrigger=0,"object"==typeof n&&Gibberish.dirty(this)}else this.frequency[0]=c=n,this.releaseTrigger=0,Gibberish.dirty(this);"undefined"!=typeof s&&(this.velocity=s),i.run()}else this.releaseTrigger=1}},e=e||{};var t="undefined"==typeof e.useADSR?!1:e.useADSR,i=t?new Gibberish.ADSR:new Gibberish.AD,n=i.getState,s=i.callback,r=new Gibberish.PWM,a=r.callback,o=(new Gibberish.OnePole).callback,h=Gibberish.makePanner(),u=this,c=0,l=[0,0];i.requireReleaseTrigger=e.requireReleaseTrigger||!1,this.callback=function(e,i,r,c,b,f,p,d,g,m,y,v,G,k,x){m=m>=1?.99999:m,e=o(e,1-m,m);var w,_;return t?(w=s(r,c,b,f,p,d,g),g&&(u.releaseTrigger=0),n()<4?(_=a(e,1,i,x)*w*k*y,1===v?_:h(_,G,l)):(_=l[0]=l[1]=0,1===v?_:l)):n()<2?(w=s(r,c),_=a(e,1,i,x)*w*k*y,1===v?_:h(_,G,l)):(_=l[0]=l[1]=0,1===v?_:l)},this.getEnv=function(){return i},this.getOsc=function(){return r},this.setOsc=function(e){r=e,a=r.callback};var b="PWM";Object.defineProperty(this,"waveform",{get:function(){return b},set:function(e){this.setOsc(new Gibberish[e])}}),this.init(),this.oscillatorInit(),this.processProperties(arguments)},Gibberish.Synth.prototype=Gibberish._synth,Gibberish.PolySynth=function(){this.__proto__=new Gibberish.Bus2,Gibberish.extend(this,{name:"polysynth",maxVoices:5,voiceCount:0,frequencies:[],_frequency:0,polyProperties:{frequency:0,glide:0,attack:22050,decay:22050,sustain:22050,release:22050,attackLevel:1,sustainLevel:.5,pulsewidth:.5,velocity:1,waveform:"PWM"},note:function(e,t){if("undefined"!=typeof e){var i=this.frequencies.indexOf(e),n=i>-1?i:this.voiceCount++,s=this.children[n];s.note(e,t),-1===i?(this.frequencies[n]=e,this._frequency=e,this.voiceCount>=this.maxVoices&&(this.voiceCount=0)):delete this.frequencies[n],this.lastChild=n}},initVoices:function(){for(var e=0;e<this.maxVoices;e++){var t={waveform:this.waveform,attack:this.attack,decay:this.decay,sustain:this.sustain,release:this.release,attackLevel:this.attackLevel,sustainLevel:this.sustainLevel,pulsewidth:this.pulsewidth,channels:2,amp:1,useADSR:this.useADSR||!1,requireReleaseTrigger:this.requireReleaseTrigger||!1},i=new Gibberish.Synth(t).connect(this);this.children.push(i)}}}),this.amp=1/this.maxVoices,this.children=[],"object"==typeof arguments[0]&&(this.maxVoices=arguments[0].maxVoices?arguments[0].maxVoices:this.maxVoices,this.useADSR="undefined"!=typeof arguments[0].useADSR?arguments[0].useADSR:!1,this.requireReleaseTrigger="undefined"!=typeof arguments[0].requireReleaseTrigger?arguments[0].requireReleaseTrigger:!1),Gibberish.polyInit(this),this.initVoices(),this.processProperties(arguments),Gibberish._synth.oscillatorInit.call(this)},Gibberish.Synth2=function(e){this.name="synth2",this.properties={frequency:0,pulsewidth:.5,attack:22050,decay:22050,sustain:22050,release:22050,attackLevel:1,sustainLevel:.5,releaseTrigger:0,cutoff:.25,resonance:3.5,useLowPassFilter:!0,glide:.15,amp:.25,channels:1,pan:0,velocity:1,sr:Gibberish.context.sampleRate},this.note=function(n,s){if("undefined"!=typeof n)if(0!==s){if("object"!=typeof this.frequency){if(t&&n===l&&e.requireReleaseTrigger)return this.releaseTrigger=1,void(l=null);this.frequency=l=n,this.releaseTrigger=0,"object"==typeof n&&Gibberish.dirty(this)}else this.frequency[0]=l=n,this.releaseTrigger=0,Gibberish.dirty(this);"undefined"!=typeof s&&(this.velocity=s),i.run()}else this.releaseTrigger=1},e=e||{};var t="undefined"==typeof e.useADSR?!1:e.useADSR,i=t?new Gibberish.ADSR:new Gibberish.AD,n=i.getState,s=i.callback,r=new Gibberish.PWM,a=r.callback,o=new Gibberish.Filter24,h=o.callback,u=(new Gibberish.OnePole).callback,c=Gibberish.makePanner(),l=0,b=this,f=[0,0];i.requireReleaseTrigger=e.requireReleaseTrigger||!1,this.callback=function(e,i,r,o,l,p,d,g,m,y,v,G,k,x,w,_,P,S){k=k>=1?.99999:k,e=u(e,1-k,k);var A,R;return t?(A=s(r,o,l,p,d,g,m),m&&(b.releaseTrigger=0),n()<4?(R=h(a(e,.15,i,S),y*A,v,G)*A*P*x,1===w?R:c(R,_,f)):(R=f[0]=f[1]=0,1===w?R:f)):n()<2?(A=s(r,o),R=h(a(e,.15,i,S),y*A,v,G)*A*P*x,1===w?R:c(R,_,f)):(R=f[0]=f[1]=0,1===w?R:f)},this.getUseADSR=function(){return t},this.getEnv=function(){return i},this.getOsc=function(){return r},this.setOsc=function(e){r=e,a=r.callback};var p="PWM";Object.defineProperty(this,"waveform",{get:function(){return p},set:function(e){this.setOsc(new Gibberish[e])}}),this.init(),this.oscillatorInit(),this.processProperties(arguments)},Gibberish.Synth2.prototype=Gibberish._synth,Gibberish.PolySynth2=function(){this.__proto__=new Gibberish.Bus2,Gibberish.extend(this,{name:"polysynth2",maxVoices:5,voiceCount:0,frequencies:[],_frequency:0,polyProperties:{frequency:0,glide:0,attack:22050,decay:22050,sustain:22050,release:22050,attackLevel:1,sustainLevel:.5,pulsewidth:.5,resonance:3.5,cutoff:.25,velocity:1,useLowPassFilter:!0,waveform:"PWM"},note:function(e,t){if("undefined"!=typeof e){var i=this.frequencies.indexOf(e),n=i>-1?i:this.voiceCount++,s=this.children[n];s.note(e,t),-1===i?(this.frequencies[n]=e,this._frequency=e,this.voiceCount>=this.maxVoices&&(this.voiceCount=0)):delete this.frequencies[n],this.lastChild=n}},initVoices:function(){this.dirty=!0;for(var e=0;e<this.maxVoices;e++){var t={attack:this.attack,decay:this.decay,sustain:this.sustain,release:this.release,attackLevel:this.attackLevel,sustainLevel:this.sustainLevel,pulsewidth:this.pulsewidth,channels:2,amp:1,useADSR:this.useADSR||!1,requireReleaseTrigger:this.requireReleaseTrigger||!1},i=new Gibberish.Synth2(t).connect(this);this.children.push(i)}}}),this.amp=1/this.maxVoices,this.children=[],"object"==typeof arguments[0]&&(this.maxVoices=arguments[0].maxVoices?arguments[0].maxVoices:this.maxVoices,this.useADSR="undefined"!=typeof arguments[0].useADSR?arguments[0].useADSR:!1,this.requireReleaseTrigger="undefined"!=typeof arguments[0].requireReleaseTrigger?arguments[0].requireReleaseTrigger:!1),Gibberish.polyInit(this),this.initVoices(),this.processProperties(arguments),Gibberish._synth.oscillatorInit.call(this)},Gibberish.FMSynth=function(e){this.name="fmSynth",this.properties={frequency:0,cmRatio:2,index:5,attack:22050,decay:22050,sustain:22050,release:22050,attackLevel:1,sustainLevel:.5,releaseTrigger:0,glide:.15,amp:.25,channels:2,velocity:1,pan:0},this.note=function(n,s){if("undefined"!=typeof n)if(console.log("VELOCITY",s),0!==s){if("object"!=typeof this.frequency){if(t&&n===l&&e.requireReleaseTrigger)return this.releaseTrigger=1,void(l=null);this.frequency=l=n,this.releaseTrigger=0,"object"==typeof n&&Gibberish.dirty(this)}else this.frequency[0]=l=n,this.releaseTrigger=0,Gibberish.dirty(this);"undefined"!=typeof s&&(this.velocity=s),i.run()}else this.releaseTrigger=1},e=e||{};var t="undefined"==typeof e.useADSR?!1:e.useADSR,i=t?new Gibberish.ADSR:new Gibberish.AD,n=i.getState,s=i.callback,r=(new Gibberish.Sine).callback,a=(new Gibberish.Sine).callback,o=(new Gibberish.OnePole).callback,h=Gibberish.makePanner(),u=[0,0],c=this,l=0;i.requireReleaseTrigger=e.requireReleaseTrigger||!1,this.callback=function(e,i,l,b,f,p,d,g,m,y,v,G,k,x,w){var _,P,S;return v>=1&&(v=.9999),e=o(e,1-v,v),t?(_=s(b,f,p,d,g,m,y)*x,y&&(c.releaseTrigger=0),n()<4?(S=a(e*i,e*l)*_,P=r(e+S,1)*_*G,1===k?P:h(P,w,u)):(P=u[0]=u[1]=0,1===k?P:u)):n()<2?(_=s(b,f)*x,S=a(e*i,e*l)*_,P=r(e+S,1)*_*G,1===k?P:h(P,w,u)):(P=u[0]=u[1]=0,1===k?P:u)},this.init(),this.oscillatorInit(),this.processProperties(arguments)},Gibberish.FMSynth.prototype=Gibberish._synth,Gibberish.PolyFM=function(){this.__proto__=new Gibberish.Bus2,Gibberish.extend(this,{name:"polyfm",maxVoices:5,voiceCount:0,children:[],frequencies:[],_frequency:0,velocity:1,polyProperties:{glide:0,attack:22050,decay:22050,sustain:22050,release:22050,attackLevel:1,sustainLevel:.5,index:5,cmRatio:2},note:function(e,t){if("undefined"!=typeof e){var i=this.frequencies.indexOf(e),n=i>-1?i:this.voiceCount++,s=this.children[n];"undefined"==typeof t&&(t=this.velocity),s.note(e,t),-1===i?(this.frequencies[n]=e,this._frequency=e,this.voiceCount>=this.maxVoices&&(this.voiceCount=0)):delete this.frequencies[n]}},initVoices:function(){for(var e=0;e<this.maxVoices;e++){var t={attack:this.attack,decay:this.decay,sustain:this.sustain,release:this.release,attackLevel:this.attackLevel,sustainLevel:this.sustainLevel,cmRatio:this.cmRatio,index:this.index,channels:2,useADSR:this.useADSR||!1,requireReleaseTrigger:this.requireReleaseTrigger||!1,amp:1},i=new Gibberish.FMSynth(t);i.connect(this),this.children.push(i)}}}),this.amp=1/this.maxVoices,this.children=[],"object"==typeof arguments[0]&&(this.maxVoices=arguments[0].maxVoices?arguments[0].maxVoices:this.maxVoices,this.useADSR="undefined"!=typeof arguments[0].useADSR?arguments[0].useADSR:!1,this.requireReleaseTrigger="undefined"!=typeof arguments[0].requireReleaseTrigger?arguments[0].requireReleaseTrigger:!1),Gibberish.polyInit(this),this.initVoices(),this.processProperties(arguments),Gibberish._synth.oscillatorInit.call(this)},Gibberish.Sampler=function(){var e=1,t=Gibberish.interpolate,i=Gibberish.makePanner(),n=[0,0],s=null,r=1,a=this;if(Gibberish.extend(this,{name:"sampler",file:null,isLoaded:!1,playOnLoad:0,buffers:{},properties:{pitch:1,amp:1,isRecording:!1,isPlaying:!0,input:0,length:0,start:0,end:1,loops:0,pan:0},_onload:function(t){s=t.channels[0],r=t.length,a.length=r,a.length=e=r,a.isPlaying=!0,Gibberish.audioFiles[a.file]=s,a.buffers[a.file]=s,a.onload&&a.onload(),0!==a.playOnLoad&&a.note(a.playOnLoad),a.isLoaded=!0},switchBuffer:function(e){if("string"==typeof e)"undefined"!=typeof this.buffers[e]&&(s=this.buffers[e],r=this.length=s.length);else if("number"==typeof e){var t=Object.keys(this.buffers);if(0===t.length)return;s=this.buffers[t[e]],r=this.length=s.length,this.setPhase(0)}},floatTo16BitPCM:function(e,t,i){for(var n=0;n<i.length-1;n++,t+=2){var s=Math.max(-1,Math.min(1,i[n]));e.setInt16(t,0>s?32768*s:32767*s,!0)}},encodeWAV:function(){function e(e,t,i){for(var n=0;n<i.length;n++)e.setUint8(t+n,i.charCodeAt(n))}var t=this.getBuffer(),i=new ArrayBuffer(44+2*t.length),n=new DataView(i),s=Gibberish.context.sampleRate;return e(n,0,"RIFF"),n.setUint32(4,32+2*t.length,!0),e(n,8,"WAVE"),e(n,12,"fmt "),n.setUint32(16,16,!0),n.setUint16(20,1,!0),n.setUint16(22,1,!0),n.setUint32(24,s,!0),n.setUint32(28,4*s,!0),n.setUint16(32,2,!0),n.setUint16(34,16,!0),e(n,36,"data"),n.setUint32(40,2*t.length,!0),this.floatTo16BitPCM(n,44,t),n},download:function(){var e=this.encodeWAV(),t=new Blob([e]),i=window.webkitURL.createObjectURL(t),n=window.document.createElement("a");n.href=i,n.download="output.wav";var s=document.createEvent("Event");s.initEvent("click",!0,!0),n.dispatchEvent(s)},range:function(e,t){if(Array.isArray(e)&&(t=e[1],e=e[0]),e>t){var i=e;e=t,t=i}this.start=e,this.end=t},note:function(t,i){if("undefined"!=typeof t){switch(typeof t){case"number":this.pitch=t;break;case"function":this.pitch=t();break;case"object":Array.isArray(t)?this.pitch=t[0]:this.pitch=t}if("number"==typeof i&&(this.amp=i),null!==this["function"]){this.isPlaying=!0;var n;switch(typeof this.pitch){case"number":n=this.pitch;break;case"function":n=this.pitch.getValue?this.pitch.getValue():this.pitch();break;case"object":n=Array.isArray(this.pitch)?this.pitch[0]:this.pitch.getValue?this.pitch.getValue():this.pitch.input.getValue(),"function"==typeof n&&(n=n())}e=0,Gibberish.dirty(this)}}},getBuffer:function(){return s},setBuffer:function(e){s=e},getPhase:function(){return e},setPhase:function(t){e=t},getNumberOfBuffers:function(){return Object.keys(a.buffers).length-1},callback:function(r,a,o,h,u,c,l,b,f,p){var d=0,g=l*c,m=b*c;return e+=r,null!==s&&h?(r>0?m>g+e?d=t(s,g+e):f&&(e=0):m+e>g?d=t(s,m+e):f&&(e=0),i(d*a,p,n)):(n[0]=n[1]=d,n)}}).init().oscillatorInit().processProperties(arguments),"undefined"!=typeof arguments[0]&&("string"==typeof arguments[0]?(this.file=arguments[0],this.pitch=0):"object"==typeof arguments[0]&&arguments[0].file&&(this.file=arguments[0].file)),"undefined"!=typeof Gibberish.audioFiles[this.file])s=Gibberish.audioFiles[this.file],this.end=1,this.buffers[this.file]=s,this.length=e=this.bufferLength=s.length,Gibberish.dirty(this),this.onload&&this.onload();else if(null!==this.file){var o,h=new XMLHttpRequest;h.open("GET",this.file,!0),h.responseType="arraybuffer",h.onload=function(e){o(this.response)},h.send(),h.onerror=function(e){console.error("Sampler file loading error",e)},o=function(t){Gibberish.context.decodeAudioData(t,function(t){s=t.getChannelData(0),a.length=e=r=s.length,a.isPlaying=!0,a.buffers[a.file]=s,Gibberish.audioFiles[a.file]=s,a.onload&&a.onload(),0!==a.playOnLoad&&a.note(a.playOnLoad),a.isLoaded=!0},function(e){console.log("Error decoding file",e)})}}else"undefined"!=typeof this.buffer&&(this.isLoaded=!0,s=this.buffer,this.bufferLength=s.length||88200,e=this.bufferLength,arguments[0]&&arguments[0].loops&&(this.loops=1),Gibberish.dirty(this),this.onload&&this.onload())},Gibberish.Sampler.prototype=Gibberish._oscillator,Gibberish.Sampler.prototype.record=function(e,t){this.isRecording=!0;var i=this;return this.recorder=new Gibberish.Record(e,t,function(){i.setBuffer(this.getBuffer()),bufferLength=i.getBuffer().length,i.setPhase(i.end),i.isRecording=!1}).record(),this},Gibberish.MonoSynth=function(){Gibberish.extend(this,{name:"monosynth",properties:{attack:1e4,decay:1e4,cutoff:.2,resonance:2.5,amp1:1,amp2:1,amp3:1,filterMult:.3,isLowPass:!0,pulsewidth:.5,amp:.6,detune2:.01,detune3:-.01,octave2:1,octave3:-1,glide:0,pan:0,velocity:1,frequency:0,channels:2},waveform:"Saw3",note:function(e,n){"undefined"!=typeof e&&("undefined"!=typeof n&&0!==n&&(this.velocity=n),0!==n&&("object"!=typeof this.frequency?this.frequency=e:(this.frequency[0]=e,Gibberish.dirty(this)),i()>0&&t.run()))}});var e=waveform1=waveform2=waveform3=this.waveform;Object.defineProperty(this,"waveform",{get:function(){return e},set:function(t){e!==t&&(e=t,r=(new Gibberish[t]).callback,a=(new Gibberish[t]).callback,o=(new Gibberish[t]).callback)}}),Object.defineProperties(this,{waveform1:{get:function(){return waveform1},set:function(e){waveform1=e,r=(new Gibberish[e]).callback}},waveform2:{get:function(){return waveform2},set:function(e){waveform2=e,a=(new Gibberish[e]).callback}},waveform3:{get:function(){return waveform3},set:function(e){waveform3=e,o=(new Gibberish[e]).callback}}});var t=new Gibberish.AD(this.attack,this.decay),i=t.getState,n=t.callback,s=(new Gibberish.Filter24).callback,r=new Gibberish[this.waveform](this.frequency,this.amp1).callback,a=new Gibberish[this.waveform](this.frequency2,this.amp2).callback,o=new Gibberish[this.waveform](this.frequency3,this.amp3).callback,h=(new Gibberish.OnePole).callback,u=Gibberish.makePanner(),c=[0,0];this.envelope=t,this.callback=function(e,t,l,b,f,p,d,g,m,y,v,G,k,x,w,_,P,S,A,R){if(i()<2){_>=1&&(_=.9999),A=h(A,1-_,_);var q=A;if(x>0)for(var M=0;x>M;M++)q*=2;else if(0>x)for(var M=0;M>x;M--)q/=2;var C=A;if(w>0)for(var M=0;w>M;M++)C*=2;else if(0>w)for(var M=0;M>w;M--)C/=2;q+=G>0?(2*A-A)*G:(A-A/2)*G,C+=k>0?(2*A-A)*k:(A-A/2)*k;var O=r(A,f,y)+a(q,p,y)+o(C,d,y),I=n(e,t)*S,T=s(O,l+g*I,b,m,1)*I;return T*=v,c[0]=c[1]=T,1===R?c:u(T,P,c)}return c[0]=c[1]=0,c},this.init(),this.oscillatorInit(),this.processProperties(arguments)},Gibberish.MonoSynth.prototype=Gibberish._synth,Gibberish.Binops={"export":function(e){Gibberish["export"]("Binops",e||window)},operator:function(){var e=new Gibberish.ugen,t=arguments[0],i=Array.prototype.slice.call(arguments,1);e.name="op",e.properties={};for(var n=0;n<i.length;n++)e.properties[n]=i[n];return e.init.apply(e,i),e.codegen=function(){var e,i="( ";if("undefined"!=typeof Gibberish.memo[this.symbol])return Gibberish.memo[this.symbol];e=Object.keys(this.properties);for(var n=!1,s=0;s<e.length;s++)if(n)n=!1;else{var r="object"==typeof this[s];i+=r?this[s].codegen():this[s],"*"!==t&&"/"!==t||1!==this[s+1]?s<e.length-1&&(i+=" "+t+" "):n=!0}return i+=" )",this.codeblock=i,i},e.valueOf=function(){return e.codegen()},e},Add:function(){var e=Array.prototype.slice.call(arguments,0);return e.unshift("+"),Gibberish.Binops.operator.apply(null,e)},Sub:function(){var e=Array.prototype.slice.call(arguments,0);return e.unshift("-"),Gibberish.Binops.operator.apply(null,e)},Mul:function(){var e=Array.prototype.slice.call(arguments,0);return e.unshift("*"),Gibberish.Binops.operator.apply(null,e)},Div:function(){var e=Array.prototype.slice.call(arguments,0);return e.unshift("/"),Gibberish.Binops.operator.apply(null,e)},Mod:function(){var e=Array.prototype.slice.call(arguments,0);return e.unshift("%"),Gibberish.Binops.operator.apply(null,e)},Abs:function(){var e=Array.prototype.slice.call(arguments,0),t={name:"abs",
properties:{},callback:Math.abs.bind(t)};return t.__proto__=new Gibberish.ugen,t.properties[0]=e[0],t.init(),t},Sqrt:function(){var e=(Array.prototype.slice.call(arguments,0),{name:"sqrt",properties:{},callback:Math.sqrt.bind(e)});return e.__proto__=new Gibberish.ugen,e.properties[i]=arguments[0],e.init(),e},Pow:function(){var e=Array.prototype.slice.call(arguments,0),t={name:"pow",properties:{},callback:Math.pow.bind(t)};t.__proto__=new Gibberish.ugen;for(var i=0;i<e.length;i++)t.properties[i]=e[i];return t.init(),console.log(t.callback),t},Clamp:function(){var e=Array.prototype.slice.call(arguments,0),t={name:"clamp",properties:{input:0,min:0,max:1},callback:function(e,t,i){return t>e?e=t:e>i&&(e=i),e}};return t.__proto__=new Gibberish.ugen,t.init(),t.processProperties(e),t},Merge:function(){var e=Array.prototype.slice.call(arguments,0),t={name:"merge",properties:{},callback:function(e){return e[0]+e[1]}};t.__proto__=new Gibberish.ugen;for(var i=0;i<e.length;i++)t.properties[i]=e[i];return t.init(),t},Map:function(e,t,i,n,s,r,a){var o=Math.pow,h=0,u=0,c={name:"map",properties:{input:e,outputMin:t,outputMax:i,inputMin:n,inputMax:s,curve:r||h,wrap:a||!1},callback:function(e,t,i,n,s,r,a){var h,c=i-t,l=s-n,b=(e-n)/l;return b>1?b=a?b%1:1:0>b&&(b=a?1+b%1:0),h=0===r?t+b*c:t+o(b,1.5)*c,u=h,h},getValue:function(){return u},invert:function(){var e=c.outputMin;c.outputMin=c.outputMax,c.outputMax=e}};return c.__proto__=new Gibberish.ugen,c.init(),c}},Gibberish.Time={bpm:120,"export":function(e){Gibberish["export"]("Time",e||window)},ms:function(e){return e*Gibberish.context.sampleRate/1e3},seconds:function(e){return e*Gibberish.context.sampleRate},beats:function(e){return function(){var t=Gibberish.context.sampleRate/(Gibberish.Time.bpm/60);return t*e}}},Gibberish.Sequencer2=function(){var e=this,t=0;Gibberish.extend(this,{target:null,key:null,values:null,valuesIndex:0,durations:null,durationsIndex:0,nextTime:0,playOnce:!1,repeatCount:0,repeatTarget:null,isConnected:!0,keysAndValues:null,counts:{},properties:{rate:1,isRunning:!1,nextTime:0},offset:0,name:"seq",callback:function(i,n,s){if(n){if(t>=s){if(null!==e.values){if(e.target){var r=e.values[e.valuesIndex++];"function"==typeof r&&(r=r()),"function"==typeof e.target[e.key]?e.target[e.key](r):e.target[e.key]=r}else"function"==typeof e.values[e.valuesIndex]&&e.values[e.valuesIndex++]();e.valuesIndex>=e.values.length&&(e.valuesIndex=0)}else if(null!==e.keysAndValues)for(var a in e.keysAndValues){var o=e.counts[a]++,r=e.keysAndValues[a][o];"function"==typeof r&&(r=r()),"function"==typeof e.target[a]?e.target[a](r):e.target[a]=r,e.counts[a]>=e.keysAndValues[a].length&&(e.counts[a]=0),e.chose&&e.chose(a,o)}else"function"==typeof e.target[e.key]&&e.target[e.key]();if(t-=s,Array.isArray(e.durations)){var h=e.durations[e.durationsIndex++];e.nextTime="function"==typeof h?h():h,e.chose&&e.chose("durations",e.durationsIndex-1),e.durationsIndex>=e.durations.length&&(e.durationsIndex=0)}else{var h=e.durations;e.nextTime="function"==typeof h?h():h}return e.repeatTarget&&(e.repeatCount++,e.repeatCount===e.repeatTarget&&(e.isRunning=!1,e.repeatCount=0)),0}t+=i}return 0},start:function(e){return e||(t=0),this.isRunning=!0,this},stop:function(){return this.isRunning=!1,this},repeat:function(e){return this.repeatTarget=e,this},shuffle:function(){for(i in this.keysAndValues)this.shuffleArray(this.keysAndValues[i])},shuffleArray:function(e){for(var t,i,n=e.length;n;t=parseInt(Math.random()*n),i=e[--n],e[n]=e[t],e[t]=i);}}),this.init(arguments),this.processProperties(arguments);for(var i in this.keysAndValues)this.counts[i]=0;this.oscillatorInit(),t+=this.offset,this.connect()},Gibberish.Sequencer2.prototype=Gibberish._oscillator,Gibberish.Sequencer=function(){Gibberish.extend(this,{target:null,key:null,values:null,valuesIndex:0,durations:null,durationsIndex:0,nextTime:0,phase:0,isRunning:!1,playOnce:!1,repeatCount:0,repeatTarget:null,isConnected:!0,keysAndValues:null,counts:{},offset:0,name:"seq",tick:function(){if(this.isRunning){if(this.phase>=this.nextTime){if(null!==this.values){if(this.target){var e=this.values[this.valuesIndex++];if("function"==typeof e)try{e=e()}catch(t){console.error("ERROR: Can't execute function triggered by Sequencer:\n"+e.toString()),this.values.splice(this.valuesIndex-1,1),this.valuesIndex--}"function"==typeof this.target[this.key]?this.target[this.key](e):this.target[this.key]=e}else if("function"==typeof this.values[this.valuesIndex])try{this.values[this.valuesIndex++]()}catch(t){console.error("ERROR: Can't execute function triggered by Sequencer:\n"+this.values[this.valuesIndex-1].toString()),this.values.splice(this.valuesIndex-1,1),this.valuesIndex--}this.valuesIndex>=this.values.length&&(this.valuesIndex=0)}else if(null!==this.keysAndValues)for(var i in this.keysAndValues){var n="function"==typeof this.keysAndValues[i].pick?this.keysAndValues[i].pick():this.counts[i]++,e=this.keysAndValues[i][n];if("function"==typeof e)try{e=e()}catch(t){console.error("ERROR: Can't execute function triggered by Sequencer:\n"+e.toString()),this.keysAndValues[i].splice(n,1),"function"!=typeof this.keysAndValues[i].pick&&this.counts[i]--}"function"==typeof this.target[i]?this.target[i](e):this.target[i]=e,this.counts[i]>=this.keysAndValues[i].length&&(this.counts[i]=0)}else"function"==typeof this.target[this.key]&&this.target[this.key]();if(this.phase-=this.nextTime,Array.isArray(this.durations)){var s="function"==typeof this.durations.pick?this.durations[this.durations.pick()]:this.durations[this.durationsIndex++];this.nextTime="function"==typeof s?s():s,this.durationsIndex>=this.durations.length&&(this.durationsIndex=0)}else{var s=this.durations;this.nextTime="function"==typeof s?s():s}return void(this.repeatTarget&&(this.repeatCount++,this.repeatCount===this.repeatTarget&&(this.isRunning=!1,this.repeatCount=0)))}this.phase++}},start:function(e){return e||(this.phase=this.offset),this.isRunning=!0,this},stop:function(){return this.isRunning=!1,this},repeat:function(e){return this.repeatTarget=e,this},shuffle:function(){for(e in this.keysAndValues)this.shuffleArray(this.keysAndValues[e])},shuffleArray:function(e){for(var t,i,n=e.length;n;t=parseInt(Math.random()*n),i=e[--n],e[n]=e[t],e[t]=i);},disconnect:function(){var e=Gibberish.sequencers.indexOf(this);Gibberish.sequencers.splice(e,1),this.isConnected=!1},connect:function(){return-1===Gibberish.sequencers.indexOf(this)&&Gibberish.sequencers.push(this),this.isConnected=!0,this}});for(var e in arguments[0])this[e]=arguments[0][e];for(var e in this.keysAndValues)this.counts[e]=0;this.connect(),this.phase+=this.offset},Gibberish.Sequencer.prototype=Gibberish._oscillator,Gibberish.PolySeq=function(){var e=this,t=0,i=function(e,t){return t>e?-1:e>t?1:0};Gibberish.extend(this,{seqs:[],autofire:[],timeline:{},playOnce:!1,repeatCount:0,repeatTarget:null,isConnected:!1,properties:{rate:1,isRunning:!1,nextTime:0},offset:0,name:"polyseq",getPhase:function(){return t},setPhase:function(e){t=e},adjustPhase:function(e){t+=e},timeModifier:null,add:function(i,n){i.valuesIndex=i.durationsIndex=0,null===i.durations?(i.autofire=!0,e.autofire.push(i)):("undefined"==typeof n?e.seqs.push(i):e.seqs.splice(n,0,i),"undefined"!=typeof e.timeline[t]?i.priority?e.timeline[t].unshift(i):e.timeline[t].push(i):e.timeline[t]=[i],e.nextTime=t),!e.scale||"frequency"!==i.key&&"note"!==i.key||e.applyScale&&e.applyScale(),i.shouldStop=!1},callback:function(n,s,r){var a;if(s){if(t>=r){var o=e.timeline[r],h=t-r;if("undefined"==typeof o)return;for(var u=0;u<o.length;u++){var c=o[u];if(!c.shouldStop){var l=c.values.pick?c.values.pick():c.valuesIndex++%c.values.length,b="function"==typeof c.values?c.values():c.values[l];if("function"==typeof b&&(b=b()),c.target&&("function"==typeof c.target[c.key]?c.target[c.key](b):c.target[c.key]=b),e.chose&&e.chose(c.key,l),Array.isArray(c.durations)){var l=c.durations.pick?c.durations.pick():c.durationsIndex++,f="function"==typeof c.durations?c.durations():c.durations[l];a="function"==typeof f?f():f,"function"!=typeof c.durations&&c.durationsIndex>=c.durations.length&&(c.durationsIndex=0),e.chose&&e.chose("durations",l)}else{var f="function"==typeof c.durations?c.durations():c.durations;a="function"==typeof f?f():f}var p;p=null!==e.timeModifier?e.timeModifier(a)+t:a+t,p-=h,a-=h,"undefined"==typeof e.timeline[p]?e.timeline[p]=[c]:c.priority?e.timeline[p].unshift(c):e.timeline[p].push(c)}}for(var u=0,d=e.autofire.length;d>u;u++){var c=e.autofire[u];if(!c.shouldStop){var l=c.values.pick?c.values.pick():c.valuesIndex++%c.values.length,b=c.values[l];"function"==typeof b&&(b=b()),c.target&&("function"==typeof c.target[c.key]?c.target[c.key](b):c.target[c.key]=b),e.chose&&e.chose(c.key,l)}}delete e.timeline[r];var g=Object.keys(e.timeline),m=g.length;if(m>1){for(var y=0;m>y;y++)g[y]=parseFloat(g[y]);g=g.sort(i),e.nextTime=g[0]}else e.nextTime=parseFloat(g[0])}t+=n}return 0},start:function(e,i){if(e&&this.offset){t=0,this.nextTime=this.offset;var n=""+this.offset;this.timeline={},this.timeline[n]=[];for(var s=0;s<this.seqs.length;s++){var r=this.seqs[s];r.valuesIndex=r.durationsIndex=r.shouldStop=0,this.timeline[n].push(r)}}else{t=0,this.nextTime=0,this.timeline={0:[]};for(var s=0;s<this.seqs.length;s++){var r=this.seqs[s];r.valuesIndex=r.durationsIndex=r.shouldStop=0,this.timeline[0].push(r)}}return this.isConnected||(this.connect(Gibberish.Master,i),this.isConnected=!0),this.isRunning=!0,this},stop:function(){return this.isRunning=!1,this.isConnected&&(this.disconnect(),this.isConnected=!1),this},repeat:function(e){return this.repeatTarget=e,this},shuffle:function(e){if("undefined"!=typeof e)for(var t=0;t<this.seqs.length;t++)this.seqs[t].key===e&&this.shuffleArray(this.seqs[t].values);else for(var t=0;t<this.seqs.length;t++)this.shuffleArray(this.seqs[t].values)},shuffleArray:function(e){for(var t,i,n=e.length;n;t=parseInt(Math.random()*n),i=e[--n],e[n]=e[t],e[t]=i);}}),this.init(arguments),this.processProperties(arguments),this.oscillatorInit()},Gibberish.PolySeq.prototype=Gibberish._oscillator;var _hasInput=!1;return"object"==typeof navigator&&(navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia),Gibberish.Input=function(){var e=[];_hasInput||createInput(),this.type=this.name="input",this.fx=new Array2,this.fx.parent=this,this.properties={input:"input",amp:.5,channels:1},this.callback=function(t,i,n){return 1===n?e=t*i:(e[0]=t[0]*i,e[1]=t[1]*i),e},this.init(arguments),this.processProperties(arguments)},Gibberish.Input.prototype=new Gibberish.ugen,Gibberish.Kick=function(){var e=!1,t=(new Gibberish.SVF).callback,i=(new Gibberish.SVF).callback,n=.2,s=.8;Gibberish.extend(this,{name:"kick",properties:{pitch:50,__decay:20,__tone:1e3,amp:2,sr:Gibberish.context.sampleRate},callback:function(n,s,r,a,o){var h=e?60:0;return h=t(h,n,s,2,o),h=i(h,r,.5,0,o),h*=a,e=!1,h},note:function(t,i,n,s){"number"==typeof t&&(this.pitch=t),"number"==typeof i&&(this.decay=i),"number"==typeof n&&(this.tone=n),"number"==typeof s&&(this.amp=s),e=!0}}).init().oscillatorInit(),Object.defineProperties(this,{decay:{get:function(){return n},set:function(e){n=e>1?1:e,this.__decay=100*n}},tone:{get:function(){return s},set:function(e){s=e>1?1:e,this.__tone=220+1400*e}}}),this.processProperties(arguments)},Gibberish.Kick.prototype=Gibberish._oscillator,Gibberish.Conga=function(){var e=!1,t=(new Gibberish.SVF).callback;Gibberish.extend(this,{name:"conga",properties:{pitch:190,amp:2,sr:Gibberish.context.sampleRate},callback:function(i,n,s){var r=e?60:0;return r=t(r,i,50,2,s),r*=n,e=!1,r},note:function(t,i){"number"==typeof t&&(this.pitch=t),"number"==typeof i&&(this.amp=i),e=!0}}).init().oscillatorInit(),this.processProperties(arguments)},Gibberish.Conga.prototype=Gibberish._oscillator,Gibberish.Clave=function(){var e=!1,t=new Gibberish.SVF,i=t.callback;Gibberish.extend(this,{name:"clave",properties:{pitch:2500,amp:1,sr:Gibberish.context.sampleRate},callback:function(t,n,s){var r=e?2:0;return r=i(r,t,5,2,s),r*=n,e=!1,r},note:function(t,i){"number"==typeof t&&(this.pitch=t),"number"==typeof i&&(this.amp=i),e=!0}}).init().oscillatorInit(),this.bpf=t,this.processProperties(arguments)},Gibberish.Clave.prototype=Gibberish._oscillator,Gibberish.Tom=function(){var e=!1,t=(new Gibberish.SVF).callback,i=(new Gibberish.SVF).callback,n=new Gibberish.ExponentialDecay,s=n.callback,r=Math.random;Gibberish.extend(this,{name:"tom",properties:{pitch:80,amp:.5,sr:Gibberish.context.sampleRate},callback:function(n,a,o){var h,u=e?60:0;return u=t(u,n,30,2,o),h=16*r()-8,h=h>0?h:0,h*=s(.05,11025),h=i(h,120,.5,0,o),u+=h,u*=a,e=!1,u},note:function(t,i){"number"==typeof t&&(this.pitch=t),"number"==typeof i&&(this.amp=i),n.trigger(),e=!0}}).init().oscillatorInit(),n.trigger(1),this.processProperties(arguments)},Gibberish.Tom.prototype=Gibberish._oscillator,Gibberish.Clap=function(){var e=new Gibberish.Biquad,t=e.callback,i=new Gibberish.Biquad,n=i.callback,s=new Gibberish.Biquad,r=s.callback,a=new Gibberish.ExponentialDecay,o=a.callback,h=new Gibberish.ExponentialDecay,u=h.callback,c=new Gibberish.Line,l=(c.callback,new Gibberish.Saw),b=l.callback,f=Math.random,p=1e3,d=2.5,g=.025,m=.9,y=1323,v=660,G=100;e.mode=i.mode="BP",s.mode="BP",s.cutoff=2400,e.cutoff=i.cutoff=1e3,e.Q=2,i.Q=1,Gibberish.extend(this,{name:"clap",properties:{amp:.5,sr:Gibberish.context.sampleRate},callback:function(e,i){var s,a,h=0;return s=4*f()-2,s=s>0?s:0,a=4*f()-2,a=a>0?a:0,h=n(t(s)),h*=u(m,v),a=r(b(G,a)*o(g,y)),h+=a,h*=e},note:function(e){"number"==typeof e&&(this.amp=e),h.trigger(),a.trigger(),c.setPhase(0),l.setPhase(0)}}).init().oscillatorInit(),this.getBPF=function(){return e},this.getBPF2=function(){return i},this.getBPF3=function(){return s},this.getLine=function(){return c},this.setEnvK=function(e,t,i,n){g=e,t&&(m=t),i&&(y=i),n&&(v=n)},this.setFreq=function(e){G=e},this.setRez=function(e){d=e},this.setCutoff=function(e){p=e},this.processProperties(arguments)},Gibberish.Clap.prototype=Gibberish._oscillator,Gibberish.Cowbell=function(){var e=new Gibberish.Square,t=new Gibberish.Square,i=e.callback,n=t.callback,s=new Gibberish.SVF({mode:2}),r=s.callback,a=new Gibberish.ExponentialDecay(.0025,10500),o=a.callback;Gibberish.extend(this,{name:"cowbell",properties:{amp:1,pitch:560,bpfFreq:1e3,bpfRez:3,decay:22050,decayCoeff:1e-4,sr:Gibberish.context.sampleRate},callback:function(e,t,s,a,h,u,c){var l;return l=i(t,1,1,0),l+=n(845,1,1,0),l=r(l,s,a,2,c),l*=o(u,h),l*=e},note:function(e,t){a.trigger(),e&&(this.decay=e)}}).init().oscillatorInit().processProperties(arguments),this.bpf=s,this.eg=a,a.trigger(1)},Gibberish.Cowbell.prototype=Gibberish._oscillator,Gibberish.Snare=function(){var e=(new Gibberish.SVF).callback,t=(new Gibberish.SVF).callback,i=(new Gibberish.SVF).callback,n=new Gibberish.ExponentialDecay(.0025,11025),s=n.callback,r=Math.random,a=0;Gibberish.extend(this,{name:"snare",properties:{cutoff:1e3,decay:11025,tune:0,snappy:.5,amp:1,sr:Gibberish.context.sampleRate},callback:function(n,o,h,u,c,l){var b,f,p=0,d=0;return p=s(.0025,o),p>.005&&(d=(2*r()-1)*p,d=i(d,n+1e3*h,.5,1,l),d*=u,d=d>0?d:0,a=p,b=e(a,180*(h+1),15,2,l),f=t(a,330*(h+1),15,2,l),d+=b,d+=.8*f,d*=c),d},note:function(e,t,i,s){"number"==typeof e&&(this.tune=e),"number"==typeof s&&(this.cutoff=s),"number"==typeof i&&(this.snappy=i),"number"==typeof t&&(this.amp=t),n.trigger()}}).init().oscillatorInit().processProperties(arguments),n.trigger(1)},Gibberish.Snare.prototype=Gibberish._oscillator,Gibberish.Hat=function(){var e=new Gibberish.Square,t=new Gibberish.Square,i=new Gibberish.Square,n=new Gibberish.Square,s=new Gibberish.Square,r=new Gibberish.Square,a=e.callback,o=t.callback,h=i.callback,u=n.callback,c=s.callback,l=r.callback,b=new Gibberish.SVF({mode:2}),f=b.callback,p=new Gibberish.Filter24,d=p.callback,g=new Gibberish.ExponentialDecay(.0025,10500),m=g.callback,y=new Gibberish.ExponentialDecay(.1,7500);y.callback;Gibberish.extend(this,{name:"hat",properties:{amp:1,pitch:325,bpfFreq:7e3,bpfRez:2,hpfFreq:.975,hpfRez:0,decay:3500,decay2:3e3,sr:Gibberish.context.sampleRate},callback:function(e,t,i,n,s,r,b,p,g){var y;return y=a(t,1,.5,0),y+=o(1.4471*t,.75,1,0),y+=h(1.617*t,1,1,0),y+=u(1.9265*t,1,1,0),y+=c(2.5028*t,1,1,0),y+=l(2.6637*t,.75,1,0),y=f(y,i,n,2,g),y*=m(.001,b),y=d(y,s,r,0,1),y*=e},note:function(e,t){g.trigger(),y.trigger(),e&&(this.decay=e),t&&(this.decay2=t)}}).init().oscillatorInit().processProperties(arguments),this.bpf=b,this.hpf=p,g.trigger(1),y.trigger(1)},Gibberish.Hat.prototype=Gibberish._oscillator,function(){var e={Soundfont:{instruments:{}}},t=e.Soundfont;"object"==typeof window?window.GenMIDI=e:global.GenMIDI=e;var i=function(e,t){function i(i){console.log("COMPLETE",e);var n=document.createElement("script");n.innerHTML=i.srcElement?i.srcElement.responseText:i.target.responseText,document.querySelector("head").appendChild(n),t(n)}var n=new XMLHttpRequest;n.addEventListener("load",i,!1),n.addEventListener("error",function(e){console.log("SF load error",e)},!1),n.open("GET",e,!0),n.send()},n={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",decodeArrayBuffer:function(e){var t=e.length/4*3,i=new ArrayBuffer(t);return this.decode(e,i),i},decode:function(e,t){var i=this._keyStr.indexOf(e.charAt(e.length-1)),n=this._keyStr.indexOf(e.charAt(e.length-2)),s=e.length/4*3;64==i&&s--,64==n&&s--;var r,a,o,h,u,c,l,b,f=0,p=0;for(r=t?new Uint8Array(t):new Uint8Array(s),e=e.replace(/[^A-Za-z0-9\+\/\=]/g,""),f=0;s>f;f+=3)u=this._keyStr.indexOf(e.charAt(p++)),c=this._keyStr.indexOf(e.charAt(p++)),l=this._keyStr.indexOf(e.charAt(p++)),b=this._keyStr.indexOf(e.charAt(p++)),a=u<<2|c>>4,o=(15&c)<<4|l>>2,h=(3&l)<<6|b,r[f]=a,64!=l&&(r[f+1]=o),64!=b&&(r[f+2]=h);return r}},s=function(e){var i=0,s=t[e.instrumentFileName];"undefined"==typeof t.instruments[e.instrumentFileName]&&(t.instruments[e.instrumentFileName]={}),e.buffers=t.instruments[e.instrumentFileName];for(var r in s)i++,!function(){var a=r,o=s[a].split(",")[1],h=n.decodeArrayBuffer(o);Gibberish.context.decodeAudioData(h,function(n){t.instruments[e.instrumentFileName][a]=n.getChannelData(0),i--,0>=i&&(console.log("Soundfont "+e.instrumentFileName+" is loaded."),e.isLoaded=!0,e.onload&&e.onload())},function(e){console.log("ERROR",e.err,arguments,a)})}()};Gibberish.SoundFont=function(e,n){return Gibberish.extend(this,{instrumentFileName:e,name:"soundfont",properties:{amp:1,pan:0},playing:[],buffers:{},onload:null,out:[0,0],isLoaded:!1,resourcePath:n||"./resources/soundfonts/",callback:function(e,t){for(var i=0,n=this.playing.length-1;n>=0;n--){var s=this.playing[n];i+=this.interpolate(s.buffer,s.phase)*s.velocity,s.phase+=s.increment,s.phase>s.length&&this.playing.splice(this.playing.indexOf(s),1)}return this.panner(i*e,t,this.out)}.bind(this),note:function(e,t,i){this.isLoaded&&this.playing.push({buffer:this.buffers[e],phase:0,increment:isNaN(i)?1:1+i,length:this.buffers[e].length,velocity:isNaN(t)?1:t})},interpolate:Gibberish.interpolate.bind(this),panner:Gibberish.makePanner()}).init().oscillatorInit(),"object"==typeof arguments[0]&&arguments[0].instrumentFileName&&(this.instrumentFileName=arguments[0].instrumentFileName),t.instruments[this.instrumentFileName]||"object"==typeof n?"object"==typeof n?(t[this.instrumentFileName]=n,s(this)):(this.buffers=t.instruments[this.instrumentFileName],this.isLoaded=!0,setTimeout(function(){this.onload&&this.onload()}.bind(this),0)):(console.log("DOWNLOADING SOUNDFONT"),i(n+this.instrumentFileName+"-mp3.js",s.bind(null,this))),this},Gibberish.SoundFont.storage=t,Gibberish.SoundFont.prototype=Gibberish._oscillator}(),Gibberish.Vocoder=function(){var e=[],t=[],i=Math.abs,n=(Math.sqrt,[0,0]),s=[],r=[],a=128,o=[],h=[],u=[],c=0,l=arguments[3]||330,b=arguments[4]||3200,f=arguments[2]||16,p=arguments[5]||.15;this.name="vocoder",this.properties={carrier:arguments[0]||null,modulator:arguments[1]||null,amp:1,pan:0};for(var d=1200*Math.log(b/l)/Math.LN2,g=d/f,m=Math.pow(2,g/1200),y=l,v=0;f>v;v++)s[v]=new Gibberish.Biquad({mode:"BP",Q:p,cutoff:y}),e[v]=s[v].callback,r[v]=new Gibberish.Biquad({mode:"BP",Q:p,cutoff:y}),t[v]=r[v].callback,o[v]=[0],h[v]=0,u[v]=0,y*=m;this.callback=function(s,r,l,b){for(var p,d=(c+1)%a,g="number"!=typeof r?r[0]+r[1]:r,m="number"!=typeof s?s[0]+s[1]:s,y=0,v=0;f>v;v++)p=i(e[v](g)),h[v]+=p,h[v]-=o[v][c],o[v][c]=p,o[v][d]=o[v][d]?o[v][d]:0,u[v]=h[v]/a,y+=t[v](m)*u[v];return c=d,n[0]=n[1]=y*l*16,n},this.getEncoders=function(){return s},this.getDecoders=function(){return r},this.init(),this.oscillatorInit()},Gibberish.Vocoder.prototype=Gibberish._synth,Gibberish});