summaryrefslogtreecommitdiff
path: root/apps/midi.c
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2015-10-12 06:47:36 +0200
committerChristian Pointner <equinox@spreadspace.org>2015-10-12 06:47:36 +0200
commit9e00c3ac52f5c289d87a017df8c25fb2d874f254 (patch)
tree59f5a655b7136cc4593cf9d932096bb01bd7beba /apps/midi.c
parentosc requests get now acked (diff)
added command line parser
midi and osc are now optional
Diffstat (limited to 'apps/midi.c')
-rw-r--r--apps/midi.c23
1 files changed, 17 insertions, 6 deletions
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)