Browse Source

Add the program dump option

master
Damien Goutte-Gattat 9 years ago
parent
commit
ff89c12f18
  1. 52
      src/kmxtool.c

52
src/kmxtool.c

@ -26,8 +26,13 @@
#include <getopt.h>
#include <err.h>
#include <hexio.h>
#include <microx.h>
#define MODE_STATUS 0x0
#define MODE_DUMP_PROGRAM 0x1
/* Globals. */
static midi_io_t *midi = NULL;
@ -51,6 +56,11 @@ Send/receive data to/from a connected microX synthesizer.\n");
-p, --port PORT Specify MIDI port to use.\n\
");
puts("\
-s, --status Print device status (default).\n\
-P, --program PRGM Dump the specified program.\n\
");
printf("Report bugs to <%s>.\n", PACKAGE_BUGREPORT);
exit(status);
@ -139,8 +149,8 @@ print_microx_status(struct kmx_microx_status *s)
int
main(int argc, char **argv)
{
char c, *port;
int e;
char c, *port, *param;
int e, mode;
struct kmx_microx_version version;
struct kmx_microx_status status;
@ -148,6 +158,8 @@ main(int argc, char **argv)
{ "help", 0, NULL, 'h' },
{ "version", 0, NULL, 'v' },
{ "port", 1, NULL, 'p' },
{ "status", 0, NULL, 's' },
{ "program", 1, NULL, 'P' },
{ NULL, 0, NULL, 0 }
};
@ -156,8 +168,9 @@ main(int argc, char **argv)
atexit(cleanup);
port = DEFAULT_MIDI_PORT;
mode = MODE_STATUS;
while ( (c = getopt_long(argc, argv, "hvp:", options, NULL)) != -1 ) {
while ( (c = getopt_long(argc, argv, "hvp:sP:", options, NULL)) != -1 ) {
switch ( c ) {
case 'h':
usage(EXIT_SUCCESS);
@ -174,6 +187,15 @@ main(int argc, char **argv)
case 'p':
port = optarg;
break;
case 's':
mode = MODE_STATUS;
break;
case 'P':
mode = MODE_DUMP_PROGRAM;
param = optarg;
break;
}
}
@ -184,14 +206,26 @@ main(int argc, char **argv)
errx(EXIT_FAILURE, "cannot identify microX device: %s",
kmx_microx_error(midi, e));
printf("%s: KORG microX synthesizer, version %02d.%02d.%02d.%02d\n",
port, version.major, version.minor, version.release, version.build);
if ( mode == MODE_STATUS ) {
printf("%s: KORG microX synthesizer, version %02d.%02d.%02d.%02d\n",
port, version.major, version.minor, version.release, version.build);
if ( (e = kmx_microx_query_status(midi, &status)) < 0 )
errx(EXIT_FAILURE, "cannot query microX status: %s",
kmx_microx_error(midi, e));
if ( (e = kmx_microx_query_status(midi, &status)) < 0 )
errx(EXIT_FAILURE, "cannot query microX status: %s",
kmx_microx_error(midi, e));
print_microx_status(&status);
print_microx_status(&status);
}
else if ( mode == MODE_DUMP_PROGRAM ) {
unsigned char program[MICROX_PROGRAM_SIZE];
int n;
if ( (n = kmx_microx_get_program(midi, param, program, sizeof(program))) < 0 )
errx(EXIT_FAILURE, "cannot get program: %s",
kmx_microx_error(midi, n));
fprinthd(stdout, program, n, 0);
}
return EXIT_SUCCESS;
}
Loading…
Cancel
Save