-
Notifications
You must be signed in to change notification settings - Fork 0
/
TR.pde
331 lines (287 loc) · 7.88 KB
/
TR.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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
import controlP5.*;
import processing.javafx.PGraphicsFX2D;
import codeanticode.tablet.*;
import oscP5.*;
import netP5.*;
String path; // sketch path
// libraries
ControlP5 cp5;
Tablet tablet;
OscP5 oscP5;
NetAddress myRemoteLocation;
//current traj
ArrayList<Point> points = new ArrayList<Point>();
ArrayList<OscBundle> traj = new ArrayList<OscBundle>();
// traj index
int ti = 0;
//
PGraphics c;
Canvas canvas;
PFont font;
color green = 0xff00e300; // font color
boolean firstClicked = true;
// controls
PImage playActive;
PImage playDefault;
PImage pauseActive;
PImage pauseDefault;
PImage stopActive;
PImage stopDefault;
PImage saveActive;
PImage saveDefault;
PImage clearActive;
PImage clearDefault;
// loop - checkbox
// tempo - slider + numeric
// play - button
// pause - button
// stop - button
// traj list / radio button
// scene list
//ControlFont.RENDER_2X = true;
RadioButton trajList;
RadioButton sceneList;
Button play;
Button pause;
Button stopButton;
Button clearButton;
//Button clear;
RadioButton loopSelect;
RadioButton useTablet;
Textfield trajNameInput;
//String trajName = "";
Textfield source;
Button saveButton;
Slider tempo;
boolean isPaused;
boolean isStopped;
// modes
byte IDLE = 35;
byte DRAW = 40;
byte PLAY = 50;
// idle by default
byte mode = IDLE;
boolean displayScene = false;
//
int cOffX = 20;
int cOffY = 65;
//
int sceneIdx = 1;
void setup() {
size(780, 600, P2D);
colorMode(HSB, 360, 100, 100);
background(0, 0, 0);
font = loadFont("SourceCodePro-Medium-48.vlw");
//font = loadFont("Corbel-Bold-48.vlw");
textFont(font, 12);
path = sketchPath();
isPaused = false;
isStopped = true;
// images - stupid and anoying icons
playDefault = loadImage("icons/play_g.png");
playActive = loadImage("icons/play_ga.png");
pauseDefault = loadImage("icons/pause_g.png");
pauseActive = loadImage("icons/pause_ga.png");
stopDefault = loadImage("icons/stop_g.png");
stopActive = loadImage("icons/stop_ga.png");
saveDefault = loadImage("icons/save_g.png");
saveActive = loadImage("icons/save_ga.png");
clearDefault = loadImage("icons/clear_g.png");
clearActive = loadImage("icons/clear_ga.png");
// NETWORK
// listening port
oscP5 = new OscP5(this, 6667);
// sending port
myRemoteLocation = new NetAddress("127.0.0.1", 6666);
// GUI
cp5 = new ControlP5(this);
Controls.config(cp5, font);
String [] optionsLoop = {"no loop", "loop"};
String [] optionsTablet = {"no tablet", "tablet"};
//loop = Controls.getSwitch(cp5, "loop", Controls.colUp*4 , 1, -20);
loopSelect = Controls.getRadioFixedOptions(cp5, "loopSelector", optionsLoop, "loop", Controls.colUp*4 , 1, -30);
play = Controls.getButton(cp5, "play", playDefault, playActive , Controls.colUp*5 , 1, -20);
pause = Controls.getButton(cp5, "pause", pauseDefault, pauseActive, Controls.colUp*5 + 50 , 1, -20);
stopButton = Controls.getButton(cp5, "stopButton", stopDefault, stopActive, Controls.colUp*5 + 100 , 1, -20);
useTablet = Controls.getRadioFixedOptions(cp5, "useTablet", optionsTablet, "no tablet", Controls.column , 1, -30);
// separator
tempo = Controls.getSliderH(cp5, "duration", 0.005, 4, Controls.colUp, 1, -20);
tempo.setValue(1);
// separator
//
trajNameInput = Controls.getTextInput(cp5, "trajName", 2);
saveButton = Controls.getButton(cp5, "saveButton", saveDefault, saveActive, Controls.column + Controls.itmWidth + 5 , 2, 2);
clearButton = Controls.getButton(cp5, "clearButton", clearDefault, clearActive, Controls.column + Controls.itmWidth + 30 , 2, 2);
trajList = Controls.getRadioOptions(cp5, "trajList", path+"/traj", ".tr", true, "<NEW>", 3);
// separator
sceneList = Controls.getRadioOptions(cp5,"sceneList", path+"/data/scenes", "", false, "st", 8);
// surface.setResizable(true);
c = createGraphics(500, 500, P2D);
tablet = new Tablet(this); //<>// //<>//
canvas = new Canvas(c, cOffX, cOffY, 500, 500, tablet);
canvas.setUsingTablet(false);
canvas.drawCanvas();
frameRate(DRAW);
}
void draw() {
background(0, 0, 0);
canvas.drawScene();
if (mousePressed && mode != PLAY) {
canvas.drawPoints(firstClicked);
firstClicked = false;
} else {
canvas.drawCanvas();
}
if ((!isPaused || !isStopped) && traj.size() > 0) {
stroke(green);
strokeWeight(8);
if(ti < points.size()) {
Point p = points.get(ti);
point(p.x+cOffX, p.y+cOffY);
} else {
if(loopSelect.getValue() == 0) {
ti = 0;
isPaused = true;
}
}
}
if(isPaused && points.size() > 0) {
Point p = points.get(ti);
point(p.x+cOffX, p.y+cOffY);
}
fill(green);
separator("TRAJECTORY", Controls.column, Controls.row *2-35, Controls.itmWidth, Controls.itmHeight);
separator("SCENE", Controls.column, Controls.row *8-35, Controls.itmWidth, Controls.itmHeight);
text("TRAJ POINTS: "+canvas.points.size(), cOffX, height -20);
//
text("_TR", cOffX, 30);
}
void mousePressed() {
if(mode != PLAY) {
firstClicked = true;
mode = DRAW;
//frameRate(DRAW);
}
}
void mouseMoved() {
firstClicked = false;
}
void mouseReleased() {
if(mode != PLAY) {
//frameRate(IDLE);
firstClicked = false;
// set END cmp to last path point
canvas.closePath();
//canvas.renderPoints();
}
}
public void saveButton(int value){
String n = trajNameInput.getText();
n = trim(n).toLowerCase().replace(".tr","");
canvas.loadTrajBundles();
canvas.saveTrajectory(n);
traj = canvas.traj;
points = canvas.points;
ti = 0;
int idx = +trajList.getItems().size();
println("New traj index: " + trajList.getItem(n));
if (trajList.getItem(n) == null) {
trajList.addItem(n, idx);
}
trajList.activate(n);
}
public void play(int value) {
canvas.loadTrajBundles();
traj = canvas.traj;
points = canvas.points;
println(value);
mode = PLAY;
isPaused = false;
isStopped = false;
// frameRate(mode);
thread("trajTimer");
}
public void pause(int value){
isPaused = true;
}
public void stopButton(int value){
isStopped = true;
isPaused = true;
ti = 0;
mode = IDLE;
// frameRate(mode);
}
public void clearButton(int value){
ti = 0;
canvas.clearTraj();
mode = IDLE;
}
public void sceneList(int s) {
try {
String name = sceneList.getItem(s).getName();
println("switching to scene " + name);
canvas.scene.loadScene(name);
} catch (Exception e) {
e.printStackTrace();
}
}
public void trajList(int t) {
try {
String name = trajList.getItem(t).getName();
canvas.clearTraj();
canvas.loadTrajectory(name);
trajNameInput.setText(name.toUpperCase());
canvas.loadTrajBundles();
traj = canvas.traj;
points = canvas.points;
if(traj.size() == 0) {
isPaused = true;
}
ti = 0;
} catch (Exception e) {
e.printStackTrace();
}
}
void useTablet (int t) {
canvas.setUsingTablet(boolean(t));
print(canvas.usingTablet);
}
public void separator(String text, int c ,int r, int w, int h) {
text("..."+text+"...", c, r, w, h);
}
/* incoming osc message are forwarded to the oscEvent method. */
void oscEvent(OscMessage msg) {
switch (msg.addrPattern()) {
case "/play":
println("play");
case "/stop":
println("stop");
case "/pause":
println("pause");
case "/duration":
println("duration");
case "/traj":
println("traj");
default:
break;
}
/* print the address pattern and the typetag of the received OscMessage */
print("### received an osc message.");
print(" addrpattern: "+msg.addrPattern());
println(" typetag: "+msg.typetag());
}
void trajTimer() {
int lastEvent = millis();
while(!isPaused && canvas.traj.size() > 0) {
if(millis()- lastEvent > 1000 * (tempo.getValue() / 10)) {
if (ti >= traj.size()) {
ti = 0;
}
if(canvas.traj.size() > 0) {
oscP5.send(canvas.traj.get(ti), myRemoteLocation);
ti++;
lastEvent = millis();
}
}
}
}