diff options
author | Bad Diode <bd@badd10de.dev> | 2023-05-28 20:07:07 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2023-05-28 20:07:07 +0200 |
commit | ac17920096b18caa4cadec3fea347f9fc804baea (patch) | |
tree | 8bf98a62b7f703d1517977389cfe1712a4dc4b75 | |
parent | 52bdd0d79c77df0a7752fd15ebcc730f9e9796b1 (diff) | |
download | stepper-ac17920096b18caa4cadec3fea347f9fc804baea.tar.gz stepper-ac17920096b18caa4cadec3fea347f9fc804baea.zip |
Make sure link cable sync respects user settings
-rw-r--r-- | src/globals.c | 6 | ||||
-rw-r--r-- | src/main.c | 8 | ||||
-rw-r--r-- | src/sequencer.c | 41 | ||||
-rw-r--r-- | src/settings.c | 2 | ||||
-rw-r--r-- | src/settings.h | 1 |
5 files changed, 37 insertions, 21 deletions
diff --git a/src/globals.c b/src/globals.c index 60e64e7..7396968 100644 --- a/src/globals.c +++ b/src/globals.c | |||
@@ -17,7 +17,7 @@ u32 last_channel_loc = 0; | |||
17 | u32 last_pattern_loc = 0; | 17 | u32 last_pattern_loc = 0; |
18 | u32 last_right_col_loc = 0; | 18 | u32 last_right_col_loc = 0; |
19 | u32 last_step_counter = 0; | 19 | u32 last_step_counter = 0; |
20 | bool clear_screen = false; | 20 | bool clear_screen = true; |
21 | 21 | ||
22 | // | 22 | // |
23 | // Color indexes. | 23 | // Color indexes. |
@@ -120,5 +120,5 @@ typedef enum Scene { | |||
120 | SCENE_SETTINGS, | 120 | SCENE_SETTINGS, |
121 | } Scene; | 121 | } Scene; |
122 | 122 | ||
123 | static Scene scene = SCENE_SETTINGS; | 123 | static Scene scene = SCENE_SEQUENCER; |
124 | static Scene next_scene = SCENE_SETTINGS; | 124 | static Scene next_scene = SCENE_SEQUENCER; |
@@ -147,6 +147,14 @@ update(void) { | |||
147 | if (next_scene != scene) { | 147 | if (next_scene != scene) { |
148 | scene = next_scene; | 148 | scene = next_scene; |
149 | clear_screen = true; | 149 | clear_screen = true; |
150 | redraw_trigs = true; | ||
151 | redraw_channels = true; | ||
152 | redraw_pattern_buttons = true; | ||
153 | redraw_bank_buttons = true; | ||
154 | redraw_bpm = true; | ||
155 | redraw_play_pause = true; | ||
156 | redraw_piano_note = true; | ||
157 | redraw_params = true; | ||
150 | } | 158 | } |
151 | last_trig_loc = trig_selection_loc; | 159 | last_trig_loc = trig_selection_loc; |
152 | last_channel_loc = channel_selection_loc; | 160 | last_channel_loc = channel_selection_loc; |
diff --git a/src/sequencer.c b/src/sequencer.c index 44ec7bb..52e0e01 100644 --- a/src/sequencer.c +++ b/src/sequencer.c | |||
@@ -32,6 +32,22 @@ gate_off(void) { | |||
32 | } | 32 | } |
33 | 33 | ||
34 | void | 34 | void |
35 | gate_on(void) { | ||
36 | SIO_MODE = SIO_MODE_GP | ||
37 | | SIO_SC_OUT(1) | ||
38 | | SIO_SD_OUT(1) | ||
39 | | SIO_SI_OUT(0) | ||
40 | | SIO_SO_OUT(1) | ||
41 | | SIO_SC(1) | ||
42 | | SIO_SD(1) | ||
43 | | SIO_SO(0); | ||
44 | int n_ticks = -244181 / 600; | ||
45 | irs_set(IRQ_TIMER_1, gate_off); | ||
46 | TIMER_DATA_1 = n_ticks; | ||
47 | TIMER_CTRL_1 = TIMER_CTRL_IRQ | TIMER_CTRL_ENABLE | TIMER_CTRL_FREQ_3; | ||
48 | } | ||
49 | |||
50 | void | ||
35 | play_step(void) { | 51 | play_step(void) { |
36 | Pattern *pat = &patterns[current_pattern]; | 52 | Pattern *pat = &patterns[current_pattern]; |
37 | if (current_pattern != next_pattern && step_counter == 15) { | 53 | if (current_pattern != next_pattern && step_counter == 15) { |
@@ -147,21 +163,12 @@ play_step(void) { | |||
147 | SOUND_NOISE_CTRL = 0; | 163 | SOUND_NOISE_CTRL = 0; |
148 | SOUND_NOISE_FREQ = 0; | 164 | SOUND_NOISE_FREQ = 0; |
149 | } | 165 | } |
150 | // TODO: This should be configurable e.g. po needs a 1 each 2 to sync | 166 | |
151 | // exactly, but we can also just want a pseudo clock divider. | 167 | switch (settings.sync) { |
152 | if (step_counter % 2 == 0) { | 168 | case SYNC_OUT_LINK_16: { gate_on(); } break; |
153 | SIO_MODE = SIO_MODE_GP | 169 | case SYNC_OUT_LINK_8: { if (step_counter % 2 == 0) { gate_on(); } } break; |
154 | | SIO_SC_OUT(1) | 170 | case SYNC_OUT_LINK_4: { if (step_counter % 4 == 0) { gate_on(); } } break; |
155 | | SIO_SD_OUT(1) | 171 | default: break; |
156 | | SIO_SI_OUT(0) | ||
157 | | SIO_SO_OUT(1) | ||
158 | | SIO_SC(1) | ||
159 | | SIO_SD(1) | ||
160 | | SIO_SO(0); | ||
161 | int n_ticks = -244181 / 600; | ||
162 | irs_set(IRQ_TIMER_1, gate_off); | ||
163 | TIMER_DATA_1 = n_ticks; | ||
164 | TIMER_CTRL_1 = TIMER_CTRL_IRQ | TIMER_CTRL_ENABLE | TIMER_CTRL_FREQ_3; | ||
165 | } | 172 | } |
166 | step_counter = (step_counter + 1) % 16; | 173 | step_counter = (step_counter + 1) % 16; |
167 | redraw_piano_note = true; | 174 | redraw_piano_note = true; |
@@ -424,7 +431,7 @@ handle_right_col_selection(void) { | |||
424 | } | 431 | } |
425 | } else if (key_tap(KEY_B)) { | 432 | } else if (key_tap(KEY_B)) { |
426 | switch (right_col_selection_loc) { | 433 | switch (right_col_selection_loc) { |
427 | case R_COL_STOP: { toggle_playing(); } break; | 434 | case R_COL_STOP: { next_scene = SCENE_SETTINGS; } break; |
428 | case R_COL_PLAY: { pause_playing(); } break; | 435 | case R_COL_PLAY: { pause_playing(); } break; |
429 | case R_COL_BANK_A: { select_bank(0); } break; | 436 | case R_COL_BANK_A: { select_bank(0); } break; |
430 | case R_COL_BANK_B: { select_bank(1); } break; | 437 | case R_COL_BANK_B: { select_bank(1); } break; |
@@ -984,6 +991,8 @@ handle_sequencer_input(void) { | |||
984 | 991 | ||
985 | void | 992 | void |
986 | sequencer_init(void) { | 993 | sequencer_init(void) { |
994 | stop_playing(); | ||
995 | |||
987 | // Load the previous bank from SRAM or initialize it if needed. | 996 | // Load the previous bank from SRAM or initialize it if needed. |
988 | sram_read(&metadata, 0, sizeof(Metadata)); | 997 | sram_read(&metadata, 0, sizeof(Metadata)); |
989 | if (metadata.initialized != SAVE_INIT_MAGIC) { | 998 | if (metadata.initialized != SAVE_INIT_MAGIC) { |
diff --git a/src/settings.c b/src/settings.c index fd5b090..fca5696 100644 --- a/src/settings.c +++ b/src/settings.c | |||
@@ -57,7 +57,7 @@ handle_settings_input(void) { | |||
57 | save_metadata(); | 57 | save_metadata(); |
58 | clear_screen = true; | 58 | clear_screen = true; |
59 | } | 59 | } |
60 | if (key_tap(KEY_B)) { | 60 | if (key_tap(KEY_A)) { |
61 | next_scene = SCENE_SEQUENCER; | 61 | next_scene = SCENE_SEQUENCER; |
62 | } | 62 | } |
63 | } | 63 | } |
diff --git a/src/settings.h b/src/settings.h index db46144..57b61a5 100644 --- a/src/settings.h +++ b/src/settings.h | |||
@@ -40,5 +40,4 @@ typedef struct Settings { | |||
40 | CursorSetting cursor; | 40 | CursorSetting cursor; |
41 | } Settings; | 41 | } Settings; |
42 | 42 | ||
43 | |||
44 | #endif // SETTINGS_H | 43 | #endif // SETTINGS_H |