diff --git a/src/forge.c b/src/forge.c index 9188698..92ff24a 100644 --- a/src/forge.c +++ b/src/forge.c @@ -85,7 +85,7 @@ static void init_inputs() { for (unsigned int i = 0; i < init_params.video_in.length; i++) { video_init(&video_captures.values[i], init_params.video_in.values[i], - init_params.video_size, init_params.video_buffers); + init_params.video_size, init_params.video_buffers, true); if (!video_captures.values[i].error) { context.input_resolutions[i][0] = video_captures.values[i].width; @@ -121,7 +121,7 @@ background_reconnect_video_captures(__attribute__((unused)) void *args) { if (video_captures.values[i].disconnected) { video_free(&video_captures.values[i]); video_init(&video_captures.values[i], init_params.video_in.values[i], - init_params.video_size, init_params.video_buffers); + init_params.video_size, init_params.video_buffers, false); if (!video_captures.values[i].error) { context.input_resolutions[i][0] = video_captures.values[i].width; @@ -219,7 +219,8 @@ static void *background_reconnect_midi(__attribute__((unused)) void *args) { while (!context.stop) { sleep(1); if (!midi.connected) { - midi_open(&midi, config_file_get_str(&project.config, "MIDI_HW", "hw")); + midi_open(&midi, config_file_get_str(&project.config, "MIDI_HW", "hw"), + false); if (midi.connected) { start_midi_background_listen(); } @@ -231,7 +232,7 @@ static void *background_reconnect_midi(__attribute__((unused)) void *args) { static void init_midi() { pthread_t thread; - midi_open(&midi, config_file_get_str(&project.config, "MIDI_HW", "hw")); + midi_open(&midi, config_file_get_str(&project.config, "MIDI_HW", "hw"), true); if (midi.connected) { start_midi_background_listen(); diff --git a/src/midi.c b/src/midi.c index 4e45494..d834d98 100644 --- a/src/midi.c +++ b/src/midi.c @@ -6,19 +6,36 @@ #include "config.h" -void midi_open(MidiDevice *device, const char *name) { +void snd_no_log(__attribute__((unused)) int prio, + __attribute__((unused)) int interface, + __attribute__((unused)) const char *file, + __attribute__((unused)) int line, + __attribute__((unused)) const char *function, + __attribute__((unused)) int errcode, + __attribute__((unused)) const char *fmt, + __attribute__((unused)) va_list arg) {} + +void midi_open(MidiDevice *device, const char *name, bool log_error) { strlcpy(device->name, name, STR_LEN); + device->connected = false; device->input = NULL; device->output = NULL; + if (!log_error) { + snd_lib_log_set_handler(snd_no_log); + } + snd_rawmidi_open(&device->input, &device->output, name, SND_RAWMIDI_NONBLOCK); device->connected = device->input != NULL && device->output != NULL; - - if (device->connected) { - log_info("(%s) MIDI open", name); + if (log_error) { + if (device->connected) { + log_info("(%s) MIDI open", name); + } else { + log_warn("(%s) MIDI open failed", name); + } } else { - log_warn("(%s) MIDI open failed", name); + snd_lib_log_set_handler(snd_lib_vlog); } } diff --git a/src/midi.h b/src/midi.h index 717fb97..1f7990e 100644 --- a/src/midi.h +++ b/src/midi.h @@ -3,7 +3,7 @@ #ifndef MIDI_H #define MIDI_H -void midi_open(MidiDevice *device, const char *name); +void midi_open(MidiDevice *device, const char *name, bool log_error); void midi_write(MidiDevice device, unsigned char code, unsigned char value); void *midi_background_listen(void *args); void midi_close(MidiDevice *device); diff --git a/src/video.c b/src/video.c index 4ed99b5..c06c289 100644 --- a/src/video.c +++ b/src/video.c @@ -70,14 +70,17 @@ static void ioctl_error(VideoCapture *video_capture, const char *operation, video_capture->error = true; } -static void open_device(VideoCapture *video_capture, const char *name) { +static void open_device(VideoCapture *video_capture, const char *name, + bool log_error) { strlcpy(video_capture->name, name, STR_LEN); video_capture->error = false; video_capture->fd = -1; video_capture->fd = open(name, O_RDWR | O_NONBLOCK); if (video_capture->fd == -1) { - log_warn("(%s) Cannot open device", name); + if (log_error) { + log_warn("(%s) Cannot open device", name); + } video_capture->error = true; } } @@ -305,8 +308,9 @@ static unsigned int read_video(VideoCapture *video_capture) { } void video_init(VideoCapture *video_capture, const char *name, - unsigned int preferred_height, unsigned int buffer_count) { - open_device(video_capture, name); + unsigned int preferred_height, unsigned int buffer_count, + bool log_error) { + open_device(video_capture, name, log_error); if (video_capture->error) { return; diff --git a/src/video.h b/src/video.h index 6581b95..7c403a9 100644 --- a/src/video.h +++ b/src/video.h @@ -6,7 +6,8 @@ #ifdef VIDEO_IN void video_init(VideoCapture *video_capture, const char *name, - unsigned int preferred_height, unsigned int buffer_count); + unsigned int preferred_height, unsigned int buffer_count, + bool log_error); void *video_background_read(void *args);