-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImplementation.pde
137 lines (113 loc) · 3.49 KB
/
Implementation.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
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.Iterator;
import java.util.List;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;
import spout.Spout;
SoundDataProvider provider;
List<SoundInfo> sounds;
int soundIndex;
boolean repeat;
List<ShaderInfo> shaders;
color backgroundColor;
PImage backgroundImage;
boolean onlyInitialization = true;
FrameRecorder recorder;
Spout spout;
boolean isPlaying;
long startTimeMillis;
int framePerSecond;
float msPerFrame;
int startFrameCount;
int frameDropCount;
final class SoundInfo {
final String location;
SoundInfo(String l) {
location = l;
}
}
final class ShaderInfo {
final PShader shader;
boolean disabled;
ShaderInfo(PShader s, boolean d) {
shader = s;
disabled = d;
}
}
FrameRecorder createFrameRecorder(JSONObject setting) {
final JSONObject record = setting.getJSONObject("record");
if (record == null) {
return null;
}
FrameRecorderType recorderType = null;
String imageType = record.getString("imageType");
if (imageType != null) {
imageType = imageType.toLowerCase();
if (imageType.equals("jpeg") || imageType.equals("jpg")) {
recorderType = FrameRecorderType.AsyncRecorder;
}
else if (imageType.equals("tga")) {
recorderType = FrameRecorderType.SyncTgaRecorder;
}
else if (imageType.equals("png")) {
recorderType = FrameRecorderType.SyncPngRecorder;
}
}
if (recorderType == null) {
return null;
}
String recordPath = record.getString("path");
if (recordPath == null || recordPath.length() == 0) {
recordPath = "img";
}
return createFrameRecorderInstanceOf(recorderType, recordPath);
}
List<SoundInfo> loadSounds(JSONArray soundDefinitions) {
List<SoundInfo> sounds = new ArrayList<SoundInfo>();
for (int index = 0; index < soundDefinitions.size(); ++index) {
final JSONObject definition = soundDefinitions.getJSONObject(index);
sounds.add(new SoundInfo(definition.getString("location")));
}
return sounds;
}
void setInitialOptions(final JSONArray options, final PShader shader) {
for (int index = 0; index < options.size(); ++index) {
final JSONObject option = options.getJSONObject(index);
shader.set(option.getString("name"), option.getFloat("value"));
}
}
List<ShaderInfo> loadShaders(JSONArray shaderDefinitions) {
List<ShaderInfo> shaders = new ArrayList<ShaderInfo>();
for (int index = 0; index < shaderDefinitions.size(); ++index) {
final JSONObject definition = shaderDefinitions.getJSONObject(index);
final PShader shader = loadShader(definition.getString("location"));
shader.set("resolution", width, height);
final JSONObject options = definition.getJSONObject("options");
if (options != null) {
final JSONArray initialOptions = options.getJSONArray("initial");
if (initialOptions != null) {
setInitialOptions(initialOptions, shader);
}
}
shaders.add(new ShaderInfo(shader, definition.getBoolean("disabled", false)));
}
return shaders;
}
void initBackground() {
println("initialize background");
background(backgroundColor);
if (backgroundImage != null) {
image(backgroundImage, 0, 0, width, height);
}
}