-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimpleServerOscProcessing.pde
More file actions
205 lines (149 loc) · 3.6 KB
/
simpleServerOscProcessing.pde
File metadata and controls
205 lines (149 loc) · 3.6 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/**
* 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;
ArrayList<DataSender> senders = new ArrayList<DataSender>();
int PORT = 12345;
int WINO_AMOUNT = 2;
float WINO_SPEED = 100000.0;
int PLANT_AMOUNT = 3;
float PLANT_SPEED = 1000.0;
int HUMIDITY_AMOUNT = 1;
float HUMIDITY_SPEED = 1200.0;
int GAME_AMOUNT = 1;
int GAME_SPEED = 1000;
boolean game_running = true;
public class DataSender {
int ID;
double value;
int seed;
public DataSender(int ID_){
ID = ID_;
seed = (int) random(12345);
}
void setValue(float v){
value = v;
}
String type(){
return "undefined";
}
String addr(){
return "/"+type()+"/"+ID;
}
String message(){
return addr() + " " + value + "\n";
}
void update(){
OscMessage myMessage = new OscMessage(addr());
myMessage.add((float)value); /* add an int to the osc message */
oscP5.send(myMessage, myRemoteLocation);
}
}
public class Winogradsky extends DataSender {
public Winogradsky(int ID_){
super(ID_);
}
String type(){
return "winogradsky";
}
void update(){
setValue(noise(frameCount / WINO_SPEED + seed));
super.update();
}
}
public class Plant extends DataSender {
public Plant(int ID_){
super(ID_);
}
String type(){
return "plant";
}
void update(){
setValue(noise(frameCount / PLANT_SPEED + seed));
super.update();
}
}
public class Humidity extends DataSender {
public Humidity(int ID_){
super(ID_);
}
String type(){
return "humidity";
}
void update(){
setValue(noise(frameCount / HUMIDITY_SPEED + seed));
super.update();
}
}
public class GamePress extends DataSender {
int target = 0;
public GamePress(int ID_){
super(ID_);
setTarget();
}
void setTarget(){
target = frameCount + (int)random(GAME_SPEED);
}
String type(){
return "gamepress";
}
void update(){
boolean check = (frameCount == target);
value = check?1.0:0.0;
if(check){
setTarget();
}
super.update();
}
String message(){
return addr() + " " + target + "->" + frameCount +"\n";
}
}
void setup() {
size(800,230);
/* start oscP5, listening for incoming messages at port 12000 */
oscP5 = new OscP5(this,1);
myRemoteLocation = new NetAddress("127.0.0.1",PORT);
frameRate(30);
for (int i = 0; i < WINO_AMOUNT; i++){
senders.add(new Winogradsky(i));
}
for (int i = 0; i < PLANT_AMOUNT; i++){
senders.add(new Plant(i));
}
for (int i = 0; i < HUMIDITY_AMOUNT; i++){
senders.add(new Humidity(i));
}
for (int i = 0; i < GAME_AMOUNT; i++){
senders.add(new GamePress(i));
}
}
void draw() {
background(0);
//OscMessage myMessage = new OscMessage("/sensor1");
//myMessage.add(noise(frameCount)); /* add an int to the osc message */
//oscP5.send(myMessage, myRemoteLocation);
String text = "";
for (int i = 0; i < senders.size(); i++){
DataSender s = senders.get(i);
s.update();
text += s.message();
rect(width/2, 18 + i*24, (float)s.value*width/2 + 3, 15);
}
text+= "game active: " + game_running + " (press space bar) \n";
textSize(15);
text(text, 10, 30);
OscMessage myMessage = new OscMessage("/gameactive/0");
myMessage.add(game_running);
oscP5.send(myMessage, myRemoteLocation);
}
void keyPressed(){
if (key == ' '){
game_running = !game_running;
}
}