Skip to content

Commit eb22e94

Browse files
committed
fix for env wasTriggered
1 parent 023e2a7 commit eb22e94

File tree

3 files changed

+31
-32
lines changed

3 files changed

+31
-32
lines changed

lib/p5.sound.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! p5.sound.js v0.2.16 2015-12-06 */
1+
/*! p5.sound.js v0.2.16 2015-12-19 */
22
(function (root, factory) {
33
if (typeof define === 'function' && define.amd)
44
define('p5.sound', ['p5'], function (p5) { (factory(p5));});
@@ -4040,11 +4040,6 @@ env = function () {
40404040
var Scale = Tone_signal_Scale;
40414041
var Tone = Tone_core_Tone;
40424042
Tone.setContext(p5sound.audiocontext);
4043-
// oscillator or buffer source to clear on env complete
4044-
// to save resources if/when it is retriggered
4045-
var sourceToClear = null;
4046-
// set to true if attack is set, then false on release
4047-
var wasTriggered = false;
40484043
/**
40494044
* <p>Envelopes are pre-defined amplitude distribution over time.
40504045
* The p5.Env accepts up to four time/level pairs, where time
@@ -4144,6 +4139,11 @@ env = function () {
41444139
// store connection
41454140
//array of math operation signal chaining
41464141
this.mathOps = [this.control];
4142+
// oscillator or buffer source to clear on env complete
4143+
// to save resources if/when it is retriggered
4144+
this.sourceToClear = null;
4145+
// set to true if attack is set, then false on release
4146+
this.wasTriggered = false;
41474147
// add to the soundArray so we can dispose of the env later
41484148
p5sound.soundArray.push(this);
41494149
};
@@ -4243,7 +4243,7 @@ env = function () {
42434243
var tFromNow = secondsFromNow || 0;
42444244
var t = now + tFromNow;
42454245
this.lastAttack = t;
4246-
wasTriggered = true;
4246+
this.wasTriggered = true;
42474247
// we should set current value, but this is not working on Firefox
42484248
var currentVal = this.control.getValue();
42494249
console.log(currentVal);
@@ -4272,7 +4272,7 @@ env = function () {
42724272
*/
42734273
p5.Env.prototype.triggerRelease = function (unit, secondsFromNow) {
42744274
// only trigger a release if an attack was triggered
4275-
if (!wasTriggered) {
4275+
if (!this.wasTriggered) {
42764276
return;
42774277
}
42784278
var now = p5sound.audiocontext.currentTime;
@@ -4316,13 +4316,13 @@ env = function () {
43164316
var clearTime = t + this.aTime + this.dTime + this.sTime + this.rTime;
43174317
// * 1000;
43184318
if (this.connection && this.connection.hasOwnProperty('oscillator')) {
4319-
sourceToClear = this.connection.oscillator;
4320-
sourceToClear.stop(clearTime + 0.01);
4319+
this.sourceToClear = this.connection.oscillator;
4320+
this.sourceToClear.stop(clearTime + 0.01);
43214321
} else if (this.connect && this.connection.hasOwnProperty('source')) {
4322-
sourceToClear = this.connection.source;
4323-
sourceToClear.stop(clearTime + 0.01);
4322+
this.sourceToClear = this.connection.source;
4323+
this.sourceToClear.stop(clearTime + 0.01);
43244324
}
4325-
wasTriggered = false;
4325+
this.wasTriggered = false;
43264326
};
43274327
p5.Env.prototype.connect = function (unit) {
43284328
this.connection = unit;
@@ -5018,8 +5018,6 @@ audioin = function () {
50185018
* audioGrab.setSource(0);
50195019
* });
50205020
* }
5021-
* function draw(){
5022-
* }
50235021
* </code></div>
50245022
*/
50255023
p5.AudioIn.prototype.getSources = function (callback) {

0 commit comments

Comments
 (0)