diff --git a/build/Tone.min.js b/build/Tone.min.js index 9c496702..86454a84 100644 --- a/build/Tone.min.js +++ b/build/Tone.min.js @@ -1,11 +1,11 @@ -!function(root){"use strict";function MainModule(a){Tone=a()}function ToneModule(a){a(Tone)}var Tone;/** +!function(root){"use strict";function ToneCore(a){Tone=a()}function ToneModule(a){a(Tone)}var Tone;/** * Tone.js * @author Yotam Mann * @license http://opensource.org/licenses/MIT MIT License * @copyright 2014-2015 Yotam Mann */ -MainModule(function(){function a(a){return void 0===a}function b(a){return"function"==typeof a}var c,d,e,f;if(a(window.AudioContext)&&(window.AudioContext=window.webkitAudioContext),a(window.OfflineAudioContext)&&(window.OfflineAudioContext=window.webkitOfflineAudioContext),a(AudioContext))throw new Error("Web Audio is not supported in this browser");return c=new AudioContext,b(AudioContext.prototype.createGain)||(AudioContext.prototype.createGain=AudioContext.prototype.createGainNode),b(AudioContext.prototype.createDelay)||(AudioContext.prototype.createDelay=AudioContext.prototype.createDelayNode),b(AudioContext.prototype.createPeriodicWave)||(AudioContext.prototype.createPeriodicWave=AudioContext.prototype.createWaveTable),b(AudioBufferSourceNode.prototype.start)||(AudioBufferSourceNode.prototype.start=AudioBufferSourceNode.prototype.noteGrainOn),b(AudioBufferSourceNode.prototype.stop)||(AudioBufferSourceNode.prototype.stop=AudioBufferSourceNode.prototype.noteOff),b(OscillatorNode.prototype.start)||(OscillatorNode.prototype.start=OscillatorNode.prototype.noteOn),b(OscillatorNode.prototype.stop)||(OscillatorNode.prototype.stop=OscillatorNode.prototype.noteOff),b(OscillatorNode.prototype.setPeriodicWave)||(OscillatorNode.prototype.setPeriodicWave=OscillatorNode.prototype.setWaveTable),AudioNode.prototype._nativeConnect=AudioNode.prototype.connect,AudioNode.prototype.connect=function(b,c,d){if(b.input)Array.isArray(b.input)?(a(d)&&(d=0),this.connect(b.input[d])):this.connect(b.input,c,d);else try{b instanceof AudioNode?this._nativeConnect(b,c,d):this._nativeConnect(b,c)}catch(e){throw new Error("error connecting to node: "+b)}},d=function(b,c){a(b)||1===b?this.input=this.context.createGain():b>1&&(this.input=new Array(b)),a(c)||1===c?this.output=this.context.createGain():c>1&&(this.output=new Array(b))},d.prototype.set=function(b,c,e){var f,g,h;"object"==typeof b?e=c:"string"==typeof b&&(f={},f[b]=c,b=f);for(g in b)h=this[g],a(h)||(c=b[g],h instanceof d.Signal?h.value!==c&&(a(e)?h.value=c:h.rampTo(c,e)):h instanceof AudioParam?h.value!==c&&(h.value=c):h instanceof d?h.set(c):h!==c&&(this[g]=c));return this},d.prototype.get=function(c){var e,f,g,h;for(a(c)&&(c=this._collectDefaults(this.constructor)),e={},f=0;f1)for(a=arguments[0],b=1;b1)for(a=1;a0)for(a=this,b=0;b0)for(var a=0;ac){var d=c;c=b,b=d}else if(b==c)return 0;return(a-b)/(c-b)},d.prototype.equalPowerScale=function(a){var b=.5*Math.PI;return Math.sin(a*b)},d.prototype.dbToGain=function(a){return Math.pow(2,a/6)},d.prototype.gainToDb=function(a){return 20*(Math.log(a)/Math.LN10)},d.prototype.now=function(){return this.context.currentTime},d.prototype.samplesToSeconds=function(a){return a/this.context.sampleRate},d.prototype.toSamples=function(a){var b=this.toSeconds(a);return Math.round(b*this.context.sampleRate)},d.prototype.toSeconds=function(a,b){if(b=this.defaultArg(b,this.now()),"number"==typeof a)return a;if("string"==typeof a){var c=0;return"+"===a.charAt(0)&&(a=a.slice(1),c=b),parseFloat(a)+c}return b},d.prototype.isFrequency=function(){var a=new RegExp(/\d*\.?\d+hz$/i);return function(b){return a.test(b)}}(),d.prototype.frequencyToSeconds=function(a){return 1/parseFloat(a)},d.prototype.secondsToFrequency=function(a){return 1/a},d.extend=function(b,c){function e(){}a(c)&&(c=d),e.prototype=c.prototype,b.prototype=new e,b.prototype.constructor=b,b._super=c},f=[],d._initAudioContext=function(a){a(d.context),f.push(a)},d.setContext=function(a){d.prototype.context=a,d.context=a;for(var b=0;bb;b++)d=b/c*2-1,this._curve[b]=a(d,b);return this._shaper.curve=this._curve,this},Object.defineProperty(a.WaveShaper.prototype,"curve",{get:function(){return this._shaper.curve},set:function(a){if(this._isSafari()){var b=a[0];a.unshift(b)}this._curve=new Float32Array(a),this._shaper.curve=this._curve}}),Object.defineProperty(a.WaveShaper.prototype,"oversample",{get:function(){return this._shaper.oversample},set:function(a){this._shaper.oversample=a}}),a.WaveShaper.prototype._isSafari=function(){var a=navigator.userAgent.toLowerCase();return-1!==a.indexOf("safari")&&-1===a.indexOf("chrome")},a.WaveShaper.prototype.dispose=function(){return a.prototype.dispose.call(this),this._shaper.disconnect(),this._shaper=null,this._curve=null,this},a.WaveShaper}),ToneModule(function(a){return a.Signal=function(b,c){this.units=this.defaultArg(c,a.Signal.Units.Number),this.output=this._scaler=this.context.createGain(),this.input=this._value=this._scaler.gain,b instanceof AudioParam?(this._scaler.connect(b),b.value=0):this.value=this.defaultArg(b,a.Signal.defaults.value),a.Signal._constant.chain(this._scaler)},a.extend(a.Signal,a.SignalBase),a.Signal.defaults={value:0},Object.defineProperty(a.Signal.prototype,"value",{get:function(){return this._toUnits(this._value.value)},set:function(a){var b=this._fromUnits(a);this.cancelScheduledValues(0),this._value.value=b}}),a.Signal.prototype._fromUnits=function(b){switch(this.units){case a.Signal.Units.Time:return this.toSeconds(b);case a.Signal.Units.Frequency:return this.toFrequency(b);case a.Signal.Units.Decibels:return this.dbToGain(b);case a.Signal.Units.Normal:return Math.min(Math.max(b,0),1);case a.Signal.Units.Audio:return Math.min(Math.max(b,-1),1);default:return b}},a.Signal.prototype._toUnits=function(b){switch(this.units){case a.Signal.Units.Decibels:return this.gainToDb(b);default:return b}},a.Signal.prototype.setValueAtTime=function(a,b){return a=this._fromUnits(a),this._value.setValueAtTime(a,this.toSeconds(b)),this},a.Signal.prototype.setCurrentValueNow=function(a){a=this.defaultArg(a,this.now());var b=this._value.value;return this.cancelScheduledValues(a),this._value.setValueAtTime(b,a),this},a.Signal.prototype.linearRampToValueAtTime=function(a,b){return a=this._fromUnits(a),this._value.linearRampToValueAtTime(a,this.toSeconds(b)),this},a.Signal.prototype.exponentialRampToValueAtTime=function(a,b){return a=this._fromUnits(a),a=Math.max(1e-5,a),this._value.exponentialRampToValueAtTime(a,this.toSeconds(b)),this},a.Signal.prototype.exponentialRampToValueNow=function(a,b){var c=this.now();return this.setCurrentValueNow(c),this.exponentialRampToValueAtTime(a,c+this.toSeconds(b)),this},a.Signal.prototype.linearRampToValueNow=function(a,b){var c=this.now();return this.setCurrentValueNow(c),this.linearRampToValueAtTime(a,c+this.toSeconds(b)),this},a.Signal.prototype.setTargetAtTime=function(a,b,c){return a=this._fromUnits(a),this._value.setTargetAtTime(a,this.toSeconds(b),c),this},a.Signal.prototype.setValueCurveAtTime=function(a,b,c){for(var d=0;d=a?0:1}),this._scale=this.input=new a.Multiply(1e4),this._scale.connect(this._thresh)},a.extend(a.GreaterThanZero,a.SignalBase),a.GreaterThanZero.prototype.dispose=function(){return a.prototype.dispose.call(this),this._scale.dispose(),this._scale=null,this._thresh.dispose(),this._thresh=null,this},a.GreaterThanZero}),ToneModule(function(a){return a.EqualZero=function(){this._scale=this.input=new a.Multiply(1e4),this._thresh=new a.WaveShaper(function(a){return 0===a?1:0},128),this._gtz=this.output=new a.GreaterThanZero,this._scale.chain(this._thresh,this._gtz)},a.extend(a.EqualZero,a.SignalBase),a.EqualZero.prototype.dispose=function(){return a.prototype.dispose.call(this),this._gtz.dispose(),this._gtz=null,this._scale.dispose(),this._scale=null,this._thresh.dispose(),this._thresh=null,this},a.EqualZero}),ToneModule(function(a){return a.Equal=function(b){a.call(this,2,0),this._sub=this.input[0]=new a.Subtract(b),this._equals=this.output=new a.EqualZero,this._sub.connect(this._equals),this.input[1]=this._sub.input[1]},a.extend(a.Equal,a.SignalBase),Object.defineProperty(a.Equal.prototype,"value",{get:function(){return this._sub.value},set:function(a){this._sub.value=a}}),a.Equal.prototype.dispose=function(){return a.prototype.dispose.call(this),this._equals.disconnect(),this._equals=null,this._sub.dispose(),this._sub=null,this},a.Equal}),ToneModule(function(a){a.Select=function(c){var d,e;for(c=this.defaultArg(c,2),a.call(this,c,1),this.gate=new a.Signal(0),d=0;c>d;d++)e=new b(d),this.input[d]=e,this.gate.connect(e.selecter),e.connect(this.output)},a.extend(a.Select,a.SignalBase),a.Select.prototype.select=function(a,b){return a=Math.floor(a),this.gate.setValueAtTime(a,this.toSeconds(b)),this},a.Select.prototype.dispose=function(){this.gate.dispose();for(var b=0;bc;c++)this.input[c]=this._sum;this._sum.connect(this._gtz)},a.extend(a.OR,a.SignalBase),a.OR.prototype.dispose=function(){return a.prototype.dispose.call(this),this._gtz.dispose(),this._gtz=null,this._sum.disconnect(),this._sum=null,this},a.OR}),ToneModule(function(a){return a.AND=function(b){b=this.defaultArg(b,2),a.call(this,b,0),this._equals=this.output=new a.Equal(b);for(var c=0;b>c;c++)this.input[c]=this._equals},a.extend(a.AND,a.SignalBase),a.AND.prototype.dispose=function(){return a.prototype.dispose.call(this),this._equals.dispose(),this._equals=null,this},a.AND}),ToneModule(function(a){return a.NOT=a.EqualZero,a.NOT}),ToneModule(function(a){return a.GreaterThan=function(b){a.call(this,2,0),this._value=this.input[0]=new a.Subtract(b),this.input[1]=this._value.input[1],this._gtz=this.output=new a.GreaterThanZero,this._value.connect(this._gtz)},a.extend(a.GreaterThan,a.Signal),a.GreaterThan.prototype.dispose=function(){return a.prototype.dispose.call(this),this._value.dispose(),this._value=null,this._gtz.dispose(),this._gtz=null,this},a.GreaterThan}),ToneModule(function(a){return a.LessThan=function(b){a.call(this,2,0),this._neg=this.input[0]=new a.Negate,this._gt=this.output=new a.GreaterThan,this._rhNeg=new a.Negate,this._value=this.input[1]=new a.Signal(b),this._neg.connect(this._gt),this._value.connect(this._rhNeg),this._rhNeg.connect(this._gt,0,1)},a.extend(a.LessThan,a.Signal),a.LessThan.prototype.dispose=function(){return a.prototype.dispose.call(this),this._neg.dispose(),this._neg=null,this._gt.dispose(),this._gt=null,this._rhNeg.dispose(),this._rhNeg=null,this._value.dispose(),this._value=null,this},a.LessThan}),ToneModule(function(a){return a.Abs=function(){a.call(this,1,0),this._ltz=new a.LessThan(0),this._switch=this.output=new a.Select(2),this._negate=new a.Negate,this.input.connect(this._switch,0,0),this.input.connect(this._negate),this._negate.connect(this._switch,0,1),this.input.chain(this._ltz,this._switch.gate)},a.extend(a.Abs,a.SignalBase),a.Abs.prototype.dispose=function(){return a.prototype.dispose.call(this),this._switch.dispose(),this._switch=null,this._ltz.dispose(),this._ltz=null,this._negate.dispose(),this._negate=null,this},a.Abs}),ToneModule(function(a){return a.Max=function(b){a.call(this,2,0),this.input[0]=this.context.createGain(),this._value=this.input[1]=new a.Signal(b),this._ifThenElse=this.output=new a.IfThenElse,this._gt=new a.GreaterThan,this.input[0].chain(this._gt,this._ifThenElse.if),this.input[0].connect(this._ifThenElse.then),this._value.connect(this._ifThenElse.else),this._value.connect(this._gt,0,1)},a.extend(a.Max,a.Signal),a.Max.prototype.dispose=function(){return a.prototype.dispose.call(this),this._value.dispose(),this._ifThenElse.dispose(),this._gt.dispose(),this._value=null,this._ifThenElse=null,this._gt=null,this},a.Max}),ToneModule(function(a){return a.Min=function(b){a.call(this,2,0),this.input[0]=this.context.createGain(),this._ifThenElse=this.output=new a.IfThenElse,this._lt=new a.LessThan,this._value=this.input[1]=new a.Signal(b),this.input[0].chain(this._lt,this._ifThenElse.if),this.input[0].connect(this._ifThenElse.then),this._value.connect(this._ifThenElse.else),this._value.connect(this._lt,0,1)},a.extend(a.Min,a.Signal),a.Min.prototype.dispose=function(){return a.prototype.dispose.call(this),this._value.dispose(),this._ifThenElse.dispose(),this._lt.dispose(),this._value=null,this._ifThenElse=null,this._lt=null,this},a.Min}),ToneModule(function(a){return a.Modulo=function(b){a.call(this,1,1),this._shaper=new a.WaveShaper(Math.pow(2,16)),this._multiply=new a.Multiply,this._subtract=this.output=new a.Subtract,this._modSignal=new a.Signal(b),this.input.fan(this._shaper,this._subtract),this._modSignal.connect(this._multiply,0,0),this._shaper.connect(this._multiply,0,1),this._multiply.connect(this._subtract,0,1),this._setWaveShaper(b)},a.extend(a.Modulo,a.SignalBase),a.Modulo.prototype._setWaveShaper=function(a){this._shaper.setMap(function(b){var c=Math.floor((b+1e-4)/a);return c})},Object.defineProperty(a.Modulo.prototype,"value",{get:function(){return this._modSignal.value},set:function(a){this._modSignal.value=a,this._setWaveShaper(a)}}),a.Modulo.prototype.dispose=function(){return a.prototype.dispose.call(this),this._shaper.dispose(),this._shaper=null,this._multiply.dispose(),this._multiply=null,this._subtract.dispose(),this._subtract=null,this._modSignal.dispose(),this._modSignal=null,this},a.Modulo}),ToneModule(function(a){function b(a,b,c){var d=new a;return c._eval(b[0]).connect(d,0,0),c._eval(b[1]).connect(d,0,1),d}function c(a,b,c){var d=new a;return c._eval(b[0]).connect(d,0,0),d}function d(a){return a?parseFloat(a):void 0}function e(a){return a&&a.args?parseFloat(a.args):void 0}return a.Expr=function(){var a,b,c,d=this._replacements(Array.prototype.slice.call(arguments)),e=this._parseInputs(d);for(this._nodes=[],this.input=new Array(e),a=0;e>a;a++)this.input[a]=this.context.createGain();b=this._parseTree(d);try{c=this._eval(b)}catch(f){throw this._disposeNodes(),new Error("Could evaluate expression: "+d)}this.output=c},a.extend(a.Expr,a.SignalBase),a.Expr._Expressions={value:{signal:{regexp:/^\d+\.\d+|^\d+/,method:function(b){var c=new a.Signal(d(b));return c}},input:{regexp:/^\$\d/,method:function(a,b){return b.input[d(a.substr(1))]}}},glue:{"(":{regexp:/^\(/},")":{regexp:/^\)/},",":{regexp:/^,/}},func:{abs:{regexp:/^abs/,method:c.bind(this,a.Abs)},min:{regexp:/^min/,method:b.bind(this,a.Min)},max:{regexp:/^max/,method:b.bind(this,a.Max)},"if":{regexp:/^if/,method:function(b,c){var d=new a.IfThenElse;return c._eval(b[0]).connect(d.if),c._eval(b[1]).connect(d.then),c._eval(b[2]).connect(d.else),d}},gt0:{regexp:/^gt0/,method:c.bind(this,a.GreaterThanZero)},eq0:{regexp:/^eq0/,method:c.bind(this,a.EqualZero)},mod:{regexp:/^mod/,method:function(b,c){var d=e(b[1]),f=new a.Modulo(d);return c._eval(b[0]).connect(f),f}},pow:{regexp:/^pow/,method:function(b,c){var d=e(b[1]),f=new a.Pow(d);return c._eval(b[0]).connect(f),f}}},binary:{"+":{regexp:/^\+/,precedence:1,method:b.bind(this,a.Add)},"-":{regexp:/^\-/,precedence:1,method:function(d,e){return 1===d.length?c(a.Negate,d,e):b(a.Subtract,d,e)}},"*":{regexp:/^\*/,precedence:0,method:b.bind(this,a.Multiply)},">":{regexp:/^\>/,precedence:2,method:b.bind(this,a.GreaterThan)},"<":{regexp:/^0;)b=b.trim(),d=c(b),f.push(d),b=b.substr(d.value.length);return{next:function(){return f[++e]},peek:function(){return f[e+1]}}},a.Expr.prototype._parseTree=function(b){function c(a,b){return!k(a)&&"glue"===a.type&&a.value===b}function d(b,c,d){var e,f,g=!1,h=a.Expr._Expressions[c];if(!k(b))for(e in h)if(f=h[e],f.regexp.test(b.value)){if(k(d))return!0;if(f.precedence===d)return!0}return g}function e(a){var b,c;for(k(a)&&(a=5),b=0>a?f():e(a-1),c=j.peek();d(c,"binary",a);)c=j.next(),b={operator:c.value,method:c.method,args:[b,e(a)]},c=j.peek();return b}function f(){var a,b;return a=j.peek(),d(a,"unary")?(a=j.next(),b=f(),{operator:a.value,method:a.method,args:[b]}):g()}function g(){var a,b;if(a=j.peek(),k(a))throw new SyntaxError("Unexpected termination of expression");if("func"===a.type)return a=j.next(),h(a);if("value"===a.type)return a=j.next(),{method:a.method,args:a.value};if(c(a,"(")){if(j.next(),b=e(),a=j.next(),!c(a,")"))throw new SyntaxError("Expected )");return b}throw new SyntaxError("Parse error, cannot process token "+a.value)}function h(a){var b,d=[];if(b=j.next(),!c(b,"("))throw new SyntaxError('Expected ( in a function call "'+a.value+'"');if(b=j.peek(),c(b,")")||(d=i()),b=j.next(),!c(b,")"))throw new SyntaxError('Expected ) in a function call "'+a.value+'"');return{method:a.method,args:d,name:name}}function i(){for(var a,b,d=[];;){if(b=e(),k(b))break;if(d.push(b),a=j.peek(),!c(a,","))break;j.next()}return d}var j=this._tokenize(b),k=this.isUndef.bind(this);return e()},a.Expr.prototype._eval=function(a){if(!this.isUndef(a)){var b=a.method(a.args,this);return this._nodes.push(b),b}},a.Expr.prototype._disposeNodes=function(){var a,b;for(a=0;ac;c++)d=this.context.createBiquadFilter(),d.type=this._type,this.frequency.connect(d.frequency),this.detune.connect(d.detune),this.Q.connect(d.Q),this.gain.connect(d.gain),this._filters[c]=d;e=[this.input].concat(this._filters).concat([this.output]),this.connectSeries.apply(this,e)}}),a.Filter.prototype.dispose=function(){a.prototype.dispose.call(this);for(var b=0;bc){for(this._highFrequencies=!0,f=Math.round(c/e*this._delayCount),g=0;f>g;g++)this._delays[g].delayTime.setValueAtTime(1/b+a,d);a=Math.floor(c)/b}else if(this._highFrequencies)for(this._highFrequencies=!1,h=0;h=c?a:b})},Object.defineProperty(a.Follower.prototype,"attack",{get:function(){return this._attack},set:function(a){this._attack=a,this._setAttackRelease(this._attack,this._release)}}),Object.defineProperty(a.Follower.prototype,"release",{get:function(){return this._release},set:function(a){this._release=a,this._setAttackRelease(this._attack,this._release)}}),a.Follower.prototype.connect=a.Signal.prototype.connect,a.Follower.prototype.dispose=function(){return a.prototype.dispose.call(this),this._filter.disconnect(),this._filter=null,this._frequencyValues.disconnect(),this._frequencyValues=null,this._delay.disconnect(),this._delay=null,this._sub.disconnect(),this._sub=null,this._abs.dispose(),this._abs=null,this._mult.dispose(),this._mult=null,this._curve=null,this},a.Follower}),ToneModule(function(a){return a.Gate=function(){a.call(this);var b=this.optionsObject(arguments,["threshold","attack","release"],a.Gate.defaults);this._follower=new a.Follower(b.attack,b.release),this._gt=new a.GreaterThan(this.dbToGain(b.threshold)),this.input.connect(this.output),this.input.chain(this._gt,this._follower,this.output.gain)},a.extend(a.Gate),a.Gate.defaults={attack:.1,release:.1,threshold:-40},Object.defineProperty(a.Gate.prototype,"threshold",{get:function(){return this.gainToDb(this._gt.value)},set:function(a){this._gt.value=this.dbToGain(a)}}),Object.defineProperty(a.Gate.prototype,"attack",{get:function(){return this._follower.attack},set:function(a){this._follower.attack=a}}),Object.defineProperty(a.Gate.prototype,"release",{get:function(){return this._follower.release},set:function(a){this._follower.release=a}}),a.Gate.prototype.dispose=function(){return a.prototype.dispose.call(this),this._follower.dispose(),this._gt.dispose(),this._follower=null,this._gt=null,this},a.Gate}),ToneModule(function(a){return a.Clock=function(b,c){this._oscillator=null,this._jsNode=this.context.createScriptProcessor(this.bufferSize,1,1),this._jsNode.onaudioprocess=this._processBuffer.bind(this),this.frequency=new a.Signal(b),this._upTick=!1,this.tick=c,this._jsNode.noGC()},a.extend(a.Clock),a.Clock.prototype.start=function(a){if(!this._oscillator){this._oscillator=this.context.createOscillator(),this._oscillator.type="square",this._oscillator.connect(this._jsNode),this.frequency.connect(this._oscillator.frequency),this._upTick=!1;var b=this.toSeconds(a);this._oscillator.start(b)}return this},a.Clock.prototype.stop=function(a,b){var c,d;return this._oscillator&&(c=this.now(),d=this.toSeconds(a,c),this._oscillator.stop(d),this._oscillator=null,a?setTimeout(b,1e3*(d-c)):b()),this},a.Clock.prototype._processBuffer=function(a){var b,c,d=this.defaultArg(a.playbackTime,this.now()),e=this._jsNode.bufferSize,f=a.inputBuffer.getChannelData(0),g=this._upTick,h=this;for(b=0;e>b;b++)c=f[b],c>0&&!g?(g=!0,setTimeout(function(){var a=d+h.samplesToSeconds(b+2*e);return function(){h.tick&&h.tick(a)}}(),0)):0>c&&g&&(g=!1);this._upTick=g},a.Clock.prototype.dispose=function(){return this._jsNode.disconnect(),this.frequency.dispose(),this.frequency=null,this._oscillator&&(this._oscillator.disconnect(),this._oscillator=null),this._jsNode.onaudioprocess=function(){},this._jsNode=null,this.tick=null,this},a.Clock}),ToneModule(function(Tone){var tatum,timelineTicks,transportTicks,swingSubdivision,swingTatum,swingAmount,transportTimeSignature,loopStart,loopEnd,intervals,timeouts,transportTimeline,timelineProgress,SyncedSources,SyncedSignals,TransportState,processIntervals,processTimeouts,processTimeline,TimelineEventIDCounter,TimelineEvent,TransportConstructor;return Tone.Transport=function(){this._clock=new Tone.Clock(0,this._processTick.bind(this)),this.loop=!1,this.bpm=new Tone.Signal(120,Tone.Signal.Units.BPM),this._bpmMult=new Tone.Multiply(1/60*tatum),this.state=TransportState.STOPPED,this.bpm.chain(this._bpmMult,this._clock.frequency)},Tone.extend(Tone.Transport),Tone.Transport.defaults={bpm:120,swing:0,swingSubdivision:"16n",timeSignature:4,loopStart:0,loopEnd:"4m"},tatum=12,timelineTicks=0,transportTicks=0,swingSubdivision="16n",swingTatum=3,swingAmount=0,transportTimeSignature=4,loopStart=0,loopEnd=4*tatum,intervals=[],timeouts=[],transportTimeline=[],timelineProgress=0,SyncedSources=[],SyncedSignals=[],TransportState={STARTED:"started",PAUSED:"paused",STOPPED:"stopped"},Tone.Transport.prototype._processTick=function(a){this.state===TransportState.STARTED&&(swingAmount>0&&timelineTicks%tatum!==0&&timelineTicks%swingTatum===0&&(a+=this._ticksToSeconds(swingTatum)*swingAmount),processIntervals(a),processTimeouts(a),processTimeline(a),transportTicks+=1,timelineTicks+=1,this.loop&&timelineTicks===loopEnd&&this._setTicks(loopStart))},Tone.Transport.prototype._setTicks=function(a){var b,c;for(timelineTicks=a,b=0;b=a){timelineProgress=b;break}},processIntervals=function(a){var b,c,d;for(b=0,c=intervals.length;c>b;b++)d=intervals[b],d.testInterval(transportTicks)&&d.doCallback(a)},processTimeouts=function(a){var b,c,d,e,f=0;for(b=0,c=timeouts.length;c>b;b++)if(d=timeouts[b],e=d.callbackTick(),transportTicks>=e)d.doCallback(a),f++;else if(e>transportTicks)break;timeouts.splice(0,f)},processTimeline=function(a){var b,c,d,e;for(b=timelineProgress,c=transportTimeline.length;c>b;b++)if(d=transportTimeline[b],e=d.callbackTick(),e===timelineTicks)timelineProgress=b,d.doCallback(a);else if(e>timelineTicks)break},Tone.Transport.prototype.setInterval=function(a,b,c){var d=this._toTicks(b),e=new TimelineEvent(a,c,d,transportTicks);return intervals.push(e),e.id},Tone.Transport.prototype.clearInterval=function(a){var b,c;for(b=0;b0;return intervals=[],a},Tone.Transport.prototype.setTimeout=function(a,b,c){var d,e,f,g=this._toTicks(b),h=new TimelineEvent(a,c,g+transportTicks,0);for(d=0,e=timeouts.length;e>d;d++)if(f=timeouts[d],f.callbackTick()>h.callbackTick())return timeouts.splice(d,0,h),h.id;return timeouts.push(h),h.id},Tone.Transport.prototype.clearTimeout=function(a){var b,c;for(b=0;b0;return timeouts=[],a},Tone.Transport.prototype.setTimeline=function(a,b,c){var d,e,f,g=this._toTicks(b),h=new TimelineEvent(a,c,g,0);for(d=timelineProgress,e=transportTimeline.length;e>d;d++)if(f=transportTimeline[d],f.callbackTick()>h.callbackTick())return transportTimeline.splice(d,0,h),h.id;return transportTimeline.push(h),h.id},Tone.Transport.prototype.clearTimeline=function(a){var b,c;for(b=0;b0;return transportTimeline=[],a},Tone.Transport.prototype._toTicks=function(a){var b=this.toSeconds(a),c=this.notationToSeconds("4n"),d=b/c,e=d*tatum;return Math.round(e)},Tone.Transport.prototype._ticksToSeconds=function(a,b,c){a=Math.floor(a);var d=this.notationToSeconds("4n",b,c);return d*a/tatum},Tone.Transport.prototype.nextBeat=function(a){var b,c,d;return a=this.defaultArg(a,"4n"),b=this._toTicks(a),c=transportTicks%b,d=c,c>0&&(d=b-c),this._ticksToSeconds(d)},Tone.Transport.prototype.start=function(a,b){var c,d,e,f;if(this.state===TransportState.STOPPED||this.state===TransportState.PAUSED)for(this.isUndef(b)||this._setTicks(this._toTicks(b)),this.state=TransportState.STARTED,c=this.toSeconds(a),this._clock.start(c),d=0;d1){for(originalTime=time,i=0;ib?a.Source.State.STARTED:this._nextStop<=b?a.Source.State.STOPPED:a.Source.State.STOPPED},a.Source.prototype.start=function(b){return b=this.toSeconds(b),(this._stateAtTime(b)!==a.Source.State.STARTED||this.retrigger)&&(this._nextStart=b,this._nextStop=1/0,this._start.apply(this,arguments)),this},a.Source.prototype.stop=function(b){var c,d=this.now();return b=this.toSeconds(b,d),this._stateAtTime(b)===a.Source.State.STARTED&&(this._nextStop=this.toSeconds(b),clearTimeout(this._timeout),c=b-d,c>0?this._timeout=setTimeout(this.onended,1e3*c+20):this.onended(),this._stop.apply(this,arguments)),this},a.Source.prototype.pause=function(a){return this.stop(a),this},a.Source.prototype.sync=function(b){return a.Transport.syncSource(this,b),this},a.Source.prototype.unsync=function(){return a.Transport.unsyncSource(this),this},a.Source.prototype.dispose=function(){a.prototype.dispose.call(this),this.stop(),clearTimeout(this._timeout),this.onended=function(){},this.volume.dispose(),this.volume=null},a.Source}),ToneModule(function(a){return a.Oscillator=function(){var b=this.optionsObject(arguments,["frequency","type"],a.Oscillator.defaults);a.Source.call(this,b),this._oscillator=null,this.frequency=new a.Signal(b.frequency,a.Signal.Units.Frequency),this.detune=new a.Signal(b.detune),this._wave=null,this._phase=b.phase,this._type=null,this.type=b.type,this.phase=this._phase},a.extend(a.Oscillator,a.Source),a.Oscillator.defaults={type:"sine",frequency:440,detune:0,phase:0},a.Oscillator.prototype._start=function(a){this._oscillator=this.context.createOscillator(),this._oscillator.setPeriodicWave(this._wave),this._oscillator.connect(this.output),this.frequency.connect(this._oscillator.frequency),this.detune.connect(this._oscillator.detune),this._oscillator.start(this.toSeconds(a))},a.Oscillator.prototype._stop=function(a){return this._oscillator&&(this._oscillator.stop(this.toSeconds(a)),this._oscillator=null),this},a.Oscillator.prototype.syncFrequency=function(){return a.Transport.syncSignal(this.frequency),this},a.Oscillator.prototype.unsyncFrequency=function(){return a.Transport.unsyncSignal(this.frequency),this},Object.defineProperty(a.Oscillator.prototype,"type",{get:function(){return this._type},set:function(a){var b,c,d,e,f,g,h,i,j;if(this.type!==a){for(b=4096,c=b/2,d=new Float32Array(c),e=new Float32Array(c),d[0]=0,e[0]=0,f=this._phase,g=1;c>g;++g){switch(h=2/(g*Math.PI),a){case"sine":i=1===g?1:0;break;case"square":i=1&g?2*h:0;break;case"sawtooth":i=h*(1&g?1:-1);break;case"triangle":i=1&g?2*h*h*(g-1>>1&1?-1:1):0;break;default:throw new TypeError("invalid oscillator type: "+a)}0!==i?(d[g]=-i*Math.sin(f),e[g]=i*Math.cos(f)):(d[g]=0,e[g]=0)}j=this.context.createPeriodicWave(d,e),this._wave=j,null!==this._oscillator&&this._oscillator.setPeriodicWave(this._wave),this._type=a}}}),Object.defineProperty(a.Oscillator.prototype,"phase",{get:function(){return this._phase*(180/Math.PI)},set:function(a){this._phase=a*Math.PI/180,this.type=this._type}}),a.Oscillator.prototype.dispose=function(){return a.Source.prototype.dispose.call(this),null!==this._oscillator&&(this._oscillator.disconnect(),this._oscillator=null),this.frequency.dispose(),this.frequency=null,this.detune.dispose(),this.detune=null,this._wave=null,this},a.Oscillator}),ToneModule(function(a){return a.AudioToGain=function(){this._norm=this.input=this.output=new a.WaveShaper([0,1])},a.extend(a.AudioToGain,a.SignalBase),a.AudioToGain.prototype.dispose=function(){return a.prototype.dispose.call(this),this._norm.disconnect(),this._norm=null,this},a.AudioToGain}),ToneModule(function(a){return a.LFO=function(){var b=this.optionsObject(arguments,["frequency","min","max"],a.LFO.defaults);this.oscillator=new a.Oscillator({frequency:b.frequency,type:b.type,phase:b.phase}),this.frequency=this.oscillator.frequency,this.amplitude=this.oscillator.volume,this.amplitude.units=a.Signal.Units.Normal,this.amplitude.value=b.amplitude,this._a2g=new a.AudioToGain,this._scaler=this.output=new a.Scale(b.min,b.max),this.oscillator.chain(this._a2g,this._scaler)},a.extend(a.LFO,a.Oscillator),a.LFO.defaults={type:"sine",min:0,max:1,phase:0,frequency:"4n",amplitude:1},a.LFO.prototype.start=function(a){return this.oscillator.start(a),this},a.LFO.prototype.stop=function(a){return this.oscillator.stop(a),this},a.LFO.prototype.sync=function(a){return this.oscillator.sync(a),this.oscillator.syncFrequency(),this},a.LFO.prototype.unsync=function(){return this.oscillator.unsync(),this.oscillator.unsyncFrequency(),this},Object.defineProperty(a.LFO.prototype,"min",{get:function(){return this._scaler.min},set:function(a){this._scaler.min=a}}),Object.defineProperty(a.LFO.prototype,"max",{get:function(){return this._scaler.max},set:function(a){this._scaler.max=a}}),Object.defineProperty(a.LFO.prototype,"type",{get:function(){return this.oscillator.type},set:function(a){this.oscillator.type=a}}),Object.defineProperty(a.LFO.prototype,"phase",{get:function(){return this.oscillator.phase},set:function(a){this.oscillator.phase=a}}),a.LFO.prototype.connect=a.Signal.prototype.connect,a.LFO.prototype.dispose=function(){return a.prototype.dispose.call(this),this.oscillator.dispose(),this.oscillator=null,this._scaler.dispose(),this._scaler=null,this._a2g.dispose(),this._a2g=null,this.frequency=null,this.amplitude=null,this},a.LFO}),ToneModule(function(a){return a.Limiter=function(b){this._compressor=this.input=this.output=new a.Compressor({attack:1e-4,decay:1e-4,threshold:b}),this.threshold=this._compressor.threshold},a.extend(a.Limiter),a.Limiter.prototype.dispose=function(){return a.prototype.dispose.call(this),this._compressor.dispose(),this._compressor=null,this.threshold=null,this},a.Limiter}),ToneModule(function(a){a.LowpassCombFilter=function(){var c,d,e,f;for(a.call(this),c=this.optionsObject(arguments,["minDelay","maxDelay"],a.LowpassCombFilter.defaults),d=Math.ceil(this.bufferSize/(c.minDelay*this.context.sampleRate)),d=Math.min(d,10),d=Math.max(d,1),this._filterDelayCount=d,this._filterDelays=new Array(this._filterDelayCount),this.dampening=new a.Signal(c.dampening,a.Signal.Units.Frequency),this.resonance=new a.Signal(c.resonance,a.Signal.Units.Normal),this._resScale=new a.ScaleExp(.01,1/this._filterDelayCount-.001,.5),this._highFrequencies=!1,this._delayTime=c.delayTime,this._feedback=this.context.createGain(),e=0;ed){for(this._highFrequencies=!0,f=Math.round(d/e*this._filterDelayCount),g=0;f>g;g++)this._filterDelays[g].setDelay(1/c+this._delayTime,b);this._delayTime=Math.floor(d)/c}else if(this._highFrequencies)for(this._highFrequencies=!1,h=0;hh;h++)f=c[h],!g&&f>.95&&(g=!0,this._lastClip=Date.now()),e+=f,d+=f*f;i=e/k,j=Math.sqrt(d/k),this._volume[b]=Math.max(j,this._volume[b]*l),this._values[b]=i}},a.Meter.prototype.getLevel=function(a){a=this.defaultArg(a,0);var b=this._volume[a];return 1e-5>b?0:b},a.Meter.prototype.getValue=function(a){return a=this.defaultArg(a,0),this._values[a]},a.Meter.prototype.getDb=function(a){return this.gainToDb(this.getLevel(a))},a.Meter.prototype.isClipped=function(){return Date.now()-this._lastClipthis._recordEndSample?(this.state=b.STOPPED,this._callback(this._recordBuffers)):d>this._recordStartSample?(g=0,h=Math.min(this._recordEndSample-d,e),this._recordChannels(a.inputBuffer,g,h,e)):f>this._recordStartSample&&(h=f-this._recordStartSample,g=e-h,this._recordChannels(a.inputBuffer,g,h,e)))},a.Recorder.prototype._recordChannels=function(a,b,c,d){var e,f,g,h,i=this._recordBufferOffset,j=this._recordBuffers;for(e=0;eg;g++)h=g-b,j[e][h+i]=f[g];this._recordBufferOffset+=c},a.Recorder.prototype.record=function(a,c,d){if(this.state===b.STOPPED){this.clear(),this._recordBufferOffset=0,c=this.defaultArg(c,0),this._recordDuration=this.toSamples(a),this._recordStartSample=this.toSamples("+"+c),this._recordEndSample=this._recordStartSample+this._recordDuration;for(var e=0;e0){if(a.Buffer._currentDownloads.length0){for(b=0;g>b;b++)c=a.Buffer._currentDownloads[b],f+=c.progress;h=f}d=g-h,e=a.Buffer._totalDownloads-a.Buffer._queue.length-d,a.Buffer.onprogress(e/a.Buffer._totalDownloads)},a.Buffer.load=function(b,c){var d=new XMLHttpRequest;return d.open("GET",b,!0),d.responseType="arraybuffer",d.onload=function(){a.context.decodeAudioData(d.response,function(a){if(!a)throw new Error("could not decode audio data:"+b);c(a)})},d.send(),d},a.Buffer.onload=function(){},a.Buffer.onprogress=function(){},a.Buffer.onerror=function(){},a.Buffer}),ToneModule(function(a){var b={};return a.prototype.send=function(a,c){b.hasOwnProperty(a)||(b[a]=this.context.createGain());var d=this.context.createGain();return d.gain.value=this.defaultArg(c,1),this.output.chain(d,b[a]),d},a.prototype.receive=function(a,c){return b.hasOwnProperty(a)||(b[a]=this.context.createGain()),this.isUndef(c)&&(c=this.input),b[a].connect(c),this},a}),ToneModule(function(a){function b(a,b,d){var e,f,g,h;if(c.hasOwnProperty(a))for(e=c[a],f=0,g=e.length;g>f;f++)h=e[f],Array.isArray(d)?h.apply(window,[b].concat(d)):h(b,d)}var c,d,e,f;return a.Note=function(b,c,d){this.value=d,this._channel=b,this._timelineID=a.Transport.setTimeline(this._trigger.bind(this),c)},a.Note.prototype._trigger=function(a){b(this._channel,a,this.value)},a.Note.prototype.dispose=function(){return a.Tranport.clearTimeline(this._timelineID),this.value=null,this},c={},a.Note.route=function(a,b){c.hasOwnProperty(a)?c[a].push(b):c[a]=[b]},a.Note.unroute=function(a,b){var d,e;c.hasOwnProperty(a)&&(d=c[a],e=d.indexOf(b),-1!==e&&c[a].splice(e,1))},a.Note.parseScore=function(b){var c,d,e,f,g,h,i,j=[];for(c in b)if(d=b[c],"tempo"===c)a.Transport.bpm.value=d;else if("timeSignature"===c)a.Transport.timeSignature=d[0]/(d[1]/4);else{if(!Array.isArray(d))throw new TypeError("score parts must be Arrays");for(e=0;ed;++d)e=2*d/c-1,b[d]=0===e?0:this._getCoefficient(e,a,{});this._shaper.curve=b}}),Object.defineProperty(a.Chebyshev.prototype,"oversample",{get:function(){return this._shaper.oversample},set:function(a){this._shaper.oversample=a}}),a.Chebyshev.prototype.dispose=function(){return a.Effect.prototype.dispose.call(this),this._shaper.dispose(),this._shaper=null,this},a.Chebyshev}),ToneModule(function(a){return a.StereoEffect=function(){a.call(this);var b=this.optionsObject(arguments,["wet"],a.Effect.defaults);this._dryWet=new a.CrossFade(b.wet),this.wet=this._dryWet.fade,this._split=new a.Split,this.effectSendL=this._split.left,this.effectSendR=this._split.right,this._merge=new a.Merge,this.effectReturnL=this._merge.left,this.effectReturnR=this._merge.right,this.input.connect(this._split),this.input.connect(this._dryWet,0,0),this._merge.connect(this._dryWet,0,1),this._dryWet.connect(this.output)},a.extend(a.StereoEffect,a.Effect),a.StereoEffect.prototype.dispose=function(){return a.prototype.dispose.call(this),this._dryWet.dispose(),this._dryWet=null,this._split.dispose(),this._split=null,this._merge.dispose(),this._merge=null,this.effectSendL=null,this.effectSendR=null,this.effectReturnL=null,this.effectReturnR=null,this.wet=null,this},a.StereoEffect}),ToneModule(function(a){return a.FeedbackEffect=function(){var b=this.optionsObject(arguments,["feedback"]);b=this.defaultArg(b,a.FeedbackEffect.defaults),a.Effect.call(this,b),this.feedback=new a.Signal(b.feedback,a.Signal.Units.Normal),this._feedbackGain=this.context.createGain(),this.effectReturn.chain(this._feedbackGain,this.effectSend),this.feedback.connect(this._feedbackGain.gain)},a.extend(a.FeedbackEffect,a.Effect),a.FeedbackEffect.defaults={feedback:.125},a.FeedbackEffect.prototype.dispose=function(){return a.Effect.prototype.dispose.call(this),this.feedback.dispose(),this.feedback=null,this._feedbackGain.disconnect(),this._feedbackGain=null,this},a.FeedbackEffect}),ToneModule(function(a){return a.StereoXFeedbackEffect=function(){var b=this.optionsObject(arguments,["feedback"],a.FeedbackEffect.defaults);a.StereoEffect.call(this,b),this.feedback=new a.Signal(b.feedback),this._feedbackLR=this.context.createGain(),this._feedbackRL=this.context.createGain(),this.effectReturnL.chain(this._feedbackLR,this.effectSendR),this.effectReturnR.chain(this._feedbackRL,this.effectSendL),this.feedback.fan(this._feedbackLR.gain,this._feedbackRL.gain)},a.extend(a.StereoXFeedbackEffect,a.FeedbackEffect),a.StereoXFeedbackEffect.prototype.dispose=function(){return a.StereoEffect.prototype.dispose.call(this),this.feedback.dispose(),this.feedback=null,this._feedbackLR.disconnect(),this._feedbackLR=null,this._feedbackRL.disconnect(),this._feedbackRL=null,this},a.StereoXFeedbackEffect}),ToneModule(function(a){return a.Chorus=function(){var b=this.optionsObject(arguments,["frequency","delayTime","depth"],a.Chorus.defaults);a.StereoXFeedbackEffect.call(this,b),this._depth=b.depth,this._delayTime=b.delayTime/1e3,this._lfoL=new a.LFO(b.rate,0,1),this._lfoR=new a.LFO(b.rate,0,1),this._lfoR.phase=180,this._delayNodeL=this.context.createDelay(),this._delayNodeR=this.context.createDelay(),this.frequency=this._lfoL.frequency,this.connectSeries(this.effectSendL,this._delayNodeL,this.effectReturnL),this.connectSeries(this.effectSendR,this._delayNodeR,this.effectReturnR),this.effectSendL.connect(this.effectReturnL),this.effectSendR.connect(this.effectReturnR),this._lfoL.connect(this._delayNodeL.delayTime),this._lfoR.connect(this._delayNodeR.delayTime),this._lfoL.start(),this._lfoR.start(),this._lfoL.frequency.connect(this._lfoR.frequency),this.depth=this._depth,this.frequency.value=b.frequency,this.type=b.type},a.extend(a.Chorus,a.StereoXFeedbackEffect),a.Chorus.defaults={frequency:1.5,delayTime:3.5,depth:.7,feedback:.1,type:"sine"},Object.defineProperty(a.Chorus.prototype,"depth",{get:function(){return this._depth},set:function(a){this._depth=a;var b=this._delayTime*a;this._lfoL.min=this._delayTime-b,this._lfoL.max=this._delayTime+b,this._lfoR.min=this._delayTime-b,this._lfoR.max=this._delayTime+b}}),Object.defineProperty(a.Chorus.prototype,"delayTime",{get:function(){return 1e3*this._delayTime},set:function(a){this._delayTime=a/1e3,this.depth=this._depth}}),Object.defineProperty(a.Chorus.prototype,"type",{get:function(){return this._lfoL.type},set:function(a){this._lfoL.type=a,this._lfoR.type=a}}),a.Chorus.prototype.dispose=function(){return a.StereoXFeedbackEffect.prototype.dispose.call(this),this._lfoL.dispose(),this._lfoL=null,this._lfoR.dispose(),this._lfoR=null,this._delayNodeL.disconnect(),this._delayNodeL=null,this._delayNodeR.disconnect(),this._delayNodeR=null,this.frequency=null,this},a.Chorus}),ToneModule(function(a){return a.Convolver=function(b){a.Effect.apply(this,arguments),this._convolver=this.context.createConvolver(),this._buffer=new a.Buffer(b,function(a){this.buffer=a}.bind(this)),this.connectEffect(this._convolver)},a.extend(a.Convolver,a.Effect),Object.defineProperty(a.Convolver.prototype,"buffer",{get:function(){return this._buffer.get()},set:function(a){this._buffer.set(a),this._convolver.buffer=a}}),a.Convolver.prototype.load=function(a,b){return this._buffer.load(a,function(a){this.buffer=a,b&&b()}.bind(this)),this},a.Convolver.prototype.dispose=function(){return a.Effect.prototype.dispose.call(this),this._convolver.disconnect(),this._convolver=null,this._buffer.dispose(),this._buffer=null,this},a.Convolver}),ToneModule(function(a){return a.Distortion=function(){var b=this.optionsObject(arguments,["distortion"],a.Distortion.defaults);a.Effect.call(this),this._shaper=new a.WaveShaper(4096),this._distortion=b.distortion,this.connectEffect(this._shaper),this.distortion=b.distortion,this.oversample=b.oversample},a.extend(a.Distortion,a.Effect),a.Distortion.defaults={distortion:.4,oversample:"none"},Object.defineProperty(a.Distortion.prototype,"distortion",{get:function(){return this._distortion},set:function(a){var b,c;this._distortion=a,b=100*a,c=Math.PI/180,this._shaper.setMap(function(a){return Math.abs(a)<.001?0:(3+b)*a*20*c/(Math.PI+b*Math.abs(a))})}}),Object.defineProperty(a.Distortion.prototype,"oversample",{get:function(){return this._shaper.oversample},set:function(a){this._shaper.oversample=a}}),a.Distortion.prototype.dispose=function(){return a.Effect.prototype.dispose.call(this),this._shaper.dispose(),this._shaper=null,this},a.Distortion}),ToneModule(function(a){return a.FeedbackDelay=function(){var b=this.optionsObject(arguments,["delayTime","feedback"],a.FeedbackDelay.defaults);a.FeedbackEffect.call(this,b),this.delayTime=new a.Signal(b.delayTime,a.Signal.Units.Time),this._delayNode=this.context.createDelay(4),this.connectEffect(this._delayNode),this.delayTime.connect(this._delayNode.delayTime)},a.extend(a.FeedbackDelay,a.FeedbackEffect),a.FeedbackDelay.defaults={delayTime:.25},a.FeedbackDelay.prototype.dispose=function(){return a.FeedbackEffect.prototype.dispose.call(this),this.delayTime.dispose(),this._delayNode.disconnect(),this._delayNode=null,this.delayTime=null,this},a.FeedbackDelay}),ToneModule(function(a){var b=[1557/44100,1617/44100,1491/44100,1422/44100,1277/44100,1356/44100,1188/44100,1116/44100],c=[225,556,441,341];return a.Freeverb=function(){var d,e,f,g,h,i,j=this.optionsObject(arguments,["roomSize","dampening"],a.Freeverb.defaults);for(a.StereoEffect.call(this,j),this.roomSize=new a.Signal(j.roomSize),this.dampening=new a.Signal(j.dampening),this._dampeningScale=new a.ScaleExp(100,8e3,.5),this._combFilters=[],this._allpassFiltersL=[],this._allpassFiltersR=[],d=0;dd;d++)e=this.context.createBiquadFilter(),e.type="allpass",e.Q.value=c,b.connect(e.frequency),f[d]=e;return this.connectSeries.apply(this,f),f},Object.defineProperty(a.Phaser.prototype,"depth",{get:function(){return this._depth},set:function(a){this._depth=a;var b=this._baseFrequency+this._baseFrequency*a;this._lfoL.max=b,this._lfoR.max=b}}),Object.defineProperty(a.Phaser.prototype,"baseFrequency",{get:function(){return this._baseFrequency},set:function(a){this._baseFrequency=a,this._lfoL.min=a,this._lfoR.min=a,this.depth=this._depth}}),a.Phaser.prototype.dispose=function(){var b,c;for(a.StereoEffect.prototype.dispose.call(this),this._lfoL.dispose(),this._lfoL=null,this._lfoR.dispose(),this._lfoR=null,b=0;ba?-1:1}),this._sawtooth.chain(this._thresh,this.output),this.width.chain(this._widthGate,this._thresh)},a.extend(a.PulseOscillator,a.Oscillator),a.PulseOscillator.defaults={frequency:440,detune:0,phase:0,width:.2},a.PulseOscillator.prototype._start=function(a){a=this.toSeconds(a),this._sawtooth.start(a),this._widthGate.gain.setValueAtTime(1,a)},a.PulseOscillator.prototype._stop=function(a){a=this.toSeconds(a),this._sawtooth.stop(a),this._widthGate.gain.setValueAtTime(0,a)},Object.defineProperty(a.PulseOscillator.prototype,"phase",{get:function(){return this._sawtooth.phase},set:function(a){this._sawtooth.phase=a}}),Object.defineProperty(a.PulseOscillator.prototype,"type",{get:function(){return"pulse"}}),a.PulseOscillator.prototype.dispose=function(){return a.Source.prototype.dispose.call(this),this._sawtooth.dispose(),this._sawtooth=null,this.width.dispose(),this.width=null,this._widthGate.disconnect(),this._widthGate=null,this._thresh.disconnect(),this._thresh=null,this.frequency=null,this.detune=null,this},a.PulseOscillator}),ToneModule(function(a){return a.PWMOscillator=function(){var b=this.optionsObject(arguments,["frequency","modulationFrequency"],a.PWMOscillator.defaults);a.Source.call(this,b),this._pulse=new a.PulseOscillator(b.modulationFrequency),this._pulse._sawtooth.type="sine",this._modulator=new a.Oscillator({frequency:b.frequency,detune:b.detune}),this._scale=new a.Multiply(1.01),this.frequency=this._modulator.frequency,this.detune=this._modulator.detune,this.modulationFrequency=this._pulse.frequency,this._modulator.chain(this._scale,this._pulse.width),this._pulse.connect(this.output)},a.extend(a.PWMOscillator,a.Oscillator),a.PWMOscillator.defaults={frequency:440,detune:0,modulationFrequency:.4},a.PWMOscillator.prototype._start=function(a){a=this.toSeconds(a),this._modulator.start(a),this._pulse.start(a)},a.PWMOscillator.prototype._stop=function(a){a=this.toSeconds(a),this._modulator.stop(a),this._pulse.stop(a)},Object.defineProperty(a.PWMOscillator.prototype,"type",{get:function(){return"pwm"}}),Object.defineProperty(a.PWMOscillator.prototype,"phase",{get:function(){return this._modulator.phase},set:function(a){this._modulator.phase=a}}),a.PWMOscillator.prototype.dispose=function(){return a.Source.prototype.dispose.call(this),this._pulse.dispose(),this._pulse=null,this._scale.dispose(),this._scale=null,this._modulator.dispose(),this._modulator=null,this.frequency=null,this.detune=null,this.modulationFrequency=null,this},a.PWMOscillator}),ToneModule(function(a){a.OmniOscillator=function(){var b=this.optionsObject(arguments,["frequency","type"],a.OmniOscillator.defaults);a.Source.call(this,b),this.frequency=new a.Signal(b.frequency,a.Signal.Units.Frequency),this.detune=new a.Signal(b.detune),this._sourceType=void 0,this._oscillator=null,this.type=b.type},a.extend(a.OmniOscillator,a.Oscillator),a.OmniOscillator.defaults={frequency:440,detune:0,type:"sine",width:.4,modulationFrequency:.4};var b={PulseOscillator:"PulseOscillator",PWMOscillator:"PWMOscillator",Oscillator:"Oscillator"};return a.OmniOscillator.prototype._start=function(a){this._oscillator.start(a)},a.OmniOscillator.prototype._stop=function(a){this._oscillator.stop(a)},Object.defineProperty(a.OmniOscillator.prototype,"type",{get:function(){return this._oscillator.type},set:function(c){if("sine"===c||"square"===c||"triangle"===c||"sawtooth"===c)this._sourceType!==b.Oscillator&&(this._sourceType=b.Oscillator,this._createNewOscillator(a.Oscillator)),this._oscillator.type=c;else if("pwm"===c)this._sourceType!==b.PWMOscillator&&(this._sourceType=b.PWMOscillator,this._createNewOscillator(a.PWMOscillator));else{if("pulse"!==c)throw new TypeError("Tone.OmniOscillator does not support type "+c);this._sourceType!==b.PulseOscillator&&(this._sourceType=b.PulseOscillator,this._createNewOscillator(a.PulseOscillator))}}}),a.OmniOscillator.prototype._createNewOscillator=function(b){var c,d=this.now()+this.bufferTime;null!==this._oscillator&&(c=this._oscillator,c.stop(d),c.onended=function(){c.dispose(),c=null}),this._oscillator=new b,this.frequency.connect(this._oscillator.frequency),this.detune.connect(this._oscillator.detune),this._oscillator.connect(this.output),this.state===a.Source.State.STARTED&&this._oscillator.start(d)},Object.defineProperty(a.OmniOscillator.prototype,"phase",{get:function(){return this._oscillator.phase},set:function(a){this._oscillator.phase=a}}),Object.defineProperty(a.OmniOscillator.prototype,"width",{get:function(){return this._sourceType===b.PulseOscillator?this._oscillator.width:void 0}}),Object.defineProperty(a.OmniOscillator.prototype,"modulationFrequency",{get:function(){return this._sourceType===b.PWMOscillator?this._oscillator.modulationFrequency:void 0}}),a.OmniOscillator.prototype.dispose=function(){return a.Source.prototype.dispose.call(this),this.detune.dispose(),this.detune=null,this.frequency.dispose(),this.frequency=null,this._oscillator.dispose(),this._oscillator=null,this._sourceType=null,this},a.OmniOscillator}),ToneModule(function(a){return a.Instrument=function(){this.output=this.context.createGain(),this.volume=new a.Signal(this.output.gain,a.Signal.Units.Decibels)},a.extend(a.Instrument),a.Instrument.prototype.triggerAttack=function(){},a.Instrument.prototype.triggerRelease=function(){},a.Instrument.prototype.triggerAttackRelease=function(a,b,c,d){return c=this.toSeconds(c),b=this.toSeconds(b),this.triggerAttack(a,c,d),this.triggerRelease(c+b),this},a.Instrument.prototype.dispose=function(){return a.prototype.dispose.call(this),this.volume.dispose(),this.volume=null,this},a.Instrument}),ToneModule(function(a){return a.Monophonic=function(b){a.Instrument.call(this),b=this.defaultArg(b,a.Monophonic.defaults),this.portamento=b.portamento},a.extend(a.Monophonic,a.Instrument),a.Monophonic.defaults={portamento:0},a.Monophonic.prototype.triggerAttack=function(a,b,c){return b=this.toSeconds(b),this.triggerEnvelopeAttack(b,c),this.setNote(a,b),this},a.Monophonic.prototype.triggerRelease=function(a){return this.triggerEnvelopeRelease(a),this},a.Monophonic.prototype.triggerEnvelopeAttack=function(){},a.Monophonic.prototype.triggerEnvelopeRelease=function(){},a.Monophonic.prototype.setNote=function(a,b){var c,d;return b=this.toSeconds(b),this.portamento>0?(c=this.frequency.value,this.frequency.setValueAtTime(c,b),d=this.toSeconds(this.portamento),this.frequency.exponentialRampToValueAtTime(a,b+d)):this.frequency.setValueAtTime(a,b),this},a.Monophonic}),ToneModule(function(a){return a.MonoSynth=function(b){b=this.defaultArg(b,a.MonoSynth.defaults),a.Monophonic.call(this,b),this.oscillator=new a.OmniOscillator(b.oscillator),this.frequency=this.oscillator.frequency,this.detune=this.oscillator.detune,this.filter=new a.Filter(b.filter),this.filterEnvelope=new a.ScaledEnvelope(b.filterEnvelope),this.envelope=new a.AmplitudeEnvelope(b.envelope),this.oscillator.chain(this.filter,this.envelope,this.output),this.oscillator.start(),this.filterEnvelope.connect(this.filter.frequency)},a.extend(a.MonoSynth,a.Monophonic),a.MonoSynth.defaults={oscillator:{type:"square"},filter:{Q:6,type:"lowpass",rolloff:-24},envelope:{attack:.005,decay:.1,sustain:.9,release:1},filterEnvelope:{attack:.06,decay:.2,sustain:.5,release:2,min:20,max:4e3,exponent:2}},a.MonoSynth.prototype.triggerEnvelopeAttack=function(a,b){return this.envelope.triggerAttack(a,b),this.filterEnvelope.triggerAttack(a),this},a.MonoSynth.prototype.triggerEnvelopeRelease=function(a){return this.envelope.triggerRelease(a),this.filterEnvelope.triggerRelease(a),this},a.MonoSynth.prototype.dispose=function(){return a.Monophonic.prototype.dispose.call(this),this.oscillator.dispose(),this.oscillator=null,this.envelope.dispose(),this.envelope=null,this.filterEnvelope.dispose(),this.filterEnvelope=null,this.filter.dispose(),this.filter=null,this.frequency=null,this.detune=null,this},a.MonoSynth}),ToneModule(function(a){return a.AMSynth=function(b){b=this.defaultArg(b,a.AMSynth.defaults),a.Monophonic.call(this,b),this.carrier=new a.MonoSynth(b.carrier),this.carrier.volume.value=-10,this.modulator=new a.MonoSynth(b.modulator),this.modulator.volume.value=-10,this.frequency=new a.Signal(440,a.Signal.Units.Frequency),this._harmonicity=new a.Multiply(b.harmonicity),this._modulationScale=new a.AudioToGain,this._modulationNode=this.context.createGain(),this.frequency.connect(this.carrier.frequency),this.frequency.chain(this._harmonicity,this.modulator.frequency),this.modulator.chain(this._modulationScale,this._modulationNode.gain),this.carrier.chain(this._modulationNode,this.output)},a.extend(a.AMSynth,a.Monophonic),a.AMSynth.defaults={harmonicity:3,carrier:{volume:-10,portamento:0,oscillator:{type:"sine"},envelope:{attack:.01,decay:.01,sustain:1,release:.5},filterEnvelope:{attack:.01,decay:0,sustain:1,release:.5,min:2e4,max:2e4}},modulator:{volume:-10,portamento:0,oscillator:{type:"square"},envelope:{attack:2,decay:0,sustain:1,release:.5},filterEnvelope:{attack:4,decay:.2,sustain:.5,release:.5,min:20,max:1500}}},a.AMSynth.prototype.triggerEnvelopeAttack=function(a,b){return a=this.toSeconds(a),this.carrier.envelope.triggerAttack(a,b),this.modulator.envelope.triggerAttack(a),this.carrier.filterEnvelope.triggerAttack(a),this.modulator.filterEnvelope.triggerAttack(a),this},a.AMSynth.prototype.triggerEnvelopeRelease=function(a){return this.carrier.triggerRelease(a),this.modulator.triggerRelease(a),this},Object.defineProperty(a.AMSynth.prototype,"harmonicity",{get:function(){return this._harmonicity.value},set:function(a){this._harmonicity.value=a}}),a.AMSynth.prototype.dispose=function(){return a.Monophonic.prototype.dispose.call(this),this.carrier.dispose(),this.carrier=null,this.modulator.dispose(),this.modulator=null,this.frequency.dispose(),this.frequency=null,this._harmonicity.dispose(),this._harmonicity=null,this._modulationScale.dispose(),this._modulationScale=null,this._modulationNode.disconnect(),this._modulationNode=null,this},a.AMSynth}),ToneModule(function(a){return a.DuoSynth=function(b){b=this.defaultArg(b,a.DuoSynth.defaults),a.Monophonic.call(this,b),this.voice0=new a.MonoSynth(b.voice0),this.voice0.volume.value=-10,this.voice1=new a.MonoSynth(b.voice1),this.voice1.volume.value=-10,this._vibrato=new a.LFO(b.vibratoRate,-50,50),this._vibrato.start(),this.vibratoRate=this._vibrato.frequency,this._vibratoGain=this.context.createGain(),this.vibratoAmount=new a.Signal(this._vibratoGain.gain,a.Signal.Units.Gain),this.vibratoAmount.value=b.vibratoAmount,this._vibratoDelay=this.toSeconds(b.vibratoDelay),this.frequency=new a.Signal(440,a.Signal.Units.Frequency),this._harmonicity=new a.Multiply(b.harmonicity),this.frequency.connect(this.voice0.frequency),this.frequency.chain(this._harmonicity,this.voice1.frequency),this._vibrato.connect(this._vibratoGain),this._vibratoGain.fan(this.voice0.detune,this.voice1.detune),this.voice0.connect(this.output),this.voice1.connect(this.output)},a.extend(a.DuoSynth,a.Monophonic),a.DuoSynth.defaults={vibratoAmount:.5,vibratoRate:5,vibratoDelay:1,harmonicity:1.5,voice0:{volume:-10,portamento:0,oscillator:{type:"sine"},filterEnvelope:{attack:.01,decay:0,sustain:1,release:.5},envelope:{attack:.01,decay:0,sustain:1,release:.5}},voice1:{volume:-10,portamento:0,oscillator:{type:"sine"},filterEnvelope:{attack:.01,decay:0,sustain:1,release:.5},envelope:{attack:.01,decay:0,sustain:1,release:.5}}},a.DuoSynth.prototype.triggerEnvelopeAttack=function(a,b){return a=this.toSeconds(a),this.voice0.envelope.triggerAttack(a,b),this.voice1.envelope.triggerAttack(a,b),this.voice0.filterEnvelope.triggerAttack(a),this.voice1.filterEnvelope.triggerAttack(a),this},a.DuoSynth.prototype.triggerEnvelopeRelease=function(a){return this.voice0.triggerRelease(a),this.voice1.triggerRelease(a),this},Object.defineProperty(a.DuoSynth.prototype,"harmonicity",{get:function(){return this._harmonicity.value},set:function(a){this._harmonicity.value=a}}),a.DuoSynth.prototype.dispose=function(){return a.Monophonic.prototype.dispose.call(this),this.voice0.dispose(),this.voice0=null,this.voice1.dispose(),this.voice1=null,this.frequency.dispose(),this.frequency=null,this._vibrato.dispose(),this._vibrato=null,this._vibratoGain.disconnect(),this._vibratoGain=null,this._harmonicity.dispose(),this._harmonicity=null,this.vibratoAmount.dispose(),this.vibratoAmount=null,this.vibratoRate=null,this},a.DuoSynth}),ToneModule(function(a){return a.FMSynth=function(b){b=this.defaultArg(b,a.FMSynth.defaults),a.Monophonic.call(this,b),this.carrier=new a.MonoSynth(b.carrier),this.carrier.volume.value=-10,this.modulator=new a.MonoSynth(b.modulator),this.modulator.volume.value=-10,this.frequency=new a.Signal(440,a.Signal.Units.Frequency),this._harmonicity=new a.Multiply(b.harmonicity),this._modulationIndex=new a.Multiply(b.modulationIndex),this._modulationNode=this.context.createGain(),this.frequency.connect(this.carrier.frequency),this.frequency.chain(this._harmonicity,this.modulator.frequency),this.frequency.chain(this._modulationIndex,this._modulationNode),this.modulator.connect(this._modulationNode.gain),this._modulationNode.gain.value=0,this._modulationNode.connect(this.carrier.frequency),this.carrier.connect(this.output)},a.extend(a.FMSynth,a.Monophonic),a.FMSynth.defaults={harmonicity:3,modulationIndex:10,carrier:{volume:-10,portamento:0,oscillator:{type:"sine"},envelope:{attack:.01,decay:0,sustain:1,release:.5},filterEnvelope:{attack:.01,decay:0,sustain:1,release:.5,min:2e4,max:2e4}},modulator:{volume:-10,portamento:0,oscillator:{type:"triangle"},envelope:{attack:.01,decay:0,sustain:1,release:.5},filterEnvelope:{attack:.01,decay:0,sustain:1,release:.5,min:2e4,max:2e4}}},a.FMSynth.prototype.triggerEnvelopeAttack=function(a,b){return a=this.toSeconds(a),this.carrier.envelope.triggerAttack(a,b),this.modulator.envelope.triggerAttack(a),this.carrier.filterEnvelope.triggerAttack(a),this.modulator.filterEnvelope.triggerAttack(a),this},a.FMSynth.prototype.triggerEnvelopeRelease=function(a){return this.carrier.triggerRelease(a),this.modulator.triggerRelease(a),this},Object.defineProperty(a.FMSynth.prototype,"harmonicity",{get:function(){return this._harmonicity.value},set:function(a){this._harmonicity.value=a}}),Object.defineProperty(a.FMSynth.prototype,"modulationIndex",{get:function(){return this._modulationIndex.value},set:function(a){this._modulationIndex.value=a}}),a.FMSynth.prototype.dispose=function(){return a.Monophonic.prototype.dispose.call(this),this.carrier.dispose(),this.carrier=null,this.modulator.dispose(),this.modulator=null,this.frequency.dispose(),this.frequency=null,this._modulationIndex.dispose(),this._modulationIndex=null,this._harmonicity.dispose(),this._harmonicity=null,this._modulationNode.disconnect(),this._modulationNode=null,this},a.FMSynth}),ToneModule(function(a){return a.Player=function(){var b=this.optionsObject(arguments,["url","onload"],a.Player.defaults);a.Source.call(this,b),this._source=null,this._buffer=new a.Buffer(b.url,b.onload.bind(null,this)),this._loop=b.loop,this._loopStart=b.loopStart,this._loopEnd=b.loopEnd,this._playbackRate=b.playbackRate,this.retrigger=b.retrigger},a.extend(a.Player,a.Source),a.Player.defaults={onload:function(){},playbackRate:1,loop:!1,loopStart:0,loopEnd:0,retrigger:!1},a.Player.prototype.load=function(a,b){return this._buffer.load(a,b.bind(this,this)),this},a.Player.prototype._start=function(a,b,c){if(!this._buffer.loaded)throw Error("tried to start Player before the buffer was loaded");return this._loop?(b=this.defaultArg(b,this._loopStart),b=this.toSeconds(b)):b=this.defaultArg(b,0),c=this.defaultArg(c,this._buffer.duration-b),a=this.toSeconds(a),c=this.toSeconds(c),this._source=this.context.createBufferSource(),this._source.buffer=this._buffer.get(),this._loop?(this._source.loop=this._loop,this._source.loopStart=this.toSeconds(this._loopStart),this._source.loopEnd=this.toSeconds(this._loopEnd)):this._nextStop=a+c,this._source.playbackRate.value=this._playbackRate,this._source.onended=this.onended,this._source.connect(this.output),this._source.start(a,b,c),this},a.Player.prototype._stop=function(a){return this._source&&(this._source.stop(this.toSeconds(a)),this._source=null),this},a.Player.prototype.setLoopPoints=function(a,b){return this.loopStart=a,this.loopEnd=b,this},Object.defineProperty(a.Player.prototype,"loopStart",{get:function(){return this._loopStart},set:function(a){this._loopStart=a,this._source&&(this._source.loopStart=this.toSeconds(a))}}),Object.defineProperty(a.Player.prototype,"loopEnd",{get:function(){return this._loopEnd},set:function(a){this._loopEnd=a,this._source&&(this._source.loopEnd=this.toSeconds(a))}}),Object.defineProperty(a.Player.prototype,"buffer",{get:function(){return this._buffer},set:function(a){this._buffer.set(a)}}),Object.defineProperty(a.Player.prototype,"loop",{get:function(){return this._loop},set:function(a){this._loop=a,this._source&&(this._source.loop=a)}}),Object.defineProperty(a.Player.prototype,"playbackRate",{get:function(){return this._playbackRate},set:function(a){this._playbackRate=a,this._source&&(this._source.playbackRate.value=a)}}),a.Player.prototype.dispose=function(){return a.Source.prototype.dispose.call(this),null!==this._source&&(this._source.disconnect(),this._source=null),this._buffer.dispose(),this._buffer=null,this},a.Player}),ToneModule(function(a){return a.Sampler=function(b,c){a.Instrument.call(this),c=this.defaultArg(c,a.Sampler.defaults),this.player=new a.Player(c.player),this.player.retrigger=!0,this._buffers={},this.envelope=new a.AmplitudeEnvelope(c.envelope),this.filterEnvelope=new a.ScaledEnvelope(c.filterEnvelope),this._sample=c.sample,this._pitch=c.pitch,this.filter=new a.Filter(c.filter),this._loadBuffers(b),this.pitch=c.pitch,this.player.chain(this.filter,this.envelope,this.output),this.filterEnvelope.connect(this.filter.frequency)},a.extend(a.Sampler,a.Instrument),a.Sampler.defaults={sample:0,pitch:0,player:{loop:!1},envelope:{attack:.001,decay:0,sustain:1,release:.1},filterEnvelope:{attack:.001,decay:.001,sustain:1,release:.5,min:20,max:2e4,exponent:2},filter:{type:"lowpass"}},a.Sampler.prototype._loadBuffers=function(b){var c,d;if("string"==typeof b)this._buffers[0]=new a.Buffer(b,function(){this.sample="0"}.bind(this));else{b=this._flattenUrls(b);for(c in b)this._sample=c,d=b[c],this._buffers[c]=new a.Buffer(d)}},a.Sampler.prototype._flattenUrls=function(a){var b,c,d,e={};for(b in a)if(a.hasOwnProperty(b))if("object"==typeof a[b]){c=this._flattenUrls(a[b]);for(d in c)c.hasOwnProperty(d)&&(e[b+"."+d]=c[d])}else e[b]=a[b];return e},a.Sampler.prototype.triggerAttack=function(a,b,c){return b=this.toSeconds(b),a&&(this.sample=a),this.player.start(b,0),this.envelope.triggerAttack(b,c),this.filterEnvelope.triggerAttack(b),this},a.Sampler.prototype.triggerRelease=function(a){return a=this.toSeconds(a),this.filterEnvelope.triggerRelease(a),this.envelope.triggerRelease(a),this.player.stop(this.toSeconds(this.envelope.release)+a),this},Object.defineProperty(a.Sampler.prototype,"sample",{get:function(){return this._sample},set:function(a){if(!this._buffers.hasOwnProperty(a))throw new Error("Sampler does not have a sample named "+a);this._sample=a,this.player.buffer=this._buffers[a]}}),Object.defineProperty(a.Sampler.prototype,"pitch",{get:function(){return this._pitch},set:function(a){this._pitch=a,this.player.playbackRate=this.intervalToFrequencyRatio(a)}}),a.Sampler.prototype.dispose=function(){a.Instrument.prototype.dispose.call(this),this.player.dispose(),this.filterEnvelope.dispose(),this.envelope.dispose(),this.filter.dispose(),this.player=null,this.filterEnvelope=null,this.envelope=null,this.filter=null;for(var b in this._buffers)this._buffers[b].dispose(),this._buffers[b]=null;return this._buffers=null,this},a.Sampler}),ToneModule(function(a){return a.MultiSampler=function(b,c){console.warn("Tone.MultiSampler is deprecated - use Tone.PolySynth with Tone.Sampler as the voice"),a.Instrument.call(this),this.samples={},this._createSamples(b,c)},a.extend(a.MultiSampler,a.Instrument),a.MultiSampler.prototype._createSamples=function(b,c){var d,e,f,g,h={total:0,loaded:0};for(i in b)h.total++;d=function(){h.loaded++,h.loaded===h.total&&c&&c()};for(e in b)f=b[e],g=new a.Sampler(f,d),g.connect(this.output),this.samples[e]=g},a.MultiSampler.prototype.triggerAttack=function(a,b,c){this.samples.hasOwnProperty(a)&&this.samples[a].triggerAttack(0,b,c)},a.MultiSampler.prototype.triggerRelease=function(a,b){this.samples.hasOwnProperty(a)&&this.samples[a].triggerRelease(b)},a.MultiSampler.prototype.triggerAttackRelease=function(a,b,c,d){if(this.samples.hasOwnProperty(a)){c=this.toSeconds(c),b=this.toSeconds(b);var e=this.samples[a];e.triggerAttack(0,c,d),e.triggerRelease(c+b)}},a.MultiSampler.prototype.set=function(a){for(var b in this.samples)this.samples[b].set(a)},a.MultiSampler.prototype.dispose=function(){a.Instrument.prototype.dispose.call(this);for(var b in this.samples)this.samples[b].dispose(),this.samples[b]=null;this.samples=null},a.MultiSampler}),ToneModule(function(a){a.Noise=function(){var b=this.optionsObject(arguments,["type"],a.Noise.defaults);a.Source.call(this,b),this._source=null,this._buffer=null,this.type=b.type},a.extend(a.Noise,a.Source),a.Noise.defaults={type:"white"},Object.defineProperty(a.Noise.prototype,"type",{get:function(){return this._buffer===d?"white":this._buffer===c?"brown":this._buffer===b?"pink":void 0},set:function(e){if(this.type!==e){switch(e){case"white":this._buffer=d;break;case"pink":this._buffer=b;break;case"brown":this._buffer=c;break;default:this._buffer=d}if(this.state===a.Source.State.STARTED){var f=this.now()+this.bufferTime;this._source.onended=void 0,this._stop(f),this._start(f)}}}}),a.Noise.prototype._start=function(a){this._source=this.context.createBufferSource(),this._source.buffer=this._buffer,this._source.loop=!0,this.connectSeries(this._source,this.output),this._source.start(this.toSeconds(a)),this._source.onended=this.onended},a.Noise.prototype._stop=function(a){this._source&&this._source.stop(this.toSeconds(a))},a.Noise.prototype.dispose=function(){return a.Source.prototype.dispose.call(this),null!==this._source&&(this._source.disconnect(),this._source=null),this._buffer=null,this};var b=null,c=null,d=null;return a._initAudioContext(function(a){var e=a.sampleRate,f=4*e;b=function(){var b,c,d,g,h,i,j,k,l,m,n,o=a.createBuffer(2,f,e);for(b=0;bm;m++)n=2*Math.random()-1,d=.99886*d+.0555179*n,g=.99332*g+.0750759*n,h=.969*h+.153852*n,i=.8665*i+.3104856*n,j=.55*j+.5329522*n,k=-.7616*k-.016898*n,c[m]=d+g+h+i+j+k+l+.5362*n,c[m]*=.11,l=.115926*n;return o}(),c=function(){var b,c,d,g,h,i=a.createBuffer(2,f,e);for(b=0;bg;g++)h=2*Math.random()-1,c[g]=(d+.02*h)/1.02,d=c[g],c[g]*=3.5;return i}(),d=function(){var b,c,d,g=a.createBuffer(2,f,e);for(b=0;bd;d++)c[d]=2*Math.random()-1;return g}()}),a.Noise}),ToneModule(function(a){return a.NoiseSynth=function(b){b=this.defaultArg(b,a.NoiseSynth.defaults),a.Instrument.call(this),this.noise=new a.Noise,this.filter=new a.Filter(b.filter),this.filterEnvelope=new a.ScaledEnvelope(b.filterEnvelope),this.envelope=new a.AmplitudeEnvelope(b.envelope),this.noise.chain(this.filter,this.envelope,this.output),this.noise.start(),this.filterEnvelope.connect(this.filter.frequency)},a.extend(a.NoiseSynth,a.Instrument),a.NoiseSynth.defaults={noise:{type:"white"},filter:{Q:6,type:"highpass",rolloff:-24},envelope:{attack:.005,decay:.1,sustain:0},filterEnvelope:{attack:.06,decay:.2,sustain:0,release:2,min:20,max:4e3,exponent:2}},a.NoiseSynth.prototype.triggerAttack=function(a,b){return this.envelope.triggerAttack(a,b),this.filterEnvelope.triggerAttack(a),this},a.NoiseSynth.prototype.triggerRelease=function(a){return this.envelope.triggerRelease(a),this.filterEnvelope.triggerRelease(a),this},a.NoiseSynth.prototype.triggerAttackRelease=function(a,b,c){return b=this.toSeconds(b),a=this.toSeconds(a),this.triggerAttack(b,c),console.log(b+a),this.triggerRelease(b+a),this},a.NoiseSynth.prototype.dispose=function(){return a.Instrument.prototype.dispose.call(this),this.noise.dispose(),this.noise=null,this.envelope.dispose(),this.envelope=null,this.filterEnvelope.dispose(),this.filterEnvelope=null,this.filter.dispose(),this.filter=null,this},a.NoiseSynth}),ToneModule(function(a){return a.PluckSynth=function(b){b=this.defaultArg(b,a.PluckSynth.defaults),a.Instrument.call(this),this._noise=new a.Noise("pink"),this.attackNoise=1,this._lfcf=new a.LowpassCombFilter(1/440),this.resonance=this._lfcf.resonance,this.dampening=this._lfcf.dampening,this._noise.connect(this._lfcf),this._lfcf.connect(this.output)},a.extend(a.PluckSynth,a.Instrument),a.PluckSynth.defaults={attackNoise:1,dampening:4e3,resonance:.5},a.PluckSynth.prototype.triggerAttack=function(a,b){a=this.toFrequency(a),b=this.toSeconds(b);var c=1/a;return this._lfcf.setDelayTimeAtTime(c,b),this._noise.start(b),this._noise.stop(b+c*this.attackNoise),this},a.PluckSynth.prototype.dispose=function(){return a.Instrument.prototype.dispose.call(this),this._noise.dispose(),this._lfcf.dispose(),this._noise=null,this._lfcf=null,this.dampening=null,this.resonance=null,this},a.PluckSynth}),ToneModule(function(a){return a.PolySynth=function(){var b,c,d;for(a.Instrument.call(this),b=this.optionsObject(arguments,["polyphony","voice"],a.PolySynth.defaults),this.voices=new Array(b.polyphony),this._freeVoices=[],this._activeVoices={},c=0;c0&&(g=this._freeVoices.shift(),g.triggerAttack(e,b,c),this._activeVoices[f]=g);return this},a.PolySynth.prototype.triggerAttackRelease=function(a,b,c,d){return c=this.toSeconds(c),this.triggerAttack(a,c,d),this.triggerRelease(a,c+this.toSeconds(b)),this},a.PolySynth.prototype.triggerRelease=function(a,b){var c,d,e;for(Array.isArray(a)||(a=[a]),c=0;cc){var d=b;b=c,c=d}this.min=this.input=new a.Min(c),this.max=this.output=new a.Max(b),this.min.connect(this.max)},a.extend(a.Clip,a.SignalBase),a.Clip.prototype.dispose=function(){return a.prototype.dispose.call(this),this.min.dispose(),this.min=null,this.max.dispose(),this.max=null,this},a.Clip}),ToneModule(function(a){var b,c,d,e=Math.pow(2,13),f=new Array(e);for(b=0;bc;c++)g=0===c?this._guess:this._inverses[c-1],h=new d(g,this._two),this.input.connect(h),this._inverses[c]=h;this._inverses[b-1].connect(this.output)},a.extend(a.Inverse,a.SignalBase),a.Inverse.prototype.dispose=function(){a.prototype.dispose.call(this);for(var b=0;bd;d++)e=new b(d),this.output[d]=e,this.gate.connect(e.selecter),this.input.connect(e)},a.extend(a.Route,a.SignalBase),a.Route.prototype.select=function(a,b){return a=Math.floor(a),this.gate.setValueAtTime(a,this.toSeconds(b)),this},a.Route.prototype.dispose=function(){this.gate.dispose();for(var b=0;b1&&(this.input=new Array(b)),a(c)||1===c?this.output=this.context.createGain():c>1&&(this.output=new Array(b))},d.prototype.set=function(b,c,e){var f,g,h;"object"==typeof b?e=c:"string"==typeof b&&(f={},f[b]=c,b=f);for(g in b)h=this[g],a(h)||(c=b[g],h instanceof d.Signal?h.value!==c&&(a(e)?h.value=c:h.rampTo(c,e)):h instanceof AudioParam?h.value!==c&&(h.value=c):h instanceof d?h.set(c):h!==c&&(this[g]=c));return this},d.prototype.get=function(c){var e,f,g,h,i,j;if(a(c))c=this._collectDefaults(this.constructor);else if("string"==typeof c)e={},e[c]=0,c=e;else if(Array.isArray(c)){for(f={},g=0;g1)for(a=arguments[0],b=1;b1)for(a=1;a0)for(a=this,b=0;b0)for(var a=0;ab;b++)d=b/c*2-1,this._curve[b]=a(d,b);return this._shaper.curve=this._curve,this},Object.defineProperty(a.WaveShaper.prototype,"curve",{get:function(){return this._shaper.curve},set:function(a){if(this._isSafari()){var b=a[0];a.unshift(b)}this._curve=new Float32Array(a),this._shaper.curve=this._curve}}),Object.defineProperty(a.WaveShaper.prototype,"oversample",{get:function(){return this._shaper.oversample},set:function(a){this._shaper.oversample=a}}),a.WaveShaper.prototype._isSafari=function(){var a=navigator.userAgent.toLowerCase();return-1!==a.indexOf("safari")&&-1===a.indexOf("chrome")},a.WaveShaper.prototype.dispose=function(){return a.prototype.dispose.call(this),this._shaper.disconnect(),this._shaper=null,this._curve=null,this},a.WaveShaper}),ToneModule(function(a){return a.Signal=function(b,c){this.units=this.defaultArg(c,a.Signal.Units.Number),this.convert=!0,this.overridden=!1,this.output=this._scaler=this.context.createGain(),this.input=this._value=this._scaler.gain,b instanceof AudioParam?(this._scaler.connect(b),b.value=0):this.value=this.defaultArg(b,a.Signal.defaults.value),a.Signal._constant.chain(this._scaler)},a.extend(a.Signal,a.SignalBase),a.Signal.defaults={value:0},Object.defineProperty(a.Signal.prototype,"value",{get:function(){return this._toUnits(this._value.value)},set:function(a){var b=this._fromUnits(a);this.cancelScheduledValues(0),this._value.value=b}}),a.Signal.prototype._fromUnits=function(b){if(!this.convert)return b;switch(this.units){case a.Signal.Units.Time:return this.toSeconds(b);case a.Signal.Units.Frequency:return this.toFrequency(b);case a.Signal.Units.Decibels:return this.dbToGain(b);case a.Signal.Units.Normal:return Math.min(Math.max(b,0),1);case a.Signal.Units.Audio:return Math.min(Math.max(b,-1),1);default:return b}},a.Signal.prototype._toUnits=function(b){if(!this.convert)return b;switch(this.units){case a.Signal.Units.Decibels:return this.gainToDb(b);default:return b}},a.Signal.prototype.setValueAtTime=function(a,b){return a=this._fromUnits(a),this._value.setValueAtTime(a,this.toSeconds(b)),this},a.Signal.prototype.setCurrentValueNow=function(a){a=this.defaultArg(a,this.now());var b=this._value.value;return this.cancelScheduledValues(a),this._value.setValueAtTime(b,a),this},a.Signal.prototype.linearRampToValueAtTime=function(a,b){return a=this._fromUnits(a),this._value.linearRampToValueAtTime(a,this.toSeconds(b)),this},a.Signal.prototype.exponentialRampToValueAtTime=function(a,b){return a=this._fromUnits(a),a=Math.max(1e-5,a),this._value.exponentialRampToValueAtTime(a,this.toSeconds(b)),this},a.Signal.prototype.exponentialRampToValueNow=function(a,b){var c=this.now(),d=this.value;return this.setValueAtTime(Math.max(d,1e-4),c),this.exponentialRampToValueAtTime(a,c+this.toSeconds(b)),this},a.Signal.prototype.linearRampToValueNow=function(a,b){var c=this.now();return this.setCurrentValueNow(c),this.linearRampToValueAtTime(a,c+this.toSeconds(b)),this},a.Signal.prototype.setTargetAtTime=function(a,b,c){return a=this._fromUnits(a),c=Math.max(1e-5,c),this._value.setTargetAtTime(a,this.toSeconds(b),c),this},a.Signal.prototype.setValueCurveAtTime=function(a,b,c){for(var d=0;db?this._nextAttack<=b&&this._nextDecay>b?a.Envelope.Phase.ATTACK:this._nextDecay<=b&&this._nextSustain>b?a.Envelope.Phase.DECAY:this._nextSustain<=b&&this._nextRelease>b?a.Envelope.Phase.SUSTAIN:a.Envelope.Phase.STANDBY:this._nextReleaseb?a.Envelope.Phase.RELEASE:a.Envelope.Phase.STANDBY},a.Envelope.prototype._exponentialApproach=function(a,b,c,d,e){return c+(b-c)*Math.exp(-(e-a)/d)},a.Envelope.prototype._linearInterpolate=function(a,b,c,d,e){return b+(d-b)*((e-a)/(c-a))},a.Envelope.prototype._exponentialInterpolate=function(a,b,c,d,e){return b*Math.pow(d/b,(e-a)/(c-a))},a.Envelope.prototype._valueAtTime=function(b){var c=this.toSeconds(this.attack),d=this.toSeconds(this.decay),e=this.toSeconds(this.release);switch(this._phaseAtTime(b)){case a.Envelope.Phase.ATTACK:return this._attackCurve===a.Envelope.Type.LINEAR?this._linearInterpolate(this._nextAttack,this._minOutput,this._nextAttack+c,this._peakValue,b):this._exponentialInterpolate(this._nextAttack,this._minOutput,this._nextAttack+c,this._peakValue,b);case a.Envelope.Phase.DECAY:return this._exponentialApproach(this._nextDecay,this._peakValue,this.sustain*this._peakValue,d*this._timeMult,b);case a.Envelope.Phase.RELEASE:return this._exponentialApproach(this._nextRelease,this._peakValue,this._minOutput,e*this._timeMult,b);case a.Envelope.Phase.SUSTAIN:return this.sustain*this._peakValue;case a.Envelope.Phase.STANDBY:return this._minOutput}},a.Envelope.prototype.triggerAttack=function(b,c){var d,e,f,g,h,i;return b=this.toSeconds(b),d=this.toSeconds(this.attack),e=this.toSeconds(this.decay),f=this._valueAtTime(b),g=f*d,this._nextAttack=b-g,this._nextDecay=this._nextAttack+d,this._nextSustain=this._nextDecay+e,this._nextRelease=1/0,this._peakValue=this.defaultArg(c,1),h=this._peakValue,i=this.sustain*h,this._sig.cancelScheduledValues(b),this._sig.setValueAtTime(f,b),this._attackCurve===a.Envelope.Type.LINEAR?this._sig.linearRampToValueAtTime(h,this._nextDecay):this._sig.exponentialRampToValueAtTime(h,this._nextDecay),this._sig.setTargetAtTime(i,this._nextDecay,e*this._timeMult),this},a.Envelope.prototype.triggerRelease=function(b){var c,d,e;return b=this.toSeconds(b),c=this._phaseAtTime(b),d=this.toSeconds(this.release),e=this._valueAtTime(b),this._peakValue=e,this._nextRelease=b,this._nextStandby=this._nextRelease+d,this._sig.cancelScheduledValues(this._nextRelease),c===a.Envelope.Phase.ATTACK?(this._sig.setCurrentValueNow(),this.attackCurve===a.Envelope.Type.LINEAR?this._sig.linearRampToValueAtTime(this._peakValue,this._nextRelease):this._sig.exponentialRampToValueAtTime(this._peakValue,this._nextRelease)):this._sig.setValueAtTime(this._peakValue,this._nextRelease),this._sig.setTargetAtTime(this._minOutput,this._nextRelease,d*this._timeMult),this},a.Envelope.prototype.triggerAttackRelease=function(a,b,c){return b=this.toSeconds(b),this.triggerAttack(b,c),this.triggerRelease(b+this.toSeconds(a)),this},a.Envelope.prototype.connect=a.Signal.prototype.connect,a.Envelope.prototype.dispose=function(){return a.prototype.dispose.call(this),this._sig.dispose(),this._sig=null,this},a.Envelope.Phase={ATTACK:"attack",DECAY:"decay",SUSTAIN:"sustain",RELEASE:"release",STANDBY:"standby"},a.Envelope.Type={LINEAR:"linear",EXPONENTIAL:"exponential"},a.Envelope}),ToneModule(function(a){return a.AmplitudeEnvelope=function(){a.Envelope.apply(this,arguments),this.input=this.output=this.context.createGain(),this._sig.connect(this.output.gain)},a.extend(a.AmplitudeEnvelope,a.Envelope),a.AmplitudeEnvelope}),ToneModule(function(a){return a.Compressor=function(){var b=this.optionsObject(arguments,["threshold","ratio"],a.Compressor.defaults);this._compressor=this.input=this.output=this.context.createDynamicsCompressor(),this.threshold=this._compressor.threshold,this.attack=new a.Signal(this._compressor.attack,a.Signal.Units.Time),this.release=new a.Signal(this._compressor.release,a.Signal.Units.Time),this.knee=this._compressor.knee,this.ratio=this._compressor.ratio,this.attack.connect(this._compressor.attack),this.release.connect(this._compressor.release),this._readOnly(["knee","release","attack","ratio","threshold"]),this.set(b)},a.extend(a.Compressor),a.Compressor.defaults={ratio:12,threshold:-24,release:.25,attack:.003,knee:30},a.Compressor.prototype.dispose=function(){return a.prototype.dispose.call(this),this._writable(["knee","release","attack","ratio","threshold"]),this._compressor.disconnect(),this._compressor=null,this.attack.dispose(),this.attack=null,this.release.dispose(),this.release=null,this.threshold=null,this.ratio=null,this.knee=null,this},a.Compressor}),ToneModule(function(a){return a.Add=function(b){a.call(this,2,0),this._sum=this.input[0]=this.input[1]=this.output=this.context.createGain(),this._value=this.input[1]=new a.Signal(b),this._value.connect(this._sum)},a.extend(a.Add,a.Signal),a.Add.prototype.dispose=function(){return a.prototype.dispose.call(this),this._sum.disconnect(),this._sum=null,this._value.dispose(),this._value=null,this},a.Add}),ToneModule(function(a){return a.Multiply=function(b){a.call(this,2,0),this._mult=this.input[0]=this.output=this.context.createGain(),this._value=this.input[1]=this.output.gain,this._value.value=this.defaultArg(b,0)},a.extend(a.Multiply,a.Signal),a.Multiply.prototype.dispose=function(){return a.prototype.dispose.call(this),this._mult.disconnect(),this._mult=null,this._value=null,this},a.Multiply}),ToneModule(function(a){return a.Negate=function(){this._multiply=this.input=this.output=new a.Multiply(-1)},a.extend(a.Negate,a.SignalBase),a.Negate.prototype.dispose=function(){return a.prototype.dispose.call(this),this._multiply.dispose(),this._multiply=null,this},a.Negate}),ToneModule(function(a){return a.Subtract=function(b){a.call(this,2,0),this._sum=this.input[0]=this.output=this.context.createGain(),this._neg=new a.Negate,this._value=this.input[1]=new a.Signal(b),this._value.chain(this._neg,this._sum)},a.extend(a.Subtract,a.Signal),a.Subtract.prototype.dispose=function(){return a.prototype.dispose.call(this),this._neg.dispose(),this._neg=null,this._sum.disconnect(),this._sum=null,this._value.dispose(),this._value=null,this},a.Subtract}),ToneModule(function(a){return a.GreaterThanZero=function(){this._thresh=this.output=new a.WaveShaper(function(a){return 0>=a?0:1}),this._scale=this.input=new a.Multiply(1e4),this._scale.connect(this._thresh)},a.extend(a.GreaterThanZero,a.SignalBase),a.GreaterThanZero.prototype.dispose=function(){return a.prototype.dispose.call(this),this._scale.dispose(),this._scale=null,this._thresh.dispose(),this._thresh=null,this},a.GreaterThanZero}),ToneModule(function(a){return a.EqualZero=function(){this._scale=this.input=new a.Multiply(1e4),this._thresh=new a.WaveShaper(function(a){return 0===a?1:0},128),this._gtz=this.output=new a.GreaterThanZero,this._scale.chain(this._thresh,this._gtz)},a.extend(a.EqualZero,a.SignalBase),a.EqualZero.prototype.dispose=function(){return a.prototype.dispose.call(this),this._gtz.dispose(),this._gtz=null,this._scale.dispose(),this._scale=null,this._thresh.dispose(),this._thresh=null,this},a.EqualZero}),ToneModule(function(a){return a.Equal=function(b){a.call(this,2,0),this._sub=this.input[0]=new a.Subtract(b),this._equals=this.output=new a.EqualZero,this._sub.connect(this._equals),this.input[1]=this._sub.input[1]},a.extend(a.Equal,a.SignalBase),Object.defineProperty(a.Equal.prototype,"value",{get:function(){return this._sub.value},set:function(a){this._sub.value=a}}),a.Equal.prototype.dispose=function(){return a.prototype.dispose.call(this),this._equals.dispose(),this._equals=null,this._sub.dispose(),this._sub=null,this},a.Equal}),ToneModule(function(a){a.Select=function(c){var d,e;for(c=this.defaultArg(c,2),a.call(this,c,1),this.gate=new a.Signal(0),this._readOnly("gate"),d=0;c>d;d++)e=new b(d),this.input[d]=e,this.gate.connect(e.selecter),e.connect(this.output)},a.extend(a.Select,a.SignalBase),a.Select.prototype.select=function(a,b){return a=Math.floor(a),this.gate.setValueAtTime(a,this.toSeconds(b)),this},a.Select.prototype.dispose=function(){this._writable("gate"),this.gate.dispose(),this.gate=null;for(var b=0;bc;c++)this.input[c]=this._sum;this._sum.connect(this._gtz)},a.extend(a.OR,a.SignalBase),a.OR.prototype.dispose=function(){return a.prototype.dispose.call(this),this._gtz.dispose(),this._gtz=null,this._sum.disconnect(),this._sum=null,this},a.OR}),ToneModule(function(a){return a.AND=function(b){b=this.defaultArg(b,2),a.call(this,b,0),this._equals=this.output=new a.Equal(b);for(var c=0;b>c;c++)this.input[c]=this._equals},a.extend(a.AND,a.SignalBase),a.AND.prototype.dispose=function(){return a.prototype.dispose.call(this),this._equals.dispose(),this._equals=null,this},a.AND}),ToneModule(function(a){return a.NOT=a.EqualZero,a.NOT}),ToneModule(function(a){return a.GreaterThan=function(b){a.call(this,2,0),this._value=this.input[0]=new a.Subtract(b),this.input[1]=this._value.input[1],this._gtz=this.output=new a.GreaterThanZero,this._value.connect(this._gtz)},a.extend(a.GreaterThan,a.Signal),a.GreaterThan.prototype.dispose=function(){return a.prototype.dispose.call(this),this._value.dispose(),this._value=null,this._gtz.dispose(),this._gtz=null,this},a.GreaterThan}),ToneModule(function(a){return a.LessThan=function(b){a.call(this,2,0),this._neg=this.input[0]=new a.Negate,this._gt=this.output=new a.GreaterThan,this._rhNeg=new a.Negate,this._value=this.input[1]=new a.Signal(b),this._neg.connect(this._gt),this._value.connect(this._rhNeg),this._rhNeg.connect(this._gt,0,1)},a.extend(a.LessThan,a.Signal),a.LessThan.prototype.dispose=function(){return a.prototype.dispose.call(this),this._neg.dispose(),this._neg=null,this._gt.dispose(),this._gt=null,this._rhNeg.dispose(),this._rhNeg=null,this._value.dispose(),this._value=null,this},a.LessThan}),ToneModule(function(a){return a.Abs=function(){a.call(this,1,0),this._ltz=new a.LessThan(0),this._switch=this.output=new a.Select(2),this._negate=new a.Negate,this.input.connect(this._switch,0,0),this.input.connect(this._negate),this._negate.connect(this._switch,0,1),this.input.chain(this._ltz,this._switch.gate)},a.extend(a.Abs,a.SignalBase),a.Abs.prototype.dispose=function(){return a.prototype.dispose.call(this),this._switch.dispose(),this._switch=null,this._ltz.dispose(),this._ltz=null,this._negate.dispose(),this._negate=null,this},a.Abs}),ToneModule(function(a){return a.Max=function(b){a.call(this,2,0),this.input[0]=this.context.createGain(),this._value=this.input[1]=new a.Signal(b),this._ifThenElse=this.output=new a.IfThenElse,this._gt=new a.GreaterThan,this.input[0].chain(this._gt,this._ifThenElse.if),this.input[0].connect(this._ifThenElse.then),this._value.connect(this._ifThenElse.else),this._value.connect(this._gt,0,1)},a.extend(a.Max,a.Signal),a.Max.prototype.dispose=function(){return a.prototype.dispose.call(this),this._value.dispose(),this._ifThenElse.dispose(),this._gt.dispose(),this._value=null,this._ifThenElse=null,this._gt=null,this},a.Max}),ToneModule(function(a){return a.Min=function(b){a.call(this,2,0),this.input[0]=this.context.createGain(),this._ifThenElse=this.output=new a.IfThenElse,this._lt=new a.LessThan,this._value=this.input[1]=new a.Signal(b),this.input[0].chain(this._lt,this._ifThenElse.if),this.input[0].connect(this._ifThenElse.then),this._value.connect(this._ifThenElse.else),this._value.connect(this._lt,0,1)},a.extend(a.Min,a.Signal),a.Min.prototype.dispose=function(){return a.prototype.dispose.call(this),this._value.dispose(),this._ifThenElse.dispose(),this._lt.dispose(),this._value=null,this._ifThenElse=null,this._lt=null,this},a.Min}),ToneModule(function(a){return a.Modulo=function(b){a.call(this,1,1),this._shaper=new a.WaveShaper(Math.pow(2,16)),this._multiply=new a.Multiply,this._subtract=this.output=new a.Subtract,this._modSignal=new a.Signal(b),this.input.fan(this._shaper,this._subtract),this._modSignal.connect(this._multiply,0,0),this._shaper.connect(this._multiply,0,1),this._multiply.connect(this._subtract,0,1),this._setWaveShaper(b)},a.extend(a.Modulo,a.SignalBase),a.Modulo.prototype._setWaveShaper=function(a){this._shaper.setMap(function(b){var c=Math.floor((b+1e-4)/a);return c})},Object.defineProperty(a.Modulo.prototype,"value",{get:function(){return this._modSignal.value},set:function(a){this._modSignal.value=a,this._setWaveShaper(a)}}),a.Modulo.prototype.dispose=function(){return a.prototype.dispose.call(this),this._shaper.dispose(),this._shaper=null,this._multiply.dispose(),this._multiply=null,this._subtract.dispose(),this._subtract=null,this._modSignal.dispose(),this._modSignal=null,this},a.Modulo}),ToneModule(function(a){function b(a,b,c){var d=new a;return c._eval(b[0]).connect(d,0,0),c._eval(b[1]).connect(d,0,1),d}function c(a,b,c){var d=new a;return c._eval(b[0]).connect(d,0,0),d}function d(a){return a?parseFloat(a):void 0}function e(a){return a&&a.args?parseFloat(a.args):void 0}return a.Expr=function(){var a,b,c,d=this._replacements(Array.prototype.slice.call(arguments)),e=this._parseInputs(d);for(this._nodes=[],this.input=new Array(e),a=0;e>a;a++)this.input[a]=this.context.createGain();b=this._parseTree(d);try{c=this._eval(b)}catch(f){throw this._disposeNodes(),new Error("Could evaluate expression: "+d)}this.output=c},a.extend(a.Expr,a.SignalBase),a.Expr._Expressions={value:{signal:{regexp:/^\d+\.\d+|^\d+/,method:function(b){var c=new a.Signal(d(b));return c}},input:{regexp:/^\$\d/,method:function(a,b){return b.input[d(a.substr(1))]}}},glue:{"(":{regexp:/^\(/},")":{regexp:/^\)/},",":{regexp:/^,/}},func:{abs:{regexp:/^abs/,method:c.bind(this,a.Abs)},min:{regexp:/^min/,method:b.bind(this,a.Min)},max:{regexp:/^max/,method:b.bind(this,a.Max)},"if":{regexp:/^if/,method:function(b,c){var d=new a.IfThenElse;return c._eval(b[0]).connect(d.if),c._eval(b[1]).connect(d.then),c._eval(b[2]).connect(d.else),d}},gt0:{regexp:/^gt0/,method:c.bind(this,a.GreaterThanZero)},eq0:{regexp:/^eq0/,method:c.bind(this,a.EqualZero)},mod:{regexp:/^mod/,method:function(b,c){var d=e(b[1]),f=new a.Modulo(d);return c._eval(b[0]).connect(f),f}},pow:{regexp:/^pow/,method:function(b,c){var d=e(b[1]),f=new a.Pow(d);return c._eval(b[0]).connect(f),f}}},binary:{"+":{regexp:/^\+/,precedence:1,method:b.bind(this,a.Add)},"-":{regexp:/^\-/,precedence:1,method:function(d,e){return 1===d.length?c(a.Negate,d,e):b(a.Subtract,d,e)}},"*":{regexp:/^\*/,precedence:0,method:b.bind(this,a.Multiply)},">":{regexp:/^\>/,precedence:2,method:b.bind(this,a.GreaterThan)},"<":{regexp:/^0;)b=b.trim(),d=c(b),f.push(d),b=b.substr(d.value.length);return{next:function(){return f[++e]},peek:function(){return f[e+1]}}},a.Expr.prototype._parseTree=function(b){function c(a,b){return!k(a)&&"glue"===a.type&&a.value===b}function d(b,c,d){var e,f,g=!1,h=a.Expr._Expressions[c];if(!k(b))for(e in h)if(f=h[e],f.regexp.test(b.value)){if(k(d))return!0;if(f.precedence===d)return!0}return g}function e(a){var b,c;for(k(a)&&(a=5),b=0>a?f():e(a-1),c=j.peek();d(c,"binary",a);)c=j.next(),b={operator:c.value,method:c.method,args:[b,e(a)]},c=j.peek();return b}function f(){var a,b;return a=j.peek(),d(a,"unary")?(a=j.next(),b=f(),{operator:a.value,method:a.method,args:[b]}):g()}function g(){var a,b;if(a=j.peek(),k(a))throw new SyntaxError("Unexpected termination of expression");if("func"===a.type)return a=j.next(),h(a);if("value"===a.type)return a=j.next(),{method:a.method,args:a.value};if(c(a,"(")){if(j.next(),b=e(),a=j.next(),!c(a,")"))throw new SyntaxError("Expected )");return b}throw new SyntaxError("Parse error, cannot process token "+a.value)}function h(a){var b,d=[];if(b=j.next(),!c(b,"("))throw new SyntaxError('Expected ( in a function call "'+a.value+'"');if(b=j.peek(),c(b,")")||(d=i()),b=j.next(),!c(b,")"))throw new SyntaxError('Expected ) in a function call "'+a.value+'"');return{method:a.method,args:d,name:name}}function i(){for(var a,b,d=[];;){if(b=e(),k(b))break;if(d.push(b),a=j.peek(),!c(a,","))break;j.next()}return d}var j=this._tokenize(b),k=this.isUndef.bind(this);return e()},a.Expr.prototype._eval=function(a){if(!this.isUndef(a)){var b=a.method(a.args,this);return this._nodes.push(b),b}},a.Expr.prototype._disposeNodes=function(){var a,b;for(a=0;ac;c++)d=this.context.createBiquadFilter(),d.type=this._type,this.frequency.connect(d.frequency),this.detune.connect(d.detune),this.Q.connect(d.Q),this.gain.connect(d.gain),this._filters[c]=d;e=[this.input].concat(this._filters).concat([this.output]),this.connectSeries.apply(this,e)}}),a.Filter.prototype.dispose=function(){a.prototype.dispose.call(this);for(var b=0;b=c?a:b})},Object.defineProperty(a.Follower.prototype,"attack",{get:function(){return this._attack},set:function(a){this._attack=a,this._setAttackRelease(this._attack,this._release)}}),Object.defineProperty(a.Follower.prototype,"release",{get:function(){return this._release},set:function(a){this._release=a,this._setAttackRelease(this._attack,this._release)}}),a.Follower.prototype.connect=a.Signal.prototype.connect,a.Follower.prototype.dispose=function(){return a.prototype.dispose.call(this),this._filter.disconnect(),this._filter=null,this._frequencyValues.disconnect(),this._frequencyValues=null,this._delay.disconnect(),this._delay=null,this._sub.disconnect(),this._sub=null,this._abs.dispose(),this._abs=null,this._mult.dispose(),this._mult=null,this._curve=null,this},a.Follower}),ToneModule(function(a){return a.Gate=function(){a.call(this);var b=this.optionsObject(arguments,["threshold","attack","release"],a.Gate.defaults);this._follower=new a.Follower(b.attack,b.release),this._gt=new a.GreaterThan(this.dbToGain(b.threshold)),this.input.connect(this.output),this.input.chain(this._gt,this._follower,this.output.gain)},a.extend(a.Gate),a.Gate.defaults={attack:.1,release:.1,threshold:-40},Object.defineProperty(a.Gate.prototype,"threshold",{get:function(){return this.gainToDb(this._gt.value)},set:function(a){this._gt.value=this.dbToGain(a)}}),Object.defineProperty(a.Gate.prototype,"attack",{get:function(){return this._follower.attack},set:function(a){this._follower.attack=a}}),Object.defineProperty(a.Gate.prototype,"release",{get:function(){return this._follower.release},set:function(a){this._follower.release=a}}),a.Gate.prototype.dispose=function(){return a.prototype.dispose.call(this),this._follower.dispose(),this._gt.dispose(),this._follower=null,this._gt=null,this},a.Gate}),ToneModule(function(a){return a.Clock=function(b,c){this._oscillator=null,this._jsNode=this.context.createScriptProcessor(this.bufferSize,1,1),this._jsNode.onaudioprocess=this._processBuffer.bind(this),this.frequency=new a.Signal(b,a.Signal.Units.Frequency),this._upTick=!1,this.tick=c,this.onended=function(){},this._jsNode.noGC()},a.extend(a.Clock),a.Clock.prototype.start=function(a){if(!this._oscillator){this._oscillator=this.context.createOscillator(),this._oscillator.type="square",this._oscillator.connect(this._jsNode),this.frequency.connect(this._oscillator.frequency),this._upTick=!1;var b=this.toSeconds(a);this._oscillator.start(b)}return this},a.Clock.prototype.stop=function(a){var b,c;return this._oscillator&&(b=this.now(),c=this.toSeconds(a,b),this._oscillator.stop(c),this._oscillator=null,a?setTimeout(this.onended.bind(this),1e3*(c-b)):this.onended()),this},a.Clock.prototype._processBuffer=function(a){var b,c,d=this.defaultArg(a.playbackTime,this.now()),e=this._jsNode.bufferSize,f=a.inputBuffer.getChannelData(0),g=this._upTick,h=this;for(b=0;e>b;b++)c=f[b],c>0&&!g?(g=!0,setTimeout(function(){var a=d+h.samplesToSeconds(b+2*e);return function(){h.tick&&h.tick(a)}}(),0)):0>c&&g&&(g=!1);this._upTick=g},a.Clock.prototype.dispose=function(){return this._jsNode.disconnect(),this.frequency.dispose(),this.frequency=null,this._oscillator&&(this._oscillator.disconnect(),this._oscillator=null),this._jsNode.onaudioprocess=function(){},this._jsNode=null,this.tick=null,this.onended=function(){},this},a.Clock}),ToneModule(function(Tone){var tatum,timelineTicks,transportTicks,swingSubdivision,swingTatum,swingAmount,transportTimeSignature,loopStart,loopEnd,intervals,timeouts,transportTimeline,timelineProgress,SyncedSources,SyncedSignals,TransportState,processIntervals,processTimeouts,processTimeline,TimelineEventIDCounter,TimelineEvent,TransportConstructor;return Tone.Transport=function(){this._clock=new Tone.Clock(0,this._processTick.bind(this)),this._clock.onended=this._onended.bind(this),this.loop=!1,this.bpm=new Tone.Signal(120,Tone.Signal.Units.BPM),this._bpmMult=new Tone.Multiply(1/60*tatum),this.state=TransportState.STOPPED,this.bpm.chain(this._bpmMult,this._clock.frequency)},Tone.extend(Tone.Transport),Tone.Transport.defaults={bpm:120,swing:0,swingSubdivision:"16n",timeSignature:4,loopStart:0,loopEnd:"4m"},tatum=12,timelineTicks=0,transportTicks=0,swingSubdivision="16n",swingTatum=3,swingAmount=0,transportTimeSignature=4,loopStart=0,loopEnd=4*tatum,intervals=[],timeouts=[],transportTimeline=[],timelineProgress=0,SyncedSources=[],SyncedSignals=[],TransportState={STARTED:"started",PAUSED:"paused",STOPPED:"stopped"},Tone.Transport.prototype._processTick=function(a){this.state===TransportState.STARTED&&(swingAmount>0&&timelineTicks%tatum!==0&&timelineTicks%swingTatum===0&&(a+=this._ticksToSeconds(swingTatum)*swingAmount),processIntervals(a),processTimeouts(a),processTimeline(a),transportTicks+=1,timelineTicks+=1,this.loop&&timelineTicks===loopEnd&&this._setTicks(loopStart))},Tone.Transport.prototype._setTicks=function(a){var b,c;for(timelineTicks=a,b=0;b=a){timelineProgress=b;break}},processIntervals=function(a){var b,c,d;for(b=0,c=intervals.length;c>b;b++)d=intervals[b],d.testInterval(transportTicks)&&d.doCallback(a)},processTimeouts=function(a){var b,c,d,e,f=0;for(b=0,c=timeouts.length;c>b;b++)if(d=timeouts[b],e=d.callbackTick(),transportTicks>=e)d.doCallback(a),f++;else if(e>transportTicks)break;timeouts.splice(0,f)},processTimeline=function(a){var b,c,d,e;for(b=timelineProgress,c=transportTimeline.length;c>b;b++)if(d=transportTimeline[b],e=d.callbackTick(),e===timelineTicks)timelineProgress=b,d.doCallback(a);else if(e>timelineTicks)break},Tone.Transport.prototype.setInterval=function(a,b,c){var d=this._toTicks(b),e=new TimelineEvent(a,c,d,transportTicks);return intervals.push(e),e.id},Tone.Transport.prototype.clearInterval=function(a){var b,c;for(b=0;b0;return intervals=[],a},Tone.Transport.prototype.setTimeout=function(a,b,c){var d,e,f,g=this._toTicks(b),h=new TimelineEvent(a,c,g+transportTicks,0);for(d=0,e=timeouts.length;e>d;d++)if(f=timeouts[d],f.callbackTick()>h.callbackTick())return timeouts.splice(d,0,h),h.id;return timeouts.push(h),h.id},Tone.Transport.prototype.clearTimeout=function(a){var b,c;for(b=0;b0;return timeouts=[],a},Tone.Transport.prototype.setTimeline=function(a,b,c){var d,e,f,g=this._toTicks(b),h=new TimelineEvent(a,c,g,0);for(d=timelineProgress,e=transportTimeline.length;e>d;d++)if(f=transportTimeline[d],f.callbackTick()>h.callbackTick())return transportTimeline.splice(d,0,h),h.id;return transportTimeline.push(h),h.id},Tone.Transport.prototype.clearTimeline=function(a){var b,c;for(b=0;b0;return transportTimeline=[],a},Tone.Transport.prototype._toTicks=function(a){var b=this.toSeconds(a),c=this.notationToSeconds("4n"),d=b/c,e=d*tatum;return Math.round(e)},Tone.Transport.prototype._ticksToSeconds=function(a,b,c){a=Math.floor(a);var d=this.notationToSeconds("4n",b,c);return d*a/tatum},Tone.Transport.prototype.nextBeat=function(a){var b,c,d;return a=this.defaultArg(a,"4n"),b=this._toTicks(a),c=transportTicks%b,d=c,c>0&&(d=b-c),this._ticksToSeconds(d)},Tone.Transport.prototype.start=function(a,b){var c,d,e,f;if(this.state===TransportState.STOPPED||this.state===TransportState.PAUSED)for(this.isUndef(b)||this._setTicks(this._toTicks(b)),this.state=TransportState.STARTED,c=this.toSeconds(a),this._clock.start(c),d=0;d1){for(originalTime=time,i=0;ib?a.Source.State.STARTED:this._nextStop<=b?a.Source.State.STOPPED:a.Source.State.STOPPED},a.Source.prototype.start=function(b){return b=this.toSeconds(b),(this._stateAtTime(b)!==a.Source.State.STARTED||this.retrigger)&&(this._nextStart=b,this._nextStop=1/0,this._start.apply(this,arguments)),this},a.Source.prototype.stop=function(b){var c,d=this.now();return b=this.toSeconds(b,d),this._stateAtTime(b)===a.Source.State.STARTED&&(this._nextStop=this.toSeconds(b),clearTimeout(this._timeout),c=b-d,c>0?this._timeout=setTimeout(this.onended,1e3*c+20):this.onended(),this._stop.apply(this,arguments)),this},a.Source.prototype.pause=function(a){return this.stop(a),this},a.Source.prototype.sync=function(b){return a.Transport.syncSource(this,b),this},a.Source.prototype.unsync=function(){return a.Transport.unsyncSource(this),this},a.Source.prototype.dispose=function(){a.prototype.dispose.call(this),this.stop(),clearTimeout(this._timeout),this.onended=function(){},this._writable("volume"),this.volume.dispose(),this.volume=null},a.Source}),ToneModule(function(a){return a.Oscillator=function(){var b=this.optionsObject(arguments,["frequency","type"],a.Oscillator.defaults);a.Source.call(this,b),this._oscillator=null,this.frequency=new a.Signal(b.frequency,a.Signal.Units.Frequency),this.detune=new a.Signal(b.detune),this._wave=null,this._phase=b.phase,this._type=null,this.type=b.type,this.phase=this._phase,this._readOnly(["frequency","detune"])},a.extend(a.Oscillator,a.Source),a.Oscillator.defaults={type:"sine",frequency:440,detune:0,phase:0},a.Oscillator.prototype._start=function(a){this._oscillator=this.context.createOscillator(),this._oscillator.setPeriodicWave(this._wave),this._oscillator.connect(this.output),this.frequency.connect(this._oscillator.frequency),this.detune.connect(this._oscillator.detune),this._oscillator.start(this.toSeconds(a))},a.Oscillator.prototype._stop=function(a){return this._oscillator&&(this._oscillator.stop(this.toSeconds(a)),this._oscillator=null),this},a.Oscillator.prototype.syncFrequency=function(){return a.Transport.syncSignal(this.frequency),this},a.Oscillator.prototype.unsyncFrequency=function(){return a.Transport.unsyncSignal(this.frequency),this},Object.defineProperty(a.Oscillator.prototype,"type",{get:function(){return this._type},set:function(a){var b,c,d,e,f,g=a,h=4096,i=h/2,j=new Float32Array(i),k=new Float32Array(i),l=1,m=/(sine|triangle|square|sawtooth)(\d+)$/.exec(a);for(m&&(l=parseInt(m[2]),a=m[1],l=Math.max(l,2),i=l),b=this._phase,c=1;i>c;++c){switch(d=2/(c*Math.PI),a){case"sine":e=l>=c?1:0;break;case"square":e=1&c?2*d:0;break;case"sawtooth":e=d*(1&c?1:-1);break;case"triangle":e=1&c?2*d*d*(c-1>>1&1?-1:1):0;break;default:throw new TypeError("invalid oscillator type: "+a)}0!==e?(j[c]=-e*Math.sin(b*c),k[c]=e*Math.cos(b*c)):(j[c]=0,k[c]=0)}f=this.context.createPeriodicWave(j,k),this._wave=f,null!==this._oscillator&&this._oscillator.setPeriodicWave(this._wave),this._type=g}}),Object.defineProperty(a.Oscillator.prototype,"phase",{get:function(){return this._phase*(180/Math.PI)},set:function(a){this._phase=a*Math.PI/180,this.type=this._type}}),a.Oscillator.prototype.dispose=function(){return a.Source.prototype.dispose.call(this),null!==this._oscillator&&(this._oscillator.disconnect(),this._oscillator=null),this._wave=null,this._writable(["frequency","detune"]),this.frequency.dispose(),this.frequency=null,this.detune.dispose(),this.detune=null,this},a.Oscillator}),ToneModule(function(a){return a.AudioToGain=function(){this._norm=this.input=this.output=new a.WaveShaper(function(a){return(a+1)/2})},a.extend(a.AudioToGain,a.SignalBase),a.AudioToGain.prototype.dispose=function(){return a.prototype.dispose.call(this),this._norm.dispose(),this._norm=null,this},a.AudioToGain}),ToneModule(function(a){return a.LFO=function(){var b=this.optionsObject(arguments,["frequency","min","max"],a.LFO.defaults);this.oscillator=new a.Oscillator({frequency:b.frequency,type:b.type,phase:b.phase}),this.frequency=this.oscillator.frequency,this.amplitude=this.oscillator.volume,this.amplitude.units=a.Signal.Units.Normal,this.amplitude.value=b.amplitude,this._a2g=new a.AudioToGain,this._scaler=this.output=new a.Scale(b.min,b.max),this.oscillator.chain(this._a2g,this._scaler),this._readOnly(["amplitude","frequency","oscillator"])},a.extend(a.LFO,a.Oscillator),a.LFO.defaults={type:"sine",min:0,max:1,phase:0,frequency:"4n",amplitude:1},a.LFO.prototype.start=function(a){return this.oscillator.start(a),this},a.LFO.prototype.stop=function(a){return this.oscillator.stop(a),this},a.LFO.prototype.sync=function(a){return this.oscillator.sync(a),this.oscillator.syncFrequency(),this},a.LFO.prototype.unsync=function(){return this.oscillator.unsync(),this.oscillator.unsyncFrequency(),this},Object.defineProperty(a.LFO.prototype,"min",{get:function(){return this._scaler.min},set:function(a){this._scaler.min=a}}),Object.defineProperty(a.LFO.prototype,"max",{get:function(){return this._scaler.max},set:function(a){this._scaler.max=a}}),Object.defineProperty(a.LFO.prototype,"type",{get:function(){return this.oscillator.type},set:function(a){this.oscillator.type=a}}),Object.defineProperty(a.LFO.prototype,"phase",{get:function(){return this.oscillator.phase},set:function(a){this.oscillator.phase=a}}),a.LFO.prototype.connect=a.Signal.prototype.connect,a.LFO.prototype.dispose=function(){return a.prototype.dispose.call(this),this._writable(["amplitude","frequency","oscillator"]),this.oscillator.dispose(),this.oscillator=null,this._scaler.dispose(),this._scaler=null,this._a2g.dispose(),this._a2g=null,this.frequency=null,this.amplitude=null,this},a.LFO}),ToneModule(function(a){return a.Limiter=function(b){this._compressor=this.input=this.output=new a.Compressor({attack:1e-4,decay:1e-4,threshold:b}),this.threshold=this._compressor.threshold,this._readOnly("threshold")},a.extend(a.Limiter),a.Limiter.prototype.dispose=function(){return a.prototype.dispose.call(this),this._compressor.dispose(),this._compressor=null,this._writable("threshold"),this.threshold=null,this},a.Limiter}),ToneModule(function(a){return a.LowpassCombFilter=function(){a.call(this);var b=this.optionsObject(arguments,["delayTime","resonance","dampening"],a.LowpassCombFilter.defaults);this._delay=this.input=this.context.createDelay(1),this.delayTime=new a.Signal(b.delayTime,a.Signal.Units.Time),this._lowpass=this.output=this.context.createBiquadFilter(),this._lowpass.Q.value=0,this._lowpass.type="lowpass",this._lowpass.frequency.value=b.dampening,this.dampening=new a.Signal(this._lowpass.frequency,a.Signal.Units.Frequency),this._feedback=this.context.createGain(),this.resonance=new a.Signal(b.resonance,a.Signal.Units.Normal),this._delay.chain(this._lowpass,this._feedback,this._delay),this.delayTime.connect(this._delay.delayTime),this.resonance.connect(this._feedback.gain),this._readOnly(["dampening","resonance","delayTime"])},a.extend(a.LowpassCombFilter),a.LowpassCombFilter.defaults={delayTime:.1,resonance:.5,dampening:3e3},a.LowpassCombFilter.prototype.dispose=function(){return a.prototype.dispose.call(this),this._writable(["dampening","resonance","delayTime"]),this.dampening.dispose(),this.dampening=null,this.resonance.dispose(),this.resonance=null,this._delay.disconnect(),this._delay=null,this._lowpass.disconnect(),this._lowpass=null,this._feedback.disconnect(),this._feedback=null,this.delayTime.dispose(),this.delayTime=null,this +},a.LowpassCombFilter}),ToneModule(function(a){return a.Merge=function(){a.call(this,2,0),this.left=this.input[0]=this.context.createGain(),this.right=this.input[1]=this.context.createGain(),this._merger=this.output=this.context.createChannelMerger(2),this.left.connect(this._merger,0,0),this.right.connect(this._merger,0,1)},a.extend(a.Merge),a.Merge.prototype.dispose=function(){return a.prototype.dispose.call(this),this.left.disconnect(),this.left=null,this.right.disconnect(),this.right=null,this._merger.disconnect(),this._merger=null,this},a.Merge}),ToneModule(function(a){return a.Meter=function(b,c,d){a.call(this),this._channels=this.defaultArg(b,1),this._smoothing=this.defaultArg(c,.8),this._clipMemory=1e3*this.defaultArg(d,.5),this._volume=new Array(this._channels),this._values=new Array(this._channels);for(var e=0;eh;h++)f=c[h],!g&&f>.95&&(g=!0,this._lastClip=Date.now()),e+=f,d+=f*f;i=e/k,j=Math.sqrt(d/k),this._volume[b]=Math.max(j,this._volume[b]*l),this._values[b]=i}},a.Meter.prototype.getLevel=function(a){a=this.defaultArg(a,0);var b=this._volume[a];return 1e-5>b?0:b},a.Meter.prototype.getValue=function(a){return a=this.defaultArg(a,0),this._values[a]},a.Meter.prototype.getDb=function(a){return this.gainToDb(this.getLevel(a))},a.Meter.prototype.isClipped=function(){return Date.now()-this._lastClip0){if(a.Buffer._currentDownloads.length0){for(b=0;g>b;b++)c=a.Buffer._currentDownloads[b],f+=c.progress;h=f}d=g-h,e=a.Buffer._totalDownloads-a.Buffer._queue.length-d,a.Buffer.onprogress(e/a.Buffer._totalDownloads)},a.Buffer.load=function(b,c){var d=new XMLHttpRequest;return d.open("GET",b,!0),d.responseType="arraybuffer",d.onload=function(){a.context.decodeAudioData(d.response,function(a){if(!a)throw new Error("could not decode audio data:"+b);c(a)})},d.send(),d},a.Buffer.onload=function(){},a.Buffer.onprogress=function(){},a.Buffer.onerror=function(){},a.Buffer}),ToneModule(function(a){var b={};return a.prototype.send=function(a,c){b.hasOwnProperty(a)||(b[a]=this.context.createGain());var d=this.context.createGain();return d.gain.value=this.dbToGain(this.defaultArg(c,1)),this.output.chain(d,b[a]),d},a.prototype.receive=function(a,c){return b.hasOwnProperty(a)||(b[a]=this.context.createGain()),this.isUndef(c)&&(c=this.input),b[a].connect(c),this},a}),ToneModule(function(a){function b(a,b,d){var e,f,g,h;if(c.hasOwnProperty(a))for(e=c[a],f=0,g=e.length;g>f;f++)h=e[f],Array.isArray(d)?h.apply(window,[b].concat(d)):h(b,d)}var c,d,e,f;return a.Note=function(b,c,d){this.value=d,this._channel=b,this._timelineID=a.Transport.setTimeline(this._trigger.bind(this),c)},a.Note.prototype._trigger=function(a){b(this._channel,a,this.value)},a.Note.prototype.dispose=function(){return a.Tranport.clearTimeline(this._timelineID),this.value=null,this},c={},a.Note.route=function(a,b){c.hasOwnProperty(a)?c[a].push(b):c[a]=[b]},a.Note.unroute=function(a,b){var d,e;c.hasOwnProperty(a)&&(d=c[a],e=d.indexOf(b),-1!==e&&c[a].splice(e,1))},a.Note.parseScore=function(b){var c,d,e,f,g,h,i,j=[];for(c in b)if(d=b[c],"tempo"===c)a.Transport.bpm.value=d;else if("timeSignature"===c)a.Transport.timeSignature=d[0]/(d[1]/4);else{if(!Array.isArray(d))throw new TypeError("score parts must be Arrays");for(e=0;ed;++d)e=2*d/c-1,b[d]=0===e?0:this._getCoefficient(e,a,{});this._shaper.curve=b}}),Object.defineProperty(a.Chebyshev.prototype,"oversample",{get:function(){return this._shaper.oversample},set:function(a){this._shaper.oversample=a}}),a.Chebyshev.prototype.dispose=function(){return a.Effect.prototype.dispose.call(this),this._shaper.dispose(),this._shaper=null,this},a.Chebyshev}),ToneModule(function(a){return a.StereoEffect=function(){a.call(this);var b=this.optionsObject(arguments,["wet"],a.Effect.defaults);this._dryWet=new a.CrossFade(b.wet),this.wet=this._dryWet.fade,this._split=new a.Split,this.effectSendL=this._split.left,this.effectSendR=this._split.right,this._merge=new a.Merge,this.effectReturnL=this._merge.left,this.effectReturnR=this._merge.right,this.input.connect(this._split),this.input.connect(this._dryWet,0,0),this._merge.connect(this._dryWet,0,1),this._dryWet.connect(this.output),this._readOnly(["wet"])},a.extend(a.StereoEffect,a.Effect),a.StereoEffect.prototype.dispose=function(){return a.prototype.dispose.call(this),this._dryWet.dispose(),this._dryWet=null,this._split.dispose(),this._split=null,this._merge.dispose(),this._merge=null,this.effectSendL=null,this.effectSendR=null,this.effectReturnL=null,this.effectReturnR=null,this._writable(["wet"]),this.wet=null,this},a.StereoEffect}),ToneModule(function(a){return a.FeedbackEffect=function(){var b=this.optionsObject(arguments,["feedback"]);b=this.defaultArg(b,a.FeedbackEffect.defaults),a.Effect.call(this,b),this.feedback=new a.Signal(b.feedback,a.Signal.Units.Normal),this._feedbackGain=this.context.createGain(),this.effectReturn.chain(this._feedbackGain,this.effectSend),this.feedback.connect(this._feedbackGain.gain),this._readOnly(["feedback"])},a.extend(a.FeedbackEffect,a.Effect),a.FeedbackEffect.defaults={feedback:.125},a.FeedbackEffect.prototype.dispose=function(){return a.Effect.prototype.dispose.call(this),this._writable(["feedback"]),this.feedback.dispose(),this.feedback=null,this._feedbackGain.disconnect(),this._feedbackGain=null,this},a.FeedbackEffect}),ToneModule(function(a){return a.StereoXFeedbackEffect=function(){var b=this.optionsObject(arguments,["feedback"],a.FeedbackEffect.defaults);a.StereoEffect.call(this,b),this.feedback=new a.Signal(b.feedback),this._feedbackLR=this.context.createGain(),this._feedbackRL=this.context.createGain(),this.effectReturnL.chain(this._feedbackLR,this.effectSendR),this.effectReturnR.chain(this._feedbackRL,this.effectSendL),this.feedback.fan(this._feedbackLR.gain,this._feedbackRL.gain),this._readOnly(["feedback"])},a.extend(a.StereoXFeedbackEffect,a.FeedbackEffect),a.StereoXFeedbackEffect.prototype.dispose=function(){return a.StereoEffect.prototype.dispose.call(this),this._writable(["feedback"]),this.feedback.dispose(),this.feedback=null,this._feedbackLR.disconnect(),this._feedbackLR=null,this._feedbackRL.disconnect(),this._feedbackRL=null,this},a.StereoXFeedbackEffect}),ToneModule(function(a){return a.Chorus=function(){var b=this.optionsObject(arguments,["frequency","delayTime","depth"],a.Chorus.defaults);a.StereoXFeedbackEffect.call(this,b),this._depth=b.depth,this._delayTime=b.delayTime/1e3,this._lfoL=new a.LFO(b.rate,0,1),this._lfoR=new a.LFO(b.rate,0,1),this._lfoR.phase=180,this._delayNodeL=this.context.createDelay(),this._delayNodeR=this.context.createDelay(),this.frequency=this._lfoL.frequency,this.connectSeries(this.effectSendL,this._delayNodeL,this.effectReturnL),this.connectSeries(this.effectSendR,this._delayNodeR,this.effectReturnR),this.effectSendL.connect(this.effectReturnL),this.effectSendR.connect(this.effectReturnR),this._lfoL.connect(this._delayNodeL.delayTime),this._lfoR.connect(this._delayNodeR.delayTime),this._lfoL.start(),this._lfoR.start(),this._lfoL.frequency.connect(this._lfoR.frequency),this.depth=this._depth,this.frequency.value=b.frequency,this.type=b.type,this._readOnly(["frequency"])},a.extend(a.Chorus,a.StereoXFeedbackEffect),a.Chorus.defaults={frequency:1.5,delayTime:3.5,depth:.7,feedback:.1,type:"sine"},Object.defineProperty(a.Chorus.prototype,"depth",{get:function(){return this._depth},set:function(a){this._depth=a;var b=this._delayTime*a;this._lfoL.min=Math.max(this._delayTime-b,0),this._lfoL.max=this._delayTime+b,this._lfoR.min=Math.max(this._delayTime-b,0),this._lfoR.max=this._delayTime+b}}),Object.defineProperty(a.Chorus.prototype,"delayTime",{get:function(){return 1e3*this._delayTime},set:function(a){this._delayTime=a/1e3,this.depth=this._depth}}),Object.defineProperty(a.Chorus.prototype,"type",{get:function(){return this._lfoL.type},set:function(a){this._lfoL.type=a,this._lfoR.type=a}}),a.Chorus.prototype.dispose=function(){return a.StereoXFeedbackEffect.prototype.dispose.call(this),this._lfoL.dispose(),this._lfoL=null,this._lfoR.dispose(),this._lfoR=null,this._delayNodeL.disconnect(),this._delayNodeL=null,this._delayNodeR.disconnect(),this._delayNodeR=null,this._writable("frequency"),this.frequency=null,this},a.Chorus}),ToneModule(function(a){return a.Convolver=function(){var b=this.optionsObject(arguments,["url"],a.Convolver.defaults);a.Effect.call(this,b),this._convolver=this.context.createConvolver(),this._buffer=new a.Buffer(b.url,function(a){this.buffer=a,b.onload()}.bind(this)),this.connectEffect(this._convolver)},a.extend(a.Convolver,a.Effect),a.Convolver.defaults={url:"",onload:function(){}},Object.defineProperty(a.Convolver.prototype,"buffer",{get:function(){return this._buffer.get()},set:function(a){this._buffer.set(a),this._convolver.buffer=this._buffer.get()}}),a.Convolver.prototype.load=function(a,b){return this._buffer.load(a,function(a){this.buffer=a,b&&b()}.bind(this)),this},a.Convolver.prototype.dispose=function(){return a.Effect.prototype.dispose.call(this),this._convolver.disconnect(),this._convolver=null,this._buffer.dispose(),this._buffer=null,this},a.Convolver}),ToneModule(function(a){return a.Distortion=function(){var b=this.optionsObject(arguments,["distortion"],a.Distortion.defaults);a.Effect.call(this),this._shaper=new a.WaveShaper(4096),this._distortion=b.distortion,this.connectEffect(this._shaper),this.distortion=b.distortion,this.oversample=b.oversample},a.extend(a.Distortion,a.Effect),a.Distortion.defaults={distortion:.4,oversample:"none"},Object.defineProperty(a.Distortion.prototype,"distortion",{get:function(){return this._distortion},set:function(a){var b,c;this._distortion=a,b=100*a,c=Math.PI/180,this._shaper.setMap(function(a){return Math.abs(a)<.001?0:(3+b)*a*20*c/(Math.PI+b*Math.abs(a))})}}),Object.defineProperty(a.Distortion.prototype,"oversample",{get:function(){return this._shaper.oversample},set:function(a){this._shaper.oversample=a}}),a.Distortion.prototype.dispose=function(){return a.Effect.prototype.dispose.call(this),this._shaper.dispose(),this._shaper=null,this},a.Distortion}),ToneModule(function(a){return a.FeedbackDelay=function(){var b=this.optionsObject(arguments,["delayTime","feedback"],a.FeedbackDelay.defaults);a.FeedbackEffect.call(this,b),this.delayTime=new a.Signal(b.delayTime,a.Signal.Units.Time),this._delayNode=this.context.createDelay(4),this.connectEffect(this._delayNode),this.delayTime.connect(this._delayNode.delayTime),this._readOnly(["delayTime"])},a.extend(a.FeedbackDelay,a.FeedbackEffect),a.FeedbackDelay.defaults={delayTime:.25},a.FeedbackDelay.prototype.dispose=function(){return a.FeedbackEffect.prototype.dispose.call(this),this.delayTime.dispose(),this._delayNode.disconnect(),this._delayNode=null,this._writable(["delayTime"]),this.delayTime=null,this},a.FeedbackDelay}),ToneModule(function(a){var b=[1557/44100,1617/44100,1491/44100,1422/44100,1277/44100,1356/44100,1188/44100,1116/44100],c=[225,556,441,341];return a.Freeverb=function(){var d,e,f,g,h,i,j=this.optionsObject(arguments,["roomSize","dampening"],a.Freeverb.defaults);for(a.StereoEffect.call(this,j),this.roomSize=new a.Signal(j.roomSize,a.Signal.Units.Normal),this.dampening=new a.Signal(j.dampening,a.Signal.Units.Frequency),this._combFilters=[],this._allpassFiltersL=[],this._allpassFiltersR=[],d=0;dd;d++)e=this.context.createBiquadFilter(),e.type="allpass",e.Q.value=c,b.connect(e.frequency),f[d]=e;return this.connectSeries.apply(this,f),f},Object.defineProperty(a.Phaser.prototype,"depth",{get:function(){return this._depth},set:function(a){this._depth=a;var b=this._baseFrequency+this._baseFrequency*a;this._lfoL.max=b,this._lfoR.max=b}}),Object.defineProperty(a.Phaser.prototype,"baseFrequency",{get:function(){return this._baseFrequency},set:function(a){this._baseFrequency=a,this._lfoL.min=a,this._lfoR.min=a,this.depth=this._depth}}),a.Phaser.prototype.dispose=function(){var b,c;for(a.StereoEffect.prototype.dispose.call(this),this._lfoL.dispose(),this._lfoL=null,this._lfoR.dispose(),this._lfoR=null,b=0;ba?-1:1}),this._sawtooth.chain(this._thresh,this.output),this.width.chain(this._widthGate,this._thresh),this._readOnly(["width","frequency","detune"])},a.extend(a.PulseOscillator,a.Oscillator),a.PulseOscillator.defaults={frequency:440,detune:0,phase:0,width:.2},a.PulseOscillator.prototype._start=function(a){a=this.toSeconds(a),this._sawtooth.start(a),this._widthGate.gain.setValueAtTime(1,a)},a.PulseOscillator.prototype._stop=function(a){a=this.toSeconds(a),this._sawtooth.stop(a),this._widthGate.gain.setValueAtTime(0,a)},Object.defineProperty(a.PulseOscillator.prototype,"phase",{get:function(){return this._sawtooth.phase},set:function(a){this._sawtooth.phase=a}}),Object.defineProperty(a.PulseOscillator.prototype,"type",{get:function(){return"pulse"}}),a.PulseOscillator.prototype.dispose=function(){return a.Source.prototype.dispose.call(this),this._sawtooth.dispose(),this._sawtooth=null,this._writable(["width","frequency","detune"]),this.width.dispose(),this.width=null,this._widthGate.disconnect(),this._widthGate=null,this._widthGate=null,this._thresh.disconnect(),this._thresh=null,this.frequency=null,this.detune=null,this},a.PulseOscillator}),ToneModule(function(a){return a.PWMOscillator=function(){var b=this.optionsObject(arguments,["frequency","modulationFrequency"],a.PWMOscillator.defaults);a.Source.call(this,b),this._pulse=new a.PulseOscillator(b.modulationFrequency),this._pulse._sawtooth.type="sine",this._modulator=new a.Oscillator({frequency:b.frequency,detune:b.detune}),this._scale=new a.Multiply(1.01),this.frequency=this._modulator.frequency,this.detune=this._modulator.detune,this.modulationFrequency=this._pulse.frequency,this._modulator.chain(this._scale,this._pulse.width),this._pulse.connect(this.output),this._readOnly(["modulationFrequency","frequency","detune"])},a.extend(a.PWMOscillator,a.Oscillator),a.PWMOscillator.defaults={frequency:440,detune:0,modulationFrequency:.4},a.PWMOscillator.prototype._start=function(a){a=this.toSeconds(a),this._modulator.start(a),this._pulse.start(a)},a.PWMOscillator.prototype._stop=function(a){a=this.toSeconds(a),this._modulator.stop(a),this._pulse.stop(a)},Object.defineProperty(a.PWMOscillator.prototype,"type",{get:function(){return"pwm"}}),Object.defineProperty(a.PWMOscillator.prototype,"phase",{get:function(){return this._modulator.phase},set:function(a){this._modulator.phase=a}}),a.PWMOscillator.prototype.dispose=function(){return a.Source.prototype.dispose.call(this),this._pulse.dispose(),this._pulse=null,this._scale.dispose(),this._scale=null,this._modulator.dispose(),this._modulator=null,this._writable(["modulationFrequency","frequency","detune"]),this.frequency=null,this.detune=null,this.modulationFrequency=null,this},a.PWMOscillator}),ToneModule(function(a){a.OmniOscillator=function(){var b=this.optionsObject(arguments,["frequency","type"],a.OmniOscillator.defaults);a.Source.call(this,b),this.frequency=new a.Signal(b.frequency,a.Signal.Units.Frequency),this.detune=new a.Signal(b.detune),this._sourceType=void 0,this._oscillator=null,this.type=b.type,this._readOnly(["frequency","detune"])},a.extend(a.OmniOscillator,a.Oscillator),a.OmniOscillator.defaults={frequency:440,detune:0,type:"sine",width:.4,modulationFrequency:.4};var b={PulseOscillator:"PulseOscillator",PWMOscillator:"PWMOscillator",Oscillator:"Oscillator"};return a.OmniOscillator.prototype._start=function(a){this._oscillator.start(a)},a.OmniOscillator.prototype._stop=function(a){this._oscillator.stop(a)},Object.defineProperty(a.OmniOscillator.prototype,"type",{get:function(){return this._oscillator.type},set:function(c){if("sine"===c||"square"===c||"triangle"===c||"sawtooth"===c)this._sourceType!==b.Oscillator&&(this._sourceType=b.Oscillator,this._createNewOscillator(a.Oscillator)),this._oscillator.type=c;else if("pwm"===c)this._sourceType!==b.PWMOscillator&&(this._sourceType=b.PWMOscillator,this._createNewOscillator(a.PWMOscillator));else{if("pulse"!==c)throw new TypeError("Tone.OmniOscillator does not support type "+c);this._sourceType!==b.PulseOscillator&&(this._sourceType=b.PulseOscillator,this._createNewOscillator(a.PulseOscillator))}}}),a.OmniOscillator.prototype._createNewOscillator=function(b){var c,d=this.now()+this.bufferTime;null!==this._oscillator&&(c=this._oscillator,c.stop(d),c.onended=function(){c.dispose(),c=null}),this._oscillator=new b,this.frequency.connect(this._oscillator.frequency),this.detune.connect(this._oscillator.detune),this._oscillator.connect(this.output),this.state===a.Source.State.STARTED&&this._oscillator.start(d)},Object.defineProperty(a.OmniOscillator.prototype,"phase",{get:function(){return this._oscillator.phase},set:function(a){this._oscillator.phase=a}}),Object.defineProperty(a.OmniOscillator.prototype,"width",{get:function(){return this._sourceType===b.PulseOscillator?this._oscillator.width:void 0}}),Object.defineProperty(a.OmniOscillator.prototype,"modulationFrequency",{get:function(){return this._sourceType===b.PWMOscillator?this._oscillator.modulationFrequency:void 0}}),a.OmniOscillator.prototype.dispose=function(){return a.Source.prototype.dispose.call(this),this._writable(["frequency","detune"]),this.detune.dispose(),this.detune=null,this.frequency.dispose(),this.frequency=null,this._oscillator.dispose(),this._oscillator=null,this._sourceType=null,this},a.OmniOscillator}),ToneModule(function(a){return a.Instrument=function(){this.output=this.context.createGain(),this.volume=new a.Signal(this.output.gain,a.Signal.Units.Decibels),this._readOnly(["volume"])},a.extend(a.Instrument),a.Instrument.prototype.triggerAttack=function(){},a.Instrument.prototype.triggerRelease=function(){},a.Instrument.prototype.triggerAttackRelease=function(a,b,c,d){return c=this.toSeconds(c),b=this.toSeconds(b),this.triggerAttack(a,c,d),this.triggerRelease(c+b),this},a.Instrument.prototype.dispose=function(){return a.prototype.dispose.call(this),this._writable(["volume"]),this.volume.dispose(),this.volume=null,this},a.Instrument}),ToneModule(function(a){return a.Monophonic=function(b){a.Instrument.call(this),b=this.defaultArg(b,a.Monophonic.defaults),this.portamento=b.portamento},a.extend(a.Monophonic,a.Instrument),a.Monophonic.defaults={portamento:0},a.Monophonic.prototype.triggerAttack=function(a,b,c){return b=this.toSeconds(b),this.triggerEnvelopeAttack(b,c),this.setNote(a,b),this},a.Monophonic.prototype.triggerRelease=function(a){return this.triggerEnvelopeRelease(a),this},a.Monophonic.prototype.triggerEnvelopeAttack=function(){},a.Monophonic.prototype.triggerEnvelopeRelease=function(){},a.Monophonic.prototype.setNote=function(a,b){var c,d;return b=this.toSeconds(b),this.portamento>0?(c=this.frequency.value,this.frequency.setValueAtTime(c,b),d=this.toSeconds(this.portamento),this.frequency.exponentialRampToValueAtTime(a,b+d)):this.frequency.setValueAtTime(a,b),this},a.Monophonic}),ToneModule(function(a){return a.MonoSynth=function(b){b=this.defaultArg(b,a.MonoSynth.defaults),a.Monophonic.call(this,b),this.oscillator=new a.OmniOscillator(b.oscillator),this.frequency=this.oscillator.frequency,this.detune=this.oscillator.detune,this.filter=new a.Filter(b.filter),this.filterEnvelope=new a.ScaledEnvelope(b.filterEnvelope),this.envelope=new a.AmplitudeEnvelope(b.envelope),this.oscillator.chain(this.filter,this.envelope,this.output),this.oscillator.start(),this.filterEnvelope.connect(this.filter.frequency),this._readOnly(["oscillator","frequency","detune","filter","filterEnvelope","envelope"])},a.extend(a.MonoSynth,a.Monophonic),a.MonoSynth.defaults={frequency:"C4",detune:0,oscillator:{type:"square"},filter:{Q:6,type:"lowpass",rolloff:-24},envelope:{attack:.005,decay:.1,sustain:.9,release:1},filterEnvelope:{attack:.06,decay:.2,sustain:.5,release:2,min:20,max:4e3,exponent:2}},a.MonoSynth.prototype.triggerEnvelopeAttack=function(a,b){return this.envelope.triggerAttack(a,b),this.filterEnvelope.triggerAttack(a),this},a.MonoSynth.prototype.triggerEnvelopeRelease=function(a){return this.envelope.triggerRelease(a),this.filterEnvelope.triggerRelease(a),this},a.MonoSynth.prototype.dispose=function(){return a.Monophonic.prototype.dispose.call(this),this._writable(["oscillator","frequency","detune","filter","filterEnvelope","envelope"]),this.oscillator.dispose(),this.oscillator=null,this.envelope.dispose(),this.envelope=null,this.filterEnvelope.dispose(),this.filterEnvelope=null,this.filter.dispose(),this.filter=null,this.frequency=null,this.detune=null,this},a.MonoSynth}),ToneModule(function(a){return a.AMSynth=function(b){b=this.defaultArg(b,a.AMSynth.defaults),a.Monophonic.call(this,b),this.carrier=new a.MonoSynth(b.carrier),this.carrier.volume.value=-10,this.modulator=new a.MonoSynth(b.modulator),this.modulator.volume.value=-10,this.frequency=new a.Signal(440,a.Signal.Units.Frequency),this._harmonicity=new a.Multiply(b.harmonicity),this._modulationScale=new a.AudioToGain,this._modulationNode=this.context.createGain(),this.frequency.connect(this.carrier.frequency),this.frequency.chain(this._harmonicity,this.modulator.frequency),this.modulator.chain(this._modulationScale,this._modulationNode.gain),this.carrier.chain(this._modulationNode,this.output),this._readOnly(["carrier","modulator","frequency"])},a.extend(a.AMSynth,a.Monophonic),a.AMSynth.defaults={harmonicity:3,carrier:{volume:-10,oscillator:{type:"sine"},envelope:{attack:.01,decay:.01,sustain:1,release:.5},filterEnvelope:{attack:.01,decay:0,sustain:1,release:.5,min:2e4,max:2e4},filter:{Q:6,type:"lowpass",rolloff:-24}},modulator:{volume:-10,oscillator:{type:"square"},envelope:{attack:2,decay:0,sustain:1,release:.5},filterEnvelope:{attack:4,decay:.2,sustain:.5,release:.5,min:20,max:1500},filter:{Q:6,type:"lowpass",rolloff:-24}}},a.AMSynth.prototype.triggerEnvelopeAttack=function(a,b){return a=this.toSeconds(a),this.carrier.envelope.triggerAttack(a,b),this.modulator.envelope.triggerAttack(a),this.carrier.filterEnvelope.triggerAttack(a),this.modulator.filterEnvelope.triggerAttack(a),this},a.AMSynth.prototype.triggerEnvelopeRelease=function(a){return this.carrier.triggerRelease(a),this.modulator.triggerRelease(a),this},Object.defineProperty(a.AMSynth.prototype,"harmonicity",{get:function(){return this._harmonicity.value},set:function(a){this._harmonicity.value=a}}),a.AMSynth.prototype.dispose=function(){return a.Monophonic.prototype.dispose.call(this),this._writable(["carrier","modulator","frequency"]),this.carrier.dispose(),this.carrier=null,this.modulator.dispose(),this.modulator=null,this.frequency.dispose(),this.frequency=null,this._harmonicity.dispose(),this._harmonicity=null,this._modulationScale.dispose(),this._modulationScale=null,this._modulationNode.disconnect(),this._modulationNode=null,this},a.AMSynth}),ToneModule(function(a){return a.DroneSynth=function(b){b=this.defaultArg(b,a.DroneSynth.defaults),a.Monophonic.call(this,b),this.oscillator=new a.OmniOscillator(b.oscillator),this.frequency=this.oscillator.frequency,this.detune=this.oscillator.detune,this.envelope=new a.AmplitudeEnvelope(b.envelope),this.oscillator.chain(this.envelope,this.output),this.oscillator.start(),this._readOnly(["oscillator","frequency","detune","envelope"])},a.extend(a.DroneSynth,a.Monophonic),a.DroneSynth.defaults={oscillator:{type:"triangle"},envelope:{attack:.005,decay:.1,sustain:.3,release:1}},a.DroneSynth.prototype.triggerEnvelopeAttack=function(a,b){return this.envelope.triggerAttack(a,b),this},a.DroneSynth.prototype.triggerEnvelopeRelease=function(a){return this.envelope.triggerRelease(a),this},a.DroneSynth.prototype.dispose=function(){return a.Monophonic.prototype.dispose.call(this),this._writable(["oscillator","frequency","detune","envelope"]),this.oscillator.dispose(),this.oscillator=null,this.envelope.dispose(),this.envelope=null,this.frequency=null,this.detune=null,this},a.DroneSynth}),ToneModule(function(a){return a.DrumSynth=function(b){b=this.defaultArg(b,a.DrumSynth.defaults),a.Instrument.call(this,b),this.oscillator=new a.Oscillator(b.oscillator).start(),this.envelope=new a.AmplitudeEnvelope(b.envelope),this.octaves=b.octaves,this.pitchDecay=b.pitchDecay,this.oscillator.chain(this.envelope,this.output),this._readOnly(["oscillator","envelope"])},a.extend(a.DrumSynth,a.Instrument),a.DrumSynth.defaults={pitchDecay:.05,octaves:10,oscillator:{type:"sine"},envelope:{attack:.001,decay:.4,sustain:.01,release:1.4,attackCurve:"exponential"}},a.DrumSynth.prototype.triggerAttack=function(a,b,c){b=this.toSeconds(b),a=this.toFrequency(a);var d=a*this.octaves;return this.oscillator.frequency.setValueAtTime(d,b),this.oscillator.frequency.exponentialRampToValueAtTime(a,b+this.toSeconds(this.pitchDecay)),this.envelope.triggerAttack(b,c),this},a.DrumSynth.prototype.triggerRelease=function(a){return this.envelope.triggerRelease(a),this},a.DrumSynth.prototype.dispose=function(){return a.Instrument.prototype.dispose.call(this),this._writable(["oscillator","envelope"]),this.oscillator.dispose(),this.oscillator=null,this.envelope.dispose(),this.envelope=null,this},a.DrumSynth}),ToneModule(function(a){return a.DuoSynth=function(b){b=this.defaultArg(b,a.DuoSynth.defaults),a.Monophonic.call(this,b),this.voice0=new a.MonoSynth(b.voice0),this.voice0.volume.value=-10,this.voice1=new a.MonoSynth(b.voice1),this.voice1.volume.value=-10,this._vibrato=new a.LFO(b.vibratoRate,-50,50),this._vibrato.start(),this.vibratoRate=this._vibrato.frequency,this._vibratoGain=this.context.createGain(),this.vibratoAmount=new a.Signal(this._vibratoGain.gain,a.Signal.Units.Gain),this.vibratoAmount.value=b.vibratoAmount,this._vibratoDelay=this.toSeconds(b.vibratoDelay),this.frequency=new a.Signal(440,a.Signal.Units.Frequency),this._harmonicity=new a.Multiply(b.harmonicity),this.frequency.connect(this.voice0.frequency),this.frequency.chain(this._harmonicity,this.voice1.frequency),this._vibrato.connect(this._vibratoGain),this._vibratoGain.fan(this.voice0.detune,this.voice1.detune),this.voice0.connect(this.output),this.voice1.connect(this.output),this._readOnly(["voice0","voice1","frequency","vibratoAmount","vibratoRate"])},a.extend(a.DuoSynth,a.Monophonic),a.DuoSynth.defaults={vibratoAmount:.5,vibratoRate:5,vibratoDelay:1,harmonicity:1.5,voice0:{volume:-10,portamento:0,oscillator:{type:"sine"},filterEnvelope:{attack:.01,decay:0,sustain:1,release:.5},envelope:{attack:.01,decay:0,sustain:1,release:.5}},voice1:{volume:-10,portamento:0,oscillator:{type:"sine"},filterEnvelope:{attack:.01,decay:0,sustain:1,release:.5},envelope:{attack:.01,decay:0,sustain:1,release:.5}}},a.DuoSynth.prototype.triggerEnvelopeAttack=function(a,b){return a=this.toSeconds(a),this.voice0.envelope.triggerAttack(a,b),this.voice1.envelope.triggerAttack(a,b),this.voice0.filterEnvelope.triggerAttack(a),this.voice1.filterEnvelope.triggerAttack(a),this},a.DuoSynth.prototype.triggerEnvelopeRelease=function(a){return this.voice0.triggerRelease(a),this.voice1.triggerRelease(a),this},Object.defineProperty(a.DuoSynth.prototype,"harmonicity",{get:function(){return this._harmonicity.value},set:function(a){this._harmonicity.value=a}}),a.DuoSynth.prototype.dispose=function(){return a.Monophonic.prototype.dispose.call(this),this._writable(["voice0","voice1","frequency","vibratoAmount","vibratoRate"]),this.voice0.dispose(),this.voice0=null,this.voice1.dispose(),this.voice1=null,this.frequency.dispose(),this.frequency=null,this._vibrato.dispose(),this._vibrato=null,this._vibratoGain.disconnect(),this._vibratoGain=null,this._harmonicity.dispose(),this._harmonicity=null,this.vibratoAmount.dispose(),this.vibratoAmount=null,this.vibratoRate=null,this},a.DuoSynth}),ToneModule(function(a){return a.FMSynth=function(b){b=this.defaultArg(b,a.FMSynth.defaults),a.Monophonic.call(this,b),this.carrier=new a.MonoSynth(b.carrier),this.carrier.volume.value=-10,this.modulator=new a.MonoSynth(b.modulator),this.modulator.volume.value=-10,this.frequency=new a.Signal(440,a.Signal.Units.Frequency),this._harmonicity=new a.Multiply(b.harmonicity),this._modulationIndex=new a.Multiply(b.modulationIndex),this._modulationNode=this.context.createGain(),this.frequency.connect(this.carrier.frequency),this.frequency.chain(this._harmonicity,this.modulator.frequency),this.frequency.chain(this._modulationIndex,this._modulationNode),this.modulator.connect(this._modulationNode.gain),this._modulationNode.gain.value=0,this._modulationNode.connect(this.carrier.frequency),this.carrier.connect(this.output),this._readOnly(["carrier","modulator","frequency"])},a.extend(a.FMSynth,a.Monophonic),a.FMSynth.defaults={harmonicity:3,modulationIndex:10,carrier:{volume:-10,portamento:0,oscillator:{type:"sine"},envelope:{attack:.01,decay:0,sustain:1,release:.5},filterEnvelope:{attack:.01,decay:0,sustain:1,release:.5,min:2e4,max:2e4}},modulator:{volume:-10,portamento:0,oscillator:{type:"triangle"},envelope:{attack:.01,decay:0,sustain:1,release:.5},filterEnvelope:{attack:.01,decay:0,sustain:1,release:.5,min:2e4,max:2e4}}},a.FMSynth.prototype.triggerEnvelopeAttack=function(a,b){return a=this.toSeconds(a),this.carrier.envelope.triggerAttack(a,b),this.modulator.envelope.triggerAttack(a),this.carrier.filterEnvelope.triggerAttack(a),this.modulator.filterEnvelope.triggerAttack(a),this},a.FMSynth.prototype.triggerEnvelopeRelease=function(a){return this.carrier.triggerRelease(a),this.modulator.triggerRelease(a),this},Object.defineProperty(a.FMSynth.prototype,"harmonicity",{get:function(){return this._harmonicity.value},set:function(a){this._harmonicity.value=a}}),Object.defineProperty(a.FMSynth.prototype,"modulationIndex",{get:function(){return this._modulationIndex.value},set:function(a){this._modulationIndex.value=a}}),a.FMSynth.prototype.dispose=function(){return a.Monophonic.prototype.dispose.call(this),this._writable(["carrier","modulator","frequency"]),this.carrier.dispose(),this.carrier=null,this.modulator.dispose(),this.modulator=null,this.frequency.dispose(),this.frequency=null,this._modulationIndex.dispose(),this._modulationIndex=null,this._harmonicity.dispose(),this._harmonicity=null,this._modulationNode.disconnect(),this._modulationNode=null,this},a.FMSynth}),ToneModule(function(a){a.Noise=function(){var b=this.optionsObject(arguments,["type"],a.Noise.defaults);a.Source.call(this,b),this._source=null,this._buffer=null,this.type=b.type},a.extend(a.Noise,a.Source),a.Noise.defaults={type:"white"},Object.defineProperty(a.Noise.prototype,"type",{get:function(){return this._buffer===d?"white":this._buffer===c?"brown":this._buffer===b?"pink":void 0},set:function(e){if(this.type!==e){switch(e){case"white":this._buffer=d;break;case"pink":this._buffer=b;break;case"brown":this._buffer=c;break;default:this._buffer=d}if(this.state===a.Source.State.STARTED){var f=this.now()+this.bufferTime;this._source.onended=void 0,this._stop(f),this._start(f)}}}}),a.Noise.prototype._start=function(a){this._source=this.context.createBufferSource(),this._source.buffer=this._buffer,this._source.loop=!0,this.connectSeries(this._source,this.output),this._source.start(this.toSeconds(a)),this._source.onended=this.onended},a.Noise.prototype._stop=function(a){this._source&&this._source.stop(this.toSeconds(a))},a.Noise.prototype.dispose=function(){return a.Source.prototype.dispose.call(this),null!==this._source&&(this._source.disconnect(),this._source=null),this._buffer=null,this};var b=null,c=null,d=null;return a._initAudioContext(function(a){var e=a.sampleRate,f=4*e;b=function(){var b,c,d,g,h,i,j,k,l,m,n,o=a.createBuffer(2,f,e);for(b=0;bm;m++)n=2*Math.random()-1,d=.99886*d+.0555179*n,g=.99332*g+.0750759*n,h=.969*h+.153852*n,i=.8665*i+.3104856*n,j=.55*j+.5329522*n,k=-.7616*k-.016898*n,c[m]=d+g+h+i+j+k+l+.5362*n,c[m]*=.11,l=.115926*n;return o}(),c=function(){var b,c,d,g,h,i=a.createBuffer(2,f,e);for(b=0;bg;g++)h=2*Math.random()-1,c[g]=(d+.02*h)/1.02,d=c[g],c[g]*=3.5;return i}(),d=function(){var b,c,d,g=a.createBuffer(2,f,e);for(b=0;bd;d++)c[d]=2*Math.random()-1;return g}()}),a.Noise}),ToneModule(function(a){return a.NoiseSynth=function(b){b=this.defaultArg(b,a.NoiseSynth.defaults),a.Instrument.call(this),this.noise=new a.Noise,this.filter=new a.Filter(b.filter),this.filterEnvelope=new a.ScaledEnvelope(b.filterEnvelope),this.envelope=new a.AmplitudeEnvelope(b.envelope),this.noise.chain(this.filter,this.envelope,this.output),this.noise.start(),this.filterEnvelope.connect(this.filter.frequency),this._readOnly(["noise","filter","filterEnvelope","envelope"])},a.extend(a.NoiseSynth,a.Instrument),a.NoiseSynth.defaults={noise:{type:"white"},filter:{Q:6,type:"highpass",rolloff:-24},envelope:{attack:.005,decay:.1,sustain:0},filterEnvelope:{attack:.06,decay:.2,sustain:0,release:2,min:20,max:4e3,exponent:2}},a.NoiseSynth.prototype.triggerAttack=function(a,b){return this.envelope.triggerAttack(a,b),this.filterEnvelope.triggerAttack(a),this},a.NoiseSynth.prototype.triggerRelease=function(a){return this.envelope.triggerRelease(a),this.filterEnvelope.triggerRelease(a),this},a.NoiseSynth.prototype.triggerAttackRelease=function(a,b,c){return b=this.toSeconds(b),a=this.toSeconds(a),this.triggerAttack(b,c),this.triggerRelease(b+a),this},a.NoiseSynth.prototype.dispose=function(){return a.Instrument.prototype.dispose.call(this),this._writable(["noise","filter","filterEnvelope","envelope"]),this.noise.dispose(),this.noise=null,this.envelope.dispose(),this.envelope=null,this.filterEnvelope.dispose(),this.filterEnvelope=null,this.filter.dispose(),this.filter=null,this},a.NoiseSynth}),ToneModule(function(a){return a.PluckSynth=function(b){b=this.defaultArg(b,a.PluckSynth.defaults),a.Instrument.call(this),this._noise=new a.Noise("pink"),this.attackNoise=1,this._lfcf=new a.LowpassCombFilter(1/440),this.resonance=this._lfcf.resonance,this.dampening=this._lfcf.dampening,this._noise.connect(this._lfcf),this._lfcf.connect(this.output),this._readOnly(["resonance","dampening"])},a.extend(a.PluckSynth,a.Instrument),a.PluckSynth.defaults={attackNoise:1,dampening:4e3,resonance:.5},a.PluckSynth.prototype.triggerAttack=function(a,b){a=this.toFrequency(a),b=this.toSeconds(b); +var c=1/a;return this._lfcf.delayTime.setValueAtTime(c,b),this._noise.start(b),this._noise.stop(b+c*this.attackNoise),this},a.PluckSynth.prototype.dispose=function(){return a.Instrument.prototype.dispose.call(this),this._noise.dispose(),this._lfcf.dispose(),this._noise=null,this._lfcf=null,this._writable(["resonance","dampening"]),this.dampening=null,this.resonance=null,this},a.PluckSynth}),ToneModule(function(a){return a.PolySynth=function(){var b,c,d;for(a.Instrument.call(this),b=this.optionsObject(arguments,["polyphony","voice"],a.PolySynth.defaults),this.voices=new Array(b.polyphony),this._freeVoices=[],this._activeVoices={},c=0;c0&&(g=this._freeVoices.shift(),g.triggerAttack(e,b,c),this._activeVoices[f]=g);return this},a.PolySynth.prototype.triggerAttackRelease=function(a,b,c,d){return c=this.toSeconds(c),this.triggerAttack(a,c,d),this.triggerRelease(a,c+this.toSeconds(b)),this},a.PolySynth.prototype.triggerRelease=function(a,b){var c,d,e;for(Array.isArray(a)||(a=[a]),c=0;cc){var d=b;b=c,c=d}this.min=this.input=new a.Min(c),this._readOnly("min"),this.max=this.output=new a.Max(b),this._readOnly("max"),this.min.connect(this.max)},a.extend(a.Clip,a.SignalBase),a.Clip.prototype.dispose=function(){return a.prototype.dispose.call(this),this._writable("min"),this.min.dispose(),this.min=null,this._writable("max"),this.max.dispose(),this.max=null,this},a.Clip}),ToneModule(function(a){return a.Normalize=function(b,c){this._inputMin=this.defaultArg(b,0),this._inputMax=this.defaultArg(c,1),this._sub=this.input=new a.Add(0),this._div=this.output=new a.Multiply(1),this._sub.connect(this._div),this._setRange()},a.extend(a.Normalize,a.SignalBase),Object.defineProperty(a.Normalize.prototype,"min",{get:function(){return this._inputMin},set:function(a){this._inputMin=a,this._setRange()}}),Object.defineProperty(a.Normalize.prototype,"max",{get:function(){return this._inputMax},set:function(a){this._inputMax=a,this._setRange()}}),a.Normalize.prototype._setRange=function(){this._sub.value=-this._inputMin,this._div.value=1/(this._inputMax-this._inputMin)},a.Normalize.prototype.dispose=function(){return a.prototype.dispose.call(this),this._sub.dispose(),this._sub=null,this._div.dispose(),this._div=null,this},a.Normalize}),ToneModule(function(a){a.Route=function(c){var d,e;for(c=this.defaultArg(c,2),a.call(this,1,c),this.gate=new a.Signal(0),this._readOnly("gate"),d=0;c>d;d++)e=new b(d),this.output[d]=e,this.gate.connect(e.selecter),this.input.connect(e)},a.extend(a.Route,a.SignalBase),a.Route.prototype.select=function(a,b){return a=Math.floor(a),this.gate.setValueAtTime(a,this.toSeconds(b)),this},a.Route.prototype.dispose=function(){this._writable("gate"),this.gate.dispose(),this.gate=null;for(var b=0;b