LiveOSC (Sonic Pi -> Ableton Live)

I’m still pretty new to Sonic Pi, but the first thing I needed was to try and record live_loops to tracks in Ableton. My goal was to sync BPM and start recording with tracks armed. I couldn’t find this else where so thought I’d share what works so far on a Mac (not sure about Windows, but believe it works the same):

UPDATE: Judging by a comment below, if you aren’t on a Mac you may need to install Python for this to work. https://www.python.org/

Install LiveOSC into the Live app on your system:

This receives on port 9000 and sends on 9001 (which is hard to find).

NOTE: You need to receive on port 4560. The LiveOSC command for that is:
osc "osc "/remix/set_peer", "", 4560

A list of available LiveOSC commands are here:

The only thing that was missing so far is the global record so I needed to just map the record button to a midi_cc.

My test session had 4 live_loops. I also wanted to record midi to two tracks. I set up a define for this, like so:

define :osc_setup do
      use_osc "192.168.1.6", 9000
      osc "osc "/remix/set_peer", "", 4560
  
     osc "/live/tempo", current_bpm
     osc "/live/arm", 0, 1
     osc "/live/arm", 1, 1
     osc "/live/arm", 2, 1
     osc "/live/arm", 3, 1
     osc "/live/arm", 4, 1
     osc "/live/arm", 5, 1
end

use_bpm 60

osc_setup
midi_cc 1, 1, channel: 9

To record multiple tracks at once I needed to setup a multichannel audio source using Loopback by Rogue Amoeba (a flexible aggregate audio builder). I used a normal “pass-through” as source with 10 channels and routed everything but the default 1,2 stereo channels to 4 other output channels like this.

Choose this as your mac audio source input
image

In Ableton you will also need to set this for your audio input:

And choose LiveOSC from your control surface under Link/Midi:

From inside each live_loop you can then use with_fx :sound_out_stereo, channel [channel you want to send to - remembering that with stereo they come in pairs - so I use 3, 5, 7, 9 for my 4 tracks.

You can also send midi out from the loops as needed. I use the IAC Driver on my mac (which wasn’t enabled by default):

With this when you run your code, it will start Ableton recording the tracks it arms. You still need to stop recording in Ableton, but it will start recording from the beginning.

This is pretty rudimentary, but a good starting point.

Oh, and you can also control params on devices and all kinds of other things. This was one of my main reasons for trying to learn Sonic Pi - even though it is incredible on its own.

There is also a Python library (pylive https://github.com/ideoforms/pylive ) that allows python control of Live - but what seems to be missing is the runtime engine available in Sonic Pi.

But this allows for some serious generative audio, midi and parameter control via Sonic Pi.

ONE CAVEAT SO FAR:
I thought I’d be able to receive these commands using the Max 4 Live “Connection Kit” which contains TouchOSC for learning/mapping OSC sends to parameters. This works much like @robin.newman shared in a previous post ( view it here ). However, for some reason I can’t receive any commands sent at this point in TouchOSC, even when set to port 9000 - so I assume that LiveOSC is commandeering that port.

UPDATE on reading OSC responses back in Sonic Pi:
If you send an OSC command that is just expecting a return - you have to actually read the cue log to see what OSC path/command it’s actually sending back then use ‘get’ from the Time State.

Example:
##| requests info from track zero, device zero
osc “/live/device”, 0, 0

##| returns all device parameters with names and values (it seems the OSCAPI doc is a bit incorrect here)
devices = get "/osc*/live/device/allparam"
puts devices

That will output an array into your log so you can find the exact parameter to manipulate.

2 Likes

First thanks for sharing your exporations !

Which version of Ableton Live do we need ?
Does the lighter version, Ableton live Intro is sufficient ?

Hi Isaac,

I don’t work with Ableton but I really appreciate this thorough documentation you have shared here!

The context of why I am generally interested in interfacing Sonic Pi with external gear/software: I meanwhile have a Fates, which is a Raspberry-based music platform originally developed by Monome and its community. Currently I am trying to marry Sonic Pi live coding with the different applications which Fates provides. So one of the main goals here is to clock Fates with Sonic Pi, which proves to be kind of tricky (although it seems to be simple).

Nice article. This was my previous post about using Ableton with SP

@nlb - I’m running the full version of Live 10, but I think it should work with the Lite version. LiveOSC also has two different forks on Github for 9.6 or later and also for prior. TouchOSC is a Max 4 Live device so you need the full version to access that (as Max iisn’t included in the lite version).

If it does work in the Lite versions I’m sure people would like to know. If you try it, please share your findings!

@Martin. Thanks! And that Fates looks like fun - now I want one! I need to dig deeper into that. It should be noted I suppose that yeah, the syncing is something I’m not even totally sure about yet with Ableton. As I’m just for now looking at recording and manipulating, the above works - trying to perform it all might be another story. As I’m still learning SP in the first place I haven’t gotten that deep yet. But algorithmic control of Ableton Live via SP code is definitely intriguing to me. Max is just not the way I envision code - at least for most of what I want to do. I’m not a super coder either but am familiar with many languages. Obviously using something more standardized is very powerful.

1 Like

Well bad news…

Tested with Adobe Live 9 Lite:

it seems not to work.

Am i correct with the set up in Ableton ?

the osc messages are well received (checked with another program)

EDIT : python must be installed ? Start of headhache :slight_smile: under windows 10

Interesting. Yeah, the Live setup looks accurate. I failed to mention the need for Python (forgetting the LiveOSC is python based). Python 2.7 is default on Macs and I had actually upgraded to 3.8 when installing PyLive, so I had that dependency already. I’ll edit my notes above though. Sorry if I steered you down one of those hurdle paths.

And yeah, worse, testing inside (other than trial and error) is tough without Max 4 Live and some of the tools in their connection kit (which mentioned in my caveat, don’t register with LiveOSC). TouchOSC is great for mapping any commands from SP to various things as @robin.newman showed, but I was most interested in the way I could have easy command control for recording at this point. You can’t for instance map TouchOSC to the transport record button. For algorithmic ‘knob twiddling’ and everything else it would be great. Another ideal would be if you do get it working with the Lite - but it is possible the developers realized that it was opening up the door to getting around a full purchase and stopped OSC support on it. I’ll try and do some research into that.

One thing @nlb - Here are my MIDI/Link settings:

  • I don’t believe the Link features (not in your Lite version) matter - that’s for Midi.

It is interesting though that under “input” it shows the greyed out “touchAble”. I’ll have to look into this, but again might be a default only included in the full Live Suite.

Hi
I’m trying to try LiveOSC with Ableton Live but it’s not working, something i am doing wrong

LiveOSC1

@Lunatico - for starters, it looks like you have the error OSC line incorrect:

osc "osc "/remix/set_peer", "", 4559

EDIT: I realize that this was in my code above. My fault for not typing code in the forum properly! And seems it’s been too long and I can’t edit.

should be

osc "/remix/set_peer", "", 4560

The first issue is the two osc calls with one in quotes. The second is that this command is telling Ableton to send OSC messages back to Sonic Pi on 4560, which can’t be easily adjusted. I think by default LiveOSC uses 9001, which means Sonic Pi won’t hear the messages. Sonic Pi sending can be whatever port you prefer (matching the port set wherever you are sending obviously), but the incoming is fixed for now.

Also, make sure you also have the send and receive OSC turned on in the Sonic Pi settings.

ADDITION: It’s been a while since I’ve done this all, but make sure @Lunatico that you do all of the setup mentioned above, including install python if you don’t have it already. On Mac OS (which I was using for this) python 2.7 should be installed. I updated to python 3 though.

Hi
Hypostatic a lot of thanks for your answer & help
I’ve tried but it doesn’t work.
No problem, I’ll wait for the configuration of the fantastic Reaper :wink:

Hey @Lunatico - see if this works for you: Sonic Pi OSC with REAPER

The hardest part might be routing all of the audio which is different on each system but I tried to explain the best I could.

Hello !

AbletonOSC sends response on the 11001 port. Sonic pi use 4560. How can i change this port to set to 11001 ?
Cheers

Probably easier to change it at the Control Ableton_Live 11 end. Looking at the software there is a file constants.py which sets the OSC_LISTEN_PORT and the OSC_SEND_PORT change the send port from 11001 to 4560 Before you install it. I think that should work, unless Ableton itself requires port 11001. I only have an earlier version of Ableton so cant test.

EDIT you can alter the code similarly in the sonic pi daemon.rb file Look for the line that says
"osc-cues" => 4560, This is around line 1363 and alter it to say "osc-cues" => 11001
Then resave. (you may want to save a copy of tehe original first). YOu can do this in an existing build, as it will not afrfect or need any files to be recompiled.
I tried it on a mac build looking inside the package Contents/Resources/App/Server/Ruby/bin folder to find the file. This will also work in LInuc builds. Haven’t tried Windows, but should be possible there tool.

1 Like

Thanks @robin.newman ! Your help is always appreciated :slight_smile:
it works a priori. I mean spi receives some osc messages from ableton live so good point.

in this folder, edit constants.py and restart Ableton Live
image

Now in SPI. I can set easily but get data is harder.

use_osc "localhost", 11000

# sending osc

osc "/live/song/set/tempo", 60
sleep 1
osc "/live/song/set/tempo", 110
sleep 1

# getting




##| (1653)(AbletonOSC)$ ./run-console.py
##| AbletonOSC command console
##| Usage: /live/osc/command [params]
##| >>> /live/song/set/tempo 123.0
##| >>> /live/song/get/tempo
##| (123.0,)
##| >>> /live/song/get/track_names
##| ('1-MIDI', '2-MIDI', '3-Audio', '4-Audio')

foo = osc "/live/song/get/tempo"

print foo

image

I guess i have to use a live_loop but i have to check my past notes :slight_smile:

Yup, you need a live loop. Something like this I would imagine, looking at your info above

live_loop :getTempo do
  t = sync "/osc*/live/song/get/tempo"
  puts "tempo is: #{t[0]}"
end

live_loop :getTrackNames do
  tn = sync "/osc*/live/song/get/track_names"
  tn.length.times do |x|
    puts "track_name #{(x+1)} is #{tn[x}" #index goes from 0 so track_name 1 is when x=0
end

thank you @robin.newman but no success with this code ( a little typo)…

live_loop :getTempo do
  t = sync "/osc*/live/song/get/tempo"
  puts "tempo is: #{t[0]}"
end

live_loop :getTrackNames do
  tn = sync "/osc*/live/song/get/track_names"
  tn.length.times do |x|
    puts "track_name #{(x+1)} is #{tn[x]}" #index goes from 0 so track_name 1 is when x=0
  end
end

i will look at the reasons why tomorrow :slight_smile:

Good morning,

Okay so with AbletonOSC to get some data, you have first to send the osc message then AbletonOSC will send you the answer

use_osc "localhost", 11000

# sending osc

osc "/live/song/set/tempo", 60
sleep 1
osc "/live/song/set/tempo", 110
sleep 1

# getting




##| (1653)(AbletonOSC)$ ./run-console.py
##| AbletonOSC command console
##| Usage: /live/osc/command [params]
##| >>> /live/song/set/tempo 123.0
##| >>> /live/song/get/tempo
##| (123.0,)
##| >>> /live/song/get/track_names
##| ('1-MIDI', '2-MIDI', '3-Audio', '4-Audio')

live_loop :getTempo do
  osc "/live/song/get/tempo"
  t = sync "/osc*/live/song/get/tempo"
  puts "tempo is: #{t[0]}"
end

live_loop :getBeat do
  
  t = sync "/osc*/live/song/beat"
  puts "beat number: #{t[0]}"
end

live_loop :getTrackNames do
  
  path = "/live/song/get/track_names"
  osc path
  tn = sync "/osc*"+path
  tn.length.times do |x|
    puts "track_name #{(x+1)} is #{tn[x]}" #index goes from 0 so track_name 1 is when x=0
  end
end

image

Maybe kill the live_loop when i get the info but don’t know how to. @robin.newman an idea ?

First use of AbletonOSC so i guess my journey just begins :slight_smile:
So next episode soon

Have a good day