-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFixture.pde
530 lines (465 loc) · 14.8 KB
/
Fixture.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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
/**
* ##copyright##
* See LICENSE.md
*
* @author Maxime Damecour (http://nnvtn.ca)
* @version 0.4
* @since 2016-06-10
*/
// DMX fixture objects
class Fixture {
String name;
String description;
int address;
int channelCount;
byte[] buffer;
// position on the canvas;
PVector position;
ArrayList<Fixture> subFixtures;
public Fixture(int _adr) {
name = "genericFixture";
description = "describe fixture";
address = _adr;
channelCount = 3;
buffer = new byte[channelCount];
position = new PVector(0,0);
}
// to override
public void parseGraphics(PGraphics _pg) {
}
// to override
void drawFixtureOverlay(PGraphics _pg) {
}
public void bufferChannels(byte[] _buff) {
for(int i = 0; i < channelCount; i++) {
// println(address+i+" -> "+int(buffer[i]));
if(address+i < _buff.length) _buff[address+i] = buffer[i];
}
}
void setPosition(int _x, int _y) {
position.set(_x, _y);
}
void setChannelManual(int _chan, int _val) {
int _c = _chan - address;
if(_c < channelCount && _c >= 0) buffer[_c] = byte(_val);
}
int getAddress() {
return address;
}
String getName() {
return name;
}
String getDescription() {
return description;
}
PVector getPosition() {
return position.get();
}
ArrayList<Fixture> getSubFixtures() {
return subFixtures;
}
}
////////////////////////////////////////////////////////////////////////////////////
///////
/////// Strip
///////
////////////////////////////////////////////////////////////////////////////////////
// class for RGB ledStrips
class RGBStrip extends Fixture {
int ledCount;
int ledChannels;
public RGBStrip(int _adr, int _cnt, int _ax, int _ay, int _bx, int _by) {
super(_adr);
name = "RGBStrip";
description = "A series of RGBFixtures";
ledCount = _cnt;
ledChannels = 3;
channelCount = ledCount * ledChannels;
buffer = new byte[channelCount];
position = new PVector(_ax, _ay);
subFixtures = new ArrayList<Fixture>();
addRGBFixtures(ledCount, _ax, _ay, _bx, _by);
}
protected void addRGBFixtures(int _cnt, float _ax, float _ay, float _bx, float _by) {
float gap = 1.0/(_cnt-1);
int ind;
int x;
int y;
RGBFixture _fix;
int _adr = 0;
for(int i = 0; i < _cnt; i++) {
ind = int(lerp(0, _cnt, i*gap));
x = int(lerp(_ax, _bx, i*gap));
y = int(lerp(_ay, _by, i*gap));
// _fix = new RGBFixture(address+(i*ledChannels));
_adr = i*ledChannels;
_adr += address;
_fix = new RGBFixture(_adr);//address+(i*ledChannels));
_fix.setPosition(x,y);
subFixtures.add(_fix);
// println(ledChannels+" "+i+" "+address+" "+_adr);
}
// }
}
public void parseGraphics(PGraphics _pg) {
for(Fixture _fix : subFixtures)
_fix.parseGraphics(_pg);
}
// override
void drawFixtureOverlay(PGraphics _pg) {
for(Fixture _fix : subFixtures)
_fix.drawFixtureOverlay(_pg);
}
public void bufferChannels(byte[] _buff) {
for(Fixture _fix : subFixtures)
_fix.bufferChannels(_buff);
}
}
// class for RGB ledStrips
class RGBWStrip extends RGBStrip {
public RGBWStrip(int _adr, int _cnt, int _ax, int _ay, int _bx, int _by) {
super(_adr, _cnt, _ax, _ay, _bx, _by);
name = "RGBWStrip";
description = "A series of RGBFixtures";
ledCount = _cnt;
ledChannels = 4;
channelCount = ledCount * ledChannels;
buffer = new byte[channelCount];
position = new PVector(_ax, _ay);
subFixtures = new ArrayList<Fixture>();
addRGBFixtures(ledCount, _ax, _ay, _bx, _by);
}
}
////////////////////////////////////////////////////////////////////////////////////
///////
/////// RGBFixture
///////
////////////////////////////////////////////////////////////////////////////////////
// a base class for RGB fixture.
class RGBFixture extends Fixture {
boolean correctGamma = true;
color col;
public RGBFixture(int _adr) {
super(_adr);
name = "RGBFixture";
description = "a RGB light fixture";
channelCount = 3;
address = _adr;
buffer = new byte[channelCount];
position = new PVector(0,0);
}
// override
public void parseGraphics(PGraphics _pg) {
if(_pg == null) return;
int ind = int(position.x + (position.y*_pg.width));
int max = _pg.width*_pg.height;
if(ind < max) setColor(_pg.pixels[ind]);
}
// override
void drawFixtureOverlay(PGraphics _pg) {
if(_pg == null) return;
_pg.stroke(255, 100);
_pg.noFill();
_pg.ellipseMode(CENTER);
_pg.ellipse(position.x, position.y, 10, 10);
_pg.textSize(10);
_pg.fill(255);
_pg.text(str(address), position.x, position.y);
}
// RGBFixture specific
public void setColor(color _c) {
col = _c;
int red = (col >> 16) & 0xFF;
int green = (col >> 8) & 0xFF;
int blue = col & 0xFF;
buffer[0] = byte(correctGamma ? red : gammatable[red]);
buffer[1] = byte(correctGamma ? green : gammatable[green]);
buffer[2] = byte(correctGamma ? blue : gammatable[blue]);
// println(buffer[0]+" "+buffer[1]+" "+buffer[2]);
}
public color getColor() {
return col;
}
public int getX() {
return int(position.x);
}
public int getY() {
return int(position.y);
}
}
// for other light channels
class ColorFlexWAUV extends RGBFixture {
public ColorFlexWAUV(int _adr) {
super(_adr);
name = "ColorFlexUVW";
description = "fixture for uv and whites for Neto ColorFlex";
channelCount = 3;
address = _adr;
buffer = new byte[channelCount];
position = new PVector(0,0);
}
public void bufferChannels(byte[] _buff) {
for(int i = 0; i < channelCount; i++) {
_buff[address+i+3] = buffer[i];
// println(address+i+" -> "+int(buffer[i]));
}
}
}
///////////////////////////////////////////////////////
// a base class for RGB fixture.
class RGBPar extends Fixture {
boolean correctGamma = true;
color col;
public RGBPar(int _adr) {
super(_adr);
name = "RGBAWPar";
description = "a RGB light fixture";
channelCount = 3;
address = _adr;
buffer = new byte[channelCount];
position = new PVector(0,0);
}
public void parseGraphics(PGraphics _pg) {
if(_pg == null) return;
int ind = int(position.x + (position.y*_pg.width));
int max = _pg.width*_pg.height;
if(ind < max) setColor(_pg.pixels[ind]);
}
// RGBFixture specific
public void setColor(color _c) {
col = _c;
int red = (col >> 16) & 0xFF;
int green = (col >> 8) & 0xFF;
int blue = col & 0xFF;
buffer[0] = byte(correctGamma ? red : gammatable[red]);
buffer[1] = byte(correctGamma ? green : gammatable[green]);
buffer[2] = byte(correctGamma ? blue : gammatable[blue]);
}
// override
void drawFixtureOverlay(PGraphics _pg) {
if(_pg == null) return;
_pg.stroke(255, 100);
_pg.noFill();
_pg.ellipseMode(CENTER);
_pg.ellipse(position.x, position.y, 10, 10);
_pg.textSize(10);
_pg.fill(255);
_pg.text(str(address), position.x, position.y);
}
}
class AWPar extends Fixture {
boolean correctGamma = true;
color col;
public AWPar(int _adr) {
super(_adr);
name = "AWPar";
description = "a RGB light fixture";
channelCount = 2;
address = _adr;
buffer = new byte[channelCount];
position = new PVector(0,0);
}
public void parseGraphics(PGraphics _pg) {
if(_pg == null) return;
int ind = int(position.x + (position.y*_pg.width));
int max = _pg.width*_pg.height;
if(ind < max) setColor(_pg.pixels[ind]);
}
// RGBFixture specific
public void setColor(color _c) {
col = _c;
int red = (col >> 16) & 0xFF;
int green = (col >> 8) & 0xFF;
// int blue = col & 0xFF;
buffer[0] = byte(correctGamma ? red : gammatable[red]);
buffer[1] = byte(correctGamma ? green : gammatable[green]);
// buffer[2] = byte(correctGamma ? blue : gammatable[blue]);
}
// override
void drawFixtureOverlay(PGraphics _pg) {
if(_pg == null) return;
_pg.stroke(255, 100);
_pg.noFill();
_pg.ellipseMode(CENTER);
_pg.ellipse(position.x, position.y, 10, 10);
_pg.textSize(10);
_pg.fill(255);
_pg.text(str(address), position.x, position.y);
}
}
///////////////////////////////////////////////////////////////////////////////////
///////
/////// `Mp`anel
///////
////////////////////////////////////////////////////////////////////////////////////
// class for RGB ledStrips
class MPanel extends Fixture {
final int PAN_CHANNEL = 0;
final int TILT_CHANNEL = 2;
final int MPANEL_SIZE = 160;
public MPanel(int _adr, int _x, int _y) {
super(_adr);
name = "MPanel";
description = "Neto's crazy MPanel fixture";
channelCount = 121;
address = _adr;
buffer = new byte[channelCount];
position = new PVector(_x, _y);
subFixtures = new ArrayList<Fixture>();
addMatrix();
}
private void addMatrix() {
RGBWStrip _fix;
int _gap = MPANEL_SIZE/5;
int _adr = 0;
for(int i = 0; i < 5; i++) {
_adr = address+20+(i*20);
_fix = new RGBWStrip(_adr, 5, int(position.x), int(position.y+(i*_gap)), int(position.x)+MPANEL_SIZE, int(position.y+(i*_gap)));
subFixtures.add(_fix);
}
}
public void parseGraphics(PGraphics _pg) {
for(Fixture _fix : subFixtures)
_fix.parseGraphics(_pg);
}
// override
void drawFixtureOverlay(PGraphics _pg) {
for(Fixture _fix : subFixtures)
_fix.drawFixtureOverlay(_pg);
}
public void bufferChannels(byte[] _buff) {
for(int i = 0; i < channelCount; i++) {
_buff[address+i] = buffer[i];
}
mpanelRules();
for(Fixture _fix : subFixtures)
_fix.bufferChannels(_buff);
}
public void mpanelRules() {
// buffer[0] = byte(map(mouseX, 0, width, 0, 255));
// buffer[2] = byte(map(mouseY, 0, height, 0, 255));
buffer[1] = byte(127);
buffer[15] = byte(255);
// println("tilt "+int(buffer[TILT_CHANNEL]));
// buffer[19] = byte(255);
// buffer[118] = byte(255);
//
// buffer[118] = byte(255);
// buffer[119] = byte(255);
}
}
///////////////////////////////////////////////////////////////////////////////////
///////
/////// Neto PAR5
///////
////////////////////////////////////////////////////////////////////////////////////
class NetoParFive extends Fixture {
boolean correctGamma = true;
color col;
public NetoParFive(int _adr) {
super(_adr);
name = "NetoPAR5";
description = "a fixture for the Neto PAR5";
channelCount = 9;
address = _adr;
buffer = new byte[channelCount];
position = new PVector(0,0);
}
public void parseGraphics(PGraphics _pg) {
if(_pg == null) return;
int ind = int(position.x + (position.y*_pg.width));
int max = _pg.width*_pg.height;
if(ind < max) setColor(_pg.pixels[ind]);
}
// RGBFixture specific
public void setColor(color _c) {
col = _c;
int red = (col >> 16) & 0xFF;
int green = (col >> 8) & 0xFF;
int blue = col & 0xFF;
buffer[0] = byte(255);
if(red == green && green == blue) {
buffer[1] = 0;
buffer[2] = 0;
buffer[3] = 0;
buffer[4] = byte(correctGamma ? red : gammatable[red]);
} else {
buffer[1] = byte(correctGamma ? red : gammatable[red]);
buffer[2] = byte(correctGamma ? green : gammatable[green]);
buffer[3] = byte(correctGamma ? blue : gammatable[blue]);
buffer[4] = 0;
}
}
// override
void drawFixtureOverlay(PGraphics _pg) {
if(_pg == null) return;
_pg.stroke(255, 100);
_pg.noFill();
_pg.ellipseMode(CENTER);
_pg.ellipse(position.x, position.y, 20, 20);
_pg.textSize(10);
_pg.fill(255);
_pg.text(str(address), position.x, position.y);
}
}
///////////////////////////////////////////////////////////////////////////////////
///////
/////// WS2812 8X32 zigzag
///////
////////////////////////////////////////////////////////////////////////////////////
class ZigZagMatrix extends Fixture {
boolean correctGamma = true;
color col;
int matrixSpacing = 16;
int matrixWidth = 0;
int matrixHeight = 0;
public ZigZagMatrix(int _adr, int _width, int _height, int _spacing) {
super(_adr);
name = "ZigZagMatrix";
description = "a ZigZagMatrix of RGB pixels";
channelCount = _width * _height;
address = _adr;
matrixWidth = _width;
matrixHeight = _height;
matrixSpacing = _spacing;
buffer = new byte[channelCount];
position = new PVector(0,0);
subFixtures = new ArrayList<Fixture>();
}
public void init(){
addMatrix();
}
private void addMatrix() {
RGBFixture _fix;
int _gap = matrixSpacing;
int _adr = 0;
PVector _start = new PVector(0,0);
PVector _end = new PVector(0,0);
for(int i = 0; i < matrixWidth; i++) {
for(int j = 0; j < matrixHeight; j++) {
_adr = address+(i*matrixHeight*3 + j*3);
_fix = new RGBFixture(_adr);
if(i % 2 == 1){
_fix.setPosition(int(position.x + i* _gap), int(position.y + matrixHeight*_gap - _gap - j* _gap));
}
else {
_fix.setPosition(int(position.x + i* _gap), int(position.y + j* _gap));
}
subFixtures.add(_fix);
}
}
}
public void parseGraphics(PGraphics _pg) {
for(Fixture _fix : subFixtures)
_fix.parseGraphics(_pg);
}
// override
void drawFixtureOverlay(PGraphics _pg) {
for(Fixture _fix : subFixtures)
_fix.drawFixtureOverlay(_pg);
}
public void bufferChannels(byte[] _buff) {
for(Fixture _fix : subFixtures)
_fix.bufferChannels(_buff);
}
}