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.
Page Index Toggle Pages: 1
OscPlug? (Read 1447 times)
OscPlug?
Jun 18th, 2009, 1:16pm
 
Hallo,

Is OscPlug useful to tell Processing that a received osc msg will switch another osc msg to be sent?
Is it also possible to this msg by msg?
Re: OscPlug?
Reply #1 - Jun 18th, 2009, 10:01pm
 
the intention of osc plug is to provide a mechanism which automatically directs an incoming osc message with a specific address pattern and typetag to its dedicated function inside your processing sketch. in order to get this to work you need to let oscP5 know which address pattern links with which function. more details can be found in the oscP5plug example. by default oscP5 doesnt know about any functions inside your sketch - oscP5 does a check for function oscEvent though. oscEvent is used to forward any incoming osc message to your sketch. there, you can check the address pattern, typetag, etc. of each incoming message and make decisions.

oscP5 does not automatically check if an address pattern of an osc message matches a function in your sketch. this has to be done by instruction, e.g. using oscP5.plug(). osc plug is useful if you are waiting for a particular osc message - in your case to fire another osc message. e.g.
osc message, contains 1 int:
/ping 123

plug:
Code:

// 1. parameter = sketch
// 2. parameter = function name
// 3. parameter  = address pattern of osc message
oscP5.plug(this,"ping","/ping");


sketch function:
Code:
 
// oscP5 has plugged the /ping address pattern to function ping
// therefore any osc message with address pattern /ping
// and typetag i will be directed to this function
void ping(int theValue) {
OscMessage o = new OscMessage("/pong");
oscP5.send(o);
}


or, whenever message /ping with typetag i (1 int) reaches your sketch, function ping(int) will be called and oscmessage /pong will be sent.
instead of using osc plug, you can parse an osc message in oscEvent
Code:

void oscEvent(OscMessage theMessage) {
if(theMessage.addrPattern().equals("/ping") && theMessage.typetag().equals("i")) {
OscMessage o = new OscMessage("/pong");
oscP5.send(o);
}
}
Re: OscPlug?
Reply #2 - Jun 20th, 2009, 6:26am
 
@sojamo


thahnks!

your repliexs are always very useful, I followed your instructions and almost there.... this is the final part of the sketch:

void oscEvent(OscMessage theOscMessage) {
   
   println("received a message.");
   if(theOscMessage.addrPattern().equals("/test") && theOscMessage.typetag().equals("iii") ) {            
   OscMessage o = new OscMessage("/pang");            
 oscP5.send(o, myRemoteAddress);      
}


so everything works so far, when /test message with three ints reaches the incoming port, a /pang message is sent to myRemoteAddress. this is what I wanted to achieve.
The only thing that i'm missing is to specify the values of the three ints. so assuming that the message that I need in order to fire /pang is:

/test  int=1 , int=2, int=3

I tried to substitute the ("iii") with (123) and also (1,2,3) but it didn't work. so the question is, how can I specify the incoming int  values to fire /pang message, so I can be even more specific?

thanks
Re: OscPlug?
Reply #3 - Jun 30th, 2009, 3:34am
 
hi, details how to parse an osc message can be found in the oscP5 parsing example. in your case the following should work.

Code:

void oscEvent(OscMessage theOscMessage) {
 
  if(theOscMessage.addrPattern().equals("/test") && theOscMessage.typetag().equals("iii") ) {  
   // extract the 3 ints from the incoming message
   int a = theOscMessage.get(0).intValue();  
   int b = theOscMessage.get(1).intValue();  
   int c = theOscMessage.get(2).intValue();  
   if(a==1 && b==2 && c==3) {
     OscMessage o = new OscMessage("/pang");            
     oscP5.send(o, myRemoteAddress);  
   }
}


best,
andreas

Page Index Toggle Pages: 1