diff --git a/lib/addons/p5.sound.js b/lib/addons/p5.sound.js index 52ed7bf91e..978043f887 100644 --- a/lib/addons/p5.sound.js +++ b/lib/addons/p5.sound.js @@ -1,4 +1,4 @@ -/*! p5.sound.js v0.3.5 2017-07-28 */ +/*! p5.sound.js v0.3.6 2017-10-25 */ /** * p5.sound extends p5 with Web Audio functionality including audio input, @@ -426,6 +426,7 @@ helpers = function () { * Returns the closest MIDI note value for * a given frequency. * + * @method freqToMidi * @param {Number} frequency A freqeuncy, for example, the "A" * above Middle C is 440Hz * @return {Number} MIDI note value @@ -730,19 +731,6 @@ panner = function () { this.output.disconnect(); }; } - // 3D panner - p5.Panner3D = function (input, output) { - var panner3D = ac.createPanner(); - panner3D.panningModel = 'HRTF'; - panner3D.distanceModel = 'linear'; - panner3D.setPosition(0, 0, 0); - input.connect(panner3D); - panner3D.connect(output); - panner3D.pan = function (xVal, yVal, zVal) { - panner3D.setPosition(xVal, yVal, zVal); - }; - return panner3D; - }; }(master); var soundfile; 'use strict'; @@ -1050,6 +1038,10 @@ soundfile = function () { this.bufferSourceNode.stop(time); this._counterNode.stop(time); } + //dont create another instance if already playing + if (this.mode === 'untildone' && this.isPlaying()) { + return; + } // make a new source and counter. They are automatically assigned playbackRate and buffer this.bufferSourceNode = this._initSourceNode(); // garbage collect counterNode and create a new one @@ -1122,10 +1114,11 @@ soundfile = function () { * p5.SoundFile if it is triggered while in the middle of playback. * In sustain mode, playback will continue simultaneous to the * new playback. In restart mode, play() will stop playback - * and start over. Sustain is the default mode. + * and start over. With untilDone, a sound will play only if it's + * not already playing. Sustain is the default mode. * * @method playMode - * @param {String} str 'restart' or 'sustain' + * @param {String} str 'restart' or 'sustain' or 'untilDone' * @example *
* function setup(){
@@ -1152,7 +1145,7 @@ soundfile = function () {
}
}
// set play mode to effect future playback
- if (s === 'restart' || s === 'sustain') {
+ if (s === 'restart' || s === 'sustain' || s === 'untildone') {
this.mode = s;
} else {
throw 'Invalid play mode. Must be either "restart" or "sustain"';
@@ -1223,7 +1216,7 @@ soundfile = function () {
* seconds from now
* @param {Number} [rate] (optional) playback rate
* @param {Number} [amp] (optional) playback volume
- * @param {Number} [cueLoopStart](optional) startTime in seconds
+ * @param {Number} [cueLoopStart] (optional) startTime in seconds
* @param {Number} [duration] (optional) loop duration in seconds
*/
p5.SoundFile.prototype.loop = function (startTime, rate, amp, loopStart, duration) {
@@ -1235,6 +1228,7 @@ soundfile = function () {
* is currently playing, this change will take effect when it
* reaches the end of the current playback.
*
+ * @method setLoop
* @param {Boolean} Boolean set looping to true or false
*/
p5.SoundFile.prototype.setLoop = function (bool) {
@@ -1253,6 +1247,7 @@ soundfile = function () {
/**
* Returns 'true' if a p5.SoundFile is currently looping and playing, 'false' if not.
*
+ * @method isLooping
* @return {Boolean}
*/
p5.SoundFile.prototype.isLooping = function () {
@@ -1293,7 +1288,7 @@ soundfile = function () {
*/
p5.SoundFile.prototype.stop = function (timeFromNow) {
var time = timeFromNow || 0;
- if (this.mode === 'sustain') {
+ if (this.mode === 'sustain' || this.mode === 'untildone') {
this.stopAll(time);
this._playing = false;
this.pauseTime = 0;
@@ -1413,6 +1408,7 @@ soundfile = function () {
/**
* Returns the current stereo pan position (-1.0 to 1.0)
*
+ * @method getPan
* @return {Number} Returns the stereo pan setting of the Oscillator
* as a number between -1.0 (left) and 1.0 (right).
* 0.0 is center and default.
@@ -1764,6 +1760,7 @@ soundfile = function () {
/**
* Replace the current Audio Buffer with a new Buffer.
*
+ * @method setBuffer
* @param {Array} buf Array of Float32 Array(s). 2 Float32 Arrays
* will create a stereo source. 1 will create
* a mono source.
@@ -4331,6 +4328,7 @@ signal = function () {
* Connect a p5.sound object or Web Audio node to this
* p5.Signal so that its amplitude values can be scaled.
*
+ * @method setInput
* @param {Object} input
*/
Signal.prototype.setInput = function (_input) {
@@ -4348,7 +4346,7 @@ signal = function () {
*
* @method add
* @param {Number} number
- * @return {p5.SignalAdd} object
+ * @return {p5.Signal} object
*/
Signal.prototype.add = function (num) {
var add = new Add(num);
@@ -4367,7 +4365,7 @@ signal = function () {
*
* @method mult
* @param {Number} number to multiply
- * @return {Tone.Multiply} object
+ * @return {p5.Signal} object
*/
Signal.prototype.mult = function (num) {
var mult = new Mult(num);
@@ -4390,7 +4388,7 @@ signal = function () {
* @param {Number} inMax input range maximum
* @param {Number} outMin input range minumum
* @param {Number} outMax input range maximum
- * @return {p5.SignalScale} object
+ * @return {p5.Signal} object
*/
Signal.prototype.scale = function (inMin, inMax, outMin, outMax) {
var mapOutMin, mapOutMax;
@@ -4461,7 +4459,7 @@ oscillator = function () {
* function mouseClicked() {
* if (mouseX > 0 && mouseX < width && mouseY < height && mouseY > 0) {
* if (!playing) {
- * // ramp amplitude to 0.5 over 0.1 seconds
+ * // ramp amplitude to 0.5 over 0.05 seconds
* osc.amp(0.5, 0.05);
* playing = true;
* backgroundColor = color(0,255,255);
@@ -4630,10 +4628,10 @@ oscillator = function () {
var now = p5sound.audiocontext.currentTime;
var rampTime = rampTime || 0;
var tFromNow = tFromNow || 0;
+ var t = now + tFromNow + rampTime;
// var currentFreq = this.oscillator.frequency.value;
// this.oscillator.frequency.cancelScheduledValues(now);
if (rampTime === 0) {
- this.oscillator.frequency.cancelScheduledValues(now);
this.oscillator.frequency.setValueAtTime(val, tFromNow + now);
} else {
if (val > 0) {
@@ -4861,7 +4859,7 @@ oscillator = function () {
*
* @class p5.SinOsc
* @constructor
- * @extends {p5.Oscillator}
+ * @extends p5.Oscillator
* @param {Number} [freq] Set the frequency
*/
p5.SinOsc = function (freq) {
@@ -4878,7 +4876,7 @@ oscillator = function () {
*
* @class p5.TriOsc
* @constructor
- * @extends {p5.Oscillator}
+ * @extends p5.Oscillator
* @param {Number} [freq] Set the frequency
*/
p5.TriOsc = function (freq) {
@@ -4895,7 +4893,7 @@ oscillator = function () {
*
* @class p5.SawOsc
* @constructor
- * @extends {p5.Oscillator}
+ * @extends p5.Oscillator
* @param {Number} [freq] Set the frequency
*/
p5.SawOsc = function (freq) {
@@ -4912,7 +4910,7 @@ oscillator = function () {
*
* @class p5.SqrOsc
* @constructor
- * @extends {p5.Oscillator}
+ * @extends p5.Oscillator
* @param {Number} [freq] Set the frequency
*/
p5.SqrOsc = function (freq) {
@@ -5759,8 +5757,6 @@ env = function () {
}
// get and set value (with linear ramp) to anchor automation
var valToSet = this.control.getValueAtTime(t);
- this.control.cancelScheduledValues(t);
- // not sure if this is necessary
if (this.isExponential === true) {
this.control.exponentialRampToValueAtTime(this.checkExpInput(valToSet), t);
} else {
@@ -5874,8 +5870,6 @@ env = function () {
}
// get and set value (with linear or exponential ramp) to anchor automation
var valToSet = this.control.getValueAtTime(t);
- this.control.cancelScheduledValues(t);
- // not sure if this is necessary
if (this.isExponential === true) {
this.control.exponentialRampToValueAtTime(this.checkExpInput(valToSet), t);
} else {
@@ -5962,7 +5956,7 @@ env = function () {
}
//get current value
var currentVal = this.checkExpInput(this.control.getValueAtTime(t));
- this.control.cancelScheduledValues(t);
+ // this.control.cancelScheduledValues(t);
//if it's going up
if (destination1 > currentVal) {
this.control.setTargetAtTime(destination1, t, this._rampAttackTC);
@@ -6394,6 +6388,7 @@ noise = function () {
* Set the amplitude of the noise between 0 and 1.0. Or,
* modulate amplitude with an audio signal such as an oscillator.
*
+ * @method amp
* @param {Number|Object} volume amplitude between 0 and 1.0
* or modulating signal/oscillator
* @param {Number} [rampTime] create a fade that lasts rampTime
@@ -7705,12 +7700,12 @@ effect = function () {
*
* @class p5.Effect
* @constructor
- *
+ *
* @param {Object} [ac] Reference to the audio context of the p5 object
- * @param {WebAudioNode} [input] Gain Node effect wrapper
- * @param {WebAudioNode} [output] Gain Node effect wrapper
+ * @param {AudioNode} [input] Gain Node effect wrapper
+ * @param {AudioNode} [output] Gain Node effect wrapper
* @param {Object} [_drywet] Tone.JS CrossFade node (defaults to value: 1)
- * @param {WebAudioNode} [wet] Effects that extend this class should connect
+ * @param {AudioNode} [wet] Effects that extend this class should connect
* to the wet signal to this gain node, so that dry and wet
* signals are mixed properly.
*/
@@ -7719,15 +7714,15 @@ effect = function () {
this.input = this.ac.createGain();
this.output = this.ac.createGain();
/**
- * The p5.Effect class is built
- * using Tone.js CrossFade
- * @private
+ * The p5.Effect class is built
+ * using Tone.js CrossFade
+ * @private
*/
this._drywet = new CrossFade(1);
/**
- * In classes that extend
- * p5.Effect, connect effect nodes
- * to the wet parameter
+ * In classes that extend
+ * p5.Effect, connect effect nodes
+ * to the wet parameter
*/
this.wet = this.ac.createGain();
this.input.connect(this._drywet.a);
@@ -7755,16 +7750,16 @@ effect = function () {
this.output.gain.linearRampToValueAtTime(vol, now + tFromNow + rampTime + 0.001);
};
/**
- * Link effects together in a chain
- * Example usage: filter.chain(reverb, delay, panner);
- * May be used with an open-ended number of arguments
+ * Link effects together in a chain
+ * Example usage: filter.chain(reverb, delay, panner);
+ * May be used with an open-ended number of arguments
*
- * @method chain
- * @param {Object} [arguments] Chain together multiple sound objects
+ * @method chain
+ * @param {Object} [arguments] Chain together multiple sound objects
*/
p5.Effect.prototype.chain = function () {
if (arguments.length > 0) {
- this.output.connect(arguments[0]);
+ this.connect(arguments[0]);
for (var i = 1; i < arguments.length; i += 1) {
arguments[i - 1].connect(arguments[i]);
}
@@ -7772,10 +7767,10 @@ effect = function () {
return this;
};
/**
- * Adjust the dry/wet value.
- *
- * @method drywet
- * @param {Number} [fade] The desired drywet value (0 - 1.0)
+ * Adjust the dry/wet value.
+ *
+ * @method drywet
+ * @param {Number} [fade] The desired drywet value (0 - 1.0)
*/
p5.Effect.prototype.drywet = function (fade) {
if (typeof fade !== 'undefined') {
@@ -7784,20 +7779,20 @@ effect = function () {
return this._drywet.fade.value;
};
/**
- * Send output to a p5.js-sound, Web Audio Node, or use signal to
- * control an AudioParam
- *
- * @method connect
- * @param {Object} unit
+ * Send output to a p5.js-sound, Web Audio Node, or use signal to
+ * control an AudioParam
+ *
+ * @method connect
+ * @param {Object} unit
*/
p5.Effect.prototype.connect = function (unit) {
var u = unit || p5.soundOut.input;
this.output.connect(u.input ? u.input : u);
};
/**
- * Disconnect all output.
- *
- * @method disconnect
+ * Disconnect all output.
+ *
+ * @method disconnect
*/
p5.Effect.prototype.disconnect = function () {
this.output.disconnect();
@@ -7821,6 +7816,7 @@ effect = function () {
var filter;
'use strict';
filter = function () {
+ var p5sound = master;
var Effect = effect;
/**
* A p5.Filter uses a Web Audio Biquad Filter to filter
@@ -7914,6 +7910,9 @@ filter = function () {
if (type) {
this.setType(type);
}
+ //Properties useful for the toggle method.
+ this._on = true;
+ this._untoggledType = this.biquad.type;
};
p5.Filter.prototype = Object.create(Effect.prototype);
/**
@@ -7994,6 +7993,42 @@ filter = function () {
}
return this.biquad.Q.value;
};
+ /**
+ * Controls the gain attribute of a Biquad Filter.
+ * This is distinctly different from .amp() which is inherited from p5.Effect
+ * .amp() controls the volume via the output gain node
+ * p5.Filter.gain() controls the gain parameter of a Biquad Filter node.
+ *
+ * @method gain
+ * @param {Number} gain
+ * @return {Number} Returns the current or updated gain value
+ */
+ p5.Filter.prototype.gain = function (gain, time) {
+ var t = time || 0;
+ if (typeof gain === 'number') {
+ this.biquad.gain.value = gain;
+ this.biquad.gain.cancelScheduledValues(this.ac.currentTime + 0.01 + t);
+ this.biquad.gain.linearRampToValueAtTime(gain, this.ac.currentTime + 0.02 + t);
+ } else if (gain) {
+ gain.connect(this.biquad.gain);
+ }
+ return this.biquad.gain.value;
+ };
+ /**
+ * Toggle function. Switches between the specified type and allpass
+ *
+ * @method toggle
+ * @return {boolean} [Toggle value]
+ */
+ p5.Filter.prototype.toggle = function () {
+ this._on = !this._on;
+ if (this._on === true) {
+ this.biquad.type = this._untoggledType;
+ } else if (this._on === false) {
+ this.biquad.type = 'allpass';
+ }
+ return this._on;
+ };
/**
* Set the type of a p5.Filter. Possible types include:
* "lowpass" (default), "highpass", "bandpass",
@@ -8005,6 +8040,7 @@ filter = function () {
*/
p5.Filter.prototype.setType = function (t) {
this.biquad.type = t;
+ this._untoggledType = this.biquad.type;
};
p5.Filter.prototype.dispose = function () {
// remove reference from soundArray
@@ -8020,7 +8056,7 @@ filter = function () {
*
* @class p5.LowPass
* @constructor
- * @extends {p5.Filter}
+ * @extends p5.Filter
*/
p5.LowPass = function () {
p5.Filter.call(this, 'lowpass');
@@ -8034,7 +8070,7 @@ filter = function () {
*
* @class p5.HighPass
* @constructor
- * @extends {p5.Filter}
+ * @extends p5.Filter
*/
p5.HighPass = function () {
p5.Filter.call(this, 'highpass');
@@ -8046,16 +8082,703 @@ filter = function () {
* its method setType('bandpass')
.
* See p5.Filter for methods.
*
- * @class BandPass
+ * @class p5.BandPass
* @constructor
- * @extends {p5.Filter}
+ * @extends p5.Filter
*/
p5.BandPass = function () {
p5.Filter.call(this, 'bandpass');
};
p5.BandPass.prototype = Object.create(p5.Filter.prototype);
return p5.Filter;
-}(effect);
+}(master, effect);
+var src_eqFilter;
+'use strict';
+src_eqFilter = function () {
+ var Filter = filter;
+ var p5sound = master;
+ /**
+ * EQFilter extends p5.Filter with constraints
+ * necessary for the p5.EQ
+ *
+ * @private
+ */
+ var EQFilter = function (freq, res) {
+ Filter.call(this, 'peaking');
+ this.disconnect();
+ this.set(freq, res);
+ this.biquad.gain.value = 0;
+ delete this.input;
+ delete this.output;
+ delete this._drywet;
+ delete this.wet;
+ };
+ EQFilter.prototype = Object.create(Filter.prototype);
+ EQFilter.prototype.amp = function () {
+ console.warn('`amp()` is not available for p5.EQ bands. Use `.gain()`');
+ };
+ EQFilter.prototype.drywet = function () {
+ console.warn('`drywet()` is not available for p5.EQ bands.');
+ };
+ EQFilter.prototype.connect = function (unit) {
+ var u = unit || p5.soundOut.input;
+ if (this.biquad) {
+ this.biquad.connect(u.input ? u.input : u);
+ } else {
+ this.output.connect(u.input ? u.input : u);
+ }
+ };
+ EQFilter.prototype.disconnect = function () {
+ this.biquad.disconnect();
+ };
+ EQFilter.prototype.dispose = function () {
+ // remove reference form soundArray
+ var index = p5sound.soundArray.indexOf(this);
+ p5sound.soundArray.splice(index, 1);
+ this.disconnect();
+ delete this.biquad;
+ };
+ return EQFilter;
+}(filter, master);
+var eq;
+'use strict';
+eq = function () {
+ var Effect = effect;
+ var EQFilter = src_eqFilter;
+ /**
+ * p5.EQ is an audio effect that performs the function of a multiband
+ * audio equalizer. Equalization is used to adjust the balance of
+ * frequency compoenents of an audio signal. This process is commonly used
+ * in sound production and recording to change the waveform before it reaches
+ * a sound output device. EQ can also be used as an audio effect to create
+ * interesting distortions by filtering out parts of the spectrum. p5.EQ is
+ * built using a chain of Web Audio Biquad Filter Nodes and can be
+ * instantiated with 3 or 8 bands. Bands can be added or removed from
+ * the EQ by directly modifying p5.EQ.bands (the array that stores filters).
+ *
+ * This class extends p5.Effect.
+ * Methods amp(), chain(),
+ * drywet(), connect(), and
+ * disconnect() are available.
+ *
+ * @class p5.EQ
+ * @constructor
+ * @extends p5.Effect
+ * @param {Number} [_eqsize] Constructor will accept 3 or 8, defaults to 3
+ * @return {Object} p5.EQ object
+ *
+ * @example
+ *
+ * var eq;
+ * var band_names;
+ * var band_index;
+ *
+ * var soundFile, play;
+ *
+ * function preload() {
+ * soundFormats('mp3', 'ogg');
+ * soundFile = loadSound('assets/beat');
+ * }
+ *
+ * function setup() {
+ * eq = new p5.EQ(3);
+ * soundFile.disconnect();
+ * eq.process(soundFile);
+ *
+ * band_names = ['lows','mids','highs'];
+ * band_index = 0;
+ * play = false;
+ * textAlign(CENTER);
+ * }
+ *
+ * function draw() {
+ * background(30);
+ * noStroke();
+ * fill(255);
+ * text('click to kill',50,25);
+ *
+ * fill(255, 40, 255);
+ * textSize(26);
+ * text(band_names[band_index],50,55);
+ *
+ * fill(255);
+ * textSize(9);
+ * text('space = play/pause',50,80);
+ * }
+ *
+ * //If mouse is over canvas, cycle to the next band and kill the frequency
+ * function mouseClicked() {
+ * for (var i = 0; i < eq.bands.length; i++) {
+ * eq.bands[i].gain(0);
+ * }
+ * eq.bands[band_index].gain(-40);
+ * if (mouseX > 0 && mouseX < width && mouseY < height && mouseY > 0) {
+ * band_index === 2 ? band_index = 0 : band_index++;
+ * }
+ * }
+ *
+ * //use space bar to trigger play / pause
+ * function keyPressed() {
+ * if (key===' ') {
+ * play = !play
+ * play ? soundFile.loop() : soundFile.pause();
+ * }
+ * }
+ *
+ */
+ p5.EQ = function (_eqsize) {
+ Effect.call(this);
+ //p5.EQ can be of size (3) or (8), defaults to 3
+ _eqsize = _eqsize === 3 || _eqsize === 8 ? _eqsize : 3;
+ var factor;
+ _eqsize === 3 ? factor = Math.pow(2, 3) : factor = 2;
+ /**
+ * The p5.EQ is built with abstracted p5.Filter objects.
+ * To modify any bands, use methods of the
+ * p5.Filter API, especially `gain` and `freq`.
+ * Bands are stored in an array, with indices 0 - 3, or 0 - 7
+ * @property {Array} bands
+ *
+ */
+ this.bands = [];
+ var freq, res;
+ for (var i = 0; i < _eqsize; i++) {
+ if (i === _eqsize - 1) {
+ freq = 21000;
+ res = 0.01;
+ } else if (i === 0) {
+ freq = 100;
+ res = 0.1;
+ } else if (i === 1) {
+ freq = _eqsize === 3 ? 360 * factor : 360;
+ res = 1;
+ } else {
+ freq = this.bands[i - 1].freq() * factor;
+ res = 1;
+ }
+ this.bands[i] = this._newBand(freq, res);
+ if (i > 0) {
+ this.bands[i - 1].connect(this.bands[i].biquad);
+ } else {
+ this.input.connect(this.bands[i].biquad);
+ }
+ }
+ this.bands[_eqsize - 1].connect(this.output);
+ };
+ p5.EQ.prototype = Object.create(Effect.prototype);
+ /**
+ * Process an input by connecting it to the EQ
+ * @method process
+ * @param {Object} src Audio source
+ */
+ p5.EQ.prototype.process = function (src) {
+ src.connect(this.input);
+ };
+ // /**
+ // * Set the frequency and gain of each band in the EQ. This method should be
+ // * called with 3 or 8 frequency and gain pairs, depending on the size of the EQ.
+ // * ex. eq.set(freq0, gain0, freq1, gain1, freq2, gain2);
+ // *
+ // * @method set
+ // * @param {Number} [freq0] Frequency value for band with index 0
+ // * @param {Number} [gain0] Gain value for band with index 0
+ // * @param {Number} [freq1] Frequency value for band with index 1
+ // * @param {Number} [gain1] Gain value for band with index 1
+ // * @param {Number} [freq2] Frequency value for band with index 2
+ // * @param {Number} [gain2] Gain value for band with index 2
+ // * @param {Number} [freq3] Frequency value for band with index 3
+ // * @param {Number} [gain3] Gain value for band with index 3
+ // * @param {Number} [freq4] Frequency value for band with index 4
+ // * @param {Number} [gain4] Gain value for band with index 4
+ // * @param {Number} [freq5] Frequency value for band with index 5
+ // * @param {Number} [gain5] Gain value for band with index 5
+ // * @param {Number} [freq6] Frequency value for band with index 6
+ // * @param {Number} [gain6] Gain value for band with index 6
+ // * @param {Number} [freq7] Frequency value for band with index 7
+ // * @param {Number} [gain7] Gain value for band with index 7
+ // */
+ p5.EQ.prototype.set = function () {
+ if (arguments.length === this.bands.length * 2) {
+ for (var i = 0; i < arguments.length; i += 2) {
+ this.bands[i / 2].freq(arguments[i]);
+ this.bands[i / 2].gain(arguments[i + 1]);
+ }
+ } else {
+ console.error('Argument mismatch. .set() should be called with ' + this.bands.length * 2 + ' arguments. (one frequency and gain value pair for each band of the eq)');
+ }
+ };
+ /**
+ * Add a new band. Creates a p5.Filter and strips away everything but
+ * the raw biquad filter. This method returns an abstracted p5.Filter,
+ * which can be added to p5.EQ.bands, in order to create new EQ bands.
+ * @private
+ * @method _newBand
+ * @param {Number} freq
+ * @param {Number} res
+ * @return {Object} Abstracted Filter
+ */
+ p5.EQ.prototype._newBand = function (freq, res) {
+ return new EQFilter(freq, res);
+ };
+ p5.EQ.prototype.dispose = function () {
+ Effect.prototype.dispose.apply(this);
+ while (this.bands.length > 0) {
+ delete this.bands.pop().dispose();
+ }
+ delete this.bands;
+ };
+ return p5.EQ;
+}(effect, src_eqFilter);
+var panner3d;
+'use strict';
+panner3d = function () {
+ var p5sound = master;
+ var Effect = effect;
+ /**
+ * Panner3D is based on the
+ * Web Audio Spatial Panner Node.
+ * This panner is a spatial processing node that allows audio to be positioned
+ * and oriented in 3D space.
+ *
+ * The position is relative to an
+ * Audio Context Listener, which can be accessed
+ * by p5.soundOut.audiocontext.listener
+ *
+ *
+ * @class p5.Panner3D
+ * @constructor
+ */
+ p5.Panner3D = function () {
+ Effect.call(this);
+ /**
+ *
+ * Web Audio Spatial Panner Node
+ *
+ * Properties include
+ * - panningModel: "equal power" or "HRTF"
+ * - distanceModel: "linear", "inverse", or "exponential"
+ *
+ * @property {AudioNode} panner
+ *
+ */
+ this.panner = this.ac.createPanner();
+ this.panner.panningModel = 'HRTF';
+ this.panner.distanceModel = 'linear';
+ this.panner.connect(this.output);
+ this.input.connect(this.panner);
+ };
+ p5.Panner3D.prototype = Object.create(Effect.prototype);
+ /**
+ * Connect an audio sorce
+ *
+ * @method process
+ * @param {Object} src Input source
+ */
+ p5.Panner3D.prototype.process = function (src) {
+ src.connect(this.input);
+ };
+ /**
+ * Set the X,Y,Z position of the Panner
+ * @method set
+ * @param {Number} xVal
+ * @param {Number} yVal
+ * @param {Number} zVal
+ * @param {Number} time
+ * @return {Array} Updated x, y, z values as an array
+ */
+ p5.Panner3D.prototype.set = function (xVal, yVal, zVal, time) {
+ this.positionX(xVal, time);
+ this.positionY(yVal, time);
+ this.positionZ(zVal, time);
+ return [
+ this.panner.positionX.value,
+ this.panner.positionY.value,
+ this.panner.positionZ.value
+ ];
+ };
+ /**
+ * Getter and setter methods for position coordinates
+ * @method positionX
+ * @return {Number} updated coordinate value
+ */
+ /**
+ * Getter and setter methods for position coordinates
+ * @method positionY
+ * @return {Number} updated coordinate value
+ */
+ /**
+ * Getter and setter methods for position coordinates
+ * @method positionZ
+ * @return {Number} updated coordinate value
+ */
+ p5.Panner3D.prototype.positionX = function (xVal, time) {
+ var t = time || 0;
+ if (typeof xVal === 'number') {
+ this.panner.positionX.value = xVal;
+ this.panner.positionX.cancelScheduledValues(this.ac.currentTime + 0.01 + t);
+ this.panner.positionX.linearRampToValueAtTime(xVal, this.ac.currentTime + 0.02 + t);
+ } else if (xVal) {
+ xVal.connect(this.panner.positionX);
+ }
+ return this.panner.positionX.value;
+ };
+ p5.Panner3D.prototype.positionY = function (yVal, time) {
+ var t = time || 0;
+ if (typeof yVal === 'number') {
+ this.panner.positionY.value = yVal;
+ this.panner.positionY.cancelScheduledValues(this.ac.currentTime + 0.01 + t);
+ this.panner.positionY.linearRampToValueAtTime(yVal, this.ac.currentTime + 0.02 + t);
+ } else if (yVal) {
+ yVal.connect(this.panner.positionY);
+ }
+ return this.panner.positionY.value;
+ };
+ p5.Panner3D.prototype.positionZ = function (zVal, time) {
+ var t = time || 0;
+ if (typeof zVal === 'number') {
+ this.panner.positionZ.value = zVal;
+ this.panner.positionZ.cancelScheduledValues(this.ac.currentTime + 0.01 + t);
+ this.panner.positionZ.linearRampToValueAtTime(zVal, this.ac.currentTime + 0.02 + t);
+ } else if (zVal) {
+ zVal.connect(this.panner.positionZ);
+ }
+ return this.panner.positionZ.value;
+ };
+ /**
+ * Set the X,Y,Z position of the Panner
+ * @method orient
+ * @param {Number} xVal
+ * @param {Number} yVal
+ * @param {Number} zVal
+ * @param {Number} time
+ * @return {Array} Updated x, y, z values as an array
+ */
+ p5.Panner3D.prototype.orient = function (xVal, yVal, zVal, time) {
+ this.orientX(xVal, time);
+ this.orientY(yVal, time);
+ this.orientZ(zVal, time);
+ return [
+ this.panner.orientationX.value,
+ this.panner.orientationY.value,
+ this.panner.orientationZ.value
+ ];
+ };
+ /**
+ * Getter and setter methods for orient coordinates
+ * @method orientX
+ * @return {Number} updated coordinate value
+ */
+ /**
+ * Getter and setter methods for orient coordinates
+ * @method orientY
+ * @return {Number} updated coordinate value
+ */
+ /**
+ * Getter and setter methods for orient coordinates
+ * @method orientZ
+ * @return {Number} updated coordinate value
+ */
+ p5.Panner3D.prototype.orientX = function (xVal, time) {
+ var t = time || 0;
+ if (typeof xVal === 'number') {
+ this.panner.orientationX.value = xVal;
+ this.panner.orientationX.cancelScheduledValues(this.ac.currentTime + 0.01 + t);
+ this.panner.orientationX.linearRampToValueAtTime(xVal, this.ac.currentTime + 0.02 + t);
+ } else if (xVal) {
+ xVal.connect(this.panner.orientationX);
+ }
+ return this.panner.orientationX.value;
+ };
+ p5.Panner3D.prototype.orientY = function (yVal, time) {
+ var t = time || 0;
+ if (typeof yVal === 'number') {
+ this.panner.orientationY.value = yVal;
+ this.panner.orientationY.cancelScheduledValues(this.ac.currentTime + 0.01 + t);
+ this.panner.orientationY.linearRampToValueAtTime(yVal, this.ac.currentTime + 0.02 + t);
+ } else if (yVal) {
+ yVal.connect(this.panner.orientationY);
+ }
+ return this.panner.orientationY.value;
+ };
+ p5.Panner3D.prototype.orientZ = function (zVal, time) {
+ var t = time || 0;
+ if (typeof zVal === 'number') {
+ this.panner.orientationZ.value = zVal;
+ this.panner.orientationZ.cancelScheduledValues(this.ac.currentTime + 0.01 + t);
+ this.panner.orientationZ.linearRampToValueAtTime(zVal, this.ac.currentTime + 0.02 + t);
+ } else if (zVal) {
+ zVal.connect(this.panner.orientationZ);
+ }
+ return this.panner.orientationZ.value;
+ };
+ /**
+ * Set the rolloff factor and max distance
+ * @method setFalloff
+ * @param {Number} [maxDistance]
+ * @param {Number} [rolloffFactor]
+ */
+ p5.Panner3D.prototype.setFalloff = function (maxDistance, rolloffFactor) {
+ this.maxDist(maxDistance);
+ this.rolloff(rolloffFactor);
+ };
+ /**
+ * Maxium distance between the source and the listener
+ * @method maxDist
+ * @param {Number} maxDistance
+ * @return {Number} updated value
+ */
+ p5.Panner3D.prototype.maxDist = function (maxDistance) {
+ if (typeof maxDistance === 'number') {
+ this.panner.maxDistance = maxDistance;
+ }
+ return this.panner.maxDistance;
+ };
+ /**
+ * How quickly the volume is reduced as the source moves away from the listener
+ * @method rollof
+ * @param {Number} rolloffFactor
+ * @return {Number} updated value
+ */
+ p5.Panner3D.prototype.rolloff = function (rolloffFactor) {
+ if (typeof rolloffFactor === 'number') {
+ this.panner.rolloffFactor = rolloffFactor;
+ }
+ return this.panner.rolloffFactor;
+ };
+ p5.Panner3D.dispose = function () {
+ Effect.prototype.dispose.apply(this);
+ this.panner.disconnect();
+ delete this.panner;
+ };
+ return p5.Panner3D;
+}(master, effect);
+var listener3d;
+'use strict';
+listener3d = function () {
+ var p5sound = master;
+ var Effect = effect;
+ // /**
+ // * listener is a class that can construct both a Spatial Panner
+ // * and a Spatial Listener. The panner is based on the
+ // * Web Audio Spatial Panner Node
+ // * https://www.w3.org/TR/webaudio/#the-listenernode-interface
+ // * This panner is a spatial processing node that allows audio to be positioned
+ // * and oriented in 3D space.
+ // *
+ // * The Listener modifies the properties of the Audio Context Listener.
+ // * Both objects types use the same methods. The default is a spatial panner.
+ // *
+ // * p5.Panner3D
- Constructs a Spatial Panner
+ // * p5.Listener3D
- Constructs a Spatial Listener
+ // *
+ // * @class listener
+ // * @constructor
+ // * @return {Object} p5.Listener3D Object
+ // *
+ // * @param {Web Audio Node} listener Web Audio Spatial Panning Node
+ // * @param {AudioParam} listener.panningModel "equal power" or "HRTF"
+ // * @param {AudioParam} listener.distanceModel "linear", "inverse", or "exponential"
+ // * @param {String} [type] [Specify construction of a spatial panner or listener]
+ // */
+ p5.Listener3D = function (type) {
+ this.ac = p5sound.audiocontext;
+ this.listener = this.ac.listener;
+ };
+ // /**
+ // * Connect an audio sorce
+ // * @param {Object} src Input source
+ // */
+ p5.Listener3D.prototype.process = function (src) {
+ src.connect(this.input);
+ };
+ // /**
+ // * Set the X,Y,Z position of the Panner
+ // * @param {[Number]} xVal
+ // * @param {[Number]} yVal
+ // * @param {[Number]} zVal
+ // * @param {[Number]} time
+ // * @return {[Array]} [Updated x, y, z values as an array]
+ // */
+ p5.Listener3D.prototype.position = function (xVal, yVal, zVal, time) {
+ this.positionX(xVal, time);
+ this.positionY(yVal, time);
+ this.positionZ(zVal, time);
+ return [
+ this.listener.positionX.value,
+ this.listener.positionY.value,
+ this.listener.positionZ.value
+ ];
+ };
+ // /**
+ // * Getter and setter methods for position coordinates
+ // * @return {Number} [updated coordinate value]
+ // */
+ p5.Listener3D.prototype.positionX = function (xVal, time) {
+ var t = time || 0;
+ if (typeof xVal === 'number') {
+ this.listener.positionX.value = xVal;
+ this.listener.positionX.cancelScheduledValues(this.ac.currentTime + 0.01 + t);
+ this.listener.positionX.linearRampToValueAtTime(xVal, this.ac.currentTime + 0.02 + t);
+ } else if (xVal) {
+ xVal.connect(this.listener.positionX);
+ }
+ return this.listener.positionX.value;
+ };
+ p5.Listener3D.prototype.positionY = function (yVal, time) {
+ var t = time || 0;
+ if (typeof yVal === 'number') {
+ this.listener.positionY.value = yVal;
+ this.listener.positionY.cancelScheduledValues(this.ac.currentTime + 0.01 + t);
+ this.listener.positionY.linearRampToValueAtTime(yVal, this.ac.currentTime + 0.02 + t);
+ } else if (yVal) {
+ yVal.connect(this.listener.positionY);
+ }
+ return this.listener.positionY.value;
+ };
+ p5.Listener3D.prototype.positionZ = function (zVal, time) {
+ var t = time || 0;
+ if (typeof zVal === 'number') {
+ this.listener.positionZ.value = zVal;
+ this.listener.positionZ.cancelScheduledValues(this.ac.currentTime + 0.01 + t);
+ this.listener.positionZ.linearRampToValueAtTime(zVal, this.ac.currentTime + 0.02 + t);
+ } else if (zVal) {
+ zVal.connect(this.listener.positionZ);
+ }
+ return this.listener.positionZ.value;
+ };
+ // cannot define method when class definition is commented
+ // /**
+ // * Overrides the listener orient() method because Listener has slightly
+ // * different params. In human terms, Forward vectors are the direction the
+ // * nose is pointing. Up vectors are the direction of the top of the head.
+ // *
+ // * @method orient
+ // * @param {Number} xValF Forward vector X direction
+ // * @param {Number} yValF Forward vector Y direction
+ // * @param {Number} zValF Forward vector Z direction
+ // * @param {Number} xValU Up vector X direction
+ // * @param {Number} yValU Up vector Y direction
+ // * @param {Number} zValU Up vector Z direction
+ // * @param {Number} time
+ // * @return {Array} All orienation params
+ // */
+ p5.Listener3D.prototype.orient = function (xValF, yValF, zValF, xValU, yValU, zValU, time) {
+ if (arguments.length === 3 || arguments.length === 4) {
+ time = arguments[3];
+ this.orientForward(xValF, yValF, zValF, time);
+ } else if (arguments.length === 6 || arguments === 7) {
+ this.orientForward(xValF, yValF, zValF);
+ this.orientUp(xValU, yValU, zValU, time);
+ }
+ return [
+ this.listener.forwardX.value,
+ this.listener.forwardY.value,
+ this.listener.forwardZ.value,
+ this.listener.upX.value,
+ this.listener.upY.value,
+ this.listener.upZ.value
+ ];
+ };
+ p5.Listener3D.prototype.orientForward = function (xValF, yValF, zValF, time) {
+ this.forwardX(xValF, time);
+ this.forwardY(yValF, time);
+ this.forwardZ(zValF, time);
+ return [
+ this.listener.forwardX,
+ this.listener.forwardY,
+ this.listener.forwardZ
+ ];
+ };
+ p5.Listener3D.prototype.orientUp = function (xValU, yValU, zValU, time) {
+ this.upX(xValU, time);
+ this.upY(yValU, time);
+ this.upZ(zValU, time);
+ return [
+ this.listener.upX,
+ this.listener.upY,
+ this.listener.upZ
+ ];
+ };
+ // /**
+ // * Getter and setter methods for orient coordinates
+ // * @return {Number} [updated coordinate value]
+ // */
+ p5.Listener3D.prototype.forwardX = function (xVal, time) {
+ var t = time || 0;
+ if (typeof xVal === 'number') {
+ this.listener.forwardX.value = xVal;
+ this.listener.forwardX.cancelScheduledValues(this.ac.currentTime + 0.01 + t);
+ this.listener.forwardX.linearRampToValueAtTime(xVal, this.ac.currentTime + 0.02 + t);
+ } else if (xVal) {
+ xVal.connect(this.listener.forwardX);
+ }
+ return this.listener.forwardX.value;
+ };
+ p5.Listener3D.prototype.forwardY = function (yVal, time) {
+ var t = time || 0;
+ if (typeof yVal === 'number') {
+ this.listener.forwardY.value = yVal;
+ this.listener.forwardY.cancelScheduledValues(this.ac.currentTime + 0.01 + t);
+ this.listener.forwardY.linearRampToValueAtTime(yVal, this.ac.currentTime + 0.02 + t);
+ } else if (yVal) {
+ yVal.connect(this.listener.forwardY);
+ }
+ return this.listener.forwardY.value;
+ };
+ p5.Listener3D.prototype.forwardZ = function (zVal, time) {
+ var t = time || 0;
+ if (typeof zVal === 'number') {
+ this.listener.forwardZ.value = zVal;
+ this.listener.forwardZ.cancelScheduledValues(this.ac.currentTime + 0.01 + t);
+ this.listener.forwardZ.linearRampToValueAtTime(zVal, this.ac.currentTime + 0.02 + t);
+ } else if (zVal) {
+ zVal.connect(this.listener.forwardZ);
+ }
+ return this.listener.forwardZ.value;
+ };
+ p5.Listener3D.prototype.upX = function (xVal, time) {
+ var t = time || 0;
+ if (typeof xVal === 'number') {
+ this.listener.upX.value = xVal;
+ this.listener.upX.cancelScheduledValues(this.ac.currentTime + 0.01 + t);
+ this.listener.upX.linearRampToValueAtTime(xVal, this.ac.currentTime + 0.02 + t);
+ } else if (xVal) {
+ xVal.connect(this.listener.upX);
+ }
+ return this.listener.upX.value;
+ };
+ p5.Listener3D.prototype.upY = function (yVal, time) {
+ var t = time || 0;
+ if (typeof yVal === 'number') {
+ this.listener.upY.value = yVal;
+ this.listener.upY.cancelScheduledValues(this.ac.currentTime + 0.01 + t);
+ this.listener.upY.linearRampToValueAtTime(yVal, this.ac.currentTime + 0.02 + t);
+ } else if (yVal) {
+ yVal.connect(this.listener.upY);
+ }
+ return this.listener.upY.value;
+ };
+ p5.Listener3D.prototype.upZ = function (zVal, time) {
+ var t = time || 0;
+ if (typeof zVal === 'number') {
+ this.listener.upZ.value = zVal;
+ this.listener.upZ.cancelScheduledValues(this.ac.currentTime + 0.01 + t);
+ this.listener.upZ.linearRampToValueAtTime(zVal, this.ac.currentTime + 0.02 + t);
+ } else if (zVal) {
+ zVal.connect(this.listener.upZ);
+ }
+ return this.listener.upZ.value;
+ };
+ return p5.Listener3D;
+}(master, effect);
var delay;
'use strict';
delay = function () {
@@ -9060,6 +9783,7 @@ looper = function () {
* Set the global tempo, in beats per minute, for all
* p5.Parts. This method will impact all active p5.Parts.
*
+ * @method setBPM
* @param {Number} BPM Beats Per Minute
* @param {Number} rampTime Seconds from now
*/
@@ -9513,6 +10237,7 @@ looper = function () {
/**
* Set the tempo for all parts in the score
*
+ * @method setBPM
* @param {Number} BPM Beats Per Minute
* @param {Number} rampTime Seconds from now
*/
@@ -9535,52 +10260,310 @@ looper = function () {
}
}
}(master);
-var compressor;
-compressor = function () {
- 'use strict';
+var soundloop;
+'use strict';
+soundloop = function () {
var p5sound = master;
- var Effect = effect;
- var CustomError = errorHandler;
+ var Clock = Tone_core_Clock;
/**
- * Compressor is an audio effect class that performs dynamics compression
- * on an audio input source. This is a very commonly used technique in music
- * and sound production. Compression creates an overall louder, richer,
- * and fuller sound by lowering the volume of louds and raising that of softs.
- * Compression can be used to avoid clipping (sound distortion due to
- * peaks in volume) and is especially useful when many sounds are played
- * at once. Compression can be used on indivudal sound sources in addition
- * to the master output.
+ * SoundLoop
*
- * This class extends p5.Effect.
- * Methods amp(), chain(),
- * drywet(), connect(), and
- * disconnect() are available.
- *
- * @class p5.Compressor
+ * @class p5.SoundLoop
* @constructor
- * @extends p5.Effect
*
+ * @param {Function} callback this function will be called on each iteration of theloop
+ * @param {Number|String} [interval] amount of time or beats for each iteration of the loop
+ * defaults to 1
+ *
+ * @example
+ *
+ * var click;
+ * var looper1;
+ *
+ * function preload() {
+ * click = loadSound('assets/drum.mp3'
+ * }
*
+ * function setup() {
+ * //the looper's callback is passed the timeFromNow
+ * //this value should be used as a reference point from
+ * //which to schedule sounds
+ * looper1 = new p5.SoundLoop(function(timeFromNow){
+ * click.play(timeFromNow);
+ * background(255 * (looper1.iterations % 2));
+ * }, 2);
+ *
+ * //stop after 10 iteratios;
+ * looper1.maxIterations = 10;
+ * //start the loop
+ * looper1.start();
+ * }
+ *
*/
- p5.Compressor = function () {
- Effect.call(this);
+ p5.SoundLoop = function (callback, interval) {
+ this.callback = callback;
/**
- * The p5.Compressor is built with a Web Audio Dynamics Compressor Node
- *
- * @property {WebAudioNode} compressor
+ * musicalTimeMode uses Tone.Time convention
+ * true if string, false if number
+ * @property {Boolean} musicalTimeMode
*/
- this.compressor = this.ac.createDynamicsCompressor();
- this.input.connect(this.compressor);
- this.compressor.connect(this.wet);
- };
- p5.Compressor.prototype = Object.create(Effect.prototype);
- /**
- * Performs the same function as .connect, but also accepts
- * optional parameters to set compressor's audioParams
- * @method process
- *
- * @param {Object} src Sound source to be connected
+ this.musicalTimeMode = typeof this._interval === 'number' ? false : true;
+ this._interval = interval || 1;
+ /**
+ * musicalTimeMode variables
+ * modify these only when the interval is specified in musicalTime format as a string
+ */
+ this._timeSignature = 4;
+ this._bpm = 60;
+ this.isPlaying = false;
+ /**
+ * Set a limit to the number of loops to play. defaults to Infinity
+ * @property {Number} maxIterations
+ */
+ this.maxIterations = Infinity;
+ var self = this;
+ this.clock = new Clock({
+ 'callback': function (time) {
+ var timeFromNow = time - p5sound.audiocontext.currentTime;
+ /**
+ * Do not initiate the callback if timeFromNow is < 0
+ * This ususually occurs for a few milliseconds when the page
+ * is not fully loaded
+ *
+ * The callback should only be called until maxIterations is reached
+ */
+ if (timeFromNow > 0 && self.iterations <= self.maxIterations) {
+ self.callback(timeFromNow);
+ }
+ },
+ 'frequency': this._calcFreq()
+ });
+ };
+ /**
+ * Start the loop
+ * @method start
+ * @param {Number} [timeFromNow] schedule a starting time
+ */
+ p5.SoundLoop.prototype.start = function (timeFromNow) {
+ var t = timeFromNow || 0;
+ var now = p5sound.audiocontext.currentTime;
+ if (!this.isPlaying) {
+ this.clock.start(now + t);
+ this.isPlaying = true;
+ }
+ };
+ /**
+ * Stop the loop
+ * @method stop
+ * @param {Number} [timeFromNow] schedule a stopping time
+ */
+ p5.SoundLoop.prototype.stop = function (timeFromNow) {
+ var t = timeFromNow || 0;
+ var now = p5sound.audiocontext.currentTime;
+ if (this.isPlaying) {
+ this.clock.stop(now + t);
+ this.isPlaying = false;
+ }
+ };
+ /**
+ * Pause the loop
+ * @method pause
+ * @param {Number} [timeFromNow] schedule a pausing time
+ */
+ p5.SoundLoop.prototype.pause = function (timeFromNow) {
+ var t = timeFromNow || 0;
+ if (this.isPlaying) {
+ this.clock.pause(t);
+ this.isPlaying = false;
+ }
+ };
+ /**
+ * Synchronize loops. Use this method to start two more more loops in synchronization
+ * or to start a loop in synchronization with a loop that is already playing
+ * This method will schedule the implicit loop in sync with the explicit master loop
+ * i.e. loopToStart.syncedStart(loopToSyncWith)
+ *
+ * @method syncedStart
+ * @param {Object} otherLoop a p5.SoundLoop to sync with
+ * @param {Number} [timeFromNow] Start the loops in sync after timeFromNow seconds
+ */
+ p5.SoundLoop.prototype.syncedStart = function (otherLoop, timeFromNow) {
+ var t = timeFromNow || 0;
+ var now = p5sound.audiocontext.currentTime;
+ if (!otherLoop.isPlaying) {
+ otherLoop.clock.start(now + t);
+ otherLoop.isPlaying = true;
+ this.clock.start(now + t);
+ this.isPlaying = true;
+ } else if (otherLoop.isPlaying) {
+ var time = otherLoop.clock._nextTick - p5sound.audiocontext.currentTime;
+ this.clock.start(now + time);
+ this.isPlaying = true;
+ }
+ };
+ /**
+ * Updates frequency value, reflected in next callback
+ * @private
+ * @method _update
+ */
+ p5.SoundLoop.prototype._update = function () {
+ this.clock.frequency.value = this._calcFreq();
+ };
+ /**
+ * Calculate the frequency of the clock's callback based on bpm, interval, and timesignature
+ * @private
+ * @method _calcFreq
+ * @return {Number} new clock frequency value
+ */
+ p5.SoundLoop.prototype._calcFreq = function () {
+ //Seconds mode, bpm / timesignature has no effect
+ if (typeof this._interval === 'number') {
+ this.musicalTimeMode = false;
+ return 1 / this._interval;
+ } else if (typeof this._interval === 'string') {
+ this.musicalTimeMode = true;
+ return this._bpm / 60 / this._convertNotation(this._interval) * (this._timeSignature / 4);
+ }
+ };
+ /**
+ * Convert notation from musical time format to seconds
+ * Uses Tone.Time convention
+ * @private
+ * @method _convertNotation
+ * @param {String} value value to be converted
+ * @return {Number} converted value in seconds
+ */
+ p5.SoundLoop.prototype._convertNotation = function (value) {
+ var type = value.slice(-1);
+ value = Number(value.slice(0, -1));
+ switch (type) {
+ case 'm':
+ return this._measure(value);
+ case 'n':
+ return this._note(value);
+ default:
+ console.warn('Specified interval is not formatted correctly. See Tone.js ' + 'timing reference for more info: https://github.com/Tonejs/Tone.js/wiki/Time');
+ }
+ };
+ /**
+ * Helper conversion methods of measure and note
+ * @private
+ * @method _measure
+ * @private
+ * @method _note
+ */
+ p5.SoundLoop.prototype._measure = function (value) {
+ return value * this._timeSignature;
+ };
+ p5.SoundLoop.prototype._note = function (value) {
+ return this._timeSignature / value;
+ };
+ /**
+ * Getters and Setters, setting any paramter will result in a change in the clock's
+ * frequency, that will be reflected after the next callback
+ * beats per minute (defaults to 60)
+ * @property {Number} bpm
+ */
+ Object.defineProperty(p5.SoundLoop.prototype, 'bpm', {
+ get: function () {
+ return this._bpm;
+ },
+ set: function (bpm) {
+ if (!this.musicalTimeMode) {
+ console.warn('Changing the BPM in "seconds" mode has no effect. ' + 'BPM is only relevant in musicalTimeMode ' + 'when the interval is specified as a string ' + '("2n", "4n", "1m"...etc)');
+ }
+ this._bpm = bpm;
+ this._update();
+ }
+ });
+ /**
+ * number of quarter notes in a measure (defaults to 4)
+ * @property {Number} timeSignature
+ */
+ Object.defineProperty(p5.SoundLoop.prototype, 'timeSignature', {
+ get: function () {
+ return this._timeSignature;
+ },
+ set: function (timeSig) {
+ if (!this.musicalTimeMode) {
+ console.warn('Changing the timeSignature in "seconds" mode has no effect. ' + 'BPM is only relevant in musicalTimeMode ' + 'when the interval is specified as a string ' + '("2n", "4n", "1m"...etc)');
+ }
+ this._timeSignature = timeSig;
+ this._update();
+ }
+ });
+ /**
+ * length of the loops interval
+ * @property {Number|String} interval
+ */
+ Object.defineProperty(p5.SoundLoop.prototype, 'interval', {
+ get: function () {
+ return this._interval;
+ },
+ set: function (interval) {
+ this.musicalTimeMode = typeof interval === 'Number' ? false : true;
+ this._interval = interval;
+ this._update();
+ }
+ });
+ /**
+ * how many times the callback has been called so far
+ * @property {Number} iterations
+ * @readonly
+ */
+ Object.defineProperty(p5.SoundLoop.prototype, 'iterations', {
+ get: function () {
+ return this.clock.ticks;
+ }
+ });
+ return p5.SoundLoop;
+}(master, Tone_core_Clock);
+var compressor;
+compressor = function () {
+ 'use strict';
+ var p5sound = master;
+ var Effect = effect;
+ var CustomError = errorHandler;
+ /**
+ * Compressor is an audio effect class that performs dynamics compression
+ * on an audio input source. This is a very commonly used technique in music
+ * and sound production. Compression creates an overall louder, richer,
+ * and fuller sound by lowering the volume of louds and raising that of softs.
+ * Compression can be used to avoid clipping (sound distortion due to
+ * peaks in volume) and is especially useful when many sounds are played
+ * at once. Compression can be used on indivudal sound sources in addition
+ * to the master output.
+ *
+ * This class extends p5.Effect.
+ * Methods amp(), chain(),
+ * drywet(), connect(), and
+ * disconnect() are available.
+ *
+ * @class p5.Compressor
+ * @constructor
+ * @extends p5.Effect
+ *
+ *
+ */
+ p5.Compressor = function () {
+ Effect.call(this);
+ /**
+ * The p5.Compressor is built with a Web Audio Dynamics Compressor Node
+ *
+ * @property {AudioNode} compressor
+ */
+ this.compressor = this.ac.createDynamicsCompressor();
+ this.input.connect(this.compressor);
+ this.compressor.connect(this.wet);
+ };
+ p5.Compressor.prototype = Object.create(Effect.prototype);
+ /**
+ * Performs the same function as .connect, but also accepts
+ * optional parameters to set compressor's audioParams
+ * @method process
+ *
+ * @param {Object} src Sound source to be connected
*
* @param {Number} [attack] The amount of time (in seconds) to reduce the gain by 10dB,
* default = .003, range 0 - 1
@@ -9730,6 +10713,8 @@ compressor = function () {
};
/**
* Return the current reduction value
+ *
+ * @method reduction
* @return {Number} Value of the amount of gain reduction that is applied to the signal
*/
p5.Compressor.prototype.reduction = function () {
@@ -10387,6 +11372,595 @@ gain = function () {
this.input = undefined;
};
}(master, sndcore);
+var audioVoice;
+'use strict';
+audioVoice = function () {
+ var p5sound = master;
+ /**
+ * Base class for monophonic synthesizers. Any extensions of this class
+ * should follow the API and implement the methods below in order to
+ * remain compatible with p5.PolySynth();
+ *
+ * @class p5.AudioVoice
+ * @constructor
+ */
+ p5.AudioVoice = function () {
+ this.ac = p5sound.audiocontext;
+ this.output = this.ac.createGain();
+ this.connect();
+ p5sound.soundArray.push(this);
+ };
+ /**
+ * This method converts midi notes specified as a string "C4", "Eb3"...etc
+ * to frequency
+ * @private
+ * @method _setNote
+ * @param {String} note
+ */
+ p5.AudioVoice.prototype._setNote = function (note) {
+ var wholeNotes = {
+ A: 21,
+ B: 23,
+ C: 24,
+ D: 26,
+ E: 28,
+ F: 29,
+ G: 31
+ };
+ var value = wholeNotes[note[0]];
+ var octave = typeof Number(note.slice(-1)) === 'number' ? note.slice(-1) : 0;
+ value += 12 * octave;
+ value = note[1] === '#' ? value + 1 : note[1] === 'b' ? value - 1 : value;
+ //return midi value converted to frequency
+ return p5.prototype.midiToFreq(value);
+ };
+ p5.AudioVoice.prototype.play = function (note, velocity, secondsFromNow, sustime) {
+ };
+ p5.AudioVoice.prototype.triggerAttack = function (note, velocity, secondsFromNow) {
+ };
+ p5.AudioVoice.prototype.triggerRelease = function (secondsFromNow) {
+ };
+ p5.AudioVoice.prototype.amp = function (vol, rampTime) {
+ };
+ /**
+ * Connect to p5 objects or Web Audio Nodes
+ * @method connect
+ * @param {Object} unit
+ */
+ p5.AudioVoice.prototype.connect = function (unit) {
+ var u = unit || p5sound.input;
+ this.output.connect(u.input ? u.input : u);
+ };
+ /**
+ * Disconnect from soundOut
+ * @method disconnect
+ */
+ p5.AudioVoice.prototype.disconnect = function () {
+ this.output.disconnect();
+ };
+ p5.AudioVoice.prototype.dispose = function () {
+ this.output.disconnect();
+ delete this.output;
+ };
+ return p5.AudioVoice;
+}(master);
+var monosynth;
+'use strict';
+monosynth = function () {
+ var p5sound = master;
+ var AudioVoice = audioVoice;
+ /**
+ * An MonoSynth is used as a single voice for sound synthesis.
+ * This is a class to be used in conjonction with the PolySynth
+ * class. Custom synthetisers should be built inheriting from
+ * this class.
+ *
+ * @class p5.MonoSynth
+ * @constructor
+ * @example
+ *
+ * var monosynth;
+ * var x;
+ *
+ * function setup() {
+ * monosynth = new p5.MonoSynth();
+ * monosynth.loadPreset('simpleBass');
+ * monosynth.play(45,1,x=0,1);
+ * monosynth.play(49,1,x+=1,0.25);
+ * monosynth.play(50,1,x+=0.25,0.25);
+ * monosynth.play(49,1,x+=0.5,0.25);
+ * monosynth.play(50,1,x+=0.25,0.25);
+ * }
+ *
+ **/
+ p5.MonoSynth = function () {
+ AudioVoice.call(this);
+ this.oscillator = new p5.Oscillator();
+ // this.oscillator.disconnect();
+ this.env = new p5.Env();
+ this.env.setRange(1, 0);
+ this.env.setExp(true);
+ //set params
+ this.setADSR(0.02, 0.25, 0.05, 0.35);
+ // filter
+ this.filter = new p5.Filter('highpass');
+ this.filter.set(5, 1);
+ // oscillator --> env --> filter --> this.output (gain) --> p5.soundOut
+ this.oscillator.disconnect();
+ this.oscillator.connect(this.filter);
+ this.env.disconnect();
+ this.env.setInput(this.oscillator);
+ // this.env.connect(this.filter);
+ this.filter.connect(this.output);
+ this.oscillator.start();
+ this.connect();
+ //Audiovoices are connected to soundout by default
+ this._isOn = false;
+ p5sound.soundArray.push(this);
+ };
+ p5.MonoSynth.prototype = Object.create(p5.AudioVoice.prototype);
+ /**
+ * Play tells the MonoSynth to start playing a note. This method schedules
+ * the calling of .triggerAttack and .triggerRelease.
+ *
+ * @method play
+ * @param {String | Number} note the note you want to play, specified as a
+ * frequency in Hertz (Number) or as a midi
+ * value in Note/Octave format ("C4", "Eb3"...etc")
+ * See
+ * Tone. Defaults to 440 hz.
+ * @param {Number} [velocity] velocity of the note to play (ranging from 0 to 1)
+ * @param {Number} [secondsFromNow] time from now (in seconds) at which to play
+ * @param {Number} [sustainTime] time to sustain before releasing the envelope
+ *
+ */
+ p5.MonoSynth.prototype.play = function (note, velocity, secondsFromNow, susTime) {
+ // set range of env (TO DO: allow this to be scheduled in advance)
+ var susTime = susTime || this.sustain;
+ this.susTime = susTime;
+ this.triggerAttack(note, velocity, secondsFromNow);
+ this.triggerRelease(secondsFromNow + susTime);
+ };
+ /**
+ * Trigger the Attack, and Decay portion of the Envelope.
+ * Similar to holding down a key on a piano, but it will
+ * hold the sustain level until you let go.
+ *
+ * @param {String | Number} note the note you want to play, specified as a
+ * frequency in Hertz (Number) or as a midi
+ * value in Note/Octave format ("C4", "Eb3"...etc")
+ * See
+ * Tone. Defaults to 440 hz
+ * @param {Number} [velocity] velocity of the note to play (ranging from 0 to 1)
+ * @param {Number} [secondsFromNow] time from now (in seconds) at which to play
+ * @method triggerAttack
+ */
+ p5.MonoSynth.prototype.triggerAttack = function (note, velocity, secondsFromNow) {
+ var secondsFromNow = secondsFromNow || 0;
+ //triggerAttack uses ._setNote to convert a midi string to a frequency if necessary
+ var freq = typeof note === 'string' ? this._setNote(note) : typeof note === 'number' ? note : 440;
+ var vel = velocity || 1;
+ this._isOn = true;
+ this.oscillator.freq(freq, 0, secondsFromNow);
+ this.env.ramp(this.output, secondsFromNow, vel);
+ };
+ /**
+ * Trigger the release of the Envelope. This is similar to releasing
+ * the key on a piano and letting the sound fade according to the
+ * release level and release time.
+ *
+ * @param {Number} secondsFromNow time to trigger the release
+ * @method triggerRelease
+ */
+ p5.MonoSynth.prototype.triggerRelease = function (secondsFromNow) {
+ var secondsFromNow = secondsFromNow || 0;
+ this.env.ramp(this.output, secondsFromNow, 0);
+ this._isOn = false;
+ };
+ /**
+ * Set values like a traditional
+ *
+ * ADSR envelope
+ * .
+ *
+ * @method setADSR
+ * @param {Number} attackTime Time (in seconds before envelope
+ * reaches Attack Level
+ * @param {Number} [decayTime] Time (in seconds) before envelope
+ * reaches Decay/Sustain Level
+ * @param {Number} [susRatio] Ratio between attackLevel and releaseLevel, on a scale from 0 to 1,
+ * where 1.0 = attackLevel, 0.0 = releaseLevel.
+ * The susRatio determines the decayLevel and the level at which the
+ * sustain portion of the envelope will sustain.
+ * For example, if attackLevel is 0.4, releaseLevel is 0,
+ * and susAmt is 0.5, the decayLevel would be 0.2. If attackLevel is
+ * increased to 1.0 (using setRange
),
+ * then decayLevel would increase proportionally, to become 0.5.
+ * @param {Number} [releaseTime] Time in seconds from now (defaults to 0)
+ */
+ p5.MonoSynth.prototype.setADSR = function (attack, decay, sustain, release) {
+ this.env.setADSR(attack, decay, sustain, release);
+ };
+ /**
+ * Getters and Setters
+ * @property {Number} attack
+ */
+ /**
+ * @property {Number} decay
+ */
+ /**
+ * @property {Number} sustain
+ */
+ /**
+ * @property {Number} release
+ */
+ Object.defineProperties(p5.MonoSynth.prototype, {
+ 'attack': {
+ get: function () {
+ return this.env.aTime;
+ },
+ set: function (attack) {
+ this.env.setADSR(attack, this.env.dTime, this.env.sPercent, this.env.rTime);
+ }
+ },
+ 'decay': {
+ get: function () {
+ return this.env.dTime;
+ },
+ set: function (decay) {
+ this.env.setADSR(this.env.aTime, decay, this.env.sPercent, this.env.rTime);
+ }
+ },
+ 'sustain': {
+ get: function () {
+ return this.env.sPercent;
+ },
+ set: function (sustain) {
+ this.env.setADSR(this.env.aTime, this.env.dTime, sustain, this.env.rTime);
+ }
+ },
+ 'release': {
+ get: function () {
+ return this.env.rTime;
+ },
+ set: function (release) {
+ this.env.setADSR(this.env.aTime, this.env.dTime, this.env.sPercent, release);
+ }
+ }
+ });
+ /**
+ * MonoSynth amp
+ * @method amp
+ * @param {Number} vol desired volume
+ * @param {Number} [rampTime] Time to reach new volume
+ * @return {Number} new volume value
+ */
+ p5.MonoSynth.prototype.amp = function (vol, rampTime) {
+ var t = rampTime || 0;
+ if (typeof vol !== 'undefined') {
+ this.oscillator.amp(vol, t);
+ }
+ return this.oscillator.amp().value;
+ };
+ /**
+ * Connect to a p5.sound / Web Audio object.
+ *
+ * @method connect
+ * @param {Object} unit A p5.sound or Web Audio object
+ */
+ p5.MonoSynth.prototype.connect = function (unit) {
+ var u = unit || p5sound.input;
+ this.output.connect(u.input ? u.input : u);
+ };
+ /**
+ * Disconnect all outputs
+ *
+ * @method disconnect
+ */
+ p5.MonoSynth.prototype.disconnect = function () {
+ this.output.disconnect();
+ };
+ /**
+ * Get rid of the MonoSynth and free up its resources / memory.
+ *
+ * @method dispose
+ */
+ p5.MonoSynth.prototype.dispose = function () {
+ AudioVoice.prototype.dispose.apply(this);
+ this.filter.dispose();
+ this.env.dispose();
+ try {
+ this.oscillator.dispose();
+ } catch (e) {
+ console.error('mono synth default oscillator already disposed');
+ }
+ };
+}(master, audioVoice);
+var polysynth;
+'use strict';
+polysynth = function () {
+ var p5sound = master;
+ var TimelineSignal = Tone_signal_TimelineSignal;
+ /**
+ * An AudioVoice is used as a single voice for sound synthesis.
+ * The PolySynth class holds an array of AudioVoice, and deals
+ * with voices allocations, with setting notes to be played, and
+ * parameters to be set.
+ *
+ * @class p5.PolySynth
+ * @constructor
+ *
+ * @param {Number} [synthVoice] A monophonic synth voice inheriting
+ * the AudioVoice class. Defaults to p5.MonoSynth
+ * @param {Number} [polyValue] Number of voices, defaults to 8;
+ *
+ *
+ * @example
+ *
+ * var polysynth;
+ * function setup() {
+ * polysynth = new p5.PolySynth();
+ * polysynth.play(53,1,0,3);
+ * polysynth.play(60,1,0,2.9);
+ * polysynth.play(69,1,0,3);
+ * polysynth.play(71,1,0,3);
+ * polysynth.play(74,1,0,3);
+ * }
+ *
+ *
+ **/
+ p5.PolySynth = function (audioVoice, polyValue) {
+ //audiovoices will contain polyValue many monophonic synths
+ this.audiovoices = [];
+ /**
+ * An object that holds information about which notes have been played and
+ * which notes are currently being played. New notes are added as keys
+ * on the fly. While a note has been attacked, but not released, the value of the
+ * key is the audiovoice which is generating that note. When notes are released,
+ * the value of the key becomes undefined.
+ * @property notes
+ */
+ this.notes = {};
+ //indices of the most recently used, and least recently used audiovoice
+ this._newest = 0;
+ this._oldest = 0;
+ /**
+ * A PolySynth must have at least 1 voice, defaults to 8
+ * @property polyvalue
+ */
+ this.polyValue = polyValue || 8;
+ /**
+ * Monosynth that generates the sound for each note that is triggered. The
+ * p5.PolySynth defaults to using the p5.MonoSynth as its voice.
+ * @property AudioVoice
+ */
+ this.AudioVoice = audioVoice === undefined ? p5.MonoSynth : audioVoice;
+ /**
+ * This value must only change as a note is attacked or released. Due to delay
+ * and sustain times, Tone.TimelineSignal is required to schedule the change in value.
+ * @private
+ * @property {Tone.TimelineSignal} _voicesInUse
+ */
+ this._voicesInUse = new TimelineSignal(0);
+ this.output = p5sound.audiocontext.createGain();
+ this.connect();
+ //Construct the appropriate number of audiovoices
+ this._allocateVoices();
+ p5sound.soundArray.push(this);
+ };
+ /**
+ * Construct the appropriate number of audiovoices
+ * @private
+ * @method _allocateVoices
+ */
+ p5.PolySynth.prototype._allocateVoices = function () {
+ for (var i = 0; i < this.polyValue; i++) {
+ this.audiovoices.push(new this.AudioVoice());
+ this.audiovoices[i].disconnect();
+ this.audiovoices[i].connect(this.output);
+ }
+ };
+ /**
+ * Play a note by triggering noteAttack and noteRelease with sustain time
+ *
+ * @method play
+ * @param {Number} [note] midi note to play (ranging from 0 to 127 - 60 being a middle C)
+ * @param {Number} [velocity] velocity of the note to play (ranging from 0 to 1)
+ * @param {Number} [secondsFromNow] time from now (in seconds) at which to play
+ * @param {Number} [sustainTime] time to sustain before releasing the envelope
+ */
+ p5.PolySynth.prototype.play = function (note, velocity, secondsFromNow, susTime) {
+ var susTime = susTime || 1;
+ this.noteAttack(note, velocity, secondsFromNow);
+ this.noteRelease(note, secondsFromNow + susTime);
+ };
+ /**
+ * noteADSR sets the envelope for a specific note that has just been triggered.
+ * Using this method modifies the envelope of whichever audiovoice is being used
+ * to play the desired note. The envelope should be reset before noteRelease is called
+ * in order to prevent the modified envelope from being used on other notes.
+ *
+ * @method noteADSR
+ * @param {Number} [note] Midi note on which ADSR should be set.
+ * @param {Number} [attackTime] Time (in seconds before envelope
+ * reaches Attack Level
+ * @param {Number} [decayTime] Time (in seconds) before envelope
+ * reaches Decay/Sustain Level
+ * @param {Number} [susRatio] Ratio between attackLevel and releaseLevel, on a scale from 0 to 1,
+ * where 1.0 = attackLevel, 0.0 = releaseLevel.
+ * The susRatio determines the decayLevel and the level at which the
+ * sustain portion of the envelope will sustain.
+ * For example, if attackLevel is 0.4, releaseLevel is 0,
+ * and susAmt is 0.5, the decayLevel would be 0.2. If attackLevel is
+ * increased to 1.0 (using setRange
),
+ * then decayLevel would increase proportionally, to become 0.5.
+ * @param {Number} [releaseTime] Time in seconds from now (defaults to 0)
+ **/
+ p5.PolySynth.prototype.noteADSR = function (note, a, d, s, r, timeFromNow) {
+ var now = p5sound.audiocontext.currentTime;
+ var timeFromNow = timeFromNow || 0;
+ var t = now + timeFromNow;
+ this.audiovoices[this.notes[note].getValueAtTime(t)].setADSR(a, d, s, r);
+ };
+ /**
+ * Set the PolySynths global envelope. This method modifies the envelopes of each
+ * monosynth so that all notes are played with this envelope.
+ *
+ * @method setADSR
+ * @param {Number} [note] Midi note on which ADSR should be set.
+ * @param {Number} [attackTime] Time (in seconds before envelope
+ * reaches Attack Level
+ * @param {Number} [decayTime] Time (in seconds) before envelope
+ * reaches Decay/Sustain Level
+ * @param {Number} [susRatio] Ratio between attackLevel and releaseLevel, on a scale from 0 to 1,
+ * where 1.0 = attackLevel, 0.0 = releaseLevel.
+ * The susRatio determines the decayLevel and the level at which the
+ * sustain portion of the envelope will sustain.
+ * For example, if attackLevel is 0.4, releaseLevel is 0,
+ * and susAmt is 0.5, the decayLevel would be 0.2. If attackLevel is
+ * increased to 1.0 (using setRange
),
+ * then decayLevel would increase proportionally, to become 0.5.
+ * @param {Number} [releaseTime] Time in seconds from now (defaults to 0)
+ **/
+ p5.PolySynth.prototype.setADSR = function (a, d, s, r) {
+ this.audiovoices.forEach(function (voice) {
+ voice.setADSR(a, d, s, r);
+ });
+ };
+ /**
+ * Trigger the Attack, and Decay portion of a MonoSynth.
+ * Similar to holding down a key on a piano, but it will
+ * hold the sustain level until you let go.
+ *
+ * @method noteAttack
+ * @param {Number} [note] midi note on which attack should be triggered.
+ * @param {Number} [velocity] velocity of the note to play (ranging from 0 to 1)/
+ * @param {Number} [secondsFromNow] time from now (in seconds)
+ *
+ */
+ p5.PolySynth.prototype.noteAttack = function (_note, _velocity, secondsFromNow) {
+ var now = p5sound.audiocontext.currentTime;
+ //this value goes to the audiovoices which handle their own scheduling
+ var tFromNow = secondsFromNow || 0;
+ //this value is used by this._voicesInUse
+ var t = now + tFromNow;
+ //Convert note to frequency if necessary. This is because entries into this.notes
+ //should be based on frequency for the sake of consistency.
+ var note = typeof _note === 'string' ? this.AudioVoice.prototype._setNote(_note) : typeof _note === 'number' ? _note : 440;
+ var velocity = _velocity === undefined ? 1 : _velocity;
+ var currentVoice;
+ //Release the note if it is already playing
+ if (this.notes[note] !== undefined && this.notes[note].getValueAtTime(t) !== null) {
+ this.noteRelease(note, 0);
+ }
+ //Check to see how many voices are in use at the time the note will start
+ if (this._voicesInUse.getValueAtTime(t) < this.polyValue) {
+ currentVoice = this._voicesInUse.getValueAtTime(t);
+ } else {
+ currentVoice = this._oldest;
+ var oldestNote = p5.prototype.freqToMidi(this.audiovoices[this._oldest].oscillator.freq().value);
+ this.noteRelease(oldestNote);
+ this._oldest = (this._oldest + 1) % (this.polyValue - 1);
+ }
+ //Overrite the entry in the notes object. A note (frequency value)
+ //corresponds to the index of the audiovoice that is playing it
+ this.notes[note] = new TimelineSignal();
+ this.notes[note].setValueAtTime(currentVoice, t);
+ //Find the scheduled change in this._voicesInUse that will be previous to this new note
+ //Add 1 and schedule this value at time 't', when this note will start playing
+ var previousVal = this._voicesInUse._searchBefore(t) === null ? 0 : this._voicesInUse._searchBefore(t).value;
+ this._voicesInUse.setValueAtTime(previousVal + 1, t);
+ //Then update all scheduled values that follow to increase by 1
+ this._updateAfter(t, 1);
+ this._newest = currentVoice;
+ //The audiovoice handles the actual scheduling of the note
+ if (typeof velocity === 'number') {
+ var maxRange = 1 / this._voicesInUse.getValueAtTime(t) * 2;
+ velocity = velocity > maxRange ? maxRange : velocity;
+ }
+ this.audiovoices[currentVoice].triggerAttack(note, velocity, tFromNow);
+ };
+ /**
+ * Private method to ensure accurate values of this._voicesInUse
+ * Any time a new value is scheduled, it is necessary to increment all subsequent
+ * scheduledValues after attack, and decrement all subsequent
+ * scheduledValues after release
+ *
+ * @private
+ * @param {[type]} time [description]
+ * @param {[type]} value [description]
+ * @return {[type]} [description]
+ */
+ p5.PolySynth.prototype._updateAfter = function (time, value) {
+ if (this._voicesInUse._searchAfter(time) === null) {
+ return;
+ } else {
+ this._voicesInUse._searchAfter(time).value += value;
+ var nextTime = this._voicesInUse._searchAfter(time).time;
+ this._updateAfter(nextTime, value);
+ }
+ };
+ /**
+ * Trigger the Release of an AudioVoice note. This is similar to releasing
+ * the key on a piano and letting the sound fade according to the
+ * release level and release time.
+ *
+ * @method noteRelease
+ * @param {Number} [note] midi note on which attack should be triggered.
+ * @param {Number} [secondsFromNow] time to trigger the release
+ *
+ */
+ p5.PolySynth.prototype.noteRelease = function (_note, secondsFromNow) {
+ //Make sure note is in frequency inorder to query the this.notes object
+ var note = typeof _note === 'string' ? this.AudioVoice.prototype._setNote(_note) : typeof _note === 'number' ? _note : this.audiovoices[this._newest].oscillator.freq().value;
+ var now = p5sound.audiocontext.currentTime;
+ var tFromNow = secondsFromNow || 0;
+ var t = now + tFromNow;
+ if (this.notes[note].getValueAtTime(t) === null) {
+ console.warn('Cannot release a note that is not already playing');
+ } else {
+ //Find the scheduled change in this._voicesInUse that will be previous to this new note
+ //subtract 1 and schedule this value at time 't', when this note will stop playing
+ var previousVal = this._voicesInUse._searchBefore(t) === null ? 0 : this._voicesInUse._searchBefore(t).value;
+ this._voicesInUse.setValueAtTime(previousVal - 1, t);
+ //Then update all scheduled values that follow to decrease by 1
+ this._updateAfter(t, -1);
+ this.audiovoices[this.notes[note].getValueAtTime(t)].triggerRelease(tFromNow);
+ this.notes[note].setValueAtTime(null, t);
+ this._newest = this._newest === 0 ? 0 : (this._newest - 1) % (this.polyValue - 1);
+ }
+ };
+ /**
+ * Connect to a p5.sound / Web Audio object.
+ *
+ * @method connect
+ * @param {Object} unit A p5.sound or Web Audio object
+ */
+ p5.PolySynth.prototype.connect = function (unit) {
+ var u = unit || p5sound.input;
+ this.output.connect(u.input ? u.input : u);
+ };
+ /**
+ * Disconnect all outputs
+ *
+ * @method disconnect
+ */
+ p5.PolySynth.prototype.disconnect = function () {
+ this.output.disconnect();
+ };
+ /**
+ * Get rid of the MonoSynth and free up its resources / memory.
+ *
+ * @method dispose
+ */
+ p5.PolySynth.prototype.dispose = function () {
+ this.audiovoices.forEach(function (voice) {
+ voice.dispose();
+ });
+ this.output.disconnect();
+ delete this.output;
+ };
+}(master, Tone_signal_TimelineSignal, sndcore);
var distortion;
'use strict';
distortion = function () {
@@ -10516,5 +12090,5 @@ var src_app;
src_app = function () {
var p5SOUND = sndcore;
return p5SOUND;
-}(sndcore, master, helpers, errorHandler, panner, soundfile, amplitude, fft, signal, oscillator, env, pulse, noise, audioin, filter, delay, reverb, metro, looper, compressor, soundRecorder, peakdetect, gain, distortion);
-}));
+}(sndcore, master, helpers, errorHandler, panner, soundfile, amplitude, fft, signal, oscillator, env, pulse, noise, audioin, filter, eq, panner3d, listener3d, delay, reverb, metro, looper, soundloop, compressor, soundRecorder, peakdetect, gain, monosynth, polysynth, distortion, audioVoice, monosynth, polysynth);
+}));
\ No newline at end of file
diff --git a/lib/addons/p5.sound.min.js b/lib/addons/p5.sound.min.js
index 85a916c3e4..4338da4872 100644
--- a/lib/addons/p5.sound.min.js
+++ b/lib/addons/p5.sound.min.js
@@ -1,6 +1,28 @@
-/*! p5.sound.min.js v0.3.5 2017-07-28 */
+/*! p5.sound.min.js v0.3.6 2017-10-25 */
-!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-1))throw arguments[e]+" is not a valid sound format!";t.extensions.push(arguments[e])}},p5.prototype.disposeSound=function(){for(var e=0;e-1)if(p5.prototype.isFileSupported(n))i=i;else for(var o=i.split("."),r=o[o.length-1],s=0;s1?(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;no;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.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&&nt&&!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;eo;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=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&&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;ea;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;ri){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;os;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.hi1&&(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;p1)for(var t=arguments[0],e=1;e1)for(var e=1;e0)for(var t=this,e=0;e0)for(var t=0;te;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;a1-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;j0&&(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;in&&(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;n0?this.oscillator.frequency.exponentialRampToValueAtTime(e,n+i+o):this.oscillator.frequency.linearRampToValueAtTime(e,n+i+o),this.phaseAmount&&this.phase(this.phaseAmount)}},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(){var e=t.soundArray.indexOf(this);if(t.soundArray.splice(e,1),this.oscillator){var i=t.audiocontext.currentTime;this.stop(i),this.disconnect(),this.panner=null,this.oscillator=null}this.osc2&&this.osc2.dispose()},p5.Oscillator.prototype.phase=function(e){var i=p5.prototype.map(e,0,1,0,1/this.f),n=t.audiocontext.currentTime;this.phaseAmount=e,this.dNode||(this.dNode=t.audiocontext.createDelay(),this.oscillator.disconnect(),this.oscillator.connect(this.dNode),this.dNode.connect(this.output)),this.dNode.delayTime.setValueAtTime(i,n)};var o=function(t,e,i,n,o){var r=t.oscillator;for(var s in t.mathOps)t.mathOps[s]instanceof o&&(r.disconnect(),t.mathOps[s].dispose(),i=s,i0&&(r=t.mathOps[s-1]),r.disconnect(),r.connect(e),e.connect(n),t.mathOps[i]=e,t};p5.Oscillator.prototype.add=function(t){var i=new e(t),n=this.mathOps.length-1,r=this.output;return o(this,i,n,r,e)},p5.Oscillator.prototype.mult=function(t){var e=new i(t),n=this.mathOps.length-1,r=this.output;return o(this,e,n,r,i)},p5.Oscillator.prototype.scale=function(t,e,i,r){var s,a;4===arguments.length?(s=p5.prototype.map(i,t,e,0,1)-.5,a=p5.prototype.map(r,t,e,0,1)-.5):(s=arguments[0],a=arguments[1]);var u=new n(s,a),p=this.mathOps.length-1,c=this.output;return o(this,u,p,c,n)},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_Add,Tone_signal_Multiply,Tone_signal_Scale);var Tone_core_Timeline;Tone_core_Timeline=function(t){"use strict";return t.Timeline=function(){var e=this.optionsObject(arguments,["memory"],t.Timeline.defaults);this._timeline=[],this._toRemove=[],this._iterating=!1,this.memory=e.memory},t.extend(t.Timeline),t.Timeline.defaults={memory:1/0},Object.defineProperty(t.Timeline.prototype,"length",{get:function(){return this._timeline.length}}),t.Timeline.prototype.addEvent=function(t){if(this.isUndef(t.time))throw new Error("events must have a time attribute");if(t.time=this.toSeconds(t.time),this._timeline.length){var e=this._search(t.time);this._timeline.splice(e+1,0,t)}else this._timeline.push(t);if(this.length>this.memory){var i=this.length-this.memory;this._timeline.splice(0,i)}return this},t.Timeline.prototype.removeEvent=function(t){if(this._iterating)this._toRemove.push(t);else{var e=this._timeline.indexOf(t);-1!==e&&this._timeline.splice(e,1)}return this},t.Timeline.prototype.getEvent=function(t){t=this.toSeconds(t);var e=this._search(t);return-1!==e?this._timeline[e]:null},t.Timeline.prototype.getEventAfter=function(t){t=this.toSeconds(t);var e=this._search(t);return e+1=0?this._timeline[e-1]:null},t.Timeline.prototype.cancel=function(t){if(this._timeline.length>1){t=this.toSeconds(t);var e=this._search(t);e>=0?this._timeline=this._timeline.slice(0,e):this._timeline=[]}else 1===this._timeline.length&&this._timeline[0].time>=t&&(this._timeline=[]);return this},t.Timeline.prototype.cancelBefore=function(t){if(this._timeline.length){t=this.toSeconds(t);var e=this._search(t);e>=0&&(this._timeline=this._timeline.slice(e+1))}return this},t.Timeline.prototype._search=function(t){for(var e=0,i=this._timeline.length,n=i;n>=e&&i>e;){var o=Math.floor(e+(n-e)/2),r=this._timeline[o];if(r.time===t){for(var s=o;st?n=o-1:r.time=n;n++)t(this._timeline[n]);if(this._iterating=!1,this._toRemove.length>0){for(var o=0;o=0&&this._timeline[i].time>=t;)i--;return this._iterate(e,i+1),this},t.Timeline.prototype.forEachAtTime=function(t,e){t=this.toSeconds(t);var i=this._search(t);return-1!==i&&this._iterate(function(i){i.time===t&&e(i)},0,i),this},t.Timeline.prototype.dispose=function(){t.prototype.dispose.call(this),this._timeline=null,this._toRemove=null},t.Timeline}(Tone_core_Tone);var Tone_signal_TimelineSignal;Tone_signal_TimelineSignal=function(t){"use strict";return t.TimelineSignal=function(){var e=this.optionsObject(arguments,["value","units"],t.Signal.defaults);t.Signal.apply(this,e),e.param=this._param,t.Param.call(this,e),this._events=new t.Timeline(10),this._initial=this._fromUnits(this._param.value)},t.extend(t.TimelineSignal,t.Param),t.TimelineSignal.Type={Linear:"linear",Exponential:"exponential",Target:"target",Set:"set"},Object.defineProperty(t.TimelineSignal.prototype,"value",{get:function(){return this._toUnits(this._param.value)},set:function(t){var e=this._fromUnits(t);this._initial=e,this._param.value=e}}),t.TimelineSignal.prototype.setValueAtTime=function(e,i){return e=this._fromUnits(e),i=this.toSeconds(i),this._events.addEvent({type:t.TimelineSignal.Type.Set,value:e,time:i}),this._param.setValueAtTime(e,i),this},t.TimelineSignal.prototype.linearRampToValueAtTime=function(e,i){return e=this._fromUnits(e),i=this.toSeconds(i),this._events.addEvent({type:t.TimelineSignal.Type.Linear,value:e,time:i}),this._param.linearRampToValueAtTime(e,i),
-this},t.TimelineSignal.prototype.exponentialRampToValueAtTime=function(e,i){return e=this._fromUnits(e),e=Math.max(this._minOutput,e),i=this.toSeconds(i),this._events.addEvent({type:t.TimelineSignal.Type.Exponential,value:e,time:i}),this._param.exponentialRampToValueAtTime(e,i),this},t.TimelineSignal.prototype.setTargetAtTime=function(e,i,n){return e=this._fromUnits(e),e=Math.max(this._minOutput,e),n=Math.max(this._minOutput,n),i=this.toSeconds(i),this._events.addEvent({type:t.TimelineSignal.Type.Target,value:e,time:i,constant:n}),this._param.setTargetAtTime(e,i,n),this},t.TimelineSignal.prototype.cancelScheduledValues=function(t){return this._events.cancel(t),this._param.cancelScheduledValues(this.toSeconds(t)),this},t.TimelineSignal.prototype.setRampPoint=function(e){e=this.toSeconds(e);var i=this.getValueAtTime(e),n=this._searchAfter(e);return n&&(this.cancelScheduledValues(e),n.type===t.TimelineSignal.Type.Linear?this.linearRampToValueAtTime(i,e):n.type===t.TimelineSignal.Type.Exponential&&this.exponentialRampToValueAtTime(i,e)),this.setValueAtTime(i,e),this},t.TimelineSignal.prototype.linearRampToValueBetween=function(t,e,i){return this.setRampPoint(e),this.linearRampToValueAtTime(t,i),this},t.TimelineSignal.prototype.exponentialRampToValueBetween=function(t,e,i){return this.setRampPoint(e),this.exponentialRampToValueAtTime(t,i),this},t.TimelineSignal.prototype._searchBefore=function(t){return this._events.getEvent(t)},t.TimelineSignal.prototype._searchAfter=function(t){return this._events.getEventAfter(t)},t.TimelineSignal.prototype.getValueAtTime=function(e){var i=this._searchAfter(e),n=this._searchBefore(e),o=this._initial;if(null===n)o=this._initial;else if(n.type===t.TimelineSignal.Type.Target){var r,s=this._events.getEventBefore(n.time);r=null===s?this._initial:s.value,o=this._exponentialApproach(n.time,r,n.value,n.constant,e)}else o=null===i?n.value:i.type===t.TimelineSignal.Type.Linear?this._linearInterpolate(n.time,n.value,i.time,i.value,e):i.type===t.TimelineSignal.Type.Exponential?this._exponentialInterpolate(n.time,n.value,i.time,i.value,e):n.value;return o},t.TimelineSignal.prototype.connect=t.SignalBase.prototype.connect,t.TimelineSignal.prototype._exponentialApproach=function(t,e,i,n,o){return i+(e-i)*Math.exp(-(o-t)/n)},t.TimelineSignal.prototype._linearInterpolate=function(t,e,i,n,o){return e+(n-e)*((o-t)/(i-t))},t.TimelineSignal.prototype._exponentialInterpolate=function(t,e,i,n,o){return e=Math.max(this._minOutput,e),e*Math.pow(n/e,(o-t)/(i-t))},t.TimelineSignal.prototype.dispose=function(){t.Signal.prototype.dispose.call(this),t.Param.prototype.dispose.call(this),this._events.dispose(),this._events=null},t.TimelineSignal}(Tone_core_Tone,Tone_signal_Signal);var env;env=function(){var t=master,e=Tone_signal_Add,i=Tone_signal_Multiply,n=Tone_signal_Scale,o=Tone_signal_TimelineSignal,r=Tone_core_Tone;r.setContext(t.audiocontext),p5.Env=function(e,i,n,r,s,a){this.aTime=e||.1,this.aLevel=i||1,this.dTime=n||.5,this.dLevel=r||0,this.rTime=s||0,this.rLevel=a||0,this._rampHighPercentage=.98,this._rampLowPercentage=.02,this.output=t.audiocontext.createGain(),this.control=new o,this._init(),this.control.connect(this.output),this.connection=null,this.mathOps=[this.control],this.isExponential=!1,this.sourceToClear=null,this.wasTriggered=!1,t.soundArray.push(this)},p5.Env.prototype._init=function(){var e=t.audiocontext.currentTime,i=e;this.control.setTargetAtTime(1e-5,i,.001),this._setRampAD(this.aTime,this.dTime)},p5.Env.prototype.set=function(t,e,i,n,o,r){this.aTime=t,this.aLevel=e,this.dTime=i||0,this.dLevel=n||0,this.rTime=o||0,this.rLevel=r||0,this._setRampAD(t,i)},p5.Env.prototype.setADSR=function(t,e,i,n){this.aTime=t,this.dTime=e||0,this.sPercent=i||0,this.dLevel="undefined"!=typeof i?i*(this.aLevel-this.rLevel)+this.rLevel:0,this.rTime=n||0,this._setRampAD(t,e)},p5.Env.prototype.setRange=function(t,e){this.aLevel=t||1,this.rLevel=e||0},p5.Env.prototype._setRampAD=function(t,e){this._rampAttackTime=this.checkExpInput(t),this._rampDecayTime=this.checkExpInput(e);var i=1;i=Math.log(1/this.checkExpInput(1-this._rampHighPercentage)),this._rampAttackTC=t/this.checkExpInput(i),i=Math.log(1/this._rampLowPercentage),this._rampDecayTC=e/this.checkExpInput(i)},p5.Env.prototype.setRampPercentages=function(t,e){this._rampHighPercentage=this.checkExpInput(t),this._rampLowPercentage=this.checkExpInput(e);var i=1;i=Math.log(1/this.checkExpInput(1-this._rampHighPercentage)),this._rampAttackTC=this._rampAttackTime/this.checkExpInput(i),i=Math.log(1/this._rampLowPercentage),this._rampDecayTC=this._rampDecayTime/this.checkExpInput(i)},p5.Env.prototype.setInput=function(){for(var t=0;t=t&&(t=1e-8),t},p5.Env.prototype.play=function(t,e,i){var n=e||0,i=i||0;t&&this.connection!==t&&this.connect(t),this.triggerAttack(t,n),this.triggerRelease(t,n+this.aTime+this.dTime+i)},p5.Env.prototype.triggerAttack=function(e,i){var n=t.audiocontext.currentTime,o=i||0,r=n+o;this.lastAttack=r,this.wasTriggered=!0,e&&this.connection!==e&&this.connect(e);var s=this.control.getValueAtTime(r);this.control.cancelScheduledValues(r),this.isExponential===!0?this.control.exponentialRampToValueAtTime(this.checkExpInput(s),r):this.control.linearRampToValueAtTime(s,r),r+=this.aTime,this.isExponential===!0?(this.control.exponentialRampToValueAtTime(this.checkExpInput(this.aLevel),r),s=this.checkExpInput(this.control.getValueAtTime(r)),this.control.cancelScheduledValues(r),this.control.exponentialRampToValueAtTime(s,r)):(this.control.linearRampToValueAtTime(this.aLevel,r),s=this.control.getValueAtTime(r),this.control.cancelScheduledValues(r),this.control.linearRampToValueAtTime(s,r)),r+=this.dTime,this.isExponential===!0?(this.control.exponentialRampToValueAtTime(this.checkExpInput(this.dLevel),r),s=this.checkExpInput(this.control.getValueAtTime(r)),this.control.cancelScheduledValues(r),this.control.exponentialRampToValueAtTime(s,r)):(this.control.linearRampToValueAtTime(this.dLevel,r),s=this.control.getValueAtTime(r),this.control.cancelScheduledValues(r),this.control.linearRampToValueAtTime(s,r))},p5.Env.prototype.triggerRelease=function(e,i){if(this.wasTriggered){var n=t.audiocontext.currentTime,o=i||0,r=n+o;e&&this.connection!==e&&this.connect(e);var s=this.control.getValueAtTime(r);this.control.cancelScheduledValues(r),this.isExponential===!0?this.control.exponentialRampToValueAtTime(this.checkExpInput(s),r):this.control.linearRampToValueAtTime(s,r),r+=this.rTime,this.isExponential===!0?(this.control.exponentialRampToValueAtTime(this.checkExpInput(this.rLevel),r),s=this.checkExpInput(this.control.getValueAtTime(r)),this.control.cancelScheduledValues(r),this.control.exponentialRampToValueAtTime(s,r)):(this.control.linearRampToValueAtTime(this.rLevel,r),s=this.control.getValueAtTime(r),this.control.cancelScheduledValues(r),this.control.linearRampToValueAtTime(s,r)),this.wasTriggered=!1}},p5.Env.prototype.ramp=function(e,i,n,o){var r=t.audiocontext.currentTime,s=i||0,a=r+s,u=this.checkExpInput(n),p="undefined"!=typeof o?this.checkExpInput(o):void 0;e&&this.connection!==e&&this.connect(e);var c=this.checkExpInput(this.control.getValueAtTime(a));this.control.cancelScheduledValues(a),u>c?(this.control.setTargetAtTime(u,a,this._rampAttackTC),a+=this._rampAttackTime):c>u&&(this.control.setTargetAtTime(u,a,this._rampDecayTC),a+=this._rampDecayTime),void 0!==p&&(p>u?this.control.setTargetAtTime(p,a,this._rampAttackTC):u>p&&this.control.setTargetAtTime(p,a,this._rampDecayTC))},p5.Env.prototype.connect=function(e){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),n=this.mathOps.length,o=this.output;return p5.prototype._mathChain(this,i,n,o,e)},p5.Env.prototype.mult=function(t){var e=new i(t),n=this.mathOps.length,o=this.output;return p5.prototype._mathChain(this,e,n,o,i)},p5.Env.prototype.scale=function(t,e,i,o){var r=new n(t,e,i,o),s=this.mathOps.length,a=this.output;return p5.prototype._mathChain(this,r,s,a,n)},p5.Env.prototype.dispose=function(){var e=t.soundArray.indexOf(this);t.soundArray.splice(e,1),this.disconnect();try{this.control.dispose(),this.control=null}catch(i){console.warn(i,"already disposed p5.Env")}for(var n=1;no;o++)n[o]=1;var r=t.createBufferSource();return r.buffer=i,r.loop=!0,r}var e=master;p5.Pulse=function(i,n){p5.Oscillator.call(this,i,"sawtooth"),this.w=n||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 o=this.w/this.oscillator.frequency.value;this.dNode.delayTime.value=o,this.dcGain.gain.value=1.7*(.5-this.w),this.osc2.disconnect(),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,n){var o=e.audiocontext.currentTime,r=n||0;if(!this.started){var s=i||this.f,a=this.oscillator.type;this.oscillator=e.audiocontext.createOscillator(),this.oscillator.frequency.setValueAtTime(s,o),this.oscillator.type=a,this.oscillator.connect(this.output),this.oscillator.start(r+o),this.osc2.oscillator=e.audiocontext.createOscillator(),this.osc2.oscillator.frequency.setValueAtTime(s,r+o),this.osc2.oscillator.type=a,this.osc2.oscillator.connect(this.osc2.output),this.osc2.start(r+o),this.freqNode=[this.oscillator.frequency,this.osc2.oscillator.frequency],this.dcOffset=t(),this.dcOffset.connect(this.dcGain),this.dcOffset.start(r+o),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,n=e.audiocontext.currentTime;this.oscillator.stop(i+n),this.osc2.oscillator.stop(i+n),this.dcOffset.stop(i+n),this.started=!1,this.osc2.started=!1}},p5.Pulse.prototype.freq=function(t,i,n){if("number"==typeof t){this.f=t;var o=e.audiocontext.currentTime,i=i||0,n=n||0,r=this.oscillator.frequency.value;this.oscillator.frequency.cancelScheduledValues(o),this.oscillator.frequency.setValueAtTime(r,o+n),this.oscillator.frequency.exponentialRampToValueAtTime(t,n+i+o),this.osc2.oscillator.frequency.cancelScheduledValues(o),this.osc2.oscillator.frequency.setValueAtTime(r,o+n),this.osc2.oscillator.frequency.exponentialRampToValueAtTime(t,n+i+o),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(){var t=master;p5.Noise=function(t){var o;p5.Oscillator.call(this),delete this.f,delete this.freq,delete this.oscillator,o="brown"===t?n:"pink"===t?i:e,this.buffer=o},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),n=i.getChannelData(0),o=0;e>o;o++)n[o]=2*Math.random()-1;return i.type="white",i}(),i=function(){var e,i,n,o,r,s,a,u=2*t.audiocontext.sampleRate,p=t.audiocontext.createBuffer(1,u,t.audiocontext.sampleRate),c=p.getChannelData(0);e=i=n=o=r=s=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,n=.969*n+.153852*l,o=.8665*o+.3104856*l,r=.55*r+.5329522*l,s=-.7616*s-.016898*l,c[h]=e+i+n+o+r+s+a+.5362*l,c[h]*=.11,a=.115926*l}return p.type="pink",p}(),n=function(){for(var e=2*t.audiocontext.sampleRate,i=t.audiocontext.createBuffer(1,e,t.audiocontext.sampleRate),n=i.getChannelData(0),o=0,r=0;e>r;r++){var s=2*Math.random()-1;n[r]=(o+.02*s)/1.02,o=n[r],n[r]*=3.5}return i.type="brown",i}();p5.Noise.prototype.setType=function(o){switch(o){case"white":this.buffer=e;break;case"pink":this.buffer=i;break;case"brown":this.buffer=n;break;default:this.buffer=e}if(this.started){var r=t.audiocontext.currentTime;this.stop(r),this.start(r+.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,i=t.soundArray.indexOf(this);t.soundArray.splice(i,1),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(){var t=master;p5.AudioIn=function(e){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?e?e():window.alert("This browser does not support AudioIn"):"function"==typeof window.MediaDevices.enumerateDevices&&window.MediaDevices.enumerateDevices(this._gotSources),t.soundArray.push(this)},p5.AudioIn.prototype.start=function(e,i){var n=this;if(t.inputSources[n.currentSource]){var o=t.inputSources[n.currentSource].id,r={audio:{optional:[{sourceId:o}]}};window.navigator.getUserMedia(r,this._onStream=function(i){n.stream=i,n.enabled=!0,n.mediaStream=t.audiocontext.createMediaStreamSource(i),n.mediaStream.connect(n.output),e&&e(),n.amplitude.setInput(n.output)},this._onStreamError=function(t){i?i(t):console.error(t)})}else window.navigator.getUserMedia({audio:!0},this._onStream=function(i){n.stream=i,n.enabled=!0,n.mediaStream=t.audiocontext.createMediaStreamSource(i),n.mediaStream.connect(n.output),n.amplitude.setInput(n.output),e&&e()},this._onStreamError=function(t){i?i(t):console.error(t)})},p5.AudioIn.prototype.stop=function(){this.stream&&this.stream.getTracks()[0].stop()},p5.AudioIn.prototype.connect=function(e){e?e.hasOwnProperty("input")?this.output.connect(e.input):e.hasOwnProperty("analyser")?this.output.connect(e.analyser):this.output.connect(e):this.output.connect(t.input)},p5.AudioIn.prototype.disconnect=function(){this.output.disconnect(),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(t){for(var e=0;e0?t.inputSources:"This browser does not support MediaStreamTrack.getSources()"},p5.AudioIn.prototype.getSources=function(e){"function"==typeof window.MediaStreamTrack.getSources?window.MediaStreamTrack.getSources(function(i){for(var n=0,o=i.length;o>n;n++){var r=i[n];"audio"===r.kind&&t.inputSources.push(r)}e(t.inputSources)}):console.log("This browser does not support MediaStreamTrack.getSources()")},p5.AudioIn.prototype.setSource=function(e){var i=this;t.inputSources.length>0&&e=t?0:1}),this._scale=this.input=new t.Multiply(1e4),this._scale.connect(this._thresh)},t.extend(t.GreaterThanZero,t.SignalBase),t.GreaterThanZero.prototype.dispose=function(){return t.prototype.dispose.call(this),this._scale.dispose(),this._scale=null,this._thresh.dispose(),this._thresh=null,this},t.GreaterThanZero}(Tone_core_Tone,Tone_signal_Signal,Tone_signal_Multiply);var Tone_signal_EqualZero;Tone_signal_EqualZero=function(t){"use strict";return t.EqualZero=function(){this._scale=this.input=new t.Multiply(1e4),this._thresh=new t.WaveShaper(function(t){return 0===t?1:0},128),this._gtz=this.output=new t.GreaterThanZero,this._scale.chain(this._thresh,this._gtz)},t.extend(t.EqualZero,t.SignalBase),t.EqualZero.prototype.dispose=function(){return t.prototype.dispose.call(this),this._gtz.dispose(),this._gtz=null,this._scale.dispose(),this._scale=null,this._thresh.dispose(),this._thresh=null,this},t.EqualZero}(Tone_core_Tone,Tone_signal_Signal,Tone_signal_GreaterThanZero);var Tone_signal_Equal;Tone_signal_Equal=function(t){"use strict";return t.Equal=function(e){t.call(this,2,0),this._sub=this.input[0]=new t.Subtract(e),this._equals=this.output=new t.EqualZero,this._sub.connect(this._equals),this.input[1]=this._sub.input[1]},t.extend(t.Equal,t.SignalBase),Object.defineProperty(t.Equal.prototype,"value",{get:function(){return this._sub.value},set:function(t){this._sub.value=t}}),t.Equal.prototype.dispose=function(){return t.prototype.dispose.call(this),this._equals.dispose(),this._equals=null,this._sub.dispose(),this._sub=null,this},t.Equal}(Tone_core_Tone,Tone_signal_EqualZero,Tone_signal_Subtract);var Tone_signal_Select;Tone_signal_Select=function(t){"use strict";t.Select=function(i){i=this.defaultArg(i,2),t.call(this,i,1),this.gate=new t.Signal(0),this._readOnly("gate");for(var n=0;i>n;n++){var o=new e(n);this.input[n]=o,this.gate.connect(o.selecter),o.connect(this.output)}},t.extend(t.Select,t.SignalBase),t.Select.prototype.select=function(t,e){return t=Math.floor(t),this.gate.setValueAtTime(t,this.toSeconds(e)),this},t.Select.prototype.dispose=function(){this._writable("gate"),this.gate.dispose(),this.gate=null;for(var e=0;ei;i++)this.input[i]=this._sum;this._sum.connect(this._gtz)},t.extend(t.OR,t.SignalBase),t.OR.prototype.dispose=function(){return t.prototype.dispose.call(this),this._gtz.dispose(),this._gtz=null,this._sum.disconnect(),this._sum=null,this},t.OR}(Tone_core_Tone);var Tone_signal_AND;Tone_signal_AND=function(t){"use strict";return t.AND=function(e){e=this.defaultArg(e,2),t.call(this,e,0),this._equals=this.output=new t.Equal(e);for(var i=0;e>i;i++)this.input[i]=this._equals},t.extend(t.AND,t.SignalBase),t.AND.prototype.dispose=function(){return t.prototype.dispose.call(this),this._equals.dispose(),this._equals=null,this},t.AND}(Tone_core_Tone);var Tone_signal_NOT;Tone_signal_NOT=function(t){"use strict";return t.NOT=t.EqualZero,t.NOT}(Tone_core_Tone);var Tone_signal_GreaterThan;Tone_signal_GreaterThan=function(t){"use strict";return t.GreaterThan=function(e){t.call(this,2,0),this._param=this.input[0]=new t.Subtract(e),this.input[1]=this._param.input[1],this._gtz=this.output=new t.GreaterThanZero,this._param.connect(this._gtz)},t.extend(t.GreaterThan,t.Signal),t.GreaterThan.prototype.dispose=function(){return t.prototype.dispose.call(this),this._param.dispose(),this._param=null,this._gtz.dispose(),this._gtz=null,this},t.GreaterThan}(Tone_core_Tone,Tone_signal_GreaterThanZero,Tone_signal_Subtract);var Tone_signal_LessThan;Tone_signal_LessThan=function(t){"use strict";return t.LessThan=function(e){t.call(this,2,0),this._neg=this.input[0]=new t.Negate,this._gt=this.output=new t.GreaterThan,this._rhNeg=new t.Negate,this._param=this.input[1]=new t.Signal(e),this._neg.connect(this._gt),this._param.connect(this._rhNeg),this._rhNeg.connect(this._gt,0,1)},t.extend(t.LessThan,t.Signal),t.LessThan.prototype.dispose=function(){return t.prototype.dispose.call(this),this._neg.dispose(),this._neg=null,this._gt.dispose(),this._gt=null,this._rhNeg.dispose(),this._rhNeg=null,this._param.dispose(),this._param=null,this},t.LessThan}(Tone_core_Tone,Tone_signal_GreaterThan,Tone_signal_Negate);var Tone_signal_Abs;Tone_signal_Abs=function(t){"use strict";return t.Abs=function(){t.call(this,1,0),this._ltz=new t.LessThan(0),this._switch=this.output=new t.Select(2),this._negate=new t.Negate,this.input.connect(this._switch,0,0),this.input.connect(this._negate),this._negate.connect(this._switch,0,1),this.input.chain(this._ltz,this._switch.gate)},t.extend(t.Abs,t.SignalBase),t.Abs.prototype.dispose=function(){return t.prototype.dispose.call(this),this._switch.dispose(),this._switch=null,this._ltz.dispose(),this._ltz=null,this._negate.dispose(),this._negate=null,this},t.Abs}(Tone_core_Tone,Tone_signal_Select,Tone_signal_Negate,Tone_signal_LessThan);var Tone_signal_Max;Tone_signal_Max=function(t){"use strict";return t.Max=function(e){t.call(this,2,0),this.input[0]=this.context.createGain(),this._param=this.input[1]=new t.Signal(e),this._ifThenElse=this.output=new t.IfThenElse,this._gt=new t.GreaterThan,this.input[0].chain(this._gt,this._ifThenElse["if"]),this.input[0].connect(this._ifThenElse.then),this._param.connect(this._ifThenElse["else"]),this._param.connect(this._gt,0,1)},t.extend(t.Max,t.Signal),t.Max.prototype.dispose=function(){return t.prototype.dispose.call(this),this._param.dispose(),this._ifThenElse.dispose(),this._gt.dispose(),this._param=null,this._ifThenElse=null,this._gt=null,this},t.Max}(Tone_core_Tone,Tone_signal_GreaterThan,Tone_signal_IfThenElse);var Tone_signal_Min;Tone_signal_Min=function(t){"use strict";return t.Min=function(e){t.call(this,2,0),this.input[0]=this.context.createGain(),this._ifThenElse=this.output=new t.IfThenElse,this._lt=new t.LessThan,this._param=this.input[1]=new t.Signal(e),this.input[0].chain(this._lt,this._ifThenElse["if"]),this.input[0].connect(this._ifThenElse.then),this._param.connect(this._ifThenElse["else"]),this._param.connect(this._lt,0,1)},t.extend(t.Min,t.Signal),t.Min.prototype.dispose=function(){return t.prototype.dispose.call(this),this._param.dispose(),this._ifThenElse.dispose(),this._lt.dispose(),this._param=null,this._ifThenElse=null,this._lt=null,this},t.Min}(Tone_core_Tone,Tone_signal_LessThan,Tone_signal_IfThenElse);var Tone_signal_Modulo;Tone_signal_Modulo=function(t){"use strict";return t.Modulo=function(e){t.call(this,1,1),this._shaper=new t.WaveShaper(Math.pow(2,16)),this._multiply=new t.Multiply,this._subtract=this.output=new t.Subtract,this._modSignal=new t.Signal(e),this.input.fan(this._shaper,this._subtract),this._modSignal.connect(this._multiply,0,0),this._shaper.connect(this._multiply,0,1),this._multiply.connect(this._subtract,0,1),this._setWaveShaper(e)},t.extend(t.Modulo,t.SignalBase),t.Modulo.prototype._setWaveShaper=function(t){this._shaper.setMap(function(e){var i=Math.floor((e+1e-4)/t);return i})},Object.defineProperty(t.Modulo.prototype,"value",{get:function(){return this._modSignal.value},set:function(t){this._modSignal.value=t,this._setWaveShaper(t)}}),t.Modulo.prototype.dispose=function(){return t.prototype.dispose.call(this),this._shaper.dispose(),this._shaper=null,this._multiply.dispose(),this._multiply=null,this._subtract.dispose(),this._subtract=null,this._modSignal.dispose(),this._modSignal=null,this},t.Modulo}(Tone_core_Tone,Tone_signal_WaveShaper,Tone_signal_Multiply);var Tone_signal_Pow;Tone_signal_Pow=function(t){"use strict";return t.Pow=function(e){this._exp=this.defaultArg(e,1),this._expScaler=this.input=this.output=new t.WaveShaper(this._expFunc(this._exp),8192)},t.extend(t.Pow,t.SignalBase),Object.defineProperty(t.Pow.prototype,"value",{get:function(){return this._exp},set:function(t){this._exp=t,this._expScaler.setMap(this._expFunc(this._exp))}}),t.Pow.prototype._expFunc=function(t){return function(e){return Math.pow(Math.abs(e),t)}},t.Pow.prototype.dispose=function(){return t.prototype.dispose.call(this),this._expScaler.dispose(),this._expScaler=null,this},t.Pow}(Tone_core_Tone);var Tone_signal_AudioToGain;Tone_signal_AudioToGain=function(t){"use strict";return t.AudioToGain=function(){this._norm=this.input=this.output=new t.WaveShaper(function(t){return(t+1)/2})},t.extend(t.AudioToGain,t.SignalBase),t.AudioToGain.prototype.dispose=function(){return t.prototype.dispose.call(this),this._norm.dispose(),this._norm=null,this},t.AudioToGain}(Tone_core_Tone,Tone_signal_WaveShaper);var Tone_signal_Expr;Tone_signal_Expr=function(t){"use strict";function e(t,e,i){var n=new t;return i._eval(e[0]).connect(n,0,0),i._eval(e[1]).connect(n,0,1),n}function i(t,e,i){var n=new t;return i._eval(e[0]).connect(n,0,0),n}function n(t){return t?parseFloat(t):void 0}function o(t){return t&&t.args?parseFloat(t.args):void 0}return t.Expr=function(){var t=this._replacements(Array.prototype.slice.call(arguments)),e=this._parseInputs(t);this._nodes=[],this.input=new Array(e);for(var i=0;e>i;i++)this.input[i]=this.context.createGain();var n,o=this._parseTree(t);try{n=this._eval(o)}catch(r){throw this._disposeNodes(),new Error("Could evaluate expression: "+t)}this.output=n},t.extend(t.Expr,t.SignalBase),t.Expr._Expressions={value:{signal:{regexp:/^\d+\.\d+|^\d+/,method:function(e){var i=new t.Signal(n(e));return i}},input:{regexp:/^\$\d/,method:function(t,e){return e.input[n(t.substr(1))]}}},glue:{"(":{regexp:/^\(/},")":{regexp:/^\)/},",":{regexp:/^,/}},func:{abs:{regexp:/^abs/,method:i.bind(this,t.Abs)},min:{regexp:/^min/,method:e.bind(this,t.Min)},max:{regexp:/^max/,method:e.bind(this,t.Max)},"if":{regexp:/^if/,method:function(e,i){var n=new t.IfThenElse;return i._eval(e[0]).connect(n["if"]),i._eval(e[1]).connect(n.then),i._eval(e[2]).connect(n["else"]),n}},gt0:{regexp:/^gt0/,method:i.bind(this,t.GreaterThanZero)},eq0:{regexp:/^eq0/,method:i.bind(this,t.EqualZero)},mod:{regexp:/^mod/,method:function(e,i){var n=o(e[1]),r=new t.Modulo(n);return i._eval(e[0]).connect(r),r}},pow:{regexp:/^pow/,method:function(e,i){var n=o(e[1]),r=new t.Pow(n);return i._eval(e[0]).connect(r),r}},a2g:{regexp:/^a2g/,method:function(e,i){var n=new t.AudioToGain;return i._eval(e[0]).connect(n),n}}},binary:{"+":{regexp:/^\+/,precedence:1,method:e.bind(this,t.Add)},"-":{regexp:/^\-/,precedence:1,method:function(n,o){return 1===n.length?i(t.Negate,n,o):e(t.Subtract,n,o)}},"*":{regexp:/^\*/,precedence:0,method:e.bind(this,t.Multiply)},">":{regexp:/^\>/,precedence:2,method:e.bind(this,t.GreaterThan)},"<":{regexp:/^,precedence:2,method:e.bind(this,t.LessThan)},"==":{regexp:/^==/,precedence:3,method:e.bind(this,t.Equal)},"&&":{regexp:/^&&/,precedence:4,method:e.bind(this,t.AND)},"||":{regexp:/^\|\|/,precedence:5,method:e.bind(this,t.OR)}},unary:{"-":{regexp:/^\-/,method:i.bind(this,t.Negate)},"!":{regexp:/^\!/,method:i.bind(this,t.NOT)}}},t.Expr.prototype._parseInputs=function(t){var e=t.match(/\$\d/g),i=0;if(null!==e)for(var n=0;n0;){e=e.trim();var r=i(e);o.push(r),e=e.substr(r.value.length)}return{next:function(){return o[++n]},peek:function(){return o[n+1]}}},t.Expr.prototype._parseTree=function(e){function i(t,e){return!c(t)&&"glue"===t.type&&t.value===e}function n(e,i,n){var o=!1,r=t.Expr._Expressions[i];if(!c(e))for(var s in r){var a=r[s];if(a.regexp.test(e.value)){if(c(n))return!0;if(a.precedence===n)return!0}}return o}function o(t){c(t)&&(t=5);var e;e=0>t?r():o(t-1);for(var i=p.peek();n(i,"binary",t);)i=p.next(),e={operator:i.value,method:i.method,args:[e,o(t)]},i=p.peek();return e}function r(){var t,e;return t=p.peek(),n(t,"unary")?(t=p.next(),e=r(),{operator:t.value,method:t.method,args:[e]}):s()}function s(){var t,e;if(t=p.peek(),c(t))throw new SyntaxError("Unexpected termination of expression");if("func"===t.type)return t=p.next(),a(t);if("value"===t.type)return t=p.next(),{method:t.method,args:t.value};if(i(t,"(")){if(p.next(),e=o(),t=p.next(),!i(t,")"))throw new SyntaxError("Expected )");
-return e}throw new SyntaxError("Parse error, cannot process token "+t.value)}function a(t){var e,n=[];if(e=p.next(),!i(e,"("))throw new SyntaxError('Expected ( in a function call "'+t.value+'"');if(e=p.peek(),i(e,")")||(n=u()),e=p.next(),!i(e,")"))throw new SyntaxError('Expected ) in a function call "'+t.value+'"');return{method:t.method,args:n,name:name}}function u(){for(var t,e,n=[];;){if(e=o(),c(e))break;if(n.push(e),t=p.peek(),!i(t,","))break;p.next()}return n}var p=this._tokenize(e),c=this.isUndef.bind(this);return o()},t.Expr.prototype._eval=function(t){if(!this.isUndef(t)){var e=t.method(t.args,this);return this._nodes.push(e),e}},t.Expr.prototype._disposeNodes=function(){for(var t=0;t0){this.output.connect(arguments[0]);for(var t=1;t=t&&(t=1),"number"==typeof t?(this.biquad.frequency.value=t,this.biquad.frequency.cancelScheduledValues(this.ac.currentTime+.01+i),this.biquad.frequency.exponentialRampToValueAtTime(t,this.ac.currentTime+.02+i)):t&&t.connect(this.biquad.frequency),this.biquad.frequency.value},p5.Filter.prototype.res=function(t,e){var i=e||0;return"number"==typeof t?(this.biquad.Q.value=t,this.biquad.Q.cancelScheduledValues(this.ac.currentTime+.01+i),this.biquad.Q.linearRampToValueAtTime(t,this.ac.currentTime+.02+i)):t&&t.connect(this.biquad.Q),this.biquad.Q.value},p5.Filter.prototype.setType=function(t){this.biquad.type=t},p5.Filter.prototype.dispose=function(){t.prototype.dispose.apply(this),this.biquad.disconnect(),this.biquad=void 0},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),p5.Filter}(effect);var delay;delay=function(){var t=filter,e=effect;p5.Delay=function(){e.call(this),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 t,this._rightFilter=new t,this._leftFilter.disconnect(),this._rightFilter.disconnect(),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.wet),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,this.feedback(.5)},p5.Delay.prototype=Object.create(e.prototype),p5.Delay.prototype.process=function(t,e,i,n){var o=i||0,r=e||0;if(o>=1)throw new Error("Feedback value will force a positive feedback loop.");if(r>=this._maxDelay)throw new Error("Delay Time exceeds maximum delay time of "+this._maxDelay+" second.");t.connect(this.input),this.leftDelay.delayTime.setValueAtTime(r,this.ac.currentTime),this.rightDelay.delayTime.setValueAtTime(r,this.ac.currentTime),this._leftGain.gain.value=o,this._rightGain.gain.value=o,n&&(this._leftFilter.freq(n),this._rightFilter.freq(n))},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(t&&"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.");"number"==typeof t&&(this._leftGain.gain.value=t,this._rightGain.gain.value=t)}return this._leftGain.gain.value},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._rightFilter.output.connect(this._merge,0,1),this._leftFilter.output.connect(this.leftDelay),this._rightFilter.output.connect(this.rightDelay)}},p5.Delay.prototype.dispose=function(){e.prototype.dispose.apply(this),this._split.disconnect(),this._leftFilter.dispose(),this._rightFilter.dispose(),this._merge.disconnect(),this._leftGain.disconnect(),this._rightGain.disconnect(),this.leftDelay.disconnect(),this.rightDelay.disconnect(),this._split=void 0,this._leftFilter=void 0,this._rightFilter=void 0,this._merge=void 0,this._leftGain=void 0,this._rightGain=void 0,this.leftDelay=void 0,this.rightDelay=void 0}}(filter,effect);var reverb;reverb=function(){var t=errorHandler,e=effect;p5.Reverb=function(){e.call(this),this.convolverNode=this.ac.createConvolver(),this.input.gain.value=.5,this.input.connect(this.convolverNode),this.convolverNode.connect(this.wet),this._seconds=3,this._decay=2,this._reverse=!1,this._buildImpulse()},p5.Reverb.prototype=Object.create(e.prototype),p5.Reverb.prototype.process=function(t,e,i,n){t.connect(this.input);var o=!1;e&&(this._seconds=e,o=!0),i&&(this._decay=i),n&&(this._reverse=n),o&&this._buildImpulse()},p5.Reverb.prototype.set=function(t,e,i){var n=!1;t&&(this._seconds=t,n=!0),e&&(this._decay=e),i&&(this._reverse=i),n&&this._buildImpulse()},p5.Reverb.prototype._buildImpulse=function(){var t,e,i=this.ac.sampleRate,n=i*this._seconds,o=this._decay,r=this.ac.createBuffer(2,n,i),s=r.getChannelData(0),a=r.getChannelData(1);for(e=0;n>e;e++)t=this._reverse?n-e:e,s[e]=(2*Math.random()-1)*Math.pow(1-t/n,o),a[e]=(2*Math.random()-1)*Math.pow(1-t/n,o);this.convolverNode.buffer=r},p5.Reverb.prototype.dispose=function(){e.prototype.dispose.apply(this),this.convolverNode&&(this.convolverNode.buffer=null,this.convolverNode=null)},p5.Convolver=function(t,i,n){e.call(this),this.convolverNode=this.ac.createConvolver(),this.input.gain.value=.5,this.input.connect(this.convolverNode),this.convolverNode.connect(this.wet),t?(this.impulses=[],this._loadBuffer(t,i,n)):(this._seconds=3,this._decay=2,this._reverse=!1,this._buildImpulse())},p5.Convolver.prototype=Object.create(p5.Reverb.prototype),p5.prototype.registerPreloadMethod("createConvolver",p5.prototype),p5.prototype.createConvolver=function(t,e,i){window.location.origin.indexOf("file://")>-1&&"undefined"===window.cordova&&alert("This sketch may require a server to load external files. Please see http://bit.ly/1qcInwS");var n=new p5.Convolver(t,e,i);return n.impulses=[],n},p5.Convolver.prototype._loadBuffer=function(e,i,n){var e=p5.prototype._checkFileFormats(e),o=this,r=(new Error).stack,s=p5.prototype.getAudioContext(),a=new XMLHttpRequest;a.open("GET",e,!0),a.responseType="arraybuffer",a.onload=function(){if(200===a.status)s.decodeAudioData(a.response,function(t){var n={},r=e.split("/");n.name=r[r.length-1],n.audioBuffer=t,o.impulses.push(n),o.convolverNode.buffer=n.audioBuffer,i&&i(n)},function(){var e=new t("decodeAudioData",r,o.url),i="AudioContext error at decodeAudioData for "+o.url;n?(e.msg=i,n(e)):console.error(i+"\n The error stack trace includes: \n"+e.stack)});else{var u=new t("loadConvolver",r,o.url),p="Unable to load "+o.url+". The request status was: "+a.status+" ("+a.statusText+")";n?(u.message=p,n(u)):console.error(p+"\n The error stack trace includes: \n"+u.stack)}},a.onerror=function(){var e=new t("loadConvolver",r,o.url),i="There was no response from the server at "+o.url+". Check the url and internet connectivity.";n?(e.message=i,n(e)):console.error(i+"\n The error stack trace includes: \n"+e.stack)},a.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,i){window.location.origin.indexOf("file://")>-1&&"undefined"===window.cordova&&alert("This sketch may require a server to load external files. Please see http://bit.ly/1qcInwS"),this._loadBuffer(t,e,i)},p5.Convolver.prototype.resetImpulse=function(t,e,i){window.location.origin.indexOf("file://")>-1&&"undefined"===window.cordova&&alert("This sketch may require a server to load external files. Please see http://bit.ly/1qcInwS"),this.impulses=[],this._loadBuffer(t,e,i)},p5.Convolver.prototype.toggleImpulse=function(t){if("number"==typeof t&&tthis._nextTick;){n>this._nextTick+this._threshold&&(this._nextTick=n);var a=this._nextTick;this._nextTick+=1/this.frequency.getValueAtTime(this._nextTick),this.callback(a),this.ticks++}else s===t.State.Stopped&&(this._nextTick=-1,this.ticks=0)},t.Clock.prototype.getStateAtTime=function(t){return this._state.getStateAtTime(t)},t.Clock.prototype.dispose=function(){cancelAnimationFrame(this._loopID),t.TimelineState.prototype.dispose.call(this),this._writable("frequency"),this.frequency.dispose(),this.frequency=null,this._boundLoop=t.noOp,this._nextTick=1/0,this.callback=null,this._state.dispose(),this._state=null},t.Clock}(Tone_core_Tone,Tone_signal_TimelineSignal);var metro;metro=function(){var t=master,e=Tone_core_Clock;p5.Metro=function(){this.clock=new e({callback:this.ontick.bind(this)}),this.syncedParts=[],this.bpm=120,this._init(),this.prevTick=0,this.tatumTime=0,this.tickCallback=function(){}},p5.Metro.prototype.ontick=function(e){var i=e-this.prevTick,n=e-t.audiocontext.currentTime;if(!(i-this.tatumTime<=-.02)){this.prevTick=e;var o=this;this.syncedParts.forEach(function(t){t.isPlaying&&(t.incrementStep(n),t.phrases.forEach(function(t){var e=t.sequence,i=o.metroTicks%e.length;0!==e[i]&&(o.metroTicks=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,n){i=t;for(var o in e.parts)e.parts[o]&&e.parts[o].setBPM(t,n)},p5.Phrase=function(t,e,i){this.phraseStep=0,this.name=t,this.callback=e,this.sequence=i},p5.Part=function(t,n){this.length=t||0,this.partStep=0,this.phrases=[],this.isPlaying=!1,this.noLoop(),this.tatums=n||.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 n;if(3===arguments.length)n=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";n=arguments[0]}this.phrases.push(n),n.sequence.length>this.length&&(this.length=n.sequence.length)},p5.Part.prototype.removePhrase=function(t){for(var e in this.phrases)this.phrases[e].name===t&&this.phrases.splice(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.partStepr;)n[r++]=t[o],n[r++]=e[o],o++;return n}function e(t,e,i){for(var n=i.length,o=0;n>o;o++)t.setUint8(e+o,i.charCodeAt(o))}var i=master,n=i.audiocontext;p5.SoundRecorder=function(){this.input=n.createGain(),this.output=n.createGain(),this.recording=!1,this.bufferSize=1024,this._channels=2,this._clear(),this._jsNode=n.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=n.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*n.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,n=t.length,o=0;n>o;o++){var r=t[o];e.set(r,i),i+=r.length}return e},p5.SoundRecorder.prototype.dispose=function(){this._clear();var t=i.soundArray.indexOf(this);i.soundArray.splice(t,1),this._callback=function(){},this.input&&this.input.disconnect(),this.input=null,this._jsNode=null},p5.prototype.saveSound=function(i,n){var o,r;o=i.buffer.getChannelData(0),r=i.buffer.numberOfChannels>1?i.buffer.getChannelData(1):o;var s=t(o,r),a=new window.ArrayBuffer(44+2*s.length),u=new window.DataView(a);e(u,0,"RIFF"),u.setUint32(4,36+2*s.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*s.length,!0);for(var p=s.length,c=44,h=1,l=0;p>l;l++)u.setInt16(c,s[l]*(32767*h),!0),c+=2;p5.prototype.writeFile([u],n,"wav")}}(sndcore,master);var peakdetect;peakdetect=function(){p5.PeakDetect=function(t,e,i,n){this.framesPerPeak=n||20,this.framesSinceLastPeak=0,this.decayRate=.95,this.threshold=i||.35,this.cutoff=0,this.cutoffMult=1.5,this.energy=0,this.penergy=0,this.currentValue=0,this.isDetected=!1,this.f1=t||40,this.f2=e||2e4,this._onPeak=function(){}},p5.PeakDetect.prototype.update=function(t){var e=this.energy=t.getEnergy(this.f1,this.f2)/255;e>this.cutoff&&e>this.threshold&&e-this.penergy>0?(this._onPeak(),this.isDetected=!0,this.cutoff=e*this.cutoffMult,this.framesSinceLastPeak=0):(this.isDetected=!1,this.framesSinceLastPeak<=this.framesPerPeak?this.framesSinceLastPeak++:(this.cutoff*=this.decayRate,this.cutoff=Math.max(this.cutoff,this.threshold))),this.currentValue=e,this.penergy=e},p5.PeakDetect.prototype.onPeak=function(t,e){var i=this;i._onPeak=function(){t(i.energy,e)}}}();var gain;gain=function(){var t=master;p5.Gain=function(){this.ac=t.audiocontext,this.input=this.ac.createGain(),this.output=this.ac.createGain(),this.input.gain.value=.5,this.input.connect(this.output),t.soundArray.push(this)},p5.Gain.prototype.setInput=function(t){t.connect(this.input)},p5.Gain.prototype.connect=function(t){var e=t||p5.soundOut.input;this.output.connect(e.input?e.input:e)},p5.Gain.prototype.disconnect=function(){this.output.disconnect()},p5.Gain.prototype.amp=function(e,i,n){var i=i||0,n=n||0,o=t.audiocontext.currentTime,r=this.output.gain.value;this.output.gain.cancelScheduledValues(o),this.output.gain.linearRampToValueAtTime(r,o+n),this.output.gain.linearRampToValueAtTime(e,o+n+i)},p5.Gain.prototype.dispose=function(){var e=t.soundArray.indexOf(this);t.soundArray.splice(e,1),this.output.disconnect(),this.input.disconnect(),this.output=void 0,this.input=void 0}}(master,sndcore);var distortion;distortion=function(){function t(t){for(var e,i="number"==typeof t?t:50,n=44100,o=new Float32Array(n),r=Math.PI/180,s=0;n>s;++s)e=2*s/n-1,o[s]=(3+i)*e*20*r/(Math.PI+i*Math.abs(e));return o}var e=effect;p5.Distortion=function(i,n){if(e.call(this),"undefined"==typeof i&&(i=.25),"number"!=typeof i)throw new Error("amount must be a number");if("undefined"==typeof n&&(n="2x"),"string"!=typeof n)throw new Error("oversample must be a String");var o=p5.prototype.map(i,0,1,0,2e3);this.waveShaperNode=this.ac.createWaveShaper(),this.amount=o,this.waveShaperNode.curve=t(o),this.waveShaperNode.oversample=n,this.input.connect(this.waveShaperNode),this.waveShaperNode.connect(this.wet)},p5.Distortion.prototype=Object.create(e.prototype),p5.Distortion.prototype.process=function(t,e,i){t.connect(this.input),this.set(e,i)},p5.Distortion.prototype.set=function(e,i){if(e){var n=p5.prototype.map(e,0,1,0,2e3);this.amount=n,this.waveShaperNode.curve=t(n)}i&&(this.waveShaperNode.oversample=i)},p5.Distortion.prototype.getAmount=function(){return this.amount},p5.Distortion.prototype.getOversample=function(){return this.waveShaperNode.oversample},p5.Distortion.prototype.dispose=function(){e.prototype.dispose.apply(this),this.waveShaperNode.disconnect(),this.waveShaperNode=null}}(effect);var src_app;src_app=function(){var t=sndcore;return t}(sndcore,master,helpers,errorHandler,panner,soundfile,amplitude,fft,signal,oscillator,env,pulse,noise,audioin,filter,delay,reverb,metro,looper,compressor,soundRecorder,peakdetect,gain,distortion)});
+/**
+ * p5.sound
+ * https://p5js.org/reference/#/libraries/p5.sound
+ *
+ * From the Processing Foundation and contributors
+ * https://github.com/processing/p5.js-sound/graphs/contributors
+ *
+ * MIT License (MIT)
+ * https://github.com/processing/p5.js-sound/blob/master/LICENSE
+ *
+ * Some of the many audio libraries & resources that inspire p5.sound:
+ * - TONE.js (c) Yotam Mann. Licensed under The MIT License (MIT). https://github.com/TONEnoTONE/Tone.js
+ * - buzz.js (c) Jay Salvat. Licensed under The MIT License (MIT). http://buzz.jaysalvat.com/
+ * - Boris Smus Web Audio API book, 2013. Licensed under the Apache License http://www.apache.org/licenses/LICENSE-2.0
+ * - wavesurfer.js https://github.com/katspaugh/wavesurfer.js
+ * - Web Audio Components by Jordan Santell https://github.com/web-audio-components
+ * - Wilm Thoben's Sound library for Processing https://github.com/processing/processing/tree/master/java/libraries/sound
+ *
+ * Web Audio API: http://w3.org/TR/webaudio/
+ */
+
+!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"')},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 n();case"wav":return o();case"ogg":return i();case"aac":case"m4a":case"mp4":return s();case"aif":case"aiff":return r();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,s=e.output.gain.value;e.output.gain.cancelScheduledValues(o+n),e.output.gain.linearRampToValueAtTime(s,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-1))throw arguments[e]+" is not a valid sound format!";t.extensions.push(arguments[e])}},p5.prototype.disposeSound=function(){for(var e=0;e-1)if(p5.prototype.isFileSupported(n))i=i;else for(var o=i.split("."),s=o[o.length-1],r=0;r1?(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,s=(t+1)/2,r=Math.cos(s*Math.PI/2),a=Math.sin(s*Math.PI/2);this.left.gain.linearRampToValueAtTime(a,o),this.right.gain.linearRampToValueAtTime(r,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()})}(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 s=t[o],r=new c(s,o);i[o]=r,o+=6e3}o++}return i}function e(t){for(var e=[],i=Object.keys(t).sort(),n=0;no;o++){var s=t[i[n]],r=t[i[n+o]];if(s&&r){var a=s.sampleIndex,u=r.sampleIndex,p=u-a;p>0&&s.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 s=i.some(function(e){return e.tempo===n?e.count+=t.count:void 0});if(!s){if(isNaN(n))return;i.push({tempo:Math.round(n),count:t.count})}}catch(r){throw r}}),i}function n(t,e,i,n){for(var s=[],r=Object.keys(t).sort(),a=0;a.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 s=errorHandler,r=master,a=r.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=r.audiocontext.createGain(),this.output=r.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,r.input,2),(this.url||this.file)&&this.load(e,i),r.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,s=new p5.SoundFile(t,function(){"function"==typeof e&&e.apply(o,arguments),o._decrementPreload()},i,n);return s},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 s("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 r=new s("loadSound",n,i.url),u="Unable to load "+i.url+". The request status was: "+o.status+" ("+o.statusText+")";e?(r.message=u,e(r)):console.error(u+"\n The error stack trace includes: \n"+r.stack)}},o.onerror=function(){var t=new s("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 r=new FileReader;r.onload=function(){a.decodeAudioData(r.result,function(e){i.buffer=e,i.panner.inputChannels(e.numberOfChannels),t&&t(i)})},r.onerror=function(t){onerror&&onerror(t)},r.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 s,a,u=this,p=r.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)),"untildone"!==this.mode||!this.isPlaying()){if(this.bufferSourceNode=this._initSourceNode(),this._counterNode&&(this._counterNode=void 0),this._counterNode=this._initCounterNode(),n){if(!(n>=0&&nt&&!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=r.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,s=new Float32Array(Math.round(t)),r=0;o>r;r++)for(var a=e.getChannelData(r),u=0;t>u;u++){for(var p=~~(u*i),c=~~(p+i),h=0,l=p;c>l;l+=n){var d=a[l];d>h?h=d:-d>h&&(h=d)}(0===r||Math.abs(h)>s[u])&&(s[u]=h)}return s}},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;eo;o++){var s=n.getChannelData(o);s.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=f);var u=e(h),p=i(u,r.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,r.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],s=o.time,r=o.val;this._prevTime=s&&o.callback(r)}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;ea;a++)i=n[a],this.normalize?(s+=Math.max(Math.min(i/this.volMax,1),-1),r+=Math.max(Math.min(i/this.volMax,1),-1)*Math.max(Math.min(i/this.volMax,1),-1)):(s+=i,r+=i*i);var u=s/o,p=Math.sqrt(r/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,s=0;si){var o=i;i=e,e=o}for(var s=Math.round(e/n*this.freqDomain.length),r=Math.round(i/n*this.freqDomain.length),a=0,u=0,p=s;r>=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;or;r++)o[s]=void 0!==o[s]?(o[s]+e[r])/2:e[r],r%n===n-1&&s++;return o},p5.FFT.prototype.logAverages=function(e){for(var i=t.audiocontext.sampleRate/2,n=this.freqDomain,o=n.length,s=new Array(e.length),r=0,a=0;o>a;a++){var u=Math.round(a*i/this.freqDomain.length);u>e[r].hi&&r++,s[r]=void 0!==s[r]?(s[r]+n[a])/2:n[a]}return s},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 s=t.audiocontext.sampleRate/2;o.hi1&&(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 s={};s[e]=i,e=s}for(var r in e){i=e[r];var a=this;if(-1!==r.indexOf(".")){for(var u=r.split("."),p=0;p1)for(var t=arguments[0],e=1;e1)for(var e=1;e0)for(var t=this,e=0;e0)for(var t=0;te;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),s=this.notationToSeconds(n[n.length-1],e,i),r="",a=0;a1-p%1&&(p+=c),p=Math.floor(p),p>0){if(r+=1===p?n[a]:p.toString()+"*"+n[a],o-=p*u,s>o)break;r+=" + "}}return""===r&&(r="0"),r}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),s=0;0===o&&(s=0);var r=t.slice(-1);return s="t"===r?4/o*2/3:"n"===r?4/o:"m"===r?o*i:0,n*s},Tone.prototype.transportTimeToSeconds=function(t,e,i){e=this.defaultArg(e,getTransportBpm()),i=this.defaultArg(i,getTransportTimeSignature());var n=0,o=0,s=0,r=t.split(":");2===r.length?(n=parseFloat(r[0]),o=parseFloat(r[1])):1===r.length?o=parseFloat(r[0]):3===r.length&&(n=parseFloat(r[0]),o=parseFloat(r[1]),s=parseFloat(r[2]));var a=n*i+o+s/4;return a*(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,s=Math.floor(o/i),r=o%1*4;o=Math.floor(o)%i;var a=[s,o,r];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,s=n/o,r=s*Tone.Transport.PPQ;return Math.round(r+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;j0&&(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;in&&(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;n0?this.oscillator.frequency.exponentialRampToValueAtTime(e,n+i+o):this.oscillator.frequency.linearRampToValueAtTime(e,n+i+o),this.phaseAmount&&this.phase(this.phaseAmount)}},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(){var e=t.soundArray.indexOf(this);if(t.soundArray.splice(e,1),this.oscillator){var i=t.audiocontext.currentTime;this.stop(i),this.disconnect(),this.panner=null,this.oscillator=null}this.osc2&&this.osc2.dispose()},p5.Oscillator.prototype.phase=function(e){var i=p5.prototype.map(e,0,1,0,1/this.f),n=t.audiocontext.currentTime;this.phaseAmount=e,this.dNode||(this.dNode=t.audiocontext.createDelay(),this.oscillator.disconnect(),this.oscillator.connect(this.dNode),this.dNode.connect(this.output)),this.dNode.delayTime.setValueAtTime(i,n)};var o=function(t,e,i,n,o){var s=t.oscillator;for(var r in t.mathOps)t.mathOps[r]instanceof o&&(s.disconnect(),t.mathOps[r].dispose(),i=r,i0&&(s=t.mathOps[r-1]),s.disconnect(),s.connect(e),e.connect(n),t.mathOps[i]=e,t};p5.Oscillator.prototype.add=function(t){var i=new e(t),n=this.mathOps.length-1,s=this.output;return o(this,i,n,s,e)},p5.Oscillator.prototype.mult=function(t){var e=new i(t),n=this.mathOps.length-1,s=this.output;return o(this,e,n,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 n(r,a),p=this.mathOps.length-1,c=this.output;return o(this,u,p,c,n)},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_Add,Tone_signal_Multiply,Tone_signal_Scale);var Tone_core_Timeline;Tone_core_Timeline=function(t){"use strict";return t.Timeline=function(){var e=this.optionsObject(arguments,["memory"],t.Timeline.defaults);this._timeline=[],this._toRemove=[],this._iterating=!1,this.memory=e.memory},t.extend(t.Timeline),t.Timeline.defaults={memory:1/0},Object.defineProperty(t.Timeline.prototype,"length",{get:function(){return this._timeline.length}}),t.Timeline.prototype.addEvent=function(t){if(this.isUndef(t.time))throw new Error("events must have a time attribute");if(t.time=this.toSeconds(t.time),this._timeline.length){var e=this._search(t.time);this._timeline.splice(e+1,0,t)}else this._timeline.push(t);if(this.length>this.memory){var i=this.length-this.memory;this._timeline.splice(0,i)}return this},t.Timeline.prototype.removeEvent=function(t){if(this._iterating)this._toRemove.push(t);else{var e=this._timeline.indexOf(t);-1!==e&&this._timeline.splice(e,1)}return this},t.Timeline.prototype.getEvent=function(t){t=this.toSeconds(t);var e=this._search(t);return-1!==e?this._timeline[e]:null},t.Timeline.prototype.getEventAfter=function(t){t=this.toSeconds(t);var e=this._search(t);return e+1=0?this._timeline[e-1]:null},t.Timeline.prototype.cancel=function(t){if(this._timeline.length>1){t=this.toSeconds(t);var e=this._search(t);e>=0?this._timeline=this._timeline.slice(0,e):this._timeline=[]}else 1===this._timeline.length&&this._timeline[0].time>=t&&(this._timeline=[]);return this},t.Timeline.prototype.cancelBefore=function(t){if(this._timeline.length){t=this.toSeconds(t);var e=this._search(t);e>=0&&(this._timeline=this._timeline.slice(e+1))}return this},t.Timeline.prototype._search=function(t){for(var e=0,i=this._timeline.length,n=i;n>=e&&i>e;){var o=Math.floor(e+(n-e)/2),s=this._timeline[o];if(s.time===t){for(var r=o;rt?n=o-1:s.time=n;n++)t(this._timeline[n]);if(this._iterating=!1,this._toRemove.length>0){for(var o=0;o=0&&this._timeline[i].time>=t;)i--;return this._iterate(e,i+1),this},t.Timeline.prototype.forEachAtTime=function(t,e){t=this.toSeconds(t);var i=this._search(t);return-1!==i&&this._iterate(function(i){i.time===t&&e(i)},0,i),this},t.Timeline.prototype.dispose=function(){t.prototype.dispose.call(this),this._timeline=null,this._toRemove=null},t.Timeline}(Tone_core_Tone);var Tone_signal_TimelineSignal;Tone_signal_TimelineSignal=function(t){"use strict";return t.TimelineSignal=function(){var e=this.optionsObject(arguments,["value","units"],t.Signal.defaults);t.Signal.apply(this,e),e.param=this._param,t.Param.call(this,e),this._events=new t.Timeline(10),this._initial=this._fromUnits(this._param.value)},t.extend(t.TimelineSignal,t.Param),t.TimelineSignal.Type={Linear:"linear",Exponential:"exponential",Target:"target",Set:"set"},Object.defineProperty(t.TimelineSignal.prototype,"value",{get:function(){return this._toUnits(this._param.value)},set:function(t){var e=this._fromUnits(t);this._initial=e,this._param.value=e}}),t.TimelineSignal.prototype.setValueAtTime=function(e,i){return e=this._fromUnits(e),i=this.toSeconds(i),this._events.addEvent({type:t.TimelineSignal.Type.Set,value:e,time:i}),this._param.setValueAtTime(e,i),this},t.TimelineSignal.prototype.linearRampToValueAtTime=function(e,i){return e=this._fromUnits(e),i=this.toSeconds(i),this._events.addEvent({type:t.TimelineSignal.Type.Linear,value:e,time:i}),this._param.linearRampToValueAtTime(e,i),this},t.TimelineSignal.prototype.exponentialRampToValueAtTime=function(e,i){return e=this._fromUnits(e),e=Math.max(this._minOutput,e),i=this.toSeconds(i),
+this._events.addEvent({type:t.TimelineSignal.Type.Exponential,value:e,time:i}),this._param.exponentialRampToValueAtTime(e,i),this},t.TimelineSignal.prototype.setTargetAtTime=function(e,i,n){return e=this._fromUnits(e),e=Math.max(this._minOutput,e),n=Math.max(this._minOutput,n),i=this.toSeconds(i),this._events.addEvent({type:t.TimelineSignal.Type.Target,value:e,time:i,constant:n}),this._param.setTargetAtTime(e,i,n),this},t.TimelineSignal.prototype.cancelScheduledValues=function(t){return this._events.cancel(t),this._param.cancelScheduledValues(this.toSeconds(t)),this},t.TimelineSignal.prototype.setRampPoint=function(e){e=this.toSeconds(e);var i=this.getValueAtTime(e),n=this._searchAfter(e);return n&&(this.cancelScheduledValues(e),n.type===t.TimelineSignal.Type.Linear?this.linearRampToValueAtTime(i,e):n.type===t.TimelineSignal.Type.Exponential&&this.exponentialRampToValueAtTime(i,e)),this.setValueAtTime(i,e),this},t.TimelineSignal.prototype.linearRampToValueBetween=function(t,e,i){return this.setRampPoint(e),this.linearRampToValueAtTime(t,i),this},t.TimelineSignal.prototype.exponentialRampToValueBetween=function(t,e,i){return this.setRampPoint(e),this.exponentialRampToValueAtTime(t,i),this},t.TimelineSignal.prototype._searchBefore=function(t){return this._events.getEvent(t)},t.TimelineSignal.prototype._searchAfter=function(t){return this._events.getEventAfter(t)},t.TimelineSignal.prototype.getValueAtTime=function(e){var i=this._searchAfter(e),n=this._searchBefore(e),o=this._initial;if(null===n)o=this._initial;else if(n.type===t.TimelineSignal.Type.Target){var s,r=this._events.getEventBefore(n.time);s=null===r?this._initial:r.value,o=this._exponentialApproach(n.time,s,n.value,n.constant,e)}else o=null===i?n.value:i.type===t.TimelineSignal.Type.Linear?this._linearInterpolate(n.time,n.value,i.time,i.value,e):i.type===t.TimelineSignal.Type.Exponential?this._exponentialInterpolate(n.time,n.value,i.time,i.value,e):n.value;return o},t.TimelineSignal.prototype.connect=t.SignalBase.prototype.connect,t.TimelineSignal.prototype._exponentialApproach=function(t,e,i,n,o){return i+(e-i)*Math.exp(-(o-t)/n)},t.TimelineSignal.prototype._linearInterpolate=function(t,e,i,n,o){return e+(n-e)*((o-t)/(i-t))},t.TimelineSignal.prototype._exponentialInterpolate=function(t,e,i,n,o){return e=Math.max(this._minOutput,e),e*Math.pow(n/e,(o-t)/(i-t))},t.TimelineSignal.prototype.dispose=function(){t.Signal.prototype.dispose.call(this),t.Param.prototype.dispose.call(this),this._events.dispose(),this._events=null},t.TimelineSignal}(Tone_core_Tone,Tone_signal_Signal);var env;env=function(){var t=master,e=Tone_signal_Add,i=Tone_signal_Multiply,n=Tone_signal_Scale,o=Tone_signal_TimelineSignal,s=Tone_core_Tone;s.setContext(t.audiocontext),p5.Env=function(e,i,n,s,r,a){this.aTime=e||.1,this.aLevel=i||1,this.dTime=n||.5,this.dLevel=s||0,this.rTime=r||0,this.rLevel=a||0,this._rampHighPercentage=.98,this._rampLowPercentage=.02,this.output=t.audiocontext.createGain(),this.control=new o,this._init(),this.control.connect(this.output),this.connection=null,this.mathOps=[this.control],this.isExponential=!1,this.sourceToClear=null,this.wasTriggered=!1,t.soundArray.push(this)},p5.Env.prototype._init=function(){var e=t.audiocontext.currentTime,i=e;this.control.setTargetAtTime(1e-5,i,.001),this._setRampAD(this.aTime,this.dTime)},p5.Env.prototype.set=function(t,e,i,n,o,s){this.aTime=t,this.aLevel=e,this.dTime=i||0,this.dLevel=n||0,this.rTime=o||0,this.rLevel=s||0,this._setRampAD(t,i)},p5.Env.prototype.setADSR=function(t,e,i,n){this.aTime=t,this.dTime=e||0,this.sPercent=i||0,this.dLevel="undefined"!=typeof i?i*(this.aLevel-this.rLevel)+this.rLevel:0,this.rTime=n||0,this._setRampAD(t,e)},p5.Env.prototype.setRange=function(t,e){this.aLevel=t||1,this.rLevel=e||0},p5.Env.prototype._setRampAD=function(t,e){this._rampAttackTime=this.checkExpInput(t),this._rampDecayTime=this.checkExpInput(e);var i=1;i=Math.log(1/this.checkExpInput(1-this._rampHighPercentage)),this._rampAttackTC=t/this.checkExpInput(i),i=Math.log(1/this._rampLowPercentage),this._rampDecayTC=e/this.checkExpInput(i)},p5.Env.prototype.setRampPercentages=function(t,e){this._rampHighPercentage=this.checkExpInput(t),this._rampLowPercentage=this.checkExpInput(e);var i=1;i=Math.log(1/this.checkExpInput(1-this._rampHighPercentage)),this._rampAttackTC=this._rampAttackTime/this.checkExpInput(i),i=Math.log(1/this._rampLowPercentage),this._rampDecayTC=this._rampDecayTime/this.checkExpInput(i)},p5.Env.prototype.setInput=function(){for(var t=0;t=t&&(t=1e-8),t},p5.Env.prototype.play=function(t,e,i){var n=e||0,i=i||0;t&&this.connection!==t&&this.connect(t),this.triggerAttack(t,n),this.triggerRelease(t,n+this.aTime+this.dTime+i)},p5.Env.prototype.triggerAttack=function(e,i){var n=t.audiocontext.currentTime,o=i||0,s=n+o;this.lastAttack=s,this.wasTriggered=!0,e&&this.connection!==e&&this.connect(e);var r=this.control.getValueAtTime(s);this.isExponential===!0?this.control.exponentialRampToValueAtTime(this.checkExpInput(r),s):this.control.linearRampToValueAtTime(r,s),s+=this.aTime,this.isExponential===!0?(this.control.exponentialRampToValueAtTime(this.checkExpInput(this.aLevel),s),r=this.checkExpInput(this.control.getValueAtTime(s)),this.control.cancelScheduledValues(s),this.control.exponentialRampToValueAtTime(r,s)):(this.control.linearRampToValueAtTime(this.aLevel,s),r=this.control.getValueAtTime(s),this.control.cancelScheduledValues(s),this.control.linearRampToValueAtTime(r,s)),s+=this.dTime,this.isExponential===!0?(this.control.exponentialRampToValueAtTime(this.checkExpInput(this.dLevel),s),r=this.checkExpInput(this.control.getValueAtTime(s)),this.control.cancelScheduledValues(s),this.control.exponentialRampToValueAtTime(r,s)):(this.control.linearRampToValueAtTime(this.dLevel,s),r=this.control.getValueAtTime(s),this.control.cancelScheduledValues(s),this.control.linearRampToValueAtTime(r,s))},p5.Env.prototype.triggerRelease=function(e,i){if(this.wasTriggered){var n=t.audiocontext.currentTime,o=i||0,s=n+o;e&&this.connection!==e&&this.connect(e);var r=this.control.getValueAtTime(s);this.isExponential===!0?this.control.exponentialRampToValueAtTime(this.checkExpInput(r),s):this.control.linearRampToValueAtTime(r,s),s+=this.rTime,this.isExponential===!0?(this.control.exponentialRampToValueAtTime(this.checkExpInput(this.rLevel),s),r=this.checkExpInput(this.control.getValueAtTime(s)),this.control.cancelScheduledValues(s),this.control.exponentialRampToValueAtTime(r,s)):(this.control.linearRampToValueAtTime(this.rLevel,s),r=this.control.getValueAtTime(s),this.control.cancelScheduledValues(s),this.control.linearRampToValueAtTime(r,s)),this.wasTriggered=!1}},p5.Env.prototype.ramp=function(e,i,n,o){var s=t.audiocontext.currentTime,r=i||0,a=s+r,u=this.checkExpInput(n),p="undefined"!=typeof o?this.checkExpInput(o):void 0;e&&this.connection!==e&&this.connect(e);var c=this.checkExpInput(this.control.getValueAtTime(a));u>c?(this.control.setTargetAtTime(u,a,this._rampAttackTC),a+=this._rampAttackTime):c>u&&(this.control.setTargetAtTime(u,a,this._rampDecayTC),a+=this._rampDecayTime),void 0!==p&&(p>u?this.control.setTargetAtTime(p,a,this._rampAttackTC):u>p&&this.control.setTargetAtTime(p,a,this._rampDecayTC))},p5.Env.prototype.connect=function(e){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),n=this.mathOps.length,o=this.output;return p5.prototype._mathChain(this,i,n,o,e)},p5.Env.prototype.mult=function(t){var e=new i(t),n=this.mathOps.length,o=this.output;return p5.prototype._mathChain(this,e,n,o,i)},p5.Env.prototype.scale=function(t,e,i,o){var s=new n(t,e,i,o),r=this.mathOps.length,a=this.output;return p5.prototype._mathChain(this,s,r,a,n)},p5.Env.prototype.dispose=function(){var e=t.soundArray.indexOf(this);t.soundArray.splice(e,1),this.disconnect();try{this.control.dispose(),this.control=null}catch(i){console.warn(i,"already disposed p5.Env")}for(var n=1;no;o++)n[o]=1;var s=t.createBufferSource();return s.buffer=i,s.loop=!0,s}var e=master;p5.Pulse=function(i,n){p5.Oscillator.call(this,i,"sawtooth"),this.w=n||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 o=this.w/this.oscillator.frequency.value;this.dNode.delayTime.value=o,this.dcGain.gain.value=1.7*(.5-this.w),this.osc2.disconnect(),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,n){var o=e.audiocontext.currentTime,s=n||0;if(!this.started){var r=i||this.f,a=this.oscillator.type;this.oscillator=e.audiocontext.createOscillator(),this.oscillator.frequency.setValueAtTime(r,o),this.oscillator.type=a,this.oscillator.connect(this.output),this.oscillator.start(s+o),this.osc2.oscillator=e.audiocontext.createOscillator(),this.osc2.oscillator.frequency.setValueAtTime(r,s+o),this.osc2.oscillator.type=a,this.osc2.oscillator.connect(this.osc2.output),this.osc2.start(s+o),this.freqNode=[this.oscillator.frequency,this.osc2.oscillator.frequency],this.dcOffset=t(),this.dcOffset.connect(this.dcGain),this.dcOffset.start(s+o),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,n=e.audiocontext.currentTime;this.oscillator.stop(i+n),this.osc2.oscillator.stop(i+n),this.dcOffset.stop(i+n),this.started=!1,this.osc2.started=!1}},p5.Pulse.prototype.freq=function(t,i,n){if("number"==typeof t){this.f=t;var o=e.audiocontext.currentTime,i=i||0,n=n||0,s=this.oscillator.frequency.value;this.oscillator.frequency.cancelScheduledValues(o),this.oscillator.frequency.setValueAtTime(s,o+n),this.oscillator.frequency.exponentialRampToValueAtTime(t,n+i+o),this.osc2.oscillator.frequency.cancelScheduledValues(o),this.osc2.oscillator.frequency.setValueAtTime(s,o+n),this.osc2.oscillator.frequency.exponentialRampToValueAtTime(t,n+i+o),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(){var t=master;p5.Noise=function(t){var o;p5.Oscillator.call(this),delete this.f,delete this.freq,delete this.oscillator,o="brown"===t?n:"pink"===t?i:e,this.buffer=o},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),n=i.getChannelData(0),o=0;e>o;o++)n[o]=2*Math.random()-1;return i.type="white",i}(),i=function(){var e,i,n,o,s,r,a,u=2*t.audiocontext.sampleRate,p=t.audiocontext.createBuffer(1,u,t.audiocontext.sampleRate),c=p.getChannelData(0);e=i=n=o=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,n=.969*n+.153852*l,o=.8665*o+.3104856*l,s=.55*s+.5329522*l,r=-.7616*r-.016898*l,c[h]=e+i+n+o+s+r+a+.5362*l,c[h]*=.11,a=.115926*l}return p.type="pink",p}(),n=function(){for(var e=2*t.audiocontext.sampleRate,i=t.audiocontext.createBuffer(1,e,t.audiocontext.sampleRate),n=i.getChannelData(0),o=0,s=0;e>s;s++){var r=2*Math.random()-1;n[s]=(o+.02*r)/1.02,o=n[s],n[s]*=3.5}return i.type="brown",i}();p5.Noise.prototype.setType=function(o){switch(o){case"white":this.buffer=e;break;case"pink":this.buffer=i;break;case"brown":this.buffer=n;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,i=t.soundArray.indexOf(this);t.soundArray.splice(i,1),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(){var t=master;p5.AudioIn=function(e){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?e?e():window.alert("This browser does not support AudioIn"):"function"==typeof window.MediaDevices.enumerateDevices&&window.MediaDevices.enumerateDevices(this._gotSources),t.soundArray.push(this)},p5.AudioIn.prototype.start=function(e,i){var n=this;if(t.inputSources[n.currentSource]){var o=t.inputSources[n.currentSource].id,s={audio:{optional:[{sourceId:o}]}};window.navigator.getUserMedia(s,this._onStream=function(i){n.stream=i,n.enabled=!0,n.mediaStream=t.audiocontext.createMediaStreamSource(i),n.mediaStream.connect(n.output),e&&e(),n.amplitude.setInput(n.output)},this._onStreamError=function(t){i?i(t):console.error(t)})}else window.navigator.getUserMedia({audio:!0},this._onStream=function(i){n.stream=i,n.enabled=!0,n.mediaStream=t.audiocontext.createMediaStreamSource(i),n.mediaStream.connect(n.output),n.amplitude.setInput(n.output),e&&e()},this._onStreamError=function(t){i?i(t):console.error(t)})},p5.AudioIn.prototype.stop=function(){this.stream&&this.stream.getTracks()[0].stop()},p5.AudioIn.prototype.connect=function(e){e?e.hasOwnProperty("input")?this.output.connect(e.input):e.hasOwnProperty("analyser")?this.output.connect(e.analyser):this.output.connect(e):this.output.connect(t.input)},p5.AudioIn.prototype.disconnect=function(){this.output.disconnect(),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(t){for(var e=0;e0?t.inputSources:"This browser does not support MediaStreamTrack.getSources()"},p5.AudioIn.prototype.getSources=function(e){"function"==typeof window.MediaStreamTrack.getSources?window.MediaStreamTrack.getSources(function(i){for(var n=0,o=i.length;o>n;n++){var s=i[n];"audio"===s.kind&&t.inputSources.push(s)}e(t.inputSources)}):console.log("This browser does not support MediaStreamTrack.getSources()")},p5.AudioIn.prototype.setSource=function(e){var i=this;t.inputSources.length>0&&e=t?0:1}),this._scale=this.input=new t.Multiply(1e4),this._scale.connect(this._thresh)},t.extend(t.GreaterThanZero,t.SignalBase),t.GreaterThanZero.prototype.dispose=function(){return t.prototype.dispose.call(this),this._scale.dispose(),this._scale=null,this._thresh.dispose(),this._thresh=null,this},t.GreaterThanZero}(Tone_core_Tone,Tone_signal_Signal,Tone_signal_Multiply);var Tone_signal_EqualZero;Tone_signal_EqualZero=function(t){"use strict";return t.EqualZero=function(){this._scale=this.input=new t.Multiply(1e4),this._thresh=new t.WaveShaper(function(t){return 0===t?1:0},128),this._gtz=this.output=new t.GreaterThanZero,this._scale.chain(this._thresh,this._gtz)},t.extend(t.EqualZero,t.SignalBase),t.EqualZero.prototype.dispose=function(){return t.prototype.dispose.call(this),this._gtz.dispose(),this._gtz=null,this._scale.dispose(),this._scale=null,this._thresh.dispose(),this._thresh=null,this},t.EqualZero}(Tone_core_Tone,Tone_signal_Signal,Tone_signal_GreaterThanZero);var Tone_signal_Equal;Tone_signal_Equal=function(t){"use strict";return t.Equal=function(e){t.call(this,2,0),this._sub=this.input[0]=new t.Subtract(e),this._equals=this.output=new t.EqualZero,this._sub.connect(this._equals),this.input[1]=this._sub.input[1]},t.extend(t.Equal,t.SignalBase),Object.defineProperty(t.Equal.prototype,"value",{get:function(){return this._sub.value},set:function(t){this._sub.value=t}}),t.Equal.prototype.dispose=function(){return t.prototype.dispose.call(this),this._equals.dispose(),this._equals=null,this._sub.dispose(),this._sub=null,this},t.Equal}(Tone_core_Tone,Tone_signal_EqualZero,Tone_signal_Subtract);var Tone_signal_Select;Tone_signal_Select=function(t){"use strict";t.Select=function(i){i=this.defaultArg(i,2),t.call(this,i,1),this.gate=new t.Signal(0),this._readOnly("gate");for(var n=0;i>n;n++){var o=new e(n);this.input[n]=o,this.gate.connect(o.selecter),o.connect(this.output)}},t.extend(t.Select,t.SignalBase),t.Select.prototype.select=function(t,e){return t=Math.floor(t),this.gate.setValueAtTime(t,this.toSeconds(e)),this},t.Select.prototype.dispose=function(){this._writable("gate"),this.gate.dispose(),this.gate=null;for(var e=0;ei;i++)this.input[i]=this._sum;this._sum.connect(this._gtz)},t.extend(t.OR,t.SignalBase),t.OR.prototype.dispose=function(){return t.prototype.dispose.call(this),this._gtz.dispose(),this._gtz=null,this._sum.disconnect(),this._sum=null,this},t.OR}(Tone_core_Tone);var Tone_signal_AND;Tone_signal_AND=function(t){"use strict";return t.AND=function(e){e=this.defaultArg(e,2),t.call(this,e,0),this._equals=this.output=new t.Equal(e);for(var i=0;e>i;i++)this.input[i]=this._equals},t.extend(t.AND,t.SignalBase),t.AND.prototype.dispose=function(){return t.prototype.dispose.call(this),this._equals.dispose(),this._equals=null,this},t.AND}(Tone_core_Tone);var Tone_signal_NOT;Tone_signal_NOT=function(t){"use strict";return t.NOT=t.EqualZero,t.NOT}(Tone_core_Tone);var Tone_signal_GreaterThan;Tone_signal_GreaterThan=function(t){"use strict";return t.GreaterThan=function(e){t.call(this,2,0),this._param=this.input[0]=new t.Subtract(e),this.input[1]=this._param.input[1],this._gtz=this.output=new t.GreaterThanZero,this._param.connect(this._gtz)},t.extend(t.GreaterThan,t.Signal),t.GreaterThan.prototype.dispose=function(){return t.prototype.dispose.call(this),this._param.dispose(),this._param=null,this._gtz.dispose(),this._gtz=null,this},t.GreaterThan}(Tone_core_Tone,Tone_signal_GreaterThanZero,Tone_signal_Subtract);var Tone_signal_LessThan;Tone_signal_LessThan=function(t){"use strict";return t.LessThan=function(e){t.call(this,2,0),this._neg=this.input[0]=new t.Negate,this._gt=this.output=new t.GreaterThan,this._rhNeg=new t.Negate,this._param=this.input[1]=new t.Signal(e),this._neg.connect(this._gt),this._param.connect(this._rhNeg),this._rhNeg.connect(this._gt,0,1)},t.extend(t.LessThan,t.Signal),t.LessThan.prototype.dispose=function(){return t.prototype.dispose.call(this),this._neg.dispose(),this._neg=null,this._gt.dispose(),this._gt=null,this._rhNeg.dispose(),this._rhNeg=null,this._param.dispose(),this._param=null,this},t.LessThan}(Tone_core_Tone,Tone_signal_GreaterThan,Tone_signal_Negate);var Tone_signal_Abs;Tone_signal_Abs=function(t){"use strict";return t.Abs=function(){t.call(this,1,0),this._ltz=new t.LessThan(0),this._switch=this.output=new t.Select(2),this._negate=new t.Negate,this.input.connect(this._switch,0,0),this.input.connect(this._negate),this._negate.connect(this._switch,0,1),this.input.chain(this._ltz,this._switch.gate)},t.extend(t.Abs,t.SignalBase),t.Abs.prototype.dispose=function(){return t.prototype.dispose.call(this),this._switch.dispose(),this._switch=null,this._ltz.dispose(),this._ltz=null,this._negate.dispose(),this._negate=null,this},t.Abs}(Tone_core_Tone,Tone_signal_Select,Tone_signal_Negate,Tone_signal_LessThan);var Tone_signal_Max;Tone_signal_Max=function(t){"use strict";return t.Max=function(e){t.call(this,2,0),this.input[0]=this.context.createGain(),this._param=this.input[1]=new t.Signal(e),this._ifThenElse=this.output=new t.IfThenElse,this._gt=new t.GreaterThan,this.input[0].chain(this._gt,this._ifThenElse["if"]),this.input[0].connect(this._ifThenElse.then),this._param.connect(this._ifThenElse["else"]),this._param.connect(this._gt,0,1)},t.extend(t.Max,t.Signal),t.Max.prototype.dispose=function(){return t.prototype.dispose.call(this),this._param.dispose(),this._ifThenElse.dispose(),this._gt.dispose(),this._param=null,this._ifThenElse=null,this._gt=null,this},t.Max}(Tone_core_Tone,Tone_signal_GreaterThan,Tone_signal_IfThenElse);var Tone_signal_Min;Tone_signal_Min=function(t){"use strict";return t.Min=function(e){t.call(this,2,0),this.input[0]=this.context.createGain(),this._ifThenElse=this.output=new t.IfThenElse,this._lt=new t.LessThan,this._param=this.input[1]=new t.Signal(e),this.input[0].chain(this._lt,this._ifThenElse["if"]),this.input[0].connect(this._ifThenElse.then),this._param.connect(this._ifThenElse["else"]),this._param.connect(this._lt,0,1)},t.extend(t.Min,t.Signal),t.Min.prototype.dispose=function(){return t.prototype.dispose.call(this),this._param.dispose(),this._ifThenElse.dispose(),this._lt.dispose(),this._param=null,this._ifThenElse=null,this._lt=null,this},t.Min}(Tone_core_Tone,Tone_signal_LessThan,Tone_signal_IfThenElse);var Tone_signal_Modulo;Tone_signal_Modulo=function(t){"use strict";return t.Modulo=function(e){t.call(this,1,1),this._shaper=new t.WaveShaper(Math.pow(2,16)),this._multiply=new t.Multiply,this._subtract=this.output=new t.Subtract,this._modSignal=new t.Signal(e),this.input.fan(this._shaper,this._subtract),this._modSignal.connect(this._multiply,0,0),this._shaper.connect(this._multiply,0,1),this._multiply.connect(this._subtract,0,1),this._setWaveShaper(e)},t.extend(t.Modulo,t.SignalBase),t.Modulo.prototype._setWaveShaper=function(t){this._shaper.setMap(function(e){var i=Math.floor((e+1e-4)/t);return i})},Object.defineProperty(t.Modulo.prototype,"value",{get:function(){return this._modSignal.value},set:function(t){this._modSignal.value=t,this._setWaveShaper(t)}}),t.Modulo.prototype.dispose=function(){return t.prototype.dispose.call(this),this._shaper.dispose(),this._shaper=null,this._multiply.dispose(),this._multiply=null,this._subtract.dispose(),this._subtract=null,this._modSignal.dispose(),this._modSignal=null,this},t.Modulo}(Tone_core_Tone,Tone_signal_WaveShaper,Tone_signal_Multiply);var Tone_signal_Pow;Tone_signal_Pow=function(t){"use strict";return t.Pow=function(e){this._exp=this.defaultArg(e,1),this._expScaler=this.input=this.output=new t.WaveShaper(this._expFunc(this._exp),8192)},t.extend(t.Pow,t.SignalBase),Object.defineProperty(t.Pow.prototype,"value",{get:function(){return this._exp},set:function(t){this._exp=t,this._expScaler.setMap(this._expFunc(this._exp))}}),t.Pow.prototype._expFunc=function(t){return function(e){return Math.pow(Math.abs(e),t)}},t.Pow.prototype.dispose=function(){return t.prototype.dispose.call(this),this._expScaler.dispose(),this._expScaler=null,this},t.Pow}(Tone_core_Tone);var Tone_signal_AudioToGain;Tone_signal_AudioToGain=function(t){"use strict";return t.AudioToGain=function(){this._norm=this.input=this.output=new t.WaveShaper(function(t){return(t+1)/2})},t.extend(t.AudioToGain,t.SignalBase),t.AudioToGain.prototype.dispose=function(){return t.prototype.dispose.call(this),this._norm.dispose(),this._norm=null,this},t.AudioToGain}(Tone_core_Tone,Tone_signal_WaveShaper);var Tone_signal_Expr;Tone_signal_Expr=function(t){"use strict";function e(t,e,i){var n=new t;return i._eval(e[0]).connect(n,0,0),i._eval(e[1]).connect(n,0,1),n}function i(t,e,i){var n=new t;return i._eval(e[0]).connect(n,0,0),n}function n(t){return t?parseFloat(t):void 0}function o(t){return t&&t.args?parseFloat(t.args):void 0}return t.Expr=function(){var t=this._replacements(Array.prototype.slice.call(arguments)),e=this._parseInputs(t);this._nodes=[],this.input=new Array(e);for(var i=0;e>i;i++)this.input[i]=this.context.createGain();var n,o=this._parseTree(t);try{n=this._eval(o)}catch(s){throw this._disposeNodes(),new Error("Could evaluate expression: "+t)}this.output=n},t.extend(t.Expr,t.SignalBase),t.Expr._Expressions={value:{signal:{regexp:/^\d+\.\d+|^\d+/,method:function(e){var i=new t.Signal(n(e));return i}},input:{regexp:/^\$\d/,method:function(t,e){return e.input[n(t.substr(1))]}}},glue:{"(":{regexp:/^\(/},")":{regexp:/^\)/},",":{regexp:/^,/}},func:{abs:{regexp:/^abs/,method:i.bind(this,t.Abs)},min:{regexp:/^min/,method:e.bind(this,t.Min)},max:{regexp:/^max/,method:e.bind(this,t.Max)},"if":{regexp:/^if/,method:function(e,i){var n=new t.IfThenElse;return i._eval(e[0]).connect(n["if"]),i._eval(e[1]).connect(n.then),i._eval(e[2]).connect(n["else"]),n}},gt0:{regexp:/^gt0/,method:i.bind(this,t.GreaterThanZero)},eq0:{regexp:/^eq0/,method:i.bind(this,t.EqualZero)},mod:{regexp:/^mod/,method:function(e,i){var n=o(e[1]),s=new t.Modulo(n);return i._eval(e[0]).connect(s),s}},pow:{regexp:/^pow/,method:function(e,i){var n=o(e[1]),s=new t.Pow(n);return i._eval(e[0]).connect(s),s}},a2g:{regexp:/^a2g/,method:function(e,i){var n=new t.AudioToGain;return i._eval(e[0]).connect(n),n}}},binary:{"+":{regexp:/^\+/,precedence:1,method:e.bind(this,t.Add)},"-":{regexp:/^\-/,precedence:1,method:function(n,o){return 1===n.length?i(t.Negate,n,o):e(t.Subtract,n,o)}},"*":{regexp:/^\*/,precedence:0,method:e.bind(this,t.Multiply)},">":{regexp:/^\>/,precedence:2,method:e.bind(this,t.GreaterThan)},"<":{regexp:/^,precedence:2,method:e.bind(this,t.LessThan)},"==":{regexp:/^==/,precedence:3,method:e.bind(this,t.Equal)},"&&":{regexp:/^&&/,precedence:4,method:e.bind(this,t.AND)},"||":{regexp:/^\|\|/,precedence:5,method:e.bind(this,t.OR)}},unary:{"-":{regexp:/^\-/,method:i.bind(this,t.Negate)},"!":{regexp:/^\!/,method:i.bind(this,t.NOT)}}},t.Expr.prototype._parseInputs=function(t){var e=t.match(/\$\d/g),i=0;if(null!==e)for(var n=0;n0;){e=e.trim();var s=i(e);o.push(s),e=e.substr(s.value.length)}return{next:function(){return o[++n]},peek:function(){return o[n+1]}}},t.Expr.prototype._parseTree=function(e){function i(t,e){return!c(t)&&"glue"===t.type&&t.value===e}function n(e,i,n){var o=!1,s=t.Expr._Expressions[i];if(!c(e))for(var r in s){var a=s[r];if(a.regexp.test(e.value)){if(c(n))return!0;if(a.precedence===n)return!0}}return o}function o(t){c(t)&&(t=5);var e;e=0>t?s():o(t-1);for(var i=p.peek();n(i,"binary",t);)i=p.next(),e={operator:i.value,method:i.method,args:[e,o(t)]},i=p.peek();return e}function s(){var t,e;return t=p.peek(),n(t,"unary")?(t=p.next(),e=s(),{operator:t.value,method:t.method,args:[e]}):r()}function r(){var t,e;if(t=p.peek(),c(t))throw new SyntaxError("Unexpected termination of expression");if("func"===t.type)return t=p.next(),a(t);if("value"===t.type)return t=p.next(),{method:t.method,args:t.value};if(i(t,"(")){if(p.next(),e=o(),t=p.next(),!i(t,")"))throw new SyntaxError("Expected )");return e}throw new SyntaxError("Parse error, cannot process token "+t.value)}function a(t){var e,n=[];if(e=p.next(),!i(e,"("))throw new SyntaxError('Expected ( in a function call "'+t.value+'"');if(e=p.peek(),i(e,")")||(n=u()),
+e=p.next(),!i(e,")"))throw new SyntaxError('Expected ) in a function call "'+t.value+'"');return{method:t.method,args:n,name:name}}function u(){for(var t,e,n=[];;){if(e=o(),c(e))break;if(n.push(e),t=p.peek(),!i(t,","))break;p.next()}return n}var p=this._tokenize(e),c=this.isUndef.bind(this);return o()},t.Expr.prototype._eval=function(t){if(!this.isUndef(t)){var e=t.method(t.args,this);return this._nodes.push(e),e}},t.Expr.prototype._disposeNodes=function(){for(var t=0;t0){this.connect(arguments[0]);for(var t=1;t=t&&(t=1),"number"==typeof t?(this.biquad.frequency.value=t,this.biquad.frequency.cancelScheduledValues(this.ac.currentTime+.01+i),this.biquad.frequency.exponentialRampToValueAtTime(t,this.ac.currentTime+.02+i)):t&&t.connect(this.biquad.frequency),this.biquad.frequency.value},p5.Filter.prototype.res=function(t,e){var i=e||0;return"number"==typeof t?(this.biquad.Q.value=t,this.biquad.Q.cancelScheduledValues(this.ac.currentTime+.01+i),this.biquad.Q.linearRampToValueAtTime(t,this.ac.currentTime+.02+i)):t&&t.connect(this.biquad.Q),this.biquad.Q.value},p5.Filter.prototype.gain=function(t,e){var i=e||0;return"number"==typeof t?(this.biquad.gain.value=t,this.biquad.gain.cancelScheduledValues(this.ac.currentTime+.01+i),this.biquad.gain.linearRampToValueAtTime(t,this.ac.currentTime+.02+i)):t&&t.connect(this.biquad.gain),this.biquad.gain.value},p5.Filter.prototype.toggle=function(){return this._on=!this._on,this._on===!0?this.biquad.type=this._untoggledType:this._on===!1&&(this.biquad.type="allpass"),this._on},p5.Filter.prototype.setType=function(t){this.biquad.type=t,this._untoggledType=this.biquad.type},p5.Filter.prototype.dispose=function(){t.prototype.dispose.apply(this),this.biquad.disconnect(),this.biquad=void 0},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),p5.Filter}(master,effect);var src_eqFilter;src_eqFilter=function(){var t=filter,e=master,i=function(e,i){t.call(this,"peaking"),this.disconnect(),this.set(e,i),this.biquad.gain.value=0,delete this.input,delete this.output,delete this._drywet,delete this.wet};return i.prototype=Object.create(t.prototype),i.prototype.amp=function(){console.warn("`amp()` is not available for p5.EQ bands. Use `.gain()`")},i.prototype.drywet=function(){console.warn("`drywet()` is not available for p5.EQ bands.")},i.prototype.connect=function(t){var e=t||p5.soundOut.input;this.biquad?this.biquad.connect(e.input?e.input:e):this.output.connect(e.input?e.input:e)},i.prototype.disconnect=function(){this.biquad.disconnect()},i.prototype.dispose=function(){var t=e.soundArray.indexOf(this);e.soundArray.splice(t,1),this.disconnect(),delete this.biquad},i}(filter,master);var eq;eq=function(){var t=effect,e=src_eqFilter;return p5.EQ=function(e){t.call(this),e=3===e||8===e?e:3;var i;i=3===e?Math.pow(2,3):2,this.bands=[];for(var n,o,s=0;e>s;s++)s===e-1?(n=21e3,o=.01):0===s?(n=100,o=.1):1===s?(n=3===e?360*i:360,o=1):(n=this.bands[s-1].freq()*i,o=1),this.bands[s]=this._newBand(n,o),s>0?this.bands[s-1].connect(this.bands[s].biquad):this.input.connect(this.bands[s].biquad);this.bands[e-1].connect(this.output)},p5.EQ.prototype=Object.create(t.prototype),p5.EQ.prototype.process=function(t){t.connect(this.input)},p5.EQ.prototype.set=function(){if(arguments.length===2*this.bands.length)for(var t=0;t0;)delete this.bands.pop().dispose();delete this.bands},p5.EQ}(effect,src_eqFilter);var panner3d;panner3d=function(){var t=effect;return p5.Panner3D=function(){t.call(this),this.panner=this.ac.createPanner(),this.panner.panningModel="HRTF",this.panner.distanceModel="linear",this.panner.connect(this.output),this.input.connect(this.panner)},p5.Panner3D.prototype=Object.create(t.prototype),p5.Panner3D.prototype.process=function(t){t.connect(this.input)},p5.Panner3D.prototype.set=function(t,e,i,n){return this.positionX(t,n),this.positionY(e,n),this.positionZ(i,n),[this.panner.positionX.value,this.panner.positionY.value,this.panner.positionZ.value]},p5.Panner3D.prototype.positionX=function(t,e){var i=e||0;return"number"==typeof t?(this.panner.positionX.value=t,this.panner.positionX.cancelScheduledValues(this.ac.currentTime+.01+i),this.panner.positionX.linearRampToValueAtTime(t,this.ac.currentTime+.02+i)):t&&t.connect(this.panner.positionX),this.panner.positionX.value},p5.Panner3D.prototype.positionY=function(t,e){var i=e||0;return"number"==typeof t?(this.panner.positionY.value=t,this.panner.positionY.cancelScheduledValues(this.ac.currentTime+.01+i),this.panner.positionY.linearRampToValueAtTime(t,this.ac.currentTime+.02+i)):t&&t.connect(this.panner.positionY),this.panner.positionY.value},p5.Panner3D.prototype.positionZ=function(t,e){var i=e||0;return"number"==typeof t?(this.panner.positionZ.value=t,this.panner.positionZ.cancelScheduledValues(this.ac.currentTime+.01+i),this.panner.positionZ.linearRampToValueAtTime(t,this.ac.currentTime+.02+i)):t&&t.connect(this.panner.positionZ),this.panner.positionZ.value},p5.Panner3D.prototype.orient=function(t,e,i,n){return this.orientX(t,n),this.orientY(e,n),this.orientZ(i,n),[this.panner.orientationX.value,this.panner.orientationY.value,this.panner.orientationZ.value]},p5.Panner3D.prototype.orientX=function(t,e){var i=e||0;return"number"==typeof t?(this.panner.orientationX.value=t,this.panner.orientationX.cancelScheduledValues(this.ac.currentTime+.01+i),this.panner.orientationX.linearRampToValueAtTime(t,this.ac.currentTime+.02+i)):t&&t.connect(this.panner.orientationX),this.panner.orientationX.value},p5.Panner3D.prototype.orientY=function(t,e){var i=e||0;return"number"==typeof t?(this.panner.orientationY.value=t,this.panner.orientationY.cancelScheduledValues(this.ac.currentTime+.01+i),this.panner.orientationY.linearRampToValueAtTime(t,this.ac.currentTime+.02+i)):t&&t.connect(this.panner.orientationY),this.panner.orientationY.value},p5.Panner3D.prototype.orientZ=function(t,e){var i=e||0;return"number"==typeof t?(this.panner.orientationZ.value=t,this.panner.orientationZ.cancelScheduledValues(this.ac.currentTime+.01+i),this.panner.orientationZ.linearRampToValueAtTime(t,this.ac.currentTime+.02+i)):t&&t.connect(this.panner.orientationZ),this.panner.orientationZ.value},p5.Panner3D.prototype.setFalloff=function(t,e){this.maxDist(t),this.rolloff(e)},p5.Panner3D.prototype.maxDist=function(t){return"number"==typeof t&&(this.panner.maxDistance=t),this.panner.maxDistance},p5.Panner3D.prototype.rolloff=function(t){return"number"==typeof t&&(this.panner.rolloffFactor=t),this.panner.rolloffFactor},p5.Panner3D.dispose=function(){t.prototype.dispose.apply(this),this.panner.disconnect(),delete this.panner},p5.Panner3D}(master,effect);var listener3d;listener3d=function(){var t=master;return p5.Listener3D=function(e){this.ac=t.audiocontext,this.listener=this.ac.listener},p5.Listener3D.prototype.process=function(t){t.connect(this.input)},p5.Listener3D.prototype.position=function(t,e,i,n){return this.positionX(t,n),this.positionY(e,n),this.positionZ(i,n),[this.listener.positionX.value,this.listener.positionY.value,this.listener.positionZ.value]},p5.Listener3D.prototype.positionX=function(t,e){var i=e||0;return"number"==typeof t?(this.listener.positionX.value=t,this.listener.positionX.cancelScheduledValues(this.ac.currentTime+.01+i),this.listener.positionX.linearRampToValueAtTime(t,this.ac.currentTime+.02+i)):t&&t.connect(this.listener.positionX),this.listener.positionX.value},p5.Listener3D.prototype.positionY=function(t,e){var i=e||0;return"number"==typeof t?(this.listener.positionY.value=t,this.listener.positionY.cancelScheduledValues(this.ac.currentTime+.01+i),this.listener.positionY.linearRampToValueAtTime(t,this.ac.currentTime+.02+i)):t&&t.connect(this.listener.positionY),this.listener.positionY.value},p5.Listener3D.prototype.positionZ=function(t,e){var i=e||0;return"number"==typeof t?(this.listener.positionZ.value=t,this.listener.positionZ.cancelScheduledValues(this.ac.currentTime+.01+i),this.listener.positionZ.linearRampToValueAtTime(t,this.ac.currentTime+.02+i)):t&&t.connect(this.listener.positionZ),this.listener.positionZ.value},p5.Listener3D.prototype.orient=function(t,e,i,n,o,s,r){return 3===arguments.length||4===arguments.length?(r=arguments[3],this.orientForward(t,e,i,r)):(6===arguments.length||7===arguments)&&(this.orientForward(t,e,i),this.orientUp(n,o,s,r)),[this.listener.forwardX.value,this.listener.forwardY.value,this.listener.forwardZ.value,this.listener.upX.value,this.listener.upY.value,this.listener.upZ.value]},p5.Listener3D.prototype.orientForward=function(t,e,i,n){return this.forwardX(t,n),this.forwardY(e,n),this.forwardZ(i,n),[this.listener.forwardX,this.listener.forwardY,this.listener.forwardZ]},p5.Listener3D.prototype.orientUp=function(t,e,i,n){return this.upX(t,n),this.upY(e,n),this.upZ(i,n),[this.listener.upX,this.listener.upY,this.listener.upZ]},p5.Listener3D.prototype.forwardX=function(t,e){var i=e||0;return"number"==typeof t?(this.listener.forwardX.value=t,this.listener.forwardX.cancelScheduledValues(this.ac.currentTime+.01+i),this.listener.forwardX.linearRampToValueAtTime(t,this.ac.currentTime+.02+i)):t&&t.connect(this.listener.forwardX),this.listener.forwardX.value},p5.Listener3D.prototype.forwardY=function(t,e){var i=e||0;return"number"==typeof t?(this.listener.forwardY.value=t,this.listener.forwardY.cancelScheduledValues(this.ac.currentTime+.01+i),this.listener.forwardY.linearRampToValueAtTime(t,this.ac.currentTime+.02+i)):t&&t.connect(this.listener.forwardY),this.listener.forwardY.value},p5.Listener3D.prototype.forwardZ=function(t,e){var i=e||0;return"number"==typeof t?(this.listener.forwardZ.value=t,this.listener.forwardZ.cancelScheduledValues(this.ac.currentTime+.01+i),this.listener.forwardZ.linearRampToValueAtTime(t,this.ac.currentTime+.02+i)):t&&t.connect(this.listener.forwardZ),this.listener.forwardZ.value},p5.Listener3D.prototype.upX=function(t,e){var i=e||0;return"number"==typeof t?(this.listener.upX.value=t,this.listener.upX.cancelScheduledValues(this.ac.currentTime+.01+i),this.listener.upX.linearRampToValueAtTime(t,this.ac.currentTime+.02+i)):t&&t.connect(this.listener.upX),this.listener.upX.value},p5.Listener3D.prototype.upY=function(t,e){var i=e||0;return"number"==typeof t?(this.listener.upY.value=t,this.listener.upY.cancelScheduledValues(this.ac.currentTime+.01+i),this.listener.upY.linearRampToValueAtTime(t,this.ac.currentTime+.02+i)):t&&t.connect(this.listener.upY),this.listener.upY.value},p5.Listener3D.prototype.upZ=function(t,e){var i=e||0;return"number"==typeof t?(this.listener.upZ.value=t,this.listener.upZ.cancelScheduledValues(this.ac.currentTime+.01+i),this.listener.upZ.linearRampToValueAtTime(t,this.ac.currentTime+.02+i)):t&&t.connect(this.listener.upZ),this.listener.upZ.value},p5.Listener3D}(master,effect);var delay;delay=function(){var t=filter,e=effect;p5.Delay=function(){e.call(this),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 t,this._rightFilter=new t,this._leftFilter.disconnect(),this._rightFilter.disconnect(),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.wet),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,this.feedback(.5)},p5.Delay.prototype=Object.create(e.prototype),p5.Delay.prototype.process=function(t,e,i,n){var o=i||0,s=e||0;if(o>=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.value=o,this._rightGain.gain.value=o,n&&(this._leftFilter.freq(n),this._rightFilter.freq(n))},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(t&&"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.");"number"==typeof t&&(this._leftGain.gain.value=t,this._rightGain.gain.value=t)}return this._leftGain.gain.value},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._rightFilter.output.connect(this._merge,0,1),this._leftFilter.output.connect(this.leftDelay),this._rightFilter.output.connect(this.rightDelay)}},p5.Delay.prototype.dispose=function(){e.prototype.dispose.apply(this),this._split.disconnect(),this._leftFilter.dispose(),this._rightFilter.dispose(),this._merge.disconnect(),this._leftGain.disconnect(),this._rightGain.disconnect(),this.leftDelay.disconnect(),this.rightDelay.disconnect(),this._split=void 0,this._leftFilter=void 0,this._rightFilter=void 0,this._merge=void 0,this._leftGain=void 0,this._rightGain=void 0,this.leftDelay=void 0,this.rightDelay=void 0}}(filter,effect);var reverb;reverb=function(){var t=errorHandler,e=effect;p5.Reverb=function(){e.call(this),this.convolverNode=this.ac.createConvolver(),this.input.gain.value=.5,this.input.connect(this.convolverNode),this.convolverNode.connect(this.wet),this._seconds=3,this._decay=2,this._reverse=!1,this._buildImpulse()},p5.Reverb.prototype=Object.create(e.prototype),p5.Reverb.prototype.process=function(t,e,i,n){t.connect(this.input);var o=!1;e&&(this._seconds=e,o=!0),i&&(this._decay=i),n&&(this._reverse=n),o&&this._buildImpulse()},p5.Reverb.prototype.set=function(t,e,i){var n=!1;t&&(this._seconds=t,n=!0),e&&(this._decay=e),i&&(this._reverse=i),n&&this._buildImpulse()},p5.Reverb.prototype._buildImpulse=function(){var t,e,i=this.ac.sampleRate,n=i*this._seconds,o=this._decay,s=this.ac.createBuffer(2,n,i),r=s.getChannelData(0),a=s.getChannelData(1);for(e=0;n>e;e++)t=this._reverse?n-e:e,r[e]=(2*Math.random()-1)*Math.pow(1-t/n,o),a[e]=(2*Math.random()-1)*Math.pow(1-t/n,o);this.convolverNode.buffer=s},p5.Reverb.prototype.dispose=function(){e.prototype.dispose.apply(this),this.convolverNode&&(this.convolverNode.buffer=null,this.convolverNode=null)},p5.Convolver=function(t,i,n){e.call(this),this.convolverNode=this.ac.createConvolver(),this.input.gain.value=.5,this.input.connect(this.convolverNode),this.convolverNode.connect(this.wet),t?(this.impulses=[],this._loadBuffer(t,i,n)):(this._seconds=3,this._decay=2,this._reverse=!1,this._buildImpulse())},p5.Convolver.prototype=Object.create(p5.Reverb.prototype),p5.prototype.registerPreloadMethod("createConvolver",p5.prototype),p5.prototype.createConvolver=function(t,e,i){window.location.origin.indexOf("file://")>-1&&"undefined"===window.cordova&&alert("This sketch may require a server to load external files. Please see http://bit.ly/1qcInwS");var n=new p5.Convolver(t,e,i);return n.impulses=[],n},p5.Convolver.prototype._loadBuffer=function(e,i,n){var e=p5.prototype._checkFileFormats(e),o=this,s=(new Error).stack,r=p5.prototype.getAudioContext(),a=new XMLHttpRequest;a.open("GET",e,!0),a.responseType="arraybuffer",a.onload=function(){if(200===a.status)r.decodeAudioData(a.response,function(t){var n={},s=e.split("/");n.name=s[s.length-1],n.audioBuffer=t,o.impulses.push(n),o.convolverNode.buffer=n.audioBuffer,i&&i(n)},function(){var e=new t("decodeAudioData",s,o.url),i="AudioContext error at decodeAudioData for "+o.url;n?(e.msg=i,n(e)):console.error(i+"\n The error stack trace includes: \n"+e.stack)});else{var u=new t("loadConvolver",s,o.url),p="Unable to load "+o.url+". The request status was: "+a.status+" ("+a.statusText+")";n?(u.message=p,n(u)):console.error(p+"\n The error stack trace includes: \n"+u.stack)}},a.onerror=function(){var e=new t("loadConvolver",s,o.url),i="There was no response from the server at "+o.url+". Check the url and internet connectivity.";n?(e.message=i,n(e)):console.error(i+"\n The error stack trace includes: \n"+e.stack)},a.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,i){window.location.origin.indexOf("file://")>-1&&"undefined"===window.cordova&&alert("This sketch may require a server to load external files. Please see http://bit.ly/1qcInwS"),this._loadBuffer(t,e,i)},p5.Convolver.prototype.resetImpulse=function(t,e,i){window.location.origin.indexOf("file://")>-1&&"undefined"===window.cordova&&alert("This sketch may require a server to load external files. Please see http://bit.ly/1qcInwS"),this.impulses=[],this._loadBuffer(t,e,i)},p5.Convolver.prototype.toggleImpulse=function(t){if("number"==typeof t&&tthis._nextTick;){n>this._nextTick+this._threshold&&(this._nextTick=n);var a=this._nextTick;this._nextTick+=1/this.frequency.getValueAtTime(this._nextTick),this.callback(a),this.ticks++}else r===t.State.Stopped&&(this._nextTick=-1,this.ticks=0)},t.Clock.prototype.getStateAtTime=function(t){return this._state.getStateAtTime(t)},t.Clock.prototype.dispose=function(){cancelAnimationFrame(this._loopID),t.TimelineState.prototype.dispose.call(this),this._writable("frequency"),this.frequency.dispose(),this.frequency=null,this._boundLoop=t.noOp,this._nextTick=1/0,this.callback=null,this._state.dispose(),this._state=null},t.Clock}(Tone_core_Tone,Tone_signal_TimelineSignal);var metro;metro=function(){var t=master,e=Tone_core_Clock;p5.Metro=function(){this.clock=new e({callback:this.ontick.bind(this)}),this.syncedParts=[],this.bpm=120,this._init(),this.prevTick=0,this.tatumTime=0,this.tickCallback=function(){}},p5.Metro.prototype.ontick=function(e){var i=e-this.prevTick,n=e-t.audiocontext.currentTime;if(!(i-this.tatumTime<=-.02)){this.prevTick=e;var o=this;this.syncedParts.forEach(function(t){t.isPlaying&&(t.incrementStep(n),t.phrases.forEach(function(t){var e=t.sequence,i=o.metroTicks%e.length;0!==e[i]&&(o.metroTicks=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,n){i=t;for(var o in e.parts)e.parts[o]&&e.parts[o].setBPM(t,n)},p5.Phrase=function(t,e,i){this.phraseStep=0,this.name=t,this.callback=e,this.sequence=i},p5.Part=function(t,n){this.length=t||0,this.partStep=0,this.phrases=[],this.isPlaying=!1,this.noLoop(),this.tatums=n||.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 n;if(3===arguments.length)n=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";n=arguments[0]}this.phrases.push(n),n.sequence.length>this.length&&(this.length=n.sequence.length)},p5.Part.prototype.removePhrase=function(t){for(var e in this.phrases)this.phrases[e].name===t&&this.phrases.splice(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.partStep0&&o.iterations<=o.maxIterations&&o.callback(i)},frequency:this._calcFreq()})},p5.SoundLoop.prototype.start=function(e){var i=e||0,n=t.audiocontext.currentTime;this.isPlaying||(this.clock.start(n+i),this.isPlaying=!0)},p5.SoundLoop.prototype.stop=function(e){var i=e||0,n=t.audiocontext.currentTime;this.isPlaying&&(this.clock.stop(n+i),this.isPlaying=!1)},
+p5.SoundLoop.prototype.pause=function(t){var e=t||0;this.isPlaying&&(this.clock.pause(e),this.isPlaying=!1)},p5.SoundLoop.prototype.syncedStart=function(e,i){var n=i||0,o=t.audiocontext.currentTime;if(e.isPlaying){if(e.isPlaying){var s=e.clock._nextTick-t.audiocontext.currentTime;this.clock.start(o+s),this.isPlaying=!0}}else e.clock.start(o+n),e.isPlaying=!0,this.clock.start(o+n),this.isPlaying=!0},p5.SoundLoop.prototype._update=function(){this.clock.frequency.value=this._calcFreq()},p5.SoundLoop.prototype._calcFreq=function(){return"number"==typeof this._interval?(this.musicalTimeMode=!1,1/this._interval):"string"==typeof this._interval?(this.musicalTimeMode=!0,this._bpm/60/this._convertNotation(this._interval)*(this._timeSignature/4)):void 0},p5.SoundLoop.prototype._convertNotation=function(t){var e=t.slice(-1);switch(t=Number(t.slice(0,-1)),e){case"m":return this._measure(t);case"n":return this._note(t);default:console.warn("Specified interval is not formatted correctly. See Tone.js timing reference for more info: https://github.com/Tonejs/Tone.js/wiki/Time")}},p5.SoundLoop.prototype._measure=function(t){return t*this._timeSignature},p5.SoundLoop.prototype._note=function(t){return this._timeSignature/t},Object.defineProperty(p5.SoundLoop.prototype,"bpm",{get:function(){return this._bpm},set:function(t){this.musicalTimeMode||console.warn('Changing the BPM in "seconds" mode has no effect. BPM is only relevant in musicalTimeMode when the interval is specified as a string ("2n", "4n", "1m"...etc)'),this._bpm=t,this._update()}}),Object.defineProperty(p5.SoundLoop.prototype,"timeSignature",{get:function(){return this._timeSignature},set:function(t){this.musicalTimeMode||console.warn('Changing the timeSignature in "seconds" mode has no effect. BPM is only relevant in musicalTimeMode when the interval is specified as a string ("2n", "4n", "1m"...etc)'),this._timeSignature=t,this._update()}}),Object.defineProperty(p5.SoundLoop.prototype,"interval",{get:function(){return this._interval},set:function(t){this.musicalTimeMode="Number"==typeof t?!1:!0,this._interval=t,this._update()}}),Object.defineProperty(p5.SoundLoop.prototype,"iterations",{get:function(){return this.clock.ticks}}),p5.SoundLoop}(master,Tone_core_Clock);var compressor;compressor=function(){"use strict";var t=effect;return p5.Compressor=function(){t.call(this),this.compressor=this.ac.createDynamicsCompressor(),this.input.connect(this.compressor),this.compressor.connect(this.wet)},p5.Compressor.prototype=Object.create(t.prototype),p5.Compressor.prototype.process=function(t,e,i,n,o,s){t.connect(this.input),this.set(e,i,n,o,s)},p5.Compressor.prototype.set=function(t,e,i,n,o){"undefined"!=typeof t&&this.attack(t),"undefined"!=typeof e&&this.knee(e),"undefined"!=typeof i&&this.ratio(i),"undefined"!=typeof n&&this.threshold(n),"undefined"!=typeof o&&this.release(o)},p5.Compressor.prototype.attack=function(t,e){var i=e||0;return"number"==typeof t?(this.compressor.attack.value=t,this.compressor.attack.cancelScheduledValues(this.ac.currentTime+.01+i),this.compressor.attack.linearRampToValueAtTime(t,this.ac.currentTime+.02+i)):"undefined"!=typeof t&&t.connect(this.compressor.attack),this.compressor.attack.value},p5.Compressor.prototype.knee=function(t,e){var i=e||0;return"number"==typeof t?(this.compressor.knee.value=t,this.compressor.knee.cancelScheduledValues(this.ac.currentTime+.01+i),this.compressor.knee.linearRampToValueAtTime(t,this.ac.currentTime+.02+i)):"undefined"!=typeof t&&t.connect(this.compressor.knee),this.compressor.knee.value},p5.Compressor.prototype.ratio=function(t,e){var i=e||0;return"number"==typeof t?(this.compressor.ratio.value=t,this.compressor.ratio.cancelScheduledValues(this.ac.currentTime+.01+i),this.compressor.ratio.linearRampToValueAtTime(t,this.ac.currentTime+.02+i)):"undefined"!=typeof t&&t.connect(this.compressor.ratio),this.compressor.ratio.value},p5.Compressor.prototype.threshold=function(t,e){var i=e||0;return"number"==typeof t?(this.compressor.threshold.value=t,this.compressor.threshold.cancelScheduledValues(this.ac.currentTime+.01+i),this.compressor.threshold.linearRampToValueAtTime(t,this.ac.currentTime+.02+i)):"undefined"!=typeof t&&t.connect(this.compressor.threshold),this.compressor.threshold.value},p5.Compressor.prototype.release=function(t,e){var i=e||0;return"number"==typeof t?(this.compressor.release.value=t,this.compressor.release.cancelScheduledValues(this.ac.currentTime+.01+i),this.compressor.release.linearRampToValueAtTime(t,this.ac.currentTime+.02+i)):"undefined"!=typeof number&&t.connect(this.compressor.release),this.compressor.release.value},p5.Compressor.prototype.reduction=function(){return this.compressor.reduction.value},p5.Compressor.prototype.dispose=function(){t.prototype.dispose.apply(this),this.compressor.disconnect(),this.compressor=void 0},p5.Compressor}(master,effect,errorHandler);var soundRecorder;soundRecorder=function(){function t(t,e){for(var i=t.length+e.length,n=new Float32Array(i),o=0,s=0;i>s;)n[s++]=t[o],n[s++]=e[o],o++;return n}function e(t,e,i){for(var n=i.length,o=0;n>o;o++)t.setUint8(e+o,i.charCodeAt(o))}var i=master,n=i.audiocontext;p5.SoundRecorder=function(){this.input=n.createGain(),this.output=n.createGain(),this.recording=!1,this.bufferSize=1024,this._channels=2,this._clear(),this._jsNode=n.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=n.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*n.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,n=t.length,o=0;n>o;o++){var s=t[o];e.set(s,i),i+=s.length}return e},p5.SoundRecorder.prototype.dispose=function(){this._clear();var t=i.soundArray.indexOf(this);i.soundArray.splice(t,1),this._callback=function(){},this.input&&this.input.disconnect(),this.input=null,this._jsNode=null},p5.prototype.saveSound=function(i,n){var o,s;o=i.buffer.getChannelData(0),s=i.buffer.numberOfChannels>1?i.buffer.getChannelData(1):o;var r=t(o,s),a=new window.ArrayBuffer(44+2*r.length),u=new window.DataView(a);e(u,0,"RIFF"),u.setUint32(4,36+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 p=r.length,c=44,h=1,l=0;p>l;l++)u.setInt16(c,r[l]*(32767*h),!0),c+=2;p5.prototype.writeFile([u],n,"wav")}}(sndcore,master);var peakdetect;peakdetect=function(){p5.PeakDetect=function(t,e,i,n){this.framesPerPeak=n||20,this.framesSinceLastPeak=0,this.decayRate=.95,this.threshold=i||.35,this.cutoff=0,this.cutoffMult=1.5,this.energy=0,this.penergy=0,this.currentValue=0,this.isDetected=!1,this.f1=t||40,this.f2=e||2e4,this._onPeak=function(){}},p5.PeakDetect.prototype.update=function(t){var e=this.energy=t.getEnergy(this.f1,this.f2)/255;e>this.cutoff&&e>this.threshold&&e-this.penergy>0?(this._onPeak(),this.isDetected=!0,this.cutoff=e*this.cutoffMult,this.framesSinceLastPeak=0):(this.isDetected=!1,this.framesSinceLastPeak<=this.framesPerPeak?this.framesSinceLastPeak++:(this.cutoff*=this.decayRate,this.cutoff=Math.max(this.cutoff,this.threshold))),this.currentValue=e,this.penergy=e},p5.PeakDetect.prototype.onPeak=function(t,e){var i=this;i._onPeak=function(){t(i.energy,e)}}}();var gain;gain=function(){var t=master;p5.Gain=function(){this.ac=t.audiocontext,this.input=this.ac.createGain(),this.output=this.ac.createGain(),this.input.gain.value=.5,this.input.connect(this.output),t.soundArray.push(this)},p5.Gain.prototype.setInput=function(t){t.connect(this.input)},p5.Gain.prototype.connect=function(t){var e=t||p5.soundOut.input;this.output.connect(e.input?e.input:e)},p5.Gain.prototype.disconnect=function(){this.output.disconnect()},p5.Gain.prototype.amp=function(e,i,n){var i=i||0,n=n||0,o=t.audiocontext.currentTime,s=this.output.gain.value;this.output.gain.cancelScheduledValues(o),this.output.gain.linearRampToValueAtTime(s,o+n),this.output.gain.linearRampToValueAtTime(e,o+n+i)},p5.Gain.prototype.dispose=function(){var e=t.soundArray.indexOf(this);t.soundArray.splice(e,1),this.output.disconnect(),this.input.disconnect(),this.output=void 0,this.input=void 0}}(master,sndcore);var audioVoice;audioVoice=function(){var t=master;return p5.AudioVoice=function(){this.ac=t.audiocontext,this.output=this.ac.createGain(),this.connect(),t.soundArray.push(this)},p5.AudioVoice.prototype._setNote=function(t){var e={A:21,B:23,C:24,D:26,E:28,F:29,G:31},i=e[t[0]],n="number"==typeof Number(t.slice(-1))?t.slice(-1):0;return i+=12*n,i="#"===t[1]?i+1:"b"===t[1]?i-1:i,p5.prototype.midiToFreq(i)},p5.AudioVoice.prototype.play=function(t,e,i,n){},p5.AudioVoice.prototype.triggerAttack=function(t,e,i){},p5.AudioVoice.prototype.triggerRelease=function(t){},p5.AudioVoice.prototype.amp=function(t,e){},p5.AudioVoice.prototype.connect=function(e){var i=e||t.input;this.output.connect(i.input?i.input:i)},p5.AudioVoice.prototype.disconnect=function(){this.output.disconnect()},p5.AudioVoice.prototype.dispose=function(){this.output.disconnect(),delete this.output},p5.AudioVoice}(master);var monosynth;monosynth=function(){var t=master,e=audioVoice;p5.MonoSynth=function(){e.call(this),this.oscillator=new p5.Oscillator,this.env=new p5.Env,this.env.setRange(1,0),this.env.setExp(!0),this.setADSR(.02,.25,.05,.35),this.filter=new p5.Filter("highpass"),this.filter.set(5,1),this.oscillator.disconnect(),this.oscillator.connect(this.filter),this.env.disconnect(),this.env.setInput(this.oscillator),this.filter.connect(this.output),this.oscillator.start(),this.connect(),this._isOn=!1,t.soundArray.push(this)},p5.MonoSynth.prototype=Object.create(p5.AudioVoice.prototype),p5.MonoSynth.prototype.play=function(t,e,i,n){var n=n||this.sustain;this.susTime=n,this.triggerAttack(t,e,i),this.triggerRelease(i+n)},p5.MonoSynth.prototype.triggerAttack=function(t,e,i){var i=i||0,n="string"==typeof t?this._setNote(t):"number"==typeof t?t:440,o=e||1;this._isOn=!0,this.oscillator.freq(n,0,i),this.env.ramp(this.output,i,o)},p5.MonoSynth.prototype.triggerRelease=function(t){var t=t||0;this.env.ramp(this.output,t,0),this._isOn=!1},p5.MonoSynth.prototype.setADSR=function(t,e,i,n){this.env.setADSR(t,e,i,n)},Object.defineProperties(p5.MonoSynth.prototype,{attack:{get:function(){return this.env.aTime},set:function(t){this.env.setADSR(t,this.env.dTime,this.env.sPercent,this.env.rTime)}},decay:{get:function(){return this.env.dTime},set:function(t){this.env.setADSR(this.env.aTime,t,this.env.sPercent,this.env.rTime)}},sustain:{get:function(){return this.env.sPercent},set:function(t){this.env.setADSR(this.env.aTime,this.env.dTime,t,this.env.rTime)}},release:{get:function(){return this.env.rTime},set:function(t){this.env.setADSR(this.env.aTime,this.env.dTime,this.env.sPercent,t)}}}),p5.MonoSynth.prototype.amp=function(t,e){var i=e||0;return"undefined"!=typeof t&&this.oscillator.amp(t,i),this.oscillator.amp().value},p5.MonoSynth.prototype.connect=function(e){var i=e||t.input;this.output.connect(i.input?i.input:i)},p5.MonoSynth.prototype.disconnect=function(){this.output.disconnect()},p5.MonoSynth.prototype.dispose=function(){e.prototype.dispose.apply(this),this.filter.dispose(),this.env.dispose();try{this.oscillator.dispose()}catch(t){console.error("mono synth default oscillator already disposed")}}}(master,audioVoice);var polysynth;polysynth=function(){var t=master,e=Tone_signal_TimelineSignal;p5.PolySynth=function(i,n){this.audiovoices=[],this.notes={},this._newest=0,this._oldest=0,this.polyValue=n||8,this.AudioVoice=void 0===i?p5.MonoSynth:i,this._voicesInUse=new e(0),this.output=t.audiocontext.createGain(),this.connect(),this._allocateVoices(),t.soundArray.push(this)},p5.PolySynth.prototype._allocateVoices=function(){for(var t=0;td?d:c}this.audiovoices[s].triggerAttack(p,c,a)},p5.PolySynth.prototype._updateAfter=function(t,e){if(null!==this._voicesInUse._searchAfter(t)){this._voicesInUse._searchAfter(t).value+=e;var i=this._voicesInUse._searchAfter(t).time;this._updateAfter(i,e)}},p5.PolySynth.prototype.noteRelease=function(e,i){var n="string"==typeof e?this.AudioVoice.prototype._setNote(e):"number"==typeof e?e:this.audiovoices[this._newest].oscillator.freq().value,o=t.audiocontext.currentTime,s=i||0,r=o+s;if(null===this.notes[n].getValueAtTime(r))console.warn("Cannot release a note that is not already playing");else{var a=null===this._voicesInUse._searchBefore(r)?0:this._voicesInUse._searchBefore(r).value;this._voicesInUse.setValueAtTime(a-1,r),this._updateAfter(r,-1),this.audiovoices[this.notes[n].getValueAtTime(r)].triggerRelease(s),this.notes[n].setValueAtTime(null,r),this._newest=0===this._newest?0:(this._newest-1)%(this.polyValue-1)}},p5.PolySynth.prototype.connect=function(e){var i=e||t.input;this.output.connect(i.input?i.input:i)},p5.PolySynth.prototype.disconnect=function(){this.output.disconnect()},p5.PolySynth.prototype.dispose=function(){this.audiovoices.forEach(function(t){t.dispose()}),this.output.disconnect(),delete this.output}}(master,Tone_signal_TimelineSignal,sndcore);var distortion;distortion=function(){function t(t){for(var e,i="number"==typeof t?t:50,n=44100,o=new Float32Array(n),s=Math.PI/180,r=0;n>r;++r)e=2*r/n-1,o[r]=(3+i)*e*20*s/(Math.PI+i*Math.abs(e));return o}var e=effect;p5.Distortion=function(i,n){if(e.call(this),"undefined"==typeof i&&(i=.25),"number"!=typeof i)throw new Error("amount must be a number");if("undefined"==typeof n&&(n="2x"),"string"!=typeof n)throw new Error("oversample must be a String");var o=p5.prototype.map(i,0,1,0,2e3);this.waveShaperNode=this.ac.createWaveShaper(),this.amount=o,this.waveShaperNode.curve=t(o),this.waveShaperNode.oversample=n,this.input.connect(this.waveShaperNode),this.waveShaperNode.connect(this.wet)},p5.Distortion.prototype=Object.create(e.prototype),p5.Distortion.prototype.process=function(t,e,i){t.connect(this.input),this.set(e,i)},p5.Distortion.prototype.set=function(e,i){if(e){var n=p5.prototype.map(e,0,1,0,2e3);this.amount=n,this.waveShaperNode.curve=t(n)}i&&(this.waveShaperNode.oversample=i)},p5.Distortion.prototype.getAmount=function(){return this.amount},p5.Distortion.prototype.getOversample=function(){return this.waveShaperNode.oversample},p5.Distortion.prototype.dispose=function(){e.prototype.dispose.apply(this),this.waveShaperNode.disconnect(),this.waveShaperNode=null}}(effect);var src_app;src_app=function(){var t=sndcore;return t}(sndcore,master,helpers,errorHandler,panner,soundfile,amplitude,fft,signal,oscillator,env,pulse,noise,audioin,filter,eq,panner3d,listener3d,delay,reverb,metro,looper,soundloop,compressor,soundRecorder,peakdetect,gain,monosynth,polysynth,distortion,audioVoice,monosynth,polysynth)});
\ No newline at end of file