Sysex in serial midi and usbMIDI

Status
Not open for further replies.

sixeight

Well-known member
I am using both Serial Midi and usbMIDI in my project.
For the serial Midi I am using the 4.2 Library of Francois Best.

Now all the Midi commands work, apart from receiving Sysex. Here the libraries are different. In my setup I have included:
usbMIDI.setHandleSysEx(OnSysEx);
MIDI1.setHandleSystemExclusive(OnSerialSysEx);

Because of the differences I want to convert the serial sysex to the usbMidi sysex. But I cannot get this working. Does anyone have any idea how I could fix this? The code is below and does compile with errors:

Error message:
In function 'void OnSerialSysEx(byte*, unsigned int)':
MIDI_in.ino:59:43: warning: 'sxdata_convert' is used uninitialized in this function [-Wuninitialized]

Code:
void OnSerialSysEx(byte *ssxdata, unsigned ssxlength) {
unsigned char* sxdata_convert;
for (uint8_t count = 0; count < ssxlength; count++) {
sxdata_convert[count] = ssxdata[count];
}
OnSysEx(sxdata_convert, ssxlength, true);
}

void OnSysEx(const unsigned char* sxdata, short unsigned int sxlength, bool sx_comp) {
}
 
You would need to allocate some memory buffer for the converted message.

You could do a sxdata_convert = malloc(ssxlength) and free(sxdata_convert) afterwards, BUT a static buffer like unsigned char sxdata_convert[SYSEX_MAX_SIZE] is a better idea, (less overhead and avoids memory fragmentation).

As long as you know the maximum length of a SYSEX message (I'm no MIDI specialist), you should be fine with that.
 
I solved it in the following way:

void OnSysEx(const unsigned char* sxdata, short unsigned int sxlength, bool sx_comp)
{
if (sxdata[1] == 0x41) { //Check if it is a message from a Roland device
check_MIDI_in_GP10(sxdata, sxlength);
check_MIDI_in_GR55(sxdata, sxlength);

}

if (sxdata[1] == 0x7E) { //Check if it is a Universal Non-Real Time message
check_MIDI_in_universal(sxdata, sxlength);
}
}

void OnSerialSysEx(byte *sxdata, unsigned sxlength)
{
if (sxdata[1] == 0x41) { //Check if it is a message from a Roland device
check_MIDI_in_GP10(sxdata, sxlength);
check_MIDI_in_GR55(sxdata, sxlength);

}

if (sxdata[1] == 0x7E) { //Check if it is a Universal Non-Real Time message
check_MIDI_in_universal(sxdata, sxlength);
}
}
 
Status
Not open for further replies.
Back
Top