Hello. This is my first post here.
I am trying to learn to use the oscP5 library, and I’m making a tester sketch based on one of the examples.
The attached code is supposed to send and receive osc messages, and help me build understanding of forming and parsing them by drawing a bigger dot on screen where I press the mouse button, sending those screen coordinates (in normalized float x, y, form) out on the osc server. When it receives the message, it draws a smaller dot at the same location. My plan was to start testing multiple concurrent sketches to find out for myself how osc messages can reach or not reach their intended goals when there are many sources and many receivers.
I got stumped because this sketch won’t draw the second smaller dot on a successfully received message. I know it succeeds because my console message appears correctly. I know the smalDot method works because I can invoke it from other places in the code and get the expected result.
I don’t know what is going on… and I am a pretty novice coder.
Can anyone point out my error?
Thanks
// osc send & receive tester
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;
void setup() {
size(400,400);
frameRate(25);
background(40);
noStroke();
oscP5 = new OscP5(this,12000);
myRemoteLocation = new NetAddress("127.0.0.1",12000);
}
void draw() {
}
void bigDot (float x, float y) {
fill(255,100);
ellipseMode(CENTER);
ellipse(x*width,y*height,50,50);
println("bigDot "+x+" "+y);
}
void smallDot (float x, float y) {
fill(255,100);
ellipseMode(CENTER);
ellipse(x*width,y*height,30,30);
println("smallDot "+x+" "+y);
}
void mousePressed() {
println("---");
OscMessage myMessage = new OscMessage("/test");
float x = float(mouseX)/width;
float y = float(mouseY)/height;
myMessage.add(x); /* add a float to the osc message */
myMessage.add(y); /* add a float to the osc message */
bigDot(x,y);
oscP5.send(myMessage, myRemoteLocation);
}
void oscEvent(OscMessage theOscMessage) {
if(theOscMessage.checkAddrPattern("/test")==true) {
if(theOscMessage.checkTypetag("ff")) {
float x = theOscMessage.get(0).floatValue();
float y = theOscMessage.get(1).floatValue();
smallDot(x,y);
return;
}
}
println("received unrecognized osc message");
}