From 42791afe69fc2f06a8c606008b933323c55b1039 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sat, 10 Oct 2015 05:59:43 +0200 Subject: osc know has an own stuct too --- apps/dolmetschctl.c | 9 +++++---- apps/midi.c | 11 ++++++----- apps/midi.h | 1 - apps/osc.c | 42 +++++++++++++++++++----------------------- apps/osc.h | 10 +++++++--- 5 files changed, 37 insertions(+), 36 deletions(-) (limited to 'apps') diff --git a/apps/dolmetschctl.c b/apps/dolmetschctl.c index 0fc9877..6e92b2c 100644 --- a/apps/dolmetschctl.c +++ b/apps/dolmetschctl.c @@ -43,16 +43,17 @@ void print_version() int main(int argc, char* argv[]) { - lo_server_thread st = osc_init("7770"); - // TODO: check if this worked! + osc_t o; + if(osc_init(&o, "7770")) + return -1; midi_t m; if(midi_init(&m, "hw:2,0,0")) return -1; - osc_start(st); + osc_start(&o); midi_run(&m); - osc_stop(st); + osc_stop(&o); return 0; } diff --git a/apps/midi.c b/apps/midi.c index 45cb12f..8110475 100644 --- a/apps/midi.c +++ b/apps/midi.c @@ -34,9 +34,9 @@ int midi_init(midi_t* m, const char* device) if(!m) return -1; - int ret = snd_rawmidi_open(&(m->input_), &(m->output_), device, SND_RAWMIDI_NONBLOCK); + int ret = snd_rawmidi_open(&(m->input_), NULL, device, SND_RAWMIDI_NONBLOCK); if(ret < 0) { - error(0, 0, "cannot open midi port '%s': %s", device, snd_strerror(ret)); + error(0, 0, "MIDI: cannot open port '%s': %s", device, snd_strerror(ret)); return ret; } @@ -59,7 +59,7 @@ void midi_run(midi_t* m) if(err < 0 && errno == EINTR) break; if(err < 0) { - error(0, errno, "poll failed"); + error(0, errno, "MIDI: poll failed"); break; } /* if(err == 0) { */ @@ -68,7 +68,7 @@ void midi_run(midi_t* m) unsigned short revents; if((err = snd_rawmidi_poll_descriptors_revents(m->input_, pfds, npfds, &revents)) < 0) { - error(0, 0, "cannot get poll events: %s", snd_strerror(errno)); + error(0, 0, "MIDI: cannot get poll events: %s", snd_strerror(errno)); break; } if(revents & (POLLERR | POLLHUP)) @@ -81,11 +81,12 @@ void midi_run(midi_t* m) if (ret == -EAGAIN) continue; if(ret < 0) { - error(0, 0, "cannot read from midi port: %s", snd_strerror(ret)); + error(0, 0, "MIDI: cannot read from midi port: %s", snd_strerror(ret)); break; } int i; + printf("MIDI:%s", ret ? " ": " no data?\n"); for (i = 0; i < ret; ++i) printf("%02X%c", buf[i], (i >= (ret-1)) ? '\n' : ' '); } diff --git a/apps/midi.h b/apps/midi.h index 176b528..91634a8 100644 --- a/apps/midi.h +++ b/apps/midi.h @@ -27,7 +27,6 @@ typedef struct { snd_rawmidi_t* input_; - snd_rawmidi_t* output_; } midi_t; int midi_init(midi_t* m, const char* device); diff --git a/apps/osc.c b/apps/osc.c index 4cba491..701481f 100644 --- a/apps/osc.c +++ b/apps/osc.c @@ -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 ? " ": " \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_); } diff --git a/apps/osc.h b/apps/osc.h index 51c0539..d9163e2 100644 --- a/apps/osc.h +++ b/apps/osc.h @@ -25,8 +25,12 @@ #include "lo/lo.h" -lo_server_thread osc_init(const char* port); -void osc_start(lo_server_thread); -void osc_stop(lo_server_thread); +typedef struct { + lo_server_thread st_; +} osc_t; + +int osc_init(osc_t* o, const char* port); +void osc_start(osc_t* o); +void osc_stop(osc_t* o); #endif -- cgit v1.2.3