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