mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-17 09:08:10 +00:00
11 lines
No EOL
92 KiB
JavaScript
11 lines
No EOL
92 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={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},s=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],r=261.6255653005986;i.prototype.noteToFrequency=function(t){var e=t.split(/(\d+)/);if(3===e.length){var i=o[e[0].toLowerCase()],n=e[1],s=i+12*parseInt(n,10);return Math.pow(2,(s-48)/12)*r}return 0},i.prototype.frequencyToNote=function(t){var e=Math.log(t/r)/Math.LN2,i=Math.round(12*e)+48,n=Math.floor(i/12),o=s[i%12];return o+n.toString()};var a=[];return i._initAudioContext=function(t){t(i.context),a.push(t)},i.setContext=function(t){i.prototype.context=t,i.context=t;for(var e=0;e<a.length;e++)a[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 r1-dev"),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(){this.output.disconnect(),this._scalar.disconnect(),this.output=null,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/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(){this._value.dispose(),this.output.disconnect(),this._value=null,this.output=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(){this.input.disconnect(),this.input=null},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(){this.input.disconnect(),this.output.disconnect(),this._plusInput.dispose(),this._plusOutput.dispose(),this._scale.dispose(),this.input=null,this.output=null,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.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.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.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.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(){for(var t=0;t<this._filters.length;t++)this._filters[t].disconnect(),this._filters[t]=null;this.frequency.dispose(),this.Q.dispose(),this.gain.dispose(),this._filters=null,this.frequency=null,this.Q=null,this.gain=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.lowGain.gain.value=e.low,this.midGain=this.context.createGain(),this.midGain.gain.value=e.mid,this.highGain=this.context.createGain(),this.highGain.gain.value=e.high,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)},t.extend(t.EQ),t.EQ.defaults={low:1,mid:1,high:1,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=t},t.EQ.prototype.setHigh=function(t){this.highGain.gain.value=t},t.EQ.prototype.setLow=function(t){this.lowGain.gain.value=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/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.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/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,1)},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(){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(){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(){this._equals.disconnect(),this._adder.dispose(),this._equals=null,this._adder=null},t.Equal}),define("Tone/signal/Selector",["Tone/core/Tone","Tone/signal/Equal","Tone/signal/Signal"],function(t){t.Selector=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.Selector),t.Selector.prototype.select=function(t,e){t=Math.floor(t),this.gate.setValueAtTime(t,this.toSeconds(e))},t.Selector.prototype.connect=t.Signal.prototype.connect,t.Selector.prototype.dispose=function(){this.output.disconnect(),this.gate.dispose();for(var t=0;t<this.input.length;t++)this.input[t].dispose(),this.input[t]=null;this.gate=null,this.output=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(){this.selecter.dispose(),this.gate.disconnect(),this.selecter=null,this.gate=null},t.Selector}),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(){this.input.disconnect(),this.input=null},t.Negate}),define("Tone/signal/LessThan",["Tone/core/Tone","Tone/signal/Threshold","Tone/signal/Add","Tone/signal/Signal"],function(t){return t.LessThan=function(e){this._lt=this.context.createWaveShaper(),this._thresh=new t.Threshold(.5),this._adder=new t.Add(this.defaultArg(-e,0)),this.input=this._adder,this.output=this._thresh,this.chain(this._adder,this._lt,this._thresh),this._setLessThanZero()},t.extend(t.LessThan),t.LessThan.prototype._setLessThanZero=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._lt.curve=e},t.LessThan.prototype.setValue=function(t){this._adder.setValue(-t)},t.LessThan.prototype.connect=t.Signal.prototype.connect,t.LessThan.prototype.dispose=function(){this._lt.disconnect(),this._adder.disconnect(),this._thresh.dispose(),this._lt=null,this._adder=null,this._thresh=null},t.LessThan}),define("Tone/signal/Abs",["Tone/core/Tone","Tone/signal/Selector","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.Selector(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/Threshold","Tone/signal/Add","Tone/signal/Signal"],function(t){return t.GreaterThan=function(e){this._gt=this.context.createWaveShaper(),this._thresh=new t.Threshold(.001),this._adder=new t.Add(this.defaultArg(-e,0)),this.input=this._adder,this.output=this._thresh,this.chain(this._adder,this._gt,this._thresh),this._setGreaterThanZero()},t.extend(t.GreaterThan),t.GreaterThan.prototype._setGreaterThanZero=function(){for(var t=1023,e=new Float32Array(t),i=0;t>i;i++){var n=i/(t-1)*2-1;e[i]=n>0?1:0}this._gt.curve=e},t.GreaterThan.prototype.setValue=function(t){this._adder.setValue(-t)},t.GreaterThan.prototype.connect=t.Signal.prototype.connect,t.GreaterThan.prototype.dispose=function(){this._gt.disconnect(),this._adder.disconnect(),this._thresh.dispose(),this._gt=null,this._adder=null,this._thresh=null},t.GreaterThan}),define("Tone/component/Gate",["Tone/core/Tone","Tone/component/Follower","Tone/signal/GreaterThan"],function(t){return t.Gate=function(e,i){t.call(this),e=this.defaultArg(e,-40),i=this.defaultArg(i,.1),this._follower=new t.Follower(i),this._gt=new t.GreaterThan(this.dbToGain(e)),this.chain(this.input,this.output),this.chain(this.input,this._follower,this._gt,this.output.gain)},t.extend(t.Gate),t.Gate.prototype.setThreshold=function(t){this._gt.setValue(this.dbToGain(t))},t.Gate.prototype.setSmoothTime=function(t){this._follower.setSmoothTime(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)},t.Clock.prototype.stop=function(t){var e=this.toSeconds(t);this._oscillator.stop(e)},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=0;i>s;s++){var r=n[s];r>0&&!o?(o=!0,this.tick(e+this.samplesToSeconds(s))):0>r&&o&&(o=!1)}this._upTick=o},t.Clock.prototype.dispose=function(){this._jsNode.disconnect(),this._controlSignal.dispose(),this._oscillator&&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){var Transport=function(){this._clock=new Tone.Clock(1,this._processTick.bind(this)),this.loop=!1,this.state=TransportState.STOPPED};Tone.extend(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"};Transport.prototype._processTick=function(t){processIntervals(t),processTimeouts(t),processTimeline(t),transportTicks+=1,timelineTicks+=1,this.loop&&timelineTicks===loopEnd&&this._setTicks(loopStart)},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)n.doCallback(t),timelineProgress=e;else if(o>timelineTicks)break}};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},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},Transport.prototype.clearIntervals=function(){intervals=[]},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},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},Transport.prototype.clearTimeouts=function(){timeouts=[]},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},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},Transport.prototype.clearTimelines=function(){timelineProgress=0,transportTimeline=[]},Transport.prototype.toTicks=function(t){var e=this.toSeconds(t),i=this.notationToSeconds("4n"),n=e/i,o=n*tatum;return Math.round(o)},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(":")},Transport.prototype.setTransportTime=function(t){var e=this.toTicks(t);this._setTicks(e)},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)}}},Transport.prototype.stop=function(t){if(this.state===TransportState.STARTED||this.state===TransportState.PAUSED){this.state=TransportState.STOPPED;var e=this.toSeconds(t);this._clock.stop(e),this._setTicks(0),this.clearTimeouts();
|
|
for(var i=0;i<SyncedSources.length;i++){var n=SyncedSources[i].source;n.stop(e)}}},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)}}},Transport.prototype.setBpm=function(t,e){var i=this.notationToSeconds(tatum.toString()+"n",t,transportTimeSignature)/4;this._clock.setRate(i,e)},Transport.prototype.getBpm=function(){var t=this._clock.getRate();return 60*(t/tatum)},Transport.prototype.setTimeSignature=function(t,e){e=this.defaultArg(e,4),transportTimeSignature=t/(e/4)},Transport.prototype.getTimeSignature=function(){return transportTimeSignature},Transport.prototype.setLoopStart=function(t){loopStart=this.toTicks(t)},Transport.prototype.setLoopEnd=function(t){loopEnd=this.toTicks(t)},Transport.prototype.setLoopPoints=function(t,e){this.setLoopStart(t),this.setLoopEnd(e)},Transport.prototype.syncSource=function(t,e){SyncedSources.push({source:t,delay:this.toSeconds(this.defaultArg(e,0))})},Transport.prototype.unsyncSource=function(t){for(var e=0;e<SyncedSources.length;e++)SyncedSources[e].source===t&&SyncedSources.splice(e,1)},Transport.prototype.syncSignal=function(){};var TimelineEventIDCounter=0,TimelineEvent=function(t,e,i,n){this.startTicks=n,this.tickTime=i,this.callback=t,this.context=e,this.id=TimelineEventIDCounter++};return 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},Transport.prototype.dispose=function(){this._clock.dispose(),this._clock=null},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=parseInt(t);var n=this.notationToSeconds("4n",e,i);return 4*n/(tatum/t)},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){console.log("problem evaluating Tone.Time: "+oringalTime),time=0}}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},Tone.Transport=new Transport,Tone.Transport.setBpm(120),Tone._initAudioContext(function(){var t=Tone.Transport.getBpm();Tone.Transport._clock=new Tone.Clock(1,Tone.Transport._processTick.bind(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 h=this.context.createPeriodicWave(n,o);this._wave=h,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(){this.oscillator.dispose(),this._scaler.dispose(),this.oscillator=null,this.frequency=null,this.output=null},t.LFO}),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){var e=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)};return t.extend(e),e.prototype.mute=function(t){t=this.defaultArg(t,!0),this.output.gain.value=t?0:1},e.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)},t.Master=new e,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,h=0;e>h;h++)o=s[h],!c&&o>.95&&(c=!0,this._lastClip=Date.now()),a+=o,r+=o*o;var l=a/e,u=Math.sqrt(r/e);this._volume[n]=Math.max(u,this._volume[n]*i),this._values[n]=l}},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/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},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 h=c-e;s[r][h+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={};return 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(!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],h=a.slice(1);r=new t.Note(n,c,h)}else r=new t.Note(n,a);i.push(r)}}return i},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/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(){this.input.disconnect(),this.output.disconnect(),this._plusInput.dispose(),this._plusOutput.dispose(),this._normalize.dispose(),this._scale.dispose(),this.input=null,this.output=null,this._plusInput=null,this._plusOutput=null,this._scale=null},t.ScaleExp}),define("Tone/effect/AutoWah",["Tone/core/Tone","Tone/component/Follower","Tone/signal/ScaleExp","Tone/effect/Effect"],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/effect/BitCrusher",["Tone/core/Tone","Tone/effect/Effect"],function(t){return t.BitCrusher=function(){var e=this.optionsObject(arguments,["bits","frequency"],t.BitCrusher.defaults);t.Effect.call(this,e),this._bits=this.defaultArg(e.bits,8),this._frequency=this.defaultArg(e.frequency,.5),this._step=2*Math.pow(.5,this._bits),this._invStep=1/this._step,this._phasor=0,this._last=0,this._crusher=this.context.createScriptProcessor(this.bufferSize,1,1),this._crusher.onaudioprocess=this._audioprocess.bind(this),this.connectEffect(this._crusher)},t.extend(t.BitCrusher,t.Effect),t.BitCrusher.defaults={bits:8,frequency:.5},t.BitCrusher.prototype._audioprocess=function(t){for(var e=this._phasor,i=this._frequency,n=this._invStep,o=this._last,s=this._step,r=t.inputBuffer.getChannelData(0),a=t.outputBuffer.getChannelData(0),c=0,h=a.length;h>c;c++)e+=i,e>=1&&(e-=1,o=s*(r[c]*n|.5)),a[c]=o;this._phasor=e,this._last=o},t.BitCrusher.prototype.setBits=function(t){this._bits=t,this._step=2*Math.pow(.5,this._bits),this._invStep=1/this._step},t.BitCrusher.prototype.setFrequency=function(t){this._frequency=t},t.BitCrusher.prototype.set=function(e){this.isUndef(e.frequency)||this.setFrequency(e.frequency),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._crusher.disconnect(),this._crusher=null},t.BitCrusher}),define("Tone/effect/StereoEffect",["Tone/core/Tone","Tone/effect/Effect","Tone/component/Split","Tone/component/Merge"],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.Merge,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,0,0),this.input.connect(this._mono,0,1),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/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/Monophonic",["Tone/core/Tone","Tone/source/Source","Tone/signal/Signal"],function(t){return t.Monophonic=function(e){e=this.defaultArg(e,t.Monophonic.defaults),this.output=this.context.createGain(),this.portamento=e.portamento},t.extend(t.Monophonic),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.triggerAttackRelease=function(t,e,i,n){i=this.toSeconds(i),this.triggerAttack(t,i,n),this.triggerRelease(i+this.toSeconds(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.setVolume=t.Source.prototype.setVolume,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.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:10,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.detune.dispose(),this._unison.dispose(),this.oscillator=null,this.filterEnvelope=null,this.envelope=null,this.filter=null,this.detune=null,this._unison=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.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.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/Envelope","Tone/component/Filter"],function(t){return t.Sampler=function(){var e=this.optionsObject(arguments,["url","load"],t.Sampler.defaults);this.output=this.context.createGain(),this.player=new t.Player(e.url,e.load),this.player.retrigger=!0,this.envelope=new t.Envelope(e.envelope),this.filterEnvelope=new t.Envelope(e.filterEnvelope),this.filter=new t.Filter(e.filter),this.chain(this.player,this.filter,this.output),this.envelope.connect(this.player.output.gain),this.filterEnvelope.connect(this.filter.frequency)},t.extend(t.Sampler),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:0,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){this.player.start(t),this.envelope.triggerAttack(t,e),this.filterEnvelope.triggerAttack(t)},t.Sampler.prototype.triggerRelease=function(t){this.filterEnvelope.triggerRelease(t),this.envelope.triggerRelease(t)},t.Sampler.prototype.dispose=function(){t.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/source/Source"],function(t){return t.MultiSampler=function(t,e){this.output=this.context.createGain(),this.samples={},this._createSamples(t,e)},t.extend(t.MultiSampler),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){this.samples.hasOwnProperty(t)&&this.samples[t].triggerAttack(e)},t.MultiSampler.prototype.triggerRelease=function(t,e){this.samples.hasOwnProperty(t)&&this.samples[t].triggerRelease(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.dispose=function(){t.prototype.dispose.call(this);for(var e in this.samples)this.samples[e].dispose(),this.samples[e]=null},t.MultiSampler}),define("Tone/instrument/PolySynth",["Tone/core/Tone","Tone/instrument/MonoSynth","Tone/source/Source"],function(t){return t.PolySynth=function(){var e=this.optionsObject(arguments,["polyphony","voice","voiceOptions"],t.PolySynth.defaults);this.output=this.context.createGain(),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.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),this._activeVoices[n]=o}},t.PolySynth.prototype.triggerAttackRelease=function(t,e,i,n){i=this.toSeconds(i),this.triggerAttack(t,i,n),this.triggerRelease(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.setVolume=t.Source.prototype.setVolume,t.PolySynth.prototype.dispose=function(){t.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/Selector","Tone/signal/Signal"],function(t){return t.Max=function(e){t.call(this),this._maxSignal=new t.Signal(e),this._switch=new t.Selector(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(){this.input.disconnect(),this.output.disconnect(),this._maxSignal.dispose(),this._switch.dispose(),this._gt.dispose(),this.input=null,this.output=null,this._maxSignal=null,this._switch=null,this._gt=null},t.Max}),define("Tone/signal/Min",["Tone/core/Tone","Tone/signal/LessThan","Tone/signal/Selector","Tone/signal/Signal"],function(t){return t.Min=function(e){t.call(this),this._minSignal=new t.Signal(e),this._switch=new t.Selector(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(){this.input.disconnect(),this.output.disconnect(),this._minSignal.dispose(),this._switch.dispose(),this._lt.dispose(),this.input=null,this.output=null,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(){this._min.dispose(),this._max.dispose(),this.input.disconnect(),this.output.disconnect(),this._min=null,this._max=null,this.input=null,this.output=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.input.disconnect(),this.gate.dispose();for(var t=0;t<this.output.length;t++)this.output[t].dispose(),this.output[t]=null;this.gate=null,this.input=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(){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),this.output.gain.value=0},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.signal=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/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,h,l,u,p=e.getChannelData(i);n=r=a=c=h=l=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,h=.55*h+.5329522*d,l=-.7616*l-.016898*d,p[f]=n+r+a+c+h+l+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/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(){this._sawtooth.dispose(),this._sawtooth=null,this.width.dispose(),this.width=null},t.PulseOscillator}) |