-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOSCreceive.ino
More file actions
100 lines (83 loc) · 2.45 KB
/
Copy pathOSCreceive.ino
File metadata and controls
100 lines (83 loc) · 2.45 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
byte OSCMsgReceive()
{
boolean changed = 0;
OSCMessage msgRec;
int size = oscEndpoint.parsePacket();
//Serial.println(size);
if (size > 0) {
if (DEBUG) {
Serial.printf("Received %d bytes from %s, port %d\n", size, oscEndpoint.remoteIP().toString().c_str(), oscEndpoint.remotePort());
}
while (size--) {
msgRec.fill(oscEndpoint.read());
}
if (!msgRec.hasError()) {
changed = 1;
msgRec.route("/status", fromHost);
}
}
return changed;
}
void fromHost(OSCMessage &msg, int addrOffset) {
int S = msg.size();
if (DEBUG) {
int L = msg.getDataLength(0);
char type = msg.getType(0);
Serial.print("Size total msg: "); Serial.println(S);
Serial.print("Size of msg: "); Serial.println(L);
Serial.print("Type of msg: "); Serial.println(type);
}
for (int i = 0; i < S; i++)
{
bufferFromHost[i] = msg.getInt(i);
}
}
void OSCMsgSet(OSCMessage& msg, float* data, int dataSize, int offset) {
for (int i = 0; i < dataSize; i++) {
msg.set(i, data[i + offset]);
}
}
void OSCMsgSet(OSCMessage& msg, int* data, int dataSize, int offset) {
for (int i = 0; i < dataSize; i++) {
msg.set(i, data[i + offset]);
}
}
void OSCMsgSet(OSCMessage& msg, int data, int offset) {
msg.set(offset, data);
}
void OSCMsgSet(OSCMessage& msg, float data, int offset) {
msg.set(offset, data);
}
void OSCMsgSend(OSCMessage& msg, float* data, int dataSize, IPAddress oscEndpointIP, int oscEndpointPORT) {
for (int i = 0; i < dataSize; i++) {
msg.set(i, data[i]);
}
oscEndpoint.beginPacket(oscEndpointIP, oscEndpointPORT);
msg.send(oscEndpoint);
oscEndpoint.endPacket();
msg.empty();
}
void OSCMsgSend(OSCMessage& msg, uint8_t* data, int dataSize, IPAddress oscEndpointIP, int oscEndpointPORT) {
for (int i = 0; i < dataSize; i++) {
msg.set(i, data[i]);
}
oscEndpoint.beginPacket(oscEndpointIP, oscEndpointPORT);
msg.send(oscEndpoint);
oscEndpoint.endPacket();
msg.empty();
}
void OSCMsgSend(OSCMessage& msg, int* data, int dataSize, IPAddress oscEndpointIP, int oscEndpointPORT) {
for (int i = 0; i < dataSize; i++) {
msg.set(i, data[i]);
}
oscEndpoint.beginPacket(oscEndpointIP, oscEndpointPORT);
msg.send(oscEndpoint);
oscEndpoint.endPacket();
msg.empty();
}
void OSCMsgSend(OSCMessage& msg, IPAddress oscEndpointIP, int oscEndpointPORT) {
oscEndpoint.beginPacket(oscEndpointIP, oscEndpointPORT);
msg.send(oscEndpoint);
oscEndpoint.endPacket();
msg.empty();
}