1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
6 * Copyright 1993 Martin Ayotte
7 * 1998-2002 Eric Pouech
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 * 98/9 added Win32 MCI support
27 * 99/4 added midiStream support
28 * 99/9 added support for loadable low level drivers
32 * + it seems that some programs check what's installed in
33 * registry against the value returned by drivers. Wine is
34 * currently broken regarding this point.
35 * + check thread-safeness for MMSYSTEM and WINMM entry points
36 * + unicode entry points are badly supported (would require
37 * moving 32 bit drivers as Unicode as they are supposed to be)
38 * + allow joystick and timer external calls as we do for wave,
46 #define NONAMELESSUNION
47 #define NONAMELESSSTRUCT
57 #include "wine/debug.h"
59 WINE_DEFAULT_DEBUG_CHANNEL(winmm);
61 void (WINAPI *pFnReleaseThunkLock)(DWORD*);
62 void (WINAPI *pFnRestoreThunkLock)(DWORD);
64 /* ========================================================================
65 * G L O B A L S E T T I N G S
66 * ========================================================================*/
68 WINE_MM_IDATA WINMM_IData;
70 /**************************************************************************
71 * WINMM_CreateIData [internal]
73 static BOOL WINMM_CreateIData(HINSTANCE hInstDLL)
75 memset( &WINMM_IData, 0, sizeof WINMM_IData );
77 WINMM_IData.hWinMM32Instance = hInstDLL;
78 InitializeCriticalSection(&WINMM_IData.cs);
79 WINMM_IData.cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": WINE_MM_IDATA.cs");
80 WINMM_IData.psStopEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
81 WINMM_IData.psLastEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
82 TRACE("Initialized IData (%p)\n", &WINMM_IData);
86 /**************************************************************************
87 * WINMM_DeleteIData [internal]
89 static void WINMM_DeleteIData(void)
93 /* FIXME: should also free content and resources allocated
94 * inside WINMM_IData */
95 CloseHandle(WINMM_IData.psStopEvent);
96 CloseHandle(WINMM_IData.psLastEvent);
97 WINMM_IData.cs.DebugInfo->Spare[0] = 0;
98 DeleteCriticalSection(&WINMM_IData.cs);
101 /******************************************************************
105 static HANDLE (WINAPI *pGetModuleHandle16)(LPCSTR);
106 static DWORD (WINAPI *pLoadLibrary16)(LPCSTR);
108 BOOL WINMM_CheckForMMSystem(void)
110 /* 0 is not checked yet, -1 is not present, 1 is present */
111 static int loaded /* = 0 */;
115 HANDLE h = GetModuleHandleA("kernel32");
119 pGetModuleHandle16 = (void*)GetProcAddress(h, "GetModuleHandle16");
120 pLoadLibrary16 = (void*)GetProcAddress(h, (LPCSTR)35); /* ordinal for LoadLibrary16 */
121 if (pGetModuleHandle16 && pLoadLibrary16 &&
122 (pGetModuleHandle16("MMSYSTEM.DLL") || pLoadLibrary16("MMSYSTEM.DLL")))
129 /******************************************************************
130 * WINMM_ErrorToString
132 const char* WINMM_ErrorToString(MMRESULT error)
134 #define ERR_TO_STR(dev) case dev: return #dev
135 static char unknown[32];
137 ERR_TO_STR(MMSYSERR_NOERROR);
138 ERR_TO_STR(MMSYSERR_ERROR);
139 ERR_TO_STR(MMSYSERR_BADDEVICEID);
140 ERR_TO_STR(MMSYSERR_NOTENABLED);
141 ERR_TO_STR(MMSYSERR_ALLOCATED);
142 ERR_TO_STR(MMSYSERR_INVALHANDLE);
143 ERR_TO_STR(MMSYSERR_NODRIVER);
144 ERR_TO_STR(MMSYSERR_NOMEM);
145 ERR_TO_STR(MMSYSERR_NOTSUPPORTED);
146 ERR_TO_STR(MMSYSERR_BADERRNUM);
147 ERR_TO_STR(MMSYSERR_INVALFLAG);
148 ERR_TO_STR(MMSYSERR_INVALPARAM);
149 ERR_TO_STR(MMSYSERR_HANDLEBUSY);
150 ERR_TO_STR(MMSYSERR_INVALIDALIAS);
151 ERR_TO_STR(MMSYSERR_BADDB);
152 ERR_TO_STR(MMSYSERR_KEYNOTFOUND);
153 ERR_TO_STR(MMSYSERR_READERROR);
154 ERR_TO_STR(MMSYSERR_WRITEERROR);
155 ERR_TO_STR(MMSYSERR_DELETEERROR);
156 ERR_TO_STR(MMSYSERR_VALNOTFOUND);
157 ERR_TO_STR(MMSYSERR_NODRIVERCB);
158 ERR_TO_STR(WAVERR_BADFORMAT);
159 ERR_TO_STR(WAVERR_STILLPLAYING);
160 ERR_TO_STR(WAVERR_UNPREPARED);
161 ERR_TO_STR(WAVERR_SYNC);
163 sprintf(unknown, "Unknown(0x%08x)", error);
168 /**************************************************************************
169 * DllMain (WINMM.init)
171 * WINMM DLL entry point
174 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID fImpLoad)
176 TRACE("%p 0x%x %p\n", hInstDLL, fdwReason, fImpLoad);
179 case DLL_PROCESS_ATTACH:
180 DisableThreadLibraryCalls(hInstDLL);
182 if (!WINMM_CreateIData(hInstDLL))
189 case DLL_PROCESS_DETACH:
190 /* close all opened MCI drivers */
191 MCI_SendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_WAIT, 0L, TRUE);
193 /* now unload all remaining drivers... */
202 /**************************************************************************
203 * Mixer devices. New to Win95
206 /**************************************************************************
207 * find out the real mixer ID depending on hmix (depends on dwFlags)
209 static UINT MIXER_GetDev(HMIXEROBJ hmix, DWORD dwFlags, LPWINE_MIXER * lplpwm)
211 LPWINE_MIXER lpwm = NULL;
212 UINT uRet = MMSYSERR_NOERROR;
214 switch (dwFlags & 0xF0000000ul) {
215 case MIXER_OBJECTF_MIXER:
216 lpwm = (LPWINE_MIXER)MMDRV_Get(hmix, MMDRV_MIXER, TRUE);
218 case MIXER_OBJECTF_HMIXER:
219 lpwm = (LPWINE_MIXER)MMDRV_Get(hmix, MMDRV_MIXER, FALSE);
221 case MIXER_OBJECTF_WAVEOUT:
222 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEOUT, TRUE, MMDRV_MIXER);
224 case MIXER_OBJECTF_HWAVEOUT:
225 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEOUT, FALSE, MMDRV_MIXER);
227 case MIXER_OBJECTF_WAVEIN:
228 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEIN, TRUE, MMDRV_MIXER);
230 case MIXER_OBJECTF_HWAVEIN:
231 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEIN, FALSE, MMDRV_MIXER);
233 case MIXER_OBJECTF_MIDIOUT:
234 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIOUT, TRUE, MMDRV_MIXER);
236 case MIXER_OBJECTF_HMIDIOUT:
237 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIOUT, FALSE, MMDRV_MIXER);
239 case MIXER_OBJECTF_MIDIIN:
240 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIIN, TRUE, MMDRV_MIXER);
242 case MIXER_OBJECTF_HMIDIIN:
243 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIIN, FALSE, MMDRV_MIXER);
245 case MIXER_OBJECTF_AUX:
246 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_AUX, TRUE, MMDRV_MIXER);
249 WARN("Unsupported flag (%08lx)\n", dwFlags & 0xF0000000ul);
251 uRet = MMSYSERR_INVALFLAG;
255 if (lpwm == 0 && uRet == MMSYSERR_NOERROR)
256 uRet = MMSYSERR_INVALPARAM;
260 /**************************************************************************
261 * mixerGetNumDevs [WINMM.@]
263 UINT WINAPI mixerGetNumDevs(void)
265 return MMDRV_GetNum(MMDRV_MIXER);
268 /**************************************************************************
269 * mixerGetDevCapsA [WINMM.@]
271 UINT WINAPI mixerGetDevCapsA(UINT_PTR uDeviceID, LPMIXERCAPSA lpCaps, UINT uSize)
276 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
278 ret = mixerGetDevCapsW(uDeviceID, &micW, sizeof(micW));
280 if (ret == MMSYSERR_NOERROR) {
282 micA.wMid = micW.wMid;
283 micA.wPid = micW.wPid;
284 micA.vDriverVersion = micW.vDriverVersion;
285 WideCharToMultiByte( CP_ACP, 0, micW.szPname, -1, micA.szPname,
286 sizeof(micA.szPname), NULL, NULL );
287 micA.fdwSupport = micW.fdwSupport;
288 micA.cDestinations = micW.cDestinations;
289 memcpy(lpCaps, &micA, min(uSize, sizeof(micA)));
294 /**************************************************************************
295 * mixerGetDevCapsW [WINMM.@]
297 UINT WINAPI mixerGetDevCapsW(UINT_PTR uDeviceID, LPMIXERCAPSW lpCaps, UINT uSize)
301 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
303 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_MIXER, TRUE)) == NULL)
304 return MMSYSERR_BADDEVICEID;
306 return MMDRV_Message(wmld, MXDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
309 UINT MIXER_Open(LPHMIXER lphMix, UINT uDeviceID, DWORD_PTR dwCallback,
310 DWORD_PTR dwInstance, DWORD fdwOpen, BOOL bFrom32)
317 TRACE("(%p, %d, %08lx, %08lx, %08x)\n",
318 lphMix, uDeviceID, dwCallback, dwInstance, fdwOpen);
320 wmld = MMDRV_Alloc(sizeof(WINE_MIXER), MMDRV_MIXER, &hMix, &fdwOpen,
321 &dwCallback, &dwInstance, bFrom32);
323 wmld->uDeviceID = uDeviceID;
324 mod.hmx = (HMIXEROBJ)hMix;
325 mod.dwCallback = dwCallback;
326 mod.dwInstance = dwInstance;
328 dwRet = MMDRV_Open(wmld, MXDM_OPEN, (DWORD)&mod, fdwOpen);
330 if (dwRet != MMSYSERR_NOERROR) {
331 MMDRV_Free(hMix, wmld);
334 if (lphMix) *lphMix = hMix;
335 TRACE("=> %d hMixer=%p\n", dwRet, hMix);
340 /**************************************************************************
341 * mixerOpen [WINMM.@]
343 UINT WINAPI mixerOpen(LPHMIXER lphMix, UINT uDeviceID, DWORD_PTR dwCallback,
344 DWORD_PTR dwInstance, DWORD fdwOpen)
346 return MIXER_Open(lphMix, uDeviceID, dwCallback, dwInstance, fdwOpen, TRUE);
349 /**************************************************************************
350 * mixerClose [WINMM.@]
352 UINT WINAPI mixerClose(HMIXER hMix)
357 TRACE("(%p)\n", hMix);
359 if ((wmld = MMDRV_Get(hMix, MMDRV_MIXER, FALSE)) == NULL) return MMSYSERR_INVALHANDLE;
361 dwRet = MMDRV_Close(wmld, MXDM_CLOSE);
362 MMDRV_Free(hMix, wmld);
367 /**************************************************************************
368 * mixerGetID [WINMM.@]
370 UINT WINAPI mixerGetID(HMIXEROBJ hmix, LPUINT lpid, DWORD fdwID)
373 UINT uRet = MMSYSERR_NOERROR;
375 TRACE("(%p %p %08x)\n", hmix, lpid, fdwID);
377 if ((uRet = MIXER_GetDev(hmix, fdwID, &lpwm)) != MMSYSERR_NOERROR)
381 *lpid = lpwm->mld.uDeviceID;
386 /**************************************************************************
387 * mixerGetControlDetailsW [WINMM.@]
389 UINT WINAPI mixerGetControlDetailsW(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcdW,
393 UINT uRet = MMSYSERR_NOERROR;
395 TRACE("(%p, %p, %08x)\n", hmix, lpmcdW, fdwDetails);
397 if ((uRet = MIXER_GetDev(hmix, fdwDetails, &lpwm)) != MMSYSERR_NOERROR)
400 if (lpmcdW == NULL || lpmcdW->cbStruct != sizeof(*lpmcdW))
401 return MMSYSERR_INVALPARAM;
403 return MMDRV_Message(&lpwm->mld, MXDM_GETCONTROLDETAILS, (DWORD_PTR)lpmcdW,
407 /**************************************************************************
408 * mixerGetControlDetailsA [WINMM.@]
410 UINT WINAPI mixerGetControlDetailsA(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcdA,
413 DWORD ret = MMSYSERR_NOTENABLED;
415 TRACE("(%p, %p, %08x)\n", hmix, lpmcdA, fdwDetails);
417 if (lpmcdA == NULL || lpmcdA->cbStruct != sizeof(*lpmcdA))
418 return MMSYSERR_INVALPARAM;
420 switch (fdwDetails & MIXER_GETCONTROLDETAILSF_QUERYMASK) {
421 case MIXER_GETCONTROLDETAILSF_VALUE:
422 /* can savely use A structure as it is, no string inside */
423 ret = mixerGetControlDetailsW(hmix, lpmcdA, fdwDetails);
425 case MIXER_GETCONTROLDETAILSF_LISTTEXT:
427 MIXERCONTROLDETAILS_LISTTEXTA *pDetailsA = (MIXERCONTROLDETAILS_LISTTEXTA *)lpmcdA->paDetails;
428 MIXERCONTROLDETAILS_LISTTEXTW *pDetailsW;
429 int size = max(1, lpmcdA->cChannels) * sizeof(MIXERCONTROLDETAILS_LISTTEXTW);
432 if (lpmcdA->u.cMultipleItems != 0) {
433 size *= lpmcdA->u.cMultipleItems;
435 pDetailsW = HeapAlloc(GetProcessHeap(), 0, size);
436 lpmcdA->paDetails = pDetailsW;
437 lpmcdA->cbDetails = sizeof(MIXERCONTROLDETAILS_LISTTEXTW);
438 /* set up lpmcd->paDetails */
439 ret = mixerGetControlDetailsW(hmix, lpmcdA, fdwDetails);
440 /* copy from lpmcd->paDetails back to paDetailsW; */
441 if (ret == MMSYSERR_NOERROR) {
442 for (i = 0; i < lpmcdA->u.cMultipleItems * lpmcdA->cChannels; i++) {
443 pDetailsA->dwParam1 = pDetailsW->dwParam1;
444 pDetailsA->dwParam2 = pDetailsW->dwParam2;
445 WideCharToMultiByte( CP_ACP, 0, pDetailsW->szName, -1,
447 sizeof(pDetailsA->szName), NULL, NULL );
451 pDetailsA -= lpmcdA->u.cMultipleItems * lpmcdA->cChannels;
452 pDetailsW -= lpmcdA->u.cMultipleItems * lpmcdA->cChannels;
454 HeapFree(GetProcessHeap(), 0, pDetailsW);
455 lpmcdA->paDetails = pDetailsA;
456 lpmcdA->cbDetails = sizeof(MIXERCONTROLDETAILS_LISTTEXTA);
460 ERR("Unsupported fdwDetails=0x%08x\n", fdwDetails);
466 /**************************************************************************
467 * mixerGetLineControlsA [WINMM.@]
469 UINT WINAPI mixerGetLineControlsA(HMIXEROBJ hmix, LPMIXERLINECONTROLSA lpmlcA,
472 MIXERLINECONTROLSW mlcW;
476 TRACE("(%p, %p, %08x)\n", hmix, lpmlcA, fdwControls);
478 if (lpmlcA == NULL || lpmlcA->cbStruct != sizeof(*lpmlcA) ||
479 lpmlcA->cbmxctrl != sizeof(MIXERCONTROLA))
480 return MMSYSERR_INVALPARAM;
482 mlcW.cbStruct = sizeof(mlcW);
483 mlcW.dwLineID = lpmlcA->dwLineID;
484 mlcW.u.dwControlID = lpmlcA->u.dwControlID;
485 mlcW.u.dwControlType = lpmlcA->u.dwControlType;
487 /* Debugging on Windows shows for MIXER_GETLINECONTROLSF_ONEBYTYPE only,
488 the control count is assumed to be 1 - This is relied upon by a game,
490 if (MIXER_GETLINECONTROLSF_ONEBYTYPE == fdwControls) {
493 mlcW.cControls = lpmlcA->cControls;
495 mlcW.cbmxctrl = sizeof(MIXERCONTROLW);
496 mlcW.pamxctrl = HeapAlloc(GetProcessHeap(), 0,
497 mlcW.cControls * mlcW.cbmxctrl);
499 ret = mixerGetLineControlsW(hmix, &mlcW, fdwControls);
501 if (ret == MMSYSERR_NOERROR) {
502 lpmlcA->dwLineID = mlcW.dwLineID;
503 lpmlcA->u.dwControlID = mlcW.u.dwControlID;
504 lpmlcA->u.dwControlType = mlcW.u.dwControlType;
505 lpmlcA->cControls = mlcW.cControls;
507 for (i = 0; i < mlcW.cControls; i++) {
508 lpmlcA->pamxctrl[i].cbStruct = sizeof(MIXERCONTROLA);
509 lpmlcA->pamxctrl[i].dwControlID = mlcW.pamxctrl[i].dwControlID;
510 lpmlcA->pamxctrl[i].dwControlType = mlcW.pamxctrl[i].dwControlType;
511 lpmlcA->pamxctrl[i].fdwControl = mlcW.pamxctrl[i].fdwControl;
512 lpmlcA->pamxctrl[i].cMultipleItems = mlcW.pamxctrl[i].cMultipleItems;
513 WideCharToMultiByte( CP_ACP, 0, mlcW.pamxctrl[i].szShortName, -1,
514 lpmlcA->pamxctrl[i].szShortName,
515 sizeof(lpmlcA->pamxctrl[i].szShortName), NULL, NULL );
516 WideCharToMultiByte( CP_ACP, 0, mlcW.pamxctrl[i].szName, -1,
517 lpmlcA->pamxctrl[i].szName,
518 sizeof(lpmlcA->pamxctrl[i].szName), NULL, NULL );
519 /* sizeof(lpmlcA->pamxctrl[i].Bounds) ==
520 * sizeof(mlcW.pamxctrl[i].Bounds) */
521 memcpy(&lpmlcA->pamxctrl[i].Bounds, &mlcW.pamxctrl[i].Bounds,
522 sizeof(mlcW.pamxctrl[i].Bounds));
523 /* sizeof(lpmlcA->pamxctrl[i].Metrics) ==
524 * sizeof(mlcW.pamxctrl[i].Metrics) */
525 memcpy(&lpmlcA->pamxctrl[i].Metrics, &mlcW.pamxctrl[i].Metrics,
526 sizeof(mlcW.pamxctrl[i].Metrics));
530 HeapFree(GetProcessHeap(), 0, mlcW.pamxctrl);
535 /**************************************************************************
536 * mixerGetLineControlsW [WINMM.@]
538 UINT WINAPI mixerGetLineControlsW(HMIXEROBJ hmix, LPMIXERLINECONTROLSW lpmlcW,
542 UINT uRet = MMSYSERR_NOERROR;
544 TRACE("(%p, %p, %08x)\n", hmix, lpmlcW, fdwControls);
546 if ((uRet = MIXER_GetDev(hmix, fdwControls, &lpwm)) != MMSYSERR_NOERROR)
549 if (lpmlcW == NULL || lpmlcW->cbStruct != sizeof(*lpmlcW))
550 return MMSYSERR_INVALPARAM;
552 return MMDRV_Message(&lpwm->mld, MXDM_GETLINECONTROLS, (DWORD_PTR)lpmlcW,
556 /**************************************************************************
557 * mixerGetLineInfoW [WINMM.@]
559 UINT WINAPI mixerGetLineInfoW(HMIXEROBJ hmix, LPMIXERLINEW lpmliW, DWORD fdwInfo)
562 UINT uRet = MMSYSERR_NOERROR;
564 TRACE("(%p, %p, %08x)\n", hmix, lpmliW, fdwInfo);
566 if ((uRet = MIXER_GetDev(hmix, fdwInfo, &lpwm)) != MMSYSERR_NOERROR)
569 return MMDRV_Message(&lpwm->mld, MXDM_GETLINEINFO, (DWORD_PTR)lpmliW,
573 /**************************************************************************
574 * mixerGetLineInfoA [WINMM.@]
576 UINT WINAPI mixerGetLineInfoA(HMIXEROBJ hmix, LPMIXERLINEA lpmliA,
582 TRACE("(%p, %p, %08x)\n", hmix, lpmliA, fdwInfo);
584 if (lpmliA == NULL || lpmliA->cbStruct != sizeof(*lpmliA))
585 return MMSYSERR_INVALPARAM;
587 mliW.cbStruct = sizeof(mliW);
588 switch (fdwInfo & MIXER_GETLINEINFOF_QUERYMASK) {
589 case MIXER_GETLINEINFOF_COMPONENTTYPE:
590 mliW.dwComponentType = lpmliA->dwComponentType;
592 case MIXER_GETLINEINFOF_DESTINATION:
593 mliW.dwDestination = lpmliA->dwDestination;
595 case MIXER_GETLINEINFOF_LINEID:
596 mliW.dwLineID = lpmliA->dwLineID;
598 case MIXER_GETLINEINFOF_SOURCE:
599 mliW.dwDestination = lpmliA->dwDestination;
600 mliW.dwSource = lpmliA->dwSource;
602 case MIXER_GETLINEINFOF_TARGETTYPE:
603 mliW.Target.dwType = lpmliA->Target.dwType;
604 mliW.Target.wMid = lpmliA->Target.wMid;
605 mliW.Target.wPid = lpmliA->Target.wPid;
606 mliW.Target.vDriverVersion = lpmliA->Target.vDriverVersion;
607 MultiByteToWideChar( CP_ACP, 0, lpmliA->Target.szPname, -1, mliW.Target.szPname, sizeof(mliW.Target.szPname)/sizeof(WCHAR));
610 WARN("Unsupported fdwControls=0x%08x\n", fdwInfo);
611 return MMSYSERR_INVALFLAG;
614 ret = mixerGetLineInfoW(hmix, &mliW, fdwInfo);
616 lpmliA->dwDestination = mliW.dwDestination;
617 lpmliA->dwSource = mliW.dwSource;
618 lpmliA->dwLineID = mliW.dwLineID;
619 lpmliA->fdwLine = mliW.fdwLine;
620 lpmliA->dwUser = mliW.dwUser;
621 lpmliA->dwComponentType = mliW.dwComponentType;
622 lpmliA->cChannels = mliW.cChannels;
623 lpmliA->cConnections = mliW.cConnections;
624 lpmliA->cControls = mliW.cControls;
625 WideCharToMultiByte( CP_ACP, 0, mliW.szShortName, -1, lpmliA->szShortName,
626 sizeof(lpmliA->szShortName), NULL, NULL);
627 WideCharToMultiByte( CP_ACP, 0, mliW.szName, -1, lpmliA->szName,
628 sizeof(lpmliA->szName), NULL, NULL );
629 lpmliA->Target.dwType = mliW.Target.dwType;
630 lpmliA->Target.dwDeviceID = mliW.Target.dwDeviceID;
631 lpmliA->Target.wMid = mliW.Target.wMid;
632 lpmliA->Target.wPid = mliW.Target.wPid;
633 lpmliA->Target.vDriverVersion = mliW.Target.vDriverVersion;
634 WideCharToMultiByte( CP_ACP, 0, mliW.Target.szPname, -1, lpmliA->Target.szPname,
635 sizeof(lpmliA->Target.szPname), NULL, NULL );
640 /**************************************************************************
641 * mixerSetControlDetails [WINMM.@]
643 UINT WINAPI mixerSetControlDetails(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcd,
647 UINT uRet = MMSYSERR_NOERROR;
649 TRACE("(%p, %p, %08x)\n", hmix, lpmcd, fdwDetails);
651 if ((uRet = MIXER_GetDev(hmix, fdwDetails, &lpwm)) != MMSYSERR_NOERROR)
654 return MMDRV_Message(&lpwm->mld, MXDM_SETCONTROLDETAILS, (DWORD_PTR)lpmcd,
658 /**************************************************************************
659 * mixerMessage [WINMM.@]
661 DWORD WINAPI mixerMessage(HMIXER hmix, UINT uMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
665 TRACE("(%p, %d, %08lx, %08lx): semi-stub?\n",
666 hmix, uMsg, dwParam1, dwParam2);
668 if ((wmld = MMDRV_Get(hmix, MMDRV_MIXER, FALSE)) == NULL)
669 return MMSYSERR_INVALHANDLE;
671 return MMDRV_Message(wmld, uMsg, dwParam1, dwParam2, TRUE);
674 /**************************************************************************
675 * auxGetNumDevs [WINMM.@]
677 UINT WINAPI auxGetNumDevs(void)
679 return MMDRV_GetNum(MMDRV_AUX);
682 /**************************************************************************
683 * auxGetDevCapsW [WINMM.@]
685 UINT WINAPI auxGetDevCapsW(UINT_PTR uDeviceID, LPAUXCAPSW lpCaps, UINT uSize)
689 TRACE("(%04X, %p, %d) !\n", uDeviceID, lpCaps, uSize);
691 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
693 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
694 return MMSYSERR_INVALHANDLE;
695 return MMDRV_Message(wmld, AUXDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
698 /**************************************************************************
699 * auxGetDevCapsA [WINMM.@]
701 UINT WINAPI auxGetDevCapsA(UINT_PTR uDeviceID, LPAUXCAPSA lpCaps, UINT uSize)
706 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
708 ret = auxGetDevCapsW(uDeviceID, &acW, sizeof(acW));
710 if (ret == MMSYSERR_NOERROR) {
714 acA.vDriverVersion = acW.vDriverVersion;
715 WideCharToMultiByte( CP_ACP, 0, acW.szPname, -1, acA.szPname,
716 sizeof(acA.szPname), NULL, NULL );
717 acA.wTechnology = acW.wTechnology;
718 acA.dwSupport = acW.dwSupport;
719 memcpy(lpCaps, &acA, min(uSize, sizeof(acA)));
724 /**************************************************************************
725 * auxGetVolume [WINMM.@]
727 UINT WINAPI auxGetVolume(UINT uDeviceID, DWORD* lpdwVolume)
731 TRACE("(%04X, %p) !\n", uDeviceID, lpdwVolume);
733 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
734 return MMSYSERR_INVALHANDLE;
735 return MMDRV_Message(wmld, AUXDM_GETVOLUME, (DWORD_PTR)lpdwVolume, 0L, TRUE);
738 /**************************************************************************
739 * auxSetVolume [WINMM.@]
741 UINT WINAPI auxSetVolume(UINT uDeviceID, DWORD dwVolume)
745 TRACE("(%04X, %u) !\n", uDeviceID, dwVolume);
747 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
748 return MMSYSERR_INVALHANDLE;
749 return MMDRV_Message(wmld, AUXDM_SETVOLUME, dwVolume, 0L, TRUE);
752 /**************************************************************************
753 * auxOutMessage [WINMM.@]
755 UINT WINAPI auxOutMessage(UINT uDeviceID, UINT uMessage, DWORD_PTR dw1, DWORD_PTR dw2)
759 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
760 return MMSYSERR_INVALHANDLE;
762 return MMDRV_Message(wmld, uMessage, dw1, dw2, TRUE);
765 /**************************************************************************
766 * midiOutGetNumDevs [WINMM.@]
768 UINT WINAPI midiOutGetNumDevs(void)
770 return MMDRV_GetNum(MMDRV_MIDIOUT);
773 /**************************************************************************
774 * midiOutGetDevCapsW [WINMM.@]
776 UINT WINAPI midiOutGetDevCapsW(UINT_PTR uDeviceID, LPMIDIOUTCAPSW lpCaps,
781 TRACE("(%u, %p, %u);\n", uDeviceID, lpCaps, uSize);
783 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
785 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_MIDIOUT, TRUE)) == NULL)
786 return MMSYSERR_INVALHANDLE;
788 return MMDRV_Message(wmld, MODM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
791 /**************************************************************************
792 * midiOutGetDevCapsA [WINMM.@]
794 UINT WINAPI midiOutGetDevCapsA(UINT_PTR uDeviceID, LPMIDIOUTCAPSA lpCaps,
800 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
802 ret = midiOutGetDevCapsW(uDeviceID, &mocW, sizeof(mocW));
804 if (ret == MMSYSERR_NOERROR) {
806 mocA.wMid = mocW.wMid;
807 mocA.wPid = mocW.wPid;
808 mocA.vDriverVersion = mocW.vDriverVersion;
809 WideCharToMultiByte( CP_ACP, 0, mocW.szPname, -1, mocA.szPname,
810 sizeof(mocA.szPname), NULL, NULL );
811 mocA.wTechnology = mocW.wTechnology;
812 mocA.wVoices = mocW.wVoices;
813 mocA.wNotes = mocW.wNotes;
814 mocA.wChannelMask = mocW.wChannelMask;
815 mocA.dwSupport = mocW.dwSupport;
816 memcpy(lpCaps, &mocA, min(uSize, sizeof(mocA)));
821 /**************************************************************************
822 * midiOutGetErrorTextA [WINMM.@]
823 * midiInGetErrorTextA [WINMM.@]
825 UINT WINAPI midiOutGetErrorTextA(UINT uError, LPSTR lpText, UINT uSize)
829 if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
830 else if (uSize == 0) ret = MMSYSERR_NOERROR;
833 LPWSTR xstr = HeapAlloc(GetProcessHeap(), 0, uSize * sizeof(WCHAR));
834 if (!xstr) ret = MMSYSERR_NOMEM;
837 ret = midiOutGetErrorTextW(uError, xstr, uSize);
838 if (ret == MMSYSERR_NOERROR)
839 WideCharToMultiByte(CP_ACP, 0, xstr, -1, lpText, uSize, NULL, NULL);
840 HeapFree(GetProcessHeap(), 0, xstr);
846 /**************************************************************************
847 * midiOutGetErrorTextW [WINMM.@]
848 * midiInGetErrorTextW [WINMM.@]
850 UINT WINAPI midiOutGetErrorTextW(UINT uError, LPWSTR lpText, UINT uSize)
852 UINT ret = MMSYSERR_BADERRNUM;
854 if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
855 else if (uSize == 0) ret = MMSYSERR_NOERROR;
857 /* test has been removed 'coz MMSYSERR_BASE is 0, and gcc did emit
858 * a warning for the test was always true */
859 (/*uError >= MMSYSERR_BASE && */ uError <= MMSYSERR_LASTERROR) ||
860 (uError >= MIDIERR_BASE && uError <= MIDIERR_LASTERROR)) {
861 if (LoadStringW(WINMM_IData.hWinMM32Instance,
862 uError, lpText, uSize) > 0) {
863 ret = MMSYSERR_NOERROR;
869 /**************************************************************************
870 * MIDI_OutAlloc [internal]
872 static LPWINE_MIDI MIDI_OutAlloc(HMIDIOUT* lphMidiOut, DWORD_PTR* lpdwCallback,
873 DWORD_PTR* lpdwInstance, LPDWORD lpdwFlags,
874 DWORD cIDs, MIDIOPENSTRMID* lpIDs, BOOL bFrom32)
880 size = sizeof(WINE_MIDI) + (cIDs ? (cIDs-1) : 0) * sizeof(MIDIOPENSTRMID);
882 lpwm = (LPWINE_MIDI)MMDRV_Alloc(size, MMDRV_MIDIOUT, &hMidiOut, lpdwFlags,
883 lpdwCallback, lpdwInstance, bFrom32);
885 if (lphMidiOut != NULL)
886 *lphMidiOut = hMidiOut;
889 lpwm->mod.hMidi = (HMIDI) hMidiOut;
890 lpwm->mod.dwCallback = *lpdwCallback;
891 lpwm->mod.dwInstance = *lpdwInstance;
892 lpwm->mod.dnDevNode = 0;
893 lpwm->mod.cIds = cIDs;
895 memcpy(&(lpwm->mod.rgIds), lpIDs, cIDs * sizeof(MIDIOPENSTRMID));
900 UINT MIDI_OutOpen(LPHMIDIOUT lphMidiOut, UINT uDeviceID, DWORD_PTR dwCallback,
901 DWORD_PTR dwInstance, DWORD dwFlags, BOOL bFrom32)
907 TRACE("(%p, %d, %08lX, %08lX, %08X);\n",
908 lphMidiOut, uDeviceID, dwCallback, dwInstance, dwFlags);
910 if (lphMidiOut != NULL) *lphMidiOut = 0;
912 lpwm = MIDI_OutAlloc(&hMidiOut, &dwCallback, &dwInstance, &dwFlags,
916 return MMSYSERR_NOMEM;
918 lpwm->mld.uDeviceID = uDeviceID;
920 dwRet = MMDRV_Open((LPWINE_MLD)lpwm, MODM_OPEN, (DWORD)&lpwm->mod, dwFlags);
922 if (dwRet != MMSYSERR_NOERROR) {
923 MMDRV_Free(hMidiOut, (LPWINE_MLD)lpwm);
927 if (lphMidiOut) *lphMidiOut = hMidiOut;
928 TRACE("=> %d hMidi=%p\n", dwRet, hMidiOut);
933 /**************************************************************************
934 * midiOutOpen [WINMM.@]
936 UINT WINAPI midiOutOpen(LPHMIDIOUT lphMidiOut, UINT uDeviceID,
937 DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD dwFlags)
939 return MIDI_OutOpen(lphMidiOut, uDeviceID, dwCallback, dwInstance, dwFlags, TRUE);
942 /**************************************************************************
943 * midiOutClose [WINMM.@]
945 UINT WINAPI midiOutClose(HMIDIOUT hMidiOut)
950 TRACE("(%p)\n", hMidiOut);
952 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
953 return MMSYSERR_INVALHANDLE;
955 dwRet = MMDRV_Close(wmld, MODM_CLOSE);
956 MMDRV_Free(hMidiOut, wmld);
961 /**************************************************************************
962 * midiOutPrepareHeader [WINMM.@]
964 UINT WINAPI midiOutPrepareHeader(HMIDIOUT hMidiOut,
965 MIDIHDR* lpMidiOutHdr, UINT uSize)
969 TRACE("(%p, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
971 if (lpMidiOutHdr == NULL || uSize < sizeof (MIDIHDR))
972 return MMSYSERR_INVALPARAM;
974 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
975 return MMSYSERR_INVALHANDLE;
977 return MMDRV_Message(wmld, MODM_PREPARE, (DWORD_PTR)lpMidiOutHdr, uSize, TRUE);
980 /**************************************************************************
981 * midiOutUnprepareHeader [WINMM.@]
983 UINT WINAPI midiOutUnprepareHeader(HMIDIOUT hMidiOut,
984 MIDIHDR* lpMidiOutHdr, UINT uSize)
988 TRACE("(%p, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
990 if (lpMidiOutHdr == NULL || uSize < sizeof (MIDIHDR))
991 return MMSYSERR_INVALPARAM;
993 if (!(lpMidiOutHdr->dwFlags & MHDR_PREPARED)) {
994 return MMSYSERR_NOERROR;
997 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
998 return MMSYSERR_INVALHANDLE;
1000 return MMDRV_Message(wmld, MODM_UNPREPARE, (DWORD_PTR)lpMidiOutHdr, uSize, TRUE);
1003 /**************************************************************************
1004 * midiOutShortMsg [WINMM.@]
1006 UINT WINAPI midiOutShortMsg(HMIDIOUT hMidiOut, DWORD dwMsg)
1010 TRACE("(%p, %08X)\n", hMidiOut, dwMsg);
1012 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1013 return MMSYSERR_INVALHANDLE;
1015 return MMDRV_Message(wmld, MODM_DATA, dwMsg, 0L, TRUE);
1018 /**************************************************************************
1019 * midiOutLongMsg [WINMM.@]
1021 UINT WINAPI midiOutLongMsg(HMIDIOUT hMidiOut,
1022 MIDIHDR* lpMidiOutHdr, UINT uSize)
1026 TRACE("(%p, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
1028 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1029 return MMSYSERR_INVALHANDLE;
1031 return MMDRV_Message(wmld, MODM_LONGDATA, (DWORD_PTR)lpMidiOutHdr, uSize, TRUE);
1034 /**************************************************************************
1035 * midiOutReset [WINMM.@]
1037 UINT WINAPI midiOutReset(HMIDIOUT hMidiOut)
1041 TRACE("(%p)\n", hMidiOut);
1043 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1044 return MMSYSERR_INVALHANDLE;
1046 return MMDRV_Message(wmld, MODM_RESET, 0L, 0L, TRUE);
1049 /**************************************************************************
1050 * midiOutGetVolume [WINMM.@]
1052 UINT WINAPI midiOutGetVolume(HMIDIOUT hMidiOut, DWORD* lpdwVolume)
1056 TRACE("(%p, %p);\n", hMidiOut, lpdwVolume);
1058 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, TRUE)) == NULL)
1059 return MMSYSERR_INVALHANDLE;
1061 return MMDRV_Message(wmld, MODM_GETVOLUME, (DWORD_PTR)lpdwVolume, 0L, TRUE);
1064 /**************************************************************************
1065 * midiOutSetVolume [WINMM.@]
1067 UINT WINAPI midiOutSetVolume(HMIDIOUT hMidiOut, DWORD dwVolume)
1071 TRACE("(%p, %d);\n", hMidiOut, dwVolume);
1073 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, TRUE)) == NULL)
1074 return MMSYSERR_INVALHANDLE;
1076 return MMDRV_Message(wmld, MODM_SETVOLUME, dwVolume, 0L, TRUE);
1079 /**************************************************************************
1080 * midiOutCachePatches [WINMM.@]
1082 UINT WINAPI midiOutCachePatches(HMIDIOUT hMidiOut, UINT uBank,
1083 WORD* lpwPatchArray, UINT uFlags)
1085 /* not really necessary to support this */
1086 FIXME("not supported yet\n");
1087 return MMSYSERR_NOTSUPPORTED;
1090 /**************************************************************************
1091 * midiOutCacheDrumPatches [WINMM.@]
1093 UINT WINAPI midiOutCacheDrumPatches(HMIDIOUT hMidiOut, UINT uPatch,
1094 WORD* lpwKeyArray, UINT uFlags)
1096 FIXME("not supported yet\n");
1097 return MMSYSERR_NOTSUPPORTED;
1100 /**************************************************************************
1101 * midiOutGetID [WINMM.@]
1103 UINT WINAPI midiOutGetID(HMIDIOUT hMidiOut, UINT* lpuDeviceID)
1107 TRACE("(%p, %p)\n", hMidiOut, lpuDeviceID);
1109 if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
1110 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1111 return MMSYSERR_INVALHANDLE;
1113 *lpuDeviceID = wmld->uDeviceID;
1114 return MMSYSERR_NOERROR;
1117 /**************************************************************************
1118 * midiOutMessage [WINMM.@]
1120 UINT WINAPI midiOutMessage(HMIDIOUT hMidiOut, UINT uMessage,
1121 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1125 TRACE("(%p, %04X, %08lX, %08lX)\n", hMidiOut, uMessage, dwParam1, dwParam2);
1127 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL) {
1129 if (uMessage == 0x0001) {
1130 *(LPDWORD)dwParam1 = 1;
1133 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, TRUE)) != NULL) {
1134 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
1136 return MMSYSERR_INVALHANDLE;
1142 FIXME("can't handle OPEN or CLOSE message!\n");
1143 return MMSYSERR_NOTSUPPORTED;
1145 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
1148 /**************************************************************************
1149 * midiInGetNumDevs [WINMM.@]
1151 UINT WINAPI midiInGetNumDevs(void)
1153 return MMDRV_GetNum(MMDRV_MIDIIN);
1156 /**************************************************************************
1157 * midiInGetDevCapsW [WINMM.@]
1159 UINT WINAPI midiInGetDevCapsW(UINT_PTR uDeviceID, LPMIDIINCAPSW lpCaps, UINT uSize)
1163 TRACE("(%d, %p, %d);\n", uDeviceID, lpCaps, uSize);
1165 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
1167 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_MIDIIN, TRUE)) == NULL)
1168 return MMSYSERR_INVALHANDLE;
1170 return MMDRV_Message(wmld, MIDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
1173 /**************************************************************************
1174 * midiInGetDevCapsA [WINMM.@]
1176 UINT WINAPI midiInGetDevCapsA(UINT_PTR uDeviceID, LPMIDIINCAPSA lpCaps, UINT uSize)
1181 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
1183 ret = midiInGetDevCapsW(uDeviceID, &micW, sizeof(micW));
1185 if (ret == MMSYSERR_NOERROR) {
1187 micA.wMid = micW.wMid;
1188 micA.wPid = micW.wPid;
1189 micA.vDriverVersion = micW.vDriverVersion;
1190 WideCharToMultiByte( CP_ACP, 0, micW.szPname, -1, micA.szPname,
1191 sizeof(micA.szPname), NULL, NULL );
1192 micA.dwSupport = micW.dwSupport;
1193 memcpy(lpCaps, &micA, min(uSize, sizeof(micA)));
1198 UINT MIDI_InOpen(HMIDIIN* lphMidiIn, UINT uDeviceID, DWORD_PTR dwCallback,
1199 DWORD_PTR dwInstance, DWORD dwFlags, BOOL bFrom32)
1205 TRACE("(%p, %d, %08lX, %08lX, %08X);\n",
1206 lphMidiIn, uDeviceID, dwCallback, dwInstance, dwFlags);
1208 if (lphMidiIn != NULL) *lphMidiIn = 0;
1210 lpwm = (LPWINE_MIDI)MMDRV_Alloc(sizeof(WINE_MIDI), MMDRV_MIDIIN, &hMidiIn,
1211 &dwFlags, &dwCallback, &dwInstance, bFrom32);
1214 return MMSYSERR_NOMEM;
1216 lpwm->mod.hMidi = (HMIDI) hMidiIn;
1217 lpwm->mod.dwCallback = dwCallback;
1218 lpwm->mod.dwInstance = dwInstance;
1220 lpwm->mld.uDeviceID = uDeviceID;
1221 dwRet = MMDRV_Open(&lpwm->mld, MIDM_OPEN, (DWORD)&lpwm->mod, dwFlags);
1223 if (dwRet != MMSYSERR_NOERROR) {
1224 MMDRV_Free(hMidiIn, &lpwm->mld);
1227 if (lphMidiIn != NULL) *lphMidiIn = hMidiIn;
1228 TRACE("=> %d hMidi=%p\n", dwRet, hMidiIn);
1233 /**************************************************************************
1234 * midiInOpen [WINMM.@]
1236 UINT WINAPI midiInOpen(HMIDIIN* lphMidiIn, UINT uDeviceID,
1237 DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD dwFlags)
1239 return MIDI_InOpen(lphMidiIn, uDeviceID, dwCallback, dwInstance, dwFlags, TRUE);
1242 /**************************************************************************
1243 * midiInClose [WINMM.@]
1245 UINT WINAPI midiInClose(HMIDIIN hMidiIn)
1250 TRACE("(%p)\n", hMidiIn);
1252 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1253 return MMSYSERR_INVALHANDLE;
1255 dwRet = MMDRV_Close(wmld, MIDM_CLOSE);
1256 MMDRV_Free(hMidiIn, wmld);
1260 /**************************************************************************
1261 * midiInPrepareHeader [WINMM.@]
1263 UINT WINAPI midiInPrepareHeader(HMIDIIN hMidiIn,
1264 MIDIHDR* lpMidiInHdr, UINT uSize)
1268 TRACE("(%p, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
1270 if (lpMidiInHdr == NULL || uSize < sizeof (MIDIHDR))
1271 return MMSYSERR_INVALPARAM;
1273 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1274 return MMSYSERR_INVALHANDLE;
1276 return MMDRV_Message(wmld, MIDM_PREPARE, (DWORD_PTR)lpMidiInHdr, uSize, TRUE);
1279 /**************************************************************************
1280 * midiInUnprepareHeader [WINMM.@]
1282 UINT WINAPI midiInUnprepareHeader(HMIDIIN hMidiIn,
1283 MIDIHDR* lpMidiInHdr, UINT uSize)
1287 TRACE("(%p, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
1289 if (lpMidiInHdr == NULL || uSize < sizeof (MIDIHDR))
1290 return MMSYSERR_INVALPARAM;
1292 if (!(lpMidiInHdr->dwFlags & MHDR_PREPARED)) {
1293 return MMSYSERR_NOERROR;
1296 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1297 return MMSYSERR_INVALHANDLE;
1299 return MMDRV_Message(wmld, MIDM_UNPREPARE, (DWORD_PTR)lpMidiInHdr, uSize, TRUE);
1302 /**************************************************************************
1303 * midiInAddBuffer [WINMM.@]
1305 UINT WINAPI midiInAddBuffer(HMIDIIN hMidiIn,
1306 MIDIHDR* lpMidiInHdr, UINT uSize)
1310 TRACE("(%p, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
1312 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1313 return MMSYSERR_INVALHANDLE;
1315 return MMDRV_Message(wmld, MIDM_ADDBUFFER, (DWORD_PTR)lpMidiInHdr, uSize, TRUE);
1318 /**************************************************************************
1319 * midiInStart [WINMM.@]
1321 UINT WINAPI midiInStart(HMIDIIN hMidiIn)
1325 TRACE("(%p)\n", hMidiIn);
1327 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1328 return MMSYSERR_INVALHANDLE;
1330 return MMDRV_Message(wmld, MIDM_START, 0L, 0L, TRUE);
1333 /**************************************************************************
1334 * midiInStop [WINMM.@]
1336 UINT WINAPI midiInStop(HMIDIIN hMidiIn)
1340 TRACE("(%p)\n", hMidiIn);
1342 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1343 return MMSYSERR_INVALHANDLE;
1345 return MMDRV_Message(wmld, MIDM_STOP, 0L, 0L, TRUE);
1348 /**************************************************************************
1349 * midiInReset [WINMM.@]
1351 UINT WINAPI midiInReset(HMIDIIN hMidiIn)
1355 TRACE("(%p)\n", hMidiIn);
1357 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1358 return MMSYSERR_INVALHANDLE;
1360 return MMDRV_Message(wmld, MIDM_RESET, 0L, 0L, TRUE);
1363 /**************************************************************************
1364 * midiInGetID [WINMM.@]
1366 UINT WINAPI midiInGetID(HMIDIIN hMidiIn, UINT* lpuDeviceID)
1370 TRACE("(%p, %p)\n", hMidiIn, lpuDeviceID);
1372 if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
1374 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, TRUE)) == NULL)
1375 return MMSYSERR_INVALHANDLE;
1377 *lpuDeviceID = wmld->uDeviceID;
1379 return MMSYSERR_NOERROR;
1382 /**************************************************************************
1383 * midiInMessage [WINMM.@]
1385 UINT WINAPI midiInMessage(HMIDIIN hMidiIn, UINT uMessage,
1386 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1390 TRACE("(%p, %04X, %08lX, %08lX)\n", hMidiIn, uMessage, dwParam1, dwParam2);
1392 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1393 return MMSYSERR_INVALHANDLE;
1398 FIXME("can't handle OPEN or CLOSE message!\n");
1399 return MMSYSERR_NOTSUPPORTED;
1401 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
1404 typedef struct WINE_MIDIStream {
1415 LPMIDIHDR lpMidiHdr;
1418 #define WINE_MSM_HEADER (WM_USER+0)
1419 #define WINE_MSM_STOP (WM_USER+1)
1421 /**************************************************************************
1422 * MMSYSTEM_GetMidiStream [internal]
1424 static BOOL MMSYSTEM_GetMidiStream(HMIDISTRM hMidiStrm, WINE_MIDIStream** lpMidiStrm, WINE_MIDI** lplpwm)
1426 WINE_MIDI* lpwm = (LPWINE_MIDI)MMDRV_Get(hMidiStrm, MMDRV_MIDIOUT, FALSE);
1435 *lpMidiStrm = (WINE_MIDIStream*)lpwm->mod.rgIds.dwStreamID;
1437 return *lpMidiStrm != NULL;
1440 /**************************************************************************
1441 * MMSYSTEM_MidiStream_Convert [internal]
1443 static DWORD MMSYSTEM_MidiStream_Convert(WINE_MIDIStream* lpMidiStrm, DWORD pulse)
1447 if (lpMidiStrm->dwTimeDiv == 0) {
1448 FIXME("Shouldn't happen. lpMidiStrm->dwTimeDiv = 0\n");
1449 } else if (lpMidiStrm->dwTimeDiv > 0x8000) { /* SMPTE, unchecked FIXME? */
1450 int nf = -(char)HIBYTE(lpMidiStrm->dwTimeDiv); /* number of frames */
1451 int nsf = LOBYTE(lpMidiStrm->dwTimeDiv); /* number of sub-frames */
1452 ret = (pulse * 1000) / (nf * nsf);
1454 ret = (DWORD)((double)pulse * ((double)lpMidiStrm->dwTempo / 1000) /
1455 (double)lpMidiStrm->dwTimeDiv);
1461 /**************************************************************************
1462 * MMSYSTEM_MidiStream_MessageHandler [internal]
1464 static BOOL MMSYSTEM_MidiStream_MessageHandler(WINE_MIDIStream* lpMidiStrm, LPWINE_MIDI lpwm, LPMSG msg)
1466 LPMIDIHDR lpMidiHdr;
1470 switch (msg->message) {
1472 SetEvent(lpMidiStrm->hEvent);
1476 /* this is not quite what MS doc says... */
1477 midiOutReset(lpMidiStrm->hDevice);
1478 /* empty list of already submitted buffers */
1479 for (lpMidiHdr = lpMidiStrm->lpMidiHdr; lpMidiHdr; lpMidiHdr = (LPMIDIHDR)lpMidiHdr->lpNext) {
1480 lpMidiHdr->dwFlags |= MHDR_DONE;
1481 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
1483 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1484 (HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
1485 lpwm->mod.dwInstance, (DWORD)lpMidiHdr, 0L);
1487 lpMidiStrm->lpMidiHdr = 0;
1488 SetEvent(lpMidiStrm->hEvent);
1490 case WINE_MSM_HEADER:
1491 /* sets initial tick count for first MIDIHDR */
1492 if (!lpMidiStrm->dwStartTicks)
1493 lpMidiStrm->dwStartTicks = GetTickCount();
1495 /* FIXME(EPP): "I don't understand the content of the first MIDIHDR sent
1496 * by native mcimidi, it doesn't look like a correct one".
1497 * this trick allows to throw it away... but I don't like it.
1498 * It looks like part of the file I'm trying to play and definitively looks
1499 * like raw midi content
1500 * I'd really like to understand why native mcimidi sends it. Perhaps a bad
1501 * synchronization issue where native mcimidi is still processing raw MIDI
1502 * content before generating MIDIEVENTs ?
1504 * 4c 04 89 3b 00 81 7c 99 3b 43 00 99 23 5e 04 89 L..;..|.;C..#^..
1505 * 3b 00 00 89 23 00 7c 99 3b 45 00 99 28 62 04 89 ;...#.|.;E..(b..
1506 * 3b 00 00 89 28 00 81 7c 99 3b 4e 00 99 23 5e 04 ;...(..|.;N..#^.
1507 * 89 3b 00 00 89 23 00 7c 99 3b 45 00 99 23 78 04 .;...#.|.;E..#x.
1508 * 89 3b 00 00 89 23 00 81 7c 99 3b 48 00 99 23 5e .;...#..|.;H..#^
1509 * 04 89 3b 00 00 89 23 00 7c 99 3b 4e 00 99 28 62 ..;...#.|.;N..(b
1510 * 04 89 3b 00 00 89 28 00 81 7c 99 39 4c 00 99 23 ..;...(..|.9L..#
1511 * 5e 04 89 39 00 00 89 23 00 82 7c 99 3b 4c 00 99 ^..9...#..|.;L..
1512 * 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 00 99 #^..;...#.|.;H..
1513 * 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b 3f 04 (b..;...(..|.;?.
1514 * 89 3b 00 1c 99 23 5e 04 89 23 00 5c 99 3b 45 00 .;...#^..#.\.;E.
1515 * 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 3b 46 .#x..;...#..|.;F
1516 * 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 ..#^..;...#.|.;H
1517 * 00 99 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b ..(b..;...(..|.;
1518 * 46 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b F..#^..;...#.|.;
1519 * 48 00 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 H..#x..;...#..|.
1520 * 3b 4c 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 ;L..#^..;...#.|.
1522 lpMidiHdr = (LPMIDIHDR)msg->lParam;
1523 lpData = (LPBYTE)lpMidiHdr->lpData;
1524 TRACE("Adding %s lpMidiHdr=%p [lpData=0x%p dwBufferLength=%u/%u dwFlags=0x%08x size=%u]\n",
1525 (lpMidiHdr->dwFlags & MHDR_ISSTRM) ? "stream" : "regular", lpMidiHdr,
1526 lpMidiHdr, lpMidiHdr->dwBufferLength, lpMidiHdr->dwBytesRecorded,
1527 lpMidiHdr->dwFlags, msg->wParam);
1529 /* dumps content of lpMidiHdr->lpData
1530 * FIXME: there should be a debug routine somewhere that already does this
1531 * I hate spreading this type of shit all around the code
1533 for (dwToGo = 0; dwToGo < lpMidiHdr->dwBufferLength; dwToGo += 16) {
1537 for (i = 0; i < min(16, lpMidiHdr->dwBufferLength - dwToGo); i++)
1538 printf("%02x ", lpData[dwToGo + i]);
1541 for (i = 0; i < min(16, lpMidiHdr->dwBufferLength - dwToGo); i++) {
1542 ch = lpData[dwToGo + i];
1543 printf("%c", (ch >= 0x20 && ch <= 0x7F) ? ch : '.');
1548 if (((LPMIDIEVENT)lpData)->dwStreamID != 0 &&
1549 ((LPMIDIEVENT)lpData)->dwStreamID != 0xFFFFFFFF &&
1550 ((LPMIDIEVENT)lpData)->dwStreamID != (DWORD)lpMidiStrm) {
1551 FIXME("Dropping bad %s lpMidiHdr (streamID=%08x)\n",
1552 (lpMidiHdr->dwFlags & MHDR_ISSTRM) ? "stream" : "regular",
1553 ((LPMIDIEVENT)lpData)->dwStreamID);
1554 lpMidiHdr->dwFlags |= MHDR_DONE;
1555 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
1557 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1558 (HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
1559 lpwm->mod.dwInstance, (DWORD)lpMidiHdr, 0L);
1563 for (lpmh = &lpMidiStrm->lpMidiHdr; *lpmh; lpmh = (LPMIDIHDR*)&((*lpmh)->lpNext));
1565 lpMidiHdr = (LPMIDIHDR)msg->lParam;
1566 lpMidiHdr->lpNext = 0;
1567 lpMidiHdr->dwFlags |= MHDR_INQUEUE;
1568 lpMidiHdr->dwFlags &= ~MHDR_DONE;
1569 lpMidiHdr->dwOffset = 0;
1573 FIXME("Unknown message %d\n", msg->message);
1579 /**************************************************************************
1580 * MMSYSTEM_MidiStream_Player [internal]
1582 static DWORD CALLBACK MMSYSTEM_MidiStream_Player(LPVOID pmt)
1584 WINE_MIDIStream* lpMidiStrm = pmt;
1589 LPMIDIHDR lpMidiHdr;
1593 TRACE("(%p)!\n", lpMidiStrm);
1596 (lpwm = (LPWINE_MIDI)MMDRV_Get(lpMidiStrm->hDevice, MMDRV_MIDIOUT, FALSE)) == NULL)
1599 /* force thread's queue creation */
1600 /* Used to be InitThreadInput16(0, 5); */
1601 /* but following works also with hack in midiStreamOpen */
1602 PeekMessageA(&msg, 0, 0, 0, 0);
1604 /* FIXME: this next line must be called before midiStreamOut or midiStreamRestart are called */
1605 SetEvent(lpMidiStrm->hEvent);
1606 TRACE("Ready to go 1\n");
1607 /* thread is started in paused mode */
1608 SuspendThread(lpMidiStrm->hThread);
1609 TRACE("Ready to go 2\n");
1611 lpMidiStrm->dwStartTicks = 0;
1612 lpMidiStrm->dwPulses = 0;
1614 lpMidiStrm->lpMidiHdr = 0;
1617 lpMidiHdr = lpMidiStrm->lpMidiHdr;
1619 /* for first message, block until one arrives, then process all that are available */
1620 GetMessageA(&msg, 0, 0, 0);
1622 if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm, lpwm, &msg))
1624 } while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE));
1630 lpData = (LPBYTE)lpMidiHdr->lpData;
1632 me = (LPMIDIEVENT)(lpData + lpMidiHdr->dwOffset);
1634 /* do we have to wait ? */
1635 if (me->dwDeltaTime) {
1636 lpMidiStrm->dwPositionMS += MMSYSTEM_MidiStream_Convert(lpMidiStrm, me->dwDeltaTime);
1637 lpMidiStrm->dwPulses += me->dwDeltaTime;
1639 dwToGo = lpMidiStrm->dwStartTicks + lpMidiStrm->dwPositionMS;
1641 TRACE("%d/%d/%d\n", dwToGo, GetTickCount(), me->dwDeltaTime);
1642 while ((dwCurrTC = GetTickCount()) < dwToGo) {
1643 if (MsgWaitForMultipleObjects(0, NULL, FALSE, dwToGo - dwCurrTC, QS_ALLINPUT) == WAIT_OBJECT_0) {
1644 /* got a message, handle it */
1645 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) {
1646 if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm, lpwm, &msg))
1651 /* timeout, so me->dwDeltaTime is elapsed, can break the while loop */
1656 switch (MEVT_EVENTTYPE(me->dwEvent & ~MEVT_F_CALLBACK)) {
1658 FIXME("NIY: MEVT_COMMENT\n");
1659 /* do nothing, skip bytes */
1662 FIXME("NIY: MEVT_LONGMSG, aka sending Sysex event\n");
1667 midiOutShortMsg(lpMidiStrm->hDevice, MEVT_EVENTPARM(me->dwEvent));
1670 lpMidiStrm->dwTempo = MEVT_EVENTPARM(me->dwEvent);
1675 FIXME("Unknown MEVT (0x%02x)\n", MEVT_EVENTTYPE(me->dwEvent & ~MEVT_F_CALLBACK));
1678 if (me->dwEvent & MEVT_F_CALLBACK) {
1679 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1680 (HDRVR)lpMidiStrm->hDevice, MM_MOM_POSITIONCB,
1681 lpwm->mod.dwInstance, (LPARAM)lpMidiHdr, 0L);
1683 lpMidiHdr->dwOffset += sizeof(MIDIEVENT) - sizeof(me->dwParms);
1684 if (me->dwEvent & MEVT_F_LONG)
1685 lpMidiHdr->dwOffset += (MEVT_EVENTPARM(me->dwEvent) + 3) & ~3;
1686 if (lpMidiHdr->dwOffset >= lpMidiHdr->dwBufferLength) {
1687 /* done with this header */
1688 lpMidiHdr->dwFlags |= MHDR_DONE;
1689 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
1691 lpMidiStrm->lpMidiHdr = (LPMIDIHDR)lpMidiHdr->lpNext;
1692 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1693 (HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
1694 lpwm->mod.dwInstance, (DWORD)lpMidiHdr, 0L);
1699 TRACE("End of thread\n");
1701 return 0; /* for removing the warning, never executed */
1704 /**************************************************************************
1705 * MMSYSTEM_MidiStream_PostMessage [internal]
1707 static BOOL MMSYSTEM_MidiStream_PostMessage(WINE_MIDIStream* lpMidiStrm, WORD msg, DWORD pmt1, DWORD pmt2)
1709 if (PostThreadMessageA(lpMidiStrm->dwThreadID, msg, pmt1, pmt2)) {
1712 if (pFnReleaseThunkLock) pFnReleaseThunkLock(&count);
1713 WaitForSingleObject(lpMidiStrm->hEvent, INFINITE);
1714 if (pFnRestoreThunkLock) pFnRestoreThunkLock(count);
1716 WARN("bad PostThreadMessageA\n");
1722 /**************************************************************************
1723 * midiStreamClose [WINMM.@]
1725 MMRESULT WINAPI midiStreamClose(HMIDISTRM hMidiStrm)
1727 WINE_MIDIStream* lpMidiStrm;
1729 TRACE("(%p)!\n", hMidiStrm);
1731 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL))
1732 return MMSYSERR_INVALHANDLE;
1734 midiStreamStop(hMidiStrm);
1735 MMSYSTEM_MidiStream_PostMessage(lpMidiStrm, WM_QUIT, 0, 0);
1736 HeapFree(GetProcessHeap(), 0, lpMidiStrm);
1737 CloseHandle(lpMidiStrm->hEvent);
1739 return midiOutClose((HMIDIOUT)hMidiStrm);
1742 /**************************************************************************
1743 * MMSYSTEM_MidiStream_Open [internal]
1745 MMRESULT MIDI_StreamOpen(HMIDISTRM* lphMidiStrm, LPUINT lpuDeviceID, DWORD cMidi,
1746 DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD fdwOpen,
1749 WINE_MIDIStream* lpMidiStrm;
1751 MIDIOPENSTRMID mosm;
1755 TRACE("(%p, %p, %d, 0x%08lx, 0x%08lx, 0x%08x)!\n",
1756 lphMidiStrm, lpuDeviceID, cMidi, dwCallback, dwInstance, fdwOpen);
1758 if (cMidi != 1 || lphMidiStrm == NULL || lpuDeviceID == NULL)
1759 return MMSYSERR_INVALPARAM;
1761 lpMidiStrm = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_MIDIStream));
1763 return MMSYSERR_NOMEM;
1765 lpMidiStrm->dwTempo = 500000;
1766 lpMidiStrm->dwTimeDiv = 480; /* 480 is 120 quater notes per minute *//* FIXME ??*/
1767 lpMidiStrm->dwPositionMS = 0;
1769 mosm.dwStreamID = (DWORD)lpMidiStrm;
1770 /* FIXME: the correct value is not allocated yet for MAPPER */
1771 mosm.wDeviceID = *lpuDeviceID;
1772 lpwm = MIDI_OutAlloc(&hMidiOut, &dwCallback, &dwInstance, &fdwOpen, 1, &mosm, bFrom32);
1773 lpMidiStrm->hDevice = hMidiOut;
1775 *lphMidiStrm = (HMIDISTRM)hMidiOut;
1777 lpwm->mld.uDeviceID = *lpuDeviceID;
1779 ret = MMDRV_Open(&lpwm->mld, MODM_OPEN, (DWORD)&lpwm->mod, fdwOpen);
1780 lpMidiStrm->hEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
1781 lpMidiStrm->wFlags = HIWORD(fdwOpen);
1783 lpMidiStrm->hThread = CreateThread(NULL, 0, MMSYSTEM_MidiStream_Player,
1784 lpMidiStrm, 0, &(lpMidiStrm->dwThreadID));
1786 if (!lpMidiStrm->hThread) {
1787 midiStreamClose((HMIDISTRM)hMidiOut);
1788 return MMSYSERR_NOMEM;
1790 SetThreadPriority(lpMidiStrm->hThread, THREAD_PRIORITY_TIME_CRITICAL);
1792 /* wait for thread to have started, and for its queue to be created */
1796 /* (Release|Restore)ThunkLock() is needed when this method is called from 16 bit code,
1797 * (meaning the Win16Lock is set), so that it's released and the 32 bit thread running
1798 * MMSYSTEM_MidiStreamPlayer can acquire Win16Lock to create its queue.
1800 if (pFnReleaseThunkLock) pFnReleaseThunkLock(&count);
1801 WaitForSingleObject(lpMidiStrm->hEvent, INFINITE);
1802 if (pFnRestoreThunkLock) pFnRestoreThunkLock(count);
1805 TRACE("=> (%u/%d) hMidi=%p ret=%d lpMidiStrm=%p\n",
1806 *lpuDeviceID, lpwm->mld.uDeviceID, *lphMidiStrm, ret, lpMidiStrm);
1810 /**************************************************************************
1811 * midiStreamOpen [WINMM.@]
1813 MMRESULT WINAPI midiStreamOpen(HMIDISTRM* lphMidiStrm, LPUINT lpuDeviceID,
1814 DWORD cMidi, DWORD_PTR dwCallback,
1815 DWORD_PTR dwInstance, DWORD fdwOpen)
1817 return MIDI_StreamOpen(lphMidiStrm, lpuDeviceID, cMidi, dwCallback,
1818 dwInstance, fdwOpen, TRUE);
1821 /**************************************************************************
1822 * midiStreamOut [WINMM.@]
1824 MMRESULT WINAPI midiStreamOut(HMIDISTRM hMidiStrm, LPMIDIHDR lpMidiHdr,
1827 WINE_MIDIStream* lpMidiStrm;
1828 DWORD ret = MMSYSERR_NOERROR;
1830 TRACE("(%p, %p, %u)!\n", hMidiStrm, lpMidiHdr, cbMidiHdr);
1832 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1833 ret = MMSYSERR_INVALHANDLE;
1834 } else if (!lpMidiHdr) {
1835 ret = MMSYSERR_INVALPARAM;
1837 if (!PostThreadMessageA(lpMidiStrm->dwThreadID,
1838 WINE_MSM_HEADER, cbMidiHdr,
1839 (DWORD)lpMidiHdr)) {
1840 WARN("bad PostThreadMessageA\n");
1841 ret = MMSYSERR_ERROR;
1847 /**************************************************************************
1848 * midiStreamPause [WINMM.@]
1850 MMRESULT WINAPI midiStreamPause(HMIDISTRM hMidiStrm)
1852 WINE_MIDIStream* lpMidiStrm;
1853 DWORD ret = MMSYSERR_NOERROR;
1855 TRACE("(%p)!\n", hMidiStrm);
1857 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1858 ret = MMSYSERR_INVALHANDLE;
1860 if (SuspendThread(lpMidiStrm->hThread) == 0xFFFFFFFF) {
1861 WARN("bad Suspend (%d)\n", GetLastError());
1862 ret = MMSYSERR_ERROR;
1868 /**************************************************************************
1869 * midiStreamPosition [WINMM.@]
1871 MMRESULT WINAPI midiStreamPosition(HMIDISTRM hMidiStrm, LPMMTIME lpMMT, UINT cbmmt)
1873 WINE_MIDIStream* lpMidiStrm;
1874 DWORD ret = MMSYSERR_NOERROR;
1876 TRACE("(%p, %p, %u)!\n", hMidiStrm, lpMMT, cbmmt);
1878 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1879 ret = MMSYSERR_INVALHANDLE;
1880 } else if (lpMMT == NULL || cbmmt != sizeof(MMTIME)) {
1881 ret = MMSYSERR_INVALPARAM;
1883 switch (lpMMT->wType) {
1885 lpMMT->u.ms = lpMidiStrm->dwPositionMS;
1886 TRACE("=> %d ms\n", lpMMT->u.ms);
1889 lpMMT->u.ticks = lpMidiStrm->dwPulses;
1890 TRACE("=> %d ticks\n", lpMMT->u.ticks);
1893 WARN("Unsupported time type %d\n", lpMMT->wType);
1894 lpMMT->wType = TIME_MS;
1895 ret = MMSYSERR_INVALPARAM;
1902 /**************************************************************************
1903 * midiStreamProperty [WINMM.@]
1905 MMRESULT WINAPI midiStreamProperty(HMIDISTRM hMidiStrm, LPBYTE lpPropData, DWORD dwProperty)
1907 WINE_MIDIStream* lpMidiStrm;
1908 MMRESULT ret = MMSYSERR_NOERROR;
1910 TRACE("(%p, %p, %x)\n", hMidiStrm, lpPropData, dwProperty);
1912 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1913 ret = MMSYSERR_INVALHANDLE;
1914 } else if ((dwProperty & (MIDIPROP_GET|MIDIPROP_SET)) == 0) {
1915 ret = MMSYSERR_INVALPARAM;
1916 } else if (dwProperty & MIDIPROP_TEMPO) {
1917 MIDIPROPTEMPO* mpt = (MIDIPROPTEMPO*)lpPropData;
1919 if (sizeof(MIDIPROPTEMPO) != mpt->cbStruct) {
1920 ret = MMSYSERR_INVALPARAM;
1921 } else if (dwProperty & MIDIPROP_SET) {
1922 lpMidiStrm->dwTempo = mpt->dwTempo;
1923 TRACE("Setting tempo to %d\n", mpt->dwTempo);
1924 } else if (dwProperty & MIDIPROP_GET) {
1925 mpt->dwTempo = lpMidiStrm->dwTempo;
1926 TRACE("Getting tempo <= %d\n", mpt->dwTempo);
1928 } else if (dwProperty & MIDIPROP_TIMEDIV) {
1929 MIDIPROPTIMEDIV* mptd = (MIDIPROPTIMEDIV*)lpPropData;
1931 if (sizeof(MIDIPROPTIMEDIV) != mptd->cbStruct) {
1932 ret = MMSYSERR_INVALPARAM;
1933 } else if (dwProperty & MIDIPROP_SET) {
1934 lpMidiStrm->dwTimeDiv = mptd->dwTimeDiv;
1935 TRACE("Setting time div to %d\n", mptd->dwTimeDiv);
1936 } else if (dwProperty & MIDIPROP_GET) {
1937 mptd->dwTimeDiv = lpMidiStrm->dwTimeDiv;
1938 TRACE("Getting time div <= %d\n", mptd->dwTimeDiv);
1941 ret = MMSYSERR_INVALPARAM;
1947 /**************************************************************************
1948 * midiStreamRestart [WINMM.@]
1950 MMRESULT WINAPI midiStreamRestart(HMIDISTRM hMidiStrm)
1952 WINE_MIDIStream* lpMidiStrm;
1953 MMRESULT ret = MMSYSERR_NOERROR;
1955 TRACE("(%p)!\n", hMidiStrm);
1957 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1958 ret = MMSYSERR_INVALHANDLE;
1962 /* since we increase the thread suspend count on each midiStreamPause
1963 * there may be a need for several midiStreamResume
1966 ret = ResumeThread(lpMidiStrm->hThread);
1967 } while (ret != 0xFFFFFFFF && ret != 0);
1968 if (ret == 0xFFFFFFFF) {
1969 WARN("bad Resume (%d)\n", GetLastError());
1970 ret = MMSYSERR_ERROR;
1972 lpMidiStrm->dwStartTicks = GetTickCount() - lpMidiStrm->dwPositionMS;
1978 /**************************************************************************
1979 * midiStreamStop [WINMM.@]
1981 MMRESULT WINAPI midiStreamStop(HMIDISTRM hMidiStrm)
1983 WINE_MIDIStream* lpMidiStrm;
1984 MMRESULT ret = MMSYSERR_NOERROR;
1986 TRACE("(%p)!\n", hMidiStrm);
1988 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1989 ret = MMSYSERR_INVALHANDLE;
1991 /* in case stream has been paused... FIXME is the current state correct ? */
1992 midiStreamRestart(hMidiStrm);
1993 MMSYSTEM_MidiStream_PostMessage(lpMidiStrm, WINE_MSM_STOP, 0, 0);
1998 UINT WAVE_Open(HANDLE* lphndl, UINT uDeviceID, UINT uType,
1999 LPCWAVEFORMATEX lpFormat, DWORD_PTR dwCallback,
2000 DWORD_PTR dwInstance, DWORD dwFlags, BOOL bFrom32)
2004 DWORD dwRet = MMSYSERR_NOERROR;
2007 TRACE("(%p, %d, %s, %p, %08lX, %08lX, %08X, %d);\n",
2008 lphndl, (int)uDeviceID, (uType==MMDRV_WAVEOUT)?"Out":"In", lpFormat, dwCallback,
2009 dwInstance, dwFlags, bFrom32?32:16);
2011 if (dwFlags & WAVE_FORMAT_QUERY)
2012 TRACE("WAVE_FORMAT_QUERY requested !\n");
2014 if (lpFormat == NULL) {
2015 WARN("bad format\n");
2016 return WAVERR_BADFORMAT;
2019 if ((dwFlags & WAVE_MAPPED) && (uDeviceID == (UINT)-1)) {
2020 WARN("invalid parameter\n");
2021 return MMSYSERR_INVALPARAM;
2024 /* may have a PCMWAVEFORMAT rather than a WAVEFORMATEX so don't read cbSize */
2025 TRACE("wFormatTag=%u, nChannels=%u, nSamplesPerSec=%u, nAvgBytesPerSec=%u, nBlockAlign=%u, wBitsPerSample=%u\n",
2026 lpFormat->wFormatTag, lpFormat->nChannels, lpFormat->nSamplesPerSec,
2027 lpFormat->nAvgBytesPerSec, lpFormat->nBlockAlign, lpFormat->wBitsPerSample);
2029 if ((wmld = MMDRV_Alloc(sizeof(WINE_WAVE), uType, &handle,
2030 &dwFlags, &dwCallback, &dwInstance, bFrom32)) == NULL) {
2031 WARN("no memory\n");
2032 return MMSYSERR_NOMEM;
2036 wod.lpFormat = (LPWAVEFORMATEX)lpFormat; /* should the struct be copied iso pointer? */
2037 wod.dwCallback = dwCallback;
2038 wod.dwInstance = dwInstance;
2041 TRACE("cb=%08x\n", wod.dwCallback);
2044 if (dwFlags & WAVE_MAPPED) {
2045 wod.uMappedDeviceID = uDeviceID;
2046 uDeviceID = WAVE_MAPPER;
2048 wod.uMappedDeviceID = -1;
2050 wmld->uDeviceID = uDeviceID;
2052 dwRet = MMDRV_Open(wmld, (uType == MMDRV_WAVEOUT) ? WODM_OPEN : WIDM_OPEN,
2053 (DWORD)&wod, dwFlags);
2055 TRACE("dwRet = %s\n", WINMM_ErrorToString(dwRet));
2056 if (dwRet != WAVERR_BADFORMAT ||
2057 ((dwFlags & (WAVE_MAPPED|WAVE_FORMAT_DIRECT)) != 0) || (uDeviceID == WAVE_MAPPER)) break;
2058 /* if we ask for a format which isn't supported by the physical driver,
2059 * let's try to map it through the wave mapper (except, if we already tried
2060 * or user didn't allow us to use acm codecs or the device is already the mapper)
2062 dwFlags |= WAVE_MAPPED;
2063 /* we shall loop only one */
2066 if ((dwFlags & WAVE_FORMAT_QUERY) || dwRet != MMSYSERR_NOERROR) {
2067 MMDRV_Free(handle, wmld);
2071 if (lphndl != NULL) *lphndl = handle;
2072 TRACE("=> %s hWave=%p\n", WINMM_ErrorToString(dwRet), handle);
2077 /**************************************************************************
2078 * waveOutGetNumDevs [WINMM.@]
2080 UINT WINAPI waveOutGetNumDevs(void)
2082 return MMDRV_GetNum(MMDRV_WAVEOUT);
2085 /**************************************************************************
2086 * waveOutGetDevCapsA [WINMM.@]
2088 UINT WINAPI waveOutGetDevCapsA(UINT_PTR uDeviceID, LPWAVEOUTCAPSA lpCaps,
2094 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2096 ret = waveOutGetDevCapsW(uDeviceID, &wocW, sizeof(wocW));
2098 if (ret == MMSYSERR_NOERROR) {
2100 wocA.wMid = wocW.wMid;
2101 wocA.wPid = wocW.wPid;
2102 wocA.vDriverVersion = wocW.vDriverVersion;
2103 WideCharToMultiByte( CP_ACP, 0, wocW.szPname, -1, wocA.szPname,
2104 sizeof(wocA.szPname), NULL, NULL );
2105 wocA.dwFormats = wocW.dwFormats;
2106 wocA.wChannels = wocW.wChannels;
2107 wocA.dwSupport = wocW.dwSupport;
2108 memcpy(lpCaps, &wocA, min(uSize, sizeof(wocA)));
2113 /**************************************************************************
2114 * waveOutGetDevCapsW [WINMM.@]
2116 UINT WINAPI waveOutGetDevCapsW(UINT_PTR uDeviceID, LPWAVEOUTCAPSW lpCaps,
2121 TRACE("(%u %p %u)!\n", uDeviceID, lpCaps, uSize);
2123 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2125 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_WAVEOUT, TRUE)) == NULL)
2126 return MMSYSERR_BADDEVICEID;
2128 return MMDRV_Message(wmld, WODM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
2132 /**************************************************************************
2133 * waveOutGetErrorTextA [WINMM.@]
2134 * waveInGetErrorTextA [WINMM.@]
2136 UINT WINAPI waveOutGetErrorTextA(UINT uError, LPSTR lpText, UINT uSize)
2140 if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
2141 else if (uSize == 0) ret = MMSYSERR_NOERROR;
2144 LPWSTR xstr = HeapAlloc(GetProcessHeap(), 0, uSize * sizeof(WCHAR));
2145 if (!xstr) ret = MMSYSERR_NOMEM;
2148 ret = waveOutGetErrorTextW(uError, xstr, uSize);
2149 if (ret == MMSYSERR_NOERROR)
2150 WideCharToMultiByte(CP_ACP, 0, xstr, -1, lpText, uSize, NULL, NULL);
2151 HeapFree(GetProcessHeap(), 0, xstr);
2157 /**************************************************************************
2158 * waveOutGetErrorTextW [WINMM.@]
2159 * waveInGetErrorTextW [WINMM.@]
2161 UINT WINAPI waveOutGetErrorTextW(UINT uError, LPWSTR lpText, UINT uSize)
2163 UINT ret = MMSYSERR_BADERRNUM;
2165 if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
2166 else if (uSize == 0) ret = MMSYSERR_NOERROR;
2168 /* test has been removed 'coz MMSYSERR_BASE is 0, and gcc did emit
2169 * a warning for the test was always true */
2170 (/*uError >= MMSYSERR_BASE && */ uError <= MMSYSERR_LASTERROR) ||
2171 (uError >= WAVERR_BASE && uError <= WAVERR_LASTERROR)) {
2172 if (LoadStringW(WINMM_IData.hWinMM32Instance,
2173 uError, lpText, uSize) > 0) {
2174 ret = MMSYSERR_NOERROR;
2180 /**************************************************************************
2181 * waveOutOpen [WINMM.@]
2182 * All the args/structs have the same layout as the win16 equivalents
2184 MMRESULT WINAPI waveOutOpen(LPHWAVEOUT lphWaveOut, UINT uDeviceID,
2185 LPCWAVEFORMATEX lpFormat, DWORD_PTR dwCallback,
2186 DWORD_PTR dwInstance, DWORD dwFlags)
2188 return WAVE_Open((HANDLE*)lphWaveOut, uDeviceID, MMDRV_WAVEOUT, lpFormat,
2189 dwCallback, dwInstance, dwFlags, TRUE);
2192 /**************************************************************************
2193 * waveOutClose [WINMM.@]
2195 UINT WINAPI waveOutClose(HWAVEOUT hWaveOut)
2200 TRACE("(%p)\n", hWaveOut);
2202 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2203 return MMSYSERR_INVALHANDLE;
2205 dwRet = MMDRV_Close(wmld, WODM_CLOSE);
2206 if (dwRet != WAVERR_STILLPLAYING)
2207 MMDRV_Free(hWaveOut, wmld);
2212 /**************************************************************************
2213 * waveOutPrepareHeader [WINMM.@]
2215 UINT WINAPI waveOutPrepareHeader(HWAVEOUT hWaveOut,
2216 WAVEHDR* lpWaveOutHdr, UINT uSize)
2221 TRACE("(%p, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
2223 if (lpWaveOutHdr == NULL || uSize < sizeof (WAVEHDR))
2224 return MMSYSERR_INVALPARAM;
2226 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2227 return MMSYSERR_INVALHANDLE;
2229 if ((result = MMDRV_Message(wmld, WODM_PREPARE, (DWORD_PTR)lpWaveOutHdr,
2230 uSize, TRUE)) != MMSYSERR_NOTSUPPORTED)
2233 if (lpWaveOutHdr->dwFlags & WHDR_INQUEUE)
2234 return WAVERR_STILLPLAYING;
2236 lpWaveOutHdr->dwFlags |= WHDR_PREPARED;
2237 lpWaveOutHdr->dwFlags &= ~WHDR_DONE;
2239 return MMSYSERR_NOERROR;
2242 /**************************************************************************
2243 * waveOutUnprepareHeader [WINMM.@]
2245 UINT WINAPI waveOutUnprepareHeader(HWAVEOUT hWaveOut,
2246 LPWAVEHDR lpWaveOutHdr, UINT uSize)
2251 TRACE("(%p, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
2253 if (lpWaveOutHdr == NULL || uSize < sizeof (WAVEHDR))
2254 return MMSYSERR_INVALPARAM;
2256 if (!(lpWaveOutHdr->dwFlags & WHDR_PREPARED)) {
2257 return MMSYSERR_NOERROR;
2260 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2261 return MMSYSERR_INVALHANDLE;
2263 if ((result = MMDRV_Message(wmld, WODM_UNPREPARE, (DWORD_PTR)lpWaveOutHdr,
2264 uSize, TRUE)) != MMSYSERR_NOTSUPPORTED)
2267 if (lpWaveOutHdr->dwFlags & WHDR_INQUEUE)
2268 return WAVERR_STILLPLAYING;
2270 lpWaveOutHdr->dwFlags &= ~WHDR_PREPARED;
2271 lpWaveOutHdr->dwFlags |= WHDR_DONE;
2273 return MMSYSERR_NOERROR;
2276 /**************************************************************************
2277 * waveOutWrite [WINMM.@]
2279 UINT WINAPI waveOutWrite(HWAVEOUT hWaveOut, LPWAVEHDR lpWaveOutHdr,
2284 TRACE("(%p, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
2286 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2287 return MMSYSERR_INVALHANDLE;
2289 return MMDRV_Message(wmld, WODM_WRITE, (DWORD_PTR)lpWaveOutHdr, uSize, TRUE);
2292 /**************************************************************************
2293 * waveOutBreakLoop [WINMM.@]
2295 UINT WINAPI waveOutBreakLoop(HWAVEOUT hWaveOut)
2299 TRACE("(%p);\n", hWaveOut);
2301 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2302 return MMSYSERR_INVALHANDLE;
2303 return MMDRV_Message(wmld, WODM_BREAKLOOP, 0L, 0L, TRUE);
2306 /**************************************************************************
2307 * waveOutPause [WINMM.@]
2309 UINT WINAPI waveOutPause(HWAVEOUT hWaveOut)
2313 TRACE("(%p);\n", hWaveOut);
2315 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2316 return MMSYSERR_INVALHANDLE;
2317 return MMDRV_Message(wmld, WODM_PAUSE, 0L, 0L, TRUE);
2320 /**************************************************************************
2321 * waveOutReset [WINMM.@]
2323 UINT WINAPI waveOutReset(HWAVEOUT hWaveOut)
2327 TRACE("(%p);\n", hWaveOut);
2329 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2330 return MMSYSERR_INVALHANDLE;
2331 return MMDRV_Message(wmld, WODM_RESET, 0L, 0L, TRUE);
2334 /**************************************************************************
2335 * waveOutRestart [WINMM.@]
2337 UINT WINAPI waveOutRestart(HWAVEOUT hWaveOut)
2341 TRACE("(%p);\n", hWaveOut);
2343 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2344 return MMSYSERR_INVALHANDLE;
2345 return MMDRV_Message(wmld, WODM_RESTART, 0L, 0L, TRUE);
2348 /**************************************************************************
2349 * waveOutGetPosition [WINMM.@]
2351 UINT WINAPI waveOutGetPosition(HWAVEOUT hWaveOut, LPMMTIME lpTime,
2356 TRACE("(%p, %p, %u);\n", hWaveOut, lpTime, uSize);
2358 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2359 return MMSYSERR_INVALHANDLE;
2361 return MMDRV_Message(wmld, WODM_GETPOS, (DWORD_PTR)lpTime, uSize, TRUE);
2364 /**************************************************************************
2365 * waveOutGetPitch [WINMM.@]
2367 UINT WINAPI waveOutGetPitch(HWAVEOUT hWaveOut, LPDWORD lpdw)
2371 TRACE("(%p, %p);\n", hWaveOut, lpdw);
2373 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2374 return MMSYSERR_INVALHANDLE;
2375 return MMDRV_Message(wmld, WODM_GETPITCH, (DWORD_PTR)lpdw, 0L, TRUE);
2378 /**************************************************************************
2379 * waveOutSetPitch [WINMM.@]
2381 UINT WINAPI waveOutSetPitch(HWAVEOUT hWaveOut, DWORD dw)
2385 TRACE("(%p, %08x);\n", hWaveOut, dw);
2387 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2388 return MMSYSERR_INVALHANDLE;
2389 return MMDRV_Message(wmld, WODM_SETPITCH, dw, 0L, TRUE);
2392 /**************************************************************************
2393 * waveOutGetPlaybackRate [WINMM.@]
2395 UINT WINAPI waveOutGetPlaybackRate(HWAVEOUT hWaveOut, LPDWORD lpdw)
2399 TRACE("(%p, %p);\n", hWaveOut, lpdw);
2401 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2402 return MMSYSERR_INVALHANDLE;
2403 return MMDRV_Message(wmld, WODM_GETPLAYBACKRATE, (DWORD_PTR)lpdw, 0L, TRUE);
2406 /**************************************************************************
2407 * waveOutSetPlaybackRate [WINMM.@]
2409 UINT WINAPI waveOutSetPlaybackRate(HWAVEOUT hWaveOut, DWORD dw)
2413 TRACE("(%p, %08x);\n", hWaveOut, dw);
2415 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2416 return MMSYSERR_INVALHANDLE;
2417 return MMDRV_Message(wmld, WODM_SETPLAYBACKRATE, dw, 0L, TRUE);
2420 /**************************************************************************
2421 * waveOutGetVolume [WINMM.@]
2423 UINT WINAPI waveOutGetVolume(HWAVEOUT hWaveOut, LPDWORD lpdw)
2427 TRACE("(%p, %p);\n", hWaveOut, lpdw);
2430 WARN("invalid parameter\n");
2431 return MMSYSERR_INVALPARAM;
2434 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, TRUE)) == NULL)
2435 return MMSYSERR_INVALHANDLE;
2437 return MMDRV_Message(wmld, WODM_GETVOLUME, (DWORD_PTR)lpdw, 0L, TRUE);
2440 /**************************************************************************
2441 * waveOutSetVolume [WINMM.@]
2443 UINT WINAPI waveOutSetVolume(HWAVEOUT hWaveOut, DWORD dw)
2447 TRACE("(%p, %08x);\n", hWaveOut, dw);
2449 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, TRUE)) == NULL)
2450 return MMSYSERR_INVALHANDLE;
2452 return MMDRV_Message(wmld, WODM_SETVOLUME, dw, 0L, TRUE);
2455 /**************************************************************************
2456 * waveOutGetID [WINMM.@]
2458 UINT WINAPI waveOutGetID(HWAVEOUT hWaveOut, UINT* lpuDeviceID)
2462 TRACE("(%p, %p);\n", hWaveOut, lpuDeviceID);
2464 if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
2466 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2467 return MMSYSERR_INVALHANDLE;
2469 *lpuDeviceID = wmld->uDeviceID;
2473 /**************************************************************************
2474 * waveOutMessage [WINMM.@]
2476 UINT WINAPI waveOutMessage(HWAVEOUT hWaveOut, UINT uMessage,
2477 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2481 TRACE("(%p, %u, %ld, %ld)\n", hWaveOut, uMessage, dwParam1, dwParam2);
2483 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL) {
2484 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, TRUE)) != NULL) {
2485 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
2487 WARN("invalid handle\n");
2488 return MMSYSERR_INVALHANDLE;
2492 if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER)) {
2493 WARN("invalid parameter\n");
2494 return MMSYSERR_INVALPARAM;
2497 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
2500 /**************************************************************************
2501 * waveInGetNumDevs [WINMM.@]
2503 UINT WINAPI waveInGetNumDevs(void)
2505 return MMDRV_GetNum(MMDRV_WAVEIN);
2508 /**************************************************************************
2509 * waveInGetDevCapsW [WINMM.@]
2511 UINT WINAPI waveInGetDevCapsW(UINT_PTR uDeviceID, LPWAVEINCAPSW lpCaps, UINT uSize)
2515 TRACE("(%u %p %u)!\n", uDeviceID, lpCaps, uSize);
2517 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2519 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_WAVEIN, TRUE)) == NULL)
2520 return MMSYSERR_BADDEVICEID;
2522 return MMDRV_Message(wmld, WIDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
2525 /**************************************************************************
2526 * waveInGetDevCapsA [WINMM.@]
2528 UINT WINAPI waveInGetDevCapsA(UINT_PTR uDeviceID, LPWAVEINCAPSA lpCaps, UINT uSize)
2533 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2535 ret = waveInGetDevCapsW(uDeviceID, &wicW, sizeof(wicW));
2537 if (ret == MMSYSERR_NOERROR) {
2539 wicA.wMid = wicW.wMid;
2540 wicA.wPid = wicW.wPid;
2541 wicA.vDriverVersion = wicW.vDriverVersion;
2542 WideCharToMultiByte( CP_ACP, 0, wicW.szPname, -1, wicA.szPname,
2543 sizeof(wicA.szPname), NULL, NULL );
2544 wicA.dwFormats = wicW.dwFormats;
2545 wicA.wChannels = wicW.wChannels;
2546 memcpy(lpCaps, &wicA, min(uSize, sizeof(wicA)));
2551 /**************************************************************************
2552 * waveInOpen [WINMM.@]
2554 MMRESULT WINAPI waveInOpen(HWAVEIN* lphWaveIn, UINT uDeviceID,
2555 LPCWAVEFORMATEX lpFormat, DWORD_PTR dwCallback,
2556 DWORD_PTR dwInstance, DWORD dwFlags)
2558 return WAVE_Open((HANDLE*)lphWaveIn, uDeviceID, MMDRV_WAVEIN, lpFormat,
2559 dwCallback, dwInstance, dwFlags, TRUE);
2562 /**************************************************************************
2563 * waveInClose [WINMM.@]
2565 UINT WINAPI waveInClose(HWAVEIN hWaveIn)
2570 TRACE("(%p)\n", hWaveIn);
2572 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2573 return MMSYSERR_INVALHANDLE;
2575 dwRet = MMDRV_Message(wmld, WIDM_CLOSE, 0L, 0L, TRUE);
2576 if (dwRet != WAVERR_STILLPLAYING)
2577 MMDRV_Free(hWaveIn, wmld);
2581 /**************************************************************************
2582 * waveInPrepareHeader [WINMM.@]
2584 UINT WINAPI waveInPrepareHeader(HWAVEIN hWaveIn, WAVEHDR* lpWaveInHdr,
2590 TRACE("(%p, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
2592 if (lpWaveInHdr == NULL || uSize < sizeof (WAVEHDR))
2593 return MMSYSERR_INVALPARAM;
2595 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2596 return MMSYSERR_INVALHANDLE;
2598 if ((result = MMDRV_Message(wmld, WIDM_PREPARE, (DWORD_PTR)lpWaveInHdr,
2599 uSize, TRUE)) != MMSYSERR_NOTSUPPORTED)
2602 if (lpWaveInHdr->dwFlags & WHDR_INQUEUE)
2603 return WAVERR_STILLPLAYING;
2605 lpWaveInHdr->dwFlags |= WHDR_PREPARED;
2606 lpWaveInHdr->dwFlags &= ~WHDR_DONE;
2607 lpWaveInHdr->dwBytesRecorded = 0;
2609 return MMSYSERR_NOERROR;
2612 /**************************************************************************
2613 * waveInUnprepareHeader [WINMM.@]
2615 UINT WINAPI waveInUnprepareHeader(HWAVEIN hWaveIn, WAVEHDR* lpWaveInHdr,
2621 TRACE("(%p, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
2623 if (lpWaveInHdr == NULL || uSize < sizeof (WAVEHDR))
2624 return MMSYSERR_INVALPARAM;
2626 if (!(lpWaveInHdr->dwFlags & WHDR_PREPARED))
2627 return MMSYSERR_NOERROR;
2629 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2630 return MMSYSERR_INVALHANDLE;
2632 if ((result = MMDRV_Message(wmld, WIDM_UNPREPARE, (DWORD_PTR)lpWaveInHdr,
2633 uSize, TRUE)) != MMSYSERR_NOTSUPPORTED)
2636 if (lpWaveInHdr->dwFlags & WHDR_INQUEUE)
2637 return WAVERR_STILLPLAYING;
2639 lpWaveInHdr->dwFlags &= ~WHDR_PREPARED;
2640 lpWaveInHdr->dwFlags |= WHDR_DONE;
2642 return MMSYSERR_NOERROR;
2645 /**************************************************************************
2646 * waveInAddBuffer [WINMM.@]
2648 UINT WINAPI waveInAddBuffer(HWAVEIN hWaveIn,
2649 WAVEHDR* lpWaveInHdr, UINT uSize)
2653 TRACE("(%p, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
2655 if (lpWaveInHdr == NULL) return MMSYSERR_INVALPARAM;
2656 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2657 return MMSYSERR_INVALHANDLE;
2659 return MMDRV_Message(wmld, WIDM_ADDBUFFER, (DWORD_PTR)lpWaveInHdr, uSize, TRUE);
2662 /**************************************************************************
2663 * waveInReset [WINMM.@]
2665 UINT WINAPI waveInReset(HWAVEIN hWaveIn)
2669 TRACE("(%p);\n", hWaveIn);
2671 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2672 return MMSYSERR_INVALHANDLE;
2674 return MMDRV_Message(wmld, WIDM_RESET, 0L, 0L, TRUE);
2677 /**************************************************************************
2678 * waveInStart [WINMM.@]
2680 UINT WINAPI waveInStart(HWAVEIN hWaveIn)
2684 TRACE("(%p);\n", hWaveIn);
2686 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2687 return MMSYSERR_INVALHANDLE;
2689 return MMDRV_Message(wmld, WIDM_START, 0L, 0L, TRUE);
2692 /**************************************************************************
2693 * waveInStop [WINMM.@]
2695 UINT WINAPI waveInStop(HWAVEIN hWaveIn)
2699 TRACE("(%p);\n", hWaveIn);
2701 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2702 return MMSYSERR_INVALHANDLE;
2704 return MMDRV_Message(wmld,WIDM_STOP, 0L, 0L, TRUE);
2707 /**************************************************************************
2708 * waveInGetPosition [WINMM.@]
2710 UINT WINAPI waveInGetPosition(HWAVEIN hWaveIn, LPMMTIME lpTime,
2715 TRACE("(%p, %p, %u);\n", hWaveIn, lpTime, uSize);
2717 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2718 return MMSYSERR_INVALHANDLE;
2720 return MMDRV_Message(wmld, WIDM_GETPOS, (DWORD_PTR)lpTime, uSize, TRUE);
2723 /**************************************************************************
2724 * waveInGetID [WINMM.@]
2726 UINT WINAPI waveInGetID(HWAVEIN hWaveIn, UINT* lpuDeviceID)
2730 TRACE("(%p, %p);\n", hWaveIn, lpuDeviceID);
2732 if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
2734 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2735 return MMSYSERR_INVALHANDLE;
2737 *lpuDeviceID = wmld->uDeviceID;
2738 return MMSYSERR_NOERROR;
2741 /**************************************************************************
2742 * waveInMessage [WINMM.@]
2744 UINT WINAPI waveInMessage(HWAVEIN hWaveIn, UINT uMessage,
2745 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2749 TRACE("(%p, %u, %ld, %ld)\n", hWaveIn, uMessage, dwParam1, dwParam2);
2751 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL) {
2752 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, TRUE)) != NULL) {
2753 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
2755 return MMSYSERR_INVALHANDLE;
2759 if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER))
2760 return MMSYSERR_INVALPARAM;
2763 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
2773 static DWORD WINAPI mmTaskRun(void* pmt)
2775 struct mm_starter mms;
2777 memcpy(&mms, pmt, sizeof(struct mm_starter));
2778 HeapFree(GetProcessHeap(), 0, pmt);
2780 if (mms.event) SetEvent(mms.event);
2784 /******************************************************************
2785 * mmTaskCreate (WINMM.@)
2787 MMRESULT WINAPI mmTaskCreate(LPTASKCALLBACK cb, HANDLE* ph, DWORD client)
2791 struct mm_starter *mms;
2793 mms = HeapAlloc(GetProcessHeap(), 0, sizeof(struct mm_starter));
2794 if (mms == NULL) return TASKERR_OUTOFMEMORY;
2797 mms->client = client;
2798 if (ph) hEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
2799 mms->event = hEvent;
2801 hThread = CreateThread(0, 0, mmTaskRun, mms, 0, NULL);
2803 HeapFree(GetProcessHeap(), 0, mms);
2804 if (hEvent) CloseHandle(hEvent);
2805 return TASKERR_OUTOFMEMORY;
2807 SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);
2808 if (ph) *ph = hEvent;
2809 CloseHandle(hThread);
2813 /******************************************************************
2814 * mmTaskBlock (WINMM.@)
2816 void WINAPI mmTaskBlock(HANDLE tid)
2822 GetMessageA(&msg, 0, 0, 0);
2823 if (msg.hwnd) DispatchMessageA(&msg);
2824 } while (msg.message != WM_USER);
2827 /******************************************************************
2828 * mmTaskSignal (WINMM.@)
2830 BOOL WINAPI mmTaskSignal(HANDLE tid)
2832 return PostThreadMessageW((DWORD)tid, WM_USER, 0, 0);
2835 /******************************************************************
2836 * mmTaskYield (WINMM.@)
2838 void WINAPI mmTaskYield(void) {}
2840 /******************************************************************
2841 * mmGetCurrentTask (WINMM.@)
2843 HANDLE WINAPI mmGetCurrentTask(void)
2845 return (HANDLE)GetCurrentThreadId();