aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2023-05-31 18:21:30 +0200
committerBad Diode <bd@badd10de.dev>2023-05-31 18:21:30 +0200
commit300ca4c16a45ef129a65a5520eab068f1f74c29b (patch)
tree18a935c27789079a7fa096afbef1c80d7e122daa
parentf0ebc747d1b0d8753a1bc0f74b34a3012dd16753 (diff)
downloadstepper-300ca4c16a45ef129a65a5520eab068f1f74c29b.tar.gz
stepper-300ca4c16a45ef129a65a5520eab068f1f74c29b.zip
Add link cable sync in
-rw-r--r--Makefile2
-rw-r--r--src/main.c4
-rw-r--r--src/sequencer.c46
-rw-r--r--src/settings.c20
-rw-r--r--src/settings.h2
5 files changed, 60 insertions, 14 deletions
diff --git a/Makefile b/Makefile
index 5ccc725..ff4204f 100644
--- a/Makefile
+++ b/Makefile
@@ -27,7 +27,7 @@ INC_FLAGS := $(addprefix -I,$(INC_DIRS))
27INC_FLAGS += -I$(LIBGBA_SRC) 27INC_FLAGS += -I$(LIBGBA_SRC)
28 28
29# Output library names and executables. 29# Output library names and executables.
30TARGET := STEPPER-v1.4-dev 30TARGET := STEPPER-v1.4-dev-syncin
31ELF := $(BUILD_DIR)/$(TARGET).elf 31ELF := $(BUILD_DIR)/$(TARGET).elf
32BIN := $(BUILD_DIR)/$(TARGET).gba 32BIN := $(BUILD_DIR)/$(TARGET).gba
33 33
diff --git a/src/main.c b/src/main.c
index 0d4056a..ab5bccf 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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
183void 183void
184set_time(int bpm) { 184set_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
301void 304void
302stop_playing(void) { 305stop_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
313void 315void
316stop_playing(void) {
317 step_counter = 0;
318 stop_sound();
319}
320
321void
314toggle_playing(void) { 322toggle_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
334void 346void
335pause_playing(void) { 347pause_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
354void 369void
@@ -1007,6 +1022,13 @@ handle_sequencer_input(void) {
1007} 1022}
1008 1023
1009void 1024void
1025serial_irq() {
1026 if (play_status) {
1027 play_step();
1028 }
1029}
1030
1031void
1010sequencer_init(void) { 1032sequencer_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
16void serial_irq(void);
17void stop_sound(void);
18void toggle_playing(void);
19
16void 20void
17set_audio_settings(void) { 21set_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
33typedef enum ThemeSetting { 35typedef enum ThemeSetting {