1
0
mirror of git://projects.qi-hardware.com/wernermisc.git synced 2024-12-19 08:19:41 +02:00

midi2osc: new option -d (debug) to print MIDI messages we receive

This commit is contained in:
Werner Almesberger 2011-11-24 00:25:16 -03:00
parent 448e02f771
commit 571af6d11f

View File

@ -21,6 +21,9 @@
#define NAME "midi2osc" #define NAME "midi2osc"
static int debug = 0;
static void forward(snd_seq_t *midi, lo_address osc) static void forward(snd_seq_t *midi, lo_address osc)
{ {
snd_seq_event_t *ev; 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[1] = 0xb0 | ev->data.control.channel;
msg[2] = ev->data.control.param; msg[2] = ev->data.control.param;
msg[3] = ev->data.control.value; msg[3] = ev->data.control.value;
if (debug)
fprintf(stderr, "CC(%u) %u %u\n",
ev->data.control.channel, msg[2], msg[3]);
break; break;
case SND_SEQ_EVENT_PITCHBEND: case SND_SEQ_EVENT_PITCHBEND:
msg[1] = 0xe0 | ev->data.control.channel; 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) 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); exit(1);
} }
@ -67,20 +76,31 @@ int main(int argc, char **argv)
const char *port = "4444"; /* Milkymist One OSC port */ const char *port = "4444"; /* Milkymist One OSC port */
lo_address osc; lo_address osc;
snd_seq_t *midi; snd_seq_t *midi;
int c;
switch (argc) {
case 2: while ((c = getopt(argc, argv, "d")) != EOF)
break; switch (c) {
case 3: case 'd':
port = argv[2]; debug = 1;
break; break;
default: default:
usage(*argv); usage(*argv);
} }
osc = lo_address_new(argv[1], port); switch (argc-optind) {
case 1:
break;
case 2:
port = argv[optind+1];
break;
default:
usage(*argv);
}
osc = lo_address_new(argv[optind], port);
if (!osc) { if (!osc) {
fprintf(stderr, "invalid address %s %s\n", argv[1], port); fprintf(stderr, "invalid address %s %s\n", argv[optind], port);
exit(1); exit(1);
} }