Browse Source

Add the --inquiry option

master
Damien Goutte-Gattat 9 years ago
parent
commit
b23bee1647
  1. 35
      src/asysex.c

35
src/asysex.c

@ -50,6 +50,10 @@ Read/write MIDI SysEx messages.\n");
-p, --port PORT Specify MIDI port to use.\n\
");
puts("\
-I, --inquiry Identify the MIDI device and exit.\n\
");
printf("Report bugs to <%s>.\n", PACKAGE_BUGREPORT);
exit(status);
@ -81,6 +85,23 @@ cleanup(void)
}
}
static void
identify_device(midi_io_t *midi)
{
midi_device_id_t dev;
if ( sysex_identify(midi, &dev) <= 0 )
errx(EXIT_FAILURE, "cannot identify MIDI device");
printf("%s family %x, model %x, version %d.%d.%d.%d\n",
sysex_get_manufacturer(dev.manufacturer),
dev.family, dev.model,
dev.version & 0xFF,
(dev.version >> 8) & 0xFF,
(dev.version >> 16) & 0xFF,
(dev.version >> 24) & 0xFF);
}
/* Main function. */
@ -88,11 +109,13 @@ int
main(int argc, char **argv)
{
char c, *port;
int inquiry;
struct option options[] = {
{ "help", 0, NULL, 'h' },
{ "version", 0, NULL, 'v' },
{ "port", 1, NULL, 'p' },
{ "inquiry", 0, NULL, 'I' },
{ NULL, 0, NULL, 0 }
};
@ -101,8 +124,9 @@ main(int argc, char **argv)
atexit(cleanup);
port = "hw:1,0,0";
inquiry = 0;
while ( (c = getopt_long(argc, argv, "hvp:", options, NULL)) != -1 ) {
while ( (c = getopt_long(argc, argv, "hvp:I", options, NULL)) != -1 ) {
switch ( c ) {
case 'h':
usage(EXIT_SUCCESS);
@ -119,11 +143,20 @@ main(int argc, char **argv)
case 'p':
port = optarg;
break;
case 'I':
inquiry = 1;
break;
}
}
if ( ! (midi = midi_open(port)) )
errx(EXIT_FAILURE, "cannot open MIDI port %s", port);
if ( inquiry ) {
identify_device(midi);
return EXIT_SUCCESS;
}
return EXIT_SUCCESS;
}
Loading…
Cancel
Save