/** * Tone.js * * @author Yotam Mann * * @license http://opensource.org/licenses/MIT MIT License 2014 */ !function(t){"function"!=typeof define&&"function"!=typeof t.Tone&&(t.define=function(){var e=arguments[arguments.length-1],i=arguments[0];"Tone/core/Tone"===i?t.Tone=e():"function"==typeof e&&e(t.Tone)})}(this),define("Tone/core/Tone",[],function(){function t(t){return void 0===t}var e;if(t(window.AudioContext)&&(window.AudioContext=window.webkitAudioContext),t(window.OfflineAudioContext)&&(window.OfflineAudioContext=window.webkitOfflineAudioContext),t(AudioContext))throw new Error("Web Audio is not supported in this browser");e=new AudioContext,"function"!=typeof AudioContext.prototype.createGain&&(AudioContext.prototype.createGain=AudioContext.prototype.createGainNode),"function"!=typeof AudioContext.prototype.createDelay&&(AudioContext.prototype.createDelay=AudioContext.prototype.createDelayNode),"function"!=typeof AudioContext.prototype.createPeriodicWave&&(AudioContext.prototype.createPeriodicWave=AudioContext.prototype.createWaveTable),"function"!=typeof AudioBufferSourceNode.prototype.start&&(AudioBufferSourceNode.prototype.start=AudioBufferSourceNode.prototype.noteGrainOn),"function"!=typeof AudioBufferSourceNode.prototype.stop&&(AudioBufferSourceNode.prototype.stop=AudioBufferSourceNode.prototype.noteOff),"function"!=typeof OscillatorNode.prototype.start&&(OscillatorNode.prototype.start=OscillatorNode.prototype.noteOn),"function"!=typeof OscillatorNode.prototype.stop&&(OscillatorNode.prototype.stop=OscillatorNode.prototype.noteOff),"function"!=typeof OscillatorNode.prototype.setPeriodicWave&&(OscillatorNode.prototype.setPeriodicWave=OscillatorNode.prototype.setWaveTable),AudioNode.prototype._nativeConnect=AudioNode.prototype.connect,AudioNode.prototype.connect=function(e,i,n){if(e.input)Array.isArray(e.input)?(t(n)&&(n=0),this.connect(e.input[n])):this.connect(e.input);else try{e instanceof AudioNode?this._nativeConnect(e,i,n):this._nativeConnect(e,i)}catch(o){throw new Error("error connecting to node: "+e)}};var i=function(){this.input=this.context.createGain(),this.output=this.context.createGain()};i.context=e,i.prototype.context=i.context,i.prototype.bufferSize=2048,i.prototype.connect=function(t,e,i){Array.isArray(this.output)?(e=this.defaultArg(e,0),this.output[e].connect(t,0,i)):this.output.connect(t,e,i)},i.prototype.disconnect=function(){this.output.disconnect()},i.prototype.chain=function(){if(arguments.length>1)for(var t=arguments[0],e=1;e1)for(var e=1;ei){var n=i;i=e,e=n}else if(e==i)return 0;return(t-e)/(i-e)},i.prototype.dispose=function(){this.isUndef(this.input)||(this.input instanceof AudioNode&&this.input.disconnect(),this.input=null),this.isUndef(this.output)||(this.output instanceof AudioNode&&this.output.disconnect(),this.output=null)};var n=null;i.prototype.noGC=function(){this.output.connect(n)},AudioNode.prototype.noGC=function(){this.connect(n)},i.prototype.now=function(){return this.context.currentTime},i.prototype.samplesToSeconds=function(t){return t/this.context.sampleRate},i.prototype.toSamples=function(t){var e=this.toSeconds(t);return Math.round(e*this.context.sampleRate)},i.prototype.toSeconds=function(t,e){if(e=this.defaultArg(e,this.now()),"number"==typeof t)return t;if("string"==typeof t){var i=0;return"+"===t.charAt(0)&&(t=t.slice(1),i=e),parseFloat(t)+i}return e},i.prototype.frequencyToSeconds=function(t){return 1/parseFloat(t)},i.prototype.secondsToFrequency=function(t){return 1/t};var o=[];return i._initAudioContext=function(t){t(i.context),o.push(t)},i.setContext=function(t){i.prototype.context=t,i.context=t;for(var e=0;es;s++)o[s]=1;i.curve=o,e.connect(i),e.start(0),e.noGC()}),t.Signal}),define("Tone/component/Envelope",["Tone/core/Tone","Tone/signal/Signal"],function(t){return t.Envelope=function(){var e=this.optionsObject(arguments,["attack","decay","sustain","release"],t.Envelope.defaults);this.output=this.context.createGain(),this.attack=this.toSeconds(e.attack),this.decay=this.toSeconds(e.decay),this.sustain=this.toSeconds(e.sustain),this.release=this.toSeconds(e.release),this.min=this.toSeconds(e.min),this.max=this.toSeconds(e.max),this._control=new t.Signal(this.min),this._control.connect(this.output)},t.extend(t.Envelope),t.Envelope.defaults={attack:.01,decay:.1,sustain:.5,release:1,min:0,max:1},t.Envelope.prototype.set=function(t){this.isUndef(t.attack)||this.setAttack(t.attack),this.isUndef(t.decay)||this.setDecay(t.decay),this.isUndef(t.sustain)||this.setSustain(t.sustain),this.isUndef(t.release)||this.setRelease(t.release),this.isUndef(t.min)||this.setMin(t.min),this.isUndef(t.max)||this.setMax(t.max)},t.Envelope.prototype.setAttack=function(t){this.attack=this.toSeconds(t)},t.Envelope.prototype.setDecay=function(t){this.decay=this.toSeconds(t)},t.Envelope.prototype.setRelease=function(t){this.release=this.toSeconds(t)},t.Envelope.prototype.setSustain=function(t){this.sustain=t},t.Envelope.prototype.setMax=function(t){this.max=t},t.Envelope.prototype.setMin=function(t){this.min=t,this._control.setValueAtTime(this.min,this.now())},t.Envelope.prototype.triggerAttack=function(t,e){e=this.defaultArg(e,1);var i=this.max*e,n=(i-this.min)*this.sustain+this.min;t=this.toSeconds(t),this._control.cancelScheduledValues(t),this._control.setTargetAtTime(i,t,this.attack/4),this._control.setTargetAtTime(n,t+this.attack,this.decay/4)},t.Envelope.prototype.triggerRelease=function(t){t=this.toSeconds(t),this._control.cancelScheduledValues(t),this._control.setTargetAtTime(this.min,t,this.toSeconds(this.release)/4)},t.Envelope.prototype.triggerAttackRelease=function(t,e,i){e=this.toSeconds(e),this.triggerAttack(e,i),this.triggerRelease(e+this.toSeconds(t))},t.Envelope.prototype.connect=t.Signal.prototype.connect,t.Envelope.prototype.dispose=function(){t.prototype.dispose.call(this),this._control.dispose(),this._control=null},t.Envelope}),define("Tone/component/AmplitudeEnvelope",["Tone/core/Tone","Tone/component/Envelope"],function(t){return t.AmplitudeEnvelope=function(){t.Envelope.apply(this,arguments),this.input=this.context.createGain(),this._control.disconnect(),this._control.connect(this.output.gain),this.input.connect(this.output)},t.extend(t.AmplitudeEnvelope,t.Envelope),t.AmplitudeEnvelope.prototype.dispose=function(){t.Envelope.prototype.dispose.call(this)},t.AmplitudeEnvelope}),define("Tone/signal/Add",["Tone/core/Tone","Tone/signal/Signal"],function(t){return t.Add=function(e){this._value=new t.Signal(e),this.input=this.output=this.context.createGain(),this._value.connect(this.output)},t.extend(t.Add),t.Add.prototype.setValue=function(t){this._value.setValue(t)},t.Add.prototype.connect=t.Signal.prototype.connect,t.Add.prototype.dispose=function(){t.prototype.dispose.call(this),this._value.dispose(),this._value=null},t.Add}),define("Tone/signal/Multiply",["Tone/core/Tone","Tone/signal/Signal"],function(t){return t.Multiply=function(t){this.input=this.output=this.context.createGain(),this.input.gain.value=this.defaultArg(t,1)},t.extend(t.Multiply),t.Multiply.prototype.setValue=function(t){this.input.gain.value=t},t.Multiply.prototype.connect=t.Signal.prototype.connect,t.Multiply.prototype.dispose=function(){t.prototype.dispose.call(this)},t.Multiply}),define("Tone/signal/Scale",["Tone/core/Tone","Tone/signal/Add","Tone/signal/Multiply","Tone/signal/Signal"],function(t){return t.Scale=function(e,i,n,o){t.call(this),2==arguments.length&&(n=e,o=i,e=-1,i=1),this._inputMin=e,this._inputMax=i,this._outputMin=n,this._outputMax=o,this._plusInput=new t.Add(0),this._scale=new t.Multiply(1),this._plusOutput=new t.Add(0),this.chain(this.input,this._plusInput,this._scale,this._plusOutput,this.output),this._setScalingParameters()},t.extend(t.Scale),t.Scale.prototype._setScalingParameters=function(){this._plusInput.setValue(-this._inputMin),this._scale.setValue((this._outputMax-this._outputMin)/(this._inputMax-this._inputMin)),this._plusOutput.setValue(this._outputMin)},t.Scale.prototype.setInputMin=function(t){this._inputMin=t,this._setScalingParameters()},t.Scale.prototype.setInputMax=function(t){this._inputMax=t,this._setScalingParameters()},t.Scale.prototype.setOutputMin=function(t){this._outputMin=t,this._setScalingParameters()},t.Scale.prototype.setOutputMax=function(t){this._outputMax=t,this._setScalingParameters()},t.Scale.prototype.connect=t.Signal.prototype.connect,t.Scale.prototype.dispose=function(){t.prototype.dispose.call(this),this._plusInput.dispose(),this._plusOutput.dispose(),this._scale.dispose(),this._plusInput=null,this._plusOutput=null,this._scale=null},t.Scale}),define("Tone/component/DryWet",["Tone/core/Tone","Tone/signal/Signal","Tone/signal/Scale"],function(t){return t.DryWet=function(e){t.call(this),this.dry=this.input,this.wet=this.context.createGain(),this.wetness=new t.Signal,this._invert=new t.Scale(0,1,1,0),this.dry.connect(this.output),this.wet.connect(this.output),this.chain(this.wetness,this.wet.gain),this.chain(this.wetness,this._invert,this.dry.gain),this.setDry(this.defaultArg(e,0))},t.extend(t.DryWet),t.DryWet.prototype.setDry=function(t,e){this.setWet(1-t,e)},t.DryWet.prototype.setWet=function(t,e){e?this.wetness.linearRampToValueNow(t,e):this.wetness.setValue(t)},t.DryWet.prototype.dispose=function(){t.prototype.dispose.call(this),this.dry.disconnect(),this.wet.disconnect(),this.wetness.dispose(),this._invert.dispose(),this.dry=null,this.wet=null,this.wetness=null,this._invert=null},t.DryWet}),define("Tone/component/Filter",["Tone/core/Tone","Tone/signal/Signal"],function(t){return t.Filter=function(){t.call(this);var e=this.optionsObject(arguments,["frequency","type","rolloff"],t.Filter.defaults);this._filters=[],this.frequency=new t.Signal(e.frequency),this.detune=new t.Signal(0),this.gain=new t.Signal(e.gain),this.Q=new t.Signal(e.Q),this._type=e.type,this.setRolloff(e.rolloff)},t.extend(t.Filter),t.Filter.defaults={type:"lowpass",frequency:350,rolloff:-12,Q:1,gain:0},t.Filter.prototype.set=function(t){this.isUndef(t.type)||this.setType(t.type),this.isUndef(t.detune)||this.detune.setValue(t.detune),this.isUndef(t.frequency)||this.frequency.setValue(t.frequency),this.isUndef(t.Q)||this.Q.setValue(t.Q),this.isUndef(t.gain)||this.gain.setValue(t.gain),this.isUndef(t.rolloff)||this.setRolloff(t.rolloff)},t.Filter.prototype.setType=function(t){this._type=t;for(var e=0;en;n++){var o=this.context.createBiquadFilter();o.type=this._type,this.frequency.connect(o.frequency),this.detune.connect(o.detune),this.Q.connect(o.Q),this.gain.connect(o.gain),this._filters[n]=o}var s=[this.input].concat(this._filters).concat([this.output]);this.chain.apply(this,s)},t.Filter.prototype.dispose=function(){t.prototype.dispose.call(this);for(var e=0;en;n++){var o=n/e*2-1;i[n]=o>=0?Math.pow(o,t):o}this._expScaler.curve=i},t.ScaleExp.prototype.setInputMin=function(t){this._inputMin=t,this._setScalingParameters()},t.ScaleExp.prototype.setInputMax=function(t){this._inputMax=t,this._setScalingParameters()},t.ScaleExp.prototype.setOutputMin=function(t){this._outputMin=t,this._setScalingParameters()},t.ScaleExp.prototype.setOutputMax=function(t){this._outputMax=t,this._setScalingParameters()},t.ScaleExp.prototype.connect=t.Signal.prototype.connect,t.ScaleExp.prototype.dispose=function(){t.prototype.dispose.call(this),this._plusInput.dispose(),this._plusOutput.dispose(),this._normalize.dispose(),this._scale.dispose(),this._expScaler.disconnect(),this._plusInput=null,this._plusOutput=null,this._scale=null,this._normalize=null,this._expScaler=null},t.ScaleExp}),define("Tone/component/FeedbackCombFilter",["Tone/core/Tone","Tone/signal/ScaleExp","Tone/signal/Signal"],function(t){return t.FeedbackCombFilter=function(e){t.call(this),e=this.defaultArg(e,.01);var i=Math.ceil(this.bufferSize/(e*this.context.sampleRate));i=Math.min(i,10),i=Math.max(i,1),this._delayCount=i,this._delays=new Array(this._delayCount),this._delayTime=new t.Signal(1),this.resonance=new t.Signal(.5),this._resScale=new t.ScaleExp(0,1,.01,1/this._delayCount-.001,.5),this._highFrequencies=!1,this._feedback=this.context.createGain();for(var n=0;nn){this._highFrequencies=!0;for(var s=Math.round(n/o*this._delayCount),r=0;s>r;r++)this._delays[r].delayTime.setValueAtTime(1/i,e);t=Math.floor(n)/i}else if(this._highFrequencies){this._highFrequencies=!1;for(var a=0;ao;o++){var s,r=o/(i-1)*2-1;s=e>r?0:1,n[o]=s}t.curve=n},t.Threshold.prototype.setThreshold=function(t){this._setThresh(this._thresh,t)},t.Threshold.prototype.connect=t.Signal.prototype.connect,t.Threshold.prototype.dispose=function(){t.prototype.dispose.call(this),this._thresh.disconnect(),this._doubleThresh.disconnect(),this._thresh=null,this._doubleThresh=null},t.Threshold}),define("Tone/signal/EqualZero",["Tone/core/Tone","Tone/signal/Threshold","Tone/signal/Signal"],function(t){return t.EqualZero=function(){this._equals=this.context.createWaveShaper(),this._thresh=new t.Threshold(1),this.input=this._equals,this._equals.connect(this._thresh),this.output=this._thresh,this._setEquals()},t.extend(t.EqualZero),t.EqualZero.prototype._setEquals=function(){for(var t=1023,e=new Float32Array(t),i=0;t>i;i++){var n=i/(t-1)*2-1;e[i]=0===n?1:0}this._equals.curve=e},t.EqualZero.prototype.connect=t.Signal.prototype.connect,t.EqualZero.prototype.dispose=function(){t.prototype.dispose.call(this),this._equals.disconnect(),this._thresh.dispose(),this._equals=null,this._thresh=null},t.EqualZero}),define("Tone/signal/Equal",["Tone/core/Tone","Tone/signal/EqualZero","Tone/signal/Add","Tone/signal/Signal"],function(t){return t.Equal=function(e){this._adder=new t.Add(-e),this._equals=new t.EqualZero,this.input=this._adder,this.output=this._equals,this._adder.connect(this._equals)},t.extend(t.Equal),t.Equal.prototype.setValue=function(t){this._adder.setValue(-t)},t.Equal.prototype.connect=t.Signal.prototype.connect,t.Equal.prototype.dispose=function(){t.prototype.dispose.call(this),this._equals.disconnect(),this._adder.dispose(),this._equals=null,this._adder=null},t.Equal}),define("Tone/signal/Select",["Tone/core/Tone","Tone/signal/Equal","Tone/signal/Signal"],function(t){t.Select=function(i){i=this.defaultArg(i,2),this.input=new Array(i),this.output=this.context.createGain(),this.gate=new t.Signal(0);for(var n=0;i>n;n++){var o=new e(n);this.input[n]=o,this.gate.connect(o.selecter),o.connect(this.output)}},t.extend(t.Select),t.Select.prototype.select=function(t,e){t=Math.floor(t),this.gate.setValueAtTime(t,this.toSeconds(e))},t.Select.prototype.connect=t.Signal.prototype.connect,t.Select.prototype.dispose=function(){this.gate.dispose();for(var e=0;eo;o++){var s,r=o/(i-1)*2-1;s=0>=r?t:e,n[o]=s}this._frequencyValues.curve=n},t.Follower.prototype.setAttack=function(t){this._attack=this.secondsToFrequency(t),this._setAttackRelease(this._attack,this._release)},t.Follower.prototype.setRelease=function(t){this._release=this.secondsToFrequency(t),this._setAttackRelease(this._attack,this._release)},t.Follower.prototype.set=function(e){this.isUndef(e.attack)||this.setAttack(e.attack),this.isUndef(e.release)||this.setRelease(e.release),t.Effect.prototype.set.call(this,e)},t.Follower.prototype.connect=t.Signal.prototype.connect,t.Follower.prototype.dispose=function(){t.prototype.dispose.call(this),this._filter.disconnect(),this._frequencyValues.disconnect(),this._delay.disconnect(),this._difference.disconnect(),this._abs.dispose(),this._negate.dispose(),this._mult.dispose(),this._filter=null,this._delay=null,this._frequencyValues=null,this._abs=null,this._negate=null,this._difference=null,this._mult=null},t.Follower}),define("Tone/signal/GreaterThan",["Tone/core/Tone","Tone/signal/LessThan","Tone/signal/Negate","Tone/signal/Signal"],function(t){return t.GreaterThan=function(e){this._lt=new t.LessThan(-e),this._neg=new t.Negate,this.input=this._neg,this.output=this._lt,this._neg.connect(this._lt)},t.extend(t.GreaterThan),t.GreaterThan.prototype.setValue=function(t){this._lt.setValue(-t)},t.GreaterThan.prototype.connect=t.Signal.prototype.connect,t.GreaterThan.prototype.dispose=function(){t.prototype.dispose.call(this),this._lt.disconnect(),this._neg.disconnect(),this._lt=null,this._neg=null},t.GreaterThan}),define("Tone/component/Gate",["Tone/core/Tone","Tone/component/Follower","Tone/signal/GreaterThan"],function(t){return t.Gate=function(e,i,n){t.call(this),e=this.defaultArg(e,-40),i=this.defaultArg(i,.1),n=this.defaultArg(n,.2),this._follower=new t.Follower(i,n),this._gt=new t.GreaterThan(this.dbToGain(e)),this.chain(this.input,this.output),this.chain(this.input,this._gt,this._follower,this.output.gain)},t.extend(t.Gate),t.Gate.prototype.setThreshold=function(t){this._gt.setValue(this.dbToGain(t))},t.Gate.prototype.setAttack=function(t){this._follower.setAttack(t)},t.Gate.prototype.setRelease=function(t){this._follower.setRelease(t)},t.Gate.prototype.dispose=function(){t.prototype.dispose.call(this),this._follower.dispose(),this._gt.dispose(),this._follower=null,this._gt=null},t.Gate}),define("Tone/core/Clock",["Tone/core/Tone","Tone/signal/Signal"],function(t){return t.Clock=function(e,i){this._oscillator=null,this._jsNode=this.context.createScriptProcessor(this.bufferSize,1,1),this._jsNode.onaudioprocess=this._processBuffer.bind(this),this._controlSignal=new t.Signal(1),this._upTick=!1,this.tick=this.defaultArg(i,function(){}),this._jsNode.noGC(),this.setRate(e)},t.extend(t.Clock),t.Clock.prototype.setRate=function(t,e){var i=this.secondsToFrequency(this.toSeconds(t));e?this._controlSignal.exponentialRampToValueNow(i,e):(this._controlSignal.cancelScheduledValues(0),this._controlSignal.setValue(i))},t.Clock.prototype.getRate=function(){return this._controlSignal.getValue()},t.Clock.prototype.start=function(t){this._oscillator=this.context.createOscillator(),this._oscillator.type="square",this._oscillator.connect(this._jsNode),this._controlSignal.connect(this._oscillator.frequency),this._upTick=!1;var e=this.toSeconds(t);this._oscillator.start(e),this._oscillator.onended=function(){}},t.Clock.prototype.stop=function(t,e){var i=this.toSeconds(t);this._oscillator.onended=e,this._oscillator.stop(i)},t.Clock.prototype._processBuffer=function(t){for(var e=this.defaultArg(t.playbackTime,this.now()),i=this._jsNode.bufferSize,n=t.inputBuffer.getChannelData(0),o=this._upTick,s=this,r=0;i>r;r++){var a=n[r];a>0&&!o?(o=!0,setTimeout(function(){var t=e+s.samplesToSeconds(r+2*i);return function(){s.tick(t)}}(),0)):0>a&&o&&(o=!1)}this._upTick=o },t.Clock.prototype.dispose=function(){this._jsNode.disconnect(),this._controlSignal.dispose(),this._oscillator&&(this._oscillator.onended(),this._oscillator.disconnect()),this._jsNode.onaudioprocess=function(){},this._jsNode=null,this._controlSignal=null,this._oscillator=null},t.Clock}),define("Tone/core/Transport",["Tone/core/Tone","Tone/core/Clock","Tone/signal/Signal"],function(Tone){Tone.Transport=function(){this._clock=new Tone.Clock(1,this._processTick.bind(this)),this.loop=!1,this.state=TransportState.STOPPED},Tone.extend(Tone.Transport);var timelineTicks=0,transportTicks=0,tatum=12,transportTimeSignature=4,loopStart=0,loopEnd=4*tatum,intervals=[],timeouts=[],transportTimeline=[],timelineProgress=0,SyncedSources=[],TransportState={STARTED:"started",PAUSED:"paused",STOPPED:"stopped"};Tone.Transport.prototype._processTick=function(t){this.state===TransportState.STARTED&&(processIntervals(t),processTimeouts(t),processTimeline(t),transportTicks+=1,timelineTicks+=1,this.loop&&timelineTicks===loopEnd&&this._setTicks(loopStart))},Tone.Transport.prototype._setTicks=function(t){timelineTicks=t;for(var e=0;e=t){timelineProgress=e;break}}};var processIntervals=function(t){for(var e=0,i=intervals.length;i>e;e++){var n=intervals[e];n.testInterval(transportTicks)&&n.doCallback(t)}},processTimeouts=function(t){for(var e=0,i=0,n=timeouts.length;n>i;i++){var o=timeouts[i],s=o.callbackTick();if(transportTicks>=s)o.doCallback(t),e++;else if(s>transportTicks)break}timeouts.splice(0,e)},processTimeline=function(t){for(var e=timelineProgress,i=transportTimeline.length;i>e;e++){var n=transportTimeline[e],o=n.callbackTick();if(o===timelineTicks)timelineProgress=e,n.doCallback(t);else if(o>timelineTicks)break}};Tone.Transport.prototype.setInterval=function(t,e,i){var n=this.toTicks(e),o=new TimelineEvent(t,i,n,transportTicks);return intervals.push(o),o.id},Tone.Transport.prototype.clearInterval=function(t){for(var e=0;es;s++){var a=timeouts[s];if(a.callbackTick()>o.callbackTick())return timeouts.splice(s,0,o),o.id}return timeouts.push(o),o.id},Tone.Transport.prototype.clearTimeout=function(t){for(var e=0;es;s++){var a=transportTimeline[s];if(a.callbackTick()>o.callbackTick())return transportTimeline.splice(s,0,o),o.id}return transportTimeline.push(o),o.id},Tone.Transport.prototype.clearTimeline=function(t){for(var e=0;e1){for(var oringalTime=time,i=0;ir;++r){var a,c=2/(r*Math.PI);switch(t){case"sine":a=1===r?1:0;break;case"square":a=1&r?2*c:0;break;case"sawtooth":a=c*(1&r?1:-1);break;case"triangle":a=1&r?2*c*c*(r-1>>1&1?-1:1):0;break;default:throw new TypeError("invalid oscillator type: "+t)}0!==a?(n[r]=-a*Math.sin(s),o[r]=a*Math.cos(s)):(n[r]=0,o[r]=0)}var l=this.context.createPeriodicWave(n,o);this._wave=l,this.oscillator.setPeriodicWave(this._wave),this._type=t},t.Oscillator.prototype.getType=function(){return this._type},t.Oscillator.prototype.setPhase=function(t){this._phase=t*Math.PI/180,this.setType(this._type)},t.Oscillator.prototype.set=function(t){this.isUndef(t.type)||this.setType(t.type),this.isUndef(t.phase)||this.setPhase(t.phase),this.isUndef(t.frequency)||this.frequency.setValue(t.frequency),this.isUndef(t.onended)||(this.onended=t.onended),this.isUndef(t.detune)||this.detune.setValue(t.detune)},t.Oscillator.prototype._onended=function(){this.state=t.Source.State.STOPPED,this.onended()},t.Oscillator.prototype.dispose=function(){t.Source.prototype.dispose.call(this),this.stop(),null!==this.oscillator&&(this.oscillator.disconnect(),this.oscillator=null),this.frequency.dispose(),this.detune.dispose(),this._wave=null,this.detune=null,this.frequency=null},t.Oscillator}),define("Tone/component/LFO",["Tone/core/Tone","Tone/source/Oscillator","Tone/signal/Scale","Tone/signal/Signal"],function(t){return t.LFO=function(e,i,n){this.oscillator=new t.Oscillator(this.defaultArg(e,1),"sine"),this.frequency=this.oscillator.frequency,this._scaler=new t.Scale(this.defaultArg(i,0),this.defaultArg(n,1)),this.output=this._scaler,this.chain(this.oscillator,this.output)},t.extend(t.LFO),t.LFO.prototype.start=function(t){this.oscillator.start(t)},t.LFO.prototype.stop=function(t){this.oscillator.stop(t)},t.LFO.prototype.sync=function(e){t.Transport.syncSource(this.oscillator,e),t.Transport.syncSignal(this.oscillator.frequency)},t.LFO.prototype.unsync=function(){t.Transport.unsyncSource(this.oscillator),t.Transport.unsyncSignal(this.oscillator.frequency)},t.LFO.prototype.setFrequency=function(t){this.oscillator.setFrequency(t)},t.LFO.prototype.setPhase=function(t){this.oscillator.setPhase(t)},t.LFO.prototype.setMin=function(t){this._scaler.setOutputMin(t)},t.LFO.prototype.setMax=function(t){this._scaler.setOutputMax(t)},t.LFO.prototype.setType=function(t){this.oscillator.setType(t)},t.LFO.prototype.set=function(t){this.isUndef(t.frequency)||this.setFrequency(t.frequency),this.isUndef(t.type)||this.setType(t.type),this.isUndef(t.min)||this.setMin(t.min),this.isUndef(t.max)||this.setMax(t.max)},t.LFO.prototype.connect=t.Signal.prototype.connect,t.LFO.prototype.dispose=function(){t.prototype.dispose.call(this),this.oscillator.dispose(),this._scaler.dispose(),this._scaler=null,this.oscillator=null,this.frequency=null},t.LFO}),define("Tone/component/LowpassCombFilter",["Tone/core/Tone","Tone/signal/ScaleExp","Tone/signal/Signal"],function(t){t.LowpassCombFilter=function(i){t.call(this),i=this.defaultArg(i,.01);var n=Math.ceil(this.bufferSize/(i*this.context.sampleRate));n=Math.min(n,10),n=Math.max(n,1),this._filterDelayCount=n,this._filterDelays=new Array(this._filterDelayCount),this._delayTime=new t.Signal(1),this.dampening=new t.Signal(3e3),this.resonance=new t.Signal(.5),this._resScale=new t.ScaleExp(0,1,.01,1/this._filterDelayCount-.001,.5),this._highFrequencies=!1,this._feedback=this.context.createGain();for(var o=0;on){this._highFrequencies=!0;for(var s=Math.round(n/o*this._filterDelayCount),r=0;s>r;r++)this._filterDelays[r].setDelay(1/i,e);t=Math.floor(n)/i}else if(this._highFrequencies){this._highFrequencies=!1;for(var a=0;al;l++)o=s[l],!c&&o>.95&&(c=!0,this._lastClip=Date.now()),a+=o,r+=o*o;var h=a/e,u=Math.sqrt(r/e);this._volume[n]=Math.max(u,this._volume[n]*i),this._values[n]=h}},t.Meter.prototype.getLevel=function(t){t=this.defaultArg(t,0);var e=this._volume[t];return 1e-5>e?0:e},t.Meter.prototype.getValue=function(t){return t=this.defaultArg(t,0),this._values[t]},t.Meter.prototype.getDb=function(t){return this.gainToDb(this.getLevel(t))},t.Meter.prototype.isClipped=function(){return Date.now()-this._lastClipthis._recordEndSample?(this.state=e.STOPPED,this._callback(this._recordBuffers)):s>this._recordStartSample?(i=0,n=Math.min(this._recordEndSample-s,r),this._recordChannels(t.inputBuffer,i,n,r)):a>this._recordStartSample&&(n=a-this._recordStartSample,i=r-n,this._recordChannels(t.inputBuffer,i,n,r))}},t.Recorder.prototype._recordChannels=function(t,e,i,n){for(var o=this._recordBufferOffset,s=this._recordBuffers,r=0;rc;c++){var l=c-e;s[r][l+o]=a[c]}}this._recordBufferOffset+=i},t.Recorder.prototype.record=function(t,i,n){if(this.state===e.STOPPED){this.clear(),this._recordBufferOffset=0,i=this.defaultArg(i,0),this._recordDuration=this.toSamples(t),this._recordStartSample=this.toSamples("+"+i),this._recordEndSample=this._recordStartSample+this._recordDuration;for(var o=0;os;s++){var a=o[s];Array.isArray(n)?a.apply(window,[e].concat(n)):a(e,n)}}t.Note=function(e,i,n){this.value=n,this._channel=e,this._timelineID=t.Transport.setTimeline(this._trigger.bind(this),i)},t.Note.prototype._trigger=function(t){e(this._channel,t,this.value)},t.Note.prototype.dispose=function(){t.Tranport.clearTimeline(this._timelineID),this.value=null};var i={};t.Note.route=function(t,e){i.hasOwnProperty(t)?i[t].push(e):i[t]=[e]},t.Note.unroute=function(t,e){if(i.hasOwnProperty(t)){var n=i[t],o=n.indexOf(e);-1!==o&&i[t].splice(o,1)}},t.Note.parseScore=function(e){var i=[];for(var n in e){var o=e[n];if("tempo"===n)t.Transport.setBpm(o);else if("timeSignature"===n)t.Transport.setTimeSignature(o[0],o[1]);else{if(!Array.isArray(o))throw new TypeError("score parts must be Arrays");for(var s=0;s=0;o--){var s=new e(i,Math.pow(2,o));this._modChain.push(s)}this.chain.apply(this,this._modChain),this.input.connect(this._modChain[0]),this._modChain[this._modChain.length-1].connect(this.output)},t.extend(t.Modulo),t.Modulo.prototype.dispose=function(){t.prototype.dispose.call(this);for(var e=0;eo;o++){var s=this.context.createBiquadFilter();s.type="allpass",s.Q.value=i,e.connect(s.frequency),n[o]=s}return this.chain.apply(this,n),n},t.Phaser.prototype.setDepth=function(t){this._depth=t;var e=this._baseFrequency+this._baseFrequency*t;this._lfoL.setMax(e),this._lfoR.setMax(e)},t.Phaser.prototype.setBaseFrequency=function(t){this._baseFrequency=t,this._lfoL.setMin(t),this._lfoR.setMin(t),this.setDepth(this._depth)},t.Phaser.prototype.setRate=function(t){this._lfoL.setFrequency(t)},t.Phaser.prototype.set=function(e){this.isUndef(e.rate)||this.setRate(e.rate),this.isUndef(e.baseFrequency)||this.setBaseFrequency(e.baseFrequency),this.isUndef(e.depth)||this.setDepth(e.depth),t.StereoFeedbackEffect.prototype.set.call(this,e)},t.Phaser.prototype.dispose=function(){t.StereoFeedbackEffect.prototype.dispose.call(this),this._lfoL.dispose(),this._lfoR.dispose();for(var e=0;e0){var i=this.frequency.getValue();this.frequency.setValueAtTime(i,e),this.frequency.exponentialRampToValueAtTime(t,e+this.portamento)}else this.frequency.setValueAtTime(t,e)},t.Monophonic.prototype.setPortamento=function(t){this.portamento=this.toSeconds(t)},t.Monophonic.prototype.set=function(t){this.isUndef(t.volume)||this.setVolume(t.volume),this.isUndef(t.portamento)||this.setPortamento(t.portamento)},t.Monophonic.prototype.setPreset=function(t){!this.isUndef(this.preset)&&this.preset.hasOwnProperty(t)&&this.set(this.preset[t])},t.Monophonic.prototype.dispose=function(){t.Instrument.prototype.dispose.call(this)},t.Monophonic}),define("Tone/instrument/MonoSynth",["Tone/core/Tone","Tone/component/Envelope","Tone/source/Oscillator","Tone/signal/Signal","Tone/component/Filter","Tone/signal/Add","Tone/instrument/Monophonic"],function(t){return t.MonoSynth=function(e){e=this.defaultArg(e,t.MonoSynth.defaults),t.Monophonic.call(this,e),this.oscillator=new t.Oscillator(0,e.oscType),this.frequency=this.oscillator.frequency,this.detune=this.oscillator.detune,this.filter=new t.Filter(e.filter),this.filterEnvelope=new t.Envelope(e.filterEnvelope),this.envelope=new t.Envelope(e.envelope),this._amplitude=this.context.createGain(),this.oscillator.connect(this.filter),this.filter.connect(this._amplitude),this.oscillator.start(),this.filterEnvelope.connect(this.filter.frequency),this.envelope.connect(this._amplitude.gain),this._amplitude.connect(this.output)},t.extend(t.MonoSynth,t.Monophonic),t.MonoSynth.defaults={oscType:"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}},t.MonoSynth.prototype.triggerEnvelopeAttack=function(t,e){this.envelope.triggerAttack(t,e),this.filterEnvelope.triggerAttack(t)},t.MonoSynth.prototype.triggerEnvelopeRelease=function(t){this.envelope.triggerRelease(t),this.filterEnvelope.triggerRelease(t)},t.MonoSynth.prototype.setOscType=function(t){this.oscillator.setType(t)},t.MonoSynth.prototype.set=function(e){this.isUndef(e.detune)||this.detune.setValue(e.detune),this.isUndef(e.oscType)||this.setOscType(e.oscType),this.isUndef(e.filterEnvelope)||this.filterEnvelope.set(e.filterEnvelope),this.isUndef(e.envelope)||this.envelope.set(e.envelope),this.isUndef(e.filter)||this.filter.set(e.filter),t.Monophonic.prototype.set.call(this,e)},t.MonoSynth.prototype.dispose=function(){t.Monophonic.prototype.dispose.call(this),this.oscillator.dispose(),this.envelope.dispose(),this.filterEnvelope.dispose(),this.filter.dispose(),this._amplitude.disconnect(),this.oscillator=null,this.filterEnvelope=null,this.envelope=null,this.filter=null,this.detune=null,this._amplitude=null,this.frequency=null,this.detune=null},t.MonoSynth}),define("Tone/instrument/DuoSynth",["Tone/core/Tone","Tone/instrument/MonoSynth","Tone/component/LFO","Tone/signal/Signal","Tone/signal/Multiply","Tone/instrument/Monophonic"],function(t){return t.DuoSynth=function(e){e=this.defaultArg(e,t.DuoSynth.defaults),t.Monophonic.call(this,e),this.voice0=new t.MonoSynth(e.voice0),this.voice0.setVolume(-10),this.voice1=new t.MonoSynth(e.voice1),this.voice1.setVolume(-10),this._vibrato=new t.LFO(e.vibratoRate,-50,50),this._vibrato.start(),this._vibratoGain=this.context.createGain(),this._vibratoGain.gain.value=e.vibratoAmount,this._vibratoDelay=this.toSeconds(e.vibratoDelay),this._vibratoAmount=e.vibratoAmount,this.frequency=new t.Signal(440),this._harmonicity=new t.Multiply(e.harmonicity),this.frequency.connect(this.voice0.frequency),this.chain(this.frequency,this._harmonicity,this.voice1.frequency),this._vibrato.connect(this._vibratoGain),this.fan(this._vibratoGain,this.voice0.detune,this.voice1.detune),this.voice0.connect(this.output),this.voice1.connect(this.output)},t.extend(t.DuoSynth,t.Monophonic),t.DuoSynth.defaults={vibratoAmount:.5,vibratoRate:5,vibratoDelay:1,harmonicity:1.5,voice0:{volume:-10,portamento:0,oscType:"sine",filterEnvelope:{attack:.01,decay:0,sustain:1,release:.5},envelope:{attack:.01,decay:0,sustain:1,release:.5}},voice1:{volume:-10,portamento:0,oscType:"sine",filterEnvelope:{attack:.01,decay:0,sustain:1,release:.5},envelope:{attack:.01,decay:0,sustain:1,release:.5}}},t.DuoSynth.prototype.triggerEnvelopeAttack=function(t,e){t=this.toSeconds(t),this.voice0.envelope.triggerAttack(t,e),this.voice1.envelope.triggerAttack(t,e),this.voice0.filterEnvelope.triggerAttack(t),this.voice1.filterEnvelope.triggerAttack(t)},t.DuoSynth.prototype.triggerEnvelopeRelease=function(t){this.voice0.triggerRelease(t),this.voice1.triggerRelease(t)},t.DuoSynth.prototype.setHarmonicity=function(t){this._harmonicity.setValue(t)},t.DuoSynth.prototype.setPortamento=function(t){this.portamento=this.toSeconds(t)},t.DuoSynth.prototype.setVibratoDelay=function(t){this._vibratoDelay=this.toSeconds(t)},t.DuoSynth.prototype.setVibratoAmount=function(t){this._vibratoAmount=t,this._vibratoGain.gain.setValueAtTime(t,this.now())},t.DuoSynth.prototype.setVibratoRate=function(t){this._vibrato.setFrequency(t)},t.DuoSynth.prototype.setVolume=t.Source.prototype.setVolume,t.DuoSynth.prototype.set=function(e){this.isUndef(e.harmonicity)||this.setHarmonicity(e.harmonicity),this.isUndef(e.vibratoRate)||this.setVibratoRate(e.vibratoRate),this.isUndef(e.vibratoAmount)||this.setVibratoAmount(e.vibratoAmount),this.isUndef(e.vibratoDelay)||this.setVibratoDelay(e.vibratoDelay),this.isUndef(e.voice0)||this.voice0.set(e.voice0),this.isUndef(e.voice1)||this.voice1.set(e.voice1),t.Monophonic.prototype.set.call(this,e)},t.DuoSynth.prototype.dispose=function(){t.Monophonic.prototype.dispose.call(this),this.voice0.dispose(),this.voice1.dispose(),this.frequency.dispose(),this._vibrato.dispose(),this._vibratoGain.disconnect(),this._harmonicity.dispose(),this.voice0=null,this.voice1=null,this.frequency=null,this._vibrato=null,this._vibratoGain=null,this._harmonicity=null},t.DuoSynth}),define("Tone/instrument/FMSynth",["Tone/core/Tone","Tone/instrument/MonoSynth","Tone/signal/Signal","Tone/signal/Multiply","Tone/instrument/Monophonic"],function(t){return t.FMSynth=function(e){e=this.defaultArg(e,t.FMSynth.defaults),t.Monophonic.call(this,e),this.carrier=new t.MonoSynth(e.carrier),this.carrier.setVolume(-10),this.modulator=new t.MonoSynth(e.modulator),this.modulator.setVolume(-10),this.frequency=new t.Signal(440),this._harmonicity=new t.Multiply(e.harmonicity),this._modulationIndex=new t.Multiply(e.modulationIndex),this._modulationNode=this.context.createGain(),this.frequency.connect(this.carrier.frequency),this.chain(this.frequency,this._harmonicity,this.modulator.frequency),this.chain(this.frequency,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)},t.extend(t.FMSynth,t.Monophonic),t.FMSynth.defaults={harmonicity:3,modulationIndex:10,carrier:{volume:-10,portamento:0,oscType:"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,oscType:"triangle",envelope:{attack:.01,decay:0,sustain:1,release:.5},filterEnvelope:{attack:.01,decay:0,sustain:1,release:.5,min:2e4,max:2e4}}},t.FMSynth.prototype.triggerEnvelopeAttack=function(t,e){t=this.toSeconds(t),this.carrier.envelope.triggerAttack(t,e),this.modulator.envelope.triggerAttack(t),this.carrier.filterEnvelope.triggerAttack(t),this.modulator.filterEnvelope.triggerAttack(t)},t.FMSynth.prototype.triggerEnvelopeRelease=function(t){this.carrier.triggerRelease(t),this.modulator.triggerRelease(t)},t.FMSynth.prototype.setHarmonicity=function(t){this._harmonicity.setValue(t)},t.FMSynth.prototype.setModulationIndex=function(t){this._modulationIndex.setValue(t)},t.FMSynth.prototype.set=function(e){this.isUndef(e.harmonicity)||this.setHarmonicity(e.harmonicity),this.isUndef(e.modulationIndex)||this.setModulationIndex(e.modulationIndex),this.isUndef(e.carrier)||this.carrier.set(e.carrier),this.isUndef(e.modulator)||this.modulator.set(e.modulator),t.Monophonic.prototype.set.call(this,e)},t.FMSynth.prototype.dispose=function(){t.Monophonic.prototype.dispose.call(this),this.carrier.dispose(),this.modulator.dispose(),this.frequency.dispose(),this._modulationIndex.dispose(),this._harmonicity.dispose(),this._modulationNode.disconnect(),this.carrier=null,this.modulator=null,this.frequency=null,this._modulationIndex=null,this._harmonicity=null,this._modulationNode=null},t.FMSynth}),define("Tone/source/Player",["Tone/core/Tone","Tone/source/Source"],function(t){return t.Player=function(e,i){t.Source.call(this),this._source=null,this._buffer=null,this.duration=0,this.loop=!1,this.loopStart=0,this.loopEnd=0,this._playbackRate=1,this.retrigger=!1,this.onended=function(){},e&&this.load(e,i)},t.extend(t.Player,t.Source),t.Player.prototype.load=function(t,e){if(this._buffer)e&&e(this);else{var i=new XMLHttpRequest;i.open("GET",t,!0),i.responseType="arraybuffer";var n=this;i.onload=function(){n.context.decodeAudioData(i.response,function(t){n.setBuffer(t),e&&e(n)})},i.send()}},t.Player.prototype.setBuffer=function(t){this._buffer=t,this.duration=t.duration},t.Player.prototype.start=function(e,i,n){(this.state===t.Source.State.STOPPED||this.retrigger)&&this._buffer&&(this.state=t.Source.State.STARTED,i=this.defaultArg(i,0),this.loop&&(i=this.loopStart),n=this.defaultArg(n,this._buffer.duration-i),this._source=this.context.createBufferSource(),this._source.buffer=this._buffer,this._source.loop=this.loop,this._source.loopStart=this.loopStart,this._source.loopEnd=this.loopEnd,this._source.playbackRate.value=this._playbackRate,this._source.onended=this._onended.bind(this),this.chain(this._source,this.output),this._source.start(this.toSeconds(e),this.toSeconds(i),this.toSeconds(n)))},t.Player.prototype.stop=function(e){this.state===t.Source.State.STARTED&&this._buffer&&this._source&&(e||(this.state=t.Source.State.STOPPED),this._source.stop(this.toSeconds(e)))},t.Player.prototype.setPlaybackRate=function(t,e){this._playbackRate=t,this._source&&(e?this._source.playbackRate.exponentialRampToValueAtTime(t,this.toSeconds(e)):this._source.playbackRate.value=e)},t.Player.prototype._onended=function(){this.state=t.Source.State.STOPPED,this.onended()},t.Player.prototype.dispose=function(){t.Source.prototype.dispose.call(this),null!==this._source&&(this._source.disconnect(),this._source=null),this._buffer=null},t.Player}),define("Tone/instrument/Sampler",["Tone/core/Tone","Tone/source/Player","Tone/component/AmplitudeEnvelope","Tone/component/Filter","Tone/instrument/Instrument"],function(t){return t.Sampler=function(){t.Instrument.call(this);var e=this.optionsObject(arguments,["url","load"],t.Sampler.defaults);this.player=new t.Player(e.url,e.load),this.player.retrigger=!0,this.envelope=new t.AmplitudeEnvelope(e.envelope),this.filterEnvelope=new t.Envelope(e.filterEnvelope),this.filter=new t.Filter(e.filter),this.chain(this.player,this.filter,this.envelope,this.output),this.filterEnvelope.connect(this.filter.frequency)},t.extend(t.Sampler,t.Instrument),t.Sampler.defaults={url:null,load:function(){},envelope:{attack:.001,decay:0,sustain:1,release:.1},filterEnvelope:{attack:.001,decay:.001,sustain:1,release:.5,min:20,max:2e4},filter:{type:"lowpass"}},t.Sampler.prototype.set=function(t){this.isUndef(t.filterEnvelope)||this.filterEnvelope.set(t.filterEnvelope),this.isUndef(t.envelope)||this.envelope.set(t.envelope),this.isUndef(t.filter)||this.filter.set(t.filter)},t.Sampler.prototype.triggerAttack=function(t,e,i){e=this.toSeconds(e),t=this.defaultArg(t,0),this.player.setPlaybackRate(this.intervalToFrequencyRatio(t),e),this.player.start(e),this.envelope.triggerAttack(e,i),this.filterEnvelope.triggerAttack(e)},t.Sampler.prototype.triggerRelease=function(t){t=this.toSeconds(t),this.filterEnvelope.triggerRelease(t),this.envelope.triggerRelease(t)},t.Sampler.prototype.dispose=function(){t.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},t.Sampler}),define("Tone/instrument/MultiSampler",["Tone/core/Tone","Tone/instrument/Sampler","Tone/instrument/Instrument"],function(t){return t.MultiSampler=function(e,i){t.Instrument.call(this),this.samples={},this._createSamples(e,i)},t.extend(t.MultiSampler,t.Instrument),t.MultiSampler.prototype._createSamples=function(e,i){var n={total:0,loaded:0};for(var o in e)"string"==typeof e[o]&&n.total++;var s=function(){n.loaded++,n.loaded===n.total&&i&&i()};for(var r in e){var a=e[r],c=new t.Sampler(a,s);c.connect(this.output),this.samples[r]=c}},t.MultiSampler.prototype.triggerAttack=function(t,e,i){this.samples.hasOwnProperty(t)&&this.samples[t].triggerAttack(0,e,i)},t.MultiSampler.prototype.triggerRelease=function(t,e){this.samples.hasOwnProperty(t)&&this.samples[t].triggerRelease(e)},t.MultiSampler.prototype.triggerAttackRelease=function(t,e,i,n){if(this.samples.hasOwnProperty(t)){i=this.toSeconds(i),e=this.toSeconds(e);var o=this.samples[t];o.triggerAttack(0,i,n),o.triggerRelease(i+e)}},t.MultiSampler.prototype.set=function(t){for(var e in this.samples)this.samples[e].set(t)},t.MultiSampler.prototype.setVolume=t.Source.prototype.setVolume,t.MultiSampler.prototype.dispose=function(){t.Instrument.prototype.dispose.call(this);for(var e in this.samples)this.samples[e].dispose(),this.samples[e]=null;this.samples=null },t.MultiSampler}),define("Tone/source/Noise",["Tone/core/Tone","Tone/source/Source"],function(t){t.Noise=function(e){t.Source.call(this),this._source=null,this._buffer=null,this.onended=function(){},this.setType(this.defaultArg(e,"white"))},t.extend(t.Noise,t.Source),t.Noise.prototype.setType=function(o,s){switch(o){case"white":this._buffer=n;break;case"pink":this._buffer=e;break;case"brown":this._buffer=i;break;default:this._buffer=n}this.state===t.Source.State.STARTED&&(s=this.toSeconds(s),this._source.onended=void 0,this._stop(s),this._start(s))},t.Noise.prototype._start=function(t){this._source=this.context.createBufferSource(),this._source.buffer=this._buffer,this._source.loop=!0,this.chain(this._source,this.output),this._source.start(this.toSeconds(t)),this._source.onended=this._onended.bind(this)},t.Noise.prototype.start=function(e){this.state===t.Source.State.STOPPED&&(this.state=t.Source.State.STARTED,this._start(e))},t.Noise.prototype._stop=function(t){this._source.stop(this.toSeconds(t))},t.Noise.prototype.stop=function(e){this.state===t.Source.State.STARTED&&this._buffer&&this._source&&(e||(this.state=t.Source.State.STOPPED),this._stop(e))},t.Noise.prototype._onended=function(){this.state=t.Source.State.STOPPED,this.onended()},t.Noise.prototype.dispose=function(){t.Source.prototype.dispose.call(this),null!==this._source&&(this._source.disconnect(),this._source=null),this._buffer=null};var e=null,i=null,n=null;return t._initAudioContext(function(t){var o=t.sampleRate,s=4*o;e=function(){for(var e=t.createBuffer(2,s,o),i=0;if;f++){var d=2*Math.random()-1;n=.99886*n+.0555179*d,r=.99332*r+.0750759*d,a=.969*a+.153852*d,c=.8665*c+.3104856*d,l=.55*l+.5329522*d,h=-.7616*h-.016898*d,p[f]=n+r+a+c+l+h+u+.5362*d,p[f]*=.11,u=.115926*d}}return e}(),i=function(){for(var e=t.createBuffer(2,s,o),i=0;ia;a++){var c=2*Math.random()-1;n[a]=(r+.02*c)/1.02,r=n[a],n[a]*=3.5}return e}(),n=function(){for(var e=t.createBuffer(2,s,o),i=0;ir;r++)n[r]=2*Math.random()-1;return e}()}),t.Noise}),define("Tone/instrument/PluckSynth",["Tone/core/Tone","Tone/instrument/Instrument","Tone/source/Noise","Tone/component/LowpassCombFilter"],function(t){return t.PluckSynth=function(){t.Instrument.call(this),this._noise=new t.Noise("pink"),this.attackNoise=1,this._lfcf=new t.LowpassCombFilter(1/440),this.resonance=this._lfcf.resonance,this.dampening=this._lfcf.dampening,this._noise.connect(this._lfcf),this._lfcf.connect(this.output)},t.extend(t.PluckSynth,t.Instrument),t.PluckSynth.prototype.triggerAttack=function(t,e){"string"==typeof t&&(t=this.noteToFrequency(t)),e=this.toSeconds(e);var i=1/t;this._lfcf.setDelayTime(i,e),this._noise.start(e),this._noise.stop(e+i*this.attackNoise)},t.PluckSynth.prototype.dispose=function(){t.Instrument.prototype.dispose.call(this),this._noise.dispose(),this._lfcf.dispose(),this._noise=null,this._lfcf=null,this.dampening=null,this.resonance=null},t.PluckSynth}),define("Tone/instrument/PolySynth",["Tone/core/Tone","Tone/instrument/MonoSynth","Tone/source/Source"],function(t){return t.PolySynth=function(){t.Instrument.call(this);var e=this.optionsObject(arguments,["polyphony","voice","voiceOptions"],t.PolySynth.defaults);this._voices=new Array(e.polyphony),this._freeVoices=[],this._activeVoices={};for(var i=0;i0){var o=this._freeVoices.shift();o.triggerAttack(t,e,i),this._activeVoices[n]=o}},t.PolySynth.prototype.triggerAttackRelease=function(t,e,i,n){i=this.toSeconds(i),this.triggerAttack(t,i,n),this.triggerRelease(t,i+this.toSeconds(e))},t.PolySynth.prototype.triggerRelease=function(t,e){var i=JSON.stringify(t),n=this._activeVoices[i];n&&(n.triggerRelease(e),this._freeVoices.push(n),this._activeVoices[i]=null)},t.PolySynth.prototype.set=function(t){for(var e=0;ei){var n=e;e=i,i=n}this._min=new t.Min(i),this._max=new t.Max(e),this.chain(this.input,this._min,this._max,this.output)},t.extend(t.Clip),t.Clip.prototype.setMin=function(t){this._min.setMin(t)},t.Clip.prototype.setMax=function(t){this._max.setMax(t)},t.Clip.prototype.connect=t.Signal.prototype.connect,t.Clip.prototype.dispose=function(){t.prototype.dispose.call(this),this._min.dispose(),this._max.dispose(),this._min=null,this._max=null},t.Clip}),define("Tone/signal/Route",["Tone/core/Tone","Tone/signal/Equal","Tone/signal/Signal"],function(t){t.Route=function(i){i=this.defaultArg(i,2),this.output=new Array(i),this.input=this.context.createGain(),this.gate=new t.Signal(0);for(var n=0;i>n;n++){var o=new e(n);this.output[n]=o,this.gate.connect(o.selecter),this.input.connect(o)}},t.extend(t.Route),t.Route.prototype.select=function(t,e){t=Math.floor(t),this.gate.setValueAtTime(t,this.toSeconds(e))},t.Route.prototype.connect=t.Signal.prototype.connect,t.Route.prototype.dispose=function(){this.gate.dispose();for(var e=0;ei;i++)e[i]=-1,e[i+128]=1;return t.PulseOscillator=function(i,n){t.Source.call(this),this.width=new t.Signal(this.defaultArg(n,.5)),this._sawtooth=new t.Oscillator(i,"sawtooth"),this.frequency=this._sawtooth.frequency,this.detune=this._sawtooth.detune,this._thresh=this.context.createWaveShaper(),this._thresh.curve=e,this.chain(this._sawtooth,this._thresh,this.output),this.width.connect(this._thresh)},t.extend(t.PulseOscillator,t.Source),t.PulseOscillator.prototype.setWidth=function(t){this.width.setValue(t)},t.PulseOscillator.prototype.start=function(e){this.state===t.Source.State.STOPPED&&(e=this.toSeconds(e),this._sawtooth.start(e),this.width.output.gain.setValueAtTime(1,e),this.state=t.Source.State.STARTED)},t.PulseOscillator.prototype.stop=function(e){this.state===t.Source.State.STARTED&&(e=this.toSeconds(e),this._sawtooth.stop(e),this.width.output.gain.setValueAtTime(0,e),this.state=t.Source.State.STOPPED)},t.PulseOscillator.prototype.dispose=function(){t.Source.prototype.dispose.call(this),this._sawtooth.dispose(),this.width.dispose(),this._thresh.disconnect(),this._sawtooth=null,this.frequency=null,this.detune=null,this.width=null,this._thresh=null},t.PulseOscillator})