From fad07c17dede63b0c00544426562d11e73c7a22c Mon Sep 17 00:00:00 2001 From: Robert Hargreaves Date: Sun, 31 Mar 2024 21:45:28 +0100 Subject: [PATCH] Move MIDI PSG scheduler hook-up to `midi_psg` module init --- src/main.c | 1 - src/midi_psg.c | 3 +++ tests/system/test_e2e.c | 2 ++ tests/unit/test_midi.c | 4 ++++ tests/unit/test_midi_psg.c | 6 ++++++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index c36ba9c..a50d5a2 100644 --- a/src/main.c +++ b/src/main.c @@ -15,7 +15,6 @@ static void registerSchedulerHandlers() { - scheduler_addFrameHandler(midi_psg_tick); scheduler_addFrameHandler(ui_update); scheduler_addFrameHandler(everdrive_led_tick); scheduler_addFrameHandler(comm_megawifi_vsync); diff --git a/src/midi_psg.c b/src/midi_psg.c index 0af9d28..c795baa 100644 --- a/src/midi_psg.c +++ b/src/midi_psg.c @@ -4,6 +4,7 @@ #include "midi.h" #include "psg.h" #include "region.h" +#include "scheduler.h" #include #include #include @@ -70,6 +71,8 @@ static u16 effectiveTone(MidiPsgChannel* psgChan); void midi_psg_init(const u8** defaultEnvelopes) { + scheduler_addFrameHandler(midi_psg_tick); + userDefinedEnvelopePtr = NULL; envelopes = defaultEnvelopes; for (u8 chan = 0; chan < MAX_PSG_CHANS; chan++) { diff --git a/tests/system/test_e2e.c b/tests/system/test_e2e.c index ef4dd44..bd449cd 100644 --- a/tests/system/test_e2e.c +++ b/tests/system/test_e2e.c @@ -9,11 +9,13 @@ #include "midi_receiver.h" #include "presets.h" #include "wraps.h" +#include "scheduler.h" #include static int test_e2e_setup(void** state) { wraps_disable_checks(); + scheduler_init(); comm_reset_counts(); comm_init(); midi_init(M_BANK_0, P_BANK_0, ENVELOPES); diff --git a/tests/unit/test_midi.c b/tests/unit/test_midi.c index 5bf69a8..b63ba5a 100644 --- a/tests/unit/test_midi.c +++ b/tests/unit/test_midi.c @@ -62,6 +62,8 @@ static const u8* TEST_ENVELOPES[MIDI_PROGRAMS] = { ENVELOPE_0, ENVELOPE_1, int test_midi_setup(UNUSED void** state) { + expect_function_call(__wrap_scheduler_addFrameHandler); + P_BANK_0[30] = &P_BANK_0_INST_30_CASTANETS; expect_any(__wrap_synth_init, defaultPreset); wraps_disable_logging_checks(); @@ -154,5 +156,7 @@ void test_midi_hides_fm_parameter_ui(UNUSED void** state) void test_midi_reset_reinitialises_module(UNUSED void** state) { expect_any(__wrap_synth_init, defaultPreset); + expect_function_call(__wrap_scheduler_addFrameHandler); + __real_midi_reset(); } diff --git a/tests/unit/test_midi_psg.c b/tests/unit/test_midi_psg.c index 1deb5c7..f53de72 100644 --- a/tests/unit/test_midi_psg.c +++ b/tests/unit/test_midi_psg.c @@ -348,6 +348,8 @@ static void test_midi_shifts_semitone_in_psg_envelope(UNUSED void** state) const u8* envelopes[] = { envelope }; print_message("Shift: %d %d\n", i, envelopeStep); + + expect_function_call(__wrap_scheduler_addFrameHandler); midi_psg_init(envelopes); expect_psg_attenuation(expectedPsgChan, PSG_ATTENUATION_LOUDEST); @@ -371,6 +373,8 @@ static void test_midi_pitch_shift_handles_upper_limit_psg_envelope( const u16 expectedInitialTone = 8; const u8 envelope[] = { EEF_LOOP_START, 0x00, 0x10, EEF_END }; const u8* envelopes[] = { envelope }; + + expect_function_call(__wrap_scheduler_addFrameHandler); midi_psg_init(envelopes); expect_psg_tone(expectedPsgChan, expectedInitialTone); @@ -389,6 +393,8 @@ static void test_midi_pitch_shift_handles_lower_limit_psg_envelope( const u16 expectedInitialTone = TONE_NTSC_A2; const u8 envelope[] = { EEF_LOOP_START, 0x00, 0x80, EEF_END }; const u8* envelopes[] = { envelope }; + + expect_function_call(__wrap_scheduler_addFrameHandler); midi_psg_init(envelopes); expect_psg_tone(expectedPsgChan, expectedInitialTone);