Skip to content

Instantly share code, notes, and snippets.

@YuuichiAkagawa
Created January 20, 2017 14:46
Show Gist options
  • Save YuuichiAkagawa/959002dea3e7ad94c09c76e6fdafb8bc to your computer and use it in GitHub Desktop.
Save YuuichiAkagawa/959002dea3e7ad94c09c76e6fdafb8bc to your computer and use it in GitHub Desktop.
New SysEx example
// Poll USB MIDI Controler and send to serial MIDI
void MIDI_poll()
{
uint8_t size;
uint8_t recvBuf[MIDI_EVENT_PACKET_SIZE];
uint8_t rcode = 0; //return code
uint16_t rcvd;
uint8_t readPtr = 0;
rcode = Midi.RecvData( &rcvd, recvBuf);
//data check
if (rcode != 0) return;
if ( recvBuf[0] == 0 && recvBuf[1] == 0 && recvBuf[2] == 0 && recvBuf[3] == 0 ) {
return ;
}
uint8_t *p = recvBuf;
while (readPtr < MIDI_EVENT_PACKET_SIZE) {
if (*p == 0 && *(p + 1) == 0) break; //data end
uint8_t outbuf[3];
uint8_t rc = sysExData.extract(p, outbuf);
if( rc == 0 ) {
p++;
size = Midi.lookupMsgSize(*p);
_MIDI_SERIAL_PORT.write(p, size);
p += 3;
} else {
_MIDI_SERIAL_PORT.write(outbuf, rc);
p += 4;
}
readPtr += 4;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment