Created
November 25, 2016 07:45
-
-
Save Enkerli/a9c3f3d308c00c9ae74a4e1c19ec1ec3 to your computer and use it in GitHub Desktop.
Using TouchOSC to control Sonic Pi, with Processing as a bridge.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Passing on OSC data to Sonic Pi | |
| 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,12000); // The port to which TouchOSC or other OSC programs sends messages. | |
| 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… | |
| oscP5.send(theOscMessage, myBroadcastLocation); // …just send it to Sonic Pi. | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| set_sched_ahead_time! 0 # Setting that one to a negative value makes Sonic Pi complain, it sounds like. | |
| with_fx :bpf do |s| # Setting up the fx to be controlled internally | |
| synth :blade, note: 32,release: 400 # Long release as the control will affect a single note | |
| live_loop :ctl do # The loop is inside the fx as this is where the action will be. | |
| ctl=sync "/accxyz" # The OSC message which Processing relays from TouchOSC's three-axes accelerometer. Sent from -1 to 1, so we need to get absolute values. | |
| rz=ctl[:args][0] # Assigning the x axis to resonance. | |
| ct=ctl[:args][1] # Assigning the y axis to centre frequency. | |
| mp=ctl[:args][2] # Assigning the z axis to amplitude. | |
| control s, res: (rz/2).abs, centre: (ct*100).abs, amp: mp.abs # The actual control of the fx. | |
| set_sched_ahead_time! -2 | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment