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
34 #define NONAMELESSUNION
35 #define NONAMELESSSTRUCT
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(winmm
);
49 /******************************************************************
52 * Internal wrapper to call USER.UserYield16 (in fact through a Wine only export from USER32).
54 static void MyUserYield(void)
56 HMODULE mod
= GetModuleHandleA( "user32.dll" );
59 FARPROC proc
= GetProcAddress( mod
, "UserYield16" );
64 /* ========================================================================
65 * G L O B A L S E T T I N G S
66 * ========================================================================*/
68 LPWINE_MM_IDATA WINMM_IData
/* = NULL */;
70 /**************************************************************************
71 * WINMM_CreateIData [internal]
73 static BOOL
WINMM_CreateIData(HINSTANCE hInstDLL
)
75 WINMM_IData
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WINE_MM_IDATA
));
79 WINMM_IData
->hWinMM32Instance
= hInstDLL
;
80 InitializeCriticalSection(&WINMM_IData
->cs
);
81 WINMM_IData
->cs
.DebugInfo
= (void*)__FILE__
": WinMM";
82 WINMM_IData
->psStopEvent
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
83 WINMM_IData
->psLastEvent
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
84 TRACE("Created IData (%p)\n", WINMM_IData
);
88 /**************************************************************************
89 * WINMM_DeleteIData [internal]
91 static void WINMM_DeleteIData(void)
96 /* FIXME: should also free content and resources allocated
97 * inside WINMM_IData */
98 CloseHandle(WINMM_IData
->psStopEvent
);
99 CloseHandle(WINMM_IData
->psLastEvent
);
100 DeleteCriticalSection(&WINMM_IData
->cs
);
101 HeapFree(GetProcessHeap(), 0, WINMM_IData
);
106 /******************************************************************
110 static HANDLE (WINAPI
*pGetModuleHandle16
)(LPCSTR
);
111 static DWORD (WINAPI
*pLoadLibrary16
)(LPCSTR
);
113 BOOL
WINMM_CheckForMMSystem(void)
115 /* 0 is not checked yet, -1 is not present, 1 is present */
116 static int loaded
/* = 0 */;
120 HANDLE h
= GetModuleHandleA("kernel32");
124 pGetModuleHandle16
= (void*)GetProcAddress(h
, "GetModuleHandle16");
125 pLoadLibrary16
= (void*)GetProcAddress(h
, "LoadLibrary16");
126 if (pGetModuleHandle16
&& pLoadLibrary16
&&
127 (pGetModuleHandle16("MMSYSTEM.DLL") || pLoadLibrary16("MMSYSTEM.DLL")))
134 /**************************************************************************
135 * DllMain (WINMM.init)
137 * WINMM DLL entry point
140 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID fImpLoad
)
142 TRACE("%p 0x%lx %p\n", hInstDLL
, fdwReason
, fImpLoad
);
145 case DLL_PROCESS_ATTACH
:
146 DisableThreadLibraryCalls(hInstDLL
);
148 if (!WINMM_CreateIData(hInstDLL
))
150 if (!MCI_Init() || !MMDRV_Init()) {
155 case DLL_PROCESS_DETACH
:
156 /* close all opened MCI drivers */
157 MCI_SendCommand(MCI_ALL_DEVICE_ID
, MCI_CLOSE
, MCI_WAIT
, 0L, TRUE
);
159 /* now unload all remaining drivers... */
168 /**************************************************************************
169 * Mixer devices. New to Win95
172 /**************************************************************************
173 * find out the real mixer ID depending on hmix (depends on dwFlags)
175 static LPWINE_MIXER
MIXER_GetDev(HMIXEROBJ hmix
, DWORD dwFlags
)
177 LPWINE_MIXER lpwm
= NULL
;
179 switch (dwFlags
& 0xF0000000ul
) {
180 case MIXER_OBJECTF_MIXER
:
181 lpwm
= (LPWINE_MIXER
)MMDRV_Get(hmix
, MMDRV_MIXER
, TRUE
);
183 case MIXER_OBJECTF_HMIXER
:
184 lpwm
= (LPWINE_MIXER
)MMDRV_Get(hmix
, MMDRV_MIXER
, FALSE
);
186 case MIXER_OBJECTF_WAVEOUT
:
187 lpwm
= (LPWINE_MIXER
)MMDRV_GetRelated(hmix
, MMDRV_WAVEOUT
, TRUE
, MMDRV_MIXER
);
189 case MIXER_OBJECTF_HWAVEOUT
:
190 lpwm
= (LPWINE_MIXER
)MMDRV_GetRelated(hmix
, MMDRV_WAVEOUT
, FALSE
, MMDRV_MIXER
);
192 case MIXER_OBJECTF_WAVEIN
:
193 lpwm
= (LPWINE_MIXER
)MMDRV_GetRelated(hmix
, MMDRV_WAVEIN
, TRUE
, MMDRV_MIXER
);
195 case MIXER_OBJECTF_HWAVEIN
:
196 lpwm
= (LPWINE_MIXER
)MMDRV_GetRelated(hmix
, MMDRV_WAVEIN
, FALSE
, MMDRV_MIXER
);
198 case MIXER_OBJECTF_MIDIOUT
:
199 lpwm
= (LPWINE_MIXER
)MMDRV_GetRelated(hmix
, MMDRV_MIDIOUT
, TRUE
, MMDRV_MIXER
);
201 case MIXER_OBJECTF_HMIDIOUT
:
202 lpwm
= (LPWINE_MIXER
)MMDRV_GetRelated(hmix
, MMDRV_MIDIOUT
, FALSE
, MMDRV_MIXER
);
204 case MIXER_OBJECTF_MIDIIN
:
205 lpwm
= (LPWINE_MIXER
)MMDRV_GetRelated(hmix
, MMDRV_MIDIIN
, TRUE
, MMDRV_MIXER
);
207 case MIXER_OBJECTF_HMIDIIN
:
208 lpwm
= (LPWINE_MIXER
)MMDRV_GetRelated(hmix
, MMDRV_MIDIIN
, FALSE
, MMDRV_MIXER
);
210 case MIXER_OBJECTF_AUX
:
211 lpwm
= (LPWINE_MIXER
)MMDRV_GetRelated(hmix
, MMDRV_AUX
, TRUE
, MMDRV_MIXER
);
214 FIXME("Unsupported flag (%08lx)\n", dwFlags
& 0xF0000000ul
);
220 /**************************************************************************
221 * mixerGetNumDevs [WINMM.@]
223 UINT WINAPI
mixerGetNumDevs(void)
225 return MMDRV_GetNum(MMDRV_MIXER
);
228 /**************************************************************************
229 * mixerGetDevCapsA [WINMM.@]
231 UINT WINAPI
mixerGetDevCapsA(UINT devid
, LPMIXERCAPSA mixcaps
, UINT size
)
235 if ((wmld
= MMDRV_Get((HANDLE
)devid
, MMDRV_MIXER
, TRUE
)) == NULL
)
236 return MMSYSERR_BADDEVICEID
;
238 return MMDRV_Message(wmld
, MXDM_GETDEVCAPS
, (DWORD
)mixcaps
, size
, TRUE
);
241 /**************************************************************************
242 * mixerGetDevCapsW [WINMM.@]
244 UINT WINAPI
mixerGetDevCapsW(UINT devid
, LPMIXERCAPSW mixcaps
, UINT size
)
247 UINT ret
= mixerGetDevCapsA(devid
, &micA
, sizeof(micA
));
249 if (ret
== MMSYSERR_NOERROR
) {
250 mixcaps
->wMid
= micA
.wMid
;
251 mixcaps
->wPid
= micA
.wPid
;
252 mixcaps
->vDriverVersion
= micA
.vDriverVersion
;
253 MultiByteToWideChar( CP_ACP
, 0, micA
.szPname
, -1, mixcaps
->szPname
,
254 sizeof(mixcaps
->szPname
)/sizeof(WCHAR
) );
255 mixcaps
->fdwSupport
= micA
.fdwSupport
;
256 mixcaps
->cDestinations
= micA
.cDestinations
;
261 UINT
MIXER_Open(LPHMIXER lphMix
, UINT uDeviceID
, DWORD dwCallback
,
262 DWORD dwInstance
, DWORD fdwOpen
, BOOL bFrom32
)
269 TRACE("(%p, %d, %08lx, %08lx, %08lx)\n",
270 lphMix
, uDeviceID
, dwCallback
, dwInstance
, fdwOpen
);
272 wmld
= MMDRV_Alloc(sizeof(WINE_MIXER
), MMDRV_MIXER
, &hMix
, &fdwOpen
,
273 &dwCallback
, &dwInstance
, bFrom32
);
275 wmld
->uDeviceID
= uDeviceID
;
276 mod
.hmx
= (HMIXEROBJ
)hMix
;
277 mod
.dwCallback
= dwCallback
;
278 mod
.dwInstance
= dwInstance
;
280 dwRet
= MMDRV_Open(wmld
, MXDM_OPEN
, (DWORD
)&mod
, fdwOpen
);
282 if (dwRet
!= MMSYSERR_NOERROR
) {
283 MMDRV_Free(hMix
, wmld
);
286 if (lphMix
) *lphMix
= hMix
;
287 TRACE("=> %ld hMixer=%p\n", dwRet
, hMix
);
292 /**************************************************************************
293 * mixerOpen [WINMM.@]
295 UINT WINAPI
mixerOpen(LPHMIXER lphMix
, UINT uDeviceID
, DWORD dwCallback
,
296 DWORD dwInstance
, DWORD fdwOpen
)
298 return MIXER_Open(lphMix
, uDeviceID
, dwCallback
, dwInstance
, fdwOpen
, TRUE
);
301 /**************************************************************************
302 * mixerClose [WINMM.@]
304 UINT WINAPI
mixerClose(HMIXER hMix
)
309 TRACE("(%p)\n", hMix
);
311 if ((wmld
= MMDRV_Get(hMix
, MMDRV_MIXER
, FALSE
)) == NULL
) return MMSYSERR_INVALHANDLE
;
313 dwRet
= MMDRV_Close(wmld
, MXDM_CLOSE
);
314 MMDRV_Free(hMix
, wmld
);
319 /**************************************************************************
320 * mixerGetID [WINMM.@]
322 UINT WINAPI
mixerGetID(HMIXEROBJ hmix
, LPUINT lpid
, DWORD fdwID
)
326 TRACE("(%p %p %08lx)\n", hmix
, lpid
, fdwID
);
328 if ((lpwm
= MIXER_GetDev(hmix
, fdwID
)) == NULL
) {
329 return MMSYSERR_INVALHANDLE
;
333 *lpid
= lpwm
->mld
.uDeviceID
;
335 return MMSYSERR_NOERROR
;
338 /**************************************************************************
339 * mixerGetControlDetailsA [WINMM.@]
341 UINT WINAPI
mixerGetControlDetailsA(HMIXEROBJ hmix
, LPMIXERCONTROLDETAILS lpmcdA
,
346 TRACE("(%p, %p, %08lx)\n", hmix
, lpmcdA
, fdwDetails
);
348 if ((lpwm
= MIXER_GetDev(hmix
, fdwDetails
)) == NULL
)
349 return MMSYSERR_INVALHANDLE
;
351 if (lpmcdA
== NULL
|| lpmcdA
->cbStruct
!= sizeof(*lpmcdA
))
352 return MMSYSERR_INVALPARAM
;
354 return MMDRV_Message(&lpwm
->mld
, MXDM_GETCONTROLDETAILS
, (DWORD
)lpmcdA
,
358 /**************************************************************************
359 * mixerGetControlDetailsW [WINMM.@]
361 UINT WINAPI
mixerGetControlDetailsW(HMIXEROBJ hmix
, LPMIXERCONTROLDETAILS lpmcd
, DWORD fdwDetails
)
363 DWORD ret
= MMSYSERR_NOTENABLED
;
365 TRACE("(%p, %p, %08lx)\n", hmix
, lpmcd
, fdwDetails
);
367 if (lpmcd
== NULL
|| lpmcd
->cbStruct
!= sizeof(*lpmcd
))
368 return MMSYSERR_INVALPARAM
;
370 switch (fdwDetails
& MIXER_GETCONTROLDETAILSF_QUERYMASK
) {
371 case MIXER_GETCONTROLDETAILSF_VALUE
:
372 /* can savely use W structure as it is, no string inside */
373 ret
= mixerGetControlDetailsA(hmix
, lpmcd
, fdwDetails
);
375 case MIXER_GETCONTROLDETAILSF_LISTTEXT
:
377 MIXERCONTROLDETAILS_LISTTEXTW
*pDetailsW
= (MIXERCONTROLDETAILS_LISTTEXTW
*)lpmcd
->paDetails
;
378 MIXERCONTROLDETAILS_LISTTEXTA
*pDetailsA
;
379 int size
= max(1, lpmcd
->cChannels
) * sizeof(MIXERCONTROLDETAILS_LISTTEXTA
);
382 if (lpmcd
->u
.cMultipleItems
!= 0) {
383 size
*= lpmcd
->u
.cMultipleItems
;
385 pDetailsA
= (MIXERCONTROLDETAILS_LISTTEXTA
*)HeapAlloc(GetProcessHeap(), 0, size
);
386 lpmcd
->paDetails
= pDetailsA
;
387 lpmcd
->cbDetails
= sizeof(MIXERCONTROLDETAILS_LISTTEXTA
);
388 /* set up lpmcd->paDetails */
389 ret
= mixerGetControlDetailsA(hmix
, lpmcd
, fdwDetails
);
390 /* copy from lpmcd->paDetails back to paDetailsW; */
391 if(ret
== MMSYSERR_NOERROR
) {
392 for(i
=0;i
<lpmcd
->u
.cMultipleItems
*lpmcd
->cChannels
;i
++) {
393 pDetailsW
->dwParam1
= pDetailsA
->dwParam1
;
394 pDetailsW
->dwParam2
= pDetailsA
->dwParam2
;
395 MultiByteToWideChar( CP_ACP
, 0, pDetailsA
->szName
, -1,
397 sizeof(pDetailsW
->szName
)/sizeof(WCHAR
) );
401 pDetailsA
-= lpmcd
->u
.cMultipleItems
*lpmcd
->cChannels
;
402 pDetailsW
-= lpmcd
->u
.cMultipleItems
*lpmcd
->cChannels
;
404 HeapFree(GetProcessHeap(), 0, pDetailsA
);
405 lpmcd
->paDetails
= pDetailsW
;
406 lpmcd
->cbDetails
= sizeof(MIXERCONTROLDETAILS_LISTTEXTW
);
410 ERR("Unsupported fdwDetails=0x%08lx\n", fdwDetails
);
416 /**************************************************************************
417 * mixerGetLineControlsA [WINMM.@]
419 UINT WINAPI
mixerGetLineControlsA(HMIXEROBJ hmix
, LPMIXERLINECONTROLSA lpmlcA
,
424 TRACE("(%p, %p, %08lx)\n", hmix
, lpmlcA
, fdwControls
);
426 if ((lpwm
= MIXER_GetDev(hmix
, fdwControls
)) == NULL
)
427 return MMSYSERR_INVALHANDLE
;
429 if (lpmlcA
== NULL
|| lpmlcA
->cbStruct
!= sizeof(*lpmlcA
))
430 return MMSYSERR_INVALPARAM
;
432 return MMDRV_Message(&lpwm
->mld
, MXDM_GETLINECONTROLS
, (DWORD
)lpmlcA
,
436 /**************************************************************************
437 * mixerGetLineControlsW [WINMM.@]
439 UINT WINAPI
mixerGetLineControlsW(HMIXEROBJ hmix
, LPMIXERLINECONTROLSW lpmlcW
,
442 MIXERLINECONTROLSA mlcA
;
446 TRACE("(%p, %p, %08lx)\n", hmix
, lpmlcW
, fdwControls
);
448 if (lpmlcW
== NULL
|| lpmlcW
->cbStruct
!= sizeof(*lpmlcW
) ||
449 lpmlcW
->cbmxctrl
!= sizeof(MIXERCONTROLW
))
450 return MMSYSERR_INVALPARAM
;
452 mlcA
.cbStruct
= sizeof(mlcA
);
453 mlcA
.dwLineID
= lpmlcW
->dwLineID
;
454 mlcA
.u
.dwControlID
= lpmlcW
->u
.dwControlID
;
455 mlcA
.u
.dwControlType
= lpmlcW
->u
.dwControlType
;
456 mlcA
.cControls
= lpmlcW
->cControls
;
457 mlcA
.cbmxctrl
= sizeof(MIXERCONTROLA
);
458 mlcA
.pamxctrl
= HeapAlloc(GetProcessHeap(), 0,
459 mlcA
.cControls
* mlcA
.cbmxctrl
);
461 ret
= mixerGetLineControlsA(hmix
, &mlcA
, fdwControls
);
463 if (ret
== MMSYSERR_NOERROR
) {
464 lpmlcW
->dwLineID
= mlcA
.dwLineID
;
465 lpmlcW
->u
.dwControlID
= mlcA
.u
.dwControlID
;
466 lpmlcW
->u
.dwControlType
= mlcA
.u
.dwControlType
;
467 lpmlcW
->cControls
= mlcA
.cControls
;
469 for (i
= 0; i
< mlcA
.cControls
; i
++) {
470 lpmlcW
->pamxctrl
[i
].cbStruct
= sizeof(MIXERCONTROLW
);
471 lpmlcW
->pamxctrl
[i
].dwControlID
= mlcA
.pamxctrl
[i
].dwControlID
;
472 lpmlcW
->pamxctrl
[i
].dwControlType
= mlcA
.pamxctrl
[i
].dwControlType
;
473 lpmlcW
->pamxctrl
[i
].fdwControl
= mlcA
.pamxctrl
[i
].fdwControl
;
474 lpmlcW
->pamxctrl
[i
].cMultipleItems
= mlcA
.pamxctrl
[i
].cMultipleItems
;
475 MultiByteToWideChar( CP_ACP
, 0, mlcA
.pamxctrl
[i
].szShortName
, -1,
476 lpmlcW
->pamxctrl
[i
].szShortName
,
477 sizeof(lpmlcW
->pamxctrl
[i
].szShortName
)/sizeof(WCHAR
) );
478 MultiByteToWideChar( CP_ACP
, 0, mlcA
.pamxctrl
[i
].szName
, -1,
479 lpmlcW
->pamxctrl
[i
].szName
,
480 sizeof(lpmlcW
->pamxctrl
[i
].szName
)/sizeof(WCHAR
) );
481 /* sizeof(lpmlcW->pamxctrl[i].Bounds) ==
482 * sizeof(mlcA.pamxctrl[i].Bounds) */
483 memcpy(&lpmlcW
->pamxctrl
[i
].Bounds
, &mlcA
.pamxctrl
[i
].Bounds
,
484 sizeof(mlcA
.pamxctrl
[i
].Bounds
));
485 /* sizeof(lpmlcW->pamxctrl[i].Metrics) ==
486 * sizeof(mlcA.pamxctrl[i].Metrics) */
487 memcpy(&lpmlcW
->pamxctrl
[i
].Metrics
, &mlcA
.pamxctrl
[i
].Metrics
,
488 sizeof(mlcA
.pamxctrl
[i
].Metrics
));
492 HeapFree(GetProcessHeap(), 0, mlcA
.pamxctrl
);
497 /**************************************************************************
498 * mixerGetLineInfoA [WINMM.@]
500 UINT WINAPI
mixerGetLineInfoA(HMIXEROBJ hmix
, LPMIXERLINEA lpmliW
, DWORD fdwInfo
)
504 TRACE("(%p, %p, %08lx)\n", hmix
, lpmliW
, fdwInfo
);
506 if ((lpwm
= MIXER_GetDev(hmix
, fdwInfo
)) == NULL
)
507 return MMSYSERR_INVALHANDLE
;
509 return MMDRV_Message(&lpwm
->mld
, MXDM_GETLINEINFO
, (DWORD
)lpmliW
,
513 /**************************************************************************
514 * mixerGetLineInfoW [WINMM.@]
516 UINT WINAPI
mixerGetLineInfoW(HMIXEROBJ hmix
, LPMIXERLINEW lpmliW
,
522 TRACE("(%p, %p, %08lx)\n", hmix
, lpmliW
, fdwInfo
);
524 if (lpmliW
== NULL
|| lpmliW
->cbStruct
!= sizeof(*lpmliW
))
525 return MMSYSERR_INVALPARAM
;
527 mliA
.cbStruct
= sizeof(mliA
);
528 switch (fdwInfo
& MIXER_GETLINEINFOF_QUERYMASK
) {
529 case MIXER_GETLINEINFOF_COMPONENTTYPE
:
530 mliA
.dwComponentType
= lpmliW
->dwComponentType
;
532 case MIXER_GETLINEINFOF_DESTINATION
:
533 mliA
.dwDestination
= lpmliW
->dwDestination
;
535 case MIXER_GETLINEINFOF_LINEID
:
536 mliA
.dwLineID
= lpmliW
->dwLineID
;
538 case MIXER_GETLINEINFOF_SOURCE
:
539 mliA
.dwDestination
= lpmliW
->dwDestination
;
540 mliA
.dwSource
= lpmliW
->dwSource
;
542 case MIXER_GETLINEINFOF_TARGETTYPE
:
543 mliA
.Target
.dwType
= lpmliW
->Target
.dwType
;
544 mliA
.Target
.wMid
= lpmliW
->Target
.wMid
;
545 mliA
.Target
.wPid
= lpmliW
->Target
.wPid
;
546 mliA
.Target
.vDriverVersion
= lpmliW
->Target
.vDriverVersion
;
547 WideCharToMultiByte( CP_ACP
, 0, lpmliW
->Target
.szPname
, -1, mliA
.Target
.szPname
, sizeof(mliA
.Target
.szPname
), NULL
, NULL
);
550 FIXME("Unsupported fdwControls=0x%08lx\n", fdwInfo
);
553 ret
= mixerGetLineInfoA(hmix
, &mliA
, fdwInfo
);
555 lpmliW
->dwDestination
= mliA
.dwDestination
;
556 lpmliW
->dwSource
= mliA
.dwSource
;
557 lpmliW
->dwLineID
= mliA
.dwLineID
;
558 lpmliW
->fdwLine
= mliA
.fdwLine
;
559 lpmliW
->dwUser
= mliA
.dwUser
;
560 lpmliW
->dwComponentType
= mliA
.dwComponentType
;
561 lpmliW
->cChannels
= mliA
.cChannels
;
562 lpmliW
->cConnections
= mliA
.cConnections
;
563 lpmliW
->cControls
= mliA
.cControls
;
564 MultiByteToWideChar( CP_ACP
, 0, mliA
.szShortName
, -1, lpmliW
->szShortName
,
565 sizeof(lpmliW
->szShortName
)/sizeof(WCHAR
) );
566 MultiByteToWideChar( CP_ACP
, 0, mliA
.szName
, -1, lpmliW
->szName
,
567 sizeof(lpmliW
->szName
)/sizeof(WCHAR
) );
568 lpmliW
->Target
.dwType
= mliA
.Target
.dwType
;
569 lpmliW
->Target
.dwDeviceID
= mliA
.Target
.dwDeviceID
;
570 lpmliW
->Target
.wMid
= mliA
.Target
.wMid
;
571 lpmliW
->Target
.wPid
= mliA
.Target
.wPid
;
572 lpmliW
->Target
.vDriverVersion
= mliA
.Target
.vDriverVersion
;
573 MultiByteToWideChar( CP_ACP
, 0, mliA
.Target
.szPname
, -1, lpmliW
->Target
.szPname
,
574 sizeof(lpmliW
->Target
.szPname
)/sizeof(WCHAR
) );
579 /**************************************************************************
580 * mixerSetControlDetails [WINMM.@]
582 UINT WINAPI
mixerSetControlDetails(HMIXEROBJ hmix
, LPMIXERCONTROLDETAILS lpmcdA
,
587 TRACE("(%p, %p, %08lx)\n", hmix
, lpmcdA
, fdwDetails
);
589 if ((lpwm
= MIXER_GetDev(hmix
, fdwDetails
)) == NULL
)
590 return MMSYSERR_INVALHANDLE
;
592 return MMDRV_Message(&lpwm
->mld
, MXDM_SETCONTROLDETAILS
, (DWORD
)lpmcdA
,
596 /**************************************************************************
597 * mixerMessage [WINMM.@]
599 UINT WINAPI
mixerMessage(HMIXER hmix
, UINT uMsg
, DWORD dwParam1
, DWORD dwParam2
)
603 TRACE("(%04lx, %d, %08lx, %08lx): semi-stub?\n",
604 (DWORD
)hmix
, uMsg
, dwParam1
, dwParam2
);
606 if ((wmld
= MMDRV_Get(hmix
, MMDRV_MIXER
, FALSE
)) == NULL
)
607 return MMSYSERR_INVALHANDLE
;
609 return MMDRV_Message(wmld
, uMsg
, dwParam1
, dwParam2
, TRUE
);
612 /**************************************************************************
613 * auxGetNumDevs [WINMM.@]
615 UINT WINAPI
auxGetNumDevs(void)
617 return MMDRV_GetNum(MMDRV_AUX
);
620 /**************************************************************************
621 * auxGetDevCapsW [WINMM.@]
623 UINT WINAPI
auxGetDevCapsW(UINT uDeviceID
, LPAUXCAPSW lpCaps
, UINT uSize
)
626 UINT ret
= auxGetDevCapsA(uDeviceID
, &acA
, sizeof(acA
));
628 lpCaps
->wMid
= acA
.wMid
;
629 lpCaps
->wPid
= acA
.wPid
;
630 lpCaps
->vDriverVersion
= acA
.vDriverVersion
;
631 MultiByteToWideChar( CP_ACP
, 0, acA
.szPname
, -1, lpCaps
->szPname
,
632 sizeof(lpCaps
->szPname
)/sizeof(WCHAR
) );
633 lpCaps
->wTechnology
= acA
.wTechnology
;
634 lpCaps
->dwSupport
= acA
.dwSupport
;
638 /**************************************************************************
639 * auxGetDevCapsA [WINMM.@]
641 UINT WINAPI
auxGetDevCapsA(UINT uDeviceID
, LPAUXCAPSA lpCaps
, UINT uSize
)
645 TRACE("(%04X, %p, %d) !\n", uDeviceID
, lpCaps
, uSize
);
647 if ((wmld
= MMDRV_Get((HANDLE
)uDeviceID
, MMDRV_AUX
, TRUE
)) == NULL
)
648 return MMSYSERR_INVALHANDLE
;
649 return MMDRV_Message(wmld
, AUXDM_GETDEVCAPS
, (DWORD
)lpCaps
, uSize
, TRUE
);
652 /**************************************************************************
653 * auxGetVolume [WINMM.@]
655 UINT WINAPI
auxGetVolume(UINT uDeviceID
, DWORD
* lpdwVolume
)
659 TRACE("(%04X, %p) !\n", uDeviceID
, lpdwVolume
);
661 if ((wmld
= MMDRV_Get((HANDLE
)uDeviceID
, MMDRV_AUX
, TRUE
)) == NULL
)
662 return MMSYSERR_INVALHANDLE
;
663 return MMDRV_Message(wmld
, AUXDM_GETVOLUME
, (DWORD
)lpdwVolume
, 0L, TRUE
);
666 /**************************************************************************
667 * auxSetVolume [WINMM.@]
669 UINT WINAPI
auxSetVolume(UINT uDeviceID
, DWORD dwVolume
)
673 TRACE("(%04X, %lu) !\n", uDeviceID
, dwVolume
);
675 if ((wmld
= MMDRV_Get((HANDLE
)uDeviceID
, MMDRV_AUX
, TRUE
)) == NULL
)
676 return MMSYSERR_INVALHANDLE
;
677 return MMDRV_Message(wmld
, AUXDM_SETVOLUME
, dwVolume
, 0L, TRUE
);
680 /**************************************************************************
681 * auxOutMessage [WINMM.@]
683 DWORD WINAPI
auxOutMessage(UINT uDeviceID
, UINT uMessage
, DWORD dw1
, DWORD dw2
)
687 if ((wmld
= MMDRV_Get((HANDLE
)uDeviceID
, MMDRV_AUX
, TRUE
)) == NULL
)
688 return MMSYSERR_INVALHANDLE
;
690 return MMDRV_Message(wmld
, uMessage
, dw1
, dw2
, TRUE
);
693 /**************************************************************************
694 * mciGetErrorStringW [WINMM.@]
696 BOOL WINAPI
mciGetErrorStringW(DWORD wError
, LPWSTR lpstrBuffer
, UINT uLength
)
698 LPSTR bufstr
= HeapAlloc(GetProcessHeap(), 0, uLength
);
699 BOOL ret
= mciGetErrorStringA(wError
, bufstr
, uLength
);
701 MultiByteToWideChar( CP_ACP
, 0, bufstr
, -1, lpstrBuffer
, uLength
);
702 HeapFree(GetProcessHeap(), 0, bufstr
);
706 /**************************************************************************
707 * mciGetErrorStringA [WINMM.@]
709 BOOL WINAPI
mciGetErrorStringA(DWORD dwError
, LPSTR lpstrBuffer
, UINT uLength
)
713 if (lpstrBuffer
!= NULL
&& uLength
> 0 &&
714 dwError
>= MCIERR_BASE
&& dwError
<= MCIERR_CUSTOM_DRIVER_BASE
) {
716 if (LoadStringA(WINMM_IData
->hWinMM32Instance
,
717 dwError
, lpstrBuffer
, uLength
) > 0) {
724 /**************************************************************************
725 * mciDriverNotify [WINMM.@]
727 BOOL WINAPI
mciDriverNotify(HWND hWndCallBack
, UINT wDevID
, UINT wStatus
)
730 TRACE("(%p, %04x, %04X)\n", hWndCallBack
, wDevID
, wStatus
);
732 return PostMessageA(hWndCallBack
, MM_MCINOTIFY
, wStatus
, wDevID
);
735 /**************************************************************************
736 * mciGetDriverData [WINMM.@]
738 DWORD WINAPI
mciGetDriverData(UINT uDeviceID
)
740 LPWINE_MCIDRIVER wmd
;
742 TRACE("(%04x)\n", uDeviceID
);
744 wmd
= MCI_GetDriver(uDeviceID
);
747 WARN("Bad uDeviceID\n");
751 return wmd
->dwPrivate
;
754 /**************************************************************************
755 * mciSetDriverData [WINMM.@]
757 BOOL WINAPI
mciSetDriverData(UINT uDeviceID
, DWORD data
)
759 LPWINE_MCIDRIVER wmd
;
761 TRACE("(%04x, %08lx)\n", uDeviceID
, data
);
763 wmd
= MCI_GetDriver(uDeviceID
);
766 WARN("Bad uDeviceID\n");
770 wmd
->dwPrivate
= data
;
774 /**************************************************************************
775 * mciSendCommandA [WINMM.@]
777 DWORD WINAPI
mciSendCommandA(UINT wDevID
, UINT wMsg
, DWORD dwParam1
, DWORD dwParam2
)
781 TRACE("(%08x, %s, %08lx, %08lx)\n",
782 wDevID
, MCI_MessageToString(wMsg
), dwParam1
, dwParam2
);
784 dwRet
= MCI_SendCommand(wDevID
, wMsg
, dwParam1
, dwParam2
, TRUE
);
785 dwRet
= MCI_CleanUp(dwRet
, wMsg
, dwParam2
);
786 TRACE("=> %08lx\n", dwRet
);
790 /**************************************************************************
791 * mciSendCommandW [WINMM.@]
793 DWORD WINAPI
mciSendCommandW(UINT wDevID
, UINT wMsg
, DWORD dwParam1
, DWORD dwParam2
)
795 FIXME("(%08x, %s, %08lx, %08lx): stub\n",
796 wDevID
, MCI_MessageToString(wMsg
), dwParam1
, dwParam2
);
797 return MCIERR_UNSUPPORTED_FUNCTION
;
800 /**************************************************************************
801 * mciGetDeviceIDA [WINMM.@]
803 UINT WINAPI
mciGetDeviceIDA(LPCSTR lpstrName
)
805 return MCI_GetDriverFromString(lpstrName
);
808 /**************************************************************************
809 * mciGetDeviceIDW [WINMM.@]
811 UINT WINAPI
mciGetDeviceIDW(LPCWSTR lpwstrName
)
816 lpstrName
= HEAP_strdupWtoA(GetProcessHeap(), 0, lpwstrName
);
817 ret
= MCI_GetDriverFromString(lpstrName
);
818 HeapFree(GetProcessHeap(), 0, lpstrName
);
822 /**************************************************************************
823 * MCI_DefYieldProc [internal]
825 UINT WINAPI
MCI_DefYieldProc(MCIDEVICEID wDevID
, DWORD data
)
829 TRACE("(0x%04x, 0x%08lx)\n", wDevID
, data
);
831 if ((HIWORD(data
) != 0 && HWND_16(GetActiveWindow()) != HIWORD(data
)) ||
832 (GetAsyncKeyState(LOWORD(data
)) & 1) == 0) {
838 msg
.hwnd
= HWND_32(HIWORD(data
));
839 while (!PeekMessageA(&msg
, msg
.hwnd
, WM_KEYFIRST
, WM_KEYLAST
, PM_REMOVE
));
845 /**************************************************************************
846 * mciSetYieldProc [WINMM.@]
848 BOOL WINAPI
mciSetYieldProc(UINT uDeviceID
, YIELDPROC fpYieldProc
, DWORD dwYieldData
)
850 LPWINE_MCIDRIVER wmd
;
852 TRACE("(%u, %p, %08lx)\n", uDeviceID
, fpYieldProc
, dwYieldData
);
854 if (!(wmd
= MCI_GetDriver(uDeviceID
))) {
855 WARN("Bad uDeviceID\n");
859 wmd
->lpfnYieldProc
= fpYieldProc
;
860 wmd
->dwYieldData
= dwYieldData
;
866 /**************************************************************************
867 * mciGetDeviceIDFromElementIDW [WINMM.@]
869 UINT WINAPI
mciGetDeviceIDFromElementIDW(DWORD dwElementID
, LPCWSTR lpstrType
)
871 /* FIXME: that's rather strange, there is no
872 * mciGetDeviceIDFromElementID32A in winmm.spec
874 FIXME("(%lu, %p) stub\n", dwElementID
, lpstrType
);
878 /**************************************************************************
879 * mciGetYieldProc [WINMM.@]
881 YIELDPROC WINAPI
mciGetYieldProc(UINT uDeviceID
, DWORD
* lpdwYieldData
)
883 LPWINE_MCIDRIVER wmd
;
885 TRACE("(%u, %p)\n", uDeviceID
, lpdwYieldData
);
887 if (!(wmd
= MCI_GetDriver(uDeviceID
))) {
888 WARN("Bad uDeviceID\n");
891 if (!wmd
->lpfnYieldProc
) {
892 WARN("No proc set\n");
896 WARN("Proc is 32 bit\n");
899 return wmd
->lpfnYieldProc
;
902 /**************************************************************************
903 * mciGetCreatorTask [WINMM.@]
905 HTASK WINAPI
mciGetCreatorTask(UINT uDeviceID
)
907 LPWINE_MCIDRIVER wmd
;
910 if ((wmd
= MCI_GetDriver(uDeviceID
))) ret
= (HTASK
)wmd
->CreatorThread
;
912 TRACE("(%u) => %p\n", uDeviceID
, ret
);
916 /**************************************************************************
917 * mciDriverYield [WINMM.@]
919 UINT WINAPI
mciDriverYield(UINT uDeviceID
)
921 LPWINE_MCIDRIVER wmd
;
924 TRACE("(%04x)\n", uDeviceID
);
926 if (!(wmd
= MCI_GetDriver(uDeviceID
)) || !wmd
->lpfnYieldProc
|| !wmd
->bIs32
) {
929 ret
= wmd
->lpfnYieldProc(uDeviceID
, wmd
->dwYieldData
);
935 /**************************************************************************
936 * midiOutGetNumDevs [WINMM.@]
938 UINT WINAPI
midiOutGetNumDevs(void)
940 return MMDRV_GetNum(MMDRV_MIDIOUT
);
943 /**************************************************************************
944 * midiOutGetDevCapsW [WINMM.@]
946 UINT WINAPI
midiOutGetDevCapsW(UINT uDeviceID
, LPMIDIOUTCAPSW lpCaps
,
952 ret
= midiOutGetDevCapsA(uDeviceID
, &mocA
, sizeof(mocA
));
953 lpCaps
->wMid
= mocA
.wMid
;
954 lpCaps
->wPid
= mocA
.wPid
;
955 lpCaps
->vDriverVersion
= mocA
.vDriverVersion
;
956 MultiByteToWideChar( CP_ACP
, 0, mocA
.szPname
, -1, lpCaps
->szPname
,
957 sizeof(lpCaps
->szPname
)/sizeof(WCHAR
) );
958 lpCaps
->wTechnology
= mocA
.wTechnology
;
959 lpCaps
->wVoices
= mocA
.wVoices
;
960 lpCaps
->wNotes
= mocA
.wNotes
;
961 lpCaps
->wChannelMask
= mocA
.wChannelMask
;
962 lpCaps
->dwSupport
= mocA
.dwSupport
;
966 /**************************************************************************
967 * midiOutGetDevCapsA [WINMM.@]
969 UINT WINAPI
midiOutGetDevCapsA(UINT uDeviceID
, LPMIDIOUTCAPSA lpCaps
,
974 TRACE("(%u, %p, %u);\n", uDeviceID
, lpCaps
, uSize
);
976 if (lpCaps
== NULL
) return MMSYSERR_INVALPARAM
;
978 if ((wmld
= MMDRV_Get((HANDLE
)uDeviceID
, MMDRV_MIDIOUT
, TRUE
)) == NULL
)
979 return MMSYSERR_INVALHANDLE
;
981 return MMDRV_Message(wmld
, MODM_GETDEVCAPS
, (DWORD
)lpCaps
, uSize
, TRUE
);
984 /**************************************************************************
985 * MIDI_GetErrorText [internal]
987 static UINT16
MIDI_GetErrorText(UINT16 uError
, LPSTR lpText
, UINT16 uSize
)
989 UINT16 ret
= MMSYSERR_BADERRNUM
;
991 if (lpText
== NULL
) {
992 ret
= MMSYSERR_INVALPARAM
;
993 } else if (uSize
== 0) {
994 ret
= MMSYSERR_NOERROR
;
996 /* test has been removed 'coz MMSYSERR_BASE is 0, and gcc did emit
997 * a warning for the test was always true */
998 (/*uError >= MMSYSERR_BASE && */ uError
<= MMSYSERR_LASTERROR
) ||
999 (uError
>= MIDIERR_BASE
&& uError
<= MIDIERR_LASTERROR
)) {
1001 if (LoadStringA(WINMM_IData
->hWinMM32Instance
,
1002 uError
, lpText
, uSize
) > 0) {
1003 ret
= MMSYSERR_NOERROR
;
1009 /**************************************************************************
1010 * midiOutGetErrorTextA [WINMM.@]
1012 UINT WINAPI
midiOutGetErrorTextA(UINT uError
, LPSTR lpText
, UINT uSize
)
1014 return MIDI_GetErrorText(uError
, lpText
, uSize
);
1017 /**************************************************************************
1018 * midiOutGetErrorTextW [WINMM.@]
1020 UINT WINAPI
midiOutGetErrorTextW(UINT uError
, LPWSTR lpText
, UINT uSize
)
1022 LPSTR xstr
= HeapAlloc(GetProcessHeap(), 0, uSize
);
1025 ret
= MIDI_GetErrorText(uError
, xstr
, uSize
);
1026 MultiByteToWideChar( CP_ACP
, 0, xstr
, -1, lpText
, uSize
);
1027 HeapFree(GetProcessHeap(), 0, xstr
);
1031 /**************************************************************************
1032 * MIDI_OutAlloc [internal]
1034 static LPWINE_MIDI
MIDI_OutAlloc(HMIDIOUT
* lphMidiOut
, LPDWORD lpdwCallback
,
1035 LPDWORD lpdwInstance
, LPDWORD lpdwFlags
,
1036 DWORD cIDs
, MIDIOPENSTRMID
* lpIDs
, BOOL bFrom32
)
1042 size
= sizeof(WINE_MIDI
) + (cIDs
? (cIDs
-1) : 0) * sizeof(MIDIOPENSTRMID
);
1044 lpwm
= (LPWINE_MIDI
)MMDRV_Alloc(size
, MMDRV_MIDIOUT
, &hMidiOut
, lpdwFlags
,
1045 lpdwCallback
, lpdwInstance
, bFrom32
);
1047 if (lphMidiOut
!= NULL
)
1048 *lphMidiOut
= hMidiOut
;
1051 lpwm
->mod
.hMidi
= (HMIDI
) hMidiOut
;
1052 lpwm
->mod
.dwCallback
= *lpdwCallback
;
1053 lpwm
->mod
.dwInstance
= *lpdwInstance
;
1054 lpwm
->mod
.dnDevNode
= 0;
1055 lpwm
->mod
.cIds
= cIDs
;
1057 memcpy(&(lpwm
->mod
.rgIds
), lpIDs
, cIDs
* sizeof(MIDIOPENSTRMID
));
1062 UINT
MIDI_OutOpen(HMIDIOUT
* lphMidiOut
, UINT uDeviceID
, DWORD dwCallback
,
1063 DWORD dwInstance
, DWORD dwFlags
, BOOL bFrom32
)
1069 TRACE("(%p, %d, %08lX, %08lX, %08lX);\n",
1070 lphMidiOut
, uDeviceID
, dwCallback
, dwInstance
, dwFlags
);
1072 if (lphMidiOut
!= NULL
) *lphMidiOut
= 0;
1074 lpwm
= MIDI_OutAlloc(&hMidiOut
, &dwCallback
, &dwInstance
, &dwFlags
,
1078 return MMSYSERR_NOMEM
;
1080 lpwm
->mld
.uDeviceID
= uDeviceID
;
1082 dwRet
= MMDRV_Open((LPWINE_MLD
)lpwm
, MODM_OPEN
, (DWORD
)&lpwm
->mod
, dwFlags
);
1084 if (dwRet
!= MMSYSERR_NOERROR
) {
1085 MMDRV_Free(hMidiOut
, (LPWINE_MLD
)lpwm
);
1089 if (lphMidiOut
) *lphMidiOut
= hMidiOut
;
1090 TRACE("=> %d hMidi=%p\n", dwRet
, hMidiOut
);
1095 /**************************************************************************
1096 * midiOutOpen [WINMM.@]
1098 UINT WINAPI
midiOutOpen(HMIDIOUT
* lphMidiOut
, UINT uDeviceID
,
1099 DWORD dwCallback
, DWORD dwInstance
, DWORD dwFlags
)
1101 return MIDI_OutOpen(lphMidiOut
, uDeviceID
, dwCallback
, dwInstance
, dwFlags
, TRUE
);
1104 /**************************************************************************
1105 * midiOutClose [WINMM.@]
1107 UINT WINAPI
midiOutClose(HMIDIOUT hMidiOut
)
1112 TRACE("(%p)\n", hMidiOut
);
1114 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, FALSE
)) == NULL
)
1115 return MMSYSERR_INVALHANDLE
;
1117 dwRet
= MMDRV_Close(wmld
, MODM_CLOSE
);
1118 MMDRV_Free(hMidiOut
, wmld
);
1123 /**************************************************************************
1124 * midiOutPrepareHeader [WINMM.@]
1126 UINT WINAPI
midiOutPrepareHeader(HMIDIOUT hMidiOut
,
1127 MIDIHDR
* lpMidiOutHdr
, UINT uSize
)
1131 TRACE("(%p, %p, %d)\n", hMidiOut
, lpMidiOutHdr
, uSize
);
1133 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, FALSE
)) == NULL
)
1134 return MMSYSERR_INVALHANDLE
;
1136 return MMDRV_Message(wmld
, MODM_PREPARE
, (DWORD
)lpMidiOutHdr
, uSize
, TRUE
);
1139 /**************************************************************************
1140 * midiOutUnprepareHeader [WINMM.@]
1142 UINT WINAPI
midiOutUnprepareHeader(HMIDIOUT hMidiOut
,
1143 MIDIHDR
* lpMidiOutHdr
, UINT uSize
)
1147 TRACE("(%p, %p, %d)\n", hMidiOut
, lpMidiOutHdr
, uSize
);
1149 if (!(lpMidiOutHdr
->dwFlags
& MHDR_PREPARED
)) {
1150 return MMSYSERR_NOERROR
;
1153 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, FALSE
)) == NULL
)
1154 return MMSYSERR_INVALHANDLE
;
1156 return MMDRV_Message(wmld
, MODM_UNPREPARE
, (DWORD
)lpMidiOutHdr
, uSize
, TRUE
);
1159 /**************************************************************************
1160 * midiOutShortMsg [WINMM.@]
1162 UINT WINAPI
midiOutShortMsg(HMIDIOUT hMidiOut
, DWORD dwMsg
)
1166 TRACE("(%p, %08lX)\n", hMidiOut
, dwMsg
);
1168 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, FALSE
)) == NULL
)
1169 return MMSYSERR_INVALHANDLE
;
1171 return MMDRV_Message(wmld
, MODM_DATA
, dwMsg
, 0L, TRUE
);
1174 /**************************************************************************
1175 * midiOutLongMsg [WINMM.@]
1177 UINT WINAPI
midiOutLongMsg(HMIDIOUT hMidiOut
,
1178 MIDIHDR
* lpMidiOutHdr
, UINT uSize
)
1182 TRACE("(%p, %p, %d)\n", hMidiOut
, lpMidiOutHdr
, uSize
);
1184 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, FALSE
)) == NULL
)
1185 return MMSYSERR_INVALHANDLE
;
1187 return MMDRV_Message(wmld
, MODM_LONGDATA
, (DWORD
)lpMidiOutHdr
, uSize
, TRUE
);
1190 /**************************************************************************
1191 * midiOutReset [WINMM.@]
1193 UINT WINAPI
midiOutReset(HMIDIOUT hMidiOut
)
1197 TRACE("(%p)\n", hMidiOut
);
1199 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, FALSE
)) == NULL
)
1200 return MMSYSERR_INVALHANDLE
;
1202 return MMDRV_Message(wmld
, MODM_RESET
, 0L, 0L, TRUE
);
1205 /**************************************************************************
1206 * midiOutGetVolume [WINMM.@]
1208 UINT WINAPI
midiOutGetVolume(HMIDIOUT hMidiOut
, DWORD
* lpdwVolume
)
1212 TRACE("(%p, %p);\n", hMidiOut
, lpdwVolume
);
1214 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, TRUE
)) == NULL
)
1215 return MMSYSERR_INVALHANDLE
;
1217 return MMDRV_Message(wmld
, MODM_GETVOLUME
, (DWORD
)lpdwVolume
, 0L, TRUE
);
1220 /**************************************************************************
1221 * midiOutSetVolume [WINMM.@]
1223 UINT WINAPI
midiOutSetVolume(HMIDIOUT hMidiOut
, DWORD dwVolume
)
1227 TRACE("(%p, %ld);\n", hMidiOut
, dwVolume
);
1229 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, TRUE
)) == NULL
)
1230 return MMSYSERR_INVALHANDLE
;
1232 return MMDRV_Message(wmld
, MODM_SETVOLUME
, dwVolume
, 0L, TRUE
);
1235 /**************************************************************************
1236 * midiOutCachePatches [WINMM.@]
1238 UINT WINAPI
midiOutCachePatches(HMIDIOUT hMidiOut
, UINT uBank
,
1239 WORD
* lpwPatchArray
, UINT uFlags
)
1241 /* not really necessary to support this */
1242 FIXME("not supported yet\n");
1243 return MMSYSERR_NOTSUPPORTED
;
1246 /**************************************************************************
1247 * midiOutCacheDrumPatches [WINMM.@]
1249 UINT WINAPI
midiOutCacheDrumPatches(HMIDIOUT hMidiOut
, UINT uPatch
,
1250 WORD
* lpwKeyArray
, UINT uFlags
)
1252 FIXME("not supported yet\n");
1253 return MMSYSERR_NOTSUPPORTED
;
1256 /**************************************************************************
1257 * midiOutGetID [WINMM.@]
1259 UINT WINAPI
midiOutGetID(HMIDIOUT hMidiOut
, UINT
* lpuDeviceID
)
1263 TRACE("(%p, %p)\n", hMidiOut
, lpuDeviceID
);
1265 if (lpuDeviceID
== NULL
) return MMSYSERR_INVALPARAM
;
1266 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, FALSE
)) == NULL
)
1267 return MMSYSERR_INVALHANDLE
;
1269 *lpuDeviceID
= wmld
->uDeviceID
;
1270 return MMSYSERR_NOERROR
;
1273 /**************************************************************************
1274 * midiOutMessage [WINMM.@]
1276 DWORD WINAPI
midiOutMessage(HMIDIOUT hMidiOut
, UINT uMessage
,
1277 DWORD dwParam1
, DWORD dwParam2
)
1281 TRACE("(%p, %04X, %08lX, %08lX)\n", hMidiOut
, uMessage
, dwParam1
, dwParam2
);
1283 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, FALSE
)) == NULL
) {
1285 if (uMessage
== 0x0001) {
1286 *(LPDWORD
)dwParam1
= 1;
1289 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, TRUE
)) != NULL
) {
1290 return MMDRV_PhysicalFeatures(wmld
, uMessage
, dwParam1
, dwParam2
);
1292 return MMSYSERR_INVALHANDLE
;
1298 FIXME("can't handle OPEN or CLOSE message!\n");
1299 return MMSYSERR_NOTSUPPORTED
;
1301 return MMDRV_Message(wmld
, uMessage
, dwParam1
, dwParam2
, TRUE
);
1304 /**************************************************************************
1305 * midiInGetNumDevs [WINMM.@]
1307 UINT WINAPI
midiInGetNumDevs(void)
1309 return MMDRV_GetNum(MMDRV_MIDIIN
);
1312 /**************************************************************************
1313 * midiInGetDevCapsW [WINMM.@]
1315 UINT WINAPI
midiInGetDevCapsW(UINT uDeviceID
, LPMIDIINCAPSW lpCaps
, UINT uSize
)
1318 UINT ret
= midiInGetDevCapsA(uDeviceID
, &micA
, uSize
);
1320 if (ret
== MMSYSERR_NOERROR
) {
1321 lpCaps
->wMid
= micA
.wMid
;
1322 lpCaps
->wPid
= micA
.wPid
;
1323 lpCaps
->vDriverVersion
= micA
.vDriverVersion
;
1324 MultiByteToWideChar( CP_ACP
, 0, micA
.szPname
, -1, lpCaps
->szPname
,
1325 sizeof(lpCaps
->szPname
)/sizeof(WCHAR
) );
1326 lpCaps
->dwSupport
= micA
.dwSupport
;
1331 /**************************************************************************
1332 * midiInGetDevCapsA [WINMM.@]
1334 UINT WINAPI
midiInGetDevCapsA(UINT uDeviceID
, LPMIDIINCAPSA lpCaps
, UINT uSize
)
1338 TRACE("(%d, %p, %d);\n", uDeviceID
, lpCaps
, uSize
);
1340 if ((wmld
= MMDRV_Get((HANDLE
)uDeviceID
, MMDRV_MIDIIN
, TRUE
)) == NULL
)
1341 return MMSYSERR_INVALHANDLE
;
1343 return MMDRV_Message(wmld
, MIDM_GETDEVCAPS
, (DWORD
)lpCaps
, uSize
, TRUE
);
1346 /**************************************************************************
1347 * midiInGetErrorTextW [WINMM.@]
1349 UINT WINAPI
midiInGetErrorTextW(UINT uError
, LPWSTR lpText
, UINT uSize
)
1351 LPSTR xstr
= HeapAlloc(GetProcessHeap(), 0, uSize
);
1352 UINT ret
= MIDI_GetErrorText(uError
, xstr
, uSize
);
1354 MultiByteToWideChar( CP_ACP
, 0, xstr
, -1, lpText
, uSize
);
1355 HeapFree(GetProcessHeap(), 0, xstr
);
1359 /**************************************************************************
1360 * midiInGetErrorTextA [WINMM.@]
1362 UINT WINAPI
midiInGetErrorTextA(UINT uError
, LPSTR lpText
, UINT uSize
)
1364 return MIDI_GetErrorText(uError
, lpText
, uSize
);
1367 UINT
MIDI_InOpen(HMIDIIN
* lphMidiIn
, UINT uDeviceID
, DWORD dwCallback
,
1368 DWORD dwInstance
, DWORD dwFlags
, BOOL bFrom32
)
1374 TRACE("(%p, %d, %08lX, %08lX, %08lX);\n",
1375 lphMidiIn
, uDeviceID
, dwCallback
, dwInstance
, dwFlags
);
1377 if (lphMidiIn
!= NULL
) *lphMidiIn
= 0;
1379 lpwm
= (LPWINE_MIDI
)MMDRV_Alloc(sizeof(WINE_MIDI
), MMDRV_MIDIIN
, &hMidiIn
,
1380 &dwFlags
, &dwCallback
, &dwInstance
, bFrom32
);
1383 return MMSYSERR_NOMEM
;
1385 lpwm
->mod
.hMidi
= (HMIDI
) hMidiIn
;
1386 lpwm
->mod
.dwCallback
= dwCallback
;
1387 lpwm
->mod
.dwInstance
= dwInstance
;
1389 lpwm
->mld
.uDeviceID
= uDeviceID
;
1390 dwRet
= MMDRV_Open(&lpwm
->mld
, MIDM_OPEN
, (DWORD
)&lpwm
->mod
, dwFlags
);
1392 if (dwRet
!= MMSYSERR_NOERROR
) {
1393 MMDRV_Free(hMidiIn
, &lpwm
->mld
);
1396 if (lphMidiIn
!= NULL
) *lphMidiIn
= hMidiIn
;
1397 TRACE("=> %ld hMidi=%p\n", dwRet
, hMidiIn
);
1402 /**************************************************************************
1403 * midiInOpen [WINMM.@]
1405 UINT WINAPI
midiInOpen(HMIDIIN
* lphMidiIn
, UINT uDeviceID
,
1406 DWORD dwCallback
, DWORD dwInstance
, DWORD dwFlags
)
1408 return MIDI_InOpen(lphMidiIn
, uDeviceID
, dwCallback
, dwInstance
, dwFlags
, TRUE
);
1411 /**************************************************************************
1412 * midiInClose [WINMM.@]
1414 UINT WINAPI
midiInClose(HMIDIIN hMidiIn
)
1419 TRACE("(%p)\n", hMidiIn
);
1421 if ((wmld
= MMDRV_Get(hMidiIn
, MMDRV_MIDIIN
, FALSE
)) == NULL
)
1422 return MMSYSERR_INVALHANDLE
;
1424 dwRet
= MMDRV_Close(wmld
, MIDM_CLOSE
);
1425 MMDRV_Free(hMidiIn
, wmld
);
1429 /**************************************************************************
1430 * midiInPrepareHeader [WINMM.@]
1432 UINT WINAPI
midiInPrepareHeader(HMIDIIN hMidiIn
,
1433 MIDIHDR
* lpMidiInHdr
, UINT uSize
)
1437 TRACE("(%p, %p, %d)\n", hMidiIn
, lpMidiInHdr
, uSize
);
1439 if ((wmld
= MMDRV_Get(hMidiIn
, MMDRV_MIDIIN
, FALSE
)) == NULL
)
1440 return MMSYSERR_INVALHANDLE
;
1442 return MMDRV_Message(wmld
, MIDM_PREPARE
, (DWORD
)lpMidiInHdr
, uSize
, TRUE
);
1445 /**************************************************************************
1446 * midiInUnprepareHeader [WINMM.@]
1448 UINT WINAPI
midiInUnprepareHeader(HMIDIIN hMidiIn
,
1449 MIDIHDR
* lpMidiInHdr
, UINT uSize
)
1453 TRACE("(%p, %p, %d)\n", hMidiIn
, lpMidiInHdr
, uSize
);
1455 if (!(lpMidiInHdr
->dwFlags
& MHDR_PREPARED
)) {
1456 return MMSYSERR_NOERROR
;
1459 if ((wmld
= MMDRV_Get(hMidiIn
, MMDRV_MIDIIN
, FALSE
)) == NULL
)
1460 return MMSYSERR_INVALHANDLE
;
1462 return MMDRV_Message(wmld
, MIDM_UNPREPARE
, (DWORD
)lpMidiInHdr
, uSize
, TRUE
);
1465 /**************************************************************************
1466 * midiInAddBuffer [WINMM.@]
1468 UINT WINAPI
midiInAddBuffer(HMIDIIN hMidiIn
,
1469 MIDIHDR
* lpMidiInHdr
, UINT uSize
)
1473 TRACE("(%p, %p, %d)\n", hMidiIn
, lpMidiInHdr
, uSize
);
1475 if ((wmld
= MMDRV_Get(hMidiIn
, MMDRV_MIDIIN
, FALSE
)) == NULL
)
1476 return MMSYSERR_INVALHANDLE
;
1478 return MMDRV_Message(wmld
, MIDM_ADDBUFFER
, (DWORD
)lpMidiInHdr
, uSize
, TRUE
);
1481 /**************************************************************************
1482 * midiInStart [WINMM.@]
1484 UINT WINAPI
midiInStart(HMIDIIN hMidiIn
)
1488 TRACE("(%p)\n", hMidiIn
);
1490 if ((wmld
= MMDRV_Get(hMidiIn
, MMDRV_MIDIIN
, FALSE
)) == NULL
)
1491 return MMSYSERR_INVALHANDLE
;
1493 return MMDRV_Message(wmld
, MIDM_START
, 0L, 0L, TRUE
);
1496 /**************************************************************************
1497 * midiInStop [WINMM.@]
1499 UINT WINAPI
midiInStop(HMIDIIN hMidiIn
)
1503 TRACE("(%p)\n", hMidiIn
);
1505 if ((wmld
= MMDRV_Get(hMidiIn
, MMDRV_MIDIIN
, FALSE
)) == NULL
)
1506 return MMSYSERR_INVALHANDLE
;
1508 return MMDRV_Message(wmld
, MIDM_STOP
, 0L, 0L, TRUE
);
1511 /**************************************************************************
1512 * midiInReset [WINMM.@]
1514 UINT WINAPI
midiInReset(HMIDIIN hMidiIn
)
1518 TRACE("(%p)\n", hMidiIn
);
1520 if ((wmld
= MMDRV_Get(hMidiIn
, MMDRV_MIDIIN
, FALSE
)) == NULL
)
1521 return MMSYSERR_INVALHANDLE
;
1523 return MMDRV_Message(wmld
, MIDM_RESET
, 0L, 0L, TRUE
);
1526 /**************************************************************************
1527 * midiInGetID [WINMM.@]
1529 UINT WINAPI
midiInGetID(HMIDIIN hMidiIn
, UINT
* lpuDeviceID
)
1533 TRACE("(%p, %p)\n", hMidiIn
, lpuDeviceID
);
1535 if (lpuDeviceID
== NULL
) return MMSYSERR_INVALPARAM
;
1537 if ((wmld
= MMDRV_Get(hMidiIn
, MMDRV_MIDIIN
, TRUE
)) == NULL
)
1538 return MMSYSERR_INVALHANDLE
;
1540 *lpuDeviceID
= wmld
->uDeviceID
;
1542 return MMSYSERR_NOERROR
;
1545 /**************************************************************************
1546 * midiInMessage [WINMM.@]
1548 DWORD WINAPI
midiInMessage(HMIDIIN hMidiIn
, UINT uMessage
,
1549 DWORD dwParam1
, DWORD dwParam2
)
1553 TRACE("(%p, %04X, %08lX, %08lX)\n", hMidiIn
, uMessage
, dwParam1
, dwParam2
);
1555 if ((wmld
= MMDRV_Get(hMidiIn
, MMDRV_MIDIIN
, FALSE
)) == NULL
)
1556 return MMSYSERR_INVALHANDLE
;
1561 FIXME("can't handle OPEN or CLOSE message!\n");
1562 return MMSYSERR_NOTSUPPORTED
;
1564 return MMDRV_Message(wmld
, uMessage
, dwParam1
, dwParam2
, TRUE
);
1567 typedef struct WINE_MIDIStream
{
1578 LPMIDIHDR lpMidiHdr
;
1581 #define WINE_MSM_HEADER (WM_USER+0)
1582 #define WINE_MSM_STOP (WM_USER+1)
1584 /**************************************************************************
1585 * MMSYSTEM_GetMidiStream [internal]
1587 static BOOL
MMSYSTEM_GetMidiStream(HMIDISTRM hMidiStrm
, WINE_MIDIStream
** lpMidiStrm
, WINE_MIDI
** lplpwm
)
1589 WINE_MIDI
* lpwm
= (LPWINE_MIDI
)MMDRV_Get(hMidiStrm
, MMDRV_MIDIOUT
, FALSE
);
1598 *lpMidiStrm
= (WINE_MIDIStream
*)lpwm
->mod
.rgIds
.dwStreamID
;
1600 return *lpMidiStrm
!= NULL
;
1603 /**************************************************************************
1604 * MMSYSTEM_MidiStream_Convert [internal]
1606 static DWORD
MMSYSTEM_MidiStream_Convert(WINE_MIDIStream
* lpMidiStrm
, DWORD pulse
)
1610 if (lpMidiStrm
->dwTimeDiv
== 0) {
1611 FIXME("Shouldn't happen. lpMidiStrm->dwTimeDiv = 0\n");
1612 } else if (lpMidiStrm
->dwTimeDiv
> 0x8000) { /* SMPTE, unchecked FIXME? */
1613 int nf
= -(char)HIBYTE(lpMidiStrm
->dwTimeDiv
); /* number of frames */
1614 int nsf
= LOBYTE(lpMidiStrm
->dwTimeDiv
); /* number of sub-frames */
1615 ret
= (pulse
* 1000) / (nf
* nsf
);
1617 ret
= (DWORD
)((double)pulse
* ((double)lpMidiStrm
->dwTempo
/ 1000) /
1618 (double)lpMidiStrm
->dwTimeDiv
);
1624 /**************************************************************************
1625 * MMSYSTEM_MidiStream_MessageHandler [internal]
1627 static BOOL
MMSYSTEM_MidiStream_MessageHandler(WINE_MIDIStream
* lpMidiStrm
, LPWINE_MIDI lpwm
, LPMSG msg
)
1629 LPMIDIHDR lpMidiHdr
;
1633 switch (msg
->message
) {
1635 SetEvent(lpMidiStrm
->hEvent
);
1639 /* this is not quite what MS doc says... */
1640 midiOutReset(lpMidiStrm
->hDevice
);
1641 /* empty list of already submitted buffers */
1642 for (lpMidiHdr
= lpMidiStrm
->lpMidiHdr
; lpMidiHdr
; lpMidiHdr
= (LPMIDIHDR
)lpMidiHdr
->lpNext
) {
1643 lpMidiHdr
->dwFlags
|= MHDR_DONE
;
1644 lpMidiHdr
->dwFlags
&= ~MHDR_INQUEUE
;
1646 DriverCallback(lpwm
->mod
.dwCallback
, lpMidiStrm
->wFlags
,
1647 (HDRVR
)lpMidiStrm
->hDevice
, MM_MOM_DONE
,
1648 lpwm
->mod
.dwInstance
, (DWORD
)lpMidiHdr
, 0L);
1650 lpMidiStrm
->lpMidiHdr
= 0;
1651 SetEvent(lpMidiStrm
->hEvent
);
1653 case WINE_MSM_HEADER
:
1654 /* sets initial tick count for first MIDIHDR */
1655 if (!lpMidiStrm
->dwStartTicks
)
1656 lpMidiStrm
->dwStartTicks
= GetTickCount();
1658 /* FIXME(EPP): "I don't understand the content of the first MIDIHDR sent
1659 * by native mcimidi, it doesn't look like a correct one".
1660 * this trick allows to throw it away... but I don't like it.
1661 * It looks like part of the file I'm trying to play and definitively looks
1662 * like raw midi content
1663 * I'd really like to understand why native mcimidi sends it. Perhaps a bad
1664 * synchronization issue where native mcimidi is still processing raw MIDI
1665 * content before generating MIDIEVENTs ?
1667 * 4c 04 89 3b 00 81 7c 99 3b 43 00 99 23 5e 04 89 L..;..|.;C..#^..
1668 * 3b 00 00 89 23 00 7c 99 3b 45 00 99 28 62 04 89 ;...#.|.;E..(b..
1669 * 3b 00 00 89 28 00 81 7c 99 3b 4e 00 99 23 5e 04 ;...(..|.;N..#^.
1670 * 89 3b 00 00 89 23 00 7c 99 3b 45 00 99 23 78 04 .;...#.|.;E..#x.
1671 * 89 3b 00 00 89 23 00 81 7c 99 3b 48 00 99 23 5e .;...#..|.;H..#^
1672 * 04 89 3b 00 00 89 23 00 7c 99 3b 4e 00 99 28 62 ..;...#.|.;N..(b
1673 * 04 89 3b 00 00 89 28 00 81 7c 99 39 4c 00 99 23 ..;...(..|.9L..#
1674 * 5e 04 89 39 00 00 89 23 00 82 7c 99 3b 4c 00 99 ^..9...#..|.;L..
1675 * 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 00 99 #^..;...#.|.;H..
1676 * 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b 3f 04 (b..;...(..|.;?.
1677 * 89 3b 00 1c 99 23 5e 04 89 23 00 5c 99 3b 45 00 .;...#^..#.\.;E.
1678 * 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 3b 46 .#x..;...#..|.;F
1679 * 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 ..#^..;...#.|.;H
1680 * 00 99 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b ..(b..;...(..|.;
1681 * 46 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b F..#^..;...#.|.;
1682 * 48 00 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 H..#x..;...#..|.
1683 * 3b 4c 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 ;L..#^..;...#.|.
1685 lpMidiHdr
= (LPMIDIHDR
)msg
->lParam
;
1686 lpData
= lpMidiHdr
->lpData
;
1687 TRACE("Adding %s lpMidiHdr=%p [lpData=0x%08lx dwBufferLength=%lu/%lu dwFlags=0x%08lx size=%u]\n",
1688 (lpMidiHdr
->dwFlags
& MHDR_ISSTRM
) ? "stream" : "regular", lpMidiHdr
,
1689 (DWORD
)lpMidiHdr
, lpMidiHdr
->dwBufferLength
, lpMidiHdr
->dwBytesRecorded
,
1690 lpMidiHdr
->dwFlags
, msg
->wParam
);
1692 /* dumps content of lpMidiHdr->lpData
1693 * FIXME: there should be a debug routine somewhere that already does this
1694 * I hate spreading this type of shit all around the code
1696 for (dwToGo
= 0; dwToGo
< lpMidiHdr
->dwBufferLength
; dwToGo
+= 16) {
1700 for (i
= 0; i
< min(16, lpMidiHdr
->dwBufferLength
- dwToGo
); i
++)
1701 printf("%02x ", lpData
[dwToGo
+ i
]);
1704 for (i
= 0; i
< min(16, lpMidiHdr
->dwBufferLength
- dwToGo
); i
++) {
1705 ch
= lpData
[dwToGo
+ i
];
1706 printf("%c", (ch
>= 0x20 && ch
<= 0x7F) ? ch
: '.');
1711 if (((LPMIDIEVENT
)lpData
)->dwStreamID
!= 0 &&
1712 ((LPMIDIEVENT
)lpData
)->dwStreamID
!= 0xFFFFFFFF &&
1713 ((LPMIDIEVENT
)lpData
)->dwStreamID
!= (DWORD
)lpMidiStrm
) {
1714 FIXME("Dropping bad %s lpMidiHdr (streamID=%08lx)\n",
1715 (lpMidiHdr
->dwFlags
& MHDR_ISSTRM
) ? "stream" : "regular",
1716 ((LPMIDIEVENT
)lpData
)->dwStreamID
);
1717 lpMidiHdr
->dwFlags
|= MHDR_DONE
;
1718 lpMidiHdr
->dwFlags
&= ~MHDR_INQUEUE
;
1720 DriverCallback(lpwm
->mod
.dwCallback
, lpMidiStrm
->wFlags
,
1721 (HDRVR
)lpMidiStrm
->hDevice
, MM_MOM_DONE
,
1722 lpwm
->mod
.dwInstance
, (DWORD
)lpMidiHdr
, 0L);
1726 for (lpmh
= &lpMidiStrm
->lpMidiHdr
; *lpmh
; lpmh
= (LPMIDIHDR
*)&((*lpmh
)->lpNext
));
1728 lpMidiHdr
= (LPMIDIHDR
)msg
->lParam
;
1729 lpMidiHdr
->lpNext
= 0;
1730 lpMidiHdr
->dwFlags
|= MHDR_INQUEUE
;
1731 lpMidiHdr
->dwFlags
&= MHDR_DONE
;
1732 lpMidiHdr
->dwOffset
= 0;
1736 FIXME("Unknown message %d\n", msg
->message
);
1742 /**************************************************************************
1743 * MMSYSTEM_MidiStream_Player [internal]
1745 static DWORD CALLBACK
MMSYSTEM_MidiStream_Player(LPVOID pmt
)
1747 WINE_MIDIStream
* lpMidiStrm
= pmt
;
1752 LPMIDIHDR lpMidiHdr
;
1756 TRACE("(%p)!\n", lpMidiStrm
);
1759 (lpwm
= (LPWINE_MIDI
)MMDRV_Get(lpMidiStrm
->hDevice
, MMDRV_MIDIOUT
, FALSE
)) == NULL
)
1762 /* force thread's queue creation */
1763 /* Used to be InitThreadInput16(0, 5); */
1764 /* but following works also with hack in midiStreamOpen */
1765 PeekMessageA(&msg
, 0, 0, 0, 0);
1767 /* FIXME: this next line must be called before midiStreamOut or midiStreamRestart are called */
1768 SetEvent(lpMidiStrm
->hEvent
);
1769 TRACE("Ready to go 1\n");
1770 /* thread is started in paused mode */
1771 SuspendThread(lpMidiStrm
->hThread
);
1772 TRACE("Ready to go 2\n");
1774 lpMidiStrm
->dwStartTicks
= 0;
1775 lpMidiStrm
->dwPulses
= 0;
1777 lpMidiStrm
->lpMidiHdr
= 0;
1780 lpMidiHdr
= lpMidiStrm
->lpMidiHdr
;
1782 /* for first message, block until one arrives, then process all that are available */
1783 GetMessageA(&msg
, 0, 0, 0);
1785 if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm
, lpwm
, &msg
))
1787 } while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
));
1793 lpData
= lpMidiHdr
->lpData
;
1795 me
= (LPMIDIEVENT
)(lpData
+ lpMidiHdr
->dwOffset
);
1797 /* do we have to wait ? */
1798 if (me
->dwDeltaTime
) {
1799 lpMidiStrm
->dwPositionMS
+= MMSYSTEM_MidiStream_Convert(lpMidiStrm
, me
->dwDeltaTime
);
1800 lpMidiStrm
->dwPulses
+= me
->dwDeltaTime
;
1802 dwToGo
= lpMidiStrm
->dwStartTicks
+ lpMidiStrm
->dwPositionMS
;
1804 TRACE("%ld/%ld/%ld\n", dwToGo
, GetTickCount(), me
->dwDeltaTime
);
1805 while ((dwCurrTC
= GetTickCount()) < dwToGo
) {
1806 if (MsgWaitForMultipleObjects(0, NULL
, FALSE
, dwToGo
- dwCurrTC
, QS_ALLINPUT
) == WAIT_OBJECT_0
) {
1807 /* got a message, handle it */
1808 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) {
1809 if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm
, lpwm
, &msg
))
1814 /* timeout, so me->dwDeltaTime is elapsed, can break the while loop */
1819 switch (MEVT_EVENTTYPE(me
->dwEvent
& ~MEVT_F_CALLBACK
)) {
1821 FIXME("NIY: MEVT_COMMENT\n");
1822 /* do nothing, skip bytes */
1825 FIXME("NIY: MEVT_LONGMSG, aka sending Sysex event\n");
1830 midiOutShortMsg(lpMidiStrm
->hDevice
, MEVT_EVENTPARM(me
->dwEvent
));
1833 lpMidiStrm
->dwTempo
= MEVT_EVENTPARM(me
->dwEvent
);
1838 FIXME("Unknown MEVT (0x%02x)\n", MEVT_EVENTTYPE(me
->dwEvent
& ~MEVT_F_CALLBACK
));
1841 if (me
->dwEvent
& MEVT_F_CALLBACK
) {
1842 DriverCallback(lpwm
->mod
.dwCallback
, lpMidiStrm
->wFlags
,
1843 (HDRVR
)lpMidiStrm
->hDevice
, MM_MOM_POSITIONCB
,
1844 lpwm
->mod
.dwInstance
, (LPARAM
)lpMidiHdr
, 0L);
1846 lpMidiHdr
->dwOffset
+= sizeof(MIDIEVENT
) - sizeof(me
->dwParms
);
1847 if (me
->dwEvent
& MEVT_F_LONG
)
1848 lpMidiHdr
->dwOffset
+= (MEVT_EVENTPARM(me
->dwEvent
) + 3) & ~3;
1849 if (lpMidiHdr
->dwOffset
>= lpMidiHdr
->dwBufferLength
) {
1850 /* done with this header */
1851 lpMidiHdr
->dwFlags
|= MHDR_DONE
;
1852 lpMidiHdr
->dwFlags
&= ~MHDR_INQUEUE
;
1854 lpMidiStrm
->lpMidiHdr
= (LPMIDIHDR
)lpMidiHdr
->lpNext
;
1855 DriverCallback(lpwm
->mod
.dwCallback
, lpMidiStrm
->wFlags
,
1856 (HDRVR
)lpMidiStrm
->hDevice
, MM_MOM_DONE
,
1857 lpwm
->mod
.dwInstance
, (DWORD
)lpMidiHdr
, 0L);
1862 TRACE("End of thread\n");
1864 return 0; /* for removing the warning, never executed */
1867 /**************************************************************************
1868 * MMSYSTEM_MidiStream_PostMessage [internal]
1870 static BOOL
MMSYSTEM_MidiStream_PostMessage(WINE_MIDIStream
* lpMidiStrm
, WORD msg
, DWORD pmt1
, DWORD pmt2
)
1872 if (PostThreadMessageA(lpMidiStrm
->dwThreadID
, msg
, pmt1
, pmt2
)) {
1875 ReleaseThunkLock(&count
);
1876 WaitForSingleObject(lpMidiStrm
->hEvent
, INFINITE
);
1877 RestoreThunkLock(count
);
1879 WARN("bad PostThreadMessageA\n");
1885 /**************************************************************************
1886 * midiStreamClose [WINMM.@]
1888 MMRESULT WINAPI
midiStreamClose(HMIDISTRM hMidiStrm
)
1890 WINE_MIDIStream
* lpMidiStrm
;
1892 TRACE("(%p)!\n", hMidiStrm
);
1894 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
))
1895 return MMSYSERR_INVALHANDLE
;
1897 midiStreamStop(hMidiStrm
);
1898 MMSYSTEM_MidiStream_PostMessage(lpMidiStrm
, WM_QUIT
, 0, 0);
1899 HeapFree(GetProcessHeap(), 0, lpMidiStrm
);
1900 CloseHandle(lpMidiStrm
->hEvent
);
1902 return midiOutClose((HMIDIOUT
)hMidiStrm
);
1905 /**************************************************************************
1906 * MMSYSTEM_MidiStream_Open [internal]
1908 MMRESULT
MIDI_StreamOpen(HMIDISTRM
* lphMidiStrm
, LPUINT lpuDeviceID
, DWORD cMidi
,
1909 DWORD dwCallback
, DWORD dwInstance
, DWORD fdwOpen
,
1912 WINE_MIDIStream
* lpMidiStrm
;
1914 MIDIOPENSTRMID mosm
;
1918 TRACE("(%p, %p, %ld, 0x%08lx, 0x%08lx, 0x%08lx)!\n",
1919 lphMidiStrm
, lpuDeviceID
, cMidi
, dwCallback
, dwInstance
, fdwOpen
);
1921 if (cMidi
!= 1 || lphMidiStrm
== NULL
|| lpuDeviceID
== NULL
)
1922 return MMSYSERR_INVALPARAM
;
1924 lpMidiStrm
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_MIDIStream
));
1926 return MMSYSERR_NOMEM
;
1928 lpMidiStrm
->dwTempo
= 500000;
1929 lpMidiStrm
->dwTimeDiv
= 480; /* 480 is 120 quater notes per minute *//* FIXME ??*/
1930 lpMidiStrm
->dwPositionMS
= 0;
1932 mosm
.dwStreamID
= (DWORD
)lpMidiStrm
;
1933 /* FIXME: the correct value is not allocated yet for MAPPER */
1934 mosm
.wDeviceID
= *lpuDeviceID
;
1935 lpwm
= MIDI_OutAlloc(&hMidiOut
, &dwCallback
, &dwInstance
, &fdwOpen
, 1, &mosm
, bFrom32
);
1936 lpMidiStrm
->hDevice
= hMidiOut
;
1938 *lphMidiStrm
= (HMIDISTRM
)hMidiOut
;
1940 /* FIXME: is lpuDevice initialized upon entering midiStreamOpen ? */
1941 FIXME("*lpuDeviceID=%x\n", *lpuDeviceID
);
1942 lpwm
->mld
.uDeviceID
= *lpuDeviceID
= 0;
1944 ret
= MMDRV_Open(&lpwm
->mld
, MODM_OPEN
, (DWORD
)&lpwm
->mod
, fdwOpen
);
1945 lpMidiStrm
->hEvent
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
1946 lpMidiStrm
->wFlags
= HIWORD(fdwOpen
);
1948 lpMidiStrm
->hThread
= CreateThread(NULL
, 0, MMSYSTEM_MidiStream_Player
,
1949 lpMidiStrm
, 0, &(lpMidiStrm
->dwThreadID
));
1951 if (!lpMidiStrm
->hThread
) {
1952 midiStreamClose((HMIDISTRM
)hMidiOut
);
1953 return MMSYSERR_NOMEM
;
1956 /* wait for thread to have started, and for its queue to be created */
1960 /* (Release|Restore)ThunkLock() is needed when this method is called from 16 bit code,
1961 * (meaning the Win16Lock is set), so that it's released and the 32 bit thread running
1962 * MMSYSTEM_MidiStreamPlayer can acquire Win16Lock to create its queue.
1964 ReleaseThunkLock(&count
);
1965 WaitForSingleObject(lpMidiStrm
->hEvent
, INFINITE
);
1966 RestoreThunkLock(count
);
1969 TRACE("=> (%u/%d) hMidi=%p ret=%d lpMidiStrm=%p\n",
1970 *lpuDeviceID
, lpwm
->mld
.uDeviceID
, *lphMidiStrm
, ret
, lpMidiStrm
);
1974 /**************************************************************************
1975 * midiStreamOpen [WINMM.@]
1977 MMRESULT WINAPI
midiStreamOpen(HMIDISTRM
* lphMidiStrm
, LPUINT lpuDeviceID
,
1978 DWORD cMidi
, DWORD dwCallback
,
1979 DWORD dwInstance
, DWORD fdwOpen
)
1981 return MIDI_StreamOpen(lphMidiStrm
, lpuDeviceID
, cMidi
, dwCallback
,
1982 dwInstance
, fdwOpen
, TRUE
);
1985 /**************************************************************************
1986 * midiStreamOut [WINMM.@]
1988 MMRESULT WINAPI
midiStreamOut(HMIDISTRM hMidiStrm
, LPMIDIHDR lpMidiHdr
,
1991 WINE_MIDIStream
* lpMidiStrm
;
1992 DWORD ret
= MMSYSERR_NOERROR
;
1994 TRACE("(%p, %p, %u)!\n", hMidiStrm
, lpMidiHdr
, cbMidiHdr
);
1996 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
)) {
1997 ret
= MMSYSERR_INVALHANDLE
;
1998 } else if (!lpMidiHdr
) {
1999 ret
= MMSYSERR_INVALPARAM
;
2001 if (!PostThreadMessageA(lpMidiStrm
->dwThreadID
,
2002 WINE_MSM_HEADER
, cbMidiHdr
,
2003 (DWORD
)lpMidiHdr
)) {
2004 WARN("bad PostThreadMessageA\n");
2005 ret
= MMSYSERR_ERROR
;
2011 /**************************************************************************
2012 * midiStreamPause [WINMM.@]
2014 MMRESULT WINAPI
midiStreamPause(HMIDISTRM hMidiStrm
)
2016 WINE_MIDIStream
* lpMidiStrm
;
2017 DWORD ret
= MMSYSERR_NOERROR
;
2019 TRACE("(%p)!\n", hMidiStrm
);
2021 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
)) {
2022 ret
= MMSYSERR_INVALHANDLE
;
2024 if (SuspendThread(lpMidiStrm
->hThread
) == 0xFFFFFFFF) {
2025 WARN("bad Suspend (%ld)\n", GetLastError());
2026 ret
= MMSYSERR_ERROR
;
2032 /**************************************************************************
2033 * midiStreamPosition [WINMM.@]
2035 MMRESULT WINAPI
midiStreamPosition(HMIDISTRM hMidiStrm
, LPMMTIME lpMMT
, UINT cbmmt
)
2037 WINE_MIDIStream
* lpMidiStrm
;
2038 DWORD ret
= MMSYSERR_NOERROR
;
2040 TRACE("(%p, %p, %u)!\n", hMidiStrm
, lpMMT
, cbmmt
);
2042 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
)) {
2043 ret
= MMSYSERR_INVALHANDLE
;
2044 } else if (lpMMT
== NULL
|| cbmmt
!= sizeof(MMTIME
)) {
2045 ret
= MMSYSERR_INVALPARAM
;
2047 switch (lpMMT
->wType
) {
2049 lpMMT
->u
.ms
= lpMidiStrm
->dwPositionMS
;
2050 TRACE("=> %ld ms\n", lpMMT
->u
.ms
);
2053 lpMMT
->u
.ticks
= lpMidiStrm
->dwPulses
;
2054 TRACE("=> %ld ticks\n", lpMMT
->u
.ticks
);
2057 WARN("Unsupported time type %d\n", lpMMT
->wType
);
2058 lpMMT
->wType
= TIME_MS
;
2059 ret
= MMSYSERR_INVALPARAM
;
2066 /**************************************************************************
2067 * midiStreamProperty [WINMM.@]
2069 MMRESULT WINAPI
midiStreamProperty(HMIDISTRM hMidiStrm
, LPBYTE lpPropData
, DWORD dwProperty
)
2071 WINE_MIDIStream
* lpMidiStrm
;
2072 MMRESULT ret
= MMSYSERR_NOERROR
;
2074 TRACE("(%p, %p, %lx)\n", hMidiStrm
, lpPropData
, dwProperty
);
2076 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
)) {
2077 ret
= MMSYSERR_INVALHANDLE
;
2078 } else if ((dwProperty
& (MIDIPROP_GET
|MIDIPROP_SET
)) == 0) {
2079 ret
= MMSYSERR_INVALPARAM
;
2080 } else if (dwProperty
& MIDIPROP_TEMPO
) {
2081 MIDIPROPTEMPO
* mpt
= (MIDIPROPTEMPO
*)lpPropData
;
2083 if (sizeof(MIDIPROPTEMPO
) != mpt
->cbStruct
) {
2084 ret
= MMSYSERR_INVALPARAM
;
2085 } else if (dwProperty
& MIDIPROP_SET
) {
2086 lpMidiStrm
->dwTempo
= mpt
->dwTempo
;
2087 TRACE("Setting tempo to %ld\n", mpt
->dwTempo
);
2088 } else if (dwProperty
& MIDIPROP_GET
) {
2089 mpt
->dwTempo
= lpMidiStrm
->dwTempo
;
2090 TRACE("Getting tempo <= %ld\n", mpt
->dwTempo
);
2092 } else if (dwProperty
& MIDIPROP_TIMEDIV
) {
2093 MIDIPROPTIMEDIV
* mptd
= (MIDIPROPTIMEDIV
*)lpPropData
;
2095 if (sizeof(MIDIPROPTIMEDIV
) != mptd
->cbStruct
) {
2096 ret
= MMSYSERR_INVALPARAM
;
2097 } else if (dwProperty
& MIDIPROP_SET
) {
2098 lpMidiStrm
->dwTimeDiv
= mptd
->dwTimeDiv
;
2099 TRACE("Setting time div to %ld\n", mptd
->dwTimeDiv
);
2100 } else if (dwProperty
& MIDIPROP_GET
) {
2101 mptd
->dwTimeDiv
= lpMidiStrm
->dwTimeDiv
;
2102 TRACE("Getting time div <= %ld\n", mptd
->dwTimeDiv
);
2105 ret
= MMSYSERR_INVALPARAM
;
2111 /**************************************************************************
2112 * midiStreamRestart [WINMM.@]
2114 MMRESULT WINAPI
midiStreamRestart(HMIDISTRM hMidiStrm
)
2116 WINE_MIDIStream
* lpMidiStrm
;
2117 MMRESULT ret
= MMSYSERR_NOERROR
;
2119 TRACE("(%p)!\n", hMidiStrm
);
2121 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
)) {
2122 ret
= MMSYSERR_INVALHANDLE
;
2126 /* since we increase the thread suspend count on each midiStreamPause
2127 * there may be a need for several midiStreamResume
2130 ret
= ResumeThread(lpMidiStrm
->hThread
);
2131 } while (ret
!= 0xFFFFFFFF && ret
!= 0);
2132 if (ret
== 0xFFFFFFFF) {
2133 WARN("bad Resume (%ld)\n", GetLastError());
2134 ret
= MMSYSERR_ERROR
;
2136 lpMidiStrm
->dwStartTicks
= GetTickCount() - lpMidiStrm
->dwPositionMS
;
2142 /**************************************************************************
2143 * midiStreamStop [WINMM.@]
2145 MMRESULT WINAPI
midiStreamStop(HMIDISTRM hMidiStrm
)
2147 WINE_MIDIStream
* lpMidiStrm
;
2148 MMRESULT ret
= MMSYSERR_NOERROR
;
2150 TRACE("(%p)!\n", hMidiStrm
);
2152 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
)) {
2153 ret
= MMSYSERR_INVALHANDLE
;
2155 /* in case stream has been paused... FIXME is the current state correct ? */
2156 midiStreamRestart(hMidiStrm
);
2157 MMSYSTEM_MidiStream_PostMessage(lpMidiStrm
, WINE_MSM_STOP
, 0, 0);
2162 UINT
WAVE_Open(HANDLE
* lphndl
, UINT uDeviceID
, UINT uType
,
2163 const LPWAVEFORMATEX lpFormat
, DWORD dwCallback
,
2164 DWORD dwInstance
, DWORD dwFlags
, BOOL bFrom32
)
2168 DWORD dwRet
= MMSYSERR_NOERROR
;
2171 TRACE("(%p, %d, %s, %p, %08lX, %08lX, %08lX, %d);\n",
2172 lphndl
, (int)uDeviceID
, (uType
==MMDRV_WAVEOUT
)?"Out":"In", lpFormat
, dwCallback
,
2173 dwInstance
, dwFlags
, bFrom32
?32:16);
2175 if (dwFlags
& WAVE_FORMAT_QUERY
) TRACE("WAVE_FORMAT_QUERY requested !\n");
2177 if (lpFormat
== NULL
) return WAVERR_BADFORMAT
;
2178 if ((dwFlags
& WAVE_MAPPED
) && (uDeviceID
== (UINT
)-1))
2179 return MMSYSERR_INVALPARAM
;
2181 TRACE("wFormatTag=%u, nChannels=%u, nSamplesPerSec=%lu, nAvgBytesPerSec=%lu, nBlockAlign=%u, wBitsPerSample=%u, cbSize=%u\n",
2182 lpFormat
->wFormatTag
, lpFormat
->nChannels
, lpFormat
->nSamplesPerSec
,
2183 lpFormat
->nAvgBytesPerSec
, lpFormat
->nBlockAlign
, lpFormat
->wBitsPerSample
, lpFormat
->cbSize
);
2185 if ((wmld
= MMDRV_Alloc(sizeof(WINE_WAVE
), uType
, &handle
,
2186 &dwFlags
, &dwCallback
, &dwInstance
, bFrom32
)) == NULL
)
2187 return MMSYSERR_NOMEM
;
2190 wod
.lpFormat
= lpFormat
; /* should the struct be copied iso pointer? */
2191 wod
.dwCallback
= dwCallback
;
2192 wod
.dwInstance
= dwInstance
;
2195 TRACE("cb=%08lx\n", wod
.dwCallback
);
2198 if (dwFlags
& WAVE_MAPPED
) {
2199 wod
.uMappedDeviceID
= uDeviceID
;
2200 uDeviceID
= WAVE_MAPPER
;
2202 wod
.uMappedDeviceID
= -1;
2204 wmld
->uDeviceID
= uDeviceID
;
2206 dwRet
= MMDRV_Open(wmld
, (uType
== MMDRV_WAVEOUT
) ? WODM_OPEN
: WIDM_OPEN
,
2207 (DWORD
)&wod
, dwFlags
);
2209 if (dwRet
!= WAVERR_BADFORMAT
||
2210 (dwFlags
& (WAVE_MAPPED
|WAVE_FORMAT_DIRECT
)) != 0) break;
2211 /* if we ask for a format which isn't supported by the physical driver,
2212 * let's try to map it through the wave mapper (except, if we already tried
2213 * or user didn't allow us to use acm codecs)
2215 dwFlags
|= WAVE_MAPPED
;
2216 /* we shall loop only one */
2219 if ((dwFlags
& WAVE_FORMAT_QUERY
) || dwRet
!= MMSYSERR_NOERROR
) {
2220 MMDRV_Free(handle
, wmld
);
2224 if (lphndl
!= NULL
) *lphndl
= handle
;
2225 TRACE("=> %ld hWave=%p\n", dwRet
, handle
);
2230 /**************************************************************************
2231 * waveOutGetNumDevs [WINMM.@]
2233 UINT WINAPI
waveOutGetNumDevs(void)
2235 return MMDRV_GetNum(MMDRV_WAVEOUT
);
2238 /**************************************************************************
2239 * waveOutGetDevCapsA [WINMM.@]
2241 UINT WINAPI
waveOutGetDevCapsA(UINT uDeviceID
, LPWAVEOUTCAPSA lpCaps
,
2246 TRACE("(%u %p %u)!\n", uDeviceID
, lpCaps
, uSize
);
2248 if (lpCaps
== NULL
) return MMSYSERR_INVALPARAM
;
2250 if ((wmld
= MMDRV_Get((HANDLE
)uDeviceID
, MMDRV_WAVEOUT
, TRUE
)) == NULL
)
2251 return MMSYSERR_BADDEVICEID
;
2253 return MMDRV_Message(wmld
, WODM_GETDEVCAPS
, (DWORD
)lpCaps
, uSize
, TRUE
);
2257 /**************************************************************************
2258 * waveOutGetDevCapsW [WINMM.@]
2260 UINT WINAPI
waveOutGetDevCapsW(UINT uDeviceID
, LPWAVEOUTCAPSW lpCaps
,
2266 if (lpCaps
== NULL
) return MMSYSERR_INVALPARAM
;
2268 ret
= waveOutGetDevCapsA(uDeviceID
, &wocA
, sizeof(wocA
));
2270 if (ret
== MMSYSERR_NOERROR
) {
2271 lpCaps
->wMid
= wocA
.wMid
;
2272 lpCaps
->wPid
= wocA
.wPid
;
2273 lpCaps
->vDriverVersion
= wocA
.vDriverVersion
;
2274 MultiByteToWideChar( CP_ACP
, 0, wocA
.szPname
, -1, lpCaps
->szPname
,
2275 sizeof(lpCaps
->szPname
)/sizeof(WCHAR
) );
2276 lpCaps
->dwFormats
= wocA
.dwFormats
;
2277 lpCaps
->wChannels
= wocA
.wChannels
;
2278 lpCaps
->dwSupport
= wocA
.dwSupport
;
2283 /**************************************************************************
2284 * WAVE_GetErrorText [internal]
2286 static UINT16
WAVE_GetErrorText(UINT16 uError
, LPSTR lpText
, UINT16 uSize
)
2288 UINT16 ret
= MMSYSERR_BADERRNUM
;
2290 if (lpText
== NULL
) {
2291 ret
= MMSYSERR_INVALPARAM
;
2292 } else if (uSize
== 0) {
2293 ret
= MMSYSERR_NOERROR
;
2295 /* test has been removed 'coz MMSYSERR_BASE is 0, and gcc did emit
2296 * a warning for the test was always true */
2297 (/*uError >= MMSYSERR_BASE && */uError
<= MMSYSERR_LASTERROR
) ||
2298 (uError
>= WAVERR_BASE
&& uError
<= WAVERR_LASTERROR
)) {
2300 if (LoadStringA(WINMM_IData
->hWinMM32Instance
,
2301 uError
, lpText
, uSize
) > 0) {
2302 ret
= MMSYSERR_NOERROR
;
2308 /**************************************************************************
2309 * waveOutGetErrorTextA [WINMM.@]
2311 UINT WINAPI
waveOutGetErrorTextA(UINT uError
, LPSTR lpText
, UINT uSize
)
2313 return WAVE_GetErrorText(uError
, lpText
, uSize
);
2316 /**************************************************************************
2317 * waveOutGetErrorTextW [WINMM.@]
2319 UINT WINAPI
waveOutGetErrorTextW(UINT uError
, LPWSTR lpText
, UINT uSize
)
2321 LPSTR xstr
= HeapAlloc(GetProcessHeap(), 0, uSize
);
2322 UINT ret
= WAVE_GetErrorText(uError
, xstr
, uSize
);
2324 MultiByteToWideChar( CP_ACP
, 0, xstr
, -1, lpText
, uSize
);
2325 HeapFree(GetProcessHeap(), 0, xstr
);
2329 /**************************************************************************
2330 * waveOutOpen [WINMM.@]
2331 * All the args/structs have the same layout as the win16 equivalents
2333 UINT WINAPI
waveOutOpen(HWAVEOUT
* lphWaveOut
, UINT uDeviceID
,
2334 const LPWAVEFORMATEX lpFormat
, DWORD dwCallback
,
2335 DWORD dwInstance
, DWORD dwFlags
)
2337 return WAVE_Open((HANDLE
*)lphWaveOut
, uDeviceID
, MMDRV_WAVEOUT
, lpFormat
,
2338 dwCallback
, dwInstance
, dwFlags
, TRUE
);
2341 /**************************************************************************
2342 * waveOutClose [WINMM.@]
2344 UINT WINAPI
waveOutClose(HWAVEOUT hWaveOut
)
2349 TRACE("(%p)\n", hWaveOut
);
2351 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2352 return MMSYSERR_INVALHANDLE
;
2354 dwRet
= MMDRV_Close(wmld
, WODM_CLOSE
);
2355 MMDRV_Free(hWaveOut
, wmld
);
2360 /**************************************************************************
2361 * waveOutPrepareHeader [WINMM.@]
2363 UINT WINAPI
waveOutPrepareHeader(HWAVEOUT hWaveOut
,
2364 WAVEHDR
* lpWaveOutHdr
, UINT uSize
)
2368 TRACE("(%p, %p, %u);\n", hWaveOut
, lpWaveOutHdr
, uSize
);
2370 if (lpWaveOutHdr
== NULL
) return MMSYSERR_INVALPARAM
;
2372 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2373 return MMSYSERR_INVALHANDLE
;
2375 return MMDRV_Message(wmld
, WODM_PREPARE
, (DWORD
)lpWaveOutHdr
, uSize
, TRUE
);
2378 /**************************************************************************
2379 * waveOutUnprepareHeader [WINMM.@]
2381 UINT WINAPI
waveOutUnprepareHeader(HWAVEOUT hWaveOut
,
2382 LPWAVEHDR lpWaveOutHdr
, UINT uSize
)
2386 TRACE("(%p, %p, %u);\n", hWaveOut
, lpWaveOutHdr
, uSize
);
2388 if (!(lpWaveOutHdr
->dwFlags
& WHDR_PREPARED
)) {
2389 return MMSYSERR_NOERROR
;
2392 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2393 return MMSYSERR_INVALHANDLE
;
2395 return MMDRV_Message(wmld
, WODM_UNPREPARE
, (DWORD
)lpWaveOutHdr
, uSize
, TRUE
);
2398 /**************************************************************************
2399 * waveOutWrite [WINMM.@]
2401 UINT WINAPI
waveOutWrite(HWAVEOUT hWaveOut
, LPWAVEHDR lpWaveOutHdr
,
2406 TRACE("(%p, %p, %u);\n", hWaveOut
, lpWaveOutHdr
, uSize
);
2408 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2409 return MMSYSERR_INVALHANDLE
;
2411 return MMDRV_Message(wmld
, WODM_WRITE
, (DWORD
)lpWaveOutHdr
, uSize
, TRUE
);
2414 /**************************************************************************
2415 * waveOutBreakLoop [WINMM.@]
2417 UINT WINAPI
waveOutBreakLoop(HWAVEOUT hWaveOut
)
2421 TRACE("(%p);\n", hWaveOut
);
2423 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2424 return MMSYSERR_INVALHANDLE
;
2425 return MMDRV_Message(wmld
, WODM_BREAKLOOP
, 0L, 0L, TRUE
);
2428 /**************************************************************************
2429 * waveOutPause [WINMM.@]
2431 UINT WINAPI
waveOutPause(HWAVEOUT hWaveOut
)
2435 TRACE("(%p);\n", hWaveOut
);
2437 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2438 return MMSYSERR_INVALHANDLE
;
2439 return MMDRV_Message(wmld
, WODM_PAUSE
, 0L, 0L, TRUE
);
2442 /**************************************************************************
2443 * waveOutReset [WINMM.@]
2445 UINT WINAPI
waveOutReset(HWAVEOUT hWaveOut
)
2449 TRACE("(%p);\n", hWaveOut
);
2451 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2452 return MMSYSERR_INVALHANDLE
;
2453 return MMDRV_Message(wmld
, WODM_RESET
, 0L, 0L, TRUE
);
2456 /**************************************************************************
2457 * waveOutRestart [WINMM.@]
2459 UINT WINAPI
waveOutRestart(HWAVEOUT hWaveOut
)
2463 TRACE("(%p);\n", hWaveOut
);
2465 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2466 return MMSYSERR_INVALHANDLE
;
2467 return MMDRV_Message(wmld
, WODM_RESTART
, 0L, 0L, TRUE
);
2470 /**************************************************************************
2471 * waveOutGetPosition [WINMM.@]
2473 UINT WINAPI
waveOutGetPosition(HWAVEOUT hWaveOut
, LPMMTIME lpTime
,
2478 TRACE("(%p, %p, %u);\n", hWaveOut
, lpTime
, uSize
);
2480 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2481 return MMSYSERR_INVALHANDLE
;
2483 return MMDRV_Message(wmld
, WODM_GETPOS
, (DWORD
)lpTime
, uSize
, TRUE
);
2486 /**************************************************************************
2487 * waveOutGetPitch [WINMM.@]
2489 UINT WINAPI
waveOutGetPitch(HWAVEOUT hWaveOut
, LPDWORD lpdw
)
2493 TRACE("(%p, %08lx);\n", hWaveOut
, (DWORD
)lpdw
);
2495 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2496 return MMSYSERR_INVALHANDLE
;
2497 return MMDRV_Message(wmld
, WODM_GETPITCH
, (DWORD
)lpdw
, 0L, TRUE
);
2500 /**************************************************************************
2501 * waveOutSetPitch [WINMM.@]
2503 UINT WINAPI
waveOutSetPitch(HWAVEOUT hWaveOut
, DWORD dw
)
2507 TRACE("(%p, %08lx);\n", hWaveOut
, (DWORD
)dw
);
2509 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2510 return MMSYSERR_INVALHANDLE
;
2511 return MMDRV_Message(wmld
, WODM_SETPITCH
, dw
, 0L, TRUE
);
2514 /**************************************************************************
2515 * waveOutGetPlaybackRate [WINMM.@]
2517 UINT WINAPI
waveOutGetPlaybackRate(HWAVEOUT hWaveOut
, LPDWORD lpdw
)
2521 TRACE("(%p, %08lx);\n", hWaveOut
, (DWORD
)lpdw
);
2523 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2524 return MMSYSERR_INVALHANDLE
;
2525 return MMDRV_Message(wmld
, WODM_GETPLAYBACKRATE
, (DWORD
)lpdw
, 0L, TRUE
);
2528 /**************************************************************************
2529 * waveOutSetPlaybackRate [WINMM.@]
2531 UINT WINAPI
waveOutSetPlaybackRate(HWAVEOUT hWaveOut
, DWORD dw
)
2535 TRACE("(%p, %08lx);\n", hWaveOut
, (DWORD
)dw
);
2537 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2538 return MMSYSERR_INVALHANDLE
;
2539 return MMDRV_Message(wmld
, WODM_SETPLAYBACKRATE
, dw
, 0L, TRUE
);
2542 /**************************************************************************
2543 * waveOutGetVolume [WINMM.@]
2545 UINT WINAPI
waveOutGetVolume(HWAVEOUT hWaveOut
, LPDWORD lpdw
)
2549 TRACE("(%p, %08lx);\n", hWaveOut
, (DWORD
)lpdw
);
2551 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, TRUE
)) == NULL
)
2552 return MMSYSERR_INVALHANDLE
;
2554 return MMDRV_Message(wmld
, WODM_GETVOLUME
, (DWORD
)lpdw
, 0L, TRUE
);
2557 /**************************************************************************
2558 * waveOutSetVolume [WINMM.@]
2560 UINT WINAPI
waveOutSetVolume(HWAVEOUT hWaveOut
, DWORD dw
)
2564 TRACE("(%p, %08lx);\n", hWaveOut
, dw
);
2566 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, TRUE
)) == NULL
)
2567 return MMSYSERR_INVALHANDLE
;
2569 return MMDRV_Message(wmld
, WODM_SETVOLUME
, dw
, 0L, TRUE
);
2572 /**************************************************************************
2573 * waveOutGetID [WINMM.@]
2575 UINT WINAPI
waveOutGetID(HWAVEOUT hWaveOut
, UINT
* lpuDeviceID
)
2579 TRACE("(%p, %p);\n", hWaveOut
, lpuDeviceID
);
2581 if (lpuDeviceID
== NULL
) return MMSYSERR_INVALHANDLE
;
2583 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2584 return MMSYSERR_INVALHANDLE
;
2586 *lpuDeviceID
= wmld
->uDeviceID
;
2590 /**************************************************************************
2591 * waveOutMessage [WINMM.@]
2593 DWORD WINAPI
waveOutMessage(HWAVEOUT hWaveOut
, UINT uMessage
,
2594 DWORD dwParam1
, DWORD dwParam2
)
2598 TRACE("(%p, %u, %ld, %ld)\n", hWaveOut
, uMessage
, dwParam1
, dwParam2
);
2600 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
) {
2601 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, TRUE
)) != NULL
) {
2602 return MMDRV_PhysicalFeatures(wmld
, uMessage
, dwParam1
, dwParam2
);
2604 return MMSYSERR_INVALHANDLE
;
2608 if (uMessage
< DRVM_IOCTL
|| (uMessage
>= DRVM_IOCTL_LAST
&& uMessage
< DRVM_MAPPER
))
2609 return MMSYSERR_INVALPARAM
;
2611 return MMDRV_Message(wmld
, uMessage
, dwParam1
, dwParam2
, TRUE
);
2614 /**************************************************************************
2615 * waveInGetNumDevs [WINMM.@]
2617 UINT WINAPI
waveInGetNumDevs(void)
2619 return MMDRV_GetNum(MMDRV_WAVEIN
);
2622 /**************************************************************************
2623 * waveInGetDevCapsW [WINMM.@]
2625 UINT WINAPI
waveInGetDevCapsW(UINT uDeviceID
, LPWAVEINCAPSW lpCaps
, UINT uSize
)
2628 UINT ret
= waveInGetDevCapsA(uDeviceID
, &wicA
, uSize
);
2630 if (ret
== MMSYSERR_NOERROR
) {
2631 lpCaps
->wMid
= wicA
.wMid
;
2632 lpCaps
->wPid
= wicA
.wPid
;
2633 lpCaps
->vDriverVersion
= wicA
.vDriverVersion
;
2634 MultiByteToWideChar( CP_ACP
, 0, wicA
.szPname
, -1, lpCaps
->szPname
,
2635 sizeof(lpCaps
->szPname
)/sizeof(WCHAR
) );
2636 lpCaps
->dwFormats
= wicA
.dwFormats
;
2637 lpCaps
->wChannels
= wicA
.wChannels
;
2643 /**************************************************************************
2644 * waveInGetDevCapsA [WINMM.@]
2646 UINT WINAPI
waveInGetDevCapsA(UINT uDeviceID
, LPWAVEINCAPSA lpCaps
, UINT uSize
)
2650 TRACE("(%u %p %u)!\n", uDeviceID
, lpCaps
, uSize
);
2652 if ((wmld
= MMDRV_Get((HANDLE
)uDeviceID
, MMDRV_WAVEIN
, TRUE
)) == NULL
)
2653 return MMSYSERR_BADDEVICEID
;
2655 return MMDRV_Message(wmld
, WIDM_GETDEVCAPS
, (DWORD
)lpCaps
, uSize
, TRUE
);
2658 /**************************************************************************
2659 * waveInGetErrorTextA [WINMM.@]
2661 UINT WINAPI
waveInGetErrorTextA(UINT uError
, LPSTR lpText
, UINT uSize
)
2663 return WAVE_GetErrorText(uError
, lpText
, uSize
);
2666 /**************************************************************************
2667 * waveInGetErrorTextW [WINMM.@]
2669 UINT WINAPI
waveInGetErrorTextW(UINT uError
, LPWSTR lpText
, UINT uSize
)
2671 LPSTR txt
= HeapAlloc(GetProcessHeap(), 0, uSize
);
2672 UINT ret
= WAVE_GetErrorText(uError
, txt
, uSize
);
2674 MultiByteToWideChar( CP_ACP
, 0, txt
, -1, lpText
, uSize
);
2675 HeapFree(GetProcessHeap(), 0, txt
);
2679 /**************************************************************************
2680 * waveInOpen [WINMM.@]
2682 UINT WINAPI
waveInOpen(HWAVEIN
* lphWaveIn
, UINT uDeviceID
,
2683 const LPWAVEFORMATEX lpFormat
, DWORD dwCallback
,
2684 DWORD dwInstance
, DWORD dwFlags
)
2686 return WAVE_Open((HANDLE
*)lphWaveIn
, uDeviceID
, MMDRV_WAVEIN
, lpFormat
,
2687 dwCallback
, dwInstance
, dwFlags
, TRUE
);
2690 /**************************************************************************
2691 * waveInClose [WINMM.@]
2693 UINT WINAPI
waveInClose(HWAVEIN hWaveIn
)
2698 TRACE("(%p)\n", hWaveIn
);
2700 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
)
2701 return MMSYSERR_INVALHANDLE
;
2703 dwRet
= MMDRV_Message(wmld
, WIDM_CLOSE
, 0L, 0L, TRUE
);
2704 MMDRV_Free(hWaveIn
, wmld
);
2708 /**************************************************************************
2709 * waveInPrepareHeader [WINMM.@]
2711 UINT WINAPI
waveInPrepareHeader(HWAVEIN hWaveIn
, WAVEHDR
* lpWaveInHdr
,
2716 TRACE("(%p, %p, %u);\n", hWaveIn
, lpWaveInHdr
, uSize
);
2718 if (lpWaveInHdr
== NULL
) return MMSYSERR_INVALPARAM
;
2719 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
)
2720 return MMSYSERR_INVALHANDLE
;
2722 lpWaveInHdr
->dwBytesRecorded
= 0;
2724 return MMDRV_Message(wmld
, WIDM_PREPARE
, (DWORD
)lpWaveInHdr
, uSize
, TRUE
);
2727 /**************************************************************************
2728 * waveInUnprepareHeader [WINMM.@]
2730 UINT WINAPI
waveInUnprepareHeader(HWAVEIN hWaveIn
, WAVEHDR
* lpWaveInHdr
,
2735 TRACE("(%p, %p, %u);\n", hWaveIn
, lpWaveInHdr
, uSize
);
2737 if (lpWaveInHdr
== NULL
) return MMSYSERR_INVALPARAM
;
2738 if (!(lpWaveInHdr
->dwFlags
& WHDR_PREPARED
)) {
2739 return MMSYSERR_NOERROR
;
2742 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
)
2743 return MMSYSERR_INVALHANDLE
;
2745 return MMDRV_Message(wmld
, WIDM_UNPREPARE
, (DWORD
)lpWaveInHdr
, uSize
, TRUE
);
2748 /**************************************************************************
2749 * waveInAddBuffer [WINMM.@]
2751 UINT WINAPI
waveInAddBuffer(HWAVEIN hWaveIn
,
2752 WAVEHDR
* lpWaveInHdr
, UINT uSize
)
2756 TRACE("(%p, %p, %u);\n", hWaveIn
, lpWaveInHdr
, uSize
);
2758 if (lpWaveInHdr
== NULL
) return MMSYSERR_INVALPARAM
;
2759 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
)
2760 return MMSYSERR_INVALHANDLE
;
2762 return MMDRV_Message(wmld
, WIDM_ADDBUFFER
, (DWORD
)lpWaveInHdr
, uSize
, TRUE
);
2765 /**************************************************************************
2766 * waveInReset [WINMM.@]
2768 UINT WINAPI
waveInReset(HWAVEIN hWaveIn
)
2772 TRACE("(%p);\n", hWaveIn
);
2774 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
)
2775 return MMSYSERR_INVALHANDLE
;
2777 return MMDRV_Message(wmld
, WIDM_RESET
, 0L, 0L, TRUE
);
2780 /**************************************************************************
2781 * waveInStart [WINMM.@]
2783 UINT WINAPI
waveInStart(HWAVEIN hWaveIn
)
2787 TRACE("(%p);\n", hWaveIn
);
2789 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
)
2790 return MMSYSERR_INVALHANDLE
;
2792 return MMDRV_Message(wmld
, WIDM_START
, 0L, 0L, TRUE
);
2795 /**************************************************************************
2796 * waveInStop [WINMM.@]
2798 UINT WINAPI
waveInStop(HWAVEIN hWaveIn
)
2802 TRACE("(%p);\n", hWaveIn
);
2804 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
)
2805 return MMSYSERR_INVALHANDLE
;
2807 return MMDRV_Message(wmld
,WIDM_STOP
, 0L, 0L, TRUE
);
2810 /**************************************************************************
2811 * waveInGetPosition [WINMM.@]
2813 UINT WINAPI
waveInGetPosition(HWAVEIN hWaveIn
, LPMMTIME lpTime
,
2818 TRACE("(%p, %p, %u);\n", hWaveIn
, lpTime
, uSize
);
2820 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
)
2821 return MMSYSERR_INVALHANDLE
;
2823 return MMDRV_Message(wmld
, WIDM_GETPOS
, (DWORD
)lpTime
, uSize
, TRUE
);
2826 /**************************************************************************
2827 * waveInGetID [WINMM.@]
2829 UINT WINAPI
waveInGetID(HWAVEIN hWaveIn
, UINT
* lpuDeviceID
)
2833 TRACE("(%p, %p);\n", hWaveIn
, lpuDeviceID
);
2835 if (lpuDeviceID
== NULL
) return MMSYSERR_INVALHANDLE
;
2837 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
)
2838 return MMSYSERR_INVALHANDLE
;
2840 *lpuDeviceID
= wmld
->uDeviceID
;
2841 return MMSYSERR_NOERROR
;
2844 /**************************************************************************
2845 * waveInMessage [WINMM.@]
2847 DWORD WINAPI
waveInMessage(HWAVEIN hWaveIn
, UINT uMessage
,
2848 DWORD dwParam1
, DWORD dwParam2
)
2852 TRACE("(%p, %u, %ld, %ld)\n", hWaveIn
, uMessage
, dwParam1
, dwParam2
);
2854 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
) {
2855 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, TRUE
)) != NULL
) {
2856 return MMDRV_PhysicalFeatures(wmld
, uMessage
, dwParam1
, dwParam2
);
2858 return MMSYSERR_INVALHANDLE
;
2862 if (uMessage
< DRVM_IOCTL
|| (uMessage
>= DRVM_IOCTL_LAST
&& uMessage
< DRVM_MAPPER
))
2863 return MMSYSERR_INVALPARAM
;
2866 return MMDRV_Message(wmld
, uMessage
, dwParam1
, dwParam2
, TRUE
);