Browse Source

Allow dumping and loading of all data types

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

64
src/kmxtool.c

@ -31,8 +31,8 @@
#include <microx.h>
#define MODE_STATUS 0x0
#define MODE_DUMP_PROGRAM 0x1
#define MODE_LOAD_PROGRAM 0x2
#define MODE_DATA_DUMP 0x1
#define MODE_DATA_LOAD 0x2
/* Globals. */
@ -59,9 +59,12 @@ Send/receive data to/from a connected microX synthesizer.\n");
puts("\
-s, --status Print device status (default).\n\
-P, --program PRGM Dump the specified program.\n\
-L, --load-into PRGM Load program read from standard\n\
-d, --dump-data ID Dump the specified slot.\n\
-l, --load-data ID Load program read from standard\n\
input into the specified slot.\n\
-t, --data-type {program|combination|multi|drumkit|arpeggio|extset}\n\
Specify the type of data to dump\n\
or load. Default is `program'.\n\
");
printf("Report bugs to <%s>.\n", PACKAGE_BUGREPORT);
@ -156,14 +159,16 @@ main(int argc, char **argv)
int e, mode;
struct kmx_microx_version version;
struct kmx_microx_status status;
enum kmx_microx_data_type type;
struct option options[] = {
{ "help", 0, NULL, 'h' },
{ "version", 0, NULL, 'v' },
{ "port", 1, NULL, 'p' },
{ "status", 0, NULL, 's' },
{ "program", 1, NULL, 'P' },
{ "load-into", 1, NULL, 'L' },
{ "help", 0, NULL, 'h' },
{ "version", 0, NULL, 'v' },
{ "port", 1, NULL, 'p' },
{ "status", 0, NULL, 's' },
{ "dump-data", 1, NULL, 'd' },
{ "load-data", 1, NULL, 'l' },
{ "data-type", 1, NULL, 't' },
{ NULL, 0, NULL, 0 }
};
@ -173,8 +178,10 @@ main(int argc, char **argv)
port = DEFAULT_MIDI_PORT;
mode = MODE_STATUS;
type = PROGRAM_DATA;
while ( (c = getopt_long(argc, argv, "hvp:sP:L:", options, NULL)) != -1 ) {
while ( (c = getopt_long(argc, argv, "hvp:sd:l:t:",
options, NULL)) != -1 ) {
switch ( c ) {
case 'h':
usage(EXIT_SUCCESS);
@ -196,15 +203,32 @@ main(int argc, char **argv)
mode = MODE_STATUS;
break;
case 'P':
mode = MODE_DUMP_PROGRAM;
case 'd':
mode = MODE_DATA_DUMP;
param = optarg;
break;
case 'L':
mode = MODE_LOAD_PROGRAM;
case 'l':
mode = MODE_DATA_DUMP;
param = optarg;
break;
case 't':
if ( strcmp(optarg, "program") == 0 )
type = PROGRAM_DATA;
else if ( strcmp(optarg, "combination") == 0 )
type = COMBINATION_DATA;
else if ( strcmp(optarg, "multi") == 0 )
type = MULTI_DATA;
else if ( strcmp(optarg, "drumkit") == 0 )
type = DRUMKIT_DATA;
else if ( strcmp(optarg, "arpeggio") == 0 )
type = ARPEGGIO_DATA;
else if ( strcmp(optarg, "extset") == 0 )
type = EXTSET_DATA;
else
err(EXIT_FAILURE, "invalid data type: %s", optarg);
break;
}
}
@ -225,17 +249,17 @@ main(int argc, char **argv)
print_microx_status(&status);
}
else if ( mode == MODE_DUMP_PROGRAM ) {
unsigned char program[MICROX_PROGRAM_SIZE];
else if ( mode == MODE_DATA_DUMP ) {
unsigned char program[MICROX_DRUMKIT_SIZE];
int n;
if ( (n = kmx_microx_dump(midi, PROGRAM_DATA, param, program, sizeof(program))) < 0 )
if ( (n = kmx_microx_dump(midi, type, param, program, sizeof(program))) < 0 )
errx(EXIT_FAILURE, "cannot get program: %s",
kmx_microx_error(midi, n));
fprinthd(stdout, program, n, 0);
}
else if ( mode == MODE_LOAD_PROGRAM ) {
else if ( mode == MODE_DATA_LOAD ) {
unsigned char *program;
ssize_t n;
@ -244,7 +268,7 @@ main(int argc, char **argv)
if ( n < 1 )
err(EXIT_FAILURE, "cannot read program");
kmx_microx_load(midi, PROGRAM_DATA, param, program, n);
kmx_microx_load(midi, type, param, program, n);
}
return EXIT_SUCCESS;

Loading…
Cancel
Save