From a4131adf2a1bd11c2d47da4ef1a1461ab907059b Mon Sep 17 00:00:00 2001 From: Ashley Strahle Date: Tue, 30 Jun 2026 04:04:37 +0000 Subject: [PATCH] Fix CC feedback: route to correct pixel by LED index --- include/led_stub.h | 4 ++-- src/app_task.cpp | 3 ++- src/led_stub.cpp | 20 +++++++++++++++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/include/led_stub.h b/include/led_stub.h index 5537f37..c44274a 100644 --- a/include/led_stub.h +++ b/include/led_stub.h @@ -7,7 +7,7 @@ public: virtual ~LedStub() {} virtual void begin() = 0; - virtual void set_led_state(uint8_t note, uint8_t channel, uint8_t velocity) = 0; + virtual void set_led_state(uint8_t note, uint8_t channel, uint8_t velocity, int8_t led_index = -1) = 0; virtual void clear_all() = 0; virtual void set_led_brightness(uint8_t brightness) = 0; virtual void flash_activity() {} @@ -39,7 +39,7 @@ private: public: DefaultLedStub(); void begin() override; - void set_led_state(uint8_t note, uint8_t channel, uint8_t velocity) override; + void set_led_state(uint8_t note, uint8_t channel, uint8_t velocity, int8_t led_index = -1) override; void clear_all() override; void set_led_brightness(uint8_t brightness) override; void flash_activity() override; diff --git a/src/app_task.cpp b/src/app_task.cpp index dacab2d..63023ca 100644 --- a/src/app_task.cpp +++ b/src/app_task.cpp @@ -112,7 +112,8 @@ void AppTask::process_midi_event(const MidiEvent& event) { led_driver->set_led_state( pad_mapping[led_index].midi_note, pad_mapping[led_index].midi_channel, - cc_val + cc_val, + led_index ); Serial.printf("[APP] CC -> LED: Ch%d CC%d Val%d -> LED%d\n", midi_channel, cc_num, cc_val, led_index); diff --git a/src/led_stub.cpp b/src/led_stub.cpp index 8e4b3fb..78ee743 100644 --- a/src/led_stub.cpp +++ b/src/led_stub.cpp @@ -200,9 +200,27 @@ void DefaultLedStub::begin() { Serial.println("[LED] Startup complete"); } -void DefaultLedStub::set_led_state(uint8_t note, uint8_t channel, uint8_t velocity) { +void DefaultLedStub::set_led_state(uint8_t note, uint8_t channel, uint8_t velocity, int8_t led_index) { if (!initialized || !mux_ptr) return; + // Direct index mode (used by CC feedback) + if (led_index >= 0 && led_index < NUM_LEDS) { + led_states[led_index].active = (velocity > 0); + led_states[led_index].note = note; + led_states[led_index].channel = channel; + led_states[led_index].velocity = velocity; + led_states[led_index].timestamp = millis(); + uint32_t color = velocity_to_color(velocity); + uint8_t r = (color >> 16) & 0xFF; + uint8_t g = (color >> 8) & 0xFF; + uint8_t b = color & 0xFF; + mux_ptr->set_led_color(led_index, r, g, b); + mux_ptr->show(); + Serial.printf("[LED] Set LED %d: note=%d ch=%d vel=%d\n", led_index, note, channel, velocity); + return; + } + + // Note-match mode (used by NOTE_ON/OFF) for (int i = 0; i < NUM_LEDS; i++) { if (led_states[i].active && led_states[i].note == note) { led_states[i].channel = channel;