oscP5
Class OscMessage

java.lang.Object
  extended by oscP5.OscPatcher
      extended by oscP5.OscPacket
          extended by oscP5.OscMessage
Direct Known Subclasses:
OscIn

public class OscMessage
extends OscPacket

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 http://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());
}

Constructor Summary
OscMessage(int theAddrInt)
           
OscMessage(int theAddrPattern, Object[] theArguments)
           
OscMessage(OscMessage theOscMessage)
           
OscMessage(String theAddrPattern)
           
OscMessage(String theAddrPattern, Object[] theArguments)
           
 
Method Summary
 OscMessage add()
          add values to an osc message.
 OscMessage add(boolean theValue)
           
 OscMessage add(Boolean theValue)
           
 OscMessage add(byte[] theArray)
           
 OscMessage add(char theValue)
           
 OscMessage add(char[] theArray)
           
 OscMessage add(Character theValue)
           
 OscMessage add(double theValue)
           
 OscMessage add(Double theValue)
           
 OscMessage add(float theValue)
           
 OscMessage add(Float theValue)
           
 OscMessage add(float[] theArray)
           
 OscMessage add(int theValue)
           
 OscMessage add(int[] theArray)
           
 OscMessage add(Integer theValue)
           
 OscMessage add(int channel, int status, int value1, int value2)
           
 OscMessage add(Object[] theArray)
           
 OscMessage add(String theValue)
           
 OscMessage add(String[] theArray)
           
 OscMessage addArguments(Object[] theArguments)
          add a list of arguments to an exisiting set of arguments.
 int addrInt()
          returns the address pattern of the osc message as int.
 String addrPattern()
           
 Object[] arguments()
           
 boolean checkAddrPattern(String theAddrPattern)
          check if an address pattern equals a specific address pattern you are looking for.
 boolean checkTypetag(String theTypeTag)
           
 void clear()
          clear and reset an OscMessage for reuse.
 void clearArguments()
          clears the arguments in a message, but keeps the address the address pattern.
 OscArgument get(int theIndex)
          get a value at a specific position in the osc message.
 byte[] getAddrPatternAsBytes()
           
 byte[] getBytes()
           
 byte[] getTypetagAsBytes()
           
 boolean isPlugged()
           
static byte[] makeBlob(byte[] b)
           
 void print()
           
 void printData()
           
 void set(int theIndex, Object theObject)
          TODO set should enable the programmer to set values of an existing osc message.
 void setAddrPattern(int theAddrPattern)
           
 void setAddrPattern(String theAddrPattern)
          set the address pattern of an osc message.
 void setArguments(Object[] theArguments)
          set the arguments of the osc message using an object array.
 long timetag()
          get the timetag of an osc message.
 String toString()
           
 String typetag()
          returns the typetag of the osc message.
 
Methods inherited from class oscP5.OscPacket
address, netaddress, netAddress, port, tcpConnection
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OscMessage

public OscMessage(OscMessage theOscMessage)
Parameters:
theOscMessage - OscMessage

OscMessage

public OscMessage(String theAddrPattern)
Parameters:
theAddrPattern - String

OscMessage

public OscMessage(int theAddrInt)
Parameters:
theAddrInt - int

OscMessage

public OscMessage(String theAddrPattern,
                  Object[] theArguments)
Parameters:
theAddrPattern - String
theArguments - Object[]

OscMessage

public OscMessage(int theAddrPattern,
                  Object[] theArguments)
Parameters:
theAddrPattern - int
theArguments - Object[]
Method Detail

clear

public void clear()
clear and reset an OscMessage for reuse.


clearArguments

public void clearArguments()
clears the arguments in a message, but keeps the address the address pattern.


set

public void set(int theIndex,
                Object theObject)
TODO set should enable the programmer to set values of an existing osc message.


checkTypetag

public boolean checkTypetag(String theTypeTag)
Parameters:
theTypeTag - String
Returns:
boolean
+Example
/**
 * oscP5parsing by andreas schlegel
 * example shows how to parse incoming osc messages "by hand".
 * it is recommended to take a look at oscP5plug for an
 * alternative and more convenient way to parse messages.
 * oscP5 website at http://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() {
  /* create a new osc message object */
  OscMessage myMessage = new OscMessage("/test");
  
  myMessage.add(123); /* add an int to the osc message */
  myMessage.add(12.34); /* add a float to the osc message */
  myMessage.add("some text"); /* add a string to the osc message */

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


void oscEvent(OscMessage theOscMessage) {
  /* check if theOscMessage has the address pattern we are looking for. */
  
  if(theOscMessage.checkAddrPattern("/test")==true) {
    /* check if the typetag is the right one. */
    if(theOscMessage.checkTypetag("ifs")) {
      /* parse theOscMessage and extract the values from the osc message arguments. */
      int firstValue = theOscMessage.get(0).intValue();  
      float secondValue = theOscMessage.get(1).floatValue();
      String thirdValue = theOscMessage.get(2).stringValue();
      print("### received an osc message /test with typetag ifs.");
      println(" values: "+firstValue+", "+secondValue+", "+thirdValue);
      return;
    }  
  } 
  println("### received an osc message. with address pattern "+theOscMessage.addrPattern());
}

checkAddrPattern

public boolean checkAddrPattern(String theAddrPattern)
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) {...}

Parameters:
theAddrPattern - String
Returns:
boolean
+Example
/**
 * oscP5parsing by andreas schlegel
 * example shows how to parse incoming osc messages "by hand".
 * it is recommended to take a look at oscP5plug for an
 * alternative and more convenient way to parse messages.
 * oscP5 website at http://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() {
  /* create a new osc message object */
  OscMessage myMessage = new OscMessage("/test");
  
  myMessage.add(123); /* add an int to the osc message */
  myMessage.add(12.34); /* add a float to the osc message */
  myMessage.add("some text"); /* add a string to the osc message */

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


void oscEvent(OscMessage theOscMessage) {
  /* check if theOscMessage has the address pattern we are looking for. */
  
  if(theOscMessage.checkAddrPattern("/test")==true) {
    /* check if the typetag is the right one. */
    if(theOscMessage.checkTypetag("ifs")) {
      /* parse theOscMessage and extract the values from the osc message arguments. */
      int firstValue = theOscMessage.get(0).intValue();  
      float secondValue = theOscMessage.get(1).floatValue();
      String thirdValue = theOscMessage.get(2).stringValue();
      print("### received an osc message /test with typetag ifs.");
      println(" values: "+firstValue+", "+secondValue+", "+thirdValue);
      return;
    }  
  } 
  println("### received an osc message. with address pattern "+theOscMessage.addrPattern());
}

setAddrPattern

public void setAddrPattern(String theAddrPattern)
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.

Parameters:
theAddrPattern - String

setAddrPattern

public void setAddrPattern(int theAddrPattern)
Parameters:
theAddrPattern - int

setArguments

public void setArguments(Object[] theArguments)
set the arguments of the osc message using an object array. with version 0.9.4 the existing arguments are overwritten, to add the arguments to the argument list, use addArguments(Object[])

Parameters:
theArguments - Object[]

addArguments

public OscMessage addArguments(Object[] theArguments)
add a list of arguments to an exisiting set of arguments. to overwrite the existing argument list, use setArguments(Object[])

Parameters:
theArguments -

addrPattern

public String addrPattern()

addrInt

public int addrInt()
returns the address pattern of the osc message as int.

Returns:
int

typetag

public String typetag()
returns the typetag of the osc message. e.g. the message contains 3 floats then the typetag would be "fff"

Returns:
String

timetag

public long timetag()
get the timetag of an osc message. timetags are only sent by osc bundles.

Returns:
long

arguments

public Object[] arguments()
Returns:
Object[]

getAddrPatternAsBytes

public byte[] getAddrPatternAsBytes()
Returns:
byte[]

getTypetagAsBytes

public byte[] getTypetagAsBytes()
Returns:
byte[]

getBytes

public byte[] getBytes()
Specified by:
getBytes in class OscPacket
Returns:
byte[]

add

public OscMessage add()
add values to an osc message. please check the add documentation for specific information.

+Example
/**
 * oscP5message by andreas schlegel
 * example shows how to create osc messages.
 * oscP5 website at http://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 */
  myMessage.add(12.34); /* add a float to the osc message */
  myMessage.add("some text"); /* add a string to the osc message */
  myMessage.add(new byte[] {0x00, 0x01, 0x10, 0x20}); /* add a byte blob to the osc message */
  myMessage.add(new int[] {1,2,3,4}); /* add an int array 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());
}

add

public OscMessage add(int theValue)
Parameters:
theValue - int

add

public OscMessage add(String theValue)
Parameters:
theValue - String

add

public OscMessage add(float theValue)
Parameters:
theValue - float

add

public OscMessage add(double theValue)
Parameters:
theValue - double

add

public OscMessage add(boolean theValue)
Parameters:
theValue - boolean

add

public OscMessage add(Boolean theValue)
Parameters:
theValue - Boolean

add

public OscMessage add(Integer theValue)
Parameters:
theValue - Integer

add

public OscMessage add(Float theValue)
Parameters:
theValue - Float

add

public OscMessage add(Double theValue)
Parameters:
theValue - Double

add

public OscMessage add(Character theValue)
Parameters:
theValue - Character

add

public OscMessage add(char theValue)
Parameters:
theValue - char

add

public OscMessage add(int channel,
                      int status,
                      int value1,
                      int value2)
Parameters:
channel - int
status - int
value1 - int
value2 - int

add

public OscMessage add(int[] theArray)
Parameters:
theArray - int[]

add

public OscMessage add(char[] theArray)
Parameters:
theArray - char[]

add

public OscMessage add(float[] theArray)
Parameters:
theArray - float[]

add

public OscMessage add(String[] theArray)
Parameters:
theArray - String[]

add

public OscMessage add(byte[] theArray)
Parameters:
theArray - byte[]

add

public OscMessage add(Object[] theArray)
Parameters:
theArray - Object[]

makeBlob

public static byte[] makeBlob(byte[] b)
Parameters:
b - byte[]
Returns:
byte[]

get

public OscArgument get(int theIndex)
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();

Parameters:
theIndex - int
Returns:
OscArgument

toString

public final String toString()
Overrides:
toString in class Object
Returns:
String

isPlugged

public boolean isPlugged()

print

public void print()

printData

public void printData()


processing library oscP5 by Andreas Schlegel. (c) 2004-2012