front_processing/extern/TUIO_JAVA/src/com/illposed/osc/OSCMessage.java
changeset 0 6fefd4afe506
child 9 0f44b7360c8d
equal deleted inserted replaced
-1:000000000000 0:6fefd4afe506
       
     1 /**
       
     2  * @author cramakrishnan
       
     3  *
       
     4  * Copyright (C) 2003, C. Ramakrishnan / Illposed Software
       
     5  * All rights reserved.
       
     6  * 
       
     7  * See license.txt (or license.rtf) for license information.
       
     8  * 
       
     9  * 
       
    10  * An simple (non-bundle) OSC message. An OSC message is made up of 
       
    11  *     an address (who is this message sent to)
       
    12  *     and arguments (what is the contents of this message).
       
    13  */
       
    14 
       
    15 package com.illposed.osc;
       
    16 
       
    17 import java.util.Enumeration;
       
    18 import java.util.Vector;
       
    19 
       
    20 import com.illposed.osc.utility.*;
       
    21 
       
    22 public class OSCMessage extends OSCPacket {
       
    23 
       
    24 	protected String address;
       
    25 	protected Vector<Object> arguments;
       
    26 
       
    27 	/**
       
    28 	 * Create an empty OSC Message
       
    29 	 * In order to send this osc message, you need to set the address
       
    30 	 * and, perhaps, some arguments.
       
    31 	 */
       
    32 	public OSCMessage() {
       
    33 		super();
       
    34 		arguments = new Vector<Object>();
       
    35 	}
       
    36 
       
    37 	/**
       
    38 	 * Create an OSCMessage with an address already initialized
       
    39 	 * @param newAddress The recepient of this OSC message
       
    40 	 */
       
    41 	public OSCMessage(String newAddress) {
       
    42 		this(newAddress, null);
       
    43 	}
       
    44 
       
    45 	/**
       
    46 	 * Create an OSCMessage with an address and arguments already initialized
       
    47 	 * @param newAddress    The recepient of this OSC message
       
    48 	 * @param newArguments  The data sent to the receiver
       
    49 	 */
       
    50 	public OSCMessage(String newAddress, Object[] newArguments) {
       
    51 		super();
       
    52 		address = newAddress;
       
    53 		if (null != newArguments) {
       
    54 			arguments = new Vector<Object>(newArguments.length);
       
    55 			for (int i = 0; i < newArguments.length; i++) {
       
    56 				arguments.add(newArguments[i]);
       
    57 			}
       
    58 		} else
       
    59 			arguments = new Vector<Object>();
       
    60 		init();
       
    61 	}
       
    62 	
       
    63 	/**
       
    64 	 * @return the address of this OSC Message
       
    65 	 */
       
    66 	public String getAddress() {
       
    67 		return address;
       
    68 	}
       
    69 	
       
    70 	/**
       
    71 	 * Set the address of this messsage
       
    72 	 * @param anAddress
       
    73 	 */
       
    74 	public void setAddress(String anAddress) {
       
    75 		address = anAddress;
       
    76 	}
       
    77 	
       
    78 	public void addArgument(Object argument) {
       
    79 		arguments.add(argument);
       
    80 	}
       
    81 	
       
    82 	public Object[] getArguments() {
       
    83 		return arguments.toArray();
       
    84 	}
       
    85 
       
    86 	/**
       
    87 	 * @param stream OscPacketByteArrayConverter
       
    88 	 */
       
    89 	protected void computeAddressByteArray(OSCJavaToByteArrayConverter stream) {
       
    90 		stream.write(address);
       
    91 	}
       
    92 
       
    93 	/**
       
    94 	 * @param stream OscPacketByteArrayConverter
       
    95 	 */
       
    96 	protected void computeArgumentsByteArray(OSCJavaToByteArrayConverter stream) {
       
    97 		// SC starting at version 2.2.10 wants a comma at the beginning
       
    98 		// of the arguments array.
       
    99 		stream.write(',');
       
   100 		if (null == arguments)
       
   101 			return;
       
   102 		stream.writeTypes(arguments);
       
   103 		Enumeration enm = arguments.elements();
       
   104 		while (enm.hasMoreElements()) {
       
   105 			stream.write(enm.nextElement());
       
   106 		}
       
   107 	}
       
   108 
       
   109 	/**
       
   110 	 * @param stream OscPacketByteArrayConverter
       
   111 	 */
       
   112 	protected void computeByteArray(OSCJavaToByteArrayConverter stream) {
       
   113 		computeAddressByteArray(stream);
       
   114 		computeArgumentsByteArray(stream);
       
   115 		byteArray = stream.toByteArray();
       
   116 	}
       
   117 
       
   118 }