Update serialmididevice.cpp

pull/206/head
arsamus 3 years ago committed by GitHub
parent 3a6111889b
commit cedeeb33dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 54
      src/serialmididevice.cpp

@ -85,6 +85,26 @@ void CSerialMIDIDevice::Process (void)
{ {
u8 uchData = Buffer[i]; u8 uchData = Buffer[i];
if(uchData == 0xF0)
{
// SYSEX found
m_SerialMessage[m_nSysEx++]=uchData;
continue;
}
if(m_nSysEx > 0)
{
m_SerialMessage[m_nSysEx++]=uchData;
if ((uchData & 0x80) == 0x80 || m_nSysEx >= MAX_MIDI_MESSAGE)
{
if(uchData == 0xF7)
MIDIMessageHandler (m_SerialMessage, m_nSysEx);
m_nSysEx = 0;
}
continue;
}
else
{
switch (m_nSerialState) switch (m_nSerialState)
{ {
case 0: case 0:
@ -94,14 +114,6 @@ void CSerialMIDIDevice::Process (void)
{ {
m_SerialMessage[m_nSerialState++] = uchData; m_SerialMessage[m_nSerialState++] = uchData;
} }
if (uchData == 0xF0) // SysEx status Byte jumps to m_nSerialState=5 and iniciate reading
{
m_nSerialState = 5;
m_nSysEx = 0;
goto MIDISysEx;
}
break; break;
case 1: case 1:
@ -123,35 +135,19 @@ void CSerialMIDIDevice::Process (void)
m_nSerialState = 4; // State 4 for test if 4th byte is a status byte or a data byte m_nSerialState = 4; // State 4 for test if 4th byte is a status byte or a data byte
} }
break; break;
case 4: // Running Status evaluation case 4:
if ((uchData & 0x80) == 0) // true data byte, false status byte if ((uchData & 0x80) == 0) // true data byte, false status byte
{ {
m_nSerialState = 1; // Byte 0 not change on Running Status m_nSerialState = 1;
goto DATABytes; goto DATABytes;
} }
else else
{ {
m_nSerialState = 0; m_nSerialState = 0;
goto MIDIRestart; // This is necessary in order to not miss the first byte goto MIDIRestart;
}
break;
case 5: // SyxEx reading
MIDISysEx:
m_SerialMessage[m_nSysEx++] = uchData;
if (((uchData & 0x80) && m_nSysEx > 1 ) || m_nSysEx >= MAX_MIDI_MESSAGE)
{
m_nSerialState = 0; //New Status byte ends SerialState 5 (SysEx reading)
if (uchData == 0xF7)
{
MIDIMessageHandler (m_SerialMessage, m_nSysEx);
}
else
{
goto MIDIRestart; //other status byte abort SysEx process and jump to MIDIRestart in order to not miss the byte
}
} }
break; break;
default: default:
@ -160,7 +156,7 @@ void CSerialMIDIDevice::Process (void)
} }
} }
} }
}
void CSerialMIDIDevice::Send (const u8 *pMessage, size_t nLength, unsigned nCable) void CSerialMIDIDevice::Send (const u8 *pMessage, size_t nLength, unsigned nCable)
{ {
m_SendBuffer.Write (pMessage, nLength); m_SendBuffer.Write (pMessage, nLength);

Loading…
Cancel
Save