Hi There
You are nearly there. One or two things to change.
First the osc message actually received when you adjust the fader is of the form
/osc:127.0.0.1:9000/fader1 [0.4881889820098877]
It contains several elements.
1 The osc header which shows it is an osc message rather than a cue or a midi message
2 after a colon the ip address from which it is received (in this case 127.0.0.1) or “localhost”
3 after a second colon the port from which it is sent (9000)
4 after a / the control name fader1
5 the value of the fader in the range 0…1.0 note it is sent in a list [0.4881889820098877] in my example
To extract this you need to use
a = sync "/osc*/fader1"
. #the * matches and ignores the ip and port data.
a will then contain [0.4881889820098877] (in my example)
to get its value you need to use puts a[0]
ie to get the first, in this case the only, element of the list.
If you only want to receive you do not need a use_osc statement. That only affects ip and port on which Sonic Pi SENDS osc messages. The ip address and port used by TouchOSC is controlled at THAT end, as shown in your setup photo.
Here is a simple progam which receives and prints the data as the slider is moved (my your mouse)
live_loop :test do
a = sync "/osc*/fader1"
puts "slider is at",a[0]
end
It is a good idea to add a port on which TouchOSC can receive incoming OSC mesages here. I put 9000 in.the Receive port.
Here is a fuller program I set up to test things which sends stuff bpth ways.
use_osc "localhost", 9000 #sets address and port to send to
live_loop :setIt do
use_real_time
#now send data to set fader: look at line info in language help to see how it works
osc "/fader1",line(0,1,steps: 50,inclusive: true).mirror.tick
sleep 0.1
end
live_loop :rx,delay: 0.1 do
use_real_time
a = sync "/osc*/fader1"
n = 48+(a[0]*48).to_i #set range of n as 48 to 96 in integer steps (the .to_i ensures this)
play n,release: 0.5
end
Note set up fader as per your example FIRST and start the TouchOSC program running before running theSonic Pi program.
You will not get the full value of TouchOSC on a Mac desktop because you really need a touch sensitive screen for best results, but you can either drive the control remotely 9as in my dxample) or you can drag the slider with your mouse.
Hope this helps. TouchOSC is a great proram, and you will ahve a lot of fun using it.