aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2023-09-08 14:29:12 +0200
committerBad Diode <bd@badd10de.dev>2023-09-08 14:29:12 +0200
commit004e84fd5ed8943f6058dc31690bb3af61d27574 (patch)
treed9f7ba0803fc18ea6fd4a167e513e8084bd5753e
parentfff06404696bb8790901cdefe016cd8d0fe856cb (diff)
downloadstepper-004e84fd5ed8943f6058dc31690bb3af61d27574.tar.gz
stepper-004e84fd5ed8943f6058dc31690bb3af61d27574.zip
Fix a few bugs and randomize patterns properly
-rw-r--r--src/main.c15
-rw-r--r--src/sequencer.c46
-rw-r--r--src/settings.c9
3 files changed, 63 insertions, 7 deletions
diff --git a/src/main.c b/src/main.c
index 6f34d27..d6ea621 100644
--- a/src/main.c
+++ b/src/main.c
@@ -39,6 +39,7 @@ WITH REGARD TO THIS SOFTWARE.
39// - Should scale mode be toggleable? 39// - Should scale mode be toggleable?
40// - Improve SRAM saving to make room for longer patterns and/or more banks. 40// - Improve SRAM saving to make room for longer patterns and/or more banks.
41// - Higher resolution clock to allow for microtiming and more accurate tempo. 41// - Higher resolution clock to allow for microtiming and more accurate tempo.
42// - Add clipboard sharing between banks.
42// 43//
43// WIP (1.7) 44// WIP (1.7)
44// + Improve "grey" cursor with dithering instead. 45// + Improve "grey" cursor with dithering instead.
@@ -66,9 +67,23 @@ WITH REGARD TO THIS SOFTWARE.
66// + Enable pattern chain toggling. 67// + Enable pattern chain toggling.
67// + Enable pattern chain clearing. 68// + Enable pattern chain clearing.
68// + Enable pattern chain randomizing. 69// + Enable pattern chain randomizing.
70// + Check to make sure parameters are fully clearing the screen, the cursor
71// can hang (need to clear the cursor parameter position when moving to/from
72// patterns to channels)
73// + If select random chain patterns when nothing there chain is propagated but
74// play head doesn’t begin at first chain pattern. User must manually place
75// a pattern to start chain.
76// + Random chain just places A- doesn’t check if which patterns have content
77// in bank for random placement.
69// - Add CREDITS to the documentation for now, should probably be a menu item 78// - Add CREDITS to the documentation for now, should probably be a menu item
70// later. 79// later.
71// - Make sure sync works with the same cable for in/out. 80// - Make sure sync works with the same cable for in/out.
81// - Add help for scale parameters and banks E/F (consider auto-save settings
82// for notification)
83// - Add help for pattern chain
84// - Default should be help is on
85// - Cursor on bank can wrap around (up/down) but the same can't be done on
86// patterns.
72 87
73#include "gba/gba.h" 88#include "gba/gba.h"
74 89
diff --git a/src/sequencer.c b/src/sequencer.c
index 266db94..512555a 100644
--- a/src/sequencer.c
+++ b/src/sequencer.c
@@ -805,13 +805,12 @@ handle_pattern_chain(void) {
805 switch (param_selection_loc) { 805 switch (param_selection_loc) {
806 case CHAIN_BTN_ENABLE: { 806 case CHAIN_BTN_ENABLE: {
807 chain.enabled ^= 1; 807 chain.enabled ^= 1;
808 chain.current = 15; 808 chain.playing ^= 1;
809 chain.current = find_next_pattern();
810 chain.playing = false;
811 } break; 809 } break;
812 case CHAIN_BTN_CLEAR: { 810 case CHAIN_BTN_CLEAR: {
813 chain.len = 0; 811 chain.len = 0;
814 chain.playing = false; 812 chain.playing = false;
813 chain.enabled = 0;
815 for (size_t i = 0; i < MAX_CHAIN; i++) { 814 for (size_t i = 0; i < MAX_CHAIN; i++) {
816 chain.active[i] = false; 815 chain.active[i] = false;
817 chain.chain[i] = 0; 816 chain.chain[i] = 0;
@@ -821,18 +820,49 @@ handle_pattern_chain(void) {
821 } break; 820 } break;
822 case CHAIN_BTN_RANDOM: { 821 case CHAIN_BTN_RANDOM: {
823 u8 cur = chain.current % 16; 822 u8 cur = chain.current % 16;
823 chain.len = 0;
824 for (size_t i = 0; i < MAX_CHAIN; i++) { 824 for (size_t i = 0; i < MAX_CHAIN; i++) {
825 if (i == cur && chain.playing) { 825 if (i == cur && chain.playing) {
826 chain.len++;
826 continue; 827 continue;
827 } 828 }
828 if (rng16() < 32765) { 829 if (rng16() < 32765) {
830 u16 idx = 0;
831 for (size_t i = 0; i < 8; i++) {
832 u16 val = rng16();
833 if (val < 1 * 65530 / 8 && !patterns[0].empty) { idx = 0; break; }
834 if (val < 2 * 65530 / 8 && !patterns[1].empty) { idx = 1; break; }
835 if (val < 3 * 65530 / 8 && !patterns[2].empty) { idx = 2; break; }
836 if (val < 4 * 65530 / 8 && !patterns[3].empty) { idx = 3; break; }
837 if (val < 5 * 65530 / 8 && !patterns[4].empty) { idx = 4; break; }
838 if (val < 6 * 65530 / 8 && !patterns[5].empty) { idx = 5; break; }
839 if (val < 7 * 65530 / 8 && !patterns[6].empty) { idx = 6; break; }
840 if (val < 8 * 65530 / 8 && !patterns[7].empty) { idx = 7; break; }
841 }
842 chain.chain[i] = idx;
843 if (!chain.playing && chain.len == 0) {
844 chain.chain[i] = current_pattern;
845 chain.current = current_pattern;
846 }
829 chain.active[i] = true; 847 chain.active[i] = true;
848 chain.len++;
830 } else { 849 } else {
831 chain.active[i] = false; 850 chain.active[i] = false;
832 } 851 }
833 // NOTE: Should we also randomize the patterns or isn't it
834 // necessary?
835 } 852 }
853
854 // Make sure at least one chain step is set.
855 if (chain.len == 0) {
856 chain.chain[0] = current_pattern;
857 chain.active[0] = true;
858 chain.len++;
859 }
860 if (!chain.playing) {
861 chain.current = 15;
862 chain.current = find_next_pattern();
863 }
864 chain.enabled = 1;
865 chain.playing = true;
836 } break; 866 } break;
837 default: { 867 default: {
838 if (chain.active[param_selection_loc]) { 868 if (chain.active[param_selection_loc]) {
@@ -902,6 +932,7 @@ handle_pattern_selection(void) {
902 input_handler = handle_pattern_chain; 932 input_handler = handle_pattern_chain;
903 } 933 }
904 if (key_tap(KEY_RIGHT)) { 934 if (key_tap(KEY_RIGHT)) {
935 param_selection_loc = 0;
905 input_handler = handle_channel_selection; 936 input_handler = handle_channel_selection;
906 redraw_params = true; 937 redraw_params = true;
907 } else if (key_tap(KEY_UP)) { 938 } else if (key_tap(KEY_UP)) {
@@ -922,6 +953,7 @@ handle_pattern_selection(void) {
922 if (key_tap(KEY_LEFT)) { 953 if (key_tap(KEY_LEFT)) {
923 redraw_params = true; 954 redraw_params = true;
924 input_handler = handle_right_col_selection; 955 input_handler = handle_right_col_selection;
956 param_selection_loc = 0;
925 right_col_selection_loc = R_COL_BPM; 957 right_col_selection_loc = R_COL_BPM;
926 switch (pattern_selection_loc) { 958 switch (pattern_selection_loc) {
927 case 0: { right_col_selection_loc = R_COL_BANK_B; } break; 959 case 0: { right_col_selection_loc = R_COL_BANK_B; } break;
@@ -949,6 +981,7 @@ handle_pattern_selection(void) {
949 } 981 }
950 chain.chain[slot] = pattern_selection_loc; 982 chain.chain[slot] = pattern_selection_loc;
951 chain.active[slot] = 1; 983 chain.active[slot] = 1;
984 chain.enabled = 1;
952 chain.len++; 985 chain.len++;
953 } 986 }
954 } 987 }
@@ -976,6 +1009,9 @@ handle_pattern_selection(void) {
976 chain.current = find_prev_pattern(); 1009 chain.current = find_prev_pattern();
977 } 1010 }
978 } 1011 }
1012 if (chain.len == 0) {
1013 chain.enabled = 0;
1014 }
979 } 1015 }
980} 1016}
981 1017
diff --git a/src/settings.c b/src/settings.c
index 5a10c90..31b3dd3 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -4,6 +4,7 @@
4static Settings settings = { 4static Settings settings = {
5 .bpm = 90, 5 .bpm = 90,
6 .auto_save = TOGGLE_ON, 6 .auto_save = TOGGLE_ON,
7 .help = TOGGLE_ON,
7}; 8};
8static int settings_cursor_loc = 0; 9static int settings_cursor_loc = 0;
9 10
@@ -103,7 +104,9 @@ handle_settings_input(void) {
103 settings.global_bpm++; 104 settings.global_bpm++;
104 } 105 }
105 redraw_bpm = true; 106 redraw_bpm = true;
106 update_bpm = true; 107 if (play_status) {
108 update_bpm = true;
109 }
107 } break; 110 } break;
108 case SETTINGS_AUTO_SAVE: { 111 case SETTINGS_AUTO_SAVE: {
109 if ((settings.auto_save + 1) >= TOGGLE_NUM) { 112 if ((settings.auto_save + 1) >= TOGGLE_NUM) {
@@ -155,7 +158,9 @@ handle_settings_input(void) {
155 settings.global_bpm--; 158 settings.global_bpm--;
156 } 159 }
157 redraw_bpm = true; 160 redraw_bpm = true;
158 update_bpm = true; 161 if (play_status) {
162 update_bpm = true;
163 }
159 } break; 164 } break;
160 case SETTINGS_AUTO_SAVE: { 165 case SETTINGS_AUTO_SAVE: {
161 if (settings.auto_save == 0) { 166 if (settings.auto_save == 0) {