|
|
@ -37,6 +37,7 @@ TMIDIPacketHandler * const CMIDIKeyboard::s_pMIDIPacketHandler[MaxInstances] = |
|
|
|
|
|
|
|
|
|
|
|
CMIDIKeyboard::CMIDIKeyboard (CMiniDexed *pSynthesizer, CConfig *pConfig, CUserInterface *pUI, unsigned nInstance) |
|
|
|
CMIDIKeyboard::CMIDIKeyboard (CMiniDexed *pSynthesizer, CConfig *pConfig, CUserInterface *pUI, unsigned nInstance) |
|
|
|
: CMIDIDevice (pSynthesizer, pConfig, pUI), |
|
|
|
: CMIDIDevice (pSynthesizer, pConfig, pUI), |
|
|
|
|
|
|
|
m_nSysExIdx (0), |
|
|
|
m_nInstance (nInstance), |
|
|
|
m_nInstance (nInstance), |
|
|
|
m_pMIDIDevice (0) |
|
|
|
m_pMIDIDevice (0) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -100,28 +101,86 @@ void CMIDIKeyboard::Send (const u8 *pMessage, size_t nLength, unsigned nCable) |
|
|
|
m_SendQueue.push (Entry); |
|
|
|
m_SendQueue.push (Entry); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Most packets will be passed straight onto the main MIDI message handler
|
|
|
|
|
|
|
|
// but SysEx messages are multiple USB packets and so will need building up
|
|
|
|
|
|
|
|
// before parsing.
|
|
|
|
|
|
|
|
void CMIDIKeyboard::USBMIDIMessageHandler (u8 *pPacket, unsigned nLength, unsigned nCable) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if ((pPacket[0] == 0xF0) && (m_nSysExIdx == 0)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Start of SysEx message
|
|
|
|
|
|
|
|
//printf("SysEx Start Idx=%d, (%d)\n", m_nSysExIdx, nLength);
|
|
|
|
|
|
|
|
for (unsigned i=0; i<USB_SYSEX_BUFFER_SIZE; i++) { |
|
|
|
|
|
|
|
m_SysEx[i] = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for (unsigned i=0; i<nLength; i++) { |
|
|
|
|
|
|
|
m_SysEx[m_nSysExIdx++] = pPacket[i]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (m_nSysExIdx != 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Continue processing SysEx message
|
|
|
|
|
|
|
|
//printf("SysEx Packet Idx=%d, (%d)\n", m_nSysExIdx, nLength);
|
|
|
|
|
|
|
|
for (unsigned i=0; i<nLength; i++) { |
|
|
|
|
|
|
|
if (pPacket[i] == 0xF8 || pPacket[i] == 0xFA || pPacket[i] == 0xFB || pPacket[i] == 0xFC || pPacket[i] == 0xFE || pPacket[i] == 0xFF) { |
|
|
|
|
|
|
|
// Singe-byte System Realtime Messages can happen at any time!
|
|
|
|
|
|
|
|
MIDIMessageHandler (&pPacket[i], 1, nCable); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (m_nSysExIdx >= USB_SYSEX_BUFFER_SIZE) { |
|
|
|
|
|
|
|
// Run out of space, so reset and ignore rest of the message
|
|
|
|
|
|
|
|
m_nSysExIdx = 0; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (pPacket[i] == 0xF7) { |
|
|
|
|
|
|
|
// End of SysEx message
|
|
|
|
|
|
|
|
m_SysEx[m_nSysExIdx++] = pPacket[i]; |
|
|
|
|
|
|
|
//printf ("SysEx End Idx=%d\n", m_nSysExIdx);
|
|
|
|
|
|
|
|
MIDIMessageHandler (m_SysEx, m_nSysExIdx, nCable); |
|
|
|
|
|
|
|
// Reset ready for next time
|
|
|
|
|
|
|
|
m_nSysExIdx = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if ((pPacket[i] & 0x80) != 0) { |
|
|
|
|
|
|
|
// Received another command, so reset processing as something has gone wrong
|
|
|
|
|
|
|
|
//printf ("SysEx Reset\n");
|
|
|
|
|
|
|
|
m_nSysExIdx = 0; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Store the byte
|
|
|
|
|
|
|
|
m_SysEx[m_nSysExIdx++] = pPacket[i]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Assume it is a standard message
|
|
|
|
|
|
|
|
MIDIMessageHandler (pPacket, nLength, nCable); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void CMIDIKeyboard::MIDIPacketHandler0 (unsigned nCable, u8 *pPacket, unsigned nLength) |
|
|
|
void CMIDIKeyboard::MIDIPacketHandler0 (unsigned nCable, u8 *pPacket, unsigned nLength) |
|
|
|
{ |
|
|
|
{ |
|
|
|
assert (s_pThis[0] != 0); |
|
|
|
assert (s_pThis[0] != 0); |
|
|
|
s_pThis[0]->MIDIMessageHandler (pPacket, nLength, nCable); |
|
|
|
s_pThis[0]->USBMIDIMessageHandler (pPacket, nLength, nCable); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void CMIDIKeyboard::MIDIPacketHandler1 (unsigned nCable, u8 *pPacket, unsigned nLength) |
|
|
|
void CMIDIKeyboard::MIDIPacketHandler1 (unsigned nCable, u8 *pPacket, unsigned nLength) |
|
|
|
{ |
|
|
|
{ |
|
|
|
assert (s_pThis[1] != 0); |
|
|
|
assert (s_pThis[1] != 0); |
|
|
|
s_pThis[1]->MIDIMessageHandler (pPacket, nLength, nCable); |
|
|
|
s_pThis[1]->USBMIDIMessageHandler (pPacket, nLength, nCable); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void CMIDIKeyboard::MIDIPacketHandler2 (unsigned nCable, u8 *pPacket, unsigned nLength) |
|
|
|
void CMIDIKeyboard::MIDIPacketHandler2 (unsigned nCable, u8 *pPacket, unsigned nLength) |
|
|
|
{ |
|
|
|
{ |
|
|
|
assert (s_pThis[2] != 0); |
|
|
|
assert (s_pThis[2] != 0); |
|
|
|
s_pThis[2]->MIDIMessageHandler (pPacket, nLength, nCable); |
|
|
|
s_pThis[2]->USBMIDIMessageHandler (pPacket, nLength, nCable); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void CMIDIKeyboard::MIDIPacketHandler3 (unsigned nCable, u8 *pPacket, unsigned nLength) |
|
|
|
void CMIDIKeyboard::MIDIPacketHandler3 (unsigned nCable, u8 *pPacket, unsigned nLength) |
|
|
|
{ |
|
|
|
{ |
|
|
|
assert (s_pThis[3] != 0); |
|
|
|
assert (s_pThis[3] != 0); |
|
|
|
s_pThis[3]->MIDIMessageHandler (pPacket, nLength, nCable); |
|
|
|
s_pThis[3]->USBMIDIMessageHandler (pPacket, nLength, nCable); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void CMIDIKeyboard::DeviceRemovedHandler (CDevice *pDevice, void *pContext) |
|
|
|
void CMIDIKeyboard::DeviceRemovedHandler (CDevice *pDevice, void *pContext) |
|
|
|