Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 257 lines (187 sloc) 5.797 kB
4670ee1 forst commit
Johan authored
1 /*
2 Johan Bichel Lindegaard
3 http://johan.cc
4 2011
5
6 Lightmaxx par 64
7 Channels:
8 1: Red [ 0 - 255]
9 2: Green [ 0 - 255 ]
10 3: Blue [ 0 - 255 ]
11 4: Dimmer [ 000 - 189 dimmer ] [ 190 - 250 Flash]
12
13 */
14
15 import ddf.minim.analysis.*;
16 import ddf.minim.*;
17
18 Minim minim;
19 AudioInput in;
20 FFT fft;
21
7231d78 Added color pickers.
Johan authored
22 int[] peakColor = new int[3];
23 int[] normalColor = new int[3];
24
4670ee1 forst commit
Johan authored
25 import processing.serial.*; // Import Serial library to talk to Arduino
26 import processing.opengl.*; // Import OpenGL to draw a gradient window
27
28 Serial myPort;
29
30 int group_num = 3; // number of lamp groups
31 int[] lampGroups = {1, 130, 20}; // DMX addresses for lamp groups
32 int[] groupsMin = {20,800,5000}; // minimum threshold for lamp groups in Hz
33 int[] groupsMax = {50,2500,8000}; // maximum threshold for lamp groups in Hz
34
35 float[] avgs = new float[group_num];
36 float[] avgsMax = new float[group_num];
37 float[] avgsMin = new float[group_num];
38 float[] lightValues = new float[group_num];
39
f04c93f Added slew.
Johan authored
40 float slew = 94.999;
41 boolean slewSwitch = true;
42
4670ee1 forst commit
Johan authored
43 boolean autoCalibrate = true;
44
45 public void resetCalibration() {
46 for(int i = 0; i < group_num; i++)
47 {
48 avgsMax[i] = 0.5;
49 avgsMin[i] = 0.1;
50
51 try {
52 updateThresholdInputs(i);
53 } catch (Exception e) {
54 }
55 }
56 }
57
58 void setup() {
59 println(Serial.list()); // shows available serial ports on the system
60
f04c93f Added slew.
Johan authored
61 size(1275,750,OPENGL); // Create a window
4670ee1 forst commit
Johan authored
62 frameRate(30);
63
64 resetCalibration();
65 setupControlInterface();
66
67 // Select the appropriate port as required.
68 String portName = Serial.list()[1];
69 myPort = new Serial(this, portName, 9600);
70
71 minim = new Minim(this);
72 minim.debugOn();
73
74 // get a line in from Minim, default bit depth is 16
75 in = minim.getLineIn(Minim.STEREO, 2048);
76 fft = new FFT(in.bufferSize(), in.sampleRate());
8fdcaea Added another call to dimmer to make it work with plano spots.
Johan authored
77 fft.logAverages(20, 8);
4670ee1 forst commit
Johan authored
78 rectMode(CORNERS);
79
80 // set dim channel to full on all lamp groups
8fdcaea Added another call to dimmer to make it work with plano spots.
Johan authored
81
82 setDmxChannel(4, 255);
83
4670ee1 forst commit
Johan authored
84 for (int g = 0; g < lampGroups.length; g++) {
8fdcaea Added another call to dimmer to make it work with plano spots.
Johan authored
85 setDmxChannel(lampGroups[g] + 3, 155);
4670ee1 forst commit
Johan authored
86 }
87
88 }
89
90 void draw() {
91
92 int w;
93
94 background(0);
95 stroke(255);
96
97 // perform a forward FFT on the samples in jingle's mix buffer
98 // note that if jingle were a MONO file, this would be the same as using jingle.left or jingle.right
99 fft.forward(in.mix);
100
101
f04c93f Added slew.
Johan authored
102 // draw the waveforms
103 for(int i = 0; i < in.bufferSize() - 1; i++)
104 {
105 stroke(30, 30, 250);
106 line(i, height/2 - 50 + in.left.get(i)*50, i+1, height/2 - 50 + in.left.get(i+1)*50);
107 stroke(30, 30, 250);
108 line(i, height/2 + 50 + in.right.get(i)*50, i+1, height/2 + 50 + in.right.get(i+1)*50);
109 }
110
4670ee1 forst commit
Johan authored
111 for(int i = 0; i < group_num; i++)
112 {
113 avgs[i] = fft.calcAvg(groupsMin[i], groupsMax[i]);
114 }
115
116
8fdcaea Added another call to dimmer to make it work with plano spots.
Johan authored
117 w = int(width/60);
118 for(int i = 0; i < 60; i++)
4670ee1 forst commit
Johan authored
119 {
f04c93f Added slew.
Johan authored
120 fill(40);
121 stroke(80);
122 rect(i*w+2, height, i*w + w -2, height - 30 - fft.getAvg(i));
4670ee1 forst commit
Johan authored
123
124 }
125
126 w = int((width/2)/group_num);
f04c93f Added slew.
Johan authored
127
128 fill(0);
129 noStroke();
130 rect(0, height, width, height-30);
131
4670ee1 forst commit
Johan authored
132 for(int i = 0; i < group_num; i++)
133 {
134
135 float m = sqrt(groupsMax[i] - groupsMin[i])/4;
136
137 if (autoCalibrate) {
138 updateThresholdInputs(i);
139 }
140
f04c93f Added slew.
Johan authored
141 fill(100, 100, 220, 200);
142 noStroke();
143 rect(i*w + 2, height-30, i*w + w - 2, height - 30 - avgs[i]*m);
144
4670ee1 forst commit
Johan authored
145
f04c93f Added slew.
Johan authored
146 stroke(0, 255, 255);
147 float mx = height - 30 - avgsMax[i]*m;
148 float mn = height - 30 - avgsMin[i]*m;
149 line(i*w + 2, mx, i*w + w - 2, mx);
150
151 stroke(255, 255, 0);
152 line(i*w + 2, mn, i*w + w - 2, mn);
4670ee1 forst commit
Johan authored
153
154 fill(255);
f04c93f Added slew.
Johan authored
155 text(groupsMin[i] + "Hz - " + groupsMax[i] + "Hz", (i*w) + 10, height-10);
4670ee1 forst commit
Johan authored
156 }
157
158 for (int i = 0; i < avgs.length; i++) {
159
160 if (avgs[i] > avgsMax[i]) {
161 if (autoCalibrate) {
162 avgsMax[i] = avgs[i];
163 } else {
164 avgs[i] = avgsMax[i];
165 }
166 } else if (avgs[i] < avgsMin[i]) {
167 if (autoCalibrate) {
168 avgsMin[i] = avgs[i];
169 } else {
170 avgs[i] = avgsMin[i];
171 }
172 }
f04c93f Added slew.
Johan authored
173
174
175 float mapped = map(avgs[i], avgsMin[i], avgsMax[i], 0, 255);
176
177 if (mapped > lightValues[i]) {
178 lightValues[i] = mapped;
179 }
4670ee1 forst commit
Johan authored
180 }
181
182 w = int((width/2)/group_num);
183
f04c93f Added slew.
Johan authored
184
185 fill(150, 20, 20, 70);
7231d78 Added color pickers.
Johan authored
186
f04c93f Added slew.
Johan authored
187 noStroke();
188 rect(width/2, height-(255*2) + ((255*2)/100*10) - 30, width, height-(255*2)-30);
7231d78 Added color pickers.
Johan authored
189
f04c93f Added slew.
Johan authored
190 for(int i = 0; i < group_num; i++)
191 {
192 noStroke();
193 fill(255, 255, 255, lightValues[i]);
194 rect(i*w + width/2 + 2, height - 30, i*w + w + width/2 - 2, height - 30 - (lightValues[i]*2));
195
196 }
7231d78 Added color pickers.
Johan authored
197
4670ee1 forst commit
Johan authored
198 for(int i = 0; i < group_num; i++)
7231d78 Added color pickers.
Johan authored
199 {
200 int cc = 1;
201 float intensity = 1;
202
4670ee1 forst commit
Johan authored
203 if (lightValues[i]/255*100 > 90) {
7231d78 Added color pickers.
Johan authored
204
205 intensity = alpha(peakCP.getColorValue()) / 255 * lightValues[i];
206 cc = peakCP.getColorValue();
207
4670ee1 forst commit
Johan authored
208 } else if (lightValues[i]/255*100 < 1) {
209
210 } else {
7231d78 Added color pickers.
Johan authored
211
212 intensity = alpha(normalCP.getColorValue()) / 255 * lightValues[i];
213 cc = normalCP.getColorValue();
214
4670ee1 forst commit
Johan authored
215 }
7231d78 Added color pickers.
Johan authored
216 setColor(red(cc), green(cc), blue(cc), i, intensity);
4670ee1 forst commit
Johan authored
217 }
218
f04c93f Added slew.
Johan authored
219 for(int i = 0; i < group_num; i++)
4670ee1 forst commit
Johan authored
220 {
f04c93f Added slew.
Johan authored
221 if (slewSwitch) {
222 lightValues[i] = lightValues[i] * (slew/100);
223 } else {
224 lightValues[i] = 0;
225 }
226 }
227
4670ee1 forst commit
Johan authored
228 }
229
230 void stop()
231 {
232 // always close Minim audio classes when you are done with them
233 in.close();
234 minim.stop();
235 super.stop();
236 }
237
238 boolean overRect(int x, int y, int width, int height) {
239 if (mouseX >= x && mouseX <= x+width &&
240 mouseY >= y && mouseY <= y+height) {
241 return true;
242 } else {
243 return false;
244 }
245 }
246
247 boolean uiThresholdForceUpdate = false;
248
249 void updateThresholdInputs(int i) {
250
251 uiThresholdForceUpdate = true;
252
253 float m = sqrt(groupsMax[i] - groupsMin[i])/8;
254 thresholdRanges[i].setLowValue(avgsMin[i]*m);
255 thresholdRanges[i].setHighValue(avgsMax[i]*m);
256 }
Something went wrong with that request. Please try again.