From 0ed2530afe9be5b7fa6905d4380f9ed2a13c7996 Mon Sep 17 00:00:00 2001 From: mohayonao Date: Wed, 12 Dec 2012 09:16:58 +0900 Subject: [PATCH] fixed issue #4 --- src/window/player.js | 14 +++----------- timbre.js | 18 +++++------------- timbre.min.js | 6 +++--- 3 files changed, 11 insertions(+), 27 deletions(-) diff --git a/src/window/player.js b/src/window/player.js index fd58f9a..5831305 100644 --- a/src/window/player.js +++ b/src/window/player.js @@ -103,20 +103,13 @@ var MozPlayer = function(sys) { this.audio.mozSetup(timbre.channels, timbre.samplerate); timbre.samplerate = this.audio.mozSampleRate; timbre.channels = this.audio.mozChannels; - - this.written = 0; + this.interleaved = new Float32Array(timbre.streamsize * timbre.channels); this.onaudioprocess = function() { var mozCurrentSampleOffset = this.audio.mozCurrentSampleOffset(); - // v12.07.23: bugfix for linux (mozCurrentSampleOffset > 0) - if (mozCurrentSampleOffset > 0 && - this.written > mozCurrentSampleOffset + 16384) { - return this; - } - var interleaved = this.interleaved; this.audio.mozWriteAudio(interleaved); sys.process(); @@ -128,15 +121,14 @@ var MozPlayer = function(sys) { interleaved[--i] = inR[j]; interleaved[--i] = inL[j]; } - this.written += interleaved.length; }.bind(this); return this; }; this.on = function() { - this.written = 0; - this.timer.setInterval(this.onaudioprocess, 20); + var interval = timbre.streamsize / timbre.samplerate * 1000; + this.timer.setInterval(this.onaudioprocess, interval); }; this.off = function() { diff --git a/timbre.js b/timbre.js index 18810ee..97f31cb 100644 --- a/timbre.js +++ b/timbre.js @@ -1,5 +1,5 @@ /** - * timbre.js v12.07.24 / JavaScript Library for Objective Sound Programming + * timbre.js v12.12.12 / JavaScript Library for Objective Sound Programming */ ; var timbre = (function(context, timbre) { @@ -9,7 +9,7 @@ var timbre = (function(context, timbre) { var timbre = function() { return timbre.fn.init.apply(timbre, arguments); }; - timbre.VERSION = "v12.07.24"; + timbre.VERSION = "v12.12.12"; timbre.env = ""; timbre.platform = ""; timbre.samplerate = 0; @@ -9373,20 +9373,13 @@ var timbre = (function(context, timbre) { this.audio.mozSetup(timbre.channels, timbre.samplerate); timbre.samplerate = this.audio.mozSampleRate; timbre.channels = this.audio.mozChannels; - - this.written = 0; + this.interleaved = new Float32Array(timbre.streamsize * timbre.channels); this.onaudioprocess = function() { var mozCurrentSampleOffset = this.audio.mozCurrentSampleOffset(); - // v12.07.23: bugfix for linux (mozCurrentSampleOffset > 0) - if (mozCurrentSampleOffset > 0 && - this.written > mozCurrentSampleOffset + 16384) { - return this; - } - var interleaved = this.interleaved; this.audio.mozWriteAudio(interleaved); sys.process(); @@ -9398,15 +9391,14 @@ var timbre = (function(context, timbre) { interleaved[--i] = inR[j]; interleaved[--i] = inL[j]; } - this.written += interleaved.length; }.bind(this); return this; }; this.on = function() { - this.written = 0; - this.timer.setInterval(this.onaudioprocess, 20); + var interval = timbre.streamsize / timbre.samplerate * 1000; + this.timer.setInterval(this.onaudioprocess, interval); }; this.off = function() { diff --git a/timbre.min.js b/timbre.min.js index a4b4519..94d21db 100644 --- a/timbre.min.js +++ b/timbre.min.js @@ -1,6 +1,6 @@ /** - * timbre.js v12.07.24 / JavaScript Library for Objective Sound Programming - */var timbre=function(a,b){"use strict";var b=function(){return b.fn.init.apply(b,arguments)};b.VERSION="v12.07.24",b.env="",b.platform="",b.samplerate=0,b.channels=2,b.cellsize=128,b.streamsize=1024,b.dacs=[],b.timers=[],b.listeners=[],b.sys=null,b.context={},b.utils={},b._={ev:{},amp:.8,autorun:!0,verbose:!0,workerpath:"",none:new Float32Array(b.cellsize)},Object.defineProperties(b,{amp:{set:function(a){typeof a=="number"&&(b._.amp=a)},get:function(){return b._.amp}},autorun:{set:function(a){b._.autorun=!!a},get:function(){return b._.autorun}},workerpath:{set:function(a){typeof a=="string"&&(b._.workerpath=a)},get:function(){return b._.workerpath}},verbose:{set:function(a){b._.verbose=!!a},get:function(){return b._.verbose}},isOn:{get:function(){return b.sys._.ison}},isOff:{get:function(){return!b.sys._.ison}}}),b.setup=function(a){Object.isFrozen(b)?b._.verbose&&a&&console.warn("timbre is already configured."):(typeof a=="object"&&(typeof a.samplerate=="number"&&(b.samplerate=a.samplerate),typeof a.channels=="number"&&(b.channels=a.channels),typeof a.cellsize=="number"&&(b.cellsize=a.cellsize),typeof a.streamsize=="number"&&(b.cellsize=a.streamsize)),b.sys.setup(),b._.none=new Float32Array(b.cellsize),Object.freeze(b));return b},b.on=function(){b.sys._.ison||(b.setup(),b.sys.on(),b.fn.doEvent(this,"on"));return b},b.off=function(){b.sys._.ison&&(b.sys.off(),b.fn.doEvent(this,"off"));return b},b.addEventListener=function(a,b){if(typeof b=="function"){a[0]==="~"&&(a=a.substr(1),b.rm=!0);var c,d=this._.ev[a];d===undefined&&(this._.ev[a]=d=[]),(c=d.indexOf(b))===-1&&d.push(b)}return this},b.removeEventListener=function(a,b){if(typeof a=="string"&&a!==""){var c,d=this._.ev[a];d!==undefined&&(c=d.indexOf(b))!==-1&&d.splice(c,1)}return this},b.removeAllEventListeners=function(a){typeof a=="string"&&a!==""&&(delete this._.ev[a],delete this["on"+a]);return this},function(){var a=function(){var a=b.fn.valist(arguments);for(var c=0,d=a.length,e=!1;c0)this.pop();b._.autorun&&b.dacs.length===0&&b.timers.length===0&&b.off();return this};for(var e,f=arguments.length;f--;)e=arguments[f],e.append=a,e.remove=c,e.removeAll=d}(b.dacs,b.timers,b.listeners),b.dacs.type=1,b.timers.type=2,b.listeners.type=3,b.fn=function(a){var b={},c=function(){return this},h=function(){};h.objectId=0,h.klasses={_find:function(b){if(typeof h.klasses[b]=="function")return h.klasses[b];b="-"+a.env+"-"+b;if(typeof h.klasses[b]=="function")return h.klasses[b]}},h.PrototypeValue=function(){},a.TimbreBasePrototype=h.prototype={play:function(){var b,c=this._;c.ar&&(c.dac===null?(c.dac=a("dac",this),(b=c.proto._.play)instanceof Function&&b.call(this),a.fn.doEvent(this,"play")):this.dac.args.indexOf(this)===-1&&(c.dac.append(this),(b=c.proto._.play)instanceof Function&&b.call(this),a.fn.doEvent(this,"play")),c.dac.isOff&&c.dac.on());return this},pause:function(){var b,c=this._;c.dac&&c.dac.args.indexOf(this)!==-1&&(c.dac.remove(this),(b=c.proto._.pause)instanceof Function&&b.call(this),a.fn.doEvent(this,"pause"),c.dac.isOn&&c.dac.args.length===0&&c.dac.off());return this},ar:function(){this._.ar=!0;return this},kr:function(){this._.ar=!1;return this},bang:function(){a.fn.doEvent(this,"bang");return this},seq:function(){return this.cell},on:function(){var b;this._.ison=!0,(b=this._.proto._.on)instanceof Function&&b.call(this),a.fn.doEvent(this,"on");return this},off:function(){var b;this._.ison=!1,(b=this._.proto._.off)instanceof Function&&b.call(this),a.fn.doEvent(this,"off");return this},clone:function(b){var c=a(this._.proto._.klassname);a.fn.copyBaseArguments(this,c,b);return c},buddy:function(a,b,c){var d=this._.buddies;typeof a=="string"&&(a=[a]);if(a instanceof Array)for(var e=a.length,f;e--;)typeof (f=a[e])=="string"&&(b===null?delete d[f]:b===undefined?d[f]=[this.args,c]:b instanceof Array?d[f]=[b,c]:b instanceof Function?d[f]=[[b],c]:b instanceof h&&(d[f]=[[b],c]));return this},append:function(){var a;this.args.append.apply(this.args,arguments),(a=this._.proto._.append)instanceof Function&&a.call(this);return this},appendTo:function(a){a.args.append.call(a.args,this);return this},remove:function(){var a;this.args.remove.apply(this.args,arguments),(a=this._.proto._.remove)instanceof Function&&a.call(this);return this},removeFrom:function(a){a.args.remove.call(a.args,this);return this},removeAll:function(){var a;this.args.removeAll.apply(this.args,arguments),(a=this._.proto._.remove)instanceof Function&&a.call(this);return this},set:function(a,b){var c=Object.getOwnPropertyDescriptor;if(typeof a=="string"){var d=this._.proto;while(d!==null){if(c(d,a)!==undefined){this[a]=b;break}d=Object.getPrototypeOf(d)}}else if(typeof a=="object")for(var e in a){var d=this._.proto;while(d!==null){if(c(d,e)!==undefined){this[e]=a[e];break}d=Object.getPrototypeOf(d)}}return this},get:function(a){var b=Object.getOwnPropertyDescriptor,c=this._.proto;while(c!==null){if(b(c,a)!==undefined)return this[a];c=Object.getPrototypeOf(c)}},addEventListener:a.addEventListener,removeEventListener:a.removeEventListener,removeAllEventListeners:a.removeAllEventListeners};var i={isAr:{get:function(){return!!this._.ar}},isKr:{get:function(){return!this._.ar}},isOn:{get:function(){return!!this._.ison}},isOff:{get:function(){return!this._.ison}},isUndefined:{get:function(){return this._.isUndefined}},scalar:{get:function(){a.sys.seq_id!==this.seq_id&&this.seq(a.sys.seq_id);return this.cell[0]}},dac:{set:function(a){a!==this._.dac&&(this._.dac!==null&&this._.dac.remove(this),a!==null?this._.dac=a.append(this):this._.dac=null)},get:function(){return this._.dac}},mul:{set:function(a){typeof a=="number"&&(this._.mul=a)},get:function(){return this._.mul}},add:{set:function(a){typeof a=="number"&&(this._.add=a)},get:function(){return this._.add}}};Object.defineProperties(h.prototype,i),b.init=function(){h.objectId===0&&a.setup();var c,i,j,k,l=Array.prototype.slice.call(arguments),m=l[0];switch(typeof m){case"string":(c=h.klasses._find(m))!==undefined&&(i=new c(l.slice(1)));break;case"number":i=new d([m]);break;case"boolean":i=new e([m]);break;case"function":i=new g(l);break;case"object":m===null?i=new d([0]):b.isTimbreObject(m)?(i=m,j=!0):m instanceof Array&&(i=new f([m]))}i===undefined&&(i=new d([0]),k=!0,a._.verbose&&console.warn("'"+m+"' is not defined."));var n=Object.getPrototypeOf(i);j||(i.seq_id=-1,i.cell||(i.cell=new Float32Array(a.cellsize)),i.args||(i.args=[]),a.fn.arrayset(i.args),i.hasOwnProperty("_")||(i._={}),i._.proto=n,i._.isUndefined=!!k,i._.id=h.objectId++,typeof i._.ev!="object"&&(i._.ev={}),typeof i._.buddies!="object"&&(i._.buddies={}),typeof i._.ar!="boolean"&&(n&&typeof n._=="object"?i._.ar=!!n._.ar:i._.ar=!1),typeof i._.ison!="boolean"&&(i._.ison=!0),typeof i._.mul!="number"&&(i._.mul=1),typeof i._.add!="number"&&(i._.add=0),typeof i._.dac!="object"&&(i._.dac=null)),n._.init instanceof Function&&n._.init.call(i);return i},b.register=function(a,d,e){if(typeof a=="string"){if(d instanceof Function){var f=d.prototype,g=h.prototype,j=new h.PrototypeValue;if(typeof f._=="object")for(var k in f._)j[k]=f._[k];f._=j;if(!(f instanceof h)){for(var k in g)typeof g[k]=="function"&&(f[k]instanceof Function||(f[k]=g[k]));for(var k in i)Object.getOwnPropertyDescriptor(f,k)===undefined&&Object.defineProperty(f,k,i[k])}typeof f.ar!="function"&&b.setPrototypeOf.call(f,"ar-kr");for(var l in f)f.hasOwnProperty(l)&&f[l]instanceof Function&&g[l]===undefined&&(g[l]=c)}e instanceof Function?h.klasses[a]=e:(f._.klassname=a,f._.klass=d,h.klasses[a]=d)}},h.dac={on:function(){var b;this._.ison=!0,a.dacs.append(this),(b=this._.proto._.on)&&b.call(this),a.fn.doEvent(this,"on");return this},off:function(){var b;this._.ison=!1,a.dacs.remove(this),(b=this._.proto._.off)&&b.call(this),a.fn.doEvent(this,"off");return this},play:function(){var b;this._.ison=!0,a.dacs.append(this),(b=this._.proto._.play)&&b.call(this),a.fn.doEvent(this,"play");return this},pause:function(){var b;this._.ison=!1,a.dacs.remove(this),(b=this._.proto._.pause)&&b.call(this),a.fn.doEvent(this,"pause");return this}},h.timer={on:function(){var b;this._.ison=!0,a.timers.append(this),(b=this._.proto._.on)&&b.call(this),a.fn.doEvent(this,"on");return this},off:function(){var b;this._.ison=!1,a.timers.remove(this),(b=this._.proto._.off)&&b.call(this),a.fn.doEvent(this,"off");return this},play:function(){var b;(b=this._.proto._.play)&&b.call(this),a.fn.doEvent(this,"play");return this},pause:function(){var b;(b=this._.proto._.pause)&&b.call(this),a.fn.doEvent(this,"pause");return this}},h.listener={listen:function(c){c===null?(this._.args&&(this.args=this._.args),a.listeners.remove(this)):b.isTimbreObject(c)&&(this._.args=this.args,this.args.removeAll(),this.args.append(c),a.listeners.append(this));return this}},b.setPrototypeOf=function(a){this._||(this._={});switch(a){case"ar-only":case"ar":this.ar=this.kr=c,this._.ar=!0;break;case"kr-only":case"kr":this.ar=this.kr=c,this._.ar=!1;break;case"kr-ar":case"kr->ar":this._.ar=!1;break;case"ar-kr":case"ar->kr":this._.ar=!0;break;case"dac":this.on=h.dac.on,this.off=h.dac.off,this.play=h.dac.play,this.pause=h.dac.pause,this._.type=1;break;case"timer":this.on=h.timer.on,this.off=h.timer.off,this.play=h.timer.play,this.pause=h.timer.pause,this._.type=2;break;case"listener":this.listen=h.listener.listen,this._.type=3}return this},b.valist=function(b){return b instanceof Array?b.map(a):Array.prototype.map.call(b,a)},b.arrayset=function(){var a=function(){var a=b.valist(arguments);for(var c=0,d=a.length;c0)this.pop();return this},e=function(){this.append.apply(this,list);return this};return function(b){var f=[];for(var g=1,h=b.length;g0)if(b.ar){c=i[0].seq(a);for(f=g=h.length;f--;)h[f]=c[f];for(d=1,e=i.length;d0)if(b.ar){c=j[0].seq(a);for(g=h=i.length;g--;)i[g]=c[g];for(e=1,f=j.length;e0)if(b.ar){c=j[0].seq(a);for(g=h=i.length;g--;)i[g]=c[g];for(e=1,f=j.length;e=1)a-=1;while(a<0)a+=1;this._.phase=a,this._.x=1024*this._.phase}},get:function(){return this._.phase}}}}),d=function(a){var c=this._={};c.wave=new Float32Array(1024),c.phase=0,c.x=0,c.coeff=1024/b.samplerate;var d=0;this.wave="sin",typeof a[d]=="function"?this.wave=a[d++]:a[d]instanceof Float32Array?this.wave=a[d++]:typeof a[d]=="string"&&(this.wave=a[d++]),a[d]!==undefined?this.freq=a[d++]:this.freq=440,typeof a[d]=="number"&&(c.mul=a[d++]),typeof a[d]=="number"&&(c.add=a[d++])};c.clone=function(a){var c=this._,d=b("osc",c.wave);a?d._.freq=c.freq.clone(!0):d._.freq=c.freq,d._.phase=c.phase;return b.fn.copyBaseArguments(this,d,a)},c.bang=function(){var a=this._;a.x=1024*a.phase,b.fn.doEvent(this,"bang");return this},c.seq=function(a){var c=this._,d,e,f,g,h,i,j;if(!c.ison)return b._.none;var k=this.cell;if(a!==this.seq_id){this.seq_id=a;var l=c.freq.seq(a),m=c.mul,n=c.add,o=c.wave,p=c.x,q=c.coeff;if(c.ar)if(c.freq.isAr)for(i=0,j=k.length;i1024)p-=1024;c.x=p}return k};var e=function(a,b){var c,d;switch(a){case"@1":for(c=512;c<1024;++c)b[c]=0;break;case"@2":for(c=512;c<1024;++c)b[c]=Math.abs(b[c]);break;case"@3":for(c=256;c<512;++c)b[c]=0;for(c=512;c<768;++c)b[c]=Math.abs(b[c]);for(c=768;c<1024;++c)b[c]=0;break;case"@4":d=new Float32Array(1024);for(c=0;c<512;++c)d[c]=b[c<<1];b=d;break;case"@5":d=new Float32Array(1024);for(c=0;c<512;++c)d[c]=Math.abs(b[c<<1]);b=d}return b},f=function(a,b){if(a!==undefined){a*=.01,a=a<0?0:a>1?1:a;var c=new Float32Array(1024),d=1024*a|0,e=0,f=a>0?.5/a:0,g,h,i,j;for(var k=0;k<1024;++k)g=e|0,h=e-g,i=b[g&1023],j=b[g+1&1023],c[k]=(1-h)*i+h*j,k===d&&(e=512,f=a<1?.5/(1-a):0),e+=f;b=c}return b};c.getWavetable=function(c){var d,g=a.Wavetables[c];if(g!==undefined){g instanceof Function&&(g=g());return g}d=/^([-+]?)(\w+)(?:\((@[0-7])?:?(\d+\.?\d*)?\))?$/.exec(c);if(d!==null){var h=d[1],i=d[2],j=d[3],k=d[4];g=a.Wavetables[i];if(g!==undefined){g=g instanceof Function?g():g,g=e(j,g),g=f(k,g);if(h==="+")for(var l=1024;l--;)g[l]=g[l]*.5+.5;else if(h==="-")for(var l=1024;l--;)g[l]*=-1;return a.Wavetables[c]=g}}d=/^wavb\(((?:[0-9a-fA-F][0-9a-fA-F])+)\)$/.exec(c);if(d!==null){g=b.utils.wavb(d[1]);return a.Wavetables[c]=g}d=/^wavc\(([0-9a-fA-F]{8})\)$/.exec(c);if(d!==null){g=b.utils.wavc(d[1]);return a.Wavetables[c]=g}},c.setWavetable=function(b,c){if(typeof c=="function"){var d=new Float32Array(1024);for(var e=0;e<1024;e++)d[e]=c(e/1024);a.Wavetables[b]=d}else if(typeof c=="object"&&(c instanceof Array||c.buffer instanceof ArrayBuffer))if(c.length===1024)a.Wavetables[b]=c;else{var d=new Float32Array(1024),f=c.length/1024;for(var e=0;e<1024;e++)d[e]=c[e*f|0]||0;a.Wavetables[b]=c}};return a}();b.fn.register("osc",p),p.Wavetables={sin:function(){var a=new Float32Array(1024);for(var b=1024;b--;)a[b]=Math.sin(2*Math.PI*(b/1024));return a},cos:function(){var a=new Float32Array(1024);for(var b=1024;b--;)a[b]=Math.cos(2*Math + * timbre.js v12.12.12 / JavaScript Library for Objective Sound Programming + */var timbre=function(a,b){"use strict";var b=function(){return b.fn.init.apply(b,arguments)};b.VERSION="v12.12.12",b.env="",b.platform="",b.samplerate=0,b.channels=2,b.cellsize=128,b.streamsize=1024,b.dacs=[],b.timers=[],b.listeners=[],b.sys=null,b.context={},b.utils={},b._={ev:{},amp:.8,autorun:!0,verbose:!0,workerpath:"",none:new Float32Array(b.cellsize)},Object.defineProperties(b,{amp:{set:function(a){typeof a=="number"&&(b._.amp=a)},get:function(){return b._.amp}},autorun:{set:function(a){b._.autorun=!!a},get:function(){return b._.autorun}},workerpath:{set:function(a){typeof a=="string"&&(b._.workerpath=a)},get:function(){return b._.workerpath}},verbose:{set:function(a){b._.verbose=!!a},get:function(){return b._.verbose}},isOn:{get:function(){return b.sys._.ison}},isOff:{get:function(){return!b.sys._.ison}}}),b.setup=function(a){Object.isFrozen(b)?b._.verbose&&a&&console.warn("timbre is already configured."):(typeof a=="object"&&(typeof a.samplerate=="number"&&(b.samplerate=a.samplerate),typeof a.channels=="number"&&(b.channels=a.channels),typeof a.cellsize=="number"&&(b.cellsize=a.cellsize),typeof a.streamsize=="number"&&(b.cellsize=a.streamsize)),b.sys.setup(),b._.none=new Float32Array(b.cellsize),Object.freeze(b));return b},b.on=function(){b.sys._.ison||(b.setup(),b.sys.on(),b.fn.doEvent(this,"on"));return b},b.off=function(){b.sys._.ison&&(b.sys.off(),b.fn.doEvent(this,"off"));return b},b.addEventListener=function(a,b){if(typeof b=="function"){a[0]==="~"&&(a=a.substr(1),b.rm=!0);var c,d=this._.ev[a];d===undefined&&(this._.ev[a]=d=[]),(c=d.indexOf(b))===-1&&d.push(b)}return this},b.removeEventListener=function(a,b){if(typeof a=="string"&&a!==""){var c,d=this._.ev[a];d!==undefined&&(c=d.indexOf(b))!==-1&&d.splice(c,1)}return this},b.removeAllEventListeners=function(a){typeof a=="string"&&a!==""&&(delete this._.ev[a],delete this["on"+a]);return this},function(){var a=function(){var a=b.fn.valist(arguments);for(var c=0,d=a.length,e=!1;c0)this.pop();b._.autorun&&b.dacs.length===0&&b.timers.length===0&&b.off();return this};for(var e,f=arguments.length;f--;)e=arguments[f],e.append=a,e.remove=c,e.removeAll=d}(b.dacs,b.timers,b.listeners),b.dacs.type=1,b.timers.type=2,b.listeners.type=3,b.fn=function(a){var b={},c=function(){return this},h=function(){};h.objectId=0,h.klasses={_find:function(b){if(typeof h.klasses[b]=="function")return h.klasses[b];b="-"+a.env+"-"+b;if(typeof h.klasses[b]=="function")return h.klasses[b]}},h.PrototypeValue=function(){},a.TimbreBasePrototype=h.prototype={play:function(){var b,c=this._;c.ar&&(c.dac===null?(c.dac=a("dac",this),(b=c.proto._.play)instanceof Function&&b.call(this),a.fn.doEvent(this,"play")):this.dac.args.indexOf(this)===-1&&(c.dac.append(this),(b=c.proto._.play)instanceof Function&&b.call(this),a.fn.doEvent(this,"play")),c.dac.isOff&&c.dac.on());return this},pause:function(){var b,c=this._;c.dac&&c.dac.args.indexOf(this)!==-1&&(c.dac.remove(this),(b=c.proto._.pause)instanceof Function&&b.call(this),a.fn.doEvent(this,"pause"),c.dac.isOn&&c.dac.args.length===0&&c.dac.off());return this},ar:function(){this._.ar=!0;return this},kr:function(){this._.ar=!1;return this},bang:function(){a.fn.doEvent(this,"bang");return this},seq:function(){return this.cell},on:function(){var b;this._.ison=!0,(b=this._.proto._.on)instanceof Function&&b.call(this),a.fn.doEvent(this,"on");return this},off:function(){var b;this._.ison=!1,(b=this._.proto._.off)instanceof Function&&b.call(this),a.fn.doEvent(this,"off");return this},clone:function(b){var c=a(this._.proto._.klassname);a.fn.copyBaseArguments(this,c,b);return c},buddy:function(a,b,c){var d=this._.buddies;typeof a=="string"&&(a=[a]);if(a instanceof Array)for(var e=a.length,f;e--;)typeof (f=a[e])=="string"&&(b===null?delete d[f]:b===undefined?d[f]=[this.args,c]:b instanceof Array?d[f]=[b,c]:b instanceof Function?d[f]=[[b],c]:b instanceof h&&(d[f]=[[b],c]));return this},append:function(){var a;this.args.append.apply(this.args,arguments),(a=this._.proto._.append)instanceof Function&&a.call(this);return this},appendTo:function(a){a.args.append.call(a.args,this);return this},remove:function(){var a;this.args.remove.apply(this.args,arguments),(a=this._.proto._.remove)instanceof Function&&a.call(this);return this},removeFrom:function(a){a.args.remove.call(a.args,this);return this},removeAll:function(){var a;this.args.removeAll.apply(this.args,arguments),(a=this._.proto._.remove)instanceof Function&&a.call(this);return this},set:function(a,b){var c=Object.getOwnPropertyDescriptor;if(typeof a=="string"){var d=this._.proto;while(d!==null){if(c(d,a)!==undefined){this[a]=b;break}d=Object.getPrototypeOf(d)}}else if(typeof a=="object")for(var e in a){var d=this._.proto;while(d!==null){if(c(d,e)!==undefined){this[e]=a[e];break}d=Object.getPrototypeOf(d)}}return this},get:function(a){var b=Object.getOwnPropertyDescriptor,c=this._.proto;while(c!==null){if(b(c,a)!==undefined)return this[a];c=Object.getPrototypeOf(c)}},addEventListener:a.addEventListener,removeEventListener:a.removeEventListener,removeAllEventListeners:a.removeAllEventListeners};var i={isAr:{get:function(){return!!this._.ar}},isKr:{get:function(){return!this._.ar}},isOn:{get:function(){return!!this._.ison}},isOff:{get:function(){return!this._.ison}},isUndefined:{get:function(){return this._.isUndefined}},scalar:{get:function(){a.sys.seq_id!==this.seq_id&&this.seq(a.sys.seq_id);return this.cell[0]}},dac:{set:function(a){a!==this._.dac&&(this._.dac!==null&&this._.dac.remove(this),a!==null?this._.dac=a.append(this):this._.dac=null)},get:function(){return this._.dac}},mul:{set:function(a){typeof a=="number"&&(this._.mul=a)},get:function(){return this._.mul}},add:{set:function(a){typeof a=="number"&&(this._.add=a)},get:function(){return this._.add}}};Object.defineProperties(h.prototype,i),b.init=function(){h.objectId===0&&a.setup();var c,i,j,k,l=Array.prototype.slice.call(arguments),m=l[0];switch(typeof m){case"string":(c=h.klasses._find(m))!==undefined&&(i=new c(l.slice(1)));break;case"number":i=new d([m]);break;case"boolean":i=new e([m]);break;case"function":i=new g(l);break;case"object":m===null?i=new d([0]):b.isTimbreObject(m)?(i=m,j=!0):m instanceof Array&&(i=new f([m]))}i===undefined&&(i=new d([0]),k=!0,a._.verbose&&console.warn("'"+m+"' is not defined."));var n=Object.getPrototypeOf(i);j||(i.seq_id=-1,i.cell||(i.cell=new Float32Array(a.cellsize)),i.args||(i.args=[]),a.fn.arrayset(i.args),i.hasOwnProperty("_")||(i._={}),i._.proto=n,i._.isUndefined=!!k,i._.id=h.objectId++,typeof i._.ev!="object"&&(i._.ev={}),typeof i._.buddies!="object"&&(i._.buddies={}),typeof i._.ar!="boolean"&&(n&&typeof n._=="object"?i._.ar=!!n._.ar:i._.ar=!1),typeof i._.ison!="boolean"&&(i._.ison=!0),typeof i._.mul!="number"&&(i._.mul=1),typeof i._.add!="number"&&(i._.add=0),typeof i._.dac!="object"&&(i._.dac=null)),n._.init instanceof Function&&n._.init.call(i);return i},b.register=function(a,d,e){if(typeof a=="string"){if(d instanceof Function){var f=d.prototype,g=h.prototype,j=new h.PrototypeValue;if(typeof f._=="object")for(var k in f._)j[k]=f._[k];f._=j;if(!(f instanceof h)){for(var k in g)typeof g[k]=="function"&&(f[k]instanceof Function||(f[k]=g[k]));for(var k in i)Object.getOwnPropertyDescriptor(f,k)===undefined&&Object.defineProperty(f,k,i[k])}typeof f.ar!="function"&&b.setPrototypeOf.call(f,"ar-kr");for(var l in f)f.hasOwnProperty(l)&&f[l]instanceof Function&&g[l]===undefined&&(g[l]=c)}e instanceof Function?h.klasses[a]=e:(f._.klassname=a,f._.klass=d,h.klasses[a]=d)}},h.dac={on:function(){var b;this._.ison=!0,a.dacs.append(this),(b=this._.proto._.on)&&b.call(this),a.fn.doEvent(this,"on");return this},off:function(){var b;this._.ison=!1,a.dacs.remove(this),(b=this._.proto._.off)&&b.call(this),a.fn.doEvent(this,"off");return this},play:function(){var b;this._.ison=!0,a.dacs.append(this),(b=this._.proto._.play)&&b.call(this),a.fn.doEvent(this,"play");return this},pause:function(){var b;this._.ison=!1,a.dacs.remove(this),(b=this._.proto._.pause)&&b.call(this),a.fn.doEvent(this,"pause");return this}},h.timer={on:function(){var b;this._.ison=!0,a.timers.append(this),(b=this._.proto._.on)&&b.call(this),a.fn.doEvent(this,"on");return this},off:function(){var b;this._.ison=!1,a.timers.remove(this),(b=this._.proto._.off)&&b.call(this),a.fn.doEvent(this,"off");return this},play:function(){var b;(b=this._.proto._.play)&&b.call(this),a.fn.doEvent(this,"play");return this},pause:function(){var b;(b=this._.proto._.pause)&&b.call(this),a.fn.doEvent(this,"pause");return this}},h.listener={listen:function(c){c===null?(this._.args&&(this.args=this._.args),a.listeners.remove(this)):b.isTimbreObject(c)&&(this._.args=this.args,this.args.removeAll(),this.args.append(c),a.listeners.append(this));return this}},b.setPrototypeOf=function(a){this._||(this._={});switch(a){case"ar-only":case"ar":this.ar=this.kr=c,this._.ar=!0;break;case"kr-only":case"kr":this.ar=this.kr=c,this._.ar=!1;break;case"kr-ar":case"kr->ar":this._.ar=!1;break;case"ar-kr":case"ar->kr":this._.ar=!0;break;case"dac":this.on=h.dac.on,this.off=h.dac.off,this.play=h.dac.play,this.pause=h.dac.pause,this._.type=1;break;case"timer":this.on=h.timer.on,this.off=h.timer.off,this.play=h.timer.play,this.pause=h.timer.pause,this._.type=2;break;case"listener":this.listen=h.listener.listen,this._.type=3}return this},b.valist=function(b){return b instanceof Array?b.map(a):Array.prototype.map.call(b,a)},b.arrayset=function(){var a=function(){var a=b.valist(arguments);for(var c=0,d=a.length;c0)this.pop();return this},e=function(){this.append.apply(this,list);return this};return function(b){var f=[];for(var g=1,h=b.length;g0)if(b.ar){c=i[0].seq(a);for(f=g=h.length;f--;)h[f]=c[f];for(d=1,e=i.length;d0)if(b.ar){c=j[0].seq(a);for(g=h=i.length;g--;)i[g]=c[g];for(e=1,f=j.length;e0)if(b.ar){c=j[0].seq(a);for(g=h=i.length;g--;)i[g]=c[g];for(e=1,f=j.length;e=1)a-=1;while(a<0)a+=1;this._.phase=a,this._.x=1024*this._.phase}},get:function(){return this._.phase}}}}),d=function(a){var c=this._={};c.wave=new Float32Array(1024),c.phase=0,c.x=0,c.coeff=1024/b.samplerate;var d=0;this.wave="sin",typeof a[d]=="function"?this.wave=a[d++]:a[d]instanceof Float32Array?this.wave=a[d++]:typeof a[d]=="string"&&(this.wave=a[d++]),a[d]!==undefined?this.freq=a[d++]:this.freq=440,typeof a[d]=="number"&&(c.mul=a[d++]),typeof a[d]=="number"&&(c.add=a[d++])};c.clone=function(a){var c=this._,d=b("osc",c.wave);a?d._.freq=c.freq.clone(!0):d._.freq=c.freq,d._.phase=c.phase;return b.fn.copyBaseArguments(this,d,a)},c.bang=function(){var a=this._;a.x=1024*a.phase,b.fn.doEvent(this,"bang");return this},c.seq=function(a){var c=this._,d,e,f,g,h,i,j;if(!c.ison)return b._.none;var k=this.cell;if(a!==this.seq_id){this.seq_id=a;var l=c.freq.seq(a),m=c.mul,n=c.add,o=c.wave,p=c.x,q=c.coeff;if(c.ar)if(c.freq.isAr)for(i=0,j=k.length;i1024)p-=1024;c.x=p}return k};var e=function(a,b){var c,d;switch(a){case"@1":for(c=512;c<1024;++c)b[c]=0;break;case"@2":for(c=512;c<1024;++c)b[c]=Math.abs(b[c]);break;case"@3":for(c=256;c<512;++c)b[c]=0;for(c=512;c<768;++c)b[c]=Math.abs(b[c]);for(c=768;c<1024;++c)b[c]=0;break;case"@4":d=new Float32Array(1024);for(c=0;c<512;++c)d[c]=b[c<<1];b=d;break;case"@5":d=new Float32Array(1024);for(c=0;c<512;++c)d[c]=Math.abs(b[c<<1]);b=d}return b},f=function(a,b){if(a!==undefined){a*=.01,a=a<0?0:a>1?1:a;var c=new Float32Array(1024),d=1024*a|0,e=0,f=a>0?.5/a:0,g,h,i,j;for(var k=0;k<1024;++k)g=e|0,h=e-g,i=b[g&1023],j=b[g+1&1023],c[k]=(1-h)*i+h*j,k===d&&(e=512,f=a<1?.5/(1-a):0),e+=f;b=c}return b};c.getWavetable=function(c){var d,g=a.Wavetables[c];if(g!==undefined){g instanceof Function&&(g=g());return g}d=/^([-+]?)(\w+)(?:\((@[0-7])?:?(\d+\.?\d*)?\))?$/.exec(c);if(d!==null){var h=d[1],i=d[2],j=d[3],k=d[4];g=a.Wavetables[i];if(g!==undefined){g=g instanceof Function?g():g,g=e(j,g),g=f(k,g);if(h==="+")for(var l=1024;l--;)g[l]=g[l]*.5+.5;else if(h==="-")for(var l=1024;l--;)g[l]*=-1;return a.Wavetables[c]=g}}d=/^wavb\(((?:[0-9a-fA-F][0-9a-fA-F])+)\)$/.exec(c);if(d!==null){g=b.utils.wavb(d[1]);return a.Wavetables[c]=g}d=/^wavc\(([0-9a-fA-F]{8})\)$/.exec(c);if(d!==null){g=b.utils.wavc(d[1]);return a.Wavetables[c]=g}},c.setWavetable=function(b,c){if(typeof c=="function"){var d=new Float32Array(1024);for(var e=0;e<1024;e++)d[e]=c(e/1024);a.Wavetables[b]=d}else if(typeof c=="object"&&(c instanceof Array||c.buffer instanceof ArrayBuffer))if(c.length===1024)a.Wavetables[b]=c;else{var d=new Float32Array(1024),f=c.length/1024;for(var e=0;e<1024;e++)d[e]=c[e*f|0]||0;a.Wavetables[b]=c}};return a}();b.fn.register("osc",p),p.Wavetables={sin:function(){var a=new Float32Array(1024);for(var b=1024;b--;)a[b]=Math.sin(2*Math.PI*(b/1024));return a},cos:function(){var a=new Float32Array(1024);for(var b=1024;b--;)a[b]=Math.cos(2*Math .PI*(b/1024));return a},pulse:function(){var a=new Float32Array(1024);for(var b=1024;b--;)a[b]=b<512?1:-1;return a},tri:function(){var a=new Float32Array(1024);for(var b,c=1024;c--;)b=c/1024-.25,a[c]=1-4*Math.abs(Math.round(b)-b);return a},sawup:function(){var a=new Float32Array(1024);for(var b,c=1024;c--;)b=c/1024,a[c]=2*(b-Math.round(b));return a},sawdown:function(){var a=new Float32Array(1024);for(var b,c=1024;c--;)b=c/1024,a[c]=-2*(b-Math.round(b));return a},fami:function(){var a=[0,.125,.25,.375,.5,.625,.75,.875,.875,.75,.625,.5,.375,.25,.125,0,-0.125,-0.25,-0.375,-0.5,-0.625,-0.75,-0.875,-1,-1,-0.875,-0.75,-0.625,-0.5,-0.375,-0.25,-0.125],b=new Float32Array(1024);for(var c=1024;c--;)b[c]=a[c/1024*a.length|0];return b},konami:function(){var a=[-0.625,-0.875,-0.125,.75,.5,.125,.5,.75,.25,-0.125,.5,.875,.625,0,.25,.375,-0.125,-0.75,0,.625,.125,-0.5,-0.375,-0.125,-0.75,-1,-0.625,0,-0.375,-0.875,-0.625,-0.25],b=new Float32Array(1024);for(var c=1024;c--;)b[c]=a[c/1024*a.length|0];return b}},p.Wavetables.saw=p.Wavetables.sawup,b.fn.register("sin",p,function(a){return new p(["sin"].concat(a))}),b.fn.register("cos",p,function(a){return new p(["cos"].concat(a))}),b.fn.register("pulse",p,function(a){return new p(["pulse"].concat(a))}),b.fn.register("tri",p,function(a){return new p(["tri"].concat(a))}),b.fn.register("saw",p,function(a){return new p(["saw"].concat(a))}),b.fn.register("fami",p,function(a){return new p(["fami"].concat(a))}),b.fn.register("konami",p,function(a){return new p(["konami"].concat(a))}),b.fn.register("+sin",p,function(a){return(new p(["+sin"].concat(a))).kr()}),b.fn.register("+cos",p,function(a){return(new p(["+cos"].concat(a))).kr()}),b.fn.register("+pulse",p,function(a){return(new p(["+pulse"].concat(a))).kr()}),b.fn.register("+tri",p,function(a){return(new p(["+tri"].concat(a))).kr()}),b.fn.register("+saw",p,function(a){return(new p(["+saw"].concat(a))).kr()});var q=function(){var a=function(){e.apply(this,arguments)},c=b.fn.buildPrototype(a,{base:"ar-kr",properties:{func:{set:function(a){typeof a=="function"&&(this._.func=a)},get:function(){return this._.func}},numOfSamples:{set:function(a){typeof a=="number"&&(this._.saved=new Float32Array(a),this._.numOfSamples=a)},get:function(){return this._.numOfSamples}},freq:{set:function(a){this._.freq=b(a)},get:function(){return this._.freq}},phase:{set:function(a){if(typeof a=="number"){while(a>=1)a-=1;while(a<0)a+=1;this._.phase=this._.x=a}},get:function(){return this._.phase}}}}),d=function(a){return a},e=function(a){var c,e,f;this._=f={},e=0,typeof a[e]=="number"&&a[e]>0?f.numOfSamples=a[e++]|0:f.numOfSamples=0,typeof a[e]=="function"?f.func=a[e++]:f.func=d,typeof a[e]!="undefined"?this.freq=a[e++]:this.freq=440,f.saved=new Float32Array(f.numOfSamples),f.index=0,f.phase=f.x=0,f.coeff=1/b.samplerate};c.clone=function(a){var c,d=this._;c=b("func",d.func,null,d.numOfSamples),a?c._.freq=d.freq.clone(!0):c._.freq=d.freq,c._.phase=d.phase;return b.fn.copyBaseArguments(this,c,a)},c.bang=function(){this._.x=this._.phase,b.fn.doEvent(this,"bang");return this},c.seq=function(a){var c=this._,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r;if(!c.ison)return b._.none;d=this.cell;if(this.seq_id!==a){this.seq_id=a,e=c.func,f=c.freq.seq(a),g=c.x,h=c.coeff,i=c.mul,j=c.add,k=c.saved,p=c.index,q=k.length;for(n=0,o=d.length;n=q){m=e(g,f[n]*h);if(q!==0)for(r=m.length;r--;)k[r]=m[r]||0;p=0}d[n]=k[p]*i+j}g+=f[n]*h;while(g>=1)g-=1}c.index=p,c.x=g}return d};return a}();b.fn.register("func",q);var r=function(){var a=function(){d.apply(this,arguments)},c=b.fn.buildPrototype(a,{base:"ar-kr"}),d=function(a){var b=this._={},c=0;typeof a[c]=="number"&&(b.mul=a[c++])};c.clone=function(a){return b.fn.copyBaseArguments(this,b("noise"),a)},c.seq=function(a){var c=this._;if(!c.ison)return b._.none;var d=this.cell;if(a!==this.seq_id){this.seq_id=a;var e=c.mul,f=c.add;if(c.ar){var g=Math.random;for(var h=d.length;h--;)d[h]=(g()*2-1)*e+f}else{var i=(Math.random()*2-1)*e+f;for(var h=d.length;h--;)d[h]=i}}return d};return a}();b.fn.register("noise",r);var s=function(){var a=function(){d.apply(this,arguments)},c=b.fn.buildPrototype(a,{base:"ar-kr"}),d=function(a){var b=this._={};b.b0=0,b.b1=0,b.b2=0;var c=0;typeof a[c]=="number"&&(b.mul=a[c++])};c.clone=function(a){return b.fn.copyBaseArguments(this,b("pink"),a)},c.seq=function(a){var c=this._;if(!c.ison)return b._.none;var d=this.cell;if(a!==this.seq_id){this.seq_id=a;var e=c.b0,f=c.b1,g=c.b2,h=c.mul,i=c.add,j=Math.random;for(var k=d.length;k--;){var l=j()*2-1;e=.99765*e+l*.099046,f=.963*f+l*.2965164,g=.57*g+l*1.0526913,l=e+f+g+l*.1848,d[k]=l*h+i}c.b0=e,c.b1=f,c.b2=g;if(!c.ar)for(k=d.length;k--;)d[k]=d[0]}return d};return a}();b.fn.register("pink",s);var t=function(){var a=function(){e.apply(this,arguments)},c=b.fn.buildPrototype(a,{base:"ar-kr",properties:{phase:{set:function(a){this._.phase=b(a)},get:function(){return this._.phase}},fb:{set:function(a){typeof a=="number"&&(this._.fb=a)},get:function(){return this._.fb}}},copies:["osc.wave","osc.getWavetable()","osc.setWavetable()"]}),d=b.fn.getClass("osc"),e=function(a){var b=this._={};b.wave=new Float32Array(1024),b.px=0,b.fb=0;var c=0;this.wave="sin",typeof a[c]=="function"?this.wave=a[c++]:a[c]instanceof Float32Array?this.wave=a[c++]:typeof a[c]=="string"&&(this.wave=a[c++]),a[c]!==undefined?this.phase=a[c++]:this.phase=0,typeof a[c]=="number"&&(b.mul=a[c++]),typeof a[c]=="number"&&(b.add=a[c++])};c.clone=function(a){var c=this._,d=T("oscx",c.wave);a?d._.phase=c.phase.clone(!0):d._.phase=c.phase,d._.fb=c.fb;return b.fn.copyBaseArguments(this,d,a)},c.bang=function(){this._.phase.bang(),b.fn.doEvent(this,"bang");return this},c.seq=function(a){var c=this._,d,e,f,g,h,i,j;if(!c.ison)return b._.none;var k=this.cell;if(a!==this.seq_id){this.seq_id=a;var l=c.phase.seq(a),m=c.fb,n=c.mul,o=c.add,p=c.wave,q=c.px;if(c.ar&&c.phase.isAr){for(i=0,j=b.cellsize;i=0&&(this._.fmul=a)},get:function(){return this._.fmul}},phase:{set:function(a){if(typeof a=="number"){while(a>=1)a-=1;while(a<0)a+=1;this._.phase=this._.x=a}},get:function(){return this._.phase}}}}),d=function(a){var c,d;this._=d={},c=0,typeof a[c]!="undefined"?this.freq=a[c++]:this.freq=440,d.fmul=typeof a[c]=="number"?a[c++]:1,d.phase=typeof a[c]=="number"?a[c++]:0,d.fmul<0&&(d.fmul=0),this.phase=d.phase,d.x=d.phase,d.coeff=1/b.samplerate};c.clone=function(a){var c,d=this._;c=T("phasor"),a?c._.freq=d.freq.clone(!0):c._.freq=d.freq,c._.fmul=d.fmul,c._.phase=d.phase;return b.fn.copyBaseArguments(this,c,a)},c.bang=function(){this._.x=this._.phase,b.fn.doEvent(this,"bang");return this},c.seq=function(a){var c=this._,d,e,f,g,h,i,j,k,l,m;if(!c.ison)return b._.none;d=this.cell;if(a!==this.seq_id){this.seq_id=a,e=c.freq.seq(a),f=c.mul,g=c.add,h=c.x,j=c.coeff*c.fmul;if(c.ar)if(c.freq.isAr)for(l=0,m=b.cellsize;l1)h-=1}else{i=e[0]*j;for(l=0,m=b.cellsize;l1)h-=1}}else{k=c.x*c.mul+g;for(l=0,m=b.cellsize;l1)h-=1}c.x=h}return d};return a}();b.fn.register("phasor",u);var v=function(){var a=function(){d.apply(this,arguments)},c=b.fn.buildPrototype(a,{base:"ar-kr",properties:{width:{set:function(a){this._.width=b(a)},get:function(){return this._.width}},freq:{set:function(a){this._.freq=b(a)},get:function(){return this._.freq}}}}),d=function(a){var c=this._={};c.x=0,c.coeff=1/b.samplerate;var d=0;typeof a[d]!="undefined"?this.width=a[d++]:this.width=.5,typeof a[d]!="undefined"?this.freq=a[d++]:this.freq=440,typeof a[d]=="number"&&(c.mul=a[d++]),typeof a[d]=="number"&&(c.add=a[d++])};c.clone=function(a){var c=this._,d=T("pwm");a?(d._.width=c.width.clone(!0),d._.freq=c.freq.clone(!0)):(d._.width=c.width,d._.freq=c.freq);return b.fn.copyBaseArguments(this,d,a)},c.bang=function(){this._.x=0,b.fn.doEvent(this,"bang");return this},c.seq=function(a){var c=this._;if(!c.ison)return b._.none;var d=this.cell;if(a!==this.seq_id){this.seq_id=a;var e=c.width.seq(a)[0],f=c.freq.seq(a),g=c.mul,h=c.add,i=c.x,j=c.coeff;if(c.ar)if(c.freq.isAr)for(var k=0,l=b.cellsize;k1)i-=1}else{var m=f[0]*j;for(var k=0,l=b.cellsize;k1)i-=1}}else{var n=(c.x1)i-=1}c.x=i}return d};return a}();b.fn.register("pwm",v),b.fn.register("pwm125",v,function(a){return new v([.125].concat(a))}),b.fn.register("pwm25",v,function(a){return new v([.25].concat(a))}),b.fn.register("pwm50",v,function(a){return new v([.5].concat(a))});var w=function(){var a=function(){d.apply(this,arguments)},c=b.fn.buildPrototype(a,{base:"ar-kr",properties:{freq:{set:function(a){this._.freq=b(a)},get:function(){return this._.freq}}}}),d=function(a){var b=this._={};b.x=0,b.y=1;var c=0;typeof a[c]!="undefined"?this.freq=a[c++]:this.freq=440,typeof a[c]=="number"&&(b.mul=a[c++])};c.clone=function(a){var c=this._,d=b("8bitnoise");a?d._.freq=c.freq.clone(!0):d._.freq=c.freq;return b.fn.copyBaseArguments(this,d,a)},c.bang=function(){var a=this._;a.x=0,a.y=1,b.fn.doEvent(this,"bang");return this},c.seq=function(a){var c=this._;if(!c.ison)return b._.none;var d=this.cell;if(a!==this.seq_id){this.seq_id=a;var e=c.freq.seq(a)[0],f=c.x,g=c.y,h=c.mul,i=c.add,j=e/b.samplerate,k=Math.random;for(var l=0,m=d.length;l=.25){g=k()*2-1;do f-=.25;while(f>=.25)}d[l]=g*h+i,f+=j}c.x=f,c.y=g;if(!c.ar)for(l=m;l--;)d[l]=d[0]}return d};return a}();b.fn.register("fnoise",w);var x=function(){var a=function(){d.apply(this,arguments)},c=b.fn.buildPrototype(a,{base:"kr-ar",properties:{table:{set:function(b){var c,d,e=this._;typeof b=="string"&&(b==="~"?(d=e.tableName,d.charAt(0)==="~"?d=d.substr(1):d="~"+d):d=b,(c=a.AmpTables[d])!==undefined&&(typeof c=="function"&&(c=c()),e.tableName=d,e.table=c))},get:function(){return this._.tableName}},delay:{set:function(a){typeof a=="number"&&(this._.delay=a)},get:function(){return this._.delay}},reversed:{set:function(a){this._.reversed=!!a},get:function(){return this._.reversed}},currentTime:{get:function(){return this._.currentTime}}}}),d=function(a){var b=this._={};b.changeState=function(){}};c.seq=function(a){var c=this._;if(!c.ison)return b._.none;var d=this.cell;if(a!==this.seq_id){this.seq_id=a,c.changeState.call(this);var e=c.table,f=c.mul,g=c.add,h,i=d.length,j=c.x0;j>.999&&(j=.999);var k=j+c.dx;k>.999&&(k=.999),j=e[j*512|0],k=e[k*512|0],c.reversed&&(j=1-j,k=1-k);if(c.ar){var l=(k-j)/i;for(h=0;h0?c.delay===Infinity?(c.samples=Infinity,c.dx=0):(c.samples=b.samplerate*(c.delay/1e3)|0,c.dx=b.cellsize*(c.al-c.rl)/c.samples):c.samples=c.dx=0,c.x0=c.rl,c.currentTime=0,b.fn.doEvent(this,"bang");return this},c.keyoff=function(){var a=this._;a.status<=3&&(a.status=4,a.r>0?a.r===Infinity?(a.samples=Infinity,a.dx=0):(a.samples=b.samplerate*a.r/1e3|0,a.dx=-b.cellsize*(a.x0-a.rl)/a.samples):a.samples=a.dx=0,b.fn.doEvent(this,"R"))};var f=function(){var a=this._;while(a.samples<=0){if(a.status===0){a.status=1,a.a>0?a.a===Infinity?(a.samples=Infinity,a.dx=0):(a.samples+=b.samplerate*a.a/1e3|0,a.dx=b.cellsize*(a.dl-a.al)/a.samples):a.samples=a.dx=0,a.x0=a.al,b.fn.doEvent(this,"A");continue}if(a.status===1){a.status=2,a.d>0?a.d===Infinity?(a.samples=Infinity,a.dx=0):(a.samples+=b.samplerate*a.d/1e3|0,a.dx=-b.cellsize*(a.dl-a.sl)/a.samples):a.samples=a.dx=0,a.x0=a.dl,b.fn.doEvent(this,"D");continue}if(a.status===2){if(a.sl===0){a.status=4;continue}a.status=3,a.x0=a.sl,a.s>0?a.s===Infinity?(a.samples=Infinity,a.dx=0):(a.samples+=b.samplerate*a.s/1e3|0,a.dx=-b.cellsize*(a.sl-a.rl)/a.samples):a.samples=a.dx=0,b.fn.doEvent(this,"S");continue}if(a.status<=4){a.status=-1,a.samples=Infinity,a.x0=a.rl,a.dx=0,b.fn.doEvent(this,"ended");continue}}};return a}();b.fn.register("adsr",y),function(){var a=function(){var a=this._;while(a.samples<=0){if(a.status===0){a.status=1,a.a>0?a.a===Infinity?(a.samples=Infinity,a.dx=0):(a.samples+=b.samplerate*a.a/1e3|0,a.dx=b.cellsize*(1-a.al)/a.samples):a.samples=a.dx=0,a.x0=a.al,b.fn.doEvent(this,"A");continue}if(a.status===1){a.status=4,a.r>0?a.r===Infinity?(a.x0=1,a.samples=Infinity,a.dx=0):(a.x0=1,a.samples=b.samplerate*a.r/1e3|0,a.dx=-b.cellsize/a.samples):(a.x0=0,a.samples=0,a.dx=0),b.fn.doEvent(this,"R");continue}if(a.status===4){a.status=-1,a.samples=Infinity,a.x0=a.dx=0,b.fn.doEvent(this,"ended");continue}}};b.fn.register("perc",y,function(b){var c=0,d=[];typeof b[c]=="string"&&d.push(b[c++]);var e=[];while(typeof b[c]=="number")e.push(b[c++]);switch(e.length){case 0:d=d.concat([0,0,0,0,1e3,0,1,0,0]);break;case 1:d=d.concat([0,0,0,0,e[0],0,1,0,0]);break;case 2:d=d.concat([0,e[0],0,0,e[1],0,1,0,0]);break;case 3:d=d.concat([e[0],e[1],0,0,e[2],0,1,0,0]);break;default:d=d.concat([e[0],e[1],0,0,e[2],e[3],1,0,0])}typeof b[c]=="boolean"&&d.push(b[c++]),typeof b[c]=="function"&&d.push(b[c++]);var f=new y(d);f._.changeState=a;return f})}();var z=function(){var a=function(){d.apply(this,arguments)},c=b.fn.buildPrototype(a,{base:"ar-only",properties:{list:{set:function(a){a instanceof Array&&(this._.list=a,e.call(this))},get:function(){return this._.list}}}}),d=function(a){var c=this._={};c.list=[],c.workcell=new Float32Array(b.cellsize),c.stub={seq:function(){return c.workcell}},this.args=a.map(b)},e=function(){var a=this._,b=a.list,c=a.stub;for(var d=b.length;d--;)b[d].args.removeAll().push(c)};c.seq=function(a){var c,d=this._,e=this.cell;if(a!==this.seq_id){this.seq_id=a;var f=this.args.slice(0),g=d.workcell,h=d.list,i=d.mul,j=d.add,k,l;e=b.fn.sumargsAR(this,f,a),g.set(e);var m=g[0];for(k=0,l=h.length;k1?A=1:A<-1&&(A=-1),w=v,v=z,y=x,x=A,e[m]=A;c.in1=v,c.in2=w,c.out1=x,c.out2=y}for(m=e.length;m--;)e[m]=e[m]*f+g}return e},c.getFilter=function(b){return a.Types[b]},c.setFilter=function(b,c){typeof c=="object"&&typeof c.set_params=="function"&&(typeof c.default_freq!="number"&&(c.default_freq=2e3),typeof c.default_band!="number"&&(c.default_freq=1),typeof c.default_gain!="number"&&(c.default_freq=6),a.Types[b]=c)};return a}();A.Types={},A.Types.lpf={default_freq:800,default_band:1,set_params:function(a,c){var d=this._,e,f,g,h,i,j;e=a*2*Math.PI/b.samplerate,f=Math.cos(e),g=Math.sin(e),i=.34657359027997264*c*e/g,h=g*(Math.exp(i)-Math.exp(-i))*.5,h===Infinity&&(h=0),j=1/(1+h),d.a1=-2*f*j,d.a2=(1-h)*j,d.b1=(1-f)*j,d.b2=d.b0=d.b1*.5}},A.Types.hpf={default_freq:5500,default_band:1,set_params:function(a,c){var d=this._,e,f,g,h,i,j;e=a*2*Math.PI/b.samplerate,f=Math.cos(e),g=Math.sin(e),i=.34657359027997264*c*e/g,h=g*(Math.exp(i)-Math.exp(-i))*.5,h===Infinity&&(h=0),j=1/(1+h),d.a1=-2*f*j,d.a2=+(1-h)*j,d.b1=-(1+f)*j,d.b2=d.b0=-d.b1*.5}},A.Types.bpf={default_freq:3e3,default_band:1,set_params:function(a,c){var d=this._,e,f,g,h,i,j;e=a*2*Math.PI/b.samplerate,f=Math.cos(e),g=Math.sin(e),i=.34657359027997264*c*e/g,h=g*(Math.exp(i)-Math.exp(-i))*.5,h===Infinity&&(h=0),j=1/(1+h),d.a1=-2*f*j,d.a2=(1-h)*j,d.b0=h*j,d.b1=0,d.b2=-d.b0}},A.Types.brf={default_freq:3e3,default_band:1,set_params:function(a,c){var d=this._,e,f,g,h,i,j;e=a*2*Math.PI/b.samplerate,f=Math.cos(e),g=Math.sin(e),i=.34657359027997264*c*e/g,h=g*(Math.exp(i)-Math.exp(-i))*.5,h===Infinity&&(h=0),j=1/(1+h),d.a1=-2*f*j,d.a2=+(1-h)*j,d.b0=1,d.b1=-(1+f)*j,d.b2=1}},A.Types.allpass={default_freq:3e3,default_band:1,set_params:function(a,c){var d=this._,e,f,g,h,i,j;e=a*2*Math.PI/b.samplerate,f=Math.cos(e),g=Math.sin(e),i=.34657359027997264*c*e/g,h=g*(Math.exp(i)-Math.exp(-i))*.5,h===Infinity&&(h=0),j=1/(1+h),d.a1=-2*f*j,d.a2=+(1-h)*j,d.b0=d.a2,d.b1=d.a1,d.b2=1}},A.Types.peaking={default_freq:3e3,default_band:1,default_gain:6,set_params:function(a,c,d){var e=this._,f,g,h,i,j,k,l,m,n;f=Math.pow(10,d*.025),g=a*2*Math.PI/b.samplerate,h=Math.cos(g),i=Math.sin(g),m=.34657359027997264*c*g/i,j=i*(Math.exp(m)-Math.exp(-m))*.5,j===Infinity&&(j=0),k=j*f,l=j/f,n=1/(1+l),e.a1=-2*h*n,e.a2=+(1-l)*n,e.b0=+(1+k)*n,e.b1=e.a1,e.b2=+(1-k)*n}},A.Types.lowboost={default_freq:3e3,default_band:1,default_gain:6,set_params:function(a,c,d){var e=this._,f,g,h,i,j,k,l;f=Math.pow(10,d*.025),g=a*2*Math.PI/b.samplerate,h=Math.cos(g),i=Math.sin(g),j=i*.5*Math.sqrt((f+1/f)*(1/c-1)+2),k=j*Math.sqrt(f)*2,l=1/(f+1+(f-1)*h+k),e.a1=-2*(f-1+(f+1)*h)*l,e.a2=(f+1+(f-1)*h-k)*l,e.b0=(f+1-(f-1)*h+k)*f*l,e.b1=2*(f-1-(f+1)*h)*f*l,e.b2=(f+1-(f-1)*h-k)*f*l}},A.Types.highboost={default_freq:5500,default_band:1,default_gain:6,set_params:function(a,c,d){var e=this._,f,g,h,i,j,k,l;f=Math.pow(10,d*.025),g=a*2*Math.PI/b.samplerate,h=Math.cos(g),i=Math.sin(g),j=i*.5*Math.sqrt((f+1/f)*(1/c-1)+2),k=j*Math.sqrt(f)*2,l=1/(f+1+(f-1)*h+k),e.a1=2*(f-1+(f+1)*h)*l,e.a2=(f+1+(f-1)*h-k)*l,e.b0=(f+1-(f-1)*h+k)*f*l,e.b1=-2*(f-1-(f+1)*h)*f*l,e.b2=(f+1-(f-1)*h-k)*f*l}},b.fn.register("filter",A),b.fn.register("lpf",A,function(a){return new A(["lpf"].concat(a))}),b.fn.register("hpf",A,function(a){return new A(["hpf"].concat(a))}),b.fn.register("bpf",A,function(a){return new A(["bpf"].concat(a))}),b.fn.register("brf",A,function(a){return new A(["brf"].concat(a))}),b.fn.register("allpass",A,function(a){return new A(["allpass"].concat(a))}),b.fn.register("peaking",A,function(a){return new A(["peaking"].concat(a))}),b.fn.register("lowboost",A,function(a){return new A(["lowboost"].concat(a))}),b.fn.register("highboost",A,function(a){return new A(["highboost"].concat(a))});var B=function(){var a=function(){d.apply(this,arguments)},c=b.fn.buildPrototype(a,{base:"ar-only",properties:{type:{set:function(b){var c;typeof b=="string"&&(c=a.Types[b])!==undefined&&(this._.type=b,this._.mode=c)},get:function(){return this._.type}},cutoff:{set:function(a){this._.cutoff=b(a)},get:function(){return this._.cutoff}},Q:{set:function(a){this._.Q=b(a)},get:function(){return this._.Q}},depth:{set:function(a){this._.depth=b(a)},get:function(){return this._.depth}}}});a.Types={lpf:0,hpf:1,bpf:2,brf:3};var d=function(c){var d,e,f;this._=f={},e=0,typeof c[e]=="string"&&a.Types[c[e]]!==undefined?this.type=c[e++]:this.type="lpf",typeof c[e]=="object"&&c[e].isKr?f.cutoff=c[e++]:typeof c[e]=="number"?f.cutoff=b(c[e++]):f.cutoff=b(800),typeof c[e]=="object"&&c[e].isKr?f.Q=c[e++]:typeof c[e]=="number"?f.Q=b(c[e++]):f.Q=b(.5),typeof c[e]=="object"&&c[e].isKr?f.depth=c[e++]:typeof c[e]=="number"?f.depth=b(c[e++]):f.depth=b(.5),this.args=c.slice(e).map(b),f.prev_cutoff=undefined,f.prev_Q=undefined,f.prev_depth=undefined,f.f=new Float32Array(4),f.mode=0,f.damp=0,f.freq=0};c.clone=function(a){var c,d=this._,e,f,g;c=b("rfilter",d.type),a?(c.cutoff=d.cutoff.clone(a),c.Q=d.Q.clone(a),c.depth=d.depth.clone(a)):(c.cutoff=d.cutoff,c.Q=d.Q,c.depth=d.depth);return b.fn.copyBaseArguments(this,c,a)},c.seq=function(a){var c=this._,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t;e=this.cell;if(a!==this.seq_id){this.seq_id=a,d=this.args.slice(0),f=c.mul,g=c.add,e=b.fn.sumargsAR(this,d,a);if(c.ison){k=c.mode,h=c.cutoff.seq(a)[0],i=c.Q.seq(a)[0];if(h!==c.prev_cutoff||i!==c.prev_Q)m=2*Math.sin(3.141592653589793*Math.min(.25,h/(b.samplerate*2))),c.damp=Math.min(2*(1-Math.pow(i,.25)),Math.min(2,2/m-m*.5)),c.freq=m,c.prev_cutoff=h,c.prev_Q=i;n=c.depth.seq(a)[0],n!==c.prev_depth&&(c.depth0=Math.cos(.5*Math.PI*n),c.depth1=Math.sin(.5*Math.PI*n)),j=c.f,l=c.damp,m=c.freq,o=c.depth0,p=c.depth1;for(s=0,t=e.length;s-0.995?e.fb=c:e.fb=-0.995:e.fb=.995,d>1?d=1:d<0&&(d=0),e.wet=d};c.seq=function(a){var c=this._,d,e,f,g,h=this.cell;if(a!==this.seq_id){this.seq_id=a;var i=this.args.slice(0);h=b.fn.sumargsAR(this,i,a);var j,k=c.buffer,l=c.mask,m=c.idx,n=c.fb,o=c.out,p=c.wet,q=1-c.wet;if(c.ison)for(d=0,e=h.length;d-0.995?this.fb=c:this.fb=-0.995:this.fb=.995,d>1?d=1:d<0&&(d=0),this.wet=d},process:function(a){var b,c,d,e=this.buffer,f=this.mask,g=this.idx,h=this.fb,i=this.out,j=this.wet,k=1-this.wet;for(b=0,c=a.length;bm?C=m:C<-m&&(C=-m),D=p*C+q*s+r*t-n*u-o*v,D>1?D=1:D<-1&&(D=-1),t=s,s=C,v=u,u=D,d[E]=D*f+g;c.in1=s,c.in2=t,c.out1=u,c.out2=v}else for(E=0,F=d.length;Em?C=m:C<-m&&(C=-m),d[E]=C*f+g}else for(E=d.length;E--;)d[E]=d[E]*f+g}return d};return a}();b.fn.register("efx.dist",E);var F=function(){var a=function(){d.apply(this,arguments)},c=b.fn.buildPrototype(a,{base:"ar-only",properties:{depth:{set:function(a){var b=this._;typeof a=="number"&&(b.depth=a,b.lfo.mul=b.depth*b.offset)},get:function(){return this._.depth}},rate:{set:function(a){var b=this._;typeof a=="number"&&(b.rate=a,b.lfo.freq.value=a)},get:function(){return this._.rate}},wet:{set:function(a){var b=this._;typeof a=="number"&&0<=a&&a<=1&&(b.wet=a,b.wet0=Math.sin(.25*Math.PI*a),b.dry0=Math.cos(.25*Math.PI*a))},get:function(){return this._.wet}}}}),d=function(a){var c,d,e;this._=e={},c=Math.ceil(Math.log(b.samplerate*.02)*Math.LOG2E),e.buffer=new Float32Array(1<.999755859375?a=.999755859375:a<0&&(a=0),e.adx=(1-a)/(c*b.samplerate/1e3),e.rdx=(1-a)/(d*b.samplerate/1e3),e.xrt=1};c.seq=function(a){var c=this._,d,e,f=this.cell;if(a!==this.seq_id){this.seq_id=a;var g=this.args.slice(0);f=b.fn.sumargsAR(this,g,a);if(c.ison){var h=c.thres,i=c.ratio,j=c.gain,k,l=c.buffer,m=c.mask,n=c.idx,o=c.sum,p=c.avg,q=c.xrt,r=c.adx,s=c.rdx,t=c.thres2,u;for(d=0,e=f.length;dt?(q-=r)1&&(q=1),q<1&&(k>h?k=+h+(k-h)*q:k<-h&&(k=-h+(k+h)*q)),f[d]=k*j;c.sum=o,c.idx=n,c.xrt=q}var v=c.mul,w=c.add;for(d=f.length;d--;)f[d]=f[d]*v+w}return f};return a}();b.fn.register("efx.comp",G);var H={initialize:function(a){var b,c;this._=c={},b=0,c.src=typeof a[b]=="string"?a[b++]:"",c.loop=typeof a[b]=="boolean"?a[b++]:!1,typeof a[b]=="function"&&(c.loop?this.onlooped=a[b++]:this.onended=a[b++]),c.buffer=new Float32Array(0),c.duration=0,c.phase=0,c.reversed=!1,c.isloaded=!1},setPrototype:function(){Object.defineProperty(this,"src",{set:function(a){typeof a=="string"?this._.src!==a&&(this._.src=a,this._.isloaded=!1):b.platform==="web"&&a instanceof File&&(this._.src=a,this._.isloaded=!1)},get:function(){return this._.src}}),Object.defineProperty(this,"loop",{set:function(a){this._.loop=!!a},get:function(){return this._.loop}}),Object.defineProperty(this,"reversed",{set:function(a){var b=this._;b.reversed=!!a,b.reversed&&b.phase===0&&(b.phase=Math.max(0,b.buffer.length-1))},get:function(){return this._.reversed}}),Object.defineProperty(this,"isLoaded",{get:function(){return this._.isloaded}}),Object.defineProperty(this,"duration",{get:function(){return this._.duration}}),Object.defineProperty(this,"currentTime",{set:function(a){var c=this._;typeof a=="number"&&0<=a&&a<=c.duration&&(c.phase=a/1e3*b.samplerate|0)},get:function(){return this._.phase/b.samplerate*1e3}}),this.clone=function(a){var c,d,e=this._;c=this._.proto._.klassname,d=b(c,e.src,e.loop),d._.reversed=e.reversed,d._.isloaded=e.isloaded,d._.buffer=e.buffer,d._.duration=e.duration,d._.phase=e.reversed?Math.max(0,e.buffer.length-1):0;return b.fn.copyBaseArguments(this,d,a)},this.slice=function(a,c){var d,e,f=this._,g,h;d=this._.proto._.klassname,h=f.reversed,typeof a=="number"?a=a/1e3*b.samplerate:a=0,typeof c=="number"?c=c/1e3*b.samplerate:c=f.buffer.length,a>c&&(g=a,a=c,c=g,h=!h),e=b(d),e._.loop=f.loop,e._.reversed=h,e._.buffer=f.buffer.subarray(a,c),e._.duration=(c-a/b.samplerate)*1e3,e._.phase=h?Math.max(0,e._.buffer.length-1):0;return b.fn.copyBaseArguments(this,e)},this.bang=function(){var a=this._;a.phase=a.reversed?Math.max(0,a.buffer.length-1):0,b.fn.doEvent(this,"bang");return this},this.seq=function(a){var c=this._,d,e,f,g,h,i;if(!c.ison)return b._.none;d=this.cell;if(a!==this.seq_id){this.seq_id=a,e=c.buffer,f=c.mul,g=c.add;if(c.reversed)for(h=0,i=d.length;h=e.length&&(c.loop?(c.phase=0,b.fn.doEvent(this,"looped")):b.fn.doEvent(this,"ended"))}return d},this.getAudioSrc=function(){var a=this._,c,d,e,f,g;if(b.platform==="web"){e="",c=a.src.split(/,/).map(function(a){return a.trim()});for(f=0,g=c.length;fc&&(f=a,a=c,c=f,g=!g),d=b("wav"),d._.src=e.src,d._.loop=e.loop,d._.reversed=e.reversed,d._.isloaded=e.isloaded,d._.loaded_src=e.loaded_src,d._.buffer=e.buffer.subarray(a,c),d._.samplerate=e.samplerate,d._.duration=(c-a/e.samplerate)*1e3,d._.phaseStep=e.phaseStep,d._.phase=g?Math.max(0,d._.buffer.length-1):0;return b.fn.copyBaseArguments(this,d)};var e=function(a,c,d){a==="loadedmetadata"?b.fn.doEvent(this,"loadedmetadata",[c]):a==="loadeddata"?(typeof d=="function"?d.call(this,c):typeof d=="object"&&c.buffer&&(d.self=this,d.samplerate=c.samplerate,d.duration=c.buffer.length/samplerate*1e3,d.buffer=c.buffer,console.log("wav.load: done.")),b.fn.doEvent(this,"loadeddata",[c])):a==="error"&&(typeof d=="function"?d.call(this,"error"):typeof d=="object"&&console.log("wav.load: error."),b.fn.doEvent(this,"error"))};c.load=function(a){var c=this,d=this._,f,g,h,i,j;d.loaded_src===d.src?d.samplerate===0?e.call(this,"error",{},a):(e.call(this,"loadedmetadata",{samplerate:d.samplerate,buffer:d.buffer},a),e.call(this,"loadeddata",{samplerate:d.samplerate,buffer:d.buffer},a)):d.src!==""?(b.fn.doEvent(this,"loading"),b.platform==="web"&&b._.workerpath?(g=b.utils.relpath2rootpath(d.src),f=new Worker(b._.workerpath),f.onmessage=function(f){var g=f.data;switch(g.result){case"metadata":i=new Int16Array(g.bufferSize),j=g.samplerate,d.buffer=i,d.samplerate=j,e.call(c,"loadedmetadata",{samplerate:d.samplerate,buffer:d.buffer},a);break;case"data":i.set(g.array,g.offset);break;case"ended":d.isloaded=!0,d.loaded_src=d.src,d.duration=i.length/j*1e3,d.phaseStep=j/b.samplerate,d.reversed?d.phase=Math.max(0,newone._.buffer.length-1):d.phase=0,e.call(c,"loadeddata",{samplerate:j,buffer:i},a);break;default:e.call(c,"error",{},a)}},f.postMessage({action:"wav.decode",src:g})):b.utils.binary.load(d.src,function(f){b.utils.wav.decode(f,function(f){f.err?(d.loaded_src=undefined,d.buffer=new Int16Array(0),d.samplerate=0,d.duration=0,d.phaseStep=0,d.phase=0,e.call(c,"error",{},a)):(d.isloaded=!0,d.loaded_src=d.src,d.buffer=f.buffer,d.samplerate=f.samplerate,d.duration=f.buffer.length/f.samplerate*1e3,d.phaseStep=f.samplerate/b.samplerate,d.reversed?d.phase=Math.max(0,newone._.buffer.length-1):d.phase=0,e.call(c,"loadedmetadata",{samplerate:d.samplerate,buffer:d.buffer},a),e.call(c,"loadeddata",{samplerate:d.samplerate,buffer:d.buffer},a))})})):e.call(this,{},a),this._.isloaded=!1;return this},c.bang=function(){this._.phase=0,b.fn.doEvent(this,"bang");return this},c.seq=function(a){var c=this._,d,e,f,g,h,i,j,k,l,m,n,o;if(!c.ison)return b._.none;d=this.cell;if(a!==this.seq_id){this.seq_id=a,e=c.mul,f=c.add,g=c.buffer,i=c.phaseStep;if(c.reversed)for(n=0,o=d.length;n=g.length&&(c.loop?(c.phase=0,b.fn.doEvent(this,"looped")):b.fn.doEvent(this,"ended"))}return d};return a}();b.fn.register("wav",K);var L=function(){var a=function(){console.warn("Buddy is deprecated."),d.apply(this,arguments)},c=a.prototype;b.fn.setPrototypeOf.call(c,"ar-kr");var d=function(a){this.args=b.fn.valist.call(this,a)};c._.init=function(){c._._play=this.play,c._._pause=this.pause,c._._on=this.on,c._._off=this.off,c._._bang=this.bang,this.play=c._.$play,this.pause=c._.$pause,this.on=c._.$on,this.off=c._.$off,this.bang=c._.$bang},c.clone=function(a){return b.fn.copyBaseArguments(this,b("buddy"),a)},c._.$play=function(){var a,d,e;a=this.args.slice(0);for(d=0,e=a.length;d>1,h=i&1?1-(h-(i<<1)):-1+(h-(i<<1))):1>1,h=i&1?-1+(h-(i<<1)):1-(h-(i<<1))),e[j]=h*f+g}else{h=b.fn.sumargsKR(this,d,a),h<-1?(h=-h-1,i=h>>1,h=i&1?1-(h-(i<<1)):-1+(h-(i<<1))):1>1,h=i&1?-1+(h-(i<<1)):1-(h-(i<<1))),h=h*f+g;for(j=e.length;j--;)e[j]=h}}return e};return a}();b.fn.register("pong",O);var P=function(){var a=function(){d.apply(this,arguments)},c=b.fn.buildPrototype(a,{base:"ar-kr",properties:{min:{set:function(a){typeof a=="number"&&(this._.min=a)},get:function(){return this._.min}},max:{set:function(a){typeof a=="number"&&(this._.max=a)},get:function(){return this._.max}}}}),d=function(a){var c,d,e;this._=e={},d=[],c=0,typeof a[c]=="number"&&(d.push(a[c++]),typeof a[c]=="number"&&d.push(a[c++]));switch(d.length){case 1:d[0]<0?(e.min=d[0],e.max=-d[0]):(e.min=-d[0],e.max=d[0]);break;case 2:d[0]0&&(c.recTime=a,c.buffer=new Float32Array(b.samplerate*c.recTime/1e3|0))},get:function(){return this._.recTime}},interval:{set:function(a){var c=this._;typeof a=="number"&&(c.interval=a,c.interval_samples=b.samplerate*(a/1e3)|0,c.interval_samples0?d.recTime=a[c++]:d.recTime=1e3,d.buffer=new Float32Array(b.samplerate*d.recTime/1e3|0),typeof a[c]=="number"&&a[c]>0?this.interval=a[c++]:this.interval=Infinity,typeof a[c]=="function"&&(this.onrecorded=a[c++]),this.args=a.slice(c).map(b),d.index=0,d.samples=0,d.currentTime=0,d.overwrite=!1,d.status=0};c.clone=function(a){var c,d=this._;c=b("rec",d.recTime),c._.overwrite=d.overwrite;return b.fn.copyBaseArguments(this,c,a)},c.on=function(){var a,c,d=this._;d.ison=!0,d.samples=0,d.status=0,b.fn.doEvent(this,"on");return this},c.off=function(){this._.ison&&e.call(this),this._.ison=!1,b.fn.doEvent(this,"off");return this},c.bang=function(){var a=this._;a.samples=0,a.status=0,b.fn.doEvent(this,"bang");return this};var e=function(){var a=this._;b.fn.doEvent(this,"recorded",[a.buffer.subarray(0,a.index)])};c.seq=function(a){var c=this._,d,f,g,h,i,j,k;f=this.cell;if(a!==this.seq_id){this.seq_id=a,d=this.args.slice(0),g=c.buffer,h=c.mul,i=c.add,f=b.fn.sumargsAR(this,d,a);if(c.status===0&&c.samples<=0){c.status=1,c.index=c.currentTime=0,c.samples+=c.interval_samples;if(!c.overwrite)for(j=g.length;j--;)g[j]=0}if(c.ison&&c.status===1){for(j=0,k=f.length;j=g.length&&(e.call(this),c.interval===Infinity?(c.status=2,c.ison=!1,b.fn.doEvent(this,"ended")):(c.status=0,b.fn.doEvent(this,"looped")))}else for(j=f.length;j--;)f[j]=f[j]*h+i;c.samples-=f.length}return f};return a}();b.fn.register("rec",S);var U=function(){var a=function(){d.apply(this,arguments)},c=b.fn.buildPrototype(a,{base:"ar-only",properties:{buffer:{set:function(a){var c,d,e=this._;if(typeof a=="object")if(a instanceof Float32Array)e.buffer=a;else if(a instanceof Array||a.buffer instanceof ArrayBuffer){c=new Float32Array(a.length);for(d=c.length;d--;)c[d]=a[d];e.buffer=c,e.duration=c.length/b.samplerate*1e3,e.reversed?e.phase=Math.max(0,e.buffer.length-1):e.phase=0}},get:function(){return this._.buffer}},loop:{set:function(a){this._.loop=!!a},get:function(){return this._.loop}},reversed:{set:function(a){var b=this._;b.reversed=!!a,b.reversed&&b.phase===0&&(b.phase=Math.max(0,b.buffer.length-1))},get:function(){return this._.reversed}},duration:{get:function(){return this._.duration}},currentTime:{set:function(a){typeof a=="number"&&0<=a&&a<=this._.duration&&(this._.phase=a/1e3*this._.samplerate)},get:function(){return this._.phase/this._.samplerate*1e3}}}}),d=function(a){var c,d,e,f,g;this._=g={},e=0;if(typeof a[e]=="object")if(a[e]instanceof Float32Array)c=a[e++];else if(a[e]instanceof Array||a[e].buffer instanceof ArrayBuffer){d=a[e++],c=new Float32Array(d.length);for(f=c.length;f--;)c[f]=d[f]}c===undefined&&(c=new Float32Array(0)),g.loop=typeof a[e]=="boolean"?a[e++]:!1,g.buffer=c,g.duration=c.length/b.samplerate*1e3,g.phase=0,g.reversed=!1};c.clone=function(a){var c,d=this._;c=b("buffer",d.buffer,d.loop),c._.reversed=d.reversed,c._.phase=d.reversed?Math.max(0,d.buffer.length-1):0;return b.fn.copyBaseArguments(this,c,a)},c.slice=function(a,c){var d,e=this._,f,g;g=e.reversed,typeof a=="number"?a=a/1e3*b.samplerate:a=0,typeof c=="number"?c=c/1e3*b.samplerate:c=e.buffer.length,a>c&&(f=a,a=c,c=f,g=!g),d=b("buffer"),d._.loop=e.loop,d._.reversed=g,d._.buffer=e.buffer.subarray(a,c),d._.duration=(c-a/b.samplerate)*1e3,d._.phase=g?Math.max(0,d._.buffer.length-1):0,b.fn.copy_for_clone(this,d);return d},c.bang=function(){var a=this._;a.phase=a.reversed?Math.max(0,a.buffer.length-1):0,b.fn.doEvent(this,"bang");return this},c.seq=function(a){var c=this._,d,e,f,g,h,i;if(!c.ison)return b._.none;d=this.cell;if(a!==this.seq_id){this.seq_id=a,e=c.buffer,f=c.mul,g=c.add;if(c.reversed)for(h=0,i=d.length;h=e.length&&(c.loop?(c.phase=0,b.fn.doEvent(this,"looped")):b.fn.doEvent(this,"ended"))}return d};return a}();b.fn.register("buffer",U);var V=function(){var a=function(){d.apply(this,arguments)},c=b.fn.buildPrototype(a,{base:["ar-only","listener"],properties:{size:{get:function(){return this._.buffersize>>1}},window:{set:function(a){var c;if(typeof a=="string"){var d=/([A-Z][a-z]+)(?:([01]\.?\d*))?/.exec(a);if(d!==null){var e=d[1],f=d[2]!==undefined?+d[2]:.25;(c=b.utils.FFT.WindowFunctions[e])!==undefined&&(this._.window=e,this._.fft.setWindow(e,f))}}},get:function(){return this._.window}},interval:{set:function(a){var c=this._;typeof a=="number"&&(c.interval=a,c.interval_samples=b.samplerate*(a/1e3)|0,c.interval_samples>1)};c.clone=function(a){var c,d=this._;c=b("fft",d.buffersize),c._.window=d.window,c._.interval=d.interval,c._.interval_samples=d.interval_samples;return b.fn.copyBaseArguments(this,c,a)},c.seq=function(a){var c=this._,d,f,g,h,i,j,k,l;d=this.cell;if(a!==this.seq_id){this.seq_id=a,f=this.args.slice(0),g=c.buffer,h=c.buffersize,i=c.mul,j=c.add,d=b.fn.sumargsAR(this,f,a);for(k=0,l=d.length;k>1;for(k=i;k--;)l=e[k],m=f[k],n=i*h(l*l+m*m),g[k]=n}b.fn.doEvent(this,"fft",[e,f])};return a}();b.fn.register("fft",V);var W=function(){var a=function(){d.apply(this,arguments)},c=b.fn.buildPrototype(a,{base:["kr-only","timer"],properties:{interval:{set:function(a){typeof a=="number"&&a>=0&&(this._.interval=a)},get:function(){return this._.interval}},delay:{set:function(a){typeof a=="number"&&a>=0&&(this._.delay=a,this._.delaySamples=b.samplerate*(a/1e3)|0)},get:function(){return this._.delay}},count:{set:function(a){typeof a=="number"&&(this._.count=a)},get:function(){return this._.count}},currentTime:{get:function(){return this._.currentTime}}}}),d=function(a){var c=this._={};c.ison=!1,c.samples=c.count=c.currentTime=0;var d=0,e=[];while(typeof a[d]=="number")e.push(a[d++]);switch(e.length){case 1:this.delay=0,this.interval=e[0];break;case 2:this.delay=e[0],this.interval=e[1];break;default:this.delay=0,this.interval=1e3}this.args=a.slice(d).map(b)};c.clone=function(a){return b("interval",this._.delay,this._.interval)},c.bang=function(){var a=this._;a.delaySamples=b.samplerate*(a.delay/1e3)|0,a.samples=a.count=a.currentTime=0,b.fn.doEvent(this,"bang");return this},c.seq=function(a){var c=this._;if(a!==this.seq_id){this.seq_id=a,c.delaySamples>0&& -(c.delaySamples-=b.cellsize);if(c.delaySamples<=0){c.samples-=b.cellsize;if(c.samples<=0){c.samples+=b.samplerate*c.interval/1e3|0;var d=this.args.slice(0);for(var e=0,f=d.length;e0&&(this._.timeout=a,this._.timeout_samples=b.samplerate*(a/1e3)|0)},get:function(){return this._.timeout}},currentTime:{get:function(){return this._.currentTime}}}}),d=function(a){var c=this._={};c.ison=!1,c.samples=c.currentTime=0;var d=0;typeof a[d]=="number"?this.timeout=a[d++]:this.timeout=1e3,this.args=a.slice(d).map(b)};c.clone=function(a){return b("timeout",this._.timeout)},c._.on=function(){this._.samples=this._.timeout_samples},c.bang=function(){var a=this._;a.samples=a.timeout_samples,a.currentTime=0,b.fn.doEvent(this,"bang");return this},c.seq=function(a){var c=this._;if(a!==this.seq_id){this.seq_id=a,c.samples-=b.cellsize;if(c.samples<=0){c.samples=0;var d=this.args.slice(0);for(var e=0,f=d.length;e0&&f.call(this,a)},get:function(){return this._.bpm}},currentTime:{get:function(){return this._.currentTime}}}}),d=function(a){var b=this._={ev:{}};b.bpm=0,b.mode="msec",b.msec=1,b.timetable=[],b.index=0,b.ison=!1,b.currentTime=0,b.loopcount=0,b.inseq=!1,b.updated=!1;var c=0;typeof a[c]=="string"&&e.call(this,a[c++]),typeof a[c]=="object"&&a[c]instanceof Array&&this.append(a[c++]),typeof a[c]=="boolean"?b.loop=a[c++]:b.loop=!1};c.clone=function(a){var c=this._,d=b("schedule");d._.mode=c.mode,d._.msec=c.msec;return d};var e=function(a){var c,d=this._;if(c=/^bpm\s*\(\s*(\d+(?:\.\d*)?)\s*(?:,\s*(\d+))?\s*\)/.exec(a))d.mode="bpm",d.bpm=c[1]|0,d.len=c[2]|0||16,d.msec=b.utils.bpm2msec(d.bpm,d.len)},f=function(a){var c,d,e,f,g=this._;c=b.utils.bpm2msec(a,g.len),d=c/g.msec,e=g.timetable;for(f=e.length;f--;)e[f][0]*=d;g.currentTime*=d,g.msec=c,g.bpm=a};c.bang=function(){var a=this._;a.index=a.currentTime=a.loopcount=0,b.fn.doEvent(this,"bang");return this},c.append=function(){var a=this._,c=a.timetable,d=c[a.index],e=[];for(var f=0,g=arguments.length;f=f.length){var h=f.length-1;if(c.loop)c.currentTime-=f[h][0]*g||0,c.index=0,b.fn.doEvent(this,"looped",[++c.loopcount]);else{b.fn.doEvent(this,"ended");var i=c.currentTime;while(f[h]&&i<=f[h][0]*g)h-=1;h===f.length-1?this.off():h!==-1&&(c.index=h)}}c.currentTime+=b.cellsize/b.samplerate*1e3}return this.cell};return a}();b.fn.register("schedule",Y);var Z=function(){var a=function(){o.apply(this,arguments)},c=b.fn.buildPrototype(a,{base:["kr-only","timer"],properties:{mml:{set:function(a){var b=this._;if(typeof a=="string"){var c=b.tracks[b.selected];c?c.compile(a):b.tracks[b.selected]=new n(this,a)}else if(a===null)delete b.tracks[b.selected];else if(typeof a=="object")for(var d in a){var e=a[d],c=b.tracks[d];e===null?delete b.tracks[d]:c?c.compile(e):b.tracks[d]=new n(this,e)}},get:function(){var a=this._;return a.tracks[a.selected]}},bpm:{set:function(a){typeof a=="number"&&1<=a&&a<=511&&(this._.bpm=a)},get:function(){return this._.bpm}},selected:{set:function(a){var b=this._;(typeof a=="string"||typeof a=="number")&&b.tracks[a]instanceof n&&(b.selected=a)},get:function(){return this._.selected}},synth:{set:function(a){b.fn.isTimbreObject(a)&&(this._.synth=a)},get:function(){return this._.synth}},synthdef:{set:function(a){var b=this._;if(typeof a=="function"){b.synthdef=a;var c=b.synth;if(c)while(c.args.length>0){var d=c.args.shift();d&&d.tnum&&delete c.keyon[d.tnum]}}},get:function(){return this._.synthdef}},synthpoly:{set:function(a){typeof a=="number"&&(this._.synthpoly=a)},get:function(){return this._.synthpoly}},currentTime:{get:function(){return this._.currentTime}}}}),d=0,e=1,f=2,g=3,h=4,i=function(a,b,c,d){this.name=a,">":this.octave>0&&(this.octave-=1);break;case"<":this.octave<9&&(this.octave+=1);break;case"l":0<=c&&c<=1920&&(this.length=c,this.dot=a.dot);break;case"o":0<=c&&c<=9&&(this.octave=c);break;case"k":0<=c&&c<=8192&&(a.sign==="-"?this.detune=-c:this.detune=+c);break;case"q":0<=c&&c<=8&&(this.quantize=c);break;case"v":0<=c&&c<=128&&(this.volume=a.length);break;case"t":1<=c&&c<=511&&(this.parent._.bpm=c,b.fn.doEvent(this.parent,"bpm",[c]))}a=this.fetch()}else if(a.type===g){var e=this.loopStack;switch(a.name){case"[":c===undefined&&(c=2),e.push({count:c,begin:this.index,end:null});break;case"]":if(e.length!==0){var h=e[e.length-1];h.end===null&&(h.end=this.index,typeof c=="number"&&(h.count=c|0)),h.count>1?(--h.count,this.index=h.begin):e.pop()}break;case"|":if(e.length===0)return{type:d};var h=e[e.length-1];h.count<=1&&(this.index=h.end,e.pop())}a=this.fetch()}return a};return a}(),o=function(a){var b=this._={};b.bpm=120,b.samples=Infinity,b.keyons=[],b.keyons.samples=0,b.tie=!1,b.synth=null,b.synthdef=null,b.synthpoly=4;var c={};if(typeof a[0]=="object"){var d=a[0];for(var e in d)c[e]=new n(this,d[e])}else for(var f=0,g=a.length;fb.synthpoly&&delete c.keyon[c.args.shift().tnum]}else if(a.cmd==="keyoff"){var e=c.keyon[a.tnum];e!==undefined&&e.keyoff&&e.keyoff(a)}}};c.bang=function(){var a=this._;p.call(this);var c=a.tracks[a.selected];c?(c.bang(),a.samples>0&&(a.samples=0),a.endedEvent=!1):a.samples=Infinity,a.tie=!1,b.fn.doEvent(this,"bang");return this},c._.on=function(){this.bang()},c.segno=function(a){var b=this._,c=b.tracks[b.selected];c&&c.segno(a)},c.seq=function(a){var c=this._;if(a!==this.seq_id){this.seq_id=a;var f=c.keyons;c.sentinel=!1;while(c.samples<=0){if(f.length>0&&!c.tie){p.call(this);continue}for(;;){var g=c.tracks[c.selected];if(g===undefined)break;var i=g.fetch();if(i.type===e){var j=i.dot;j===0&&i.length===undefined&&(j=g.dot);var n=i.length;n===undefined&&(n=g.length);if(i.name!=="r"){var o=l(i.name,i.sign,g.octave),q=m((o<<6)+g.detune);c.tie?o=c.keyons[c.keyons.length-1]:c.keyons.push(o),b.fn.doEvent(this,"mml",[{cmd:"keyon",freq:q,tnum:o,volume:g.volume,length:n,tie:c.tie}]),c.tie=i.tie}else o=0,c.tie=!1;if(n===0)continue;var r=b.samplerate*(60/c.bpm)*(4/n);r*=k[j]||1;if(o!==0&&!c.tie){var s=r*(g.quantize/8)|0;f.samples=r-s,c.samples+=s}else c.samples+=r|0}else if(i.type===h){var t=null;i.length!==undefined&&(t=i.length,i.sign==="-"&&(t*=-1)),b.fn.doEvent(this,"external",[{cmd:i.name,value:t}])}else i.type===d&&(c.sentinel?c.samples=Infinity:(c.sentinel=!0,c.endedEvent=!0,g.segnoIndex[0]===undefined?(b.fn.doEvent(this,"ended"),c.endedEvent&&(c.samples=Infinity)):(g.index=g.segnoIndex[0],b.fn.doEvent(this,"segno")),c.endedEvent=!1));break}}c.samples-=b.cellsize,c.currentTime+=b.cellsize/b.samplerate*1e3}return this.cell};return a}();b.fn.register("mml",Z);var $=function(){var a=function(){d.apply(this,arguments)},c=b.fn.buildPrototype(a,{base:"ar-kr",properties:{version:{set:function(b){var c,d=this._;typeof b=="string"&&b!==d.version&&(c=a.Versions[b])!==undefined&&(d.version=b,d.synth&&d.synth.destroy&&d.synth.destroy(this),d.synth=c(this))},get:function(){return this._.version}}}}),d=function(b){var c,d;this._=d={},c=0,typeof b[c]=="string"&&a.Versions[b[c]]!==undefined?this.version=b[c++]:this.version="0.1"};c.clone=function(a){var c;c=b("timbre",this._.version);return b.fn.copyBaseArguments(this,c,a)},c.bang=function(){this._.synth&&this._.synth.bang(),b.fn.doEvent(this,"bang");return this},c.seq=function(a){var c=this._,d,e,f,g,h,i;if(!c.ison)return b._.none;d=this.cell;if(a!==this.seq_id){this.seq_id=a;if(c.synth){g=c.synth.seq(a),e=c.mul,f=c.add;for(h=g.length;h--;)d[h]=g[h]*e+f}}return d};return a}();b.fn.register("timbre",$),$.Versions={},$.Versions["0.1"]=function(a){var b=T("+");b.onbang=function(){var a,c,d;a=T("*"),c=T("pulse",987.7666,.25),d=T("adsr",0,80,1,720).bang(),a.append(c,d),d.onS=function(){c.freq.value=1318.5102,d.keyoff()},d.onended=function(){b.remove(a)},b.append(a)};return b},b.utils=function(a){var b={$exports:{}};b.mtof=function(){var a=function(){var a=new Float32Array(128);for(var b=0;b<128;b++)a[b]=440*Math.pow(Math.pow(2,1/12),b-69);return a}();return function(b){return 0<=b&&b<128?a[b|0]:0}}(),b.ftom=function(a){return Math.round(Math.log(a/440)*Math.LOG2E*12+69)},b.mtoa=function(){var a=["c","c+","d","d+","e","f","f+","g","g+","a","a+","b"];return function(b){var c=(b|0)%12,d=(b|0)/12;return a[c]+((d|0)-2)}}(),b.ftoa=function(a){return b.mtoa(b.ftom(a))},b.atom=function(){var a=/^([CDEFGABcdefgab])([-+#b]?)([0-9]?)$/,b={c:0,d:2,e:4,f:5,g:7,a:9,b:11},c=function(d){var e,f=0;if((e=d.match(a))!==null){f=b[e[1].toLowerCase()];switch(e[2]){case"+":case"#":++f;break;case"-":case"b":--f}f+=12*((e[3]|0)+2+c.octaveshift)}return f};c.octaveshift=0;return c}(),b.atof=function(a){return b.mtof(b.atom(a))},b.bpm2msec=function(a,b){typeof b=="undefined"&&(b=4);return 60/a*(4/b)*1e3},b.msec2bpm=function(a,b){typeof b=="undefined"&&(b=4);return 60/(a/1e3)*(4/b)},b.msec2hz=function(a){return 1e3/a},b.hz2msec=function(a){return 1e3/a},b.bpm2hz=function(a,b){typeof b=="undefined"&&(b=4);return 1e3/(60/a*(4/b)*1e3)},b.hz2bpm=function(a,b){typeof b=="undefined"&&(b=4);return 60/(1e3/msec/1e3)*(4/b)},b.num2db=function(a){return-20*Math.log(a)*Math.LOG10E},b.db2num=function(a){return Math.pow(10,a/-20)},b.$exports.converter=["mtof","ftom","mtoa","ftoa","atom","atof","bpm2msec","msec2bpm","msec2hz","msec2hz","bpm2hz","hz2bpm"],b.range=function(){var a,b,c,d,e=[];switch(arguments.length){case 1:a=0,b=arguments[0]|0,c=1;break;case 2:a=arguments[0]|0,b=arguments[1]|0,c=1;break;case 3:a=arguments[0]|0,b=arguments[1]|0,c=arguments[2]|0}if(c>0)for(d=a;db;d+=c)e.push(d);return e},function(a){var c=function(a){var b=new Uint32Array(32);this.seed=function(a){var c;typeof a!="number"&&(a=+(new Date)*1e3+Math.random()*1e3),a|=0,b[0]=3,b[1]=a;for(c=2;c<=31;++c)a=16807*a&2147483647,b[c]=a;for(c=310;c--;)this.next()},this.next=function(){var a=b[0];a=a===31?1:a+1,b[0]=a,b[a]+=a>3?b[a-3]:b[a+31-3];return(b[a]>>>1)/2147483647},this.seed(a)};a.Random=c;var d=new c,e=function(a){d.seed(a)};a.seed=e;var f=function(){return h(b.range.apply(null,arguments))};a.randrange=f;var g=function(a,b){return a+(b-a+1)*d.next()|0};a.randint=g;var h=function(a){return a[a.length*d.next()|0]};a.choice=h;var i=function(a,b){var e;typeof b=="number"?e=new c(b):e=d,a.sort(function(){return e.next()-e.next()});return a};a.shuffle=i;var a=function(){return d.next()};a.random=a;var j=function(a,b){return a+(b-a)*d.next()};a.uniform=j,b.$exports.random=["random"]}(b.random={});var c=function(){var a=function(){d.apply(this,arguments)},b=a.prototype,c={get:function(a){return c[a]||function(){var b=function(){var b,c,d,e,f;b=new Int16Array(a),f=a>>1,c=d=0;for(;;){b[c]=d;if(++c>=a)break;e=f;while(e<=d)d-=e,e>>=1;d+=e}return b}(),d,e=Math.floor(Math.log(a)/Math.LN2),f=new Float32Array((1<>1;if(c===2||c===4||c===8||c===16||c===32||c===64)for(var d=0,e=0;d>=4)d[h+1]=(c&15)/16;var j=0,k;for(h=0;h<8;++h){var l=0,m=(h+1)/1024;for(i=0;i<1024;++i)b[i]+=f(e*l)*d[h],l+=m,j<(k=g(b[i]))&&(j=k)}if(j>0)for(h=1024;h--;)b[h]/=j}return b},function(b){var c=function(a,b){typeof a=="function"?a(b):typeof a=="object"&&(a.buffer=b)},d=function(a,b){if(typeof a=="string"){var d=new XMLHttpRequest;d.open("GET",a,!0),d.responseType="arraybuffer",d.onload=function(){c(b,d.response)},d.send()}},e=function(a,b){var c;typeof a=="string"&&((c=/^(https?):\/\/(.*?)(\/.*)?$/.exec(a))!==null?f(c[1],{host:c[2],path:c[3]||""},b):g(a,b))},f=function(a,b,d){require(a).get(b,function(a){var b,e;a.statusCode===200&&(b=new ArrayBuffer(a.headers["content-length"]),e=0,a.on("data",function(a){var c,d;for(c=0,d=a.length;c>1)/l;if(h>a.length-44){b(0,null,c,"HeaderError: not exists data");return}d=new Int16Array(p*l|0),o===8?q=new Int8Array(a.buffer,44):o===16?q=new Int16Array(a.buffer,44):o===32?q=new Int32Array(a.buffer,44):o===24&&(q=function(){var b,c,d,e,f,g,h,i,j;b=new Int32Array((a.length-44)/3),j=0;for(h=44,i=a.length;h=i&&(a.process(),j-=i),m=j|0,n=1-(j-m),p=c[m],q=(1-n)*k+n*p,k=p,f[r]=q,p=e[m],q=(1-n)*l+n*p,l=p,g[r]=q,j+=d;this.x=j,this.prevL=k,this.prevR=l}.bind(this)}return this},this.on=function(){this.x=this.streamsize,this.prevL=this.prevR=0,this.node=this.ctx.createJavaScriptNode(a.streamsize,1,a.channels),this.node.onaudioprocess=this.onaudioprocess,this.node.connect(this.ctx.destination)},this.off=function(){this.node.disconnect(),this.node=null};return this},e=function(a){this.timer=new c,this.setup=function(){b.fn._setupTimbre(44100),this.audio=new Audio,this.audio.mozSetup(b.channels,b.samplerate),b.samplerate=this.audio.mozSampleRate,b.channels=this.audio.mozChannels,this.written=0,this.interleaved=new Float32Array(b.streamsize*b.channels),this.onaudioprocess=function(){var b=this.audio.mozCurrentSampleOffset();if(b>0&&this.written>b+16384)return this;var c=this.interleaved;this.audio.mozWriteAudio(c),a.process();var d=a.L,e=a.R,f=c.length,g=d.length;while(g--)c[--f]=e[g],c[--f]=d[g];this.written+=c.length}.bind(this);return this},this.on=function(){this.written=0,this.timer.setInterval(this.onaudioprocess,20)},this.off=function(){var a=this.interleaved;for(var b=a.length;b--;)a[b]=0;this.timer.clearInterval()};return this};typeof webkitAudioContext=="function"?(b.env="webkit",b.sys.bind(d)):typeof webkitAudioContext=="object"?(b.env="webkit",b.sys.bind(d)):typeof Audio=="function"&&typeof (new Audio).mozSetup=="function"&&(b.env="moz",b.sys.bind(e)),b.utils.relpath2rootpath=function(b){if(/^https?:\/\//.test(b))return b;if(b[0]==="/")return b;var c=a.location.pathname;c=c.substr(0,c.lastIndexOf("/")),c=c.split("/").filter(function(a){return a!==""}),b=b.split("/");for(var d=0;d=j&&(a.process(),k-=j),n=k|0,o=1-(k-n),q=c[n],r=(1-o)*l+o*q,l=q,g[s]=r,q=e[n],r=(1-o)*m+o*q,m=q,h[s]=r,k+=f;d.x=k,d.prevL=l,d.prevR=m}),this.jsnode.onaudioprocess=g;return this},this.on=function(){this.x=this.streamsize,this.prevL=this.prevR=0,this.jsnode.start()},this.off=function(){this.jsnode.stop()}},e=function(a){this.timerId=0,this.setup=function(){b.fn._setupTimbre(44100),this.interval=b.streamsize*1e3/b.samplerate,this.onaudioprocess=function(){a.process()}.bind(this);return this},this.on=function(){this.timerId!==0&&clearInterval(this.timerId),this.timerId=setInterval(this.onaudioprocess,this.interval)},this.off=function(){this.timerId!==0&&clearInterval(this.timerId)};return this};try{c=require("ctimbre")}catch(f){c=null}c!==null?(b.env="ctimbre",b.sys.bind(d)):(b.env="nop",b.sys.bind(e))}(a,b),b.isEnabled=!!b.sys._.impl;return b}(this) \ No newline at end of file +(c.delaySamples-=b.cellsize);if(c.delaySamples<=0){c.samples-=b.cellsize;if(c.samples<=0){c.samples+=b.samplerate*c.interval/1e3|0;var d=this.args.slice(0);for(var e=0,f=d.length;e0&&(this._.timeout=a,this._.timeout_samples=b.samplerate*(a/1e3)|0)},get:function(){return this._.timeout}},currentTime:{get:function(){return this._.currentTime}}}}),d=function(a){var c=this._={};c.ison=!1,c.samples=c.currentTime=0;var d=0;typeof a[d]=="number"?this.timeout=a[d++]:this.timeout=1e3,this.args=a.slice(d).map(b)};c.clone=function(a){return b("timeout",this._.timeout)},c._.on=function(){this._.samples=this._.timeout_samples},c.bang=function(){var a=this._;a.samples=a.timeout_samples,a.currentTime=0,b.fn.doEvent(this,"bang");return this},c.seq=function(a){var c=this._;if(a!==this.seq_id){this.seq_id=a,c.samples-=b.cellsize;if(c.samples<=0){c.samples=0;var d=this.args.slice(0);for(var e=0,f=d.length;e0&&f.call(this,a)},get:function(){return this._.bpm}},currentTime:{get:function(){return this._.currentTime}}}}),d=function(a){var b=this._={ev:{}};b.bpm=0,b.mode="msec",b.msec=1,b.timetable=[],b.index=0,b.ison=!1,b.currentTime=0,b.loopcount=0,b.inseq=!1,b.updated=!1;var c=0;typeof a[c]=="string"&&e.call(this,a[c++]),typeof a[c]=="object"&&a[c]instanceof Array&&this.append(a[c++]),typeof a[c]=="boolean"?b.loop=a[c++]:b.loop=!1};c.clone=function(a){var c=this._,d=b("schedule");d._.mode=c.mode,d._.msec=c.msec;return d};var e=function(a){var c,d=this._;if(c=/^bpm\s*\(\s*(\d+(?:\.\d*)?)\s*(?:,\s*(\d+))?\s*\)/.exec(a))d.mode="bpm",d.bpm=c[1]|0,d.len=c[2]|0||16,d.msec=b.utils.bpm2msec(d.bpm,d.len)},f=function(a){var c,d,e,f,g=this._;c=b.utils.bpm2msec(a,g.len),d=c/g.msec,e=g.timetable;for(f=e.length;f--;)e[f][0]*=d;g.currentTime*=d,g.msec=c,g.bpm=a};c.bang=function(){var a=this._;a.index=a.currentTime=a.loopcount=0,b.fn.doEvent(this,"bang");return this},c.append=function(){var a=this._,c=a.timetable,d=c[a.index],e=[];for(var f=0,g=arguments.length;f=f.length){var h=f.length-1;if(c.loop)c.currentTime-=f[h][0]*g||0,c.index=0,b.fn.doEvent(this,"looped",[++c.loopcount]);else{b.fn.doEvent(this,"ended");var i=c.currentTime;while(f[h]&&i<=f[h][0]*g)h-=1;h===f.length-1?this.off():h!==-1&&(c.index=h)}}c.currentTime+=b.cellsize/b.samplerate*1e3}return this.cell};return a}();b.fn.register("schedule",Y);var Z=function(){var a=function(){o.apply(this,arguments)},c=b.fn.buildPrototype(a,{base:["kr-only","timer"],properties:{mml:{set:function(a){var b=this._;if(typeof a=="string"){var c=b.tracks[b.selected];c?c.compile(a):b.tracks[b.selected]=new n(this,a)}else if(a===null)delete b.tracks[b.selected];else if(typeof a=="object")for(var d in a){var e=a[d],c=b.tracks[d];e===null?delete b.tracks[d]:c?c.compile(e):b.tracks[d]=new n(this,e)}},get:function(){var a=this._;return a.tracks[a.selected]}},bpm:{set:function(a){typeof a=="number"&&1<=a&&a<=511&&(this._.bpm=a)},get:function(){return this._.bpm}},selected:{set:function(a){var b=this._;(typeof a=="string"||typeof a=="number")&&b.tracks[a]instanceof n&&(b.selected=a)},get:function(){return this._.selected}},synth:{set:function(a){b.fn.isTimbreObject(a)&&(this._.synth=a)},get:function(){return this._.synth}},synthdef:{set:function(a){var b=this._;if(typeof a=="function"){b.synthdef=a;var c=b.synth;if(c)while(c.args.length>0){var d=c.args.shift();d&&d.tnum&&delete c.keyon[d.tnum]}}},get:function(){return this._.synthdef}},synthpoly:{set:function(a){typeof a=="number"&&(this._.synthpoly=a)},get:function(){return this._.synthpoly}},currentTime:{get:function(){return this._.currentTime}}}}),d=0,e=1,f=2,g=3,h=4,i=function(a,b,c,d){this.name=a,">":this.octave>0&&(this.octave-=1);break;case"<":this.octave<9&&(this.octave+=1);break;case"l":0<=c&&c<=1920&&(this.length=c,this.dot=a.dot);break;case"o":0<=c&&c<=9&&(this.octave=c);break;case"k":0<=c&&c<=8192&&(a.sign==="-"?this.detune=-c:this.detune=+c);break;case"q":0<=c&&c<=8&&(this.quantize=c);break;case"v":0<=c&&c<=128&&(this.volume=a.length);break;case"t":1<=c&&c<=511&&(this.parent._.bpm=c,b.fn.doEvent(this.parent,"bpm",[c]))}a=this.fetch()}else if(a.type===g){var e=this.loopStack;switch(a.name){case"[":c===undefined&&(c=2),e.push({count:c,begin:this.index,end:null});break;case"]":if(e.length!==0){var h=e[e.length-1];h.end===null&&(h.end=this.index,typeof c=="number"&&(h.count=c|0)),h.count>1?(--h.count,this.index=h.begin):e.pop()}break;case"|":if(e.length===0)return{type:d};var h=e[e.length-1];h.count<=1&&(this.index=h.end,e.pop())}a=this.fetch()}return a};return a}(),o=function(a){var b=this._={};b.bpm=120,b.samples=Infinity,b.keyons=[],b.keyons.samples=0,b.tie=!1,b.synth=null,b.synthdef=null,b.synthpoly=4;var c={};if(typeof a[0]=="object"){var d=a[0];for(var e in d)c[e]=new n(this,d[e])}else for(var f=0,g=a.length;fb.synthpoly&&delete c.keyon[c.args.shift().tnum]}else if(a.cmd==="keyoff"){var e=c.keyon[a.tnum];e!==undefined&&e.keyoff&&e.keyoff(a)}}};c.bang=function(){var a=this._;p.call(this);var c=a.tracks[a.selected];c?(c.bang(),a.samples>0&&(a.samples=0),a.endedEvent=!1):a.samples=Infinity,a.tie=!1,b.fn.doEvent(this,"bang");return this},c._.on=function(){this.bang()},c.segno=function(a){var b=this._,c=b.tracks[b.selected];c&&c.segno(a)},c.seq=function(a){var c=this._;if(a!==this.seq_id){this.seq_id=a;var f=c.keyons;c.sentinel=!1;while(c.samples<=0){if(f.length>0&&!c.tie){p.call(this);continue}for(;;){var g=c.tracks[c.selected];if(g===undefined)break;var i=g.fetch();if(i.type===e){var j=i.dot;j===0&&i.length===undefined&&(j=g.dot);var n=i.length;n===undefined&&(n=g.length);if(i.name!=="r"){var o=l(i.name,i.sign,g.octave),q=m((o<<6)+g.detune);c.tie?o=c.keyons[c.keyons.length-1]:c.keyons.push(o),b.fn.doEvent(this,"mml",[{cmd:"keyon",freq:q,tnum:o,volume:g.volume,length:n,tie:c.tie}]),c.tie=i.tie}else o=0,c.tie=!1;if(n===0)continue;var r=b.samplerate*(60/c.bpm)*(4/n);r*=k[j]||1;if(o!==0&&!c.tie){var s=r*(g.quantize/8)|0;f.samples=r-s,c.samples+=s}else c.samples+=r|0}else if(i.type===h){var t=null;i.length!==undefined&&(t=i.length,i.sign==="-"&&(t*=-1)),b.fn.doEvent(this,"external",[{cmd:i.name,value:t}])}else i.type===d&&(c.sentinel?c.samples=Infinity:(c.sentinel=!0,c.endedEvent=!0,g.segnoIndex[0]===undefined?(b.fn.doEvent(this,"ended"),c.endedEvent&&(c.samples=Infinity)):(g.index=g.segnoIndex[0],b.fn.doEvent(this,"segno")),c.endedEvent=!1));break}}c.samples-=b.cellsize,c.currentTime+=b.cellsize/b.samplerate*1e3}return this.cell};return a}();b.fn.register("mml",Z);var $=function(){var a=function(){d.apply(this,arguments)},c=b.fn.buildPrototype(a,{base:"ar-kr",properties:{version:{set:function(b){var c,d=this._;typeof b=="string"&&b!==d.version&&(c=a.Versions[b])!==undefined&&(d.version=b,d.synth&&d.synth.destroy&&d.synth.destroy(this),d.synth=c(this))},get:function(){return this._.version}}}}),d=function(b){var c,d;this._=d={},c=0,typeof b[c]=="string"&&a.Versions[b[c]]!==undefined?this.version=b[c++]:this.version="0.1"};c.clone=function(a){var c;c=b("timbre",this._.version);return b.fn.copyBaseArguments(this,c,a)},c.bang=function(){this._.synth&&this._.synth.bang(),b.fn.doEvent(this,"bang");return this},c.seq=function(a){var c=this._,d,e,f,g,h,i;if(!c.ison)return b._.none;d=this.cell;if(a!==this.seq_id){this.seq_id=a;if(c.synth){g=c.synth.seq(a),e=c.mul,f=c.add;for(h=g.length;h--;)d[h]=g[h]*e+f}}return d};return a}();b.fn.register("timbre",$),$.Versions={},$.Versions["0.1"]=function(a){var b=T("+");b.onbang=function(){var a,c,d;a=T("*"),c=T("pulse",987.7666,.25),d=T("adsr",0,80,1,720).bang(),a.append(c,d),d.onS=function(){c.freq.value=1318.5102,d.keyoff()},d.onended=function(){b.remove(a)},b.append(a)};return b},b.utils=function(a){var b={$exports:{}};b.mtof=function(){var a=function(){var a=new Float32Array(128);for(var b=0;b<128;b++)a[b]=440*Math.pow(Math.pow(2,1/12),b-69);return a}();return function(b){return 0<=b&&b<128?a[b|0]:0}}(),b.ftom=function(a){return Math.round(Math.log(a/440)*Math.LOG2E*12+69)},b.mtoa=function(){var a=["c","c+","d","d+","e","f","f+","g","g+","a","a+","b"];return function(b){var c=(b|0)%12,d=(b|0)/12;return a[c]+((d|0)-2)}}(),b.ftoa=function(a){return b.mtoa(b.ftom(a))},b.atom=function(){var a=/^([CDEFGABcdefgab])([-+#b]?)([0-9]?)$/,b={c:0,d:2,e:4,f:5,g:7,a:9,b:11},c=function(d){var e,f=0;if((e=d.match(a))!==null){f=b[e[1].toLowerCase()];switch(e[2]){case"+":case"#":++f;break;case"-":case"b":--f}f+=12*((e[3]|0)+2+c.octaveshift)}return f};c.octaveshift=0;return c}(),b.atof=function(a){return b.mtof(b.atom(a))},b.bpm2msec=function(a,b){typeof b=="undefined"&&(b=4);return 60/a*(4/b)*1e3},b.msec2bpm=function(a,b){typeof b=="undefined"&&(b=4);return 60/(a/1e3)*(4/b)},b.msec2hz=function(a){return 1e3/a},b.hz2msec=function(a){return 1e3/a},b.bpm2hz=function(a,b){typeof b=="undefined"&&(b=4);return 1e3/(60/a*(4/b)*1e3)},b.hz2bpm=function(a,b){typeof b=="undefined"&&(b=4);return 60/(1e3/msec/1e3)*(4/b)},b.num2db=function(a){return-20*Math.log(a)*Math.LOG10E},b.db2num=function(a){return Math.pow(10,a/-20)},b.$exports.converter=["mtof","ftom","mtoa","ftoa","atom","atof","bpm2msec","msec2bpm","msec2hz","msec2hz","bpm2hz","hz2bpm"],b.range=function(){var a,b,c,d,e=[];switch(arguments.length){case 1:a=0,b=arguments[0]|0,c=1;break;case 2:a=arguments[0]|0,b=arguments[1]|0,c=1;break;case 3:a=arguments[0]|0,b=arguments[1]|0,c=arguments[2]|0}if(c>0)for(d=a;db;d+=c)e.push(d);return e},function(a){var c=function(a){var b=new Uint32Array(32);this.seed=function(a){var c;typeof a!="number"&&(a=+(new Date)*1e3+Math.random()*1e3),a|=0,b[0]=3,b[1]=a;for(c=2;c<=31;++c)a=16807*a&2147483647,b[c]=a;for(c=310;c--;)this.next()},this.next=function(){var a=b[0];a=a===31?1:a+1,b[0]=a,b[a]+=a>3?b[a-3]:b[a+31-3];return(b[a]>>>1)/2147483647},this.seed(a)};a.Random=c;var d=new c,e=function(a){d.seed(a)};a.seed=e;var f=function(){return h(b.range.apply(null,arguments))};a.randrange=f;var g=function(a,b){return a+(b-a+1)*d.next()|0};a.randint=g;var h=function(a){return a[a.length*d.next()|0]};a.choice=h;var i=function(a,b){var e;typeof b=="number"?e=new c(b):e=d,a.sort(function(){return e.next()-e.next()});return a};a.shuffle=i;var a=function(){return d.next()};a.random=a;var j=function(a,b){return a+(b-a)*d.next()};a.uniform=j,b.$exports.random=["random"]}(b.random={});var c=function(){var a=function(){d.apply(this,arguments)},b=a.prototype,c={get:function(a){return c[a]||function(){var b=function(){var b,c,d,e,f;b=new Int16Array(a),f=a>>1,c=d=0;for(;;){b[c]=d;if(++c>=a)break;e=f;while(e<=d)d-=e,e>>=1;d+=e}return b}(),d,e=Math.floor(Math.log(a)/Math.LN2),f=new Float32Array((1<>1;if(c===2||c===4||c===8||c===16||c===32||c===64)for(var d=0,e=0;d>=4)d[h+1]=(c&15)/16;var j=0,k;for(h=0;h<8;++h){var l=0,m=(h+1)/1024;for(i=0;i<1024;++i)b[i]+=f(e*l)*d[h],l+=m,j<(k=g(b[i]))&&(j=k)}if(j>0)for(h=1024;h--;)b[h]/=j}return b},function(b){var c=function(a,b){typeof a=="function"?a(b):typeof a=="object"&&(a.buffer=b)},d=function(a,b){if(typeof a=="string"){var d=new XMLHttpRequest;d.open("GET",a,!0),d.responseType="arraybuffer",d.onload=function(){c(b,d.response)},d.send()}},e=function(a,b){var c;typeof a=="string"&&((c=/^(https?):\/\/(.*?)(\/.*)?$/.exec(a))!==null?f(c[1],{host:c[2],path:c[3]||""},b):g(a,b))},f=function(a,b,d){require(a).get(b,function(a){var b,e;a.statusCode===200&&(b=new ArrayBuffer(a.headers["content-length"]),e=0,a.on("data",function(a){var c,d;for(c=0,d=a.length;c>1)/l;if(h>a.length-44){b(0,null,c,"HeaderError: not exists data");return}d=new Int16Array(p*l|0),o===8?q=new Int8Array(a.buffer,44):o===16?q=new Int16Array(a.buffer,44):o===32?q=new Int32Array(a.buffer,44):o===24&&(q=function(){var b,c,d,e,f,g,h,i,j;b=new Int32Array((a.length-44)/3),j=0;for(h=44,i=a.length;h=i&&(a.process(),j-=i),m=j|0,n=1-(j-m),p=c[m],q=(1-n)*k+n*p,k=p,f[r]=q,p=e[m],q=(1-n)*l+n*p,l=p,g[r]=q,j+=d;this.x=j,this.prevL=k,this.prevR=l}.bind(this)}return this},this.on=function(){this.x=this.streamsize,this.prevL=this.prevR=0,this.node=this.ctx.createJavaScriptNode(a.streamsize,1,a.channels),this.node.onaudioprocess=this.onaudioprocess,this.node.connect(this.ctx.destination)},this.off=function(){this.node.disconnect(),this.node=null};return this},e=function(a){this.timer=new c,this.setup=function(){b.fn._setupTimbre(44100),this.audio=new Audio,this.audio.mozSetup(b.channels,b.samplerate),b.samplerate=this.audio.mozSampleRate,b.channels=this.audio.mozChannels,this.interleaved=new Float32Array(b.streamsize*b.channels),this.onaudioprocess=function(){var b=this.audio.mozCurrentSampleOffset(),c=this.interleaved;this.audio.mozWriteAudio(c),a.process();var d=a.L,e=a.R,f=c.length,g=d.length;while(g--)c[--f]=e[g],c[--f]=d[g]}.bind(this);return this},this.on=function(){var a=b.streamsize/b.samplerate*1e3;this.timer.setInterval(this.onaudioprocess,a)},this.off=function(){var a=this.interleaved;for(var b=a.length;b--;)a[b]=0;this.timer.clearInterval()};return this};typeof webkitAudioContext=="function"?(b.env="webkit",b.sys.bind(d)):typeof webkitAudioContext=="object"?(b.env="webkit",b.sys.bind(d)):typeof Audio=="function"&&typeof (new Audio).mozSetup=="function"&&(b.env="moz",b.sys.bind(e)),b.utils.relpath2rootpath=function(b){if(/^https?:\/\//.test(b))return b;if(b[0]==="/")return b;var c=a.location.pathname;c=c.substr(0,c.lastIndexOf("/")),c=c.split("/").filter(function(a){return a!==""}),b=b.split("/");for(var d=0;d=j&&(a.process(),k-=j),n=k|0,o=1-(k-n),q=c[n],r=(1-o)*l+o*q,l=q,g[s]=r,q=e[n],r=(1-o)*m+o*q,m=q,h[s]=r,k+=f;d.x=k,d.prevL=l,d.prevR=m}),this.jsnode.onaudioprocess=g;return this},this.on=function(){this.x=this.streamsize,this.prevL=this.prevR=0,this.jsnode.start()},this.off=function(){this.jsnode.stop()}},e=function(a){this.timerId=0,this.setup=function(){b.fn._setupTimbre(44100),this.interval=b.streamsize*1e3/b.samplerate,this.onaudioprocess=function(){a.process()}.bind(this);return this},this.on=function(){this.timerId!==0&&clearInterval(this.timerId),this.timerId=setInterval(this.onaudioprocess,this.interval)},this.off=function(){this.timerId!==0&&clearInterval(this.timerId)};return this};try{c=require("ctimbre")}catch(f){c=null}c!==null?(b.env="ctimbre",b.sys.bind(d)):(b.env="nop",b.sys.bind(e))}(a,b),b.isEnabled=!!b.sys._.impl;return b}(this) \ No newline at end of file