Get the value from the Osc function

(
~osc_receive = OSCFunc(

{ arg msg, time, addr, recvPort;

post('Revceived message to path: ');
msg[0].postln;

post('With value: ');
msg[1].postln;

}, '/test/message');
)

(
Ndef(\bass, {
	Pan2.ar(SinOsc.ar(110, 0, EnvGen.kr(Env.perc(0.0, 1.0), Impulse.kr(1))));
}).play;
)


I have question to get the value from the Osc

I run the two pc for visual and sound,
get the other computer’s message to control the Supercollider.
for example, from the OSC(other pc), send a level value or impulse
then how to read the values from the OSCFunction or defined global variable “~osc_receive”?

I found the OSCDef, but In this time, I just get the values from OSC

I think you are already doing so, in your code, the OSC function is receiving the message then you can decide what to do with the incoming values you can implement it in the function as well. For example, Ndef(\bass).set(\speed, msg[0]); of course, this is dependent on the format of the ongoing streams of data, that is, n.sendMsg('/test/message/, rrand(0.1, 1.0)) so to recreate your code you need something like this below:

Spec.add(\speed, [1, 20]);

(
OSCdef(\test_osc, { |...args|
	var value = args[0][1];
	("Raw Value: " + value).postln;
	Ndef(\test).set(\speed, \speed.asSpec.map(value / 100).postln ); 
//spec is here unnecessary but useful .map expects a normalized range.
}, '/test/message/');
)

//Control something below:
(
Ndef(\test, {
	Impulse.ar(\speed.kr(0.5))
}).play;
)

NetAddr("127.0.0.1", 57120).sendMsg('/test/message/', rrand(1, 100.0));


OSCdef(\test_osc).disable; //off OSC
OSCdef(\test_osc).enable; //On again!
1 Like

Hi, thanks, I solved the issues! I try to figure out the parameter outside of the OSCdef, but I think this is a reasonable solution to handle the parameter in the time domain! Thanks

1 Like