diff --git a/Gruntfile.js b/Gruntfile.js
index 9ef8b98b..1cea38d2 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -55,10 +55,13 @@ module.exports = function(grunt) {
findNestedDependencies: true,
include: ['src/app'],
onBuildWrite: function( name, path, contents ) {
- return require('amdclean').clean({
- 'code':contents,
+ if (path.indexOf('node_modules') > 1) {
+ return '/** Tone.js module by Yotam Mann, MIT License 2014 http://opensource.org/licenses/MIT **/\n' +
+ require('amdclean').clean({
+ 'code': contents,
'escodegen': {
- 'comment': true,
+ 'comment': false,
+ 'skipDirOptimize':true,
'format': {
'indent': {
'style': ' ',
@@ -67,6 +70,20 @@ module.exports = function(grunt) {
}
}
});
+ } else {
+ return require('amdclean').clean({
+ 'code':contents,
+ 'escodegen': {
+ 'comment': true,
+ 'format': {
+ 'indent': {
+ 'style': ' ',
+ 'adjustMultiLineComment': true
+ }
+ }
+ }
+ });
+ }
},
optimize: 'none',
out: 'lib/p5.sound.js',
@@ -122,33 +139,6 @@ module.exports = function(grunt) {
}
}
},
- yuidoc_theme: {
- options: {
- baseUrl: './docs/yuidoc-p5-theme-src/scripts/',
- mainConfigFile: './docs/yuidoc-p5-theme-src/scripts/config.js',
- name: 'main',
- out: './docs/yuidoc-p5-theme/assets/js/reference.js',
- optimize: 'none',
- generateSourceMaps: true,
- findNestedDependencies: true,
- wrap: true,
- paths: { 'jquery': 'empty:' }
- }
- }
- },
- yuidoc: {
- compile: {
- name: '<%= pkg.name %>',
- description: '<%= pkg.description %>',
- version: '<%= pkg.version %>',
- url: '<%= pkg.homepage %>',
- options: {
- paths: ['src/', 'lib/addons/'],
- //helpers: [],
- themedir: 'docs/yuidoc-p5-theme/',
- outdir: 'docs/reference/'
- }
- }
}
});
diff --git a/lib/p5.sound.js b/lib/p5.sound.js
index 420b6028..599c85e0 100644
--- a/lib/p5.sound.js
+++ b/lib/p5.sound.js
@@ -1,4 +1,4 @@
-/*! p5.sound.js v0.1.7 2015-01-27 */
+/*! p5.sound.js v0.1.7 2015-01-30 */
/**
* p5.sound extends p5 with Web Audio functionality including audio input,
@@ -1968,25 +1968,14 @@ fft = function () {
this.analyser.smoothingTimeConstant = s;
};
}(master);
-/**
- * Tone.js
- *
- * @author Yotam Mann
- *
- * @license http://opensource.org/licenses/MIT MIT License 2014
- */
+/** Tone.js module by Yotam Mann, MIT License 2014 http://opensource.org/licenses/MIT **/
var Tone_core_Tone;
Tone_core_Tone = function () {
'use strict';
- //////////////////////////////////////////////////////////////////////////
- // WEB AUDIO CONTEXT
- ///////////////////////////////////////////////////////////////////////////
- //borrowed from underscore.js
function isUndef(val) {
return val === void 0;
}
var audioContext;
- //polyfill for AudioContext and OfflineAudioContext
if (isUndef(window.AudioContext)) {
window.AudioContext = window.webkitAudioContext;
}
@@ -1998,7 +1987,6 @@ Tone_core_Tone = function () {
} else {
throw new Error('Web Audio is not supported in this browser');
}
- //SHIMS////////////////////////////////////////////////////////////////////
if (typeof AudioContext.prototype.createGain !== 'function') {
AudioContext.prototype.createGain = AudioContext.prototype.createGainNode;
}
@@ -2023,7 +2011,6 @@ Tone_core_Tone = function () {
if (typeof OscillatorNode.prototype.setPeriodicWave !== 'function') {
OscillatorNode.prototype.setPeriodicWave = OscillatorNode.prototype.setWaveTable;
}
- //extend the connect function to include Tones
AudioNode.prototype._nativeConnect = AudioNode.prototype.connect;
AudioNode.prototype.connect = function (B, outNum, inNum) {
if (B.input) {
@@ -2047,74 +2034,22 @@ Tone_core_Tone = function () {
}
}
};
- ///////////////////////////////////////////////////////////////////////////
- // TONE
- ///////////////////////////////////////////////////////////////////////////
- /**
- * @class Tone is the baseclass of all Tone Modules.
- *
- * @constructor
- * @alias Tone
- * @param {number} [inputs=1] the number of input nodes
- * @param {number} [outputs=1] the number of output nodes
- */
var Tone = function (inputs, outputs) {
- /**
- * the input node(s)
- * @type {GainNode|Array}
- */
if (isUndef(inputs) || inputs === 1) {
this.input = this.context.createGain();
} else if (inputs > 1) {
this.input = new Array(inputs);
}
- /**
- * the output node(s)
- * @type {GainNode|Array}
- */
if (isUndef(outputs) || outputs === 1) {
this.output = this.context.createGain();
} else if (outputs > 1) {
this.output = new Array(inputs);
}
};
- ///////////////////////////////////////////////////////////////////////////
- // CLASS VARS
- ///////////////////////////////////////////////////////////////////////////
- /**
- * A static pointer to the audio context
- * @static
- * @type {AudioContext}
- */
Tone.context = audioContext;
- /**
- * A static pointer to the audio context
- * @type {AudioContext}
- */
Tone.prototype.context = Tone.context;
- /**
- * the default buffer size
- * @type {number}
- * @static
- * @const
- */
Tone.prototype.bufferSize = 2048;
- /**
- * the delay time of a single buffer frame
- * @type {number}
- * @static
- * @const
- */
Tone.prototype.bufferTime = Tone.prototype.bufferSize / Tone.context.sampleRate;
- ///////////////////////////////////////////////////////////////////////////
- // CONNECTIONS
- ///////////////////////////////////////////////////////////////////////////
- /**
- * connect the output of a ToneNode to an AudioParam, AudioNode, or ToneNode
- * @param {Tone | AudioParam | AudioNode} unit
- * @param {number} [outputNum=0] optionally which output to connect from
- * @param {number} [inputNum=0] optionally which input to connect to
- */
Tone.prototype.connect = function (unit, outputNum, inputNum) {
if (Array.isArray(this.output)) {
outputNum = this.defaultArg(outputNum, 0);
@@ -2123,9 +2058,6 @@ Tone_core_Tone = function () {
this.output.connect(unit, outputNum, inputNum);
}
};
- /**
- * disconnect the output
- */
Tone.prototype.disconnect = function (outputNum) {
if (Array.isArray(this.output)) {
outputNum = this.defaultArg(outputNum, 0);
@@ -2134,10 +2066,6 @@ Tone_core_Tone = function () {
this.output.disconnect();
}
};
- /**
- * connect together all of the arguments in series
- * @param {...AudioParam|Tone|AudioNode}
- */
Tone.prototype.connectSeries = function () {
if (arguments.length > 1) {
var currentUnit = arguments[0];
@@ -2148,10 +2076,6 @@ Tone_core_Tone = function () {
}
}
};
- /**
- * fan out the connection from the first argument to the rest of the arguments
- * @param {...AudioParam|Tone|AudioNode}
- */
Tone.prototype.connectParallel = function () {
var connectFrom = arguments[0];
if (arguments.length > 1) {
@@ -2161,10 +2085,6 @@ Tone_core_Tone = function () {
}
}
};
- /**
- * connect the output of this node to the rest of the nodes in series.
- * @param {...AudioParam|Tone|AudioNode}
- */
Tone.prototype.chain = function () {
if (arguments.length > 0) {
var currentUnit = this;
@@ -2175,10 +2095,6 @@ Tone_core_Tone = function () {
}
}
};
- /**
- * connect the output of this node to the rest of the nodes in parallel.
- * @param {...AudioParam|Tone|AudioNode}
- */
Tone.prototype.fan = function () {
if (arguments.length > 0) {
for (var i = 1; i < arguments.length; i++) {
@@ -2186,29 +2102,11 @@ Tone_core_Tone = function () {
}
}
};
- //give native nodes chain and fan methods
AudioNode.prototype.chain = Tone.prototype.chain;
AudioNode.prototype.fan = Tone.prototype.fan;
- ///////////////////////////////////////////////////////////////////////////
- // UTILITIES / HELPERS / MATHS
- ///////////////////////////////////////////////////////////////////////////
- /**
- * if a the given is undefined, use the fallback.
- * if both given and fallback are objects, given
- * will be augmented with whatever properties it's
- * missing which are in fallback
- *
- * warning: if object is self referential, it will go into an an
- * infinite recursive loop.
- *
- * @param {*} given
- * @param {*} fallback
- * @return {*}
- */
Tone.prototype.defaultArg = function (given, fallback) {
if (typeof given === 'object' && typeof fallback === 'object') {
var ret = {};
- //make a deep copy of the given object
for (var givenProp in given) {
ret[givenProp] = this.defaultArg(given[givenProp], given[givenProp]);
}
@@ -2220,20 +2118,6 @@ Tone_core_Tone = function () {
return isUndef(given) ? fallback : given;
}
};
- /**
- * returns the args as an options object with given arguments
- * mapped to the names provided.
- *
- * if the args given is an array containing an object, it is assumed
- * that that's already the options object and will just return it.
- *
- * @param {Array} values the 'arguments' object of the function
- * @param {Array.} keys the names of the arguments as they
- * should appear in the options object
- * @param {Object=} defaults optional defaults to mixin to the returned
- * options object
- * @return {Object} the options object with the names mapped to the arguments
- */
Tone.prototype.optionsObject = function (values, keys, defaults) {
var options = {};
if (values.length === 1 && typeof values[0] === 'object') {
@@ -2249,73 +2133,27 @@ Tone_core_Tone = function () {
return options;
}
};
- /**
- * test if the arg is undefined
- * @param {*} arg the argument to test
- * @returns {boolean} true if the arg is undefined
- * @function
- */
Tone.prototype.isUndef = isUndef;
- /**
- * equal power gain scale
- * good for cross-fading
- *
- * @param {number} percent (0-1)
- * @return {number} output gain (0-1)
- */
Tone.prototype.equalPowerScale = function (percent) {
var piFactor = 0.5 * Math.PI;
return Math.sin(percent * piFactor);
};
- /**
- * @param {number} gain (0-1)
- * @return {number} gain (decibel scale but betwee 0-1)
- */
Tone.prototype.logScale = function (gain) {
return Math.max(this.normalize(this.gainToDb(gain), -100, 0), 0);
};
- /**
- * @param {number} gain (0-1)
- * @return {number} gain (decibel scale but betwee 0-1)
- */
Tone.prototype.expScale = function (gain) {
return this.dbToGain(this.interpolate(gain, -100, 0));
};
- /**
- * convert db scale to gain scale (0-1)
- * @param {number} db
- * @return {number}
- */
Tone.prototype.dbToGain = function (db) {
return Math.pow(2, db / 6);
};
- /**
- * convert gain scale to decibels
- * @param {number} gain (0-1)
- * @return {number}
- */
Tone.prototype.gainToDb = function (gain) {
return 20 * (Math.log(gain) / Math.LN10);
};
- /**
- * interpolate the input value (0-1) to be between outputMin and outputMax
- * @param {number} input
- * @param {number} outputMin
- * @param {number} outputMax
- * @return {number}
- */
Tone.prototype.interpolate = function (input, outputMin, outputMax) {
return input * (outputMax - outputMin) + outputMin;
};
- /**
- * normalize the input to 0-1 from between inputMin to inputMax
- * @param {number} input
- * @param {number} inputMin
- * @param {number} inputMax
- * @return {number}
- */
Tone.prototype.normalize = function (input, inputMin, inputMax) {
- //make sure that min < max
if (inputMin > inputMax) {
var tmp = inputMax;
inputMax = inputMin;
@@ -2325,9 +2163,6 @@ Tone_core_Tone = function () {
}
return (input - inputMin) / (inputMax - inputMin);
};
- /**
- * a dispose method
- */
Tone.prototype.dispose = function () {
if (!this.isUndef(this.input)) {
if (this.input instanceof AudioNode) {
@@ -2342,66 +2177,23 @@ Tone_core_Tone = function () {
this.output = null;
}
};
- /**
- * a silent connection to the DesinationNode
- * which will ensure that anything connected to it
- * will not be garbage collected
- *
- * @private
- */
var _silentNode = null;
- /**
- * makes a connection to ensure that the node will not be garbage collected
- * until 'dispose' is explicitly called
- *
- * use carefully. circumvents JS and WebAudio's normal Garbage Collection behavior
- */
Tone.prototype.noGC = function () {
this.output.connect(_silentNode);
};
AudioNode.prototype.noGC = function () {
this.connect(_silentNode);
};
- ///////////////////////////////////////////////////////////////////////////
- // TIMING
- ///////////////////////////////////////////////////////////////////////////
- /**
- * @return {number} the currentTime from the AudioContext
- */
Tone.prototype.now = function () {
return this.context.currentTime;
};
- /**
- * convert a sample count to seconds
- * @param {number} samples
- * @return {number}
- */
Tone.prototype.samplesToSeconds = function (samples) {
return samples / this.context.sampleRate;
};
- /**
- * convert a time into samples
- *
- * @param {Tone.time} time
- * @return {number}
- */
Tone.prototype.toSamples = function (time) {
var seconds = this.toSeconds(time);
return Math.round(seconds * this.context.sampleRate);
};
- /**
- * convert time to seconds
- *
- * this is a simplified version which only handles numbers and
- * 'now' relative numbers. If the Transport is included this
- * method is overridden to include many other features including
- * notationTime, Frequency, and transportTime
- *
- * @param {number=} time
- * @param {number=} now if passed in, this number will be
- * used for all 'now' relative timings
- * @return {number} seconds in the same timescale as the AudioContext
- */
Tone.prototype.toSeconds = function (time, now) {
now = this.defaultArg(now, this.now());
if (typeof time === 'number') {
@@ -2417,73 +2209,24 @@ Tone_core_Tone = function () {
return now;
}
};
- /**
- * convert a frequency into seconds
- * accepts both numbers and strings
- * i.e. 10hz or 10 both equal .1
- *
- * @param {number|string} freq
- * @return {number}
- */
Tone.prototype.frequencyToSeconds = function (freq) {
return 1 / parseFloat(freq);
};
- /**
- * convert a number in seconds to a frequency
- * @param {number} seconds
- * @return {number}
- */
Tone.prototype.secondsToFrequency = function (seconds) {
return 1 / seconds;
};
- ///////////////////////////////////////////////////////////////////////////
- // STATIC METHODS
- ///////////////////////////////////////////////////////////////////////////
- /**
- * array of callbacks to be invoked when a new context is added
- * @internal
- * @private
- */
var newContextCallbacks = [];
- /**
- * invoke this callback when a new context is added
- * will be invoked initially with the first context
- * @private
- * @static
- * @param {function(AudioContext)} callback the callback to be invoked
- * with the audio context
- */
Tone._initAudioContext = function (callback) {
- //invoke the callback with the existing AudioContext
callback(Tone.context);
- //add it to the array
newContextCallbacks.push(callback);
};
- /**
- * @static
- */
Tone.setContext = function (ctx) {
- //set the prototypes
Tone.prototype.context = ctx;
Tone.context = ctx;
- //invoke all the callbacks
for (var i = 0; i < newContextCallbacks.length; i++) {
newContextCallbacks[i](ctx);
}
};
- /**
- * have a child inherit all of Tone's (or a parent's) prototype
- * to inherit the parent's properties, make sure to call
- * Parent.call(this) in the child's constructor
- *
- * based on closure library's inherit function
- *
- * @static
- * @param {function} child
- * @param {function=} parent (optional) parent to inherit from
- * if no parent is supplied, the child
- * will inherit from Tone
- */
Tone.extend = function (child, parent) {
if (isUndef(parent)) {
parent = Tone;
@@ -2492,16 +2235,8 @@ Tone_core_Tone = function () {
}
TempConstructor.prototype = parent.prototype;
child.prototype = new TempConstructor();
- /** @override */
child.prototype.constructor = child;
};
- /**
- * bind this to a touchstart event to start the audio
- *
- * http://stackoverflow.com/questions/12517000/no-sound-on-ios-6-web-audio-api/12569290#12569290
- *
- * @static
- */
Tone.startMobile = function () {
var osc = Tone.context.createOscillator();
var silent = Tone.context.createGain();
@@ -2512,38 +2247,23 @@ Tone_core_Tone = function () {
osc.start(now);
osc.stop(now + 1);
};
- //setup the context
Tone._initAudioContext(function (audioContext) {
- //set the bufferTime
Tone.prototype.bufferTime = Tone.prototype.bufferSize / audioContext.sampleRate;
_silentNode = audioContext.createGain();
_silentNode.gain.value = 0;
_silentNode.connect(audioContext.destination);
});
+ console.log('%c * Tone.js r3 * ', 'background: #000; color: #fff');
return Tone;
}();
+/** Tone.js module by Yotam Mann, MIT License 2014 http://opensource.org/licenses/MIT **/
var Tone_signal_SignalBase;
Tone_signal_SignalBase = function (Tone) {
'use strict';
- /**
- * @class Base class for all Signals
- *
- * @constructor
- * @extends {Tone}
- */
Tone.SignalBase = function () {
};
Tone.extend(Tone.SignalBase);
- /**
- * Signals can connect to other Signals
- *
- * @override
- * @param {AudioParam|AudioNode|Tone.Signal|Tone} node
- * @param {number} [outputNumber=0]
- * @param {number} [inputNumber=0]
- */
Tone.SignalBase.prototype.connect = function (node, outputNumber, inputNumber) {
- //zero it out so that the signal can have full control
if (node instanceof Tone.Signal) {
node.setValue(0);
} else if (node instanceof AudioParam) {
@@ -2551,48 +2271,17 @@ Tone_signal_SignalBase = function (Tone) {
}
Tone.prototype.connect.call(this, node, outputNumber, inputNumber);
};
- /**
- * internal dispose method to tear down the node
- */
Tone.SignalBase.prototype.dispose = function () {
Tone.prototype.dispose.call(this);
};
return Tone.SignalBase;
}(Tone_core_Tone);
+/** Tone.js module by Yotam Mann, MIT License 2014 http://opensource.org/licenses/MIT **/
var Tone_signal_WaveShaper;
Tone_signal_WaveShaper = function (Tone) {
'use strict';
- /**
- * @class Wraps the WaveShaperNode
- *
- * ```javascript
- * var timesTwo = new Tone.WaveShaper(function(val){
- * return val * 2;
- * }, 2048);
- * ```
- *
- * @extends {Tone.SignalBase}
- * @constructor
- * @param {function(number, number)|Array|number} mapping the function used to define the values.
- * The mapping function should take two arguments:
- * the first is the value at the current position
- * and the second is the array position.
- * If the argument is an array, that array will be
- * set as the wave shapping function
- * @param {number} [bufferLen=1024] the length of the WaveShaperNode buffer.
- */
Tone.WaveShaper = function (mapping, bufferLen) {
- /**
- * the waveshaper
- * @type {WaveShaperNode}
- * @private
- */
this._shaper = this.input = this.output = this.context.createWaveShaper();
- /**
- * the waveshapers curve
- * @type {Float32Array}
- * @private
- */
this._curve = null;
if (Array.isArray(mapping)) {
this.setCurve(mapping);
@@ -2604,13 +2293,6 @@ Tone_signal_WaveShaper = function (Tone) {
}
};
Tone.extend(Tone.WaveShaper, Tone.SignalBase);
- /**
- * uses a mapping function to set the value of the curve
- * @param {function(number, number)} mapping the function used to define the values.
- * The mapping function should take two arguments:
- * the first is the value at the current position
- * and the second is the array position
- */
Tone.WaveShaper.prototype.setMap = function (mapping) {
for (var i = 0, len = this._curve.length; i < len; i++) {
var normalized = i / len * 2 - 1;
@@ -2619,12 +2301,7 @@ Tone_signal_WaveShaper = function (Tone) {
}
this._shaper.curve = this._curve;
};
- /**
- * use an array to set the waveshaper curve
- * @param {Array} mapping the array to use as the waveshaper
- */
Tone.WaveShaper.prototype.setCurve = function (mapping) {
- //fixes safari WaveShaperNode bug
if (this._isSafari()) {
var first = mapping[0];
mapping.unshift(first);
@@ -2632,25 +2309,13 @@ Tone_signal_WaveShaper = function (Tone) {
this._curve = new Float32Array(mapping);
this._shaper.curve = this._curve;
};
- /**
- * set the oversampling
- * @param {string} oversampling can either be "none", "2x" or "4x"
- */
Tone.WaveShaper.prototype.setOversample = function (oversampling) {
this._shaper.oversample = oversampling;
};
- /**
- * returns true if the browser is safari
- * @return {boolean}
- * @private
- */
Tone.WaveShaper.prototype._isSafari = function () {
var ua = navigator.userAgent.toLowerCase();
return ua.indexOf('safari') !== -1 && ua.indexOf('chrome') === -1;
};
- /**
- * clean up
- */
Tone.WaveShaper.prototype.dispose = function () {
Tone.prototype.dispose.call(this);
this._shaper.disconnect();
@@ -2659,58 +2324,21 @@ Tone_signal_WaveShaper = function (Tone) {
};
return Tone.WaveShaper;
}(Tone_core_Tone);
+/** Tone.js module by Yotam Mann, MIT License 2014 http://opensource.org/licenses/MIT **/
var Tone_signal_Signal;
Tone_signal_Signal = function (Tone) {
'use strict';
- /**
- * @class Constant audio-rate signal.
- * Tone.Signal is a core component which allows for sample-accurate
- * synchronization of many components. Tone.Signal can be scheduled
- * with all of the functions available to AudioParams
- *
- * @constructor
- * @extends {Tone.SignalBase}
- * @param {number} [value=0] initial value
- */
Tone.Signal = function (value) {
- /**
- * scales the constant output to the desired output
- * @type {GainNode}
- * @private
- */
this._scalar = this.context.createGain();
- /**
- * @type {GainNode}
- */
this.input = this.output = this.context.createGain();
- /**
- * the ratio of the this value to the control signal value
- *
- * @private
- * @type {number}
- */
this._syncRatio = 1;
- /**
- * the value of the Signal
- * @type {number}
- */
this.value = this.defaultArg(value, 0);
- //connect the constant 1 output to the node output
Tone.Signal._constant.chain(this._scalar, this.output);
};
Tone.extend(Tone.Signal, Tone.SignalBase);
- /**
- * @return {number} the current value of the signal
- */
Tone.Signal.prototype.getValue = function () {
return this._scalar.gain.value;
};
- /**
- * set the value of the signal right away
- * will be overwritten if there are previously scheduled automation curves
- *
- * @param {number} value
- */
Tone.Signal.prototype.setValue = function (value) {
if (this._syncRatio === 0) {
value = 0;
@@ -2719,22 +2347,10 @@ Tone_signal_Signal = function (Tone) {
}
this._scalar.gain.value = value;
};
- /**
- * Schedules a parameter value change at the given time.
- *
- * @param {number} value
- * @param {Tone.Time} time
- */
Tone.Signal.prototype.setValueAtTime = function (value, time) {
value *= this._syncRatio;
this._scalar.gain.setValueAtTime(value, this.toSeconds(time));
};
- /**
- * creates a schedule point with the current value at the current time
- *
- * @param {number=} now (optionally) pass the now value in
- * @returns {number} the current value
- */
Tone.Signal.prototype.setCurrentValueNow = function (now) {
now = this.defaultArg(now, this.now());
var currentVal = this.getValue();
@@ -2742,159 +2358,76 @@ Tone_signal_Signal = function (Tone) {
this._scalar.gain.setValueAtTime(currentVal, now);
return currentVal;
};
- /**
- * Schedules a linear continuous change in parameter value from the
- * previous scheduled parameter value to the given value.
- *
- * @param {number} value
- * @param {Tone.Time} endTime
- */
Tone.Signal.prototype.linearRampToValueAtTime = function (value, endTime) {
value *= this._syncRatio;
this._scalar.gain.linearRampToValueAtTime(value, this.toSeconds(endTime));
};
- /**
- * Schedules an exponential continuous change in parameter value from
- * the previous scheduled parameter value to the given value.
- *
- * NOTE: Chrome will throw an error if you try to exponentially ramp to a
- * value 0 or less.
- *
- * @param {number} value
- * @param {Tone.Time} endTime
- */
Tone.Signal.prototype.exponentialRampToValueAtTime = function (value, endTime) {
value *= this._syncRatio;
try {
this._scalar.gain.exponentialRampToValueAtTime(value, this.toSeconds(endTime));
} catch (e) {
- //firefox won't let the signal ramp past 1, in these cases, revert to linear ramp
this._scalar.gain.linearRampToValueAtTime(value, this.toSeconds(endTime));
}
};
- /**
- * Schedules an exponential continuous change in parameter value from
- * the current time and current value to the given value.
- *
- * @param {number} value
- * @param {Tone.Time} endTime
- */
Tone.Signal.prototype.exponentialRampToValueNow = function (value, endTime) {
var now = this.now();
this.setCurrentValueNow(now);
- //make sure that the endTime doesn't start with +
if (endTime.toString().charAt(0) === '+') {
endTime = endTime.substr(1);
}
this.exponentialRampToValueAtTime(value, now + this.toSeconds(endTime));
};
- /**
- * Schedules an linear continuous change in parameter value from
- * the current time and current value to the given value at the given time.
- *
- * @param {number} value
- * @param {Tone.Time} endTime
- */
Tone.Signal.prototype.linearRampToValueNow = function (value, endTime) {
var now = this.now();
this.setCurrentValueNow(now);
value *= this._syncRatio;
- //make sure that the endTime doesn't start with +
if (endTime.toString().charAt(0) === '+') {
endTime = endTime.substr(1);
}
this._scalar.gain.linearRampToValueAtTime(value, now + this.toSeconds(endTime));
};
- /**
- * Start exponentially approaching the target value at the given time with
- * a rate having the given time constant.
- *
- * @param {number} value
- * @param {Tone.Time} startTime
- * @param {number} timeConstant
- */
Tone.Signal.prototype.setTargetAtTime = function (value, startTime, timeConstant) {
value *= this._syncRatio;
this._scalar.gain.setTargetAtTime(value, this.toSeconds(startTime), timeConstant);
};
- /**
- * Sets an array of arbitrary parameter values starting at the given time
- * for the given duration.
- *
- * @param {Array} values
- * @param {Tone.Time} startTime
- * @param {Tone.Time} duration
- */
Tone.Signal.prototype.setValueCurveAtTime = function (values, startTime, duration) {
for (var i = 0; i < values.length; i++) {
values[i] *= this._syncRatio;
}
this._scalar.gain.setValueCurveAtTime(values, this.toSeconds(startTime), this.toSeconds(duration));
};
- /**
- * Cancels all scheduled parameter changes with times greater than or
- * equal to startTime.
- *
- * @param {Tone.Time} startTime
- */
Tone.Signal.prototype.cancelScheduledValues = function (startTime) {
this._scalar.gain.cancelScheduledValues(this.toSeconds(startTime));
};
- /**
- * Sync this to another signal and it will always maintain the
- * ratio between the two signals until it is unsynced
- *
- * Signals can only be synced to one other signal. while syncing,
- * if a signal's value is changed, the new ratio between the signals
- * is maintained as the syncing signal is changed.
- *
- * @param {Tone.Signal} signal to sync to
- * @param {number=} ratio optionally pass in the ratio between
- * the two signals, otherwise it will be computed
- */
Tone.Signal.prototype.sync = function (signal, ratio) {
if (ratio) {
this._syncRatio = ratio;
} else {
- //get the sync ratio
if (signal.getValue() !== 0) {
this._syncRatio = this.getValue() / signal.getValue();
} else {
this._syncRatio = 0;
}
}
- //make a new scalar which is not connected to the constant signal
this._scalar.disconnect();
this._scalar = this.context.createGain();
this.connectSeries(signal, this._scalar, this.output);
- //set it ot the sync ratio
this._scalar.gain.value = this._syncRatio;
};
- /**
- * unbind the signal control
- *
- * will leave the signal value as it was without the influence of the control signal
- */
Tone.Signal.prototype.unsync = function () {
- //make a new scalar so that it's disconnected from the control signal
- //get the current gain
var currentGain = this.getValue();
this._scalar.disconnect();
this._scalar = this.context.createGain();
this._scalar.gain.value = currentGain / this._syncRatio;
this._syncRatio = 1;
- //reconnect things up
Tone.Signal._constant.chain(this._scalar, this.output);
};
- /**
- * internal dispose method to tear down the node
- */
Tone.Signal.prototype.dispose = function () {
Tone.prototype.dispose.call(this);
this._scalar.disconnect();
this._scalar = null;
};
- //defines getter / setter for value
Object.defineProperty(Tone.Signal.prototype, 'value', {
get: function () {
return this.getValue();
@@ -2903,29 +2436,8 @@ Tone_signal_Signal = function (Tone) {
this.setValue(val);
}
});
- ///////////////////////////////////////////////////////////////////////////
- // STATIC
- ///////////////////////////////////////////////////////////////////////////
- /**
- * the constant signal generator
- * @static
- * @private
- * @const
- * @type {OscillatorNode}
- */
Tone.Signal._generator = null;
- /**
- * the signal generator waveshaper. makes the incoming signal
- * only output 1 for all inputs.
- * @static
- * @private
- * @const
- * @type {Tone.WaveShaper}
- */
Tone.Signal._constant = null;
- /**
- * initializer function
- */
Tone._initAudioContext(function (audioContext) {
Tone.Signal._generator = audioContext.createOscillator();
Tone.Signal._constant = new Tone.WaveShaper([
@@ -2938,30 +2450,13 @@ Tone_signal_Signal = function (Tone) {
});
return Tone.Signal;
}(Tone_core_Tone);
+/** Tone.js module by Yotam Mann, MIT License 2014 http://opensource.org/licenses/MIT **/
var Tone_signal_Add;
Tone_signal_Add = function (Tone) {
'use strict';
- /**
- * @class Add a signal and a number or two signals.
- * input 0: augend. input 1: addend
- *
- * @constructor
- * @extends {Tone.SignalBase}
- * @param {number=} value if no value is provided, Tone.Add will sum the first
- * and second inputs.
- */
Tone.Add = function (value) {
Tone.call(this, 2, 0);
- /**
- * the summing node
- * @type {GainNode}
- * @private
- */
this._sum = this.input[0] = this.input[1] = this.output = this.context.createGain();
- /**
- * @private
- * @type {Tone.Signal}
- */
this._value = null;
if (isFinite(value)) {
this._value = new Tone.Signal(value);
@@ -2969,11 +2464,6 @@ Tone_signal_Add = function (Tone) {
}
};
Tone.extend(Tone.Add, Tone.SignalBase);
- /**
- * set the constant
- *
- * @param {number} value
- */
Tone.Add.prototype.setValue = function (value) {
if (this._value !== null) {
this._value.setValue(value);
@@ -2981,9 +2471,6 @@ Tone_signal_Add = function (Tone) {
throw new Error('cannot switch from signal to number');
}
};
- /**
- * dispose method
- */
Tone.Add.prototype.dispose = function () {
Tone.prototype.dispose.call(this);
this._sum = null;
@@ -2994,49 +2481,20 @@ Tone_signal_Add = function (Tone) {
};
return Tone.Add;
}(Tone_core_Tone);
+/** Tone.js module by Yotam Mann, MIT License 2014 http://opensource.org/licenses/MIT **/
var Tone_signal_Multiply;
Tone_signal_Multiply = function (Tone) {
'use strict';
- /**
- * @class Multiply the incoming signal by a number or Multiply two signals.
- * input 0: multiplicand.
- * input 1: multiplier.
- *
- * @constructor
- * @extends {Tone.SignalBase}
- * @param {number=} value constant value to multiple. if no value is provided
- * it will be multiplied by the value of input 1.
- */
Tone.Multiply = function (value) {
Tone.call(this, 2, 0);
- /**
- * the input node is the same as the output node
- * it is also the GainNode which handles the scaling of incoming signal
- *
- * @type {GainNode}
- * @private
- */
this._mult = this.input[0] = this.output = this.context.createGain();
- /**
- * the scaling parameter
- * @type {AudioParam}
- * @private
- */
this._factor = this.input[1] = this.output.gain;
this._factor.value = this.defaultArg(value, 0);
};
Tone.extend(Tone.Multiply, Tone.SignalBase);
- /**
- * set the constant multiple
- *
- * @param {number} value
- */
Tone.Multiply.prototype.setValue = function (value) {
this._factor.value = value;
};
- /**
- * clean up
- */
Tone.Multiply.prototype.dispose = function () {
Tone.prototype.dispose.call(this);
this._mult = null;
@@ -3044,73 +2502,31 @@ Tone_signal_Multiply = function (Tone) {
};
return Tone.Multiply;
}(Tone_core_Tone);
+/** Tone.js module by Yotam Mann, MIT License 2014 http://opensource.org/licenses/MIT **/
var Tone_signal_Scale;
Tone_signal_Scale = function (Tone) {
'use strict';
- /**
- * @class performs a linear scaling on an input signal.
- * Scales a normal gain input range [0,1] to between
- * outputMin and outputMax
- *
- * @constructor
- * @extends {Tone.SignalBase}
- * @param {number} [outputMin=0]
- * @param {number} [outputMax=1]
- */
Tone.Scale = function (outputMin, outputMax) {
- /**
- * @private
- * @type {number}
- */
this._outputMin = this.defaultArg(outputMin, 0);
- /**
- * @private
- * @type {number}
- */
this._outputMax = this.defaultArg(outputMax, 1);
- /**
- * @private
- * @type {Tone.Multiply}
- * @private
- */
this._scale = this.input = new Tone.Multiply(1);
- /**
- * @private
- * @type {Tone.Add}
- * @private
- */
this._add = this.output = new Tone.Add(0);
this._scale.connect(this._add);
this._setRange();
};
Tone.extend(Tone.Scale, Tone.SignalBase);
- /**
- * set the minimum output value
- * @param {number} min the minimum output value
- */
Tone.Scale.prototype.setMin = function (min) {
this._outputMin = min;
this._setRange();
};
- /**
- * set the minimum output value
- * @param {number} min the minimum output value
- */
Tone.Scale.prototype.setMax = function (max) {
this._outputMax = max;
this._setRange();
};
- /**
- * set the values
- * @private
- */
Tone.Scale.prototype._setRange = function () {
this._add.setValue(this._outputMin);
this._scale.setValue(this._outputMax - this._outputMin);
};
- /**
- * clean up
- */
Tone.Scale.prototype.dispose = function () {
Tone.prototype.dispose.call(this);
this._add.dispose();
@@ -5654,67 +5070,23 @@ reverb = function () {
}
};
}(master, sndcore);
+/** Tone.js module by Yotam Mann, MIT License 2014 http://opensource.org/licenses/MIT **/
var Tone_core_Clock;
Tone_core_Clock = function (Tone) {
'use strict';
- /**
- * @class a sample accurate clock built on an oscillator.
- * Invokes the onTick method at the set rate
- * NB: can cause audio glitches. use sparingly.
- *
- * @internal
- * @constructor
- * @extends {Tone}
- * @param {number} rate the rate of the callback
- * @param {function} callback the callback to be invoked with the time of the audio event
- * NB: it is very important that only
- */
Tone.Clock = function (rate, callback) {
- /**
- * the oscillator
- * @type {OscillatorNode}
- * @private
- */
this._oscillator = null;
- /**
- * the script processor which listens to the oscillator
- * @type {ScriptProcessorNode}
- * @private
- */
this._jsNode = this.context.createScriptProcessor(this.bufferSize, 1, 1);
this._jsNode.onaudioprocess = this._processBuffer.bind(this);
- /**
- * the rate control signal
- * @type {Tone.Signal}
- * @private
- */
this._controlSignal = new Tone.Signal(1);
- /**
- * whether the tick is on the up or down
- * @type {boolean}
- * @private
- */
this._upTick = false;
- /**
- * the callback which is invoked on every tick
- * with the time of that tick as the argument
- * @type {function(number)}
- */
this.tick = this.defaultArg(callback, function () {
});
- //setup
this._jsNode.noGC();
this.setRate(rate);
};
Tone.extend(Tone.Clock);
- /**
- * set the rate of the clock
- * optionally ramp to the rate over the rampTime
- * @param {Tone.Time} rate
- * @param {Tone.Time=} rampTime
- */
Tone.Clock.prototype.setRate = function (rate, rampTime) {
- //convert the time to a to frequency
var freqVal = this.secondsToFrequency(this.toSeconds(rate));
if (!rampTime) {
this._controlSignal.cancelScheduledValues(0);
@@ -5723,24 +5095,13 @@ Tone_core_Clock = function (Tone) {
this._controlSignal.exponentialRampToValueNow(freqVal, rampTime);
}
};
- /**
- * return the current rate
- *
- * @return {number}
- */
Tone.Clock.prototype.getRate = function () {
return this._controlSignal.getValue();
};
- /**
- * start the clock
- * @param {Tone.Time} time the time when the clock should start
- */
Tone.Clock.prototype.start = function (time) {
- //reset the oscillator
this._oscillator = this.context.createOscillator();
this._oscillator.type = 'square';
this._oscillator.connect(this._jsNode);
- //connect it up
this._controlSignal.connect(this._oscillator.frequency);
this._upTick = false;
var startTime = this.toSeconds(time);
@@ -5748,20 +5109,11 @@ Tone_core_Clock = function (Tone) {
this._oscillator.onended = function () {
};
};
- /**
- * stop the clock
- * @param {Tone.Time} time the time when the clock should stop
- * @param {function} onend called when the oscilator stops
- */
Tone.Clock.prototype.stop = function (time, onend) {
var stopTime = this.toSeconds(time);
this._oscillator.onended = onend;
this._oscillator.stop(stopTime);
};
- /**
- * @private
- * @param {AudioProcessingEvent} event
- */
Tone.Clock.prototype._processBuffer = function (event) {
var now = this.defaultArg(event.playbackTime, this.now());
var bufferSize = this._jsNode.bufferSize;
@@ -5772,9 +5124,7 @@ Tone_core_Clock = function (Tone) {
var sample = incomingBuffer[i];
if (sample > 0 && !upTick) {
upTick = true;
- //get the callback out of audio thread
setTimeout(function () {
- //to account for the double buffering
var tickTime = now + self.samplesToSeconds(i + bufferSize * 2);
return function () {
self.tick(tickTime);
@@ -5786,9 +5136,6 @@ Tone_core_Clock = function (Tone) {
}
this._upTick = upTick;
};
- /**
- * clean up
- */
Tone.Clock.prototype.dispose = function () {
this._jsNode.disconnect();
this._controlSignal.dispose();
diff --git a/lib/p5.sound.min.js b/lib/p5.sound.min.js
index 56e206c9..b0a1028e 100644
--- a/lib/p5.sound.min.js
+++ b/lib/p5.sound.min.js
@@ -1,5 +1,5 @@
-/*! p5.sound.min.js v0.1.7 2015-01-27 */
+/*! p5.sound.min.js v0.1.7 2015-01-30 */
-var sndcore;sndcore=function(){"use strict";window.AudioContext=window.AudioContext||window.webkitAudioContext;var t=new window.AudioContext;p5.prototype.getAudioContext=function(){return t},"function"!=typeof t.createGain&&(window.audioContext.createGain=window.audioContext.createGainNode),"function"!=typeof t.createDelay&&(window.audioContext.createDelay=window.audioContext.createDelayNode),"function"!=typeof window.AudioBufferSourceNode.prototype.start&&(window.AudioBufferSourceNode.prototype.start=window.AudioBufferSourceNode.prototype.noteGrainOn),"function"!=typeof window.AudioBufferSourceNode.prototype.stop&&(window.AudioBufferSourceNode.prototype.stop=window.AudioBufferSourceNode.prototype.noteOff),"function"!=typeof window.OscillatorNode.prototype.start&&(window.OscillatorNode.prototype.start=window.OscillatorNode.prototype.noteOn),"function"!=typeof window.OscillatorNode.prototype.stop&&(window.OscillatorNode.prototype.stop=window.OscillatorNode.prototype.noteOff),window.AudioContext.prototype.hasOwnProperty("createScriptProcessor")||(window.AudioContext.prototype.createScriptProcessor=window.AudioContext.prototype.createJavaScriptNode),navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;var e=document.createElement("audio");p5.prototype.isSupported=function(){return!!e.canPlayType};var i=function(){return!!e.canPlayType&&e.canPlayType('audio/ogg; codecs="vorbis"')},o=function(){return!!e.canPlayType&&e.canPlayType("audio/mpeg;")},n=function(){return!!e.canPlayType&&e.canPlayType('audio/wav; codecs="1"')},s=function(){return!!e.canPlayType&&(e.canPlayType("audio/x-m4a;")||e.canPlayType("audio/aac;"))},r=function(){return!!e.canPlayType&&e.canPlayType("audio/x-aiff;")};p5.prototype.isFileSupported=function(t){switch(t.toLowerCase()){case"mp3":return o();case"wav":return n();case"ogg":return i();case"mp4":return s();case"aiff":return r();default:return!1}};var a=navigator.userAgent.match(/(iPad|iPhone|iPod)/g)?!0:!1;a&&window.addEventListener("touchstart",function(){var e=t.createBuffer(1,1,22050),i=t.createBufferSource();i.buffer=e,i.connect(t.destination),i.start(0)},!1)}();var master;master=function(){"use strict";var t=function(){var t=p5.prototype.getAudioContext();this.input=t.createGain(),this.output=t.createGain(),this.limiter=t.createDynamicsCompressor(),this.limiter.threshold.value=0,this.limiter.ratio.value=100,this.audiocontext=t,this.output.disconnect(this.audiocontext.destination),this.inputSources=[],this.input.connect(this.limiter),this.limiter.connect(this.output),this.meter=t.createGain(),this.output.connect(this.meter),this.output.connect(this.audiocontext.destination),this.soundArray=[],this.parts=[],this.extensions=[]},e=new t;return p5.soundOut=e,p5.soundOut._silentNode=e.audiocontext.createGain(),p5.soundOut._silentNode.gain.value=0,p5.soundOut._silentNode.connect(e.audiocontext.destination),e}(sndcore);var helpers;helpers=function(){"use strict";var t=master;p5.prototype.masterVolume=function(e){t.output.gain.value=e},p5.prototype.sampleRate=function(){return t.audiocontext.sampleRate},p5.prototype.getMasterVolume=function(){return t.output.gain.value},p5.prototype.freqToMidi=function(t){var e=Math.log(t/440)/Math.log(2),i=Math.round(12*e)+57;return i},p5.prototype.midiToFreq=function(t){return 440*Math.pow(2,(t-69)/12)},p5.prototype.soundFormats=function(){t.extensions=[];for(var e=0;e-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){var n=p5.prototype.isFileSupported(o);if(n)i=i;else for(var s=i.split("."),r=s[s.length-1],a=0;a1?(this.splitter=e.createChannelSplitter(2),this.input.connect(this.splitter),this.splitter.connect(this.left,1),this.splitter.connect(this.right,0)):(this.input.connect(this.left),this.input.connect(this.right)),this.output=e.createChannelMerger(2),this.left.connect(this.output,0,1),this.right.connect(this.output,0,0),this.output.connect(i)},p5.Panner.prototype.pan=function(t,i){var o=i||0,n=e.currentTime+o,s=(t+1)/2,r=Math.cos(s*Math.PI/2),a=Math.sin(s*Math.PI/2);this.left.gain.linearRampToValueAtTime(r,n),this.right.gain.linearRampToValueAtTime(a,n)},p5.Panner.prototype.inputChannels=function(t){1===t?(this.input.disconnect(),this.input.connect(this.left),this.input.connect(this.right)):2===t&&(this.splitter=e.createChannelSplitter(2),this.input.disconnect(),this.input.connect(this.splitter),this.splitter.connect(this.left,1),this.splitter.connect(this.right,0))},p5.Panner.prototype.connect=function(t){this.output.connect(t)},p5.Panner.prototype.disconnect=function(){this.output.disconnect()},p5.Panner3D=function(t,i){var o=e.createPanner();return o.panningModel="HRTF",o.distanceModel="linear",o.setPosition(0,0,0),t.connect(o),o.connect(i),o.pan=function(t,e,i){o.setPosition(t,e,i)},o}}(master);var soundfile;soundfile=function(){"use strict";var t=master;p5.SoundFile=function(e,i,o){var n=p5.prototype._checkFileFormats(e);this.url=n,this.sources=[],this.source=null,this.buffer=null,this.playbackRate=1,this.gain=1,this.input=t.audiocontext.createGain(),this.output=t.audiocontext.createGain(),this.reversed=!1,this.startTime=0,this.endTime=null,this.playing=!1,this.paused=null,this.mode="sustain",this.startMillis=null,this.amplitude=new p5.Amplitude,this.output.connect(this.amplitude.input),this.panPosition=0,this.panner=new p5.Panner(this.output,t.input,2),this.url&&this.load(i),t.soundArray.push(this),this.whileLoading="function"==typeof o?o:function(){}},p5.prototype.registerPreloadMethod("loadSound"),p5.prototype.loadSound=function(t,e,i){window.location.origin.indexOf("file://")>-1&&alert("This sketch may require a server to load external files. Please see http://bit.ly/1qcInwS");var o=new p5.SoundFile(t,e,i);return o},p5.SoundFile.prototype.load=function(t){var e=this,i=new XMLHttpRequest;i.addEventListener("progress",function(t){e._updateProgress(t)},!1),i.open("GET",this.url,!0),i.responseType="arraybuffer";var o=this;i.onload=function(){var e=p5.prototype.getAudioContext();e.decodeAudioData(i.response,function(e){o.buffer=e,o.panner.inputChannels(e.numberOfChannels),t&&t(o)})},i.send()},p5.SoundFile.prototype._updateProgress=function(t){if(t.lengthComputable){var e=Math.log(t.loaded/t.total*9.9);this.whileLoading(e)}else console.log("size unknown")},p5.SoundFile.prototype.isLoaded=function(){return this.buffer?!0:!1},p5.SoundFile.prototype.play=function(e,i,o,n,s){var r=t.audiocontext.currentTime,e=e||0;if(0>e&&(e=0),!this.buffer)throw"not ready to play file, buffer has yet to load. Try preload()";if("restart"===this.mode&&this.buffer&&this.source){var r=t.audiocontext.currentTime;this.source.stop(e)}if(n){if(!(n>=0&&n=0&&s<=this.buffer.duration))throw"end time out of range";this.endTime=s}else this.endTime=this.buffer.duration;if(this.source=t.audiocontext.createBufferSource(),this.source.buffer=this.buffer,this.source.loop=this.looping,this.source.loop===!0&&(this.source.loopStart=this.startTime,this.source.loopEnd=this.endTime),this.source.onended=function(){},this.source.gain)this.source.gain.value=o||1,this.source.connect(this.output);else{this.source.gain=t.audiocontext.createGain(),this.source.connect(this.source.gain);var a=o||1;this.source.gain.gain.setValueAtTime(a,t.audiocontext.currentTime),this.source.gain.connect(this.output)}this.source.playbackRate.cancelScheduledValues(r),i=i||Math.abs(this.playbackRate),this.source.playbackRate.setValueAtTime(i,r),this.paused&&(this.wasUnpaused=!0),this.paused&&this.wasUnpaused?this.source.start(e,this.pauseTime,this.endTime):(this.wasUnpaused=!1,this.pauseTime=0,this.source.start(e,this.startTime,this.endTime)),this.startSeconds=e+r,this.playing=!0,this.paused=!1,this.sources.push(this.source)},p5.SoundFile.prototype.playMode=function(e){var i=e.toLowerCase();if("restart"===i&&this.buffer&&this.source)for(var o=0;o0&&this.reversed&&this.reverseBuffer();if(this.source){var s=t.audiocontext.currentTime;this.source.playbackRate.cancelScheduledValues(s),this.source.playbackRate.linearRampToValueAtTime(Math.abs(i),s)}}},p5.SoundFile.prototype.getPlaybackRate=function(){return this.playbackRate},p5.SoundFile.prototype.duration=function(){return this.buffer?this.buffer.duration:0},p5.SoundFile.prototype.currentTime=function(){var e;if(this.isPlaying()){var i=t.audiocontext.currentTime-this.startSeconds+this.startTime+this.pauseTime;return e=i*this.playbackRate%(this.duration()*this.playbackRate),console.log("1"),e}return this.paused?this.pauseTime:this.startTime},p5.SoundFile.prototype.jump=function(e,i){if(0>e||e>this.buffer.duration)throw"jump time out of range";if(e>i||i>this.buffer.duration)throw"end time out of range";if(this.startTime=e||0,this.endTime=i?i:this.buffer.duration,this.isPlaying()){var o=t.audiocontext.currentTime;this.stop(o),this.play(e,this.endTime)}},p5.SoundFile.prototype.channels=function(){return this.buffer.numberOfChannels},p5.SoundFile.prototype.sampleRate=function(){return this.buffer.sampleRate},p5.SoundFile.prototype.frames=function(){return this.buffer.length},p5.SoundFile.prototype.getPeaks=function(t){if(!this.buffer)throw"Cannot load peaks yet, buffer is not loaded";if(t||(t=5*window.width),this.buffer){for(var e=this.buffer,i=e.length/t,o=~~(i/10)||1,n=e.numberOfChannels,s=new Float32Array(Math.round(t)),r=0;n>r;r++)for(var a=e.getChannelData(r),u=0;t>u;u++){for(var c=~~(u*i),p=~~(c+i),h=0,l=c;p>l;l+=o){var d=a[l];d>h?h=d:-d>h&&(h=d)}(0===r||h>s[u])&&(s[u]=h)}return s}},p5.SoundFile.prototype.reverseBuffer=function(){var t=this.getVolume();if(this.setVolume(0,.01,0),this.pause(),!this.buffer)throw"SoundFile is not done loading";Array.prototype.reverse.call(this.buffer.getChannelData(0)),Array.prototype.reverse.call(this.buffer.getChannelData(1)),this.reversed=!this.reversed,this.setVolume(t,.01,.0101),this.play()},p5.SoundFile.prototype._onEnded=function(e){e.onended=function(e){var i=t.audiocontext.currentTime;e.stop(i)}},p5.SoundFile.prototype.add=function(){},p5.SoundFile.prototype.dispose=function(){if(this.buffer&&this.source)for(var e=0;er;r++)e=i[r],this.normalize?(n+=Math.max(Math.min(e/this.volMax,1),-1),s+=Math.max(Math.min(e/this.volMax,1),-1)*Math.max(Math.min(e/this.volMax,1),-1)):(n+=e,s+=e*e);var a=Math.sqrt(s/o);this.volume=Math.max(a,this.volume*this.smoothing),this.volMax=Math.max(this.volume,this.volMax),this.volNorm=Math.max(Math.min(this.volume/this.volMax,1),0)},p5.Amplitude.prototype.getLevel=function(){return this.normalize?this.volNorm:this.volume},p5.Amplitude.prototype.toggleNormalize=function(t){this.normalize="boolean"==typeof t?t:!this.normalize},p5.Amplitude.prototype.smooth=function(t){t>=0&&1>t?this.smoothing=t:console.log("Error: smoothing must be between 0 and 1")}}(master);var fft;fft=function(){"use strict";var t=master;p5.FFT=function(e,i){var o=e||.8;0===e&&(o=e);var n=2*i||2048;this.analyser=t.audiocontext.createAnalyser(),t.output.connect(this.analyser),this.analyser.smoothingTimeConstant=o,this.analyser.fftSize=n,this.freqDomain=new Uint8Array(this.analyser.frequencyBinCount),this.timeDomain=new Uint8Array(this.analyser.frequencyBinCount),this.bass=[20,140],this.lowMid=[140,400],this.mid=[400,2600],this.highMid=[2600,5200],this.treble=[5200,14e3]},p5.FFT.prototype.setInput=function(t,e){e&&(this.analyser.fftSize=2*e),t.output?t.output.connect(this.analyser):t.connect(this.analyser)},p5.FFT.prototype.waveform=function(t){t&&(this.analyser.fftSize=2*t),this.analyser.getByteTimeDomainData(this.timeDomain);var e=Array.apply([],this.timeDomain);return e.length===this.analyser.fftSize,e.constructor===Array,e},p5.FFT.prototype.analyze=function(t){t&&(this.analyser.fftSize=2*t),this.analyser.getByteFrequencyData(this.freqDomain);var e=Array.apply([],this.freqDomain);return e.length===this.analyser.fftSize,e.constructor===Array,e},p5.FFT.prototype.getEnergy=function(e,i){var o=t.audiocontext.sampleRate/2;if("bass"===e?(e=this.bass[0],i=this.bass[1]):"lowMid"===e?(e=this.lowMid[0],i=this.lowMid[1]):"mid"===e?(e=this.mid[0],i=this.mid[1]):"highMid"===e?(e=this.highMid[0],i=this.highMid[1]):"treble"===e&&(e=this.treble[0],i=this.treble[1]),"number"!=typeof e)throw"invalid input for getEnergy()";if(i){if(e&&i){if(e>i){var n=i;i=e,e=n}for(var s=Math.round(e/o*this.freqDomain.length),r=Math.round(i/o*this.freqDomain.length),a=0,u=0,c=s;r>=c;c++)a+=this.freqDomain[c],u+=1;var p=a/u;return p}throw"invalid input for getEnergy()"}var h=Math.round(e/o*this.freqDomain.length);return this.freqDomain[h]},p5.FFT.prototype.getFreq=function(t,e){console.log("getFreq() is deprecated. Please use getEnergy() instead.");var i=this.getEnergy(t,e);return i},p5.FFT.prototype.smooth=function(t){this.analyser.smoothingTimeConstant=t}}(master);var Tone_core_Tone;Tone_core_Tone=function(){"use strict";function t(t){return void 0===t}var e;if(t(window.AudioContext)&&(window.AudioContext=window.webkitAudioContext),t(window.OfflineAudioContext)&&(window.OfflineAudioContext=window.webkitOfflineAudioContext),t(AudioContext))throw new Error("Web Audio is not supported in this browser");e=new AudioContext,"function"!=typeof AudioContext.prototype.createGain&&(AudioContext.prototype.createGain=AudioContext.prototype.createGainNode),"function"!=typeof AudioContext.prototype.createDelay&&(AudioContext.prototype.createDelay=AudioContext.prototype.createDelayNode),"function"!=typeof AudioContext.prototype.createPeriodicWave&&(AudioContext.prototype.createPeriodicWave=AudioContext.prototype.createWaveTable),"function"!=typeof AudioBufferSourceNode.prototype.start&&(AudioBufferSourceNode.prototype.start=AudioBufferSourceNode.prototype.noteGrainOn),"function"!=typeof AudioBufferSourceNode.prototype.stop&&(AudioBufferSourceNode.prototype.stop=AudioBufferSourceNode.prototype.noteOff),"function"!=typeof OscillatorNode.prototype.start&&(OscillatorNode.prototype.start=OscillatorNode.prototype.noteOn),"function"!=typeof OscillatorNode.prototype.stop&&(OscillatorNode.prototype.stop=OscillatorNode.prototype.noteOff),"function"!=typeof OscillatorNode.prototype.setPeriodicWave&&(OscillatorNode.prototype.setPeriodicWave=OscillatorNode.prototype.setWaveTable),AudioNode.prototype._nativeConnect=AudioNode.prototype.connect,AudioNode.prototype.connect=function(e,i,o){if(e.input)Array.isArray(e.input)?(t(o)&&(o=0),this.connect(e.input[o])):this.connect(e.input,i,o);else try{e instanceof AudioNode?this._nativeConnect(e,i,o):this._nativeConnect(e,i)}catch(n){throw new Error("error connecting to node: "+e)}};var i=function(e,i){t(e)||1===e?this.input=this.context.createGain():e>1&&(this.input=new Array(e)),t(i)||1===i?this.output=this.context.createGain():i>1&&(this.output=new Array(e))};i.context=e,i.prototype.context=i.context,i.prototype.bufferSize=2048,i.prototype.bufferTime=i.prototype.bufferSize/i.context.sampleRate,i.prototype.connect=function(t,e,i){Array.isArray(this.output)?(e=this.defaultArg(e,0),this.output[e].connect(t,0,i)):this.output.connect(t,e,i)},i.prototype.disconnect=function(t){Array.isArray(this.output)?(t=this.defaultArg(t,0),this.output[t].disconnect()):this.output.disconnect()},i.prototype.connectSeries=function(){if(arguments.length>1)for(var t=arguments[0],e=1;e1)for(var e=1;e0)for(var t=this,e=0;e0)for(var t=1;ti){var o=i;i=e,e=o}else if(e==i)return 0;return(t-e)/(i-e)},i.prototype.dispose=function(){this.isUndef(this.input)||(this.input instanceof AudioNode&&this.input.disconnect(),this.input=null),this.isUndef(this.output)||(this.output instanceof AudioNode&&this.output.disconnect(),this.output=null)};var o=null;i.prototype.noGC=function(){this.output.connect(o)},AudioNode.prototype.noGC=function(){this.connect(o)},i.prototype.now=function(){return this.context.currentTime},i.prototype.samplesToSeconds=function(t){return t/this.context.sampleRate},i.prototype.toSamples=function(t){var e=this.toSeconds(t);return Math.round(e*this.context.sampleRate)},i.prototype.toSeconds=function(t,e){if(e=this.defaultArg(e,this.now()),"number"==typeof t)return t;if("string"==typeof t){var i=0;return"+"===t.charAt(0)&&(t=t.slice(1),i=e),parseFloat(t)+i}return e},i.prototype.frequencyToSeconds=function(t){return 1/parseFloat(t)},i.prototype.secondsToFrequency=function(t){return 1/t};var n=[];return i._initAudioContext=function(t){t(i.context),n.push(t)},i.setContext=function(t){i.prototype.context=t,i.context=t;for(var e=0;ee;e++){var o=e/i*2-1,n=e/(i-1)*2-1;this._curve[e]=t(o,e,n)}this._shaper.curve=this._curve},t.WaveShaper.prototype.setCurve=function(t){if(this._isSafari()){var e=t[0];t.unshift(e)}this._curve=new Float32Array(t),this._shaper.curve=this._curve},t.WaveShaper.prototype.setOversample=function(t){this._shaper.oversample=t},t.WaveShaper.prototype._isSafari=function(){var t=navigator.userAgent.toLowerCase();return-1!==t.indexOf("safari")&&-1===t.indexOf("chrome")},t.WaveShaper.prototype.dispose=function(){t.prototype.dispose.call(this),this._shaper.disconnect(),this._shaper=null,this._curve=null},t.WaveShaper}(Tone_core_Tone);var Tone_signal_Signal;Tone_signal_Signal=function(t){"use strict";return t.Signal=function(e){this._scalar=this.context.createGain(),this.input=this.output=this.context.createGain(),this._syncRatio=1,this.value=this.defaultArg(e,0),t.Signal._constant.chain(this._scalar,this.output)},t.extend(t.Signal,t.SignalBase),t.Signal.prototype.getValue=function(){return this._scalar.gain.value},t.Signal.prototype.setValue=function(t){0===this._syncRatio?t=0:t*=this._syncRatio,this._scalar.gain.value=t},t.Signal.prototype.setValueAtTime=function(t,e){t*=this._syncRatio,this._scalar.gain.setValueAtTime(t,this.toSeconds(e))},t.Signal.prototype.setCurrentValueNow=function(t){t=this.defaultArg(t,this.now());var e=this.getValue();return this.cancelScheduledValues(t),this._scalar.gain.setValueAtTime(e,t),e},t.Signal.prototype.linearRampToValueAtTime=function(t,e){t*=this._syncRatio,this._scalar.gain.linearRampToValueAtTime(t,this.toSeconds(e))},t.Signal.prototype.exponentialRampToValueAtTime=function(t,e){t*=this._syncRatio;try{this._scalar.gain.exponentialRampToValueAtTime(t,this.toSeconds(e))}catch(i){this._scalar.gain.linearRampToValueAtTime(t,this.toSeconds(e))}},t.Signal.prototype.exponentialRampToValueNow=function(t,e){var i=this.now();this.setCurrentValueNow(i),"+"===e.toString().charAt(0)&&(e=e.substr(1)),this.exponentialRampToValueAtTime(t,i+this.toSeconds(e))},t.Signal.prototype.linearRampToValueNow=function(t,e){var i=this.now();this.setCurrentValueNow(i),t*=this._syncRatio,"+"===e.toString().charAt(0)&&(e=e.substr(1)),this._scalar.gain.linearRampToValueAtTime(t,i+this.toSeconds(e))},t.Signal.prototype.setTargetAtTime=function(t,e,i){t*=this._syncRatio,this._scalar.gain.setTargetAtTime(t,this.toSeconds(e),i)},t.Signal.prototype.setValueCurveAtTime=function(t,e,i){for(var o=0;o-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){var n=p5.prototype.isFileSupported(o);if(n)i=i;else for(var s=i.split("."),r=s[s.length-1],a=0;a1?(this.splitter=e.createChannelSplitter(2),this.input.connect(this.splitter),this.splitter.connect(this.left,1),this.splitter.connect(this.right,0)):(this.input.connect(this.left),this.input.connect(this.right)),this.output=e.createChannelMerger(2),this.left.connect(this.output,0,1),this.right.connect(this.output,0,0),this.output.connect(i)},p5.Panner.prototype.pan=function(t,i){var o=i||0,n=e.currentTime+o,s=(t+1)/2,r=Math.cos(s*Math.PI/2),a=Math.sin(s*Math.PI/2);this.left.gain.linearRampToValueAtTime(r,n),this.right.gain.linearRampToValueAtTime(a,n)},p5.Panner.prototype.inputChannels=function(t){1===t?(this.input.disconnect(),this.input.connect(this.left),this.input.connect(this.right)):2===t&&(this.splitter=e.createChannelSplitter(2),this.input.disconnect(),this.input.connect(this.splitter),this.splitter.connect(this.left,1),this.splitter.connect(this.right,0))},p5.Panner.prototype.connect=function(t){this.output.connect(t)},p5.Panner.prototype.disconnect=function(){this.output.disconnect()},p5.Panner3D=function(t,i){var o=e.createPanner();return o.panningModel="HRTF",o.distanceModel="linear",o.setPosition(0,0,0),t.connect(o),o.connect(i),o.pan=function(t,e,i){o.setPosition(t,e,i)},o}}(master);var soundfile;soundfile=function(){"use strict";var t=master;p5.SoundFile=function(e,i,o){var n=p5.prototype._checkFileFormats(e);this.url=n,this.sources=[],this.source=null,this.buffer=null,this.playbackRate=1,this.gain=1,this.input=t.audiocontext.createGain(),this.output=t.audiocontext.createGain(),this.reversed=!1,this.startTime=0,this.endTime=null,this.playing=!1,this.paused=null,this.mode="sustain",this.startMillis=null,this.amplitude=new p5.Amplitude,this.output.connect(this.amplitude.input),this.panPosition=0,this.panner=new p5.Panner(this.output,t.input,2),this.url&&this.load(i),t.soundArray.push(this),this.whileLoading="function"==typeof o?o:function(){}},p5.prototype.registerPreloadMethod("loadSound"),p5.prototype.loadSound=function(t,e,i){window.location.origin.indexOf("file://")>-1&&alert("This sketch may require a server to load external files. Please see http://bit.ly/1qcInwS");var o=new p5.SoundFile(t,e,i);return o},p5.SoundFile.prototype.load=function(t){var e=this,i=new XMLHttpRequest;i.addEventListener("progress",function(t){e._updateProgress(t)},!1),i.open("GET",this.url,!0),i.responseType="arraybuffer";var o=this;i.onload=function(){var e=p5.prototype.getAudioContext();e.decodeAudioData(i.response,function(e){o.buffer=e,o.panner.inputChannels(e.numberOfChannels),t&&t(o)})},i.send()},p5.SoundFile.prototype._updateProgress=function(t){if(t.lengthComputable){var e=Math.log(t.loaded/t.total*9.9);this.whileLoading(e)}else console.log("size unknown")},p5.SoundFile.prototype.isLoaded=function(){return this.buffer?!0:!1},p5.SoundFile.prototype.play=function(e,i,o,n,s){var r=t.audiocontext.currentTime,e=e||0;if(0>e&&(e=0),!this.buffer)throw"not ready to play file, buffer has yet to load. Try preload()";if("restart"===this.mode&&this.buffer&&this.source){var r=t.audiocontext.currentTime;this.source.stop(e)}if(n){if(!(n>=0&&n=0&&s<=this.buffer.duration))throw"end time out of range";this.endTime=s}else this.endTime=this.buffer.duration;if(this.source=t.audiocontext.createBufferSource(),this.source.buffer=this.buffer,this.source.loop=this.looping,this.source.loop===!0&&(this.source.loopStart=this.startTime,this.source.loopEnd=this.endTime),this.source.onended=function(){},this.source.gain)this.source.gain.value=o||1,this.source.connect(this.output);else{this.source.gain=t.audiocontext.createGain(),this.source.connect(this.source.gain);var a=o||1;this.source.gain.gain.setValueAtTime(a,t.audiocontext.currentTime),this.source.gain.connect(this.output)}this.source.playbackRate.cancelScheduledValues(r),i=i||Math.abs(this.playbackRate),this.source.playbackRate.setValueAtTime(i,r),this.paused&&(this.wasUnpaused=!0),this.paused&&this.wasUnpaused?this.source.start(e,this.pauseTime,this.endTime):(this.wasUnpaused=!1,this.pauseTime=0,this.source.start(e,this.startTime,this.endTime)),this.startSeconds=e+r,this.playing=!0,this.paused=!1,this.sources.push(this.source)},p5.SoundFile.prototype.playMode=function(e){var i=e.toLowerCase();if("restart"===i&&this.buffer&&this.source)for(var o=0;o0&&this.reversed&&this.reverseBuffer();if(this.source){var s=t.audiocontext.currentTime;this.source.playbackRate.cancelScheduledValues(s),this.source.playbackRate.linearRampToValueAtTime(Math.abs(i),s)}}},p5.SoundFile.prototype.getPlaybackRate=function(){return this.playbackRate},p5.SoundFile.prototype.duration=function(){return this.buffer?this.buffer.duration:0},p5.SoundFile.prototype.currentTime=function(){var e;if(this.isPlaying()){var i=t.audiocontext.currentTime-this.startSeconds+this.startTime+this.pauseTime;return e=i*this.playbackRate%(this.duration()*this.playbackRate),console.log("1"),e}return this.paused?this.pauseTime:this.startTime},p5.SoundFile.prototype.jump=function(e,i){if(0>e||e>this.buffer.duration)throw"jump time out of range";if(e>i||i>this.buffer.duration)throw"end time out of range";if(this.startTime=e||0,this.endTime=i?i:this.buffer.duration,this.isPlaying()){var o=t.audiocontext.currentTime;this.stop(o),this.play(e,this.endTime)}},p5.SoundFile.prototype.channels=function(){return this.buffer.numberOfChannels},p5.SoundFile.prototype.sampleRate=function(){return this.buffer.sampleRate},p5.SoundFile.prototype.frames=function(){return this.buffer.length},p5.SoundFile.prototype.getPeaks=function(t){if(!this.buffer)throw"Cannot load peaks yet, buffer is not loaded";if(t||(t=5*window.width),this.buffer){for(var e=this.buffer,i=e.length/t,o=~~(i/10)||1,n=e.numberOfChannels,s=new Float32Array(Math.round(t)),r=0;n>r;r++)for(var a=e.getChannelData(r),u=0;t>u;u++){for(var c=~~(u*i),p=~~(c+i),h=0,l=c;p>l;l+=o){var d=a[l];d>h?h=d:-d>h&&(h=d)}(0===r||h>s[u])&&(s[u]=h)}return s}},p5.SoundFile.prototype.reverseBuffer=function(){var t=this.getVolume();if(this.setVolume(0,.01,0),this.pause(),!this.buffer)throw"SoundFile is not done loading";Array.prototype.reverse.call(this.buffer.getChannelData(0)),Array.prototype.reverse.call(this.buffer.getChannelData(1)),this.reversed=!this.reversed,this.setVolume(t,.01,.0101),this.play()},p5.SoundFile.prototype._onEnded=function(e){e.onended=function(e){var i=t.audiocontext.currentTime;e.stop(i)}},p5.SoundFile.prototype.add=function(){},p5.SoundFile.prototype.dispose=function(){if(this.buffer&&this.source)for(var e=0;er;r++)e=i[r],this.normalize?(n+=Math.max(Math.min(e/this.volMax,1),-1),s+=Math.max(Math.min(e/this.volMax,1),-1)*Math.max(Math.min(e/this.volMax,1),-1)):(n+=e,s+=e*e);var a=Math.sqrt(s/o);this.volume=Math.max(a,this.volume*this.smoothing),this.volMax=Math.max(this.volume,this.volMax),this.volNorm=Math.max(Math.min(this.volume/this.volMax,1),0)},p5.Amplitude.prototype.getLevel=function(){return this.normalize?this.volNorm:this.volume},p5.Amplitude.prototype.toggleNormalize=function(t){this.normalize="boolean"==typeof t?t:!this.normalize},p5.Amplitude.prototype.smooth=function(t){t>=0&&1>t?this.smoothing=t:console.log("Error: smoothing must be between 0 and 1")}}(master);var fft;fft=function(){"use strict";var t=master;p5.FFT=function(e,i){var o=e||.8;0===e&&(o=e);var n=2*i||2048;this.analyser=t.audiocontext.createAnalyser(),t.output.connect(this.analyser),this.analyser.smoothingTimeConstant=o,this.analyser.fftSize=n,this.freqDomain=new Uint8Array(this.analyser.frequencyBinCount),this.timeDomain=new Uint8Array(this.analyser.frequencyBinCount),this.bass=[20,140],this.lowMid=[140,400],this.mid=[400,2600],this.highMid=[2600,5200],this.treble=[5200,14e3]},p5.FFT.prototype.setInput=function(t,e){e&&(this.analyser.fftSize=2*e),t.output?t.output.connect(this.analyser):t.connect(this.analyser)},p5.FFT.prototype.waveform=function(t){t&&(this.analyser.fftSize=2*t),this.analyser.getByteTimeDomainData(this.timeDomain);var e=Array.apply([],this.timeDomain);return e.length===this.analyser.fftSize,e.constructor===Array,e},p5.FFT.prototype.analyze=function(t){t&&(this.analyser.fftSize=2*t),this.analyser.getByteFrequencyData(this.freqDomain);var e=Array.apply([],this.freqDomain);return e.length===this.analyser.fftSize,e.constructor===Array,e},p5.FFT.prototype.getEnergy=function(e,i){var o=t.audiocontext.sampleRate/2;if("bass"===e?(e=this.bass[0],i=this.bass[1]):"lowMid"===e?(e=this.lowMid[0],i=this.lowMid[1]):"mid"===e?(e=this.mid[0],i=this.mid[1]):"highMid"===e?(e=this.highMid[0],i=this.highMid[1]):"treble"===e&&(e=this.treble[0],i=this.treble[1]),"number"!=typeof e)throw"invalid input for getEnergy()";if(i){if(e&&i){if(e>i){var n=i;i=e,e=n}for(var s=Math.round(e/o*this.freqDomain.length),r=Math.round(i/o*this.freqDomain.length),a=0,u=0,c=s;r>=c;c++)a+=this.freqDomain[c],u+=1;var p=a/u;return p}throw"invalid input for getEnergy()"}var h=Math.round(e/o*this.freqDomain.length);return this.freqDomain[h]},p5.FFT.prototype.getFreq=function(t,e){console.log("getFreq() is deprecated. Please use getEnergy() instead.");var i=this.getEnergy(t,e);return i},p5.FFT.prototype.smooth=function(t){this.analyser.smoothingTimeConstant=t}}(master);var Tone_core_Tone;Tone_core_Tone=function(){"use strict";function t(t){return void 0===t}var e;if(t(window.AudioContext)&&(window.AudioContext=window.webkitAudioContext),t(window.OfflineAudioContext)&&(window.OfflineAudioContext=window.webkitOfflineAudioContext),t(AudioContext))throw new Error("Web Audio is not supported in this browser");e=new AudioContext,"function"!=typeof AudioContext.prototype.createGain&&(AudioContext.prototype.createGain=AudioContext.prototype.createGainNode),"function"!=typeof AudioContext.prototype.createDelay&&(AudioContext.prototype.createDelay=AudioContext.prototype.createDelayNode),"function"!=typeof AudioContext.prototype.createPeriodicWave&&(AudioContext.prototype.createPeriodicWave=AudioContext.prototype.createWaveTable),"function"!=typeof AudioBufferSourceNode.prototype.start&&(AudioBufferSourceNode.prototype.start=AudioBufferSourceNode.prototype.noteGrainOn),"function"!=typeof AudioBufferSourceNode.prototype.stop&&(AudioBufferSourceNode.prototype.stop=AudioBufferSourceNode.prototype.noteOff),"function"!=typeof OscillatorNode.prototype.start&&(OscillatorNode.prototype.start=OscillatorNode.prototype.noteOn),"function"!=typeof OscillatorNode.prototype.stop&&(OscillatorNode.prototype.stop=OscillatorNode.prototype.noteOff),"function"!=typeof OscillatorNode.prototype.setPeriodicWave&&(OscillatorNode.prototype.setPeriodicWave=OscillatorNode.prototype.setWaveTable),AudioNode.prototype._nativeConnect=AudioNode.prototype.connect,AudioNode.prototype.connect=function(e,i,o){if(e.input)Array.isArray(e.input)?(t(o)&&(o=0),this.connect(e.input[o])):this.connect(e.input,i,o);else try{e instanceof AudioNode?this._nativeConnect(e,i,o):this._nativeConnect(e,i)}catch(n){throw new Error("error connecting to node: "+e)}};var i=function(e,i){t(e)||1===e?this.input=this.context.createGain():e>1&&(this.input=new Array(e)),t(i)||1===i?this.output=this.context.createGain():i>1&&(this.output=new Array(e))};i.context=e,i.prototype.context=i.context,i.prototype.bufferSize=2048,i.prototype.bufferTime=i.prototype.bufferSize/i.context.sampleRate,i.prototype.connect=function(t,e,i){Array.isArray(this.output)?(e=this.defaultArg(e,0),this.output[e].connect(t,0,i)):this.output.connect(t,e,i)},i.prototype.disconnect=function(t){Array.isArray(this.output)?(t=this.defaultArg(t,0),this.output[t].disconnect()):this.output.disconnect()},i.prototype.connectSeries=function(){if(arguments.length>1)for(var t=arguments[0],e=1;e1)for(var e=1;e0)for(var t=this,e=0;e0)for(var t=1;ti){var o=i;i=e,e=o}else if(e==i)return 0;return(t-e)/(i-e)},i.prototype.dispose=function(){this.isUndef(this.input)||(this.input instanceof AudioNode&&this.input.disconnect(),this.input=null),this.isUndef(this.output)||(this.output instanceof AudioNode&&this.output.disconnect(),this.output=null)};var o=null;i.prototype.noGC=function(){this.output.connect(o)},AudioNode.prototype.noGC=function(){this.connect(o)},i.prototype.now=function(){return this.context.currentTime},i.prototype.samplesToSeconds=function(t){return t/this.context.sampleRate},i.prototype.toSamples=function(t){var e=this.toSeconds(t);return Math.round(e*this.context.sampleRate)},i.prototype.toSeconds=function(t,e){if(e=this.defaultArg(e,this.now()),"number"==typeof t)return t;if("string"==typeof t){var i=0;return"+"===t.charAt(0)&&(t=t.slice(1),i=e),parseFloat(t)+i}return e},i.prototype.frequencyToSeconds=function(t){return 1/parseFloat(t)},i.prototype.secondsToFrequency=function(t){return 1/t};var n=[];return i._initAudioContext=function(t){t(i.context),n.push(t)},i.setContext=function(t){i.prototype.context=t,i.context=t;for(var e=0;ee;e++){var o=e/i*2-1,n=e/(i-1)*2-1;this._curve[e]=t(o,e,n)}this._shaper.curve=this._curve},t.WaveShaper.prototype.setCurve=function(t){if(this._isSafari()){var e=t[0];t.unshift(e)}this._curve=new Float32Array(t),this._shaper.curve=this._curve},t.WaveShaper.prototype.setOversample=function(t){this._shaper.oversample=t},t.WaveShaper.prototype._isSafari=function(){var t=navigator.userAgent.toLowerCase();return-1!==t.indexOf("safari")&&-1===t.indexOf("chrome")},t.WaveShaper.prototype.dispose=function(){t.prototype.dispose.call(this),this._shaper.disconnect(),this._shaper=null,this._curve=null},t.WaveShaper}(Tone_core_Tone);var Tone_signal_Signal;Tone_signal_Signal=function(t){"use strict";return t.Signal=function(e){this._scalar=this.context.createGain(),this.input=this.output=this.context.createGain(),this._syncRatio=1,this.value=this.defaultArg(e,0),t.Signal._constant.chain(this._scalar,this.output)},t.extend(t.Signal,t.SignalBase),t.Signal.prototype.getValue=function(){return this._scalar.gain.value},t.Signal.prototype.setValue=function(t){0===this._syncRatio?t=0:t*=this._syncRatio,this._scalar.gain.value=t},t.Signal.prototype.setValueAtTime=function(t,e){t*=this._syncRatio,this._scalar.gain.setValueAtTime(t,this.toSeconds(e))},t.Signal.prototype.setCurrentValueNow=function(t){t=this.defaultArg(t,this.now());var e=this.getValue();return this.cancelScheduledValues(t),this._scalar.gain.setValueAtTime(e,t),e},t.Signal.prototype.linearRampToValueAtTime=function(t,e){t*=this._syncRatio,this._scalar.gain.linearRampToValueAtTime(t,this.toSeconds(e))},t.Signal.prototype.exponentialRampToValueAtTime=function(t,e){t*=this._syncRatio;try{this._scalar.gain.exponentialRampToValueAtTime(t,this.toSeconds(e))}catch(i){this._scalar.gain.linearRampToValueAtTime(t,this.toSeconds(e))}},t.Signal.prototype.exponentialRampToValueNow=function(t,e){var i=this.now();this.setCurrentValueNow(i),"+"===e.toString().charAt(0)&&(e=e.substr(1)),this.exponentialRampToValueAtTime(t,i+this.toSeconds(e))},t.Signal.prototype.linearRampToValueNow=function(t,e){var i=this.now();this.setCurrentValueNow(i),t*=this._syncRatio,"+"===e.toString().charAt(0)&&(e=e.substr(1)),this._scalar.gain.linearRampToValueAtTime(t,i+this.toSeconds(e))},t.Signal.prototype.setTargetAtTime=function(t,e,i){t*=this._syncRatio,this._scalar.gain.setTargetAtTime(t,this.toSeconds(e),i)},t.Signal.prototype.setValueCurveAtTime=function(t,e,i){for(var o=0;o0?this.oscillator.frequency.exponentialRampToValueAtTime(e,o+i+n):this.oscillator.frequency.linearRampToValueAtTime(e,o+i+n)}},p5.Oscillator.prototype.getFreq=function(){return this.oscillator.frequency.value},p5.Oscillator.prototype.setType=function(t){this.oscillator.type=t},p5.Oscillator.prototype.getType=function(){return this.oscillator.type},p5.Oscillator.prototype.connect=function(e){e?e.hasOwnProperty("input")?(this.panner.connect(e.input),this.connection=e.input):(this.panner.connect(e),this.connection=e):this.panner.connect(t.input)},p5.Oscillator.prototype.disconnect=function(){this.output.disconnect(),this.panner.disconnect(),this.output.connect(this.panner),this.oscMods=[]},p5.Oscillator.prototype.pan=function(t,e){this.panPosition=t,this.panner.pan(t,e)},p5.Oscillator.prototype.getPan=function(){return this.panPosition},p5.Oscillator.prototype.dispose=function(){if(this.oscillator){var e=t.audiocontext.currentTime;this.stop(e),this.disconnect(),this.oscillator.disconnect(),this.panner=null,this.oscillator=null}this.osc2&&this.osc2.dispose()},p5.Oscillator.prototype.phase=function(e){this.dNode||(this.dNode=t.audiocontext.createDelay(),this.output.disconnect(),this.output.connect(this.dNode),this.dNode.connect(this.panner));var i=t.audiocontext.currentTime;this.dNode.delayTime.linearRampToValueAtTime(p5.prototype.map(e,0,1,0,1/this.oscillator.frequency.value),i)};var n=function(t,e,i,o,n){var s=t.oscillator;for(var r in t.mathOps)t.mathOps[r]instanceof n&&(s.disconnect(),t.mathOps[r].dispose(),i=r,i0&&(s=t.mathOps[r-1]),s.disconnect(),s.connect(e),e.connect(o),t.mathOps[i]=e,t};p5.Oscillator.prototype.add=function(t){var i=new e(t),o=this.mathOps.length-1,s=this.output;return n(this,i,o,s,e)},p5.Oscillator.prototype.mult=function(t){var e=new i(t),o=this.mathOps.length-1,s=this.output;return n(this,e,o,s,i)},p5.Oscillator.prototype.scale=function(t,e,i,s){var r,a;4===arguments.length?(r=p5.prototype.map(i,t,e,0,1)-.5,a=p5.prototype.map(s,t,e,0,1)-.5):(r=arguments[0],a=arguments[1]);var u=new o(r,a),c=this.mathOps.length-1,p=this.output;return n(this,u,c,p,o)},p5.SinOsc=function(t){p5.Oscillator.call(this,t,"sine")},p5.SinOsc.prototype=Object.create(p5.Oscillator.prototype),p5.TriOsc=function(t){p5.Oscillator.call(this,t,"triangle")},p5.TriOsc.prototype=Object.create(p5.Oscillator.prototype),p5.SawOsc=function(t){p5.Oscillator.call(this,t,"sawtooth")},p5.SawOsc.prototype=Object.create(p5.Oscillator.prototype),p5.SqrOsc=function(t){p5.Oscillator.call(this,t,"square")},p5.SqrOsc.prototype=Object.create(p5.Oscillator.prototype)}(master,Tone_signal_Signal,Tone_signal_Add,Tone_signal_Multiply,Tone_signal_Scale);var env;env=function(){"use strict";var t=master,e=Tone_signal_Add,i=Tone_signal_Multiply,o=Tone_signal_Scale,n=Tone_core_Tone;n.setContext(t.audiocontext);var s=null;p5.Env=function(e,i,o,n,s,r,a,u){this.aTime=e,this.aLevel=i,this.dTime=o||0,this.dLevel=n||0,this.sTime=s||0,this.sLevel=r||0,this.rTime=a||0,this.rLevel=u||0,this.output=t.audiocontext.createGain(),this.control=new p5.Signal,this.control.connect(this.output),this.timeoutID=null,this.connection=null,this.mathOps=[this.control],t.soundArray.push(this)},p5.Env.prototype.set=function(t,e,i,o,n,s,r,a){this.aTime=t,this.aLevel=e,this.dTime=i||0,this.dLevel=o||0,this.sTime=n||0,this.sLevel=s||0,this.rTime=r||0,this.rLevel=a||0},p5.Env.prototype.setInput=function(t){this.connect(t)},p5.Env.prototype.ctrl=function(t){this.connect(t)},p5.Env.prototype.play=function(e,i){var o=t.audiocontext.currentTime,n=i||0,s=o+n+1e-4;"number"==typeof this.timeoutID&&window.clearTimeout(this.timeoutID),e&&this.connection!==e&&this.connect(e),this.control.cancelScheduledValues(s-1e-4),this.control.linearRampToValueAtTime(0,s-5e-5),this.control.linearRampToValueAtTime(this.aLevel,s+this.aTime),this.control.linearRampToValueAtTime(this.dLevel,s+this.aTime+this.dTime),this.control.linearRampToValueAtTime(this.sLevel,s+this.aTime+this.dTime+this.sTime),this.control.linearRampToValueAtTime(this.rLevel,s+this.aTime+this.dTime+this.sTime+this.rTime);s+this.aTime+this.dTime+this.sTime+this.rTime},p5.Env.prototype.triggerAttack=function(e,i){var o=t.audiocontext.currentTime,n=i||0,s=o+n+1e-4;this.lastAttack=s,"number"==typeof this.timeoutID&&window.clearTimeout(this.timeoutID);var r=this.control.getValue();this.control.cancelScheduledValues(s-1e-4),this.control.linearRampToValueAtTime(r,s-5e-5),e&&this.connection!==e&&this.connect(e),this.control.linearRampToValueAtTime(this.aLevel,s+this.aTime),this.control.linearRampToValueAtTime(this.aLevel,s+this.aTime),this.control.linearRampToValueAtTime(this.dLevel,s+this.aTime+this.dTime),this.control.linearRampToValueAtTime(this.sLevel,s+this.aTime+this.dTime+this.sTime)},p5.Env.prototype.triggerRelease=function(e,i){var o,n=t.audiocontext.currentTime,r=i||0,a=n+r+1e-5;if(e&&this.connection!==e&&this.connect(e),this.control.cancelScheduledValues(a-1e-5),n-this.lastAttackn;n++)o[n]=1;var s=t.createBufferSource();return s.buffer=i,s.loop=!0,s}var e=master;p5.Pulse=function(i,o){p5.Oscillator.call(this,i,"sawtooth"),this.w=o||0,this.osc2=new p5.SawOsc(i),this.dNode=e.audiocontext.createDelay(),this.dcOffset=t(),this.dcGain=e.audiocontext.createGain(),this.dcOffset.connect(this.dcGain),this.dcGain.connect(this.output),this.f=i||440;var n=this.w/this.oscillator.frequency.value;this.dNode.delayTime.value=n,this.dcGain.gain.value=1.7*(.5-this.w),this.osc2.disconnect(),this.osc2.output.gain.minValue=-10,this.osc2.output.gain.maxValue=10,this.osc2.panner.disconnect(),this.osc2.amp(-1),this.osc2.output.connect(this.dNode),this.dNode.connect(this.output),this.output.gain.value=1,this.output.connect(this.panner)},p5.Pulse.prototype=Object.create(p5.Oscillator.prototype),p5.Pulse.prototype.width=function(t){if("number"==typeof t){if(1>=t&&t>=0){this.w=t;var e=this.w/this.oscillator.frequency.value;this.dNode.delayTime.value=e}this.dcGain.gain.value=1.7*(.5-this.w)}else{t.connect(this.dNode.delayTime);var i=new p5.SignalAdd(-.5);i.setInput(t),i=i.mult(-1),i=i.mult(1.7),i.connect(this.dcGain.gain)}},p5.Pulse.prototype.start=function(i,o){var n=e.audiocontext.currentTime,s=o||0;if(!this.started){var r=i||this.f,a=this.oscillator.type;this.oscillator=e.audiocontext.createOscillator(),this.oscillator.frequency.setValueAtTime(r,n),this.oscillator.type=a,this.oscillator.connect(this.output),this.oscillator.start(s+n),this.osc2.oscillator=e.audiocontext.createOscillator(),this.osc2.oscillator.frequency.setValueAtTime(r,s+n),this.osc2.oscillator.type=a,this.osc2.oscillator.connect(this.osc2.output),this.osc2.start(s+n),this.freqNode=[this.oscillator.frequency,this.osc2.oscillator.frequency],this.dcOffset=t(),this.dcOffset.connect(this.dcGain),this.dcOffset.start(s+n),void 0!==this.mods&&void 0!==this.mods.frequency&&(this.mods.frequency.connect(this.freqNode[0]),this.mods.frequency.connect(this.freqNode[1])),this.started=!0,this.osc2.started=!0}},p5.Pulse.prototype.stop=function(t){if(this.started){var i=t||0,o=e.audiocontext.currentTime;this.oscillator.stop(i+o),this.osc2.oscillator.stop(i+o),this.dcOffset.stop(i+o),this.started=!1,this.osc2.started=!1}},p5.Pulse.prototype.freq=function(t,i,o){if("number"==typeof t){this.f=t;var n=e.audiocontext.currentTime,i=i||0,o=o||0,s=this.oscillator.frequency.value;this.oscillator.frequency.cancelScheduledValues(n),this.oscillator.frequency.setValueAtTime(s,n+o),this.oscillator.frequency.exponentialRampToValueAtTime(t,o+i+n),this.osc2.oscillator.frequency.cancelScheduledValues(n),this.osc2.oscillator.frequency.setValueAtTime(s,n+o),this.osc2.oscillator.frequency.exponentialRampToValueAtTime(t,o+i+n),this.freqMod&&(this.freqMod.output.disconnect(),this.freqMod=null)}else t.output&&(t.output.disconnect(),t.output.connect(this.oscillator.frequency),t.output.connect(this.osc2.oscillator.frequency),this.freqMod=t)}}(master,oscillator);var noise;noise=function(){"use strict";var t=master;p5.Noise=function(){p5.Oscillator.call(this),delete this.f,delete this.freq,delete this.oscillator,this.buffer=e},p5.Noise.prototype=Object.create(p5.Oscillator.prototype);var e=function(){for(var e=2*t.audiocontext.sampleRate,i=t.audiocontext.createBuffer(1,e,t.audiocontext.sampleRate),o=i.getChannelData(0),n=0;e>n;n++)o[n]=2*Math.random()-1;return i.type="white",i}(),i=function(){var e,i,o,n,s,r,a,u=2*t.audiocontext.sampleRate,c=t.audiocontext.createBuffer(1,u,t.audiocontext.sampleRate),p=c.getChannelData(0);e=i=o=n=s=r=a=0;for(var h=0;u>h;h++){var l=2*Math.random()-1;e=.99886*e+.0555179*l,i=.99332*i+.0750759*l,o=.969*o+.153852*l,n=.8665*n+.3104856*l,s=.55*s+.5329522*l,r=-.7616*r-.016898*l,p[h]=e+i+o+n+s+r+a+.5362*l,p[h]*=.11,a=.115926*l}return c.type="pink",c}(),o=function(){for(var e=2*t.audiocontext.sampleRate,i=t.audiocontext.createBuffer(1,e,t.audiocontext.sampleRate),o=i.getChannelData(0),n=0,s=0;e>s;s++){var r=2*Math.random()-1;o[s]=(n+.02*r)/1.02,n=o[s],o[s]*=3.5}return i.type="brown",i}();p5.Noise.prototype.setType=function(n){switch(n){case"white":this.buffer=e;break;case"pink":this.buffer=i;break;case"brown":this.buffer=o;break;default:this.buffer=e}if(this.started){var s=t.audiocontext.currentTime;this.stop(s),this.start(s+.01)}},p5.Noise.prototype.getType=function(){return this.buffer.type},p5.Noise.prototype.start=function(){this.started&&this.stop(),this.noise=t.audiocontext.createBufferSource(),this.noise.buffer=this.buffer,this.noise.loop=!0,this.noise.connect(this.output);var e=t.audiocontext.currentTime;this.noise.start(e),this.started=!0},p5.Noise.prototype.stop=function(){var e=t.audiocontext.currentTime;this.noise&&(this.noise.stop(e),this.started=!1)},p5.Noise.prototype.dispose=function(){var e=t.audiocontext.currentTime;this.noise&&(this.noise.disconnect(),this.stop(e)),this.output&&this.output.disconnect(),this.panner&&this.panner.disconnect(),this.output=null,this.panner=null,this.buffer=null,this.noise=null}}(master);var audioin;audioin=function(){"use strict";var t=master;p5.AudioIn=function(){this.input=t.audiocontext.createGain(),this.output=t.audiocontext.createGain(),this.stream=null,this.mediaStream=null,this.currentSource=0,this.enabled=!1,this.amplitude=new p5.Amplitude,this.output.connect(this.amplitude.input),"undefined"==typeof window.MediaStreamTrack?window.alert("This browser does not support MediaStreamTrack"):"undefined"!=typeof window.MediaStreamTrack.getSources&&window.MediaStreamTrack.getSources(this._gotSources),t.soundArray.push(this)},p5.AudioIn.prototype.start=function(){var e=this;if(t.inputSources[e.currentSource]){var i=t.inputSources[e.currentSource].id,o={audio:{optional:[{sourceId:i}]}};navigator.getUserMedia(o,this._onStream=function(i){e.stream=i,e.enabled=!0,e.mediaStream=t.audiocontext.createMediaStreamSource(i),e.mediaStream.connect(e.output),e.amplitude.setInput(e.output)},this._onStreamError=function(t){console.error(t)})}else window.navigator.getUserMedia({audio:!0},this._onStream=function(i){e.stream=i,e.enabled=!0,e.mediaStream=t.audiocontext.createMediaStreamSource(i),e.mediaStream.connect(e.output),e.amplitude.setInput(e.output)},this._onStreamError=function(t){console.error(t)})},p5.AudioIn.prototype.stop=function(){this.stream&&this.stream.stop()},p5.AudioIn.prototype.connect=function(e){this.output.connect(e?e.hasOwnProperty("input")?e.input:e.hasOwnProperty("analyser")?e.analyser:e:t.input)},p5.AudioIn.prototype.disconnect=function(t){this.output.disconnect(t),this.output.connect(this.amplitude.input)},p5.AudioIn.prototype.getLevel=function(t){return t&&(this.amplitude.smoothing=t),this.amplitude.getLevel()},p5.AudioIn.prototype._gotSources=function(e){for(var i=0;i!==e.length;i++){var o=e[i];"audio"===o.kind&&t.inputSources.push(o)}},p5.AudioIn.prototype.amp=function(e,i){if(i){var o=i||0,n=this.output.gain.value;this.output.gain.cancelScheduledValues(t.audiocontext.currentTime),this.output.gain.setValueAtTime(n,t.audiocontext.currentTime),this.output.gain.linearRampToValueAtTime(e,o+t.audiocontext.currentTime)}else this.output.gain.cancelScheduledValues(t.audiocontext.currentTime),this.output.gain.setValueAtTime(e,t.audiocontext.currentTime)},p5.AudioIn.prototype.listSources=function(){return console.log("input sources: "),console.log(t.inputSources),t.inputSources.length>0?t.inputSources:"This browser does not support MediaStreamTrack.getSources()"},p5.AudioIn.prototype.setSource=function(e){var i=this;t.inputSources.length>0&&e=t&&(t=1),"number"==typeof t?(i.biquad.frequency.value=t,i.biquad.frequency.cancelScheduledValues(this.ac.currentTime+.01+o),i.biquad.frequency.exponentialRampToValueAtTime(t,this.ac.currentTime+.02+o)):t&&t.connect(this.biquad.frequency),i.biquad.frequency.value},p5.Filter.prototype.res=function(t,e){var i=this,o=e||0;return"number"==typeof t?(i.biquad.Q.value=t,i.biquad.Q.cancelScheduledValues(i.ac.currentTime+.01+o),i.biquad.Q.linearRampToValueAtTime(t,i.ac.currentTime+.02+o)):t&&freq.connect(this.biquad.Q),i.biquad.Q.value},p5.Filter.prototype.setType=function(t){this.biquad.type=t},p5.Filter.prototype.amp=function(e,i,o){var i=i||0,o=o||0,n=t.audiocontext.currentTime,s=this.output.gain.value;this.output.gain.cancelScheduledValues(n),this.output.gain.linearRampToValueAtTime(s,n+o+.001),this.output.gain.linearRampToValueAtTime(e,n+o+i+.001)},p5.Filter.prototype.connect=function(t){var e=t||p5.soundOut.input;this.output.connect(e)},p5.Filter.prototype.disconnect=function(){this.output.disconnect()},p5.LowPass=function(){p5.Filter.call(this,"lowpass")},p5.LowPass.prototype=Object.create(p5.Filter.prototype),p5.HighPass=function(){p5.Filter.call(this,"highpass")},p5.HighPass.prototype=Object.create(p5.Filter.prototype),p5.BandPass=function(){p5.Filter.call(this,"bandpass")},p5.BandPass.prototype=Object.create(p5.Filter.prototype)}(master);var delay;delay=function(){"use strict";var t=master;p5.Delay=function(){this.ac=t.audiocontext,this.input=this.ac.createGain(),this.output=this.ac.createGain(),this._split=this.ac.createChannelSplitter(2),this._merge=this.ac.createChannelMerger(2),this._leftGain=this.ac.createGain(),this._rightGain=this.ac.createGain(),this.leftDelay=this.ac.createDelay(),this.rightDelay=this.ac.createDelay(),this._leftFilter=new p5.Filter,this._rightFilter=new p5.Filter,this._leftFilter.disconnect(),this._rightFilter.disconnect(),this.lowPass=this._leftFilter,this._leftFilter.biquad.frequency.setValueAtTime(1200,this.ac.currentTime),this._rightFilter.biquad.frequency.setValueAtTime(1200,this.ac.currentTime),this._leftFilter.biquad.Q.setValueAtTime(.3,this.ac.currentTime),this._rightFilter.biquad.Q.setValueAtTime(.3,this.ac.currentTime),this.input.connect(this._split),this.leftDelay.connect(this._leftGain),this.rightDelay.connect(this._rightGain),this._leftGain.connect(this._leftFilter.input),this._rightGain.connect(this._rightFilter.input),this._merge.connect(this.output),this.output.connect(p5.soundOut.input),this._leftFilter.biquad.gain.setValueAtTime(1,this.ac.currentTime),this._rightFilter.biquad.gain.setValueAtTime(1,this.ac.currentTime),this.setType(0),this._maxDelay=this.leftDelay.delayTime.maxValue},p5.Delay.prototype.process=function(t,e,i,o){var n=i||0,s=e||0;if(n>=1)throw new Error("Feedback value will force a positive feedback loop.");if(s>=this._maxDelay)throw new Error("Delay Time exceeds maximum delay time of "+this._maxDelay+" second.");t.connect(this.input),this.leftDelay.delayTime.setValueAtTime(s,this.ac.currentTime),this.rightDelay.delayTime.setValueAtTime(s,this.ac.currentTime),this._leftGain.gain.setValueAtTime(n,this.ac.currentTime),this._rightGain.gain.setValueAtTime(n,this.ac.currentTime),o&&(this._leftFilter.freq(o),this._rightFilter.freq(o))},p5.Delay.prototype.delayTime=function(t){"number"!=typeof t?(t.connect(this.leftDelay.delayTime),t.connect(this.rightDelay.delayTime)):(this.leftDelay.delayTime.cancelScheduledValues(this.ac.currentTime),this.rightDelay.delayTime.cancelScheduledValues(this.ac.currentTime),this.leftDelay.delayTime.linearRampToValueAtTime(t,this.ac.currentTime),this.rightDelay.delayTime.linearRampToValueAtTime(t,this.ac.currentTime))},p5.Delay.prototype.feedback=function(t){if("number"!=typeof t)t.connect(this._leftGain.gain),t.connect(this._rightGain.gain);else{if(t>=1)throw new Error("Feedback value will force a positive feedback loop.");this._leftGain.gain.exponentialRampToValueAtTime(t,this.ac.currentTime),this._rightGain.gain.exponentialRampToValueAtTime(t,this.ac.currentTime)}},p5.Delay.prototype.filter=function(t,e){this._leftFilter.set(t,e),this._rightFilter.set(t,e)},p5.Delay.prototype.setType=function(t){switch(1===t&&(t="pingPong"),this._split.disconnect(),this._leftFilter.disconnect(),this._rightFilter.disconnect(),this._split.connect(this.leftDelay,0),this._split.connect(this.rightDelay,1),t){case"pingPong":this._rightFilter.setType(this._leftFilter.biquad.type),this._leftFilter.output.connect(this._merge,0,0),this._rightFilter.output.connect(this._merge,0,1),this._leftFilter.output.connect(this.rightDelay),this._rightFilter.output.connect(this.leftDelay);break;default:this._leftFilter.output.connect(this._merge,0,0),this._leftFilter.output.connect(this._merge,0,1),this._leftFilter.output.connect(this.leftDelay),this._leftFilter.output.connect(this.rightDelay)}},p5.Delay.prototype.amp=function(e,i,o){var i=i||0,o=o||0,n=t.audiocontext.currentTime,s=this.output.gain.value;this.output.gain.cancelScheduledValues(n),this.output.gain.linearRampToValueAtTime(s,n+o+.001),this.output.gain.linearRampToValueAtTime(e,n+o+i+.001)},p5.Delay.prototype.connect=function(t){var e=t||p5.soundOut.input;this.output.connect(e)},p5.Delay.prototype.disconnect=function(){this.output.disconnect()}}(master,filter);var reverb;reverb=function(){"use strict";var t=master;p5.Reverb=function(){this.ac=t.audiocontext,this.convolverNode=this.ac.createConvolver(),this.input=this.ac.createGain(),this.output=this.ac.createGain(),this.input.gain.value=.5,this.input.connect(this.convolverNode),this.convolverNode.connect(this.output),this._seconds=3,this._decay=2,this._reverse=!1,this._buildImpulse(),this.connect(),t.soundArray.push(this)},p5.Reverb.prototype.process=function(t,e,i,o){t.connect(this.input);var n=!1;e&&(this._seconds=e,n=!0),i&&(this._decay=i),o&&(this._reverse=o),n&&this._buildImpulse()},p5.Reverb.prototype.set=function(t,e,i){var o=!1;t&&(this._seconds=t,o=!0),e&&(this._decay=e),i&&(this._reverse=i),o&&this._buildImpulse()},p5.Reverb.prototype.amp=function(e,i,o){var i=i||0,o=o||0,n=t.audiocontext.currentTime,s=this.output.gain.value;this.output.gain.cancelScheduledValues(n),this.output.gain.linearRampToValueAtTime(s,n+o+.001),this.output.gain.linearRampToValueAtTime(e,n+o+i+.001)},p5.Reverb.prototype.connect=function(t){var e=t||p5.soundOut.input;this.output.connect(e.input?e.input:e)},p5.Reverb.prototype.disconnect=function(){this.output.disconnect()},p5.Reverb.prototype._buildImpulse=function(){var t,e,i=this.ac.sampleRate,o=i*this._seconds,n=this._decay,s=this.ac.createBuffer(2,o,i),r=s.getChannelData(0),a=s.getChannelData(1);for(e=0;o>e;e++)t=this.reverse?o-e:e,r[e]=(2*Math.random()-1)*Math.pow(1-t/o,n),a[e]=(2*Math.random()-1)*Math.pow(1-t/o,n);this.convolverNode.buffer=s},p5.Reverb.prototype.dispose=function(){this.convolverNode.buffer=null,this.convolverNode=null,"undefined"!=typeof this.output&&(this.output.disconnect(),this.output=null),"undefined"!=typeof this.panner&&(this.panner.disconnect(),this.panner=null)},p5.Convolver=function(e,i){this.ac=t.audiocontext,this.convolverNode=this.ac.createConvolver(),this.input=this.ac.createGain(),this.output=this.ac.createGain(),this.input.gain.value=.5,this.input.connect(this.convolverNode),this.convolverNode.connect(this.output),e?(this.impulses=[],this._loadBuffer(e,i)):(this._seconds=3,this._decay=2,this._reverse=!1,this._buildImpulse()),this.connect(),t.soundArray.push(this)},p5.Convolver.prototype=Object.create(p5.Reverb.prototype),p5.prototype.registerPreloadMethod("createConvolver"),p5.prototype.createConvolver=function(t,e){window.location.origin.indexOf("file://")>-1&&alert("This sketch may require a server to load external files. Please see http://bit.ly/1qcInwS");var i=new p5.Convolver(t,e);return i.impulses=[],i},p5.Convolver.prototype._loadBuffer=function(t,e){t=p5.prototype._checkFileFormats(t);var i=new XMLHttpRequest;i.open("GET",t,!0),i.responseType="arraybuffer";var o=this;i.onload=function(){var n=p5.prototype.getAudioContext();n.decodeAudioData(i.response,function(i){var n={},s=t.split("/");n.name=s[s.length-1],n.audioBuffer=i,o.impulses.push(n),o.convolverNode.buffer=n.audioBuffer,e&&e(n)})},i.send()},p5.Convolver.prototype.set=null,p5.Convolver.prototype.process=function(t){t.connect(this.input)},p5.Convolver.prototype.impulses=[],p5.Convolver.prototype.addImpulse=function(t,e){window.location.origin.indexOf("file://")>-1&&alert("This sketch may require a server to load external files. Please see http://bit.ly/1qcInwS"),this._loadBuffer(t,e)},p5.Convolver.prototype.resetImpulse=function(t,e){window.location.origin.indexOf("file://")>-1&&alert("This sketch may require a server to load external files. Please see http://bit.ly/1qcInwS"),this.impulses=[],this._loadBuffer(t,e)},p5.Convolver.prototype.toggleImpulse=function(t){if("number"==typeof t&&tr;r++){var a=o[r];a>0&&!n?(n=!0,setTimeout(function(){var t=e+s.samplesToSeconds(r+2*i);return function(){s.tick(t)}}(),0)):0>a&&n&&(n=!1)}this._upTick=n},t.Clock.prototype.dispose=function(){this._jsNode.disconnect(),this._controlSignal.dispose(),this._oscillator&&(this._oscillator.onended(),this._oscillator.disconnect()),this._jsNode.onaudioprocess=function(){},this._jsNode=null,this._controlSignal=null,this._oscillator=null},t.Clock}(Tone_core_Tone);var metro;metro=function(){"use strict";var t=master,e=Tone_core_Clock,i=t.audiocontext;p5.Metro=function(){this.clock=new e(i.sampleRate,this.ontick.bind(this)),this.syncedParts=[],this.bpm=120,this._init(),this.tickCallback=function(){}};var o=0,n=0;p5.Metro.prototype.ontick=function(e){var i=e-o,s=e-t.audiocontext.currentTime;if(!(-.02>=i-n)){o=e;for(var r in this.syncedParts){var a=this.syncedParts[r];a.incrementStep(s);for(var u in a.phrases){var c=a.phrases[u],p=c.sequence,h=this.metroTicks%p.length;0!==p[h]&&(this.metroTicks=t.parts.length?(t.scoreStep=0,t.onended()):(t.scoreStep=0,t.parts[t.currentPart-1].stop(),t.parts[t.currentPart].start())}var e=master,i=120;p5.prototype.setBPM=function(t,o){i=t;for(var n in e.parts)e.parts[n].setBPM(i,o)},p5.Phrase=function(t,e,i){this.phraseStep=0,this.name=t,this.callback=e,this.sequence=i},p5.Part=function(t,o){this.length=t||0,this.partStep=0,this.phrases=[],this.looping=!1,this.isPlaying=!1,this.onended=function(){this.stop()},this.tatums=o||.0625,this.metro=new p5.Metro,this.metro._init(),this.metro.beatLength(this.tatums),this.metro.setBPM(i),e.parts.push(this),this.callback=function(){}},p5.Part.prototype.setBPM=function(t,e){this.metro.setBPM(t,e)
},p5.Part.prototype.getBPM=function(){return this.metro.getBPM()},p5.Part.prototype.start=function(t){if(!this.isPlaying){this.isPlaying=!0,this.metro.resetSync(this);var e=t||0;this.metro.start(e)}},p5.Part.prototype.loop=function(t){this.looping=!0,this.onended=function(){this.partStep=0};var e=t||0;this.start(e)},p5.Part.prototype.noLoop=function(){this.looping=!1,this.onended=function(){this.stop()}},p5.Part.prototype.stop=function(t){this.partStep=0,this.pause(t)},p5.Part.prototype.pause=function(t){this.isPlaying=!1;var e=t||0;this.metro.stop(e)},p5.Part.prototype.addPhrase=function(t,e,i){var o;if(3===arguments.length)o=new p5.Phrase(t,e,i);else{if(!(arguments[0]instanceof p5.Phrase))throw"invalid input. addPhrase accepts name, callback, array or a p5.Phrase";o=arguments[0]}this.phrases.push(o),o.sequence.length>this.length&&(this.length=o.sequence.length)},p5.Part.prototype.removePhrase=function(t){for(var e in this.phrases)this.phrases[e].name===t&&this.phrases.split(e,1)},p5.Part.prototype.getPhrase=function(t){for(var e in this.phrases)if(this.phrases[e].name===t)return this.phrases[e]},p5.Part.prototype.replaceSequence=function(t,e){for(var i in this.phrases)this.phrases[i].name===t&&(this.phrases[i].sequence=e)},p5.Part.prototype.incrementStep=function(t){this.partSteps;)o[s++]=t[n],o[s++]=e[n],n++;return o}function e(t,e,i){for(var o=i.length,n=0;o>n;n++)t.setUint8(e+n,i.charCodeAt(n))}var i=master,o=i.audiocontext;p5.SoundRecorder=function(){this.input=o.createGain(),this.output=o.createGain(),this.recording=!1,this.bufferSize=1024,this._channels=2,this._clear(),this._jsNode=o.createScriptProcessor(this.bufferSize,this._channels,2),this._jsNode.onaudioprocess=this._audioprocess.bind(this),this._callback=function(){},this._jsNode.connect(p5.soundOut._silentNode),this.setInput(),i.soundArray.push(this)},p5.SoundRecorder.prototype.setInput=function(t){this.input.disconnect(),this.input=null,this.input=o.createGain(),this.input.connect(this._jsNode),this.input.connect(this.output),t?t.connect(this.input):p5.soundOut.output.connect(this.input)},p5.SoundRecorder.prototype.record=function(t,e,i){this.recording=!0,e&&(this.sampleLimit=Math.round(e*o.sampleRate)),t&&i?this._callback=function(){this.buffer=this._getBuffer(),t.setBuffer(this.buffer),i()}:t&&(this._callback=function(){this.buffer=this._getBuffer(),t.setBuffer(this.buffer)})},p5.SoundRecorder.prototype.stop=function(){this.recording=!1,this._callback(),this._clear()},p5.SoundRecorder.prototype._clear=function(){this._leftBuffers=[],this._rightBuffers=[],this.recordedSamples=0,this.sampleLimit=null},p5.SoundRecorder.prototype._audioprocess=function(t){if(this.recording!==!1&&this.recording===!0)if(this.sampleLimit&&this.recordedSamples>=this.sampleLimit)this.stop();else{var e=t.inputBuffer.getChannelData(0),i=t.inputBuffer.getChannelData(1);this._leftBuffers.push(new Float32Array(e)),this._rightBuffers.push(new Float32Array(i)),this.recordedSamples+=this.bufferSize}},p5.SoundRecorder.prototype._getBuffer=function(){var t=[];return t.push(this._mergeBuffers(this._leftBuffers)),t.push(this._mergeBuffers(this._rightBuffers)),t},p5.SoundRecorder.prototype._mergeBuffers=function(t){for(var e=new Float32Array(this.recordedSamples),i=0,o=t.length,n=0;o>n;n++){var s=t[n];e.set(s,i),i+=s.length}return e},p5.SoundRecorder.prototype.dispose=function(){this._clear(),this._callback=function(){},this.input&&this.input.disconnect(),this.input=null,this._jsNode=null},p5.prototype.saveSound=function(i,o){var n=i.buffer.getChannelData(0),s=i.buffer.getChannelData(1),r=t(n,s),a=new ArrayBuffer(44+2*r.length),u=new DataView(a);e(u,0,"RIFF"),u.setUint32(4,44+2*r.length,!0),e(u,8,"WAVE"),e(u,12,"fmt "),u.setUint32(16,16,!0),u.setUint16(20,1,!0),u.setUint16(22,2,!0),u.setUint32(24,44100,!0),u.setUint32(28,176400,!0),u.setUint16(32,4,!0),u.setUint16(34,16,!0),e(u,36,"data"),u.setUint32(40,2*r.length,!0);for(var c=r.length,p=44,h=1,l=0;c>l;l++)u.setInt16(p,32767*r[l]*h,!0),p+=2;p5.prototype.writeFile([u],o,"wav")}}(sndcore,master);var src_app;src_app=function(){"use strict";var t=sndcore;return t}(sndcore,master,helpers,panner,soundfile,amplitude,fft,signal,oscillator,env,pulse,noise,audioin,filter,delay,reverb,metro,looper,soundRecorder);
\ No newline at end of file