summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-06-11 17:55:06 +0200
committerBad Diode <bd@badd10de.dev>2021-06-11 17:55:06 +0200
commitdab077db84599aedc2a48a6114ba7b1730702a3e (patch)
tree654a14590a367fd70a3465a47d4236e7c807591e
parent3c228ddd6a4df9ca055b7e22786ae3b7c43b5ea3 (diff)
downloadgba-sequencer-dab077db84599aedc2a48a6114ba7b1730702a3e.tar.gz
gba-sequencer-dab077db84599aedc2a48a6114ba7b1730702a3e.zip
Add wave mode control on ch3
-rw-r--r--src/sequencer.c96
1 files changed, 54 insertions, 42 deletions
diff --git a/src/sequencer.c b/src/sequencer.c
index d1be12d..0f3cff7 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 = 0; 138int param_selection_loc = 70;
139int channel_selection_loc = 0; 139int channel_selection_loc = 0;
140 140
141typedef struct TriggerNote { 141typedef struct TriggerNote {
@@ -561,7 +561,7 @@ draw_piano(void) {
561#define PARAMS_START_Y 12 561#define PARAMS_START_Y 12
562 562
563void 563void
564draw_parameters_cursor_ch3(size_t i, u8 clr) { 564draw_params_cursor_ch3(size_t i, u8 clr) {
565 u8 x_positions[] = { 565 u8 x_positions[] = {
566 // 32 half bytes (Wave A). 566 // 32 half bytes (Wave A).
567 0, 4, 8, 12, 16, 20, 24, 28, 567 0, 4, 8, 12, 16, 20, 24, 28,
@@ -577,6 +577,8 @@ draw_parameters_cursor_ch3(size_t i, u8 clr) {
577 1, 18, 35, 52, 577 1, 18, 35, 52,
578 // Default wave B. 578 // Default wave B.
579 71, 88, 105, 122, 579 71, 88, 105, 122,
580 // Mode selection.
581 141,
580 }; 582 };
581 u8 y_positions[] = { 583 u8 y_positions[] = {
582 // 32 half bytes (Wave A) 584 // 32 half bytes (Wave A)
@@ -593,12 +595,16 @@ draw_parameters_cursor_ch3(size_t i, u8 clr) {
593 20, 20, 20, 20, 595 20, 20, 20, 20,
594 // Default wave B. 596 // Default wave B.
595 20, 20, 20, 20, 597 20, 20, 20, 20,
598 // Mode seleciton.
599 20,
596 }; 600 };
597 size_t cursor_length = 0; 601 size_t cursor_length = 0;
598 if (i < 64) { 602 if (i < 64) {
599 cursor_length = 4; 603 cursor_length = 4;
600 } else { 604 } else if (i < 72) {
601 cursor_length = 13; 605 cursor_length = 13;
606 } else {
607 cursor_length = 30;
602 } 608 }
603 size_t x = PARAMS_START_X + x_positions[i] - 1; 609 size_t x = PARAMS_START_X + x_positions[i] - 1;
604 size_t y = PARAMS_START_Y + PARAMS_H - 18 + y_positions[i]; 610 size_t y = PARAMS_START_Y + PARAMS_H - 18 + y_positions[i];
@@ -606,14 +612,14 @@ draw_parameters_cursor_ch3(size_t i, u8 clr) {
606} 612}
607 613
608void 614void
609draw_parameters_cursor(size_t i, u8 clr) { 615draw_params_cursor(size_t i, u8 clr) {
610 switch (channel_selection_loc) { 616 switch (channel_selection_loc) {
611 case 0: { 617 case 0: {
612 } break; 618 } break;
613 case 1: { 619 case 1: {
614 } break; 620 } break;
615 case 2: { 621 case 2: {
616 draw_parameters_cursor_ch3(i, clr); 622 draw_params_cursor_ch3(i, clr);
617 } break; 623 } break;
618 case 3: { 624 case 3: {
619 } break; 625 } break;
@@ -649,14 +655,7 @@ clear_parameters(void) {
649IWRAM_CODE 655IWRAM_CODE
650void 656void
651draw_parameters_ch3(void) { 657draw_parameters_ch3(void) {
652 // Clear until the default parameters, since those don't change. 658 clear_parameters();
653 {
654 size_t x0 = PARAMS_START_X;
655 size_t y0 = PARAMS_START_Y;
656 size_t x1 = PARAMS_START_X + PARAMS_W;
657 size_t y1 = PARAMS_START_Y + PARAMS_H - 8;
658 draw_filled_rect(x0, y0, x1, y1, COL_BG);
659 }
660 659
661 // TODO: Move to VRAM and decompress at the beginning. 660 // TODO: Move to VRAM and decompress at the beginning.
662 Tile wave_tiles[4 * 2] = {0}; 661 Tile wave_tiles[4 * 2] = {0};
@@ -792,30 +791,32 @@ irq_timer(void) {
792 TriggerNote *trig = &ch3.notes[step_counter]; 791 TriggerNote *trig = &ch3.notes[step_counter];
793 ChannelWaveParams *params = &ch3.params[step_counter]; 792 ChannelWaveParams *params = &ch3.params[step_counter];
794 if (trig->active) { 793 if (trig->active) {
795 // Update both banks.
796 // TODO: Actually depends on which bank is selected, no need to
797 // update both if only one is playing.
798 // TODO: Should we compare if previous and current wave are the
799 // same before updating?
800 SOUND_WAVE_MODE = SOUND_WAVE_BANK_SELECT(1);
801 memcpy32(SOUND_WAVE_RAM, params->wave_a, 16);
802 SOUND_WAVE_MODE = SOUND_WAVE_BANK_SELECT(0);
803 memcpy32(SOUND_WAVE_RAM, params->wave_b, 16);
804
805 switch (params->wave_mode) { 794 switch (params->wave_mode) {
806 case 0: { 795 case 0: {
796 SOUND_WAVE_MODE = SOUND_WAVE_BANK_SELECT(1);
797 memcpy32(SOUND_WAVE_RAM, params->wave_a, 16);
807 SOUND_WAVE_MODE = SOUND_WAVE_BANK_MODE(0) 798 SOUND_WAVE_MODE = SOUND_WAVE_BANK_MODE(0)
808 | SOUND_WAVE_BANK_SELECT(0); 799 | SOUND_WAVE_BANK_SELECT(0);
809 } break; 800 } break;
810 case 1: { 801 case 1: {
802 SOUND_WAVE_MODE = SOUND_WAVE_BANK_SELECT(0);
803 memcpy32(SOUND_WAVE_RAM, params->wave_b, 16);
811 SOUND_WAVE_MODE = SOUND_WAVE_BANK_MODE(0) 804 SOUND_WAVE_MODE = SOUND_WAVE_BANK_MODE(0)
812 | SOUND_WAVE_BANK_SELECT(1); 805 | SOUND_WAVE_BANK_SELECT(1);
813 } break; 806 } break;
814 case 2: { 807 case 2: {
808 SOUND_WAVE_MODE = SOUND_WAVE_BANK_SELECT(0);
809 memcpy32(SOUND_WAVE_RAM, params->wave_b, 16);
810 SOUND_WAVE_MODE = SOUND_WAVE_BANK_SELECT(1);
811 memcpy32(SOUND_WAVE_RAM, params->wave_a, 16);
815 SOUND_WAVE_MODE = SOUND_WAVE_BANK_MODE(1) 812 SOUND_WAVE_MODE = SOUND_WAVE_BANK_MODE(1)
816 | SOUND_WAVE_BANK_SELECT(0); 813 | SOUND_WAVE_BANK_SELECT(0);
817 } break; 814 } break;
818 case 3: { 815 case 3: {
816 SOUND_WAVE_MODE = SOUND_WAVE_BANK_SELECT(1);
817 memcpy32(SOUND_WAVE_RAM, params->wave_a, 16);
818 SOUND_WAVE_MODE = SOUND_WAVE_BANK_SELECT(0);
819 memcpy32(SOUND_WAVE_RAM, params->wave_b, 16);
819 SOUND_WAVE_MODE = SOUND_WAVE_BANK_MODE(1) 820 SOUND_WAVE_MODE = SOUND_WAVE_BANK_MODE(1)
820 | SOUND_WAVE_BANK_SELECT(1); 821 | SOUND_WAVE_BANK_SELECT(1);
821 } break; 822 } break;
@@ -1080,7 +1081,7 @@ void
1080handle_param_selection_ch3(void) { 1081handle_param_selection_ch3(void) {
1081 if (key_tap(KEY_A)) { 1082 if (key_tap(KEY_A)) {
1082 // Go back to trigger selection. 1083 // Go back to trigger selection.
1083 draw_parameters_cursor(param_selection_loc, COL_BG); 1084 draw_params_cursor(param_selection_loc, COL_BG);
1084 input_handler = handle_trigger_selection; 1085 input_handler = handle_trigger_selection;
1085 draw_trig_cursor(trig_selection_loc, COL_BLUE); 1086 draw_trig_cursor(trig_selection_loc, COL_BLUE);
1086 } 1087 }
@@ -1090,19 +1091,23 @@ handle_param_selection_ch3(void) {
1090 if (key_tap(KEY_RIGHT)) { 1091 if (key_tap(KEY_RIGHT)) {
1091 if (loc == 15 || loc == 31) { 1092 if (loc == 15 || loc == 31) {
1092 inc = 17; 1093 inc = 17;
1093 } else if (loc != 47 && loc != 63){ 1094 } else if (loc == 47) {
1095 inc = 25;
1096 } else if (loc == 63) {
1097 inc = 9;
1098 } else if (loc != 47 && loc != 63) {
1094 inc = 1; 1099 inc = 1;
1095 } 1100 }
1096 } else { 1101 } else {
1097 if (loc == 32 || loc == 48) { 1102 if (loc == 32 || loc == 48) {
1098 inc = -17; 1103 inc = -17;
1099 } else if (loc != 16 && loc != 64){ 1104 } else if (loc != 16 && loc != 64) {
1100 inc = -1; 1105 inc = -1;
1101 } 1106 }
1102 } 1107 }
1103 draw_parameters_cursor_ch3(param_selection_loc, COL_BG); 1108 draw_params_cursor_ch3(param_selection_loc, COL_BG);
1104 param_selection_loc = CLAMP(loc + inc, 0, 71); 1109 param_selection_loc = CLAMP(loc + inc, 0, 72);
1105 draw_parameters_cursor_ch3(param_selection_loc, COL_BLUE); 1110 draw_params_cursor_ch3(param_selection_loc, COL_BLUE);
1106 } 1111 }
1107 if (key_tap(KEY_UP) || key_tap(KEY_DOWN)) { 1112 if (key_tap(KEY_UP) || key_tap(KEY_DOWN)) {
1108 int inc = 0; 1113 int inc = 0;
@@ -1130,27 +1135,27 @@ handle_param_selection_ch3(void) {
1130 } else { 1135 } else {
1131 if (loc < 16 || (loc >= 32 && loc < 48)) { 1136 if (loc < 16 || (loc >= 32 && loc < 48)) {
1132 inc = 16; 1137 inc = 16;
1133 } else if (loc >= 16 && loc <= 19){ 1138 } else if (loc >= 16 && loc <= 19) {
1134 inc = 48 - (loc - 16); 1139 inc = 48 - (loc - 16);
1135 } else if (loc >= 20 && loc <= 23){ 1140 } else if (loc >= 20 && loc <= 23) {
1136 inc = 45 - (loc - 20); 1141 inc = 45 - (loc - 20);
1137 } else if (loc >= 24 && loc <= 27){ 1142 } else if (loc >= 24 && loc <= 27) {
1138 inc = 42 - (loc - 24); 1143 inc = 42 - (loc - 24);
1139 } else if (loc >= 28 && loc <= 31){ 1144 } else if (loc >= 28 && loc <= 31) {
1140 inc = 39 - (loc - 28); 1145 inc = 39 - (loc - 28);
1141 } else if (loc >= 48 && loc <= 51){ 1146 } else if (loc >= 48 && loc <= 51) {
1142 inc = 20 - (loc - 48); 1147 inc = 20 - (loc - 48);
1143 } else if (loc >= 52 && loc <= 55){ 1148 } else if (loc >= 52 && loc <= 55) {
1144 inc = 17 - (loc - 52); 1149 inc = 17 - (loc - 52);
1145 } else if (loc >= 56 && loc <= 59){ 1150 } else if (loc >= 56 && loc <= 59) {
1146 inc = 14 - (loc - 56); 1151 inc = 14 - (loc - 56);
1147 } else if (loc >= 60 && loc <= 63){ 1152 } else if (loc >= 60 && loc <= 63) {
1148 inc = 11 - (loc - 60); 1153 inc = 11 - (loc - 60);
1149 } 1154 }
1150 } 1155 }
1151 draw_parameters_cursor_ch3(param_selection_loc, COL_BG); 1156 draw_params_cursor_ch3(param_selection_loc, COL_BG);
1152 param_selection_loc = CLAMP(loc + inc, 0, 71); 1157 param_selection_loc = CLAMP(loc + inc, 0, 71);
1153 draw_parameters_cursor_ch3(param_selection_loc, COL_BLUE); 1158 draw_params_cursor_ch3(param_selection_loc, COL_BLUE);
1154 } 1159 }
1155 if (key_tap(KEY_R) || key_tap(KEY_L)) { 1160 if (key_tap(KEY_R) || key_tap(KEY_L)) {
1156 int odd = param_selection_loc & 0x1; 1161 int odd = param_selection_loc & 0x1;
@@ -1160,11 +1165,13 @@ handle_param_selection_ch3(void) {
1160 } else { 1165 } else {
1161 inc = -1; 1166 inc = -1;
1162 } 1167 }
1168
1163 // Wave: AA BB CC DD ... 1169 // Wave: AA BB CC DD ...
1164 // ^^ 1170 // ^^
1165 // |`- odd 1171 // |`- odd
1166 // `-- even 1172 // `-- even
1167 if (param_selection_loc < 32) { 1173 if (param_selection_loc < 32) {
1174 // Draw on wave a.
1168 u8 byte_number = param_selection_loc / 2; 1175 u8 byte_number = param_selection_loc / 2;
1169 u8 *byte = &ch3.params[trig_selection_loc].wave_a; 1176 u8 *byte = &ch3.params[trig_selection_loc].wave_a;
1170 byte += byte_number; 1177 byte += byte_number;
@@ -1174,6 +1181,7 @@ handle_param_selection_ch3(void) {
1174 *byte = (0xF & *byte) | (((*byte >> 4) + inc) & 0xF) << 4; 1181 *byte = (0xF & *byte) | (((*byte >> 4) + inc) & 0xF) << 4;
1175 } 1182 }
1176 } else if (param_selection_loc < 64){ 1183 } else if (param_selection_loc < 64){
1184 // Draw on wave b.
1177 u8 byte_number = (param_selection_loc - 32) / 2; 1185 u8 byte_number = (param_selection_loc - 32) / 2;
1178 u8 *byte = &ch3.params[trig_selection_loc].wave_b; 1186 u8 *byte = &ch3.params[trig_selection_loc].wave_b;
1179 byte += byte_number; 1187 byte += byte_number;
@@ -1182,7 +1190,8 @@ handle_param_selection_ch3(void) {
1182 } else { 1190 } else {
1183 *byte = (0xF & *byte) | (((*byte >> 4) + inc) & 0xF) << 4; 1191 *byte = (0xF & *byte) | (((*byte >> 4) + inc) & 0xF) << 4;
1184 } 1192 }
1185 } else { 1193 } else if (param_selection_loc < 72) {
1194 // Copy default waves.
1186 u32 *wave_a = &ch3.params[trig_selection_loc].wave_a; 1195 u32 *wave_a = &ch3.params[trig_selection_loc].wave_a;
1187 u32 *wave_b = &ch3.params[trig_selection_loc].wave_b; 1196 u32 *wave_b = &ch3.params[trig_selection_loc].wave_b;
1188 switch (param_selection_loc) { 1197 switch (param_selection_loc) {
@@ -1217,9 +1226,12 @@ handle_param_selection_ch3(void) {
1217 memcpy32(wave_b, rand_wave, 16); 1226 memcpy32(wave_b, rand_wave, 16);
1218 } break; 1227 } break;
1219 } 1228 }
1229 } else {
1230 u8 *wave_mode = &ch3.params[trig_selection_loc].wave_mode;
1231 *wave_mode = CLAMP(*wave_mode + inc, 0, 3);
1220 } 1232 }
1221 draw_parameters(); 1233 draw_parameters();
1222 draw_parameters_cursor(param_selection_loc, COL_BLUE); 1234 draw_params_cursor(param_selection_loc, COL_BLUE);
1223 } 1235 }
1224} 1236}
1225 1237
@@ -1300,7 +1312,7 @@ handle_trigger_selection(void) {
1300 input_handler = handle_param_selection_ch3; 1312 input_handler = handle_param_selection_ch3;
1301 } break; 1313 } break;
1302 } 1314 }
1303 draw_parameters_cursor(param_selection_loc, COL_BLUE); 1315 draw_params_cursor(param_selection_loc, COL_BLUE);
1304 draw_trig_cursor(trig_selection_loc, COL_GREY); 1316 draw_trig_cursor(trig_selection_loc, COL_GREY);
1305 } 1317 }
1306} 1318}