Browse Source

Add a generic function to read MicroX dump data

develop
Damien Goutte-Gattat 8 years ago
parent
commit
0302711766
  1. 66
      src/microx.c
  2. 6
      src/microx.h

66
src/microx.c

@ -304,36 +304,16 @@ get_dump_parameters(enum kmx_microx_data_type type,
}
int
kmx_microx_dump(midi_io_t *midi,
enum kmx_microx_data_type type,
const char *what,
unsigned char *data,
size_t len)
kmx_microx_read_dump(midi_io_t *midi,
unsigned char reply_code,
unsigned char *data,
size_t len)
{
size_t n;
int i, j, k, m;
unsigned char i, j, k ,m;
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;
query[4] = dumps[type].query_code;
if ( get_dump_parameters(type, what, &(query[5]), 0) < 0 )
return KMX_INVALID_QUERY;
if ( (n = midi_write(midi, query, sizeof(query))) < 0 )
return KMX_IO_ERROR;
i = j = k = 0;
j = k = m = 0;
do {
if ( (n = sysex_read(midi, reply, sizeof(reply))) < 0 )
@ -342,9 +322,8 @@ kmx_microx_dump(midi_io_t *midi,
i = 0;
if ( j == 0 ) {
/* Check reply header. */
if ( reply[0] != 0xF0 || reply[4] != dumps[type].reply_code )
if ( reply[0] != 0xF0 || reply[4] != reply_code )
return KMX_INVALID_REPLY;
if ( reply[1] != KORG_ID )
return KMX_NOT_KORG;
@ -384,6 +363,37 @@ kmx_microx_dump(midi_io_t *midi,
return j - 1; /* Remove SysEx terminating byte. */
}
int
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;
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;
query[4] = dumps[type].query_code;
if ( get_dump_parameters(type, what, &(query[5]), 0) < 0 )
return KMX_INVALID_QUERY;
if ( (n = midi_write(midi, query, sizeof(query))) < 0 )
return KMX_IO_ERROR;
return kmx_microx_read_dump(midi, dumps[type].reply_code, data, len);
}
int
kmx_microx_load(midi_io_t *midi,
enum kmx_microx_data_type type,

6
src/microx.h

@ -164,6 +164,12 @@ kmx_microx_query_status(midi_io_t *, struct kmx_microx_status *);
const char *
kmx_microx_error(midi_io_t *, int);
int
kmx_microx_read_dump(midi_io_t *,
unsigned char,
unsigned char *,
size_t);
int
kmx_microx_dump(midi_io_t *,
enum kmx_microx_data_type,

Loading…
Cancel
Save