From 024e372b9e271ea817353f7d07a810b99c62eb60 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Thu, 4 Jan 2024 15:36:09 +0100 Subject: Add initial Analogue MIDI sync functionality (needs options) --- src/sequencer.c | 20 +++++++++++++++++--- src/settings.c | 2 ++ 2 files changed, 19 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/sequencer.c b/src/sequencer.c index 11c0f5a..9dcaa89 100644 --- a/src/sequencer.c +++ b/src/sequencer.c @@ -346,9 +346,9 @@ play_step(void) { step_counter = (step_counter + 1) % 16; } -static nseq_ticks = 0; void sequencer_tick(void) { + static int nseq_ticks = 0; if (nseq_ticks++ < 24) { return; } @@ -1549,10 +1549,24 @@ handle_sequencer_input(void) { } } +static int in_ticks = 0; + +void +reset_serial_in(void) { + in_ticks = 0; +} + void -serial_irq() { +serial_irq(void) { if (play_status) { - play_step(); + if (in_ticks++ == 0) { + // TODO: Instead of play_step use the nseq_ticks instead! + play_step(); + // MIDI: 24 / 8 = 3 + // set to 6 for half tempo + } else if (in_ticks == 3) { + in_ticks = 0; + } } } diff --git a/src/settings.c b/src/settings.c index 374618c..7cebcf6 100644 --- a/src/settings.c +++ b/src/settings.c @@ -8,6 +8,7 @@ static Settings settings = { }; static int settings_cursor_loc = 0; +void reset_serial_in(void); void serial_irq(void); void stop_sound(void); void toggle_playing(void); @@ -16,6 +17,7 @@ void set_audio_settings(void) { stop_sound(); if (settings.sync == SYNC_IN_LINK) { + reset_serial_in(); irs_set(IRQ_SERIAL, serial_irq); irs_set(IRQ_TIMER_2, NULL); SIO_MODE = SIO_MODE_GP -- cgit v1.2.1