summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-06-20 12:10:53 +0200
committerBad Diode <bd@badd10de.dev>2021-06-20 12:10:53 +0200
commit4cde886bc202d0c8c0ee52279cd4c653829afc09 (patch)
tree852437a4e1f72d90fa0910553c1dbe619ae77fc5
parentc9135315d7bab62a00efbce2758ceed855de66d5 (diff)
downloadgba-sequencer-4cde886bc202d0c8c0ee52279cd4c653829afc09.tar.gz
gba-sequencer-4cde886bc202d0c8c0ee52279cd4c653829afc09.zip
Add initial parameter display for square channels
-rw-r--r--src/sequencer.c274
1 files changed, 260 insertions, 14 deletions
diff --git a/src/sequencer.c b/src/sequencer.c
index a5addf4..41d8ee7 100644
--- a/src/sequencer.c
+++ b/src/sequencer.c
@@ -574,7 +574,7 @@ draw_piano(void) {
574#define PARAMS_START_Y 8 574#define PARAMS_START_Y 8
575 575
576void 576void
577draw_params_cursor_ch3(size_t i, u8 clr) { 577draw_params_cursor_wave(size_t i, u8 clr) {
578 u8 x_positions[] = { 578 u8 x_positions[] = {
579 // 32 half bytes (Wave A). 579 // 32 half bytes (Wave A).
580 0, 4, 8, 12, 16, 20, 24, 28, 580 0, 4, 8, 12, 16, 20, 24, 28,
@@ -632,11 +632,13 @@ void
632draw_params_cursor(size_t i, u8 clr) { 632draw_params_cursor(size_t i, u8 clr) {
633 switch (channel_selection_loc) { 633 switch (channel_selection_loc) {
634 case 0: { 634 case 0: {
635 // draw_params_cursor_ch1(i, clr);
635 } break; 636 } break;
636 case 1: { 637 case 1: {
638 // draw_params_cursor_ch2(i, clr);
637 } break; 639 } break;
638 case 2: { 640 case 2: {
639 draw_params_cursor_ch3(i, clr); 641 draw_params_cursor_wave(i, clr);
640 } break; 642 } break;
641 case 3: { 643 case 3: {
642 } break; 644 } break;
@@ -671,9 +673,7 @@ clear_parameters(void) {
671 673
672IWRAM_CODE 674IWRAM_CODE
673void 675void
674draw_parameters_ch3(void) { 676draw_parameters_wave(void) {
675 clear_parameters();
676
677 // Draw current wave data. 677 // Draw current wave data.
678 { 678 {
679 u8 *wave_a = ch3.params[trig_selection_loc].wave_a; 679 u8 *wave_a = ch3.params[trig_selection_loc].wave_a;
@@ -779,14 +779,261 @@ draw_parameters_ch3(void) {
779} 779}
780 780
781void 781void
782draw_parameters_square(ChannelSquareParams *params, bool sweep) {
783 // DEBUG: Bounding box.
784 {
785 size_t x0 = PARAMS_START_X;
786 size_t y0 = PARAMS_START_Y;
787 size_t x1 = PARAMS_START_X + PARAMS_W;
788 size_t y1 = PARAMS_START_Y + PARAMS_H - 5;
789 // draw_rect(x0, y0, x1, y1, COL_FG);
790 }
791
792 // Duty cycle.
793 {
794 size_t x = PARAMS_START_X;
795 size_t y = PARAMS_START_Y + PARAMS_H - 25;
796 draw_line(x, y + 7, x + 2, y + 7, COL_FG);
797 draw_line(x + 22, y + 7, x + 24, y + 7, COL_FG);
798 draw_line(x, y + 8, x, y + 19, COL_FG);
799 draw_line(x + 24, y + 8, x + 24, y + 19, COL_FG);
800 draw_line(x, y + 20, x + 24, y + 20, COL_FG);
801 txt_drawf_small("duty", x + 3, y + 3, 4, COL_FG);
802
803 switch (params->duty_cycle) {
804 case 0: {
805 txt_drawf("0", x + 9, y + 10, 6, COL_FG);
806 } break;
807 case 1: {
808 txt_drawf("25", x + 6, y + 10, 6, COL_FG);
809 } break;
810 case 2: {
811 txt_drawf("50", x + 6, y + 10, 6, COL_FG);
812 } break;
813 case 3: {
814 txt_drawf("75", x + 6, y + 10, 6, COL_FG);
815 } break;
816 case 4: {
817 txt_drawf("100", x + 3, y + 10, 6, COL_FG);
818 } break;
819 }
820 }
821
822 // Env. volume.
823 {
824 size_t x = PARAMS_START_X + 31;
825 size_t y = PARAMS_START_Y + PARAMS_H - 25;
826 draw_line(x, y + 7, x + 4, y + 7, COL_FG);
827 draw_line(x + 20, y + 7, x + 24, y + 7, COL_FG);
828 draw_line(x, y + 8, x, y + 19, COL_FG);
829 draw_line(x + 24, y + 8, x + 24, y + 19, COL_FG);
830 draw_line(x, y + 20, x + 24, y + 20, COL_FG);
831 txt_drawf_small("vol", x + 5, y + 3, 4, COL_FG);
832
833 switch (params->env_volume) {
834 case 0: {
835 txt_drawf("0", x + 9, y + 10, 6, COL_FG);
836 } break;
837 case 1: {
838 txt_drawf("6", x + 9, y + 10, 6, COL_FG);
839 } break;
840 case 2: {
841 txt_drawf("13", x + 6, y + 10, 6, COL_FG);
842 } break;
843 case 3: {
844 txt_drawf("20", x + 6, y + 10, 6, COL_FG);
845 } break;
846 case 4: {
847 txt_drawf("26", x + 6, y + 10, 6, COL_FG);
848 } break;
849 case 5: {
850 txt_drawf("33", x + 6, y + 10, 6, COL_FG);
851 } break;
852 case 6: {
853 txt_drawf("40", x + 6, y + 10, 6, COL_FG);
854 } break;
855 case 7: {
856 txt_drawf("46", x + 6, y + 10, 6, COL_FG);
857 } break;
858 case 8: {
859 txt_drawf("53", x + 6, y + 10, 6, COL_FG);
860 } break;
861 case 9: {
862 txt_drawf("60", x + 6, y + 10, 6, COL_FG);
863 } break;
864 case 10: {
865 txt_drawf("66", x + 6, y + 10, 6, COL_FG);
866 } break;
867 case 11: {
868 txt_drawf("73", x + 6, y + 10, 6, COL_FG);
869 } break;
870 case 12: {
871 txt_drawf("80", x + 6, y + 10, 6, COL_FG);
872 } break;
873 case 13: {
874 txt_drawf("86", x + 6, y + 10, 6, COL_FG);
875 } break;
876 case 14: {
877 txt_drawf("93", x + 6, y + 10, 6, COL_FG);
878 } break;
879 case 15: {
880 txt_drawf("100", x + 3, y + 10, 6, COL_FG);
881 } break;
882 }
883 }
884
885 // Env. direction
886 {
887 size_t x = PARAMS_START_X + 59;
888 size_t y = PARAMS_START_Y + PARAMS_H - 25;
889 draw_line(x, y + 7, x + 4, y + 7, COL_FG);
890 draw_line(x + 20, y + 7, x + 24, y + 7, COL_FG);
891 draw_line(x, y + 8, x, y + 19, COL_FG);
892 draw_line(x + 24, y + 8, x + 24, y + 19, COL_FG);
893 draw_line(x, y + 20, x + 24, y + 20, COL_FG);
894 txt_drawf_small("dir", x + 5, y + 3, 4, COL_FG);
895
896 char arr_up[2] = { 0x19, 0 };
897 char arr_down[2] = { 0x18, 0 };
898 switch (params->env_direction) {
899 case 0: {
900 txt_drawf(arr_down, x + 9, y + 11, 6, COL_FG);
901 } break;
902 case 1: {
903 txt_drawf(arr_up, x + 9, y + 11, 6, COL_FG);
904 } break;
905 }
906 }
907
908 // Env. time.
909 {
910 size_t x = PARAMS_START_X + 87;
911 size_t y = PARAMS_START_Y + PARAMS_H - 25;
912 draw_line(x, y + 7, x + 2, y + 7, COL_FG);
913 draw_line(x + 22, y + 7, x + 24, y + 7, COL_FG);
914 draw_line(x, y + 8, x, y + 19, COL_FG);
915 draw_line(x + 24, y + 8, x + 24, y + 19, COL_FG);
916 draw_line(x, y + 20, x + 24, y + 20, COL_FG);
917 txt_drawf_small("time", x + 3, y + 3, 4, COL_FG);
918
919 switch (params->env_time) {
920 case 0: {
921 txt_drawf("0", x + 9, y + 10, 6, COL_FG);
922 } break;
923 case 1: {
924 txt_drawf("14", x + 6, y + 10, 6, COL_FG);
925 } break;
926 case 2: {
927 txt_drawf("28", x + 6, y + 10, 6, COL_FG);
928 } break;
929 case 3: {
930 txt_drawf("42", x + 6, y + 10, 6, COL_FG);
931 } break;
932 case 4: {
933 txt_drawf("57", x + 6, y + 10, 6, COL_FG);
934 } break;
935 case 5: {
936 txt_drawf("71", x + 6, y + 10, 6, COL_FG);
937 } break;
938 case 6: {
939 txt_drawf("85", x + 6, y + 10, 6, COL_FG);
940 } break;
941 case 7: {
942 txt_drawf("100", x + 3, y + 10, 6, COL_FG);
943 } break;
944 }
945 }
946
947 // Sweep number.
948 {
949 size_t x = PARAMS_START_X + 118;
950 size_t y = PARAMS_START_Y + PARAMS_H - 25;
951 draw_line(x, y + 7, x + 4, y + 7, COL_FG);
952 draw_line(x + 20, y + 7, x + 24, y + 7, COL_FG);
953 draw_line(x, y + 8, x, y + 19, COL_FG);
954 draw_line(x + 24, y + 8, x + 24, y + 19, COL_FG);
955 draw_line(x, y + 20, x + 24, y + 20, COL_FG);
956 txt_drawf_small("num", x + 5, y + 3, 4, COL_FG);
957
958 switch (params->sweep_number) {
959 case 0: {
960 txt_drawf("0", x + 9, y + 10, 6, COL_FG);
961 } break;
962 case 1: {
963 txt_drawf("1", x + 9, y + 10, 6, COL_FG);
964 } break;
965 case 2: {
966 txt_drawf("2", x + 9, y + 10, 6, COL_FG);
967 } break;
968 case 3: {
969 txt_drawf("3", x + 9, y + 10, 6, COL_FG);
970 } break;
971 }
972 }
973
974 // Sweep time.
975 {
976 size_t x = PARAMS_START_X + 146;
977 size_t y = PARAMS_START_Y + PARAMS_H - 25;
978 draw_line(x, y + 7, x + 2, y + 7, COL_FG);
979 draw_line(x + 22, y + 7, x + 24, y + 7, COL_FG);
980 draw_line(x, y + 8, x, y + 19, COL_FG);
981 draw_line(x + 24, y + 8, x + 24, y + 19, COL_FG);
982 draw_line(x, y + 20, x + 24, y + 20, COL_FG);
983 txt_drawf_small("time", x + 3, y + 3, 4, COL_FG);
984
985 switch (params->sweep_time) {
986 case 0: {
987 txt_drawf("0", x + 9, y + 10, 6, COL_FG);
988 } break;
989 case 1: {
990 txt_drawf("1", x + 9, y + 10, 6, COL_FG);
991 } break;
992 case 2: {
993 txt_drawf("2", x + 9, y + 10, 6, COL_FG);
994 } break;
995 case 3: {
996 txt_drawf("3", x + 9, y + 10, 6, COL_FG);
997 } break;
998 }
999 }
1000
1001 // Sweep direction.
1002 {
1003 size_t x = PARAMS_START_X + 132;
1004 size_t y = PARAMS_START_Y + PARAMS_H - 45;
1005 draw_line(x, y + 7, x + 4, y + 7, COL_FG);
1006 draw_line(x + 20, y + 7, x + 24, y + 7, COL_FG);
1007 draw_line(x, y + 8, x, y + 19, COL_FG);
1008 draw_line(x + 24, y + 8, x + 24, y + 19, COL_FG);
1009 draw_line(x, y + 20, x + 24, y + 20, COL_FG);
1010 txt_drawf_small("dir", x + 5, y + 3, 4, COL_FG);
1011
1012 char arr_up[2] = { 0x19, 0 };
1013 char arr_down[2] = { 0x18, 0 };
1014 switch (params->env_direction) {
1015 case 0: {
1016 txt_drawf(arr_up, x + 9, y + 11, 6, COL_FG);
1017 } break;
1018 case 1: {
1019 txt_drawf(arr_down, x + 9, y + 11, 6, COL_FG);
1020 } break;
1021 }
1022 }
1023}
1024
1025void
782draw_parameters(void) { 1026draw_parameters(void) {
1027 clear_parameters();
783 switch (channel_selection_loc) { 1028 switch (channel_selection_loc) {
784 case 0: { 1029 case 0: {
1030 draw_parameters_square(&ch1.params[trig_selection_loc], true);
785 } break; 1031 } break;
786 case 1: { 1032 case 1: {
1033 draw_parameters_square(&ch2.params[trig_selection_loc], false);
787 } break; 1034 } break;
788 case 2: { 1035 case 2: {
789 draw_parameters_ch3(); 1036 draw_parameters_wave();
790 } break; 1037 } break;
791 case 3: { 1038 case 3: {
792 } break; 1039 } break;
@@ -924,7 +1171,7 @@ void handle_trigger_selection(void);
924void handle_channel_selection(void); 1171void handle_channel_selection(void);
925void handle_param_selection_ch1(void); 1172void handle_param_selection_ch1(void);
926void handle_param_selection_ch2(void); 1173void handle_param_selection_ch2(void);
927void handle_param_selection_ch3(void); 1174void handle_param_selection_wave(void);
928 1175
929void 1176void
930handle_channel_selection(void) { 1177handle_channel_selection(void) {
@@ -1111,7 +1358,7 @@ handle_param_selection_ch2(void) {
1111} 1358}
1112 1359
1113void 1360void
1114handle_param_selection_ch3(void) { 1361handle_param_selection_wave(void) {
1115 if (key_tap(KEY_A)) { 1362 if (key_tap(KEY_A)) {
1116 // Go back to trigger selection. 1363 // Go back to trigger selection.
1117 draw_params_cursor(param_selection_loc, COL_BG); 1364 draw_params_cursor(param_selection_loc, COL_BG);
@@ -1140,9 +1387,9 @@ handle_param_selection_ch3(void) {
1140 inc = -1; 1387 inc = -1;
1141 } 1388 }
1142 } 1389 }
1143 draw_params_cursor_ch3(param_selection_loc, COL_BG); 1390 draw_params_cursor_wave(param_selection_loc, COL_BG);
1144 param_selection_loc = CLAMP(loc + inc, 0, 73); 1391 param_selection_loc = CLAMP(loc + inc, 0, 73);
1145 draw_params_cursor_ch3(param_selection_loc, COL_CURSOR); 1392 draw_params_cursor_wave(param_selection_loc, COL_CURSOR);
1146 } 1393 }
1147 if (key_tap(KEY_UP) || key_tap(KEY_DOWN)) { 1394 if (key_tap(KEY_UP) || key_tap(KEY_DOWN)) {
1148 int inc = 0; 1395 int inc = 0;
@@ -1196,9 +1443,9 @@ handle_param_selection_ch3(void) {
1196 inc = -1; 1443 inc = -1;
1197 } 1444 }
1198 } 1445 }
1199 draw_params_cursor_ch3(param_selection_loc, COL_BG); 1446 draw_params_cursor_wave(param_selection_loc, COL_BG);
1200 param_selection_loc = CLAMP(loc + inc, 0, 73); 1447 param_selection_loc = CLAMP(loc + inc, 0, 73);
1201 draw_params_cursor_ch3(param_selection_loc, COL_CURSOR); 1448 draw_params_cursor_wave(param_selection_loc, COL_CURSOR);
1202 } 1449 }
1203 if (key_tap(KEY_R) || key_tap(KEY_L)) { 1450 if (key_tap(KEY_R) || key_tap(KEY_L)) {
1204 int odd = param_selection_loc & 0x1; 1451 int odd = param_selection_loc & 0x1;
@@ -1355,7 +1602,7 @@ handle_trigger_selection(void) {
1355 input_handler = handle_param_selection_ch2; 1602 input_handler = handle_param_selection_ch2;
1356 } break; 1603 } break;
1357 case 2: { 1604 case 2: {
1358 input_handler = handle_param_selection_ch3; 1605 input_handler = handle_param_selection_wave;
1359 } break; 1606 } break;
1360 } 1607 }
1361 draw_params_cursor(param_selection_loc, COL_CURSOR); 1608 draw_params_cursor(param_selection_loc, COL_CURSOR);
@@ -1408,7 +1655,6 @@ sequencer_init(void) {
1408 draw_note(trig->note, COL_NOTE_PRESSED); 1655 draw_note(trig->note, COL_NOTE_PRESSED);
1409 1656
1410 // Initialize input handler. 1657 // Initialize input handler.
1411 channel_selection_loc = 2; // DEBUG: Starting on CH3
1412 input_handler = handle_trigger_selection; 1658 input_handler = handle_trigger_selection;
1413 draw_trig_cursor(trig_selection_loc, COL_CURSOR); 1659 draw_trig_cursor(trig_selection_loc, COL_CURSOR);
1414 draw_channel_cursor(channel_selection_loc, COL_CURRENT_CHANNEL); 1660 draw_channel_cursor(channel_selection_loc, COL_CURRENT_CHANNEL);