Fix pixel 6 beat timing: align with actual MIDI beats using tick-based counting (24 ticks per beat)
This commit is contained in:
+33
-14
@@ -26,10 +26,8 @@ TaskHandle_t midi_task_handle = NULL;
|
||||
void midi_task(void* parameter) {
|
||||
Serial.println("[TASK] MIDI task started on core 0");
|
||||
|
||||
// Beat timing fixes for precise beat alignment
|
||||
const uint32_t BEAT_MS = 500; // 120 BPM target (500ms per beat)
|
||||
uint32_t last_beat_time = 0;
|
||||
uint32_t current_real_beat = 0;
|
||||
// Beat timing fixes for precise beat alignment - sync to real MIDI time, not hardcoded tempo
|
||||
uint32_t last_beat = 0;
|
||||
uint32_t flash_start = 0;
|
||||
|
||||
while (true) {
|
||||
@@ -39,19 +37,15 @@ void midi_task(void* parameter) {
|
||||
uint32_t tick = midi_tick_count;
|
||||
uint32_t now = millis();
|
||||
|
||||
// Precise beat detection: calculate which real-time beat we're on
|
||||
uint32_t real_beat = now / BEAT_MS;
|
||||
// Calculate beat using MIDI tick count (24 ticks per beat/PPQN)
|
||||
uint32_t current_beat = tick / 24;
|
||||
|
||||
// Check if we've crossed a real-time beat boundary
|
||||
if (real_beat != current_real_beat) {
|
||||
// Track the current real-time beat
|
||||
current_real_beat = real_beat;
|
||||
last_beat_time = now;
|
||||
|
||||
// Flash pixel 6 on the precise real-time beat
|
||||
// Check if we've crossed a beat boundary
|
||||
if (current_beat != last_beat) {
|
||||
last_beat = current_beat;
|
||||
flash_start = now;
|
||||
mux.set_led_color(6, 255, 255, 255);
|
||||
mux.show();
|
||||
flash_start = now;
|
||||
}
|
||||
|
||||
// Handle flash animation
|
||||
@@ -72,6 +66,31 @@ void midi_task(void* parameter) {
|
||||
vTaskDelay(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle flash animation
|
||||
if (flash_start > 0) {
|
||||
uint32_t elapsed = now - flash_start;
|
||||
if (elapsed >= 80) {
|
||||
mux.set_led_color(6, 20, 20, 20);
|
||||
mux.show();
|
||||
flash_start = 0;
|
||||
} else {
|
||||
float b = 1.0f - (float)elapsed / 80.0f;
|
||||
uint8_t v = (uint8_t)(255 * b * b);
|
||||
mux.set_led_color(6, v, v, v);
|
||||
mux.show();
|
||||
}
|
||||
}
|
||||
|
||||
// Update last_clock_time at the end of MIDI update
|
||||
// (checks happen during midi_transport.update())
|
||||
|
||||
vTaskDelay(1);
|
||||
}
|
||||
}
|
||||
|
||||
void sync_main.cpp():miditempfix() {
|
||||
|
||||
void handle_serial_command(const String& cmd) {
|
||||
if (cmd == "dump" || cmd == "d") {
|
||||
|
||||
Reference in New Issue
Block a user