Skip to content

Commit

Permalink
Move MIDI PSG scheduler hook-up to midi_psg module init
Browse files Browse the repository at this point in the history
  • Loading branch information
rhargreaves committed Mar 31, 2024
1 parent 218b6d5 commit fad07c1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/midi_psg.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "midi.h"
#include "psg.h"
#include "region.h"
#include "scheduler.h"
#include <memory.h>
#include <psg.h>
#include <stdbool.h>
Expand Down Expand Up @@ -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++) {
Expand Down
2 changes: 2 additions & 0 deletions tests/system/test_e2e.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
#include "midi_receiver.h"
#include "presets.h"
#include "wraps.h"
#include "scheduler.h"
#include <cmocka.h>

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);
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/test_midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
6 changes: 6 additions & 0 deletions tests/unit/test_midi_psg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit fad07c1

Please sign in to comment.