sendOSC with Pbind

I try to send OSC with some date for visualization.

Pbindef(\pdef_test1, \bla, Pfunc( {arg event; ~oscOut.sendMsg("/triger1", event.pan , event.freq ); } ) );

When i receive osc data in other software ,
freq data is correct but pan data is keep “0”.
I set it “1”.

I mistake some thing ??
Is there solution ??

//////tes code
s.boot;

~oscOut = NetAddr.new(“127.0.0.1”, 1234 );

//1 synth definition____________________________________________________/////////////////////////////////////////////

//sin pi
(
SynthDef(“sin_atac”, { | amp=0.5 , freq=400 , pan=1 |
var sig, env , ch ,val;

// パーカッション的な音の減衰を作る
env = EnvGen.kr(Env.perc(0, 0.11), doneAction: 2);

sig = SinOsc.ar(freq);

sig = sig*env;

sig = sig * amp ;
sig = Pan2.ar(sig, pan); // 左右の音の位置を決める

Out.ar(0, sig );

}).add;
);

Synth(“sin_atac”, [amp:0.5 , freq:1000 , pan: 1 ] );

//2 pattern____________________________________________________/////////////////////////////////////////////
(
Pbindef(\pdef_test1,
\instrument, “sin_atac”,
\dur, 1.0 ,
\freq, 1000 ,
\amp, 0.5,
\pan , 1,
);
)

//add osc event
Pbindef(\pdef_test1, \bla, Pfunc( {arg event; ~oscOut.sendMsg("/triger1", event.pan , event.freq ); } ) );

//play
Pdef(\pdef_test1).play;
Pdef(\pdef_test1).stop;

**i got attached image osc data.

I cannot test myself right now, but maybe it’s a matter of key order? If you want to access the event properties, the properties have to be set already, so the \bla key should come as last in the pattern definition.

Perhaps, as an experiment, you could add \bla, 1 at the end of \pdef_test1 to ensure it comes after all the others. Then, when you override the \bla key to add the osc event, it might work.

Thank you.
It worked!!

I tried random lefrt, right switched sound.
Pbindef(\pdef_test1, \pan, { rand(2)*2-1 } );

In sc, worked !!
But when i received osc , pan data is not matched to sound.
Sometimes sond left , but osc pan data is right.

Is there deep soft wear problem ??

This is test capture .
Left bottom , there is SC meter , and it is correct with sound pan.
Right bottom , these text is OSC data i got , but it is sometimes not same as SC meter.
Top visual just check OSC pan data.

This might be the same problem again.
My guess is key \bla is already evaluated (and the OSC sent out) before \pan is updated.
You could try to examine this by inserting some “trace” calls in the patterns.

Unfortunately I’m not an advanced user enough to propose a solution.
I hope someone else can chime in with deeper insights.

Not at my computer now, but something like Pbindef(\pdef_test1).source.pairs should show you the actual order of keys. Instead of trying to guess what is going on inside a black box, you could… open the box.

Also, when resetting a Pbindef, probably a good idea to .clear it. Otherwise it may remember an old ordering.

hjh

Thank you for help .
I traced “Pdef” and i found sending osc before pan set.
Do you know how to set these event order ??

These are Events that you’re highlighting.

Events are unordered collections. There is no connection between the order of processing and the order they appear in the event. So the screenshot doesn’t help with troubleshooting at all. It shows the result, but not the reason why this result occurred.

You need to investigate the order of the pairs in the Pbindef’s source pattern object.

hjh

This problem was solved other thread.
https://scsynth.org/t/pfunc-event-order-in-pbindef

Thank you.