aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2023-04-24 17:31:17 +0200
committerBad Diode <bd@badd10de.dev>2023-04-24 17:31:17 +0200
commit4771c84572008a223b1f35f6b2cb1d8b92bb2083 (patch)
treeb7f8318c2003a43dfa75c6e5727c15e895b908fd
parent694bcf4790f7c03751972832bf6f2cbe6a215d04 (diff)
downloadstepper-4771c84572008a223b1f35f6b2cb1d8b92bb2083.tar.gz
stepper-4771c84572008a223b1f35f6b2cb1d8b92bb2083.zip
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.
-rw-r--r--src/clipboard.c21
-rw-r--r--src/drawing.c8
-rw-r--r--src/patterns.c11
-rw-r--r--src/sequencer.c56
4 files changed, 53 insertions, 43 deletions
diff --git a/src/clipboard.c b/src/clipboard.c
index 9d39598..eba28ae 100644
--- a/src/clipboard.c
+++ b/src/clipboard.c
@@ -286,12 +286,17 @@ clipboard_paste(void) {
286 clipboard.type == CLIP_PARAM_CH1 || 286 clipboard.type == CLIP_PARAM_CH1 ||
287 clipboard.type == CLIP_PARAM_CH2) { 287 clipboard.type == CLIP_PARAM_CH2) {
288 if (clipboard.src_chan == 0) { 288 if (clipboard.src_chan == 0) {
289 for (size_t i = 0; i < 17; i++) { 289 ch1_params = pat_src->ch1.params[clipboard.src_trig];
290 for (size_t i = 0; i < 16; i++) {
290 pat_dst->ch1.params[i] = pat_src->ch1.params[clipboard.src_trig]; 291 pat_dst->ch1.params[i] = pat_src->ch1.params[clipboard.src_trig];
291 } 292 }
292 } 293 }
293 if (clipboard.src_chan == 1) { 294 if (clipboard.src_chan == 1) {
294 for (size_t i = 0; i < 17; i++) { 295 ch1_params.env_volume = pat_src->ch2.params[clipboard.src_trig].env_volume;
296 ch1_params.env_time = pat_src->ch2.params[clipboard.src_trig].env_time;
297 ch1_params.env_direction = pat_src->ch2.params[clipboard.src_trig].env_direction;
298 ch1_params.duty_cycle = pat_src->ch2.params[clipboard.src_trig].duty_cycle;
299 for (size_t i = 0; i < 16; i++) {
295 pat_dst->ch1.params[i].env_volume = pat_src->ch2.params[clipboard.src_trig].env_volume; 300 pat_dst->ch1.params[i].env_volume = pat_src->ch2.params[clipboard.src_trig].env_volume;
296 pat_dst->ch1.params[i].env_time = pat_src->ch2.params[clipboard.src_trig].env_time; 301 pat_dst->ch1.params[i].env_time = pat_src->ch2.params[clipboard.src_trig].env_time;
297 pat_dst->ch1.params[i].env_direction = pat_src->ch2.params[clipboard.src_trig].env_direction; 302 pat_dst->ch1.params[i].env_direction = pat_src->ch2.params[clipboard.src_trig].env_direction;
@@ -305,12 +310,14 @@ clipboard_paste(void) {
305 clipboard.type == CLIP_PARAM_CH1 || 310 clipboard.type == CLIP_PARAM_CH1 ||
306 clipboard.type == CLIP_PARAM_CH2) { 311 clipboard.type == CLIP_PARAM_CH2) {
307 if (clipboard.src_chan == 0) { 312 if (clipboard.src_chan == 0) {
308 for (size_t i = 0; i < 17; i++) { 313 ch2_params = pat_src->ch1.params[clipboard.src_trig];
314 for (size_t i = 0; i < 16; i++) {
309 pat_dst->ch2.params[i] = pat_src->ch1.params[clipboard.src_trig]; 315 pat_dst->ch2.params[i] = pat_src->ch1.params[clipboard.src_trig];
310 } 316 }
311 } 317 }
312 if (clipboard.src_chan == 1) { 318 if (clipboard.src_chan == 1) {
313 for (size_t i = 0; i < 17; i++) { 319 ch2_params = pat_src->ch2.params[clipboard.src_trig];
320 for (size_t i = 0; i < 16; i++) {
314 pat_dst->ch2.params[i] = pat_src->ch2.params[clipboard.src_trig]; 321 pat_dst->ch2.params[i] = pat_src->ch2.params[clipboard.src_trig];
315 } 322 }
316 } 323 }
@@ -321,7 +328,8 @@ clipboard_paste(void) {
321 return; 328 return;
322 } 329 }
323 if (clipboard.type == CLIP_TRIG || clipboard.type == CLIP_PARAM_CH3) { 330 if (clipboard.type == CLIP_TRIG || clipboard.type == CLIP_PARAM_CH3) {
324 for (size_t i = 0; i < 17; i++) { 331 ch3_params = pat_src->ch3.params[clipboard.src_trig];
332 for (size_t i = 0; i < 16; i++) {
325 pat_dst->ch3.params[i] = pat_src->ch3.params[clipboard.src_trig]; 333 pat_dst->ch3.params[i] = pat_src->ch3.params[clipboard.src_trig];
326 } 334 }
327 } 335 }
@@ -331,7 +339,8 @@ clipboard_paste(void) {
331 return; 339 return;
332 } 340 }
333 if (clipboard.type == CLIP_TRIG || clipboard.type == CLIP_PARAM_CH4) { 341 if (clipboard.type == CLIP_TRIG || clipboard.type == CLIP_PARAM_CH4) {
334 for (size_t i = 0; i < 17; i++) { 342 ch4_params = pat_src->ch4.params[clipboard.src_trig];
343 for (size_t i = 0; i < 16; i++) {
335 pat_dst->ch4.params[i] = pat_src->ch4.params[clipboard.src_trig]; 344 pat_dst->ch4.params[i] = pat_src->ch4.params[clipboard.src_trig];
336 } 345 }
337 } 346 }
diff --git a/src/drawing.c b/src/drawing.c
index e0f7a3a..acf1e63 100644
--- a/src/drawing.c
+++ b/src/drawing.c
@@ -1040,10 +1040,10 @@ draw_parameters(void) {
1040 input_handler == handle_param_selection_ch3 || 1040 input_handler == handle_param_selection_ch3 ||
1041 input_handler == handle_param_selection_ch4) { 1041 input_handler == handle_param_selection_ch4) {
1042 switch (channel_selection_loc) { 1042 switch (channel_selection_loc) {
1043 case 0: { draw_parameters_square(&pat->ch1.params[16], true); } break; 1043 case 0: { draw_parameters_square(&ch1_params, true); } break;
1044 case 1: { draw_parameters_square(&pat->ch2.params[16], false); } break; 1044 case 1: { draw_parameters_square(&ch2_params, false); } break;
1045 case 2: { draw_parameters_wave(&pat->ch3.params[16]); } break; 1045 case 2: { draw_parameters_wave(&ch3_params); } break;
1046 case 3: { draw_parameters_noise(&pat->ch4.params[16]); } break; 1046 case 3: { draw_parameters_noise(&ch4_params); } break;
1047 } 1047 }
1048 return; 1048 return;
1049 } 1049 }
diff --git a/src/patterns.c b/src/patterns.c
index dbd9c9f..6ce0878 100644
--- a/src/patterns.c
+++ b/src/patterns.c
@@ -34,19 +34,19 @@ typedef struct ChannelNoiseParams {
34typedef struct ChannelSquare { 34typedef struct ChannelSquare {
35 bool active; 35 bool active;
36 TriggerNote notes[16]; 36 TriggerNote notes[16];
37 ChannelSquareParams params[17]; 37 ChannelSquareParams params[16];
38} ChannelSquare; 38} ChannelSquare;
39 39
40typedef struct ChannelWave { 40typedef struct ChannelWave {
41 bool active; 41 bool active;
42 TriggerNote notes[16]; 42 TriggerNote notes[16];
43 ChannelWaveParams params[17]; 43 ChannelWaveParams params[16];
44} ChannelWave; 44} ChannelWave;
45 45
46typedef struct ChannelNoise { 46typedef struct ChannelNoise {
47 bool active; 47 bool active;
48 TriggerNote notes[16]; 48 TriggerNote notes[16];
49 ChannelNoiseParams params[17]; 49 ChannelNoiseParams params[16];
50} ChannelNoise; 50} ChannelNoise;
51 51
52typedef struct Pattern { 52typedef struct Pattern {
@@ -58,6 +58,11 @@ typedef struct Pattern {
58 u8 bank; 58 u8 bank;
59} Pattern; 59} Pattern;
60 60
61static ChannelSquareParams ch1_params = {0};
62static ChannelSquareParams ch2_params = {0};
63static ChannelWaveParams ch3_params = {0};
64static ChannelNoiseParams ch4_params = {0};
65
61// 66//
62// Defaults. 67// Defaults.
63// 68//
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) {
462} 462}
463 463
464bool 464bool
465set_param_selection_sq1(size_t i, InputHandler return_handler) { 465set_param_selection_sq1(ChannelSquareParams *params, InputHandler return_handler) {
466 // Go back to trigger selection. 466 // Go back to trigger selection.
467 if (key_released(KEY_A)) { 467 if (key_released(KEY_A)) {
468 input_handler = return_handler; 468 input_handler = return_handler;
@@ -525,8 +525,6 @@ set_param_selection_sq1(size_t i, InputHandler return_handler) {
525 } else { 525 } else {
526 inc = 1; 526 inc = 1;
527 } 527 }
528 Pattern *pat = &patterns[pattern_selection_loc];
529 ChannelSquareParams *params = &pat->ch1.params[i];
530 switch (param_selection_loc) { 528 switch (param_selection_loc) {
531 case 0: { 529 case 0: {
532 params->duty_cycle = CLAMP(params->duty_cycle + inc, 0, 3); 530 params->duty_cycle = CLAMP(params->duty_cycle + inc, 0, 3);
@@ -558,7 +556,7 @@ set_param_selection_sq1(size_t i, InputHandler return_handler) {
558} 556}
559 557
560bool 558bool
561set_param_selection_sq2(size_t i, InputHandler return_handler) { 559set_param_selection_sq2(ChannelSquareParams *params, InputHandler return_handler) {
562 // Go back to trigger selection. 560 // Go back to trigger selection.
563 if (key_released(KEY_A)) { 561 if (key_released(KEY_A)) {
564 input_handler = return_handler; 562 input_handler = return_handler;
@@ -588,8 +586,6 @@ set_param_selection_sq2(size_t i, InputHandler return_handler) {
588 } else { 586 } else {
589 inc = 1; 587 inc = 1;
590 } 588 }
591 Pattern *pat = &patterns[pattern_selection_loc];
592 ChannelSquareParams *params = &pat->ch2.params[i];
593 switch (param_selection_loc) { 589 switch (param_selection_loc) {
594 case 0: { 590 case 0: {
595 params->duty_cycle = CLAMP(params->duty_cycle + inc, 0, 3); 591 params->duty_cycle = CLAMP(params->duty_cycle + inc, 0, 3);
@@ -612,9 +608,7 @@ set_param_selection_sq2(size_t i, InputHandler return_handler) {
612} 608}
613 609
614bool 610bool
615set_param_selection_wave(size_t i, InputHandler return_handler) { 611set_param_selection_wave(ChannelWaveParams *params, InputHandler return_handler) {
616 Pattern *pat = &patterns[pattern_selection_loc];
617
618 // Go back to trigger selection. 612 // Go back to trigger selection.
619 if (key_released(KEY_A)) { 613 if (key_released(KEY_A)) {
620 input_handler = return_handler; 614 input_handler = return_handler;
@@ -724,7 +718,7 @@ set_param_selection_wave(size_t i, InputHandler return_handler) {
724 if (param_selection_loc < 32) { 718 if (param_selection_loc < 32) {
725 // Draw on wave a. 719 // Draw on wave a.
726 u8 byte_number = param_selection_loc / 2; 720 u8 byte_number = param_selection_loc / 2;
727 u8 *byte = &pat->ch3.params[i].wave_a; 721 u8 *byte = &params->wave_a;
728 byte += byte_number; 722 byte += byte_number;
729 if (odd) { 723 if (odd) {
730 *byte = (~0xF & *byte) | ((*byte + inc) & 0xF); 724 *byte = (~0xF & *byte) | ((*byte + inc) & 0xF);
@@ -734,7 +728,7 @@ set_param_selection_wave(size_t i, InputHandler return_handler) {
734 } else if (param_selection_loc < 64){ 728 } else if (param_selection_loc < 64){
735 // Draw on wave b. 729 // Draw on wave b.
736 u8 byte_number = (param_selection_loc - 32) / 2; 730 u8 byte_number = (param_selection_loc - 32) / 2;
737 u8 *byte = &pat->ch3.params[i].wave_b; 731 u8 *byte = &params->wave_b;
738 byte += byte_number; 732 byte += byte_number;
739 if (odd) { 733 if (odd) {
740 *byte = (~0xF & *byte) | ((*byte + inc) & 0xF); 734 *byte = (~0xF & *byte) | ((*byte + inc) & 0xF);
@@ -743,8 +737,8 @@ set_param_selection_wave(size_t i, InputHandler return_handler) {
743 } 737 }
744 } else if (param_selection_loc < 72) { 738 } else if (param_selection_loc < 72) {
745 // Copy default waves. 739 // Copy default waves.
746 u32 *wave_a = &pat->ch3.params[i].wave_a; 740 u32 *wave_a = &params->wave_a;
747 u32 *wave_b = &pat->ch3.params[i].wave_b; 741 u32 *wave_b = &params->wave_b;
748 switch (param_selection_loc) { 742 switch (param_selection_loc) {
749 case 64: { memcpy32(wave_a, sine_wave, 16); } break; 743 case 64: { memcpy32(wave_a, sine_wave, 16); } break;
750 case 65: { memcpy32(wave_a, saw_wave, 16); } break; 744 case 65: { memcpy32(wave_a, saw_wave, 16); } break;
@@ -766,10 +760,10 @@ set_param_selection_wave(size_t i, InputHandler return_handler) {
766 } break; 760 } break;
767 } 761 }
768 } else if (param_selection_loc == 72) { 762 } else if (param_selection_loc == 72) {
769 u8 *wave_mode = &pat->ch3.params[i].wave_mode; 763 u8 *wave_mode = &params->wave_mode;
770 *wave_mode = CLAMP(*wave_mode + inc, 0, 2); 764 *wave_mode = CLAMP(*wave_mode + inc, 0, 2);
771 } else if (param_selection_loc == 73) { 765 } else if (param_selection_loc == 73) {
772 u8 *wave_volume = &pat->ch3.params[i].wave_volume; 766 u8 *wave_volume = &params->wave_volume;
773 *wave_volume = CLAMP(*wave_volume + inc, 0, 4); 767 *wave_volume = CLAMP(*wave_volume + inc, 0, 4);
774 } 768 }
775 redraw_params = true; 769 redraw_params = true;
@@ -780,7 +774,7 @@ set_param_selection_wave(size_t i, InputHandler return_handler) {
780} 774}
781 775
782bool 776bool
783set_param_selection_noise(size_t i, InputHandler return_handler) { 777set_param_selection_noise(ChannelNoiseParams *params, InputHandler return_handler) {
784 // Go back to trigger selection. 778 // Go back to trigger selection.
785 if (key_released(KEY_A)) { 779 if (key_released(KEY_A)) {
786 input_handler = return_handler; 780 input_handler = return_handler;
@@ -810,8 +804,6 @@ set_param_selection_noise(size_t i, InputHandler return_handler) {
810 } else { 804 } else {
811 inc = 1; 805 inc = 1;
812 } 806 }
813 Pattern *pat = &patterns[pattern_selection_loc];
814 ChannelNoiseParams *params = &pat->ch4.params[i];
815 switch (param_selection_loc) { 807 switch (param_selection_loc) {
816 case 0: { 808 case 0: {
817 params->bit_mode = CLAMP(params->bit_mode + inc, 0, 1); 809 params->bit_mode = CLAMP(params->bit_mode + inc, 0, 1);
@@ -836,9 +828,9 @@ set_param_selection_noise(size_t i, InputHandler return_handler) {
836void 828void
837handle_param_selection_ch1() { 829handle_param_selection_ch1() {
838 Pattern *pat = &patterns[pattern_selection_loc]; 830 Pattern *pat = &patterns[pattern_selection_loc];
839 if (set_param_selection_sq1(16, handle_channel_selection)) { 831 if (set_param_selection_sq1(&ch1_params, handle_channel_selection)) {
840 for (size_t i = 0; i < 16; i++) { 832 for (size_t i = 0; i < 16; i++) {
841 pat->ch1.params[i] = pat->ch1.params[16]; 833 pat->ch1.params[i] = ch1_params;
842 } 834 }
843 } 835 }
844} 836}
@@ -846,9 +838,9 @@ handle_param_selection_ch1() {
846void 838void
847handle_param_selection_ch2() { 839handle_param_selection_ch2() {
848 Pattern *pat = &patterns[pattern_selection_loc]; 840 Pattern *pat = &patterns[pattern_selection_loc];
849 if (set_param_selection_sq2(16, handle_channel_selection)) { 841 if (set_param_selection_sq2(&ch2_params, handle_channel_selection)) {
850 for (size_t i = 0; i < 16; i++) { 842 for (size_t i = 0; i < 16; i++) {
851 pat->ch2.params[i] = pat->ch2.params[16]; 843 pat->ch2.params[i] = ch2_params;
852 } 844 }
853 } 845 }
854} 846}
@@ -856,9 +848,9 @@ handle_param_selection_ch2() {
856void 848void
857handle_param_selection_ch3() { 849handle_param_selection_ch3() {
858 Pattern *pat = &patterns[pattern_selection_loc]; 850 Pattern *pat = &patterns[pattern_selection_loc];
859 if (set_param_selection_wave(16, handle_channel_selection)) { 851 if (set_param_selection_wave(&ch3_params, handle_channel_selection)) {
860 for (size_t i = 0; i < 16; i++) { 852 for (size_t i = 0; i < 16; i++) {
861 pat->ch3.params[i] = pat->ch3.params[16]; 853 pat->ch3.params[i] = ch3_params;
862 } 854 }
863 } 855 }
864} 856}
@@ -866,31 +858,35 @@ handle_param_selection_ch3() {
866void 858void
867handle_param_selection_ch4() { 859handle_param_selection_ch4() {
868 Pattern *pat = &patterns[pattern_selection_loc]; 860 Pattern *pat = &patterns[pattern_selection_loc];
869 if (set_param_selection_noise(16, handle_channel_selection)) { 861 if (set_param_selection_noise(&ch4_params, handle_channel_selection)) {
870 for (size_t i = 0; i < 16; i++) { 862 for (size_t i = 0; i < 16; i++) {
871 pat->ch4.params[i] = pat->ch4.params[16]; 863 pat->ch4.params[i] = ch4_params;
872 } 864 }
873 } 865 }
874} 866}
875 867
876void 868void
877handle_param_selection_sq1() { 869handle_param_selection_sq1() {
878 set_param_selection_sq1(trig_selection_loc, handle_trigger_selection); 870 ChannelSquareParams *params = &patterns[pattern_selection_loc].ch1.params[trig_selection_loc];
871 set_param_selection_sq1(params, handle_trigger_selection);
879} 872}
880 873
881void 874void
882handle_param_selection_sq2() { 875handle_param_selection_sq2() {
883 set_param_selection_sq2(trig_selection_loc, handle_trigger_selection); 876 ChannelSquareParams *params = &patterns[pattern_selection_loc].ch2.params[trig_selection_loc];
877 set_param_selection_sq2(params, handle_trigger_selection);
884} 878}
885 879
886void 880void
887handle_param_selection_wave() { 881handle_param_selection_wave() {
888 set_param_selection_wave(trig_selection_loc, handle_trigger_selection); 882 ChannelWaveParams *params = &patterns[pattern_selection_loc].ch3.params[trig_selection_loc];
883 set_param_selection_wave(params, handle_trigger_selection);
889} 884}
890 885
891void 886void
892handle_param_selection_noise() { 887handle_param_selection_noise() {
893 set_param_selection_noise(trig_selection_loc, handle_trigger_selection); 888 ChannelNoiseParams *params = &patterns[pattern_selection_loc].ch4.params[trig_selection_loc];
889 set_param_selection_noise(params, handle_trigger_selection);
894} 890}
895 891
896void 892void