Skip to content

Commit

Permalink
system: restore the ability to indicate current MIDI program on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
paradajz committed Nov 5, 2021
1 parent 5822d88 commit 0e741eb
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/application/system/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,24 @@ bool System::init()
_touchscreen.init(IO::Touchscreen::mode_t::normal);
_leds.init();

// on startup, indicate current program for all channels (if any leds have program change assigned as control mode)
for (int i = 0; i < 16; i++)
{
Util::MessageDispatcher::message_t dispatchMessage;

dispatchMessage.componentIndex = 0;
dispatchMessage.midiChannel = i;
dispatchMessage.midiIndex = IO::Common::program(i);
dispatchMessage.midiValue = 0;
dispatchMessage.message = MIDI::messageType_t::programChange;

// pretend this midi in message - source isn't important here as
// both midi in and local control for program change are synced
_dispatcher.notify(Util::MessageDispatcher::messageSource_t::midiIn,
dispatchMessage,
Util::MessageDispatcher::listenType_t::nonFwd);
}

_sysExConf.setLayout(sysExLayout);
_sysExConf.setupCustomRequests(customRequests);

Expand Down
111 changes: 111 additions & 0 deletions tests/src/system/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,117 @@ TEST_CASE(PresetChangeIndicatedOnLEDs)
0x01, // LED state - on
0xF7 });
}

TEST_CASE(ProgramIndicatedOnStartup)
{
_database.factoryReset();
TEST_ASSERT(systemStub.init() == true);

// handshake
sendAndVerifySysExRequest({ 0xF0,
0x00,
0x53,
0x43,
0x00,
0x00,
0x01,
0xF7 },
{ 0xF0,
0x00,
0x53,
0x43,
0x01,
0x00,
0x01,
0xF7 });

std::vector<uint8_t> generatedSysExReq;

// configure the first LED to indicate program change
// its activation ID is 0 so it should be on only for program 0
MIDIHelper::generateSysExSetReq(System::Section::leds_t::controlType, 0, static_cast<size_t>(IO::LEDs::controlType_t::pcSingleVal), generatedSysExReq);

sendAndVerifySysExRequest(generatedSysExReq,
{ 0xF0,
0x00,
0x53,
0x43,
0x01,
0x00,
0x01, // set
0x00, // single
static_cast<uint8_t>(System::block_t::leds),
static_cast<uint8_t>(System::Section::leds_t::controlType),
0x00, // LED 0
0x00,
0x00,
static_cast<uint8_t>(IO::LEDs::controlType_t::pcSingleVal),
0xF7 });

// led should be off for now
MIDIHelper::generateSysExGetReq(System::Section::leds_t::testColor, 0, generatedSysExReq);

sendAndVerifySysExRequest(generatedSysExReq,
{ 0xF0,
0x00,
0x53,
0x43,
0x01,
0x00,
0x00, // get
0x00, // single
static_cast<uint8_t>(System::block_t::leds),
static_cast<uint8_t>(System::Section::leds_t::testColor),
0x00, // LED 0
0x00,
0x00, // new value / blank
0x00, // new value / blank
0x00,
0x00, // LED state - off
0xF7 });

TEST_ASSERT(systemStub.init() == true);

// handshake
sendAndVerifySysExRequest({ 0xF0,
0x00,
0x53,
0x43,
0x00,
0x00,
0x01,
0xF7 },
{ 0xF0,
0x00,
0x53,
0x43,
0x01,
0x00,
0x01,
0xF7 });

// verify that the led is turned on on startup since initially, program for all channels is 0
MIDIHelper::generateSysExGetReq(System::Section::leds_t::testColor, 0, generatedSysExReq);

sendAndVerifySysExRequest(generatedSysExReq,
{ 0xF0,
0x00,
0x53,
0x43,
0x01,
0x00,
0x00, // get
0x00, // single
static_cast<uint8_t>(System::block_t::leds),
static_cast<uint8_t>(System::Section::leds_t::testColor),
0x00, // LED 0
0x00,
0x00, // new value / blank
0x00, // new value / blank
0x00,
0x01, // LED state - on
0xF7 });
}
#endif

#endif

0 comments on commit 0e741eb

Please sign in to comment.