Fix clock latency: process one USB packet per update() — no more batch-processing 0xF8 bursts

This commit is contained in:
ash
2026-07-03 07:19:05 +00:00
parent 72496d2daf
commit ea45c927e7
+5 -6
View File
@@ -50,7 +50,7 @@ void UsbMidiTransport::update() {
TinyUSBDevice.mounted() ? "YES" : "NO"); TinyUSBDevice.mounted() ? "YES" : "NO");
} }
while (usb_midi.available()) { if (usb_midi.available()) {
uint8_t packet[4]; uint8_t packet[4];
if (usb_midi.readPacket(packet)) { if (usb_midi.readPacket(packet)) {
uint8_t cin = packet[0] & 0x0F; uint8_t cin = packet[0] & 0x0F;
@@ -58,12 +58,10 @@ void UsbMidiTransport::update() {
if (packet[1] == 0xF8) { if (packet[1] == 0xF8) {
midi_tick_count++; midi_tick_count++;
} else if (packet[1] == 0xFA) { } else if (packet[1] == 0xFA) {
midi_tick_count = 0; midi_tick_count = 0xFFFFFFFF;
Serial.println("[CLK] START - reset tick to 0"); Serial.println("[CLK] START - next F8 = tick 0");
} }
continue; } else {
}
MidiEvent event; MidiEvent event;
parse_midi_packet(packet, 4, event); parse_midi_packet(packet, 4, event);
@@ -84,6 +82,7 @@ void UsbMidiTransport::update() {
} }
} }
} }
}
void UsbMidiTransport::on_midi_receive(std::function<void(const MidiEvent&)> callback) { void UsbMidiTransport::on_midi_receive(std::function<void(const MidiEvent&)> callback) {
receive_callback = callback; receive_callback = callback;