Replace MIDI clock with internal BPM timer for pixel 6 pulse

Revert:
- Remove midi_clock.h/cpp (was causing cross-core crash)
- Remove real-time MIDI message parsing from midi_transport.cpp

New approach:
- Pixel 6 (and all active LEDs) pulse to internal BPM timer
- Default 120 BPM (500ms beat interval)
- 'bpm <n>' serial command to change tempo (20-300)
- Only calls FastLED.show() when actively pulsing (avoids USB/WS2812 interference)
- 33ms update rate (30fps)
- Inactive LEDs left untouched (no unnecessary show() calls)
This commit is contained in:
ash
2026-07-02 07:27:26 +00:00
parent 5dc10eea87
commit af14c2f759
6 changed files with 31 additions and 97 deletions
+18 -12
View File
@@ -1,7 +1,7 @@
#include "led_stub.h"
#include "pixel_stomp_mux.h"
#include "midi_clock.h"
#include <Arduino.h>
#include <math.h>
static PixelStompMux* mux_ptr = nullptr;
@@ -300,40 +300,46 @@ void DefaultLedStub::flash_activity() {
// LED feedback is handled directly by set_led_state().
}
void DefaultLedStub::set_bpm(uint16_t bpm) {
if (bpm == 0) bpm = 120;
beat_interval_ms = 60000 / bpm;
Serial.printf("[LED] Pulse BPM set to %d (%dms)\n", bpm, beat_interval_ms);
}
void DefaultLedStub::update() {
if (!initialized || !mux_ptr) return;
uint32_t now = millis();
static uint32_t last_pulse_update = 0;
if (now - last_pulse_update < 20) return;
if (now - last_pulse_update < 33) return;
last_pulse_update = now;
bool clock_running = MidiClock::is_running();
float pulse = 1.0f;
if (clock_running) {
pulse = MidiClock::get_pulse();
}
float phase = (now % beat_interval_ms) / (float)beat_interval_ms;
float pulse = sinf(M_PI * phase);
bool active = false;
for (int i = 0; i < NUM_LEDS; i++) {
if (led_states[i].active) {
float brightness = clock_running ? (0.5f + 0.5f * pulse) : 1.0f;
active = true;
float brightness = 0.5f + 0.5f * pulse;
uint32_t base = pad_base_colors[i];
uint8_t r = (uint8_t)(((base >> 16) & 0xFF) * brightness);
uint8_t g = (uint8_t)(((base >> 8) & 0xFF) * brightness);
uint8_t b = (uint8_t)((base & 0xFF) * brightness);
mux_ptr->set_led_color(i, r, g, b);
} else if (clock_running && i == 6) {
} else if (i == 6) {
active = true;
float brightness = 0.3f + 0.7f * pulse;
uint32_t base = pad_base_colors[6];
uint8_t r = (uint8_t)(((base >> 16) & 0xFF) * brightness);
uint8_t g = (uint8_t)(((base >> 8) & 0xFF) * brightness);
uint8_t b = (uint8_t)((base & 0xFF) * brightness);
mux_ptr->set_led_color(6, r, g, b);
} else {
apply_pad_color(i, 0);
}
}
mux_ptr->show();
if (active) {
mux_ptr->show();
}
}