diff options
author | Christian Pointner <equinox@spreadspace.org> | 2015-10-10 07:20:31 +0200 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2015-10-10 07:20:31 +0200 |
commit | e1e94206e5de0a1b4e03593ffeb9d5cb6ce81abb (patch) | |
tree | 1801606ee6f5b8385905e7db133e597566a270d7 /apps/dolmetschctl.c | |
parent | improved error handling (diff) |
midi is back from threded to async io
Diffstat (limited to 'apps/dolmetschctl.c')
-rw-r--r-- | apps/dolmetschctl.c | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/apps/dolmetschctl.c b/apps/dolmetschctl.c index cdf95bb..26b8e83 100644 --- a/apps/dolmetschctl.c +++ b/apps/dolmetschctl.c @@ -23,7 +23,7 @@ #include "config.h" #include <stdio.h> -#include <unistd.h> +#include <error.h> #include "osc.h" #include "midi.h" @@ -41,6 +41,42 @@ void print_version() #endif } +int main_loop(osc_t* o, midi_t* m) +{ + int ret = 0; + + printf("main_loop just started\n"); + + int npfds; + struct pollfd *pfds; + + npfds = midi_get_poll_desc_count(m); + pfds = alloca(npfds * sizeof(struct pollfd)); + midi_get_poll_desc(m, pfds, npfds); + + printf("main_loop running...\n"); + for (;;) { + int err = poll(pfds, npfds, 200); + if(err < 0) { + if(errno == EINTR) + continue; + + error(0, errno, "poll failed"); + break; + } + if(err == 0) { + // timeout is reached + continue; + } + + ret = midi_handle_revents(m, pfds, npfds); + if(ret) + break; + } + + return ret; +} + int main(int argc, char* argv[]) { osc_t o; @@ -51,13 +87,12 @@ int main(int argc, char* argv[]) if(midi_init(&m, "hw:2,0,0")) return -1; - if(osc_start(&o) || midi_start(&m)) + if(osc_start(&o)) return -1; - sleep(10); + int ret = main_loop(&o, &m); - midi_stop(&m); osc_stop(&o); - return 0; + return ret; } |