Browse Source

Add program dumping function

master
Damien Goutte-Gattat 9 years ago
parent
commit
46037d8bfa
  1. 77
      src/microx.c
  2. 41
      src/microx.h

77
src/microx.c

@ -20,6 +20,8 @@
#include <config.h>
#endif
#include <stdio.h>
#include <microx.h>
#include <sysex.h>
@ -182,6 +184,14 @@ kmx_microx_error(midi_io_t *midi, int e)
case KMX_NOT_MICROX:
msg = "not a microX device";
case KMX_INVALID_QUERY:
msg = "invalid query";
break;
case KMX_BUFFER_TOO_SMALL:
msg = "output buffer too small";
break;
default: /* Should not happen. */
msg = "unknown error";
break;
@ -189,3 +199,70 @@ kmx_microx_error(midi_io_t *midi, int e)
return msg;
}
int
kmx_microx_get_program(midi_io_t *midi,
const char *param,
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 )
return KMX_BUFFER_TOO_SMALL;
if ( sscanf(param, "%c%03hhd", &bank, &program) != 2 )
return KMX_INVALID_QUERY;
query[5] += bank - 'A';
query[6] = program;
if ( (n = midi_write(midi, query, sizeof(query))) < 0 )
return KMX_IO_ERROR;
i = j = k = 0;
do {
if ( (n = sysex_read(midi, reply, sizeof(reply))) < 0 )
return KMX_IO_ERROR;
i = 0;
if ( j == 0 ) {
/* Check reply header. */
if ( reply[0] != 0xF0 || reply[4] != 0x4C )
return KMX_INVALID_REPLY;
if ( reply[1] != KORG_ID )
return KMX_NOT_KORG;
if ( reply[3] != MICROX_ID )
return KMX_NOT_MICROX;
/* Skip reply header. */
i = 8;
}
/*
* Convert data back to the microX internal representation
* and copy it to the caller's buffer. The conversion
* consists simply in skipping the null byte inserted
* every 7 data bytes.
*/
for ( ; i < n; i++, k++ ) {
if ( k % 8 != 0 )
data[j++] = reply[i];
}
} while ( reply[n-1] != 0xF7 );
return j;
}

41
src/microx.h

@ -27,10 +27,37 @@
#define MICROX_SUB_ID 0x09
/* Error codes. */
#define KMX_IO_ERROR -1
#define KMX_INVALID_REPLY -2
#define KMX_NOT_KORG -3
#define KMX_NOT_MICROX -4
#define KMX_IO_ERROR -1
#define KMX_INVALID_REPLY -2
#define KMX_NOT_KORG -3
#define KMX_NOT_MICROX -4
#define KMX_INVALID_QUERY -10
#define KMX_BUFFER_TOO_SMALL -11
/* Numbers of memories. */
#define MICROX_N_PROGRAM 640
#define MICROX_N_COMBINATION 384
#define MICROX_N_MULTI 128
#define MICROX_N_DRUMKIT 40
#define MICROX_N_ARPEGGIO 251
#define MICROX_N_EXTSET 64
/* Size of memories. */
#define MICROX_PROGRAM_SIZE 444
#define MICROX_COMBINATION_SIZE 544
#define MICROX_MULTI_SIZE 1220
#define MICROX_GLOBAL_SIZE 850
#define MICROX_DRUMKIT_SIZE 4112
#define MICROX_ARPEGGIO_SIZE 320
#define MICROX_EXTSET_SIZE 40
#define MICROX_ALLDATA_SIZE \
(MICROX_GLOBAL_SIZE + \
(MICROX_N_DRUMKIT * MICROX_DRUMKIT_SIZE) + \
(MICROX_N_ARPEGGIO * MICROX_ARPEGGIO_SIZE) + \
(MICROX_N_COMBINATION * MICROX_COMBINATION_SIZE) + \
(MICROX_N_PROGRAM * MICROX_PROGRAM_SIZE) + \
(MICROX_N_MULTI * MICROX_MULTI_SIZE) + \
(MICROX_N_EXTSET * MICROX_EXTSET_SIZE))
struct kmx_microx_version
{
@ -120,6 +147,12 @@ kmx_microx_query_status(midi_io_t *, struct kmx_microx_status *);
const char *
kmx_microx_error(midi_io_t *, int);
int
kmx_microx_get_program(midi_io_t *,
const char *,
unsigned char *,
size_t);
#ifdef __cplusplus
}
#endif

Loading…
Cancel
Save