Browse Source

Do not hardcode global MIDI channel

Do not assume the global MIDI channel is always the first channel.
Use instead the channel returned by the DEVICE INQUIRY reply
message when identifying the microX.
develop
Damien Goutte-Gattat 5 years ago
parent
commit
3b27931214
  1. 11
      src/kmxtool.c
  2. 23
      src/microx.c
  3. 10
      src/microx.h
  4. 2
      src/sysex.c
  5. 3
      src/sysex.h

11
src/kmxtool.c

@ -38,6 +38,7 @@
/* Globals. */
static midi_io_t *midi = NULL;
static unsigned channel = 0;
/* Help and informations about the program. */
@ -167,7 +168,7 @@ do_list_programs(midi_io_t *midi)
if ( ! (reply = malloc(len)) )
err(EXIT_FAILURE, "cannot dump data");
if ( (n = kmx_microx_dump(midi, &dump, reply, len)) < 0 )
if ( (n = kmx_microx_dump(midi, channel, &dump, reply, len)) < 0 )
errx(EXIT_FAILURE, "cannot dump data: %s", kmx_microx_error(midi, n));
for ( cursor = reply, bank = 'A'; bank < 'F'; bank++ ) {
@ -194,7 +195,7 @@ find_microx_on_port(const char *port,
ret = -1;
if ( (midi = midi_open(port)) != NULL ) {
if ( (e = kmx_microx_identify(midi, version)) == 0 )
if ( (e = kmx_microx_identify(midi, version, &channel)) == 0 )
ret = 0;
else {
midi_close(midi);
@ -305,7 +306,7 @@ main(int argc, char **argv)
printf("KORG microX synthesizer, version %02d.%02d.%02d.%02d\n",
version.major, version.minor, version.release, version.build);
if ( (e = kmx_microx_query_status(midi, &status)) < 0 )
if ( (e = kmx_microx_query_status(midi, channel, &status)) < 0 )
errx(EXIT_FAILURE, "cannot query microX status: %s",
kmx_microx_error(midi, e));
@ -323,7 +324,7 @@ main(int argc, char **argv)
if ( ! (data = malloc(n)) )
err(EXIT_FAILURE, "cannot dump data");
if ( (n = kmx_microx_dump(midi, &dump, data, n)) < 0 )
if ( (n = kmx_microx_dump(midi, channel, &dump, data, n)) < 0 )
errx(EXIT_FAILURE, "cannot dump data: %s",
kmx_microx_error(midi, n));
@ -342,7 +343,7 @@ main(int argc, char **argv)
if ( n < 1 )
err(EXIT_FAILURE, "cannot read data");
if ( (n = kmx_microx_load(midi, &dump, data, n)) < 0 )
if ( (n = kmx_microx_load(midi, channel, &dump, data, n)) < 0 )
errx(EXIT_FAILURE, "cannot load data: %s",
kmx_microx_error(midi, n));
}

23
src/microx.c

@ -41,6 +41,9 @@
* @param[out] version A pointer to a kmx_microx_version structure
* to be filled in with informations from the
* device; may be @c NULL.
* @param[out] global A pointer to an integer to receive the
* global MIDI channel used by the microX;
* may be @c NULL.
*
* @return
* - @e KMX_OK if the port is connected to a device which
@ -54,7 +57,8 @@
*/
int
kmx_microx_identify(midi_io_t *midi,
struct kmx_microx_version *version)
struct kmx_microx_version *version,
unsigned int *global)
{
int n;
midi_device_id_t devid;
@ -77,6 +81,9 @@ kmx_microx_identify(midi_io_t *midi,
version->build = (devid.version >> 24) & 0xFF;
}
if ( global )
*global = devid.global_channel;
return KMX_OK;
}
@ -86,6 +93,7 @@ kmx_microx_identify(midi_io_t *midi,
* synthesizer.
*
* @param[in] midi The MIDI port.
* @param[int] chan The global MIDI channel.
* @param[out] status A pointer to a kmx_microx_status structure
* to be filled in with the status data
* received from the microX; may be @c NULL.
@ -98,6 +106,7 @@ kmx_microx_identify(midi_io_t *midi,
*/
int
kmx_microx_query_status(midi_io_t *midi,
unsigned int chan,
struct kmx_microx_status *s)
{
ssize_t n;
@ -109,6 +118,10 @@ kmx_microx_query_status(midi_io_t *midi,
0x12, /* Mode and state request */
0xF7 /* SysEx message end */ };
fprintf(stderr, "querying status on channel %d\n", chan);
query[2] |= chan & 0xF;
if ( (n = sysex_query(midi, query, sizeof(query),
reply, sizeof(reply))) == -1 )
return KMX_IO_ERROR;
@ -698,6 +711,7 @@ kmx_microx_read_dump(midi_io_t *midi,
* in reply.
*
* @param[in] midi The MIDI port.
* @param[in] chan The global MIDI channel.
* @param[in] dump A kmx_microx_dump structure representing
* the dump request.
* @param[out] data The buffer where to store the dump.
@ -715,6 +729,7 @@ kmx_microx_read_dump(midi_io_t *midi,
*/
int
kmx_microx_dump(midi_io_t *midi,
unsigned int chan,
struct kmx_microx_dump *dump,
unsigned char *data,
size_t len)
@ -730,6 +745,8 @@ kmx_microx_dump(midi_io_t *midi,
0x00, /* Dump parameter 3 */
0xF7 /* SysEx message end */ };
query[2] |= chan & 0xF;
if ( get_dump_parameters(dump, &(query[4])) == KMX_INVALID_QUERY )
return KMX_INVALID_QUERY;
@ -748,6 +765,7 @@ kmx_microx_dump(midi_io_t *midi,
* the microX synthesizer.
*
* @param[in] midi The MIDI port.
* @param[in] chan The global MIDI channel.
* @param[in] dump A kmx_microx_dump structure indicating the
* memory slot to load the data into.
* @param[in] data The data to load.
@ -771,6 +789,7 @@ kmx_microx_dump(midi_io_t *midi,
*/
int
kmx_microx_load(midi_io_t *midi,
unsigned int chan,
struct kmx_microx_dump *dump,
unsigned char *data,
size_t len)
@ -787,6 +806,8 @@ kmx_microx_load(midi_io_t *midi,
0x00, /* Dump parameter 3 */ };
unsigned char reply[7];
buffer[2] |= chan & 0xF;
if ( get_dump_parameters(dump, &(buffer[4])) == KMX_INVALID_QUERY )
return KMX_INVALID_QUERY;

10
src/microx.h

@ -185,10 +185,14 @@ extern "C" {
#endif
int
kmx_microx_identify(midi_io_t *, struct kmx_microx_version *);
kmx_microx_identify(midi_io_t *,
struct kmx_microx_version *,
unsigned int *);
int
kmx_microx_query_status(midi_io_t *, struct kmx_microx_status *);
kmx_microx_query_status(midi_io_t *,
unsigned int,
struct kmx_microx_status *);
const char *
kmx_microx_error(midi_io_t *, int);
@ -208,12 +212,14 @@ kmx_microx_read_dump(midi_io_t *,
int
kmx_microx_dump(midi_io_t *,
unsigned int,
struct kmx_microx_dump *,
unsigned char *,
size_t);
int
kmx_microx_load(midi_io_t *,
unsigned int,
struct kmx_microx_dump *,
unsigned char *,
size_t );

2
src/sysex.c

@ -183,6 +183,8 @@ sysex_identify(midi_io_t *midi, midi_device_id_t *devid)
/* invalid reply */
return 0;
devid->global_channel = reply[2] & 0xF;
p = &reply[5];
devid->manufacturer = *p++;
if ( devid->manufacturer == 0x00 ) { /* extended manufacturer ID */

3
src/sysex.h

@ -42,6 +42,9 @@ typedef struct midi_device_id
/** A version number for the device. */
unsigned int version;
/** The global MIDI channel used by this device. */
unsigned int global_channel;
} midi_device_id_t;
#ifdef __cpluscplus

Loading…
Cancel
Save