From fb4695460b6ecc3a380e1bda5cb2e2173e980ed9 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Sat, 6 Jan 2024 13:02:22 +0100 Subject: Rework play/pause functions --- src/sequencer.c | 88 +++++++++++++-------------------------------------------- 1 file changed, 19 insertions(+), 69 deletions(-) (limited to 'src') 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) { void stop_sound(void) { - play_status = 0; TIMER_CTRL_2 = 0; SOUND_SQUARE1_SWEEP = SOUND_SWEEP_DIR(1); asm("nop"); asm("nop"); @@ -521,50 +520,42 @@ stop_sound(void) { } void -stop_playing(void) { +reset_sequencer(void) { step_counter = 0; nseq_ticks = 0; chain.current = 15; chain.current = find_next_pattern(); chain.playing = false; bar_counter = 0; +} + +void +stop_playing(void) { + play_status = 0; + reset_sequencer(); stop_sound(); } void toggle_playing(void) { + // Toggle play status. play_status ^= 1; - step_counter = 0; - nseq_ticks = 0; - chain.current = 15; - chain.current = find_next_pattern(); - chain.playing = false; - bar_counter = 0; + redraw_play_pause = true; + redraw_pattern_buttons = true; + + // Make sure fresh playing from a sequence works as expected. if (current_pattern == next_pattern && chain.len > 0 && chain.enabled) { chain.playing = true; next_pattern = chain.chain[chain.current]; current_pattern = next_pattern; } - SOUND_SQUARE1_SWEEP = SOUND_SWEEP_DIR(1); - asm("nop"); asm("nop"); - asm("nop"); asm("nop"); - asm("nop"); asm("nop"); - asm("nop"); asm("nop"); - SOUND_SQUARE1_FREQ = SOUND_FREQ_RESET; - SOUND_SQUARE2_FREQ = SOUND_FREQ_RESET; - SOUND_WAVE_FREQ = SOUND_FREQ_RESET; - SOUND_NOISE_FREQ = SOUND_FREQ_RESET; - SOUND_SQUARE1_CTRL = 0; - SOUND_SQUARE2_CTRL = 0; - SOUND_WAVE_CTRL = 0; - SOUND_NOISE_CTRL = 0; - redraw_play_pause = true; - redraw_pattern_buttons = true; + if (settings.sync == SYNC_IN_LINK) { return; } - if ((TIMER_CTRL_2 & TIMER_CTRL_ENABLE) == 0) { + // Toggle sequencer. + if (play_status == 1) { if (current_pattern != next_pattern) { current_pattern = next_pattern; redraw_pattern_buttons = true; @@ -577,51 +568,8 @@ toggle_playing(void) { } else { set_time(patterns[current_pattern].bpm); } - play_step(); - } else { - TIMER_CTRL_2 ^= TIMER_CTRL_ENABLE; - } -} - -void -pause_playing(void) { - play_status ^= 1; - SOUND_SQUARE1_SWEEP = SOUND_SWEEP_DIR(1); - asm("nop"); asm("nop"); - asm("nop"); asm("nop"); - asm("nop"); asm("nop"); - asm("nop"); asm("nop"); - SOUND_SQUARE1_FREQ = SOUND_FREQ_RESET; - SOUND_SQUARE2_FREQ = SOUND_FREQ_RESET; - SOUND_WAVE_FREQ = SOUND_FREQ_RESET; - SOUND_NOISE_FREQ = SOUND_FREQ_RESET; - SOUND_SQUARE1_CTRL = 0; - SOUND_SQUARE2_CTRL = 0; - SOUND_WAVE_CTRL = 0; - SOUND_NOISE_CTRL = 0; - chain.playing = false; - if (current_pattern == next_pattern && chain.len > 0 && chain.enabled) { - chain.playing = true; - next_pattern = chain.chain[chain.current]; - current_pattern = next_pattern; - } - redraw_play_pause = true; - if (settings.sync == SYNC_IN_LINK) { - return; - } - if ((TIMER_CTRL_2 & TIMER_CTRL_ENABLE) == 0) { - if (current_pattern != next_pattern && step_counter == 0) { - current_pattern = next_pattern; - redraw_pattern_buttons = true; - } - if (settings.global_bpm) { - set_time(settings.bpm); - } else { - set_time(patterns[current_pattern].bpm); - } - play_step(); } else { - TIMER_CTRL_2 ^= TIMER_CTRL_ENABLE; + stop_sound(); } } @@ -769,7 +717,7 @@ handle_right_col_selection(void) { case R_COL_SETTINGS: { next_scene = SCENE_SETTINGS; } break; // case R_COL_SCALE: { stop_playing(); } break; // TODO: Should scale be toggleable? case R_COL_STOP: { stop_playing(); } break; - case R_COL_PLAY: { pause_playing(); } break; + case R_COL_PLAY: { toggle_playing(); } break; case R_COL_BANK_A: { if (play_status) { next_bank = 0; } else { select_bank(0); } redraw_bank_buttons = true; } break; case R_COL_BANK_B: { if (play_status) { next_bank = 1; } else { select_bank(1); } redraw_bank_buttons = true; } break; 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) { return; } // Stop the sequencer or start playing from the beginning. + reset_sequencer(); toggle_playing(); } else if (key_hold(KEY_SELECT)) { if (input_handler == handle_param_selection_sq1 || @@ -1561,6 +1510,7 @@ reset_serial_in(void) { void serial_irq(void) { if (play_status) { + // 12bpq -> 96bpq? sequencer_tick(); sequencer_tick(); sequencer_tick(); -- cgit v1.2.1