From 6323ef42f6b0e87b978ef54505c743ca0e274a0f Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Thu, 1 Dec 2022 04:24:23 +0700 Subject: [PATCH] winmidi: fix SysEx messages Tested with Yamaha S-YXG50 software emulation. --- src/i_winmusic.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/i_winmusic.c b/src/i_winmusic.c index e3085909..8a6ec38d 100644 --- a/src/i_winmusic.c +++ b/src/i_winmusic.c @@ -170,6 +170,17 @@ static void WriteBuffer(const byte *ptr, size_t size) buffer.position = round; } +static void WriteByte(const byte c) +{ + if (buffer.position + sizeof(byte) >= buffer.size) + { + AllocateBuffer(buffer.size * 2); + } + + buffer.data[buffer.position] = c; + buffer.position++; +} + static void StreamOut(void) { MIDIHDR *hdr = &MidiStreamHdr; @@ -366,8 +377,7 @@ static void FillBuffer(void) break; case MIDI_EVENT_SYSEX: - case MIDI_EVENT_SYSEX_SPLIT: - data = MAKE_EVT(event->data.sysex.length, 0, 0, MEVT_LONGMSG); + data = MAKE_EVT(event->data.sysex.length + 1, 0, 0, MEVT_LONGMSG); break; } @@ -380,9 +390,9 @@ static void FillBuffer(void) native_event.dwEvent = data; WriteBuffer((byte *)&native_event, sizeof(native_event_t)); - if (event->event_type == MIDI_EVENT_SYSEX || - event->event_type == MIDI_EVENT_SYSEX_SPLIT) + if (event->event_type == MIDI_EVENT_SYSEX) { + WriteByte(MIDI_EVENT_SYSEX); WriteBuffer(event->data.sysex.data, event->data.sysex.length); }