feat: auto-reconnect midi
Clang Lint CI / lint-no-video (push) Successful in 59s
Clang Build CI / run-no-video (push) Successful in 59s
Clang Build CI / run-video (push) Successful in 59s
Clang Build CI / build-release (push) Successful in 1m31s
Clang Lint CI / lint-video (push) Successful in 1m7s
Clang Lint CI / lint-no-video (push) Successful in 59s
Clang Build CI / run-no-video (push) Successful in 59s
Clang Build CI / run-video (push) Successful in 59s
Clang Build CI / build-release (push) Successful in 1m31s
Clang Lint CI / lint-video (push) Successful in 1m7s
This commit is contained in:
+34
-9
@@ -181,12 +181,12 @@ static void key_callback(Window *window, int key,
|
||||
log_info("[ESC] Closing...");
|
||||
window_close(window);
|
||||
} else if (event > 0) {
|
||||
state_key_event(&context, project.state_config, event, &midi);
|
||||
state_key_event(&context, project.state_config, event, midi);
|
||||
}
|
||||
}
|
||||
|
||||
static void midi_callback(unsigned char code, unsigned char value) {
|
||||
state_midi_event(&context, project.state_config, &midi, code, value,
|
||||
state_midi_event(&context, project.state_config, midi, code, value,
|
||||
init_params.trace_midi);
|
||||
}
|
||||
|
||||
@@ -214,6 +214,35 @@ static void start_midi_background_listen() {
|
||||
pthread_detach(thread);
|
||||
}
|
||||
|
||||
static void *background_reconnect_midi(__attribute__((unused)) void *args) {
|
||||
log_info("background midi reconnect started");
|
||||
while (!context.stop) {
|
||||
sleep(1);
|
||||
if (!midi.connected) {
|
||||
midi_open(&midi, config_file_get_str(&project.config, "MIDI_HW", "hw"));
|
||||
if (midi.connected) {
|
||||
start_midi_background_listen();
|
||||
}
|
||||
}
|
||||
}
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
static void init_midi() {
|
||||
pthread_t thread;
|
||||
|
||||
midi_open(&midi, config_file_get_str(&project.config, "MIDI_HW", "hw"));
|
||||
|
||||
if (midi.connected) {
|
||||
start_midi_background_listen();
|
||||
}
|
||||
|
||||
if (init_params.midi_reconnect) {
|
||||
pthread_create(&thread, NULL, background_reconnect_midi, NULL);
|
||||
pthread_detach(thread);
|
||||
}
|
||||
}
|
||||
|
||||
static bool init(const Parameters *params) {
|
||||
init_params = *params;
|
||||
|
||||
@@ -231,13 +260,7 @@ static bool init(const Parameters *params) {
|
||||
start_video_captures();
|
||||
#endif /* VIDEO_IN */
|
||||
|
||||
midi_open(&midi, config_file_get_str(&project.config, "MIDI_HW", "hw"));
|
||||
|
||||
if (midi.error) {
|
||||
context.demo = true;
|
||||
} else {
|
||||
start_midi_background_listen();
|
||||
}
|
||||
init_midi();
|
||||
|
||||
start_state_background_write();
|
||||
|
||||
@@ -357,6 +380,8 @@ static void shutdown() {
|
||||
free_video_captures();
|
||||
#endif /* VIDEO_IN */
|
||||
|
||||
midi_close(&midi);
|
||||
|
||||
project_free(&project);
|
||||
|
||||
window_terminate();
|
||||
|
||||
Reference in New Issue
Block a user