- Pass pointer to debugprint function to the kernel in LoaderBlock->u.I386.CommonDataArea
[reactos.git] / reactos / dll / win32 / winmm / winmm.c
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
2
3 /*
4 * WINMM functions
5 *
6 * Copyright 1993 Martin Ayotte
7 * 1998-2002 Eric Pouech
8 *
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.
13 *
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.
18 *
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
22 */
23
24 /*
25 * Eric POUECH :
26 * 98/9 added Win32 MCI support
27 * 99/4 added midiStream support
28 * 99/9 added support for loadable low level drivers
29 */
30
31 /* TODO
32 * + it seems that some programs check what's installed in
33 * registry against the value returned by drivers. Wine is
34 * currently broken regarding this point.
35 * + check thread-safeness for MMSYSTEM and WINMM entry points
36 * + unicode entry points are badly supported (would require
37 * moving 32 bit drivers as Unicode as they are supposed to be)
38 * + allow joystick and timer external calls as we do for wave,
39 * midi, mixer and aux
40 */
41
42 #include <stdio.h>
43 #include <stdarg.h>
44 #include <string.h>
45
46 #define NONAMELESSUNION
47 #define NONAMELESSSTRUCT
48 #include "windef.h"
49 #include "winbase.h"
50 #include "mmsystem.h"
51 #include "winuser.h"
52 #include "winnls.h"
53 #include "winreg.h"
54 #include "winternl.h"
55 #include "winemm.h"
56
57 #include "wine/debug.h"
58
59 WINE_DEFAULT_DEBUG_CHANNEL(winmm);
60
61 void (WINAPI *pFnReleaseThunkLock)(DWORD*);
62 void (WINAPI *pFnRestoreThunkLock)(DWORD);
63
64 /* ========================================================================
65 * G L O B A L S E T T I N G S
66 * ========================================================================*/
67
68 WINE_MM_IDATA WINMM_IData;
69
70 /**************************************************************************
71 * WINMM_CreateIData [internal]
72 */
73 static BOOL WINMM_CreateIData(HINSTANCE hInstDLL)
74 {
75 memset( &WINMM_IData, 0, sizeof WINMM_IData );
76
77 WINMM_IData.hWinMM32Instance = hInstDLL;
78 InitializeCriticalSection(&WINMM_IData.cs);
79 /* FIXME crashes in ReactOS
80 WINMM_IData.cs.DebugInfo->Spare[1] = (DWORD)"WINMM_IData";
81 */
82 WINMM_IData.psStopEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
83 WINMM_IData.psLastEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
84 TRACE("Initialized IData (%p)\n", &WINMM_IData);
85 return TRUE;
86 }
87
88 /**************************************************************************
89 * WINMM_DeleteIData [internal]
90 */
91 static void WINMM_DeleteIData(void)
92 {
93 TIME_MMTimeStop();
94
95 /* FIXME: should also free content and resources allocated
96 * inside WINMM_IData */
97 CloseHandle(WINMM_IData.psStopEvent);
98 CloseHandle(WINMM_IData.psLastEvent);
99 DeleteCriticalSection(&WINMM_IData.cs);
100 }
101
102 /******************************************************************
103 * WINMM_LoadMMSystem
104 *
105 */
106 #ifndef __REACTOS__
107 static HANDLE (WINAPI *pGetModuleHandle16)(LPCSTR);
108 static DWORD (WINAPI *pLoadLibrary16)(LPCSTR);
109 #endif
110
111 BOOL WINMM_CheckForMMSystem(void)
112 {
113 /* 0 is not checked yet, -1 is not present, 1 is present */
114 static int loaded /* = 0 */;
115
116 if (loaded == 0)
117 {
118 HANDLE h = GetModuleHandleA("kernel32");
119 loaded = -1;
120 if (h)
121 {
122 #ifndef __REACTOS__
123 pGetModuleHandle16 = (void*)GetProcAddress(h, "GetModuleHandle16");
124 pLoadLibrary16 = (void*)GetProcAddress(h, "LoadLibrary16");
125 if (pGetModuleHandle16 && pLoadLibrary16 &&
126 (pGetModuleHandle16("MMSYSTEM.DLL") || pLoadLibrary16("MMSYSTEM.DLL")))
127 #endif /* __REACTOS__ */
128 loaded = 1;
129 }
130 }
131 return loaded > 0;
132 }
133
134 /******************************************************************
135 * WINMM_ErrorToString
136 */
137 const char* WINMM_ErrorToString(MMRESULT error)
138 {
139 #define ERR_TO_STR(dev) case dev: return #dev
140 static char unknown[32];
141 switch (error) {
142 ERR_TO_STR(MMSYSERR_NOERROR);
143 ERR_TO_STR(MMSYSERR_ERROR);
144 ERR_TO_STR(MMSYSERR_BADDEVICEID);
145 ERR_TO_STR(MMSYSERR_NOTENABLED);
146 ERR_TO_STR(MMSYSERR_ALLOCATED);
147 ERR_TO_STR(MMSYSERR_INVALHANDLE);
148 ERR_TO_STR(MMSYSERR_NODRIVER);
149 ERR_TO_STR(MMSYSERR_NOMEM);
150 ERR_TO_STR(MMSYSERR_NOTSUPPORTED);
151 ERR_TO_STR(MMSYSERR_BADERRNUM);
152 ERR_TO_STR(MMSYSERR_INVALFLAG);
153 ERR_TO_STR(MMSYSERR_INVALPARAM);
154 ERR_TO_STR(MMSYSERR_HANDLEBUSY);
155 ERR_TO_STR(MMSYSERR_INVALIDALIAS);
156 ERR_TO_STR(MMSYSERR_BADDB);
157 ERR_TO_STR(MMSYSERR_KEYNOTFOUND);
158 ERR_TO_STR(MMSYSERR_READERROR);
159 ERR_TO_STR(MMSYSERR_WRITEERROR);
160 ERR_TO_STR(MMSYSERR_DELETEERROR);
161 ERR_TO_STR(MMSYSERR_VALNOTFOUND);
162 ERR_TO_STR(MMSYSERR_NODRIVERCB);
163 ERR_TO_STR(WAVERR_BADFORMAT);
164 ERR_TO_STR(WAVERR_STILLPLAYING);
165 ERR_TO_STR(WAVERR_UNPREPARED);
166 ERR_TO_STR(WAVERR_SYNC);
167 }
168 sprintf(unknown, "Unknown(0x%08x)", error);
169 return unknown;
170 #undef ERR_TO_STR
171 }
172
173 /**************************************************************************
174 * DllMain (WINMM.init)
175 *
176 * WINMM DLL entry point
177 *
178 */
179 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID fImpLoad)
180 {
181 TRACE("%p 0x%lx %p\n", hInstDLL, fdwReason, fImpLoad);
182
183 switch (fdwReason) {
184 case DLL_PROCESS_ATTACH:
185 DisableThreadLibraryCalls(hInstDLL);
186
187 if (!WINMM_CreateIData(hInstDLL))
188 return FALSE;
189 if (!MMDRV_Init()) {
190 WINMM_DeleteIData();
191 return FALSE;
192 }
193 break;
194 case DLL_PROCESS_DETACH:
195 /* close all opened MCI drivers */
196 MCI_SendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_WAIT, 0L, TRUE);
197 MMDRV_Exit();
198 /* now unload all remaining drivers... */
199 DRIVER_UnloadAll();
200
201 WINMM_DeleteIData();
202 break;
203 }
204 return TRUE;
205 }
206
207 /**************************************************************************
208 * Mixer devices. New to Win95
209 */
210
211 /**************************************************************************
212 * find out the real mixer ID depending on hmix (depends on dwFlags)
213 */
214 static UINT MIXER_GetDev(HMIXEROBJ hmix, DWORD dwFlags, LPWINE_MIXER * lplpwm)
215 {
216 LPWINE_MIXER lpwm = NULL;
217 UINT uRet = MMSYSERR_NOERROR;
218
219 switch (dwFlags & 0xF0000000ul) {
220 case MIXER_OBJECTF_MIXER:
221 lpwm = (LPWINE_MIXER)MMDRV_Get(hmix, MMDRV_MIXER, TRUE);
222 break;
223 case MIXER_OBJECTF_HMIXER:
224 lpwm = (LPWINE_MIXER)MMDRV_Get(hmix, MMDRV_MIXER, FALSE);
225 break;
226 case MIXER_OBJECTF_WAVEOUT:
227 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEOUT, TRUE, MMDRV_MIXER);
228 break;
229 case MIXER_OBJECTF_HWAVEOUT:
230 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEOUT, FALSE, MMDRV_MIXER);
231 break;
232 case MIXER_OBJECTF_WAVEIN:
233 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEIN, TRUE, MMDRV_MIXER);
234 break;
235 case MIXER_OBJECTF_HWAVEIN:
236 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEIN, FALSE, MMDRV_MIXER);
237 break;
238 case MIXER_OBJECTF_MIDIOUT:
239 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIOUT, TRUE, MMDRV_MIXER);
240 break;
241 case MIXER_OBJECTF_HMIDIOUT:
242 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIOUT, FALSE, MMDRV_MIXER);
243 break;
244 case MIXER_OBJECTF_MIDIIN:
245 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIIN, TRUE, MMDRV_MIXER);
246 break;
247 case MIXER_OBJECTF_HMIDIIN:
248 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIIN, FALSE, MMDRV_MIXER);
249 break;
250 case MIXER_OBJECTF_AUX:
251 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_AUX, TRUE, MMDRV_MIXER);
252 break;
253 default:
254 WARN("Unsupported flag (%08lx)\n", dwFlags & 0xF0000000ul);
255 lpwm = 0;
256 uRet = MMSYSERR_INVALFLAG;
257 break;
258 }
259 *lplpwm = lpwm;
260 if (lpwm == 0 && uRet == MMSYSERR_NOERROR)
261 uRet = MMSYSERR_INVALPARAM;
262 return uRet;
263 }
264
265 /**************************************************************************
266 * mixerGetNumDevs [WINMM.@]
267 */
268 UINT WINAPI mixerGetNumDevs(void)
269 {
270 return MMDRV_GetNum(MMDRV_MIXER);
271 }
272
273 /**************************************************************************
274 * mixerGetDevCapsA [WINMM.@]
275 */
276 UINT WINAPI mixerGetDevCapsA(UINT_PTR uDeviceID, LPMIXERCAPSA lpCaps, UINT uSize)
277 {
278 MIXERCAPSW micW;
279 UINT ret;
280
281 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
282
283 ret = mixerGetDevCapsW(uDeviceID, &micW, sizeof(micW));
284
285 if (ret == MMSYSERR_NOERROR) {
286 MIXERCAPSA micA;
287 micA.wMid = micW.wMid;
288 micA.wPid = micW.wPid;
289 micA.vDriverVersion = micW.vDriverVersion;
290 WideCharToMultiByte( CP_ACP, 0, micW.szPname, -1, micA.szPname,
291 sizeof(micA.szPname), NULL, NULL );
292 micA.fdwSupport = micW.fdwSupport;
293 micA.cDestinations = micW.cDestinations;
294 memcpy(lpCaps, &micA, min(uSize, sizeof(micA)));
295 }
296 return ret;
297 }
298
299 /**************************************************************************
300 * mixerGetDevCapsW [WINMM.@]
301 */
302 UINT WINAPI mixerGetDevCapsW(UINT_PTR uDeviceID, LPMIXERCAPSW lpCaps, UINT uSize)
303 {
304 LPWINE_MLD wmld;
305
306 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
307
308 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_MIXER, TRUE)) == NULL)
309 return MMSYSERR_BADDEVICEID;
310
311 return MMDRV_Message(wmld, MXDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
312 }
313
314 UINT MIXER_Open(LPHMIXER lphMix, UINT uDeviceID, DWORD_PTR dwCallback,
315 DWORD_PTR dwInstance, DWORD fdwOpen, BOOL bFrom32)
316 {
317 HANDLE hMix;
318 LPWINE_MLD wmld;
319 DWORD dwRet = 0;
320 MIXEROPENDESC mod;
321
322 TRACE("(%p, %d, %08lx, %08lx, %08lx)\n",
323 lphMix, uDeviceID, dwCallback, dwInstance, fdwOpen);
324
325 wmld = MMDRV_Alloc(sizeof(WINE_MIXER), MMDRV_MIXER, &hMix, &fdwOpen,
326 &dwCallback, &dwInstance, bFrom32);
327
328 wmld->uDeviceID = uDeviceID;
329 mod.hmx = (HMIXEROBJ)hMix;
330 mod.dwCallback = dwCallback;
331 mod.dwInstance = dwInstance;
332
333 dwRet = MMDRV_Open(wmld, MXDM_OPEN, (DWORD)&mod, fdwOpen);
334
335 if (dwRet != MMSYSERR_NOERROR) {
336 MMDRV_Free(hMix, wmld);
337 hMix = 0;
338 }
339 if (lphMix) *lphMix = hMix;
340 TRACE("=> %ld hMixer=%p\n", dwRet, hMix);
341
342 return dwRet;
343 }
344
345 /**************************************************************************
346 * mixerOpen [WINMM.@]
347 */
348 MMRESULT WINAPI mixerOpen(LPHMIXER lphMix, UINT uDeviceID, DWORD_PTR dwCallback,
349 DWORD_PTR dwInstance, DWORD fdwOpen)
350 {
351 return MIXER_Open(lphMix, uDeviceID, dwCallback, dwInstance, fdwOpen, TRUE);
352 }
353
354 /**************************************************************************
355 * mixerClose [WINMM.@]
356 */
357 UINT WINAPI mixerClose(HMIXER hMix)
358 {
359 LPWINE_MLD wmld;
360 DWORD dwRet;
361
362 TRACE("(%p)\n", hMix);
363
364 if ((wmld = MMDRV_Get(hMix, MMDRV_MIXER, FALSE)) == NULL) return MMSYSERR_INVALHANDLE;
365
366 dwRet = MMDRV_Close(wmld, MXDM_CLOSE);
367 MMDRV_Free(hMix, wmld);
368
369 return dwRet;
370 }
371
372 /**************************************************************************
373 * mixerGetID [WINMM.@]
374 */
375 UINT WINAPI mixerGetID(HMIXEROBJ hmix, LPUINT lpid, DWORD fdwID)
376 {
377 LPWINE_MIXER lpwm;
378 UINT uRet = MMSYSERR_NOERROR;
379
380 TRACE("(%p %p %08lx)\n", hmix, lpid, fdwID);
381
382 if ((uRet = MIXER_GetDev(hmix, fdwID, &lpwm)) != MMSYSERR_NOERROR)
383 return uRet;
384
385 if (lpid)
386 *lpid = lpwm->mld.uDeviceID;
387
388 return uRet;
389 }
390
391 /**************************************************************************
392 * mixerGetControlDetailsW [WINMM.@]
393 */
394 UINT WINAPI mixerGetControlDetailsW(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcdW,
395 DWORD fdwDetails)
396 {
397 LPWINE_MIXER lpwm;
398 UINT uRet = MMSYSERR_NOERROR;
399
400 TRACE("(%p, %p, %08lx)\n", hmix, lpmcdW, fdwDetails);
401
402 if ((uRet = MIXER_GetDev(hmix, fdwDetails, &lpwm)) != MMSYSERR_NOERROR)
403 return uRet;
404
405 if (lpmcdW == NULL || lpmcdW->cbStruct != sizeof(*lpmcdW))
406 return MMSYSERR_INVALPARAM;
407
408 return MMDRV_Message(&lpwm->mld, MXDM_GETCONTROLDETAILS, (DWORD_PTR)lpmcdW,
409 fdwDetails, TRUE);
410 }
411
412 /**************************************************************************
413 * mixerGetControlDetailsA [WINMM.@]
414 */
415 UINT WINAPI mixerGetControlDetailsA(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcdA,
416 DWORD fdwDetails)
417 {
418 DWORD ret = MMSYSERR_NOTENABLED;
419
420 TRACE("(%p, %p, %08lx)\n", hmix, lpmcdA, fdwDetails);
421
422 if (lpmcdA == NULL || lpmcdA->cbStruct != sizeof(*lpmcdA))
423 return MMSYSERR_INVALPARAM;
424
425 switch (fdwDetails & MIXER_GETCONTROLDETAILSF_QUERYMASK) {
426 case MIXER_GETCONTROLDETAILSF_VALUE:
427 /* can savely use A structure as it is, no string inside */
428 ret = mixerGetControlDetailsW(hmix, lpmcdA, fdwDetails);
429 break;
430 case MIXER_GETCONTROLDETAILSF_LISTTEXT:
431 {
432 MIXERCONTROLDETAILS_LISTTEXTA *pDetailsA = (MIXERCONTROLDETAILS_LISTTEXTA *)lpmcdA->paDetails;
433 MIXERCONTROLDETAILS_LISTTEXTW *pDetailsW;
434 int size = max(1, lpmcdA->cChannels) * sizeof(MIXERCONTROLDETAILS_LISTTEXTW);
435 unsigned int i;
436
437 if (lpmcdA->u.cMultipleItems != 0) {
438 size *= lpmcdA->u.cMultipleItems;
439 }
440 pDetailsW = HeapAlloc(GetProcessHeap(), 0, size);
441 lpmcdA->paDetails = pDetailsW;
442 lpmcdA->cbDetails = sizeof(MIXERCONTROLDETAILS_LISTTEXTW);
443 /* set up lpmcd->paDetails */
444 ret = mixerGetControlDetailsW(hmix, lpmcdA, fdwDetails);
445 /* copy from lpmcd->paDetails back to paDetailsW; */
446 if (ret == MMSYSERR_NOERROR) {
447 for (i = 0; i < lpmcdA->u.cMultipleItems * lpmcdA->cChannels; i++) {
448 pDetailsA->dwParam1 = pDetailsW->dwParam1;
449 pDetailsA->dwParam2 = pDetailsW->dwParam2;
450 WideCharToMultiByte( CP_ACP, 0, pDetailsW->szName, -1,
451 pDetailsA->szName,
452 sizeof(pDetailsA->szName), NULL, NULL );
453 pDetailsA++;
454 pDetailsW++;
455 }
456 pDetailsA -= lpmcdA->u.cMultipleItems * lpmcdA->cChannels;
457 pDetailsW -= lpmcdA->u.cMultipleItems * lpmcdA->cChannels;
458 }
459 HeapFree(GetProcessHeap(), 0, pDetailsW);
460 lpmcdA->paDetails = pDetailsA;
461 lpmcdA->cbDetails = sizeof(MIXERCONTROLDETAILS_LISTTEXTA);
462 }
463 break;
464 default:
465 ERR("Unsupported fdwDetails=0x%08lx\n", fdwDetails);
466 }
467
468 return ret;
469 }
470
471 /**************************************************************************
472 * mixerGetLineControlsA [WINMM.@]
473 */
474 UINT WINAPI mixerGetLineControlsA(HMIXEROBJ hmix, LPMIXERLINECONTROLSA lpmlcA,
475 DWORD fdwControls)
476 {
477 MIXERLINECONTROLSW mlcW;
478 DWORD ret;
479 unsigned int i;
480
481 TRACE("(%p, %p, %08lx)\n", hmix, lpmlcA, fdwControls);
482
483 if (lpmlcA == NULL || lpmlcA->cbStruct != sizeof(*lpmlcA) ||
484 lpmlcA->cbmxctrl != sizeof(MIXERCONTROLA))
485 return MMSYSERR_INVALPARAM;
486
487 mlcW.cbStruct = sizeof(mlcW);
488 mlcW.dwLineID = lpmlcA->dwLineID;
489 mlcW.u.dwControlID = lpmlcA->u.dwControlID;
490 mlcW.u.dwControlType = lpmlcA->u.dwControlType;
491
492 /* Debugging on Windows shows for MIXER_GETLINECONTROLSF_ONEBYTYPE only,
493 the control count is assumed to be 1 - This is relied upon by a game,
494 "Dynomite Deluze" */
495 if (MIXER_GETLINECONTROLSF_ONEBYTYPE == fdwControls) {
496 mlcW.cControls = 1;
497 } else {
498 mlcW.cControls = lpmlcA->cControls;
499 }
500 mlcW.cbmxctrl = sizeof(MIXERCONTROLW);
501 mlcW.pamxctrl = HeapAlloc(GetProcessHeap(), 0,
502 mlcW.cControls * mlcW.cbmxctrl);
503
504 ret = mixerGetLineControlsW(hmix, &mlcW, fdwControls);
505
506 if (ret == MMSYSERR_NOERROR) {
507 lpmlcA->dwLineID = mlcW.dwLineID;
508 lpmlcA->u.dwControlID = mlcW.u.dwControlID;
509 lpmlcA->u.dwControlType = mlcW.u.dwControlType;
510 lpmlcA->cControls = mlcW.cControls;
511
512 for (i = 0; i < mlcW.cControls; i++) {
513 lpmlcA->pamxctrl[i].cbStruct = sizeof(MIXERCONTROLA);
514 lpmlcA->pamxctrl[i].dwControlID = mlcW.pamxctrl[i].dwControlID;
515 lpmlcA->pamxctrl[i].dwControlType = mlcW.pamxctrl[i].dwControlType;
516 lpmlcA->pamxctrl[i].fdwControl = mlcW.pamxctrl[i].fdwControl;
517 lpmlcA->pamxctrl[i].cMultipleItems = mlcW.pamxctrl[i].cMultipleItems;
518 WideCharToMultiByte( CP_ACP, 0, mlcW.pamxctrl[i].szShortName, -1,
519 lpmlcA->pamxctrl[i].szShortName,
520 sizeof(lpmlcA->pamxctrl[i].szShortName), NULL, NULL );
521 WideCharToMultiByte( CP_ACP, 0, mlcW.pamxctrl[i].szName, -1,
522 lpmlcA->pamxctrl[i].szName,
523 sizeof(lpmlcA->pamxctrl[i].szName), NULL, NULL );
524 /* sizeof(lpmlcA->pamxctrl[i].Bounds) ==
525 * sizeof(mlcW.pamxctrl[i].Bounds) */
526 memcpy(&lpmlcA->pamxctrl[i].Bounds, &mlcW.pamxctrl[i].Bounds,
527 sizeof(mlcW.pamxctrl[i].Bounds));
528 /* sizeof(lpmlcA->pamxctrl[i].Metrics) ==
529 * sizeof(mlcW.pamxctrl[i].Metrics) */
530 memcpy(&lpmlcA->pamxctrl[i].Metrics, &mlcW.pamxctrl[i].Metrics,
531 sizeof(mlcW.pamxctrl[i].Metrics));
532 }
533 }
534
535 HeapFree(GetProcessHeap(), 0, mlcW.pamxctrl);
536
537 return ret;
538 }
539
540 /**************************************************************************
541 * mixerGetLineControlsW [WINMM.@]
542 */
543 UINT WINAPI mixerGetLineControlsW(HMIXEROBJ hmix, LPMIXERLINECONTROLSW lpmlcW,
544 DWORD fdwControls)
545 {
546 LPWINE_MIXER lpwm;
547 UINT uRet = MMSYSERR_NOERROR;
548
549 TRACE("(%p, %p, %08lx)\n", hmix, lpmlcW, fdwControls);
550
551 if ((uRet = MIXER_GetDev(hmix, fdwControls, &lpwm)) != MMSYSERR_NOERROR)
552 return uRet;
553
554 if (lpmlcW == NULL || lpmlcW->cbStruct != sizeof(*lpmlcW))
555 return MMSYSERR_INVALPARAM;
556
557 return MMDRV_Message(&lpwm->mld, MXDM_GETLINECONTROLS, (DWORD_PTR)lpmlcW,
558 fdwControls, TRUE);
559 }
560
561 /**************************************************************************
562 * mixerGetLineInfoW [WINMM.@]
563 */
564 UINT WINAPI mixerGetLineInfoW(HMIXEROBJ hmix, LPMIXERLINEW lpmliW, DWORD fdwInfo)
565 {
566 LPWINE_MIXER lpwm;
567 UINT uRet = MMSYSERR_NOERROR;
568
569 TRACE("(%p, %p, %08lx)\n", hmix, lpmliW, fdwInfo);
570
571 if ((uRet = MIXER_GetDev(hmix, fdwInfo, &lpwm)) != MMSYSERR_NOERROR)
572 return uRet;
573
574 return MMDRV_Message(&lpwm->mld, MXDM_GETLINEINFO, (DWORD_PTR)lpmliW,
575 fdwInfo, TRUE);
576 }
577
578 /**************************************************************************
579 * mixerGetLineInfoA [WINMM.@]
580 */
581 UINT WINAPI mixerGetLineInfoA(HMIXEROBJ hmix, LPMIXERLINEA lpmliA,
582 DWORD fdwInfo)
583 {
584 MIXERLINEW mliW;
585 UINT ret;
586
587 TRACE("(%p, %p, %08lx)\n", hmix, lpmliA, fdwInfo);
588
589 if (lpmliA == NULL || lpmliA->cbStruct != sizeof(*lpmliA))
590 return MMSYSERR_INVALPARAM;
591
592 mliW.cbStruct = sizeof(mliW);
593 switch (fdwInfo & MIXER_GETLINEINFOF_QUERYMASK) {
594 case MIXER_GETLINEINFOF_COMPONENTTYPE:
595 mliW.dwComponentType = lpmliA->dwComponentType;
596 break;
597 case MIXER_GETLINEINFOF_DESTINATION:
598 mliW.dwDestination = lpmliA->dwDestination;
599 break;
600 case MIXER_GETLINEINFOF_LINEID:
601 mliW.dwLineID = lpmliA->dwLineID;
602 break;
603 case MIXER_GETLINEINFOF_SOURCE:
604 mliW.dwDestination = lpmliA->dwDestination;
605 mliW.dwSource = lpmliA->dwSource;
606 break;
607 case MIXER_GETLINEINFOF_TARGETTYPE:
608 mliW.Target.dwType = lpmliA->Target.dwType;
609 mliW.Target.wMid = lpmliA->Target.wMid;
610 mliW.Target.wPid = lpmliA->Target.wPid;
611 mliW.Target.vDriverVersion = lpmliA->Target.vDriverVersion;
612 MultiByteToWideChar( CP_ACP, 0, lpmliA->Target.szPname, -1, mliW.Target.szPname, sizeof(mliW.Target.szPname));
613 break;
614 default:
615 WARN("Unsupported fdwControls=0x%08lx\n", fdwInfo);
616 return MMSYSERR_INVALFLAG;
617 }
618
619 ret = mixerGetLineInfoW(hmix, &mliW, fdwInfo);
620
621 lpmliA->dwDestination = mliW.dwDestination;
622 lpmliA->dwSource = mliW.dwSource;
623 lpmliA->dwLineID = mliW.dwLineID;
624 lpmliA->fdwLine = mliW.fdwLine;
625 lpmliA->dwUser = mliW.dwUser;
626 lpmliA->dwComponentType = mliW.dwComponentType;
627 lpmliA->cChannels = mliW.cChannels;
628 lpmliA->cConnections = mliW.cConnections;
629 lpmliA->cControls = mliW.cControls;
630 WideCharToMultiByte( CP_ACP, 0, mliW.szShortName, -1, lpmliA->szShortName,
631 sizeof(lpmliA->szShortName), NULL, NULL);
632 WideCharToMultiByte( CP_ACP, 0, mliW.szName, -1, lpmliA->szName,
633 sizeof(lpmliA->szName), NULL, NULL );
634 lpmliA->Target.dwType = mliW.Target.dwType;
635 lpmliA->Target.dwDeviceID = mliW.Target.dwDeviceID;
636 lpmliA->Target.wMid = mliW.Target.wMid;
637 lpmliA->Target.wPid = mliW.Target.wPid;
638 lpmliA->Target.vDriverVersion = mliW.Target.vDriverVersion;
639 WideCharToMultiByte( CP_ACP, 0, mliW.Target.szPname, -1, lpmliA->Target.szPname,
640 sizeof(lpmliA->Target.szPname), NULL, NULL );
641
642 return ret;
643 }
644
645 /**************************************************************************
646 * mixerSetControlDetails [WINMM.@]
647 */
648 UINT WINAPI mixerSetControlDetails(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcd,
649 DWORD fdwDetails)
650 {
651 LPWINE_MIXER lpwm;
652 UINT uRet = MMSYSERR_NOERROR;
653
654 TRACE("(%p, %p, %08lx)\n", hmix, lpmcd, fdwDetails);
655
656 if ((uRet = MIXER_GetDev(hmix, fdwDetails, &lpwm)) != MMSYSERR_NOERROR)
657 return uRet;
658
659 return MMDRV_Message(&lpwm->mld, MXDM_SETCONTROLDETAILS, (DWORD_PTR)lpmcd,
660 fdwDetails, TRUE);
661 }
662
663 /**************************************************************************
664 * mixerMessage [WINMM.@]
665 */
666 DWORD WINAPI mixerMessage(HMIXER hmix, UINT uMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
667 {
668 LPWINE_MLD wmld;
669
670 TRACE("(%04lx, %d, %08lx, %08lx): semi-stub?\n",
671 (DWORD)hmix, uMsg, dwParam1, dwParam2);
672
673 if ((wmld = MMDRV_Get(hmix, MMDRV_MIXER, FALSE)) == NULL)
674 return MMSYSERR_INVALHANDLE;
675
676 return MMDRV_Message(wmld, uMsg, dwParam1, dwParam2, TRUE);
677 }
678
679 /**************************************************************************
680 * auxGetNumDevs [WINMM.@]
681 */
682 UINT WINAPI auxGetNumDevs(void)
683 {
684 return MMDRV_GetNum(MMDRV_AUX);
685 }
686
687 /**************************************************************************
688 * auxGetDevCapsW [WINMM.@]
689 */
690 MMRESULT WINAPI auxGetDevCapsW(UINT_PTR uDeviceID, LPAUXCAPSW lpCaps, UINT uSize)
691 {
692 LPWINE_MLD wmld;
693
694 TRACE("(%04X, %p, %d) !\n", uDeviceID, lpCaps, uSize);
695
696 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
697
698 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
699 return MMSYSERR_INVALHANDLE;
700 return MMDRV_Message(wmld, AUXDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
701 }
702
703 /**************************************************************************
704 * auxGetDevCapsA [WINMM.@]
705 */
706 MMRESULT WINAPI auxGetDevCapsA(UINT_PTR uDeviceID, LPAUXCAPSA lpCaps, UINT uSize)
707 {
708 AUXCAPSW acW;
709 UINT ret;
710
711 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
712
713 ret = auxGetDevCapsW(uDeviceID, &acW, sizeof(acW));
714
715 if (ret == MMSYSERR_NOERROR) {
716 AUXCAPSA acA;
717 acA.wMid = acW.wMid;
718 acA.wPid = acW.wPid;
719 acA.vDriverVersion = acW.vDriverVersion;
720 WideCharToMultiByte( CP_ACP, 0, acW.szPname, -1, acA.szPname,
721 sizeof(acA.szPname), NULL, NULL );
722 acA.wTechnology = acW.wTechnology;
723 acA.dwSupport = acW.dwSupport;
724 memcpy(lpCaps, &acA, min(uSize, sizeof(acA)));
725 }
726 return ret;
727 }
728
729 /**************************************************************************
730 * auxGetVolume [WINMM.@]
731 */
732 MMRESULT WINAPI auxGetVolume(UINT uDeviceID, DWORD* lpdwVolume)
733 {
734 LPWINE_MLD wmld;
735
736 TRACE("(%04X, %p) !\n", uDeviceID, lpdwVolume);
737
738 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
739 return MMSYSERR_INVALHANDLE;
740 return MMDRV_Message(wmld, AUXDM_GETVOLUME, (DWORD_PTR)lpdwVolume, 0L, TRUE);
741 }
742
743 /**************************************************************************
744 * auxSetVolume [WINMM.@]
745 */
746 UINT WINAPI auxSetVolume(UINT uDeviceID, DWORD dwVolume)
747 {
748 LPWINE_MLD wmld;
749
750 TRACE("(%04X, %lu) !\n", uDeviceID, dwVolume);
751
752 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
753 return MMSYSERR_INVALHANDLE;
754 return MMDRV_Message(wmld, AUXDM_SETVOLUME, dwVolume, 0L, TRUE);
755 }
756
757 /**************************************************************************
758 * auxOutMessage [WINMM.@]
759 */
760 MMRESULT WINAPI auxOutMessage(UINT uDeviceID, UINT uMessage, DWORD_PTR dw1, DWORD_PTR dw2)
761 {
762 LPWINE_MLD wmld;
763
764 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
765 return MMSYSERR_INVALHANDLE;
766
767 return MMDRV_Message(wmld, uMessage, dw1, dw2, TRUE);
768 }
769
770 /**************************************************************************
771 * midiOutGetNumDevs [WINMM.@]
772 */
773 UINT WINAPI midiOutGetNumDevs(void)
774 {
775 return MMDRV_GetNum(MMDRV_MIDIOUT);
776 }
777
778 /**************************************************************************
779 * midiOutGetDevCapsW [WINMM.@]
780 */
781 UINT WINAPI midiOutGetDevCapsW(UINT_PTR uDeviceID, LPMIDIOUTCAPSW lpCaps,
782 UINT uSize)
783 {
784 LPWINE_MLD wmld;
785
786 TRACE("(%u, %p, %u);\n", uDeviceID, lpCaps, uSize);
787
788 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
789
790 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_MIDIOUT, TRUE)) == NULL)
791 return MMSYSERR_INVALHANDLE;
792
793 return MMDRV_Message(wmld, MODM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
794 }
795
796 /**************************************************************************
797 * midiOutGetDevCapsA [WINMM.@]
798 */
799 UINT WINAPI midiOutGetDevCapsA(UINT_PTR uDeviceID, LPMIDIOUTCAPSA lpCaps,
800 UINT uSize)
801 {
802 MIDIOUTCAPSW mocW;
803 UINT ret;
804
805 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
806
807 ret = midiOutGetDevCapsW(uDeviceID, &mocW, sizeof(mocW));
808
809 if (ret == MMSYSERR_NOERROR) {
810 MIDIOUTCAPSA mocA;
811 mocA.wMid = mocW.wMid;
812 mocA.wPid = mocW.wPid;
813 mocA.vDriverVersion = mocW.vDriverVersion;
814 WideCharToMultiByte( CP_ACP, 0, mocW.szPname, -1, mocA.szPname,
815 sizeof(mocA.szPname), NULL, NULL );
816 mocA.wTechnology = mocW.wTechnology;
817 mocA.wVoices = mocW.wVoices;
818 mocA.wNotes = mocW.wNotes;
819 mocA.wChannelMask = mocW.wChannelMask;
820 mocA.dwSupport = mocW.dwSupport;
821 memcpy(lpCaps, &mocA, min(uSize, sizeof(mocA)));
822 }
823 return ret;
824 }
825
826 /**************************************************************************
827 * midiOutGetErrorTextA [WINMM.@]
828 * midiInGetErrorTextA [WINMM.@]
829 */
830 UINT WINAPI midiOutGetErrorTextA(UINT uError, LPSTR lpText, UINT uSize)
831 {
832 UINT ret;
833
834 if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
835 else if (uSize == 0) ret = MMSYSERR_NOERROR;
836 else
837 {
838 LPWSTR xstr = HeapAlloc(GetProcessHeap(), 0, uSize * sizeof(WCHAR));
839 if (!xstr) ret = MMSYSERR_NOMEM;
840 else
841 {
842 ret = midiOutGetErrorTextW(uError, xstr, uSize);
843 if (ret == MMSYSERR_NOERROR)
844 WideCharToMultiByte(CP_ACP, 0, xstr, -1, lpText, uSize, NULL, NULL);
845 HeapFree(GetProcessHeap(), 0, xstr);
846 }
847 }
848 return ret;
849 }
850
851 /**************************************************************************
852 * midiOutGetErrorTextW [WINMM.@]
853 * midiInGetErrorTextW [WINMM.@]
854 */
855 UINT WINAPI midiOutGetErrorTextW(UINT uError, LPWSTR lpText, UINT uSize)
856 {
857 UINT ret = MMSYSERR_BADERRNUM;
858
859 if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
860 else if (uSize == 0) ret = MMSYSERR_NOERROR;
861 else if (
862 /* test has been removed 'coz MMSYSERR_BASE is 0, and gcc did emit
863 * a warning for the test was always true */
864 (/*uError >= MMSYSERR_BASE && */ uError <= MMSYSERR_LASTERROR) ||
865 (uError >= MIDIERR_BASE && uError <= MIDIERR_LASTERROR)) {
866 if (LoadStringW(WINMM_IData.hWinMM32Instance,
867 uError, lpText, uSize) > 0) {
868 ret = MMSYSERR_NOERROR;
869 }
870 }
871 return ret;
872 }
873
874 /**************************************************************************
875 * MIDI_OutAlloc [internal]
876 */
877 static LPWINE_MIDI MIDI_OutAlloc(HMIDIOUT* lphMidiOut, LPDWORD lpdwCallback,
878 LPDWORD lpdwInstance, LPDWORD lpdwFlags,
879 DWORD cIDs, MIDIOPENSTRMID* lpIDs, BOOL bFrom32)
880 {
881 HANDLE hMidiOut;
882 LPWINE_MIDI lpwm;
883 UINT size;
884
885 size = sizeof(WINE_MIDI) + (cIDs ? (cIDs-1) : 0) * sizeof(MIDIOPENSTRMID);
886
887 lpwm = (LPWINE_MIDI)MMDRV_Alloc(size, MMDRV_MIDIOUT, &hMidiOut, lpdwFlags,
888 lpdwCallback, lpdwInstance, bFrom32);
889
890 if (lphMidiOut != NULL)
891 *lphMidiOut = hMidiOut;
892
893 if (lpwm) {
894 lpwm->mod.hMidi = (HMIDI) hMidiOut;
895 lpwm->mod.dwCallback = *lpdwCallback;
896 lpwm->mod.dwInstance = *lpdwInstance;
897 lpwm->mod.dnDevNode = 0;
898 lpwm->mod.cIds = cIDs;
899 if (cIDs)
900 memcpy(&(lpwm->mod.rgIds), lpIDs, cIDs * sizeof(MIDIOPENSTRMID));
901 }
902 return lpwm;
903 }
904
905 UINT MIDI_OutOpen(LPHMIDIOUT lphMidiOut, UINT uDeviceID, DWORD_PTR dwCallback,
906 DWORD_PTR dwInstance, DWORD dwFlags, BOOL bFrom32)
907 {
908 HMIDIOUT hMidiOut;
909 LPWINE_MIDI lpwm;
910 UINT dwRet = 0;
911
912 TRACE("(%p, %d, %08lX, %08lX, %08lX);\n",
913 lphMidiOut, uDeviceID, dwCallback, dwInstance, dwFlags);
914
915 if (lphMidiOut != NULL) *lphMidiOut = 0;
916
917 lpwm = MIDI_OutAlloc(&hMidiOut, &dwCallback, &dwInstance, &dwFlags,
918 0, NULL, bFrom32);
919
920 if (lpwm == NULL)
921 return MMSYSERR_NOMEM;
922
923 lpwm->mld.uDeviceID = uDeviceID;
924
925 dwRet = MMDRV_Open((LPWINE_MLD)lpwm, MODM_OPEN, (DWORD)&lpwm->mod, dwFlags);
926
927 if (dwRet != MMSYSERR_NOERROR) {
928 MMDRV_Free(hMidiOut, (LPWINE_MLD)lpwm);
929 hMidiOut = 0;
930 }
931
932 if (lphMidiOut) *lphMidiOut = hMidiOut;
933 TRACE("=> %d hMidi=%p\n", dwRet, hMidiOut);
934
935 return dwRet;
936 }
937
938 /**************************************************************************
939 * midiOutOpen [WINMM.@]
940 */
941 MMRESULT WINAPI midiOutOpen(LPHMIDIOUT lphMidiOut, UINT_PTR uDeviceID,
942 DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD dwFlags)
943 {
944 return MIDI_OutOpen(lphMidiOut, uDeviceID, dwCallback, dwInstance, dwFlags, TRUE);
945 }
946
947 /**************************************************************************
948 * midiOutClose [WINMM.@]
949 */
950 UINT WINAPI midiOutClose(HMIDIOUT hMidiOut)
951 {
952 LPWINE_MLD wmld;
953 DWORD dwRet;
954
955 TRACE("(%p)\n", hMidiOut);
956
957 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
958 return MMSYSERR_INVALHANDLE;
959
960 dwRet = MMDRV_Close(wmld, MODM_CLOSE);
961 MMDRV_Free(hMidiOut, wmld);
962
963 return dwRet;
964 }
965
966 /**************************************************************************
967 * midiOutPrepareHeader [WINMM.@]
968 */
969 UINT WINAPI midiOutPrepareHeader(HMIDIOUT hMidiOut,
970 MIDIHDR* lpMidiOutHdr, UINT uSize)
971 {
972 LPWINE_MLD wmld;
973
974 TRACE("(%p, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
975
976 if (lpMidiOutHdr == NULL || uSize < sizeof (MIDIHDR))
977 return MMSYSERR_INVALPARAM;
978
979 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
980 return MMSYSERR_INVALHANDLE;
981
982 return MMDRV_Message(wmld, MODM_PREPARE, (DWORD_PTR)lpMidiOutHdr, uSize, TRUE);
983 }
984
985 /**************************************************************************
986 * midiOutUnprepareHeader [WINMM.@]
987 */
988 UINT WINAPI midiOutUnprepareHeader(HMIDIOUT hMidiOut,
989 MIDIHDR* lpMidiOutHdr, UINT uSize)
990 {
991 LPWINE_MLD wmld;
992
993 TRACE("(%p, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
994
995 if (lpMidiOutHdr == NULL || uSize < sizeof (MIDIHDR))
996 return MMSYSERR_INVALPARAM;
997
998 if (!(lpMidiOutHdr->dwFlags & MHDR_PREPARED)) {
999 return MMSYSERR_NOERROR;
1000 }
1001
1002 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1003 return MMSYSERR_INVALHANDLE;
1004
1005 return MMDRV_Message(wmld, MODM_UNPREPARE, (DWORD_PTR)lpMidiOutHdr, uSize, TRUE);
1006 }
1007
1008 /**************************************************************************
1009 * midiOutShortMsg [WINMM.@]
1010 */
1011 UINT WINAPI midiOutShortMsg(HMIDIOUT hMidiOut, DWORD dwMsg)
1012 {
1013 LPWINE_MLD wmld;
1014
1015 TRACE("(%p, %08lX)\n", hMidiOut, dwMsg);
1016
1017 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1018 return MMSYSERR_INVALHANDLE;
1019
1020 return MMDRV_Message(wmld, MODM_DATA, dwMsg, 0L, TRUE);
1021 }
1022
1023 /**************************************************************************
1024 * midiOutLongMsg [WINMM.@]
1025 */
1026 UINT WINAPI midiOutLongMsg(HMIDIOUT hMidiOut,
1027 MIDIHDR* lpMidiOutHdr, UINT uSize)
1028 {
1029 LPWINE_MLD wmld;
1030
1031 TRACE("(%p, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
1032
1033 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1034 return MMSYSERR_INVALHANDLE;
1035
1036 return MMDRV_Message(wmld, MODM_LONGDATA, (DWORD_PTR)lpMidiOutHdr, uSize, TRUE);
1037 }
1038
1039 /**************************************************************************
1040 * midiOutReset [WINMM.@]
1041 */
1042 UINT WINAPI midiOutReset(HMIDIOUT hMidiOut)
1043 {
1044 LPWINE_MLD wmld;
1045
1046 TRACE("(%p)\n", hMidiOut);
1047
1048 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1049 return MMSYSERR_INVALHANDLE;
1050
1051 return MMDRV_Message(wmld, MODM_RESET, 0L, 0L, TRUE);
1052 }
1053
1054 /**************************************************************************
1055 * midiOutGetVolume [WINMM.@]
1056 */
1057 UINT WINAPI midiOutGetVolume(HMIDIOUT hMidiOut, DWORD* lpdwVolume)
1058 {
1059 LPWINE_MLD wmld;
1060
1061 TRACE("(%p, %p);\n", hMidiOut, lpdwVolume);
1062
1063 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, TRUE)) == NULL)
1064 return MMSYSERR_INVALHANDLE;
1065
1066 return MMDRV_Message(wmld, MODM_GETVOLUME, (DWORD_PTR)lpdwVolume, 0L, TRUE);
1067 }
1068
1069 /**************************************************************************
1070 * midiOutSetVolume [WINMM.@]
1071 */
1072 UINT WINAPI midiOutSetVolume(HMIDIOUT hMidiOut, DWORD dwVolume)
1073 {
1074 LPWINE_MLD wmld;
1075
1076 TRACE("(%p, %ld);\n", hMidiOut, dwVolume);
1077
1078 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, TRUE)) == NULL)
1079 return MMSYSERR_INVALHANDLE;
1080
1081 return MMDRV_Message(wmld, MODM_SETVOLUME, dwVolume, 0L, TRUE);
1082 }
1083
1084 /**************************************************************************
1085 * midiOutCachePatches [WINMM.@]
1086 */
1087 UINT WINAPI midiOutCachePatches(HMIDIOUT hMidiOut, UINT uBank,
1088 WORD* lpwPatchArray, UINT uFlags)
1089 {
1090 /* not really necessary to support this */
1091 FIXME("not supported yet\n");
1092 return MMSYSERR_NOTSUPPORTED;
1093 }
1094
1095 /**************************************************************************
1096 * midiOutCacheDrumPatches [WINMM.@]
1097 */
1098 UINT WINAPI midiOutCacheDrumPatches(HMIDIOUT hMidiOut, UINT uPatch,
1099 WORD* lpwKeyArray, UINT uFlags)
1100 {
1101 FIXME("not supported yet\n");
1102 return MMSYSERR_NOTSUPPORTED;
1103 }
1104
1105 /**************************************************************************
1106 * midiOutGetID [WINMM.@]
1107 */
1108 UINT WINAPI midiOutGetID(HMIDIOUT hMidiOut, UINT* lpuDeviceID)
1109 {
1110 LPWINE_MLD wmld;
1111
1112 TRACE("(%p, %p)\n", hMidiOut, lpuDeviceID);
1113
1114 if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
1115 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
1116 return MMSYSERR_INVALHANDLE;
1117
1118 *lpuDeviceID = wmld->uDeviceID;
1119 return MMSYSERR_NOERROR;
1120 }
1121
1122 /**************************************************************************
1123 * midiOutMessage [WINMM.@]
1124 */
1125 DWORD WINAPI midiOutMessage(HMIDIOUT hMidiOut, UINT uMessage,
1126 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1127 {
1128 LPWINE_MLD wmld;
1129
1130 TRACE("(%p, %04X, %08lX, %08lX)\n", hMidiOut, uMessage, dwParam1, dwParam2);
1131
1132 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL) {
1133 /* HACK... */
1134 if (uMessage == 0x0001) {
1135 *(LPDWORD)dwParam1 = 1;
1136 return 0;
1137 }
1138 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, TRUE)) != NULL) {
1139 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
1140 }
1141 return MMSYSERR_INVALHANDLE;
1142 }
1143
1144 switch (uMessage) {
1145 case MODM_OPEN:
1146 case MODM_CLOSE:
1147 FIXME("can't handle OPEN or CLOSE message!\n");
1148 return MMSYSERR_NOTSUPPORTED;
1149 }
1150 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
1151 }
1152
1153 /**************************************************************************
1154 * midiInGetNumDevs [WINMM.@]
1155 */
1156 UINT WINAPI midiInGetNumDevs(void)
1157 {
1158 return MMDRV_GetNum(MMDRV_MIDIIN);
1159 }
1160
1161 /**************************************************************************
1162 * midiInGetDevCapsW [WINMM.@]
1163 */
1164 MMRESULT WINAPI midiInGetDevCapsW(UINT_PTR uDeviceID, LPMIDIINCAPSW lpCaps, UINT uSize)
1165 {
1166 LPWINE_MLD wmld;
1167
1168 TRACE("(%d, %p, %d);\n", uDeviceID, lpCaps, uSize);
1169
1170 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
1171
1172 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_MIDIIN, TRUE)) == NULL)
1173 return MMSYSERR_INVALHANDLE;
1174
1175 return MMDRV_Message(wmld, MIDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
1176 }
1177
1178 /**************************************************************************
1179 * midiInGetDevCapsA [WINMM.@]
1180 */
1181 MMRESULT WINAPI midiInGetDevCapsA(UINT_PTR uDeviceID, LPMIDIINCAPSA lpCaps, UINT uSize)
1182 {
1183 MIDIINCAPSW micW;
1184 UINT ret;
1185
1186 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
1187
1188 ret = midiInGetDevCapsW(uDeviceID, &micW, sizeof(micW));
1189
1190 if (ret == MMSYSERR_NOERROR) {
1191 MIDIINCAPSA micA;
1192 micA.wMid = micW.wMid;
1193 micA.wPid = micW.wPid;
1194 micA.vDriverVersion = micW.vDriverVersion;
1195 WideCharToMultiByte( CP_ACP, 0, micW.szPname, -1, micA.szPname,
1196 sizeof(micA.szPname), NULL, NULL );
1197 micA.dwSupport = micW.dwSupport;
1198 memcpy(lpCaps, &micA, min(uSize, sizeof(micA)));
1199 }
1200 return ret;
1201 }
1202
1203 UINT MIDI_InOpen(HMIDIIN* lphMidiIn, UINT uDeviceID, DWORD_PTR dwCallback,
1204 DWORD_PTR dwInstance, DWORD dwFlags, BOOL bFrom32)
1205 {
1206 HANDLE hMidiIn;
1207 LPWINE_MIDI lpwm;
1208 DWORD dwRet = 0;
1209
1210 TRACE("(%p, %d, %08lX, %08lX, %08lX);\n",
1211 lphMidiIn, uDeviceID, dwCallback, dwInstance, dwFlags);
1212
1213 if (lphMidiIn != NULL) *lphMidiIn = 0;
1214
1215 lpwm = (LPWINE_MIDI)MMDRV_Alloc(sizeof(WINE_MIDI), MMDRV_MIDIIN, &hMidiIn,
1216 &dwFlags, &dwCallback, &dwInstance, bFrom32);
1217
1218 if (lpwm == NULL)
1219 return MMSYSERR_NOMEM;
1220
1221 lpwm->mod.hMidi = (HMIDI) hMidiIn;
1222 lpwm->mod.dwCallback = dwCallback;
1223 lpwm->mod.dwInstance = dwInstance;
1224
1225 lpwm->mld.uDeviceID = uDeviceID;
1226 dwRet = MMDRV_Open(&lpwm->mld, MIDM_OPEN, (DWORD)&lpwm->mod, dwFlags);
1227
1228 if (dwRet != MMSYSERR_NOERROR) {
1229 MMDRV_Free(hMidiIn, &lpwm->mld);
1230 hMidiIn = 0;
1231 }
1232 if (lphMidiIn != NULL) *lphMidiIn = hMidiIn;
1233 TRACE("=> %ld hMidi=%p\n", dwRet, hMidiIn);
1234
1235 return dwRet;
1236 }
1237
1238 /**************************************************************************
1239 * midiInOpen [WINMM.@]
1240 */
1241 MMRESULT WINAPI midiInOpen(HMIDIIN* lphMidiIn, UINT_PTR uDeviceID,
1242 DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD dwFlags)
1243 {
1244 return MIDI_InOpen(lphMidiIn, uDeviceID, dwCallback, dwInstance, dwFlags, TRUE);
1245 }
1246
1247 /**************************************************************************
1248 * midiInClose [WINMM.@]
1249 */
1250 UINT WINAPI midiInClose(HMIDIIN hMidiIn)
1251 {
1252 LPWINE_MLD wmld;
1253 DWORD dwRet;
1254
1255 TRACE("(%p)\n", hMidiIn);
1256
1257 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1258 return MMSYSERR_INVALHANDLE;
1259
1260 dwRet = MMDRV_Close(wmld, MIDM_CLOSE);
1261 MMDRV_Free(hMidiIn, wmld);
1262 return dwRet;
1263 }
1264
1265 /**************************************************************************
1266 * midiInPrepareHeader [WINMM.@]
1267 */
1268 UINT WINAPI midiInPrepareHeader(HMIDIIN hMidiIn,
1269 MIDIHDR* lpMidiInHdr, UINT uSize)
1270 {
1271 LPWINE_MLD wmld;
1272
1273 TRACE("(%p, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
1274
1275 if (lpMidiInHdr == NULL || uSize < sizeof (MIDIHDR))
1276 return MMSYSERR_INVALPARAM;
1277
1278 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1279 return MMSYSERR_INVALHANDLE;
1280
1281 return MMDRV_Message(wmld, MIDM_PREPARE, (DWORD_PTR)lpMidiInHdr, uSize, TRUE);
1282 }
1283
1284 /**************************************************************************
1285 * midiInUnprepareHeader [WINMM.@]
1286 */
1287 UINT WINAPI midiInUnprepareHeader(HMIDIIN hMidiIn,
1288 MIDIHDR* lpMidiInHdr, UINT uSize)
1289 {
1290 LPWINE_MLD wmld;
1291
1292 TRACE("(%p, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
1293
1294 if (lpMidiInHdr == NULL || uSize < sizeof (MIDIHDR))
1295 return MMSYSERR_INVALPARAM;
1296
1297 if (!(lpMidiInHdr->dwFlags & MHDR_PREPARED)) {
1298 return MMSYSERR_NOERROR;
1299 }
1300
1301 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1302 return MMSYSERR_INVALHANDLE;
1303
1304 return MMDRV_Message(wmld, MIDM_UNPREPARE, (DWORD_PTR)lpMidiInHdr, uSize, TRUE);
1305 }
1306
1307 /**************************************************************************
1308 * midiInAddBuffer [WINMM.@]
1309 */
1310 UINT WINAPI midiInAddBuffer(HMIDIIN hMidiIn,
1311 MIDIHDR* lpMidiInHdr, UINT uSize)
1312 {
1313 LPWINE_MLD wmld;
1314
1315 TRACE("(%p, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
1316
1317 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1318 return MMSYSERR_INVALHANDLE;
1319
1320 return MMDRV_Message(wmld, MIDM_ADDBUFFER, (DWORD_PTR)lpMidiInHdr, uSize, TRUE);
1321 }
1322
1323 /**************************************************************************
1324 * midiInStart [WINMM.@]
1325 */
1326 UINT WINAPI midiInStart(HMIDIIN hMidiIn)
1327 {
1328 LPWINE_MLD wmld;
1329
1330 TRACE("(%p)\n", hMidiIn);
1331
1332 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1333 return MMSYSERR_INVALHANDLE;
1334
1335 return MMDRV_Message(wmld, MIDM_START, 0L, 0L, TRUE);
1336 }
1337
1338 /**************************************************************************
1339 * midiInStop [WINMM.@]
1340 */
1341 UINT WINAPI midiInStop(HMIDIIN hMidiIn)
1342 {
1343 LPWINE_MLD wmld;
1344
1345 TRACE("(%p)\n", hMidiIn);
1346
1347 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1348 return MMSYSERR_INVALHANDLE;
1349
1350 return MMDRV_Message(wmld, MIDM_STOP, 0L, 0L, TRUE);
1351 }
1352
1353 /**************************************************************************
1354 * midiInReset [WINMM.@]
1355 */
1356 UINT WINAPI midiInReset(HMIDIIN hMidiIn)
1357 {
1358 LPWINE_MLD wmld;
1359
1360 TRACE("(%p)\n", hMidiIn);
1361
1362 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1363 return MMSYSERR_INVALHANDLE;
1364
1365 return MMDRV_Message(wmld, MIDM_RESET, 0L, 0L, TRUE);
1366 }
1367
1368 /**************************************************************************
1369 * midiInGetID [WINMM.@]
1370 */
1371 UINT WINAPI midiInGetID(HMIDIIN hMidiIn, UINT* lpuDeviceID)
1372 {
1373 LPWINE_MLD wmld;
1374
1375 TRACE("(%p, %p)\n", hMidiIn, lpuDeviceID);
1376
1377 if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
1378
1379 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, TRUE)) == NULL)
1380 return MMSYSERR_INVALHANDLE;
1381
1382 *lpuDeviceID = wmld->uDeviceID;
1383
1384 return MMSYSERR_NOERROR;
1385 }
1386
1387 /**************************************************************************
1388 * midiInMessage [WINMM.@]
1389 */
1390 DWORD WINAPI midiInMessage(HMIDIIN hMidiIn, UINT uMessage,
1391 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1392 {
1393 LPWINE_MLD wmld;
1394
1395 TRACE("(%p, %04X, %08lX, %08lX)\n", hMidiIn, uMessage, dwParam1, dwParam2);
1396
1397 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
1398 return MMSYSERR_INVALHANDLE;
1399
1400 switch (uMessage) {
1401 case MIDM_OPEN:
1402 case MIDM_CLOSE:
1403 FIXME("can't handle OPEN or CLOSE message!\n");
1404 return MMSYSERR_NOTSUPPORTED;
1405 }
1406 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
1407 }
1408
1409 typedef struct WINE_MIDIStream {
1410 HMIDIOUT hDevice;
1411 HANDLE hThread;
1412 DWORD dwThreadID;
1413 DWORD dwTempo;
1414 DWORD dwTimeDiv;
1415 DWORD dwPositionMS;
1416 DWORD dwPulses;
1417 DWORD dwStartTicks;
1418 WORD wFlags;
1419 HANDLE hEvent;
1420 LPMIDIHDR lpMidiHdr;
1421 } WINE_MIDIStream;
1422
1423 #define WINE_MSM_HEADER (WM_USER+0)
1424 #define WINE_MSM_STOP (WM_USER+1)
1425
1426 /**************************************************************************
1427 * MMSYSTEM_GetMidiStream [internal]
1428 */
1429 static BOOL MMSYSTEM_GetMidiStream(HMIDISTRM hMidiStrm, WINE_MIDIStream** lpMidiStrm, WINE_MIDI** lplpwm)
1430 {
1431 WINE_MIDI* lpwm = (LPWINE_MIDI)MMDRV_Get(hMidiStrm, MMDRV_MIDIOUT, FALSE);
1432
1433 if (lplpwm)
1434 *lplpwm = lpwm;
1435
1436 if (lpwm == NULL) {
1437 return FALSE;
1438 }
1439
1440 *lpMidiStrm = (WINE_MIDIStream*)lpwm->mod.rgIds.dwStreamID;
1441
1442 return *lpMidiStrm != NULL;
1443 }
1444
1445 /**************************************************************************
1446 * MMSYSTEM_MidiStream_Convert [internal]
1447 */
1448 static DWORD MMSYSTEM_MidiStream_Convert(WINE_MIDIStream* lpMidiStrm, DWORD pulse)
1449 {
1450 DWORD ret = 0;
1451
1452 if (lpMidiStrm->dwTimeDiv == 0) {
1453 FIXME("Shouldn't happen. lpMidiStrm->dwTimeDiv = 0\n");
1454 } else if (lpMidiStrm->dwTimeDiv > 0x8000) { /* SMPTE, unchecked FIXME? */
1455 int nf = -(char)HIBYTE(lpMidiStrm->dwTimeDiv); /* number of frames */
1456 int nsf = LOBYTE(lpMidiStrm->dwTimeDiv); /* number of sub-frames */
1457 ret = (pulse * 1000) / (nf * nsf);
1458 } else {
1459 ret = (DWORD)((double)pulse * ((double)lpMidiStrm->dwTempo / 1000) /
1460 (double)lpMidiStrm->dwTimeDiv);
1461 }
1462
1463 return ret;
1464 }
1465
1466 /**************************************************************************
1467 * MMSYSTEM_MidiStream_MessageHandler [internal]
1468 */
1469 static BOOL MMSYSTEM_MidiStream_MessageHandler(WINE_MIDIStream* lpMidiStrm, LPWINE_MIDI lpwm, LPMSG msg)
1470 {
1471 LPMIDIHDR lpMidiHdr;
1472 LPMIDIHDR* lpmh;
1473 LPBYTE lpData;
1474
1475 switch (msg->message) {
1476 case WM_QUIT:
1477 SetEvent(lpMidiStrm->hEvent);
1478 return FALSE;
1479 case WINE_MSM_STOP:
1480 TRACE("STOP\n");
1481 /* this is not quite what MS doc says... */
1482 midiOutReset(lpMidiStrm->hDevice);
1483 /* empty list of already submitted buffers */
1484 for (lpMidiHdr = lpMidiStrm->lpMidiHdr; lpMidiHdr; lpMidiHdr = (LPMIDIHDR)lpMidiHdr->lpNext) {
1485 lpMidiHdr->dwFlags |= MHDR_DONE;
1486 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
1487
1488 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1489 (HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
1490 lpwm->mod.dwInstance, (DWORD)lpMidiHdr, 0L);
1491 }
1492 lpMidiStrm->lpMidiHdr = 0;
1493 SetEvent(lpMidiStrm->hEvent);
1494 break;
1495 case WINE_MSM_HEADER:
1496 /* sets initial tick count for first MIDIHDR */
1497 if (!lpMidiStrm->dwStartTicks)
1498 lpMidiStrm->dwStartTicks = GetTickCount();
1499
1500 /* FIXME(EPP): "I don't understand the content of the first MIDIHDR sent
1501 * by native mcimidi, it doesn't look like a correct one".
1502 * this trick allows to throw it away... but I don't like it.
1503 * It looks like part of the file I'm trying to play and definitively looks
1504 * like raw midi content
1505 * I'd really like to understand why native mcimidi sends it. Perhaps a bad
1506 * synchronization issue where native mcimidi is still processing raw MIDI
1507 * content before generating MIDIEVENTs ?
1508 *
1509 * 4c 04 89 3b 00 81 7c 99 3b 43 00 99 23 5e 04 89 L..;..|.;C..#^..
1510 * 3b 00 00 89 23 00 7c 99 3b 45 00 99 28 62 04 89 ;...#.|.;E..(b..
1511 * 3b 00 00 89 28 00 81 7c 99 3b 4e 00 99 23 5e 04 ;...(..|.;N..#^.
1512 * 89 3b 00 00 89 23 00 7c 99 3b 45 00 99 23 78 04 .;...#.|.;E..#x.
1513 * 89 3b 00 00 89 23 00 81 7c 99 3b 48 00 99 23 5e .;...#..|.;H..#^
1514 * 04 89 3b 00 00 89 23 00 7c 99 3b 4e 00 99 28 62 ..;...#.|.;N..(b
1515 * 04 89 3b 00 00 89 28 00 81 7c 99 39 4c 00 99 23 ..;...(..|.9L..#
1516 * 5e 04 89 39 00 00 89 23 00 82 7c 99 3b 4c 00 99 ^..9...#..|.;L..
1517 * 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 00 99 #^..;...#.|.;H..
1518 * 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b 3f 04 (b..;...(..|.;?.
1519 * 89 3b 00 1c 99 23 5e 04 89 23 00 5c 99 3b 45 00 .;...#^..#.\.;E.
1520 * 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 3b 46 .#x..;...#..|.;F
1521 * 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 ..#^..;...#.|.;H
1522 * 00 99 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b ..(b..;...(..|.;
1523 * 46 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b F..#^..;...#.|.;
1524 * 48 00 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 H..#x..;...#..|.
1525 * 3b 4c 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 ;L..#^..;...#.|.
1526 */
1527 lpMidiHdr = (LPMIDIHDR)msg->lParam;
1528 lpData = (LPBYTE)lpMidiHdr->lpData;
1529 TRACE("Adding %s lpMidiHdr=%p [lpData=0x%08lx dwBufferLength=%lu/%lu dwFlags=0x%08lx size=%u]\n",
1530 (lpMidiHdr->dwFlags & MHDR_ISSTRM) ? "stream" : "regular", lpMidiHdr,
1531 (DWORD)lpMidiHdr, lpMidiHdr->dwBufferLength, lpMidiHdr->dwBytesRecorded,
1532 lpMidiHdr->dwFlags, msg->wParam);
1533 #if 0
1534 /* dumps content of lpMidiHdr->lpData
1535 * FIXME: there should be a debug routine somewhere that already does this
1536 * I hate spreading this type of shit all around the code
1537 */
1538 for (dwToGo = 0; dwToGo < lpMidiHdr->dwBufferLength; dwToGo += 16) {
1539 DWORD i;
1540 BYTE ch;
1541
1542 for (i = 0; i < min(16, lpMidiHdr->dwBufferLength - dwToGo); i++)
1543 printf("%02x ", lpData[dwToGo + i]);
1544 for (; i < 16; i++)
1545 printf(" ");
1546 for (i = 0; i < min(16, lpMidiHdr->dwBufferLength - dwToGo); i++) {
1547 ch = lpData[dwToGo + i];
1548 printf("%c", (ch >= 0x20 && ch <= 0x7F) ? ch : '.');
1549 }
1550 printf("\n");
1551 }
1552 #endif
1553 if (((LPMIDIEVENT)lpData)->dwStreamID != 0 &&
1554 ((LPMIDIEVENT)lpData)->dwStreamID != 0xFFFFFFFF &&
1555 ((LPMIDIEVENT)lpData)->dwStreamID != (DWORD)lpMidiStrm) {
1556 FIXME("Dropping bad %s lpMidiHdr (streamID=%08lx)\n",
1557 (lpMidiHdr->dwFlags & MHDR_ISSTRM) ? "stream" : "regular",
1558 ((LPMIDIEVENT)lpData)->dwStreamID);
1559 lpMidiHdr->dwFlags |= MHDR_DONE;
1560 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
1561
1562 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1563 (HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
1564 lpwm->mod.dwInstance, (DWORD)lpMidiHdr, 0L);
1565 break;
1566 }
1567
1568 for (lpmh = &lpMidiStrm->lpMidiHdr; *lpmh; lpmh = (LPMIDIHDR*)&((*lpmh)->lpNext));
1569 *lpmh = lpMidiHdr;
1570 lpMidiHdr = (LPMIDIHDR)msg->lParam;
1571 lpMidiHdr->lpNext = 0;
1572 lpMidiHdr->dwFlags |= MHDR_INQUEUE;
1573 lpMidiHdr->dwFlags &= ~MHDR_DONE;
1574 lpMidiHdr->dwOffset = 0;
1575
1576 break;
1577 default:
1578 FIXME("Unknown message %d\n", msg->message);
1579 break;
1580 }
1581 return TRUE;
1582 }
1583
1584 /**************************************************************************
1585 * MMSYSTEM_MidiStream_Player [internal]
1586 */
1587 static DWORD CALLBACK MMSYSTEM_MidiStream_Player(LPVOID pmt)
1588 {
1589 WINE_MIDIStream* lpMidiStrm = pmt;
1590 WINE_MIDI* lpwm;
1591 MSG msg;
1592 DWORD dwToGo;
1593 DWORD dwCurrTC;
1594 LPMIDIHDR lpMidiHdr;
1595 LPMIDIEVENT me;
1596 LPBYTE lpData = 0;
1597
1598 TRACE("(%p)!\n", lpMidiStrm);
1599
1600 if (!lpMidiStrm ||
1601 (lpwm = (LPWINE_MIDI)MMDRV_Get(lpMidiStrm->hDevice, MMDRV_MIDIOUT, FALSE)) == NULL)
1602 goto the_end;
1603
1604 /* force thread's queue creation */
1605 /* Used to be InitThreadInput16(0, 5); */
1606 /* but following works also with hack in midiStreamOpen */
1607 PeekMessageA(&msg, 0, 0, 0, 0);
1608
1609 /* FIXME: this next line must be called before midiStreamOut or midiStreamRestart are called */
1610 SetEvent(lpMidiStrm->hEvent);
1611 TRACE("Ready to go 1\n");
1612 /* thread is started in paused mode */
1613 SuspendThread(lpMidiStrm->hThread);
1614 TRACE("Ready to go 2\n");
1615
1616 lpMidiStrm->dwStartTicks = 0;
1617 lpMidiStrm->dwPulses = 0;
1618
1619 lpMidiStrm->lpMidiHdr = 0;
1620
1621 for (;;) {
1622 lpMidiHdr = lpMidiStrm->lpMidiHdr;
1623 if (!lpMidiHdr) {
1624 /* for first message, block until one arrives, then process all that are available */
1625 GetMessageA(&msg, 0, 0, 0);
1626 do {
1627 if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm, lpwm, &msg))
1628 goto the_end;
1629 } while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE));
1630 lpData = 0;
1631 continue;
1632 }
1633
1634 if (!lpData)
1635 lpData = (LPBYTE)lpMidiHdr->lpData;
1636
1637 me = (LPMIDIEVENT)(lpData + lpMidiHdr->dwOffset);
1638
1639 /* do we have to wait ? */
1640 if (me->dwDeltaTime) {
1641 lpMidiStrm->dwPositionMS += MMSYSTEM_MidiStream_Convert(lpMidiStrm, me->dwDeltaTime);
1642 lpMidiStrm->dwPulses += me->dwDeltaTime;
1643
1644 dwToGo = lpMidiStrm->dwStartTicks + lpMidiStrm->dwPositionMS;
1645
1646 TRACE("%ld/%ld/%ld\n", dwToGo, GetTickCount(), me->dwDeltaTime);
1647 while ((dwCurrTC = GetTickCount()) < dwToGo) {
1648 if (MsgWaitForMultipleObjects(0, NULL, FALSE, dwToGo - dwCurrTC, QS_ALLINPUT) == WAIT_OBJECT_0) {
1649 /* got a message, handle it */
1650 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) {
1651 if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm, lpwm, &msg))
1652 goto the_end;
1653 }
1654 lpData = 0;
1655 } else {
1656 /* timeout, so me->dwDeltaTime is elapsed, can break the while loop */
1657 break;
1658 }
1659 }
1660 }
1661 switch (MEVT_EVENTTYPE(me->dwEvent & ~MEVT_F_CALLBACK)) {
1662 case MEVT_COMMENT:
1663 FIXME("NIY: MEVT_COMMENT\n");
1664 /* do nothing, skip bytes */
1665 break;
1666 case MEVT_LONGMSG:
1667 FIXME("NIY: MEVT_LONGMSG, aka sending Sysex event\n");
1668 break;
1669 case MEVT_NOP:
1670 break;
1671 case MEVT_SHORTMSG:
1672 midiOutShortMsg(lpMidiStrm->hDevice, MEVT_EVENTPARM(me->dwEvent));
1673 break;
1674 case MEVT_TEMPO:
1675 lpMidiStrm->dwTempo = MEVT_EVENTPARM(me->dwEvent);
1676 break;
1677 case MEVT_VERSION:
1678 break;
1679 default:
1680 FIXME("Unknown MEVT (0x%02x)\n", MEVT_EVENTTYPE(me->dwEvent & ~MEVT_F_CALLBACK));
1681 break;
1682 }
1683 if (me->dwEvent & MEVT_F_CALLBACK) {
1684 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1685 (HDRVR)lpMidiStrm->hDevice, MM_MOM_POSITIONCB,
1686 lpwm->mod.dwInstance, (LPARAM)lpMidiHdr, 0L);
1687 }
1688 lpMidiHdr->dwOffset += sizeof(MIDIEVENT) - sizeof(me->dwParms);
1689 if (me->dwEvent & MEVT_F_LONG)
1690 lpMidiHdr->dwOffset += (MEVT_EVENTPARM(me->dwEvent) + 3) & ~3;
1691 if (lpMidiHdr->dwOffset >= lpMidiHdr->dwBufferLength) {
1692 /* done with this header */
1693 lpMidiHdr->dwFlags |= MHDR_DONE;
1694 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
1695
1696 lpMidiStrm->lpMidiHdr = (LPMIDIHDR)lpMidiHdr->lpNext;
1697 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
1698 (HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
1699 lpwm->mod.dwInstance, (DWORD)lpMidiHdr, 0L);
1700 lpData = 0;
1701 }
1702 }
1703 the_end:
1704 TRACE("End of thread\n");
1705 ExitThread(0);
1706 return 0; /* for removing the warning, never executed */
1707 }
1708
1709 /**************************************************************************
1710 * MMSYSTEM_MidiStream_PostMessage [internal]
1711 */
1712 static BOOL MMSYSTEM_MidiStream_PostMessage(WINE_MIDIStream* lpMidiStrm, WORD msg, DWORD pmt1, DWORD pmt2)
1713 {
1714 if (PostThreadMessageA(lpMidiStrm->dwThreadID, msg, pmt1, pmt2)) {
1715 DWORD count;
1716
1717 if (pFnReleaseThunkLock) pFnReleaseThunkLock(&count);
1718 WaitForSingleObject(lpMidiStrm->hEvent, INFINITE);
1719 if (pFnRestoreThunkLock) pFnRestoreThunkLock(count);
1720 } else {
1721 WARN("bad PostThreadMessageA\n");
1722 return FALSE;
1723 }
1724 return TRUE;
1725 }
1726
1727 /**************************************************************************
1728 * midiStreamClose [WINMM.@]
1729 */
1730 MMRESULT WINAPI midiStreamClose(HMIDISTRM hMidiStrm)
1731 {
1732 WINE_MIDIStream* lpMidiStrm;
1733
1734 TRACE("(%p)!\n", hMidiStrm);
1735
1736 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL))
1737 return MMSYSERR_INVALHANDLE;
1738
1739 midiStreamStop(hMidiStrm);
1740 MMSYSTEM_MidiStream_PostMessage(lpMidiStrm, WM_QUIT, 0, 0);
1741 HeapFree(GetProcessHeap(), 0, lpMidiStrm);
1742 CloseHandle(lpMidiStrm->hEvent);
1743
1744 return midiOutClose((HMIDIOUT)hMidiStrm);
1745 }
1746
1747 /**************************************************************************
1748 * MMSYSTEM_MidiStream_Open [internal]
1749 */
1750 MMRESULT MIDI_StreamOpen(HMIDISTRM* lphMidiStrm, LPUINT lpuDeviceID, DWORD cMidi,
1751 DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD fdwOpen,
1752 BOOL bFrom32)
1753 {
1754 WINE_MIDIStream* lpMidiStrm;
1755 MMRESULT ret;
1756 MIDIOPENSTRMID mosm;
1757 LPWINE_MIDI lpwm;
1758 HMIDIOUT hMidiOut;
1759
1760 TRACE("(%p, %p, %ld, 0x%08lx, 0x%08lx, 0x%08lx)!\n",
1761 lphMidiStrm, lpuDeviceID, cMidi, dwCallback, dwInstance, fdwOpen);
1762
1763 if (cMidi != 1 || lphMidiStrm == NULL || lpuDeviceID == NULL)
1764 return MMSYSERR_INVALPARAM;
1765
1766 lpMidiStrm = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_MIDIStream));
1767 if (!lpMidiStrm)
1768 return MMSYSERR_NOMEM;
1769
1770 lpMidiStrm->dwTempo = 500000;
1771 lpMidiStrm->dwTimeDiv = 480; /* 480 is 120 quater notes per minute *//* FIXME ??*/
1772 lpMidiStrm->dwPositionMS = 0;
1773
1774 mosm.dwStreamID = (DWORD)lpMidiStrm;
1775 /* FIXME: the correct value is not allocated yet for MAPPER */
1776 mosm.wDeviceID = *lpuDeviceID;
1777 lpwm = MIDI_OutAlloc(&hMidiOut, &dwCallback, &dwInstance, &fdwOpen, 1, &mosm, bFrom32);
1778 lpMidiStrm->hDevice = hMidiOut;
1779 if (lphMidiStrm)
1780 *lphMidiStrm = (HMIDISTRM)hMidiOut;
1781
1782 lpwm->mld.uDeviceID = *lpuDeviceID;
1783
1784 ret = MMDRV_Open(&lpwm->mld, MODM_OPEN, (DWORD)&lpwm->mod, fdwOpen);
1785 lpMidiStrm->hEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
1786 lpMidiStrm->wFlags = HIWORD(fdwOpen);
1787
1788 lpMidiStrm->hThread = CreateThread(NULL, 0, MMSYSTEM_MidiStream_Player,
1789 lpMidiStrm, 0, &(lpMidiStrm->dwThreadID));
1790
1791 if (!lpMidiStrm->hThread) {
1792 midiStreamClose((HMIDISTRM)hMidiOut);
1793 return MMSYSERR_NOMEM;
1794 }
1795 SetThreadPriority(lpMidiStrm->hThread, THREAD_PRIORITY_TIME_CRITICAL);
1796
1797 /* wait for thread to have started, and for its queue to be created */
1798 {
1799 DWORD count;
1800
1801 /* (Release|Restore)ThunkLock() is needed when this method is called from 16 bit code,
1802 * (meaning the Win16Lock is set), so that it's released and the 32 bit thread running
1803 * MMSYSTEM_MidiStreamPlayer can acquire Win16Lock to create its queue.
1804 */
1805 if (pFnReleaseThunkLock) pFnReleaseThunkLock(&count);
1806 WaitForSingleObject(lpMidiStrm->hEvent, INFINITE);
1807 if (pFnRestoreThunkLock) pFnRestoreThunkLock(count);
1808 }
1809
1810 TRACE("=> (%u/%d) hMidi=%p ret=%d lpMidiStrm=%p\n",
1811 *lpuDeviceID, lpwm->mld.uDeviceID, *lphMidiStrm, ret, lpMidiStrm);
1812 return ret;
1813 }
1814
1815 /**************************************************************************
1816 * midiStreamOpen [WINMM.@]
1817 */
1818 MMRESULT WINAPI midiStreamOpen(HMIDISTRM* lphMidiStrm, LPUINT lpuDeviceID,
1819 DWORD cMidi, DWORD_PTR dwCallback,
1820 DWORD_PTR dwInstance, DWORD fdwOpen)
1821 {
1822 return MIDI_StreamOpen(lphMidiStrm, lpuDeviceID, cMidi, dwCallback,
1823 dwInstance, fdwOpen, TRUE);
1824 }
1825
1826 /**************************************************************************
1827 * midiStreamOut [WINMM.@]
1828 */
1829 MMRESULT WINAPI midiStreamOut(HMIDISTRM hMidiStrm, LPMIDIHDR lpMidiHdr,
1830 UINT cbMidiHdr)
1831 {
1832 WINE_MIDIStream* lpMidiStrm;
1833 DWORD ret = MMSYSERR_NOERROR;
1834
1835 TRACE("(%p, %p, %u)!\n", hMidiStrm, lpMidiHdr, cbMidiHdr);
1836
1837 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1838 ret = MMSYSERR_INVALHANDLE;
1839 } else if (!lpMidiHdr) {
1840 ret = MMSYSERR_INVALPARAM;
1841 } else {
1842 if (!PostThreadMessageA(lpMidiStrm->dwThreadID,
1843 WINE_MSM_HEADER, cbMidiHdr,
1844 (DWORD)lpMidiHdr)) {
1845 WARN("bad PostThreadMessageA\n");
1846 ret = MMSYSERR_ERROR;
1847 }
1848 }
1849 return ret;
1850 }
1851
1852 /**************************************************************************
1853 * midiStreamPause [WINMM.@]
1854 */
1855 MMRESULT WINAPI midiStreamPause(HMIDISTRM hMidiStrm)
1856 {
1857 WINE_MIDIStream* lpMidiStrm;
1858 DWORD ret = MMSYSERR_NOERROR;
1859
1860 TRACE("(%p)!\n", hMidiStrm);
1861
1862 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1863 ret = MMSYSERR_INVALHANDLE;
1864 } else {
1865 if (SuspendThread(lpMidiStrm->hThread) == 0xFFFFFFFF) {
1866 WARN("bad Suspend (%ld)\n", GetLastError());
1867 ret = MMSYSERR_ERROR;
1868 }
1869 }
1870 return ret;
1871 }
1872
1873 /**************************************************************************
1874 * midiStreamPosition [WINMM.@]
1875 */
1876 MMRESULT WINAPI midiStreamPosition(HMIDISTRM hMidiStrm, LPMMTIME lpMMT, UINT cbmmt)
1877 {
1878 WINE_MIDIStream* lpMidiStrm;
1879 DWORD ret = MMSYSERR_NOERROR;
1880
1881 TRACE("(%p, %p, %u)!\n", hMidiStrm, lpMMT, cbmmt);
1882
1883 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1884 ret = MMSYSERR_INVALHANDLE;
1885 } else if (lpMMT == NULL || cbmmt != sizeof(MMTIME)) {
1886 ret = MMSYSERR_INVALPARAM;
1887 } else {
1888 switch (lpMMT->wType) {
1889 case TIME_MS:
1890 lpMMT->u.ms = lpMidiStrm->dwPositionMS;
1891 TRACE("=> %ld ms\n", lpMMT->u.ms);
1892 break;
1893 case TIME_TICKS:
1894 lpMMT->u.ticks = lpMidiStrm->dwPulses;
1895 TRACE("=> %ld ticks\n", lpMMT->u.ticks);
1896 break;
1897 default:
1898 WARN("Unsupported time type %d\n", lpMMT->wType);
1899 lpMMT->wType = TIME_MS;
1900 ret = MMSYSERR_INVALPARAM;
1901 break;
1902 }
1903 }
1904 return ret;
1905 }
1906
1907 /**************************************************************************
1908 * midiStreamProperty [WINMM.@]
1909 */
1910 MMRESULT WINAPI midiStreamProperty(HMIDISTRM hMidiStrm, LPBYTE lpPropData, DWORD dwProperty)
1911 {
1912 WINE_MIDIStream* lpMidiStrm;
1913 MMRESULT ret = MMSYSERR_NOERROR;
1914
1915 TRACE("(%p, %p, %lx)\n", hMidiStrm, lpPropData, dwProperty);
1916
1917 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1918 ret = MMSYSERR_INVALHANDLE;
1919 } else if ((dwProperty & (MIDIPROP_GET|MIDIPROP_SET)) == 0) {
1920 ret = MMSYSERR_INVALPARAM;
1921 } else if (dwProperty & MIDIPROP_TEMPO) {
1922 MIDIPROPTEMPO* mpt = (MIDIPROPTEMPO*)lpPropData;
1923
1924 if (sizeof(MIDIPROPTEMPO) != mpt->cbStruct) {
1925 ret = MMSYSERR_INVALPARAM;
1926 } else if (dwProperty & MIDIPROP_SET) {
1927 lpMidiStrm->dwTempo = mpt->dwTempo;
1928 TRACE("Setting tempo to %ld\n", mpt->dwTempo);
1929 } else if (dwProperty & MIDIPROP_GET) {
1930 mpt->dwTempo = lpMidiStrm->dwTempo;
1931 TRACE("Getting tempo <= %ld\n", mpt->dwTempo);
1932 }
1933 } else if (dwProperty & MIDIPROP_TIMEDIV) {
1934 MIDIPROPTIMEDIV* mptd = (MIDIPROPTIMEDIV*)lpPropData;
1935
1936 if (sizeof(MIDIPROPTIMEDIV) != mptd->cbStruct) {
1937 ret = MMSYSERR_INVALPARAM;
1938 } else if (dwProperty & MIDIPROP_SET) {
1939 lpMidiStrm->dwTimeDiv = mptd->dwTimeDiv;
1940 TRACE("Setting time div to %ld\n", mptd->dwTimeDiv);
1941 } else if (dwProperty & MIDIPROP_GET) {
1942 mptd->dwTimeDiv = lpMidiStrm->dwTimeDiv;
1943 TRACE("Getting time div <= %ld\n", mptd->dwTimeDiv);
1944 }
1945 } else {
1946 ret = MMSYSERR_INVALPARAM;
1947 }
1948
1949 return ret;
1950 }
1951
1952 /**************************************************************************
1953 * midiStreamRestart [WINMM.@]
1954 */
1955 MMRESULT WINAPI midiStreamRestart(HMIDISTRM hMidiStrm)
1956 {
1957 WINE_MIDIStream* lpMidiStrm;
1958 MMRESULT ret = MMSYSERR_NOERROR;
1959
1960 TRACE("(%p)!\n", hMidiStrm);
1961
1962 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1963 ret = MMSYSERR_INVALHANDLE;
1964 } else {
1965 DWORD ret;
1966
1967 /* since we increase the thread suspend count on each midiStreamPause
1968 * there may be a need for several midiStreamResume
1969 */
1970 do {
1971 ret = ResumeThread(lpMidiStrm->hThread);
1972 } while (ret != 0xFFFFFFFF && ret != 0);
1973 if (ret == 0xFFFFFFFF) {
1974 WARN("bad Resume (%ld)\n", GetLastError());
1975 ret = MMSYSERR_ERROR;
1976 } else {
1977 lpMidiStrm->dwStartTicks = GetTickCount() - lpMidiStrm->dwPositionMS;
1978 }
1979 }
1980 return ret;
1981 }
1982
1983 /**************************************************************************
1984 * midiStreamStop [WINMM.@]
1985 */
1986 MMRESULT WINAPI midiStreamStop(HMIDISTRM hMidiStrm)
1987 {
1988 WINE_MIDIStream* lpMidiStrm;
1989 MMRESULT ret = MMSYSERR_NOERROR;
1990
1991 TRACE("(%p)!\n", hMidiStrm);
1992
1993 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
1994 ret = MMSYSERR_INVALHANDLE;
1995 } else {
1996 /* in case stream has been paused... FIXME is the current state correct ? */
1997 midiStreamRestart(hMidiStrm);
1998 MMSYSTEM_MidiStream_PostMessage(lpMidiStrm, WINE_MSM_STOP, 0, 0);
1999 }
2000 return ret;
2001 }
2002
2003 UINT WAVE_Open(HANDLE* lphndl, UINT uDeviceID, UINT uType,
2004 LPCWAVEFORMATEX lpFormat, DWORD_PTR dwCallback,
2005 DWORD_PTR dwInstance, DWORD dwFlags, BOOL bFrom32)
2006 {
2007 HANDLE handle;
2008 LPWINE_MLD wmld;
2009 DWORD dwRet = MMSYSERR_NOERROR;
2010 WAVEOPENDESC wod;
2011
2012 TRACE("(%p, %d, %s, %p, %08lX, %08lX, %08lX, %d);\n",
2013 lphndl, (int)uDeviceID, (uType==MMDRV_WAVEOUT)?"Out":"In", lpFormat, dwCallback,
2014 dwInstance, dwFlags, bFrom32?32:16);
2015
2016 if (dwFlags & WAVE_FORMAT_QUERY)
2017 TRACE("WAVE_FORMAT_QUERY requested !\n");
2018
2019 if (lpFormat == NULL) {
2020 WARN("bad format\n");
2021 return WAVERR_BADFORMAT;
2022 }
2023
2024 if ((dwFlags & WAVE_MAPPED) && (uDeviceID == (UINT)-1)) {
2025 WARN("invalid parameter\n");
2026 return MMSYSERR_INVALPARAM;
2027 }
2028
2029 /* may have a PCMWAVEFORMAT rather than a WAVEFORMATEX so don't read cbSize */
2030 TRACE("wFormatTag=%u, nChannels=%u, nSamplesPerSec=%lu, nAvgBytesPerSec=%lu, nBlockAlign=%u, wBitsPerSample=%u\n",
2031 lpFormat->wFormatTag, lpFormat->nChannels, lpFormat->nSamplesPerSec,
2032 lpFormat->nAvgBytesPerSec, lpFormat->nBlockAlign, lpFormat->wBitsPerSample);
2033
2034 if ((wmld = MMDRV_Alloc(sizeof(WINE_WAVE), uType, &handle,
2035 &dwFlags, &dwCallback, &dwInstance, bFrom32)) == NULL) {
2036 WARN("no memory\n");
2037 return MMSYSERR_NOMEM;
2038 }
2039
2040 wod.hWave = handle;
2041 wod.lpFormat = (LPWAVEFORMATEX)lpFormat; /* should the struct be copied iso pointer? */
2042 wod.dwCallback = dwCallback;
2043 wod.dwInstance = dwInstance;
2044 wod.dnDevNode = 0L;
2045
2046 TRACE("cb=%08lx\n", wod.dwCallback);
2047
2048 for (;;) {
2049 if (dwFlags & WAVE_MAPPED) {
2050 wod.uMappedDeviceID = uDeviceID;
2051 uDeviceID = WAVE_MAPPER;
2052 } else {
2053 wod.uMappedDeviceID = -1;
2054 }
2055 wmld->uDeviceID = uDeviceID;
2056
2057 dwRet = MMDRV_Open(wmld, (uType == MMDRV_WAVEOUT) ? WODM_OPEN : WIDM_OPEN,
2058 (DWORD)&wod, dwFlags);
2059
2060 TRACE("dwRet = %s\n", WINMM_ErrorToString(dwRet));
2061 if (dwRet != WAVERR_BADFORMAT ||
2062 ((dwFlags & (WAVE_MAPPED|WAVE_FORMAT_DIRECT)) != 0) || (uDeviceID == WAVE_MAPPER)) break;
2063 /* if we ask for a format which isn't supported by the physical driver,
2064 * let's try to map it through the wave mapper (except, if we already tried
2065 * or user didn't allow us to use acm codecs or the device is already the mapper)
2066 */
2067 dwFlags |= WAVE_MAPPED;
2068 /* we shall loop only one */
2069 }
2070
2071 if ((dwFlags & WAVE_FORMAT_QUERY) || dwRet != MMSYSERR_NOERROR) {
2072 MMDRV_Free(handle, wmld);
2073 handle = 0;
2074 }
2075
2076 if (lphndl != NULL) *lphndl = handle;
2077 TRACE("=> %s hWave=%p\n", WINMM_ErrorToString(dwRet), handle);
2078
2079 return dwRet;
2080 }
2081
2082 /**************************************************************************
2083 * waveOutGetNumDevs [WINMM.@]
2084 */
2085 UINT WINAPI waveOutGetNumDevs(void)
2086 {
2087 return MMDRV_GetNum(MMDRV_WAVEOUT);
2088 }
2089
2090 /**************************************************************************
2091 * waveOutGetDevCapsA [WINMM.@]
2092 */
2093 MMRESULT WINAPI waveOutGetDevCapsA(UINT_PTR uDeviceID, LPWAVEOUTCAPSA lpCaps,
2094 UINT uSize)
2095 {
2096 WAVEOUTCAPSW wocW;
2097 UINT ret;
2098
2099 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2100
2101 ret = waveOutGetDevCapsW(uDeviceID, &wocW, sizeof(wocW));
2102
2103 if (ret == MMSYSERR_NOERROR) {
2104 WAVEOUTCAPSA wocA;
2105 wocA.wMid = wocW.wMid;
2106 wocA.wPid = wocW.wPid;
2107 wocA.vDriverVersion = wocW.vDriverVersion;
2108 WideCharToMultiByte( CP_ACP, 0, wocW.szPname, -1, wocA.szPname,
2109 sizeof(wocA.szPname), NULL, NULL );
2110 wocA.dwFormats = wocW.dwFormats;
2111 wocA.wChannels = wocW.wChannels;
2112 wocA.dwSupport = wocW.dwSupport;
2113 memcpy(lpCaps, &wocA, min(uSize, sizeof(wocA)));
2114 }
2115 return ret;
2116 }
2117
2118 /**************************************************************************
2119 * waveOutGetDevCapsW [WINMM.@]
2120 */
2121 UINT WINAPI waveOutGetDevCapsW(UINT_PTR uDeviceID, LPWAVEOUTCAPSW lpCaps,
2122 UINT uSize)
2123 {
2124 LPWINE_MLD wmld;
2125
2126 TRACE("(%u %p %u)!\n", uDeviceID, lpCaps, uSize);
2127
2128 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2129
2130 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_WAVEOUT, TRUE)) == NULL)
2131 return MMSYSERR_BADDEVICEID;
2132
2133 return MMDRV_Message(wmld, WODM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
2134
2135 }
2136
2137 /**************************************************************************
2138 * waveOutGetErrorTextA [WINMM.@]
2139 * waveInGetErrorTextA [WINMM.@]
2140 */
2141 UINT WINAPI waveOutGetErrorTextA(UINT uError, LPSTR lpText, UINT uSize)
2142 {
2143 UINT ret;
2144
2145 if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
2146 else if (uSize == 0) ret = MMSYSERR_NOERROR;
2147 else
2148 {
2149 LPWSTR xstr = HeapAlloc(GetProcessHeap(), 0, uSize * sizeof(WCHAR));
2150 if (!xstr) ret = MMSYSERR_NOMEM;
2151 else
2152 {
2153 ret = waveOutGetErrorTextW(uError, xstr, uSize);
2154 if (ret == MMSYSERR_NOERROR)
2155 WideCharToMultiByte(CP_ACP, 0, xstr, -1, lpText, uSize, NULL, NULL);
2156 HeapFree(GetProcessHeap(), 0, xstr);
2157 }
2158 }
2159 return ret;
2160 }
2161
2162 /**************************************************************************
2163 * waveOutGetErrorTextW [WINMM.@]
2164 * waveInGetErrorTextW [WINMM.@]
2165 */
2166 UINT WINAPI waveOutGetErrorTextW(UINT uError, LPWSTR lpText, UINT uSize)
2167 {
2168 UINT ret = MMSYSERR_BADERRNUM;
2169
2170 if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
2171 else if (uSize == 0) ret = MMSYSERR_NOERROR;
2172 else if (
2173 /* test has been removed 'coz MMSYSERR_BASE is 0, and gcc did emit
2174 * a warning for the test was always true */
2175 (/*uError >= MMSYSERR_BASE && */ uError <= MMSYSERR_LASTERROR) ||
2176 (uError >= WAVERR_BASE && uError <= WAVERR_LASTERROR)) {
2177 if (LoadStringW(WINMM_IData.hWinMM32Instance,
2178 uError, lpText, uSize) > 0) {
2179 ret = MMSYSERR_NOERROR;
2180 }
2181 }
2182 return ret;
2183 }
2184
2185 /**************************************************************************
2186 * waveOutOpen [WINMM.@]
2187 * All the args/structs have the same layout as the win16 equivalents
2188 */
2189 MMRESULT WINAPI waveOutOpen(LPHWAVEOUT lphWaveOut, UINT uDeviceID,
2190 LPCWAVEFORMATEX lpFormat, DWORD_PTR dwCallback,
2191 DWORD_PTR dwInstance, DWORD dwFlags)
2192 {
2193 return WAVE_Open((HANDLE*)lphWaveOut, uDeviceID, MMDRV_WAVEOUT, lpFormat,
2194 dwCallback, dwInstance, dwFlags, TRUE);
2195 }
2196
2197 /**************************************************************************
2198 * waveOutClose [WINMM.@]
2199 */
2200 UINT WINAPI waveOutClose(HWAVEOUT hWaveOut)
2201 {
2202 LPWINE_MLD wmld;
2203 DWORD dwRet;
2204
2205 TRACE("(%p)\n", hWaveOut);
2206
2207 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2208 return MMSYSERR_INVALHANDLE;
2209
2210 dwRet = MMDRV_Close(wmld, WODM_CLOSE);
2211 if (dwRet != WAVERR_STILLPLAYING)
2212 MMDRV_Free(hWaveOut, wmld);
2213
2214 return dwRet;
2215 }
2216
2217 /**************************************************************************
2218 * waveOutPrepareHeader [WINMM.@]
2219 */
2220 UINT WINAPI waveOutPrepareHeader(HWAVEOUT hWaveOut,
2221 WAVEHDR* lpWaveOutHdr, UINT uSize)
2222 {
2223 LPWINE_MLD wmld;
2224 UINT result;
2225
2226 TRACE("(%p, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
2227
2228 if (lpWaveOutHdr == NULL || uSize < sizeof (WAVEHDR))
2229 return MMSYSERR_INVALPARAM;
2230
2231 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2232 return MMSYSERR_INVALHANDLE;
2233
2234 if ((result = MMDRV_Message(wmld, WODM_PREPARE, (DWORD_PTR)lpWaveOutHdr,
2235 uSize, TRUE)) != MMSYSERR_NOTSUPPORTED)
2236 return result;
2237
2238 if (lpWaveOutHdr->dwFlags & WHDR_INQUEUE)
2239 return WAVERR_STILLPLAYING;
2240
2241 lpWaveOutHdr->dwFlags |= WHDR_PREPARED;
2242 lpWaveOutHdr->dwFlags &= ~WHDR_DONE;
2243
2244 return MMSYSERR_NOERROR;
2245 }
2246
2247 /**************************************************************************
2248 * waveOutUnprepareHeader [WINMM.@]
2249 */
2250 UINT WINAPI waveOutUnprepareHeader(HWAVEOUT hWaveOut,
2251 LPWAVEHDR lpWaveOutHdr, UINT uSize)
2252 {
2253 LPWINE_MLD wmld;
2254 UINT result;
2255
2256 TRACE("(%p, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
2257
2258 if (lpWaveOutHdr == NULL || uSize < sizeof (WAVEHDR))
2259 return MMSYSERR_INVALPARAM;
2260
2261 if (!(lpWaveOutHdr->dwFlags & WHDR_PREPARED)) {
2262 return MMSYSERR_NOERROR;
2263 }
2264
2265 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2266 return MMSYSERR_INVALHANDLE;
2267
2268 if ((result = MMDRV_Message(wmld, WODM_UNPREPARE, (DWORD_PTR)lpWaveOutHdr,
2269 uSize, TRUE)) != MMSYSERR_NOTSUPPORTED)
2270 return result;
2271
2272 if (lpWaveOutHdr->dwFlags & WHDR_INQUEUE)
2273 return WAVERR_STILLPLAYING;
2274
2275 lpWaveOutHdr->dwFlags &= ~WHDR_PREPARED;
2276 lpWaveOutHdr->dwFlags |= WHDR_DONE;
2277
2278 return MMSYSERR_NOERROR;
2279 }
2280
2281 /**************************************************************************
2282 * waveOutWrite [WINMM.@]
2283 */
2284 UINT WINAPI waveOutWrite(HWAVEOUT hWaveOut, LPWAVEHDR lpWaveOutHdr,
2285 UINT uSize)
2286 {
2287 LPWINE_MLD wmld;
2288
2289 TRACE("(%p, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
2290
2291 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2292 return MMSYSERR_INVALHANDLE;
2293
2294 return MMDRV_Message(wmld, WODM_WRITE, (DWORD_PTR)lpWaveOutHdr, uSize, TRUE);
2295 }
2296
2297 /**************************************************************************
2298 * waveOutBreakLoop [WINMM.@]
2299 */
2300 UINT WINAPI waveOutBreakLoop(HWAVEOUT hWaveOut)
2301 {
2302 LPWINE_MLD wmld;
2303
2304 TRACE("(%p);\n", hWaveOut);
2305
2306 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2307 return MMSYSERR_INVALHANDLE;
2308 return MMDRV_Message(wmld, WODM_BREAKLOOP, 0L, 0L, TRUE);
2309 }
2310
2311 /**************************************************************************
2312 * waveOutPause [WINMM.@]
2313 */
2314 UINT WINAPI waveOutPause(HWAVEOUT hWaveOut)
2315 {
2316 LPWINE_MLD wmld;
2317
2318 TRACE("(%p);\n", hWaveOut);
2319
2320 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2321 return MMSYSERR_INVALHANDLE;
2322 return MMDRV_Message(wmld, WODM_PAUSE, 0L, 0L, TRUE);
2323 }
2324
2325 /**************************************************************************
2326 * waveOutReset [WINMM.@]
2327 */
2328 UINT WINAPI waveOutReset(HWAVEOUT hWaveOut)
2329 {
2330 LPWINE_MLD wmld;
2331
2332 TRACE("(%p);\n", hWaveOut);
2333
2334 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2335 return MMSYSERR_INVALHANDLE;
2336 return MMDRV_Message(wmld, WODM_RESET, 0L, 0L, TRUE);
2337 }
2338
2339 /**************************************************************************
2340 * waveOutRestart [WINMM.@]
2341 */
2342 UINT WINAPI waveOutRestart(HWAVEOUT hWaveOut)
2343 {
2344 LPWINE_MLD wmld;
2345
2346 TRACE("(%p);\n", hWaveOut);
2347
2348 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2349 return MMSYSERR_INVALHANDLE;
2350 return MMDRV_Message(wmld, WODM_RESTART, 0L, 0L, TRUE);
2351 }
2352
2353 /**************************************************************************
2354 * waveOutGetPosition [WINMM.@]
2355 */
2356 UINT WINAPI waveOutGetPosition(HWAVEOUT hWaveOut, LPMMTIME lpTime,
2357 UINT uSize)
2358 {
2359 LPWINE_MLD wmld;
2360
2361 TRACE("(%p, %p, %u);\n", hWaveOut, lpTime, uSize);
2362
2363 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2364 return MMSYSERR_INVALHANDLE;
2365
2366 return MMDRV_Message(wmld, WODM_GETPOS, (DWORD_PTR)lpTime, uSize, TRUE);
2367 }
2368
2369 /**************************************************************************
2370 * waveOutGetPitch [WINMM.@]
2371 */
2372 UINT WINAPI waveOutGetPitch(HWAVEOUT hWaveOut, LPDWORD lpdw)
2373 {
2374 LPWINE_MLD wmld;
2375
2376 TRACE("(%p, %08lx);\n", hWaveOut, (DWORD)lpdw);
2377
2378 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2379 return MMSYSERR_INVALHANDLE;
2380 return MMDRV_Message(wmld, WODM_GETPITCH, (DWORD_PTR)lpdw, 0L, TRUE);
2381 }
2382
2383 /**************************************************************************
2384 * waveOutSetPitch [WINMM.@]
2385 */
2386 UINT WINAPI waveOutSetPitch(HWAVEOUT hWaveOut, DWORD dw)
2387 {
2388 LPWINE_MLD wmld;
2389
2390 TRACE("(%p, %08lx);\n", hWaveOut, (DWORD)dw);
2391
2392 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2393 return MMSYSERR_INVALHANDLE;
2394 return MMDRV_Message(wmld, WODM_SETPITCH, dw, 0L, TRUE);
2395 }
2396
2397 /**************************************************************************
2398 * waveOutGetPlaybackRate [WINMM.@]
2399 */
2400 UINT WINAPI waveOutGetPlaybackRate(HWAVEOUT hWaveOut, LPDWORD lpdw)
2401 {
2402 LPWINE_MLD wmld;
2403
2404 TRACE("(%p, %08lx);\n", hWaveOut, (DWORD)lpdw);
2405
2406 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2407 return MMSYSERR_INVALHANDLE;
2408 return MMDRV_Message(wmld, WODM_GETPLAYBACKRATE, (DWORD_PTR)lpdw, 0L, TRUE);
2409 }
2410
2411 /**************************************************************************
2412 * waveOutSetPlaybackRate [WINMM.@]
2413 */
2414 UINT WINAPI waveOutSetPlaybackRate(HWAVEOUT hWaveOut, DWORD dw)
2415 {
2416 LPWINE_MLD wmld;
2417
2418 TRACE("(%p, %08lx);\n", hWaveOut, (DWORD)dw);
2419
2420 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2421 return MMSYSERR_INVALHANDLE;
2422 return MMDRV_Message(wmld, WODM_SETPLAYBACKRATE, dw, 0L, TRUE);
2423 }
2424
2425 /**************************************************************************
2426 * waveOutGetVolume [WINMM.@]
2427 */
2428 UINT WINAPI waveOutGetVolume(HWAVEOUT hWaveOut, LPDWORD lpdw)
2429 {
2430 LPWINE_MLD wmld;
2431
2432 TRACE("(%p, %08lx);\n", hWaveOut, (DWORD)lpdw);
2433
2434 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, TRUE)) == NULL)
2435 return MMSYSERR_INVALHANDLE;
2436
2437 return MMDRV_Message(wmld, WODM_GETVOLUME, (DWORD_PTR)lpdw, 0L, TRUE);
2438 }
2439
2440 /**************************************************************************
2441 * waveOutSetVolume [WINMM.@]
2442 */
2443 UINT WINAPI waveOutSetVolume(HWAVEOUT hWaveOut, DWORD dw)
2444 {
2445 LPWINE_MLD wmld;
2446
2447 TRACE("(%p, %08lx);\n", hWaveOut, dw);
2448
2449 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, TRUE)) == NULL)
2450 return MMSYSERR_INVALHANDLE;
2451
2452 return MMDRV_Message(wmld, WODM_SETVOLUME, dw, 0L, TRUE);
2453 }
2454
2455 /**************************************************************************
2456 * waveOutGetID [WINMM.@]
2457 */
2458 UINT WINAPI waveOutGetID(HWAVEOUT hWaveOut, UINT* lpuDeviceID)
2459 {
2460 LPWINE_MLD wmld;
2461
2462 TRACE("(%p, %p);\n", hWaveOut, lpuDeviceID);
2463
2464 if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
2465
2466 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
2467 return MMSYSERR_INVALHANDLE;
2468
2469 *lpuDeviceID = wmld->uDeviceID;
2470 return 0;
2471 }
2472
2473 /**************************************************************************
2474 * waveOutMessage [WINMM.@]
2475 */
2476 DWORD WINAPI waveOutMessage(HWAVEOUT hWaveOut, UINT uMessage,
2477 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2478 {
2479 LPWINE_MLD wmld;
2480
2481 TRACE("(%p, %u, %ld, %ld)\n", hWaveOut, uMessage, dwParam1, dwParam2);
2482
2483 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL) {
2484 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, TRUE)) != NULL) {
2485 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
2486 }
2487 WARN("invalid handle\n");
2488 return MMSYSERR_INVALHANDLE;
2489 }
2490
2491 /* from M$ KB */
2492 if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER)) {
2493 WARN("invalid parameter\n");
2494 return MMSYSERR_INVALPARAM;
2495 }
2496
2497 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
2498 }
2499
2500 /**************************************************************************
2501 * waveInGetNumDevs [WINMM.@]
2502 */
2503 UINT WINAPI waveInGetNumDevs(void)
2504 {
2505 return MMDRV_GetNum(MMDRV_WAVEIN);
2506 }
2507
2508 /**************************************************************************
2509 * waveInGetDevCapsW [WINMM.@]
2510 */
2511 MMRESULT WINAPI waveInGetDevCapsW(UINT_PTR uDeviceID, LPWAVEINCAPSW lpCaps, UINT uSize)
2512 {
2513 LPWINE_MLD wmld;
2514
2515 TRACE("(%u %p %u)!\n", uDeviceID, lpCaps, uSize);
2516
2517 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2518
2519 if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_WAVEIN, TRUE)) == NULL)
2520 return MMSYSERR_BADDEVICEID;
2521
2522 return MMDRV_Message(wmld, WIDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize, TRUE);
2523 }
2524
2525 /**************************************************************************
2526 * waveInGetDevCapsA [WINMM.@]
2527 */
2528 UINT WINAPI waveInGetDevCapsA(UINT_PTR uDeviceID, LPWAVEINCAPSA lpCaps, UINT uSize)
2529 {
2530 WAVEINCAPSW wicW;
2531 UINT ret;
2532
2533 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
2534
2535 ret = waveInGetDevCapsW(uDeviceID, &wicW, sizeof(wicW));
2536
2537 if (ret == MMSYSERR_NOERROR) {
2538 WAVEINCAPSA wicA;
2539 wicA.wMid = wicW.wMid;
2540 wicA.wPid = wicW.wPid;
2541 wicA.vDriverVersion = wicW.vDriverVersion;
2542 WideCharToMultiByte( CP_ACP, 0, wicW.szPname, -1, wicA.szPname,
2543 sizeof(wicA.szPname), NULL, NULL );
2544 wicA.dwFormats = wicW.dwFormats;
2545 wicA.wChannels = wicW.wChannels;
2546 memcpy(lpCaps, &wicA, min(uSize, sizeof(wicA)));
2547 }
2548 return ret;
2549 }
2550
2551 /**************************************************************************
2552 * waveInOpen [WINMM.@]
2553 */
2554 MMRESULT WINAPI waveInOpen(LPHWAVEIN lphWaveIn, UINT uDeviceID,
2555 LPCWAVEFORMATEX lpFormat, DWORD_PTR dwCallback,
2556 DWORD_PTR dwInstance, DWORD dwFlags)
2557 {
2558 return WAVE_Open((HANDLE*)lphWaveIn, uDeviceID, MMDRV_WAVEIN, lpFormat,
2559 dwCallback, dwInstance, dwFlags, TRUE);
2560 }
2561
2562 /**************************************************************************
2563 * waveInClose [WINMM.@]
2564 */
2565 UINT WINAPI waveInClose(HWAVEIN hWaveIn)
2566 {
2567 LPWINE_MLD wmld;
2568 DWORD dwRet;
2569
2570 TRACE("(%p)\n", hWaveIn);
2571
2572 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2573 return MMSYSERR_INVALHANDLE;
2574
2575 dwRet = MMDRV_Message(wmld, WIDM_CLOSE, 0L, 0L, TRUE);
2576 if (dwRet != WAVERR_STILLPLAYING)
2577 MMDRV_Free(hWaveIn, wmld);
2578 return dwRet;
2579 }
2580
2581 /**************************************************************************
2582 * waveInPrepareHeader [WINMM.@]
2583 */
2584 UINT WINAPI waveInPrepareHeader(HWAVEIN hWaveIn, WAVEHDR* lpWaveInHdr,
2585 UINT uSize)
2586 {
2587 LPWINE_MLD wmld;
2588 UINT result;
2589
2590 TRACE("(%p, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
2591
2592 if (lpWaveInHdr == NULL || uSize < sizeof (WAVEHDR))
2593 return MMSYSERR_INVALPARAM;
2594
2595 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2596 return MMSYSERR_INVALHANDLE;
2597
2598 if ((result = MMDRV_Message(wmld, WIDM_PREPARE, (DWORD_PTR)lpWaveInHdr,
2599 uSize, TRUE)) != MMSYSERR_NOTSUPPORTED)
2600 return result;
2601
2602 if (lpWaveInHdr->dwFlags & WHDR_INQUEUE)
2603 return WAVERR_STILLPLAYING;
2604
2605 lpWaveInHdr->dwFlags |= WHDR_PREPARED;
2606 lpWaveInHdr->dwFlags &= ~WHDR_DONE;
2607 lpWaveInHdr->dwBytesRecorded = 0;
2608
2609 return MMSYSERR_NOERROR;
2610 }
2611
2612 /**************************************************************************
2613 * waveInUnprepareHeader [WINMM.@]
2614 */
2615 UINT WINAPI waveInUnprepareHeader(HWAVEIN hWaveIn, WAVEHDR* lpWaveInHdr,
2616 UINT uSize)
2617 {
2618 LPWINE_MLD wmld;
2619 UINT result;
2620
2621 TRACE("(%p, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
2622
2623 if (lpWaveInHdr == NULL || uSize < sizeof (WAVEHDR))
2624 return MMSYSERR_INVALPARAM;
2625
2626 if (!(lpWaveInHdr->dwFlags & WHDR_PREPARED))
2627 return MMSYSERR_NOERROR;
2628
2629 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2630 return MMSYSERR_INVALHANDLE;
2631
2632 if ((result = MMDRV_Message(wmld, WIDM_UNPREPARE, (DWORD_PTR)lpWaveInHdr,
2633 uSize, TRUE)) != MMSYSERR_NOTSUPPORTED)
2634 return result;
2635
2636 if (lpWaveInHdr->dwFlags & WHDR_INQUEUE)
2637 return WAVERR_STILLPLAYING;
2638
2639 lpWaveInHdr->dwFlags &= ~WHDR_PREPARED;
2640 lpWaveInHdr->dwFlags |= WHDR_DONE;
2641
2642 return MMSYSERR_NOERROR;
2643 }
2644
2645 /**************************************************************************
2646 * waveInAddBuffer [WINMM.@]
2647 */
2648 UINT WINAPI waveInAddBuffer(HWAVEIN hWaveIn,
2649 WAVEHDR* lpWaveInHdr, UINT uSize)
2650 {
2651 LPWINE_MLD wmld;
2652
2653 TRACE("(%p, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
2654
2655 if (lpWaveInHdr == NULL) return MMSYSERR_INVALPARAM;
2656 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2657 return MMSYSERR_INVALHANDLE;
2658
2659 return MMDRV_Message(wmld, WIDM_ADDBUFFER, (DWORD_PTR)lpWaveInHdr, uSize, TRUE);
2660 }
2661
2662 /**************************************************************************
2663 * waveInReset [WINMM.@]
2664 */
2665 UINT WINAPI waveInReset(HWAVEIN hWaveIn)
2666 {
2667 LPWINE_MLD wmld;
2668
2669 TRACE("(%p);\n", hWaveIn);
2670
2671 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2672 return MMSYSERR_INVALHANDLE;
2673
2674 return MMDRV_Message(wmld, WIDM_RESET, 0L, 0L, TRUE);
2675 }
2676
2677 /**************************************************************************
2678 * waveInStart [WINMM.@]
2679 */
2680 UINT WINAPI waveInStart(HWAVEIN hWaveIn)
2681 {
2682 LPWINE_MLD wmld;
2683
2684 TRACE("(%p);\n", hWaveIn);
2685
2686 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2687 return MMSYSERR_INVALHANDLE;
2688
2689 return MMDRV_Message(wmld, WIDM_START, 0L, 0L, TRUE);
2690 }
2691
2692 /**************************************************************************
2693 * waveInStop [WINMM.@]
2694 */
2695 UINT WINAPI waveInStop(HWAVEIN hWaveIn)
2696 {
2697 LPWINE_MLD wmld;
2698
2699 TRACE("(%p);\n", hWaveIn);
2700
2701 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2702 return MMSYSERR_INVALHANDLE;
2703
2704 return MMDRV_Message(wmld,WIDM_STOP, 0L, 0L, TRUE);
2705 }
2706
2707 /**************************************************************************
2708 * waveInGetPosition [WINMM.@]
2709 */
2710 UINT WINAPI waveInGetPosition(HWAVEIN hWaveIn, LPMMTIME lpTime,
2711 UINT uSize)
2712 {
2713 LPWINE_MLD wmld;
2714
2715 TRACE("(%p, %p, %u);\n", hWaveIn, lpTime, uSize);
2716
2717 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2718 return MMSYSERR_INVALHANDLE;
2719
2720 return MMDRV_Message(wmld, WIDM_GETPOS, (DWORD_PTR)lpTime, uSize, TRUE);
2721 }
2722
2723 /**************************************************************************
2724 * waveInGetID [WINMM.@]
2725 */
2726 UINT WINAPI waveInGetID(HWAVEIN hWaveIn, UINT* lpuDeviceID)
2727 {
2728 LPWINE_MLD wmld;
2729
2730 TRACE("(%p, %p);\n", hWaveIn, lpuDeviceID);
2731
2732 if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
2733
2734 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
2735 return MMSYSERR_INVALHANDLE;
2736
2737 *lpuDeviceID = wmld->uDeviceID;
2738 return MMSYSERR_NOERROR;
2739 }
2740
2741 /**************************************************************************
2742 * waveInMessage [WINMM.@]
2743 */
2744 DWORD WINAPI waveInMessage(HWAVEIN hWaveIn, UINT uMessage,
2745 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
2746 {
2747 LPWINE_MLD wmld;
2748
2749 TRACE("(%p, %u, %ld, %ld)\n", hWaveIn, uMessage, dwParam1, dwParam2);
2750
2751 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL) {
2752 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, TRUE)) != NULL) {
2753 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
2754 }
2755 return MMSYSERR_INVALHANDLE;
2756 }
2757
2758 /* from M$ KB */
2759 if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER))
2760 return MMSYSERR_INVALPARAM;
2761
2762
2763 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
2764 }
2765
2766 struct mm_starter
2767 {
2768 LPTASKCALLBACK cb;
2769 DWORD client;
2770 HANDLE event;
2771 };
2772
2773 static DWORD WINAPI mmTaskRun(void* pmt)
2774 {
2775 struct mm_starter mms;
2776
2777 memcpy(&mms, pmt, sizeof(struct mm_starter));
2778 HeapFree(GetProcessHeap(), 0, pmt);
2779 mms.cb(mms.client);
2780 if (mms.event) SetEvent(mms.event);
2781 return 0;
2782 }
2783
2784 /******************************************************************
2785 * mmTaskCreate (WINMM.@)
2786 */
2787 MMRESULT WINAPI mmTaskCreate(LPTASKCALLBACK cb, HANDLE* ph, DWORD client)
2788 {
2789 HANDLE hThread;
2790 HANDLE hEvent = 0;
2791 struct mm_starter *mms;
2792
2793 mms = HeapAlloc(GetProcessHeap(), 0, sizeof(struct mm_starter));
2794 if (mms == NULL) return TASKERR_OUTOFMEMORY;
2795
2796 mms->cb = cb;
2797 mms->client = client;
2798 if (ph) hEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
2799 mms->event = hEvent;
2800
2801 hThread = CreateThread(0, 0, mmTaskRun, mms, 0, NULL);
2802 if (!hThread) {
2803 HeapFree(GetProcessHeap(), 0, mms);
2804 if (hEvent) CloseHandle(hEvent);
2805 return TASKERR_OUTOFMEMORY;
2806 }
2807 SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);
2808 if (ph) *ph = hEvent;
2809 CloseHandle(hThread);
2810 return 0;
2811 }
2812
2813 /******************************************************************
2814 * mmTaskBlock (WINMM.@)
2815 */
2816 void WINAPI mmTaskBlock(HANDLE tid)
2817 {
2818 MSG msg;
2819
2820 do
2821 {
2822 GetMessageA(&msg, 0, 0, 0);
2823 if (msg.hwnd) DispatchMessageA(&msg);
2824 } while (msg.message != WM_USER);
2825 }
2826
2827 /******************************************************************
2828 * mmTaskSignal (WINMM.@)
2829 */
2830 BOOL WINAPI mmTaskSignal(HANDLE tid)
2831 {
2832 return PostThreadMessageW((DWORD)tid, WM_USER, 0, 0);
2833 }
2834
2835 /******************************************************************
2836 * mmTaskYield (WINMM.@)
2837 */
2838 void WINAPI mmTaskYield(void) {}
2839
2840 /******************************************************************
2841 * mmGetCurrentTask (WINMM.@)
2842 */
2843 HANDLE WINAPI mmGetCurrentTask(void)
2844 {
2845 return (HANDLE)GetCurrentThreadId();
2846 }