1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
6 * Copyright 1993 Martin Ayotte
7 * 1998-2002 Eric Pouech
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 * 98/9 added Win32 MCI support
27 * 99/4 added midiStream support
28 * 99/9 added support for loadable low level drivers
32 * + it seems that some programs check what's installed in
33 * registry against the value returned by drivers. Wine is
34 * currently broken regarding this point.
35 * + check thread-safeness for MMSYSTEM and WINMM entry points
36 * + unicode entry points are badly supported (would require
37 * moving 32 bit drivers as Unicode as they are supposed to be)
38 * + allow joystick and timer external calls as we do for wave,
46 #define NONAMELESSUNION
47 #define NONAMELESSSTRUCT
56 #include "wine/debug.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(winmm);
60 /* ========================================================================
61 * G L O B A L S E T T I N G S
62 * ========================================================================*/
64 HINSTANCE hWinMM32Instance;
67 static CRITICAL_SECTION_DEBUG critsect_debug =
70 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
71 0, 0, { (DWORD_PTR)(__FILE__ ": WINMM_cs") }
73 CRITICAL_SECTION WINMM_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
75 /**************************************************************************
76 * WINMM_CreateIData [internal]
78 static BOOL WINMM_CreateIData(HINSTANCE hInstDLL)
80 hWinMM32Instance = hInstDLL;
81 psLastEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
85 /**************************************************************************
86 * WINMM_DeleteIData [internal]
88 static void WINMM_DeleteIData(void)
92 /* FIXME: should also free content and resources allocated
93 * inside WINMM_IData */
94 CloseHandle(psLastEvent);
95 DeleteCriticalSection(&WINMM_cs);
98 /******************************************************************
101 const char* WINMM_ErrorToString(MMRESULT error)
103 #define ERR_TO_STR(dev) case dev: return #dev
105 ERR_TO_STR(MMSYSERR_NOERROR);
106 ERR_TO_STR(MMSYSERR_ERROR);
107 ERR_TO_STR(MMSYSERR_BADDEVICEID);
108 ERR_TO_STR(MMSYSERR_NOTENABLED);
109 ERR_TO_STR(MMSYSERR_ALLOCATED);
110 ERR_TO_STR(MMSYSERR_INVALHANDLE);
111 ERR_TO_STR(MMSYSERR_NODRIVER);
112 ERR_TO_STR(MMSYSERR_NOMEM);
113 ERR_TO_STR(MMSYSERR_NOTSUPPORTED);
114 ERR_TO_STR(MMSYSERR_BADERRNUM);
115 ERR_TO_STR(MMSYSERR_INVALFLAG);
116 ERR_TO_STR(MMSYSERR_INVALPARAM);
117 ERR_TO_STR(MMSYSERR_HANDLEBUSY);
118 ERR_TO_STR(MMSYSERR_INVALIDALIAS);
119 ERR_TO_STR(MMSYSERR_BADDB);
120 ERR_TO_STR(MMSYSERR_KEYNOTFOUND);
121 ERR_TO_STR(MMSYSERR_READERROR);
122 ERR_TO_STR(MMSYSERR_WRITEERROR);
123 ERR_TO_STR(MMSYSERR_DELETEERROR);
124 ERR_TO_STR(MMSYSERR_VALNOTFOUND);
125 ERR_TO_STR(MMSYSERR_NODRIVERCB);
126 ERR_TO_STR(WAVERR_BADFORMAT);
127 ERR_TO_STR(WAVERR_STILLPLAYING);
128 ERR_TO_STR(WAVERR_UNPREPARED);
129 ERR_TO_STR(WAVERR_SYNC);
130 ERR_TO_STR(MIDIERR_INVALIDSETUP);
131 ERR_TO_STR(MIDIERR_NODEVICE);
132 ERR_TO_STR(MIDIERR_STILLPLAYING);
133 ERR_TO_STR(MIDIERR_UNPREPARED);
136 return wine_dbg_sprintf("Unknown(0x%08x)", error);
139 /**************************************************************************
140 * DllMain (WINMM.init)
142 * WINMM DLL entry point
145 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID fImpLoad)
147 TRACE("%p 0x%x %p\n", hInstDLL, fdwReason, fImpLoad);
150 case DLL_PROCESS_ATTACH:
151 DisableThreadLibraryCalls(hInstDLL);
153 if (!WINMM_CreateIData(hInstDLL))
156 case DLL_PROCESS_DETACH:
157 /* close all opened MCI drivers */
158 MCI_SendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_WAIT, 0L);
160 /* There's no guarantee the drivers haven't already been unloaded on
165 /* now unload all remaining drivers... */
175 /**************************************************************************
176 * WINMM_CheckCallback [internal]
178 static MMRESULT WINMM_CheckCallback(DWORD_PTR dwCallback, DWORD fdwOpen, BOOL mixer)
180 switch (fdwOpen & CALLBACK_TYPEMASK) {
181 case CALLBACK_NULL: /* dwCallback need not be NULL */
183 case CALLBACK_WINDOW:
184 if (dwCallback && !IsWindow((HWND)dwCallback))
185 return MMSYSERR_INVALPARAM;
188 case CALLBACK_FUNCTION:
189 /* a NULL cb is acceptable since w2k, MMSYSERR_INVALPARAM earlier */
191 return MMSYSERR_INVALFLAG; /* since w2k, MMSYSERR_NOTSUPPORTED earlier */
193 case CALLBACK_THREAD:
195 if (mixer) /* FIXME: mixer supports THREAD+EVENT since w2k */
196 return MMSYSERR_NOTSUPPORTED; /* w9X */
199 WARN("Unknown callback type %d\n", HIWORD(fdwOpen));
201 return MMSYSERR_NOERROR;
204 /**************************************************************************
205 * Mixer devices. New to Win95
208 /**************************************************************************
209 * find out the real mixer ID depending on hmix (depends on dwFlags)
211 static UINT MIXER_GetDev(HMIXEROBJ hmix, DWORD dwFlags, LPWINE_MIXER * lplpwm)
213 LPWINE_MIXER lpwm = NULL;
214 UINT uRet = MMSYSERR_NOERROR;
216 switch (dwFlags & 0xF0000000ul) {
217 case MIXER_OBJECTF_MIXER:
218 lpwm = (LPWINE_MIXER)MMDRV_Get(hmix, MMDRV_MIXER, TRUE);
220 case MIXER_OBJECTF_HMIXER:
221 lpwm = (LPWINE_MIXER)MMDRV_Get(hmix, MMDRV_MIXER, FALSE);
223 case MIXER_OBJECTF_WAVEOUT:
224 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEOUT, TRUE, MMDRV_MIXER);
226 case MIXER_OBJECTF_HWAVEOUT:
227 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEOUT, FALSE, MMDRV_MIXER);
229 case MIXER_OBJECTF_WAVEIN:
230 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEIN, TRUE, MMDRV_MIXER);
232 case MIXER_OBJECTF_HWAVEIN:
233 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEIN, FALSE, MMDRV_MIXER);
235 case MIXER_OBJECTF_MIDIOUT:
236 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIOUT, TRUE, MMDRV_MIXER);
238 case MIXER_OBJECTF_HMIDIOUT:
239 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIOUT, FALSE, MMDRV_MIXER);
241 case MIXER_OBJECTF_MIDIIN:
242 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIIN, TRUE, MMDRV_MIXER);
244 case MIXER_OBJECTF_HMIDIIN:
245 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIIN, FALSE, MMDRV_MIXER);
247 case MIXER_OBJECTF_AUX:
248 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_AUX, TRUE, MMDRV_MIXER);
251 WARN("Unsupported flag (%08lx)\n", dwFlags & 0xF0000000ul);
253 uRet = MMSYSERR_INVALFLAG;
257 if (lpwm == 0 && uRet == MMSYSERR_NOERROR)
258 uRet = MMSYSERR_INVALPARAM;
262 /**************************************************************************
263 * mixerGetNumDevs [WINMM.@]
265 UINT WINAPI mixerGetNumDevs(void)
267 return MMDRV_GetNum(MMDRV_MIXER);
270 /**************************************************************************
271 * mixerGetDevCapsA [WINMM.@]
273 UINT WINAPI mixerGetDevCapsA(UINT_PTR uDeviceID, LPMIXERCAPSA lpCaps, UINT uSize)
278 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
280 ret = mixerGetDevCapsW(uDeviceID, &micW, sizeof(micW));
282 if (ret == MMSYSERR_NOERROR) {
284 micA.wMid = micW.wMid;
285 micA.wPid = micW.wPid;
286 micA.vDriverVersion = micW.vDriverVersion;
287 WideCharToMultiByte( CP_ACP, 0, micW.szPname, -1, micA.szPname,
288 sizeof(micA.szPname), NULL, NULL );
289 micA.fdwSupport = micW.fdwSupport;
290 micA.cDestinations = micW.cDestinations;
291 memcpy(lpCaps, &micA, min(uSize, sizeof(micA)));
296 /**************************************************************************
297 * mixerGetDevCapsW [WINMM.@]
299 UINT WINAPI mixerGetDevCapsW(UINT_PTR uDeviceID, LPMIXERCAPSW lpCaps, UINT uSize)
303 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
305 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_MIXER, TRUE)) == NULL)
306 return MMSYSERR_BADDEVICEID;
308 return MMDRV_Message(wmld, MXDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize);
311 static void CALLBACK MIXER_WCallback(HMIXEROBJ hmx, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam, DWORD_PTR param2)
313 HWND hWnd = (HWND)dwInstance;
318 PostMessageW(hWnd, uMsg, (WPARAM)hmx, (LPARAM)dwParam);
321 /**************************************************************************
322 * mixerOpen [WINMM.@]
324 UINT WINAPI mixerOpen(LPHMIXER lphMix, UINT uDeviceID, DWORD_PTR dwCallback,
325 DWORD_PTR dwInstance, DWORD fdwOpen)
332 TRACE("(%p, %d, %08lx, %08lx, %08x)\n",
333 lphMix, uDeviceID, dwCallback, dwInstance, fdwOpen);
335 dwRet = WINMM_CheckCallback(dwCallback, fdwOpen, TRUE);
336 if (dwRet != MMSYSERR_NOERROR)
339 mod.dwCallback = (DWORD_PTR)MIXER_WCallback;
340 if ((fdwOpen & CALLBACK_TYPEMASK) == CALLBACK_WINDOW)
341 mod.dwInstance = dwCallback;
345 /* We're remapping to CALLBACK_FUNCTION because that's what old winmm is
346 * documented to do when opening the mixer driver.
347 * FIXME: Native supports CALLBACK_EVENT + CALLBACK_THREAD flags since w2k.
348 * FIXME: The non ALSA drivers ignore callback requests - bug.
351 wmld = MMDRV_Alloc(sizeof(WINE_MIXER), MMDRV_MIXER, &hMix, &fdwOpen,
352 &dwCallback, &dwInstance);
353 wmld->uDeviceID = uDeviceID;
356 dwRet = MMDRV_Open(wmld, MXDM_OPEN, (DWORD_PTR)&mod, CALLBACK_FUNCTION);
358 if (dwRet != MMSYSERR_NOERROR) {
359 MMDRV_Free(hMix, wmld);
362 if (lphMix) *lphMix = hMix;
363 TRACE("=> %d hMixer=%p\n", dwRet, hMix);
368 /**************************************************************************
369 * mixerClose [WINMM.@]
371 UINT WINAPI mixerClose(HMIXER hMix)
376 TRACE("(%p)\n", hMix);
378 if ((wmld = MMDRV_Get(hMix, MMDRV_MIXER, FALSE)) == NULL) return MMSYSERR_INVALHANDLE;
380 dwRet = MMDRV_Close(wmld, MXDM_CLOSE);
381 MMDRV_Free(hMix, wmld);
386 /**************************************************************************
387 * mixerGetID [WINMM.@]
389 UINT WINAPI mixerGetID(HMIXEROBJ hmix, LPUINT lpid, DWORD fdwID)
392 UINT uRet = MMSYSERR_NOERROR;
394 TRACE("(%p %p %08x)\n", hmix, lpid, fdwID);
396 if ((uRet = MIXER_GetDev(hmix, fdwID, &lpwm)) != MMSYSERR_NOERROR)
400 *lpid = lpwm->mld.uDeviceID;
405 /**************************************************************************
406 * mixerGetControlDetailsW [WINMM.@]
408 UINT WINAPI mixerGetControlDetailsW(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcdW,
412 UINT uRet = MMSYSERR_NOERROR;
414 TRACE("(%p, %p, %08x)\n", hmix, lpmcdW, fdwDetails);
416 if ((uRet = MIXER_GetDev(hmix, fdwDetails, &lpwm)) != MMSYSERR_NOERROR)
419 if (lpmcdW == NULL || lpmcdW->cbStruct != sizeof(*lpmcdW))
420 return MMSYSERR_INVALPARAM;
422 return MMDRV_Message(&lpwm->mld, MXDM_GETCONTROLDETAILS, (DWORD_PTR)lpmcdW,
426 /**************************************************************************
427 * mixerGetControlDetailsA [WINMM.@]
429 UINT WINAPI mixerGetControlDetailsA(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcdA,
432 DWORD ret = MMSYSERR_NOTENABLED;
434 TRACE("(%p, %p, %08x)\n", hmix, lpmcdA, fdwDetails);
436 if (lpmcdA == NULL || lpmcdA->cbStruct != sizeof(*lpmcdA))
437 return MMSYSERR_INVALPARAM;
439 switch (fdwDetails & MIXER_GETCONTROLDETAILSF_QUERYMASK) {
440 case MIXER_GETCONTROLDETAILSF_VALUE:
441 /* can safely use A structure as it is, no string inside */
442 ret = mixerGetControlDetailsW(hmix, lpmcdA, fdwDetails);
444 case MIXER_GETCONTROLDETAILSF_LISTTEXT:
446 MIXERCONTROLDETAILS_LISTTEXTA *pDetailsA = lpmcdA->paDetails;
447 MIXERCONTROLDETAILS_LISTTEXTW *pDetailsW;
448 int size = max(1, lpmcdA->cChannels) * sizeof(MIXERCONTROLDETAILS_LISTTEXTW);
451 if (lpmcdA->u.cMultipleItems != 0) {
452 size *= lpmcdA->u.cMultipleItems;
454 pDetailsW = HeapAlloc(GetProcessHeap(), 0, size);
455 lpmcdA->paDetails = pDetailsW;
456 lpmcdA->cbDetails = sizeof(MIXERCONTROLDETAILS_LISTTEXTW);
457 /* set up lpmcd->paDetails */
458 ret = mixerGetControlDetailsW(hmix, lpmcdA, fdwDetails);
459 /* copy from lpmcd->paDetails back to paDetailsW; */
460 if (ret == MMSYSERR_NOERROR) {
461 for (i = 0; i < lpmcdA->u.cMultipleItems * lpmcdA->cChannels; i++) {
462 pDetailsA->dwParam1 = pDetailsW->dwParam1;
463 pDetailsA->dwParam2 = pDetailsW->dwParam2;
464 WideCharToMultiByte( CP_ACP, 0, pDetailsW->szName, -1,
466 sizeof(pDetailsA->szName), NULL, NULL );
470 pDetailsA -= lpmcdA->u.cMultipleItems * lpmcdA->cChannels;
471 pDetailsW -= lpmcdA->u.cMultipleItems * lpmcdA->cChannels;
473 HeapFree(GetProcessHeap(), 0, pDetailsW);
474 lpmcdA->paDetails = pDetailsA;
475 lpmcdA->cbDetails = sizeof(MIXERCONTROLDETAILS_LISTTEXTA);
479 ERR("Unsupported fdwDetails=0x%08x\n", fdwDetails);
485 /**************************************************************************
486 * mixerGetLineControlsA [WINMM.@]
488 UINT WINAPI mixerGetLineControlsA(HMIXEROBJ hmix, LPMIXERLINECONTROLSA lpmlcA,
491 MIXERLINECONTROLSW mlcW;
495 TRACE("(%p, %p, %08x)\n", hmix, lpmlcA, fdwControls);
497 if (lpmlcA == NULL || lpmlcA->cbStruct != sizeof(*lpmlcA) ||
498 lpmlcA->cbmxctrl != sizeof(MIXERCONTROLA))
499 return MMSYSERR_INVALPARAM;
501 mlcW.cbStruct = sizeof(mlcW);
502 mlcW.dwLineID = lpmlcA->dwLineID;
503 mlcW.u.dwControlID = lpmlcA->u.dwControlID;
504 mlcW.u.dwControlType = lpmlcA->u.dwControlType;
506 /* Debugging on Windows shows for MIXER_GETLINECONTROLSF_ONEBYTYPE only,
507 the control count is assumed to be 1 - This is relied upon by a game,
509 if (MIXER_GETLINECONTROLSF_ONEBYTYPE == (fdwControls & MIXER_GETLINECONTROLSF_QUERYMASK)) {
512 mlcW.cControls = lpmlcA->cControls;
514 mlcW.cbmxctrl = sizeof(MIXERCONTROLW);
515 mlcW.pamxctrl = HeapAlloc(GetProcessHeap(), 0,
516 mlcW.cControls * mlcW.cbmxctrl);
518 ret = mixerGetLineControlsW(hmix, &mlcW, fdwControls);
520 if (ret == MMSYSERR_NOERROR) {
521 lpmlcA->dwLineID = mlcW.dwLineID;
522 lpmlcA->u.dwControlID = mlcW.u.dwControlID;
523 lpmlcA->u.dwControlType = mlcW.u.dwControlType;
525 for (i = 0; i < mlcW.cControls; i++) {
526 lpmlcA->pamxctrl[i].cbStruct = sizeof(MIXERCONTROLA);
527 lpmlcA->pamxctrl[i].dwControlID = mlcW.pamxctrl[i].dwControlID;
528 lpmlcA->pamxctrl[i].dwControlType = mlcW.pamxctrl[i].dwControlType;
529 lpmlcA->pamxctrl[i].fdwControl = mlcW.pamxctrl[i].fdwControl;
530 lpmlcA->pamxctrl[i].cMultipleItems = mlcW.pamxctrl[i].cMultipleItems;
531 WideCharToMultiByte( CP_ACP, 0, mlcW.pamxctrl[i].szShortName, -1,
532 lpmlcA->pamxctrl[i].szShortName,
533 sizeof(lpmlcA->pamxctrl[i].szShortName), NULL, NULL );
534 WideCharToMultiByte( CP_ACP, 0, mlcW.pamxctrl[i].szName, -1,
535 lpmlcA->pamxctrl[i].szName,
536 sizeof(lpmlcA->pamxctrl[i].szName), NULL, NULL );
537 /* sizeof(lpmlcA->pamxctrl[i].Bounds) ==
538 * sizeof(mlcW.pamxctrl[i].Bounds) */
539 memcpy(&lpmlcA->pamxctrl[i].Bounds, &mlcW.pamxctrl[i].Bounds,
540 sizeof(mlcW.pamxctrl[i].Bounds));
541 /* sizeof(lpmlcA->pamxctrl[i].Metrics) ==
542 * sizeof(mlcW.pamxctrl[i].Metrics) */
543 memcpy(&lpmlcA->pamxctrl[i].Metrics, &mlcW.pamxctrl[i].Metrics,
544 sizeof(mlcW.pamxctrl[i].Metrics));
548 HeapFree(GetProcessHeap(), 0, mlcW.pamxctrl);
553 /**************************************************************************
554 * mixerGetLineControlsW [WINMM.@]
556 UINT WINAPI mixerGetLineControlsW(HMIXEROBJ hmix, LPMIXERLINECONTROLSW lpmlcW,
560 UINT uRet = MMSYSERR_NOERROR;
562 TRACE("(%p, %p, %08x)\n", hmix, lpmlcW, fdwControls);
564 if ((uRet = MIXER_GetDev(hmix, fdwControls, &lpwm)) != MMSYSERR_NOERROR)
567 if (lpmlcW == NULL || lpmlcW->cbStruct != sizeof(*lpmlcW))
568 return MMSYSERR_INVALPARAM;
570 return MMDRV_Message(&lpwm->mld, MXDM_GETLINECONTROLS, (DWORD_PTR)lpmlcW,
574 /**************************************************************************
575 * mixerGetLineInfoW [WINMM.@]
577 UINT WINAPI mixerGetLineInfoW(HMIXEROBJ hmix, LPMIXERLINEW lpmliW, DWORD fdwInfo)
580 UINT uRet = MMSYSERR_NOERROR;
582 TRACE("(%p, %p, %08x)\n", hmix, lpmliW, fdwInfo);
584 if ((uRet = MIXER_GetDev(hmix, fdwInfo, &lpwm)) != MMSYSERR_NOERROR)
587 return MMDRV_Message(&lpwm->mld, MXDM_GETLINEINFO, (DWORD_PTR)lpmliW,
591 /**************************************************************************
592 * mixerGetLineInfoA [WINMM.@]
594 UINT WINAPI mixerGetLineInfoA(HMIXEROBJ hmix, LPMIXERLINEA lpmliA,
600 TRACE("(%p, %p, %08x)\n", hmix, lpmliA, fdwInfo);
602 if (lpmliA == NULL || lpmliA->cbStruct != sizeof(*lpmliA))
603 return MMSYSERR_INVALPARAM;
605 mliW.cbStruct = sizeof(mliW);
606 switch (fdwInfo & MIXER_GETLINEINFOF_QUERYMASK) {
607 case MIXER_GETLINEINFOF_COMPONENTTYPE:
608 mliW.dwComponentType = lpmliA->dwComponentType;
610 case MIXER_GETLINEINFOF_DESTINATION:
611 mliW.dwDestination = lpmliA->dwDestination;
613 case MIXER_GETLINEINFOF_LINEID:
614 mliW.dwLineID = lpmliA->dwLineID;
616 case MIXER_GETLINEINFOF_SOURCE:
617 mliW.dwDestination = lpmliA->dwDestination;
618 mliW.dwSource = lpmliA->dwSource;
620 case MIXER_GETLINEINFOF_TARGETTYPE:
621 mliW.Target.dwType = lpmliA->Target.dwType;
622 mliW.Target.wMid = lpmliA->Target.wMid;
623 mliW.Target.wPid = lpmliA->Target.wPid;
624 mliW.Target.vDriverVersion = lpmliA->Target.vDriverVersion;
625 MultiByteToWideChar( CP_ACP, 0, lpmliA->Target.szPname, -1, mliW.Target.szPname, sizeof(mliW.Target.szPname)/sizeof(WCHAR));
628 WARN("Unsupported fdwControls=0x%08x\n", fdwInfo);
629 return MMSYSERR_INVALFLAG;
632 ret = mixerGetLineInfoW(hmix, &mliW, fdwInfo);
634 if(ret == MMSYSERR_NOERROR)
636 lpmliA->dwDestination = mliW.dwDestination;
637 lpmliA->dwSource = mliW.dwSource;
638 lpmliA->dwLineID = mliW.dwLineID;
639 lpmliA->fdwLine = mliW.fdwLine;
640 lpmliA->dwUser = mliW.dwUser;
641 lpmliA->dwComponentType = mliW.dwComponentType;
642 lpmliA->cChannels = mliW.cChannels;
643 lpmliA->cConnections = mliW.cConnections;
644 lpmliA->cControls = mliW.cControls;
645 WideCharToMultiByte( CP_ACP, 0, mliW.szShortName, -1, lpmliA->szShortName,
646 sizeof(lpmliA->szShortName), NULL, NULL);
647 WideCharToMultiByte( CP_ACP, 0, mliW.szName, -1, lpmliA->szName,
648 sizeof(lpmliA->szName), NULL, NULL );
649 lpmliA->Target.dwType = mliW.Target.dwType;
650 lpmliA->Target.dwDeviceID = mliW.Target.dwDeviceID;
651 lpmliA->Target.wMid = mliW.Target.wMid;
652 lpmliA->Target.wPid = mliW.Target.wPid;
653 lpmliA->Target.vDriverVersion = mliW.Target.vDriverVersion;
654 WideCharToMultiByte( CP_ACP, 0, mliW.Target.szPname, -1, lpmliA->Target.szPname,
655 sizeof(lpmliA->Target.szPname), NULL, NULL );
660 /**************************************************************************
661 * mixerSetControlDetails [WINMM.@]
663 UINT WINAPI mixerSetControlDetails(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcd,
667 UINT uRet = MMSYSERR_NOERROR;
669 TRACE("(%p, %p, %08x)\n", hmix, lpmcd, fdwDetails);
671 if ((uRet = MIXER_GetDev(hmix, fdwDetails, &lpwm)) != MMSYSERR_NOERROR)
674 return MMDRV_Message(&lpwm->mld, MXDM_SETCONTROLDETAILS, (DWORD_PTR)lpmcd,
678 /**************************************************************************
679 * mixerMessage [WINMM.@]
681 DWORD WINAPI mixerMessage(HMIXER hmix, UINT uMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
685 TRACE("(%p, %d, %08lx, %08lx): semi-stub?\n",
686 hmix, uMsg, dwParam1, dwParam2);
688 if ((wmld = MMDRV_Get(hmix, MMDRV_MIXER, FALSE)) == NULL)
689 return MMSYSERR_INVALHANDLE;
691 return MMDRV_Message(wmld, uMsg, dwParam1, dwParam2);
694 /**************************************************************************
695 * auxGetNumDevs [WINMM.@]
697 UINT WINAPI auxGetNumDevs(void)
699 return MMDRV_GetNum(MMDRV_AUX);
702 /**************************************************************************
703 * auxGetDevCapsW [WINMM.@]
705 UINT WINAPI auxGetDevCapsW(UINT_PTR uDeviceID, LPAUXCAPSW lpCaps, UINT uSize)
709 TRACE("(%04lX, %p, %d) !\n", uDeviceID, lpCaps, uSize);
711 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
713 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
714 return MMSYSERR_BADDEVICEID;
715 return MMDRV_Message(wmld, AUXDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize);
718 /**************************************************************************
719 * auxGetDevCapsA [WINMM.@]
721 UINT WINAPI auxGetDevCapsA(UINT_PTR uDeviceID, LPAUXCAPSA lpCaps, UINT uSize)
726 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
728 ret = auxGetDevCapsW(uDeviceID, &acW, sizeof(acW));
730 if (ret == MMSYSERR_NOERROR) {
734 acA.vDriverVersion = acW.vDriverVersion;
735 WideCharToMultiByte( CP_ACP, 0, acW.szPname, -1, acA.szPname,
736 sizeof(acA.szPname), NULL, NULL );
737 acA.wTechnology = acW.wTechnology;
738 acA.dwSupport = acW.dwSupport;
739 memcpy(lpCaps, &acA, min(uSize, sizeof(acA)));
744 /**************************************************************************
745 * auxGetVolume [WINMM.@]
747 UINT WINAPI auxGetVolume(UINT uDeviceID, DWORD* lpdwVolume)
751 TRACE("(%04X, %p) !\n", uDeviceID, lpdwVolume);
753 if ((wmld = MMDRV_Get((HANDLE)(DWORD_PTR)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
754 return MMSYSERR_INVALHANDLE;
755 return MMDRV_Message(wmld, AUXDM_GETVOLUME, (DWORD_PTR)lpdwVolume, 0L);
758 /**************************************************************************
759 * auxSetVolume [WINMM.@]
761 UINT WINAPI auxSetVolume(UINT uDeviceID, DWORD dwVolume)
765 TRACE("(%04X, %u) !\n", uDeviceID, dwVolume);
767 if ((wmld = MMDRV_Get((HANDLE)(DWORD_PTR)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
768 return MMSYSERR_INVALHANDLE;
769 return MMDRV_Message(wmld, AUXDM_SETVOLUME, dwVolume, 0L);
772 /**************************************************************************
773 * auxOutMessage [WINMM.@]
775 UINT WINAPI auxOutMessage(UINT uDeviceID, UINT uMessage, DWORD_PTR dw1, DWORD_PTR dw2)
779 if ((wmld = MMDRV_Get((HANDLE)(DWORD_PTR)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
780 return MMSYSERR_INVALHANDLE;
782 return MMDRV_Message(wmld, uMessage, dw1, dw2);
785 /**************************************************************************
786 * midiOutGetNumDevs [WINMM.@]
788 UINT WINAPI midiOutGetNumDevs(void)
790 return MMDRV_GetNum(MMDRV_MIDIOUT);
793 /**************************************************************************
794 * midiOutGetDevCapsW [WINMM.@]
796 UINT WINAPI midiOutGetDevCapsW(UINT_PTR uDeviceID, LPMIDIOUTCAPSW lpCaps,
801 TRACE("(%lu, %p, %u);\n", uDeviceID, lpCaps, uSize);
803 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
805 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_MIDIOUT, TRUE)) == NULL)
806 return MMSYSERR_BADDEVICEID;
808 return MMDRV_Message(wmld, MODM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize);
811 /**************************************************************************
812 * midiOutGetDevCapsA [WINMM.@]
814 UINT WINAPI midiOutGetDevCapsA(UINT_PTR uDeviceID, LPMIDIOUTCAPSA lpCaps,
820 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
822 ret = midiOutGetDevCapsW(uDeviceID, &mocW, sizeof(mocW));
824 if (ret == MMSYSERR_NOERROR) {
826 mocA.wMid = mocW.wMid;
827 mocA.wPid = mocW.wPid;
828 mocA.vDriverVersion = mocW.vDriverVersion;
829 WideCharToMultiByte( CP_ACP, 0, mocW.szPname, -1, mocA.szPname,
830 sizeof(mocA.szPname), NULL, NULL );
831 mocA.wTechnology = mocW.wTechnology;
832 mocA.wVoices = mocW.wVoices;
833 mocA.wNotes = mocW.wNotes;
834 mocA.wChannelMask = mocW.wChannelMask;
835 mocA.dwSupport = mocW.dwSupport;
836 memcpy(lpCaps, &mocA, min(uSize, sizeof(mocA)));
841 /**************************************************************************
842 * midiOutGetErrorTextA [WINMM.@]
843 * midiInGetErrorTextA [WINMM.@]
845 UINT WINAPI midiOutGetErrorTextA(UINT uError, LPSTR lpText, UINT uSize)
849 if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
850 else if (uSize == 0) ret = MMSYSERR_NOERROR;
853 LPWSTR xstr = HeapAlloc(GetProcessHeap(), 0, uSize * sizeof(WCHAR));
854 if (!xstr) ret = MMSYSERR_NOMEM;
857 ret = midiOutGetErrorTextW(uError, xstr, uSize);
858 if (ret == MMSYSERR_NOERROR)
859 WideCharToMultiByte(CP_ACP, 0, xstr, -1, lpText, uSize, NULL, NULL);
860 HeapFree(GetProcessHeap(), 0, xstr);
866 /**************************************************************************
867 * midiOutGetErrorTextW [WINMM.@]
868 * midiInGetErrorTextW [WINMM.@]
870 UINT WINAPI midiOutGetErrorTextW(UINT uError, LPWSTR lpText, UINT uSize)
872 UINT ret = MMSYSERR_BADERRNUM;
874 if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
875 else if (uSize == 0) ret = MMSYSERR_NOERROR;
877 /* test has been removed because MMSYSERR_BASE is 0, and gcc did emit
878 * a warning for the test was always true */
879 (/*uError >= MMSYSERR_BASE && */ uError <= MMSYSERR_LASTERROR) ||
880 (uError >= MIDIERR_BASE && uError <= MIDIERR_LASTERROR)) {
881 if (LoadStringW(hWinMM32Instance, uError, lpText, uSize) > 0) {
882 ret = MMSYSERR_NOERROR;
888 /**************************************************************************
889 * MIDI_OutAlloc [internal]
891 static LPWINE_MIDI MIDI_OutAlloc(HMIDIOUT* lphMidiOut, DWORD_PTR* lpdwCallback,
892 DWORD_PTR* lpdwInstance, LPDWORD lpdwFlags,
893 DWORD cIDs, MIDIOPENSTRMID* lpIDs)
899 size = sizeof(WINE_MIDI) + (cIDs ? (cIDs-1) : 0) * sizeof(MIDIOPENSTRMID);
901 lpwm = (LPWINE_MIDI)MMDRV_Alloc(size, MMDRV_MIDIOUT, &hMidiOut, lpdwFlags,
902 lpdwCallback, lpdwInstance);
903 *lphMidiOut = hMidiOut;
906 lpwm->mod.hMidi = hMidiOut;
907 lpwm->mod.dwCallback = *lpdwCallback;
908 lpwm->mod.dwInstance = *lpdwInstance;
909 lpwm->mod.dnDevNode = 0;
910 lpwm->mod.cIds = cIDs;
912 memcpy(&(lpwm->mod.rgIds), lpIDs, cIDs * sizeof(MIDIOPENSTRMID));
917 /**************************************************************************
918 * midiOutOpen [WINMM.@]
920 UINT WINAPI midiOutOpen(LPHMIDIOUT lphMidiOut, UINT uDeviceID,
921 DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD dwFlags)
927 TRACE("(%p, %d, %08lX, %08lX, %08X);\n",
928 lphMidiOut, uDeviceID, dwCallback, dwInstance, dwFlags);
930 if (lphMidiOut != NULL) *lphMidiOut = 0;
932 dwRet = WINMM_CheckCallback(dwCallback, dwFlags, FALSE);
933 if (dwRet != MMSYSERR_NOERROR)
936 lpwm = MIDI_OutAlloc(&hMidiOut, &dwCallback, &dwInstance, &dwFlags, 0, NULL);
939 return MMSYSERR_NOMEM;
941 lpwm->mld.uDeviceID = uDeviceID;
943 dwRet = MMDRV_Open((LPWINE_MLD)lpwm, MODM_OPEN, (DWORD_PTR)&lpwm->mod, dwFlags);
945 if (dwRet != MMSYSERR_NOERROR) {
946 MMDRV_Free(hMidiOut, (LPWINE_MLD)lpwm);
950 if (lphMidiOut) *lphMidiOut = hMidiOut;
951 TRACE("=> %d hMidi=%p\n", dwRet, hMidiOut);
956 /**************************************************************************
957 * midiOutClose [WINMM.@]
959 UINT WINAPI midiOutClose(HMIDIOUT hMidiOut)
964 TRACE("(%p)\n", hMidiOut);
966 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
967 return MMSYSERR_INVALHANDLE;
969 dwRet = MMDRV_Close(wmld, MODM_CLOSE);
970 MMDRV_Free(hMidiOut, wmld);
975 /**************************************************************************
976 * midiOutPrepareHeader [WINMM.@]
978 UINT WINAPI midiOutPrepareHeader(HMIDIOUT hMidiOut,
979 MIDIHDR* lpMidiOutHdr, UINT uSize)
983 TRACE("(%p, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
985 if (lpMidiOutHdr == NULL || uSize < offsetof(MIDIHDR,dwOffset))
986 return MMSYSERR_INVALPARAM;
988 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
989 return MMSYSERR_INVALHANDLE;
990 /* FIXME: detect MIDIStream handles and enforce 64KB buffer limit on those */
992 return MMDRV_Message(wmld, MODM_PREPARE, (DWORD_PTR)lpMidiOutHdr, uSize);
995 /**************************************************************************
996 * midiOutUnprepareHeader [WINMM.@]
998 UINT WINAPI midiOutUnprepareHeader(HMIDIOUT hMidiOut,
999 MIDIHDR* lpMidiOutHdr, UINT uSize)
1003 TRACE("(%p, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
1005 if (lpMidiOutHdr == NULL || uSize < offsetof(MIDIHDR,dwOffset))
1006 return MMSYSERR_INVALPARAM;
1008 if (!(lpMidiOutHdr->dwFlags & MHDR_PREPARED)) {
1009 return MMSYSERR_NOERROR;
1012 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1013 return MMSYSERR_INVALHANDLE;
1015 return MMDRV_Message(wmld, MODM_UNPREPARE, (DWORD_PTR)lpMidiOutHdr, uSize);
1018 /**************************************************************************
1019 * midiOutShortMsg [WINMM.@]
1021 UINT WINAPI midiOutShortMsg(HMIDIOUT hMidiOut, DWORD dwMsg)
1025 TRACE("(%p, %08X)\n", hMidiOut, dwMsg);
1027 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1028 return MMSYSERR_INVALHANDLE;
1030 return MMDRV_Message(wmld, MODM_DATA, dwMsg, 0L);
1033 /**************************************************************************
1034 * midiOutLongMsg [WINMM.@]
1036 UINT WINAPI midiOutLongMsg(HMIDIOUT hMidiOut,
1037 MIDIHDR* lpMidiOutHdr, UINT uSize)
1041 TRACE("(%p, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
1043 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1044 return MMSYSERR_INVALHANDLE;
1046 return MMDRV_Message(wmld, MODM_LONGDATA, (DWORD_PTR)lpMidiOutHdr, uSize);
1049 /**************************************************************************
1050 * midiOutReset [WINMM.@]
1052 UINT WINAPI midiOutReset(HMIDIOUT hMidiOut)
1056 TRACE("(%p)\n", hMidiOut);
1058 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1059 return MMSYSERR_INVALHANDLE;
1061 return MMDRV_Message(wmld, MODM_RESET, 0L, 0L);
1064 /**************************************************************************
1065 * midiOutGetVolume [WINMM.@]
1067 UINT WINAPI midiOutGetVolume(HMIDIOUT hMidiOut, DWORD* lpdwVolume)
1071 TRACE("(%p, %p);\n", hMidiOut, lpdwVolume);
1073 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, TRUE)) == NULL)
1074 return MMSYSERR_INVALHANDLE;
1076 return MMDRV_Message(wmld, MODM_GETVOLUME, (DWORD_PTR)lpdwVolume, 0L);
1079 /**************************************************************************
1080 * midiOutSetVolume [WINMM.@]
1082 UINT WINAPI midiOutSetVolume(HMIDIOUT hMidiOut, DWORD dwVolume)
1086 TRACE("(%p, %d);\n", hMidiOut, dwVolume);
1088 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, TRUE)) == NULL)
1089 return MMSYSERR_INVALHANDLE;
1091 return MMDRV_Message(wmld, MODM_SETVOLUME, dwVolume, 0L);
1094 /**************************************************************************
1095 * midiOutCachePatches [WINMM.@]
1097 UINT WINAPI midiOutCachePatches(HMIDIOUT hMidiOut, UINT uBank,
1098 WORD* lpwPatchArray, UINT uFlags)
1100 /* not really necessary to support this */
1101 FIXME("not supported yet\n");
1102 return MMSYSERR_NOTSUPPORTED;
1105 /**************************************************************************
1106 * midiOutCacheDrumPatches [WINMM.@]
1108 UINT WINAPI midiOutCacheDrumPatches(HMIDIOUT hMidiOut, UINT uPatch,
1109 WORD* lpwKeyArray, UINT uFlags)
1111 FIXME("not supported yet\n");
1112 return MMSYSERR_NOTSUPPORTED;
1115 /**************************************************************************
1116 * midiOutGetID [WINMM.@]
1118 UINT WINAPI midiOutGetID(HMIDIOUT hMidiOut, UINT* lpuDeviceID)
1122 TRACE("(%p, %p)\n", hMidiOut, lpuDeviceID);
1124 if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
1125 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1126 return MMSYSERR_INVALHANDLE;
1128 *lpuDeviceID = wmld->uDeviceID;
1129 return MMSYSERR_NOERROR;
1132 /**************************************************************************
1133 * midiOutMessage [WINMM.@]
1135 UINT WINAPI midiOutMessage(HMIDIOUT hMidiOut, UINT uMessage,
1136 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1140 TRACE("(%p, %04X, %08lX, %08lX)\n", hMidiOut, uMessage, dwParam1, dwParam2);
1142 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL) {
1144 if (uMessage == 0x0001) {
1145 *(LPDWORD)dwParam1 = 1;
1148 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, TRUE)) != NULL) {
1149 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
1151 return MMSYSERR_INVALHANDLE;
1157 FIXME("can't handle OPEN or CLOSE message!\n");
1158 return MMSYSERR_NOTSUPPORTED;
1160 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2);
1163 /**************************************************************************
1164 * midiInGetNumDevs [WINMM.@]
1166 UINT WINAPI midiInGetNumDevs(void)
1168 return MMDRV_GetNum(MMDRV_MIDIIN);
1171 /**************************************************************************
1172 * midiInGetDevCapsW [WINMM.@]
1174 UINT WINAPI midiInGetDevCapsW(UINT_PTR uDeviceID, LPMIDIINCAPSW lpCaps, UINT uSize)
1178 TRACE("(%ld, %p, %d);\n", uDeviceID, lpCaps, uSize);
1180 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
1182 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_MIDIIN, TRUE)) == NULL)
1183 return MMSYSERR_BADDEVICEID;
1185 return MMDRV_Message(wmld, MIDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize);
1188 /**************************************************************************
1189 * midiInGetDevCapsA [WINMM.@]
1191 UINT WINAPI midiInGetDevCapsA(UINT_PTR uDeviceID, LPMIDIINCAPSA lpCaps, UINT uSize)
1196 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
1198 ret = midiInGetDevCapsW(uDeviceID, &micW, sizeof(micW));
1200 if (ret == MMSYSERR_NOERROR) {
1202 micA.wMid = micW.wMid;
1203 micA.wPid = micW.wPid;
1204 micA.vDriverVersion = micW.vDriverVersion;
1205 WideCharToMultiByte( CP_ACP, 0, micW.szPname, -1, micA.szPname,
1206 sizeof(micA.szPname), NULL, NULL );
1207 micA.dwSupport = micW.dwSupport;
1208 memcpy(lpCaps, &micA, min(uSize, sizeof(micA)));
1213 /**************************************************************************
1214 * midiInOpen [WINMM.@]
1216 UINT WINAPI midiInOpen(HMIDIIN* lphMidiIn, UINT uDeviceID,
1217 DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD dwFlags)
1223 TRACE("(%p, %d, %08lX, %08lX, %08X);\n",
1224 lphMidiIn, uDeviceID, dwCallback, dwInstance, dwFlags);
1226 if (lphMidiIn != NULL) *lphMidiIn = 0;
1228 dwRet = WINMM_CheckCallback(dwCallback, dwFlags, FALSE);
1229 if (dwRet != MMSYSERR_NOERROR)
1232 lpwm = (LPWINE_MIDI)MMDRV_Alloc(sizeof(WINE_MIDI), MMDRV_MIDIIN, &hMidiIn,
1233 &dwFlags, &dwCallback, &dwInstance);
1236 return MMSYSERR_NOMEM;
1238 lpwm->mod.hMidi = hMidiIn;
1239 lpwm->mod.dwCallback = dwCallback;
1240 lpwm->mod.dwInstance = dwInstance;
1242 lpwm->mld.uDeviceID = uDeviceID;
1243 dwRet = MMDRV_Open(&lpwm->mld, MIDM_OPEN, (DWORD_PTR)&lpwm->mod, dwFlags);
1245 if (dwRet != MMSYSERR_NOERROR) {
1246 MMDRV_Free(hMidiIn, &lpwm->mld);
1249 if (lphMidiIn != NULL) *lphMidiIn = hMidiIn;
1250 TRACE("=> %d hMidi=%p\n", dwRet, hMidiIn);
1255 /**************************************************************************
1256 * midiInClose [WINMM.@]
1258 UINT WINAPI midiInClose(HMIDIIN hMidiIn)
1263 TRACE("(%p)\n", hMidiIn);
1265 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1266 return MMSYSERR_INVALHANDLE;
1268 dwRet = MMDRV_Close(wmld, MIDM_CLOSE);
1269 MMDRV_Free(hMidiIn, wmld);
1273 /**************************************************************************
1274 * midiInPrepareHeader [WINMM.@]
1276 UINT WINAPI midiInPrepareHeader(HMIDIIN hMidiIn,
1277 MIDIHDR* lpMidiInHdr, UINT uSize)
1281 TRACE("(%p, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
1283 if (lpMidiInHdr == NULL || uSize < offsetof(MIDIHDR,dwOffset))
1284 return MMSYSERR_INVALPARAM;
1286 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1287 return MMSYSERR_INVALHANDLE;
1289 return MMDRV_Message(wmld, MIDM_PREPARE, (DWORD_PTR)lpMidiInHdr, uSize);
1292 /**************************************************************************
1293 * midiInUnprepareHeader [WINMM.@]
1295 UINT WINAPI midiInUnprepareHeader(HMIDIIN hMidiIn,
1296 MIDIHDR* lpMidiInHdr, UINT uSize)
1300 TRACE("(%p, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
1302 if (lpMidiInHdr == NULL || uSize < offsetof(MIDIHDR,dwOffset))
1303 return MMSYSERR_INVALPARAM;
1305 if (!(lpMidiInHdr->dwFlags & MHDR_PREPARED)) {
1306 return MMSYSERR_NOERROR;
1309 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1310 return MMSYSERR_INVALHANDLE;
1312 return MMDRV_Message(wmld, MIDM_UNPREPARE, (DWORD_PTR)lpMidiInHdr, uSize);
1315 /**************************************************************************
1316 * midiInAddBuffer [WINMM.@]
1318 UINT WINAPI midiInAddBuffer(HMIDIIN hMidiIn,
1319 MIDIHDR* lpMidiInHdr, UINT uSize)
1323 TRACE("(%p, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
1325 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1326 return MMSYSERR_INVALHANDLE;
1328 return MMDRV_Message(wmld, MIDM_ADDBUFFER, (DWORD_PTR)lpMidiInHdr, uSize);
1331 /**************************************************************************
1332 * midiInStart [WINMM.@]
1334 UINT WINAPI midiInStart(HMIDIIN hMidiIn)
1338 TRACE("(%p)\n", hMidiIn);
1340 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1341 return MMSYSERR_INVALHANDLE;
1343 return MMDRV_Message(wmld, MIDM_START, 0L, 0L);
1346 /**************************************************************************
1347 * midiInStop [WINMM.@]
1349 UINT WINAPI midiInStop(HMIDIIN hMidiIn)
1353 TRACE("(%p)\n", hMidiIn);
1355 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1356 return MMSYSERR_INVALHANDLE;
1358 return MMDRV_Message(wmld, MIDM_STOP, 0L, 0L);
1361 /**************************************************************************
1362 * midiInReset [WINMM.@]
1364 UINT WINAPI midiInReset(HMIDIIN hMidiIn)
1368 TRACE("(%p)\n", hMidiIn);
1370 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1371 return MMSYSERR_INVALHANDLE;
1373 return MMDRV_Message(wmld, MIDM_RESET, 0L, 0L);
1376 /**************************************************************************
1377 * midiInGetID [WINMM.@]
1379 UINT WINAPI midiInGetID(HMIDIIN hMidiIn, UINT* lpuDeviceID)
1383 TRACE("(%p, %p)\n", hMidiIn, lpuDeviceID);
1385 if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
1387 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, TRUE)) == NULL)
1388 return MMSYSERR_INVALHANDLE;
1390 *lpuDeviceID = wmld->uDeviceID;
1392 return MMSYSERR_NOERROR;
1395 /**************************************************************************
1396 * midiInMessage [WINMM.@]
1398 UINT WINAPI midiInMessage(HMIDIIN hMidiIn, UINT uMessage,
1399 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1403 TRACE("(%p, %04X, %08lX, %08lX)\n", hMidiIn, uMessage, dwParam1, dwParam2);
1405 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1406 return MMSYSERR_INVALHANDLE;
1411 FIXME("can't handle OPEN or CLOSE message!\n");
1412 return MMSYSERR_NOTSUPPORTED;
1414 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2);
1417 /**************************************************************************
1418 * midiConnect [WINMM.@]
1420 MMRESULT WINAPI midiConnect(HMIDI hMidi, HMIDIOUT hmo, LPVOID pReserved)
1422 FIXME("(%p, %p, %p): Stub\n", hMidi, hmo, pReserved);
1423 return MMSYSERR_ERROR;
1426 /**************************************************************************
1427 * midiDisconnect [WINMM.@]
1429 MMRESULT WINAPI midiDisconnect(HMIDI hMidi, HMIDIOUT hmo, LPVOID pReserved)
1431 FIXME("(%p, %p, %p): Stub\n", hMidi, hmo, pReserved);
1432 return MMSYSERR_ERROR;
1435 typedef struct WINE_MIDIStream {
1446 LPMIDIHDR lpMidiHdr;
1449 #define WINE_MSM_HEADER (WM_USER+0)
1450 #define WINE_MSM_STOP (WM_USER+1)
1452 /**************************************************************************
1453 * MMSYSTEM_GetMidiStream [internal]
1455 static BOOL MMSYSTEM_GetMidiStream(HMIDISTRM hMidiStrm, WINE_MIDIStream** lpMidiStrm, WINE_MIDI** lplpwm)
1457 WINE_MIDI* lpwm = (LPWINE_MIDI)MMDRV_Get(hMidiStrm, MMDRV_MIDIOUT, FALSE);
1466 *lpMidiStrm = (WINE_MIDIStream*)lpwm->mod.rgIds.dwStreamID;
1468 return *lpMidiStrm != NULL;
1471 /**************************************************************************
1472 * MMSYSTEM_MidiStream_Convert [internal]
1474 static DWORD MMSYSTEM_MidiStream_Convert(WINE_MIDIStream* lpMidiStrm, DWORD pulse)
1478 if (lpMidiStrm->dwTimeDiv == 0) {
1479 FIXME("Shouldn't happen. lpMidiStrm->dwTimeDiv = 0\n");
1480 } else if (lpMidiStrm->dwTimeDiv > 0x8000) { /* SMPTE, unchecked FIXME? */
1481 int nf = -(char)HIBYTE(lpMidiStrm->dwTimeDiv); /* number of frames */
1482 int nsf = LOBYTE(lpMidiStrm->dwTimeDiv); /* number of sub-frames */
1483 ret = (pulse * 1000) / (nf * nsf);
1485 ret = (DWORD)((double)pulse * ((double)lpMidiStrm->dwTempo / 1000) /
1486 (double)lpMidiStrm->dwTimeDiv);
1492 /**************************************************************************
1493 * MMSYSTEM_MidiStream_MessageHandler [internal]
1495 static BOOL MMSYSTEM_MidiStream_MessageHandler(WINE_MIDIStream* lpMidiStrm, LPWINE_MIDI lpwm, LPMSG msg)
1497 LPMIDIHDR lpMidiHdr;
1501 switch (msg->message) {
1503 SetEvent(lpMidiStrm->hEvent);
1507 /* this is not quite what MS doc says... */
1508 midiOutReset(lpMidiStrm->hDevice);
1509 /* empty list of already submitted buffers */
1510 for (lpMidiHdr = lpMidiStrm->lpMidiHdr; lpMidiHdr; ) {
1511 LPMIDIHDR lphdr = lpMidiHdr;
1512 lpMidiHdr = lpMidiHdr->lpNext;
1513 lphdr->dwFlags |= MHDR_DONE;
1514 lphdr->dwFlags &= ~MHDR_INQUEUE;
1516 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1517 (HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
1518 lpwm->mod.dwInstance, (DWORD_PTR)lphdr, 0);
1520 lpMidiStrm->lpMidiHdr = 0;
1521 SetEvent(lpMidiStrm->hEvent);
1523 case WINE_MSM_HEADER:
1524 /* sets initial tick count for first MIDIHDR */
1525 if (!lpMidiStrm->dwStartTicks)
1526 lpMidiStrm->dwStartTicks = GetTickCount();
1528 /* FIXME(EPP): "I don't understand the content of the first MIDIHDR sent
1529 * by native mcimidi, it doesn't look like a correct one".
1530 * this trick allows to throw it away... but I don't like it.
1531 * It looks like part of the file I'm trying to play and definitively looks
1532 * like raw midi content
1533 * I'd really like to understand why native mcimidi sends it. Perhaps a bad
1534 * synchronization issue where native mcimidi is still processing raw MIDI
1535 * content before generating MIDIEVENTs ?
1537 * 4c 04 89 3b 00 81 7c 99 3b 43 00 99 23 5e 04 89 L..;..|.;C..#^..
1538 * 3b 00 00 89 23 00 7c 99 3b 45 00 99 28 62 04 89 ;...#.|.;E..(b..
1539 * 3b 00 00 89 28 00 81 7c 99 3b 4e 00 99 23 5e 04 ;...(..|.;N..#^.
1540 * 89 3b 00 00 89 23 00 7c 99 3b 45 00 99 23 78 04 .;...#.|.;E..#x.
1541 * 89 3b 00 00 89 23 00 81 7c 99 3b 48 00 99 23 5e .;...#..|.;H..#^
1542 * 04 89 3b 00 00 89 23 00 7c 99 3b 4e 00 99 28 62 ..;...#.|.;N..(b
1543 * 04 89 3b 00 00 89 28 00 81 7c 99 39 4c 00 99 23 ..;...(..|.9L..#
1544 * 5e 04 89 39 00 00 89 23 00 82 7c 99 3b 4c 00 99 ^..9...#..|.;L..
1545 * 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 00 99 #^..;...#.|.;H..
1546 * 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b 3f 04 (b..;...(..|.;?.
1547 * 89 3b 00 1c 99 23 5e 04 89 23 00 5c 99 3b 45 00 .;...#^..#.\.;E.
1548 * 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 3b 46 .#x..;...#..|.;F
1549 * 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 ..#^..;...#.|.;H
1550 * 00 99 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b ..(b..;...(..|.;
1551 * 46 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b F..#^..;...#.|.;
1552 * 48 00 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 H..#x..;...#..|.
1553 * 3b 4c 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 ;L..#^..;...#.|.
1555 lpMidiHdr = (LPMIDIHDR)msg->lParam;
1556 lpData = (LPBYTE)lpMidiHdr->lpData;
1557 TRACE("Adding %s lpMidiHdr=%p [lpData=0x%p dwBytesRecorded=%u/%u dwFlags=0x%08x size=%lu]\n",
1558 (lpMidiHdr->dwFlags & MHDR_ISSTRM) ? "stream" : "regular", lpMidiHdr,
1559 lpMidiHdr, lpMidiHdr->dwBytesRecorded, lpMidiHdr->dwBufferLength,
1560 lpMidiHdr->dwFlags, msg->wParam);
1562 /* dumps content of lpMidiHdr->lpData
1563 * FIXME: there should be a debug routine somewhere that already does this
1564 * I hate spreading this type of shit all around the code
1566 for (dwToGo = 0; dwToGo < lpMidiHdr->dwBufferLength; dwToGo += 16) {
1570 for (i = 0; i < min(16, lpMidiHdr->dwBufferLength - dwToGo); i++)
1571 printf("%02x ", lpData[dwToGo + i]);
1574 for (i = 0; i < min(16, lpMidiHdr->dwBufferLength - dwToGo); i++) {
1575 ch = lpData[dwToGo + i];
1576 printf("%c", (ch >= 0x20 && ch <= 0x7F) ? ch : '.');
1581 if (((LPMIDIEVENT)lpData)->dwStreamID != 0 &&
1582 ((LPMIDIEVENT)lpData)->dwStreamID != 0xFFFFFFFF &&
1583 ((LPMIDIEVENT)lpData)->dwStreamID != (DWORD)lpMidiStrm) {
1584 FIXME("Dropping bad %s lpMidiHdr (streamID=%08x)\n",
1585 (lpMidiHdr->dwFlags & MHDR_ISSTRM) ? "stream" : "regular",
1586 ((LPMIDIEVENT)lpData)->dwStreamID);
1587 lpMidiHdr->dwFlags |= MHDR_DONE;
1588 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
1590 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1591 (HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
1592 lpwm->mod.dwInstance, (DWORD_PTR)lpMidiHdr, 0);
1596 for (lpmh = &lpMidiStrm->lpMidiHdr; *lpmh; lpmh = &(*lpmh)->lpNext);
1598 lpMidiHdr = (LPMIDIHDR)msg->lParam;
1599 lpMidiHdr->lpNext = 0;
1600 lpMidiHdr->dwFlags |= MHDR_INQUEUE;
1601 lpMidiHdr->dwFlags &= ~MHDR_DONE;
1605 FIXME("Unknown message %d\n", msg->message);
1611 /**************************************************************************
1612 * MMSYSTEM_MidiStream_Player [internal]
1614 static DWORD CALLBACK MMSYSTEM_MidiStream_Player(LPVOID pmt)
1616 WINE_MIDIStream* lpMidiStrm = pmt;
1621 LPMIDIHDR lpMidiHdr;
1624 TRACE("(%p)!\n", lpMidiStrm);
1627 (lpwm = (LPWINE_MIDI)MMDRV_Get(lpMidiStrm->hDevice, MMDRV_MIDIOUT, FALSE)) == NULL)
1630 /* force thread's queue creation */
1631 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
1633 lpMidiStrm->dwStartTicks = 0;
1634 lpMidiStrm->dwPulses = 0;
1636 lpMidiStrm->lpMidiHdr = 0;
1638 /* midiStreamOpen is waiting for ack */
1639 SetEvent(lpMidiStrm->hEvent);
1642 lpMidiHdr = lpMidiStrm->lpMidiHdr;
1644 /* for first message, block until one arrives, then process all that are available */
1645 GetMessageA(&msg, 0, 0, 0);
1647 if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm, lpwm, &msg))
1649 } while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE));
1654 while (dwOffset + offsetof(MIDIEVENT,dwParms) <= lpMidiHdr->dwBytesRecorded) {
1655 LPMIDIEVENT me = (LPMIDIEVENT)(lpMidiHdr->lpData+dwOffset);
1657 /* do we have to wait ? */
1658 if (me->dwDeltaTime) {
1659 lpMidiStrm->dwPositionMS += MMSYSTEM_MidiStream_Convert(lpMidiStrm, me->dwDeltaTime);
1660 lpMidiStrm->dwPulses += me->dwDeltaTime;
1662 dwToGo = lpMidiStrm->dwStartTicks + lpMidiStrm->dwPositionMS;
1664 TRACE("%d/%d/%d\n", dwToGo, GetTickCount(), me->dwDeltaTime);
1665 while ((dwCurrTC = GetTickCount()) < dwToGo) {
1666 if (MsgWaitForMultipleObjects(0, NULL, FALSE, dwToGo - dwCurrTC, QS_ALLINPUT) == WAIT_OBJECT_0) {
1667 /* got a message, handle it */
1668 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) {
1669 if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm, lpwm, &msg))
1671 /* is lpMidiHdr still current? */
1672 if (lpMidiHdr != lpMidiStrm->lpMidiHdr) {
1677 /* timeout, so me->dwDeltaTime is elapsed, can break the while loop */
1682 switch (MEVT_EVENTTYPE(me->dwEvent & ~MEVT_F_CALLBACK)) {
1684 FIXME("NIY: MEVT_COMMENT\n");
1685 /* do nothing, skip bytes */
1688 FIXME("NIY: MEVT_LONGMSG, aka sending Sysex event\n");
1693 midiOutShortMsg(lpMidiStrm->hDevice, MEVT_EVENTPARM(me->dwEvent));
1696 lpMidiStrm->dwTempo = MEVT_EVENTPARM(me->dwEvent);
1701 FIXME("Unknown MEVT (0x%02x)\n", MEVT_EVENTTYPE(me->dwEvent & ~MEVT_F_CALLBACK));
1704 if (me->dwEvent & MEVT_F_CALLBACK) {
1705 /* native fills dwOffset regardless of the cbMidiHdr size argument to midiStreamOut */
1706 lpMidiHdr->dwOffset = dwOffset;
1707 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1708 (HDRVR)lpMidiStrm->hDevice, MM_MOM_POSITIONCB,
1709 lpwm->mod.dwInstance, (LPARAM)lpMidiHdr, 0L);
1711 dwOffset += offsetof(MIDIEVENT,dwParms);
1712 if (me->dwEvent & MEVT_F_LONG)
1713 dwOffset += (MEVT_EVENTPARM(me->dwEvent) + 3) & ~3;
1715 /* done with this header */
1716 lpMidiStrm->lpMidiHdr = lpMidiHdr->lpNext;
1717 lpMidiHdr->dwFlags |= MHDR_DONE;
1718 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
1720 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1721 (HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
1722 lpwm->mod.dwInstance, (DWORD_PTR)lpMidiHdr, 0);
1726 TRACE("End of thread\n");
1730 /**************************************************************************
1731 * MMSYSTEM_MidiStream_PostMessage [internal]
1733 static BOOL MMSYSTEM_MidiStream_PostMessage(WINE_MIDIStream* lpMidiStrm, WORD msg, DWORD pmt1, DWORD pmt2)
1735 if (PostThreadMessageA(lpMidiStrm->dwThreadID, msg, pmt1, pmt2)) {
1736 MsgWaitForMultipleObjects( 1, &lpMidiStrm->hEvent, FALSE, INFINITE, 0 );
1738 ERR("bad PostThreadMessageA\n");
1744 /**************************************************************************
1745 * midiStreamClose [WINMM.@]
1747 MMRESULT WINAPI midiStreamClose(HMIDISTRM hMidiStrm)
1749 WINE_MIDIStream* lpMidiStrm;
1751 TRACE("(%p)!\n", hMidiStrm);
1753 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL))
1754 return MMSYSERR_INVALHANDLE;
1756 midiStreamStop(hMidiStrm);
1757 MMSYSTEM_MidiStream_PostMessage(lpMidiStrm, WM_QUIT, 0, 0);
1758 CloseHandle(lpMidiStrm->hEvent);
1759 HeapFree(GetProcessHeap(), 0, lpMidiStrm);
1761 return midiOutClose((HMIDIOUT)hMidiStrm);
1764 /**************************************************************************
1765 * midiStreamOpen [WINMM.@]
1767 MMRESULT WINAPI midiStreamOpen(HMIDISTRM* lphMidiStrm, LPUINT lpuDeviceID,
1768 DWORD cMidi, DWORD_PTR dwCallback,
1769 DWORD_PTR dwInstance, DWORD fdwOpen)
1771 WINE_MIDIStream* lpMidiStrm;
1773 MIDIOPENSTRMID mosm;
1777 TRACE("(%p, %p, %d, 0x%08lx, 0x%08lx, 0x%08x)!\n",
1778 lphMidiStrm, lpuDeviceID, cMidi, dwCallback, dwInstance, fdwOpen);
1780 if (cMidi != 1 || lphMidiStrm == NULL || lpuDeviceID == NULL)
1781 return MMSYSERR_INVALPARAM;
1783 ret = WINMM_CheckCallback(dwCallback, fdwOpen, FALSE);
1784 if (ret != MMSYSERR_NOERROR)
1787 lpMidiStrm = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_MIDIStream));
1789 return MMSYSERR_NOMEM;
1791 lpMidiStrm->dwTempo = 500000;
1792 lpMidiStrm->dwTimeDiv = 480; /* 480 is 120 quarter notes per minute *//* FIXME ??*/
1793 lpMidiStrm->dwPositionMS = 0;
1795 mosm.dwStreamID = (DWORD)lpMidiStrm;
1796 /* FIXME: the correct value is not allocated yet for MAPPER */
1797 mosm.wDeviceID = *lpuDeviceID;
1798 lpwm = MIDI_OutAlloc(&hMidiOut, &dwCallback, &dwInstance, &fdwOpen, 1, &mosm);
1800 HeapFree(GetProcessHeap(), 0, lpMidiStrm);
1801 return MMSYSERR_NOMEM;
1803 lpMidiStrm->hDevice = hMidiOut;
1804 *lphMidiStrm = (HMIDISTRM)hMidiOut;
1806 lpwm->mld.uDeviceID = *lpuDeviceID;
1808 ret = MMDRV_Open(&lpwm->mld, MODM_OPEN, (DWORD_PTR)&lpwm->mod, fdwOpen);
1809 if (ret != MMSYSERR_NOERROR) {
1810 MMDRV_Free(hMidiOut, &lpwm->mld);
1811 HeapFree(GetProcessHeap(), 0, lpMidiStrm);
1815 lpMidiStrm->hEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
1816 lpMidiStrm->wFlags = HIWORD(fdwOpen);
1818 lpMidiStrm->hThread = CreateThread(NULL, 0, MMSYSTEM_MidiStream_Player,
1819 lpMidiStrm, 0, &(lpMidiStrm->dwThreadID));
1821 if (!lpMidiStrm->hThread) {
1822 midiStreamClose((HMIDISTRM)hMidiOut);
1823 return MMSYSERR_NOMEM;
1825 SetThreadPriority(lpMidiStrm->hThread, THREAD_PRIORITY_TIME_CRITICAL);
1827 /* wait for thread to have started, and for its queue to be created */
1828 WaitForSingleObject(lpMidiStrm->hEvent, INFINITE);
1829 /* start in paused mode */
1830 SuspendThread(lpMidiStrm->hThread);
1832 TRACE("=> (%u/%d) hMidi=%p ret=%d lpMidiStrm=%p\n",
1833 *lpuDeviceID, lpwm->mld.uDeviceID, *lphMidiStrm, ret, lpMidiStrm);
1837 /**************************************************************************
1838 * midiStreamOut [WINMM.@]
1840 MMRESULT WINAPI midiStreamOut(HMIDISTRM hMidiStrm, LPMIDIHDR lpMidiHdr,
1843 WINE_MIDIStream* lpMidiStrm;
1844 DWORD ret = MMSYSERR_NOERROR;
1846 TRACE("(%p, %p, %u)!\n", hMidiStrm, lpMidiHdr, cbMidiHdr);
1848 if (cbMidiHdr < offsetof(MIDIHDR,dwOffset) || !lpMidiHdr || !lpMidiHdr->lpData
1849 || lpMidiHdr->dwBufferLength < lpMidiHdr->dwBytesRecorded
1850 || lpMidiHdr->dwBytesRecorded % 4 /* player expects DWORD padding */)
1851 return MMSYSERR_INVALPARAM;
1852 /* FIXME: Native additionally checks if the MIDIEVENTs in lpData
1853 * exactly fit dwBytesRecorded. */
1855 if (!(lpMidiHdr->dwFlags & MHDR_PREPARED))
1856 return MIDIERR_UNPREPARED;
1858 if (lpMidiHdr->dwFlags & MHDR_INQUEUE)
1859 return MIDIERR_STILLPLAYING;
1861 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1862 ret = MMSYSERR_INVALHANDLE;
1864 lpMidiHdr->dwFlags |= MHDR_ISSTRM | MHDR_INQUEUE;
1865 lpMidiHdr->dwFlags &= ~MHDR_DONE;
1866 if (!PostThreadMessageA(lpMidiStrm->dwThreadID,
1867 WINE_MSM_HEADER, cbMidiHdr,
1868 (LPARAM)lpMidiHdr)) {
1869 ERR("bad PostThreadMessageA\n");
1870 ret = MMSYSERR_ERROR;
1876 /**************************************************************************
1877 * midiStreamPause [WINMM.@]
1879 MMRESULT WINAPI midiStreamPause(HMIDISTRM hMidiStrm)
1881 WINE_MIDIStream* lpMidiStrm;
1882 DWORD ret = MMSYSERR_NOERROR;
1884 TRACE("(%p)!\n", hMidiStrm);
1886 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1887 ret = MMSYSERR_INVALHANDLE;
1889 if (SuspendThread(lpMidiStrm->hThread) == 0xFFFFFFFF) {
1890 ERR("bad Suspend (%d)\n", GetLastError());
1891 ret = MMSYSERR_ERROR;
1897 /**************************************************************************
1898 * midiStreamPosition [WINMM.@]
1900 MMRESULT WINAPI midiStreamPosition(HMIDISTRM hMidiStrm, LPMMTIME lpMMT, UINT cbmmt)
1902 WINE_MIDIStream* lpMidiStrm;
1903 DWORD ret = MMSYSERR_NOERROR;
1905 TRACE("(%p, %p, %u)!\n", hMidiStrm, lpMMT, cbmmt);
1907 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1908 ret = MMSYSERR_INVALHANDLE;
1909 } else if (lpMMT == NULL || cbmmt != sizeof(MMTIME)) {
1910 ret = MMSYSERR_INVALPARAM;
1912 switch (lpMMT->wType) {
1914 FIXME("Unsupported time type %x\n", lpMMT->wType);
1917 lpMMT->wType = TIME_MS;
1918 /* fall through to alternative format */
1920 lpMMT->u.ms = lpMidiStrm->dwPositionMS;
1921 TRACE("=> %d ms\n", lpMMT->u.ms);
1924 lpMMT->u.ticks = lpMidiStrm->dwPulses;
1925 TRACE("=> %d ticks\n", lpMMT->u.ticks);
1932 /**************************************************************************
1933 * midiStreamProperty [WINMM.@]
1935 MMRESULT WINAPI midiStreamProperty(HMIDISTRM hMidiStrm, LPBYTE lpPropData, DWORD dwProperty)
1937 WINE_MIDIStream* lpMidiStrm;
1938 MMRESULT ret = MMSYSERR_NOERROR;
1940 TRACE("(%p, %p, %x)\n", hMidiStrm, lpPropData, dwProperty);
1942 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1943 ret = MMSYSERR_INVALHANDLE;
1944 } else if ((dwProperty & (MIDIPROP_GET|MIDIPROP_SET)) == 0) {
1945 ret = MMSYSERR_INVALPARAM;
1946 } else if (dwProperty & MIDIPROP_TEMPO) {
1947 MIDIPROPTEMPO* mpt = (MIDIPROPTEMPO*)lpPropData;
1949 if (sizeof(MIDIPROPTEMPO) != mpt->cbStruct) {
1950 ret = MMSYSERR_INVALPARAM;
1951 } else if (dwProperty & MIDIPROP_SET) {
1952 lpMidiStrm->dwTempo = mpt->dwTempo;
1953 TRACE("Setting tempo to %d\n", mpt->dwTempo);
1954 } else if (dwProperty & MIDIPROP_GET) {
1955 mpt->dwTempo = lpMidiStrm->dwTempo;
1956 TRACE("Getting tempo <= %d\n", mpt->dwTempo);
1958 } else if (dwProperty & MIDIPROP_TIMEDIV) {
1959 MIDIPROPTIMEDIV* mptd = (MIDIPROPTIMEDIV*)lpPropData;
1961 if (sizeof(MIDIPROPTIMEDIV) != mptd->cbStruct) {
1962 ret = MMSYSERR_INVALPARAM;
1963 } else if (dwProperty & MIDIPROP_SET) {
1964 lpMidiStrm->dwTimeDiv = mptd->dwTimeDiv;
1965 TRACE("Setting time div to %d\n", mptd->dwTimeDiv);
1966 } else if (dwProperty & MIDIPROP_GET) {
1967 mptd->dwTimeDiv = lpMidiStrm->dwTimeDiv;
1968 TRACE("Getting time div <= %d\n", mptd->dwTimeDiv);
1971 ret = MMSYSERR_INVALPARAM;
1977 /**************************************************************************
1978 * midiStreamRestart [WINMM.@]
1980 MMRESULT WINAPI midiStreamRestart(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;
1992 /* since we increase the thread suspend count on each midiStreamPause
1993 * there may be a need for several ResumeThread
1996 ret = ResumeThread(lpMidiStrm->hThread);
1997 } while (ret != 0xFFFFFFFF && ret > 1);
1998 if (ret == 0xFFFFFFFF) {
1999 ERR("bad Resume (%d)\n", GetLastError());
2000 ret = MMSYSERR_ERROR;
2002 lpMidiStrm->dwStartTicks = GetTickCount() - lpMidiStrm->dwPositionMS;
2008 /**************************************************************************
2009 * midiStreamStop [WINMM.@]
2011 MMRESULT WINAPI midiStreamStop(HMIDISTRM hMidiStrm)
2013 WINE_MIDIStream* lpMidiStrm;
2014 MMRESULT ret = MMSYSERR_NOERROR;
2016 TRACE("(%p)!\n", hMidiStrm);
2018 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
2019 ret = MMSYSERR_INVALHANDLE;
2021 /* in case stream has been paused... FIXME is the current state correct ? */
2022 midiStreamRestart(hMidiStrm);
2023 MMSYSTEM_MidiStream_PostMessage(lpMidiStrm, WINE_MSM_STOP, 0, 0);
2028 static UINT WAVE_Open(HANDLE* lphndl, UINT uDeviceID, UINT uType,
2029 LPCWAVEFORMATEX lpFormat, DWORD_PTR dwCallback,
2030 DWORD_PTR dwInstance, DWORD dwFlags)
2037 TRACE("(%p, %d, %s, %p, %08lX, %08lX, %08X);\n",
2038 lphndl, (int)uDeviceID, (uType==MMDRV_WAVEOUT)?"Out":"In", lpFormat, dwCallback,
2039 dwInstance, dwFlags);
2041 if (dwFlags & WAVE_FORMAT_QUERY)
2042 TRACE("WAVE_FORMAT_QUERY requested !\n");
2044 dwRet = WINMM_CheckCallback(dwCallback, dwFlags, FALSE);
2045 if (dwRet != MMSYSERR_NOERROR)
2048 if (lpFormat == NULL) {
2049 WARN("bad format\n");
2050 return WAVERR_BADFORMAT;
2053 if ((dwFlags & WAVE_MAPPED) && (uDeviceID == (UINT)-1)) {
2054 WARN("invalid parameter\n");
2055 return MMSYSERR_INVALPARAM;
2058 /* may have a PCMWAVEFORMAT rather than a WAVEFORMATEX so don't read cbSize */
2059 TRACE("wFormatTag=%u, nChannels=%u, nSamplesPerSec=%u, nAvgBytesPerSec=%u, nBlockAlign=%u, wBitsPerSample=%u\n",
2060 lpFormat->wFormatTag, lpFormat->nChannels, lpFormat->nSamplesPerSec,
2061 lpFormat->nAvgBytesPerSec, lpFormat->nBlockAlign, lpFormat->wBitsPerSample);
2063 if ((wmld = MMDRV_Alloc(sizeof(WINE_WAVE), uType, &handle,
2064 &dwFlags, &dwCallback, &dwInstance)) == NULL) {
2065 return MMSYSERR_NOMEM;
2069 wod.lpFormat = (LPWAVEFORMATEX)lpFormat; /* should the struct be copied iso pointer? */
2070 wod.dwCallback = dwCallback;
2071 wod.dwInstance = dwInstance;
2074 TRACE("cb=%08lx\n", wod.dwCallback);
2077 if (dwFlags & WAVE_MAPPED) {
2078 wod.uMappedDeviceID = uDeviceID;
2079 uDeviceID = WAVE_MAPPER;
2081 wod.uMappedDeviceID = -1;
2083 wmld->uDeviceID = uDeviceID;
2085 dwRet = MMDRV_Open(wmld, (uType == MMDRV_WAVEOUT) ? WODM_OPEN : WIDM_OPEN,
2086 (DWORD_PTR)&wod, dwFlags);
2088 TRACE("dwRet = %s\n", WINMM_ErrorToString(dwRet));
2089 if (dwRet != WAVERR_BADFORMAT ||
2090 ((dwFlags & (WAVE_MAPPED|WAVE_FORMAT_DIRECT)) != 0) || (uDeviceID == WAVE_MAPPER)) break;
2091 /* if we ask for a format which isn't supported by the physical driver,
2092 * let's try to map it through the wave mapper (except, if we already tried
2093 * or user didn't allow us to use acm codecs or the device is already the mapper)
2095 dwFlags |= WAVE_MAPPED;
2096 /* we shall loop only one */
2099 if ((dwFlags & WAVE_FORMAT_QUERY) || dwRet != MMSYSERR_NOERROR) {
2100 MMDRV_Free(handle, wmld);
2104 if (lphndl != NULL) *lphndl = handle;
2105 TRACE("=> %s hWave=%p\n", WINMM_ErrorToString(dwRet), handle);
2110 /**************************************************************************
2111 * waveOutGetNumDevs [WINMM.@]
2113 UINT WINAPI waveOutGetNumDevs(void)
2115 return MMDRV_GetNum(MMDRV_WAVEOUT);
2118 /**************************************************************************
2119 * waveOutGetDevCapsA [WINMM.@]
2121 UINT WINAPI waveOutGetDevCapsA(UINT_PTR uDeviceID, LPWAVEOUTCAPSA lpCaps,
2127 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2129 ret = waveOutGetDevCapsW(uDeviceID, &wocW, sizeof(wocW));
2131 if (ret == MMSYSERR_NOERROR) {
2133 wocA.wMid = wocW.wMid;
2134 wocA.wPid = wocW.wPid;
2135 wocA.vDriverVersion = wocW.vDriverVersion;
2136 WideCharToMultiByte( CP_ACP, 0, wocW.szPname, -1, wocA.szPname,
2137 sizeof(wocA.szPname), NULL, NULL );
2138 wocA.dwFormats = wocW.dwFormats;
2139 wocA.wChannels = wocW.wChannels;
2140 wocA.dwSupport = wocW.dwSupport;
2141 memcpy(lpCaps, &wocA, min(uSize, sizeof(wocA)));
2146 /**************************************************************************
2147 * waveOutGetDevCapsW [WINMM.@]
2149 UINT WINAPI waveOutGetDevCapsW(UINT_PTR uDeviceID, LPWAVEOUTCAPSW lpCaps,
2154 TRACE("(%lu %p %u)!\n", uDeviceID, lpCaps, uSize);
2156 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2158 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_WAVEOUT, TRUE)) == NULL)
2159 return MMSYSERR_BADDEVICEID;
2161 return MMDRV_Message(wmld, WODM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize);
2164 /**************************************************************************
2165 * waveOutGetErrorTextA [WINMM.@]
2166 * waveInGetErrorTextA [WINMM.@]
2168 UINT WINAPI waveOutGetErrorTextA(UINT uError, LPSTR lpText, UINT uSize)
2172 if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
2173 else if (uSize == 0) ret = MMSYSERR_NOERROR;
2176 LPWSTR xstr = HeapAlloc(GetProcessHeap(), 0, uSize * sizeof(WCHAR));
2177 if (!xstr) ret = MMSYSERR_NOMEM;
2180 ret = waveOutGetErrorTextW(uError, xstr, uSize);
2181 if (ret == MMSYSERR_NOERROR)
2182 WideCharToMultiByte(CP_ACP, 0, xstr, -1, lpText, uSize, NULL, NULL);
2183 HeapFree(GetProcessHeap(), 0, xstr);
2189 /**************************************************************************
2190 * waveOutGetErrorTextW [WINMM.@]
2191 * waveInGetErrorTextW [WINMM.@]
2193 UINT WINAPI waveOutGetErrorTextW(UINT uError, LPWSTR lpText, UINT uSize)
2195 UINT ret = MMSYSERR_BADERRNUM;
2197 if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
2198 else if (uSize == 0) ret = MMSYSERR_NOERROR;
2200 /* test has been removed because MMSYSERR_BASE is 0, and gcc did emit
2201 * a warning for the test was always true */
2202 (/*uError >= MMSYSERR_BASE && */ uError <= MMSYSERR_LASTERROR) ||
2203 (uError >= WAVERR_BASE && uError <= WAVERR_LASTERROR)) {
2204 if (LoadStringW(hWinMM32Instance,
2205 uError, lpText, uSize) > 0) {
2206 ret = MMSYSERR_NOERROR;
2212 /**************************************************************************
2213 * waveOutOpen [WINMM.@]
2214 * All the args/structs have the same layout as the win16 equivalents
2216 MMRESULT WINAPI waveOutOpen(LPHWAVEOUT lphWaveOut, UINT uDeviceID,
2217 LPCWAVEFORMATEX lpFormat, DWORD_PTR dwCallback,
2218 DWORD_PTR dwInstance, DWORD dwFlags)
2220 return WAVE_Open((HANDLE*)lphWaveOut, uDeviceID, MMDRV_WAVEOUT, lpFormat,
2221 dwCallback, dwInstance, dwFlags);
2224 /**************************************************************************
2225 * waveOutClose [WINMM.@]
2227 UINT WINAPI waveOutClose(HWAVEOUT hWaveOut)
2232 TRACE("(%p)\n", hWaveOut);
2234 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2235 return MMSYSERR_INVALHANDLE;
2237 dwRet = MMDRV_Close(wmld, WODM_CLOSE);
2238 if (dwRet != WAVERR_STILLPLAYING)
2239 MMDRV_Free(hWaveOut, wmld);
2244 /**************************************************************************
2245 * waveOutPrepareHeader [WINMM.@]
2247 UINT WINAPI waveOutPrepareHeader(HWAVEOUT hWaveOut,
2248 WAVEHDR* lpWaveOutHdr, UINT uSize)
2253 TRACE("(%p, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
2255 if (lpWaveOutHdr == NULL || uSize < sizeof (WAVEHDR))
2256 return MMSYSERR_INVALPARAM;
2258 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2259 return MMSYSERR_INVALHANDLE;
2261 if ((result = MMDRV_Message(wmld, WODM_PREPARE, (DWORD_PTR)lpWaveOutHdr,
2262 uSize)) != MMSYSERR_NOTSUPPORTED)
2265 if (lpWaveOutHdr->dwFlags & WHDR_INQUEUE)
2266 return WAVERR_STILLPLAYING;
2268 lpWaveOutHdr->dwFlags |= WHDR_PREPARED;
2269 lpWaveOutHdr->dwFlags &= ~WHDR_DONE;
2271 return MMSYSERR_NOERROR;
2274 /**************************************************************************
2275 * waveOutUnprepareHeader [WINMM.@]
2277 UINT WINAPI waveOutUnprepareHeader(HWAVEOUT hWaveOut,
2278 LPWAVEHDR lpWaveOutHdr, UINT uSize)
2283 TRACE("(%p, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
2285 if (lpWaveOutHdr == NULL || uSize < sizeof (WAVEHDR))
2286 return MMSYSERR_INVALPARAM;
2288 if (!(lpWaveOutHdr->dwFlags & WHDR_PREPARED)) {
2289 return MMSYSERR_NOERROR;
2292 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2293 return MMSYSERR_INVALHANDLE;
2295 if ((result = MMDRV_Message(wmld, WODM_UNPREPARE, (DWORD_PTR)lpWaveOutHdr,
2296 uSize)) != MMSYSERR_NOTSUPPORTED)
2299 if (lpWaveOutHdr->dwFlags & WHDR_INQUEUE)
2300 return WAVERR_STILLPLAYING;
2302 lpWaveOutHdr->dwFlags &= ~WHDR_PREPARED;
2303 lpWaveOutHdr->dwFlags |= WHDR_DONE;
2305 return MMSYSERR_NOERROR;
2308 /**************************************************************************
2309 * waveOutWrite [WINMM.@]
2311 UINT WINAPI waveOutWrite(HWAVEOUT hWaveOut, LPWAVEHDR lpWaveOutHdr,
2316 TRACE("(%p, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
2318 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2319 return MMSYSERR_INVALHANDLE;
2321 return MMDRV_Message(wmld, WODM_WRITE, (DWORD_PTR)lpWaveOutHdr, uSize);
2324 /**************************************************************************
2325 * waveOutBreakLoop [WINMM.@]
2327 UINT WINAPI waveOutBreakLoop(HWAVEOUT hWaveOut)
2331 TRACE("(%p);\n", hWaveOut);
2333 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2334 return MMSYSERR_INVALHANDLE;
2335 return MMDRV_Message(wmld, WODM_BREAKLOOP, 0L, 0L);
2338 /**************************************************************************
2339 * waveOutPause [WINMM.@]
2341 UINT WINAPI waveOutPause(HWAVEOUT hWaveOut)
2345 TRACE("(%p);\n", hWaveOut);
2347 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2348 return MMSYSERR_INVALHANDLE;
2349 return MMDRV_Message(wmld, WODM_PAUSE, 0L, 0L);
2352 /**************************************************************************
2353 * waveOutReset [WINMM.@]
2355 UINT WINAPI waveOutReset(HWAVEOUT hWaveOut)
2359 TRACE("(%p);\n", hWaveOut);
2361 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2362 return MMSYSERR_INVALHANDLE;
2363 return MMDRV_Message(wmld, WODM_RESET, 0L, 0L);
2366 /**************************************************************************
2367 * waveOutRestart [WINMM.@]
2369 UINT WINAPI waveOutRestart(HWAVEOUT hWaveOut)
2373 TRACE("(%p);\n", hWaveOut);
2375 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2376 return MMSYSERR_INVALHANDLE;
2377 return MMDRV_Message(wmld, WODM_RESTART, 0L, 0L);
2380 /**************************************************************************
2381 * waveOutGetPosition [WINMM.@]
2383 UINT WINAPI waveOutGetPosition(HWAVEOUT hWaveOut, LPMMTIME lpTime,
2388 TRACE("(%p, %p, %u);\n", hWaveOut, lpTime, uSize);
2390 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2391 return MMSYSERR_INVALHANDLE;
2393 return MMDRV_Message(wmld, WODM_GETPOS, (DWORD_PTR)lpTime, uSize);
2396 /**************************************************************************
2397 * waveOutGetPitch [WINMM.@]
2399 UINT WINAPI waveOutGetPitch(HWAVEOUT hWaveOut, LPDWORD lpdw)
2403 TRACE("(%p, %p);\n", hWaveOut, lpdw);
2405 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2406 return MMSYSERR_INVALHANDLE;
2407 return MMDRV_Message(wmld, WODM_GETPITCH, (DWORD_PTR)lpdw, 0L);
2410 /**************************************************************************
2411 * waveOutSetPitch [WINMM.@]
2413 UINT WINAPI waveOutSetPitch(HWAVEOUT hWaveOut, DWORD dw)
2417 TRACE("(%p, %08x);\n", hWaveOut, dw);
2419 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2420 return MMSYSERR_INVALHANDLE;
2421 return MMDRV_Message(wmld, WODM_SETPITCH, dw, 0L);
2424 /**************************************************************************
2425 * waveOutGetPlaybackRate [WINMM.@]
2427 UINT WINAPI waveOutGetPlaybackRate(HWAVEOUT hWaveOut, LPDWORD lpdw)
2431 TRACE("(%p, %p);\n", hWaveOut, lpdw);
2433 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2434 return MMSYSERR_INVALHANDLE;
2435 return MMDRV_Message(wmld, WODM_GETPLAYBACKRATE, (DWORD_PTR)lpdw, 0L);
2438 /**************************************************************************
2439 * waveOutSetPlaybackRate [WINMM.@]
2441 UINT WINAPI waveOutSetPlaybackRate(HWAVEOUT hWaveOut, DWORD dw)
2445 TRACE("(%p, %08x);\n", hWaveOut, dw);
2447 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2448 return MMSYSERR_INVALHANDLE;
2449 return MMDRV_Message(wmld, WODM_SETPLAYBACKRATE, dw, 0L);
2452 /**************************************************************************
2453 * waveOutGetVolume [WINMM.@]
2455 UINT WINAPI waveOutGetVolume(HWAVEOUT hWaveOut, LPDWORD lpdw)
2459 TRACE("(%p, %p);\n", hWaveOut, lpdw);
2462 WARN("invalid parameter\n");
2463 return MMSYSERR_INVALPARAM;
2466 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, TRUE)) == NULL)
2467 return MMSYSERR_INVALHANDLE;
2469 return MMDRV_Message(wmld, WODM_GETVOLUME, (DWORD_PTR)lpdw, 0L);
2472 /**************************************************************************
2473 * waveOutSetVolume [WINMM.@]
2475 UINT WINAPI waveOutSetVolume(HWAVEOUT hWaveOut, DWORD dw)
2479 TRACE("(%p, %08x);\n", hWaveOut, dw);
2481 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, TRUE)) == NULL)
2482 return MMSYSERR_INVALHANDLE;
2484 return MMDRV_Message(wmld, WODM_SETVOLUME, dw, 0L);
2487 /**************************************************************************
2488 * waveOutGetID [WINMM.@]
2490 UINT WINAPI waveOutGetID(HWAVEOUT hWaveOut, UINT* lpuDeviceID)
2494 TRACE("(%p, %p);\n", hWaveOut, lpuDeviceID);
2496 if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
2498 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2499 return MMSYSERR_INVALHANDLE;
2501 *lpuDeviceID = wmld->uDeviceID;
2505 /**************************************************************************
2506 * waveOutMessage [WINMM.@]
2508 UINT WINAPI waveOutMessage(HWAVEOUT hWaveOut, UINT uMessage,
2509 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2513 TRACE("(%p, %u, %ld, %ld)\n", hWaveOut, uMessage, dwParam1, dwParam2);
2515 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL) {
2516 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, TRUE)) != NULL) {
2517 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
2519 WARN("invalid handle\n");
2520 return MMSYSERR_INVALHANDLE;
2524 if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER)) {
2525 WARN("invalid parameter\n");
2526 return MMSYSERR_INVALPARAM;
2529 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2);
2532 /**************************************************************************
2533 * waveInGetNumDevs [WINMM.@]
2535 UINT WINAPI waveInGetNumDevs(void)
2537 return MMDRV_GetNum(MMDRV_WAVEIN);
2540 /**************************************************************************
2541 * waveInGetDevCapsW [WINMM.@]
2543 UINT WINAPI waveInGetDevCapsW(UINT_PTR uDeviceID, LPWAVEINCAPSW lpCaps, UINT uSize)
2547 TRACE("(%lu %p %u)!\n", uDeviceID, lpCaps, uSize);
2549 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2551 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_WAVEIN, TRUE)) == NULL)
2552 return MMSYSERR_BADDEVICEID;
2554 return MMDRV_Message(wmld, WIDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize);
2557 /**************************************************************************
2558 * waveInGetDevCapsA [WINMM.@]
2560 UINT WINAPI waveInGetDevCapsA(UINT_PTR uDeviceID, LPWAVEINCAPSA lpCaps, UINT uSize)
2565 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2567 ret = waveInGetDevCapsW(uDeviceID, &wicW, sizeof(wicW));
2569 if (ret == MMSYSERR_NOERROR) {
2571 wicA.wMid = wicW.wMid;
2572 wicA.wPid = wicW.wPid;
2573 wicA.vDriverVersion = wicW.vDriverVersion;
2574 WideCharToMultiByte( CP_ACP, 0, wicW.szPname, -1, wicA.szPname,
2575 sizeof(wicA.szPname), NULL, NULL );
2576 wicA.dwFormats = wicW.dwFormats;
2577 wicA.wChannels = wicW.wChannels;
2578 memcpy(lpCaps, &wicA, min(uSize, sizeof(wicA)));
2583 /**************************************************************************
2584 * waveInOpen [WINMM.@]
2586 MMRESULT WINAPI waveInOpen(HWAVEIN* lphWaveIn, UINT uDeviceID,
2587 LPCWAVEFORMATEX lpFormat, DWORD_PTR dwCallback,
2588 DWORD_PTR dwInstance, DWORD dwFlags)
2590 return WAVE_Open((HANDLE*)lphWaveIn, uDeviceID, MMDRV_WAVEIN, lpFormat,
2591 dwCallback, dwInstance, dwFlags);
2594 /**************************************************************************
2595 * waveInClose [WINMM.@]
2597 UINT WINAPI waveInClose(HWAVEIN hWaveIn)
2602 TRACE("(%p)\n", hWaveIn);
2604 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2605 return MMSYSERR_INVALHANDLE;
2607 dwRet = MMDRV_Message(wmld, WIDM_CLOSE, 0L, 0L);
2608 if (dwRet != WAVERR_STILLPLAYING)
2609 MMDRV_Free(hWaveIn, wmld);
2613 /**************************************************************************
2614 * waveInPrepareHeader [WINMM.@]
2616 UINT WINAPI waveInPrepareHeader(HWAVEIN hWaveIn, WAVEHDR* lpWaveInHdr,
2622 TRACE("(%p, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
2624 if (lpWaveInHdr == NULL || uSize < sizeof (WAVEHDR))
2625 return MMSYSERR_INVALPARAM;
2627 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2628 return MMSYSERR_INVALHANDLE;
2630 if ((result = MMDRV_Message(wmld, WIDM_PREPARE, (DWORD_PTR)lpWaveInHdr,
2631 uSize)) != MMSYSERR_NOTSUPPORTED)
2634 if (lpWaveInHdr->dwFlags & WHDR_INQUEUE)
2635 return WAVERR_STILLPLAYING;
2637 lpWaveInHdr->dwFlags |= WHDR_PREPARED;
2638 lpWaveInHdr->dwFlags &= ~WHDR_DONE;
2639 lpWaveInHdr->dwBytesRecorded = 0;
2641 return MMSYSERR_NOERROR;
2644 /**************************************************************************
2645 * waveInUnprepareHeader [WINMM.@]
2647 UINT WINAPI waveInUnprepareHeader(HWAVEIN hWaveIn, WAVEHDR* lpWaveInHdr,
2653 TRACE("(%p, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
2655 if (lpWaveInHdr == NULL || uSize < sizeof (WAVEHDR))
2656 return MMSYSERR_INVALPARAM;
2658 if (!(lpWaveInHdr->dwFlags & WHDR_PREPARED))
2659 return MMSYSERR_NOERROR;
2661 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2662 return MMSYSERR_INVALHANDLE;
2664 if ((result = MMDRV_Message(wmld, WIDM_UNPREPARE, (DWORD_PTR)lpWaveInHdr,
2665 uSize)) != MMSYSERR_NOTSUPPORTED)
2668 if (lpWaveInHdr->dwFlags & WHDR_INQUEUE)
2669 return WAVERR_STILLPLAYING;
2671 lpWaveInHdr->dwFlags &= ~WHDR_PREPARED;
2672 lpWaveInHdr->dwFlags |= WHDR_DONE;
2674 return MMSYSERR_NOERROR;
2677 /**************************************************************************
2678 * waveInAddBuffer [WINMM.@]
2680 UINT WINAPI waveInAddBuffer(HWAVEIN hWaveIn,
2681 WAVEHDR* lpWaveInHdr, UINT uSize)
2685 TRACE("(%p, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
2687 if (lpWaveInHdr == NULL) return MMSYSERR_INVALPARAM;
2688 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2689 return MMSYSERR_INVALHANDLE;
2691 return MMDRV_Message(wmld, WIDM_ADDBUFFER, (DWORD_PTR)lpWaveInHdr, uSize);
2694 /**************************************************************************
2695 * waveInReset [WINMM.@]
2697 UINT WINAPI waveInReset(HWAVEIN hWaveIn)
2701 TRACE("(%p);\n", hWaveIn);
2703 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2704 return MMSYSERR_INVALHANDLE;
2706 return MMDRV_Message(wmld, WIDM_RESET, 0L, 0L);
2709 /**************************************************************************
2710 * waveInStart [WINMM.@]
2712 UINT WINAPI waveInStart(HWAVEIN hWaveIn)
2716 TRACE("(%p);\n", hWaveIn);
2718 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2719 return MMSYSERR_INVALHANDLE;
2721 return MMDRV_Message(wmld, WIDM_START, 0L, 0L);
2724 /**************************************************************************
2725 * waveInStop [WINMM.@]
2727 UINT WINAPI waveInStop(HWAVEIN hWaveIn)
2731 TRACE("(%p);\n", hWaveIn);
2733 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2734 return MMSYSERR_INVALHANDLE;
2736 return MMDRV_Message(wmld,WIDM_STOP, 0L, 0L);
2739 /**************************************************************************
2740 * waveInGetPosition [WINMM.@]
2742 UINT WINAPI waveInGetPosition(HWAVEIN hWaveIn, LPMMTIME lpTime,
2747 TRACE("(%p, %p, %u);\n", hWaveIn, lpTime, uSize);
2749 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2750 return MMSYSERR_INVALHANDLE;
2752 return MMDRV_Message(wmld, WIDM_GETPOS, (DWORD_PTR)lpTime, uSize);
2755 /**************************************************************************
2756 * waveInGetID [WINMM.@]
2758 UINT WINAPI waveInGetID(HWAVEIN hWaveIn, UINT* lpuDeviceID)
2762 TRACE("(%p, %p);\n", hWaveIn, lpuDeviceID);
2764 if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
2766 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2767 return MMSYSERR_INVALHANDLE;
2769 *lpuDeviceID = wmld->uDeviceID;
2770 return MMSYSERR_NOERROR;
2773 /**************************************************************************
2774 * waveInMessage [WINMM.@]
2776 UINT WINAPI waveInMessage(HWAVEIN hWaveIn, UINT uMessage,
2777 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2781 TRACE("(%p, %u, %ld, %ld)\n", hWaveIn, uMessage, dwParam1, dwParam2);
2783 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL) {
2784 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, TRUE)) != NULL) {
2785 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
2787 return MMSYSERR_INVALHANDLE;
2791 if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER))
2792 return MMSYSERR_INVALPARAM;
2795 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2);
2805 static DWORD WINAPI mmTaskRun(void* pmt)
2807 struct mm_starter mms;
2809 memcpy(&mms, pmt, sizeof(struct mm_starter));
2810 HeapFree(GetProcessHeap(), 0, pmt);
2812 if (mms.event) SetEvent(mms.event);
2816 /******************************************************************
2817 * mmTaskCreate (WINMM.@)
2819 UINT WINAPI mmTaskCreate(LPTASKCALLBACK cb, HANDLE* ph, DWORD_PTR client)
2823 struct mm_starter *mms;
2825 mms = HeapAlloc(GetProcessHeap(), 0, sizeof(struct mm_starter));
2826 if (mms == NULL) return TASKERR_OUTOFMEMORY;
2829 mms->client = client;
2830 if (ph) hEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
2831 mms->event = hEvent;
2833 hThread = CreateThread(0, 0, mmTaskRun, mms, 0, NULL);
2835 HeapFree(GetProcessHeap(), 0, mms);
2836 if (hEvent) CloseHandle(hEvent);
2837 return TASKERR_OUTOFMEMORY;
2839 SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);
2840 if (ph) *ph = hEvent;
2841 CloseHandle(hThread);
2845 /******************************************************************
2846 * mmTaskBlock (WINMM.@)
2848 VOID WINAPI mmTaskBlock(DWORD tid)
2854 GetMessageA(&msg, 0, 0, 0);
2855 if (msg.hwnd) DispatchMessageA(&msg);
2856 } while (msg.message != WM_USER);
2859 /******************************************************************
2860 * mmTaskSignal (WINMM.@)
2862 BOOL WINAPI mmTaskSignal(DWORD tid)
2864 return PostThreadMessageW(tid, WM_USER, 0, 0);
2867 /******************************************************************
2868 * mmTaskYield (WINMM.@)
2870 VOID WINAPI mmTaskYield(VOID) {}
2872 /******************************************************************
2873 * mmGetCurrentTask (WINMM.@)
2875 DWORD WINAPI mmGetCurrentTask(VOID)
2877 return GetCurrentThreadId();