-
Notifications
You must be signed in to change notification settings - Fork 0
/
FourDV7.pde
1690 lines (1465 loc) · 44.1 KB
/
FourDV7.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
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
18
20
6,5
7,4,1
8,3,2,17,16
9,12
10,11,19
13,14,15
*/
/**************************************************************
* POWDERLY - NASA FACTORY - URBANTAINER *
* Octagon Lounge Lighting System Control S/W V0.1 *
* 2011 - 2013 *
* No Rights Reserved *
***************************************************************/
//using the entec DMX Pro
//on OSX 10.7 Lion
//install the ftdi USD driver
//and unlock the port using these commands
//sudo mkdir -p /var/lock
//sudo chmod 777 /var/lock
/********************************************************************************** LIBRARIES
*/
//IMPORT LIBRARIES
//DMX CONTROL LIBRARIES
import dmxP512.*; //DMX Libraries
import processing.serial.*; // Serial control library for DMX
//GUI ELEMENTS LIBRARIY
import controlP5.*;
//COLOR/GRADIENT LIBRARIES
import colorLib.calculation.*;
import colorLib.*;
import colorLib.webServices.*;
//SOUND LIBRARY
import ddf.minim.*; //sound input
import ddf.minim.analysis.*; //FFT analysis for the beat detection
//color wheel class
ColorPicker cp;
/************************************************************************************ VARIABLES
*/
//SOUND RELATED VARIABLES
private static final long serialVersionUID = 5454L;
int config_SAMPLERATE = 44100; //important var
int config_BUFFERSIZE = 512; //important var
int config_BPM = 140; //fine tune this var
int config_FFT_BAND_PER_OCT = 12;
int config_FFT_BASE_FREQ = 55;
private boolean scaleEq = true;
public boolean onBeat = false;
public boolean oscOnBeat = false;
public boolean autoBeatSense = true;
public float beatSense = 8;
public float beatSenseSense = 1;
private long lastbeatTimestamp = 0;
private float level = 0;
private float leveldB = -100;
private int lastBand = 0;
private int lastBandCount = 0;
private int nbAverage = config_SAMPLERATE / config_BUFFERSIZE * 2; // one second
private float modulationSmooth = 0.30f;
private int nbAverageLongTerm = 8 * config_SAMPLERATE / config_BUFFERSIZE;
private int nbAverageShortTerm = config_SAMPLERATE / config_BUFFERSIZE / 3;
// skip beat for a quarter of beat
private int repeatDelay = (int) ((60f / config_BPM / 4f) * (config_SAMPLERATE / config_BUFFERSIZE));
private FFT fft;
private AudioInput input;
// private int bufferSize;
private Minim minim;
// private boolean localOnBeat = false;
private int playhead = 0;
private int playheadShortTerm = 0;
private int playheadLongTerm = 0;
private int skipFrames = 0;
public int numZones = 0;
public boolean zoneEnabled[];
private float score2 = 0;
// private float avg=0;
private float modulation = 0;
private float[][] zoneEnergy;
private float[][] zoneEnergyShortTerm;
private float[][] zoneScore;
private float[] score = new float[nbAverage];
private float[] scoreLongTerm = new float[nbAverageLongTerm];
private float[] zoneEnergyVuMeter;
private float[] zoneEnergyPeak;
private int[] zoneEnergyPeakHoldTimes;
private int peakHoldTime = 30; // hold longer
private float peakDecayRate = 0.98f; // decay slower
private float linearEQIntercept = 0.8f; // reduced gain at lowest frequency
private float linearEQSlope = 0.2f; // increasing gain at higher frequencies
//our beat boolean *VERY IMPORTANT*
boolean gotBeat = false;
//DMX OBJECTS AND LED DATA
DmxP512 dmxOutput;
boolean LANBOX=false;
boolean DMXPRO=true;
//THIS IS MY USB PORT BUT YOU WILL SEE YOURS LISTED IN THE DEBUG WINDOW ON STARTUP
String DMXPRO_PORT="/dev/tty.usbserial-EN093272";//case matters ! on windows port must be upper cased.
int DMXPRO_BAUDRATE=115000;
//THE LIGHTING SYSTEM VARIABLES AND DATA STRUCTURES
int universeSize=400;
int stripNum = 80;
int unitNum = 20;
int _SQUARE = 0;
int _OCTAGON = 1;
int[] DMXarray = new int[universeSize];
ArrayList strips;
ArrayList units;
ArrayList locs;
//test value I forget what this is...
PVector v1 = new PVector(40, 20);
//INTERFACE BOOLEANS TO TOGGLE DIFFERENT UI MODES
boolean shiftPressed = false; //to hide/unihide (on rollover and keydown) the DMX output value monitor for each unit
boolean spacePressed = false; //To hide/unhide the master on/of checkboxes
boolean beatMode = false; //toggle to beat-reactive mode
boolean diagMode = false; // toggle to diagnostic mode to test each light
boolean waveTog = false;
boolean dessertMode = false;
boolean colorPickerMode = false;
//diag GUI controls for diagnostic
ControlP5 cp5;
ControlP5 ss1; // object for just the master speed
ControlP5 buttons;
controlP5.Button b;
int buttonValue = 1;
//diag GUI element variables
//Sliders for color and speed
int EdgeRed=0;
int EdgeBlue = 0;
int EdgeGreen = 0;
int EdgeSpeed = 0;
int DownwardRed=0;
int DownwardBlue = 0;
int DownwardGreen = 0;
int DownwardSpeed = 0;
int ReflectiveRed=0;
int ReflectiveBlue=0;
int ReflectiveGreen=0;
int ReflectiveSpeed = 0;
int StripeRed=0;
int StripeBlue = 0;
int StripeGreen = 0;
int StripeSpeed = 0;
// master speed slider experiment
int MasterSpeed = 0;
int Activity = 5;
//checkboxes for mask and direction
CheckBox EdgeCheckBox;
CheckBox EdgeMode;
CheckBox DownwardCheckBox;
CheckBox DownwardMode;
CheckBox ReflectiveCheckBox;
CheckBox ReflectiveMode;
CheckBox StripeCheckBox;
CheckBox StripeMode;
CheckBox allToggle;
CheckBox manualColorMode;
//LIGHTING UNIT AND LED STRIP SPECIFIC INFORMATION
//THIS IS THE ARRAY THAT HOLDS THE MASTER LIST OF STRIPE SUBSTRIPS FOR THE OCTAGON STAGE
int[] subStripArray = {
1, 1, 2, 2, 3,
2, 1, 2, 2, 2,
2, 1, 0, 2, 2,
2, 1, 2, 1, 2,
};
//THIS IS THE ARRAY THAT HOLDS THE MASTER LIST OF TYPES FOR THE OCTAGON STAGE
int[] typeArray = {
_OCTAGON, _SQUARE, _OCTAGON, _SQUARE, _OCTAGON,
_OCTAGON, _SQUARE, _OCTAGON, _SQUARE, _OCTAGON,
_OCTAGON, _OCTAGON, _SQUARE, _OCTAGON, _OCTAGON,
_SQUARE, _OCTAGON, _OCTAGON, _SQUARE, _OCTAGON
};
//THIS IS THE MASK FOR CONTROLLING UP TO 8 SUB-STRIPS ON ANY FACE
int mask0 = 0;
int mask1 = 1;
int mask2 = 2;
int mask3 = 4;
int mask4 = 8;
int mask5 = 16;
int mask6 = 32;
int mask7 = 64;
int mask8 = 128;
//COLOR RELATED VARIABLES AND OBJECTS
//COLOR PALETTES AND GRADIENTS
Palette whiteBlack;
Gradient fade1;
ArrayList Palettes;
ArrayList Gradients;
Palette startPalette;
Gradient startGradient;
Palette sp;
int colorNum = 5;
boolean skip = false;
int step = 0;
color manualColor;
//THE FONT. THE GODDAMN FONT
PFont sysFont;
//TIMER VARIABLES
int startTime;
PVector eTime;
//AUDIO DELAY TIMER VARIABLE
int delay=0;
int waveTimer=0;
int moveTime = 30;
int directionTog = 1;
int fadeDir = 1;
int testVal=0;
/********************************************************************************************** THE SETUP
*/
//SET IT UP HACKA
void setup() {
//STAGE SIZE
size(1440, 900, P2D);
//DMX CONSTRUCTOR
dmxOutput=new DmxP512(this, universeSize, true);
pGenerate();
ss1 = new ControlP5(this);
ss1.addSlider("MasterSpeed")
.setPosition(400, 60)
.setRange(1, 50)
;
ss1.addSlider("Activity")
.setPosition(400, 70)
.setRange(30, 0)
.setNumberOfTickMarks(30)
;
allToggle = ss1.addCheckBox("All Toggle")
.setPosition(600, 70)
.setColorForeground(color(120))
.setColorActive(color(255))
.setColorLabel(color(255))
.setSize(10, 10)
.setItemsPerRow(4)
.setSpacingColumn(100)
// .setSpacingRow(20)
.addItem("stripe", 1)
.addItem("edge", 1)
.addItem("downward", 1)
.addItem("reflective", 1)
;
//initialize the Diagnostic Mode GUI ELements
cp5 = new ControlP5(this);
/*EDGE*/
//red slider for the edge face
cp5.addSlider("EdgeRed")
.setPosition(10, 250)
.setRange(0, 255)
;
//checkboxes for the edge face
EdgeCheckBox = cp5.addCheckBox("EdgeMaskCheck")
.setPosition(200, 250)
.setColorForeground(color(120))
.setColorActive(color(255))
.setColorLabel(color(255))
.setSize(10, 10)
.setItemsPerRow(8)
.setSpacingColumn(25)
// .setSpacingRow(20)
.addItem("e1", mask1)
.addItem("e2", mask2)
.addItem("e4", mask3)
.addItem("e8", mask4)
.addItem("e16", mask5)
.addItem("e32", mask6)
.addItem("e64", mask7)
.addItem("e128", mask8)
;
//green slider for the edge face
cp5.addSlider("EdgeGreen")
.setPosition(10, 260)
.setRange(0, 255)
;
//blue slider for the edge face
cp5.addSlider("EdgeBlue")
.setPosition(10, 270)
.setRange(0, 255)
;
//edge face speed checkboxes
cp5.addSlider("EdgeSpeed")
.setPosition(10, 280)
.setRange(0, 50)
;
//edge face mode check boxes
EdgeMode = cp5.addCheckBox("EdgeModeCheck")
.setPosition(200, 280)
.setColorForeground(color(120))
.setColorActive(color(255))
.setColorLabel(color(255))
.setSize(10, 10)
.setItemsPerRow(8)
.setSpacingColumn(25)
// .setSpacingRow(20)
.addItem("eDot", 1)
.addItem("eDirection", 127)
;
/*DOWNWARD*/
//red slider for downward face
cp5.addSlider("DownwardRed")
.setPosition(10, 300)
.setRange(0, 255)
;
//checkboxes for the mask of downward face
DownwardCheckBox = cp5.addCheckBox("DownwardMaskCheck")
.setPosition(200, 300)
.setColorForeground(color(120))
.setColorActive(color(255))
.setColorLabel(color(255))
.setSize(10, 10)
.setItemsPerRow(8)
.setSpacingColumn(25)
// .setSpacingRow(20)
.addItem("d1", mask1)
.addItem("d2", mask2)
.addItem("d4", mask3)
.addItem("d8", mask4)
;
//green slider for downward face
cp5.addSlider("DownwardGreen")
.setPosition(10, 310)
.setRange(0, 255)
;
//blue slider for downward face
cp5.addSlider("DownwardBlue")
.setPosition(10, 320)
.setRange(0, 255)
;
//speed slider for downward face
cp5.addSlider("DownwardSpeed")
.setPosition(10, 330)
.setRange(0, 50)
;
// checkboxes for mode and direction for downward face
DownwardMode = cp5.addCheckBox("DownwardModeCheck")
.setPosition(200, 330)
.setColorForeground(color(120))
.setColorActive(color(255))
.setColorLabel(color(255))
.setSize(10, 10)
.setItemsPerRow(8)
.setSpacingColumn(25)
// .setSpacingRow(20)
.addItem("dDot", 1)
.addItem("dDirection", 127)
;
/*REFLECTIVE*/
cp5.addSlider("ReflectiveRed")
.setPosition(10, 350)
.setRange(0, 255)
;
ReflectiveCheckBox = cp5.addCheckBox("ReflectiveMaskCheck")
.setPosition(200, 350)
.setColorForeground(color(120))
.setColorActive(color(255))
.setColorLabel(color(255))
.setSize(10, 10)
.setItemsPerRow(8)
.setSpacingColumn(25)
// .setSpacingRow(20)
.addItem("r1", mask1)
.addItem("r2", mask2)
.addItem("r4", mask3)
.addItem("r8", mask4)
.addItem("r16", mask5)
.addItem("r32", mask6)
.addItem("r64", mask7)
.addItem("r128", mask8)
;
cp5.addSlider("ReflectiveGreen")
.setPosition(10, 360)
.setRange(0, 255)
;
cp5.addSlider("ReflectiveBlue")
.setPosition(10, 370)
.setRange(0, 255)
;
cp5.addSlider("ReflectiveSpeed")
.setPosition(10, 380)
.setRange(0, 50)
;
ReflectiveMode = cp5.addCheckBox("ReflectiveModeCheck")
.setPosition(200, 380)
.setColorForeground(color(120))
.setColorActive(color(255))
.setColorLabel(color(255))
.setSize(10, 10)
.setItemsPerRow(8)
.setSpacingColumn(25)
// .setSpacingRow(20)
.addItem("rDot", 1)
.addItem("rDirection", 127)
;
/*STRIPE*/
cp5.addSlider("StripeRed")
.setPosition(10, 400)
.setRange(0, 255)
;
StripeCheckBox = cp5.addCheckBox("StripMaskCheck")
.setPosition(200, 400)
.setColorForeground(color(120))
.setColorActive(color(255))
.setColorLabel(color(255))
.setSize(10, 10)
.setItemsPerRow(8)
.setSpacingColumn(25)
// .setSpacingRow(20)
.addItem("s1", mask1)
.addItem("s2", mask2)
.addItem("s4", mask3)
;
cp5.addSlider("StripeGreen")
.setPosition(10, 410)
.setRange(0, 255)
;
cp5.addSlider("StripeBlue")
.setPosition(10, 420)
.setRange(0, 255)
;
cp5.addSlider("StripeSpeed")
.setPosition(10, 430)
.setRange(0, 50)
;
StripeMode = cp5.addCheckBox("StripeModeCheck")
.setPosition(200, 430)
.setColorForeground(color(120))
.setColorActive(color(255))
.setColorLabel(color(255))
.setSize(10, 10)
.setItemsPerRow(8)
.setSpacingColumn(25)
// .setSpacingRow(20)
.addItem("sDot", 1)
.addItem("sDirection", 127)
;
//THIS HIDES THE GUI ELEMENTS UNTIL THE .show is called
cp5.hide();
//INIT PALETTES AND GRADIENT
//old 80 color library
//initColors();
//new 5 color library
initSelectColors();
//DETERMINE LANBOX OR DMXPRO -- we use the pro
if (DMXPRO) {
dmxOutput.setupDmxPro(DMXPRO_PORT, DMXPRO_BAUDRATE);
}
//INITIALIZE OUT STRIPS AND UNITS
initLocs();
initStrips();
initUnits();
//INITIALIZE COLOR PALETTES AND GRADIENTS
initPalettes();
//INITIALIZE GIU ELEMENTS
initGUI();
//AUDIO SETUP
minim = new Minim(this);
input = minim.getLineIn(Minim.STEREO, config_BUFFERSIZE,
config_SAMPLERATE);
input.addListener(new Listener());
fft = new FFT(config_BUFFERSIZE, config_SAMPLERATE);
fft.logAverages(config_FFT_BASE_FREQ, config_FFT_BAND_PER_OCT);
// fft.noAverages();
// fft.linAverages(128);
fft.window(FFT.HAMMING);
System.out.println("Sound Control: FFT on " + fft.avgSize()
+ " log bands. samplerate: " + config_SAMPLERATE + "Hz. "
+ config_SAMPLERATE / config_BUFFERSIZE + " buffers of "
+ config_BUFFERSIZE + " samples per second.");
numZones = fft.avgSize();//
zoneEnergy = new float[numZones][];
zoneEnergyShortTerm = new float[numZones][];
zoneScore = new float[numZones][];
zoneEnabled = new boolean[numZones];
zoneEnergyVuMeter = new float[numZones];
zoneEnergyPeak = new float[numZones];
zoneEnergyPeakHoldTimes = new int[numZones];
for (int i = 0; i < numZones; i++) {
zoneEnergy[i] = new float[nbAverage];
zoneScore[i] = new float[nbAverage];
zoneEnergyShortTerm[i] = new float[nbAverageShortTerm];
zoneEnabled[i] = true;
}
//colorpicker init
cp = new ColorPicker( 1000, 300, 400, 400, 255 );
//TIMER SETUP AND FRAMERATE
frameRate(60);
startTime = millis();
eTime = elapsedTime(startTime);
}
void pGenerate()
{
sp = new Palette(this);
for (int i = 0; i < 5; i++) {
sp.addColor( color(random(255), random(255), random(255) ) );
}
sp.sortByLuminance();
}
void draw() {
//updateUNITS;
//old random 80 colors library
//initColors();
//new 5 color library
initSelectColors();
updateStrips();
updateDMXarray();
sendDMX();
updateScreen();
eTime=elapsedTime(startTime);
//random reseed the color generator every 30 seconds
if ((eTime.z == 0 || eTime.z == 30) && skip == false) {
pGenerate();
skip = true;
}
if (eTime.z == 2 || eTime.z == 32) {
skip = false;
}
// currentSwatch+=looper;
if(colorPickerMode){
cp.render();
}
}
void drawColorSwatches() {
pushMatrix();
translate(1000, 100);
sp.drawSwatches();
popMatrix();
}
void initColors() {
Palettes = new ArrayList();
Gradients = new ArrayList();
//create 20 palettes
for (int i=0; i < colorNum; i++) {
Palettes.add(new Palette(this));
}
// add 2 colors to each palette
for (int i=0; i < stripNum; i++) {
Palette tp = (Palette)Palettes.get(i);
tp.addColor(color(random(0, 255), random(0, 255), random(0, 255)));
tp.addColor(color(0, 0, 0));
Gradients.add(new Gradient(tp, 120));
}
}
void initSelectColors() {
Palettes = new ArrayList();
Gradients = new ArrayList();
//create 20 palettes
for (int i=0; i < stripNum; i++) {
Palettes.add(new Palette(this));
}
// add 2 colors to each palette
for (int i=0; i < stripNum; i++) {
Palette tp = (Palette)Palettes.get(i);
tp.addColor(sp.getColor(i%colorNum));
tp.addColor(color(0, 0, 0));
Gradients.add(new Gradient(tp, 120));
}
}
//FUNCTION TO UPDATE THE DMXARRAY WITH NEW VALUES
void updateDMXarray() {
for (int i=0;i<stripNum;i++) {
//DMXarray[i]=(int)random(10)+((i%2==0)?mouseX:mouseY);
Strip ts = (Strip)strips.get(i);
DMXarray[i*5]=ts.rChan;
DMXarray[i*5+1]=ts.gChan;
DMXarray[i*5+2]=ts.bChan;
DMXarray[i*5+3]=ts.modeChan;
DMXarray[i*5+4]=ts.maskChan;
}
}
void initPalettes() {
whiteBlack = new Palette(this);
whiteBlack.addColor( color(255, 255, 255));
whiteBlack.addColor(color(0, 0, 0));
initGradients();
}
void initGradients() {
fade1 = new Gradient(whiteBlack, moveTime*4+1);
}
void initGUI() {
sysFont = loadFont("Helvetica.vlw");
textFont(sysFont, 24);
fill(255, 255, 255);
}
//SEND DMX OUT USING THE DMXARRAY[]
void sendDMX() {
for (int i=1;i<universeSize+1;i++) {
dmxOutput.set(i, DMXarray[i-1]);
}
}
void updateScreen() {
//MAKE THE SCREEN BLACK
background(0);
//DRAW FFT< SOUND LEVEL AND BEAT DETECTION TO THE SCREEN
CalcBeatAndDrawSoundViz(-3, 550);
//DRAW THE UNITS
drawOctagonGUI();
//PUT SOME TEXT
drawMisc();
drawColorSwatches();
}
//int r = (argb >> 16) & 0xFF; // Faster way of getting red(argb)
//int g = (argb >> 8) & 0xFF; // Faster way of getting green(argb)
//int b = argb & 0xFF; // Faster way of getting blue(argb)
void updateStrips() {
if (beatMode) {
boolean beatControl = control();
//println(beatControl);
//testing parameter
//beatControl=true;
for (int i=0; i < stripNum; i++) {
Strip ts = (Strip)strips.get(i);
Gradient tg = (Gradient)Gradients.get(i);
color tc = color(0,0,0);
if(colorPickerMode){
tc = manualColor;
}else{
tc = color(tg.getColor(0));
}
int beatrandomizer = (int)(random(0, Activity));
int directionrandomizer = (int)(random(0, 1));
int speedrandomizer = (int)(random(0, 10));
if (ts.tog>0 && beatControl == true && beatrandomizer == 1) {
int at = (int)allToggle.getArrayValue()[i%4];
if (at==1) {
ts.rChan = (tc >> 16) & 0xFF;
ts.gChan = (tc >> 8) & 0xFF;
ts.bChan = tc & 0xFF;
ts.modeChan = 0;
ts.maskChan = 255;
}
//else{
// ts.rChan = 0;
// ts.gChan = 0;
// ts.bChan = 0;
// if(directionrandomizer>0){
// ts.modeChan = MasterSpeed + speedrandomizer;
// }else{
// ts.modeChan = MasterSpeed+ (speedrandomizer + 127);
// }
// ts.maskChan = 255;
// }
//println(MasterSpeed);
gotBeat = false;
}
else if (ts.tog==0 || beatControl == false) {
ts.rChan = 0;
ts.gChan = 0;
ts.bChan = 0;
if (directionrandomizer>0) {
ts.modeChan = MasterSpeed + speedrandomizer;
}
else {
ts.modeChan = MasterSpeed+ (speedrandomizer + 127);
}
ts.maskChan = 255;
}
}
}
else if (diagMode) {
//make the manual arrays of colors, modes and masks for all four strips according to the diag sliders and checkboxes
color[] diagc= new color[4];
int[] dmode = {
0, 0, 0, 0
};
int[] dmask = {
0, 0, 0, 0
};
//fill the arrays based on the values from the sliders
diagc[0] = color(StripeRed, StripeGreen, StripeBlue);
diagc[1] = color(EdgeRed, EdgeGreen, EdgeBlue);
diagc[2] = color(DownwardRed, DownwardGreen, DownwardBlue);
diagc[3] = color(ReflectiveRed, ReflectiveGreen, ReflectiveBlue);
//calculate the values of the checkboxes.
//MASK CHECKBOXES
for (int i=0;i<StripeCheckBox.getArrayValue().length;i++) {
int n = (int)StripeCheckBox.getArrayValue()[i];
if (n==1) {
dmask[0] += StripeCheckBox.getItem(i).internalValue();
}
}
for (int i=0;i<EdgeCheckBox.getArrayValue().length;i++) {
int n = (int)EdgeCheckBox.getArrayValue()[i];
if (n==1) {
dmask[1] += EdgeCheckBox.getItem(i).internalValue();
}
}
for (int i=0;i<DownwardCheckBox.getArrayValue().length;i++) {
int n = (int)DownwardCheckBox.getArrayValue()[i];
if (n==1) {
dmask[2] += DownwardCheckBox.getItem(i).internalValue();
}
}
for (int i=0;i<ReflectiveCheckBox.getArrayValue().length;i++) {
int n = (int)ReflectiveCheckBox.getArrayValue()[i];
if (n==1) {
dmask[3] += ReflectiveCheckBox.getItem(i).internalValue();
}
}
//MODE CHECK BOXES
for (int i=0;i<StripeMode.getArrayValue().length;i++) {
int s = (int)StripeMode.getArrayValue()[i];
if (s==1) {
dmode[0] += StripeMode.getItem(i).internalValue();
}
}
if (dmode[0]>0) {
dmode[0] += StripeSpeed;
}
for (int i=0;i<EdgeMode.getArrayValue().length;i++) {
int e = (int)EdgeMode.getArrayValue()[i];
if (e==1) {
dmode[1] += EdgeMode.getItem(i).internalValue();
}
}
if (dmode[1]>0) {
dmode[1] += EdgeSpeed;
}
for (int i=0;i<DownwardMode.getArrayValue().length;i++) {
int d = (int)DownwardMode.getArrayValue()[i];
if (d==1) {
dmode[2] += DownwardMode.getItem(i).internalValue();
}
}
if (dmode[2]>0) {
dmode[2] += DownwardSpeed;
}
for (int i=0;i<ReflectiveMode.getArrayValue().length;i++) {
int r = (int)ReflectiveMode.getArrayValue()[i];
if (r==1) {
dmode[3] += ReflectiveMode.getItem(i).internalValue();
}
}
if (dmode[3]>0) {
dmode[3] += ReflectiveSpeed;
}
//send them to the strips using modulus (%) to split the strips into groups of four to correspond to the [4] arrays
for (int i=0; i < stripNum; i++) {
Strip ts = (Strip)strips.get(i);
if (ts.stripDiagToggle) {
ts.rChan = (diagc[i%4] >> 16) & 0xFF;
ts.gChan = (diagc[i%4] >> 8) & 0xFF;
ts.bChan = diagc[i%4] & 0xFF;
ts.modeChan = dmode[i%4];
ts.maskChan = dmask[i%4];
}
}
}
else if ((!diagMode && !beatMode) && !waveTog) {
for (int i=0; i < stripNum; i++) {
Strip ts = (Strip)strips.get(i);
if (ts.tog==0) {
ts.rChan = (0 >> 16) & 0xFF;
ts.gChan = (0 >> 8) & 0xFF;
ts.bChan = 0 & 0xFF;
ts.modeChan = 0;
ts.maskChan = 255;
}
}
} else if (waveTog == true) {
int tempTimer = millis()-waveTimer;
if(tempTimer > 0 && tempTimer <moveTime){
//tc = color(0,0,0);
//println("off");
}else if (tempTimer > (moveTime*2) && tempTimer < moveTime*3) {
//tc = color(255,255,255);
//println("on");
}else if (tempTimer > moveTime*4){
waveTimer = millis();
step+=directionTog;
}
//println(tempTimer);
for (int i=0; i < unitNum; i++) {
//if(testVal == 0){
// fadeDir = 1;
//}
// if(testVal == 10){
// fadeDir = -1;
//}
//testVal+=fadeDir;
println(testVal);
color tc = color(0,0,0);
Unit u = (Unit)units.get(i);
int tempID = u.unit_ID;
//println(tempID);
Strip ts1 = (Strip)u.stripe;
Strip ts2 = (Strip)u.edge;
Strip ts3 = (Strip)u.downward;
Strip ts4 = (Strip)u.reflective;
println("step= "+ step + " Unit ID= " + tempID);
//moveTime*4-(millis()%(moveTime*4))
if(step==1 && tempID == 18){
tc = fade1.getColor(0);
//println("there");
}
if(step==2 && tempID == 20){
tc = fade1.getColor(0);
//println("there");
}
if(step==3 && (tempID == 6 || tempID == 5)){
tc = fade1.getColor(0);
}
if(step==4 && (tempID ==7 || tempID == 4 || tempID == 1) ){
tc = fade1.getColor(0);
}
if(step==5 && (tempID ==8 || tempID == 3 || tempID == 2 || tempID == 17 || tempID == 16)){
tc = fade1.getColor(0);
}
if(step==6 && (tempID == 9 || tempID == 12)){
tc = fade1.getColor(0);
}
if(step==7 && (tempID ==10 || tempID == 11 || tempID == 19 )){
tc = fade1.getColor(0);
}
if(step==8 && (tempID ==13 || tempID == 14 || tempID == 15) ){
tc = fade1.getColor(0);
}
if (step == 9){
tc = color(0,0,0);
directionTog=-1;
}
if (step == 0){
tc = color(0,0,0);
directionTog=1;
step=1;
}
//int at = (int)allToggle.getArrayValue()[i%4];
ts1.rChan = (tc >> 16) & 0xFF;
ts1.gChan = (tc >> 8) & 0xFF;
ts1.bChan = tc & 0xFF;
ts1.modeChan = 0;
ts1.maskChan = 0;
ts2.rChan = (tc >> 16) & 0xFF;
ts2.gChan = (tc >> 8) & 0xFF;
ts2.bChan = tc & 0xFF;
ts2.modeChan = 0;
ts2.maskChan = 0;
ts3.rChan = (tc >> 16) & 0xFF;
ts3.gChan = (tc >> 8) & 0xFF;
ts3.bChan = tc & 0xFF;
ts3.modeChan = 0;
ts3.maskChan = 0;
ts4.rChan = (tc >> 16) & 0xFF;
ts4.gChan = (tc >> 8) & 0xFF;
ts4.bChan = tc & 0xFF;
ts4.modeChan = 0;
ts4.maskChan = 255;
//units.add(new Unit(i, (Strip)strips.get(i*4), (Strip)strips.get(i*4+1), (Strip)strips.get(i*4+2), (Strip)strips.get(i*4+3), subStripArray[i], typeArray[i], (PVector)locs.get(i)));
}
// println("wave");
}
//do the wave
}
/* CREATES THE STRIP OBJECTS.
*/
void initStrips() {
strips = new ArrayList();
//int testVal=0;
int tog=100;
boolean diag = false;
for (int i=0; i < stripNum; i++) {
strips.add(new Strip(0, 0, 0, 0, 255, tog, diag));
}
}
void initUnits() {
units = new ArrayList();
for (int i=0; i < unitNum; i++) {
units.add(new Unit(i, (Strip)strips.get(i*4), (Strip)strips.get(i*4+1), (Strip)strips.get(i*4+2), (Strip)strips.get(i*4+3), subStripArray[i], typeArray[i], (PVector)locs.get(i)));
}
}
//THE MASTER ARRAY FOR THE ON-SCREEN LOCATION OF THE OCTAGONS IN THE GUI. IF YOU CHANGE THESE VALUES EVERYTHING ELSE MOVES RELATIVE TO THESE CORDS
//SO LAY OUT THE INTERFACE HOWEVER YOU LIKE. BECAUSE I LOVE YOU.