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