#include "led_stub.h" #include "pixel_stomp_mux.h" #include static PixelStompMux* mux_ptr = nullptr; // Launchpad colour palette - velocity 0-127 maps to specific colours // Key breakpoints: 0=Off, 5=Red, 13=Orange, 21=Yellow, 37=Green, 45=Cyan, 53=Blue, 81=Purple // Values between are linear RGB gradients; 82-127 fade purple to black static const uint32_t launchpad_palette[128] = { 0x000000, // 0: Off 0x330000, // 1 0x660000, // 2 0x990000, // 3 0xCC0000, // 4 0xFF0000, // 5: Red 0xFF1500, // 6 0xFF2A00, // 7 0xFF4000, // 8 0xFF5500, // 9 0xFF6A00, // 10 0xFF8000, // 11 0xFF9500, // 12 0xFFAA00, // 13: Orange 0xFFB500, // 14 0xFFC000, // 15 0xFFCB00, // 16 0xFFD600, // 17 0xFFE100, // 18 0xFFEC00, // 19 0xFFF700, // 20 0xFFFF00, // 21: Yellow 0xEFFF00, // 22 0xDFFF00, // 23 0xCFFF00, // 24 0xBFFF00, // 25 0xAFFF00, // 26 0x9FFF00, // 27 0x8FFF00, // 28 0x7FFF00, // 29 0x6FFF00, // 30 0x5FFF00, // 31 0x4FFF00, // 32 0x3FFF00, // 33 0x2FFF00, // 34 0x1FFF00, // 35 0x0FFF00, // 36 0x00FF00, // 37: Green 0x00FF20, // 38 0x00FF40, // 39 0x00FF60, // 40 0x00FF80, // 41 0x00FF9F, // 42 0x00FFBF, // 43 0x00FFDF, // 44 0x00FFFF, // 45: Cyan 0x00DFFF, // 46 0x00BFFF, // 47 0x009FFF, // 48 0x007FFF, // 49 0x005FFF, // 50 0x003FFF, // 51 0x001FFF, // 52 0x0000FF, // 53: Blue 0x0500FF, // 54 0x0B00FF, // 55 0x1000FF, // 56 0x1600FF, // 57 0x1B00FF, // 58 0x2100FF, // 59 0x2600FF, // 60 0x2B00FF, // 61 0x3100FF, // 62 0x3600FF, // 63 0x3C00FF, // 64 0x4100FF, // 65 0x4600FF, // 66 0x4C00FF, // 67 0x5100FF, // 68 0x5700FF, // 69 0x5C00FF, // 70 0x6200FF, // 71 0x6700FF, // 72 0x6D00FF, // 73 0x7200FF, // 74 0x7700FF, // 75 0x7D00FF, // 76 0x8200FF, // 77 0x8800FF, // 78 0x8D00FF, // 79 0x9300FF, // 80 0x9900FF, // 81: Purple 0x9600F9, // 82 0x9300F4, // 83 0x8F00EE, // 84 0x8C00E8, // 85 0x8900E3, // 86 0x8500DD, // 87 0x8200D8, // 88 0x7F00D2, // 89 0x7B00CC, // 90 0x7800C7, // 91 0x7500C1, // 92 0x7100BC, // 93 0x6E00B6, // 94 0x6B00B0, // 95 0x6700AB, // 96 0x6400A5, // 97 0x61009F, // 98 0x5D009A, // 99 0x5A0094, // 100 0x57008E, // 101 0x530089, // 102 0x500083, // 103 0x4D007D, // 104 0x490078, // 105 0x460072, // 106 0x43006D, // 107 0x3F0067, // 108 0x3C0061, // 109 0x39005C, // 110 0x350056, // 111 0x320050, // 112 0x2F004B, // 113 0x2B0045, // 114 0x280040, // 115 0x25003A, // 116 0x210034, // 117 0x1E002F, // 118 0x1B0029, // 119 0x170023, // 120 0x190033, // 121: dark purple-red (was near-black) 0x3D0047, // 122: medium purple-red 0x61005C, // 123: bright purple 0x850070, // 124: brighter purple 0x9900CC, // 125: bright magenta 0xCC00FF, // 126: full magenta 0xFF00FF, // 127: full magenta (Maximum velocity = visible) }; static uint32_t velocity_to_color(uint8_t velocity) { return launchpad_palette[velocity]; } static const uint32_t pad_base_colors[10] = { 0x0000FF, // 0: Blue 0x0000FF, // 1: Blue 0xFF6600, // 2: Orange 0xFF6600, // 3: Orange 0xFF6600, // 4: Orange 0xFF0000, // 5: Red 0xFFFFFF, // 6: White 0xFFBF00, // 7: Amber 0x9900FF, // 8: Purple 0x9900FF, // 9: Purple }; static void apply_pad_color(uint8_t index, uint8_t velocity) { if (index >= 10) return; uint32_t base = pad_base_colors[index]; uint8_t r = (base >> 16) & 0xFF; uint8_t g = (base >> 8) & 0xFF; uint8_t b = base & 0xFF; if (velocity == 0) { r = (uint16_t)r * 20 / 255; g = (uint16_t)g * 20 / 255; b = (uint16_t)b * 20 / 255; } mux_ptr->set_led_color(index, r, g, b); } DefaultLedStub::DefaultLedStub() : initialized(false) { for (int i = 0; i < NUM_LEDS; i++) { led_states[i].active = false; led_states[i].velocity = 0; led_states[i].note = 0; led_states[i].channel = 0; led_states[i].timestamp = 0; } } void DefaultLedStub::set_mux(PixelStompMux* mux) { mux_ptr = mux; } void DefaultLedStub::begin() { Serial.println("[LED] Using WS2812C via PixelStomp MUX (FastLED)"); initialized = true; if (!mux_ptr) { Serial.println("[LED] ERROR: No MUX configured"); return; } Serial.println("[LED] Launchpad-style startup animation (paired)..."); // Sweep each pixel-pair through palette, then off for (int pair = 0; pair < 5; pair++) { int i1 = pair * 2; int i2 = pair * 2 + 1; for (int c = 1; c <= 127; c += 8) { uint32_t color = launchpad_palette[c]; uint8_t r = (color >> 16) & 0xFF; uint8_t g = (color >> 8) & 0xFF; uint8_t b = color & 0xFF; mux_ptr->set_led_color(i1, r, g, b); mux_ptr->set_led_color(i2, r, g, b); mux_ptr->show(); delay(15); } // Turn off this pair before moving to next mux_ptr->set_led_color(i1, 0, 0, 0); mux_ptr->set_led_color(i2, 0, 0, 0); mux_ptr->show(); } // Final: all LEDs pulse through palette once together for (int c = 1; c <= 127; c += 4) { uint32_t color = launchpad_palette[c]; uint8_t r = (color >> 16) & 0xFF; uint8_t g = (color >> 8) & 0xFF; uint8_t b = color & 0xFF; for (int i = 0; i < NUM_LEDS; i++) { mux_ptr->set_led_color(i, r, g, b); } mux_ptr->show(); delay(12); } clear_all(); Serial.println("[LED] Startup complete"); } 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 / pad colors) 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(); apply_pad_color(led_index, velocity); 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; led_states[i].velocity = velocity; led_states[i].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(i, r, g, b); mux_ptr->show(); Serial.printf("[LED] Updated LED %d: note=%d ch=%d vel=%d\n", i, note, channel, velocity); return; } } for (int i = 0; i < NUM_LEDS; i++) { if (!led_states[i].active) { led_states[i].active = true; led_states[i].note = note; led_states[i].channel = channel; led_states[i].velocity = velocity; led_states[i].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(i, r, g, b); mux_ptr->show(); Serial.printf("[LED] Activated LED %d: note=%d ch=%d vel=%d\n", i, note, channel, velocity); return; } } } void DefaultLedStub::clear_all() { if (!initialized || !mux_ptr) return; for (int i = 0; i < NUM_LEDS; i++) { led_states[i].active = false; led_states[i].velocity = 0; led_states[i].note = 0; led_states[i].channel = 0; led_states[i].timestamp = 0; apply_pad_color(i, 0); } mux_ptr->show(); Serial.println("[LED] All cleared"); } void DefaultLedStub::set_led_brightness(uint8_t brightness) { if (!initialized || !mux_ptr) return; mux_ptr->set_led_brightness(brightness); mux_ptr->show(); } void DefaultLedStub::flash_activity() { // No-op: activity flash on all MIDI input was confusing. // LED feedback is handled directly by set_led_state(). } void DefaultLedStub::update() { if (!initialized || !mux_ptr) return; uint32_t now = millis(); // Turn off activity flash if (activity_off_time > 0 && now >= activity_off_time) { mux_ptr->set_led_color(0, saved_r, saved_g, saved_b); mux_ptr->show(); activity_off_time = 0; } }