OscMessage

description
An OSC message consists of an OSC Address Pattern, an OSC Type Tag String and the OSC arguments.
+Example
/**
 * oscP5sendreceive by andreas schlegel
 * example shows how to send and receive osc messages.
 * oscP5 website at https://www.sojamo.de/oscP5
 */
 
import oscP5.*;
import netP5.*;
  
OscP5 oscP5;
NetAddress myRemoteLocation;

void setup() {
  size(400,400);
  frameRate(25);
  /* start oscP5, listening for incoming messages at port 12000 */
  oscP5 = new OscP5(this,12000);
  
  /* myRemoteLocation is a NetAddress. a NetAddress takes 2 parameters,
   * an ip address and a port number. myRemoteLocation is used as parameter in
   * oscP5.send() when sending osc packets to another computer, device, 
   * application. usage see below. for testing purposes the listening port
   * and the port of the remote location address are the same, hence you will
   * send messages back to this sketch.
   */
  myRemoteLocation = new NetAddress("127.0.0.1",12000);
}


void draw() {
  background(0);  
}

void mousePressed() {
  /* in the following different ways of creating osc messages are shown by example */
  OscMessage myMessage = new OscMessage("/test");
  
  myMessage.add(123); /* add an int to the osc message */

  /* send the message */
  oscP5.send(myMessage, myRemoteLocation); 
}


/* incoming osc message are forwarded to the oscEvent method. */
void oscEvent(OscMessage theOscMessage) {
  /* print the address pattern and the typetag of the received OscMessage */
  print("### received an osc message.");
  print(" addrpattern: "+theOscMessage.addrPattern());
  println(" typetag: "+theOscMessage.typetag());
}
constructors
OscMessage(theAddrPattern);
OscMessage(theAddrInt);
OscMessage(theAddrPattern, theArguments);
parameters
theAddrPatternString 
theAddrIntint 
theArgumentsObject[] 
theAddrPatternint 
Methods
add ( )
add values to an osc message. please check the add documentation for specific information.
addrInt ( )
returns the address pattern of the osc message as int.
checkAddrPattern ( )
check if an address pattern equals a specific address pattern you are looking for. this is usually used when parsing an osc message. e.g. if(theOscMessage.checkAddrPattern("/test")==true) {...}
clear ( )
clear and reset an OscMessage for reuse.
get ( )
get a value at a specific position in the osc message. the get method returns an OscArgument from which the value can be parsed into the right format. e.g. to parse an int from the first argument in the osc message, use theOscMessage.get(0).intValue();
setAddrPattern ( )
set the address pattern of an osc message. you can set a string or an int as address pattern.tnt might be useful for supercollider users. oscP5 does support ints and strings as address patterns when sending and receiving messages.
setArguments ( )
set the arguments of the osc message using an object array.
tcpConnection ( )
when in TCP mode, tcpConnection() returns the instance of the TcpClient that has sent the OscMessage.
timetag ( )
get the timetag of an osc message. timetags are only sent by osc bundles.
typetag ( )
returns the typetag of the osc message. e.g. the message contains 3 floats then the typetag would be "fff"
usage
Web & Application
related