Browse Source

Support dumping of multiple programs

develop
Damien Goutte-Gattat 8 years ago
parent
commit
f1a58f56bb
  1. 25
      src/kmxtool.c
  2. 57
      src/microx.c

25
src/kmxtool.c

@ -155,28 +155,15 @@ print_microx_status(struct kmx_microx_status *s)
static void
do_list_programs(midi_io_t *midi)
{
size_t n, len;
size_t len;
int n;
unsigned char *reply, *cursor, bank, program;
unsigned char query[] = { 0xF0, /* SysEx message begin */
0x42, /* Korg manufacturer ID */
0x30, /* Global channel */
0x7A, /* End of SysEx header */
0x1C, /* Program Parameter Dump Request */
0x00, /* Dump all programs */
0x00, /* Unused. */
0x00, /* Reserved */
0xF7 /* SysEx message end */ };
len = MICROX_PROGRAM_SIZE * MICROX_N_PROGRAM + 9;
reply = xmalloc(len);
if ( (n = midi_write(midi, query, sizeof(query))) < 0 )
errx(EXIT_FAILURE, "cannot dump data: %s",
kmx_microx_error(midi, n));
len = MICROX_PROGRAM_SIZE * MICROX_N_PROGRAM;
reply = xmalloc(len);
if ( (n = kmx_microx_read_dump(midi, 0x4C, reply, len)) < 0 )
err(EXIT_FAILURE, "cannot read dump data: %s",
kmx_microx_error(midi, n));
if ( (n = kmx_microx_dump(midi, PROGRAM_DATA, "????", reply, len)) < 0 )
errx(EXIT_FAILURE, "cannot dump data: %s", kmx_microx_error(midi, n));
for ( cursor = reply, bank = 'A'; bank < 'F'; bank++ ) {
for ( program = 0; program < 128; program++ ) {

57
src/microx.c

@ -240,24 +240,40 @@ static int
get_dump_parameters(enum kmx_microx_data_type type,
const char *what,
unsigned char *buffer,
int load)
int load,
size_t *size)
{
unsigned char program, bank;
switch ( type ) {
case PROGRAM_DATA:
if ( sscanf(what, "%c%03hhd", &bank, &program) != 2 )
return KMX_INVALID_QUERY;
if ( (bank < 'A' || bank > 'E') || program > 127 )
bank = what[0];
if ( bank != '?' && (bank < 'A' || bank > 'E') )
return KMX_INVALID_QUERY;
if ( load ) {
buffer[0] = 1;
buffer[1] = 0x20 + (bank - 'A');
buffer[2] = program;
if ( bank == '?' ) { /* Dump all programs. */
buffer[0] = 0;
buffer[1] = 0;
*size = MICROX_PROGRAM_SIZE * MICROX_N_PROGRAM;
}
else if ( what[1] == '?' ) { /* Dump all programs in bank. */
buffer[0] = 0x10 + (bank - 'A');
buffer[1] = 0;
*size = MICROX_PROGRAM_SIZE * 128;
}
else {
else if ( sscanf(&(what[1]), "%03hhd", &program) == 1 &&
program < 128 ) { /* Dump specified program. */
buffer[0] = 0x20 + (bank - 'A');
buffer[1] = program;
*size = MICROX_PROGRAM_SIZE;
}
else
return KMX_INVALID_QUERY;
if ( load ) {
buffer[2] = buffer[1];
buffer[1] = buffer[0];
buffer[0] = 1;
}
break;
@ -268,6 +284,7 @@ get_dump_parameters(enum kmx_microx_data_type type,
return KMX_INVALID_QUERY;
buffer[0] = 0x20 + (bank - 'A');
buffer[1] = program;
*size = MICROX_COMBINATION_SIZE;
break;
case MULTI_DATA:
@ -275,6 +292,7 @@ get_dump_parameters(enum kmx_microx_data_type type,
return KMX_INVALID_QUERY;
buffer[0] = 1;
buffer[1] = program;
*size = MICROX_MULTI_SIZE;
break;
case DRUMKIT_DATA:
@ -282,6 +300,7 @@ get_dump_parameters(enum kmx_microx_data_type type,
return KMX_INVALID_QUERY;
buffer[0] = 1;
buffer[1] = program;
*size = MICROX_DRUMKIT_SIZE;
break;
case ARPEGGIO_DATA:
@ -290,6 +309,7 @@ get_dump_parameters(enum kmx_microx_data_type type,
buffer[0] = 1;
buffer[1] = program >> 7;
buffer[2] = program & 0x7F;
*size = MICROX_ARPEGGIO_SIZE;
break;
case EXTSET_DATA:
@ -297,6 +317,7 @@ get_dump_parameters(enum kmx_microx_data_type type,
return KMX_INVALID_QUERY;
buffer[0] = 1;
buffer[1] = program;
*size = MICROX_EXTSET_SIZE;
break;
}
@ -381,13 +402,13 @@ kmx_microx_dump(midi_io_t *midi,
0x00, /* Dump parameter 3 */
0xF7 /* SysEx message end */ };
if ( len < dumps[type].data_size )
return KMX_BUFFER_TOO_SMALL;
query[4] = dumps[type].query_code;
if ( get_dump_parameters(type, what, &(query[5]), 0) < 0 )
if ( get_dump_parameters(type, what, &(query[5]), 0, &n) < 0 )
return KMX_INVALID_QUERY;
if ( len < n )
return KMX_BUFFER_TOO_SMALL;
if ( (n = midi_write(midi, query, sizeof(query))) < 0 )
return KMX_IO_ERROR;
@ -413,14 +434,14 @@ kmx_microx_load(midi_io_t *midi,
0x00, /* Dump parameter 3 */ };
unsigned char reply[7];
if ( len < dumps[type].data_size )
return KMX_BUFFER_TOO_SMALL;
buffer[4] = dumps[type].reply_code;
if ( get_dump_parameters(type, what, &(buffer[5]), 1) < 0 )
if ( get_dump_parameters(type, what, &(buffer[5]), 1, &n) < 0 )
return KMX_INVALID_QUERY;
n = 8;
if ( len < n )
return KMX_BUFFER_TOO_SMALL;
n = 8;
m = status = 0;
while ( m < len && status == 0 ) {

Loading…
Cancel
Save