From 804b7184744194dca5cab79726f31194b7f55b80 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Fri, 21 Jul 2023 20:28:27 +0200 Subject: Fix param cursor behaviour for square and noise channels --- src/sequencer.c | 129 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 80 insertions(+), 49 deletions(-) (limited to 'src/sequencer.c') diff --git a/src/sequencer.c b/src/sequencer.c index c544f67..7a3ccb4 100644 --- a/src/sequencer.c +++ b/src/sequencer.c @@ -725,47 +725,33 @@ set_param_selection_sq1(ChannelSquareParams *params, InputHandler return_handler // Cursor movement. if (key_tap(KEY_LEFT) || key_tap(KEY_RIGHT)) { - int inc = 0; - int loc = param_selection_loc; if (key_tap(KEY_RIGHT)) { - if (loc < 5) { - inc = 1; - } else if (loc == 6) { - inc = -1; + if (param_selection_loc == 4) { + param_selection_loc = 0; + } else if (param_selection_loc == 7) { + param_selection_loc = 5; + } else if (param_selection_loc < 7) { + param_selection_loc++; } } else { - if (loc <= 5) { - inc = -1; - } else if (loc == 6) { - inc = -2; + if (param_selection_loc == 0) { + param_selection_loc = 4; + } else if (param_selection_loc == 5) { + param_selection_loc = 7; + } else if (param_selection_loc > 0) { + param_selection_loc--; } } - param_selection_loc = CLAMP(loc + inc, 0, 6); redraw_params = true; return false; } if (key_tap(KEY_UP) || key_tap(KEY_DOWN)) { - int inc = 0; - int loc = param_selection_loc; - if (key_tap(KEY_UP)) { - if (loc == 4) { - inc = 2; - } else if (loc == 5) { - inc = 1; - } else if (loc == 6) { - inc = -1; - } - } else { - if (loc == 4) { - inc = 2; - } else if (loc == 5) { - inc = 1; - } else if (loc == 6) { - inc = -1; - } + if (param_selection_loc < 3) { + param_selection_loc += 5; + } else if (param_selection_loc > 4) { + param_selection_loc -= 5; } - param_selection_loc = CLAMP(loc + inc, 0, 6); redraw_params = true; return false; } @@ -781,11 +767,20 @@ set_param_selection_sq1(ChannelSquareParams *params, InputHandler return_handler switch (param_selection_loc) { case 0: { params->duty_cycle = CLAMP(params->duty_cycle + inc, 0, 3); } break; case 1: { params->env_volume = CLAMP(params->env_volume + inc, 0, 15); } break; - case 2: { params->env_direction ^= 1; } break; - case 3: { params->env_time = CLAMP(params->env_time + inc, 0, 7); } break; - case 4: { params->sweep_number = CLAMP(params->sweep_number + inc, 0, 7); } break; - case 5: { params->sweep_time = CLAMP(params->sweep_time + inc, 0, 7); } break; - case 6: { params->sweep_direction ^= 1; } break; + case 2: { + if (params->env_time == 7 && inc > 0) { + params->env_time = 0; + } else if (params->env_time == 0 && inc < 0) { + params->env_time = 7; + } else if (params->env_time != 0) { + params->env_time = CLAMP(params->env_time + inc, 1, 7); + } + } break; + case 3: { params->env_direction ^= 1; } break; + case 4: { /* TODO: probability */ } break; + case 5: { params->sweep_number = CLAMP(params->sweep_number + inc, 0, 7); } break; + case 6: { params->sweep_time = CLAMP(params->sweep_time + inc, 0, 7); } break; + case 7: { params->sweep_direction ^= 1; } break; } redraw_params = true; return true; @@ -805,14 +800,23 @@ set_param_selection_sq2(ChannelSquareParams *params, InputHandler return_handler // Cursor movement. if (key_tap(KEY_LEFT) || key_tap(KEY_RIGHT)) { - int inc = 0; - int loc = param_selection_loc; if (key_tap(KEY_RIGHT)) { - inc = 1; + if (param_selection_loc == 4) { + param_selection_loc = 0; + } else if (param_selection_loc == 7) { + param_selection_loc = 5; + } else if (param_selection_loc < 7) { + param_selection_loc++; + } } else { - inc = -1; + if (param_selection_loc == 0) { + param_selection_loc = 4; + } else if (param_selection_loc == 5) { + param_selection_loc = 7; + } else if (param_selection_loc > 0) { + param_selection_loc--; + } } - param_selection_loc = CLAMP(loc + inc, 0, 3); redraw_params = true; return false; } @@ -828,8 +832,17 @@ set_param_selection_sq2(ChannelSquareParams *params, InputHandler return_handler switch (param_selection_loc) { case 0: { params->duty_cycle = CLAMP(params->duty_cycle + inc, 0, 3); } break; case 1: { params->env_volume = CLAMP(params->env_volume + inc, 0, 15); } break; - case 2: { params->env_direction ^= 1; } break; - case 3: { params->env_time = CLAMP(params->env_time + inc, 0, 7); } break; + case 2: { + if (params->env_time == 7 && inc > 0) { + params->env_time = 0; + } else if (params->env_time == 0 && inc < 0) { + params->env_time = 7; + } else if (params->env_time != 0) { + params->env_time = CLAMP(params->env_time + inc, 1, 7); + } + } break; + case 3: { params->env_direction ^= 1; } break; + case 4: { /* TODO: probability */ } break; } redraw_params = true; return true; @@ -1015,14 +1028,23 @@ set_param_selection_noise(ChannelNoiseParams *params, InputHandler return_handle // Cursor movement. if (key_tap(KEY_LEFT) || key_tap(KEY_RIGHT)) { - int inc = 0; - int loc = param_selection_loc; if (key_tap(KEY_RIGHT)) { - inc = 1; + if (param_selection_loc == 4) { + param_selection_loc = 0; + } else if (param_selection_loc == 7) { + param_selection_loc = 5; + } else if (param_selection_loc < 7) { + param_selection_loc++; + } } else { - inc = -1; + if (param_selection_loc == 0) { + param_selection_loc = 4; + } else if (param_selection_loc == 5) { + param_selection_loc = 7; + } else if (param_selection_loc > 0) { + param_selection_loc--; + } } - param_selection_loc = CLAMP(loc + inc, 0, 3); redraw_params = true; return false; } @@ -1038,8 +1060,17 @@ set_param_selection_noise(ChannelNoiseParams *params, InputHandler return_handle switch (param_selection_loc) { case 0: { params->bit_mode = CLAMP(params->bit_mode + inc, 0, 1); } break; case 1: { params->env_volume = CLAMP(params->env_volume + inc, 0, 15); } break; - case 2: { params->env_direction ^= 1; } break; - case 3: { params->env_time = CLAMP(params->env_time + inc, 0, 7); } break; + case 2: { + if (params->env_time == 7 && inc > 0) { + params->env_time = 0; + } else if (params->env_time == 0 && inc < 0) { + params->env_time = 7; + } else if (params->env_time != 0) { + params->env_time = CLAMP(params->env_time + inc, 1, 7); + } + } break; + case 3: { params->env_direction ^= 1; } break; + case 4: { /* TODO: probability */ } break; } redraw_params = true; return true; -- cgit v1.2.1