From e8be8a52e999b7a9ee4fc935a33ebfefad5bae3a Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Wed, 19 Jul 2023 10:03:33 +0200 Subject: Allow removing the last chain when playing --- src/globals.c | 2 -- src/main.c | 2 +- src/sequencer.c | 13 +++++++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/globals.c b/src/globals.c index 1e0d964..7a55f02 100644 --- a/src/globals.c +++ b/src/globals.c @@ -149,6 +149,4 @@ typedef struct Chain { u8 playing; } Chain; -// DEBUG:... -// static Chain chain = {.chain = {0, 1, 2, 3, 4, 5, 6}, .active = { 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1,1, 1,1,1,1}, .len = 14}; static Chain chain = {0}; diff --git a/src/main.c b/src/main.c index 2cda769..61e26e7 100644 --- a/src/main.c +++ b/src/main.c @@ -95,7 +95,7 @@ render_sequencer(void) { } if (input_handler == handle_pattern_selection || - input_handler == handle_pattern_chain){ + input_handler == handle_pattern_chain) { draw_pattern_chain(); } diff --git a/src/sequencer.c b/src/sequencer.c index 9de08f8..038b608 100644 --- a/src/sequencer.c +++ b/src/sequencer.c @@ -565,22 +565,27 @@ handle_pattern_chain(void) { } else if (key_tap(KEY_B)) { if (chain.active[param_selection_loc]) { // Can't toggle current chain. - if (!play_status || param_selection_loc != chain.current) { + if (!play_status + || param_selection_loc != chain.current + || chain.len == 1) { chain.active[param_selection_loc] = 0; chain.len--; } } else { + if (chain.len == 0) { + chain.current = param_selection_loc; + } chain.active[param_selection_loc] = 1; chain.len++; } } else if (key_tap(KEY_L)) { - if (chain.active[param_selection_loc] + if (chain.active[param_selection_loc] && chain.chain[param_selection_loc] > 0 && (!play_status || param_selection_loc != chain.current)) { chain.chain[param_selection_loc]--; } } else if (key_tap(KEY_R)) { - if (chain.active[param_selection_loc] + if (chain.active[param_selection_loc] && chain.chain[param_selection_loc] < 7 && (!play_status || param_selection_loc != chain.current)) { chain.chain[param_selection_loc]++; @@ -663,7 +668,7 @@ handle_pattern_selection(void) { size_t idx = 15 - i; if (chain.active[idx] == 1) { // If the pattern is currently playing it can't be removed. - if (play_status && idx == chain.current) { + if (play_status && idx == chain.current && chain.len > 1) { continue; } else if (idx == chain.current) { update_current = true; -- cgit v1.2.1