summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/dolmetschctl.c29
-rw-r--r--apps/midi.c4
-rw-r--r--apps/midi.h4
-rw-r--r--apps/osc.c37
-rw-r--r--apps/osc.h8
5 files changed, 50 insertions, 32 deletions
diff --git a/apps/dolmetschctl.c b/apps/dolmetschctl.c
index 26b8e83..b8f9197 100644
--- a/apps/dolmetschctl.c
+++ b/apps/dolmetschctl.c
@@ -47,12 +47,20 @@ int main_loop(osc_t* o, midi_t* m)
printf("main_loop just started\n");
- int npfds;
- struct pollfd *pfds;
+ int midi_npfds_offset = 0;
+ int midi_npfds = midi_get_poll_fd_count(m);
+ assert(midi_npfds > 0);
- npfds = midi_get_poll_desc_count(m);
- pfds = alloca(npfds * sizeof(struct pollfd));
- midi_get_poll_desc(m, pfds, npfds);
+ int osc_npfds_offset = midi_npfds_offset + midi_npfds;
+ int osc_npfds = osc_get_poll_fd_count(o);
+ assert(osc_npfds > 0);
+
+ int npfds = midi_npfds + osc_npfds;
+ struct pollfd *pfds = alloca(npfds * sizeof(struct pollfd));
+
+
+ midi_get_poll_fds(m, &(pfds[midi_npfds_offset]), midi_npfds);
+ osc_get_poll_fds(o, &(pfds[osc_npfds_offset]), osc_npfds);
printf("main_loop running...\n");
for (;;) {
@@ -69,7 +77,11 @@ int main_loop(osc_t* o, midi_t* m)
continue;
}
- ret = midi_handle_revents(m, pfds, npfds);
+ ret = midi_handle_revents(m, &(pfds[midi_npfds_offset]), midi_npfds);
+ if(ret)
+ break;
+
+ ret = osc_handle_revents(o, &(pfds[osc_npfds_offset]), osc_npfds);
if(ret)
break;
}
@@ -87,12 +99,7 @@ int main(int argc, char* argv[])
if(midi_init(&m, "hw:2,0,0"))
return -1;
- if(osc_start(&o))
- return -1;
-
int ret = main_loop(&o, &m);
- osc_stop(&o);
-
return ret;
}
diff --git a/apps/midi.c b/apps/midi.c
index 261e12f..821f353 100644
--- a/apps/midi.c
+++ b/apps/midi.c
@@ -43,12 +43,12 @@ int midi_init(midi_t* m, const char* device)
return 0;
}
-int midi_get_poll_desc_count(midi_t* m)
+int midi_get_poll_fd_count(midi_t* m)
{
return snd_rawmidi_poll_descriptors_count(m->input_);
}
-int midi_get_poll_desc(midi_t* m, struct pollfd *pfds, int npfds)
+int midi_get_poll_fds(midi_t* m, struct pollfd *pfds, int npfds)
{
return snd_rawmidi_poll_descriptors(m->input_, pfds, npfds);
}
diff --git a/apps/midi.h b/apps/midi.h
index f2aa119..38b1a7c 100644
--- a/apps/midi.h
+++ b/apps/midi.h
@@ -31,8 +31,8 @@ typedef struct {
} midi_t;
int midi_init(midi_t* m, const char* device);
-int midi_get_poll_desc_count(midi_t* m);
-int midi_get_poll_desc(midi_t* m, struct pollfd *pfds, int npfds);
+int midi_get_poll_fd_count(midi_t* m);
+int midi_get_poll_fds(midi_t* m, struct pollfd *pfds, int npfds);
int midi_handle_revents(midi_t* m, struct pollfd *pfds, int npfds);
#endif
diff --git a/apps/osc.c b/apps/osc.c
index 7effa54..0291af3 100644
--- a/apps/osc.c
+++ b/apps/osc.c
@@ -54,36 +54,45 @@ int osc_init(osc_t* o, const char* port)
{
assert(o != NULL);
- o->st_ = lo_server_thread_new(port, print_error);
- if(!o->st_)
+ o->server_ = lo_server_new(port, print_error);
+ if(!o->server_)
return -1;
- if(!lo_server_thread_add_method(o->st_, NULL, NULL, generic_handler, NULL))
+ if(!lo_server_add_method(o->server_, NULL, NULL, generic_handler, NULL))
return -1;
return 0;
}
-int osc_start(osc_t* o)
+
+int osc_get_poll_fd_count(osc_t* o)
{
- assert(o != NULL);
+ return 1;
+}
- int ret = lo_server_thread_start(o->st_);
- if(ret)
- error(0, ret, "faild to create osc thread");
+int osc_get_poll_fds(osc_t* o, struct pollfd *pfds, int npfds)
+{
+ assert(npfds == 1);
+
+ pfds[0].fd = lo_server_get_socket_fd(o->server_);
+ pfds[0].events = POLLIN;
+ pfds[0].revents = 0;
return 0;
}
-int osc_stop(osc_t* o)
+int osc_handle_revents(osc_t* o, struct pollfd *pfds, int npfds)
{
- assert(o != NULL);
+ assert(npfds == 1);
- int ret = lo_server_thread_stop(o->st_);
- if(ret)
- error(0, ret, "faild to stop osc thread");
+ if(pfds[0].revents & (POLLERR | POLLHUP)) {
+ error(0, 0, "OSC: got POLLERR or POLLHUP");
+ return -1;
+ }
+ if(!(pfds[0].revents & POLLIN))
+ return 0;
- lo_server_thread_free(o->st_);
+ lo_server_recv_noblock(o->server_, 0);
return 0;
}
diff --git a/apps/osc.h b/apps/osc.h
index 7a03cb7..ddef73e 100644
--- a/apps/osc.h
+++ b/apps/osc.h
@@ -24,13 +24,15 @@
#define DOLMETSCHCTL_osc_h_INCLUDED
#include "lo/lo.h"
+#include <poll.h>
typedef struct {
- lo_server_thread st_;
+ lo_server server_;
} osc_t;
int osc_init(osc_t* o, const char* port);
-int osc_start(osc_t* o);
-int osc_stop(osc_t* o);
+int osc_get_poll_fd_count(osc_t* o);
+int osc_get_poll_fds(osc_t* o, struct pollfd *pfds, int npfds);
+int osc_handle_revents(osc_t* o, struct pollfd *pfds, int npfds);
#endif