diff --git a/src/application/system/System.cpp b/src/application/system/System.cpp index d2acb88cc..280ed7a3f 100644 --- a/src/application/system/System.cpp +++ b/src/application/system/System.cpp @@ -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); diff --git a/tests/src/system/test.cpp b/tests/src/system/test.cpp index 21ae81c55..3831d7a9d 100644 --- a/tests/src/system/test.cpp +++ b/tests/src/system/test.cpp @@ -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 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(IO::LEDs::controlType_t::pcSingleVal), generatedSysExReq); + + sendAndVerifySysExRequest(generatedSysExReq, + { 0xF0, + 0x00, + 0x53, + 0x43, + 0x01, + 0x00, + 0x01, // set + 0x00, // single + static_cast(System::block_t::leds), + static_cast(System::Section::leds_t::controlType), + 0x00, // LED 0 + 0x00, + 0x00, + static_cast(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(System::block_t::leds), + static_cast(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(System::block_t::leds), + static_cast(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 \ No newline at end of file