Skip to content

Instantly share code, notes, and snippets.

@AlexandreRangel
Last active April 8, 2019 10:40
Show Gist options
  • Save AlexandreRangel/e82072203fcf4b89f12003b1f1a957fa to your computer and use it in GitHub Desktop.
Save AlexandreRangel/e82072203fcf4b89f12003b1f1a957fa to your computer and use it in GitHub Desktop.
Controling Sonic Pi from Processing OSC
# reading OSC from Processing, Alexandre Enkerli
# full screen, fulltime mouse, Alexandre Rangel
# 24-Nov-2016
# Sonic Pi 2.11
use_bpm 120
set_sched_ahead_time! 0 # Setting that one to a negative value makes Sonic Pi complain, it sounds like.
live_loop :osc do # The loop is inside the fx as this is where the action will be.
osc=sync "/osc" # The OSC message which Processing sends, based on mouse coordinates.
mousex=osc[:args][0] # Assigning the first argument to resonance.
mousey=osc[:args][1] # Assigning the second argument to centre.
use_synth :piano
myscale = scale_names[(73 * mousey).to_int] # mouse y sets scale
mynote = 24 + (48 * mousex) # mouse x sets scale root note
play scale(mynote,myscale,num_ontaves: 5).tick
sleep 0.25
end
// sending OSC from Processing to Sonic Pi, Alexandre Enkerli
// full screen, fulltime mouse, Alexandre Rangel
// 24-Nov-2016
// Processing 3.2.3
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import oscP5.*;
import netP5.*;
Point mouse;
OscP5 oscP5;
NetAddress myBroadcastLocation;
float mousex, mousey;
void setup() {
background(0,255,0);
frameRate(60);
size (160,140);
mouse = MouseInfo.getPointerInfo().getLocation();
oscP5 = new OscP5(this,12000);
myBroadcastLocation = new NetAddress("127.0.0.1",4559);
}
void draw() {
mouse = MouseInfo.getPointerInfo().getLocation();
mousex = float(mouse.x) / float(displayWidth); // normalizes mouse to 0.0-1.0
mousey = float(mouse.y) / float(displayHeight); // normalizes mouse to 0.0-1.0
OscMessage myOscMessage = new OscMessage("/osc"); // Preparing the OSC message to be sent to the right address, the one Sonic Pi expects.
myOscMessage.add(mousex); // Adding those floats to the OSC message…
myOscMessage.add(mousey);
//println(mouse.x, mouse.y); // To check on those values…
//println(mousex, mousey); // To check on those values…
oscP5.send(myOscMessage, myBroadcastLocation); // Broadcast
}
@mikkoelo
Copy link

mikkoelo commented Feb 5, 2018

Hi! I think on latest Sonic Pi 3, you have to add one /osc -path to the messages in Sonic Pi to make it work. It also didn't work on my computer with the :args- commands so I left them out.

So the first three lines in Sonic Pi should maybe be:

osc=sync "/osc/osc" #One more "/osc" added!
mousex=osc[0]
mousey=osc[1]

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