No problem. I’ll try and write you a simple abc on connecting TouchOSC and Sonic Pi together later today.
They say the best way to demonstrate knowledge is by teaching what you know to somebody else…
You’ve done the right thing by ticking ‘Receive Remote OSC Messages’ (an error I first made in that I hadn’t ticked it).
Next, have you configured TouchOSC to talk to Sonic Pi by going to settings in the app>Connections>Host and change it so that it is the IP address of the shared router (I’m assuming your computer and device with the TouchOSC app on are connected to the same network?). Then run the program with that code you posted earlier and fiddle with the A slider and you should hear sound? If not, fiddle with the slider and see if anything shows up under Cues (see pic). If nothing shows up under Cues, then the app and computer are still not connected…
In case you don’t use a VPN like me, the host IP address should be of the machine running Sonic Pi. This IP address can be found by looking in the IO section of the prefs.
I have made a series of three videos posted on youtube which show in detail how to create a simple layout in TouchOSC and set it up to control Sonic Pi 3. You can find the videos
here video1
here video2
here video3
or as a playlist here
The code used in the final Sonic Pi program (which is explained in detail in the third video) is below
#Test program to illustrate use of TouchOSC with Sonic Pi 3
#by Robin Newman, October 2017
set :trans,0 #set initial slider recorded position
#optional reset slider on TouchOSC
osc_send "192.168.1.240",9000,"/test/fader1",0
#optional reset onoff toggle to off
osc_send "192.168.1.240",9000,"/test/toggle1",0
sleep 0.2 #allow it to happen
#live loop to handle the push button
live_loop :b1 do
use_real_time
b = sync "/osc/test/push1" #match the push button address
puts "button 1 is ",b[0]
if b[0]>0 # only proceed when button is pushed, not released
use_synth :tri
10.times do #use 10 times loop to play some notes
play scale(:e3,:minor_pentatonic).choose,release: 0.1
sleep 0.1
end
end
end
#live loop to read slider position and record it with set :trans
live_loop :slider do
use_real_time
b = sync "/osc/test/fader1"
puts "slider is ",b[0]
set :trans,b[0]*12 #scale to +- octave
end
#live loop to respond to presses on the toggle switch toggle1
#this is used to switch on and off a long (1000 sec) note
#The pitch of the note is controlled by the slider value
live_loop :toggle do
use_real_time
b = sync "/osc/test/toggle1"
puts "toggle1 is ",b[0]
if b[0]>0 #if it is active (pressed and on)
use_synth :tri
x=play note(:c4)+get(:trans),sustain: 1000 #start a very long note and record referece in x
set :x,x #save x in :x for retrieval in following loop
in_thread do #a thread containing a continuously running loop
loop do
#get the control value and alter the pitch
#using the stored :trans value. Alter over a 0.1 slide time
control get(:x),note: note(:c4)+get(:trans),note_slide: 0.1
sleep 0.1 # wait for slide to finish and rerun loop
end
end
else #toggle has just been switched to off
control get(:x),amp: 0,amp_slide: 0.1 #fade out note
sleep 0.1
kill get(:x) #kill the long note (sustain: 1000)
end
end
As explained in the second video, the TouchOSC template is a zip or compressed file named tester.touchosc which contains a file index.xml shown below
<?xml version="1.0" encoding="UTF-8"?><layout version="15" mode="1" orientation="horizontal"><tabpage name="dGVzdA==" scalef="0.0" scalet="1.0" ><control name="bGFiZWwx" x="269" y="102" w="231" h="20" color="yellow" type="labelh" text="VG91Y2hPU0MgYW5kIFNvbmljIFBpIDM=" size="18" background="true" outline="false" ></control><control name="cHVzaDE=" x="181" y="193" w="45" h="45" color="red" scalef="0.0" scalet="1.0" type="push" local_off="false" ></control><control name="ZmFkZXIx" x="361" y="193" w="50" h="349" color="red" scalef="-1.0" scalet="1.0" type="faderv" response="absolute" inverted="true" centered="true" ></control><control name="dG9nZ2xlMQ==" x="547" y="193" w="45" h="45" color="red" scalef="0.0" scalet="1.0" type="toggle" local_off="false" ></control></tabpage></layout>
You can copy and save this as a text file index.html
Then compress this (right click and choose compress on the Mac, and right click and choose send to compressed folder on Windows) and rename the compressed file as tester.touchosc
This can then be put in the folder of TouchOSC files that are used with the TouchOSC editor, from whene you can load it into the Editor and then sync it to your IOS or Android device, running TouchOSC.
I hope you find the videos helpful. Please ask if anything is not clear.
Thank you sooooo much! This was super helpful. I am now successfully communicating through TouchOSC on my iPhone to Sonic Pi. So excited about all the possibilities.
That’s great. It is a super useful program (TouchOSC) and I’m sure you will have a lot of fun with it.
Awesome! Post a video of what you program it to do.
Hi Robin, hi Perpglo,
thanks also from my side! This will get me starting more easily. I bought the app but haven’t tried it out yet (I did mess around a bit with Control, which seems to have the same range of functionality - plus: it is Open Source).
But I guess touchOSC will be a brilliant tool for custom Sonic-Pi-midi interfaces.
Martin
Amazing stuff! Much easier to set up than I thought. Cellphone- and Wifi-powered control of Sonic Pi! Just spent about an hour and had a custom layout made with the touchOSC editor as well as osc messages within Sonic Pi. First project will be my ‘4-track’ recorder [1, 2] with a touchOSC layout. Using Arturia minilab was a good exercise but is very clumsy. I will post as soon as I have a working example. The good thing is, that you can distribute the interface as well…
For all who want to use touchOSC with Linux: You have to have installed some kind of client/bridge to receive the osc messages. I am successfully using touchosc2midi. I did not know that when I started… (That is wrong. See @samaaron and my comment below.)
Martin
Just for those who like the basic idea and care to improve it:
A few months ago I did a session with a Digeridoo-player. That was fun!
What I want to achieve now in a first step:
- Get live sound from another player into Sonic Pi (need to buy an external interface so that my laptop can work with it)
- Use the looper to record bits of it and play it back (using the touchOSC-interface to when and what I want to record)
- Have the option to modify the samples coming in (along with what I live-produce in Sonci Pi)
- Having a lot of fun with Sonic Pi as a live instrument
- …
Martin
That surprises me! Are you sending OSC or MIDI from TouchOSC? You’re much better off sending OSC and then it’s just a matter of Linux having a network stack which can handle UDP - which clearly all distros do! I’m very curious to know what issues you were having and why you needed a bridge…
If you use midi with TouchOSC then touchosc2midi performs the same function as the TouchOSC Bridge supplied with TouchOSC for Mac and Windows. This allows TouchOSC to send midi signals effectively over a LAN. Personally I use OSC almost exclusively now with TouchOSC communicating with Sonic Pi so don’t use this. It works fine just sending OSC messages to linux (eg RPi).
Well, actually I was also a bit confused because I did obviously receive osc messages which I could detect from running oscdump. But they did not seem to get through to Sonic Pi. (The osc area in the preferences also did not show any device.) Once the bridge was installed I received them via
sync /osc/...
(Now the midi area in the preferences shows the running bridge.)
It is probably my poor understanding of the underlying processes… I will have some time next week to check again. Thanks for making me aware of that. If there is an even more easier way, it would be great.
(I am so thrilled, that I can just switch on the Smartphone and communicate with Sonic Pi )
Update: You are right!
I just checked… I don’t need this osc2midi stuff!! Great. Thanks again.
I’m pretty sure the problem was that you hadn’t enabled external osc connections in the preferences. By default, Sonic Pi will only listen to messages from local host unless you specifically allow incoming messages from other machines. This stops the windows firewall from complaining in addition to stopping random users affecting your machine with rogue osc messages
Well, I think I did check that. (I did not change anything when I checked a few moments ago.) Probably I did something else wrong in the first place (could have been just a wrong sync path). Anyhow: Glad it works. Thanks again!
excuse me, i still have a question. the pc i use is asus and mobile is oppo. i had followed your tutorial step by step. but the sonic pi cannot catch the signal(osc) from touchosc. however, it can catch the midi signal from touchosc. my sonic pi can’t make out sound successfully. i need help~~~~
after i adjust the code in “sync”, it successfully works. but thanks again. :))