forked from Chysn/O_C-HemisphereSuite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HEM_ADSREG_PLUS.ino
1515 lines (1307 loc) · 59.6 KB
/
HEM_ADSREG_PLUS.ino
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
// Copyright (c) 2018, Jason Justian
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
/*
ghostils:
Envelopes are now independent for control and mod source/destination allowing two individual ADSR's with Release MOD CV input per hemisphere.
* CV mod is now limited to release for each channel
* Output Level indicators have been shrunk to make room for additional on screen indicators for which envelope you are editing.
* Switching between envelopes is currently handled by simply pressing the encoder button until you pass the release stage on each envelope which will toggle the active envelope you are editing
* Envelope is indicated by A or B just above the ADSR segments.
*
* TODO Features/UI:
* *COMPLETE* Implement Menu System to select which EG and parameters to edit. (Attempt to keep this as one screen if possible). Would like to keep visual envelop editing, may need to implement timer based menu return with interruption time out.
*
* *COMPLETE* Add CV Routing selection to any STAGE.
* *COMPLETE* Add Envelope output scaling to not require external attenuator/attenuverter for flexibility.
* Add Gate triggered modulation source that can be assigned to any specific stage of the envelope and controlled by delayed number of gates or simple random probability.
* Underpants
* ???
* Profit?
*/
#include <stdlib.h>
#define HEM_EG_ATTACK 0
#define HEM_EG_DECAY 1
#define HEM_EG_SUSTAIN 2
#define HEM_EG_RELEASE 3
#define HEM_EG_NO_STAGE -1
#define HEM_EG_MAX_VALUE 255
#define HEM_SUSTAIN_CONST 35
#define HEM_EG_DISPLAY_HEIGHT 30
//-ghostils: DEFINE Main menu inactivity timeout ~5secs this will return the user to the main menu:
#define HEM_EG_UI_MENU_TIMEOUT_TICKS 41666
// About four seconds
#define HEM_EG_MAX_TICKS_AD 33333
// About eight seconds
#define HEM_EG_MAX_TICKS_R 133333
//-ghostils: Create menu items enum and some defines:
#define HEM_EG_UI_FIRST_MENU_ITEM 0
#define HEM_EG_UI_LAST_MENU_ITEM 9
#define HEM_EG_UI_FIRST_CV_MOD_DEST_ITEM 0
#define HEM_EG_UI_LAST_CV_MOD_DEST_ITEM 4
#define HEM_EG_UI_EG1_INT_MOD_TYPE_FIRST_ITEM 0
#define HEM_EG_UI_EG1_INT_MOD_TYPE_LAST_ITEM 1
#define HEM_EG_UI_EG2_INT_MOD_TYPE_FIRST_ITEM 0
#define HEM_EG_UI_EG2_INT_MOD_TYPE_LAST_ITEM 1
#define HEM_EG_UI_EG1_INT_GATE_DELAY_FIRST_ITEM 0
#define HEM_EG_UI_EG1_INT_GATE_DELAY_LAST_ITEM 1
#define HEM_EG_UI_EG2_INT_GATE_DELAY_FIRST_ITEM 0
#define HEM_EG_UI_EG2_INT_GATE_DELAY_LAST_ITEM 1
#define HEM_EG_UI_EG1_INT_PROB_FIRST_ITEM 0
#define HEM_EG_UI_EG1_INT_PROB_LAST_ITEM 1
#define HEM_EG_UI_EG2_INT_PROB_FIRST_ITEM 0
#define HEM_EG_UI_EG2_INT_PROB_LAST_ITEM 1
#define HEM_EG_UI_EG1_INT_GATE_DELAY_FIRST_PARAM 0
#define HEM_EG_UI_EG1_INT_GATE_DELAY_LAST_PARAM 2
#define HEM_EG_UI_EG1_INT_GATE_DELAY_MAX_STEPS 0
#define HEM_EG_UI_EG1_INT_GATE_DELAY_LENGTH 1
#define HEM_EG_UI_EG1_INT_GATE_DELAY_VALUE 2
#define HEM_EG_UI_EG2_INT_GATE_DELAY_FIRST_PARAM 0
#define HEM_EG_UI_EG2_INT_GATE_DELAY_LAST_PARAM 2
#define HEM_EG_UI_EG2_INT_GATE_DELAY_MAX_STEPS 0
#define HEM_EG_UI_EG2_INT_GATE_DELAY_LENGTH 1
#define HEM_EG_UI_EG2_INT_GATE_DELAY_VALUE 2
#define HEM_EG_UI_EG1_INT_PROB_FIRST_PARAM 0
#define HEM_EG_UI_EG1_INT_PROB_LAST_PARAM 2
#define HEM_EG_UI_EG1_INT_PROB_FIRST_TYPE 0
#define HEM_EG_UI_EG1_INT_PROB_LAST_TYPE 2
#define HEM_EG_UI_EG1_INT_PROB_TYPE_VAL 0
#define HEM_EG_UI_EG1_INT_PROB_TYPE_RND 1
#define HEM_EG_UI_EG1_INT_PROB_TYPE_SNH 2
#define HEM_EG_UI_EG1_INT_PROB_PERCENT 0
#define HEM_EG_UI_EG1_INT_PROB_TYPE 1
#define HEM_EG_UI_EG1_INT_PROB_VALUE 2
#define HEM_EG_UI_EG2_INT_PROB_FIRST_PARAM 0
#define HEM_EG_UI_EG2_INT_PROB_LAST_PARAM 2
#define HEM_EG_UI_EG2_INT_PROB_FIRST_TYPE 0
#define HEM_EG_UI_EG2_INT_PROB_LAST_TYPE 2
#define HEM_EG_UI_EG2_INT_PROB_TYPE_VAL 0
#define HEM_EG_UI_EG2_INT_PROB_TYPE_RND 1
#define HEM_EG_UI_EG2_INT_PROB_TYPE_SNH 2
#define HEM_EG_UI_EG2_INT_PROB_PERCENT 0
#define HEM_EG_UI_EG2_INT_PROB_TYPE 1
#define HEM_EG_UI_EG2_INT_PROB_VALUE 2
#define HEM_EG_UI_MAIN_MENU 0
#define HEM_EG_UI_EG1_MENU 1
#define HEM_EG_UI_EG2_MENU 2
#define HEM_EG_UI_CV1_DEST_MENU 3
#define HEM_EG_UI_CV2_DEST_MENU 4
#define HEM_EG_UI_EG1_ENV_OUT_STR 5
#define HEM_EG_UI_EG2_ENV_OUT_STR 6
#define HEM_EG_UI_EG1_INT_MOD_DEST_MENU 7
#define HEM_EG_UI_EG2_INT_MOD_DEST_MENU 8
#define HEM_EG_UI_EG1_INT_MOD_TYPE_MENU 9
#define HEM_EG_UI_EG2_INT_MOD_TYPE_MENU 10
#define HEM_EG_UI_SCREEN_WIDTH 64
#define HEM_EG_UI_SCREEN_HEIGHT 64
#define HEM_EG_UI_CHAR_WIDTH 8
#define HEM_EG_UI_CHAR_HEIGHT 8
#define HEM_EG_UI_MENU_ITEM_WIDTH 24
#define HEM_EG_UI_ENCODER_RIGHT 1
#define HEM_EG_UI_ENCODER_LEFT -1
typedef enum{
EG1_Edit = 0,
EG1_CV1_Mod_Dest = 1,
EG1_GateTriggered_Mod_Dest = 2,
EG1_GateTriggered_Mod_Type = 3,
EG1_Env_Out_Strength = 4,
EG2_Edit = 5,
EG2_CV2_Mod_Dest = 6,
EG2_GateTriggered_Mod_Dest = 7,
EG2_GateTriggered_Mod_Type = 8,
EG2_Env_Out_Strength = 9
}menuItems_t;
//-ghostils:Modulation Destinations:
typedef enum{
ATTACK = 0,
DECAY = 1,
SUSTAIN = 2,
RELEASE = 3,
STRENGTH = 4
}modDest_t;
//-ghostils:Internal Modulation Type:
typedef enum {
GATE_DELAY = 0,
PROBABILITY = 1
}intModType_t;
class ADSREGPLUS : public HemisphereApplet {
public:
const char* applet_name() { // Maximum 10 characters
return "ADSR PLUS";
}
void Start() {
edit_stage = 0;
//attack = 20;
//decay = 30;
//sustain = 120;
//release = 25;
ForEachChannel(ch)
{
stage_ticks[ch] = 0;
gated[ch] = 0;
stage[ch] = HEM_EG_NO_STAGE;
//-ghostils:Initialize ADSR and other 2 value arrays independently
attack[ch] = 20;
decay[ch] = 30;
sustain[ch] = 120;
release[ch] = 25;
release_mod[ch] = 0;
curIntModDestType[ch] = 0;
egGateCount[ch] = 0;
egProbGateCount[ch] = 0;
curIntAmpStr[ch] = 0;
//-ghostils:Default Envelope Output to 100% on each channel, allow user to scale as needed:
curCVAmpStr[ch] = 100;
}
//-ghostils:Multiple ADSR Envelope Tracking:
curEG = 0;
//-ghostils: Init UI Items:
curMenu = 0;
curMenuItem = 0;
curMenuTimeOutTicks = 0;
curCV1ModDest = 0;
curCV1ModDestItem = 0;
curCV2ModDest = 0;
curCV2ModDestItem = 0;
eg1IntGatedDelayEditPress = false;
eg1IntProbEditPress = false;
eg2IntGatedDelayEditPress = false;
eg2IntProbEditPress = false;
//-ghostils: Init mod destination values:
for(int i = 0; i < 2; i++){
for(int j = 0; j < 5; j++){
cvModDestVal[i][j] = 0;
intModDestVal[i][j] = 0;
intModProbDestVal[i][j] = 0;
}
}
cv1 = 0;
cv2 = 0;
curEG1IntModDest = 0;
curEG1IntModDestItem = 0;
curEG1IntModDestSubItem = 0;
curEG1IntModDestType = 0;
eg1IntDelayGateMaxSteps = 0;
eg1IntDelayGateStepLength = 0;
eg1IntDelayGateModValue = 0;
eg1IntDelayGateModActive = false;
curEG1IntGatedDelayItem = -1;
curEG1IntProbItem = -1;
eg1IntProbGatePercent = 0;
eg1IntProbGateStepLength = 0;
eg1IntProbGateModValue = 0;
eg1IntProbGateModActive = false;
eg1ProbTrigger = 0;
eg1ProbType = 0;
curEG2IntModDest = 0;
curEG2IntModDestItem = 0;
curEG2IntModDestSubItem = 0;
curEG2IntModDestType = 0;
curEG2IntGatedDelayItem = -1;
curEG2IntProbItem = -1;
eg2IntDelayGateMaxSteps = 0;
eg2IntDelayGateStepLength = 0;
eg2IntDelayGateModValue = 0;
eg2IntDelayGateModActive = false;
eg2IntProbGatePercent = 0;
eg2IntProbGateStepLength = 0;
eg2IntProbGateModValue = 0;
eg2IntProbGateModActive = false;
eg2ProbTrigger = 0;
eg2ProbType = 0;
}
void Controller() {
// Look for CV modification
//attack_mod = get_modification_with_input(0);
//release_mod[0] = get_modification_with_input(1);
//-ghostils: Update CV1/CV2 to support release only but on each ADSR independently:
//release_mod[0] = get_modification_with_input(0);
//release_mod[1] = get_modification_with_input(1);
cv1 = get_modification_with_input(0);
cv2 = get_modification_with_input(1);
//-ghostils: CV Destitinations:
//-ghostils:If we are using Probability and SNH break the connection to this mod destination and use the CV source for sample and hold:
if(eg1ProbType != HEM_EG_UI_EG1_INT_PROB_TYPE_SNH){
cvModDestVal[0][curCV1ModDestItem] = cv1;
}else{
cvModDestVal[0][curCV1ModDestItem] = 0;
}
if(eg2ProbType != HEM_EG_UI_EG2_INT_PROB_TYPE_SNH){
cvModDestVal[1][curCV2ModDestItem] = cv2;
}else{
cvModDestVal[1][curCV2ModDestItem] = 0;
}
ForEachChannel(ch)
{
if (Gate(ch)) {
if (!gated[ch]) { // The gate wasn't on last time, so this is a newly-gated EG
//-ghostils: Advance gate count for Gated / Probability modulation:
egGateCount[ch]++;
egProbGateCount[ch]++;
eg1ProbTrigger = getProbability(eg1IntProbGatePercent);
eg2ProbTrigger = getProbability(eg2IntProbGatePercent);
stage_ticks[ch] = 0;
if (stage[ch] != HEM_EG_RELEASE) amplitude[ch] = 0;
stage[ch] = HEM_EG_ATTACK;
AttackAmplitude(ch);
} else { // The gate is STILL on, so process the appopriate stage
stage_ticks[ch]++;
if (stage[ch] == HEM_EG_ATTACK) AttackAmplitude(ch);
if (stage[ch] == HEM_EG_DECAY) DecayAmplitude(ch);
if (stage[ch] == HEM_EG_SUSTAIN) SustainAmplitude(ch);
}
gated[ch] = 1;
} else {
if (gated[ch]) { // The gate was on last time, so this is a newly-released EG
stage[ch] = HEM_EG_RELEASE;
stage_ticks[ch] = 0;
}
if (stage[ch] == HEM_EG_RELEASE) { // Process the release stage, if necessary
stage_ticks[ch]++;
ReleaseAmplitude(ch);
}
gated[ch] = 0;
}
//-ghostils:GATED MODULATION:
//-ghostils:EG1 GATED Delay modulation: intModDestVal[ch][curEG1IntModDest]
if(eg1IntDelayGateMaxSteps != 0 && egGateCount[0] >= eg1IntDelayGateMaxSteps){
egGateCount[0] = 0;
eg1IntDelayGateModActive = true;
}else{
eg1IntDelayGateModActive = false;
}
//-ghostils:Apply EG1 Modulation value over X steps:
if(egGateCount[0] <= eg1IntDelayGateStepLength && eg1IntDelayGateModActive == true){
intModDestVal[0][curEG1IntModDestItem] = eg1IntDelayGateModValue;
} else if(egGateCount[0] >= eg1IntDelayGateStepLength){
intModDestVal[0][curEG1IntModDestItem] = 0;
eg1IntDelayGateModActive = false;
}
//-ghostils:EG2 GATED Delay modulation: intModDestVal[ch][curEG1IntModDest]
if(eg2IntDelayGateMaxSteps != 0 && egGateCount[1] >= eg2IntDelayGateMaxSteps){
egGateCount[1] = 0;
eg2IntDelayGateModActive = true;
}else{
eg2IntDelayGateModActive = false;
}
//-ghostils:Apply EG2 Modulation value over X steps:
if(egGateCount[1] <= eg2IntDelayGateStepLength && eg2IntDelayGateModActive == true){
intModDestVal[1][curEG2IntModDestItem] = eg2IntDelayGateModValue;
} else if(egGateCount[1] >= eg2IntDelayGateStepLength){
intModDestVal[1][curEG2IntModDestItem] = 0;
eg2IntDelayGateModActive = false;
}
//-ghostils:PROBABILITY MODULATION:
//-ghostils:Apply EG1 Probability based on static value "VAL" or Random "RND" using "VAL" as the ceiling or sampling the current incomming CV1 value for this gate:
if((egProbGateCount[0] < 1) && (eg1IntProbGatePercent == 100 || eg1ProbTrigger) && eg1IntProbGatePercent != 0){
switch(eg1ProbType){
//-ghostils:Static modulation value triggered when get a probability hit:
case HEM_EG_UI_EG1_INT_PROB_TYPE_VAL:
intModProbDestVal[0][curEG1IntModDestItem] = eg1IntProbGateModValue;
break;
case HEM_EG_UI_EG1_INT_PROB_TYPE_RND:
//-ghostils: If the static modulation value is not zero, we can use this to set a ceiling on the random modulation value:
if(eg1IntProbGateModValue !=0){
intModProbDestVal[0][curEG1IntModDestItem] = random(1,eg1IntProbGateModValue);
}
break;
//-Sample and hold the incomming CV value and scale between 0 and eg1IntProbGateModValue:
case HEM_EG_UI_EG1_INT_PROB_TYPE_SNH:
intModProbDestVal[0][curEG1IntModDestItem] = constrain(cv1,0,eg1IntProbGateModValue);
break;
}
} else if(egProbGateCount[0] > eg1IntProbGateStepLength){
egProbGateCount[0] = 0;
intModProbDestVal[0][curEG1IntModDestItem] = 0;
eg1IntProbGateModActive = false;
}
//-ghostils:Apply EG2 Probability based on static value "VAL" or Random "RND" using "VAL" as the ceiling or sampling the current incomming CV1 value for this gate:
if((egProbGateCount[1] < 1) && (eg2IntProbGatePercent == 100 || eg2ProbTrigger) && eg2IntProbGatePercent != 0){
switch(eg2ProbType){
//-ghostils:Static modulation value triggered when get a probability hit:
case HEM_EG_UI_EG2_INT_PROB_TYPE_VAL:
intModProbDestVal[1][curEG2IntModDestItem] = eg2IntProbGateModValue;
break;
case HEM_EG_UI_EG2_INT_PROB_TYPE_RND:
//-ghostils: If the static modulation value is not zero, we can use this to set a ceiling on the random modulation value:
if(eg2IntProbGateModValue !=0){
intModProbDestVal[1][curEG2IntModDestItem] = random(1,eg2IntProbGateModValue);
}
break;
//-Sample and hold the incomming CV value and scale between 0 and eg2IntProbGateModValue:
case HEM_EG_UI_EG2_INT_PROB_TYPE_SNH:
intModProbDestVal[1][curEG2IntModDestItem] = constrain(cv2,0,eg2IntProbGateModValue);
break;
}
} else if(egProbGateCount[1] > eg2IntProbGateStepLength){
egProbGateCount[1] = 0;
intModProbDestVal[1][curEG2IntModDestItem] = 0;
eg2IntProbGateModActive = false;
}
//-ghostils:Attenuate/Proportion Output based on EG strength value: Lock to 0 - MAX CV add any modulation from CV and internal
//Out(ch, GetAmplitudeOf(ch));
int signal = Proportion(GetAmplitudeOf(ch),100,curCVAmpStr[ch] + cvModDestVal[ch][STRENGTH] + intModDestVal[ch][STRENGTH] + intModProbDestVal[ch][STRENGTH]);
Out(ch,constrain(signal,0,HEMISPHERE_MAX_CV));
}
//-ghostils:Return to main menu after inactivity time out:
if(curMenuTimeOutTicks >= HEM_EG_UI_MENU_TIMEOUT_TICKS){
curMenuTimeOutTicks = 0;
curMenu = HEM_EG_UI_MAIN_MENU;
}else{
curMenuTimeOutTicks++;
}
}
void View() {
gfxHeader(applet_name());
//-ghostils: Don't draw ADSR or Indicators while in MAIN MENU:
switch(curMenu){
case HEM_EG_UI_EG1_MENU:
DrawIndicator();
DrawADSR();
break;
case HEM_EG_UI_EG2_MENU:
DrawIndicator();
DrawADSR();
break;
case HEM_EG_UI_CV1_DEST_MENU:
DrawMainMenu();
DrawCV1ModDestMenu();
break;
case HEM_EG_UI_CV2_DEST_MENU:
DrawMainMenu();
DrawCV2ModDestMenu();
break;
case HEM_EG_UI_EG1_INT_MOD_DEST_MENU:
DrawMainMenu();
DrawIntEG1ModDestMenu();
break;
case HEM_EG_UI_EG1_INT_MOD_TYPE_MENU:
DrawIntEG1ModTypeMenu();
break;
case HEM_EG_UI_EG2_INT_MOD_DEST_MENU:
DrawMainMenu();
DrawIntEG2ModDestMenu();
break;
case HEM_EG_UI_EG2_INT_MOD_TYPE_MENU:
DrawIntEG2ModTypeMenu();
break;
case HEM_EG_UI_EG1_ENV_OUT_STR:
DrawMainMenu();
DrawEG1OutStrMenu();
break;
case HEM_EG_UI_EG2_ENV_OUT_STR:
DrawMainMenu();
DrawEG2OutStrMenu();
break;
default:
DrawMainMenu();
break;
}
}
void OnButtonPress() {
//-ghostils:If we are pressing buttons we are not timing out reset the timer:
curMenuTimeOutTicks = 0;
//-ghostils: EG1 Mod Type Sub Menu:
if(curMenu == HEM_EG_UI_EG1_INT_MOD_TYPE_MENU){
switch(curEG1IntModDestSubItem){
case GATE_DELAY:
eg1IntGatedDelayEditPress = true;
curIntModDestType[0] = GATE_DELAY;
if(curEG1IntGatedDelayItem == -1){
curEG1IntGatedDelayItem = HEM_EG_UI_EG1_INT_GATE_DELAY_FIRST_PARAM;
} else if( curEG1IntGatedDelayItem == HEM_EG_UI_EG1_INT_GATE_DELAY_LAST_PARAM){
curEG1IntGatedDelayItem = HEM_EG_UI_EG1_INT_GATE_DELAY_FIRST_PARAM;
}else {
curEG1IntGatedDelayItem++;
}
break;
case PROBABILITY:
eg1IntProbEditPress = true;
curIntModDestType[0] = PROBABILITY;
if(curEG1IntProbItem == -1){
curEG1IntProbItem = HEM_EG_UI_EG1_INT_PROB_FIRST_PARAM;
} else if( curEG1IntProbItem == HEM_EG_UI_EG1_INT_PROB_LAST_PARAM){
curEG1IntProbItem = HEM_EG_UI_EG1_INT_PROB_FIRST_PARAM;
}else {
curEG1IntProbItem++;
}
break;
default:
break;
}
}
//-ghostils: EG2 Mod Type Sub Menu:
if(curMenu == HEM_EG_UI_EG2_INT_MOD_TYPE_MENU){
switch(curEG2IntModDestSubItem){
case GATE_DELAY:
eg2IntGatedDelayEditPress = true;
curIntModDestType[1] = GATE_DELAY;
if(curEG2IntGatedDelayItem == -1){
curEG2IntGatedDelayItem = HEM_EG_UI_EG2_INT_GATE_DELAY_FIRST_PARAM;
} else if( curEG2IntGatedDelayItem == HEM_EG_UI_EG2_INT_GATE_DELAY_LAST_PARAM){
curEG2IntGatedDelayItem = HEM_EG_UI_EG2_INT_GATE_DELAY_FIRST_PARAM;
}else {
curEG2IntGatedDelayItem++;
}
break;
case PROBABILITY:
eg2IntProbEditPress = true;
curIntModDestType[1] = PROBABILITY;
if(curEG2IntProbItem == -1){
curEG2IntProbItem = HEM_EG_UI_EG2_INT_PROB_FIRST_PARAM;
} else if( curEG2IntProbItem == HEM_EG_UI_EG2_INT_PROB_LAST_PARAM){
curEG2IntProbItem = HEM_EG_UI_EG2_INT_PROB_FIRST_PARAM;
}else {
curEG2IntProbItem++;
}
break;
default:
break;
}
}
//-ghostils: Menu selection:
if(curMenu == HEM_EG_UI_MAIN_MENU){
switch(curMenuItem){
case EG1_Edit:
curMenu = HEM_EG_UI_EG1_MENU;
curEG = 0;
edit_stage = HEM_EG_ATTACK;
break;
case EG2_Edit:
curMenu = HEM_EG_UI_EG2_MENU;
curEG = 1;
edit_stage = HEM_EG_ATTACK;
break;
case EG1_CV1_Mod_Dest:
curMenu = HEM_EG_UI_CV1_DEST_MENU;
break;
case EG2_CV2_Mod_Dest:
curMenu = HEM_EG_UI_CV2_DEST_MENU;
break;
case EG1_GateTriggered_Mod_Dest:
curMenu = HEM_EG_UI_EG1_INT_MOD_DEST_MENU;
break;
case EG2_GateTriggered_Mod_Dest:
curMenu = HEM_EG_UI_EG2_INT_MOD_DEST_MENU;
break;
case EG1_GateTriggered_Mod_Type:
curMenu = HEM_EG_UI_EG1_INT_MOD_TYPE_MENU;
//-ghostils: Always set the value of the 1st item and ensure we are NOT in sub item edit mode:
curEG1IntGatedDelayItem = -1;
eg1IntGatedDelayEditPress = false;
curEG1IntProbItem = -1;
eg1IntProbEditPress = false;
break;
case EG2_GateTriggered_Mod_Type:
curMenu = HEM_EG_UI_EG2_INT_MOD_TYPE_MENU;
//-ghostils: Always set the value of the 1st item and ensure we are NOT in sub item edit mode:
curEG2IntGatedDelayItem = -1;
eg2IntGatedDelayEditPress = false;
curEG2IntProbItem = -1;
eg2IntProbEditPress = false;
break;
case EG1_Env_Out_Strength:
curMenu = HEM_EG_UI_EG1_ENV_OUT_STR;
break;
case EG2_Env_Out_Strength:
curMenu = HEM_EG_UI_EG2_ENV_OUT_STR;
break;
default:
curMenu = HEM_EG_UI_MAIN_MENU;
break;
}
//-ghostils:Return after switch selection we don't want to impact other clicks if set immediately we may add a click to other down stream items here:
return;
}
//if (++edit_stage > HEM_EG_RELEASE) {edit_stage = HEM_EG_ATTACK;}
//-ghostils: Allow selecting stages ONLY if we are in the EG1/EG2 menu:
if(curMenu == HEM_EG_UI_EG1_MENU || curMenu == HEM_EG_UI_EG2_MENU){
if (++edit_stage > HEM_EG_RELEASE) {edit_stage = HEM_EG_ATTACK;}
}
}
//-ghostils:OMG FIX THIS STUPID SHIT (after it all works though =D)
void OnEncoderMove(int direction) {
//-ghostils:If we are twiddling knobs we are not timing out reset the timer
curMenuTimeOutTicks = 0;
//-ghostils: Drive Basic Menu Navigation:
if(direction == HEM_EG_UI_ENCODER_RIGHT && curMenu == HEM_EG_UI_MAIN_MENU){
if(curMenuItem == HEM_EG_UI_LAST_MENU_ITEM){
curMenuItem = HEM_EG_UI_FIRST_MENU_ITEM;
}else{
curMenuItem++;
}
}else if(direction == HEM_EG_UI_ENCODER_LEFT && curMenu == HEM_EG_UI_MAIN_MENU){
if(curMenuItem == HEM_EG_UI_FIRST_MENU_ITEM){
curMenuItem = HEM_EG_UI_LAST_MENU_ITEM;
}else{
curMenuItem--;
}
}
//-ghostils:Reference curEG as the indexer to current ADSR when editing stages:
if(curMenu == HEM_EG_UI_EG1_MENU || curMenu == HEM_EG_UI_EG2_MENU) {
int adsr[4] = {attack[curEG], decay[curEG], sustain[curEG], release[curEG]};
adsr[edit_stage] = constrain(adsr[edit_stage] += direction, 1, HEM_EG_MAX_VALUE);
attack[curEG] = adsr[HEM_EG_ATTACK];
decay[curEG] = adsr[HEM_EG_DECAY];
sustain[curEG] = adsr[HEM_EG_SUSTAIN];
release[curEG] = adsr[HEM_EG_RELEASE];
}
//-ghostils:CV1 Mod Destination:
if(direction == HEM_EG_UI_ENCODER_RIGHT && curMenu == HEM_EG_UI_CV1_DEST_MENU){
if(curCV1ModDestItem == HEM_EG_UI_LAST_CV_MOD_DEST_ITEM){
curCV1ModDestItem = HEM_EG_UI_FIRST_CV_MOD_DEST_ITEM;
//-ghostils:clear existing destination before setting new:
for(int i = 0; i < 5; i++) {cvModDestVal[0][i] = 0;}
}else{
curCV1ModDestItem++;
//-ghostils:clear existing destination before setting new:
for(int i = 0; i < 5; i++) {cvModDestVal[0][i] = 0;}
}
} else if(direction == HEM_EG_UI_ENCODER_LEFT && curMenu == HEM_EG_UI_CV1_DEST_MENU) {
if(curCV1ModDestItem == HEM_EG_UI_FIRST_CV_MOD_DEST_ITEM){
//-ghostils:clear existing destination before setting new:
curCV1ModDestItem = HEM_EG_UI_LAST_CV_MOD_DEST_ITEM;
for(int i = 0; i < 5; i++) {cvModDestVal[0][i] = 0;}
}else{
curCV1ModDestItem--;
//-ghostils:clear existing destination before setting new:
for(int i = 0; i < 5; i++) {cvModDestVal[0][i] = 0;}
}
}
//-ghostils:CV2 Mod Destination:
if(direction == HEM_EG_UI_ENCODER_RIGHT && curMenu == HEM_EG_UI_CV2_DEST_MENU){
if(curCV2ModDestItem == HEM_EG_UI_LAST_CV_MOD_DEST_ITEM){
curCV2ModDestItem = HEM_EG_UI_FIRST_CV_MOD_DEST_ITEM;
//-ghostils:clear existing destination before setting new:
for(int i = 0; i < 5; i++) {cvModDestVal[1][i] = 0;}
}else{
curCV2ModDestItem++;
//-ghostils:clear existing destination before setting new:
for(int i = 0; i < 5; i++) {cvModDestVal[1][i] = 0;}
}
} else if(direction == HEM_EG_UI_ENCODER_LEFT && curMenu == HEM_EG_UI_CV2_DEST_MENU) {
if(curCV2ModDestItem == HEM_EG_UI_FIRST_CV_MOD_DEST_ITEM){
//-ghostils:clear existing destination before setting new:
curCV2ModDestItem = HEM_EG_UI_LAST_CV_MOD_DEST_ITEM;
for(int i = 0; i < 5; i++) {cvModDestVal[1][i] = 0;}
}else{
curCV2ModDestItem--;
//-ghostils:clear existing destination before setting new:
for(int i = 0; i < 5; i++) {cvModDestVal[1][i] = 0;}
}
}
//-ghostils:EG1 Amp Output Strength:
if(direction == HEM_EG_UI_ENCODER_RIGHT && curMenu == HEM_EG_UI_EG1_ENV_OUT_STR){
if(curCVAmpStr[0] >= 100){
curCVAmpStr[0] = 0;
}else{
curCVAmpStr[0]++;
}
} else if(direction == HEM_EG_UI_ENCODER_LEFT && curMenu == HEM_EG_UI_EG1_ENV_OUT_STR) {
if(curCVAmpStr[0] <= 0){
curCVAmpStr[0] = 100;
}else{
curCVAmpStr[0]--;
}
}
//-ghostils:EG2 Amp Output Strength:
if(direction == HEM_EG_UI_ENCODER_RIGHT && curMenu == HEM_EG_UI_EG2_ENV_OUT_STR){
if(curCVAmpStr[1] >= 100){
curCVAmpStr[1] = 0;
}else{
curCVAmpStr[1]++;
}
} else if(direction == HEM_EG_UI_ENCODER_LEFT && curMenu == HEM_EG_UI_EG2_ENV_OUT_STR) {
if(curCVAmpStr[1] <= 0){
curCVAmpStr[1] = 100;
}else{
curCVAmpStr[1]--;
}
}
//-ghostils:Internal Mod Destination EG1
if(direction == HEM_EG_UI_ENCODER_RIGHT && curMenu == HEM_EG_UI_EG1_INT_MOD_DEST_MENU){
if(curEG1IntModDestItem == HEM_EG_UI_LAST_CV_MOD_DEST_ITEM){
curEG1IntModDestItem = HEM_EG_UI_FIRST_CV_MOD_DEST_ITEM;
//-ghostils:clear existing destination before setting new:
for(int i = 0; i < 5; i++) {intModDestVal[0][i] = 0;}
for(int i = 0; i < 5; i++) {intModProbDestVal[0][i] = 0;}
}else{
curEG1IntModDestItem++;
//-ghostils:clear existing destination before setting new:
for(int i = 0; i < 5; i++) {intModDestVal[0][i] = 0;}
for(int i = 0; i < 5; i++) {intModProbDestVal[0][i] = 0;}
}
} else if(direction == HEM_EG_UI_ENCODER_LEFT && curMenu == HEM_EG_UI_EG1_INT_MOD_DEST_MENU) {
if(curEG1IntModDestItem == HEM_EG_UI_FIRST_CV_MOD_DEST_ITEM){
//-ghostils:clear existing destination before setting new:
curEG1IntModDestItem = HEM_EG_UI_LAST_CV_MOD_DEST_ITEM;
for(int i = 0; i < 5; i++) {intModDestVal[0][i] = 0;}
for(int i = 0; i < 5; i++) {intModProbDestVal[0][i] = 0;}
}else{
curEG1IntModDestItem--;
//-ghostils:clear existing destination before setting new:
for(int i = 0; i < 5; i++) {intModDestVal[0][i] = 0;}
for(int i = 0; i < 5; i++) {intModProbDestVal[0][i] = 0;}
}
}
//-ghostils:Internal Mod Destination EG2
if(direction == HEM_EG_UI_ENCODER_RIGHT && curMenu == HEM_EG_UI_EG2_INT_MOD_DEST_MENU){
if(curEG2IntModDestItem == HEM_EG_UI_LAST_CV_MOD_DEST_ITEM){
curEG2IntModDestItem = HEM_EG_UI_FIRST_CV_MOD_DEST_ITEM;
//-ghostils:clear existing destination before setting new:
for(int i = 0; i < 5; i++) {intModDestVal[1][i] = 0;}
}else{
curEG2IntModDestItem++;
//-ghostils:clear existing destination before setting new:
for(int i = 0; i < 5; i++) {intModDestVal[1][i] = 0;}
}
} else if(direction == HEM_EG_UI_ENCODER_LEFT && curMenu == HEM_EG_UI_EG2_INT_MOD_DEST_MENU) {
if(curEG2IntModDestItem == HEM_EG_UI_FIRST_CV_MOD_DEST_ITEM){
//-ghostils:clear existing destination before setting new:
curEG2IntModDestItem = HEM_EG_UI_LAST_CV_MOD_DEST_ITEM;
for(int i = 0; i < 5; i++) {intModDestVal[1][i] = 0;}
}else{
curEG2IntModDestItem--;
//-ghostils:clear existing destination before setting new:
for(int i = 0; i < 5; i++) {intModDestVal[1][i] = 0;}
}
}
//-ghostils:Internal Mod Type Sub Menu: EG1
if(direction == HEM_EG_UI_ENCODER_RIGHT && curMenu == HEM_EG_UI_EG1_INT_MOD_TYPE_MENU){
if(eg1IntGatedDelayEditPress == false && eg1IntProbEditPress == false){
if(curEG1IntModDestSubItem == HEM_EG_UI_EG1_INT_MOD_TYPE_LAST_ITEM){
curEG1IntModDestSubItem = HEM_EG_UI_EG1_INT_MOD_TYPE_FIRST_ITEM;
}else{
curEG1IntModDestSubItem++;
}
//-ghostils: Set Mod TYPE Sub Parameter Options for Gated Delay:
} else if(eg1IntGatedDelayEditPress == true) {
if (curEG1IntGatedDelayItem == HEM_EG_UI_EG1_INT_GATE_DELAY_MAX_STEPS) {
if(eg1IntDelayGateMaxSteps >= 128){
eg1IntDelayGateMaxSteps = 0;
} else {
eg1IntDelayGateMaxSteps++;
}
}
if (curEG1IntGatedDelayItem == HEM_EG_UI_EG1_INT_GATE_DELAY_LENGTH) {
if(eg1IntDelayGateStepLength >= eg1IntDelayGateMaxSteps){
//-This should always be atleast one step:
eg1IntDelayGateStepLength = 0;
} else {
eg1IntDelayGateStepLength++;
}
}
if (curEG1IntGatedDelayItem == HEM_EG_UI_EG1_INT_GATE_DELAY_VALUE) {
if(eg1IntDelayGateModValue >= 100){
eg1IntDelayGateModValue = 0;
} else {
eg1IntDelayGateModValue++;
}
}
//-ghostils: Set Mod TYPE sub parameter for probability:
} else if(eg1IntProbEditPress == true) {
if (curEG1IntProbItem == HEM_EG_UI_EG1_INT_PROB_PERCENT) {
if(eg1IntProbGatePercent >= 100){
eg1IntProbGatePercent = 0;
} else {
eg1IntProbGatePercent++;
}
}
if (curEG1IntProbItem == HEM_EG_UI_EG1_INT_PROB_TYPE) {
if(eg1ProbType >= HEM_EG_UI_EG2_INT_PROB_LAST_PARAM){
//-This should always be atleast one step:
eg1ProbType = HEM_EG_UI_EG2_INT_PROB_FIRST_PARAM;
} else {
eg1ProbType++;
}
}
if (curEG1IntProbItem == HEM_EG_UI_EG1_INT_PROB_VALUE) {
if(eg1IntProbGateModValue >= 100){
eg1IntProbGateModValue = 0;
} else {
eg1IntProbGateModValue++;
}
}
}
} else if(direction == HEM_EG_UI_ENCODER_LEFT && curMenu == HEM_EG_UI_EG1_INT_MOD_TYPE_MENU) {
if(eg1IntGatedDelayEditPress == false && eg1IntProbEditPress == false) {
if(curEG1IntModDestSubItem== HEM_EG_UI_EG1_INT_MOD_TYPE_FIRST_ITEM){
//-ghostils:clear existing destination before setting new:
curEG1IntModDestSubItem = HEM_EG_UI_EG1_INT_MOD_TYPE_LAST_ITEM;
}else{
curEG1IntModDestSubItem--;
}
} else if(eg1IntGatedDelayEditPress == true) {
if (curEG1IntGatedDelayItem == HEM_EG_UI_EG1_INT_GATE_DELAY_MAX_STEPS) {
if(eg1IntDelayGateMaxSteps <= 0){
eg1IntDelayGateMaxSteps = 128;
} else if (eg2IntDelayGateStepLength > eg2IntDelayGateMaxSteps) {
eg1IntDelayGateStepLength = eg1IntDelayGateMaxSteps;
} else {
eg1IntDelayGateMaxSteps--;
}
}
if (curEG1IntGatedDelayItem == HEM_EG_UI_EG1_INT_GATE_DELAY_LENGTH) {
if(eg1IntDelayGateStepLength <= 0){
eg1IntDelayGateStepLength = eg1IntDelayGateMaxSteps;
} else {
eg1IntDelayGateStepLength--;
}
}
if (curEG1IntGatedDelayItem == HEM_EG_UI_EG1_INT_GATE_DELAY_VALUE) {
if(eg1IntDelayGateModValue <= 0){
eg1IntDelayGateModValue = 100;
} else {
eg1IntDelayGateModValue--;
}
}
//-ghostils: Set Mod TYPE sub parameter for probability:
} else if(eg1IntProbEditPress == true) {
if (curEG1IntProbItem == HEM_EG_UI_EG1_INT_PROB_PERCENT) {
if(eg1IntProbGatePercent <= 0){
eg1IntProbGatePercent = 100;
} else {
eg1IntProbGatePercent--;
}
}
if (curEG1IntProbItem == HEM_EG_UI_EG1_INT_PROB_TYPE) {
if(eg1ProbType <= HEM_EG_UI_EG1_INT_PROB_FIRST_PARAM){
//-This should always be atleast one step:
eg1ProbType = HEM_EG_UI_EG1_INT_PROB_LAST_PARAM;
} else {
eg1ProbType--;
}
}
if (curEG1IntProbItem == HEM_EG_UI_EG1_INT_PROB_VALUE) {
if(eg1IntProbGateModValue <= 0){
eg1IntProbGateModValue = 100;
} else {
eg1IntProbGateModValue--;
}
}
}
}
//-ghostils:Internal Mod Type Sub Menu: EG2
if(direction == HEM_EG_UI_ENCODER_RIGHT && curMenu == HEM_EG_UI_EG2_INT_MOD_TYPE_MENU){
if(eg2IntGatedDelayEditPress == false && eg2IntProbEditPress == false){
if(curEG2IntModDestSubItem == HEM_EG_UI_EG2_INT_MOD_TYPE_LAST_ITEM){
curEG2IntModDestSubItem = HEM_EG_UI_EG2_INT_MOD_TYPE_FIRST_ITEM;
}else{
curEG2IntModDestSubItem++;
}
//-ghostils: Set Mod TYPE Sub Parameter Optiosn:
} else if(eg2IntGatedDelayEditPress == true) {
if (curEG2IntGatedDelayItem == HEM_EG_UI_EG2_INT_GATE_DELAY_MAX_STEPS) {
if(eg2IntDelayGateMaxSteps >= 128){
eg2IntDelayGateMaxSteps = 0;
} else {
eg2IntDelayGateMaxSteps++;
}
}
if (curEG2IntGatedDelayItem == HEM_EG_UI_EG2_INT_GATE_DELAY_LENGTH) {
if(eg2IntDelayGateStepLength >= eg2IntDelayGateMaxSteps){
//-This should always be atleast one step:
eg2IntDelayGateStepLength = 0;
} else {
eg2IntDelayGateStepLength++;
}
}
if (curEG2IntGatedDelayItem == HEM_EG_UI_EG2_INT_GATE_DELAY_VALUE) {
if(eg2IntDelayGateModValue >= 100){
eg2IntDelayGateModValue = 0;
} else {
eg2IntDelayGateModValue++;
}
}
//-ghostils: Set Mod TYPE sub parameter for probability:
} else if(eg2IntProbEditPress == true) {
if (curEG2IntProbItem == HEM_EG_UI_EG2_INT_PROB_PERCENT) {
if(eg2IntProbGatePercent >= 100){
eg2IntProbGatePercent = 0;
} else {
eg2IntProbGatePercent++;
}
}
if (curEG2IntProbItem == HEM_EG_UI_EG2_INT_PROB_TYPE) {
if(eg2ProbType >= HEM_EG_UI_EG2_INT_PROB_LAST_PARAM){
//-This should always be atleast one step:
eg2ProbType = HEM_EG_UI_EG2_INT_PROB_FIRST_PARAM;
} else {
eg2ProbType++;
}
}
if (curEG2IntProbItem == HEM_EG_UI_EG2_INT_PROB_VALUE) {
if(eg2IntProbGateModValue >= 100){
eg2IntProbGateModValue = 0;
} else {
eg2IntProbGateModValue++;
}
}
}
} else if(direction == HEM_EG_UI_ENCODER_LEFT && curMenu == HEM_EG_UI_EG2_INT_MOD_TYPE_MENU) {
if(eg2IntGatedDelayEditPress == false && eg2IntProbEditPress == false) {
if(curEG2IntModDestSubItem == HEM_EG_UI_EG2_INT_MOD_TYPE_FIRST_ITEM){
//-ghostils:clear existing destination before setting new:
curEG2IntModDestSubItem = HEM_EG_UI_EG2_INT_MOD_TYPE_LAST_ITEM;