diff --git a/dlls/winmm/message16.c b/dlls/winmm/message16.c index b6041e269b7..fc455b43c17 100644 --- a/dlls/winmm/message16.c +++ b/dlls/winmm/message16.c @@ -314,18 +314,18 @@ static void MMSYSTDRV_MidiIn_MapCB(UINT uMsg, DWORD_PTR* dwUser, DW * ================================= */ /************************************************************************** - * MMDRV_MidiOut_Map16To32W [internal] + * MMSYSTDRV_MidiOut_Map16To32W [internal] */ -static WINMM_MapType MMDRV_MidiOut_Map16To32W (UINT wMsg, DWORD_PTR *lpdwUser, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2) +static MMSYSTEM_MapType MMSYSTDRV_MidiOut_Map16To32W (UINT wMsg, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2) { - WINMM_MapType ret = WINMM_MAP_MSGERROR; + MMSYSTEM_MapType ret = MMSYSTEM_MAP_MSGERROR; switch (wMsg) { case MODM_GETNUMDEVS: case MODM_DATA: case MODM_RESET: case MODM_SETVOLUME: - ret = WINMM_MAP_OK; + ret = MMSYSTEM_MAP_OK; break; case MODM_OPEN: @@ -345,9 +345,9 @@ static WINMM_MapType MMDRV_MidiOut_Map16To32W (UINT wMsg, DWORD_PTR *lpdwUser, *lpParam1 = (DWORD)moc32; *lpParam2 = sizeof(MIDIOUTCAPSW); - ret = WINMM_MAP_OKMEM; + ret = MMSYSTEM_MAP_OKMEM; } else { - ret = WINMM_MAP_NOMEM; + ret = MMSYSTEM_MAP_NOMEM; } } break; @@ -373,9 +373,9 @@ static WINMM_MapType MMDRV_MidiOut_Map16To32W (UINT wMsg, DWORD_PTR *lpdwUser, *lpParam1 = (DWORD)mh32; *lpParam2 = sizeof(MIDIHDR); - ret = WINMM_MAP_OKMEM; + ret = MMSYSTEM_MAP_OKMEM; } else { - ret = WINMM_MAP_NOMEM; + ret = MMSYSTEM_MAP_NOMEM; } } break; @@ -393,7 +393,7 @@ static WINMM_MapType MMDRV_MidiOut_Map16To32W (UINT wMsg, DWORD_PTR *lpdwUser, mh32->dwBufferLength, mh16->dwBufferLength); } else mh32->dwBufferLength = mh16->dwBufferLength; - ret = WINMM_MAP_OKMEM; + ret = MMSYSTEM_MAP_OKMEM; } break; @@ -407,18 +407,18 @@ static WINMM_MapType MMDRV_MidiOut_Map16To32W (UINT wMsg, DWORD_PTR *lpdwUser, } /************************************************************************** - * MMDRV_MidiOut_UnMap16To32W [internal] + * MMSYSTDRV_MidiOut_UnMap16To32W [internal] */ -static WINMM_MapType MMDRV_MidiOut_UnMap16To32W(UINT wMsg, DWORD_PTR *lpdwUser, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2, MMRESULT fn_ret) +static MMSYSTEM_MapType MMSYSTDRV_MidiOut_UnMap16To32W(UINT wMsg, DWORD_PTR* lpParam1, DWORD_PTR* lpParam2, MMRESULT fn_ret) { - WINMM_MapType ret = WINMM_MAP_MSGERROR; + MMSYSTEM_MapType ret = MMSYSTEM_MAP_MSGERROR; switch (wMsg) { case MODM_GETNUMDEVS: case MODM_DATA: case MODM_RESET: case MODM_SETVOLUME: - ret = WINMM_MAP_OK; + ret = MMSYSTEM_MAP_OK; break; case MODM_OPEN: @@ -443,7 +443,7 @@ static WINMM_MapType MMDRV_MidiOut_UnMap16To32W(UINT wMsg, DWORD_PTR *lpdwUser, moc16->wChannelMask = moc32->wChannelMask; moc16->dwSupport = moc32->dwSupport; HeapFree(GetProcessHeap(), 0, (LPSTR)moc32 - sizeof(LPMIDIOUTCAPS16)); - ret = WINMM_MAP_OK; + ret = MMSYSTEM_MAP_OK; } break; case MODM_PREPARE: @@ -465,7 +465,7 @@ static WINMM_MapType MMDRV_MidiOut_UnMap16To32W(UINT wMsg, DWORD_PTR *lpdwUser, HeapFree(GetProcessHeap(), 0, (LPSTR)mh32 - sizeof(LPMIDIHDR)); mh16->lpNext = 0; } - ret = WINMM_MAP_OK; + ret = MMSYSTEM_MAP_OK; } break; @@ -739,6 +739,34 @@ static void CALLBACK MMDRV_MidiOut_Callback(HDRVR hDev, UINT uMsg, DWORD_PTR dw MMDRV_Callback(mld, hDev, uMsg, dwParam1, dwParam2); } +/****************************************************************** + * MMSYSTDRV_MidiOut_MapCB + */ +static void MMSYSTDRV_MidiOut_MapCB(UINT uMsg, DWORD_PTR* dwUser, DWORD_PTR* dwParam1, DWORD_PTR* dwParam2) +{ + switch (uMsg) { + case MOM_OPEN: + case MOM_CLOSE: + /* dwParam1 & dwParam2 are supposed to be 0, nothing to do */ + break; + case MOM_DONE: + { + /* initial map is: 16 => 32 */ + LPMIDIHDR mh32 = (LPMIDIHDR)(*dwParam1); + SEGPTR segmh16 = *(SEGPTR*)((LPSTR)mh32 - sizeof(LPMIDIHDR)); + LPMIDIHDR mh16 = MapSL(segmh16); + + *dwParam1 = (DWORD)segmh16; + mh16->dwFlags = mh32->dwFlags; + if (mh16->reserved >= sizeof(MIDIHDR)) + mh16->dwOffset = mh32->dwOffset; + } + break; + default: + ERR("Unknown msg %u\n", uMsg); + } +} + /* ================================= * W A V E I N M A P P E R S * ================================= */ @@ -2580,6 +2608,8 @@ static WINMM_MapType MMDRV_UnMap16To32W(UINT wMsg, DWORD_PTR *lpdwUser, DWORD_P #define MMDRV_Mixer_UnMap16To32W MMDRV_UnMap16To32W #define MMDRV_MidiIn_Map16To32W MMDRV_Map16To32W #define MMDRV_MidiIn_UnMap16To32W MMDRV_UnMap16To32W +#define MMDRV_MidiOut_Map16To32W MMDRV_Map16To32W +#define MMDRV_MidiOut_UnMap16To32W MMDRV_UnMap16To32W void MMDRV_Init16(void) { @@ -2637,6 +2667,7 @@ static struct MMSYSTDRV_Type { {MMSYSTDRV_Mixer_Map16To32W, MMSYSTDRV_Mixer_UnMap16To32W, MMSYSTDRV_Mixer_MapCB}, {MMSYSTDRV_MidiIn_Map16To32W, MMSYSTDRV_MidiIn_UnMap16To32W, MMSYSTDRV_MidiIn_MapCB}, + {MMSYSTDRV_MidiOut_Map16To32W, MMSYSTDRV_MidiOut_UnMap16To32W, MMSYSTDRV_MidiOut_MapCB}, }; /****************************************************************** diff --git a/dlls/winmm/mmsystem.c b/dlls/winmm/mmsystem.c index 564fbf41613..00a185982af 100644 --- a/dlls/winmm/mmsystem.c +++ b/dlls/winmm/mmsystem.c @@ -595,12 +595,25 @@ UINT16 WINAPI midiOutGetErrorText16(UINT16 uError, LPSTR lpText, UINT16 uSize) UINT16 WINAPI midiOutOpen16(HMIDIOUT16* lphMidiOut, UINT16 uDeviceID, DWORD dwCallback, DWORD dwInstance, DWORD dwFlags) { - HMIDIOUT hmo; - UINT ret; + HMIDIOUT hmo; + UINT ret; + struct mmsystdrv_thunk* thunk; - ret = MIDI_OutOpen(&hmo, uDeviceID, dwCallback, dwInstance, dwFlags, FALSE); - - if (lphMidiOut != NULL) *lphMidiOut = HMIDIOUT_16(hmo); + if (!(thunk = MMSYSTDRV_AddThunk(dwCallback, MMSYSTDRV_MIDIOUT))) + { + return MMSYSERR_NOMEM; + } + if ((dwFlags & CALLBACK_TYPEMASK) == CALLBACK_FUNCTION) + { + dwCallback = (DWORD)thunk; + } + ret = midiOutOpen(&hmo, uDeviceID, dwCallback, dwInstance, dwFlags); + if (ret == MMSYSERR_NOERROR) + { + if (lphMidiOut != NULL) *lphMidiOut = HMIDIOUT_16(hmo); + MMSYSTDRV_SetHandle(thunk, (void*)hmo); + } + else MMSYSTDRV_DeleteThunk(thunk); return ret; } @@ -609,7 +622,11 @@ UINT16 WINAPI midiOutOpen16(HMIDIOUT16* lphMidiOut, UINT16 uDeviceID, */ UINT16 WINAPI midiOutClose16(HMIDIOUT16 hMidiOut) { - return midiOutClose(HMIDIOUT_32(hMidiOut)); + UINT ret = midiOutClose(HMIDIOUT_32(hMidiOut)); + + if (ret == MMSYSERR_NOERROR) + MMSYSTDRV_CloseHandle((void*)HMIDIOUT_32(hMidiOut)); + return ret; } /************************************************************************** @@ -619,14 +636,9 @@ UINT16 WINAPI midiOutPrepareHeader16(HMIDIOUT16 hMidiOut, /* [in] */ SEGPTR lpsegMidiOutHdr, /* [???] */ UINT16 uSize) /* [in] */ { - LPWINE_MLD wmld; - TRACE("(%04X, %08x, %d)\n", hMidiOut, lpsegMidiOutHdr, uSize); - if ((wmld = MMDRV_Get(HMIDIOUT_32(hMidiOut), MMDRV_MIDIOUT, FALSE)) == NULL) - return MMSYSERR_INVALHANDLE; - - return MMDRV_Message(wmld, MODM_PREPARE, lpsegMidiOutHdr, uSize, FALSE); + return MMSYSTDRV_Message(HMIDIOUT_32(hMidiOut), MODM_PREPARE, lpsegMidiOutHdr, uSize); } /************************************************************************** @@ -636,7 +648,6 @@ UINT16 WINAPI midiOutUnprepareHeader16(HMIDIOUT16 hMidiOut, /* [in] */ SEGPTR lpsegMidiOutHdr, /* [???] */ UINT16 uSize) /* [in] */ { - LPWINE_MLD wmld; LPMIDIHDR16 lpMidiOutHdr = MapSL(lpsegMidiOutHdr); TRACE("(%04X, %08x, %d)\n", hMidiOut, lpsegMidiOutHdr, uSize); @@ -645,10 +656,7 @@ UINT16 WINAPI midiOutUnprepareHeader16(HMIDIOUT16 hMidiOut, /* [in] */ return MMSYSERR_NOERROR; } - if ((wmld = MMDRV_Get(HMIDIOUT_32(hMidiOut), MMDRV_MIDIOUT, FALSE)) == NULL) - return MMSYSERR_INVALHANDLE; - - return MMDRV_Message(wmld, MODM_UNPREPARE, lpsegMidiOutHdr, uSize, FALSE); + return MMSYSTDRV_Message(HMIDIOUT_32(hMidiOut), MODM_UNPREPARE, lpsegMidiOutHdr, uSize); } /************************************************************************** @@ -666,14 +674,9 @@ UINT16 WINAPI midiOutLongMsg16(HMIDIOUT16 hMidiOut, /* [in] */ LPMIDIHDR16 lpsegMidiOutHdr, /* [???] NOTE: SEGPTR */ UINT16 uSize) /* [in] */ { - LPWINE_MLD wmld; - TRACE("(%04X, %p, %d)\n", hMidiOut, lpsegMidiOutHdr, uSize); - if ((wmld = MMDRV_Get(HMIDIOUT_32(hMidiOut), MMDRV_MIDIOUT, FALSE)) == NULL) - return MMSYSERR_INVALHANDLE; - - return MMDRV_Message(wmld, MODM_LONGDATA, (DWORD_PTR)lpsegMidiOutHdr, uSize, FALSE); + return MMSYSTDRV_Message(HMIDIOUT_32(hMidiOut), MODM_LONGDATA, (DWORD_PTR)lpsegMidiOutHdr, uSize); } /************************************************************************** @@ -739,13 +742,8 @@ UINT16 WINAPI midiOutGetID16(HMIDIOUT16 hMidiOut, UINT16* lpuDeviceID) DWORD WINAPI midiOutMessage16(HMIDIOUT16 hMidiOut, UINT16 uMessage, DWORD dwParam1, DWORD dwParam2) { - LPWINE_MLD wmld; - TRACE("(%04X, %04X, %08X, %08X)\n", hMidiOut, uMessage, dwParam1, dwParam2); - if ((wmld = MMDRV_Get(HMIDIOUT_32(hMidiOut), MMDRV_MIDIOUT, FALSE)) == NULL) - return MMSYSERR_INVALHANDLE; - switch (uMessage) { case MODM_OPEN: case MODM_CLOSE: @@ -762,7 +760,7 @@ DWORD WINAPI midiOutMessage16(HMIDIOUT16 hMidiOut, UINT16 uMessage, case MODM_UNPREPARE: return midiOutUnprepareHeader16(hMidiOut, dwParam1, dwParam2); } - return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE); + return MMSYSTDRV_Message(HMIDIOUT_32(hMidiOut), uMessage, dwParam1, dwParam2); } /************************************************************************** diff --git a/dlls/winmm/winemm.h b/dlls/winmm/winemm.h index 83eb2e499cd..82139c54ce0 100644 --- a/dlls/winmm/winemm.h +++ b/dlls/winmm/winemm.h @@ -203,8 +203,6 @@ LPSTR MCI_strdupWtoA(LPCWSTR str); BOOL WINMM_CheckForMMSystem(void); const char* WINMM_ErrorToString(MMRESULT error); -UINT MIDI_OutOpen(HMIDIOUT* lphMidiOut, UINT uDeviceID, DWORD_PTR dwCallback, - DWORD_PTR dwInstance, DWORD dwFlags, BOOL bFrom32); MMRESULT MIDI_StreamOpen(HMIDISTRM* lphMidiStrm, LPUINT lpuDeviceID, DWORD cMidi, DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD fdwOpen, BOOL bFrom32); diff --git a/dlls/winmm/winmm.c b/dlls/winmm/winmm.c index 77f11d244b0..00d25b6ff67 100644 --- a/dlls/winmm/winmm.c +++ b/dlls/winmm/winmm.c @@ -931,8 +931,11 @@ static LPWINE_MIDI MIDI_OutAlloc(HMIDIOUT* lphMidiOut, DWORD_PTR* lpdwCallback, return lpwm; } -UINT MIDI_OutOpen(LPHMIDIOUT lphMidiOut, UINT uDeviceID, DWORD_PTR dwCallback, - DWORD_PTR dwInstance, DWORD dwFlags, BOOL bFrom32) +/************************************************************************** + * midiOutOpen [WINMM.@] + */ +UINT WINAPI midiOutOpen(LPHMIDIOUT lphMidiOut, UINT uDeviceID, + DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD dwFlags) { HMIDIOUT hMidiOut; LPWINE_MIDI lpwm; @@ -944,7 +947,7 @@ UINT MIDI_OutOpen(LPHMIDIOUT lphMidiOut, UINT uDeviceID, DWORD_PTR dwCallback, if (lphMidiOut != NULL) *lphMidiOut = 0; lpwm = MIDI_OutAlloc(&hMidiOut, &dwCallback, &dwInstance, &dwFlags, - 0, NULL, bFrom32); + 0, NULL, TRUE); if (lpwm == NULL) return MMSYSERR_NOMEM; @@ -964,15 +967,6 @@ UINT MIDI_OutOpen(LPHMIDIOUT lphMidiOut, UINT uDeviceID, DWORD_PTR dwCallback, return dwRet; } -/************************************************************************** - * midiOutOpen [WINMM.@] - */ -UINT WINAPI midiOutOpen(LPHMIDIOUT lphMidiOut, UINT uDeviceID, - DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD dwFlags) -{ - return MIDI_OutOpen(lphMidiOut, uDeviceID, dwCallback, dwInstance, dwFlags, TRUE); -} - /************************************************************************** * midiOutClose [WINMM.@] */