fix: correct MIDI channel processing and port cleanup
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
This commit is contained in:
18
src/looper.c
18
src/looper.c
@@ -143,9 +143,17 @@ int process_callback(jack_nframes_t nframes, void *arg) {
|
||||
continue;
|
||||
|
||||
/* Guard against NULL ports (e.g. if port registration failed) */
|
||||
if (!active_channels[c].audio_in || !active_channels[c].audio_out) {
|
||||
fprintf(stderr, "WARN: channel %d has NULL audio port(s), skipping\n", c);
|
||||
continue;
|
||||
if (active_channels[c].type == CHANNEL_AUDIO) {
|
||||
if (!active_channels[c].audio_in || !active_channels[c].audio_out) {
|
||||
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 =
|
||||
@@ -507,6 +515,10 @@ void looper_process_commands(jack_client_t *client) {
|
||||
jack_port_unregister(client, cur[idx].audio_in);
|
||||
if (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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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};
|
||||
queue_push(&cmd_queue, cmd);
|
||||
} break;
|
||||
case 66: {
|
||||
command_t cmd = {.type = CMD_ADD_MIDI_CHANNEL, .channel = -1, .data = 0};
|
||||
queue_push(&cmd_queue_main_midi, cmd);
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user