mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-17 09:08:10 +00:00
12 lines
No EOL
105 KiB
JavaScript
12 lines
No EOL
105 KiB
JavaScript
/**
|
|
* 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;e<arguments.length;e++){var i=arguments[e];t.connect(i),t=i}},i.prototype.fan=function(){var t=arguments[0];if(arguments.length>1)for(var e=1;e<arguments.length;e++){var i=arguments[e];t.connect(i)}},i.prototype.defaultArg=function(e,i){if("object"==typeof e&&"object"==typeof i){var n={};for(var o in e)n[o]=this.defaultArg(e[o],e[o]);for(var s in i)n[s]=this.defaultArg(e[s],i[s]);return n}return t(e)?i:e},i.prototype.optionsObject=function(t,e,i){var n={};if(1===t.length&&"object"==typeof t[0])n=t[0];else for(var o=0;o<e.length;o++)n[e[o]]=t[o];return this.isUndef(i)?n:this.defaultArg(n,i)},i.prototype.isUndef=t,i.prototype.equalPowerScale=function(t){var e=.5*Math.PI;return Math.sin(t*e)},i.prototype.logScale=function(t){return Math.max(this.normalize(this.gainToDb(t),-100,0),0)},i.prototype.expScale=function(t){return this.dbToGain(this.interpolate(t,-100,0))},i.prototype.dbToGain=function(t){return Math.pow(2,t/6)},i.prototype.gainToDb=function(t){return 20*(Math.log(t)/Math.LN10)},i.prototype.interpolate=function(t,e,i){return t*(i-e)+e},i.prototype.normalize=function(t,e,i){if(e>i){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;e<o.length;e++)o[e](t)},i.extend=function(e,n){function o(){}t(n)&&(n=i),o.prototype=n.prototype,e.prototype=new o,e.prototype.constructor=e},i.startMobile=function(){var t=i.context.createOscillator(),e=i.context.createGain();e.gain.value=0,t.connect(e),e.connect(i.context.destination);var n=i.context.currentTime;t.start(n),t.stop(n+1)},i._initAudioContext(function(t){n=t.createGain(),n.gain.value=0,n.connect(t.destination)}),console.log("Tone.js r2"),i}),define("Tone/signal/Signal",["Tone/core/Tone"],function(t){t.Signal=function(e){t.call(this),this._scalar=this.context.createGain(),this._syncRatio=1,this.chain(i,this._scalar,this.output),this.input.connect(this.output),this.setValue(this.defaultArg(e,0))},t.extend(t.Signal),t.Signal.prototype.getValue=function(){return this._scalar.gain.value},t.Signal.prototype.setValue=function(t){0===this._syncRatio?t=0:t*=this._syncRatio,this._scalar.gain.value=t},t.Signal.prototype.setValueAtTime=function(t,e){t*=this._syncRatio,this._scalar.gain.setValueAtTime(t,this.toSeconds(e))},t.Signal.prototype.setCurrentValueNow=function(t){t=this.defaultArg(t,this.now());var e=this.getValue();return this.cancelScheduledValues(t),this._scalar.gain.setValueAtTime(e,t),e},t.Signal.prototype.linearRampToValueAtTime=function(t,e){t*=this._syncRatio,this._scalar.gain.linearRampToValueAtTime(t,this.toSeconds(e))},t.Signal.prototype.exponentialRampToValueAtTime=function(t,e){t*=this._syncRatio;try{this._scalar.gain.exponentialRampToValueAtTime(t,this.toSeconds(e))}catch(i){this._scalar.gain.linearRampToValueAtTime(t,this.toSeconds(e))}},t.Signal.prototype.exponentialRampToValueNow=function(t,e){var i=this.now();this.setCurrentValueNow(i),"+"===e.toString().charAt(0)&&(e=e.substr(1)),this.exponentialRampToValueAtTime(t,i+this.toSeconds(e))},t.Signal.prototype.linearRampToValueNow=function(t,e){var i=this.now();this.setCurrentValueNow(i),t*=this._syncRatio,"+"===e.toString().charAt(0)&&(e=e.substr(1)),this._scalar.gain.linearRampToValueAtTime(t,i+this.toSeconds(e))},t.Signal.prototype.setTargetAtTime=function(t,e,i){t*=this._syncRatio,this._scalar.gain.setTargetAtTime(t,this.toSeconds(e),i)},t.Signal.prototype.setValueCurveAtTime=function(t,e,i){for(var n=0;n<t.length;n++)t[n]*=this._syncRatio;this._scalar.gain.setValueCurveAtTime(t,this.toSeconds(e),this.toSeconds(i))},t.Signal.prototype.cancelScheduledValues=function(t){this._scalar.gain.cancelScheduledValues(this.toSeconds(t))},t.Signal.prototype.sync=function(t,e){this._syncRatio=e?e:0!==t.getValue()?this.getValue()/t.getValue():0,this._scalar.disconnect(),this._scalar=this.context.createGain(),this.chain(t,this._scalar,this.output),this._scalar.gain.value=this._syncRatio},t.Signal.prototype.unsync=function(){var t=this.getValue();this._scalar.disconnect(),this._scalar=this.context.createGain(),this._scalar.gain.value=t/this._syncRatio,this._syncRatio=1,this.chain(i,this._scalar,this.output)},t.Signal.prototype.dispose=function(){t.prototype.dispose.call(this),this._scalar.disconnect(),this._scalar=null},t.Signal.prototype.connect=function(e,i,n){e instanceof t.Signal?e.setValue(0):e instanceof AudioParam&&(e.value=0),t.prototype.connect.call(this,e,i,n)};var e=null,i=null;return t._initAudioContext(function(t){e=t.createOscillator(),i=t.createWaveShaper();for(var n=8,o=new Float32Array(n),s=0;n>s;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;e<this._filters.length;e++)this._filters[e].type=t},t.Filter.prototype.getType=function(){return this._type},t.Filter.prototype.setFrequency=function(t){this.frequency.setValue(t)},t.Filter.prototype.setQ=function(t){this.Q.setValue(t)},t.Filter.prototype.setRolloff=function(t){var e=Math.log(t/-12)/Math.LN2+1;if(e%1!==0)throw new RangeError("Filter rolloff can only be -12, -24, or -48");this.input.disconnect();for(var i=0;i<this._filters.length;i++)this._filters[i].disconnect(),this._filters[i]=null;this._filters=new Array(e);for(var n=0;e>n;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;e<this._filters.length;e++)this._filters[e].disconnect(),this._filters[e]=null;this.frequency.dispose(),this.Q.dispose(),this.detune.dispose(),this.gain.dispose(),this._filters=null,this.frequency=null,this.Q=null,this.gain=null,this.detune=null},t.Filter}),define("Tone/component/EQ",["Tone/core/Tone","Tone/signal/Signal","Tone/component/Filter"],function(t){return t.EQ=function(){t.call(this);var e=this.optionsObject(arguments,["low","mid","high"],t.EQ.defaults);this._lowFilter=new t.Filter(0,"lowpass"),this._lowMidFilter=new t.Filter(0,"highpass"),this._highMidFilter=new t.Filter(0,"lowpass"),this._highFilter=new t.Filter(0,"highpass"),this.lowFrequency=new t.Signal(e.lowFrequency),this.highFrequency=new t.Signal(e.highFrequency),this.lowGain=this.context.createGain(),this.midGain=this.context.createGain(),this.highGain=this.context.createGain(),this.chain(this.input,this._lowFilter,this.lowGain,this.output),this.chain(this.input,this._lowMidFilter,this._highMidFilter,this.midGain,this.output),this.chain(this.input,this._highFilter,this.highGain,this.output),this.lowFrequency.connect(this._lowFilter.frequency),this.lowFrequency.connect(this._lowMidFilter.frequency),this.highFrequency.connect(this._highMidFilter.frequency),this.highFrequency.connect(this._highFilter.frequency),this.setLow(e.low),this.setMid(e.mid),this.setHigh(e.high)},t.extend(t.EQ),t.EQ.defaults={low:0,mid:0,high:0,lowFrequency:400,highFrequency:2500},t.EQ.prototype.set=function(t){this.isUndef(t.mid)||this.setMid(t.mid),this.isUndef(t.high)||this.setHigh(t.high),this.isUndef(t.low)||this.setLow(t.low),this.isUndef(t.lowFrequency)||this.lowFrequency.setValue(t.lowFrequency),this.isUndef(t.highFrequency)||this.highFrequency.setValue(t.highFrequency)},t.EQ.prototype.setMid=function(t){this.midGain.gain.value=this.dbToGain(t)},t.EQ.prototype.setHigh=function(t){this.highGain.gain.value=this.dbToGain(t)},t.EQ.prototype.setLow=function(t){this.lowGain.gain.value=this.dbToGain(t)},t.EQ.prototype.dispose=function(){t.prototype.dispose.call(this),this._lowFilter.dispose(),this._lowMidFilter.dispose(),this._highMidFilter.dispose(),this._highFilter.dispose(),this.lowFrequency.dispose(),this.highFrequency.dispose(),this.lowGain.disconnect(),this.midGain.disconnect(),this.highGain.disconnect(),this._lowFilter=null,this._lowMidFilter=null,this._highMidFilter=null,this._highFilter=null,this.lowFrequency=null,this.highFrequency=null,this.lowGain=null,this.midGain=null,this.highGain=null},t.EQ}),define("Tone/signal/ScaleExp",["Tone/core/Tone","Tone/signal/Add","Tone/signal/Multiply","Tone/signal/Signal"],function(t){return t.ScaleExp=function(e,i,n,o,s){t.call(this),2===arguments.length?(n=e,o=i,s=2,e=-1,i=1):3===arguments.length&&(s=n,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._normalize=new t.Multiply(1),this._scale=new t.Multiply(1),this._plusOutput=new t.Add(0),this._expScaler=this.context.createWaveShaper(),this.chain(this.input,this._plusInput,this._normalize,this._expScaler,this._scale,this._plusOutput,this.output),this._setScalingParameters(),this.setExponent(this.defaultArg(s,2))},t.extend(t.ScaleExp),t.ScaleExp.prototype._setScalingParameters=function(){this._plusInput.setValue(-this._inputMin),this._scale.setValue(this._outputMax-this._outputMin),this._normalize.setValue(1/(this._inputMax-this._inputMin)),this._plusOutput.setValue(this._outputMin)},t.ScaleExp.prototype.setExponent=function(t){for(var e=1024,i=new Float32Array(e),n=0;e>n;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;n<this._delayCount;n++){var o=this.context.createDelay();o.connect(this._feedback),this._delayTime.connect(o.delayTime),this._delays[n]=o}this.input.connect(this._delays[0]),this._feedback.connect(this._delays[0]),this.chain.apply(this,this._delays),this.chain(this.resonance,this._resScale,this._feedback.gain),this._feedback.connect(this.output),this.setDelayTime(e)},t.extend(t.FeedbackCombFilter),t.FeedbackCombFilter.prototype.setDelayTime=function(t,e){e=this.toSeconds(e);var i=this.context.sampleRate,n=i*t;e=this.toSeconds(e);var o=100;if(o>n){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;a<this._delays.length;a++)this._delays[a].delayTime.setValueAtTime(0,e)}this._delayTime.setValueAtTime(t,e)},t.FeedbackCombFilter.prototype.dispose=function(){t.prototype.dispose.call(this);for(var e=0;e<this._delays.length;e++)this._delays[e].disconnect(),this._delays[e]=null;this._delayTime.dispose(),this.resonance.dispose(),this._resScale.dispose(),this._feedback.disconnect(),this._delays=null,this.resonance=null,this._resScale=null,this._feedback=null,this._delayTime=null},t.FeedbackCombFilter}),define("Tone/signal/Threshold",["Tone/core/Tone","Tone/signal/Signal"],function(t){return t.Threshold=function(t){this._thresh=this.context.createWaveShaper(),this._doubleThresh=this.context.createWaveShaper(),this.input=this._thresh,this.output=this._doubleThresh,this._thresh.connect(this._doubleThresh),this._setThresh(this._thresh,this.defaultArg(t,0)),this._setThresh(this._doubleThresh,.5)},t.extend(t.Threshold),t.Threshold.prototype._setThresh=function(t,e){for(var i=1023,n=new Float32Array(i),o=0;i>o;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;e<this.input.length;e++)this.input[e].dispose(),this.input[e]=null;t.prototype.dispose.call(this),this.gate=null};var e=function(e){this.selecter=new t.Equal(e),this.gate=this.input=this.output=this.context.createGain(),this.selecter.connect(this.gate.gain)};return t.extend(e),e.prototype.dispose=function(){t.prototype.dispose.call(this),this.selecter.dispose(),this.gate.disconnect(),this.selecter=null,this.gate=null},t.Select}),define("Tone/signal/Negate",["Tone/core/Tone","Tone/signal/Multiply","Tone/signal/Signal"],function(t){return t.Negate=function(){this._multiply=new t.Multiply(-1),this.input=this.output=this._multiply},t.extend(t.Negate),t.Negate.prototype.connect=t.Signal.prototype.connect,t.Negate.prototype.dispose=function(){t.prototype.dispose.call(this),this._multiply.dispose(),this._multiply=null},t.Negate}),define("Tone/signal/Not",["Tone/core/Tone","Tone/signal/EqualZero"],function(t){return t.Not=t.EqualZero,t.Not}),define("Tone/signal/LessThan",["Tone/core/Tone","Tone/signal/Threshold","Tone/signal/Add","Tone/signal/Signal","Tone/signal/Not"],function(t){return t.LessThan=function(e){this._adder=new t.Add(this.defaultArg(-e,0)),this._thresh=new t.Threshold(0),this._not=new t.Not,this.input=this._adder,this.output=this._not,this.chain(this._adder,this._thresh,this._not)},t.extend(t.LessThan),t.LessThan.prototype.setValue=function(t){this._adder.setValue(-t)},t.LessThan.prototype.connect=t.Signal.prototype.connect,t.LessThan.prototype.dispose=function(){t.prototype.dispose.call(this),this._adder.disconnect(),this._thresh.dispose(),this._not.dispose(),this._adder=null,this._thresh=null,this._not=null},t.LessThan}),define("Tone/signal/Abs",["Tone/core/Tone","Tone/signal/Select","Tone/signal/Negate","Tone/signal/LessThan","Tone/signal/Signal"],function(t){return t.Abs=function(){t.call(this),this._ltz=new t.LessThan(0),this._switch=new t.Select(2),this._negate=new t.Negate,this.input.connect(this._switch,0,0),this.input.connect(this._negate),this._negate.connect(this._switch,0,1),this._switch.connect(this.output),this.chain(this.input,this._ltz,this._switch.gate)},t.extend(t.Abs),t.Abs.prototype.connect=t.Signal.prototype.connect,t.Abs.prototype.dispose=function(){this._switch.dispose(),this._ltz.dispose(),this._negate.dispose(),this.input.disconnect(),this.output.disconnect(),this._switch=null,this._ltz=null,this._negate=null,this.input=null,this.output=null},t.Abs}),define("Tone/component/Follower",["Tone/core/Tone","Tone/signal/Abs","Tone/signal/Negate","Tone/signal/Multiply","Tone/signal/Signal"],function(t){return t.Follower=function(){t.call(this);var e=this.optionsObject(arguments,["attack","release"],t.Follower.defaults);this._abs=new t.Abs,this._filter=this.context.createBiquadFilter(),this._filter.type="lowpass",this._filter.frequency.value=0,this._filter.Q.value=-100,this._frequencyValues=this.context.createWaveShaper(),this._negate=new t.Negate,this._difference=this.context.createGain(),this._delay=this.context.createDelay(),this._delay.delayTime.value=.02,this._mult=new t.Multiply(1e3),this._attack=this.secondsToFrequency(e.attack),this._release=this.secondsToFrequency(e.release),this.chain(this.input,this._abs,this._filter,this.output),this.chain(this._abs,this._negate,this._difference),this.chain(this._filter,this._delay,this._difference),this.chain(this._difference,this._mult,this._frequencyValues,this._filter.frequency),this._setAttackRelease(this._attack,this._release)},t.extend(t.Follower),t.Follower.defaults={attack:.05,release:.5},t.Follower.prototype._setAttackRelease=function(t,e){for(var i=1024,n=new Float32Array(i),o=0;i>o;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<transportTimeline.length;e++){var i=transportTimeline[e];if(i.callbackTick()>=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;e<intervals.length;e++){var i=intervals[e];if(i.id===t)return intervals.splice(e,1),!0}return!1},Tone.Transport.prototype.clearIntervals=function(){intervals=[]},Tone.Transport.prototype.setTimeout=function(t,e,i){for(var n=this.toTicks(e),o=new TimelineEvent(t,i,n+transportTicks,0),s=0,r=timeouts.length;r>s;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;e<timeouts.length;e++){var i=timeouts[e];if(i.id===t)return timeouts.splice(e,1),!0}return!1},Tone.Transport.prototype.clearTimeouts=function(){timeouts=[]},Tone.Transport.prototype.setTimeline=function(t,e,i){for(var n=this.toTicks(e),o=new TimelineEvent(t,i,n,0),s=timelineProgress,r=transportTimeline.length;r>s;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;e<transportTimeline.length;e++){var i=transportTimeline[e];if(i.id===t)return transportTimeline.splice(e,1),!0}return!1},Tone.Transport.prototype.clearTimelines=function(){timelineProgress=0,transportTimeline=[]},Tone.Transport.prototype.toTicks=function(t){var e=this.toSeconds(t),i=this.notationToSeconds("4n"),n=e/i,o=n*tatum;return Math.round(o)},Tone.Transport.prototype.getTransportTime=function(){var t=timelineTicks/tatum,e=Math.floor(t/transportTimeSignature),i=Math.floor(t%1*4);t=Math.floor(t)%transportTimeSignature;var n=[e,t,i];return n.join(":")},Tone.Transport.prototype.setTransportTime=function(t){var e=this.toTicks(t);this._setTicks(e)},Tone.Transport.prototype.start=function(t){if(this.state===TransportState.STOPPED||this.state===TransportState.PAUSED){this.state=TransportState.STARTED;var e=this.toSeconds(t);this._clock.start(e);for(var i=0;i<SyncedSources.length;i++){var n=SyncedSources[i].source,o=SyncedSources[i].delay;n.start(e+o)}}},Tone.Transport.prototype.stop=function(t){if(this.state===TransportState.STARTED||this.state===TransportState.PAUSED){var e=this.toSeconds(t);this._clock.stop(e,this._onend.bind(this));for(var i=0;i<SyncedSources.length;i++){var n=SyncedSources[i].source;n.stop(e)}}else this._onend()},Tone.Transport.prototype._onend=function(){transportTicks=0,this._setTicks(0),this.clearTimeouts(),this.state=TransportState.STOPPED},Tone.Transport.prototype.pause=function(t){if(this.state===TransportState.STARTED){this.state=TransportState.PAUSED;var e=this.toSeconds(t);this._clock.stop(e);for(var i=0;i<SyncedSources.length;i++){var n=SyncedSources[i].source;n.pause(e)}}},Tone.Transport.prototype.setBpm=function(t,e){var i=this.notationToSeconds(tatum.toString()+"n",t,transportTimeSignature)/4;this._clock.setRate(i,e)},Tone.Transport.prototype.getBpm=function(){var t=this._clock.getRate();return 60*(t/tatum)},Tone.Transport.prototype.setTimeSignature=function(t,e){e=this.defaultArg(e,4),transportTimeSignature=t/(e/4)},Tone.Transport.prototype.getTimeSignature=function(){return transportTimeSignature},Tone.Transport.prototype.setLoopStart=function(t){loopStart=this.toTicks(t)},Tone.Transport.prototype.setLoopEnd=function(t){loopEnd=this.toTicks(t)},Tone.Transport.prototype.setLoopPoints=function(t,e){this.setLoopStart(t),this.setLoopEnd(e)},Tone.Transport.prototype.syncSource=function(t,e){SyncedSources.push({source:t,delay:this.toSeconds(this.defaultArg(e,0))})},Tone.Transport.prototype.unsyncSource=function(t){for(var e=0;e<SyncedSources.length;e++)SyncedSources[e].source===t&&SyncedSources.splice(e,1)},Tone.Transport.prototype.syncSignal=function(t){t.sync(this._clock._controlSignal)},Tone.Transport.prototype.dispose=function(){this._clock.dispose(),this._clock=null};var TimelineEventIDCounter=0,TimelineEvent=function(t,e,i,n){this.startTicks=n,this.tickTime=i,this.callback=t,this.context=e,this.id=TimelineEventIDCounter++};TimelineEvent.prototype.doCallback=function(t){this.callback.call(this.context,t)},TimelineEvent.prototype.callbackTick=function(){return this.startTicks+this.tickTime},TimelineEvent.prototype.testInterval=function(t){return(t-this.startTicks)%this.tickTime===0},Tone.prototype.isNotation=function(){var t=new RegExp(/[0-9]+[mnt]$/i);return function(e){return t.test(e)}}(),Tone.prototype.isTicks=function(){var t=new RegExp(/[0-9]+[i]$/i);return function(e){return t.test(e)}}(),Tone.prototype.isTransportTime=function(){var t=new RegExp(/^\d+(\.\d+)?:\d+(\.\d+)?(:\d+(\.\d+)?)?$/);return function(e){return t.test(e)}}(),Tone.prototype.isFrequency=function(){var t=new RegExp(/[0-9]+hz$/i);return function(e){return t.test(e)}}(),Tone.prototype.notationToSeconds=function(t,e,i){e=this.defaultArg(e,Tone.Transport.getBpm()),i=this.defaultArg(i,transportTimeSignature);var n=60/e,o=parseInt(t,10),s=0;0===o&&(s=0);var r=t.slice(-1);return s="t"===r?4/o*2/3:"n"===r?4/o:"m"===r?o*i:0,n*s},Tone.prototype.transportTimeToSeconds=function(t,e,i){e=this.defaultArg(e,Tone.Transport.getBpm()),i=this.defaultArg(i,transportTimeSignature);var n=0,o=0,s=0,r=t.split(":");2===r.length?(n=parseFloat(r[0]),o=parseFloat(r[1])):1===r.length?o=parseFloat(r[0]):3===r.length&&(n=parseFloat(r[0]),o=parseFloat(r[1]),s=parseFloat(r[2]));var a=n*i+o+s/4;return a*this.notationToSeconds("4n")},Tone.prototype.ticksToSeconds=function(t,e,i){t=Math.floor(t);var n=this.notationToSeconds("4n",e,i);return n*t/tatum},Tone.prototype.toTransportTime=function(t,e,i){var n=this.toSeconds(t,e,i);e=this.defaultArg(e,Tone.Transport.getBpm()),i=this.defaultArg(i,transportTimeSignature);var o=this.notationToSeconds("4n"),s=n/o,r=Math.floor(s/i),a=Math.floor(s%1*4);s=Math.floor(s)%i;var c=[r,s,a];return c.join(":")},Tone.prototype.toFrequency=function(t,e){return this.isFrequency(t)?parseFloat(t):this.isNotation(t)||this.isTransportTime(t)?this.secondsToFrequency(this.toSeconds(t,e)):t},Tone.prototype.toSeconds=function(time,now){if(now=this.defaultArg(now,this.now()),"number"==typeof time)return time;if("string"==typeof time){var plusTime=0;"+"===time.charAt(0)&&(plusTime=now,time=time.slice(1));var components=time.split(/[\(\)\-\+\/\*]/);if(components.length>1){for(var oringalTime=time,i=0;i<components.length;i++){var symb=components[i];if(""!==symb){var val=this.toSeconds(symb.trim());time=time.replace(symb,val)}}try{time=eval(time)}catch(e){throw new EvalError("problem evaluating Tone.Time: "+oringalTime)}}else time=this.isNotation(time)?this.notationToSeconds(time):this.isTransportTime(time)?this.transportTimeToSeconds(time):this.isFrequency(time)?this.frequencyToSeconds(time):parseFloat(time);return time+plusTime}return now};var TransportConstructor=Tone.Transport;return Tone.Transport=new Tone.Transport,Tone.Transport.setBpm(120),Tone._initAudioContext(function(){Tone.Transport.stop();var t=Tone.Transport.getBpm();Tone.Transport._clock.dispose(),TransportConstructor.call(Tone.Transport),Tone.Transport.setBpm(t)}),Tone.Transport}),define("Tone/source/Source",["Tone/core/Tone","Tone/core/Transport"],function(t){return t.Source=function(){this.output=this.context.createGain(),this.state=t.Source.State.STOPPED},t.extend(t.Source),t.Source.prototype.start=function(){},t.Source.prototype.stop=function(){},t.Source.prototype.pause=function(t){this.stop(t)},t.Source.prototype.sync=function(e){t.Transport.syncSource(this,e)},t.Source.prototype.unsync=function(){t.Transport.unsyncSource(this)},t.Source.prototype.setVolume=function(t,e){var i=this.now(),n=this.dbToGain(t);if(e){var o=this.output.gain.value;this.output.gain.cancelScheduledValues(i),this.output.gain.setValueAtTime(o,i),this.output.gain.linearRampToValueAtTime(n,i+this.toSeconds(e))}else this.output.gain.setValueAtTime(n,i)},t.Source.prototype.dispose=function(){t.prototype.dispose.call(this),this.state=null},t.Source.State={STARTED:"started",PAUSED:"paused",STOPPED:"stopped",SYNCED:"synced"},t.Source}),define("Tone/source/Oscillator",["Tone/core/Tone","Tone/signal/Signal","Tone/source/Source"],function(t){return t.Oscillator=function(){t.Source.call(this);var e=this.optionsObject(arguments,["frequency","type"],t.Oscillator.defaults);this.oscillator=this.context.createOscillator(),this.frequency=new t.Signal(e.frequency),this.detune=new t.Signal(e.detune),this.onended=e.onended,this._wave=null,this._phase=e.phase,this._type=e.type,this.oscillator.connect(this.output),this.setPhase(this._phase)},t.extend(t.Oscillator,t.Source),t.Oscillator.defaults={type:"sine",frequency:440,onended:function(){},detune:0,phase:0},t.Oscillator.prototype.start=function(e){this.state===t.Source.State.STOPPED&&(this.state=t.Source.State.STARTED,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(e)),this.oscillator.onended=this._onended.bind(this))},t.Oscillator.prototype.stop=function(e){this.state===t.Source.State.STARTED&&(e||(this.state=t.Source.State.STOPPED),this.oscillator.stop(this.toSeconds(e)))},t.Oscillator.prototype.setFrequency=function(t,e){e?this.frequency.exponentialRampToValueAtTime(this.toFrequency(t),this.toSeconds(e)):this.frequency.setValue(this.toFrequency(t))},t.Oscillator.prototype.setType=function(t){var e=4096,i=e/2,n=new Float32Array(i),o=new Float32Array(i);n[0]=0,o[0]=0;for(var s=this._phase,r=1;i>r;++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;o<this._filterDelayCount;o++){var s=new e(this._delayTime,this.dampening);s.connect(this._feedback),this._filterDelays[o]=s}this.input.connect(this._filterDelays[0]),this._feedback.connect(this._filterDelays[0]),this.chain.apply(this,this._filterDelays),this.chain(this.resonance,this._resScale,this._feedback.gain),this._feedback.connect(this.output),this.setDelayTime(i)},t.extend(t.LowpassCombFilter),t.LowpassCombFilter.prototype.setDelayTime=function(t,e){e=this.toSeconds(e);var i=this.context.sampleRate,n=i*t;e=this.toSeconds(e);var o=100;if(o>n){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;a<this._filterDelays.length;a++)this._filterDelays[a].setDelay(0,e)}this._delayTime.setValueAtTime(t,e)},t.LowpassCombFilter.prototype.dispose=function(){t.prototype.dispose.call(this);for(var e=0;e<this._filterDelays.length;e++)this._filterDelays[e].dispose(),this._filterDelays[e]=null;this._delayTime.dispose(),this.dampening.dispose(),this.resonance.dispose(),this._resScale.dispose(),this._feedback.disconnect(),this._filterDelays=null,this.dampening=null,this.resonance=null,this._resScale=null,this._feedback=null,this._delayTime=null};var e=function(t,e){this.delay=this.input=this.context.createDelay(),t.connect(this.delay.delayTime),this.filter=this.output=this.context.createBiquadFilter(),e.connect(this.filter.frequency),this.filter.type="lowpass",this.filter.Q.value=0,this.delay.connect(this.filter)};return t.extend(e),e.prototype.setDelay=function(t,e){this.delay.delayTime.setValueAtTime(t,e)},e.prototype.dispose=function(){this.delay.disconnect(),this.filter.disconnect(),this.delay=null,this.filter=null},t.LowpassCombFilter}),define("Tone/component/Merge",["Tone/core/Tone"],function(t){return t.Merge=function(){this.output=this.context.createGain(),this.input=new Array(2),this.left=this.input[0]=this.context.createGain(),this.right=this.input[1]=this.context.createGain(),this._merger=this.context.createChannelMerger(2),this.left.connect(this._merger,0,0),this.right.connect(this._merger,0,1),this._merger.connect(this.output)},t.extend(t.Merge),t.Merge.prototype.dispose=function(){t.prototype.dispose.call(this),this.left.disconnect(),this.right.disconnect(),this._merger.disconnect(),this.left=null,this.right=null,this._merger=null},t.Merge}),define("Tone/core/Master",["Tone/core/Tone"],function(t){t.Master=function(){t.call(this),this.limiter=this.context.createDynamicsCompressor(),this.limiter.threshold.value=0,this.limiter.ratio.value=20,this.chain(this.input,this.limiter,this.output,this.context.destination)},t.extend(t.Master),t.Master.prototype.mute=function(t){t=this.defaultArg(t,!0),this.output.gain.value=t?0:1},t.Master.prototype.setVolume=function(t,e){var i=this.now(),n=this.dbToGain(t);if(e){var o=this.output.gain.value;this.output.gain.cancelScheduledValues(i),this.output.gain.setValueAtTime(o,i),this.output.gain.linearRampToValueAtTime(n,i+this.toSeconds(e))}else this.output.gain.setValueAtTime(n,i)},t.prototype.toMaster=function(){this.connect(t.Master)},AudioNode.prototype.toMaster=function(){this.connect(t.Master)};var e=t.Master;return t.Master=new t.Master,t._initAudioContext(function(){e.call(t.Master)}),t.Master}),define("Tone/component/Meter",["Tone/core/Tone","Tone/core/Master"],function(t){return t.Meter=function(e,i,n){t.call(this),this.channels=this.defaultArg(e,1),this.smoothing=this.defaultArg(i,.8),this.clipMemory=this.defaultArg(n,500),this._volume=new Array(this.channels),this._values=new Array(this.channels);for(var o=0;o<this.channels;o++)this._volume[o]=0,this._values[o]=0;this._lastClip=0,this._jsNode=this.context.createScriptProcessor(this.bufferSize,this.channels,1),this._jsNode.onaudioprocess=this._onprocess.bind(this),this._jsNode.noGC(),this.input.connect(this.output),this.input.connect(this._jsNode)},t.extend(t.Meter),t.Meter.prototype._onprocess=function(t){for(var e=this._jsNode.bufferSize,i=this.smoothing,n=0;n<this.channels;n++){for(var o,s=t.inputBuffer.getChannelData(n),r=0,a=0,c=!1,l=0;e>l;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._lastClip<this.clipMemory},t.Meter.prototype.dispose=function(){t.prototype.dispose.call(this),this._jsNode.disconnect(),this._jsNode.onaudioprocess=null,this._volume=null,this._values=null},t.Meter}),define("Tone/component/Mono",["Tone/core/Tone","Tone/component/Merge"],function(t){return t.Mono=function(){t.call(this),this._merge=new t.Merge,this.input.connect(this._merge,0,0),this.input.connect(this._merge,0,1),this.input.gain.value=this.dbToGain(-10),this._merge.connect(this.output)},t.extend(t.Mono),t.Mono.prototype.dispose=function(){t.prototype.dispose.call(this),this._merge.dispose(),this._merge=null},t.Mono}),define("Tone/component/Split",["Tone/core/Tone"],function(t){return t.Split=function(){this.input=this.context.createGain(),this.output=new Array(2),this._splitter=this.context.createChannelSplitter(2),this.left=this.output[0]=this.context.createGain(),this.right=this.output[1]=this.context.createGain(),this.input.connect(this._splitter),this._splitter.connect(this.left,0,0),this._splitter.connect(this.right,1,0)},t.extend(t.Split),t.Split.prototype.dispose=function(){t.prototype.dispose.call(this),this._splitter.disconnect(),this.left.disconnect(),this.right.disconnect(),this.left=null,this.right=null,this._splitter=null},t.Split}),define("Tone/component/Panner",["Tone/core/Tone","Tone/component/DryWet","Tone/component/Merge","Tone/component/Split"],function(t){return t.Panner=function(e){t.call(this),this._dryWet=new t.DryWet,this._merger=new t.Merge,this._splitter=new t.Split,this.pan=this._dryWet.wetness,this.input.connect(this._splitter.left),this.input.connect(this._splitter.right),this._splitter.left.connect(this._dryWet.dry),this._splitter.right.connect(this._dryWet.wet),this._dryWet.dry.connect(this._merger.left),this._dryWet.wet.connect(this._merger.right),this._merger.connect(this.output),this.setPan(this.defaultArg(e,.5))},t.extend(t.Panner),t.Panner.prototype.setPan=function(t,e){this._dryWet.setWet(t,e)},t.Panner.prototype.dispose=function(){t.prototype.dispose.call(this),this._dryWet.dispose(),this._splitter.dispose(),this._merger.dispose(),this._dryWet=null,this._splitter=null,this._merger=null,this.pan=null},t.Panner}),define("Tone/component/Recorder",["Tone/core/Tone","Tone/core/Master"],function(t){t.Recorder=function(i){t.call(this),this.channels=this.defaultArg(i,1),this._jsNode=this.context.createScriptProcessor(this.bufferSize,this.channels,1),this._jsNode.onaudioprocess=this._audioprocess.bind(this),this._recordBuffers=new Array(this.channels),this._recordStartSample=0,this._recordEndSample=0,this._recordDuration=0,this.state=e.STOPPED,this._recordBufferOffset=0,this._callback=function(){},this.input.connect(this._jsNode),this.input.connect(this.output),this._jsNode.noGC(),this.clear()},t.extend(t.Recorder),t.Recorder.prototype._audioprocess=function(t){if(this.state!==e.STOPPED&&this.state===e.RECORDING){var i,n,o=this.defaultArg(t.playbackTime,this.now()),s=this.toSamples(o),r=this._jsNode.bufferSize,a=s+r;s>this._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;r<t.numberOfChannels;r++){var a=t.getChannelData(r);if(0===e&&i===n)this._recordBuffers[r].set(a,o);else for(var c=e;e+i>c;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;o<this.channels;o++)this._recordBuffers[o]=new Float32Array(this._recordDuration);this.state=e.RECORDING,this._callback=this.defaultArg(n,function(){})}},t.Recorder.prototype.clear=function(){for(var t=0;t<this.channels;t++)this._recordBuffers[t]=null;this._recordBufferOffset=0},t.Recorder.prototype.isEmpty=function(){return null===this._recordBuffers[0]},t.Recorder.prototype.getFloat32Array=function(){return this.isEmpty()?null:this._recordBuffers},t.Recorder.prototype.getAudioBuffer=function(){if(this.isEmpty())return null;for(var t=this.context.createBuffer(this.channels,this._recordBuffers[0].length,this.context.sampleRate),e=0;e<t.numberOfChannels;e++){var i=t.getChannelData(e);i.set(this._recordBuffers[e])}return t},t.Recorder.prototype.dispose=function(){t.prototype.dispose.call(this),this._jsNode.disconnect(),this._jsNode.onaudioprocess=void 0,this._jsNode=null,this._recordBuffers=null};var e={STOPPED:"stopped",SCHEDULED:"scheduled",RECORDING:"recording"};return t.Recorder}),define("Tone/core/Bus",["Tone/core/Tone"],function(t){var e={};t.prototype.send=function(t,i){e.hasOwnProperty(t)||(e[t]=this.context.createGain());var n=this.context.createGain();return n.gain.value=this.defaultArg(i,1),this.chain(this.output,n,e[t]),n},t.prototype.receive=function(t,i){e.hasOwnProperty(t)||(e[t]=this.context.createGain()),i=this.defaultArg(i,this.input),e[t].connect(i)}}),define("Tone/core/Note",["Tone/core/Tone","Tone/core/Transport"],function(t){function e(t,e,n){if(i.hasOwnProperty(t))for(var o=i[t],s=0,r=o.length;r>s;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<o.length;s++){var r,a=o[s];if(Array.isArray(a)){var c=a[0],l=a.slice(1);r=new t.Note(n,c,l)}else r=new t.Note(n,a);i.push(r)}}}return i};var n={c:0,"c#":1,db:1,d:2,"d#":3,eb:3,e:4,f:5,"f#":6,gb:6,g:7,"g#":8,ab:8,a:9,"a#":10,bb:10,b:11},o=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],s=261.6255653005986;return t.prototype.noteToFrequency=function(t){var e=t.split(/(\d+)/);if(3===e.length){var i=n[e[0].toLowerCase()],o=e[1],r=i+12*parseInt(o,10);return Math.pow(2,(r-48)/12)*s}return 0},t.prototype.frequencyToNote=function(t){var e=Math.log(t/s)/Math.LN2,i=Math.round(12*e)+48,n=Math.floor(i/12),r=o[i%12];return r+n.toString()},t.prototype.intervalToFrequencyRatio=function(t){return Math.pow(2,t/12)},t.prototype.midiToNote=function(t){var e=Math.floor(t/12)-2,i=t%12;return o[i]+e},t.prototype.noteToMidi=function(t){var e=t.split(/(\d+)/);if(3===e.length){var i=n[e[0].toLowerCase()],o=e[1];return i+12*(parseInt(o,10)+2)}return 0},t.Note}),define("Tone/effect/Effect",["Tone/core/Tone","Tone/component/DryWet"],function(t){return t.Effect=function(){t.call(this);var e=this.optionsObject(arguments,["dry"],t.Effect.defaults);this.dryWet=new t.DryWet,this.effectSend=this.context.createGain(),this.effectReturn=this.context.createGain(),this.input.connect(this.dryWet.dry),this.input.connect(this.effectSend),this.effectReturn.connect(this.dryWet.wet),this.dryWet.connect(this.output),this.setDry(e.dry)},t.extend(t.Effect),t.Effect.defaults={dry:0},t.Effect.prototype.setDry=function(t,e){this.dryWet.setDry(t,e)},t.Effect.prototype.setWet=function(t,e){this.dryWet.setWet(t,e)},t.Effect.prototype.set=function(t){this.isUndef(t.dry)||this.setDry(t.dry),this.isUndef(t.wet)||this.setWet(t.wet)},t.Effect.prototype.bypass=function(){this.setDry(1)},t.Effect.prototype.connectEffect=function(t){this.chain(this.effectSend,t,this.effectReturn)},t.Effect.prototype.setPreset=function(t){!this.isUndef(this.preset)&&this.preset.hasOwnProperty(t)&&this.set(this.preset[t])},t.Effect.prototype.dispose=function(){t.prototype.dispose.call(this),this.dryWet.dispose(),this.effectSend.disconnect(),this.effectReturn.disconnect(),this.dryWet=null,this.effectSend=null,this.effectReturn=null},t.Effect}),define("Tone/effect/AutoPanner",["Tone/core/Tone","Tone/effect/Effect","Tone/component/LFO","Tone/component/Panner"],function(t){return t.AutoPanner=function(){var e=this.optionsObject(arguments,["frequency"],t.AutoPanner.defaults);t.Effect.call(this,e),this._lfo=new t.LFO(e.frequency,0,1),this._panner=new t.Panner,this.connectEffect(this._panner),this._lfo.connect(this._panner.pan),this.setType(e.type)},t.extend(t.AutoPanner,t.Effect),t.AutoPanner.defaults={frequency:1,type:"sine"},t.AutoPanner.prototype.start=function(t){this._lfo.start(t)},t.AutoPanner.prototype.stop=function(t){this._lfo.stop(t)},t.AutoPanner.prototype.setType=function(t){this._lfo.setType(t)},t.AutoPanner.prototype.setFrequency=function(t){this._lfo.setFrequency(t)},t.AutoPanner.prototype.set=function(e){this.isUndef(e.frequency)||this.setFrequency(e.frequency),this.isUndef(e.type)||this.setType(e.type),t.Effect.prototype.set.call(this,e)},t.AutoPanner.prototype.dispose=function(){t.Effect.prototype.dispose.call(this),this._lfo.dispose(),this._panner.dispose(),this._lfo=null,this._panner=null},t.AutoPanner}),define("Tone/effect/AutoWah",["Tone/core/Tone","Tone/component/Follower","Tone/signal/ScaleExp","Tone/effect/Effect","Tone/component/Filter"],function(t){return t.AutoWah=function(){var e=this.optionsObject(arguments,["baseFrequency","octaves","sensitivity"],t.AutoWah.defaults);t.Effect.call(this,e),this._follower=new t.Follower(e.follower),this._sweepRange=new t.ScaleExp(0,1,0,1,.5),this._baseFrequency=e.baseFrequency,this._octaves=e.octaves,this._bandpass=new t.Filter(0,"bandpass"),this._bandpass.setRolloff(e.rolloff),this._peaking=this.context.createBiquadFilter(),this._peaking.type="peaking",this._peaking.gain.value=e.gain,this.chain(this.effectSend,this._follower,this._sweepRange),this._sweepRange.connect(this._bandpass.frequency),this._sweepRange.connect(this._peaking.frequency),this.chain(this.effectSend,this._bandpass,this._peaking,this.effectReturn),this._setSweepRange(),this.setSensitiviy(e.sensitivity)},t.extend(t.AutoWah,t.Effect),t.AutoWah.defaults={baseFrequency:100,octaves:6,sensitivity:0,Q:2,gain:2,rolloff:-48,follower:{attack:.3,release:.5}},t.AutoWah.prototype.setOctaves=function(t){this._octaves=t,this._setSweepRange()},t.AutoWah.prototype.setBaseFrequency=function(t){this._baseFrequency=t,this._setSweepRange()},t.AutoWah.prototype.setSensitiviy=function(t){this._sweepRange.setInputMax(this.dbToGain(t))},t.AutoWah.prototype._setSweepRange=function(){this._sweepRange.setOutputMin(this._baseFrequency),this._sweepRange.setOutputMax(Math.min(this._baseFrequency*Math.pow(2,this._octaves),this.context.sampleRate/2))},t.AutoWah.prototype.set=function(e){this.isUndef(e.baseFrequency)||this.setBaseFrequency(e.baseFrequency),this.isUndef(e.sensitivity)||this.setSensitiviy(e.sensitivity),this.isUndef(e.octaves)||this.setOctaves(e.octaves),this.isUndef(e.follower)||this._follower.set(e.follower),this.isUndef(e.Q)||(this._bandpass.Q.value=e.Q),this.isUndef(e.gain)||(this._peaking.gain.value=e.gain),t.Effect.prototype.set.call(this,e)},t.AutoWah.prototype.dispose=function(){t.Effect.prototype.dispose.call(this),this._follower.dispose(),this._sweepRange.dispose(),this._bandpass.disconnect(),this._peaking.disconnect(),this._follower=null,this._sweepRange=null,this._bandpass=null,this._peaking=null},t.AutoWah}),define("Tone/signal/Modulo",["Tone/core/Tone","Tone/signal/Multiply"],function(t){t.Modulo=function(i,n){t.call(this),n=this.defaultArg(n,8),this._modChain=[];for(var o=n-1;o>=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;e<this._modChain.length;e++)this._modChain[e].dispose(),this._modChain[e]=null;this._modChain=null};var e=function(e,i){var n=e*i;this.input=this.context.createGain(),this._div=new t.Multiply(1/n),this._operator=this.context.createWaveShaper(),this.chain(this.input,this._div,this._operator),this._makeCurve(n)
|
|
};return t.extend(e),e.prototype._makeCurve=function(t){for(var e=Math.pow(2,18),i=new Float32Array(e),n=0;n<i.length;n++)i[n]=n===e-1?-t:0===n?t:0;this._operator.curve=i},e.prototype.connect=function(t){this._operator.connect(t),this.input.connect(t)},e.prototype.dispose=function(){t.prototype.dispose.call(this),this._div.dispose(),this._operator.disconnect(),this._div=null,this._operator=null},t.Modulo}),define("Tone/effect/BitCrusher",["Tone/core/Tone","Tone/effect/Effect","Tone/signal/Modulo","Tone/signal/Negate","Tone/signal/Add"],function(t){return t.BitCrusher=function(){var e=this.optionsObject(arguments,["bits"],t.BitCrusher.defaults);t.Effect.call(this,e),this._modulo=new t.Modulo(1,e.bits),this._neg=new t.Negate,this._sub=this.context.createGain();var i=Math.pow(2,e.bits-1);this._scale=new t.Scale(-1,1,0,i),this._invScale=new t.Scale(0,i,-1,1),this.effectSend.connect(this._scale),this._scale.connect(this._invScale),this.chain(this._scale,this._modulo,this._neg,this._invScale,this.effectReturn)},t.extend(t.BitCrusher,t.Effect),t.BitCrusher.defaults={bits:4},t.BitCrusher.prototype.setBits=function(t){t=Math.min(t,8);var e=Math.pow(2,t-1);this._scale.setOutputMax(e),this._invScale.setInputMax(e)},t.BitCrusher.prototype.set=function(e){this.isUndef(e.bits)||this.setBits(e.bits),t.Effect.prototype.set.call(this,e)},t.BitCrusher.prototype.dispose=function(){t.Effect.prototype.dispose.call(this),this._modulo.dispose(),this._neg.dispose(),this._sub.disconnect(),this._scale.dispose(),this._invScale.dispose(),this._modulo=null,this._neg=null,this._sub=null,this._scale=null,this._invScale=null},t.BitCrusher}),define("Tone/effect/StereoEffect",["Tone/core/Tone","Tone/effect/Effect","Tone/component/Split","Tone/component/Merge","Tone/component/Mono"],function(t){return t.StereoEffect=function(){t.call(this);var e=this.optionsObject(arguments,["dry"],t.Effect.defaults);this.dryWet=new t.DryWet,this._mono=new t.Mono,this._split=new t.Split,this.effectSendL=this._split.left,this.effectSendR=this._split.right,this._merge=new t.Merge,this.effectReturnL=this._merge.left,this.effectReturnR=this._merge.right,this.input.connect(this._mono),this._mono.connect(this._split),this._mono.connect(this.dryWet.dry),this._merge.connect(this.dryWet.wet),this.dryWet.connect(this.output),this.setDry(e.dry)},t.extend(t.StereoEffect,t.Effect),t.StereoEffect.prototype.dispose=function(){t.prototype.dispose.call(this),this.dryWet.dispose(),this._mono.dispose(),this._split.dispose(),this._merge.dispose(),this._mono=null,this._split=null,this._merge=null,this.effectSendL=null,this.effectSendR=null,this.effectReturnL=null,this.effectReturnR=null,this.dryWet=null},t.StereoEffect}),define("Tone/effect/FeedbackEffect",["Tone/core/Tone","Tone/effect/Effect","Tone/signal/Signal","Tone/signal/Multiply"],function(t){return t.FeedbackEffect=function(){var e=this.optionsObject(arguments,["feedback"]);e=this.defaultArg(e,t.FeedbackEffect.defaults),t.Effect.call(this,e),this.feedback=new t.Signal(e.feedback),this._half=new t.Multiply(.5),this._feedbackGain=this.context.createGain(),this.chain(this.effectReturn,this._feedbackGain,this.effectSend),this.chain(this.feedback,this._half,this._feedbackGain.gain)},t.extend(t.FeedbackEffect,t.Effect),t.FeedbackEffect.defaults={feedback:.25},t.FeedbackEffect.prototype.setFeedback=function(t,e){e?this.feedback.linearRampToValueNow(t,e):this.feedback.setValue(t)},t.FeedbackEffect.prototype.set=function(e){this.isUndef(e.feedback)||this.setFeedback(e.feedback),t.Effect.prototype.set.call(this,e)},t.FeedbackEffect.prototype.dispose=function(){t.Effect.prototype.dispose.call(this),this.feedback.dispose(),this._half.dispose(),this._feedbackGain.disconnect(),this.feedback=null,this._feedbackGain=null,this._half=null},t.FeedbackEffect}),define("Tone/effect/StereoXFeedbackEffect",["Tone/core/Tone","Tone/effect/StereoEffect","Tone/effect/FeedbackEffect"],function(t){return t.StereoXFeedbackEffect=function(){var e=this.optionsObject(arguments,["feedback"],t.FeedbackEffect.defaults);t.StereoEffect.call(this,e),this.feedback=new t.Signal(e.feedback),this._half=new t.Multiply(.5),this._feedbackLR=this.context.createGain(),this._feedbackRL=this.context.createGain(),this.chain(this.effectReturnL,this._feedbackLR,this.effectSendR),this.chain(this.effectReturnR,this._feedbackRL,this.effectSendL),this.feedback.connect(this._half),this.fan(this._half,this._feedbackLR.gain,this._feedbackRL.gain)},t.extend(t.StereoXFeedbackEffect,t.FeedbackEffect),t.StereoXFeedbackEffect.prototype.dispose=function(){t.StereoEffect.prototype.dispose.call(this),this.feedback.dispose(),this._half.dispose(),this._feedbackLR.disconnect(),this._feedbackRL.disconnect(),this.feedback=null,this._feedbackLR=null,this._feedbackRL=null,this._half=null},t.StereoXFeedbackEffect}),define("Tone/effect/Chorus",["Tone/core/Tone","Tone/component/LFO","Tone/effect/StereoXFeedbackEffect"],function(t){return t.Chorus=function(){var e=this.optionsObject(arguments,["rate","delayTime","depth"],t.Chorus.defaults);t.StereoXFeedbackEffect.call(this,e),this._depth=e.depth,this._delayTime=e.delayTime/1e3,this._lfoL=new t.LFO(e.rate,0,1),this._lfoR=new t.LFO(e.rate,0,1),this._lfoR.setPhase(180),this._delayNodeL=this.context.createDelay(),this._delayNodeR=this.context.createDelay(),this.chain(this.effectSendL,this._delayNodeL,this.effectReturnL),this.chain(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.setDepth(this._depth),this.setRate(e.rate),this.setType(e.type)},t.extend(t.Chorus,t.StereoXFeedbackEffect),t.Chorus.defaults={rate:1.5,delayTime:3.5,depth:.7,feedback:.4,type:"sine"},t.Chorus.prototype.setDepth=function(t){this._depth=t;var e=this._delayTime*t;this._lfoL.setMin(this._delayTime-e),this._lfoL.setMax(this._delayTime+e),this._lfoR.setMin(this._delayTime-e),this._lfoR.setMax(this._delayTime+e)},t.Chorus.prototype.setDelayTime=function(t){this._delayTime=t/1e3,this.setDepth(this._depth)},t.Chorus.prototype.setRate=function(t){this._lfoL.setFrequency(t)},t.Chorus.prototype.setType=function(t){this._lfoL.setType(t),this._lfoR.setType(t)},t.Chorus.prototype.set=function(e){this.isUndef(e.rate)||this.setRate(e.rate),this.isUndef(e.delayTime)||this.setDelayTime(e.delayTime),this.isUndef(e.depth)||this.setDepth(e.depth),this.isUndef(e.type)||this.setType(e.type),t.FeedbackEffect.prototype.set.call(this,e)},t.Chorus.prototype.dispose=function(){t.StereoXFeedbackEffect.prototype.dispose.call(this),this._lfoL.dispose(),this._lfoR.dispose(),this._delayNodeL.disconnect(),this._delayNodeR.disconnect(),this._lfoL=null,this._lfoR=null,this._delayNodeL=null,this._delayNodeR=null},t.Chorus}),define("Tone/effect/FeedbackDelay",["Tone/core/Tone","Tone/effect/FeedbackEffect","Tone/signal/Signal"],function(t){return t.FeedbackDelay=function(){var e=this.optionsObject(arguments,["delayTime"],t.FeedbackDelay.defaults);t.FeedbackEffect.call(this,e),this.delayTime=new t.Signal,this._delayNode=this.context.createDelay(4),this.connectEffect(this._delayNode),this.delayTime.connect(this._delayNode.delayTime),this.setDelayTime(e.delayTime)},t.extend(t.FeedbackDelay,t.FeedbackEffect),t.FeedbackDelay.defaults={delayTime:.25},t.FeedbackDelay.prototype.setDelayTime=function(t,e){e?this.delayTime.linearRampToValueNow(this.toSeconds(t),e):this.delayTime.setValue(this.toSeconds(t))},t.FeedbackDelay.prototype.set=function(e){this.isUndef(e.delayTime)||this.setDelayTime(e.delayTime),t.FeedbackEffect.prototype.set.call(this,e)},t.FeedbackDelay.prototype.dispose=function(){t.FeedbackEffect.prototype.dispose.call(this),this.delayTime.dispose(),this._delayNode.disconnect(),this._delayNode=null,this.delayTime=null},t.FeedbackDelay}),define("Tone/effect/Freeverb",["Tone/core/Tone","Tone/component/LowpassCombFilter","Tone/effect/StereoEffect","Tone/signal/Signal","Tone/component/Split","Tone/component/Merge"],function(t){var e=[1557/44100,1617/44100,1491/44100,1422/44100,1277/44100,1356/44100,1188/44100,1116/44100],i=[225,556,441,341];return t.Freeverb=function(){var n=this.optionsObject(arguments,["roomSize","dampening"],t.Freeverb.defaults);t.StereoEffect.call(this,n),this.roomSize=new t.Signal(n.roomSize),this.dampening=new t.Signal(n.dampening),this._dampeningScale=new t.ScaleExp(0,1,100,8e3,.5),this._combFilters=[],this._allpassFiltersL=[],this._allpassFiltersR=[];for(var o=0;o<i.length;o++){var s=this.context.createBiquadFilter();s.type="allpass",s.frequency.value=i[o],this._allpassFiltersL.push(s)}for(var r=0;r<i.length;r++){var a=this.context.createBiquadFilter();a.type="allpass",a.frequency.value=i[r],this._allpassFiltersR.push(a)}for(var c=0;c<e.length;c++){var l=new t.LowpassCombFilter(e[c]);c<e.length/2?this.chain(this.effectSendL,l,this._allpassFiltersL[0]):this.chain(this.effectSendR,l,this._allpassFiltersR[0]),this.roomSize.connect(l.resonance),this._dampeningScale.connect(l.dampening),this._combFilters.push(l)}this.chain.apply(this,this._allpassFiltersL),this.chain.apply(this,this._allpassFiltersR),this._allpassFiltersL[this._allpassFiltersL.length-1].connect(this.effectReturnL),this._allpassFiltersR[this._allpassFiltersR.length-1].connect(this.effectReturnR),this.dampening.connect(this._dampeningScale)},t.extend(t.Freeverb,t.StereoEffect),t.Freeverb.defaults={roomSize:.7,dampening:.5},t.Freeverb.prototype.setRoomSize=function(t){this.roomSize.setValue(t)},t.Freeverb.prototype.setDampening=function(t){this.dampening.setValue(t)},t.Freeverb.prototype.set=function(e){this.isUndef(e.dampening)||this.setDampening(e.dampening),this.isUndef(e.roomSize)||this.setRoomSize(e.roomSize),t.StereoEffect.prototype.set.call(this,e)},t.Freeverb.prototype.dispose=function(){t.StereoEffect.prototype.dispose.call(this);for(var e=0;e<this._allpassFiltersL.length;e++)this._allpassFiltersL[e].disconnect(),this._allpassFiltersL[e]=null;this._allpassFiltersL=null;for(var i=0;i<this._allpassFiltersR.length;i++)this._allpassFiltersR[i].disconnect(),this._allpassFiltersR[i]=null;this._allpassFiltersR=null;for(var n=0;n<this._combFilters.length;n++)this._combFilters[n].dispose(),this._combFilters[n]=null;this._combFilters=null,this.roomSize.dispose(),this.dampening.dispose(),this._dampeningScale.dispose(),this.roomSize=null,this.dampening=null,this._dampeningScale=null},t.Freeverb}),define("Tone/effect/JCReverb",["Tone/core/Tone","Tone/component/FeedbackCombFilter","Tone/effect/StereoEffect","Tone/signal/Scale"],function(t){var e=[.06748,.06404,.08212,.09004],i=[.773,.802,.753,.733],n=[347,113,37];return t.JCReverb=function(){t.StereoEffect.call(this),this.roomSize=new t.Signal(.5),this._scaleRoomSize=new t.Scale(0,1,-.733,.197),this._allpassFilters=[],this._feedbackCombFilters=[];for(var o=0;o<n.length;o++){var s=this.context.createBiquadFilter();s.type="allpass",s.frequency.value=n[o],this._allpassFilters.push(s)}for(var r=0;r<e.length;r++){var a=new t.FeedbackCombFilter(e[r]);this._scaleRoomSize.connect(a.resonance),a.resonance.setValue(i[r]),this._allpassFilters[this._allpassFilters.length-1].connect(a),a.connect(r<e.length/2?this.effectReturnL:this.effectReturnR),this._feedbackCombFilters.push(a)}this.roomSize.connect(this._scaleRoomSize),this.chain.apply(this,this._allpassFilters),this.effectSendL.connect(this._allpassFilters[0]),this.effectSendR.connect(this._allpassFilters[0])},t.extend(t.JCReverb,t.StereoEffect),t.JCReverb.prototype.setRoomSize=function(t){this.roomSize.setValue(t)},t.JCReverb.prototype.set=function(e){this.isUndef(e.roomSize)||this.setRoomSize(e.roomSize),t.StereoEffect.prototype.set.call(this,e)},t.JCReverb.prototype.dispose=function(){t.StereoEffect.prototype.dispose.call(this);for(var e=0;e<this._allpassFilters.length;e++)this._allpassFilters[e].disconnect(),this._allpassFilters[e]=null;this._allpassFilters=null;for(var i=0;i<this._feedbackCombFilters.length;i++)this._feedbackCombFilters[i].dispose(),this._feedbackCombFilters[i]=null;this._feedbackCombFilters=null,this.roomSize.dispose(),this._scaleRoomSize.dispose(),this.roomSize=null,this._scaleRoomSize=null},t.JCReverb}),define("Tone/effect/StereoFeedbackEffect",["Tone/core/Tone","Tone/effect/StereoEffect","Tone/effect/FeedbackEffect"],function(t){return t.StereoFeedbackEffect=function(){var e=this.optionsObject(arguments,["feedback"],t.FeedbackEffect.defaults);t.StereoEffect.call(this,e),this.feedback=new t.Signal(e.feedback),this._half=new t.Multiply(.5),this._feedbackL=this.context.createGain(),this._feedbackR=this.context.createGain(),this.chain(this.effectReturnL,this._feedbackL,this.effectSendL),this.chain(this.effectReturnR,this._feedbackR,this.effectSendR),this.feedback.connect(this._half),this.fan(this._half,this._feedbackL.gain,this._feedbackR.gain)},t.extend(t.StereoFeedbackEffect,t.FeedbackEffect),t.StereoFeedbackEffect.prototype.dispose=function(){t.StereoEffect.prototype.dispose.call(this),this.feedback.dispose(),this._half.dispose(),this._feedbackL.disconnect(),this._feedbackR.disconnect(),this.feedback=null,this._feedbackL=null,this._feedbackR=null,this._half=null},t.StereoFeedbackEffect}),define("Tone/effect/Phaser",["Tone/core/Tone","Tone/component/LFO","Tone/effect/FeedbackEffect","Tone/component/Filter","Tone/effect/StereoFeedbackEffect"],function(t){return t.Phaser=function(){var e=this.optionsObject(arguments,["rate","depth","baseFrequency"],t.Phaser.defaults);t.StereoFeedbackEffect.call(this,e),this._lfoL=new t.LFO(e.rate,0,1),this._lfoR=new t.LFO(e.rate,0,1),this._lfoR.setPhase(180),this._baseFrequency=e.baseFrequency,this._depth=e.depth,this._filtersL=this._makeFilters(e.stages,this._lfoL,e.Q),this._filtersR=this._makeFilters(e.stages,this._lfoR,e.Q),this.effectSendL.connect(this._filtersL[0]),this.effectSendR.connect(this._filtersR[0]),this._filtersL[e.stages-1].connect(this.effectReturnL),this._filtersR[e.stages-1].connect(this.effectReturnR),this.effectSendL.connect(this.effectReturnL),this.effectSendR.connect(this.effectReturnR),this._lfoL.frequency.connect(this._lfoR.frequency),this.setBaseFrequency(e.baseFrequency),this.setDepth(e.depth),this.setRate(e.rate),this._lfoL.start(),this._lfoR.start()},t.extend(t.Phaser,t.StereoFeedbackEffect),t.Phaser.defaults={rate:.5,depth:1,stages:4,Q:6,baseFrequency:400,feedback:.6},t.Phaser.prototype._makeFilters=function(t,e,i){for(var n=new Array(t),o=0;t>o;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;e<this._filtersL.length;e++)this._filtersL[e].disconnect(),this._filtersL[e]=null;for(var e=0;e<this._filtersR.length;e++)this._filtersR[e].disconnect(),this._filtersR[e]=null;this._filtersL=null,this._filtersR=null,this._lfoL=null,this._lfoR=null},t.Phaser}),define("Tone/effect/PingPongDelay",["Tone/core/Tone","Tone/effect/StereoXFeedbackEffect","Tone/signal/Signal","Tone/signal/Multiply"],function(t){return t.PingPongDelay=function(){var e=this.optionsObject(arguments,["delayTime"],t.PingPongDelay.defaults);t.StereoXFeedbackEffect.call(this,e),this._leftDelay=this.context.createDelay(),this._rightDelay=this.context.createDelay(),this.delayTime=new t.Signal(0),this._timesTwo=new t.Multiply(2),this.chain(this.effectSendL,this._leftDelay,this.effectReturnL),this.chain(this.effectSendR,this._rightDelay,this.effectReturnR),this.delayTime.connect(this._leftDelay.delayTime),this.chain(this.delayTime,this._timesTwo,this._rightDelay.delayTime),this.setDelayTime(e.delayTime)},t.extend(t.PingPongDelay,t.StereoXFeedbackEffect),t.PingPongDelay.defaults={delayTime:.25},t.PingPongDelay.prototype.setDelayTime=function(t){this.delayTime.setValue(this.toSeconds(t))},t.PingPongDelay.prototype.set=function(e){this.isUndef(e.delayTime)||this.setDelayTime(e.delayTime),t.StereoXFeedbackEffect.prototype.set.call(this,e)},t.PingPongDelay.prototype.dispose=function(){t.StereoXFeedbackEffect.prototype.dispose.call(this),this._leftDelay.disconnect(),this._rightDelay.disconnect(),this._timesTwo.dispose(),this.delayTime.dispose(),this._leftDelay=null,this._rightDelay=null,this._timesTwo=null,this.delayTime=null},t.PingPongDelay}),define("Tone/instrument/Instrument",["Tone/core/Tone","Tone/source/Source","Tone/core/Note"],function(t){return t.Instrument=function(){this.output=this.context.createGain()},t.extend(t.Instrument),t.Instrument.prototype.triggerAttack=function(){},t.Instrument.prototype.triggerRelease=function(){},t.Instrument.prototype.triggerAttackRelease=function(t,e,i,n){i=this.toSeconds(i),e=this.toSeconds(e),this.triggerAttack(t,i,n),this.triggerRelease(i+e)},t.Instrument.prototype.setVolume=t.Source.prototype.setVolume,t.Instrument.prototype.dispose=function(){t.prototype.dispose.call(this)},t.Instrument}),define("Tone/instrument/Monophonic",["Tone/core/Tone","Tone/instrument/Instrument","Tone/signal/Signal"],function(t){return t.Monophonic=function(e){t.Instrument.call(this),e=this.defaultArg(e,t.Monophonic.defaults),this.portamento=e.portamento},t.extend(t.Monophonic,t.Instrument),t.Monophonic.defaults={portamento:0},t.Monophonic.prototype.triggerAttack=function(t,e,i){e=this.toSeconds(e),this.triggerEnvelopeAttack(e,i),this.setNote(t,e)},t.Monophonic.prototype.triggerRelease=function(t){this.triggerEnvelopeRelease(t)},t.Monophonic.prototype.triggerEnvelopeAttack=function(){},t.Monophonic.prototype.triggerEnvelopeRelease=function(){},t.Monophonic.prototype.setNote=function(t,e){if("string"==typeof t&&(t=this.noteToFrequency(t)),e=this.toSeconds(e),this.portamento>0){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;i<e.numberOfChannels;i++){var n,r,a,c,l,h,u,p=e.getChannelData(i);n=r=a=c=l=h=u=0;for(var f=0;s>f;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;i<e.numberOfChannels;i++)for(var n=e.getChannelData(i),r=0,a=0;s>a;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;i<e.numberOfChannels;i++)for(var n=e.getChannelData(i),r=0;s>r;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;i<e.polyphony;i++){var n=new e.voice(e.voiceOptions);this._voices[i]=n,n.connect(this.output)}this._freeVoices=this._voices.slice(0)},t.extend(t.PolySynth,t.Instrument),t.PolySynth.defaults={polyphony:4,voice:t.MonoSynth,voiceOptions:{portamento:0}},t.PolySynth.prototype.triggerAttack=function(t,e,i){var n=JSON.stringify(t);if(this._activeVoices[n])this._activeVoices[n].triggerAttack(t,e,i);else if(this._freeVoices.length>0){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;e<this._voices.length;e++)this._voices[e].set(t)},t.PolySynth.prototype.setPreset=function(t){for(var e=0;e<this._voices.length;e++)this._voices[e].setPreset(t)},t.PolySynth.prototype.dispose=function(){t.Instrument.prototype.dispose.call(this);for(var e=0;e<this._voices.length;e++)this._voices[e].dispose(),this._voices[e]=null;this._voices=null,this._activeVoices=null,this._freeVoices=null},t.PolySynth}),define("Tone/signal/Max",["Tone/core/Tone","Tone/signal/GreaterThan","Tone/signal/Select","Tone/signal/Signal"],function(t){return t.Max=function(e){t.call(this),this._maxSignal=new t.Signal(e),this._switch=new t.Select(2),this._gt=new t.GreaterThan(e),this._maxSignal.connect(this._switch,0,0),this.input.connect(this._switch,0,1),this.input.connect(this._gt),this._gt.connect(this._switch.gate),this._switch.connect(this.output)},t.extend(t.Max),t.Max.prototype.setMax=function(t){this._maxSignal.setValue(t)},t.Max.prototype.connect=t.Signal.prototype.connect,t.Max.prototype.dispose=function(){t.prototype.dispose.call(this),this._maxSignal.dispose(),this._switch.dispose(),this._gt.dispose(),this._maxSignal=null,this._switch=null,this._gt=null},t.Max}),define("Tone/signal/Min",["Tone/core/Tone","Tone/signal/LessThan","Tone/signal/Select","Tone/signal/Signal"],function(t){return t.Min=function(e){t.call(this),this._minSignal=new t.Signal(e),this._switch=new t.Select(2),this._lt=new t.LessThan(e),this._minSignal.connect(this._switch,0,0),this.input.connect(this._switch,0,1),this.input.connect(this._lt),this._lt.connect(this._switch.gate),this._switch.connect(this.output)},t.extend(t.Min),t.Min.prototype.setMin=function(t){this._minSignal.setValue(t)},t.Min.prototype.connect=t.Signal.prototype.connect,t.Min.prototype.dispose=function(){t.prototype.dispose.call(this),this._minSignal.dispose(),this._switch.dispose(),this._lt.dispose(),this._minSignal=null,this._switch=null,this._lt=null},t.Min}),define("Tone/signal/Clip",["Tone/core/Tone","Tone/signal/Max","Tone/signal/Min","Tone/signal/Signal"],function(t){return t.Clip=function(e,i){if(t.call(this),e>i){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;e<this.output.length;e++)this.output[e].dispose(),this.output[e]=null;t.prototype.dispose.call(this),this.gate=null};var e=function(e){this.selecter=new t.Equal(e),this.gate=this.input=this.output=this.context.createGain(),this.selecter.connect(this.gate.gain)};return t.extend(e),e.prototype.dispose=function(){t.prototype.dispose.call(this),this.selecter.dispose(),this.gate.disconnect(),this.selecter=null,this.gate=null},t.Route}),define("Tone/signal/Switch",["Tone/core/Tone","Tone/signal/Signal","Tone/signal/Threshold"],function(t){return t.Switch=function(){t.call(this),this.gate=new t.Signal(0),this._thresh=new t.Threshold(.5),this.input.connect(this.output),this.chain(this.gate,this._thresh,this.output.gain)},t.extend(t.Switch),t.Switch.prototype.open=function(t){this.gate.setValueAtTime(1,this.toSeconds(t))},t.Switch.prototype.close=function(t){this.gate.setValueAtTime(0,this.toSeconds(t))},t.Switch.prototype.connect=t.Signal.prototype.connect,t.Switch.prototype.dispose=function(){t.prototype.dispose.call(this),this.gate.dispose(),this._thresh.dispose(),this.gate=null,this._thresh=null},t.Switch}),define("Tone/source/Microphone",["Tone/core/Tone","Tone/source/Source"],function(t){return t.Microphone=function(e){t.Source.call(this),this._mediaStream=null,this._stream=null,this.constraints={audio:!0};var i=this;MediaStreamTrack.getSources(function(t){e<t.length&&(i.constraints.audio={optional:[{sourceId:t[e].id}]})})},t.extend(t.Microphone,t.Source),t.Microphone.prototype.start=function(){this.state===t.Source.State.STOPPED&&(this.state=t.Source.State.STARTED,navigator.getUserMedia(this.constraints,this._onStream.bind(this),this._onStreamError.bind(this)))},t.Microphone.prototype.stop=function(){this._stream&&this.state===t.Source.State.STARTED&&(this.state=t.Source.State.STOPPED,this._stream.stop())},t.Microphone.prototype._onStream=function(t){this._stream=t,this._mediaStream=this.context.createMediaStreamSource(t),this._mediaStream.connect(this.output)},t.Microphone.prototype._onStreamError=function(t){console.error(t)},t.Microphone.prototype.dispose=function(){t.Source.prototype.dispose.call(this),this._stream.disconnect(),this._mediaStream.disconnect(),this._stream=null,this._mediaStream=null},navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia,t.Microphone}),define("Tone/source/PulseOscillator",["Tone/core/Tone","Tone/source/Source","Tone/source/Oscillator","Tone/signal/Signal","Tone/signal/Threshold"],function(t){for(var e=new Float32Array(256),i=0;128>i;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}) |