-
Notifications
You must be signed in to change notification settings - Fork 1
/
osc_Processing_oscP5sendReceive_pde.pde
61 lines (47 loc) · 1.88 KB
/
osc_Processing_oscP5sendReceive_pde.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
/**
* oscP5sendreceive by andreas schlegel
* example shows how to send and receive osc messages.
* oscP5 website at http://www.sojamo.de/oscP5
*/
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;
void setup() {
size(400,400);
frameRate(25);
/* start oscP5, listening for incoming messages at port 12000 */
oscP5 = new OscP5(this,12000);
/* myRemoteLocation is a NetAddress. a NetAddress takes 2 parameters,
* an ip address and a port number. myRemoteLocation is used as parameter in
* oscP5.send() when sending osc packets to another computer, device,
* application. usage see below. for testing purposes the listening port
* and the port of the remote location address are the same, hence you will
* send messages back to this sketch.
*/
myRemoteLocation = new NetAddress("127.0.0.1",12001);
}
void draw() {
background(0);
}
void mousePressed() {
/* in the following different ways of creating osc messages are shown by example */
OscMessage myMessage = new OscMessage("/hellopwgl/");
myMessage.add(123); /* add an int to the osc message */
/* send the message */
oscP5.send(myMessage, myRemoteLocation);
}
void oscEvent(OscMessage theOscMessage) {
/* check if theOscMessage has the address pattern we are looking for. */
/* check if the typetag is the right one. */
if(theOscMessage.checkTypetag("fis")) {
/* parse theOscMessage and extract the values from the osc message arguments. */
float firstValue = theOscMessage.get(0).floatValue();
int secondValue = theOscMessage.get(1).intValue();
String thirdValue = theOscMessage.get(2).stringValue();
print("### received an osc message...");
println(" values: "+firstValue+", "+secondValue+", "+thirdValue);
return;
}
println("### received an osc message. with address pattern "+theOscMessage.addrPattern());
}