refactor: extract JACK MIDI client reconnection logic
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
This commit is contained in:
@@ -252,35 +252,9 @@ static jack_client_t *midi_persistent_client = NULL;
|
|||||||
static jack_port_t *midi_persistent_port = NULL;
|
static jack_port_t *midi_persistent_port = NULL;
|
||||||
|
|
||||||
static int send_jack_note_on(const char *target_port, unsigned char note, unsigned char velocity) {
|
static int send_jack_note_on(const char *target_port, unsigned char note, unsigned char velocity) {
|
||||||
/* create persistent client on first call */
|
midi_inject_reconnect(target_port);
|
||||||
if (!midi_persistent_client) {
|
if (!midi_inject_client || !midi_inject_port) return -1;
|
||||||
jack_status_t st;
|
|
||||||
midi_persistent_client = jack_client_open("midi_inject_persistent", JackNoStartServer, &st);
|
|
||||||
if (!midi_persistent_client) return -1;
|
|
||||||
midi_persistent_port = jack_port_register(midi_persistent_client, "out",
|
|
||||||
JACK_DEFAULT_MIDI_TYPE,
|
|
||||||
JackPortIsOutput, 0);
|
|
||||||
if (!midi_persistent_port) {
|
|
||||||
jack_client_close(midi_persistent_client);
|
|
||||||
midi_persistent_client = NULL;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
char src[64];
|
|
||||||
snprintf(src, sizeof(src), "midi_inject_persistent:out");
|
|
||||||
if (jack_connect(midi_persistent_client, src, target_port) != 0) {
|
|
||||||
jack_client_close(midi_persistent_client);
|
|
||||||
midi_persistent_client = NULL;
|
|
||||||
midi_persistent_port = NULL;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
jack_set_process_callback(midi_persistent_client, midi_inject_process, NULL);
|
|
||||||
if (jack_activate(midi_persistent_client) != 0) {
|
|
||||||
jack_client_close(midi_persistent_client);
|
|
||||||
midi_persistent_client = NULL;
|
|
||||||
midi_persistent_port = NULL;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
midi_inject_note = note;
|
midi_inject_note = note;
|
||||||
midi_inject_velocity = velocity;
|
midi_inject_velocity = velocity;
|
||||||
midi_inject_pending = 1;
|
midi_inject_pending = 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user