-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtscope.pde
356 lines (279 loc) · 7.84 KB
/
tscope.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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/**
* Tachistoscope
* ispiro
*/
import processing.opengl.*;
import java.util.Map;
import gifAnimation.*;
/******************* GLOBALS *******************/
int currentSearch = 30;
int currentImage = 0;
int count = 0;
int freezeImage = -1;
int attempt = 0;
int lastTime;
int lastBuffer = 0;
int nextSet = -1;
int previewWidth;
int framesToExport = -1;
String statusMessage;
String searchString;
String search;
float statusCount = 0;
float randomFrame;
boolean newSearch;
boolean updateSpeed = true;
boolean ready = false;
boolean filling = false;
HashMap<String, String[]> images;
ArrayList searches;
PFont font;
PImage buffer[] = new PImage[100];
PImage grays[] = new PImage[100];
GifMaker gifExport;
TOptions t;
TInput in;
/******************* SETUP *******************/
void setup() {
t = new TOptions();
in = new TInput(this, t);
loadCachedSearches();
lastTime = millis();
int windowWidth = t.width;
if (t.doubleMode) {
previewWidth = (int)(t.width * t.previewScale);
windowWidth = t.width + previewWidth;
}
size((int)(windowWidth), (int)(t.height), OPENGL);
if (t.doubleMode) {
frame.setLocation(t.masterWidth-previewWidth, -20);
}
colorMode(HSB);
frameRate(100);
font = loadFont("CourierNew36.vlw");
textFont(font, 32);
fillBuffer();
}
void drawTexture(PImage img) {
float displayWidth;
float displayHeight;
float aspect = (float)img.width/(float) img.height;
displayWidth = aspect * height;
displayHeight = height;
if (displayWidth > t.width) {
displayWidth = t.width;
}
if (t.doubleMode) {
int startX = (int)(t.width*t.previewScale) + abs((int)((displayWidth - t.width) / 2));
image(img, startX, 0, displayWidth, displayHeight);
startX = (int)((t.width*t.previewScale - displayWidth*t.previewScale) / 2);
image(img, startX, 0, displayWidth * t.previewScale, displayHeight*t.previewScale);
}
else {
int startX = (int)((t.width - displayWidth) / 2);
image(img, startX, 0, displayWidth, displayHeight);
}
}
void draw() {
updateBuffer();
background(0);
if (!ready) return;
if (updateSpeed) {
frameRate(t.frameSpeed);
updateSpeed = false;
}
int theTint = t.tintHue;
if (t.tintHue == 0) {
float milli = millis();
float milliNoise = noise(milli*.0001) * 2 * (noise(milli) - .5);
theTint = (int)(abs(milliNoise) * 2 * 360.0);
}
if (freezeImage != -1) {
tint(theTint, t.tintAmount, t.brightness);
drawTexture(buffer[freezeImage]);
tint(theTint, t.tintAmount, t.brightness, t.imageSaturation);
drawTexture(grays[freezeImage]);
} else {
if (t.kernelSize == 1) {
tint(theTint, t.tintAmount, t.brightness);
drawTexture(buffer[currentImage]);
tint(theTint, t.tintAmount, t.brightness, t.imageSaturation);
drawTexture(grays[currentImage]);
} else {
for (int d = 0; d < t.kernelSize; d++) {
int pos = currentImage + d;
while (pos >= t.bufferSize) {
pos -= t.bufferSize;
}
tint(theTint, t.tintAmount, t.brightness, t.kernel[d]);
drawTexture(buffer[pos]);
tint(theTint, t.tintAmount, t.brightness, t.kernel[d]);
drawTexture(grays[pos]);
}
}
}
count++;
currentImage = count + t.bufferOffset;
currentImage = t.bufferOffset + ((count + t.bufferOffset) % t.loopSize);
while (currentImage >= t.bufferSize) {
currentImage -= t.bufferSize;
}
if (statusCount > 0) {
statusCount-= (10.0 / t.frameSpeed);
if (t.verbose || statusMessage == "t.verbose off") {
fill(255, 0, 0, 255 * (statusCount / 20.0));
text(statusMessage, 50-2, 50);
fill(255, 0, 0, 255 * (statusCount / 20.0));
text(statusMessage, 50+2, 50);
fill(255, 0, 0, 255 * (statusCount / 20.0));
text(statusMessage, 50, 50+2);
fill(255, 0, 0, 255 * (statusCount / 20.0));
text(statusMessage, 50, 50-2);
fill(70, 255, 255, 255 * (statusCount / 20.0));
text(statusMessage, 50, 50);
}
}
if (framesToExport > 0) {
int delay = int(1000.0 / t.frameSpeed);
int frame = t.loopSize - framesToExport;
gifExport.setDelay(delay);
gifExport.addFrame();
println("Added frame " + frame + " to GIF");
framesToExport--;
} else if (framesToExport == 0) {
gifExport.finish();
println("Done exporting GIF");
framesToExport = -1;
}
}
void setStatus(String stat) {
setStatus(stat, false);
}
void setStatus(String stat, boolean slow) {
statusMessage = stat;
if (slow) statusCount = 200;
else statusCount = 20;
}
/******************* KEYBOARD *******************/
void keyPressed() {
in.keyPressed(key, keyCode);
/*if (newSearch) {
if (keyCode == ENTER) {
newSearch = false;
setStatus("Searching...");
return;
}
if (keyCode == BACKSPACE && searchString.length() > 0) {
searchString = searchString.substring(0, searchString.length()-1);
}
if (((key>='a')&&(key<='z')) || ((key>='0')&&(key<='9')) || key==' ') {
searchString += key;
}
setStatus("Search: " + searchString, true);
return;
}*/
}
void loadCachedSearches() {
searches = new ArrayList();
images = new HashMap<String, String[]>();
File file = new File(sketchPath + "/cache");
if (file.isDirectory()) {
String names[] = file.list();
for (int i = 0; i < names.length; i++) {
if (!names[i].substring(0, 1).equals(".")) {
File subdir = new File(sketchPath + "/cache/" + names[i]);
if (subdir.isDirectory()) {
searches.add(names[i]);
images.put(names[i], subdir.list());
}
}
}
}
search = (String)searches.get(0);
println(images);
println(searches);
}
void fillBuffer() {
attempt = 0;
lastBuffer = 0;
filling = true;
}
PImage img;
PImage cp;
void updateBuffer() {
//search = (String)searches.get(currentSearch);
String[] ims = images.get(search);
if (lastBuffer >= ims.length) {
t.bufferSize = ims.length;
lastBuffer = 0;
filling = false;
ready = true;
}
if (!filling) return;
while (true) {
attempt++;
String fname = "cache/" + search + "/" + ims[lastBuffer];
img = loadImage(fname);
if (img != null) {
buffer[lastBuffer] = img;
cp = img.get();
cp.filter(GRAY);
grays[lastBuffer] = cp;
println("Found " + fname);
lastBuffer++;
return;
}
}
}
void randomizeBuffer() {
for (int i = 0; i < 32; i++) {
int rs = (int)random(searches.size());
String search = (String)searches.get(rs);
String[] ims = images.get(search);
int ri = (int)random(ims.length);
String fname = "cache/" + search + "/" + ims[ri];
img = loadImage(fname);
if (img != null) {
buffer[i] = img;
cp = img.get();
cp.filter(GRAY);
grays[i] = cp;
println("Randomized " + fname);
}
}
t.bufferSize = 32;
}
void exportGif() {
gifExport = new GifMaker(this, "test.gif");
gifExport.setRepeat(0);
framesToExport = t.loopSize;
}
void noteOn(int channel, int pitch, int velocity) {
in.noteOn(channel, pitch, velocity);
println();
println("Note On:");
println("--------");
println("Channel:"+channel);
println("Pitch:"+pitch);
println("Velocity:"+velocity);
}
void noteOff(int channel, int pitch, int velocity) {
in.noteOn(channel, pitch, velocity);
// Receive a noteOff
println();
println("Note Off:");
println("--------");
println("Channel:"+channel);
println("Pitch:"+pitch);
println("Velocity:"+velocity);
}
void controllerChange(int channel, int number, int value) {
in.controllerChange(channel, number, value);
// Receive a controllerChange
println();
println("Controller Change:");
println("--------");
println("Channel:"+channel);
println("Number:"+number);
println("Value:"+value);
}