feat: implement MIDI clock transport control in process callback

Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
This commit is contained in:
Loic Coenen
2026-05-07 20:17:14 +00:00
parent 7014aa9e34
commit 2a630688e8

View File

@@ -63,7 +63,32 @@ static int process(jack_nframes_t nframes, void *arg)
} }
} }
// midi clock port is registered but not processed here // Process MIDI clock messages for transport control (start/stop)
void *midi_clock_buf = jack_port_get_buffer(midi_clock_port, nframes);
if (midi_clock_buf) {
jack_nframes_t n_clock_events = jack_midi_get_event_count(midi_clock_buf);
jack_midi_event_t cev;
for (jack_nframes_t j = 0; j < n_clock_events; j++) {
if (jack_midi_event_get(&cev, midi_clock_buf, j) == 0) {
if (cev.size >= 1) {
unsigned char msg = cev.buffer[0];
// real-time messages: Start (0xFA), Stop (0xFC), Continue (0xFB)
if (msg == 0xFA) { // Start transport -> begin recording if idle
if (current_state == STATE_IDLE) {
current_state = STATE_RECORD;
}
} else if (msg == 0xFC) { // Stop transport -> return to IDLE
current_state = STATE_IDLE;
} else if (msg == 0xFB) { // Continue transport -> resume looping (if paused)
if (current_state == STATE_PAUSED) {
current_state = STATE_LOOPING;
}
}
}
}
}
}
return 0; return 0;
} }