From 4771c84572008a223b1f35f6b2cb1d8b92bb2083 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Mon, 24 Apr 2023 17:31:17 +0200 Subject: Fix SRAM bug due to exceeding 32KB capacity This means that currently the global channel parameters are not saved, but this is kind of unimportant, since they are just used to change all the triggers. In the future we may choose to discard a pattern, a bank or compress the data before storing it on the SRAM, depending on how much more data we need to save. --- src/sequencer.c | 56 ++++++++++++++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 30 deletions(-) (limited to 'src/sequencer.c') diff --git a/src/sequencer.c b/src/sequencer.c index 397d6f9..9c92ef0 100644 --- a/src/sequencer.c +++ b/src/sequencer.c @@ -462,7 +462,7 @@ handle_pattern_selection(void) { } bool -set_param_selection_sq1(size_t i, InputHandler return_handler) { +set_param_selection_sq1(ChannelSquareParams *params, InputHandler return_handler) { // Go back to trigger selection. if (key_released(KEY_A)) { input_handler = return_handler; @@ -525,8 +525,6 @@ set_param_selection_sq1(size_t i, InputHandler return_handler) { } else { inc = 1; } - Pattern *pat = &patterns[pattern_selection_loc]; - ChannelSquareParams *params = &pat->ch1.params[i]; switch (param_selection_loc) { case 0: { params->duty_cycle = CLAMP(params->duty_cycle + inc, 0, 3); @@ -558,7 +556,7 @@ set_param_selection_sq1(size_t i, InputHandler return_handler) { } bool -set_param_selection_sq2(size_t i, InputHandler return_handler) { +set_param_selection_sq2(ChannelSquareParams *params, InputHandler return_handler) { // Go back to trigger selection. if (key_released(KEY_A)) { input_handler = return_handler; @@ -588,8 +586,6 @@ set_param_selection_sq2(size_t i, InputHandler return_handler) { } else { inc = 1; } - Pattern *pat = &patterns[pattern_selection_loc]; - ChannelSquareParams *params = &pat->ch2.params[i]; switch (param_selection_loc) { case 0: { params->duty_cycle = CLAMP(params->duty_cycle + inc, 0, 3); @@ -612,9 +608,7 @@ set_param_selection_sq2(size_t i, InputHandler return_handler) { } bool -set_param_selection_wave(size_t i, InputHandler return_handler) { - Pattern *pat = &patterns[pattern_selection_loc]; - +set_param_selection_wave(ChannelWaveParams *params, InputHandler return_handler) { // Go back to trigger selection. if (key_released(KEY_A)) { input_handler = return_handler; @@ -724,7 +718,7 @@ set_param_selection_wave(size_t i, InputHandler return_handler) { if (param_selection_loc < 32) { // Draw on wave a. u8 byte_number = param_selection_loc / 2; - u8 *byte = &pat->ch3.params[i].wave_a; + u8 *byte = ¶ms->wave_a; byte += byte_number; if (odd) { *byte = (~0xF & *byte) | ((*byte + inc) & 0xF); @@ -734,7 +728,7 @@ set_param_selection_wave(size_t i, InputHandler return_handler) { } else if (param_selection_loc < 64){ // Draw on wave b. u8 byte_number = (param_selection_loc - 32) / 2; - u8 *byte = &pat->ch3.params[i].wave_b; + u8 *byte = ¶ms->wave_b; byte += byte_number; if (odd) { *byte = (~0xF & *byte) | ((*byte + inc) & 0xF); @@ -743,8 +737,8 @@ set_param_selection_wave(size_t i, InputHandler return_handler) { } } else if (param_selection_loc < 72) { // Copy default waves. - u32 *wave_a = &pat->ch3.params[i].wave_a; - u32 *wave_b = &pat->ch3.params[i].wave_b; + u32 *wave_a = ¶ms->wave_a; + u32 *wave_b = ¶ms->wave_b; switch (param_selection_loc) { case 64: { memcpy32(wave_a, sine_wave, 16); } break; case 65: { memcpy32(wave_a, saw_wave, 16); } break; @@ -766,10 +760,10 @@ set_param_selection_wave(size_t i, InputHandler return_handler) { } break; } } else if (param_selection_loc == 72) { - u8 *wave_mode = &pat->ch3.params[i].wave_mode; + u8 *wave_mode = ¶ms->wave_mode; *wave_mode = CLAMP(*wave_mode + inc, 0, 2); } else if (param_selection_loc == 73) { - u8 *wave_volume = &pat->ch3.params[i].wave_volume; + u8 *wave_volume = ¶ms->wave_volume; *wave_volume = CLAMP(*wave_volume + inc, 0, 4); } redraw_params = true; @@ -780,7 +774,7 @@ set_param_selection_wave(size_t i, InputHandler return_handler) { } bool -set_param_selection_noise(size_t i, InputHandler return_handler) { +set_param_selection_noise(ChannelNoiseParams *params, InputHandler return_handler) { // Go back to trigger selection. if (key_released(KEY_A)) { input_handler = return_handler; @@ -810,8 +804,6 @@ set_param_selection_noise(size_t i, InputHandler return_handler) { } else { inc = 1; } - Pattern *pat = &patterns[pattern_selection_loc]; - ChannelNoiseParams *params = &pat->ch4.params[i]; switch (param_selection_loc) { case 0: { params->bit_mode = CLAMP(params->bit_mode + inc, 0, 1); @@ -836,9 +828,9 @@ set_param_selection_noise(size_t i, InputHandler return_handler) { void handle_param_selection_ch1() { Pattern *pat = &patterns[pattern_selection_loc]; - if (set_param_selection_sq1(16, handle_channel_selection)) { + if (set_param_selection_sq1(&ch1_params, handle_channel_selection)) { for (size_t i = 0; i < 16; i++) { - pat->ch1.params[i] = pat->ch1.params[16]; + pat->ch1.params[i] = ch1_params; } } } @@ -846,9 +838,9 @@ handle_param_selection_ch1() { void handle_param_selection_ch2() { Pattern *pat = &patterns[pattern_selection_loc]; - if (set_param_selection_sq2(16, handle_channel_selection)) { + if (set_param_selection_sq2(&ch2_params, handle_channel_selection)) { for (size_t i = 0; i < 16; i++) { - pat->ch2.params[i] = pat->ch2.params[16]; + pat->ch2.params[i] = ch2_params; } } } @@ -856,9 +848,9 @@ handle_param_selection_ch2() { void handle_param_selection_ch3() { Pattern *pat = &patterns[pattern_selection_loc]; - if (set_param_selection_wave(16, handle_channel_selection)) { + if (set_param_selection_wave(&ch3_params, handle_channel_selection)) { for (size_t i = 0; i < 16; i++) { - pat->ch3.params[i] = pat->ch3.params[16]; + pat->ch3.params[i] = ch3_params; } } } @@ -866,31 +858,35 @@ handle_param_selection_ch3() { void handle_param_selection_ch4() { Pattern *pat = &patterns[pattern_selection_loc]; - if (set_param_selection_noise(16, handle_channel_selection)) { + if (set_param_selection_noise(&ch4_params, handle_channel_selection)) { for (size_t i = 0; i < 16; i++) { - pat->ch4.params[i] = pat->ch4.params[16]; + pat->ch4.params[i] = ch4_params; } } } void handle_param_selection_sq1() { - set_param_selection_sq1(trig_selection_loc, handle_trigger_selection); + ChannelSquareParams *params = &patterns[pattern_selection_loc].ch1.params[trig_selection_loc]; + set_param_selection_sq1(params, handle_trigger_selection); } void handle_param_selection_sq2() { - set_param_selection_sq2(trig_selection_loc, handle_trigger_selection); + ChannelSquareParams *params = &patterns[pattern_selection_loc].ch2.params[trig_selection_loc]; + set_param_selection_sq2(params, handle_trigger_selection); } void handle_param_selection_wave() { - set_param_selection_wave(trig_selection_loc, handle_trigger_selection); + ChannelWaveParams *params = &patterns[pattern_selection_loc].ch3.params[trig_selection_loc]; + set_param_selection_wave(params, handle_trigger_selection); } void handle_param_selection_noise() { - set_param_selection_noise(trig_selection_loc, handle_trigger_selection); + ChannelNoiseParams *params = &patterns[pattern_selection_loc].ch4.params[trig_selection_loc]; + set_param_selection_noise(params, handle_trigger_selection); } void -- cgit v1.2.1