Browse Source

Add function to load programs to the microX

master
Damien Goutte-Gattat 9 years ago
parent
commit
110a175b94
  1. 108
      src/microx.c
  2. 7
      src/microx.h

108
src/microx.c

@ -356,3 +356,111 @@ kmx_microx_dump(midi_io_t *midi,
return j;
}
static int
get_load_parameters(enum kmx_microx_data_type type,
const char *what,
unsigned char *buffer)
{
unsigned char program, bank;
switch ( type ) {
case PROGRAM_DATA:
buffer[0] = 1;
if ( sscanf(what, "%c%03hhd", &bank, &program) != 2 )
return KMX_INVALID_QUERY;
if ( (bank < 'A' || bank > 'E') || program > 127 )
return KMX_INVALID_QUERY;
buffer[1] = 0x20 + (bank - 'A');
buffer[2] = 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[1] = 0x20 + (bank - 'A');
buffer[2] = 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_load(midi_io_t *midi,
enum kmx_microx_data_type type,
const char *what,
unsigned char *data,
size_t len)
{
size_t n, m;
unsigned char buffer[256] = { 0xF0, /* Begin SysEx message */
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 */ };
if ( len < dumps[type].data_size )
return KMX_BUFFER_TOO_SMALL;
buffer[4] = dumps[type].reply_code;
if ( get_load_parameters(type, what, &(buffer[5])) < 0 )
return KMX_INVALID_QUERY;
n = 8;
m = 0;
while ( m < len ) {
/* Convert data from the microX internal representation
* to MIDI format. See comment in kmx_micro_dump above. */
if ( m % 7 == 0 )
buffer[n++] = 0;
buffer[n - (m % 7) - 1] += (data[m] & 0x80) << (m % 7);
buffer[n++] = data[m++] & 0x7F;
if ( n == sizeof(buffer) ) {
/* TODO: error check */
midi_write(midi, buffer, n);
n = 0;
}
}
buffer[n++] = 0xF7; /* SysEx message end */
midi_write(midi, buffer, n); /* TODO: error check */
return 0;
}

7
src/microx.h

@ -164,6 +164,13 @@ kmx_microx_dump(midi_io_t *,
unsigned char *,
size_t);
int
kmx_microx_load(midi_io_t *,
enum kmx_microx_data_type,
const char *,
unsigned char *,
size_t );
#ifdef __cplusplus
}
#endif

Loading…
Cancel
Save