Browse Source

Handle MIDI error when loading data to the microX

master
Damien Goutte-Gattat 9 years ago
parent
commit
b3993da063
  1. 42
      src/microx.c
  2. 7
      src/microx.h

42
src/microx.c

@ -193,6 +193,26 @@ kmx_microx_error(midi_io_t *midi, int e)
msg = "output buffer too small";
break;
case KMX_DEST_MEM_PROTECTED:
msg = "destination memory is write-protected";
break;
case KMX_DEST_PRG_MISSING:
msg = "destination bank/program/parameter does not exist";
break;
case KMX_WRONG_MODE:
msg = "the mode is wrong";
break;
case KMX_MEM_OVERFLOW:
msg = "memory overflow";
break;
case KMX_OTHER_ERROR:
msg = "another error type";
break;
default: /* Should not happen. */
msg = "unknown error";
break;
@ -373,6 +393,7 @@ kmx_microx_load(midi_io_t *midi,
size_t len)
{
size_t n, m;
int status;
unsigned char buffer[256] = { 0xF0, /* Begin SysEx message */
0x42, /* KORG manufacturer ID */
0x30, /* Global channel */
@ -381,6 +402,7 @@ kmx_microx_load(midi_io_t *midi,
0x00, /* Dump parameter 1 */
0x00, /* Dump parameter 2 */
0x00, /* Dump parameter 3 */ };
unsigned char reply[7];
if ( len < dumps[type].data_size )
return KMX_BUFFER_TOO_SMALL;
@ -390,9 +412,9 @@ kmx_microx_load(midi_io_t *midi,
return KMX_INVALID_QUERY;
n = 8;
m = 0;
m = status = 0;
while ( m < len ) {
while ( m < len && status == 0 ) {
/* Convert data from the microX internal representation
* to MIDI format. See comment in kmx_micro_dump above. */
if ( m % 7 == 0 )
@ -401,14 +423,22 @@ kmx_microx_load(midi_io_t *midi,
buffer[n++] = data[m++] & 0x7F;
if ( n == sizeof(buffer) ) {
/* TODO: error check */
midi_write(midi, buffer, n);
if ( midi_write(midi, buffer, n) < 0 )
status = KMX_IO_ERROR;
n = 0;
}
}
buffer[n++] = 0xF7; /* SysEx message end */
midi_write(midi, buffer, n); /* TODO: error check */
if ( (n = sysex_query(midi, buffer, n, reply, sizeof(reply))) < 6 )
status = KMX_IO_ERROR;
return 0;
if ( reply[0] != 0xF0 || reply[1] != KORG_ID || reply[3] != 0x7A )
status = KMX_INVALID_REPLY;
else if ( reply[4] == 0x24 ) /* DATA LOAD ERROR (NAC) */
status = KMX_ERROR_CODE - reply[5];
else if ( reply[4] == 0x23 ) /* DATA LOAD COMPLETED (ACK) */
status = KMX_OK;
return status;
}

7
src/microx.h

@ -27,12 +27,19 @@
#define MICROX_SUB_ID 0x09
/* Error codes. */
#define KMX_OK 0
#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
#define KMX_ERROR_CODE -100
#define KMX_DEST_MEM_PROTECTED KMX_ERROR_CODE
#define KMX_DEST_PRG_MISSING KMX_ERROR_CODE - 1
#define KMX_WRONG_MODE KMX_ERROR_CODE - 2
#define KMX_MEM_OVERFLOW KMX_ERROR_CODE - 3
#define KMX_OTHER_ERROR KMX_ERROR_CODE - 40
/* Numbers of memories. */
#define MICROX_N_PROGRAM 640

Loading…
Cancel
Save