summaryrefslogtreecommitdiff
path: root/apps/dolmetschctl.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dolmetschctl.c')
-rw-r--r--apps/dolmetschctl.c45
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;
}