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
34 #define NONAMELESSUNION
35 #define NONAMELESSSTRUCT
46 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(winmm);
50 /******************************************************************
53 * Internal wrapper to call USER.UserYield16 (in fact through a Wine only export from USER32).
55 static void MyUserYield(void)
57 HMODULE mod = GetModuleHandleA( "user32.dll" );
60 FARPROC proc = GetProcAddress( mod, "UserYield16" );
65 void (WINAPI *pFnReleaseThunkLock)(DWORD*);
66 void (WINAPI *pFnRestoreThunkLock)(DWORD);
68 /* ========================================================================
69 * G L O B A L S E T T I N G S
70 * ========================================================================*/
72 LPWINE_MM_IDATA WINMM_IData /* = NULL */;
74 /**************************************************************************
75 * WINMM_CreateIData [internal]
77 static BOOL WINMM_CreateIData(HINSTANCE hInstDLL)
79 WINMM_IData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINE_MM_IDATA));
83 WINMM_IData->hWinMM32Instance = hInstDLL;
84 InitializeCriticalSection(&WINMM_IData->cs);
85 WINMM_IData->cs.DebugInfo = (void*)__FILE__ ": WinMM";
86 WINMM_IData->psStopEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
87 WINMM_IData->psLastEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
88 TRACE("Created IData (%p)\n", WINMM_IData);
92 /**************************************************************************
93 * WINMM_DeleteIData [internal]
95 static void WINMM_DeleteIData(void)
100 /* FIXME: should also free content and resources allocated
101 * inside WINMM_IData */
102 CloseHandle(WINMM_IData->psStopEvent);
103 CloseHandle(WINMM_IData->psLastEvent);
104 DeleteCriticalSection(&WINMM_IData->cs);
105 HeapFree(GetProcessHeap(), 0, WINMM_IData);
110 /******************************************************************
114 static HANDLE (WINAPI *pGetModuleHandle16)(LPCSTR);
115 static DWORD (WINAPI *pLoadLibrary16)(LPCSTR);
117 BOOL WINMM_CheckForMMSystem(void)
119 /* 0 is not checked yet, -1 is not present, 1 is present */
120 static int loaded /* = 0 */;
124 HANDLE h = GetModuleHandleA("kernel32");
128 pGetModuleHandle16 = (void*)GetProcAddress(h, "GetModuleHandle16");
129 pLoadLibrary16 = (void*)GetProcAddress(h, "LoadLibrary16");
130 if (pGetModuleHandle16 && pLoadLibrary16 &&
131 (pGetModuleHandle16("MMSYSTEM.DLL") || pLoadLibrary16("MMSYSTEM.DLL")))
138 /**************************************************************************
139 * DllMain (WINMM.init)
141 * WINMM DLL entry point
144 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID fImpLoad)
146 TRACE("%p 0x%lx %p\n", hInstDLL, fdwReason, fImpLoad);
149 case DLL_PROCESS_ATTACH:
150 DisableThreadLibraryCalls(hInstDLL);
152 if (!WINMM_CreateIData(hInstDLL))
154 if (!MCI_Init() || !MMDRV_Init()) {
159 case DLL_PROCESS_DETACH:
160 /* close all opened MCI drivers */
161 MCI_SendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_WAIT, 0L, TRUE);
163 /* now unload all remaining drivers... */
172 /**************************************************************************
173 * Mixer devices. New to Win95
176 /**************************************************************************
177 * find out the real mixer ID depending on hmix (depends on dwFlags)
179 static LPWINE_MIXER MIXER_GetDev(HMIXEROBJ hmix, DWORD dwFlags)
181 LPWINE_MIXER lpwm = NULL;
183 switch (dwFlags & 0xF0000000ul) {
184 case MIXER_OBJECTF_MIXER:
185 lpwm = (LPWINE_MIXER)MMDRV_Get(hmix, MMDRV_MIXER, TRUE);
187 case MIXER_OBJECTF_HMIXER:
188 lpwm = (LPWINE_MIXER)MMDRV_Get(hmix, MMDRV_MIXER, FALSE);
190 case MIXER_OBJECTF_WAVEOUT:
191 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEOUT, TRUE, MMDRV_MIXER);
193 case MIXER_OBJECTF_HWAVEOUT:
194 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEOUT, FALSE, MMDRV_MIXER);
196 case MIXER_OBJECTF_WAVEIN:
197 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEIN, TRUE, MMDRV_MIXER);
199 case MIXER_OBJECTF_HWAVEIN:
200 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEIN, FALSE, MMDRV_MIXER);
202 case MIXER_OBJECTF_MIDIOUT:
203 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIOUT, TRUE, MMDRV_MIXER);
205 case MIXER_OBJECTF_HMIDIOUT:
206 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIOUT, FALSE, MMDRV_MIXER);
208 case MIXER_OBJECTF_MIDIIN:
209 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIIN, TRUE, MMDRV_MIXER);
211 case MIXER_OBJECTF_HMIDIIN:
212 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIIN, FALSE, MMDRV_MIXER);
214 case MIXER_OBJECTF_AUX:
215 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_AUX, TRUE, MMDRV_MIXER);
218 FIXME("Unsupported flag (%08lx)\n", dwFlags & 0xF0000000ul);
224 /**************************************************************************
225 * mixerGetNumDevs [WINMM.@]
227 UINT WINAPI mixerGetNumDevs(void)
229 return MMDRV_GetNum(MMDRV_MIXER);
232 /**************************************************************************
233 * mixerGetDevCapsA [WINMM.@]
235 UINT WINAPI mixerGetDevCapsA(UINT_PTR uDeviceID, LPMIXERCAPSA lpCaps, UINT uSize)
239 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
241 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_MIXER, TRUE)) == NULL)
242 return MMSYSERR_BADDEVICEID;
244 return MMDRV_Message(wmld, MXDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
247 /**************************************************************************
248 * mixerGetDevCapsW [WINMM.@]
250 UINT WINAPI mixerGetDevCapsW(UINT_PTR uDeviceID, LPMIXERCAPSW lpCaps, UINT uSize)
253 UINT ret = mixerGetDevCapsA(uDeviceID, &micA, sizeof(micA));
255 if (ret == MMSYSERR_NOERROR) {
257 micW.wMid = micA.wMid;
258 micW.wPid = micA.wPid;
259 micW.vDriverVersion = micA.vDriverVersion;
260 MultiByteToWideChar( CP_ACP, 0, micA.szPname, -1, micW.szPname,
261 sizeof(micW.szPname)/sizeof(WCHAR) );
262 micW.fdwSupport = micA.fdwSupport;
263 micW.cDestinations = micA.cDestinations;
264 memcpy(lpCaps, &micW, min(uSize, sizeof(micW)));
269 UINT MIXER_Open(LPHMIXER lphMix, UINT uDeviceID, DWORD_PTR dwCallback,
270 DWORD_PTR dwInstance, DWORD fdwOpen, BOOL bFrom32)
277 TRACE("(%p, %d, %08lx, %08lx, %08lx)\n",
278 lphMix, uDeviceID, dwCallback, dwInstance, fdwOpen);
280 wmld = MMDRV_Alloc(sizeof(WINE_MIXER), MMDRV_MIXER, &hMix, &fdwOpen,
281 &dwCallback, &dwInstance, bFrom32);
283 wmld->uDeviceID = uDeviceID;
284 mod.hmx = (HMIXEROBJ)hMix;
285 mod.dwCallback = dwCallback;
286 mod.dwInstance = dwInstance;
288 dwRet = MMDRV_Open(wmld, MXDM_OPEN, (DWORD)&mod, fdwOpen);
290 if (dwRet != MMSYSERR_NOERROR) {
291 MMDRV_Free(hMix, wmld);
294 if (lphMix) *lphMix = hMix;
295 TRACE("=> %ld hMixer=%p\n", dwRet, hMix);
300 /**************************************************************************
301 * mixerOpen [WINMM.@]
303 UINT WINAPI mixerOpen(LPHMIXER lphMix, UINT uDeviceID, DWORD_PTR dwCallback,
304 DWORD_PTR dwInstance, DWORD fdwOpen)
306 return MIXER_Open(lphMix, uDeviceID, dwCallback, dwInstance, fdwOpen, TRUE);
309 /**************************************************************************
310 * mixerClose [WINMM.@]
312 UINT WINAPI mixerClose(HMIXER hMix)
317 TRACE("(%p)\n", hMix);
319 if ((wmld = MMDRV_Get(hMix, MMDRV_MIXER, FALSE)) == NULL) return MMSYSERR_INVALHANDLE;
321 dwRet = MMDRV_Close(wmld, MXDM_CLOSE);
322 MMDRV_Free(hMix, wmld);
327 /**************************************************************************
328 * mixerGetID [WINMM.@]
330 UINT WINAPI mixerGetID(HMIXEROBJ hmix, LPUINT lpid, DWORD fdwID)
334 TRACE("(%p %p %08lx)\n", hmix, lpid, fdwID);
336 if ((lpwm = MIXER_GetDev(hmix, fdwID)) == NULL) {
337 return MMSYSERR_INVALHANDLE;
341 *lpid = lpwm->mld.uDeviceID;
343 return MMSYSERR_NOERROR;
346 /**************************************************************************
347 * mixerGetControlDetailsA [WINMM.@]
349 UINT WINAPI mixerGetControlDetailsA(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcdA,
354 TRACE("(%p, %p, %08lx)\n", hmix, lpmcdA, fdwDetails);
356 if ((lpwm = MIXER_GetDev(hmix, fdwDetails)) == NULL)
357 return MMSYSERR_INVALHANDLE;
359 if (lpmcdA == NULL || lpmcdA->cbStruct != sizeof(*lpmcdA))
360 return MMSYSERR_INVALPARAM;
362 return MMDRV_Message(&lpwm->mld, MXDM_GETCONTROLDETAILS, (DWORD_PTR)lpmcdA,
366 /**************************************************************************
367 * mixerGetControlDetailsW [WINMM.@]
369 UINT WINAPI mixerGetControlDetailsW(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcd, DWORD fdwDetails)
371 DWORD ret = MMSYSERR_NOTENABLED;
373 TRACE("(%p, %p, %08lx)\n", hmix, lpmcd, fdwDetails);
375 if (lpmcd == NULL || lpmcd->cbStruct != sizeof(*lpmcd))
376 return MMSYSERR_INVALPARAM;
378 switch (fdwDetails & MIXER_GETCONTROLDETAILSF_QUERYMASK) {
379 case MIXER_GETCONTROLDETAILSF_VALUE:
380 /* can savely use W structure as it is, no string inside */
381 ret = mixerGetControlDetailsA(hmix, lpmcd, fdwDetails);
383 case MIXER_GETCONTROLDETAILSF_LISTTEXT:
385 MIXERCONTROLDETAILS_LISTTEXTW *pDetailsW = (MIXERCONTROLDETAILS_LISTTEXTW *)lpmcd->paDetails;
386 MIXERCONTROLDETAILS_LISTTEXTA *pDetailsA;
387 int size = max(1, lpmcd->cChannels) * sizeof(MIXERCONTROLDETAILS_LISTTEXTA);
390 if (lpmcd->u.cMultipleItems != 0) {
391 size *= lpmcd->u.cMultipleItems;
393 pDetailsA = (MIXERCONTROLDETAILS_LISTTEXTA *)HeapAlloc(GetProcessHeap(), 0, size);
394 lpmcd->paDetails = pDetailsA;
395 lpmcd->cbDetails = sizeof(MIXERCONTROLDETAILS_LISTTEXTA);
396 /* set up lpmcd->paDetails */
397 ret = mixerGetControlDetailsA(hmix, lpmcd, fdwDetails);
398 /* copy from lpmcd->paDetails back to paDetailsW; */
399 if(ret == MMSYSERR_NOERROR) {
400 for(i=0;i<lpmcd->u.cMultipleItems*lpmcd->cChannels;i++) {
401 pDetailsW->dwParam1 = pDetailsA->dwParam1;
402 pDetailsW->dwParam2 = pDetailsA->dwParam2;
403 MultiByteToWideChar( CP_ACP, 0, pDetailsA->szName, -1,
405 sizeof(pDetailsW->szName)/sizeof(WCHAR) );
409 pDetailsA -= lpmcd->u.cMultipleItems*lpmcd->cChannels;
410 pDetailsW -= lpmcd->u.cMultipleItems*lpmcd->cChannels;
412 HeapFree(GetProcessHeap(), 0, pDetailsA);
413 lpmcd->paDetails = pDetailsW;
414 lpmcd->cbDetails = sizeof(MIXERCONTROLDETAILS_LISTTEXTW);
418 ERR("Unsupported fdwDetails=0x%08lx\n", fdwDetails);
424 /**************************************************************************
425 * mixerGetLineControlsA [WINMM.@]
427 UINT WINAPI mixerGetLineControlsA(HMIXEROBJ hmix, LPMIXERLINECONTROLSA lpmlcA,
432 TRACE("(%p, %p, %08lx)\n", hmix, lpmlcA, fdwControls);
434 if ((lpwm = MIXER_GetDev(hmix, fdwControls)) == NULL)
435 return MMSYSERR_INVALHANDLE;
437 if (lpmlcA == NULL || lpmlcA->cbStruct != sizeof(*lpmlcA))
438 return MMSYSERR_INVALPARAM;
440 return MMDRV_Message(&lpwm->mld, MXDM_GETLINECONTROLS, (DWORD_PTR)lpmlcA,
444 /**************************************************************************
445 * mixerGetLineControlsW [WINMM.@]
447 UINT WINAPI mixerGetLineControlsW(HMIXEROBJ hmix, LPMIXERLINECONTROLSW lpmlcW,
450 MIXERLINECONTROLSA mlcA;
454 TRACE("(%p, %p, %08lx)\n", hmix, lpmlcW, fdwControls);
456 if (lpmlcW == NULL || lpmlcW->cbStruct != sizeof(*lpmlcW) ||
457 lpmlcW->cbmxctrl != sizeof(MIXERCONTROLW))
458 return MMSYSERR_INVALPARAM;
460 mlcA.cbStruct = sizeof(mlcA);
461 mlcA.dwLineID = lpmlcW->dwLineID;
462 mlcA.u.dwControlID = lpmlcW->u.dwControlID;
463 mlcA.u.dwControlType = lpmlcW->u.dwControlType;
464 mlcA.cControls = lpmlcW->cControls;
465 mlcA.cbmxctrl = sizeof(MIXERCONTROLA);
466 mlcA.pamxctrl = HeapAlloc(GetProcessHeap(), 0,
467 mlcA.cControls * mlcA.cbmxctrl);
469 ret = mixerGetLineControlsA(hmix, &mlcA, fdwControls);
471 if (ret == MMSYSERR_NOERROR) {
472 lpmlcW->dwLineID = mlcA.dwLineID;
473 lpmlcW->u.dwControlID = mlcA.u.dwControlID;
474 lpmlcW->u.dwControlType = mlcA.u.dwControlType;
475 lpmlcW->cControls = mlcA.cControls;
477 for (i = 0; i < mlcA.cControls; i++) {
478 lpmlcW->pamxctrl[i].cbStruct = sizeof(MIXERCONTROLW);
479 lpmlcW->pamxctrl[i].dwControlID = mlcA.pamxctrl[i].dwControlID;
480 lpmlcW->pamxctrl[i].dwControlType = mlcA.pamxctrl[i].dwControlType;
481 lpmlcW->pamxctrl[i].fdwControl = mlcA.pamxctrl[i].fdwControl;
482 lpmlcW->pamxctrl[i].cMultipleItems = mlcA.pamxctrl[i].cMultipleItems;
483 MultiByteToWideChar( CP_ACP, 0, mlcA.pamxctrl[i].szShortName, -1,
484 lpmlcW->pamxctrl[i].szShortName,
485 sizeof(lpmlcW->pamxctrl[i].szShortName)/sizeof(WCHAR) );
486 MultiByteToWideChar( CP_ACP, 0, mlcA.pamxctrl[i].szName, -1,
487 lpmlcW->pamxctrl[i].szName,
488 sizeof(lpmlcW->pamxctrl[i].szName)/sizeof(WCHAR) );
489 /* sizeof(lpmlcW->pamxctrl[i].Bounds) ==
490 * sizeof(mlcA.pamxctrl[i].Bounds) */
491 memcpy(&lpmlcW->pamxctrl[i].Bounds, &mlcA.pamxctrl[i].Bounds,
492 sizeof(mlcA.pamxctrl[i].Bounds));
493 /* sizeof(lpmlcW->pamxctrl[i].Metrics) ==
494 * sizeof(mlcA.pamxctrl[i].Metrics) */
495 memcpy(&lpmlcW->pamxctrl[i].Metrics, &mlcA.pamxctrl[i].Metrics,
496 sizeof(mlcA.pamxctrl[i].Metrics));
500 HeapFree(GetProcessHeap(), 0, mlcA.pamxctrl);
505 /**************************************************************************
506 * mixerGetLineInfoA [WINMM.@]
508 UINT WINAPI mixerGetLineInfoA(HMIXEROBJ hmix, LPMIXERLINEA lpmliW, DWORD fdwInfo)
512 TRACE("(%p, %p, %08lx)\n", hmix, lpmliW, fdwInfo);
514 if ((lpwm = MIXER_GetDev(hmix, fdwInfo)) == NULL)
515 return MMSYSERR_INVALHANDLE;
517 return MMDRV_Message(&lpwm->mld, MXDM_GETLINEINFO, (DWORD_PTR)lpmliW,
521 /**************************************************************************
522 * mixerGetLineInfoW [WINMM.@]
524 UINT WINAPI mixerGetLineInfoW(HMIXEROBJ hmix, LPMIXERLINEW lpmliW,
530 TRACE("(%p, %p, %08lx)\n", hmix, lpmliW, fdwInfo);
532 if (lpmliW == NULL || lpmliW->cbStruct != sizeof(*lpmliW))
533 return MMSYSERR_INVALPARAM;
535 mliA.cbStruct = sizeof(mliA);
536 switch (fdwInfo & MIXER_GETLINEINFOF_QUERYMASK) {
537 case MIXER_GETLINEINFOF_COMPONENTTYPE:
538 mliA.dwComponentType = lpmliW->dwComponentType;
540 case MIXER_GETLINEINFOF_DESTINATION:
541 mliA.dwDestination = lpmliW->dwDestination;
543 case MIXER_GETLINEINFOF_LINEID:
544 mliA.dwLineID = lpmliW->dwLineID;
546 case MIXER_GETLINEINFOF_SOURCE:
547 mliA.dwDestination = lpmliW->dwDestination;
548 mliA.dwSource = lpmliW->dwSource;
550 case MIXER_GETLINEINFOF_TARGETTYPE:
551 mliA.Target.dwType = lpmliW->Target.dwType;
552 mliA.Target.wMid = lpmliW->Target.wMid;
553 mliA.Target.wPid = lpmliW->Target.wPid;
554 mliA.Target.vDriverVersion = lpmliW->Target.vDriverVersion;
555 WideCharToMultiByte( CP_ACP, 0, lpmliW->Target.szPname, -1, mliA.Target.szPname, sizeof(mliA.Target.szPname), NULL, NULL);
558 FIXME("Unsupported fdwControls=0x%08lx\n", fdwInfo);
561 ret = mixerGetLineInfoA(hmix, &mliA, fdwInfo);
563 lpmliW->dwDestination = mliA.dwDestination;
564 lpmliW->dwSource = mliA.dwSource;
565 lpmliW->dwLineID = mliA.dwLineID;
566 lpmliW->fdwLine = mliA.fdwLine;
567 lpmliW->dwUser = mliA.dwUser;
568 lpmliW->dwComponentType = mliA.dwComponentType;
569 lpmliW->cChannels = mliA.cChannels;
570 lpmliW->cConnections = mliA.cConnections;
571 lpmliW->cControls = mliA.cControls;
572 MultiByteToWideChar( CP_ACP, 0, mliA.szShortName, -1, lpmliW->szShortName,
573 sizeof(lpmliW->szShortName)/sizeof(WCHAR) );
574 MultiByteToWideChar( CP_ACP, 0, mliA.szName, -1, lpmliW->szName,
575 sizeof(lpmliW->szName)/sizeof(WCHAR) );
576 lpmliW->Target.dwType = mliA.Target.dwType;
577 lpmliW->Target.dwDeviceID = mliA.Target.dwDeviceID;
578 lpmliW->Target.wMid = mliA.Target.wMid;
579 lpmliW->Target.wPid = mliA.Target.wPid;
580 lpmliW->Target.vDriverVersion = mliA.Target.vDriverVersion;
581 MultiByteToWideChar( CP_ACP, 0, mliA.Target.szPname, -1, lpmliW->Target.szPname,
582 sizeof(lpmliW->Target.szPname)/sizeof(WCHAR) );
587 /**************************************************************************
588 * mixerSetControlDetails [WINMM.@]
590 UINT WINAPI mixerSetControlDetails(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcdA,
595 TRACE("(%p, %p, %08lx)\n", hmix, lpmcdA, fdwDetails);
597 if ((lpwm = MIXER_GetDev(hmix, fdwDetails)) == NULL)
598 return MMSYSERR_INVALHANDLE;
600 return MMDRV_Message(&lpwm->mld, MXDM_SETCONTROLDETAILS, (DWORD_PTR)lpmcdA,
604 /**************************************************************************
605 * mixerMessage [WINMM.@]
607 UINT WINAPI mixerMessage(HMIXER hmix, UINT uMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
611 TRACE("(%04lx, %d, %08lx, %08lx): semi-stub?\n",
612 (DWORD)hmix, uMsg, dwParam1, dwParam2);
614 if ((wmld = MMDRV_Get(hmix, MMDRV_MIXER, FALSE)) == NULL)
615 return MMSYSERR_INVALHANDLE;
617 return MMDRV_Message(wmld, uMsg, dwParam1, dwParam2, TRUE);
620 /**************************************************************************
621 * auxGetNumDevs [WINMM.@]
623 UINT WINAPI auxGetNumDevs(void)
625 return MMDRV_GetNum(MMDRV_AUX);
628 /**************************************************************************
629 * auxGetDevCapsW [WINMM.@]
631 UINT WINAPI auxGetDevCapsW(UINT_PTR uDeviceID, LPAUXCAPSW lpCaps, UINT uSize)
634 UINT ret = auxGetDevCapsA(uDeviceID, &acA, sizeof(acA));
636 if (ret == MMSYSERR_NOERROR) {
640 acW.vDriverVersion = acA.vDriverVersion;
641 MultiByteToWideChar( CP_ACP, 0, acA.szPname, -1, acW.szPname,
642 sizeof(acW.szPname)/sizeof(WCHAR) );
643 acW.wTechnology = acA.wTechnology;
644 acW.dwSupport = acA.dwSupport;
645 memcpy(lpCaps, &acW, min(uSize, sizeof(acW)));
650 /**************************************************************************
651 * auxGetDevCapsA [WINMM.@]
653 UINT WINAPI auxGetDevCapsA(UINT_PTR uDeviceID, LPAUXCAPSA lpCaps, UINT uSize)
657 TRACE("(%04X, %p, %d) !\n", uDeviceID, lpCaps, uSize);
659 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
661 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
662 return MMSYSERR_INVALHANDLE;
663 return MMDRV_Message(wmld, AUXDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
666 /**************************************************************************
667 * auxGetVolume [WINMM.@]
669 UINT WINAPI auxGetVolume(UINT uDeviceID, DWORD* lpdwVolume)
673 TRACE("(%04X, %p) !\n", uDeviceID, lpdwVolume);
675 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
676 return MMSYSERR_INVALHANDLE;
677 return MMDRV_Message(wmld, AUXDM_GETVOLUME, (DWORD_PTR)lpdwVolume, 0L, TRUE);
680 /**************************************************************************
681 * auxSetVolume [WINMM.@]
683 UINT WINAPI auxSetVolume(UINT uDeviceID, DWORD dwVolume)
687 TRACE("(%04X, %lu) !\n", uDeviceID, dwVolume);
689 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
690 return MMSYSERR_INVALHANDLE;
691 return MMDRV_Message(wmld, AUXDM_SETVOLUME, dwVolume, 0L, TRUE);
694 /**************************************************************************
695 * auxOutMessage [WINMM.@]
697 UINT WINAPI auxOutMessage(UINT uDeviceID, UINT uMessage, DWORD_PTR dw1, DWORD_PTR dw2)
701 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
702 return MMSYSERR_INVALHANDLE;
704 return MMDRV_Message(wmld, uMessage, dw1, dw2, TRUE);
707 /**************************************************************************
708 * mciGetErrorStringW [WINMM.@]
710 BOOL WINAPI mciGetErrorStringW(MCIERROR wError, LPWSTR lpstrBuffer, UINT uLength)
712 char bufstr[MAXERRORLENGTH];
713 BOOL ret = mciGetErrorStringA(wError, bufstr, MAXERRORLENGTH);
715 MultiByteToWideChar( CP_ACP, 0, bufstr, -1, lpstrBuffer, uLength );
719 /**************************************************************************
720 * mciGetErrorStringA [WINMM.@]
722 BOOL WINAPI mciGetErrorStringA(MCIERROR dwError, LPSTR lpstrBuffer, UINT uLength)
726 if (lpstrBuffer != NULL && uLength > 0 &&
727 dwError >= MCIERR_BASE && dwError <= MCIERR_CUSTOM_DRIVER_BASE) {
729 if (LoadStringA(WINMM_IData->hWinMM32Instance,
730 dwError, lpstrBuffer, uLength) > 0) {
737 /**************************************************************************
738 * mciDriverNotify [WINMM.@]
740 BOOL WINAPI mciDriverNotify(HWND hWndCallBack, MCIDEVICEID wDevID, UINT wStatus)
742 TRACE("(%p, %04x, %04X)\n", hWndCallBack, wDevID, wStatus);
744 return PostMessageW(hWndCallBack, MM_MCINOTIFY, wStatus, wDevID);
747 /**************************************************************************
748 * mciGetDriverData [WINMM.@]
750 DWORD WINAPI mciGetDriverData(MCIDEVICEID uDeviceID)
752 LPWINE_MCIDRIVER wmd;
754 TRACE("(%04x)\n", uDeviceID);
756 wmd = MCI_GetDriver(uDeviceID);
759 WARN("Bad uDeviceID\n");
763 return wmd->dwPrivate;
766 /**************************************************************************
767 * mciSetDriverData [WINMM.@]
769 BOOL WINAPI mciSetDriverData(MCIDEVICEID uDeviceID, DWORD data)
771 LPWINE_MCIDRIVER wmd;
773 TRACE("(%04x, %08lx)\n", uDeviceID, data);
775 wmd = MCI_GetDriver(uDeviceID);
778 WARN("Bad uDeviceID\n");
782 wmd->dwPrivate = data;
786 /**************************************************************************
787 * mciSendCommandA [WINMM.@]
789 DWORD WINAPI mciSendCommandA(MCIDEVICEID wDevID, UINT wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
793 TRACE("(%08x, %s, %08lx, %08lx)\n",
794 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
796 dwRet = MCI_SendCommand(wDevID, wMsg, dwParam1, dwParam2, TRUE);
797 dwRet = MCI_CleanUp(dwRet, wMsg, dwParam2);
798 TRACE("=> %08lx\n", dwRet);
802 inline static LPSTR strdupWtoA( LPCWSTR str )
807 if (!str) return NULL;
808 len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
809 ret = HeapAlloc( GetProcessHeap(), 0, len );
810 if(ret) WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
814 static int MCI_MapMsgWtoA(UINT msg, DWORD_PTR dwParam1, DWORD_PTR *dwParam2)
847 MCI_OPEN_PARMSW *mci_openW = (MCI_OPEN_PARMSW *)*dwParam2;
848 MCI_OPEN_PARMSA *mci_openA;
851 ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_openA) + sizeof(DWORD_PTR));
854 *ptr++ = *dwParam2; /* save the previous pointer */
855 *dwParam2 = (DWORD_PTR)ptr;
856 mci_openA = (MCI_OPEN_PARMSA *)ptr;
858 if (dwParam1 & MCI_NOTIFY)
859 mci_openA->dwCallback = mci_openW->dwCallback;
861 if (dwParam1 & MCI_OPEN_TYPE)
863 if (dwParam1 & MCI_OPEN_TYPE_ID)
864 mci_openA->lpstrDeviceType = (LPSTR)mci_openW->lpstrDeviceType;
866 mci_openA->lpstrDeviceType = strdupWtoA(mci_openW->lpstrDeviceType);
868 if (dwParam1 & MCI_OPEN_ELEMENT)
870 if (dwParam1 & MCI_OPEN_ELEMENT_ID)
871 mci_openA->lpstrElementName = (LPSTR)mci_openW->lpstrElementName;
873 mci_openA->lpstrElementName = strdupWtoA(mci_openW->lpstrElementName);
875 if (dwParam1 & MCI_OPEN_ALIAS)
876 mci_openA->lpstrAlias = strdupWtoA(mci_openW->lpstrAlias);
881 if (dwParam1 & MCI_ANIM_WINDOW_TEXT)
883 MCI_ANIM_WINDOW_PARMSW *mci_windowW = (MCI_ANIM_WINDOW_PARMSW *)*dwParam2;
884 MCI_ANIM_WINDOW_PARMSA *mci_windowA;
886 mci_windowA = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_windowA));
887 if (!mci_windowA) return -1;
889 *dwParam2 = (DWORD_PTR)mci_windowA;
891 mci_windowA->lpstrText = strdupWtoA(mci_windowW->lpstrText);
893 if (dwParam1 & MCI_NOTIFY)
894 mci_windowA->dwCallback = mci_windowW->dwCallback;
895 if (dwParam1 & MCI_ANIM_WINDOW_HWND)
896 mci_windowA->hWnd = mci_windowW->hWnd;
897 if (dwParam1 & MCI_ANIM_WINDOW_STATE)
898 mci_windowA->nCmdShow = mci_windowW->nCmdShow;
906 MCI_SYSINFO_PARMSW *mci_sysinfoW = (MCI_SYSINFO_PARMSW *)*dwParam2;
907 MCI_SYSINFO_PARMSA *mci_sysinfoA;
910 ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(*mci_sysinfoA) + sizeof(DWORD_PTR));
913 *ptr++ = *dwParam2; /* save the previous pointer */
914 *dwParam2 = (DWORD_PTR)ptr;
915 mci_sysinfoA = (MCI_SYSINFO_PARMSA *)ptr;
917 if (dwParam1 & MCI_NOTIFY)
918 mci_sysinfoA->dwCallback = mci_sysinfoW->dwCallback;
920 mci_sysinfoA->dwRetSize = mci_sysinfoW->dwRetSize; /* FIXME */
921 mci_sysinfoA->lpstrReturn = HeapAlloc(GetProcessHeap(), 0, mci_sysinfoA->dwRetSize);
931 FIXME("Message 0x%04x needs translation\n", msg);
937 static DWORD MCI_UnmapMsgWtoA(UINT msg, DWORD_PTR dwParam1, DWORD_PTR dwParam2,
944 DWORD_PTR *ptr = (DWORD_PTR *)dwParam2 - 1;
945 MCI_OPEN_PARMSW *mci_openW = (MCI_OPEN_PARMSW *)*ptr;
946 MCI_OPEN_PARMSA *mci_openA = (MCI_OPEN_PARMSA *)(ptr + 1);
948 mci_openW->wDeviceID = mci_openA->wDeviceID;
950 if (dwParam1 & MCI_OPEN_TYPE)
952 if (!(dwParam1 & MCI_OPEN_TYPE_ID))
953 HeapFree(GetProcessHeap(), 0, mci_openA->lpstrDeviceType);
955 if (dwParam1 & MCI_OPEN_ELEMENT)
957 if (!(dwParam1 & MCI_OPEN_ELEMENT_ID))
958 HeapFree(GetProcessHeap(), 0, mci_openA->lpstrElementName);
960 if (dwParam1 & MCI_OPEN_ALIAS)
961 HeapFree(GetProcessHeap(), 0, mci_openA->lpstrAlias);
962 HeapFree(GetProcessHeap(), 0, ptr);
967 if (dwParam1 & MCI_ANIM_WINDOW_TEXT)
969 MCI_ANIM_WINDOW_PARMSA *mci_windowA = (MCI_ANIM_WINDOW_PARMSA *)dwParam2;
971 HeapFree(GetProcessHeap(), 0, (void *)mci_windowA->lpstrText);
972 HeapFree(GetProcessHeap(), 0, mci_windowA);
978 DWORD_PTR *ptr = (DWORD_PTR *)dwParam2 - 1;
979 MCI_SYSINFO_PARMSW *mci_sysinfoW = (MCI_SYSINFO_PARMSW *)*ptr;
980 MCI_SYSINFO_PARMSA *mci_sysinfoA = (MCI_SYSINFO_PARMSA *)(ptr + 1);
984 mci_sysinfoW->dwNumber = mci_sysinfoA->dwNumber;
985 mci_sysinfoW->wDeviceType = mci_sysinfoA->wDeviceType;
986 MultiByteToWideChar(CP_ACP, 0,
987 mci_sysinfoA->lpstrReturn, mci_sysinfoA->dwRetSize,
988 mci_sysinfoW->lpstrReturn, mci_sysinfoW->dwRetSize);
991 HeapFree(GetProcessHeap(), 0, mci_sysinfoA->lpstrReturn);
992 HeapFree(GetProcessHeap(), 0, ptr);
997 FIXME("Message 0x%04x needs unmapping\n", msg);
1005 /**************************************************************************
1006 * mciSendCommandW [WINMM.@]
1008 * FIXME: we should do the things other way around, but since our
1009 * MM subsystem is not unicode aware...
1011 DWORD WINAPI mciSendCommandW(MCIDEVICEID wDevID, UINT wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1016 TRACE("(%08x, %s, %08lx, %08lx)\n",
1017 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
1019 mapped = MCI_MapMsgWtoA(wMsg, dwParam1, &dwParam2);
1022 FIXME("message %04x mapping failed\n", wMsg);
1023 return MMSYSERR_NOMEM;
1025 ret = mciSendCommandA(wDevID, wMsg, dwParam1, dwParam2);
1027 MCI_UnmapMsgWtoA(wMsg, dwParam1, dwParam2, ret);
1031 /**************************************************************************
1032 * mciGetDeviceIDA [WINMM.@]
1034 UINT WINAPI mciGetDeviceIDA(LPCSTR lpstrName)
1036 return MCI_GetDriverFromString(lpstrName);
1039 /**************************************************************************
1040 * mciGetDeviceIDW [WINMM.@]
1042 UINT WINAPI mciGetDeviceIDW(LPCWSTR lpwstrName)
1044 LPSTR lpstrName = NULL;
1049 len = WideCharToMultiByte( CP_ACP, 0, lpwstrName, -1, NULL, 0, NULL, NULL );
1050 lpstrName = HeapAlloc( GetProcessHeap(), 0, len );
1051 if (lpstrName) WideCharToMultiByte( CP_ACP, 0, lpwstrName, -1, lpstrName, len, NULL, NULL );
1053 ret = MCI_GetDriverFromString(lpstrName);
1054 HeapFree(GetProcessHeap(), 0, lpstrName);
1058 /**************************************************************************
1059 * MCI_DefYieldProc [internal]
1061 UINT WINAPI MCI_DefYieldProc(MCIDEVICEID wDevID, DWORD data)
1065 TRACE("(0x%04x, 0x%08lx)\n", wDevID, data);
1067 if ((HIWORD(data) != 0 && HWND_16(GetActiveWindow()) != HIWORD(data)) ||
1068 (GetAsyncKeyState(LOWORD(data)) & 1) == 0) {
1074 msg.hwnd = HWND_32(HIWORD(data));
1075 while (!PeekMessageA(&msg, msg.hwnd, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE));
1081 /**************************************************************************
1082 * mciSetYieldProc [WINMM.@]
1084 BOOL WINAPI mciSetYieldProc(MCIDEVICEID uDeviceID, YIELDPROC fpYieldProc, DWORD dwYieldData)
1086 LPWINE_MCIDRIVER wmd;
1088 TRACE("(%u, %p, %08lx)\n", uDeviceID, fpYieldProc, dwYieldData);
1090 if (!(wmd = MCI_GetDriver(uDeviceID))) {
1091 WARN("Bad uDeviceID\n");
1095 wmd->lpfnYieldProc = fpYieldProc;
1096 wmd->dwYieldData = dwYieldData;
1102 /**************************************************************************
1103 * mciGetDeviceIDFromElementIDW [WINMM.@]
1105 UINT WINAPI mciGetDeviceIDFromElementIDW(DWORD dwElementID, LPCWSTR lpstrType)
1107 /* FIXME: that's rather strange, there is no
1108 * mciGetDeviceIDFromElementID32A in winmm.spec
1110 FIXME("(%lu, %p) stub\n", dwElementID, lpstrType);
1114 /**************************************************************************
1115 * mciGetYieldProc [WINMM.@]
1117 YIELDPROC WINAPI mciGetYieldProc(MCIDEVICEID uDeviceID, DWORD* lpdwYieldData)
1119 LPWINE_MCIDRIVER wmd;
1121 TRACE("(%u, %p)\n", uDeviceID, lpdwYieldData);
1123 if (!(wmd = MCI_GetDriver(uDeviceID))) {
1124 WARN("Bad uDeviceID\n");
1127 if (!wmd->lpfnYieldProc) {
1128 WARN("No proc set\n");
1132 WARN("Proc is 32 bit\n");
1135 return wmd->lpfnYieldProc;
1138 /**************************************************************************
1139 * mciGetCreatorTask [WINMM.@]
1141 HTASK WINAPI mciGetCreatorTask(MCIDEVICEID uDeviceID)
1143 LPWINE_MCIDRIVER wmd;
1146 if ((wmd = MCI_GetDriver(uDeviceID))) ret = (HTASK)wmd->CreatorThread;
1148 TRACE("(%u) => %p\n", uDeviceID, ret);
1152 /**************************************************************************
1153 * mciDriverYield [WINMM.@]
1155 UINT WINAPI mciDriverYield(MCIDEVICEID uDeviceID)
1157 LPWINE_MCIDRIVER wmd;
1160 TRACE("(%04x)\n", uDeviceID);
1162 if (!(wmd = MCI_GetDriver(uDeviceID)) || !wmd->lpfnYieldProc || !wmd->bIs32) {
1165 ret = wmd->lpfnYieldProc(uDeviceID, wmd->dwYieldData);
1171 /**************************************************************************
1172 * midiOutGetNumDevs [WINMM.@]
1174 UINT WINAPI midiOutGetNumDevs(void)
1176 return MMDRV_GetNum(MMDRV_MIDIOUT);
1179 /**************************************************************************
1180 * midiOutGetDevCapsW [WINMM.@]
1182 UINT WINAPI midiOutGetDevCapsW(UINT_PTR uDeviceID, LPMIDIOUTCAPSW lpCaps,
1186 UINT ret = midiOutGetDevCapsA(uDeviceID, &mocA, sizeof(mocA));
1188 if (ret == MMSYSERR_NOERROR) {
1190 mocW.wMid = mocA.wMid;
1191 mocW.wPid = mocA.wPid;
1192 mocW.vDriverVersion = mocA.vDriverVersion;
1193 MultiByteToWideChar( CP_ACP, 0, mocA.szPname, -1, mocW.szPname,
1194 sizeof(mocW.szPname)/sizeof(WCHAR) );
1195 mocW.wTechnology = mocA.wTechnology;
1196 mocW.wVoices = mocA.wVoices;
1197 mocW.wNotes = mocA.wNotes;
1198 mocW.wChannelMask = mocA.wChannelMask;
1199 mocW.dwSupport = mocA.dwSupport;
1200 memcpy(lpCaps, &mocW, min(uSize, sizeof(mocW)));
1205 /**************************************************************************
1206 * midiOutGetDevCapsA [WINMM.@]
1208 UINT WINAPI midiOutGetDevCapsA(UINT_PTR uDeviceID, LPMIDIOUTCAPSA lpCaps,
1213 TRACE("(%u, %p, %u);\n", uDeviceID, lpCaps, uSize);
1215 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
1217 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_MIDIOUT, TRUE)) == NULL)
1218 return MMSYSERR_INVALHANDLE;
1220 return MMDRV_Message(wmld, MODM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
1223 /**************************************************************************
1224 * MIDI_GetErrorText [internal]
1226 static UINT16 MIDI_GetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize)
1228 UINT16 ret = MMSYSERR_BADERRNUM;
1230 if (lpText == NULL) {
1231 ret = MMSYSERR_INVALPARAM;
1232 } else if (uSize == 0) {
1233 ret = MMSYSERR_NOERROR;
1235 /* test has been removed 'coz MMSYSERR_BASE is 0, and gcc did emit
1236 * a warning for the test was always true */
1237 (/*uError >= MMSYSERR_BASE && */ uError <= MMSYSERR_LASTERROR) ||
1238 (uError >= MIDIERR_BASE && uError <= MIDIERR_LASTERROR)) {
1240 if (LoadStringA(WINMM_IData->hWinMM32Instance,
1241 uError, lpText, uSize) > 0) {
1242 ret = MMSYSERR_NOERROR;
1248 /**************************************************************************
1249 * midiOutGetErrorTextA [WINMM.@]
1251 UINT WINAPI midiOutGetErrorTextA(UINT uError, LPSTR lpText, UINT uSize)
1253 return MIDI_GetErrorText(uError, lpText, uSize);
1256 /**************************************************************************
1257 * midiOutGetErrorTextW [WINMM.@]
1259 UINT WINAPI midiOutGetErrorTextW(UINT uError, LPWSTR lpText, UINT uSize)
1261 LPSTR xstr = HeapAlloc(GetProcessHeap(), 0, uSize);
1264 ret = MIDI_GetErrorText(uError, xstr, uSize);
1265 MultiByteToWideChar( CP_ACP, 0, xstr, -1, lpText, uSize );
1266 HeapFree(GetProcessHeap(), 0, xstr);
1270 /**************************************************************************
1271 * MIDI_OutAlloc [internal]
1273 static LPWINE_MIDI MIDI_OutAlloc(HMIDIOUT* lphMidiOut, LPDWORD lpdwCallback,
1274 LPDWORD lpdwInstance, LPDWORD lpdwFlags,
1275 DWORD cIDs, MIDIOPENSTRMID* lpIDs, BOOL bFrom32)
1281 size = sizeof(WINE_MIDI) + (cIDs ? (cIDs-1) : 0) * sizeof(MIDIOPENSTRMID);
1283 lpwm = (LPWINE_MIDI)MMDRV_Alloc(size, MMDRV_MIDIOUT, &hMidiOut, lpdwFlags,
1284 lpdwCallback, lpdwInstance, bFrom32);
1286 if (lphMidiOut != NULL)
1287 *lphMidiOut = hMidiOut;
1290 lpwm->mod.hMidi = (HMIDI) hMidiOut;
1291 lpwm->mod.dwCallback = *lpdwCallback;
1292 lpwm->mod.dwInstance = *lpdwInstance;
1293 lpwm->mod.dnDevNode = 0;
1294 lpwm->mod.cIds = cIDs;
1296 memcpy(&(lpwm->mod.rgIds), lpIDs, cIDs * sizeof(MIDIOPENSTRMID));
1301 UINT MIDI_OutOpen(LPHMIDIOUT lphMidiOut, UINT uDeviceID, DWORD_PTR dwCallback,
1302 DWORD_PTR dwInstance, DWORD dwFlags, BOOL bFrom32)
1308 TRACE("(%p, %d, %08lX, %08lX, %08lX);\n",
1309 lphMidiOut, uDeviceID, dwCallback, dwInstance, dwFlags);
1311 if (lphMidiOut != NULL) *lphMidiOut = 0;
1313 lpwm = MIDI_OutAlloc(&hMidiOut, &dwCallback, &dwInstance, &dwFlags,
1317 return MMSYSERR_NOMEM;
1319 lpwm->mld.uDeviceID = uDeviceID;
1321 dwRet = MMDRV_Open((LPWINE_MLD)lpwm, MODM_OPEN, (DWORD)&lpwm->mod, dwFlags);
1323 if (dwRet != MMSYSERR_NOERROR) {
1324 MMDRV_Free(hMidiOut, (LPWINE_MLD)lpwm);
1328 if (lphMidiOut) *lphMidiOut = hMidiOut;
1329 TRACE("=> %d hMidi=%p\n", dwRet, hMidiOut);
1334 /**************************************************************************
1335 * midiOutOpen [WINMM.@]
1337 UINT WINAPI midiOutOpen(LPHMIDIOUT lphMidiOut, UINT uDeviceID,
1338 DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD dwFlags)
1340 return MIDI_OutOpen(lphMidiOut, uDeviceID, dwCallback, dwInstance, dwFlags, TRUE);
1343 /**************************************************************************
1344 * midiOutClose [WINMM.@]
1346 UINT WINAPI midiOutClose(HMIDIOUT hMidiOut)
1351 TRACE("(%p)\n", hMidiOut);
1353 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1354 return MMSYSERR_INVALHANDLE;
1356 dwRet = MMDRV_Close(wmld, MODM_CLOSE);
1357 MMDRV_Free(hMidiOut, wmld);
1362 /**************************************************************************
1363 * midiOutPrepareHeader [WINMM.@]
1365 UINT WINAPI midiOutPrepareHeader(HMIDIOUT hMidiOut,
1366 MIDIHDR* lpMidiOutHdr, UINT uSize)
1370 TRACE("(%p, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
1372 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1373 return MMSYSERR_INVALHANDLE;
1375 return MMDRV_Message(wmld, MODM_PREPARE, (DWORD_PTR)lpMidiOutHdr, uSize, TRUE);
1378 /**************************************************************************
1379 * midiOutUnprepareHeader [WINMM.@]
1381 UINT WINAPI midiOutUnprepareHeader(HMIDIOUT hMidiOut,
1382 MIDIHDR* lpMidiOutHdr, UINT uSize)
1386 TRACE("(%p, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
1388 if (!(lpMidiOutHdr->dwFlags & MHDR_PREPARED)) {
1389 return MMSYSERR_NOERROR;
1392 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1393 return MMSYSERR_INVALHANDLE;
1395 return MMDRV_Message(wmld, MODM_UNPREPARE, (DWORD_PTR)lpMidiOutHdr, uSize, TRUE);
1398 /**************************************************************************
1399 * midiOutShortMsg [WINMM.@]
1401 UINT WINAPI midiOutShortMsg(HMIDIOUT hMidiOut, DWORD dwMsg)
1405 TRACE("(%p, %08lX)\n", hMidiOut, dwMsg);
1407 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1408 return MMSYSERR_INVALHANDLE;
1410 return MMDRV_Message(wmld, MODM_DATA, dwMsg, 0L, TRUE);
1413 /**************************************************************************
1414 * midiOutLongMsg [WINMM.@]
1416 UINT WINAPI midiOutLongMsg(HMIDIOUT hMidiOut,
1417 MIDIHDR* lpMidiOutHdr, UINT uSize)
1421 TRACE("(%p, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
1423 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1424 return MMSYSERR_INVALHANDLE;
1426 return MMDRV_Message(wmld, MODM_LONGDATA, (DWORD_PTR)lpMidiOutHdr, uSize, TRUE);
1429 /**************************************************************************
1430 * midiOutReset [WINMM.@]
1432 UINT WINAPI midiOutReset(HMIDIOUT hMidiOut)
1436 TRACE("(%p)\n", hMidiOut);
1438 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1439 return MMSYSERR_INVALHANDLE;
1441 return MMDRV_Message(wmld, MODM_RESET, 0L, 0L, TRUE);
1444 /**************************************************************************
1445 * midiOutGetVolume [WINMM.@]
1447 UINT WINAPI midiOutGetVolume(HMIDIOUT hMidiOut, DWORD* lpdwVolume)
1451 TRACE("(%p, %p);\n", hMidiOut, lpdwVolume);
1453 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, TRUE)) == NULL)
1454 return MMSYSERR_INVALHANDLE;
1456 return MMDRV_Message(wmld, MODM_GETVOLUME, (DWORD_PTR)lpdwVolume, 0L, TRUE);
1459 /**************************************************************************
1460 * midiOutSetVolume [WINMM.@]
1462 UINT WINAPI midiOutSetVolume(HMIDIOUT hMidiOut, DWORD dwVolume)
1466 TRACE("(%p, %ld);\n", hMidiOut, dwVolume);
1468 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, TRUE)) == NULL)
1469 return MMSYSERR_INVALHANDLE;
1471 return MMDRV_Message(wmld, MODM_SETVOLUME, dwVolume, 0L, TRUE);
1474 /**************************************************************************
1475 * midiOutCachePatches [WINMM.@]
1477 UINT WINAPI midiOutCachePatches(HMIDIOUT hMidiOut, UINT uBank,
1478 WORD* lpwPatchArray, UINT uFlags)
1480 /* not really necessary to support this */
1481 FIXME("not supported yet\n");
1482 return MMSYSERR_NOTSUPPORTED;
1485 /**************************************************************************
1486 * midiOutCacheDrumPatches [WINMM.@]
1488 UINT WINAPI midiOutCacheDrumPatches(HMIDIOUT hMidiOut, UINT uPatch,
1489 WORD* lpwKeyArray, UINT uFlags)
1491 FIXME("not supported yet\n");
1492 return MMSYSERR_NOTSUPPORTED;
1495 /**************************************************************************
1496 * midiOutGetID [WINMM.@]
1498 UINT WINAPI midiOutGetID(HMIDIOUT hMidiOut, UINT* lpuDeviceID)
1502 TRACE("(%p, %p)\n", hMidiOut, lpuDeviceID);
1504 if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
1505 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1506 return MMSYSERR_INVALHANDLE;
1508 *lpuDeviceID = wmld->uDeviceID;
1509 return MMSYSERR_NOERROR;
1512 /**************************************************************************
1513 * midiOutMessage [WINMM.@]
1515 UINT WINAPI midiOutMessage(HMIDIOUT hMidiOut, UINT uMessage,
1516 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1520 TRACE("(%p, %04X, %08lX, %08lX)\n", hMidiOut, uMessage, dwParam1, dwParam2);
1522 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL) {
1524 if (uMessage == 0x0001) {
1525 *(LPDWORD)dwParam1 = 1;
1528 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, TRUE)) != NULL) {
1529 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
1531 return MMSYSERR_INVALHANDLE;
1537 FIXME("can't handle OPEN or CLOSE message!\n");
1538 return MMSYSERR_NOTSUPPORTED;
1540 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
1543 /**************************************************************************
1544 * midiInGetNumDevs [WINMM.@]
1546 UINT WINAPI midiInGetNumDevs(void)
1548 return MMDRV_GetNum(MMDRV_MIDIIN);
1551 /**************************************************************************
1552 * midiInGetDevCapsW [WINMM.@]
1554 UINT WINAPI midiInGetDevCapsW(UINT_PTR uDeviceID, LPMIDIINCAPSW lpCaps, UINT uSize)
1557 UINT ret = midiInGetDevCapsA(uDeviceID, &micA, uSize);
1559 if (ret == MMSYSERR_NOERROR) {
1561 micW.wMid = micA.wMid;
1562 micW.wPid = micA.wPid;
1563 micW.vDriverVersion = micA.vDriverVersion;
1564 MultiByteToWideChar( CP_ACP, 0, micA.szPname, -1, micW.szPname,
1565 sizeof(micW.szPname)/sizeof(WCHAR) );
1566 micW.dwSupport = micA.dwSupport;
1567 memcpy(lpCaps, &micW, min(uSize, sizeof(micW)));
1572 /**************************************************************************
1573 * midiInGetDevCapsA [WINMM.@]
1575 UINT WINAPI midiInGetDevCapsA(UINT_PTR uDeviceID, LPMIDIINCAPSA lpCaps, UINT uSize)
1579 TRACE("(%d, %p, %d);\n", uDeviceID, lpCaps, uSize);
1581 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
1583 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_MIDIIN, TRUE)) == NULL)
1584 return MMSYSERR_INVALHANDLE;
1586 return MMDRV_Message(wmld, MIDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
1589 /**************************************************************************
1590 * midiInGetErrorTextW [WINMM.@]
1592 UINT WINAPI midiInGetErrorTextW(UINT uError, LPWSTR lpText, UINT uSize)
1594 LPSTR xstr = HeapAlloc(GetProcessHeap(), 0, uSize);
1595 UINT ret = MIDI_GetErrorText(uError, xstr, uSize);
1597 MultiByteToWideChar( CP_ACP, 0, xstr, -1, lpText, uSize );
1598 HeapFree(GetProcessHeap(), 0, xstr);
1602 /**************************************************************************
1603 * midiInGetErrorTextA [WINMM.@]
1605 UINT WINAPI midiInGetErrorTextA(UINT uError, LPSTR lpText, UINT uSize)
1607 return MIDI_GetErrorText(uError, lpText, uSize);
1610 UINT MIDI_InOpen(HMIDIIN* lphMidiIn, UINT uDeviceID, DWORD dwCallback,
1611 DWORD dwInstance, DWORD dwFlags, BOOL bFrom32)
1617 TRACE("(%p, %d, %08lX, %08lX, %08lX);\n",
1618 lphMidiIn, uDeviceID, dwCallback, dwInstance, dwFlags);
1620 if (lphMidiIn != NULL) *lphMidiIn = 0;
1622 lpwm = (LPWINE_MIDI)MMDRV_Alloc(sizeof(WINE_MIDI), MMDRV_MIDIIN, &hMidiIn,
1623 &dwFlags, &dwCallback, &dwInstance, bFrom32);
1626 return MMSYSERR_NOMEM;
1628 lpwm->mod.hMidi = (HMIDI) hMidiIn;
1629 lpwm->mod.dwCallback = dwCallback;
1630 lpwm->mod.dwInstance = dwInstance;
1632 lpwm->mld.uDeviceID = uDeviceID;
1633 dwRet = MMDRV_Open(&lpwm->mld, MIDM_OPEN, (DWORD)&lpwm->mod, dwFlags);
1635 if (dwRet != MMSYSERR_NOERROR) {
1636 MMDRV_Free(hMidiIn, &lpwm->mld);
1639 if (lphMidiIn != NULL) *lphMidiIn = hMidiIn;
1640 TRACE("=> %ld hMidi=%p\n", dwRet, hMidiIn);
1645 /**************************************************************************
1646 * midiInOpen [WINMM.@]
1648 UINT WINAPI midiInOpen(HMIDIIN* lphMidiIn, UINT uDeviceID,
1649 DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
1651 return MIDI_InOpen(lphMidiIn, uDeviceID, dwCallback, dwInstance, dwFlags, TRUE);
1654 /**************************************************************************
1655 * midiInClose [WINMM.@]
1657 UINT WINAPI midiInClose(HMIDIIN hMidiIn)
1662 TRACE("(%p)\n", hMidiIn);
1664 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1665 return MMSYSERR_INVALHANDLE;
1667 dwRet = MMDRV_Close(wmld, MIDM_CLOSE);
1668 MMDRV_Free(hMidiIn, wmld);
1672 /**************************************************************************
1673 * midiInPrepareHeader [WINMM.@]
1675 UINT WINAPI midiInPrepareHeader(HMIDIIN hMidiIn,
1676 MIDIHDR* lpMidiInHdr, UINT uSize)
1680 TRACE("(%p, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
1682 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1683 return MMSYSERR_INVALHANDLE;
1685 return MMDRV_Message(wmld, MIDM_PREPARE, (DWORD_PTR)lpMidiInHdr, uSize, TRUE);
1688 /**************************************************************************
1689 * midiInUnprepareHeader [WINMM.@]
1691 UINT WINAPI midiInUnprepareHeader(HMIDIIN hMidiIn,
1692 MIDIHDR* lpMidiInHdr, UINT uSize)
1696 TRACE("(%p, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
1698 if (!(lpMidiInHdr->dwFlags & MHDR_PREPARED)) {
1699 return MMSYSERR_NOERROR;
1702 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1703 return MMSYSERR_INVALHANDLE;
1705 return MMDRV_Message(wmld, MIDM_UNPREPARE, (DWORD_PTR)lpMidiInHdr, uSize, TRUE);
1708 /**************************************************************************
1709 * midiInAddBuffer [WINMM.@]
1711 UINT WINAPI midiInAddBuffer(HMIDIIN hMidiIn,
1712 MIDIHDR* lpMidiInHdr, UINT uSize)
1716 TRACE("(%p, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
1718 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1719 return MMSYSERR_INVALHANDLE;
1721 return MMDRV_Message(wmld, MIDM_ADDBUFFER, (DWORD_PTR)lpMidiInHdr, uSize, TRUE);
1724 /**************************************************************************
1725 * midiInStart [WINMM.@]
1727 UINT WINAPI midiInStart(HMIDIIN hMidiIn)
1731 TRACE("(%p)\n", hMidiIn);
1733 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1734 return MMSYSERR_INVALHANDLE;
1736 return MMDRV_Message(wmld, MIDM_START, 0L, 0L, TRUE);
1739 /**************************************************************************
1740 * midiInStop [WINMM.@]
1742 UINT WINAPI midiInStop(HMIDIIN hMidiIn)
1746 TRACE("(%p)\n", hMidiIn);
1748 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1749 return MMSYSERR_INVALHANDLE;
1751 return MMDRV_Message(wmld, MIDM_STOP, 0L, 0L, TRUE);
1754 /**************************************************************************
1755 * midiInReset [WINMM.@]
1757 UINT WINAPI midiInReset(HMIDIIN hMidiIn)
1761 TRACE("(%p)\n", hMidiIn);
1763 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1764 return MMSYSERR_INVALHANDLE;
1766 return MMDRV_Message(wmld, MIDM_RESET, 0L, 0L, TRUE);
1769 /**************************************************************************
1770 * midiInGetID [WINMM.@]
1772 UINT WINAPI midiInGetID(HMIDIIN hMidiIn, UINT* lpuDeviceID)
1776 TRACE("(%p, %p)\n", hMidiIn, lpuDeviceID);
1778 if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
1780 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, TRUE)) == NULL)
1781 return MMSYSERR_INVALHANDLE;
1783 *lpuDeviceID = wmld->uDeviceID;
1785 return MMSYSERR_NOERROR;
1788 /**************************************************************************
1789 * midiInMessage [WINMM.@]
1791 UINT WINAPI midiInMessage(HMIDIIN hMidiIn, UINT uMessage,
1792 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1796 TRACE("(%p, %04X, %08lX, %08lX)\n", hMidiIn, uMessage, dwParam1, dwParam2);
1798 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1799 return MMSYSERR_INVALHANDLE;
1804 FIXME("can't handle OPEN or CLOSE message!\n");
1805 return MMSYSERR_NOTSUPPORTED;
1807 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
1810 typedef struct WINE_MIDIStream {
1821 LPMIDIHDR lpMidiHdr;
1824 #define WINE_MSM_HEADER (WM_USER+0)
1825 #define WINE_MSM_STOP (WM_USER+1)
1827 /**************************************************************************
1828 * MMSYSTEM_GetMidiStream [internal]
1830 static BOOL MMSYSTEM_GetMidiStream(HMIDISTRM hMidiStrm, WINE_MIDIStream** lpMidiStrm, WINE_MIDI** lplpwm)
1832 WINE_MIDI* lpwm = (LPWINE_MIDI)MMDRV_Get(hMidiStrm, MMDRV_MIDIOUT, FALSE);
1841 *lpMidiStrm = (WINE_MIDIStream*)lpwm->mod.rgIds.dwStreamID;
1843 return *lpMidiStrm != NULL;
1846 /**************************************************************************
1847 * MMSYSTEM_MidiStream_Convert [internal]
1849 static DWORD MMSYSTEM_MidiStream_Convert(WINE_MIDIStream* lpMidiStrm, DWORD pulse)
1853 if (lpMidiStrm->dwTimeDiv == 0) {
1854 FIXME("Shouldn't happen. lpMidiStrm->dwTimeDiv = 0\n");
1855 } else if (lpMidiStrm->dwTimeDiv > 0x8000) { /* SMPTE, unchecked FIXME? */
1856 int nf = -(char)HIBYTE(lpMidiStrm->dwTimeDiv); /* number of frames */
1857 int nsf = LOBYTE(lpMidiStrm->dwTimeDiv); /* number of sub-frames */
1858 ret = (pulse * 1000) / (nf * nsf);
1860 ret = (DWORD)((double)pulse * ((double)lpMidiStrm->dwTempo / 1000) /
1861 (double)lpMidiStrm->dwTimeDiv);
1867 /**************************************************************************
1868 * MMSYSTEM_MidiStream_MessageHandler [internal]
1870 static BOOL MMSYSTEM_MidiStream_MessageHandler(WINE_MIDIStream* lpMidiStrm, LPWINE_MIDI lpwm, LPMSG msg)
1872 LPMIDIHDR lpMidiHdr;
1876 switch (msg->message) {
1878 SetEvent(lpMidiStrm->hEvent);
1882 /* this is not quite what MS doc says... */
1883 midiOutReset(lpMidiStrm->hDevice);
1884 /* empty list of already submitted buffers */
1885 for (lpMidiHdr = lpMidiStrm->lpMidiHdr; lpMidiHdr; lpMidiHdr = (LPMIDIHDR)lpMidiHdr->lpNext) {
1886 lpMidiHdr->dwFlags |= MHDR_DONE;
1887 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
1889 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1890 (HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
1891 lpwm->mod.dwInstance, (DWORD)lpMidiHdr, 0L);
1893 lpMidiStrm->lpMidiHdr = 0;
1894 SetEvent(lpMidiStrm->hEvent);
1896 case WINE_MSM_HEADER:
1897 /* sets initial tick count for first MIDIHDR */
1898 if (!lpMidiStrm->dwStartTicks)
1899 lpMidiStrm->dwStartTicks = GetTickCount();
1901 /* FIXME(EPP): "I don't understand the content of the first MIDIHDR sent
1902 * by native mcimidi, it doesn't look like a correct one".
1903 * this trick allows to throw it away... but I don't like it.
1904 * It looks like part of the file I'm trying to play and definitively looks
1905 * like raw midi content
1906 * I'd really like to understand why native mcimidi sends it. Perhaps a bad
1907 * synchronization issue where native mcimidi is still processing raw MIDI
1908 * content before generating MIDIEVENTs ?
1910 * 4c 04 89 3b 00 81 7c 99 3b 43 00 99 23 5e 04 89 L..;..|.;C..#^..
1911 * 3b 00 00 89 23 00 7c 99 3b 45 00 99 28 62 04 89 ;...#.|.;E..(b..
1912 * 3b 00 00 89 28 00 81 7c 99 3b 4e 00 99 23 5e 04 ;...(..|.;N..#^.
1913 * 89 3b 00 00 89 23 00 7c 99 3b 45 00 99 23 78 04 .;...#.|.;E..#x.
1914 * 89 3b 00 00 89 23 00 81 7c 99 3b 48 00 99 23 5e .;...#..|.;H..#^
1915 * 04 89 3b 00 00 89 23 00 7c 99 3b 4e 00 99 28 62 ..;...#.|.;N..(b
1916 * 04 89 3b 00 00 89 28 00 81 7c 99 39 4c 00 99 23 ..;...(..|.9L..#
1917 * 5e 04 89 39 00 00 89 23 00 82 7c 99 3b 4c 00 99 ^..9...#..|.;L..
1918 * 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 00 99 #^..;...#.|.;H..
1919 * 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b 3f 04 (b..;...(..|.;?.
1920 * 89 3b 00 1c 99 23 5e 04 89 23 00 5c 99 3b 45 00 .;...#^..#.\.;E.
1921 * 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 3b 46 .#x..;...#..|.;F
1922 * 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 ..#^..;...#.|.;H
1923 * 00 99 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b ..(b..;...(..|.;
1924 * 46 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b F..#^..;...#.|.;
1925 * 48 00 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 H..#x..;...#..|.
1926 * 3b 4c 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 ;L..#^..;...#.|.
1928 lpMidiHdr = (LPMIDIHDR)msg->lParam;
1929 lpData = lpMidiHdr->lpData;
1930 TRACE("Adding %s lpMidiHdr=%p [lpData=0x%08lx dwBufferLength=%lu/%lu dwFlags=0x%08lx size=%u]\n",
1931 (lpMidiHdr->dwFlags & MHDR_ISSTRM) ? "stream" : "regular", lpMidiHdr,
1932 (DWORD)lpMidiHdr, lpMidiHdr->dwBufferLength, lpMidiHdr->dwBytesRecorded,
1933 lpMidiHdr->dwFlags, msg->wParam);
1935 /* dumps content of lpMidiHdr->lpData
1936 * FIXME: there should be a debug routine somewhere that already does this
1937 * I hate spreading this type of shit all around the code
1939 for (dwToGo = 0; dwToGo < lpMidiHdr->dwBufferLength; dwToGo += 16) {
1943 for (i = 0; i < min(16, lpMidiHdr->dwBufferLength - dwToGo); i++)
1944 printf("%02x ", lpData[dwToGo + i]);
1947 for (i = 0; i < min(16, lpMidiHdr->dwBufferLength - dwToGo); i++) {
1948 ch = lpData[dwToGo + i];
1949 printf("%c", (ch >= 0x20 && ch <= 0x7F) ? ch : '.');
1954 if (((LPMIDIEVENT)lpData)->dwStreamID != 0 &&
1955 ((LPMIDIEVENT)lpData)->dwStreamID != 0xFFFFFFFF &&
1956 ((LPMIDIEVENT)lpData)->dwStreamID != (DWORD)lpMidiStrm) {
1957 FIXME("Dropping bad %s lpMidiHdr (streamID=%08lx)\n",
1958 (lpMidiHdr->dwFlags & MHDR_ISSTRM) ? "stream" : "regular",
1959 ((LPMIDIEVENT)lpData)->dwStreamID);
1960 lpMidiHdr->dwFlags |= MHDR_DONE;
1961 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
1963 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1964 (HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
1965 lpwm->mod.dwInstance, (DWORD)lpMidiHdr, 0L);
1969 for (lpmh = &lpMidiStrm->lpMidiHdr; *lpmh; lpmh = (LPMIDIHDR*)&((*lpmh)->lpNext));
1971 lpMidiHdr = (LPMIDIHDR)msg->lParam;
1972 lpMidiHdr->lpNext = 0;
1973 lpMidiHdr->dwFlags |= MHDR_INQUEUE;
1974 lpMidiHdr->dwFlags &= MHDR_DONE;
1975 lpMidiHdr->dwOffset = 0;
1979 FIXME("Unknown message %d\n", msg->message);
1985 /**************************************************************************
1986 * MMSYSTEM_MidiStream_Player [internal]
1988 static DWORD CALLBACK MMSYSTEM_MidiStream_Player(LPVOID pmt)
1990 WINE_MIDIStream* lpMidiStrm = pmt;
1995 LPMIDIHDR lpMidiHdr;
1999 TRACE("(%p)!\n", lpMidiStrm);
2002 (lpwm = (LPWINE_MIDI)MMDRV_Get(lpMidiStrm->hDevice, MMDRV_MIDIOUT, FALSE)) == NULL)
2005 /* force thread's queue creation */
2006 /* Used to be InitThreadInput16(0, 5); */
2007 /* but following works also with hack in midiStreamOpen */
2008 PeekMessageA(&msg, 0, 0, 0, 0);
2010 /* FIXME: this next line must be called before midiStreamOut or midiStreamRestart are called */
2011 SetEvent(lpMidiStrm->hEvent);
2012 TRACE("Ready to go 1\n");
2013 /* thread is started in paused mode */
2014 SuspendThread(lpMidiStrm->hThread);
2015 TRACE("Ready to go 2\n");
2017 lpMidiStrm->dwStartTicks = 0;
2018 lpMidiStrm->dwPulses = 0;
2020 lpMidiStrm->lpMidiHdr = 0;
2023 lpMidiHdr = lpMidiStrm->lpMidiHdr;
2025 /* for first message, block until one arrives, then process all that are available */
2026 GetMessageA(&msg, 0, 0, 0);
2028 if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm, lpwm, &msg))
2030 } while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE));
2036 lpData = lpMidiHdr->lpData;
2038 me = (LPMIDIEVENT)(lpData + lpMidiHdr->dwOffset);
2040 /* do we have to wait ? */
2041 if (me->dwDeltaTime) {
2042 lpMidiStrm->dwPositionMS += MMSYSTEM_MidiStream_Convert(lpMidiStrm, me->dwDeltaTime);
2043 lpMidiStrm->dwPulses += me->dwDeltaTime;
2045 dwToGo = lpMidiStrm->dwStartTicks + lpMidiStrm->dwPositionMS;
2047 TRACE("%ld/%ld/%ld\n", dwToGo, GetTickCount(), me->dwDeltaTime);
2048 while ((dwCurrTC = GetTickCount()) < dwToGo) {
2049 if (MsgWaitForMultipleObjects(0, NULL, FALSE, dwToGo - dwCurrTC, QS_ALLINPUT) == WAIT_OBJECT_0) {
2050 /* got a message, handle it */
2051 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) {
2052 if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm, lpwm, &msg))
2057 /* timeout, so me->dwDeltaTime is elapsed, can break the while loop */
2062 switch (MEVT_EVENTTYPE(me->dwEvent & ~MEVT_F_CALLBACK)) {
2064 FIXME("NIY: MEVT_COMMENT\n");
2065 /* do nothing, skip bytes */
2068 FIXME("NIY: MEVT_LONGMSG, aka sending Sysex event\n");
2073 midiOutShortMsg(lpMidiStrm->hDevice, MEVT_EVENTPARM(me->dwEvent));
2076 lpMidiStrm->dwTempo = MEVT_EVENTPARM(me->dwEvent);
2081 FIXME("Unknown MEVT (0x%02x)\n", MEVT_EVENTTYPE(me->dwEvent & ~MEVT_F_CALLBACK));
2084 if (me->dwEvent & MEVT_F_CALLBACK) {
2085 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
2086 (HDRVR)lpMidiStrm->hDevice, MM_MOM_POSITIONCB,
2087 lpwm->mod.dwInstance, (LPARAM)lpMidiHdr, 0L);
2089 lpMidiHdr->dwOffset += sizeof(MIDIEVENT) - sizeof(me->dwParms);
2090 if (me->dwEvent & MEVT_F_LONG)
2091 lpMidiHdr->dwOffset += (MEVT_EVENTPARM(me->dwEvent) + 3) & ~3;
2092 if (lpMidiHdr->dwOffset >= lpMidiHdr->dwBufferLength) {
2093 /* done with this header */
2094 lpMidiHdr->dwFlags |= MHDR_DONE;
2095 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
2097 lpMidiStrm->lpMidiHdr = (LPMIDIHDR)lpMidiHdr->lpNext;
2098 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
2099 (HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
2100 lpwm->mod.dwInstance, (DWORD)lpMidiHdr, 0L);
2105 TRACE("End of thread\n");
2107 return 0; /* for removing the warning, never executed */
2110 /**************************************************************************
2111 * MMSYSTEM_MidiStream_PostMessage [internal]
2113 static BOOL MMSYSTEM_MidiStream_PostMessage(WINE_MIDIStream* lpMidiStrm, WORD msg, DWORD pmt1, DWORD pmt2)
2115 if (PostThreadMessageA(lpMidiStrm->dwThreadID, msg, pmt1, pmt2)) {
2118 if (pFnReleaseThunkLock) pFnReleaseThunkLock(&count);
2119 WaitForSingleObject(lpMidiStrm->hEvent, INFINITE);
2120 if (pFnRestoreThunkLock) pFnRestoreThunkLock(count);
2122 WARN("bad PostThreadMessageA\n");
2128 /**************************************************************************
2129 * midiStreamClose [WINMM.@]
2131 MMRESULT WINAPI midiStreamClose(HMIDISTRM hMidiStrm)
2133 WINE_MIDIStream* lpMidiStrm;
2135 TRACE("(%p)!\n", hMidiStrm);
2137 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL))
2138 return MMSYSERR_INVALHANDLE;
2140 midiStreamStop(hMidiStrm);
2141 MMSYSTEM_MidiStream_PostMessage(lpMidiStrm, WM_QUIT, 0, 0);
2142 HeapFree(GetProcessHeap(), 0, lpMidiStrm);
2143 CloseHandle(lpMidiStrm->hEvent);
2145 return midiOutClose((HMIDIOUT)hMidiStrm);
2148 /**************************************************************************
2149 * MMSYSTEM_MidiStream_Open [internal]
2151 MMRESULT MIDI_StreamOpen(HMIDISTRM* lphMidiStrm, LPUINT lpuDeviceID, DWORD cMidi,
2152 DWORD dwCallback, DWORD dwInstance, DWORD fdwOpen,
2155 WINE_MIDIStream* lpMidiStrm;
2157 MIDIOPENSTRMID mosm;
2161 TRACE("(%p, %p, %ld, 0x%08lx, 0x%08lx, 0x%08lx)!\n",
2162 lphMidiStrm, lpuDeviceID, cMidi, dwCallback, dwInstance, fdwOpen);
2164 if (cMidi != 1 || lphMidiStrm == NULL || lpuDeviceID == NULL)
2165 return MMSYSERR_INVALPARAM;
2167 lpMidiStrm = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_MIDIStream));
2169 return MMSYSERR_NOMEM;
2171 lpMidiStrm->dwTempo = 500000;
2172 lpMidiStrm->dwTimeDiv = 480; /* 480 is 120 quater notes per minute *//* FIXME ??*/
2173 lpMidiStrm->dwPositionMS = 0;
2175 mosm.dwStreamID = (DWORD)lpMidiStrm;
2176 /* FIXME: the correct value is not allocated yet for MAPPER */
2177 mosm.wDeviceID = *lpuDeviceID;
2178 lpwm = MIDI_OutAlloc(&hMidiOut, &dwCallback, &dwInstance, &fdwOpen, 1, &mosm, bFrom32);
2179 lpMidiStrm->hDevice = hMidiOut;
2181 *lphMidiStrm = (HMIDISTRM)hMidiOut;
2183 lpwm->mld.uDeviceID = *lpuDeviceID;
2185 ret = MMDRV_Open(&lpwm->mld, MODM_OPEN, (DWORD)&lpwm->mod, fdwOpen);
2186 lpMidiStrm->hEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
2187 lpMidiStrm->wFlags = HIWORD(fdwOpen);
2189 lpMidiStrm->hThread = CreateThread(NULL, 0, MMSYSTEM_MidiStream_Player,
2190 lpMidiStrm, 0, &(lpMidiStrm->dwThreadID));
2192 if (!lpMidiStrm->hThread) {
2193 midiStreamClose((HMIDISTRM)hMidiOut);
2194 return MMSYSERR_NOMEM;
2197 /* wait for thread to have started, and for its queue to be created */
2201 /* (Release|Restore)ThunkLock() is needed when this method is called from 16 bit code,
2202 * (meaning the Win16Lock is set), so that it's released and the 32 bit thread running
2203 * MMSYSTEM_MidiStreamPlayer can acquire Win16Lock to create its queue.
2205 if (pFnReleaseThunkLock) pFnReleaseThunkLock(&count);
2206 WaitForSingleObject(lpMidiStrm->hEvent, INFINITE);
2207 if (pFnRestoreThunkLock) pFnRestoreThunkLock(count);
2210 TRACE("=> (%u/%d) hMidi=%p ret=%d lpMidiStrm=%p\n",
2211 *lpuDeviceID, lpwm->mld.uDeviceID, *lphMidiStrm, ret, lpMidiStrm);
2215 /**************************************************************************
2216 * midiStreamOpen [WINMM.@]
2218 MMRESULT WINAPI midiStreamOpen(HMIDISTRM* lphMidiStrm, LPUINT lpuDeviceID,
2219 DWORD cMidi, DWORD dwCallback,
2220 DWORD dwInstance, DWORD fdwOpen)
2222 return MIDI_StreamOpen(lphMidiStrm, lpuDeviceID, cMidi, dwCallback,
2223 dwInstance, fdwOpen, TRUE);
2226 /**************************************************************************
2227 * midiStreamOut [WINMM.@]
2229 MMRESULT WINAPI midiStreamOut(HMIDISTRM hMidiStrm, LPMIDIHDR lpMidiHdr,
2232 WINE_MIDIStream* lpMidiStrm;
2233 DWORD ret = MMSYSERR_NOERROR;
2235 TRACE("(%p, %p, %u)!\n", hMidiStrm, lpMidiHdr, cbMidiHdr);
2237 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
2238 ret = MMSYSERR_INVALHANDLE;
2239 } else if (!lpMidiHdr) {
2240 ret = MMSYSERR_INVALPARAM;
2242 if (!PostThreadMessageA(lpMidiStrm->dwThreadID,
2243 WINE_MSM_HEADER, cbMidiHdr,
2244 (DWORD)lpMidiHdr)) {
2245 WARN("bad PostThreadMessageA\n");
2246 ret = MMSYSERR_ERROR;
2252 /**************************************************************************
2253 * midiStreamPause [WINMM.@]
2255 MMRESULT WINAPI midiStreamPause(HMIDISTRM hMidiStrm)
2257 WINE_MIDIStream* lpMidiStrm;
2258 DWORD ret = MMSYSERR_NOERROR;
2260 TRACE("(%p)!\n", hMidiStrm);
2262 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
2263 ret = MMSYSERR_INVALHANDLE;
2265 if (SuspendThread(lpMidiStrm->hThread) == 0xFFFFFFFF) {
2266 WARN("bad Suspend (%ld)\n", GetLastError());
2267 ret = MMSYSERR_ERROR;
2273 /**************************************************************************
2274 * midiStreamPosition [WINMM.@]
2276 MMRESULT WINAPI midiStreamPosition(HMIDISTRM hMidiStrm, LPMMTIME lpMMT, UINT cbmmt)
2278 WINE_MIDIStream* lpMidiStrm;
2279 DWORD ret = MMSYSERR_NOERROR;
2281 TRACE("(%p, %p, %u)!\n", hMidiStrm, lpMMT, cbmmt);
2283 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
2284 ret = MMSYSERR_INVALHANDLE;
2285 } else if (lpMMT == NULL || cbmmt != sizeof(MMTIME)) {
2286 ret = MMSYSERR_INVALPARAM;
2288 switch (lpMMT->wType) {
2290 lpMMT->u.ms = lpMidiStrm->dwPositionMS;
2291 TRACE("=> %ld ms\n", lpMMT->u.ms);
2294 lpMMT->u.ticks = lpMidiStrm->dwPulses;
2295 TRACE("=> %ld ticks\n", lpMMT->u.ticks);
2298 WARN("Unsupported time type %d\n", lpMMT->wType);
2299 lpMMT->wType = TIME_MS;
2300 ret = MMSYSERR_INVALPARAM;
2307 /**************************************************************************
2308 * midiStreamProperty [WINMM.@]
2310 MMRESULT WINAPI midiStreamProperty(HMIDISTRM hMidiStrm, LPBYTE lpPropData, DWORD dwProperty)
2312 WINE_MIDIStream* lpMidiStrm;
2313 MMRESULT ret = MMSYSERR_NOERROR;
2315 TRACE("(%p, %p, %lx)\n", hMidiStrm, lpPropData, dwProperty);
2317 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
2318 ret = MMSYSERR_INVALHANDLE;
2319 } else if ((dwProperty & (MIDIPROP_GET|MIDIPROP_SET)) == 0) {
2320 ret = MMSYSERR_INVALPARAM;
2321 } else if (dwProperty & MIDIPROP_TEMPO) {
2322 MIDIPROPTEMPO* mpt = (MIDIPROPTEMPO*)lpPropData;
2324 if (sizeof(MIDIPROPTEMPO) != mpt->cbStruct) {
2325 ret = MMSYSERR_INVALPARAM;
2326 } else if (dwProperty & MIDIPROP_SET) {
2327 lpMidiStrm->dwTempo = mpt->dwTempo;
2328 TRACE("Setting tempo to %ld\n", mpt->dwTempo);
2329 } else if (dwProperty & MIDIPROP_GET) {
2330 mpt->dwTempo = lpMidiStrm->dwTempo;
2331 TRACE("Getting tempo <= %ld\n", mpt->dwTempo);
2333 } else if (dwProperty & MIDIPROP_TIMEDIV) {
2334 MIDIPROPTIMEDIV* mptd = (MIDIPROPTIMEDIV*)lpPropData;
2336 if (sizeof(MIDIPROPTIMEDIV) != mptd->cbStruct) {
2337 ret = MMSYSERR_INVALPARAM;
2338 } else if (dwProperty & MIDIPROP_SET) {
2339 lpMidiStrm->dwTimeDiv = mptd->dwTimeDiv;
2340 TRACE("Setting time div to %ld\n", mptd->dwTimeDiv);
2341 } else if (dwProperty & MIDIPROP_GET) {
2342 mptd->dwTimeDiv = lpMidiStrm->dwTimeDiv;
2343 TRACE("Getting time div <= %ld\n", mptd->dwTimeDiv);
2346 ret = MMSYSERR_INVALPARAM;
2352 /**************************************************************************
2353 * midiStreamRestart [WINMM.@]
2355 MMRESULT WINAPI midiStreamRestart(HMIDISTRM hMidiStrm)
2357 WINE_MIDIStream* lpMidiStrm;
2358 MMRESULT ret = MMSYSERR_NOERROR;
2360 TRACE("(%p)!\n", hMidiStrm);
2362 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
2363 ret = MMSYSERR_INVALHANDLE;
2367 /* since we increase the thread suspend count on each midiStreamPause
2368 * there may be a need for several midiStreamResume
2371 ret = ResumeThread(lpMidiStrm->hThread);
2372 } while (ret != 0xFFFFFFFF && ret != 0);
2373 if (ret == 0xFFFFFFFF) {
2374 WARN("bad Resume (%ld)\n", GetLastError());
2375 ret = MMSYSERR_ERROR;
2377 lpMidiStrm->dwStartTicks = GetTickCount() - lpMidiStrm->dwPositionMS;
2383 /**************************************************************************
2384 * midiStreamStop [WINMM.@]
2386 MMRESULT WINAPI midiStreamStop(HMIDISTRM hMidiStrm)
2388 WINE_MIDIStream* lpMidiStrm;
2389 MMRESULT ret = MMSYSERR_NOERROR;
2391 TRACE("(%p)!\n", hMidiStrm);
2393 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
2394 ret = MMSYSERR_INVALHANDLE;
2396 /* in case stream has been paused... FIXME is the current state correct ? */
2397 midiStreamRestart(hMidiStrm);
2398 MMSYSTEM_MidiStream_PostMessage(lpMidiStrm, WINE_MSM_STOP, 0, 0);
2403 UINT WAVE_Open(HANDLE* lphndl, UINT uDeviceID, UINT uType,
2404 const LPWAVEFORMATEX lpFormat, DWORD dwCallback,
2405 DWORD dwInstance, DWORD dwFlags, BOOL bFrom32)
2409 DWORD dwRet = MMSYSERR_NOERROR;
2412 TRACE("(%p, %d, %s, %p, %08lX, %08lX, %08lX, %d);\n",
2413 lphndl, (int)uDeviceID, (uType==MMDRV_WAVEOUT)?"Out":"In", lpFormat, dwCallback,
2414 dwInstance, dwFlags, bFrom32?32:16);
2416 if (dwFlags & WAVE_FORMAT_QUERY) TRACE("WAVE_FORMAT_QUERY requested !\n");
2418 if (lpFormat == NULL) return WAVERR_BADFORMAT;
2419 if ((dwFlags & WAVE_MAPPED) && (uDeviceID == (UINT)-1))
2420 return MMSYSERR_INVALPARAM;
2422 TRACE("wFormatTag=%u, nChannels=%u, nSamplesPerSec=%lu, nAvgBytesPerSec=%lu, nBlockAlign=%u, wBitsPerSample=%u, cbSize=%u\n",
2423 lpFormat->wFormatTag, lpFormat->nChannels, lpFormat->nSamplesPerSec,
2424 lpFormat->nAvgBytesPerSec, lpFormat->nBlockAlign, lpFormat->wBitsPerSample, lpFormat->cbSize);
2426 if ((wmld = MMDRV_Alloc(sizeof(WINE_WAVE), uType, &handle,
2427 &dwFlags, &dwCallback, &dwInstance, bFrom32)) == NULL)
2428 return MMSYSERR_NOMEM;
2431 wod.lpFormat = lpFormat; /* should the struct be copied iso pointer? */
2432 wod.dwCallback = dwCallback;
2433 wod.dwInstance = dwInstance;
2436 TRACE("cb=%08lx\n", wod.dwCallback);
2439 if (dwFlags & WAVE_MAPPED) {
2440 wod.uMappedDeviceID = uDeviceID;
2441 uDeviceID = WAVE_MAPPER;
2443 wod.uMappedDeviceID = -1;
2445 wmld->uDeviceID = uDeviceID;
2447 dwRet = MMDRV_Open(wmld, (uType == MMDRV_WAVEOUT) ? WODM_OPEN : WIDM_OPEN,
2448 (DWORD)&wod, dwFlags);
2450 if (dwRet != WAVERR_BADFORMAT ||
2451 (dwFlags & (WAVE_MAPPED|WAVE_FORMAT_DIRECT)) != 0) break;
2452 /* if we ask for a format which isn't supported by the physical driver,
2453 * let's try to map it through the wave mapper (except, if we already tried
2454 * or user didn't allow us to use acm codecs)
2456 dwFlags |= WAVE_MAPPED;
2457 /* we shall loop only one */
2460 if ((dwFlags & WAVE_FORMAT_QUERY) || dwRet != MMSYSERR_NOERROR) {
2461 MMDRV_Free(handle, wmld);
2465 if (lphndl != NULL) *lphndl = handle;
2466 TRACE("=> %ld hWave=%p\n", dwRet, handle);
2471 /**************************************************************************
2472 * waveOutGetNumDevs [WINMM.@]
2474 UINT WINAPI waveOutGetNumDevs(void)
2476 return MMDRV_GetNum(MMDRV_WAVEOUT);
2479 /**************************************************************************
2480 * waveOutGetDevCapsA [WINMM.@]
2482 UINT WINAPI waveOutGetDevCapsA(UINT_PTR uDeviceID, LPWAVEOUTCAPSA lpCaps,
2487 TRACE("(%u %p %u)!\n", uDeviceID, lpCaps, uSize);
2489 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2491 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_WAVEOUT, TRUE)) == NULL)
2492 return MMSYSERR_BADDEVICEID;
2494 return MMDRV_Message(wmld, WODM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
2498 /**************************************************************************
2499 * waveOutGetDevCapsW [WINMM.@]
2501 UINT WINAPI waveOutGetDevCapsW(UINT_PTR uDeviceID, LPWAVEOUTCAPSW lpCaps,
2505 UINT ret = waveOutGetDevCapsA(uDeviceID, &wocA, sizeof(wocA));
2507 if (ret == MMSYSERR_NOERROR) {
2509 wocW.wMid = wocA.wMid;
2510 wocW.wPid = wocA.wPid;
2511 wocW.vDriverVersion = wocA.vDriverVersion;
2512 MultiByteToWideChar( CP_ACP, 0, wocA.szPname, -1, wocW.szPname,
2513 sizeof(wocW.szPname)/sizeof(WCHAR) );
2514 wocW.dwFormats = wocA.dwFormats;
2515 wocW.wChannels = wocA.wChannels;
2516 wocW.dwSupport = wocA.dwSupport;
2517 memcpy(lpCaps, &wocW, min(uSize, sizeof(wocW)));
2522 /**************************************************************************
2523 * WAVE_GetErrorText [internal]
2525 static UINT16 WAVE_GetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize)
2527 UINT16 ret = MMSYSERR_BADERRNUM;
2529 if (lpText == NULL) {
2530 ret = MMSYSERR_INVALPARAM;
2531 } else if (uSize == 0) {
2532 ret = MMSYSERR_NOERROR;
2534 /* test has been removed 'coz MMSYSERR_BASE is 0, and gcc did emit
2535 * a warning for the test was always true */
2536 (/*uError >= MMSYSERR_BASE && */uError <= MMSYSERR_LASTERROR) ||
2537 (uError >= WAVERR_BASE && uError <= WAVERR_LASTERROR)) {
2539 if (LoadStringA(WINMM_IData->hWinMM32Instance,
2540 uError, lpText, uSize) > 0) {
2541 ret = MMSYSERR_NOERROR;
2547 /**************************************************************************
2548 * waveOutGetErrorTextA [WINMM.@]
2550 UINT WINAPI waveOutGetErrorTextA(UINT uError, LPSTR lpText, UINT uSize)
2552 return WAVE_GetErrorText(uError, lpText, uSize);
2555 /**************************************************************************
2556 * waveOutGetErrorTextW [WINMM.@]
2558 UINT WINAPI waveOutGetErrorTextW(UINT uError, LPWSTR lpText, UINT uSize)
2560 LPSTR xstr = HeapAlloc(GetProcessHeap(), 0, uSize);
2561 UINT ret = WAVE_GetErrorText(uError, xstr, uSize);
2563 MultiByteToWideChar( CP_ACP, 0, xstr, -1, lpText, uSize );
2564 HeapFree(GetProcessHeap(), 0, xstr);
2568 /**************************************************************************
2569 * waveOutOpen [WINMM.@]
2570 * All the args/structs have the same layout as the win16 equivalents
2572 UINT WINAPI waveOutOpen(LPHWAVEOUT lphWaveOut, UINT uDeviceID,
2573 const LPWAVEFORMATEX lpFormat, DWORD_PTR dwCallback,
2574 DWORD_PTR dwInstance, DWORD dwFlags)
2576 return WAVE_Open((HANDLE*)lphWaveOut, uDeviceID, MMDRV_WAVEOUT, lpFormat,
2577 dwCallback, dwInstance, dwFlags, TRUE);
2580 /**************************************************************************
2581 * waveOutClose [WINMM.@]
2583 UINT WINAPI waveOutClose(HWAVEOUT hWaveOut)
2588 TRACE("(%p)\n", hWaveOut);
2590 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2591 return MMSYSERR_INVALHANDLE;
2593 dwRet = MMDRV_Close(wmld, WODM_CLOSE);
2594 if (dwRet != WAVERR_STILLPLAYING)
2595 MMDRV_Free(hWaveOut, wmld);
2600 /**************************************************************************
2601 * waveOutPrepareHeader [WINMM.@]
2603 UINT WINAPI waveOutPrepareHeader(HWAVEOUT hWaveOut,
2604 WAVEHDR* lpWaveOutHdr, UINT uSize)
2608 TRACE("(%p, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
2610 if (lpWaveOutHdr == NULL) return MMSYSERR_INVALPARAM;
2612 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2613 return MMSYSERR_INVALHANDLE;
2615 return MMDRV_Message(wmld, WODM_PREPARE, (DWORD_PTR)lpWaveOutHdr, uSize, TRUE);
2618 /**************************************************************************
2619 * waveOutUnprepareHeader [WINMM.@]
2621 UINT WINAPI waveOutUnprepareHeader(HWAVEOUT hWaveOut,
2622 LPWAVEHDR lpWaveOutHdr, UINT uSize)
2626 TRACE("(%p, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
2628 if (!(lpWaveOutHdr->dwFlags & WHDR_PREPARED)) {
2629 return MMSYSERR_NOERROR;
2632 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2633 return MMSYSERR_INVALHANDLE;
2635 return MMDRV_Message(wmld, WODM_UNPREPARE, (DWORD_PTR)lpWaveOutHdr, uSize, TRUE);
2638 /**************************************************************************
2639 * waveOutWrite [WINMM.@]
2641 UINT WINAPI waveOutWrite(HWAVEOUT hWaveOut, LPWAVEHDR lpWaveOutHdr,
2646 TRACE("(%p, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
2648 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2649 return MMSYSERR_INVALHANDLE;
2651 return MMDRV_Message(wmld, WODM_WRITE, (DWORD_PTR)lpWaveOutHdr, uSize, TRUE);
2654 /**************************************************************************
2655 * waveOutBreakLoop [WINMM.@]
2657 UINT WINAPI waveOutBreakLoop(HWAVEOUT hWaveOut)
2661 TRACE("(%p);\n", hWaveOut);
2663 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2664 return MMSYSERR_INVALHANDLE;
2665 return MMDRV_Message(wmld, WODM_BREAKLOOP, 0L, 0L, TRUE);
2668 /**************************************************************************
2669 * waveOutPause [WINMM.@]
2671 UINT WINAPI waveOutPause(HWAVEOUT hWaveOut)
2675 TRACE("(%p);\n", hWaveOut);
2677 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2678 return MMSYSERR_INVALHANDLE;
2679 return MMDRV_Message(wmld, WODM_PAUSE, 0L, 0L, TRUE);
2682 /**************************************************************************
2683 * waveOutReset [WINMM.@]
2685 UINT WINAPI waveOutReset(HWAVEOUT hWaveOut)
2689 TRACE("(%p);\n", hWaveOut);
2691 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2692 return MMSYSERR_INVALHANDLE;
2693 return MMDRV_Message(wmld, WODM_RESET, 0L, 0L, TRUE);
2696 /**************************************************************************
2697 * waveOutRestart [WINMM.@]
2699 UINT WINAPI waveOutRestart(HWAVEOUT hWaveOut)
2703 TRACE("(%p);\n", hWaveOut);
2705 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2706 return MMSYSERR_INVALHANDLE;
2707 return MMDRV_Message(wmld, WODM_RESTART, 0L, 0L, TRUE);
2710 /**************************************************************************
2711 * waveOutGetPosition [WINMM.@]
2713 UINT WINAPI waveOutGetPosition(HWAVEOUT hWaveOut, LPMMTIME lpTime,
2718 TRACE("(%p, %p, %u);\n", hWaveOut, lpTime, uSize);
2720 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2721 return MMSYSERR_INVALHANDLE;
2723 return MMDRV_Message(wmld, WODM_GETPOS, (DWORD_PTR)lpTime, uSize, TRUE);
2726 /**************************************************************************
2727 * waveOutGetPitch [WINMM.@]
2729 UINT WINAPI waveOutGetPitch(HWAVEOUT hWaveOut, LPDWORD lpdw)
2733 TRACE("(%p, %08lx);\n", hWaveOut, (DWORD)lpdw);
2735 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2736 return MMSYSERR_INVALHANDLE;
2737 return MMDRV_Message(wmld, WODM_GETPITCH, (DWORD_PTR)lpdw, 0L, TRUE);
2740 /**************************************************************************
2741 * waveOutSetPitch [WINMM.@]
2743 UINT WINAPI waveOutSetPitch(HWAVEOUT hWaveOut, DWORD dw)
2747 TRACE("(%p, %08lx);\n", hWaveOut, (DWORD)dw);
2749 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2750 return MMSYSERR_INVALHANDLE;
2751 return MMDRV_Message(wmld, WODM_SETPITCH, dw, 0L, TRUE);
2754 /**************************************************************************
2755 * waveOutGetPlaybackRate [WINMM.@]
2757 UINT WINAPI waveOutGetPlaybackRate(HWAVEOUT hWaveOut, LPDWORD lpdw)
2761 TRACE("(%p, %08lx);\n", hWaveOut, (DWORD)lpdw);
2763 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2764 return MMSYSERR_INVALHANDLE;
2765 return MMDRV_Message(wmld, WODM_GETPLAYBACKRATE, (DWORD_PTR)lpdw, 0L, TRUE);
2768 /**************************************************************************
2769 * waveOutSetPlaybackRate [WINMM.@]
2771 UINT WINAPI waveOutSetPlaybackRate(HWAVEOUT hWaveOut, DWORD dw)
2775 TRACE("(%p, %08lx);\n", hWaveOut, (DWORD)dw);
2777 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2778 return MMSYSERR_INVALHANDLE;
2779 return MMDRV_Message(wmld, WODM_SETPLAYBACKRATE, dw, 0L, TRUE);
2782 /**************************************************************************
2783 * waveOutGetVolume [WINMM.@]
2785 UINT WINAPI waveOutGetVolume(HWAVEOUT hWaveOut, LPDWORD lpdw)
2789 TRACE("(%p, %08lx);\n", hWaveOut, (DWORD)lpdw);
2791 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, TRUE)) == NULL)
2792 return MMSYSERR_INVALHANDLE;
2794 return MMDRV_Message(wmld, WODM_GETVOLUME, (DWORD_PTR)lpdw, 0L, TRUE);
2797 /**************************************************************************
2798 * waveOutSetVolume [WINMM.@]
2800 UINT WINAPI waveOutSetVolume(HWAVEOUT hWaveOut, DWORD dw)
2804 TRACE("(%p, %08lx);\n", hWaveOut, dw);
2806 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, TRUE)) == NULL)
2807 return MMSYSERR_INVALHANDLE;
2809 return MMDRV_Message(wmld, WODM_SETVOLUME, dw, 0L, TRUE);
2812 /**************************************************************************
2813 * waveOutGetID [WINMM.@]
2815 UINT WINAPI waveOutGetID(HWAVEOUT hWaveOut, UINT* lpuDeviceID)
2819 TRACE("(%p, %p);\n", hWaveOut, lpuDeviceID);
2821 if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
2823 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2824 return MMSYSERR_INVALHANDLE;
2826 *lpuDeviceID = wmld->uDeviceID;
2830 /**************************************************************************
2831 * waveOutMessage [WINMM.@]
2833 UINT WINAPI waveOutMessage(HWAVEOUT hWaveOut, UINT uMessage,
2834 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2838 TRACE("(%p, %u, %ld, %ld)\n", hWaveOut, uMessage, dwParam1, dwParam2);
2840 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL) {
2841 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, TRUE)) != NULL) {
2842 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
2844 return MMSYSERR_INVALHANDLE;
2848 if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER))
2849 return MMSYSERR_INVALPARAM;
2851 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
2854 /**************************************************************************
2855 * waveInGetNumDevs [WINMM.@]
2857 UINT WINAPI waveInGetNumDevs(void)
2859 return MMDRV_GetNum(MMDRV_WAVEIN);
2862 /**************************************************************************
2863 * waveInGetDevCapsW [WINMM.@]
2865 UINT WINAPI waveInGetDevCapsW(UINT_PTR uDeviceID, LPWAVEINCAPSW lpCaps, UINT uSize)
2868 UINT ret = waveInGetDevCapsA(uDeviceID, &wicA, uSize);
2870 if (ret == MMSYSERR_NOERROR) {
2872 wicW.wMid = wicA.wMid;
2873 wicW.wPid = wicA.wPid;
2874 wicW.vDriverVersion = wicA.vDriverVersion;
2875 MultiByteToWideChar( CP_ACP, 0, wicA.szPname, -1, wicW.szPname,
2876 sizeof(wicW.szPname)/sizeof(WCHAR) );
2877 wicW.dwFormats = wicA.dwFormats;
2878 wicW.wChannels = wicA.wChannels;
2879 memcpy(lpCaps, &wicW, min(uSize, sizeof(wicW)));
2884 /**************************************************************************
2885 * waveInGetDevCapsA [WINMM.@]
2887 UINT WINAPI waveInGetDevCapsA(UINT_PTR uDeviceID, LPWAVEINCAPSA lpCaps, UINT uSize)
2891 TRACE("(%u %p %u)!\n", uDeviceID, lpCaps, uSize);
2893 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2895 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_WAVEIN, TRUE)) == NULL)
2896 return MMSYSERR_BADDEVICEID;
2898 return MMDRV_Message(wmld, WIDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
2901 /**************************************************************************
2902 * waveInGetErrorTextA [WINMM.@]
2904 UINT WINAPI waveInGetErrorTextA(UINT uError, LPSTR lpText, UINT uSize)
2906 return WAVE_GetErrorText(uError, lpText, uSize);
2909 /**************************************************************************
2910 * waveInGetErrorTextW [WINMM.@]
2912 UINT WINAPI waveInGetErrorTextW(UINT uError, LPWSTR lpText, UINT uSize)
2914 LPSTR txt = HeapAlloc(GetProcessHeap(), 0, uSize);
2915 UINT ret = WAVE_GetErrorText(uError, txt, uSize);
2917 MultiByteToWideChar( CP_ACP, 0, txt, -1, lpText, uSize );
2918 HeapFree(GetProcessHeap(), 0, txt);
2922 /**************************************************************************
2923 * waveInOpen [WINMM.@]
2925 UINT WINAPI waveInOpen(HWAVEIN* lphWaveIn, UINT uDeviceID,
2926 const LPWAVEFORMATEX lpFormat, DWORD dwCallback,
2927 DWORD dwInstance, DWORD dwFlags)
2929 return WAVE_Open((HANDLE*)lphWaveIn, uDeviceID, MMDRV_WAVEIN, lpFormat,
2930 dwCallback, dwInstance, dwFlags, TRUE);
2933 /**************************************************************************
2934 * waveInClose [WINMM.@]
2936 UINT WINAPI waveInClose(HWAVEIN hWaveIn)
2941 TRACE("(%p)\n", hWaveIn);
2943 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2944 return MMSYSERR_INVALHANDLE;
2946 dwRet = MMDRV_Message(wmld, WIDM_CLOSE, 0L, 0L, TRUE);
2947 if (dwRet != WAVERR_STILLPLAYING)
2948 MMDRV_Free(hWaveIn, wmld);
2952 /**************************************************************************
2953 * waveInPrepareHeader [WINMM.@]
2955 UINT WINAPI waveInPrepareHeader(HWAVEIN hWaveIn, WAVEHDR* lpWaveInHdr,
2960 TRACE("(%p, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
2962 if (lpWaveInHdr == NULL) return MMSYSERR_INVALPARAM;
2963 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2964 return MMSYSERR_INVALHANDLE;
2966 lpWaveInHdr->dwBytesRecorded = 0;
2968 return MMDRV_Message(wmld, WIDM_PREPARE, (DWORD_PTR)lpWaveInHdr, uSize, TRUE);
2971 /**************************************************************************
2972 * waveInUnprepareHeader [WINMM.@]
2974 UINT WINAPI waveInUnprepareHeader(HWAVEIN hWaveIn, WAVEHDR* lpWaveInHdr,
2979 TRACE("(%p, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
2981 if (lpWaveInHdr == NULL) return MMSYSERR_INVALPARAM;
2982 if (!(lpWaveInHdr->dwFlags & WHDR_PREPARED)) {
2983 return MMSYSERR_NOERROR;
2986 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2987 return MMSYSERR_INVALHANDLE;
2989 return MMDRV_Message(wmld, WIDM_UNPREPARE, (DWORD_PTR)lpWaveInHdr, uSize, TRUE);
2992 /**************************************************************************
2993 * waveInAddBuffer [WINMM.@]
2995 UINT WINAPI waveInAddBuffer(HWAVEIN hWaveIn,
2996 WAVEHDR* lpWaveInHdr, UINT uSize)
3000 TRACE("(%p, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
3002 if (lpWaveInHdr == NULL) return MMSYSERR_INVALPARAM;
3003 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
3004 return MMSYSERR_INVALHANDLE;
3006 return MMDRV_Message(wmld, WIDM_ADDBUFFER, (DWORD_PTR)lpWaveInHdr, uSize, TRUE);
3009 /**************************************************************************
3010 * waveInReset [WINMM.@]
3012 UINT WINAPI waveInReset(HWAVEIN hWaveIn)
3016 TRACE("(%p);\n", hWaveIn);
3018 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
3019 return MMSYSERR_INVALHANDLE;
3021 return MMDRV_Message(wmld, WIDM_RESET, 0L, 0L, TRUE);
3024 /**************************************************************************
3025 * waveInStart [WINMM.@]
3027 UINT WINAPI waveInStart(HWAVEIN hWaveIn)
3031 TRACE("(%p);\n", hWaveIn);
3033 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
3034 return MMSYSERR_INVALHANDLE;
3036 return MMDRV_Message(wmld, WIDM_START, 0L, 0L, TRUE);
3039 /**************************************************************************
3040 * waveInStop [WINMM.@]
3042 UINT WINAPI waveInStop(HWAVEIN hWaveIn)
3046 TRACE("(%p);\n", hWaveIn);
3048 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
3049 return MMSYSERR_INVALHANDLE;
3051 return MMDRV_Message(wmld,WIDM_STOP, 0L, 0L, TRUE);
3054 /**************************************************************************
3055 * waveInGetPosition [WINMM.@]
3057 UINT WINAPI waveInGetPosition(HWAVEIN hWaveIn, LPMMTIME lpTime,
3062 TRACE("(%p, %p, %u);\n", hWaveIn, lpTime, uSize);
3064 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
3065 return MMSYSERR_INVALHANDLE;
3067 return MMDRV_Message(wmld, WIDM_GETPOS, (DWORD_PTR)lpTime, uSize, TRUE);
3070 /**************************************************************************
3071 * waveInGetID [WINMM.@]
3073 UINT WINAPI waveInGetID(HWAVEIN hWaveIn, UINT* lpuDeviceID)
3077 TRACE("(%p, %p);\n", hWaveIn, lpuDeviceID);
3079 if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
3081 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
3082 return MMSYSERR_INVALHANDLE;
3084 *lpuDeviceID = wmld->uDeviceID;
3085 return MMSYSERR_NOERROR;
3088 /**************************************************************************
3089 * waveInMessage [WINMM.@]
3091 UINT WINAPI waveInMessage(HWAVEIN hWaveIn, UINT uMessage,
3092 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
3096 TRACE("(%p, %u, %ld, %ld)\n", hWaveIn, uMessage, dwParam1, dwParam2);
3098 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL) {
3099 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, TRUE)) != NULL) {
3100 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
3102 return MMSYSERR_INVALHANDLE;
3106 if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER))
3107 return MMSYSERR_INVALPARAM;
3110 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);