Sending slider value / plotter values via OSC

hi,
could anyone help explain the most suitable way to send the value of a sliders current state via OSC?
im guessing obj.value.astring?
and a similar question with sending plotter values via osc,
‘’’
Signal.sineFill(1000, 1.0/[1,2,3,4,5,6]).plot;

‘’’
what is the best way to send this information?
many thanks

You just need to know the NetAddr of where you are sending the message, so IP address and port. The code below sends to a Fader on my iPad, but the message could go anywhere.

(

var oscFader = NetAddr("127.0.0.1", 61383);


w = Window.new.front;
c = NumberBox(w, Rect(20, 20, 150, 20));
a = Slider(w, Rect(20, 60, 150, 20))
.action_({
	c.value_(a.value);
	oscFader.sendMsg('/Container3/Fader4/x', a.value)
});
a.action.value;
)

Sending the entire Signal is a little trickier. This example just sends it to a local OSCFunc, but you can send the message wherever. The 2 tricks are using .as(Array) to turn the Signal into an Array and then the *, which takes an array and spreads it out into individual values (which is what the sendMsg needs.

a = Signal.sineFill(1000, 1.0/[1,2,3,4,5,6]);
~oscFader = NetAddr("127.0.0.1", 1200);

OSCFunc({|msg|
	msg.postln;
}, '/test', nil, 1200);

~oscFader.sendMsg('/test', *a.as(Array));

2 Likes

yeah thats soo helpful, thank u , could i send a buffer inplace on array?

  1. The maximum size of an OSC message may vary depending on OS and perhaps even on the LAN router. Sending a thousand values as in Sam’s example may or may not work. If it fails, you’d have to split up the array and send multiple messages, and reassemble on the other side.

  2. UDP is known to drop packets sometimes. It might not be reliable for transmitting large amounts of data. TCP is another option but trickier.

  3. Buffer data live in the server. sendMsg is a language operation. So you will need to transfer the data to the language first (loadToFloatArray). Or, the remote app could send /b_getn messages directly to the server.

hjh

1 Like