d3dxof: Store number of subojects for all top level objects.
[wine/multimedia.git] / dlls / winmm / winmm.c
blob389fff86350d8b055cd8f8882c524e06acf3b52d
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
3 /*
4 * WINMM functions
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
25 * Eric POUECH :
26 * 98/9 added Win32 MCI support
27 * 99/4 added midiStream support
28 * 99/9 added support for loadable low level drivers
31 /* TODO
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,
39 * midi, mixer and aux
42 #include <stdio.h>
43 #include <stdarg.h>
44 #include <string.h>
46 #define NONAMELESSUNION
47 #define NONAMELESSSTRUCT
48 #include "windef.h"
49 #include "winbase.h"
50 #include "mmsystem.h"
51 #include "winuser.h"
52 #include "winnls.h"
53 #include "winternl.h"
54 #include "winemm.h"
56 #include "wine/debug.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(winmm);
60 void (WINAPI *pFnReleaseThunkLock)(DWORD*);
61 void (WINAPI *pFnRestoreThunkLock)(DWORD);
63 /* ========================================================================
64 * G L O B A L S E T T I N G S
65 * ========================================================================*/
67 HINSTANCE hWinMM32Instance;
68 HANDLE psLastEvent;
69 HANDLE psStopEvent;
71 static CRITICAL_SECTION_DEBUG critsect_debug =
73 0, 0, &WINMM_cs,
74 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
75 0, 0, { (DWORD_PTR)(__FILE__ ": WINMM_cs") }
77 CRITICAL_SECTION WINMM_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
79 /**************************************************************************
80 * WINMM_CreateIData [internal]
82 static BOOL WINMM_CreateIData(HINSTANCE hInstDLL)
84 hWinMM32Instance = hInstDLL;
85 psStopEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
86 psLastEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
87 return TRUE;
90 /**************************************************************************
91 * WINMM_DeleteIData [internal]
93 static void WINMM_DeleteIData(void)
95 TIME_MMTimeStop();
97 /* FIXME: should also free content and resources allocated
98 * inside WINMM_IData */
99 CloseHandle(psStopEvent);
100 CloseHandle(psLastEvent);
101 DeleteCriticalSection(&WINMM_cs);
104 /******************************************************************
105 * WINMM_LoadMMSystem
108 static HANDLE (WINAPI *pGetModuleHandle16)(LPCSTR);
109 static DWORD (WINAPI *pLoadLibrary16)(LPCSTR);
111 BOOL WINMM_CheckForMMSystem(void)
113 /* 0 is not checked yet, -1 is not present, 1 is present */
114 static int loaded /* = 0 */;
116 if (loaded == 0)
118 HANDLE h = GetModuleHandleA("kernel32");
119 loaded = -1;
120 if (h)
122 pGetModuleHandle16 = (void*)GetProcAddress(h, "GetModuleHandle16");
123 pLoadLibrary16 = (void*)GetProcAddress(h, (LPCSTR)35); /* ordinal for LoadLibrary16 */
124 if (pGetModuleHandle16 && pLoadLibrary16 &&
125 (pGetModuleHandle16("MMSYSTEM.DLL") || pLoadLibrary16("MMSYSTEM.DLL")))
126 loaded = 1;
129 return loaded > 0;
132 /******************************************************************
133 * WINMM_ErrorToString
135 const char* WINMM_ErrorToString(MMRESULT error)
137 #define ERR_TO_STR(dev) case dev: return #dev
138 static char unknown[32];
139 switch (error) {
140 ERR_TO_STR(MMSYSERR_NOERROR);
141 ERR_TO_STR(MMSYSERR_ERROR);
142 ERR_TO_STR(MMSYSERR_BADDEVICEID);
143 ERR_TO_STR(MMSYSERR_NOTENABLED);
144 ERR_TO_STR(MMSYSERR_ALLOCATED);
145 ERR_TO_STR(MMSYSERR_INVALHANDLE);
146 ERR_TO_STR(MMSYSERR_NODRIVER);
147 ERR_TO_STR(MMSYSERR_NOMEM);
148 ERR_TO_STR(MMSYSERR_NOTSUPPORTED);
149 ERR_TO_STR(MMSYSERR_BADERRNUM);
150 ERR_TO_STR(MMSYSERR_INVALFLAG);
151 ERR_TO_STR(MMSYSERR_INVALPARAM);
152 ERR_TO_STR(MMSYSERR_HANDLEBUSY);
153 ERR_TO_STR(MMSYSERR_INVALIDALIAS);
154 ERR_TO_STR(MMSYSERR_BADDB);
155 ERR_TO_STR(MMSYSERR_KEYNOTFOUND);
156 ERR_TO_STR(MMSYSERR_READERROR);
157 ERR_TO_STR(MMSYSERR_WRITEERROR);
158 ERR_TO_STR(MMSYSERR_DELETEERROR);
159 ERR_TO_STR(MMSYSERR_VALNOTFOUND);
160 ERR_TO_STR(MMSYSERR_NODRIVERCB);
161 ERR_TO_STR(WAVERR_BADFORMAT);
162 ERR_TO_STR(WAVERR_STILLPLAYING);
163 ERR_TO_STR(WAVERR_UNPREPARED);
164 ERR_TO_STR(WAVERR_SYNC);
166 sprintf(unknown, "Unknown(0x%08x)", error);
167 return unknown;
168 #undef ERR_TO_STR
171 /**************************************************************************
172 * DllMain (WINMM.init)
174 * WINMM DLL entry point
177 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID fImpLoad)
179 TRACE("%p 0x%x %p\n", hInstDLL, fdwReason, fImpLoad);
181 switch (fdwReason) {
182 case DLL_PROCESS_ATTACH:
183 DisableThreadLibraryCalls(hInstDLL);
185 if (!WINMM_CreateIData(hInstDLL))
186 return FALSE;
187 if (!MMDRV_Init()) {
188 WINMM_DeleteIData();
189 return FALSE;
191 break;
192 case DLL_PROCESS_DETACH:
193 /* close all opened MCI drivers */
194 MCI_SendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_WAIT, 0L, TRUE);
195 MMDRV_Exit();
196 /* There's no guarantee the drivers haven't already been unloaded on
197 * process shutdown.
199 if (!fImpLoad)
201 /* now unload all remaining drivers... */
202 DRIVER_UnloadAll();
205 WINMM_DeleteIData();
206 break;
208 return TRUE;
211 /**************************************************************************
212 * Mixer devices. New to Win95
215 /**************************************************************************
216 * find out the real mixer ID depending on hmix (depends on dwFlags)
218 static UINT MIXER_GetDev(HMIXEROBJ hmix, DWORD dwFlags, LPWINE_MIXER * lplpwm)
220 LPWINE_MIXER lpwm = NULL;
221 UINT uRet = MMSYSERR_NOERROR;
223 switch (dwFlags & 0xF0000000ul) {
224 case MIXER_OBJECTF_MIXER:
225 lpwm = (LPWINE_MIXER)MMDRV_Get(hmix, MMDRV_MIXER, TRUE);
226 break;
227 case MIXER_OBJECTF_HMIXER:
228 lpwm = (LPWINE_MIXER)MMDRV_Get(hmix, MMDRV_MIXER, FALSE);
229 break;
230 case MIXER_OBJECTF_WAVEOUT:
231 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEOUT, TRUE, MMDRV_MIXER);
232 break;
233 case MIXER_OBJECTF_HWAVEOUT:
234 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEOUT, FALSE, MMDRV_MIXER);
235 break;
236 case MIXER_OBJECTF_WAVEIN:
237 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEIN, TRUE, MMDRV_MIXER);
238 break;
239 case MIXER_OBJECTF_HWAVEIN:
240 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEIN, FALSE, MMDRV_MIXER);
241 break;
242 case MIXER_OBJECTF_MIDIOUT:
243 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIOUT, TRUE, MMDRV_MIXER);
244 break;
245 case MIXER_OBJECTF_HMIDIOUT:
246 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIOUT, FALSE, MMDRV_MIXER);
247 break;
248 case MIXER_OBJECTF_MIDIIN:
249 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIIN, TRUE, MMDRV_MIXER);
250 break;
251 case MIXER_OBJECTF_HMIDIIN:
252 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIIN, FALSE, MMDRV_MIXER);
253 break;
254 case MIXER_OBJECTF_AUX:
255 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_AUX, TRUE, MMDRV_MIXER);
256 break;
257 default:
258 WARN("Unsupported flag (%08lx)\n", dwFlags & 0xF0000000ul);
259 lpwm = 0;
260 uRet = MMSYSERR_INVALFLAG;
261 break;
263 *lplpwm = lpwm;
264 if (lpwm == 0 && uRet == MMSYSERR_NOERROR)
265 uRet = MMSYSERR_INVALPARAM;
266 return uRet;
269 /**************************************************************************
270 * mixerGetNumDevs [WINMM.@]
272 UINT WINAPI mixerGetNumDevs(void)
274 return MMDRV_GetNum(MMDRV_MIXER);
277 /**************************************************************************
278 * mixerGetDevCapsA [WINMM.@]
280 UINT WINAPI mixerGetDevCapsA(UINT_PTR uDeviceID, LPMIXERCAPSA lpCaps, UINT uSize)
282 MIXERCAPSW micW;
283 UINT ret;
285 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
287 ret = mixerGetDevCapsW(uDeviceID, &micW, sizeof(micW));
289 if (ret == MMSYSERR_NOERROR) {
290 MIXERCAPSA micA;
291 micA.wMid = micW.wMid;
292 micA.wPid = micW.wPid;
293 micA.vDriverVersion = micW.vDriverVersion;
294 WideCharToMultiByte( CP_ACP, 0, micW.szPname, -1, micA.szPname,
295 sizeof(micA.szPname), NULL, NULL );
296 micA.fdwSupport = micW.fdwSupport;
297 micA.cDestinations = micW.cDestinations;
298 memcpy(lpCaps, &micA, min(uSize, sizeof(micA)));
300 return ret;
303 /**************************************************************************
304 * mixerGetDevCapsW [WINMM.@]
306 UINT WINAPI mixerGetDevCapsW(UINT_PTR uDeviceID, LPMIXERCAPSW lpCaps, UINT uSize)
308 LPWINE_MLD wmld;
310 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
312 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_MIXER, TRUE)) == NULL)
313 return MMSYSERR_BADDEVICEID;
315 return MMDRV_Message(wmld, MXDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
318 static void CALLBACK MIXER_WCallback(HMIXEROBJ hmx, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam, DWORD_PTR param2)
320 HWND hWnd = (HWND)dwInstance;
322 if (!dwInstance)
323 return;
325 PostMessageW(hWnd, uMsg, (WPARAM)hmx, (LPARAM)dwParam);
328 UINT MIXER_Open(LPHMIXER lphMix, UINT uDeviceID, DWORD_PTR dwCallback,
329 DWORD_PTR dwInstance, DWORD fdwOpen, BOOL bFrom32)
331 HANDLE hMix;
332 LPWINE_MLD wmld;
333 DWORD dwRet = 0;
334 MIXEROPENDESC mod;
336 TRACE("(%p, %d, %08lx, %08lx, %08x)\n",
337 lphMix, uDeviceID, dwCallback, dwInstance, fdwOpen);
339 mod.dwCallback = (DWORD_PTR)MIXER_WCallback;
340 mod.dwInstance = 0;
342 /* If callback is a function,
343 * dwCallback contains function pointer
344 * dwInstance private data
346 * if callback is a window
347 * dwCallback contains a window handle
349 switch (fdwOpen & CALLBACK_TYPEMASK) {
350 default:
351 return MMSYSERR_INVALFLAG;
353 case CALLBACK_NULL:
354 break;
356 case CALLBACK_WINDOW:
357 mod.dwInstance = dwCallback;
358 if (!IsWindow((HWND)dwCallback))
359 return MMSYSERR_INVALPARAM;
360 break;
363 wmld = MMDRV_Alloc(sizeof(WINE_MIXER), MMDRV_MIXER, &hMix, &fdwOpen,
364 &dwCallback, &dwInstance, bFrom32);
365 wmld->uDeviceID = uDeviceID;
366 mod.hmx = (HMIXEROBJ)hMix;
368 dwRet = MMDRV_Open(wmld, MXDM_OPEN, (DWORD)&mod, CALLBACK_FUNCTION);
370 if (dwRet != MMSYSERR_NOERROR) {
371 MMDRV_Free(hMix, wmld);
372 hMix = 0;
374 if (lphMix) *lphMix = hMix;
375 TRACE("=> %d hMixer=%p\n", dwRet, hMix);
377 return dwRet;
380 /**************************************************************************
381 * mixerOpen [WINMM.@]
383 UINT WINAPI mixerOpen(LPHMIXER lphMix, UINT uDeviceID, DWORD_PTR dwCallback,
384 DWORD_PTR dwInstance, DWORD fdwOpen)
386 return MIXER_Open(lphMix, uDeviceID, dwCallback, dwInstance, fdwOpen, TRUE);
389 /**************************************************************************
390 * mixerClose [WINMM.@]
392 UINT WINAPI mixerClose(HMIXER hMix)
394 LPWINE_MLD wmld;
395 DWORD dwRet;
397 TRACE("(%p)\n", hMix);
399 if ((wmld = MMDRV_Get(hMix, MMDRV_MIXER, FALSE)) == NULL) return MMSYSERR_INVALHANDLE;
401 dwRet = MMDRV_Close(wmld, MXDM_CLOSE);
402 MMDRV_Free(hMix, wmld);
404 return dwRet;
407 /**************************************************************************
408 * mixerGetID [WINMM.@]
410 UINT WINAPI mixerGetID(HMIXEROBJ hmix, LPUINT lpid, DWORD fdwID)
412 LPWINE_MIXER lpwm;
413 UINT uRet = MMSYSERR_NOERROR;
415 TRACE("(%p %p %08x)\n", hmix, lpid, fdwID);
417 if ((uRet = MIXER_GetDev(hmix, fdwID, &lpwm)) != MMSYSERR_NOERROR)
418 return uRet;
420 if (lpid)
421 *lpid = lpwm->mld.uDeviceID;
423 return uRet;
426 /**************************************************************************
427 * mixerGetControlDetailsW [WINMM.@]
429 UINT WINAPI mixerGetControlDetailsW(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcdW,
430 DWORD fdwDetails)
432 LPWINE_MIXER lpwm;
433 UINT uRet = MMSYSERR_NOERROR;
435 TRACE("(%p, %p, %08x)\n", hmix, lpmcdW, fdwDetails);
437 if ((uRet = MIXER_GetDev(hmix, fdwDetails, &lpwm)) != MMSYSERR_NOERROR)
438 return uRet;
440 if (lpmcdW == NULL || lpmcdW->cbStruct != sizeof(*lpmcdW))
441 return MMSYSERR_INVALPARAM;
443 return MMDRV_Message(&lpwm->mld, MXDM_GETCONTROLDETAILS, (DWORD_PTR)lpmcdW,
444 fdwDetails, TRUE);
447 /**************************************************************************
448 * mixerGetControlDetailsA [WINMM.@]
450 UINT WINAPI mixerGetControlDetailsA(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcdA,
451 DWORD fdwDetails)
453 DWORD ret = MMSYSERR_NOTENABLED;
455 TRACE("(%p, %p, %08x)\n", hmix, lpmcdA, fdwDetails);
457 if (lpmcdA == NULL || lpmcdA->cbStruct != sizeof(*lpmcdA))
458 return MMSYSERR_INVALPARAM;
460 switch (fdwDetails & MIXER_GETCONTROLDETAILSF_QUERYMASK) {
461 case MIXER_GETCONTROLDETAILSF_VALUE:
462 /* can safely use A structure as it is, no string inside */
463 ret = mixerGetControlDetailsW(hmix, lpmcdA, fdwDetails);
464 break;
465 case MIXER_GETCONTROLDETAILSF_LISTTEXT:
467 MIXERCONTROLDETAILS_LISTTEXTA *pDetailsA = (MIXERCONTROLDETAILS_LISTTEXTA *)lpmcdA->paDetails;
468 MIXERCONTROLDETAILS_LISTTEXTW *pDetailsW;
469 int size = max(1, lpmcdA->cChannels) * sizeof(MIXERCONTROLDETAILS_LISTTEXTW);
470 unsigned int i;
472 if (lpmcdA->u.cMultipleItems != 0) {
473 size *= lpmcdA->u.cMultipleItems;
475 pDetailsW = HeapAlloc(GetProcessHeap(), 0, size);
476 lpmcdA->paDetails = pDetailsW;
477 lpmcdA->cbDetails = sizeof(MIXERCONTROLDETAILS_LISTTEXTW);
478 /* set up lpmcd->paDetails */
479 ret = mixerGetControlDetailsW(hmix, lpmcdA, fdwDetails);
480 /* copy from lpmcd->paDetails back to paDetailsW; */
481 if (ret == MMSYSERR_NOERROR) {
482 for (i = 0; i < lpmcdA->u.cMultipleItems * lpmcdA->cChannels; i++) {
483 pDetailsA->dwParam1 = pDetailsW->dwParam1;
484 pDetailsA->dwParam2 = pDetailsW->dwParam2;
485 WideCharToMultiByte( CP_ACP, 0, pDetailsW->szName, -1,
486 pDetailsA->szName,
487 sizeof(pDetailsA->szName), NULL, NULL );
488 pDetailsA++;
489 pDetailsW++;
491 pDetailsA -= lpmcdA->u.cMultipleItems * lpmcdA->cChannels;
492 pDetailsW -= lpmcdA->u.cMultipleItems * lpmcdA->cChannels;
494 HeapFree(GetProcessHeap(), 0, pDetailsW);
495 lpmcdA->paDetails = pDetailsA;
496 lpmcdA->cbDetails = sizeof(MIXERCONTROLDETAILS_LISTTEXTA);
498 break;
499 default:
500 ERR("Unsupported fdwDetails=0x%08x\n", fdwDetails);
503 return ret;
506 /**************************************************************************
507 * mixerGetLineControlsA [WINMM.@]
509 UINT WINAPI mixerGetLineControlsA(HMIXEROBJ hmix, LPMIXERLINECONTROLSA lpmlcA,
510 DWORD fdwControls)
512 MIXERLINECONTROLSW mlcW;
513 DWORD ret;
514 unsigned int i;
516 TRACE("(%p, %p, %08x)\n", hmix, lpmlcA, fdwControls);
518 if (lpmlcA == NULL || lpmlcA->cbStruct != sizeof(*lpmlcA) ||
519 lpmlcA->cbmxctrl != sizeof(MIXERCONTROLA))
520 return MMSYSERR_INVALPARAM;
522 mlcW.cbStruct = sizeof(mlcW);
523 mlcW.dwLineID = lpmlcA->dwLineID;
524 mlcW.u.dwControlID = lpmlcA->u.dwControlID;
525 mlcW.u.dwControlType = lpmlcA->u.dwControlType;
527 /* Debugging on Windows shows for MIXER_GETLINECONTROLSF_ONEBYTYPE only,
528 the control count is assumed to be 1 - This is relied upon by a game,
529 "Dynomite Deluze" */
530 if (MIXER_GETLINECONTROLSF_ONEBYTYPE == (fdwControls & MIXER_GETLINECONTROLSF_QUERYMASK)) {
531 mlcW.cControls = 1;
532 } else {
533 mlcW.cControls = lpmlcA->cControls;
535 mlcW.cbmxctrl = sizeof(MIXERCONTROLW);
536 mlcW.pamxctrl = HeapAlloc(GetProcessHeap(), 0,
537 mlcW.cControls * mlcW.cbmxctrl);
539 ret = mixerGetLineControlsW(hmix, &mlcW, fdwControls);
541 if (ret == MMSYSERR_NOERROR) {
542 lpmlcA->dwLineID = mlcW.dwLineID;
543 lpmlcA->u.dwControlID = mlcW.u.dwControlID;
544 lpmlcA->u.dwControlType = mlcW.u.dwControlType;
546 for (i = 0; i < mlcW.cControls; i++) {
547 lpmlcA->pamxctrl[i].cbStruct = sizeof(MIXERCONTROLA);
548 lpmlcA->pamxctrl[i].dwControlID = mlcW.pamxctrl[i].dwControlID;
549 lpmlcA->pamxctrl[i].dwControlType = mlcW.pamxctrl[i].dwControlType;
550 lpmlcA->pamxctrl[i].fdwControl = mlcW.pamxctrl[i].fdwControl;
551 lpmlcA->pamxctrl[i].cMultipleItems = mlcW.pamxctrl[i].cMultipleItems;
552 WideCharToMultiByte( CP_ACP, 0, mlcW.pamxctrl[i].szShortName, -1,
553 lpmlcA->pamxctrl[i].szShortName,
554 sizeof(lpmlcA->pamxctrl[i].szShortName), NULL, NULL );
555 WideCharToMultiByte( CP_ACP, 0, mlcW.pamxctrl[i].szName, -1,
556 lpmlcA->pamxctrl[i].szName,
557 sizeof(lpmlcA->pamxctrl[i].szName), NULL, NULL );
558 /* sizeof(lpmlcA->pamxctrl[i].Bounds) ==
559 * sizeof(mlcW.pamxctrl[i].Bounds) */
560 memcpy(&lpmlcA->pamxctrl[i].Bounds, &mlcW.pamxctrl[i].Bounds,
561 sizeof(mlcW.pamxctrl[i].Bounds));
562 /* sizeof(lpmlcA->pamxctrl[i].Metrics) ==
563 * sizeof(mlcW.pamxctrl[i].Metrics) */
564 memcpy(&lpmlcA->pamxctrl[i].Metrics, &mlcW.pamxctrl[i].Metrics,
565 sizeof(mlcW.pamxctrl[i].Metrics));
569 HeapFree(GetProcessHeap(), 0, mlcW.pamxctrl);
571 return ret;
574 /**************************************************************************
575 * mixerGetLineControlsW [WINMM.@]
577 UINT WINAPI mixerGetLineControlsW(HMIXEROBJ hmix, LPMIXERLINECONTROLSW lpmlcW,
578 DWORD fdwControls)
580 LPWINE_MIXER lpwm;
581 UINT uRet = MMSYSERR_NOERROR;
583 TRACE("(%p, %p, %08x)\n", hmix, lpmlcW, fdwControls);
585 if ((uRet = MIXER_GetDev(hmix, fdwControls, &lpwm)) != MMSYSERR_NOERROR)
586 return uRet;
588 if (lpmlcW == NULL || lpmlcW->cbStruct != sizeof(*lpmlcW))
589 return MMSYSERR_INVALPARAM;
591 return MMDRV_Message(&lpwm->mld, MXDM_GETLINECONTROLS, (DWORD_PTR)lpmlcW,
592 fdwControls, TRUE);
595 /**************************************************************************
596 * mixerGetLineInfoW [WINMM.@]
598 UINT WINAPI mixerGetLineInfoW(HMIXEROBJ hmix, LPMIXERLINEW lpmliW, DWORD fdwInfo)
600 LPWINE_MIXER lpwm;
601 UINT uRet = MMSYSERR_NOERROR;
603 TRACE("(%p, %p, %08x)\n", hmix, lpmliW, fdwInfo);
605 if ((uRet = MIXER_GetDev(hmix, fdwInfo, &lpwm)) != MMSYSERR_NOERROR)
606 return uRet;
608 return MMDRV_Message(&lpwm->mld, MXDM_GETLINEINFO, (DWORD_PTR)lpmliW,
609 fdwInfo, TRUE);
612 /**************************************************************************
613 * mixerGetLineInfoA [WINMM.@]
615 UINT WINAPI mixerGetLineInfoA(HMIXEROBJ hmix, LPMIXERLINEA lpmliA,
616 DWORD fdwInfo)
618 MIXERLINEW mliW;
619 UINT ret;
621 TRACE("(%p, %p, %08x)\n", hmix, lpmliA, fdwInfo);
623 if (lpmliA == NULL || lpmliA->cbStruct != sizeof(*lpmliA))
624 return MMSYSERR_INVALPARAM;
626 mliW.cbStruct = sizeof(mliW);
627 switch (fdwInfo & MIXER_GETLINEINFOF_QUERYMASK) {
628 case MIXER_GETLINEINFOF_COMPONENTTYPE:
629 mliW.dwComponentType = lpmliA->dwComponentType;
630 break;
631 case MIXER_GETLINEINFOF_DESTINATION:
632 mliW.dwDestination = lpmliA->dwDestination;
633 break;
634 case MIXER_GETLINEINFOF_LINEID:
635 mliW.dwLineID = lpmliA->dwLineID;
636 break;
637 case MIXER_GETLINEINFOF_SOURCE:
638 mliW.dwDestination = lpmliA->dwDestination;
639 mliW.dwSource = lpmliA->dwSource;
640 break;
641 case MIXER_GETLINEINFOF_TARGETTYPE:
642 mliW.Target.dwType = lpmliA->Target.dwType;
643 mliW.Target.wMid = lpmliA->Target.wMid;
644 mliW.Target.wPid = lpmliA->Target.wPid;
645 mliW.Target.vDriverVersion = lpmliA->Target.vDriverVersion;
646 MultiByteToWideChar( CP_ACP, 0, lpmliA->Target.szPname, -1, mliW.Target.szPname, sizeof(mliW.Target.szPname)/sizeof(WCHAR));
647 break;
648 default:
649 WARN("Unsupported fdwControls=0x%08x\n", fdwInfo);
650 return MMSYSERR_INVALFLAG;
653 ret = mixerGetLineInfoW(hmix, &mliW, fdwInfo);
655 if(ret == MMSYSERR_NOERROR)
657 lpmliA->dwDestination = mliW.dwDestination;
658 lpmliA->dwSource = mliW.dwSource;
659 lpmliA->dwLineID = mliW.dwLineID;
660 lpmliA->fdwLine = mliW.fdwLine;
661 lpmliA->dwUser = mliW.dwUser;
662 lpmliA->dwComponentType = mliW.dwComponentType;
663 lpmliA->cChannels = mliW.cChannels;
664 lpmliA->cConnections = mliW.cConnections;
665 lpmliA->cControls = mliW.cControls;
666 WideCharToMultiByte( CP_ACP, 0, mliW.szShortName, -1, lpmliA->szShortName,
667 sizeof(lpmliA->szShortName), NULL, NULL);
668 WideCharToMultiByte( CP_ACP, 0, mliW.szName, -1, lpmliA->szName,
669 sizeof(lpmliA->szName), NULL, NULL );
670 lpmliA->Target.dwType = mliW.Target.dwType;
671 lpmliA->Target.dwDeviceID = mliW.Target.dwDeviceID;
672 lpmliA->Target.wMid = mliW.Target.wMid;
673 lpmliA->Target.wPid = mliW.Target.wPid;
674 lpmliA->Target.vDriverVersion = mliW.Target.vDriverVersion;
675 WideCharToMultiByte( CP_ACP, 0, mliW.Target.szPname, -1, lpmliA->Target.szPname,
676 sizeof(lpmliA->Target.szPname), NULL, NULL );
678 return ret;
681 /**************************************************************************
682 * mixerSetControlDetails [WINMM.@]
684 UINT WINAPI mixerSetControlDetails(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcd,
685 DWORD fdwDetails)
687 LPWINE_MIXER lpwm;
688 UINT uRet = MMSYSERR_NOERROR;
690 TRACE("(%p, %p, %08x)\n", hmix, lpmcd, fdwDetails);
692 if ((uRet = MIXER_GetDev(hmix, fdwDetails, &lpwm)) != MMSYSERR_NOERROR)
693 return uRet;
695 return MMDRV_Message(&lpwm->mld, MXDM_SETCONTROLDETAILS, (DWORD_PTR)lpmcd,
696 fdwDetails, TRUE);
699 /**************************************************************************
700 * mixerMessage [WINMM.@]
702 DWORD WINAPI mixerMessage(HMIXER hmix, UINT uMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
704 LPWINE_MLD wmld;
706 TRACE("(%p, %d, %08lx, %08lx): semi-stub?\n",
707 hmix, uMsg, dwParam1, dwParam2);
709 if ((wmld = MMDRV_Get(hmix, MMDRV_MIXER, FALSE)) == NULL)
710 return MMSYSERR_INVALHANDLE;
712 return MMDRV_Message(wmld, uMsg, dwParam1, dwParam2, TRUE);
715 /**************************************************************************
716 * auxGetNumDevs [WINMM.@]
718 UINT WINAPI auxGetNumDevs(void)
720 return MMDRV_GetNum(MMDRV_AUX);
723 /**************************************************************************
724 * auxGetDevCapsW [WINMM.@]
726 UINT WINAPI auxGetDevCapsW(UINT_PTR uDeviceID, LPAUXCAPSW lpCaps, UINT uSize)
728 LPWINE_MLD wmld;
730 TRACE("(%04lX, %p, %d) !\n", uDeviceID, lpCaps, uSize);
732 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
734 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
735 return MMSYSERR_INVALHANDLE;
736 return MMDRV_Message(wmld, AUXDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
739 /**************************************************************************
740 * auxGetDevCapsA [WINMM.@]
742 UINT WINAPI auxGetDevCapsA(UINT_PTR uDeviceID, LPAUXCAPSA lpCaps, UINT uSize)
744 AUXCAPSW acW;
745 UINT ret;
747 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
749 ret = auxGetDevCapsW(uDeviceID, &acW, sizeof(acW));
751 if (ret == MMSYSERR_NOERROR) {
752 AUXCAPSA acA;
753 acA.wMid = acW.wMid;
754 acA.wPid = acW.wPid;
755 acA.vDriverVersion = acW.vDriverVersion;
756 WideCharToMultiByte( CP_ACP, 0, acW.szPname, -1, acA.szPname,
757 sizeof(acA.szPname), NULL, NULL );
758 acA.wTechnology = acW.wTechnology;
759 acA.dwSupport = acW.dwSupport;
760 memcpy(lpCaps, &acA, min(uSize, sizeof(acA)));
762 return ret;
765 /**************************************************************************
766 * auxGetVolume [WINMM.@]
768 UINT WINAPI auxGetVolume(UINT uDeviceID, DWORD* lpdwVolume)
770 LPWINE_MLD wmld;
772 TRACE("(%04X, %p) !\n", uDeviceID, lpdwVolume);
774 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
775 return MMSYSERR_INVALHANDLE;
776 return MMDRV_Message(wmld, AUXDM_GETVOLUME, (DWORD_PTR)lpdwVolume, 0L, TRUE);
779 /**************************************************************************
780 * auxSetVolume [WINMM.@]
782 UINT WINAPI auxSetVolume(UINT uDeviceID, DWORD dwVolume)
784 LPWINE_MLD wmld;
786 TRACE("(%04X, %u) !\n", uDeviceID, dwVolume);
788 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
789 return MMSYSERR_INVALHANDLE;
790 return MMDRV_Message(wmld, AUXDM_SETVOLUME, dwVolume, 0L, TRUE);
793 /**************************************************************************
794 * auxOutMessage [WINMM.@]
796 UINT WINAPI auxOutMessage(UINT uDeviceID, UINT uMessage, DWORD_PTR dw1, DWORD_PTR dw2)
798 LPWINE_MLD wmld;
800 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
801 return MMSYSERR_INVALHANDLE;
803 return MMDRV_Message(wmld, uMessage, dw1, dw2, TRUE);
806 /**************************************************************************
807 * midiOutGetNumDevs [WINMM.@]
809 UINT WINAPI midiOutGetNumDevs(void)
811 return MMDRV_GetNum(MMDRV_MIDIOUT);
814 /**************************************************************************
815 * midiOutGetDevCapsW [WINMM.@]
817 UINT WINAPI midiOutGetDevCapsW(UINT_PTR uDeviceID, LPMIDIOUTCAPSW lpCaps,
818 UINT uSize)
820 LPWINE_MLD wmld;
822 TRACE("(%lu, %p, %u);\n", uDeviceID, lpCaps, uSize);
824 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
826 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_MIDIOUT, TRUE)) == NULL)
827 return MMSYSERR_INVALHANDLE;
829 return MMDRV_Message(wmld, MODM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
832 /**************************************************************************
833 * midiOutGetDevCapsA [WINMM.@]
835 UINT WINAPI midiOutGetDevCapsA(UINT_PTR uDeviceID, LPMIDIOUTCAPSA lpCaps,
836 UINT uSize)
838 MIDIOUTCAPSW mocW;
839 UINT ret;
841 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
843 ret = midiOutGetDevCapsW(uDeviceID, &mocW, sizeof(mocW));
845 if (ret == MMSYSERR_NOERROR) {
846 MIDIOUTCAPSA mocA;
847 mocA.wMid = mocW.wMid;
848 mocA.wPid = mocW.wPid;
849 mocA.vDriverVersion = mocW.vDriverVersion;
850 WideCharToMultiByte( CP_ACP, 0, mocW.szPname, -1, mocA.szPname,
851 sizeof(mocA.szPname), NULL, NULL );
852 mocA.wTechnology = mocW.wTechnology;
853 mocA.wVoices = mocW.wVoices;
854 mocA.wNotes = mocW.wNotes;
855 mocA.wChannelMask = mocW.wChannelMask;
856 mocA.dwSupport = mocW.dwSupport;
857 memcpy(lpCaps, &mocA, min(uSize, sizeof(mocA)));
859 return ret;
862 /**************************************************************************
863 * midiOutGetErrorTextA [WINMM.@]
864 * midiInGetErrorTextA [WINMM.@]
866 UINT WINAPI midiOutGetErrorTextA(UINT uError, LPSTR lpText, UINT uSize)
868 UINT ret;
870 if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
871 else if (uSize == 0) ret = MMSYSERR_NOERROR;
872 else
874 LPWSTR xstr = HeapAlloc(GetProcessHeap(), 0, uSize * sizeof(WCHAR));
875 if (!xstr) ret = MMSYSERR_NOMEM;
876 else
878 ret = midiOutGetErrorTextW(uError, xstr, uSize);
879 if (ret == MMSYSERR_NOERROR)
880 WideCharToMultiByte(CP_ACP, 0, xstr, -1, lpText, uSize, NULL, NULL);
881 HeapFree(GetProcessHeap(), 0, xstr);
884 return ret;
887 /**************************************************************************
888 * midiOutGetErrorTextW [WINMM.@]
889 * midiInGetErrorTextW [WINMM.@]
891 UINT WINAPI midiOutGetErrorTextW(UINT uError, LPWSTR lpText, UINT uSize)
893 UINT ret = MMSYSERR_BADERRNUM;
895 if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
896 else if (uSize == 0) ret = MMSYSERR_NOERROR;
897 else if (
898 /* test has been removed because MMSYSERR_BASE is 0, and gcc did emit
899 * a warning for the test was always true */
900 (/*uError >= MMSYSERR_BASE && */ uError <= MMSYSERR_LASTERROR) ||
901 (uError >= MIDIERR_BASE && uError <= MIDIERR_LASTERROR)) {
902 if (LoadStringW(hWinMM32Instance, uError, lpText, uSize) > 0) {
903 ret = MMSYSERR_NOERROR;
906 return ret;
909 /**************************************************************************
910 * MIDI_OutAlloc [internal]
912 static LPWINE_MIDI MIDI_OutAlloc(HMIDIOUT* lphMidiOut, DWORD_PTR* lpdwCallback,
913 DWORD_PTR* lpdwInstance, LPDWORD lpdwFlags,
914 DWORD cIDs, MIDIOPENSTRMID* lpIDs, BOOL bFrom32)
916 HANDLE hMidiOut;
917 LPWINE_MIDI lpwm;
918 UINT size;
920 size = sizeof(WINE_MIDI) + (cIDs ? (cIDs-1) : 0) * sizeof(MIDIOPENSTRMID);
922 lpwm = (LPWINE_MIDI)MMDRV_Alloc(size, MMDRV_MIDIOUT, &hMidiOut, lpdwFlags,
923 lpdwCallback, lpdwInstance, bFrom32);
925 if (lphMidiOut != NULL)
926 *lphMidiOut = hMidiOut;
928 if (lpwm) {
929 lpwm->mod.hMidi = (HMIDI) hMidiOut;
930 lpwm->mod.dwCallback = *lpdwCallback;
931 lpwm->mod.dwInstance = *lpdwInstance;
932 lpwm->mod.dnDevNode = 0;
933 lpwm->mod.cIds = cIDs;
934 if (cIDs)
935 memcpy(&(lpwm->mod.rgIds), lpIDs, cIDs * sizeof(MIDIOPENSTRMID));
937 return lpwm;
940 UINT MIDI_OutOpen(LPHMIDIOUT lphMidiOut, UINT uDeviceID, DWORD_PTR dwCallback,
941 DWORD_PTR dwInstance, DWORD dwFlags, BOOL bFrom32)
943 HMIDIOUT hMidiOut;
944 LPWINE_MIDI lpwm;
945 UINT dwRet = 0;
947 TRACE("(%p, %d, %08lX, %08lX, %08X);\n",
948 lphMidiOut, uDeviceID, dwCallback, dwInstance, dwFlags);
950 if (lphMidiOut != NULL) *lphMidiOut = 0;
952 lpwm = MIDI_OutAlloc(&hMidiOut, &dwCallback, &dwInstance, &dwFlags,
953 0, NULL, bFrom32);
955 if (lpwm == NULL)
956 return MMSYSERR_NOMEM;
958 lpwm->mld.uDeviceID = uDeviceID;
960 dwRet = MMDRV_Open((LPWINE_MLD)lpwm, MODM_OPEN, (DWORD)&lpwm->mod, dwFlags);
962 if (dwRet != MMSYSERR_NOERROR) {
963 MMDRV_Free(hMidiOut, (LPWINE_MLD)lpwm);
964 hMidiOut = 0;
967 if (lphMidiOut) *lphMidiOut = hMidiOut;
968 TRACE("=> %d hMidi=%p\n", dwRet, hMidiOut);
970 return dwRet;
973 /**************************************************************************
974 * midiOutOpen [WINMM.@]
976 UINT WINAPI midiOutOpen(LPHMIDIOUT lphMidiOut, UINT uDeviceID,
977 DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD dwFlags)
979 return MIDI_OutOpen(lphMidiOut, uDeviceID, dwCallback, dwInstance, dwFlags, TRUE);
982 /**************************************************************************
983 * midiOutClose [WINMM.@]
985 UINT WINAPI midiOutClose(HMIDIOUT hMidiOut)
987 LPWINE_MLD wmld;
988 DWORD dwRet;
990 TRACE("(%p)\n", hMidiOut);
992 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
993 return MMSYSERR_INVALHANDLE;
995 dwRet = MMDRV_Close(wmld, MODM_CLOSE);
996 MMDRV_Free(hMidiOut, wmld);
998 return dwRet;
1001 /**************************************************************************
1002 * midiOutPrepareHeader [WINMM.@]
1004 UINT WINAPI midiOutPrepareHeader(HMIDIOUT hMidiOut,
1005 MIDIHDR* lpMidiOutHdr, UINT uSize)
1007 LPWINE_MLD wmld;
1009 TRACE("(%p, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
1011 if (lpMidiOutHdr == NULL || uSize < sizeof (MIDIHDR))
1012 return MMSYSERR_INVALPARAM;
1014 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1015 return MMSYSERR_INVALHANDLE;
1017 return MMDRV_Message(wmld, MODM_PREPARE, (DWORD_PTR)lpMidiOutHdr, uSize, TRUE);
1020 /**************************************************************************
1021 * midiOutUnprepareHeader [WINMM.@]
1023 UINT WINAPI midiOutUnprepareHeader(HMIDIOUT hMidiOut,
1024 MIDIHDR* lpMidiOutHdr, UINT uSize)
1026 LPWINE_MLD wmld;
1028 TRACE("(%p, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
1030 if (lpMidiOutHdr == NULL || uSize < sizeof (MIDIHDR))
1031 return MMSYSERR_INVALPARAM;
1033 if (!(lpMidiOutHdr->dwFlags & MHDR_PREPARED)) {
1034 return MMSYSERR_NOERROR;
1037 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1038 return MMSYSERR_INVALHANDLE;
1040 return MMDRV_Message(wmld, MODM_UNPREPARE, (DWORD_PTR)lpMidiOutHdr, uSize, TRUE);
1043 /**************************************************************************
1044 * midiOutShortMsg [WINMM.@]
1046 UINT WINAPI midiOutShortMsg(HMIDIOUT hMidiOut, DWORD dwMsg)
1048 LPWINE_MLD wmld;
1050 TRACE("(%p, %08X)\n", hMidiOut, dwMsg);
1052 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1053 return MMSYSERR_INVALHANDLE;
1055 return MMDRV_Message(wmld, MODM_DATA, dwMsg, 0L, TRUE);
1058 /**************************************************************************
1059 * midiOutLongMsg [WINMM.@]
1061 UINT WINAPI midiOutLongMsg(HMIDIOUT hMidiOut,
1062 MIDIHDR* lpMidiOutHdr, UINT uSize)
1064 LPWINE_MLD wmld;
1066 TRACE("(%p, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
1068 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1069 return MMSYSERR_INVALHANDLE;
1071 return MMDRV_Message(wmld, MODM_LONGDATA, (DWORD_PTR)lpMidiOutHdr, uSize, TRUE);
1074 /**************************************************************************
1075 * midiOutReset [WINMM.@]
1077 UINT WINAPI midiOutReset(HMIDIOUT hMidiOut)
1079 LPWINE_MLD wmld;
1081 TRACE("(%p)\n", hMidiOut);
1083 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1084 return MMSYSERR_INVALHANDLE;
1086 return MMDRV_Message(wmld, MODM_RESET, 0L, 0L, TRUE);
1089 /**************************************************************************
1090 * midiOutGetVolume [WINMM.@]
1092 UINT WINAPI midiOutGetVolume(HMIDIOUT hMidiOut, DWORD* lpdwVolume)
1094 LPWINE_MLD wmld;
1096 TRACE("(%p, %p);\n", hMidiOut, lpdwVolume);
1098 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, TRUE)) == NULL)
1099 return MMSYSERR_INVALHANDLE;
1101 return MMDRV_Message(wmld, MODM_GETVOLUME, (DWORD_PTR)lpdwVolume, 0L, TRUE);
1104 /**************************************************************************
1105 * midiOutSetVolume [WINMM.@]
1107 UINT WINAPI midiOutSetVolume(HMIDIOUT hMidiOut, DWORD dwVolume)
1109 LPWINE_MLD wmld;
1111 TRACE("(%p, %d);\n", hMidiOut, dwVolume);
1113 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, TRUE)) == NULL)
1114 return MMSYSERR_INVALHANDLE;
1116 return MMDRV_Message(wmld, MODM_SETVOLUME, dwVolume, 0L, TRUE);
1119 /**************************************************************************
1120 * midiOutCachePatches [WINMM.@]
1122 UINT WINAPI midiOutCachePatches(HMIDIOUT hMidiOut, UINT uBank,
1123 WORD* lpwPatchArray, UINT uFlags)
1125 /* not really necessary to support this */
1126 FIXME("not supported yet\n");
1127 return MMSYSERR_NOTSUPPORTED;
1130 /**************************************************************************
1131 * midiOutCacheDrumPatches [WINMM.@]
1133 UINT WINAPI midiOutCacheDrumPatches(HMIDIOUT hMidiOut, UINT uPatch,
1134 WORD* lpwKeyArray, UINT uFlags)
1136 FIXME("not supported yet\n");
1137 return MMSYSERR_NOTSUPPORTED;
1140 /**************************************************************************
1141 * midiOutGetID [WINMM.@]
1143 UINT WINAPI midiOutGetID(HMIDIOUT hMidiOut, UINT* lpuDeviceID)
1145 LPWINE_MLD wmld;
1147 TRACE("(%p, %p)\n", hMidiOut, lpuDeviceID);
1149 if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
1150 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1151 return MMSYSERR_INVALHANDLE;
1153 *lpuDeviceID = wmld->uDeviceID;
1154 return MMSYSERR_NOERROR;
1157 /**************************************************************************
1158 * midiOutMessage [WINMM.@]
1160 UINT WINAPI midiOutMessage(HMIDIOUT hMidiOut, UINT uMessage,
1161 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1163 LPWINE_MLD wmld;
1165 TRACE("(%p, %04X, %08lX, %08lX)\n", hMidiOut, uMessage, dwParam1, dwParam2);
1167 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL) {
1168 /* HACK... */
1169 if (uMessage == 0x0001) {
1170 *(LPDWORD)dwParam1 = 1;
1171 return 0;
1173 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, TRUE)) != NULL) {
1174 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
1176 return MMSYSERR_INVALHANDLE;
1179 switch (uMessage) {
1180 case MODM_OPEN:
1181 case MODM_CLOSE:
1182 FIXME("can't handle OPEN or CLOSE message!\n");
1183 return MMSYSERR_NOTSUPPORTED;
1185 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
1188 /**************************************************************************
1189 * midiInGetNumDevs [WINMM.@]
1191 UINT WINAPI midiInGetNumDevs(void)
1193 return MMDRV_GetNum(MMDRV_MIDIIN);
1196 /**************************************************************************
1197 * midiInGetDevCapsW [WINMM.@]
1199 UINT WINAPI midiInGetDevCapsW(UINT_PTR uDeviceID, LPMIDIINCAPSW lpCaps, UINT uSize)
1201 LPWINE_MLD wmld;
1203 TRACE("(%ld, %p, %d);\n", uDeviceID, lpCaps, uSize);
1205 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
1207 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_MIDIIN, TRUE)) == NULL)
1208 return MMSYSERR_INVALHANDLE;
1210 return MMDRV_Message(wmld, MIDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
1213 /**************************************************************************
1214 * midiInGetDevCapsA [WINMM.@]
1216 UINT WINAPI midiInGetDevCapsA(UINT_PTR uDeviceID, LPMIDIINCAPSA lpCaps, UINT uSize)
1218 MIDIINCAPSW micW;
1219 UINT ret;
1221 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
1223 ret = midiInGetDevCapsW(uDeviceID, &micW, sizeof(micW));
1225 if (ret == MMSYSERR_NOERROR) {
1226 MIDIINCAPSA micA;
1227 micA.wMid = micW.wMid;
1228 micA.wPid = micW.wPid;
1229 micA.vDriverVersion = micW.vDriverVersion;
1230 WideCharToMultiByte( CP_ACP, 0, micW.szPname, -1, micA.szPname,
1231 sizeof(micA.szPname), NULL, NULL );
1232 micA.dwSupport = micW.dwSupport;
1233 memcpy(lpCaps, &micA, min(uSize, sizeof(micA)));
1235 return ret;
1238 UINT MIDI_InOpen(HMIDIIN* lphMidiIn, UINT uDeviceID, DWORD_PTR dwCallback,
1239 DWORD_PTR dwInstance, DWORD dwFlags, BOOL bFrom32)
1241 HANDLE hMidiIn;
1242 LPWINE_MIDI lpwm;
1243 DWORD dwRet = 0;
1245 TRACE("(%p, %d, %08lX, %08lX, %08X);\n",
1246 lphMidiIn, uDeviceID, dwCallback, dwInstance, dwFlags);
1248 if (lphMidiIn != NULL) *lphMidiIn = 0;
1250 lpwm = (LPWINE_MIDI)MMDRV_Alloc(sizeof(WINE_MIDI), MMDRV_MIDIIN, &hMidiIn,
1251 &dwFlags, &dwCallback, &dwInstance, bFrom32);
1253 if (lpwm == NULL)
1254 return MMSYSERR_NOMEM;
1256 lpwm->mod.hMidi = (HMIDI) hMidiIn;
1257 lpwm->mod.dwCallback = dwCallback;
1258 lpwm->mod.dwInstance = dwInstance;
1260 lpwm->mld.uDeviceID = uDeviceID;
1261 dwRet = MMDRV_Open(&lpwm->mld, MIDM_OPEN, (DWORD)&lpwm->mod, dwFlags);
1263 if (dwRet != MMSYSERR_NOERROR) {
1264 MMDRV_Free(hMidiIn, &lpwm->mld);
1265 hMidiIn = 0;
1267 if (lphMidiIn != NULL) *lphMidiIn = hMidiIn;
1268 TRACE("=> %d hMidi=%p\n", dwRet, hMidiIn);
1270 return dwRet;
1273 /**************************************************************************
1274 * midiInOpen [WINMM.@]
1276 UINT WINAPI midiInOpen(HMIDIIN* lphMidiIn, UINT uDeviceID,
1277 DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD dwFlags)
1279 return MIDI_InOpen(lphMidiIn, uDeviceID, dwCallback, dwInstance, dwFlags, TRUE);
1282 /**************************************************************************
1283 * midiInClose [WINMM.@]
1285 UINT WINAPI midiInClose(HMIDIIN hMidiIn)
1287 LPWINE_MLD wmld;
1288 DWORD dwRet;
1290 TRACE("(%p)\n", hMidiIn);
1292 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1293 return MMSYSERR_INVALHANDLE;
1295 dwRet = MMDRV_Close(wmld, MIDM_CLOSE);
1296 MMDRV_Free(hMidiIn, wmld);
1297 return dwRet;
1300 /**************************************************************************
1301 * midiInPrepareHeader [WINMM.@]
1303 UINT WINAPI midiInPrepareHeader(HMIDIIN hMidiIn,
1304 MIDIHDR* lpMidiInHdr, UINT uSize)
1306 LPWINE_MLD wmld;
1308 TRACE("(%p, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
1310 if (lpMidiInHdr == NULL || uSize < sizeof (MIDIHDR))
1311 return MMSYSERR_INVALPARAM;
1313 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1314 return MMSYSERR_INVALHANDLE;
1316 return MMDRV_Message(wmld, MIDM_PREPARE, (DWORD_PTR)lpMidiInHdr, uSize, TRUE);
1319 /**************************************************************************
1320 * midiInUnprepareHeader [WINMM.@]
1322 UINT WINAPI midiInUnprepareHeader(HMIDIIN hMidiIn,
1323 MIDIHDR* lpMidiInHdr, UINT uSize)
1325 LPWINE_MLD wmld;
1327 TRACE("(%p, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
1329 if (lpMidiInHdr == NULL || uSize < sizeof (MIDIHDR))
1330 return MMSYSERR_INVALPARAM;
1332 if (!(lpMidiInHdr->dwFlags & MHDR_PREPARED)) {
1333 return MMSYSERR_NOERROR;
1336 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1337 return MMSYSERR_INVALHANDLE;
1339 return MMDRV_Message(wmld, MIDM_UNPREPARE, (DWORD_PTR)lpMidiInHdr, uSize, TRUE);
1342 /**************************************************************************
1343 * midiInAddBuffer [WINMM.@]
1345 UINT WINAPI midiInAddBuffer(HMIDIIN hMidiIn,
1346 MIDIHDR* lpMidiInHdr, UINT uSize)
1348 LPWINE_MLD wmld;
1350 TRACE("(%p, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
1352 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1353 return MMSYSERR_INVALHANDLE;
1355 return MMDRV_Message(wmld, MIDM_ADDBUFFER, (DWORD_PTR)lpMidiInHdr, uSize, TRUE);
1358 /**************************************************************************
1359 * midiInStart [WINMM.@]
1361 UINT WINAPI midiInStart(HMIDIIN hMidiIn)
1363 LPWINE_MLD wmld;
1365 TRACE("(%p)\n", hMidiIn);
1367 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1368 return MMSYSERR_INVALHANDLE;
1370 return MMDRV_Message(wmld, MIDM_START, 0L, 0L, TRUE);
1373 /**************************************************************************
1374 * midiInStop [WINMM.@]
1376 UINT WINAPI midiInStop(HMIDIIN hMidiIn)
1378 LPWINE_MLD wmld;
1380 TRACE("(%p)\n", hMidiIn);
1382 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1383 return MMSYSERR_INVALHANDLE;
1385 return MMDRV_Message(wmld, MIDM_STOP, 0L, 0L, TRUE);
1388 /**************************************************************************
1389 * midiInReset [WINMM.@]
1391 UINT WINAPI midiInReset(HMIDIIN hMidiIn)
1393 LPWINE_MLD wmld;
1395 TRACE("(%p)\n", hMidiIn);
1397 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1398 return MMSYSERR_INVALHANDLE;
1400 return MMDRV_Message(wmld, MIDM_RESET, 0L, 0L, TRUE);
1403 /**************************************************************************
1404 * midiInGetID [WINMM.@]
1406 UINT WINAPI midiInGetID(HMIDIIN hMidiIn, UINT* lpuDeviceID)
1408 LPWINE_MLD wmld;
1410 TRACE("(%p, %p)\n", hMidiIn, lpuDeviceID);
1412 if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
1414 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, TRUE)) == NULL)
1415 return MMSYSERR_INVALHANDLE;
1417 *lpuDeviceID = wmld->uDeviceID;
1419 return MMSYSERR_NOERROR;
1422 /**************************************************************************
1423 * midiInMessage [WINMM.@]
1425 UINT WINAPI midiInMessage(HMIDIIN hMidiIn, UINT uMessage,
1426 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1428 LPWINE_MLD wmld;
1430 TRACE("(%p, %04X, %08lX, %08lX)\n", hMidiIn, uMessage, dwParam1, dwParam2);
1432 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1433 return MMSYSERR_INVALHANDLE;
1435 switch (uMessage) {
1436 case MIDM_OPEN:
1437 case MIDM_CLOSE:
1438 FIXME("can't handle OPEN or CLOSE message!\n");
1439 return MMSYSERR_NOTSUPPORTED;
1441 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
1444 /**************************************************************************
1445 * midiConnect [WINMM.@]
1447 MMRESULT WINAPI midiConnect(HMIDI hMidi, HMIDIOUT hmo, LPVOID pReserved)
1449 FIXME("(%p, %p, %p): Stub\n", hMidi, hmo, pReserved);
1450 return MMSYSERR_ERROR;
1453 /**************************************************************************
1454 * midiDisconnect [WINMM.@]
1456 MMRESULT WINAPI midiDisconnect(HMIDI hMidi, HMIDIOUT hmo, LPVOID pReserved)
1458 FIXME("(%p, %p, %p): Stub\n", hMidi, hmo, pReserved);
1459 return MMSYSERR_ERROR;
1462 typedef struct WINE_MIDIStream {
1463 HMIDIOUT hDevice;
1464 HANDLE hThread;
1465 DWORD dwThreadID;
1466 DWORD dwTempo;
1467 DWORD dwTimeDiv;
1468 DWORD dwPositionMS;
1469 DWORD dwPulses;
1470 DWORD dwStartTicks;
1471 WORD wFlags;
1472 HANDLE hEvent;
1473 LPMIDIHDR lpMidiHdr;
1474 } WINE_MIDIStream;
1476 #define WINE_MSM_HEADER (WM_USER+0)
1477 #define WINE_MSM_STOP (WM_USER+1)
1479 /**************************************************************************
1480 * MMSYSTEM_GetMidiStream [internal]
1482 static BOOL MMSYSTEM_GetMidiStream(HMIDISTRM hMidiStrm, WINE_MIDIStream** lpMidiStrm, WINE_MIDI** lplpwm)
1484 WINE_MIDI* lpwm = (LPWINE_MIDI)MMDRV_Get(hMidiStrm, MMDRV_MIDIOUT, FALSE);
1486 if (lplpwm)
1487 *lplpwm = lpwm;
1489 if (lpwm == NULL) {
1490 return FALSE;
1493 *lpMidiStrm = (WINE_MIDIStream*)lpwm->mod.rgIds.dwStreamID;
1495 return *lpMidiStrm != NULL;
1498 /**************************************************************************
1499 * MMSYSTEM_MidiStream_Convert [internal]
1501 static DWORD MMSYSTEM_MidiStream_Convert(WINE_MIDIStream* lpMidiStrm, DWORD pulse)
1503 DWORD ret = 0;
1505 if (lpMidiStrm->dwTimeDiv == 0) {
1506 FIXME("Shouldn't happen. lpMidiStrm->dwTimeDiv = 0\n");
1507 } else if (lpMidiStrm->dwTimeDiv > 0x8000) { /* SMPTE, unchecked FIXME? */
1508 int nf = -(char)HIBYTE(lpMidiStrm->dwTimeDiv); /* number of frames */
1509 int nsf = LOBYTE(lpMidiStrm->dwTimeDiv); /* number of sub-frames */
1510 ret = (pulse * 1000) / (nf * nsf);
1511 } else {
1512 ret = (DWORD)((double)pulse * ((double)lpMidiStrm->dwTempo / 1000) /
1513 (double)lpMidiStrm->dwTimeDiv);
1516 return ret;
1519 /**************************************************************************
1520 * MMSYSTEM_MidiStream_MessageHandler [internal]
1522 static BOOL MMSYSTEM_MidiStream_MessageHandler(WINE_MIDIStream* lpMidiStrm, LPWINE_MIDI lpwm, LPMSG msg)
1524 LPMIDIHDR lpMidiHdr;
1525 LPMIDIHDR* lpmh;
1526 LPBYTE lpData;
1528 switch (msg->message) {
1529 case WM_QUIT:
1530 SetEvent(lpMidiStrm->hEvent);
1531 return FALSE;
1532 case WINE_MSM_STOP:
1533 TRACE("STOP\n");
1534 /* this is not quite what MS doc says... */
1535 midiOutReset(lpMidiStrm->hDevice);
1536 /* empty list of already submitted buffers */
1537 for (lpMidiHdr = lpMidiStrm->lpMidiHdr; lpMidiHdr; lpMidiHdr = lpMidiHdr->lpNext) {
1538 lpMidiHdr->dwFlags |= MHDR_DONE;
1539 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
1541 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1542 (HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
1543 lpwm->mod.dwInstance, (DWORD)lpMidiHdr, 0L);
1545 lpMidiStrm->lpMidiHdr = 0;
1546 SetEvent(lpMidiStrm->hEvent);
1547 break;
1548 case WINE_MSM_HEADER:
1549 /* sets initial tick count for first MIDIHDR */
1550 if (!lpMidiStrm->dwStartTicks)
1551 lpMidiStrm->dwStartTicks = GetTickCount();
1553 /* FIXME(EPP): "I don't understand the content of the first MIDIHDR sent
1554 * by native mcimidi, it doesn't look like a correct one".
1555 * this trick allows to throw it away... but I don't like it.
1556 * It looks like part of the file I'm trying to play and definitively looks
1557 * like raw midi content
1558 * I'd really like to understand why native mcimidi sends it. Perhaps a bad
1559 * synchronization issue where native mcimidi is still processing raw MIDI
1560 * content before generating MIDIEVENTs ?
1562 * 4c 04 89 3b 00 81 7c 99 3b 43 00 99 23 5e 04 89 L..;..|.;C..#^..
1563 * 3b 00 00 89 23 00 7c 99 3b 45 00 99 28 62 04 89 ;...#.|.;E..(b..
1564 * 3b 00 00 89 28 00 81 7c 99 3b 4e 00 99 23 5e 04 ;...(..|.;N..#^.
1565 * 89 3b 00 00 89 23 00 7c 99 3b 45 00 99 23 78 04 .;...#.|.;E..#x.
1566 * 89 3b 00 00 89 23 00 81 7c 99 3b 48 00 99 23 5e .;...#..|.;H..#^
1567 * 04 89 3b 00 00 89 23 00 7c 99 3b 4e 00 99 28 62 ..;...#.|.;N..(b
1568 * 04 89 3b 00 00 89 28 00 81 7c 99 39 4c 00 99 23 ..;...(..|.9L..#
1569 * 5e 04 89 39 00 00 89 23 00 82 7c 99 3b 4c 00 99 ^..9...#..|.;L..
1570 * 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 00 99 #^..;...#.|.;H..
1571 * 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b 3f 04 (b..;...(..|.;?.
1572 * 89 3b 00 1c 99 23 5e 04 89 23 00 5c 99 3b 45 00 .;...#^..#.\.;E.
1573 * 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 3b 46 .#x..;...#..|.;F
1574 * 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 ..#^..;...#.|.;H
1575 * 00 99 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b ..(b..;...(..|.;
1576 * 46 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b F..#^..;...#.|.;
1577 * 48 00 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 H..#x..;...#..|.
1578 * 3b 4c 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 ;L..#^..;...#.|.
1580 lpMidiHdr = (LPMIDIHDR)msg->lParam;
1581 lpData = (LPBYTE)lpMidiHdr->lpData;
1582 TRACE("Adding %s lpMidiHdr=%p [lpData=0x%p dwBufferLength=%u/%u dwFlags=0x%08x size=%lu]\n",
1583 (lpMidiHdr->dwFlags & MHDR_ISSTRM) ? "stream" : "regular", lpMidiHdr,
1584 lpMidiHdr, lpMidiHdr->dwBufferLength, lpMidiHdr->dwBytesRecorded,
1585 lpMidiHdr->dwFlags, msg->wParam);
1586 #if 0
1587 /* dumps content of lpMidiHdr->lpData
1588 * FIXME: there should be a debug routine somewhere that already does this
1589 * I hate spreading this type of shit all around the code
1591 for (dwToGo = 0; dwToGo < lpMidiHdr->dwBufferLength; dwToGo += 16) {
1592 DWORD i;
1593 BYTE ch;
1595 for (i = 0; i < min(16, lpMidiHdr->dwBufferLength - dwToGo); i++)
1596 printf("%02x ", lpData[dwToGo + i]);
1597 for (; i < 16; i++)
1598 printf(" ");
1599 for (i = 0; i < min(16, lpMidiHdr->dwBufferLength - dwToGo); i++) {
1600 ch = lpData[dwToGo + i];
1601 printf("%c", (ch >= 0x20 && ch <= 0x7F) ? ch : '.');
1603 printf("\n");
1605 #endif
1606 if (((LPMIDIEVENT)lpData)->dwStreamID != 0 &&
1607 ((LPMIDIEVENT)lpData)->dwStreamID != 0xFFFFFFFF &&
1608 ((LPMIDIEVENT)lpData)->dwStreamID != (DWORD)lpMidiStrm) {
1609 FIXME("Dropping bad %s lpMidiHdr (streamID=%08x)\n",
1610 (lpMidiHdr->dwFlags & MHDR_ISSTRM) ? "stream" : "regular",
1611 ((LPMIDIEVENT)lpData)->dwStreamID);
1612 lpMidiHdr->dwFlags |= MHDR_DONE;
1613 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
1615 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1616 (HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
1617 lpwm->mod.dwInstance, (DWORD)lpMidiHdr, 0L);
1618 break;
1621 for (lpmh = &lpMidiStrm->lpMidiHdr; *lpmh; lpmh = &(*lpmh)->lpNext);
1622 *lpmh = lpMidiHdr;
1623 lpMidiHdr = (LPMIDIHDR)msg->lParam;
1624 lpMidiHdr->lpNext = 0;
1625 lpMidiHdr->dwFlags |= MHDR_INQUEUE;
1626 lpMidiHdr->dwFlags &= ~MHDR_DONE;
1627 lpMidiHdr->dwOffset = 0;
1629 break;
1630 default:
1631 FIXME("Unknown message %d\n", msg->message);
1632 break;
1634 return TRUE;
1637 /**************************************************************************
1638 * MMSYSTEM_MidiStream_Player [internal]
1640 static DWORD CALLBACK MMSYSTEM_MidiStream_Player(LPVOID pmt)
1642 WINE_MIDIStream* lpMidiStrm = pmt;
1643 WINE_MIDI* lpwm;
1644 MSG msg;
1645 DWORD dwToGo;
1646 DWORD dwCurrTC;
1647 LPMIDIHDR lpMidiHdr;
1648 LPMIDIEVENT me;
1649 LPBYTE lpData = 0;
1651 TRACE("(%p)!\n", lpMidiStrm);
1653 if (!lpMidiStrm ||
1654 (lpwm = (LPWINE_MIDI)MMDRV_Get(lpMidiStrm->hDevice, MMDRV_MIDIOUT, FALSE)) == NULL)
1655 goto the_end;
1657 /* force thread's queue creation */
1658 /* Used to be InitThreadInput16(0, 5); */
1659 /* but following works also with hack in midiStreamOpen */
1660 PeekMessageA(&msg, 0, 0, 0, 0);
1662 /* FIXME: this next line must be called before midiStreamOut or midiStreamRestart are called */
1663 SetEvent(lpMidiStrm->hEvent);
1664 TRACE("Ready to go 1\n");
1665 /* thread is started in paused mode */
1666 SuspendThread(lpMidiStrm->hThread);
1667 TRACE("Ready to go 2\n");
1669 lpMidiStrm->dwStartTicks = 0;
1670 lpMidiStrm->dwPulses = 0;
1672 lpMidiStrm->lpMidiHdr = 0;
1674 for (;;) {
1675 lpMidiHdr = lpMidiStrm->lpMidiHdr;
1676 if (!lpMidiHdr) {
1677 /* for first message, block until one arrives, then process all that are available */
1678 GetMessageA(&msg, 0, 0, 0);
1679 do {
1680 if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm, lpwm, &msg))
1681 goto the_end;
1682 } while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE));
1683 lpData = 0;
1684 continue;
1687 if (!lpData)
1688 lpData = (LPBYTE)lpMidiHdr->lpData;
1690 me = (LPMIDIEVENT)(lpData + lpMidiHdr->dwOffset);
1692 /* do we have to wait ? */
1693 if (me->dwDeltaTime) {
1694 lpMidiStrm->dwPositionMS += MMSYSTEM_MidiStream_Convert(lpMidiStrm, me->dwDeltaTime);
1695 lpMidiStrm->dwPulses += me->dwDeltaTime;
1697 dwToGo = lpMidiStrm->dwStartTicks + lpMidiStrm->dwPositionMS;
1699 TRACE("%d/%d/%d\n", dwToGo, GetTickCount(), me->dwDeltaTime);
1700 while ((dwCurrTC = GetTickCount()) < dwToGo) {
1701 if (MsgWaitForMultipleObjects(0, NULL, FALSE, dwToGo - dwCurrTC, QS_ALLINPUT) == WAIT_OBJECT_0) {
1702 /* got a message, handle it */
1703 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) {
1704 if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm, lpwm, &msg))
1705 goto the_end;
1707 lpData = 0;
1708 } else {
1709 /* timeout, so me->dwDeltaTime is elapsed, can break the while loop */
1710 break;
1714 switch (MEVT_EVENTTYPE(me->dwEvent & ~MEVT_F_CALLBACK)) {
1715 case MEVT_COMMENT:
1716 FIXME("NIY: MEVT_COMMENT\n");
1717 /* do nothing, skip bytes */
1718 break;
1719 case MEVT_LONGMSG:
1720 FIXME("NIY: MEVT_LONGMSG, aka sending Sysex event\n");
1721 break;
1722 case MEVT_NOP:
1723 break;
1724 case MEVT_SHORTMSG:
1725 midiOutShortMsg(lpMidiStrm->hDevice, MEVT_EVENTPARM(me->dwEvent));
1726 break;
1727 case MEVT_TEMPO:
1728 lpMidiStrm->dwTempo = MEVT_EVENTPARM(me->dwEvent);
1729 break;
1730 case MEVT_VERSION:
1731 break;
1732 default:
1733 FIXME("Unknown MEVT (0x%02x)\n", MEVT_EVENTTYPE(me->dwEvent & ~MEVT_F_CALLBACK));
1734 break;
1736 if (me->dwEvent & MEVT_F_CALLBACK) {
1737 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1738 (HDRVR)lpMidiStrm->hDevice, MM_MOM_POSITIONCB,
1739 lpwm->mod.dwInstance, (LPARAM)lpMidiHdr, 0L);
1741 lpMidiHdr->dwOffset += sizeof(MIDIEVENT) - sizeof(me->dwParms);
1742 if (me->dwEvent & MEVT_F_LONG)
1743 lpMidiHdr->dwOffset += (MEVT_EVENTPARM(me->dwEvent) + 3) & ~3;
1744 if (lpMidiHdr->dwOffset >= lpMidiHdr->dwBufferLength) {
1745 /* done with this header */
1746 lpMidiHdr->dwFlags |= MHDR_DONE;
1747 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
1749 lpMidiStrm->lpMidiHdr = lpMidiHdr->lpNext;
1750 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1751 (HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
1752 lpwm->mod.dwInstance, (DWORD)lpMidiHdr, 0L);
1753 lpData = 0;
1756 the_end:
1757 TRACE("End of thread\n");
1758 ExitThread(0);
1759 return 0; /* for removing the warning, never executed */
1762 /**************************************************************************
1763 * MMSYSTEM_MidiStream_PostMessage [internal]
1765 static BOOL MMSYSTEM_MidiStream_PostMessage(WINE_MIDIStream* lpMidiStrm, WORD msg, DWORD pmt1, DWORD pmt2)
1767 if (PostThreadMessageA(lpMidiStrm->dwThreadID, msg, pmt1, pmt2)) {
1768 DWORD count;
1770 if (pFnReleaseThunkLock) pFnReleaseThunkLock(&count);
1771 WaitForSingleObject(lpMidiStrm->hEvent, INFINITE);
1772 if (pFnRestoreThunkLock) pFnRestoreThunkLock(count);
1773 } else {
1774 WARN("bad PostThreadMessageA\n");
1775 return FALSE;
1777 return TRUE;
1780 /**************************************************************************
1781 * midiStreamClose [WINMM.@]
1783 MMRESULT WINAPI midiStreamClose(HMIDISTRM hMidiStrm)
1785 WINE_MIDIStream* lpMidiStrm;
1787 TRACE("(%p)!\n", hMidiStrm);
1789 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL))
1790 return MMSYSERR_INVALHANDLE;
1792 midiStreamStop(hMidiStrm);
1793 MMSYSTEM_MidiStream_PostMessage(lpMidiStrm, WM_QUIT, 0, 0);
1794 HeapFree(GetProcessHeap(), 0, lpMidiStrm);
1795 CloseHandle(lpMidiStrm->hEvent);
1797 return midiOutClose((HMIDIOUT)hMidiStrm);
1800 /**************************************************************************
1801 * MMSYSTEM_MidiStream_Open [internal]
1803 MMRESULT MIDI_StreamOpen(HMIDISTRM* lphMidiStrm, LPUINT lpuDeviceID, DWORD cMidi,
1804 DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD fdwOpen,
1805 BOOL bFrom32)
1807 WINE_MIDIStream* lpMidiStrm;
1808 MMRESULT ret;
1809 MIDIOPENSTRMID mosm;
1810 LPWINE_MIDI lpwm;
1811 HMIDIOUT hMidiOut;
1813 TRACE("(%p, %p, %d, 0x%08lx, 0x%08lx, 0x%08x)!\n",
1814 lphMidiStrm, lpuDeviceID, cMidi, dwCallback, dwInstance, fdwOpen);
1816 if (cMidi != 1 || lphMidiStrm == NULL || lpuDeviceID == NULL)
1817 return MMSYSERR_INVALPARAM;
1819 lpMidiStrm = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_MIDIStream));
1820 if (!lpMidiStrm)
1821 return MMSYSERR_NOMEM;
1823 lpMidiStrm->dwTempo = 500000;
1824 lpMidiStrm->dwTimeDiv = 480; /* 480 is 120 quarter notes per minute *//* FIXME ??*/
1825 lpMidiStrm->dwPositionMS = 0;
1827 mosm.dwStreamID = (DWORD)lpMidiStrm;
1828 /* FIXME: the correct value is not allocated yet for MAPPER */
1829 mosm.wDeviceID = *lpuDeviceID;
1830 lpwm = MIDI_OutAlloc(&hMidiOut, &dwCallback, &dwInstance, &fdwOpen, 1, &mosm, bFrom32);
1831 lpMidiStrm->hDevice = hMidiOut;
1832 if (lphMidiStrm)
1833 *lphMidiStrm = (HMIDISTRM)hMidiOut;
1835 lpwm->mld.uDeviceID = *lpuDeviceID;
1837 ret = MMDRV_Open(&lpwm->mld, MODM_OPEN, (DWORD)&lpwm->mod, fdwOpen);
1838 lpMidiStrm->hEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
1839 lpMidiStrm->wFlags = HIWORD(fdwOpen);
1841 lpMidiStrm->hThread = CreateThread(NULL, 0, MMSYSTEM_MidiStream_Player,
1842 lpMidiStrm, 0, &(lpMidiStrm->dwThreadID));
1844 if (!lpMidiStrm->hThread) {
1845 midiStreamClose((HMIDISTRM)hMidiOut);
1846 return MMSYSERR_NOMEM;
1848 SetThreadPriority(lpMidiStrm->hThread, THREAD_PRIORITY_TIME_CRITICAL);
1850 /* wait for thread to have started, and for its queue to be created */
1852 DWORD count;
1854 /* (Release|Restore)ThunkLock() is needed when this method is called from 16 bit code,
1855 * (meaning the Win16Lock is set), so that it's released and the 32 bit thread running
1856 * MMSYSTEM_MidiStreamPlayer can acquire Win16Lock to create its queue.
1858 if (pFnReleaseThunkLock) pFnReleaseThunkLock(&count);
1859 WaitForSingleObject(lpMidiStrm->hEvent, INFINITE);
1860 if (pFnRestoreThunkLock) pFnRestoreThunkLock(count);
1863 TRACE("=> (%u/%d) hMidi=%p ret=%d lpMidiStrm=%p\n",
1864 *lpuDeviceID, lpwm->mld.uDeviceID, *lphMidiStrm, ret, lpMidiStrm);
1865 return ret;
1868 /**************************************************************************
1869 * midiStreamOpen [WINMM.@]
1871 MMRESULT WINAPI midiStreamOpen(HMIDISTRM* lphMidiStrm, LPUINT lpuDeviceID,
1872 DWORD cMidi, DWORD_PTR dwCallback,
1873 DWORD_PTR dwInstance, DWORD fdwOpen)
1875 return MIDI_StreamOpen(lphMidiStrm, lpuDeviceID, cMidi, dwCallback,
1876 dwInstance, fdwOpen, TRUE);
1879 /**************************************************************************
1880 * midiStreamOut [WINMM.@]
1882 MMRESULT WINAPI midiStreamOut(HMIDISTRM hMidiStrm, LPMIDIHDR lpMidiHdr,
1883 UINT cbMidiHdr)
1885 WINE_MIDIStream* lpMidiStrm;
1886 DWORD ret = MMSYSERR_NOERROR;
1888 TRACE("(%p, %p, %u)!\n", hMidiStrm, lpMidiHdr, cbMidiHdr);
1890 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1891 ret = MMSYSERR_INVALHANDLE;
1892 } else if (!lpMidiHdr) {
1893 ret = MMSYSERR_INVALPARAM;
1894 } else {
1895 if (!PostThreadMessageA(lpMidiStrm->dwThreadID,
1896 WINE_MSM_HEADER, cbMidiHdr,
1897 (DWORD)lpMidiHdr)) {
1898 WARN("bad PostThreadMessageA\n");
1899 ret = MMSYSERR_ERROR;
1902 return ret;
1905 /**************************************************************************
1906 * midiStreamPause [WINMM.@]
1908 MMRESULT WINAPI midiStreamPause(HMIDISTRM hMidiStrm)
1910 WINE_MIDIStream* lpMidiStrm;
1911 DWORD ret = MMSYSERR_NOERROR;
1913 TRACE("(%p)!\n", hMidiStrm);
1915 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1916 ret = MMSYSERR_INVALHANDLE;
1917 } else {
1918 if (SuspendThread(lpMidiStrm->hThread) == 0xFFFFFFFF) {
1919 WARN("bad Suspend (%d)\n", GetLastError());
1920 ret = MMSYSERR_ERROR;
1923 return ret;
1926 /**************************************************************************
1927 * midiStreamPosition [WINMM.@]
1929 MMRESULT WINAPI midiStreamPosition(HMIDISTRM hMidiStrm, LPMMTIME lpMMT, UINT cbmmt)
1931 WINE_MIDIStream* lpMidiStrm;
1932 DWORD ret = MMSYSERR_NOERROR;
1934 TRACE("(%p, %p, %u)!\n", hMidiStrm, lpMMT, cbmmt);
1936 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1937 ret = MMSYSERR_INVALHANDLE;
1938 } else if (lpMMT == NULL || cbmmt != sizeof(MMTIME)) {
1939 ret = MMSYSERR_INVALPARAM;
1940 } else {
1941 switch (lpMMT->wType) {
1942 case TIME_MS:
1943 lpMMT->u.ms = lpMidiStrm->dwPositionMS;
1944 TRACE("=> %d ms\n", lpMMT->u.ms);
1945 break;
1946 case TIME_TICKS:
1947 lpMMT->u.ticks = lpMidiStrm->dwPulses;
1948 TRACE("=> %d ticks\n", lpMMT->u.ticks);
1949 break;
1950 default:
1951 WARN("Unsupported time type %d\n", lpMMT->wType);
1952 lpMMT->wType = TIME_MS;
1953 ret = MMSYSERR_INVALPARAM;
1954 break;
1957 return ret;
1960 /**************************************************************************
1961 * midiStreamProperty [WINMM.@]
1963 MMRESULT WINAPI midiStreamProperty(HMIDISTRM hMidiStrm, LPBYTE lpPropData, DWORD dwProperty)
1965 WINE_MIDIStream* lpMidiStrm;
1966 MMRESULT ret = MMSYSERR_NOERROR;
1968 TRACE("(%p, %p, %x)\n", hMidiStrm, lpPropData, dwProperty);
1970 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1971 ret = MMSYSERR_INVALHANDLE;
1972 } else if ((dwProperty & (MIDIPROP_GET|MIDIPROP_SET)) == 0) {
1973 ret = MMSYSERR_INVALPARAM;
1974 } else if (dwProperty & MIDIPROP_TEMPO) {
1975 MIDIPROPTEMPO* mpt = (MIDIPROPTEMPO*)lpPropData;
1977 if (sizeof(MIDIPROPTEMPO) != mpt->cbStruct) {
1978 ret = MMSYSERR_INVALPARAM;
1979 } else if (dwProperty & MIDIPROP_SET) {
1980 lpMidiStrm->dwTempo = mpt->dwTempo;
1981 TRACE("Setting tempo to %d\n", mpt->dwTempo);
1982 } else if (dwProperty & MIDIPROP_GET) {
1983 mpt->dwTempo = lpMidiStrm->dwTempo;
1984 TRACE("Getting tempo <= %d\n", mpt->dwTempo);
1986 } else if (dwProperty & MIDIPROP_TIMEDIV) {
1987 MIDIPROPTIMEDIV* mptd = (MIDIPROPTIMEDIV*)lpPropData;
1989 if (sizeof(MIDIPROPTIMEDIV) != mptd->cbStruct) {
1990 ret = MMSYSERR_INVALPARAM;
1991 } else if (dwProperty & MIDIPROP_SET) {
1992 lpMidiStrm->dwTimeDiv = mptd->dwTimeDiv;
1993 TRACE("Setting time div to %d\n", mptd->dwTimeDiv);
1994 } else if (dwProperty & MIDIPROP_GET) {
1995 mptd->dwTimeDiv = lpMidiStrm->dwTimeDiv;
1996 TRACE("Getting time div <= %d\n", mptd->dwTimeDiv);
1998 } else {
1999 ret = MMSYSERR_INVALPARAM;
2002 return ret;
2005 /**************************************************************************
2006 * midiStreamRestart [WINMM.@]
2008 MMRESULT WINAPI midiStreamRestart(HMIDISTRM hMidiStrm)
2010 WINE_MIDIStream* lpMidiStrm;
2011 MMRESULT ret = MMSYSERR_NOERROR;
2013 TRACE("(%p)!\n", hMidiStrm);
2015 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
2016 ret = MMSYSERR_INVALHANDLE;
2017 } else {
2018 DWORD ret;
2020 /* since we increase the thread suspend count on each midiStreamPause
2021 * there may be a need for several midiStreamResume
2023 do {
2024 ret = ResumeThread(lpMidiStrm->hThread);
2025 } while (ret != 0xFFFFFFFF && ret != 0);
2026 if (ret == 0xFFFFFFFF) {
2027 WARN("bad Resume (%d)\n", GetLastError());
2028 ret = MMSYSERR_ERROR;
2029 } else {
2030 lpMidiStrm->dwStartTicks = GetTickCount() - lpMidiStrm->dwPositionMS;
2033 return ret;
2036 /**************************************************************************
2037 * midiStreamStop [WINMM.@]
2039 MMRESULT WINAPI midiStreamStop(HMIDISTRM hMidiStrm)
2041 WINE_MIDIStream* lpMidiStrm;
2042 MMRESULT ret = MMSYSERR_NOERROR;
2044 TRACE("(%p)!\n", hMidiStrm);
2046 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
2047 ret = MMSYSERR_INVALHANDLE;
2048 } else {
2049 /* in case stream has been paused... FIXME is the current state correct ? */
2050 midiStreamRestart(hMidiStrm);
2051 MMSYSTEM_MidiStream_PostMessage(lpMidiStrm, WINE_MSM_STOP, 0, 0);
2053 return ret;
2056 UINT WAVE_Open(HANDLE* lphndl, UINT uDeviceID, UINT uType,
2057 LPCWAVEFORMATEX lpFormat, DWORD_PTR dwCallback,
2058 DWORD_PTR dwInstance, DWORD dwFlags, BOOL bFrom32)
2060 HANDLE handle;
2061 LPWINE_MLD wmld;
2062 DWORD dwRet = MMSYSERR_NOERROR;
2063 WAVEOPENDESC wod;
2065 TRACE("(%p, %d, %s, %p, %08lX, %08lX, %08X, %d);\n",
2066 lphndl, (int)uDeviceID, (uType==MMDRV_WAVEOUT)?"Out":"In", lpFormat, dwCallback,
2067 dwInstance, dwFlags, bFrom32?32:16);
2069 if (dwFlags & WAVE_FORMAT_QUERY)
2070 TRACE("WAVE_FORMAT_QUERY requested !\n");
2072 if (lpFormat == NULL) {
2073 WARN("bad format\n");
2074 return WAVERR_BADFORMAT;
2077 if ((dwFlags & WAVE_MAPPED) && (uDeviceID == (UINT)-1)) {
2078 WARN("invalid parameter\n");
2079 return MMSYSERR_INVALPARAM;
2082 /* may have a PCMWAVEFORMAT rather than a WAVEFORMATEX so don't read cbSize */
2083 TRACE("wFormatTag=%u, nChannels=%u, nSamplesPerSec=%u, nAvgBytesPerSec=%u, nBlockAlign=%u, wBitsPerSample=%u\n",
2084 lpFormat->wFormatTag, lpFormat->nChannels, lpFormat->nSamplesPerSec,
2085 lpFormat->nAvgBytesPerSec, lpFormat->nBlockAlign, lpFormat->wBitsPerSample);
2087 if ((wmld = MMDRV_Alloc(sizeof(WINE_WAVE), uType, &handle,
2088 &dwFlags, &dwCallback, &dwInstance, bFrom32)) == NULL) {
2089 WARN("no memory\n");
2090 return MMSYSERR_NOMEM;
2093 wod.hWave = handle;
2094 wod.lpFormat = (LPWAVEFORMATEX)lpFormat; /* should the struct be copied iso pointer? */
2095 wod.dwCallback = dwCallback;
2096 wod.dwInstance = dwInstance;
2097 wod.dnDevNode = 0L;
2099 TRACE("cb=%08x\n", wod.dwCallback);
2101 for (;;) {
2102 if (dwFlags & WAVE_MAPPED) {
2103 wod.uMappedDeviceID = uDeviceID;
2104 uDeviceID = WAVE_MAPPER;
2105 } else {
2106 wod.uMappedDeviceID = -1;
2108 wmld->uDeviceID = uDeviceID;
2110 dwRet = MMDRV_Open(wmld, (uType == MMDRV_WAVEOUT) ? WODM_OPEN : WIDM_OPEN,
2111 (DWORD)&wod, dwFlags);
2113 TRACE("dwRet = %s\n", WINMM_ErrorToString(dwRet));
2114 if (dwRet != WAVERR_BADFORMAT ||
2115 ((dwFlags & (WAVE_MAPPED|WAVE_FORMAT_DIRECT)) != 0) || (uDeviceID == WAVE_MAPPER)) break;
2116 /* if we ask for a format which isn't supported by the physical driver,
2117 * let's try to map it through the wave mapper (except, if we already tried
2118 * or user didn't allow us to use acm codecs or the device is already the mapper)
2120 dwFlags |= WAVE_MAPPED;
2121 /* we shall loop only one */
2124 if ((dwFlags & WAVE_FORMAT_QUERY) || dwRet != MMSYSERR_NOERROR) {
2125 MMDRV_Free(handle, wmld);
2126 handle = 0;
2129 if (lphndl != NULL) *lphndl = handle;
2130 TRACE("=> %s hWave=%p\n", WINMM_ErrorToString(dwRet), handle);
2132 return dwRet;
2135 /**************************************************************************
2136 * waveOutGetNumDevs [WINMM.@]
2138 UINT WINAPI waveOutGetNumDevs(void)
2140 return MMDRV_GetNum(MMDRV_WAVEOUT);
2143 /**************************************************************************
2144 * waveOutGetDevCapsA [WINMM.@]
2146 UINT WINAPI waveOutGetDevCapsA(UINT_PTR uDeviceID, LPWAVEOUTCAPSA lpCaps,
2147 UINT uSize)
2149 WAVEOUTCAPSW wocW;
2150 UINT ret;
2152 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2154 ret = waveOutGetDevCapsW(uDeviceID, &wocW, sizeof(wocW));
2156 if (ret == MMSYSERR_NOERROR) {
2157 WAVEOUTCAPSA wocA;
2158 wocA.wMid = wocW.wMid;
2159 wocA.wPid = wocW.wPid;
2160 wocA.vDriverVersion = wocW.vDriverVersion;
2161 WideCharToMultiByte( CP_ACP, 0, wocW.szPname, -1, wocA.szPname,
2162 sizeof(wocA.szPname), NULL, NULL );
2163 wocA.dwFormats = wocW.dwFormats;
2164 wocA.wChannels = wocW.wChannels;
2165 wocA.dwSupport = wocW.dwSupport;
2166 memcpy(lpCaps, &wocA, min(uSize, sizeof(wocA)));
2168 return ret;
2171 /**************************************************************************
2172 * waveOutGetDevCapsW [WINMM.@]
2174 UINT WINAPI waveOutGetDevCapsW(UINT_PTR uDeviceID, LPWAVEOUTCAPSW lpCaps,
2175 UINT uSize)
2177 LPWINE_MLD wmld;
2179 TRACE("(%lu %p %u)!\n", uDeviceID, lpCaps, uSize);
2181 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2183 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_WAVEOUT, TRUE)) == NULL)
2184 return MMSYSERR_BADDEVICEID;
2186 return MMDRV_Message(wmld, WODM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
2190 /**************************************************************************
2191 * waveOutGetErrorTextA [WINMM.@]
2192 * waveInGetErrorTextA [WINMM.@]
2194 UINT WINAPI waveOutGetErrorTextA(UINT uError, LPSTR lpText, UINT uSize)
2196 UINT ret;
2198 if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
2199 else if (uSize == 0) ret = MMSYSERR_NOERROR;
2200 else
2202 LPWSTR xstr = HeapAlloc(GetProcessHeap(), 0, uSize * sizeof(WCHAR));
2203 if (!xstr) ret = MMSYSERR_NOMEM;
2204 else
2206 ret = waveOutGetErrorTextW(uError, xstr, uSize);
2207 if (ret == MMSYSERR_NOERROR)
2208 WideCharToMultiByte(CP_ACP, 0, xstr, -1, lpText, uSize, NULL, NULL);
2209 HeapFree(GetProcessHeap(), 0, xstr);
2212 return ret;
2215 /**************************************************************************
2216 * waveOutGetErrorTextW [WINMM.@]
2217 * waveInGetErrorTextW [WINMM.@]
2219 UINT WINAPI waveOutGetErrorTextW(UINT uError, LPWSTR lpText, UINT uSize)
2221 UINT ret = MMSYSERR_BADERRNUM;
2223 if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
2224 else if (uSize == 0) ret = MMSYSERR_NOERROR;
2225 else if (
2226 /* test has been removed because MMSYSERR_BASE is 0, and gcc did emit
2227 * a warning for the test was always true */
2228 (/*uError >= MMSYSERR_BASE && */ uError <= MMSYSERR_LASTERROR) ||
2229 (uError >= WAVERR_BASE && uError <= WAVERR_LASTERROR)) {
2230 if (LoadStringW(hWinMM32Instance,
2231 uError, lpText, uSize) > 0) {
2232 ret = MMSYSERR_NOERROR;
2235 return ret;
2238 /**************************************************************************
2239 * waveOutOpen [WINMM.@]
2240 * All the args/structs have the same layout as the win16 equivalents
2242 MMRESULT WINAPI waveOutOpen(LPHWAVEOUT lphWaveOut, UINT uDeviceID,
2243 LPCWAVEFORMATEX lpFormat, DWORD_PTR dwCallback,
2244 DWORD_PTR dwInstance, DWORD dwFlags)
2246 return WAVE_Open((HANDLE*)lphWaveOut, uDeviceID, MMDRV_WAVEOUT, lpFormat,
2247 dwCallback, dwInstance, dwFlags, TRUE);
2250 /**************************************************************************
2251 * waveOutClose [WINMM.@]
2253 UINT WINAPI waveOutClose(HWAVEOUT hWaveOut)
2255 LPWINE_MLD wmld;
2256 DWORD dwRet;
2258 TRACE("(%p)\n", hWaveOut);
2260 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2261 return MMSYSERR_INVALHANDLE;
2263 dwRet = MMDRV_Close(wmld, WODM_CLOSE);
2264 if (dwRet != WAVERR_STILLPLAYING)
2265 MMDRV_Free(hWaveOut, wmld);
2267 return dwRet;
2270 /**************************************************************************
2271 * waveOutPrepareHeader [WINMM.@]
2273 UINT WINAPI waveOutPrepareHeader(HWAVEOUT hWaveOut,
2274 WAVEHDR* lpWaveOutHdr, UINT uSize)
2276 LPWINE_MLD wmld;
2277 UINT result;
2279 TRACE("(%p, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
2281 if (lpWaveOutHdr == NULL || uSize < sizeof (WAVEHDR))
2282 return MMSYSERR_INVALPARAM;
2284 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2285 return MMSYSERR_INVALHANDLE;
2287 if ((result = MMDRV_Message(wmld, WODM_PREPARE, (DWORD_PTR)lpWaveOutHdr,
2288 uSize, TRUE)) != MMSYSERR_NOTSUPPORTED)
2289 return result;
2291 if (lpWaveOutHdr->dwFlags & WHDR_INQUEUE)
2292 return WAVERR_STILLPLAYING;
2294 lpWaveOutHdr->dwFlags |= WHDR_PREPARED;
2295 lpWaveOutHdr->dwFlags &= ~WHDR_DONE;
2297 return MMSYSERR_NOERROR;
2300 /**************************************************************************
2301 * waveOutUnprepareHeader [WINMM.@]
2303 UINT WINAPI waveOutUnprepareHeader(HWAVEOUT hWaveOut,
2304 LPWAVEHDR lpWaveOutHdr, UINT uSize)
2306 LPWINE_MLD wmld;
2307 UINT result;
2309 TRACE("(%p, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
2311 if (lpWaveOutHdr == NULL || uSize < sizeof (WAVEHDR))
2312 return MMSYSERR_INVALPARAM;
2314 if (!(lpWaveOutHdr->dwFlags & WHDR_PREPARED)) {
2315 return MMSYSERR_NOERROR;
2318 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2319 return MMSYSERR_INVALHANDLE;
2321 if ((result = MMDRV_Message(wmld, WODM_UNPREPARE, (DWORD_PTR)lpWaveOutHdr,
2322 uSize, TRUE)) != MMSYSERR_NOTSUPPORTED)
2323 return result;
2325 if (lpWaveOutHdr->dwFlags & WHDR_INQUEUE)
2326 return WAVERR_STILLPLAYING;
2328 lpWaveOutHdr->dwFlags &= ~WHDR_PREPARED;
2329 lpWaveOutHdr->dwFlags |= WHDR_DONE;
2331 return MMSYSERR_NOERROR;
2334 /**************************************************************************
2335 * waveOutWrite [WINMM.@]
2337 UINT WINAPI waveOutWrite(HWAVEOUT hWaveOut, LPWAVEHDR lpWaveOutHdr,
2338 UINT uSize)
2340 LPWINE_MLD wmld;
2342 TRACE("(%p, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
2344 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2345 return MMSYSERR_INVALHANDLE;
2347 return MMDRV_Message(wmld, WODM_WRITE, (DWORD_PTR)lpWaveOutHdr, uSize, TRUE);
2350 /**************************************************************************
2351 * waveOutBreakLoop [WINMM.@]
2353 UINT WINAPI waveOutBreakLoop(HWAVEOUT hWaveOut)
2355 LPWINE_MLD wmld;
2357 TRACE("(%p);\n", hWaveOut);
2359 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2360 return MMSYSERR_INVALHANDLE;
2361 return MMDRV_Message(wmld, WODM_BREAKLOOP, 0L, 0L, TRUE);
2364 /**************************************************************************
2365 * waveOutPause [WINMM.@]
2367 UINT WINAPI waveOutPause(HWAVEOUT hWaveOut)
2369 LPWINE_MLD wmld;
2371 TRACE("(%p);\n", hWaveOut);
2373 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2374 return MMSYSERR_INVALHANDLE;
2375 return MMDRV_Message(wmld, WODM_PAUSE, 0L, 0L, TRUE);
2378 /**************************************************************************
2379 * waveOutReset [WINMM.@]
2381 UINT WINAPI waveOutReset(HWAVEOUT hWaveOut)
2383 LPWINE_MLD wmld;
2385 TRACE("(%p);\n", hWaveOut);
2387 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2388 return MMSYSERR_INVALHANDLE;
2389 return MMDRV_Message(wmld, WODM_RESET, 0L, 0L, TRUE);
2392 /**************************************************************************
2393 * waveOutRestart [WINMM.@]
2395 UINT WINAPI waveOutRestart(HWAVEOUT hWaveOut)
2397 LPWINE_MLD wmld;
2399 TRACE("(%p);\n", hWaveOut);
2401 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2402 return MMSYSERR_INVALHANDLE;
2403 return MMDRV_Message(wmld, WODM_RESTART, 0L, 0L, TRUE);
2406 /**************************************************************************
2407 * waveOutGetPosition [WINMM.@]
2409 UINT WINAPI waveOutGetPosition(HWAVEOUT hWaveOut, LPMMTIME lpTime,
2410 UINT uSize)
2412 LPWINE_MLD wmld;
2414 TRACE("(%p, %p, %u);\n", hWaveOut, lpTime, uSize);
2416 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2417 return MMSYSERR_INVALHANDLE;
2419 return MMDRV_Message(wmld, WODM_GETPOS, (DWORD_PTR)lpTime, uSize, TRUE);
2422 /**************************************************************************
2423 * waveOutGetPitch [WINMM.@]
2425 UINT WINAPI waveOutGetPitch(HWAVEOUT hWaveOut, LPDWORD lpdw)
2427 LPWINE_MLD wmld;
2429 TRACE("(%p, %p);\n", hWaveOut, lpdw);
2431 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2432 return MMSYSERR_INVALHANDLE;
2433 return MMDRV_Message(wmld, WODM_GETPITCH, (DWORD_PTR)lpdw, 0L, TRUE);
2436 /**************************************************************************
2437 * waveOutSetPitch [WINMM.@]
2439 UINT WINAPI waveOutSetPitch(HWAVEOUT hWaveOut, DWORD dw)
2441 LPWINE_MLD wmld;
2443 TRACE("(%p, %08x);\n", hWaveOut, dw);
2445 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2446 return MMSYSERR_INVALHANDLE;
2447 return MMDRV_Message(wmld, WODM_SETPITCH, dw, 0L, TRUE);
2450 /**************************************************************************
2451 * waveOutGetPlaybackRate [WINMM.@]
2453 UINT WINAPI waveOutGetPlaybackRate(HWAVEOUT hWaveOut, LPDWORD lpdw)
2455 LPWINE_MLD wmld;
2457 TRACE("(%p, %p);\n", hWaveOut, lpdw);
2459 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2460 return MMSYSERR_INVALHANDLE;
2461 return MMDRV_Message(wmld, WODM_GETPLAYBACKRATE, (DWORD_PTR)lpdw, 0L, TRUE);
2464 /**************************************************************************
2465 * waveOutSetPlaybackRate [WINMM.@]
2467 UINT WINAPI waveOutSetPlaybackRate(HWAVEOUT hWaveOut, DWORD dw)
2469 LPWINE_MLD wmld;
2471 TRACE("(%p, %08x);\n", hWaveOut, dw);
2473 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2474 return MMSYSERR_INVALHANDLE;
2475 return MMDRV_Message(wmld, WODM_SETPLAYBACKRATE, dw, 0L, TRUE);
2478 /**************************************************************************
2479 * waveOutGetVolume [WINMM.@]
2481 UINT WINAPI waveOutGetVolume(HWAVEOUT hWaveOut, LPDWORD lpdw)
2483 LPWINE_MLD wmld;
2485 TRACE("(%p, %p);\n", hWaveOut, lpdw);
2487 if (lpdw == NULL) {
2488 WARN("invalid parameter\n");
2489 return MMSYSERR_INVALPARAM;
2492 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, TRUE)) == NULL)
2493 return MMSYSERR_INVALHANDLE;
2495 return MMDRV_Message(wmld, WODM_GETVOLUME, (DWORD_PTR)lpdw, 0L, TRUE);
2498 /**************************************************************************
2499 * waveOutSetVolume [WINMM.@]
2501 UINT WINAPI waveOutSetVolume(HWAVEOUT hWaveOut, DWORD dw)
2503 LPWINE_MLD wmld;
2505 TRACE("(%p, %08x);\n", hWaveOut, dw);
2507 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, TRUE)) == NULL)
2508 return MMSYSERR_INVALHANDLE;
2510 return MMDRV_Message(wmld, WODM_SETVOLUME, dw, 0L, TRUE);
2513 /**************************************************************************
2514 * waveOutGetID [WINMM.@]
2516 UINT WINAPI waveOutGetID(HWAVEOUT hWaveOut, UINT* lpuDeviceID)
2518 LPWINE_MLD wmld;
2520 TRACE("(%p, %p);\n", hWaveOut, lpuDeviceID);
2522 if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
2524 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2525 return MMSYSERR_INVALHANDLE;
2527 *lpuDeviceID = wmld->uDeviceID;
2528 return 0;
2531 /**************************************************************************
2532 * waveOutMessage [WINMM.@]
2534 UINT WINAPI waveOutMessage(HWAVEOUT hWaveOut, UINT uMessage,
2535 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2537 LPWINE_MLD wmld;
2539 TRACE("(%p, %u, %ld, %ld)\n", hWaveOut, uMessage, dwParam1, dwParam2);
2541 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL) {
2542 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, TRUE)) != NULL) {
2543 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
2545 WARN("invalid handle\n");
2546 return MMSYSERR_INVALHANDLE;
2549 /* from M$ KB */
2550 if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER)) {
2551 WARN("invalid parameter\n");
2552 return MMSYSERR_INVALPARAM;
2555 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
2558 /**************************************************************************
2559 * waveInGetNumDevs [WINMM.@]
2561 UINT WINAPI waveInGetNumDevs(void)
2563 return MMDRV_GetNum(MMDRV_WAVEIN);
2566 /**************************************************************************
2567 * waveInGetDevCapsW [WINMM.@]
2569 UINT WINAPI waveInGetDevCapsW(UINT_PTR uDeviceID, LPWAVEINCAPSW lpCaps, UINT uSize)
2571 LPWINE_MLD wmld;
2573 TRACE("(%lu %p %u)!\n", uDeviceID, lpCaps, uSize);
2575 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2577 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_WAVEIN, TRUE)) == NULL)
2578 return MMSYSERR_BADDEVICEID;
2580 return MMDRV_Message(wmld, WIDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
2583 /**************************************************************************
2584 * waveInGetDevCapsA [WINMM.@]
2586 UINT WINAPI waveInGetDevCapsA(UINT_PTR uDeviceID, LPWAVEINCAPSA lpCaps, UINT uSize)
2588 WAVEINCAPSW wicW;
2589 UINT ret;
2591 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2593 ret = waveInGetDevCapsW(uDeviceID, &wicW, sizeof(wicW));
2595 if (ret == MMSYSERR_NOERROR) {
2596 WAVEINCAPSA wicA;
2597 wicA.wMid = wicW.wMid;
2598 wicA.wPid = wicW.wPid;
2599 wicA.vDriverVersion = wicW.vDriverVersion;
2600 WideCharToMultiByte( CP_ACP, 0, wicW.szPname, -1, wicA.szPname,
2601 sizeof(wicA.szPname), NULL, NULL );
2602 wicA.dwFormats = wicW.dwFormats;
2603 wicA.wChannels = wicW.wChannels;
2604 memcpy(lpCaps, &wicA, min(uSize, sizeof(wicA)));
2606 return ret;
2609 /**************************************************************************
2610 * waveInOpen [WINMM.@]
2612 MMRESULT WINAPI waveInOpen(HWAVEIN* lphWaveIn, UINT uDeviceID,
2613 LPCWAVEFORMATEX lpFormat, DWORD_PTR dwCallback,
2614 DWORD_PTR dwInstance, DWORD dwFlags)
2616 return WAVE_Open((HANDLE*)lphWaveIn, uDeviceID, MMDRV_WAVEIN, lpFormat,
2617 dwCallback, dwInstance, dwFlags, TRUE);
2620 /**************************************************************************
2621 * waveInClose [WINMM.@]
2623 UINT WINAPI waveInClose(HWAVEIN hWaveIn)
2625 LPWINE_MLD wmld;
2626 DWORD dwRet;
2628 TRACE("(%p)\n", hWaveIn);
2630 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2631 return MMSYSERR_INVALHANDLE;
2633 dwRet = MMDRV_Message(wmld, WIDM_CLOSE, 0L, 0L, TRUE);
2634 if (dwRet != WAVERR_STILLPLAYING)
2635 MMDRV_Free(hWaveIn, wmld);
2636 return dwRet;
2639 /**************************************************************************
2640 * waveInPrepareHeader [WINMM.@]
2642 UINT WINAPI waveInPrepareHeader(HWAVEIN hWaveIn, WAVEHDR* lpWaveInHdr,
2643 UINT uSize)
2645 LPWINE_MLD wmld;
2646 UINT result;
2648 TRACE("(%p, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
2650 if (lpWaveInHdr == NULL || uSize < sizeof (WAVEHDR))
2651 return MMSYSERR_INVALPARAM;
2653 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2654 return MMSYSERR_INVALHANDLE;
2656 if ((result = MMDRV_Message(wmld, WIDM_PREPARE, (DWORD_PTR)lpWaveInHdr,
2657 uSize, TRUE)) != MMSYSERR_NOTSUPPORTED)
2658 return result;
2660 if (lpWaveInHdr->dwFlags & WHDR_INQUEUE)
2661 return WAVERR_STILLPLAYING;
2663 lpWaveInHdr->dwFlags |= WHDR_PREPARED;
2664 lpWaveInHdr->dwFlags &= ~WHDR_DONE;
2665 lpWaveInHdr->dwBytesRecorded = 0;
2667 return MMSYSERR_NOERROR;
2670 /**************************************************************************
2671 * waveInUnprepareHeader [WINMM.@]
2673 UINT WINAPI waveInUnprepareHeader(HWAVEIN hWaveIn, WAVEHDR* lpWaveInHdr,
2674 UINT uSize)
2676 LPWINE_MLD wmld;
2677 UINT result;
2679 TRACE("(%p, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
2681 if (lpWaveInHdr == NULL || uSize < sizeof (WAVEHDR))
2682 return MMSYSERR_INVALPARAM;
2684 if (!(lpWaveInHdr->dwFlags & WHDR_PREPARED))
2685 return MMSYSERR_NOERROR;
2687 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2688 return MMSYSERR_INVALHANDLE;
2690 if ((result = MMDRV_Message(wmld, WIDM_UNPREPARE, (DWORD_PTR)lpWaveInHdr,
2691 uSize, TRUE)) != MMSYSERR_NOTSUPPORTED)
2692 return result;
2694 if (lpWaveInHdr->dwFlags & WHDR_INQUEUE)
2695 return WAVERR_STILLPLAYING;
2697 lpWaveInHdr->dwFlags &= ~WHDR_PREPARED;
2698 lpWaveInHdr->dwFlags |= WHDR_DONE;
2700 return MMSYSERR_NOERROR;
2703 /**************************************************************************
2704 * waveInAddBuffer [WINMM.@]
2706 UINT WINAPI waveInAddBuffer(HWAVEIN hWaveIn,
2707 WAVEHDR* lpWaveInHdr, UINT uSize)
2709 LPWINE_MLD wmld;
2711 TRACE("(%p, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
2713 if (lpWaveInHdr == NULL) return MMSYSERR_INVALPARAM;
2714 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2715 return MMSYSERR_INVALHANDLE;
2717 return MMDRV_Message(wmld, WIDM_ADDBUFFER, (DWORD_PTR)lpWaveInHdr, uSize, TRUE);
2720 /**************************************************************************
2721 * waveInReset [WINMM.@]
2723 UINT WINAPI waveInReset(HWAVEIN hWaveIn)
2725 LPWINE_MLD wmld;
2727 TRACE("(%p);\n", hWaveIn);
2729 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2730 return MMSYSERR_INVALHANDLE;
2732 return MMDRV_Message(wmld, WIDM_RESET, 0L, 0L, TRUE);
2735 /**************************************************************************
2736 * waveInStart [WINMM.@]
2738 UINT WINAPI waveInStart(HWAVEIN hWaveIn)
2740 LPWINE_MLD wmld;
2742 TRACE("(%p);\n", hWaveIn);
2744 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2745 return MMSYSERR_INVALHANDLE;
2747 return MMDRV_Message(wmld, WIDM_START, 0L, 0L, TRUE);
2750 /**************************************************************************
2751 * waveInStop [WINMM.@]
2753 UINT WINAPI waveInStop(HWAVEIN hWaveIn)
2755 LPWINE_MLD wmld;
2757 TRACE("(%p);\n", hWaveIn);
2759 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2760 return MMSYSERR_INVALHANDLE;
2762 return MMDRV_Message(wmld,WIDM_STOP, 0L, 0L, TRUE);
2765 /**************************************************************************
2766 * waveInGetPosition [WINMM.@]
2768 UINT WINAPI waveInGetPosition(HWAVEIN hWaveIn, LPMMTIME lpTime,
2769 UINT uSize)
2771 LPWINE_MLD wmld;
2773 TRACE("(%p, %p, %u);\n", hWaveIn, lpTime, uSize);
2775 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2776 return MMSYSERR_INVALHANDLE;
2778 return MMDRV_Message(wmld, WIDM_GETPOS, (DWORD_PTR)lpTime, uSize, TRUE);
2781 /**************************************************************************
2782 * waveInGetID [WINMM.@]
2784 UINT WINAPI waveInGetID(HWAVEIN hWaveIn, UINT* lpuDeviceID)
2786 LPWINE_MLD wmld;
2788 TRACE("(%p, %p);\n", hWaveIn, lpuDeviceID);
2790 if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
2792 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2793 return MMSYSERR_INVALHANDLE;
2795 *lpuDeviceID = wmld->uDeviceID;
2796 return MMSYSERR_NOERROR;
2799 /**************************************************************************
2800 * waveInMessage [WINMM.@]
2802 UINT WINAPI waveInMessage(HWAVEIN hWaveIn, UINT uMessage,
2803 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2805 LPWINE_MLD wmld;
2807 TRACE("(%p, %u, %ld, %ld)\n", hWaveIn, uMessage, dwParam1, dwParam2);
2809 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL) {
2810 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, TRUE)) != NULL) {
2811 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
2813 return MMSYSERR_INVALHANDLE;
2816 /* from M$ KB */
2817 if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER))
2818 return MMSYSERR_INVALPARAM;
2821 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
2824 struct mm_starter
2826 LPTASKCALLBACK cb;
2827 DWORD client;
2828 HANDLE event;
2831 static DWORD WINAPI mmTaskRun(void* pmt)
2833 struct mm_starter mms;
2835 memcpy(&mms, pmt, sizeof(struct mm_starter));
2836 HeapFree(GetProcessHeap(), 0, pmt);
2837 mms.cb(mms.client);
2838 if (mms.event) SetEvent(mms.event);
2839 return 0;
2842 /******************************************************************
2843 * mmTaskCreate (WINMM.@)
2845 UINT WINAPI mmTaskCreate(LPTASKCALLBACK cb, HANDLE* ph, DWORD_PTR client)
2847 HANDLE hThread;
2848 HANDLE hEvent = 0;
2849 struct mm_starter *mms;
2851 mms = HeapAlloc(GetProcessHeap(), 0, sizeof(struct mm_starter));
2852 if (mms == NULL) return TASKERR_OUTOFMEMORY;
2854 mms->cb = cb;
2855 mms->client = client;
2856 if (ph) hEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
2857 mms->event = hEvent;
2859 hThread = CreateThread(0, 0, mmTaskRun, mms, 0, NULL);
2860 if (!hThread) {
2861 HeapFree(GetProcessHeap(), 0, mms);
2862 if (hEvent) CloseHandle(hEvent);
2863 return TASKERR_OUTOFMEMORY;
2865 SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);
2866 if (ph) *ph = hEvent;
2867 CloseHandle(hThread);
2868 return 0;
2871 /******************************************************************
2872 * mmTaskBlock (WINMM.@)
2874 VOID WINAPI mmTaskBlock(DWORD tid)
2876 MSG msg;
2880 GetMessageA(&msg, 0, 0, 0);
2881 if (msg.hwnd) DispatchMessageA(&msg);
2882 } while (msg.message != WM_USER);
2885 /******************************************************************
2886 * mmTaskSignal (WINMM.@)
2888 BOOL WINAPI mmTaskSignal(DWORD tid)
2890 return PostThreadMessageW(tid, WM_USER, 0, 0);
2893 /******************************************************************
2894 * mmTaskYield (WINMM.@)
2896 VOID WINAPI mmTaskYield(VOID) {}
2898 /******************************************************************
2899 * mmGetCurrentTask (WINMM.@)
2901 DWORD WINAPI mmGetCurrentTask(VOID)
2903 return GetCurrentThreadId();