If given a bad device id waveOutGetDevCapsA is supposed to return
[wine/multimedia.git] / dlls / winmm / winmm.c
blobd5c451c55f0ff8c0ea6c481cd261844a8e348352
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 #include <string.h>
33 #include "mmsystem.h"
34 #include "winbase.h"
35 #include "wine/winuser16.h" /* FIXME: should be removed, only used for UserYield16 */
36 #include "heap.h"
37 #include "winternl.h"
38 #include "winemm.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(winmm);
44 /* ========================================================================
45 * G L O B A L S E T T I N G S
46 * ========================================================================*/
48 LPWINE_MM_IDATA WINMM_IData /* = NULL */;
50 /**************************************************************************
51 * WINMM_CreateIData [internal]
53 static BOOL WINMM_CreateIData(HINSTANCE hInstDLL)
55 WINMM_IData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINE_MM_IDATA));
57 if (!WINMM_IData)
58 return FALSE;
59 WINMM_IData->hWinMM32Instance = hInstDLL;
60 InitializeCriticalSection(&WINMM_IData->cs);
61 WINMM_IData->cs.DebugInfo = (void*)__FILE__ ": WinMM";
62 WINMM_IData->psStopEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
63 WINMM_IData->psLastEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
64 TRACE("Created IData (%p)\n", WINMM_IData);
65 return TRUE;
68 /**************************************************************************
69 * WINMM_DeleteIData [internal]
71 static void WINMM_DeleteIData(void)
73 if (WINMM_IData) {
74 TIME_MMTimeStop();
76 /* FIXME: should also free content and resources allocated
77 * inside WINMM_IData */
78 CloseHandle(WINMM_IData->psStopEvent);
79 CloseHandle(WINMM_IData->psLastEvent);
80 DeleteCriticalSection(&WINMM_IData->cs);
81 HeapFree(GetProcessHeap(), 0, WINMM_IData);
82 WINMM_IData = NULL;
86 /******************************************************************
87 * WINMM_LoadMMSystem
90 BOOL WINMM_CheckForMMSystem(void)
92 /* 0 is not checked yet, -1 is not present, 1 is present */
93 static int loaded /* = 0 */;
95 if (loaded == 0)
97 HANDLE h = GetModuleHandleA("kernel32");
98 loaded = -1;
99 if (h)
101 HANDLE (WINAPI *gmh)(LPCSTR) = (void*)GetProcAddress(h, "GetModuleHandle16");
102 DWORD (WINAPI *ll)(LPCSTR) = (void*)GetProcAddress(h, "LoadLibrary16");
103 if (gmh && ll && (gmh("MMSYSTEM.DLL") || ll("MMSYSTEM.DLL")))
104 loaded = 1;
107 return loaded > 0;
110 /**************************************************************************
111 * DllMain (WINMM.init)
113 * WINMM DLL entry point
116 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID fImpLoad)
118 TRACE("%p 0x%lx %p\n", hInstDLL, fdwReason, fImpLoad);
120 switch (fdwReason) {
121 case DLL_PROCESS_ATTACH:
122 if (!WINMM_CreateIData(hInstDLL))
123 return FALSE;
124 if (!MCI_Init() || !MMDRV_Init()) {
125 WINMM_DeleteIData();
126 return FALSE;
128 break;
129 case DLL_PROCESS_DETACH:
130 /* close all opened MCI drivers */
131 MCI_SendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_WAIT, 0L, TRUE);
132 MMDRV_Exit();
133 /* now unload all remaining drivers... */
134 DRIVER_UnloadAll();
136 WINMM_DeleteIData();
137 break;
138 case DLL_THREAD_ATTACH:
139 case DLL_THREAD_DETACH:
140 break;
142 return TRUE;
145 /**************************************************************************
146 * Mixer devices. New to Win95
149 /**************************************************************************
150 * find out the real mixer ID depending on hmix (depends on dwFlags)
152 static LPWINE_MIXER MIXER_GetDev(HMIXEROBJ hmix, DWORD dwFlags)
154 LPWINE_MIXER lpwm = NULL;
156 switch (dwFlags & 0xF0000000ul) {
157 case MIXER_OBJECTF_MIXER:
158 lpwm = (LPWINE_MIXER)MMDRV_Get(hmix, MMDRV_MIXER, TRUE);
159 break;
160 case MIXER_OBJECTF_HMIXER:
161 lpwm = (LPWINE_MIXER)MMDRV_Get(hmix, MMDRV_MIXER, FALSE);
162 break;
163 case MIXER_OBJECTF_WAVEOUT:
164 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEOUT, TRUE, MMDRV_MIXER);
165 break;
166 case MIXER_OBJECTF_HWAVEOUT:
167 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEOUT, FALSE, MMDRV_MIXER);
168 break;
169 case MIXER_OBJECTF_WAVEIN:
170 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEIN, TRUE, MMDRV_MIXER);
171 break;
172 case MIXER_OBJECTF_HWAVEIN:
173 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEIN, FALSE, MMDRV_MIXER);
174 break;
175 case MIXER_OBJECTF_MIDIOUT:
176 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIOUT, TRUE, MMDRV_MIXER);
177 break;
178 case MIXER_OBJECTF_HMIDIOUT:
179 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIOUT, FALSE, MMDRV_MIXER);
180 break;
181 case MIXER_OBJECTF_MIDIIN:
182 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIIN, TRUE, MMDRV_MIXER);
183 break;
184 case MIXER_OBJECTF_HMIDIIN:
185 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIIN, FALSE, MMDRV_MIXER);
186 break;
187 case MIXER_OBJECTF_AUX:
188 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_AUX, TRUE, MMDRV_MIXER);
189 break;
190 default:
191 FIXME("Unsupported flag (%08lx)\n", dwFlags & 0xF0000000ul);
192 break;
194 return lpwm;
197 /**************************************************************************
198 * mixerGetNumDevs [WINMM.@]
200 UINT WINAPI mixerGetNumDevs(void)
202 return MMDRV_GetNum(MMDRV_MIXER);
205 /**************************************************************************
206 * mixerGetDevCapsA [WINMM.@]
208 UINT WINAPI mixerGetDevCapsA(UINT devid, LPMIXERCAPSA mixcaps, UINT size)
210 LPWINE_MLD wmld;
212 if ((wmld = MMDRV_Get((HANDLE)devid, MMDRV_MIXER, TRUE)) == NULL)
213 return MMSYSERR_BADDEVICEID;
215 return MMDRV_Message(wmld, MXDM_GETDEVCAPS, (DWORD)mixcaps, size, TRUE);
218 /**************************************************************************
219 * mixerGetDevCapsW [WINMM.@]
221 UINT WINAPI mixerGetDevCapsW(UINT devid, LPMIXERCAPSW mixcaps, UINT size)
223 MIXERCAPSA micA;
224 UINT ret = mixerGetDevCapsA(devid, &micA, sizeof(micA));
226 if (ret == MMSYSERR_NOERROR) {
227 mixcaps->wMid = micA.wMid;
228 mixcaps->wPid = micA.wPid;
229 mixcaps->vDriverVersion = micA.vDriverVersion;
230 MultiByteToWideChar( CP_ACP, 0, micA.szPname, -1, mixcaps->szPname,
231 sizeof(mixcaps->szPname)/sizeof(WCHAR) );
232 mixcaps->fdwSupport = micA.fdwSupport;
233 mixcaps->cDestinations = micA.cDestinations;
235 return ret;
238 UINT MIXER_Open(LPHMIXER lphMix, UINT uDeviceID, DWORD dwCallback,
239 DWORD dwInstance, DWORD fdwOpen, BOOL bFrom32)
241 HANDLE hMix;
242 LPWINE_MLD wmld;
243 DWORD dwRet = 0;
244 MIXEROPENDESC mod;
246 TRACE("(%p, %d, %08lx, %08lx, %08lx)\n",
247 lphMix, uDeviceID, dwCallback, dwInstance, fdwOpen);
249 wmld = MMDRV_Alloc(sizeof(WINE_MIXER), MMDRV_MIXER, &hMix, &fdwOpen,
250 &dwCallback, &dwInstance, bFrom32);
252 wmld->uDeviceID = uDeviceID;
253 mod.hmx = (HMIXEROBJ)hMix;
254 mod.dwCallback = dwCallback;
255 mod.dwInstance = dwInstance;
257 dwRet = MMDRV_Open(wmld, MXDM_OPEN, (DWORD)&mod, fdwOpen);
259 if (dwRet != MMSYSERR_NOERROR) {
260 MMDRV_Free(hMix, wmld);
261 hMix = 0;
263 if (lphMix) *lphMix = hMix;
264 TRACE("=> %ld hMixer=%p\n", dwRet, hMix);
266 return dwRet;
269 /**************************************************************************
270 * mixerOpen [WINMM.@]
272 UINT WINAPI mixerOpen(LPHMIXER lphMix, UINT uDeviceID, DWORD dwCallback,
273 DWORD dwInstance, DWORD fdwOpen)
275 return MIXER_Open(lphMix, uDeviceID, dwCallback, dwInstance, fdwOpen, TRUE);
278 /**************************************************************************
279 * mixerClose [WINMM.@]
281 UINT WINAPI mixerClose(HMIXER hMix)
283 LPWINE_MLD wmld;
284 DWORD dwRet;
286 TRACE("(%p)\n", hMix);
288 if ((wmld = MMDRV_Get(hMix, MMDRV_MIXER, FALSE)) == NULL) return MMSYSERR_INVALHANDLE;
290 dwRet = MMDRV_Close(wmld, MXDM_CLOSE);
291 MMDRV_Free(hMix, wmld);
293 return dwRet;
296 /**************************************************************************
297 * mixerGetID [WINMM.@]
299 UINT WINAPI mixerGetID(HMIXEROBJ hmix, LPUINT lpid, DWORD fdwID)
301 LPWINE_MIXER lpwm;
303 TRACE("(%p %p %08lx)\n", hmix, lpid, fdwID);
305 if ((lpwm = MIXER_GetDev(hmix, fdwID)) == NULL) {
306 return MMSYSERR_INVALHANDLE;
309 if (lpid)
310 *lpid = lpwm->mld.uDeviceID;
312 return MMSYSERR_NOERROR;
315 /**************************************************************************
316 * mixerGetControlDetailsA [WINMM.@]
318 UINT WINAPI mixerGetControlDetailsA(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcdA,
319 DWORD fdwDetails)
321 LPWINE_MIXER lpwm;
323 TRACE("(%p, %p, %08lx)\n", hmix, lpmcdA, fdwDetails);
325 if ((lpwm = MIXER_GetDev(hmix, fdwDetails)) == NULL)
326 return MMSYSERR_INVALHANDLE;
328 if (lpmcdA == NULL || lpmcdA->cbStruct != sizeof(*lpmcdA))
329 return MMSYSERR_INVALPARAM;
331 return MMDRV_Message(&lpwm->mld, MXDM_GETCONTROLDETAILS, (DWORD)lpmcdA,
332 fdwDetails, TRUE);
335 /**************************************************************************
336 * mixerGetControlDetailsW [WINMM.@]
338 UINT WINAPI mixerGetControlDetailsW(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcd, DWORD fdwDetails)
340 DWORD ret = MMSYSERR_NOTENABLED;
342 TRACE("(%p, %p, %08lx)\n", hmix, lpmcd, fdwDetails);
344 if (lpmcd == NULL || lpmcd->cbStruct != sizeof(*lpmcd))
345 return MMSYSERR_INVALPARAM;
347 switch (fdwDetails & MIXER_GETCONTROLDETAILSF_QUERYMASK) {
348 case MIXER_GETCONTROLDETAILSF_VALUE:
349 /* can savely use W structure as it is, no string inside */
350 ret = mixerGetControlDetailsA(hmix, lpmcd, fdwDetails);
351 break;
352 case MIXER_GETCONTROLDETAILSF_LISTTEXT:
354 MIXERCONTROLDETAILS_LISTTEXTW *pDetailsW = (MIXERCONTROLDETAILS_LISTTEXTW *)lpmcd->paDetails;
355 MIXERCONTROLDETAILS_LISTTEXTA *pDetailsA;
356 int size = max(1, lpmcd->cChannels) * sizeof(MIXERCONTROLDETAILS_LISTTEXTA);
357 int i;
359 if (lpmcd->u.cMultipleItems != 0) {
360 size *= lpmcd->u.cMultipleItems;
362 pDetailsA = (MIXERCONTROLDETAILS_LISTTEXTA *)HeapAlloc(GetProcessHeap(), 0, size);
363 lpmcd->paDetails = pDetailsA;
364 lpmcd->cbDetails = sizeof(MIXERCONTROLDETAILS_LISTTEXTA);
365 /* set up lpmcd->paDetails */
366 ret = mixerGetControlDetailsA(hmix, lpmcd, fdwDetails);
367 /* copy from lpmcd->paDetails back to paDetailsW; */
368 if(ret == MMSYSERR_NOERROR) {
369 for(i=0;i<lpmcd->u.cMultipleItems*lpmcd->cChannels;i++) {
370 pDetailsW->dwParam1 = pDetailsA->dwParam1;
371 pDetailsW->dwParam2 = pDetailsA->dwParam2;
372 MultiByteToWideChar( CP_ACP, 0, pDetailsA->szName, -1,
373 pDetailsW->szName,
374 sizeof(pDetailsW->szName)/sizeof(WCHAR) );
375 pDetailsA++;
376 pDetailsW++;
378 pDetailsA -= lpmcd->u.cMultipleItems*lpmcd->cChannels;
379 pDetailsW -= lpmcd->u.cMultipleItems*lpmcd->cChannels;
381 HeapFree(GetProcessHeap(), 0, pDetailsA);
382 lpmcd->paDetails = pDetailsW;
383 lpmcd->cbDetails = sizeof(MIXERCONTROLDETAILS_LISTTEXTW);
385 break;
386 default:
387 ERR("Unsupported fdwDetails=0x%08lx\n", fdwDetails);
390 return ret;
393 /**************************************************************************
394 * mixerGetLineControlsA [WINMM.@]
396 UINT WINAPI mixerGetLineControlsA(HMIXEROBJ hmix, LPMIXERLINECONTROLSA lpmlcA,
397 DWORD fdwControls)
399 LPWINE_MIXER lpwm;
401 TRACE("(%p, %p, %08lx)\n", hmix, lpmlcA, fdwControls);
403 if ((lpwm = MIXER_GetDev(hmix, fdwControls)) == NULL)
404 return MMSYSERR_INVALHANDLE;
406 if (lpmlcA == NULL || lpmlcA->cbStruct != sizeof(*lpmlcA))
407 return MMSYSERR_INVALPARAM;
409 return MMDRV_Message(&lpwm->mld, MXDM_GETLINECONTROLS, (DWORD)lpmlcA,
410 fdwControls, TRUE);
413 /**************************************************************************
414 * mixerGetLineControlsW [WINMM.@]
416 UINT WINAPI mixerGetLineControlsW(HMIXEROBJ hmix, LPMIXERLINECONTROLSW lpmlcW,
417 DWORD fdwControls)
419 MIXERLINECONTROLSA mlcA;
420 DWORD ret;
421 int i;
423 TRACE("(%p, %p, %08lx)\n", hmix, lpmlcW, fdwControls);
425 if (lpmlcW == NULL || lpmlcW->cbStruct != sizeof(*lpmlcW) ||
426 lpmlcW->cbmxctrl != sizeof(MIXERCONTROLW))
427 return MMSYSERR_INVALPARAM;
429 mlcA.cbStruct = sizeof(mlcA);
430 mlcA.dwLineID = lpmlcW->dwLineID;
431 mlcA.u.dwControlID = lpmlcW->u.dwControlID;
432 mlcA.u.dwControlType = lpmlcW->u.dwControlType;
433 mlcA.cControls = lpmlcW->cControls;
434 mlcA.cbmxctrl = sizeof(MIXERCONTROLA);
435 mlcA.pamxctrl = HeapAlloc(GetProcessHeap(), 0,
436 mlcA.cControls * mlcA.cbmxctrl);
438 ret = mixerGetLineControlsA(hmix, &mlcA, fdwControls);
440 if (ret == MMSYSERR_NOERROR) {
441 lpmlcW->dwLineID = mlcA.dwLineID;
442 lpmlcW->u.dwControlID = mlcA.u.dwControlID;
443 lpmlcW->u.dwControlType = mlcA.u.dwControlType;
444 lpmlcW->cControls = mlcA.cControls;
446 for (i = 0; i < mlcA.cControls; i++) {
447 lpmlcW->pamxctrl[i].cbStruct = sizeof(MIXERCONTROLW);
448 lpmlcW->pamxctrl[i].dwControlID = mlcA.pamxctrl[i].dwControlID;
449 lpmlcW->pamxctrl[i].dwControlType = mlcA.pamxctrl[i].dwControlType;
450 lpmlcW->pamxctrl[i].fdwControl = mlcA.pamxctrl[i].fdwControl;
451 lpmlcW->pamxctrl[i].cMultipleItems = mlcA.pamxctrl[i].cMultipleItems;
452 MultiByteToWideChar( CP_ACP, 0, mlcA.pamxctrl[i].szShortName, -1,
453 lpmlcW->pamxctrl[i].szShortName,
454 sizeof(lpmlcW->pamxctrl[i].szShortName)/sizeof(WCHAR) );
455 MultiByteToWideChar( CP_ACP, 0, mlcA.pamxctrl[i].szName, -1,
456 lpmlcW->pamxctrl[i].szName,
457 sizeof(lpmlcW->pamxctrl[i].szName)/sizeof(WCHAR) );
458 /* sizeof(lpmlcW->pamxctrl[i].Bounds) ==
459 * sizeof(mlcA.pamxctrl[i].Bounds) */
460 memcpy(&lpmlcW->pamxctrl[i].Bounds, &mlcA.pamxctrl[i].Bounds,
461 sizeof(mlcA.pamxctrl[i].Bounds));
462 /* sizeof(lpmlcW->pamxctrl[i].Metrics) ==
463 * sizeof(mlcA.pamxctrl[i].Metrics) */
464 memcpy(&lpmlcW->pamxctrl[i].Metrics, &mlcA.pamxctrl[i].Metrics,
465 sizeof(mlcA.pamxctrl[i].Metrics));
469 HeapFree(GetProcessHeap(), 0, mlcA.pamxctrl);
471 return ret;
474 /**************************************************************************
475 * mixerGetLineInfoA [WINMM.@]
477 UINT WINAPI mixerGetLineInfoA(HMIXEROBJ hmix, LPMIXERLINEA lpmliW, DWORD fdwInfo)
479 LPWINE_MIXER lpwm;
481 TRACE("(%p, %p, %08lx)\n", hmix, lpmliW, fdwInfo);
483 if ((lpwm = MIXER_GetDev(hmix, fdwInfo)) == NULL)
484 return MMSYSERR_INVALHANDLE;
486 return MMDRV_Message(&lpwm->mld, MXDM_GETLINEINFO, (DWORD)lpmliW,
487 fdwInfo, TRUE);
490 /**************************************************************************
491 * mixerGetLineInfoW [WINMM.@]
493 UINT WINAPI mixerGetLineInfoW(HMIXEROBJ hmix, LPMIXERLINEW lpmliW,
494 DWORD fdwInfo)
496 MIXERLINEA mliA;
497 UINT ret;
499 TRACE("(%p, %p, %08lx)\n", hmix, lpmliW, fdwInfo);
501 if (lpmliW == NULL || lpmliW->cbStruct != sizeof(*lpmliW))
502 return MMSYSERR_INVALPARAM;
504 mliA.cbStruct = sizeof(mliA);
505 switch (fdwInfo & MIXER_GETLINEINFOF_QUERYMASK) {
506 case MIXER_GETLINEINFOF_COMPONENTTYPE:
507 mliA.dwComponentType = lpmliW->dwComponentType;
508 break;
509 case MIXER_GETLINEINFOF_DESTINATION:
510 mliA.dwDestination = lpmliW->dwDestination;
511 break;
512 case MIXER_GETLINEINFOF_LINEID:
513 mliA.dwLineID = lpmliW->dwLineID;
514 break;
515 case MIXER_GETLINEINFOF_SOURCE:
516 mliA.dwDestination = lpmliW->dwDestination;
517 mliA.dwSource = lpmliW->dwSource;
518 break;
519 case MIXER_GETLINEINFOF_TARGETTYPE:
520 mliA.Target.dwType = lpmliW->Target.dwType;
521 mliA.Target.wMid = lpmliW->Target.wMid;
522 mliA.Target.wPid = lpmliW->Target.wPid;
523 mliA.Target.vDriverVersion = lpmliW->Target.vDriverVersion;
524 WideCharToMultiByte( CP_ACP, 0, lpmliW->Target.szPname, -1, mliA.Target.szPname, sizeof(mliA.Target.szPname), NULL, NULL);
525 break;
526 default:
527 FIXME("Unsupported fdwControls=0x%08lx\n", fdwInfo);
530 ret = mixerGetLineInfoA(hmix, &mliA, fdwInfo);
532 lpmliW->dwDestination = mliA.dwDestination;
533 lpmliW->dwSource = mliA.dwSource;
534 lpmliW->dwLineID = mliA.dwLineID;
535 lpmliW->fdwLine = mliA.fdwLine;
536 lpmliW->dwUser = mliA.dwUser;
537 lpmliW->dwComponentType = mliA.dwComponentType;
538 lpmliW->cChannels = mliA.cChannels;
539 lpmliW->cConnections = mliA.cConnections;
540 lpmliW->cControls = mliA.cControls;
541 MultiByteToWideChar( CP_ACP, 0, mliA.szShortName, -1, lpmliW->szShortName,
542 sizeof(lpmliW->szShortName)/sizeof(WCHAR) );
543 MultiByteToWideChar( CP_ACP, 0, mliA.szName, -1, lpmliW->szName,
544 sizeof(lpmliW->szName)/sizeof(WCHAR) );
545 lpmliW->Target.dwType = mliA.Target.dwType;
546 lpmliW->Target.dwDeviceID = mliA.Target.dwDeviceID;
547 lpmliW->Target.wMid = mliA.Target.wMid;
548 lpmliW->Target.wPid = mliA.Target.wPid;
549 lpmliW->Target.vDriverVersion = mliA.Target.vDriverVersion;
550 MultiByteToWideChar( CP_ACP, 0, mliA.Target.szPname, -1, lpmliW->Target.szPname,
551 sizeof(lpmliW->Target.szPname)/sizeof(WCHAR) );
553 return ret;
556 /**************************************************************************
557 * mixerSetControlDetails [WINMM.@]
559 UINT WINAPI mixerSetControlDetails(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcdA,
560 DWORD fdwDetails)
562 LPWINE_MIXER lpwm;
564 TRACE("(%p, %p, %08lx)\n", hmix, lpmcdA, fdwDetails);
566 if ((lpwm = MIXER_GetDev(hmix, fdwDetails)) == NULL)
567 return MMSYSERR_INVALHANDLE;
569 return MMDRV_Message(&lpwm->mld, MXDM_SETCONTROLDETAILS, (DWORD)lpmcdA,
570 fdwDetails, TRUE);
573 /**************************************************************************
574 * mixerMessage [WINMM.@]
576 UINT WINAPI mixerMessage(HMIXER hmix, UINT uMsg, DWORD dwParam1, DWORD dwParam2)
578 LPWINE_MLD wmld;
580 TRACE("(%04lx, %d, %08lx, %08lx): semi-stub?\n",
581 (DWORD)hmix, uMsg, dwParam1, dwParam2);
583 if ((wmld = MMDRV_Get(hmix, MMDRV_MIXER, FALSE)) == NULL)
584 return MMSYSERR_INVALHANDLE;
586 return MMDRV_Message(wmld, uMsg, dwParam1, dwParam2, TRUE);
589 /**************************************************************************
590 * auxGetNumDevs [WINMM.@]
592 UINT WINAPI auxGetNumDevs(void)
594 return MMDRV_GetNum(MMDRV_AUX);
597 /**************************************************************************
598 * auxGetDevCapsW [WINMM.@]
600 UINT WINAPI auxGetDevCapsW(UINT uDeviceID, LPAUXCAPSW lpCaps, UINT uSize)
602 AUXCAPSA acA;
603 UINT ret = auxGetDevCapsA(uDeviceID, &acA, sizeof(acA));
605 lpCaps->wMid = acA.wMid;
606 lpCaps->wPid = acA.wPid;
607 lpCaps->vDriverVersion = acA.vDriverVersion;
608 MultiByteToWideChar( CP_ACP, 0, acA.szPname, -1, lpCaps->szPname,
609 sizeof(lpCaps->szPname)/sizeof(WCHAR) );
610 lpCaps->wTechnology = acA.wTechnology;
611 lpCaps->dwSupport = acA.dwSupport;
612 return ret;
615 /**************************************************************************
616 * auxGetDevCapsA [WINMM.@]
618 UINT WINAPI auxGetDevCapsA(UINT uDeviceID, LPAUXCAPSA lpCaps, UINT uSize)
620 LPWINE_MLD wmld;
622 TRACE("(%04X, %p, %d) !\n", uDeviceID, lpCaps, uSize);
624 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
625 return MMSYSERR_INVALHANDLE;
626 return MMDRV_Message(wmld, AUXDM_GETDEVCAPS, (DWORD)lpCaps, uSize, TRUE);
629 /**************************************************************************
630 * auxGetVolume [WINMM.@]
632 UINT WINAPI auxGetVolume(UINT uDeviceID, DWORD* lpdwVolume)
634 LPWINE_MLD wmld;
636 TRACE("(%04X, %p) !\n", uDeviceID, lpdwVolume);
638 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
639 return MMSYSERR_INVALHANDLE;
640 return MMDRV_Message(wmld, AUXDM_GETVOLUME, (DWORD)lpdwVolume, 0L, TRUE);
643 /**************************************************************************
644 * auxSetVolume [WINMM.@]
646 UINT WINAPI auxSetVolume(UINT uDeviceID, DWORD dwVolume)
648 LPWINE_MLD wmld;
650 TRACE("(%04X, %lu) !\n", uDeviceID, dwVolume);
652 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
653 return MMSYSERR_INVALHANDLE;
654 return MMDRV_Message(wmld, AUXDM_SETVOLUME, dwVolume, 0L, TRUE);
657 /**************************************************************************
658 * auxOutMessage [WINMM.@]
660 DWORD WINAPI auxOutMessage(UINT uDeviceID, UINT uMessage, DWORD dw1, DWORD dw2)
662 LPWINE_MLD wmld;
664 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
665 return MMSYSERR_INVALHANDLE;
667 return MMDRV_Message(wmld, uMessage, dw1, dw2, TRUE);
670 /**************************************************************************
671 * mciGetErrorStringW [WINMM.@]
673 BOOL WINAPI mciGetErrorStringW(DWORD wError, LPWSTR lpstrBuffer, UINT uLength)
675 LPSTR bufstr = HeapAlloc(GetProcessHeap(), 0, uLength);
676 BOOL ret = mciGetErrorStringA(wError, bufstr, uLength);
678 MultiByteToWideChar( CP_ACP, 0, bufstr, -1, lpstrBuffer, uLength );
679 HeapFree(GetProcessHeap(), 0, bufstr);
680 return ret;
683 /**************************************************************************
684 * mciGetErrorStringA [WINMM.@]
686 BOOL WINAPI mciGetErrorStringA(DWORD dwError, LPSTR lpstrBuffer, UINT uLength)
688 BOOL16 ret = FALSE;
690 if (lpstrBuffer != NULL && uLength > 0 &&
691 dwError >= MCIERR_BASE && dwError <= MCIERR_CUSTOM_DRIVER_BASE) {
693 if (LoadStringA(WINMM_IData->hWinMM32Instance,
694 dwError, lpstrBuffer, uLength) > 0) {
695 ret = TRUE;
698 return ret;
701 /**************************************************************************
702 * mciDriverNotify [WINMM.@]
704 BOOL WINAPI mciDriverNotify(HWND hWndCallBack, UINT wDevID, UINT wStatus)
707 TRACE("(%p, %04x, %04X)\n", hWndCallBack, wDevID, wStatus);
709 return PostMessageA(hWndCallBack, MM_MCINOTIFY, wStatus, wDevID);
712 /**************************************************************************
713 * mciGetDriverData [WINMM.@]
715 DWORD WINAPI mciGetDriverData(UINT uDeviceID)
717 LPWINE_MCIDRIVER wmd;
719 TRACE("(%04x)\n", uDeviceID);
721 wmd = MCI_GetDriver(uDeviceID);
723 if (!wmd) {
724 WARN("Bad uDeviceID\n");
725 return 0L;
728 return wmd->dwPrivate;
731 /**************************************************************************
732 * mciSetDriverData [WINMM.@]
734 BOOL WINAPI mciSetDriverData(UINT uDeviceID, DWORD data)
736 LPWINE_MCIDRIVER wmd;
738 TRACE("(%04x, %08lx)\n", uDeviceID, data);
740 wmd = MCI_GetDriver(uDeviceID);
742 if (!wmd) {
743 WARN("Bad uDeviceID\n");
744 return FALSE;
747 wmd->dwPrivate = data;
748 return TRUE;
751 /**************************************************************************
752 * mciSendCommandA [WINMM.@]
754 DWORD WINAPI mciSendCommandA(UINT wDevID, UINT wMsg, DWORD dwParam1, DWORD dwParam2)
756 DWORD dwRet;
758 TRACE("(%08x, %s, %08lx, %08lx)\n",
759 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
761 dwRet = MCI_SendCommand(wDevID, wMsg, dwParam1, dwParam2, TRUE);
762 dwRet = MCI_CleanUp(dwRet, wMsg, dwParam2);
763 TRACE("=> %08lx\n", dwRet);
764 return dwRet;
767 /**************************************************************************
768 * mciSendCommandW [WINMM.@]
770 DWORD WINAPI mciSendCommandW(UINT wDevID, UINT wMsg, DWORD dwParam1, DWORD dwParam2)
772 FIXME("(%08x, %s, %08lx, %08lx): stub\n",
773 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
774 return MCIERR_UNSUPPORTED_FUNCTION;
777 /**************************************************************************
778 * mciGetDeviceIDA [WINMM.@]
780 UINT WINAPI mciGetDeviceIDA(LPCSTR lpstrName)
782 return MCI_GetDriverFromString(lpstrName);
785 /**************************************************************************
786 * mciGetDeviceIDW [WINMM.@]
788 UINT WINAPI mciGetDeviceIDW(LPCWSTR lpwstrName)
790 LPSTR lpstrName;
791 UINT ret;
793 lpstrName = HEAP_strdupWtoA(GetProcessHeap(), 0, lpwstrName);
794 ret = MCI_GetDriverFromString(lpstrName);
795 HeapFree(GetProcessHeap(), 0, lpstrName);
796 return ret;
799 /**************************************************************************
800 * MCI_DefYieldProc [internal]
802 UINT WINAPI MCI_DefYieldProc(MCIDEVICEID wDevID, DWORD data)
804 INT16 ret;
806 TRACE("(0x%04x, 0x%08lx)\n", wDevID, data);
808 if ((HIWORD(data) != 0 && HWND_16(GetActiveWindow()) != HIWORD(data)) ||
809 (GetAsyncKeyState(LOWORD(data)) & 1) == 0) {
810 UserYield16();
811 ret = 0;
812 } else {
813 MSG msg;
815 msg.hwnd = HWND_32(HIWORD(data));
816 while (!PeekMessageA(&msg, msg.hwnd, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE));
817 ret = -1;
819 return ret;
822 /**************************************************************************
823 * mciSetYieldProc [WINMM.@]
825 BOOL WINAPI mciSetYieldProc(UINT uDeviceID, YIELDPROC fpYieldProc, DWORD dwYieldData)
827 LPWINE_MCIDRIVER wmd;
829 TRACE("(%u, %p, %08lx)\n", uDeviceID, fpYieldProc, dwYieldData);
831 if (!(wmd = MCI_GetDriver(uDeviceID))) {
832 WARN("Bad uDeviceID\n");
833 return FALSE;
836 wmd->lpfnYieldProc = fpYieldProc;
837 wmd->dwYieldData = dwYieldData;
838 wmd->bIs32 = TRUE;
840 return TRUE;
843 /**************************************************************************
844 * mciGetDeviceIDFromElementIDW [WINMM.@]
846 UINT WINAPI mciGetDeviceIDFromElementIDW(DWORD dwElementID, LPCWSTR lpstrType)
848 /* FIXME: that's rather strange, there is no
849 * mciGetDeviceIDFromElementID32A in winmm.spec
851 FIXME("(%lu, %p) stub\n", dwElementID, lpstrType);
852 return 0;
855 /**************************************************************************
856 * mciGetYieldProc [WINMM.@]
858 YIELDPROC WINAPI mciGetYieldProc(UINT uDeviceID, DWORD* lpdwYieldData)
860 LPWINE_MCIDRIVER wmd;
862 TRACE("(%u, %p)\n", uDeviceID, lpdwYieldData);
864 if (!(wmd = MCI_GetDriver(uDeviceID))) {
865 WARN("Bad uDeviceID\n");
866 return NULL;
868 if (!wmd->lpfnYieldProc) {
869 WARN("No proc set\n");
870 return NULL;
872 if (!wmd->bIs32) {
873 WARN("Proc is 32 bit\n");
874 return NULL;
876 return wmd->lpfnYieldProc;
879 /**************************************************************************
880 * mciGetCreatorTask [WINMM.@]
882 HTASK WINAPI mciGetCreatorTask(UINT uDeviceID)
884 LPWINE_MCIDRIVER wmd;
885 HTASK ret = 0;
887 if ((wmd = MCI_GetDriver(uDeviceID))) ret = (HTASK)wmd->CreatorThread;
889 TRACE("(%u) => %p\n", uDeviceID, ret);
890 return ret;
893 /**************************************************************************
894 * mciDriverYield [WINMM.@]
896 UINT WINAPI mciDriverYield(UINT uDeviceID)
898 LPWINE_MCIDRIVER wmd;
899 UINT ret = 0;
901 TRACE("(%04x)\n", uDeviceID);
903 if (!(wmd = MCI_GetDriver(uDeviceID)) || !wmd->lpfnYieldProc || !wmd->bIs32) {
904 UserYield16();
905 } else {
906 ret = wmd->lpfnYieldProc(uDeviceID, wmd->dwYieldData);
909 return ret;
912 /**************************************************************************
913 * midiOutGetNumDevs [WINMM.@]
915 UINT WINAPI midiOutGetNumDevs(void)
917 return MMDRV_GetNum(MMDRV_MIDIOUT);
920 /**************************************************************************
921 * midiOutGetDevCapsW [WINMM.@]
923 UINT WINAPI midiOutGetDevCapsW(UINT uDeviceID, LPMIDIOUTCAPSW lpCaps,
924 UINT uSize)
926 MIDIOUTCAPSA mocA;
927 UINT ret;
929 ret = midiOutGetDevCapsA(uDeviceID, &mocA, sizeof(mocA));
930 lpCaps->wMid = mocA.wMid;
931 lpCaps->wPid = mocA.wPid;
932 lpCaps->vDriverVersion = mocA.vDriverVersion;
933 MultiByteToWideChar( CP_ACP, 0, mocA.szPname, -1, lpCaps->szPname,
934 sizeof(lpCaps->szPname)/sizeof(WCHAR) );
935 lpCaps->wTechnology = mocA.wTechnology;
936 lpCaps->wVoices = mocA.wVoices;
937 lpCaps->wNotes = mocA.wNotes;
938 lpCaps->wChannelMask = mocA.wChannelMask;
939 lpCaps->dwSupport = mocA.dwSupport;
940 return ret;
943 /**************************************************************************
944 * midiOutGetDevCapsA [WINMM.@]
946 UINT WINAPI midiOutGetDevCapsA(UINT uDeviceID, LPMIDIOUTCAPSA lpCaps,
947 UINT uSize)
949 LPWINE_MLD wmld;
951 TRACE("(%u, %p, %u);\n", uDeviceID, lpCaps, uSize);
953 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
955 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_MIDIOUT, TRUE)) == NULL)
956 return MMSYSERR_INVALHANDLE;
958 return MMDRV_Message(wmld, MODM_GETDEVCAPS, (DWORD)lpCaps, uSize, TRUE);
961 /**************************************************************************
962 * MIDI_GetErrorText [internal]
964 static UINT16 MIDI_GetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize)
966 UINT16 ret = MMSYSERR_BADERRNUM;
968 if (lpText == NULL) {
969 ret = MMSYSERR_INVALPARAM;
970 } else if (uSize == 0) {
971 ret = MMSYSERR_NOERROR;
972 } else if (
973 /* test has been removed 'coz MMSYSERR_BASE is 0, and gcc did emit
974 * a warning for the test was always true */
975 (/*uError >= MMSYSERR_BASE && */ uError <= MMSYSERR_LASTERROR) ||
976 (uError >= MIDIERR_BASE && uError <= MIDIERR_LASTERROR)) {
978 if (LoadStringA(WINMM_IData->hWinMM32Instance,
979 uError, lpText, uSize) > 0) {
980 ret = MMSYSERR_NOERROR;
983 return ret;
986 /**************************************************************************
987 * midiOutGetErrorTextA [WINMM.@]
989 UINT WINAPI midiOutGetErrorTextA(UINT uError, LPSTR lpText, UINT uSize)
991 return MIDI_GetErrorText(uError, lpText, uSize);
994 /**************************************************************************
995 * midiOutGetErrorTextW [WINMM.@]
997 UINT WINAPI midiOutGetErrorTextW(UINT uError, LPWSTR lpText, UINT uSize)
999 LPSTR xstr = HeapAlloc(GetProcessHeap(), 0, uSize);
1000 UINT ret;
1002 ret = MIDI_GetErrorText(uError, xstr, uSize);
1003 MultiByteToWideChar( CP_ACP, 0, xstr, -1, lpText, uSize );
1004 HeapFree(GetProcessHeap(), 0, xstr);
1005 return ret;
1008 /**************************************************************************
1009 * MIDI_OutAlloc [internal]
1011 static LPWINE_MIDI MIDI_OutAlloc(HMIDIOUT* lphMidiOut, LPDWORD lpdwCallback,
1012 LPDWORD lpdwInstance, LPDWORD lpdwFlags,
1013 DWORD cIDs, MIDIOPENSTRMID* lpIDs, BOOL bFrom32)
1015 HANDLE hMidiOut;
1016 LPWINE_MIDI lpwm;
1017 UINT size;
1019 size = sizeof(WINE_MIDI) + (cIDs ? (cIDs-1) : 0) * sizeof(MIDIOPENSTRMID);
1021 lpwm = (LPWINE_MIDI)MMDRV_Alloc(size, MMDRV_MIDIOUT, &hMidiOut, lpdwFlags,
1022 lpdwCallback, lpdwInstance, bFrom32);
1024 if (lphMidiOut != NULL)
1025 *lphMidiOut = hMidiOut;
1027 if (lpwm) {
1028 lpwm->mod.hMidi = (HMIDI) hMidiOut;
1029 lpwm->mod.dwCallback = *lpdwCallback;
1030 lpwm->mod.dwInstance = *lpdwInstance;
1031 lpwm->mod.dnDevNode = 0;
1032 lpwm->mod.cIds = cIDs;
1033 if (cIDs)
1034 memcpy(&(lpwm->mod.rgIds), lpIDs, cIDs * sizeof(MIDIOPENSTRMID));
1036 return lpwm;
1039 UINT MIDI_OutOpen(HMIDIOUT* lphMidiOut, UINT uDeviceID, DWORD dwCallback,
1040 DWORD dwInstance, DWORD dwFlags, BOOL bFrom32)
1042 HMIDIOUT hMidiOut;
1043 LPWINE_MIDI lpwm;
1044 UINT dwRet = 0;
1046 TRACE("(%p, %d, %08lX, %08lX, %08lX);\n",
1047 lphMidiOut, uDeviceID, dwCallback, dwInstance, dwFlags);
1049 if (lphMidiOut != NULL) *lphMidiOut = 0;
1051 lpwm = MIDI_OutAlloc(&hMidiOut, &dwCallback, &dwInstance, &dwFlags,
1052 0, NULL, bFrom32);
1054 if (lpwm == NULL)
1055 return MMSYSERR_NOMEM;
1057 lpwm->mld.uDeviceID = uDeviceID;
1059 dwRet = MMDRV_Open((LPWINE_MLD)lpwm, MODM_OPEN, (DWORD)&lpwm->mod, dwFlags);
1061 if (dwRet != MMSYSERR_NOERROR) {
1062 MMDRV_Free(hMidiOut, (LPWINE_MLD)lpwm);
1063 hMidiOut = 0;
1066 if (lphMidiOut) *lphMidiOut = hMidiOut;
1067 TRACE("=> %d hMidi=%p\n", dwRet, hMidiOut);
1069 return dwRet;
1072 /**************************************************************************
1073 * midiOutOpen [WINMM.@]
1075 UINT WINAPI midiOutOpen(HMIDIOUT* lphMidiOut, UINT uDeviceID,
1076 DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
1078 return MIDI_OutOpen(lphMidiOut, uDeviceID, dwCallback, dwInstance, dwFlags, TRUE);
1081 /**************************************************************************
1082 * midiOutClose [WINMM.@]
1084 UINT WINAPI midiOutClose(HMIDIOUT hMidiOut)
1086 LPWINE_MLD wmld;
1087 DWORD dwRet;
1089 TRACE("(%p)\n", hMidiOut);
1091 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1092 return MMSYSERR_INVALHANDLE;
1094 dwRet = MMDRV_Close(wmld, MODM_CLOSE);
1095 MMDRV_Free(hMidiOut, wmld);
1097 return dwRet;
1100 /**************************************************************************
1101 * midiOutPrepareHeader [WINMM.@]
1103 UINT WINAPI midiOutPrepareHeader(HMIDIOUT hMidiOut,
1104 MIDIHDR* lpMidiOutHdr, UINT uSize)
1106 LPWINE_MLD wmld;
1108 TRACE("(%p, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
1110 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1111 return MMSYSERR_INVALHANDLE;
1113 return MMDRV_Message(wmld, MODM_PREPARE, (DWORD)lpMidiOutHdr, uSize, TRUE);
1116 /**************************************************************************
1117 * midiOutUnprepareHeader [WINMM.@]
1119 UINT WINAPI midiOutUnprepareHeader(HMIDIOUT hMidiOut,
1120 MIDIHDR* lpMidiOutHdr, UINT uSize)
1122 LPWINE_MLD wmld;
1124 TRACE("(%p, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
1126 if (!(lpMidiOutHdr->dwFlags & MHDR_PREPARED)) {
1127 return MMSYSERR_NOERROR;
1130 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1131 return MMSYSERR_INVALHANDLE;
1133 return MMDRV_Message(wmld, MODM_UNPREPARE, (DWORD)lpMidiOutHdr, uSize, TRUE);
1136 /**************************************************************************
1137 * midiOutShortMsg [WINMM.@]
1139 UINT WINAPI midiOutShortMsg(HMIDIOUT hMidiOut, DWORD dwMsg)
1141 LPWINE_MLD wmld;
1143 TRACE("(%p, %08lX)\n", hMidiOut, dwMsg);
1145 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1146 return MMSYSERR_INVALHANDLE;
1148 return MMDRV_Message(wmld, MODM_DATA, dwMsg, 0L, TRUE);
1151 /**************************************************************************
1152 * midiOutLongMsg [WINMM.@]
1154 UINT WINAPI midiOutLongMsg(HMIDIOUT hMidiOut,
1155 MIDIHDR* lpMidiOutHdr, UINT uSize)
1157 LPWINE_MLD wmld;
1159 TRACE("(%p, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
1161 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1162 return MMSYSERR_INVALHANDLE;
1164 return MMDRV_Message(wmld, MODM_LONGDATA, (DWORD)lpMidiOutHdr, uSize, TRUE);
1167 /**************************************************************************
1168 * midiOutReset [WINMM.@]
1170 UINT WINAPI midiOutReset(HMIDIOUT hMidiOut)
1172 LPWINE_MLD wmld;
1174 TRACE("(%p)\n", hMidiOut);
1176 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1177 return MMSYSERR_INVALHANDLE;
1179 return MMDRV_Message(wmld, MODM_RESET, 0L, 0L, TRUE);
1182 /**************************************************************************
1183 * midiOutGetVolume [WINMM.@]
1185 UINT WINAPI midiOutGetVolume(UINT uDeviceID, DWORD* lpdwVolume)
1187 LPWINE_MLD wmld;
1189 TRACE("(%04X, %p);\n", uDeviceID, lpdwVolume);
1191 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_MIDIOUT, TRUE)) == NULL)
1192 return MMSYSERR_INVALHANDLE;
1194 return MMDRV_Message(wmld, MODM_GETVOLUME, (DWORD)lpdwVolume, 0L, TRUE);
1197 /**************************************************************************
1198 * midiOutSetVolume [WINMM.@]
1200 UINT WINAPI midiOutSetVolume(UINT uDeviceID, DWORD dwVolume)
1202 LPWINE_MLD wmld;
1204 TRACE("(%04X, %ld);\n", uDeviceID, dwVolume);
1206 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_MIDIOUT, TRUE)) == NULL)
1207 return MMSYSERR_INVALHANDLE;
1209 return MMDRV_Message(wmld, MODM_SETVOLUME, dwVolume, 0L, TRUE);
1212 /**************************************************************************
1213 * midiOutCachePatches [WINMM.@]
1215 UINT WINAPI midiOutCachePatches(HMIDIOUT hMidiOut, UINT uBank,
1216 WORD* lpwPatchArray, UINT uFlags)
1218 /* not really necessary to support this */
1219 FIXME("not supported yet\n");
1220 return MMSYSERR_NOTSUPPORTED;
1223 /**************************************************************************
1224 * midiOutCacheDrumPatches [WINMM.@]
1226 UINT WINAPI midiOutCacheDrumPatches(HMIDIOUT hMidiOut, UINT uPatch,
1227 WORD* lpwKeyArray, UINT uFlags)
1229 FIXME("not supported yet\n");
1230 return MMSYSERR_NOTSUPPORTED;
1233 /**************************************************************************
1234 * midiOutGetID [WINMM.@]
1236 UINT WINAPI midiOutGetID(HMIDIOUT hMidiOut, UINT* lpuDeviceID)
1238 LPWINE_MLD wmld;
1240 TRACE("(%p, %p)\n", hMidiOut, lpuDeviceID);
1242 if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
1243 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1244 return MMSYSERR_INVALHANDLE;
1246 *lpuDeviceID = wmld->uDeviceID;
1247 return MMSYSERR_NOERROR;
1250 /**************************************************************************
1251 * midiOutMessage [WINMM.@]
1253 DWORD WINAPI midiOutMessage(HMIDIOUT hMidiOut, UINT uMessage,
1254 DWORD dwParam1, DWORD dwParam2)
1256 LPWINE_MLD wmld;
1258 TRACE("(%p, %04X, %08lX, %08lX)\n", hMidiOut, uMessage, dwParam1, dwParam2);
1260 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL) {
1261 /* HACK... */
1262 if (uMessage == 0x0001) {
1263 *(LPDWORD)dwParam1 = 1;
1264 return 0;
1266 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, TRUE)) != NULL) {
1267 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
1269 return MMSYSERR_INVALHANDLE;
1272 switch (uMessage) {
1273 case MODM_OPEN:
1274 case MODM_CLOSE:
1275 FIXME("can't handle OPEN or CLOSE message!\n");
1276 return MMSYSERR_NOTSUPPORTED;
1278 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
1281 /**************************************************************************
1282 * midiInGetNumDevs [WINMM.@]
1284 UINT WINAPI midiInGetNumDevs(void)
1286 return MMDRV_GetNum(MMDRV_MIDIIN);
1289 /**************************************************************************
1290 * midiInGetDevCapsW [WINMM.@]
1292 UINT WINAPI midiInGetDevCapsW(UINT uDeviceID, LPMIDIINCAPSW lpCaps, UINT uSize)
1294 MIDIINCAPSA micA;
1295 UINT ret = midiInGetDevCapsA(uDeviceID, &micA, uSize);
1297 if (ret == MMSYSERR_NOERROR) {
1298 lpCaps->wMid = micA.wMid;
1299 lpCaps->wPid = micA.wPid;
1300 lpCaps->vDriverVersion = micA.vDriverVersion;
1301 MultiByteToWideChar( CP_ACP, 0, micA.szPname, -1, lpCaps->szPname,
1302 sizeof(lpCaps->szPname)/sizeof(WCHAR) );
1303 lpCaps->dwSupport = micA.dwSupport;
1305 return ret;
1308 /**************************************************************************
1309 * midiInGetDevCapsA [WINMM.@]
1311 UINT WINAPI midiInGetDevCapsA(UINT uDeviceID, LPMIDIINCAPSA lpCaps, UINT uSize)
1313 LPWINE_MLD wmld;
1315 TRACE("(%d, %p, %d);\n", uDeviceID, lpCaps, uSize);
1317 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_MIDIIN, TRUE)) == NULL)
1318 return MMSYSERR_INVALHANDLE;
1320 return MMDRV_Message(wmld, MIDM_GETDEVCAPS, (DWORD)lpCaps, uSize, TRUE);
1323 /**************************************************************************
1324 * midiInGetErrorTextW [WINMM.@]
1326 UINT WINAPI midiInGetErrorTextW(UINT uError, LPWSTR lpText, UINT uSize)
1328 LPSTR xstr = HeapAlloc(GetProcessHeap(), 0, uSize);
1329 UINT ret = MIDI_GetErrorText(uError, xstr, uSize);
1331 MultiByteToWideChar( CP_ACP, 0, xstr, -1, lpText, uSize );
1332 HeapFree(GetProcessHeap(), 0, xstr);
1333 return ret;
1336 /**************************************************************************
1337 * midiInGetErrorTextA [WINMM.@]
1339 UINT WINAPI midiInGetErrorTextA(UINT uError, LPSTR lpText, UINT uSize)
1341 return MIDI_GetErrorText(uError, lpText, uSize);
1344 UINT MIDI_InOpen(HMIDIIN* lphMidiIn, UINT uDeviceID, DWORD dwCallback,
1345 DWORD dwInstance, DWORD dwFlags, BOOL bFrom32)
1347 HANDLE hMidiIn;
1348 LPWINE_MIDI lpwm;
1349 DWORD dwRet = 0;
1351 TRACE("(%p, %d, %08lX, %08lX, %08lX);\n",
1352 lphMidiIn, uDeviceID, dwCallback, dwInstance, dwFlags);
1354 if (lphMidiIn != NULL) *lphMidiIn = 0;
1356 lpwm = (LPWINE_MIDI)MMDRV_Alloc(sizeof(WINE_MIDI), MMDRV_MIDIIN, &hMidiIn,
1357 &dwFlags, &dwCallback, &dwInstance, bFrom32);
1359 if (lpwm == NULL)
1360 return MMSYSERR_NOMEM;
1362 lpwm->mod.hMidi = (HMIDI) hMidiIn;
1363 lpwm->mod.dwCallback = dwCallback;
1364 lpwm->mod.dwInstance = dwInstance;
1366 lpwm->mld.uDeviceID = uDeviceID;
1367 dwRet = MMDRV_Open(&lpwm->mld, MIDM_OPEN, (DWORD)&lpwm->mod, dwFlags);
1369 if (dwRet != MMSYSERR_NOERROR) {
1370 MMDRV_Free(hMidiIn, &lpwm->mld);
1371 hMidiIn = 0;
1373 if (lphMidiIn != NULL) *lphMidiIn = hMidiIn;
1374 TRACE("=> %ld hMidi=%p\n", dwRet, hMidiIn);
1376 return dwRet;
1379 /**************************************************************************
1380 * midiInOpen [WINMM.@]
1382 UINT WINAPI midiInOpen(HMIDIIN* lphMidiIn, UINT uDeviceID,
1383 DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
1385 return MIDI_InOpen(lphMidiIn, uDeviceID, dwCallback, dwInstance, dwFlags, TRUE);
1388 /**************************************************************************
1389 * midiInClose [WINMM.@]
1391 UINT WINAPI midiInClose(HMIDIIN hMidiIn)
1393 LPWINE_MLD wmld;
1394 DWORD dwRet;
1396 TRACE("(%p)\n", hMidiIn);
1398 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1399 return MMSYSERR_INVALHANDLE;
1401 dwRet = MMDRV_Close(wmld, MIDM_CLOSE);
1402 MMDRV_Free(hMidiIn, wmld);
1403 return dwRet;
1406 /**************************************************************************
1407 * midiInPrepareHeader [WINMM.@]
1409 UINT WINAPI midiInPrepareHeader(HMIDIIN hMidiIn,
1410 MIDIHDR* lpMidiInHdr, UINT uSize)
1412 LPWINE_MLD wmld;
1414 TRACE("(%p, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
1416 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1417 return MMSYSERR_INVALHANDLE;
1419 return MMDRV_Message(wmld, MIDM_PREPARE, (DWORD)lpMidiInHdr, uSize, TRUE);
1422 /**************************************************************************
1423 * midiInUnprepareHeader [WINMM.@]
1425 UINT WINAPI midiInUnprepareHeader(HMIDIIN hMidiIn,
1426 MIDIHDR* lpMidiInHdr, UINT uSize)
1428 LPWINE_MLD wmld;
1430 TRACE("(%p, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
1432 if (!(lpMidiInHdr->dwFlags & MHDR_PREPARED)) {
1433 return MMSYSERR_NOERROR;
1436 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1437 return MMSYSERR_INVALHANDLE;
1439 return MMDRV_Message(wmld, MIDM_UNPREPARE, (DWORD)lpMidiInHdr, uSize, TRUE);
1442 /**************************************************************************
1443 * midiInAddBuffer [WINMM.@]
1445 UINT WINAPI midiInAddBuffer(HMIDIIN hMidiIn,
1446 MIDIHDR* lpMidiInHdr, UINT uSize)
1448 LPWINE_MLD wmld;
1450 TRACE("(%p, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
1452 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1453 return MMSYSERR_INVALHANDLE;
1455 return MMDRV_Message(wmld, MIDM_ADDBUFFER, (DWORD)lpMidiInHdr, uSize, TRUE);
1458 /**************************************************************************
1459 * midiInStart [WINMM.@]
1461 UINT WINAPI midiInStart(HMIDIIN hMidiIn)
1463 LPWINE_MLD wmld;
1465 TRACE("(%p)\n", hMidiIn);
1467 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1468 return MMSYSERR_INVALHANDLE;
1470 return MMDRV_Message(wmld, MIDM_START, 0L, 0L, TRUE);
1473 /**************************************************************************
1474 * midiInStop [WINMM.@]
1476 UINT WINAPI midiInStop(HMIDIIN hMidiIn)
1478 LPWINE_MLD wmld;
1480 TRACE("(%p)\n", hMidiIn);
1482 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1483 return MMSYSERR_INVALHANDLE;
1485 return MMDRV_Message(wmld, MIDM_STOP, 0L, 0L, TRUE);
1488 /**************************************************************************
1489 * midiInReset [WINMM.@]
1491 UINT WINAPI midiInReset(HMIDIIN hMidiIn)
1493 LPWINE_MLD wmld;
1495 TRACE("(%p)\n", hMidiIn);
1497 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1498 return MMSYSERR_INVALHANDLE;
1500 return MMDRV_Message(wmld, MIDM_RESET, 0L, 0L, TRUE);
1503 /**************************************************************************
1504 * midiInGetID [WINMM.@]
1506 UINT WINAPI midiInGetID(HMIDIIN hMidiIn, UINT* lpuDeviceID)
1508 LPWINE_MLD wmld;
1510 TRACE("(%p, %p)\n", hMidiIn, lpuDeviceID);
1512 if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
1514 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, TRUE)) == NULL)
1515 return MMSYSERR_INVALHANDLE;
1517 *lpuDeviceID = wmld->uDeviceID;
1519 return MMSYSERR_NOERROR;
1522 /**************************************************************************
1523 * midiInMessage [WINMM.@]
1525 DWORD WINAPI midiInMessage(HMIDIIN hMidiIn, UINT uMessage,
1526 DWORD dwParam1, DWORD dwParam2)
1528 LPWINE_MLD wmld;
1530 TRACE("(%p, %04X, %08lX, %08lX)\n", hMidiIn, uMessage, dwParam1, dwParam2);
1532 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1533 return MMSYSERR_INVALHANDLE;
1535 switch (uMessage) {
1536 case MIDM_OPEN:
1537 case MIDM_CLOSE:
1538 FIXME("can't handle OPEN or CLOSE message!\n");
1539 return MMSYSERR_NOTSUPPORTED;
1541 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
1544 typedef struct WINE_MIDIStream {
1545 HMIDIOUT hDevice;
1546 HANDLE hThread;
1547 DWORD dwThreadID;
1548 DWORD dwTempo;
1549 DWORD dwTimeDiv;
1550 DWORD dwPositionMS;
1551 DWORD dwPulses;
1552 DWORD dwStartTicks;
1553 WORD wFlags;
1554 HANDLE hEvent;
1555 LPMIDIHDR lpMidiHdr;
1556 } WINE_MIDIStream;
1558 #define WINE_MSM_HEADER (WM_USER+0)
1559 #define WINE_MSM_STOP (WM_USER+1)
1561 /**************************************************************************
1562 * MMSYSTEM_GetMidiStream [internal]
1564 static BOOL MMSYSTEM_GetMidiStream(HMIDISTRM hMidiStrm, WINE_MIDIStream** lpMidiStrm, WINE_MIDI** lplpwm)
1566 WINE_MIDI* lpwm = (LPWINE_MIDI)MMDRV_Get(hMidiStrm, MMDRV_MIDIOUT, FALSE);
1568 if (lplpwm)
1569 *lplpwm = lpwm;
1571 if (lpwm == NULL) {
1572 return FALSE;
1575 *lpMidiStrm = (WINE_MIDIStream*)lpwm->mod.rgIds.dwStreamID;
1577 return *lpMidiStrm != NULL;
1580 /**************************************************************************
1581 * MMSYSTEM_MidiStream_Convert [internal]
1583 static DWORD MMSYSTEM_MidiStream_Convert(WINE_MIDIStream* lpMidiStrm, DWORD pulse)
1585 DWORD ret = 0;
1587 if (lpMidiStrm->dwTimeDiv == 0) {
1588 FIXME("Shouldn't happen. lpMidiStrm->dwTimeDiv = 0\n");
1589 } else if (lpMidiStrm->dwTimeDiv > 0x8000) { /* SMPTE, unchecked FIXME? */
1590 int nf = -(char)HIBYTE(lpMidiStrm->dwTimeDiv); /* number of frames */
1591 int nsf = LOBYTE(lpMidiStrm->dwTimeDiv); /* number of sub-frames */
1592 ret = (pulse * 1000) / (nf * nsf);
1593 } else {
1594 ret = (DWORD)((double)pulse * ((double)lpMidiStrm->dwTempo / 1000) /
1595 (double)lpMidiStrm->dwTimeDiv);
1598 return ret;
1601 /**************************************************************************
1602 * MMSYSTEM_MidiStream_MessageHandler [internal]
1604 static BOOL MMSYSTEM_MidiStream_MessageHandler(WINE_MIDIStream* lpMidiStrm, LPWINE_MIDI lpwm, LPMSG msg)
1606 LPMIDIHDR lpMidiHdr;
1607 LPMIDIHDR* lpmh;
1608 LPBYTE lpData;
1610 switch (msg->message) {
1611 case WM_QUIT:
1612 SetEvent(lpMidiStrm->hEvent);
1613 return FALSE;
1614 case WINE_MSM_STOP:
1615 TRACE("STOP\n");
1616 /* this is not quite what MS doc says... */
1617 midiOutReset(lpMidiStrm->hDevice);
1618 /* empty list of already submitted buffers */
1619 for (lpMidiHdr = lpMidiStrm->lpMidiHdr; lpMidiHdr; lpMidiHdr = (LPMIDIHDR)lpMidiHdr->lpNext) {
1620 lpMidiHdr->dwFlags |= MHDR_DONE;
1621 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
1623 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1624 (HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
1625 lpwm->mod.dwInstance, (DWORD)lpMidiHdr, 0L);
1627 lpMidiStrm->lpMidiHdr = 0;
1628 SetEvent(lpMidiStrm->hEvent);
1629 break;
1630 case WINE_MSM_HEADER:
1631 /* sets initial tick count for first MIDIHDR */
1632 if (!lpMidiStrm->dwStartTicks)
1633 lpMidiStrm->dwStartTicks = GetTickCount();
1635 /* FIXME(EPP): "I don't understand the content of the first MIDIHDR sent
1636 * by native mcimidi, it doesn't look like a correct one".
1637 * this trick allows to throw it away... but I don't like it.
1638 * It looks like part of the file I'm trying to play and definitively looks
1639 * like raw midi content
1640 * I'd really like to understand why native mcimidi sends it. Perhaps a bad
1641 * synchronization issue where native mcimidi is still processing raw MIDI
1642 * content before generating MIDIEVENTs ?
1644 * 4c 04 89 3b 00 81 7c 99 3b 43 00 99 23 5e 04 89 L..;..|.;C..#^..
1645 * 3b 00 00 89 23 00 7c 99 3b 45 00 99 28 62 04 89 ;...#.|.;E..(b..
1646 * 3b 00 00 89 28 00 81 7c 99 3b 4e 00 99 23 5e 04 ;...(..|.;N..#^.
1647 * 89 3b 00 00 89 23 00 7c 99 3b 45 00 99 23 78 04 .;...#.|.;E..#x.
1648 * 89 3b 00 00 89 23 00 81 7c 99 3b 48 00 99 23 5e .;...#..|.;H..#^
1649 * 04 89 3b 00 00 89 23 00 7c 99 3b 4e 00 99 28 62 ..;...#.|.;N..(b
1650 * 04 89 3b 00 00 89 28 00 81 7c 99 39 4c 00 99 23 ..;...(..|.9L..#
1651 * 5e 04 89 39 00 00 89 23 00 82 7c 99 3b 4c 00 99 ^..9...#..|.;L..
1652 * 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 00 99 #^..;...#.|.;H..
1653 * 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b 3f 04 (b..;...(..|.;?.
1654 * 89 3b 00 1c 99 23 5e 04 89 23 00 5c 99 3b 45 00 .;...#^..#.\.;E.
1655 * 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 3b 46 .#x..;...#..|.;F
1656 * 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 ..#^..;...#.|.;H
1657 * 00 99 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b ..(b..;...(..|.;
1658 * 46 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b F..#^..;...#.|.;
1659 * 48 00 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 H..#x..;...#..|.
1660 * 3b 4c 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 ;L..#^..;...#.|.
1662 lpMidiHdr = (LPMIDIHDR)msg->lParam;
1663 lpData = lpMidiHdr->lpData;
1664 TRACE("Adding %s lpMidiHdr=%p [lpData=0x%08lx dwBufferLength=%lu/%lu dwFlags=0x%08lx size=%u]\n",
1665 (lpMidiHdr->dwFlags & MHDR_ISSTRM) ? "stream" : "regular", lpMidiHdr,
1666 (DWORD)lpMidiHdr, lpMidiHdr->dwBufferLength, lpMidiHdr->dwBytesRecorded,
1667 lpMidiHdr->dwFlags, msg->wParam);
1668 #if 0
1669 /* dumps content of lpMidiHdr->lpData
1670 * FIXME: there should be a debug routine somewhere that already does this
1671 * I hate spreading this type of shit all around the code
1673 for (dwToGo = 0; dwToGo < lpMidiHdr->dwBufferLength; dwToGo += 16) {
1674 DWORD i;
1675 BYTE ch;
1677 for (i = 0; i < min(16, lpMidiHdr->dwBufferLength - dwToGo); i++)
1678 printf("%02x ", lpData[dwToGo + i]);
1679 for (; i < 16; i++)
1680 printf(" ");
1681 for (i = 0; i < min(16, lpMidiHdr->dwBufferLength - dwToGo); i++) {
1682 ch = lpData[dwToGo + i];
1683 printf("%c", (ch >= 0x20 && ch <= 0x7F) ? ch : '.');
1685 printf("\n");
1687 #endif
1688 if (((LPMIDIEVENT)lpData)->dwStreamID != 0 &&
1689 ((LPMIDIEVENT)lpData)->dwStreamID != 0xFFFFFFFF &&
1690 ((LPMIDIEVENT)lpData)->dwStreamID != (DWORD)lpMidiStrm) {
1691 FIXME("Dropping bad %s lpMidiHdr (streamID=%08lx)\n",
1692 (lpMidiHdr->dwFlags & MHDR_ISSTRM) ? "stream" : "regular",
1693 ((LPMIDIEVENT)lpData)->dwStreamID);
1694 lpMidiHdr->dwFlags |= MHDR_DONE;
1695 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
1697 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1698 (HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
1699 lpwm->mod.dwInstance, (DWORD)lpMidiHdr, 0L);
1700 break;
1703 for (lpmh = &lpMidiStrm->lpMidiHdr; *lpmh; lpmh = (LPMIDIHDR*)&((*lpmh)->lpNext));
1704 *lpmh = lpMidiHdr;
1705 lpMidiHdr = (LPMIDIHDR)msg->lParam;
1706 lpMidiHdr->lpNext = 0;
1707 lpMidiHdr->dwFlags |= MHDR_INQUEUE;
1708 lpMidiHdr->dwFlags &= MHDR_DONE;
1709 lpMidiHdr->dwOffset = 0;
1711 break;
1712 default:
1713 FIXME("Unknown message %d\n", msg->message);
1714 break;
1716 return TRUE;
1719 /**************************************************************************
1720 * MMSYSTEM_MidiStream_Player [internal]
1722 static DWORD CALLBACK MMSYSTEM_MidiStream_Player(LPVOID pmt)
1724 WINE_MIDIStream* lpMidiStrm = pmt;
1725 WINE_MIDI* lpwm;
1726 MSG msg;
1727 DWORD dwToGo;
1728 DWORD dwCurrTC;
1729 LPMIDIHDR lpMidiHdr;
1730 LPMIDIEVENT me;
1731 LPBYTE lpData = 0;
1733 TRACE("(%p)!\n", lpMidiStrm);
1735 if (!lpMidiStrm ||
1736 (lpwm = (LPWINE_MIDI)MMDRV_Get(lpMidiStrm->hDevice, MMDRV_MIDIOUT, FALSE)) == NULL)
1737 goto the_end;
1739 /* force thread's queue creation */
1740 /* Used to be InitThreadInput16(0, 5); */
1741 /* but following works also with hack in midiStreamOpen */
1742 PeekMessageA(&msg, 0, 0, 0, 0);
1744 /* FIXME: this next line must be called before midiStreamOut or midiStreamRestart are called */
1745 SetEvent(lpMidiStrm->hEvent);
1746 TRACE("Ready to go 1\n");
1747 /* thread is started in paused mode */
1748 SuspendThread(lpMidiStrm->hThread);
1749 TRACE("Ready to go 2\n");
1751 lpMidiStrm->dwStartTicks = 0;
1752 lpMidiStrm->dwPulses = 0;
1754 lpMidiStrm->lpMidiHdr = 0;
1756 for (;;) {
1757 lpMidiHdr = lpMidiStrm->lpMidiHdr;
1758 if (!lpMidiHdr) {
1759 /* for first message, block until one arrives, then process all that are available */
1760 GetMessageA(&msg, 0, 0, 0);
1761 do {
1762 if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm, lpwm, &msg))
1763 goto the_end;
1764 } while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE));
1765 lpData = 0;
1766 continue;
1769 if (!lpData)
1770 lpData = lpMidiHdr->lpData;
1772 me = (LPMIDIEVENT)(lpData + lpMidiHdr->dwOffset);
1774 /* do we have to wait ? */
1775 if (me->dwDeltaTime) {
1776 lpMidiStrm->dwPositionMS += MMSYSTEM_MidiStream_Convert(lpMidiStrm, me->dwDeltaTime);
1777 lpMidiStrm->dwPulses += me->dwDeltaTime;
1779 dwToGo = lpMidiStrm->dwStartTicks + lpMidiStrm->dwPositionMS;
1781 TRACE("%ld/%ld/%ld\n", dwToGo, GetTickCount(), me->dwDeltaTime);
1782 while ((dwCurrTC = GetTickCount()) < dwToGo) {
1783 if (MsgWaitForMultipleObjects(0, NULL, FALSE, dwToGo - dwCurrTC, QS_ALLINPUT) == WAIT_OBJECT_0) {
1784 /* got a message, handle it */
1785 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) {
1786 if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm, lpwm, &msg))
1787 goto the_end;
1789 lpData = 0;
1790 } else {
1791 /* timeout, so me->dwDeltaTime is elapsed, can break the while loop */
1792 break;
1796 switch (MEVT_EVENTTYPE(me->dwEvent & ~MEVT_F_CALLBACK)) {
1797 case MEVT_COMMENT:
1798 FIXME("NIY: MEVT_COMMENT\n");
1799 /* do nothing, skip bytes */
1800 break;
1801 case MEVT_LONGMSG:
1802 FIXME("NIY: MEVT_LONGMSG, aka sending Sysex event\n");
1803 break;
1804 case MEVT_NOP:
1805 break;
1806 case MEVT_SHORTMSG:
1807 midiOutShortMsg(lpMidiStrm->hDevice, MEVT_EVENTPARM(me->dwEvent));
1808 break;
1809 case MEVT_TEMPO:
1810 lpMidiStrm->dwTempo = MEVT_EVENTPARM(me->dwEvent);
1811 break;
1812 case MEVT_VERSION:
1813 break;
1814 default:
1815 FIXME("Unknown MEVT (0x%02x)\n", MEVT_EVENTTYPE(me->dwEvent & ~MEVT_F_CALLBACK));
1816 break;
1818 if (me->dwEvent & MEVT_F_CALLBACK) {
1819 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1820 (HDRVR)lpMidiStrm->hDevice, MM_MOM_POSITIONCB,
1821 lpwm->mod.dwInstance, (LPARAM)lpMidiHdr, 0L);
1823 lpMidiHdr->dwOffset += sizeof(MIDIEVENT) - sizeof(me->dwParms);
1824 if (me->dwEvent & MEVT_F_LONG)
1825 lpMidiHdr->dwOffset += (MEVT_EVENTPARM(me->dwEvent) + 3) & ~3;
1826 if (lpMidiHdr->dwOffset >= lpMidiHdr->dwBufferLength) {
1827 /* done with this header */
1828 lpMidiHdr->dwFlags |= MHDR_DONE;
1829 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
1831 lpMidiStrm->lpMidiHdr = (LPMIDIHDR)lpMidiHdr->lpNext;
1832 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1833 (HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
1834 lpwm->mod.dwInstance, (DWORD)lpMidiHdr, 0L);
1835 lpData = 0;
1838 the_end:
1839 TRACE("End of thread\n");
1840 ExitThread(0);
1841 return 0; /* for removing the warning, never executed */
1844 /**************************************************************************
1845 * MMSYSTEM_MidiStream_PostMessage [internal]
1847 static BOOL MMSYSTEM_MidiStream_PostMessage(WINE_MIDIStream* lpMidiStrm, WORD msg, DWORD pmt1, DWORD pmt2)
1849 if (PostThreadMessageA(lpMidiStrm->dwThreadID, msg, pmt1, pmt2)) {
1850 DWORD count;
1852 ReleaseThunkLock(&count);
1853 WaitForSingleObject(lpMidiStrm->hEvent, INFINITE);
1854 RestoreThunkLock(count);
1855 } else {
1856 WARN("bad PostThreadMessageA\n");
1857 return FALSE;
1859 return TRUE;
1862 /**************************************************************************
1863 * midiStreamClose [WINMM.@]
1865 MMRESULT WINAPI midiStreamClose(HMIDISTRM hMidiStrm)
1867 WINE_MIDIStream* lpMidiStrm;
1869 TRACE("(%p)!\n", hMidiStrm);
1871 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL))
1872 return MMSYSERR_INVALHANDLE;
1874 midiStreamStop(hMidiStrm);
1875 MMSYSTEM_MidiStream_PostMessage(lpMidiStrm, WM_QUIT, 0, 0);
1876 HeapFree(GetProcessHeap(), 0, lpMidiStrm);
1877 CloseHandle(lpMidiStrm->hEvent);
1879 return midiOutClose((HMIDIOUT)hMidiStrm);
1882 /**************************************************************************
1883 * MMSYSTEM_MidiStream_Open [internal]
1885 MMRESULT MIDI_StreamOpen(HMIDISTRM* lphMidiStrm, LPUINT lpuDeviceID, DWORD cMidi,
1886 DWORD dwCallback, DWORD dwInstance, DWORD fdwOpen,
1887 BOOL bFrom32)
1889 WINE_MIDIStream* lpMidiStrm;
1890 MMRESULT ret;
1891 MIDIOPENSTRMID mosm;
1892 LPWINE_MIDI lpwm;
1893 HMIDIOUT hMidiOut;
1895 TRACE("(%p, %p, %ld, 0x%08lx, 0x%08lx, 0x%08lx)!\n",
1896 lphMidiStrm, lpuDeviceID, cMidi, dwCallback, dwInstance, fdwOpen);
1898 if (cMidi != 1 || lphMidiStrm == NULL || lpuDeviceID == NULL)
1899 return MMSYSERR_INVALPARAM;
1901 lpMidiStrm = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_MIDIStream));
1902 if (!lpMidiStrm)
1903 return MMSYSERR_NOMEM;
1905 lpMidiStrm->dwTempo = 500000;
1906 lpMidiStrm->dwTimeDiv = 480; /* 480 is 120 quater notes per minute *//* FIXME ??*/
1907 lpMidiStrm->dwPositionMS = 0;
1909 mosm.dwStreamID = (DWORD)lpMidiStrm;
1910 /* FIXME: the correct value is not allocated yet for MAPPER */
1911 mosm.wDeviceID = *lpuDeviceID;
1912 lpwm = MIDI_OutAlloc(&hMidiOut, &dwCallback, &dwInstance, &fdwOpen, 1, &mosm, bFrom32);
1913 lpMidiStrm->hDevice = hMidiOut;
1914 if (lphMidiStrm)
1915 *lphMidiStrm = (HMIDISTRM)hMidiOut;
1917 /* FIXME: is lpuDevice initialized upon entering midiStreamOpen ? */
1918 FIXME("*lpuDeviceID=%x\n", *lpuDeviceID);
1919 lpwm->mld.uDeviceID = *lpuDeviceID = 0;
1921 ret = MMDRV_Open(&lpwm->mld, MODM_OPEN, (DWORD)&lpwm->mod, fdwOpen);
1922 lpMidiStrm->hEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
1923 lpMidiStrm->wFlags = HIWORD(fdwOpen);
1925 lpMidiStrm->hThread = CreateThread(NULL, 0, MMSYSTEM_MidiStream_Player,
1926 lpMidiStrm, 0, &(lpMidiStrm->dwThreadID));
1928 if (!lpMidiStrm->hThread) {
1929 midiStreamClose((HMIDISTRM)hMidiOut);
1930 return MMSYSERR_NOMEM;
1933 /* wait for thread to have started, and for its queue to be created */
1935 DWORD count;
1937 /* (Release|Restore)ThunkLock() is needed when this method is called from 16 bit code,
1938 * (meaning the Win16Lock is set), so that it's released and the 32 bit thread running
1939 * MMSYSTEM_MidiStreamPlayer can acquire Win16Lock to create its queue.
1941 ReleaseThunkLock(&count);
1942 WaitForSingleObject(lpMidiStrm->hEvent, INFINITE);
1943 RestoreThunkLock(count);
1946 TRACE("=> (%u/%d) hMidi=%p ret=%d lpMidiStrm=%p\n",
1947 *lpuDeviceID, lpwm->mld.uDeviceID, *lphMidiStrm, ret, lpMidiStrm);
1948 return ret;
1951 /**************************************************************************
1952 * midiStreamOpen [WINMM.@]
1954 MMRESULT WINAPI midiStreamOpen(HMIDISTRM* lphMidiStrm, LPUINT lpuDeviceID,
1955 DWORD cMidi, DWORD dwCallback,
1956 DWORD dwInstance, DWORD fdwOpen)
1958 return MIDI_StreamOpen(lphMidiStrm, lpuDeviceID, cMidi, dwCallback,
1959 dwInstance, fdwOpen, TRUE);
1962 /**************************************************************************
1963 * midiStreamOut [WINMM.@]
1965 MMRESULT WINAPI midiStreamOut(HMIDISTRM hMidiStrm, LPMIDIHDR lpMidiHdr,
1966 UINT cbMidiHdr)
1968 WINE_MIDIStream* lpMidiStrm;
1969 DWORD ret = MMSYSERR_NOERROR;
1971 TRACE("(%p, %p, %u)!\n", hMidiStrm, lpMidiHdr, cbMidiHdr);
1973 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1974 ret = MMSYSERR_INVALHANDLE;
1975 } else if (!lpMidiHdr) {
1976 ret = MMSYSERR_INVALPARAM;
1977 } else {
1978 if (!PostThreadMessageA(lpMidiStrm->dwThreadID,
1979 WINE_MSM_HEADER, cbMidiHdr,
1980 (DWORD)lpMidiHdr)) {
1981 WARN("bad PostThreadMessageA\n");
1982 ret = MMSYSERR_ERROR;
1985 return ret;
1988 /**************************************************************************
1989 * midiStreamPause [WINMM.@]
1991 MMRESULT WINAPI midiStreamPause(HMIDISTRM hMidiStrm)
1993 WINE_MIDIStream* lpMidiStrm;
1994 DWORD ret = MMSYSERR_NOERROR;
1996 TRACE("(%p)!\n", hMidiStrm);
1998 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1999 ret = MMSYSERR_INVALHANDLE;
2000 } else {
2001 if (SuspendThread(lpMidiStrm->hThread) == 0xFFFFFFFF) {
2002 WARN("bad Suspend (%ld)\n", GetLastError());
2003 ret = MMSYSERR_ERROR;
2006 return ret;
2009 /**************************************************************************
2010 * midiStreamPosition [WINMM.@]
2012 MMRESULT WINAPI midiStreamPosition(HMIDISTRM hMidiStrm, LPMMTIME lpMMT, UINT cbmmt)
2014 WINE_MIDIStream* lpMidiStrm;
2015 DWORD ret = MMSYSERR_NOERROR;
2017 TRACE("(%p, %p, %u)!\n", hMidiStrm, lpMMT, cbmmt);
2019 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
2020 ret = MMSYSERR_INVALHANDLE;
2021 } else if (lpMMT == NULL || cbmmt != sizeof(MMTIME)) {
2022 ret = MMSYSERR_INVALPARAM;
2023 } else {
2024 switch (lpMMT->wType) {
2025 case TIME_MS:
2026 lpMMT->u.ms = lpMidiStrm->dwPositionMS;
2027 TRACE("=> %ld ms\n", lpMMT->u.ms);
2028 break;
2029 case TIME_TICKS:
2030 lpMMT->u.ticks = lpMidiStrm->dwPulses;
2031 TRACE("=> %ld ticks\n", lpMMT->u.ticks);
2032 break;
2033 default:
2034 WARN("Unsupported time type %d\n", lpMMT->wType);
2035 lpMMT->wType = TIME_MS;
2036 ret = MMSYSERR_INVALPARAM;
2037 break;
2040 return ret;
2043 /**************************************************************************
2044 * midiStreamProperty [WINMM.@]
2046 MMRESULT WINAPI midiStreamProperty(HMIDISTRM hMidiStrm, LPBYTE lpPropData, DWORD dwProperty)
2048 WINE_MIDIStream* lpMidiStrm;
2049 MMRESULT ret = MMSYSERR_NOERROR;
2051 TRACE("(%p, %p, %lx)\n", hMidiStrm, lpPropData, dwProperty);
2053 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
2054 ret = MMSYSERR_INVALHANDLE;
2055 } else if ((dwProperty & (MIDIPROP_GET|MIDIPROP_SET)) == 0) {
2056 ret = MMSYSERR_INVALPARAM;
2057 } else if (dwProperty & MIDIPROP_TEMPO) {
2058 MIDIPROPTEMPO* mpt = (MIDIPROPTEMPO*)lpPropData;
2060 if (sizeof(MIDIPROPTEMPO) != mpt->cbStruct) {
2061 ret = MMSYSERR_INVALPARAM;
2062 } else if (dwProperty & MIDIPROP_SET) {
2063 lpMidiStrm->dwTempo = mpt->dwTempo;
2064 TRACE("Setting tempo to %ld\n", mpt->dwTempo);
2065 } else if (dwProperty & MIDIPROP_GET) {
2066 mpt->dwTempo = lpMidiStrm->dwTempo;
2067 TRACE("Getting tempo <= %ld\n", mpt->dwTempo);
2069 } else if (dwProperty & MIDIPROP_TIMEDIV) {
2070 MIDIPROPTIMEDIV* mptd = (MIDIPROPTIMEDIV*)lpPropData;
2072 if (sizeof(MIDIPROPTIMEDIV) != mptd->cbStruct) {
2073 ret = MMSYSERR_INVALPARAM;
2074 } else if (dwProperty & MIDIPROP_SET) {
2075 lpMidiStrm->dwTimeDiv = mptd->dwTimeDiv;
2076 TRACE("Setting time div to %ld\n", mptd->dwTimeDiv);
2077 } else if (dwProperty & MIDIPROP_GET) {
2078 mptd->dwTimeDiv = lpMidiStrm->dwTimeDiv;
2079 TRACE("Getting time div <= %ld\n", mptd->dwTimeDiv);
2081 } else {
2082 ret = MMSYSERR_INVALPARAM;
2085 return ret;
2088 /**************************************************************************
2089 * midiStreamRestart [WINMM.@]
2091 MMRESULT WINAPI midiStreamRestart(HMIDISTRM hMidiStrm)
2093 WINE_MIDIStream* lpMidiStrm;
2094 MMRESULT ret = MMSYSERR_NOERROR;
2096 TRACE("(%p)!\n", hMidiStrm);
2098 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
2099 ret = MMSYSERR_INVALHANDLE;
2100 } else {
2101 DWORD ret;
2103 /* since we increase the thread suspend count on each midiStreamPause
2104 * there may be a need for several midiStreamResume
2106 do {
2107 ret = ResumeThread(lpMidiStrm->hThread);
2108 } while (ret != 0xFFFFFFFF && ret != 0);
2109 if (ret == 0xFFFFFFFF) {
2110 WARN("bad Resume (%ld)\n", GetLastError());
2111 ret = MMSYSERR_ERROR;
2112 } else {
2113 lpMidiStrm->dwStartTicks = GetTickCount() - lpMidiStrm->dwPositionMS;
2116 return ret;
2119 /**************************************************************************
2120 * midiStreamStop [WINMM.@]
2122 MMRESULT WINAPI midiStreamStop(HMIDISTRM hMidiStrm)
2124 WINE_MIDIStream* lpMidiStrm;
2125 MMRESULT ret = MMSYSERR_NOERROR;
2127 TRACE("(%p)!\n", hMidiStrm);
2129 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
2130 ret = MMSYSERR_INVALHANDLE;
2131 } else {
2132 /* in case stream has been paused... FIXME is the current state correct ? */
2133 midiStreamRestart(hMidiStrm);
2134 MMSYSTEM_MidiStream_PostMessage(lpMidiStrm, WINE_MSM_STOP, 0, 0);
2136 return ret;
2139 UINT WAVE_Open(HANDLE* lphndl, UINT uDeviceID, UINT uType,
2140 const LPWAVEFORMATEX lpFormat, DWORD dwCallback,
2141 DWORD dwInstance, DWORD dwFlags, BOOL bFrom32)
2143 HANDLE handle;
2144 LPWINE_MLD wmld;
2145 DWORD dwRet = MMSYSERR_NOERROR;
2146 WAVEOPENDESC wod;
2148 TRACE("(%p, %d, %s, %p, %08lX, %08lX, %08lX, %d);\n",
2149 lphndl, (int)uDeviceID, (uType==MMDRV_WAVEOUT)?"Out":"In", lpFormat, dwCallback,
2150 dwInstance, dwFlags, bFrom32?32:16);
2152 if (dwFlags & WAVE_FORMAT_QUERY) TRACE("WAVE_FORMAT_QUERY requested !\n");
2154 if (lpFormat == NULL) return WAVERR_BADFORMAT;
2155 if ((dwFlags & WAVE_MAPPED) && (uDeviceID == (UINT)-1))
2156 return MMSYSERR_INVALPARAM;
2158 TRACE("wFormatTag=%u, nChannels=%u, nSamplesPerSec=%lu, nAvgBytesPerSec=%lu, nBlockAlign=%u, wBitsPerSample=%u, cbSize=%u\n",
2159 lpFormat->wFormatTag, lpFormat->nChannels, lpFormat->nSamplesPerSec,
2160 lpFormat->nAvgBytesPerSec, lpFormat->nBlockAlign, lpFormat->wBitsPerSample, lpFormat->cbSize);
2162 if ((wmld = MMDRV_Alloc(sizeof(WINE_WAVE), uType, &handle,
2163 &dwFlags, &dwCallback, &dwInstance, bFrom32)) == NULL)
2164 return MMSYSERR_NOMEM;
2166 wod.hWave = handle;
2167 wod.lpFormat = lpFormat; /* should the struct be copied iso pointer? */
2168 wod.dwCallback = dwCallback;
2169 wod.dwInstance = dwInstance;
2170 wod.dnDevNode = 0L;
2172 TRACE("cb=%08lx\n", wod.dwCallback);
2174 for (;;) {
2175 if (dwFlags & WAVE_MAPPED) {
2176 wod.uMappedDeviceID = uDeviceID;
2177 uDeviceID = WAVE_MAPPER;
2178 } else {
2179 wod.uMappedDeviceID = -1;
2181 wmld->uDeviceID = uDeviceID;
2183 dwRet = MMDRV_Open(wmld, (uType == MMDRV_WAVEOUT) ? WODM_OPEN : WIDM_OPEN,
2184 (DWORD)&wod, dwFlags);
2186 if (dwRet != WAVERR_BADFORMAT ||
2187 (dwFlags & (WAVE_MAPPED|WAVE_FORMAT_DIRECT)) != 0) break;
2188 /* if we ask for a format which isn't supported by the physical driver,
2189 * let's try to map it through the wave mapper (except, if we already tried
2190 * or user didn't allow us to use acm codecs)
2192 dwFlags |= WAVE_MAPPED;
2193 /* we shall loop only one */
2196 if ((dwFlags & WAVE_FORMAT_QUERY) || dwRet != MMSYSERR_NOERROR) {
2197 MMDRV_Free(handle, wmld);
2198 handle = 0;
2201 if (lphndl != NULL) *lphndl = handle;
2202 TRACE("=> %ld hWave=%p\n", dwRet, handle);
2204 return dwRet;
2207 /**************************************************************************
2208 * waveOutGetNumDevs [WINMM.@]
2210 UINT WINAPI waveOutGetNumDevs(void)
2212 return MMDRV_GetNum(MMDRV_WAVEOUT);
2215 /**************************************************************************
2216 * waveOutGetDevCapsA [WINMM.@]
2218 UINT WINAPI waveOutGetDevCapsA(UINT uDeviceID, LPWAVEOUTCAPSA lpCaps,
2219 UINT uSize)
2221 LPWINE_MLD wmld;
2223 TRACE("(%u %p %u)!\n", uDeviceID, lpCaps, uSize);
2225 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2227 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_WAVEOUT, TRUE)) == NULL)
2228 return MMSYSERR_BADDEVICEID;
2230 return MMDRV_Message(wmld, WODM_GETDEVCAPS, (DWORD)lpCaps, uSize, TRUE);
2234 /**************************************************************************
2235 * waveOutGetDevCapsW [WINMM.@]
2237 UINT WINAPI waveOutGetDevCapsW(UINT uDeviceID, LPWAVEOUTCAPSW lpCaps,
2238 UINT uSize)
2240 WAVEOUTCAPSA wocA;
2241 UINT ret;
2243 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2245 ret = waveOutGetDevCapsA(uDeviceID, &wocA, sizeof(wocA));
2247 if (ret == MMSYSERR_NOERROR) {
2248 lpCaps->wMid = wocA.wMid;
2249 lpCaps->wPid = wocA.wPid;
2250 lpCaps->vDriverVersion = wocA.vDriverVersion;
2251 MultiByteToWideChar( CP_ACP, 0, wocA.szPname, -1, lpCaps->szPname,
2252 sizeof(lpCaps->szPname)/sizeof(WCHAR) );
2253 lpCaps->dwFormats = wocA.dwFormats;
2254 lpCaps->wChannels = wocA.wChannels;
2255 lpCaps->dwSupport = wocA.dwSupport;
2257 return ret;
2260 /**************************************************************************
2261 * WAVE_GetErrorText [internal]
2263 static UINT16 WAVE_GetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize)
2265 UINT16 ret = MMSYSERR_BADERRNUM;
2267 if (lpText == NULL) {
2268 ret = MMSYSERR_INVALPARAM;
2269 } else if (uSize == 0) {
2270 ret = MMSYSERR_NOERROR;
2271 } else if (
2272 /* test has been removed 'coz MMSYSERR_BASE is 0, and gcc did emit
2273 * a warning for the test was always true */
2274 (/*uError >= MMSYSERR_BASE && */uError <= MMSYSERR_LASTERROR) ||
2275 (uError >= WAVERR_BASE && uError <= WAVERR_LASTERROR)) {
2277 if (LoadStringA(WINMM_IData->hWinMM32Instance,
2278 uError, lpText, uSize) > 0) {
2279 ret = MMSYSERR_NOERROR;
2282 return ret;
2285 /**************************************************************************
2286 * waveOutGetErrorTextA [WINMM.@]
2288 UINT WINAPI waveOutGetErrorTextA(UINT uError, LPSTR lpText, UINT uSize)
2290 return WAVE_GetErrorText(uError, lpText, uSize);
2293 /**************************************************************************
2294 * waveOutGetErrorTextW [WINMM.@]
2296 UINT WINAPI waveOutGetErrorTextW(UINT uError, LPWSTR lpText, UINT uSize)
2298 LPSTR xstr = HeapAlloc(GetProcessHeap(), 0, uSize);
2299 UINT ret = WAVE_GetErrorText(uError, xstr, uSize);
2301 MultiByteToWideChar( CP_ACP, 0, xstr, -1, lpText, uSize );
2302 HeapFree(GetProcessHeap(), 0, xstr);
2303 return ret;
2306 /**************************************************************************
2307 * waveOutOpen [WINMM.@]
2308 * All the args/structs have the same layout as the win16 equivalents
2310 UINT WINAPI waveOutOpen(HWAVEOUT* lphWaveOut, UINT uDeviceID,
2311 const LPWAVEFORMATEX lpFormat, DWORD dwCallback,
2312 DWORD dwInstance, DWORD dwFlags)
2314 return WAVE_Open((HANDLE*)lphWaveOut, uDeviceID, MMDRV_WAVEOUT, lpFormat,
2315 dwCallback, dwInstance, dwFlags, TRUE);
2318 /**************************************************************************
2319 * waveOutClose [WINMM.@]
2321 UINT WINAPI waveOutClose(HWAVEOUT hWaveOut)
2323 LPWINE_MLD wmld;
2324 DWORD dwRet;
2326 TRACE("(%p)\n", hWaveOut);
2328 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2329 return MMSYSERR_INVALHANDLE;
2331 dwRet = MMDRV_Close(wmld, WODM_CLOSE);
2332 MMDRV_Free(hWaveOut, wmld);
2334 return dwRet;
2337 /**************************************************************************
2338 * waveOutPrepareHeader [WINMM.@]
2340 UINT WINAPI waveOutPrepareHeader(HWAVEOUT hWaveOut,
2341 WAVEHDR* lpWaveOutHdr, UINT uSize)
2343 LPWINE_MLD wmld;
2345 TRACE("(%p, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
2347 if (lpWaveOutHdr == NULL) return MMSYSERR_INVALPARAM;
2349 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2350 return MMSYSERR_INVALHANDLE;
2352 return MMDRV_Message(wmld, WODM_PREPARE, (DWORD)lpWaveOutHdr, uSize, TRUE);
2355 /**************************************************************************
2356 * waveOutUnprepareHeader [WINMM.@]
2358 UINT WINAPI waveOutUnprepareHeader(HWAVEOUT hWaveOut,
2359 LPWAVEHDR lpWaveOutHdr, UINT uSize)
2361 LPWINE_MLD wmld;
2363 TRACE("(%p, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
2365 if (!(lpWaveOutHdr->dwFlags & WHDR_PREPARED)) {
2366 return MMSYSERR_NOERROR;
2369 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2370 return MMSYSERR_INVALHANDLE;
2372 return MMDRV_Message(wmld, WODM_UNPREPARE, (DWORD)lpWaveOutHdr, uSize, TRUE);
2375 /**************************************************************************
2376 * waveOutWrite [WINMM.@]
2378 UINT WINAPI waveOutWrite(HWAVEOUT hWaveOut, LPWAVEHDR lpWaveOutHdr,
2379 UINT uSize)
2381 LPWINE_MLD wmld;
2383 TRACE("(%p, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
2385 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2386 return MMSYSERR_INVALHANDLE;
2388 return MMDRV_Message(wmld, WODM_WRITE, (DWORD)lpWaveOutHdr, uSize, TRUE);
2391 /**************************************************************************
2392 * waveOutBreakLoop [WINMM.@]
2394 UINT WINAPI waveOutBreakLoop(HWAVEOUT hWaveOut)
2396 LPWINE_MLD wmld;
2398 TRACE("(%p);\n", hWaveOut);
2400 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2401 return MMSYSERR_INVALHANDLE;
2402 return MMDRV_Message(wmld, WODM_BREAKLOOP, 0L, 0L, TRUE);
2405 /**************************************************************************
2406 * waveOutPause [WINMM.@]
2408 UINT WINAPI waveOutPause(HWAVEOUT hWaveOut)
2410 LPWINE_MLD wmld;
2412 TRACE("(%p);\n", hWaveOut);
2414 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2415 return MMSYSERR_INVALHANDLE;
2416 return MMDRV_Message(wmld, WODM_PAUSE, 0L, 0L, TRUE);
2419 /**************************************************************************
2420 * waveOutReset [WINMM.@]
2422 UINT WINAPI waveOutReset(HWAVEOUT hWaveOut)
2424 LPWINE_MLD wmld;
2426 TRACE("(%p);\n", hWaveOut);
2428 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2429 return MMSYSERR_INVALHANDLE;
2430 return MMDRV_Message(wmld, WODM_RESET, 0L, 0L, TRUE);
2433 /**************************************************************************
2434 * waveOutRestart [WINMM.@]
2436 UINT WINAPI waveOutRestart(HWAVEOUT hWaveOut)
2438 LPWINE_MLD wmld;
2440 TRACE("(%p);\n", hWaveOut);
2442 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2443 return MMSYSERR_INVALHANDLE;
2444 return MMDRV_Message(wmld, WODM_RESTART, 0L, 0L, TRUE);
2447 /**************************************************************************
2448 * waveOutGetPosition [WINMM.@]
2450 UINT WINAPI waveOutGetPosition(HWAVEOUT hWaveOut, LPMMTIME lpTime,
2451 UINT uSize)
2453 LPWINE_MLD wmld;
2455 TRACE("(%p, %p, %u);\n", hWaveOut, lpTime, uSize);
2457 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2458 return MMSYSERR_INVALHANDLE;
2460 return MMDRV_Message(wmld, WODM_GETPOS, (DWORD)lpTime, uSize, TRUE);
2463 /**************************************************************************
2464 * waveOutGetPitch [WINMM.@]
2466 UINT WINAPI waveOutGetPitch(HWAVEOUT hWaveOut, LPDWORD lpdw)
2468 LPWINE_MLD wmld;
2470 TRACE("(%p, %08lx);\n", hWaveOut, (DWORD)lpdw);
2472 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2473 return MMSYSERR_INVALHANDLE;
2474 return MMDRV_Message(wmld, WODM_GETPITCH, (DWORD)lpdw, 0L, TRUE);
2477 /**************************************************************************
2478 * waveOutSetPitch [WINMM.@]
2480 UINT WINAPI waveOutSetPitch(HWAVEOUT hWaveOut, DWORD dw)
2482 LPWINE_MLD wmld;
2484 TRACE("(%p, %08lx);\n", hWaveOut, (DWORD)dw);
2486 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2487 return MMSYSERR_INVALHANDLE;
2488 return MMDRV_Message(wmld, WODM_SETPITCH, dw, 0L, TRUE);
2491 /**************************************************************************
2492 * waveOutGetPlaybackRate [WINMM.@]
2494 UINT WINAPI waveOutGetPlaybackRate(HWAVEOUT hWaveOut, LPDWORD lpdw)
2496 LPWINE_MLD wmld;
2498 TRACE("(%p, %08lx);\n", hWaveOut, (DWORD)lpdw);
2500 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2501 return MMSYSERR_INVALHANDLE;
2502 return MMDRV_Message(wmld, WODM_GETPLAYBACKRATE, (DWORD)lpdw, 0L, TRUE);
2505 /**************************************************************************
2506 * waveOutSetPlaybackRate [WINMM.@]
2508 UINT WINAPI waveOutSetPlaybackRate(HWAVEOUT hWaveOut, DWORD dw)
2510 LPWINE_MLD wmld;
2512 TRACE("(%p, %08lx);\n", hWaveOut, (DWORD)dw);
2514 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2515 return MMSYSERR_INVALHANDLE;
2516 return MMDRV_Message(wmld, WODM_SETPLAYBACKRATE, dw, 0L, TRUE);
2519 /**************************************************************************
2520 * waveOutGetVolume [WINMM.@]
2522 UINT WINAPI waveOutGetVolume(UINT devid, LPDWORD lpdw)
2524 LPWINE_MLD wmld;
2526 TRACE("(%04X, %08lx);\n", devid, (DWORD)lpdw);
2528 if ((wmld = MMDRV_Get((HANDLE)devid, MMDRV_WAVEOUT, TRUE)) == NULL)
2529 return MMSYSERR_INVALHANDLE;
2531 return MMDRV_Message(wmld, WODM_GETVOLUME, (DWORD)lpdw, 0L, TRUE);
2534 /**************************************************************************
2535 * waveOutSetVolume [WINMM.@]
2537 UINT WINAPI waveOutSetVolume(UINT devid, DWORD dw)
2539 LPWINE_MLD wmld;
2541 TRACE("(%04X, %08lx);\n", devid, dw);
2543 if ((wmld = MMDRV_Get((HANDLE)devid, MMDRV_WAVEOUT, TRUE)) == NULL)
2544 return MMSYSERR_INVALHANDLE;
2546 return MMDRV_Message(wmld, WODM_SETVOLUME, dw, 0L, TRUE);
2549 /**************************************************************************
2550 * waveOutGetID [WINMM.@]
2552 UINT WINAPI waveOutGetID(HWAVEOUT hWaveOut, UINT* lpuDeviceID)
2554 LPWINE_MLD wmld;
2556 TRACE("(%p, %p);\n", hWaveOut, lpuDeviceID);
2558 if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
2560 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2561 return MMSYSERR_INVALHANDLE;
2563 *lpuDeviceID = wmld->uDeviceID;
2564 return 0;
2567 /**************************************************************************
2568 * waveOutMessage [WINMM.@]
2570 DWORD WINAPI waveOutMessage(HWAVEOUT hWaveOut, UINT uMessage,
2571 DWORD dwParam1, DWORD dwParam2)
2573 LPWINE_MLD wmld;
2575 TRACE("(%p, %u, %ld, %ld)\n", hWaveOut, uMessage, dwParam1, dwParam2);
2577 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL) {
2578 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, TRUE)) != NULL) {
2579 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
2581 return MMSYSERR_INVALHANDLE;
2584 /* from M$ KB */
2585 if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER))
2586 return MMSYSERR_INVALPARAM;
2588 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
2591 /**************************************************************************
2592 * waveInGetNumDevs [WINMM.@]
2594 UINT WINAPI waveInGetNumDevs(void)
2596 return MMDRV_GetNum(MMDRV_WAVEIN);
2599 /**************************************************************************
2600 * waveInGetDevCapsW [WINMM.@]
2602 UINT WINAPI waveInGetDevCapsW(UINT uDeviceID, LPWAVEINCAPSW lpCaps, UINT uSize)
2604 WAVEINCAPSA wicA;
2605 UINT ret = waveInGetDevCapsA(uDeviceID, &wicA, uSize);
2607 if (ret == MMSYSERR_NOERROR) {
2608 lpCaps->wMid = wicA.wMid;
2609 lpCaps->wPid = wicA.wPid;
2610 lpCaps->vDriverVersion = wicA.vDriverVersion;
2611 MultiByteToWideChar( CP_ACP, 0, wicA.szPname, -1, lpCaps->szPname,
2612 sizeof(lpCaps->szPname)/sizeof(WCHAR) );
2613 lpCaps->dwFormats = wicA.dwFormats;
2614 lpCaps->wChannels = wicA.wChannels;
2617 return ret;
2620 /**************************************************************************
2621 * waveInGetDevCapsA [WINMM.@]
2623 UINT WINAPI waveInGetDevCapsA(UINT uDeviceID, LPWAVEINCAPSA lpCaps, UINT uSize)
2625 LPWINE_MLD wmld;
2627 TRACE("(%u %p %u)!\n", uDeviceID, lpCaps, uSize);
2629 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_WAVEIN, TRUE)) == NULL)
2630 return MMSYSERR_INVALHANDLE;
2632 return MMDRV_Message(wmld, WIDM_GETDEVCAPS, (DWORD)lpCaps, uSize, TRUE);
2635 /**************************************************************************
2636 * waveInGetErrorTextA [WINMM.@]
2638 UINT WINAPI waveInGetErrorTextA(UINT uError, LPSTR lpText, UINT uSize)
2640 return WAVE_GetErrorText(uError, lpText, uSize);
2643 /**************************************************************************
2644 * waveInGetErrorTextW [WINMM.@]
2646 UINT WINAPI waveInGetErrorTextW(UINT uError, LPWSTR lpText, UINT uSize)
2648 LPSTR txt = HeapAlloc(GetProcessHeap(), 0, uSize);
2649 UINT ret = WAVE_GetErrorText(uError, txt, uSize);
2651 MultiByteToWideChar( CP_ACP, 0, txt, -1, lpText, uSize );
2652 HeapFree(GetProcessHeap(), 0, txt);
2653 return ret;
2656 /**************************************************************************
2657 * waveInOpen [WINMM.@]
2659 UINT WINAPI waveInOpen(HWAVEIN* lphWaveIn, UINT uDeviceID,
2660 const LPWAVEFORMATEX lpFormat, DWORD dwCallback,
2661 DWORD dwInstance, DWORD dwFlags)
2663 return WAVE_Open((HANDLE*)lphWaveIn, uDeviceID, MMDRV_WAVEIN, lpFormat,
2664 dwCallback, dwInstance, dwFlags, TRUE);
2667 /**************************************************************************
2668 * waveInClose [WINMM.@]
2670 UINT WINAPI waveInClose(HWAVEIN hWaveIn)
2672 LPWINE_MLD wmld;
2673 DWORD dwRet;
2675 TRACE("(%p)\n", hWaveIn);
2677 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2678 return MMSYSERR_INVALHANDLE;
2680 dwRet = MMDRV_Message(wmld, WIDM_CLOSE, 0L, 0L, TRUE);
2681 MMDRV_Free(hWaveIn, wmld);
2682 return dwRet;
2685 /**************************************************************************
2686 * waveInPrepareHeader [WINMM.@]
2688 UINT WINAPI waveInPrepareHeader(HWAVEIN hWaveIn, WAVEHDR* lpWaveInHdr,
2689 UINT uSize)
2691 LPWINE_MLD wmld;
2693 TRACE("(%p, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
2695 if (lpWaveInHdr == NULL) return MMSYSERR_INVALPARAM;
2696 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2697 return MMSYSERR_INVALHANDLE;
2699 lpWaveInHdr->dwBytesRecorded = 0;
2701 return MMDRV_Message(wmld, WIDM_PREPARE, (DWORD)lpWaveInHdr, uSize, TRUE);
2704 /**************************************************************************
2705 * waveInUnprepareHeader [WINMM.@]
2707 UINT WINAPI waveInUnprepareHeader(HWAVEIN hWaveIn, WAVEHDR* lpWaveInHdr,
2708 UINT uSize)
2710 LPWINE_MLD wmld;
2712 TRACE("(%p, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
2714 if (lpWaveInHdr == NULL) return MMSYSERR_INVALPARAM;
2715 if (!(lpWaveInHdr->dwFlags & WHDR_PREPARED)) {
2716 return MMSYSERR_NOERROR;
2719 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2720 return MMSYSERR_INVALHANDLE;
2722 return MMDRV_Message(wmld, WIDM_UNPREPARE, (DWORD)lpWaveInHdr, uSize, TRUE);
2725 /**************************************************************************
2726 * waveInAddBuffer [WINMM.@]
2728 UINT WINAPI waveInAddBuffer(HWAVEIN hWaveIn,
2729 WAVEHDR* lpWaveInHdr, UINT uSize)
2731 LPWINE_MLD wmld;
2733 TRACE("(%p, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
2735 if (lpWaveInHdr == NULL) return MMSYSERR_INVALPARAM;
2736 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2737 return MMSYSERR_INVALHANDLE;
2739 return MMDRV_Message(wmld, WIDM_ADDBUFFER, (DWORD)lpWaveInHdr, uSize, TRUE);
2742 /**************************************************************************
2743 * waveInReset [WINMM.@]
2745 UINT WINAPI waveInReset(HWAVEIN hWaveIn)
2747 LPWINE_MLD wmld;
2749 TRACE("(%p);\n", hWaveIn);
2751 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2752 return MMSYSERR_INVALHANDLE;
2754 return MMDRV_Message(wmld, WIDM_RESET, 0L, 0L, TRUE);
2757 /**************************************************************************
2758 * waveInStart [WINMM.@]
2760 UINT WINAPI waveInStart(HWAVEIN hWaveIn)
2762 LPWINE_MLD wmld;
2764 TRACE("(%p);\n", hWaveIn);
2766 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2767 return MMSYSERR_INVALHANDLE;
2769 return MMDRV_Message(wmld, WIDM_START, 0L, 0L, TRUE);
2772 /**************************************************************************
2773 * waveInStop [WINMM.@]
2775 UINT WINAPI waveInStop(HWAVEIN hWaveIn)
2777 LPWINE_MLD wmld;
2779 TRACE("(%p);\n", hWaveIn);
2781 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2782 return MMSYSERR_INVALHANDLE;
2784 return MMDRV_Message(wmld,WIDM_STOP, 0L, 0L, TRUE);
2787 /**************************************************************************
2788 * waveInGetPosition [WINMM.@]
2790 UINT WINAPI waveInGetPosition(HWAVEIN hWaveIn, LPMMTIME lpTime,
2791 UINT uSize)
2793 LPWINE_MLD wmld;
2795 TRACE("(%p, %p, %u);\n", hWaveIn, lpTime, uSize);
2797 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2798 return MMSYSERR_INVALHANDLE;
2800 return MMDRV_Message(wmld, WIDM_GETPOS, (DWORD)lpTime, uSize, TRUE);
2803 /**************************************************************************
2804 * waveInGetID [WINMM.@]
2806 UINT WINAPI waveInGetID(HWAVEIN hWaveIn, UINT* lpuDeviceID)
2808 LPWINE_MLD wmld;
2810 TRACE("(%p, %p);\n", hWaveIn, lpuDeviceID);
2812 if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
2814 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2815 return MMSYSERR_INVALHANDLE;
2817 *lpuDeviceID = wmld->uDeviceID;
2818 return MMSYSERR_NOERROR;
2821 /**************************************************************************
2822 * waveInMessage [WINMM.@]
2824 DWORD WINAPI waveInMessage(HWAVEIN hWaveIn, UINT uMessage,
2825 DWORD dwParam1, DWORD dwParam2)
2827 LPWINE_MLD wmld;
2829 TRACE("(%p, %u, %ld, %ld)\n", hWaveIn, uMessage, dwParam1, dwParam2);
2831 /* from M$ KB */
2832 if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER))
2833 return MMSYSERR_INVALPARAM;
2835 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2836 return MMSYSERR_INVALHANDLE;
2838 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);