msi: Handle environment strings without a value.
[wine.git] / dlls / winmm / winmm.c
blobef993f225145c1fa4a8c58dce33aee523cc1b809
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 /* ========================================================================
61 * G L O B A L S E T T I N G S
62 * ========================================================================*/
64 HINSTANCE hWinMM32Instance;
65 HANDLE psLastEvent;
66 HANDLE psStopEvent;
68 static CRITICAL_SECTION_DEBUG critsect_debug =
70 0, 0, &WINMM_cs,
71 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
72 0, 0, { (DWORD_PTR)(__FILE__ ": WINMM_cs") }
74 CRITICAL_SECTION WINMM_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
76 /**************************************************************************
77 * WINMM_CreateIData [internal]
79 static BOOL WINMM_CreateIData(HINSTANCE hInstDLL)
81 hWinMM32Instance = hInstDLL;
82 psStopEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
83 psLastEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
84 return TRUE;
87 /**************************************************************************
88 * WINMM_DeleteIData [internal]
90 static void WINMM_DeleteIData(void)
92 TIME_MMTimeStop();
94 /* FIXME: should also free content and resources allocated
95 * inside WINMM_IData */
96 CloseHandle(psStopEvent);
97 CloseHandle(psLastEvent);
98 DeleteCriticalSection(&WINMM_cs);
101 /******************************************************************
102 * WINMM_ErrorToString
104 const char* WINMM_ErrorToString(MMRESULT error)
106 #define ERR_TO_STR(dev) case dev: return #dev
107 static char unknown[32];
108 switch (error) {
109 ERR_TO_STR(MMSYSERR_NOERROR);
110 ERR_TO_STR(MMSYSERR_ERROR);
111 ERR_TO_STR(MMSYSERR_BADDEVICEID);
112 ERR_TO_STR(MMSYSERR_NOTENABLED);
113 ERR_TO_STR(MMSYSERR_ALLOCATED);
114 ERR_TO_STR(MMSYSERR_INVALHANDLE);
115 ERR_TO_STR(MMSYSERR_NODRIVER);
116 ERR_TO_STR(MMSYSERR_NOMEM);
117 ERR_TO_STR(MMSYSERR_NOTSUPPORTED);
118 ERR_TO_STR(MMSYSERR_BADERRNUM);
119 ERR_TO_STR(MMSYSERR_INVALFLAG);
120 ERR_TO_STR(MMSYSERR_INVALPARAM);
121 ERR_TO_STR(MMSYSERR_HANDLEBUSY);
122 ERR_TO_STR(MMSYSERR_INVALIDALIAS);
123 ERR_TO_STR(MMSYSERR_BADDB);
124 ERR_TO_STR(MMSYSERR_KEYNOTFOUND);
125 ERR_TO_STR(MMSYSERR_READERROR);
126 ERR_TO_STR(MMSYSERR_WRITEERROR);
127 ERR_TO_STR(MMSYSERR_DELETEERROR);
128 ERR_TO_STR(MMSYSERR_VALNOTFOUND);
129 ERR_TO_STR(MMSYSERR_NODRIVERCB);
130 ERR_TO_STR(WAVERR_BADFORMAT);
131 ERR_TO_STR(WAVERR_STILLPLAYING);
132 ERR_TO_STR(WAVERR_UNPREPARED);
133 ERR_TO_STR(WAVERR_SYNC);
135 sprintf(unknown, "Unknown(0x%08x)", error);
136 return unknown;
137 #undef ERR_TO_STR
140 /**************************************************************************
141 * DllMain (WINMM.init)
143 * WINMM DLL entry point
146 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID fImpLoad)
148 TRACE("%p 0x%x %p\n", hInstDLL, fdwReason, fImpLoad);
150 switch (fdwReason) {
151 case DLL_PROCESS_ATTACH:
152 DisableThreadLibraryCalls(hInstDLL);
154 if (!WINMM_CreateIData(hInstDLL))
155 return FALSE;
156 if (!MMDRV_Init()) {
157 WINMM_DeleteIData();
158 return FALSE;
160 break;
161 case DLL_PROCESS_DETACH:
162 /* close all opened MCI drivers */
163 MCI_SendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_WAIT, 0L);
164 MMDRV_Exit();
165 /* There's no guarantee the drivers haven't already been unloaded on
166 * process shutdown.
168 if (!fImpLoad)
170 /* now unload all remaining drivers... */
171 DRIVER_UnloadAll();
174 WINMM_DeleteIData();
175 break;
177 return TRUE;
180 /**************************************************************************
181 * Mixer devices. New to Win95
184 /**************************************************************************
185 * find out the real mixer ID depending on hmix (depends on dwFlags)
187 static UINT MIXER_GetDev(HMIXEROBJ hmix, DWORD dwFlags, LPWINE_MIXER * lplpwm)
189 LPWINE_MIXER lpwm = NULL;
190 UINT uRet = MMSYSERR_NOERROR;
192 switch (dwFlags & 0xF0000000ul) {
193 case MIXER_OBJECTF_MIXER:
194 lpwm = (LPWINE_MIXER)MMDRV_Get(hmix, MMDRV_MIXER, TRUE);
195 break;
196 case MIXER_OBJECTF_HMIXER:
197 lpwm = (LPWINE_MIXER)MMDRV_Get(hmix, MMDRV_MIXER, FALSE);
198 break;
199 case MIXER_OBJECTF_WAVEOUT:
200 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEOUT, TRUE, MMDRV_MIXER);
201 break;
202 case MIXER_OBJECTF_HWAVEOUT:
203 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEOUT, FALSE, MMDRV_MIXER);
204 break;
205 case MIXER_OBJECTF_WAVEIN:
206 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEIN, TRUE, MMDRV_MIXER);
207 break;
208 case MIXER_OBJECTF_HWAVEIN:
209 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEIN, FALSE, MMDRV_MIXER);
210 break;
211 case MIXER_OBJECTF_MIDIOUT:
212 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIOUT, TRUE, MMDRV_MIXER);
213 break;
214 case MIXER_OBJECTF_HMIDIOUT:
215 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIOUT, FALSE, MMDRV_MIXER);
216 break;
217 case MIXER_OBJECTF_MIDIIN:
218 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIIN, TRUE, MMDRV_MIXER);
219 break;
220 case MIXER_OBJECTF_HMIDIIN:
221 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIIN, FALSE, MMDRV_MIXER);
222 break;
223 case MIXER_OBJECTF_AUX:
224 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_AUX, TRUE, MMDRV_MIXER);
225 break;
226 default:
227 WARN("Unsupported flag (%08lx)\n", dwFlags & 0xF0000000ul);
228 lpwm = 0;
229 uRet = MMSYSERR_INVALFLAG;
230 break;
232 *lplpwm = lpwm;
233 if (lpwm == 0 && uRet == MMSYSERR_NOERROR)
234 uRet = MMSYSERR_INVALPARAM;
235 return uRet;
238 /**************************************************************************
239 * mixerGetNumDevs [WINMM.@]
241 UINT WINAPI mixerGetNumDevs(void)
243 return MMDRV_GetNum(MMDRV_MIXER);
246 /**************************************************************************
247 * mixerGetDevCapsA [WINMM.@]
249 UINT WINAPI mixerGetDevCapsA(UINT_PTR uDeviceID, LPMIXERCAPSA lpCaps, UINT uSize)
251 MIXERCAPSW micW;
252 UINT ret;
254 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
256 ret = mixerGetDevCapsW(uDeviceID, &micW, sizeof(micW));
258 if (ret == MMSYSERR_NOERROR) {
259 MIXERCAPSA micA;
260 micA.wMid = micW.wMid;
261 micA.wPid = micW.wPid;
262 micA.vDriverVersion = micW.vDriverVersion;
263 WideCharToMultiByte( CP_ACP, 0, micW.szPname, -1, micA.szPname,
264 sizeof(micA.szPname), NULL, NULL );
265 micA.fdwSupport = micW.fdwSupport;
266 micA.cDestinations = micW.cDestinations;
267 memcpy(lpCaps, &micA, min(uSize, sizeof(micA)));
269 return ret;
272 /**************************************************************************
273 * mixerGetDevCapsW [WINMM.@]
275 UINT WINAPI mixerGetDevCapsW(UINT_PTR uDeviceID, LPMIXERCAPSW lpCaps, UINT uSize)
277 LPWINE_MLD wmld;
279 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
281 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_MIXER, TRUE)) == NULL)
282 return MMSYSERR_BADDEVICEID;
284 return MMDRV_Message(wmld, MXDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize);
287 static void CALLBACK MIXER_WCallback(HMIXEROBJ hmx, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam, DWORD_PTR param2)
289 HWND hWnd = (HWND)dwInstance;
291 if (!dwInstance)
292 return;
294 PostMessageW(hWnd, uMsg, (WPARAM)hmx, (LPARAM)dwParam);
297 /**************************************************************************
298 * mixerOpen [WINMM.@]
300 UINT WINAPI mixerOpen(LPHMIXER lphMix, UINT uDeviceID, DWORD_PTR dwCallback,
301 DWORD_PTR dwInstance, DWORD fdwOpen)
303 HANDLE hMix;
304 LPWINE_MLD wmld;
305 DWORD dwRet = 0;
306 MIXEROPENDESC mod;
308 TRACE("(%p, %d, %08lx, %08lx, %08x)\n",
309 lphMix, uDeviceID, dwCallback, dwInstance, fdwOpen);
311 mod.dwCallback = (DWORD_PTR)MIXER_WCallback;
312 mod.dwInstance = 0;
314 /* If callback is a function,
315 * dwCallback contains function pointer
316 * dwInstance private data
318 * if callback is a window
319 * dwCallback contains a window handle
321 switch (fdwOpen & CALLBACK_TYPEMASK) {
322 default:
323 return MMSYSERR_INVALFLAG;
325 case CALLBACK_NULL:
326 break;
328 case CALLBACK_WINDOW:
329 mod.dwInstance = dwCallback;
330 if (dwCallback && !IsWindow((HWND)dwCallback))
331 return MMSYSERR_INVALPARAM;
332 break;
335 wmld = MMDRV_Alloc(sizeof(WINE_MIXER), MMDRV_MIXER, &hMix, &fdwOpen,
336 &dwCallback, &dwInstance);
337 wmld->uDeviceID = uDeviceID;
338 mod.hmx = hMix;
340 dwRet = MMDRV_Open(wmld, MXDM_OPEN, (DWORD_PTR)&mod, CALLBACK_FUNCTION);
342 if (dwRet != MMSYSERR_NOERROR) {
343 MMDRV_Free(hMix, wmld);
344 hMix = 0;
346 if (lphMix) *lphMix = hMix;
347 TRACE("=> %d hMixer=%p\n", dwRet, hMix);
349 return dwRet;
352 /**************************************************************************
353 * mixerClose [WINMM.@]
355 UINT WINAPI mixerClose(HMIXER hMix)
357 LPWINE_MLD wmld;
358 DWORD dwRet;
360 TRACE("(%p)\n", hMix);
362 if ((wmld = MMDRV_Get(hMix, MMDRV_MIXER, FALSE)) == NULL) return MMSYSERR_INVALHANDLE;
364 dwRet = MMDRV_Close(wmld, MXDM_CLOSE);
365 MMDRV_Free(hMix, wmld);
367 return dwRet;
370 /**************************************************************************
371 * mixerGetID [WINMM.@]
373 UINT WINAPI mixerGetID(HMIXEROBJ hmix, LPUINT lpid, DWORD fdwID)
375 LPWINE_MIXER lpwm;
376 UINT uRet = MMSYSERR_NOERROR;
378 TRACE("(%p %p %08x)\n", hmix, lpid, fdwID);
380 if ((uRet = MIXER_GetDev(hmix, fdwID, &lpwm)) != MMSYSERR_NOERROR)
381 return uRet;
383 if (lpid)
384 *lpid = lpwm->mld.uDeviceID;
386 return uRet;
389 /**************************************************************************
390 * mixerGetControlDetailsW [WINMM.@]
392 UINT WINAPI mixerGetControlDetailsW(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcdW,
393 DWORD fdwDetails)
395 LPWINE_MIXER lpwm;
396 UINT uRet = MMSYSERR_NOERROR;
398 TRACE("(%p, %p, %08x)\n", hmix, lpmcdW, fdwDetails);
400 if ((uRet = MIXER_GetDev(hmix, fdwDetails, &lpwm)) != MMSYSERR_NOERROR)
401 return uRet;
403 if (lpmcdW == NULL || lpmcdW->cbStruct != sizeof(*lpmcdW))
404 return MMSYSERR_INVALPARAM;
406 return MMDRV_Message(&lpwm->mld, MXDM_GETCONTROLDETAILS, (DWORD_PTR)lpmcdW,
407 fdwDetails);
410 /**************************************************************************
411 * mixerGetControlDetailsA [WINMM.@]
413 UINT WINAPI mixerGetControlDetailsA(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcdA,
414 DWORD fdwDetails)
416 DWORD ret = MMSYSERR_NOTENABLED;
418 TRACE("(%p, %p, %08x)\n", hmix, lpmcdA, fdwDetails);
420 if (lpmcdA == NULL || lpmcdA->cbStruct != sizeof(*lpmcdA))
421 return MMSYSERR_INVALPARAM;
423 switch (fdwDetails & MIXER_GETCONTROLDETAILSF_QUERYMASK) {
424 case MIXER_GETCONTROLDETAILSF_VALUE:
425 /* can safely use A structure as it is, no string inside */
426 ret = mixerGetControlDetailsW(hmix, lpmcdA, fdwDetails);
427 break;
428 case MIXER_GETCONTROLDETAILSF_LISTTEXT:
430 MIXERCONTROLDETAILS_LISTTEXTA *pDetailsA = lpmcdA->paDetails;
431 MIXERCONTROLDETAILS_LISTTEXTW *pDetailsW;
432 int size = max(1, lpmcdA->cChannels) * sizeof(MIXERCONTROLDETAILS_LISTTEXTW);
433 unsigned int i;
435 if (lpmcdA->u.cMultipleItems != 0) {
436 size *= lpmcdA->u.cMultipleItems;
438 pDetailsW = HeapAlloc(GetProcessHeap(), 0, size);
439 lpmcdA->paDetails = pDetailsW;
440 lpmcdA->cbDetails = sizeof(MIXERCONTROLDETAILS_LISTTEXTW);
441 /* set up lpmcd->paDetails */
442 ret = mixerGetControlDetailsW(hmix, lpmcdA, fdwDetails);
443 /* copy from lpmcd->paDetails back to paDetailsW; */
444 if (ret == MMSYSERR_NOERROR) {
445 for (i = 0; i < lpmcdA->u.cMultipleItems * lpmcdA->cChannels; i++) {
446 pDetailsA->dwParam1 = pDetailsW->dwParam1;
447 pDetailsA->dwParam2 = pDetailsW->dwParam2;
448 WideCharToMultiByte( CP_ACP, 0, pDetailsW->szName, -1,
449 pDetailsA->szName,
450 sizeof(pDetailsA->szName), NULL, NULL );
451 pDetailsA++;
452 pDetailsW++;
454 pDetailsA -= lpmcdA->u.cMultipleItems * lpmcdA->cChannels;
455 pDetailsW -= lpmcdA->u.cMultipleItems * lpmcdA->cChannels;
457 HeapFree(GetProcessHeap(), 0, pDetailsW);
458 lpmcdA->paDetails = pDetailsA;
459 lpmcdA->cbDetails = sizeof(MIXERCONTROLDETAILS_LISTTEXTA);
461 break;
462 default:
463 ERR("Unsupported fdwDetails=0x%08x\n", fdwDetails);
466 return ret;
469 /**************************************************************************
470 * mixerGetLineControlsA [WINMM.@]
472 UINT WINAPI mixerGetLineControlsA(HMIXEROBJ hmix, LPMIXERLINECONTROLSA lpmlcA,
473 DWORD fdwControls)
475 MIXERLINECONTROLSW mlcW;
476 DWORD ret;
477 unsigned int i;
479 TRACE("(%p, %p, %08x)\n", hmix, lpmlcA, fdwControls);
481 if (lpmlcA == NULL || lpmlcA->cbStruct != sizeof(*lpmlcA) ||
482 lpmlcA->cbmxctrl != sizeof(MIXERCONTROLA))
483 return MMSYSERR_INVALPARAM;
485 mlcW.cbStruct = sizeof(mlcW);
486 mlcW.dwLineID = lpmlcA->dwLineID;
487 mlcW.u.dwControlID = lpmlcA->u.dwControlID;
488 mlcW.u.dwControlType = lpmlcA->u.dwControlType;
490 /* Debugging on Windows shows for MIXER_GETLINECONTROLSF_ONEBYTYPE only,
491 the control count is assumed to be 1 - This is relied upon by a game,
492 "Dynomite Deluze" */
493 if (MIXER_GETLINECONTROLSF_ONEBYTYPE == (fdwControls & MIXER_GETLINECONTROLSF_QUERYMASK)) {
494 mlcW.cControls = 1;
495 } else {
496 mlcW.cControls = lpmlcA->cControls;
498 mlcW.cbmxctrl = sizeof(MIXERCONTROLW);
499 mlcW.pamxctrl = HeapAlloc(GetProcessHeap(), 0,
500 mlcW.cControls * mlcW.cbmxctrl);
502 ret = mixerGetLineControlsW(hmix, &mlcW, fdwControls);
504 if (ret == MMSYSERR_NOERROR) {
505 lpmlcA->dwLineID = mlcW.dwLineID;
506 lpmlcA->u.dwControlID = mlcW.u.dwControlID;
507 lpmlcA->u.dwControlType = mlcW.u.dwControlType;
509 for (i = 0; i < mlcW.cControls; i++) {
510 lpmlcA->pamxctrl[i].cbStruct = sizeof(MIXERCONTROLA);
511 lpmlcA->pamxctrl[i].dwControlID = mlcW.pamxctrl[i].dwControlID;
512 lpmlcA->pamxctrl[i].dwControlType = mlcW.pamxctrl[i].dwControlType;
513 lpmlcA->pamxctrl[i].fdwControl = mlcW.pamxctrl[i].fdwControl;
514 lpmlcA->pamxctrl[i].cMultipleItems = mlcW.pamxctrl[i].cMultipleItems;
515 WideCharToMultiByte( CP_ACP, 0, mlcW.pamxctrl[i].szShortName, -1,
516 lpmlcA->pamxctrl[i].szShortName,
517 sizeof(lpmlcA->pamxctrl[i].szShortName), NULL, NULL );
518 WideCharToMultiByte( CP_ACP, 0, mlcW.pamxctrl[i].szName, -1,
519 lpmlcA->pamxctrl[i].szName,
520 sizeof(lpmlcA->pamxctrl[i].szName), NULL, NULL );
521 /* sizeof(lpmlcA->pamxctrl[i].Bounds) ==
522 * sizeof(mlcW.pamxctrl[i].Bounds) */
523 memcpy(&lpmlcA->pamxctrl[i].Bounds, &mlcW.pamxctrl[i].Bounds,
524 sizeof(mlcW.pamxctrl[i].Bounds));
525 /* sizeof(lpmlcA->pamxctrl[i].Metrics) ==
526 * sizeof(mlcW.pamxctrl[i].Metrics) */
527 memcpy(&lpmlcA->pamxctrl[i].Metrics, &mlcW.pamxctrl[i].Metrics,
528 sizeof(mlcW.pamxctrl[i].Metrics));
532 HeapFree(GetProcessHeap(), 0, mlcW.pamxctrl);
534 return ret;
537 /**************************************************************************
538 * mixerGetLineControlsW [WINMM.@]
540 UINT WINAPI mixerGetLineControlsW(HMIXEROBJ hmix, LPMIXERLINECONTROLSW lpmlcW,
541 DWORD fdwControls)
543 LPWINE_MIXER lpwm;
544 UINT uRet = MMSYSERR_NOERROR;
546 TRACE("(%p, %p, %08x)\n", hmix, lpmlcW, fdwControls);
548 if ((uRet = MIXER_GetDev(hmix, fdwControls, &lpwm)) != MMSYSERR_NOERROR)
549 return uRet;
551 if (lpmlcW == NULL || lpmlcW->cbStruct != sizeof(*lpmlcW))
552 return MMSYSERR_INVALPARAM;
554 return MMDRV_Message(&lpwm->mld, MXDM_GETLINECONTROLS, (DWORD_PTR)lpmlcW,
555 fdwControls);
558 /**************************************************************************
559 * mixerGetLineInfoW [WINMM.@]
561 UINT WINAPI mixerGetLineInfoW(HMIXEROBJ hmix, LPMIXERLINEW lpmliW, DWORD fdwInfo)
563 LPWINE_MIXER lpwm;
564 UINT uRet = MMSYSERR_NOERROR;
566 TRACE("(%p, %p, %08x)\n", hmix, lpmliW, fdwInfo);
568 if ((uRet = MIXER_GetDev(hmix, fdwInfo, &lpwm)) != MMSYSERR_NOERROR)
569 return uRet;
571 return MMDRV_Message(&lpwm->mld, MXDM_GETLINEINFO, (DWORD_PTR)lpmliW,
572 fdwInfo);
575 /**************************************************************************
576 * mixerGetLineInfoA [WINMM.@]
578 UINT WINAPI mixerGetLineInfoA(HMIXEROBJ hmix, LPMIXERLINEA lpmliA,
579 DWORD fdwInfo)
581 MIXERLINEW mliW;
582 UINT ret;
584 TRACE("(%p, %p, %08x)\n", hmix, lpmliA, fdwInfo);
586 if (lpmliA == NULL || lpmliA->cbStruct != sizeof(*lpmliA))
587 return MMSYSERR_INVALPARAM;
589 mliW.cbStruct = sizeof(mliW);
590 switch (fdwInfo & MIXER_GETLINEINFOF_QUERYMASK) {
591 case MIXER_GETLINEINFOF_COMPONENTTYPE:
592 mliW.dwComponentType = lpmliA->dwComponentType;
593 break;
594 case MIXER_GETLINEINFOF_DESTINATION:
595 mliW.dwDestination = lpmliA->dwDestination;
596 break;
597 case MIXER_GETLINEINFOF_LINEID:
598 mliW.dwLineID = lpmliA->dwLineID;
599 break;
600 case MIXER_GETLINEINFOF_SOURCE:
601 mliW.dwDestination = lpmliA->dwDestination;
602 mliW.dwSource = lpmliA->dwSource;
603 break;
604 case MIXER_GETLINEINFOF_TARGETTYPE:
605 mliW.Target.dwType = lpmliA->Target.dwType;
606 mliW.Target.wMid = lpmliA->Target.wMid;
607 mliW.Target.wPid = lpmliA->Target.wPid;
608 mliW.Target.vDriverVersion = lpmliA->Target.vDriverVersion;
609 MultiByteToWideChar( CP_ACP, 0, lpmliA->Target.szPname, -1, mliW.Target.szPname, sizeof(mliW.Target.szPname)/sizeof(WCHAR));
610 break;
611 default:
612 WARN("Unsupported fdwControls=0x%08x\n", fdwInfo);
613 return MMSYSERR_INVALFLAG;
616 ret = mixerGetLineInfoW(hmix, &mliW, fdwInfo);
618 if(ret == MMSYSERR_NOERROR)
620 lpmliA->dwDestination = mliW.dwDestination;
621 lpmliA->dwSource = mliW.dwSource;
622 lpmliA->dwLineID = mliW.dwLineID;
623 lpmliA->fdwLine = mliW.fdwLine;
624 lpmliA->dwUser = mliW.dwUser;
625 lpmliA->dwComponentType = mliW.dwComponentType;
626 lpmliA->cChannels = mliW.cChannels;
627 lpmliA->cConnections = mliW.cConnections;
628 lpmliA->cControls = mliW.cControls;
629 WideCharToMultiByte( CP_ACP, 0, mliW.szShortName, -1, lpmliA->szShortName,
630 sizeof(lpmliA->szShortName), NULL, NULL);
631 WideCharToMultiByte( CP_ACP, 0, mliW.szName, -1, lpmliA->szName,
632 sizeof(lpmliA->szName), NULL, NULL );
633 lpmliA->Target.dwType = mliW.Target.dwType;
634 lpmliA->Target.dwDeviceID = mliW.Target.dwDeviceID;
635 lpmliA->Target.wMid = mliW.Target.wMid;
636 lpmliA->Target.wPid = mliW.Target.wPid;
637 lpmliA->Target.vDriverVersion = mliW.Target.vDriverVersion;
638 WideCharToMultiByte( CP_ACP, 0, mliW.Target.szPname, -1, lpmliA->Target.szPname,
639 sizeof(lpmliA->Target.szPname), NULL, NULL );
641 return ret;
644 /**************************************************************************
645 * mixerSetControlDetails [WINMM.@]
647 UINT WINAPI mixerSetControlDetails(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcd,
648 DWORD fdwDetails)
650 LPWINE_MIXER lpwm;
651 UINT uRet = MMSYSERR_NOERROR;
653 TRACE("(%p, %p, %08x)\n", hmix, lpmcd, fdwDetails);
655 if ((uRet = MIXER_GetDev(hmix, fdwDetails, &lpwm)) != MMSYSERR_NOERROR)
656 return uRet;
658 return MMDRV_Message(&lpwm->mld, MXDM_SETCONTROLDETAILS, (DWORD_PTR)lpmcd,
659 fdwDetails);
662 /**************************************************************************
663 * mixerMessage [WINMM.@]
665 DWORD WINAPI mixerMessage(HMIXER hmix, UINT uMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
667 LPWINE_MLD wmld;
669 TRACE("(%p, %d, %08lx, %08lx): semi-stub?\n",
670 hmix, uMsg, dwParam1, dwParam2);
672 if ((wmld = MMDRV_Get(hmix, MMDRV_MIXER, FALSE)) == NULL)
673 return MMSYSERR_INVALHANDLE;
675 return MMDRV_Message(wmld, uMsg, dwParam1, dwParam2);
678 /**************************************************************************
679 * auxGetNumDevs [WINMM.@]
681 UINT WINAPI auxGetNumDevs(void)
683 return MMDRV_GetNum(MMDRV_AUX);
686 /**************************************************************************
687 * auxGetDevCapsW [WINMM.@]
689 UINT WINAPI auxGetDevCapsW(UINT_PTR uDeviceID, LPAUXCAPSW lpCaps, UINT uSize)
691 LPWINE_MLD wmld;
693 TRACE("(%04lX, %p, %d) !\n", uDeviceID, lpCaps, uSize);
695 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
697 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
698 return MMSYSERR_INVALHANDLE;
699 return MMDRV_Message(wmld, AUXDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize);
702 /**************************************************************************
703 * auxGetDevCapsA [WINMM.@]
705 UINT WINAPI auxGetDevCapsA(UINT_PTR uDeviceID, LPAUXCAPSA lpCaps, UINT uSize)
707 AUXCAPSW acW;
708 UINT ret;
710 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
712 ret = auxGetDevCapsW(uDeviceID, &acW, sizeof(acW));
714 if (ret == MMSYSERR_NOERROR) {
715 AUXCAPSA acA;
716 acA.wMid = acW.wMid;
717 acA.wPid = acW.wPid;
718 acA.vDriverVersion = acW.vDriverVersion;
719 WideCharToMultiByte( CP_ACP, 0, acW.szPname, -1, acA.szPname,
720 sizeof(acA.szPname), NULL, NULL );
721 acA.wTechnology = acW.wTechnology;
722 acA.dwSupport = acW.dwSupport;
723 memcpy(lpCaps, &acA, min(uSize, sizeof(acA)));
725 return ret;
728 /**************************************************************************
729 * auxGetVolume [WINMM.@]
731 UINT WINAPI auxGetVolume(UINT uDeviceID, DWORD* lpdwVolume)
733 LPWINE_MLD wmld;
735 TRACE("(%04X, %p) !\n", uDeviceID, lpdwVolume);
737 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
738 return MMSYSERR_INVALHANDLE;
739 return MMDRV_Message(wmld, AUXDM_GETVOLUME, (DWORD_PTR)lpdwVolume, 0L);
742 /**************************************************************************
743 * auxSetVolume [WINMM.@]
745 UINT WINAPI auxSetVolume(UINT uDeviceID, DWORD dwVolume)
747 LPWINE_MLD wmld;
749 TRACE("(%04X, %u) !\n", uDeviceID, dwVolume);
751 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
752 return MMSYSERR_INVALHANDLE;
753 return MMDRV_Message(wmld, AUXDM_SETVOLUME, dwVolume, 0L);
756 /**************************************************************************
757 * auxOutMessage [WINMM.@]
759 UINT WINAPI auxOutMessage(UINT uDeviceID, UINT uMessage, DWORD_PTR dw1, DWORD_PTR dw2)
761 LPWINE_MLD wmld;
763 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
764 return MMSYSERR_INVALHANDLE;
766 return MMDRV_Message(wmld, uMessage, dw1, dw2);
769 /**************************************************************************
770 * midiOutGetNumDevs [WINMM.@]
772 UINT WINAPI midiOutGetNumDevs(void)
774 return MMDRV_GetNum(MMDRV_MIDIOUT);
777 /**************************************************************************
778 * midiOutGetDevCapsW [WINMM.@]
780 UINT WINAPI midiOutGetDevCapsW(UINT_PTR uDeviceID, LPMIDIOUTCAPSW lpCaps,
781 UINT uSize)
783 LPWINE_MLD wmld;
785 TRACE("(%lu, %p, %u);\n", uDeviceID, lpCaps, uSize);
787 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
789 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_MIDIOUT, TRUE)) == NULL)
790 return MMSYSERR_INVALHANDLE;
792 return MMDRV_Message(wmld, MODM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize);
795 /**************************************************************************
796 * midiOutGetDevCapsA [WINMM.@]
798 UINT WINAPI midiOutGetDevCapsA(UINT_PTR uDeviceID, LPMIDIOUTCAPSA lpCaps,
799 UINT uSize)
801 MIDIOUTCAPSW mocW;
802 UINT ret;
804 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
806 ret = midiOutGetDevCapsW(uDeviceID, &mocW, sizeof(mocW));
808 if (ret == MMSYSERR_NOERROR) {
809 MIDIOUTCAPSA mocA;
810 mocA.wMid = mocW.wMid;
811 mocA.wPid = mocW.wPid;
812 mocA.vDriverVersion = mocW.vDriverVersion;
813 WideCharToMultiByte( CP_ACP, 0, mocW.szPname, -1, mocA.szPname,
814 sizeof(mocA.szPname), NULL, NULL );
815 mocA.wTechnology = mocW.wTechnology;
816 mocA.wVoices = mocW.wVoices;
817 mocA.wNotes = mocW.wNotes;
818 mocA.wChannelMask = mocW.wChannelMask;
819 mocA.dwSupport = mocW.dwSupport;
820 memcpy(lpCaps, &mocA, min(uSize, sizeof(mocA)));
822 return ret;
825 /**************************************************************************
826 * midiOutGetErrorTextA [WINMM.@]
827 * midiInGetErrorTextA [WINMM.@]
829 UINT WINAPI midiOutGetErrorTextA(UINT uError, LPSTR lpText, UINT uSize)
831 UINT ret;
833 if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
834 else if (uSize == 0) ret = MMSYSERR_NOERROR;
835 else
837 LPWSTR xstr = HeapAlloc(GetProcessHeap(), 0, uSize * sizeof(WCHAR));
838 if (!xstr) ret = MMSYSERR_NOMEM;
839 else
841 ret = midiOutGetErrorTextW(uError, xstr, uSize);
842 if (ret == MMSYSERR_NOERROR)
843 WideCharToMultiByte(CP_ACP, 0, xstr, -1, lpText, uSize, NULL, NULL);
844 HeapFree(GetProcessHeap(), 0, xstr);
847 return ret;
850 /**************************************************************************
851 * midiOutGetErrorTextW [WINMM.@]
852 * midiInGetErrorTextW [WINMM.@]
854 UINT WINAPI midiOutGetErrorTextW(UINT uError, LPWSTR lpText, UINT uSize)
856 UINT ret = MMSYSERR_BADERRNUM;
858 if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
859 else if (uSize == 0) ret = MMSYSERR_NOERROR;
860 else if (
861 /* test has been removed because MMSYSERR_BASE is 0, and gcc did emit
862 * a warning for the test was always true */
863 (/*uError >= MMSYSERR_BASE && */ uError <= MMSYSERR_LASTERROR) ||
864 (uError >= MIDIERR_BASE && uError <= MIDIERR_LASTERROR)) {
865 if (LoadStringW(hWinMM32Instance, uError, lpText, uSize) > 0) {
866 ret = MMSYSERR_NOERROR;
869 return ret;
872 /**************************************************************************
873 * MIDI_OutAlloc [internal]
875 static LPWINE_MIDI MIDI_OutAlloc(HMIDIOUT* lphMidiOut, DWORD_PTR* lpdwCallback,
876 DWORD_PTR* lpdwInstance, LPDWORD lpdwFlags,
877 DWORD cIDs, MIDIOPENSTRMID* lpIDs)
879 HANDLE hMidiOut;
880 LPWINE_MIDI lpwm;
881 UINT size;
883 size = sizeof(WINE_MIDI) + (cIDs ? (cIDs-1) : 0) * sizeof(MIDIOPENSTRMID);
885 lpwm = (LPWINE_MIDI)MMDRV_Alloc(size, MMDRV_MIDIOUT, &hMidiOut, lpdwFlags,
886 lpdwCallback, lpdwInstance);
888 if (lphMidiOut != NULL)
889 *lphMidiOut = hMidiOut;
891 if (lpwm) {
892 lpwm->mod.hMidi = hMidiOut;
893 lpwm->mod.dwCallback = *lpdwCallback;
894 lpwm->mod.dwInstance = *lpdwInstance;
895 lpwm->mod.dnDevNode = 0;
896 lpwm->mod.cIds = cIDs;
897 if (cIDs)
898 memcpy(&(lpwm->mod.rgIds), lpIDs, cIDs * sizeof(MIDIOPENSTRMID));
900 return lpwm;
903 /**************************************************************************
904 * midiOutOpen [WINMM.@]
906 UINT WINAPI midiOutOpen(LPHMIDIOUT lphMidiOut, UINT uDeviceID,
907 DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD dwFlags)
909 HMIDIOUT hMidiOut;
910 LPWINE_MIDI lpwm;
911 UINT dwRet = 0;
913 TRACE("(%p, %d, %08lX, %08lX, %08X);\n",
914 lphMidiOut, uDeviceID, dwCallback, dwInstance, dwFlags);
916 if (lphMidiOut != NULL) *lphMidiOut = 0;
918 lpwm = MIDI_OutAlloc(&hMidiOut, &dwCallback, &dwInstance, &dwFlags, 0, NULL);
920 if (lpwm == NULL)
921 return MMSYSERR_NOMEM;
923 lpwm->mld.uDeviceID = uDeviceID;
925 dwRet = MMDRV_Open((LPWINE_MLD)lpwm, MODM_OPEN, (DWORD_PTR)&lpwm->mod, dwFlags);
927 if (dwRet != MMSYSERR_NOERROR) {
928 MMDRV_Free(hMidiOut, (LPWINE_MLD)lpwm);
929 hMidiOut = 0;
932 if (lphMidiOut) *lphMidiOut = hMidiOut;
933 TRACE("=> %d hMidi=%p\n", dwRet, hMidiOut);
935 return dwRet;
938 /**************************************************************************
939 * midiOutClose [WINMM.@]
941 UINT WINAPI midiOutClose(HMIDIOUT hMidiOut)
943 LPWINE_MLD wmld;
944 DWORD dwRet;
946 TRACE("(%p)\n", hMidiOut);
948 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
949 return MMSYSERR_INVALHANDLE;
951 dwRet = MMDRV_Close(wmld, MODM_CLOSE);
952 MMDRV_Free(hMidiOut, wmld);
954 return dwRet;
957 /**************************************************************************
958 * midiOutPrepareHeader [WINMM.@]
960 UINT WINAPI midiOutPrepareHeader(HMIDIOUT hMidiOut,
961 MIDIHDR* lpMidiOutHdr, UINT uSize)
963 LPWINE_MLD wmld;
965 TRACE("(%p, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
967 if (lpMidiOutHdr == NULL || uSize < sizeof (MIDIHDR))
968 return MMSYSERR_INVALPARAM;
970 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
971 return MMSYSERR_INVALHANDLE;
973 return MMDRV_Message(wmld, MODM_PREPARE, (DWORD_PTR)lpMidiOutHdr, uSize);
976 /**************************************************************************
977 * midiOutUnprepareHeader [WINMM.@]
979 UINT WINAPI midiOutUnprepareHeader(HMIDIOUT hMidiOut,
980 MIDIHDR* lpMidiOutHdr, UINT uSize)
982 LPWINE_MLD wmld;
984 TRACE("(%p, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
986 if (lpMidiOutHdr == NULL || uSize < sizeof (MIDIHDR))
987 return MMSYSERR_INVALPARAM;
989 if (!(lpMidiOutHdr->dwFlags & MHDR_PREPARED)) {
990 return MMSYSERR_NOERROR;
993 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
994 return MMSYSERR_INVALHANDLE;
996 return MMDRV_Message(wmld, MODM_UNPREPARE, (DWORD_PTR)lpMidiOutHdr, uSize);
999 /**************************************************************************
1000 * midiOutShortMsg [WINMM.@]
1002 UINT WINAPI midiOutShortMsg(HMIDIOUT hMidiOut, DWORD dwMsg)
1004 LPWINE_MLD wmld;
1006 TRACE("(%p, %08X)\n", hMidiOut, dwMsg);
1008 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1009 return MMSYSERR_INVALHANDLE;
1011 return MMDRV_Message(wmld, MODM_DATA, dwMsg, 0L);
1014 /**************************************************************************
1015 * midiOutLongMsg [WINMM.@]
1017 UINT WINAPI midiOutLongMsg(HMIDIOUT hMidiOut,
1018 MIDIHDR* lpMidiOutHdr, UINT uSize)
1020 LPWINE_MLD wmld;
1022 TRACE("(%p, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
1024 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1025 return MMSYSERR_INVALHANDLE;
1027 return MMDRV_Message(wmld, MODM_LONGDATA, (DWORD_PTR)lpMidiOutHdr, uSize);
1030 /**************************************************************************
1031 * midiOutReset [WINMM.@]
1033 UINT WINAPI midiOutReset(HMIDIOUT hMidiOut)
1035 LPWINE_MLD wmld;
1037 TRACE("(%p)\n", hMidiOut);
1039 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1040 return MMSYSERR_INVALHANDLE;
1042 return MMDRV_Message(wmld, MODM_RESET, 0L, 0L);
1045 /**************************************************************************
1046 * midiOutGetVolume [WINMM.@]
1048 UINT WINAPI midiOutGetVolume(HMIDIOUT hMidiOut, DWORD* lpdwVolume)
1050 LPWINE_MLD wmld;
1052 TRACE("(%p, %p);\n", hMidiOut, lpdwVolume);
1054 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, TRUE)) == NULL)
1055 return MMSYSERR_INVALHANDLE;
1057 return MMDRV_Message(wmld, MODM_GETVOLUME, (DWORD_PTR)lpdwVolume, 0L);
1060 /**************************************************************************
1061 * midiOutSetVolume [WINMM.@]
1063 UINT WINAPI midiOutSetVolume(HMIDIOUT hMidiOut, DWORD dwVolume)
1065 LPWINE_MLD wmld;
1067 TRACE("(%p, %d);\n", hMidiOut, dwVolume);
1069 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, TRUE)) == NULL)
1070 return MMSYSERR_INVALHANDLE;
1072 return MMDRV_Message(wmld, MODM_SETVOLUME, dwVolume, 0L);
1075 /**************************************************************************
1076 * midiOutCachePatches [WINMM.@]
1078 UINT WINAPI midiOutCachePatches(HMIDIOUT hMidiOut, UINT uBank,
1079 WORD* lpwPatchArray, UINT uFlags)
1081 /* not really necessary to support this */
1082 FIXME("not supported yet\n");
1083 return MMSYSERR_NOTSUPPORTED;
1086 /**************************************************************************
1087 * midiOutCacheDrumPatches [WINMM.@]
1089 UINT WINAPI midiOutCacheDrumPatches(HMIDIOUT hMidiOut, UINT uPatch,
1090 WORD* lpwKeyArray, UINT uFlags)
1092 FIXME("not supported yet\n");
1093 return MMSYSERR_NOTSUPPORTED;
1096 /**************************************************************************
1097 * midiOutGetID [WINMM.@]
1099 UINT WINAPI midiOutGetID(HMIDIOUT hMidiOut, UINT* lpuDeviceID)
1101 LPWINE_MLD wmld;
1103 TRACE("(%p, %p)\n", hMidiOut, lpuDeviceID);
1105 if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
1106 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1107 return MMSYSERR_INVALHANDLE;
1109 *lpuDeviceID = wmld->uDeviceID;
1110 return MMSYSERR_NOERROR;
1113 /**************************************************************************
1114 * midiOutMessage [WINMM.@]
1116 UINT WINAPI midiOutMessage(HMIDIOUT hMidiOut, UINT uMessage,
1117 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1119 LPWINE_MLD wmld;
1121 TRACE("(%p, %04X, %08lX, %08lX)\n", hMidiOut, uMessage, dwParam1, dwParam2);
1123 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL) {
1124 /* HACK... */
1125 if (uMessage == 0x0001) {
1126 *(LPDWORD)dwParam1 = 1;
1127 return 0;
1129 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, TRUE)) != NULL) {
1130 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
1132 return MMSYSERR_INVALHANDLE;
1135 switch (uMessage) {
1136 case MODM_OPEN:
1137 case MODM_CLOSE:
1138 FIXME("can't handle OPEN or CLOSE message!\n");
1139 return MMSYSERR_NOTSUPPORTED;
1141 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2);
1144 /**************************************************************************
1145 * midiInGetNumDevs [WINMM.@]
1147 UINT WINAPI midiInGetNumDevs(void)
1149 return MMDRV_GetNum(MMDRV_MIDIIN);
1152 /**************************************************************************
1153 * midiInGetDevCapsW [WINMM.@]
1155 UINT WINAPI midiInGetDevCapsW(UINT_PTR uDeviceID, LPMIDIINCAPSW lpCaps, UINT uSize)
1157 LPWINE_MLD wmld;
1159 TRACE("(%ld, %p, %d);\n", uDeviceID, lpCaps, uSize);
1161 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
1163 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_MIDIIN, TRUE)) == NULL)
1164 return MMSYSERR_INVALHANDLE;
1166 return MMDRV_Message(wmld, MIDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize);
1169 /**************************************************************************
1170 * midiInGetDevCapsA [WINMM.@]
1172 UINT WINAPI midiInGetDevCapsA(UINT_PTR uDeviceID, LPMIDIINCAPSA lpCaps, UINT uSize)
1174 MIDIINCAPSW micW;
1175 UINT ret;
1177 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
1179 ret = midiInGetDevCapsW(uDeviceID, &micW, sizeof(micW));
1181 if (ret == MMSYSERR_NOERROR) {
1182 MIDIINCAPSA micA;
1183 micA.wMid = micW.wMid;
1184 micA.wPid = micW.wPid;
1185 micA.vDriverVersion = micW.vDriverVersion;
1186 WideCharToMultiByte( CP_ACP, 0, micW.szPname, -1, micA.szPname,
1187 sizeof(micA.szPname), NULL, NULL );
1188 micA.dwSupport = micW.dwSupport;
1189 memcpy(lpCaps, &micA, min(uSize, sizeof(micA)));
1191 return ret;
1194 /**************************************************************************
1195 * midiInOpen [WINMM.@]
1197 UINT WINAPI midiInOpen(HMIDIIN* lphMidiIn, UINT uDeviceID,
1198 DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD dwFlags)
1200 HANDLE hMidiIn;
1201 LPWINE_MIDI lpwm;
1202 DWORD dwRet = 0;
1204 TRACE("(%p, %d, %08lX, %08lX, %08X);\n",
1205 lphMidiIn, uDeviceID, dwCallback, dwInstance, dwFlags);
1207 if (lphMidiIn != NULL) *lphMidiIn = 0;
1209 lpwm = (LPWINE_MIDI)MMDRV_Alloc(sizeof(WINE_MIDI), MMDRV_MIDIIN, &hMidiIn,
1210 &dwFlags, &dwCallback, &dwInstance);
1212 if (lpwm == NULL)
1213 return MMSYSERR_NOMEM;
1215 lpwm->mod.hMidi = hMidiIn;
1216 lpwm->mod.dwCallback = dwCallback;
1217 lpwm->mod.dwInstance = dwInstance;
1219 lpwm->mld.uDeviceID = uDeviceID;
1220 dwRet = MMDRV_Open(&lpwm->mld, MIDM_OPEN, (DWORD_PTR)&lpwm->mod, dwFlags);
1222 if (dwRet != MMSYSERR_NOERROR) {
1223 MMDRV_Free(hMidiIn, &lpwm->mld);
1224 hMidiIn = 0;
1226 if (lphMidiIn != NULL) *lphMidiIn = hMidiIn;
1227 TRACE("=> %d hMidi=%p\n", dwRet, hMidiIn);
1229 return dwRet;
1232 /**************************************************************************
1233 * midiInClose [WINMM.@]
1235 UINT WINAPI midiInClose(HMIDIIN hMidiIn)
1237 LPWINE_MLD wmld;
1238 DWORD dwRet;
1240 TRACE("(%p)\n", hMidiIn);
1242 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1243 return MMSYSERR_INVALHANDLE;
1245 dwRet = MMDRV_Close(wmld, MIDM_CLOSE);
1246 MMDRV_Free(hMidiIn, wmld);
1247 return dwRet;
1250 /**************************************************************************
1251 * midiInPrepareHeader [WINMM.@]
1253 UINT WINAPI midiInPrepareHeader(HMIDIIN hMidiIn,
1254 MIDIHDR* lpMidiInHdr, UINT uSize)
1256 LPWINE_MLD wmld;
1258 TRACE("(%p, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
1260 if (lpMidiInHdr == NULL || uSize < sizeof (MIDIHDR))
1261 return MMSYSERR_INVALPARAM;
1263 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1264 return MMSYSERR_INVALHANDLE;
1266 return MMDRV_Message(wmld, MIDM_PREPARE, (DWORD_PTR)lpMidiInHdr, uSize);
1269 /**************************************************************************
1270 * midiInUnprepareHeader [WINMM.@]
1272 UINT WINAPI midiInUnprepareHeader(HMIDIIN hMidiIn,
1273 MIDIHDR* lpMidiInHdr, UINT uSize)
1275 LPWINE_MLD wmld;
1277 TRACE("(%p, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
1279 if (lpMidiInHdr == NULL || uSize < sizeof (MIDIHDR))
1280 return MMSYSERR_INVALPARAM;
1282 if (!(lpMidiInHdr->dwFlags & MHDR_PREPARED)) {
1283 return MMSYSERR_NOERROR;
1286 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1287 return MMSYSERR_INVALHANDLE;
1289 return MMDRV_Message(wmld, MIDM_UNPREPARE, (DWORD_PTR)lpMidiInHdr, uSize);
1292 /**************************************************************************
1293 * midiInAddBuffer [WINMM.@]
1295 UINT WINAPI midiInAddBuffer(HMIDIIN hMidiIn,
1296 MIDIHDR* lpMidiInHdr, UINT uSize)
1298 LPWINE_MLD wmld;
1300 TRACE("(%p, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
1302 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1303 return MMSYSERR_INVALHANDLE;
1305 return MMDRV_Message(wmld, MIDM_ADDBUFFER, (DWORD_PTR)lpMidiInHdr, uSize);
1308 /**************************************************************************
1309 * midiInStart [WINMM.@]
1311 UINT WINAPI midiInStart(HMIDIIN hMidiIn)
1313 LPWINE_MLD wmld;
1315 TRACE("(%p)\n", hMidiIn);
1317 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1318 return MMSYSERR_INVALHANDLE;
1320 return MMDRV_Message(wmld, MIDM_START, 0L, 0L);
1323 /**************************************************************************
1324 * midiInStop [WINMM.@]
1326 UINT WINAPI midiInStop(HMIDIIN hMidiIn)
1328 LPWINE_MLD wmld;
1330 TRACE("(%p)\n", hMidiIn);
1332 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1333 return MMSYSERR_INVALHANDLE;
1335 return MMDRV_Message(wmld, MIDM_STOP, 0L, 0L);
1338 /**************************************************************************
1339 * midiInReset [WINMM.@]
1341 UINT WINAPI midiInReset(HMIDIIN hMidiIn)
1343 LPWINE_MLD wmld;
1345 TRACE("(%p)\n", hMidiIn);
1347 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1348 return MMSYSERR_INVALHANDLE;
1350 return MMDRV_Message(wmld, MIDM_RESET, 0L, 0L);
1353 /**************************************************************************
1354 * midiInGetID [WINMM.@]
1356 UINT WINAPI midiInGetID(HMIDIIN hMidiIn, UINT* lpuDeviceID)
1358 LPWINE_MLD wmld;
1360 TRACE("(%p, %p)\n", hMidiIn, lpuDeviceID);
1362 if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
1364 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, TRUE)) == NULL)
1365 return MMSYSERR_INVALHANDLE;
1367 *lpuDeviceID = wmld->uDeviceID;
1369 return MMSYSERR_NOERROR;
1372 /**************************************************************************
1373 * midiInMessage [WINMM.@]
1375 UINT WINAPI midiInMessage(HMIDIIN hMidiIn, UINT uMessage,
1376 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1378 LPWINE_MLD wmld;
1380 TRACE("(%p, %04X, %08lX, %08lX)\n", hMidiIn, uMessage, dwParam1, dwParam2);
1382 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1383 return MMSYSERR_INVALHANDLE;
1385 switch (uMessage) {
1386 case MIDM_OPEN:
1387 case MIDM_CLOSE:
1388 FIXME("can't handle OPEN or CLOSE message!\n");
1389 return MMSYSERR_NOTSUPPORTED;
1391 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2);
1394 /**************************************************************************
1395 * midiConnect [WINMM.@]
1397 MMRESULT WINAPI midiConnect(HMIDI hMidi, HMIDIOUT hmo, LPVOID pReserved)
1399 FIXME("(%p, %p, %p): Stub\n", hMidi, hmo, pReserved);
1400 return MMSYSERR_ERROR;
1403 /**************************************************************************
1404 * midiDisconnect [WINMM.@]
1406 MMRESULT WINAPI midiDisconnect(HMIDI hMidi, HMIDIOUT hmo, LPVOID pReserved)
1408 FIXME("(%p, %p, %p): Stub\n", hMidi, hmo, pReserved);
1409 return MMSYSERR_ERROR;
1412 typedef struct WINE_MIDIStream {
1413 HMIDIOUT hDevice;
1414 HANDLE hThread;
1415 DWORD dwThreadID;
1416 DWORD dwTempo;
1417 DWORD dwTimeDiv;
1418 DWORD dwPositionMS;
1419 DWORD dwPulses;
1420 DWORD dwStartTicks;
1421 WORD wFlags;
1422 HANDLE hEvent;
1423 LPMIDIHDR lpMidiHdr;
1424 } WINE_MIDIStream;
1426 #define WINE_MSM_HEADER (WM_USER+0)
1427 #define WINE_MSM_STOP (WM_USER+1)
1429 /**************************************************************************
1430 * MMSYSTEM_GetMidiStream [internal]
1432 static BOOL MMSYSTEM_GetMidiStream(HMIDISTRM hMidiStrm, WINE_MIDIStream** lpMidiStrm, WINE_MIDI** lplpwm)
1434 WINE_MIDI* lpwm = (LPWINE_MIDI)MMDRV_Get(hMidiStrm, MMDRV_MIDIOUT, FALSE);
1436 if (lplpwm)
1437 *lplpwm = lpwm;
1439 if (lpwm == NULL) {
1440 return FALSE;
1443 *lpMidiStrm = (WINE_MIDIStream*)lpwm->mod.rgIds.dwStreamID;
1445 return *lpMidiStrm != NULL;
1448 /**************************************************************************
1449 * MMSYSTEM_MidiStream_Convert [internal]
1451 static DWORD MMSYSTEM_MidiStream_Convert(WINE_MIDIStream* lpMidiStrm, DWORD pulse)
1453 DWORD ret = 0;
1455 if (lpMidiStrm->dwTimeDiv == 0) {
1456 FIXME("Shouldn't happen. lpMidiStrm->dwTimeDiv = 0\n");
1457 } else if (lpMidiStrm->dwTimeDiv > 0x8000) { /* SMPTE, unchecked FIXME? */
1458 int nf = -(char)HIBYTE(lpMidiStrm->dwTimeDiv); /* number of frames */
1459 int nsf = LOBYTE(lpMidiStrm->dwTimeDiv); /* number of sub-frames */
1460 ret = (pulse * 1000) / (nf * nsf);
1461 } else {
1462 ret = (DWORD)((double)pulse * ((double)lpMidiStrm->dwTempo / 1000) /
1463 (double)lpMidiStrm->dwTimeDiv);
1466 return ret;
1469 /**************************************************************************
1470 * MMSYSTEM_MidiStream_MessageHandler [internal]
1472 static BOOL MMSYSTEM_MidiStream_MessageHandler(WINE_MIDIStream* lpMidiStrm, LPWINE_MIDI lpwm, LPMSG msg)
1474 LPMIDIHDR lpMidiHdr;
1475 LPMIDIHDR* lpmh;
1476 LPBYTE lpData;
1478 switch (msg->message) {
1479 case WM_QUIT:
1480 SetEvent(lpMidiStrm->hEvent);
1481 return FALSE;
1482 case WINE_MSM_STOP:
1483 TRACE("STOP\n");
1484 /* this is not quite what MS doc says... */
1485 midiOutReset(lpMidiStrm->hDevice);
1486 /* empty list of already submitted buffers */
1487 for (lpMidiHdr = lpMidiStrm->lpMidiHdr; lpMidiHdr; lpMidiHdr = lpMidiHdr->lpNext) {
1488 lpMidiHdr->dwFlags |= MHDR_DONE;
1489 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
1491 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1492 (HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
1493 lpwm->mod.dwInstance, (DWORD_PTR)lpMidiHdr, 0);
1495 lpMidiStrm->lpMidiHdr = 0;
1496 SetEvent(lpMidiStrm->hEvent);
1497 break;
1498 case WINE_MSM_HEADER:
1499 /* sets initial tick count for first MIDIHDR */
1500 if (!lpMidiStrm->dwStartTicks)
1501 lpMidiStrm->dwStartTicks = GetTickCount();
1503 /* FIXME(EPP): "I don't understand the content of the first MIDIHDR sent
1504 * by native mcimidi, it doesn't look like a correct one".
1505 * this trick allows to throw it away... but I don't like it.
1506 * It looks like part of the file I'm trying to play and definitively looks
1507 * like raw midi content
1508 * I'd really like to understand why native mcimidi sends it. Perhaps a bad
1509 * synchronization issue where native mcimidi is still processing raw MIDI
1510 * content before generating MIDIEVENTs ?
1512 * 4c 04 89 3b 00 81 7c 99 3b 43 00 99 23 5e 04 89 L..;..|.;C..#^..
1513 * 3b 00 00 89 23 00 7c 99 3b 45 00 99 28 62 04 89 ;...#.|.;E..(b..
1514 * 3b 00 00 89 28 00 81 7c 99 3b 4e 00 99 23 5e 04 ;...(..|.;N..#^.
1515 * 89 3b 00 00 89 23 00 7c 99 3b 45 00 99 23 78 04 .;...#.|.;E..#x.
1516 * 89 3b 00 00 89 23 00 81 7c 99 3b 48 00 99 23 5e .;...#..|.;H..#^
1517 * 04 89 3b 00 00 89 23 00 7c 99 3b 4e 00 99 28 62 ..;...#.|.;N..(b
1518 * 04 89 3b 00 00 89 28 00 81 7c 99 39 4c 00 99 23 ..;...(..|.9L..#
1519 * 5e 04 89 39 00 00 89 23 00 82 7c 99 3b 4c 00 99 ^..9...#..|.;L..
1520 * 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 00 99 #^..;...#.|.;H..
1521 * 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b 3f 04 (b..;...(..|.;?.
1522 * 89 3b 00 1c 99 23 5e 04 89 23 00 5c 99 3b 45 00 .;...#^..#.\.;E.
1523 * 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 3b 46 .#x..;...#..|.;F
1524 * 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 ..#^..;...#.|.;H
1525 * 00 99 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b ..(b..;...(..|.;
1526 * 46 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b F..#^..;...#.|.;
1527 * 48 00 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 H..#x..;...#..|.
1528 * 3b 4c 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 ;L..#^..;...#.|.
1530 lpMidiHdr = (LPMIDIHDR)msg->lParam;
1531 lpData = (LPBYTE)lpMidiHdr->lpData;
1532 TRACE("Adding %s lpMidiHdr=%p [lpData=0x%p dwBufferLength=%u/%u dwFlags=0x%08x size=%lu]\n",
1533 (lpMidiHdr->dwFlags & MHDR_ISSTRM) ? "stream" : "regular", lpMidiHdr,
1534 lpMidiHdr, lpMidiHdr->dwBufferLength, lpMidiHdr->dwBytesRecorded,
1535 lpMidiHdr->dwFlags, msg->wParam);
1536 #if 0
1537 /* dumps content of lpMidiHdr->lpData
1538 * FIXME: there should be a debug routine somewhere that already does this
1539 * I hate spreading this type of shit all around the code
1541 for (dwToGo = 0; dwToGo < lpMidiHdr->dwBufferLength; dwToGo += 16) {
1542 DWORD i;
1543 BYTE ch;
1545 for (i = 0; i < min(16, lpMidiHdr->dwBufferLength - dwToGo); i++)
1546 printf("%02x ", lpData[dwToGo + i]);
1547 for (; i < 16; i++)
1548 printf(" ");
1549 for (i = 0; i < min(16, lpMidiHdr->dwBufferLength - dwToGo); i++) {
1550 ch = lpData[dwToGo + i];
1551 printf("%c", (ch >= 0x20 && ch <= 0x7F) ? ch : '.');
1553 printf("\n");
1555 #endif
1556 if (((LPMIDIEVENT)lpData)->dwStreamID != 0 &&
1557 ((LPMIDIEVENT)lpData)->dwStreamID != 0xFFFFFFFF &&
1558 ((LPMIDIEVENT)lpData)->dwStreamID != (DWORD)lpMidiStrm) {
1559 FIXME("Dropping bad %s lpMidiHdr (streamID=%08x)\n",
1560 (lpMidiHdr->dwFlags & MHDR_ISSTRM) ? "stream" : "regular",
1561 ((LPMIDIEVENT)lpData)->dwStreamID);
1562 lpMidiHdr->dwFlags |= MHDR_DONE;
1563 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
1565 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1566 (HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
1567 lpwm->mod.dwInstance, (DWORD_PTR)lpMidiHdr, 0);
1568 break;
1571 for (lpmh = &lpMidiStrm->lpMidiHdr; *lpmh; lpmh = &(*lpmh)->lpNext);
1572 *lpmh = lpMidiHdr;
1573 lpMidiHdr = (LPMIDIHDR)msg->lParam;
1574 lpMidiHdr->lpNext = 0;
1575 lpMidiHdr->dwFlags |= MHDR_INQUEUE;
1576 lpMidiHdr->dwFlags &= ~MHDR_DONE;
1577 lpMidiHdr->dwOffset = 0;
1579 break;
1580 default:
1581 FIXME("Unknown message %d\n", msg->message);
1582 break;
1584 return TRUE;
1587 /**************************************************************************
1588 * MMSYSTEM_MidiStream_Player [internal]
1590 static DWORD CALLBACK MMSYSTEM_MidiStream_Player(LPVOID pmt)
1592 WINE_MIDIStream* lpMidiStrm = pmt;
1593 WINE_MIDI* lpwm;
1594 MSG msg;
1595 DWORD dwToGo;
1596 DWORD dwCurrTC;
1597 LPMIDIHDR lpMidiHdr;
1598 LPMIDIEVENT me;
1599 LPBYTE lpData = 0;
1601 TRACE("(%p)!\n", lpMidiStrm);
1603 if (!lpMidiStrm ||
1604 (lpwm = (LPWINE_MIDI)MMDRV_Get(lpMidiStrm->hDevice, MMDRV_MIDIOUT, FALSE)) == NULL)
1605 goto the_end;
1607 /* force thread's queue creation */
1608 /* Used to be InitThreadInput16(0, 5); */
1609 /* but following works also with hack in midiStreamOpen */
1610 PeekMessageA(&msg, 0, 0, 0, 0);
1612 /* FIXME: this next line must be called before midiStreamOut or midiStreamRestart are called */
1613 SetEvent(lpMidiStrm->hEvent);
1614 TRACE("Ready to go 1\n");
1615 /* thread is started in paused mode */
1616 SuspendThread(lpMidiStrm->hThread);
1617 TRACE("Ready to go 2\n");
1619 lpMidiStrm->dwStartTicks = 0;
1620 lpMidiStrm->dwPulses = 0;
1622 lpMidiStrm->lpMidiHdr = 0;
1624 for (;;) {
1625 lpMidiHdr = lpMidiStrm->lpMidiHdr;
1626 if (!lpMidiHdr) {
1627 /* for first message, block until one arrives, then process all that are available */
1628 GetMessageA(&msg, 0, 0, 0);
1629 do {
1630 if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm, lpwm, &msg))
1631 goto the_end;
1632 } while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE));
1633 lpData = 0;
1634 continue;
1637 if (!lpData)
1638 lpData = (LPBYTE)lpMidiHdr->lpData;
1640 me = (LPMIDIEVENT)(lpData + lpMidiHdr->dwOffset);
1642 /* do we have to wait ? */
1643 if (me->dwDeltaTime) {
1644 lpMidiStrm->dwPositionMS += MMSYSTEM_MidiStream_Convert(lpMidiStrm, me->dwDeltaTime);
1645 lpMidiStrm->dwPulses += me->dwDeltaTime;
1647 dwToGo = lpMidiStrm->dwStartTicks + lpMidiStrm->dwPositionMS;
1649 TRACE("%d/%d/%d\n", dwToGo, GetTickCount(), me->dwDeltaTime);
1650 while ((dwCurrTC = GetTickCount()) < dwToGo) {
1651 if (MsgWaitForMultipleObjects(0, NULL, FALSE, dwToGo - dwCurrTC, QS_ALLINPUT) == WAIT_OBJECT_0) {
1652 /* got a message, handle it */
1653 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) {
1654 if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm, lpwm, &msg))
1655 goto the_end;
1657 lpData = 0;
1658 } else {
1659 /* timeout, so me->dwDeltaTime is elapsed, can break the while loop */
1660 break;
1664 switch (MEVT_EVENTTYPE(me->dwEvent & ~MEVT_F_CALLBACK)) {
1665 case MEVT_COMMENT:
1666 FIXME("NIY: MEVT_COMMENT\n");
1667 /* do nothing, skip bytes */
1668 break;
1669 case MEVT_LONGMSG:
1670 FIXME("NIY: MEVT_LONGMSG, aka sending Sysex event\n");
1671 break;
1672 case MEVT_NOP:
1673 break;
1674 case MEVT_SHORTMSG:
1675 midiOutShortMsg(lpMidiStrm->hDevice, MEVT_EVENTPARM(me->dwEvent));
1676 break;
1677 case MEVT_TEMPO:
1678 lpMidiStrm->dwTempo = MEVT_EVENTPARM(me->dwEvent);
1679 break;
1680 case MEVT_VERSION:
1681 break;
1682 default:
1683 FIXME("Unknown MEVT (0x%02x)\n", MEVT_EVENTTYPE(me->dwEvent & ~MEVT_F_CALLBACK));
1684 break;
1686 if (me->dwEvent & MEVT_F_CALLBACK) {
1687 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1688 (HDRVR)lpMidiStrm->hDevice, MM_MOM_POSITIONCB,
1689 lpwm->mod.dwInstance, (LPARAM)lpMidiHdr, 0L);
1691 lpMidiHdr->dwOffset += sizeof(MIDIEVENT) - sizeof(me->dwParms);
1692 if (me->dwEvent & MEVT_F_LONG)
1693 lpMidiHdr->dwOffset += (MEVT_EVENTPARM(me->dwEvent) + 3) & ~3;
1694 if (lpMidiHdr->dwOffset >= lpMidiHdr->dwBufferLength) {
1695 /* done with this header */
1696 lpMidiHdr->dwFlags |= MHDR_DONE;
1697 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
1699 lpMidiStrm->lpMidiHdr = lpMidiHdr->lpNext;
1700 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1701 (HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
1702 lpwm->mod.dwInstance, (DWORD_PTR)lpMidiHdr, 0);
1703 lpData = 0;
1706 the_end:
1707 TRACE("End of thread\n");
1708 ExitThread(0);
1709 return 0; /* for removing the warning, never executed */
1712 /**************************************************************************
1713 * MMSYSTEM_MidiStream_PostMessage [internal]
1715 static BOOL MMSYSTEM_MidiStream_PostMessage(WINE_MIDIStream* lpMidiStrm, WORD msg, DWORD pmt1, DWORD pmt2)
1717 if (PostThreadMessageA(lpMidiStrm->dwThreadID, msg, pmt1, pmt2)) {
1718 DWORD count;
1720 ReleaseThunkLock(&count);
1721 WaitForSingleObject(lpMidiStrm->hEvent, INFINITE);
1722 RestoreThunkLock(count);
1723 } else {
1724 WARN("bad PostThreadMessageA\n");
1725 return FALSE;
1727 return TRUE;
1730 /**************************************************************************
1731 * midiStreamClose [WINMM.@]
1733 MMRESULT WINAPI midiStreamClose(HMIDISTRM hMidiStrm)
1735 WINE_MIDIStream* lpMidiStrm;
1737 TRACE("(%p)!\n", hMidiStrm);
1739 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL))
1740 return MMSYSERR_INVALHANDLE;
1742 midiStreamStop(hMidiStrm);
1743 MMSYSTEM_MidiStream_PostMessage(lpMidiStrm, WM_QUIT, 0, 0);
1744 HeapFree(GetProcessHeap(), 0, lpMidiStrm);
1745 CloseHandle(lpMidiStrm->hEvent);
1747 return midiOutClose((HMIDIOUT)hMidiStrm);
1750 /**************************************************************************
1751 * midiStreamOpen [WINMM.@]
1753 MMRESULT WINAPI midiStreamOpen(HMIDISTRM* lphMidiStrm, LPUINT lpuDeviceID,
1754 DWORD cMidi, DWORD_PTR dwCallback,
1755 DWORD_PTR dwInstance, DWORD fdwOpen)
1757 WINE_MIDIStream* lpMidiStrm;
1758 MMRESULT ret;
1759 MIDIOPENSTRMID mosm;
1760 LPWINE_MIDI lpwm;
1761 HMIDIOUT hMidiOut;
1763 TRACE("(%p, %p, %d, 0x%08lx, 0x%08lx, 0x%08x)!\n",
1764 lphMidiStrm, lpuDeviceID, cMidi, dwCallback, dwInstance, fdwOpen);
1766 if (cMidi != 1 || lphMidiStrm == NULL || lpuDeviceID == NULL)
1767 return MMSYSERR_INVALPARAM;
1769 lpMidiStrm = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_MIDIStream));
1770 if (!lpMidiStrm)
1771 return MMSYSERR_NOMEM;
1773 lpMidiStrm->dwTempo = 500000;
1774 lpMidiStrm->dwTimeDiv = 480; /* 480 is 120 quarter notes per minute *//* FIXME ??*/
1775 lpMidiStrm->dwPositionMS = 0;
1777 mosm.dwStreamID = (DWORD)lpMidiStrm;
1778 /* FIXME: the correct value is not allocated yet for MAPPER */
1779 mosm.wDeviceID = *lpuDeviceID;
1780 lpwm = MIDI_OutAlloc(&hMidiOut, &dwCallback, &dwInstance, &fdwOpen, 1, &mosm);
1781 lpMidiStrm->hDevice = hMidiOut;
1782 if (lphMidiStrm)
1783 *lphMidiStrm = (HMIDISTRM)hMidiOut;
1785 lpwm->mld.uDeviceID = *lpuDeviceID;
1787 ret = MMDRV_Open(&lpwm->mld, MODM_OPEN, (DWORD_PTR)&lpwm->mod, fdwOpen);
1788 lpMidiStrm->hEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
1789 lpMidiStrm->wFlags = HIWORD(fdwOpen);
1791 lpMidiStrm->hThread = CreateThread(NULL, 0, MMSYSTEM_MidiStream_Player,
1792 lpMidiStrm, 0, &(lpMidiStrm->dwThreadID));
1794 if (!lpMidiStrm->hThread) {
1795 midiStreamClose((HMIDISTRM)hMidiOut);
1796 return MMSYSERR_NOMEM;
1798 SetThreadPriority(lpMidiStrm->hThread, THREAD_PRIORITY_TIME_CRITICAL);
1800 /* wait for thread to have started, and for its queue to be created */
1802 DWORD count;
1804 /* (Release|Restore)ThunkLock() is needed when this method is called from 16 bit code,
1805 * (meaning the Win16Lock is set), so that it's released and the 32 bit thread running
1806 * MMSYSTEM_MidiStreamPlayer can acquire Win16Lock to create its queue.
1808 ReleaseThunkLock(&count);
1809 WaitForSingleObject(lpMidiStrm->hEvent, INFINITE);
1810 RestoreThunkLock(count);
1813 TRACE("=> (%u/%d) hMidi=%p ret=%d lpMidiStrm=%p\n",
1814 *lpuDeviceID, lpwm->mld.uDeviceID, *lphMidiStrm, ret, lpMidiStrm);
1815 return ret;
1818 /**************************************************************************
1819 * midiStreamOut [WINMM.@]
1821 MMRESULT WINAPI midiStreamOut(HMIDISTRM hMidiStrm, LPMIDIHDR lpMidiHdr,
1822 UINT cbMidiHdr)
1824 WINE_MIDIStream* lpMidiStrm;
1825 DWORD ret = MMSYSERR_NOERROR;
1827 TRACE("(%p, %p, %u)!\n", hMidiStrm, lpMidiHdr, cbMidiHdr);
1829 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1830 ret = MMSYSERR_INVALHANDLE;
1831 } else if (!lpMidiHdr) {
1832 ret = MMSYSERR_INVALPARAM;
1833 } else {
1834 if (!PostThreadMessageA(lpMidiStrm->dwThreadID,
1835 WINE_MSM_HEADER, cbMidiHdr,
1836 (LPARAM)lpMidiHdr)) {
1837 WARN("bad PostThreadMessageA\n");
1838 ret = MMSYSERR_ERROR;
1841 return ret;
1844 /**************************************************************************
1845 * midiStreamPause [WINMM.@]
1847 MMRESULT WINAPI midiStreamPause(HMIDISTRM hMidiStrm)
1849 WINE_MIDIStream* lpMidiStrm;
1850 DWORD ret = MMSYSERR_NOERROR;
1852 TRACE("(%p)!\n", hMidiStrm);
1854 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1855 ret = MMSYSERR_INVALHANDLE;
1856 } else {
1857 if (SuspendThread(lpMidiStrm->hThread) == 0xFFFFFFFF) {
1858 WARN("bad Suspend (%d)\n", GetLastError());
1859 ret = MMSYSERR_ERROR;
1862 return ret;
1865 /**************************************************************************
1866 * midiStreamPosition [WINMM.@]
1868 MMRESULT WINAPI midiStreamPosition(HMIDISTRM hMidiStrm, LPMMTIME lpMMT, UINT cbmmt)
1870 WINE_MIDIStream* lpMidiStrm;
1871 DWORD ret = MMSYSERR_NOERROR;
1873 TRACE("(%p, %p, %u)!\n", hMidiStrm, lpMMT, cbmmt);
1875 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1876 ret = MMSYSERR_INVALHANDLE;
1877 } else if (lpMMT == NULL || cbmmt != sizeof(MMTIME)) {
1878 ret = MMSYSERR_INVALPARAM;
1879 } else {
1880 switch (lpMMT->wType) {
1881 case TIME_MS:
1882 lpMMT->u.ms = lpMidiStrm->dwPositionMS;
1883 TRACE("=> %d ms\n", lpMMT->u.ms);
1884 break;
1885 case TIME_TICKS:
1886 lpMMT->u.ticks = lpMidiStrm->dwPulses;
1887 TRACE("=> %d ticks\n", lpMMT->u.ticks);
1888 break;
1889 default:
1890 WARN("Unsupported time type %d\n", lpMMT->wType);
1891 lpMMT->wType = TIME_MS;
1892 ret = MMSYSERR_INVALPARAM;
1893 break;
1896 return ret;
1899 /**************************************************************************
1900 * midiStreamProperty [WINMM.@]
1902 MMRESULT WINAPI midiStreamProperty(HMIDISTRM hMidiStrm, LPBYTE lpPropData, DWORD dwProperty)
1904 WINE_MIDIStream* lpMidiStrm;
1905 MMRESULT ret = MMSYSERR_NOERROR;
1907 TRACE("(%p, %p, %x)\n", hMidiStrm, lpPropData, dwProperty);
1909 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1910 ret = MMSYSERR_INVALHANDLE;
1911 } else if ((dwProperty & (MIDIPROP_GET|MIDIPROP_SET)) == 0) {
1912 ret = MMSYSERR_INVALPARAM;
1913 } else if (dwProperty & MIDIPROP_TEMPO) {
1914 MIDIPROPTEMPO* mpt = (MIDIPROPTEMPO*)lpPropData;
1916 if (sizeof(MIDIPROPTEMPO) != mpt->cbStruct) {
1917 ret = MMSYSERR_INVALPARAM;
1918 } else if (dwProperty & MIDIPROP_SET) {
1919 lpMidiStrm->dwTempo = mpt->dwTempo;
1920 TRACE("Setting tempo to %d\n", mpt->dwTempo);
1921 } else if (dwProperty & MIDIPROP_GET) {
1922 mpt->dwTempo = lpMidiStrm->dwTempo;
1923 TRACE("Getting tempo <= %d\n", mpt->dwTempo);
1925 } else if (dwProperty & MIDIPROP_TIMEDIV) {
1926 MIDIPROPTIMEDIV* mptd = (MIDIPROPTIMEDIV*)lpPropData;
1928 if (sizeof(MIDIPROPTIMEDIV) != mptd->cbStruct) {
1929 ret = MMSYSERR_INVALPARAM;
1930 } else if (dwProperty & MIDIPROP_SET) {
1931 lpMidiStrm->dwTimeDiv = mptd->dwTimeDiv;
1932 TRACE("Setting time div to %d\n", mptd->dwTimeDiv);
1933 } else if (dwProperty & MIDIPROP_GET) {
1934 mptd->dwTimeDiv = lpMidiStrm->dwTimeDiv;
1935 TRACE("Getting time div <= %d\n", mptd->dwTimeDiv);
1937 } else {
1938 ret = MMSYSERR_INVALPARAM;
1941 return ret;
1944 /**************************************************************************
1945 * midiStreamRestart [WINMM.@]
1947 MMRESULT WINAPI midiStreamRestart(HMIDISTRM hMidiStrm)
1949 WINE_MIDIStream* lpMidiStrm;
1950 MMRESULT ret = MMSYSERR_NOERROR;
1952 TRACE("(%p)!\n", hMidiStrm);
1954 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1955 ret = MMSYSERR_INVALHANDLE;
1956 } else {
1957 DWORD ret;
1959 /* since we increase the thread suspend count on each midiStreamPause
1960 * there may be a need for several midiStreamResume
1962 do {
1963 ret = ResumeThread(lpMidiStrm->hThread);
1964 } while (ret != 0xFFFFFFFF && ret != 0);
1965 if (ret == 0xFFFFFFFF) {
1966 WARN("bad Resume (%d)\n", GetLastError());
1967 ret = MMSYSERR_ERROR;
1968 } else {
1969 lpMidiStrm->dwStartTicks = GetTickCount() - lpMidiStrm->dwPositionMS;
1972 return ret;
1975 /**************************************************************************
1976 * midiStreamStop [WINMM.@]
1978 MMRESULT WINAPI midiStreamStop(HMIDISTRM hMidiStrm)
1980 WINE_MIDIStream* lpMidiStrm;
1981 MMRESULT ret = MMSYSERR_NOERROR;
1983 TRACE("(%p)!\n", hMidiStrm);
1985 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1986 ret = MMSYSERR_INVALHANDLE;
1987 } else {
1988 /* in case stream has been paused... FIXME is the current state correct ? */
1989 midiStreamRestart(hMidiStrm);
1990 MMSYSTEM_MidiStream_PostMessage(lpMidiStrm, WINE_MSM_STOP, 0, 0);
1992 return ret;
1995 static UINT WAVE_Open(HANDLE* lphndl, UINT uDeviceID, UINT uType,
1996 LPCWAVEFORMATEX lpFormat, DWORD_PTR dwCallback,
1997 DWORD_PTR dwInstance, DWORD dwFlags)
1999 HANDLE handle;
2000 LPWINE_MLD wmld;
2001 DWORD dwRet = MMSYSERR_NOERROR;
2002 WAVEOPENDESC wod;
2004 TRACE("(%p, %d, %s, %p, %08lX, %08lX, %08X);\n",
2005 lphndl, (int)uDeviceID, (uType==MMDRV_WAVEOUT)?"Out":"In", lpFormat, dwCallback,
2006 dwInstance, dwFlags);
2008 if (dwFlags & WAVE_FORMAT_QUERY)
2009 TRACE("WAVE_FORMAT_QUERY requested !\n");
2011 if (lpFormat == NULL) {
2012 WARN("bad format\n");
2013 return WAVERR_BADFORMAT;
2016 if ((dwFlags & WAVE_MAPPED) && (uDeviceID == (UINT)-1)) {
2017 WARN("invalid parameter\n");
2018 return MMSYSERR_INVALPARAM;
2021 /* may have a PCMWAVEFORMAT rather than a WAVEFORMATEX so don't read cbSize */
2022 TRACE("wFormatTag=%u, nChannels=%u, nSamplesPerSec=%u, nAvgBytesPerSec=%u, nBlockAlign=%u, wBitsPerSample=%u\n",
2023 lpFormat->wFormatTag, lpFormat->nChannels, lpFormat->nSamplesPerSec,
2024 lpFormat->nAvgBytesPerSec, lpFormat->nBlockAlign, lpFormat->wBitsPerSample);
2026 if ((wmld = MMDRV_Alloc(sizeof(WINE_WAVE), uType, &handle,
2027 &dwFlags, &dwCallback, &dwInstance)) == NULL) {
2028 WARN("no memory\n");
2029 return MMSYSERR_NOMEM;
2032 wod.hWave = handle;
2033 wod.lpFormat = (LPWAVEFORMATEX)lpFormat; /* should the struct be copied iso pointer? */
2034 wod.dwCallback = dwCallback;
2035 wod.dwInstance = dwInstance;
2036 wod.dnDevNode = 0L;
2038 TRACE("cb=%08lx\n", wod.dwCallback);
2040 for (;;) {
2041 if (dwFlags & WAVE_MAPPED) {
2042 wod.uMappedDeviceID = uDeviceID;
2043 uDeviceID = WAVE_MAPPER;
2044 } else {
2045 wod.uMappedDeviceID = -1;
2047 wmld->uDeviceID = uDeviceID;
2049 dwRet = MMDRV_Open(wmld, (uType == MMDRV_WAVEOUT) ? WODM_OPEN : WIDM_OPEN,
2050 (DWORD_PTR)&wod, dwFlags);
2052 TRACE("dwRet = %s\n", WINMM_ErrorToString(dwRet));
2053 if (dwRet != WAVERR_BADFORMAT ||
2054 ((dwFlags & (WAVE_MAPPED|WAVE_FORMAT_DIRECT)) != 0) || (uDeviceID == WAVE_MAPPER)) break;
2055 /* if we ask for a format which isn't supported by the physical driver,
2056 * let's try to map it through the wave mapper (except, if we already tried
2057 * or user didn't allow us to use acm codecs or the device is already the mapper)
2059 dwFlags |= WAVE_MAPPED;
2060 /* we shall loop only one */
2063 if ((dwFlags & WAVE_FORMAT_QUERY) || dwRet != MMSYSERR_NOERROR) {
2064 MMDRV_Free(handle, wmld);
2065 handle = 0;
2068 if (lphndl != NULL) *lphndl = handle;
2069 TRACE("=> %s hWave=%p\n", WINMM_ErrorToString(dwRet), handle);
2071 return dwRet;
2074 /**************************************************************************
2075 * waveOutGetNumDevs [WINMM.@]
2077 UINT WINAPI waveOutGetNumDevs(void)
2079 return MMDRV_GetNum(MMDRV_WAVEOUT);
2082 /**************************************************************************
2083 * waveOutGetDevCapsA [WINMM.@]
2085 UINT WINAPI waveOutGetDevCapsA(UINT_PTR uDeviceID, LPWAVEOUTCAPSA lpCaps,
2086 UINT uSize)
2088 WAVEOUTCAPSW wocW;
2089 UINT ret;
2091 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2093 ret = waveOutGetDevCapsW(uDeviceID, &wocW, sizeof(wocW));
2095 if (ret == MMSYSERR_NOERROR) {
2096 WAVEOUTCAPSA wocA;
2097 wocA.wMid = wocW.wMid;
2098 wocA.wPid = wocW.wPid;
2099 wocA.vDriverVersion = wocW.vDriverVersion;
2100 WideCharToMultiByte( CP_ACP, 0, wocW.szPname, -1, wocA.szPname,
2101 sizeof(wocA.szPname), NULL, NULL );
2102 wocA.dwFormats = wocW.dwFormats;
2103 wocA.wChannels = wocW.wChannels;
2104 wocA.dwSupport = wocW.dwSupport;
2105 memcpy(lpCaps, &wocA, min(uSize, sizeof(wocA)));
2107 return ret;
2110 /**************************************************************************
2111 * waveOutGetDevCapsW [WINMM.@]
2113 UINT WINAPI waveOutGetDevCapsW(UINT_PTR uDeviceID, LPWAVEOUTCAPSW lpCaps,
2114 UINT uSize)
2116 LPWINE_MLD wmld;
2118 TRACE("(%lu %p %u)!\n", uDeviceID, lpCaps, uSize);
2120 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2122 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_WAVEOUT, TRUE)) == NULL)
2123 return MMSYSERR_BADDEVICEID;
2125 return MMDRV_Message(wmld, WODM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize);
2128 /**************************************************************************
2129 * waveOutGetErrorTextA [WINMM.@]
2130 * waveInGetErrorTextA [WINMM.@]
2132 UINT WINAPI waveOutGetErrorTextA(UINT uError, LPSTR lpText, UINT uSize)
2134 UINT ret;
2136 if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
2137 else if (uSize == 0) ret = MMSYSERR_NOERROR;
2138 else
2140 LPWSTR xstr = HeapAlloc(GetProcessHeap(), 0, uSize * sizeof(WCHAR));
2141 if (!xstr) ret = MMSYSERR_NOMEM;
2142 else
2144 ret = waveOutGetErrorTextW(uError, xstr, uSize);
2145 if (ret == MMSYSERR_NOERROR)
2146 WideCharToMultiByte(CP_ACP, 0, xstr, -1, lpText, uSize, NULL, NULL);
2147 HeapFree(GetProcessHeap(), 0, xstr);
2150 return ret;
2153 /**************************************************************************
2154 * waveOutGetErrorTextW [WINMM.@]
2155 * waveInGetErrorTextW [WINMM.@]
2157 UINT WINAPI waveOutGetErrorTextW(UINT uError, LPWSTR lpText, UINT uSize)
2159 UINT ret = MMSYSERR_BADERRNUM;
2161 if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
2162 else if (uSize == 0) ret = MMSYSERR_NOERROR;
2163 else if (
2164 /* test has been removed because MMSYSERR_BASE is 0, and gcc did emit
2165 * a warning for the test was always true */
2166 (/*uError >= MMSYSERR_BASE && */ uError <= MMSYSERR_LASTERROR) ||
2167 (uError >= WAVERR_BASE && uError <= WAVERR_LASTERROR)) {
2168 if (LoadStringW(hWinMM32Instance,
2169 uError, lpText, uSize) > 0) {
2170 ret = MMSYSERR_NOERROR;
2173 return ret;
2176 /**************************************************************************
2177 * waveOutOpen [WINMM.@]
2178 * All the args/structs have the same layout as the win16 equivalents
2180 MMRESULT WINAPI waveOutOpen(LPHWAVEOUT lphWaveOut, UINT uDeviceID,
2181 LPCWAVEFORMATEX lpFormat, DWORD_PTR dwCallback,
2182 DWORD_PTR dwInstance, DWORD dwFlags)
2184 return WAVE_Open((HANDLE*)lphWaveOut, uDeviceID, MMDRV_WAVEOUT, lpFormat,
2185 dwCallback, dwInstance, dwFlags);
2188 /**************************************************************************
2189 * waveOutClose [WINMM.@]
2191 UINT WINAPI waveOutClose(HWAVEOUT hWaveOut)
2193 LPWINE_MLD wmld;
2194 DWORD dwRet;
2196 TRACE("(%p)\n", hWaveOut);
2198 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2199 return MMSYSERR_INVALHANDLE;
2201 dwRet = MMDRV_Close(wmld, WODM_CLOSE);
2202 if (dwRet != WAVERR_STILLPLAYING)
2203 MMDRV_Free(hWaveOut, wmld);
2205 return dwRet;
2208 /**************************************************************************
2209 * waveOutPrepareHeader [WINMM.@]
2211 UINT WINAPI waveOutPrepareHeader(HWAVEOUT hWaveOut,
2212 WAVEHDR* lpWaveOutHdr, UINT uSize)
2214 LPWINE_MLD wmld;
2215 UINT result;
2217 TRACE("(%p, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
2219 if (lpWaveOutHdr == NULL || uSize < sizeof (WAVEHDR))
2220 return MMSYSERR_INVALPARAM;
2222 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2223 return MMSYSERR_INVALHANDLE;
2225 if ((result = MMDRV_Message(wmld, WODM_PREPARE, (DWORD_PTR)lpWaveOutHdr,
2226 uSize)) != MMSYSERR_NOTSUPPORTED)
2227 return result;
2229 if (lpWaveOutHdr->dwFlags & WHDR_INQUEUE)
2230 return WAVERR_STILLPLAYING;
2232 lpWaveOutHdr->dwFlags |= WHDR_PREPARED;
2233 lpWaveOutHdr->dwFlags &= ~WHDR_DONE;
2235 return MMSYSERR_NOERROR;
2238 /**************************************************************************
2239 * waveOutUnprepareHeader [WINMM.@]
2241 UINT WINAPI waveOutUnprepareHeader(HWAVEOUT hWaveOut,
2242 LPWAVEHDR lpWaveOutHdr, UINT uSize)
2244 LPWINE_MLD wmld;
2245 UINT result;
2247 TRACE("(%p, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
2249 if (lpWaveOutHdr == NULL || uSize < sizeof (WAVEHDR))
2250 return MMSYSERR_INVALPARAM;
2252 if (!(lpWaveOutHdr->dwFlags & WHDR_PREPARED)) {
2253 return MMSYSERR_NOERROR;
2256 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2257 return MMSYSERR_INVALHANDLE;
2259 if ((result = MMDRV_Message(wmld, WODM_UNPREPARE, (DWORD_PTR)lpWaveOutHdr,
2260 uSize)) != MMSYSERR_NOTSUPPORTED)
2261 return result;
2263 if (lpWaveOutHdr->dwFlags & WHDR_INQUEUE)
2264 return WAVERR_STILLPLAYING;
2266 lpWaveOutHdr->dwFlags &= ~WHDR_PREPARED;
2267 lpWaveOutHdr->dwFlags |= WHDR_DONE;
2269 return MMSYSERR_NOERROR;
2272 /**************************************************************************
2273 * waveOutWrite [WINMM.@]
2275 UINT WINAPI waveOutWrite(HWAVEOUT hWaveOut, LPWAVEHDR lpWaveOutHdr,
2276 UINT uSize)
2278 LPWINE_MLD wmld;
2280 TRACE("(%p, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
2282 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2283 return MMSYSERR_INVALHANDLE;
2285 return MMDRV_Message(wmld, WODM_WRITE, (DWORD_PTR)lpWaveOutHdr, uSize);
2288 /**************************************************************************
2289 * waveOutBreakLoop [WINMM.@]
2291 UINT WINAPI waveOutBreakLoop(HWAVEOUT hWaveOut)
2293 LPWINE_MLD wmld;
2295 TRACE("(%p);\n", hWaveOut);
2297 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2298 return MMSYSERR_INVALHANDLE;
2299 return MMDRV_Message(wmld, WODM_BREAKLOOP, 0L, 0L);
2302 /**************************************************************************
2303 * waveOutPause [WINMM.@]
2305 UINT WINAPI waveOutPause(HWAVEOUT hWaveOut)
2307 LPWINE_MLD wmld;
2309 TRACE("(%p);\n", hWaveOut);
2311 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2312 return MMSYSERR_INVALHANDLE;
2313 return MMDRV_Message(wmld, WODM_PAUSE, 0L, 0L);
2316 /**************************************************************************
2317 * waveOutReset [WINMM.@]
2319 UINT WINAPI waveOutReset(HWAVEOUT hWaveOut)
2321 LPWINE_MLD wmld;
2323 TRACE("(%p);\n", hWaveOut);
2325 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2326 return MMSYSERR_INVALHANDLE;
2327 return MMDRV_Message(wmld, WODM_RESET, 0L, 0L);
2330 /**************************************************************************
2331 * waveOutRestart [WINMM.@]
2333 UINT WINAPI waveOutRestart(HWAVEOUT hWaveOut)
2335 LPWINE_MLD wmld;
2337 TRACE("(%p);\n", hWaveOut);
2339 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2340 return MMSYSERR_INVALHANDLE;
2341 return MMDRV_Message(wmld, WODM_RESTART, 0L, 0L);
2344 /**************************************************************************
2345 * waveOutGetPosition [WINMM.@]
2347 UINT WINAPI waveOutGetPosition(HWAVEOUT hWaveOut, LPMMTIME lpTime,
2348 UINT uSize)
2350 LPWINE_MLD wmld;
2352 TRACE("(%p, %p, %u);\n", hWaveOut, lpTime, uSize);
2354 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2355 return MMSYSERR_INVALHANDLE;
2357 return MMDRV_Message(wmld, WODM_GETPOS, (DWORD_PTR)lpTime, uSize);
2360 /**************************************************************************
2361 * waveOutGetPitch [WINMM.@]
2363 UINT WINAPI waveOutGetPitch(HWAVEOUT hWaveOut, LPDWORD lpdw)
2365 LPWINE_MLD wmld;
2367 TRACE("(%p, %p);\n", hWaveOut, lpdw);
2369 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2370 return MMSYSERR_INVALHANDLE;
2371 return MMDRV_Message(wmld, WODM_GETPITCH, (DWORD_PTR)lpdw, 0L);
2374 /**************************************************************************
2375 * waveOutSetPitch [WINMM.@]
2377 UINT WINAPI waveOutSetPitch(HWAVEOUT hWaveOut, DWORD dw)
2379 LPWINE_MLD wmld;
2381 TRACE("(%p, %08x);\n", hWaveOut, dw);
2383 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2384 return MMSYSERR_INVALHANDLE;
2385 return MMDRV_Message(wmld, WODM_SETPITCH, dw, 0L);
2388 /**************************************************************************
2389 * waveOutGetPlaybackRate [WINMM.@]
2391 UINT WINAPI waveOutGetPlaybackRate(HWAVEOUT hWaveOut, LPDWORD lpdw)
2393 LPWINE_MLD wmld;
2395 TRACE("(%p, %p);\n", hWaveOut, lpdw);
2397 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2398 return MMSYSERR_INVALHANDLE;
2399 return MMDRV_Message(wmld, WODM_GETPLAYBACKRATE, (DWORD_PTR)lpdw, 0L);
2402 /**************************************************************************
2403 * waveOutSetPlaybackRate [WINMM.@]
2405 UINT WINAPI waveOutSetPlaybackRate(HWAVEOUT hWaveOut, DWORD dw)
2407 LPWINE_MLD wmld;
2409 TRACE("(%p, %08x);\n", hWaveOut, dw);
2411 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2412 return MMSYSERR_INVALHANDLE;
2413 return MMDRV_Message(wmld, WODM_SETPLAYBACKRATE, dw, 0L);
2416 /**************************************************************************
2417 * waveOutGetVolume [WINMM.@]
2419 UINT WINAPI waveOutGetVolume(HWAVEOUT hWaveOut, LPDWORD lpdw)
2421 LPWINE_MLD wmld;
2423 TRACE("(%p, %p);\n", hWaveOut, lpdw);
2425 if (lpdw == NULL) {
2426 WARN("invalid parameter\n");
2427 return MMSYSERR_INVALPARAM;
2430 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, TRUE)) == NULL)
2431 return MMSYSERR_INVALHANDLE;
2433 return MMDRV_Message(wmld, WODM_GETVOLUME, (DWORD_PTR)lpdw, 0L);
2436 /**************************************************************************
2437 * waveOutSetVolume [WINMM.@]
2439 UINT WINAPI waveOutSetVolume(HWAVEOUT hWaveOut, DWORD dw)
2441 LPWINE_MLD wmld;
2443 TRACE("(%p, %08x);\n", hWaveOut, dw);
2445 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, TRUE)) == NULL)
2446 return MMSYSERR_INVALHANDLE;
2448 return MMDRV_Message(wmld, WODM_SETVOLUME, dw, 0L);
2451 /**************************************************************************
2452 * waveOutGetID [WINMM.@]
2454 UINT WINAPI waveOutGetID(HWAVEOUT hWaveOut, UINT* lpuDeviceID)
2456 LPWINE_MLD wmld;
2458 TRACE("(%p, %p);\n", hWaveOut, lpuDeviceID);
2460 if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
2462 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2463 return MMSYSERR_INVALHANDLE;
2465 *lpuDeviceID = wmld->uDeviceID;
2466 return 0;
2469 /**************************************************************************
2470 * waveOutMessage [WINMM.@]
2472 UINT WINAPI waveOutMessage(HWAVEOUT hWaveOut, UINT uMessage,
2473 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2475 LPWINE_MLD wmld;
2477 TRACE("(%p, %u, %ld, %ld)\n", hWaveOut, uMessage, dwParam1, dwParam2);
2479 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL) {
2480 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, TRUE)) != NULL) {
2481 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
2483 WARN("invalid handle\n");
2484 return MMSYSERR_INVALHANDLE;
2487 /* from M$ KB */
2488 if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER)) {
2489 WARN("invalid parameter\n");
2490 return MMSYSERR_INVALPARAM;
2493 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2);
2496 /**************************************************************************
2497 * waveInGetNumDevs [WINMM.@]
2499 UINT WINAPI waveInGetNumDevs(void)
2501 return MMDRV_GetNum(MMDRV_WAVEIN);
2504 /**************************************************************************
2505 * waveInGetDevCapsW [WINMM.@]
2507 UINT WINAPI waveInGetDevCapsW(UINT_PTR uDeviceID, LPWAVEINCAPSW lpCaps, UINT uSize)
2509 LPWINE_MLD wmld;
2511 TRACE("(%lu %p %u)!\n", uDeviceID, lpCaps, uSize);
2513 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2515 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_WAVEIN, TRUE)) == NULL)
2516 return MMSYSERR_BADDEVICEID;
2518 return MMDRV_Message(wmld, WIDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize);
2521 /**************************************************************************
2522 * waveInGetDevCapsA [WINMM.@]
2524 UINT WINAPI waveInGetDevCapsA(UINT_PTR uDeviceID, LPWAVEINCAPSA lpCaps, UINT uSize)
2526 WAVEINCAPSW wicW;
2527 UINT ret;
2529 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2531 ret = waveInGetDevCapsW(uDeviceID, &wicW, sizeof(wicW));
2533 if (ret == MMSYSERR_NOERROR) {
2534 WAVEINCAPSA wicA;
2535 wicA.wMid = wicW.wMid;
2536 wicA.wPid = wicW.wPid;
2537 wicA.vDriverVersion = wicW.vDriverVersion;
2538 WideCharToMultiByte( CP_ACP, 0, wicW.szPname, -1, wicA.szPname,
2539 sizeof(wicA.szPname), NULL, NULL );
2540 wicA.dwFormats = wicW.dwFormats;
2541 wicA.wChannels = wicW.wChannels;
2542 memcpy(lpCaps, &wicA, min(uSize, sizeof(wicA)));
2544 return ret;
2547 /**************************************************************************
2548 * waveInOpen [WINMM.@]
2550 MMRESULT WINAPI waveInOpen(HWAVEIN* lphWaveIn, UINT uDeviceID,
2551 LPCWAVEFORMATEX lpFormat, DWORD_PTR dwCallback,
2552 DWORD_PTR dwInstance, DWORD dwFlags)
2554 return WAVE_Open((HANDLE*)lphWaveIn, uDeviceID, MMDRV_WAVEIN, lpFormat,
2555 dwCallback, dwInstance, dwFlags);
2558 /**************************************************************************
2559 * waveInClose [WINMM.@]
2561 UINT WINAPI waveInClose(HWAVEIN hWaveIn)
2563 LPWINE_MLD wmld;
2564 DWORD dwRet;
2566 TRACE("(%p)\n", hWaveIn);
2568 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2569 return MMSYSERR_INVALHANDLE;
2571 dwRet = MMDRV_Message(wmld, WIDM_CLOSE, 0L, 0L);
2572 if (dwRet != WAVERR_STILLPLAYING)
2573 MMDRV_Free(hWaveIn, wmld);
2574 return dwRet;
2577 /**************************************************************************
2578 * waveInPrepareHeader [WINMM.@]
2580 UINT WINAPI waveInPrepareHeader(HWAVEIN hWaveIn, WAVEHDR* lpWaveInHdr,
2581 UINT uSize)
2583 LPWINE_MLD wmld;
2584 UINT result;
2586 TRACE("(%p, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
2588 if (lpWaveInHdr == NULL || uSize < sizeof (WAVEHDR))
2589 return MMSYSERR_INVALPARAM;
2591 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2592 return MMSYSERR_INVALHANDLE;
2594 if ((result = MMDRV_Message(wmld, WIDM_PREPARE, (DWORD_PTR)lpWaveInHdr,
2595 uSize)) != MMSYSERR_NOTSUPPORTED)
2596 return result;
2598 if (lpWaveInHdr->dwFlags & WHDR_INQUEUE)
2599 return WAVERR_STILLPLAYING;
2601 lpWaveInHdr->dwFlags |= WHDR_PREPARED;
2602 lpWaveInHdr->dwFlags &= ~WHDR_DONE;
2603 lpWaveInHdr->dwBytesRecorded = 0;
2605 return MMSYSERR_NOERROR;
2608 /**************************************************************************
2609 * waveInUnprepareHeader [WINMM.@]
2611 UINT WINAPI waveInUnprepareHeader(HWAVEIN hWaveIn, WAVEHDR* lpWaveInHdr,
2612 UINT uSize)
2614 LPWINE_MLD wmld;
2615 UINT result;
2617 TRACE("(%p, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
2619 if (lpWaveInHdr == NULL || uSize < sizeof (WAVEHDR))
2620 return MMSYSERR_INVALPARAM;
2622 if (!(lpWaveInHdr->dwFlags & WHDR_PREPARED))
2623 return MMSYSERR_NOERROR;
2625 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2626 return MMSYSERR_INVALHANDLE;
2628 if ((result = MMDRV_Message(wmld, WIDM_UNPREPARE, (DWORD_PTR)lpWaveInHdr,
2629 uSize)) != MMSYSERR_NOTSUPPORTED)
2630 return result;
2632 if (lpWaveInHdr->dwFlags & WHDR_INQUEUE)
2633 return WAVERR_STILLPLAYING;
2635 lpWaveInHdr->dwFlags &= ~WHDR_PREPARED;
2636 lpWaveInHdr->dwFlags |= WHDR_DONE;
2638 return MMSYSERR_NOERROR;
2641 /**************************************************************************
2642 * waveInAddBuffer [WINMM.@]
2644 UINT WINAPI waveInAddBuffer(HWAVEIN hWaveIn,
2645 WAVEHDR* lpWaveInHdr, UINT uSize)
2647 LPWINE_MLD wmld;
2649 TRACE("(%p, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
2651 if (lpWaveInHdr == NULL) return MMSYSERR_INVALPARAM;
2652 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2653 return MMSYSERR_INVALHANDLE;
2655 return MMDRV_Message(wmld, WIDM_ADDBUFFER, (DWORD_PTR)lpWaveInHdr, uSize);
2658 /**************************************************************************
2659 * waveInReset [WINMM.@]
2661 UINT WINAPI waveInReset(HWAVEIN hWaveIn)
2663 LPWINE_MLD wmld;
2665 TRACE("(%p);\n", hWaveIn);
2667 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2668 return MMSYSERR_INVALHANDLE;
2670 return MMDRV_Message(wmld, WIDM_RESET, 0L, 0L);
2673 /**************************************************************************
2674 * waveInStart [WINMM.@]
2676 UINT WINAPI waveInStart(HWAVEIN hWaveIn)
2678 LPWINE_MLD wmld;
2680 TRACE("(%p);\n", hWaveIn);
2682 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2683 return MMSYSERR_INVALHANDLE;
2685 return MMDRV_Message(wmld, WIDM_START, 0L, 0L);
2688 /**************************************************************************
2689 * waveInStop [WINMM.@]
2691 UINT WINAPI waveInStop(HWAVEIN hWaveIn)
2693 LPWINE_MLD wmld;
2695 TRACE("(%p);\n", hWaveIn);
2697 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2698 return MMSYSERR_INVALHANDLE;
2700 return MMDRV_Message(wmld,WIDM_STOP, 0L, 0L);
2703 /**************************************************************************
2704 * waveInGetPosition [WINMM.@]
2706 UINT WINAPI waveInGetPosition(HWAVEIN hWaveIn, LPMMTIME lpTime,
2707 UINT uSize)
2709 LPWINE_MLD wmld;
2711 TRACE("(%p, %p, %u);\n", hWaveIn, lpTime, uSize);
2713 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2714 return MMSYSERR_INVALHANDLE;
2716 return MMDRV_Message(wmld, WIDM_GETPOS, (DWORD_PTR)lpTime, uSize);
2719 /**************************************************************************
2720 * waveInGetID [WINMM.@]
2722 UINT WINAPI waveInGetID(HWAVEIN hWaveIn, UINT* lpuDeviceID)
2724 LPWINE_MLD wmld;
2726 TRACE("(%p, %p);\n", hWaveIn, lpuDeviceID);
2728 if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
2730 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2731 return MMSYSERR_INVALHANDLE;
2733 *lpuDeviceID = wmld->uDeviceID;
2734 return MMSYSERR_NOERROR;
2737 /**************************************************************************
2738 * waveInMessage [WINMM.@]
2740 UINT WINAPI waveInMessage(HWAVEIN hWaveIn, UINT uMessage,
2741 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2743 LPWINE_MLD wmld;
2745 TRACE("(%p, %u, %ld, %ld)\n", hWaveIn, uMessage, dwParam1, dwParam2);
2747 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL) {
2748 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, TRUE)) != NULL) {
2749 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
2751 return MMSYSERR_INVALHANDLE;
2754 /* from M$ KB */
2755 if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER))
2756 return MMSYSERR_INVALPARAM;
2759 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2);
2762 struct mm_starter
2764 LPTASKCALLBACK cb;
2765 DWORD client;
2766 HANDLE event;
2769 static DWORD WINAPI mmTaskRun(void* pmt)
2771 struct mm_starter mms;
2773 memcpy(&mms, pmt, sizeof(struct mm_starter));
2774 HeapFree(GetProcessHeap(), 0, pmt);
2775 mms.cb(mms.client);
2776 if (mms.event) SetEvent(mms.event);
2777 return 0;
2780 /******************************************************************
2781 * mmTaskCreate (WINMM.@)
2783 UINT WINAPI mmTaskCreate(LPTASKCALLBACK cb, HANDLE* ph, DWORD_PTR client)
2785 HANDLE hThread;
2786 HANDLE hEvent = 0;
2787 struct mm_starter *mms;
2789 mms = HeapAlloc(GetProcessHeap(), 0, sizeof(struct mm_starter));
2790 if (mms == NULL) return TASKERR_OUTOFMEMORY;
2792 mms->cb = cb;
2793 mms->client = client;
2794 if (ph) hEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
2795 mms->event = hEvent;
2797 hThread = CreateThread(0, 0, mmTaskRun, mms, 0, NULL);
2798 if (!hThread) {
2799 HeapFree(GetProcessHeap(), 0, mms);
2800 if (hEvent) CloseHandle(hEvent);
2801 return TASKERR_OUTOFMEMORY;
2803 SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);
2804 if (ph) *ph = hEvent;
2805 CloseHandle(hThread);
2806 return 0;
2809 /******************************************************************
2810 * mmTaskBlock (WINMM.@)
2812 VOID WINAPI mmTaskBlock(DWORD tid)
2814 MSG msg;
2818 GetMessageA(&msg, 0, 0, 0);
2819 if (msg.hwnd) DispatchMessageA(&msg);
2820 } while (msg.message != WM_USER);
2823 /******************************************************************
2824 * mmTaskSignal (WINMM.@)
2826 BOOL WINAPI mmTaskSignal(DWORD tid)
2828 return PostThreadMessageW(tid, WM_USER, 0, 0);
2831 /******************************************************************
2832 * mmTaskYield (WINMM.@)
2834 VOID WINAPI mmTaskYield(VOID) {}
2836 /******************************************************************
2837 * mmGetCurrentTask (WINMM.@)
2839 DWORD WINAPI mmGetCurrentTask(VOID)
2841 return GetCurrentThreadId();