-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpanel3.js
1189 lines (848 loc) · 25.9 KB
/
panel3.js
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
// inlets and outlets
inlets = 1;
outlets = 1;
// radio 'control panel' - panel3.js - this version runs as bpatcher with maxsdr
//
//
//
var cellobj = new Array("led"); // this version uses led objects
var modblob = new Array(7); // modulators
var xmax = 40; // panel dimensions
var ymax = 26;
// color codes for the mapkeys along x and y axes
var xkey = new Array ( 9,9, 1,4,2, 9, 4,4,0,4,4,0,4,4,2,2, 9, 2,2,1, 9, 1,1,1,1,3,3, 9,9, 0,9,1,1,9,2,2,9,3,9,9 );
var ykey = new Array( 9, 9 ,3,2,1,0, 4,3,2,1,0, 9, 9, 9,3,2,1, 0,4,3,2,1, 0,9,9, 9 );
// blob data structure
//
// x, y upper left
// lengthx, lengthy,
//
// orientation: 0 = horizontal, 1 = vertical
// step 1 = downward or rightward, -1 = upward or leftward (this defines the corner of origin too)
//
// data lorange, hirange
// scale: 0 = no, 1 = yes
//
// blobtype: 0 = generic decimal, 1 = spare, 2 = pushbutton flash, 3 = radiobutton,
// color code 0-9
// contrast color 0-9
//
// signed ( 0 = no, 1 = yes) // booooooooooooooolean
// colorshift ( 0 = normal , 1 = use different colors every 3 digits, like comma separators (frequency display)
//
// blink (milliseconds duration for pushbutton flash type only (led blinktime )
//
// radio number
// name
// value
//
//
// it would be nice to add a property for fatness of the radio buttons
//
// blob object constructor
//
function blob( ulx, uly, lengthx, lengthy, orient, step, lo, hi, scale, ctype, color, ccolor, signed, colorshift, blink, radno, name, val )
{
this.ulx = ulx;
this.uly = uly;
this.lengthx = lengthx;
this.lengthy = lengthy;
this.orient = orient;
this.step = step;
this.lo = lo;
this.hi = hi;
this.scale = scale;
this.ctype = ctype;
this.color = color;
this.ccolor = ccolor;
this.signed = signed;
this.colorshift = colorshift;
this.blink = blink;
this.radno = radno; // ? this stuff kinda kills the obectivity
this.name = name; // ?
this.val = val; // ?
}
var MAXBLOBS = 34;
var blobarray = new Array(MAXBLOBS);
// row 1 blobs
blobarray[0] = new blob( 2, 10, 1, 9, 1, -1, 0, 9, 0, 0, 1, 1, 0,0, 0, 1, "RFMeter", 0 );
blobarray[1] = new blob( 3, 10, 1, 9, 1, -1, 0, 9, 0, 0, 4, 4, 0,0, 0, 1, "RFGain", 0 );
blobarray[2] = new blob( 4, 10, 1, 9, 1, -1, 0, 9, 0, 0, 2, 2, 0,0, 0, 1, "preampRadiogroup", 0 );
blobarray[3] = new blob( 6, 10, 9,9,1,-1,0,999999999, 0, 0, 1, 3, 1,1, 0, 1,"freq", 0 );
blobarray[4] = new blob( 16, 10, 1, 4, 1, -1, 0 , 2, 0, 3, 4, 4, 0,0, 0, 1,"modeSelectRadiogroup", 0 );
blobarray[5] = new blob( 17, 10, 1, 9, 1, -1, 0, 9, 0, 0, 4, 4, 0,0, 0, 1, "mainTuningSlider", 0 );
blobarray[6] = new blob( 18, 10, 1, 9, 1, -1, 0, 9, 0, 0, 4, 4, 0,0, 0, 1, "fineTuningSlider", 0 );
blobarray[7] = new blob( 20, 10, 1, 9, 1, -1, 0, 9, 0, 0, 2, 2, 0,0, 0, 1, "inputMenuSelect", 0 );
blobarray[8] = new blob( 21, 10, 1, 9, 1, -1, 0, 9, 0, 0, 0, 0, 0,0, 0, 1, "deviceTuningCoarseSlider", 0 );
blobarray[9] = new blob( 22, 10, 1, 9, 1, -1, 0, 9, 0, 0, 1, 1, 0,0, 0, 1, "deviceTuningFineSlider", 0 );
blobarray[10] = new blob( 24, 10, 3, 9,1, -1, 0, 999, 0, 0, 2, 2, 0,0, 0, 1, "memory", 0 );
// row 1 toggle blobs
blobarray[11] = new blob( 4, 11, 1, 1,1, 1, 0, 1, 0,0,1,1,0,0,0, 1, "preampToggle", 0 );
blobarray[12] = new blob( 22, 11, 1, 1,1, 1, 0, 1, 0,0,1,1,0,0,0, 1, "IQFlipToggle", 0 );
// row 2 blobs
blobarray[13] = new blob( 2, 22, 1, 9, 1, -1, 0, 9, 0, 0, 1, 1, 0,0, 0, 1, "AFMeter", 0 );
blobarray[14] = new blob( 3, 22, 1, 9, 1, -1, 0, 9, 0, 0, 4, 4, 0,0, 0, 1, "AFGain", 0 );
blobarray[15] = new blob( 4, 22, 1, 9, 1, -1, 0, 9, 0, 0, 2, 2, 0,0, 0, 1, "AGCThresholdLevelSlider", 0 );
blobarray[16] = new blob( 6, 22, 1, 9, 1, -1, 0, 9, 0, 0, 4, 4, 0,0, 0, 1, "LPF1CutoffFreqSlider", 0 );
blobarray[17] = new blob( 7, 22, 1, 9, 1, -1, 0, 9, 0, 0, 4, 4, 0,0, 0, 1, "LPF1QSlider", 0 );
blobarray[18] = new blob( 8, 22, 1, 9, 1, -1, 0, 9, 0, 0, 0, 0, 0,0, 0, 1, "notchFilter1Toggle", 0 );
blobarray[19] = new blob( 9, 22, 1, 9, 1, -1, 0, 9, 0, 0, 4, 4, 0,0, 0, 1, "notchFilter1FreqSlider", 0 );
blobarray[20] = new blob( 10, 22, 1, 9, 1, -1, 0, 9, 0, 0, 4, 4, 0,0, 0, 1, "notchFilter1WidthSlider", 0 );
blobarray[21] = new blob( 11, 22, 1, 9, 1, -1, 0, 9, 0, 0, 0, 0, 0,0, 0, 1, "notchFilter2Toggle", 0 );
blobarray[22] = new blob( 12, 22, 1, 9, 1, -1, 0, 9, 0, 0, 4, 4, 0,0, 0, 1, "notchFilter2FreqSlider", 0 );
blobarray[23] = new blob( 13, 22, 1, 9, 1, -1, 0, 9, 0, 0, 4, 4, 0,0, 0, 1, "notchFilter2WidthSlider", 0 );
blobarray[24] = new blob( 14, 22, 1, 9, 1, -1, 0, 9, 0, 0, 2, 2, 0,0, 0, 1, "noiseFilter1LevelSlider", 0 );
blobarray[25] = new blob( 15, 22, 1, 9, 1, -1, 0, 9, 0, 0, 2, 2, 0,0, 0, 1, "noiseFilter2LevelSlider", 0 );
blobarray[26] = new blob( 17, 22, 1, 9, 1, -1, 0, 9, 0, 0, 0, 0, 0,0, 0, 1, "humFilterToggle", 0 );
blobarray[27] = new blob( 18, 22, 1, 9, 1, -1, 0, 9, 0, 0, 4, 4, 0,0, 0, 1, "humFilterWidthSlider", 0 );
blobarray[28] = new blob( 19, 22, 1, 9, 1, -1, 0, 9, 0, 0, 1, 1, 0,0, 0, 1, "LPF2CutoffFreqSlider", 0 );
blobarray[29] = new blob( 14, 22, 1, 9, 1, -1, 0, 9, 0, 0, 4, 4, 0,0, 0, 1, "noiseFilter1LevelSlider", 0 );
blobarray[30] = new blob( 21, 22, 2, 9,1, -1, 0, 99, 0,0,1,1,0,0,0, 0, "clockh", 0 );
blobarray[31] = new blob( 23, 22, 2, 9,1, -1, 0, 99, 0,0,1,1,0,0,0, 0, "clockm", 0 );
blobarray[32] = new blob( 25, 22, 2, 9,1, -1, 0, 99, 0,0,3,3,0,0,0, 0, "clocks", 0 );
// row 2 toggles
blobarray[33] = new blob( 4, 23, 1, 1,1, 1, 0, 1, 0,0,1,1,0,0,0, 1, "AGCToggle", 0 );
// modulator data structure
// these are fixed structures 8x2, with specific color rules
//
// ulx, uly
// mod id number 1-n
// on : 0 = off, 1 = on
// modin : modulation source index 0-4
// clockspeed : 0-4
// wavetype : 0-4
// lorange : 0-4
// hirange : 0-4
// ingate : 0 - 4 (tells which control is being modulated)
// spare
// destination : 0-127 destination index // this is displayed elsewhere
//
// modulator constructor function
//
function modulator( ulx, uly, id, on, modin, clockspeed, wavetype, lo, hi, ingate, spare, destination )
{
this.ulx = ulx;
this.uly = uly;
this.id = id;
this.on = on;
this.modin = modin;
this.clockspeed = clockspeed;
this.wavetype = wavetype;
this.lo = lo;
this.hi = hi;
this.ingate = ingate;
this.spare = spare;
this.destination = destination;
}
// mod destination constructor function
//
function modulatorDestination( x, y, source )
{
this.x = x;
this.y = y;
this.source = source;
}
//
//
var MAXMD = 27; // actual amount of md's used
var md = new Array(MAXMD);
for(i=0; i< MAXMD; i++)
{
md[i] = new modulatorDestination( 0,0,0 ); // populate the destinations with nothing
}
/* wire up actual destinations */
md[1] ={ x:29, y:3, val:0 };
md[2] ={ x:29, y:7, val:0 };
md[3] ={ x:29, y:11, val:0 };
md[4] ={ x:29, y:15, val:0 };
md[5] ={ x:29, y:19, val:0 };
md[7] ={ x:16, y:1, val:0 };
md[8] ={ x:17, y:1, val:0 };
md[9] ={ x:18, y:1, val:0 };
md[10] ={ x:21, y:1, val:0 };
md[11] ={ x:22, y:1, val:0 };
md[12] ={ x:6, y:13, val:0 };
md[13] ={ x:7, y:13, val:0 };
md[14] ={ x:8, y:14, val:0 };
md[15] ={ x:9, y:15, val:0 };
md[16] ={ x:10, y:16, val:0 };
md[17] ={ x:11, y:17, val:0 };
md[18] ={ x:12, y:13, val:0 };
md[19] ={ x:13, y:13, val:0 };
md[20] ={ x:14, y:13, val:0 };
md[21] ={ x:15, y:13, val:0 };
md[22] ={ x:17, y:13, val:0 };
md[23] ={ x:18, y:13, val:0 };
md[24] ={ x:19, y:13, val:0 };
md[25] ={ x:3, y:13, val:0 };
//
// here is the new stuff (this is an old comment)
//
var cellspace = 17;
// multidimensional array to store matrix of objects to provide color and beauty to the world
//
var cell = new Array(128);
for(i=0;i<128;i++)
{
cell[i] = new Array(128);
}
// home coordinates
var xorigin = 50;
var yorigin = 50;
var ledsize = 17; // this is the default size of a square led object
modblob[0] = new modulator( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ); // zero is just a place holder
modblob[1] = new modulator( 29, 3, 1, 0, 0, 0, 0, 0, 4, 0, 0, 0 );
modblob[2] = new modulator( 29, 7, 2, 0, 0, 0, 0, 0, 4, 0, 0, 0 );
modblob[3] = new modulator( 29, 11, 3, 0, 0, 0, 0, 0, 4, 0, 0, 0 );
modblob[4] = new modulator( 29, 15, 4, 0, 0, 0, 0, 0, 4, 0, 0, 0 );
modblob[5] = new modulator( 29, 19, 5, 0, 0, 0, 0, 0, 4, 0, 0, 0 );
var crmb = 0; // last modulator id to be refreshed //
// etch-a-sketch stuff
var esx = 0;
var esy = 0;
// ---------------------------------------------------------------------------------------------------------------------------------------------------
// methods start here
// ----------------------------------------------------------------------------------------------------------------------------------------------------
//
//
// refresh the modulator destination indicators
// this solves issue of having several modulators target the same destination.
// each time this function is called, it cycles through the modulators until it find an active destination to light up
// typically you would call this once every second or two, or by pressing a special shiny red activator button hidden in your pants.
//
function refresh_md( )
{
// this is kind of a brute force thing but is better than nothing at all
// loop through modulators 1-5 skipping over '0' destinations, as soon as you find one to light up, light it and return
// next time the function is called it resumes where it left off, or if there are no active destinations, it starts again at 1
while(++crmb < 6)
{
if( modblob[ crmb ].destination )
{
setmd( crmb, modblob[crmb].destination );
return;
}
}
crmb = 0;
}
// generic function to display incoming data on the panel
//
// r is radio number ( 1, 2, or 0 (no radio))
// name is blob name
// val is data value to display
//
//
function data( name, r, val )
{
// find matching blob
// call blob show
for( i= 0; i< blobarray.length; i++ )
{
if((blobarray[i].name == name) && (blobarray[i].radno == r))
{
blobarray[i].val = val;
blobshow( blobarray[i] );
break;
}
}
}
//
// debugging to see value of md[]
function postmd()
{
i = 1;
post( "md: ", i, md[i].x, md[i].y, md[i].val );
post();
}
//
// show blobs with test data for debugging
//
function showblobs()
{
/*
blobarray[0].val = 7;
blobarray[1].val = 10324600;
blobarray[2].val = 0;
blobarray[3].val = 9;
blobarray[4].val = 1400;
blobarray[5].val = 3;
blobarray[6].val = 0;
blobarray[7].val = 40;
blobarray[8].val = 4;
blobarray[9].val = 5462345;
blobarray[10].val = 1;
blobarray[11].val = 8;
blobarray[12].val = 2500;
blobarray[13].val = 1;
blobarray[14].val = -1;
blobarray[15].val = -20;
blobarray[16].val = 33;
blobarray[17].val = 3;
blobarray[18].val = 1;
blobarray[19].val = 1;
blobarray[20].val = 0;
blobarray[21].val = 0;
blobarray[22].val = 1;
blobarray[23].val = 0;
blobarray[24].val = 3;
blobarray[25].val = 2;
blobarray[26].val = 19;
blobarray[27].val = 20;
blobarray[28].val = 24;
*/
for( z = 0; z < blobarray.length; z++ )
{
blobshow ( blobarray[z] );
}
}
//
// display key strips on x,y axes
//
function showkeys()
{
for(i = 0; i < xmax; i++ )
{
if(xkey[i] == 9)
cell[i][ymax - 1].hidden = 1;
else
{
cell[i][ymax - 1].message( "pict", xkey[i] );
cell[i][ymax-1].hidden = 0;
cell[i][ymax -1].message( 1 );
}
}
for(i = 0; i < ymax; i++ )
{
if(ykey[i] == 9)
cell[0][i].hidden = 1;
else
{
cell[0][i].message( "pict", ykey[i] );
cell[0][i].hidden = 0;
cell[0][i].message( 1 );
}
}
}
//
// display incoming data from modulator n
//
function moddata( n, on, clockspeed, wavetype, lo, hi, ingate, spare, destination )
{
modblob[n].on = on;
modblob[n].clockspeed = clockspeed;
modblob[n].wavetype = wavetype;
modblob[n].lo = lo;
modblob[n].hi = hi;
modblob[n].ingate = ingate;
modblob[n].spare = spare;
modblob[n].destination = destination;
setmod(n);
}
// initialize all 5 modulator blocks
//
function initmods()
{
var i;
for (i = 1; i < 6; i++ )
setmod(i);
}
//
// set modulator block i (0-4)
//
function setmod( i )
{
// note that modulators start at 1 and go to 5
var mb; // pointer to current modblob
mb = modblob[i];
cell[mb.ulx][mb.uly + 1].message( "pict", mb.id -1 ); // id color, on off
cell[mb.ulx][mb.uly + 1].hidden = 0;
cell[mb.ulx][mb.uly + 1].message( mb.on );
cell[mb.ulx][mb.uly + 1].message( "pict", mb.id - 1 );
cell[mb.ulx][mb.uly + 1].hidden = 0;
cell[mb.ulx][mb.uly + 1].message(mb.on );
cell[mb.ulx][mb.uly + 2].message( "pict", mb.id - 1 );
cell[mb.ulx][mb.uly + 2].hidden = 0;
cell[mb.ulx][mb.uly + 2].message(mb.on );
// the input modulator gets set by the destination of other modulators, so we don't actually set this cell here
//
// cell[mb.ulx + 1][mb.uly + 1].message( "pict", mb.modin ); // input modulator source
// cell[mb.ulx + 1][mb.uly + 1].hidden = 0;
// cell[mb.ulx + 1][mb.uly + 1].message(0);
//
if(mb.ingate == 0)
{
cell[mb.ulx + 2][mb.uly].message( "pict", 4 ); // ingate 0 (clockspeed), on off
cell[mb.ulx + 2][mb.uly].hidden = 0;
cell[mb.ulx + 2][mb.uly].message(1);
}
else
{
cell[mb.ulx + 2][mb.uly].message( "pict", 4 );
cell[mb.ulx + 2][mb.uly].hidden = 0;
cell[mb.ulx + 2][mb.uly].message(0);
}
cell[mb.ulx + 2][mb.uly + 1].message( "pict", mb.clockspeed ); // clockspeed
cell[mb.ulx + 2][mb.uly + 1].hidden = 0;
cell[mb.ulx + 2][mb.uly + 1].message(1);
cell[mb.ulx + 2][mb.uly + 2].message( "pict", mb.clockspeed );
cell[mb.ulx + 2][mb.uly + 2].hidden = 0;
cell[mb.ulx + 2][mb.uly + 2].message(1);
if(mb.ingate == 1)
{
cell[mb.ulx + 3][mb.uly].message( "pict", 4 ); // ingate 1 (wavetype), on, off
cell[mb.ulx + 3][mb.uly].hidden = 0;
cell[mb.ulx + 3][mb.uly].message(1);
}
else
{
cell[mb.ulx + 3][mb.uly].message( "pict", 4 );
cell[mb.ulx + 3][mb.uly].hidden = 0;
cell[mb.ulx + 3][mb.uly].message(0);
}
cell[mb.ulx + 3][mb.uly + 1].message( "pict", mb.wavetype ); // wavetype 0-4
cell[mb.ulx + 3][mb.uly + 1].hidden = 0;
cell[mb.ulx + 3][mb.uly + 1].message(1);
cell[mb.ulx + 3][mb.uly + 2].message( "pict", mb.wavetype );
cell[mb.ulx + 3][mb.uly + 2].hidden = 0;
cell[mb.ulx + 3][mb.uly + 2].message(1);
if(mb.ingate == 2)
{
cell[mb.ulx + 5][mb.uly].message( "pict", 4 ); // ingate 2 (lo range), on, off
cell[mb.ulx + 5][mb.uly].hidden = 0;
cell[mb.ulx + 5][mb.uly].message(1);
}
else
{
cell[mb.ulx + 5][mb.uly].message( "pict", 4 );
cell[mb.ulx + 5][mb.uly].hidden = 0;
cell[mb.ulx + 5][mb.uly].message(0);
}
cell[mb.ulx + 5][mb.uly + 2].message( "pict", mb.lo ); // lo range 0-4
cell[mb.ulx + 5][mb.uly + 2].hidden = 0;
cell[mb.ulx + 5][mb.uly + 2].message(1);
cell[mb.ulx + 5][mb.uly + 1].message( "pict", mb.lo ); // lo range 0-4
cell[mb.ulx + 5][mb.uly + 1].hidden = 0;
cell[mb.ulx + 5][mb.uly + 1].message(1);
if(mb.ingate == 3)
{
cell[mb.ulx + 6][mb.uly].message( "pict", 4 ); // ingate 3 (hi range), on, off
cell[mb.ulx + 6][mb.uly].hidden = 0;
cell[mb.ulx + 6][mb.uly].message(1);
}
else
{
cell[mb.ulx + 6][mb.uly].message( "pict", 4 );
cell[mb.ulx + 6][mb.uly].hidden = 0;
cell[mb.ulx + 6][mb.uly].message(0);
}
cell[mb.ulx + 6][mb.uly + 1].message( "pict", mb.hi ); // hi range 0-4
cell[mb.ulx + 6][mb.uly + 1].hidden = 0;
cell[mb.ulx + 6][mb.uly + 1].message(1);
cell[mb.ulx + 6][mb.uly + 2].message( "pict", mb.hi ); // hi range 0-4
cell[mb.ulx + 6][mb.uly + 2].hidden = 0;
cell[mb.ulx + 6][mb.uly + 2].message(1);
if(mb.ingate == 4)
{
cell[mb.ulx + 8][mb.uly].message( "pict", 4 ); // ingate 4 (destination), on, off
cell[mb.ulx + 8][mb.uly].hidden = 0;
cell[mb.ulx + 8][mb.uly].message(1);
}
else
{
cell[mb.ulx + 8][mb.uly].message( "pict", 4 );
cell[mb.ulx + 8][mb.uly].hidden = 0;
cell[mb.ulx + 8][mb.uly].message(0);
}
if(mb.destination != 0)
{
cell[mb.ulx + 8][mb.uly + 1].message( "pict", 4 ); // destination - lights if non-zero
cell[mb.ulx + 8][mb.uly + 1].hidden = 0;
cell[mb.ulx + 8][mb.uly + 1].message(1);
cell[mb.ulx + 8][mb.uly + 2].message( "pict", 4 ); // destination - lights if non-zero
cell[mb.ulx + 8][mb.uly + 2].hidden = 0;
cell[mb.ulx + 8][mb.uly + 2].message(1);
}
else
{
cell[mb.ulx + 8][mb.uly + 1].message( "pict", 4 );
cell[mb.ulx + 8][mb.uly + 1].hidden = 0;
cell[mb.ulx + 8][mb.uly + 1].message(0);
cell[mb.ulx + 8][mb.uly + 2].message( "pict", 4 );
cell[mb.ulx + 8][mb.uly + 2].hidden = 0;
cell[mb.ulx + 8][mb.uly + 2].message(0);
}
// turn off all modulator destinations with source equal to this modulator,
// then light up the destination indexed by the desination value
//
setmd( mb.id, mb.destination );
// room for future expansion
// cell[mb.ulx + 7][mb.uly].hidden = 1; // blank cell
// cell[mb.ulx + 7][mb.uly + 1].message( "pict", mb.spare ); // spare
// cell[mb.ulx + 7][mb.uly + 1].hidden = 0;
// cell[mb.ulx + 7][mb.uly + 1].message(0);
}
//
// turn off all modulator destinations with source equal to this modulator,
// then light up the destination indexed by the desination value
//
function setmd( s, d )
{
// just need to figure out the indexing issues with 0 and 1
for (i = 0; i < MAXMD; i++ )
{
if( md[i].source == s )
{
md[i].source == 0;
cell[md[i].x][md[i].y].hidden = 1;
}
}
if( d > 0 )
{
if( d != 6) // light it up if non zero & kluge exception for 6
{
md[d].source = s;
cell[md[d].x][md[d].y].message( "pict", s - 1 );
cell[md[d].x][md[d].y].hidden = 0;
cell[md[d].x][md[d].y].message( 1 );
}
}
}
// initialize display surface
//
function start( color )
{
makecells( xmax, ymax, color );
// here's a kludge to correct poor graph paper design skills
// we could dedicate blank rows for modifier destinations, to solve the problem
// paintrect( 0, 0, 25, 1, 9 ); // clear cells
// paintrect( 0, 11, 25, 1, 9 ); // clear cells
showkeys();
initmods();
showblobs();
// cells should be hidden
// cell state should be set to 0
// draw keys
}
// display a blob
// this should really be a method of blob
//
function blobshow( c )
{
var place; // current decimal place for digit to be displayed
var digit;
var placeval;
var nextop; // successively smaller values by powers of 10, to display
var drawcolor;
var myplaces; // maximum number of 'places' , ie 9999 has four places, 999 has 3
var myradix; // maximum number of digits for each place (1-9),
var cellx, celly; // variables to assign actual drawing place in loop
var m; // a maxobj
//
// note 2 self: this function (and the one that shows modulators) could be more efficient if we saved the current state of each
// cell, because most data updates are incremental, and we could just update the actual cells that change. for example when the
// data changes from "43" to "44", we would update only one cell instead of 8. The tradeoff would be in code complexity and the
// time needed to update state settings and compare.
//
post( "blobshow ", c.name );
post();
// adjust colors and such for negative values
drawcolor = c.color;
if( c.val < 0) // if data is negative
{
coladj = -1; // color shift
c.val = c.val * -1; // make positive
}
else
coladj = 0; // default , no adjustment
// set orientation
if ( c.orient == 1) // if vertically oriented
{
myplaces = c.lengthx; // width
myradix = c.lengthy; // heighth
}
else // if horizontally oriented
{
myplaces = c.lengthy;
myradix = c.lengthx;
}
// do the display
nextop = c.val; // preload the data value
for ( i = 0 ; i < myplaces; i++ ) // break down the input data in powers of 10 from the left until you get to the 1's place
{
// post( "i: ", i );
// post();
if( c.colorshift)
{
switch(i) // for large numbers, break colors into groups of 3 - like commas
{
case 0:
drawcolor = c.color;
break;
case 3:
drawcolor = c.ccolor;
break
case 6:
drawcolor = c.color;
break;
}
}
place = myplaces - (i + 1);
// post( "place: ", place );
if(place > 0) // if not 1's place, then...
{
placeval = Math.pow(10,place);
// post(" , placeval: ", placeval, " nextop: ", nextop );
digit = Math.floor(nextop / placeval); // break out the digit for this place
// post( ", digit (before): ", digit );
// digit = parseInt(digit);
// post(" digit: ", digit );
// post();
nextop = nextop % placeval; // assign remainder to next place going rightward
}
else
{
digit = nextop; // if 1's place then just use the remaining digit
}
for ( j = 0; j < myradix ; j++ ) // loop through and draw cells from 0 to radix
{
if(c.orient == 1) // if vertically oriented
{
cellx = c.ulx + i;
celly = c.uly + (j * c.step);
}
else // if horizontally oriented
{
cellx = c.ulx + (j * c.step);
celly = c.uly + i;
}
m = cell[cellx][celly]; // This is the cell we will draw in
switch( c.ctype)
{
case 0: // normal data display
if( j < digit ) // fill in 'on' color from 0 through value of digit
{
m.message( "pict", drawcolor + coladj);
m.hidden = 0;
m.message(1);
}
else
{
m.hidden = 1;
}
break;
case 2: // momentary flash
if(j == digit) // only light up actual value, all others are blank
{
m.message( "pict", drawcolor + coladj);
m.hidden = 0;
m.message( "blinktime", c.blink ); // set the duration of blink
m.message("bang" );
}
else
{
m.hidden = 1;
}
break;
case 3: // radio button
if(j == digit) // only light up actual value, all others are blank
{
m.message( "pict", drawcolor + coladj);
m.hidden = 0;
m.message(1);
}
else
{
m.hidden = 1;
}
break;
}
}
}
}
// clean up the mess
//
function end( )
{
destroycells ( xmax, ymax );
}
//
//
function bang()
{
for( i = 0; i < xkey.length; i++ )
{
post ( "xkey: ", i, ":", xkey[i] );
post();
}
}
//
// expand or contract the structure by changing the cellspace n
//
function gridexpand( x, y, n )
{
var ulx;
var uly;
var lrx;
var lry;
post( "gridexpand: ", n );
post( );
// calculate new positions for all the objects
cellspace = n;
for( i = 0; i < x; i++ )
{
for ( j = 0 ; j < y; j++ )
{
ulx = xorigin + (i * cellspace);
uly = yorigin + (j * cellspace);
lrx = xorigin + (i * cellspace) + ledsize;
lry = yorigin + (j * cellspace) + ledsize;
cell[i][j].rect = [ ulx, uly, lrx, lry ];
}
}
}
// gate - sends message to ctrlin gates to open selected channel number
function gate( n, numsliders )
{
for ( i = 0; i < numsliders; i++ )
{
ctlgate[i].message ( n );
}
}
//
// setspace - sets the amount of space between cells - but does not move them if they already exist
//
function setspace(n)
{
cellspace = n
}
// destroycells - useful for debugging
//
function destroycells( x, y )
{
var p;
p = this.patcher;
for( i = 0; i < x; i++ )
{
for(j = 0; j < y; j++ )
{
if(cell[i][j].valid)
p.remove( cell[i][j] );
}
}
}
// newcolor send a new color to all cells
//
function newcolor(rows, cols, n)
{