fix: correct MIDI channel processing and port cleanup

Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
This commit is contained in:
Loic Coenen
2026-05-10 11:37:04 +00:00
parent ff226a8ea6
commit df181b117e
2 changed files with 19 additions and 3 deletions

View File

@@ -143,9 +143,17 @@ int process_callback(jack_nframes_t nframes, void *arg) {
continue; continue;
/* Guard against NULL ports (e.g. if port registration failed) */ /* Guard against NULL ports (e.g. if port registration failed) */
if (!active_channels[c].audio_in || !active_channels[c].audio_out) { if (active_channels[c].type == CHANNEL_AUDIO) {
fprintf(stderr, "WARN: channel %d has NULL audio port(s), skipping\n", c); if (!active_channels[c].audio_in || !active_channels[c].audio_out) {
continue; fprintf(stderr, "WARN: channel %d has NULL audio port(s), skipping\n", c);
continue;
}
} else {
/* CHANNEL_MIDI */
if (!active_channels[c].midi_in || !active_channels[c].midi_out) {
fprintf(stderr, "WARN: channel %d has NULL MIDI port(s), skipping\n", c);
continue;
}
} }
const jack_default_audio_sample_t *in = const jack_default_audio_sample_t *in =
@@ -507,6 +515,10 @@ void looper_process_commands(jack_client_t *client) {
jack_port_unregister(client, cur[idx].audio_in); jack_port_unregister(client, cur[idx].audio_in);
if (cur[idx].audio_out) if (cur[idx].audio_out)
jack_port_unregister(client, cur[idx].audio_out); jack_port_unregister(client, cur[idx].audio_out);
if (cur[idx].midi_in)
jack_port_unregister(client, cur[idx].midi_in);
if (cur[idx].midi_out)
jack_port_unregister(client, cur[idx].midi_out);
pending_unregister_idx = -1; pending_unregister_idx = -1;
} }
} }

View File

@@ -66,6 +66,10 @@ void midi_handle_events(void *port_buffer, jack_nframes_t nframes) {
command_t cmd = {.type = CMD_STOP, .channel = -1, .data = 0}; command_t cmd = {.type = CMD_STOP, .channel = -1, .data = 0};
queue_push(&cmd_queue, cmd); queue_push(&cmd_queue, cmd);
} break; } break;
case 66: {
command_t cmd = {.type = CMD_ADD_MIDI_CHANNEL, .channel = -1, .data = 0};
queue_push(&cmd_queue_main_midi, cmd);
} break;
default: default:
break; break;
} }