-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsally_slg.pde
318 lines (253 loc) · 9.34 KB
/
sally_slg.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
import beads.*;
import org.jaudiolibs.beads.AudioServerIO;
// ratio 600/800 = 0.75
boolean developmentMode = true; // false in the gallery!
boolean fullScreen = !developmentMode;
boolean debugTripleheadScreens = false;
float scaler = developmentMode ? 2.5 : 1; // needs to be set to 1 when using 800x600 projectors! Maybe, 1.5 or 2 when testing without external projectors
int projectorWidth = 800/(int)scaler;
int projectorHeight = 600/(int)scaler;
int screenWidth = projectorWidth * 3;
int screenHeight = projectorHeight;
int targetDisplay = 1; // triplehead is the only screen
int alphaFade = 25;
int alphaDuration = 60;
boolean linkImageDurationToSample = true;
boolean debugTimeline = developmentMode;
int blurCounter = 0;
ArrayList<PImage> images1 = new ArrayList<PImage>();
ArrayList<PImage> images2 = new ArrayList<PImage>();
ArrayList<PImage> images3 = new ArrayList<PImage>();
PImage p1Image;
PImage p2Image;
PImage p3Image;
SamplePlayer p1Player;
SamplePlayer p2Player;
SamplePlayer p3Player;
int p1PlayerDuration;
int p2PlayerDuration;
int p3PlayerDuration;
int p1PlayerClearDuration;
int p2PlayerClearDuration;
int p3PlayerClearDuration;
Timeline projector1;
Timeline projector2;
Timeline projector3;
AudioContext audioContext;
IOAudioFormat audioFormat;
float sampleRate = 44100;
int buffer = 512;
int bitDepth = 16;
int inputs = 2;
int outputs = 4;
// PROCESSING
void settings() {
if (fullScreen) {
fullScreen(targetDisplay);
} else {
size(screenWidth, screenHeight);
}
}
void setup() {
background(0);
audioFormat = new IOAudioFormat(sampleRate, bitDepth, inputs, outputs);
audioContext = new AudioContext(new AudioServerIO.Jack(), buffer, audioFormat);
FileUtils.loadImagesInto(images1, sketchPath()+"/data/projector-1/images", this, screenWidth/3, screenHeight);
FileUtils.loadImagesInto(images2, sketchPath()+"/data/projector-2/images", this, screenWidth/3, screenHeight);
FileUtils.loadImagesInto(images3, sketchPath()+"/data/projector-3/images", this, screenWidth/3, screenHeight);
SampleManager.group("projector-1", FileUtils.loadSounds(sketchPath()+"/data/projector-1/sounds"));
SampleManager.group("projector-2", FileUtils.loadSounds(sketchPath()+"/data/projector-2/sounds"));
SampleManager.group("projector-3", FileUtils.loadSounds(sketchPath()+"/data/projector-3/sounds"));
projector1 = new Timeline(Config.timeline1, new TimelineRenderer(0, 0) {
public void action() {
int chance = getChance();
if (chance > (100 - Config.likelihood)) {
if (debugTimeline) println("!!!! Projector 1 fire");
p1PlayerClearDuration = calculateClearDuration();
projector1.keepImageForFramesCount = 0;
stopSampleFor(p1Player);
p1Image = images1.get((int)random(images1.size()));
Sample sample = SampleManager.randomFromGroup("projector-1");
p1Player = new SamplePlayer(audioContext, sample);
// tint(random(255), random(255), random(255), random(255));
noStroke();
image(p1Image, this.xpos, this.ypos);
int channel = 0; // OUT 1
Gain g = new Gain(audioContext, 2, Config.globalGain);
g.addInput(p1Player);
float reverbDuration = randomReverb(audioContext, g, channel);
int sampleDuration = calculateDuration(sample);
p1PlayerDuration = sampleDuration + (int) (reverbDuration * frameRate);
//println(reverbDuration+ " | "+sampleDuration+ " | "+p1PlayerDuration);
audioContext.out.addInput(channel, g, 0);
audioContext.start();
}
}
public void clear() {
//print(projector1.keepImageForFramesCount+" | "); print(p1PlayerDuration+" | "); print(p1PlayerClearDuration);
//println("");
if (projector1.keepImageForFramesCount < p1PlayerDuration) {
// keep visible
} else {
if (p1PlayerClearDuration > 0) {
//stroke(204, 102, 0);
fill(0, 0, 0, alphaFade);
rect(this.xpos, this.ypos, projectorWidth, projectorHeight);
p1PlayerClearDuration--;
}
}
}
});
projector2 = new Timeline(Config.timeline2, new TimelineRenderer(projectorWidth, 0) {
public void action() {
int chance = getChance();
if (chance > (100 - Config.likelihood)) {
if (debugTimeline) println("!!!! Projector 2 fire");
p2PlayerClearDuration = calculateClearDuration();
projector2.keepImageForFramesCount = 0;
stopSampleFor(p1Player);
p2Image = images2.get((int)random(images2.size()));
Sample sample = SampleManager.randomFromGroup("projector-2");
p2PlayerDuration = calculateDuration(sample);
p2Player = new SamplePlayer(audioContext, sample);
noStroke();
image(p2Image, this.xpos, this.ypos);
int channel = 1; // OUT 2
Gain g = new Gain(audioContext, 2, Config.globalGain);
g.addInput(p2Player);
float reverbDuration = randomReverb(audioContext, g, channel);
int sampleDuration = calculateDuration(sample);
p2PlayerDuration = sampleDuration + (int) (reverbDuration * frameRate);
audioContext.out.addInput(channel, g, 0);
audioContext.start();
}
}
public void clear() {
if (projector2.keepImageForFramesCount < p2PlayerDuration) {
// keep visible
} else {
if (p2PlayerClearDuration > 0) {
//stroke(50, 102, 0);
fill(0, 0, 0, alphaFade);
rect(this.xpos, this.ypos, projectorWidth, projectorHeight);
p2PlayerClearDuration--;
}
}
}
});
projector3 = new Timeline(Config.timeline3, new TimelineRenderer(projectorWidth*2, 0) {
public void action() {
int chance = getChance();
if (chance > (100 - Config.likelihood)) {
if (debugTimeline) println("!!!! Projector 3 fire");
p3PlayerClearDuration = calculateClearDuration();
projector3.keepImageForFramesCount = 0;
if (p3Player != null) {
p3Player.setToEnd(); // stop anything still playing
}
p3Image = images3.get((int)random(images3.size()));
Sample sample = SampleManager.randomFromGroup("projector-3");
p3PlayerDuration = calculateDuration(sample);
p3Player = new SamplePlayer(audioContext, sample);
noStroke();
image(p3Image, this.xpos, this.ypos);
int channel = developmentMode ? 1 : 2; // OUT 3
Gain g = new Gain(audioContext, 2, Config.globalGain);
g.addInput(p3Player);
float reverbDuration = randomReverb(audioContext, g, channel);
int sampleDuration = calculateDuration(sample);
p3PlayerDuration = sampleDuration + (int) (reverbDuration * frameRate);
audioContext.out.addInput(channel, g, 0);
audioContext.start();
}
}
public void clear() {
//print(projector3.keepImageForFramesCount+" | "); print(p3PlayerDuration+" | "); print(p3PlayerClearDuration);
//println("");
if (projector3.keepImageForFramesCount < p3PlayerDuration) {
// keep visible
} else {
if (p3PlayerClearDuration > 0) {
//stroke(255);
fill(0, 0, 0, alphaFade);
rect(this.xpos, this.ypos, projectorWidth, projectorHeight);
p3PlayerClearDuration--;
}
}
}
});
}
void draw() {
if (debugTimeline) {
print((int)frameRate+"\t"); print(projector1); print(projector2); print(projector3);
print("\t\t"+blurCounter+"\t >"+Config.blurFromFrame+"<"+Config.blurUntilFrame);
println("");
}
if (debugTripleheadScreens) {
noStroke();
fill(255, 0, 0);
rect(0, 0, projectorWidth, projectorHeight);
fill(0, 255, 0);
rect(projectorWidth, 0, projectorWidth, projectorHeight);
fill(0, 0, 255);
rect(projectorWidth*2, 0, projectorWidth, projectorHeight);
} else {
projector1.draw();
projector2.draw();
projector3.draw();
}
checkWhetherToBlurImages();
}
// UTILS
int getChance() {
int chance = 100;
if (Config.enableProbability) {
chance = (int) random(1, 100);
}
return chance;
}
void checkWhetherToBlurImages() {
if (blurCounter >= Config.blurUntilFrame) {
blurCounter = 0;
} else if (blurCounter >= Config.blurFromFrame) {
if (debugTimeline) println("############### BLURING! ");
filter(BLUR, 2);
blurCounter++;
} else {
blurCounter++;
}
}
int calculateDuration(Sample sample) {
int duration = Config.keepImageForFrames;
if (linkImageDurationToSample) {
duration = (int) ((sample.getLength()/1000) * frameRate);
}
return duration;
}
int calculateClearDuration() {
int duration = alphaDuration;
return duration;
}
void stopSampleFor(SamplePlayer player) {
audioContext.out.clearInputConnections();
if (player != null) {
player.setToEnd();
}
}
float randomReverb(AudioContext ac, Gain gain, int channel) {
float reverbDuration = 0.0;
if (getChance() > (100 - Config.reverbLikelihood)) {
Reverb reverb = new Reverb(audioContext, 1);
float maxReverbSeconds = 3.0;
float reverbSize = random(0.0, 1.0);
reverbDuration = map(reverbSize, 0.0, 1.0, 0.0, maxReverbSeconds);
reverb.setSize(reverbSize);
reverb.setDamping(random(0.3, 1.0));
reverb.addInput(gain);
audioContext.out.addInput(channel, reverb, 0);
}
return reverbDuration;
}
// INTERACTIONS
void mousePressed() {
}