I'm looking to provide a UI for changing which OSC port my processing app will listen for data on. I've run through the paces of trying to figure this out and haven't been able to so far. I'm OK with the basics like controlP5 number boxes, change events, setting up OSC on a pre-defined port, receiving OSC, etc. I even figured out how to change the sending port after setup... so I'm a little stumped that I can't get the listening port to change. Is it possible to change the listening port after setup?
Ok, well. Look here is a stripped down version of the code. One app is sending random ints on three ports, and the other one is listening for osc messages on one port at a time, and I've added a number box to update the osc properties to the new port number, but it doesn't seem to work.
Here's the listener:
Quote:int OSC_RECEIVE_PORT = 8111;
import oscP5.*;
import netP5.*;
import controlP5.*;
ControlP5 controlP5;
OscP5 oscP5;
OscProperties properties = new OscProperties();
void setup() {
size(190,300);
frameRate(1);
controlP5 = new ControlP5(this);
// this is a control that sets the receiving port of the OSC object... or.. should anyway.
controlP5.addNumberbox("receiveport",OSC_RECEIVE_PORT,70,130,50,14);
controlP5.addButton("button",10,70,160,80,20).setId(1);
properties.setListeningPort(OSC_RECEIVE_PORT);
oscP5 = new OscP5(this,properties);
oscP5.plug(this,"from_8111","/from_8111");
oscP5.plug(this,"from_8113","/from_8113");
oscP5.plug(this,"from_8115","/from_8115");
}
void draw()
{
background(0);
}
void from_8111(int theInt)
{
println("from_8111: "+theInt);
}
void from_8113(int theInt)
{
println("from_8113: "+theInt);
}
void from_8115(int theInt)
{
println("from_8115: "+theInt);
}
void button(float theValue) {
println(properties.toString());
}
void receiveport(int thePortNumber)
{
properties.setListeningPort(thePortNumber);
}
and here's the sender:
Quote:import oscP5.*;
import netP5.*;
OscP5 oscP5_8111;
OscProperties properties_8111 = new OscProperties();
OscP5 oscP5_8113;
OscProperties properties_8113 = new OscProperties();
OscP5 oscP5_8115;
OscProperties properties_8115 = new OscProperties();
void setup() {
size(190,300);
frameRate(1);
properties_8111.setRemoteAddress("127.0.0.1",8111);
oscP5_8111 = new OscP5(this,properties_8111);
properties_8113.setRemoteAddress("127.0.0.1",8113);
oscP5_8113 = new OscP5(this,properties_8113);
properties_8115.setRemoteAddress("127.0.0.1",8115);
oscP5_8115 = new OscP5(this,properties_8115);
}
void draw()
{
background(0);
OscMessage myMessage_8111 = new OscMessage("/from_8111");
myMessage_8111.add(int(random(0,255)));
oscP5_8111.send(myMessage_8111);
OscMessage myMessage_8113 = new OscMessage("/from_8113");
myMessage_8113.add(int(random(0,255)));
oscP5_8113.send(myMessage_8113);
OscMessage myMessage_8115 = new OscMessage("/from_8115");
myMessage_8115.add(int(random(0,255)));
oscP5_8115.send(myMessage_8115);
}