aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2023-04-04 10:28:11 +0200
committerBad Diode <bd@badd10de.dev>2023-04-04 10:28:11 +0200
commita3f5ae41e96e4a0b77870483864f660a797ea506 (patch)
treed3a35e9005f95079d43da124d66b7bc3c710cc62
parent3f3968e15776104c5420a0442364cda5a76d3f77 (diff)
downloadstepper-a3f5ae41e96e4a0b77870483864f660a797ea506.tar.gz
stepper-a3f5ae41e96e4a0b77870483864f660a797ea506.zip
Bugfixes and draw bank selection ui
-rw-r--r--src/sequencer.c64
1 files changed, 49 insertions, 15 deletions
diff --git a/src/sequencer.c b/src/sequencer.c
index 855bbe5..587a720 100644
--- a/src/sequencer.c
+++ b/src/sequencer.c
@@ -298,7 +298,7 @@ const ChannelSquare default_ch1 = {
298 {8, 4, 0, 2, 0, 0, 0}, 298 {8, 4, 0, 2, 0, 0, 0},
299 {8, 4, 0, 2, 0, 0, 0}, 299 {8, 4, 0, 2, 0, 0, 0},
300 }, 300 },
301 .active = false, 301 .active = true,
302}; 302};
303 303
304const ChannelSquare default_ch2 = { 304const ChannelSquare default_ch2 = {
@@ -338,7 +338,7 @@ const ChannelSquare default_ch2 = {
338 {8, 4, 0, 2, 0, 0, 0}, 338 {8, 4, 0, 2, 0, 0, 0},
339 {8, 4, 0, 2, 0, 0, 0}, 339 {8, 4, 0, 2, 0, 0, 0},
340 }, 340 },
341 .active = false, 341 .active = true,
342}; 342};
343 343
344const ChannelWave default_ch3 = { 344const ChannelWave default_ch3 = {
@@ -378,7 +378,7 @@ const ChannelWave default_ch3 = {
378 {3, 0, {0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000},{0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000}}, 378 {3, 0, {0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000},{0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000}},
379 {3, 0, {0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000},{0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000}}, 379 {3, 0, {0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000},{0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000}},
380 }, 380 },
381 .active = false, 381 .active = true,
382}; 382};
383 383
384const ChannelNoise default_ch4 = { 384const ChannelNoise default_ch4 = {
@@ -422,22 +422,23 @@ const ChannelNoise default_ch4 = {
422}; 422};
423 423
424typedef struct Pattern { 424typedef struct Pattern {
425 int bpm;
426 ChannelSquare ch1; 425 ChannelSquare ch1;
427 ChannelSquare ch2; 426 ChannelSquare ch2;
428 ChannelWave ch3; 427 ChannelWave ch3;
429 ChannelNoise ch4; 428 ChannelNoise ch4;
429 u8 bpm;
430 u8 bank;
430} Pattern; 431} Pattern;
431 432
432static Pattern patterns[8] = { 433static Pattern patterns[8] = {
433 {default_bpm, default_ch1, default_ch2, default_ch3, default_ch4}, 434 {default_ch1, default_ch2, default_ch3, default_ch4, default_bpm, 0},
434 {default_bpm, default_ch1, default_ch2, default_ch3, default_ch4}, 435 {default_ch1, default_ch2, default_ch3, default_ch4, default_bpm, 0},
435 {default_bpm, default_ch1, default_ch2, default_ch3, default_ch4}, 436 {default_ch1, default_ch2, default_ch3, default_ch4, default_bpm, 0},
436 {default_bpm, default_ch1, default_ch2, default_ch3, default_ch4}, 437 {default_ch1, default_ch2, default_ch3, default_ch4, default_bpm, 0},
437 {default_bpm, default_ch1, default_ch2, default_ch3, default_ch4}, 438 {default_ch1, default_ch2, default_ch3, default_ch4, default_bpm, 0},
438 {default_bpm, default_ch1, default_ch2, default_ch3, default_ch4}, 439 {default_ch1, default_ch2, default_ch3, default_ch4, default_bpm, 0},
439 {default_bpm, default_ch1, default_ch2, default_ch3, default_ch4}, 440 {default_ch1, default_ch2, default_ch3, default_ch4, default_bpm, 0},
440 {default_bpm, default_ch1, default_ch2, default_ch3, default_ch4}, 441 {default_ch1, default_ch2, default_ch3, default_ch4, default_bpm, 0},
441}; 442};
442 443
443// 444//
@@ -576,6 +577,27 @@ draw_current_step(u8 col) {
576} 577}
577 578
578void 579void
580draw_bank_buttons() {
581 size_t x = R_SIDEBAR_X + 5;
582 size_t y = PAT_START_Y;
583 txt_drawf_small("BANK", x - 2, y - 10, 4, COL_FG);
584 char bank_names[] = {
585 'A', 'B', 'C', 'D',
586 };
587 for (int i = 0; i < 4; i++) {
588 int color = COL_GREY;
589 if (i == current_pattern) {
590 // TODO: current bank.
591 color = COL_FG;
592 }
593 draw_filled_rect(x, y, x + PAT_W, y + PAT_H, COL_BG);
594 draw_rect(x, y, x + PAT_W, y + PAT_H, color);
595 txt_drawc(bank_names[i], x + 4, y + 2, 6, color);
596 y += PAT_OFFSET_Y;
597 }
598}
599
600void
579draw_pattern_buttons() { 601draw_pattern_buttons() {
580 size_t x = PAT_START_X; 602 size_t x = PAT_START_X;
581 size_t y = PAT_START_Y; 603 size_t y = PAT_START_Y;
@@ -649,7 +671,7 @@ draw_bpm() {
649 txt_drawf_small("BPM", x + 5, y - 4, 4, COL_FG); 671 txt_drawf_small("BPM", x + 5, y - 4, 4, COL_FG);
650 672
651 // Make sure its horizontally centered if only 2 digits 673 // Make sure its horizontally centered if only 2 digits
652 int bpm = patterns[current_pattern].bpm; 674 int bpm = patterns[pattern_selection_loc].bpm;
653 if (bpm >= 100) { 675 if (bpm >= 100) {
654 txt_drawf("%d", x + 3, y + 7, 6, COL_FG, bpm); 676 txt_drawf("%d", x + 3, y + 7, 6, COL_FG, bpm);
655 } else { 677 } else {
@@ -1486,6 +1508,7 @@ irq_timer(void) {
1486 draw_pattern_buttons(); 1508 draw_pattern_buttons();
1487 } 1509 }
1488 Pattern *pat = &patterns[current_pattern]; 1510 Pattern *pat = &patterns[current_pattern];
1511 set_time(pat->bpm);
1489 if (pat->ch1.active) { 1512 if (pat->ch1.active) {
1490 TriggerNote *trig = &pat->ch1.notes[step_counter]; 1513 TriggerNote *trig = &pat->ch1.notes[step_counter];
1491 ChannelSquareParams *params = &pat->ch1.params[step_counter]; 1514 ChannelSquareParams *params = &pat->ch1.params[step_counter];
@@ -1781,7 +1804,11 @@ handle_right_col_selection(void) {
1781 switch (right_col_selection_loc) { 1804 switch (right_col_selection_loc) {
1782 case R_COL_BPM: { 1805 case R_COL_BPM: {
1783 if (patterns[pattern_selection_loc].bpm > 10) { 1806 if (patterns[pattern_selection_loc].bpm > 10) {
1784 set_time(--patterns[pattern_selection_loc].bpm); 1807 patterns[pattern_selection_loc].bpm--;
1808 if ((TIMER_CTRL_0 & TIMER_CTRL_ENABLE) != 0
1809 && current_pattern == pattern_selection_loc) {
1810 set_time(patterns[current_pattern].bpm);
1811 }
1785 draw_bpm(); 1812 draw_bpm();
1786 } 1813 }
1787 } break; 1814 } break;
@@ -1790,7 +1817,11 @@ handle_right_col_selection(void) {
1790 switch (right_col_selection_loc) { 1817 switch (right_col_selection_loc) {
1791 case R_COL_BPM: { 1818 case R_COL_BPM: {
1792 if (patterns[pattern_selection_loc].bpm < 300) { 1819 if (patterns[pattern_selection_loc].bpm < 300) {
1793 set_time(++patterns[pattern_selection_loc].bpm); 1820 patterns[pattern_selection_loc].bpm++;
1821 if ((TIMER_CTRL_0 & TIMER_CTRL_ENABLE) != 0
1822 && current_pattern == pattern_selection_loc) {
1823 set_time(patterns[current_pattern].bpm);
1824 }
1794 draw_bpm(); 1825 draw_bpm();
1795 } 1826 }
1796 } break; 1827 } break;
@@ -1823,6 +1854,7 @@ handle_pattern_selection(void) {
1823 pattern_selection_loc = pattern_selection_loc - 1; 1854 pattern_selection_loc = pattern_selection_loc - 1;
1824 draw_pattern_cursor(pattern_selection_loc, COL_CURSOR); 1855 draw_pattern_cursor(pattern_selection_loc, COL_CURSOR);
1825 draw_triggers(); 1856 draw_triggers();
1857 draw_bpm();
1826 } 1858 }
1827 } else if (key_tap(KEY_DOWN)) { 1859 } else if (key_tap(KEY_DOWN)) {
1828 if (pattern_selection_loc < 7) { 1860 if (pattern_selection_loc < 7) {
@@ -1830,6 +1862,7 @@ handle_pattern_selection(void) {
1830 pattern_selection_loc = pattern_selection_loc + 1; 1862 pattern_selection_loc = pattern_selection_loc + 1;
1831 draw_pattern_cursor(pattern_selection_loc, COL_CURSOR); 1863 draw_pattern_cursor(pattern_selection_loc, COL_CURSOR);
1832 draw_triggers(); 1864 draw_triggers();
1865 draw_bpm();
1833 } 1866 }
1834 } 1867 }
1835} 1868}
@@ -2475,6 +2508,7 @@ sequencer_init(void) {
2475 draw_play(); 2508 draw_play();
2476 draw_stop(); 2509 draw_stop();
2477 draw_pattern_buttons(); 2510 draw_pattern_buttons();
2511 draw_bank_buttons();
2478 2512
2479 // Initialize sound system. 2513 // Initialize sound system.
2480 SOUND_STATUS = SOUND_ENABLE; 2514 SOUND_STATUS = SOUND_ENABLE;