Created
July 27, 2014 17:56
-
-
Save colormono/98fc076677a46ee490c0 to your computer and use it in GitHub Desktop.
OSC Listen and Send
This file contains 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
/* | |
This sketch demonstrates the use of OSC in Resolume Avenue 3 and TouchOSC | |
an application made for the iPhone that can send OSC messages. | |
So install TouchOSC on your Iphone or Ipod touch (available in the App store) | |
*/ | |
// start OSC config | |
import oscP5.*; | |
import netP5.*; | |
/*portToListenTo, port we are listening on, this should be the same as | |
the outgoing port of TouchOsc on your iphone | |
*/ | |
int portToListenTo = 8000; | |
/*portToSendTo, port we are sending to, this should be the same as | |
the incomning port of Resolume 3, default it is set to 7000, so you wouldn't need to change it. | |
*/ | |
int portToSendTo = 9000; | |
/*ipAddressToSendTo, ip address of the computer we are sending messages to (where Resolume 3 runs) | |
*/ | |
String ipAddressToSendTo = "localhost"; | |
OscP5 oscP5; | |
NetAddress myRemoteLocation; | |
OscBundle myBundle; | |
OscMessage myMessage; | |
//end OSC config | |
boolean newMessages = false; | |
void setup() { | |
size(40,30); | |
frameRate(25); | |
/* start oscP5*/ | |
oscP5 = new OscP5(this,portToListenTo); | |
myRemoteLocation = new NetAddress(ipAddressToSendTo, portToSendTo); | |
myBundle = new OscBundle(); | |
myMessage = new OscMessage("/"); | |
} | |
void draw() { | |
background(0); | |
if (newMessages) { | |
/* send the message */ | |
oscP5.send(myBundle, myRemoteLocation); | |
myBundle.clear(); | |
newMessages = false; | |
} | |
} | |
/* incoming osc message are forwarded to the oscEvent method. */ | |
void oscEvent(OscMessage theOscMessage) { | |
//translate touchOSC messages | |
//touchOSC is set to the beatmachine template | |
String address = theOscMessage.addrPattern(); | |
int num = int( address.substring(address.length()-1) ); //get trailing number | |
int page = int( address.substring(1,2) ); //get page number | |
print('\n'+address); | |
if (page != 4) { | |
String newAddress = ""; | |
address = address.substring(0, address.length()-1); //remove trailing number so we get /1/push instead of /1/push1 | |
//page 1 | |
//translate the two faders to the volume and fadeout of the composition | |
if( address.equals("/1/fader") ) { // | |
if (num == 1) { | |
newAddress = "/composition/video/fadeout/values"; | |
} else { | |
newAddress = "/composition/audio/volume/values"; | |
} | |
//translate 9 button grid to clip triggers | |
} else if( address.equals("/1/push") ) { // | |
if ( num < 10) { | |
int layer = 1; | |
int clip = 1; | |
if (num <= 3) { | |
clip = num; | |
layer = 1; | |
} else if (num <= 6) { | |
clip = num - 3; | |
layer = 2; | |
} else if (num <= 9) { | |
clip = num-6; | |
layer = 3; | |
} | |
newAddress = "/layer" + layer + "/clip" + clip + "/connect"; | |
} else { | |
newAddress = "/layer" + (num - 9) + "/clear"; | |
} | |
//page 3 | |
//translate rotary controls to composition dashboard (links) | |
} else if( address.equals("/3/rotary") ) { | |
newAddress = "/composition/link" + num + "/values"; | |
} | |
theOscMessage.setAddrPattern( newAddress ); | |
myBundle.add(theOscMessage); | |
newMessages = true; | |
} else { | |
//page 4 | |
if( address.equals("/4/xy") ) { // | |
myMessage.clear(); | |
myMessage.setAddrPattern("/composition/video/rotatey/values"); | |
myMessage.add( 1.0 - theOscMessage.get(0).floatValue() ); | |
myBundle.add(myMessage); | |
myMessage.clear(); | |
myMessage.setAddrPattern("/composition/video/rotatex/values"); | |
myMessage.add( theOscMessage.get(1).floatValue() ); | |
myBundle.add(myMessage); | |
newMessages = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment