forked from processing/processing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOSCMessage.java
More file actions
150 lines (132 loc) · 3.56 KB
/
Copy pathOSCMessage.java
File metadata and controls
150 lines (132 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* Copyright (C) 2003-2006, C. Ramakrishnan / Illposed Software.
* All rights reserved.
*
* This code is licensed under the BSD 3-Clause license.
* See file LICENSE (or LICENSE.html) for more information.
*/
package com.illposed.osc;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import com.illposed.osc.utility.OSCJavaToByteArrayConverter;
/**
* An simple (non-bundle) OSC message.
*
* An OSC message is made up of an address (the receiver of the message)
* and arguments (the content of the message).
*
* @author Chandrasekhar Ramakrishnan
*/
public class OSCMessage extends OSCPacket {
private String address;
private List<Object> arguments;
/**
* Creates an empty OSC Message.
* In order to send this OSC message,
* you need to set the address and optionally some arguments.
*/
public OSCMessage() {
arguments = new LinkedList<Object>();
}
/**
* Creates an OSCMessage with an address already initialized.
* @param address the recipient of this OSC message
*/
public OSCMessage(String address) {
this(address, (Collection<Object>) null);
}
// deprecated since version 1.0, March 2012
/**
* Creates an OSCMessage with an address and arguments already initialized.
* @param address the recipient of this OSC message
* @param arguments the data sent to the receiver
* @deprecated
*/
public OSCMessage(String address, Object[] arguments) {
this.address = address;
if (arguments == null) {
this.arguments = new LinkedList<Object>();
} else {
this.arguments = new ArrayList<Object>(arguments.length);
this.arguments.addAll(Arrays.asList(arguments));
}
init();
}
/**
* Creates an OSCMessage with an address
* and arguments already initialized.
* @param address the recipient of this OSC message
* @param arguments the data sent to the receiver
*/
public OSCMessage(String address, Collection<Object> arguments) {
this.address = address;
if (arguments == null) {
this.arguments = new LinkedList<Object>();
} else {
this.arguments = new ArrayList<Object>(arguments);
}
init();
}
/**
* The receiver of this message.
* @return the receiver of this OSC Message
*/
public String getAddress() {
return address;
}
/**
* Set the address of this message.
* @param address the receiver of the message
*/
public void setAddress(String address) {
this.address = address;
}
/**
* Add an argument to the list of arguments.
* @param argument a Float, String, Integer, BigInteger, Boolean
* or an array of these
*/
public void addArgument(Object argument) {
arguments.add(argument);
}
/**
* The arguments of this message.
* @return the arguments to this message
*/
public Object[] getArguments() {
return arguments.toArray();
}
/**
* Convert the address into a byte array.
* Used internally only.
*/
protected void computeAddressByteArray(OSCJavaToByteArrayConverter stream) {
stream.write(address);
}
/**
* Convert the arguments into a byte array.
* Used internally only.
*/
protected void computeArgumentsByteArray(OSCJavaToByteArrayConverter stream) {
stream.write(',');
if (null == arguments) {
return;
}
stream.writeTypes(arguments);
for (Object argument : arguments) {
stream.write(argument);
}
}
/**
* Convert the message into a byte array.
* Used internally only.
*/
protected byte[] computeByteArray(OSCJavaToByteArrayConverter stream) {
computeAddressByteArray(stream);
computeArgumentsByteArray(stream);
return stream.toByteArray();
}
}