1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
6 * Copyright 1993 Martin Ayotte
7 * 1998-2002 Eric Pouech
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * 98/9 added Win32 MCI support
27 * 99/4 added midiStream support
28 * 99/9 added support for loadable low level drivers
33 #define NONAMELESSUNION
34 #define NONAMELESSSTRUCT
37 #include "wine/winuser16.h" /* FIXME: should be removed, only used for UserYield16 */
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(winmm
);
46 /* ========================================================================
47 * G L O B A L S E T T I N G S
48 * ========================================================================*/
50 LPWINE_MM_IDATA WINMM_IData
/* = NULL */;
52 /**************************************************************************
53 * WINMM_CreateIData [internal]
55 static BOOL
WINMM_CreateIData(HINSTANCE hInstDLL
)
57 WINMM_IData
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WINE_MM_IDATA
));
61 WINMM_IData
->hWinMM32Instance
= hInstDLL
;
62 InitializeCriticalSection(&WINMM_IData
->cs
);
63 WINMM_IData
->cs
.DebugInfo
= (void*)__FILE__
": WinMM";
64 WINMM_IData
->psStopEvent
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
65 WINMM_IData
->psLastEvent
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
66 TRACE("Created IData (%p)\n", WINMM_IData
);
70 /**************************************************************************
71 * WINMM_DeleteIData [internal]
73 static void WINMM_DeleteIData(void)
78 /* FIXME: should also free content and resources allocated
79 * inside WINMM_IData */
80 CloseHandle(WINMM_IData
->psStopEvent
);
81 CloseHandle(WINMM_IData
->psLastEvent
);
82 DeleteCriticalSection(&WINMM_IData
->cs
);
83 HeapFree(GetProcessHeap(), 0, WINMM_IData
);
88 /******************************************************************
92 BOOL
WINMM_CheckForMMSystem(void)
94 /* 0 is not checked yet, -1 is not present, 1 is present */
95 static int loaded
/* = 0 */;
99 HANDLE h
= GetModuleHandleA("kernel32");
103 HANDLE (WINAPI
*gmh
)(LPCSTR
) = (void*)GetProcAddress(h
, "GetModuleHandle16");
104 DWORD (WINAPI
*ll
)(LPCSTR
) = (void*)GetProcAddress(h
, "LoadLibrary16");
105 if (gmh
&& ll
&& (gmh("MMSYSTEM.DLL") || ll("MMSYSTEM.DLL")))
112 /**************************************************************************
113 * DllMain (WINMM.init)
115 * WINMM DLL entry point
118 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID fImpLoad
)
120 TRACE("%p 0x%lx %p\n", hInstDLL
, fdwReason
, fImpLoad
);
123 case DLL_PROCESS_ATTACH
:
124 if (!WINMM_CreateIData(hInstDLL
))
126 if (!MCI_Init() || !MMDRV_Init()) {
131 case DLL_PROCESS_DETACH
:
132 /* close all opened MCI drivers */
133 MCI_SendCommand(MCI_ALL_DEVICE_ID
, MCI_CLOSE
, MCI_WAIT
, 0L, TRUE
);
135 /* now unload all remaining drivers... */
140 case DLL_THREAD_ATTACH
:
141 case DLL_THREAD_DETACH
:
147 /**************************************************************************
148 * Mixer devices. New to Win95
151 /**************************************************************************
152 * find out the real mixer ID depending on hmix (depends on dwFlags)
154 static LPWINE_MIXER
MIXER_GetDev(HMIXEROBJ hmix
, DWORD dwFlags
)
156 LPWINE_MIXER lpwm
= NULL
;
158 switch (dwFlags
& 0xF0000000ul
) {
159 case MIXER_OBJECTF_MIXER
:
160 lpwm
= (LPWINE_MIXER
)MMDRV_Get(hmix
, MMDRV_MIXER
, TRUE
);
162 case MIXER_OBJECTF_HMIXER
:
163 lpwm
= (LPWINE_MIXER
)MMDRV_Get(hmix
, MMDRV_MIXER
, FALSE
);
165 case MIXER_OBJECTF_WAVEOUT
:
166 lpwm
= (LPWINE_MIXER
)MMDRV_GetRelated(hmix
, MMDRV_WAVEOUT
, TRUE
, MMDRV_MIXER
);
168 case MIXER_OBJECTF_HWAVEOUT
:
169 lpwm
= (LPWINE_MIXER
)MMDRV_GetRelated(hmix
, MMDRV_WAVEOUT
, FALSE
, MMDRV_MIXER
);
171 case MIXER_OBJECTF_WAVEIN
:
172 lpwm
= (LPWINE_MIXER
)MMDRV_GetRelated(hmix
, MMDRV_WAVEIN
, TRUE
, MMDRV_MIXER
);
174 case MIXER_OBJECTF_HWAVEIN
:
175 lpwm
= (LPWINE_MIXER
)MMDRV_GetRelated(hmix
, MMDRV_WAVEIN
, FALSE
, MMDRV_MIXER
);
177 case MIXER_OBJECTF_MIDIOUT
:
178 lpwm
= (LPWINE_MIXER
)MMDRV_GetRelated(hmix
, MMDRV_MIDIOUT
, TRUE
, MMDRV_MIXER
);
180 case MIXER_OBJECTF_HMIDIOUT
:
181 lpwm
= (LPWINE_MIXER
)MMDRV_GetRelated(hmix
, MMDRV_MIDIOUT
, FALSE
, MMDRV_MIXER
);
183 case MIXER_OBJECTF_MIDIIN
:
184 lpwm
= (LPWINE_MIXER
)MMDRV_GetRelated(hmix
, MMDRV_MIDIIN
, TRUE
, MMDRV_MIXER
);
186 case MIXER_OBJECTF_HMIDIIN
:
187 lpwm
= (LPWINE_MIXER
)MMDRV_GetRelated(hmix
, MMDRV_MIDIIN
, FALSE
, MMDRV_MIXER
);
189 case MIXER_OBJECTF_AUX
:
190 lpwm
= (LPWINE_MIXER
)MMDRV_GetRelated(hmix
, MMDRV_AUX
, TRUE
, MMDRV_MIXER
);
193 FIXME("Unsupported flag (%08lx)\n", dwFlags
& 0xF0000000ul
);
199 /**************************************************************************
200 * mixerGetNumDevs [WINMM.@]
202 UINT WINAPI
mixerGetNumDevs(void)
204 return MMDRV_GetNum(MMDRV_MIXER
);
207 /**************************************************************************
208 * mixerGetDevCapsA [WINMM.@]
210 UINT WINAPI
mixerGetDevCapsA(UINT devid
, LPMIXERCAPSA mixcaps
, UINT size
)
214 if ((wmld
= MMDRV_Get((HANDLE
)devid
, MMDRV_MIXER
, TRUE
)) == NULL
)
215 return MMSYSERR_BADDEVICEID
;
217 return MMDRV_Message(wmld
, MXDM_GETDEVCAPS
, (DWORD
)mixcaps
, size
, TRUE
);
220 /**************************************************************************
221 * mixerGetDevCapsW [WINMM.@]
223 UINT WINAPI
mixerGetDevCapsW(UINT devid
, LPMIXERCAPSW mixcaps
, UINT size
)
226 UINT ret
= mixerGetDevCapsA(devid
, &micA
, sizeof(micA
));
228 if (ret
== MMSYSERR_NOERROR
) {
229 mixcaps
->wMid
= micA
.wMid
;
230 mixcaps
->wPid
= micA
.wPid
;
231 mixcaps
->vDriverVersion
= micA
.vDriverVersion
;
232 MultiByteToWideChar( CP_ACP
, 0, micA
.szPname
, -1, mixcaps
->szPname
,
233 sizeof(mixcaps
->szPname
)/sizeof(WCHAR
) );
234 mixcaps
->fdwSupport
= micA
.fdwSupport
;
235 mixcaps
->cDestinations
= micA
.cDestinations
;
240 UINT
MIXER_Open(LPHMIXER lphMix
, UINT uDeviceID
, DWORD dwCallback
,
241 DWORD dwInstance
, DWORD fdwOpen
, BOOL bFrom32
)
248 TRACE("(%p, %d, %08lx, %08lx, %08lx)\n",
249 lphMix
, uDeviceID
, dwCallback
, dwInstance
, fdwOpen
);
251 wmld
= MMDRV_Alloc(sizeof(WINE_MIXER
), MMDRV_MIXER
, &hMix
, &fdwOpen
,
252 &dwCallback
, &dwInstance
, bFrom32
);
254 wmld
->uDeviceID
= uDeviceID
;
255 mod
.hmx
= (HMIXEROBJ
)hMix
;
256 mod
.dwCallback
= dwCallback
;
257 mod
.dwInstance
= dwInstance
;
259 dwRet
= MMDRV_Open(wmld
, MXDM_OPEN
, (DWORD
)&mod
, fdwOpen
);
261 if (dwRet
!= MMSYSERR_NOERROR
) {
262 MMDRV_Free(hMix
, wmld
);
265 if (lphMix
) *lphMix
= hMix
;
266 TRACE("=> %ld hMixer=%p\n", dwRet
, hMix
);
271 /**************************************************************************
272 * mixerOpen [WINMM.@]
274 UINT WINAPI
mixerOpen(LPHMIXER lphMix
, UINT uDeviceID
, DWORD dwCallback
,
275 DWORD dwInstance
, DWORD fdwOpen
)
277 return MIXER_Open(lphMix
, uDeviceID
, dwCallback
, dwInstance
, fdwOpen
, TRUE
);
280 /**************************************************************************
281 * mixerClose [WINMM.@]
283 UINT WINAPI
mixerClose(HMIXER hMix
)
288 TRACE("(%p)\n", hMix
);
290 if ((wmld
= MMDRV_Get(hMix
, MMDRV_MIXER
, FALSE
)) == NULL
) return MMSYSERR_INVALHANDLE
;
292 dwRet
= MMDRV_Close(wmld
, MXDM_CLOSE
);
293 MMDRV_Free(hMix
, wmld
);
298 /**************************************************************************
299 * mixerGetID [WINMM.@]
301 UINT WINAPI
mixerGetID(HMIXEROBJ hmix
, LPUINT lpid
, DWORD fdwID
)
305 TRACE("(%p %p %08lx)\n", hmix
, lpid
, fdwID
);
307 if ((lpwm
= MIXER_GetDev(hmix
, fdwID
)) == NULL
) {
308 return MMSYSERR_INVALHANDLE
;
312 *lpid
= lpwm
->mld
.uDeviceID
;
314 return MMSYSERR_NOERROR
;
317 /**************************************************************************
318 * mixerGetControlDetailsA [WINMM.@]
320 UINT WINAPI
mixerGetControlDetailsA(HMIXEROBJ hmix
, LPMIXERCONTROLDETAILS lpmcdA
,
325 TRACE("(%p, %p, %08lx)\n", hmix
, lpmcdA
, fdwDetails
);
327 if ((lpwm
= MIXER_GetDev(hmix
, fdwDetails
)) == NULL
)
328 return MMSYSERR_INVALHANDLE
;
330 if (lpmcdA
== NULL
|| lpmcdA
->cbStruct
!= sizeof(*lpmcdA
))
331 return MMSYSERR_INVALPARAM
;
333 return MMDRV_Message(&lpwm
->mld
, MXDM_GETCONTROLDETAILS
, (DWORD
)lpmcdA
,
337 /**************************************************************************
338 * mixerGetControlDetailsW [WINMM.@]
340 UINT WINAPI
mixerGetControlDetailsW(HMIXEROBJ hmix
, LPMIXERCONTROLDETAILS lpmcd
, DWORD fdwDetails
)
342 DWORD ret
= MMSYSERR_NOTENABLED
;
344 TRACE("(%p, %p, %08lx)\n", hmix
, lpmcd
, fdwDetails
);
346 if (lpmcd
== NULL
|| lpmcd
->cbStruct
!= sizeof(*lpmcd
))
347 return MMSYSERR_INVALPARAM
;
349 switch (fdwDetails
& MIXER_GETCONTROLDETAILSF_QUERYMASK
) {
350 case MIXER_GETCONTROLDETAILSF_VALUE
:
351 /* can savely use W structure as it is, no string inside */
352 ret
= mixerGetControlDetailsA(hmix
, lpmcd
, fdwDetails
);
354 case MIXER_GETCONTROLDETAILSF_LISTTEXT
:
356 MIXERCONTROLDETAILS_LISTTEXTW
*pDetailsW
= (MIXERCONTROLDETAILS_LISTTEXTW
*)lpmcd
->paDetails
;
357 MIXERCONTROLDETAILS_LISTTEXTA
*pDetailsA
;
358 int size
= max(1, lpmcd
->cChannels
) * sizeof(MIXERCONTROLDETAILS_LISTTEXTA
);
361 if (lpmcd
->u
.cMultipleItems
!= 0) {
362 size
*= lpmcd
->u
.cMultipleItems
;
364 pDetailsA
= (MIXERCONTROLDETAILS_LISTTEXTA
*)HeapAlloc(GetProcessHeap(), 0, size
);
365 lpmcd
->paDetails
= pDetailsA
;
366 lpmcd
->cbDetails
= sizeof(MIXERCONTROLDETAILS_LISTTEXTA
);
367 /* set up lpmcd->paDetails */
368 ret
= mixerGetControlDetailsA(hmix
, lpmcd
, fdwDetails
);
369 /* copy from lpmcd->paDetails back to paDetailsW; */
370 if(ret
== MMSYSERR_NOERROR
) {
371 for(i
=0;i
<lpmcd
->u
.cMultipleItems
*lpmcd
->cChannels
;i
++) {
372 pDetailsW
->dwParam1
= pDetailsA
->dwParam1
;
373 pDetailsW
->dwParam2
= pDetailsA
->dwParam2
;
374 MultiByteToWideChar( CP_ACP
, 0, pDetailsA
->szName
, -1,
376 sizeof(pDetailsW
->szName
)/sizeof(WCHAR
) );
380 pDetailsA
-= lpmcd
->u
.cMultipleItems
*lpmcd
->cChannels
;
381 pDetailsW
-= lpmcd
->u
.cMultipleItems
*lpmcd
->cChannels
;
383 HeapFree(GetProcessHeap(), 0, pDetailsA
);
384 lpmcd
->paDetails
= pDetailsW
;
385 lpmcd
->cbDetails
= sizeof(MIXERCONTROLDETAILS_LISTTEXTW
);
389 ERR("Unsupported fdwDetails=0x%08lx\n", fdwDetails
);
395 /**************************************************************************
396 * mixerGetLineControlsA [WINMM.@]
398 UINT WINAPI
mixerGetLineControlsA(HMIXEROBJ hmix
, LPMIXERLINECONTROLSA lpmlcA
,
403 TRACE("(%p, %p, %08lx)\n", hmix
, lpmlcA
, fdwControls
);
405 if ((lpwm
= MIXER_GetDev(hmix
, fdwControls
)) == NULL
)
406 return MMSYSERR_INVALHANDLE
;
408 if (lpmlcA
== NULL
|| lpmlcA
->cbStruct
!= sizeof(*lpmlcA
))
409 return MMSYSERR_INVALPARAM
;
411 return MMDRV_Message(&lpwm
->mld
, MXDM_GETLINECONTROLS
, (DWORD
)lpmlcA
,
415 /**************************************************************************
416 * mixerGetLineControlsW [WINMM.@]
418 UINT WINAPI
mixerGetLineControlsW(HMIXEROBJ hmix
, LPMIXERLINECONTROLSW lpmlcW
,
421 MIXERLINECONTROLSA mlcA
;
425 TRACE("(%p, %p, %08lx)\n", hmix
, lpmlcW
, fdwControls
);
427 if (lpmlcW
== NULL
|| lpmlcW
->cbStruct
!= sizeof(*lpmlcW
) ||
428 lpmlcW
->cbmxctrl
!= sizeof(MIXERCONTROLW
))
429 return MMSYSERR_INVALPARAM
;
431 mlcA
.cbStruct
= sizeof(mlcA
);
432 mlcA
.dwLineID
= lpmlcW
->dwLineID
;
433 mlcA
.u
.dwControlID
= lpmlcW
->u
.dwControlID
;
434 mlcA
.u
.dwControlType
= lpmlcW
->u
.dwControlType
;
435 mlcA
.cControls
= lpmlcW
->cControls
;
436 mlcA
.cbmxctrl
= sizeof(MIXERCONTROLA
);
437 mlcA
.pamxctrl
= HeapAlloc(GetProcessHeap(), 0,
438 mlcA
.cControls
* mlcA
.cbmxctrl
);
440 ret
= mixerGetLineControlsA(hmix
, &mlcA
, fdwControls
);
442 if (ret
== MMSYSERR_NOERROR
) {
443 lpmlcW
->dwLineID
= mlcA
.dwLineID
;
444 lpmlcW
->u
.dwControlID
= mlcA
.u
.dwControlID
;
445 lpmlcW
->u
.dwControlType
= mlcA
.u
.dwControlType
;
446 lpmlcW
->cControls
= mlcA
.cControls
;
448 for (i
= 0; i
< mlcA
.cControls
; i
++) {
449 lpmlcW
->pamxctrl
[i
].cbStruct
= sizeof(MIXERCONTROLW
);
450 lpmlcW
->pamxctrl
[i
].dwControlID
= mlcA
.pamxctrl
[i
].dwControlID
;
451 lpmlcW
->pamxctrl
[i
].dwControlType
= mlcA
.pamxctrl
[i
].dwControlType
;
452 lpmlcW
->pamxctrl
[i
].fdwControl
= mlcA
.pamxctrl
[i
].fdwControl
;
453 lpmlcW
->pamxctrl
[i
].cMultipleItems
= mlcA
.pamxctrl
[i
].cMultipleItems
;
454 MultiByteToWideChar( CP_ACP
, 0, mlcA
.pamxctrl
[i
].szShortName
, -1,
455 lpmlcW
->pamxctrl
[i
].szShortName
,
456 sizeof(lpmlcW
->pamxctrl
[i
].szShortName
)/sizeof(WCHAR
) );
457 MultiByteToWideChar( CP_ACP
, 0, mlcA
.pamxctrl
[i
].szName
, -1,
458 lpmlcW
->pamxctrl
[i
].szName
,
459 sizeof(lpmlcW
->pamxctrl
[i
].szName
)/sizeof(WCHAR
) );
460 /* sizeof(lpmlcW->pamxctrl[i].Bounds) ==
461 * sizeof(mlcA.pamxctrl[i].Bounds) */
462 memcpy(&lpmlcW
->pamxctrl
[i
].Bounds
, &mlcA
.pamxctrl
[i
].Bounds
,
463 sizeof(mlcA
.pamxctrl
[i
].Bounds
));
464 /* sizeof(lpmlcW->pamxctrl[i].Metrics) ==
465 * sizeof(mlcA.pamxctrl[i].Metrics) */
466 memcpy(&lpmlcW
->pamxctrl
[i
].Metrics
, &mlcA
.pamxctrl
[i
].Metrics
,
467 sizeof(mlcA
.pamxctrl
[i
].Metrics
));
471 HeapFree(GetProcessHeap(), 0, mlcA
.pamxctrl
);
476 /**************************************************************************
477 * mixerGetLineInfoA [WINMM.@]
479 UINT WINAPI
mixerGetLineInfoA(HMIXEROBJ hmix
, LPMIXERLINEA lpmliW
, DWORD fdwInfo
)
483 TRACE("(%p, %p, %08lx)\n", hmix
, lpmliW
, fdwInfo
);
485 if ((lpwm
= MIXER_GetDev(hmix
, fdwInfo
)) == NULL
)
486 return MMSYSERR_INVALHANDLE
;
488 return MMDRV_Message(&lpwm
->mld
, MXDM_GETLINEINFO
, (DWORD
)lpmliW
,
492 /**************************************************************************
493 * mixerGetLineInfoW [WINMM.@]
495 UINT WINAPI
mixerGetLineInfoW(HMIXEROBJ hmix
, LPMIXERLINEW lpmliW
,
501 TRACE("(%p, %p, %08lx)\n", hmix
, lpmliW
, fdwInfo
);
503 if (lpmliW
== NULL
|| lpmliW
->cbStruct
!= sizeof(*lpmliW
))
504 return MMSYSERR_INVALPARAM
;
506 mliA
.cbStruct
= sizeof(mliA
);
507 switch (fdwInfo
& MIXER_GETLINEINFOF_QUERYMASK
) {
508 case MIXER_GETLINEINFOF_COMPONENTTYPE
:
509 mliA
.dwComponentType
= lpmliW
->dwComponentType
;
511 case MIXER_GETLINEINFOF_DESTINATION
:
512 mliA
.dwDestination
= lpmliW
->dwDestination
;
514 case MIXER_GETLINEINFOF_LINEID
:
515 mliA
.dwLineID
= lpmliW
->dwLineID
;
517 case MIXER_GETLINEINFOF_SOURCE
:
518 mliA
.dwDestination
= lpmliW
->dwDestination
;
519 mliA
.dwSource
= lpmliW
->dwSource
;
521 case MIXER_GETLINEINFOF_TARGETTYPE
:
522 mliA
.Target
.dwType
= lpmliW
->Target
.dwType
;
523 mliA
.Target
.wMid
= lpmliW
->Target
.wMid
;
524 mliA
.Target
.wPid
= lpmliW
->Target
.wPid
;
525 mliA
.Target
.vDriverVersion
= lpmliW
->Target
.vDriverVersion
;
526 WideCharToMultiByte( CP_ACP
, 0, lpmliW
->Target
.szPname
, -1, mliA
.Target
.szPname
, sizeof(mliA
.Target
.szPname
), NULL
, NULL
);
529 FIXME("Unsupported fdwControls=0x%08lx\n", fdwInfo
);
532 ret
= mixerGetLineInfoA(hmix
, &mliA
, fdwInfo
);
534 lpmliW
->dwDestination
= mliA
.dwDestination
;
535 lpmliW
->dwSource
= mliA
.dwSource
;
536 lpmliW
->dwLineID
= mliA
.dwLineID
;
537 lpmliW
->fdwLine
= mliA
.fdwLine
;
538 lpmliW
->dwUser
= mliA
.dwUser
;
539 lpmliW
->dwComponentType
= mliA
.dwComponentType
;
540 lpmliW
->cChannels
= mliA
.cChannels
;
541 lpmliW
->cConnections
= mliA
.cConnections
;
542 lpmliW
->cControls
= mliA
.cControls
;
543 MultiByteToWideChar( CP_ACP
, 0, mliA
.szShortName
, -1, lpmliW
->szShortName
,
544 sizeof(lpmliW
->szShortName
)/sizeof(WCHAR
) );
545 MultiByteToWideChar( CP_ACP
, 0, mliA
.szName
, -1, lpmliW
->szName
,
546 sizeof(lpmliW
->szName
)/sizeof(WCHAR
) );
547 lpmliW
->Target
.dwType
= mliA
.Target
.dwType
;
548 lpmliW
->Target
.dwDeviceID
= mliA
.Target
.dwDeviceID
;
549 lpmliW
->Target
.wMid
= mliA
.Target
.wMid
;
550 lpmliW
->Target
.wPid
= mliA
.Target
.wPid
;
551 lpmliW
->Target
.vDriverVersion
= mliA
.Target
.vDriverVersion
;
552 MultiByteToWideChar( CP_ACP
, 0, mliA
.Target
.szPname
, -1, lpmliW
->Target
.szPname
,
553 sizeof(lpmliW
->Target
.szPname
)/sizeof(WCHAR
) );
558 /**************************************************************************
559 * mixerSetControlDetails [WINMM.@]
561 UINT WINAPI
mixerSetControlDetails(HMIXEROBJ hmix
, LPMIXERCONTROLDETAILS lpmcdA
,
566 TRACE("(%p, %p, %08lx)\n", hmix
, lpmcdA
, fdwDetails
);
568 if ((lpwm
= MIXER_GetDev(hmix
, fdwDetails
)) == NULL
)
569 return MMSYSERR_INVALHANDLE
;
571 return MMDRV_Message(&lpwm
->mld
, MXDM_SETCONTROLDETAILS
, (DWORD
)lpmcdA
,
575 /**************************************************************************
576 * mixerMessage [WINMM.@]
578 UINT WINAPI
mixerMessage(HMIXER hmix
, UINT uMsg
, DWORD dwParam1
, DWORD dwParam2
)
582 TRACE("(%04lx, %d, %08lx, %08lx): semi-stub?\n",
583 (DWORD
)hmix
, uMsg
, dwParam1
, dwParam2
);
585 if ((wmld
= MMDRV_Get(hmix
, MMDRV_MIXER
, FALSE
)) == NULL
)
586 return MMSYSERR_INVALHANDLE
;
588 return MMDRV_Message(wmld
, uMsg
, dwParam1
, dwParam2
, TRUE
);
591 /**************************************************************************
592 * auxGetNumDevs [WINMM.@]
594 UINT WINAPI
auxGetNumDevs(void)
596 return MMDRV_GetNum(MMDRV_AUX
);
599 /**************************************************************************
600 * auxGetDevCapsW [WINMM.@]
602 UINT WINAPI
auxGetDevCapsW(UINT uDeviceID
, LPAUXCAPSW lpCaps
, UINT uSize
)
605 UINT ret
= auxGetDevCapsA(uDeviceID
, &acA
, sizeof(acA
));
607 lpCaps
->wMid
= acA
.wMid
;
608 lpCaps
->wPid
= acA
.wPid
;
609 lpCaps
->vDriverVersion
= acA
.vDriverVersion
;
610 MultiByteToWideChar( CP_ACP
, 0, acA
.szPname
, -1, lpCaps
->szPname
,
611 sizeof(lpCaps
->szPname
)/sizeof(WCHAR
) );
612 lpCaps
->wTechnology
= acA
.wTechnology
;
613 lpCaps
->dwSupport
= acA
.dwSupport
;
617 /**************************************************************************
618 * auxGetDevCapsA [WINMM.@]
620 UINT WINAPI
auxGetDevCapsA(UINT uDeviceID
, LPAUXCAPSA lpCaps
, UINT uSize
)
624 TRACE("(%04X, %p, %d) !\n", uDeviceID
, lpCaps
, uSize
);
626 if ((wmld
= MMDRV_Get((HANDLE
)uDeviceID
, MMDRV_AUX
, TRUE
)) == NULL
)
627 return MMSYSERR_INVALHANDLE
;
628 return MMDRV_Message(wmld
, AUXDM_GETDEVCAPS
, (DWORD
)lpCaps
, uSize
, TRUE
);
631 /**************************************************************************
632 * auxGetVolume [WINMM.@]
634 UINT WINAPI
auxGetVolume(UINT uDeviceID
, DWORD
* lpdwVolume
)
638 TRACE("(%04X, %p) !\n", uDeviceID
, lpdwVolume
);
640 if ((wmld
= MMDRV_Get((HANDLE
)uDeviceID
, MMDRV_AUX
, TRUE
)) == NULL
)
641 return MMSYSERR_INVALHANDLE
;
642 return MMDRV_Message(wmld
, AUXDM_GETVOLUME
, (DWORD
)lpdwVolume
, 0L, TRUE
);
645 /**************************************************************************
646 * auxSetVolume [WINMM.@]
648 UINT WINAPI
auxSetVolume(UINT uDeviceID
, DWORD dwVolume
)
652 TRACE("(%04X, %lu) !\n", uDeviceID
, dwVolume
);
654 if ((wmld
= MMDRV_Get((HANDLE
)uDeviceID
, MMDRV_AUX
, TRUE
)) == NULL
)
655 return MMSYSERR_INVALHANDLE
;
656 return MMDRV_Message(wmld
, AUXDM_SETVOLUME
, dwVolume
, 0L, TRUE
);
659 /**************************************************************************
660 * auxOutMessage [WINMM.@]
662 DWORD WINAPI
auxOutMessage(UINT uDeviceID
, UINT uMessage
, DWORD dw1
, DWORD dw2
)
666 if ((wmld
= MMDRV_Get((HANDLE
)uDeviceID
, MMDRV_AUX
, TRUE
)) == NULL
)
667 return MMSYSERR_INVALHANDLE
;
669 return MMDRV_Message(wmld
, uMessage
, dw1
, dw2
, TRUE
);
672 /**************************************************************************
673 * mciGetErrorStringW [WINMM.@]
675 BOOL WINAPI
mciGetErrorStringW(DWORD wError
, LPWSTR lpstrBuffer
, UINT uLength
)
677 LPSTR bufstr
= HeapAlloc(GetProcessHeap(), 0, uLength
);
678 BOOL ret
= mciGetErrorStringA(wError
, bufstr
, uLength
);
680 MultiByteToWideChar( CP_ACP
, 0, bufstr
, -1, lpstrBuffer
, uLength
);
681 HeapFree(GetProcessHeap(), 0, bufstr
);
685 /**************************************************************************
686 * mciGetErrorStringA [WINMM.@]
688 BOOL WINAPI
mciGetErrorStringA(DWORD dwError
, LPSTR lpstrBuffer
, UINT uLength
)
692 if (lpstrBuffer
!= NULL
&& uLength
> 0 &&
693 dwError
>= MCIERR_BASE
&& dwError
<= MCIERR_CUSTOM_DRIVER_BASE
) {
695 if (LoadStringA(WINMM_IData
->hWinMM32Instance
,
696 dwError
, lpstrBuffer
, uLength
) > 0) {
703 /**************************************************************************
704 * mciDriverNotify [WINMM.@]
706 BOOL WINAPI
mciDriverNotify(HWND hWndCallBack
, UINT wDevID
, UINT wStatus
)
709 TRACE("(%p, %04x, %04X)\n", hWndCallBack
, wDevID
, wStatus
);
711 return PostMessageA(hWndCallBack
, MM_MCINOTIFY
, wStatus
, wDevID
);
714 /**************************************************************************
715 * mciGetDriverData [WINMM.@]
717 DWORD WINAPI
mciGetDriverData(UINT uDeviceID
)
719 LPWINE_MCIDRIVER wmd
;
721 TRACE("(%04x)\n", uDeviceID
);
723 wmd
= MCI_GetDriver(uDeviceID
);
726 WARN("Bad uDeviceID\n");
730 return wmd
->dwPrivate
;
733 /**************************************************************************
734 * mciSetDriverData [WINMM.@]
736 BOOL WINAPI
mciSetDriverData(UINT uDeviceID
, DWORD data
)
738 LPWINE_MCIDRIVER wmd
;
740 TRACE("(%04x, %08lx)\n", uDeviceID
, data
);
742 wmd
= MCI_GetDriver(uDeviceID
);
745 WARN("Bad uDeviceID\n");
749 wmd
->dwPrivate
= data
;
753 /**************************************************************************
754 * mciSendCommandA [WINMM.@]
756 DWORD WINAPI
mciSendCommandA(UINT wDevID
, UINT wMsg
, DWORD dwParam1
, DWORD dwParam2
)
760 TRACE("(%08x, %s, %08lx, %08lx)\n",
761 wDevID
, MCI_MessageToString(wMsg
), dwParam1
, dwParam2
);
763 dwRet
= MCI_SendCommand(wDevID
, wMsg
, dwParam1
, dwParam2
, TRUE
);
764 dwRet
= MCI_CleanUp(dwRet
, wMsg
, dwParam2
);
765 TRACE("=> %08lx\n", dwRet
);
769 /**************************************************************************
770 * mciSendCommandW [WINMM.@]
772 DWORD WINAPI
mciSendCommandW(UINT wDevID
, UINT wMsg
, DWORD dwParam1
, DWORD dwParam2
)
774 FIXME("(%08x, %s, %08lx, %08lx): stub\n",
775 wDevID
, MCI_MessageToString(wMsg
), dwParam1
, dwParam2
);
776 return MCIERR_UNSUPPORTED_FUNCTION
;
779 /**************************************************************************
780 * mciGetDeviceIDA [WINMM.@]
782 UINT WINAPI
mciGetDeviceIDA(LPCSTR lpstrName
)
784 return MCI_GetDriverFromString(lpstrName
);
787 /**************************************************************************
788 * mciGetDeviceIDW [WINMM.@]
790 UINT WINAPI
mciGetDeviceIDW(LPCWSTR lpwstrName
)
795 lpstrName
= HEAP_strdupWtoA(GetProcessHeap(), 0, lpwstrName
);
796 ret
= MCI_GetDriverFromString(lpstrName
);
797 HeapFree(GetProcessHeap(), 0, lpstrName
);
801 /**************************************************************************
802 * MCI_DefYieldProc [internal]
804 UINT WINAPI
MCI_DefYieldProc(MCIDEVICEID wDevID
, DWORD data
)
808 TRACE("(0x%04x, 0x%08lx)\n", wDevID
, data
);
810 if ((HIWORD(data
) != 0 && HWND_16(GetActiveWindow()) != HIWORD(data
)) ||
811 (GetAsyncKeyState(LOWORD(data
)) & 1) == 0) {
817 msg
.hwnd
= HWND_32(HIWORD(data
));
818 while (!PeekMessageA(&msg
, msg
.hwnd
, WM_KEYFIRST
, WM_KEYLAST
, PM_REMOVE
));
824 /**************************************************************************
825 * mciSetYieldProc [WINMM.@]
827 BOOL WINAPI
mciSetYieldProc(UINT uDeviceID
, YIELDPROC fpYieldProc
, DWORD dwYieldData
)
829 LPWINE_MCIDRIVER wmd
;
831 TRACE("(%u, %p, %08lx)\n", uDeviceID
, fpYieldProc
, dwYieldData
);
833 if (!(wmd
= MCI_GetDriver(uDeviceID
))) {
834 WARN("Bad uDeviceID\n");
838 wmd
->lpfnYieldProc
= fpYieldProc
;
839 wmd
->dwYieldData
= dwYieldData
;
845 /**************************************************************************
846 * mciGetDeviceIDFromElementIDW [WINMM.@]
848 UINT WINAPI
mciGetDeviceIDFromElementIDW(DWORD dwElementID
, LPCWSTR lpstrType
)
850 /* FIXME: that's rather strange, there is no
851 * mciGetDeviceIDFromElementID32A in winmm.spec
853 FIXME("(%lu, %p) stub\n", dwElementID
, lpstrType
);
857 /**************************************************************************
858 * mciGetYieldProc [WINMM.@]
860 YIELDPROC WINAPI
mciGetYieldProc(UINT uDeviceID
, DWORD
* lpdwYieldData
)
862 LPWINE_MCIDRIVER wmd
;
864 TRACE("(%u, %p)\n", uDeviceID
, lpdwYieldData
);
866 if (!(wmd
= MCI_GetDriver(uDeviceID
))) {
867 WARN("Bad uDeviceID\n");
870 if (!wmd
->lpfnYieldProc
) {
871 WARN("No proc set\n");
875 WARN("Proc is 32 bit\n");
878 return wmd
->lpfnYieldProc
;
881 /**************************************************************************
882 * mciGetCreatorTask [WINMM.@]
884 HTASK WINAPI
mciGetCreatorTask(UINT uDeviceID
)
886 LPWINE_MCIDRIVER wmd
;
889 if ((wmd
= MCI_GetDriver(uDeviceID
))) ret
= (HTASK
)wmd
->CreatorThread
;
891 TRACE("(%u) => %p\n", uDeviceID
, ret
);
895 /**************************************************************************
896 * mciDriverYield [WINMM.@]
898 UINT WINAPI
mciDriverYield(UINT uDeviceID
)
900 LPWINE_MCIDRIVER wmd
;
903 TRACE("(%04x)\n", uDeviceID
);
905 if (!(wmd
= MCI_GetDriver(uDeviceID
)) || !wmd
->lpfnYieldProc
|| !wmd
->bIs32
) {
908 ret
= wmd
->lpfnYieldProc(uDeviceID
, wmd
->dwYieldData
);
914 /**************************************************************************
915 * midiOutGetNumDevs [WINMM.@]
917 UINT WINAPI
midiOutGetNumDevs(void)
919 return MMDRV_GetNum(MMDRV_MIDIOUT
);
922 /**************************************************************************
923 * midiOutGetDevCapsW [WINMM.@]
925 UINT WINAPI
midiOutGetDevCapsW(UINT uDeviceID
, LPMIDIOUTCAPSW lpCaps
,
931 ret
= midiOutGetDevCapsA(uDeviceID
, &mocA
, sizeof(mocA
));
932 lpCaps
->wMid
= mocA
.wMid
;
933 lpCaps
->wPid
= mocA
.wPid
;
934 lpCaps
->vDriverVersion
= mocA
.vDriverVersion
;
935 MultiByteToWideChar( CP_ACP
, 0, mocA
.szPname
, -1, lpCaps
->szPname
,
936 sizeof(lpCaps
->szPname
)/sizeof(WCHAR
) );
937 lpCaps
->wTechnology
= mocA
.wTechnology
;
938 lpCaps
->wVoices
= mocA
.wVoices
;
939 lpCaps
->wNotes
= mocA
.wNotes
;
940 lpCaps
->wChannelMask
= mocA
.wChannelMask
;
941 lpCaps
->dwSupport
= mocA
.dwSupport
;
945 /**************************************************************************
946 * midiOutGetDevCapsA [WINMM.@]
948 UINT WINAPI
midiOutGetDevCapsA(UINT uDeviceID
, LPMIDIOUTCAPSA lpCaps
,
953 TRACE("(%u, %p, %u);\n", uDeviceID
, lpCaps
, uSize
);
955 if (lpCaps
== NULL
) return MMSYSERR_INVALPARAM
;
957 if ((wmld
= MMDRV_Get((HANDLE
)uDeviceID
, MMDRV_MIDIOUT
, TRUE
)) == NULL
)
958 return MMSYSERR_INVALHANDLE
;
960 return MMDRV_Message(wmld
, MODM_GETDEVCAPS
, (DWORD
)lpCaps
, uSize
, TRUE
);
963 /**************************************************************************
964 * MIDI_GetErrorText [internal]
966 static UINT16
MIDI_GetErrorText(UINT16 uError
, LPSTR lpText
, UINT16 uSize
)
968 UINT16 ret
= MMSYSERR_BADERRNUM
;
970 if (lpText
== NULL
) {
971 ret
= MMSYSERR_INVALPARAM
;
972 } else if (uSize
== 0) {
973 ret
= MMSYSERR_NOERROR
;
975 /* test has been removed 'coz MMSYSERR_BASE is 0, and gcc did emit
976 * a warning for the test was always true */
977 (/*uError >= MMSYSERR_BASE && */ uError
<= MMSYSERR_LASTERROR
) ||
978 (uError
>= MIDIERR_BASE
&& uError
<= MIDIERR_LASTERROR
)) {
980 if (LoadStringA(WINMM_IData
->hWinMM32Instance
,
981 uError
, lpText
, uSize
) > 0) {
982 ret
= MMSYSERR_NOERROR
;
988 /**************************************************************************
989 * midiOutGetErrorTextA [WINMM.@]
991 UINT WINAPI
midiOutGetErrorTextA(UINT uError
, LPSTR lpText
, UINT uSize
)
993 return MIDI_GetErrorText(uError
, lpText
, uSize
);
996 /**************************************************************************
997 * midiOutGetErrorTextW [WINMM.@]
999 UINT WINAPI
midiOutGetErrorTextW(UINT uError
, LPWSTR lpText
, UINT uSize
)
1001 LPSTR xstr
= HeapAlloc(GetProcessHeap(), 0, uSize
);
1004 ret
= MIDI_GetErrorText(uError
, xstr
, uSize
);
1005 MultiByteToWideChar( CP_ACP
, 0, xstr
, -1, lpText
, uSize
);
1006 HeapFree(GetProcessHeap(), 0, xstr
);
1010 /**************************************************************************
1011 * MIDI_OutAlloc [internal]
1013 static LPWINE_MIDI
MIDI_OutAlloc(HMIDIOUT
* lphMidiOut
, LPDWORD lpdwCallback
,
1014 LPDWORD lpdwInstance
, LPDWORD lpdwFlags
,
1015 DWORD cIDs
, MIDIOPENSTRMID
* lpIDs
, BOOL bFrom32
)
1021 size
= sizeof(WINE_MIDI
) + (cIDs
? (cIDs
-1) : 0) * sizeof(MIDIOPENSTRMID
);
1023 lpwm
= (LPWINE_MIDI
)MMDRV_Alloc(size
, MMDRV_MIDIOUT
, &hMidiOut
, lpdwFlags
,
1024 lpdwCallback
, lpdwInstance
, bFrom32
);
1026 if (lphMidiOut
!= NULL
)
1027 *lphMidiOut
= hMidiOut
;
1030 lpwm
->mod
.hMidi
= (HMIDI
) hMidiOut
;
1031 lpwm
->mod
.dwCallback
= *lpdwCallback
;
1032 lpwm
->mod
.dwInstance
= *lpdwInstance
;
1033 lpwm
->mod
.dnDevNode
= 0;
1034 lpwm
->mod
.cIds
= cIDs
;
1036 memcpy(&(lpwm
->mod
.rgIds
), lpIDs
, cIDs
* sizeof(MIDIOPENSTRMID
));
1041 UINT
MIDI_OutOpen(HMIDIOUT
* lphMidiOut
, UINT uDeviceID
, DWORD dwCallback
,
1042 DWORD dwInstance
, DWORD dwFlags
, BOOL bFrom32
)
1048 TRACE("(%p, %d, %08lX, %08lX, %08lX);\n",
1049 lphMidiOut
, uDeviceID
, dwCallback
, dwInstance
, dwFlags
);
1051 if (lphMidiOut
!= NULL
) *lphMidiOut
= 0;
1053 lpwm
= MIDI_OutAlloc(&hMidiOut
, &dwCallback
, &dwInstance
, &dwFlags
,
1057 return MMSYSERR_NOMEM
;
1059 lpwm
->mld
.uDeviceID
= uDeviceID
;
1061 dwRet
= MMDRV_Open((LPWINE_MLD
)lpwm
, MODM_OPEN
, (DWORD
)&lpwm
->mod
, dwFlags
);
1063 if (dwRet
!= MMSYSERR_NOERROR
) {
1064 MMDRV_Free(hMidiOut
, (LPWINE_MLD
)lpwm
);
1068 if (lphMidiOut
) *lphMidiOut
= hMidiOut
;
1069 TRACE("=> %d hMidi=%p\n", dwRet
, hMidiOut
);
1074 /**************************************************************************
1075 * midiOutOpen [WINMM.@]
1077 UINT WINAPI
midiOutOpen(HMIDIOUT
* lphMidiOut
, UINT uDeviceID
,
1078 DWORD dwCallback
, DWORD dwInstance
, DWORD dwFlags
)
1080 return MIDI_OutOpen(lphMidiOut
, uDeviceID
, dwCallback
, dwInstance
, dwFlags
, TRUE
);
1083 /**************************************************************************
1084 * midiOutClose [WINMM.@]
1086 UINT WINAPI
midiOutClose(HMIDIOUT hMidiOut
)
1091 TRACE("(%p)\n", hMidiOut
);
1093 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, FALSE
)) == NULL
)
1094 return MMSYSERR_INVALHANDLE
;
1096 dwRet
= MMDRV_Close(wmld
, MODM_CLOSE
);
1097 MMDRV_Free(hMidiOut
, wmld
);
1102 /**************************************************************************
1103 * midiOutPrepareHeader [WINMM.@]
1105 UINT WINAPI
midiOutPrepareHeader(HMIDIOUT hMidiOut
,
1106 MIDIHDR
* lpMidiOutHdr
, UINT uSize
)
1110 TRACE("(%p, %p, %d)\n", hMidiOut
, lpMidiOutHdr
, uSize
);
1112 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, FALSE
)) == NULL
)
1113 return MMSYSERR_INVALHANDLE
;
1115 return MMDRV_Message(wmld
, MODM_PREPARE
, (DWORD
)lpMidiOutHdr
, uSize
, TRUE
);
1118 /**************************************************************************
1119 * midiOutUnprepareHeader [WINMM.@]
1121 UINT WINAPI
midiOutUnprepareHeader(HMIDIOUT hMidiOut
,
1122 MIDIHDR
* lpMidiOutHdr
, UINT uSize
)
1126 TRACE("(%p, %p, %d)\n", hMidiOut
, lpMidiOutHdr
, uSize
);
1128 if (!(lpMidiOutHdr
->dwFlags
& MHDR_PREPARED
)) {
1129 return MMSYSERR_NOERROR
;
1132 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, FALSE
)) == NULL
)
1133 return MMSYSERR_INVALHANDLE
;
1135 return MMDRV_Message(wmld
, MODM_UNPREPARE
, (DWORD
)lpMidiOutHdr
, uSize
, TRUE
);
1138 /**************************************************************************
1139 * midiOutShortMsg [WINMM.@]
1141 UINT WINAPI
midiOutShortMsg(HMIDIOUT hMidiOut
, DWORD dwMsg
)
1145 TRACE("(%p, %08lX)\n", hMidiOut
, dwMsg
);
1147 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, FALSE
)) == NULL
)
1148 return MMSYSERR_INVALHANDLE
;
1150 return MMDRV_Message(wmld
, MODM_DATA
, dwMsg
, 0L, TRUE
);
1153 /**************************************************************************
1154 * midiOutLongMsg [WINMM.@]
1156 UINT WINAPI
midiOutLongMsg(HMIDIOUT hMidiOut
,
1157 MIDIHDR
* lpMidiOutHdr
, UINT uSize
)
1161 TRACE("(%p, %p, %d)\n", hMidiOut
, lpMidiOutHdr
, uSize
);
1163 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, FALSE
)) == NULL
)
1164 return MMSYSERR_INVALHANDLE
;
1166 return MMDRV_Message(wmld
, MODM_LONGDATA
, (DWORD
)lpMidiOutHdr
, uSize
, TRUE
);
1169 /**************************************************************************
1170 * midiOutReset [WINMM.@]
1172 UINT WINAPI
midiOutReset(HMIDIOUT hMidiOut
)
1176 TRACE("(%p)\n", hMidiOut
);
1178 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, FALSE
)) == NULL
)
1179 return MMSYSERR_INVALHANDLE
;
1181 return MMDRV_Message(wmld
, MODM_RESET
, 0L, 0L, TRUE
);
1184 /**************************************************************************
1185 * midiOutGetVolume [WINMM.@]
1187 UINT WINAPI
midiOutGetVolume(HMIDIOUT hMidiOut
, DWORD
* lpdwVolume
)
1191 TRACE("(%p, %p);\n", hMidiOut
, lpdwVolume
);
1193 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, TRUE
)) == NULL
)
1194 return MMSYSERR_INVALHANDLE
;
1196 return MMDRV_Message(wmld
, MODM_GETVOLUME
, (DWORD
)lpdwVolume
, 0L, TRUE
);
1199 /**************************************************************************
1200 * midiOutSetVolume [WINMM.@]
1202 UINT WINAPI
midiOutSetVolume(HMIDIOUT hMidiOut
, DWORD dwVolume
)
1206 TRACE("(%p, %ld);\n", hMidiOut
, dwVolume
);
1208 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, TRUE
)) == NULL
)
1209 return MMSYSERR_INVALHANDLE
;
1211 return MMDRV_Message(wmld
, MODM_SETVOLUME
, dwVolume
, 0L, TRUE
);
1214 /**************************************************************************
1215 * midiOutCachePatches [WINMM.@]
1217 UINT WINAPI
midiOutCachePatches(HMIDIOUT hMidiOut
, UINT uBank
,
1218 WORD
* lpwPatchArray
, UINT uFlags
)
1220 /* not really necessary to support this */
1221 FIXME("not supported yet\n");
1222 return MMSYSERR_NOTSUPPORTED
;
1225 /**************************************************************************
1226 * midiOutCacheDrumPatches [WINMM.@]
1228 UINT WINAPI
midiOutCacheDrumPatches(HMIDIOUT hMidiOut
, UINT uPatch
,
1229 WORD
* lpwKeyArray
, UINT uFlags
)
1231 FIXME("not supported yet\n");
1232 return MMSYSERR_NOTSUPPORTED
;
1235 /**************************************************************************
1236 * midiOutGetID [WINMM.@]
1238 UINT WINAPI
midiOutGetID(HMIDIOUT hMidiOut
, UINT
* lpuDeviceID
)
1242 TRACE("(%p, %p)\n", hMidiOut
, lpuDeviceID
);
1244 if (lpuDeviceID
== NULL
) return MMSYSERR_INVALPARAM
;
1245 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, FALSE
)) == NULL
)
1246 return MMSYSERR_INVALHANDLE
;
1248 *lpuDeviceID
= wmld
->uDeviceID
;
1249 return MMSYSERR_NOERROR
;
1252 /**************************************************************************
1253 * midiOutMessage [WINMM.@]
1255 DWORD WINAPI
midiOutMessage(HMIDIOUT hMidiOut
, UINT uMessage
,
1256 DWORD dwParam1
, DWORD dwParam2
)
1260 TRACE("(%p, %04X, %08lX, %08lX)\n", hMidiOut
, uMessage
, dwParam1
, dwParam2
);
1262 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, FALSE
)) == NULL
) {
1264 if (uMessage
== 0x0001) {
1265 *(LPDWORD
)dwParam1
= 1;
1268 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, TRUE
)) != NULL
) {
1269 return MMDRV_PhysicalFeatures(wmld
, uMessage
, dwParam1
, dwParam2
);
1271 return MMSYSERR_INVALHANDLE
;
1277 FIXME("can't handle OPEN or CLOSE message!\n");
1278 return MMSYSERR_NOTSUPPORTED
;
1280 return MMDRV_Message(wmld
, uMessage
, dwParam1
, dwParam2
, TRUE
);
1283 /**************************************************************************
1284 * midiInGetNumDevs [WINMM.@]
1286 UINT WINAPI
midiInGetNumDevs(void)
1288 return MMDRV_GetNum(MMDRV_MIDIIN
);
1291 /**************************************************************************
1292 * midiInGetDevCapsW [WINMM.@]
1294 UINT WINAPI
midiInGetDevCapsW(UINT uDeviceID
, LPMIDIINCAPSW lpCaps
, UINT uSize
)
1297 UINT ret
= midiInGetDevCapsA(uDeviceID
, &micA
, uSize
);
1299 if (ret
== MMSYSERR_NOERROR
) {
1300 lpCaps
->wMid
= micA
.wMid
;
1301 lpCaps
->wPid
= micA
.wPid
;
1302 lpCaps
->vDriverVersion
= micA
.vDriverVersion
;
1303 MultiByteToWideChar( CP_ACP
, 0, micA
.szPname
, -1, lpCaps
->szPname
,
1304 sizeof(lpCaps
->szPname
)/sizeof(WCHAR
) );
1305 lpCaps
->dwSupport
= micA
.dwSupport
;
1310 /**************************************************************************
1311 * midiInGetDevCapsA [WINMM.@]
1313 UINT WINAPI
midiInGetDevCapsA(UINT uDeviceID
, LPMIDIINCAPSA lpCaps
, UINT uSize
)
1317 TRACE("(%d, %p, %d);\n", uDeviceID
, lpCaps
, uSize
);
1319 if ((wmld
= MMDRV_Get((HANDLE
)uDeviceID
, MMDRV_MIDIIN
, TRUE
)) == NULL
)
1320 return MMSYSERR_INVALHANDLE
;
1322 return MMDRV_Message(wmld
, MIDM_GETDEVCAPS
, (DWORD
)lpCaps
, uSize
, TRUE
);
1325 /**************************************************************************
1326 * midiInGetErrorTextW [WINMM.@]
1328 UINT WINAPI
midiInGetErrorTextW(UINT uError
, LPWSTR lpText
, UINT uSize
)
1330 LPSTR xstr
= HeapAlloc(GetProcessHeap(), 0, uSize
);
1331 UINT ret
= MIDI_GetErrorText(uError
, xstr
, uSize
);
1333 MultiByteToWideChar( CP_ACP
, 0, xstr
, -1, lpText
, uSize
);
1334 HeapFree(GetProcessHeap(), 0, xstr
);
1338 /**************************************************************************
1339 * midiInGetErrorTextA [WINMM.@]
1341 UINT WINAPI
midiInGetErrorTextA(UINT uError
, LPSTR lpText
, UINT uSize
)
1343 return MIDI_GetErrorText(uError
, lpText
, uSize
);
1346 UINT
MIDI_InOpen(HMIDIIN
* lphMidiIn
, UINT uDeviceID
, DWORD dwCallback
,
1347 DWORD dwInstance
, DWORD dwFlags
, BOOL bFrom32
)
1353 TRACE("(%p, %d, %08lX, %08lX, %08lX);\n",
1354 lphMidiIn
, uDeviceID
, dwCallback
, dwInstance
, dwFlags
);
1356 if (lphMidiIn
!= NULL
) *lphMidiIn
= 0;
1358 lpwm
= (LPWINE_MIDI
)MMDRV_Alloc(sizeof(WINE_MIDI
), MMDRV_MIDIIN
, &hMidiIn
,
1359 &dwFlags
, &dwCallback
, &dwInstance
, bFrom32
);
1362 return MMSYSERR_NOMEM
;
1364 lpwm
->mod
.hMidi
= (HMIDI
) hMidiIn
;
1365 lpwm
->mod
.dwCallback
= dwCallback
;
1366 lpwm
->mod
.dwInstance
= dwInstance
;
1368 lpwm
->mld
.uDeviceID
= uDeviceID
;
1369 dwRet
= MMDRV_Open(&lpwm
->mld
, MIDM_OPEN
, (DWORD
)&lpwm
->mod
, dwFlags
);
1371 if (dwRet
!= MMSYSERR_NOERROR
) {
1372 MMDRV_Free(hMidiIn
, &lpwm
->mld
);
1375 if (lphMidiIn
!= NULL
) *lphMidiIn
= hMidiIn
;
1376 TRACE("=> %ld hMidi=%p\n", dwRet
, hMidiIn
);
1381 /**************************************************************************
1382 * midiInOpen [WINMM.@]
1384 UINT WINAPI
midiInOpen(HMIDIIN
* lphMidiIn
, UINT uDeviceID
,
1385 DWORD dwCallback
, DWORD dwInstance
, DWORD dwFlags
)
1387 return MIDI_InOpen(lphMidiIn
, uDeviceID
, dwCallback
, dwInstance
, dwFlags
, TRUE
);
1390 /**************************************************************************
1391 * midiInClose [WINMM.@]
1393 UINT WINAPI
midiInClose(HMIDIIN hMidiIn
)
1398 TRACE("(%p)\n", hMidiIn
);
1400 if ((wmld
= MMDRV_Get(hMidiIn
, MMDRV_MIDIIN
, FALSE
)) == NULL
)
1401 return MMSYSERR_INVALHANDLE
;
1403 dwRet
= MMDRV_Close(wmld
, MIDM_CLOSE
);
1404 MMDRV_Free(hMidiIn
, wmld
);
1408 /**************************************************************************
1409 * midiInPrepareHeader [WINMM.@]
1411 UINT WINAPI
midiInPrepareHeader(HMIDIIN hMidiIn
,
1412 MIDIHDR
* lpMidiInHdr
, UINT uSize
)
1416 TRACE("(%p, %p, %d)\n", hMidiIn
, lpMidiInHdr
, uSize
);
1418 if ((wmld
= MMDRV_Get(hMidiIn
, MMDRV_MIDIIN
, FALSE
)) == NULL
)
1419 return MMSYSERR_INVALHANDLE
;
1421 return MMDRV_Message(wmld
, MIDM_PREPARE
, (DWORD
)lpMidiInHdr
, uSize
, TRUE
);
1424 /**************************************************************************
1425 * midiInUnprepareHeader [WINMM.@]
1427 UINT WINAPI
midiInUnprepareHeader(HMIDIIN hMidiIn
,
1428 MIDIHDR
* lpMidiInHdr
, UINT uSize
)
1432 TRACE("(%p, %p, %d)\n", hMidiIn
, lpMidiInHdr
, uSize
);
1434 if (!(lpMidiInHdr
->dwFlags
& MHDR_PREPARED
)) {
1435 return MMSYSERR_NOERROR
;
1438 if ((wmld
= MMDRV_Get(hMidiIn
, MMDRV_MIDIIN
, FALSE
)) == NULL
)
1439 return MMSYSERR_INVALHANDLE
;
1441 return MMDRV_Message(wmld
, MIDM_UNPREPARE
, (DWORD
)lpMidiInHdr
, uSize
, TRUE
);
1444 /**************************************************************************
1445 * midiInAddBuffer [WINMM.@]
1447 UINT WINAPI
midiInAddBuffer(HMIDIIN hMidiIn
,
1448 MIDIHDR
* lpMidiInHdr
, UINT uSize
)
1452 TRACE("(%p, %p, %d)\n", hMidiIn
, lpMidiInHdr
, uSize
);
1454 if ((wmld
= MMDRV_Get(hMidiIn
, MMDRV_MIDIIN
, FALSE
)) == NULL
)
1455 return MMSYSERR_INVALHANDLE
;
1457 return MMDRV_Message(wmld
, MIDM_ADDBUFFER
, (DWORD
)lpMidiInHdr
, uSize
, TRUE
);
1460 /**************************************************************************
1461 * midiInStart [WINMM.@]
1463 UINT WINAPI
midiInStart(HMIDIIN hMidiIn
)
1467 TRACE("(%p)\n", hMidiIn
);
1469 if ((wmld
= MMDRV_Get(hMidiIn
, MMDRV_MIDIIN
, FALSE
)) == NULL
)
1470 return MMSYSERR_INVALHANDLE
;
1472 return MMDRV_Message(wmld
, MIDM_START
, 0L, 0L, TRUE
);
1475 /**************************************************************************
1476 * midiInStop [WINMM.@]
1478 UINT WINAPI
midiInStop(HMIDIIN hMidiIn
)
1482 TRACE("(%p)\n", hMidiIn
);
1484 if ((wmld
= MMDRV_Get(hMidiIn
, MMDRV_MIDIIN
, FALSE
)) == NULL
)
1485 return MMSYSERR_INVALHANDLE
;
1487 return MMDRV_Message(wmld
, MIDM_STOP
, 0L, 0L, TRUE
);
1490 /**************************************************************************
1491 * midiInReset [WINMM.@]
1493 UINT WINAPI
midiInReset(HMIDIIN hMidiIn
)
1497 TRACE("(%p)\n", hMidiIn
);
1499 if ((wmld
= MMDRV_Get(hMidiIn
, MMDRV_MIDIIN
, FALSE
)) == NULL
)
1500 return MMSYSERR_INVALHANDLE
;
1502 return MMDRV_Message(wmld
, MIDM_RESET
, 0L, 0L, TRUE
);
1505 /**************************************************************************
1506 * midiInGetID [WINMM.@]
1508 UINT WINAPI
midiInGetID(HMIDIIN hMidiIn
, UINT
* lpuDeviceID
)
1512 TRACE("(%p, %p)\n", hMidiIn
, lpuDeviceID
);
1514 if (lpuDeviceID
== NULL
) return MMSYSERR_INVALPARAM
;
1516 if ((wmld
= MMDRV_Get(hMidiIn
, MMDRV_MIDIIN
, TRUE
)) == NULL
)
1517 return MMSYSERR_INVALHANDLE
;
1519 *lpuDeviceID
= wmld
->uDeviceID
;
1521 return MMSYSERR_NOERROR
;
1524 /**************************************************************************
1525 * midiInMessage [WINMM.@]
1527 DWORD WINAPI
midiInMessage(HMIDIIN hMidiIn
, UINT uMessage
,
1528 DWORD dwParam1
, DWORD dwParam2
)
1532 TRACE("(%p, %04X, %08lX, %08lX)\n", hMidiIn
, uMessage
, dwParam1
, dwParam2
);
1534 if ((wmld
= MMDRV_Get(hMidiIn
, MMDRV_MIDIIN
, FALSE
)) == NULL
)
1535 return MMSYSERR_INVALHANDLE
;
1540 FIXME("can't handle OPEN or CLOSE message!\n");
1541 return MMSYSERR_NOTSUPPORTED
;
1543 return MMDRV_Message(wmld
, uMessage
, dwParam1
, dwParam2
, TRUE
);
1546 typedef struct WINE_MIDIStream
{
1557 LPMIDIHDR lpMidiHdr
;
1560 #define WINE_MSM_HEADER (WM_USER+0)
1561 #define WINE_MSM_STOP (WM_USER+1)
1563 /**************************************************************************
1564 * MMSYSTEM_GetMidiStream [internal]
1566 static BOOL
MMSYSTEM_GetMidiStream(HMIDISTRM hMidiStrm
, WINE_MIDIStream
** lpMidiStrm
, WINE_MIDI
** lplpwm
)
1568 WINE_MIDI
* lpwm
= (LPWINE_MIDI
)MMDRV_Get(hMidiStrm
, MMDRV_MIDIOUT
, FALSE
);
1577 *lpMidiStrm
= (WINE_MIDIStream
*)lpwm
->mod
.rgIds
.dwStreamID
;
1579 return *lpMidiStrm
!= NULL
;
1582 /**************************************************************************
1583 * MMSYSTEM_MidiStream_Convert [internal]
1585 static DWORD
MMSYSTEM_MidiStream_Convert(WINE_MIDIStream
* lpMidiStrm
, DWORD pulse
)
1589 if (lpMidiStrm
->dwTimeDiv
== 0) {
1590 FIXME("Shouldn't happen. lpMidiStrm->dwTimeDiv = 0\n");
1591 } else if (lpMidiStrm
->dwTimeDiv
> 0x8000) { /* SMPTE, unchecked FIXME? */
1592 int nf
= -(char)HIBYTE(lpMidiStrm
->dwTimeDiv
); /* number of frames */
1593 int nsf
= LOBYTE(lpMidiStrm
->dwTimeDiv
); /* number of sub-frames */
1594 ret
= (pulse
* 1000) / (nf
* nsf
);
1596 ret
= (DWORD
)((double)pulse
* ((double)lpMidiStrm
->dwTempo
/ 1000) /
1597 (double)lpMidiStrm
->dwTimeDiv
);
1603 /**************************************************************************
1604 * MMSYSTEM_MidiStream_MessageHandler [internal]
1606 static BOOL
MMSYSTEM_MidiStream_MessageHandler(WINE_MIDIStream
* lpMidiStrm
, LPWINE_MIDI lpwm
, LPMSG msg
)
1608 LPMIDIHDR lpMidiHdr
;
1612 switch (msg
->message
) {
1614 SetEvent(lpMidiStrm
->hEvent
);
1618 /* this is not quite what MS doc says... */
1619 midiOutReset(lpMidiStrm
->hDevice
);
1620 /* empty list of already submitted buffers */
1621 for (lpMidiHdr
= lpMidiStrm
->lpMidiHdr
; lpMidiHdr
; lpMidiHdr
= (LPMIDIHDR
)lpMidiHdr
->lpNext
) {
1622 lpMidiHdr
->dwFlags
|= MHDR_DONE
;
1623 lpMidiHdr
->dwFlags
&= ~MHDR_INQUEUE
;
1625 DriverCallback(lpwm
->mod
.dwCallback
, lpMidiStrm
->wFlags
,
1626 (HDRVR
)lpMidiStrm
->hDevice
, MM_MOM_DONE
,
1627 lpwm
->mod
.dwInstance
, (DWORD
)lpMidiHdr
, 0L);
1629 lpMidiStrm
->lpMidiHdr
= 0;
1630 SetEvent(lpMidiStrm
->hEvent
);
1632 case WINE_MSM_HEADER
:
1633 /* sets initial tick count for first MIDIHDR */
1634 if (!lpMidiStrm
->dwStartTicks
)
1635 lpMidiStrm
->dwStartTicks
= GetTickCount();
1637 /* FIXME(EPP): "I don't understand the content of the first MIDIHDR sent
1638 * by native mcimidi, it doesn't look like a correct one".
1639 * this trick allows to throw it away... but I don't like it.
1640 * It looks like part of the file I'm trying to play and definitively looks
1641 * like raw midi content
1642 * I'd really like to understand why native mcimidi sends it. Perhaps a bad
1643 * synchronization issue where native mcimidi is still processing raw MIDI
1644 * content before generating MIDIEVENTs ?
1646 * 4c 04 89 3b 00 81 7c 99 3b 43 00 99 23 5e 04 89 L..;..|.;C..#^..
1647 * 3b 00 00 89 23 00 7c 99 3b 45 00 99 28 62 04 89 ;...#.|.;E..(b..
1648 * 3b 00 00 89 28 00 81 7c 99 3b 4e 00 99 23 5e 04 ;...(..|.;N..#^.
1649 * 89 3b 00 00 89 23 00 7c 99 3b 45 00 99 23 78 04 .;...#.|.;E..#x.
1650 * 89 3b 00 00 89 23 00 81 7c 99 3b 48 00 99 23 5e .;...#..|.;H..#^
1651 * 04 89 3b 00 00 89 23 00 7c 99 3b 4e 00 99 28 62 ..;...#.|.;N..(b
1652 * 04 89 3b 00 00 89 28 00 81 7c 99 39 4c 00 99 23 ..;...(..|.9L..#
1653 * 5e 04 89 39 00 00 89 23 00 82 7c 99 3b 4c 00 99 ^..9...#..|.;L..
1654 * 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 00 99 #^..;...#.|.;H..
1655 * 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b 3f 04 (b..;...(..|.;?.
1656 * 89 3b 00 1c 99 23 5e 04 89 23 00 5c 99 3b 45 00 .;...#^..#.\.;E.
1657 * 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 3b 46 .#x..;...#..|.;F
1658 * 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 ..#^..;...#.|.;H
1659 * 00 99 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b ..(b..;...(..|.;
1660 * 46 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b F..#^..;...#.|.;
1661 * 48 00 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 H..#x..;...#..|.
1662 * 3b 4c 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 ;L..#^..;...#.|.
1664 lpMidiHdr
= (LPMIDIHDR
)msg
->lParam
;
1665 lpData
= lpMidiHdr
->lpData
;
1666 TRACE("Adding %s lpMidiHdr=%p [lpData=0x%08lx dwBufferLength=%lu/%lu dwFlags=0x%08lx size=%u]\n",
1667 (lpMidiHdr
->dwFlags
& MHDR_ISSTRM
) ? "stream" : "regular", lpMidiHdr
,
1668 (DWORD
)lpMidiHdr
, lpMidiHdr
->dwBufferLength
, lpMidiHdr
->dwBytesRecorded
,
1669 lpMidiHdr
->dwFlags
, msg
->wParam
);
1671 /* dumps content of lpMidiHdr->lpData
1672 * FIXME: there should be a debug routine somewhere that already does this
1673 * I hate spreading this type of shit all around the code
1675 for (dwToGo
= 0; dwToGo
< lpMidiHdr
->dwBufferLength
; dwToGo
+= 16) {
1679 for (i
= 0; i
< min(16, lpMidiHdr
->dwBufferLength
- dwToGo
); i
++)
1680 printf("%02x ", lpData
[dwToGo
+ i
]);
1683 for (i
= 0; i
< min(16, lpMidiHdr
->dwBufferLength
- dwToGo
); i
++) {
1684 ch
= lpData
[dwToGo
+ i
];
1685 printf("%c", (ch
>= 0x20 && ch
<= 0x7F) ? ch
: '.');
1690 if (((LPMIDIEVENT
)lpData
)->dwStreamID
!= 0 &&
1691 ((LPMIDIEVENT
)lpData
)->dwStreamID
!= 0xFFFFFFFF &&
1692 ((LPMIDIEVENT
)lpData
)->dwStreamID
!= (DWORD
)lpMidiStrm
) {
1693 FIXME("Dropping bad %s lpMidiHdr (streamID=%08lx)\n",
1694 (lpMidiHdr
->dwFlags
& MHDR_ISSTRM
) ? "stream" : "regular",
1695 ((LPMIDIEVENT
)lpData
)->dwStreamID
);
1696 lpMidiHdr
->dwFlags
|= MHDR_DONE
;
1697 lpMidiHdr
->dwFlags
&= ~MHDR_INQUEUE
;
1699 DriverCallback(lpwm
->mod
.dwCallback
, lpMidiStrm
->wFlags
,
1700 (HDRVR
)lpMidiStrm
->hDevice
, MM_MOM_DONE
,
1701 lpwm
->mod
.dwInstance
, (DWORD
)lpMidiHdr
, 0L);
1705 for (lpmh
= &lpMidiStrm
->lpMidiHdr
; *lpmh
; lpmh
= (LPMIDIHDR
*)&((*lpmh
)->lpNext
));
1707 lpMidiHdr
= (LPMIDIHDR
)msg
->lParam
;
1708 lpMidiHdr
->lpNext
= 0;
1709 lpMidiHdr
->dwFlags
|= MHDR_INQUEUE
;
1710 lpMidiHdr
->dwFlags
&= MHDR_DONE
;
1711 lpMidiHdr
->dwOffset
= 0;
1715 FIXME("Unknown message %d\n", msg
->message
);
1721 /**************************************************************************
1722 * MMSYSTEM_MidiStream_Player [internal]
1724 static DWORD CALLBACK
MMSYSTEM_MidiStream_Player(LPVOID pmt
)
1726 WINE_MIDIStream
* lpMidiStrm
= pmt
;
1731 LPMIDIHDR lpMidiHdr
;
1735 TRACE("(%p)!\n", lpMidiStrm
);
1738 (lpwm
= (LPWINE_MIDI
)MMDRV_Get(lpMidiStrm
->hDevice
, MMDRV_MIDIOUT
, FALSE
)) == NULL
)
1741 /* force thread's queue creation */
1742 /* Used to be InitThreadInput16(0, 5); */
1743 /* but following works also with hack in midiStreamOpen */
1744 PeekMessageA(&msg
, 0, 0, 0, 0);
1746 /* FIXME: this next line must be called before midiStreamOut or midiStreamRestart are called */
1747 SetEvent(lpMidiStrm
->hEvent
);
1748 TRACE("Ready to go 1\n");
1749 /* thread is started in paused mode */
1750 SuspendThread(lpMidiStrm
->hThread
);
1751 TRACE("Ready to go 2\n");
1753 lpMidiStrm
->dwStartTicks
= 0;
1754 lpMidiStrm
->dwPulses
= 0;
1756 lpMidiStrm
->lpMidiHdr
= 0;
1759 lpMidiHdr
= lpMidiStrm
->lpMidiHdr
;
1761 /* for first message, block until one arrives, then process all that are available */
1762 GetMessageA(&msg
, 0, 0, 0);
1764 if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm
, lpwm
, &msg
))
1766 } while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
));
1772 lpData
= lpMidiHdr
->lpData
;
1774 me
= (LPMIDIEVENT
)(lpData
+ lpMidiHdr
->dwOffset
);
1776 /* do we have to wait ? */
1777 if (me
->dwDeltaTime
) {
1778 lpMidiStrm
->dwPositionMS
+= MMSYSTEM_MidiStream_Convert(lpMidiStrm
, me
->dwDeltaTime
);
1779 lpMidiStrm
->dwPulses
+= me
->dwDeltaTime
;
1781 dwToGo
= lpMidiStrm
->dwStartTicks
+ lpMidiStrm
->dwPositionMS
;
1783 TRACE("%ld/%ld/%ld\n", dwToGo
, GetTickCount(), me
->dwDeltaTime
);
1784 while ((dwCurrTC
= GetTickCount()) < dwToGo
) {
1785 if (MsgWaitForMultipleObjects(0, NULL
, FALSE
, dwToGo
- dwCurrTC
, QS_ALLINPUT
) == WAIT_OBJECT_0
) {
1786 /* got a message, handle it */
1787 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) {
1788 if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm
, lpwm
, &msg
))
1793 /* timeout, so me->dwDeltaTime is elapsed, can break the while loop */
1798 switch (MEVT_EVENTTYPE(me
->dwEvent
& ~MEVT_F_CALLBACK
)) {
1800 FIXME("NIY: MEVT_COMMENT\n");
1801 /* do nothing, skip bytes */
1804 FIXME("NIY: MEVT_LONGMSG, aka sending Sysex event\n");
1809 midiOutShortMsg(lpMidiStrm
->hDevice
, MEVT_EVENTPARM(me
->dwEvent
));
1812 lpMidiStrm
->dwTempo
= MEVT_EVENTPARM(me
->dwEvent
);
1817 FIXME("Unknown MEVT (0x%02x)\n", MEVT_EVENTTYPE(me
->dwEvent
& ~MEVT_F_CALLBACK
));
1820 if (me
->dwEvent
& MEVT_F_CALLBACK
) {
1821 DriverCallback(lpwm
->mod
.dwCallback
, lpMidiStrm
->wFlags
,
1822 (HDRVR
)lpMidiStrm
->hDevice
, MM_MOM_POSITIONCB
,
1823 lpwm
->mod
.dwInstance
, (LPARAM
)lpMidiHdr
, 0L);
1825 lpMidiHdr
->dwOffset
+= sizeof(MIDIEVENT
) - sizeof(me
->dwParms
);
1826 if (me
->dwEvent
& MEVT_F_LONG
)
1827 lpMidiHdr
->dwOffset
+= (MEVT_EVENTPARM(me
->dwEvent
) + 3) & ~3;
1828 if (lpMidiHdr
->dwOffset
>= lpMidiHdr
->dwBufferLength
) {
1829 /* done with this header */
1830 lpMidiHdr
->dwFlags
|= MHDR_DONE
;
1831 lpMidiHdr
->dwFlags
&= ~MHDR_INQUEUE
;
1833 lpMidiStrm
->lpMidiHdr
= (LPMIDIHDR
)lpMidiHdr
->lpNext
;
1834 DriverCallback(lpwm
->mod
.dwCallback
, lpMidiStrm
->wFlags
,
1835 (HDRVR
)lpMidiStrm
->hDevice
, MM_MOM_DONE
,
1836 lpwm
->mod
.dwInstance
, (DWORD
)lpMidiHdr
, 0L);
1841 TRACE("End of thread\n");
1843 return 0; /* for removing the warning, never executed */
1846 /**************************************************************************
1847 * MMSYSTEM_MidiStream_PostMessage [internal]
1849 static BOOL
MMSYSTEM_MidiStream_PostMessage(WINE_MIDIStream
* lpMidiStrm
, WORD msg
, DWORD pmt1
, DWORD pmt2
)
1851 if (PostThreadMessageA(lpMidiStrm
->dwThreadID
, msg
, pmt1
, pmt2
)) {
1854 ReleaseThunkLock(&count
);
1855 WaitForSingleObject(lpMidiStrm
->hEvent
, INFINITE
);
1856 RestoreThunkLock(count
);
1858 WARN("bad PostThreadMessageA\n");
1864 /**************************************************************************
1865 * midiStreamClose [WINMM.@]
1867 MMRESULT WINAPI
midiStreamClose(HMIDISTRM hMidiStrm
)
1869 WINE_MIDIStream
* lpMidiStrm
;
1871 TRACE("(%p)!\n", hMidiStrm
);
1873 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
))
1874 return MMSYSERR_INVALHANDLE
;
1876 midiStreamStop(hMidiStrm
);
1877 MMSYSTEM_MidiStream_PostMessage(lpMidiStrm
, WM_QUIT
, 0, 0);
1878 HeapFree(GetProcessHeap(), 0, lpMidiStrm
);
1879 CloseHandle(lpMidiStrm
->hEvent
);
1881 return midiOutClose((HMIDIOUT
)hMidiStrm
);
1884 /**************************************************************************
1885 * MMSYSTEM_MidiStream_Open [internal]
1887 MMRESULT
MIDI_StreamOpen(HMIDISTRM
* lphMidiStrm
, LPUINT lpuDeviceID
, DWORD cMidi
,
1888 DWORD dwCallback
, DWORD dwInstance
, DWORD fdwOpen
,
1891 WINE_MIDIStream
* lpMidiStrm
;
1893 MIDIOPENSTRMID mosm
;
1897 TRACE("(%p, %p, %ld, 0x%08lx, 0x%08lx, 0x%08lx)!\n",
1898 lphMidiStrm
, lpuDeviceID
, cMidi
, dwCallback
, dwInstance
, fdwOpen
);
1900 if (cMidi
!= 1 || lphMidiStrm
== NULL
|| lpuDeviceID
== NULL
)
1901 return MMSYSERR_INVALPARAM
;
1903 lpMidiStrm
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_MIDIStream
));
1905 return MMSYSERR_NOMEM
;
1907 lpMidiStrm
->dwTempo
= 500000;
1908 lpMidiStrm
->dwTimeDiv
= 480; /* 480 is 120 quater notes per minute *//* FIXME ??*/
1909 lpMidiStrm
->dwPositionMS
= 0;
1911 mosm
.dwStreamID
= (DWORD
)lpMidiStrm
;
1912 /* FIXME: the correct value is not allocated yet for MAPPER */
1913 mosm
.wDeviceID
= *lpuDeviceID
;
1914 lpwm
= MIDI_OutAlloc(&hMidiOut
, &dwCallback
, &dwInstance
, &fdwOpen
, 1, &mosm
, bFrom32
);
1915 lpMidiStrm
->hDevice
= hMidiOut
;
1917 *lphMidiStrm
= (HMIDISTRM
)hMidiOut
;
1919 /* FIXME: is lpuDevice initialized upon entering midiStreamOpen ? */
1920 FIXME("*lpuDeviceID=%x\n", *lpuDeviceID
);
1921 lpwm
->mld
.uDeviceID
= *lpuDeviceID
= 0;
1923 ret
= MMDRV_Open(&lpwm
->mld
, MODM_OPEN
, (DWORD
)&lpwm
->mod
, fdwOpen
);
1924 lpMidiStrm
->hEvent
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
1925 lpMidiStrm
->wFlags
= HIWORD(fdwOpen
);
1927 lpMidiStrm
->hThread
= CreateThread(NULL
, 0, MMSYSTEM_MidiStream_Player
,
1928 lpMidiStrm
, 0, &(lpMidiStrm
->dwThreadID
));
1930 if (!lpMidiStrm
->hThread
) {
1931 midiStreamClose((HMIDISTRM
)hMidiOut
);
1932 return MMSYSERR_NOMEM
;
1935 /* wait for thread to have started, and for its queue to be created */
1939 /* (Release|Restore)ThunkLock() is needed when this method is called from 16 bit code,
1940 * (meaning the Win16Lock is set), so that it's released and the 32 bit thread running
1941 * MMSYSTEM_MidiStreamPlayer can acquire Win16Lock to create its queue.
1943 ReleaseThunkLock(&count
);
1944 WaitForSingleObject(lpMidiStrm
->hEvent
, INFINITE
);
1945 RestoreThunkLock(count
);
1948 TRACE("=> (%u/%d) hMidi=%p ret=%d lpMidiStrm=%p\n",
1949 *lpuDeviceID
, lpwm
->mld
.uDeviceID
, *lphMidiStrm
, ret
, lpMidiStrm
);
1953 /**************************************************************************
1954 * midiStreamOpen [WINMM.@]
1956 MMRESULT WINAPI
midiStreamOpen(HMIDISTRM
* lphMidiStrm
, LPUINT lpuDeviceID
,
1957 DWORD cMidi
, DWORD dwCallback
,
1958 DWORD dwInstance
, DWORD fdwOpen
)
1960 return MIDI_StreamOpen(lphMidiStrm
, lpuDeviceID
, cMidi
, dwCallback
,
1961 dwInstance
, fdwOpen
, TRUE
);
1964 /**************************************************************************
1965 * midiStreamOut [WINMM.@]
1967 MMRESULT WINAPI
midiStreamOut(HMIDISTRM hMidiStrm
, LPMIDIHDR lpMidiHdr
,
1970 WINE_MIDIStream
* lpMidiStrm
;
1971 DWORD ret
= MMSYSERR_NOERROR
;
1973 TRACE("(%p, %p, %u)!\n", hMidiStrm
, lpMidiHdr
, cbMidiHdr
);
1975 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
)) {
1976 ret
= MMSYSERR_INVALHANDLE
;
1977 } else if (!lpMidiHdr
) {
1978 ret
= MMSYSERR_INVALPARAM
;
1980 if (!PostThreadMessageA(lpMidiStrm
->dwThreadID
,
1981 WINE_MSM_HEADER
, cbMidiHdr
,
1982 (DWORD
)lpMidiHdr
)) {
1983 WARN("bad PostThreadMessageA\n");
1984 ret
= MMSYSERR_ERROR
;
1990 /**************************************************************************
1991 * midiStreamPause [WINMM.@]
1993 MMRESULT WINAPI
midiStreamPause(HMIDISTRM hMidiStrm
)
1995 WINE_MIDIStream
* lpMidiStrm
;
1996 DWORD ret
= MMSYSERR_NOERROR
;
1998 TRACE("(%p)!\n", hMidiStrm
);
2000 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
)) {
2001 ret
= MMSYSERR_INVALHANDLE
;
2003 if (SuspendThread(lpMidiStrm
->hThread
) == 0xFFFFFFFF) {
2004 WARN("bad Suspend (%ld)\n", GetLastError());
2005 ret
= MMSYSERR_ERROR
;
2011 /**************************************************************************
2012 * midiStreamPosition [WINMM.@]
2014 MMRESULT WINAPI
midiStreamPosition(HMIDISTRM hMidiStrm
, LPMMTIME lpMMT
, UINT cbmmt
)
2016 WINE_MIDIStream
* lpMidiStrm
;
2017 DWORD ret
= MMSYSERR_NOERROR
;
2019 TRACE("(%p, %p, %u)!\n", hMidiStrm
, lpMMT
, cbmmt
);
2021 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
)) {
2022 ret
= MMSYSERR_INVALHANDLE
;
2023 } else if (lpMMT
== NULL
|| cbmmt
!= sizeof(MMTIME
)) {
2024 ret
= MMSYSERR_INVALPARAM
;
2026 switch (lpMMT
->wType
) {
2028 lpMMT
->u
.ms
= lpMidiStrm
->dwPositionMS
;
2029 TRACE("=> %ld ms\n", lpMMT
->u
.ms
);
2032 lpMMT
->u
.ticks
= lpMidiStrm
->dwPulses
;
2033 TRACE("=> %ld ticks\n", lpMMT
->u
.ticks
);
2036 WARN("Unsupported time type %d\n", lpMMT
->wType
);
2037 lpMMT
->wType
= TIME_MS
;
2038 ret
= MMSYSERR_INVALPARAM
;
2045 /**************************************************************************
2046 * midiStreamProperty [WINMM.@]
2048 MMRESULT WINAPI
midiStreamProperty(HMIDISTRM hMidiStrm
, LPBYTE lpPropData
, DWORD dwProperty
)
2050 WINE_MIDIStream
* lpMidiStrm
;
2051 MMRESULT ret
= MMSYSERR_NOERROR
;
2053 TRACE("(%p, %p, %lx)\n", hMidiStrm
, lpPropData
, dwProperty
);
2055 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
)) {
2056 ret
= MMSYSERR_INVALHANDLE
;
2057 } else if ((dwProperty
& (MIDIPROP_GET
|MIDIPROP_SET
)) == 0) {
2058 ret
= MMSYSERR_INVALPARAM
;
2059 } else if (dwProperty
& MIDIPROP_TEMPO
) {
2060 MIDIPROPTEMPO
* mpt
= (MIDIPROPTEMPO
*)lpPropData
;
2062 if (sizeof(MIDIPROPTEMPO
) != mpt
->cbStruct
) {
2063 ret
= MMSYSERR_INVALPARAM
;
2064 } else if (dwProperty
& MIDIPROP_SET
) {
2065 lpMidiStrm
->dwTempo
= mpt
->dwTempo
;
2066 TRACE("Setting tempo to %ld\n", mpt
->dwTempo
);
2067 } else if (dwProperty
& MIDIPROP_GET
) {
2068 mpt
->dwTempo
= lpMidiStrm
->dwTempo
;
2069 TRACE("Getting tempo <= %ld\n", mpt
->dwTempo
);
2071 } else if (dwProperty
& MIDIPROP_TIMEDIV
) {
2072 MIDIPROPTIMEDIV
* mptd
= (MIDIPROPTIMEDIV
*)lpPropData
;
2074 if (sizeof(MIDIPROPTIMEDIV
) != mptd
->cbStruct
) {
2075 ret
= MMSYSERR_INVALPARAM
;
2076 } else if (dwProperty
& MIDIPROP_SET
) {
2077 lpMidiStrm
->dwTimeDiv
= mptd
->dwTimeDiv
;
2078 TRACE("Setting time div to %ld\n", mptd
->dwTimeDiv
);
2079 } else if (dwProperty
& MIDIPROP_GET
) {
2080 mptd
->dwTimeDiv
= lpMidiStrm
->dwTimeDiv
;
2081 TRACE("Getting time div <= %ld\n", mptd
->dwTimeDiv
);
2084 ret
= MMSYSERR_INVALPARAM
;
2090 /**************************************************************************
2091 * midiStreamRestart [WINMM.@]
2093 MMRESULT WINAPI
midiStreamRestart(HMIDISTRM hMidiStrm
)
2095 WINE_MIDIStream
* lpMidiStrm
;
2096 MMRESULT ret
= MMSYSERR_NOERROR
;
2098 TRACE("(%p)!\n", hMidiStrm
);
2100 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
)) {
2101 ret
= MMSYSERR_INVALHANDLE
;
2105 /* since we increase the thread suspend count on each midiStreamPause
2106 * there may be a need for several midiStreamResume
2109 ret
= ResumeThread(lpMidiStrm
->hThread
);
2110 } while (ret
!= 0xFFFFFFFF && ret
!= 0);
2111 if (ret
== 0xFFFFFFFF) {
2112 WARN("bad Resume (%ld)\n", GetLastError());
2113 ret
= MMSYSERR_ERROR
;
2115 lpMidiStrm
->dwStartTicks
= GetTickCount() - lpMidiStrm
->dwPositionMS
;
2121 /**************************************************************************
2122 * midiStreamStop [WINMM.@]
2124 MMRESULT WINAPI
midiStreamStop(HMIDISTRM hMidiStrm
)
2126 WINE_MIDIStream
* lpMidiStrm
;
2127 MMRESULT ret
= MMSYSERR_NOERROR
;
2129 TRACE("(%p)!\n", hMidiStrm
);
2131 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
)) {
2132 ret
= MMSYSERR_INVALHANDLE
;
2134 /* in case stream has been paused... FIXME is the current state correct ? */
2135 midiStreamRestart(hMidiStrm
);
2136 MMSYSTEM_MidiStream_PostMessage(lpMidiStrm
, WINE_MSM_STOP
, 0, 0);
2141 UINT
WAVE_Open(HANDLE
* lphndl
, UINT uDeviceID
, UINT uType
,
2142 const LPWAVEFORMATEX lpFormat
, DWORD dwCallback
,
2143 DWORD dwInstance
, DWORD dwFlags
, BOOL bFrom32
)
2147 DWORD dwRet
= MMSYSERR_NOERROR
;
2150 TRACE("(%p, %d, %s, %p, %08lX, %08lX, %08lX, %d);\n",
2151 lphndl
, (int)uDeviceID
, (uType
==MMDRV_WAVEOUT
)?"Out":"In", lpFormat
, dwCallback
,
2152 dwInstance
, dwFlags
, bFrom32
?32:16);
2154 if (dwFlags
& WAVE_FORMAT_QUERY
) TRACE("WAVE_FORMAT_QUERY requested !\n");
2156 if (lpFormat
== NULL
) return WAVERR_BADFORMAT
;
2157 if ((dwFlags
& WAVE_MAPPED
) && (uDeviceID
== (UINT
)-1))
2158 return MMSYSERR_INVALPARAM
;
2160 TRACE("wFormatTag=%u, nChannels=%u, nSamplesPerSec=%lu, nAvgBytesPerSec=%lu, nBlockAlign=%u, wBitsPerSample=%u, cbSize=%u\n",
2161 lpFormat
->wFormatTag
, lpFormat
->nChannels
, lpFormat
->nSamplesPerSec
,
2162 lpFormat
->nAvgBytesPerSec
, lpFormat
->nBlockAlign
, lpFormat
->wBitsPerSample
, lpFormat
->cbSize
);
2164 if ((wmld
= MMDRV_Alloc(sizeof(WINE_WAVE
), uType
, &handle
,
2165 &dwFlags
, &dwCallback
, &dwInstance
, bFrom32
)) == NULL
)
2166 return MMSYSERR_NOMEM
;
2169 wod
.lpFormat
= lpFormat
; /* should the struct be copied iso pointer? */
2170 wod
.dwCallback
= dwCallback
;
2171 wod
.dwInstance
= dwInstance
;
2174 TRACE("cb=%08lx\n", wod
.dwCallback
);
2177 if (dwFlags
& WAVE_MAPPED
) {
2178 wod
.uMappedDeviceID
= uDeviceID
;
2179 uDeviceID
= WAVE_MAPPER
;
2181 wod
.uMappedDeviceID
= -1;
2183 wmld
->uDeviceID
= uDeviceID
;
2185 dwRet
= MMDRV_Open(wmld
, (uType
== MMDRV_WAVEOUT
) ? WODM_OPEN
: WIDM_OPEN
,
2186 (DWORD
)&wod
, dwFlags
);
2188 if (dwRet
!= WAVERR_BADFORMAT
||
2189 (dwFlags
& (WAVE_MAPPED
|WAVE_FORMAT_DIRECT
)) != 0) break;
2190 /* if we ask for a format which isn't supported by the physical driver,
2191 * let's try to map it through the wave mapper (except, if we already tried
2192 * or user didn't allow us to use acm codecs)
2194 dwFlags
|= WAVE_MAPPED
;
2195 /* we shall loop only one */
2198 if ((dwFlags
& WAVE_FORMAT_QUERY
) || dwRet
!= MMSYSERR_NOERROR
) {
2199 MMDRV_Free(handle
, wmld
);
2203 if (lphndl
!= NULL
) *lphndl
= handle
;
2204 TRACE("=> %ld hWave=%p\n", dwRet
, handle
);
2209 /**************************************************************************
2210 * waveOutGetNumDevs [WINMM.@]
2212 UINT WINAPI
waveOutGetNumDevs(void)
2214 return MMDRV_GetNum(MMDRV_WAVEOUT
);
2217 /**************************************************************************
2218 * waveOutGetDevCapsA [WINMM.@]
2220 UINT WINAPI
waveOutGetDevCapsA(UINT uDeviceID
, LPWAVEOUTCAPSA lpCaps
,
2225 TRACE("(%u %p %u)!\n", uDeviceID
, lpCaps
, uSize
);
2227 if (lpCaps
== NULL
) return MMSYSERR_INVALPARAM
;
2229 if ((wmld
= MMDRV_Get((HANDLE
)uDeviceID
, MMDRV_WAVEOUT
, TRUE
)) == NULL
)
2230 return MMSYSERR_BADDEVICEID
;
2232 return MMDRV_Message(wmld
, WODM_GETDEVCAPS
, (DWORD
)lpCaps
, uSize
, TRUE
);
2236 /**************************************************************************
2237 * waveOutGetDevCapsW [WINMM.@]
2239 UINT WINAPI
waveOutGetDevCapsW(UINT uDeviceID
, LPWAVEOUTCAPSW lpCaps
,
2245 if (lpCaps
== NULL
) return MMSYSERR_INVALPARAM
;
2247 ret
= waveOutGetDevCapsA(uDeviceID
, &wocA
, sizeof(wocA
));
2249 if (ret
== MMSYSERR_NOERROR
) {
2250 lpCaps
->wMid
= wocA
.wMid
;
2251 lpCaps
->wPid
= wocA
.wPid
;
2252 lpCaps
->vDriverVersion
= wocA
.vDriverVersion
;
2253 MultiByteToWideChar( CP_ACP
, 0, wocA
.szPname
, -1, lpCaps
->szPname
,
2254 sizeof(lpCaps
->szPname
)/sizeof(WCHAR
) );
2255 lpCaps
->dwFormats
= wocA
.dwFormats
;
2256 lpCaps
->wChannels
= wocA
.wChannels
;
2257 lpCaps
->dwSupport
= wocA
.dwSupport
;
2262 /**************************************************************************
2263 * WAVE_GetErrorText [internal]
2265 static UINT16
WAVE_GetErrorText(UINT16 uError
, LPSTR lpText
, UINT16 uSize
)
2267 UINT16 ret
= MMSYSERR_BADERRNUM
;
2269 if (lpText
== NULL
) {
2270 ret
= MMSYSERR_INVALPARAM
;
2271 } else if (uSize
== 0) {
2272 ret
= MMSYSERR_NOERROR
;
2274 /* test has been removed 'coz MMSYSERR_BASE is 0, and gcc did emit
2275 * a warning for the test was always true */
2276 (/*uError >= MMSYSERR_BASE && */uError
<= MMSYSERR_LASTERROR
) ||
2277 (uError
>= WAVERR_BASE
&& uError
<= WAVERR_LASTERROR
)) {
2279 if (LoadStringA(WINMM_IData
->hWinMM32Instance
,
2280 uError
, lpText
, uSize
) > 0) {
2281 ret
= MMSYSERR_NOERROR
;
2287 /**************************************************************************
2288 * waveOutGetErrorTextA [WINMM.@]
2290 UINT WINAPI
waveOutGetErrorTextA(UINT uError
, LPSTR lpText
, UINT uSize
)
2292 return WAVE_GetErrorText(uError
, lpText
, uSize
);
2295 /**************************************************************************
2296 * waveOutGetErrorTextW [WINMM.@]
2298 UINT WINAPI
waveOutGetErrorTextW(UINT uError
, LPWSTR lpText
, UINT uSize
)
2300 LPSTR xstr
= HeapAlloc(GetProcessHeap(), 0, uSize
);
2301 UINT ret
= WAVE_GetErrorText(uError
, xstr
, uSize
);
2303 MultiByteToWideChar( CP_ACP
, 0, xstr
, -1, lpText
, uSize
);
2304 HeapFree(GetProcessHeap(), 0, xstr
);
2308 /**************************************************************************
2309 * waveOutOpen [WINMM.@]
2310 * All the args/structs have the same layout as the win16 equivalents
2312 UINT WINAPI
waveOutOpen(HWAVEOUT
* lphWaveOut
, UINT uDeviceID
,
2313 const LPWAVEFORMATEX lpFormat
, DWORD dwCallback
,
2314 DWORD dwInstance
, DWORD dwFlags
)
2316 return WAVE_Open((HANDLE
*)lphWaveOut
, uDeviceID
, MMDRV_WAVEOUT
, lpFormat
,
2317 dwCallback
, dwInstance
, dwFlags
, TRUE
);
2320 /**************************************************************************
2321 * waveOutClose [WINMM.@]
2323 UINT WINAPI
waveOutClose(HWAVEOUT hWaveOut
)
2328 TRACE("(%p)\n", hWaveOut
);
2330 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2331 return MMSYSERR_INVALHANDLE
;
2333 dwRet
= MMDRV_Close(wmld
, WODM_CLOSE
);
2334 MMDRV_Free(hWaveOut
, wmld
);
2339 /**************************************************************************
2340 * waveOutPrepareHeader [WINMM.@]
2342 UINT WINAPI
waveOutPrepareHeader(HWAVEOUT hWaveOut
,
2343 WAVEHDR
* lpWaveOutHdr
, UINT uSize
)
2347 TRACE("(%p, %p, %u);\n", hWaveOut
, lpWaveOutHdr
, uSize
);
2349 if (lpWaveOutHdr
== NULL
) return MMSYSERR_INVALPARAM
;
2351 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2352 return MMSYSERR_INVALHANDLE
;
2354 return MMDRV_Message(wmld
, WODM_PREPARE
, (DWORD
)lpWaveOutHdr
, uSize
, TRUE
);
2357 /**************************************************************************
2358 * waveOutUnprepareHeader [WINMM.@]
2360 UINT WINAPI
waveOutUnprepareHeader(HWAVEOUT hWaveOut
,
2361 LPWAVEHDR lpWaveOutHdr
, UINT uSize
)
2365 TRACE("(%p, %p, %u);\n", hWaveOut
, lpWaveOutHdr
, uSize
);
2367 if (!(lpWaveOutHdr
->dwFlags
& WHDR_PREPARED
)) {
2368 return MMSYSERR_NOERROR
;
2371 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2372 return MMSYSERR_INVALHANDLE
;
2374 return MMDRV_Message(wmld
, WODM_UNPREPARE
, (DWORD
)lpWaveOutHdr
, uSize
, TRUE
);
2377 /**************************************************************************
2378 * waveOutWrite [WINMM.@]
2380 UINT WINAPI
waveOutWrite(HWAVEOUT hWaveOut
, LPWAVEHDR lpWaveOutHdr
,
2385 TRACE("(%p, %p, %u);\n", hWaveOut
, lpWaveOutHdr
, uSize
);
2387 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2388 return MMSYSERR_INVALHANDLE
;
2390 return MMDRV_Message(wmld
, WODM_WRITE
, (DWORD
)lpWaveOutHdr
, uSize
, TRUE
);
2393 /**************************************************************************
2394 * waveOutBreakLoop [WINMM.@]
2396 UINT WINAPI
waveOutBreakLoop(HWAVEOUT hWaveOut
)
2400 TRACE("(%p);\n", hWaveOut
);
2402 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2403 return MMSYSERR_INVALHANDLE
;
2404 return MMDRV_Message(wmld
, WODM_BREAKLOOP
, 0L, 0L, TRUE
);
2407 /**************************************************************************
2408 * waveOutPause [WINMM.@]
2410 UINT WINAPI
waveOutPause(HWAVEOUT hWaveOut
)
2414 TRACE("(%p);\n", hWaveOut
);
2416 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2417 return MMSYSERR_INVALHANDLE
;
2418 return MMDRV_Message(wmld
, WODM_PAUSE
, 0L, 0L, TRUE
);
2421 /**************************************************************************
2422 * waveOutReset [WINMM.@]
2424 UINT WINAPI
waveOutReset(HWAVEOUT hWaveOut
)
2428 TRACE("(%p);\n", hWaveOut
);
2430 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2431 return MMSYSERR_INVALHANDLE
;
2432 return MMDRV_Message(wmld
, WODM_RESET
, 0L, 0L, TRUE
);
2435 /**************************************************************************
2436 * waveOutRestart [WINMM.@]
2438 UINT WINAPI
waveOutRestart(HWAVEOUT hWaveOut
)
2442 TRACE("(%p);\n", hWaveOut
);
2444 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2445 return MMSYSERR_INVALHANDLE
;
2446 return MMDRV_Message(wmld
, WODM_RESTART
, 0L, 0L, TRUE
);
2449 /**************************************************************************
2450 * waveOutGetPosition [WINMM.@]
2452 UINT WINAPI
waveOutGetPosition(HWAVEOUT hWaveOut
, LPMMTIME lpTime
,
2457 TRACE("(%p, %p, %u);\n", hWaveOut
, lpTime
, uSize
);
2459 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2460 return MMSYSERR_INVALHANDLE
;
2462 return MMDRV_Message(wmld
, WODM_GETPOS
, (DWORD
)lpTime
, uSize
, TRUE
);
2465 /**************************************************************************
2466 * waveOutGetPitch [WINMM.@]
2468 UINT WINAPI
waveOutGetPitch(HWAVEOUT hWaveOut
, LPDWORD lpdw
)
2472 TRACE("(%p, %08lx);\n", hWaveOut
, (DWORD
)lpdw
);
2474 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2475 return MMSYSERR_INVALHANDLE
;
2476 return MMDRV_Message(wmld
, WODM_GETPITCH
, (DWORD
)lpdw
, 0L, TRUE
);
2479 /**************************************************************************
2480 * waveOutSetPitch [WINMM.@]
2482 UINT WINAPI
waveOutSetPitch(HWAVEOUT hWaveOut
, DWORD dw
)
2486 TRACE("(%p, %08lx);\n", hWaveOut
, (DWORD
)dw
);
2488 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2489 return MMSYSERR_INVALHANDLE
;
2490 return MMDRV_Message(wmld
, WODM_SETPITCH
, dw
, 0L, TRUE
);
2493 /**************************************************************************
2494 * waveOutGetPlaybackRate [WINMM.@]
2496 UINT WINAPI
waveOutGetPlaybackRate(HWAVEOUT hWaveOut
, LPDWORD lpdw
)
2500 TRACE("(%p, %08lx);\n", hWaveOut
, (DWORD
)lpdw
);
2502 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2503 return MMSYSERR_INVALHANDLE
;
2504 return MMDRV_Message(wmld
, WODM_GETPLAYBACKRATE
, (DWORD
)lpdw
, 0L, TRUE
);
2507 /**************************************************************************
2508 * waveOutSetPlaybackRate [WINMM.@]
2510 UINT WINAPI
waveOutSetPlaybackRate(HWAVEOUT hWaveOut
, DWORD dw
)
2514 TRACE("(%p, %08lx);\n", hWaveOut
, (DWORD
)dw
);
2516 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2517 return MMSYSERR_INVALHANDLE
;
2518 return MMDRV_Message(wmld
, WODM_SETPLAYBACKRATE
, dw
, 0L, TRUE
);
2521 /**************************************************************************
2522 * waveOutGetVolume [WINMM.@]
2524 UINT WINAPI
waveOutGetVolume(HWAVEOUT hWaveOut
, LPDWORD lpdw
)
2528 TRACE("(%p, %08lx);\n", hWaveOut
, (DWORD
)lpdw
);
2530 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, TRUE
)) == NULL
)
2531 return MMSYSERR_INVALHANDLE
;
2533 return MMDRV_Message(wmld
, WODM_GETVOLUME
, (DWORD
)lpdw
, 0L, TRUE
);
2536 /**************************************************************************
2537 * waveOutSetVolume [WINMM.@]
2539 UINT WINAPI
waveOutSetVolume(HWAVEOUT hWaveOut
, DWORD dw
)
2543 TRACE("(%p, %08lx);\n", hWaveOut
, dw
);
2545 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, TRUE
)) == NULL
)
2546 return MMSYSERR_INVALHANDLE
;
2548 return MMDRV_Message(wmld
, WODM_SETVOLUME
, dw
, 0L, TRUE
);
2551 /**************************************************************************
2552 * waveOutGetID [WINMM.@]
2554 UINT WINAPI
waveOutGetID(HWAVEOUT hWaveOut
, UINT
* lpuDeviceID
)
2558 TRACE("(%p, %p);\n", hWaveOut
, lpuDeviceID
);
2560 if (lpuDeviceID
== NULL
) return MMSYSERR_INVALHANDLE
;
2562 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2563 return MMSYSERR_INVALHANDLE
;
2565 *lpuDeviceID
= wmld
->uDeviceID
;
2569 /**************************************************************************
2570 * waveOutMessage [WINMM.@]
2572 DWORD WINAPI
waveOutMessage(HWAVEOUT hWaveOut
, UINT uMessage
,
2573 DWORD dwParam1
, DWORD dwParam2
)
2577 TRACE("(%p, %u, %ld, %ld)\n", hWaveOut
, uMessage
, dwParam1
, dwParam2
);
2579 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
) {
2580 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, TRUE
)) != NULL
) {
2581 return MMDRV_PhysicalFeatures(wmld
, uMessage
, dwParam1
, dwParam2
);
2583 return MMSYSERR_INVALHANDLE
;
2587 if (uMessage
< DRVM_IOCTL
|| (uMessage
>= DRVM_IOCTL_LAST
&& uMessage
< DRVM_MAPPER
))
2588 return MMSYSERR_INVALPARAM
;
2590 return MMDRV_Message(wmld
, uMessage
, dwParam1
, dwParam2
, TRUE
);
2593 /**************************************************************************
2594 * waveInGetNumDevs [WINMM.@]
2596 UINT WINAPI
waveInGetNumDevs(void)
2598 return MMDRV_GetNum(MMDRV_WAVEIN
);
2601 /**************************************************************************
2602 * waveInGetDevCapsW [WINMM.@]
2604 UINT WINAPI
waveInGetDevCapsW(UINT uDeviceID
, LPWAVEINCAPSW lpCaps
, UINT uSize
)
2607 UINT ret
= waveInGetDevCapsA(uDeviceID
, &wicA
, uSize
);
2609 if (ret
== MMSYSERR_NOERROR
) {
2610 lpCaps
->wMid
= wicA
.wMid
;
2611 lpCaps
->wPid
= wicA
.wPid
;
2612 lpCaps
->vDriverVersion
= wicA
.vDriverVersion
;
2613 MultiByteToWideChar( CP_ACP
, 0, wicA
.szPname
, -1, lpCaps
->szPname
,
2614 sizeof(lpCaps
->szPname
)/sizeof(WCHAR
) );
2615 lpCaps
->dwFormats
= wicA
.dwFormats
;
2616 lpCaps
->wChannels
= wicA
.wChannels
;
2622 /**************************************************************************
2623 * waveInGetDevCapsA [WINMM.@]
2625 UINT WINAPI
waveInGetDevCapsA(UINT uDeviceID
, LPWAVEINCAPSA lpCaps
, UINT uSize
)
2629 TRACE("(%u %p %u)!\n", uDeviceID
, lpCaps
, uSize
);
2631 if ((wmld
= MMDRV_Get((HANDLE
)uDeviceID
, MMDRV_WAVEIN
, TRUE
)) == NULL
)
2632 return MMSYSERR_BADDEVICEID
;
2634 return MMDRV_Message(wmld
, WIDM_GETDEVCAPS
, (DWORD
)lpCaps
, uSize
, TRUE
);
2637 /**************************************************************************
2638 * waveInGetErrorTextA [WINMM.@]
2640 UINT WINAPI
waveInGetErrorTextA(UINT uError
, LPSTR lpText
, UINT uSize
)
2642 return WAVE_GetErrorText(uError
, lpText
, uSize
);
2645 /**************************************************************************
2646 * waveInGetErrorTextW [WINMM.@]
2648 UINT WINAPI
waveInGetErrorTextW(UINT uError
, LPWSTR lpText
, UINT uSize
)
2650 LPSTR txt
= HeapAlloc(GetProcessHeap(), 0, uSize
);
2651 UINT ret
= WAVE_GetErrorText(uError
, txt
, uSize
);
2653 MultiByteToWideChar( CP_ACP
, 0, txt
, -1, lpText
, uSize
);
2654 HeapFree(GetProcessHeap(), 0, txt
);
2658 /**************************************************************************
2659 * waveInOpen [WINMM.@]
2661 UINT WINAPI
waveInOpen(HWAVEIN
* lphWaveIn
, UINT uDeviceID
,
2662 const LPWAVEFORMATEX lpFormat
, DWORD dwCallback
,
2663 DWORD dwInstance
, DWORD dwFlags
)
2665 return WAVE_Open((HANDLE
*)lphWaveIn
, uDeviceID
, MMDRV_WAVEIN
, lpFormat
,
2666 dwCallback
, dwInstance
, dwFlags
, TRUE
);
2669 /**************************************************************************
2670 * waveInClose [WINMM.@]
2672 UINT WINAPI
waveInClose(HWAVEIN hWaveIn
)
2677 TRACE("(%p)\n", hWaveIn
);
2679 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
)
2680 return MMSYSERR_INVALHANDLE
;
2682 dwRet
= MMDRV_Message(wmld
, WIDM_CLOSE
, 0L, 0L, TRUE
);
2683 MMDRV_Free(hWaveIn
, wmld
);
2687 /**************************************************************************
2688 * waveInPrepareHeader [WINMM.@]
2690 UINT WINAPI
waveInPrepareHeader(HWAVEIN hWaveIn
, WAVEHDR
* lpWaveInHdr
,
2695 TRACE("(%p, %p, %u);\n", hWaveIn
, lpWaveInHdr
, uSize
);
2697 if (lpWaveInHdr
== NULL
) return MMSYSERR_INVALPARAM
;
2698 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
)
2699 return MMSYSERR_INVALHANDLE
;
2701 lpWaveInHdr
->dwBytesRecorded
= 0;
2703 return MMDRV_Message(wmld
, WIDM_PREPARE
, (DWORD
)lpWaveInHdr
, uSize
, TRUE
);
2706 /**************************************************************************
2707 * waveInUnprepareHeader [WINMM.@]
2709 UINT WINAPI
waveInUnprepareHeader(HWAVEIN hWaveIn
, WAVEHDR
* lpWaveInHdr
,
2714 TRACE("(%p, %p, %u);\n", hWaveIn
, lpWaveInHdr
, uSize
);
2716 if (lpWaveInHdr
== NULL
) return MMSYSERR_INVALPARAM
;
2717 if (!(lpWaveInHdr
->dwFlags
& WHDR_PREPARED
)) {
2718 return MMSYSERR_NOERROR
;
2721 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
)
2722 return MMSYSERR_INVALHANDLE
;
2724 return MMDRV_Message(wmld
, WIDM_UNPREPARE
, (DWORD
)lpWaveInHdr
, uSize
, TRUE
);
2727 /**************************************************************************
2728 * waveInAddBuffer [WINMM.@]
2730 UINT WINAPI
waveInAddBuffer(HWAVEIN hWaveIn
,
2731 WAVEHDR
* lpWaveInHdr
, UINT uSize
)
2735 TRACE("(%p, %p, %u);\n", hWaveIn
, lpWaveInHdr
, uSize
);
2737 if (lpWaveInHdr
== NULL
) return MMSYSERR_INVALPARAM
;
2738 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
)
2739 return MMSYSERR_INVALHANDLE
;
2741 return MMDRV_Message(wmld
, WIDM_ADDBUFFER
, (DWORD
)lpWaveInHdr
, uSize
, TRUE
);
2744 /**************************************************************************
2745 * waveInReset [WINMM.@]
2747 UINT WINAPI
waveInReset(HWAVEIN hWaveIn
)
2751 TRACE("(%p);\n", hWaveIn
);
2753 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
)
2754 return MMSYSERR_INVALHANDLE
;
2756 return MMDRV_Message(wmld
, WIDM_RESET
, 0L, 0L, TRUE
);
2759 /**************************************************************************
2760 * waveInStart [WINMM.@]
2762 UINT WINAPI
waveInStart(HWAVEIN hWaveIn
)
2766 TRACE("(%p);\n", hWaveIn
);
2768 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
)
2769 return MMSYSERR_INVALHANDLE
;
2771 return MMDRV_Message(wmld
, WIDM_START
, 0L, 0L, TRUE
);
2774 /**************************************************************************
2775 * waveInStop [WINMM.@]
2777 UINT WINAPI
waveInStop(HWAVEIN hWaveIn
)
2781 TRACE("(%p);\n", hWaveIn
);
2783 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
)
2784 return MMSYSERR_INVALHANDLE
;
2786 return MMDRV_Message(wmld
,WIDM_STOP
, 0L, 0L, TRUE
);
2789 /**************************************************************************
2790 * waveInGetPosition [WINMM.@]
2792 UINT WINAPI
waveInGetPosition(HWAVEIN hWaveIn
, LPMMTIME lpTime
,
2797 TRACE("(%p, %p, %u);\n", hWaveIn
, lpTime
, uSize
);
2799 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
)
2800 return MMSYSERR_INVALHANDLE
;
2802 return MMDRV_Message(wmld
, WIDM_GETPOS
, (DWORD
)lpTime
, uSize
, TRUE
);
2805 /**************************************************************************
2806 * waveInGetID [WINMM.@]
2808 UINT WINAPI
waveInGetID(HWAVEIN hWaveIn
, UINT
* lpuDeviceID
)
2812 TRACE("(%p, %p);\n", hWaveIn
, lpuDeviceID
);
2814 if (lpuDeviceID
== NULL
) return MMSYSERR_INVALHANDLE
;
2816 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
)
2817 return MMSYSERR_INVALHANDLE
;
2819 *lpuDeviceID
= wmld
->uDeviceID
;
2820 return MMSYSERR_NOERROR
;
2823 /**************************************************************************
2824 * waveInMessage [WINMM.@]
2826 DWORD WINAPI
waveInMessage(HWAVEIN hWaveIn
, UINT uMessage
,
2827 DWORD dwParam1
, DWORD dwParam2
)
2831 TRACE("(%p, %u, %ld, %ld)\n", hWaveIn
, uMessage
, dwParam1
, dwParam2
);
2833 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
) {
2834 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, TRUE
)) != NULL
) {
2835 return MMDRV_PhysicalFeatures(wmld
, uMessage
, dwParam1
, dwParam2
);
2837 return MMSYSERR_INVALHANDLE
;
2841 if (uMessage
< DRVM_IOCTL
|| (uMessage
>= DRVM_IOCTL_LAST
&& uMessage
< DRVM_MAPPER
))
2842 return MMSYSERR_INVALPARAM
;
2845 return MMDRV_Message(wmld
, uMessage
, dwParam1
, dwParam2
, TRUE
);