Browse Source

Generalize data dump function

master
Damien Goutte-Gattat 9 years ago
parent
commit
56849c603b
  1. 2
      src/kmxtool.c
  2. 114
      src/microx.c
  3. 19
      src/microx.h

2
src/kmxtool.c

@ -220,7 +220,7 @@ main(int argc, char **argv)
unsigned char program[MICROX_PROGRAM_SIZE];
int n;
if ( (n = kmx_microx_get_program(midi, param, program, sizeof(program))) < 0 )
if ( (n = kmx_microx_dump(midi, PROGRAM_DATA, param, program, sizeof(program))) < 0 )
errx(EXIT_FAILURE, "cannot get program: %s",
kmx_microx_error(midi, n));

114
src/microx.c

@ -200,32 +200,106 @@ kmx_microx_error(midi_io_t *midi, int e)
return msg;
}
struct dump {
unsigned char query_code;
unsigned char reply_code;
size_t data_size;
};
static struct dump dumps[] = {
{ 0x1C, 0x4C, MICROX_PROGRAM_SIZE },
{ 0x1D, 0x4D, MICROX_COMBINATION_SIZE },
{ 0x18, 0x48, MICROX_MULTI_SIZE },
{ 0x0D, 0x52, MICROX_DRUMKIT_SIZE },
{ 0x34, 0x69, MICROX_ARPEGGIO_SIZE },
{ 0x1E, 0x6E, MICROX_EXTSET_SIZE }
};
static int
get_dump_parameters(enum kmx_microx_data_type type,
const char *what,
unsigned char *buffer)
{
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 )
return KMX_INVALID_QUERY;
buffer[0] = 0x20 + (bank - 'A');
buffer[1] = program;
break;
case COMBINATION_DATA:
if ( sscanf(what, "%c%03hhd", &bank, &program) != 2 )
return KMX_INVALID_QUERY;
if ( (bank < 'A' || bank > 'C') || program > 127 )
return KMX_INVALID_QUERY;
buffer[0] = 0x20 + (bank - 'A');
buffer[1] = program;
break;
case MULTI_DATA:
if ( sscanf(what, "%02hhd", &program) != 1 || program > 127 )
return KMX_INVALID_QUERY;
buffer[0] = 1;
buffer[1] = program;
break;
case DRUMKIT_DATA:
if ( sscanf(what, "%03hhd", &program) != 1 || program > 39 )
return KMX_INVALID_QUERY;
buffer[0] = 1;
buffer[1] = program;
break;
case ARPEGGIO_DATA:
if ( sscanf(what, "%03hhd", &program) != 1 || program > 250 )
return KMX_INVALID_QUERY;
buffer[0] = 1;
buffer[1] = program >> 7;
buffer[2] = program & 0x7F;
break;
case EXTSET_DATA:
if ( sscanf(what, "%02hhd", &program) != 1 || program > 63 )
return KMX_INVALID_QUERY;
buffer[0] = 1;
buffer[1] = program;
break;
}
return 0;
}
int
kmx_microx_get_program(midi_io_t *midi,
const char *param,
unsigned char *data,
size_t len)
kmx_microx_dump(midi_io_t *midi,
enum kmx_microx_data_type type,
const char *what,
unsigned char *data,
size_t len)
{
size_t n;
int i, j, k;
unsigned char reply[1024], 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 */
0x20, /* Bank number */
0x00, /* Program number */
0x00, /* Unused */
0xF7 /* SysEx message end */ };
if ( len < MICROX_PROGRAM_SIZE )
unsigned char reply[1024];
unsigned char query[] = { 0xF0, /* SysEx message begin */
0x42, /* KORG manufacturer ID */
0x30, /* Global channel */
0x7A, /* End of SysEx header */
0x00, /* Dump type */
0x00, /* Dump parameter 1 */
0x00, /* Dump parameter 2 */
0x00, /* Dump parameter 3 */
0xF7 /* SysEx message end */ };
if ( len < dumps[type].data_size )
return KMX_BUFFER_TOO_SMALL;
if ( sscanf(param, "%c%03hhd", &bank, &program) != 2 )
query[4] = dumps[type].query_code;
if ( get_dump_parameters(type, what, &(query[5])) < 0 )
return KMX_INVALID_QUERY;
query[5] += bank - 'A';
query[6] = program;
if ( (n = midi_write(midi, query, sizeof(query))) < 0 )
return KMX_IO_ERROR;
@ -241,7 +315,7 @@ kmx_microx_get_program(midi_io_t *midi,
if ( j == 0 ) {
/* Check reply header. */
if ( reply[0] != 0xF0 || reply[4] != 0x4C )
if ( reply[0] != 0xF0 || reply[4] != dumps[type].reply_code )
return KMX_INVALID_REPLY;
if ( reply[1] != KORG_ID )
return KMX_NOT_KORG;

19
src/microx.h

@ -59,6 +59,16 @@
(MICROX_N_MULTI * MICROX_MULTI_SIZE) + \
(MICROX_N_EXTSET * MICROX_EXTSET_SIZE))
enum kmx_microx_data_type
{
PROGRAM_DATA = 0,
COMBINATION_DATA,
MULTI_DATA,
DRUMKIT_DATA,
ARPEGGIO_DATA,
EXTSET_DATA
};
struct kmx_microx_version
{
unsigned char major;
@ -148,10 +158,11 @@ const char *
kmx_microx_error(midi_io_t *, int);
int
kmx_microx_get_program(midi_io_t *,
const char *,
unsigned char *,
size_t);
kmx_microx_dump(midi_io_t *,
enum kmx_microx_data_type,
const char *,
unsigned char *,
size_t);
#ifdef __cplusplus
}

Loading…
Cancel
Save