Skip to content

Commit ca1e8e8

Browse files
committed
register objects with soundArray so they can be disposed when sketch is removed
1 parent 676dbaa commit ca1e8e8

File tree

8 files changed

+26
-5
lines changed

8 files changed

+26
-5
lines changed

lib/p5.sound.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2232,6 +2232,8 @@ amplitude = function () {
22322232
this.output.connect(this.audiocontext.destination);
22332233
// connect to p5sound master output by default, unless set by input()
22342234
p5sound.meter.connect(this.processor);
2235+
// add this p5.SoundFile to the soundArray
2236+
p5sound.soundArray.push(this);
22352237
};
22362238
/**
22372239
* Connects to the p5sound instance (master output) by default.
@@ -2547,6 +2549,8 @@ fft = function () {
25472549
5200,
25482550
14000
25492551
];
2552+
// add this p5.SoundFile to the soundArray
2553+
p5sound.soundArray.push(this);
25502554
};
25512555
/**
25522556
* Set the input source for the FFT analysis. If no source is
@@ -3729,7 +3733,6 @@ oscillator = function () {
37293733
this.output.gain.linearRampToValueAtTime(currentVol, now + tFromNow);
37303734
this.output.gain.linearRampToValueAtTime(vol, now + tFromNow + rampTime);
37313735
} else if (vol) {
3732-
console.log(vol);
37333736
vol.connect(self.output.gain);
37343737
} else {
37353738
// return the Gain Node
@@ -5188,6 +5191,8 @@ filter = function () {
51885191
if (type) {
51895192
this.setType(type);
51905193
}
5194+
// add to the soundArray
5195+
p5sound.soundArray.push(this);
51915196
};
51925197
/**
51935198
* Filter an audio signal according to a set
@@ -5465,6 +5470,8 @@ delay = function () {
54655470
// default routing
54665471
this.setType(0);
54675472
this._maxDelay = this.leftDelay.delayTime.maxValue;
5473+
// add this p5.SoundFile to the soundArray
5474+
p5sound.soundArray.push(this);
54685475
};
54695476
/**
54705477
* Add delay to an audio signal according to a set
@@ -7394,6 +7401,8 @@ gain = function () {
73947401
// otherwise, Safari distorts
73957402
this.input.gain.value = 0.5;
73967403
this.input.connect(this.output);
7404+
// add to the soundArray
7405+
p5sound.soundArray.push(this);
73977406
};
73987407
/**
73997408
* Connect a source to the gain node.

lib/p5.sound.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/amplitude.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ define(function (require) {
8383
// connect to p5sound master output by default, unless set by input()
8484
p5sound.meter.connect(this.processor);
8585

86+
// add this p5.SoundFile to the soundArray
87+
p5sound.soundArray.push(this);
8688
};
8789

8890
/**

src/delay.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ define(function (require) {
108108
this.setType(0);
109109

110110
this._maxDelay = this.leftDelay.delayTime.maxValue;
111+
112+
// add this p5.SoundFile to the soundArray
113+
p5sound.soundArray.push(this);
111114
};
112115

113116
/**

src/fft.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ define(function (require) {
113113
this.highMid = [2600, 5200];
114114
this.treble = [5200, 14000];
115115

116+
// add this p5.SoundFile to the soundArray
117+
p5sound.soundArray.push(this);
116118
};
117119

118120
/**

src/filter.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ define(function (require) {
9696
if (type) {
9797
this.setType(type);
9898
}
99+
100+
// add to the soundArray
101+
p5sound.soundArray.push(this);
99102
};
100103

101104
/**

src/gain.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ define(function (require) {
8080
// otherwise, Safari distorts
8181
this.input.gain.value = 0.5;
8282
this.input.connect(this.output);
83+
84+
// add to the soundArray
85+
p5sound.soundArray.push(this);
8386
}
8487

8588
/**

src/oscillator.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ define(function (require) {
195195
}
196196

197197
else if (vol) {
198-
console.log(vol);
199198
vol.connect(self.output.gain);
200199
} else {
201200
// return the Gain Node

0 commit comments

Comments
 (0)