 |
Author |
Topic: trigger P5 from patching? (Read 2133 times) |
|
nay
|
trigger P5 from patching?
« on: Feb 7th, 2004, 2:32am » |
|
Hi all - i'm new to P5 and loving it i am wondering if there is a way to have a patching environment such as max/pd/jmax trigger events in P5. maybe via midi, osc or something else. preferably something internal but if it has to be over a network that's cool too. i searched the forums on midi but was a little overwhelmed as i don't know java yet. eventually i will try to code an osc input based on the kits at the proctologic site: http://galatea.stetson.edu/~ProctoLogic/ but i won't have time to do this in time for a show soon for which i'm hoping to make my first P5 work - audio triggering a max patch and then sending ints from there to P5 to control animation. does any one have any sample code to do something like this that i can look at? any help or advice would be greatly appreciated
|
|
|
|
pyson
|
Re: trigger P5 from patching?
« Reply #1 on: Feb 7th, 2004, 7:25pm » |
|
hi, i was able to do the reverse that is have p55 communicate with SuperCollider using Open Source Control (OSC). i'm putting down my thoughts as i believe that with some extra work you can get p55 to talk to max/msp. I used an open source piece of software called flosc which was written in java http://www.benchun.net/flosc/. This software acts as a gateway between 2 applications that want to send to each other OSC packets. It was originally developed to enable Flash to communicate with other applications using OSC. Still it is applicable to p55. if you follow the forum http://www.randominterface.com/forum/ you can find topics on how people were able to put it to work with max/msp. i include the code with some explanations. this code is very specific to what i wanted to do but i hope it will help you or help others give you more clear advice. BTW the result of this code is to send SuperCollider a message that plays a sawtooth oscillator in various frequencies which are calculated by p55. Code: // Talks to SC3 through Gateway // You will need to have SC3 & Gateway running, especially Gateway listening on port 3000 // use run gateway with the following command line // java Gateway oscPort tcpPort // in my case it was java Gateway 1250 3000 /* In the code i'm referencing a class called XMLElement. This is a class from the NanoXml project http://web.wanadoo.be/cyberelf/nanoxml/ XML is required in order to talk to Flosc's Gateway. This class and the other required class XMLElementException need to located in the code folder of p55 project. Whenever you want to reference Java code that is not included in p55 then you need to create a code folder in your sketch and place the code there. The other thing i did is to use the Socket class to do the network communication. p55 comes equipped with methods for networking (beginNet, writeNet etc) but they proved unreliable in my case. The Socket class though is included in the standard Java libraries so we don't have to place it in the code folder. There is no need for special OSC code in p55. Flash & p55 don't need to know much about OSC they just sent/receive data from Gateway. That should be the next step, to integrate the OSC code in the p55 and eliminate the need for Flosc. Even though i feel that using a gateway is probably better as it allows many to many communication (e.g. flash and java at the same time communicating with sc3 and max/msp) */ int baseFreq = 0; int y = 100; int time = 0; int freq = 300; XMLElement oscPacketXML, messageXML, argumentXML; // this xmlString is very specific to my SC3 pactch // you will need to define your own based on what kind of values you want max/msp to receive String xmlString = "<OSCPACKET ADDRESS=\"127.0.0.1\" PORT=\"57120\" TIME=\"0\"><MESSAGE NAME=\"flash\"><ARGUMENT TYPE=\"s\" VALUE=\"431\" /></MESSAGE></OSCPACKET>"; String ipAddress = "127.0.0.1"; // this is the localhost int port = 3000; // this is the port that the gateway is listening for incoming tcp messages Socket s; // we need to create a socket so that we can send tcp messages PrintWriter out; // we do this using a PrintWriter instance void setup() { size(200, 200); stroke(255); framerate(30); // Starts the socket, if things are incorrectly setup p55 might get stack here so save your work ! startNet(); // XML variables oscPacketXML = new XMLElement(); oscPacketXML.parseString(xmlString); messageXML = (XMLElement)oscPacketXML.getChildren().elementAt(0); argumentXML = (XMLElement)messageXML.getChildren().elementAt(0); } void loop() { background(51); y -= 1; if (y < 0) { y = height; } line(0, y, width, y); oscPacketXML.addProperty("time", time++); // Update the time attribute, this an SC3 specific attribute argumentXML.addProperty("value", y+baseFreq); // Update the value attribute with the calculated frequency, this an SC3 specific attribute try { // send this to gateway appending a null character, without the null gateway doesn't work // the null defines the end character of a message out.print(oscPacketXML.toString() + '\0'); out.flush(); } catch (Exception e) { println("IO EXCEPTION Err "+e); } } void keyPressed() { // Allow the user to change the base frequency using + - keys if (key == '+' || key == '=') { baseFreq += 5; } else if (key == '-') { baseFreq -= 5; } } // Using Socket as beginNet&writeNet are quite buggy void startNet() { try{ s = new Socket(ipAddress,port); // create a socket & connect to the ip:port out = new PrintWriter(s.getOutputStream()); // get a reference to the output stream print ("Socket listening to ip:"+ipAddress+", port:"+port); } catch(IOException e){ println("IO EXCEPTION Err "+e); } } |
|
|
|
|
|
REAS
|
Re: trigger P5 from patching?
« Reply #2 on: Feb 7th, 2004, 9:32pm » |
|
It is possible to communicate between Processing and MAX via a serial connection. I don't know the details of the implementation, but I know it's not too difficult. Has anyone done this yet? Pyson, this is an extremely helpful post! Thank you! FYI. David Muth, a developer in London has agreed to integrated OSC into Processing. We still working on the details of how libraries will be written, but I'm looking forward to having this functionality.
|
« Last Edit: Feb 7th, 2004, 9:38pm by REAS » |
|
|
|
|
nay
|
Re: trigger P5 from patching?
« Reply #3 on: Feb 8th, 2004, 7:02am » |
|
thanks for the feedback very helpful but i don't think i have time to get my head around it for this project. will sit tight and wait for osc if someone's already on the case, do plan on looking into serial eventually - contemplating getting into pic programming but willl see what other people are doing here first. think i might just use the same audio feed to control max and p55 to sync them up for this work. still interested in any other ideas though. btw, in terms of stability (even though this is a case by case question) would p55 run ok for 2 weeks straight? anyone have a record on how long they've had a processing applet running? realise it's a lot to ask from an alpha app. cheers.
|
|
|
|
REAS
|
Re: trigger P5 from patching?
« Reply #4 on: Feb 9th, 2004, 4:36am » |
|
Processing is as stabile as Java. We've run applications for this long without a problem. The main reason the software is alpha is due to the fact it's not feature complete and there are many platform / configuration specific bugs.
|
« Last Edit: Apr 2nd, 2004, 12:50pm by REAS » |
|
|
|
|
mKoser

|
Re: trigger P5 from patching?
« Reply #5 on: Feb 9th, 2004, 1:17pm » |
|
regarding stability: in january i had an exhibition piece running for a week. it was a processing-piece which was showing fullscreen video (640*480) and on the side of this, controlling via serial-communication a video-switch (switching between 7 cctv cameras)... so, i can confirm that for something as heavy as doing a long period of video + serial, processing performed really well ...oh, and this was even running on a Mac (wow!)
|
« Last Edit: Feb 9th, 2004, 1:18pm by mKoser » |
|
mikkel crone koser | www.beyondthree.com | http://processing.beyondthree.com
|
|
|
pyson
|
Re: trigger P5 from patching?
« Reply #6 on: Feb 10th, 2004, 7:21pm » |
|
hi, i've updated the code so that if people are interested can use it as a starting point to have bi-directional communication between p55 and some osc-enabled application (SuperCollider in my case). that small example was my first attempt to use p55 so it lacks imagination BTW david was my flatmate a year ago, what a small world Code: // Talks to SC3 through Gateway // You will need to have SC3 & Gateway running, especially Gateway listening on port 3000 // use run gateway with the following command line // java Gateway oscPort tcpPort // in my case it was java Gateway 1250 3000 /* In the code i'm referencing a class called XMLElement. This is a class from the NanoXml project http://web.wanadoo.be/cyberelf/nanoxml/ XML is required in order to talk to Flosc's Gateway. This class and the other required class XMLElementException are located in the code folder of p55 project. Whenever you want to reference Java code that is not included in p55 then you need to place it in the code folder. The other thing i did is to use the Socket class to do the network communication. p55 comes equipped with methods for networking (beginNet, writeNet etc) but are very buggy. The Socket class though is included in the standard Java libraries so we don't have to place it in the code folder. There is no need for special OSC code in p55. Flash & p55 don't need to know much about OSC they just sent/receive data from Gateway. That should be the next step, to integrate the OSC code in the p55 and eliminate the need for Flosc. Even though i feel that using a gateway is probably better as it allows many to many communication (e.g. flash and java at the same time communicating with sc3 and max/msp) */ int baseFreq = 0; int y = 100; int time = 0; int freq = 300; int y1,y2,cnt; XMLElement oscPacketXML, messageXML, argumentXML; // this xmlString is very specific to my SC3 pactch // you will need to define your own based on what kind of values you want max/msp to receive String xmlString = "<OSCPACKET ADDRESS=\"127.0.0.1\" PORT=\"57120\" TIME=\"0\"><MESSAGE NAME=\"flash\"><ARGUMENT TYPE=\"s\" VALUE=\"431\" /></MESSAGE></OSCPACKET>"; String ipAddress = "127.0.0.1"; // this is the localhost int port = 3000; // this is the port that the gateway is listening for incoming tcp messages Socket s; // we need to create a socket so that we can send tcp messages PrintWriter out; // we do this using a PrintWriter instance BufferedReader rd; // rd is used to read data from the socket void setup() { size(200, 200); stroke(255); framerate(30); // Starts the socket, if things are incorrectly setup p55 might get stack here so save your work ! startNet(); // XML variables oscPacketXML = new XMLElement(); oscPacketXML.parseString(xmlString); messageXML = (XMLElement)oscPacketXML.getChildren().elementAt(0); argumentXML = (XMLElement)messageXML.getChildren().elementAt(0); } void loop() { background(51); sendOscPacket(); // this does p55 -> SC3 communication //getTcpMessage(); // this does SC3 -> p55 communication } void getTcpMessage() { try { // need to obtain a new reference to the input stream, else the xml parser fails to read the xml data properly rd = new BufferedReader(new InputStreamReader(s.getInputStream())); if (rd.ready()) { // are there any available data? XMLElement oscPacketXML = new XMLElement(); oscPacketXML.parseFromReader(rd); // this line halts the execution until new data have arrived through the socket XMLElement messageXML = (XMLElement)oscPacketXML.getChildren().elementAt(0); XMLElement argumentXML = (XMLElement)messageXML.getChildren().elementAt(0); String s = (String)argumentXML.getAttribute ("value", "100"); // default value is 100 y = Integer.parseInt(s); } line(0, y-300, width, y-300); // } catch (Exception e) { println("IO EXCEPTION Err "+e); } } void sendOscPacket () { y -= 1; if (y < 0) { y = height; } line(0, y, width, y); oscPacketXML.addProperty("time", time++); // Update the time attribute, this an SC3 specific attribute argumentXML.addProperty("value", y+baseFreq); // Update the value attribute with the calculated frequency, this an SC3 specific attribute try { // send this to gateway appending a null character, without the null gateway doesn't work // the null defines the end character of a message out.print(oscPacketXML.toString() + '\0'); out.flush(); } catch (Exception e) { println("IO EXCEPTION Err "+e); } } void keyPressed() { // Allow the user to change the base frequency using + - keys if (key == '+' || key == '=') { baseFreq += 5; } else if (key == '-') { baseFreq -= 5; } } // Using Socket as beginNet&writeNet are quite buggy void startNet() { try { s = new Socket(ipAddress,port); // create a socket & connect to the ip:port out = new PrintWriter(s.getOutputStream()); // get a reference to the output stream print ("Socket listening to ip:"+ipAddress+", port:"+port); } catch (Exception e) { e.printStackTrace(); } } |
|
|
|
|
|
|