From 9a7924a687e5ae53a076de823d34976f99d04421 Mon Sep 17 00:00:00 2001 From: Huw Davies Date: Thu, 28 Apr 2022 08:49:55 -0500 Subject: [PATCH] wineoss: Simplify the midi in dispatcher. The continue statement looks a bit awkward at the moment, but a future patch will introduce more code into the for loop. Signed-off-by: Huw Davies Signed-off-by: Andrew Eikum Signed-off-by: Alexandre Julliard --- dlls/wineoss.drv/midi.c | 42 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/dlls/wineoss.drv/midi.c b/dlls/wineoss.drv/midi.c index fe73d97f5ab..1a5b348da9f 100644 --- a/dlls/wineoss.drv/midi.c +++ b/dlls/wineoss.drv/midi.c @@ -320,12 +320,23 @@ static void midReceiveChar(WORD wDevID, unsigned char value, DWORD dwTime) } } +static void handle_midi_data(unsigned char *buffer, unsigned int len) +{ + unsigned int time = GetTickCount(), i; + + for (i = 0; i < len; i += (buffer[i] & 0x80) ? 8 : 4) + { + if (buffer[i] != SEQ_MIDIPUTC) continue; + + midReceiveChar(buffer[i + 2], buffer[i + 1], time); + } +} + static DWORD WINAPI midRecThread(void *arg) { int fd = (int)(INT_PTR)arg; unsigned char buffer[256]; - int len, idx; - DWORD dwTime; + int len; struct pollfd pfd; TRACE("Thread startup\n"); @@ -349,32 +360,7 @@ static DWORD WINAPI midRecThread(void *arg) continue; } - dwTime = GetTickCount(); - - for (idx = 0; idx < len; ) { - if (buffer[idx] & 0x80) { - TRACE( - "Reading<8> %02x %02x %02x %02x %02x %02x %02x %02x\n", - buffer[idx + 0], buffer[idx + 1], - buffer[idx + 2], buffer[idx + 3], - buffer[idx + 4], buffer[idx + 5], - buffer[idx + 6], buffer[idx + 7]); - idx += 8; - } else { - switch (buffer[idx + 0]) { - case SEQ_WAIT: - case SEQ_ECHO: - break; - case SEQ_MIDIPUTC: - midReceiveChar(buffer[idx + 2], buffer[idx + 1], dwTime); - break; - default: - TRACE("Unsupported event %d\n", buffer[idx + 0]); - break; - } - idx += 4; - } - } + handle_midi_data(buffer, len); } return 0; }