Skip to content

Commit

Permalink
Check for a valid status byte in SendMidiMessage from wdmaud2.drv
Browse files Browse the repository at this point in the history
  • Loading branch information
Psychlist1972 committed Feb 9, 2025
1 parent 8280193 commit 0ff58e4
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions src/api/Client/WinMM/MidiSrvPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,22 +728,32 @@ CMidiPort::SendMidiMessage(UINT32 midiMessage)
byte status = midiMessage & 0x000000FF;
//byte* messagePointer = (byte*)(&midiMessage);

if (MIDI_MESSAGE_IS_ONE_BYTE(status))
// if it's a valid status byte, then figure
// out the actual size of the message. If it's
// not a valid status byte, then we just drop it
if (MIDI_BYTE_IS_STATUS_BYTE(status))
{
messageSize = 1;
}
else if (MIDI_MESSAGE_IS_TWO_BYTES(status))
{
messageSize = 2;
if (MIDI_MESSAGE_IS_ONE_BYTE(status))
{
messageSize = 1;
}
else if (MIDI_MESSAGE_IS_TWO_BYTES(status))
{
messageSize = 2;
}
else if (MIDI_MESSAGE_IS_THREE_BYTES(status))
{
messageSize = 3;
}

// send the message to the transport
// pass a timestamp of 0 to bypass scheduler
RETURN_IF_FAILED(m_MidisrvTransport->SendMidiMessage(&midiMessage, messageSize, 0));
}
else if (MIDI_MESSAGE_IS_THREE_BYTES(status))
else
{
messageSize = 3;
return E_INVALIDARG;
}

// send the message to the transport
// pass a timestamp of 0 to bypass scheduler
RETURN_IF_FAILED(m_MidisrvTransport->SendMidiMessage(&midiMessage, messageSize, 0));
}

return S_OK;
Expand Down Expand Up @@ -789,7 +799,8 @@ CMidiPort::SendLongMessage(LPMIDIHDR buffer)
// TODO: based on the buffer length, this message may require chunking into smaller
// pieces to ensure it fits into the cross process queue.
//
RETURN_IF_FAILED(m_MidisrvTransport->SendMidiMessage(buffer->lpData, buffer->dwBytesRecorded, 0));
//RETURN_IF_FAILED(m_MidisrvTransport->SendMidiMessage(buffer->lpData, buffer->dwBytesRecorded, 0));
RETURN_IF_FAILED(m_MidisrvTransport->SendMidiMessage(buffer->lpData, buffer->dwBufferLength, 0));
}

// mark the buffer as completed
Expand Down

0 comments on commit 0ff58e4

Please sign in to comment.