summaryrefslogtreecommitdiffstats
path: root/src/sequencer.c
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-06-11 16:42:18 +0200
committerBad Diode <bd@badd10de.dev>2021-06-11 16:42:18 +0200
commit5cd6fa9ce339189d5e4e57d78206254f687507fa (patch)
tree540e1ae32db82b9e75c9ed89fc3422f5860012b4 /src/sequencer.c
parent2a3e728c3d4ca3e3ad3479456e7a02bd72931745 (diff)
downloadgba-sequencer-5cd6fa9ce339189d5e4e57d78206254f687507fa.tar.gz
gba-sequencer-5cd6fa9ce339189d5e4e57d78206254f687507fa.zip
Add parameter cursor drawing for ch3
Diffstat (limited to 'src/sequencer.c')
-rw-r--r--src/sequencer.c311
1 files changed, 188 insertions, 123 deletions
diff --git a/src/sequencer.c b/src/sequencer.c
index b82ee8a..002b4d0 100644
--- a/src/sequencer.c
+++ b/src/sequencer.c
@@ -135,7 +135,7 @@ static const u32 square_wave[16] = {
135static int bpm = 115; 135static int bpm = 115;
136static int step_counter = 0; 136static int step_counter = 0;
137int trig_selection_loc = 0; 137int trig_selection_loc = 0;
138int param_selection_loc = 64; 138int param_selection_loc = 0;
139int channel_selection_loc = 0; 139int channel_selection_loc = 0;
140 140
141typedef struct TriggerNote { 141typedef struct TriggerNote {
@@ -345,7 +345,7 @@ draw_trigger(size_t chan, size_t i) {
345void 345void
346draw_trig_cursor(size_t i, u8 clr) { 346draw_trig_cursor(size_t i, u8 clr) {
347 size_t offset_x = TRIG_OFFSET_X * (i % 8); 347 size_t offset_x = TRIG_OFFSET_X * (i % 8);
348 size_t offset_y = i < 8 ? 1 : 1 + TRIG_OFFSET_Y; 348 size_t offset_y = i < 8 ? 2 : 2 + TRIG_OFFSET_Y;
349 size_t x0 = TRIG_START_X + offset_x; 349 size_t x0 = TRIG_START_X + offset_x;
350 size_t x1 = TRIG_START_X + TRIG_W + offset_x; 350 size_t x1 = TRIG_START_X + TRIG_W + offset_x;
351 size_t y = TRIG_START_Y + TRIG_H + offset_y; 351 size_t y = TRIG_START_Y + TRIG_H + offset_y;
@@ -408,7 +408,7 @@ draw_channels(void) {
408void 408void
409draw_channel_cursor(size_t i, u8 clr) { 409draw_channel_cursor(size_t i, u8 clr) {
410 size_t offset_x = 0; 410 size_t offset_x = 0;
411 size_t offset_y = CHAN_H + i * CHAN_OFFSET_Y; 411 size_t offset_y = CHAN_H + i * CHAN_OFFSET_Y + 1;
412 size_t x0 = CHAN_START_X + offset_x; 412 size_t x0 = CHAN_START_X + offset_x;
413 size_t x1 = CHAN_START_X + offset_x + CHAN_W; 413 size_t x1 = CHAN_START_X + offset_x + CHAN_W;
414 size_t y = CHAN_START_Y + offset_y; 414 size_t y = CHAN_START_Y + offset_y;
@@ -560,6 +560,66 @@ draw_piano(void) {
560#define PARAMS_START_X 35 560#define PARAMS_START_X 35
561#define PARAMS_START_Y 12 561#define PARAMS_START_Y 12
562 562
563void
564draw_parameters_cursor_ch3(size_t i, u8 clr) {
565 u8 x_positions[] = {
566 // 32 half bytes (Wave A).
567 0, 4, 8, 12, 16, 20, 24, 28,
568 34, 38, 42, 46, 50, 54, 58, 62,
569 0, 4, 8, 12, 16, 20, 24, 28,
570 34, 38, 42, 46, 50, 54, 58, 62,
571 // 32 half bytes (Wave B).
572 70, 74, 78, 82, 86, 90, 94, 98,
573 104, 108, 112, 116, 120, 124, 128, 132,
574 70, 74, 78, 82, 86, 90, 94, 98,
575 104, 108, 112, 116, 120, 124, 128, 132,
576 // Default wave A.
577 1, 18, 35, 52,
578 // Default wave B.
579 71, 88, 105, 122,
580 };
581 u8 y_positions[] = {
582 // 32 half bytes (Wave A)
583 0, 0, 0, 0, 0, 0, 0, 0,
584 0, 0, 0, 0, 0, 0, 0, 0,
585 8, 8, 8, 8, 8, 8, 8, 8,
586 8, 8, 8, 8, 8, 8, 8, 8,
587 // 32 half bytes (Wave B)
588 0, 0, 0, 0, 0, 0, 0, 0,
589 0, 0, 0, 0, 0, 0, 0, 0,
590 8, 8, 8, 8, 8, 8, 8, 8,
591 8, 8, 8, 8, 8, 8, 8, 8,
592 // Default wave A.
593 20, 20, 20, 20,
594 // Default wave B.
595 20, 20, 20, 20,
596 };
597 size_t cursor_length = 0;
598 if (i < 64) {
599 cursor_length = 4;
600 } else {
601 cursor_length = 13;
602 }
603 size_t x = PARAMS_START_X + x_positions[i] - 1;
604 size_t y = PARAMS_START_Y + PARAMS_H - 18 + y_positions[i];
605 draw_line(x, y, x + cursor_length, y, clr);
606}
607
608void
609draw_parameters_cursor(size_t i, u8 clr) {
610 switch (channel_selection_loc) {
611 case 0: {
612 } break;
613 case 1: {
614 } break;
615 case 2: {
616 draw_parameters_cursor_ch3(i, clr);
617 } break;
618 case 3: {
619 } break;
620 }
621}
622
563IWRAM_CODE 623IWRAM_CODE
564void 624void
565draw_wave_pattern(u8 *pattern, int x, int y, u8 clr) { 625draw_wave_pattern(u8 *pattern, int x, int y, u8 clr) {
@@ -1019,128 +1079,133 @@ handle_param_selection_ch2(void) {
1019void 1079void
1020handle_param_selection_ch3(void) { 1080handle_param_selection_ch3(void) {
1021 if (key_tap(KEY_A)) { 1081 if (key_tap(KEY_A)) {
1022 // TODO: draw param cursor. 1082 // Go back to trigger selection.
1083 draw_parameters_cursor(param_selection_loc, COL_BG);
1023 input_handler = handle_trigger_selection; 1084 input_handler = handle_trigger_selection;
1024 draw_trig_cursor(trig_selection_loc, COL_BLUE); 1085 draw_trig_cursor(trig_selection_loc, COL_BLUE);
1025 } 1086 }
1026 // if (key_tap(KEY_LEFT) || key_tap(KEY_RIGHT)) { 1087 if (key_tap(KEY_LEFT) || key_tap(KEY_RIGHT)) {
1027 // int inc = 0; 1088 int inc = 0;
1028 // int loc = param_selection_loc; 1089 int loc = param_selection_loc;
1029 // if (key_tap(KEY_RIGHT)) { 1090 if (key_tap(KEY_RIGHT)) {
1030 // if (loc == 15 || loc == 31) { 1091 if (loc == 15 || loc == 31) {
1031 // inc = 17; 1092 inc = 17;
1032 // } else if (loc != 47 && loc != 63){ 1093 } else if (loc != 47 && loc != 63){
1033 // inc = 1; 1094 inc = 1;
1034 // } 1095 }
1035 // } else { 1096 } else {
1036 // if (loc == 32 || loc == 48) { 1097 if (loc == 32 || loc == 48) {
1037 // inc = -17; 1098 inc = -17;
1038 // } else if (loc != 16 && loc != 64){ 1099 } else if (loc != 16 && loc != 64){
1039 // inc = -1; 1100 inc = -1;
1040 // } 1101 }
1041 // } 1102 }
1042 // param_selection_loc = CLAMP(loc + inc, 0, 71); 1103 draw_parameters_cursor_ch3(param_selection_loc, COL_BG);
1043 // } 1104 param_selection_loc = CLAMP(loc + inc, 0, 71);
1044 // if (key_tap(KEY_UP) || key_tap(KEY_DOWN)) { 1105 draw_parameters_cursor_ch3(param_selection_loc, COL_BLUE);
1045 // int inc = 0; 1106 }
1046 // int loc = param_selection_loc; 1107 if (key_tap(KEY_UP) || key_tap(KEY_DOWN)) {
1047 // if (key_tap(KEY_UP)) { 1108 int inc = 0;
1048 // if ((loc >= 16 && loc < 32) || (loc >= 48 && loc < 64)) { 1109 int loc = param_selection_loc;
1049 // inc = -16; 1110 if (key_tap(KEY_UP)) {
1050 // } else if (loc == 64) { 1111 if ((loc >= 16 && loc < 32) || (loc >= 48 && loc < 64)) {
1051 // inc = -48; 1112 inc = -16;
1052 // } else if (loc == 65) { 1113 } else if (loc == 64) {
1053 // inc = -45; 1114 inc = -48;
1054 // } else if (loc == 66) { 1115 } else if (loc == 65) {
1055 // inc = -42; 1116 inc = -45;
1056 // } else if (loc == 67) { 1117 } else if (loc == 66) {
1057 // inc = -39; 1118 inc = -42;
1058 // } else if (loc == 68) { 1119 } else if (loc == 67) {
1059 // inc = -20; 1120 inc = -39;
1060 // } else if (loc == 69) { 1121 } else if (loc == 68) {
1061 // inc = -17; 1122 inc = -20;
1062 // } else if (loc == 70) { 1123 } else if (loc == 69) {
1063 // inc = -14; 1124 inc = -17;
1064 // } else if (loc == 71) { 1125 } else if (loc == 70) {
1065 // inc = -11; 1126 inc = -14;
1066 // } 1127 } else if (loc == 71) {
1067 // } else { 1128 inc = -11;
1068 // if (loc < 16 || (loc >= 32 && loc < 48)) { 1129 }
1069 // inc = 16; 1130 } else {
1070 // } else if (loc >= 16 && loc <= 19){ 1131 if (loc < 16 || (loc >= 32 && loc < 48)) {
1071 // inc = 48 - (loc - 16); 1132 inc = 16;
1072 // } else if (loc >= 20 && loc <= 23){ 1133 } else if (loc >= 16 && loc <= 19){
1073 // inc = 45 - (loc - 20); 1134 inc = 48 - (loc - 16);
1074 // } else if (loc >= 24 && loc <= 27){ 1135 } else if (loc >= 20 && loc <= 23){
1075 // inc = 42 - (loc - 24); 1136 inc = 45 - (loc - 20);
1076 // } else if (loc >= 28 && loc <= 31){ 1137 } else if (loc >= 24 && loc <= 27){
1077 // inc = 39 - (loc - 28); 1138 inc = 42 - (loc - 24);
1078 // } else if (loc >= 48 && loc <= 51){ 1139 } else if (loc >= 28 && loc <= 31){
1079 // inc = 20 - (loc - 48); 1140 inc = 39 - (loc - 28);
1080 // } else if (loc >= 52 && loc <= 55){ 1141 } else if (loc >= 48 && loc <= 51){
1081 // inc = 17 - (loc - 52); 1142 inc = 20 - (loc - 48);
1082 // } else if (loc >= 56 && loc <= 59){ 1143 } else if (loc >= 52 && loc <= 55){
1083 // inc = 14 - (loc - 56); 1144 inc = 17 - (loc - 52);
1084 // } else if (loc >= 60 && loc <= 63){ 1145 } else if (loc >= 56 && loc <= 59){
1085 // inc = 11 - (loc - 60); 1146 inc = 14 - (loc - 56);
1086 // } 1147 } else if (loc >= 60 && loc <= 63){
1087 // } 1148 inc = 11 - (loc - 60);
1088 // param_selection_loc = CLAMP(loc + inc, 0, 71); 1149 }
1089 // } 1150 }
1090 // if (key_tap(KEY_R) || key_tap(KEY_L)) { 1151 draw_parameters_cursor_ch3(param_selection_loc, COL_BG);
1091 // int odd = param_selection_loc & 0x1; 1152 param_selection_loc = CLAMP(loc + inc, 0, 71);
1092 // int inc; 1153 draw_parameters_cursor_ch3(param_selection_loc, COL_BLUE);
1093 // if (key_tap(KEY_R)) { 1154 }
1094 // inc = 1; 1155 if (key_tap(KEY_R) || key_tap(KEY_L)) {
1095 // } else { 1156 int odd = param_selection_loc & 0x1;
1096 // inc = -1; 1157 int inc;
1097 // } 1158 if (key_tap(KEY_R)) {
1098 // // Wave: AA BB CC DD ... 1159 inc = 1;
1099 // // ^^ 1160 } else {
1100 // // |`- odd 1161 inc = -1;
1101 // // `-- even 1162 }
1102 // if (param_selection_loc < 32) { 1163 // Wave: AA BB CC DD ...
1103 // u8 byte_number = param_selection_loc >> 1; 1164 // ^^
1104 // u8 byte = sequences[2][trig_selection_loc].wave_a[byte_number]; 1165 // |`- odd
1105 // if (odd) { 1166 // `-- even
1106 // byte = (~0xF & byte) | ((byte + inc) & 0xF); 1167 // if (param_selection_loc < 32) {
1107 // } else { 1168 // u8 byte_number = param_selection_loc >> 1;
1108 // byte = (0xF & byte) | (((byte >> 4) + inc) & 0xF) << 4; 1169 // u8 byte = sequences[2][trig_selection_loc].wave_a[byte_number];
1109 // } 1170 // if (odd) {
1110 // sequences[2][trig_selection_loc].wave_a[byte_number] = byte; 1171 // byte = (~0xF & byte) | ((byte + inc) & 0xF);
1111 // } else if (param_selection_loc < 64){ 1172 // } else {
1112 // u8 byte_number = (param_selection_loc - 32) >> 1; 1173 // byte = (0xF & byte) | (((byte >> 4) + inc) & 0xF) << 4;
1113 // u8 byte = sequences[2][trig_selection_loc].wave_b[byte_number]; 1174 // }
1114 // if (odd) { 1175 // sequences[2][trig_selection_loc].wave_a[byte_number] = byte;
1115 // byte = (~0xF & byte) | (byte + inc); 1176 // } else if (param_selection_loc < 64){
1116 // } else { 1177 // u8 byte_number = (param_selection_loc - 32) >> 1;
1117 // byte = (0xF & byte) | ((byte >> 4) + inc) << 4; 1178 // u8 byte = sequences[2][trig_selection_loc].wave_b[byte_number];
1118 // } 1179 // if (odd) {
1119 // sequences[2][trig_selection_loc].wave_b[byte_number] = byte; 1180 // byte = (~0xF & byte) | (byte + inc);
1120 // } else if (param_selection_loc == 64){ 1181 // } else {
1121 // dma_copy(&trig->wave_a, &sine_wave, 16); 1182 // byte = (0xF & byte) | ((byte >> 4) + inc) << 4;
1122 // } else if (param_selection_loc == 65){ 1183 // }
1123 // dma_copy(&trig->wave_a, &saw_wave, 16); 1184 // sequences[2][trig_selection_loc].wave_b[byte_number] = byte;
1124 // } else if (param_selection_loc == 66){ 1185 // } else if (param_selection_loc == 64){
1125 // dma_copy(&trig->wave_a, &square_wave, 16); 1186 // dma_copy(&trig->wave_a, &sine_wave, 16, 3);
1126 // } else if (param_selection_loc == 67){ 1187 // } else if (param_selection_loc == 65){
1127 // u32 rand_wave[4] = { 1188 // dma_copy(&trig->wave_a, &saw_wave, 16, 3);
1128 // rng32(), rng32(), rng32(), rng32(), 1189 // } else if (param_selection_loc == 66){
1129 // }; 1190 // dma_copy(&trig->wave_a, &square_wave, 16, 3);
1130 // dma_copy(&trig->wave_a, &rand_wave, 16); 1191 // } else if (param_selection_loc == 67){
1131 // } else if (param_selection_loc == 68){ 1192 // u32 rand_wave[4] = {
1132 // dma_copy(&trig->wave_b, &sine_wave, 16); 1193 // rng32(), rng32(), rng32(), rng32(),
1133 // } else if (param_selection_loc == 69){ 1194 // };
1134 // dma_copy(&trig->wave_b, &saw_wave, 16); 1195 // dma_copy(&trig->wave_a, &rand_wave, 16, 3);
1135 // } else if (param_selection_loc == 70){ 1196 // } else if (param_selection_loc == 68){
1136 // dma_copy(&trig->wave_b, &square_wave, 16); 1197 // dma_copy(&trig->wave_b, &sine_wave, 16, 3);
1137 // } else if (param_selection_loc == 71){ 1198 // } else if (param_selection_loc == 69){
1138 // u32 rand_wave[4] = { 1199 // dma_copy(&trig->wave_b, &saw_wave, 16, 3);
1139 // rng32(), rng32(), rng32(), rng32(), 1200 // } else if (param_selection_loc == 70){
1140 // }; 1201 // dma_copy(&trig->wave_b, &square_wave, 16, 3);
1141 // dma_copy(&trig->wave_b, &rand_wave, 16); 1202 // } else if (param_selection_loc == 71){
1142 // } 1203 // u32 rand_wave[4] = {
1143 // } 1204 // rng32(), rng32(), rng32(), rng32(),
1205 // };
1206 // dma_copy(&trig->wave_b, &rand_wave, 16, 3);
1207 // }
1208 }
1144} 1209}
1145 1210
1146void 1211void
@@ -1220,7 +1285,7 @@ handle_trigger_selection(void) {
1220 input_handler = handle_param_selection_ch3; 1285 input_handler = handle_param_selection_ch3;
1221 } break; 1286 } break;
1222 } 1287 }
1223 // TODO: draw param cursor. 1288 draw_parameters_cursor(param_selection_loc, COL_BLUE);
1224 draw_trig_cursor(trig_selection_loc, COL_GREY); 1289 draw_trig_cursor(trig_selection_loc, COL_GREY);
1225 } 1290 }
1226} 1291}