We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello processing world! (this is my first post here)
I have a problem with the OSC reciever of oscP5 library. I can see the messges I'm receiving from SuperCollider. I can set variables in processig. Also I can send back the recieved messages. But unfortunetly I can not draw anything with that messages. I tried 4 different methods and still nothing. Please some help!
Thanks a lot..!
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;
NetAddress superCollider;
void setup() {
size(700, 500);
background(0);
oscP5 = new OscP5(this, 12000);
myRemoteLocation = new NetAddress("127.0.0.2", 12000);
superCollider = new NetAddress("192.168.1.4", 57120);
oscP5.plug(this, "test3", "/test3");
}
void draw() {
}
void mousePressed() {
fill(250);
rect(random(0, width), random(0, height), random(50, 200), random(50, 200));
}
void oscEvent(OscMessage theOscMessage) {
/* check if theOscMessage has the address pattern we are looking for. */
if (theOscMessage.checkAddrPattern("/test")==true) {
/* check if the typetag is the right one. */
if (theOscMessage.checkTypetag("ii")) {
/* parse theOscMessage and extract the values from the osc message arguments. */
int val01 = theOscMessage.get(0).intValue(); // get the first osc argument
int val02 = theOscMessage.get(1).intValue(); // get the second osc argument
fill(250);
rect(random(0, width), random(0, height), random(50, 200), random(50, 200));
OscMessage myMessage = new OscMessage("/testBack");
myMessage.add(val01); /* add an int to the osc message */
myMessage.add(val02);
oscP5.send(myMessage, superCollider);
}
}
/* check if theOscMessage has the address pattern we are looking for. */
String addr = theOscMessage.addrPattern();
int val0 = theOscMessage.get(0).intValue();
if (addr.equals("/test2")) {
fill(250);
rect(random(0, width), random(0, height), random(50, 200), random(50, 200));
}
if (theOscMessage.checkAddrPattern("/test4")==true) {
/* parse theOscMessage and extract the values from the osc message arguments. */
int val01 = theOscMessage.get(0).intValue(); // get the first osc argument
int val02 = theOscMessage.get(1).intValue(); // get the second osc argument
fill(150);
ellipse(20, 20, 50, 50);
OscMessage myMessage = new OscMessage("/testBack4");
myMessage.add(val01); /* add an int to the osc message */
myMessage.add(val02);
oscP5.send(myMessage, superCollider);
}
}
public void test3(int theA, int theB) {
println("### plug event method. received a message /test3.");
println(" 2 ints received: " +theA+ ", " +theB);
fill(250);
rect(random(0, width), random(0, height), random(50, 200), random(50, 200));
}
Answers
Format your code. Edit your post, select your code and hit ctrl+o. Ensure there is an empty line above and below your code.
Kf
Sorry, first try. Thanks
Do not issue drawing commands outside the "Animation Thread"! [-X
Place them in draw() or some other function called from draw(). :-B
@GoToLoop okay. can you tell me please if I have to place all the reciever in draw() or only the the rect() for example and trigger it in some way from the recieved message?
Here is an example of how to use data from an OSC event. just click and move the mouse around.
Kf
@kfrajer Hey.. thank you very much!