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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 * 98/9 added Win32 MCI support
27 * 99/4 added midiStream support
28 * 99/9 added support for loadable low level drivers
32 * + it seems that some programs check what's installed in
33 * registry against the value returned by drivers. Wine is
34 * currently broken regarding this point.
35 * + check thread-safeness for MMSYSTEM and WINMM entry points
36 * + unicode entry points are badly supported (would require
37 * moving 32 bit drivers as Unicode as they are supposed to be)
38 * + allow joystick and timer external calls as we do for wave,
46 #define NONAMELESSUNION
47 #define NONAMELESSSTRUCT
56 #include "wine/debug.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(winmm
);
60 void (WINAPI
*pFnReleaseThunkLock
)(DWORD
*);
61 void (WINAPI
*pFnRestoreThunkLock
)(DWORD
);
63 /* ========================================================================
64 * G L O B A L S E T T I N G S
65 * ========================================================================*/
67 HINSTANCE hWinMM32Instance
;
71 static CRITICAL_SECTION_DEBUG critsect_debug
=
74 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
75 0, 0, { (DWORD_PTR
)(__FILE__
": WINMM_cs") }
77 CRITICAL_SECTION WINMM_cs
= { &critsect_debug
, -1, 0, 0, 0, 0 };
79 /**************************************************************************
80 * WINMM_CreateIData [internal]
82 static BOOL
WINMM_CreateIData(HINSTANCE hInstDLL
)
84 hWinMM32Instance
= hInstDLL
;
85 psStopEvent
= CreateEventW(NULL
, TRUE
, FALSE
, NULL
);
86 psLastEvent
= CreateEventW(NULL
, TRUE
, FALSE
, NULL
);
90 /**************************************************************************
91 * WINMM_DeleteIData [internal]
93 static void WINMM_DeleteIData(void)
97 /* FIXME: should also free content and resources allocated
98 * inside WINMM_IData */
99 CloseHandle(psStopEvent
);
100 CloseHandle(psLastEvent
);
101 DeleteCriticalSection(&WINMM_cs
);
104 /******************************************************************
108 static HANDLE (WINAPI
*pGetModuleHandle16
)(LPCSTR
);
109 static DWORD (WINAPI
*pLoadLibrary16
)(LPCSTR
);
111 BOOL
WINMM_CheckForMMSystem(void)
113 /* 0 is not checked yet, -1 is not present, 1 is present */
114 static int loaded
/* = 0 */;
118 HANDLE h
= GetModuleHandleA("kernel32");
122 pGetModuleHandle16
= (void*)GetProcAddress(h
, "GetModuleHandle16");
123 pLoadLibrary16
= (void*)GetProcAddress(h
, (LPCSTR
)35); /* ordinal for LoadLibrary16 */
124 if (pGetModuleHandle16
&& pLoadLibrary16
&&
125 (pGetModuleHandle16("MMSYSTEM.DLL") || pLoadLibrary16("MMSYSTEM.DLL")))
132 /******************************************************************
133 * WINMM_ErrorToString
135 const char* WINMM_ErrorToString(MMRESULT error
)
137 #define ERR_TO_STR(dev) case dev: return #dev
138 static char unknown
[32];
140 ERR_TO_STR(MMSYSERR_NOERROR
);
141 ERR_TO_STR(MMSYSERR_ERROR
);
142 ERR_TO_STR(MMSYSERR_BADDEVICEID
);
143 ERR_TO_STR(MMSYSERR_NOTENABLED
);
144 ERR_TO_STR(MMSYSERR_ALLOCATED
);
145 ERR_TO_STR(MMSYSERR_INVALHANDLE
);
146 ERR_TO_STR(MMSYSERR_NODRIVER
);
147 ERR_TO_STR(MMSYSERR_NOMEM
);
148 ERR_TO_STR(MMSYSERR_NOTSUPPORTED
);
149 ERR_TO_STR(MMSYSERR_BADERRNUM
);
150 ERR_TO_STR(MMSYSERR_INVALFLAG
);
151 ERR_TO_STR(MMSYSERR_INVALPARAM
);
152 ERR_TO_STR(MMSYSERR_HANDLEBUSY
);
153 ERR_TO_STR(MMSYSERR_INVALIDALIAS
);
154 ERR_TO_STR(MMSYSERR_BADDB
);
155 ERR_TO_STR(MMSYSERR_KEYNOTFOUND
);
156 ERR_TO_STR(MMSYSERR_READERROR
);
157 ERR_TO_STR(MMSYSERR_WRITEERROR
);
158 ERR_TO_STR(MMSYSERR_DELETEERROR
);
159 ERR_TO_STR(MMSYSERR_VALNOTFOUND
);
160 ERR_TO_STR(MMSYSERR_NODRIVERCB
);
161 ERR_TO_STR(WAVERR_BADFORMAT
);
162 ERR_TO_STR(WAVERR_STILLPLAYING
);
163 ERR_TO_STR(WAVERR_UNPREPARED
);
164 ERR_TO_STR(WAVERR_SYNC
);
166 sprintf(unknown
, "Unknown(0x%08x)", error
);
171 /**************************************************************************
172 * DllMain (WINMM.init)
174 * WINMM DLL entry point
177 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID fImpLoad
)
179 TRACE("%p 0x%x %p\n", hInstDLL
, fdwReason
, fImpLoad
);
182 case DLL_PROCESS_ATTACH
:
183 DisableThreadLibraryCalls(hInstDLL
);
185 if (!WINMM_CreateIData(hInstDLL
))
192 case DLL_PROCESS_DETACH
:
193 /* close all opened MCI drivers */
194 MCI_SendCommand(MCI_ALL_DEVICE_ID
, MCI_CLOSE
, MCI_WAIT
, 0L, TRUE
);
196 /* There's no guarantee the drivers haven't already been unloaded on
201 /* now unload all remaining drivers... */
211 /**************************************************************************
212 * Mixer devices. New to Win95
215 /**************************************************************************
216 * find out the real mixer ID depending on hmix (depends on dwFlags)
218 static UINT
MIXER_GetDev(HMIXEROBJ hmix
, DWORD dwFlags
, LPWINE_MIXER
* lplpwm
)
220 LPWINE_MIXER lpwm
= NULL
;
221 UINT uRet
= MMSYSERR_NOERROR
;
223 switch (dwFlags
& 0xF0000000ul
) {
224 case MIXER_OBJECTF_MIXER
:
225 lpwm
= (LPWINE_MIXER
)MMDRV_Get(hmix
, MMDRV_MIXER
, TRUE
);
227 case MIXER_OBJECTF_HMIXER
:
228 lpwm
= (LPWINE_MIXER
)MMDRV_Get(hmix
, MMDRV_MIXER
, FALSE
);
230 case MIXER_OBJECTF_WAVEOUT
:
231 lpwm
= (LPWINE_MIXER
)MMDRV_GetRelated(hmix
, MMDRV_WAVEOUT
, TRUE
, MMDRV_MIXER
);
233 case MIXER_OBJECTF_HWAVEOUT
:
234 lpwm
= (LPWINE_MIXER
)MMDRV_GetRelated(hmix
, MMDRV_WAVEOUT
, FALSE
, MMDRV_MIXER
);
236 case MIXER_OBJECTF_WAVEIN
:
237 lpwm
= (LPWINE_MIXER
)MMDRV_GetRelated(hmix
, MMDRV_WAVEIN
, TRUE
, MMDRV_MIXER
);
239 case MIXER_OBJECTF_HWAVEIN
:
240 lpwm
= (LPWINE_MIXER
)MMDRV_GetRelated(hmix
, MMDRV_WAVEIN
, FALSE
, MMDRV_MIXER
);
242 case MIXER_OBJECTF_MIDIOUT
:
243 lpwm
= (LPWINE_MIXER
)MMDRV_GetRelated(hmix
, MMDRV_MIDIOUT
, TRUE
, MMDRV_MIXER
);
245 case MIXER_OBJECTF_HMIDIOUT
:
246 lpwm
= (LPWINE_MIXER
)MMDRV_GetRelated(hmix
, MMDRV_MIDIOUT
, FALSE
, MMDRV_MIXER
);
248 case MIXER_OBJECTF_MIDIIN
:
249 lpwm
= (LPWINE_MIXER
)MMDRV_GetRelated(hmix
, MMDRV_MIDIIN
, TRUE
, MMDRV_MIXER
);
251 case MIXER_OBJECTF_HMIDIIN
:
252 lpwm
= (LPWINE_MIXER
)MMDRV_GetRelated(hmix
, MMDRV_MIDIIN
, FALSE
, MMDRV_MIXER
);
254 case MIXER_OBJECTF_AUX
:
255 lpwm
= (LPWINE_MIXER
)MMDRV_GetRelated(hmix
, MMDRV_AUX
, TRUE
, MMDRV_MIXER
);
258 WARN("Unsupported flag (%08lx)\n", dwFlags
& 0xF0000000ul
);
260 uRet
= MMSYSERR_INVALFLAG
;
264 if (lpwm
== 0 && uRet
== MMSYSERR_NOERROR
)
265 uRet
= MMSYSERR_INVALPARAM
;
269 /**************************************************************************
270 * mixerGetNumDevs [WINMM.@]
272 UINT WINAPI
mixerGetNumDevs(void)
274 return MMDRV_GetNum(MMDRV_MIXER
);
277 /**************************************************************************
278 * mixerGetDevCapsA [WINMM.@]
280 UINT WINAPI
mixerGetDevCapsA(UINT_PTR uDeviceID
, LPMIXERCAPSA lpCaps
, UINT uSize
)
285 if (lpCaps
== NULL
) return MMSYSERR_INVALPARAM
;
287 ret
= mixerGetDevCapsW(uDeviceID
, &micW
, sizeof(micW
));
289 if (ret
== MMSYSERR_NOERROR
) {
291 micA
.wMid
= micW
.wMid
;
292 micA
.wPid
= micW
.wPid
;
293 micA
.vDriverVersion
= micW
.vDriverVersion
;
294 WideCharToMultiByte( CP_ACP
, 0, micW
.szPname
, -1, micA
.szPname
,
295 sizeof(micA
.szPname
), NULL
, NULL
);
296 micA
.fdwSupport
= micW
.fdwSupport
;
297 micA
.cDestinations
= micW
.cDestinations
;
298 memcpy(lpCaps
, &micA
, min(uSize
, sizeof(micA
)));
303 /**************************************************************************
304 * mixerGetDevCapsW [WINMM.@]
306 UINT WINAPI
mixerGetDevCapsW(UINT_PTR uDeviceID
, LPMIXERCAPSW lpCaps
, UINT uSize
)
310 if (lpCaps
== NULL
) return MMSYSERR_INVALPARAM
;
312 if ((wmld
= MMDRV_Get((HANDLE
)uDeviceID
, MMDRV_MIXER
, TRUE
)) == NULL
)
313 return MMSYSERR_BADDEVICEID
;
315 return MMDRV_Message(wmld
, MXDM_GETDEVCAPS
, (DWORD_PTR
)lpCaps
, uSize
, TRUE
);
318 static void CALLBACK
MIXER_WCallback(HMIXEROBJ hmx
, UINT uMsg
, DWORD_PTR dwInstance
, DWORD_PTR dwParam
, DWORD_PTR param2
)
320 HWND hWnd
= (HWND
)dwInstance
;
325 PostMessageW(hWnd
, uMsg
, (WPARAM
)hmx
, (LPARAM
)dwParam
);
328 UINT
MIXER_Open(LPHMIXER lphMix
, UINT uDeviceID
, DWORD_PTR dwCallback
,
329 DWORD_PTR dwInstance
, DWORD fdwOpen
, BOOL bFrom32
)
336 TRACE("(%p, %d, %08lx, %08lx, %08x)\n",
337 lphMix
, uDeviceID
, dwCallback
, dwInstance
, fdwOpen
);
339 mod
.dwCallback
= (DWORD_PTR
)MIXER_WCallback
;
342 /* If callback is a function,
343 * dwCallback contains function pointer
344 * dwInstance private data
346 * if callback is a window
347 * dwCallback contains a window handle
349 switch (fdwOpen
& CALLBACK_TYPEMASK
) {
351 return MMSYSERR_INVALFLAG
;
356 case CALLBACK_WINDOW
:
357 mod
.dwInstance
= dwCallback
;
358 if (!IsWindow((HWND
)dwCallback
))
359 return MMSYSERR_INVALPARAM
;
363 wmld
= MMDRV_Alloc(sizeof(WINE_MIXER
), MMDRV_MIXER
, &hMix
, &fdwOpen
,
364 &dwCallback
, &dwInstance
, bFrom32
);
365 wmld
->uDeviceID
= uDeviceID
;
366 mod
.hmx
= (HMIXEROBJ
)hMix
;
368 dwRet
= MMDRV_Open(wmld
, MXDM_OPEN
, (DWORD
)&mod
, CALLBACK_FUNCTION
);
370 if (dwRet
!= MMSYSERR_NOERROR
) {
371 MMDRV_Free(hMix
, wmld
);
374 if (lphMix
) *lphMix
= hMix
;
375 TRACE("=> %d hMixer=%p\n", dwRet
, hMix
);
380 /**************************************************************************
381 * mixerOpen [WINMM.@]
383 UINT WINAPI
mixerOpen(LPHMIXER lphMix
, UINT uDeviceID
, DWORD_PTR dwCallback
,
384 DWORD_PTR dwInstance
, DWORD fdwOpen
)
386 return MIXER_Open(lphMix
, uDeviceID
, dwCallback
, dwInstance
, fdwOpen
, TRUE
);
389 /**************************************************************************
390 * mixerClose [WINMM.@]
392 UINT WINAPI
mixerClose(HMIXER hMix
)
397 TRACE("(%p)\n", hMix
);
399 if ((wmld
= MMDRV_Get(hMix
, MMDRV_MIXER
, FALSE
)) == NULL
) return MMSYSERR_INVALHANDLE
;
401 dwRet
= MMDRV_Close(wmld
, MXDM_CLOSE
);
402 MMDRV_Free(hMix
, wmld
);
407 /**************************************************************************
408 * mixerGetID [WINMM.@]
410 UINT WINAPI
mixerGetID(HMIXEROBJ hmix
, LPUINT lpid
, DWORD fdwID
)
413 UINT uRet
= MMSYSERR_NOERROR
;
415 TRACE("(%p %p %08x)\n", hmix
, lpid
, fdwID
);
417 if ((uRet
= MIXER_GetDev(hmix
, fdwID
, &lpwm
)) != MMSYSERR_NOERROR
)
421 *lpid
= lpwm
->mld
.uDeviceID
;
426 /**************************************************************************
427 * mixerGetControlDetailsW [WINMM.@]
429 UINT WINAPI
mixerGetControlDetailsW(HMIXEROBJ hmix
, LPMIXERCONTROLDETAILS lpmcdW
,
433 UINT uRet
= MMSYSERR_NOERROR
;
435 TRACE("(%p, %p, %08x)\n", hmix
, lpmcdW
, fdwDetails
);
437 if ((uRet
= MIXER_GetDev(hmix
, fdwDetails
, &lpwm
)) != MMSYSERR_NOERROR
)
440 if (lpmcdW
== NULL
|| lpmcdW
->cbStruct
!= sizeof(*lpmcdW
))
441 return MMSYSERR_INVALPARAM
;
443 return MMDRV_Message(&lpwm
->mld
, MXDM_GETCONTROLDETAILS
, (DWORD_PTR
)lpmcdW
,
447 /**************************************************************************
448 * mixerGetControlDetailsA [WINMM.@]
450 UINT WINAPI
mixerGetControlDetailsA(HMIXEROBJ hmix
, LPMIXERCONTROLDETAILS lpmcdA
,
453 DWORD ret
= MMSYSERR_NOTENABLED
;
455 TRACE("(%p, %p, %08x)\n", hmix
, lpmcdA
, fdwDetails
);
457 if (lpmcdA
== NULL
|| lpmcdA
->cbStruct
!= sizeof(*lpmcdA
))
458 return MMSYSERR_INVALPARAM
;
460 switch (fdwDetails
& MIXER_GETCONTROLDETAILSF_QUERYMASK
) {
461 case MIXER_GETCONTROLDETAILSF_VALUE
:
462 /* can safely use A structure as it is, no string inside */
463 ret
= mixerGetControlDetailsW(hmix
, lpmcdA
, fdwDetails
);
465 case MIXER_GETCONTROLDETAILSF_LISTTEXT
:
467 MIXERCONTROLDETAILS_LISTTEXTA
*pDetailsA
= (MIXERCONTROLDETAILS_LISTTEXTA
*)lpmcdA
->paDetails
;
468 MIXERCONTROLDETAILS_LISTTEXTW
*pDetailsW
;
469 int size
= max(1, lpmcdA
->cChannels
) * sizeof(MIXERCONTROLDETAILS_LISTTEXTW
);
472 if (lpmcdA
->u
.cMultipleItems
!= 0) {
473 size
*= lpmcdA
->u
.cMultipleItems
;
475 pDetailsW
= HeapAlloc(GetProcessHeap(), 0, size
);
476 lpmcdA
->paDetails
= pDetailsW
;
477 lpmcdA
->cbDetails
= sizeof(MIXERCONTROLDETAILS_LISTTEXTW
);
478 /* set up lpmcd->paDetails */
479 ret
= mixerGetControlDetailsW(hmix
, lpmcdA
, fdwDetails
);
480 /* copy from lpmcd->paDetails back to paDetailsW; */
481 if (ret
== MMSYSERR_NOERROR
) {
482 for (i
= 0; i
< lpmcdA
->u
.cMultipleItems
* lpmcdA
->cChannels
; i
++) {
483 pDetailsA
->dwParam1
= pDetailsW
->dwParam1
;
484 pDetailsA
->dwParam2
= pDetailsW
->dwParam2
;
485 WideCharToMultiByte( CP_ACP
, 0, pDetailsW
->szName
, -1,
487 sizeof(pDetailsA
->szName
), NULL
, NULL
);
491 pDetailsA
-= lpmcdA
->u
.cMultipleItems
* lpmcdA
->cChannels
;
492 pDetailsW
-= lpmcdA
->u
.cMultipleItems
* lpmcdA
->cChannels
;
494 HeapFree(GetProcessHeap(), 0, pDetailsW
);
495 lpmcdA
->paDetails
= pDetailsA
;
496 lpmcdA
->cbDetails
= sizeof(MIXERCONTROLDETAILS_LISTTEXTA
);
500 ERR("Unsupported fdwDetails=0x%08x\n", fdwDetails
);
506 /**************************************************************************
507 * mixerGetLineControlsA [WINMM.@]
509 UINT WINAPI
mixerGetLineControlsA(HMIXEROBJ hmix
, LPMIXERLINECONTROLSA lpmlcA
,
512 MIXERLINECONTROLSW mlcW
;
516 TRACE("(%p, %p, %08x)\n", hmix
, lpmlcA
, fdwControls
);
518 if (lpmlcA
== NULL
|| lpmlcA
->cbStruct
!= sizeof(*lpmlcA
) ||
519 lpmlcA
->cbmxctrl
!= sizeof(MIXERCONTROLA
))
520 return MMSYSERR_INVALPARAM
;
522 mlcW
.cbStruct
= sizeof(mlcW
);
523 mlcW
.dwLineID
= lpmlcA
->dwLineID
;
524 mlcW
.u
.dwControlID
= lpmlcA
->u
.dwControlID
;
525 mlcW
.u
.dwControlType
= lpmlcA
->u
.dwControlType
;
527 /* Debugging on Windows shows for MIXER_GETLINECONTROLSF_ONEBYTYPE only,
528 the control count is assumed to be 1 - This is relied upon by a game,
530 if (MIXER_GETLINECONTROLSF_ONEBYTYPE
== (fdwControls
& MIXER_GETLINECONTROLSF_QUERYMASK
)) {
533 mlcW
.cControls
= lpmlcA
->cControls
;
535 mlcW
.cbmxctrl
= sizeof(MIXERCONTROLW
);
536 mlcW
.pamxctrl
= HeapAlloc(GetProcessHeap(), 0,
537 mlcW
.cControls
* mlcW
.cbmxctrl
);
539 ret
= mixerGetLineControlsW(hmix
, &mlcW
, fdwControls
);
541 if (ret
== MMSYSERR_NOERROR
) {
542 lpmlcA
->dwLineID
= mlcW
.dwLineID
;
543 lpmlcA
->u
.dwControlID
= mlcW
.u
.dwControlID
;
544 lpmlcA
->u
.dwControlType
= mlcW
.u
.dwControlType
;
546 for (i
= 0; i
< mlcW
.cControls
; i
++) {
547 lpmlcA
->pamxctrl
[i
].cbStruct
= sizeof(MIXERCONTROLA
);
548 lpmlcA
->pamxctrl
[i
].dwControlID
= mlcW
.pamxctrl
[i
].dwControlID
;
549 lpmlcA
->pamxctrl
[i
].dwControlType
= mlcW
.pamxctrl
[i
].dwControlType
;
550 lpmlcA
->pamxctrl
[i
].fdwControl
= mlcW
.pamxctrl
[i
].fdwControl
;
551 lpmlcA
->pamxctrl
[i
].cMultipleItems
= mlcW
.pamxctrl
[i
].cMultipleItems
;
552 WideCharToMultiByte( CP_ACP
, 0, mlcW
.pamxctrl
[i
].szShortName
, -1,
553 lpmlcA
->pamxctrl
[i
].szShortName
,
554 sizeof(lpmlcA
->pamxctrl
[i
].szShortName
), NULL
, NULL
);
555 WideCharToMultiByte( CP_ACP
, 0, mlcW
.pamxctrl
[i
].szName
, -1,
556 lpmlcA
->pamxctrl
[i
].szName
,
557 sizeof(lpmlcA
->pamxctrl
[i
].szName
), NULL
, NULL
);
558 /* sizeof(lpmlcA->pamxctrl[i].Bounds) ==
559 * sizeof(mlcW.pamxctrl[i].Bounds) */
560 memcpy(&lpmlcA
->pamxctrl
[i
].Bounds
, &mlcW
.pamxctrl
[i
].Bounds
,
561 sizeof(mlcW
.pamxctrl
[i
].Bounds
));
562 /* sizeof(lpmlcA->pamxctrl[i].Metrics) ==
563 * sizeof(mlcW.pamxctrl[i].Metrics) */
564 memcpy(&lpmlcA
->pamxctrl
[i
].Metrics
, &mlcW
.pamxctrl
[i
].Metrics
,
565 sizeof(mlcW
.pamxctrl
[i
].Metrics
));
569 HeapFree(GetProcessHeap(), 0, mlcW
.pamxctrl
);
574 /**************************************************************************
575 * mixerGetLineControlsW [WINMM.@]
577 UINT WINAPI
mixerGetLineControlsW(HMIXEROBJ hmix
, LPMIXERLINECONTROLSW lpmlcW
,
581 UINT uRet
= MMSYSERR_NOERROR
;
583 TRACE("(%p, %p, %08x)\n", hmix
, lpmlcW
, fdwControls
);
585 if ((uRet
= MIXER_GetDev(hmix
, fdwControls
, &lpwm
)) != MMSYSERR_NOERROR
)
588 if (lpmlcW
== NULL
|| lpmlcW
->cbStruct
!= sizeof(*lpmlcW
))
589 return MMSYSERR_INVALPARAM
;
591 return MMDRV_Message(&lpwm
->mld
, MXDM_GETLINECONTROLS
, (DWORD_PTR
)lpmlcW
,
595 /**************************************************************************
596 * mixerGetLineInfoW [WINMM.@]
598 UINT WINAPI
mixerGetLineInfoW(HMIXEROBJ hmix
, LPMIXERLINEW lpmliW
, DWORD fdwInfo
)
601 UINT uRet
= MMSYSERR_NOERROR
;
603 TRACE("(%p, %p, %08x)\n", hmix
, lpmliW
, fdwInfo
);
605 if ((uRet
= MIXER_GetDev(hmix
, fdwInfo
, &lpwm
)) != MMSYSERR_NOERROR
)
608 return MMDRV_Message(&lpwm
->mld
, MXDM_GETLINEINFO
, (DWORD_PTR
)lpmliW
,
612 /**************************************************************************
613 * mixerGetLineInfoA [WINMM.@]
615 UINT WINAPI
mixerGetLineInfoA(HMIXEROBJ hmix
, LPMIXERLINEA lpmliA
,
621 TRACE("(%p, %p, %08x)\n", hmix
, lpmliA
, fdwInfo
);
623 if (lpmliA
== NULL
|| lpmliA
->cbStruct
!= sizeof(*lpmliA
))
624 return MMSYSERR_INVALPARAM
;
626 mliW
.cbStruct
= sizeof(mliW
);
627 switch (fdwInfo
& MIXER_GETLINEINFOF_QUERYMASK
) {
628 case MIXER_GETLINEINFOF_COMPONENTTYPE
:
629 mliW
.dwComponentType
= lpmliA
->dwComponentType
;
631 case MIXER_GETLINEINFOF_DESTINATION
:
632 mliW
.dwDestination
= lpmliA
->dwDestination
;
634 case MIXER_GETLINEINFOF_LINEID
:
635 mliW
.dwLineID
= lpmliA
->dwLineID
;
637 case MIXER_GETLINEINFOF_SOURCE
:
638 mliW
.dwDestination
= lpmliA
->dwDestination
;
639 mliW
.dwSource
= lpmliA
->dwSource
;
641 case MIXER_GETLINEINFOF_TARGETTYPE
:
642 mliW
.Target
.dwType
= lpmliA
->Target
.dwType
;
643 mliW
.Target
.wMid
= lpmliA
->Target
.wMid
;
644 mliW
.Target
.wPid
= lpmliA
->Target
.wPid
;
645 mliW
.Target
.vDriverVersion
= lpmliA
->Target
.vDriverVersion
;
646 MultiByteToWideChar( CP_ACP
, 0, lpmliA
->Target
.szPname
, -1, mliW
.Target
.szPname
, sizeof(mliW
.Target
.szPname
)/sizeof(WCHAR
));
649 WARN("Unsupported fdwControls=0x%08x\n", fdwInfo
);
650 return MMSYSERR_INVALFLAG
;
653 ret
= mixerGetLineInfoW(hmix
, &mliW
, fdwInfo
);
655 lpmliA
->dwDestination
= mliW
.dwDestination
;
656 lpmliA
->dwSource
= mliW
.dwSource
;
657 lpmliA
->dwLineID
= mliW
.dwLineID
;
658 lpmliA
->fdwLine
= mliW
.fdwLine
;
659 lpmliA
->dwUser
= mliW
.dwUser
;
660 lpmliA
->dwComponentType
= mliW
.dwComponentType
;
661 lpmliA
->cChannels
= mliW
.cChannels
;
662 lpmliA
->cConnections
= mliW
.cConnections
;
663 lpmliA
->cControls
= mliW
.cControls
;
664 WideCharToMultiByte( CP_ACP
, 0, mliW
.szShortName
, -1, lpmliA
->szShortName
,
665 sizeof(lpmliA
->szShortName
), NULL
, NULL
);
666 WideCharToMultiByte( CP_ACP
, 0, mliW
.szName
, -1, lpmliA
->szName
,
667 sizeof(lpmliA
->szName
), NULL
, NULL
);
668 lpmliA
->Target
.dwType
= mliW
.Target
.dwType
;
669 lpmliA
->Target
.dwDeviceID
= mliW
.Target
.dwDeviceID
;
670 lpmliA
->Target
.wMid
= mliW
.Target
.wMid
;
671 lpmliA
->Target
.wPid
= mliW
.Target
.wPid
;
672 lpmliA
->Target
.vDriverVersion
= mliW
.Target
.vDriverVersion
;
673 WideCharToMultiByte( CP_ACP
, 0, mliW
.Target
.szPname
, -1, lpmliA
->Target
.szPname
,
674 sizeof(lpmliA
->Target
.szPname
), NULL
, NULL
);
679 /**************************************************************************
680 * mixerSetControlDetails [WINMM.@]
682 UINT WINAPI
mixerSetControlDetails(HMIXEROBJ hmix
, LPMIXERCONTROLDETAILS lpmcd
,
686 UINT uRet
= MMSYSERR_NOERROR
;
688 TRACE("(%p, %p, %08x)\n", hmix
, lpmcd
, fdwDetails
);
690 if ((uRet
= MIXER_GetDev(hmix
, fdwDetails
, &lpwm
)) != MMSYSERR_NOERROR
)
693 return MMDRV_Message(&lpwm
->mld
, MXDM_SETCONTROLDETAILS
, (DWORD_PTR
)lpmcd
,
697 /**************************************************************************
698 * mixerMessage [WINMM.@]
700 DWORD WINAPI
mixerMessage(HMIXER hmix
, UINT uMsg
, DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
704 TRACE("(%p, %d, %08lx, %08lx): semi-stub?\n",
705 hmix
, uMsg
, dwParam1
, dwParam2
);
707 if ((wmld
= MMDRV_Get(hmix
, MMDRV_MIXER
, FALSE
)) == NULL
)
708 return MMSYSERR_INVALHANDLE
;
710 return MMDRV_Message(wmld
, uMsg
, dwParam1
, dwParam2
, TRUE
);
713 /**************************************************************************
714 * auxGetNumDevs [WINMM.@]
716 UINT WINAPI
auxGetNumDevs(void)
718 return MMDRV_GetNum(MMDRV_AUX
);
721 /**************************************************************************
722 * auxGetDevCapsW [WINMM.@]
724 UINT WINAPI
auxGetDevCapsW(UINT_PTR uDeviceID
, LPAUXCAPSW lpCaps
, UINT uSize
)
728 TRACE("(%04lX, %p, %d) !\n", uDeviceID
, lpCaps
, uSize
);
730 if (lpCaps
== NULL
) return MMSYSERR_INVALPARAM
;
732 if ((wmld
= MMDRV_Get((HANDLE
)uDeviceID
, MMDRV_AUX
, TRUE
)) == NULL
)
733 return MMSYSERR_INVALHANDLE
;
734 return MMDRV_Message(wmld
, AUXDM_GETDEVCAPS
, (DWORD_PTR
)lpCaps
, uSize
, TRUE
);
737 /**************************************************************************
738 * auxGetDevCapsA [WINMM.@]
740 UINT WINAPI
auxGetDevCapsA(UINT_PTR uDeviceID
, LPAUXCAPSA lpCaps
, UINT uSize
)
745 if (lpCaps
== NULL
) return MMSYSERR_INVALPARAM
;
747 ret
= auxGetDevCapsW(uDeviceID
, &acW
, sizeof(acW
));
749 if (ret
== MMSYSERR_NOERROR
) {
753 acA
.vDriverVersion
= acW
.vDriverVersion
;
754 WideCharToMultiByte( CP_ACP
, 0, acW
.szPname
, -1, acA
.szPname
,
755 sizeof(acA
.szPname
), NULL
, NULL
);
756 acA
.wTechnology
= acW
.wTechnology
;
757 acA
.dwSupport
= acW
.dwSupport
;
758 memcpy(lpCaps
, &acA
, min(uSize
, sizeof(acA
)));
763 /**************************************************************************
764 * auxGetVolume [WINMM.@]
766 UINT WINAPI
auxGetVolume(UINT uDeviceID
, DWORD
* lpdwVolume
)
770 TRACE("(%04X, %p) !\n", uDeviceID
, lpdwVolume
);
772 if ((wmld
= MMDRV_Get((HANDLE
)uDeviceID
, MMDRV_AUX
, TRUE
)) == NULL
)
773 return MMSYSERR_INVALHANDLE
;
774 return MMDRV_Message(wmld
, AUXDM_GETVOLUME
, (DWORD_PTR
)lpdwVolume
, 0L, TRUE
);
777 /**************************************************************************
778 * auxSetVolume [WINMM.@]
780 UINT WINAPI
auxSetVolume(UINT uDeviceID
, DWORD dwVolume
)
784 TRACE("(%04X, %u) !\n", uDeviceID
, dwVolume
);
786 if ((wmld
= MMDRV_Get((HANDLE
)uDeviceID
, MMDRV_AUX
, TRUE
)) == NULL
)
787 return MMSYSERR_INVALHANDLE
;
788 return MMDRV_Message(wmld
, AUXDM_SETVOLUME
, dwVolume
, 0L, TRUE
);
791 /**************************************************************************
792 * auxOutMessage [WINMM.@]
794 UINT WINAPI
auxOutMessage(UINT uDeviceID
, UINT uMessage
, DWORD_PTR dw1
, DWORD_PTR dw2
)
798 if ((wmld
= MMDRV_Get((HANDLE
)uDeviceID
, MMDRV_AUX
, TRUE
)) == NULL
)
799 return MMSYSERR_INVALHANDLE
;
801 return MMDRV_Message(wmld
, uMessage
, dw1
, dw2
, TRUE
);
804 /**************************************************************************
805 * midiOutGetNumDevs [WINMM.@]
807 UINT WINAPI
midiOutGetNumDevs(void)
809 return MMDRV_GetNum(MMDRV_MIDIOUT
);
812 /**************************************************************************
813 * midiOutGetDevCapsW [WINMM.@]
815 UINT WINAPI
midiOutGetDevCapsW(UINT_PTR uDeviceID
, LPMIDIOUTCAPSW lpCaps
,
820 TRACE("(%lu, %p, %u);\n", uDeviceID
, lpCaps
, uSize
);
822 if (lpCaps
== NULL
) return MMSYSERR_INVALPARAM
;
824 if ((wmld
= MMDRV_Get((HANDLE
)uDeviceID
, MMDRV_MIDIOUT
, TRUE
)) == NULL
)
825 return MMSYSERR_INVALHANDLE
;
827 return MMDRV_Message(wmld
, MODM_GETDEVCAPS
, (DWORD_PTR
)lpCaps
, uSize
, TRUE
);
830 /**************************************************************************
831 * midiOutGetDevCapsA [WINMM.@]
833 UINT WINAPI
midiOutGetDevCapsA(UINT_PTR uDeviceID
, LPMIDIOUTCAPSA lpCaps
,
839 if (lpCaps
== NULL
) return MMSYSERR_INVALPARAM
;
841 ret
= midiOutGetDevCapsW(uDeviceID
, &mocW
, sizeof(mocW
));
843 if (ret
== MMSYSERR_NOERROR
) {
845 mocA
.wMid
= mocW
.wMid
;
846 mocA
.wPid
= mocW
.wPid
;
847 mocA
.vDriverVersion
= mocW
.vDriverVersion
;
848 WideCharToMultiByte( CP_ACP
, 0, mocW
.szPname
, -1, mocA
.szPname
,
849 sizeof(mocA
.szPname
), NULL
, NULL
);
850 mocA
.wTechnology
= mocW
.wTechnology
;
851 mocA
.wVoices
= mocW
.wVoices
;
852 mocA
.wNotes
= mocW
.wNotes
;
853 mocA
.wChannelMask
= mocW
.wChannelMask
;
854 mocA
.dwSupport
= mocW
.dwSupport
;
855 memcpy(lpCaps
, &mocA
, min(uSize
, sizeof(mocA
)));
860 /**************************************************************************
861 * midiOutGetErrorTextA [WINMM.@]
862 * midiInGetErrorTextA [WINMM.@]
864 UINT WINAPI
midiOutGetErrorTextA(UINT uError
, LPSTR lpText
, UINT uSize
)
868 if (lpText
== NULL
) ret
= MMSYSERR_INVALPARAM
;
869 else if (uSize
== 0) ret
= MMSYSERR_NOERROR
;
872 LPWSTR xstr
= HeapAlloc(GetProcessHeap(), 0, uSize
* sizeof(WCHAR
));
873 if (!xstr
) ret
= MMSYSERR_NOMEM
;
876 ret
= midiOutGetErrorTextW(uError
, xstr
, uSize
);
877 if (ret
== MMSYSERR_NOERROR
)
878 WideCharToMultiByte(CP_ACP
, 0, xstr
, -1, lpText
, uSize
, NULL
, NULL
);
879 HeapFree(GetProcessHeap(), 0, xstr
);
885 /**************************************************************************
886 * midiOutGetErrorTextW [WINMM.@]
887 * midiInGetErrorTextW [WINMM.@]
889 UINT WINAPI
midiOutGetErrorTextW(UINT uError
, LPWSTR lpText
, UINT uSize
)
891 UINT ret
= MMSYSERR_BADERRNUM
;
893 if (lpText
== NULL
) ret
= MMSYSERR_INVALPARAM
;
894 else if (uSize
== 0) ret
= MMSYSERR_NOERROR
;
896 /* test has been removed because MMSYSERR_BASE is 0, and gcc did emit
897 * a warning for the test was always true */
898 (/*uError >= MMSYSERR_BASE && */ uError
<= MMSYSERR_LASTERROR
) ||
899 (uError
>= MIDIERR_BASE
&& uError
<= MIDIERR_LASTERROR
)) {
900 if (LoadStringW(hWinMM32Instance
, uError
, lpText
, uSize
) > 0) {
901 ret
= MMSYSERR_NOERROR
;
907 /**************************************************************************
908 * MIDI_OutAlloc [internal]
910 static LPWINE_MIDI
MIDI_OutAlloc(HMIDIOUT
* lphMidiOut
, DWORD_PTR
* lpdwCallback
,
911 DWORD_PTR
* lpdwInstance
, LPDWORD lpdwFlags
,
912 DWORD cIDs
, MIDIOPENSTRMID
* lpIDs
, BOOL bFrom32
)
918 size
= sizeof(WINE_MIDI
) + (cIDs
? (cIDs
-1) : 0) * sizeof(MIDIOPENSTRMID
);
920 lpwm
= (LPWINE_MIDI
)MMDRV_Alloc(size
, MMDRV_MIDIOUT
, &hMidiOut
, lpdwFlags
,
921 lpdwCallback
, lpdwInstance
, bFrom32
);
923 if (lphMidiOut
!= NULL
)
924 *lphMidiOut
= hMidiOut
;
927 lpwm
->mod
.hMidi
= (HMIDI
) hMidiOut
;
928 lpwm
->mod
.dwCallback
= *lpdwCallback
;
929 lpwm
->mod
.dwInstance
= *lpdwInstance
;
930 lpwm
->mod
.dnDevNode
= 0;
931 lpwm
->mod
.cIds
= cIDs
;
933 memcpy(&(lpwm
->mod
.rgIds
), lpIDs
, cIDs
* sizeof(MIDIOPENSTRMID
));
938 UINT
MIDI_OutOpen(LPHMIDIOUT lphMidiOut
, UINT uDeviceID
, DWORD_PTR dwCallback
,
939 DWORD_PTR dwInstance
, DWORD dwFlags
, BOOL bFrom32
)
945 TRACE("(%p, %d, %08lX, %08lX, %08X);\n",
946 lphMidiOut
, uDeviceID
, dwCallback
, dwInstance
, dwFlags
);
948 if (lphMidiOut
!= NULL
) *lphMidiOut
= 0;
950 lpwm
= MIDI_OutAlloc(&hMidiOut
, &dwCallback
, &dwInstance
, &dwFlags
,
954 return MMSYSERR_NOMEM
;
956 lpwm
->mld
.uDeviceID
= uDeviceID
;
958 dwRet
= MMDRV_Open((LPWINE_MLD
)lpwm
, MODM_OPEN
, (DWORD
)&lpwm
->mod
, dwFlags
);
960 if (dwRet
!= MMSYSERR_NOERROR
) {
961 MMDRV_Free(hMidiOut
, (LPWINE_MLD
)lpwm
);
965 if (lphMidiOut
) *lphMidiOut
= hMidiOut
;
966 TRACE("=> %d hMidi=%p\n", dwRet
, hMidiOut
);
971 /**************************************************************************
972 * midiOutOpen [WINMM.@]
974 UINT WINAPI
midiOutOpen(LPHMIDIOUT lphMidiOut
, UINT uDeviceID
,
975 DWORD_PTR dwCallback
, DWORD_PTR dwInstance
, DWORD dwFlags
)
977 return MIDI_OutOpen(lphMidiOut
, uDeviceID
, dwCallback
, dwInstance
, dwFlags
, TRUE
);
980 /**************************************************************************
981 * midiOutClose [WINMM.@]
983 UINT WINAPI
midiOutClose(HMIDIOUT hMidiOut
)
988 TRACE("(%p)\n", hMidiOut
);
990 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, FALSE
)) == NULL
)
991 return MMSYSERR_INVALHANDLE
;
993 dwRet
= MMDRV_Close(wmld
, MODM_CLOSE
);
994 MMDRV_Free(hMidiOut
, wmld
);
999 /**************************************************************************
1000 * midiOutPrepareHeader [WINMM.@]
1002 UINT WINAPI
midiOutPrepareHeader(HMIDIOUT hMidiOut
,
1003 MIDIHDR
* lpMidiOutHdr
, UINT uSize
)
1007 TRACE("(%p, %p, %d)\n", hMidiOut
, lpMidiOutHdr
, uSize
);
1009 if (lpMidiOutHdr
== NULL
|| uSize
< sizeof (MIDIHDR
))
1010 return MMSYSERR_INVALPARAM
;
1012 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, FALSE
)) == NULL
)
1013 return MMSYSERR_INVALHANDLE
;
1015 return MMDRV_Message(wmld
, MODM_PREPARE
, (DWORD_PTR
)lpMidiOutHdr
, uSize
, TRUE
);
1018 /**************************************************************************
1019 * midiOutUnprepareHeader [WINMM.@]
1021 UINT WINAPI
midiOutUnprepareHeader(HMIDIOUT hMidiOut
,
1022 MIDIHDR
* lpMidiOutHdr
, UINT uSize
)
1026 TRACE("(%p, %p, %d)\n", hMidiOut
, lpMidiOutHdr
, uSize
);
1028 if (lpMidiOutHdr
== NULL
|| uSize
< sizeof (MIDIHDR
))
1029 return MMSYSERR_INVALPARAM
;
1031 if (!(lpMidiOutHdr
->dwFlags
& MHDR_PREPARED
)) {
1032 return MMSYSERR_NOERROR
;
1035 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, FALSE
)) == NULL
)
1036 return MMSYSERR_INVALHANDLE
;
1038 return MMDRV_Message(wmld
, MODM_UNPREPARE
, (DWORD_PTR
)lpMidiOutHdr
, uSize
, TRUE
);
1041 /**************************************************************************
1042 * midiOutShortMsg [WINMM.@]
1044 UINT WINAPI
midiOutShortMsg(HMIDIOUT hMidiOut
, DWORD dwMsg
)
1048 TRACE("(%p, %08X)\n", hMidiOut
, dwMsg
);
1050 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, FALSE
)) == NULL
)
1051 return MMSYSERR_INVALHANDLE
;
1053 return MMDRV_Message(wmld
, MODM_DATA
, dwMsg
, 0L, TRUE
);
1056 /**************************************************************************
1057 * midiOutLongMsg [WINMM.@]
1059 UINT WINAPI
midiOutLongMsg(HMIDIOUT hMidiOut
,
1060 MIDIHDR
* lpMidiOutHdr
, UINT uSize
)
1064 TRACE("(%p, %p, %d)\n", hMidiOut
, lpMidiOutHdr
, uSize
);
1066 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, FALSE
)) == NULL
)
1067 return MMSYSERR_INVALHANDLE
;
1069 return MMDRV_Message(wmld
, MODM_LONGDATA
, (DWORD_PTR
)lpMidiOutHdr
, uSize
, TRUE
);
1072 /**************************************************************************
1073 * midiOutReset [WINMM.@]
1075 UINT WINAPI
midiOutReset(HMIDIOUT hMidiOut
)
1079 TRACE("(%p)\n", hMidiOut
);
1081 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, FALSE
)) == NULL
)
1082 return MMSYSERR_INVALHANDLE
;
1084 return MMDRV_Message(wmld
, MODM_RESET
, 0L, 0L, TRUE
);
1087 /**************************************************************************
1088 * midiOutGetVolume [WINMM.@]
1090 UINT WINAPI
midiOutGetVolume(HMIDIOUT hMidiOut
, DWORD
* lpdwVolume
)
1094 TRACE("(%p, %p);\n", hMidiOut
, lpdwVolume
);
1096 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, TRUE
)) == NULL
)
1097 return MMSYSERR_INVALHANDLE
;
1099 return MMDRV_Message(wmld
, MODM_GETVOLUME
, (DWORD_PTR
)lpdwVolume
, 0L, TRUE
);
1102 /**************************************************************************
1103 * midiOutSetVolume [WINMM.@]
1105 UINT WINAPI
midiOutSetVolume(HMIDIOUT hMidiOut
, DWORD dwVolume
)
1109 TRACE("(%p, %d);\n", hMidiOut
, dwVolume
);
1111 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, TRUE
)) == NULL
)
1112 return MMSYSERR_INVALHANDLE
;
1114 return MMDRV_Message(wmld
, MODM_SETVOLUME
, dwVolume
, 0L, TRUE
);
1117 /**************************************************************************
1118 * midiOutCachePatches [WINMM.@]
1120 UINT WINAPI
midiOutCachePatches(HMIDIOUT hMidiOut
, UINT uBank
,
1121 WORD
* lpwPatchArray
, UINT uFlags
)
1123 /* not really necessary to support this */
1124 FIXME("not supported yet\n");
1125 return MMSYSERR_NOTSUPPORTED
;
1128 /**************************************************************************
1129 * midiOutCacheDrumPatches [WINMM.@]
1131 UINT WINAPI
midiOutCacheDrumPatches(HMIDIOUT hMidiOut
, UINT uPatch
,
1132 WORD
* lpwKeyArray
, UINT uFlags
)
1134 FIXME("not supported yet\n");
1135 return MMSYSERR_NOTSUPPORTED
;
1138 /**************************************************************************
1139 * midiOutGetID [WINMM.@]
1141 UINT WINAPI
midiOutGetID(HMIDIOUT hMidiOut
, UINT
* lpuDeviceID
)
1145 TRACE("(%p, %p)\n", hMidiOut
, lpuDeviceID
);
1147 if (lpuDeviceID
== NULL
) return MMSYSERR_INVALPARAM
;
1148 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, FALSE
)) == NULL
)
1149 return MMSYSERR_INVALHANDLE
;
1151 *lpuDeviceID
= wmld
->uDeviceID
;
1152 return MMSYSERR_NOERROR
;
1155 /**************************************************************************
1156 * midiOutMessage [WINMM.@]
1158 UINT WINAPI
midiOutMessage(HMIDIOUT hMidiOut
, UINT uMessage
,
1159 DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
1163 TRACE("(%p, %04X, %08lX, %08lX)\n", hMidiOut
, uMessage
, dwParam1
, dwParam2
);
1165 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, FALSE
)) == NULL
) {
1167 if (uMessage
== 0x0001) {
1168 *(LPDWORD
)dwParam1
= 1;
1171 if ((wmld
= MMDRV_Get(hMidiOut
, MMDRV_MIDIOUT
, TRUE
)) != NULL
) {
1172 return MMDRV_PhysicalFeatures(wmld
, uMessage
, dwParam1
, dwParam2
);
1174 return MMSYSERR_INVALHANDLE
;
1180 FIXME("can't handle OPEN or CLOSE message!\n");
1181 return MMSYSERR_NOTSUPPORTED
;
1183 return MMDRV_Message(wmld
, uMessage
, dwParam1
, dwParam2
, TRUE
);
1186 /**************************************************************************
1187 * midiInGetNumDevs [WINMM.@]
1189 UINT WINAPI
midiInGetNumDevs(void)
1191 return MMDRV_GetNum(MMDRV_MIDIIN
);
1194 /**************************************************************************
1195 * midiInGetDevCapsW [WINMM.@]
1197 UINT WINAPI
midiInGetDevCapsW(UINT_PTR uDeviceID
, LPMIDIINCAPSW lpCaps
, UINT uSize
)
1201 TRACE("(%ld, %p, %d);\n", uDeviceID
, lpCaps
, uSize
);
1203 if (lpCaps
== NULL
) return MMSYSERR_INVALPARAM
;
1205 if ((wmld
= MMDRV_Get((HANDLE
)uDeviceID
, MMDRV_MIDIIN
, TRUE
)) == NULL
)
1206 return MMSYSERR_INVALHANDLE
;
1208 return MMDRV_Message(wmld
, MIDM_GETDEVCAPS
, (DWORD_PTR
)lpCaps
, uSize
, TRUE
);
1211 /**************************************************************************
1212 * midiInGetDevCapsA [WINMM.@]
1214 UINT WINAPI
midiInGetDevCapsA(UINT_PTR uDeviceID
, LPMIDIINCAPSA lpCaps
, UINT uSize
)
1219 if (lpCaps
== NULL
) return MMSYSERR_INVALPARAM
;
1221 ret
= midiInGetDevCapsW(uDeviceID
, &micW
, sizeof(micW
));
1223 if (ret
== MMSYSERR_NOERROR
) {
1225 micA
.wMid
= micW
.wMid
;
1226 micA
.wPid
= micW
.wPid
;
1227 micA
.vDriverVersion
= micW
.vDriverVersion
;
1228 WideCharToMultiByte( CP_ACP
, 0, micW
.szPname
, -1, micA
.szPname
,
1229 sizeof(micA
.szPname
), NULL
, NULL
);
1230 micA
.dwSupport
= micW
.dwSupport
;
1231 memcpy(lpCaps
, &micA
, min(uSize
, sizeof(micA
)));
1236 UINT
MIDI_InOpen(HMIDIIN
* lphMidiIn
, UINT uDeviceID
, DWORD_PTR dwCallback
,
1237 DWORD_PTR dwInstance
, DWORD dwFlags
, BOOL bFrom32
)
1243 TRACE("(%p, %d, %08lX, %08lX, %08X);\n",
1244 lphMidiIn
, uDeviceID
, dwCallback
, dwInstance
, dwFlags
);
1246 if (lphMidiIn
!= NULL
) *lphMidiIn
= 0;
1248 lpwm
= (LPWINE_MIDI
)MMDRV_Alloc(sizeof(WINE_MIDI
), MMDRV_MIDIIN
, &hMidiIn
,
1249 &dwFlags
, &dwCallback
, &dwInstance
, bFrom32
);
1252 return MMSYSERR_NOMEM
;
1254 lpwm
->mod
.hMidi
= (HMIDI
) hMidiIn
;
1255 lpwm
->mod
.dwCallback
= dwCallback
;
1256 lpwm
->mod
.dwInstance
= dwInstance
;
1258 lpwm
->mld
.uDeviceID
= uDeviceID
;
1259 dwRet
= MMDRV_Open(&lpwm
->mld
, MIDM_OPEN
, (DWORD
)&lpwm
->mod
, dwFlags
);
1261 if (dwRet
!= MMSYSERR_NOERROR
) {
1262 MMDRV_Free(hMidiIn
, &lpwm
->mld
);
1265 if (lphMidiIn
!= NULL
) *lphMidiIn
= hMidiIn
;
1266 TRACE("=> %d hMidi=%p\n", dwRet
, hMidiIn
);
1271 /**************************************************************************
1272 * midiInOpen [WINMM.@]
1274 UINT WINAPI
midiInOpen(HMIDIIN
* lphMidiIn
, UINT uDeviceID
,
1275 DWORD_PTR dwCallback
, DWORD_PTR dwInstance
, DWORD dwFlags
)
1277 return MIDI_InOpen(lphMidiIn
, uDeviceID
, dwCallback
, dwInstance
, dwFlags
, TRUE
);
1280 /**************************************************************************
1281 * midiInClose [WINMM.@]
1283 UINT WINAPI
midiInClose(HMIDIIN hMidiIn
)
1288 TRACE("(%p)\n", hMidiIn
);
1290 if ((wmld
= MMDRV_Get(hMidiIn
, MMDRV_MIDIIN
, FALSE
)) == NULL
)
1291 return MMSYSERR_INVALHANDLE
;
1293 dwRet
= MMDRV_Close(wmld
, MIDM_CLOSE
);
1294 MMDRV_Free(hMidiIn
, wmld
);
1298 /**************************************************************************
1299 * midiInPrepareHeader [WINMM.@]
1301 UINT WINAPI
midiInPrepareHeader(HMIDIIN hMidiIn
,
1302 MIDIHDR
* lpMidiInHdr
, UINT uSize
)
1306 TRACE("(%p, %p, %d)\n", hMidiIn
, lpMidiInHdr
, uSize
);
1308 if (lpMidiInHdr
== NULL
|| uSize
< sizeof (MIDIHDR
))
1309 return MMSYSERR_INVALPARAM
;
1311 if ((wmld
= MMDRV_Get(hMidiIn
, MMDRV_MIDIIN
, FALSE
)) == NULL
)
1312 return MMSYSERR_INVALHANDLE
;
1314 return MMDRV_Message(wmld
, MIDM_PREPARE
, (DWORD_PTR
)lpMidiInHdr
, uSize
, TRUE
);
1317 /**************************************************************************
1318 * midiInUnprepareHeader [WINMM.@]
1320 UINT WINAPI
midiInUnprepareHeader(HMIDIIN hMidiIn
,
1321 MIDIHDR
* lpMidiInHdr
, UINT uSize
)
1325 TRACE("(%p, %p, %d)\n", hMidiIn
, lpMidiInHdr
, uSize
);
1327 if (lpMidiInHdr
== NULL
|| uSize
< sizeof (MIDIHDR
))
1328 return MMSYSERR_INVALPARAM
;
1330 if (!(lpMidiInHdr
->dwFlags
& MHDR_PREPARED
)) {
1331 return MMSYSERR_NOERROR
;
1334 if ((wmld
= MMDRV_Get(hMidiIn
, MMDRV_MIDIIN
, FALSE
)) == NULL
)
1335 return MMSYSERR_INVALHANDLE
;
1337 return MMDRV_Message(wmld
, MIDM_UNPREPARE
, (DWORD_PTR
)lpMidiInHdr
, uSize
, TRUE
);
1340 /**************************************************************************
1341 * midiInAddBuffer [WINMM.@]
1343 UINT WINAPI
midiInAddBuffer(HMIDIIN hMidiIn
,
1344 MIDIHDR
* lpMidiInHdr
, UINT uSize
)
1348 TRACE("(%p, %p, %d)\n", hMidiIn
, lpMidiInHdr
, uSize
);
1350 if ((wmld
= MMDRV_Get(hMidiIn
, MMDRV_MIDIIN
, FALSE
)) == NULL
)
1351 return MMSYSERR_INVALHANDLE
;
1353 return MMDRV_Message(wmld
, MIDM_ADDBUFFER
, (DWORD_PTR
)lpMidiInHdr
, uSize
, TRUE
);
1356 /**************************************************************************
1357 * midiInStart [WINMM.@]
1359 UINT WINAPI
midiInStart(HMIDIIN hMidiIn
)
1363 TRACE("(%p)\n", hMidiIn
);
1365 if ((wmld
= MMDRV_Get(hMidiIn
, MMDRV_MIDIIN
, FALSE
)) == NULL
)
1366 return MMSYSERR_INVALHANDLE
;
1368 return MMDRV_Message(wmld
, MIDM_START
, 0L, 0L, TRUE
);
1371 /**************************************************************************
1372 * midiInStop [WINMM.@]
1374 UINT WINAPI
midiInStop(HMIDIIN hMidiIn
)
1378 TRACE("(%p)\n", hMidiIn
);
1380 if ((wmld
= MMDRV_Get(hMidiIn
, MMDRV_MIDIIN
, FALSE
)) == NULL
)
1381 return MMSYSERR_INVALHANDLE
;
1383 return MMDRV_Message(wmld
, MIDM_STOP
, 0L, 0L, TRUE
);
1386 /**************************************************************************
1387 * midiInReset [WINMM.@]
1389 UINT WINAPI
midiInReset(HMIDIIN hMidiIn
)
1393 TRACE("(%p)\n", hMidiIn
);
1395 if ((wmld
= MMDRV_Get(hMidiIn
, MMDRV_MIDIIN
, FALSE
)) == NULL
)
1396 return MMSYSERR_INVALHANDLE
;
1398 return MMDRV_Message(wmld
, MIDM_RESET
, 0L, 0L, TRUE
);
1401 /**************************************************************************
1402 * midiInGetID [WINMM.@]
1404 UINT WINAPI
midiInGetID(HMIDIIN hMidiIn
, UINT
* lpuDeviceID
)
1408 TRACE("(%p, %p)\n", hMidiIn
, lpuDeviceID
);
1410 if (lpuDeviceID
== NULL
) return MMSYSERR_INVALPARAM
;
1412 if ((wmld
= MMDRV_Get(hMidiIn
, MMDRV_MIDIIN
, TRUE
)) == NULL
)
1413 return MMSYSERR_INVALHANDLE
;
1415 *lpuDeviceID
= wmld
->uDeviceID
;
1417 return MMSYSERR_NOERROR
;
1420 /**************************************************************************
1421 * midiInMessage [WINMM.@]
1423 UINT WINAPI
midiInMessage(HMIDIIN hMidiIn
, UINT uMessage
,
1424 DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
1428 TRACE("(%p, %04X, %08lX, %08lX)\n", hMidiIn
, uMessage
, dwParam1
, dwParam2
);
1430 if ((wmld
= MMDRV_Get(hMidiIn
, MMDRV_MIDIIN
, FALSE
)) == NULL
)
1431 return MMSYSERR_INVALHANDLE
;
1436 FIXME("can't handle OPEN or CLOSE message!\n");
1437 return MMSYSERR_NOTSUPPORTED
;
1439 return MMDRV_Message(wmld
, uMessage
, dwParam1
, dwParam2
, TRUE
);
1442 typedef struct WINE_MIDIStream
{
1453 LPMIDIHDR lpMidiHdr
;
1456 #define WINE_MSM_HEADER (WM_USER+0)
1457 #define WINE_MSM_STOP (WM_USER+1)
1459 /**************************************************************************
1460 * MMSYSTEM_GetMidiStream [internal]
1462 static BOOL
MMSYSTEM_GetMidiStream(HMIDISTRM hMidiStrm
, WINE_MIDIStream
** lpMidiStrm
, WINE_MIDI
** lplpwm
)
1464 WINE_MIDI
* lpwm
= (LPWINE_MIDI
)MMDRV_Get(hMidiStrm
, MMDRV_MIDIOUT
, FALSE
);
1473 *lpMidiStrm
= (WINE_MIDIStream
*)lpwm
->mod
.rgIds
.dwStreamID
;
1475 return *lpMidiStrm
!= NULL
;
1478 /**************************************************************************
1479 * MMSYSTEM_MidiStream_Convert [internal]
1481 static DWORD
MMSYSTEM_MidiStream_Convert(WINE_MIDIStream
* lpMidiStrm
, DWORD pulse
)
1485 if (lpMidiStrm
->dwTimeDiv
== 0) {
1486 FIXME("Shouldn't happen. lpMidiStrm->dwTimeDiv = 0\n");
1487 } else if (lpMidiStrm
->dwTimeDiv
> 0x8000) { /* SMPTE, unchecked FIXME? */
1488 int nf
= -(char)HIBYTE(lpMidiStrm
->dwTimeDiv
); /* number of frames */
1489 int nsf
= LOBYTE(lpMidiStrm
->dwTimeDiv
); /* number of sub-frames */
1490 ret
= (pulse
* 1000) / (nf
* nsf
);
1492 ret
= (DWORD
)((double)pulse
* ((double)lpMidiStrm
->dwTempo
/ 1000) /
1493 (double)lpMidiStrm
->dwTimeDiv
);
1499 /**************************************************************************
1500 * MMSYSTEM_MidiStream_MessageHandler [internal]
1502 static BOOL
MMSYSTEM_MidiStream_MessageHandler(WINE_MIDIStream
* lpMidiStrm
, LPWINE_MIDI lpwm
, LPMSG msg
)
1504 LPMIDIHDR lpMidiHdr
;
1508 switch (msg
->message
) {
1510 SetEvent(lpMidiStrm
->hEvent
);
1514 /* this is not quite what MS doc says... */
1515 midiOutReset(lpMidiStrm
->hDevice
);
1516 /* empty list of already submitted buffers */
1517 for (lpMidiHdr
= lpMidiStrm
->lpMidiHdr
; lpMidiHdr
; lpMidiHdr
= lpMidiHdr
->lpNext
) {
1518 lpMidiHdr
->dwFlags
|= MHDR_DONE
;
1519 lpMidiHdr
->dwFlags
&= ~MHDR_INQUEUE
;
1521 DriverCallback(lpwm
->mod
.dwCallback
, lpMidiStrm
->wFlags
,
1522 (HDRVR
)lpMidiStrm
->hDevice
, MM_MOM_DONE
,
1523 lpwm
->mod
.dwInstance
, (DWORD
)lpMidiHdr
, 0L);
1525 lpMidiStrm
->lpMidiHdr
= 0;
1526 SetEvent(lpMidiStrm
->hEvent
);
1528 case WINE_MSM_HEADER
:
1529 /* sets initial tick count for first MIDIHDR */
1530 if (!lpMidiStrm
->dwStartTicks
)
1531 lpMidiStrm
->dwStartTicks
= GetTickCount();
1533 /* FIXME(EPP): "I don't understand the content of the first MIDIHDR sent
1534 * by native mcimidi, it doesn't look like a correct one".
1535 * this trick allows to throw it away... but I don't like it.
1536 * It looks like part of the file I'm trying to play and definitively looks
1537 * like raw midi content
1538 * I'd really like to understand why native mcimidi sends it. Perhaps a bad
1539 * synchronization issue where native mcimidi is still processing raw MIDI
1540 * content before generating MIDIEVENTs ?
1542 * 4c 04 89 3b 00 81 7c 99 3b 43 00 99 23 5e 04 89 L..;..|.;C..#^..
1543 * 3b 00 00 89 23 00 7c 99 3b 45 00 99 28 62 04 89 ;...#.|.;E..(b..
1544 * 3b 00 00 89 28 00 81 7c 99 3b 4e 00 99 23 5e 04 ;...(..|.;N..#^.
1545 * 89 3b 00 00 89 23 00 7c 99 3b 45 00 99 23 78 04 .;...#.|.;E..#x.
1546 * 89 3b 00 00 89 23 00 81 7c 99 3b 48 00 99 23 5e .;...#..|.;H..#^
1547 * 04 89 3b 00 00 89 23 00 7c 99 3b 4e 00 99 28 62 ..;...#.|.;N..(b
1548 * 04 89 3b 00 00 89 28 00 81 7c 99 39 4c 00 99 23 ..;...(..|.9L..#
1549 * 5e 04 89 39 00 00 89 23 00 82 7c 99 3b 4c 00 99 ^..9...#..|.;L..
1550 * 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 00 99 #^..;...#.|.;H..
1551 * 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b 3f 04 (b..;...(..|.;?.
1552 * 89 3b 00 1c 99 23 5e 04 89 23 00 5c 99 3b 45 00 .;...#^..#.\.;E.
1553 * 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 3b 46 .#x..;...#..|.;F
1554 * 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 ..#^..;...#.|.;H
1555 * 00 99 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b ..(b..;...(..|.;
1556 * 46 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b F..#^..;...#.|.;
1557 * 48 00 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 H..#x..;...#..|.
1558 * 3b 4c 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 ;L..#^..;...#.|.
1560 lpMidiHdr
= (LPMIDIHDR
)msg
->lParam
;
1561 lpData
= (LPBYTE
)lpMidiHdr
->lpData
;
1562 TRACE("Adding %s lpMidiHdr=%p [lpData=0x%p dwBufferLength=%u/%u dwFlags=0x%08x size=%lu]\n",
1563 (lpMidiHdr
->dwFlags
& MHDR_ISSTRM
) ? "stream" : "regular", lpMidiHdr
,
1564 lpMidiHdr
, lpMidiHdr
->dwBufferLength
, lpMidiHdr
->dwBytesRecorded
,
1565 lpMidiHdr
->dwFlags
, msg
->wParam
);
1567 /* dumps content of lpMidiHdr->lpData
1568 * FIXME: there should be a debug routine somewhere that already does this
1569 * I hate spreading this type of shit all around the code
1571 for (dwToGo
= 0; dwToGo
< lpMidiHdr
->dwBufferLength
; dwToGo
+= 16) {
1575 for (i
= 0; i
< min(16, lpMidiHdr
->dwBufferLength
- dwToGo
); i
++)
1576 printf("%02x ", lpData
[dwToGo
+ i
]);
1579 for (i
= 0; i
< min(16, lpMidiHdr
->dwBufferLength
- dwToGo
); i
++) {
1580 ch
= lpData
[dwToGo
+ i
];
1581 printf("%c", (ch
>= 0x20 && ch
<= 0x7F) ? ch
: '.');
1586 if (((LPMIDIEVENT
)lpData
)->dwStreamID
!= 0 &&
1587 ((LPMIDIEVENT
)lpData
)->dwStreamID
!= 0xFFFFFFFF &&
1588 ((LPMIDIEVENT
)lpData
)->dwStreamID
!= (DWORD
)lpMidiStrm
) {
1589 FIXME("Dropping bad %s lpMidiHdr (streamID=%08x)\n",
1590 (lpMidiHdr
->dwFlags
& MHDR_ISSTRM
) ? "stream" : "regular",
1591 ((LPMIDIEVENT
)lpData
)->dwStreamID
);
1592 lpMidiHdr
->dwFlags
|= MHDR_DONE
;
1593 lpMidiHdr
->dwFlags
&= ~MHDR_INQUEUE
;
1595 DriverCallback(lpwm
->mod
.dwCallback
, lpMidiStrm
->wFlags
,
1596 (HDRVR
)lpMidiStrm
->hDevice
, MM_MOM_DONE
,
1597 lpwm
->mod
.dwInstance
, (DWORD
)lpMidiHdr
, 0L);
1601 for (lpmh
= &lpMidiStrm
->lpMidiHdr
; *lpmh
; lpmh
= &(*lpmh
)->lpNext
);
1603 lpMidiHdr
= (LPMIDIHDR
)msg
->lParam
;
1604 lpMidiHdr
->lpNext
= 0;
1605 lpMidiHdr
->dwFlags
|= MHDR_INQUEUE
;
1606 lpMidiHdr
->dwFlags
&= ~MHDR_DONE
;
1607 lpMidiHdr
->dwOffset
= 0;
1611 FIXME("Unknown message %d\n", msg
->message
);
1617 /**************************************************************************
1618 * MMSYSTEM_MidiStream_Player [internal]
1620 static DWORD CALLBACK
MMSYSTEM_MidiStream_Player(LPVOID pmt
)
1622 WINE_MIDIStream
* lpMidiStrm
= pmt
;
1627 LPMIDIHDR lpMidiHdr
;
1631 TRACE("(%p)!\n", lpMidiStrm
);
1634 (lpwm
= (LPWINE_MIDI
)MMDRV_Get(lpMidiStrm
->hDevice
, MMDRV_MIDIOUT
, FALSE
)) == NULL
)
1637 /* force thread's queue creation */
1638 /* Used to be InitThreadInput16(0, 5); */
1639 /* but following works also with hack in midiStreamOpen */
1640 PeekMessageA(&msg
, 0, 0, 0, 0);
1642 /* FIXME: this next line must be called before midiStreamOut or midiStreamRestart are called */
1643 SetEvent(lpMidiStrm
->hEvent
);
1644 TRACE("Ready to go 1\n");
1645 /* thread is started in paused mode */
1646 SuspendThread(lpMidiStrm
->hThread
);
1647 TRACE("Ready to go 2\n");
1649 lpMidiStrm
->dwStartTicks
= 0;
1650 lpMidiStrm
->dwPulses
= 0;
1652 lpMidiStrm
->lpMidiHdr
= 0;
1655 lpMidiHdr
= lpMidiStrm
->lpMidiHdr
;
1657 /* for first message, block until one arrives, then process all that are available */
1658 GetMessageA(&msg
, 0, 0, 0);
1660 if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm
, lpwm
, &msg
))
1662 } while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
));
1668 lpData
= (LPBYTE
)lpMidiHdr
->lpData
;
1670 me
= (LPMIDIEVENT
)(lpData
+ lpMidiHdr
->dwOffset
);
1672 /* do we have to wait ? */
1673 if (me
->dwDeltaTime
) {
1674 lpMidiStrm
->dwPositionMS
+= MMSYSTEM_MidiStream_Convert(lpMidiStrm
, me
->dwDeltaTime
);
1675 lpMidiStrm
->dwPulses
+= me
->dwDeltaTime
;
1677 dwToGo
= lpMidiStrm
->dwStartTicks
+ lpMidiStrm
->dwPositionMS
;
1679 TRACE("%d/%d/%d\n", dwToGo
, GetTickCount(), me
->dwDeltaTime
);
1680 while ((dwCurrTC
= GetTickCount()) < dwToGo
) {
1681 if (MsgWaitForMultipleObjects(0, NULL
, FALSE
, dwToGo
- dwCurrTC
, QS_ALLINPUT
) == WAIT_OBJECT_0
) {
1682 /* got a message, handle it */
1683 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) {
1684 if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm
, lpwm
, &msg
))
1689 /* timeout, so me->dwDeltaTime is elapsed, can break the while loop */
1694 switch (MEVT_EVENTTYPE(me
->dwEvent
& ~MEVT_F_CALLBACK
)) {
1696 FIXME("NIY: MEVT_COMMENT\n");
1697 /* do nothing, skip bytes */
1700 FIXME("NIY: MEVT_LONGMSG, aka sending Sysex event\n");
1705 midiOutShortMsg(lpMidiStrm
->hDevice
, MEVT_EVENTPARM(me
->dwEvent
));
1708 lpMidiStrm
->dwTempo
= MEVT_EVENTPARM(me
->dwEvent
);
1713 FIXME("Unknown MEVT (0x%02x)\n", MEVT_EVENTTYPE(me
->dwEvent
& ~MEVT_F_CALLBACK
));
1716 if (me
->dwEvent
& MEVT_F_CALLBACK
) {
1717 DriverCallback(lpwm
->mod
.dwCallback
, lpMidiStrm
->wFlags
,
1718 (HDRVR
)lpMidiStrm
->hDevice
, MM_MOM_POSITIONCB
,
1719 lpwm
->mod
.dwInstance
, (LPARAM
)lpMidiHdr
, 0L);
1721 lpMidiHdr
->dwOffset
+= sizeof(MIDIEVENT
) - sizeof(me
->dwParms
);
1722 if (me
->dwEvent
& MEVT_F_LONG
)
1723 lpMidiHdr
->dwOffset
+= (MEVT_EVENTPARM(me
->dwEvent
) + 3) & ~3;
1724 if (lpMidiHdr
->dwOffset
>= lpMidiHdr
->dwBufferLength
) {
1725 /* done with this header */
1726 lpMidiHdr
->dwFlags
|= MHDR_DONE
;
1727 lpMidiHdr
->dwFlags
&= ~MHDR_INQUEUE
;
1729 lpMidiStrm
->lpMidiHdr
= lpMidiHdr
->lpNext
;
1730 DriverCallback(lpwm
->mod
.dwCallback
, lpMidiStrm
->wFlags
,
1731 (HDRVR
)lpMidiStrm
->hDevice
, MM_MOM_DONE
,
1732 lpwm
->mod
.dwInstance
, (DWORD
)lpMidiHdr
, 0L);
1737 TRACE("End of thread\n");
1739 return 0; /* for removing the warning, never executed */
1742 /**************************************************************************
1743 * MMSYSTEM_MidiStream_PostMessage [internal]
1745 static BOOL
MMSYSTEM_MidiStream_PostMessage(WINE_MIDIStream
* lpMidiStrm
, WORD msg
, DWORD pmt1
, DWORD pmt2
)
1747 if (PostThreadMessageA(lpMidiStrm
->dwThreadID
, msg
, pmt1
, pmt2
)) {
1750 if (pFnReleaseThunkLock
) pFnReleaseThunkLock(&count
);
1751 WaitForSingleObject(lpMidiStrm
->hEvent
, INFINITE
);
1752 if (pFnRestoreThunkLock
) pFnRestoreThunkLock(count
);
1754 WARN("bad PostThreadMessageA\n");
1760 /**************************************************************************
1761 * midiStreamClose [WINMM.@]
1763 MMRESULT WINAPI
midiStreamClose(HMIDISTRM hMidiStrm
)
1765 WINE_MIDIStream
* lpMidiStrm
;
1767 TRACE("(%p)!\n", hMidiStrm
);
1769 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
))
1770 return MMSYSERR_INVALHANDLE
;
1772 midiStreamStop(hMidiStrm
);
1773 MMSYSTEM_MidiStream_PostMessage(lpMidiStrm
, WM_QUIT
, 0, 0);
1774 HeapFree(GetProcessHeap(), 0, lpMidiStrm
);
1775 CloseHandle(lpMidiStrm
->hEvent
);
1777 return midiOutClose((HMIDIOUT
)hMidiStrm
);
1780 /**************************************************************************
1781 * MMSYSTEM_MidiStream_Open [internal]
1783 MMRESULT
MIDI_StreamOpen(HMIDISTRM
* lphMidiStrm
, LPUINT lpuDeviceID
, DWORD cMidi
,
1784 DWORD_PTR dwCallback
, DWORD_PTR dwInstance
, DWORD fdwOpen
,
1787 WINE_MIDIStream
* lpMidiStrm
;
1789 MIDIOPENSTRMID mosm
;
1793 TRACE("(%p, %p, %d, 0x%08lx, 0x%08lx, 0x%08x)!\n",
1794 lphMidiStrm
, lpuDeviceID
, cMidi
, dwCallback
, dwInstance
, fdwOpen
);
1796 if (cMidi
!= 1 || lphMidiStrm
== NULL
|| lpuDeviceID
== NULL
)
1797 return MMSYSERR_INVALPARAM
;
1799 lpMidiStrm
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_MIDIStream
));
1801 return MMSYSERR_NOMEM
;
1803 lpMidiStrm
->dwTempo
= 500000;
1804 lpMidiStrm
->dwTimeDiv
= 480; /* 480 is 120 quarter notes per minute *//* FIXME ??*/
1805 lpMidiStrm
->dwPositionMS
= 0;
1807 mosm
.dwStreamID
= (DWORD
)lpMidiStrm
;
1808 /* FIXME: the correct value is not allocated yet for MAPPER */
1809 mosm
.wDeviceID
= *lpuDeviceID
;
1810 lpwm
= MIDI_OutAlloc(&hMidiOut
, &dwCallback
, &dwInstance
, &fdwOpen
, 1, &mosm
, bFrom32
);
1811 lpMidiStrm
->hDevice
= hMidiOut
;
1813 *lphMidiStrm
= (HMIDISTRM
)hMidiOut
;
1815 lpwm
->mld
.uDeviceID
= *lpuDeviceID
;
1817 ret
= MMDRV_Open(&lpwm
->mld
, MODM_OPEN
, (DWORD
)&lpwm
->mod
, fdwOpen
);
1818 lpMidiStrm
->hEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
1819 lpMidiStrm
->wFlags
= HIWORD(fdwOpen
);
1821 lpMidiStrm
->hThread
= CreateThread(NULL
, 0, MMSYSTEM_MidiStream_Player
,
1822 lpMidiStrm
, 0, &(lpMidiStrm
->dwThreadID
));
1824 if (!lpMidiStrm
->hThread
) {
1825 midiStreamClose((HMIDISTRM
)hMidiOut
);
1826 return MMSYSERR_NOMEM
;
1828 SetThreadPriority(lpMidiStrm
->hThread
, THREAD_PRIORITY_TIME_CRITICAL
);
1830 /* wait for thread to have started, and for its queue to be created */
1834 /* (Release|Restore)ThunkLock() is needed when this method is called from 16 bit code,
1835 * (meaning the Win16Lock is set), so that it's released and the 32 bit thread running
1836 * MMSYSTEM_MidiStreamPlayer can acquire Win16Lock to create its queue.
1838 if (pFnReleaseThunkLock
) pFnReleaseThunkLock(&count
);
1839 WaitForSingleObject(lpMidiStrm
->hEvent
, INFINITE
);
1840 if (pFnRestoreThunkLock
) pFnRestoreThunkLock(count
);
1843 TRACE("=> (%u/%d) hMidi=%p ret=%d lpMidiStrm=%p\n",
1844 *lpuDeviceID
, lpwm
->mld
.uDeviceID
, *lphMidiStrm
, ret
, lpMidiStrm
);
1848 /**************************************************************************
1849 * midiStreamOpen [WINMM.@]
1851 MMRESULT WINAPI
midiStreamOpen(HMIDISTRM
* lphMidiStrm
, LPUINT lpuDeviceID
,
1852 DWORD cMidi
, DWORD_PTR dwCallback
,
1853 DWORD_PTR dwInstance
, DWORD fdwOpen
)
1855 return MIDI_StreamOpen(lphMidiStrm
, lpuDeviceID
, cMidi
, dwCallback
,
1856 dwInstance
, fdwOpen
, TRUE
);
1859 /**************************************************************************
1860 * midiStreamOut [WINMM.@]
1862 MMRESULT WINAPI
midiStreamOut(HMIDISTRM hMidiStrm
, LPMIDIHDR lpMidiHdr
,
1865 WINE_MIDIStream
* lpMidiStrm
;
1866 DWORD ret
= MMSYSERR_NOERROR
;
1868 TRACE("(%p, %p, %u)!\n", hMidiStrm
, lpMidiHdr
, cbMidiHdr
);
1870 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
)) {
1871 ret
= MMSYSERR_INVALHANDLE
;
1872 } else if (!lpMidiHdr
) {
1873 ret
= MMSYSERR_INVALPARAM
;
1875 if (!PostThreadMessageA(lpMidiStrm
->dwThreadID
,
1876 WINE_MSM_HEADER
, cbMidiHdr
,
1877 (DWORD
)lpMidiHdr
)) {
1878 WARN("bad PostThreadMessageA\n");
1879 ret
= MMSYSERR_ERROR
;
1885 /**************************************************************************
1886 * midiStreamPause [WINMM.@]
1888 MMRESULT WINAPI
midiStreamPause(HMIDISTRM hMidiStrm
)
1890 WINE_MIDIStream
* lpMidiStrm
;
1891 DWORD ret
= MMSYSERR_NOERROR
;
1893 TRACE("(%p)!\n", hMidiStrm
);
1895 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
)) {
1896 ret
= MMSYSERR_INVALHANDLE
;
1898 if (SuspendThread(lpMidiStrm
->hThread
) == 0xFFFFFFFF) {
1899 WARN("bad Suspend (%d)\n", GetLastError());
1900 ret
= MMSYSERR_ERROR
;
1906 /**************************************************************************
1907 * midiStreamPosition [WINMM.@]
1909 MMRESULT WINAPI
midiStreamPosition(HMIDISTRM hMidiStrm
, LPMMTIME lpMMT
, UINT cbmmt
)
1911 WINE_MIDIStream
* lpMidiStrm
;
1912 DWORD ret
= MMSYSERR_NOERROR
;
1914 TRACE("(%p, %p, %u)!\n", hMidiStrm
, lpMMT
, cbmmt
);
1916 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
)) {
1917 ret
= MMSYSERR_INVALHANDLE
;
1918 } else if (lpMMT
== NULL
|| cbmmt
!= sizeof(MMTIME
)) {
1919 ret
= MMSYSERR_INVALPARAM
;
1921 switch (lpMMT
->wType
) {
1923 lpMMT
->u
.ms
= lpMidiStrm
->dwPositionMS
;
1924 TRACE("=> %d ms\n", lpMMT
->u
.ms
);
1927 lpMMT
->u
.ticks
= lpMidiStrm
->dwPulses
;
1928 TRACE("=> %d ticks\n", lpMMT
->u
.ticks
);
1931 WARN("Unsupported time type %d\n", lpMMT
->wType
);
1932 lpMMT
->wType
= TIME_MS
;
1933 ret
= MMSYSERR_INVALPARAM
;
1940 /**************************************************************************
1941 * midiStreamProperty [WINMM.@]
1943 MMRESULT WINAPI
midiStreamProperty(HMIDISTRM hMidiStrm
, LPBYTE lpPropData
, DWORD dwProperty
)
1945 WINE_MIDIStream
* lpMidiStrm
;
1946 MMRESULT ret
= MMSYSERR_NOERROR
;
1948 TRACE("(%p, %p, %x)\n", hMidiStrm
, lpPropData
, dwProperty
);
1950 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
)) {
1951 ret
= MMSYSERR_INVALHANDLE
;
1952 } else if ((dwProperty
& (MIDIPROP_GET
|MIDIPROP_SET
)) == 0) {
1953 ret
= MMSYSERR_INVALPARAM
;
1954 } else if (dwProperty
& MIDIPROP_TEMPO
) {
1955 MIDIPROPTEMPO
* mpt
= (MIDIPROPTEMPO
*)lpPropData
;
1957 if (sizeof(MIDIPROPTEMPO
) != mpt
->cbStruct
) {
1958 ret
= MMSYSERR_INVALPARAM
;
1959 } else if (dwProperty
& MIDIPROP_SET
) {
1960 lpMidiStrm
->dwTempo
= mpt
->dwTempo
;
1961 TRACE("Setting tempo to %d\n", mpt
->dwTempo
);
1962 } else if (dwProperty
& MIDIPROP_GET
) {
1963 mpt
->dwTempo
= lpMidiStrm
->dwTempo
;
1964 TRACE("Getting tempo <= %d\n", mpt
->dwTempo
);
1966 } else if (dwProperty
& MIDIPROP_TIMEDIV
) {
1967 MIDIPROPTIMEDIV
* mptd
= (MIDIPROPTIMEDIV
*)lpPropData
;
1969 if (sizeof(MIDIPROPTIMEDIV
) != mptd
->cbStruct
) {
1970 ret
= MMSYSERR_INVALPARAM
;
1971 } else if (dwProperty
& MIDIPROP_SET
) {
1972 lpMidiStrm
->dwTimeDiv
= mptd
->dwTimeDiv
;
1973 TRACE("Setting time div to %d\n", mptd
->dwTimeDiv
);
1974 } else if (dwProperty
& MIDIPROP_GET
) {
1975 mptd
->dwTimeDiv
= lpMidiStrm
->dwTimeDiv
;
1976 TRACE("Getting time div <= %d\n", mptd
->dwTimeDiv
);
1979 ret
= MMSYSERR_INVALPARAM
;
1985 /**************************************************************************
1986 * midiStreamRestart [WINMM.@]
1988 MMRESULT WINAPI
midiStreamRestart(HMIDISTRM hMidiStrm
)
1990 WINE_MIDIStream
* lpMidiStrm
;
1991 MMRESULT ret
= MMSYSERR_NOERROR
;
1993 TRACE("(%p)!\n", hMidiStrm
);
1995 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
)) {
1996 ret
= MMSYSERR_INVALHANDLE
;
2000 /* since we increase the thread suspend count on each midiStreamPause
2001 * there may be a need for several midiStreamResume
2004 ret
= ResumeThread(lpMidiStrm
->hThread
);
2005 } while (ret
!= 0xFFFFFFFF && ret
!= 0);
2006 if (ret
== 0xFFFFFFFF) {
2007 WARN("bad Resume (%d)\n", GetLastError());
2008 ret
= MMSYSERR_ERROR
;
2010 lpMidiStrm
->dwStartTicks
= GetTickCount() - lpMidiStrm
->dwPositionMS
;
2016 /**************************************************************************
2017 * midiStreamStop [WINMM.@]
2019 MMRESULT WINAPI
midiStreamStop(HMIDISTRM hMidiStrm
)
2021 WINE_MIDIStream
* lpMidiStrm
;
2022 MMRESULT ret
= MMSYSERR_NOERROR
;
2024 TRACE("(%p)!\n", hMidiStrm
);
2026 if (!MMSYSTEM_GetMidiStream(hMidiStrm
, &lpMidiStrm
, NULL
)) {
2027 ret
= MMSYSERR_INVALHANDLE
;
2029 /* in case stream has been paused... FIXME is the current state correct ? */
2030 midiStreamRestart(hMidiStrm
);
2031 MMSYSTEM_MidiStream_PostMessage(lpMidiStrm
, WINE_MSM_STOP
, 0, 0);
2036 UINT
WAVE_Open(HANDLE
* lphndl
, UINT uDeviceID
, UINT uType
,
2037 LPCWAVEFORMATEX lpFormat
, DWORD_PTR dwCallback
,
2038 DWORD_PTR dwInstance
, DWORD dwFlags
, BOOL bFrom32
)
2042 DWORD dwRet
= MMSYSERR_NOERROR
;
2045 TRACE("(%p, %d, %s, %p, %08lX, %08lX, %08X, %d);\n",
2046 lphndl
, (int)uDeviceID
, (uType
==MMDRV_WAVEOUT
)?"Out":"In", lpFormat
, dwCallback
,
2047 dwInstance
, dwFlags
, bFrom32
?32:16);
2049 if (dwFlags
& WAVE_FORMAT_QUERY
)
2050 TRACE("WAVE_FORMAT_QUERY requested !\n");
2052 if (lpFormat
== NULL
) {
2053 WARN("bad format\n");
2054 return WAVERR_BADFORMAT
;
2057 if ((dwFlags
& WAVE_MAPPED
) && (uDeviceID
== (UINT
)-1)) {
2058 WARN("invalid parameter\n");
2059 return MMSYSERR_INVALPARAM
;
2062 /* may have a PCMWAVEFORMAT rather than a WAVEFORMATEX so don't read cbSize */
2063 TRACE("wFormatTag=%u, nChannels=%u, nSamplesPerSec=%u, nAvgBytesPerSec=%u, nBlockAlign=%u, wBitsPerSample=%u\n",
2064 lpFormat
->wFormatTag
, lpFormat
->nChannels
, lpFormat
->nSamplesPerSec
,
2065 lpFormat
->nAvgBytesPerSec
, lpFormat
->nBlockAlign
, lpFormat
->wBitsPerSample
);
2067 if ((wmld
= MMDRV_Alloc(sizeof(WINE_WAVE
), uType
, &handle
,
2068 &dwFlags
, &dwCallback
, &dwInstance
, bFrom32
)) == NULL
) {
2069 WARN("no memory\n");
2070 return MMSYSERR_NOMEM
;
2074 wod
.lpFormat
= (LPWAVEFORMATEX
)lpFormat
; /* should the struct be copied iso pointer? */
2075 wod
.dwCallback
= dwCallback
;
2076 wod
.dwInstance
= dwInstance
;
2079 TRACE("cb=%08x\n", wod
.dwCallback
);
2082 if (dwFlags
& WAVE_MAPPED
) {
2083 wod
.uMappedDeviceID
= uDeviceID
;
2084 uDeviceID
= WAVE_MAPPER
;
2086 wod
.uMappedDeviceID
= -1;
2088 wmld
->uDeviceID
= uDeviceID
;
2090 dwRet
= MMDRV_Open(wmld
, (uType
== MMDRV_WAVEOUT
) ? WODM_OPEN
: WIDM_OPEN
,
2091 (DWORD
)&wod
, dwFlags
);
2093 TRACE("dwRet = %s\n", WINMM_ErrorToString(dwRet
));
2094 if (dwRet
!= WAVERR_BADFORMAT
||
2095 ((dwFlags
& (WAVE_MAPPED
|WAVE_FORMAT_DIRECT
)) != 0) || (uDeviceID
== WAVE_MAPPER
)) break;
2096 /* if we ask for a format which isn't supported by the physical driver,
2097 * let's try to map it through the wave mapper (except, if we already tried
2098 * or user didn't allow us to use acm codecs or the device is already the mapper)
2100 dwFlags
|= WAVE_MAPPED
;
2101 /* we shall loop only one */
2104 if ((dwFlags
& WAVE_FORMAT_QUERY
) || dwRet
!= MMSYSERR_NOERROR
) {
2105 MMDRV_Free(handle
, wmld
);
2109 if (lphndl
!= NULL
) *lphndl
= handle
;
2110 TRACE("=> %s hWave=%p\n", WINMM_ErrorToString(dwRet
), handle
);
2115 /**************************************************************************
2116 * waveOutGetNumDevs [WINMM.@]
2118 UINT WINAPI
waveOutGetNumDevs(void)
2120 return MMDRV_GetNum(MMDRV_WAVEOUT
);
2123 /**************************************************************************
2124 * waveOutGetDevCapsA [WINMM.@]
2126 UINT WINAPI
waveOutGetDevCapsA(UINT_PTR uDeviceID
, LPWAVEOUTCAPSA lpCaps
,
2132 if (lpCaps
== NULL
) return MMSYSERR_INVALPARAM
;
2134 ret
= waveOutGetDevCapsW(uDeviceID
, &wocW
, sizeof(wocW
));
2136 if (ret
== MMSYSERR_NOERROR
) {
2138 wocA
.wMid
= wocW
.wMid
;
2139 wocA
.wPid
= wocW
.wPid
;
2140 wocA
.vDriverVersion
= wocW
.vDriverVersion
;
2141 WideCharToMultiByte( CP_ACP
, 0, wocW
.szPname
, -1, wocA
.szPname
,
2142 sizeof(wocA
.szPname
), NULL
, NULL
);
2143 wocA
.dwFormats
= wocW
.dwFormats
;
2144 wocA
.wChannels
= wocW
.wChannels
;
2145 wocA
.dwSupport
= wocW
.dwSupport
;
2146 memcpy(lpCaps
, &wocA
, min(uSize
, sizeof(wocA
)));
2151 /**************************************************************************
2152 * waveOutGetDevCapsW [WINMM.@]
2154 UINT WINAPI
waveOutGetDevCapsW(UINT_PTR uDeviceID
, LPWAVEOUTCAPSW lpCaps
,
2159 TRACE("(%lu %p %u)!\n", uDeviceID
, lpCaps
, uSize
);
2161 if (lpCaps
== NULL
) return MMSYSERR_INVALPARAM
;
2163 if ((wmld
= MMDRV_Get((HANDLE
)uDeviceID
, MMDRV_WAVEOUT
, TRUE
)) == NULL
)
2164 return MMSYSERR_BADDEVICEID
;
2166 return MMDRV_Message(wmld
, WODM_GETDEVCAPS
, (DWORD_PTR
)lpCaps
, uSize
, TRUE
);
2170 /**************************************************************************
2171 * waveOutGetErrorTextA [WINMM.@]
2172 * waveInGetErrorTextA [WINMM.@]
2174 UINT WINAPI
waveOutGetErrorTextA(UINT uError
, LPSTR lpText
, UINT uSize
)
2178 if (lpText
== NULL
) ret
= MMSYSERR_INVALPARAM
;
2179 else if (uSize
== 0) ret
= MMSYSERR_NOERROR
;
2182 LPWSTR xstr
= HeapAlloc(GetProcessHeap(), 0, uSize
* sizeof(WCHAR
));
2183 if (!xstr
) ret
= MMSYSERR_NOMEM
;
2186 ret
= waveOutGetErrorTextW(uError
, xstr
, uSize
);
2187 if (ret
== MMSYSERR_NOERROR
)
2188 WideCharToMultiByte(CP_ACP
, 0, xstr
, -1, lpText
, uSize
, NULL
, NULL
);
2189 HeapFree(GetProcessHeap(), 0, xstr
);
2195 /**************************************************************************
2196 * waveOutGetErrorTextW [WINMM.@]
2197 * waveInGetErrorTextW [WINMM.@]
2199 UINT WINAPI
waveOutGetErrorTextW(UINT uError
, LPWSTR lpText
, UINT uSize
)
2201 UINT ret
= MMSYSERR_BADERRNUM
;
2203 if (lpText
== NULL
) ret
= MMSYSERR_INVALPARAM
;
2204 else if (uSize
== 0) ret
= MMSYSERR_NOERROR
;
2206 /* test has been removed because MMSYSERR_BASE is 0, and gcc did emit
2207 * a warning for the test was always true */
2208 (/*uError >= MMSYSERR_BASE && */ uError
<= MMSYSERR_LASTERROR
) ||
2209 (uError
>= WAVERR_BASE
&& uError
<= WAVERR_LASTERROR
)) {
2210 if (LoadStringW(hWinMM32Instance
,
2211 uError
, lpText
, uSize
) > 0) {
2212 ret
= MMSYSERR_NOERROR
;
2218 /**************************************************************************
2219 * waveOutOpen [WINMM.@]
2220 * All the args/structs have the same layout as the win16 equivalents
2222 MMRESULT WINAPI
waveOutOpen(LPHWAVEOUT lphWaveOut
, UINT uDeviceID
,
2223 LPCWAVEFORMATEX lpFormat
, DWORD_PTR dwCallback
,
2224 DWORD_PTR dwInstance
, DWORD dwFlags
)
2226 return WAVE_Open((HANDLE
*)lphWaveOut
, uDeviceID
, MMDRV_WAVEOUT
, lpFormat
,
2227 dwCallback
, dwInstance
, dwFlags
, TRUE
);
2230 /**************************************************************************
2231 * waveOutClose [WINMM.@]
2233 UINT WINAPI
waveOutClose(HWAVEOUT hWaveOut
)
2238 TRACE("(%p)\n", hWaveOut
);
2240 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2241 return MMSYSERR_INVALHANDLE
;
2243 dwRet
= MMDRV_Close(wmld
, WODM_CLOSE
);
2244 if (dwRet
!= WAVERR_STILLPLAYING
)
2245 MMDRV_Free(hWaveOut
, wmld
);
2250 /**************************************************************************
2251 * waveOutPrepareHeader [WINMM.@]
2253 UINT WINAPI
waveOutPrepareHeader(HWAVEOUT hWaveOut
,
2254 WAVEHDR
* lpWaveOutHdr
, UINT uSize
)
2259 TRACE("(%p, %p, %u);\n", hWaveOut
, lpWaveOutHdr
, uSize
);
2261 if (lpWaveOutHdr
== NULL
|| uSize
< sizeof (WAVEHDR
))
2262 return MMSYSERR_INVALPARAM
;
2264 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2265 return MMSYSERR_INVALHANDLE
;
2267 if ((result
= MMDRV_Message(wmld
, WODM_PREPARE
, (DWORD_PTR
)lpWaveOutHdr
,
2268 uSize
, TRUE
)) != MMSYSERR_NOTSUPPORTED
)
2271 if (lpWaveOutHdr
->dwFlags
& WHDR_INQUEUE
)
2272 return WAVERR_STILLPLAYING
;
2274 lpWaveOutHdr
->dwFlags
|= WHDR_PREPARED
;
2275 lpWaveOutHdr
->dwFlags
&= ~WHDR_DONE
;
2277 return MMSYSERR_NOERROR
;
2280 /**************************************************************************
2281 * waveOutUnprepareHeader [WINMM.@]
2283 UINT WINAPI
waveOutUnprepareHeader(HWAVEOUT hWaveOut
,
2284 LPWAVEHDR lpWaveOutHdr
, UINT uSize
)
2289 TRACE("(%p, %p, %u);\n", hWaveOut
, lpWaveOutHdr
, uSize
);
2291 if (lpWaveOutHdr
== NULL
|| uSize
< sizeof (WAVEHDR
))
2292 return MMSYSERR_INVALPARAM
;
2294 if (!(lpWaveOutHdr
->dwFlags
& WHDR_PREPARED
)) {
2295 return MMSYSERR_NOERROR
;
2298 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2299 return MMSYSERR_INVALHANDLE
;
2301 if ((result
= MMDRV_Message(wmld
, WODM_UNPREPARE
, (DWORD_PTR
)lpWaveOutHdr
,
2302 uSize
, TRUE
)) != MMSYSERR_NOTSUPPORTED
)
2305 if (lpWaveOutHdr
->dwFlags
& WHDR_INQUEUE
)
2306 return WAVERR_STILLPLAYING
;
2308 lpWaveOutHdr
->dwFlags
&= ~WHDR_PREPARED
;
2309 lpWaveOutHdr
->dwFlags
|= WHDR_DONE
;
2311 return MMSYSERR_NOERROR
;
2314 /**************************************************************************
2315 * waveOutWrite [WINMM.@]
2317 UINT WINAPI
waveOutWrite(HWAVEOUT hWaveOut
, LPWAVEHDR lpWaveOutHdr
,
2322 TRACE("(%p, %p, %u);\n", hWaveOut
, lpWaveOutHdr
, uSize
);
2324 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2325 return MMSYSERR_INVALHANDLE
;
2327 return MMDRV_Message(wmld
, WODM_WRITE
, (DWORD_PTR
)lpWaveOutHdr
, uSize
, TRUE
);
2330 /**************************************************************************
2331 * waveOutBreakLoop [WINMM.@]
2333 UINT WINAPI
waveOutBreakLoop(HWAVEOUT hWaveOut
)
2337 TRACE("(%p);\n", hWaveOut
);
2339 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2340 return MMSYSERR_INVALHANDLE
;
2341 return MMDRV_Message(wmld
, WODM_BREAKLOOP
, 0L, 0L, TRUE
);
2344 /**************************************************************************
2345 * waveOutPause [WINMM.@]
2347 UINT WINAPI
waveOutPause(HWAVEOUT hWaveOut
)
2351 TRACE("(%p);\n", hWaveOut
);
2353 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2354 return MMSYSERR_INVALHANDLE
;
2355 return MMDRV_Message(wmld
, WODM_PAUSE
, 0L, 0L, TRUE
);
2358 /**************************************************************************
2359 * waveOutReset [WINMM.@]
2361 UINT WINAPI
waveOutReset(HWAVEOUT hWaveOut
)
2365 TRACE("(%p);\n", hWaveOut
);
2367 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2368 return MMSYSERR_INVALHANDLE
;
2369 return MMDRV_Message(wmld
, WODM_RESET
, 0L, 0L, TRUE
);
2372 /**************************************************************************
2373 * waveOutRestart [WINMM.@]
2375 UINT WINAPI
waveOutRestart(HWAVEOUT hWaveOut
)
2379 TRACE("(%p);\n", hWaveOut
);
2381 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2382 return MMSYSERR_INVALHANDLE
;
2383 return MMDRV_Message(wmld
, WODM_RESTART
, 0L, 0L, TRUE
);
2386 /**************************************************************************
2387 * waveOutGetPosition [WINMM.@]
2389 UINT WINAPI
waveOutGetPosition(HWAVEOUT hWaveOut
, LPMMTIME lpTime
,
2394 TRACE("(%p, %p, %u);\n", hWaveOut
, lpTime
, uSize
);
2396 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2397 return MMSYSERR_INVALHANDLE
;
2399 return MMDRV_Message(wmld
, WODM_GETPOS
, (DWORD_PTR
)lpTime
, uSize
, TRUE
);
2402 /**************************************************************************
2403 * waveOutGetPitch [WINMM.@]
2405 UINT WINAPI
waveOutGetPitch(HWAVEOUT hWaveOut
, LPDWORD lpdw
)
2409 TRACE("(%p, %p);\n", hWaveOut
, lpdw
);
2411 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2412 return MMSYSERR_INVALHANDLE
;
2413 return MMDRV_Message(wmld
, WODM_GETPITCH
, (DWORD_PTR
)lpdw
, 0L, TRUE
);
2416 /**************************************************************************
2417 * waveOutSetPitch [WINMM.@]
2419 UINT WINAPI
waveOutSetPitch(HWAVEOUT hWaveOut
, DWORD dw
)
2423 TRACE("(%p, %08x);\n", hWaveOut
, dw
);
2425 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2426 return MMSYSERR_INVALHANDLE
;
2427 return MMDRV_Message(wmld
, WODM_SETPITCH
, dw
, 0L, TRUE
);
2430 /**************************************************************************
2431 * waveOutGetPlaybackRate [WINMM.@]
2433 UINT WINAPI
waveOutGetPlaybackRate(HWAVEOUT hWaveOut
, LPDWORD lpdw
)
2437 TRACE("(%p, %p);\n", hWaveOut
, lpdw
);
2439 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2440 return MMSYSERR_INVALHANDLE
;
2441 return MMDRV_Message(wmld
, WODM_GETPLAYBACKRATE
, (DWORD_PTR
)lpdw
, 0L, TRUE
);
2444 /**************************************************************************
2445 * waveOutSetPlaybackRate [WINMM.@]
2447 UINT WINAPI
waveOutSetPlaybackRate(HWAVEOUT hWaveOut
, DWORD dw
)
2451 TRACE("(%p, %08x);\n", hWaveOut
, dw
);
2453 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2454 return MMSYSERR_INVALHANDLE
;
2455 return MMDRV_Message(wmld
, WODM_SETPLAYBACKRATE
, dw
, 0L, TRUE
);
2458 /**************************************************************************
2459 * waveOutGetVolume [WINMM.@]
2461 UINT WINAPI
waveOutGetVolume(HWAVEOUT hWaveOut
, LPDWORD lpdw
)
2465 TRACE("(%p, %p);\n", hWaveOut
, lpdw
);
2468 WARN("invalid parameter\n");
2469 return MMSYSERR_INVALPARAM
;
2472 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, TRUE
)) == NULL
)
2473 return MMSYSERR_INVALHANDLE
;
2475 return MMDRV_Message(wmld
, WODM_GETVOLUME
, (DWORD_PTR
)lpdw
, 0L, TRUE
);
2478 /**************************************************************************
2479 * waveOutSetVolume [WINMM.@]
2481 UINT WINAPI
waveOutSetVolume(HWAVEOUT hWaveOut
, DWORD dw
)
2485 TRACE("(%p, %08x);\n", hWaveOut
, dw
);
2487 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, TRUE
)) == NULL
)
2488 return MMSYSERR_INVALHANDLE
;
2490 return MMDRV_Message(wmld
, WODM_SETVOLUME
, dw
, 0L, TRUE
);
2493 /**************************************************************************
2494 * waveOutGetID [WINMM.@]
2496 UINT WINAPI
waveOutGetID(HWAVEOUT hWaveOut
, UINT
* lpuDeviceID
)
2500 TRACE("(%p, %p);\n", hWaveOut
, lpuDeviceID
);
2502 if (lpuDeviceID
== NULL
) return MMSYSERR_INVALHANDLE
;
2504 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
)
2505 return MMSYSERR_INVALHANDLE
;
2507 *lpuDeviceID
= wmld
->uDeviceID
;
2511 /**************************************************************************
2512 * waveOutMessage [WINMM.@]
2514 UINT WINAPI
waveOutMessage(HWAVEOUT hWaveOut
, UINT uMessage
,
2515 DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
2519 TRACE("(%p, %u, %ld, %ld)\n", hWaveOut
, uMessage
, dwParam1
, dwParam2
);
2521 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, FALSE
)) == NULL
) {
2522 if ((wmld
= MMDRV_Get(hWaveOut
, MMDRV_WAVEOUT
, TRUE
)) != NULL
) {
2523 return MMDRV_PhysicalFeatures(wmld
, uMessage
, dwParam1
, dwParam2
);
2525 WARN("invalid handle\n");
2526 return MMSYSERR_INVALHANDLE
;
2530 if (uMessage
< DRVM_IOCTL
|| (uMessage
>= DRVM_IOCTL_LAST
&& uMessage
< DRVM_MAPPER
)) {
2531 WARN("invalid parameter\n");
2532 return MMSYSERR_INVALPARAM
;
2535 return MMDRV_Message(wmld
, uMessage
, dwParam1
, dwParam2
, TRUE
);
2538 /**************************************************************************
2539 * waveInGetNumDevs [WINMM.@]
2541 UINT WINAPI
waveInGetNumDevs(void)
2543 return MMDRV_GetNum(MMDRV_WAVEIN
);
2546 /**************************************************************************
2547 * waveInGetDevCapsW [WINMM.@]
2549 UINT WINAPI
waveInGetDevCapsW(UINT_PTR uDeviceID
, LPWAVEINCAPSW lpCaps
, UINT uSize
)
2553 TRACE("(%lu %p %u)!\n", uDeviceID
, lpCaps
, uSize
);
2555 if (lpCaps
== NULL
) return MMSYSERR_INVALPARAM
;
2557 if ((wmld
= MMDRV_Get((HANDLE
)uDeviceID
, MMDRV_WAVEIN
, TRUE
)) == NULL
)
2558 return MMSYSERR_BADDEVICEID
;
2560 return MMDRV_Message(wmld
, WIDM_GETDEVCAPS
, (DWORD_PTR
)lpCaps
, uSize
, TRUE
);
2563 /**************************************************************************
2564 * waveInGetDevCapsA [WINMM.@]
2566 UINT WINAPI
waveInGetDevCapsA(UINT_PTR uDeviceID
, LPWAVEINCAPSA lpCaps
, UINT uSize
)
2571 if (lpCaps
== NULL
) return MMSYSERR_INVALPARAM
;
2573 ret
= waveInGetDevCapsW(uDeviceID
, &wicW
, sizeof(wicW
));
2575 if (ret
== MMSYSERR_NOERROR
) {
2577 wicA
.wMid
= wicW
.wMid
;
2578 wicA
.wPid
= wicW
.wPid
;
2579 wicA
.vDriverVersion
= wicW
.vDriverVersion
;
2580 WideCharToMultiByte( CP_ACP
, 0, wicW
.szPname
, -1, wicA
.szPname
,
2581 sizeof(wicA
.szPname
), NULL
, NULL
);
2582 wicA
.dwFormats
= wicW
.dwFormats
;
2583 wicA
.wChannels
= wicW
.wChannels
;
2584 memcpy(lpCaps
, &wicA
, min(uSize
, sizeof(wicA
)));
2589 /**************************************************************************
2590 * waveInOpen [WINMM.@]
2592 MMRESULT WINAPI
waveInOpen(HWAVEIN
* lphWaveIn
, UINT uDeviceID
,
2593 LPCWAVEFORMATEX lpFormat
, DWORD_PTR dwCallback
,
2594 DWORD_PTR dwInstance
, DWORD dwFlags
)
2596 return WAVE_Open((HANDLE
*)lphWaveIn
, uDeviceID
, MMDRV_WAVEIN
, lpFormat
,
2597 dwCallback
, dwInstance
, dwFlags
, TRUE
);
2600 /**************************************************************************
2601 * waveInClose [WINMM.@]
2603 UINT WINAPI
waveInClose(HWAVEIN hWaveIn
)
2608 TRACE("(%p)\n", hWaveIn
);
2610 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
)
2611 return MMSYSERR_INVALHANDLE
;
2613 dwRet
= MMDRV_Message(wmld
, WIDM_CLOSE
, 0L, 0L, TRUE
);
2614 if (dwRet
!= WAVERR_STILLPLAYING
)
2615 MMDRV_Free(hWaveIn
, wmld
);
2619 /**************************************************************************
2620 * waveInPrepareHeader [WINMM.@]
2622 UINT WINAPI
waveInPrepareHeader(HWAVEIN hWaveIn
, WAVEHDR
* lpWaveInHdr
,
2628 TRACE("(%p, %p, %u);\n", hWaveIn
, lpWaveInHdr
, uSize
);
2630 if (lpWaveInHdr
== NULL
|| uSize
< sizeof (WAVEHDR
))
2631 return MMSYSERR_INVALPARAM
;
2633 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
)
2634 return MMSYSERR_INVALHANDLE
;
2636 if ((result
= MMDRV_Message(wmld
, WIDM_PREPARE
, (DWORD_PTR
)lpWaveInHdr
,
2637 uSize
, TRUE
)) != MMSYSERR_NOTSUPPORTED
)
2640 if (lpWaveInHdr
->dwFlags
& WHDR_INQUEUE
)
2641 return WAVERR_STILLPLAYING
;
2643 lpWaveInHdr
->dwFlags
|= WHDR_PREPARED
;
2644 lpWaveInHdr
->dwFlags
&= ~WHDR_DONE
;
2645 lpWaveInHdr
->dwBytesRecorded
= 0;
2647 return MMSYSERR_NOERROR
;
2650 /**************************************************************************
2651 * waveInUnprepareHeader [WINMM.@]
2653 UINT WINAPI
waveInUnprepareHeader(HWAVEIN hWaveIn
, WAVEHDR
* lpWaveInHdr
,
2659 TRACE("(%p, %p, %u);\n", hWaveIn
, lpWaveInHdr
, uSize
);
2661 if (lpWaveInHdr
== NULL
|| uSize
< sizeof (WAVEHDR
))
2662 return MMSYSERR_INVALPARAM
;
2664 if (!(lpWaveInHdr
->dwFlags
& WHDR_PREPARED
))
2665 return MMSYSERR_NOERROR
;
2667 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
)
2668 return MMSYSERR_INVALHANDLE
;
2670 if ((result
= MMDRV_Message(wmld
, WIDM_UNPREPARE
, (DWORD_PTR
)lpWaveInHdr
,
2671 uSize
, TRUE
)) != MMSYSERR_NOTSUPPORTED
)
2674 if (lpWaveInHdr
->dwFlags
& WHDR_INQUEUE
)
2675 return WAVERR_STILLPLAYING
;
2677 lpWaveInHdr
->dwFlags
&= ~WHDR_PREPARED
;
2678 lpWaveInHdr
->dwFlags
|= WHDR_DONE
;
2680 return MMSYSERR_NOERROR
;
2683 /**************************************************************************
2684 * waveInAddBuffer [WINMM.@]
2686 UINT WINAPI
waveInAddBuffer(HWAVEIN hWaveIn
,
2687 WAVEHDR
* lpWaveInHdr
, UINT uSize
)
2691 TRACE("(%p, %p, %u);\n", hWaveIn
, lpWaveInHdr
, uSize
);
2693 if (lpWaveInHdr
== NULL
) return MMSYSERR_INVALPARAM
;
2694 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
)
2695 return MMSYSERR_INVALHANDLE
;
2697 return MMDRV_Message(wmld
, WIDM_ADDBUFFER
, (DWORD_PTR
)lpWaveInHdr
, uSize
, TRUE
);
2700 /**************************************************************************
2701 * waveInReset [WINMM.@]
2703 UINT WINAPI
waveInReset(HWAVEIN hWaveIn
)
2707 TRACE("(%p);\n", hWaveIn
);
2709 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
)
2710 return MMSYSERR_INVALHANDLE
;
2712 return MMDRV_Message(wmld
, WIDM_RESET
, 0L, 0L, TRUE
);
2715 /**************************************************************************
2716 * waveInStart [WINMM.@]
2718 UINT WINAPI
waveInStart(HWAVEIN hWaveIn
)
2722 TRACE("(%p);\n", hWaveIn
);
2724 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
)
2725 return MMSYSERR_INVALHANDLE
;
2727 return MMDRV_Message(wmld
, WIDM_START
, 0L, 0L, TRUE
);
2730 /**************************************************************************
2731 * waveInStop [WINMM.@]
2733 UINT WINAPI
waveInStop(HWAVEIN hWaveIn
)
2737 TRACE("(%p);\n", hWaveIn
);
2739 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
)
2740 return MMSYSERR_INVALHANDLE
;
2742 return MMDRV_Message(wmld
,WIDM_STOP
, 0L, 0L, TRUE
);
2745 /**************************************************************************
2746 * waveInGetPosition [WINMM.@]
2748 UINT WINAPI
waveInGetPosition(HWAVEIN hWaveIn
, LPMMTIME lpTime
,
2753 TRACE("(%p, %p, %u);\n", hWaveIn
, lpTime
, uSize
);
2755 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
)
2756 return MMSYSERR_INVALHANDLE
;
2758 return MMDRV_Message(wmld
, WIDM_GETPOS
, (DWORD_PTR
)lpTime
, uSize
, TRUE
);
2761 /**************************************************************************
2762 * waveInGetID [WINMM.@]
2764 UINT WINAPI
waveInGetID(HWAVEIN hWaveIn
, UINT
* lpuDeviceID
)
2768 TRACE("(%p, %p);\n", hWaveIn
, lpuDeviceID
);
2770 if (lpuDeviceID
== NULL
) return MMSYSERR_INVALHANDLE
;
2772 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
)
2773 return MMSYSERR_INVALHANDLE
;
2775 *lpuDeviceID
= wmld
->uDeviceID
;
2776 return MMSYSERR_NOERROR
;
2779 /**************************************************************************
2780 * waveInMessage [WINMM.@]
2782 UINT WINAPI
waveInMessage(HWAVEIN hWaveIn
, UINT uMessage
,
2783 DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
2787 TRACE("(%p, %u, %ld, %ld)\n", hWaveIn
, uMessage
, dwParam1
, dwParam2
);
2789 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, FALSE
)) == NULL
) {
2790 if ((wmld
= MMDRV_Get(hWaveIn
, MMDRV_WAVEIN
, TRUE
)) != NULL
) {
2791 return MMDRV_PhysicalFeatures(wmld
, uMessage
, dwParam1
, dwParam2
);
2793 return MMSYSERR_INVALHANDLE
;
2797 if (uMessage
< DRVM_IOCTL
|| (uMessage
>= DRVM_IOCTL_LAST
&& uMessage
< DRVM_MAPPER
))
2798 return MMSYSERR_INVALPARAM
;
2801 return MMDRV_Message(wmld
, uMessage
, dwParam1
, dwParam2
, TRUE
);
2811 static DWORD WINAPI
mmTaskRun(void* pmt
)
2813 struct mm_starter mms
;
2815 memcpy(&mms
, pmt
, sizeof(struct mm_starter
));
2816 HeapFree(GetProcessHeap(), 0, pmt
);
2818 if (mms
.event
) SetEvent(mms
.event
);
2822 /******************************************************************
2823 * mmTaskCreate (WINMM.@)
2825 UINT WINAPI
mmTaskCreate(LPTASKCALLBACK cb
, HANDLE
* ph
, DWORD_PTR client
)
2829 struct mm_starter
*mms
;
2831 mms
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct mm_starter
));
2832 if (mms
== NULL
) return TASKERR_OUTOFMEMORY
;
2835 mms
->client
= client
;
2836 if (ph
) hEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2837 mms
->event
= hEvent
;
2839 hThread
= CreateThread(0, 0, mmTaskRun
, mms
, 0, NULL
);
2841 HeapFree(GetProcessHeap(), 0, mms
);
2842 if (hEvent
) CloseHandle(hEvent
);
2843 return TASKERR_OUTOFMEMORY
;
2845 SetThreadPriority(hThread
, THREAD_PRIORITY_TIME_CRITICAL
);
2846 if (ph
) *ph
= hEvent
;
2847 CloseHandle(hThread
);
2851 /******************************************************************
2852 * mmTaskBlock (WINMM.@)
2854 VOID WINAPI
mmTaskBlock(DWORD tid
)
2860 GetMessageA(&msg
, 0, 0, 0);
2861 if (msg
.hwnd
) DispatchMessageA(&msg
);
2862 } while (msg
.message
!= WM_USER
);
2865 /******************************************************************
2866 * mmTaskSignal (WINMM.@)
2868 BOOL WINAPI
mmTaskSignal(DWORD tid
)
2870 return PostThreadMessageW(tid
, WM_USER
, 0, 0);
2873 /******************************************************************
2874 * mmTaskYield (WINMM.@)
2876 VOID WINAPI
mmTaskYield(VOID
) {}
2878 /******************************************************************
2879 * mmGetCurrentTask (WINMM.@)
2881 DWORD WINAPI
mmGetCurrentTask(VOID
)
2883 return GetCurrentThreadId();