From e1e94206e5de0a1b4e03593ffeb9d5cb6ce81abb Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sat, 10 Oct 2015 07:20:31 +0200 Subject: midi is back from threded to async io --- apps/dolmetschctl.c | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) (limited to 'apps/dolmetschctl.c') 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 -#include +#include #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; } -- cgit v1.2.3