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