aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2024-01-06 13:02:22 +0100
committerBad Diode <bd@badd10de.dev>2024-01-06 13:02:22 +0100
commitfb4695460b6ecc3a380e1bda5cb2e2173e980ed9 (patch)
tree7b51345fcdb1a5cef147df94a864670b0280d629
parentb83804d58aa7d5a04c9b336c523b1337bc2411d3 (diff)
downloadstepper-fb4695460b6ecc3a380e1bda5cb2e2173e980ed9.tar.gz
stepper-fb4695460b6ecc3a380e1bda5cb2e2173e980ed9.zip
Rework play/pause functions
-rw-r--r--Makefile2
-rw-r--r--src/sequencer.c88
2 files changed, 20 insertions, 70 deletions
diff --git a/Makefile b/Makefile
index 3486200..e867ed3 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.8-dev-02 30TARGET := STEPPER-v1.8-dev-05
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/sequencer.c b/src/sequencer.c
index b5cfd46..ab21274 100644
--- a/src/sequencer.c
+++ b/src/sequencer.c
@@ -501,7 +501,6 @@ handle_channel_selection(void) {
501 501
502void 502void
503stop_sound(void) { 503stop_sound(void) {
504 play_status = 0;
505 TIMER_CTRL_2 = 0; 504 TIMER_CTRL_2 = 0;
506 SOUND_SQUARE1_SWEEP = SOUND_SWEEP_DIR(1); 505 SOUND_SQUARE1_SWEEP = SOUND_SWEEP_DIR(1);
507 asm("nop"); asm("nop"); 506 asm("nop"); asm("nop");
@@ -521,50 +520,42 @@ stop_sound(void) {
521} 520}
522 521
523void 522void
524stop_playing(void) { 523reset_sequencer(void) {
525 step_counter = 0; 524 step_counter = 0;
526 nseq_ticks = 0; 525 nseq_ticks = 0;
527 chain.current = 15; 526 chain.current = 15;
528 chain.current = find_next_pattern(); 527 chain.current = find_next_pattern();
529 chain.playing = false; 528 chain.playing = false;
530 bar_counter = 0; 529 bar_counter = 0;
530}
531
532void
533stop_playing(void) {
534 play_status = 0;
535 reset_sequencer();
531 stop_sound(); 536 stop_sound();
532} 537}
533 538
534void 539void
535toggle_playing(void) { 540toggle_playing(void) {
541 // Toggle play status.
536 play_status ^= 1; 542 play_status ^= 1;
537 step_counter = 0; 543 redraw_play_pause = true;
538 nseq_ticks = 0; 544 redraw_pattern_buttons = true;
539 chain.current = 15; 545
540 chain.current = find_next_pattern(); 546 // Make sure fresh playing from a sequence works as expected.
541 chain.playing = false;
542 bar_counter = 0;
543 if (current_pattern == next_pattern && chain.len > 0 && chain.enabled) { 547 if (current_pattern == next_pattern && chain.len > 0 && chain.enabled) {
544 chain.playing = true; 548 chain.playing = true;
545 next_pattern = chain.chain[chain.current]; 549 next_pattern = chain.chain[chain.current];
546 current_pattern = next_pattern; 550 current_pattern = next_pattern;
547 } 551 }
548 SOUND_SQUARE1_SWEEP = SOUND_SWEEP_DIR(1); 552
549 asm("nop"); asm("nop");
550 asm("nop"); asm("nop");
551 asm("nop"); asm("nop");
552 asm("nop"); asm("nop");
553 SOUND_SQUARE1_FREQ = SOUND_FREQ_RESET;
554 SOUND_SQUARE2_FREQ = SOUND_FREQ_RESET;
555 SOUND_WAVE_FREQ = SOUND_FREQ_RESET;
556 SOUND_NOISE_FREQ = SOUND_FREQ_RESET;
557 SOUND_SQUARE1_CTRL = 0;
558 SOUND_SQUARE2_CTRL = 0;
559 SOUND_WAVE_CTRL = 0;
560 SOUND_NOISE_CTRL = 0;
561 redraw_play_pause = true;
562 redraw_pattern_buttons = true;
563 if (settings.sync == SYNC_IN_LINK) { 553 if (settings.sync == SYNC_IN_LINK) {
564 return; 554 return;
565 } 555 }
566 556
567 if ((TIMER_CTRL_2 & TIMER_CTRL_ENABLE) == 0) { 557 // Toggle sequencer.
558 if (play_status == 1) {
568 if (current_pattern != next_pattern) { 559 if (current_pattern != next_pattern) {
569 current_pattern = next_pattern; 560 current_pattern = next_pattern;
570 redraw_pattern_buttons = true; 561 redraw_pattern_buttons = true;
@@ -577,51 +568,8 @@ toggle_playing(void) {
577 } else { 568 } else {
578 set_time(patterns[current_pattern].bpm); 569 set_time(patterns[current_pattern].bpm);
579 } 570 }
580 play_step();
581 } else {
582 TIMER_CTRL_2 ^= TIMER_CTRL_ENABLE;
583 }
584}
585
586void
587pause_playing(void) {
588 play_status ^= 1;
589 SOUND_SQUARE1_SWEEP = SOUND_SWEEP_DIR(1);
590 asm("nop"); asm("nop");
591 asm("nop"); asm("nop");
592 asm("nop"); asm("nop");
593 asm("nop"); asm("nop");
594 SOUND_SQUARE1_FREQ = SOUND_FREQ_RESET;
595 SOUND_SQUARE2_FREQ = SOUND_FREQ_RESET;
596 SOUND_WAVE_FREQ = SOUND_FREQ_RESET;
597 SOUND_NOISE_FREQ = SOUND_FREQ_RESET;
598 SOUND_SQUARE1_CTRL = 0;
599 SOUND_SQUARE2_CTRL = 0;
600 SOUND_WAVE_CTRL = 0;
601 SOUND_NOISE_CTRL = 0;
602 chain.playing = false;
603 if (current_pattern == next_pattern && chain.len > 0 && chain.enabled) {
604 chain.playing = true;
605 next_pattern = chain.chain[chain.current];
606 current_pattern = next_pattern;
607 }
608 redraw_play_pause = true;
609 if (settings.sync == SYNC_IN_LINK) {
610 return;
611 }
612 if ((TIMER_CTRL_2 & TIMER_CTRL_ENABLE) == 0) {
613 if (current_pattern != next_pattern && step_counter == 0) {
614 current_pattern = next_pattern;
615 redraw_pattern_buttons = true;
616 }
617 if (settings.global_bpm) {
618 set_time(settings.bpm);
619 } else {
620 set_time(patterns[current_pattern].bpm);
621 }
622 play_step();
623 } else { 571 } else {
624 TIMER_CTRL_2 ^= TIMER_CTRL_ENABLE; 572 stop_sound();
625 } 573 }
626} 574}
627 575
@@ -769,7 +717,7 @@ handle_right_col_selection(void) {
769 case R_COL_SETTINGS: { next_scene = SCENE_SETTINGS; } break; 717 case R_COL_SETTINGS: { next_scene = SCENE_SETTINGS; } break;
770 // case R_COL_SCALE: { stop_playing(); } break; // TODO: Should scale be toggleable? 718 // case R_COL_SCALE: { stop_playing(); } break; // TODO: Should scale be toggleable?
771 case R_COL_STOP: { stop_playing(); } break; 719 case R_COL_STOP: { stop_playing(); } break;
772 case R_COL_PLAY: { pause_playing(); } break; 720 case R_COL_PLAY: { toggle_playing(); } break;
773 case R_COL_BANK_A: { if (play_status) { next_bank = 0; } else { select_bank(0); } redraw_bank_buttons = true; } break; 721 case R_COL_BANK_A: { if (play_status) { next_bank = 0; } else { select_bank(0); } redraw_bank_buttons = true; } break;
774 case R_COL_BANK_B: { if (play_status) { next_bank = 1; } else { select_bank(1); } redraw_bank_buttons = true; } break; 722 case R_COL_BANK_B: { if (play_status) { next_bank = 1; } else { select_bank(1); } redraw_bank_buttons = true; } break;
775 case R_COL_BANK_C: { if (play_status) { next_bank = 2; } else { select_bank(2); } redraw_bank_buttons = true; } break; 723 case R_COL_BANK_C: { if (play_status) { next_bank = 2; } else { select_bank(2); } redraw_bank_buttons = true; } break;
@@ -1537,6 +1485,7 @@ handle_sequencer_input(void) {
1537 return; 1485 return;
1538 } 1486 }
1539 // Stop the sequencer or start playing from the beginning. 1487 // Stop the sequencer or start playing from the beginning.
1488 reset_sequencer();
1540 toggle_playing(); 1489 toggle_playing();
1541 } else if (key_hold(KEY_SELECT)) { 1490 } else if (key_hold(KEY_SELECT)) {
1542 if (input_handler == handle_param_selection_sq1 || 1491 if (input_handler == handle_param_selection_sq1 ||
@@ -1561,6 +1510,7 @@ reset_serial_in(void) {
1561void 1510void
1562serial_irq(void) { 1511serial_irq(void) {
1563 if (play_status) { 1512 if (play_status) {
1513 // 12bpq -> 96bpq?
1564 sequencer_tick(); 1514 sequencer_tick();
1565 sequencer_tick(); 1515 sequencer_tick();
1566 sequencer_tick(); 1516 sequencer_tick();