From 004e84fd5ed8943f6058dc31690bb3af61d27574 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Fri, 8 Sep 2023 14:29:12 +0200 Subject: Fix a few bugs and randomize patterns properly --- src/main.c | 15 +++++++++++++++ src/sequencer.c | 46 +++++++++++++++++++++++++++++++++++++++++----- src/settings.c | 9 +++++++-- 3 files changed, 63 insertions(+), 7 deletions(-) diff --git a/src/main.c b/src/main.c index 6f34d27..d6ea621 100644 --- a/src/main.c +++ b/src/main.c @@ -39,6 +39,7 @@ WITH REGARD TO THIS SOFTWARE. // - Should scale mode be toggleable? // - Improve SRAM saving to make room for longer patterns and/or more banks. // - Higher resolution clock to allow for microtiming and more accurate tempo. +// - Add clipboard sharing between banks. // // WIP (1.7) // + Improve "grey" cursor with dithering instead. @@ -66,9 +67,23 @@ WITH REGARD TO THIS SOFTWARE. // + Enable pattern chain toggling. // + Enable pattern chain clearing. // + Enable pattern chain randomizing. +// + Check to make sure parameters are fully clearing the screen, the cursor +// can hang (need to clear the cursor parameter position when moving to/from +// patterns to channels) +// + If select random chain patterns when nothing there chain is propagated but +// play head doesn’t begin at first chain pattern. User must manually place +// a pattern to start chain. +// + Random chain just places A- doesn’t check if which patterns have content +// in bank for random placement. // - Add CREDITS to the documentation for now, should probably be a menu item // later. // - Make sure sync works with the same cable for in/out. +// - Add help for scale parameters and banks E/F (consider auto-save settings +// for notification) +// - Add help for pattern chain +// - Default should be help is on +// - Cursor on bank can wrap around (up/down) but the same can't be done on +// patterns. #include "gba/gba.h" diff --git a/src/sequencer.c b/src/sequencer.c index 266db94..512555a 100644 --- a/src/sequencer.c +++ b/src/sequencer.c @@ -805,13 +805,12 @@ handle_pattern_chain(void) { switch (param_selection_loc) { case CHAIN_BTN_ENABLE: { chain.enabled ^= 1; - chain.current = 15; - chain.current = find_next_pattern(); - chain.playing = false; + chain.playing ^= 1; } break; case CHAIN_BTN_CLEAR: { chain.len = 0; chain.playing = false; + chain.enabled = 0; for (size_t i = 0; i < MAX_CHAIN; i++) { chain.active[i] = false; chain.chain[i] = 0; @@ -821,18 +820,49 @@ handle_pattern_chain(void) { } break; case CHAIN_BTN_RANDOM: { u8 cur = chain.current % 16; + chain.len = 0; for (size_t i = 0; i < MAX_CHAIN; i++) { if (i == cur && chain.playing) { + chain.len++; continue; } if (rng16() < 32765) { + u16 idx = 0; + for (size_t i = 0; i < 8; i++) { + u16 val = rng16(); + if (val < 1 * 65530 / 8 && !patterns[0].empty) { idx = 0; break; } + if (val < 2 * 65530 / 8 && !patterns[1].empty) { idx = 1; break; } + if (val < 3 * 65530 / 8 && !patterns[2].empty) { idx = 2; break; } + if (val < 4 * 65530 / 8 && !patterns[3].empty) { idx = 3; break; } + if (val < 5 * 65530 / 8 && !patterns[4].empty) { idx = 4; break; } + if (val < 6 * 65530 / 8 && !patterns[5].empty) { idx = 5; break; } + if (val < 7 * 65530 / 8 && !patterns[6].empty) { idx = 6; break; } + if (val < 8 * 65530 / 8 && !patterns[7].empty) { idx = 7; break; } + } + chain.chain[i] = idx; + if (!chain.playing && chain.len == 0) { + chain.chain[i] = current_pattern; + chain.current = current_pattern; + } chain.active[i] = true; + chain.len++; } else { chain.active[i] = false; } - // NOTE: Should we also randomize the patterns or isn't it - // necessary? } + + // Make sure at least one chain step is set. + if (chain.len == 0) { + chain.chain[0] = current_pattern; + chain.active[0] = true; + chain.len++; + } + if (!chain.playing) { + chain.current = 15; + chain.current = find_next_pattern(); + } + chain.enabled = 1; + chain.playing = true; } break; default: { if (chain.active[param_selection_loc]) { @@ -902,6 +932,7 @@ handle_pattern_selection(void) { input_handler = handle_pattern_chain; } if (key_tap(KEY_RIGHT)) { + param_selection_loc = 0; input_handler = handle_channel_selection; redraw_params = true; } else if (key_tap(KEY_UP)) { @@ -922,6 +953,7 @@ handle_pattern_selection(void) { if (key_tap(KEY_LEFT)) { redraw_params = true; input_handler = handle_right_col_selection; + param_selection_loc = 0; right_col_selection_loc = R_COL_BPM; switch (pattern_selection_loc) { case 0: { right_col_selection_loc = R_COL_BANK_B; } break; @@ -949,6 +981,7 @@ handle_pattern_selection(void) { } chain.chain[slot] = pattern_selection_loc; chain.active[slot] = 1; + chain.enabled = 1; chain.len++; } } @@ -976,6 +1009,9 @@ handle_pattern_selection(void) { chain.current = find_prev_pattern(); } } + if (chain.len == 0) { + chain.enabled = 0; + } } } diff --git a/src/settings.c b/src/settings.c index 5a10c90..31b3dd3 100644 --- a/src/settings.c +++ b/src/settings.c @@ -4,6 +4,7 @@ static Settings settings = { .bpm = 90, .auto_save = TOGGLE_ON, + .help = TOGGLE_ON, }; static int settings_cursor_loc = 0; @@ -103,7 +104,9 @@ handle_settings_input(void) { settings.global_bpm++; } redraw_bpm = true; - update_bpm = true; + if (play_status) { + update_bpm = true; + } } break; case SETTINGS_AUTO_SAVE: { if ((settings.auto_save + 1) >= TOGGLE_NUM) { @@ -155,7 +158,9 @@ handle_settings_input(void) { settings.global_bpm--; } redraw_bpm = true; - update_bpm = true; + if (play_status) { + update_bpm = true; + } } break; case SETTINGS_AUTO_SAVE: { if (settings.auto_save == 0) { -- cgit v1.2.1