From: Huw Davies huw@codeweavers.com
Signed-off-by: Huw Davies huw@codeweavers.com Signed-off-by: Andrew Eikum aeikum@codeweavers.com ---
v2: Keep old locking order.
dlls/winealsa.drv/alsamidi.c | 35 +++++++++++++++++++++++++++++++++ dlls/winealsa.drv/midi.c | 38 ------------------------------------ 2 files changed, 35 insertions(+), 38 deletions(-)
diff --git a/dlls/winealsa.drv/alsamidi.c b/dlls/winealsa.drv/alsamidi.c index a78102745bc..80e677b3064 100644 --- a/dlls/winealsa.drv/alsamidi.c +++ b/dlls/winealsa.drv/alsamidi.c @@ -852,6 +852,38 @@ static UINT midi_out_reset(WORD dev_id) return MMSYSERR_NOERROR; }
+static UINT midi_in_add_buffer(WORD dev_id, MIDIHDR *hdr, UINT hdr_size) +{ + struct midi_src *src; + MIDIHDR **next; + + TRACE("(%04X, %p, %d);\n", dev_id, hdr, hdr_size); + + if (dev_id >= num_srcs) return MMSYSERR_BADDEVICEID; + src = srcs + dev_id; + if (src->state == -1) return MIDIERR_NODEVICE; + + if (!hdr || hdr_size < offsetof(MIDIHDR, dwOffset) || !hdr->dwBufferLength) + return MMSYSERR_INVALPARAM; + if (hdr->dwFlags & MHDR_INQUEUE) return MIDIERR_STILLPLAYING; + if (!(hdr->dwFlags & MHDR_PREPARED)) return MIDIERR_UNPREPARED; + + in_buffer_lock(); + + hdr->dwFlags &= ~WHDR_DONE; + hdr->dwFlags |= MHDR_INQUEUE; + hdr->dwBytesRecorded = 0; + hdr->lpNext = NULL; + + next = &src->lpQueueHdr; + while (*next) next = &(*next)->lpNext; + *next = hdr; + + in_buffer_unlock(); + + return MMSYSERR_NOERROR; +} + static UINT midi_in_prepare(WORD dev_id, MIDIHDR *hdr, UINT hdr_size) { TRACE("(%04X, %p, %d);\n", dev_id, hdr, hdr_size); @@ -963,6 +995,9 @@ NTSTATUS midi_in_message(void *args) /* FIXME: Pretend this is supported */ *params->err = MMSYSERR_NOERROR; break; + case MIDM_ADDBUFFER: + *params->err = midi_in_add_buffer(params->dev_id, (MIDIHDR *)params->param_1, params->param_2); + break; case MIDM_PREPARE: *params->err = midi_in_prepare(params->dev_id, (MIDIHDR *)params->param_1, params->param_2); break; diff --git a/dlls/winealsa.drv/midi.c b/dlls/winealsa.drv/midi.c index 70e6caebfc7..3665b557d03 100644 --- a/dlls/winealsa.drv/midi.c +++ b/dlls/winealsa.drv/midi.c @@ -459,42 +459,6 @@ static DWORD midClose(WORD wDevID) return ret; }
- -/************************************************************************** - * midAddBuffer [internal] - */ -static DWORD midAddBuffer(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize) -{ - TRACE("(%04X, %p, %d);\n", wDevID, lpMidiHdr, dwSize); - - if (wDevID >= MIDM_NumDevs) return MMSYSERR_BADDEVICEID; - if (MidiInDev[wDevID].state == -1) return MIDIERR_NODEVICE; - - if (lpMidiHdr == NULL) return MMSYSERR_INVALPARAM; - if (dwSize < offsetof(MIDIHDR,dwOffset)) return MMSYSERR_INVALPARAM; - if (lpMidiHdr->dwBufferLength == 0) return MMSYSERR_INVALPARAM; - if (lpMidiHdr->dwFlags & MHDR_INQUEUE) return MIDIERR_STILLPLAYING; - if (!(lpMidiHdr->dwFlags & MHDR_PREPARED)) return MIDIERR_UNPREPARED; - - in_buffer_lock(); - lpMidiHdr->dwFlags &= ~WHDR_DONE; - lpMidiHdr->dwFlags |= MHDR_INQUEUE; - lpMidiHdr->dwBytesRecorded = 0; - lpMidiHdr->lpNext = 0; - if (MidiInDev[wDevID].lpQueueHdr == 0) { - MidiInDev[wDevID].lpQueueHdr = lpMidiHdr; - } else { - LPMIDIHDR ptr; - - for (ptr = MidiInDev[wDevID].lpQueueHdr; ptr->lpNext != 0; - ptr = ptr->lpNext); - ptr->lpNext = lpMidiHdr; - } - in_buffer_unlock(); - - return MMSYSERR_NOERROR; -} - /************************************************************************** * midReset [internal] */ @@ -593,8 +557,6 @@ DWORD WINAPI ALSA_midMessage(UINT wDevID, UINT wMsg, DWORD_PTR dwUser, return midOpen(wDevID, (LPMIDIOPENDESC)dwParam1, dwParam2); case MIDM_CLOSE: return midClose(wDevID); - case MIDM_ADDBUFFER: - return midAddBuffer(wDevID, (LPMIDIHDR)dwParam1, dwParam2); case MIDM_RESET: return midReset(wDevID); case MIDM_START: