mirror of
https://github.com/Tonejs/Tone.js
synced 2025-01-09 02:18:57 +00:00
11 lines
No EOL
143 KiB
JavaScript
11 lines
No EOL
143 KiB
JavaScript
!function(root){"use strict";function ToneCore(a){Tone=a()}function ToneModule(a){a(Tone)}var Tone;/**
|
|
* Tone.js
|
|
* @author Yotam Mann
|
|
* @license http://opensource.org/licenses/MIT MIT License
|
|
* @copyright 2014-2015 Yotam Mann
|
|
*/
|
|
ToneCore(function(){function a(a){return void 0===a}function b(a){return"function"==typeof a}var c,d,e,f;if(a(window.AudioContext)&&(window.AudioContext=window.webkitAudioContext),a(window.OfflineAudioContext)&&(window.OfflineAudioContext=window.webkitOfflineAudioContext),a(AudioContext))throw new Error("Web Audio is not supported in this browser");return c=new AudioContext,b(AudioContext.prototype.createGain)||(AudioContext.prototype.createGain=AudioContext.prototype.createGainNode),b(AudioContext.prototype.createDelay)||(AudioContext.prototype.createDelay=AudioContext.prototype.createDelayNode),b(AudioContext.prototype.createPeriodicWave)||(AudioContext.prototype.createPeriodicWave=AudioContext.prototype.createWaveTable),b(AudioBufferSourceNode.prototype.start)||(AudioBufferSourceNode.prototype.start=AudioBufferSourceNode.prototype.noteGrainOn),b(AudioBufferSourceNode.prototype.stop)||(AudioBufferSourceNode.prototype.stop=AudioBufferSourceNode.prototype.noteOff),b(OscillatorNode.prototype.start)||(OscillatorNode.prototype.start=OscillatorNode.prototype.noteOn),b(OscillatorNode.prototype.stop)||(OscillatorNode.prototype.stop=OscillatorNode.prototype.noteOff),b(OscillatorNode.prototype.setPeriodicWave)||(OscillatorNode.prototype.setPeriodicWave=OscillatorNode.prototype.setWaveTable),AudioNode.prototype._nativeConnect=AudioNode.prototype.connect,AudioNode.prototype.connect=function(b,c,d){if(b.input)Array.isArray(b.input)?(a(d)&&(d=0),this.connect(b.input[d])):this.connect(b.input,c,d);else try{b instanceof AudioNode?this._nativeConnect(b,c,d):this._nativeConnect(b,c)}catch(e){throw new Error("error connecting to node: "+b)}},d=function(b,c){a(b)||1===b?this.input=this.context.createGain():b>1&&(this.input=new Array(b)),a(c)||1===c?this.output=this.context.createGain():c>1&&(this.output=new Array(b))},d.prototype.set=function(b,c,e){var f,g,h;"object"==typeof b?e=c:"string"==typeof b&&(f={},f[b]=c,b=f);for(g in b)h=this[g],a(h)||(c=b[g],h instanceof d.Signal?h.value!==c&&(a(e)?h.value=c:h.rampTo(c,e)):h instanceof AudioParam?h.value!==c&&(h.value=c):h instanceof d?h.set(c):h!==c&&(this[g]=c));return this},d.prototype.get=function(c){var e,f,g,h,i,j;if(a(c))c=this._collectDefaults(this.constructor);else if("string"==typeof c)e={},e[c]=0,c=e;else if(Array.isArray(c)){for(f={},g=0;g<c.length;g++)f[c[g]]=0;c=f}h={};for(i in c)j=this[i],"object"==typeof c[i]?h[i]=j.get(c[i]):j instanceof d.Signal?h[i]=j.value:j instanceof AudioParam?h[i]=j.value:j instanceof d?h[i]=j.get():b(j)||a(j)||(h[i]=j);return h},d.prototype._collectDefaults=function(b){var c,d,e={};if(a(b.defaults)||(e=b.defaults),!a(b._super)){c=this._collectDefaults(b._super);for(d in c)e[d]=c[d]}return e},d.prototype.setPreset=function(a){return!this.isUndef(this.preset)&&this.preset.hasOwnProperty(a)&&this.set(this.preset[a]),this},d.prototype.toString=function(){var a,c,e;for(a in d)if(c=a[0].match(/^[A-Z]$/),e=d[a]===this.constructor,b(d[a])&&c&&e)return a;return"Tone"},d.context=c,d.prototype.context=d.context,d.prototype.bufferSize=2048,d.prototype.bufferTime=d.prototype.bufferSize/d.context.sampleRate,d.prototype.dispose=function(){return 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),this},e=null,d.prototype.noGC=function(){return this.output.connect(e),this},AudioNode.prototype.noGC=function(){return this.connect(e),this},d.prototype.connect=function(a,b,c){return Array.isArray(this.output)?(b=this.defaultArg(b,0),this.output[b].connect(a,0,c)):this.output.connect(a,b,c),this},d.prototype.disconnect=function(a){return Array.isArray(this.output)?(a=this.defaultArg(a,0),this.output[a].disconnect()):this.output.disconnect(),this},d.prototype.connectSeries=function(){var a,b,c;if(arguments.length>1)for(a=arguments[0],b=1;b<arguments.length;b++)c=arguments[b],a.connect(c),a=c;return this},d.prototype.connectParallel=function(){var a,b,c=arguments[0];if(arguments.length>1)for(a=1;a<arguments.length;a++)b=arguments[a],c.connect(b);return this},d.prototype.chain=function(){var a,b,c;if(arguments.length>0)for(a=this,b=0;b<arguments.length;b++)c=arguments[b],a.connect(c),a=c;return this},d.prototype.fan=function(){if(arguments.length>0)for(var a=0;a<arguments.length;a++)this.connect(arguments[a]);return this},AudioNode.prototype.chain=d.prototype.chain,AudioNode.prototype.fan=d.prototype.fan,d.prototype.defaultArg=function(b,c){var d,e,f;if("object"==typeof b&&"object"==typeof c){d={};for(e in b)d[e]=this.defaultArg(b[e],b[e]);for(f in c)d[f]=this.defaultArg(b[f],c[f]);return d}return a(b)?c:b},d.prototype.optionsObject=function(a,b,c){var d,e={};if(1===a.length&&"object"==typeof a[0])e=a[0];else for(d=0;d<b.length;d++)e[b[d]]=a[d];return this.isUndef(c)?e:this.defaultArg(e,c)},d.prototype.isUndef=a,d.prototype.isFunction=b,d.prototype._readOnly=function(a){if(Array.isArray(a))for(var b=0;b<a.length;b++)this._readOnly(a[b]);else Object.defineProperty(this,a,{writable:!1,enumerable:!0})},d.prototype._writable=function(a){if(Array.isArray(a))for(var b=0;b<a.length;b++)this._writable(a[b]);else Object.defineProperty(this,a,{writable:!0})},d.prototype.equalPowerScale=function(a){var b=.5*Math.PI;return Math.sin(a*b)},d.prototype.dbToGain=function(a){return Math.pow(2,a/6)},d.prototype.gainToDb=function(a){return 20*(Math.log(a)/Math.LN10)},d.prototype.now=function(){return this.context.currentTime},d.prototype.samplesToSeconds=function(a){return a/this.context.sampleRate},d.prototype.toSamples=function(a){var b=this.toSeconds(a);return Math.round(b*this.context.sampleRate)},d.prototype.toSeconds=function(a,b){if(b=this.defaultArg(b,this.now()),"number"==typeof a)return a;if("string"==typeof a){var c=0;return"+"===a.charAt(0)&&(a=a.slice(1),c=b),parseFloat(a)+c}return b},d.prototype.isFrequency=function(){var a=new RegExp(/\d*\.?\d+hz$/i);return function(b){return a.test(b)}}(),d.prototype.frequencyToSeconds=function(a){return 1/parseFloat(a)},d.prototype.secondsToFrequency=function(a){return 1/a},d.extend=function(b,c){function e(){}a(c)&&(c=d),e.prototype=c.prototype,b.prototype=new e,b.prototype.constructor=b,b._super=c},f=[],d._initAudioContext=function(a){a(d.context),f.push(a)},d.setContext=function(a){d.prototype.context=a,d.context=a;for(var b=0;b<f.length;b++)f[b](a)},d.startMobile=function(){var a,b=d.context.createOscillator(),c=d.context.createGain();c.gain.value=0,b.connect(c),c.connect(d.context.destination),a=d.context.currentTime,b.start(a),b.stop(a+1)},d._initAudioContext(function(a){d.prototype.bufferTime=d.prototype.bufferSize/a.sampleRate,e=a.createGain(),e.gain.value=0,e.connect(a.destination)}),console.log("%c * Tone.js r5-dev * ","background: #000; color: #fff"),d}),ToneModule(function(a){return a.SignalBase=function(){},a.extend(a.SignalBase),a.SignalBase.prototype.connect=function(b,c,d){return b.constructor===a.Signal?(b._value.cancelScheduledValues(0),b._value.value=0,b.overridden=!0):b instanceof AudioParam&&(b.cancelScheduledValues(0),b.value=0),a.prototype.connect.call(this,b,c,d),this},a.SignalBase}),ToneModule(function(a){return a.WaveShaper=function(a,b){this._shaper=this.input=this.output=this.context.createWaveShaper(),this._curve=null,Array.isArray(a)?this.curve=a:isFinite(a)||this.isUndef(a)?this._curve=new Float32Array(this.defaultArg(a,1024)):this.isFunction(a)&&(this._curve=new Float32Array(this.defaultArg(b,1024)),this.setMap(a))},a.extend(a.WaveShaper,a.SignalBase),a.WaveShaper.prototype.setMap=function(a){var b,c,d;for(b=0,c=this._curve.length;c>b;b++)d=b/c*2-1,this._curve[b]=a(d,b);return this._shaper.curve=this._curve,this},Object.defineProperty(a.WaveShaper.prototype,"curve",{get:function(){return this._shaper.curve},set:function(a){if(this._isSafari()){var b=a[0];a.unshift(b)}this._curve=new Float32Array(a),this._shaper.curve=this._curve}}),Object.defineProperty(a.WaveShaper.prototype,"oversample",{get:function(){return this._shaper.oversample},set:function(a){this._shaper.oversample=a}}),a.WaveShaper.prototype._isSafari=function(){var a=navigator.userAgent.toLowerCase();return-1!==a.indexOf("safari")&&-1===a.indexOf("chrome")},a.WaveShaper.prototype.dispose=function(){return a.prototype.dispose.call(this),this._shaper.disconnect(),this._shaper=null,this._curve=null,this},a.WaveShaper}),ToneModule(function(a){return a.Signal=function(b,c){this.units=this.defaultArg(c,a.Signal.Units.Number),this.convert=!0,this.overridden=!1,this.output=this._scaler=this.context.createGain(),this.input=this._value=this._scaler.gain,b instanceof AudioParam?(this._scaler.connect(b),b.value=0):this.value=this.defaultArg(b,a.Signal.defaults.value),a.Signal._constant.chain(this._scaler)},a.extend(a.Signal,a.SignalBase),a.Signal.defaults={value:0},Object.defineProperty(a.Signal.prototype,"value",{get:function(){return this._toUnits(this._value.value)},set:function(a){var b=this._fromUnits(a);this.cancelScheduledValues(0),this._value.value=b}}),a.Signal.prototype._fromUnits=function(b){if(!this.convert)return b;switch(this.units){case a.Signal.Units.Time:return this.toSeconds(b);case a.Signal.Units.Frequency:return this.toFrequency(b);case a.Signal.Units.Decibels:return this.dbToGain(b);case a.Signal.Units.Normal:return Math.min(Math.max(b,0),1);case a.Signal.Units.Audio:return Math.min(Math.max(b,-1),1);default:return b}},a.Signal.prototype._toUnits=function(b){if(!this.convert)return b;switch(this.units){case a.Signal.Units.Decibels:return this.gainToDb(b);default:return b}},a.Signal.prototype.setValueAtTime=function(a,b){return a=this._fromUnits(a),this._value.setValueAtTime(a,this.toSeconds(b)),this},a.Signal.prototype.setCurrentValueNow=function(a){a=this.defaultArg(a,this.now());var b=this._value.value;return this.cancelScheduledValues(a),this._value.setValueAtTime(b,a),this},a.Signal.prototype.linearRampToValueAtTime=function(a,b){return a=this._fromUnits(a),this._value.linearRampToValueAtTime(a,this.toSeconds(b)),this},a.Signal.prototype.exponentialRampToValueAtTime=function(a,b){return a=this._fromUnits(a),a=Math.max(1e-5,a),this._value.exponentialRampToValueAtTime(a,this.toSeconds(b)),this},a.Signal.prototype.exponentialRampToValueNow=function(a,b){var c=this.now(),d=this.value;return this.setValueAtTime(Math.max(d,1e-4),c),this.exponentialRampToValueAtTime(a,c+this.toSeconds(b)),this},a.Signal.prototype.linearRampToValueNow=function(a,b){var c=this.now();return this.setCurrentValueNow(c),this.linearRampToValueAtTime(a,c+this.toSeconds(b)),this},a.Signal.prototype.setTargetAtTime=function(a,b,c){return a=this._fromUnits(a),c=Math.max(1e-5,c),this._value.setTargetAtTime(a,this.toSeconds(b),c),this},a.Signal.prototype.setValueCurveAtTime=function(a,b,c){for(var d=0;d<a.length;d++)a[d]=this._fromUnits(a[d]);return this._value.setValueCurveAtTime(a,this.toSeconds(b),this.toSeconds(c)),this},a.Signal.prototype.cancelScheduledValues=function(a){return this._value.cancelScheduledValues(this.toSeconds(a)),this},a.Signal.prototype.rampTo=function(b,c){return c=this.defaultArg(c,0),this.units===a.Signal.Units.Frequency||this.units===a.Signal.Units.BPM?this.exponentialRampToValueNow(b,c):this.linearRampToValueNow(b,c),this},a.Signal.prototype.dispose=function(){return a.prototype.dispose.call(this),this._value=null,this._scaler=null,this},a.Signal.Units={Number:"number",Time:"time",Frequency:"frequency",Gain:"gain",Normal:"normal",Audio:"audio",Decibels:"db",Interval:"interval",BPM:"bpm",Positive:"positive"},a.Signal._generator=null,a.Signal._constant=null,a._initAudioContext(function(b){a.Signal._generator=b.createOscillator(),a.Signal._constant=new a.WaveShaper([1,1]),a.Signal._generator.connect(a.Signal._constant),a.Signal._generator.start(0),a.Signal._generator.noGC()}),a.Signal}),ToneModule(function(a){return a.Pow=function(b){this._exp=this.defaultArg(b,1),this._expScaler=this.input=this.output=new a.WaveShaper(this._expFunc(this._exp),8192)},a.extend(a.Pow,a.SignalBase),Object.defineProperty(a.Pow.prototype,"value",{get:function(){return this._exp},set:function(a){this._exp=a,this._expScaler.setMap(this._expFunc(this._exp))}}),a.Pow.prototype._expFunc=function(a){return function(b){return Math.pow(Math.abs(b),a)}},a.Pow.prototype.dispose=function(){return a.prototype.dispose.call(this),this._expScaler.dispose(),this._expScaler=null,this},a.Pow}),ToneModule(function(a){return a.Envelope=function(){var b=this.optionsObject(arguments,["attack","decay","sustain","release"],a.Envelope.defaults);this.attack=b.attack,this.decay=b.decay,this.sustain=b.sustain,this.release=b.release,this._nextAttack=1/0,this._nextDecay=1/0,this._nextSustain=1/0,this._nextRelease=1/0,this._nextStandby=1/0,this._attackCurve=a.Envelope.Type.LINEAR,this._peakValue=1,this._minOutput=1e-4,this._sig=this.output=new a.Signal(0),this.attackCurve=b.attackCurve},a.extend(a.Envelope),a.Envelope.defaults={attack:.01,decay:.1,sustain:.5,release:1,attackCurve:"linear"},a.Envelope.prototype._timeMult=.25,Object.defineProperty(a.Envelope.prototype,"attackCurve",{get:function(){return this._attackCurve},set:function(b){if(b!==a.Envelope.Type.LINEAR&&b!==a.Envelope.Type.EXPONENTIAL)throw Error('attackCurve must be either "linear" or "exponential". Invalid type: ',b);this._attackCurve=b}}),a.Envelope.prototype._phaseAtTime=function(b){return this._nextRelease>b?this._nextAttack<=b&&this._nextDecay>b?a.Envelope.Phase.ATTACK:this._nextDecay<=b&&this._nextSustain>b?a.Envelope.Phase.DECAY:this._nextSustain<=b&&this._nextRelease>b?a.Envelope.Phase.SUSTAIN:a.Envelope.Phase.STANDBY:this._nextRelease<b&&this._nextStandby>b?a.Envelope.Phase.RELEASE:a.Envelope.Phase.STANDBY},a.Envelope.prototype._exponentialApproach=function(a,b,c,d,e){return c+(b-c)*Math.exp(-(e-a)/d)},a.Envelope.prototype._linearInterpolate=function(a,b,c,d,e){return b+(d-b)*((e-a)/(c-a))},a.Envelope.prototype._exponentialInterpolate=function(a,b,c,d,e){return b*Math.pow(d/b,(e-a)/(c-a))},a.Envelope.prototype._valueAtTime=function(b){var c=this.toSeconds(this.attack),d=this.toSeconds(this.decay),e=this.toSeconds(this.release);switch(this._phaseAtTime(b)){case a.Envelope.Phase.ATTACK:return this._attackCurve===a.Envelope.Type.LINEAR?this._linearInterpolate(this._nextAttack,this._minOutput,this._nextAttack+c,this._peakValue,b):this._exponentialInterpolate(this._nextAttack,this._minOutput,this._nextAttack+c,this._peakValue,b);case a.Envelope.Phase.DECAY:return this._exponentialApproach(this._nextDecay,this._peakValue,this.sustain*this._peakValue,d*this._timeMult,b);case a.Envelope.Phase.RELEASE:return this._exponentialApproach(this._nextRelease,this._peakValue,this._minOutput,e*this._timeMult,b);case a.Envelope.Phase.SUSTAIN:return this.sustain*this._peakValue;case a.Envelope.Phase.STANDBY:return this._minOutput}},a.Envelope.prototype.triggerAttack=function(b,c){var d,e,f,g,h,i;return b=this.toSeconds(b),d=this.toSeconds(this.attack),e=this.toSeconds(this.decay),f=this._valueAtTime(b),g=f*d,this._nextAttack=b-g,this._nextDecay=this._nextAttack+d,this._nextSustain=this._nextDecay+e,this._nextRelease=1/0,this._peakValue=this.defaultArg(c,1),h=this._peakValue,i=this.sustain*h,this._sig.cancelScheduledValues(b),this._sig.setValueAtTime(f,b),this._attackCurve===a.Envelope.Type.LINEAR?this._sig.linearRampToValueAtTime(h,this._nextDecay):this._sig.exponentialRampToValueAtTime(h,this._nextDecay),this._sig.setTargetAtTime(i,this._nextDecay,e*this._timeMult),this},a.Envelope.prototype.triggerRelease=function(b){var c,d,e;return b=this.toSeconds(b),c=this._phaseAtTime(b),d=this.toSeconds(this.release),e=this._valueAtTime(b),this._peakValue=e,this._nextRelease=b,this._nextStandby=this._nextRelease+d,this._sig.cancelScheduledValues(this._nextRelease),c===a.Envelope.Phase.ATTACK?(this._sig.setCurrentValueNow(),this.attackCurve===a.Envelope.Type.LINEAR?this._sig.linearRampToValueAtTime(this._peakValue,this._nextRelease):this._sig.exponentialRampToValueAtTime(this._peakValue,this._nextRelease)):this._sig.setValueAtTime(this._peakValue,this._nextRelease),this._sig.setTargetAtTime(this._minOutput,this._nextRelease,d*this._timeMult),this},a.Envelope.prototype.triggerAttackRelease=function(a,b,c){return b=this.toSeconds(b),this.triggerAttack(b,c),this.triggerRelease(b+this.toSeconds(a)),this},a.Envelope.prototype.connect=a.Signal.prototype.connect,a.Envelope.prototype.dispose=function(){return a.prototype.dispose.call(this),this._sig.dispose(),this._sig=null,this},a.Envelope.Phase={ATTACK:"attack",DECAY:"decay",SUSTAIN:"sustain",RELEASE:"release",STANDBY:"standby"},a.Envelope.Type={LINEAR:"linear",EXPONENTIAL:"exponential"},a.Envelope}),ToneModule(function(a){return a.AmplitudeEnvelope=function(){a.Envelope.apply(this,arguments),this.input=this.output=this.context.createGain(),this._sig.connect(this.output.gain)},a.extend(a.AmplitudeEnvelope,a.Envelope),a.AmplitudeEnvelope}),ToneModule(function(a){return a.Compressor=function(){var b=this.optionsObject(arguments,["threshold","ratio"],a.Compressor.defaults);this._compressor=this.input=this.output=this.context.createDynamicsCompressor(),this.threshold=this._compressor.threshold,this.attack=new a.Signal(this._compressor.attack,a.Signal.Units.Time),this.release=new a.Signal(this._compressor.release,a.Signal.Units.Time),this.knee=this._compressor.knee,this.ratio=this._compressor.ratio,this.attack.connect(this._compressor.attack),this.release.connect(this._compressor.release),this._readOnly(["knee","release","attack","ratio","threshold"]),this.set(b)},a.extend(a.Compressor),a.Compressor.defaults={ratio:12,threshold:-24,release:.25,attack:.003,knee:30},a.Compressor.prototype.dispose=function(){return a.prototype.dispose.call(this),this._writable(["knee","release","attack","ratio","threshold"]),this._compressor.disconnect(),this._compressor=null,this.attack.dispose(),this.attack=null,this.release.dispose(),this.release=null,this.threshold=null,this.ratio=null,this.knee=null,this},a.Compressor}),ToneModule(function(a){return a.Add=function(b){a.call(this,2,0),this._sum=this.input[0]=this.input[1]=this.output=this.context.createGain(),this._value=this.input[1]=new a.Signal(b),this._value.connect(this._sum)},a.extend(a.Add,a.Signal),a.Add.prototype.dispose=function(){return a.prototype.dispose.call(this),this._sum.disconnect(),this._sum=null,this._value.dispose(),this._value=null,this},a.Add}),ToneModule(function(a){return a.Multiply=function(b){a.call(this,2,0),this._mult=this.input[0]=this.output=this.context.createGain(),this._value=this.input[1]=this.output.gain,this._value.value=this.defaultArg(b,0)},a.extend(a.Multiply,a.Signal),a.Multiply.prototype.dispose=function(){return a.prototype.dispose.call(this),this._mult.disconnect(),this._mult=null,this._value=null,this},a.Multiply}),ToneModule(function(a){return a.Negate=function(){this._multiply=this.input=this.output=new a.Multiply(-1)},a.extend(a.Negate,a.SignalBase),a.Negate.prototype.dispose=function(){return a.prototype.dispose.call(this),this._multiply.dispose(),this._multiply=null,this},a.Negate}),ToneModule(function(a){return a.Subtract=function(b){a.call(this,2,0),this._sum=this.input[0]=this.output=this.context.createGain(),this._neg=new a.Negate,this._value=this.input[1]=new a.Signal(b),this._value.chain(this._neg,this._sum)},a.extend(a.Subtract,a.Signal),a.Subtract.prototype.dispose=function(){return a.prototype.dispose.call(this),this._neg.dispose(),this._neg=null,this._sum.disconnect(),this._sum=null,this._value.dispose(),this._value=null,this},a.Subtract}),ToneModule(function(a){return a.GreaterThanZero=function(){this._thresh=this.output=new a.WaveShaper(function(a){return 0>=a?0:1}),this._scale=this.input=new a.Multiply(1e4),this._scale.connect(this._thresh)},a.extend(a.GreaterThanZero,a.SignalBase),a.GreaterThanZero.prototype.dispose=function(){return a.prototype.dispose.call(this),this._scale.dispose(),this._scale=null,this._thresh.dispose(),this._thresh=null,this},a.GreaterThanZero}),ToneModule(function(a){return a.EqualZero=function(){this._scale=this.input=new a.Multiply(1e4),this._thresh=new a.WaveShaper(function(a){return 0===a?1:0},128),this._gtz=this.output=new a.GreaterThanZero,this._scale.chain(this._thresh,this._gtz)},a.extend(a.EqualZero,a.SignalBase),a.EqualZero.prototype.dispose=function(){return a.prototype.dispose.call(this),this._gtz.dispose(),this._gtz=null,this._scale.dispose(),this._scale=null,this._thresh.dispose(),this._thresh=null,this},a.EqualZero}),ToneModule(function(a){return a.Equal=function(b){a.call(this,2,0),this._sub=this.input[0]=new a.Subtract(b),this._equals=this.output=new a.EqualZero,this._sub.connect(this._equals),this.input[1]=this._sub.input[1]},a.extend(a.Equal,a.SignalBase),Object.defineProperty(a.Equal.prototype,"value",{get:function(){return this._sub.value},set:function(a){this._sub.value=a}}),a.Equal.prototype.dispose=function(){return a.prototype.dispose.call(this),this._equals.dispose(),this._equals=null,this._sub.dispose(),this._sub=null,this},a.Equal}),ToneModule(function(a){a.Select=function(c){var d,e;for(c=this.defaultArg(c,2),a.call(this,c,1),this.gate=new a.Signal(0),this._readOnly("gate"),d=0;c>d;d++)e=new b(d),this.input[d]=e,this.gate.connect(e.selecter),e.connect(this.output)},a.extend(a.Select,a.SignalBase),a.Select.prototype.select=function(a,b){return a=Math.floor(a),this.gate.setValueAtTime(a,this.toSeconds(b)),this},a.Select.prototype.dispose=function(){this._writable("gate"),this.gate.dispose(),this.gate=null;for(var b=0;b<this.input.length;b++)this.input[b].dispose(),this.input[b]=null;return a.prototype.dispose.call(this),this};var b=function(b){this.selecter=new a.Equal(b),this.gate=this.input=this.output=this.context.createGain(),this.selecter.connect(this.gate.gain)};return a.extend(b),b.prototype.dispose=function(){a.prototype.dispose.call(this),this.selecter.dispose(),this.gate.disconnect(),this.selecter=null,this.gate=null},a.Select}),ToneModule(function(a){return a.IfThenElse=function(){a.call(this,3,0),this._selector=this.output=new a.Select(2),this.if=this.input[0]=this._selector.gate,this.then=this.input[1]=this._selector.input[1],this.else=this.input[2]=this._selector.input[0]},a.extend(a.IfThenElse,a.SignalBase),a.IfThenElse.prototype.dispose=function(){return a.prototype.dispose.call(this),this._selector.dispose(),this._selector=null,this.if=null,this.then=null,this.else=null,this},a.IfThenElse}),ToneModule(function(a){return a.OR=function(b){b=this.defaultArg(b,2),a.call(this,b,0),this._sum=this.context.createGain(),this._gtz=this.output=new a.GreaterThanZero;for(var c=0;b>c;c++)this.input[c]=this._sum;this._sum.connect(this._gtz)},a.extend(a.OR,a.SignalBase),a.OR.prototype.dispose=function(){return a.prototype.dispose.call(this),this._gtz.dispose(),this._gtz=null,this._sum.disconnect(),this._sum=null,this},a.OR}),ToneModule(function(a){return a.AND=function(b){b=this.defaultArg(b,2),a.call(this,b,0),this._equals=this.output=new a.Equal(b);for(var c=0;b>c;c++)this.input[c]=this._equals},a.extend(a.AND,a.SignalBase),a.AND.prototype.dispose=function(){return a.prototype.dispose.call(this),this._equals.dispose(),this._equals=null,this},a.AND}),ToneModule(function(a){return a.NOT=a.EqualZero,a.NOT}),ToneModule(function(a){return a.GreaterThan=function(b){a.call(this,2,0),this._value=this.input[0]=new a.Subtract(b),this.input[1]=this._value.input[1],this._gtz=this.output=new a.GreaterThanZero,this._value.connect(this._gtz)},a.extend(a.GreaterThan,a.Signal),a.GreaterThan.prototype.dispose=function(){return a.prototype.dispose.call(this),this._value.dispose(),this._value=null,this._gtz.dispose(),this._gtz=null,this},a.GreaterThan}),ToneModule(function(a){return a.LessThan=function(b){a.call(this,2,0),this._neg=this.input[0]=new a.Negate,this._gt=this.output=new a.GreaterThan,this._rhNeg=new a.Negate,this._value=this.input[1]=new a.Signal(b),this._neg.connect(this._gt),this._value.connect(this._rhNeg),this._rhNeg.connect(this._gt,0,1)},a.extend(a.LessThan,a.Signal),a.LessThan.prototype.dispose=function(){return a.prototype.dispose.call(this),this._neg.dispose(),this._neg=null,this._gt.dispose(),this._gt=null,this._rhNeg.dispose(),this._rhNeg=null,this._value.dispose(),this._value=null,this},a.LessThan}),ToneModule(function(a){return a.Abs=function(){a.call(this,1,0),this._ltz=new a.LessThan(0),this._switch=this.output=new a.Select(2),this._negate=new a.Negate,this.input.connect(this._switch,0,0),this.input.connect(this._negate),this._negate.connect(this._switch,0,1),this.input.chain(this._ltz,this._switch.gate)},a.extend(a.Abs,a.SignalBase),a.Abs.prototype.dispose=function(){return a.prototype.dispose.call(this),this._switch.dispose(),this._switch=null,this._ltz.dispose(),this._ltz=null,this._negate.dispose(),this._negate=null,this},a.Abs}),ToneModule(function(a){return a.Max=function(b){a.call(this,2,0),this.input[0]=this.context.createGain(),this._value=this.input[1]=new a.Signal(b),this._ifThenElse=this.output=new a.IfThenElse,this._gt=new a.GreaterThan,this.input[0].chain(this._gt,this._ifThenElse.if),this.input[0].connect(this._ifThenElse.then),this._value.connect(this._ifThenElse.else),this._value.connect(this._gt,0,1)},a.extend(a.Max,a.Signal),a.Max.prototype.dispose=function(){return a.prototype.dispose.call(this),this._value.dispose(),this._ifThenElse.dispose(),this._gt.dispose(),this._value=null,this._ifThenElse=null,this._gt=null,this},a.Max}),ToneModule(function(a){return a.Min=function(b){a.call(this,2,0),this.input[0]=this.context.createGain(),this._ifThenElse=this.output=new a.IfThenElse,this._lt=new a.LessThan,this._value=this.input[1]=new a.Signal(b),this.input[0].chain(this._lt,this._ifThenElse.if),this.input[0].connect(this._ifThenElse.then),this._value.connect(this._ifThenElse.else),this._value.connect(this._lt,0,1)},a.extend(a.Min,a.Signal),a.Min.prototype.dispose=function(){return a.prototype.dispose.call(this),this._value.dispose(),this._ifThenElse.dispose(),this._lt.dispose(),this._value=null,this._ifThenElse=null,this._lt=null,this},a.Min}),ToneModule(function(a){return a.Modulo=function(b){a.call(this,1,1),this._shaper=new a.WaveShaper(Math.pow(2,16)),this._multiply=new a.Multiply,this._subtract=this.output=new a.Subtract,this._modSignal=new a.Signal(b),this.input.fan(this._shaper,this._subtract),this._modSignal.connect(this._multiply,0,0),this._shaper.connect(this._multiply,0,1),this._multiply.connect(this._subtract,0,1),this._setWaveShaper(b)},a.extend(a.Modulo,a.SignalBase),a.Modulo.prototype._setWaveShaper=function(a){this._shaper.setMap(function(b){var c=Math.floor((b+1e-4)/a);return c})},Object.defineProperty(a.Modulo.prototype,"value",{get:function(){return this._modSignal.value},set:function(a){this._modSignal.value=a,this._setWaveShaper(a)}}),a.Modulo.prototype.dispose=function(){return a.prototype.dispose.call(this),this._shaper.dispose(),this._shaper=null,this._multiply.dispose(),this._multiply=null,this._subtract.dispose(),this._subtract=null,this._modSignal.dispose(),this._modSignal=null,this},a.Modulo}),ToneModule(function(a){function b(a,b,c){var d=new a;return c._eval(b[0]).connect(d,0,0),c._eval(b[1]).connect(d,0,1),d}function c(a,b,c){var d=new a;return c._eval(b[0]).connect(d,0,0),d}function d(a){return a?parseFloat(a):void 0}function e(a){return a&&a.args?parseFloat(a.args):void 0}return a.Expr=function(){var a,b,c,d=this._replacements(Array.prototype.slice.call(arguments)),e=this._parseInputs(d);for(this._nodes=[],this.input=new Array(e),a=0;e>a;a++)this.input[a]=this.context.createGain();b=this._parseTree(d);try{c=this._eval(b)}catch(f){throw this._disposeNodes(),new Error("Could evaluate expression: "+d)}this.output=c},a.extend(a.Expr,a.SignalBase),a.Expr._Expressions={value:{signal:{regexp:/^\d+\.\d+|^\d+/,method:function(b){var c=new a.Signal(d(b));return c}},input:{regexp:/^\$\d/,method:function(a,b){return b.input[d(a.substr(1))]}}},glue:{"(":{regexp:/^\(/},")":{regexp:/^\)/},",":{regexp:/^,/}},func:{abs:{regexp:/^abs/,method:c.bind(this,a.Abs)},min:{regexp:/^min/,method:b.bind(this,a.Min)},max:{regexp:/^max/,method:b.bind(this,a.Max)},"if":{regexp:/^if/,method:function(b,c){var d=new a.IfThenElse;return c._eval(b[0]).connect(d.if),c._eval(b[1]).connect(d.then),c._eval(b[2]).connect(d.else),d}},gt0:{regexp:/^gt0/,method:c.bind(this,a.GreaterThanZero)},eq0:{regexp:/^eq0/,method:c.bind(this,a.EqualZero)},mod:{regexp:/^mod/,method:function(b,c){var d=e(b[1]),f=new a.Modulo(d);return c._eval(b[0]).connect(f),f}},pow:{regexp:/^pow/,method:function(b,c){var d=e(b[1]),f=new a.Pow(d);return c._eval(b[0]).connect(f),f}}},binary:{"+":{regexp:/^\+/,precedence:1,method:b.bind(this,a.Add)},"-":{regexp:/^\-/,precedence:1,method:function(d,e){return 1===d.length?c(a.Negate,d,e):b(a.Subtract,d,e)}},"*":{regexp:/^\*/,precedence:0,method:b.bind(this,a.Multiply)},">":{regexp:/^\>/,precedence:2,method:b.bind(this,a.GreaterThan)},"<":{regexp:/^</,precedence:2,method:b.bind(this,a.LessThan)},"==":{regexp:/^==/,precedence:3,method:b.bind(this,a.Equal)},"&&":{regexp:/^&&/,precedence:4,method:b.bind(this,a.AND)},"||":{regexp:/^\|\|/,precedence:5,method:b.bind(this,a.OR)}},unary:{"-":{regexp:/^\-/,method:c.bind(this,a.Negate)},"!":{regexp:/^\!/,method:c.bind(this,a.NOT)}}},a.Expr.prototype._parseInputs=function(a){var b,c,d=a.match(/\$\d/g),e=0;if(null!==d)for(b=0;b<d.length;b++)c=parseInt(d[b].substr(1))+1,e=Math.max(e,c);return e},a.Expr.prototype._replacements=function(a){var b,c=a.shift();for(b=0;b<a.length;b++)c=c.replace(/\%/i,a[b]);return c},a.Expr.prototype._tokenize=function(b){function c(b){var c,d,e,f,g,h;for(c in a.Expr._Expressions){d=a.Expr._Expressions[c];for(e in d)if(f=d[e],g=f.regexp,h=b.match(g),null!==h)return{type:c,value:h[0],method:f.method}}throw new SyntaxError("Unexpected token "+b)}for(var d,e=-1,f=[];b.length>0;)b=b.trim(),d=c(b),f.push(d),b=b.substr(d.value.length);return{next:function(){return f[++e]},peek:function(){return f[e+1]}}},a.Expr.prototype._parseTree=function(b){function c(a,b){return!k(a)&&"glue"===a.type&&a.value===b}function d(b,c,d){var e,f,g=!1,h=a.Expr._Expressions[c];if(!k(b))for(e in h)if(f=h[e],f.regexp.test(b.value)){if(k(d))return!0;if(f.precedence===d)return!0}return g}function e(a){var b,c;for(k(a)&&(a=5),b=0>a?f():e(a-1),c=j.peek();d(c,"binary",a);)c=j.next(),b={operator:c.value,method:c.method,args:[b,e(a)]},c=j.peek();return b}function f(){var a,b;return a=j.peek(),d(a,"unary")?(a=j.next(),b=f(),{operator:a.value,method:a.method,args:[b]}):g()}function g(){var a,b;if(a=j.peek(),k(a))throw new SyntaxError("Unexpected termination of expression");if("func"===a.type)return a=j.next(),h(a);if("value"===a.type)return a=j.next(),{method:a.method,args:a.value};if(c(a,"(")){if(j.next(),b=e(),a=j.next(),!c(a,")"))throw new SyntaxError("Expected )");return b}throw new SyntaxError("Parse error, cannot process token "+a.value)}function h(a){var b,d=[];if(b=j.next(),!c(b,"("))throw new SyntaxError('Expected ( in a function call "'+a.value+'"');if(b=j.peek(),c(b,")")||(d=i()),b=j.next(),!c(b,")"))throw new SyntaxError('Expected ) in a function call "'+a.value+'"');return{method:a.method,args:d,name:name}}function i(){for(var a,b,d=[];;){if(b=e(),k(b))break;if(d.push(b),a=j.peek(),!c(a,","))break;j.next()}return d}var j=this._tokenize(b),k=this.isUndef.bind(this);return e()},a.Expr.prototype._eval=function(a){if(!this.isUndef(a)){var b=a.method(a.args,this);return this._nodes.push(b),b}},a.Expr.prototype._disposeNodes=function(){var a,b;for(a=0;a<this._nodes.length;a++)b=this._nodes[a],this.isFunction(b.dispose)?b.dispose():this.isFunction(b.disconnect)&&b.disconnect(),b=null,this._nodes[a]=null;this._nodes=null},a.Expr.prototype.dispose=function(){a.prototype.dispose.call(this),this._disposeNodes()},a.Expr}),ToneModule(function(a){return a.EqualPowerGain=function(){this._eqPower=this.input=this.output=new a.WaveShaper(function(a){return Math.abs(a)<.001?0:this.equalPowerScale(a)}.bind(this),4096)},a.extend(a.EqualPowerGain,a.SignalBase),a.EqualPowerGain.prototype.dispose=function(){return a.prototype.dispose.call(this),this._eqPower.dispose(),this._eqPower=null,this
|
|
},a.EqualPowerGain}),ToneModule(function(a){return a.CrossFade=function(b){a.call(this,2,1),this.a=this.input[0]=this.context.createGain(),this.b=this.input[1]=this.context.createGain(),this.fade=new a.Signal(this.defaultArg(b,.5),a.Signal.Units.Normal),this._equalPowerA=new a.EqualPowerGain,this._equalPowerB=new a.EqualPowerGain,this._invert=new a.Expr("1 - $0"),this.a.connect(this.output),this.b.connect(this.output),this.fade.chain(this._equalPowerB,this.b.gain),this.fade.chain(this._invert,this._equalPowerA,this.a.gain),this._readOnly("fade")},a.extend(a.CrossFade),a.CrossFade.prototype.dispose=function(){return a.prototype.dispose.call(this),this._writable("fade"),this._equalPowerA.dispose(),this._equalPowerA=null,this._equalPowerB.dispose(),this._equalPowerB=null,this.fade.dispose(),this.fade=null,this._invert.dispose(),this._invert=null,this.a.disconnect(),this.a=null,this.b.disconnect(),this.b=null,this},a.CrossFade}),ToneModule(function(a){return a.Filter=function(){a.call(this);var b=this.optionsObject(arguments,["frequency","type","rolloff"],a.Filter.defaults);this._filters=[],this.frequency=new a.Signal(b.frequency,a.Signal.Units.Frequency),this.detune=new a.Signal(0),this.gain=new a.Signal(b.gain,a.Signal.Units.Decibels),this.Q=new a.Signal(b.Q),this._type=b.type,this._rolloff=b.rolloff,this.rolloff=b.rolloff,this._readOnly(["detune","frequency","gain","Q"])},a.extend(a.Filter),a.Filter.defaults={type:"lowpass",frequency:350,rolloff:-12,Q:1,gain:0},Object.defineProperty(a.Filter.prototype,"type",{get:function(){return this._type},set:function(a){var b,c=["lowpass","highpass","bandpass","lowshelf","highshelf","notch","allpass","peaking"];if(-1===c.indexOf(a))throw new TypeError("Tone.Filter does not have filter type "+a);for(this._type=a,b=0;b<this._filters.length;b++)this._filters[b].type=a}}),Object.defineProperty(a.Filter.prototype,"rolloff",{get:function(){return this._rolloff},set:function(a){var b,c,d,e,f=Math.log(a/-12)/Math.LN2+1;if(f%1!==0)throw new RangeError("Filter rolloff can only be -12, -24, or -48");for(this._rolloff=a,this.input.disconnect(),b=0;b<this._filters.length;b++)this._filters[b].disconnect(),this._filters[b]=null;for(this._filters=new Array(f),c=0;f>c;c++)d=this.context.createBiquadFilter(),d.type=this._type,this.frequency.connect(d.frequency),this.detune.connect(d.detune),this.Q.connect(d.Q),this.gain.connect(d.gain),this._filters[c]=d;e=[this.input].concat(this._filters).concat([this.output]),this.connectSeries.apply(this,e)}}),a.Filter.prototype.dispose=function(){a.prototype.dispose.call(this);for(var b=0;b<this._filters.length;b++)this._filters[b].disconnect(),this._filters[b]=null;return this._filters=null,this._writable(["detune","frequency","gain","Q"]),this.frequency.dispose(),this.Q.dispose(),this.frequency=null,this.Q=null,this.detune.dispose(),this.detune=null,this.gain.dispose(),this.gain=null,this},a.Filter}),ToneModule(function(a){return a.MultibandSplit=function(){var b=this.optionsObject(arguments,["lowFrequency","highFrequency"],a.MultibandSplit.defaults);this.input=this.context.createGain(),this.output=new Array(3),this.low=this.output[0]=new a.Filter(0,"lowpass"),this._lowMidFilter=new a.Filter(0,"highpass"),this.mid=this.output[1]=new a.Filter(0,"lowpass"),this.high=this.output[2]=new a.Filter(0,"highpass"),this.lowFrequency=new a.Signal(b.lowFrequency),this.highFrequency=new a.Signal(b.highFrequency),this.input.fan(this.low,this.high),this.input.chain(this._lowMidFilter,this.mid),this.lowFrequency.connect(this.low.frequency),this.lowFrequency.connect(this._lowMidFilter.frequency),this.highFrequency.connect(this.mid.frequency),this.highFrequency.connect(this.high.frequency),this._readOnly(["high","mid","low","highFrequency","lowFrequency"])},a.extend(a.MultibandSplit),a.MultibandSplit.defaults={lowFrequency:400,highFrequency:2500},a.MultibandSplit.prototype.dispose=function(){return a.prototype.dispose.call(this),this._writable(["high","mid","low","highFrequency","lowFrequency"]),this.low.dispose(),this._lowMidFilter.dispose(),this.mid.dispose(),this.high.dispose(),this.lowFrequency.dispose(),this.highFrequency.dispose(),this.low=null,this._lowMidFilter=null,this.mid=null,this.high=null,this.lowFrequency=null,this.highFrequency=null,this},a.MultibandSplit}),ToneModule(function(a){return a.EQ3=function(){var b=this.optionsObject(arguments,["low","mid","high"],a.EQ3.defaults);this.output=this.context.createGain(),this._multibandSplit=this.input=new a.MultibandSplit({lowFrequency:b.lowFrequency,highFrequency:b.highFrequency}),this._lowGain=this.context.createGain(),this._midGain=this.context.createGain(),this._highGain=this.context.createGain(),this.low=new a.Signal(this._lowGain.gain,a.Signal.Units.Decibels),this.mid=new a.Signal(this._midGain.gain,a.Signal.Units.Decibels),this.high=new a.Signal(this._highGain.gain,a.Signal.Units.Decibels),this.lowFrequency=this._multibandSplit.lowFrequency,this.highFrequency=this._multibandSplit.highFrequency,this._multibandSplit.low.chain(this._lowGain,this.output),this._multibandSplit.mid.chain(this._midGain,this.output),this._multibandSplit.high.chain(this._highGain,this.output),this.high.value=b.low,this.mid.value=b.mid,this.low.value=b.high,this._readOnly(["low","mid","high","lowFrequency","highFrequency"])},a.extend(a.EQ3),a.EQ3.defaults={low:0,mid:0,high:0,lowFrequency:400,highFrequency:2500},a.EQ3.prototype.dispose=function(){return a.prototype.dispose.call(this),this._writable(["low","mid","high","lowFrequency","highFrequency"]),this._multibandSplit.dispose(),this._multibandSplit=null,this.lowFrequency=null,this.highFrequency=null,this._lowGain.disconnect(),this._lowGain=null,this._midGain.disconnect(),this._midGain=null,this._highGain.disconnect(),this._highGain=null,this.low.dispose(),this.low=null,this.mid.dispose(),this.mid=null,this.high.dispose(),this.high=null,this},a.EQ3}),ToneModule(function(a){return a.Scale=function(b,c){this._outputMin=this.defaultArg(b,0),this._outputMax=this.defaultArg(c,1),this._scale=this.input=new a.Multiply(1),this._add=this.output=new a.Add(0),this._scale.connect(this._add),this._setRange()},a.extend(a.Scale,a.SignalBase),Object.defineProperty(a.Scale.prototype,"min",{get:function(){return this._outputMin},set:function(a){this._outputMin=a,this._setRange()}}),Object.defineProperty(a.Scale.prototype,"max",{get:function(){return this._outputMax},set:function(a){this._outputMax=a,this._setRange()}}),a.Scale.prototype._setRange=function(){this._add.value=this._outputMin,this._scale.value=this._outputMax-this._outputMin},a.Scale.prototype.dispose=function(){return a.prototype.dispose.call(this),this._add.dispose(),this._add=null,this._scale.dispose(),this._scale=null,this},a.Scale}),ToneModule(function(a){return a.ScaleExp=function(b,c,d){this._scale=this.output=new a.Scale(b,c),this._exp=this.input=new a.Pow(this.defaultArg(d,2)),this._exp.connect(this._scale)},a.extend(a.ScaleExp,a.SignalBase),Object.defineProperty(a.ScaleExp.prototype,"exponent",{get:function(){return this._exp.value},set:function(a){this._exp.value=a}}),Object.defineProperty(a.ScaleExp.prototype,"min",{get:function(){return this._scale.min},set:function(a){this._scale.min=a}}),Object.defineProperty(a.ScaleExp.prototype,"max",{get:function(){return this._scale.max},set:function(a){this._scale.max=a}}),a.ScaleExp.prototype.dispose=function(){return a.prototype.dispose.call(this),this._scale.dispose(),this._scale=null,this._exp.dispose(),this._exp=null,this},a.ScaleExp}),ToneModule(function(a){return a.FeedbackCombFilter=function(){a.call(this);var b=this.optionsObject(arguments,["delayTime","resonance"],a.FeedbackCombFilter.defaults);this.resonance=new a.Signal(b.resonance,a.Signal.Units.Normal),this._delay=this.input=this.output=this.context.createDelay(1),this.delayTime=new a.Signal(b.delayTime,a.Signal.Units.Time),this._feedback=this.context.createGain(),this._delay.chain(this._feedback,this._delay),this.resonance.connect(this._feedback.gain),this.delayTime.connect(this._delay.delayTime),this._readOnly(["resonance","delayTime"])},a.extend(a.FeedbackCombFilter),a.FeedbackCombFilter.defaults={delayTime:.1,resonance:.5},a.FeedbackCombFilter.prototype.dispose=function(){return a.prototype.dispose.call(this),this._writable(["resonance","delayTime"]),this._delay.disconnect(),this._delay=null,this.delayTime.dispose(),this.delayTime=null,this.resonance.dispose(),this.resonance=null,this._feedback.disconnect(),this._feedback=null,this},a.FeedbackCombFilter}),ToneModule(function(a){return a.Follower=function(){a.call(this);var b=this.optionsObject(arguments,["attack","release"],a.Follower.defaults);this._abs=new a.Abs,this._filter=this.context.createBiquadFilter(),this._filter.type="lowpass",this._filter.frequency.value=0,this._filter.Q.value=-100,this._frequencyValues=new a.WaveShaper,this._sub=new a.Subtract,this._delay=this.context.createDelay(),this._delay.delayTime.value=this.bufferTime,this._mult=new a.Multiply(1e4),this._attack=b.attack,this._release=b.release,this.input.chain(this._abs,this._filter,this.output),this._abs.connect(this._sub,0,1),this._filter.chain(this._delay,this._sub),this._sub.chain(this._mult,this._frequencyValues,this._filter.frequency),this._setAttackRelease(this._attack,this._release)},a.extend(a.Follower),a.Follower.defaults={attack:.05,release:.5},a.Follower.prototype._setAttackRelease=function(a,b){var c=this.bufferTime;a=this.secondsToFrequency(this.toSeconds(a)),b=this.secondsToFrequency(this.toSeconds(b)),a=Math.max(a,c),b=Math.max(b,c),this._frequencyValues.setMap(function(c){return 0>=c?a:b})},Object.defineProperty(a.Follower.prototype,"attack",{get:function(){return this._attack},set:function(a){this._attack=a,this._setAttackRelease(this._attack,this._release)}}),Object.defineProperty(a.Follower.prototype,"release",{get:function(){return this._release},set:function(a){this._release=a,this._setAttackRelease(this._attack,this._release)}}),a.Follower.prototype.connect=a.Signal.prototype.connect,a.Follower.prototype.dispose=function(){return a.prototype.dispose.call(this),this._filter.disconnect(),this._filter=null,this._frequencyValues.disconnect(),this._frequencyValues=null,this._delay.disconnect(),this._delay=null,this._sub.disconnect(),this._sub=null,this._abs.dispose(),this._abs=null,this._mult.dispose(),this._mult=null,this._curve=null,this},a.Follower}),ToneModule(function(a){return a.Gate=function(){a.call(this);var b=this.optionsObject(arguments,["threshold","attack","release"],a.Gate.defaults);this._follower=new a.Follower(b.attack,b.release),this._gt=new a.GreaterThan(this.dbToGain(b.threshold)),this.input.connect(this.output),this.input.chain(this._gt,this._follower,this.output.gain)},a.extend(a.Gate),a.Gate.defaults={attack:.1,release:.1,threshold:-40},Object.defineProperty(a.Gate.prototype,"threshold",{get:function(){return this.gainToDb(this._gt.value)},set:function(a){this._gt.value=this.dbToGain(a)}}),Object.defineProperty(a.Gate.prototype,"attack",{get:function(){return this._follower.attack},set:function(a){this._follower.attack=a}}),Object.defineProperty(a.Gate.prototype,"release",{get:function(){return this._follower.release},set:function(a){this._follower.release=a}}),a.Gate.prototype.dispose=function(){return a.prototype.dispose.call(this),this._follower.dispose(),this._gt.dispose(),this._follower=null,this._gt=null,this},a.Gate}),ToneModule(function(a){return a.Clock=function(b,c){this._oscillator=null,this._jsNode=this.context.createScriptProcessor(this.bufferSize,1,1),this._jsNode.onaudioprocess=this._processBuffer.bind(this),this.frequency=new a.Signal(b,a.Signal.Units.Frequency),this._upTick=!1,this.tick=c,this.onended=function(){},this._jsNode.noGC()},a.extend(a.Clock),a.Clock.prototype.start=function(a){if(!this._oscillator){this._oscillator=this.context.createOscillator(),this._oscillator.type="square",this._oscillator.connect(this._jsNode),this.frequency.connect(this._oscillator.frequency),this._upTick=!1;var b=this.toSeconds(a);this._oscillator.start(b)}return this},a.Clock.prototype.stop=function(a){var b,c;return this._oscillator&&(b=this.now(),c=this.toSeconds(a,b),this._oscillator.stop(c),this._oscillator=null,a?setTimeout(this.onended.bind(this),1e3*(c-b)):this.onended()),this},a.Clock.prototype._processBuffer=function(a){var b,c,d=this.defaultArg(a.playbackTime,this.now()),e=this._jsNode.bufferSize,f=a.inputBuffer.getChannelData(0),g=this._upTick,h=this;for(b=0;e>b;b++)c=f[b],c>0&&!g?(g=!0,setTimeout(function(){var a=d+h.samplesToSeconds(b+2*e);return function(){h.tick&&h.tick(a)}}(),0)):0>c&&g&&(g=!1);this._upTick=g},a.Clock.prototype.dispose=function(){return this._jsNode.disconnect(),this.frequency.dispose(),this.frequency=null,this._oscillator&&(this._oscillator.disconnect(),this._oscillator=null),this._jsNode.onaudioprocess=function(){},this._jsNode=null,this.tick=null,this.onended=function(){},this},a.Clock}),ToneModule(function(Tone){var tatum,timelineTicks,transportTicks,swingSubdivision,swingTatum,swingAmount,transportTimeSignature,loopStart,loopEnd,intervals,timeouts,transportTimeline,timelineProgress,SyncedSources,SyncedSignals,TransportState,processIntervals,processTimeouts,processTimeline,TimelineEventIDCounter,TimelineEvent,TransportConstructor;return Tone.Transport=function(){this._clock=new Tone.Clock(0,this._processTick.bind(this)),this._clock.onended=this._onended.bind(this),this.loop=!1,this.bpm=new Tone.Signal(120,Tone.Signal.Units.BPM),this._bpmMult=new Tone.Multiply(1/60*tatum),this.state=TransportState.STOPPED,this.bpm.chain(this._bpmMult,this._clock.frequency)},Tone.extend(Tone.Transport),Tone.Transport.defaults={bpm:120,swing:0,swingSubdivision:"16n",timeSignature:4,loopStart:0,loopEnd:"4m"},tatum=12,timelineTicks=0,transportTicks=0,swingSubdivision="16n",swingTatum=3,swingAmount=0,transportTimeSignature=4,loopStart=0,loopEnd=4*tatum,intervals=[],timeouts=[],transportTimeline=[],timelineProgress=0,SyncedSources=[],SyncedSignals=[],TransportState={STARTED:"started",PAUSED:"paused",STOPPED:"stopped"},Tone.Transport.prototype._processTick=function(a){this.state===TransportState.STARTED&&(swingAmount>0&&timelineTicks%tatum!==0&&timelineTicks%swingTatum===0&&(a+=this._ticksToSeconds(swingTatum)*swingAmount),processIntervals(a),processTimeouts(a),processTimeline(a),transportTicks+=1,timelineTicks+=1,this.loop&&timelineTicks===loopEnd&&this._setTicks(loopStart))},Tone.Transport.prototype._setTicks=function(a){var b,c;for(timelineTicks=a,b=0;b<transportTimeline.length;b++)if(c=transportTimeline[b],c.callbackTick()>=a){timelineProgress=b;break}},processIntervals=function(a){var b,c,d;for(b=0,c=intervals.length;c>b;b++)d=intervals[b],d.testInterval(transportTicks)&&d.doCallback(a)},processTimeouts=function(a){var b,c,d,e,f=0;for(b=0,c=timeouts.length;c>b;b++)if(d=timeouts[b],e=d.callbackTick(),transportTicks>=e)d.doCallback(a),f++;else if(e>transportTicks)break;timeouts.splice(0,f)},processTimeline=function(a){var b,c,d,e;for(b=timelineProgress,c=transportTimeline.length;c>b;b++)if(d=transportTimeline[b],e=d.callbackTick(),e===timelineTicks)timelineProgress=b,d.doCallback(a);else if(e>timelineTicks)break},Tone.Transport.prototype.setInterval=function(a,b,c){var d=this._toTicks(b),e=new TimelineEvent(a,c,d,transportTicks);return intervals.push(e),e.id},Tone.Transport.prototype.clearInterval=function(a){var b,c;for(b=0;b<intervals.length;b++)if(c=intervals[b],c.id===a)return intervals.splice(b,1),!0;return!1},Tone.Transport.prototype.clearIntervals=function(){var a=intervals.length>0;return intervals=[],a},Tone.Transport.prototype.setTimeout=function(a,b,c){var d,e,f,g=this._toTicks(b),h=new TimelineEvent(a,c,g+transportTicks,0);for(d=0,e=timeouts.length;e>d;d++)if(f=timeouts[d],f.callbackTick()>h.callbackTick())return timeouts.splice(d,0,h),h.id;return timeouts.push(h),h.id},Tone.Transport.prototype.clearTimeout=function(a){var b,c;for(b=0;b<timeouts.length;b++)if(c=timeouts[b],c.id===a)return timeouts.splice(b,1),!0;return!1},Tone.Transport.prototype.clearTimeouts=function(){var a=timeouts.length>0;return timeouts=[],a},Tone.Transport.prototype.setTimeline=function(a,b,c){var d,e,f,g=this._toTicks(b),h=new TimelineEvent(a,c,g,0);for(d=timelineProgress,e=transportTimeline.length;e>d;d++)if(f=transportTimeline[d],f.callbackTick()>h.callbackTick())return transportTimeline.splice(d,0,h),h.id;return transportTimeline.push(h),h.id},Tone.Transport.prototype.clearTimeline=function(a){var b,c;for(b=0;b<transportTimeline.length;b++)if(c=transportTimeline[b],c.id===a)return transportTimeline.splice(b,1),!0;return!1},Tone.Transport.prototype.clearTimelines=function(){timelineProgress=0;var a=transportTimeline.length>0;return transportTimeline=[],a},Tone.Transport.prototype._toTicks=function(a){var b=this.toSeconds(a),c=this.notationToSeconds("4n"),d=b/c,e=d*tatum;return Math.round(e)},Tone.Transport.prototype._ticksToSeconds=function(a,b,c){a=Math.floor(a);var d=this.notationToSeconds("4n",b,c);return d*a/tatum},Tone.Transport.prototype.nextBeat=function(a){var b,c,d;return a=this.defaultArg(a,"4n"),b=this._toTicks(a),c=transportTicks%b,d=c,c>0&&(d=b-c),this._ticksToSeconds(d)},Tone.Transport.prototype.start=function(a,b){var c,d,e,f;if(this.state===TransportState.STOPPED||this.state===TransportState.PAUSED)for(this.isUndef(b)||this._setTicks(this._toTicks(b)),this.state=TransportState.STARTED,c=this.toSeconds(a),this._clock.start(c),d=0;d<SyncedSources.length;d++)e=SyncedSources[d].source,f=SyncedSources[d].delay,e.start(c+f);return this},Tone.Transport.prototype.stop=function(a){var b,c,d;if(this.state===TransportState.STARTED||this.state===TransportState.PAUSED)for(b=this.toSeconds(a),this._clock.stop(b),c=0;c<SyncedSources.length;c++)d=SyncedSources[c].source,d.stop(b);else this._onended();return this},Tone.Transport.prototype._onended=function(){transportTicks=0,this._setTicks(0),this.clearTimeouts(),this.state=TransportState.STOPPED},Tone.Transport.prototype.pause=function(a){var b,c,d;if(this.state===TransportState.STARTED)for(this.state=TransportState.PAUSED,b=this.toSeconds(a),this._clock.stop(b),c=0;c<SyncedSources.length;c++)d=SyncedSources[c].source,d.pause(b);return this},Object.defineProperty(Tone.Transport.prototype,"timeSignature",{get:function(){return transportTimeSignature},set:function(a){transportTimeSignature=a}}),Object.defineProperty(Tone.Transport.prototype,"loopStart",{get:function(){return this._ticksToSeconds(loopStart)},set:function(a){loopStart=this._toTicks(a)}}),Object.defineProperty(Tone.Transport.prototype,"loopEnd",{get:function(){return this._ticksToSeconds(loopEnd)},set:function(a){loopEnd=this._toTicks(a)}}),Tone.Transport.prototype.setLoopPoints=function(a,b){return this.loopStart=a,this.loopEnd=b,this},Object.defineProperty(Tone.Transport.prototype,"swing",{get:function(){return 2*swingAmount},set:function(a){swingAmount=.5*a}}),Object.defineProperty(Tone.Transport.prototype,"swingSubdivision",{get:function(){return swingSubdivision},set:function(a){swingSubdivision=a,swingTatum=this._toTicks(a)}}),Object.defineProperty(Tone.Transport.prototype,"position",{get:function(){var a,b=timelineTicks/tatum,c=Math.floor(b/transportTimeSignature),d=Math.floor(b%1*4);return b=Math.floor(b)%transportTimeSignature,a=[c,b,d],a.join(":")},set:function(a){var b=this._toTicks(a);this._setTicks(b)}}),Tone.Transport.prototype.syncSource=function(a,b){return SyncedSources.push({source:a,delay:this.toSeconds(this.defaultArg(b,0))}),this},Tone.Transport.prototype.unsyncSource=function(a){for(var b=0;b<SyncedSources.length;b++)SyncedSources[b].source===a&&SyncedSources.splice(b,1);return this},Tone.Transport.prototype.syncSignal=function(a,b){b||(b=0!==a._value.value?a._value.value/this.bpm.value:0);var c=this.context.createGain();return c.gain.value=b,this.bpm.chain(c,a._value),SyncedSignals.push({ratio:c,signal:a,initial:a._value.value}),a._value.value=0,this},Tone.Transport.prototype.unsyncSignal=function(a){var b,c;for(b=0;b<SyncedSignals.length;b++)c=SyncedSignals[b],c.signal===a&&(c.ratio.disconnect(),c.signal._value.value=c.initial,SyncedSignals.splice(b,1));return this},Tone.Transport.prototype.dispose=function(){return this._clock.dispose(),this._clock=null,this.bpm.dispose(),this.bpm=null,this._bpmMult.dispose(),this._bpmMult=null,this},TimelineEventIDCounter=0,TimelineEvent=function(a,b,c,d){this.startTicks=d,this.tickTime=c,this.callback=a,this.context=b,this.id=TimelineEventIDCounter++},TimelineEvent.prototype.doCallback=function(a){this.callback.call(this.context,a)},TimelineEvent.prototype.callbackTick=function(){return this.startTicks+this.tickTime},TimelineEvent.prototype.testInterval=function(a){return(a-this.startTicks)%this.tickTime===0},Tone.prototype.isNotation=function(){var a=new RegExp(/[0-9]+[mnt]$/i);return function(b){return a.test(b)}}(),Tone.prototype.isTransportTime=function(){var a=new RegExp(/^\d+(\.\d+)?:\d+(\.\d+)?(:\d+(\.\d+)?)?$/i);return function(b){return a.test(b)}}(),Tone.prototype.notationToSeconds=function(a,b,c){var d,e,f,g;return b=this.defaultArg(b,Tone.Transport.bpm.value),c=this.defaultArg(c,transportTimeSignature),d=60/b,e=parseInt(a,10),f=0,0===e&&(f=0),g=a.slice(-1),f="t"===g?4/e*2/3:"n"===g?4/e:"m"===g?e*c:0,d*f},Tone.prototype.transportTimeToSeconds=function(a,b,c){var d,e,f,g,h;return b=this.defaultArg(b,Tone.Transport.bpm.value),c=this.defaultArg(c,transportTimeSignature),d=0,e=0,f=0,g=a.split(":"),2===g.length?(d=parseFloat(g[0]),e=parseFloat(g[1])):1===g.length?e=parseFloat(g[0]):3===g.length&&(d=parseFloat(g[0]),e=parseFloat(g[1]),f=parseFloat(g[2])),h=d*c+e+f/4,h*this.notationToSeconds("4n")},Tone.prototype.toTransportTime=function(a,b,c){var d,e,f,g,h,i=this.toSeconds(a,b,c);return b=this.defaultArg(b,Tone.Transport.bpm.value),c=this.defaultArg(c,transportTimeSignature),d=this.notationToSeconds("4n"),e=i/d,f=Math.floor(e/c),g=Math.floor(e%1*4),e=Math.floor(e)%c,h=[f,e,g],h.join(":")},Tone.prototype.toFrequency=function(a,b){return this.isFrequency(a)?parseFloat(a):this.isNotation(a)||this.isTransportTime(a)?this.secondsToFrequency(this.toSeconds(a,b)):a},Tone.prototype.toSeconds=function(time,now){var plusTime,components,originalTime,i,symb,val;if(now=this.defaultArg(now,this.now()),"number"==typeof time)return time;if("string"==typeof time){if(plusTime=0,"+"===time.charAt(0)&&(plusTime=now,time=time.slice(1)),components=time.split(/[\(\)\-\+\/\*]/),components.length>1){for(originalTime=time,i=0;i<components.length;i++)symb=components[i].trim(),""!==symb&&(val=this.toSeconds(symb),time=time.replace(symb,val));try{time=eval(time)}catch(e){throw new EvalError("problem evaluating Tone.Time: "+originalTime)}}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},TransportConstructor=Tone.Transport,Tone._initAudioContext(function(){if("function"==typeof Tone.Transport)Tone.Transport=new Tone.Transport;else{Tone.Transport.stop();var a=Tone.Transport.bpm.value;Tone.Transport._clock.dispose(),TransportConstructor.call(Tone.Transport),Tone.Transport.bpm.value=a}}),Tone.Transport}),ToneModule(function(a){a.Master=function(){a.call(this),this._unmutedVolume=1,this._muted=!1,this.volume=new a.Signal(this.output.gain,a.Signal.Units.Decibels),this.input.chain(this.output,this.context.destination)},a.extend(a.Master),a.Master.prototype.mute=function(){return this._muted||(this._muted=!0,this._unmutedVolume=this.volume.value,this.volume.value=-1/0),this},a.Master.prototype.unmute=function(){return this._muted&&(this._muted=!1,this.volume.value=this._unmutedVolume),this},a.Master.prototype.send=function(a){return this.input.disconnect(),this.input.connect(a),this},a.Master.prototype.receive=function(a){return a.connect(this.output),this},a.prototype.toMaster=function(){return this.connect(a.Master),this},AudioNode.prototype.toMaster=function(){return this.connect(a.Master),this};var b=a.Master;return a._initAudioContext(function(){a.prototype.isUndef(a.Master)?(b.prototype.dispose.call(a.Master),b.call(a.Master)):a.Master=new b}),a.Master}),ToneModule(function(a){return a.Source=function(b){a.call(this,0,1),b=this.defaultArg(b,a.Source.defaults),this.onended=b.onended,this._nextStart=1/0,this._nextStop=1/0,this.volume=new a.Signal(this.output.gain,a.Signal.Units.Decibels),this._readOnly("volume"),this._timeout=-1,this.output.channelCount=2,this.output.channelCountMode="explicit"},a.extend(a.Source),a.Source.defaults={onended:function(){},volume:0},a.Source.State={STARTED:"started",PAUSED:"paused",STOPPED:"stopped"},Object.defineProperty(a.Source.prototype,"state",{get:function(){return this._stateAtTime(this.now())}}),a.Source.prototype._stateAtTime=function(b){return b=this.toSeconds(b),this._nextStart<=b&&this._nextStop>b?a.Source.State.STARTED:this._nextStop<=b?a.Source.State.STOPPED:a.Source.State.STOPPED},a.Source.prototype.start=function(b){return b=this.toSeconds(b),(this._stateAtTime(b)!==a.Source.State.STARTED||this.retrigger)&&(this._nextStart=b,this._nextStop=1/0,this._start.apply(this,arguments)),this},a.Source.prototype.stop=function(b){var c,d=this.now();return b=this.toSeconds(b,d),this._stateAtTime(b)===a.Source.State.STARTED&&(this._nextStop=this.toSeconds(b),clearTimeout(this._timeout),c=b-d,c>0?this._timeout=setTimeout(this.onended,1e3*c+20):this.onended(),this._stop.apply(this,arguments)),this},a.Source.prototype.pause=function(a){return this.stop(a),this},a.Source.prototype.sync=function(b){return a.Transport.syncSource(this,b),this},a.Source.prototype.unsync=function(){return a.Transport.unsyncSource(this),this},a.Source.prototype.dispose=function(){a.prototype.dispose.call(this),this.stop(),clearTimeout(this._timeout),this.onended=function(){},this._writable("volume"),this.volume.dispose(),this.volume=null},a.Source}),ToneModule(function(a){return a.Oscillator=function(){var b=this.optionsObject(arguments,["frequency","type"],a.Oscillator.defaults);a.Source.call(this,b),this._oscillator=null,this.frequency=new a.Signal(b.frequency,a.Signal.Units.Frequency),this.detune=new a.Signal(b.detune),this._wave=null,this._phase=b.phase,this._type=null,this.type=b.type,this.phase=this._phase,this._readOnly(["frequency","detune"])},a.extend(a.Oscillator,a.Source),a.Oscillator.defaults={type:"sine",frequency:440,detune:0,phase:0},a.Oscillator.prototype._start=function(a){this._oscillator=this.context.createOscillator(),this._oscillator.setPeriodicWave(this._wave),this._oscillator.connect(this.output),this.frequency.connect(this._oscillator.frequency),this.detune.connect(this._oscillator.detune),this._oscillator.start(this.toSeconds(a))},a.Oscillator.prototype._stop=function(a){return this._oscillator&&(this._oscillator.stop(this.toSeconds(a)),this._oscillator=null),this},a.Oscillator.prototype.syncFrequency=function(){return a.Transport.syncSignal(this.frequency),this},a.Oscillator.prototype.unsyncFrequency=function(){return a.Transport.unsyncSignal(this.frequency),this},Object.defineProperty(a.Oscillator.prototype,"type",{get:function(){return this._type},set:function(a){var b,c,d,e,f,g=a,h=4096,i=h/2,j=new Float32Array(i),k=new Float32Array(i),l=1,m=/(sine|triangle|square|sawtooth)(\d+)$/.exec(a);for(m&&(l=parseInt(m[2]),a=m[1],l=Math.max(l,2),i=l),b=this._phase,c=1;i>c;++c){switch(d=2/(c*Math.PI),a){case"sine":e=l>=c?1:0;break;case"square":e=1&c?2*d:0;break;case"sawtooth":e=d*(1&c?1:-1);break;case"triangle":e=1&c?2*d*d*(c-1>>1&1?-1:1):0;break;default:throw new TypeError("invalid oscillator type: "+a)}0!==e?(j[c]=-e*Math.sin(b*c),k[c]=e*Math.cos(b*c)):(j[c]=0,k[c]=0)}f=this.context.createPeriodicWave(j,k),this._wave=f,null!==this._oscillator&&this._oscillator.setPeriodicWave(this._wave),this._type=g}}),Object.defineProperty(a.Oscillator.prototype,"phase",{get:function(){return this._phase*(180/Math.PI)},set:function(a){this._phase=a*Math.PI/180,this.type=this._type}}),a.Oscillator.prototype.dispose=function(){return a.Source.prototype.dispose.call(this),null!==this._oscillator&&(this._oscillator.disconnect(),this._oscillator=null),this._wave=null,this._writable(["frequency","detune"]),this.frequency.dispose(),this.frequency=null,this.detune.dispose(),this.detune=null,this},a.Oscillator}),ToneModule(function(a){return a.AudioToGain=function(){this._norm=this.input=this.output=new a.WaveShaper(function(a){return(a+1)/2})},a.extend(a.AudioToGain,a.SignalBase),a.AudioToGain.prototype.dispose=function(){return a.prototype.dispose.call(this),this._norm.dispose(),this._norm=null,this},a.AudioToGain}),ToneModule(function(a){return a.LFO=function(){var b=this.optionsObject(arguments,["frequency","min","max"],a.LFO.defaults);this.oscillator=new a.Oscillator({frequency:b.frequency,type:b.type,phase:b.phase}),this.frequency=this.oscillator.frequency,this.amplitude=this.oscillator.volume,this.amplitude.units=a.Signal.Units.Normal,this.amplitude.value=b.amplitude,this._a2g=new a.AudioToGain,this._scaler=this.output=new a.Scale(b.min,b.max),this.oscillator.chain(this._a2g,this._scaler),this._readOnly(["amplitude","frequency","oscillator"])},a.extend(a.LFO,a.Oscillator),a.LFO.defaults={type:"sine",min:0,max:1,phase:0,frequency:"4n",amplitude:1},a.LFO.prototype.start=function(a){return this.oscillator.start(a),this},a.LFO.prototype.stop=function(a){return this.oscillator.stop(a),this},a.LFO.prototype.sync=function(a){return this.oscillator.sync(a),this.oscillator.syncFrequency(),this},a.LFO.prototype.unsync=function(){return this.oscillator.unsync(),this.oscillator.unsyncFrequency(),this},Object.defineProperty(a.LFO.prototype,"min",{get:function(){return this._scaler.min},set:function(a){this._scaler.min=a}}),Object.defineProperty(a.LFO.prototype,"max",{get:function(){return this._scaler.max},set:function(a){this._scaler.max=a}}),Object.defineProperty(a.LFO.prototype,"type",{get:function(){return this.oscillator.type},set:function(a){this.oscillator.type=a}}),Object.defineProperty(a.LFO.prototype,"phase",{get:function(){return this.oscillator.phase},set:function(a){this.oscillator.phase=a}}),a.LFO.prototype.connect=a.Signal.prototype.connect,a.LFO.prototype.dispose=function(){return a.prototype.dispose.call(this),this._writable(["amplitude","frequency","oscillator"]),this.oscillator.dispose(),this.oscillator=null,this._scaler.dispose(),this._scaler=null,this._a2g.dispose(),this._a2g=null,this.frequency=null,this.amplitude=null,this},a.LFO}),ToneModule(function(a){return a.Limiter=function(b){this._compressor=this.input=this.output=new a.Compressor({attack:1e-4,decay:1e-4,threshold:b}),this.threshold=this._compressor.threshold,this._readOnly("threshold")},a.extend(a.Limiter),a.Limiter.prototype.dispose=function(){return a.prototype.dispose.call(this),this._compressor.dispose(),this._compressor=null,this._writable("threshold"),this.threshold=null,this},a.Limiter}),ToneModule(function(a){return a.LowpassCombFilter=function(){a.call(this);var b=this.optionsObject(arguments,["delayTime","resonance","dampening"],a.LowpassCombFilter.defaults);this._delay=this.input=this.context.createDelay(1),this.delayTime=new a.Signal(b.delayTime,a.Signal.Units.Time),this._lowpass=this.output=this.context.createBiquadFilter(),this._lowpass.Q.value=0,this._lowpass.type="lowpass",this._lowpass.frequency.value=b.dampening,this.dampening=new a.Signal(this._lowpass.frequency,a.Signal.Units.Frequency),this._feedback=this.context.createGain(),this.resonance=new a.Signal(b.resonance,a.Signal.Units.Normal),this._delay.chain(this._lowpass,this._feedback,this._delay),this.delayTime.connect(this._delay.delayTime),this.resonance.connect(this._feedback.gain),this._readOnly(["dampening","resonance","delayTime"])},a.extend(a.LowpassCombFilter),a.LowpassCombFilter.defaults={delayTime:.1,resonance:.5,dampening:3e3},a.LowpassCombFilter.prototype.dispose=function(){return a.prototype.dispose.call(this),this._writable(["dampening","resonance","delayTime"]),this.dampening.dispose(),this.dampening=null,this.resonance.dispose(),this.resonance=null,this._delay.disconnect(),this._delay=null,this._lowpass.disconnect(),this._lowpass=null,this._feedback.disconnect(),this._feedback=null,this.delayTime.dispose(),this.delayTime=null,this
|
|
},a.LowpassCombFilter}),ToneModule(function(a){return a.Merge=function(){a.call(this,2,0),this.left=this.input[0]=this.context.createGain(),this.right=this.input[1]=this.context.createGain(),this._merger=this.output=this.context.createChannelMerger(2),this.left.connect(this._merger,0,0),this.right.connect(this._merger,0,1)},a.extend(a.Merge),a.Merge.prototype.dispose=function(){return a.prototype.dispose.call(this),this.left.disconnect(),this.left=null,this.right.disconnect(),this.right=null,this._merger.disconnect(),this._merger=null,this},a.Merge}),ToneModule(function(a){return a.Meter=function(b,c,d){a.call(this),this._channels=this.defaultArg(b,1),this._smoothing=this.defaultArg(c,.8),this._clipMemory=1e3*this.defaultArg(d,.5),this._volume=new Array(this._channels),this._values=new Array(this._channels);for(var e=0;e<this._channels;e++)this._volume[e]=0,this._values[e]=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)},a.extend(a.Meter),a.Meter.prototype._onprocess=function(a){var b,c,d,e,f,g,h,i,j,k=this._jsNode.bufferSize,l=this._smoothing;for(b=0;b<this._channels;b++){for(c=a.inputBuffer.getChannelData(b),d=0,e=0,g=!1,h=0;k>h;h++)f=c[h],!g&&f>.95&&(g=!0,this._lastClip=Date.now()),e+=f,d+=f*f;i=e/k,j=Math.sqrt(d/k),this._volume[b]=Math.max(j,this._volume[b]*l),this._values[b]=i}},a.Meter.prototype.getLevel=function(a){a=this.defaultArg(a,0);var b=this._volume[a];return 1e-5>b?0:b},a.Meter.prototype.getValue=function(a){return a=this.defaultArg(a,0),this._values[a]},a.Meter.prototype.getDb=function(a){return this.gainToDb(this.getLevel(a))},a.Meter.prototype.isClipped=function(){return Date.now()-this._lastClip<this._clipMemory},a.Meter.prototype.dispose=function(){return a.prototype.dispose.call(this),this._jsNode.disconnect(),this._jsNode.onaudioprocess=null,this._volume=null,this._values=null,this},a.Meter}),ToneModule(function(a){return a.Split=function(){a.call(this,0,2),this._splitter=this.input=this.context.createChannelSplitter(2),this.left=this.output[0]=this.context.createGain(),this.right=this.output[1]=this.context.createGain(),this._splitter.connect(this.left,0,0),this._splitter.connect(this.right,1,0)},a.extend(a.Split),a.Split.prototype.dispose=function(){return a.prototype.dispose.call(this),this._splitter.disconnect(),this.left.disconnect(),this.right.disconnect(),this.left=null,this.right=null,this._splitter=null,this},a.Split}),ToneModule(function(a){a.MidSideSplit=function(){a.call(this,0,2),this._split=this.input=new a.Split,this.mid=this.output[0]=new a.Expr("($0 + $1) * $2"),this.side=this.output[1]=new a.Expr("($0 - $1) * $2"),this._split.connect(this.mid,0,0),this._split.connect(this.mid,1,1),this._split.connect(this.side,0,0),this._split.connect(this.side,1,1),b.connect(this.mid,0,2),b.connect(this.side,0,2)},a.extend(a.MidSideSplit);var b=null;return a._initAudioContext(function(){b=new a.Signal(1/Math.sqrt(2))}),a.MidSideSplit.prototype.dispose=function(){return a.prototype.dispose.call(this),this.mid.dispose(),this.mid=null,this.side.dispose(),this.side=null,this._split.dispose(),this._split=null,this},a.MidSideSplit}),ToneModule(function(a){a.MidSideMerge=function(){a.call(this,2,0),this.mid=this.input[0]=this.context.createGain(),this._left=new a.Expr("($0 + $1) * $2"),this.side=this.input[1]=this.context.createGain(),this._right=new a.Expr("($0 - $1) * $2"),this._merge=this.output=new a.Merge,this.mid.connect(this._left,0,0),this.side.connect(this._left,0,1),this.mid.connect(this._right,0,0),this.side.connect(this._right,0,1),this._left.connect(this._merge,0,0),this._right.connect(this._merge,0,1),b.connect(this._left,0,2),b.connect(this._right,0,2)},a.extend(a.MidSideMerge);var b=null;return a._initAudioContext(function(){b=new a.Signal(1/Math.sqrt(2))}),a.MidSideMerge.prototype.dispose=function(){return a.prototype.dispose.call(this),this.mid.disconnect(),this.mid=null,this.side.disconnect(),this.side=null,this._left.dispose(),this._left=null,this._right.dispose(),this._right=null,this._merge.dispose(),this._merge=null,this},a.MidSideMerge}),ToneModule(function(a){return a.MidSideCompressor=function(b){b=this.defaultArg(b,a.MidSideCompressor.defaults),this._midSideSplit=this.input=new a.MidSideSplit,this._midSideMerge=this.output=new a.MidSideMerge,this.mid=new a.Compressor(b.mid),this.side=new a.Compressor(b.side),this._midSideSplit.mid.chain(this.mid,this._midSideMerge.mid),this._midSideSplit.side.chain(this.side,this._midSideMerge.side),this._readOnly(["mid","side"])},a.extend(a.MidSideCompressor),a.MidSideCompressor.defaults={mid:{ratio:3,threshold:-24,release:.03,attack:.02,knee:16},side:{ratio:6,threshold:-30,release:.25,attack:.03,knee:10}},a.MidSideCompressor.prototype.dispose=function(){return a.prototype.dispose.call(this),this._writable(["mid","side"]),this.mid.dispose(),this.mid=null,this.side.dispose(),this.side=null,this._midSideSplit.dispose(),this._midSideSplit=null,this._midSideMerge.dispose(),this._midSideMerge=null,this},a.MidSideCompressor}),ToneModule(function(a){return a.Mono=function(){a.call(this,1,0),this._merge=this.output=new a.Merge,this.input.connect(this._merge,0,0),this.input.connect(this._merge,0,1),this.input.gain.value=this.dbToGain(-10)},a.extend(a.Mono),a.Mono.prototype.dispose=function(){return a.prototype.dispose.call(this),this._merge.dispose(),this._merge=null,this},a.Mono}),ToneModule(function(a){return a.MultibandCompressor=function(b){b=this.defaultArg(arguments,a.MultibandCompressor.defaults),this._splitter=this.input=new a.MultibandSplit({lowFrequency:b.lowFrequency,highFrequency:b.highFrequency}),this.lowFrequency=this._splitter.lowFrequency,this.highFrequency=this._splitter.highFrequency,this.output=this.context.createGain(),this.low=new a.Compressor(b.low),this.mid=new a.Compressor(b.mid),this.high=new a.Compressor(b.high),this._splitter.low.chain(this.low,this.output),this._splitter.mid.chain(this.mid,this.output),this._splitter.high.chain(this.high,this.output),this._readOnly(["high","mid","low","highFrequency","lowFrequency"])},a.extend(a.MultibandCompressor),a.MultibandCompressor.defaults={low:a.Compressor.defaults,mid:a.Compressor.defaults,high:a.Compressor.defaults,lowFrequency:250,highFrequency:2e3},a.MultibandCompressor.prototype.dispose=function(){return a.prototype.dispose.call(this),this._splitter.dispose(),this._writable(["high","mid","low","highFrequency","lowFrequency"]),this.low.dispose(),this.mid.dispose(),this.high.dispose(),this._splitter=null,this.low=null,this.mid=null,this.high=null,this.lowFrequency=null,this.highFrequency=null,this},a.MultibandCompressor}),ToneModule(function(a){return a.GainToAudio=function(){this._norm=this.input=this.output=new a.WaveShaper(function(a){return 2*Math.abs(a)-1})},a.extend(a.GainToAudio,a.SignalBase),a.GainToAudio.prototype.dispose=function(){return a.prototype.dispose.call(this),this._norm.dispose(),this._norm=null,this},a.GainToAudio}),ToneModule(function(a){return a.Panner=function(b){a.call(this),this._hasStereoPanner=this.isFunction(this.context.createStereoPanner),this._hasStereoPanner?(this._panner=this.input=this.output=this.context.createStereoPanner(),this.pan=new a.Signal(0,a.Signal.Units.Normal),this._scalePan=new a.GainToAudio,this.pan.chain(this._scalePan,this._panner.pan)):(this._crossFade=new a.CrossFade,this._merger=this.output=new a.Merge,this._splitter=this.input=new a.Split,this.pan=this._crossFade.fade,this._splitter.connect(this._crossFade,0,0),this._splitter.connect(this._crossFade,1,1),this._crossFade.a.connect(this._merger,0,0),this._crossFade.b.connect(this._merger,0,1)),this.pan.value=this.defaultArg(b,.5),this._readOnly("pan")},a.extend(a.Panner),a.Panner.prototype.dispose=function(){return a.prototype.dispose.call(this),this._writable("pan"),this._hasStereoPanner?(this._panner.disconnect(),this._panner=null,this.pan.dispose(),this.pan=null,this._scalePan.dispose(),this._scalePan=null):(this._crossFade.dispose(),this._crossFade=null,this._splitter.dispose(),this._splitter=null,this._merger.dispose(),this._merger=null,this.pan=null),this},a.Panner}),ToneModule(function(a){return a.Volume=function(b,c){this.output=this.input=this.context.createGain(),this.volume=new a.Signal(this.output.gain,a.Signal.Units.Decibels),this.volume.value=this.defaultArg(c,0),this._readOnly("volume")},a.extend(a.Volume),a.Volume.prototype.dispose=function(){return a.prototype.dispose.call(this),this._writable("volume"),this.volume.dispose(),this.volume=null,this},a.Volume}),ToneModule(function(a){return a.PanVol=function(b,c){this._panner=this.input=new a.Panner(b),this.pan=this._panner.pan,this._volume=this.output=new a.Volume(c),this.volume=this._volume.volume,this._panner.connect(this._volume),this._readOnly(["pan","volume"])},a.extend(a.PanVol),a.PanVol.prototype.dispose=function(){return a.prototype.dispose.call(this),this._writable(["pan","volume"]),this._panner.dispose(),this._panner=null,this._volume.dispose(),this._volume=null,this.pan=null,this.volume=null,this},a.PanVol}),ToneModule(function(a){return a.ScaledEnvelope=function(){var b=this.optionsObject(arguments,["attack","decay","sustain","release"],a.Envelope.defaults);a.Envelope.call(this,b),b=this.defaultArg(b,a.ScaledEnvelope.defaults),this._exp=this.output=new a.Pow(b.exponent),this._scale=this.output=new a.Scale(b.min,b.max),this._sig.chain(this._exp,this._scale)},a.extend(a.ScaledEnvelope,a.Envelope),a.ScaledEnvelope.defaults={min:0,max:1,exponent:1},Object.defineProperty(a.ScaledEnvelope.prototype,"min",{get:function(){return this._scale.min},set:function(a){this._scale.min=a}}),Object.defineProperty(a.ScaledEnvelope.prototype,"max",{get:function(){return this._scale.max},set:function(a){this._scale.max=a}}),Object.defineProperty(a.ScaledEnvelope.prototype,"exponent",{get:function(){return this._exp.value},set:function(a){this._exp.value=a}}),a.ScaledEnvelope.prototype.dispose=function(){return a.Envelope.prototype.dispose.call(this),this._scale.dispose(),this._scale=null,this._exp.dispose(),this._exp=null,this},a.ScaledEnvelope}),ToneModule(function(a){return a.Buffer=function(){var b=this.optionsObject(arguments,["url","onload"],a.Buffer.defaults);this._buffer=null,this._reversed=b.reverse,this.url=void 0,this.loaded=!1,this.onload=b.onload.bind(this,this),b.url instanceof AudioBuffer?(this._buffer.set(b.url),this.onload(this)):"string"==typeof b.url&&(this.url=b.url,a.Buffer._addToQueue(b.url,this))},a.extend(a.Buffer),a.Buffer.defaults={url:void 0,onload:function(){},reverse:!1},a.Buffer.prototype.set=function(b){return this._buffer=b instanceof a.Buffer?b.get():b,this.loaded=!0,this},a.Buffer.prototype.get=function(){return this._buffer},a.Buffer.prototype.load=function(b,c){return this.url=b,this.onload=this.defaultArg(c,this.onload),a.Buffer._addToQueue(b,this),this},a.Buffer.prototype.dispose=function(){return a.prototype.dispose.call(this),a.Buffer._removeFromQueue(this),this._buffer=null,this.onload=a.Buffer.defaults.onload,this},Object.defineProperty(a.Buffer.prototype,"duration",{get:function(){return this._buffer?this._buffer.duration:0}}),a.Buffer.prototype._reverse=function(){if(this.loaded)for(var a=0;a<this._buffer.numberOfChannels;a++)Array.prototype.reverse.call(this._buffer.getChannelData(a));return this},Object.defineProperty(a.Buffer.prototype,"reverse",{get:function(){return this._reversed},set:function(a){this._reversed!==a&&(this._reversed=a,this._reverse())}}),a.Buffer._queue=[],a.Buffer._currentDownloads=[],a.Buffer._totalDownloads=0,a.Buffer.MAX_SIMULTANEOUS_DOWNLOADS=6,a.Buffer._addToQueue=function(b,c){a.Buffer._queue.push({url:b,Buffer:c,progress:0,xhr:null}),this._totalDownloads++,a.Buffer._next()},a.Buffer._removeFromQueue=function(b){var c,d,e;for(c=0;c<a.Buffer._queue.length;c++)d=a.Buffer._queue[c],d.Buffer===b&&a.Buffer._queue.splice(c,1);for(c=0;c<a.Buffer._currentDownloads.length;c++)e=a.Buffer._currentDownloads[c],e.Buffer===b&&(a.Buffer._currentDownloads.splice(c,1),e.xhr.abort(),e.xhr.onprogress=null,e.xhr.onload=null,e.xhr.onerror=null)},a.Buffer._next=function(){if(a.Buffer._queue.length>0){if(a.Buffer._currentDownloads.length<a.Buffer.MAX_SIMULTANEOUS_DOWNLOADS){var b=a.Buffer._queue.shift();a.Buffer._currentDownloads.push(b),b.xhr=a.Buffer.load(b.url,function(c){var d=a.Buffer._currentDownloads.indexOf(b);a.Buffer._currentDownloads.splice(d,1),b.Buffer.set(c),b.Buffer._reversed&&b.Buffer._reverse(),b.Buffer.onload(b.Buffer),a.Buffer._onprogress(),a.Buffer._next()}),b.xhr.onprogress=function(c){b.progress=c.loaded/c.total,a.Buffer._onprogress()},b.xhr.onerror=a.Buffer.onerror}}else 0===a.Buffer._currentDownloads.length&&(a.Buffer.onload(),a.Buffer._totalDownloads=0)},a.Buffer._onprogress=function(){var b,c,d,e,f=0,g=a.Buffer._currentDownloads.length,h=0;if(g>0){for(b=0;g>b;b++)c=a.Buffer._currentDownloads[b],f+=c.progress;h=f}d=g-h,e=a.Buffer._totalDownloads-a.Buffer._queue.length-d,a.Buffer.onprogress(e/a.Buffer._totalDownloads)},a.Buffer.load=function(b,c){var d=new XMLHttpRequest;return d.open("GET",b,!0),d.responseType="arraybuffer",d.onload=function(){a.context.decodeAudioData(d.response,function(a){if(!a)throw new Error("could not decode audio data:"+b);c(a)})},d.send(),d},a.Buffer.onload=function(){},a.Buffer.onprogress=function(){},a.Buffer.onerror=function(){},a.Buffer}),ToneModule(function(a){var b={};return a.prototype.send=function(a,c){b.hasOwnProperty(a)||(b[a]=this.context.createGain());var d=this.context.createGain();return d.gain.value=this.dbToGain(this.defaultArg(c,1)),this.output.chain(d,b[a]),d},a.prototype.receive=function(a,c){return b.hasOwnProperty(a)||(b[a]=this.context.createGain()),this.isUndef(c)&&(c=this.input),b[a].connect(c),this},a}),ToneModule(function(a){function b(a,b,d){var e,f,g,h;if(c.hasOwnProperty(a))for(e=c[a],f=0,g=e.length;g>f;f++)h=e[f],Array.isArray(d)?h.apply(window,[b].concat(d)):h(b,d)}var c,d,e,f;return a.Note=function(b,c,d){this.value=d,this._channel=b,this._timelineID=a.Transport.setTimeline(this._trigger.bind(this),c)},a.Note.prototype._trigger=function(a){b(this._channel,a,this.value)},a.Note.prototype.dispose=function(){return a.Tranport.clearTimeline(this._timelineID),this.value=null,this},c={},a.Note.route=function(a,b){c.hasOwnProperty(a)?c[a].push(b):c[a]=[b]},a.Note.unroute=function(a,b){var d,e;c.hasOwnProperty(a)&&(d=c[a],e=d.indexOf(b),-1!==e&&c[a].splice(e,1))},a.Note.parseScore=function(b){var c,d,e,f,g,h,i,j=[];for(c in b)if(d=b[c],"tempo"===c)a.Transport.bpm.value=d;else if("timeSignature"===c)a.Transport.timeSignature=d[0]/(d[1]/4);else{if(!Array.isArray(d))throw new TypeError("score parts must be Arrays");for(e=0;e<d.length;e++)f=d[e],Array.isArray(f)?(h=f[0],i=f.slice(1),g=new a.Note(c,h,i)):g=new a.Note(c,f),j.push(g)}return j},d={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},e=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],f=261.6255653005986,a.prototype.noteToFrequency=function(a){var b,c,e,g=a.split(/(\d+)/);return 3===g.length?(b=d[g[0].toLowerCase()],c=g[1],e=b+12*parseInt(c,10),Math.pow(2,(e-48)/12)*f):0},a.prototype.isNote=function(){var a=new RegExp(/[a-g]{1}([b#]{1}|[b#]{0})[0-9]+$/i);return function(b){return"string"==typeof b&&(b=b.toLowerCase()),a.test(b)}}(),a.prototype._overwrittenToFrequency=a.prototype.toFrequency,a.prototype.toFrequency=function(a,b){return this.isNote(a)&&(a=this.noteToFrequency(a)),this._overwrittenToFrequency(a,b)},a.prototype.frequencyToNote=function(a){var b=Math.log(a/f)/Math.LN2,c=Math.round(12*b)+48,d=Math.floor(c/12),g=e[c%12];return g+d.toString()},a.prototype.intervalToFrequencyRatio=function(a){return Math.pow(2,a/12)},a.prototype.midiToNote=function(a){var b=Math.floor(a/12)-2,c=a%12;return e[c]+b},a.prototype.noteToMidi=function(a){var b,c,e=a.split(/(\d+)/);return 3===e.length?(b=d[e[0].toLowerCase()],c=e[1],b+12*(parseInt(c,10)+2)):0},a.Note}),ToneModule(function(a){return a.Effect=function(){a.call(this);var b=this.optionsObject(arguments,["wet"],a.Effect.defaults);this._dryWet=new a.CrossFade(b.wet),this.wet=this._dryWet.fade,this.effectSend=this.context.createGain(),this.effectReturn=this.context.createGain(),this.input.connect(this._dryWet.a),this.input.connect(this.effectSend),this.effectReturn.connect(this._dryWet.b),this._dryWet.connect(this.output),this._readOnly(["wet"])},a.extend(a.Effect),a.Effect.defaults={wet:1},a.Effect.prototype.bypass=function(){return this.wet.value=0,this},a.Effect.prototype.connectEffect=function(a){return this.effectSend.chain(a,this.effectReturn),this},a.Effect.prototype.dispose=function(){return a.prototype.dispose.call(this),this._dryWet.dispose(),this._dryWet=null,this.effectSend.disconnect(),this.effectSend=null,this.effectReturn.disconnect(),this.effectReturn=null,this._writable(["wet"]),this.wet=null,this},a.Effect}),ToneModule(function(a){return a.AutoFilter=function(){var b=this.optionsObject(arguments,["frequency"],a.AutoFilter.defaults);a.Effect.call(this,b),this._lfo=new a.LFO(b.frequency,b.min,b.max),this.depth=this._lfo.amplitude,this.frequency=this._lfo.frequency,this._filter=new a.Filter(b.filter),this.connectEffect(this._filter),this._lfo.connect(this._filter.frequency),this.type=b.type,this._readOnly(["frequency","depth"])},a.extend(a.AutoFilter,a.Effect),a.AutoFilter.defaults={frequency:1,type:"sine",depth:1,min:200,max:1200,filter:{type:"lowpass",rolloff:-12,Q:1}},a.AutoFilter.prototype.start=function(a){return this._lfo.start(a),this},a.AutoFilter.prototype.stop=function(a){return this._lfo.stop(a),this},a.AutoFilter.prototype.sync=function(a){return this._lfo.sync(a),this},a.AutoFilter.prototype.unsync=function(){return this._lfo.unsync(),this},Object.defineProperty(a.AutoFilter.prototype,"type",{get:function(){return this._lfo.type},set:function(a){this._lfo.type=a}}),Object.defineProperty(a.AutoFilter.prototype,"min",{get:function(){return this._lfo.min},set:function(a){this._lfo.min=a}}),Object.defineProperty(a.AutoFilter.prototype,"max",{get:function(){return this._lfo.max},set:function(a){this._lfo.max=a}}),a.AutoFilter.prototype.dispose=function(){return a.Effect.prototype.dispose.call(this),this._lfo.dispose(),this._lfo=null,this._filter.dispose(),this._filter=null,this._writable(["frequency","depth"]),this.frequency=null,this.depth=null,this},a.AutoFilter}),ToneModule(function(a){return a.AutoPanner=function(){var b=this.optionsObject(arguments,["frequency"],a.AutoPanner.defaults);a.Effect.call(this,b),this._lfo=new a.LFO(b.frequency,0,1),this.depth=this._lfo.amplitude,this._panner=new a.Panner,this.frequency=this._lfo.frequency,this.connectEffect(this._panner),this._lfo.connect(this._panner.pan),this.type=b.type,this._readOnly(["depth","frequency"])},a.extend(a.AutoPanner,a.Effect),a.AutoPanner.defaults={frequency:1,type:"sine",depth:1},a.AutoPanner.prototype.start=function(a){return this._lfo.start(a),this},a.AutoPanner.prototype.stop=function(a){return this._lfo.stop(a),this},a.AutoPanner.prototype.sync=function(a){return this._lfo.sync(a),this},a.AutoPanner.prototype.unsync=function(){return this._lfo.unsync(),this},Object.defineProperty(a.AutoPanner.prototype,"type",{get:function(){return this._lfo.type},set:function(a){this._lfo.type=a}}),a.AutoPanner.prototype.dispose=function(){return a.Effect.prototype.dispose.call(this),this._lfo.dispose(),this._lfo=null,this._panner.dispose(),this._panner=null,this._writable(["depth","frequency"]),this.frequency=null,this.depth=null,this},a.AutoPanner}),ToneModule(function(a){return a.AutoWah=function(){var b=this.optionsObject(arguments,["baseFrequency","octaves","sensitivity"],a.AutoWah.defaults);a.Effect.call(this,b),this.follower=new a.Follower(b.follower),this._sweepRange=new a.ScaleExp(0,1,.5),this._baseFrequency=b.baseFrequency,this._octaves=b.octaves,this._inputBoost=this.context.createGain(),this._bandpass=new a.Filter({rolloff:-48,frequency:0,Q:b.Q}),this._peaking=new a.Filter(0,"peaking"),this._peaking.gain.value=b.gain,this.gain=this._peaking.gain,this.Q=this._bandpass.Q,this.effectSend.chain(this._inputBoost,this.follower,this._sweepRange),this._sweepRange.connect(this._bandpass.frequency),this._sweepRange.connect(this._peaking.frequency),this.effectSend.chain(this._bandpass,this._peaking,this.effectReturn),this._setSweepRange(),this.sensitivity=b.sensitivity,this._readOnly(["gain","Q"])},a.extend(a.AutoWah,a.Effect),a.AutoWah.defaults={baseFrequency:100,octaves:6,sensitivity:0,Q:2,gain:2,follower:{attack:.3,release:.5}},Object.defineProperty(a.AutoWah.prototype,"octaves",{get:function(){return this._octaves},set:function(a){this._octaves=a,this._setSweepRange()}}),Object.defineProperty(a.AutoWah.prototype,"baseFrequency",{get:function(){return this._baseFrequency},set:function(a){this._baseFrequency=a,this._setSweepRange()}}),Object.defineProperty(a.AutoWah.prototype,"sensitivity",{get:function(){return this.gainToDb(1/this._inputBoost.gain.value)},set:function(a){this._inputBoost.gain.value=1/this.dbToGain(a)}}),a.AutoWah.prototype._setSweepRange=function(){this._sweepRange.min=this._baseFrequency,this._sweepRange.max=Math.min(this._baseFrequency*Math.pow(2,this._octaves),this.context.sampleRate/2)},a.AutoWah.prototype.dispose=function(){return a.Effect.prototype.dispose.call(this),this.follower.dispose(),this.follower=null,this._sweepRange.dispose(),this._sweepRange=null,this._bandpass.dispose(),this._bandpass=null,this._peaking.dispose(),this._peaking=null,this._inputBoost.disconnect(),this._inputBoost=null,this._writable(["gain","Q"]),this.gain=null,this.Q=null,this},a.AutoWah}),ToneModule(function(a){return a.BitCrusher=function(){var b,c=this.optionsObject(arguments,["bits"],a.BitCrusher.defaults);a.Effect.call(this,c),b=1/Math.pow(2,c.bits-1),this._subtract=new a.Subtract,this._modulo=new a.Modulo(b),this._bits=c.bits,this.effectSend.fan(this._subtract,this._modulo),this._modulo.connect(this._subtract,0,1),this._subtract.connect(this.effectReturn)},a.extend(a.BitCrusher,a.Effect),a.BitCrusher.defaults={bits:4},Object.defineProperty(a.BitCrusher.prototype,"bits",{get:function(){return this._bits},set:function(a){this._bits=a;var b=1/Math.pow(2,a-1);this._modulo.value=b}}),a.BitCrusher.prototype.dispose=function(){return a.Effect.prototype.dispose.call(this),this._subtract.dispose(),this._subtract=null,this._modulo.dispose(),this._modulo=null,this},a.BitCrusher}),ToneModule(function(a){return a.Chebyshev=function(){var b=this.optionsObject(arguments,["order"],a.Chebyshev.defaults);a.Effect.call(this),this._shaper=new a.WaveShaper(4096),this._order=b.order,this.connectEffect(this._shaper),this.order=b.order,this.oversample=b.oversample},a.extend(a.Chebyshev,a.Effect),a.Chebyshev.defaults={order:1,oversample:"none"},a.Chebyshev.prototype._getCoefficient=function(a,b,c){return c.hasOwnProperty(b)?c[b]:(c[b]=0===b?0:1===b?a:2*a*this._getCoefficient(a,b-1,c)-this._getCoefficient(a,b-2,c),c[b])},Object.defineProperty(a.Chebyshev.prototype,"order",{get:function(){return this._order},set:function(a){var b,c,d,e;for(this._order=a,b=new Array(4096),c=b.length,d=0;c>d;++d)e=2*d/c-1,b[d]=0===e?0:this._getCoefficient(e,a,{});this._shaper.curve=b}}),Object.defineProperty(a.Chebyshev.prototype,"oversample",{get:function(){return this._shaper.oversample},set:function(a){this._shaper.oversample=a}}),a.Chebyshev.prototype.dispose=function(){return a.Effect.prototype.dispose.call(this),this._shaper.dispose(),this._shaper=null,this},a.Chebyshev}),ToneModule(function(a){return a.StereoEffect=function(){a.call(this);var b=this.optionsObject(arguments,["wet"],a.Effect.defaults);this._dryWet=new a.CrossFade(b.wet),this.wet=this._dryWet.fade,this._split=new a.Split,this.effectSendL=this._split.left,this.effectSendR=this._split.right,this._merge=new a.Merge,this.effectReturnL=this._merge.left,this.effectReturnR=this._merge.right,this.input.connect(this._split),this.input.connect(this._dryWet,0,0),this._merge.connect(this._dryWet,0,1),this._dryWet.connect(this.output),this._readOnly(["wet"])},a.extend(a.StereoEffect,a.Effect),a.StereoEffect.prototype.dispose=function(){return a.prototype.dispose.call(this),this._dryWet.dispose(),this._dryWet=null,this._split.dispose(),this._split=null,this._merge.dispose(),this._merge=null,this.effectSendL=null,this.effectSendR=null,this.effectReturnL=null,this.effectReturnR=null,this._writable(["wet"]),this.wet=null,this},a.StereoEffect}),ToneModule(function(a){return a.FeedbackEffect=function(){var b=this.optionsObject(arguments,["feedback"]);b=this.defaultArg(b,a.FeedbackEffect.defaults),a.Effect.call(this,b),this.feedback=new a.Signal(b.feedback,a.Signal.Units.Normal),this._feedbackGain=this.context.createGain(),this.effectReturn.chain(this._feedbackGain,this.effectSend),this.feedback.connect(this._feedbackGain.gain),this._readOnly(["feedback"])},a.extend(a.FeedbackEffect,a.Effect),a.FeedbackEffect.defaults={feedback:.125},a.FeedbackEffect.prototype.dispose=function(){return a.Effect.prototype.dispose.call(this),this._writable(["feedback"]),this.feedback.dispose(),this.feedback=null,this._feedbackGain.disconnect(),this._feedbackGain=null,this},a.FeedbackEffect}),ToneModule(function(a){return a.StereoXFeedbackEffect=function(){var b=this.optionsObject(arguments,["feedback"],a.FeedbackEffect.defaults);a.StereoEffect.call(this,b),this.feedback=new a.Signal(b.feedback),this._feedbackLR=this.context.createGain(),this._feedbackRL=this.context.createGain(),this.effectReturnL.chain(this._feedbackLR,this.effectSendR),this.effectReturnR.chain(this._feedbackRL,this.effectSendL),this.feedback.fan(this._feedbackLR.gain,this._feedbackRL.gain),this._readOnly(["feedback"])},a.extend(a.StereoXFeedbackEffect,a.FeedbackEffect),a.StereoXFeedbackEffect.prototype.dispose=function(){return a.StereoEffect.prototype.dispose.call(this),this._writable(["feedback"]),this.feedback.dispose(),this.feedback=null,this._feedbackLR.disconnect(),this._feedbackLR=null,this._feedbackRL.disconnect(),this._feedbackRL=null,this},a.StereoXFeedbackEffect}),ToneModule(function(a){return a.Chorus=function(){var b=this.optionsObject(arguments,["frequency","delayTime","depth"],a.Chorus.defaults);a.StereoXFeedbackEffect.call(this,b),this._depth=b.depth,this._delayTime=b.delayTime/1e3,this._lfoL=new a.LFO(b.rate,0,1),this._lfoR=new a.LFO(b.rate,0,1),this._lfoR.phase=180,this._delayNodeL=this.context.createDelay(),this._delayNodeR=this.context.createDelay(),this.frequency=this._lfoL.frequency,this.connectSeries(this.effectSendL,this._delayNodeL,this.effectReturnL),this.connectSeries(this.effectSendR,this._delayNodeR,this.effectReturnR),this.effectSendL.connect(this.effectReturnL),this.effectSendR.connect(this.effectReturnR),this._lfoL.connect(this._delayNodeL.delayTime),this._lfoR.connect(this._delayNodeR.delayTime),this._lfoL.start(),this._lfoR.start(),this._lfoL.frequency.connect(this._lfoR.frequency),this.depth=this._depth,this.frequency.value=b.frequency,this.type=b.type,this._readOnly(["frequency"])},a.extend(a.Chorus,a.StereoXFeedbackEffect),a.Chorus.defaults={frequency:1.5,delayTime:3.5,depth:.7,feedback:.1,type:"sine"},Object.defineProperty(a.Chorus.prototype,"depth",{get:function(){return this._depth},set:function(a){this._depth=a;var b=this._delayTime*a;this._lfoL.min=Math.max(this._delayTime-b,0),this._lfoL.max=this._delayTime+b,this._lfoR.min=Math.max(this._delayTime-b,0),this._lfoR.max=this._delayTime+b}}),Object.defineProperty(a.Chorus.prototype,"delayTime",{get:function(){return 1e3*this._delayTime},set:function(a){this._delayTime=a/1e3,this.depth=this._depth}}),Object.defineProperty(a.Chorus.prototype,"type",{get:function(){return this._lfoL.type},set:function(a){this._lfoL.type=a,this._lfoR.type=a}}),a.Chorus.prototype.dispose=function(){return a.StereoXFeedbackEffect.prototype.dispose.call(this),this._lfoL.dispose(),this._lfoL=null,this._lfoR.dispose(),this._lfoR=null,this._delayNodeL.disconnect(),this._delayNodeL=null,this._delayNodeR.disconnect(),this._delayNodeR=null,this._writable("frequency"),this.frequency=null,this},a.Chorus}),ToneModule(function(a){return a.Convolver=function(){var b=this.optionsObject(arguments,["url"],a.Convolver.defaults);a.Effect.call(this,b),this._convolver=this.context.createConvolver(),this._buffer=new a.Buffer(b.url,function(a){this.buffer=a,b.onload()}.bind(this)),this.connectEffect(this._convolver)},a.extend(a.Convolver,a.Effect),a.Convolver.defaults={url:"",onload:function(){}},Object.defineProperty(a.Convolver.prototype,"buffer",{get:function(){return this._buffer.get()},set:function(a){this._buffer.set(a),this._convolver.buffer=this._buffer.get()}}),a.Convolver.prototype.load=function(a,b){return this._buffer.load(a,function(a){this.buffer=a,b&&b()}.bind(this)),this},a.Convolver.prototype.dispose=function(){return a.Effect.prototype.dispose.call(this),this._convolver.disconnect(),this._convolver=null,this._buffer.dispose(),this._buffer=null,this},a.Convolver}),ToneModule(function(a){return a.Distortion=function(){var b=this.optionsObject(arguments,["distortion"],a.Distortion.defaults);a.Effect.call(this),this._shaper=new a.WaveShaper(4096),this._distortion=b.distortion,this.connectEffect(this._shaper),this.distortion=b.distortion,this.oversample=b.oversample},a.extend(a.Distortion,a.Effect),a.Distortion.defaults={distortion:.4,oversample:"none"},Object.defineProperty(a.Distortion.prototype,"distortion",{get:function(){return this._distortion},set:function(a){var b,c;this._distortion=a,b=100*a,c=Math.PI/180,this._shaper.setMap(function(a){return Math.abs(a)<.001?0:(3+b)*a*20*c/(Math.PI+b*Math.abs(a))})}}),Object.defineProperty(a.Distortion.prototype,"oversample",{get:function(){return this._shaper.oversample},set:function(a){this._shaper.oversample=a}}),a.Distortion.prototype.dispose=function(){return a.Effect.prototype.dispose.call(this),this._shaper.dispose(),this._shaper=null,this},a.Distortion}),ToneModule(function(a){return a.FeedbackDelay=function(){var b=this.optionsObject(arguments,["delayTime","feedback"],a.FeedbackDelay.defaults);a.FeedbackEffect.call(this,b),this.delayTime=new a.Signal(b.delayTime,a.Signal.Units.Time),this._delayNode=this.context.createDelay(4),this.connectEffect(this._delayNode),this.delayTime.connect(this._delayNode.delayTime),this._readOnly(["delayTime"])},a.extend(a.FeedbackDelay,a.FeedbackEffect),a.FeedbackDelay.defaults={delayTime:.25},a.FeedbackDelay.prototype.dispose=function(){return a.FeedbackEffect.prototype.dispose.call(this),this.delayTime.dispose(),this._delayNode.disconnect(),this._delayNode=null,this._writable(["delayTime"]),this.delayTime=null,this},a.FeedbackDelay}),ToneModule(function(a){var b=[1557/44100,1617/44100,1491/44100,1422/44100,1277/44100,1356/44100,1188/44100,1116/44100],c=[225,556,441,341];return a.Freeverb=function(){var d,e,f,g,h,i,j=this.optionsObject(arguments,["roomSize","dampening"],a.Freeverb.defaults);for(a.StereoEffect.call(this,j),this.roomSize=new a.Signal(j.roomSize,a.Signal.Units.Normal),this.dampening=new a.Signal(j.dampening,a.Signal.Units.Frequency),this._combFilters=[],this._allpassFiltersL=[],this._allpassFiltersR=[],d=0;d<c.length;d++)e=this.context.createBiquadFilter(),e.type="allpass",e.frequency.value=c[d],this._allpassFiltersL.push(e);for(f=0;f<c.length;f++)g=this.context.createBiquadFilter(),g.type="allpass",g.frequency.value=c[f],this._allpassFiltersR.push(g);for(h=0;h<b.length;h++)i=new a.LowpassCombFilter(b[h]),h<b.length/2?this.effectSendL.chain(i,this._allpassFiltersL[0]):this.effectSendR.chain(i,this._allpassFiltersR[0]),this.roomSize.connect(i.resonance),this.dampening.connect(i.dampening),this._combFilters.push(i);this.connectSeries.apply(this,this._allpassFiltersL),this.connectSeries.apply(this,this._allpassFiltersR),this._allpassFiltersL[this._allpassFiltersL.length-1].connect(this.effectReturnL),this._allpassFiltersR[this._allpassFiltersR.length-1].connect(this.effectReturnR),this._readOnly(["roomSize","dampening"])
|
|
},a.extend(a.Freeverb,a.StereoEffect),a.Freeverb.defaults={roomSize:.7,dampening:3e3},a.Freeverb.prototype.dispose=function(){var b,c,d;for(a.StereoEffect.prototype.dispose.call(this),b=0;b<this._allpassFiltersL.length;b++)this._allpassFiltersL[b].disconnect(),this._allpassFiltersL[b]=null;for(this._allpassFiltersL=null,c=0;c<this._allpassFiltersR.length;c++)this._allpassFiltersR[c].disconnect(),this._allpassFiltersR[c]=null;for(this._allpassFiltersR=null,d=0;d<this._combFilters.length;d++)this._combFilters[d].dispose(),this._combFilters[d]=null;return this._combFilters=null,this._writable(["roomSize","dampening"]),this.roomSize.dispose(),this.roomSize=null,this.dampening.dispose(),this.dampening=null,this},a.Freeverb}),ToneModule(function(a){var b=[.06748,.06404,.08212,.09004],c=[.773,.802,.753,.733],d=[347,113,37];return a.JCReverb=function(){var e,f,g,h,i=this.optionsObject(arguments,["roomSize"],a.JCReverb.defaults);for(a.StereoEffect.call(this,i),this.roomSize=new a.Signal(i.roomSize,a.Signal.Units.Normal),this._scaleRoomSize=new a.Scale(-.733,.197),this._allpassFilters=[],this._feedbackCombFilters=[],e=0;e<d.length;e++)f=this.context.createBiquadFilter(),f.type="allpass",f.frequency.value=d[e],this._allpassFilters.push(f);for(g=0;g<b.length;g++)h=new a.FeedbackCombFilter(b[g],.1),this._scaleRoomSize.connect(h.resonance),h.resonance.value=c[g],this._allpassFilters[this._allpassFilters.length-1].connect(h),h.connect(g<b.length/2?this.effectReturnL:this.effectReturnR),this._feedbackCombFilters.push(h);this.roomSize.connect(this._scaleRoomSize),this.connectSeries.apply(this,this._allpassFilters),this.effectSendL.connect(this._allpassFilters[0]),this.effectSendR.connect(this._allpassFilters[0]),this._readOnly(["roomSize"])},a.extend(a.JCReverb,a.StereoEffect),a.JCReverb.defaults={roomSize:.5},a.JCReverb.prototype.dispose=function(){var b,c;for(a.StereoEffect.prototype.dispose.call(this),b=0;b<this._allpassFilters.length;b++)this._allpassFilters[b].disconnect(),this._allpassFilters[b]=null;for(this._allpassFilters=null,c=0;c<this._feedbackCombFilters.length;c++)this._feedbackCombFilters[c].dispose(),this._feedbackCombFilters[c]=null;return this._feedbackCombFilters=null,this._writable(["roomSize"]),this.roomSize.dispose(),this.roomSize=null,this._scaleRoomSize.dispose(),this._scaleRoomSize=null,this},a.JCReverb}),ToneModule(function(a){return a.MidSideEffect=function(){a.Effect.call(this),this._midSideSplit=new a.MidSideSplit,this._midSideMerge=new a.MidSideMerge,this.midSend=this._midSideSplit.mid,this.sideSend=this._midSideSplit.side,this.midReturn=this._midSideMerge.mid,this.sideReturn=this._midSideMerge.side,this.effectSend.connect(this._midSideSplit),this._midSideMerge.connect(this.effectReturn)},a.extend(a.MidSideEffect,a.Effect),a.MidSideEffect.prototype.dispose=function(){return a.Effect.prototype.dispose.call(this),this._midSideSplit.dispose(),this._midSideSplit=null,this._midSideMerge.dispose(),this._midSideMerge=null,this.midSend=null,this.sideSend=null,this.midReturn=null,this.sideReturn=null,this},a.MidSideEffect}),ToneModule(function(a){return a.Phaser=function(){var b=this.optionsObject(arguments,["frequency","depth","baseFrequency"],a.Phaser.defaults);a.StereoEffect.call(this,b),this._lfoL=new a.LFO(b.frequency,0,1),this._lfoR=new a.LFO(b.frequency,0,1),this._lfoR.phase=180,this._baseFrequency=b.baseFrequency,this._depth=b.depth,this._filtersL=this._makeFilters(b.stages,this._lfoL,b.Q),this._filtersR=this._makeFilters(b.stages,this._lfoR,b.Q),this.frequency=this._lfoL.frequency,this.frequency.value=b.frequency,this.effectSendL.connect(this._filtersL[0]),this.effectSendR.connect(this._filtersR[0]),this._filtersL[b.stages-1].connect(this.effectReturnL),this._filtersR[b.stages-1].connect(this.effectReturnR),this.effectSendL.connect(this.effectReturnL),this.effectSendR.connect(this.effectReturnR),this._lfoL.frequency.connect(this._lfoR.frequency),this.baseFrequency=b.baseFrequency,this.depth=b.depth,this._lfoL.start(),this._lfoR.start(),this._readOnly(["frequency"])},a.extend(a.Phaser,a.StereoEffect),a.Phaser.defaults={frequency:.5,depth:10,stages:4,Q:100,baseFrequency:400},a.Phaser.prototype._makeFilters=function(a,b,c){var d,e,f=new Array(a);for(d=0;a>d;d++)e=this.context.createBiquadFilter(),e.type="allpass",e.Q.value=c,b.connect(e.frequency),f[d]=e;return this.connectSeries.apply(this,f),f},Object.defineProperty(a.Phaser.prototype,"depth",{get:function(){return this._depth},set:function(a){this._depth=a;var b=this._baseFrequency+this._baseFrequency*a;this._lfoL.max=b,this._lfoR.max=b}}),Object.defineProperty(a.Phaser.prototype,"baseFrequency",{get:function(){return this._baseFrequency},set:function(a){this._baseFrequency=a,this._lfoL.min=a,this._lfoR.min=a,this.depth=this._depth}}),a.Phaser.prototype.dispose=function(){var b,c;for(a.StereoEffect.prototype.dispose.call(this),this._lfoL.dispose(),this._lfoL=null,this._lfoR.dispose(),this._lfoR=null,b=0;b<this._filtersL.length;b++)this._filtersL[b].disconnect(),this._filtersL[b]=null;for(this._filtersL=null,c=0;c<this._filtersR.length;c++)this._filtersR[c].disconnect(),this._filtersR[c]=null;return this._filtersR=null,this._writable(["frequency"]),this.frequency=null,this},a.Phaser}),ToneModule(function(a){return a.PingPongDelay=function(){var b=this.optionsObject(arguments,["delayTime","feedback"],a.PingPongDelay.defaults);a.StereoXFeedbackEffect.call(this,b),this._leftDelay=this.context.createDelay(b.maxDelayTime),this._rightDelay=this.context.createDelay(b.maxDelayTime),this._rightPreDelay=this.context.createDelay(b.maxDelayTime),this.delayTime=new a.Signal(b.delayTime,a.Signal.Units.Time),this.effectSendL.chain(this._leftDelay,this.effectReturnL),this.effectSendR.chain(this._rightPreDelay,this._rightDelay,this.effectReturnR),this.delayTime.fan(this._leftDelay.delayTime,this._rightDelay.delayTime,this._rightPreDelay.delayTime),this._feedbackLR.disconnect(),this._feedbackLR.connect(this._rightDelay),this._readOnly(["delayTime"])},a.extend(a.PingPongDelay,a.StereoXFeedbackEffect),a.PingPongDelay.defaults={delayTime:.25,maxDelayTime:1},a.PingPongDelay.prototype.dispose=function(){return a.StereoXFeedbackEffect.prototype.dispose.call(this),this._leftDelay.disconnect(),this._leftDelay=null,this._rightDelay.disconnect(),this._rightDelay=null,this._rightPreDelay.disconnect(),this._rightPreDelay=null,this._writable(["delayTime"]),this.delayTime.dispose(),this.delayTime=null,this},a.PingPongDelay}),ToneModule(function(a){return a.StereoFeedbackEffect=function(){var b=this.optionsObject(arguments,["feedback"],a.FeedbackEffect.defaults);a.StereoEffect.call(this,b),this.feedback=new a.Signal(b.feedback),this._feedbackL=this.context.createGain(),this._feedbackR=this.context.createGain(),this.effectReturnL.chain(this._feedbackL,this.effectSendL),this.effectReturnR.chain(this._feedbackR,this.effectSendR),this.feedback.fan(this._feedbackL.gain,this._feedbackR.gain),this._readOnly(["feedback"])},a.extend(a.StereoFeedbackEffect,a.FeedbackEffect),a.StereoFeedbackEffect.prototype.dispose=function(){return a.StereoEffect.prototype.dispose.call(this),this._writable(["feedback"]),this.feedback.dispose(),this.feedback=null,this._feedbackL.disconnect(),this._feedbackL=null,this._feedbackR.disconnect(),this._feedbackR=null,this},a.StereoFeedbackEffect}),ToneModule(function(a){return a.StereoWidener=function(){var b=this.optionsObject(arguments,["width"],a.StereoWidener.defaults);a.MidSideEffect.call(this,b),this.width=new a.Signal(.5,a.Signal.Units.Normal),this._midMult=new a.Expr("$0 * ($1 * (1 - $2))"),this._sideMult=new a.Expr("$0 * ($1 * $2)"),this._two=new a.Signal(2),this._two.connect(this._midMult,0,1),this.width.connect(this._midMult,0,2),this._two.connect(this._sideMult,0,1),this.width.connect(this._sideMult,0,2),this.midSend.chain(this._midMult,this.midReturn),this.sideSend.chain(this._sideMult,this.sideReturn),this._readOnly(["width"])},a.extend(a.StereoWidener,a.MidSideEffect),a.StereoWidener.defaults={width:.5},a.StereoWidener.prototype.dispose=function(){return a.MidSideEffect.prototype.dispose.call(this),this._writable(["width"]),this.width.dispose(),this.width=null,this._midMult.dispose(),this._midMult=null,this._sideMult.dispose(),this._sideMult=null,this._two.dispose(),this._two=null,this},a.StereoWidener}),ToneModule(function(a){return a.Tremolo=function(){var b=this.optionsObject(arguments,["frequency","depth"],a.Tremolo.defaults);a.Effect.call(this,b),this._lfo=new a.LFO(b.frequency,1,0),this._amplitude=this.context.createGain(),this.frequency=this._lfo.frequency,this.depth=this._lfo.amplitude,this._readOnly(["frequency","depth"]),this.connectEffect(this._amplitude),this._lfo.connect(this._amplitude.gain),this.type=b.type},a.extend(a.Tremolo,a.Effect),a.Tremolo.defaults={frequency:10,type:"sine",depth:.5},a.Tremolo.prototype.start=function(a){return this._lfo.start(a),this},a.Tremolo.prototype.stop=function(a){return this._lfo.stop(a),this},a.Tremolo.prototype.sync=function(a){return this._lfo.sync(a),this},a.Tremolo.prototype.unsync=function(){return this._lfo.unsync(),this},Object.defineProperty(a.Tremolo.prototype,"type",{get:function(){return this._lfo.type},set:function(a){this._lfo.type=a}}),a.Tremolo.prototype.dispose=function(){return a.Effect.prototype.dispose.call(this),this._writable(["frequency","depth"]),this._lfo.dispose(),this._lfo=null,this._amplitude.disconnect(),this._amplitude=null,this.frequency=null,this.depth=null,this},a.Tremolo}),ToneModule(function(a){return a.PulseOscillator=function(){var b=this.optionsObject(arguments,["frequency","width"],a.Oscillator.defaults);a.Source.call(this,b),this.width=new a.Signal(b.width,a.Signal.Units.Normal),this._widthGate=this.context.createGain(),this._sawtooth=new a.Oscillator({frequency:b.frequency,detune:b.detune,type:"sawtooth",phase:b.phase}),this.frequency=this._sawtooth.frequency,this.detune=this._sawtooth.detune,this._thresh=new a.WaveShaper(function(a){return 0>a?-1:1}),this._sawtooth.chain(this._thresh,this.output),this.width.chain(this._widthGate,this._thresh),this._readOnly(["width","frequency","detune"])},a.extend(a.PulseOscillator,a.Oscillator),a.PulseOscillator.defaults={frequency:440,detune:0,phase:0,width:.2},a.PulseOscillator.prototype._start=function(a){a=this.toSeconds(a),this._sawtooth.start(a),this._widthGate.gain.setValueAtTime(1,a)},a.PulseOscillator.prototype._stop=function(a){a=this.toSeconds(a),this._sawtooth.stop(a),this._widthGate.gain.setValueAtTime(0,a)},Object.defineProperty(a.PulseOscillator.prototype,"phase",{get:function(){return this._sawtooth.phase},set:function(a){this._sawtooth.phase=a}}),Object.defineProperty(a.PulseOscillator.prototype,"type",{get:function(){return"pulse"}}),a.PulseOscillator.prototype.dispose=function(){return a.Source.prototype.dispose.call(this),this._sawtooth.dispose(),this._sawtooth=null,this._writable(["width","frequency","detune"]),this.width.dispose(),this.width=null,this._widthGate.disconnect(),this._widthGate=null,this._widthGate=null,this._thresh.disconnect(),this._thresh=null,this.frequency=null,this.detune=null,this},a.PulseOscillator}),ToneModule(function(a){return a.PWMOscillator=function(){var b=this.optionsObject(arguments,["frequency","modulationFrequency"],a.PWMOscillator.defaults);a.Source.call(this,b),this._pulse=new a.PulseOscillator(b.modulationFrequency),this._pulse._sawtooth.type="sine",this._modulator=new a.Oscillator({frequency:b.frequency,detune:b.detune}),this._scale=new a.Multiply(1.01),this.frequency=this._modulator.frequency,this.detune=this._modulator.detune,this.modulationFrequency=this._pulse.frequency,this._modulator.chain(this._scale,this._pulse.width),this._pulse.connect(this.output),this._readOnly(["modulationFrequency","frequency","detune"])},a.extend(a.PWMOscillator,a.Oscillator),a.PWMOscillator.defaults={frequency:440,detune:0,modulationFrequency:.4},a.PWMOscillator.prototype._start=function(a){a=this.toSeconds(a),this._modulator.start(a),this._pulse.start(a)},a.PWMOscillator.prototype._stop=function(a){a=this.toSeconds(a),this._modulator.stop(a),this._pulse.stop(a)},Object.defineProperty(a.PWMOscillator.prototype,"type",{get:function(){return"pwm"}}),Object.defineProperty(a.PWMOscillator.prototype,"phase",{get:function(){return this._modulator.phase},set:function(a){this._modulator.phase=a}}),a.PWMOscillator.prototype.dispose=function(){return a.Source.prototype.dispose.call(this),this._pulse.dispose(),this._pulse=null,this._scale.dispose(),this._scale=null,this._modulator.dispose(),this._modulator=null,this._writable(["modulationFrequency","frequency","detune"]),this.frequency=null,this.detune=null,this.modulationFrequency=null,this},a.PWMOscillator}),ToneModule(function(a){a.OmniOscillator=function(){var b=this.optionsObject(arguments,["frequency","type"],a.OmniOscillator.defaults);a.Source.call(this,b),this.frequency=new a.Signal(b.frequency,a.Signal.Units.Frequency),this.detune=new a.Signal(b.detune),this._sourceType=void 0,this._oscillator=null,this.type=b.type,this._readOnly(["frequency","detune"])},a.extend(a.OmniOscillator,a.Oscillator),a.OmniOscillator.defaults={frequency:440,detune:0,type:"sine",width:.4,modulationFrequency:.4};var b={PulseOscillator:"PulseOscillator",PWMOscillator:"PWMOscillator",Oscillator:"Oscillator"};return a.OmniOscillator.prototype._start=function(a){this._oscillator.start(a)},a.OmniOscillator.prototype._stop=function(a){this._oscillator.stop(a)},Object.defineProperty(a.OmniOscillator.prototype,"type",{get:function(){return this._oscillator.type},set:function(c){if("sine"===c||"square"===c||"triangle"===c||"sawtooth"===c)this._sourceType!==b.Oscillator&&(this._sourceType=b.Oscillator,this._createNewOscillator(a.Oscillator)),this._oscillator.type=c;else if("pwm"===c)this._sourceType!==b.PWMOscillator&&(this._sourceType=b.PWMOscillator,this._createNewOscillator(a.PWMOscillator));else{if("pulse"!==c)throw new TypeError("Tone.OmniOscillator does not support type "+c);this._sourceType!==b.PulseOscillator&&(this._sourceType=b.PulseOscillator,this._createNewOscillator(a.PulseOscillator))}}}),a.OmniOscillator.prototype._createNewOscillator=function(b){var c,d=this.now()+this.bufferTime;null!==this._oscillator&&(c=this._oscillator,c.stop(d),c.onended=function(){c.dispose(),c=null}),this._oscillator=new b,this.frequency.connect(this._oscillator.frequency),this.detune.connect(this._oscillator.detune),this._oscillator.connect(this.output),this.state===a.Source.State.STARTED&&this._oscillator.start(d)},Object.defineProperty(a.OmniOscillator.prototype,"phase",{get:function(){return this._oscillator.phase},set:function(a){this._oscillator.phase=a}}),Object.defineProperty(a.OmniOscillator.prototype,"width",{get:function(){return this._sourceType===b.PulseOscillator?this._oscillator.width:void 0}}),Object.defineProperty(a.OmniOscillator.prototype,"modulationFrequency",{get:function(){return this._sourceType===b.PWMOscillator?this._oscillator.modulationFrequency:void 0}}),a.OmniOscillator.prototype.dispose=function(){return a.Source.prototype.dispose.call(this),this._writable(["frequency","detune"]),this.detune.dispose(),this.detune=null,this.frequency.dispose(),this.frequency=null,this._oscillator.dispose(),this._oscillator=null,this._sourceType=null,this},a.OmniOscillator}),ToneModule(function(a){return a.Instrument=function(){this.output=this.context.createGain(),this.volume=new a.Signal(this.output.gain,a.Signal.Units.Decibels),this._readOnly(["volume"])},a.extend(a.Instrument),a.Instrument.prototype.triggerAttack=function(){},a.Instrument.prototype.triggerRelease=function(){},a.Instrument.prototype.triggerAttackRelease=function(a,b,c,d){return c=this.toSeconds(c),b=this.toSeconds(b),this.triggerAttack(a,c,d),this.triggerRelease(c+b),this},a.Instrument.prototype.dispose=function(){return a.prototype.dispose.call(this),this._writable(["volume"]),this.volume.dispose(),this.volume=null,this},a.Instrument}),ToneModule(function(a){return a.Monophonic=function(b){a.Instrument.call(this),b=this.defaultArg(b,a.Monophonic.defaults),this.portamento=b.portamento},a.extend(a.Monophonic,a.Instrument),a.Monophonic.defaults={portamento:0},a.Monophonic.prototype.triggerAttack=function(a,b,c){return b=this.toSeconds(b),this.triggerEnvelopeAttack(b,c),this.setNote(a,b),this},a.Monophonic.prototype.triggerRelease=function(a){return this.triggerEnvelopeRelease(a),this},a.Monophonic.prototype.triggerEnvelopeAttack=function(){},a.Monophonic.prototype.triggerEnvelopeRelease=function(){},a.Monophonic.prototype.setNote=function(a,b){var c,d;return b=this.toSeconds(b),this.portamento>0?(c=this.frequency.value,this.frequency.setValueAtTime(c,b),d=this.toSeconds(this.portamento),this.frequency.exponentialRampToValueAtTime(a,b+d)):this.frequency.setValueAtTime(a,b),this},a.Monophonic}),ToneModule(function(a){return a.MonoSynth=function(b){b=this.defaultArg(b,a.MonoSynth.defaults),a.Monophonic.call(this,b),this.oscillator=new a.OmniOscillator(b.oscillator),this.frequency=this.oscillator.frequency,this.detune=this.oscillator.detune,this.filter=new a.Filter(b.filter),this.filterEnvelope=new a.ScaledEnvelope(b.filterEnvelope),this.envelope=new a.AmplitudeEnvelope(b.envelope),this.oscillator.chain(this.filter,this.envelope,this.output),this.oscillator.start(),this.filterEnvelope.connect(this.filter.frequency),this._readOnly(["oscillator","frequency","detune","filter","filterEnvelope","envelope"])},a.extend(a.MonoSynth,a.Monophonic),a.MonoSynth.defaults={frequency:"C4",detune:0,oscillator:{type:"square"},filter:{Q:6,type:"lowpass",rolloff:-24},envelope:{attack:.005,decay:.1,sustain:.9,release:1},filterEnvelope:{attack:.06,decay:.2,sustain:.5,release:2,min:20,max:4e3,exponent:2}},a.MonoSynth.prototype.triggerEnvelopeAttack=function(a,b){return this.envelope.triggerAttack(a,b),this.filterEnvelope.triggerAttack(a),this},a.MonoSynth.prototype.triggerEnvelopeRelease=function(a){return this.envelope.triggerRelease(a),this.filterEnvelope.triggerRelease(a),this},a.MonoSynth.prototype.dispose=function(){return a.Monophonic.prototype.dispose.call(this),this._writable(["oscillator","frequency","detune","filter","filterEnvelope","envelope"]),this.oscillator.dispose(),this.oscillator=null,this.envelope.dispose(),this.envelope=null,this.filterEnvelope.dispose(),this.filterEnvelope=null,this.filter.dispose(),this.filter=null,this.frequency=null,this.detune=null,this},a.MonoSynth}),ToneModule(function(a){return a.AMSynth=function(b){b=this.defaultArg(b,a.AMSynth.defaults),a.Monophonic.call(this,b),this.carrier=new a.MonoSynth(b.carrier),this.carrier.volume.value=-10,this.modulator=new a.MonoSynth(b.modulator),this.modulator.volume.value=-10,this.frequency=new a.Signal(440,a.Signal.Units.Frequency),this._harmonicity=new a.Multiply(b.harmonicity),this._modulationScale=new a.AudioToGain,this._modulationNode=this.context.createGain(),this.frequency.connect(this.carrier.frequency),this.frequency.chain(this._harmonicity,this.modulator.frequency),this.modulator.chain(this._modulationScale,this._modulationNode.gain),this.carrier.chain(this._modulationNode,this.output),this._readOnly(["carrier","modulator","frequency"])},a.extend(a.AMSynth,a.Monophonic),a.AMSynth.defaults={harmonicity:3,carrier:{volume:-10,oscillator:{type:"sine"},envelope:{attack:.01,decay:.01,sustain:1,release:.5},filterEnvelope:{attack:.01,decay:0,sustain:1,release:.5,min:2e4,max:2e4},filter:{Q:6,type:"lowpass",rolloff:-24}},modulator:{volume:-10,oscillator:{type:"square"},envelope:{attack:2,decay:0,sustain:1,release:.5},filterEnvelope:{attack:4,decay:.2,sustain:.5,release:.5,min:20,max:1500},filter:{Q:6,type:"lowpass",rolloff:-24}}},a.AMSynth.prototype.triggerEnvelopeAttack=function(a,b){return a=this.toSeconds(a),this.carrier.envelope.triggerAttack(a,b),this.modulator.envelope.triggerAttack(a),this.carrier.filterEnvelope.triggerAttack(a),this.modulator.filterEnvelope.triggerAttack(a),this},a.AMSynth.prototype.triggerEnvelopeRelease=function(a){return this.carrier.triggerRelease(a),this.modulator.triggerRelease(a),this},Object.defineProperty(a.AMSynth.prototype,"harmonicity",{get:function(){return this._harmonicity.value},set:function(a){this._harmonicity.value=a}}),a.AMSynth.prototype.dispose=function(){return a.Monophonic.prototype.dispose.call(this),this._writable(["carrier","modulator","frequency"]),this.carrier.dispose(),this.carrier=null,this.modulator.dispose(),this.modulator=null,this.frequency.dispose(),this.frequency=null,this._harmonicity.dispose(),this._harmonicity=null,this._modulationScale.dispose(),this._modulationScale=null,this._modulationNode.disconnect(),this._modulationNode=null,this},a.AMSynth}),ToneModule(function(a){return a.DroneSynth=function(b){b=this.defaultArg(b,a.DroneSynth.defaults),a.Monophonic.call(this,b),this.oscillator=new a.OmniOscillator(b.oscillator),this.frequency=this.oscillator.frequency,this.detune=this.oscillator.detune,this.envelope=new a.AmplitudeEnvelope(b.envelope),this.oscillator.chain(this.envelope,this.output),this.oscillator.start(),this._readOnly(["oscillator","frequency","detune","envelope"])},a.extend(a.DroneSynth,a.Monophonic),a.DroneSynth.defaults={oscillator:{type:"triangle"},envelope:{attack:.005,decay:.1,sustain:.3,release:1}},a.DroneSynth.prototype.triggerEnvelopeAttack=function(a,b){return this.envelope.triggerAttack(a,b),this},a.DroneSynth.prototype.triggerEnvelopeRelease=function(a){return this.envelope.triggerRelease(a),this},a.DroneSynth.prototype.dispose=function(){return a.Monophonic.prototype.dispose.call(this),this._writable(["oscillator","frequency","detune","envelope"]),this.oscillator.dispose(),this.oscillator=null,this.envelope.dispose(),this.envelope=null,this.frequency=null,this.detune=null,this},a.DroneSynth}),ToneModule(function(a){return a.DrumSynth=function(b){b=this.defaultArg(b,a.DrumSynth.defaults),a.Instrument.call(this,b),this.oscillator=new a.Oscillator(b.oscillator).start(),this.envelope=new a.AmplitudeEnvelope(b.envelope),this.octaves=b.octaves,this.pitchDecay=b.pitchDecay,this.oscillator.chain(this.envelope,this.output),this._readOnly(["oscillator","envelope"])},a.extend(a.DrumSynth,a.Instrument),a.DrumSynth.defaults={pitchDecay:.05,octaves:10,oscillator:{type:"sine"},envelope:{attack:.001,decay:.4,sustain:.01,release:1.4,attackCurve:"exponential"}},a.DrumSynth.prototype.triggerAttack=function(a,b,c){b=this.toSeconds(b),a=this.toFrequency(a);var d=a*this.octaves;return this.oscillator.frequency.setValueAtTime(d,b),this.oscillator.frequency.exponentialRampToValueAtTime(a,b+this.toSeconds(this.pitchDecay)),this.envelope.triggerAttack(b,c),this},a.DrumSynth.prototype.triggerRelease=function(a){return this.envelope.triggerRelease(a),this},a.DrumSynth.prototype.dispose=function(){return a.Instrument.prototype.dispose.call(this),this._writable(["oscillator","envelope"]),this.oscillator.dispose(),this.oscillator=null,this.envelope.dispose(),this.envelope=null,this},a.DrumSynth}),ToneModule(function(a){return a.DuoSynth=function(b){b=this.defaultArg(b,a.DuoSynth.defaults),a.Monophonic.call(this,b),this.voice0=new a.MonoSynth(b.voice0),this.voice0.volume.value=-10,this.voice1=new a.MonoSynth(b.voice1),this.voice1.volume.value=-10,this._vibrato=new a.LFO(b.vibratoRate,-50,50),this._vibrato.start(),this.vibratoRate=this._vibrato.frequency,this._vibratoGain=this.context.createGain(),this.vibratoAmount=new a.Signal(this._vibratoGain.gain,a.Signal.Units.Gain),this.vibratoAmount.value=b.vibratoAmount,this._vibratoDelay=this.toSeconds(b.vibratoDelay),this.frequency=new a.Signal(440,a.Signal.Units.Frequency),this._harmonicity=new a.Multiply(b.harmonicity),this.frequency.connect(this.voice0.frequency),this.frequency.chain(this._harmonicity,this.voice1.frequency),this._vibrato.connect(this._vibratoGain),this._vibratoGain.fan(this.voice0.detune,this.voice1.detune),this.voice0.connect(this.output),this.voice1.connect(this.output),this._readOnly(["voice0","voice1","frequency","vibratoAmount","vibratoRate"])},a.extend(a.DuoSynth,a.Monophonic),a.DuoSynth.defaults={vibratoAmount:.5,vibratoRate:5,vibratoDelay:1,harmonicity:1.5,voice0:{volume:-10,portamento:0,oscillator:{type:"sine"},filterEnvelope:{attack:.01,decay:0,sustain:1,release:.5},envelope:{attack:.01,decay:0,sustain:1,release:.5}},voice1:{volume:-10,portamento:0,oscillator:{type:"sine"},filterEnvelope:{attack:.01,decay:0,sustain:1,release:.5},envelope:{attack:.01,decay:0,sustain:1,release:.5}}},a.DuoSynth.prototype.triggerEnvelopeAttack=function(a,b){return a=this.toSeconds(a),this.voice0.envelope.triggerAttack(a,b),this.voice1.envelope.triggerAttack(a,b),this.voice0.filterEnvelope.triggerAttack(a),this.voice1.filterEnvelope.triggerAttack(a),this},a.DuoSynth.prototype.triggerEnvelopeRelease=function(a){return this.voice0.triggerRelease(a),this.voice1.triggerRelease(a),this},Object.defineProperty(a.DuoSynth.prototype,"harmonicity",{get:function(){return this._harmonicity.value},set:function(a){this._harmonicity.value=a}}),a.DuoSynth.prototype.dispose=function(){return a.Monophonic.prototype.dispose.call(this),this._writable(["voice0","voice1","frequency","vibratoAmount","vibratoRate"]),this.voice0.dispose(),this.voice0=null,this.voice1.dispose(),this.voice1=null,this.frequency.dispose(),this.frequency=null,this._vibrato.dispose(),this._vibrato=null,this._vibratoGain.disconnect(),this._vibratoGain=null,this._harmonicity.dispose(),this._harmonicity=null,this.vibratoAmount.dispose(),this.vibratoAmount=null,this.vibratoRate=null,this},a.DuoSynth}),ToneModule(function(a){return a.FMSynth=function(b){b=this.defaultArg(b,a.FMSynth.defaults),a.Monophonic.call(this,b),this.carrier=new a.MonoSynth(b.carrier),this.carrier.volume.value=-10,this.modulator=new a.MonoSynth(b.modulator),this.modulator.volume.value=-10,this.frequency=new a.Signal(440,a.Signal.Units.Frequency),this._harmonicity=new a.Multiply(b.harmonicity),this._modulationIndex=new a.Multiply(b.modulationIndex),this._modulationNode=this.context.createGain(),this.frequency.connect(this.carrier.frequency),this.frequency.chain(this._harmonicity,this.modulator.frequency),this.frequency.chain(this._modulationIndex,this._modulationNode),this.modulator.connect(this._modulationNode.gain),this._modulationNode.gain.value=0,this._modulationNode.connect(this.carrier.frequency),this.carrier.connect(this.output),this._readOnly(["carrier","modulator","frequency"])},a.extend(a.FMSynth,a.Monophonic),a.FMSynth.defaults={harmonicity:3,modulationIndex:10,carrier:{volume:-10,portamento:0,oscillator:{type:"sine"},envelope:{attack:.01,decay:0,sustain:1,release:.5},filterEnvelope:{attack:.01,decay:0,sustain:1,release:.5,min:2e4,max:2e4}},modulator:{volume:-10,portamento:0,oscillator:{type:"triangle"},envelope:{attack:.01,decay:0,sustain:1,release:.5},filterEnvelope:{attack:.01,decay:0,sustain:1,release:.5,min:2e4,max:2e4}}},a.FMSynth.prototype.triggerEnvelopeAttack=function(a,b){return a=this.toSeconds(a),this.carrier.envelope.triggerAttack(a,b),this.modulator.envelope.triggerAttack(a),this.carrier.filterEnvelope.triggerAttack(a),this.modulator.filterEnvelope.triggerAttack(a),this},a.FMSynth.prototype.triggerEnvelopeRelease=function(a){return this.carrier.triggerRelease(a),this.modulator.triggerRelease(a),this},Object.defineProperty(a.FMSynth.prototype,"harmonicity",{get:function(){return this._harmonicity.value},set:function(a){this._harmonicity.value=a}}),Object.defineProperty(a.FMSynth.prototype,"modulationIndex",{get:function(){return this._modulationIndex.value},set:function(a){this._modulationIndex.value=a}}),a.FMSynth.prototype.dispose=function(){return a.Monophonic.prototype.dispose.call(this),this._writable(["carrier","modulator","frequency"]),this.carrier.dispose(),this.carrier=null,this.modulator.dispose(),this.modulator=null,this.frequency.dispose(),this.frequency=null,this._modulationIndex.dispose(),this._modulationIndex=null,this._harmonicity.dispose(),this._harmonicity=null,this._modulationNode.disconnect(),this._modulationNode=null,this},a.FMSynth}),ToneModule(function(a){a.Noise=function(){var b=this.optionsObject(arguments,["type"],a.Noise.defaults);a.Source.call(this,b),this._source=null,this._buffer=null,this.type=b.type},a.extend(a.Noise,a.Source),a.Noise.defaults={type:"white"},Object.defineProperty(a.Noise.prototype,"type",{get:function(){return this._buffer===d?"white":this._buffer===c?"brown":this._buffer===b?"pink":void 0},set:function(e){if(this.type!==e){switch(e){case"white":this._buffer=d;break;case"pink":this._buffer=b;break;case"brown":this._buffer=c;break;default:this._buffer=d}if(this.state===a.Source.State.STARTED){var f=this.now()+this.bufferTime;this._source.onended=void 0,this._stop(f),this._start(f)}}}}),a.Noise.prototype._start=function(a){this._source=this.context.createBufferSource(),this._source.buffer=this._buffer,this._source.loop=!0,this.connectSeries(this._source,this.output),this._source.start(this.toSeconds(a)),this._source.onended=this.onended},a.Noise.prototype._stop=function(a){this._source&&this._source.stop(this.toSeconds(a))},a.Noise.prototype.dispose=function(){return a.Source.prototype.dispose.call(this),null!==this._source&&(this._source.disconnect(),this._source=null),this._buffer=null,this};var b=null,c=null,d=null;return a._initAudioContext(function(a){var e=a.sampleRate,f=4*e;b=function(){var b,c,d,g,h,i,j,k,l,m,n,o=a.createBuffer(2,f,e);for(b=0;b<o.numberOfChannels;b++)for(c=o.getChannelData(b),d=g=h=i=j=k=l=0,m=0;f>m;m++)n=2*Math.random()-1,d=.99886*d+.0555179*n,g=.99332*g+.0750759*n,h=.969*h+.153852*n,i=.8665*i+.3104856*n,j=.55*j+.5329522*n,k=-.7616*k-.016898*n,c[m]=d+g+h+i+j+k+l+.5362*n,c[m]*=.11,l=.115926*n;return o}(),c=function(){var b,c,d,g,h,i=a.createBuffer(2,f,e);for(b=0;b<i.numberOfChannels;b++)for(c=i.getChannelData(b),d=0,g=0;f>g;g++)h=2*Math.random()-1,c[g]=(d+.02*h)/1.02,d=c[g],c[g]*=3.5;return i}(),d=function(){var b,c,d,g=a.createBuffer(2,f,e);for(b=0;b<g.numberOfChannels;b++)for(c=g.getChannelData(b),d=0;f>d;d++)c[d]=2*Math.random()-1;return g}()}),a.Noise}),ToneModule(function(a){return a.NoiseSynth=function(b){b=this.defaultArg(b,a.NoiseSynth.defaults),a.Instrument.call(this),this.noise=new a.Noise,this.filter=new a.Filter(b.filter),this.filterEnvelope=new a.ScaledEnvelope(b.filterEnvelope),this.envelope=new a.AmplitudeEnvelope(b.envelope),this.noise.chain(this.filter,this.envelope,this.output),this.noise.start(),this.filterEnvelope.connect(this.filter.frequency),this._readOnly(["noise","filter","filterEnvelope","envelope"])},a.extend(a.NoiseSynth,a.Instrument),a.NoiseSynth.defaults={noise:{type:"white"},filter:{Q:6,type:"highpass",rolloff:-24},envelope:{attack:.005,decay:.1,sustain:0},filterEnvelope:{attack:.06,decay:.2,sustain:0,release:2,min:20,max:4e3,exponent:2}},a.NoiseSynth.prototype.triggerAttack=function(a,b){return this.envelope.triggerAttack(a,b),this.filterEnvelope.triggerAttack(a),this},a.NoiseSynth.prototype.triggerRelease=function(a){return this.envelope.triggerRelease(a),this.filterEnvelope.triggerRelease(a),this},a.NoiseSynth.prototype.triggerAttackRelease=function(a,b,c){return b=this.toSeconds(b),a=this.toSeconds(a),this.triggerAttack(b,c),this.triggerRelease(b+a),this},a.NoiseSynth.prototype.dispose=function(){return a.Instrument.prototype.dispose.call(this),this._writable(["noise","filter","filterEnvelope","envelope"]),this.noise.dispose(),this.noise=null,this.envelope.dispose(),this.envelope=null,this.filterEnvelope.dispose(),this.filterEnvelope=null,this.filter.dispose(),this.filter=null,this},a.NoiseSynth}),ToneModule(function(a){return a.PluckSynth=function(b){b=this.defaultArg(b,a.PluckSynth.defaults),a.Instrument.call(this),this._noise=new a.Noise("pink"),this.attackNoise=1,this._lfcf=new a.LowpassCombFilter(1/440),this.resonance=this._lfcf.resonance,this.dampening=this._lfcf.dampening,this._noise.connect(this._lfcf),this._lfcf.connect(this.output),this._readOnly(["resonance","dampening"])},a.extend(a.PluckSynth,a.Instrument),a.PluckSynth.defaults={attackNoise:1,dampening:4e3,resonance:.5},a.PluckSynth.prototype.triggerAttack=function(a,b){a=this.toFrequency(a),b=this.toSeconds(b);
|
|
var c=1/a;return this._lfcf.delayTime.setValueAtTime(c,b),this._noise.start(b),this._noise.stop(b+c*this.attackNoise),this},a.PluckSynth.prototype.dispose=function(){return a.Instrument.prototype.dispose.call(this),this._noise.dispose(),this._lfcf.dispose(),this._noise=null,this._lfcf=null,this._writable(["resonance","dampening"]),this.dampening=null,this.resonance=null,this},a.PluckSynth}),ToneModule(function(a){return a.PolySynth=function(){var b,c,d;for(a.Instrument.call(this),b=this.optionsObject(arguments,["polyphony","voice"],a.PolySynth.defaults),this.voices=new Array(b.polyphony),this._freeVoices=[],this._activeVoices={},c=0;c<b.polyphony;c++)d=new b.voice(arguments[2],arguments[3]),this.voices[c]=d,d.connect(this.output);this._freeVoices=this.voices.slice(0)},a.extend(a.PolySynth,a.Instrument),a.PolySynth.defaults={polyphony:4,voice:a.MonoSynth},a.PolySynth.prototype.triggerAttack=function(a,b,c){var d,e,f,g;for(Array.isArray(a)||(a=[a]),d=0;d<a.length;d++)e=a[d],f=JSON.stringify(e),this._activeVoices[f]?this._activeVoices[f].triggerAttack(e,b,c):this._freeVoices.length>0&&(g=this._freeVoices.shift(),g.triggerAttack(e,b,c),this._activeVoices[f]=g);return this},a.PolySynth.prototype.triggerAttackRelease=function(a,b,c,d){return c=this.toSeconds(c),this.triggerAttack(a,c,d),this.triggerRelease(a,c+this.toSeconds(b)),this},a.PolySynth.prototype.triggerRelease=function(a,b){var c,d,e;for(Array.isArray(a)||(a=[a]),c=0;c<a.length;c++)d=JSON.stringify(a[c]),e=this._activeVoices[d],e&&(e.triggerRelease(b),this._freeVoices.push(e),delete this._activeVoices[d],e=null);return this},a.PolySynth.prototype.set=function(a,b,c){for(var d=0;d<this.voices.length;d++)this.voices[d].set(a,b,c);return this},a.PolySynth.prototype.get=function(a){return this.voices[0].get(a)},a.PolySynth.prototype.setPreset=function(a){for(var b=0;b<this.voices.length;b++)this.voices[b].setPreset(a);return this},a.PolySynth.prototype.dispose=function(){a.Instrument.prototype.dispose.call(this);for(var b=0;b<this.voices.length;b++)this.voices[b].dispose(),this.voices[b]=null;return this.voices=null,this._activeVoices=null,this._freeVoices=null,this},a.PolySynth}),ToneModule(function(a){return a.Player=function(){var b=this.optionsObject(arguments,["url","onload"],a.Player.defaults);a.Source.call(this,b),this._source=null,this.autostart=b.autostart,this._buffer=new a.Buffer({url:b.url,onload:this._onload.bind(this,b.onload),reverse:b.reverse}),this._loop=b.loop,this._loopStart=b.loopStart,this._loopEnd=b.loopEnd,this._playbackRate=b.playbackRate,this.retrigger=b.retrigger},a.extend(a.Player,a.Source),a.Player.defaults={onload:function(){},playbackRate:1,loop:!1,autostart:!1,loopStart:0,loopEnd:0,retrigger:!1,reverse:!1},a.Player.prototype.load=function(a,b){return this._buffer.load(a,this._onload.bind(this,b)),this},a.Player.prototype._onload=function(a){a(this),this.autostart&&this.start()},a.Player.prototype._start=function(a,b,c){if(!this._buffer.loaded)throw Error("tried to start Player before the buffer was loaded");return b=this._loop?this.defaultArg(b,this._loopStart):this.defaultArg(b,0),b=this.toSeconds(b),c=this.defaultArg(c,this._buffer.duration-b),a=this.toSeconds(a),c=this.toSeconds(c),this._source=this.context.createBufferSource(),this._source.buffer=this._buffer.get(),this._loop?(this._source.loop=this._loop,this._source.loopStart=this.toSeconds(this._loopStart),this._source.loopEnd=this.toSeconds(this._loopEnd),c=65536):this._nextStop=a+c,this._source.playbackRate.value=this._playbackRate,this._source.onended=this.onended,this._source.connect(this.output),this._source.start(a,b,c),this},a.Player.prototype._stop=function(a){return this._source&&(this._source.stop(this.toSeconds(a)),this._source=null),this},a.Player.prototype.setLoopPoints=function(a,b){return this.loopStart=a,this.loopEnd=b,this},Object.defineProperty(a.Player.prototype,"loopStart",{get:function(){return this._loopStart},set:function(a){this._loopStart=a,this._source&&(this._source.loopStart=this.toSeconds(a))}}),Object.defineProperty(a.Player.prototype,"loopEnd",{get:function(){return this._loopEnd},set:function(a){this._loopEnd=a,this._source&&(this._source.loopEnd=this.toSeconds(a))}}),Object.defineProperty(a.Player.prototype,"buffer",{get:function(){return this._buffer},set:function(a){this._buffer.set(a)}}),Object.defineProperty(a.Player.prototype,"loop",{get:function(){return this._loop},set:function(a){this._loop=a,this._source&&(this._source.loop=a)}}),Object.defineProperty(a.Player.prototype,"playbackRate",{get:function(){return this._playbackRate},set:function(a){this._playbackRate=a,this._source&&(this._source.playbackRate.value=a)}}),Object.defineProperty(a.Player.prototype,"reverse",{get:function(){return this._buffer.reverse},set:function(a){this._buffer.reverse=a}}),a.Player.prototype.dispose=function(){return a.Source.prototype.dispose.call(this),null!==this._source&&(this._source.disconnect(),this._source=null),this._buffer.dispose(),this._buffer=null,this},a.Player}),ToneModule(function(a){return a.Sampler=function(b,c){a.Instrument.call(this),c=this.defaultArg(c,a.Sampler.defaults),this.player=new a.Player(c.player),this.player.retrigger=!0,this._buffers={},this.envelope=new a.AmplitudeEnvelope(c.envelope),this.filterEnvelope=new a.ScaledEnvelope(c.filterEnvelope),this._sample=c.sample,this._pitch=c.pitch,this.filter=new a.Filter(c.filter),this._loadBuffers(b),this.pitch=c.pitch,this.player.chain(this.filter,this.envelope,this.output),this.filterEnvelope.connect(this.filter.frequency),this._readOnly(["player","filterEnvelope","envelope","filter"])},a.extend(a.Sampler,a.Instrument),a.Sampler.defaults={sample:0,pitch:0,player:{loop:!1},envelope:{attack:.001,decay:0,sustain:1,release:.1},filterEnvelope:{attack:.001,decay:.001,sustain:1,release:.5,min:20,max:2e4,exponent:2},filter:{type:"lowpass"}},a.Sampler.prototype._loadBuffers=function(b){var c,d;if("string"==typeof b)this._buffers[0]=new a.Buffer(b,function(){this.sample="0"}.bind(this));else{b=this._flattenUrls(b);for(c in b)this._sample=c,d=b[c],this._buffers[c]=new a.Buffer(d)}},a.Sampler.prototype._flattenUrls=function(a){var b,c,d,e={};for(b in a)if(a.hasOwnProperty(b))if("object"==typeof a[b]){c=this._flattenUrls(a[b]);for(d in c)c.hasOwnProperty(d)&&(e[b+"."+d]=c[d])}else e[b]=a[b];return e},a.Sampler.prototype.triggerAttack=function(a,b,c){return b=this.toSeconds(b),a&&(this.sample=a),this.player.start(b),this.envelope.triggerAttack(b,c),this.filterEnvelope.triggerAttack(b),this},a.Sampler.prototype.triggerRelease=function(a){return a=this.toSeconds(a),this.filterEnvelope.triggerRelease(a),this.envelope.triggerRelease(a),this.player.stop(this.toSeconds(this.envelope.release)+a),this},Object.defineProperty(a.Sampler.prototype,"sample",{get:function(){return this._sample},set:function(a){if(!this._buffers.hasOwnProperty(a))throw new Error("Sampler does not have a sample named "+a);this._sample=a,this.player.buffer=this._buffers[a]}}),Object.defineProperty(a.Sampler.prototype,"reverse",{get:function(){for(var a in this._buffers)return this._buffers[a].reverse},set:function(a){for(var b in this._buffers)this._buffers[b].reverse=a}}),Object.defineProperty(a.Sampler.prototype,"pitch",{get:function(){return this._pitch},set:function(a){this._pitch=a,this.player.playbackRate=this.intervalToFrequencyRatio(a)}}),a.Sampler.prototype.dispose=function(){a.Instrument.prototype.dispose.call(this),this._writable(["player","filterEnvelope","envelope","filter"]),this.player.dispose(),this.filterEnvelope.dispose(),this.envelope.dispose(),this.filter.dispose(),this.player=null,this.filterEnvelope=null,this.envelope=null,this.filter=null;for(var b in this._buffers)this._buffers[b].dispose(),this._buffers[b]=null;return this._buffers=null,this},a.Sampler}),ToneModule(function(a){return a.SimpleSynth=function(b){b=this.defaultArg(b,a.SimpleSynth.defaults),a.Monophonic.call(this,b),this.oscillator=new a.OmniOscillator(b.oscillator),this.frequency=this.oscillator.frequency,this.detune=this.oscillator.detune,this.envelope=new a.AmplitudeEnvelope(b.envelope),this.oscillator.chain(this.envelope,this.output),this.oscillator.start(),this._readOnly(["oscillator","frequency","detune","envelope"])},a.extend(a.SimpleSynth,a.Monophonic),a.SimpleSynth.defaults={oscillator:{type:"triangle"},envelope:{attack:.005,decay:.1,sustain:.3,release:1}},a.SimpleSynth.prototype.triggerEnvelopeAttack=function(a,b){return this.envelope.triggerAttack(a,b),this},a.SimpleSynth.prototype.triggerEnvelopeRelease=function(a){return this.envelope.triggerRelease(a),this},a.SimpleSynth.prototype.dispose=function(){return a.Monophonic.prototype.dispose.call(this),this._writable(["oscillator","frequency","detune","envelope"]),this.oscillator.dispose(),this.oscillator=null,this.envelope.dispose(),this.envelope=null,this.frequency=null,this.detune=null,this},a.SimpleSynth}),ToneModule(function(a){return a.SimpleAM=function(b){b=this.defaultArg(b,a.SimpleAM.defaults),a.Monophonic.call(this,b),this.carrier=new a.SimpleSynth(b.carrier),this.carrier.volume.value=-10,this.modulator=new a.SimpleSynth(b.modulator),this.modulator.volume.value=-10,this.frequency=new a.Signal(440,a.Signal.Units.Frequency),this._harmonicity=new a.Multiply(b.harmonicity),this._modulationScale=new a.AudioToGain,this._modulationNode=this.context.createGain(),this.frequency.connect(this.carrier.frequency),this.frequency.chain(this._harmonicity,this.modulator.frequency),this.modulator.chain(this._modulationScale,this._modulationNode.gain),this.carrier.chain(this._modulationNode,this.output),this._readOnly(["carrier","modulator","frequency"])},a.extend(a.SimpleAM,a.Monophonic),a.SimpleAM.defaults={harmonicity:3,carrier:{volume:-10,portamento:0,oscillator:{type:"sine"},envelope:{attack:.01,decay:.01,sustain:1,release:.5}},modulator:{volume:-10,portamento:0,oscillator:{type:"square"},envelope:{attack:2,decay:0,sustain:1,release:.5}}},a.SimpleAM.prototype.triggerEnvelopeAttack=function(a,b){return a=this.toSeconds(a),this.carrier.envelope.triggerAttack(a,b),this.modulator.envelope.triggerAttack(a),this},a.SimpleAM.prototype.triggerEnvelopeRelease=function(a){return this.carrier.triggerRelease(a),this.modulator.triggerRelease(a),this},Object.defineProperty(a.SimpleAM.prototype,"harmonicity",{get:function(){return this._harmonicity.value},set:function(a){this._harmonicity.value=a}}),a.SimpleAM.prototype.dispose=function(){return a.Monophonic.prototype.dispose.call(this),this._writable(["carrier","modulator","frequency"]),this.carrier.dispose(),this.carrier=null,this.modulator.dispose(),this.modulator=null,this.frequency.dispose(),this.frequency=null,this._harmonicity.dispose(),this._harmonicity=null,this._modulationScale.dispose(),this._modulationScale=null,this._modulationNode.disconnect(),this._modulationNode=null,this},a.SimpleAM}),ToneModule(function(a){return a.SimpleFM=function(b){b=this.defaultArg(b,a.SimpleFM.defaults),a.Monophonic.call(this,b),this.carrier=new a.SimpleSynth(b.carrier),this.carrier.volume.value=-10,this.modulator=new a.SimpleSynth(b.modulator),this.modulator.volume.value=-10,this.frequency=new a.Signal(440,a.Signal.Units.Frequency),this._harmonicity=new a.Multiply(b.harmonicity),this._modulationIndex=new a.Multiply(b.modulationIndex),this._modulationNode=this.context.createGain(),this.frequency.connect(this.carrier.frequency),this.frequency.chain(this._harmonicity,this.modulator.frequency),this.frequency.chain(this._modulationIndex,this._modulationNode),this.modulator.connect(this._modulationNode.gain),this._modulationNode.gain.value=0,this._modulationNode.connect(this.carrier.frequency),this.carrier.connect(this.output),this._readOnly(["carrier","modulator","frequency"])},a.extend(a.SimpleFM,a.Monophonic),a.SimpleFM.defaults={harmonicity:3,modulationIndex:10,carrier:{volume:-10,portamento:0,oscillator:{type:"sine"},envelope:{attack:.01,decay:0,sustain:1,release:.5}},modulator:{volume:-10,portamento:0,oscillator:{type:"triangle"},envelope:{attack:.01,decay:0,sustain:1,release:.5}}},a.SimpleFM.prototype.triggerEnvelopeAttack=function(a,b){return a=this.toSeconds(a),this.carrier.envelope.triggerAttack(a,b),this.modulator.envelope.triggerAttack(a),this},a.SimpleFM.prototype.triggerEnvelopeRelease=function(a){return this.carrier.triggerRelease(a),this.modulator.triggerRelease(a),this},Object.defineProperty(a.SimpleFM.prototype,"harmonicity",{get:function(){return this._harmonicity.value},set:function(a){this._harmonicity.value=a}}),Object.defineProperty(a.SimpleFM.prototype,"modulationIndex",{get:function(){return this._modulationIndex.value},set:function(a){this._modulationIndex.value=a}}),a.SimpleFM.prototype.dispose=function(){return a.Monophonic.prototype.dispose.call(this),this._writable(["carrier","modulator","frequency"]),this.carrier.dispose(),this.carrier=null,this.modulator.dispose(),this.modulator=null,this.frequency.dispose(),this.frequency=null,this._modulationIndex.dispose(),this._modulationIndex=null,this._harmonicity.dispose(),this._harmonicity=null,this._modulationNode.disconnect(),this._modulationNode=null,this},a.SimpleFM}),ToneModule(function(a){return a.Clip=function(b,c){if(b>c){var d=b;b=c,c=d}this.min=this.input=new a.Min(c),this._readOnly("min"),this.max=this.output=new a.Max(b),this._readOnly("max"),this.min.connect(this.max)},a.extend(a.Clip,a.SignalBase),a.Clip.prototype.dispose=function(){return a.prototype.dispose.call(this),this._writable("min"),this.min.dispose(),this.min=null,this._writable("max"),this.max.dispose(),this.max=null,this},a.Clip}),ToneModule(function(a){return a.Normalize=function(b,c){this._inputMin=this.defaultArg(b,0),this._inputMax=this.defaultArg(c,1),this._sub=this.input=new a.Add(0),this._div=this.output=new a.Multiply(1),this._sub.connect(this._div),this._setRange()},a.extend(a.Normalize,a.SignalBase),Object.defineProperty(a.Normalize.prototype,"min",{get:function(){return this._inputMin},set:function(a){this._inputMin=a,this._setRange()}}),Object.defineProperty(a.Normalize.prototype,"max",{get:function(){return this._inputMax},set:function(a){this._inputMax=a,this._setRange()}}),a.Normalize.prototype._setRange=function(){this._sub.value=-this._inputMin,this._div.value=1/(this._inputMax-this._inputMin)},a.Normalize.prototype.dispose=function(){return a.prototype.dispose.call(this),this._sub.dispose(),this._sub=null,this._div.dispose(),this._div=null,this},a.Normalize}),ToneModule(function(a){a.Route=function(c){var d,e;for(c=this.defaultArg(c,2),a.call(this,1,c),this.gate=new a.Signal(0),this._readOnly("gate"),d=0;c>d;d++)e=new b(d),this.output[d]=e,this.gate.connect(e.selecter),this.input.connect(e)},a.extend(a.Route,a.SignalBase),a.Route.prototype.select=function(a,b){return a=Math.floor(a),this.gate.setValueAtTime(a,this.toSeconds(b)),this},a.Route.prototype.dispose=function(){this._writable("gate"),this.gate.dispose(),this.gate=null;for(var b=0;b<this.output.length;b++)this.output[b].dispose(),this.output[b]=null;return a.prototype.dispose.call(this),this};var b=function(b){this.selecter=new a.Equal(b),this.gate=this.input=this.output=this.context.createGain(),this.selecter.connect(this.gate.gain)};return a.extend(b),b.prototype.dispose=function(){a.prototype.dispose.call(this),this.selecter.dispose(),this.selecter=null,this.gate.disconnect(),this.gate=null},a.Route}),ToneModule(function(a){return a.Switch=function(){a.call(this),this.gate=new a.Signal(0),this._readOnly("gate"),this._thresh=new a.GreaterThan(.5),this.input.connect(this.output),this.gate.chain(this._thresh,this.output.gain)},a.extend(a.Switch,a.SignalBase),a.Switch.prototype.open=function(a){return this.gate.setValueAtTime(1,this.toSeconds(a)),this},a.Switch.prototype.close=function(a){return this.gate.setValueAtTime(0,this.toSeconds(a)),this},a.Switch.prototype.dispose=function(){return a.prototype.dispose.call(this),this._writable("gate"),this.gate.dispose(),this.gate=null,this._thresh.dispose(),this._thresh=null,this},a.Switch}),ToneModule(function(a){return a.Microphone=function(b){a.Source.call(this),this._mediaStream=null,this._stream=null,this._constraints={audio:!0};var c=this;MediaStreamTrack.getSources(function(a){b<a.length&&(c.constraints.audio={optional:[{sourceId:a[b].id}]})})},a.extend(a.Microphone,a.Source),a.Microphone.prototype._start=function(){navigator.getUserMedia(this._constraints,this._onStream.bind(this),this._onStreamError.bind(this))},a.Microphone.prototype._stop=function(){return this._stream.stop(),this},a.Microphone.prototype._onStream=function(a){this._stream=a,this._mediaStream=this.context.createMediaStreamSource(a),this._mediaStream.connect(this.output)},a.Microphone.prototype._onStreamError=function(a){console.error(a)},a.Microphone.prototype.dispose=function(){return a.Source.prototype.dispose.call(this),this._mediaStream&&(this._mediaStream.disconnect(),this._mediaStream=null),this._stream=null,this._constraints=null,this},navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia,a.Microphone}),"function"==typeof define&&define.amd?define("Tone",[],function(){return Tone}):"object"==typeof module?module.exports=Tone:root.Tone=Tone}(this); |