From a3f5ae41e96e4a0b77870483864f660a797ea506 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Tue, 4 Apr 2023 10:28:11 +0200 Subject: Bugfixes and draw bank selection ui --- src/sequencer.c | 64 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 15 deletions(-) (limited to 'src') 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 = { {8, 4, 0, 2, 0, 0, 0}, {8, 4, 0, 2, 0, 0, 0}, }, - .active = false, + .active = true, }; const ChannelSquare default_ch2 = { @@ -338,7 +338,7 @@ const ChannelSquare default_ch2 = { {8, 4, 0, 2, 0, 0, 0}, {8, 4, 0, 2, 0, 0, 0}, }, - .active = false, + .active = true, }; const ChannelWave default_ch3 = { @@ -378,7 +378,7 @@ const ChannelWave default_ch3 = { {3, 0, {0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000},{0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000}}, {3, 0, {0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000},{0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000}}, }, - .active = false, + .active = true, }; const ChannelNoise default_ch4 = { @@ -422,22 +422,23 @@ const ChannelNoise default_ch4 = { }; typedef struct Pattern { - int bpm; ChannelSquare ch1; ChannelSquare ch2; ChannelWave ch3; ChannelNoise ch4; + u8 bpm; + u8 bank; } Pattern; static Pattern patterns[8] = { - {default_bpm, default_ch1, default_ch2, default_ch3, default_ch4}, - {default_bpm, default_ch1, default_ch2, default_ch3, default_ch4}, - {default_bpm, default_ch1, default_ch2, default_ch3, default_ch4}, - {default_bpm, default_ch1, default_ch2, default_ch3, default_ch4}, - {default_bpm, default_ch1, default_ch2, default_ch3, default_ch4}, - {default_bpm, default_ch1, default_ch2, default_ch3, default_ch4}, - {default_bpm, default_ch1, default_ch2, default_ch3, default_ch4}, - {default_bpm, default_ch1, default_ch2, default_ch3, default_ch4}, + {default_ch1, default_ch2, default_ch3, default_ch4, default_bpm, 0}, + {default_ch1, default_ch2, default_ch3, default_ch4, default_bpm, 0}, + {default_ch1, default_ch2, default_ch3, default_ch4, default_bpm, 0}, + {default_ch1, default_ch2, default_ch3, default_ch4, default_bpm, 0}, + {default_ch1, default_ch2, default_ch3, default_ch4, default_bpm, 0}, + {default_ch1, default_ch2, default_ch3, default_ch4, default_bpm, 0}, + {default_ch1, default_ch2, default_ch3, default_ch4, default_bpm, 0}, + {default_ch1, default_ch2, default_ch3, default_ch4, default_bpm, 0}, }; // @@ -575,6 +576,27 @@ draw_current_step(u8 col) { draw_line(x0, y, x1, y, col); } +void +draw_bank_buttons() { + size_t x = R_SIDEBAR_X + 5; + size_t y = PAT_START_Y; + txt_drawf_small("BANK", x - 2, y - 10, 4, COL_FG); + char bank_names[] = { + 'A', 'B', 'C', 'D', + }; + for (int i = 0; i < 4; i++) { + int color = COL_GREY; + if (i == current_pattern) { + // TODO: current bank. + color = COL_FG; + } + draw_filled_rect(x, y, x + PAT_W, y + PAT_H, COL_BG); + draw_rect(x, y, x + PAT_W, y + PAT_H, color); + txt_drawc(bank_names[i], x + 4, y + 2, 6, color); + y += PAT_OFFSET_Y; + } +} + void draw_pattern_buttons() { size_t x = PAT_START_X; @@ -649,7 +671,7 @@ draw_bpm() { txt_drawf_small("BPM", x + 5, y - 4, 4, COL_FG); // Make sure its horizontally centered if only 2 digits - int bpm = patterns[current_pattern].bpm; + int bpm = patterns[pattern_selection_loc].bpm; if (bpm >= 100) { txt_drawf("%d", x + 3, y + 7, 6, COL_FG, bpm); } else { @@ -1486,6 +1508,7 @@ irq_timer(void) { draw_pattern_buttons(); } Pattern *pat = &patterns[current_pattern]; + set_time(pat->bpm); if (pat->ch1.active) { TriggerNote *trig = &pat->ch1.notes[step_counter]; ChannelSquareParams *params = &pat->ch1.params[step_counter]; @@ -1781,7 +1804,11 @@ handle_right_col_selection(void) { switch (right_col_selection_loc) { case R_COL_BPM: { if (patterns[pattern_selection_loc].bpm > 10) { - set_time(--patterns[pattern_selection_loc].bpm); + patterns[pattern_selection_loc].bpm--; + if ((TIMER_CTRL_0 & TIMER_CTRL_ENABLE) != 0 + && current_pattern == pattern_selection_loc) { + set_time(patterns[current_pattern].bpm); + } draw_bpm(); } } break; @@ -1790,7 +1817,11 @@ handle_right_col_selection(void) { switch (right_col_selection_loc) { case R_COL_BPM: { if (patterns[pattern_selection_loc].bpm < 300) { - set_time(++patterns[pattern_selection_loc].bpm); + patterns[pattern_selection_loc].bpm++; + if ((TIMER_CTRL_0 & TIMER_CTRL_ENABLE) != 0 + && current_pattern == pattern_selection_loc) { + set_time(patterns[current_pattern].bpm); + } draw_bpm(); } } break; @@ -1823,6 +1854,7 @@ handle_pattern_selection(void) { pattern_selection_loc = pattern_selection_loc - 1; draw_pattern_cursor(pattern_selection_loc, COL_CURSOR); draw_triggers(); + draw_bpm(); } } else if (key_tap(KEY_DOWN)) { if (pattern_selection_loc < 7) { @@ -1830,6 +1862,7 @@ handle_pattern_selection(void) { pattern_selection_loc = pattern_selection_loc + 1; draw_pattern_cursor(pattern_selection_loc, COL_CURSOR); draw_triggers(); + draw_bpm(); } } } @@ -2475,6 +2508,7 @@ sequencer_init(void) { draw_play(); draw_stop(); draw_pattern_buttons(); + draw_bank_buttons(); // Initialize sound system. SOUND_STATUS = SOUND_ENABLE; -- cgit v1.2.1