/* oscP5 by andreas schlegel if you have questions, feel free to contact andi at sojamo dot de this was downloaded from http://www.sojamo.de/iv/index.php?n=11 version 0.1.1 */ /* create the necessary objects and instances for the osc communication */ oscSend osObj; oscReceive orObj; MessageOUT msg; /* sending a message: go through function simpleMessage() and advancedMessage() receiving and analysing an incoming message: go through function analyseMessage() */ void setup(){ background(0); size(400, 400); noStroke(); framerate(30); /* initialize a new osc server/client consisting of an osc receiver and and osc sender. receiveAtPort is the port number osc message should b send to at which this application will receive messages. the sendToPort nummer indicates the port number of the receiving port number of the other client/server. */ int receiveAtPort = 50000; // this would be the port processing is waiting for incoming messages. int sendToPort = 6000; // the port number of the client you want to send a message to. String host = "127.0.0.1"; // the client's ip orObj = new oscReceive(receiveAtPort); osObj = new oscSend(host,sendToPort); } void loop(){ orObj.checkOSC(); } void mousePressed() { simpleMessage(); //advancedMessage(); } ////////////////////////////////////////////////////////// // SENDING MESSAGES ////////////////////////////////////////////////////////// // notes // sc3 doesnt accept arrays and booleans // max didnt accept arrays (tested with OSC-for-Max-v2.4 on mac os 9) ////////////////////////////////////////////////////////// void simpleMessage() { // message /test with 2 arguments. a float and an int. // structure of this message: fisT // supercolloder 3 uses 1 and 0 instead of TRUE and FALSE // REAKTOR doesnt take strings msg = osObj.newMsg("/beat"); // create and prepare the new osc message msg.add(12.44); // add a float to the osc message msg.add(401); // add an int to the osc message //msg.add("some string"); // add a string to the osc message //msg.add(true); // add a boolean to the osc message osObj.sendMsg(msg); // send the osc message } void advancedMessage() { // note: this message was successfully sent to supercollider 2 // when sending this message to dumpOsc, dumpOsc reports // [Unrecognized type tag [] // so the advanced message is yet an experimental state. // structure of this message: fF[if[s]s]Ti[iii] msg = osObj.newMsg("/test"); // create and prepare the new osc message msg.add(4); // add a float msg.add(false); // add a boolean // create a 2 dimensional vector Vector v = new Vector(); // create vector v Vector vv = new Vector(); // create vector vv vv.addElement(new String("a second vector")); // add a value to vector vv v.addElement(new Integer(1)); // add an Integer to the vector v v.addElement(new Float(2.23)); // add a Float to the vector v v.addElement(vv); // add the second vector to the vector v v.addElement(new String("some String")); // add a String to the vector v msg.add(v); // add vector v to the osc message msg.add(true); // add a boolean to the osc message msg.add(12); // add an int to the osc message int[] numbers = { 90, 150, 30 }; // create an int array and initialize it with some values msg.add(numbers); // add int array numbers to the osc message osObj.sendMsg(msg); // send the osc message } ////////////////////////////////////////////////////////// // ANALYSING RECEIVED MESSAGES ////////////////////////////////////////////////////////// void analyseMessage(MessageINcontainer mic) { if(mic.checkAddrPattern("/barre")) { System.out.println("this is a test message"); if(mic.checkTypes("fiii")) { System.out.println("the types of the data structure match fiii"); // getting the second value of the received data. // this will be done more elegant in the future. // (***) Vector v = mic.getOscData(); int a = ((Number) v.elementAt(1)).intValue(); fill(0, a, 0); // fill the canvas with the received int value a } } else { fill(255, 0, 0); } System.out.println("IN --- "+mic.getAddrPattern()+" "+mic.getOscStructure()+" "+mic.getOscData()); rect(0, 0,width,height); /* a messageINcontainer objects contains the information of an osc packet. there are three elements. (1) the addressPattern, containing the name of the message in form of a Stirng. (2) the data structure. an Array of characters representing the sequence and type of the incoming data. [i,f,s] => a message with 3 values. an Integer (i), a Float (f), and a String (s). (3) the oscData itself. with the command mic.getOscData() a vector containing the data is returned. you will have to know which element of the vector is of which type. see above (***) mic.getAddrPattern() // returns the address pattern of the message // returns a string. see above (1) mic.checkAddrPattern(String) // checks an address pattern of a received osc message // returns true or false mic.checkTypes(String) // checks the sequence and types of message arguments // returns true or false // mic.checkTypes("fiii") would look if the message contains 4 arguments, // the first argument being of type float, arguments 2-4 being integers mic.getOscStructure() // returns the structure of the message's arguments. // returns a string. a message with 2 arguments, the first being a float and the second a string // would return "fs" . see above (2) mic.getOscData() // returns a vector containing the values of the message's arguments. // see above (3) */ } ////////////////////////////////////////////////////////// // classes for osc communication. // must be in here, as i dont have access to the BApplet itself. // successfully tested (browser and processing) // win xp java 1.4.2 // win 98 java 1.3.1 // max os x 10.3 java 1.4.2 // mac os x 10.2.8 java 1.4.1 // the code in oscP5.jar was adapted from the flosc source // code written by ben chun | http://www.benchun.net/flosc/ ////////////////////////////////////////////////////////// class oscReceive extends BApplet { int port; OscReceiver or; oscReceive(int port) { this.port = port; this.or = new OscReceiver(this,port); this.or.start(); } void checkOSC() { if(this.or.checkNet()==true) for(int i=0;i