We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › help oscP5 / netP5: change ports after setup()
Page Index Toggle Pages: 1
help? oscP5 / netP5: change ports after setup() (Read 1685 times)
help? oscP5 / netP5: change ports after setup()
Jan 11th, 2010, 8:50pm
 
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);
}




Re: help? oscP5 / netP5: change ports after setup()
Reply #1 - Jan 19th, 2010, 7:30am
 
Hi,

setListeningPort() is part of the osc properties, and it seems, that it only can be changed before initializing an oscP5 object.

Quote:
osc properties are used to start oscP5 with more specific settings. osc properties have to be passed to oscP5 in the constructor when starting a new instance of oscP5.

http://www.sojamo.de/libraries/oscP5/reference/oscproperties_class_oscproperties.htm

if i got this correctly, this means that you allways have to create a new object, when wanting to listen to a new port.
That e.g. would look like this:

Code:
void mousePressed(){
oscP5 = new OscP5(this,8113);
}


so you could make an array of objects and allways kill the ones you don't want to listen to anymore.

cheers
Page Index Toggle Pages: 1