Browse Source

Fix MIDI-to-microX data conversion

The precedent conversion code was completely wrong, due to a
miunderstanding of the microX MIDI spec. The conversion is a bit
more complicated than I thought. The current code is a quick and
dirty implementation of a correct conversion. It is very ugly,
but I wanted to document and commit that before I forget how the
conversion is supposed to be done.
master
Damien Goutte-Gattat 9 years ago
parent
commit
aefe0869e2
  1. 34
      src/microx.c

34
src/microx.c

@ -283,7 +283,7 @@ kmx_microx_dump(midi_io_t *midi,
size_t len)
{
size_t n;
int i, j, k;
int i, j, k, m;
unsigned char reply[1024];
unsigned char query[] = { 0xF0, /* SysEx message begin */
0x42, /* KORG manufacturer ID */
@ -329,15 +329,37 @@ kmx_microx_dump(midi_io_t *midi,
/*
* 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.
* and copy it to the caller's buffer. When transmitting its
* data, the microX converts a group of seven 8-bits bytes
* into eight MIDI bytes, where the first byte is used to
* encode the value of the 8th bit of each following byte.
*
* For example, consider the following byte sequence in the
* transmitted MIDI data (all numbers hexadecimal):
*
* 20 00 00 00 06 0e 16 00
*
* The first byte has the 6th bit set. It means that in the
* microX internal representation, the sixth byte of that
* group has its 8th bit set; so the real value of that byte
* is not 16, as transmitted, but 96.
*
* FIXME: The following conversion code is really ugly.
*/
for ( ; i < n; i++, k++ ) {
if ( k % 8 != 0 )
data[j++] = reply[i];
if ( k % 8 == 0 ) {
for ( m = 0; m < 7; m++ ) {
if ( (reply[i] >> m) & 0x1 )
data[j+m] = 0x80;
else
data[j+m] = 0;
}
}
else
data[j++] += reply[i];
}
} while ( reply[n-1] != 0xF7 );
return j;
}
Loading…
Cancel
Save