-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy patheuropi_gui.c
executable file
·2439 lines (2361 loc) · 97.1 KB
/
europi_gui.c
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 2016 Richard R. Goodwin / Audio Morphology
//
// Author: Richard R. Goodwin ([email protected])
//
// 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.
//
// See http://creativecommons.org/licenses/MIT/ for more information.
#include <stdio.h>
#include <string.h>
#include "europi.h"
#include "../raylib/src/raylib.h"
extern int clock_freq;
extern int step_ticks;
extern int prog_running;
extern int run_stop;
extern int save_run_stop;
extern int last_track;
extern int SingleChannelOffset;
extern Vector2 touchPosition;
extern int currentGesture;
extern int lastGesture;
extern menu Menu[];
extern char input_txt[];
extern char current_filename[];
extern char modal_dialog_txt1[];
extern char modal_dialog_txt2[];
extern char modal_dialog_txt3[];
extern char modal_dialog_txt4[];
extern Texture2D KeyboardTexture;
extern Texture2D DialogTexture;
extern Texture2D SmallDialogTexture;
extern Texture2D TextInputTexture;
extern Texture2D Text2chTexture;
extern Texture2D Text5chTexture;
extern Texture2D Text10chTexture;
extern Texture2D MainScreenTexture;
extern Texture2D TopBarTexture;
extern Texture2D ButtonBarTexture;
extern Texture2D VerticalScrollBarTexture;
extern Texture2D VerticalScrollBarShortTexture;
extern Texture2D ScrollHandleTexture;
extern int VerticalScrollPercent;
extern char *kbd_chars[4][11];
extern char debug_messages[10][80];
extern int next_debug_slot;
extern int kbd_char_selected;
extern int selected_step;
extern enum encoder_focus_t encoder_focus;
extern enum btnA_func_t btnA_func;
extern enum btnB_func_t btnB_func;
extern enum btnC_func_t btnC_func;
extern enum btnD_func_t btnD_func;
extern int btnA_state;
extern int btnB_state;
extern int btnC_state;
extern int btnD_state;
extern int edit_track;
extern int edit_step;
//extern struct screen_overlays ScreenOverlays;
extern uint32_t ActiveOverlays;
extern enum display_page_t DisplayPage;
extern struct europi Europi;
extern char **files;
extern size_t file_count;
extern int file_selected;
extern int first_file;
extern int debug;
extern pthread_attr_t detached_attr;
extern pthread_t ThreadId;
/*
* GUI_8x8 Attempts to display more detail in a subset of tracks and steps
* 8 Tracks x 8 Steps
*/
void gui_8x8(void){
Rectangle stepRectangle = {0,0,0,0};
Rectangle trackRectangle = {0,0,0,0};
int start_track,track, column;
int step, offset, txt_len;
char txt[20];
/* Depending on the total number of tracks, and the position
* of the vertical scroll bar, the starting track will vary
*/
if(last_track > 8){
start_track = ((last_track-8) * VerticalScrollPercent) / 100;
/* Don't display the Vertical Scroll Bar in certain situations */
if(ActiveOverlays & ovl_Keyboard) {
ActiveOverlays &= ~ovl_VerticalScrollBar;
}
else {
ActiveOverlays |= ovl_VerticalScrollBar;
}
}
else {
start_track = 0;
ActiveOverlays &= ~ovl_VerticalScrollBar;
}
BeginDrawing();
DrawTexture(MainScreenTexture,0,0,WHITE);
int vOffset = 0;
if(ShortScroll()) vOffset=20;
for(track = 0; track < 8; track++){
// Can only display 8 tracks, so need to know which
// track we are starting with, and display the next 7
offset = Europi.tracks[start_track+track].current_step / 8;
sprintf(txt,"%02d-%d:",start_track+track+1,(offset * 8)+1);
txt_len = MeasureText(txt,20);
if(start_track+track < last_track){
DrawText(txt,68-txt_len,12+(vOffset+(track * 25)),20,DARKGRAY);
DrawRectangleLines(4,vOffset+8+(track * 25),67,26,DARKGRAY);
} else {
// in-active tracks greyed-out
DrawText(txt,68-txt_len,12+(vOffset+(track * 25)),20,LIGHTGRAY);
DrawRectangleLines(4,vOffset+8+(track * 25),67,26,LIGHTGRAY);
}
// Check for Track select
trackRectangle.x = 4;
trackRectangle.y = vOffset + 8 + (track * 25);
trackRectangle.width = 67;
trackRectangle.height = 26;
// Only if no menus or overlays active, and this track isn't beyond the end track
if (CheckCollisionPointRec(touchPosition, trackRectangle) && (currentGesture != GESTURE_NONE) && (start_track+track < last_track)){
if(OverlayActive( ovl_VerticalScrollBar ) == 0){
// Open this track in a Single Channel view
edit_track = start_track+track;
select_track(start_track+track);
ClearScreenOverlays();
SwitchChannelFunction(edit_track);
encoder_focus = track_select;
}
else {
// Just update the selected track
select_track(start_track+track);
encoder_focus = track_select;
}
}
for(column=0;column<8;column++){
stepRectangle.x = 70 + (column * 25);
stepRectangle.y = vOffset + 10 + (track * 25);
stepRectangle.width = 22;
stepRectangle.height = 22;
if(start_track+track < last_track) {
// Check gesture collision
if (CheckCollisionPointRec(touchPosition, stepRectangle) && (currentGesture == GESTURE_DOUBLETAP)){
if(OverlayActive(ovl_VerticalScrollBar) == 0){
// Only if no Menus or Overlays active
// Open this step in the Single Step editor
edit_track = start_track+track;
edit_step = (offset*8)+column;
select_track(start_track+track);
ClearScreenOverlays();
DisplayPage = SingleStep;
ActiveOverlays |= ovl_SingleStep;
encoder_focus = step_select;
btnA_func = btnA_none;
btnB_func = btnB_prev;
btnC_func = btnC_next;
btnD_func = btnD_done;
save_run_stop = run_stop;
}
else {
select_track(start_track+track);
edit_step = (offset*8)+column;
encoder_focus = step_select;
}
}
if((offset*8)+column >= Europi.tracks[start_track+track].last_step){
// beyond the last step, just paint black squares
DrawRectangleRec(stepRectangle, BLACK);
}
else if((offset*8)+column == Europi.tracks[start_track+track].current_step){
// Paint current step
DrawRectangleRec(stepRectangle, LIME);
}
else {
// paint blank step
DrawRectangleRec(stepRectangle, MAROON);
}
}
else {
DrawRectangleRec(stepRectangle,LIGHTGRAY);
}
}
// Print the end-step number at the RHS of each row
sprintf(txt,":%d",(offset * 8)+8);
if(start_track+track < last_track) {
DrawText(txt,270,12+(vOffset+(track * 25)),20,DARKGRAY);
}
else {
DrawText(txt,270,12+(vOffset+(track * 25)),20,LIGHTGRAY);
}
}
// Handle any screen overlays - these need to
// be added within the Drawing loop
ShowScreenOverlays();
EndDrawing();
}
/*
* GUI_SINGLESTEP enables editing of all params
* to do with a single step
*/
void gui_singlestep(void){
int column, offset, txt_len;
char txt[20];
Rectangle stepRectangle = {0,0,0,0};
Rectangle touchRectangle = {0,0,0,0};
BeginDrawing();
DrawTexture(MainScreenTexture,0,0,WHITE);
// Items to cover:
// Track Type (CV / MIDI)
// Quantization
// Pitch
// Gate / Trigger
// Slew
// Step Repeat
// DrawRectangle(6,29, 308, 183, CLR_LIGHTBLUE);
// Draw the current Track 8-Step segement
offset = edit_step / 8; //Europi.tracks[edit_track].current_step / 8;
sprintf(txt,"%02d-%d:",edit_track+1,(offset * 8)+1);
txt_len = MeasureText(txt,20);
DrawText(txt,68-txt_len,34,20,DARKGRAY);
// Check for tap on this to switch to Track view
touchRectangle.x = 8;
touchRectangle.y = 34;
touchRectangle.width = 60;
touchRectangle.height = 20;
if (CheckCollisionPointRec(touchPosition, touchRectangle) && (currentGesture != GESTURE_NONE)){
// Switch to Track View
ClearScreenOverlays();
SwitchChannelFunction(edit_track);
encoder_focus = track_select;
}
for(column=0;column<8;column++){
stepRectangle.x = 70 + (column * 25);
stepRectangle.y = 33;
stepRectangle.width = 22;
stepRectangle.height = 22;
// Check gesture collision
if (CheckCollisionPointRec(touchPosition, stepRectangle) && (currentGesture != GESTURE_NONE)){
// Open this step in the Single Step editor
edit_step = (offset*8)+column;
ClearScreenOverlays();
DisplayPage = SingleStep;
ActiveOverlays |= ovl_SingleStep;
encoder_focus = step_select;
btnA_func = btnA_none;
btnB_func = btnB_prev;
btnC_func = btnC_next;
btnD_func = btnD_done;
save_run_stop = run_stop;
}
else {
if((offset*8)+column == Europi.tracks[edit_track].last_step){
// Paint last step
DrawRectangleRec(stepRectangle, BLACK);
}
else if((offset*8)+column == Europi.tracks[edit_track].current_step){
// Paint current step
DrawRectangleRec(stepRectangle, LIME);
}
else if((offset*8)+column == edit_step){
// Paint step currently being edited
DrawRectangleRec(stepRectangle, YELLOW);
}
else {
// paint blank step
DrawRectangleRec(stepRectangle, MAROON);
}
}
}
// Print the end-step number at the RHS of each row
sprintf(txt,":%d",(offset * 8)+8);
DrawText(txt,270,34,20,DARKGRAY);
touchRectangle.x = 8;
touchRectangle.height = 20;
// Slew Type
touchRectangle.y = 58;
switch(Europi.tracks[edit_track].channels[CV_OUT].steps[edit_step].slew_type){
default:
case Off:
DrawText("Off",140,58,20,BLUE);
touchRectangle.width = 2;
DrawRectangleRec(touchRectangle, LIGHTGRAY);
break;
case Linear:
touchRectangle.width = 16;
DrawRectangleRec(touchRectangle, LIGHTGRAY);
DrawText("Linear",140,58,20,BLUE);
break;
case Exponential:
touchRectangle.width = 32;
DrawRectangleRec(touchRectangle, LIGHTGRAY);
DrawText("Exponential",140,58,20,BLUE);
break;
case RevExp:
touchRectangle.width = 48;
DrawRectangleRec(touchRectangle, LIGHTGRAY);
DrawText("Reverse Exp",140,58,20,BLUE);
break;
case Log:
touchRectangle.width = 64;
DrawRectangleRec(touchRectangle, LIGHTGRAY);
DrawText("Logarithmic",140,58,20,BLUE);
break;
case RevLog:
touchRectangle.width = 80;
DrawRectangleRec(touchRectangle, LIGHTGRAY);
DrawText("Reverse Log",140,58,20,BLUE);
break;
case Sine:
touchRectangle.width = 96;
DrawRectangleRec(touchRectangle, LIGHTGRAY);
DrawText("Sine",140,58,20,BLUE);
break;
case RevSine:
touchRectangle.width = 112;
DrawRectangleRec(touchRectangle, LIGHTGRAY);
DrawText("Reverse Sine",140,58,20,BLUE);
break;
case Cosine:
touchRectangle.width = 128;
DrawRectangleRec(touchRectangle, LIGHTGRAY);
DrawText("Cosine",140,58,20,BLUE);
break;
}
touchRectangle.width = 128;
DrawText("Slew Type:",30,58,20,DARKGRAY);
if (CheckCollisionPointRec(touchPosition, touchRectangle) && (currentGesture != GESTURE_NONE)){
// Work out what % of the way along the touchRectangle we are
switch((int)(((touchPosition.x - 8) / (float)128) * 8)){
default:
case 0:
Europi.tracks[edit_track].channels[CV_OUT].steps[edit_step].slew_type = Off;
break;
case 1:
Europi.tracks[edit_track].channels[CV_OUT].steps[edit_step].slew_type = Linear;
break;
case 2:
Europi.tracks[edit_track].channels[CV_OUT].steps[edit_step].slew_type = Exponential;
break;
case 3:
Europi.tracks[edit_track].channels[CV_OUT].steps[edit_step].slew_type = RevExp;
break;
case 4:
Europi.tracks[edit_track].channels[CV_OUT].steps[edit_step].slew_type = Log;
break;
case 5:
Europi.tracks[edit_track].channels[CV_OUT].steps[edit_step].slew_type = RevLog;
break;
case 6:
Europi.tracks[edit_track].channels[CV_OUT].steps[edit_step].slew_type = Sine;
break;
case 7:
Europi.tracks[edit_track].channels[CV_OUT].steps[edit_step].slew_type = RevSine;
break;
case 8:
Europi.tracks[edit_track].channels[CV_OUT].steps[edit_step].slew_type = Cosine;
break;
}
}
// Slew Shape
touchRectangle.y = 78;
if(Europi.tracks[edit_track].channels[CV_OUT].steps[edit_step].slew_type != Off){
//Only draw the shape if the Slew Type isn't Off
switch(Europi.tracks[edit_track].channels[CV_OUT].steps[edit_step].slew_shape){
default:
case Both:
touchRectangle.width = 4;
DrawRectangleRec(touchRectangle, LIGHTGRAY);
DrawText("Both",140,78,20,BLUE);
break;
case Rising:
touchRectangle.width = 64;
DrawRectangleRec(touchRectangle, LIGHTGRAY);
DrawText("Rising",140,78,20,BLUE);
break;
case Falling:
touchRectangle.width = 128;
DrawRectangleRec(touchRectangle, LIGHTGRAY);
DrawText("Falling",140,78,20,BLUE);
break;
}
}
touchRectangle.width = 128;
DrawText("Slew Shape:",20,78,20,DARKGRAY);
if (CheckCollisionPointRec(touchPosition, touchRectangle) && (currentGesture != GESTURE_NONE)){
// Work out what % of the way along the touchRectangle we are
switch((int)(((touchPosition.x - 8) / (float)128) * 3)){
default:
case 0:
Europi.tracks[edit_track].channels[CV_OUT].steps[edit_step].slew_shape = Both;
break;
case 1:
Europi.tracks[edit_track].channels[CV_OUT].steps[edit_step].slew_shape = Rising;
break;
case 2:
Europi.tracks[edit_track].channels[CV_OUT].steps[edit_step].slew_shape = Falling;
break;
}
}
// Slew Length
if(Europi.tracks[edit_track].channels[CV_OUT].steps[edit_step].slew_type != Off){
sprintf(txt,"%d",Europi.tracks[edit_track].channels[CV_OUT].steps[edit_step].slew_length);
DrawText(txt,140,98,20,BLUE);
}
touchRectangle.y = 98;
touchRectangle.width = (int)((Europi.tracks[edit_track].channels[CV_OUT].steps[edit_step].slew_length/(float)500000)*128);
DrawRectangleRec(touchRectangle, LIGHTGRAY);
DrawText("Slew Length:",12,98,20,DARKGRAY);
touchRectangle.width = 128;
if (CheckCollisionPointRec(touchPosition, touchRectangle) && (currentGesture != GESTURE_NONE)){
// Work out what % of the way along the touchRectangle we are
Europi.tracks[edit_track].channels[CV_OUT].steps[edit_step].slew_length = (int)(((float)(touchPosition.x - 8) / (float)128) * (float)500000);
}
touchRectangle.y = 118;
switch(Europi.tracks[edit_track].channels[GATE_OUT].steps[edit_step].gate_type){
default:
case Gate_Off:
touchRectangle.width = 4;
DrawRectangleRec(touchRectangle, LIGHTGRAY);
DrawText("Off",140,118,20,BLUE);
break;
case Gate_On:
touchRectangle.width = 24;
DrawRectangleRec(touchRectangle, LIGHTGRAY);
DrawText("On",140,118,20,BLUE);
break;
case Trigger:
touchRectangle.width = 44;
DrawRectangleRec(touchRectangle, LIGHTGRAY);
DrawText("Trigger",140,118,20,BLUE);
break;
case Gate_25:
touchRectangle.width = 64;
DrawRectangleRec(touchRectangle, LIGHTGRAY);
DrawText("25%",140,118,20,BLUE);
break;
case Gate_50:
touchRectangle.width = 84;
DrawRectangleRec(touchRectangle, LIGHTGRAY);
DrawText("50%",140,118,20,BLUE);
break;
case Gate_75:
touchRectangle.width = 104;
DrawRectangleRec(touchRectangle, LIGHTGRAY);
DrawText("75%",140,118,20,BLUE);
break;
case Gate_95:
touchRectangle.width = 128;
DrawRectangleRec(touchRectangle, LIGHTGRAY);
DrawText("95%",140,118,20,BLUE);
break;
}
DrawText("Gate Type:",26,118,20,DARKGRAY);
touchRectangle.width = 128;
if (CheckCollisionPointRec(touchPosition, touchRectangle) && (currentGesture != GESTURE_NONE)){
// Work out what % of the way along the touchRectangle we are
switch((int)(((touchPosition.x - 8) / (float)128) * 6)){
default:
case 0:
Europi.tracks[edit_track].channels[GATE_OUT].steps[edit_step].gate_type = Gate_Off;
break;
case 1:
Europi.tracks[edit_track].channels[GATE_OUT].steps[edit_step].gate_type = Gate_On;
break;
case 2:
Europi.tracks[edit_track].channels[GATE_OUT].steps[edit_step].gate_type = Trigger;
break;
case 3:
Europi.tracks[edit_track].channels[GATE_OUT].steps[edit_step].gate_type = Gate_25;
break;
case 4:
Europi.tracks[edit_track].channels[GATE_OUT].steps[edit_step].gate_type = Gate_50;
break;
case 5:
Europi.tracks[edit_track].channels[GATE_OUT].steps[edit_step].gate_type = Gate_75;
break;
case 6:
Europi.tracks[edit_track].channels[GATE_OUT].steps[edit_step].gate_type = Gate_95;
break;
}
}
sprintf(txt,"%d",Europi.tracks[edit_track].channels[GATE_OUT].steps[edit_step].ratchets);
DrawText(txt,140,138,20,BLUE);
touchRectangle.y = 138;
touchRectangle.width = (int)((Europi.tracks[edit_track].channels[GATE_OUT].steps[edit_step].ratchets/(float)16)*128);
DrawRectangleRec(touchRectangle, LIGHTGRAY);
DrawText("Ratchets:",40,138,20,DARKGRAY);
touchRectangle.width = 128;
if (CheckCollisionPointRec(touchPosition, touchRectangle) && (currentGesture != GESTURE_NONE)){
// Work out what % of the way along the touchRectangle we are
Europi.tracks[edit_track].channels[GATE_OUT].steps[edit_step].ratchets = (int)(((touchPosition.x - 8) / (float)128) * 16);
}
sprintf(txt,"%d",Europi.tracks[edit_track].channels[GATE_OUT].steps[edit_step].fill);
DrawText(txt,140,158,20,BLUE);
touchRectangle.y = 158;
touchRectangle.width = (int)((Europi.tracks[edit_track].channels[GATE_OUT].steps[edit_step].fill/(float)16)*128);
DrawRectangleRec(touchRectangle, LIGHTGRAY);
DrawText("Fill:",104,158,20,DARKGRAY);
touchRectangle.width = 128;
if (CheckCollisionPointRec(touchPosition, touchRectangle) && (currentGesture != GESTURE_NONE)){
// Work out what % of the way along the touchRectangle we are
Europi.tracks[edit_track].channels[GATE_OUT].steps[edit_step].fill = (int)(((touchPosition.x - 8) / (float)128) * 16);
}
// Draw the Pitch 'Bar Graph' display
DrawRectangleLines(280,81,20,120,BLACK);
int Octave,Partial,Pitch,i;
Octave = Europi.tracks[edit_track].channels[CV_OUT].steps[edit_step].raw_value / 6000;
Partial = Europi.tracks[edit_track].channels[CV_OUT].steps[edit_step].raw_value % 6000;
//Check for collision within the Partial bar. Note: Ignores touches in left-most 5 pixels
stepRectangle.x = 280+5;
stepRectangle.y = 81;
stepRectangle.width = 20-5;
stepRectangle.height = 120;
if (CheckCollisionPointRec(touchPosition, stepRectangle) && (currentGesture != GESTURE_NONE)){
// Work out how far up the Partial bar we are
if((touchPosition.y >= (float)81) && (touchPosition.y <= (float)(81+120))) {
Partial = (int)(((120-(touchPosition.y - (float)81)) / (float)(120)) * 5999);
int newpitch = quantize((6000 * Octave) + Partial,Europi.tracks[edit_track].channels[CV_OUT].quantise);
Europi.tracks[edit_track].channels[CV_OUT].steps[edit_step].raw_value = newpitch;
// Update scaled value
Europi.tracks[edit_track].channels[CV_OUT].steps[edit_step].scaled_value = scale_value(edit_track,newpitch);
}
}
for(i=0;i<10;i++){
DrawRectangleLines(260,(i*12)+83,15,10,BLACK);
if((9-i) == Octave){
// Colour the current Octave
DrawRectangle(261,(i*12)+83+1,13,8,RED);
}
//Check for collision within the Octave Bar
stepRectangle.x = 260;
stepRectangle.y = (i*12)+83;
stepRectangle.width = 15;
stepRectangle.height = 10;
if (CheckCollisionPointRec(touchPosition, stepRectangle) && (currentGesture != GESTURE_NONE)){
// Set the Octave for this Step & Quantize the RAW value
int newpitch = quantize((6000 * (9-i)) + Partial,Europi.tracks[edit_track].channels[CV_OUT].quantise);
Europi.tracks[edit_track].channels[CV_OUT].steps[edit_step].raw_value = newpitch;
// Update scaled value
Europi.tracks[edit_track].channels[CV_OUT].steps[edit_step].scaled_value = scale_value(edit_track,newpitch);
}
}
// Fill the partial column = this is the percentage of an
// Octave, so 6000 would == 120 pixels
Pitch = (Partial * 120) / 6000;
DrawRectangle(281,81+120-Pitch-1,18,Pitch,BLUE);
// Draw all Steps in the track along the bottom of the screen
int x = 14;
int step;
for(step = 0; step<Europi.tracks[edit_track].last_step; step++){
if(step == offset * 8){
//Highlight behind current block of 8 steps
touchRectangle.x = x+1;
touchRectangle.y = 202;
touchRectangle.width = 8*9+1;
touchRectangle.height = 10;
DrawRectangleRec(touchRectangle,DARKGRAY);
x += 2;
}
if (step == ((offset*8)+8)) x+= 2;
touchRectangle.x = x;
touchRectangle.y = 203;
touchRectangle.width = 8;
touchRectangle.width = 8;
touchRectangle.height = 8;
if(step == edit_step){
DrawRectangleRec(touchRectangle,YELLOW);
}
else if(step == Europi.tracks[edit_track].current_step){
DrawRectangleRec(touchRectangle,LIME);
}
else{
DrawRectangleRec(touchRectangle,RED);
}
if (CheckCollisionPointRec(touchPosition, touchRectangle) && (currentGesture != GESTURE_NONE)){
//Move the displayed 8-step segment to this position
edit_step = step;
}
x += 9;
}
// Handle any screen overlays - these need to
// be added within the Drawing loop
ShowScreenOverlays();
EndDrawing();
}
/*
* gui_SingleChannel displays just the currently
* selected channel on a page of its own, but only
* in blocks of 8 steps
*/
void gui_SingleChannel(void){
Rectangle touchRectangle = {0,0,0,0};
int track, step, column, i;
int Octave, Partial, Pitch;
char track_no[20];
char step_no[5];
int txt_len;
int row;
Rectangle stepRectangle = {0,0,0,0};
BeginDrawing();
DrawTexture(MainScreenTexture,0,0,WHITE);
for(track = 0; track < last_track; track++){
if(Europi.tracks[track].selected == TRUE){
for(column = 0; column < 8; column++){
Octave = Europi.tracks[track].channels[CV_OUT].steps[SingleChannelOffset+column].raw_value / 6000;
Partial = Europi.tracks[track].channels[CV_OUT].steps[SingleChannelOffset+column].raw_value % 6000;
//Check for collision within the Partial bar
//Note: This ignores touches close to the left-hand
//edge, to reduce the accidental selection of octaves
touchRectangle.x = 22+(column*39)+5;
touchRectangle.y = 30;
touchRectangle.width = 18-5;
touchRectangle.height = 120;
if (CheckCollisionPointRec(touchPosition, touchRectangle) && (currentGesture != GESTURE_NONE)){
// Work out how far up the Partial bar we are
if((touchPosition.y >= (float)30) && (touchPosition.y <= (float)(30+120))) {
Partial = (int)(((120-(touchPosition.y - (float)30)) / (float)(120)) * 5999);
int newpitch = quantize((6000 * Octave) + Partial,Europi.tracks[track].channels[CV_OUT].quantise);
Europi.tracks[track].channels[CV_OUT].steps[SingleChannelOffset+column].raw_value = newpitch;
// Update scaled value
Europi.tracks[track].channels[CV_OUT].steps[SingleChannelOffset+column].scaled_value = scale_value(track,newpitch);
}
}
//Column of Octave buttons
for(i=0;i<10;i++){
DrawRectangleLines(6+(column*39),(i*12)+32,15,10,BLACK);
if((9-i) == Octave){
// Colour the current Octave
if(SingleChannelOffset+column == Europi.tracks[track].current_step){
DrawRectangle(6+(column*39)+1,(i*12)+32+1,13,8,LIME);
}
else{
DrawRectangle(6+(column*39)+1,(i*12)+32+1,13,8,RED);
}
}
//Check for collision within the Octave Bar
touchRectangle.x = 6+(column*39);
touchRectangle.y = (i*12)+32;
touchRectangle.width = 15;
touchRectangle.height = 10;
// Octave buttons only respond to tap, not any old gesture
if (CheckCollisionPointRec(touchPosition, touchRectangle) && (currentGesture == GESTURE_TAP)){
// Set the Octave for this Step & Quantize the RAW value
int newpitch = quantize((6000 * (9-i)) + Partial,Europi.tracks[track].channels[CV_OUT].quantise);
Europi.tracks[track].channels[CV_OUT].steps[SingleChannelOffset+column].raw_value = newpitch;
// Update scaled value
Europi.tracks[track].channels[CV_OUT].steps[SingleChannelOffset+column].scaled_value = scale_value(track,newpitch);
}
}
// Fill the partial column = this is the percentage of an
// Octave, so 6000 would == 120 pixels
Pitch = (Partial * 120) / 6000;
if(SingleChannelOffset+column == Europi.tracks[track].current_step){
DrawRectangle(22+(column*39)+1,30+120-Pitch,16,Pitch,LIME);
}
else {
DrawRectangle(22+(column*39)+1,30+120-Pitch,16,Pitch,BLUE);
}
//Fill the column THEN draw the Partial bar, though I actually
//prefer the display without this box round the partial bar, hence
//why it is commented out.
/*DrawRectangleLines(22+(column*39),30,18,120,BLACK);*/
//Step number boxes
DrawRectangleLines(6+(column*39),152,33,20,BLACK);
// Centre the Step Number in the box
sprintf(step_no,"%d",SingleChannelOffset+column+1);
txt_len = MeasureText(step_no,20);
DrawText(step_no,22+(column*39)-(txt_len/2),153,20,DARKGRAY);
//Check for tap within the Step Number box
touchRectangle.x = 6+(column*39);
touchRectangle.y = 160; //Ignores touches in the top few pixels, as it's close to the Partial bar
touchRectangle.width = 33;
touchRectangle.height = 12;
if (CheckCollisionPointRec(touchPosition, touchRectangle) && (currentGesture == GESTURE_TAP)){
//Open this Step in the Single Step editor
edit_track = track;
edit_step = SingleChannelOffset+column;
ClearScreenOverlays();
DisplayPage = SingleStep;
ActiveOverlays |= ovl_SingleStep;
encoder_focus = none;
btnA_func = btnA_none;
btnB_func = btnB_prev;
btnC_func = btnC_next;
btnD_func = btnD_done;
save_run_stop = run_stop;
}
//Draw the gate lane for this Step
touchRectangle.y = 175;
touchRectangle.width = 8;
touchRectangle.height = 8;
touchRectangle.x = 6+(column*39);
Color gate_colour;
if(SingleChannelOffset+column == Europi.tracks[track].current_step){
gate_colour = LIME;
}
else{
gate_colour = BLUE;
}
if(Europi.tracks[track].channels[GATE_OUT].steps[SingleChannelOffset+column].ratchets <= 1){
switch(Europi.tracks[track].channels[GATE_OUT].steps[SingleChannelOffset+column].gate_type){
case Gate_On:
touchRectangle.width = 39;
DrawRectangleRec(touchRectangle,gate_colour);
break;
case Trigger:
touchRectangle.width = 3;
DrawRectangleRec(touchRectangle,gate_colour);
break;
case Gate_25:
touchRectangle.width = 9;
DrawRectangleRec(touchRectangle,gate_colour);
break;
case Gate_50:
touchRectangle.width = 19;
DrawRectangleRec(touchRectangle,gate_colour);
break;
case Gate_75:
touchRectangle.width = 29;
DrawRectangleRec(touchRectangle,gate_colour);
break;
case Gate_95:
touchRectangle.width = 37;
DrawRectangleRec(touchRectangle,gate_colour);
break;
case Gate_Off:
default:
break;
}
}
else {
// Ratchetting Gate
if(Europi.tracks[track].channels[GATE_OUT].steps[SingleChannelOffset+column].ratchets <= 16){
int GateWidth = 38 / Europi.tracks[track].channels[GATE_OUT].steps[SingleChannelOffset+column].ratchets - 1;
touchRectangle.width = GateWidth;
for(i=0;i<Europi.tracks[track].channels[GATE_OUT].steps[SingleChannelOffset+column].ratchets;i++){
if(polyrhythm(Europi.tracks[track].channels[GATE_OUT].steps[SingleChannelOffset+column].ratchets,Europi.tracks[track].channels[GATE_OUT].steps[SingleChannelOffset+column].fill,i)){
DrawRectangleRec(touchRectangle,gate_colour);
}
touchRectangle.x += GateWidth + 1;
}
}
else {
// Too many ratchets to show meaningfully, so just draw a 95% fill line
touchRectangle.width = 38;
DrawRectangleRec(touchRectangle,gate_colour);
}
}
}
// Draw all Steps in the track along the bottom of the screen
int x = 14;
for(step = 0; step<Europi.tracks[track].last_step; step++){
if(step == SingleChannelOffset){
//Highlight behind current block of 8 steps
touchRectangle.x = x+1;
touchRectangle.y = 202;
touchRectangle.width = 8*9+1;
touchRectangle.height = 10;
DrawRectangleRec(touchRectangle,DARKGRAY);
x += 2;
}
if (step == SingleChannelOffset+8) x+= 2;
touchRectangle.x = x;
touchRectangle.y = 203;
touchRectangle.width = 8;
touchRectangle.height = 8;
if(step == Europi.tracks[track].current_step){
DrawRectangleRec(touchRectangle,LIME);
}
else{
DrawRectangleRec(touchRectangle,RED);
}
if (CheckCollisionPointRec(touchPosition, touchRectangle) && (currentGesture != GESTURE_NONE)){
//Move the displayed 8-step segment to this position
if(Europi.tracks[track].last_step >= 8){
if(step <= (Europi.tracks[track].last_step - 8)) SingleChannelOffset = step;
else SingleChannelOffset = Europi.tracks[track].last_step - 8;
}
}
x += 9;
}
}
}
// Handle any screen overlays - these need to
// be added within the Drawing loop
ShowScreenOverlays();
EndDrawing();
}
/* gui_SingleAD displays & edits the AD profile for
* a track of type SingleAD
*/
void gui_SingleAD(void){
int track,i,j;
Vector2 LineStart;
Vector2 LineEnd;
Vector2 Origin;
Vector2 VertexCentre;
Vector2 ADEnd;
Rectangle Vertex;
float x,y;
BeginDrawing();
DrawTexture(MainScreenTexture,0,0,WHITE);
for (track = 0; track < MAX_TRACKS; track++){
if (Europi.tracks[track].selected == TRUE){
LineStart.x = 8;
LineStart.y = 20;
LineEnd.x = 8;
LineEnd.y = 210;
// Use the pre-calculated Logarithmic Slew Profile to draw
// a horizontal log scale
for(i=0;i<=100;i+=5){
x = (slew_profiles[0][3][i]*(float)308)/100;
LineStart.x = 8+(int)x;
LineEnd.x = 8+(int)x;
DrawLineEx(LineStart,LineEnd,1,CLR_DARKBLUE);
}
// Draw the Curve
Origin.x = 8;
Origin.y = 210;
// Draw the Vertex
y = Origin.y - 180*((float)Europi.tracks[track].channels[CV_OUT].steps[Europi.tracks[track].current_step].raw_value / (float)60000);
VertexCentre.x = 100;
VertexCentre.y = y;
DrawRectangleLines(VertexCentre.x-4,VertexCentre.y-4,8,8,BLACK);
// Draw Rising curve
LineStart.x = Origin.x;
LineStart.y = Origin.y - ((slew_profiles[0][7][0]*(float)(Origin.y-VertexCentre.y))/100);
for(i=1;i<100;i++){
LineEnd.x = Origin.x+(((VertexCentre.x-Origin.x)*i)/100);
LineEnd.y = Origin.y - ((slew_profiles[0][7][i]*(float)(Origin.y-VertexCentre.y))/100);
DrawLineEx(LineStart,LineEnd,1,BLACK);
LineStart.x = LineEnd.x;
LineStart.y = LineEnd.y;
}
//Make sure graph actually arrives in the Vertex
DrawLineEx(LineStart,VertexCentre,1,BLACK);
// Draw Falling curve
ADEnd.x = 200;
ADEnd.y = 210;
LineStart.x = VertexCentre.x;
LineStart.y = VertexCentre.y;
for(i=1;i<100;i++){
LineEnd.x = VertexCentre.x+(((ADEnd.x-VertexCentre.x)*i)/100);
LineEnd.y = VertexCentre.y + ((((float)100-slew_profiles[1][7][i])*(float)(ADEnd.y-VertexCentre.y))/100);
DrawLineEx(LineStart,LineEnd,1,BLACK);
LineStart.x = LineEnd.x;
LineStart.y = LineEnd.y;
}
//Make sure the line actually arrives at the endpoint
DrawLineEx(LineStart,ADEnd,1,BLACK);
//Draw the end Vertex
DrawRectangleLines(ADEnd.x-4,ADEnd.y-4,8,8,BLACK);
}
}
// Handle any screen overlays - these need to
// be added within the Drawing loop
ShowScreenOverlays();
EndDrawing();
}
/* gui_SingleADSR displays & edits the ADSR profile for
* a track of type SingleADSR
*/
void gui_SingleADSR(void){
int track;
BeginDrawing();
DrawTexture(MainScreenTexture,0,0,WHITE);
for (track = 0; track < MAX_TRACKS; track++){
if (Europi.tracks[track].selected == TRUE){
DrawText("Track type ADSR",30,100,20,DARKGRAY);
}
}
// Handle any screen overlays - these need to
// be added within the Drawing loop
ShowScreenOverlays();
EndDrawing();
}
/*
* gui_SingleChannel displays just the currently
* selected channel on a page of its own
*/
void gui_SingleChannel_old2(void){
int track;
int step;
int val;
char track_no[20];
int row;
Rectangle stepRectangle = {0,0,0,0};
BeginDrawing();
DrawTexture(MainScreenTexture,0,0,WHITE);
for (track = 0; track < MAX_TRACKS; track++){
if (Europi.tracks[track].selected == TRUE){
sprintf(track_no,"%d",track+1);
for (step = 0; step < MAX_STEPS; step++){
row = step / 16;
if(step < Europi.tracks[track].last_step){
int Octave = (int)((float)Europi.tracks[track].channels[CV_OUT].steps[step].scaled_value / (float)6000);
val = (int)(((float)Europi.tracks[track].channels[CV_OUT].steps[step].scaled_value - (Octave * 6000)) / (float)60);
stepRectangle.x = ((step-(row*16)) * 18)+20;
stepRectangle.y = ((row+1) * 100)-val;
/* Width of the bar is the Octave */
stepRectangle.width = Octave+5;
stepRectangle.height = val;
if(step == Europi.tracks[track].current_step){
DrawRectangleRec(stepRectangle,MAROON);
}
else{
DrawRectangleRec(stepRectangle,LIME);
}
/* // Gate State
if (Europi.tracks[track].channels[GATE_OUT].steps[step].gate_value == 1){
sprintf(track_no,"%d",Europi.tracks[track].channels[GATE_OUT].steps[step].retrigger);
DrawText(track_no,15 + (step*9),220,10,DARKGRAY);
}
// Slew
if (Europi.tracks[track].channels[CV_OUT].steps[step].slew_type != Off){
switch (Europi.tracks[track].channels[CV_OUT].steps[step].slew_shape){
case Both:
DrawText("V",15 + (step*9),230,10,DARKGRAY);
break;
case Rising:
DrawText("/",15 + (step*9),230,10,DARKGRAY);
break;
case Falling:
DrawText("\\",15 + (step*9),230,10,DARKGRAY);
break;
}
} */
}
/* Draws a block to show the last step (provided it's less than MAX_STEPS) */
if(step == Europi.tracks[track].last_step - 1) {
val = (int)(((float)Europi.tracks[track].channels[CV_OUT].steps[step].scaled_value / (float)10000) * 100);
stepRectangle.x += 18;
stepRectangle.y = ((row+1) * 100)-val;
stepRectangle.width = 5;
stepRectangle.height = val;
DrawRectangleRec(stepRectangle,BLACK);
}
}
}
}
// Handle any screen overlays - these need to
// be added within the Drawing loop
ShowScreenOverlays();
EndDrawing();
}
void gui_SingleChannel_old1(void){
int track;