From 9e00c3ac52f5c289d87a017df8c25fb2d874f254 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Mon, 12 Oct 2015 06:47:36 +0200 Subject: added command line parser midi and osc are now optional --- apps/midi.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'apps/midi.c') diff --git a/apps/midi.c b/apps/midi.c index fa5739b..6ef5775 100644 --- a/apps/midi.c +++ b/apps/midi.c @@ -45,10 +45,12 @@ int midi_init(midi_t* m, const char* device) slist_init(&(m->done_data_), free); - int ret = snd_rawmidi_open(&(m->input_), &(m->output_), device, SND_RAWMIDI_NONBLOCK); - if(ret < 0) { - error(0, 0, "MIDI: cannot open port '%s': %s", device, snd_strerror(ret)); - return ret; + if(device) { + int ret = snd_rawmidi_open(&(m->input_), &(m->output_), device, SND_RAWMIDI_NONBLOCK); + if(ret < 0) { + error(0, 0, "MIDI: cannot open port '%s': %s", device, snd_strerror(ret)); + return ret; + } } return 0; @@ -58,6 +60,9 @@ int midi_get_poll_fd_count(midi_t* m) { assert(m); + if(!m->input_ || !m->output_) + return 0; + m->in_pfds_cnt_ = snd_rawmidi_poll_descriptors_count(m->input_); assert(m->in_pfds_cnt_ > 0); m->out_pfds_cnt_ = snd_rawmidi_poll_descriptors_count(m->output_); @@ -68,7 +73,10 @@ int midi_get_poll_fd_count(midi_t* m) int midi_get_poll_fds(midi_t* m, struct pollfd *pfds, int npfds) { - assert(m && pfds && npfds); + assert(m); + + if(!m->input_ || !m->output_) + return 0; snd_rawmidi_poll_descriptors(m->input_, pfds, m->in_pfds_cnt_); snd_rawmidi_poll_descriptors(m->output_, &(pfds[m->in_pfds_cnt_]), npfds - m->in_pfds_cnt_); @@ -216,7 +224,10 @@ static int midi_handle_out_revents(midi_t* m, struct pollfd *pfds, int npfds) int midi_handle_revents(midi_t* m, struct pollfd *pfds, int npfds, mixer_t* x) { - assert(m && x && pfds); + assert(m); + + if(!m->input_ || !m->output_) + return 0; int ret = midi_handle_in_revents(m, pfds, m->in_pfds_cnt_, x); if(ret) -- cgit v1.2.3