diff options
Diffstat (limited to 'apps/osc.c')
-rw-r--r-- | apps/osc.c | 42 |
1 files changed, 19 insertions, 23 deletions
@@ -30,8 +30,7 @@ static void print_error(int num, const char *msg, const char *path) { - printf("liblo server error %d in path %s: %s\n", num, path, msg); - fflush(stdout); + fprintf(stderr, "liblo server error %d in path %s: %s\n", num, path, msg); } static int generic_handler(const char *path, const char *types, lo_arg ** argv, @@ -39,43 +38,40 @@ static int generic_handler(const char *path, const char *types, lo_arg ** argv, { int i; - printf("path: <%s>\n", path); + printf("OSC(%s):%s", path, argc ? " ": " <no arguments>\n"); for(i = 0; i < argc; i++) { - printf("arg %d '%c' ", i, types[i]); + printf("arg %d '%c'", i, types[i]); lo_arg_pp((lo_type)types[i], argv[i]); - printf("\n"); + printf("%s", i >= (argc-1) ? "\n" : ", "); } - printf("\n"); - fflush(stdout); return 1; } -static int foo_handler(const char *path, const char *types, lo_arg ** argv, - int argc, void *data, void *user_data) + +int osc_init(osc_t* o, const char* port) { - printf("%s <- f:%f, i:%d\n", path, argv[0]->f, argv[1]->i); - fflush(stdout); + if(!o) + return -1; + + o->st_ = lo_server_thread_new(port, print_error); // TODO: what happends when this fails? + lo_server_thread_add_method(o->st_, NULL, NULL, generic_handler, NULL); return 0; } - -lo_server_thread osc_init(const char* port) +void osc_start(osc_t* o) { - lo_server_thread st = lo_server_thread_new(port, print_error); - lo_server_thread_add_method(st, NULL, NULL, generic_handler, NULL); - lo_server_thread_add_method(st, "/foo/bar", "fi", foo_handler, NULL); + if(!o) + return; - return st; + lo_server_thread_start(o->st_); } -void osc_start(lo_server_thread st) +void osc_stop(osc_t* o) { - lo_server_thread_start(st); -} + if(!o) + return; -void osc_stop(lo_server_thread st) -{ - lo_server_thread_free(st); + lo_server_thread_free(o->st_); } |