Sonic-Pi Network Collaboration Ressources

Hi everyone!

I’m still trying to put together a network based piece for Sonic-Pi. Do you know if Ableton Link, Carabiner and other technologies like this could allow me to :

  1. Run a Master Sonic-Pi on a local wifi network that would cue the beginning of each bar.
  2. Run between 3 and 8 slave Sonic-Pi that would catch the cue and try to do some latency compensation.

I’ve tried many things and solutions, but I still end up with too many milliseconds of delay between each computers. I’ve seen that Ableton Link may be something to try.

If someone has some experience doing this kind of things, let me know.

1 Like

This article Sonic Pi Orchestra may be of some use. You can use it just to send cues, rather than parts to play.
Basically for latency you find by trial and error the slowest (ie longest latency machine) and then delay commands to play notes on the others by an amount that gets them playing together. The latency shift is constant.
I find it is better if the broadcast machine is wired to your router, so that there is only one WiFi link on any path. Once you get more than one, you can get jitter.
I think xavierriley has done some work with Ableton Link, but not sure how far it has progressed.

Hey Robin,

First I must thank you because I’m using your code snippets as a base to improve and reach what I’m trying to do. I’m using the same synchronisation method as you, but I think that our goals are different. In the videos you posted on YouTube, you are using one computer to trigger all the other computers, or you are always using a fixed material (a score you parsed so Sonic-Pi can understand it).

What I’m trying to do is to be able to improvise on 8-9 computers that are in the same room, without any kind of drifting tempo and be precise enough to be able for instance to create a drum pattern, with each drum being played by a different computer.

For now, the best solution I got involves using the rt command for everything, instead of using wait or sleep. It allows me to have a “close enough” type of synchronisation, without having to struggle on getting the best connexion possible. If the main computer sending cues is stable (no other programs running in background), I can do something that sounds like what I intend to do.

I would like to use something really strong that care about latency compensation in a fancy way, so Ableton Link seemed to be the good solution for me.

I’ve seen the GitHub post that @xavierriley made some times ago, and I’m really curious about how he managed to do that. That would be awesome for me to use Ableton Link.

EDIT: Here is what I got so far, running very smoothly on three computers.

The Sonic-Pi master is running this:

live_loop :sendsync do ; tick
  bpm=get(:bpm) # still got traces of your good old code, Robin.
  use_bpm bpm
  osc_send "",4559,"/sync",bpm # first Sonic-Pi client
  osc_send "",4559,"/sync",bpm # second Sonic-Pi client
  sleep rt(0.01) # the less I sleep, the better the sync? 

On the client-side of things, here is what I got:

live_loop :n1 do ; tick
      b = sync "/osc/sync"
      play (ring :c3, :c3, :bb3, :ab3, :g3).look
      sample :drum_bass_hard, rate: 0.7, amp: 1 if bools(1, 0).look
      sample :drum_snare_hard, rate: 0.7, amp: 1 if bools(0, 0, 1, 0).look
      sleep rt(0.5)

live_loop :n2 do ; tick
  b = sync "/osc/sync"
  play (ring :eb3, :g3, :bb3, :c4, :eb4, :bb4).look
  sample :drum_cymbal_closed, amp: rrand(0.5, 1)
  sleep rt(0.5)

Hey! Quick update that might interest some people here.

I’ve talked to dktr0 (David Ogborn) who is in charge of the ExtraMuros GitHub project. I asked him if it was possible to use his software with Sonic-Pi. He pushed a new update today to allow this. It is now possible to create shared network sessions of Sonic-Pi.

You can try it now.

I’m really glad that he did that, and I hope that it will help people like me who’d like to play with Sonic-Pi in a collaborative way. I haven’t tried it yet but I’ll do as soon as I can.

1 Like

Gave this a try. Seems to work OK. Just 1 server and 1 client so far. I’ll try several together now…
now tried with two clients, and they play nicely synced together.
if you have different latencies on your computers running SP, you can delay the quicker one using the command set_sched_ahead_time! t where t is the delay that you need to sync them. Just run this in a buffer before you start using the system, and it will remember the delay set until you quit SP or reboot it.

We finally found an efficient solution to synchronize any number of computers on the local network. There is a Link package for Max/MSP (Ableton Live) that you can use to send very regular cues to any clients running the same patch.

The Sonic-Pi scheduler sometimes struggle to keep a straight tempo, but if something like this happen, you can always resynchronize in the middle of the performance for better precision.

I might post detailed instructions to do that a bit later in the future. I just want to say that it’s a solution that works really really well, without any noticeable latency.

1 Like

Hey people, I was thinking that it would be cool to give you an update about what I found so far on the subject of network synchronization for Sonic-Pi.

  1. The Max/MSP synchronization solution

I’m currently preparing a piece for the Princeton Laptop Orchestra, using Sonic-Pi. We built a custom Max/MSP patch that gives you the ability to synchronize N instances of Sonic-Pi very precisely on a local network. Here is a screen of the patch. Note that you can run it even without buying Max/MSP. You can just run it, and it will work.


  • The toggle starts the synchronization (through the Ableton Link package). The bang left to it is just a visual feedback on the synchronization. You can check on other players screen if you are synchronized or not. The button is blinking every bar at the current tempo.
  • The other big button is doing two different things. 1) it starts Sonic-Pi 2) a file text is copied to your clipboard so you can paste it in your Sonic-Pi editor. Then, you are ready to play.
  • The other buttons are used for my piece only. The first button opens the snippets folder (so new players can have access to some pre-written lines of code). There is a (broken) button to install some custom samples somewhere on the hard drive. The “copy to clip” is just a safety button, and the other one is not important.

On the Sonic-Pi side, every player is running a custom-made loop that ensures synchronization. Here is an example:

# This function is used only if a player is for some reason loosing
# the synchronization with the other players.

define :group do ; sync "/live_loop/a" ; use_real_time ; end

# This is a condensed version of the sync system. 

live_loop :a do ; tick ; use_real_time ; b = sync "/osc/pulse" ; use_bpm b[0] ; set :bpm, b[0] ; end

live_loop :gong, sync: :a do ; tick ; use_real_time ; use_bpm get(:bpm) ; if pat("---- ---- 1--- ---- ---- ----").look > 0
    with_fx :bitcrusher, bits: 6 do
      sample gong, "gong", rate: 1
    sample pl, 1, rate: 0.25
end ; sleep (ring 0.125).look ; end

As you can see, the live_loop :a is waiting for a pulse sent through OSC. The pulse sent is also sending the master tempo from the Max/MSP patch. Sonic-Pi will make sound only and only if the Max patch is open and running.

The group function is used to get back in time if necessary. The other loops are just syncing once on the master loop, so if you change the sleep time too much and too often, desynchronisation may happen (and can be a cool musical effect).

  1. Extramuros / Troop

You can also synchronize multiple performers by using some softwares developed by the live-coding community. Extramuros just added a support for Sonic-Pi and crucial improvements have been made to Troop. I’m very grateful that the devs were so reactive and were very receptive to requests and questions. If you want to play with friends accross the globe, that’s what you should do.

I see two possible cool applications of these softwares:

  • simultaneous multiple locations concerts.
  • shared editor live-coding.

It also gives very interesting visual indications for your audience. They can really see the piece being built by multiple people playing music together.

Please let me know if you have questions about all this, because I think that collaborative Sonic-Pi is really something that could be both artistically and pedagogically interesting.

EDIT: I’ll try to record a performance if I can so you can see how it works. I’ll also post the Max/MSP patch soon. I just want to make it a useful and complete tool for network performances.

1 Like

Looks amazing! Thanks for sharing this.

Distributed Sonic Pi is definitely one of my goals and I have got extensive ideas and plans already. I want to make all this stuff work out of the box and also be simple enough for 10 year old kids - but there’s a lot of work to be done yet and is currently very much vapourware.

This, however, is real and available now - so that’s fab!

1 Like

Hi Bubo,

I am enquiring whether the Max patch is available yet? I took a look on your website today hoping I would find it there. I would love to use it with a new live coding group that I am forming. We are hoping to create an ensemble piece using a number of networked machine in July.

Thanks for the summary above. I appreciate your work!

All the best for now.



You’re right, I totally forgot to share it. You can now find it here : Github Link. Please, note that this is a very experimental / hacky / funny attempt at creating a network synchronization for Sonic-Pi. It definitely works really well, but I cannot guarantee you that it is the best way to do it. I do believe that creating an open-source software to do it with more simplicity is the way to go.

If you feel that you can improve it in some way, please do. My only hope is to interest more people in getting an easy, functional and working network-synchronization for Sonic-Pi to play as a band/orchestra.

You can send me a PM if you want to talk about it or if you want some help with configuration.

Thank you very much for the link. I will test the patch and let you know how it goes. I’ll pm you as soon as we are up and running.

Thanks again Bubo, chat soon.


Glitch Demo:!/sonic-pi-remote-start

I’ve been experimenting with the remote syncing software Croquet and I’ve come up with a simple way to sync up two instances of Sonic Pi running on separate computers via a single webpage. The way this works is that you need the IAC Driver running on both copies of Sonic Pi, you then create a Sonic Pi loop that syncs to a midi note_on message and Croquet will reflect the start message to all connected vistors to the webpage when the start button is clicked. Each time you visit the page a unique session ID is created so you’d have to share the complete link with session ID to the other computers. But I think that to be much simpler than having separate software to run and collect IP addresses etc. I’d love to hear folks thoughts on this.

As an aside, is there a way to call Sonic Pi’s Run and Stop commands from within a midi responder or something else?


As croquet seems not to be available right now,
we can achieve this kind of sync via open stage control.

AFAIK not directly you have to use kill instruction tips in live_loop loops.

Thanks for the tip on Open Stage Control. I haven’t come across that yet. It looks fantastic!

1 Like