diff --git a/src/forge.c b/src/forge.c index 229a611..1633c8b 100644 --- a/src/forge.c +++ b/src/forge.c @@ -166,14 +166,16 @@ static void init_inputs(char *video_in[MAX_VIDEO], unsigned int input_count, } } -static void start_video_captures(unsigned int video_count) { +static bool start_video_captures(unsigned int video_count) { unsigned int i; for (i = 0; i < video_count; i++) { - if (!inputs[i].error) { - video_background_read(&inputs[i], context, i); + if (!inputs[i].error && !video_background_read(&inputs[i], context, i)) { + return false; } } + + return true; } static void free_video_captures(unsigned int video_count) { @@ -253,14 +255,18 @@ void forge_run(Parameters params) { init_inputs(params.video_in, params.video_in_count, params.video_size); - start_video_captures(params.video_in_count); + if (!start_video_captures(params.video_in_count)) { + return; + } midi = midi_open(config_file_get_str(config, "MIDI_HW", "hw")); if (midi.error) { params.demo = true; } else { - midi_background_listen(midi, context); + if (!midi_background_listen(midi, context)) { + return; + } } window_startup(error_callback); @@ -311,8 +317,6 @@ void forge_run(Parameters params) { context->stop = true; - wait(NULL); - shaders_free(program); if (window_output != NULL) { @@ -329,8 +333,6 @@ void forge_run(Parameters params) { free_video_captures(params.video_in_count); - midi_close(midi); - free_context(); free_files(frag_count); diff --git a/src/midi.c b/src/midi.c index 00a80d4..dd613ee 100644 --- a/src/midi.c +++ b/src/midi.c @@ -4,15 +4,6 @@ #include "log.h" #include "types.h" -void midi_close(MidiDevice device) { - if (device.input != NULL) { - snd_rawmidi_close(device.input); - } - if (device.output != NULL) { - snd_rawmidi_close(device.input); - } -} - MidiDevice midi_open(char *name) { MidiDevice device; @@ -24,16 +15,12 @@ MidiDevice midi_open(char *name) { device.error = device.input == NULL || device.output == NULL; - if (device.error) { - midi_close(device); - } - log_debug("(%s) MIDI open", name); return device; } -void midi_background_listen(MidiDevice device, SharedContext *context) { +bool midi_background_listen(MidiDevice device, SharedContext *context) { pid_t pid; int bytes_read; unsigned char buffer[3]; @@ -41,10 +28,10 @@ void midi_background_listen(MidiDevice device, SharedContext *context) { pid = fork(); if (pid < 0) { log_error("Could not create subprocess"); - return; + return false; } if (pid == 0) { - return; + return true; } log_info("(%s) background acquisition started (pid: %d)", device.name, pid); @@ -57,7 +44,5 @@ void midi_background_listen(MidiDevice device, SharedContext *context) { log_info("(%s) background acquisition stopped by main thread (pid: %d)", device.name, pid); + return false; } - -// int bytes_read = snd_rawmidi_read(input, input_buffer, sizeof(input_buffer)); -// snd_rawmidi_write(output, buffer, 3); \ No newline at end of file diff --git a/src/midi.h b/src/midi.h index bdcb4e6..27ab570 100644 --- a/src/midi.h +++ b/src/midi.h @@ -4,7 +4,6 @@ #define MIDI_H MidiDevice midi_open(char *name); -void midi_close(MidiDevice device); -void midi_background_listen(MidiDevice device, SharedContext *context); +bool midi_background_listen(MidiDevice device, SharedContext *context); #endif /* MIDI_H */ \ No newline at end of file diff --git a/src/video.c b/src/video.c index d740740..7eed535 100644 --- a/src/video.c +++ b/src/video.c @@ -327,7 +327,7 @@ static bool read_video(VideoCapture *video_capture) { return true; } -void video_background_read(VideoCapture *video_capture, SharedContext *context, +bool video_background_read(VideoCapture *video_capture, SharedContext *context, int input_index) { pid_t pid; Timer timer; @@ -336,10 +336,10 @@ void video_background_read(VideoCapture *video_capture, SharedContext *context, pid = fork(); if (pid < 0) { log_error("Could not create subprocess"); - return; + return false; } if (pid == 0) { - return; + return true; } log_info("(%s) background acquisition started (pid: %d)", video_capture->name, pid); @@ -362,6 +362,7 @@ void video_background_read(VideoCapture *video_capture, SharedContext *context, video_capture->name, pid); } exit(context->stop ? EXIT_SUCCESS : EXIT_FAILURE); + return false; } void video_free(VideoCapture video_capture) { diff --git a/src/video.h b/src/video.h index 654a4ff..7648786 100644 --- a/src/video.h +++ b/src/video.h @@ -5,7 +5,7 @@ VideoCapture video_init(char *name, unsigned int preferred_height); -void video_background_read(VideoCapture *video_capture, SharedContext *context, +bool video_background_read(VideoCapture *video_capture, SharedContext *context, int input_index); void video_free(VideoCapture video_capture); diff --git a/src/window.c b/src/window.c index bfce57c..8e8ab97 100644 --- a/src/window.c +++ b/src/window.c @@ -21,7 +21,7 @@ static void init_glfw(void (*error_callback)(int, const char *)) { exit(EXIT_FAILURE); } - log_info("[GLFS] Initialized..."); + log_info("[GLFW] Initialized..."); } static GLFWmonitor *get_monitor(unsigned char monitor_index) {