Openframeworks and Supercollider via osc

These last days I”ve been learning a little bit of Supercollider, which as you may know, is a software-language for synthesize sound in real time.
I may use Supercollider instead of Puredata for dealing with the installation”s sound, so these last two days I”ve been learning how to load sound files in supercollider and how to make them play from Openframeworks using OSC.

Thanks to Mark Nguyen (check his sound particles) who gave me some important help, information and good code ;), and thanks to the tutorial that Thor Magnusson (from ixi-software) made, I could end up making a basic program that communicates Openframeworks and Supercollider using OSC.

This is a video running the code:

Here is Supercollider code:

// read file into buffers
b =, "sounds/bomb.wav");
c =, "sounds/bomb3.wav");

// OSC
NetAddr.localAddr; // retrieve the current IP and port
NetAddr.langPort; // retrieve the current IP and port

// Play buffer
SynthDef(playBuf,{ arg out = 0, bufnum;
var signal;
// It is very important the 3th argument (doneAction:2) of playBuf,
// it will free the Synth. If we don"t use it we will saturate sc, becuase
// we are creating a new synth each time the ball bounce.
signal =, bufnum,, doneAction:2);, signal ! 2)

// Receive OSC and play the sound
o =, "/collision", { |time, resp, msg|
if(msg[1] == "true" && msg[2] == 0){
x = Synth(playBuf, [ufnum, b.bufnum]); // we pass in the number of the buffer
if(msg[1] == "true" && msg[2] == 1){
x = Synth(playBuf, [ufnum, c.bufnum]); // we pass in the number of the buffer

// Clean
o.remove; // remove the OSCresponder when you are done.; // free the buffer; // free the buffer

And here is Openframeworks code: