diff options
author | Bad Diode <bd@badd10de.dev> | 2023-05-31 18:21:30 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2023-05-31 18:21:30 +0200 |
commit | 300ca4c16a45ef129a65a5520eab068f1f74c29b (patch) | |
tree | 18a935c27789079a7fa096afbef1c80d7e122daa | |
parent | f0ebc747d1b0d8753a1bc0f74b34a3012dd16753 (diff) | |
download | stepper-300ca4c16a45ef129a65a5520eab068f1f74c29b.tar.gz stepper-300ca4c16a45ef129a65a5520eab068f1f74c29b.zip |
Add link cable sync in
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | src/main.c | 4 | ||||
-rw-r--r-- | src/sequencer.c | 46 | ||||
-rw-r--r-- | src/settings.c | 20 | ||||
-rw-r--r-- | src/settings.h | 2 |
5 files changed, 60 insertions, 14 deletions
@@ -27,7 +27,7 @@ INC_FLAGS := $(addprefix -I,$(INC_DIRS)) | |||
27 | INC_FLAGS += -I$(LIBGBA_SRC) | 27 | INC_FLAGS += -I$(LIBGBA_SRC) |
28 | 28 | ||
29 | # Output library names and executables. | 29 | # Output library names and executables. |
30 | TARGET := STEPPER-v1.4-dev | 30 | TARGET := STEPPER-v1.4-dev-syncin |
31 | ELF := $(BUILD_DIR)/$(TARGET).elf | 31 | ELF := $(BUILD_DIR)/$(TARGET).elf |
32 | BIN := $(BUILD_DIR)/$(TARGET).gba | 32 | BIN := $(BUILD_DIR)/$(TARGET).gba |
33 | 33 | ||
@@ -32,9 +32,11 @@ WITH REGARD TO THIS SOFTWARE. | |||
32 | // - Select + up/down to queue the next pattern as we move to it? | 32 | // - Select + up/down to queue the next pattern as we move to it? |
33 | // | 33 | // |
34 | // Advanced | 34 | // Advanced |
35 | // + Sync via CV by using the link cable. | 35 | // + Sync (OUT) via CV by using the link cable. |
36 | // + Audio sync by panning left the sound and using right as a click (or | 36 | // + Audio sync by panning left the sound and using right as a click (or |
37 | // viceversa, needs to check the standard.) | 37 | // viceversa, needs to check the standard.) |
38 | // + Sync (IN) via CV by using the link cable. | ||
39 | // - Add tap tempo for BPM. | ||
38 | // - Allow "marking" several trigs to be able to copy/paste them and/or adjust | 40 | // - Allow "marking" several trigs to be able to copy/paste them and/or adjust |
39 | // their parameters. | 41 | // their parameters. |
40 | // - Per trig note probability. | 42 | // - Per trig note probability. |
diff --git a/src/sequencer.c b/src/sequencer.c index 2ee6b07..5120805 100644 --- a/src/sequencer.c +++ b/src/sequencer.c | |||
@@ -182,6 +182,9 @@ play_step(void) { | |||
182 | 182 | ||
183 | void | 183 | void |
184 | set_time(int bpm) { | 184 | set_time(int bpm) { |
185 | if (settings.sync == SYNC_IN_LINK) { | ||
186 | return; | ||
187 | } | ||
185 | // The number of ticks of a 1024 cycle clock in a step based on the BPM can | 188 | // The number of ticks of a 1024 cycle clock in a step based on the BPM can |
186 | // be calculated as: | 189 | // be calculated as: |
187 | // X bpm -> 60000 / 4 / bpm = Y ms = Ye-3 s | 190 | // X bpm -> 60000 / 4 / bpm = Y ms = Ye-3 s |
@@ -299,9 +302,8 @@ handle_channel_selection(void) { | |||
299 | } | 302 | } |
300 | 303 | ||
301 | void | 304 | void |
302 | stop_playing(void) { | 305 | stop_sound(void) { |
303 | play_status = 0; | 306 | play_status = 0; |
304 | step_counter = 0; | ||
305 | TIMER_CTRL_2 = 0; | 307 | TIMER_CTRL_2 = 0; |
306 | SOUND_SQUARE1_CTRL = 0; | 308 | SOUND_SQUARE1_CTRL = 0; |
307 | SOUND_SQUARE2_CTRL = 0; | 309 | SOUND_SQUARE2_CTRL = 0; |
@@ -311,9 +313,24 @@ stop_playing(void) { | |||
311 | } | 313 | } |
312 | 314 | ||
313 | void | 315 | void |
316 | stop_playing(void) { | ||
317 | step_counter = 0; | ||
318 | stop_sound(); | ||
319 | } | ||
320 | |||
321 | void | ||
314 | toggle_playing(void) { | 322 | toggle_playing(void) { |
315 | play_status ^= 1; | 323 | play_status ^= 1; |
316 | step_counter = 0; | 324 | step_counter = 0; |
325 | SOUND_SQUARE1_CTRL = 0; | ||
326 | SOUND_SQUARE2_CTRL = 0; | ||
327 | SOUND_WAVE_CTRL = 0; | ||
328 | SOUND_NOISE_CTRL = 0; | ||
329 | redraw_play_pause = true; | ||
330 | if (settings.sync == SYNC_IN_LINK) { | ||
331 | return; | ||
332 | } | ||
333 | |||
317 | if ((TIMER_CTRL_2 & TIMER_CTRL_ENABLE) == 0) { | 334 | if ((TIMER_CTRL_2 & TIMER_CTRL_ENABLE) == 0) { |
318 | if (current_pattern != next_pattern) { | 335 | if (current_pattern != next_pattern) { |
319 | current_pattern = next_pattern; | 336 | current_pattern = next_pattern; |
@@ -323,17 +340,20 @@ toggle_playing(void) { | |||
323 | play_step(); | 340 | play_step(); |
324 | } else { | 341 | } else { |
325 | TIMER_CTRL_2 ^= TIMER_CTRL_ENABLE; | 342 | TIMER_CTRL_2 ^= TIMER_CTRL_ENABLE; |
326 | SOUND_SQUARE1_CTRL = 0; | ||
327 | SOUND_SQUARE2_CTRL = 0; | ||
328 | SOUND_WAVE_CTRL = 0; | ||
329 | SOUND_NOISE_CTRL = 0; | ||
330 | } | 343 | } |
331 | redraw_play_pause = true; | ||
332 | } | 344 | } |
333 | 345 | ||
334 | void | 346 | void |
335 | pause_playing(void) { | 347 | pause_playing(void) { |
336 | play_status ^= 1; | 348 | play_status ^= 1; |
349 | SOUND_SQUARE1_CTRL = 0; | ||
350 | SOUND_SQUARE2_CTRL = 0; | ||
351 | SOUND_WAVE_CTRL = 0; | ||
352 | SOUND_NOISE_CTRL = 0; | ||
353 | redraw_play_pause = true; | ||
354 | if (settings.sync == SYNC_IN_LINK) { | ||
355 | return; | ||
356 | } | ||
337 | if ((TIMER_CTRL_2 & TIMER_CTRL_ENABLE) == 0) { | 357 | if ((TIMER_CTRL_2 & TIMER_CTRL_ENABLE) == 0) { |
338 | if (current_pattern != next_pattern && step_counter == 0) { | 358 | if (current_pattern != next_pattern && step_counter == 0) { |
339 | current_pattern = next_pattern; | 359 | current_pattern = next_pattern; |
@@ -343,12 +363,7 @@ pause_playing(void) { | |||
343 | play_step(); | 363 | play_step(); |
344 | } else { | 364 | } else { |
345 | TIMER_CTRL_2 ^= TIMER_CTRL_ENABLE; | 365 | TIMER_CTRL_2 ^= TIMER_CTRL_ENABLE; |
346 | SOUND_SQUARE1_CTRL = 0; | ||
347 | SOUND_SQUARE2_CTRL = 0; | ||
348 | SOUND_WAVE_CTRL = 0; | ||
349 | SOUND_NOISE_CTRL = 0; | ||
350 | } | 366 | } |
351 | redraw_play_pause = true; | ||
352 | } | 367 | } |
353 | 368 | ||
354 | void | 369 | void |
@@ -1007,6 +1022,13 @@ handle_sequencer_input(void) { | |||
1007 | } | 1022 | } |
1008 | 1023 | ||
1009 | void | 1024 | void |
1025 | serial_irq() { | ||
1026 | if (play_status) { | ||
1027 | play_step(); | ||
1028 | } | ||
1029 | } | ||
1030 | |||
1031 | void | ||
1010 | sequencer_init(void) { | 1032 | sequencer_init(void) { |
1011 | stop_playing(); | 1033 | stop_playing(); |
1012 | 1034 | ||
diff --git a/src/settings.c b/src/settings.c index b814e1a..2c698d1 100644 --- a/src/settings.c +++ b/src/settings.c | |||
@@ -13,8 +13,25 @@ draw_settings_cursor(void) { | |||
13 | draw_line(x + 3, y + 5, x + 3, y + 5, COL_ACC_0); | 13 | draw_line(x + 3, y + 5, x + 3, y + 5, COL_ACC_0); |
14 | } | 14 | } |
15 | 15 | ||
16 | void serial_irq(void); | ||
17 | void stop_sound(void); | ||
18 | void toggle_playing(void); | ||
19 | |||
16 | void | 20 | void |
17 | set_audio_settings(void) { | 21 | set_audio_settings(void) { |
22 | stop_sound(); | ||
23 | if (settings.sync == SYNC_IN_LINK) { | ||
24 | irs_set(IRQ_SERIAL, serial_irq); | ||
25 | irs_set(IRQ_TIMER_2, NULL); | ||
26 | SIO_MODE = SIO_MODE_GP | ||
27 | | SIO_SC_OUT(0) | ||
28 | | SIO_SD_OUT(0) | ||
29 | | SIO_SI_OUT(0) | ||
30 | | SIO_SO_OUT(0) | ||
31 | | SIO_IRQ_ENABLE; | ||
32 | } else { | ||
33 | irs_set(IRQ_SERIAL, NULL); | ||
34 | } | ||
18 | switch (settings.sync) { | 35 | switch (settings.sync) { |
19 | case SYNC_OUT_LINK_AUDIO_4: | 36 | case SYNC_OUT_LINK_AUDIO_4: |
20 | case SYNC_OUT_LINK_AUDIO_8: | 37 | case SYNC_OUT_LINK_AUDIO_8: |
@@ -121,4 +138,7 @@ handle_settings_input(void) { | |||
121 | if (key_tap(KEY_A)) { | 138 | if (key_tap(KEY_A)) { |
122 | next_scene = SCENE_SEQUENCER; | 139 | next_scene = SCENE_SEQUENCER; |
123 | } | 140 | } |
141 | if (key_tap(KEY_START)) { | ||
142 | toggle_playing(); | ||
143 | } | ||
124 | } | 144 | } |
diff --git a/src/settings.h b/src/settings.h index 960eabc..1a45d75 100644 --- a/src/settings.h +++ b/src/settings.h | |||
@@ -14,6 +14,7 @@ typedef enum SyncSetting { | |||
14 | SYNC_OUT_LINK_AUDIO_16, | 14 | SYNC_OUT_LINK_AUDIO_16, |
15 | SYNC_OUT_LINK_AUDIO_8, | 15 | SYNC_OUT_LINK_AUDIO_8, |
16 | SYNC_OUT_LINK_AUDIO_4, | 16 | SYNC_OUT_LINK_AUDIO_4, |
17 | SYNC_IN_LINK, | ||
17 | SYNC_NUM, | 18 | SYNC_NUM, |
18 | } SyncSetting; | 19 | } SyncSetting; |
19 | 20 | ||
@@ -28,6 +29,7 @@ char * sync_setting_str[] = { | |||
28 | "LINK+AUDIO OUT (16)", | 29 | "LINK+AUDIO OUT (16)", |
29 | "LINK+AUDIO OUT (8)", | 30 | "LINK+AUDIO OUT (8)", |
30 | "LINK+AUDIO OUT (4)", | 31 | "LINK+AUDIO OUT (4)", |
32 | "LINK IN", | ||
31 | }; | 33 | }; |
32 | 34 | ||
33 | typedef enum ThemeSetting { | 35 | typedef enum ThemeSetting { |