Link two or more computers

Hello everyone!

At my school, I’m trying to link 3 computers so my students could live-code together and do a shared performance. I assume it’s possible with link (@samaaron, you mentioned it when you announced the link support) but I can’t find any documentation or real life examples on how to do it…

Any help ?

Thanks!

Have you tried just clicking the “Link” button on all 3 computers? When I click it, it changes to say “0 Links”, If I run a second copy of Sonic Pi and click it in there, they both change to say “1 Link” and synchronise BPMs.

Hi Emlyn,

Yes, I checked this feature and it seams to be working. What I don’t understand is how all this link stuff work. I mean the link_sync for exemple.

I know how to sync bpm across devices but I would also like to sync live_loops across computers. One or two computers would wait for a cue from a third one before playing some live_loops if you see what I mean.

Any idea or examples ?

Thanks

I don’t have much experience using it, but I think the link command will sync a live_loop top the beginning of a bar (or use link n, m to sync to the mth beat of a n-beat long bar).
link_sync apparently does the same but also requires the link session to be “playing”, but I’m not sure what it means for it to be playing or how you would trigger that; I couldn’t find anything obvious in the Sonic Pi docs about it.

The lack of proper doc about all that link feature is my main problem… @samaaron maybe you could help us ?

I tried multiple search but couldn’t find anything useful…

Hi there Pierre
I dug out a program I’d previously used and tidied it up a bit so that you could try it out.
Link on Sonic Pi easily enables you to sync the tempo of different computers linked together (which you do by clicking the link button on the SP Metronome pane (select it on the view menu if it is not visible). and using link in the actual program. However this does not enable you to sync the start of programs easily. Link does contain facilities to use a transport mechnism as in most DAWS to generate start and stop signals, but of course Sonic Pi does not include this. However there are quite a number of singnals that are generated by the system, and you can see some of these in the cue log. For example each time you add a computer to the link it sends a signal /link/num-peers xx where xx is the number of computers linkd to the one you are using. So if for example you have pressed the link button on one computer’s Sonic PI the link button will go Red and say 0 Links as there are no other computers linked. If you look at the cues log you will see /link/connected. If you do the same on a second computer they will both display 1 Link and you will see the message /link/num-peers [1] in the log. My program uses this to detect the message and use it to send a cue to start the program you want to run. The important bit is in the first uncomment do …end section
This basically starts link on the program, then starts a live_loop to detect /link/num-peers messages. Once the number returned is equal to the number of computers you want to participate minus 1 then it sends a cue to start the program. Thus for three computers you want to detect there are TWO external Sonic Pi programs linked to your computer.
If you set up the programs as described in their comments on each of your computers, you can start them all synced together in tempo and starting time.
The example I have below plays a three part round of Frere Jaques. If you use three computeres you can comment out two instances and leave each one with ONE of the three live_loops :one to :three. Once the programs have started, if you change the line uncomment… to read comment… you can alter any one of the running prgrams, for example adding a trasnposition or a differnt synth and rerun that. Next time it starts the live loop it will make the alterations.

I’ve tested 4 computgers using this. two macs and two raspberry pi. (adjusting the number of peers entry as appropriate and it works fine. )
If they are not quite togetehr you can slightly adjust the global warm slider to bring them in sync. NB progrfam may nogt work as well with Wifi. Better with wired connections.

You can of course have any code you like after the initial starting code, and thus use this for collaorating jamming sessions


#Exploring use of Link on Sonic Pi by Robin Newman, March 2025

#Example program to explore the use of link to syncrhoise three different computers
#on the same local network, using Sonic Pi
# The example used is a three part round of Frere Jaques, but the individual computers
#can play any code you like which might be synced to other machines
#eg percussion loops, melody loops etc
#Ableton Link enables the tempo of the computers to be synced, but to start t
#YOu also need to be able to sync the programs starting. There is a link /start command
#but this needs a transport mechnaism such as in Ableton Live to be used.
#Instead on Sonic Pi I use the num_peers command which is emitted each time a computer
#joins or leave the link process. The code at the beginning of the program implements this
# it waits for the number of peers (ie the number of computers connectecd by link)
# to equal one LESS than the number of computgers involved, and then sends a cue to start the program.
#Once the program is running it can be commented out. This enables the prgram to be rerun
#whilst still running and synced by link. Uncomment again to enable a compuete syc restart.
#Whie the program is running, changes made to the tempo in the Link Metronone will be followed
#by all connected computers. Not change in small indrements. Large ones can cause sync to be lost.

#Program use. Install the program on three computeres preferrably hard wired to the same local network
#make sure that the sync code is uncommented on each.
#press the link button on the link metronone panel on TWO of the computers
#Run the program on all three computers. They will all enter a wait state, waiting for the third
#computer to be linked, and a /link/num-peers [2] signal to be received
#Now press the link button on the third computer. The program should start playing in sync on all 3.
#change uncomment to comment on the sync code for all three computers.
#you can now make alterations to any computer program, eg add use_transpose 12 to the top of the live_loop
#on one of the computers, or change the synth it uses. then rerun that program.
#If one or more computer programs are stopped., you need to to unlink one of then and redo the start process,
#If you have different types of computer you may need to adjust Global Time Warp in metronone panel
#
#sync start code switch line below to uncomment for first run
uncomment do # switch to comment once code running..Allows rerun without pause
  link
  live_loop :start do
    n = sync "/link/num-peers"
    if n[0]==2  #2 is ONE LESS than number of computers participating. Change as required
      cue :go
    end
  end
  sync :go
end

#user code starts below
#notes and their duration for Frere Jaqeeus
notes=(ring :c4,:d4,:e4,:c4,:c4,:d4,:e4,:c4,:e4,:f4,:g4,:e4,:f4,:g4,\
       :g4,:a4,:g4,:f4,:e4,:c4,:g4,:a4,:g4,:f4,:e4,:c4, :c4,:g3,:c4,:c4,:g3,:c4)
durations=(ring 0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,1,0.5,0.5,1,\
           0.25,0.25,0.25,0.25,0.5,0.5,0.25,0.25,0.25,0.25,0.5,0.5,0.5,0.5,1,0.5,0.5,1)
#Three live loops follow. YOu can try all of them on one computer
#or you can have a differnt one on each computer, commenting out the other two



live_loop :one do
  use_synth :beep
  #use_transpose 24 #option to try out
  notes.length.times do
    play notes.tick,sustain: durations.look,release: 0.125,amp: 0.5
    sleep durations.look
  end
end


live_loop :two,delay: 4 do #starts after 4 beat delay (in this case after first 8 notes)
  use_synth :tri
  #use_transpose 12 #option to try out
  notes.length.times do
    play notes.tick,sustain: durations.look,release: 0.125,amp: 0.5
    sleep durations.look
  end
end


live_loop :three,delay: 8 do #starts after 8 beat delay
  use_synth :saw
  #use_transpose -12 #option to try out
  notes.length.times do
    play notes.tick,sustain: durations.look,release: 0.125,amp: 0.5
    sleep durations.look
  end
end
2 Likes

Hi Robin!

Thanks for your input and ideas!

I’ll try them tomorrow with my students!