Fix MIDI clock phase: handle 0xFA START to reset tick counter to downbeat
This commit is contained in:
+3
-2
@@ -27,7 +27,7 @@ void midi_task(void* parameter) {
|
||||
Serial.println("[TASK] MIDI task started on core 0");
|
||||
|
||||
// Beat timing fixes for precise beat alignment - sync to real MIDI time, not hardcoded tempo
|
||||
uint32_t last_beat = 0;
|
||||
uint32_t last_beat = UINT32_MAX;
|
||||
uint32_t flash_start = 0;
|
||||
|
||||
while (true) {
|
||||
@@ -40,7 +40,8 @@ void midi_task(void* parameter) {
|
||||
// Calculate beat using MIDI tick count (24 ticks per beat/PPQN)
|
||||
uint32_t current_beat = tick / 24;
|
||||
|
||||
// Check if we've crossed a beat boundary
|
||||
// Check if we've crossed a beat boundary.
|
||||
// last_beat starts as UINT32_MAX so tick 0 (START) always triggers
|
||||
if (current_beat != last_beat) {
|
||||
last_beat = current_beat;
|
||||
flash_start = now;
|
||||
|
||||
@@ -54,8 +54,13 @@ void UsbMidiTransport::update() {
|
||||
uint8_t packet[4];
|
||||
if (usb_midi.readPacket(packet)) {
|
||||
uint8_t cin = packet[0] & 0x0F;
|
||||
if (cin == 0x0F && packet[1] == 0xF8) {
|
||||
midi_tick_count++;
|
||||
if (cin == 0x0F) {
|
||||
if (packet[1] == 0xF8) {
|
||||
midi_tick_count++;
|
||||
} else if (packet[1] == 0xFA) {
|
||||
midi_tick_count = 0;
|
||||
Serial.println("[CLK] START - reset tick to 0");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user