Skip to content

Commit 517a7b7

Browse files
authored
Merge pull request #738 from KevinGrajeda/onNewInput
add `_onNewInput()` hook
2 parents 401120d + 8bedee1 commit 517a7b7

23 files changed

+116
-35
lines changed

src/amplitude.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -177,25 +177,6 @@ class Amplitude {
177177
}
178178
}
179179

180-
connect(unit) {
181-
if (unit) {
182-
if (unit.hasOwnProperty('input')) {
183-
this.output.connect(unit.input);
184-
} else {
185-
this.output.connect(unit);
186-
}
187-
}
188-
// else {
189-
// this.output.connect(this.panner.connect(p5sound.input));
190-
// }
191-
}
192-
193-
disconnect() {
194-
if (this.output) {
195-
this.output.disconnect();
196-
}
197-
}
198-
199180
/**
200181
* Returns a single Amplitude reading at the moment it is called.
201182
* For continuous readings, run in the draw loop.

src/audioVoice.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ class AudioVoice {
3434
connect(unit) {
3535
var u = unit || p5sound.input;
3636
this.output.connect(u.input ? u.input : u);
37+
if (unit && unit._onNewInput) {
38+
unit._onNewInput(this);
39+
}
3740
}
3841

3942
/**

src/audioin.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ class AudioIn {
211211
} else {
212212
this.output.connect(p5sound.input);
213213
}
214+
if (unit && unit._onNewInput) {
215+
unit._onNewInput(this);
216+
}
214217
}
215218

216219
/**
@@ -395,7 +398,7 @@ class AudioIn {
395398
this.output.disconnect();
396399
}
397400
if (this.amplitude) {
398-
this.amplitude.disconnect();
401+
this.amplitude.dispose();
399402
}
400403
delete this.amplitude;
401404
delete this.output;

src/effect.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ class Effect {
122122
connect(unit) {
123123
var u = unit || p5.soundOut.input;
124124
this.output.connect(u.input ? u.input : u);
125+
if (unit && unit._onNewInput) {
126+
unit._onNewInput(this);
127+
}
125128
}
126129

127130
/**

src/envelope.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,9 @@ class Envelope {
810810
}
811811

812812
this.output.connect(unit);
813+
if (unit && unit._onNewInput) {
814+
unit._onNewInput(this);
815+
}
813816
}
814817

815818
disconnect() {

src/fft.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,11 @@ class FFT {
614614

615615
return octaveBands;
616616
}
617+
618+
_onNewInput() {
619+
// disconnect FFT from sketch when something is connected
620+
p5sound.fftMeter.disconnect();
621+
}
617622
}
618623

619624
// helper methods to convert type from float (dB) to int (0-255)

src/gain.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ class Gain {
106106
connect(unit) {
107107
var u = unit || p5.soundOut.input;
108108
this.output.connect(u.input ? u.input : u);
109+
if (unit && unit._onNewInput) {
110+
unit._onNewInput(this);
111+
}
109112
}
110113

111114
/**

src/monosynth.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,9 @@ class MonoSynth extends AudioVoice {
355355
connect(unit) {
356356
var u = unit || p5sound.input;
357357
this.output.connect(u.input ? u.input : u);
358+
if (unit && unit._onNewInput) {
359+
unit._onNewInput(this);
360+
}
358361
}
359362

360363
/**

src/oscillator.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,9 @@ class Oscillator {
387387
this.panner.connect(unit);
388388
this.connection = unit;
389389
}
390+
if (unit && unit._onNewInput) {
391+
unit._onNewInput(this);
392+
}
390393
}
391394

392395
/**

src/panner.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ if (typeof ac.createStereoPanner !== 'undefined') {
150150

151151
connect(obj) {
152152
this.output.connect(obj);
153+
if (obj && obj._onNewInput) {
154+
obj._onNewInput(this);
155+
}
153156
}
154157

155158
disconnect() {

0 commit comments

Comments
 (0)