-
Notifications
You must be signed in to change notification settings - Fork 20
/
Osc.pde
85 lines (73 loc) · 2.45 KB
/
Osc.pde
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
void oscSetup() {
oscP5 = new OscP5(this, receivePort);
myRemoteLocation = new NetAddress(ipNumber, sendPort);
if(oscLocalEcho) myRemoteLocationEcho = new NetAddress("127.0.0.1", sendPort);
}
void oscEvent(OscMessage msg) {
if (msg.checkAddrPattern("/joint") && msg.checkTypetag("sifff")) {
found = true;
for (int i=0;i<osceletonNames.length;i++) {
if (modeOsc&&msg.get(0).stringValue().equals(osceletonNames[i])) {
x[i] = msg.get(2).floatValue();
y[i] = msg.get(3).floatValue();
z[i] = msg.get(4).floatValue();
}
}
}
}
void oscSendHandler(OscMessage _myMessage){
try{
oscP5.send(_myMessage, myRemoteLocation);
}catch(Exception e){ }
try{
if(oscLocalEcho){
oscP5.send(_myMessage, myRemoteLocationEcho);
}
}catch(Exception e){ }
}
void oscSend(int skel) {
OscMessage myMessage;
int counter = 0;
for (int i=0;i<osceletonNames.length;i++) {
try{
if(oscChannelFormat.equals("Isadora")){
counter++;
myMessage = new OscMessage("/isadora/"+counter); // x
myMessage.add(x[i]);
oscSendHandler(myMessage);
counter++;
myMessage = new OscMessage("/isadora/"+counter); // x
myMessage.add(y[i]);
oscSendHandler(myMessage);
counter++;
myMessage = new OscMessage("/isadora/"+counter); // x
myMessage.add(z[i]);
oscSendHandler(myMessage);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}else if(oscChannelFormat.equals("OSCeleton")){
myMessage = new OscMessage("/joint"); // x
myMessage.add(osceletonNames[i]);
myMessage.add(skel);
myMessage.add(x[i]);
myMessage.add(y[i]);
myMessage.add(z[i]);
oscSendHandler(myMessage);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}else if(oscChannelFormat.equals("Animata")){
myMessage = new OscMessage("/joint");
myMessage.add(osceletonNames[i]);
myMessage.add((x[i]*640)+0);
myMessage.add((y[i]*480)+0);
oscSendHandler(myMessage);
//~~
/*
myMessage = new OscMessage("/anibone");
myMessage.add(osceletonNames[i]);
myMessage.add(1);
oscSendHandler(myMessage);
*/
}
println("Sending OSC, format \""+ oscChannelFormat +"\", to " + myRemoteLocation + " " + osceletonNames[i] + " x: " + x[i] + " y: " + y[i] + " z: " + z[i]);
}catch(Exception e){ }
}
}