/** * oscP5sendreceive by andreas schlegel * example shows how to send and receive osc messages. * oscP5 website at http://www.sojamo.de/oscP5 */ import oscP5.*; import netP5.*; import processing.serial.*; Serial myPort; // The serial port static int LF = 10; OscP5 oscP5; NetAddress myRemoteLocation; void setup() { size(400, 100); frameRate(25); /* start oscP5, listening for incoming messages at port 12000 */ oscP5 = new OscP5(this, 12000); /* myRemoteLocation is a NetAddress. a NetAddress takes 2 parameters, * an ip address and a port number. myRemoteLocation is used as parameter in * oscP5.send() when sending osc packets to another computer, device, * application. usage see below. for testing purposes the listening port * and the port of the remote location address are the same, hence you will * send messages back to this sketch. */ // serial init println(Serial.list()); // I know that the first port in the serial list on my mac // is always my Keyspan adapter, so I open Serial.list()[0]. // Open whatever port is the one you're using. myPort = new Serial(this, Serial.list()[0], 4800); // the port supercollider is listening on 57120 myRemoteLocation = new NetAddress("127.0.0.1", 57120 ); // myPort.write(ESC); // myPort.write(char(100)); // myPort.write("3"); // // myPort.write(ESC); // myPort.write("i"); //change to color 1 myPort.write(ESC); myPort.write(114); myPort.write(1); // color 1 } void draw() { background(0); } /* incoming osc message are forwarded to the oscEvent method. */ void oscEvent(OscMessage theOscMessage) { /* print the address pattern and the typetag of the received OscMessage */ // println("### received an osc message."); // println(" addrpattern: "+theOscMessage.addrPattern()); // println(" typetag: "+theOscMessage.typetag()); String addrpat = theOscMessage.addrPattern(); String strval = theOscMessage.get(0).stringValue(); //println(theOscMessage.toString()); //theOscMessage.print(); //theOscMessage.printData(); if (match(addrpat, "/printme")!=null) { println("PRINTING: "+strval); myPort.write(strval); //myPort.write(LF); } }