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);
}
}