19 |
19 |
20 import com.illposed.osc.utility.*; |
20 import com.illposed.osc.utility.*; |
21 |
21 |
22 public class OSCMessage extends OSCPacket { |
22 public class OSCMessage extends OSCPacket { |
23 |
23 |
24 protected String address; |
24 protected String address; |
25 protected Vector<Object> arguments; |
25 protected Vector<Object> arguments; |
26 |
26 |
27 /** |
27 /** |
28 * Create an empty OSC Message |
28 * Create an empty OSC Message |
29 * In order to send this osc message, you need to set the address |
29 * In order to send this osc message, you need to set the address |
30 * and, perhaps, some arguments. |
30 * and, perhaps, some arguments. |
31 */ |
31 */ |
32 public OSCMessage() { |
32 public OSCMessage() { |
33 super(); |
33 super(); |
34 arguments = new Vector<Object>(); |
34 arguments = new Vector<Object>(); |
35 } |
35 } |
36 |
36 |
37 /** |
37 /** |
38 * Create an OSCMessage with an address already initialized |
38 * Create an OSCMessage with an address already initialized |
39 * @param newAddress The recepient of this OSC message |
39 * @param newAddress The recepient of this OSC message |
40 */ |
40 */ |
41 public OSCMessage(String newAddress) { |
41 public OSCMessage(String newAddress) { |
42 this(newAddress, null); |
42 this(newAddress, null); |
43 } |
43 } |
44 |
44 |
45 /** |
45 /** |
46 * Create an OSCMessage with an address and arguments already initialized |
46 * Create an OSCMessage with an address and arguments already initialized |
47 * @param newAddress The recepient of this OSC message |
47 * @param newAddress The recepient of this OSC message |
48 * @param newArguments The data sent to the receiver |
48 * @param newArguments The data sent to the receiver |
49 */ |
49 */ |
50 public OSCMessage(String newAddress, Object[] newArguments) { |
50 public OSCMessage(String newAddress, Object[] newArguments) { |
51 super(); |
51 super(); |
52 address = newAddress; |
52 address = newAddress; |
53 if (null != newArguments) { |
53 if (null != newArguments) { |
54 arguments = new Vector<Object>(newArguments.length); |
54 arguments = new Vector<Object>(newArguments.length); |
55 for (int i = 0; i < newArguments.length; i++) { |
55 for (int i = 0; i < newArguments.length; i++) { |
56 arguments.add(newArguments[i]); |
56 arguments.add(newArguments[i]); |
57 } |
57 } |
58 } else |
58 } else |
59 arguments = new Vector<Object>(); |
59 arguments = new Vector<Object>(); |
60 init(); |
60 init(); |
61 } |
61 } |
62 |
62 |
63 /** |
63 /** |
64 * @return the address of this OSC Message |
64 * @return the address of this OSC Message |
65 */ |
65 */ |
66 public String getAddress() { |
66 public String getAddress() { |
67 return address; |
67 return address; |
68 } |
68 } |
69 |
69 |
70 /** |
70 /** |
71 * Set the address of this messsage |
71 * Set the address of this messsage |
72 * @param anAddress |
72 * @param anAddress |
73 */ |
73 */ |
74 public void setAddress(String anAddress) { |
74 public void setAddress(String anAddress) { |
75 address = anAddress; |
75 address = anAddress; |
76 } |
76 } |
77 |
77 |
78 public void addArgument(Object argument) { |
78 public void addArgument(Object argument) { |
79 arguments.add(argument); |
79 arguments.add(argument); |
80 } |
80 } |
81 |
81 |
82 public Object[] getArguments() { |
82 public Object[] getArguments() { |
83 return arguments.toArray(); |
83 return arguments.toArray(); |
84 } |
84 } |
85 |
85 |
86 /** |
86 /** |
87 * @param stream OscPacketByteArrayConverter |
87 * @param stream OscPacketByteArrayConverter |
88 */ |
88 */ |
89 protected void computeAddressByteArray(OSCJavaToByteArrayConverter stream) { |
89 protected void computeAddressByteArray(OSCJavaToByteArrayConverter stream) { |
90 stream.write(address); |
90 stream.write(address); |
91 } |
91 } |
92 |
92 |
93 /** |
93 /** |
94 * @param stream OscPacketByteArrayConverter |
94 * @param stream OscPacketByteArrayConverter |
95 */ |
95 */ |
96 protected void computeArgumentsByteArray(OSCJavaToByteArrayConverter stream) { |
96 protected void computeArgumentsByteArray(OSCJavaToByteArrayConverter stream) { |
97 // SC starting at version 2.2.10 wants a comma at the beginning |
97 // SC starting at version 2.2.10 wants a comma at the beginning |
98 // of the arguments array. |
98 // of the arguments array. |
99 stream.write(','); |
99 stream.write(','); |
100 if (null == arguments) |
100 if (null == arguments) |
101 return; |
101 return; |
102 stream.writeTypes(arguments); |
102 stream.writeTypes(arguments); |
103 Enumeration enm = arguments.elements(); |
103 Enumeration enm = arguments.elements(); |
104 while (enm.hasMoreElements()) { |
104 while (enm.hasMoreElements()) { |
105 stream.write(enm.nextElement()); |
105 stream.write(enm.nextElement()); |
106 } |
106 } |
107 } |
107 } |
108 |
108 |
109 /** |
109 /** |
110 * @param stream OscPacketByteArrayConverter |
110 * @param stream OscPacketByteArrayConverter |
111 */ |
111 */ |
112 protected void computeByteArray(OSCJavaToByteArrayConverter stream) { |
112 protected void computeByteArray(OSCJavaToByteArrayConverter stream) { |
113 computeAddressByteArray(stream); |
113 computeAddressByteArray(stream); |
114 computeArgumentsByteArray(stream); |
114 computeArgumentsByteArray(stream); |
115 byteArray = stream.toByteArray(); |
115 byteArray = stream.toByteArray(); |
116 } |
116 } |
117 |
117 |
118 } |
118 } |