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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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[1] = (DWORD)"WINMM_IData";
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 DeleteCriticalSection(&WINMM_IData.cs);
100 /******************************************************************
104 static HANDLE (WINAPI *pGetModuleHandle16)(LPCSTR);
105 static DWORD (WINAPI *pLoadLibrary16)(LPCSTR);
107 BOOL WINMM_CheckForMMSystem(void)
109 /* 0 is not checked yet, -1 is not present, 1 is present */
110 static int loaded /* = 0 */;
114 HANDLE h = GetModuleHandleA("kernel32");
118 pGetModuleHandle16 = (void*)GetProcAddress(h, "GetModuleHandle16");
119 pLoadLibrary16 = (void*)GetProcAddress(h, "LoadLibrary16");
120 if (pGetModuleHandle16 && pLoadLibrary16 &&
121 (pGetModuleHandle16("MMSYSTEM.DLL") || pLoadLibrary16("MMSYSTEM.DLL")))
128 /******************************************************************
129 * WINMM_ErrorToString
131 const char* WINMM_ErrorToString(MMRESULT error)
133 #define ERR_TO_STR(dev) case dev: return #dev
134 static char unknown[32];
136 ERR_TO_STR(MMSYSERR_NOERROR);
137 ERR_TO_STR(MMSYSERR_ERROR);
138 ERR_TO_STR(MMSYSERR_BADDEVICEID);
139 ERR_TO_STR(MMSYSERR_NOTENABLED);
140 ERR_TO_STR(MMSYSERR_ALLOCATED);
141 ERR_TO_STR(MMSYSERR_INVALHANDLE);
142 ERR_TO_STR(MMSYSERR_NODRIVER);
143 ERR_TO_STR(MMSYSERR_NOMEM);
144 ERR_TO_STR(MMSYSERR_NOTSUPPORTED);
145 ERR_TO_STR(MMSYSERR_BADERRNUM);
146 ERR_TO_STR(MMSYSERR_INVALFLAG);
147 ERR_TO_STR(MMSYSERR_INVALPARAM);
148 ERR_TO_STR(MMSYSERR_HANDLEBUSY);
149 ERR_TO_STR(MMSYSERR_INVALIDALIAS);
150 ERR_TO_STR(MMSYSERR_BADDB);
151 ERR_TO_STR(MMSYSERR_KEYNOTFOUND);
152 ERR_TO_STR(MMSYSERR_READERROR);
153 ERR_TO_STR(MMSYSERR_WRITEERROR);
154 ERR_TO_STR(MMSYSERR_DELETEERROR);
155 ERR_TO_STR(MMSYSERR_VALNOTFOUND);
156 ERR_TO_STR(MMSYSERR_NODRIVERCB);
157 ERR_TO_STR(WAVERR_BADFORMAT);
158 ERR_TO_STR(WAVERR_STILLPLAYING);
159 ERR_TO_STR(WAVERR_UNPREPARED);
160 ERR_TO_STR(WAVERR_SYNC);
162 sprintf(unknown, "Unknown(0x%08x)", error);
167 /**************************************************************************
168 * DllMain (WINMM.init)
170 * WINMM DLL entry point
173 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID fImpLoad)
175 TRACE("%p 0x%lx %p\n", hInstDLL, fdwReason, fImpLoad);
178 case DLL_PROCESS_ATTACH:
179 DisableThreadLibraryCalls(hInstDLL);
181 if (!WINMM_CreateIData(hInstDLL))
188 case DLL_PROCESS_DETACH:
189 /* close all opened MCI drivers */
190 MCI_SendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_WAIT, 0L, TRUE);
192 /* now unload all remaining drivers... */
201 /**************************************************************************
202 * Mixer devices. New to Win95
205 /**************************************************************************
206 * find out the real mixer ID depending on hmix (depends on dwFlags)
208 static UINT MIXER_GetDev(HMIXEROBJ hmix, DWORD dwFlags, LPWINE_MIXER * lplpwm)
210 LPWINE_MIXER lpwm = NULL;
211 UINT uRet = MMSYSERR_NOERROR;
213 switch (dwFlags & 0xF0000000ul) {
214 case MIXER_OBJECTF_MIXER:
215 lpwm = (LPWINE_MIXER)MMDRV_Get(hmix, MMDRV_MIXER, TRUE);
217 case MIXER_OBJECTF_HMIXER:
218 lpwm = (LPWINE_MIXER)MMDRV_Get(hmix, MMDRV_MIXER, FALSE);
220 case MIXER_OBJECTF_WAVEOUT:
221 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEOUT, TRUE, MMDRV_MIXER);
223 case MIXER_OBJECTF_HWAVEOUT:
224 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEOUT, FALSE, MMDRV_MIXER);
226 case MIXER_OBJECTF_WAVEIN:
227 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEIN, TRUE, MMDRV_MIXER);
229 case MIXER_OBJECTF_HWAVEIN:
230 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEIN, FALSE, MMDRV_MIXER);
232 case MIXER_OBJECTF_MIDIOUT:
233 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIOUT, TRUE, MMDRV_MIXER);
235 case MIXER_OBJECTF_HMIDIOUT:
236 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIOUT, FALSE, MMDRV_MIXER);
238 case MIXER_OBJECTF_MIDIIN:
239 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIIN, TRUE, MMDRV_MIXER);
241 case MIXER_OBJECTF_HMIDIIN:
242 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIIN, FALSE, MMDRV_MIXER);
244 case MIXER_OBJECTF_AUX:
245 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_AUX, TRUE, MMDRV_MIXER);
248 WARN("Unsupported flag (%08lx)\n", dwFlags & 0xF0000000ul);
250 uRet = MMSYSERR_INVALFLAG;
254 if (lpwm == 0 && uRet == MMSYSERR_NOERROR)
255 uRet = MMSYSERR_INVALPARAM;
259 /**************************************************************************
260 * mixerGetNumDevs [WINMM.@]
262 UINT WINAPI mixerGetNumDevs(void)
264 return MMDRV_GetNum(MMDRV_MIXER);
267 /**************************************************************************
268 * mixerGetDevCapsA [WINMM.@]
270 UINT WINAPI mixerGetDevCapsA(UINT_PTR uDeviceID, LPMIXERCAPSA lpCaps, UINT uSize)
275 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
277 ret = mixerGetDevCapsW(uDeviceID, &micW, sizeof(micW));
279 if (ret == MMSYSERR_NOERROR) {
281 micA.wMid = micW.wMid;
282 micA.wPid = micW.wPid;
283 micA.vDriverVersion = micW.vDriverVersion;
284 WideCharToMultiByte( CP_ACP, 0, micW.szPname, -1, micA.szPname,
285 sizeof(micA.szPname), NULL, NULL );
286 micA.fdwSupport = micW.fdwSupport;
287 micA.cDestinations = micW.cDestinations;
288 memcpy(lpCaps, &micA, min(uSize, sizeof(micA)));
293 /**************************************************************************
294 * mixerGetDevCapsW [WINMM.@]
296 UINT WINAPI mixerGetDevCapsW(UINT_PTR uDeviceID, LPMIXERCAPSW lpCaps, UINT uSize)
300 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
302 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_MIXER, TRUE)) == NULL)
303 return MMSYSERR_BADDEVICEID;
305 return MMDRV_Message(wmld, MXDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
308 UINT MIXER_Open(LPHMIXER lphMix, UINT uDeviceID, DWORD_PTR dwCallback,
309 DWORD_PTR dwInstance, DWORD fdwOpen, BOOL bFrom32)
316 TRACE("(%p, %d, %08lx, %08lx, %08lx)\n",
317 lphMix, uDeviceID, dwCallback, dwInstance, fdwOpen);
319 wmld = MMDRV_Alloc(sizeof(WINE_MIXER), MMDRV_MIXER, &hMix, &fdwOpen,
320 &dwCallback, &dwInstance, bFrom32);
322 wmld->uDeviceID = uDeviceID;
323 mod.hmx = (HMIXEROBJ)hMix;
324 mod.dwCallback = dwCallback;
325 mod.dwInstance = dwInstance;
327 dwRet = MMDRV_Open(wmld, MXDM_OPEN, (DWORD)&mod, fdwOpen);
329 if (dwRet != MMSYSERR_NOERROR) {
330 MMDRV_Free(hMix, wmld);
333 if (lphMix) *lphMix = hMix;
334 TRACE("=> %ld hMixer=%p\n", dwRet, hMix);
339 /**************************************************************************
340 * mixerOpen [WINMM.@]
342 UINT WINAPI mixerOpen(LPHMIXER lphMix, UINT uDeviceID, DWORD_PTR dwCallback,
343 DWORD_PTR dwInstance, DWORD fdwOpen)
345 return MIXER_Open(lphMix, uDeviceID, dwCallback, dwInstance, fdwOpen, TRUE);
348 /**************************************************************************
349 * mixerClose [WINMM.@]
351 UINT WINAPI mixerClose(HMIXER hMix)
356 TRACE("(%p)\n", hMix);
358 if ((wmld = MMDRV_Get(hMix, MMDRV_MIXER, FALSE)) == NULL) return MMSYSERR_INVALHANDLE;
360 dwRet = MMDRV_Close(wmld, MXDM_CLOSE);
361 MMDRV_Free(hMix, wmld);
366 /**************************************************************************
367 * mixerGetID [WINMM.@]
369 UINT WINAPI mixerGetID(HMIXEROBJ hmix, LPUINT lpid, DWORD fdwID)
372 UINT uRet = MMSYSERR_NOERROR;
374 TRACE("(%p %p %08lx)\n", hmix, lpid, fdwID);
376 if ((uRet = MIXER_GetDev(hmix, fdwID, &lpwm)) != MMSYSERR_NOERROR)
380 *lpid = lpwm->mld.uDeviceID;
385 /**************************************************************************
386 * mixerGetControlDetailsW [WINMM.@]
388 UINT WINAPI mixerGetControlDetailsW(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcdW,
392 UINT uRet = MMSYSERR_NOERROR;
394 TRACE("(%p, %p, %08lx)\n", hmix, lpmcdW, fdwDetails);
396 if ((uRet = MIXER_GetDev(hmix, fdwDetails, &lpwm)) != MMSYSERR_NOERROR)
399 if (lpmcdW == NULL || lpmcdW->cbStruct != sizeof(*lpmcdW))
400 return MMSYSERR_INVALPARAM;
402 return MMDRV_Message(&lpwm->mld, MXDM_GETCONTROLDETAILS, (DWORD_PTR)lpmcdW,
406 /**************************************************************************
407 * mixerGetControlDetailsA [WINMM.@]
409 UINT WINAPI mixerGetControlDetailsA(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcdA,
412 DWORD ret = MMSYSERR_NOTENABLED;
414 TRACE("(%p, %p, %08lx)\n", hmix, lpmcdA, fdwDetails);
416 if (lpmcdA == NULL || lpmcdA->cbStruct != sizeof(*lpmcdA))
417 return MMSYSERR_INVALPARAM;
419 switch (fdwDetails & MIXER_GETCONTROLDETAILSF_QUERYMASK) {
420 case MIXER_GETCONTROLDETAILSF_VALUE:
421 /* can savely use A structure as it is, no string inside */
422 ret = mixerGetControlDetailsW(hmix, lpmcdA, fdwDetails);
424 case MIXER_GETCONTROLDETAILSF_LISTTEXT:
426 MIXERCONTROLDETAILS_LISTTEXTA *pDetailsA = (MIXERCONTROLDETAILS_LISTTEXTA *)lpmcdA->paDetails;
427 MIXERCONTROLDETAILS_LISTTEXTW *pDetailsW;
428 int size = max(1, lpmcdA->cChannels) * sizeof(MIXERCONTROLDETAILS_LISTTEXTW);
431 if (lpmcdA->u.cMultipleItems != 0) {
432 size *= lpmcdA->u.cMultipleItems;
434 pDetailsW = HeapAlloc(GetProcessHeap(), 0, size);
435 lpmcdA->paDetails = pDetailsW;
436 lpmcdA->cbDetails = sizeof(MIXERCONTROLDETAILS_LISTTEXTW);
437 /* set up lpmcd->paDetails */
438 ret = mixerGetControlDetailsW(hmix, lpmcdA, fdwDetails);
439 /* copy from lpmcd->paDetails back to paDetailsW; */
440 if (ret == MMSYSERR_NOERROR) {
441 for (i = 0; i < lpmcdA->u.cMultipleItems * lpmcdA->cChannels; i++) {
442 pDetailsA->dwParam1 = pDetailsW->dwParam1;
443 pDetailsA->dwParam2 = pDetailsW->dwParam2;
444 WideCharToMultiByte( CP_ACP, 0, pDetailsW->szName, -1,
446 sizeof(pDetailsA->szName), NULL, NULL );
450 pDetailsA -= lpmcdA->u.cMultipleItems * lpmcdA->cChannels;
451 pDetailsW -= lpmcdA->u.cMultipleItems * lpmcdA->cChannels;
453 HeapFree(GetProcessHeap(), 0, pDetailsW);
454 lpmcdA->paDetails = pDetailsA;
455 lpmcdA->cbDetails = sizeof(MIXERCONTROLDETAILS_LISTTEXTA);
459 ERR("Unsupported fdwDetails=0x%08lx\n", fdwDetails);
465 /**************************************************************************
466 * mixerGetLineControlsA [WINMM.@]
468 UINT WINAPI mixerGetLineControlsA(HMIXEROBJ hmix, LPMIXERLINECONTROLSA lpmlcA,
471 MIXERLINECONTROLSW mlcW;
475 TRACE("(%p, %p, %08lx)\n", hmix, lpmlcA, fdwControls);
477 if (lpmlcA == NULL || lpmlcA->cbStruct != sizeof(*lpmlcA) ||
478 lpmlcA->cbmxctrl != sizeof(MIXERCONTROLA))
479 return MMSYSERR_INVALPARAM;
481 mlcW.cbStruct = sizeof(mlcW);
482 mlcW.dwLineID = lpmlcA->dwLineID;
483 mlcW.u.dwControlID = lpmlcA->u.dwControlID;
484 mlcW.u.dwControlType = lpmlcA->u.dwControlType;
486 /* Debugging on Windows shows for MIXER_GETLINECONTROLSF_ONEBYTYPE only,
487 the control count is assumed to be 1 - This is relied upon by a game,
489 if (MIXER_GETLINECONTROLSF_ONEBYTYPE == fdwControls) {
492 mlcW.cControls = lpmlcA->cControls;
494 mlcW.cbmxctrl = sizeof(MIXERCONTROLW);
495 mlcW.pamxctrl = HeapAlloc(GetProcessHeap(), 0,
496 mlcW.cControls * mlcW.cbmxctrl);
498 ret = mixerGetLineControlsW(hmix, &mlcW, fdwControls);
500 if (ret == MMSYSERR_NOERROR) {
501 lpmlcA->dwLineID = mlcW.dwLineID;
502 lpmlcA->u.dwControlID = mlcW.u.dwControlID;
503 lpmlcA->u.dwControlType = mlcW.u.dwControlType;
504 lpmlcA->cControls = mlcW.cControls;
506 for (i = 0; i < mlcW.cControls; i++) {
507 lpmlcA->pamxctrl[i].cbStruct = sizeof(MIXERCONTROLA);
508 lpmlcA->pamxctrl[i].dwControlID = mlcW.pamxctrl[i].dwControlID;
509 lpmlcA->pamxctrl[i].dwControlType = mlcW.pamxctrl[i].dwControlType;
510 lpmlcA->pamxctrl[i].fdwControl = mlcW.pamxctrl[i].fdwControl;
511 lpmlcA->pamxctrl[i].cMultipleItems = mlcW.pamxctrl[i].cMultipleItems;
512 WideCharToMultiByte( CP_ACP, 0, mlcW.pamxctrl[i].szShortName, -1,
513 lpmlcA->pamxctrl[i].szShortName,
514 sizeof(lpmlcA->pamxctrl[i].szShortName), NULL, NULL );
515 WideCharToMultiByte( CP_ACP, 0, mlcW.pamxctrl[i].szName, -1,
516 lpmlcA->pamxctrl[i].szName,
517 sizeof(lpmlcA->pamxctrl[i].szName), NULL, NULL );
518 /* sizeof(lpmlcA->pamxctrl[i].Bounds) ==
519 * sizeof(mlcW.pamxctrl[i].Bounds) */
520 memcpy(&lpmlcA->pamxctrl[i].Bounds, &mlcW.pamxctrl[i].Bounds,
521 sizeof(mlcW.pamxctrl[i].Bounds));
522 /* sizeof(lpmlcA->pamxctrl[i].Metrics) ==
523 * sizeof(mlcW.pamxctrl[i].Metrics) */
524 memcpy(&lpmlcA->pamxctrl[i].Metrics, &mlcW.pamxctrl[i].Metrics,
525 sizeof(mlcW.pamxctrl[i].Metrics));
529 HeapFree(GetProcessHeap(), 0, mlcW.pamxctrl);
534 /**************************************************************************
535 * mixerGetLineControlsW [WINMM.@]
537 UINT WINAPI mixerGetLineControlsW(HMIXEROBJ hmix, LPMIXERLINECONTROLSW lpmlcW,
541 UINT uRet = MMSYSERR_NOERROR;
543 TRACE("(%p, %p, %08lx)\n", hmix, lpmlcW, fdwControls);
545 if ((uRet = MIXER_GetDev(hmix, fdwControls, &lpwm)) != MMSYSERR_NOERROR)
548 if (lpmlcW == NULL || lpmlcW->cbStruct != sizeof(*lpmlcW))
549 return MMSYSERR_INVALPARAM;
551 return MMDRV_Message(&lpwm->mld, MXDM_GETLINECONTROLS, (DWORD_PTR)lpmlcW,
555 /**************************************************************************
556 * mixerGetLineInfoW [WINMM.@]
558 UINT WINAPI mixerGetLineInfoW(HMIXEROBJ hmix, LPMIXERLINEW lpmliW, DWORD fdwInfo)
561 UINT uRet = MMSYSERR_NOERROR;
563 TRACE("(%p, %p, %08lx)\n", hmix, lpmliW, fdwInfo);
565 if ((uRet = MIXER_GetDev(hmix, fdwInfo, &lpwm)) != MMSYSERR_NOERROR)
568 return MMDRV_Message(&lpwm->mld, MXDM_GETLINEINFO, (DWORD_PTR)lpmliW,
572 /**************************************************************************
573 * mixerGetLineInfoA [WINMM.@]
575 UINT WINAPI mixerGetLineInfoA(HMIXEROBJ hmix, LPMIXERLINEA lpmliA,
581 TRACE("(%p, %p, %08lx)\n", hmix, lpmliA, fdwInfo);
583 if (lpmliA == NULL || lpmliA->cbStruct != sizeof(*lpmliA))
584 return MMSYSERR_INVALPARAM;
586 mliW.cbStruct = sizeof(mliW);
587 switch (fdwInfo & MIXER_GETLINEINFOF_QUERYMASK) {
588 case MIXER_GETLINEINFOF_COMPONENTTYPE:
589 mliW.dwComponentType = lpmliA->dwComponentType;
591 case MIXER_GETLINEINFOF_DESTINATION:
592 mliW.dwDestination = lpmliA->dwDestination;
594 case MIXER_GETLINEINFOF_LINEID:
595 mliW.dwLineID = lpmliA->dwLineID;
597 case MIXER_GETLINEINFOF_SOURCE:
598 mliW.dwDestination = lpmliA->dwDestination;
599 mliW.dwSource = lpmliA->dwSource;
601 case MIXER_GETLINEINFOF_TARGETTYPE:
602 mliW.Target.dwType = lpmliA->Target.dwType;
603 mliW.Target.wMid = lpmliA->Target.wMid;
604 mliW.Target.wPid = lpmliA->Target.wPid;
605 mliW.Target.vDriverVersion = lpmliA->Target.vDriverVersion;
606 MultiByteToWideChar( CP_ACP, 0, lpmliA->Target.szPname, -1, mliW.Target.szPname, sizeof(mliW.Target.szPname));
609 WARN("Unsupported fdwControls=0x%08lx\n", fdwInfo);
610 return MMSYSERR_INVALFLAG;
613 ret = mixerGetLineInfoW(hmix, &mliW, fdwInfo);
615 lpmliA->dwDestination = mliW.dwDestination;
616 lpmliA->dwSource = mliW.dwSource;
617 lpmliA->dwLineID = mliW.dwLineID;
618 lpmliA->fdwLine = mliW.fdwLine;
619 lpmliA->dwUser = mliW.dwUser;
620 lpmliA->dwComponentType = mliW.dwComponentType;
621 lpmliA->cChannels = mliW.cChannels;
622 lpmliA->cConnections = mliW.cConnections;
623 lpmliA->cControls = mliW.cControls;
624 WideCharToMultiByte( CP_ACP, 0, mliW.szShortName, -1, lpmliA->szShortName,
625 sizeof(lpmliA->szShortName), NULL, NULL);
626 WideCharToMultiByte( CP_ACP, 0, mliW.szName, -1, lpmliA->szName,
627 sizeof(lpmliA->szName), NULL, NULL );
628 lpmliA->Target.dwType = mliW.Target.dwType;
629 lpmliA->Target.dwDeviceID = mliW.Target.dwDeviceID;
630 lpmliA->Target.wMid = mliW.Target.wMid;
631 lpmliA->Target.wPid = mliW.Target.wPid;
632 lpmliA->Target.vDriverVersion = mliW.Target.vDriverVersion;
633 WideCharToMultiByte( CP_ACP, 0, mliW.Target.szPname, -1, lpmliA->Target.szPname,
634 sizeof(lpmliA->Target.szPname), NULL, NULL );
639 /**************************************************************************
640 * mixerSetControlDetails [WINMM.@]
642 UINT WINAPI mixerSetControlDetails(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcd,
646 UINT uRet = MMSYSERR_NOERROR;
648 TRACE("(%p, %p, %08lx)\n", hmix, lpmcd, fdwDetails);
650 if ((uRet = MIXER_GetDev(hmix, fdwDetails, &lpwm)) != MMSYSERR_NOERROR)
653 return MMDRV_Message(&lpwm->mld, MXDM_SETCONTROLDETAILS, (DWORD_PTR)lpmcd,
657 /**************************************************************************
658 * mixerMessage [WINMM.@]
660 DWORD WINAPI mixerMessage(HMIXER hmix, UINT uMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
664 TRACE("(%04lx, %d, %08lx, %08lx): semi-stub?\n",
665 (DWORD)hmix, uMsg, dwParam1, dwParam2);
667 if ((wmld = MMDRV_Get(hmix, MMDRV_MIXER, FALSE)) == NULL)
668 return MMSYSERR_INVALHANDLE;
670 return MMDRV_Message(wmld, uMsg, dwParam1, dwParam2, TRUE);
673 /**************************************************************************
674 * auxGetNumDevs [WINMM.@]
676 UINT WINAPI auxGetNumDevs(void)
678 return MMDRV_GetNum(MMDRV_AUX);
681 /**************************************************************************
682 * auxGetDevCapsW [WINMM.@]
684 UINT WINAPI auxGetDevCapsW(UINT_PTR uDeviceID, LPAUXCAPSW lpCaps, UINT uSize)
688 TRACE("(%04X, %p, %d) !\n", uDeviceID, lpCaps, uSize);
690 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
692 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
693 return MMSYSERR_INVALHANDLE;
694 return MMDRV_Message(wmld, AUXDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
697 /**************************************************************************
698 * auxGetDevCapsA [WINMM.@]
700 UINT WINAPI auxGetDevCapsA(UINT_PTR uDeviceID, LPAUXCAPSA lpCaps, UINT uSize)
705 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
707 ret = auxGetDevCapsW(uDeviceID, &acW, sizeof(acW));
709 if (ret == MMSYSERR_NOERROR) {
713 acA.vDriverVersion = acW.vDriverVersion;
714 WideCharToMultiByte( CP_ACP, 0, acW.szPname, -1, acA.szPname,
715 sizeof(acA.szPname), NULL, NULL );
716 acA.wTechnology = acW.wTechnology;
717 acA.dwSupport = acW.dwSupport;
718 memcpy(lpCaps, &acA, min(uSize, sizeof(acA)));
723 /**************************************************************************
724 * auxGetVolume [WINMM.@]
726 UINT WINAPI auxGetVolume(UINT uDeviceID, DWORD* lpdwVolume)
730 TRACE("(%04X, %p) !\n", uDeviceID, lpdwVolume);
732 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
733 return MMSYSERR_INVALHANDLE;
734 return MMDRV_Message(wmld, AUXDM_GETVOLUME, (DWORD_PTR)lpdwVolume, 0L, TRUE);
737 /**************************************************************************
738 * auxSetVolume [WINMM.@]
740 UINT WINAPI auxSetVolume(UINT uDeviceID, DWORD dwVolume)
744 TRACE("(%04X, %lu) !\n", uDeviceID, dwVolume);
746 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
747 return MMSYSERR_INVALHANDLE;
748 return MMDRV_Message(wmld, AUXDM_SETVOLUME, dwVolume, 0L, TRUE);
751 /**************************************************************************
752 * auxOutMessage [WINMM.@]
754 UINT WINAPI auxOutMessage(UINT uDeviceID, UINT uMessage, DWORD_PTR dw1, DWORD_PTR dw2)
758 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
759 return MMSYSERR_INVALHANDLE;
761 return MMDRV_Message(wmld, uMessage, dw1, dw2, TRUE);
764 /**************************************************************************
765 * midiOutGetNumDevs [WINMM.@]
767 UINT WINAPI midiOutGetNumDevs(void)
769 return MMDRV_GetNum(MMDRV_MIDIOUT);
772 /**************************************************************************
773 * midiOutGetDevCapsW [WINMM.@]
775 UINT WINAPI midiOutGetDevCapsW(UINT_PTR uDeviceID, LPMIDIOUTCAPSW lpCaps,
780 TRACE("(%u, %p, %u);\n", uDeviceID, lpCaps, uSize);
782 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
784 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_MIDIOUT, TRUE)) == NULL)
785 return MMSYSERR_INVALHANDLE;
787 return MMDRV_Message(wmld, MODM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
790 /**************************************************************************
791 * midiOutGetDevCapsA [WINMM.@]
793 UINT WINAPI midiOutGetDevCapsA(UINT_PTR uDeviceID, LPMIDIOUTCAPSA lpCaps,
799 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
801 ret = midiOutGetDevCapsW(uDeviceID, &mocW, sizeof(mocW));
803 if (ret == MMSYSERR_NOERROR) {
805 mocA.wMid = mocW.wMid;
806 mocA.wPid = mocW.wPid;
807 mocA.vDriverVersion = mocW.vDriverVersion;
808 WideCharToMultiByte( CP_ACP, 0, mocW.szPname, -1, mocA.szPname,
809 sizeof(mocA.szPname), NULL, NULL );
810 mocA.wTechnology = mocW.wTechnology;
811 mocA.wVoices = mocW.wVoices;
812 mocA.wNotes = mocW.wNotes;
813 mocA.wChannelMask = mocW.wChannelMask;
814 mocA.dwSupport = mocW.dwSupport;
815 memcpy(lpCaps, &mocA, min(uSize, sizeof(mocA)));
820 /**************************************************************************
821 * midiOutGetErrorTextA [WINMM.@]
822 * midiInGetErrorTextA [WINMM.@]
824 UINT WINAPI midiOutGetErrorTextA(UINT uError, LPSTR lpText, UINT uSize)
828 if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
829 else if (uSize == 0) ret = MMSYSERR_NOERROR;
832 LPWSTR xstr = HeapAlloc(GetProcessHeap(), 0, uSize * sizeof(WCHAR));
833 if (!xstr) ret = MMSYSERR_NOMEM;
836 ret = midiOutGetErrorTextW(uError, xstr, uSize);
837 if (ret == MMSYSERR_NOERROR)
838 WideCharToMultiByte(CP_ACP, 0, xstr, -1, lpText, uSize, NULL, NULL);
839 HeapFree(GetProcessHeap(), 0, xstr);
845 /**************************************************************************
846 * midiOutGetErrorTextW [WINMM.@]
847 * midiInGetErrorTextW [WINMM.@]
849 UINT WINAPI midiOutGetErrorTextW(UINT uError, LPWSTR lpText, UINT uSize)
851 UINT ret = MMSYSERR_BADERRNUM;
853 if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
854 else if (uSize == 0) ret = MMSYSERR_NOERROR;
856 /* test has been removed 'coz MMSYSERR_BASE is 0, and gcc did emit
857 * a warning for the test was always true */
858 (/*uError >= MMSYSERR_BASE && */ uError <= MMSYSERR_LASTERROR) ||
859 (uError >= MIDIERR_BASE && uError <= MIDIERR_LASTERROR)) {
860 if (LoadStringW(WINMM_IData.hWinMM32Instance,
861 uError, lpText, uSize) > 0) {
862 ret = MMSYSERR_NOERROR;
868 /**************************************************************************
869 * MIDI_OutAlloc [internal]
871 static LPWINE_MIDI MIDI_OutAlloc(HMIDIOUT* lphMidiOut, LPDWORD lpdwCallback,
872 LPDWORD lpdwInstance, LPDWORD lpdwFlags,
873 DWORD cIDs, MIDIOPENSTRMID* lpIDs, BOOL bFrom32)
879 size = sizeof(WINE_MIDI) + (cIDs ? (cIDs-1) : 0) * sizeof(MIDIOPENSTRMID);
881 lpwm = (LPWINE_MIDI)MMDRV_Alloc(size, MMDRV_MIDIOUT, &hMidiOut, lpdwFlags,
882 lpdwCallback, lpdwInstance, bFrom32);
884 if (lphMidiOut != NULL)
885 *lphMidiOut = hMidiOut;
888 lpwm->mod.hMidi = (HMIDI) hMidiOut;
889 lpwm->mod.dwCallback = *lpdwCallback;
890 lpwm->mod.dwInstance = *lpdwInstance;
891 lpwm->mod.dnDevNode = 0;
892 lpwm->mod.cIds = cIDs;
894 memcpy(&(lpwm->mod.rgIds), lpIDs, cIDs * sizeof(MIDIOPENSTRMID));
899 UINT MIDI_OutOpen(LPHMIDIOUT lphMidiOut, UINT uDeviceID, DWORD_PTR dwCallback,
900 DWORD_PTR dwInstance, DWORD dwFlags, BOOL bFrom32)
906 TRACE("(%p, %d, %08lX, %08lX, %08lX);\n",
907 lphMidiOut, uDeviceID, dwCallback, dwInstance, dwFlags);
909 if (lphMidiOut != NULL) *lphMidiOut = 0;
911 lpwm = MIDI_OutAlloc(&hMidiOut, &dwCallback, &dwInstance, &dwFlags,
915 return MMSYSERR_NOMEM;
917 lpwm->mld.uDeviceID = uDeviceID;
919 dwRet = MMDRV_Open((LPWINE_MLD)lpwm, MODM_OPEN, (DWORD)&lpwm->mod, dwFlags);
921 if (dwRet != MMSYSERR_NOERROR) {
922 MMDRV_Free(hMidiOut, (LPWINE_MLD)lpwm);
926 if (lphMidiOut) *lphMidiOut = hMidiOut;
927 TRACE("=> %d hMidi=%p\n", dwRet, hMidiOut);
932 /**************************************************************************
933 * midiOutOpen [WINMM.@]
935 UINT WINAPI midiOutOpen(LPHMIDIOUT lphMidiOut, UINT uDeviceID,
936 DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD dwFlags)
938 return MIDI_OutOpen(lphMidiOut, uDeviceID, dwCallback, dwInstance, dwFlags, TRUE);
941 /**************************************************************************
942 * midiOutClose [WINMM.@]
944 UINT WINAPI midiOutClose(HMIDIOUT hMidiOut)
949 TRACE("(%p)\n", hMidiOut);
951 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
952 return MMSYSERR_INVALHANDLE;
954 dwRet = MMDRV_Close(wmld, MODM_CLOSE);
955 MMDRV_Free(hMidiOut, wmld);
960 /**************************************************************************
961 * midiOutPrepareHeader [WINMM.@]
963 UINT WINAPI midiOutPrepareHeader(HMIDIOUT hMidiOut,
964 MIDIHDR* lpMidiOutHdr, UINT uSize)
968 TRACE("(%p, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
970 if (lpMidiOutHdr == NULL || uSize < sizeof (MIDIHDR))
971 return MMSYSERR_INVALPARAM;
973 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
974 return MMSYSERR_INVALHANDLE;
976 return MMDRV_Message(wmld, MODM_PREPARE, (DWORD_PTR)lpMidiOutHdr, uSize, TRUE);
979 /**************************************************************************
980 * midiOutUnprepareHeader [WINMM.@]
982 UINT WINAPI midiOutUnprepareHeader(HMIDIOUT hMidiOut,
983 MIDIHDR* lpMidiOutHdr, UINT uSize)
987 TRACE("(%p, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
989 if (lpMidiOutHdr == NULL || uSize < sizeof (MIDIHDR))
990 return MMSYSERR_INVALPARAM;
992 if (!(lpMidiOutHdr->dwFlags & MHDR_PREPARED)) {
993 return MMSYSERR_NOERROR;
996 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
997 return MMSYSERR_INVALHANDLE;
999 return MMDRV_Message(wmld, MODM_UNPREPARE, (DWORD_PTR)lpMidiOutHdr, uSize, TRUE);
1002 /**************************************************************************
1003 * midiOutShortMsg [WINMM.@]
1005 UINT WINAPI midiOutShortMsg(HMIDIOUT hMidiOut, DWORD dwMsg)
1009 TRACE("(%p, %08lX)\n", hMidiOut, dwMsg);
1011 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1012 return MMSYSERR_INVALHANDLE;
1014 return MMDRV_Message(wmld, MODM_DATA, dwMsg, 0L, TRUE);
1017 /**************************************************************************
1018 * midiOutLongMsg [WINMM.@]
1020 UINT WINAPI midiOutLongMsg(HMIDIOUT hMidiOut,
1021 MIDIHDR* lpMidiOutHdr, UINT uSize)
1025 TRACE("(%p, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
1027 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1028 return MMSYSERR_INVALHANDLE;
1030 return MMDRV_Message(wmld, MODM_LONGDATA, (DWORD_PTR)lpMidiOutHdr, uSize, TRUE);
1033 /**************************************************************************
1034 * midiOutReset [WINMM.@]
1036 UINT WINAPI midiOutReset(HMIDIOUT hMidiOut)
1040 TRACE("(%p)\n", hMidiOut);
1042 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1043 return MMSYSERR_INVALHANDLE;
1045 return MMDRV_Message(wmld, MODM_RESET, 0L, 0L, TRUE);
1048 /**************************************************************************
1049 * midiOutGetVolume [WINMM.@]
1051 UINT WINAPI midiOutGetVolume(HMIDIOUT hMidiOut, DWORD* lpdwVolume)
1055 TRACE("(%p, %p);\n", hMidiOut, lpdwVolume);
1057 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, TRUE)) == NULL)
1058 return MMSYSERR_INVALHANDLE;
1060 return MMDRV_Message(wmld, MODM_GETVOLUME, (DWORD_PTR)lpdwVolume, 0L, TRUE);
1063 /**************************************************************************
1064 * midiOutSetVolume [WINMM.@]
1066 UINT WINAPI midiOutSetVolume(HMIDIOUT hMidiOut, DWORD dwVolume)
1070 TRACE("(%p, %ld);\n", hMidiOut, dwVolume);
1072 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, TRUE)) == NULL)
1073 return MMSYSERR_INVALHANDLE;
1075 return MMDRV_Message(wmld, MODM_SETVOLUME, dwVolume, 0L, TRUE);
1078 /**************************************************************************
1079 * midiOutCachePatches [WINMM.@]
1081 UINT WINAPI midiOutCachePatches(HMIDIOUT hMidiOut, UINT uBank,
1082 WORD* lpwPatchArray, UINT uFlags)
1084 /* not really necessary to support this */
1085 FIXME("not supported yet\n");
1086 return MMSYSERR_NOTSUPPORTED;
1089 /**************************************************************************
1090 * midiOutCacheDrumPatches [WINMM.@]
1092 UINT WINAPI midiOutCacheDrumPatches(HMIDIOUT hMidiOut, UINT uPatch,
1093 WORD* lpwKeyArray, UINT uFlags)
1095 FIXME("not supported yet\n");
1096 return MMSYSERR_NOTSUPPORTED;
1099 /**************************************************************************
1100 * midiOutGetID [WINMM.@]
1102 UINT WINAPI midiOutGetID(HMIDIOUT hMidiOut, UINT* lpuDeviceID)
1106 TRACE("(%p, %p)\n", hMidiOut, lpuDeviceID);
1108 if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
1109 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1110 return MMSYSERR_INVALHANDLE;
1112 *lpuDeviceID = wmld->uDeviceID;
1113 return MMSYSERR_NOERROR;
1116 /**************************************************************************
1117 * midiOutMessage [WINMM.@]
1119 UINT WINAPI midiOutMessage(HMIDIOUT hMidiOut, UINT uMessage,
1120 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1124 TRACE("(%p, %04X, %08lX, %08lX)\n", hMidiOut, uMessage, dwParam1, dwParam2);
1126 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL) {
1128 if (uMessage == 0x0001) {
1129 *(LPDWORD)dwParam1 = 1;
1132 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, TRUE)) != NULL) {
1133 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
1135 return MMSYSERR_INVALHANDLE;
1141 FIXME("can't handle OPEN or CLOSE message!\n");
1142 return MMSYSERR_NOTSUPPORTED;
1144 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
1147 /**************************************************************************
1148 * midiInGetNumDevs [WINMM.@]
1150 UINT WINAPI midiInGetNumDevs(void)
1152 return MMDRV_GetNum(MMDRV_MIDIIN);
1155 /**************************************************************************
1156 * midiInGetDevCapsW [WINMM.@]
1158 UINT WINAPI midiInGetDevCapsW(UINT_PTR uDeviceID, LPMIDIINCAPSW lpCaps, UINT uSize)
1162 TRACE("(%d, %p, %d);\n", uDeviceID, lpCaps, uSize);
1164 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
1166 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_MIDIIN, TRUE)) == NULL)
1167 return MMSYSERR_INVALHANDLE;
1169 return MMDRV_Message(wmld, MIDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
1172 /**************************************************************************
1173 * midiInGetDevCapsA [WINMM.@]
1175 UINT WINAPI midiInGetDevCapsA(UINT_PTR uDeviceID, LPMIDIINCAPSA lpCaps, UINT uSize)
1180 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
1182 ret = midiInGetDevCapsW(uDeviceID, &micW, sizeof(micW));
1184 if (ret == MMSYSERR_NOERROR) {
1186 micA.wMid = micW.wMid;
1187 micA.wPid = micW.wPid;
1188 micA.vDriverVersion = micW.vDriverVersion;
1189 WideCharToMultiByte( CP_ACP, 0, micW.szPname, -1, micA.szPname,
1190 sizeof(micA.szPname), NULL, NULL );
1191 micA.dwSupport = micW.dwSupport;
1192 memcpy(lpCaps, &micA, min(uSize, sizeof(micA)));
1197 UINT MIDI_InOpen(HMIDIIN* lphMidiIn, UINT uDeviceID, DWORD_PTR dwCallback,
1198 DWORD_PTR dwInstance, DWORD dwFlags, BOOL bFrom32)
1204 TRACE("(%p, %d, %08lX, %08lX, %08lX);\n",
1205 lphMidiIn, uDeviceID, dwCallback, dwInstance, dwFlags);
1207 if (lphMidiIn != NULL) *lphMidiIn = 0;
1209 lpwm = (LPWINE_MIDI)MMDRV_Alloc(sizeof(WINE_MIDI), MMDRV_MIDIIN, &hMidiIn,
1210 &dwFlags, &dwCallback, &dwInstance, bFrom32);
1213 return MMSYSERR_NOMEM;
1215 lpwm->mod.hMidi = (HMIDI) hMidiIn;
1216 lpwm->mod.dwCallback = dwCallback;
1217 lpwm->mod.dwInstance = dwInstance;
1219 lpwm->mld.uDeviceID = uDeviceID;
1220 dwRet = MMDRV_Open(&lpwm->mld, MIDM_OPEN, (DWORD)&lpwm->mod, dwFlags);
1222 if (dwRet != MMSYSERR_NOERROR) {
1223 MMDRV_Free(hMidiIn, &lpwm->mld);
1226 if (lphMidiIn != NULL) *lphMidiIn = hMidiIn;
1227 TRACE("=> %ld hMidi=%p\n", dwRet, hMidiIn);
1232 /**************************************************************************
1233 * midiInOpen [WINMM.@]
1235 UINT WINAPI midiInOpen(HMIDIIN* lphMidiIn, UINT uDeviceID,
1236 DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD dwFlags)
1238 return MIDI_InOpen(lphMidiIn, uDeviceID, dwCallback, dwInstance, dwFlags, TRUE);
1241 /**************************************************************************
1242 * midiInClose [WINMM.@]
1244 UINT WINAPI midiInClose(HMIDIIN hMidiIn)
1249 TRACE("(%p)\n", hMidiIn);
1251 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1252 return MMSYSERR_INVALHANDLE;
1254 dwRet = MMDRV_Close(wmld, MIDM_CLOSE);
1255 MMDRV_Free(hMidiIn, wmld);
1259 /**************************************************************************
1260 * midiInPrepareHeader [WINMM.@]
1262 UINT WINAPI midiInPrepareHeader(HMIDIIN hMidiIn,
1263 MIDIHDR* lpMidiInHdr, UINT uSize)
1267 TRACE("(%p, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
1269 if (lpMidiInHdr == NULL || uSize < sizeof (MIDIHDR))
1270 return MMSYSERR_INVALPARAM;
1272 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1273 return MMSYSERR_INVALHANDLE;
1275 return MMDRV_Message(wmld, MIDM_PREPARE, (DWORD_PTR)lpMidiInHdr, uSize, TRUE);
1278 /**************************************************************************
1279 * midiInUnprepareHeader [WINMM.@]
1281 UINT WINAPI midiInUnprepareHeader(HMIDIIN hMidiIn,
1282 MIDIHDR* lpMidiInHdr, UINT uSize)
1286 TRACE("(%p, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
1288 if (lpMidiInHdr == NULL || uSize < sizeof (MIDIHDR))
1289 return MMSYSERR_INVALPARAM;
1291 if (!(lpMidiInHdr->dwFlags & MHDR_PREPARED)) {
1292 return MMSYSERR_NOERROR;
1295 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1296 return MMSYSERR_INVALHANDLE;
1298 return MMDRV_Message(wmld, MIDM_UNPREPARE, (DWORD_PTR)lpMidiInHdr, uSize, TRUE);
1301 /**************************************************************************
1302 * midiInAddBuffer [WINMM.@]
1304 UINT WINAPI midiInAddBuffer(HMIDIIN hMidiIn,
1305 MIDIHDR* lpMidiInHdr, UINT uSize)
1309 TRACE("(%p, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
1311 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1312 return MMSYSERR_INVALHANDLE;
1314 return MMDRV_Message(wmld, MIDM_ADDBUFFER, (DWORD_PTR)lpMidiInHdr, uSize, TRUE);
1317 /**************************************************************************
1318 * midiInStart [WINMM.@]
1320 UINT WINAPI midiInStart(HMIDIIN hMidiIn)
1324 TRACE("(%p)\n", hMidiIn);
1326 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1327 return MMSYSERR_INVALHANDLE;
1329 return MMDRV_Message(wmld, MIDM_START, 0L, 0L, TRUE);
1332 /**************************************************************************
1333 * midiInStop [WINMM.@]
1335 UINT WINAPI midiInStop(HMIDIIN hMidiIn)
1339 TRACE("(%p)\n", hMidiIn);
1341 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1342 return MMSYSERR_INVALHANDLE;
1344 return MMDRV_Message(wmld, MIDM_STOP, 0L, 0L, TRUE);
1347 /**************************************************************************
1348 * midiInReset [WINMM.@]
1350 UINT WINAPI midiInReset(HMIDIIN hMidiIn)
1354 TRACE("(%p)\n", hMidiIn);
1356 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1357 return MMSYSERR_INVALHANDLE;
1359 return MMDRV_Message(wmld, MIDM_RESET, 0L, 0L, TRUE);
1362 /**************************************************************************
1363 * midiInGetID [WINMM.@]
1365 UINT WINAPI midiInGetID(HMIDIIN hMidiIn, UINT* lpuDeviceID)
1369 TRACE("(%p, %p)\n", hMidiIn, lpuDeviceID);
1371 if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
1373 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, TRUE)) == NULL)
1374 return MMSYSERR_INVALHANDLE;
1376 *lpuDeviceID = wmld->uDeviceID;
1378 return MMSYSERR_NOERROR;
1381 /**************************************************************************
1382 * midiInMessage [WINMM.@]
1384 UINT WINAPI midiInMessage(HMIDIIN hMidiIn, UINT uMessage,
1385 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1389 TRACE("(%p, %04X, %08lX, %08lX)\n", hMidiIn, uMessage, dwParam1, dwParam2);
1391 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1392 return MMSYSERR_INVALHANDLE;
1397 FIXME("can't handle OPEN or CLOSE message!\n");
1398 return MMSYSERR_NOTSUPPORTED;
1400 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
1403 typedef struct WINE_MIDIStream {
1414 LPMIDIHDR lpMidiHdr;
1417 #define WINE_MSM_HEADER (WM_USER+0)
1418 #define WINE_MSM_STOP (WM_USER+1)
1420 /**************************************************************************
1421 * MMSYSTEM_GetMidiStream [internal]
1423 static BOOL MMSYSTEM_GetMidiStream(HMIDISTRM hMidiStrm, WINE_MIDIStream** lpMidiStrm, WINE_MIDI** lplpwm)
1425 WINE_MIDI* lpwm = (LPWINE_MIDI)MMDRV_Get(hMidiStrm, MMDRV_MIDIOUT, FALSE);
1434 *lpMidiStrm = (WINE_MIDIStream*)lpwm->mod.rgIds.dwStreamID;
1436 return *lpMidiStrm != NULL;
1439 /**************************************************************************
1440 * MMSYSTEM_MidiStream_Convert [internal]
1442 static DWORD MMSYSTEM_MidiStream_Convert(WINE_MIDIStream* lpMidiStrm, DWORD pulse)
1446 if (lpMidiStrm->dwTimeDiv == 0) {
1447 FIXME("Shouldn't happen. lpMidiStrm->dwTimeDiv = 0\n");
1448 } else if (lpMidiStrm->dwTimeDiv > 0x8000) { /* SMPTE, unchecked FIXME? */
1449 int nf = -(char)HIBYTE(lpMidiStrm->dwTimeDiv); /* number of frames */
1450 int nsf = LOBYTE(lpMidiStrm->dwTimeDiv); /* number of sub-frames */
1451 ret = (pulse * 1000) / (nf * nsf);
1453 ret = (DWORD)((double)pulse * ((double)lpMidiStrm->dwTempo / 1000) /
1454 (double)lpMidiStrm->dwTimeDiv);
1460 /**************************************************************************
1461 * MMSYSTEM_MidiStream_MessageHandler [internal]
1463 static BOOL MMSYSTEM_MidiStream_MessageHandler(WINE_MIDIStream* lpMidiStrm, LPWINE_MIDI lpwm, LPMSG msg)
1465 LPMIDIHDR lpMidiHdr;
1469 switch (msg->message) {
1471 SetEvent(lpMidiStrm->hEvent);
1475 /* this is not quite what MS doc says... */
1476 midiOutReset(lpMidiStrm->hDevice);
1477 /* empty list of already submitted buffers */
1478 for (lpMidiHdr = lpMidiStrm->lpMidiHdr; lpMidiHdr; lpMidiHdr = (LPMIDIHDR)lpMidiHdr->lpNext) {
1479 lpMidiHdr->dwFlags |= MHDR_DONE;
1480 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
1482 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1483 (HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
1484 lpwm->mod.dwInstance, (DWORD)lpMidiHdr, 0L);
1486 lpMidiStrm->lpMidiHdr = 0;
1487 SetEvent(lpMidiStrm->hEvent);
1489 case WINE_MSM_HEADER:
1490 /* sets initial tick count for first MIDIHDR */
1491 if (!lpMidiStrm->dwStartTicks)
1492 lpMidiStrm->dwStartTicks = GetTickCount();
1494 /* FIXME(EPP): "I don't understand the content of the first MIDIHDR sent
1495 * by native mcimidi, it doesn't look like a correct one".
1496 * this trick allows to throw it away... but I don't like it.
1497 * It looks like part of the file I'm trying to play and definitively looks
1498 * like raw midi content
1499 * I'd really like to understand why native mcimidi sends it. Perhaps a bad
1500 * synchronization issue where native mcimidi is still processing raw MIDI
1501 * content before generating MIDIEVENTs ?
1503 * 4c 04 89 3b 00 81 7c 99 3b 43 00 99 23 5e 04 89 L..;..|.;C..#^..
1504 * 3b 00 00 89 23 00 7c 99 3b 45 00 99 28 62 04 89 ;...#.|.;E..(b..
1505 * 3b 00 00 89 28 00 81 7c 99 3b 4e 00 99 23 5e 04 ;...(..|.;N..#^.
1506 * 89 3b 00 00 89 23 00 7c 99 3b 45 00 99 23 78 04 .;...#.|.;E..#x.
1507 * 89 3b 00 00 89 23 00 81 7c 99 3b 48 00 99 23 5e .;...#..|.;H..#^
1508 * 04 89 3b 00 00 89 23 00 7c 99 3b 4e 00 99 28 62 ..;...#.|.;N..(b
1509 * 04 89 3b 00 00 89 28 00 81 7c 99 39 4c 00 99 23 ..;...(..|.9L..#
1510 * 5e 04 89 39 00 00 89 23 00 82 7c 99 3b 4c 00 99 ^..9...#..|.;L..
1511 * 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 00 99 #^..;...#.|.;H..
1512 * 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b 3f 04 (b..;...(..|.;?.
1513 * 89 3b 00 1c 99 23 5e 04 89 23 00 5c 99 3b 45 00 .;...#^..#.\.;E.
1514 * 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 3b 46 .#x..;...#..|.;F
1515 * 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 ..#^..;...#.|.;H
1516 * 00 99 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b ..(b..;...(..|.;
1517 * 46 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b F..#^..;...#.|.;
1518 * 48 00 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 H..#x..;...#..|.
1519 * 3b 4c 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 ;L..#^..;...#.|.
1521 lpMidiHdr = (LPMIDIHDR)msg->lParam;
1522 lpData = lpMidiHdr->lpData;
1523 TRACE("Adding %s lpMidiHdr=%p [lpData=0x%08lx dwBufferLength=%lu/%lu dwFlags=0x%08lx size=%u]\n",
1524 (lpMidiHdr->dwFlags & MHDR_ISSTRM) ? "stream" : "regular", lpMidiHdr,
1525 (DWORD)lpMidiHdr, lpMidiHdr->dwBufferLength, lpMidiHdr->dwBytesRecorded,
1526 lpMidiHdr->dwFlags, msg->wParam);
1528 /* dumps content of lpMidiHdr->lpData
1529 * FIXME: there should be a debug routine somewhere that already does this
1530 * I hate spreading this type of shit all around the code
1532 for (dwToGo = 0; dwToGo < lpMidiHdr->dwBufferLength; dwToGo += 16) {
1536 for (i = 0; i < min(16, lpMidiHdr->dwBufferLength - dwToGo); i++)
1537 printf("%02x ", lpData[dwToGo + i]);
1540 for (i = 0; i < min(16, lpMidiHdr->dwBufferLength - dwToGo); i++) {
1541 ch = lpData[dwToGo + i];
1542 printf("%c", (ch >= 0x20 && ch <= 0x7F) ? ch : '.');
1547 if (((LPMIDIEVENT)lpData)->dwStreamID != 0 &&
1548 ((LPMIDIEVENT)lpData)->dwStreamID != 0xFFFFFFFF &&
1549 ((LPMIDIEVENT)lpData)->dwStreamID != (DWORD)lpMidiStrm) {
1550 FIXME("Dropping bad %s lpMidiHdr (streamID=%08lx)\n",
1551 (lpMidiHdr->dwFlags & MHDR_ISSTRM) ? "stream" : "regular",
1552 ((LPMIDIEVENT)lpData)->dwStreamID);
1553 lpMidiHdr->dwFlags |= MHDR_DONE;
1554 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
1556 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1557 (HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
1558 lpwm->mod.dwInstance, (DWORD)lpMidiHdr, 0L);
1562 for (lpmh = &lpMidiStrm->lpMidiHdr; *lpmh; lpmh = (LPMIDIHDR*)&((*lpmh)->lpNext));
1564 lpMidiHdr = (LPMIDIHDR)msg->lParam;
1565 lpMidiHdr->lpNext = 0;
1566 lpMidiHdr->dwFlags |= MHDR_INQUEUE;
1567 lpMidiHdr->dwFlags &= ~MHDR_DONE;
1568 lpMidiHdr->dwOffset = 0;
1572 FIXME("Unknown message %d\n", msg->message);
1578 /**************************************************************************
1579 * MMSYSTEM_MidiStream_Player [internal]
1581 static DWORD CALLBACK MMSYSTEM_MidiStream_Player(LPVOID pmt)
1583 WINE_MIDIStream* lpMidiStrm = pmt;
1588 LPMIDIHDR lpMidiHdr;
1592 TRACE("(%p)!\n", lpMidiStrm);
1595 (lpwm = (LPWINE_MIDI)MMDRV_Get(lpMidiStrm->hDevice, MMDRV_MIDIOUT, FALSE)) == NULL)
1598 /* force thread's queue creation */
1599 /* Used to be InitThreadInput16(0, 5); */
1600 /* but following works also with hack in midiStreamOpen */
1601 PeekMessageA(&msg, 0, 0, 0, 0);
1603 /* FIXME: this next line must be called before midiStreamOut or midiStreamRestart are called */
1604 SetEvent(lpMidiStrm->hEvent);
1605 TRACE("Ready to go 1\n");
1606 /* thread is started in paused mode */
1607 SuspendThread(lpMidiStrm->hThread);
1608 TRACE("Ready to go 2\n");
1610 lpMidiStrm->dwStartTicks = 0;
1611 lpMidiStrm->dwPulses = 0;
1613 lpMidiStrm->lpMidiHdr = 0;
1616 lpMidiHdr = lpMidiStrm->lpMidiHdr;
1618 /* for first message, block until one arrives, then process all that are available */
1619 GetMessageA(&msg, 0, 0, 0);
1621 if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm, lpwm, &msg))
1623 } while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE));
1629 lpData = lpMidiHdr->lpData;
1631 me = (LPMIDIEVENT)(lpData + lpMidiHdr->dwOffset);
1633 /* do we have to wait ? */
1634 if (me->dwDeltaTime) {
1635 lpMidiStrm->dwPositionMS += MMSYSTEM_MidiStream_Convert(lpMidiStrm, me->dwDeltaTime);
1636 lpMidiStrm->dwPulses += me->dwDeltaTime;
1638 dwToGo = lpMidiStrm->dwStartTicks + lpMidiStrm->dwPositionMS;
1640 TRACE("%ld/%ld/%ld\n", dwToGo, GetTickCount(), me->dwDeltaTime);
1641 while ((dwCurrTC = GetTickCount()) < dwToGo) {
1642 if (MsgWaitForMultipleObjects(0, NULL, FALSE, dwToGo - dwCurrTC, QS_ALLINPUT) == WAIT_OBJECT_0) {
1643 /* got a message, handle it */
1644 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) {
1645 if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm, lpwm, &msg))
1650 /* timeout, so me->dwDeltaTime is elapsed, can break the while loop */
1655 switch (MEVT_EVENTTYPE(me->dwEvent & ~MEVT_F_CALLBACK)) {
1657 FIXME("NIY: MEVT_COMMENT\n");
1658 /* do nothing, skip bytes */
1661 FIXME("NIY: MEVT_LONGMSG, aka sending Sysex event\n");
1666 midiOutShortMsg(lpMidiStrm->hDevice, MEVT_EVENTPARM(me->dwEvent));
1669 lpMidiStrm->dwTempo = MEVT_EVENTPARM(me->dwEvent);
1674 FIXME("Unknown MEVT (0x%02x)\n", MEVT_EVENTTYPE(me->dwEvent & ~MEVT_F_CALLBACK));
1677 if (me->dwEvent & MEVT_F_CALLBACK) {
1678 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1679 (HDRVR)lpMidiStrm->hDevice, MM_MOM_POSITIONCB,
1680 lpwm->mod.dwInstance, (LPARAM)lpMidiHdr, 0L);
1682 lpMidiHdr->dwOffset += sizeof(MIDIEVENT) - sizeof(me->dwParms);
1683 if (me->dwEvent & MEVT_F_LONG)
1684 lpMidiHdr->dwOffset += (MEVT_EVENTPARM(me->dwEvent) + 3) & ~3;
1685 if (lpMidiHdr->dwOffset >= lpMidiHdr->dwBufferLength) {
1686 /* done with this header */
1687 lpMidiHdr->dwFlags |= MHDR_DONE;
1688 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
1690 lpMidiStrm->lpMidiHdr = (LPMIDIHDR)lpMidiHdr->lpNext;
1691 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1692 (HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
1693 lpwm->mod.dwInstance, (DWORD)lpMidiHdr, 0L);
1698 TRACE("End of thread\n");
1700 return 0; /* for removing the warning, never executed */
1703 /**************************************************************************
1704 * MMSYSTEM_MidiStream_PostMessage [internal]
1706 static BOOL MMSYSTEM_MidiStream_PostMessage(WINE_MIDIStream* lpMidiStrm, WORD msg, DWORD pmt1, DWORD pmt2)
1708 if (PostThreadMessageA(lpMidiStrm->dwThreadID, msg, pmt1, pmt2)) {
1711 if (pFnReleaseThunkLock) pFnReleaseThunkLock(&count);
1712 WaitForSingleObject(lpMidiStrm->hEvent, INFINITE);
1713 if (pFnRestoreThunkLock) pFnRestoreThunkLock(count);
1715 WARN("bad PostThreadMessageA\n");
1721 /**************************************************************************
1722 * midiStreamClose [WINMM.@]
1724 MMRESULT WINAPI midiStreamClose(HMIDISTRM hMidiStrm)
1726 WINE_MIDIStream* lpMidiStrm;
1728 TRACE("(%p)!\n", hMidiStrm);
1730 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL))
1731 return MMSYSERR_INVALHANDLE;
1733 midiStreamStop(hMidiStrm);
1734 MMSYSTEM_MidiStream_PostMessage(lpMidiStrm, WM_QUIT, 0, 0);
1735 HeapFree(GetProcessHeap(), 0, lpMidiStrm);
1736 CloseHandle(lpMidiStrm->hEvent);
1738 return midiOutClose((HMIDIOUT)hMidiStrm);
1741 /**************************************************************************
1742 * MMSYSTEM_MidiStream_Open [internal]
1744 MMRESULT MIDI_StreamOpen(HMIDISTRM* lphMidiStrm, LPUINT lpuDeviceID, DWORD cMidi,
1745 DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD fdwOpen,
1748 WINE_MIDIStream* lpMidiStrm;
1750 MIDIOPENSTRMID mosm;
1754 TRACE("(%p, %p, %ld, 0x%08lx, 0x%08lx, 0x%08lx)!\n",
1755 lphMidiStrm, lpuDeviceID, cMidi, dwCallback, dwInstance, fdwOpen);
1757 if (cMidi != 1 || lphMidiStrm == NULL || lpuDeviceID == NULL)
1758 return MMSYSERR_INVALPARAM;
1760 lpMidiStrm = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_MIDIStream));
1762 return MMSYSERR_NOMEM;
1764 lpMidiStrm->dwTempo = 500000;
1765 lpMidiStrm->dwTimeDiv = 480; /* 480 is 120 quater notes per minute *//* FIXME ??*/
1766 lpMidiStrm->dwPositionMS = 0;
1768 mosm.dwStreamID = (DWORD)lpMidiStrm;
1769 /* FIXME: the correct value is not allocated yet for MAPPER */
1770 mosm.wDeviceID = *lpuDeviceID;
1771 lpwm = MIDI_OutAlloc(&hMidiOut, &dwCallback, &dwInstance, &fdwOpen, 1, &mosm, bFrom32);
1772 lpMidiStrm->hDevice = hMidiOut;
1774 *lphMidiStrm = (HMIDISTRM)hMidiOut;
1776 lpwm->mld.uDeviceID = *lpuDeviceID;
1778 ret = MMDRV_Open(&lpwm->mld, MODM_OPEN, (DWORD)&lpwm->mod, fdwOpen);
1779 lpMidiStrm->hEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
1780 lpMidiStrm->wFlags = HIWORD(fdwOpen);
1782 lpMidiStrm->hThread = CreateThread(NULL, 0, MMSYSTEM_MidiStream_Player,
1783 lpMidiStrm, 0, &(lpMidiStrm->dwThreadID));
1785 if (!lpMidiStrm->hThread) {
1786 midiStreamClose((HMIDISTRM)hMidiOut);
1787 return MMSYSERR_NOMEM;
1789 SetThreadPriority(lpMidiStrm->hThread, THREAD_PRIORITY_TIME_CRITICAL);
1791 /* wait for thread to have started, and for its queue to be created */
1795 /* (Release|Restore)ThunkLock() is needed when this method is called from 16 bit code,
1796 * (meaning the Win16Lock is set), so that it's released and the 32 bit thread running
1797 * MMSYSTEM_MidiStreamPlayer can acquire Win16Lock to create its queue.
1799 if (pFnReleaseThunkLock) pFnReleaseThunkLock(&count);
1800 WaitForSingleObject(lpMidiStrm->hEvent, INFINITE);
1801 if (pFnRestoreThunkLock) pFnRestoreThunkLock(count);
1804 TRACE("=> (%u/%d) hMidi=%p ret=%d lpMidiStrm=%p\n",
1805 *lpuDeviceID, lpwm->mld.uDeviceID, *lphMidiStrm, ret, lpMidiStrm);
1809 /**************************************************************************
1810 * midiStreamOpen [WINMM.@]
1812 MMRESULT WINAPI midiStreamOpen(HMIDISTRM* lphMidiStrm, LPUINT lpuDeviceID,
1813 DWORD cMidi, DWORD_PTR dwCallback,
1814 DWORD_PTR dwInstance, DWORD fdwOpen)
1816 return MIDI_StreamOpen(lphMidiStrm, lpuDeviceID, cMidi, dwCallback,
1817 dwInstance, fdwOpen, TRUE);
1820 /**************************************************************************
1821 * midiStreamOut [WINMM.@]
1823 MMRESULT WINAPI midiStreamOut(HMIDISTRM hMidiStrm, LPMIDIHDR lpMidiHdr,
1826 WINE_MIDIStream* lpMidiStrm;
1827 DWORD ret = MMSYSERR_NOERROR;
1829 TRACE("(%p, %p, %u)!\n", hMidiStrm, lpMidiHdr, cbMidiHdr);
1831 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1832 ret = MMSYSERR_INVALHANDLE;
1833 } else if (!lpMidiHdr) {
1834 ret = MMSYSERR_INVALPARAM;
1836 if (!PostThreadMessageA(lpMidiStrm->dwThreadID,
1837 WINE_MSM_HEADER, cbMidiHdr,
1838 (DWORD)lpMidiHdr)) {
1839 WARN("bad PostThreadMessageA\n");
1840 ret = MMSYSERR_ERROR;
1846 /**************************************************************************
1847 * midiStreamPause [WINMM.@]
1849 MMRESULT WINAPI midiStreamPause(HMIDISTRM hMidiStrm)
1851 WINE_MIDIStream* lpMidiStrm;
1852 DWORD ret = MMSYSERR_NOERROR;
1854 TRACE("(%p)!\n", hMidiStrm);
1856 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1857 ret = MMSYSERR_INVALHANDLE;
1859 if (SuspendThread(lpMidiStrm->hThread) == 0xFFFFFFFF) {
1860 WARN("bad Suspend (%ld)\n", GetLastError());
1861 ret = MMSYSERR_ERROR;
1867 /**************************************************************************
1868 * midiStreamPosition [WINMM.@]
1870 MMRESULT WINAPI midiStreamPosition(HMIDISTRM hMidiStrm, LPMMTIME lpMMT, UINT cbmmt)
1872 WINE_MIDIStream* lpMidiStrm;
1873 DWORD ret = MMSYSERR_NOERROR;
1875 TRACE("(%p, %p, %u)!\n", hMidiStrm, lpMMT, cbmmt);
1877 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1878 ret = MMSYSERR_INVALHANDLE;
1879 } else if (lpMMT == NULL || cbmmt != sizeof(MMTIME)) {
1880 ret = MMSYSERR_INVALPARAM;
1882 switch (lpMMT->wType) {
1884 lpMMT->u.ms = lpMidiStrm->dwPositionMS;
1885 TRACE("=> %ld ms\n", lpMMT->u.ms);
1888 lpMMT->u.ticks = lpMidiStrm->dwPulses;
1889 TRACE("=> %ld ticks\n", lpMMT->u.ticks);
1892 WARN("Unsupported time type %d\n", lpMMT->wType);
1893 lpMMT->wType = TIME_MS;
1894 ret = MMSYSERR_INVALPARAM;
1901 /**************************************************************************
1902 * midiStreamProperty [WINMM.@]
1904 MMRESULT WINAPI midiStreamProperty(HMIDISTRM hMidiStrm, LPBYTE lpPropData, DWORD dwProperty)
1906 WINE_MIDIStream* lpMidiStrm;
1907 MMRESULT ret = MMSYSERR_NOERROR;
1909 TRACE("(%p, %p, %lx)\n", hMidiStrm, lpPropData, dwProperty);
1911 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1912 ret = MMSYSERR_INVALHANDLE;
1913 } else if ((dwProperty & (MIDIPROP_GET|MIDIPROP_SET)) == 0) {
1914 ret = MMSYSERR_INVALPARAM;
1915 } else if (dwProperty & MIDIPROP_TEMPO) {
1916 MIDIPROPTEMPO* mpt = (MIDIPROPTEMPO*)lpPropData;
1918 if (sizeof(MIDIPROPTEMPO) != mpt->cbStruct) {
1919 ret = MMSYSERR_INVALPARAM;
1920 } else if (dwProperty & MIDIPROP_SET) {
1921 lpMidiStrm->dwTempo = mpt->dwTempo;
1922 TRACE("Setting tempo to %ld\n", mpt->dwTempo);
1923 } else if (dwProperty & MIDIPROP_GET) {
1924 mpt->dwTempo = lpMidiStrm->dwTempo;
1925 TRACE("Getting tempo <= %ld\n", mpt->dwTempo);
1927 } else if (dwProperty & MIDIPROP_TIMEDIV) {
1928 MIDIPROPTIMEDIV* mptd = (MIDIPROPTIMEDIV*)lpPropData;
1930 if (sizeof(MIDIPROPTIMEDIV) != mptd->cbStruct) {
1931 ret = MMSYSERR_INVALPARAM;
1932 } else if (dwProperty & MIDIPROP_SET) {
1933 lpMidiStrm->dwTimeDiv = mptd->dwTimeDiv;
1934 TRACE("Setting time div to %ld\n", mptd->dwTimeDiv);
1935 } else if (dwProperty & MIDIPROP_GET) {
1936 mptd->dwTimeDiv = lpMidiStrm->dwTimeDiv;
1937 TRACE("Getting time div <= %ld\n", mptd->dwTimeDiv);
1940 ret = MMSYSERR_INVALPARAM;
1946 /**************************************************************************
1947 * midiStreamRestart [WINMM.@]
1949 MMRESULT WINAPI midiStreamRestart(HMIDISTRM hMidiStrm)
1951 WINE_MIDIStream* lpMidiStrm;
1952 MMRESULT ret = MMSYSERR_NOERROR;
1954 TRACE("(%p)!\n", hMidiStrm);
1956 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1957 ret = MMSYSERR_INVALHANDLE;
1961 /* since we increase the thread suspend count on each midiStreamPause
1962 * there may be a need for several midiStreamResume
1965 ret = ResumeThread(lpMidiStrm->hThread);
1966 } while (ret != 0xFFFFFFFF && ret != 0);
1967 if (ret == 0xFFFFFFFF) {
1968 WARN("bad Resume (%ld)\n", GetLastError());
1969 ret = MMSYSERR_ERROR;
1971 lpMidiStrm->dwStartTicks = GetTickCount() - lpMidiStrm->dwPositionMS;
1977 /**************************************************************************
1978 * midiStreamStop [WINMM.@]
1980 MMRESULT WINAPI midiStreamStop(HMIDISTRM hMidiStrm)
1982 WINE_MIDIStream* lpMidiStrm;
1983 MMRESULT ret = MMSYSERR_NOERROR;
1985 TRACE("(%p)!\n", hMidiStrm);
1987 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1988 ret = MMSYSERR_INVALHANDLE;
1990 /* in case stream has been paused... FIXME is the current state correct ? */
1991 midiStreamRestart(hMidiStrm);
1992 MMSYSTEM_MidiStream_PostMessage(lpMidiStrm, WINE_MSM_STOP, 0, 0);
1997 UINT WAVE_Open(HANDLE* lphndl, UINT uDeviceID, UINT uType,
1998 LPCWAVEFORMATEX lpFormat, DWORD_PTR dwCallback,
1999 DWORD_PTR dwInstance, DWORD dwFlags, BOOL bFrom32)
2003 DWORD dwRet = MMSYSERR_NOERROR;
2006 TRACE("(%p, %d, %s, %p, %08lX, %08lX, %08lX, %d);\n",
2007 lphndl, (int)uDeviceID, (uType==MMDRV_WAVEOUT)?"Out":"In", lpFormat, dwCallback,
2008 dwInstance, dwFlags, bFrom32?32:16);
2010 if (dwFlags & WAVE_FORMAT_QUERY)
2011 TRACE("WAVE_FORMAT_QUERY requested !\n");
2013 if (lpFormat == NULL) {
2014 WARN("bad format\n");
2015 return WAVERR_BADFORMAT;
2018 if ((dwFlags & WAVE_MAPPED) && (uDeviceID == (UINT)-1)) {
2019 WARN("invalid parameter\n");
2020 return MMSYSERR_INVALPARAM;
2023 /* may have a PCMWAVEFORMAT rather than a WAVEFORMATEX so don't read cbSize */
2024 TRACE("wFormatTag=%u, nChannels=%u, nSamplesPerSec=%lu, nAvgBytesPerSec=%lu, nBlockAlign=%u, wBitsPerSample=%u\n",
2025 lpFormat->wFormatTag, lpFormat->nChannels, lpFormat->nSamplesPerSec,
2026 lpFormat->nAvgBytesPerSec, lpFormat->nBlockAlign, lpFormat->wBitsPerSample);
2028 if ((wmld = MMDRV_Alloc(sizeof(WINE_WAVE), uType, &handle,
2029 &dwFlags, &dwCallback, &dwInstance, bFrom32)) == NULL) {
2030 WARN("no memory\n");
2031 return MMSYSERR_NOMEM;
2035 wod.lpFormat = (LPWAVEFORMATEX)lpFormat; /* should the struct be copied iso pointer? */
2036 wod.dwCallback = dwCallback;
2037 wod.dwInstance = dwInstance;
2040 TRACE("cb=%08lx\n", wod.dwCallback);
2043 if (dwFlags & WAVE_MAPPED) {
2044 wod.uMappedDeviceID = uDeviceID;
2045 uDeviceID = WAVE_MAPPER;
2047 wod.uMappedDeviceID = -1;
2049 wmld->uDeviceID = uDeviceID;
2051 dwRet = MMDRV_Open(wmld, (uType == MMDRV_WAVEOUT) ? WODM_OPEN : WIDM_OPEN,
2052 (DWORD)&wod, dwFlags);
2054 TRACE("dwRet = %s\n", WINMM_ErrorToString(dwRet));
2055 if (dwRet != WAVERR_BADFORMAT ||
2056 ((dwFlags & (WAVE_MAPPED|WAVE_FORMAT_DIRECT)) != 0) || (uDeviceID == WAVE_MAPPER)) break;
2057 /* if we ask for a format which isn't supported by the physical driver,
2058 * let's try to map it through the wave mapper (except, if we already tried
2059 * or user didn't allow us to use acm codecs or the device is already the mapper)
2061 dwFlags |= WAVE_MAPPED;
2062 /* we shall loop only one */
2065 if ((dwFlags & WAVE_FORMAT_QUERY) || dwRet != MMSYSERR_NOERROR) {
2066 MMDRV_Free(handle, wmld);
2070 if (lphndl != NULL) *lphndl = handle;
2071 TRACE("=> %s hWave=%p\n", WINMM_ErrorToString(dwRet), handle);
2076 /**************************************************************************
2077 * waveOutGetNumDevs [WINMM.@]
2079 UINT WINAPI waveOutGetNumDevs(void)
2081 return MMDRV_GetNum(MMDRV_WAVEOUT);
2084 /**************************************************************************
2085 * waveOutGetDevCapsA [WINMM.@]
2087 UINT WINAPI waveOutGetDevCapsA(UINT_PTR uDeviceID, LPWAVEOUTCAPSA lpCaps,
2093 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2095 ret = waveOutGetDevCapsW(uDeviceID, &wocW, sizeof(wocW));
2097 if (ret == MMSYSERR_NOERROR) {
2099 wocA.wMid = wocW.wMid;
2100 wocA.wPid = wocW.wPid;
2101 wocA.vDriverVersion = wocW.vDriverVersion;
2102 WideCharToMultiByte( CP_ACP, 0, wocW.szPname, -1, wocA.szPname,
2103 sizeof(wocA.szPname), NULL, NULL );
2104 wocA.dwFormats = wocW.dwFormats;
2105 wocA.wChannels = wocW.wChannels;
2106 wocA.dwSupport = wocW.dwSupport;
2107 memcpy(lpCaps, &wocA, min(uSize, sizeof(wocA)));
2112 /**************************************************************************
2113 * waveOutGetDevCapsW [WINMM.@]
2115 UINT WINAPI waveOutGetDevCapsW(UINT_PTR uDeviceID, LPWAVEOUTCAPSW lpCaps,
2120 TRACE("(%u %p %u)!\n", uDeviceID, lpCaps, uSize);
2122 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2124 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_WAVEOUT, TRUE)) == NULL)
2125 return MMSYSERR_BADDEVICEID;
2127 return MMDRV_Message(wmld, WODM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
2131 /**************************************************************************
2132 * waveOutGetErrorTextA [WINMM.@]
2133 * waveInGetErrorTextA [WINMM.@]
2135 UINT WINAPI waveOutGetErrorTextA(UINT uError, LPSTR lpText, UINT uSize)
2139 if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
2140 else if (uSize == 0) ret = MMSYSERR_NOERROR;
2143 LPWSTR xstr = HeapAlloc(GetProcessHeap(), 0, uSize * sizeof(WCHAR));
2144 if (!xstr) ret = MMSYSERR_NOMEM;
2147 ret = waveOutGetErrorTextW(uError, xstr, uSize);
2148 if (ret == MMSYSERR_NOERROR)
2149 WideCharToMultiByte(CP_ACP, 0, xstr, -1, lpText, uSize, NULL, NULL);
2150 HeapFree(GetProcessHeap(), 0, xstr);
2156 /**************************************************************************
2157 * waveOutGetErrorTextW [WINMM.@]
2158 * waveInGetErrorTextW [WINMM.@]
2160 UINT WINAPI waveOutGetErrorTextW(UINT uError, LPWSTR lpText, UINT uSize)
2162 UINT ret = MMSYSERR_BADERRNUM;
2164 if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
2165 else if (uSize == 0) ret = MMSYSERR_NOERROR;
2167 /* test has been removed 'coz MMSYSERR_BASE is 0, and gcc did emit
2168 * a warning for the test was always true */
2169 (/*uError >= MMSYSERR_BASE && */ uError <= MMSYSERR_LASTERROR) ||
2170 (uError >= WAVERR_BASE && uError <= WAVERR_LASTERROR)) {
2171 if (LoadStringW(WINMM_IData.hWinMM32Instance,
2172 uError, lpText, uSize) > 0) {
2173 ret = MMSYSERR_NOERROR;
2179 /**************************************************************************
2180 * waveOutOpen [WINMM.@]
2181 * All the args/structs have the same layout as the win16 equivalents
2183 MMRESULT WINAPI waveOutOpen(LPHWAVEOUT lphWaveOut, UINT uDeviceID,
2184 LPCWAVEFORMATEX lpFormat, DWORD_PTR dwCallback,
2185 DWORD_PTR dwInstance, DWORD dwFlags)
2187 return WAVE_Open((HANDLE*)lphWaveOut, uDeviceID, MMDRV_WAVEOUT, lpFormat,
2188 dwCallback, dwInstance, dwFlags, TRUE);
2191 /**************************************************************************
2192 * waveOutClose [WINMM.@]
2194 UINT WINAPI waveOutClose(HWAVEOUT hWaveOut)
2199 TRACE("(%p)\n", hWaveOut);
2201 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2202 return MMSYSERR_INVALHANDLE;
2204 dwRet = MMDRV_Close(wmld, WODM_CLOSE);
2205 if (dwRet != WAVERR_STILLPLAYING)
2206 MMDRV_Free(hWaveOut, wmld);
2211 /**************************************************************************
2212 * waveOutPrepareHeader [WINMM.@]
2214 UINT WINAPI waveOutPrepareHeader(HWAVEOUT hWaveOut,
2215 WAVEHDR* lpWaveOutHdr, UINT uSize)
2220 TRACE("(%p, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
2222 if (lpWaveOutHdr == NULL || uSize < sizeof (WAVEHDR))
2223 return MMSYSERR_INVALPARAM;
2225 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2226 return MMSYSERR_INVALHANDLE;
2228 if ((result = MMDRV_Message(wmld, WODM_PREPARE, (DWORD_PTR)lpWaveOutHdr,
2229 uSize, TRUE)) != MMSYSERR_NOTSUPPORTED)
2232 if (lpWaveOutHdr->dwFlags & WHDR_INQUEUE)
2233 return WAVERR_STILLPLAYING;
2235 lpWaveOutHdr->dwFlags |= WHDR_PREPARED;
2236 lpWaveOutHdr->dwFlags &= ~WHDR_DONE;
2238 return MMSYSERR_NOERROR;
2241 /**************************************************************************
2242 * waveOutUnprepareHeader [WINMM.@]
2244 UINT WINAPI waveOutUnprepareHeader(HWAVEOUT hWaveOut,
2245 LPWAVEHDR lpWaveOutHdr, UINT uSize)
2250 TRACE("(%p, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
2252 if (lpWaveOutHdr == NULL || uSize < sizeof (WAVEHDR))
2253 return MMSYSERR_INVALPARAM;
2255 if (!(lpWaveOutHdr->dwFlags & WHDR_PREPARED)) {
2256 return MMSYSERR_NOERROR;
2259 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2260 return MMSYSERR_INVALHANDLE;
2262 if ((result = MMDRV_Message(wmld, WODM_UNPREPARE, (DWORD_PTR)lpWaveOutHdr,
2263 uSize, TRUE)) != MMSYSERR_NOTSUPPORTED)
2266 if (lpWaveOutHdr->dwFlags & WHDR_INQUEUE)
2267 return WAVERR_STILLPLAYING;
2269 lpWaveOutHdr->dwFlags &= ~WHDR_PREPARED;
2270 lpWaveOutHdr->dwFlags |= WHDR_DONE;
2272 return MMSYSERR_NOERROR;
2275 /**************************************************************************
2276 * waveOutWrite [WINMM.@]
2278 UINT WINAPI waveOutWrite(HWAVEOUT hWaveOut, LPWAVEHDR lpWaveOutHdr,
2283 TRACE("(%p, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
2285 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2286 return MMSYSERR_INVALHANDLE;
2288 return MMDRV_Message(wmld, WODM_WRITE, (DWORD_PTR)lpWaveOutHdr, uSize, TRUE);
2291 /**************************************************************************
2292 * waveOutBreakLoop [WINMM.@]
2294 UINT WINAPI waveOutBreakLoop(HWAVEOUT hWaveOut)
2298 TRACE("(%p);\n", hWaveOut);
2300 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2301 return MMSYSERR_INVALHANDLE;
2302 return MMDRV_Message(wmld, WODM_BREAKLOOP, 0L, 0L, TRUE);
2305 /**************************************************************************
2306 * waveOutPause [WINMM.@]
2308 UINT WINAPI waveOutPause(HWAVEOUT hWaveOut)
2312 TRACE("(%p);\n", hWaveOut);
2314 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2315 return MMSYSERR_INVALHANDLE;
2316 return MMDRV_Message(wmld, WODM_PAUSE, 0L, 0L, TRUE);
2319 /**************************************************************************
2320 * waveOutReset [WINMM.@]
2322 UINT WINAPI waveOutReset(HWAVEOUT hWaveOut)
2326 TRACE("(%p);\n", hWaveOut);
2328 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2329 return MMSYSERR_INVALHANDLE;
2330 return MMDRV_Message(wmld, WODM_RESET, 0L, 0L, TRUE);
2333 /**************************************************************************
2334 * waveOutRestart [WINMM.@]
2336 UINT WINAPI waveOutRestart(HWAVEOUT hWaveOut)
2340 TRACE("(%p);\n", hWaveOut);
2342 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2343 return MMSYSERR_INVALHANDLE;
2344 return MMDRV_Message(wmld, WODM_RESTART, 0L, 0L, TRUE);
2347 /**************************************************************************
2348 * waveOutGetPosition [WINMM.@]
2350 UINT WINAPI waveOutGetPosition(HWAVEOUT hWaveOut, LPMMTIME lpTime,
2355 TRACE("(%p, %p, %u);\n", hWaveOut, lpTime, uSize);
2357 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2358 return MMSYSERR_INVALHANDLE;
2360 return MMDRV_Message(wmld, WODM_GETPOS, (DWORD_PTR)lpTime, uSize, TRUE);
2363 /**************************************************************************
2364 * waveOutGetPitch [WINMM.@]
2366 UINT WINAPI waveOutGetPitch(HWAVEOUT hWaveOut, LPDWORD lpdw)
2370 TRACE("(%p, %08lx);\n", hWaveOut, (DWORD)lpdw);
2372 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2373 return MMSYSERR_INVALHANDLE;
2374 return MMDRV_Message(wmld, WODM_GETPITCH, (DWORD_PTR)lpdw, 0L, TRUE);
2377 /**************************************************************************
2378 * waveOutSetPitch [WINMM.@]
2380 UINT WINAPI waveOutSetPitch(HWAVEOUT hWaveOut, DWORD dw)
2384 TRACE("(%p, %08lx);\n", hWaveOut, (DWORD)dw);
2386 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2387 return MMSYSERR_INVALHANDLE;
2388 return MMDRV_Message(wmld, WODM_SETPITCH, dw, 0L, TRUE);
2391 /**************************************************************************
2392 * waveOutGetPlaybackRate [WINMM.@]
2394 UINT WINAPI waveOutGetPlaybackRate(HWAVEOUT hWaveOut, LPDWORD lpdw)
2398 TRACE("(%p, %08lx);\n", hWaveOut, (DWORD)lpdw);
2400 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2401 return MMSYSERR_INVALHANDLE;
2402 return MMDRV_Message(wmld, WODM_GETPLAYBACKRATE, (DWORD_PTR)lpdw, 0L, TRUE);
2405 /**************************************************************************
2406 * waveOutSetPlaybackRate [WINMM.@]
2408 UINT WINAPI waveOutSetPlaybackRate(HWAVEOUT hWaveOut, DWORD dw)
2412 TRACE("(%p, %08lx);\n", hWaveOut, (DWORD)dw);
2414 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2415 return MMSYSERR_INVALHANDLE;
2416 return MMDRV_Message(wmld, WODM_SETPLAYBACKRATE, dw, 0L, TRUE);
2419 /**************************************************************************
2420 * waveOutGetVolume [WINMM.@]
2422 UINT WINAPI waveOutGetVolume(HWAVEOUT hWaveOut, LPDWORD lpdw)
2426 TRACE("(%p, %08lx);\n", hWaveOut, (DWORD)lpdw);
2428 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, TRUE)) == NULL)
2429 return MMSYSERR_INVALHANDLE;
2431 return MMDRV_Message(wmld, WODM_GETVOLUME, (DWORD_PTR)lpdw, 0L, TRUE);
2434 /**************************************************************************
2435 * waveOutSetVolume [WINMM.@]
2437 UINT WINAPI waveOutSetVolume(HWAVEOUT hWaveOut, DWORD dw)
2441 TRACE("(%p, %08lx);\n", hWaveOut, dw);
2443 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, TRUE)) == NULL)
2444 return MMSYSERR_INVALHANDLE;
2446 return MMDRV_Message(wmld, WODM_SETVOLUME, dw, 0L, TRUE);
2449 /**************************************************************************
2450 * waveOutGetID [WINMM.@]
2452 UINT WINAPI waveOutGetID(HWAVEOUT hWaveOut, UINT* lpuDeviceID)
2456 TRACE("(%p, %p);\n", hWaveOut, lpuDeviceID);
2458 if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
2460 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2461 return MMSYSERR_INVALHANDLE;
2463 *lpuDeviceID = wmld->uDeviceID;
2467 /**************************************************************************
2468 * waveOutMessage [WINMM.@]
2470 UINT WINAPI waveOutMessage(HWAVEOUT hWaveOut, UINT uMessage,
2471 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2475 TRACE("(%p, %u, %ld, %ld)\n", hWaveOut, uMessage, dwParam1, dwParam2);
2477 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL) {
2478 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, TRUE)) != NULL) {
2479 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
2481 WARN("invalid handle\n");
2482 return MMSYSERR_INVALHANDLE;
2486 if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER)) {
2487 WARN("invalid parameter\n");
2488 return MMSYSERR_INVALPARAM;
2491 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
2494 /**************************************************************************
2495 * waveInGetNumDevs [WINMM.@]
2497 UINT WINAPI waveInGetNumDevs(void)
2499 return MMDRV_GetNum(MMDRV_WAVEIN);
2502 /**************************************************************************
2503 * waveInGetDevCapsW [WINMM.@]
2505 UINT WINAPI waveInGetDevCapsW(UINT_PTR uDeviceID, LPWAVEINCAPSW lpCaps, UINT uSize)
2509 TRACE("(%u %p %u)!\n", uDeviceID, lpCaps, uSize);
2511 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2513 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_WAVEIN, TRUE)) == NULL)
2514 return MMSYSERR_BADDEVICEID;
2516 return MMDRV_Message(wmld, WIDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
2519 /**************************************************************************
2520 * waveInGetDevCapsA [WINMM.@]
2522 UINT WINAPI waveInGetDevCapsA(UINT_PTR uDeviceID, LPWAVEINCAPSA lpCaps, UINT uSize)
2527 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2529 ret = waveInGetDevCapsW(uDeviceID, &wicW, sizeof(wicW));
2531 if (ret == MMSYSERR_NOERROR) {
2533 wicA.wMid = wicW.wMid;
2534 wicA.wPid = wicW.wPid;
2535 wicA.vDriverVersion = wicW.vDriverVersion;
2536 WideCharToMultiByte( CP_ACP, 0, wicW.szPname, -1, wicA.szPname,
2537 sizeof(wicA.szPname), NULL, NULL );
2538 wicA.dwFormats = wicW.dwFormats;
2539 wicA.wChannels = wicW.wChannels;
2540 memcpy(lpCaps, &wicA, min(uSize, sizeof(wicA)));
2545 /**************************************************************************
2546 * waveInOpen [WINMM.@]
2548 MMRESULT WINAPI waveInOpen(HWAVEIN* lphWaveIn, UINT uDeviceID,
2549 LPCWAVEFORMATEX lpFormat, DWORD_PTR dwCallback,
2550 DWORD_PTR dwInstance, DWORD dwFlags)
2552 return WAVE_Open((HANDLE*)lphWaveIn, uDeviceID, MMDRV_WAVEIN, lpFormat,
2553 dwCallback, dwInstance, dwFlags, TRUE);
2556 /**************************************************************************
2557 * waveInClose [WINMM.@]
2559 UINT WINAPI waveInClose(HWAVEIN hWaveIn)
2564 TRACE("(%p)\n", hWaveIn);
2566 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2567 return MMSYSERR_INVALHANDLE;
2569 dwRet = MMDRV_Message(wmld, WIDM_CLOSE, 0L, 0L, TRUE);
2570 if (dwRet != WAVERR_STILLPLAYING)
2571 MMDRV_Free(hWaveIn, wmld);
2575 /**************************************************************************
2576 * waveInPrepareHeader [WINMM.@]
2578 UINT WINAPI waveInPrepareHeader(HWAVEIN hWaveIn, WAVEHDR* lpWaveInHdr,
2584 TRACE("(%p, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
2586 if (lpWaveInHdr == NULL || uSize < sizeof (WAVEHDR))
2587 return MMSYSERR_INVALPARAM;
2589 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2590 return MMSYSERR_INVALHANDLE;
2592 if ((result = MMDRV_Message(wmld, WIDM_PREPARE, (DWORD_PTR)lpWaveInHdr,
2593 uSize, TRUE)) != MMSYSERR_NOTSUPPORTED)
2596 if (lpWaveInHdr->dwFlags & WHDR_INQUEUE)
2597 return WAVERR_STILLPLAYING;
2599 lpWaveInHdr->dwFlags |= WHDR_PREPARED;
2600 lpWaveInHdr->dwFlags &= ~WHDR_DONE;
2601 lpWaveInHdr->dwBytesRecorded = 0;
2603 return MMSYSERR_NOERROR;
2606 /**************************************************************************
2607 * waveInUnprepareHeader [WINMM.@]
2609 UINT WINAPI waveInUnprepareHeader(HWAVEIN hWaveIn, WAVEHDR* lpWaveInHdr,
2615 TRACE("(%p, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
2617 if (lpWaveInHdr == NULL || uSize < sizeof (WAVEHDR))
2618 return MMSYSERR_INVALPARAM;
2620 if (!(lpWaveInHdr->dwFlags & WHDR_PREPARED))
2621 return MMSYSERR_NOERROR;
2623 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2624 return MMSYSERR_INVALHANDLE;
2626 if ((result = MMDRV_Message(wmld, WIDM_UNPREPARE, (DWORD_PTR)lpWaveInHdr,
2627 uSize, TRUE)) != MMSYSERR_NOTSUPPORTED)
2630 if (lpWaveInHdr->dwFlags & WHDR_INQUEUE)
2631 return WAVERR_STILLPLAYING;
2633 lpWaveInHdr->dwFlags &= ~WHDR_PREPARED;
2634 lpWaveInHdr->dwFlags |= WHDR_DONE;
2636 return MMSYSERR_NOERROR;
2639 /**************************************************************************
2640 * waveInAddBuffer [WINMM.@]
2642 UINT WINAPI waveInAddBuffer(HWAVEIN hWaveIn,
2643 WAVEHDR* lpWaveInHdr, UINT uSize)
2647 TRACE("(%p, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
2649 if (lpWaveInHdr == NULL) return MMSYSERR_INVALPARAM;
2650 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2651 return MMSYSERR_INVALHANDLE;
2653 return MMDRV_Message(wmld, WIDM_ADDBUFFER, (DWORD_PTR)lpWaveInHdr, uSize, TRUE);
2656 /**************************************************************************
2657 * waveInReset [WINMM.@]
2659 UINT WINAPI waveInReset(HWAVEIN hWaveIn)
2663 TRACE("(%p);\n", hWaveIn);
2665 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2666 return MMSYSERR_INVALHANDLE;
2668 return MMDRV_Message(wmld, WIDM_RESET, 0L, 0L, TRUE);
2671 /**************************************************************************
2672 * waveInStart [WINMM.@]
2674 UINT WINAPI waveInStart(HWAVEIN hWaveIn)
2678 TRACE("(%p);\n", hWaveIn);
2680 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2681 return MMSYSERR_INVALHANDLE;
2683 return MMDRV_Message(wmld, WIDM_START, 0L, 0L, TRUE);
2686 /**************************************************************************
2687 * waveInStop [WINMM.@]
2689 UINT WINAPI waveInStop(HWAVEIN hWaveIn)
2693 TRACE("(%p);\n", hWaveIn);
2695 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2696 return MMSYSERR_INVALHANDLE;
2698 return MMDRV_Message(wmld,WIDM_STOP, 0L, 0L, TRUE);
2701 /**************************************************************************
2702 * waveInGetPosition [WINMM.@]
2704 UINT WINAPI waveInGetPosition(HWAVEIN hWaveIn, LPMMTIME lpTime,
2709 TRACE("(%p, %p, %u);\n", hWaveIn, lpTime, uSize);
2711 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2712 return MMSYSERR_INVALHANDLE;
2714 return MMDRV_Message(wmld, WIDM_GETPOS, (DWORD_PTR)lpTime, uSize, TRUE);
2717 /**************************************************************************
2718 * waveInGetID [WINMM.@]
2720 UINT WINAPI waveInGetID(HWAVEIN hWaveIn, UINT* lpuDeviceID)
2724 TRACE("(%p, %p);\n", hWaveIn, lpuDeviceID);
2726 if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
2728 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2729 return MMSYSERR_INVALHANDLE;
2731 *lpuDeviceID = wmld->uDeviceID;
2732 return MMSYSERR_NOERROR;
2735 /**************************************************************************
2736 * waveInMessage [WINMM.@]
2738 UINT WINAPI waveInMessage(HWAVEIN hWaveIn, UINT uMessage,
2739 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2743 TRACE("(%p, %u, %ld, %ld)\n", hWaveIn, uMessage, dwParam1, dwParam2);
2745 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL) {
2746 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, TRUE)) != NULL) {
2747 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
2749 return MMSYSERR_INVALHANDLE;
2753 if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER))
2754 return MMSYSERR_INVALPARAM;
2757 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
2767 static DWORD WINAPI mmTaskRun(void* pmt)
2769 struct mm_starter mms;
2771 memcpy(&mms, pmt, sizeof(struct mm_starter));
2772 HeapFree(GetProcessHeap(), 0, pmt);
2774 if (mms.event) SetEvent(mms.event);
2778 /******************************************************************
2779 * mmTaskCreate (WINMM.@)
2781 MMRESULT WINAPI mmTaskCreate(LPTASKCALLBACK cb, HANDLE* ph, DWORD client)
2785 struct mm_starter *mms;
2787 mms = HeapAlloc(GetProcessHeap(), 0, sizeof(struct mm_starter));
2788 if (mms == NULL) return TASKERR_OUTOFMEMORY;
2791 mms->client = client;
2792 if (ph) hEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
2793 mms->event = hEvent;
2795 hThread = CreateThread(0, 0, mmTaskRun, mms, 0, NULL);
2797 HeapFree(GetProcessHeap(), 0, mms);
2798 if (hEvent) CloseHandle(hEvent);
2799 return TASKERR_OUTOFMEMORY;
2801 SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);
2802 if (ph) *ph = hEvent;
2803 CloseHandle(hThread);
2807 /******************************************************************
2808 * mmTaskBlock (WINMM.@)
2810 void WINAPI mmTaskBlock(HANDLE tid)
2816 GetMessageA(&msg, 0, 0, 0);
2817 if (msg.hwnd) DispatchMessageA(&msg);
2818 } while (msg.message != WM_USER);
2821 /******************************************************************
2822 * mmTaskSignal (WINMM.@)
2824 BOOL WINAPI mmTaskSignal(HANDLE tid)
2826 return PostThreadMessageW((DWORD)tid, WM_USER, 0, 0);
2829 /******************************************************************
2830 * mmTaskYield (WINMM.@)
2832 void WINAPI mmTaskYield(void) {}
2834 /******************************************************************
2835 * mmGetCurrentTask (WINMM.@)
2837 HANDLE WINAPI mmGetCurrentTask(void)
2839 return (HANDLE)GetCurrentThreadId();