Skip to content

Commit a61ccca

Browse files
committed
effect nodes extend P5SoundEffectNode
1 parent e8574d9 commit a61ccca

File tree

7 files changed

+146
-236
lines changed

7 files changed

+146
-236
lines changed

src/nodes/core/effect/P5SoundDelay.js renamed to src/nodes/effect/P5SoundDelay.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
*/
66

77
import { FeedbackDelay as ToneFeedbackDelay } from "tone/build/esm/effect/FeedbackDelay.js";
8-
import { P5SoundParameter } from "../P5SoundParameter.js";
9-
import { P5SoundMixEffectNode } from "../P5SoundMixEffectNode.js";
8+
import { P5SoundParameter } from "../../P5SoundParameter.js";
9+
import { P5SoundMixEffectNode } from "../core/P5SoundMixEffectNode.js";
1010

1111
/**
1212
* A delay effect with parameters for feedback, and delay time.
@@ -52,14 +52,16 @@ export class P5SoundDelay extends P5SoundMixEffectNode
5252
{
5353
super();
5454

55-
this._delayNode = new ToneFeedbackDelay();
55+
this._toneFeedbackDelayNode = new ToneFeedbackDelay();
5656

57-
this._delayTime = new P5SoundParameter(this._delayNode.delayTime, delayTime);
58-
this._feedback = new P5SoundParameter(this._delayNode.feedback, feedback);
57+
this._delayTime = new P5SoundParameter(this._toneFeedbackDelayNode.delayTime, delayTime);
58+
this._feedback = new P5SoundParameter(this._toneFeedbackDelayNode.feedback, feedback);
5959

60-
this.configureMixIO(this._delayNode, this._delayNode);
60+
this.configureMixIO(this._toneFeedbackDelayNode, this._toneFeedbackDelayNode);
6161
}
6262

63+
isP5SoundDelay = true;
64+
6365
/**
6466
* Set the delay time in seconds.
6567
* @method delayTime
@@ -82,7 +84,7 @@ export class P5SoundDelay extends P5SoundMixEffectNode
8284
*
8385
* osc = new p5.P5SoundOscillator('sawtooth');
8486
* osc.amp(0.74);
85-
* env = new p5.Envelope(0.01);
87+
* env = new p5.P5SoundEnvelope(0.01);
8688
* delay = new p5.P5SoundDelay(0.12, 0.7);
8789
*
8890
* osc.disconnect();

src/nodes/core/effect/P5SoundGain.js renamed to src/nodes/effect/P5SoundGain.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* @for p5.sound
55
*/
66
import { Gain as ToneGain } from "tone/build/esm/core/context/Gain.js";
7-
import { P5SoundEffectNode } from "../P5SoundEffectNode.js";
8-
import { P5SoundParameter } from "../P5SoundParameter.js";
7+
import { P5SoundEffectNode } from "../core/P5SoundEffectNode.js";
8+
import { P5SoundParameter } from "../../P5SoundParameter.js";
99

1010
/**
1111
* Generate a gain node to use for mixing and main volume.
@@ -55,12 +55,12 @@ export class P5SoundGain extends P5SoundEffectNode
5555
{
5656
super();
5757

58-
this._gainNode = new ToneGain(gainValue);
58+
this._toneGainNode = new ToneGain(gainValue);
5959

60-
this._gain = new P5SoundParameter(this._gainNode.gain);
60+
this._gain = new P5SoundParameter(this._toneGainNode.gain);
6161

62-
this.configureInput(this._gainNode);
63-
this.configureOutput(this._gainNode);
62+
this.configureInput(this._toneGainNode);
63+
this.configureOutput(this._toneGainNode);
6464
}
6565

6666
isP5SoundGain = true;

src/nodes/core/effect/P5SoundPanner.js renamed to src/nodes/effect/P5SoundPanner.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* @for p5.sound
55
*/
66

7-
import { P5SoundEffectNode } from "../P5SoundEffectNode.js";
8-
import { P5SoundParameter } from "../P5SoundParameter.js";
7+
import { P5SoundEffectNode } from "../core/P5SoundEffectNode.js";
8+
import { P5SoundParameter } from "../../P5SoundParameter.js";
99
import { Panner as TonePanner} from "tone/build/esm/component/channel/Panner.js";
1010

1111
/**
@@ -51,12 +51,12 @@ export class P5SoundPanner extends P5SoundEffectNode
5151
{
5252
super();
5353

54-
this._pannerNode = new TonePanner();
54+
this._tonePannerNode = new TonePanner();
5555

56-
this._pan = new P5SoundParameter(this._pannerNode.pan, panAmount);
56+
this._pan = new P5SoundParameter(this._tonePannerNode.pan, panAmount);
5757

58-
this.configureInput(this._pannerNode);
59-
this.configureOutput(this._pannerNode);
58+
this.configureInput(this._tonePannerNode);
59+
this.configureOutput(this._tonePannerNode);
6060
}
6161

6262
isP5SoundPanner = true;

src/Panner3D.js renamed to src/nodes/effect/P5SoundPanner3D.js

Lines changed: 72 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
* @for p5.sound
55
*/
66

7-
import { Context as ToneContext } from "tone/build/esm/core/context/Context.js";
8-
import { Panner3D as TonePanner3D} from "tone/build/esm/component/channel/Panner3D.js";
7+
import { Panner3D as TonePanner3D } from "tone/build/esm/component/channel/Panner3D.js";
8+
import { P5SoundEffectNode } from "../core/P5SoundEffectNode.js";
9+
import { P5SoundParameter } from "../../P5SoundParameter.js";
910

1011
/**
1112
* A 3D sound spatializer.
12-
* @class Panner3D
13+
* @class P5SoundPanner3D
1314
* @constructor
1415
* @example
1516
* <div>
@@ -34,7 +35,7 @@ import { Panner3D as TonePanner3D} from "tone/build/esm/component/channel/Panner
3435
*
3536
* function setup() {
3637
* describe(
37-
* 'A 3D shape with a sound source attached to it. The sound source is spatialized using the Panner3D class. Click to play the sound.'
38+
* 'A 3D shape with a sound source attached to it. The sound source is spatialized using the P5SoundPanner3D class. Click to play the sound.'
3839
* );
3940
* cnv = createCanvas(100, 100, WEBGL);
4041
* cnv.mousePressed(playSound);
@@ -50,7 +51,7 @@ import { Panner3D as TonePanner3D} from "tone/build/esm/component/channel/Panner
5051
* vY = random(-0.5, 0.5);
5152
* vZ = random(-0.5, 0.5) * 1.5;
5253
*
53-
* spatializer = new p5.Panner3D();
54+
* spatializer = new p5.P5SoundPanner3D();
5455
* spatializer.maxDist(100);
5556
* soundSource.loop();
5657
* soundSource.disconnect();
@@ -101,119 +102,101 @@ import { Panner3D as TonePanner3D} from "tone/build/esm/component/channel/Panner
101102
* </code>
102103
* </div>
103104
*/
104-
class Panner3D {
105-
constructor() {
106-
this.panner3d= new TonePanner3D({
107-
coneInnerAngle:360,
108-
coneOuterAngle:360,
109-
coneOuterGain:1,
110-
positionX:0,
111-
positionY:0,
112-
positionZ:0,
113-
}).toDestination();
105+
export class P5SoundPanner3D extends P5SoundEffectNode
106+
{
107+
constructor()
108+
{
109+
super();
110+
111+
this._tonePanner3DNode = new TonePanner3D
112+
(
113+
{
114+
coneInnerAngle: 360,
115+
coneOuterAngle: 360,
116+
coneOuterGain: 1
117+
}
118+
);
119+
120+
this._positionX = new P5SoundParameter(this._tonePanner3DNode.positionX, 0);
121+
this._positionY = new P5SoundParameter(this._tonePanner3DNode.positionY, 0);
122+
this._positionZ = new P5SoundParameter(this._tonePanner3DNode.positionZ, 0);
123+
124+
this.configureInput(this._tonePanner3DNode);
125+
this.configureOutput(this._tonePanner3DNode);
114126
}
115127

128+
isP5SoundPanner3D = true;
129+
130+
get positionX() { return this._positionX; }
116131
/**
117-
* Connects an input source to the 3D panner.
118-
* @method process
119-
* @for Panner3D
120-
* @param {Object} input an input source to process with the 3D panner.
132+
* Set the X position of the sound source.
133+
* @method positionX
134+
* @for P5SoundPanner3D
135+
* @param {Number} positionX the x position of the sound source.
121136
*/
122-
process(input) {
123-
input.getNode().connect(this.panner3d);
124-
}
137+
set positionX(positionX) { this._positionX.value = positionX; }
138+
139+
get positionY() { return this._positionY; }
140+
/**
141+
* Set the Y position of the sound source.
142+
* @method positionY
143+
* @for P5SoundPanner3D
144+
* @param {Number} positionY the y position of the sound source.
145+
*/
146+
set positionY(positionY) { this._positionY.value = positionY; }
147+
148+
get positionZ() { return this._positionZ; }
149+
/**
150+
* Set the Z position of the sound source.
151+
* @method positionZ
152+
* @for P5SoundPanner3D
153+
* @param {Number} positionZ the z position of the sound source.
154+
*/
155+
set positionZ(positionZ) { this._positionZ.value = positionZ; }
125156

126157
/**
127158
* Set the x, y, and z position of the 3D panner.
128-
* @method set
129-
* @for Panner3D
159+
* @method setPositionXYZ
160+
* @for P5SoundPanner3D
130161
* @param {Number} xPosition the x coordinate of the panner.
131162
* @param {Number} yPosition the y coordinate of the panner.
132163
* @param {Number} zPosition the z coordinate of the panner.
133164
*/
134-
set(x, y, z) {
135-
this.panner3d.positionX.rampTo(x, 0.01);
136-
this.panner3d.positionY.rampTo(y, 0.01);
137-
this.panner3d.positionZ.rampTo(z, 0.01);
165+
setPositionXYZ(xPosition, yPosition, zPosition)
166+
{
167+
this.positionX.rampTo(xPosition, 0.01);
168+
this.positionY.rampTo(yPosition, 0.01);
169+
this.positionZ.rampTo(zPosition, 0.01);
138170
}
139171

140172
/**
141173
* The rolloff rate of the panner.
142174
* @method setFalloff
143-
* @for Panner3D
175+
* @for P5SoundPanner3D
144176
* @param {Number} rolloffFactor
145177
* @param {Number} maxDistance
146178
*/
147-
setFalloff(rolloffFactor, maxDistance) {
148-
this.panner3d.rolloffFactor = rolloffFactor;
149-
this.panner3d.maxDistance = maxDistance;
179+
setFalloff(rolloffFactor, maxDistance)
180+
{
181+
this._tonePanner3DNode.rolloffFactor = rolloffFactor;
182+
this._tonePanner3DNode.maxDistance = maxDistance;
150183
}
151184

185+
get maxDistance() { return this._tonePanner3DNode.maxDistance; }
152186
/**
153187
* Set the maximum distance of the panner.
154188
* @method maxDist
155-
* @for Panner3D
189+
* @for P5SoundPanner3D
156190
* @param {Number} distance the maximum distance that the sound source can be heard from.
157191
*/
158-
maxDist(d) {
159-
this.panner3d.maxDistance = d;
160-
}
192+
set maxDistance(distance) { this._tonePanner3DNode.maxDistance = distance; }
161193

194+
get rolloff() { return this._tonePanner3DNode.rolloffFactor; }
162195
/**
163196
* Set the rolloff rate of the panner.
164197
* @method rolloff
165-
* @for Panner3D
166-
* @param {Number} r the rolloff rate of the panner.
167-
*/
168-
rolloff(r) {
169-
this.panner3d.rolloffFactor = r;
170-
}
171-
172-
/**
173-
* Set the X position of the sound source.
174-
* @method positionX
175-
* @for Panner3D
176-
* @param {Number} positionX the x position of the sound source.
198+
* @for P5SoundPanner3D
199+
* @param {Number} rolloff the rolloff rate of the panner.
177200
*/
178-
positionX(p) {
179-
this.panner3d.positionX.rampTo(p, 0.01);
180-
}
181-
182-
/**
183-
* Set the Y position of the sound source.
184-
* @method positionY
185-
* @for Panner3D
186-
* @param {Number} positionY the y position of the sound source.
187-
*/
188-
positionY(p) {
189-
this.panner3d.positionY.rampTo(p, 0.01);
190-
}
191-
192-
/**
193-
* Set the Z position of the sound source.
194-
* @method positionZ
195-
* @for Panner3D
196-
* @param {Number} positionZ the z position of the sound source.
197-
*/
198-
positionZ(p) {
199-
this.panner3d.positionZ.rampTo(p, 0.01);
200-
}
201-
202-
connect(destination) {
203-
if(typeof destination.getNode === 'function') {
204-
this.panner3d.connect(destination.getNode());
205-
} else {
206-
this.panner3d.connect(destination);
207-
}
208-
}
209-
210-
disconnect() {
211-
this.panner3d.disconnect(ToneContext.destination);
212-
}
213-
214-
getNode() {
215-
return this.panner3d;
216-
}
201+
set rolloff(rolloff) { this._tonePanner3DNode.rolloffFactor = rolloff; }
217202
}
218-
219-
export default Panner3D;

src/PitchShifter.js renamed to src/nodes/effect/P5SoundPitchShifter.js

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
* @for p5.sound
55
*/
66

7-
import { Context as ToneContext } from "tone/build/esm/core/context/Context.js";
87
import { PitchShift as TonePitchShift } from "tone/build/esm/effect/PitchShift.js";
8+
import { P5SoundMixEffectNode } from "../core/P5SoundMixEffectNode.js";
99

1010
/**
1111
* Change the pitch of a sound.
12-
* @class PitchShifter
12+
* @class P5SoundPitchShifter
1313
* @constructor
1414
* @example
1515
* <div>
@@ -27,7 +27,7 @@ import { PitchShift as TonePitchShift } from "tone/build/esm/effect/PitchShift.j
2727
* textAlign(CENTER);
2828
* textSize(9);
2929
* text('click to play sound', width/2, height/2);
30-
* pitchShifter = new p5.PitchShifter();
30+
* pitchShifter = new p5.P5SoundPitchShifter();
3131
*
3232
* soundFile.disconnect();
3333
* soundFile.connect(pitchShifter);
@@ -47,38 +47,26 @@ import { PitchShift as TonePitchShift } from "tone/build/esm/effect/PitchShift.j
4747
* </code>
4848
* </div>
4949
*/
50-
class PitchShifter {
51-
constructor(shiftValue = 1) {
52-
this.pitchshifter = new TonePitchShift(shiftValue).toDestination();
50+
export class P5SoundPitchShifter extends P5SoundMixEffectNode
51+
{
52+
constructor(shiftValue = 1)
53+
{
54+
super();
55+
56+
this._tonePitchShifterNode = new TonePitchShift(shiftValue);
57+
58+
this.configureMixIO(this._tonePitchShifterNode, this._tonePitchShifterNode);
5359
}
54-
60+
61+
isP5SoundPitchShifter = true;
62+
63+
get shift() { return this._tonePitchShifterNode.pitch.value; }
64+
5565
/**
5666
* Shift the pitch of the source audio.
5767
* @method shift
58-
* @for PitchShifter
68+
* @for P5SoundPitchShifter
5969
* @param {Number} pitchValue amount of semitones to shift the pitch
6070
*/
61-
shift (value) {
62-
if (value !== undefined) {
63-
this.pitchshifter.pitch = value;
64-
}
65-
}
66-
67-
connect(destination) {
68-
if(typeof destination.getNode === 'function') {
69-
this.pitchshifter.connect(destination.getNode());
70-
} else {
71-
this.pitchshifter.connect(destination);
72-
}
73-
}
74-
75-
disconnect() {
76-
this.pitchshifter.disconnect(ToneContext.destination);
77-
}
78-
79-
getNode() {
80-
return this.pitchshifter;
81-
}
71+
set shift(pitchValue) { this._tonePitchShifterNode.pitch.value = value;}
8272
}
83-
84-
export default PitchShifter;

0 commit comments

Comments
 (0)