Skip to content

Instantly share code, notes, and snippets.

@rbnpi
Last active November 17, 2018 18:39
Show Gist options
  • Save rbnpi/aa9bc44908386d8cff736ada30975302 to your computer and use it in GitHub Desktop.
Save rbnpi/aa9bc44908386d8cff736ada30975302 to your computer and use it in GitHub Desktop.
Experimental program to receive notes from a second machine running SP 2.12beta and play them in synchronism. Requires a processing script to run on each machine as well. Video at https://youtu.be/jc45yr-LUNc

EXPERIMENTAL PROGRAMS TO SYNC TWO MACHINES RUNNING SONIC PI TOGETHER

These programs utilise experimental commands in Sonic Pi 2.12beta (after commit #78b2216). The first of the experimental commands lets you send OSC messages to a specified port on your local machine

use_osc "localhost",8000

The second osc lets you send an OSC message, which is specified in the command line. Sonic Pi can receive external OSC messages on port 4557 (which can handle commands to run Sonic Pi code, and is used by the sonic-pi-cli gem written by Nick Johnstone. However recently port 4559 has been opened for the specific purpose of receiving commands which are expected to be exernally generated sync commands, which can also incorporate additional paremeters. These can have a simple format like

osc "\waitforit","c4",1.5,60

which works like a sync command with three parameters. These can be extracted using

s=osc "\waitforit,"c4",1.5,60
nvalue=s[0]
durationvalue=s[1]
tempovalue=s[2]

By sending a succession of such cues, it is possible to play a lisat of notes accurately synced to the originating machine, and this is what these demonstration programs show.

At present, Sonic Pi is limited to using the use_osc command only on the local machine, and port 4557 and 4559 will also only accept input from the local machine, for security reasons. It may be later, that port 4559 will be able to accept OSC messages directly produced from external (ip) sources. At present, the way round this is to use two processing scripts, one running on each machine to act as intermediary relays for the osc messages. The two scripts concerned are not difficult to follow. On the orginating computer, the script accepts OSC messages on port 8000, and then rebroadcasts them to the receiving computer (in my case on ip address 192.168.1.33) to port 8000. On the receiving computer, the processing scripts listens on port 8000 and rebroadcasts to the local machine on poert 4559 (the "sync" port for Sonic Pi)

There is one receiving program which runs in a buffer on teh receiving machine;s Sonic Pi. This has a live_loop which waits for the incoming sync, matches the namein to /waitforit and then extracts the threee parameters.

(NEXT SECTION REMOVED****)

There are two alternative routes through the rest of the loop which depend on whether single notes are being sent, or whether chord info si being sent with two or more notes sounding together. A slightly differnt extraction mechanism is required ineach case, and is selected according to the length of the first parameter.)

**** Sam Aaron suggested that it was unwise to have to use eval of a string in the receive program, becuase of possible mal use. Instead I have rewritten the BachSend2.rb program so that chords are preprocessed and sent as a series of single notes one after the other. Experiments show that this only introduces a delay between "concurrent" notes of 0.0008 seconds which is acceptable. He also said that the intention was for use-osc to be able to communicate with external ip addresses, so this may obviate the use of the process sketch on teh transmitting side, when it is adjusted.

In the examples, the bpm paramter is constant throughout, but it can handle pieces where there is more than one component to the array of notes eg a1[0] and a1[1] etc.... and each can have separate bpm settings.

I hope that this brief outline will help you to understand what is going on, and how the system works.

Finally, just to emphasise that this code is experimental. The commands in Sonic Pi are NOT fixed and will more than likely change, but it is still instructive and fun to try this out. Just make sure you have the appropriate version of SP2.12beta

If you have not used processing before then just download the app from https://processing.org/download/ Put the the two .pde files into the processing folder which will be created in your My Documents folder when you run the app. When you the select and open the script (they are called sketches) it will aotomatically create a folder of teh same name and place it in that for you. To run the script you click on the arwow head as shwon in the video

#experimental program one to send notes to
#SP running on a second computer, using OSC sync
use_osc "localhost", 8000
sleep 1 #allow OSC time to setup
use_synth :piano
with_fx :reverb,room: 0.6 do
a1=[]
b1=[]
a1[0]=[:r,:C4,:D4,:E4,:F4,:D4,:E4,:C4,:G4,:C5,:B4,:A4,:B4,:C5,:D5,:G4,:A4,:B4,:C5,:A4,:B4,:G4,:D5,:G5,:F5,:E5,:F5,:G5,:E5,:A5,:G5,:F5,:E5,:G5,:F5,:A5,:G5,:F5,:E5,:D5,:C5,:E5,:D5,:F5,:E5,:D5,:C5,:B4,:A4,:C5,:B4,:D5,:C5,:B4,:A4,:G4,:Fs4,:A4,:G4,:B4,:A4,:D4,:C5,:B4,:C5,:D5,:B4,:A4,:G4,:Fs4,:E4,:G4,:Fs4,:A4,:G4,:B4,:A4,:C5,:B4,:D5,:C5,:E5,:D5,:B4,:C5,:D5,:G5,:B4,:C5,:B4,:A4,:G4,:G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25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.125,0.125,0.25,0.25,0.125,0.125,0.25,0.25,0.25,1.0,1.0,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.125,0.125,0.75,1.0,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,1.0,1.0,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,1.0,1.0,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,1.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.125,0.125,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,2.0,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,2.0,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,2.0,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,2.0,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.5,0.5,0.125,0.125,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,4.0]
c1=[70]
in_thread do
for i in 0..a1.length-1
use_bpm c1[i]
for j in 0..a1[i].length-1
play a1[i][j],sustain: b1[i][j]*0.9,release: b1[i][j]*0.1
sleep b1[i][j]
end
end
end
end
a2=[]
b2=[]
a2[0]=[:r,:r,:C3,:D3,:E3,:F3,:D3,:E3,:C3,:G3,:G2,:r,:r,:G3,:A3,:B3,:C4,:A3,:B3,:G3,:C4,:B3,:C4,:D4,:E4,:G3,:A3,:B3,:C4,:E3,:Fs3,:G3,:A3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25,0.5,0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.5,0.5,0.5,0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.5,0.5,0.5,0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.5,0.5,0.5,0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.5,0.5,0.5,0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.5,0.5,0.125,0.125,0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.5,0.5,0.5,0.5,0.5,0.5,1.0,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,2.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,2.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,2.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.5,0.5,0.5,0.5,0.25,0.25,0.25,0.25,0.5,0.5,4.0]
c2=[70]
in_thread do
for i in 0..a2.length-1
use_bpm c2[i]
for j in 0..a2[i].length-1
osc "/waitforit",a2[i][j].to_s,b2[i][j],c2[i]
sleep b2[i][j]
end
end
end
#experimental program two to send notes to
#SP running on a second computer, using OSC sync
#this example processes chords by sending separate notes in quick succession
#altered from original example. See ReadMe.md file
use_osc "localhost", 8000
sleep 1.5 #allow OSC time to set up
use_synth :piano
with_fx :reverb,room: 0.6 do
a1=[]
b1=[]
a1[0]=[[:Bf3,:D4],[:C4,:G4],[:C4,:A4],[:D4,:Bf4],[:Ef4,:C5],[:D4,:A4],[:D4,:Fs4],[:C4,:Fs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2,:G3],[:A2,:A3],[:G2,:Bf3],[:Ef3,:Bf3,:C4],[:F2,:F3,:C4],[:G2,:Bf2,:C4],[:F2,:Bf3],[:Ef2,:A3],[:F2,:A3],[:G2,:G3],[:C3,:G3],[:G2,:A3],[:G2,:Bf3],[:D3,:A3],[:G2,:Bf3]]
b2[0]=[1.0,1.0,1.0,1.0,1.0,2.0,1.0,1.0,1.0,1.0,1.0,1.0,3.0,1.0,1.0,1.0,1.0,1.0,3.0,1.0,1.0,1.0,1.0,1.0,2.0,1.0,1.0,0.5,0.5,1.0,1.0,1.0,1.0,0.5,0.5,1.0,1.0,1.0,0.5,0.5,1.0,1.0,4.0]
c2=[80]
in_thread do
for i in 0..a2.length-1
use_bpm c2[i]
for j in 0..a2[i].length-1
if a2[i][j].respond_to?(:each) #detect chord inside [..]
a2[i][j].each do |nv| #process each note in chord in succession
osc "/waitforit",nv.to_s,b2[i][j],c2[i] #no gaps between notes
end
else
osc "/waitforit",a2[i][j].to_s,b2[i][j],c2[i]
end
sleep b2[i][j] #gap after single note or chord is processed
end
end
end
#experimental program 3 to send notes to
#SP running on a second computer, using OSC sync
use_osc "localhost", 8000
sleep 1 #allow time to set up OSC channel
use_synth :piano
a1=[]
b1=[]
a1[0]=[:r,:E4,:G4,:B4,:G4,:E4,:E5,:B4,:E5,:Ef5,:B4,:Ef5,:Fs5,:Ef5,:B4,:B5,:Fs5,:B5,:G5,:Fs5,:E5,:D5,:C5,:B4,:A4,:C5,:E5,:G5,:Fs5,:E5,:Fs5,:E5,:D5,:C5,:B4,:A4,:G4,:B4,:D5,:F5,:E5,:D5,:E5,:Fs5,:E5,:Fs5,:G5,:D5,:C5,:D5,:r,:G5,:Fs5,:G5,:Fs5,:G5,:A5,:B5,:C6,:r,:B5,:A5,:B5,:A5,:G5,:A5,:C5,:B4,:G5,:Fs5,:G5,:Fs5,:E5,:Fs5,:A4,:G4,:E5,:Fs5,:E5,:D5,:Cs5,:Fs5,:G5,:Fs5,:E5,:D5,:Cs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,0.5,0.5,0.125,0.125,0.25,0.5,0.5,0.5,0.5,0.5,0.25,0.25,0.25,0.25,0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.125,0.125,1.25,0.25,0.25,0.25,0.25,0.25,0.25,0.5,0.5,0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.5,0.5,0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.5,0.125,0.125,0.25,0.5,0.125,0.125,0.75,0.5,0.5,0.125,0.125,0.25,0.5,0.25,0.25,0.5,0.5,0.5,0.125,0.125,0.25,0.5,0.5,0.5,0.5,0.5,0.125,0.125,0.25,0.5,0.5,0.5,0.5,0.5,0.25,0.25,0.25,0.25,0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.125,0.125,1.25,0.25,0.25,0.25,0.25,0.25,0.25,0.5,0.125,0.125,0.25,0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.5,0.125,0.125,0.25,0.5,0.25,0.25,0.25,0.25,0.75,0.25,0.25,0.25,0.75,0.25,0.25,0.25,0.75,0.25,0.25,0.25,0.75,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.125,0.125,0.75,0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.75,0.25,0.25,0.25,0.25,0.25,0.125,0.125,1.25,0.25,0.25,0.25,0.25,0.25,0.25,0.5,0.125,0.125,0.25,0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.5,0.125,0.125,0.25,0.5,0.25,0.25,0.25,0.25,0.75,0.25,0.25,0.25,0.75,0.25,0.25,0.25,0.75,0.25,0.25,0.25,0.75,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.125,0.125,0.75,0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.75,0.25,0.25,0.25,0.25,0.25,0.125,0.125,1.25]
c1=[80]
in_thread do
for i in 0..a1.length-1
use_bpm c1[i]
for j in 0..a1[i].length-1
play a1[i][j],sustain: b1[i][j]*0.9,release: b1[i][j]*0.1
sleep b1[i][j]
end
end
end
a2=[]
b2=[]
a2[0]=[:E3,:D3,:E3,:E2,:r,:r,:E3,:G3,:B3,:G3,:E3,:B3,:A3,:B3,:B2,:r,:r,:B3,:Ef4,:Fs4,:Ef4,:B3,:E4,:G4,:E4,:C4,:A3,:C4,:D4,:Fs4,:D4,:B3,:G3,:B3,:C4,:B3,:A3,:C4,:G3,:C4,:Fs3,:C4,:E3,:C4,:D3,:C4,:B3,:C4,:A3,:C4,:G3,:C4,:Fs3,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0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.125,0.125,0.25,0.5,0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.125,0.125,0.25,0.5,0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.125,0.125,0.25,0.5,0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.125,0.125,0.25,0.5,0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.25,0.25,0.25,0.25,0.5,0.125,0.125,0.25,0.5,0.5,0.5,0.5,0.5,0.125,0.125,0.25,0.5,0.5,0.5,0.5,0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.5,0.5,0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.125,0.125,0.25,0.5,0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.125,0.125,0.25,0.5,0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.25,0.25,0.25,0.25,0.5,0.125,0.125,0.25,0.5,0.5,0.5,0.5,0.5,0.125,0.125,0.25,0.5,0.5,0.5,0.5,0.5,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.5,0.5,0.5,1.5]
c2=[80]
in_thread do
for i in 0..a2.length-1
use_bpm c2[i]
for j in 0..a2[i].length-1
osc "/waitforit", a2[i][j].to_s,b2[i][j],c2[i]
sleep b2[i][j]
end
end
end
#experimental program to receive and play notes from SP on another machine
#using parameters attached to an OSC sync command.
#amended version removing accommodation of chord sending
#as this involves un-safe use of eval with a string argument.
#instead, chords can be processed at the sending end
#as per the second example BachSend2.rb
use_synth :piano
with_fx :reverb,room: 0.6 do
live_loop :receive do
s=sync "/waitforit"
v=s[2]
use_bpm v
puts s[0] #received note data
#if s[0].length > 3 #more than one note to play together
#play eval(s[0]),sustain: s[1]*0.9,release: s[1]*0.1
#else
if s[0]!= "r"
play s[0],sustain: s[1]*0.9,release: s[1]*0.1
end
#end
end
end
import oscP5.*;
// This sketch runs on the receiving computer which will play the received notes
// Passing on OSC data to Sonic Pi
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myBroadcastLocation;
void setup() {
background(0);
frameRate(100);
size (1,1); // We don’t need to see anything.
oscP5 = new OscP5(this,8000); // The port tothe source Soninc which the source processing app sends
myBroadcastLocation = new NetAddress("127.0.0.1",4559); // The port on which Sonic Pi listens to incoming messages.
}
void draw() {
}
void oscEvent(OscMessage theOscMessage) { // When you receive a message…
//println(theOscMessage);
println(theOscMessage.arguments());
oscP5.send(theOscMessage, myBroadcastLocation); //send it to Sonic Pi on this machine.
}
// Passing on OSC data to Sonic Pi
//This sketch runs on the orginating computer sending the note information
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myBroadcastLocation;
void setup() {
background(0);
frameRate(60);
size (1,1); // We don’t need to see anything.
oscP5 = new OscP5(this,8000); // The port to which the soruce Sonic Pi on this machine is set to send
myBroadcastLocation = new NetAddress("192.168.1.33",8000); // The port/destination ip for the receiving mac processing sketch
}
void draw() {
}
void oscEvent(OscMessage theOscMessage) { // When you receive a message…
println(theOscMessage.arguments());
oscP5.send(theOscMessage, myBroadcastLocation); // …just send it to the destination
}
@emlyn
Copy link

emlyn commented Dec 16, 2016

This is going to be fun to play around with. I think the readme has a couple errors in the code snippets, the second should probably be:

osc "/waitforit","c4",1.5,60

and the third should be:

s=sync "/waitforit"
nvalue=s[0]
durationvalue=s[1]
tempovalue=s[2]

(i.e. the osc address should start with a forward slash, not backslash, and the receiving end should use sync, not osc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment