summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-06-20 15:36:42 +0200
committerBad Diode <bd@badd10de.dev>2021-06-20 15:36:42 +0200
commit6bc6d66bbe4b644c958723b02564cc7d64b8266d (patch)
treecfd64ca9fe49e1a75ff5d02c42ddda2054c5228f
parentfc04cf5c36e22fa7982eb02d0aef390f29a96830 (diff)
downloadgba-sequencer-6bc6d66bbe4b644c958723b02564cc7d64b8266d.tar.gz
gba-sequencer-6bc6d66bbe4b644c958723b02564cc7d64b8266d.zip
Add param cursor for sq1; fix bug in line drawing
-rw-r--r--src/renderer.c42
-rw-r--r--src/sequencer.c221
2 files changed, 154 insertions, 109 deletions
diff --git a/src/renderer.c b/src/renderer.c
index 0ce3107..07d79d6 100644
--- a/src/renderer.c
+++ b/src/renderer.c
@@ -128,35 +128,21 @@ draw_line(size_t x0, size_t y0, size_t x1, size_t y1, u8 clr) {
128 } 128 }
129 } else { 129 } else {
130 // Diagonal line. 130 // Diagonal line.
131 int x_step = x0 > x1 ? -1 : 1; 131 int dx = x0 > x1 ? x0 - x1 : x1 - x0;
132 int y_step = y0 > y1 ? -1 : 1; 132 int dy = y0 > y1 ? y1 - y0 : y0 - y1;
133 size_t dx = x0 > x1 ? x0 - x1 : x1 - x0; 133 int x_step = x0 < x1 ? 1 : -1;
134 size_t dy = y0 > y1 ? y0 - y1 : y1 - y0; 134 int y_step = y0 < y1 ? 1 : -1;
135 size_t x = x0; 135 int err = dx + dy;
136 size_t y = y0; 136 while (!(x0 == x1 && y0 == y1)) {
137 if (dx >= dy) { 137 draw_pixel(x0, y0, clr);
138 // Positive slope. 138 int diff = 2 * err;
139 int diff = 2 * dy - dx; 139 if (diff >= dy) {
140 for (size_t i = 0; i <= dx; ++i) { 140 err += dy;
141 draw_pixel(x, y, clr); 141 x0 += x_step;
142 if (diff >= 0) {
143 y += y_step;
144 diff -= 2 * dx;
145 }
146 x += x_step;
147 diff += 2 * dy;
148 } 142 }
149 } else { 143 if (diff <= dx) {
150 // Negative slope. 144 err += dx;
151 int diff = 2 * dx - dy; 145 y0 += y_step;
152 for (size_t i = 0; i <= dy; ++i) {
153 draw_pixel(x, y, clr);
154 if (diff >= 0) {
155 x += x_step;
156 diff -= 2 * dy;
157 }
158 y -= y_step;
159 diff += 2 * dx;
160 } 146 }
161 } 147 }
162 } 148 }
diff --git a/src/sequencer.c b/src/sequencer.c
index 2d9ca4f..2978e9b 100644
--- a/src/sequencer.c
+++ b/src/sequencer.c
@@ -610,9 +610,9 @@ draw_params_cursor_wave(size_t i, u8 clr) {
610 20, 20, 20, 20, 610 20, 20, 20, 20,
611 // Default wave B. 611 // Default wave B.
612 20, 20, 20, 20, 612 20, 20, 20, 20,
613 // Mode seleciton. 613 // Mode selection.
614 20, 614 20,
615 // Volume seleciton. 615 // Volume selection.
616 0, 616 0,
617 }; 617 };
618 size_t cursor_length = 0; 618 size_t cursor_length = 0;
@@ -629,13 +629,39 @@ draw_params_cursor_wave(size_t i, u8 clr) {
629} 629}
630 630
631void 631void
632draw_params_cursor_sq1(size_t i, u8 clr) {
633 u8 x_positions[] = {
634 0, // Duty.
635 31, // Env. Vol.
636 59, // Env. Direction.
637 87, // Env. Time.
638 118, // Sweep Number.
639 146, // Sweep Time.
640 132, // Sweep Direction.
641 };
642 u8 y_positions[] = {
643 20, // Duty.
644 20, // Env. Vol.
645 20, // Env. Direction.
646 20, // Env. Time.
647 20, // Sweep Number.
648 20, // Sweep Time.
649 0, // Sweep Direction.
650 };
651 size_t cursor_length = 24;
652 size_t x = PARAMS_START_X + x_positions[i];
653 size_t y = PARAMS_START_Y + PARAMS_H - 23 + y_positions[i];
654 draw_line(x, y, x + cursor_length, y, clr);
655}
656
657void
632draw_params_cursor(size_t i, u8 clr) { 658draw_params_cursor(size_t i, u8 clr) {
633 switch (channel_selection_loc) { 659 switch (channel_selection_loc) {
634 case 0: { 660 case 0: {
635 // draw_params_cursor_ch1(i, clr); 661 draw_params_cursor_sq1(i, clr);
636 } break; 662 } break;
637 case 1: { 663 case 1: {
638 // draw_params_cursor_ch2(i, clr); 664 // draw_params_cursor_sq2(i, clr);
639 } break; 665 } break;
640 case 2: { 666 case 2: {
641 draw_params_cursor_wave(i, clr); 667 draw_params_cursor_wave(i, clr);
@@ -884,17 +910,23 @@ draw_parameters_square(ChannelSquareParams *params, bool sweep) {
884 size_t x = PARAMS_START_X + 43; 910 size_t x = PARAMS_START_X + 43;
885 size_t y = PARAMS_START_Y + PARAMS_H - 41; 911 size_t y = PARAMS_START_Y + PARAMS_H - 41;
886 size_t x0 = x; 912 size_t x0 = x;
887 size_t y0 = y + 16 - params->env_volume; 913 size_t y0 = y + 15 - params->env_volume;
888 size_t x1 = x + 8 * params->env_time; 914 size_t x1 = x + 8 * params->env_time;
889 size_t y1 = params->env_direction == 0 ? y : y + 16; 915 size_t y1 = params->env_direction == 0 ? y + 15 : y;
890 size_t x2 = x + 8 * 7; 916 size_t x2 = x + 8 * 7;
891 size_t y2 = y1; 917 size_t y2 = y1;
918
892 // Axis. 919 // Axis.
893 draw_line(x, y - 2, x, y + 16, COL_CYAN); 920 draw_line(x, y - 2, x, y + 16, COL_CYAN);
894 draw_line(x, y + 16, x + 8 * 7 + 2, y + 16, COL_CYAN); 921 draw_line(x, y + 16, x + 8 * 7 + 2, y + 16, COL_CYAN);
922
895 // Env. 923 // Env.
896 draw_line(x0, y0, x1, y1, COL_CYAN); 924 if (params->env_time == 0) {
897 draw_line(x1, y1, x2, y2, COL_CYAN); 925 draw_line(x1, y0, x2, y0, COL_CYAN);
926 } else {
927 draw_line(x0, y0, x1, y1, COL_CYAN);
928 draw_line(x1, y1, x2, y2, COL_CYAN);
929 }
898 } 930 }
899 931
900 // Env. volume. 932 // Env. volume.
@@ -975,10 +1007,10 @@ draw_parameters_square(ChannelSquareParams *params, bool sweep) {
975 char arr_down[2] = { 0x18, 0 }; 1007 char arr_down[2] = { 0x18, 0 };
976 switch (params->env_direction) { 1008 switch (params->env_direction) {
977 case 0: { 1009 case 0: {
978 txt_drawf(arr_down, x + 9, y + 11, 6, COL_FG); 1010 txt_drawf(arr_up, x + 9, y + 11, 6, COL_FG);
979 } break; 1011 } break;
980 case 1: { 1012 case 1: {
981 txt_drawf(arr_up, x + 9, y + 11, 6, COL_FG); 1013 txt_drawf(arr_down, x + 9, y + 11, 6, COL_FG);
982 } break; 1014 } break;
983 } 1015 }
984 } 1016 }
@@ -1090,7 +1122,7 @@ draw_parameters_square(ChannelSquareParams *params, bool sweep) {
1090 1122
1091 char arr_up[2] = { 0x19, 0 }; 1123 char arr_up[2] = { 0x19, 0 };
1092 char arr_down[2] = { 0x18, 0 }; 1124 char arr_down[2] = { 0x18, 0 };
1093 switch (params->env_direction) { 1125 switch (params->sweep_direction) {
1094 case 0: { 1126 case 0: {
1095 txt_drawf(arr_up, x + 9, y + 11, 6, COL_FG); 1127 txt_drawf(arr_up, x + 9, y + 11, 6, COL_FG);
1096 } break; 1128 } break;
@@ -1248,8 +1280,8 @@ void (*input_handler)(void);
1248 1280
1249void handle_trigger_selection(void); 1281void handle_trigger_selection(void);
1250void handle_channel_selection(void); 1282void handle_channel_selection(void);
1251void handle_param_selection_ch1(void); 1283void handle_param_selection_sq1(void);
1252void handle_param_selection_ch2(void); 1284void handle_param_selection_sq2(void);
1253void handle_param_selection_wave(void); 1285void handle_param_selection_wave(void);
1254 1286
1255void 1287void
@@ -1299,80 +1331,103 @@ handle_channel_selection(void) {
1299} 1331}
1300 1332
1301void 1333void
1302handle_param_selection_ch1(void) { 1334handle_param_selection_sq1(void) {
1335 // Go back to trigger selection.
1303 if (key_tap(KEY_A)) { 1336 if (key_tap(KEY_A)) {
1304 // TODO: draw param cursor. 1337 draw_params_cursor(param_selection_loc, COL_BG);
1305 input_handler = handle_trigger_selection; 1338 input_handler = handle_trigger_selection;
1306 draw_trig_cursor(trig_selection_loc, COL_CURRENT_TRIG); 1339 draw_trig_cursor(trig_selection_loc, COL_CURSOR);
1307 } 1340 }
1308 // // Move through the selected synth parameters.
1309 // if (key_tap(KEY_LEFT)) {
1310 // int max_param = 6;
1311 // if (channel_selection_loc == 1) {
1312 // max_param = 3;
1313 // }
1314 // if (param_selection_loc == 0) {
1315 // param_selection_loc = max_param;
1316 // } else {
1317 // param_selection_loc = MAX(param_selection_loc - 1, 0);
1318 // }
1319 // }
1320 // if (key_tap(KEY_RIGHT)) {
1321 // int max_param = 6;
1322 // if (channel_selection_loc == 1) {
1323 // max_param = 3;
1324 // }
1325 // if (param_selection_loc == max_param) {
1326 // param_selection_loc = 0;
1327 // } else {
1328 // param_selection_loc = MIN(param_selection_loc + 1, max_param);
1329 // }
1330 // }
1331 1341
1332 // // Adjust the parameters up or down. 1342 // Cursor movement.
1333 // if (key_tap(KEY_L) || key_tap(KEY_R)) { 1343 if (key_tap(KEY_LEFT) || key_tap(KEY_RIGHT)) {
1334 // int inc; 1344 int inc = 0;
1335 // if (key_tap(KEY_L)) { 1345 int loc = param_selection_loc;
1336 // inc = -1; 1346 if (key_tap(KEY_RIGHT)) {
1337 // } else { 1347 if (loc < 5) {
1338 // inc = 1; 1348 inc = 1;
1339 // } 1349 } else if (loc == 6) {
1340 // switch (param_selection_loc) { 1350 inc = -1;
1341 // case 0: { 1351 }
1342 // trig->env_volume = CLAMP(trig->env_volume + inc, 0, 15); 1352 } else {
1343 // } break; 1353 if (loc <= 5) {
1344 // case 1: { 1354 inc = -1;
1345 // trig->env_time = CLAMP(trig->env_time + inc, 0, 7); 1355 } else if (loc == 6) {
1346 // } break; 1356 inc = -2;
1347 // case 2: { 1357 }
1348 // trig->env_direction ^= 1; 1358 }
1349 // } break; 1359 draw_params_cursor_sq1(param_selection_loc, COL_BG);
1350 // case 3: { 1360 param_selection_loc = CLAMP(loc + inc, 0, 6);
1351 // trig->duty_cycle = CLAMP(trig->duty_cycle + inc, 0, 3); 1361 draw_params_cursor_sq1(param_selection_loc, COL_CURSOR);
1352 // } break; 1362 }
1353 // case 4: { 1363 if (key_tap(KEY_UP) || key_tap(KEY_DOWN)) {
1354 // trig->sweep_number = CLAMP(trig->sweep_number + inc, 0, 7); 1364 int inc = 0;
1355 // } break; 1365 int loc = param_selection_loc;
1356 // case 5: { 1366 if (key_tap(KEY_UP)) {
1357 // trig->sweep_time = CLAMP(trig->sweep_time + inc, 0, 7); 1367 if (loc == 4) {
1358 // } break; 1368 inc = 2;
1359 // case 6: { 1369 } else if (loc == 5) {
1360 // if (trig->sweep_direction == 0) { 1370 inc = 1;
1361 // trig->sweep_direction = 1; 1371 } else if (loc == 6) {
1362 // } else { 1372 inc = -1;
1363 // trig->sweep_direction = 0; 1373 }
1364 // } 1374 } else {
1365 // } break; 1375 if (loc == 4) {
1366 // } 1376 inc = 2;
1367 // } 1377 } else if (loc == 5) {
1378 inc = 1;
1379 } else if (loc == 6) {
1380 inc = -1;
1381 }
1382 }
1383 draw_params_cursor_sq1(param_selection_loc, COL_BG);
1384 param_selection_loc = CLAMP(loc + inc, 0, 6);
1385 draw_params_cursor_sq1(param_selection_loc, COL_CURSOR);
1386 }
1387
1388 // Adjust parameter.
1389 if (key_tap(KEY_R) || key_tap(KEY_L)) {
1390 int inc;
1391 if (key_tap(KEY_L)) {
1392 inc = -1;
1393 } else {
1394 inc = 1;
1395 }
1396 ChannelSquareParams *params = &ch1.params[trig_selection_loc];
1397 switch (param_selection_loc) {
1398 case 0: {
1399 params->duty_cycle = CLAMP(params->duty_cycle + inc, 0, 3);
1400 } break;
1401 case 1: {
1402 params->env_volume = CLAMP(params->env_volume + inc, 0, 15);
1403 } break;
1404 case 2: {
1405 params->env_direction ^= 1;
1406 } break;
1407 case 3: {
1408 params->env_time = CLAMP(params->env_time + inc, 0, 7);
1409 } break;
1410 case 4: {
1411 params->sweep_number = CLAMP(params->sweep_number + inc, 0, 3);
1412 } break;
1413 case 5: {
1414 params->sweep_time = CLAMP(params->sweep_time + inc, 0, 3);
1415 } break;
1416 case 6: {
1417 params->sweep_direction ^= 1;
1418 } break;
1419 }
1420 draw_parameters();
1421 draw_params_cursor(param_selection_loc, COL_CURSOR);
1422 }
1368} 1423}
1369 1424
1370void 1425void
1371handle_param_selection_ch2(void) { 1426handle_param_selection_sq2(void) {
1372 if (key_tap(KEY_A)) { 1427 if (key_tap(KEY_A)) {
1373 // TODO: draw param cursor. 1428 draw_params_cursor(param_selection_loc, COL_BG);
1374 input_handler = handle_trigger_selection; 1429 input_handler = handle_trigger_selection;
1375 draw_trig_cursor(trig_selection_loc, COL_CURRENT_TRIG); 1430 draw_trig_cursor(trig_selection_loc, COL_CURSOR);
1376 } 1431 }
1377 // // Move through the selected synth parameters. 1432 // // Move through the selected synth parameters.
1378 // if (key_tap(KEY_LEFT)) { 1433 // if (key_tap(KEY_LEFT)) {
@@ -1438,12 +1493,14 @@ handle_param_selection_ch2(void) {
1438 1493
1439void 1494void
1440handle_param_selection_wave(void) { 1495handle_param_selection_wave(void) {
1496 // Go back to trigger selection.
1441 if (key_tap(KEY_A)) { 1497 if (key_tap(KEY_A)) {
1442 // Go back to trigger selection.
1443 draw_params_cursor(param_selection_loc, COL_BG); 1498 draw_params_cursor(param_selection_loc, COL_BG);
1444 input_handler = handle_trigger_selection; 1499 input_handler = handle_trigger_selection;
1445 draw_trig_cursor(trig_selection_loc, COL_CURSOR); 1500 draw_trig_cursor(trig_selection_loc, COL_CURSOR);
1446 } 1501 }
1502
1503 // Cursor movement.
1447 if (key_tap(KEY_LEFT) || key_tap(KEY_RIGHT)) { 1504 if (key_tap(KEY_LEFT) || key_tap(KEY_RIGHT)) {
1448 int inc = 0; 1505 int inc = 0;
1449 int loc = param_selection_loc; 1506 int loc = param_selection_loc;
@@ -1526,6 +1583,8 @@ handle_param_selection_wave(void) {
1526 param_selection_loc = CLAMP(loc + inc, 0, 73); 1583 param_selection_loc = CLAMP(loc + inc, 0, 73);
1527 draw_params_cursor_wave(param_selection_loc, COL_CURSOR); 1584 draw_params_cursor_wave(param_selection_loc, COL_CURSOR);
1528 } 1585 }
1586
1587 // Adjust parameter.
1529 if (key_tap(KEY_R) || key_tap(KEY_L)) { 1588 if (key_tap(KEY_R) || key_tap(KEY_L)) {
1530 int odd = param_selection_loc & 0x1; 1589 int odd = param_selection_loc & 0x1;
1531 int inc; 1590 int inc;
@@ -1675,10 +1734,10 @@ handle_trigger_selection(void) {
1675 // Switch to parameter selection. 1734 // Switch to parameter selection.
1676 switch (channel_selection_loc) { 1735 switch (channel_selection_loc) {
1677 case 0: { 1736 case 0: {
1678 input_handler = handle_param_selection_ch1; 1737 input_handler = handle_param_selection_sq1;
1679 } break; 1738 } break;
1680 case 1: { 1739 case 1: {
1681 input_handler = handle_param_selection_ch2; 1740 input_handler = handle_param_selection_sq2;
1682 } break; 1741 } break;
1683 case 2: { 1742 case 2: {
1684 input_handler = handle_param_selection_wave; 1743 input_handler = handle_param_selection_wave;