diff --git a/midi2osc/midi2osc.c b/midi2osc/midi2osc.c index 393d278..cba961e 100644 --- a/midi2osc/midi2osc.c +++ b/midi2osc/midi2osc.c @@ -21,6 +21,9 @@ #define NAME "midi2osc" +static int debug = 0; + + static void forward(snd_seq_t *midi, lo_address osc) { snd_seq_event_t *ev; @@ -37,6 +40,9 @@ static void forward(snd_seq_t *midi, lo_address osc) msg[1] = 0xb0 | ev->data.control.channel; msg[2] = ev->data.control.param; msg[3] = ev->data.control.value; + if (debug) + fprintf(stderr, "CC(%u) %u %u\n", + ev->data.control.channel, msg[2], msg[3]); break; case SND_SEQ_EVENT_PITCHBEND: msg[1] = 0xe0 | ev->data.control.channel; @@ -57,7 +63,10 @@ static void forward(snd_seq_t *midi, lo_address osc) static void usage(const char *name) { - fprintf(stderr, "usage: %s hostname [port]\n", name); + fprintf(stderr, +"usage: %s hostname [-d] [port]\n\n" +" -d debug mode: print all MIDI messages\n", + name); exit(1); } @@ -67,20 +76,31 @@ int main(int argc, char **argv) const char *port = "4444"; /* Milkymist One OSC port */ lo_address osc; snd_seq_t *midi; + int c; - switch (argc) { - case 2: + + while ((c = getopt(argc, argv, "d")) != EOF) + switch (c) { + case 'd': + debug = 1; + break; + default: + usage(*argv); + } + + switch (argc-optind) { + case 1: break; - case 3: - port = argv[2]; + case 2: + port = argv[optind+1]; break; default: usage(*argv); } - osc = lo_address_new(argv[1], port); + osc = lo_address_new(argv[optind], port); if (!osc) { - fprintf(stderr, "invalid address %s %s\n", argv[1], port); + fprintf(stderr, "invalid address %s %s\n", argv[optind], port); exit(1); }