tone
Version:
A Web Audio framework for making interactive music in the browser.
8 lines • 240 kB
JavaScript
!function(t,e){"function"==typeof define&&define.amd?define(function(){return e()}):"object"==typeof module?module.exports=e():t.Tone=e()}(this,function(){"use strict";function t(t){t(e)}var e;/**
* Tone.js
* @author Yotam Mann
* @license http://opensource.org/licenses/MIT MIT License
* @copyright 2014-2017 Yotam Mann
*/
return function(t){e=t()}(function(){var t=function(){if(!(this instanceof t))throw new Error("constructor needs to be called with the 'new' keyword")};return t.prototype.toString=function(){var e,i,n;for(e in t)if(i=e[0].match(/^[A-Z]$/),n=t[e]===this.constructor,t.isFunction(t[e])&&i&&n)return e;return"Tone"},t.prototype.dispose=function(){return this},t.prototype.set=function(e,i,n){var s,o,r,a,l,h,u;t.isObject(e)?n=i:t.isString(e)&&(s={},s[e]=i,e=s);t:for(o in e){if(i=e[o],r=this,-1!==o.indexOf(".")){for(a=o.split("."),l=0;l<a.length-1;l++)if((r=r[a[l]])instanceof t){a.splice(0,l+1),h=a.join("."),r.set(h,i);continue t}o=a[a.length-1]}u=r[o],t.isUndef(u)||(t.Signal&&u instanceof t.Signal||t.Param&&u instanceof t.Param?u.value!==i&&(t.isUndef(n)?u.value=i:u.rampTo(i,n)):u instanceof AudioParam?u.value!==i&&(u.value=i):t.TimeBase&&u instanceof t.TimeBase?r[o]=i:u instanceof t?u.set(i):u!==i&&(r[o]=i))}return this},t.prototype.get=function(e){var i,n,s,o,r,a,l,h,u;for(t.isUndef(e)?e=this._collectDefaults(this.constructor):t.isString(e)&&(e=[e]),i={},n=0;n<e.length;n++){if(s=e[n],o=this,r=i,-1!==s.indexOf(".")){for(a=s.split("."),l=0;l<a.length-1;l++)h=a[l],r[h]=r[h]||{},r=r[h],o=o[h];s=a[a.length-1]}u=o[s],t.isObject(e[s])?r[s]=u.get():t.Signal&&u instanceof t.Signal?r[s]=u.value:t.Param&&u instanceof t.Param?r[s]=u.value:u instanceof AudioParam?r[s]=u.value:u instanceof t?r[s]=u.get():t.isFunction(u)||t.isUndef(u)||(r[s]=u)}return i},t.prototype._collectDefaults=function(e){var i,n,s=[];if(t.isUndef(e.defaults)||(s=Object.keys(e.defaults)),!t.isUndef(e._super))for(i=this._collectDefaults(e._super),n=0;n<i.length;n++)-1===s.indexOf(i[n])&&s.push(i[n]);return s},t.defaults=function(e,i,n){var s,o={};if(1===e.length&&t.isObject(e[0]))o=e[0];else for(s=0;s<i.length;s++)o[i[s]]=e[s];return t.isUndef(n.defaults)?t.isObject(n)?t.defaultArg(o,n):o:t.defaultArg(o,n.defaults)},t.defaultArg=function(e,i){var n,s,o;if(t.isObject(e)&&t.isObject(i)){n={};for(s in e)n[s]=t.defaultArg(i[s],e[s]);for(o in i)n[o]=t.defaultArg(e[o],i[o]);return n}return t.isUndef(e)?i:e},t.connectSeries=function(){var e,i,n=arguments[0];for(e=1;e<arguments.length;e++)i=arguments[e],n.connect(i),n=i;return t},t.isUndef=function(t){return void 0===t},t.isFunction=function(t){return"function"==typeof t},t.isNumber=function(t){return"number"==typeof t},t.isObject=function(t){return"[object Object]"===Object.prototype.toString.call(t)&&t.constructor===Object},t.isBoolean=function(t){return"boolean"==typeof t},t.isArray=function(t){return Array.isArray(t)},t.isString=function(t){return"string"==typeof t},t.isNote=function(e){return t.isString(e)&&/^([a-g]{1}(?:b|#|x|bb)?)(-?[0-9]+)/i.test(e)},t.noOp=function(){},t.prototype._readOnly=function(t){if(Array.isArray(t))for(var e=0;e<t.length;e++)this._readOnly(t[e]);else Object.defineProperty(this,t,{writable:!1,enumerable:!0})},t.prototype._writable=function(t){if(Array.isArray(t))for(var e=0;e<t.length;e++)this._writable(t[e]);else Object.defineProperty(this,t,{writable:!0})},t.State={Started:"started",Stopped:"stopped",Paused:"paused"},t.equalPowerScale=function(t){var e=.5*Math.PI;return Math.sin(t*e)},t.dbToGain=function(t){return Math.pow(10,t/20)},t.gainToDb=function(t){return Math.log(t)/Math.LN10*20},t.intervalToFrequencyRatio=function(t){return Math.pow(2,t/12)},t.prototype.now=function(){return t.context.now()},t.now=function(){return t.context.now()},t.isPast=function(e){e<t.context.currentTime&&console.warn("Time '"+e+"' is in the past. Scheduled time must be ≥ AudioContext.currentTime")},t.extend=function(e,i){function n(){}t.isUndef(i)&&(i=t),n.prototype=i.prototype,e.prototype=new n,e.prototype.constructor=e,e._super=i},Object.defineProperty(t,"context",{get:function(){return window.TONE_AUDIO_CONTEXT},set:function(e){t.Context&&e instanceof t.Context?window.TONE_AUDIO_CONTEXT=e:window.TONE_AUDIO_CONTEXT=new t.Context(e),t.Context.emit("init",window.TONE_AUDIO_CONTEXT)}}),Object.defineProperty(t.prototype,"context",{get:function(){return t.context}}),t.setContext=function(e){t.context=e},Object.defineProperty(t.prototype,"blockTime",{get:function(){return 128/this.context.sampleRate}}),Object.defineProperty(t.prototype,"sampleTime",{get:function(){return 1/this.context.sampleRate}}),Object.defineProperty(t,"supported",{get:function(){var t=window.hasOwnProperty("AudioContext")||window.hasOwnProperty("webkitAudioContext"),e=window.hasOwnProperty("Promise"),i=window.hasOwnProperty("Worker");return t&&e&&i}}),Object.defineProperty(t,"initialized",{get:function(){return!t.isUndef(window.TONE_AUDIO_CONTEXT)}}),t.getContext=function(e){if(t.initialized)e(t.context);else{var i=function(){e(t.context),t.Context.off("init",i)};t.Context.on("init",i)}return t},t.version="r12-dev",t}),t(function(t){return t.Emitter=function(){t.call(this),this._events={}},t.extend(t.Emitter),t.Emitter.prototype.on=function(t,e){var i,n,s=t.split(/\W+/);for(i=0;i<s.length;i++)n=s[i],this._events.hasOwnProperty(n)||(this._events[n]=[]),this._events[n].push(e);return this},t.Emitter.prototype.once=function(t,e){var i=function(){e.apply(this,arguments),this.off(t,i)}.bind(this);return this.on(t,i),this},t.Emitter.prototype.off=function(e,i){var n,s,o,r=e.split(/\W+/);for(n=0;n<r.length;n++)if(e=r[n],this._events.hasOwnProperty(e))if(t.isUndef(i))this._events[e]=[];else for(s=this._events[e],o=0;o<s.length;o++)s[o]===i&&s.splice(o,1);return this},t.Emitter.prototype.emit=function(t){var e,i,n,s;if(this._events&&(e=Array.apply(null,arguments).slice(1),this._events.hasOwnProperty(t)))for(i=this._events[t].slice(0),n=0,s=i.length;n<s;n++)i[n].apply(this,e);return this},t.Emitter.mixin=function(e){var i,n,s,o=["on","once","off","emit"];for(e._events={},i=0;i<o.length;i++)n=o[i],s=t.Emitter.prototype[n],e[n]=s;return t.Emitter},t.Emitter.prototype.dispose=function(){return t.prototype.dispose.call(this),this._events=null,this},t.Emitter}),t(function(t){return t.Timeline=function(){var e=t.defaults(arguments,["memory"],t.Timeline);t.call(this),this._timeline=[],this.memory=e.memory},t.extend(t.Timeline),t.Timeline.defaults={memory:1/0},Object.defineProperty(t.Timeline.prototype,"length",{get:function(){return this._timeline.length}}),t.Timeline.prototype.add=function(e){var i,n;if(t.isUndef(e.time))throw new Error("Tone.Timeline: events must have a time attribute");return e.time=e.time.valueOf(),i=this._search(e.time),this._timeline.splice(i+1,0,e),this.length>this.memory&&(n=this.length-this.memory,this._timeline.splice(0,n)),this},t.Timeline.prototype.remove=function(t){var e=this._timeline.indexOf(t);return-1!==e&&this._timeline.splice(e,1),this},t.Timeline.prototype.get=function(e,i){i=t.defaultArg(i,"time");var n=this._search(e,i);return-1!==n?this._timeline[n]:null},t.Timeline.prototype.peek=function(){return this._timeline[0]},t.Timeline.prototype.shift=function(){return this._timeline.shift()},t.Timeline.prototype.getAfter=function(e,i){i=t.defaultArg(i,"time");var n=this._search(e,i);return n+1<this._timeline.length?this._timeline[n+1]:null},t.Timeline.prototype.getBefore=function(e,i){var n,s;return i=t.defaultArg(i,"time"),(n=this._timeline.length)>0&&this._timeline[n-1][i]<e?this._timeline[n-1]:(s=this._search(e,i),s-1>=0?this._timeline[s-1]:null)},t.Timeline.prototype.cancel=function(t){var e,i;if(this._timeline.length>1)if((e=this._search(t))>=0)if(this._timeline[e].time===t){for(i=e;i>=0&&this._timeline[i].time===t;i--)e=i;this._timeline=this._timeline.slice(0,e)}else this._timeline=this._timeline.slice(0,e+1);else this._timeline=[];else 1===this._timeline.length&&this._timeline[0].time>=t&&(this._timeline=[]);return this},t.Timeline.prototype.cancelBefore=function(t){var e=this._search(t);return e>=0&&(this._timeline=this._timeline.slice(e+1)),this},t.Timeline.prototype.previousEvent=function(t){var e=this._timeline.indexOf(t);return e>0?this._timeline[e-1]:null},t.Timeline.prototype._search=function(e,i){var n,s,o,r,a,l,h,u;if(0===this._timeline.length)return-1;if(i=t.defaultArg(i,"time"),n=0,s=this._timeline.length,o=s,s>0&&this._timeline[s-1][i]<=e)return s-1;for(;n<o;){if(r=Math.floor(n+(o-n)/2),a=this._timeline[r],l=this._timeline[r+1],a[i]===e){for(h=r;h<this._timeline.length;h++)u=this._timeline[h],u[i]===e&&(r=h);return r}if(a[i]<e&&l[i]>e)return r;a[i]>e?o=r:n=r+1}return-1},t.Timeline.prototype._iterate=function(e,i,n){i=t.defaultArg(i,0),n=t.defaultArg(n,this._timeline.length-1),this._timeline.slice(i,n+1).forEach(function(t){e.call(this,t)}.bind(this))},t.Timeline.prototype.forEach=function(t){return this._iterate(t),this},t.Timeline.prototype.forEachBefore=function(t,e){var i=this._search(t);return-1!==i&&this._iterate(e,0,i),this},t.Timeline.prototype.forEachAfter=function(t,e){var i=this._search(t);return this._iterate(e,i+1),this},t.Timeline.prototype.forEachBetween=function(t,e,i){var n=this._search(t),s=this._search(e);return-1!==n&&-1!==s?(this._timeline[n].time!==t&&(n+=1),this._iterate(i,n,s)):-1===n&&this._iterate(i,0,s),this},t.Timeline.prototype.forEachFrom=function(t,e){for(var i=this._search(t);i>=0&&this._timeline[i].time>=t;)i--;return this._iterate(e,i+1),this},t.Timeline.prototype.forEachAtTime=function(t,e){var i=this._search(t);return-1!==i&&this._iterate(function(i){i.time===t&&e.call(this,i)},0,i),this},t.Timeline.prototype.dispose=function(){return t.prototype.dispose.call(this),this._timeline=null,this},t.Timeline}),t(function(t){var e;t.supported&&(!window.hasOwnProperty("OfflineAudioContext")&&window.hasOwnProperty("webkitOfflineAudioContext")&&(window.OfflineAudioContext=window.webkitOfflineAudioContext),e=new OfflineAudioContext(1,1,44100),e.startRendering()instanceof Promise||(OfflineAudioContext.prototype._native_startRendering=OfflineAudioContext.prototype.startRendering,OfflineAudioContext.prototype.startRendering=function(){return new Promise(function(t){this.oncomplete=function(e){t(e.renderedBuffer)},this._native_startRendering()}.bind(this))}))}),t(function(t){var e,i,n,s;if(t.supported){!window.hasOwnProperty("AudioContext")&&window.hasOwnProperty("webkitAudioContext")&&(window.AudioContext=window.webkitAudioContext),AudioContext.prototype.close||(AudioContext.prototype.close=function(){return t.isFunction(this.suspend)?this.suspend():Promise.resolve()}),AudioContext.prototype.resume||(AudioContext.prototype.resume=function(){return Promise.resolve()}),!AudioContext.prototype.createGain&&AudioContext.prototype.createGainNode&&(AudioContext.prototype.createGain=AudioContext.prototype.createGainNode),!AudioContext.prototype.createDelay&&AudioContext.prototype.createDelayNode&&(AudioContext.prototype.createDelay=AudioContext.prototype.createDelayNode),e=!1,i=new OfflineAudioContext(1,1,44100),n=new Uint32Array([1179011410,48,1163280727,544501094,16,131073,44100,176400,1048580,1635017060,8,0,0,0,0]).buffer;try{s=i.decodeAudioData(n),s instanceof Promise&&(e=!0)}catch(t){e=!1}e||(AudioContext.prototype._native_decodeAudioData=AudioContext.prototype.decodeAudioData,AudioContext.prototype.decodeAudioData=function(t){return new Promise(function(e,i){this._native_decodeAudioData(t,e,i)}.bind(this))})}}),t(function(t){t.Context=function(){var i,n;if(t.Emitter.call(this),i=t.defaults(arguments,["context"],t.Context),!i.context&&(i.context=new window.AudioContext,!i.context))throw new Error("could not create AudioContext. Possibly too many AudioContexts running already.");this._context=i.context;for(n in this._context)this._defineProperty(this._context,n);this._latencyHint=i.latencyHint,this._constants={},this.lookAhead=i.lookAhead,this._computedUpdateInterval=0,this._ticker=new e(this.emit.bind(this,"tick"),i.clockSource,i.updateInterval),this._timeouts=new t.Timeline,this._timeoutIds=0,this.on("tick",this._timeoutLoop.bind(this))},t.extend(t.Context,t.Emitter),t.Emitter.mixin(t.Context),t.Context.defaults={clockSource:"worker",latencyHint:"interactive",lookAhead:.1,updateInterval:.03},t.Context.prototype._defineProperty=function(e,i){t.isUndef(this[i])&&Object.defineProperty(this,i,{get:function(){return"function"==typeof e[i]?e[i].bind(e):e[i]},set:function(t){e[i]=t}})},t.Context.prototype.now=function(){return this._context.currentTime+this.lookAhead},t.Context.prototype.ready=function(){return new Promise(function(t){"running"===this._context.state?t():this._context.resume().then(function(){t()})}.bind(this))},t.Context.prototype.close=function(){return this._context.close().then(function(){t.Context.emit("close",this)}.bind(this))},t.Context.prototype.getConstant=function(t){var e,i,n,s;if(this._constants[t])return this._constants[t];for(e=this._context.createBuffer(1,128,this._context.sampleRate),i=e.getChannelData(0),n=0;n<i.length;n++)i[n]=t;return s=this._context.createBufferSource(),s.channelCount=1,s.channelCountMode="explicit",s.buffer=e,s.loop=!0,s.start(0),this._constants[t]=s,s},t.Context.prototype._timeoutLoop=function(){for(var t=this.now();this._timeouts&&this._timeouts.length&&this._timeouts.peek().time<=t;)this._timeouts.shift().callback()},t.Context.prototype.setTimeout=function(t,e){this._timeoutIds++;var i=this.now();return this._timeouts.add({callback:t,time:i+e,id:this._timeoutIds}),this._timeoutIds},t.Context.prototype.clearTimeout=function(t){return this._timeouts.forEach(function(e){e.id===t&&this.remove(e)}),this},Object.defineProperty(t.Context.prototype,"updateInterval",{get:function(){return this._ticker.updateInterval},set:function(t){this._ticker.updateInterval=t}}),Object.defineProperty(t.Context.prototype,"clockSource",{get:function(){return this._ticker.type},set:function(t){this._ticker.type=t}}),Object.defineProperty(t.Context.prototype,"latencyHint",{get:function(){return this._latencyHint},set:function(e){var i=e;if(this._latencyHint=e,t.isString(e))switch(e){case"interactive":i=.1,this._context.latencyHint=e;break;case"playback":i=.8,this._context.latencyHint=e;break;case"balanced":i=.25,this._context.latencyHint=e;break;case"fastest":this._context.latencyHint="interactive",i=.01}this.lookAhead=i,this.updateInterval=i/3}}),t.Context.prototype.dispose=function(){return this.close().then(function(){t.Emitter.prototype.dispose.call(this),this._ticker.dispose(),this._ticker=null,this._timeouts.dispose(),this._timeouts=null;for(var e in this._constants)this._constants[e].disconnect();this._constants=null}.bind(this))};var e=function(e,i,n){this._type=i,this._updateInterval=n,this._callback=t.defaultArg(e,t.noOp),this._createClock()};return e.Type={Worker:"worker",Timeout:"timeout",Offline:"offline"},e.prototype._createWorker=function(){var t,e,i;window.URL=window.URL||window.webkitURL,t=new Blob(["var timeoutTime = "+(1e3*this._updateInterval).toFixed(1)+";self.onmessage = function(msg){\ttimeoutTime = parseInt(msg.data);};function tick(){\tsetTimeout(tick, timeoutTime);\tself.postMessage('tick');}tick();"]),e=URL.createObjectURL(t),i=new Worker(e),i.onmessage=this._callback.bind(this),this._worker=i},e.prototype._createTimeout=function(){this._timeout=setTimeout(function(){this._createTimeout(),this._callback()}.bind(this),1e3*this._updateInterval)},e.prototype._createClock=function(){if(this._type===e.Type.Worker)try{this._createWorker()}catch(t){this._type=e.Type.Timeout,this._createClock()}else this._type===e.Type.Timeout&&this._createTimeout()},Object.defineProperty(e.prototype,"updateInterval",{get:function(){return this._updateInterval},set:function(t){this._updateInterval=Math.max(t,128/44100),this._type===e.Type.Worker&&this._worker.postMessage(Math.max(1e3*t,1))}}),Object.defineProperty(e.prototype,"type",{get:function(){return this._type},set:function(t){this._disposeClock(),this._type=t,this._createClock()}}),e.prototype._disposeClock=function(){this._timeout&&(clearTimeout(this._timeout),this._timeout=null),this._worker&&(this._worker.terminate(),this._worker.onmessage=null,this._worker=null)},e.prototype.dispose=function(){this._disposeClock(),this._callback=null},t.getContext(function(){function e(e,i,s){if(e.input)s=t.defaultArg(s,0),t.isArray(e.input)?this.connect(e.input[s]):this.connect(e.input,i,s);else try{e instanceof AudioNode?n.call(this,e,i,s):n.call(this,e,i)}catch(t){throw new Error("error connecting to node: "+e+"\n"+t)}}function i(e,i,n){if(e&&e.input&&t.isArray(e.input))n=t.defaultArg(n,0),this.disconnect(e.input[n],i,0);else if(e&&e.input)this.disconnect(e.input,i,n);else try{s.apply(this,arguments)}catch(t){throw new Error("error disconnecting node: "+e+"\n"+t)}}var n=AudioNode.prototype.connect,s=AudioNode.prototype.disconnect;AudioNode.prototype.connect!==e&&(AudioNode.prototype.connect=e,AudioNode.prototype.disconnect=i)}),t.supported&&!t.initialized?(t.context=new t.Context,window.TONE_SILENCE_VERSION_LOGGING||console.log("%c * Tone.js "+t.version+" * ","background: #000; color: #fff")):t.supported||console.warn("This browser does not support Tone.js"),t.Context}),t(function(t){return t.AudioNode=function(){t.call(this);var e=t.defaults(arguments,["context"],{context:t.context});this._context=e.context},t.extend(t.AudioNode),Object.defineProperty(t.AudioNode.prototype,"context",{get:function(){return this._context}}),t.AudioNode.prototype.createInsOuts=function(t,e){1===t?this.input=this.context.createGain():t>1&&(this.input=new Array(t)),1===e?this.output=this.context.createGain():e>1&&(this.output=new Array(e))},Object.defineProperty(t.AudioNode.prototype,"numberOfInputs",{get:function(){return this.input?t.isArray(this.input)?this.input.length:1:0}}),Object.defineProperty(t.AudioNode.prototype,"numberOfOutputs",{get:function(){return this.output?t.isArray(this.output)?this.output.length:1:0}}),t.AudioNode.prototype.connect=function(e,i,n){return t.isArray(this.output)?(i=t.defaultArg(i,0),this.output[i].connect(e,0,n)):this.output.connect(e,i,n),this},t.AudioNode.prototype.disconnect=function(e,i,n){t.isArray(this.output)?t.isNumber(e)?this.output[e].disconnect():(i=t.defaultArg(i,0),this.output[i].disconnect(e,0,n)):this.output.disconnect.apply(this.output,arguments)},t.AudioNode.prototype.chain=function(){var t,e,i=this;for(t=0;t<arguments.length;t++)e=arguments[t],i.connect(e),i=e;return this},t.AudioNode.prototype.fan=function(){for(var t=0;t<arguments.length;t++)this.connect(arguments[t]);return this},window.AudioNode&&(AudioNode.prototype.chain=t.AudioNode.prototype.chain,AudioNode.prototype.fan=t.AudioNode.prototype.fan),t.AudioNode.prototype.dispose=function(){return t.isUndef(this.input)||(this.input instanceof AudioNode&&this.input.disconnect(),this.input=null),t.isUndef(this.output)||(this.output instanceof AudioNode&&this.output.disconnect(),this.output=null),this._context=null,this},t.AudioNode}),t(function(t){return t.SignalBase=function(){t.AudioNode.call(this)},t.extend(t.SignalBase,t.AudioNode),t.SignalBase.prototype.connect=function(e,i,n){return t.Signal&&t.Signal===e.constructor||t.Param&&t.Param===e.constructor||t.TimelineSignal&&t.TimelineSignal===e.constructor?(e._param.cancelScheduledValues(0),e._param.value=0,e.overridden=!0):e instanceof AudioParam&&(e.cancelScheduledValues(0),e.value=0),t.AudioNode.prototype.connect.call(this,e,i,n),this},t.SignalBase}),t(function(t){return t.WaveShaper=function(e,i){t.SignalBase.call(this),this._shaper=this.input=this.output=this.context.createWaveShaper(),this._curve=null,Array.isArray(e)?this.curve=e:isFinite(e)||t.isUndef(e)?this._curve=new Float32Array(t.defaultArg(e,1024)):t.isFunction(e)&&(this._curve=new Float32Array(t.defaultArg(i,1024)),this.setMap(e))},t.extend(t.WaveShaper,t.SignalBase),t.WaveShaper.prototype.setMap=function(t){var e,i,n;for(e=0,i=this._curve.length;e<i;e++)n=e/(i-1)*2-1,this._curve[e]=t(n,e);return this._shaper.curve=this._curve,this},Object.defineProperty(t.WaveShaper.prototype,"curve",{get:function(){return this._shaper.curve},set:function(t){this._curve=new Float32Array(t),this._shaper.curve=this._curve}}),Object.defineProperty(t.WaveShaper.prototype,"oversample",{get:function(){return this._shaper.oversample},set:function(t){if(-1===["none","2x","4x"].indexOf(t))throw new RangeError("Tone.WaveShaper: oversampling must be either 'none', '2x', or '4x'");this._shaper.oversample=t}}),t.WaveShaper.prototype.dispose=function(){return t.SignalBase.prototype.dispose.call(this),this._shaper.disconnect(),this._shaper=null,this._curve=null,this},t.WaveShaper}),t(function(t){return t.TimeBase=function(e,i){if(!(this instanceof t.TimeBase))return new t.TimeBase(e,i);if(this._val=e,this._units=i,t.isUndef(this._units)&&t.isString(this._val)&&parseFloat(this._val)==this._val&&"+"!==this._val.charAt(0))this._val=parseFloat(this._val),this._units=this._defaultUnits;else if(e&&e.constructor===this.constructor)this._val=e._val,this._units=e._units;else if(e instanceof t.TimeBase)switch(this._defaultUnits){case"s":this._val=e.toSeconds();break;case"i":this._val=e.toTicks();break;case"hz":this._val=e.toFrequency();break;case"midi":this._val=e.toMidi();break;default:throw new Error("Unrecognized default units "+this._defaultUnits)}},t.extend(t.TimeBase),t.TimeBase.prototype._expressions={n:{regexp:/^(\d+)n(\.?)$/i,method:function(t,e){t=parseInt(t);var i="."===e?1.5:1;return 1===t?this._beatsToUnits(this._getTimeSignature())*i:this._beatsToUnits(4/t)*i}},t:{regexp:/^(\d+)t$/i,method:function(t){return t=parseInt(t),this._beatsToUnits(8/(3*parseInt(t)))}},m:{regexp:/^(\d+)m$/i,method:function(t){return this._beatsToUnits(parseInt(t)*this._getTimeSignature())}},i:{regexp:/^(\d+)i$/i,method:function(t){return this._ticksToUnits(parseInt(t))}},hz:{regexp:/^(\d+(?:\.\d+)?)hz$/i,method:function(t){return this._frequencyToUnits(parseFloat(t))}},tr:{regexp:/^(\d+(?:\.\d+)?):(\d+(?:\.\d+)?):?(\d+(?:\.\d+)?)?$/,method:function(t,e,i){var n=0;return t&&"0"!==t&&(n+=this._beatsToUnits(this._getTimeSignature()*parseFloat(t))),e&&"0"!==e&&(n+=this._beatsToUnits(parseFloat(e))),i&&"0"!==i&&(n+=this._beatsToUnits(parseFloat(i)/4)),n}},s:{regexp:/^(\d+(?:\.\d+)?s)$/,method:function(t){return this._secondsToUnits(parseFloat(t))}},samples:{regexp:/^(\d+)samples$/,method:function(t){return parseInt(t)/this.context.sampleRate}},default:{regexp:/^(\d+(?:\.\d+)?)$/,method:function(t){return this._expressions[this._defaultUnits].method.call(this,t)}}},t.TimeBase.prototype._defaultUnits="s",t.TimeBase.prototype._getBpm=function(){return t.Transport?t.Transport.bpm.value:120},t.TimeBase.prototype._getTimeSignature=function(){return t.Transport?t.Transport.timeSignature:4},t.TimeBase.prototype._getPPQ=function(){return t.Transport?t.Transport.PPQ:192},t.TimeBase.prototype._now=function(){return this.now()},t.TimeBase.prototype._frequencyToUnits=function(t){return 1/t},t.TimeBase.prototype._beatsToUnits=function(t){return 60/this._getBpm()*t},t.TimeBase.prototype._secondsToUnits=function(t){return t},t.TimeBase.prototype._ticksToUnits=function(t){return t*(this._beatsToUnits(1)/this._getPPQ())},t.TimeBase.prototype._noArg=function(){return this._now()},t.TimeBase.prototype.valueOf=function(){var e,i,n;if(t.isUndef(this._val))return this._noArg();if(t.isString(this._val)&&t.isUndef(this._units))for(e in this._expressions)if(this._expressions[e].regexp.test(this._val.trim())){this._units=e;break}return t.isUndef(this._units)?this._val:(i=this._expressions[this._units],n=this._val.toString().trim().match(i.regexp),n?i.method.apply(this,n.slice(1)):i.method.call(this,parseFloat(this._val)))},t.TimeBase.prototype.toSeconds=function(){return this.valueOf()},t.TimeBase.prototype.toFrequency=function(){return 1/this.toSeconds()},t.TimeBase.prototype.toSamples=function(){return this.toSeconds()*this.context.sampleRate},t.TimeBase.prototype.toMilliseconds=function(){return 1e3*this.toSeconds()},t.TimeBase.prototype.dispose=function(){this._val=null,this._units=null},t.TimeBase}),t(function(t){var e,i;return t.Frequency=function(e,i){if(!(this instanceof t.Frequency))return new t.Frequency(e,i);t.TimeBase.call(this,e,i)},t.extend(t.Frequency,t.TimeBase),t.Frequency.prototype._expressions=Object.assign({},t.TimeBase.prototype._expressions,{midi:{regexp:/^(\d+(?:\.\d+)?midi)/,method:function(e){return"midi"===this._defaultUnits?e:t.Frequency.mtof(e)}},note:{regexp:/^([a-g]{1}(?:b|#|x|bb)?)(-?[0-9]+)/i,method:function(i,n){var s=e[i.toLowerCase()],o=s+12*(parseInt(n)+1);return"midi"===this._defaultUnits?o:t.Frequency.mtof(o)}},tr:{regexp:/^(\d+(?:\.\d+)?):(\d+(?:\.\d+)?):?(\d+(?:\.\d+)?)?/,method:function(t,e,i){var n=1;return t&&"0"!==t&&(n*=this._beatsToUnits(this._getTimeSignature()*parseFloat(t))),e&&"0"!==e&&(n*=this._beatsToUnits(parseFloat(e))),i&&"0"!==i&&(n*=this._beatsToUnits(parseFloat(i)/4)),n}}}),t.Frequency.prototype.transpose=function(e){return new this.constructor(this.valueOf()*t.intervalToFrequencyRatio(e))},t.Frequency.prototype.harmonize=function(t){return t.map(function(t){return this.transpose(t)}.bind(this))},t.Frequency.prototype.toMidi=function(){return t.Frequency.ftom(this.valueOf())},t.Frequency.prototype.toNote=function(){var e=this.toFrequency(),n=Math.log2(e/t.Frequency.A4),s=Math.round(12*n)+57,o=Math.floor(s/12);return o<0&&(s+=-12*o),i[s%12]+o.toString()},t.Frequency.prototype.toSeconds=function(){return 1/t.TimeBase.prototype.toSeconds.call(this)},t.Frequency.prototype.toFrequency=function(){return t.TimeBase.prototype.toFrequency.call(this)},t.Frequency.prototype.toTicks=function(){var e=this._beatsToUnits(1),i=this.valueOf()/e;return Math.floor(i*t.Transport.PPQ)},t.Frequency.prototype._noArg=function(){return 0},t.Frequency.prototype._frequencyToUnits=function(t){return t},t.Frequency.prototype._ticksToUnits=function(e){return 1/(60*e/(t.Transport.bpm.value*t.Transport.PPQ))},t.Frequency.prototype._beatsToUnits=function(e){return 1/t.TimeBase.prototype._beatsToUnits.call(this,e)},t.Frequency.prototype._secondsToUnits=function(t){return 1/t},t.Frequency.prototype._defaultUnits="hz",e={cbb:-2,cb:-1,c:0,"c#":1,cx:2,dbb:0,db:1,d:2,"d#":3,dx:4,ebb:2,eb:3,e:4,"e#":5,ex:6,fbb:3,fb:4,f:5,"f#":6,fx:7,gbb:5,gb:6,g:7,"g#":8,gx:9,abb:7,ab:8,a:9,"a#":10,ax:11,bbb:9,bb:10,b:11,"b#":12,bx:13},i=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],t.Frequency.A4=440,t.Frequency.mtof=function(e){return t.Frequency.A4*Math.pow(2,(e-69)/12)},t.Frequency.ftom=function(e){return 69+Math.round(12*Math.log2(e/t.Frequency.A4))},t.Frequency}),t(function(t){return t.Time=function(e,i){if(!(this instanceof t.Time))return new t.Time(e,i);t.TimeBase.call(this,e,i)},t.extend(t.Time,t.TimeBase),t.Time.prototype._expressions=Object.assign({},t.TimeBase.prototype._expressions,{quantize:{regexp:/^@(.+)/,method:function(e){if(t.Transport){var i=new this.constructor(e);return t.Transport.nextSubdivision(i)}return 0}},now:{regexp:/^\+(.+)/,method:function(t){return this._now()+new this.constructor(t)}}}),t.Time.prototype.quantize=function(e,i){var n,s,o,r,a;return i=t.defaultArg(i,1),n=new this.constructor(e),s=this.valueOf(),o=Math.round(s/n),r=o*n,a=r-s,s+a*i},t.Time.prototype.toNotation=function(){var e,i,n,s,o=this.toSeconds(),r=["1m"];for(e=1;e<8;e++)i=Math.pow(2,e),r.push(i+"n."),r.push(i+"n"),r.push(i+"t");return r.push("0"),n=r[0],s=t.Time(r[0]).toSeconds(),r.forEach(function(e){var i=t.Time(e).toSeconds();Math.abs(i-o)<Math.abs(s-o)&&(n=e,s=i)}),n},t.Time.prototype.toBarsBeatsSixteenths=function(){var t,e=this._beatsToUnits(1),i=this.valueOf()/e,n=Math.floor(i/this._getTimeSignature()),s=i%1*4;return i=Math.floor(i)%this._getTimeSignature(),s=s.toString(),s.length>3&&(s=parseFloat(parseFloat(s).toFixed(3))),t=[n,i,s],t.join(":")},t.Time.prototype.toTicks=function(){var t=this._beatsToUnits(1),e=this.valueOf()/t;return Math.round(e*this._getPPQ())},t.Time.prototype.toSeconds=function(){return this.valueOf()},t.Time.prototype.toMidi=function(){return t.Frequency.ftom(this.toFrequency())},t.Time}),t(function(t){return t.TransportTime=function(e,i){if(!(this instanceof t.TransportTime))return new t.TransportTime(e,i);t.Time.call(this,e,i)},t.extend(t.TransportTime,t.Time),t.TransportTime.prototype._now=function(){return t.Transport.seconds},t.TransportTime}),t(function(t){return t.Type={Default:"number",Time:"time",Frequency:"frequency",TransportTime:"transportTime",Ticks:"ticks",NormalRange:"normalRange",AudioRange:"audioRange",Decibels:"db",Interval:"interval",BPM:"bpm",Positive:"positive",Gain:"gain",Cents:"cents",Degrees:"degrees",MIDI:"midi",BarsBeatsSixteenths:"barsBeatsSixteenths",Samples:"samples",Hertz:"hertz",Note:"note",Milliseconds:"milliseconds",Seconds:"seconds",Notation:"notation"},t.prototype.toSeconds=function(e){return t.isNumber(e)?e:t.isUndef(e)?this.now():t.isString(e)?new t.Time(e).toSeconds():e instanceof t.TimeBase?e.toSeconds():void 0},t.prototype.toFrequency=function(e){return t.isNumber(e)?e:t.isString(e)||t.isUndef(e)?new t.Frequency(e).valueOf():e instanceof t.TimeBase?e.toFrequency():void 0},t.prototype.toTicks=function(e){return t.isNumber(e)||t.isString(e)?new t.TransportTime(e).toTicks():t.isUndef(e)?t.Transport.ticks:e instanceof t.TimeBase?e.toTicks():void 0},t}),t(function(t){function e(e){e._events||(e._events=new t.Timeline(1e3))}var i=function(t,e,i,n,s){return i+(e-i)*Math.exp(-(s-t)/n)},n=function(t,e,i,n,s){return e+(s-t)/(i-t)*(n-e)},s=function(t,e,i,n,s){return e*Math.pow(n/e,(s-t)/(i-t))},o={Linear:"linearRampToValueAtTime",Exponential:"exponentialRampToValueAtTime",Target:"setTargetAtTime",SetValue:"setValueAtTime"};t.supported&&(Object.defineProperty(AudioParam.prototype,"value",{get:function(){var e=t.context.currentTime;return this.getValueAtTime(e)},set:function(e){this._initialValue=e;var i=t.context.currentTime;this.setValueAtTime(e,i)}}),AudioParam.prototype.hasOwnProperty("defaultValue")||Object.defineProperty(AudioParam.prototype,"defaultValue",{get:function(){return 1}}),AudioParam.prototype.hasOwnProperty("minValue")||Object.defineProperty(AudioParam.prototype,"minValue",{get:function(){return-3.4028235e38}}),AudioParam.prototype.hasOwnProperty("maxValue")||Object.defineProperty(AudioParam.prototype,"maxValue",{get:function(){return 3.4028235e38}}),["setValueAtTime","linearRampToValueAtTime","exponentialRampToValueAtTime"].forEach(function(t){var i="_native_"+t;AudioParam.prototype[i]||(AudioParam.prototype[i]=AudioParam.prototype[t],AudioParam.prototype[t]=function(n,s){if(e(this),t===o.Exponential){var r=this._events.get(s);if(r&&this.getValueAtTime(r.time)<=0)throw new Error("exponentialRampToValueAtTime must ramp from a value > 0")}return this._events.add({type:t,time:s,value:n}),AudioParam.prototype[i].call(this,n,s)})}),AudioParam.prototype._native_setTargetAtTime||(AudioParam.prototype._native_setTargetAtTime=AudioParam.prototype.setTargetAtTime,AudioParam.prototype.setTargetAtTime=function(t,i,n){return e(this),this._events.add({type:o.Target,value:t,time:i,constant:n}),this._native_setTargetAtTime(t,i,n)}),AudioParam.prototype._native_setValueCurveAtTime||(AudioParam.prototype._native_setValueCurveAtTime=AudioParam.prototype.setValueCurveAtTime,AudioParam.prototype.setValueCurveAtTime=function(t,i,n){var s,r;for(e(this),this._events.add({type:o.SetValue,value:t[0],time:i}),s=n/(t.length-1),r=1;r<t.length;r++)this._events.add({type:o.Linear,value:t[r],time:i+r*s});return this._native_setValueCurveAtTime(t,i,n)}),AudioParam.prototype._native_cancelScheduledValues||(AudioParam.prototype._native_cancelScheduledValues=AudioParam.prototype.cancelScheduledValues,AudioParam.prototype.cancelScheduledValues=function(t){return e(this),this._events.cancel(t),this._native_cancelScheduledValues(t)}),AudioParam.prototype._native_cancelAndHoldAtTime||(AudioParam.prototype._native_cancelAndHoldAtTime=AudioParam.prototype.cancelAndHoldAtTime,AudioParam.prototype.cancelAndHoldAtTime=function(t){var i,n,s;return e(this),i=this.getValueAtTime(t),n=this._events.get(t),s=this._events.getAfter(t),n&&n.time===t?s?this._events.cancel(s.time):this._events.cancel(t+1e-6):s&&(this._events.cancel(s.time),this._native_cancelAndHoldAtTime||this._native_cancelScheduledValues(t),
s.type===o.Linear?this._native_cancelAndHoldAtTime?this._events.add({type:o.Linear,value:i,time:t}):this.linearRampToValueAtTime(i,t):s.type===o.Exponential&&(this._native_cancelAndHoldAtTime?this._events.add({type:o.Exponential,value:i,time:t}):this.exponentialRampToValueAtTime(i,t))),this._events.add({type:o.SetValue,value:i,time:t}),this._native_cancelAndHoldAtTime?this._native_cancelAndHoldAtTime(t):this._native_setValueAtTime(i,t)}),AudioParam.prototype.getValueAtTime=function(r){var a,l,h,u,c;return e(this),a=this._events.getAfter(r),l=this._events.get(r),h=t.defaultArg(this._initialValue,this.defaultValue),null===l?h:l.type===o.Target?(u=this._events.getBefore(l.time),c=null===u?h:u.value,i(l.time,c,l.value,l.constant,r)):null===a?l.value:a.type===o.Linear?n(l.time,l.value,a.time,a.value,r):a.type===o.Exponential?s(l.time,l.value,a.time,a.value,r):l.value})}),t(function(t){return t.Param=function(){var e=t.defaults(arguments,["param","units","convert"],t.Param);t.AudioNode.call(this),this._param=this.input=e.param,this.units=e.units,this.convert=e.convert,this.overridden=!1,t.isUndef(e.value)||(this.value=e.value)},t.extend(t.Param,t.AudioNode),t.Param.defaults={units:t.Type.Default,convert:!0,param:void 0},Object.defineProperty(t.Param.prototype,"value",{get:function(){return this._toUnits(this._param.value)},set:function(t){var e=this._fromUnits(t);this._param.cancelScheduledValues(0),this._param.value=e}}),Object.defineProperty(t.Param.prototype,"minValue",{get:function(){return this.units===t.Type.Time||this.units===t.Type.Frequency||this.units===t.Type.NormalRange||this.units===t.Type.Positive||this.units===t.Type.BPM?0:this.units===t.Type.AudioRange?-1:this.units===t.Type.Decibels?-1/0:this._param.minValue}}),Object.defineProperty(t.Param.prototype,"maxValue",{get:function(){return this.units===t.Type.NormalRange||this.units===t.Type.AudioRange?1:this._param.maxValue}}),t.Param.prototype._fromUnits=function(e){if(!this.convert&&!t.isUndef(this.convert))return e;switch(this.units){case t.Type.Time:return this.toSeconds(e);case t.Type.Frequency:return this.toFrequency(e);case t.Type.Decibels:return t.dbToGain(e);case t.Type.NormalRange:return Math.min(Math.max(e,0),1);case t.Type.AudioRange:return Math.min(Math.max(e,-1),1);case t.Type.Positive:return Math.max(e,0);default:return e}},t.Param.prototype._toUnits=function(e){if(!this.convert&&!t.isUndef(this.convert))return e;switch(this.units){case t.Type.Decibels:return t.gainToDb(e);default:return e}},t.Param.prototype._minOutput=1e-5,t.Param.prototype.setValueAtTime=function(e,i){return i=this.toSeconds(i),t.isPast(i),this._param.setValueAtTime(this._fromUnits(e),i),this},t.Param.prototype.getValueAtTime=function(t){return t=this.toSeconds(t),this._fromUnits(this._param.getValueAtTime(t))},t.Param.prototype.setRampPoint=function(t){t=this.toSeconds(t);var e=this.getValueAtTime(t);return this.cancelAndHoldAtTime(t),0===e&&(e=this._minOutput),this._param.setValueAtTime(e,t),this},t.Param.prototype.linearRampToValueAtTime=function(e,i){return e=this._fromUnits(e),i=this.toSeconds(i),t.isPast(i),this._param.linearRampToValueAtTime(e,i),this},t.Param.prototype.exponentialRampToValueAtTime=function(e,i){return e=this._fromUnits(e),e=Math.max(this._minOutput,e),i=this.toSeconds(i),t.isPast(i),this._param.exponentialRampToValueAtTime(e,i),this},t.Param.prototype.exponentialRampTo=function(t,e,i){return i=this.toSeconds(i),this.setRampPoint(i),this.exponentialRampToValueAtTime(t,i+this.toSeconds(e)),this},t.Param.prototype.linearRampTo=function(t,e,i){return i=this.toSeconds(i),this.setRampPoint(i),this.linearRampToValueAtTime(t,i+this.toSeconds(e)),this},t.Param.prototype.targetRampTo=function(t,e,i){return i=this.toSeconds(i),this.setRampPoint(i),this.exponentialAppraochValueAtTime(t,i,e),this},t.Param.prototype.exponentialAppraochValueAtTime=function(e,i,n){var s=Math.log(this.toSeconds(n)+1)/Math.log(200);return i=this.toSeconds(i),t.isPast(i),this.setTargetAtTime(e,i,s)},t.Param.prototype.setTargetAtTime=function(t,e,i){if(t=this._fromUnits(t),i<=0)throw new Error("timeConstant must be greater than 0");return this._param.setTargetAtTime(t,this.toSeconds(e),i),this},t.Param.prototype.setValueCurveAtTime=function(e,i,n,s){var o,r;for(s=t.defaultArg(s,1),n=this.toSeconds(n),i=this.toSeconds(i),this.setValueAtTime(e[0]*s,i),o=n/(e.length-1),r=1;r<e.length;r++)this._param.linearRampToValueAtTime(this._fromUnits(e[r]*s),i+r*o);return this},t.Param.prototype.cancelScheduledValues=function(t){return this._param.cancelScheduledValues(this.toSeconds(t)),this},t.Param.prototype.cancelAndHoldAtTime=function(t){return this._param.cancelAndHoldAtTime(this.toSeconds(t)),this},t.Param.prototype.rampTo=function(e,i,n){return i=t.defaultArg(i,.1),this.units===t.Type.Frequency||this.units===t.Type.BPM||this.units===t.Type.Decibels?this.exponentialRampTo(e,i,n):this.linearRampTo(e,i,n),this},t.Param.prototype.dispose=function(){return t.AudioNode.prototype.dispose.call(this),this._param=null,this},t.Param}),t(function(t){return t.Gain=function(){var e=t.defaults(arguments,["gain","units"],t.Gain);t.AudioNode.call(this),this.input=this.output=this._gainNode=this.context.createGain(),this.gain=new t.Param({param:this._gainNode.gain,units:e.units,value:e.gain,convert:e.convert}),this._readOnly("gain")},t.extend(t.Gain,t.AudioNode),t.Gain.defaults={gain:1,convert:!0},t.Gain.prototype.dispose=function(){t.AudioNode.prototype.dispose.call(this),this._gainNode.disconnect(),this._gainNode=null,this._writable("gain"),this.gain.dispose(),this.gain=null},t.Gain}),t(function(t){if(t.supported&&!window.ConstantSourceNode){var e=function(t){var e,i,n,s;for(this.context=t,e=t.createBuffer(1,128,t.sampleRate),i=e.getChannelData(0),n=0;n<i.length;n++)i[n]=1;this._bufferSource=t.createBufferSource(),this._bufferSource.channelCount=1,this._bufferSource.channelCountMode="explicit",this._bufferSource.buffer=e,this._bufferSource.loop=!0,s=this._output=t.createGain(),this.offset=s.gain,this._bufferSource.connect(s)};e.prototype.start=function(t){return this._bufferSource.start(t),this},e.prototype.stop=function(t){return this._bufferSource.stop(t),this},e.prototype.connect=function(){return this._output.connect.apply(this._output,arguments),this},e.prototype.disconnect=function(){return this._output.disconnect.apply(this._output,arguments),this},AudioContext.prototype.createConstantSource=function(){return new e(this)},t.Context.prototype.createConstantSource=function(){return new e(this)}}}),t(function(t){return t.Signal=function(){var e=t.defaults(arguments,["value","units"],t.Signal),i=t.context.createConstantSource();i.start(0),e.param=i.offset,t.Param.call(this,e),this.output=i,this.input=this._param=this.output.offset},t.extend(t.Signal,t.Param),t.Signal.defaults={value:0,units:t.Type.Default,convert:!0},t.Signal.prototype.connect=t.SignalBase.prototype.connect,t.Signal.prototype.dispose=function(){return t.Param.prototype.dispose.call(this),this},t.Signal}),t(function(t){return t.TimelineSignal=function(){var e=t.defaults(arguments,["value","units"],t.Signal);t.Signal.call(this,e),this._events=new t.Timeline(100),this._initial=this._fromUnits(this._param.value),this.value=e.value,delete this.input},t.extend(t.TimelineSignal,t.Signal),t.TimelineSignal.Type={Linear:"linear",Exponential:"exponential",Target:"target",Set:"set"},Object.defineProperty(t.TimelineSignal.prototype,"value",{get:function(){var t=this.now(),e=this.getValueAtTime(t);return this._toUnits(e)},set:function(t){if(this._events){var e=this._fromUnits(t);this._initial=e,this.cancelScheduledValues(),this._param.value=e}}}),t.TimelineSignal.prototype.setValueAtTime=function(e,i){return e=this._fromUnits(e),i=this.toSeconds(i),this._events.add({type:t.TimelineSignal.Type.Set,value:e,time:i}),this._param.setValueAtTime(e,i),this},t.TimelineSignal.prototype.linearRampToValueAtTime=function(e,i){return e=this._fromUnits(e),i=this.toSeconds(i),this._events.add({type:t.TimelineSignal.Type.Linear,value:e,time:i}),this._param.linearRampToValueAtTime(e,i),this},t.TimelineSignal.prototype.exponentialRampToValueAtTime=function(e,i){var n,s;return i=this.toSeconds(i),n=this._searchBefore(i),n&&0===n.value&&this.setValueAtTime(this._minOutput,n.time),e=this._fromUnits(e),s=Math.max(e,this._minOutput),this._events.add({type:t.TimelineSignal.Type.Exponential,value:s,time:i}),e<this._minOutput?(this._param.exponentialRampToValueAtTime(this._minOutput,i-this.sampleTime),this.setValueAtTime(0,i)):this._param.exponentialRampToValueAtTime(e,i),this},t.TimelineSignal.prototype.setTargetAtTime=function(e,i,n){return e=this._fromUnits(e),e=Math.max(this._minOutput,e),n=Math.max(this._minOutput,n),i=this.toSeconds(i),this._events.add({type:t.TimelineSignal.Type.Target,value:e,time:i,constant:n}),this._param.setTargetAtTime(e,i,n),this},t.TimelineSignal.prototype.setValueCurveAtTime=function(e,i,n,s){var o,r;for(s=t.defaultArg(s,1),n=this.toSeconds(n),i=this.toSeconds(i),o=n/(e.length-1),this.setValueAtTime(e[0]*s,i),r=1;r<e.length;r++)this.linearRampToValueAtTime(e[r]*s,i+r*o);return this},t.TimelineSignal.prototype.cancelScheduledValues=function(t){return t=this.toSeconds(t),this._events.cancel(t),this._param.cancelScheduledValues(t),this},t.TimelineSignal.prototype.cancelAndHoldAtTime=function(t){return this.setRampPoint(this.toSeconds(t)),this},t.TimelineSignal.prototype.setRampPoint=function(e){var i,n,s;return e=this.toSeconds(e),i=this._toUnits(this.getValueAtTime(e)),n=this._searchBefore(e),n&&n.time===e?this.cancelScheduledValues(e+this.sampleTime):(s=this._searchAfter(e))&&(this.cancelScheduledValues(e),s.type===t.TimelineSignal.Type.Linear?this.linearRampToValueAtTime(i,e):s.type===t.TimelineSignal.Type.Exponential&&this.exponentialRampToValueAtTime(i,e)),this.setValueAtTime(i,e),this},t.TimelineSignal.prototype.linearRampToValueBetween=function(t,e,i){return this.setRampPoint(e),this.linearRampToValueAtTime(t,i),this},t.TimelineSignal.prototype.exponentialRampToValueBetween=function(t,e,i){return this.setRampPoint(e),this.exponentialRampToValueAtTime(t,i),this},t.TimelineSignal.prototype._searchBefore=function(t){return this._events.get(t)},t.TimelineSignal.prototype._searchAfter=function(t){return this._events.getAfter(t)},t.TimelineSignal.prototype.getValueAtTime=function(e){var i,n,s,o,r;return e=this.toSeconds(e),i=this._searchAfter(e),n=this._searchBefore(e),s=this._initial,null===n?s=this._initial:n.type===t.TimelineSignal.Type.Target?(o=this._events.getBefore(n.time),r=null===o?this._initial:o.value,s=this._exponentialApproach(n.time,r,n.value,n.constant,e)):s=null===i?n.value:i.type===t.TimelineSignal.Type.Linear?this._linearInterpolate(n.time,n.value,i.time,i.value,e):i.type===t.TimelineSignal.Type.Exponential?this._exponentialInterpolate(n.time,n.value,i.time,i.value,e):n.value,s},t.TimelineSignal.prototype.connect=t.SignalBase.prototype.connect,t.TimelineSignal.prototype._exponentialApproach=function(t,e,i,n,s){return i+(e-i)*Math.exp(-(s-t)/n)},t.TimelineSignal.prototype._linearInterpolate=function(t,e,i,n,s){return e+(s-t)/(i-t)*(n-e)},t.TimelineSignal.prototype._exponentialInterpolate=function(t,e,i,n,s){return(e=Math.max(this._minOutput,e))*Math.pow(n/e,(s-t)/(i-t))},t.TimelineSignal.prototype.dispose=function(){t.Signal.prototype.dispose.call(this),this._events.dispose(),this._events=null},t.TimelineSignal}),t(function(t){return t.Pow=function(e){t.SignalBase.call(this),this._exp=t.defaultArg(e,1),this._expScaler=this.input=this.output=new t.WaveShaper(this._expFunc(this._exp),8192)},t.extend(t.Pow,t.SignalBase),Object.defineProperty(t.Pow.prototype,"value",{get:function(){return this._exp},set:function(t){this._exp=t,this._expScaler.setMap(this._expFunc(this._exp))}}),t.Pow.prototype._expFunc=function(t){return function(e){return Math.pow(Math.abs(e),t)}},t.Pow.prototype.dispose=function(){return t.SignalBase.prototype.dispose.call(this),this._expScaler.dispose(),this._expScaler=null,this},t.Pow}),t(function(t){return t.Envelope=function(){var e=t.defaults(arguments,["attack","decay","sustain","release"],t.Envelope);t.AudioNode.call(this),this.attack=e.attack,this.decay=e.decay,this.sustain=e.sustain,this.release=e.release,this._attackCurve="linear",this._releaseCurve="exponential",this._sig=this.output=new t.Signal(0),this.attackCurve=e.attackCurve,this.releaseCurve=e.releaseCurve},t.extend(t.Envelope,t.AudioNode),t.Envelope.defaults={attack:.01,decay:.1,sustain:.5,release:1,attackCurve:"linear",releaseCurve:"exponential"},Object.defineProperty(t.Envelope.prototype,"value",{get:function(){return this.getValueAtTime(this.now())}}),Object.defineProperty(t.Envelope.prototype,"attackCurve",{get:function(){if(t.isString(this._attackCurve))return this._attackCurve;if(t.isArray(this._attackCurve)){for(var e in t.Envelope.Type)if(t.Envelope.Type[e].In===this._attackCurve)return e;return this._attackCurve}},set:function(e){if(t.Envelope.Type.hasOwnProperty(e)){var i=t.Envelope.Type[e];t.isObject(i)?this._attackCurve=i.In:this._attackCurve=i}else{if(!t.isArray(e))throw new Error("Tone.Envelope: invalid curve: "+e);this._attackCurve=e}}}),Object.defineProperty(t.Envelope.prototype,"releaseCurve",{get:function(){if(t.isString(this._releaseCurve))return this._releaseCurve;if(t.isArray(this._releaseCurve)){for(var e in t.Envelope.Type)if(t.Envelope.Type[e].Out===this._releaseCurve)return e;return this._releaseCurve}},set:function(e){if(t.Envelope.Type.hasOwnProperty(e)){var i=t.Envelope.Type[e];t.isObject(i)?this._releaseCurve=i.Out:this._releaseCurve=i}else{if(!t.isArray(e))throw new Error("Tone.Envelope: invalid curve: "+e);this._releaseCurve=e}}}),t.Envelope.prototype.triggerAttack=function(e,i){var n,s,o,r,a,l,h,u,c;return e=this.toSeconds(e),n=this.toSeconds(this.attack),s=n,o=this.toSeconds(this.decay),i=t.defaultArg(i,1),r=this.getValueAtTime(e),r>0&&(a=1/s,l=1-r,s=l/a),"linear"===this._attackCurve?this._sig.linearRampTo(i,s,e):"exponential"===this._attackCurve?this._sig.targetRampTo(i,s,e):s>0&&(this._sig.cancelAndHoldAtTime(e),h=this._attackCurve,s<n&&(u=1-s/n,c=Math.floor(u*this._attackCurve.length),h=this._attackCurve.slice(c),h[0]=r),this._sig.setValueCurveAtTime(h,e,s,i)),o&&this._sig.targetRampTo(i*this.sustain,o,s+e),this},t.Envelope.prototype.triggerRelease=function(e){var i,n,s;return e=this.toSeconds(e),i=this.getValueAtTime(e),i>0&&(n=this.toSeconds(this.release),"linear"===this._releaseCurve?this._sig.linearRampTo(0,n,e):"exponential"===this._releaseCurve?this._sig.targetRampTo(0,n,e):(s=this._releaseCurve,t.isArray(s)&&(this._sig.cancelAndHoldAtTime(e),this._sig.setValueCurveAtTime(s,e,n,i)))),this},t.Envelope.prototype.getValueAtTime=function(t){return this._sig.getValueAtTime(t)},t.Envelope.prototype.triggerAttackRelease=function(t,e,i){return e=this.toSeconds(e),this.triggerAttack(e,i),this.triggerRelease(e+this.toSeconds(t)),this},t.Envelope.prototype.cancel=function(t){return this._sig.cancelScheduledValues(t),this},t.Envelope.prototype.connect=t.Signal.prototype.connect,function(){function e(t){var e,i=new Array(t.length);for(e=0;e<t.length;e++)i[e]=1-t[e];return i}var i,n,s,o,r,a,l,h,u,c,p,d=128,f=[];for(i=0;i<d;i++)f[i]=Math.sin(i/(d-1)*(Math.PI/2));for(s=[],o=6.4,i=0;i<d-1;i++)n=i/(d-1),r=Math.sin(n*(2*Math.PI)*o-Math.PI/2)+1,s[i]=r/10+.83*n;for(s[d-1]=1,a=[],l=5,i=0;i<d;i++)a[i]=Math.ceil(i/(d-1)*l)/l;for(h=[],i=0;i<d;i++)n=i/(d-1),h[i]=.5*(1-Math.cos(Math.PI*n));for(u=[],i=0;i<d;i++)n=i/(d-1),c=4*Math.pow(n,3)+.2,p=Math.cos(c*Math.PI*2*n),u[i]=Math.abs(p*(1-n));t.Envelope.Type={linear:"linear",exponential:"exponential",bounce:{In:e(u),Out:u},cosine:{In:f,Out:function(t){return t.slice(0).reverse()}(f)},step:{In:a,Out:e(a)},ripple:{In:s,Out:e(s)},sine:{In:h,Out:e(h)}}}(),t.Envelope.prototype.dispose=function(){return t.AudioNode.prototype.dispose.call(this),this._sig.dispose(),this._sig=null,this._attackCurve=null,this._releaseCurve=null,this},t.Envelope}),t(function(t){return t.AmplitudeEnvelope=function(){t.Envelope.apply(this,arguments),this.input=this.output=new t.Gain,this._sig.connect(this.output.gain)},t.extend(t.AmplitudeEnvelope,t.Envelope),t.AmplitudeEnvelope.prototype.dispose=function(){return t.Envelope.prototype.dispose.call(this),this},t.AmplitudeEnvelope}),t(function(t){t.supported&&(AnalyserNode.prototype.getFloatTimeDomainData||(AnalyserNode.prototype.getFloatTimeDomainData=function(t){var e,i=new Uint8Array(t.length);for(this.getByteTimeDomainData(i),e=0;e<i.length;e++)t[e]=(i[e]-128)/128}))}),t(function(t){return t.Analyser=function(){var e=t.defaults(arguments,["type","size"],t.Analyser);t.AudioNode.call(this),this._analyser=this.input=this.output=this.context.createAnalyser(),this._type=e.type,this._buffer=null,this.size=e.size,this.type=e.type},t.extend(t.Analyser,t.AudioNode),t.Analyser.defaults={size:1024,type:"fft",smoothing:.8},t.Analyser.Type={Waveform:"waveform",FFT:"fft"},t.Analyser.prototype.getValue=function(){return this._type===t.Analyser.Type.FFT?this._analyser.getFloatFrequencyData(this._buffer):this._type===t.Analyser.Type.Waveform&&this._analyser.getFloatTimeDomainData(this._buffer),this._buffer},Object.defineProperty(t.Analyser.prototype,"size",{get:function(){return this._analyser.frequencyBinCount},set:function(t){this._analyser.fftSize=2*t,this._buffer=new Float32Array(t)}}),Object.defineProperty(t.Analyser.prototype,"type",{get:function(){return this._type},set:function(e){if(e!==t.Analyser.Type.Waveform&&e!==t.Analyser.Type.FFT)throw new TypeError("Tone.Analyser: invalid type: "+e);this._type=e}}),Object.defineProperty(t.Analyser.prototype,"smoothing",{get:function(){return this._analyser.s