diff options
-rw-r--r-- | apps/midi.c | 2 | ||||
-rw-r--r-- | apps/mixer.c | 2 | ||||
-rw-r--r-- | apps/osc.c | 66 | ||||
-rw-r--r-- | apps/osc.h | 9 |
4 files changed, 65 insertions, 14 deletions
diff --git a/apps/midi.c b/apps/midi.c index 5d5fb1a..fa5739b 100644 --- a/apps/midi.c +++ b/apps/midi.c @@ -171,7 +171,7 @@ static int midi_handle_in_revents(midi_t* m, struct pollfd *pfds, int npfds, mix return ret; } - return 0; + return ret; } static int midi_handle_out_revents(midi_t* m, struct pollfd *pfds, int npfds) diff --git a/apps/mixer.c b/apps/mixer.c index 83ac8c7..026a43e 100644 --- a/apps/mixer.c +++ b/apps/mixer.c @@ -195,7 +195,7 @@ int mixer_switch_lang(mixer_t* x, const char* lang, void (*done_cb)(void*), void } } error(0, 0, "requested language '%s' not found ... ignoring switch", lang); - return -1; + return 0; } void mixer_print_tasks(mixer_t* x) @@ -34,21 +34,47 @@ static void print_error(int num, const char *msg, const char *path) error(0, 0, "liblo server error %d in path %s: %s", num, path, msg); } -static int generic_handler(const char *path, const char *types, lo_arg ** argv, - int argc, void *data, void *user_data) +static int lang_handler(const char *path, const char *types, lo_arg ** argv, + int argc, lo_message msg, void *user_data) { - int i; + if(argc != 1 || !lo_is_string_type((lo_type)types[0])) + return 1; - printf("OSC(%s):%s", path, argc ? " ": " <no arguments>\n"); - for(i = 0; i < argc; i++) { - printf("arg %d '%c'", i, types[i]); - lo_arg_pp((lo_type)types[i], argv[i]); - printf("%s", i >= (argc-1) ? "\n" : ", "); - } + osc_t* o = (osc_t*)user_data; + assert(o); + osc_done_data_t* done_data = malloc(sizeof(osc_done_data_t)); + assert(done_data); - return 1; + done_data->self_ = o; + done_data->state_ = 0; + assert((done_data->lang_ = strdup(&(argv[0]->s)))); + done_data->msg_ = lo_message_new(); + assert(done_data->msg_); + assert(!lo_message_add(done_data->msg_, "s", done_data->lang_)); + + assert(slist_add(&(o->done_data_), done_data)); + + return 0; } +void free_osc_done_data(void* ptr) +{ + osc_done_data_t* done_data = (osc_done_data_t*)ptr; + + lo_message_free(done_data->msg_); + free(done_data->lang_); + free(done_data); +} + +void osc_lang_switch_done(void* data) +{ + assert(data); + osc_done_data_t* d = data; + d->state_ = 2; + + // TODO: remove this as soon as acks are sent + slist_remove(&(d->self_->done_data_), d); +} int osc_init(osc_t* o, const char* port) { @@ -58,9 +84,11 @@ int osc_init(osc_t* o, const char* port) if(!o->server_) return -1; - if(!lo_server_add_method(o->server_, NULL, NULL, generic_handler, NULL)) + if(!lo_server_add_method(o->server_, "/lang", "s", lang_handler, (void*)o)) return -1; + slist_init(&(o->done_data_), free_osc_done_data); + return 0; } @@ -94,5 +122,19 @@ int osc_handle_revents(osc_t* o, struct pollfd *pfds, int npfds, mixer_t* x) lo_server_recv_noblock(o->server_, 0); - return 0; + int ret = 0; + slist_element_t* tmp; + for(tmp = o->done_data_.first_; tmp; tmp = tmp->next_) { + osc_done_data_t* d = (osc_done_data_t*)(tmp->data_); + if(d->state_ == 0) { + ret = mixer_switch_lang(x, d->lang_, &osc_lang_switch_done, d); + if(ret) + break; + + d->state_ = 1; + } + } + + + return ret; } @@ -26,12 +26,21 @@ #include "lo/lo.h" #include <poll.h> +#include "slist.h" #include "mixer.h" typedef struct { lo_server server_; + slist_t done_data_; } osc_t; +typedef struct { + osc_t* self_; + int state_; + char* lang_; + lo_message msg_; +} osc_done_data_t; + int osc_init(osc_t* o, const char* port); int osc_get_poll_fd_count(osc_t* o); int osc_get_poll_fds(osc_t* o, struct pollfd *pfds, int npfds); |