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?
@Sam_Pluta @jamshark70
what if i had an array of 4 gui sliders, how do i send those four values?
as an array of an array?
an OSC embedded arg array?
thanks
Inside the action for each slider, put the value for that slider inside the “vals” array, then send all four like this:
netAddr.sendMsg('destination', vals[0], vals[1], vals[2], vals[3]);
@Sam_Pluta hmmm i think im still struggling to get a grasp…
what about this example, how do i use that configuration here?
~sliders = Array.fill(4,
{arg i;
var t = NumberBox(w,Rect(15+(40*i),270,37,22))
.action_({arg obj;
var ovf = obj.value.asFloat;
t.scroll_step=(0.1);
if(ovf != 0,
{~sliders[i] = ovf;
~notes.do({arg item;
if(item.isPlaying,
{item.seti(\ratio,i,ovf);});
})
});
obj.value = ~sliders[i].asString;
});
t.string = ~sliders[i].asString;
t;
q = ~sliders;
~screen = 6; //reciever address related
~displayOSC = NetAddr("192.168.7.2", 7562);
~displayOSC.sendMsg('/targetMode', 1); // this is related to reciever side address
OSCFunc({|msg|
msg.postln;
}, '/test', nil, 1200);
~displayOSC.sendMsg('/number', ~screen, *q.as(Array));
});