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 ;
0 commit comments