Is there a way to send the freq value from a pbind to Processing?

Its not quite that simple as there is no guarantee the event will happen at the same time, in fact, although they might be very close together, the server messages will all be sent at different times. Also, it depends what format you want them in.

Below, I’ve assumed you want them as a flat array, one after the other. Thats probably not the best idea as you will have to remember what order you put them in. Using different osc address for different piece of information is a better idea, but this is what it might look like.

SynthDef(\synthA, { 
	var env = Env.perc(0.01, \dur.kr - 0.01).ar(doneAction: 2);
	var sig = SinOsc.ar(\freq.kr) * 0.2 * env;
	Out.ar(0, Pan2.ar(sig, \pos.kr)); 
}).add;

~net_addr = NetAddr("localhost", 57120);

~keys_to_send = (
	\freq: 200, // a bunch of default values
	\amp: 1
);

~update_key = {|key, value|
	~keys_to_send =  ~keys_to_send ++ (key.asSymbol : value); // replaces values
     // here we send
	~net_addr.sendMsg('/my/osc/addr', ~keys_to_send[\freq], ~keys_to_send[\amp] );
};


Pdef(\pat1, Pbind(
	\instrument, \synthA,
	\freq, Pwhite(200, 400),
	\pan, -1,
	\dur, 0.5,
	\callback, {|c| topEnvironment.use{ ~update_key.(\freq, c[\freq]) } }
));

Pdef(\pat2, Pbind(
	\instrument, \synthA,
	\freq, Pwhite(600, 800),
	\amp, Pwhite(0.01, 1.0),
	\pan, 1,
	\dur, 1,
	\callback, {|c| topEnvironment.use{ ~update_key.(\amp, c[\amp]) } }
));

Pdef(\pat1).play
Pdef(\pat2).play


OSCdef(\t, _.postln, '/my/osc/addr')
1 Like