UNPKG

p5

Version:

[![Build Status](https://travis-ci.org/processing/p5.js.svg?branch=master)](https://travis-ci.org/processing/p5.js) [![npm version](https://badge.fury.io/js/p5.svg)](https://www.npmjs.com/package/p5)

4 lines (3 loc) 127 kB
/*! p5.sound.min.js v0.3.5 2017-07-28 */ !function(t,e){"function"==typeof define&&define.amd?define("p5.sound",["p5"],function(t){e(t)}):e("object"==typeof exports?require("../p5"):t.p5)}(this,function(p5){var sndcore;sndcore=function(){!function(){function t(t){t&&(t.setTargetAtTime||(t.setTargetAtTime=t.setTargetValueAtTime))}window.hasOwnProperty("webkitAudioContext")&&!window.hasOwnProperty("AudioContext")&&(window.AudioContext=window.webkitAudioContext,"function"!=typeof AudioContext.prototype.createGain&&(AudioContext.prototype.createGain=AudioContext.prototype.createGainNode),"function"!=typeof AudioContext.prototype.createDelay&&(AudioContext.prototype.createDelay=AudioContext.prototype.createDelayNode),"function"!=typeof AudioContext.prototype.createScriptProcessor&&(AudioContext.prototype.createScriptProcessor=AudioContext.prototype.createJavaScriptNode),"function"!=typeof AudioContext.prototype.createPeriodicWave&&(AudioContext.prototype.createPeriodicWave=AudioContext.prototype.createWaveTable),AudioContext.prototype.internal_createGain=AudioContext.prototype.createGain,AudioContext.prototype.createGain=function(){var e=this.internal_createGain();return t(e.gain),e},AudioContext.prototype.internal_createDelay=AudioContext.prototype.createDelay,AudioContext.prototype.createDelay=function(e){var i=e?this.internal_createDelay(e):this.internal_createDelay();return t(i.delayTime),i},AudioContext.prototype.internal_createBufferSource=AudioContext.prototype.createBufferSource,AudioContext.prototype.createBufferSource=function(){var e=this.internal_createBufferSource();return e.start?(e.internal_start=e.start,e.start=function(t,i,n){"undefined"!=typeof n?e.internal_start(t||0,i,n):e.internal_start(t||0,i||0)}):e.start=function(t,e,i){e||i?this.noteGrainOn(t||0,e,i):this.noteOn(t||0)},e.stop?(e.internal_stop=e.stop,e.stop=function(t){e.internal_stop(t||0)}):e.stop=function(t){this.noteOff(t||0)},t(e.playbackRate),e},AudioContext.prototype.internal_createDynamicsCompressor=AudioContext.prototype.createDynamicsCompressor,AudioContext.prototype.createDynamicsCompressor=function(){var e=this.internal_createDynamicsCompressor();return t(e.threshold),t(e.knee),t(e.ratio),t(e.reduction),t(e.attack),t(e.release),e},AudioContext.prototype.internal_createBiquadFilter=AudioContext.prototype.createBiquadFilter,AudioContext.prototype.createBiquadFilter=function(){var e=this.internal_createBiquadFilter();return t(e.frequency),t(e.detune),t(e.Q),t(e.gain),e},"function"!=typeof AudioContext.prototype.createOscillator&&(AudioContext.prototype.internal_createOscillator=AudioContext.prototype.createOscillator,AudioContext.prototype.createOscillator=function(){var e=this.internal_createOscillator();return e.start?(e.internal_start=e.start,e.start=function(t){e.internal_start(t||0)}):e.start=function(t){this.noteOn(t||0)},e.stop?(e.internal_stop=e.stop,e.stop=function(t){e.internal_stop(t||0)}):e.stop=function(t){this.noteOff(t||0)},e.setPeriodicWave||(e.setPeriodicWave=e.setWaveTable),t(e.frequency),t(e.detune),e})),window.hasOwnProperty("webkitOfflineAudioContext")&&!window.hasOwnProperty("OfflineAudioContext")&&(window.OfflineAudioContext=window.webkitOfflineAudioContext)}(window);var t=new window.AudioContext;p5.prototype.getAudioContext=function(){return t},navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;var e=document.createElement("audio");p5.prototype.isSupported=function(){return!!e.canPlayType};var i=function(){return!!e.canPlayType&&e.canPlayType('audio/ogg; codecs="vorbis"')},n=function(){return!!e.canPlayType&&e.canPlayType("audio/mpeg;")},o=function(){return!!e.canPlayType&&e.canPlayType('audio/wav; codecs="1"')},r=function(){return!!e.canPlayType&&(e.canPlayType("audio/x-m4a;")||e.canPlayType("audio/aac;"))},s=function(){return!!e.canPlayType&&e.canPlayType("audio/x-aiff;")};p5.prototype.isFileSupported=function(t){switch(t.toLowerCase()){case"mp3":return n();case"wav":return o();case"ogg":return i();case"aac":case"m4a":case"mp4":return r();case"aif":case"aiff":return s();default:return!1}};var a=navigator.userAgent.match(/(iPad|iPhone|iPod)/g)?!0:!1;if(a){var u=!1,p=function(){if(!u){var e=t.createBuffer(1,1,22050),i=t.createBufferSource();i.buffer=e,i.connect(t.destination),i.start(0),console.log("start ios!"),"running"===t.state&&(u=!0)}};document.addEventListener("touchend",p,!1),document.addEventListener("touchstart",p,!1)}}();var master;master=function(){var t=function(){var t=p5.prototype.getAudioContext();this.input=t.createGain(),this.output=t.createGain(),this.limiter=t.createDynamicsCompressor(),this.limiter.threshold.value=0,this.limiter.ratio.value=20,this.audiocontext=t,this.output.disconnect(),this.inputSources=[],this.input.connect(this.limiter),this.limiter.connect(this.output),this.meter=t.createGain(),this.fftMeter=t.createGain(),this.output.connect(this.meter),this.output.connect(this.fftMeter),this.output.connect(this.audiocontext.destination),this.soundArray=[],this.parts=[],this.extensions=[]},e=new t;return p5.prototype.getMasterVolume=function(){return e.output.gain.value},p5.prototype.masterVolume=function(t,i,n){if("number"==typeof t){var i=i||0,n=n||0,o=e.audiocontext.currentTime,r=e.output.gain.value;e.output.gain.cancelScheduledValues(o+n),e.output.gain.linearRampToValueAtTime(r,o+n),e.output.gain.linearRampToValueAtTime(t,o+n+i)}else{if(!t)return e.output.gain;t.connect(e.output.gain)}},p5.prototype.soundOut=p5.soundOut=e,p5.soundOut._silentNode=e.audiocontext.createGain(),p5.soundOut._silentNode.gain.value=0,p5.soundOut._silentNode.connect(e.audiocontext.destination),e}();var helpers;helpers=function(){var t=master;return p5.prototype.sampleRate=function(){return t.audiocontext.sampleRate},p5.prototype.freqToMidi=function(t){var e=Math.log(t/440)/Math.log(2),i=Math.round(12*e)+69;return i},p5.prototype.midiToFreq=function(t){return 440*Math.pow(2,(t-69)/12)},p5.prototype.soundFormats=function(){t.extensions=[];for(var e=0;e<arguments.length;e++){if(arguments[e]=arguments[e].toLowerCase(),!(["mp3","wav","ogg","m4a","aac"].indexOf(arguments[e])>-1))throw arguments[e]+" is not a valid sound format!";t.extensions.push(arguments[e])}},p5.prototype.disposeSound=function(){for(var e=0;e<t.soundArray.length;e++)t.soundArray[e].dispose()},p5.prototype.registerMethod("remove",p5.prototype.disposeSound),p5.prototype._checkFileFormats=function(e){var i;if("string"==typeof e){i=e;var n=i.split(".").pop();if(["mp3","wav","ogg","m4a","aac"].indexOf(n)>-1)if(p5.prototype.isFileSupported(n))i=i;else for(var o=i.split("."),r=o[o.length-1],s=0;s<t.extensions.length;s++){var a=t.extensions[s],u=p5.prototype.isFileSupported(a);if(u){r="",2===o.length&&(r+=o[0]);for(var s=1;s<=o.length-2;s++){var p=o[s];r+="."+p}i=r+=".",i=i+=a;break}}else for(var s=0;s<t.extensions.length;s++){var a=t.extensions[s],u=p5.prototype.isFileSupported(a);if(u){i=i+"."+a;break}}}else if("object"==typeof e)for(var s=0;s<e.length;s++){var a=e[s].split(".").pop(),u=p5.prototype.isFileSupported(a);if(u){i=e[s];break}}return i},p5.prototype._mathChain=function(t,e,i,n,o){for(var r in t.mathOps)t.mathOps[r]instanceof o&&(t.mathOps[r].dispose(),i=r,i<t.mathOps.length-1&&(n=t.mathOps[r+1]));return t.mathOps[i-1].disconnect(),t.mathOps[i-1].connect(e),e.connect(n),t.mathOps[i]=e,t},{midiToFreq:p5.prototype.midiToFreq}}(master);var errorHandler;errorHandler=function(){var t=function(t,e,i){var n,o,r=new Error;r.name=t,r.originalStack=r.stack+e,n=r.stack+e,r.failedPath=i;var o=n.split("\n");return o=o.filter(function(t){return!t.match(/(p5.|native code|globalInit)/g)}),r.stack=o.join("\n"),r};return t}();var panner;panner=function(){var t=master,e=t.audiocontext;"undefined"!=typeof e.createStereoPanner?(p5.Panner=function(t,i){this.stereoPanner=this.input=e.createStereoPanner(),t.connect(this.stereoPanner),this.stereoPanner.connect(i)},p5.Panner.prototype.pan=function(t,i){var n=i||0,o=e.currentTime+n;this.stereoPanner.pan.linearRampToValueAtTime(t,o)},p5.Panner.prototype.inputChannels=function(){},p5.Panner.prototype.connect=function(t){this.stereoPanner.connect(t)},p5.Panner.prototype.disconnect=function(){this.stereoPanner.disconnect()}):(p5.Panner=function(t,i,n){this.input=e.createGain(),t.connect(this.input),this.left=e.createGain(),this.right=e.createGain(),this.left.channelInterpretation="discrete",this.right.channelInterpretation="discrete",n>1?(this.splitter=e.createChannelSplitter(2),this.input.connect(this.splitter),this.splitter.connect(this.left,1),this.splitter.connect(this.right,0)):(this.input.connect(this.left),this.input.connect(this.right)),this.output=e.createChannelMerger(2),this.left.connect(this.output,0,1),this.right.connect(this.output,0,0),this.output.connect(i)},p5.Panner.prototype.pan=function(t,i){var n=i||0,o=e.currentTime+n,r=(t+1)/2,s=Math.cos(r*Math.PI/2),a=Math.sin(r*Math.PI/2);this.left.gain.linearRampToValueAtTime(a,o),this.right.gain.linearRampToValueAtTime(s,o)},p5.Panner.prototype.inputChannels=function(t){1===t?(this.input.disconnect(),this.input.connect(this.left),this.input.connect(this.right)):2===t&&(this.splitter=e.createChannelSplitter(2),this.input.disconnect(),this.input.connect(this.splitter),this.splitter.connect(this.left,1),this.splitter.connect(this.right,0))},p5.Panner.prototype.connect=function(t){this.output.connect(t)},p5.Panner.prototype.disconnect=function(){this.output.disconnect()}),p5.Panner3D=function(t,i){var n=e.createPanner();return n.panningModel="HRTF",n.distanceModel="linear",n.setPosition(0,0,0),t.connect(n),n.connect(i),n.pan=function(t,e,i){n.setPosition(t,e,i)},n}}(master);var soundfile;soundfile=function(){function t(t,e){for(var i={},n=t.length,o=0;n>o;o++){if(t[o]>e){var r=t[o],s=new c(r,o);i[o]=s,o+=6e3}o++}return i}function e(t){for(var e=[],i=Object.keys(t).sort(),n=0;n<i.length;n++)for(var o=0;10>o;o++){var r=t[i[n]],s=t[i[n+o]];if(r&&s){var a=r.sampleIndex,u=s.sampleIndex,p=u-a;p>0&&r.intervals.push(p);var c=e.some(function(t){return t.interval===p?(t.count++,t):void 0});c||e.push({interval:p,count:1})}}return e}function i(t,e){var i=[];return t.forEach(function(t){try{var n=Math.abs(60/(t.interval/e));n=o(n);var r=i.some(function(e){return e.tempo===n?e.count+=t.count:void 0});if(!r){if(isNaN(n))return;i.push({tempo:Math.round(n),count:t.count})}}catch(s){throw s}}),i}function n(t,e,i,n){for(var r=[],s=Object.keys(t).sort(),a=0;a<s.length;a++)for(var u=s[a],p=t[u],c=0;c<p.intervals.length;c++){var h=Math.round(Math.abs(60/(p.intervals[c]/i)));h=o(h),Math.abs(h-e)<n&&r.push(p.sampleIndex/44100)}return r=r.filter(function(t,e,i){var n=i[e+1]-t;return n>.01?!0:void 0})}function o(t){if(isFinite(t)&&0!==t){for(;90>t;)t*=2;for(;t>180&&t>90;)t/=2;return t}}var r=errorHandler,s=master,a=s.audiocontext,u=helpers.midiToFreq;p5.SoundFile=function(t,e,i,n){if("undefined"!=typeof t){if("string"==typeof t||"string"==typeof t[0]){var o=p5.prototype._checkFileFormats(t);this.url=o}else if("object"==typeof t&&!(window.File&&window.FileReader&&window.FileList&&window.Blob))throw"Unable to load file because the File API is not supported";t.file&&(t=t.file),this.file=t}this._onended=function(){},this._looping=!1,this._playing=!1,this._paused=!1,this._pauseTime=0,this._cues=[],this._lastPos=0,this._counterNode=null,this._scopeNode=null,this.bufferSourceNodes=[],this.bufferSourceNode=null,this.buffer=null,this.playbackRate=1,this.input=s.audiocontext.createGain(),this.output=s.audiocontext.createGain(),this.reversed=!1,this.startTime=0,this.endTime=null,this.pauseTime=0,this.mode="sustain",this.startMillis=null,this.panPosition=0,this.panner=new p5.Panner(this.output,s.input,2),(this.url||this.file)&&this.load(e,i),s.soundArray.push(this),"function"==typeof n?this._whileLoading=n:this._whileLoading=function(){}},p5.prototype.registerPreloadMethod("loadSound",p5.prototype),p5.prototype.loadSound=function(t,e,i,n){window.location.origin.indexOf("file://")>-1&&"undefined"===window.cordova&&window.alert("This sketch may require a server to load external files. Please see http://bit.ly/1qcInwS");var o=this,r=new p5.SoundFile(t,function(){"function"==typeof e&&e.apply(o,arguments),o._decrementPreload()},i,n);return r},p5.SoundFile.prototype.load=function(t,e){var i=this,n=(new Error).stack;if(void 0!==this.url&&""!==this.url){var o=new XMLHttpRequest;o.addEventListener("progress",function(t){i._updateProgress(t)},!1),o.open("GET",this.url,!0),o.responseType="arraybuffer",o.onload=function(){if(200===o.status)a.decodeAudioData(o.response,function(e){i.buffer=e,i.panner.inputChannels(e.numberOfChannels),t&&t(i)},function(){var t=new r("decodeAudioData",n,i.url),o="AudioContext error at decodeAudioData for "+i.url;e?(t.msg=o,e(t)):console.error(o+"\n The error stack trace includes: \n"+t.stack)});else{var s=new r("loadSound",n,i.url),u="Unable to load "+i.url+". The request status was: "+o.status+" ("+o.statusText+")";e?(s.message=u,e(s)):console.error(u+"\n The error stack trace includes: \n"+s.stack)}},o.onerror=function(){var t=new r("loadSound",n,i.url),o="There was no response from the server at "+i.url+". Check the url and internet connectivity.";e?(t.message=o,e(t)):console.error(o+"\n The error stack trace includes: \n"+t.stack)},o.send()}else if(void 0!==this.file){var s=new FileReader;s.onload=function(){a.decodeAudioData(s.result,function(e){i.buffer=e,i.panner.inputChannels(e.numberOfChannels),t&&t(i)})},s.onerror=function(t){onerror&&onerror(t)},s.readAsArrayBuffer(this.file)}},p5.SoundFile.prototype._updateProgress=function(t){if(t.lengthComputable){var e=t.loaded/t.total*.99;this._whileLoading(e,t)}else this._whileLoading("size unknown")},p5.SoundFile.prototype.isLoaded=function(){return this.buffer?!0:!1},p5.SoundFile.prototype.play=function(t,e,i,n,o){var r,a,u=this,p=s.audiocontext.currentTime,c=t||0;if(0>c&&(c=0),c+=p,this.rate(e),this.setVolume(i),!this.buffer)throw"not ready to play file, buffer has yet to load. Try preload()";if(this._pauseTime=0,"restart"===this.mode&&this.buffer&&this.bufferSourceNode&&(this.bufferSourceNode.stop(c),this._counterNode.stop(c)),this.bufferSourceNode=this._initSourceNode(),this._counterNode&&(this._counterNode=void 0),this._counterNode=this._initCounterNode(),n){if(!(n>=0&&n<this.buffer.duration))throw"start time out of range";r=n}else r=0;o=o?o<=this.buffer.duration-r?o:this.buffer.duration:this.buffer.duration-r,this.bufferSourceNode.connect(this.output),this._paused?(this.bufferSourceNode.start(c,this.pauseTime,o),this._counterNode.start(c,this.pauseTime,o)):(this.bufferSourceNode.start(c,r,o),this._counterNode.start(c,r,o)),this._playing=!0,this._paused=!1,this.bufferSourceNodes.push(this.bufferSourceNode),this.bufferSourceNode._arrayIndex=this.bufferSourceNodes.length-1;var h=function(){this._playing=!1,this.removeEventListener("ended",h,!1),u._onended(u),u.bufferSourceNodes.forEach(function(t,e){t._playing===!1&&u.bufferSourceNodes.splice(e)}),0===u.bufferSourceNodes.length&&(u._playing=!1)};this.bufferSourceNode.onended=h,this.bufferSourceNode.loop=this._looping,this._counterNode.loop=this._looping,this._looping===!0&&(a=r+o,this.bufferSourceNode.loopStart=r,this.bufferSourceNode.loopEnd=a,this._counterNode.loopStart=r,this._counterNode.loopEnd=a)},p5.SoundFile.prototype.playMode=function(t){var e=t.toLowerCase();if("restart"===e&&this.buffer&&this.bufferSourceNode)for(var i=0;i<this.bufferSourceNodes.length-1;i++){var n=s.audiocontext.currentTime;this.bufferSourceNodes[i].stop(n)}if("restart"!==e&&"sustain"!==e)throw'Invalid play mode. Must be either "restart" or "sustain"';this.mode=e},p5.SoundFile.prototype.pause=function(t){var e=s.audiocontext.currentTime,i=t||0,n=i+e;this.isPlaying()&&this.buffer&&this.bufferSourceNode?(this.pauseTime=this.currentTime(),this.bufferSourceNode.stop(n),this._counterNode.stop(n),this._paused=!0,this._playing=!1,this._pauseTime=this.currentTime()):this._pauseTime=0},p5.SoundFile.prototype.loop=function(t,e,i,n,o){this._looping=!0,this.play(t,e,i,n,o)},p5.SoundFile.prototype.setLoop=function(t){if(t===!0)this._looping=!0;else{if(t!==!1)throw"Error: setLoop accepts either true or false";this._looping=!1}this.bufferSourceNode&&(this.bufferSourceNode.loop=this._looping,this._counterNode.loop=this._looping)},p5.SoundFile.prototype.isLooping=function(){return this.bufferSourceNode&&this._looping===!0&&this.isPlaying()===!0?!0:!1},p5.SoundFile.prototype.isPlaying=function(){return this._playing},p5.SoundFile.prototype.isPaused=function(){return this._paused},p5.SoundFile.prototype.stop=function(t){var e=t||0;if("sustain"===this.mode)this.stopAll(e),this._playing=!1,this.pauseTime=0,this._paused=!1;else if(this.buffer&&this.bufferSourceNode){var i=s.audiocontext.currentTime,n=e||0;this.pauseTime=0,this.bufferSourceNode.stop(i+n),this._counterNode.stop(i+n),this._playing=!1,this._paused=!1}},p5.SoundFile.prototype.stopAll=function(t){var e=s.audiocontext.currentTime,i=t||0;if(this.buffer&&this.bufferSourceNode){for(var n=0;n<this.bufferSourceNodes.length;n++)if(void 0!==typeof this.bufferSourceNodes[n])try{this.bufferSourceNodes[n].onended=function(){},this.bufferSourceNodes[n].stop(e+i)}catch(o){}this._counterNode.stop(e+i),this._onended(this)}},p5.SoundFile.prototype.setVolume=function(t,e,i){if("number"==typeof t){var n=e||0,o=i||0,r=s.audiocontext.currentTime,a=this.output.gain.value;this.output.gain.cancelScheduledValues(r+o),this.output.gain.linearRampToValueAtTime(a,r+o),this.output.gain.linearRampToValueAtTime(t,r+o+n)}else{if(!t)return this.output.gain;t.connect(this.output.gain)}},p5.SoundFile.prototype.amp=p5.SoundFile.prototype.setVolume,p5.SoundFile.prototype.fade=p5.SoundFile.prototype.setVolume,p5.SoundFile.prototype.getVolume=function(){return this.output.gain.value},p5.SoundFile.prototype.pan=function(t,e){this.panPosition=t,this.panner.pan(t,e)},p5.SoundFile.prototype.getPan=function(){return this.panPosition},p5.SoundFile.prototype.rate=function(t){if("undefined"==typeof t)return this.playbackRate;if(0===t)t=1e-13;else if(0>t&&!this.reversed){var e=this.currentTime(),i=(e-this.duration())/t;this.pauseTime=i,this.reverseBuffer(),t=Math.abs(t)}else t>0&&this.reversed&&this.reverseBuffer();if(this.bufferSourceNode){var n=s.audiocontext.currentTime;this.bufferSourceNode.playbackRate.cancelScheduledValues(n),this.bufferSourceNode.playbackRate.linearRampToValueAtTime(Math.abs(t),n),this._counterNode.playbackRate.cancelScheduledValues(n),this._counterNode.playbackRate.linearRampToValueAtTime(Math.abs(t),n)}return this.playbackRate=t,this.playbackRate},p5.SoundFile.prototype.setPitch=function(t){var e=u(t)/u(60);this.rate(e)},p5.SoundFile.prototype.getPlaybackRate=function(){return this.playbackRate},p5.SoundFile.prototype.duration=function(){return this.buffer?this.buffer.duration:0},p5.SoundFile.prototype.currentTime=function(){return this._pauseTime>0?this._pauseTime:this._lastPos/a.sampleRate},p5.SoundFile.prototype.jump=function(t,e){if(0>t||t>this.buffer.duration)throw"jump time out of range";if(e>this.buffer.duration-t)throw"end time out of range";var i=t||0,n=e||this.buffer.duration-t;this.isPlaying()&&this.stop(),this.play(0,this.playbackRate,this.output.gain.value,i,n)},p5.SoundFile.prototype.channels=function(){return this.buffer.numberOfChannels},p5.SoundFile.prototype.sampleRate=function(){return this.buffer.sampleRate},p5.SoundFile.prototype.frames=function(){return this.buffer.length},p5.SoundFile.prototype.getPeaks=function(t){if(!this.buffer)throw"Cannot load peaks yet, buffer is not loaded";if(t||(t=5*window.width),this.buffer){for(var e=this.buffer,i=e.length/t,n=~~(i/10)||1,o=e.numberOfChannels,r=new Float32Array(Math.round(t)),s=0;o>s;s++)for(var a=e.getChannelData(s),u=0;t>u;u++){for(var p=~~(u*i),c=~~(p+i),h=0,l=p;c>l;l+=n){var f=a[l];f>h?h=f:-f>h&&(h=f)}(0===s||Math.abs(h)>r[u])&&(r[u]=h)}return r}},p5.SoundFile.prototype.reverseBuffer=function(){var t=this.getVolume();if(this.setVolume(0,.01,0),!this.buffer)throw"SoundFile is not done loading";for(var e=0;e<this.buffer.numberOfChannels;e++)Array.prototype.reverse.call(this.buffer.getChannelData(e));this.reversed=!this.reversed,this.setVolume(t,.01,.0101)},p5.SoundFile.prototype.onended=function(t){return this._onended=t,this},p5.SoundFile.prototype.add=function(){},p5.SoundFile.prototype.dispose=function(){var t=s.audiocontext.currentTime,e=s.soundArray.indexOf(this);if(s.soundArray.splice(e,1),this.stop(t),this.buffer&&this.bufferSourceNode){for(var i=0;i<this.bufferSourceNodes.length-1;i++)if(null!==this.bufferSourceNodes[i]){this.bufferSourceNodes[i].disconnect();try{this.bufferSourceNodes[i].stop(t)}catch(n){console.warning("no buffer source node to dispose")}this.bufferSourceNodes[i]=null}if(this.isPlaying()){try{this._counterNode.stop(t)}catch(n){console.log(n)}this._counterNode=null}}this.output&&(this.output.disconnect(),this.output=null),this.panner&&(this.panner.disconnect(),this.panner=null)},p5.SoundFile.prototype.connect=function(t){t?t.hasOwnProperty("input")?this.panner.connect(t.input):this.panner.connect(t):this.panner.connect(s.input)},p5.SoundFile.prototype.disconnect=function(){this.panner.disconnect()},p5.SoundFile.prototype.getLevel=function(){console.warn("p5.SoundFile.getLevel has been removed from the library. Use p5.Amplitude instead")},p5.SoundFile.prototype.setPath=function(t,e){var i=p5.prototype._checkFileFormats(t);this.url=i,this.load(e)},p5.SoundFile.prototype.setBuffer=function(t){var e=t.length,i=t[0].length,n=a.createBuffer(e,i,a.sampleRate);t[0]instanceof Float32Array||(t[0]=new Float32Array(t[0]));for(var o=0;e>o;o++){var r=n.getChannelData(o);r.set(t[o])}this.buffer=n,this.panner.inputChannels(e)};var p=function(t){for(var e=new Float32Array(t.length),i=a.createBuffer(1,t.length,44100),n=0;n<t.length;n++)e[n]=n;return i.getChannelData(0).set(e),i};p5.SoundFile.prototype._initCounterNode=function(){var t=this,e=a.currentTime,i=a.createBufferSource();return t._scopeNode&&(t._scopeNode.disconnect(),t._scopeNode.onaudioprocess=void 0,t._scopeNode=null),t._scopeNode=a.createScriptProcessor(256,1,1),i.buffer=p(t.buffer),i.playbackRate.setValueAtTime(t.playbackRate,e),i.connect(t._scopeNode),t._scopeNode.connect(p5.soundOut._silentNode),t._scopeNode.onaudioprocess=function(e){var i=e.inputBuffer.getChannelData(0);t._lastPos=i[i.length-1]||0,t._onTimeUpdate(t._lastPos)},i},p5.SoundFile.prototype._initSourceNode=function(){var t=a.createBufferSource();return t.buffer=this.buffer,t.playbackRate.value=this.playbackRate,t},p5.SoundFile.prototype.processPeaks=function(o,r,s,a){var u=this.buffer.length,p=this.buffer.sampleRate,c=this.buffer,h=[],l=r||.9,f=l,d=s||.22,m=a||200,y=new window.OfflineAudioContext(1,u,p),_=y.createBufferSource();_.buffer=c;var g=y.createBiquadFilter();g.type="lowpass",_.connect(g),g.connect(y.destination),_.start(0),y.startRendering(),y.oncomplete=function(r){var s=r.renderedBuffer,a=s.getChannelData(0);do h=t(a,f),f-=.005;while(Object.keys(h).length<m&&f>=d);var u=e(h),p=i(u,s.sampleRate),c=p.sort(function(t,e){return e.count-t.count}).splice(0,5);this.tempo=c[0].tempo;var l=5,y=n(h,c[0].tempo,s.sampleRate,l);o(y)}};var c=function(t,e){this.sampleIndex=e,this.amplitude=t,this.tempos=[],this.intervals=[]},h=function(t,e,i,n){this.callback=t,this.time=e,this.id=i,this.val=n};p5.SoundFile.prototype.addCue=function(t,e,i){var n=this._cueIDCounter++,o=new h(e,t,n,i);return this._cues.push(o),n},p5.SoundFile.prototype.removeCue=function(t){for(var e=this._cues.length,i=0;e>i;i++){var n=this._cues[i];n.id===t&&this.cues.splice(i,1)}0===this._cues.length},p5.SoundFile.prototype.clearCues=function(){this._cues=[]},p5.SoundFile.prototype._onTimeUpdate=function(t){for(var e=t/this.buffer.sampleRate,i=this._cues.length,n=0;i>n;n++){var o=this._cues[n],r=o.time,s=o.val;this._prevTime<r&&e>=r&&o.callback(s)}this._prevTime=e}}(sndcore,errorHandler,master,helpers);var amplitude;amplitude=function(){var t=master;p5.Amplitude=function(e){this.bufferSize=2048,this.audiocontext=t.audiocontext,this.processor=this.audiocontext.createScriptProcessor(this.bufferSize,2,1),this.input=this.processor,this.output=this.audiocontext.createGain(),this.smoothing=e||0,this.volume=0,this.average=0,this.stereoVol=[0,0],this.stereoAvg=[0,0],this.stereoVolNorm=[0,0],this.volMax=.001,this.normalize=!1,this.processor.onaudioprocess=this._audioProcess.bind(this),this.processor.connect(this.output),this.output.gain.value=0,this.output.connect(this.audiocontext.destination),t.meter.connect(this.processor),t.soundArray.push(this)},p5.Amplitude.prototype.setInput=function(e,i){t.meter.disconnect(),i&&(this.smoothing=i),null==e?(console.log("Amplitude input source is not ready! Connecting to master output instead"),t.meter.connect(this.processor)):e instanceof p5.Signal?e.output.connect(this.processor):e?(e.connect(this.processor),this.processor.disconnect(),this.processor.connect(this.output)):t.meter.connect(this.processor)},p5.Amplitude.prototype.connect=function(e){e?e.hasOwnProperty("input")?this.output.connect(e.input):this.output.connect(e):this.output.connect(this.panner.connect(t.input))},p5.Amplitude.prototype.disconnect=function(){this.output.disconnect()},p5.Amplitude.prototype._audioProcess=function(t){for(var e=0;e<t.inputBuffer.numberOfChannels;e++){for(var i,n=t.inputBuffer.getChannelData(e),o=n.length,r=0,s=0,a=0;o>a;a++)i=n[a],this.normalize?(r+=Math.max(Math.min(i/this.volMax,1),-1),s+=Math.max(Math.min(i/this.volMax,1),-1)*Math.max(Math.min(i/this.volMax,1),-1)):(r+=i,s+=i*i);var u=r/o,p=Math.sqrt(s/o);this.stereoVol[e]=Math.max(p,this.stereoVol[e]*this.smoothing),this.stereoAvg[e]=Math.max(u,this.stereoVol[e]*this.smoothing),this.volMax=Math.max(this.stereoVol[e],this.volMax)}var c=this,h=this.stereoVol.reduce(function(t,e,i){return c.stereoVolNorm[i-1]=Math.max(Math.min(c.stereoVol[i-1]/c.volMax,1),0),c.stereoVolNorm[i]=Math.max(Math.min(c.stereoVol[i]/c.volMax,1),0),t+e});this.volume=h/this.stereoVol.length,this.volNorm=Math.max(Math.min(this.volume/this.volMax,1),0)},p5.Amplitude.prototype.getLevel=function(t){return"undefined"!=typeof t?this.normalize?this.stereoVolNorm[t]:this.stereoVol[t]:this.normalize?this.volNorm:this.volume},p5.Amplitude.prototype.toggleNormalize=function(t){"boolean"==typeof t?this.normalize=t:this.normalize=!this.normalize},p5.Amplitude.prototype.smooth=function(t){t>=0&&1>t?this.smoothing=t:console.log("Error: smoothing must be between 0 and 1")},p5.Amplitude.prototype.dispose=function(){var e=t.soundArray.indexOf(this);t.soundArray.splice(e,1),this.input.disconnect(),this.output.disconnect(),this.input=this.processor=void 0,this.output=void 0}}(master);var fft;fft=function(){var t=master;p5.FFT=function(e,i){this.input=this.analyser=t.audiocontext.createAnalyser(),Object.defineProperties(this,{bins:{get:function(){return this.analyser.fftSize/2},set:function(t){this.analyser.fftSize=2*t},configurable:!0,enumerable:!0},smoothing:{get:function(){return this.analyser.smoothingTimeConstant},set:function(t){this.analyser.smoothingTimeConstant=t},configurable:!0,enumerable:!0}}),this.smooth(e),this.bins=i||1024,t.fftMeter.connect(this.analyser),this.freqDomain=new Uint8Array(this.analyser.frequencyBinCount),this.timeDomain=new Uint8Array(this.analyser.frequencyBinCount),this.bass=[20,140],this.lowMid=[140,400],this.mid=[400,2600],this.highMid=[2600,5200],this.treble=[5200,14e3],t.soundArray.push(this)},p5.FFT.prototype.setInput=function(e){e?(e.output?e.output.connect(this.analyser):e.connect&&e.connect(this.analyser),t.fftMeter.disconnect()):t.fftMeter.connect(this.analyser)},p5.FFT.prototype.waveform=function(){for(var t,e,i,r=0;r<arguments.length;r++)"number"==typeof arguments[r]&&(t=arguments[r],this.analyser.fftSize=2*t),"string"==typeof arguments[r]&&(e=arguments[r]);if(e&&!p5.prototype._isSafari())return n(this,this.timeDomain),this.analyser.getFloatTimeDomainData(this.timeDomain),this.timeDomain;o(this,this.timeDomain),this.analyser.getByteTimeDomainData(this.timeDomain);for(var i=new Array,s=0;s<this.timeDomain.length;s++){var a=p5.prototype.map(this.timeDomain[s],0,255,-1,1);i.push(a)}return i},p5.FFT.prototype.analyze=function(){for(var t,n=0;n<arguments.length;n++)"number"==typeof arguments[n]&&(this.bins=arguments[n],this.analyser.fftSize=2*this.bins),"string"==typeof arguments[n]&&(t=arguments[n]);if(t&&"db"===t.toLowerCase())return e(this),this.analyser.getFloatFrequencyData(this.freqDomain),this.freqDomain;i(this,this.freqDomain),this.analyser.getByteFrequencyData(this.freqDomain);var o=Array.apply([],this.freqDomain);return o.length===this.analyser.fftSize,o.constructor===Array,o},p5.FFT.prototype.getEnergy=function(e,i){var n=t.audiocontext.sampleRate/2;if("bass"===e?(e=this.bass[0],i=this.bass[1]):"lowMid"===e?(e=this.lowMid[0],i=this.lowMid[1]):"mid"===e?(e=this.mid[0],i=this.mid[1]):"highMid"===e?(e=this.highMid[0],i=this.highMid[1]):"treble"===e&&(e=this.treble[0],i=this.treble[1]),"number"!=typeof e)throw"invalid input for getEnergy()";if(i){if(e&&i){if(e>i){var o=i;i=e,e=o}for(var r=Math.round(e/n*this.freqDomain.length),s=Math.round(i/n*this.freqDomain.length),a=0,u=0,p=r;s>=p;p++)a+=this.freqDomain[p],u+=1;var c=a/u;return c}throw"invalid input for getEnergy()"}var h=Math.round(e/n*this.freqDomain.length);return this.freqDomain[h]},p5.FFT.prototype.getFreq=function(t,e){console.log("getFreq() is deprecated. Please use getEnergy() instead.");var i=this.getEnergy(t,e);return i},p5.FFT.prototype.getCentroid=function(){for(var e=t.audiocontext.sampleRate/2,i=0,n=0,o=0;o<this.freqDomain.length;o++)i+=o*this.freqDomain[o],n+=this.freqDomain[o];var r=0;0!==n&&(r=i/n);var s=r*(e/this.freqDomain.length);return s},p5.FFT.prototype.smooth=function(t){return"undefined"!=typeof t&&(this.smoothing=t),this.smoothing},p5.FFT.prototype.dispose=function(){var e=t.soundArray.indexOf(this);t.soundArray.splice(e,1),this.analyser.disconnect(),this.analyser=void 0},p5.FFT.prototype.linAverages=function(t){for(var t=t||16,e=this.freqDomain,i=e.length,n=Math.floor(i/t),o=new Array(t),r=0,s=0;i>s;s++)o[r]=void 0!==o[r]?(o[r]+e[s])/2:e[s],s%n===n-1&&r++;return o},p5.FFT.prototype.logAverages=function(e){for(var i=t.audiocontext.sampleRate/2,n=this.freqDomain,o=n.length,r=new Array(e.length),s=0,a=0;o>a;a++){var u=Math.round(a*i/this.freqDomain.length);u>e[s].hi&&s++,r[s]=void 0!==r[s]?(r[s]+n[a])/2:n[a]}return r},p5.FFT.prototype.getOctaveBands=function(e,i){var e=e||3,i=i||15.625,n=[],o={lo:i/Math.pow(2,1/(2*e)),ctr:i,hi:i*Math.pow(2,1/(2*e))};n.push(o);for(var r=t.audiocontext.sampleRate/2;o.hi<r;){var s={};s.lo=o.hi,s.ctr=o.ctr*Math.pow(2,1/e),s.hi=s.ctr*Math.pow(2,1/(2*e)),n.push(s),o=s}return n};var e=function(t){t.freqDomain instanceof Float32Array==!1&&(t.freqDomain=new Float32Array(t.analyser.frequencyBinCount))},i=function(t){t.freqDomain instanceof Uint8Array==!1&&(t.freqDomain=new Uint8Array(t.analyser.frequencyBinCount))},n=function(t){t.timeDomain instanceof Float32Array==!1&&(t.timeDomain=new Float32Array(t.analyser.frequencyBinCount))},o=function(t){t.timeDomain instanceof Uint8Array==!1&&(t.timeDomain=new Uint8Array(t.analyser.frequencyBinCount))}}(master);var Tone_core_Tone;Tone_core_Tone=function(){"use strict";function t(t){return void 0===t}function e(t){return"function"==typeof t}var i;if(t(window.AudioContext)&&(window.AudioContext=window.webkitAudioContext),t(window.OfflineAudioContext)&&(window.OfflineAudioContext=window.webkitOfflineAudioContext),t(AudioContext))throw new Error("Web Audio is not supported in this browser");i=new AudioContext,e(AudioContext.prototype.createGain)||(AudioContext.prototype.createGain=AudioContext.prototype.createGainNode),e(AudioContext.prototype.createDelay)||(AudioContext.prototype.createDelay=AudioContext.prototype.createDelayNode),e(AudioContext.prototype.createPeriodicWave)||(AudioContext.prototype.createPeriodicWave=AudioContext.prototype.createWaveTable),e(AudioBufferSourceNode.prototype.start)||(AudioBufferSourceNode.prototype.start=AudioBufferSourceNode.prototype.noteGrainOn), e(AudioBufferSourceNode.prototype.stop)||(AudioBufferSourceNode.prototype.stop=AudioBufferSourceNode.prototype.noteOff),e(OscillatorNode.prototype.start)||(OscillatorNode.prototype.start=OscillatorNode.prototype.noteOn),e(OscillatorNode.prototype.stop)||(OscillatorNode.prototype.stop=OscillatorNode.prototype.noteOff),e(OscillatorNode.prototype.setPeriodicWave)||(OscillatorNode.prototype.setPeriodicWave=OscillatorNode.prototype.setWaveTable),AudioNode.prototype._nativeConnect=AudioNode.prototype.connect,AudioNode.prototype.connect=function(e,i,n){if(e.input)Array.isArray(e.input)?(t(n)&&(n=0),this.connect(e.input[n])):this.connect(e.input,i,n);else try{e instanceof AudioNode?this._nativeConnect(e,i,n):this._nativeConnect(e,i)}catch(o){throw new Error("error connecting to node: "+e)}};var n=function(e,i){t(e)||1===e?this.input=this.context.createGain():e>1&&(this.input=new Array(e)),t(i)||1===i?this.output=this.context.createGain():i>1&&(this.output=new Array(e))};n.prototype.set=function(e,i,o){if(this.isObject(e))o=i;else if(this.isString(e)){var r={};r[e]=i,e=r}for(var s in e){i=e[s];var a=this;if(-1!==s.indexOf(".")){for(var u=s.split("."),p=0;p<u.length-1;p++)a=a[u[p]];s=u[u.length-1]}var c=a[s];t(c)||(n.Signal&&c instanceof n.Signal||n.Param&&c instanceof n.Param?c.value!==i&&(t(o)?c.value=i:c.rampTo(i,o)):c instanceof AudioParam?c.value!==i&&(c.value=i):c instanceof n?c.set(i):c!==i&&(a[s]=i))}return this},n.prototype.get=function(i){t(i)?i=this._collectDefaults(this.constructor):this.isString(i)&&(i=[i]);for(var o={},r=0;r<i.length;r++){var s=i[r],a=this,u=o;if(-1!==s.indexOf(".")){for(var p=s.split("."),c=0;c<p.length-1;c++){var h=p[c];u[h]=u[h]||{},u=u[h],a=a[h]}s=p[p.length-1]}var l=a[s];this.isObject(i[s])?u[s]=l.get():n.Signal&&l instanceof n.Signal?u[s]=l.value:n.Param&&l instanceof n.Param?u[s]=l.value:l instanceof AudioParam?u[s]=l.value:l instanceof n?u[s]=l.get():e(l)||t(l)||(u[s]=l)}return o},n.prototype._collectDefaults=function(e){var i=[];if(t(e.defaults)||(i=Object.keys(e.defaults)),!t(e._super))for(var n=this._collectDefaults(e._super),o=0;o<n.length;o++)-1===i.indexOf(n[o])&&i.push(n[o]);return i},n.prototype.toString=function(){for(var t in n){var i=t[0].match(/^[A-Z]$/),o=n[t]===this.constructor;if(e(n[t])&&i&&o)return t}return"Tone"},n.context=i,n.prototype.context=n.context,n.prototype.bufferSize=2048,n.prototype.blockTime=128/n.context.sampleRate,n.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};var o=null;n.prototype.noGC=function(){return this.output.connect(o),this},AudioNode.prototype.noGC=function(){return this.connect(o),this},n.prototype.connect=function(t,e,i){return Array.isArray(this.output)?(e=this.defaultArg(e,0),this.output[e].connect(t,0,i)):this.output.connect(t,e,i),this},n.prototype.disconnect=function(t){return Array.isArray(this.output)?(t=this.defaultArg(t,0),this.output[t].disconnect()):this.output.disconnect(),this},n.prototype.connectSeries=function(){if(arguments.length>1)for(var t=arguments[0],e=1;e<arguments.length;e++){var i=arguments[e];t.connect(i),t=i}return this},n.prototype.connectParallel=function(){var t=arguments[0];if(arguments.length>1)for(var e=1;e<arguments.length;e++){var i=arguments[e];t.connect(i)}return this},n.prototype.chain=function(){if(arguments.length>0)for(var t=this,e=0;e<arguments.length;e++){var i=arguments[e];t.connect(i),t=i}return this},n.prototype.fan=function(){if(arguments.length>0)for(var t=0;t<arguments.length;t++)this.connect(arguments[t]);return this},AudioNode.prototype.chain=n.prototype.chain,AudioNode.prototype.fan=n.prototype.fan,n.prototype.defaultArg=function(e,i){if(this.isObject(e)&&this.isObject(i)){var n={};for(var o in e)n[o]=this.defaultArg(i[o],e[o]);for(var r in i)n[r]=this.defaultArg(e[r],i[r]);return n}return t(e)?i:e},n.prototype.optionsObject=function(t,e,i){var n={};if(1===t.length&&this.isObject(t[0]))n=t[0];else for(var o=0;o<e.length;o++)n[e[o]]=t[o];return this.isUndef(i)?n:this.defaultArg(n,i)},n.prototype.isUndef=t,n.prototype.isFunction=e,n.prototype.isNumber=function(t){return"number"==typeof t},n.prototype.isObject=function(t){return"[object Object]"===Object.prototype.toString.call(t)&&t.constructor===Object},n.prototype.isBoolean=function(t){return"boolean"==typeof t},n.prototype.isArray=function(t){return Array.isArray(t)},n.prototype.isString=function(t){return"string"==typeof t},n.noOp=function(){},n.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})},n.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})},n.State={Started:"started",Stopped:"stopped",Paused:"paused"},n.prototype.equalPowerScale=function(t){var e=.5*Math.PI;return Math.sin(t*e)},n.prototype.dbToGain=function(t){return Math.pow(2,t/6)},n.prototype.gainToDb=function(t){return 20*(Math.log(t)/Math.LN10)},n.prototype.now=function(){return this.context.currentTime},n.extend=function(e,i){function o(){}t(i)&&(i=n),o.prototype=i.prototype,e.prototype=new o,e.prototype.constructor=e,e._super=i};var r=[];return n._initAudioContext=function(t){t(n.context),r.push(t)},n.setContext=function(t){n.prototype.context=t,n.context=t;for(var e=0;e<r.length;e++)r[e](t)},n.startMobile=function(){var t=n.context.createOscillator(),e=n.context.createGain();e.gain.value=0,t.connect(e),e.connect(n.context.destination);var i=n.context.currentTime;t.start(i),t.stop(i+1)},n._initAudioContext(function(t){n.prototype.blockTime=128/t.sampleRate,o=t.createGain(),o.gain.value=0,o.connect(t.destination)}),n.version="r7-dev",n}();var Tone_signal_SignalBase;Tone_signal_SignalBase=function(t){"use strict";return t.SignalBase=function(){},t.extend(t.SignalBase),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.prototype.connect.call(this,e,i,n),this},t.SignalBase}(Tone_core_Tone);var Tone_signal_WaveShaper;Tone_signal_WaveShaper=function(t){"use strict";return t.WaveShaper=function(t,e){this._shaper=this.input=this.output=this.context.createWaveShaper(),this._curve=null,Array.isArray(t)?this.curve=t:isFinite(t)||this.isUndef(t)?this._curve=new Float32Array(this.defaultArg(t,1024)):this.isFunction(t)&&(this._curve=new Float32Array(this.defaultArg(e,1024)),this.setMap(t))},t.extend(t.WaveShaper,t.SignalBase),t.WaveShaper.prototype.setMap=function(t){for(var e=0,i=this._curve.length;i>e;e++){var n=e/i*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 Error("invalid oversampling: "+t);this._shaper.oversample=t}}),t.WaveShaper.prototype.dispose=function(){return t.prototype.dispose.call(this),this._shaper.disconnect(),this._shaper=null,this._curve=null,this},t.WaveShaper}(Tone_core_Tone);var Tone_core_Type;Tone_core_Type=function(Tone){"use strict";function getTransportBpm(){return Tone.Transport&&Tone.Transport.bpm?Tone.Transport.bpm.value:120}function getTransportTimeSignature(){return Tone.Transport&&Tone.Transport.timeSignature?Tone.Transport.timeSignature:4}function toNotationHelper(t,e,i,n){for(var o=this.toSeconds(t),r=this.notationToSeconds(n[n.length-1],e,i),s="",a=0;a<n.length;a++){var u=this.notationToSeconds(n[a],e,i),p=o/u,c=1e-6;if(c>1-p%1&&(p+=c),p=Math.floor(p),p>0){if(s+=1===p?n[a]:p.toString()+"*"+n[a],o-=p*u,r>o)break;s+=" + "}}return""===s&&(s="0"),s}Tone.Type={Default:"number",Time:"time",Frequency:"frequency",NormalRange:"normalRange",AudioRange:"audioRange",Decibels:"db",Interval:"interval",BPM:"bpm",Positive:"positive",Cents:"cents",Degrees:"degrees",MIDI:"midi",TransportTime:"transportTime",Ticks:"tick",Note:"note",Milliseconds:"milliseconds",Notation:"notation"},Tone.prototype.isNowRelative=function(){var t=new RegExp(/^\s*\+(.)+/i);return function(e){return t.test(e)}}(),Tone.prototype.isTicks=function(){var t=new RegExp(/^\d+i$/i);return function(e){return t.test(e)}}(),Tone.prototype.isNotation=function(){var t=new RegExp(/^[0-9]+[mnt]$/i);return function(e){return t.test(e)}}(),Tone.prototype.isTransportTime=function(){var t=new RegExp(/^(\d+(\.\d+)?\:){1,2}(\d+(\.\d+)?)?$/i);return function(e){return t.test(e)}}(),Tone.prototype.isNote=function(){var t=new RegExp(/^[a-g]{1}(b|#|x|bb)?-?[0-9]+$/i);return function(e){return t.test(e)}}(),Tone.prototype.isFrequency=function(){var t=new RegExp(/^\d*\.?\d+hz$/i);return function(e){return t.test(e)}}(),Tone.prototype.notationToSeconds=function(t,e,i){e=this.defaultArg(e,getTransportBpm()),i=this.defaultArg(i,getTransportTimeSignature());var n=60/e;"1n"===t&&(t="1m");var o=parseInt(t,10),r=0;0===o&&(r=0);var s=t.slice(-1);return r="t"===s?4/o*2/3:"n"===s?4/o:"m"===s?o*i:0,n*r},Tone.prototype.transportTimeToSeconds=function(t,e,i){e=this.defaultArg(e,getTransportBpm()),i=this.defaultArg(i,getTransportTimeSignature());var n=0,o=0,r=0,s=t.split(":");2===s.length?(n=parseFloat(s[0]),o=parseFloat(s[1])):1===s.length?o=parseFloat(s[0]):3===s.length&&(n=parseFloat(s[0]),o=parseFloat(s[1]),r=parseFloat(s[2]));var a=n*i+o+r/4;return a*(60/e)},Tone.prototype.ticksToSeconds=function(t,e){if(this.isUndef(Tone.Transport))return 0;t=parseFloat(t),e=this.defaultArg(e,getTransportBpm());var i=60/e/Tone.Transport.PPQ;return i*t},Tone.prototype.frequencyToSeconds=function(t){return 1/parseFloat(t)},Tone.prototype.samplesToSeconds=function(t){return t/this.context.sampleRate},Tone.prototype.secondsToSamples=function(t){return t*this.context.sampleRate},Tone.prototype.secondsToTransportTime=function(t,e,i){e=this.defaultArg(e,getTransportBpm()),i=this.defaultArg(i,getTransportTimeSignature());var n=60/e,o=t/n,r=Math.floor(o/i),s=o%1*4;o=Math.floor(o)%i;var a=[r,o,s];return a.join(":")},Tone.prototype.secondsToFrequency=function(t){return 1/t},Tone.prototype.toTransportTime=function(t,e,i){var n=this.toSeconds(t);return this.secondsToTransportTime(n,e,i)},Tone.prototype.toFrequency=function(t,e){return this.isFrequency(t)?parseFloat(t):this.isNotation(t)||this.isTransportTime(t)?this.secondsToFrequency(this.toSeconds(t,e)):this.isNote(t)?this.noteToFrequency(t):t},Tone.prototype.toTicks=function(t){if(this.isUndef(Tone.Transport))return 0;var e=Tone.Transport.bpm.value,i=0;if(this.isNowRelative(t))t=t.replace("+",""),i=Tone.Transport.ticks;else if(this.isUndef(t))return Tone.Transport.ticks;var n=this.toSeconds(t),o=60/e,r=n/o,s=r*Tone.Transport.PPQ;return Math.round(s+i)},Tone.prototype.toSamples=function(t){var e=this.toSeconds(t);return Math.round(e*this.context.sampleRate)},Tone.prototype.toSeconds=function(time,now){if(now=this.defaultArg(now,this.now()),this.isNumber(time))return time;if(this.isString(time)){var plusTime=0;this.isNowRelative(time)&&(time=time.replace("+",""),plusTime=now);var betweenParens=time.match(/\(([^)(]+)\)/g);if(betweenParens)for(var j=0;j<betweenParens.length;j++){var symbol=betweenParens[j].replace(/[\(\)]/g,""),symbolVal=this.toSeconds(symbol);time=time.replace(betweenParens[j],symbolVal)}if(-1!==time.indexOf("@")){var quantizationSplit=time.split("@");if(this.isUndef(Tone.Transport))throw new Error("quantization requires Tone.Transport");var toQuantize=quantizationSplit[0].trim();""===toQuantize&&(toQuantize=void 0),plusTime>0&&(toQuantize="+"+toQuantize,plusTime=0);var subdivision=quantizationSplit[1].trim();time=Tone.Transport.quantize(toQuantize,subdivision)}else{var components=time.split(/[\(\)\-\+\/\*]/);if(components.length>1){for(var originalTime=time,i=0;i<components.length;i++){var symb=components[i].trim();if(""!==symb){var val=this.toSeconds(symb);time=time.replace(symb,val)}}try{time=eval(time)}catch(e){throw new EvalError("cannot evaluate Time: "+originalTime)}}else time=this.isNotation(time)?this.notationToSeconds(time):this.isTransportTime(time)?this.transportTimeToSeconds(time):this.isFrequency(time)?this.frequencyToSeconds(time):this.isTicks(time)?this.ticksToSeconds(time):parseFloat(time)}return time+plusTime}return now},Tone.prototype.toNotation=function(t,e,i){var n=["1m","2n","4n","8n","16n","32n","64n","128n"],o=toNotationHelper.call(this,t,e,i,n),r=["1m","2n","2t","4n","4t","8n","8t","16n","16t","32n","32t","64n","64t","128n"],s=toNotationHelper.call(this,t,e,i,r);return s.split("+").length<o.split("+").length?s:o},Tone.prototype.fromUnits=function(t,e){if(!this.convert&&!this.isUndef(this.convert))return t;switch(e){case Tone.Type.Time:return this.toSeconds(t);case Tone.Type.Frequency:return this.toFrequency(t);case Tone.Type.Decibels:return this.dbToGain(t);case Tone.Type.NormalRange:return Math.min(Math.max(t,0),1);case Tone.Type.AudioRange:return Math.min(Math.max(t,-1),1);case Tone.Type.Positive:return Math.max(t,0);default:return t}},Tone.prototype.toUnits=function(t,e){if(!this.convert&&!this.isUndef(this.convert))return t;switch(e){case Tone.Type.Decibels:return this.gainToDb(t);default:return t}};var noteToScaleIndex={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},scaleIndexToNote=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"];return Tone.A4=440,Tone.prototype.noteToFrequency=function(t){var e=t.split(/(-?\d+)/);if(3===e.length){var i=noteToScaleIndex[e[0].toLowerCase()],n=e[1],o=i+12*(parseInt(n,10)+1);return this.midiToFrequency(o)}return 0},Tone.prototype.frequencyToNote=function(t){var e=Math.log(t/Tone.A4)/Math.LN2,i=Math.round(12*e)+57,n=Math.floor(i/12);0>n&&(i+=-12*n);var o=scaleIndexToNote[i%12];return o+n.toString()},Tone.prototype.intervalToFrequencyRatio=function(t){return Math.pow(2,t/12)},Tone.prototype.midiToNote=function(t){var e=Math.floor(t/12)-1,i=t%12;return scaleIndexToNote[i]+e},Tone.prototype.noteToMidi=function(t){var e=t.split(/(\d+)/);if(3===e.length){var i=noteToScaleIndex[e[0].toLowerCase()],n=e[1];return i+12*(parseInt(n,10)+1)}return 0},Tone.prototype.midiToFrequency=function(t){return Tone.A4*Math.pow(2,(t-69)/12)},Tone}(Tone_core_Tone);var Tone_core_Param;Tone_core_Param=function(t){"use strict";return t.Param=function(){var e=this.optionsObject(arguments,["param","units","convert"],t.Param.defaults);this._param=this.input=e.param,this.units=e.units,this.convert=e.convert,this.overridden=!1,this.isUndef(e.value)||(this.value=e.value)},t.extend(t.Param),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.value=e}}),t.Param.prototype._fromUnits=function(e){if(!this.convert&&!this.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 this.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&&!this.isUndef(this.convert))return e;switch(this.units){case t.Type.Decibels:return this.gainToDb(e);default:return e}},t.Param.prototype._minOutput=1e-5,t.Param.prototype.setValueAtTime=function(t,e){return t=this._fromUnits(t),this._param.setValueAtTime(t,this.toSeconds(e)),this},t.Param.prototype.setRampPoint=function(t){t=this.defaultArg(t,this.now());var e=this._param.value;return this._param.setValueAtTime(e,t),this},t.Param.prototype.linearRampToValueAtTime=function(t,e){return t=this._fromUnits(t),this._param.linearRampToValueAtTime(t,this.toSeconds(e)),this},t.Param.prototype.exponentialRampToValueAtTime=function(t,e){return t=this._fromUnits(t),t=Math.max(this._minOutput,t),this._param.exponentialRampToValueAtTime(t,this.toSeconds(e)),this},t.Param.prototype.exponentialRampToValue=function(t,e){var i=this.now(),n=this.value;return this.setValueAtTime(Math.max(n,this._minOutput),i),this.exponentialRampToValueAtTime(t,i+this.toSeconds(e)),this},t.Param.prototype.linearRampToValue=function(t,e){var i=this.now();return this.setRampPoint(i),this.linearRampToValueAtTime(t,i+this.toSeconds(e)),this},t.Param.prototype.setTargetAtTime=function(t,e,i){return t=this._fromUnits(t),t=Math.max(this._minOutput,t),i=Math.max(this._minOutput,i),this._param.setTargetAtTime(t,this.toSeconds(e),i),this},t.Param.prototype.setValueCurveAtTime=function(t,e,i){for(var n=0;n<t.length;n++)t[n]=this._fromUnits(t[n]);return this._param.setValueCurveAtTime(t,this.toSeconds(e),this.toSeconds(i)),this},t.Param.prototype.cancelScheduledValues=function(t){return this._param.cancelScheduledValues(this.toSeconds(t)),this},t.Param.prototype.rampTo=function(e,i){return i=this.defaultArg(i,0),this.units===t.Type.Frequency||this.units===t.Type.BPM?this.exponentialRampToValue(e,i):this.linearRampToValue(e,i),this},t.Param.prototype.dispose=function(){return t.prototype.dispose.call(this),this._param=null,this},t.Param}(Tone_core_Tone);var Tone_core_Gain;Tone_core_Gain=function(t){"use strict";return t.Gain=function(){var e=this.optionsObject(arguments,["gain","units"],t.Ga