From 1e666da666081bece2c244c2297d08801add3103 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Sat, 15 Jul 2023 22:16:00 +0200 Subject: Add cursors and fully functioning chain workflow --- src/drawing.c | 21 +++++++++++++++++++ src/globals.c | 1 + src/main.c | 4 ++-- src/sequencer.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/drawing.c b/src/drawing.c index 8cd63db..b7d5421 100644 --- a/src/drawing.c +++ b/src/drawing.c @@ -1151,6 +1151,24 @@ clear_cursors(void) { } } +void +draw_pattern_chain_cursor(void) { + size_t offset_x = (PAT_TRIG_H + 7) * (param_selection_loc % 8); + size_t offset_y = param_selection_loc < 8 ? 0 : 0 + PAT_TRIG_OFFSET_Y; + size_t x0 = PAT_TRIG_START_X + offset_x; + size_t x1 = PAT_TRIG_START_X + offset_x + PAT_TRIG_W; + size_t y = PAT_TRIG_START_Y + offset_y + PAT_TRIG_H + 2; + switch (settings.cursor) { + case CURSOR_THICK_LINE: { + draw_line(x0, y, x1, y, COL_ACC_0); + draw_line(x0, y + 1, x1, y + 1, COL_ACC_0); + } break; + default: { + draw_line(x0, y, x1, y, COL_ACC_0); + } break; + } +} + void draw_cursors(void) { clear_cursors(); @@ -1184,6 +1202,9 @@ draw_cursors(void) { input_handler == handle_param_selection_ch4) { draw_params_cursor(param_selection_loc, COL_ACC_0); } + if (input_handler == handle_pattern_chain) { + draw_pattern_chain_cursor(); + } } TriggerNote * get_current_trig(void); diff --git a/src/globals.c b/src/globals.c index 1efa90c..1e0d964 100644 --- a/src/globals.c +++ b/src/globals.c @@ -119,6 +119,7 @@ void handle_param_selection_ch1(void); void handle_param_selection_ch2(void); void handle_param_selection_ch3(void); void handle_param_selection_ch4(void); +void handle_pattern_chain(void); typedef enum Scene { SCENE_SEQUENCER = 0, diff --git a/src/main.c b/src/main.c index 2f073c7..2cda769 100644 --- a/src/main.c +++ b/src/main.c @@ -94,8 +94,8 @@ render_sequencer(void) { redraw_params = false; } - if (input_handler == handle_pattern_selection){ - // TODO: redraw_params in pattern_selection context? + if (input_handler == handle_pattern_selection || + input_handler == handle_pattern_chain){ draw_pattern_chain(); } diff --git a/src/sequencer.c b/src/sequencer.c index eeb7816..9de08f8 100644 --- a/src/sequencer.c +++ b/src/sequencer.c @@ -316,6 +316,7 @@ handle_channel_selection(void) { redraw_params = true; } else if (key_tap(KEY_LEFT)) { input_handler = handle_pattern_selection; + param_selection_loc = 0; redraw_params = true; } else if (key_tap(KEY_UP)) { if (channel_selection_loc == 0) { @@ -459,6 +460,7 @@ handle_right_col_selection(void) { right_col_selection_loc = R_COL_STOP; } else { input_handler = handle_pattern_selection; + param_selection_loc = 0; redraw_trigs = true; } } else if (key_tap(KEY_UP)) { @@ -528,6 +530,64 @@ handle_right_col_selection(void) { } } +void +handle_pattern_chain(void) { + if (key_tap(KEY_A)) { + input_handler = handle_pattern_selection; + } else if (key_tap(KEY_LEFT)) { + if (param_selection_loc == 8) { + param_selection_loc = 15; + } else if (param_selection_loc > 0) { + param_selection_loc--; + } else if (param_selection_loc == 0) { + param_selection_loc = 7; + } + } else if (key_tap(KEY_RIGHT)) { + if (param_selection_loc < 15 && param_selection_loc != 7) { + param_selection_loc++; + } else if (param_selection_loc == 7) { + param_selection_loc = 0; + } else if (param_selection_loc == 15) { + param_selection_loc = 8; + } + } else if (key_tap(KEY_UP)) { + if (param_selection_loc <= 7) { + param_selection_loc += 8; + } else { + param_selection_loc -= 8; + } + } else if (key_tap(KEY_DOWN)) { + if (param_selection_loc <= 7) { + param_selection_loc += 8; + } else { + param_selection_loc -= 8; + } + } 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) { + chain.active[param_selection_loc] = 0; + chain.len--; + } + } else { + chain.active[param_selection_loc] = 1; + chain.len++; + } + } else if (key_tap(KEY_L)) { + 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] + && chain.chain[param_selection_loc] < 7 + && (!play_status || param_selection_loc != chain.current)) { + chain.chain[param_selection_loc]++; + } + } +} + void handle_pattern_selection(void) { if (key_tap(KEY_B)) { @@ -541,6 +601,8 @@ handle_pattern_selection(void) { if (key_tap(KEY_A)) { if (key_hold(KEY_SELECT)) { clipboard_paste(); + } else { + input_handler = handle_pattern_chain; } } if (key_tap(KEY_RIGHT)) { -- cgit v1.2.1