PHP Classes

File: p5/addons/p5.sound.min.js

Recommend this page to a friend!
  Classes of Ghali Ahmed   PHP Math Progressions   p5/addons/p5.sound.min.js   Download  
File: p5/addons/p5.sound.min.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: PHP Math Progressions
Calculate math progressions of several types
Author: By
Last change: Update of p5/addons/p5.sound.min.js
Date: 9 months ago
Size: 69,896 bytes
 

Contents

Class file image Download
/*! p5.sound.min.js v0.1.7 2015-01-30 */ var sndcore;sndcore=function(){"use strict";window.AudioContext=window.AudioContext||window.webkitAudioContext;var t=new window.AudioContext;p5.prototype.getAudioContext=function(){return t},"function"!=typeof t.createGain&&(window.audioContext.createGain=window.audioContext.createGainNode),"function"!=typeof t.createDelay&&(window.audioContext.createDelay=window.audioContext.createDelayNode),"function"!=typeof window.AudioBufferSourceNode.prototype.start&&(window.AudioBufferSourceNode.prototype.start=window.AudioBufferSourceNode.prototype.noteGrainOn),"function"!=typeof window.AudioBufferSourceNode.prototype.stop&&(window.AudioBufferSourceNode.prototype.stop=window.AudioBufferSourceNode.prototype.noteOff),"function"!=typeof window.OscillatorNode.prototype.start&&(window.OscillatorNode.prototype.start=window.OscillatorNode.prototype.noteOn),"function"!=typeof window.OscillatorNode.prototype.stop&&(window.OscillatorNode.prototype.stop=window.OscillatorNode.prototype.noteOff),window.AudioContext.prototype.hasOwnProperty("createScriptProcessor")||(window.AudioContext.prototype.createScriptProcessor=window.AudioContext.prototype.createJavaScriptNode),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"')},o=function(){return!!e.canPlayType&&e.canPlayType("audio/mpeg;")},n=function(){return!!e.canPlayType&&e.canPlayType('audio/wav; codecs="1"')},s=function(){return!!e.canPlayType&&(e.canPlayType("audio/x-m4a;")||e.canPlayType("audio/aac;"))},r=function(){return!!e.canPlayType&&e.canPlayType("audio/x-aiff;")};p5.prototype.isFileSupported=function(t){switch(t.toLowerCase()){case"mp3":return o();case"wav":return n();case"ogg":return i();case"mp4":return s();case"aiff":return r();default:return!1}};var a=navigator.userAgent.match(/(iPad|iPhone|iPod)/g)?!0:!1;a&&window.addEventListener("touchstart",function(){var e=t.createBuffer(1,1,22050),i=t.createBufferSource();i.buffer=e,i.connect(t.destination),i.start(0)},!1)}();var master;master=function(){"use strict";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=100,this.audiocontext=t,this.output.disconnect(this.audiocontext.destination),this.inputSources=[],this.input.connect(this.limiter),this.limiter.connect(this.output),this.meter=t.createGain(),this.output.connect(this.meter),this.output.connect(this.audiocontext.destination),this.soundArray=[],this.parts=[],this.extensions=[]},e=new t;return p5.soundOut=e,p5.soundOut._silentNode=e.audiocontext.createGain(),p5.soundOut._silentNode.gain.value=0,p5.soundOut._silentNode.connect(e.audiocontext.destination),e}(sndcore);var helpers;helpers=function(){"use strict";var t=master;p5.prototype.masterVolume=function(e){t.output.gain.value=e},p5.prototype.sampleRate=function(){return t.audiocontext.sampleRate},p5.prototype.getMasterVolume=function(){return t.output.gain.value},p5.prototype.freqToMidi=function(t){var e=Math.log(t/440)/Math.log(2),i=Math.round(12*e)+57;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 o=i.split(".").pop();if(["mp3","wav","ogg","m4a","aac"].indexOf(o)>-1){var n=p5.prototype.isFileSupported(o);if(n)i=i;else for(var s=i.split("."),r=s[s.length-1],a=0;a<t.extensions.length;a++){var u=t.extensions[a],n=p5.prototype.isFileSupported(u);if(n){r="",2===s.length&&(r+=s[0]);for(var a=1;a<=s.length-2;a++){var c=s[a];r+="."+c}i=r+=".",i=i+=u;break}}}else for(var a=0;a<t.extensions.length;a++){var u=t.extensions[a],n=p5.prototype.isFileSupported(u);if(n){i=i+"."+u;break}}}else if("object"==typeof e)for(var a=0;a<e.length;a++){var u=e[a].split(".").pop(),n=p5.prototype.isFileSupported(u);if(n){i=e[a];break}}return i},p5.prototype._mathChain=function(t,e,i,o,n){for(var s in t.mathOps)t.mathOps[s]instanceof n&&(t.mathOps[s].dispose(),i=s,i<t.mathOps.length-1&&(o=t.mathOps[s+1]));return t.mathOps[i-1].disconnect(),t.mathOps[i-1].connect(e),e.connect(o),t.mathOps[i]=e,t}}(master);var panner;panner=function(){"use strict";var t=master,e=t.audiocontext;p5.Panner=function(t,i,o){this.input=e.createGain(),t.connect(this.input),this.left=e.createGain(),this.right=e.createGain(),this.left.channelInterpretation="discrete",this.right.channelInterpretation="discrete",o>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 o=i||0,n=e.currentTime+o,s=(t+1)/2,r=Math.cos(s*Math.PI/2),a=Math.sin(s*Math.PI/2);this.left.gain.linearRampToValueAtTime(r,n),this.right.gain.linearRampToValueAtTime(a,n)},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 o=e.createPanner();return o.panningModel="HRTF",o.distanceModel="linear",o.setPosition(0,0,0),t.connect(o),o.connect(i),o.pan=function(t,e,i){o.setPosition(t,e,i)},o}}(master);var soundfile;soundfile=function(){"use strict";var t=master;p5.SoundFile=function(e,i,o){var n=p5.prototype._checkFileFormats(e);this.url=n,this.sources=[],this.source=null,this.buffer=null,this.playbackRate=1,this.gain=1,this.input=t.audiocontext.createGain(),this.output=t.audiocontext.createGain(),this.reversed=!1,this.startTime=0,this.endTime=null,this.playing=!1,this.paused=null,this.mode="sustain",this.startMillis=null,this.amplitude=new p5.Amplitude,this.output.connect(this.amplitude.input),this.panPosition=0,this.panner=new p5.Panner(this.output,t.input,2),this.url&&this.load(i),t.soundArray.push(this),this.whileLoading="function"==typeof o?o:function(){}},p5.prototype.registerPreloadMethod("loadSound"),p5.prototype.loadSound=function(t,e,i){window.location.origin.indexOf("file://")>-1&&alert("This sketch may require a server to load external files. Please see http://bit.ly/1qcInwS");var o=new p5.SoundFile(t,e,i);return o},p5.SoundFile.prototype.load=function(t){var e=this,i=new XMLHttpRequest;i.addEventListener("progress",function(t){e._updateProgress(t)},!1),i.open("GET",this.url,!0),i.responseType="arraybuffer";var o=this;i.onload=function(){var e=p5.prototype.getAudioContext();e.decodeAudioData(i.response,function(e){o.buffer=e,o.panner.inputChannels(e.numberOfChannels),t&&t(o)})},i.send()},p5.SoundFile.prototype._updateProgress=function(t){if(t.lengthComputable){var e=Math.log(t.loaded/t.total*9.9);this.whileLoading(e)}else console.log("size unknown")},p5.SoundFile.prototype.isLoaded=function(){return this.buffer?!0:!1},p5.SoundFile.prototype.play=function(e,i,o,n,s){var r=t.audiocontext.currentTime,e=e||0;if(0>e&&(e=0),!this.buffer)throw"not ready to play file, buffer has yet to load. Try preload()";if("restart"===this.mode&&this.buffer&&this.source){var r=t.audiocontext.currentTime;this.source.stop(e)}if(n){if(!(n>=0&&n<this.buffer.duration))throw"start time out of range";this.startTime=n}if(s){if(!(s>=0&&s<=this.buffer.duration))throw"end time out of range";this.endTime=s}else this.endTime=this.buffer.duration;if(this.source=t.audiocontext.createBufferSource(),this.source.buffer=this.buffer,this.source.loop=this.looping,this.source.loop===!0&&(this.source.loopStart=this.startTime,this.source.loopEnd=this.endTime),this.source.onended=function(){},this.source.gain)this.source.gain.value=o||1,this.source.connect(this.output);else{this.source.gain=t.audiocontext.createGain(),this.source.connect(this.source.gain);var a=o||1;this.source.gain.gain.setValueAtTime(a,t.audiocontext.currentTime),this.source.gain.connect(this.output)}this.source.playbackRate.cancelScheduledValues(r),i=i||Math.abs(this.playbackRate),this.source.playbackRate.setValueAtTime(i,r),this.paused&&(this.wasUnpaused=!0),this.paused&&this.wasUnpaused?this.source.start(e,this.pauseTime,this.endTime):(this.wasUnpaused=!1,this.pauseTime=0,this.source.start(e,this.startTime,this.endTime)),this.startSeconds=e+r,this.playing=!0,this.paused=!1,this.sources.push(this.source)},p5.SoundFile.prototype.playMode=function(e){var i=e.toLowerCase();if("restart"===i&&this.buffer&&this.source)for(var o=0;o<this.sources.length-1;o++){var n=t.audiocontext.currentTime;this.sources[o].stop(n)}if("restart"!==i&&"sustain"!==i)throw'Invalid play mode. Must be either "restart" or "sustain"';this.mode=i},p5.SoundFile.prototype.pause=function(e){{var i=t.audiocontext.currentTime,e=e||0,o=e+i;this.looping}this.isPlaying()&&this.buffer&&this.source&&(this.pauseTime=this.currentTime(),this.source.stop(o),this.paused=!0,this.wasUnpaused=!1,this.playing=!1)},p5.SoundFile.prototype.loop=function(t,e,i,o){this.looping=!0,this.play(t,e,i,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.source&&(this.source.loop=this.looping)},p5.SoundFile.prototype.isLooping=function(){return this.source&&this.looping===!0&&this.isPlaying()===!0?!0:!1},p5.SoundFile.prototype.isPlaying=function(){return null!==this.playing?this.playing:!1},p5.SoundFile.prototype.isPaused=function(){return this.paused?this.paused:!1},p5.SoundFile.prototype.stop=function(e){if("sustain"==this.mode)this.stopAll(),this.playing=!1,this.pauseTime=0,this.wasUnpaused=!1,this.paused=!1;else if(this.buffer&&this.source){var i=t.audiocontext.currentTime,o=e||0;this.source.stop(i+o),this.playing=!1,this.pauseTime=0,this.wasUnpaused=!1,this.paused=!1}},p5.SoundFile.prototype.stopAll=function(){if(this.buffer&&this.source)for(var e=0;e<this.sources.length;e++)if(null!==this.sources[e]){var i=t.audiocontext.currentTime;this.sources[e].stop(i)}},p5.SoundFile.prototype.setVolume=function(e,i,o){if("number"==typeof e){var i=i||0,o=o||0,n=t.audiocontext.currentTime,s=this.output.gain.value;this.output.gain.cancelScheduledValues(n+o),this.output.gain.linearRampToValueAtTime(s,n+o),this.output.gain.linearRampToValueAtTime(e,n+o+i)}else{if(!e)return this.output.gain;e.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(e){if(this.playbackRate!==e||!this.source||this.source.playbackRate.value!==e){this.playbackRate=e;var i=e;if(0===this.playbackRate&&this.playing&&this.pause(),this.playbackRate<0&&!this.reversed){{var o=this.currentTime();this.source.playbackRate.value}this.reverseBuffer(),i=Math.abs(e);var n=(o-this.duration())/i;this.pauseTime=n}else this.playbackRate>0&&this.reversed&&this.reverseBuffer();if(this.source){var s=t.audiocontext.currentTime;this.source.playbackRate.cancelScheduledValues(s),this.source.playbackRate.linearRampToValueAtTime(Math.abs(i),s)}}},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(){var e;if(this.isPlaying()){var i=t.audiocontext.currentTime-this.startSeconds+this.startTime+this.pauseTime;return e=i*this.playbackRate%(this.duration()*this.playbackRate),console.log("1"),e}return this.paused?this.pauseTime:this.startTime},p5.SoundFile.prototype.jump=function(e,i){if(0>e||e>this.buffer.duration)throw"jump time out of range";if(e>i||i>this.buffer.duration)throw"end time out of range";if(this.startTime=e||0,this.endTime=i?i:this.buffer.duration,this.isPlaying()){var o=t.audiocontext.currentTime;this.stop(o),this.play(e,this.endTime)}},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,o=~~(i/10)||1,n=e.numberOfChannels,s=new Float32Array(Math.round(t)),r=0;n>r;r++)for(var a=e.getChannelData(r),u=0;t>u;u++){for(var c=~~(u*i),p=~~(c+i),h=0,l=c;p>l;l+=o){var d=a[l];d>h?h=d:-d>h&&(h=d)}(0===r||h>s[u])&&(s[u]=h)}return s}},p5.SoundFile.prototype.reverseBuffer=function(){var t=this.getVolume();if(this.setVolume(0,.01,0),this.pause(),!this.buffer)throw"SoundFile is not done loading";Array.prototype.reverse.call(this.buffer.getChannelData(0)),Array.prototype.reverse.call(this.buffer.getChannelData(1)),this.reversed=!this.reversed,this.setVolume(t,.01,.0101),this.play()},p5.SoundFile.prototype._onEnded=function(e){e.onended=function(e){var i=t.audiocontext.currentTime;e.stop(i)}},p5.SoundFile.prototype.add=function(){},p5.SoundFile.prototype.dispose=function(){if(this.buffer&&this.source)for(var e=0;e<this.sources.length-1;e++)if(null!==this.sources[e]){var i=t.audiocontext.currentTime;this.sources[e].stop(i),this.sources[e]=null}this.output&&(this.output.disconnect(),this.output=null),this.panner&&(this.panner.disconnect(),this.panner=null)},p5.SoundFile.prototype.connect=function(e){this.panner.connect(e?e.hasOwnProperty("input")?e.input:e:t.input)},p5.SoundFile.prototype.disconnect=function(t){this.panner.disconnect(t)},p5.SoundFile.prototype.getLevel=function(t){return t&&(this.amplitude.smoothing=t),this.amplitude.getLevel()},p5.SoundFile.prototype.setPath=function(t,e){var i=p5.prototype._checkFileFormats(t);this.url=i,this.load(e)},p5.SoundFile.prototype.setBuffer=function(e){for(var i=t.audiocontext,o=i.createBuffer(2,e[0].length,i.sampleRate),n=0,s=0;s<e.length;s++){var r=o.getChannelData(s);r.set(e[s]),n++}this.buffer=o,this.panner.inputChannels(n)}}(sndcore,master);var amplitude;amplitude=function(){"use strict";var t=master;p5.Amplitude=function(e){this.bufferSize=2048,this.audiocontext=t.audiocontext,this.processor=this.audiocontext.createScriptProcessor(this.bufferSize),this.input=this.processor,this.output=this.audiocontext.createGain(),this.smoothing=e||0,this.volume=0,this.average=0,this.volMax=.001,this.normalize=!1,this.processor.onaudioprocess=this.volumeAudioProcess.bind(this),this.processor.connect(this.output),this.output.gain.value=0,this.output.connect(this.audiocontext.destination),t.meter.connect(this.processor)},p5.Amplitude.prototype.setInput=function(e,i){t.meter.disconnect(this.processor),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){this.output.connect(e?e.hasOwnProperty("input")?e.input:e:this.panner.connect(t.input))},p5.Amplitude.prototype.disconnect=function(){this.output.disconnect()},p5.Amplitude.prototype.volumeAudioProcess=function(t){for(var e,i=t.inputBuffer.getChannelData(0),o=i.length,n=0,s=0,r=0;o>r;r++)e=i[r],this.normalize?(n+=Math.max(Math.min(e/this.volMax,1),-1),s+=Math.max(Math.min(e/this.volMax,1),-1)*Math.max(Math.min(e/this.volMax,1),-1)):(n+=e,s+=e*e);var a=Math.sqrt(s/o);this.volume=Math.max(a,this.volume*this.smoothing),this.volMax=Math.max(this.volume,this.volMax),this.volNorm=Math.max(Math.min(this.volume/this.volMax,1),0)},p5.Amplitude.prototype.getLevel=function(){return this.normalize?this.volNorm:this.volume},p5.Amplitude.prototype.toggleNormalize=function(t){this.normalize="boolean"==typeof t?t:!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")}}(master);var fft;fft=function(){"use strict";var t=master;p5.FFT=function(e,i){var o=e||.8;0===e&&(o=e);var n=2*i||2048;this.analyser=t.audiocontext.createAnalyser(),t.output.connect(this.analyser),this.analyser.smoothingTimeConstant=o,this.analyser.fftSize=n,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]},p5.FFT.prototype.setInput=function(t,e){e&&(this.analyser.fftSize=2*e),t.output?t.output.connect(this.analyser):t.connect(this.analyser)},p5.FFT.prototype.waveform=function(t){t&&(this.analyser.fftSize=2*t),this.analyser.getByteTimeDomainData(this.timeDomain);var e=Array.apply([],this.timeDomain);return e.length===this.analyser.fftSize,e.constructor===Array,e},p5.FFT.prototype.analyze=function(t){t&&(this.analyser.fftSize=2*t),this.analyser.getByteFrequencyData(this.freqDomain);var e=Array.apply([],this.freqDomain);return e.length===this.analyser.fftSize,e.constructor===Array,e},p5.FFT.prototype.getEnergy=function(e,i){var o=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 n=i;i=e,e=n}for(var s=Math.round(e/o*this.freqDomain.length),r=Math.round(i/o*this.freqDomain.length),a=0,u=0,c=s;r>=c;c++)a+=this.freqDomain[c],u+=1;var p=a/u;return p}throw"invalid input for getEnergy()"}var h=Math.round(e/o*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.smooth=function(t){this.analyser.smoothingTimeConstant=t}}(master);var Tone_core_Tone;Tone_core_Tone=function(){"use strict";function t(t){return void 0===t}var e;if(t(window.AudioContext)&&(window.AudioContext=window.webkitAudioContext),t(window.OfflineAudioContext)&&(window.OfflineAudioContext=window.webkitOfflineAudioContext),t(AudioContext))throw new Error("Web Audio is not supported in this browser");e=new AudioContext,"function"!=typeof AudioContext.prototype.createGain&&(AudioContext.prototype.createGain=AudioContext.prototype.createGainNode),"function"!=typeof AudioContext.prototype.createDelay&&(AudioContext.prototype.createDelay=AudioContext.prototype.createDelayNode),"function"!=typeof AudioContext.prototype.createPeriodicWave&&(AudioContext.prototype.createPeriodicWave=AudioContext.prototype.createWaveTable),"function"!=typeof AudioBufferSourceNode.prototype.start&&(AudioBufferSourceNode.prototype.start=AudioBufferSourceNode.prototype.noteGrainOn),"function"!=typeof AudioBufferSourceNode.prototype.stop&&(AudioBufferSourceNode.prototype.stop=AudioBufferSourceNode.prototype.noteOff),"function"!=typeof OscillatorNode.prototype.start&&(OscillatorNode.prototype.start=OscillatorNode.prototype.noteOn),"function"!=typeof OscillatorNode.prototype.stop&&(OscillatorNode.prototype.stop=OscillatorNode.prototype.noteOff),"function"!=typeof OscillatorNode.prototype.setPeriodicWave&&(OscillatorNode.prototype.setPeriodicWave=OscillatorNode.prototype.setWaveTable),AudioNode.prototype._nativeConnect=AudioNode.prototype.connect,AudioNode.prototype.connect=function(e,i,o){if(e.input)Array.isArray(e.input)?(t(o)&&(o=0),this.connect(e.input[o])):this.connect(e.input,i,o);else try{e instanceof AudioNode?this._nativeConnect(e,i,o):this._nativeConnect(e,i)}catch(n){throw new Error("error connecting to node: "+e)}};var i=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))};i.context=e,i.prototype.context=i.context,i.prototype.bufferSize=2048,i.prototype.bufferTime=i.prototype.bufferSize/i.context.sampleRate,i.prototype.connect=function(t,e,i){Array.isArray(this.output)?(e=this.defaultArg(e,0),this.output[e].connect(t,0,i)):this.output.connect(t,e,i)},i.prototype.disconnect=function(t){Array.isArray(this.output)?(t=this.defaultArg(t,0),this.output[t].disconnect()):this.output.disconnect()},i.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}},i.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)}},i.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}},i.prototype.fan=function(){if(arguments.length>0)for(var t=1;t<arguments.length;t++)this.connect(arguments[t])},AudioNode.prototype.chain=i.prototype.chain,AudioNode.prototype.fan=i.prototype.fan,i.prototype.defaultArg=function(e,i){if("object"==typeof e&&"object"==typeof i){var o={};for(var n in e)o[n]=this.defaultArg(e[n],e[n]);for(var s in i)o[s]=this.defaultArg(e[s],i[s]);return o}return t(e)?i:e},i.prototype.optionsObject=function(t,e,i){var o={};if(1===t.length&&"object"==typeof t[0])o=t[0];else for(var n=0;n<e.length;n++)o[e[n]]=t[n];return this.isUndef(i)?o:this.defaultArg(o,i)},i.prototype.isUndef=t,i.prototype.equalPowerScale=function(t){var e=.5*Math.PI;return Math.sin(t*e)},i.prototype.logScale=function(t){return Math.max(this.normalize(this.gainToDb(t),-100,0),0)},i.prototype.expScale=function(t){return this.dbToGain(this.interpolate(t,-100,0))},i.prototype.dbToGain=function(t){return Math.pow(2,t/6)},i.prototype.gainToDb=function(t){return 20*(Math.log(t)/Math.LN10)},i.prototype.interpolate=function(t,e,i){return t*(i-e)+e},i.prototype.normalize=function(t,e,i){if(e>i){var o=i;i=e,e=o}else if(e==i)return 0;return(t-e)/(i-e)},i.prototype.dispose=function(){this.isUndef(this.input)||(this.input instanceof AudioNode&&this.input.disconnect(),this.input=null),this.isUndef(this.output)||(this.output instanceof AudioNode&&this.output.disconnect(),this.output=null)};var o=null;i.prototype.noGC=function(){this.output.connect(o)},AudioNode.prototype.noGC=function(){this.connect(o)},i.prototype.now=function(){return this.context.currentTime},i.prototype.samplesToSeconds=function(t){return t/this.context.sampleRate},i.prototype.toSamples=function(t){var e=this.toSeconds(t);return Math.round(e*this.context.sampleRate)},i.prototype.toSeconds=function(t,e){if(e=this.defaultArg(e,this.now()),"number"==typeof t)return t;if("string"==typeof t){var i=0;return"+"===t.charAt(0)&&(t=t.slice(1),i=e),parseFloat(t)+i}return e},i.prototype.frequencyToSeconds=function(t){return 1/parseFloat(t)},i.prototype.secondsToFrequency=function(t){return 1/t};var n=[];return i._initAudioContext=function(t){t(i.context),n.push(t)},i.setContext=function(t){i.prototype.context=t,i.context=t;for(var e=0;e<n.length;e++)n[e](t)},i.extend=function(e,o){function n(){}t(o)&&(o=i),n.prototype=o.prototype,e.prototype=new n,e.prototype.constructor=e},i.startMobile=function(){var t=i.context.createOscillator(),e=i.context.createGain();e.gain.value=0,t.connect(e),e.connect(i.context.destination);var o=i.context.currentTime;t.start(o),t.stop(o+1)},i._initAudioContext(function(t){i.prototype.bufferTime=i.prototype.bufferSize/t.sampleRate,o=t.createGain(),o.gain.value=0,o.connect(t.destination)}),console.log("%c * Tone.js r3 * ","background: #000; color: #fff"),i}();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,o){e instanceof t.Signal?e.setValue(0):e instanceof AudioParam&&(e.value=0),t.prototype.connect.call(this,e,i,o)},t.SignalBase.prototype.dispose=function(){t.prototype.dispose.call(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.setCurve(t):isFinite(t)||this.isUndef(t)?this._curve=new Float32Array(this.defaultArg(t,1024)):"function"==typeof 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 o=e/i*2-1,n=e/(i-1)*2-1;this._curve[e]=t(o,e,n)}this._shaper.curve=this._curve},t.WaveShaper.prototype.setCurve=function(t){if(this._isSafari()){var e=t[0];t.unshift(e)}this._curve=new Float32Array(t),this._shaper.curve=this._curve},t.WaveShaper.prototype.setOversample=function(t){this._shaper.oversample=t},t.WaveShaper.prototype._isSafari=function(){var t=navigator.userAgent.toLowerCase();return-1!==t.indexOf("safari")&&-1===t.indexOf("chrome")},t.WaveShaper.prototype.dispose=function(){t.prototype.dispose.call(this),this._shaper.disconnect(),this._shaper=null,this._curve=null},t.WaveShaper}(Tone_core_Tone);var Tone_signal_Signal;Tone_signal_Signal=function(t){"use strict";return t.Signal=function(e){this._scalar=this.context.createGain(),this.input=this.output=this.context.createGain(),this._syncRatio=1,this.value=this.defaultArg(e,0),t.Signal._constant.chain(this._scalar,this.output)},t.extend(t.Signal,t.SignalBase),t.Signal.prototype.getValue=function(){return this._scalar.gain.value},t.Signal.prototype.setValue=function(t){0===this._syncRatio?t=0:t*=this._syncRatio,this._scalar.gain.value=t},t.Signal.prototype.setValueAtTime=function(t,e){t*=this._syncRatio,this._scalar.gain.setValueAtTime(t,this.toSeconds(e))},t.Signal.prototype.setCurrentValueNow=function(t){t=this.defaultArg(t,this.now());var e=this.getValue();return this.cancelScheduledValues(t),this._scalar.gain.setValueAtTime(e,t),e},t.Signal.prototype.linearRampToValueAtTime=function(t,e){t*=this._syncRatio,this._scalar.gain.linearRampToValueAtTime(t,this.toSeconds(e))},t.Signal.prototype.exponentialRampToValueAtTime=function(t,e){t*=this._syncRatio;try{this._scalar.gain.exponentialRampToValueAtTime(t,this.toSeconds(e))}catch(i){this._scalar.gain.linearRampToValueAtTime(t,this.toSeconds(e))}},t.Signal.prototype.exponentialRampToValueNow=function(t,e){var i=this.now();this.setCurrentValueNow(i),"+"===e.toString().charAt(0)&&(e=e.substr(1)),this.exponentialRampToValueAtTime(t,i+this.toSeconds(e))},t.Signal.prototype.linearRampToValueNow=function(t,e){var i=this.now();this.setCurrentValueNow(i),t*=this._syncRatio,"+"===e.toString().charAt(0)&&(e=e.substr(1)),this._scalar.gain.linearRampToValueAtTime(t,i+this.toSeconds(e))},t.Signal.prototype.setTargetAtTime=function(t,e,i){t*=this._syncRatio,this._scalar.gain.setTargetAtTime(t,this.toSeconds(e),i)},t.Signal.prototype.setValueCurveAtTime=function(t,e,i){for(var o=0;o<t.length;o++)t[o]*=this._syncRatio;this._scalar.gain.setValueCurveAtTime(t,this.toSeconds(e),this.toSeconds(i))},t.Signal.prototype.cancelScheduledValues=function(t){this._scalar.gain.cancelScheduledValues(this.toSeconds(t))},t.Signal.prototype.sync=function(t,e){this._syncRatio=e?e:0!==t.getValue()?this.getValue()/t.getValue():0,this._scalar.disconnect(),this._scalar=this.context.createGain(),this.connectSeries(t,this._scalar,this.output),this._scalar.gain.value=this._syncRatio},t.Signal.prototype.unsync=function(){var e=this.getValue();this._scalar.disconnect(),this._scalar=this.context.createGain(),this._scalar.gain.value=e/this._syncRatio,this._syncRatio=1,t.Signal._constant.chain(this._scalar,this.output)},t.Signal.prototype.dispose=function(){t.prototype.dispose.call(this),this._scalar.disconnect(),this._scalar=null},Object.defineProperty(t.Signal.prototype,"value",{get:function(){return this.getValue()},set:function(t){this.setValue(t)}}),t.Signal._generator=null,t.Signal._constant=null,t._initAudioContext(function(e){t.Signal._generator=e.createOscillator(),t.Signal._constant=new t.WaveShaper([1,1]),t.Signal._generator.connect(t.Signal._constant),t.Signal._generator.start(0),t.Signal._generator.noGC()}),t.Signal}(Tone_core_Tone);var Tone_signal_Add;Tone_signal_Add=function(t){"use strict";return t.Add=function(e){t.call(this,2,0),this._sum=this.input[0]=this.input[1]=this.output=this.context.createGain(),this._value=null,isFinite(e)&&(this._value=new t.Signal(e),this._value.connect(this._sum))},t.extend(t.Add,t.SignalBase),t.Add.prototype.setValue=function(t){if(null===this._value)throw new Error("cannot switch from signal to number");this._value.setValue(t)},t.Add.prototype.dispose=function(){t.prototype.dispose.call(this),this._sum=null,this._value&&(this._value.dispose(),this._value=null)},t.Add}(Tone_core_Tone);var Tone_signal_Multiply;Tone_signal_Multiply=function(t){"use strict";return t.Multiply=function(e){t.call(this,2,0),this._mult=this.input[0]=this.output=this.context.createGain(),this._factor=this.input[1]=this.output.gain,this._factor.value=this.defaultArg(e,0)},t.extend(t.Multiply,t.SignalBase),t.Multiply.prototype.setValue=function(t){this._factor.value=t},t.Multiply.prototype.dispose=function(){t.prototype.dispose.call(this),this._mult=null,this._factor=null},t.Multiply}(Tone_core_Tone);var Tone_signal_Scale;Tone_signal_Scale=function(t){"use strict";return t.Scale=function(e,i){this._outputMin=this.defaultArg(e,0),this._outputMax=this.defaultArg(i,1),this._scale=this.input=new t.Multiply(1),this._add=this.output=new t.Add(0),this._scale.connect(this._add),this._setRange()},t.extend(t.Scale,t.SignalBase),t.Scale.prototype.setMin=function(t){this._outputMin=t,this._setRange()},t.Scale.prototype.setMax=function(t){this._outputMax=t,this._setRange()},t.Scale.prototype._setRange=function(){this._add.setValue(this._outputMin),this._scale.setValue(this._outputMax-this._outputMin)},t.Scale.prototype.dispose=function(){t.prototype.dispose.call(this),this._add.dispose(),this._add=null,this._scale.dispose(),this._scale=null},t.Scale}(Tone_core_Tone,Tone_signal_Add,Tone_signal_Multiply);var signal;signal=function(){"use strict";var t=Tone_signal_Signal,e=Tone_signal_Add,i=Tone_signal_Multiply,o=Tone_signal_Scale,n=Tone_core_Tone,s=master;n.setContext(s.audiocontext),p5.Signal=function(e){var i=new t(e);return i},t.prototype.fade=t.prototype.linearRampToValueAtTime,i.prototype.fade=t.prototype.fade,e.prototype.fade=t.prototype.fade,o.prototype.fade=t.prototype.fade,t.prototype.setInput=function(t){t.connect(this)},i.prototype.setInput=t.prototype.setInput,e.prototype.setInput=t.prototype.setInput,o.prototype.setInput=t.prototype.setInput,t.prototype.add=function(t){var i=new e(t);return this.connect(i),i},i.prototype.add=t.prototype.add,e.prototype.add=t.prototype.add,o.prototype.add=t.prototype.add,t.prototype.mult=function(t){var e=new i(t);return this.connect(e),e},i.prototype.mult=t.prototype.mult,e.prototype.mult=t.prototype.mult,o.prototype.mult=t.prototype.mult,t.prototype.scale=function(t,e,i,n){var s,r; 4===arguments.length?(s=p5.prototype.map(i,t,e,0,1)-.5,r=p5.prototype.map(n,t,e,0,1)-.5):(s=arguments[0],r=arguments[1]);var a=new o(s,r);return this.connect(a),a},i.prototype.scale=t.prototype.scale,e.prototype.scale=t.prototype.scale,o.prototype.scale=t.prototype.scale}(Tone_signal_Signal,Tone_signal_Add,Tone_signal_Multiply,Tone_signal_Scale,Tone_core_Tone,master);var oscillator;oscillator=function(){"use strict";var t=master,e=Tone_signal_Add,i=Tone_signal_Multiply,o=Tone_signal_Scale;p5.Oscillator=function(e,i){if("string"==typeof e){var o=i;i=e,e=o}if("number"==typeof i){var o=i;i=e,e=o}this.started=!1,this.oscillator=t.audiocontext.createOscillator(),this.f=e||440,this.oscillator.frequency.setValueAtTime(this.f,t.audiocontext.currentTime),this.oscillator.type=i||"sine";this.oscillator;this.input=t.audiocontext.createGain(),this.output=t.audiocontext.createGain(),this._freqMods=[],this.output.gain.value=.5,this.output.gain.setValueAtTime(.5,t.audiocontext.currentTime),this.oscillator.connect(this.output),this.panPosition=0,this.connection=t.input,this.panner=new p5.Panner(this.output,this.connection,1),this.mathOps=[this.output],t.soundArray.push(this)},p5.Oscillator.prototype.start=function(e,i){if(this.started){var o=t.audiocontext.currentTime;this.stop(o)}if(!this.started){var n=i||this.f,s=this.oscillator.type;this.oscillator=t.audiocontext.createOscillator(),this.oscillator.frequency.exponentialRampToValueAtTime(Math.abs(n),t.audiocontext.currentTime),this.oscillator.type=s,this.oscillator.connect(this.output),e=e||0,this.oscillator.start(e+t.audiocontext.currentTime),this.freqNode=this.oscillator.frequency;for(var r in this._freqMods)"undefined"!=typeof this._freqMods[r].connect&&this._freqMods[r].connect(this.oscillator.frequency);this.started=!0}},p5.Oscillator.prototype.stop=function(e){if(this.started){var i=e||0,o=t.audiocontext.currentTime;this.oscillator.stop(i+o),this.started=!1}},p5.Oscillator.prototype.amp=function(e,i,o){var n=this;if("number"==typeof e){var i=i||0,o=o||0,s=t.audiocontext.currentTime,r=this.output.gain.value;this.output.gain.cancelScheduledValues(s),this.output.gain.linearRampToValueAtTime(r,s+o),this.output.gain.linearRampToValueAtTime(e,s+o+i)}else{if(!e)return this.output.gain;console.log(e),e.connect(n.output.gain)}},p5.Oscillator.prototype.fade=p5.Oscillator.prototype.amp,p5.Oscillator.prototype.getAmp=function(){return this.output.gain.value},p5.Oscillator.prototype.freq=function(e,i,o){if("number"!=typeof e||isNaN(e)){if(!e)return this.oscillator.frequency;e.output&&(e=e.output),e.connect(this.oscillator.frequency),this._freqMods.push(e)}else{this.f=e;var n=t.audiocontext.currentTime,i=i||0,o=o||0,s=this.oscillator.frequency.value;this.oscillator.frequency.cancelScheduledValues(n),this.oscillator.frequency.setValueAtTime(s,n+o),e>0?this.oscillator.frequency.exponentialRampToValueAtTime(e,o+i+n):this.oscillator.frequency.linearRampToValueAtTime(e,o+i+n)}},p5.Oscillator.prototype.getFreq=function(){return this.oscillator.frequency.value},p5.Oscillator.prototype.setType=function(t){this.oscillator.type=t},p5.Oscillator.prototype.getType=function(){return this.oscillator.type},p5.Oscillator.prototype.connect=function(e){e?e.hasOwnProperty("input")?(this.panner.connect(e.input),this.connection=e.input):(this.panner.connect(e),this.connection=e):this.panner.connect(t.input)},p5.Oscillator.prototype.disconnect=function(){this.output.disconnect(),this.panner.disconnect(),this.output.connect(this.panner),this.oscMods=[]},p5.Oscillator.prototype.pan=function(t,e){this.panPosition=t,this.panner.pan(t,e)},p5.Oscillator.prototype.getPan=function(){return this.panPosition},p5.Oscillator.prototype.dispose=function(){if(this.oscillator){var e=t.audiocontext.currentTime;this.stop(e),this.disconnect(),this.oscillator.disconnect(),this.panner=null,this.oscillator=null}this.osc2&&this.osc2.dispose()},p5.Oscillator.prototype.phase=function(e){this.dNode||(this.dNode=t.audiocontext.createDelay(),this.output.disconnect(),this.output.connect(this.dNode),this.dNode.connect(this.panner));var i=t.audiocontext.currentTime;this.dNode.delayTime.linearRampToValueAtTime(p5.prototype.map(e,0,1,0,1/this.oscillator.frequency.value),i)};var n=function(t,e,i,o,n){var s=t.oscillator;for(var r in t.mathOps)t.mathOps[r]instanceof n&&(s.disconnect(),t.mathOps[r].dispose(),i=r,i<t.mathOps.length-2&&(o=t.mathOps[r+1]));return i==t.mathOps.length-1&&t.mathOps.push(o),r>0&&(s=t.mathOps[r-1]),s.disconnect(),s.connect(e),e.connect(o),t.mathOps[i]=e,t};p5.Oscillator.prototype.add=function(t){var i=new e(t),o=this.mathOps.length-1,s=this.output;return n(this,i,o,s,e)},p5.Oscillator.prototype.mult=function(t){var e=new i(t),o=this.mathOps.length-1,s=this.output;return n(this,e,o,s,i)},p5.Oscillator.prototype.scale=function(t,e,i,s){var r,a;4===arguments.length?(r=p5.prototype.map(i,t,e,0,1)-.5,a=p5.prototype.map(s,t,e,0,1)-.5):(r=arguments[0],a=arguments[1]);var u=new o(r,a),c=this.mathOps.length-1,p=this.output;return n(this,u,c,p,o)},p5.SinOsc=function(t){p5.Oscillator.call(this,t,"sine")},p5.SinOsc.prototype=Object.create(p5.Oscillator.prototype),p5.TriOsc=function(t){p5.Oscillator.call(this,t,"triangle")},p5.TriOsc.prototype=Object.create(p5.Oscillator.prototype),p5.SawOsc=function(t){p5.Oscillator.call(this,t,"sawtooth")},p5.SawOsc.prototype=Object.create(p5.Oscillator.prototype),p5.SqrOsc=function(t){p5.Oscillator.call(this,t,"square")},p5.SqrOsc.prototype=Object.create(p5.Oscillator.prototype)}(master,Tone_signal_Signal,Tone_signal_Add,Tone_signal_Multiply,Tone_signal_Scale);var env;env=function(){"use strict";var t=master,e=Tone_signal_Add,i=Tone_signal_Multiply,o=Tone_signal_Scale,n=Tone_core_Tone;n.setContext(t.audiocontext);var s=null;p5.Env=function(e,i,o,n,s,r,a,u){this.aTime=e,this.aLevel=i,this.dTime=o||0,this.dLevel=n||0,this.sTime=s||0,this.sLevel=r||0,this.rTime=a||0,this.rLevel=u||0,this.output=t.audiocontext.createGain(),this.control=new p5.Signal,this.control.connect(this.output),this.timeoutID=null,this.connection=null,this.mathOps=[this.control],t.soundArray.push(this)},p5.Env.prototype.set=function(t,e,i,o,n,s,r,a){this.aTime=t,this.aLevel=e,this.dTime=i||0,this.dLevel=o||0,this.sTime=n||0,this.sLevel=s||0,this.rTime=r||0,this.rLevel=a||0},p5.Env.prototype.setInput=function(t){this.connect(t)},p5.Env.prototype.ctrl=function(t){this.connect(t)},p5.Env.prototype.play=function(e,i){var o=t.audiocontext.currentTime,n=i||0,s=o+n+1e-4;"number"==typeof this.timeoutID&&window.clearTimeout(this.timeoutID),e&&this.connection!==e&&this.connect(e),this.control.cancelScheduledValues(s-1e-4),this.control.linearRampToValueAtTime(0,s-5e-5),this.control.linearRampToValueAtTime(this.aLevel,s+this.aTime),this.control.linearRampToValueAtTime(this.dLevel,s+this.aTime+this.dTime),this.control.linearRampToValueAtTime(this.sLevel,s+this.aTime+this.dTime+this.sTime),this.control.linearRampToValueAtTime(this.rLevel,s+this.aTime+this.dTime+this.sTime+this.rTime);s+this.aTime+this.dTime+this.sTime+this.rTime},p5.Env.prototype.triggerAttack=function(e,i){var o=t.audiocontext.currentTime,n=i||0,s=o+n+1e-4;this.lastAttack=s,"number"==typeof this.timeoutID&&window.clearTimeout(this.timeoutID);var r=this.control.getValue();this.control.cancelScheduledValues(s-1e-4),this.control.linearRampToValueAtTime(r,s-5e-5),e&&this.connection!==e&&this.connect(e),this.control.linearRampToValueAtTime(this.aLevel,s+this.aTime),this.control.linearRampToValueAtTime(this.aLevel,s+this.aTime),this.control.linearRampToValueAtTime(this.dLevel,s+this.aTime+this.dTime),this.control.linearRampToValueAtTime(this.sLevel,s+this.aTime+this.dTime+this.sTime)},p5.Env.prototype.triggerRelease=function(e,i){var o,n=t.audiocontext.currentTime,r=i||0,a=n+r+1e-5;if(e&&this.connection!==e&&this.connect(e),this.control.cancelScheduledValues(a-1e-5),n-this.lastAttack<this.aTime){var u=this.aTime-(a-this.lastAttack);this.control.linearRampToValueAtTime(this.aLevel,a+u),this.control.linearRampToValueAtTime(this.dLevel,a+u+this.dTime),this.control.linearRampToValueAtTime(this.sLevel,a+u+this.dTime+this.sTime),this.control.linearRampToValueAtTime(this.rLevel,a+u+this.dTime+this.sTime+this.rTime),o=a+this.dTime+this.sTime+this.rTime}else if(n-this.lastAttack<this.aTime+this.dTime){var c=this.aTime+this.dTime-(n-this.lastAttack);this.control.linearRampToValueAtTime(this.dLevel,a+c),this.control.linearRampToValueAtTime(this.sLevel,a+c+.01),this.control.linearRampToValueAtTime(this.rLevel,a+c+.01+this.rTime),o=a+this.sTime+this.rTime}else if(n-this.lastAttack<this.aTime+this.dTime+this.sTime){var p=this.aTime+this.dTime+this.sTime-(n-this.lastAttack);this.control.linearRampToValueAtTime(this.sLevel,a+p),this.control.linearRampToValueAtTime(this.rLevel,a+p+this.rTime),o=a+this.rTime}else this.control.linearRampToValueAtTime(this.sLevel,a),this.control.linearRampToValueAtTime(this.rLevel,a+this.rTime),o=a+this.dTime+this.sTime+this.rTime;var h=a+this.aTime+this.dTime+this.sTime+this.rTime;this.connection&&this.connection.hasOwnProperty("oscillator")?(s=this.connection.oscillator,s.stop(h+.01)):this.connect&&this.connection.hasOwnProperty("source")&&(s=this.connection.source,s.stop(h+.01))},p5.Env.prototype.connect=function(e){this.disconnect(),this.connection=e,(e instanceof p5.Oscillator||e instanceof p5.SoundFile||e instanceof p5.AudioIn||e instanceof p5.Reverb||e instanceof p5.Noise||e instanceof p5.Filter||e instanceof p5.Delay)&&(e=e.output.gain),e instanceof AudioParam&&e.setValueAtTime(0,t.audiocontext.currentTime),e instanceof p5.Signal&&e.setValue(0),this.output.connect(e)},p5.Env.prototype.disconnect=function(){this.output.disconnect()},p5.Env.prototype.add=function(t){var i=new e(t),o=this.mathOps.length,n=this.output;return p5.prototype._mathChain(this,i,o,n,e)},p5.Env.prototype.mult=function(t){var e=new i(t),o=this.mathOps.length,n=this.output;return p5.prototype._mathChain(this,e,o,n,i)},p5.Env.prototype.scale=function(t,e,i,n){var s=new o(t,e,i,n),r=this.mathOps.length,a=this.output;return p5.prototype._mathChain(this,s,r,a,o)},p5.Env.prototype.dispose=function(){t.audiocontext.currentTime;this.disconnect(),this.control.dispose(),this.control=null;for(var e=1;e<this.mathOps.length;e++)mathOps[e].dispose()}}(master,Tone_signal_Add,Tone_signal_Multiply,Tone_signal_Scale,Tone_core_Tone);var pulse;pulse=function(){"use strict";function t(){for(var t=e.audiocontext,i=t.createBuffer(1,2048,t.sampleRate),o=i.getChannelData(0),n=0;2048>n;n++)o[n]=1;var s=t.createBufferSource();return s.buffer=i,s.loop=!0,s}var e=master;p5.Pulse=function(i,o){p5.Oscillator.call(this,i,"sawtooth"),this.w=o||0,this.osc2=new p5.SawOsc(i),this.dNode=e.audiocontext.createDelay(),this.dcOffset=t(),this.dcGain=e.audiocontext.createGain(),this.dcOffset.connect(this.dcGain),this.dcGain.connect(this.output),this.f=i||440;var n=this.w/this.oscillator.frequency.value;this.dNode.delayTime.value=n,this.dcGain.gain.value=1.7*(.5-this.w),this.osc2.disconnect(),this.osc2.output.gain.minValue=-10,this.osc2.output.gain.maxValue=10,this.osc2.panner.disconnect(),this.osc2.amp(-1),this.osc2.output.connect(this.dNode),this.dNode.connect(this.output),this.output.gain.value=1,this.output.connect(this.panner)},p5.Pulse.prototype=Object.create(p5.Oscillator.prototype),p5.Pulse.prototype.width=function(t){if("number"==typeof t){if(1>=t&&t>=0){this.w=t;var e=this.w/this.oscillator.frequency.value;this.dNode.delayTime.value=e}this.dcGain.gain.value=1.7*(.5-this.w)}else{t.connect(this.dNode.delayTime);var i=new p5.SignalAdd(-.5);i.setInput(t),i=i.mult(-1),i=i.mult(1.7),i.connect(this.dcGain.gain)}},p5.Pulse.prototype.start=function(i,o){var n=e.audiocontext.currentTime,s=o||0;if(!this.started){var r=i||this.f,a=this.oscillator.type;this.oscillator=e.audiocontext.createOscillator(),this.oscillator.frequency.setValueAtTime(r,n),this.oscillator.type=a,this.oscillator.connect(this.output),this.oscillator.start(s+n),this.osc2.oscillator=e.audiocontext.createOscillator(),this.osc2.oscillator.frequency.setValueAtTime(r,s+n),this.osc2.oscillator.type=a,this.osc2.oscillator.connect(this.osc2.output),this.osc2.start(s+n),this.freqNode=[this.oscillator.frequency,this.osc2.oscillator.frequency],this.dcOffset=t(),this.dcOffset.connect(this.dcGain),this.dcOffset.start(s+n),void 0!==this.mods&&void 0!==this.mods.frequency&&(this.mods.frequency.connect(this.freqNode[0]),this.mods.frequency.connect(this.freqNode[1])),this.started=!0,this.osc2.started=!0}},p5.Pulse.prototype.stop=function(t){if(this.started){var i=t||0,o=e.audiocontext.currentTime;this.oscillator.stop(i+o),this.osc2.oscillator.stop(i+o),this.dcOffset.stop(i+o),this.started=!1,this.osc2.started=!1}},p5.Pulse.prototype.freq=function(t,i,o){if("number"==typeof t){this.f=t;var n=e.audiocontext.currentTime,i=i||0,o=o||0,s=this.oscillator.frequency.value;this.oscillator.frequency.cancelScheduledValues(n),this.oscillator.frequency.setValueAtTime(s,n+o),this.oscillator.frequency.exponentialRampToValueAtTime(t,o+i+n),this.osc2.oscillator.frequency.cancelScheduledValues(n),this.osc2.oscillator.frequency.setValueAtTime(s,n+o),this.osc2.oscillator.frequency.exponentialRampToValueAtTime(t,o+i+n),this.freqMod&&(this.freqMod.output.disconnect(),this.freqMod=null)}else t.output&&(t.output.disconnect(),t.output.connect(this.oscillator.frequency),t.output.connect(this.osc2.oscillator.frequency),this.freqMod=t)}}(master,oscillator);var noise;noise=function(){"use strict";var t=master;p5.Noise=function(){p5.Oscillator.call(this),delete this.f,delete this.freq,delete this.oscillator,this.buffer=e},p5.Noise.prototype=Object.create(p5.Oscillator.prototype);var e=function(){for(var e=2*t.audiocontext.sampleRate,i=t.audiocontext.createBuffer(1,e,t.audiocontext.sampleRate),o=i.getChannelData(0),n=0;e>n;n++)o[n]=2*Math.random()-1;return i.type="white",i}(),i=function(){var e,i,o,n,s,r,a,u=2*t.audiocontext.sampleRate,c=t.audiocontext.createBuffer(1,u,t.audiocontext.sampleRate),p=c.getChannelData(0);e=i=o=n=s=r=a=0;for(var h=0;u>h;h++){var l=2*Math.random()-1;e=.99886*e+.0555179*l,i=.99332*i+.0750759*l,o=.969*o+.153852*l,n=.8665*n+.3104856*l,s=.55*s+.5329522*l,r=-.7616*r-.016898*l,p[h]=e+i+o+n+s+r+a+.5362*l,p[h]*=.11,a=.115926*l}return c.type="pink",c}(),o=function(){for(var e=2*t.audiocontext.sampleRate,i=t.audiocontext.createBuffer(1,e,t.audiocontext.sampleRate),o=i.getChannelData(0),n=0,s=0;e>s;s++){var r=2*Math.random()-1;o[s]=(n+.02*r)/1.02,n=o[s],o[s]*=3.5}return i.type="brown",i}();p5.Noise.prototype.setType=function(n){switch(n){case"white":this.buffer=e;break;case"pink":this.buffer=i;break;case"brown":this.buffer=o;break;default:this.buffer=e}if(this.started){var s=t.audiocontext.currentTime;this.stop(s),this.start(s+.01)}},p5.Noise.prototype.getType=function(){return this.buffer.type},p5.Noise.prototype.start=function(){this.started&&this.stop(),this.noise=t.audiocontext.createBufferSource(),this.noise.buffer=this.buffer,this.noise.loop=!0,this.noise.connect(this.output);var e=t.audiocontext.currentTime;this.noise.start(e),this.started=!0},p5.Noise.prototype.stop=function(){var e=t.audiocontext.currentTime;this.noise&&(this.noise.stop(e),this.started=!1)},p5.Noise.prototype.dispose=function(){var e=t.audiocontext.currentTime;this.noise&&(this.noise.disconnect(),this.stop(e)),this.output&&this.output.disconnect(),this.panner&&this.panner.disconnect(),this.output=null,this.panner=null,this.buffer=null,this.noise=null}}(master);var audioin;audioin=function(){"use strict";var t=master;p5.AudioIn=function(){this.input=t.audiocontext.createGain(),this.output=t.audiocontext.createGain(),this.stream=null,this.mediaStream=null,this.currentSource=0,this.enabled=!1,this.amplitude=new p5.Amplitude,this.output.connect(this.amplitude.input),"undefined"==typeof window.MediaStreamTrack?window.alert("This browser does not support MediaStreamTrack"):"undefined"!=typeof window.MediaStreamTrack.getSources&&window.MediaStreamTrack.getSources(this._gotSources),t.soundArray.push(this)},p5.AudioIn.prototype.start=function(){var e=this;if(t.inputSources[e.currentSource]){var i=t.inputSources[e.currentSource].id,o={audio:{optional:[{sourceId:i}]}};navigator.getUserMedia(o,this._onStream=function(i){e.stream=i,e.enabled=!0,e.mediaStream=t.audiocontext.createMediaStreamSource(i),e.mediaStream.connect(e.output),e.amplitude.setInput(e.output)},this._onStreamError=function(t){console.error(t)})}else window.navigator.getUserMedia({audio:!0},this._onStream=function(i){e.stream=i,e.enabled=!0,e.mediaStream=t.audiocontext.createMediaStreamSource(i),e.mediaStream.connect(e.output),e.amplitude.setInput(e.output)},this._onStreamError=function(t){console.error(t)})},p5.AudioIn.prototype.stop=function(){this.stream&&this.stream.stop()},p5.AudioIn.prototype.connect=function(e){this.output.connect(e?e.hasOwnProperty("input")?e.input:e.hasOwnProperty("analyser")?e.analyser:e:t.input)},p5.AudioIn.prototype.disconnect=function(t){this.output.disconnect(t),this.output.connect(this.amplitude.input)},p5.AudioIn.prototype.getLevel=function(t){return t&&(this.amplitude.smoothing=t),this.amplitude.getLevel()},p5.AudioIn.prototype._gotSources=function(e){for(var i=0;i!==e.length;i++){var o=e[i];"audio"===o.kind&&t.inputSources.push(o)}},p5.AudioIn.prototype.amp=function(e,i){if(i){var o=i||0,n=this.output.gain.value;this.output.gain.cancelScheduledValues(t.audiocontext.currentTime),this.output.gain.setValueAtTime(n,t.audiocontext.currentTime),this.output.gain.linearRampToValueAtTime(e,o+t.audiocontext.currentTime)}else this.output.gain.cancelScheduledValues(t.audiocontext.currentTime),this.output.gain.setValueAtTime(e,t.audiocontext.currentTime)},p5.AudioIn.prototype.listSources=function(){return console.log("input sources: "),console.log(t.inputSources),t.inputSources.length>0?t.inputSources:"This browser does not support MediaStreamTrack.getSources()"},p5.AudioIn.prototype.setSource=function(e){var i=this;t.inputSources.length>0&&e<t.inputSources.length?(i.currentSource=e,console.log("set source to "+t.inputSources[i.currentSource].id)):console.log("unable to set input source")},p5.AudioIn.prototype.dispose=function(){this.stop(),this.output&&this.output.disconnect(),this.amplitude&&this.amplitude.disconnect(),this.amplitude=null,this.output=null}}(master);var filter;filter=function(){"use strict";var t=master;p5.Filter=function(e){this.ac=t.audiocontext,this.input=this.ac.createGain(),this.output=this.ac.createGain(),this.biquad=this.ac.createBiquadFilter(),this.input.connect(this.biquad),this.biquad.connect(this.output),this.connect(),e&&this.setType(e)},p5.Filter.prototype.process=function(t,e,i){t.connect(this.input),this.set(e,i)},p5.Filter.prototype.set=function(t,e,i){t&&this.freq(t,i),e&&this.res(e,i)},p5.Filter.prototype.freq=function(t,e){var i=this,o=e||0;return 0>=t&&(t=1),"number"==typeof t?(i.biquad.frequency.value=t,i.biquad.frequency.cancelScheduledValues(this.ac.currentTime+.01+o),i.biquad.frequency.exponentialRampToValueAtTime(t,this.ac.currentTime+.02+o)):t&&t.connect(this.biquad.frequency),i.biquad.frequency.value},p5.Filter.prototype.res=function(t,e){var i=this,o=e||0;return"number"==typeof t?(i.biquad.Q.value=t,i.biquad.Q.cancelScheduledValues(i.ac.currentTime+.01+o),i.biquad.Q.linearRampToValueAtTime(t,i.ac.currentTime+.02+o)):t&&freq.connect(this.biquad.Q),i.biquad.Q.value},p5.Filter.prototype.setType=function(t){this.biquad.type=t},p5.Filter.prototype.amp=function(e,i,o){var i=i||0,o=o||0,n=t.audiocontext.currentTime,s=this.output.gain.value;this.output.gain.cancelScheduledValues(n),this.output.gain.linearRampToValueAtTime(s,n+o+.001),this.output.gain.linearRampToValueAtTime(e,n+o+i+.001)},p5.Filter.prototype.connect=function(t){var e=t||p5.soundOut.input;this.output.connect(e)},p5.Filter.prototype.disconnect=function(){this.output.disconnect()},p5.LowPass=function(){p5.Filter.call(this,"lowpass")},p5.LowPass.prototype=Object.create(p5.Filter.prototype),p5.HighPass=function(){p5.Filter.call(this,"highpass")},p5.HighPass.prototype=Object.create(p5.Filter.prototype),p5.BandPass=function(){p5.Filter.call(this,"bandpass")},p5.BandPass.prototype=Object.create(p5.Filter.prototype)}(master);var delay;delay=function(){"use strict";var t=master;p5.Delay=function(){this.ac=t.audiocontext,this.input=this.ac.createGain(),this.output=this.ac.createGain(),this._split=this.ac.createChannelSplitter(2),this._merge=this.ac.createChannelMerger(2),this._leftGain=this.ac.createGain(),this._rightGain=this.ac.createGain(),this.leftDelay=this.ac.createDelay(),this.rightDelay=this.ac.createDelay(),this._leftFilter=new p5.Filter,this._rightFilter=new p5.Filter,this._leftFilter.disconnect(),this._rightFilter.disconnect(),this.lowPass=this._leftFilter,this._leftFilter.biquad.frequency.setValueAtTime(1200,this.ac.currentTime),this._rightFilter.biquad.frequency.setValueAtTime(1200,this.ac.currentTime),this._leftFilter.biquad.Q.setValueAtTime(.3,this.ac.currentTime),this._rightFilter.biquad.Q.setValueAtTime(.3,this.ac.currentTime),this.input.connect(this._split),this.leftDelay.connect(this._leftGain),this.rightDelay.connect(this._rightGain),this._leftGain.connect(this._leftFilter.input),this._rightGain.connect(this._rightFilter.input),this._merge.connect(this.output),this.output.connect(p5.soundOut.input),this._leftFilter.biquad.gain.setValueAtTime(1,this.ac.currentTime),this._rightFilter.biquad.gain.setValueAtTime(1,this.ac.currentTime),this.setType(0),this._maxDelay=this.leftDelay.delayTime.maxValue},p5.Delay.prototype.process=function(t,e,i,o){var n=i||0,s=e||0;if(n>=1)throw new Error("Feedback value will force a positive feedback loop.");if(s>=this._maxDelay)throw new Error("Delay Time exceeds maximum delay time of "+this._maxDelay+" second.");t.connect(this.input),this.leftDelay.delayTime.setValueAtTime(s,this.ac.currentTime),this.rightDelay.delayTime.setValueAtTime(s,this.ac.currentTime),this._leftGain.gain.setValueAtTime(n,this.ac.currentTime),this._rightGain.gain.setValueAtTime(n,this.ac.currentTime),o&&(this._leftFilter.freq(o),this._rightFilter.freq(o))},p5.Delay.prototype.delayTime=function(t){"number"!=typeof t?(t.connect(this.leftDelay.delayTime),t.connect(this.rightDelay.delayTime)):(this.leftDelay.delayTime.cancelScheduledValues(this.ac.currentTime),this.rightDelay.delayTime.cancelScheduledValues(this.ac.currentTime),this.leftDelay.delayTime.linearRampToValueAtTime(t,this.ac.currentTime),this.rightDelay.delayTime.linearRampToValueAtTime(t,this.ac.currentTime))},p5.Delay.prototype.feedback=function(t){if("number"!=typeof t)t.connect(this._leftGain.gain),t.connect(this._rightGain.gain);else{if(t>=1)throw new Error("Feedback value will force a positive feedback loop.");this._leftGain.gain.exponentialRampToValueAtTime(t,this.ac.currentTime),this._rightGain.gain.exponentialRampToValueAtTime(t,this.ac.currentTime)}},p5.Delay.prototype.filter=function(t,e){this._leftFilter.set(t,e),this._rightFilter.set(t,e)},p5.Delay.prototype.setType=function(t){switch(1===t&&(t="pingPong"),this._split.disconnect(),this._leftFilter.disconnect(),this._rightFilter.disconnect(),this._split.connect(this.leftDelay,0),this._split.connect(this.rightDelay,1),t){case"pingPong":this._rightFilter.setType(this._leftFilter.biquad.type),this._leftFilter.output.connect(this._merge,0,0),this._rightFilter.output.connect(this._merge,0,1),this._leftFilter.output.connect(this.rightDelay),this._rightFilter.output.connect(this.leftDelay);break;default:this._leftFilter.output.connect(this._merge,0,0),this._leftFilter.output.connect(this._merge,0,1),this._leftFilter.output.connect(this.leftDelay),this._leftFilter.output.connect(this.rightDelay)}},p5.Delay.prototype.amp=function(e,i,o){var i=i||0,o=o||0,n=t.audiocontext.currentTime,s=this.output.gain.value;this.output.gain.cancelScheduledValues(n),this.output.gain.linearRampToValueAtTime(s,n+o+.001),this.output.gain.linearRampToValueAtTime(e,n+o+i+.001)},p5.Delay.prototype.connect=function(t){var e=t||p5.soundOut.input;this.output.connect(e)},p5.Delay.prototype.disconnect=function(){this.output.disconnect()}}(master,filter);var reverb;reverb=function(){"use strict";var t=master;p5.Reverb=function(){this.ac=t.audiocontext,this.convolverNode=this.ac.createConvolver(),this.input=this.ac.createGain(),this.output=this.ac.createGain(),this.input.gain.value=.5,this.input.connect(this.convolverNode),this.convolverNode.connect(this.output),this._seconds=3,this._decay=2,this._reverse=!1,this._buildImpulse(),this.connect(),t.soundArray.push(this)},p5.Reverb.prototype.process=function(t,e,i,o){t.connect(this.input);var n=!1;e&&(this._seconds=e,n=!0),i&&(this._decay=i),o&&(this._reverse=o),n&&this._buildImpulse()},p5.Reverb.prototype.set=function(t,e,i){var o=!1;t&&(this._seconds=t,o=!0),e&&(this._decay=e),i&&(this._reverse=i),o&&this._buildImpulse()},p5.Reverb.prototype.amp=function(e,i,o){var i=i||0,o=o||0,n=t.audiocontext.currentTime,s=this.output.gain.value;this.output.gain.cancelScheduledValues(n),this.output.gain.linearRampToValueAtTime(s,n+o+.001),this.output.gain.linearRampToValueAtTime(e,n+o+i+.001)},p5.Reverb.prototype.connect=function(t){var e=t||p5.soundOut.input;this.output.connect(e.input?e.input:e)},p5.Reverb.prototype.disconnect=function(){this.output.disconnect()},p5.Reverb.prototype._buildImpulse=function(){var t,e,i=this.ac.sampleRate,o=i*this._seconds,n=this._decay,s=this.ac.createBuffer(2,o,i),r=s.getChannelData(0),a=s.getChannelData(1);for(e=0;o>e;e++)t=this.reverse?o-e:e,r[e]=(2*Math.random()-1)*Math.pow(1-t/o,n),a[e]=(2*Math.random()-1)*Math.pow(1-t/o,n);this.convolverNode.buffer=s},p5.Reverb.prototype.dispose=function(){this.convolverNode.buffer=null,this.convolverNode=null,"undefined"!=typeof this.output&&(this.output.disconnect(),this.output=null),"undefined"!=typeof this.panner&&(this.panner.disconnect(),this.panner=null)},p5.Convolver=function(e,i){this.ac=t.audiocontext,this.convolverNode=this.ac.createConvolver(),this.input=this.ac.createGain(),this.output=this.ac.createGain(),this.input.gain.value=.5,this.input.connect(this.convolverNode),this.convolverNode.connect(this.output),e?(this.impulses=[],this._loadBuffer(e,i)):(this._seconds=3,this._decay=2,this._reverse=!1,this._buildImpulse()),this.connect(),t.soundArray.push(this)},p5.Convolver.prototype=Object.create(p5.Reverb.prototype),p5.prototype.registerPreloadMethod("createConvolver"),p5.prototype.createConvolver=function(t,e){window.location.origin.indexOf("file://")>-1&&alert("This sketch may require a server to load external files. Please see http://bit.ly/1qcInwS");var i=new p5.Convolver(t,e);return i.impulses=[],i},p5.Convolver.prototype._loadBuffer=function(t,e){t=p5.prototype._checkFileFormats(t);var i=new XMLHttpRequest;i.open("GET",t,!0),i.responseType="arraybuffer";var o=this;i.onload=function(){var n=p5.prototype.getAudioContext();n.decodeAudioData(i.response,function(i){var n={},s=t.split("/");n.name=s[s.length-1],n.audioBuffer=i,o.impulses.push(n),o.convolverNode.buffer=n.audioBuffer,e&&e(n)})},i.send()},p5.Convolver.prototype.set=null,p5.Convolver.prototype.process=function(t){t.connect(this.input)},p5.Convolver.prototype.impulses=[],p5.Convolver.prototype.addImpulse=function(t,e){window.location.origin.indexOf("file://")>-1&&alert("This sketch may require a server to load external files. Please see http://bit.ly/1qcInwS"),this._loadBuffer(t,e)},p5.Convolver.prototype.resetImpulse=function(t,e){window.location.origin.indexOf("file://")>-1&&alert("This sketch may require a server to load external files. Please see http://bit.ly/1qcInwS"),this.impulses=[],this._loadBuffer(t,e)},p5.Convolver.prototype.toggleImpulse=function(t){if("number"==typeof t&&t<this.impulses.length&&(this.convolverNode.buffer=this.impulses[t].audioBuffer),"string"==typeof t)for(var e=0;e<this.impulses.length;e++)if(this.impulses[e].name===t){this.convolverNode.buffer=this.impulses[e].audioBuffer;break}},p5.Convolver.prototype.dispose=function(){for(var t in this.impulses)this.impulses[t]=null;this.convolverNode.disconnect(),this.concolverNode=null,"undefined"!=typeof this.output&&(this.output.disconnect(),this.output=null),"undefined"!=typeof this.panner&&(this.panner.disconnect(),this.panner=null)}}(master,sndcore);var Tone_core_Clock;Tone_core_Clock=function(t){"use strict";return t.Clock=function(e,i){this._oscillator=null,this._jsNode=this.context.createScriptProcessor(this.bufferSize,1,1),this._jsNode.onaudioprocess=this._processBuffer.bind(this),this._controlSignal=new t.Signal(1),this._upTick=!1,this.tick=this.defaultArg(i,function(){}),this._jsNode.noGC(),this.setRate(e)},t.extend(t.Clock),t.Clock.prototype.setRate=function(t,e){var i=this.secondsToFrequency(this.toSeconds(t));e?this._controlSignal.exponentialRampToValueNow(i,e):(this._controlSignal.cancelScheduledValues(0),this._controlSignal.setValue(i))},t.Clock.prototype.getRate=function(){return this._controlSignal.getValue()},t.Clock.prototype.start=function(t){this._oscillator=this.context.createOscillator(),this._oscillator.type="square",this._oscillator.connect(this._jsNode),this._controlSignal.connect(this._oscillator.frequency),this._upTick=!1;var e=this.toSeconds(t);this._oscillator.start(e),this._oscillator.onended=function(){}},t.Clock.prototype.stop=function(t,e){var i=this.toSeconds(t);this._oscillator.onended=e,this._oscillator.stop(i)},t.Clock.prototype._processBuffer=function(t){for(var e=this.defaultArg(t.playbackTime,this.now()),i=this._jsNode.bufferSize,o=t.inputBuffer.getChannelData(0),n=this._upTick,s=this,r=0;i>r;r++){var a=o[r];a>0&&!n?(n=!0,setTimeout(function(){var t=e+s.samplesToSeconds(r+2*i);return function(){s.tick(t)}}(),0)):0>a&&n&&(n=!1)}this._upTick=n},t.Clock.prototype.dispose=function(){this._jsNode.disconnect(),this._controlSignal.dispose(),this._oscillator&&(this._oscillator.onended(),this._oscillator.disconnect()),this._jsNode.onaudioprocess=function(){},this._jsNode=null,this._controlSignal=null,this._oscillator=null},t.Clock}(Tone_core_Tone);var metro;metro=function(){"use strict";var t=master,e=Tone_core_Clock,i=t.audiocontext;p5.Metro=function(){this.clock=new e(i.sampleRate,this.ontick.bind(this)),this.syncedParts=[],this.bpm=120,this._init(),this.tickCallback=function(){}};var o=0,n=0;p5.Metro.prototype.ontick=function(e){var i=e-o,s=e-t.audiocontext.currentTime;if(!(-.02>=i-n)){o=e;for(var r in this.syncedParts){var a=this.syncedParts[r];a.incrementStep(s);for(var u in a.phrases){var c=a.phrases[u],p=c.sequence,h=this.metroTicks%p.length;0!==p[h]&&(this.metroTicks<p.length||!c.looping)&&c.callback(p[h],s)}}this.metroTicks+=1,this.tickCallback(s)}},p5.Metro.prototype.setBPM=function(e,i){var o=60/(e*this.tatums);n=o;this.clock.setRate(o,i+t.audiocontext.currentTime),this.bpm=e},p5.Metro.prototype.getBPM=function(){return this.clock.getRate()/this.tatums*60},p5.Metro.prototype._init=function(){this.metroTicks=0},p5.Metro.prototype.resetSync=function(t){this.syncedParts=[t]},p5.Metro.prototype.pushSync=function(t){this.syncedParts.push(t)},p5.Metro.prototype.start=function(t){var e=t||0;this.clock.start(e),this.setBPM(this.bpm)},p5.Metro.prototype.stop=function(t){var e=t||0;this.clock._oscillator&&this.clock.stop(e)},p5.Metro.prototype.beatLength=function(t){this.tatums=1/t/4}}(master,Tone_core_Clock);var looper;looper=function(){"use strict";function t(t){t.currentPart++,t.currentPart>=t.parts.length?(t.scoreStep=0,t.onended()):(t.scoreStep=0,t.parts[t.currentPart-1].stop(),t.parts[t.currentPart].start())}var e=master,i=120;p5.prototype.setBPM=function(t,o){i=t;for(var n in e.parts)e.parts[n].setBPM(i,o)},p5.Phrase=function(t,e,i){this.phraseStep=0,this.name=t,this.callback=e,this.sequence=i},p5.Part=function(t,o){this.length=t||0,this.partStep=0,this.phrases=[],this.looping=!1,this.isPlaying=!1,this.onended=function(){this.stop()},this.tatums=o||.0625,this.metro=new p5.Metro,this.metro._init(),this.metro.beatLength(this.tatums),this.metro.setBPM(i),e.parts.push(this),this.callback=function(){}},p5.Part.prototype.setBPM=function(t,e){this.metro.setBPM(t,e) },p5.Part.prototype.getBPM=function(){return this.metro.getBPM()},p5.Part.prototype.start=function(t){if(!this.isPlaying){this.isPlaying=!0,this.metro.resetSync(this);var e=t||0;this.metro.start(e)}},p5.Part.prototype.loop=function(t){this.looping=!0,this.onended=function(){this.partStep=0};var e=t||0;this.start(e)},p5.Part.prototype.noLoop=function(){this.looping=!1,this.onended=function(){this.stop()}},p5.Part.prototype.stop=function(t){this.partStep=0,this.pause(t)},p5.Part.prototype.pause=function(t){this.isPlaying=!1;var e=t||0;this.metro.stop(e)},p5.Part.prototype.addPhrase=function(t,e,i){var o;if(3===arguments.length)o=new p5.Phrase(t,e,i);else{if(!(arguments[0]instanceof p5.Phrase))throw"invalid input. addPhrase accepts name, callback, array or a p5.Phrase";o=arguments[0]}this.phrases.push(o),o.sequence.length>this.length&&(this.length=o.sequence.length)},p5.Part.prototype.removePhrase=function(t){for(var e in this.phrases)this.phrases[e].name===t&&this.phrases.split(e,1)},p5.Part.prototype.getPhrase=function(t){for(var e in this.phrases)if(this.phrases[e].name===t)return this.phrases[e]},p5.Part.prototype.replaceSequence=function(t,e){for(var i in this.phrases)this.phrases[i].name===t&&(this.phrases[i].sequence=e)},p5.Part.prototype.incrementStep=function(t){this.partStep<this.length-1?(this.callback(t),this.partStep+=1):(this.looping&&this.callback(t),this.onended(),this.partStep=0)},p5.Part.prototype.onStep=function(t){this.callback=t},p5.Score=function(){this.parts=[],this.currentPart=0;var e=this;for(var i in arguments)this.parts[i]=arguments[i],this.parts[i].nextPart=this.parts[i+1],this.parts[i].onended=function(){e.resetPart(i),t(e)};this.looping=!1},p5.Score.prototype.onended=function(){this.looping?this.parts[0].start():this.parts[this.parts.length-1].onended=function(){this.stop(),this.resetParts()},this.currentPart=0},p5.Score.prototype.start=function(){this.parts[this.currentPart].start(),this.scoreStep=0},p5.Score.prototype.stop=function(){this.parts[this.currentPart].stop(),this.currentPart=0,this.scoreStep=0},p5.Score.prototype.pause=function(){this.parts[this.currentPart].stop()},p5.Score.prototype.loop=function(){this.looping=!0,this.start()},p5.Score.prototype.noLoop=function(){this.looping=!1},p5.Score.prototype.resetParts=function(){for(var t in this.parts)this.resetPart(t)},p5.Score.prototype.resetPart=function(t){this.parts[t].stop(),this.parts[t].partStep=0;for(var e in this.parts[t].phrases)this.parts[t].phrases[e].phraseStep=0},p5.Score.prototype.setBPM=function(t,e){for(var i in this.parts)this.parts[i].setBPM(t,e)}}(master);var soundRecorder;soundRecorder=function(){"use strict";function t(t,e){for(var i=t.length+e.length,o=new Float32Array(i),n=0,s=0;i>s;)o[s++]=t[n],o[s++]=e[n],n++;return o}function e(t,e,i){for(var o=i.length,n=0;o>n;n++)t.setUint8(e+n,i.charCodeAt(n))}var i=master,o=i.audiocontext;p5.SoundRecorder=function(){this.input=o.createGain(),this.output=o.createGain(),this.recording=!1,this.bufferSize=1024,this._channels=2,this._clear(),this._jsNode=o.createScriptProcessor(this.bufferSize,this._channels,2),this._jsNode.onaudioprocess=this._audioprocess.bind(this),this._callback=function(){},this._jsNode.connect(p5.soundOut._silentNode),this.setInput(),i.soundArray.push(this)},p5.SoundRecorder.prototype.setInput=function(t){this.input.disconnect(),this.input=null,this.input=o.createGain(),this.input.connect(this._jsNode),this.input.connect(this.output),t?t.connect(this.input):p5.soundOut.output.connect(this.input)},p5.SoundRecorder.prototype.record=function(t,e,i){this.recording=!0,e&&(this.sampleLimit=Math.round(e*o.sampleRate)),t&&i?this._callback=function(){this.buffer=this._getBuffer(),t.setBuffer(this.buffer),i()}:t&&(this._callback=function(){this.buffer=this._getBuffer(),t.setBuffer(this.buffer)})},p5.SoundRecorder.prototype.stop=function(){this.recording=!1,this._callback(),this._clear()},p5.SoundRecorder.prototype._clear=function(){this._leftBuffers=[],this._rightBuffers=[],this.recordedSamples=0,this.sampleLimit=null},p5.SoundRecorder.prototype._audioprocess=function(t){if(this.recording!==!1&&this.recording===!0)if(this.sampleLimit&&this.recordedSamples>=this.sampleLimit)this.stop();else{var e=t.inputBuffer.getChannelData(0),i=t.inputBuffer.getChannelData(1);this._leftBuffers.push(new Float32Array(e)),this._rightBuffers.push(new Float32Array(i)),this.recordedSamples+=this.bufferSize}},p5.SoundRecorder.prototype._getBuffer=function(){var t=[];return t.push(this._mergeBuffers(this._leftBuffers)),t.push(this._mergeBuffers(this._rightBuffers)),t},p5.SoundRecorder.prototype._mergeBuffers=function(t){for(var e=new Float32Array(this.recordedSamples),i=0,o=t.length,n=0;o>n;n++){var s=t[n];e.set(s,i),i+=s.length}return e},p5.SoundRecorder.prototype.dispose=function(){this._clear(),this._callback=function(){},this.input&&this.input.disconnect(),this.input=null,this._jsNode=null},p5.prototype.saveSound=function(i,o){var n=i.buffer.getChannelData(0),s=i.buffer.getChannelData(1),r=t(n,s),a=new ArrayBuffer(44+2*r.length),u=new DataView(a);e(u,0,"RIFF"),u.setUint32(4,44+2*r.length,!0),e(u,8,"WAVE"),e(u,12,"fmt "),u.setUint32(16,16,!0),u.setUint16(20,1,!0),u.setUint16(22,2,!0),u.setUint32(24,44100,!0),u.setUint32(28,176400,!0),u.setUint16(32,4,!0),u.setUint16(34,16,!0),e(u,36,"data"),u.setUint32(40,2*r.length,!0);for(var c=r.length,p=44,h=1,l=0;c>l;l++)u.setInt16(p,32767*r[l]*h,!0),p+=2;p5.prototype.writeFile([u],o,"wav")}}(sndcore,master);var src_app;src_app=function(){"use strict";var t=sndcore;return t}(sndcore,master,helpers,panner,soundfile,amplitude,fft,signal,oscillator,env,pulse,noise,audioin,filter,delay,reverb,metro,looper,soundRecorder);