Now using notification for detecting when a WAVEHDR has been played
[wine.git] / dlls / winmm / mmsystem.c
blob3a9ddcd6cf3aeb875720bf4e029fc58953a6a002
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
3 /*
4 * MMSYTEM functions
6 * Copyright 1993 Martin Ayotte
7 */
9 /*
10 * Eric POUECH :
11 * 98/9 added Win32 MCI support
12 * 99/4 added mmTask and mmThread functions support
13 * added midiStream support
14 * 99/9 added support for loadable low level drivers
17 /* FIXME: I think there are some segmented vs. linear pointer weirdnesses
18 * and long term pointers to 16 bit space in here
21 #include <string.h>
23 #include "winbase.h"
24 #include "wine/winbase16.h"
25 #include "wownt32.h"
26 #include "heap.h"
27 #include "driver.h"
28 #include "winemm.h"
29 #include "syslevel.h"
30 #include "callback.h"
31 #include "selectors.h"
32 #include "module.h"
33 #include "debugtools.h"
35 DEFAULT_DEBUG_CHANNEL(mmsys)
37 LONG WINAPI DrvDefDriverProc(DWORD dwDevID, HDRVR16 hDrv, WORD wMsg,
38 DWORD dwParam1, DWORD dwParam2);
40 static LPWINE_MM_IDATA lpFirstIData = NULL;
42 static LPWINE_MM_IDATA MULTIMEDIA_GetIDataNoCheck(void)
44 DWORD pid = GetCurrentProcessId();
45 LPWINE_MM_IDATA iData;
47 for (iData = lpFirstIData; iData; iData = iData->lpNextIData) {
48 if (iData->dwThisProcess == pid)
49 break;
51 return iData;
54 /**************************************************************************
55 * MULTIMEDIA_GetIData [internal]
57 LPWINE_MM_IDATA MULTIMEDIA_GetIData(void)
59 LPWINE_MM_IDATA iData = MULTIMEDIA_GetIDataNoCheck();
61 if (!iData) {
62 ERR("IData not found. Suicide !!!\n");
63 ExitProcess(0);
65 return iData;
68 /**************************************************************************
69 * MULTIMEDIA_CreateIData [internal]
71 static BOOL MULTIMEDIA_CreateIData(HINSTANCE hInstDLL)
73 LPWINE_MM_IDATA iData;
75 iData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINE_MM_IDATA));
77 if (!iData)
78 return FALSE;
79 iData->hWinMM32Instance = hInstDLL;
80 iData->dwThisProcess = GetCurrentProcessId();
81 iData->lpNextIData = lpFirstIData;
82 lpFirstIData = iData;
83 InitializeCriticalSection(&iData->cs);
84 return TRUE;
87 /**************************************************************************
88 * MULTIMEDIA_DeleteIData [internal]
90 static void MULTIMEDIA_DeleteIData(void)
92 LPWINE_MM_IDATA iData = MULTIMEDIA_GetIDataNoCheck();
93 LPWINE_MM_IDATA* ppid;
95 if (iData) {
96 for (ppid = &lpFirstIData; *ppid; ppid = &(*ppid)->lpNextIData) {
97 if (*ppid == iData) {
98 *ppid = iData->lpNextIData;
99 break;
102 /* FIXME: should also free content and resources allocated
103 * inside iData */
104 HeapFree(GetProcessHeap(), 0, iData);
108 /**************************************************************************
109 * WINMM_LibMain [EntryPoint]
111 * WINMM DLL entry point
114 BOOL WINAPI WINMM_LibMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID fImpLoad)
116 static BOOL bInitDone = FALSE;
118 TRACE("0x%x 0x%lx %p\n", hInstDLL, fdwReason, fImpLoad);
120 switch (fdwReason) {
121 case DLL_PROCESS_ATTACH:
122 if (!MULTIMEDIA_CreateIData(hInstDLL))
123 return FALSE;
124 if (!bInitDone) { /* to be done only once */
125 if (!MULTIMEDIA_MciInit() || !MMDRV_Init()) {
126 MULTIMEDIA_DeleteIData();
127 return FALSE;
129 bInitDone = TRUE;
131 break;
132 case DLL_PROCESS_DETACH:
133 MULTIMEDIA_DeleteIData();
134 break;
135 case DLL_THREAD_ATTACH:
136 case DLL_THREAD_DETACH:
137 break;
139 return TRUE;
142 /**************************************************************************
143 * MMSYSTEM_LibMain [EntryPoint]
145 * MMSYSTEM DLL entry point
148 BOOL WINAPI MMSYSTEM_LibMain(DWORD fdwReason, HINSTANCE hinstDLL, WORD ds,
149 WORD wHeapSize, DWORD dwReserved1, WORD wReserved2)
151 HANDLE hndl;
152 LPWINE_MM_IDATA iData;
154 TRACE("0x%x 0x%lx\n", hinstDLL, fdwReason);
156 switch (fdwReason) {
157 case DLL_PROCESS_ATTACH:
158 /* need to load WinMM in order to:
159 * - correctly initiates shared variables (MULTIMEDIA_Init())
160 * - correctly creates the per process WINE_MM_IDATA chunk
162 hndl = LoadLibraryA("WINMM.DLL");
164 if (!hndl) {
165 ERR("Could not load sibling WinMM.dll\n");
166 return FALSE;
168 iData = MULTIMEDIA_GetIData();
169 iData->hWinMM16Instance = hinstDLL;
170 iData->h16Module32 = hndl;
171 break;
172 case DLL_PROCESS_DETACH:
173 iData = MULTIMEDIA_GetIData();
174 FreeLibrary(iData->h16Module32);
175 break;
176 case DLL_THREAD_ATTACH:
177 case DLL_THREAD_DETACH:
178 break;
180 return TRUE;
183 /**************************************************************************
184 * MMSYSTEM_WEP [MMSYSTEM.1]
186 int WINAPI MMSYSTEM_WEP(HINSTANCE16 hInstance, WORD wDataSeg,
187 WORD cbHeapSize, LPSTR lpCmdLine)
189 FIXME("STUB: Unloading MMSystem DLL ... hInst=%04X \n", hInstance);
190 return TRUE;
193 void MMSYSTEM_MMTIME32to16(LPMMTIME16 mmt16, const MMTIME* mmt32)
195 mmt16->wType = mmt32->wType;
196 /* layout of rest is the same for 32/16,
197 * Note: mmt16->u is 2 bytes smaller than mmt32->u, which has padding
199 memcpy(&(mmt16->u), &(mmt32->u), sizeof(mmt16->u));
202 void MMSYSTEM_MMTIME16to32(LPMMTIME mmt32, const MMTIME16* mmt16)
204 mmt32->wType = mmt16->wType;
205 /* layout of rest is the same for 32/16,
206 * Note: mmt16->u is 2 bytes smaller than mmt32->u, which has padding
208 memcpy(&(mmt32->u), &(mmt16->u), sizeof(mmt16->u));
211 static HANDLE PlaySound_hThread = 0;
212 static HANDLE PlaySound_hPlayEvent = 0;
213 static HANDLE PlaySound_hReadyEvent = 0;
214 static HANDLE PlaySound_hMiddleEvent = 0;
215 static BOOL PlaySound_Result = FALSE;
216 static int PlaySound_Stop = FALSE;
217 static int PlaySound_Playing = FALSE;
219 static LPCSTR PlaySound_pszSound = NULL;
220 static HMODULE PlaySound_hmod = 0;
221 static DWORD PlaySound_fdwSound = 0;
222 static int PlaySound_Loop = FALSE;
223 static int PlaySound_SearchMode = 0; /* 1 - sndPlaySound search order
224 2 - PlaySound order */
226 static HMMIO get_mmioFromFile(LPCSTR lpszName)
228 return mmioOpenA((LPSTR)lpszName, NULL,
229 MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
232 static HMMIO get_mmioFromProfile(UINT uFlags, LPCSTR lpszName)
234 char str[128];
235 LPSTR ptr;
236 HMMIO hmmio;
238 TRACE("searching in SystemSound List !\n");
239 GetProfileStringA("Sounds", (LPSTR)lpszName, "", str, sizeof(str));
240 if (strlen(str) == 0) {
241 if (uFlags & SND_NODEFAULT) return 0;
242 GetProfileStringA("Sounds", "Default", "", str, sizeof(str));
243 if (strlen(str) == 0) return 0;
245 if ((ptr = (LPSTR)strchr(str, ',')) != NULL) *ptr = '\0';
246 hmmio = get_mmioFromFile(str);
247 if (hmmio == 0) {
248 WARN("can't find SystemSound='%s' !\n", str);
249 return 0;
251 return hmmio;
254 struct playsound_data {
255 HANDLE hEvent;
256 DWORD dwEventCount;
259 static void CALLBACK PlaySound_Callback(HWAVEOUT hwo, UINT uMsg,
260 DWORD dwInstance,
261 DWORD dwParam1, DWORD dwParam2)
263 struct playsound_data* s = (struct playsound_data*)dwInstance;
265 switch (uMsg) {
266 case WOM_OPEN:
267 case WOM_CLOSE:
268 break;
269 case WOM_DONE:
270 InterlockedIncrement(&s->dwEventCount);
271 TRACE("Returning waveHdr=%lx\n", dwParam1);
272 SetEvent(s->hEvent);
273 break;
274 default:
275 ERR("Unknown uMsg=%d\n", uMsg);
279 static void PlaySound_WaitDone(struct playsound_data* s)
281 for (;;) {
282 ResetEvent(s->hEvent);
283 if (InterlockedDecrement(&s->dwEventCount) >= 0) {
284 break;
286 InterlockedIncrement(&s->dwEventCount);
288 WaitForSingleObject(s->hEvent, INFINITE);
292 static BOOL WINAPI proc_PlaySound(LPCSTR lpszSoundName, UINT uFlags)
294 BOOL bRet = FALSE;
295 HMMIO hmmio = 0;
296 MMCKINFO ckMainRIFF;
297 MMCKINFO mmckInfo;
298 LPWAVEFORMATEX lpWaveFormat = NULL;
299 HWAVE hWave = 0;
300 LPWAVEHDR waveHdr = NULL;
301 INT count, bufsize, left, index;
302 struct playsound_data s;
304 s.hEvent = 0;
306 TRACE("SoundName='%s' uFlags=%04X !\n", lpszSoundName, uFlags);
307 if (lpszSoundName == NULL) {
308 TRACE("Stop !\n");
309 return FALSE;
311 if (uFlags & SND_MEMORY) {
312 MMIOINFO mminfo;
313 memset(&mminfo, 0, sizeof(mminfo));
314 mminfo.fccIOProc = FOURCC_MEM;
315 mminfo.pchBuffer = (LPSTR)lpszSoundName;
316 mminfo.cchBuffer = -1;
317 TRACE("Memory sound %p\n", lpszSoundName);
318 hmmio = mmioOpenA(NULL, &mminfo, MMIO_READ);
319 } else {
320 hmmio = 0;
321 if (uFlags & SND_ALIAS)
322 if ((hmmio = get_mmioFromProfile(uFlags, lpszSoundName)) == 0)
323 return FALSE;
325 if (uFlags & SND_FILENAME)
326 if ((hmmio=get_mmioFromFile(lpszSoundName)) == 0) return FALSE;
328 if (PlaySound_SearchMode == 1) {
329 PlaySound_SearchMode = 0;
330 if ((hmmio = get_mmioFromFile(lpszSoundName)) == 0)
331 hmmio = get_mmioFromProfile(uFlags, lpszSoundName);
334 if (PlaySound_SearchMode == 2) {
335 PlaySound_SearchMode = 0;
336 if ((hmmio = get_mmioFromProfile(uFlags | SND_NODEFAULT, lpszSoundName)) == 0)
337 if ((hmmio = get_mmioFromFile(lpszSoundName)) == 0)
338 hmmio = get_mmioFromProfile(uFlags, lpszSoundName);
341 if (hmmio == 0) return FALSE;
343 if (mmioDescend(hmmio, &ckMainRIFF, NULL, 0))
344 goto errCleanUp;
346 TRACE("ParentChunk ckid=%.4s fccType=%.4s cksize=%08lX \n",
347 (LPSTR)&ckMainRIFF.ckid, (LPSTR)&ckMainRIFF.fccType, ckMainRIFF.cksize);
349 if ((ckMainRIFF.ckid != FOURCC_RIFF) ||
350 (ckMainRIFF.fccType != mmioFOURCC('W', 'A', 'V', 'E')))
351 goto errCleanUp;
353 mmckInfo.ckid = mmioFOURCC('f', 'm', 't', ' ');
354 if (mmioDescend(hmmio, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK))
355 goto errCleanUp;
357 TRACE("Chunk Found ckid=%.4s fccType=%.4s cksize=%08lX \n",
358 (LPSTR)&mmckInfo.ckid, (LPSTR)&mmckInfo.fccType, mmckInfo.cksize);
360 lpWaveFormat = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
361 if (mmioRead(hmmio, (HPSTR)lpWaveFormat, mmckInfo.cksize) < sizeof(WAVEFORMAT))
362 goto errCleanUp;
364 TRACE("wFormatTag=%04X !\n", lpWaveFormat->wFormatTag);
365 TRACE("nChannels=%d \n", lpWaveFormat->nChannels);
366 TRACE("nSamplesPerSec=%ld\n", lpWaveFormat->nSamplesPerSec);
367 TRACE("nAvgBytesPerSec=%ld\n", lpWaveFormat->nAvgBytesPerSec);
368 TRACE("nBlockAlign=%d \n", lpWaveFormat->nBlockAlign);
369 TRACE("wBitsPerSample=%u !\n", lpWaveFormat->wBitsPerSample);
371 /* move to end of 'fmt ' chunk */
372 mmioAscend(hmmio, &mmckInfo, 0);
374 mmckInfo.ckid = mmioFOURCC('d', 'a', 't', 'a');
375 if (mmioDescend(hmmio, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK))
376 goto errCleanUp;
378 TRACE("Chunk Found ckid=%.4s fccType=%.4s cksize=%08lX\n",
379 (LPSTR)&mmckInfo.ckid, (LPSTR)&mmckInfo.fccType, mmckInfo.cksize);
381 s.hEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
383 if (waveOutOpen(&hWave, WAVE_MAPPER, lpWaveFormat, (DWORD)PlaySound_Callback,
384 (DWORD)&s, CALLBACK_FUNCTION) != MMSYSERR_NOERROR)
385 goto errCleanUp;
387 /* make it so that 3 buffers per second are needed */
388 bufsize = (((lpWaveFormat->nAvgBytesPerSec / 3) - 1) / lpWaveFormat->nBlockAlign + 1) *
389 lpWaveFormat->nBlockAlign;
390 waveHdr = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(WAVEHDR) + 2 * bufsize);
391 waveHdr[0].lpData = (char*)waveHdr + 2 * sizeof(WAVEHDR);
392 waveHdr[1].lpData = (char*)waveHdr + 2 * sizeof(WAVEHDR) + bufsize;
393 waveHdr[0].dwUser = waveHdr[1].dwUser = 0L;
394 waveHdr[0].dwLoops = waveHdr[1].dwLoops = 0L;
395 waveHdr[0].dwFlags = waveHdr[1].dwFlags = 0L;
396 waveHdr[0].dwBufferLength = waveHdr[1].dwBufferLength = bufsize;
397 if (waveOutPrepareHeader(hWave, &waveHdr[0], sizeof(WAVEHDR)) ||
398 waveOutPrepareHeader(hWave, &waveHdr[1], sizeof(WAVEHDR))) {
399 goto errCleanUp;
402 do {
403 index = 0;
404 left = mmckInfo.cksize;
405 s.dwEventCount = 1L; /* for first buffer */
407 mmioSeek(hmmio, mmckInfo.dwDataOffset, SEEK_SET);
408 while (left) {
409 if (PlaySound_Stop) {
410 PlaySound_Stop = PlaySound_Loop = FALSE;
411 break;
413 count = mmioRead(hmmio, waveHdr[index].lpData, MIN(bufsize, left));
414 if (count < 1) break;
415 left -= count;
416 waveHdr[index].dwBufferLength = count;
417 waveHdr[index].dwFlags &= ~WHDR_DONE;
418 waveOutWrite(hWave, &waveHdr[index], sizeof(WAVEHDR));
419 index ^= 1;
420 PlaySound_WaitDone(&s);
422 bRet = TRUE;
423 } while (PlaySound_Loop);
425 PlaySound_WaitDone(&s);
426 waveOutReset(hWave);
428 waveOutUnprepareHeader(hWave, &waveHdr[0], sizeof(WAVEHDR));
429 waveOutUnprepareHeader(hWave, &waveHdr[1], sizeof(WAVEHDR));
431 errCleanUp:
432 CloseHandle(s.hEvent);
433 HeapFree(GetProcessHeap(), 0, waveHdr);
434 HeapFree(GetProcessHeap(), 0, lpWaveFormat);
435 if (hWave) while (waveOutClose(hWave) == WAVERR_STILLPLAYING) Sleep(100);
436 if (hmmio) mmioClose(hmmio, 0);
438 return bRet;
441 static DWORD WINAPI PlaySound_Thread(LPVOID arg)
443 DWORD res;
445 for (;;) {
446 PlaySound_Playing = FALSE;
447 SetEvent(PlaySound_hReadyEvent);
448 res = WaitForSingleObject(PlaySound_hPlayEvent, INFINITE);
449 ResetEvent(PlaySound_hReadyEvent);
450 SetEvent(PlaySound_hMiddleEvent);
451 if (res == WAIT_FAILED) ExitThread(2);
452 if (res != WAIT_OBJECT_0) continue;
453 PlaySound_Playing = TRUE;
455 if ((PlaySound_fdwSound & SND_RESOURCE) == SND_RESOURCE) {
456 HRSRC hRES;
457 HGLOBAL hGLOB;
458 void* ptr;
460 if ((hRES = FindResourceA(PlaySound_hmod, PlaySound_pszSound, "WAVE")) == 0) {
461 PlaySound_Result = FALSE;
462 continue;
464 if ((hGLOB = LoadResource(PlaySound_hmod, hRES)) == 0) {
465 PlaySound_Result = FALSE;
466 continue;
468 if ((ptr = LockResource(hGLOB)) == NULL) {
469 FreeResource(hGLOB);
470 PlaySound_Result = FALSE;
471 continue;
473 PlaySound_Result = proc_PlaySound(ptr,
474 ((UINT16)PlaySound_fdwSound ^ SND_RESOURCE) | SND_MEMORY);
475 FreeResource(hGLOB);
476 continue;
478 PlaySound_Result = proc_PlaySound(PlaySound_pszSound, (UINT16)PlaySound_fdwSound);
482 /**************************************************************************
483 * PlaySoundA [WINMM.1]
485 BOOL WINAPI PlaySoundA(LPCSTR pszSound, HMODULE hmod, DWORD fdwSound)
487 static LPSTR StrDup = NULL;
489 TRACE("pszSound='%p' hmod=%04X fdwSound=%08lX\n",
490 pszSound, hmod, fdwSound);
492 if (PlaySound_hThread == 0) { /* This is the first time they called us */
493 DWORD id;
494 if ((PlaySound_hReadyEvent = CreateEventA(NULL, TRUE, FALSE, NULL)) == 0)
495 return FALSE;
496 if ((PlaySound_hMiddleEvent = CreateEventA(NULL, FALSE, FALSE, NULL)) == 0)
497 return FALSE;
498 if ((PlaySound_hPlayEvent = CreateEventA(NULL, FALSE, FALSE, NULL)) == 0)
499 return FALSE;
500 if ((PlaySound_hThread = CreateThread(NULL, 0, PlaySound_Thread, 0, 0, &id)) == 0)
501 return FALSE;
504 /* FIXME? I see no difference between SND_WAIT and SND_NOSTOP ! */
505 if ((fdwSound & (SND_NOWAIT | SND_NOSTOP)) && PlaySound_Playing)
506 return FALSE;
508 /* Trying to stop if playing */
509 if (PlaySound_Playing) PlaySound_Stop = TRUE;
511 /* Waiting playing thread to get ready. I think 10 secs is ok & if not then leave*/
512 if (WaitForSingleObject(PlaySound_hReadyEvent, 1000*10) != WAIT_OBJECT_0)
513 return FALSE;
515 if (!pszSound || (fdwSound & SND_PURGE))
516 return FALSE; /* We stoped playing so leaving */
518 if (PlaySound_SearchMode != 1) PlaySound_SearchMode = 2;
519 if (!(fdwSound & SND_ASYNC)) {
520 if (fdwSound & SND_LOOP)
521 return FALSE;
522 PlaySound_pszSound = pszSound;
523 PlaySound_hmod = hmod;
524 PlaySound_fdwSound = fdwSound;
525 PlaySound_Result = FALSE;
526 SetEvent(PlaySound_hPlayEvent);
527 if (WaitForSingleObject(PlaySound_hMiddleEvent, INFINITE) != WAIT_OBJECT_0)
528 return FALSE;
529 if (WaitForSingleObject(PlaySound_hReadyEvent, INFINITE) != WAIT_OBJECT_0)
530 return FALSE;
531 return PlaySound_Result;
532 } else {
533 PlaySound_hmod = hmod;
534 PlaySound_fdwSound = fdwSound;
535 PlaySound_Result = FALSE;
536 if (StrDup) {
537 HeapFree(GetProcessHeap(), 0, StrDup);
538 StrDup = NULL;
540 if (!((fdwSound & SND_MEMORY) || ((fdwSound & SND_RESOURCE) &&
541 !((DWORD)pszSound >> 16)) || !pszSound)) {
542 StrDup = HEAP_strdupA(GetProcessHeap(), 0,pszSound);
543 PlaySound_pszSound = StrDup;
544 } else PlaySound_pszSound = pszSound;
545 PlaySound_Loop = fdwSound & SND_LOOP;
546 SetEvent(PlaySound_hPlayEvent);
547 ResetEvent(PlaySound_hMiddleEvent);
548 return TRUE;
550 return FALSE;
553 /**************************************************************************
554 * PlaySoundW [WINMM.18]
556 BOOL WINAPI PlaySoundW(LPCWSTR pszSound, HMODULE hmod, DWORD fdwSound)
558 LPSTR pszSoundA;
559 BOOL bSound;
561 if (!((fdwSound & SND_MEMORY) || ((fdwSound & SND_RESOURCE) &&
562 !((DWORD)pszSound >> 16)) || !pszSound)) {
563 pszSoundA = HEAP_strdupWtoA(GetProcessHeap(), 0,pszSound);
564 bSound = PlaySoundA(pszSoundA, hmod, fdwSound);
565 HeapFree(GetProcessHeap(), 0,pszSoundA);
566 } else
567 bSound = PlaySoundA((LPCSTR)pszSound, hmod, fdwSound);
569 return bSound;
572 /**************************************************************************
573 * PlaySound16 [MMSYSTEM.3]
575 BOOL16 WINAPI PlaySound16(LPCSTR pszSound, HMODULE16 hmod, DWORD fdwSound)
577 BOOL16 retv;
579 SYSLEVEL_ReleaseWin16Lock();
580 retv = PlaySoundA( pszSound, hmod, fdwSound );
581 SYSLEVEL_RestoreWin16Lock();
583 return retv;
586 /**************************************************************************
587 * sndPlaySoundA [WINMM135]
589 BOOL WINAPI sndPlaySoundA(LPCSTR lpszSoundName, UINT uFlags)
591 PlaySound_SearchMode = 1;
592 return PlaySoundA(lpszSoundName, 0, uFlags);
595 /**************************************************************************
596 * sndPlaySoundW [WINMM.136]
598 BOOL WINAPI sndPlaySoundW(LPCWSTR lpszSoundName, UINT uFlags)
600 PlaySound_SearchMode = 1;
601 return PlaySoundW(lpszSoundName, 0, uFlags);
604 /**************************************************************************
605 * sndPlaySound16 [MMSYSTEM.2]
607 BOOL16 WINAPI sndPlaySound16(LPCSTR lpszSoundName, UINT16 uFlags)
609 BOOL16 retv;
611 SYSLEVEL_ReleaseWin16Lock();
612 retv = sndPlaySoundA( lpszSoundName, uFlags );
613 SYSLEVEL_RestoreWin16Lock();
615 return retv;
619 /**************************************************************************
620 * mmsystemGetVersion [WINMM.134]
622 UINT WINAPI mmsystemGetVersion(void)
624 return mmsystemGetVersion16();
627 /**************************************************************************
628 * mmsystemGetVersion [MMSYSTEM.5]
629 * return value borrowed from Win95 winmm.dll ;)
631 UINT16 WINAPI mmsystemGetVersion16(void)
633 TRACE("3.10 (Win95?)\n");
634 return 0x030a;
637 /**************************************************************************
638 * DriverProc [MMSYSTEM.6]
640 LRESULT WINAPI DriverProc16(DWORD dwDevID, HDRVR16 hDrv, WORD wMsg,
641 DWORD dwParam1, DWORD dwParam2)
643 TRACE("dwDevID=%08lx hDrv=%04x wMsg=%04x dwParam1=%08lx dwParam2=%08lx\n",
644 dwDevID, hDrv, wMsg, dwParam1, dwParam2);
646 return DrvDefDriverProc(dwDevID, hDrv, wMsg, dwParam1, dwParam2);
649 /**************************************************************************
650 * DriverCallback [MMSYSTEM.31]
652 BOOL WINAPI DriverCallback(DWORD dwCallBack, UINT uFlags, HDRVR hDev,
653 UINT wMsg, DWORD dwUser, DWORD dwParam1,
654 DWORD dwParam2)
656 TRACE("(%08lX, %04X, %04X, %04X, %08lX, %08lX, %08lX); !\n",
657 dwCallBack, uFlags, hDev, wMsg, dwUser, dwParam1, dwParam2);
659 switch (uFlags & DCB_TYPEMASK) {
660 case DCB_NULL:
661 TRACE("Null !\n");
662 if (dwCallBack)
663 WARN("uFlags=%04X has null DCB value, but dwCallBack=%08lX is not null !\n", uFlags, dwCallBack);
664 break;
665 case DCB_WINDOW:
666 TRACE("Window(%04lX) handle=%04X!\n", dwCallBack, hDev);
667 if (!IsWindow(dwCallBack))
668 return FALSE;
669 Callout.PostMessageA((HWND16)dwCallBack, wMsg, hDev, dwParam1);
670 break;
671 case DCB_TASK: /* aka DCB_THREAD */
672 TRACE("Task(%04lx) !\n", dwCallBack);
673 Callout.PostThreadMessageA(dwCallBack, wMsg, hDev, dwParam1);
674 break;
675 case DCB_FUNCTION:
676 TRACE("Function (32 bit) !\n");
677 ((LPDRVCALLBACK)dwCallBack)(hDev, wMsg, dwUser, dwParam1, dwParam2);
678 break;
679 case DCB_EVENT:
680 TRACE("Event(%08lx) !\n", dwCallBack);
681 SetEvent((HANDLE)dwCallBack);
682 break;
683 case 6: /* I would dub it DCB_MMTHREADSIGNAL */
684 /* this is an undocumented DCB_ value used for mmThreads
685 * loword of dwCallBack contains the handle of the lpMMThd block
686 * which dwSignalCount has to be incremented
689 WINE_MMTHREAD* lpMMThd = (WINE_MMTHREAD*)PTR_SEG_OFF_TO_LIN(LOWORD(dwCallBack), 0);
691 TRACE("mmThread (%04x, %p) !\n", LOWORD(dwCallBack), lpMMThd);
692 /* same as mmThreadSignal16 */
693 InterlockedIncrement(&lpMMThd->dwSignalCount);
694 SetEvent(lpMMThd->hEvent);
695 /* some other stuff on lpMMThd->hVxD */
697 break;
698 #if 0
699 case 4:
700 /* this is an undocumented DCB_ value for... I don't know */
701 break;
702 #endif
703 default:
704 WARN("Unknown callback type %d\n", uFlags & DCB_TYPEMASK);
705 return FALSE;
707 TRACE("Done\n");
708 return TRUE;
711 /**************************************************************************
712 * DriverCallback [MMSYSTEM.31]
714 BOOL16 WINAPI DriverCallback16(DWORD dwCallBack, UINT16 uFlags, HDRVR16 hDev,
715 WORD wMsg, DWORD dwUser, DWORD dwParam1,
716 DWORD dwParam2)
718 return DriverCallback(dwCallBack, uFlags, hDev, wMsg, dwUser, dwParam1, dwParam2);
721 /**************************************************************************
722 * Mixer devices. New to Win95
725 /**************************************************************************
726 * find out the real mixer ID depending on hmix (depends on dwFlags)
728 static LPWINE_MIXER MIXER_GetDev(HMIXEROBJ hmix, DWORD dwFlags)
730 LPWINE_MIXER lpwm = NULL;
732 switch (dwFlags & 0xF0000000ul) {
733 case MIXER_OBJECTF_MIXER:
734 lpwm = (LPWINE_MIXER)MMDRV_Get(hmix, MMDRV_MIXER, TRUE);
735 break;
736 case MIXER_OBJECTF_HMIXER:
737 lpwm = (LPWINE_MIXER)MMDRV_Get(hmix, MMDRV_MIXER, FALSE);
738 break;
739 case MIXER_OBJECTF_WAVEOUT:
740 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEOUT, TRUE, MMDRV_MIXER);
741 break;
742 case MIXER_OBJECTF_HWAVEOUT:
743 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEOUT, FALSE, MMDRV_MIXER);
744 break;
745 case MIXER_OBJECTF_WAVEIN:
746 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEIN, TRUE, MMDRV_MIXER);
747 break;
748 case MIXER_OBJECTF_HWAVEIN:
749 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_WAVEIN, FALSE, MMDRV_MIXER);
750 break;
751 case MIXER_OBJECTF_MIDIOUT:
752 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIOUT, TRUE, MMDRV_MIXER);
753 break;
754 case MIXER_OBJECTF_HMIDIOUT:
755 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIOUT, FALSE, MMDRV_MIXER);
756 break;
757 case MIXER_OBJECTF_MIDIIN:
758 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIIN, TRUE, MMDRV_MIXER);
759 break;
760 case MIXER_OBJECTF_HMIDIIN:
761 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_MIDIIN, FALSE, MMDRV_MIXER);
762 break;
763 case MIXER_OBJECTF_AUX:
764 lpwm = (LPWINE_MIXER)MMDRV_GetRelated(hmix, MMDRV_AUX, TRUE, MMDRV_MIXER);
765 break;
766 default:
767 FIXME("Unsupported flag (%08lx)\n", dwFlags & 0xF0000000ul);
768 break;
770 return lpwm;
773 /**************************************************************************
774 * mixerGetNumDevs [WINMM.108]
776 UINT WINAPI mixerGetNumDevs(void)
778 return MMDRV_GetNum(MMDRV_MIXER);
781 /**************************************************************************
782 * mixerGetNumDevs [MMSYSTEM.800]
784 UINT16 WINAPI mixerGetNumDevs16(void)
786 return MMDRV_GetNum(MMDRV_MIXER);
789 /**************************************************************************
790 * mixerGetDevCapsA [WINMM.101]
792 UINT WINAPI mixerGetDevCapsA(UINT devid, LPMIXERCAPSA mixcaps, UINT size)
794 LPWINE_MLD wmld;
796 if ((wmld = MMDRV_Get(devid, MMDRV_MIXER, TRUE)) == NULL)
797 return MMSYSERR_BADDEVICEID;
799 return MMDRV_Message(wmld, MXDM_GETDEVCAPS, (DWORD)mixcaps, size, TRUE);
802 /**************************************************************************
803 * mixerGetDevCapsW [WINMM.102]
805 UINT WINAPI mixerGetDevCapsW(UINT devid, LPMIXERCAPSW mixcaps, UINT size)
807 MIXERCAPSA micA;
808 UINT ret = mixerGetDevCapsA(devid, &micA, sizeof(micA));
810 if (ret == MMSYSERR_NOERROR) {
811 mixcaps->wMid = micA.wMid;
812 mixcaps->wPid = micA.wPid;
813 mixcaps->vDriverVersion = micA.vDriverVersion;
814 lstrcpyAtoW(mixcaps->szPname, micA.szPname);
815 mixcaps->fdwSupport = micA.fdwSupport;
816 mixcaps->cDestinations = micA.cDestinations;
818 return ret;
821 /**************************************************************************
822 * mixerGetDevCaps [MMSYSTEM.801]
824 UINT16 WINAPI mixerGetDevCaps16(UINT16 devid, LPMIXERCAPS16 mixcaps,
825 UINT16 size)
827 MIXERCAPSA micA;
828 UINT ret = mixerGetDevCapsA(devid, &micA, sizeof(micA));
830 if (ret == MMSYSERR_NOERROR) {
831 mixcaps->wMid = micA.wMid;
832 mixcaps->wPid = micA.wPid;
833 mixcaps->vDriverVersion = micA.vDriverVersion;
834 strcpy(mixcaps->szPname, micA.szPname);
835 mixcaps->fdwSupport = micA.fdwSupport;
836 mixcaps->cDestinations = micA.cDestinations;
838 return ret;
841 static UINT MMSYSTEM_mixerOpen(LPHMIXER lphMix, UINT uDeviceID, DWORD dwCallback,
842 DWORD dwInstance, DWORD fdwOpen, BOOL bFrom32)
844 HANDLE hMix;
845 LPWINE_MLD wmld;
846 DWORD dwRet = 0;
847 MIXEROPENDESC mod;
849 TRACE("(%p, %d, %08lx, %08lx, %08lx)\n",
850 lphMix, uDeviceID, dwCallback, dwInstance, fdwOpen);
852 wmld = MMDRV_Alloc(sizeof(WINE_MIXER), MMDRV_MIXER, &hMix, &fdwOpen,
853 &dwCallback, &dwInstance, bFrom32);
855 wmld->uDeviceID = uDeviceID;
856 mod.hmx = hMix;
857 mod.dwCallback = dwCallback;
858 mod.dwInstance = dwInstance;
860 dwRet = MMDRV_Open(wmld, MXDM_OPEN, (DWORD)&mod, fdwOpen);
862 if (dwRet != MMSYSERR_NOERROR) {
863 MMDRV_Free(hMix, wmld);
864 hMix = 0;
866 if (lphMix) *lphMix = hMix;
867 TRACE("=> %ld hMixer=%04x\n", dwRet, hMix);
869 return dwRet;
872 /**************************************************************************
873 * mixerOpen [WINMM.110]
875 UINT WINAPI mixerOpen(LPHMIXER lphMix, UINT uDeviceID, DWORD dwCallback,
876 DWORD dwInstance, DWORD fdwOpen)
878 return MMSYSTEM_mixerOpen(lphMix, uDeviceID,
879 dwCallback, dwInstance, fdwOpen, TRUE);
882 /**************************************************************************
883 * mixerOpen [MMSYSTEM.803]
885 UINT16 WINAPI mixerOpen16(LPHMIXER16 lphmix, UINT16 uDeviceID, DWORD dwCallback,
886 DWORD dwInstance, DWORD fdwOpen)
888 HMIXER hmix;
889 UINT ret;
891 ret = MMSYSTEM_mixerOpen(&hmix, uDeviceID,
892 dwCallback, dwInstance, fdwOpen, FALSE);
893 if (lphmix) *lphmix = hmix;
894 return ret;
897 /**************************************************************************
898 * mixerClose [WINMM.98]
900 UINT WINAPI mixerClose(HMIXER hMix)
902 LPWINE_MLD wmld;
903 DWORD dwRet;
905 TRACE("(%04x)\n", hMix);
907 if ((wmld = MMDRV_Get(hMix, MMDRV_MIXER, FALSE)) == NULL) return MMSYSERR_INVALHANDLE;
909 dwRet = MMDRV_Close(wmld, MXDM_CLOSE);
910 MMDRV_Free(hMix, wmld);
912 return dwRet;
915 /**************************************************************************
916 * mixerClose [MMSYSTEM.803]
918 UINT16 WINAPI mixerClose16(HMIXER16 hMix)
920 return mixerClose(hMix);
923 /**************************************************************************
924 * mixerGetID [WINMM.103]
926 UINT WINAPI mixerGetID(HMIXEROBJ hmix, LPUINT lpid, DWORD fdwID)
928 LPWINE_MIXER lpwm;
930 TRACE("(%04x %p %08lx)\n", hmix, lpid, fdwID);
932 if ((lpwm = MIXER_GetDev(hmix, fdwID)) == NULL) {
933 return MMSYSERR_INVALHANDLE;
936 if (lpid)
937 *lpid = lpwm->mld.uDeviceID;
939 return MMSYSERR_NOERROR;
942 /**************************************************************************
943 * mixerGetID
945 UINT16 WINAPI mixerGetID16(HMIXEROBJ16 hmix, LPUINT16 lpid, DWORD fdwID)
947 UINT xid;
948 UINT ret = mixerGetID(hmix, &xid, fdwID);
950 if (lpid)
951 *lpid = xid;
952 return ret;
955 /**************************************************************************
956 * mixerGetControlDetailsA [WINMM.99]
958 UINT WINAPI mixerGetControlDetailsA(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcdA,
959 DWORD fdwDetails)
961 LPWINE_MIXER lpwm;
963 TRACE("(%04x, %p, %08lx)\n", hmix, lpmcdA, fdwDetails);
965 if ((lpwm = MIXER_GetDev(hmix, fdwDetails)) == NULL)
966 return MMSYSERR_INVALHANDLE;
968 if (lpmcdA == NULL || lpmcdA->cbStruct != sizeof(*lpmcdA))
969 return MMSYSERR_INVALPARAM;
971 return MMDRV_Message(&lpwm->mld, MXDM_GETCONTROLDETAILS, (DWORD)lpmcdA,
972 fdwDetails, TRUE);
975 /**************************************************************************
976 * mixerGetControlDetailsW [WINMM.100]
978 UINT WINAPI mixerGetControlDetailsW(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcd, DWORD fdwDetails)
980 DWORD ret = MMSYSERR_NOTENABLED;
982 TRACE("(%04x, %p, %08lx)\n", hmix, lpmcd, fdwDetails);
984 if (lpmcd == NULL || lpmcd->cbStruct != sizeof(*lpmcd))
985 return MMSYSERR_INVALPARAM;
987 switch (fdwDetails & MIXER_GETCONTROLDETAILSF_QUERYMASK) {
988 case MIXER_GETCONTROLDETAILSF_VALUE:
989 /* can savely use W structure as it is, no string inside */
990 ret = mixerGetControlDetailsA(hmix, lpmcd, fdwDetails);
991 break;
992 case MIXER_GETCONTROLDETAILSF_LISTTEXT:
994 LPVOID paDetailsW = lpmcd->paDetails;
995 int size = MAX(1, lpmcd->cChannels) * sizeof(MIXERCONTROLDETAILS_LISTTEXTA);
997 if (lpmcd->u.cMultipleItems != 0 && lpmcd->u.cMultipleItems != lpmcd->u.hwndOwner) {
998 size *= lpmcd->u.cMultipleItems;
1000 lpmcd->paDetails = HeapAlloc(GetProcessHeap(), 0, size);
1001 /* set up lpmcd->paDetails */
1002 ret = mixerGetControlDetailsA(hmix, lpmcd, fdwDetails);
1003 /* copy from lpmcd->paDetails back to paDetailsW; */
1004 HeapFree(GetProcessHeap(), 0, lpmcd->paDetails);
1005 lpmcd->paDetails = paDetailsW;
1007 break;
1008 default:
1009 ERR("Unsupported fdwDetails=0x%08lx\n", fdwDetails);
1012 return ret;
1015 /**************************************************************************
1016 * mixerGetControlDetails [MMSYSTEM.808]
1018 UINT16 WINAPI mixerGetControlDetails16(HMIXEROBJ16 hmix,
1019 LPMIXERCONTROLDETAILS16 lpmcd,
1020 DWORD fdwDetails)
1022 DWORD ret = MMSYSERR_NOTENABLED;
1023 SEGPTR sppaDetails;
1025 TRACE("(%04x, %p, %08lx)\n", hmix, lpmcd, fdwDetails);
1027 if (lpmcd == NULL || lpmcd->cbStruct != sizeof(*lpmcd))
1028 return MMSYSERR_INVALPARAM;
1030 sppaDetails = (SEGPTR)lpmcd->paDetails;
1031 lpmcd->paDetails = PTR_SEG_TO_LIN(sppaDetails);
1032 ret = mixerGetControlDetailsA(hmix, (LPMIXERCONTROLDETAILS)lpmcd, fdwDetails);
1033 lpmcd->paDetails = (LPVOID)sppaDetails;
1035 return ret;
1038 /**************************************************************************
1039 * mixerGetLineControlsA [WINMM.104]
1041 UINT WINAPI mixerGetLineControlsA(HMIXEROBJ hmix, LPMIXERLINECONTROLSA lpmlcA,
1042 DWORD fdwControls)
1044 LPWINE_MIXER lpwm;
1046 TRACE("(%04x, %p, %08lx)\n", hmix, lpmlcA, fdwControls);
1048 if ((lpwm = MIXER_GetDev(hmix, fdwControls)) == NULL)
1049 return MMSYSERR_INVALHANDLE;
1051 if (lpmlcA == NULL || lpmlcA->cbStruct != sizeof(*lpmlcA))
1052 return MMSYSERR_INVALPARAM;
1054 return MMDRV_Message(&lpwm->mld, MXDM_GETLINECONTROLS, (DWORD)lpmlcA,
1055 fdwControls, TRUE);
1058 /**************************************************************************
1059 * mixerGetLineControlsW [WINMM.105]
1061 UINT WINAPI mixerGetLineControlsW(HMIXEROBJ hmix, LPMIXERLINECONTROLSW lpmlcW,
1062 DWORD fdwControls)
1064 MIXERLINECONTROLSA mlcA;
1065 DWORD ret;
1066 int i;
1068 TRACE("(%04x, %p, %08lx)\n", hmix, lpmlcW, fdwControls);
1070 if (lpmlcW == NULL || lpmlcW->cbStruct != sizeof(*lpmlcW) ||
1071 lpmlcW->cbmxctrl != sizeof(MIXERCONTROLW))
1072 return MMSYSERR_INVALPARAM;
1074 mlcA.cbStruct = sizeof(mlcA);
1075 mlcA.dwLineID = lpmlcW->dwLineID;
1076 mlcA.u.dwControlID = lpmlcW->u.dwControlID;
1077 mlcA.u.dwControlType = lpmlcW->u.dwControlType;
1078 mlcA.cControls = lpmlcW->cControls;
1079 mlcA.cbmxctrl = sizeof(MIXERCONTROLA);
1080 mlcA.pamxctrl = HeapAlloc(GetProcessHeap(), 0,
1081 mlcA.cControls * mlcA.cbmxctrl);
1083 ret = mixerGetLineControlsA(hmix, &mlcA, fdwControls);
1085 if (ret == MMSYSERR_NOERROR) {
1086 lpmlcW->dwLineID = mlcA.dwLineID;
1087 lpmlcW->u.dwControlID = mlcA.u.dwControlID;
1088 lpmlcW->u.dwControlType = mlcA.u.dwControlType;
1089 lpmlcW->cControls = mlcA.cControls;
1091 for (i = 0; i < mlcA.cControls; i++) {
1092 lpmlcW->pamxctrl[i].cbStruct = sizeof(MIXERCONTROLW);
1093 lpmlcW->pamxctrl[i].dwControlID = mlcA.pamxctrl[i].dwControlID;
1094 lpmlcW->pamxctrl[i].dwControlType = mlcA.pamxctrl[i].dwControlType;
1095 lpmlcW->pamxctrl[i].fdwControl = mlcA.pamxctrl[i].fdwControl;
1096 lpmlcW->pamxctrl[i].cMultipleItems = mlcA.pamxctrl[i].cMultipleItems;
1097 lstrcpyAtoW(lpmlcW->pamxctrl[i].szShortName,
1098 mlcA.pamxctrl[i].szShortName);
1099 lstrcpyAtoW(lpmlcW->pamxctrl[i].szName, mlcA.pamxctrl[i].szName);
1100 /* sizeof(lpmlcW->pamxctrl[i].Bounds) ==
1101 * sizeof(mlcA.pamxctrl[i].Bounds) */
1102 memcpy(&lpmlcW->pamxctrl[i].Bounds, &mlcA.pamxctrl[i].Bounds,
1103 sizeof(mlcA.pamxctrl[i].Bounds));
1104 /* sizeof(lpmlcW->pamxctrl[i].Metrics) ==
1105 * sizeof(mlcA.pamxctrl[i].Metrics) */
1106 memcpy(&lpmlcW->pamxctrl[i].Metrics, &mlcA.pamxctrl[i].Metrics,
1107 sizeof(mlcA.pamxctrl[i].Metrics));
1111 HeapFree(GetProcessHeap(), 0, mlcA.pamxctrl);
1113 return ret;
1116 /**************************************************************************
1117 * mixerGetLineControls [MMSYSTEM.807]
1119 UINT16 WINAPI mixerGetLineControls16(HMIXEROBJ16 hmix,
1120 LPMIXERLINECONTROLS16 lpmlc16,
1121 DWORD fdwControls)
1123 MIXERLINECONTROLSA mlcA;
1124 DWORD ret;
1125 int i;
1126 LPMIXERCONTROL16 lpmc16;
1128 TRACE("(%04x, %p, %08lx)\n", hmix, lpmlc16, fdwControls);
1130 if (lpmlc16 == NULL || lpmlc16->cbStruct != sizeof(*lpmlc16) ||
1131 lpmlc16->cbmxctrl != sizeof(MIXERCONTROL16))
1132 return MMSYSERR_INVALPARAM;
1134 mlcA.cbStruct = sizeof(mlcA);
1135 mlcA.dwLineID = lpmlc16->dwLineID;
1136 mlcA.u.dwControlID = lpmlc16->u.dwControlID;
1137 mlcA.u.dwControlType = lpmlc16->u.dwControlType;
1138 mlcA.cControls = lpmlc16->cControls;
1139 mlcA.cbmxctrl = sizeof(MIXERCONTROLA);
1140 mlcA.pamxctrl = HeapAlloc(GetProcessHeap(), 0,
1141 mlcA.cControls * mlcA.cbmxctrl);
1143 ret = mixerGetLineControlsA(hmix, &mlcA, fdwControls);
1145 if (ret == MMSYSERR_NOERROR) {
1146 lpmlc16->dwLineID = mlcA.dwLineID;
1147 lpmlc16->u.dwControlID = mlcA.u.dwControlID;
1148 lpmlc16->u.dwControlType = mlcA.u.dwControlType;
1149 lpmlc16->cControls = mlcA.cControls;
1151 lpmc16 = PTR_SEG_TO_LIN(lpmlc16->pamxctrl);
1153 for (i = 0; i < mlcA.cControls; i++) {
1154 lpmc16[i].cbStruct = sizeof(MIXERCONTROL16);
1155 lpmc16[i].dwControlID = mlcA.pamxctrl[i].dwControlID;
1156 lpmc16[i].dwControlType = mlcA.pamxctrl[i].dwControlType;
1157 lpmc16[i].fdwControl = mlcA.pamxctrl[i].fdwControl;
1158 lpmc16[i].cMultipleItems = mlcA.pamxctrl[i].cMultipleItems;
1159 strcpy(lpmc16[i].szShortName, mlcA.pamxctrl[i].szShortName);
1160 strcpy(lpmc16[i].szName, mlcA.pamxctrl[i].szName);
1161 /* sizeof(lpmc16[i].Bounds) == sizeof(mlcA.pamxctrl[i].Bounds) */
1162 memcpy(&lpmc16[i].Bounds, &mlcA.pamxctrl[i].Bounds,
1163 sizeof(mlcA.pamxctrl[i].Bounds));
1164 /* sizeof(lpmc16[i].Metrics) == sizeof(mlcA.pamxctrl[i].Metrics) */
1165 memcpy(&lpmc16[i].Metrics, &mlcA.pamxctrl[i].Metrics,
1166 sizeof(mlcA.pamxctrl[i].Metrics));
1170 HeapFree(GetProcessHeap(), 0, mlcA.pamxctrl);
1172 return ret;
1175 /**************************************************************************
1176 * mixerGetLineInfoA [WINMM.106]
1178 UINT WINAPI mixerGetLineInfoA(HMIXEROBJ hmix, LPMIXERLINEA lpmliW, DWORD fdwInfo)
1180 LPWINE_MIXER lpwm;
1182 TRACE("(%04x, %p, %08lx)\n", hmix, lpmliW, fdwInfo);
1184 if ((lpwm = MIXER_GetDev(hmix, fdwInfo)) == NULL)
1185 return MMSYSERR_INVALHANDLE;
1187 return MMDRV_Message(&lpwm->mld, MXDM_GETLINEINFO, (DWORD)lpmliW,
1188 fdwInfo, TRUE);
1191 /**************************************************************************
1192 * mixerGetLineInfoW [WINMM.107]
1194 UINT WINAPI mixerGetLineInfoW(HMIXEROBJ hmix, LPMIXERLINEW lpmliW,
1195 DWORD fdwInfo)
1197 MIXERLINEA mliA;
1198 UINT ret;
1200 TRACE("(%04x, %p, %08lx)\n", hmix, lpmliW, fdwInfo);
1202 if (lpmliW == NULL || lpmliW->cbStruct != sizeof(*lpmliW))
1203 return MMSYSERR_INVALPARAM;
1205 mliA.cbStruct = sizeof(mliA);
1206 switch (fdwInfo & MIXER_GETLINEINFOF_QUERYMASK) {
1207 case MIXER_GETLINEINFOF_COMPONENTTYPE:
1208 mliA.dwComponentType = lpmliW->dwComponentType;
1209 break;
1210 case MIXER_GETLINEINFOF_DESTINATION:
1211 mliA.dwDestination = lpmliW->dwDestination;
1212 break;
1213 case MIXER_GETLINEINFOF_LINEID:
1214 mliA.dwLineID = lpmliW->dwLineID;
1215 break;
1216 case MIXER_GETLINEINFOF_SOURCE:
1217 mliA.dwDestination = lpmliW->dwDestination;
1218 mliA.dwSource = lpmliW->dwSource;
1219 break;
1220 case MIXER_GETLINEINFOF_TARGETTYPE:
1221 mliA.Target.dwType = lpmliW->Target.dwType;
1222 mliA.Target.wMid = lpmliW->Target.wMid;
1223 mliA.Target.wPid = lpmliW->Target.wPid;
1224 mliA.Target.vDriverVersion = lpmliW->Target.vDriverVersion;
1225 lstrcpyWtoA(mliA.Target.szPname, lpmliW->Target.szPname);
1226 break;
1227 default:
1228 FIXME("Unsupported fdwControls=0x%08lx\n", fdwInfo);
1231 ret = mixerGetLineInfoA(hmix, &mliA, fdwInfo);
1233 lpmliW->dwDestination = mliA.dwDestination;
1234 lpmliW->dwSource = mliA.dwSource;
1235 lpmliW->dwLineID = mliA.dwLineID;
1236 lpmliW->fdwLine = mliA.fdwLine;
1237 lpmliW->dwUser = mliA.dwUser;
1238 lpmliW->dwComponentType = mliA.dwComponentType;
1239 lpmliW->cChannels = mliA.cChannels;
1240 lpmliW->cConnections = mliA.cConnections;
1241 lpmliW->cControls = mliA.cControls;
1242 lstrcpyAtoW(lpmliW->szShortName, mliA.szShortName);
1243 lstrcpyAtoW(lpmliW->szName, mliA.szName);
1244 lpmliW->Target.dwType = mliA.Target.dwType;
1245 lpmliW->Target.dwDeviceID = mliA.Target.dwDeviceID;
1246 lpmliW->Target.wMid = mliA.Target.wMid;
1247 lpmliW->Target.wPid = mliA.Target.wPid;
1248 lpmliW->Target.vDriverVersion = mliA.Target.vDriverVersion;
1249 lstrcpyAtoW(lpmliW->Target.szPname, mliA.Target.szPname);
1251 return ret;
1254 /**************************************************************************
1255 * mixerGetLineInfo [MMSYSTEM.805]
1257 UINT16 WINAPI mixerGetLineInfo16(HMIXEROBJ16 hmix, LPMIXERLINE16 lpmli16,
1258 DWORD fdwInfo)
1260 MIXERLINEA mliA;
1261 UINT ret;
1263 TRACE("(%04x, %p, %08lx)\n", hmix, lpmli16, fdwInfo);
1265 if (lpmli16 == NULL || lpmli16->cbStruct != sizeof(*lpmli16))
1266 return MMSYSERR_INVALPARAM;
1268 mliA.cbStruct = sizeof(mliA);
1269 switch (fdwInfo & MIXER_GETLINEINFOF_QUERYMASK) {
1270 case MIXER_GETLINEINFOF_COMPONENTTYPE:
1271 mliA.dwComponentType = lpmli16->dwComponentType;
1272 break;
1273 case MIXER_GETLINEINFOF_DESTINATION:
1274 mliA.dwDestination = lpmli16->dwDestination;
1275 break;
1276 case MIXER_GETLINEINFOF_LINEID:
1277 mliA.dwLineID = lpmli16->dwLineID;
1278 break;
1279 case MIXER_GETLINEINFOF_SOURCE:
1280 mliA.dwDestination = lpmli16->dwDestination;
1281 mliA.dwSource = lpmli16->dwSource;
1282 break;
1283 case MIXER_GETLINEINFOF_TARGETTYPE:
1284 mliA.Target.dwType = lpmli16->Target.dwType;
1285 mliA.Target.wMid = lpmli16->Target.wMid;
1286 mliA.Target.wPid = lpmli16->Target.wPid;
1287 mliA.Target.vDriverVersion = lpmli16->Target.vDriverVersion;
1288 strcpy(mliA.Target.szPname, lpmli16->Target.szPname);
1289 break;
1290 default:
1291 FIXME("Unsupported fdwControls=0x%08lx\n", fdwInfo);
1294 ret = mixerGetLineInfoA(hmix, &mliA, fdwInfo);
1296 lpmli16->dwDestination = mliA.dwDestination;
1297 lpmli16->dwSource = mliA.dwSource;
1298 lpmli16->dwLineID = mliA.dwLineID;
1299 lpmli16->fdwLine = mliA.fdwLine;
1300 lpmli16->dwUser = mliA.dwUser;
1301 lpmli16->dwComponentType = mliA.dwComponentType;
1302 lpmli16->cChannels = mliA.cChannels;
1303 lpmli16->cConnections = mliA.cConnections;
1304 lpmli16->cControls = mliA.cControls;
1305 strcpy(lpmli16->szShortName, mliA.szShortName);
1306 strcpy(lpmli16->szName, mliA.szName);
1307 lpmli16->Target.dwType = mliA.Target.dwType;
1308 lpmli16->Target.dwDeviceID = mliA.Target.dwDeviceID;
1309 lpmli16->Target.wMid = mliA.Target.wMid;
1310 lpmli16->Target.wPid = mliA.Target.wPid;
1311 lpmli16->Target.vDriverVersion = mliA.Target.vDriverVersion;
1312 strcpy(lpmli16->Target.szPname, mliA.Target.szPname);
1314 return ret;
1317 /**************************************************************************
1318 * mixerSetControlDetails [WINMM.111]
1320 UINT WINAPI mixerSetControlDetails(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcdA,
1321 DWORD fdwDetails)
1323 LPWINE_MIXER lpwm;
1325 TRACE("(%04x, %p, %08lx)\n", hmix, lpmcdA, fdwDetails);
1327 if ((lpwm = MIXER_GetDev(hmix, fdwDetails)) == NULL)
1328 return MMSYSERR_INVALHANDLE;
1330 return MMDRV_Message(&lpwm->mld, MXDM_SETCONTROLDETAILS, (DWORD)lpmcdA,
1331 fdwDetails, TRUE);
1334 /**************************************************************************
1335 * mixerSetControlDetails [MMSYSTEM.809]
1337 UINT16 WINAPI mixerSetControlDetails16(HMIXEROBJ16 hmix,
1338 LPMIXERCONTROLDETAILS16 lpmcd,
1339 DWORD fdwDetails)
1341 TRACE("(%04x, %p, %08lx)\n", hmix, lpmcd, fdwDetails);
1342 return MMSYSERR_NOTENABLED;
1345 /**************************************************************************
1346 * mixerMessage [WINMM.109]
1348 UINT WINAPI mixerMessage(HMIXER hmix, UINT uMsg, DWORD dwParam1, DWORD dwParam2)
1350 LPWINE_MLD wmld;
1352 TRACE("(%04lx, %d, %08lx, %08lx): semi-stub?\n",
1353 (DWORD)hmix, uMsg, dwParam1, dwParam2);
1355 if ((wmld = MMDRV_Get(hmix, MMDRV_MIXER, FALSE)) == NULL)
1356 return MMSYSERR_INVALHANDLE;
1358 return MMDRV_Message(wmld, uMsg, dwParam1, dwParam2, TRUE);
1361 /**************************************************************************
1362 * mixerMessage [MMSYSTEM.804]
1364 UINT16 WINAPI mixerMessage16(HMIXER16 hmix, UINT16 uMsg, DWORD dwParam1,
1365 DWORD dwParam2)
1367 return mixerMessage(hmix, uMsg, dwParam1, dwParam2);
1370 /**************************************************************************
1371 * auxGetNumDevs [WINMM.22]
1373 UINT WINAPI auxGetNumDevs(void)
1375 return MMDRV_GetNum(MMDRV_AUX);
1378 /**************************************************************************
1379 * auxGetNumDevs [MMSYSTEM.350]
1381 UINT16 WINAPI auxGetNumDevs16(void)
1383 return MMDRV_GetNum(MMDRV_AUX);
1386 /**************************************************************************
1387 * auxGetDevCaps [WINMM.20]
1389 UINT WINAPI auxGetDevCapsW(UINT uDeviceID, LPAUXCAPSW lpCaps, UINT uSize)
1391 AUXCAPSA acA;
1392 UINT ret = auxGetDevCapsA(uDeviceID, &acA, sizeof(acA));
1394 lpCaps->wMid = acA.wMid;
1395 lpCaps->wPid = acA.wPid;
1396 lpCaps->vDriverVersion = acA.vDriverVersion;
1397 lstrcpyAtoW(lpCaps->szPname, acA.szPname);
1398 lpCaps->wTechnology = acA.wTechnology;
1399 lpCaps->dwSupport = acA.dwSupport;
1400 return ret;
1403 /**************************************************************************
1404 * auxGetDevCaps [WINMM.21]
1406 UINT WINAPI auxGetDevCapsA(UINT uDeviceID, LPAUXCAPSA lpCaps, UINT uSize)
1408 LPWINE_MLD wmld;
1410 TRACE("(%04X, %p, %d) !\n", uDeviceID, lpCaps, uSize);
1412 if ((wmld = MMDRV_Get(uDeviceID, MMDRV_AUX, TRUE)) == NULL)
1413 return MMSYSERR_INVALHANDLE;
1414 return MMDRV_Message(wmld, AUXDM_GETDEVCAPS, (DWORD)lpCaps, uSize, TRUE);
1417 /**************************************************************************
1418 * auxGetDevCaps [MMSYSTEM.351]
1420 UINT16 WINAPI auxGetDevCaps16(UINT16 uDeviceID, LPAUXCAPS16 lpCaps, UINT16 uSize)
1422 LPWINE_MLD wmld;
1424 TRACE("(%04X, %p, %d) !\n", uDeviceID, lpCaps, uSize);
1426 if ((wmld = MMDRV_Get(uDeviceID, MMDRV_AUX, TRUE)) == NULL)
1427 return MMSYSERR_INVALHANDLE;
1428 return MMDRV_Message(wmld, AUXDM_GETDEVCAPS, (DWORD)lpCaps, uSize, TRUE);
1431 /**************************************************************************
1432 * auxGetVolume [WINM.23]
1434 UINT WINAPI auxGetVolume(UINT uDeviceID, DWORD* lpdwVolume)
1436 LPWINE_MLD wmld;
1438 TRACE("(%04X, %p) !\n", uDeviceID, lpdwVolume);
1440 if ((wmld = MMDRV_Get(uDeviceID, MMDRV_AUX, TRUE)) == NULL)
1441 return MMSYSERR_INVALHANDLE;
1442 return MMDRV_Message(wmld, AUXDM_GETVOLUME, (DWORD)lpdwVolume, 0L, TRUE);
1445 /**************************************************************************
1446 * auxGetVolume [MMSYSTEM.352]
1448 UINT16 WINAPI auxGetVolume16(UINT16 uDeviceID, LPDWORD lpdwVolume)
1450 LPWINE_MLD wmld;
1452 TRACE("(%04X, %p) !\n", uDeviceID, lpdwVolume);
1454 if ((wmld = MMDRV_Get(uDeviceID, MMDRV_AUX, TRUE)) == NULL)
1455 return MMSYSERR_INVALHANDLE;
1456 return MMDRV_Message(wmld, AUXDM_GETVOLUME, (DWORD)lpdwVolume, 0L, TRUE);
1459 /**************************************************************************
1460 * auxSetVolume [WINMM.25]
1462 UINT WINAPI auxSetVolume(UINT uDeviceID, DWORD dwVolume)
1464 LPWINE_MLD wmld;
1466 TRACE("(%04X, %lu) !\n", uDeviceID, dwVolume);
1468 if ((wmld = MMDRV_Get(uDeviceID, MMDRV_AUX, TRUE)) == NULL)
1469 return MMSYSERR_INVALHANDLE;
1470 return MMDRV_Message(wmld, AUXDM_SETVOLUME, dwVolume, 0L, TRUE);
1473 /**************************************************************************
1474 * auxSetVolume [MMSYSTEM.353]
1476 UINT16 WINAPI auxSetVolume16(UINT16 uDeviceID, DWORD dwVolume)
1478 LPWINE_MLD wmld;
1480 TRACE("(%04X, %lu) !\n", uDeviceID, dwVolume);
1482 if ((wmld = MMDRV_Get(uDeviceID, MMDRV_AUX, TRUE)) == NULL)
1483 return MMSYSERR_INVALHANDLE;
1484 return MMDRV_Message(wmld, AUXDM_SETVOLUME, dwVolume, 0L, TRUE);
1487 /**************************************************************************
1488 * auxOutMessage [MMSYSTEM.354]
1490 DWORD WINAPI auxOutMessage(UINT uDeviceID, UINT uMessage, DWORD dw1, DWORD dw2)
1492 LPWINE_MLD wmld;
1494 if ((wmld = MMDRV_Get(uDeviceID, MMDRV_AUX, TRUE)) == NULL)
1495 return MMSYSERR_INVALHANDLE;
1497 return MMDRV_Message(wmld, uMessage, dw1, dw2, TRUE);
1500 /**************************************************************************
1501 * auxOutMessage [MMSYSTEM.354]
1503 DWORD WINAPI auxOutMessage16(UINT16 uDeviceID, UINT16 uMessage, DWORD dw1, DWORD dw2)
1505 LPWINE_MLD wmld;
1507 TRACE("(%04X, %04X, %08lX, %08lX)\n", uDeviceID, uMessage, dw1, dw2);
1509 switch (uMessage) {
1510 case AUXDM_GETNUMDEVS:
1511 case AUXDM_SETVOLUME:
1512 /* no argument conversion needed */
1513 break;
1514 case AUXDM_GETVOLUME:
1515 return auxGetVolume16(uDeviceID, (LPDWORD)PTR_SEG_TO_LIN(dw1));
1516 case AUXDM_GETDEVCAPS:
1517 return auxGetDevCaps16(uDeviceID, (LPAUXCAPS16)PTR_SEG_TO_LIN(dw1), dw2);
1518 default:
1519 TRACE("(%04x, %04x, %08lx, %08lx): unhandled message\n",
1520 uDeviceID, uMessage, dw1, dw2);
1521 break;
1523 if ((wmld = MMDRV_Get(uDeviceID, MMDRV_AUX, TRUE)) == NULL)
1524 return MMSYSERR_INVALHANDLE;
1526 return MMDRV_Message(wmld, uMessage, dw1, dw2, TRUE);
1529 /**************************************************************************
1530 * mciGetErrorStringW [WINMM.46]
1532 BOOL WINAPI mciGetErrorStringW(DWORD wError, LPWSTR lpstrBuffer, UINT uLength)
1534 LPSTR bufstr = HeapAlloc(GetProcessHeap(), 0, uLength);
1535 BOOL ret = mciGetErrorStringA(wError, bufstr, uLength);
1537 lstrcpyAtoW(lpstrBuffer, bufstr);
1538 HeapFree(GetProcessHeap(), 0, bufstr);
1539 return ret;
1542 /**************************************************************************
1543 * mciGetErrorStringA [WINMM.45]
1545 BOOL WINAPI mciGetErrorStringA(DWORD wError, LPSTR lpstrBuffer, UINT uLength)
1547 return mciGetErrorString16(wError, lpstrBuffer, uLength);
1550 /**************************************************************************
1551 * mciGetErrorString [MMSYSTEM.706]
1553 BOOL16 WINAPI mciGetErrorString16(DWORD dwError, LPSTR lpstrBuffer, UINT16 uLength)
1555 BOOL16 ret = FALSE;
1557 if (lpstrBuffer != NULL && uLength > 0 &&
1558 dwError >= MCIERR_BASE && dwError <= MCIERR_CUSTOM_DRIVER_BASE) {
1560 if (LoadStringA(MULTIMEDIA_GetIData()->hWinMM32Instance,
1561 dwError, lpstrBuffer, uLength) > 0) {
1562 ret = TRUE;
1565 return ret;
1568 /**************************************************************************
1569 * mciDriverNotify [MMSYSTEM.711]
1571 BOOL16 WINAPI mciDriverNotify16(HWND16 hWndCallBack, UINT16 wDevID, UINT16 wStatus)
1573 TRACE("(%04X, %04x, %04X)\n", hWndCallBack, wDevID, wStatus);
1575 if (!IsWindow(hWndCallBack)) {
1576 WARN("bad hWnd for call back (0x%04x)\n", hWndCallBack);
1577 return FALSE;
1579 TRACE("before PostMessage\n");
1580 Callout.PostMessageA(hWndCallBack, MM_MCINOTIFY, wStatus, wDevID);
1581 return TRUE;
1584 /**************************************************************************
1585 * mciDriverNotify [WINMM.36]
1587 BOOL WINAPI mciDriverNotify(HWND hWndCallBack, UINT wDevID, UINT wStatus)
1590 TRACE("(%08X, %04x, %04X)\n", hWndCallBack, wDevID, wStatus);
1592 if (!IsWindow(hWndCallBack)) {
1593 WARN("bad hWnd for call back (0x%04x)\n", hWndCallBack);
1594 return FALSE;
1596 TRACE("before PostMessage\n");
1597 Callout.PostMessageA(hWndCallBack, MM_MCINOTIFY, wStatus, wDevID);
1598 return TRUE;
1601 /**************************************************************************
1602 * mciGetDriverData [MMSYSTEM.708]
1604 DWORD WINAPI mciGetDriverData16(UINT16 uDeviceID)
1606 return mciGetDriverData(uDeviceID);
1609 /**************************************************************************
1610 * mciGetDriverData [WINMM.44]
1612 DWORD WINAPI mciGetDriverData(UINT uDeviceID)
1614 LPWINE_MCIDRIVER wmd;
1616 TRACE("(%04x)\n", uDeviceID);
1618 wmd = MCI_GetDriver(uDeviceID);
1620 if (!wmd) {
1621 WARN("Bad uDeviceID\n");
1622 return 0L;
1625 return wmd->dwPrivate;
1628 /**************************************************************************
1629 * mciSetDriverData [MMSYSTEM.707]
1631 BOOL16 WINAPI mciSetDriverData16(UINT16 uDeviceID, DWORD data)
1633 return mciSetDriverData(uDeviceID, data);
1636 /**************************************************************************
1637 * mciSetDriverData [WINMM.53]
1639 BOOL WINAPI mciSetDriverData(UINT uDeviceID, DWORD data)
1641 LPWINE_MCIDRIVER wmd;
1643 TRACE("(%04x, %08lx)\n", uDeviceID, data);
1645 wmd = MCI_GetDriver(uDeviceID);
1647 if (!wmd) {
1648 WARN("Bad uDeviceID\n");
1649 return FALSE;
1652 wmd->dwPrivate = data;
1653 return TRUE;
1656 /**************************************************************************
1657 * mciSendCommandA [WINMM.49]
1659 DWORD WINAPI mciSendCommandA(UINT wDevID, UINT wMsg, DWORD dwParam1, DWORD dwParam2)
1661 DWORD dwRet;
1663 TRACE("(%08x, %s, %08lx, %08lx)\n",
1664 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
1666 dwRet = MCI_SendCommand(wDevID, wMsg, dwParam1, dwParam2, TRUE);
1667 dwRet = MCI_CleanUp(dwRet, wMsg, dwParam2, TRUE);
1668 TRACE("=> %08lx\n", dwRet);
1669 return dwRet;
1672 /**************************************************************************
1673 * mciSendCommandW [WINMM.50]
1675 DWORD WINAPI mciSendCommandW(UINT wDevID, UINT wMsg, DWORD dwParam1, DWORD dwParam2)
1677 FIXME("(%08x, %s, %08lx, %08lx): stub\n",
1678 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
1679 return MCIERR_UNSUPPORTED_FUNCTION;
1682 /**************************************************************************
1683 * mciSendCommand [MMSYSTEM.701]
1685 DWORD WINAPI mciSendCommand16(UINT16 wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2)
1687 DWORD dwRet;
1689 TRACE("(%04X, %s, %08lX, %08lX)\n",
1690 wDevID, MCI_MessageToString(wMsg), dwParam1, dwParam2);
1692 dwRet = MCI_SendCommand(wDevID, wMsg, dwParam1, dwParam2, FALSE);
1693 dwRet = MCI_CleanUp(dwRet, wMsg, dwParam2, FALSE);
1694 TRACE("=> %ld\n", dwRet);
1695 return dwRet;
1698 /**************************************************************************
1699 * mciGetDeviceID [MMSYSTEM.703]
1701 UINT16 WINAPI mciGetDeviceID16(LPCSTR lpstrName)
1703 TRACE("(\"%s\")\n", lpstrName);
1705 return MCI_GetDriverFromString(lpstrName);
1708 /**************************************************************************
1709 * mciGetDeviceIDA [WINMM.41]
1711 UINT WINAPI mciGetDeviceIDA(LPCSTR lpstrName)
1713 return MCI_GetDriverFromString(lpstrName);
1716 /**************************************************************************
1717 * mciGetDeviceIDW [WINMM.43]
1719 UINT WINAPI mciGetDeviceIDW(LPCWSTR lpwstrName)
1721 LPSTR lpstrName;
1722 UINT ret;
1724 lpstrName = HEAP_strdupWtoA(GetProcessHeap(), 0, lpwstrName);
1725 ret = MCI_GetDriverFromString(lpstrName);
1726 HeapFree(GetProcessHeap(), 0, lpstrName);
1727 return ret;
1730 /**************************************************************************
1731 * MCI_DefYieldProc [internal]
1733 UINT16 WINAPI MCI_DefYieldProc(UINT16 wDevID, DWORD data)
1735 INT16 ret;
1737 TRACE("(0x%04x, 0x%08lx)\n", wDevID, data);
1739 if ((HIWORD(data) != 0 && GetActiveWindow16() != HIWORD(data)) ||
1740 (GetAsyncKeyState(LOWORD(data)) & 1) == 0) {
1741 UserYield16();
1742 ret = 0;
1743 } else {
1744 MSG msg;
1746 msg.hwnd = HIWORD(data);
1747 while (!PeekMessageA(&msg, HIWORD(data), WM_KEYFIRST, WM_KEYLAST, PM_REMOVE));
1748 ret = -1;
1750 return ret;
1753 /**************************************************************************
1754 * mciSetYieldProc [MMSYSTEM.714]
1756 BOOL16 WINAPI mciSetYieldProc16(UINT16 uDeviceID, YIELDPROC fpYieldProc, DWORD dwYieldData)
1758 LPWINE_MCIDRIVER wmd;
1760 TRACE("(%u, %p, %08lx)\n", uDeviceID, fpYieldProc, dwYieldData);
1762 if (!(wmd = MCI_GetDriver(uDeviceID))) {
1763 WARN("Bad uDeviceID\n");
1764 return FALSE;
1767 wmd->lpfnYieldProc = fpYieldProc;
1768 wmd->dwYieldData = dwYieldData;
1769 wmd->bIs32 = FALSE;
1771 return TRUE;
1774 /**************************************************************************
1775 * mciSetYieldProc [WINMM.54]
1777 BOOL WINAPI mciSetYieldProc(UINT uDeviceID, YIELDPROC fpYieldProc, DWORD dwYieldData)
1779 LPWINE_MCIDRIVER wmd;
1781 TRACE("(%u, %p, %08lx)\n", uDeviceID, fpYieldProc, dwYieldData);
1783 if (!(wmd = MCI_GetDriver(uDeviceID))) {
1784 WARN("Bad uDeviceID\n");
1785 return FALSE;
1788 wmd->lpfnYieldProc = fpYieldProc;
1789 wmd->dwYieldData = dwYieldData;
1790 wmd->bIs32 = TRUE;
1792 return TRUE;
1795 /**************************************************************************
1796 * mciGetDeviceIDFromElementID [MMSYSTEM.715]
1798 UINT16 WINAPI mciGetDeviceIDFromElementID16(DWORD dwElementID, LPCSTR lpstrType)
1800 FIXME("(%lu, %s) stub\n", dwElementID, lpstrType);
1801 return 0;
1804 /**************************************************************************
1805 * mciGetDeviceIDFromElementIDW [WINMM.42]
1807 UINT WINAPI mciGetDeviceIDFromElementIDW(DWORD dwElementID, LPCWSTR lpstrType)
1809 /* FIXME: that's rather strange, there is no
1810 * mciGetDeviceIDFromElementID32A in winmm.spec
1812 FIXME("(%lu, %p) stub\n", dwElementID, lpstrType);
1813 return 0;
1816 /**************************************************************************
1817 * mciGetYieldProc [MMSYSTEM.716]
1819 YIELDPROC WINAPI mciGetYieldProc16(UINT16 uDeviceID, DWORD* lpdwYieldData)
1821 LPWINE_MCIDRIVER wmd;
1823 TRACE("(%u, %p)\n", uDeviceID, lpdwYieldData);
1825 if (!(wmd = MCI_GetDriver(uDeviceID))) {
1826 WARN("Bad uDeviceID\n");
1827 return NULL;
1829 if (!wmd->lpfnYieldProc) {
1830 WARN("No proc set\n");
1831 return NULL;
1833 if (wmd->bIs32) {
1834 WARN("Proc is 32 bit\n");
1835 return NULL;
1837 return wmd->lpfnYieldProc;
1840 /**************************************************************************
1841 * mciGetYieldProc [WINMM.47]
1843 YIELDPROC WINAPI mciGetYieldProc(UINT uDeviceID, DWORD* lpdwYieldData)
1845 LPWINE_MCIDRIVER wmd;
1847 TRACE("(%u, %p)\n", uDeviceID, lpdwYieldData);
1849 if (!(wmd = MCI_GetDriver(uDeviceID))) {
1850 WARN("Bad uDeviceID\n");
1851 return NULL;
1853 if (!wmd->lpfnYieldProc) {
1854 WARN("No proc set\n");
1855 return NULL;
1857 if (!wmd->bIs32) {
1858 WARN("Proc is 32 bit\n");
1859 return NULL;
1861 return wmd->lpfnYieldProc;
1864 /**************************************************************************
1865 * mciGetCreatorTask [MMSYSTEM.717]
1867 HTASK16 WINAPI mciGetCreatorTask16(UINT16 uDeviceID)
1869 return mciGetCreatorTask(uDeviceID);
1872 /**************************************************************************
1873 * mciGetCreatorTask [WINMM.40]
1875 HTASK WINAPI mciGetCreatorTask(UINT uDeviceID)
1877 LPWINE_MCIDRIVER wmd;
1878 HTASK ret;
1880 TRACE("(%u)\n", uDeviceID);
1882 ret = (!(wmd = MCI_GetDriver(uDeviceID))) ? 0 : wmd->hCreatorTask;
1884 TRACE("=> %04x\n", ret);
1885 return ret;
1888 /**************************************************************************
1889 * mciDriverYield [MMSYSTEM.710]
1891 UINT16 WINAPI mciDriverYield16(UINT16 uDeviceID)
1893 LPWINE_MCIDRIVER wmd;
1894 UINT16 ret = 0;
1896 /* TRACE("(%04x)\n", uDeviceID); */
1898 if (!(wmd = MCI_GetDriver(uDeviceID)) || !wmd->lpfnYieldProc || wmd->bIs32) {
1899 UserYield16();
1900 } else {
1901 ret = wmd->lpfnYieldProc(uDeviceID, wmd->dwYieldData);
1904 return ret;
1907 /**************************************************************************
1908 * mciDriverYield [WINMM.37]
1910 UINT WINAPI mciDriverYield(UINT uDeviceID)
1912 LPWINE_MCIDRIVER wmd;
1913 UINT ret = 0;
1915 TRACE("(%04x)\n", uDeviceID);
1917 if (!(wmd = MCI_GetDriver(uDeviceID)) || !wmd->lpfnYieldProc || !wmd->bIs32) {
1918 UserYield16();
1919 } else {
1920 ret = wmd->lpfnYieldProc(uDeviceID, wmd->dwYieldData);
1923 return ret;
1926 /**************************************************************************
1927 * midiOutGetNumDevs [WINMM.80]
1929 UINT WINAPI midiOutGetNumDevs(void)
1931 return MMDRV_GetNum(MMDRV_MIDIOUT);
1934 /**************************************************************************
1935 * midiOutGetNumDevs [MMSYSTEM.201]
1937 UINT16 WINAPI midiOutGetNumDevs16(void)
1939 return MMDRV_GetNum(MMDRV_MIDIOUT);
1942 /**************************************************************************
1943 * midiOutGetDevCapsW [WINMM.76]
1945 UINT WINAPI midiOutGetDevCapsW(UINT uDeviceID, LPMIDIOUTCAPSW lpCaps,
1946 UINT uSize)
1948 MIDIOUTCAPSA mocA;
1949 UINT ret;
1951 ret = midiOutGetDevCapsA(uDeviceID, &mocA, sizeof(mocA));
1952 lpCaps->wMid = mocA.wMid;
1953 lpCaps->wPid = mocA.wPid;
1954 lpCaps->vDriverVersion = mocA.vDriverVersion;
1955 lstrcpyAtoW(lpCaps->szPname, mocA.szPname);
1956 lpCaps->wTechnology = mocA.wTechnology;
1957 lpCaps->wVoices = mocA.wVoices;
1958 lpCaps->wNotes = mocA.wNotes;
1959 lpCaps->wChannelMask = mocA.wChannelMask;
1960 lpCaps->dwSupport = mocA.dwSupport;
1961 return ret;
1964 /**************************************************************************
1965 * midiOutGetDevCapsA [WINMM.75]
1967 UINT WINAPI midiOutGetDevCapsA(UINT uDeviceID, LPMIDIOUTCAPSA lpCaps,
1968 UINT uSize)
1970 LPWINE_MLD wmld;
1972 TRACE("(%u, %p, %u);\n", uDeviceID, lpCaps, uSize);
1974 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
1976 if ((wmld = MMDRV_Get(uDeviceID, MMDRV_MIDIOUT, TRUE)) == NULL)
1977 return MMSYSERR_INVALHANDLE;
1979 return MMDRV_Message(wmld, MODM_GETDEVCAPS, (DWORD)lpCaps, uSize, TRUE);
1982 /**************************************************************************
1983 * midiOutGetDevCaps [MMSYSTEM.202]
1985 UINT16 WINAPI midiOutGetDevCaps16(UINT16 uDeviceID, LPMIDIOUTCAPS16 lpCaps,
1986 UINT16 uSize)
1988 MIDIOUTCAPSA capsA;
1989 UINT dwRet;
1991 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
1993 dwRet = midiOutGetDevCapsA(uDeviceID, &capsA, sizeof(capsA));
1994 if (dwRet == MMSYSERR_NOERROR) {
1995 lpCaps->wMid = capsA.wMid;
1996 lpCaps->wPid = capsA.wPid;
1997 lpCaps->vDriverVersion = capsA.vDriverVersion;
1998 strcpy(lpCaps->szPname, capsA.szPname);
1999 lpCaps->wTechnology = capsA.wTechnology;
2000 lpCaps->wVoices = capsA.wVoices;
2001 lpCaps->wNotes = capsA.wNotes;
2002 lpCaps->wChannelMask = capsA.wChannelMask;
2003 lpCaps->dwSupport = capsA.dwSupport;
2005 return dwRet;
2008 /**************************************************************************
2009 * MIDI_GetErrorText [internal]
2011 static UINT16 MIDI_GetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize)
2013 UINT16 ret = MMSYSERR_BADERRNUM;
2015 if (lpText == NULL) {
2016 ret = MMSYSERR_INVALPARAM;
2017 } else if (uSize == 0) {
2018 ret = MMSYSERR_NOERROR;
2019 } else if (
2020 /* test has been removed 'coz MMSYSERR_BASE is 0, and gcc did emit
2021 * a warning for the test was always true */
2022 (/*uError >= MMSYSERR_BASE && */ uError <= MMSYSERR_LASTERROR) ||
2023 (uError >= MIDIERR_BASE && uError <= MIDIERR_LASTERROR)) {
2025 if (LoadStringA(MULTIMEDIA_GetIData()->hWinMM32Instance,
2026 uError, lpText, uSize) > 0) {
2027 ret = MMSYSERR_NOERROR;
2030 return ret;
2033 /**************************************************************************
2034 * midiOutGetErrorTextA [WINMM.77]
2036 UINT WINAPI midiOutGetErrorTextA(UINT uError, LPSTR lpText, UINT uSize)
2038 return MIDI_GetErrorText(uError, lpText, uSize);
2041 /**************************************************************************
2042 * midiOutGetErrorTextW [WINMM.78]
2044 UINT WINAPI midiOutGetErrorTextW(UINT uError, LPWSTR lpText, UINT uSize)
2046 LPSTR xstr = HeapAlloc(GetProcessHeap(), 0, uSize);
2047 UINT ret;
2049 ret = MIDI_GetErrorText(uError, xstr, uSize);
2050 lstrcpyAtoW(lpText, xstr);
2051 HeapFree(GetProcessHeap(), 0, xstr);
2052 return ret;
2055 /**************************************************************************
2056 * midiOutGetErrorText [MMSYSTEM.203]
2058 UINT16 WINAPI midiOutGetErrorText16(UINT16 uError, LPSTR lpText, UINT16 uSize)
2060 return MIDI_GetErrorText(uError, lpText, uSize);
2063 /**************************************************************************
2064 * MIDI_OutAlloc [internal]
2066 static LPWINE_MIDI MIDI_OutAlloc(HMIDIOUT* lphMidiOut, LPDWORD lpdwCallback,
2067 LPDWORD lpdwInstance, LPDWORD lpdwFlags,
2068 DWORD cIDs, MIDIOPENSTRMID* lpIDs, BOOL bFrom32)
2070 HANDLE hMidiOut;
2071 LPWINE_MIDI lpwm;
2072 UINT size;
2074 size = sizeof(WINE_MIDI) + (cIDs ? (cIDs-1) : 0) * sizeof(MIDIOPENSTRMID);
2076 lpwm = (LPWINE_MIDI)MMDRV_Alloc(size, MMDRV_MIDIOUT, &hMidiOut, lpdwFlags,
2077 lpdwCallback, lpdwInstance, bFrom32);
2079 if (lphMidiOut != NULL)
2080 *lphMidiOut = hMidiOut;
2082 if (lpwm) {
2083 lpwm->mod.hMidi = hMidiOut;
2084 lpwm->mod.dwCallback = *lpdwCallback;
2085 lpwm->mod.dwInstance = *lpdwInstance;
2086 lpwm->mod.dnDevNode = 0;
2087 lpwm->mod.cIds = cIDs;
2088 if (cIDs)
2089 memcpy(&(lpwm->mod.rgIds), lpIDs, cIDs * sizeof(MIDIOPENSTRMID));
2091 return lpwm;
2094 UINT MMSYSTEM_midiOutOpen(HMIDIOUT* lphMidiOut, UINT uDeviceID, DWORD dwCallback,
2095 DWORD dwInstance, DWORD dwFlags, BOOL bFrom32)
2097 HMIDIOUT hMidiOut;
2098 LPWINE_MIDI lpwm;
2099 UINT dwRet = 0;
2101 TRACE("(%p, %d, %08lX, %08lX, %08lX);\n",
2102 lphMidiOut, uDeviceID, dwCallback, dwInstance, dwFlags);
2104 if (lphMidiOut != NULL) *lphMidiOut = 0;
2106 lpwm = MIDI_OutAlloc(&hMidiOut, &dwCallback, &dwInstance, &dwFlags,
2107 0, NULL, bFrom32);
2109 if (lpwm == NULL)
2110 return MMSYSERR_NOMEM;
2112 lpwm->mld.uDeviceID = uDeviceID;
2114 dwRet = MMDRV_Open((LPWINE_MLD)lpwm, MODM_OPEN, (DWORD)&lpwm->mod,
2115 dwFlags);
2117 if (dwRet != MMSYSERR_NOERROR) {
2118 MMDRV_Free(hMidiOut, (LPWINE_MLD)lpwm);
2119 hMidiOut = 0;
2122 if (lphMidiOut) *lphMidiOut = hMidiOut;
2123 TRACE("=> %d hMidi=%04x\n", dwRet, hMidiOut);
2125 return dwRet;
2128 /**************************************************************************
2129 * midiOutOpen [WINM.84]
2131 UINT WINAPI midiOutOpen(HMIDIOUT* lphMidiOut, UINT uDeviceID,
2132 DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
2134 return MMSYSTEM_midiOutOpen(lphMidiOut, uDeviceID, dwCallback,
2135 dwInstance, dwFlags, TRUE);
2138 /**************************************************************************
2139 * midiOutOpen [MMSYSTEM.204]
2141 UINT16 WINAPI midiOutOpen16(HMIDIOUT16* lphMidiOut, UINT16 uDeviceID,
2142 DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
2144 HMIDIOUT hmo;
2145 UINT ret;
2147 ret = MMSYSTEM_midiOutOpen(&hmo, uDeviceID, dwCallback, dwInstance,
2148 dwFlags, FALSE);
2150 if (lphMidiOut != NULL) *lphMidiOut = hmo;
2151 return ret;
2154 /**************************************************************************
2155 * midiOutClose [WINMM.74]
2157 UINT WINAPI midiOutClose(HMIDIOUT hMidiOut)
2159 LPWINE_MLD wmld;
2160 DWORD dwRet;
2162 TRACE("(%04X)\n", hMidiOut);
2164 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
2165 return MMSYSERR_INVALHANDLE;
2167 dwRet = MMDRV_Close(wmld, MODM_CLOSE);
2168 MMDRV_Free(hMidiOut, wmld);
2170 return dwRet;
2173 /**************************************************************************
2174 * midiOutClose [MMSYSTEM.205]
2176 UINT16 WINAPI midiOutClose16(HMIDIOUT16 hMidiOut)
2178 return midiOutClose(hMidiOut);
2181 /**************************************************************************
2182 * midiOutPrepareHeader [WINMM.85]
2184 UINT WINAPI midiOutPrepareHeader(HMIDIOUT hMidiOut,
2185 MIDIHDR* lpMidiOutHdr, UINT uSize)
2187 LPWINE_MLD wmld;
2189 TRACE("(%04X, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
2191 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
2192 return MMSYSERR_INVALHANDLE;
2194 return MMDRV_Message(wmld, MODM_PREPARE, (DWORD)lpMidiOutHdr, uSize, TRUE);
2197 /**************************************************************************
2198 * midiOutPrepareHeader [MMSYSTEM.206]
2200 UINT16 WINAPI midiOutPrepareHeader16(HMIDIOUT16 hMidiOut,
2201 LPMIDIHDR16 /*SEGPTR*/ lpsegMidiOutHdr,
2202 UINT16 uSize)
2204 LPWINE_MLD wmld;
2205 LPMIDIHDR16 lpMidiOutHdr = PTR_SEG_TO_LIN(lpsegMidiOutHdr);
2207 TRACE("(%04X, %p, %d)\n", hMidiOut, lpsegMidiOutHdr, uSize);
2209 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
2210 return MMSYSERR_INVALHANDLE;
2212 return MMDRV_Message(wmld, MODM_PREPARE, (DWORD)lpMidiOutHdr, uSize, FALSE);
2215 /**************************************************************************
2216 * midiOutUnprepareHeader [WINMM.89]
2218 UINT WINAPI midiOutUnprepareHeader(HMIDIOUT hMidiOut,
2219 MIDIHDR* lpMidiOutHdr, UINT uSize)
2221 LPWINE_MLD wmld;
2223 TRACE("(%04X, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
2225 if (!(lpMidiOutHdr->dwFlags & MHDR_PREPARED)) {
2226 return MMSYSERR_NOERROR;
2229 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
2230 return MMSYSERR_INVALHANDLE;
2232 return MMDRV_Message(wmld, MODM_UNPREPARE, (DWORD)lpMidiOutHdr, uSize, TRUE);
2235 /**************************************************************************
2236 * midiOutUnprepareHeader [MMSYSTEM.207]
2238 UINT16 WINAPI midiOutUnprepareHeader16(HMIDIOUT16 hMidiOut,
2239 LPMIDIHDR16 /*SEGPTR*/ lpsegMidiOutHdr,
2240 UINT16 uSize)
2242 LPWINE_MLD wmld;
2243 LPMIDIHDR16 lpMidiOutHdr = PTR_SEG_TO_LIN(lpsegMidiOutHdr);
2245 TRACE("(%04X, %p, %d)\n", hMidiOut, lpsegMidiOutHdr, uSize);
2247 if (!(lpMidiOutHdr->dwFlags & MHDR_PREPARED)) {
2248 return MMSYSERR_NOERROR;
2251 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
2252 return MMSYSERR_INVALHANDLE;
2254 return MMDRV_Message(wmld, MODM_UNPREPARE, (DWORD)lpsegMidiOutHdr, uSize, FALSE);
2257 /**************************************************************************
2258 * midiOutShortMsg [WINMM.88]
2260 UINT WINAPI midiOutShortMsg(HMIDIOUT hMidiOut, DWORD dwMsg)
2262 LPWINE_MLD wmld;
2264 TRACE("(%04X, %08lX)\n", hMidiOut, dwMsg);
2266 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
2267 return MMSYSERR_INVALHANDLE;
2269 return MMDRV_Message(wmld, MODM_DATA, dwMsg, 0L, FALSE);
2272 /**************************************************************************
2273 * midiOutShortMsg [MMSYSTEM.208]
2275 UINT16 WINAPI midiOutShortMsg16(HMIDIOUT16 hMidiOut, DWORD dwMsg)
2277 return midiOutShortMsg(hMidiOut, dwMsg);
2280 /**************************************************************************
2281 * midiOutLongMsg [WINMM.82]
2283 UINT WINAPI midiOutLongMsg(HMIDIOUT hMidiOut,
2284 MIDIHDR* lpMidiOutHdr, UINT uSize)
2286 LPWINE_MLD wmld;
2288 TRACE("(%04X, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
2290 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
2291 return MMSYSERR_INVALHANDLE;
2293 return MMDRV_Message(wmld, MODM_LONGDATA, (DWORD)lpMidiOutHdr, uSize, TRUE);
2296 /**************************************************************************
2297 * midiOutLongMsg [MMSYSTEM.209]
2299 UINT16 WINAPI midiOutLongMsg16(HMIDIOUT16 hMidiOut,
2300 LPMIDIHDR16 /* SEGPTR */ lpsegMidiOutHdr,
2301 UINT16 uSize)
2303 LPWINE_MLD wmld;
2305 TRACE("(%04X, %p, %d)\n", hMidiOut, lpsegMidiOutHdr, uSize);
2307 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
2308 return MMSYSERR_INVALHANDLE;
2310 return MMDRV_Message(wmld, MODM_LONGDATA, (DWORD)lpsegMidiOutHdr, uSize, FALSE);
2313 /**************************************************************************
2314 * midiOutReset [WINMM.86]
2316 UINT WINAPI midiOutReset(HMIDIOUT hMidiOut)
2318 LPWINE_MLD wmld;
2320 TRACE("(%04X)\n", hMidiOut);
2322 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
2323 return MMSYSERR_INVALHANDLE;
2325 return MMDRV_Message(wmld, MODM_RESET, 0L, 0L, TRUE);
2328 /**************************************************************************
2329 * midiOutReset [MMSYSTEM.210]
2331 UINT16 WINAPI midiOutReset16(HMIDIOUT16 hMidiOut)
2333 return midiOutReset(hMidiOut);
2336 /**************************************************************************
2337 * midiOutGetVolume [WINM.81]
2339 UINT WINAPI midiOutGetVolume(UINT uDeviceID, DWORD* lpdwVolume)
2341 LPWINE_MLD wmld;
2343 TRACE("(%04X, %p);\n", uDeviceID, lpdwVolume);
2345 if ((wmld = MMDRV_Get(uDeviceID, MMDRV_MIDIOUT, TRUE)) == NULL)
2346 return MMSYSERR_INVALHANDLE;
2348 return MMDRV_Message(wmld, MODM_GETVOLUME, (DWORD)lpdwVolume, 0L, TRUE);
2351 /**************************************************************************
2352 * midiOutGetVolume [MMSYSTEM.211]
2354 UINT16 WINAPI midiOutGetVolume16(UINT16 uDeviceID, DWORD* lpdwVolume)
2356 return midiOutGetVolume(uDeviceID, lpdwVolume);
2359 /**************************************************************************
2360 * midiOutSetVolume [WINMM.87]
2362 UINT WINAPI midiOutSetVolume(UINT uDeviceID, DWORD dwVolume)
2364 LPWINE_MLD wmld;
2366 TRACE("(%04X, %ld);\n", uDeviceID, dwVolume);
2368 if ((wmld = MMDRV_Get(uDeviceID, MMDRV_MIDIOUT, TRUE)) == NULL)
2369 return MMSYSERR_INVALHANDLE;
2371 return MMDRV_Message(wmld, MODM_SETVOLUME, dwVolume, 0L, TRUE);
2374 /**************************************************************************
2375 * midiOutSetVolume [MMSYSTEM.212]
2377 UINT16 WINAPI midiOutSetVolume16(UINT16 uDeviceID, DWORD dwVolume)
2379 return midiOutSetVolume(uDeviceID, dwVolume);
2382 /**************************************************************************
2383 * midiOutCachePatches [WINMM.73]
2385 UINT WINAPI midiOutCachePatches(HMIDIOUT hMidiOut, UINT uBank,
2386 WORD* lpwPatchArray, UINT uFlags)
2388 /* not really necessary to support this */
2389 FIXME("not supported yet\n");
2390 return MMSYSERR_NOTSUPPORTED;
2393 /**************************************************************************
2394 * midiOutCachePatches [MMSYSTEM.213]
2396 UINT16 WINAPI midiOutCachePatches16(HMIDIOUT16 hMidiOut, UINT16 uBank,
2397 WORD* lpwPatchArray, UINT16 uFlags)
2399 return midiOutCachePatches(hMidiOut, uBank, lpwPatchArray, uFlags);
2402 /**************************************************************************
2403 * midiOutCacheDrumPatches [WINMM.72]
2405 UINT WINAPI midiOutCacheDrumPatches(HMIDIOUT hMidiOut, UINT uPatch,
2406 WORD* lpwKeyArray, UINT uFlags)
2408 FIXME("not supported yet\n");
2409 return MMSYSERR_NOTSUPPORTED;
2412 /**************************************************************************
2413 * midiOutCacheDrumPatches [MMSYSTEM.214]
2415 UINT16 WINAPI midiOutCacheDrumPatches16(HMIDIOUT16 hMidiOut, UINT16 uPatch,
2416 WORD* lpwKeyArray, UINT16 uFlags)
2418 return midiOutCacheDrumPatches16(hMidiOut, uPatch, lpwKeyArray, uFlags);
2421 /**************************************************************************
2422 * midiOutGetID [WINMM.79]
2424 UINT WINAPI midiOutGetID(HMIDIOUT hMidiOut, UINT* lpuDeviceID)
2426 LPWINE_MLD wmld;
2428 TRACE("(%04X, %p)\n", hMidiOut, lpuDeviceID);
2430 if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
2431 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
2432 return MMSYSERR_INVALHANDLE;
2434 *lpuDeviceID = wmld->uDeviceID;
2435 return MMSYSERR_NOERROR;
2438 /**************************************************************************
2439 * midiOutGetID [MMSYSTEM.215]
2441 UINT16 WINAPI midiOutGetID16(HMIDIOUT16 hMidiOut, UINT16* lpuDeviceID)
2443 LPWINE_MLD wmld;
2445 TRACE("(%04X, %p)\n", hMidiOut, lpuDeviceID);
2447 if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
2448 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
2449 return MMSYSERR_INVALHANDLE;
2451 *lpuDeviceID = wmld->uDeviceID;
2452 return MMSYSERR_NOERROR;
2455 /**************************************************************************
2456 * midiOutMessage [WINMM.83]
2458 DWORD WINAPI midiOutMessage(HMIDIOUT hMidiOut, UINT uMessage,
2459 DWORD dwParam1, DWORD dwParam2)
2461 LPWINE_MLD wmld;
2463 TRACE("(%04X, %04X, %08lX, %08lX)\n", hMidiOut, uMessage, dwParam1, dwParam2);
2465 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
2466 return MMSYSERR_INVALHANDLE;
2468 switch (uMessage) {
2469 case MODM_OPEN:
2470 case MODM_CLOSE:
2471 FIXME("can't handle OPEN or CLOSE message!\n");
2472 return MMSYSERR_NOTSUPPORTED;
2474 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
2477 /**************************************************************************
2478 * midiOutMessage [MMSYSTEM.216]
2480 DWORD WINAPI midiOutMessage16(HMIDIOUT16 hMidiOut, UINT16 uMessage,
2481 DWORD dwParam1, DWORD dwParam2)
2483 LPWINE_MLD wmld;
2485 TRACE("(%04X, %04X, %08lX, %08lX)\n", hMidiOut, uMessage, dwParam1, dwParam2);
2487 if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
2488 return MMSYSERR_INVALHANDLE;
2490 switch (uMessage) {
2491 case MODM_OPEN:
2492 case MODM_CLOSE:
2493 FIXME("can't handle OPEN or CLOSE message!\n");
2494 return MMSYSERR_NOTSUPPORTED;
2496 case MODM_GETVOLUME:
2497 return midiOutGetVolume16(hMidiOut, (LPDWORD)PTR_SEG_TO_LIN(dwParam1));
2498 case MODM_LONGDATA:
2499 return midiOutLongMsg16(hMidiOut, (LPMIDIHDR16)PTR_SEG_TO_LIN(dwParam1), dwParam2);
2500 case MODM_PREPARE:
2501 /* lpMidiOutHdr is still a segmented pointer for this function */
2502 return midiOutPrepareHeader16(hMidiOut, (LPMIDIHDR16)dwParam1, dwParam2);
2503 case MODM_UNPREPARE:
2504 return midiOutUnprepareHeader16(hMidiOut, (LPMIDIHDR16)PTR_SEG_TO_LIN(dwParam1), dwParam2);
2506 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
2509 /**************************************************************************
2510 * midiInGetNumDevs [WINMM.64]
2512 UINT WINAPI midiInGetNumDevs(void)
2514 return MMDRV_GetNum(MMDRV_MIDIIN);
2517 /**************************************************************************
2518 * midiInGetNumDevs [MMSYSTEM.301]
2520 UINT16 WINAPI midiInGetNumDevs16(void)
2522 return MMDRV_GetNum(MMDRV_MIDIIN);
2525 /**************************************************************************
2526 * midiInGetDevCaps [WINMM.60]
2528 UINT WINAPI midiInGetDevCapsW(UINT uDeviceID, LPMIDIINCAPSW lpCaps, UINT uSize)
2530 MIDIINCAPSA micA;
2531 UINT ret = midiInGetDevCapsA(uDeviceID, &micA, uSize);
2533 if (ret == MMSYSERR_NOERROR) {
2534 lpCaps->wMid = micA.wMid;
2535 lpCaps->wPid = micA.wPid;
2536 lpCaps->vDriverVersion = micA.vDriverVersion;
2537 lstrcpyAtoW(lpCaps->szPname, micA.szPname);
2538 lpCaps->dwSupport = micA.dwSupport;
2540 return ret;
2543 /**************************************************************************
2544 * midiInGetDevCaps [WINMM.59]
2546 UINT WINAPI midiInGetDevCapsA(UINT uDeviceID, LPMIDIINCAPSA lpCaps, UINT uSize)
2548 LPWINE_MLD wmld;
2550 TRACE("(%d, %p, %d);\n", uDeviceID, lpCaps, uSize);
2552 if ((wmld = MMDRV_Get(uDeviceID, MMDRV_MIDIIN, TRUE)) == NULL)
2553 return MMSYSERR_INVALHANDLE;
2555 return MMDRV_Message(wmld, MIDM_GETDEVCAPS, (DWORD)lpCaps, uSize, TRUE);
2558 /**************************************************************************
2559 * midiInGetDevCaps [MMSYSTEM.302]
2561 UINT16 WINAPI midiInGetDevCaps16(UINT16 uDeviceID, LPMIDIINCAPS16 lpCaps,
2562 UINT16 uSize)
2564 MIDIINCAPSA micA;
2565 UINT ret = midiInGetDevCapsA(uDeviceID, &micA, uSize);
2567 if (ret == MMSYSERR_NOERROR) {
2568 lpCaps->wMid = micA.wMid;
2569 lpCaps->wPid = micA.wPid;
2570 lpCaps->vDriverVersion = micA.vDriverVersion;
2571 strcpy(lpCaps->szPname, micA.szPname);
2572 lpCaps->dwSupport = micA.dwSupport;
2575 return ret;
2578 /**************************************************************************
2579 * midiInGetErrorText [WINMM.62]
2581 UINT WINAPI midiInGetErrorTextW(UINT uError, LPWSTR lpText, UINT uSize)
2583 LPSTR xstr = HeapAlloc(GetProcessHeap(), 0, uSize);
2584 UINT ret = MIDI_GetErrorText(uError, xstr, uSize);
2586 lstrcpyAtoW(lpText, xstr);
2587 HeapFree(GetProcessHeap(), 0, xstr);
2588 return ret;
2591 /**************************************************************************
2592 * midiInGetErrorText [WINMM.61]
2594 UINT WINAPI midiInGetErrorTextA(UINT uError, LPSTR lpText, UINT uSize)
2596 return MIDI_GetErrorText(uError, lpText, uSize);
2599 /**************************************************************************
2600 * midiInGetErrorText [MMSYSTEM.303]
2602 UINT16 WINAPI midiInGetErrorText16(UINT16 uError, LPSTR lpText, UINT16 uSize)
2604 return MIDI_GetErrorText(uError, lpText, uSize);
2607 static UINT MMSYSTEM_midiInOpen(HMIDIIN* lphMidiIn, UINT uDeviceID, DWORD dwCallback,
2608 DWORD dwInstance, DWORD dwFlags, BOOL bFrom32)
2610 HMIDI hMidiIn;
2611 LPWINE_MIDI lpwm;
2612 DWORD dwRet = 0;
2614 TRACE("(%p, %d, %08lX, %08lX, %08lX);\n",
2615 lphMidiIn, uDeviceID, dwCallback, dwInstance, dwFlags);
2617 if (lphMidiIn != NULL) *lphMidiIn = 0;
2619 lpwm = (LPWINE_MIDI)MMDRV_Alloc(sizeof(WINE_MIDI), MMDRV_MIDIIN, &hMidiIn,
2620 &dwFlags, &dwCallback, &dwInstance, bFrom32);
2622 if (lpwm == NULL)
2623 return MMSYSERR_NOMEM;
2625 lpwm->mod.hMidi = hMidiIn;
2626 lpwm->mod.dwCallback = dwCallback;
2627 lpwm->mod.dwInstance = dwInstance;
2629 lpwm->mld.uDeviceID = uDeviceID;
2630 dwRet = MMDRV_Open(&lpwm->mld, MIDM_OPEN, (DWORD)&lpwm->mod, dwFlags);
2632 if (dwRet != MMSYSERR_NOERROR) {
2633 MMDRV_Free(hMidiIn, &lpwm->mld);
2634 hMidiIn = 0;
2636 if (lphMidiIn != NULL) *lphMidiIn = hMidiIn;
2637 TRACE("=> %ld hMidi=%04x\n", dwRet, hMidiIn);
2639 return dwRet;
2642 /**************************************************************************
2643 * midiInOpen [WINMM.66]
2645 UINT WINAPI midiInOpen(HMIDIIN* lphMidiIn, UINT uDeviceID,
2646 DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
2648 return MMSYSTEM_midiInOpen(lphMidiIn, uDeviceID, dwCallback,
2649 dwInstance, dwFlags, TRUE);
2652 /**************************************************************************
2653 * midiInOpen [MMSYSTEM.304]
2655 UINT16 WINAPI midiInOpen16(HMIDIIN16* lphMidiIn, UINT16 uDeviceID,
2656 DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
2658 HMIDIIN xhmid;
2659 UINT ret;
2661 ret = MMSYSTEM_midiInOpen(&xhmid, uDeviceID, dwCallback, dwInstance,
2662 dwFlags, FALSE);
2664 if (lphMidiIn) *lphMidiIn = xhmid;
2665 return ret;
2668 /**************************************************************************
2669 * midiInClose [WINMM.58]
2671 UINT WINAPI midiInClose(HMIDIIN hMidiIn)
2673 LPWINE_MLD wmld;
2674 DWORD dwRet;
2676 TRACE("(%04X)\n", hMidiIn);
2678 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
2679 return MMSYSERR_INVALHANDLE;
2681 dwRet = MMDRV_Close(wmld, MIDM_CLOSE);
2682 MMDRV_Free(hMidiIn, wmld);
2683 return dwRet;
2686 /**************************************************************************
2687 * midiInClose [MMSYSTEM.305]
2689 UINT16 WINAPI midiInClose16(HMIDIIN16 hMidiIn)
2691 return midiInClose(hMidiIn);
2694 /**************************************************************************
2695 * midiInPrepareHeader [WINMM.67]
2697 UINT WINAPI midiInPrepareHeader(HMIDIIN hMidiIn,
2698 MIDIHDR* lpMidiInHdr, UINT uSize)
2700 LPWINE_MLD wmld;
2702 TRACE("(%04X, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
2704 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
2705 return MMSYSERR_INVALHANDLE;
2707 return MMDRV_Message(wmld, MIDM_PREPARE, (DWORD)lpMidiInHdr, uSize, TRUE);
2710 /**************************************************************************
2711 * midiInPrepareHeader [MMSYSTEM.306]
2713 UINT16 WINAPI midiInPrepareHeader16(HMIDIIN16 hMidiIn,
2714 MIDIHDR16* /*SEGPTR*/ lpsegMidiInHdr,
2715 UINT16 uSize)
2717 LPWINE_MLD wmld;
2719 TRACE("(%04X, %p, %d)\n", hMidiIn, lpsegMidiInHdr, uSize);
2721 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
2722 return MMSYSERR_INVALHANDLE;
2724 return MMDRV_Message(wmld, MIDM_PREPARE, (DWORD)lpsegMidiInHdr, uSize, FALSE);
2727 /**************************************************************************
2728 * midiInUnprepareHeader [WINMM.71]
2730 UINT WINAPI midiInUnprepareHeader(HMIDIIN hMidiIn,
2731 MIDIHDR* lpMidiInHdr, UINT uSize)
2733 LPWINE_MLD wmld;
2735 TRACE("(%04X, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
2737 if (!(lpMidiInHdr->dwFlags & MHDR_PREPARED)) {
2738 return MMSYSERR_NOERROR;
2741 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
2742 return MMSYSERR_INVALHANDLE;
2744 return MMDRV_Message(wmld, MIDM_UNPREPARE, (DWORD)lpMidiInHdr, uSize, TRUE);
2747 /**************************************************************************
2748 * midiInUnprepareHeader [MMSYSTEM.307]
2750 UINT16 WINAPI midiInUnprepareHeader16(HMIDIIN16 hMidiIn,
2751 MIDIHDR16* /* SEGPTR */ lpsegMidiInHdr,
2752 UINT16 uSize)
2754 LPWINE_MLD wmld;
2755 LPMIDIHDR16 lpMidiInHdr = PTR_SEG_TO_LIN(lpsegMidiInHdr);
2757 TRACE("(%04X, %p, %d)\n", hMidiIn, lpsegMidiInHdr, uSize);
2759 if (!(lpMidiInHdr->dwFlags & MHDR_PREPARED)) {
2760 return MMSYSERR_NOERROR;
2763 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
2764 return MMSYSERR_INVALHANDLE;
2766 return MMDRV_Message(wmld, MIDM_UNPREPARE, (DWORD)lpsegMidiInHdr, uSize, FALSE);
2769 /**************************************************************************
2770 * midiInAddBuffer [WINMM.57]
2772 UINT WINAPI midiInAddBuffer(HMIDIIN hMidiIn,
2773 MIDIHDR* lpMidiInHdr, UINT uSize)
2775 LPWINE_MLD wmld;
2777 TRACE("(%04X, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
2779 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
2780 return MMSYSERR_INVALHANDLE;
2782 return MMDRV_Message(wmld, MIDM_ADDBUFFER, (DWORD)lpMidiInHdr, uSize, TRUE);
2785 /**************************************************************************
2786 * midiInAddBuffer [MMSYSTEM.308]
2788 UINT16 WINAPI midiInAddBuffer16(HMIDIIN16 hMidiIn,
2789 MIDIHDR16* /* SEGPTR */ lpsegMidiInHdr,
2790 UINT16 uSize)
2792 LPWINE_MLD wmld;
2794 TRACE("(%04X, %p, %d)\n", hMidiIn, lpsegMidiInHdr, uSize);
2796 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
2797 return MMSYSERR_INVALHANDLE;
2799 return MMDRV_Message(wmld, MIDM_ADDBUFFER, (DWORD)lpsegMidiInHdr, uSize, FALSE);
2802 /**************************************************************************
2803 * midiInStart [WINMM.69]
2805 UINT WINAPI midiInStart(HMIDIIN hMidiIn)
2807 LPWINE_MLD wmld;
2809 TRACE("(%04X)\n", hMidiIn);
2811 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
2812 return MMSYSERR_INVALHANDLE;
2814 return MMDRV_Message(wmld, MIDM_START, 0L, 0L, TRUE);
2817 /**************************************************************************
2818 * midiInStart [MMSYSTEM.309]
2820 UINT16 WINAPI midiInStart16(HMIDIIN16 hMidiIn)
2822 return midiInStart(hMidiIn);
2825 /**************************************************************************
2826 * midiInStop [WINMM.70]
2828 UINT WINAPI midiInStop(HMIDIIN hMidiIn)
2830 LPWINE_MLD wmld;
2832 TRACE("(%04X)\n", hMidiIn);
2834 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
2835 return MMSYSERR_INVALHANDLE;
2837 return MMDRV_Message(wmld, MIDM_STOP, 0L, 0L, TRUE);
2840 /**************************************************************************
2841 * midiInStop [MMSYSTEM.310]
2843 UINT16 WINAPI midiInStop16(HMIDIIN16 hMidiIn)
2845 return midiInStop(hMidiIn);
2848 /**************************************************************************
2849 * midiInReset [WINMM.68]
2851 UINT WINAPI midiInReset(HMIDIIN hMidiIn)
2853 LPWINE_MLD wmld;
2855 TRACE("(%04X)\n", hMidiIn);
2857 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
2858 return MMSYSERR_INVALHANDLE;
2860 return MMDRV_Message(wmld, MIDM_RESET, 0L, 0L, TRUE);
2863 /**************************************************************************
2864 * midiInReset [MMSYSTEM.311]
2866 UINT16 WINAPI midiInReset16(HMIDIIN16 hMidiIn)
2868 return midiInReset(hMidiIn);
2871 /**************************************************************************
2872 * midiInGetID [WINMM.63]
2874 UINT WINAPI midiInGetID(HMIDIIN hMidiIn, UINT* lpuDeviceID)
2876 LPWINE_MLD wmld;
2878 TRACE("(%04X, %p)\n", hMidiIn, lpuDeviceID);
2880 if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
2882 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, TRUE)) == NULL)
2883 return MMSYSERR_INVALHANDLE;
2885 *lpuDeviceID = wmld->uDeviceID;
2887 return MMSYSERR_NOERROR;
2890 /**************************************************************************
2891 * midiInGetID [MMSYSTEM.312]
2893 UINT16 WINAPI midiInGetID16(HMIDIIN16 hMidiIn, UINT16* lpuDeviceID)
2895 LPWINE_MLD wmld;
2897 TRACE("(%04X, %p)\n", hMidiIn, lpuDeviceID);
2899 if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
2901 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, TRUE)) == NULL)
2902 return MMSYSERR_INVALHANDLE;
2904 *lpuDeviceID = wmld->uDeviceID;
2906 return MMSYSERR_NOERROR;
2909 /**************************************************************************
2910 * midiInMessage [WINMM.65]
2912 DWORD WINAPI midiInMessage(HMIDIIN hMidiIn, UINT uMessage,
2913 DWORD dwParam1, DWORD dwParam2)
2915 LPWINE_MLD wmld;
2917 TRACE("(%04X, %04X, %08lX, %08lX)\n", hMidiIn, uMessage, dwParam1, dwParam2);
2919 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
2920 return MMSYSERR_INVALHANDLE;
2922 switch (uMessage) {
2923 case MIDM_OPEN:
2924 case MIDM_CLOSE:
2925 FIXME("can't handle OPEN or CLOSE message!\n");
2926 return MMSYSERR_NOTSUPPORTED;
2928 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
2931 /**************************************************************************
2932 * midiInMessage [MMSYSTEM.313]
2934 DWORD WINAPI midiInMessage16(HMIDIIN16 hMidiIn, UINT16 uMessage,
2935 DWORD dwParam1, DWORD dwParam2)
2937 LPWINE_MLD wmld;
2939 TRACE("(%04X, %04X, %08lX, %08lX)\n", hMidiIn, uMessage, dwParam1, dwParam2);
2941 switch (uMessage) {
2942 case MIDM_OPEN:
2943 case MIDM_CLOSE:
2944 FIXME("can't handle OPEN or CLOSE message!\n");
2945 return MMSYSERR_NOTSUPPORTED;
2947 case MIDM_GETDEVCAPS:
2948 return midiInGetDevCaps16(hMidiIn, (LPMIDIINCAPS16)PTR_SEG_TO_LIN(dwParam1), dwParam2);
2949 case MIDM_PREPARE:
2950 return midiInPrepareHeader16(hMidiIn, (LPMIDIHDR16)PTR_SEG_TO_LIN(dwParam1), dwParam2);
2951 case MIDM_UNPREPARE:
2952 return midiInUnprepareHeader16(hMidiIn, (LPMIDIHDR16)PTR_SEG_TO_LIN(dwParam1), dwParam2);
2953 case MIDM_ADDBUFFER:
2954 return midiInAddBuffer16(hMidiIn, (LPMIDIHDR16)PTR_SEG_TO_LIN(dwParam1), dwParam2);
2957 if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
2958 return MMSYSERR_INVALHANDLE;
2960 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, FALSE);
2963 typedef struct WINE_MIDIStream {
2964 HMIDIOUT hDevice;
2965 HANDLE hThread;
2966 DWORD dwThreadID;
2967 DWORD dwTempo;
2968 DWORD dwTimeDiv;
2969 DWORD dwPositionMS;
2970 DWORD dwPulses;
2971 DWORD dwStartTicks;
2972 WORD wFlags;
2973 HANDLE hEvent;
2974 LPMIDIHDR lpMidiHdr;
2975 } WINE_MIDIStream;
2977 #define WINE_MSM_HEADER (WM_USER+0)
2978 #define WINE_MSM_STOP (WM_USER+1)
2980 /**************************************************************************
2981 * MMSYSTEM_GetMidiStream [internal]
2983 static BOOL MMSYSTEM_GetMidiStream(HMIDISTRM hMidiStrm, WINE_MIDIStream** lpMidiStrm, WINE_MIDI** lplpwm)
2985 WINE_MIDI* lpwm = (LPWINE_MIDI)MMDRV_Get(hMidiStrm, MMDRV_MIDIOUT, FALSE);
2987 if (lplpwm)
2988 *lplpwm = lpwm;
2990 if (lpwm == NULL) {
2991 return FALSE;
2994 *lpMidiStrm = (WINE_MIDIStream*)lpwm->mod.rgIds.dwStreamID;
2996 return *lpMidiStrm != NULL;
2999 /**************************************************************************
3000 * MMSYSTEM_MidiStream_Convert [internal]
3002 static DWORD MMSYSTEM_MidiStream_Convert(WINE_MIDIStream* lpMidiStrm, DWORD pulse)
3004 DWORD ret = 0;
3006 if (lpMidiStrm->dwTimeDiv == 0) {
3007 FIXME("Shouldn't happen. lpMidiStrm->dwTimeDiv = 0\n");
3008 } else if (lpMidiStrm->dwTimeDiv > 0x8000) { /* SMPTE, unchecked FIXME? */
3009 int nf = -(char)HIBYTE(lpMidiStrm->dwTimeDiv); /* number of frames */
3010 int nsf = LOBYTE(lpMidiStrm->dwTimeDiv); /* number of sub-frames */
3011 ret = (pulse * 1000) / (nf * nsf);
3012 } else {
3013 ret = (DWORD)((double)pulse * ((double)lpMidiStrm->dwTempo / 1000) /
3014 (double)lpMidiStrm->dwTimeDiv);
3017 return ret;
3020 /**************************************************************************
3021 * MMSYSTEM_MidiStream_MessageHandler [internal]
3023 static BOOL MMSYSTEM_MidiStream_MessageHandler(WINE_MIDIStream* lpMidiStrm, LPWINE_MIDI lpwm, LPMSG msg)
3025 LPMIDIHDR lpMidiHdr;
3026 LPMIDIHDR* lpmh;
3027 LPBYTE lpData;
3029 switch (msg->message) {
3030 case WM_QUIT:
3031 SetEvent(lpMidiStrm->hEvent);
3032 return FALSE;
3033 case WINE_MSM_STOP:
3034 TRACE("STOP\n");
3035 /* this is not quite what MS doc says... */
3036 midiOutReset(lpMidiStrm->hDevice);
3037 /* empty list of already submitted buffers */
3038 for (lpMidiHdr = lpMidiStrm->lpMidiHdr; lpMidiHdr; lpMidiHdr = (LPMIDIHDR)lpMidiHdr->lpNext) {
3039 lpMidiHdr->dwFlags |= MHDR_DONE;
3040 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
3042 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags, lpMidiStrm->hDevice,
3043 MM_MOM_DONE, lpwm->mod.dwInstance, (DWORD)lpMidiHdr, 0L);
3045 lpMidiStrm->lpMidiHdr = 0;
3046 SetEvent(lpMidiStrm->hEvent);
3047 break;
3048 case WINE_MSM_HEADER:
3049 /* sets initial tick count for first MIDIHDR */
3050 if (!lpMidiStrm->dwStartTicks)
3051 lpMidiStrm->dwStartTicks = GetTickCount();
3053 /* FIXME(EPP): "I don't understand the content of the first MIDIHDR sent
3054 * by native mcimidi, it doesn't look like a correct one".
3055 * this trick allows to throw it away... but I don't like it.
3056 * It looks like part of the file I'm trying to play and definitively looks
3057 * like raw midi content
3058 * I'd really like to understand why native mcimidi sends it. Perhaps a bad
3059 * synchronization issue where native mcimidi is still processing raw MIDI
3060 * content before generating MIDIEVENTs ?
3062 * 4c 04 89 3b 00 81 7c 99 3b 43 00 99 23 5e 04 89 L..;..|.;C..#^..
3063 * 3b 00 00 89 23 00 7c 99 3b 45 00 99 28 62 04 89 ;...#.|.;E..(b..
3064 * 3b 00 00 89 28 00 81 7c 99 3b 4e 00 99 23 5e 04 ;...(..|.;N..#^.
3065 * 89 3b 00 00 89 23 00 7c 99 3b 45 00 99 23 78 04 .;...#.|.;E..#x.
3066 * 89 3b 00 00 89 23 00 81 7c 99 3b 48 00 99 23 5e .;...#..|.;H..#^
3067 * 04 89 3b 00 00 89 23 00 7c 99 3b 4e 00 99 28 62 ..;...#.|.;N..(b
3068 * 04 89 3b 00 00 89 28 00 81 7c 99 39 4c 00 99 23 ..;...(..|.9L..#
3069 * 5e 04 89 39 00 00 89 23 00 82 7c 99 3b 4c 00 99 ^..9...#..|.;L..
3070 * 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 00 99 #^..;...#.|.;H..
3071 * 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b 3f 04 (b..;...(..|.;?.
3072 * 89 3b 00 1c 99 23 5e 04 89 23 00 5c 99 3b 45 00 .;...#^..#.\.;E.
3073 * 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 3b 46 .#x..;...#..|.;F
3074 * 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 ..#^..;...#.|.;H
3075 * 00 99 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b ..(b..;...(..|.;
3076 * 46 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b F..#^..;...#.|.;
3077 * 48 00 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 H..#x..;...#..|.
3078 * 3b 4c 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 ;L..#^..;...#.|.
3080 lpMidiHdr = (LPMIDIHDR)msg->lParam;
3081 lpData = lpMidiHdr->lpData;
3082 TRACE("Adding %s lpMidiHdr=%p [lpData=0x%08lx dwBufferLength=%lu/%lu dwFlags=0x%08lx size=%u]\n",
3083 (lpMidiHdr->dwFlags & MHDR_ISSTRM) ? "stream" : "regular", lpMidiHdr,
3084 (DWORD)lpMidiHdr, lpMidiHdr->dwBufferLength, lpMidiHdr->dwBytesRecorded,
3085 lpMidiHdr->dwFlags, msg->wParam);
3086 #if 0
3087 /* dumps content of lpMidiHdr->lpData
3088 * FIXME: there should be a debug routine somewhere that already does this
3089 * I hate spreading this type of shit all around the code
3091 for (dwToGo = 0; dwToGo < lpMidiHdr->dwBufferLength; dwToGo += 16) {
3092 DWORD i;
3093 BYTE ch;
3095 for (i = 0; i < MIN(16, lpMidiHdr->dwBufferLength - dwToGo); i++)
3096 printf("%02x ", lpData[dwToGo + i]);
3097 for (; i < 16; i++)
3098 printf(" ");
3099 for (i = 0; i < MIN(16, lpMidiHdr->dwBufferLength - dwToGo); i++) {
3100 ch = lpData[dwToGo + i];
3101 printf("%c", (ch >= 0x20 && ch <= 0x7F) ? ch : '.');
3103 printf("\n");
3105 #endif
3106 if (((LPMIDIEVENT)lpData)->dwStreamID != 0 &&
3107 ((LPMIDIEVENT)lpData)->dwStreamID != 0xFFFFFFFF &&
3108 ((LPMIDIEVENT)lpData)->dwStreamID != (DWORD)lpMidiStrm) {
3109 FIXME("Dropping bad %s lpMidiHdr (streamID=%08lx)\n",
3110 (lpMidiHdr->dwFlags & MHDR_ISSTRM) ? "stream" : "regular",
3111 ((LPMIDIEVENT)lpData)->dwStreamID);
3112 lpMidiHdr->dwFlags |= MHDR_DONE;
3113 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
3115 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags, lpMidiStrm->hDevice,
3116 MM_MOM_DONE, lpwm->mod.dwInstance, (DWORD)lpMidiHdr, 0L);
3117 break;
3120 for (lpmh = &lpMidiStrm->lpMidiHdr; *lpmh; lpmh = (LPMIDIHDR*)&((*lpmh)->lpNext));
3121 *lpmh = lpMidiHdr;
3122 lpMidiHdr = (LPMIDIHDR)msg->lParam;
3123 lpMidiHdr->lpNext = 0;
3124 lpMidiHdr->dwFlags |= MHDR_INQUEUE;
3125 lpMidiHdr->dwFlags &= MHDR_DONE;
3126 lpMidiHdr->dwOffset = 0;
3128 break;
3129 default:
3130 FIXME("Unknown message %d\n", msg->message);
3131 break;
3133 return TRUE;
3136 /**************************************************************************
3137 * MMSYSTEM_MidiStream_Player [internal]
3139 static DWORD CALLBACK MMSYSTEM_MidiStream_Player(LPVOID pmt)
3141 WINE_MIDIStream* lpMidiStrm = pmt;
3142 WINE_MIDI* lpwm;
3143 MSG msg;
3144 DWORD dwToGo;
3145 DWORD dwCurrTC;
3146 LPMIDIHDR lpMidiHdr;
3147 LPMIDIEVENT me;
3148 LPBYTE lpData = 0;
3150 TRACE("(%p)!\n", lpMidiStrm);
3152 if (!lpMidiStrm ||
3153 (lpwm = (LPWINE_MIDI)MMDRV_Get(lpMidiStrm->hDevice, MMDRV_MIDIOUT, FALSE)) == NULL)
3154 goto the_end;
3156 /* force thread's queue creation */
3157 /* Used to be InitThreadInput16(0, 5); */
3158 /* but following works also with hack in midiStreamOpen */
3159 Callout.PeekMessageA(&msg, 0, 0, 0, 0);
3161 /* FIXME: this next line must be called before midiStreamOut or midiStreamRestart are called */
3162 SetEvent(lpMidiStrm->hEvent);
3163 TRACE("Ready to go 1\n");
3164 /* thread is started in paused mode */
3165 SuspendThread(lpMidiStrm->hThread);
3166 TRACE("Ready to go 2\n");
3168 lpMidiStrm->dwStartTicks = 0;
3169 lpMidiStrm->dwPulses = 0;
3171 lpMidiStrm->lpMidiHdr = 0;
3173 for (;;) {
3174 lpMidiHdr = lpMidiStrm->lpMidiHdr;
3175 if (!lpMidiHdr) {
3176 /* for first message, block until one arrives, then process all that are available */
3177 Callout.GetMessageA(&msg, 0, 0, 0);
3178 do {
3179 if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm, lpwm, &msg))
3180 goto the_end;
3181 } while (Callout.PeekMessageA(&msg, 0, 0, 0, PM_REMOVE));
3182 lpData = 0;
3183 continue;
3186 if (!lpData)
3187 lpData = lpMidiHdr->lpData;
3189 me = (LPMIDIEVENT)(lpData + lpMidiHdr->dwOffset);
3191 /* do we have to wait ? */
3192 if (me->dwDeltaTime) {
3193 lpMidiStrm->dwPositionMS += MMSYSTEM_MidiStream_Convert(lpMidiStrm, me->dwDeltaTime);
3194 lpMidiStrm->dwPulses += me->dwDeltaTime;
3196 dwToGo = lpMidiStrm->dwStartTicks + lpMidiStrm->dwPositionMS;
3198 TRACE("%ld/%ld/%ld\n", dwToGo, GetTickCount(), me->dwDeltaTime);
3199 while ((dwCurrTC = GetTickCount()) < dwToGo) {
3200 if (MsgWaitForMultipleObjects(0, NULL, FALSE, dwToGo - dwCurrTC, QS_ALLINPUT) == WAIT_OBJECT_0) {
3201 /* got a message, handle it */
3202 while (Callout.PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) {
3203 if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm, lpwm, &msg))
3204 goto the_end;
3206 lpData = 0;
3207 } else {
3208 /* timeout, so me->dwDeltaTime is elapsed, can break the while loop */
3209 break;
3213 switch (MEVT_EVENTTYPE(me->dwEvent & ~MEVT_F_CALLBACK)) {
3214 case MEVT_COMMENT:
3215 FIXME("NIY: MEVT_COMMENT\n");
3216 /* do nothing, skip bytes */
3217 break;
3218 case MEVT_LONGMSG:
3219 FIXME("NIY: MEVT_LONGMSG, aka sending Sysex event\n");
3220 break;
3221 case MEVT_NOP:
3222 break;
3223 case MEVT_SHORTMSG:
3224 midiOutShortMsg(lpMidiStrm->hDevice, MEVT_EVENTPARM(me->dwEvent));
3225 break;
3226 case MEVT_TEMPO:
3227 lpMidiStrm->dwTempo = MEVT_EVENTPARM(me->dwEvent);
3228 break;
3229 case MEVT_VERSION:
3230 break;
3231 default:
3232 FIXME("Unknown MEVT (0x%02x)\n", MEVT_EVENTTYPE(me->dwEvent & ~MEVT_F_CALLBACK));
3233 break;
3235 if (me->dwEvent & MEVT_F_CALLBACK) {
3236 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags, lpMidiStrm->hDevice,
3237 MM_MOM_POSITIONCB, lpwm->mod.dwInstance, (LPARAM)lpMidiHdr, 0L);
3239 lpMidiHdr->dwOffset += sizeof(MIDIEVENT);
3240 if (me->dwEvent & MEVT_F_LONG)
3241 lpMidiHdr->dwOffset += (MEVT_EVENTPARM(me->dwEvent) + 3) & ~3;
3242 if (lpMidiHdr->dwOffset >= lpMidiHdr->dwBufferLength) {
3243 /* done with this header */
3244 lpMidiHdr->dwFlags |= MHDR_DONE;
3245 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
3247 lpMidiStrm->lpMidiHdr = (LPMIDIHDR)lpMidiHdr->lpNext;
3248 DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags, lpMidiStrm->hDevice,
3249 MM_MOM_DONE, lpwm->mod.dwInstance, (DWORD)lpMidiHdr, 0L);
3250 lpData = 0;
3253 the_end:
3254 TRACE("End of thread\n");
3255 ExitThread(0);
3256 return 0; /* for removing the warning, never executed */
3259 /**************************************************************************
3260 * MMSYSTEM_MidiStream_PostMessage [internal]
3262 static BOOL MMSYSTEM_MidiStream_PostMessage(WINE_MIDIStream* lpMidiStrm, WORD msg, DWORD pmt1, DWORD pmt2)
3264 if (Callout.PostThreadMessageA(lpMidiStrm->dwThreadID, msg, pmt1, pmt2)) {
3265 DWORD count;
3266 BOOL bHasWin16Lock;
3268 /* FIXME: should use the new syslevel APIs */
3269 if ((bHasWin16Lock = _ConfirmWin16Lock()) != 0) {
3270 ReleaseThunkLock(&count);
3272 WaitForSingleObject(lpMidiStrm->hEvent, INFINITE);
3273 if (bHasWin16Lock) {
3274 RestoreThunkLock(count);
3276 } else {
3277 WARN("bad PostThreadMessageA\n");
3278 return FALSE;
3280 return TRUE;
3283 /**************************************************************************
3284 * midiStreamClose [WINMM.90]
3286 MMRESULT WINAPI midiStreamClose(HMIDISTRM hMidiStrm)
3288 WINE_MIDIStream* lpMidiStrm;
3290 TRACE("(%08x)!\n", hMidiStrm);
3292 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL))
3293 return MMSYSERR_INVALHANDLE;
3295 midiStreamStop(hMidiStrm);
3296 MMSYSTEM_MidiStream_PostMessage(lpMidiStrm, WM_QUIT, 0, 0);
3297 HeapFree(GetProcessHeap(), 0, lpMidiStrm);
3298 CloseHandle(lpMidiStrm->hEvent);
3300 return midiOutClose(hMidiStrm);
3303 /**************************************************************************
3304 * MMSYSTEM_MidiStream_Open [internal]
3306 static MMRESULT WINAPI MMSYSTEM_MidiStream_Open(HMIDISTRM* lphMidiStrm, LPUINT lpuDeviceID,
3307 DWORD cMidi, DWORD dwCallback,
3308 DWORD dwInstance, DWORD fdwOpen, BOOL bFrom32)
3310 WINE_MIDIStream* lpMidiStrm;
3311 MMRESULT ret;
3312 MIDIOPENSTRMID mosm;
3313 LPWINE_MIDI lpwm;
3314 HMIDIOUT hMidiOut;
3316 TRACE("(%p, %p, %ld, 0x%08lx, 0x%08lx, 0x%08lx)!\n",
3317 lphMidiStrm, lpuDeviceID, cMidi, dwCallback, dwInstance, fdwOpen);
3319 if (cMidi != 1 || lphMidiStrm == NULL || lpuDeviceID == NULL)
3320 return MMSYSERR_INVALPARAM;
3322 lpMidiStrm = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_MIDIStream));
3323 if (!lpMidiStrm)
3324 return MMSYSERR_NOMEM;
3326 lpMidiStrm->dwTempo = 500000;
3327 lpMidiStrm->dwTimeDiv = 480; /* 480 is 120 quater notes per minute *//* FIXME ??*/
3328 lpMidiStrm->dwPositionMS = 0;
3330 mosm.dwStreamID = (DWORD)lpMidiStrm;
3331 /* FIXME: the correct value is not allocated yet for MAPPER */
3332 mosm.wDeviceID = *lpuDeviceID;
3333 lpwm = MIDI_OutAlloc(&hMidiOut, &dwCallback, &dwInstance, &fdwOpen, 1, &mosm, bFrom32);
3334 lpMidiStrm->hDevice = hMidiOut;
3335 if (lphMidiStrm)
3336 *lphMidiStrm = hMidiOut;
3338 /* FIXME: is lpuDevice initialized upon entering midiStreamOpen ? */
3339 FIXME("*lpuDeviceID=%u\n", *lpuDeviceID);
3340 lpwm->mld.uDeviceID = *lpuDeviceID = 0;
3342 ret = MMDRV_Open(&lpwm->mld, MODM_OPEN, (DWORD)&lpwm->mod, fdwOpen);
3343 lpMidiStrm->hEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
3344 lpMidiStrm->wFlags = HIWORD(fdwOpen);
3346 lpMidiStrm->hThread = CreateThread(NULL, 0, MMSYSTEM_MidiStream_Player,
3347 lpMidiStrm, 0, &(lpMidiStrm->dwThreadID));
3349 if (!lpMidiStrm->hThread) {
3350 midiStreamClose((HMIDISTRM)hMidiOut);
3351 return MMSYSERR_NOMEM;
3354 /* wait for thread to have started, and for it's queue to be created */
3356 DWORD count;
3357 BOOL bHasWin16Lock;
3359 /* (Release|Restore)ThunkLock() is needed when this method is called from 16 bit code,
3360 * (meaning the Win16Lock is set), so that it's released and the 32 bit thread running
3361 * MMSYSTEM_MidiStreamPlayer can acquire Win16Lock to create its queue.
3363 if ((bHasWin16Lock = _ConfirmWin16Lock()) != 0) {
3364 ReleaseThunkLock(&count);
3366 WaitForSingleObject(lpMidiStrm->hEvent, INFINITE);
3367 if (bHasWin16Lock) {
3368 RestoreThunkLock(count);
3372 TRACE("=> (%u/%d) hMidi=0x%04x ret=%d lpMidiStrm=%p\n",
3373 *lpuDeviceID, lpwm->mld.uDeviceID, *lphMidiStrm, ret, lpMidiStrm);
3374 return ret;
3377 /**************************************************************************
3378 * midiStreamOpen [WINMM.91]
3380 MMRESULT WINAPI midiStreamOpen(HMIDISTRM* lphMidiStrm, LPUINT lpuDeviceID,
3381 DWORD cMidi, DWORD dwCallback,
3382 DWORD dwInstance, DWORD fdwOpen)
3384 return MMSYSTEM_MidiStream_Open(lphMidiStrm, lpuDeviceID, cMidi, dwCallback,
3385 dwInstance, fdwOpen, TRUE);
3388 /**************************************************************************
3389 * midiStreamOut [WINMM.92]
3391 MMRESULT WINAPI midiStreamOut(HMIDISTRM hMidiStrm, LPMIDIHDR lpMidiHdr,
3392 UINT cbMidiHdr)
3394 WINE_MIDIStream* lpMidiStrm;
3395 DWORD ret = MMSYSERR_NOERROR;
3397 TRACE("(%08x, %p, %u)!\n", hMidiStrm, lpMidiHdr, cbMidiHdr);
3399 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
3400 ret = MMSYSERR_INVALHANDLE;
3401 } else {
3402 if (!Callout.PostThreadMessageA(lpMidiStrm->dwThreadID,
3403 WINE_MSM_HEADER, cbMidiHdr,
3404 (DWORD)lpMidiHdr)) {
3405 WARN("bad PostThreadMessageA\n");
3406 ret = MMSYSERR_ERROR;
3409 return ret;
3412 /**************************************************************************
3413 * midiStreamPause [WINMM.93]
3415 MMRESULT WINAPI midiStreamPause(HMIDISTRM hMidiStrm)
3417 WINE_MIDIStream* lpMidiStrm;
3418 DWORD ret = MMSYSERR_NOERROR;
3420 TRACE("(%08x)!\n", hMidiStrm);
3422 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
3423 ret = MMSYSERR_INVALHANDLE;
3424 } else {
3425 if (SuspendThread(lpMidiStrm->hThread) == 0xFFFFFFFF) {
3426 WARN("bad Suspend (%ld)\n", GetLastError());
3427 ret = MMSYSERR_ERROR;
3430 return ret;
3433 /**************************************************************************
3434 * midiStreamPosition [WINMM.94]
3436 MMRESULT WINAPI midiStreamPosition(HMIDISTRM hMidiStrm, LPMMTIME lpMMT, UINT cbmmt)
3438 WINE_MIDIStream* lpMidiStrm;
3439 DWORD ret = MMSYSERR_NOERROR;
3441 TRACE("(%08x, %p, %u)!\n", hMidiStrm, lpMMT, cbmmt);
3443 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
3444 ret = MMSYSERR_INVALHANDLE;
3445 } else if (lpMMT == NULL || cbmmt != sizeof(MMTIME)) {
3446 ret = MMSYSERR_INVALPARAM;
3447 } else {
3448 switch (lpMMT->wType) {
3449 case TIME_MS:
3450 lpMMT->u.ms = lpMidiStrm->dwPositionMS;
3451 TRACE("=> %ld ms\n", lpMMT->u.ms);
3452 break;
3453 case TIME_TICKS:
3454 lpMMT->u.ticks = lpMidiStrm->dwPulses;
3455 TRACE("=> %ld ticks\n", lpMMT->u.ticks);
3456 break;
3457 default:
3458 WARN("Unsupported time type %d\n", lpMMT->wType);
3459 lpMMT->wType = TIME_MS;
3460 ret = MMSYSERR_INVALPARAM;
3461 break;
3464 return ret;
3467 /**************************************************************************
3468 * midiStreamProperty [WINMM.95]
3470 MMRESULT WINAPI midiStreamProperty(HMIDISTRM hMidiStrm, LPBYTE lpPropData, DWORD dwProperty)
3472 WINE_MIDIStream* lpMidiStrm;
3473 MMRESULT ret = MMSYSERR_NOERROR;
3475 TRACE("(%08x, %p, %lx)\n", hMidiStrm, lpPropData, dwProperty);
3477 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
3478 ret = MMSYSERR_INVALHANDLE;
3479 } else if ((dwProperty & (MIDIPROP_GET|MIDIPROP_SET)) == 0) {
3480 ret = MMSYSERR_INVALPARAM;
3481 } else if (dwProperty & MIDIPROP_TEMPO) {
3482 MIDIPROPTEMPO* mpt = (MIDIPROPTEMPO*)lpPropData;
3484 if (sizeof(MIDIPROPTEMPO) != mpt->cbStruct) {
3485 ret = MMSYSERR_INVALPARAM;
3486 } else if (dwProperty & MIDIPROP_SET) {
3487 lpMidiStrm->dwTempo = mpt->dwTempo;
3488 TRACE("Setting tempo to %ld\n", mpt->dwTempo);
3489 } else if (dwProperty & MIDIPROP_GET) {
3490 mpt->dwTempo = lpMidiStrm->dwTempo;
3491 TRACE("Getting tempo <= %ld\n", mpt->dwTempo);
3493 } else if (dwProperty & MIDIPROP_TIMEDIV) {
3494 MIDIPROPTIMEDIV* mptd = (MIDIPROPTIMEDIV*)lpPropData;
3496 if (sizeof(MIDIPROPTIMEDIV) != mptd->cbStruct) {
3497 ret = MMSYSERR_INVALPARAM;
3498 } else if (dwProperty & MIDIPROP_SET) {
3499 lpMidiStrm->dwTimeDiv = mptd->dwTimeDiv;
3500 TRACE("Setting time div to %ld\n", mptd->dwTimeDiv);
3501 } else if (dwProperty & MIDIPROP_GET) {
3502 mptd->dwTimeDiv = lpMidiStrm->dwTimeDiv;
3503 TRACE("Getting time div <= %ld\n", mptd->dwTimeDiv);
3505 } else {
3506 ret = MMSYSERR_INVALPARAM;
3509 return ret;
3512 /**************************************************************************
3513 * midiStreamRestart [WINMM.96]
3515 MMRESULT WINAPI midiStreamRestart(HMIDISTRM hMidiStrm)
3517 WINE_MIDIStream* lpMidiStrm;
3518 MMRESULT ret = MMSYSERR_NOERROR;
3520 TRACE("(%08x)!\n", hMidiStrm);
3522 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
3523 ret = MMSYSERR_INVALHANDLE;
3524 } else {
3525 DWORD ret;
3527 /* since we increase the thread suspend count on each midiStreamPause
3528 * there may be a need for several midiStreamResume
3530 do {
3531 ret = ResumeThread(lpMidiStrm->hThread);
3532 } while (ret != 0xFFFFFFFF && ret != 0);
3533 if (ret == 0xFFFFFFFF) {
3534 WARN("bad Resume (%ld)\n", GetLastError());
3535 ret = MMSYSERR_ERROR;
3536 } else {
3537 lpMidiStrm->dwStartTicks = GetTickCount() - lpMidiStrm->dwPositionMS;
3540 return ret;
3543 /**************************************************************************
3544 * midiStreamStop [WINMM.97]
3546 MMRESULT WINAPI midiStreamStop(HMIDISTRM hMidiStrm)
3548 WINE_MIDIStream* lpMidiStrm;
3549 MMRESULT ret = MMSYSERR_NOERROR;
3551 TRACE("(%08x)!\n", hMidiStrm);
3553 if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
3554 ret = MMSYSERR_INVALHANDLE;
3555 } else {
3556 /* in case stream has been paused... FIXME is the current state correct ? */
3557 midiStreamRestart(hMidiStrm);
3558 MMSYSTEM_MidiStream_PostMessage(lpMidiStrm, WINE_MSM_STOP, 0, 0);
3560 return ret;
3563 /**************************************************************************
3564 * midiStreamClose [MMSYSTEM.252]
3566 MMRESULT16 WINAPI midiStreamClose16(HMIDISTRM16 hMidiStrm)
3568 return midiStreamClose(hMidiStrm);
3571 /**************************************************************************
3572 * midiStreamOpen [MMSYSTEM.251]
3574 MMRESULT16 WINAPI midiStreamOpen16(HMIDISTRM16* phMidiStrm, LPUINT16 devid,
3575 DWORD cMidi, DWORD dwCallback,
3576 DWORD dwInstance, DWORD fdwOpen)
3578 HMIDISTRM hMidiStrm32;
3579 MMRESULT ret;
3580 UINT devid32;
3582 if (!phMidiStrm || !devid)
3583 return MMSYSERR_INVALPARAM;
3584 devid32 = *devid;
3585 ret = MMSYSTEM_MidiStream_Open(&hMidiStrm32, &devid32, cMidi, dwCallback,
3586 dwInstance, fdwOpen, FALSE);
3587 *phMidiStrm = hMidiStrm32;
3588 *devid = devid32;
3589 return ret;
3592 /**************************************************************************
3593 * midiStreamOut [MMSYSTEM.254]
3595 MMRESULT16 WINAPI midiStreamOut16(HMIDISTRM16 hMidiStrm, LPMIDIHDR16 lpMidiHdr, UINT16 cbMidiHdr)
3597 return midiStreamOut(hMidiStrm, (LPMIDIHDR)lpMidiHdr, cbMidiHdr);
3600 /**************************************************************************
3601 * midiStreamPause [MMSYSTEM.255]
3603 MMRESULT16 WINAPI midiStreamPause16(HMIDISTRM16 hMidiStrm)
3605 return midiStreamPause(hMidiStrm);
3608 /**************************************************************************
3609 * midiStreamPosition [MMSYSTEM.253]
3611 MMRESULT16 WINAPI midiStreamPosition16(HMIDISTRM16 hMidiStrm, LPMMTIME16 lpmmt16, UINT16 cbmmt)
3613 MMTIME mmt32;
3614 MMRESULT ret;
3616 if (!lpmmt16)
3617 return MMSYSERR_INVALPARAM;
3618 MMSYSTEM_MMTIME16to32(&mmt32, lpmmt16);
3619 ret = midiStreamPosition(hMidiStrm, &mmt32, sizeof(MMTIME));
3620 MMSYSTEM_MMTIME32to16(lpmmt16, &mmt32);
3621 return ret;
3624 /**************************************************************************
3625 * midiStreamProperty [MMSYSTEM.250]
3627 MMRESULT16 WINAPI midiStreamProperty16(HMIDISTRM16 hMidiStrm, LPBYTE lpPropData, DWORD dwProperty)
3629 return midiStreamProperty(hMidiStrm, lpPropData, dwProperty);
3632 /**************************************************************************
3633 * midiStreamRestart [MMSYSTEM.256]
3635 MMRESULT16 WINAPI midiStreamRestart16(HMIDISTRM16 hMidiStrm)
3637 return midiStreamRestart(hMidiStrm);
3640 /**************************************************************************
3641 * midiStreamStop [MMSYSTEM.257]
3643 MMRESULT16 WINAPI midiStreamStop16(HMIDISTRM16 hMidiStrm)
3645 return midiStreamStop(hMidiStrm);
3648 static UINT WINAPI MMSYSTEM_waveOpen(HANDLE* lphndl, UINT uDeviceID, UINT uType,
3649 const LPWAVEFORMATEX lpFormat,
3650 DWORD dwCallback, DWORD dwInstance,
3651 DWORD dwFlags, BOOL bFrom32)
3653 HANDLE handle;
3654 LPWINE_MLD wmld;
3655 DWORD dwRet = MMSYSERR_NOERROR;
3656 WAVEOPENDESC wod;
3658 TRACE("(%p, %d, %s, %p, %08lX, %08lX, %08lX, %d);\n",
3659 lphndl, (int)uDeviceID, (uType==MMDRV_WAVEOUT)?"Out":"In", lpFormat, dwCallback,
3660 dwInstance, dwFlags, bFrom32?32:16);
3662 if (dwFlags & WAVE_FORMAT_QUERY) TRACE("WAVE_FORMAT_QUERY requested !\n");
3664 if (lpFormat == NULL) return WAVERR_BADFORMAT;
3666 TRACE("wFormatTag=%u, nChannels=%u, nSamplesPerSec=%lu, nAvgBytesPerSec=%lu, nBlockAlign=%u, wBitsPerSample=%u, cbSize=%u\n",
3667 lpFormat->wFormatTag, lpFormat->nChannels, lpFormat->nSamplesPerSec,
3668 lpFormat->nAvgBytesPerSec, lpFormat->nBlockAlign, lpFormat->wBitsPerSample, lpFormat->cbSize);
3670 if ((wmld = MMDRV_Alloc(sizeof(WINE_WAVE), uType, &handle,
3671 &dwFlags, &dwCallback, &dwInstance, bFrom32)) == NULL)
3672 return MMSYSERR_NOMEM;
3674 wod.hWave = handle;
3675 wod.lpFormat = lpFormat; /* should the struct be copied iso pointer? */
3676 wod.dwCallback = dwCallback;
3677 wod.dwInstance = dwInstance;
3678 wod.uMappedDeviceID = 0;
3679 wod.dnDevNode = 0L;
3681 /* when called from 16 bit code, mapper will be 0x0000FFFF instead of 0xFFFFFFFF */
3682 /* this should fix it */
3683 wmld->uDeviceID = (uDeviceID == (UINT16)-1 && !bFrom32) ? (UINT)-1 : uDeviceID;
3685 dwRet = MMDRV_Open(wmld, (uType==MMDRV_WAVEOUT)?WODM_OPEN:WIDM_OPEN, (DWORD)&wod, dwFlags);
3687 if ((dwFlags & WAVE_FORMAT_QUERY) || dwRet != MMSYSERR_NOERROR) {
3688 MMDRV_Free(handle, wmld);
3689 handle = 0;
3692 if (lphndl != NULL) *lphndl = handle;
3693 TRACE("=> %ld hWave=%04x\n", dwRet, handle);
3695 return dwRet;
3698 /**************************************************************************
3699 * waveOutGetNumDevs [MMSYSTEM.401]
3701 UINT WINAPI waveOutGetNumDevs(void)
3703 return MMDRV_GetNum(MMDRV_WAVEOUT);
3706 /**************************************************************************
3707 * waveOutGetNumDevs [WINMM.167]
3709 UINT16 WINAPI waveOutGetNumDevs16(void)
3711 return MMDRV_GetNum(MMDRV_WAVEOUT);
3714 /**************************************************************************
3715 * waveOutGetDevCaps [MMSYSTEM.402]
3717 UINT16 WINAPI waveOutGetDevCaps16(UINT16 uDeviceID,
3718 LPWAVEOUTCAPS16 lpCaps, UINT16 uSize)
3720 WAVEOUTCAPSA wocA;
3721 UINT ret;
3723 TRACE("(%u %p %u)!\n", uDeviceID, lpCaps, uSize);
3724 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
3726 ret = waveOutGetDevCapsA(uDeviceID, &wocA, sizeof(wocA));
3728 if (ret == MMSYSERR_NOERROR) {
3729 lpCaps->wMid = wocA.wMid;
3730 lpCaps->wPid = wocA.wPid;
3731 lpCaps->vDriverVersion = wocA.vDriverVersion;
3732 strcpy(lpCaps->szPname, wocA.szPname);
3733 lpCaps->dwFormats = wocA.dwFormats;
3734 lpCaps->wChannels = wocA.wChannels;
3735 lpCaps->dwSupport = wocA.dwSupport;
3737 return ret;
3740 /**************************************************************************
3741 * waveOutGetDevCapsA [WINMM.162]
3743 UINT WINAPI waveOutGetDevCapsA(UINT uDeviceID, LPWAVEOUTCAPSA lpCaps,
3744 UINT uSize)
3746 LPWINE_MLD wmld;
3748 TRACE("(%u %p %u)!\n", uDeviceID, lpCaps, uSize);
3750 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
3752 if ((wmld = MMDRV_Get(uDeviceID, MMDRV_WAVEOUT, TRUE)) == NULL)
3753 return MMSYSERR_INVALHANDLE;
3755 return MMDRV_Message(wmld, WODM_GETDEVCAPS, (DWORD)lpCaps, uSize, TRUE);
3759 /**************************************************************************
3760 * waveOutGetDevCapsW [WINMM.163]
3762 UINT WINAPI waveOutGetDevCapsW(UINT uDeviceID, LPWAVEOUTCAPSW lpCaps,
3763 UINT uSize)
3765 WAVEOUTCAPSA wocA;
3766 UINT ret;
3768 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
3770 ret = waveOutGetDevCapsA(uDeviceID, &wocA, sizeof(wocA));
3772 if (ret == MMSYSERR_NOERROR) {
3773 lpCaps->wMid = wocA.wMid;
3774 lpCaps->wPid = wocA.wPid;
3775 lpCaps->vDriverVersion = wocA.vDriverVersion;
3776 lstrcpyAtoW(lpCaps->szPname, wocA.szPname);
3777 lpCaps->dwFormats = wocA.dwFormats;
3778 lpCaps->wChannels = wocA.wChannels;
3779 lpCaps->dwSupport = wocA.dwSupport;
3781 return ret;
3784 /**************************************************************************
3785 * WAVE_GetErrorText [internal]
3787 static UINT16 WAVE_GetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize)
3789 UINT16 ret = MMSYSERR_BADERRNUM;
3791 if (lpText == NULL) {
3792 ret = MMSYSERR_INVALPARAM;
3793 } else if (uSize == 0) {
3794 ret = MMSYSERR_NOERROR;
3795 } else if (
3796 /* test has been removed 'coz MMSYSERR_BASE is 0, and gcc did emit
3797 * a warning for the test was always true */
3798 (/*uError >= MMSYSERR_BASE && */uError <= MMSYSERR_LASTERROR) ||
3799 (uError >= WAVERR_BASE && uError <= WAVERR_LASTERROR)) {
3801 if (LoadStringA(MULTIMEDIA_GetIData()->hWinMM32Instance,
3802 uError, lpText, uSize) > 0) {
3803 ret = MMSYSERR_NOERROR;
3806 return ret;
3809 /**************************************************************************
3810 * waveOutGetErrorText [MMSYSTEM.403]
3812 UINT16 WINAPI waveOutGetErrorText16(UINT16 uError, LPSTR lpText, UINT16 uSize)
3814 return WAVE_GetErrorText(uError, lpText, uSize);
3817 /**************************************************************************
3818 * waveOutGetErrorTextA [WINMM.164]
3820 UINT WINAPI waveOutGetErrorTextA(UINT uError, LPSTR lpText, UINT uSize)
3822 return WAVE_GetErrorText(uError, lpText, uSize);
3825 /**************************************************************************
3826 * waveOutGetErrorTextW [WINMM.165]
3828 UINT WINAPI waveOutGetErrorTextW(UINT uError, LPWSTR lpText, UINT uSize)
3830 LPSTR xstr = HeapAlloc(GetProcessHeap(), 0, uSize);
3831 UINT ret = WAVE_GetErrorText(uError, xstr, uSize);
3833 lstrcpyAtoW(lpText, xstr);
3834 HeapFree(GetProcessHeap(), 0, xstr);
3835 return ret;
3838 /**************************************************************************
3839 * waveOutOpen [WINMM.173]
3840 * All the args/structs have the same layout as the win16 equivalents
3842 UINT WINAPI waveOutOpen(HWAVEOUT* lphWaveOut, UINT uDeviceID,
3843 const LPWAVEFORMATEX lpFormat, DWORD dwCallback,
3844 DWORD dwInstance, DWORD dwFlags)
3846 return MMSYSTEM_waveOpen(lphWaveOut, uDeviceID, MMDRV_WAVEOUT, lpFormat,
3847 dwCallback, dwInstance, dwFlags, TRUE);
3850 /**************************************************************************
3851 * waveOutOpen [MMSYSTEM.404]
3853 UINT16 WINAPI waveOutOpen16(HWAVEOUT16* lphWaveOut, UINT16 uDeviceID,
3854 const LPWAVEFORMATEX lpFormat, DWORD dwCallback,
3855 DWORD dwInstance, DWORD dwFlags)
3857 HWAVEOUT hWaveOut;
3858 UINT ret;
3860 /* since layout of WAVEOFORMATEX is the same for 16/32 bits, we directly
3861 * call the 32 bit version
3863 ret = MMSYSTEM_waveOpen(&hWaveOut, uDeviceID, MMDRV_WAVEOUT, lpFormat,
3864 dwCallback, dwInstance, dwFlags, FALSE);
3866 if (lphWaveOut != NULL) *lphWaveOut = hWaveOut;
3867 return ret;
3870 /**************************************************************************
3871 * waveOutClose [WINMM.161]
3873 UINT WINAPI waveOutClose(HWAVEOUT hWaveOut)
3875 LPWINE_MLD wmld;
3876 DWORD dwRet;
3878 TRACE("(%04X)\n", hWaveOut);
3880 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
3881 return MMSYSERR_INVALHANDLE;
3883 dwRet = MMDRV_Close(wmld, WODM_CLOSE);
3884 MMDRV_Free(hWaveOut, wmld);
3886 return dwRet;
3889 /**************************************************************************
3890 * waveOutClose [MMSYSTEM.405]
3892 UINT16 WINAPI waveOutClose16(HWAVEOUT16 hWaveOut)
3894 return waveOutClose(hWaveOut);
3897 /**************************************************************************
3898 * waveOutPrepareHeader [WINMM.175]
3900 UINT WINAPI waveOutPrepareHeader(HWAVEOUT hWaveOut,
3901 WAVEHDR* lpWaveOutHdr, UINT uSize)
3903 LPWINE_MLD wmld;
3905 TRACE("(%04X, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
3907 if (lpWaveOutHdr == NULL) return MMSYSERR_INVALPARAM;
3909 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
3910 return MMSYSERR_INVALHANDLE;
3912 return MMDRV_Message(wmld, WODM_PREPARE, (DWORD)lpWaveOutHdr, uSize, TRUE);
3915 /**************************************************************************
3916 * waveOutPrepareHeader [MMSYSTEM.406]
3918 UINT16 WINAPI waveOutPrepareHeader16(HWAVEOUT16 hWaveOut,
3919 WAVEHDR* /*SEGPTR*/ lpsegWaveOutHdr,
3920 UINT16 uSize)
3922 LPWINE_MLD wmld;
3923 LPWAVEHDR lpWaveOutHdr = (LPWAVEHDR)PTR_SEG_TO_LIN(lpsegWaveOutHdr);
3925 TRACE("(%04X, %p, %u);\n", hWaveOut, lpsegWaveOutHdr, uSize);
3927 if (lpWaveOutHdr == NULL) return MMSYSERR_INVALPARAM;
3929 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
3930 return MMSYSERR_INVALHANDLE;
3932 return MMDRV_Message(wmld, WODM_PREPARE, (DWORD)lpsegWaveOutHdr, uSize, FALSE);
3935 /**************************************************************************
3936 * waveOutUnprepareHeader [WINMM.181]
3938 UINT WINAPI waveOutUnprepareHeader(HWAVEOUT hWaveOut,
3939 LPWAVEHDR lpWaveOutHdr, UINT uSize)
3941 LPWINE_MLD wmld;
3943 TRACE("(%04X, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
3945 if (!(lpWaveOutHdr->dwFlags & WHDR_PREPARED)) {
3946 return MMSYSERR_NOERROR;
3949 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
3950 return MMSYSERR_INVALHANDLE;
3952 return MMDRV_Message(wmld, WODM_UNPREPARE, (DWORD)lpWaveOutHdr, uSize, TRUE);
3955 /**************************************************************************
3956 * waveOutUnprepareHeader [MMSYSTEM.407]
3958 UINT16 WINAPI waveOutUnprepareHeader16(HWAVEOUT16 hWaveOut,
3959 LPWAVEHDR /*SEGPTR*/ lpsegWaveOutHdr,
3960 UINT16 uSize)
3962 LPWINE_MLD wmld;
3963 LPWAVEHDR lpWaveOutHdr = (LPWAVEHDR)PTR_SEG_TO_LIN(lpsegWaveOutHdr);
3965 TRACE("(%04X, %p, %u);\n", hWaveOut, lpsegWaveOutHdr, uSize);
3967 if (!(lpWaveOutHdr->dwFlags & WHDR_PREPARED)) {
3968 return MMSYSERR_NOERROR;
3971 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
3972 return MMSYSERR_INVALHANDLE;
3974 return MMDRV_Message(wmld, WODM_UNPREPARE, (DWORD)lpsegWaveOutHdr, uSize, FALSE);
3977 /**************************************************************************
3978 * waveOutWrite [MMSYSTEM.408]
3980 UINT WINAPI waveOutWrite(HWAVEOUT hWaveOut, LPWAVEHDR lpWaveOutHdr,
3981 UINT uSize)
3983 LPWINE_MLD wmld;
3985 TRACE("(%04X, %p, %u);\n", hWaveOut, lpWaveOutHdr, uSize);
3987 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
3988 return MMSYSERR_INVALHANDLE;
3990 return MMDRV_Message(wmld, WODM_WRITE, (DWORD)lpWaveOutHdr, uSize, TRUE);
3993 /**************************************************************************
3994 * waveOutWrite [MMSYSTEM.408]
3996 UINT16 WINAPI waveOutWrite16(HWAVEOUT16 hWaveOut,
3997 LPWAVEHDR /*SEGPTR*/ lpsegWaveOutHdr,
3998 UINT16 uSize)
4000 LPWINE_MLD wmld;
4002 TRACE("(%04X, %p, %u);\n", hWaveOut, lpsegWaveOutHdr, uSize);
4004 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
4005 return MMSYSERR_INVALHANDLE;
4007 return MMDRV_Message(wmld, WODM_WRITE, (DWORD)lpsegWaveOutHdr, uSize, FALSE);
4010 #define WAVEOUT_SHORTCUT_0(xx, XX) \
4011 UINT WINAPI waveOut##xx(HWAVEOUT hWaveOut) \
4013 LPWINE_MLD wmld; \
4014 TRACE("(%04X);\n", hWaveOut); \
4015 if ((wmld = MMDRV_Get(hWaveOut,MMDRV_WAVEOUT,FALSE))==NULL) \
4016 return MMSYSERR_INVALHANDLE; \
4017 return MMDRV_Message(wmld,WODM_##XX,0L,0L,TRUE); \
4019 UINT16 WINAPI waveOut##xx##16(HWAVEOUT16 hWaveOut16) \
4020 {return waveOut##xx(hWaveOut16);}
4022 WAVEOUT_SHORTCUT_0(BreakLoop, BREAKLOOP)
4023 WAVEOUT_SHORTCUT_0(Pause, PAUSE)
4024 WAVEOUT_SHORTCUT_0(Reset, RESET)
4025 WAVEOUT_SHORTCUT_0(Restart, RESTART)
4026 #undef WAVEOUT_SHORTCUT_0
4028 /**************************************************************************
4029 * waveOutGetPosition [WINMM.170]
4031 UINT WINAPI waveOutGetPosition(HWAVEOUT hWaveOut, LPMMTIME lpTime,
4032 UINT uSize)
4034 LPWINE_MLD wmld;
4036 TRACE("(%04X, %p, %u);\n", hWaveOut, lpTime, uSize);
4038 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
4039 return MMSYSERR_INVALHANDLE;
4041 return MMDRV_Message(wmld, WODM_GETPOS, (DWORD)lpTime, uSize, TRUE);
4044 /**************************************************************************
4045 * waveOutGetPosition [MMSYSTEM.412]
4047 UINT16 WINAPI waveOutGetPosition16(HWAVEOUT16 hWaveOut, LPMMTIME16 lpTime,
4048 UINT16 uSize)
4050 UINT ret;
4051 MMTIME mmt;
4053 mmt.wType = lpTime->wType;
4054 ret = waveOutGetPosition(hWaveOut, &mmt, sizeof(mmt));
4055 MMSYSTEM_MMTIME32to16(lpTime, &mmt);
4056 return ret;
4059 #define WAVEOUT_SHORTCUT_1(xx, XX, atype) \
4060 UINT WINAPI waveOut##xx(HWAVEOUT hWaveOut, atype x) \
4062 LPWINE_MLD wmld; \
4063 TRACE("(%04X, %08lx);\n", hWaveOut, (DWORD)x); \
4064 if ((wmld = MMDRV_Get(hWaveOut,MMDRV_WAVEOUT,FALSE))==NULL) \
4065 return MMSYSERR_INVALHANDLE; \
4066 return MMDRV_Message(wmld,WODM_##XX,(DWORD)x,0L,TRUE); \
4068 UINT16 WINAPI waveOut##xx##16(HWAVEOUT16 hWaveOut16, atype x) \
4069 {return waveOut##xx(hWaveOut16, x);}
4071 WAVEOUT_SHORTCUT_1(GetPitch, GETPITCH, LPDWORD)
4072 WAVEOUT_SHORTCUT_1(SetPitch, SETPITCH, DWORD)
4073 WAVEOUT_SHORTCUT_1(GetPlaybackRate, GETPLAYBACKRATE, LPDWORD)
4074 WAVEOUT_SHORTCUT_1(SetPlaybackRate, SETPLAYBACKRATE, DWORD)
4075 #undef WAVEOUT_SHORTCUT_1
4077 #define WAVEOUT_SHORTCUT_2(xx, XX, atype) \
4078 UINT WINAPI waveOut##xx(UINT devid, atype x) \
4080 LPWINE_MLD wmld; \
4081 TRACE("(%04X, %08lx);\n", devid, (DWORD)x); \
4082 if ((wmld = MMDRV_Get(devid,MMDRV_WAVEOUT,TRUE))==NULL) \
4083 return MMSYSERR_INVALHANDLE; \
4084 return MMDRV_Message(wmld, WODM_##XX, (DWORD)x, 0L, TRUE); \
4086 UINT16 WINAPI waveOut##xx##16(UINT16 devid, atype x) \
4087 {return waveOut##xx(devid, x);}
4089 WAVEOUT_SHORTCUT_2(GetVolume, GETVOLUME, LPDWORD)
4090 WAVEOUT_SHORTCUT_2(SetVolume, SETVOLUME, DWORD)
4091 #undef WAVEOUT_SHORTCUT_2
4093 /**************************************************************************
4094 * waveOutGetID [MMSYSTEM.420]
4096 UINT WINAPI waveOutGetID(HWAVEOUT hWaveOut, UINT* lpuDeviceID)
4098 LPWINE_MLD wmld;
4100 TRACE("(%04X, %p);\n", hWaveOut, lpuDeviceID);
4102 if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
4104 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
4105 return MMSYSERR_INVALHANDLE;
4107 *lpuDeviceID = wmld->uDeviceID;
4108 return 0;
4111 /**************************************************************************
4112 * waveOutGetID [MMSYSTEM.420]
4114 UINT16 WINAPI waveOutGetID16(HWAVEOUT16 hWaveOut, UINT16* lpuDeviceID)
4116 LPWINE_MLD wmld;
4118 TRACE("(%04X, %p);\n", hWaveOut, lpuDeviceID);
4120 if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
4122 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
4123 return MMSYSERR_INVALHANDLE;
4125 *lpuDeviceID = wmld->uDeviceID;
4126 return 0;
4129 /**************************************************************************
4130 * waveOutMessage [WINMM.172]
4132 DWORD WINAPI waveOutMessage(HWAVEOUT hWaveOut, UINT uMessage,
4133 DWORD dwParam1, DWORD dwParam2)
4135 LPWINE_MLD wmld;
4137 TRACE("(%04x, %u, %ld, %ld)\n", hWaveOut, uMessage, dwParam1, dwParam2);
4139 /* from M$ KB */
4140 if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER))
4141 return MMSYSERR_INVALPARAM;
4143 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL)
4144 return MMSYSERR_INVALHANDLE;
4146 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
4149 /**************************************************************************
4150 * waveOutMessage [MMSYSTEM.421]
4152 DWORD WINAPI waveOutMessage16(HWAVEOUT16 hWaveOut, UINT16 uMessage,
4153 DWORD dwParam1, DWORD dwParam2)
4155 LPWINE_MLD wmld;
4157 TRACE("(%04x, %u, %ld, %ld)\n", hWaveOut, uMessage, dwParam1, dwParam2);
4159 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, FALSE)) == NULL) {
4160 if ((wmld = MMDRV_Get(hWaveOut, MMDRV_WAVEOUT, TRUE)) != NULL) {
4161 return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
4163 return MMSYSERR_INVALHANDLE;
4166 /* from M$ KB */
4167 if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER))
4168 return MMSYSERR_INVALPARAM;
4170 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, FALSE);
4173 /**************************************************************************
4174 * waveInGetNumDevs [WINMM.151]
4176 UINT WINAPI waveInGetNumDevs(void)
4178 return MMDRV_GetNum(MMDRV_WAVEIN);
4181 /**************************************************************************
4182 * waveInGetNumDevs [MMSYSTEM.501]
4184 UINT16 WINAPI waveInGetNumDevs16(void)
4186 return MMDRV_GetNum(MMDRV_WAVEIN);
4189 /**************************************************************************
4190 * waveInGetDevCapsA [WINMM.147]
4192 UINT WINAPI waveInGetDevCapsW(UINT uDeviceID, LPWAVEINCAPSW lpCaps, UINT uSize)
4194 WAVEINCAPSA wicA;
4195 UINT ret = waveInGetDevCapsA(uDeviceID, &wicA, uSize);
4197 if (ret == MMSYSERR_NOERROR) {
4198 lpCaps->wMid = wicA.wMid;
4199 lpCaps->wPid = wicA.wPid;
4200 lpCaps->vDriverVersion = wicA.vDriverVersion;
4201 lstrcpyAtoW(lpCaps->szPname, wicA.szPname);
4202 lpCaps->dwFormats = wicA.dwFormats;
4203 lpCaps->wChannels = wicA.wChannels;
4206 return ret;
4209 /**************************************************************************
4210 * waveInGetDevCapsA [WINMM.146]
4212 UINT WINAPI waveInGetDevCapsA(UINT uDeviceID, LPWAVEINCAPSA lpCaps, UINT uSize)
4214 LPWINE_MLD wmld;
4216 TRACE("(%u %p %u)!\n", uDeviceID, lpCaps, uSize);
4218 if ((wmld = MMDRV_Get(uDeviceID, MMDRV_WAVEIN, TRUE)) == NULL)
4219 return MMSYSERR_INVALHANDLE;
4221 return MMDRV_Message(wmld, WIDM_GETDEVCAPS, (DWORD)lpCaps, uSize, TRUE);
4224 /**************************************************************************
4225 * waveInGetDevCaps [MMSYSTEM.502]
4227 UINT16 WINAPI waveInGetDevCaps16(UINT16 uDeviceID, LPWAVEINCAPS16 lpCaps,
4228 UINT16 uSize)
4230 WAVEINCAPSA wicA;
4231 UINT ret = waveInGetDevCapsA(uDeviceID, &wicA, sizeof(wicA));
4233 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
4235 if (ret == MMSYSERR_NOERROR) {
4236 lpCaps->wMid = wicA.wMid;
4237 lpCaps->wPid = wicA.wPid;
4238 lpCaps->vDriverVersion = wicA.vDriverVersion;
4239 strcpy(lpCaps->szPname, wicA.szPname);
4240 lpCaps->dwFormats = wicA.dwFormats;
4241 lpCaps->wChannels = wicA.wChannels;
4243 return ret;
4246 /**************************************************************************
4247 * waveInGetErrorTextA [WINMM.148]
4249 UINT WINAPI waveInGetErrorTextA(UINT uError, LPSTR lpText, UINT uSize)
4251 return WAVE_GetErrorText(uError, lpText, uSize);
4254 /**************************************************************************
4255 * waveInGetErrorTextW [WINMM.149]
4257 UINT WINAPI waveInGetErrorTextW(UINT uError, LPWSTR lpText, UINT uSize)
4259 LPSTR txt = HeapAlloc(GetProcessHeap(), 0, uSize);
4260 UINT ret = WAVE_GetErrorText(uError, txt, uSize);
4262 lstrcpyAtoW(lpText, txt);
4263 HeapFree(GetProcessHeap(), 0, txt);
4264 return ret;
4267 /**************************************************************************
4268 * waveInGetErrorText [MMSYSTEM.503]
4270 UINT16 WINAPI waveInGetErrorText16(UINT16 uError, LPSTR lpText, UINT16 uSize)
4272 return WAVE_GetErrorText(uError, lpText, uSize);
4275 /**************************************************************************
4276 * waveInOpen [WINMM.154]
4278 UINT WINAPI waveInOpen(HWAVEIN* lphWaveIn, UINT uDeviceID,
4279 const LPWAVEFORMATEX lpFormat, DWORD dwCallback,
4280 DWORD dwInstance, DWORD dwFlags)
4282 return MMSYSTEM_waveOpen(lphWaveIn, uDeviceID, MMDRV_WAVEIN, lpFormat,
4283 dwCallback, dwInstance, dwFlags, TRUE);
4286 /**************************************************************************
4287 * waveInOpen [MMSYSTEM.504]
4289 UINT16 WINAPI waveInOpen16(HWAVEIN16* lphWaveIn, UINT16 uDeviceID,
4290 const LPWAVEFORMATEX lpFormat, DWORD dwCallback,
4291 DWORD dwInstance, DWORD dwFlags)
4293 HWAVEIN hWaveIn;
4294 UINT ret;
4296 /* since layout of WAVEOFORMATEX is the same for 16/32 bits, we directly
4297 * call the 32 bit version
4299 ret = MMSYSTEM_waveOpen(&hWaveIn, uDeviceID, MMDRV_WAVEIN, lpFormat,
4300 dwCallback, dwInstance, dwFlags, FALSE);
4302 if (lphWaveIn != NULL) *lphWaveIn = hWaveIn;
4303 return ret;
4306 /**************************************************************************
4307 * waveInClose [WINMM.145]
4309 UINT WINAPI waveInClose(HWAVEIN hWaveIn)
4311 LPWINE_MLD wmld;
4312 DWORD dwRet;
4314 TRACE("(%04X)\n", hWaveIn);
4316 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
4317 return MMSYSERR_INVALHANDLE;
4319 dwRet = MMDRV_Message(wmld, WIDM_CLOSE, 0L, 0L, TRUE);
4320 MMDRV_Free(hWaveIn, wmld);
4321 return dwRet;
4324 /**************************************************************************
4325 * waveInClose [MMSYSTEM.505]
4327 UINT16 WINAPI waveInClose16(HWAVEIN16 hWaveIn)
4329 return waveOutClose(hWaveIn);
4332 /**************************************************************************
4333 * waveInPrepareHeader [WINMM.155]
4335 UINT WINAPI waveInPrepareHeader(HWAVEIN hWaveIn, WAVEHDR* lpWaveInHdr,
4336 UINT uSize)
4338 LPWINE_MLD wmld;
4340 TRACE("(%04X, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
4342 if (lpWaveInHdr == NULL) return MMSYSERR_INVALPARAM;
4343 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
4344 return MMSYSERR_INVALHANDLE;
4346 lpWaveInHdr->dwBytesRecorded = 0;
4348 return MMDRV_Message(wmld, WIDM_PREPARE, (DWORD)lpWaveInHdr, uSize, TRUE);
4351 /**************************************************************************
4352 * waveInPrepareHeader [MMSYSTEM.506]
4354 UINT16 WINAPI waveInPrepareHeader16(HWAVEIN16 hWaveIn,
4355 WAVEHDR* /* SEGPTR */ lpsegWaveInHdr,
4356 UINT16 uSize)
4358 LPWINE_MLD wmld;
4359 LPWAVEHDR lpWaveInHdr = (LPWAVEHDR)PTR_SEG_TO_LIN(lpsegWaveInHdr);
4360 UINT16 ret;
4362 TRACE("(%04X, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
4364 if (lpWaveInHdr == NULL) return MMSYSERR_INVALHANDLE;
4365 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
4366 return MMSYSERR_INVALHANDLE;
4368 lpWaveInHdr->dwBytesRecorded = 0;
4370 ret = MMDRV_Message(wmld, WIDM_PREPARE, (DWORD)lpsegWaveInHdr, uSize, FALSE);
4371 return ret;
4374 /**************************************************************************
4375 * waveInUnprepareHeader [WINMM.159]
4377 UINT WINAPI waveInUnprepareHeader(HWAVEIN hWaveIn, WAVEHDR* lpWaveInHdr,
4378 UINT uSize)
4380 LPWINE_MLD wmld;
4382 TRACE("(%04X, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
4384 if (lpWaveInHdr == NULL) return MMSYSERR_INVALPARAM;
4385 if (!(lpWaveInHdr->dwFlags & WHDR_PREPARED)) {
4386 return MMSYSERR_NOERROR;
4389 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
4390 return MMSYSERR_INVALHANDLE;
4392 return MMDRV_Message(wmld, WIDM_UNPREPARE, (DWORD)lpWaveInHdr, uSize, TRUE);
4395 /**************************************************************************
4396 * waveInUnprepareHeader [MMSYSTEM.507]
4398 UINT16 WINAPI waveInUnprepareHeader16(HWAVEIN16 hWaveIn,
4399 WAVEHDR* /* SEGPTR */ lpsegWaveInHdr,
4400 UINT16 uSize)
4402 LPWINE_MLD wmld;
4403 LPWAVEHDR lpWaveInHdr = (LPWAVEHDR)PTR_SEG_TO_LIN(lpsegWaveInHdr);
4405 TRACE("(%04X, %p, %u);\n", hWaveIn, lpsegWaveInHdr, uSize);
4407 if (lpWaveInHdr == NULL) return MMSYSERR_INVALPARAM;
4409 if (!(lpWaveInHdr->dwFlags & WHDR_PREPARED)) {
4410 return MMSYSERR_NOERROR;
4413 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
4414 return MMSYSERR_INVALHANDLE;
4416 return MMDRV_Message(wmld, WIDM_UNPREPARE, (DWORD)lpsegWaveInHdr, uSize, FALSE);
4419 /**************************************************************************
4420 * waveInAddBuffer [WINMM.144]
4422 UINT WINAPI waveInAddBuffer(HWAVEIN hWaveIn,
4423 WAVEHDR* lpWaveInHdr, UINT uSize)
4425 LPWINE_MLD wmld;
4427 TRACE("(%04X, %p, %u);\n", hWaveIn, lpWaveInHdr, uSize);
4429 if (lpWaveInHdr == NULL) return MMSYSERR_INVALPARAM;
4430 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
4431 return MMSYSERR_INVALHANDLE;
4433 return MMDRV_Message(wmld, WIDM_ADDBUFFER, (DWORD)lpWaveInHdr, uSize, TRUE);
4436 /**************************************************************************
4437 * waveInAddBuffer [MMSYSTEM.508]
4439 UINT16 WINAPI waveInAddBuffer16(HWAVEIN16 hWaveIn,
4440 WAVEHDR* /* SEGPTR */ lpsegWaveInHdr,
4441 UINT16 uSize)
4443 LPWINE_MLD wmld;
4445 TRACE("(%04X, %p, %u);\n", hWaveIn, lpsegWaveInHdr, uSize);
4447 if (lpsegWaveInHdr == NULL) return MMSYSERR_INVALPARAM;
4448 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
4449 return MMSYSERR_INVALHANDLE;
4451 return MMDRV_Message(wmld, WIDM_ADDBUFFER, (DWORD)lpsegWaveInHdr, uSize, FALSE);
4454 #define WAVEIN_SHORTCUT_0(xx, XX) \
4455 UINT WINAPI waveIn##xx(HWAVEIN hWaveIn) \
4457 LPWINE_MLD wmld; \
4458 TRACE("(%04X);\n", hWaveIn); \
4459 if ((wmld=MMDRV_Get(hWaveIn,MMDRV_WAVEIN,FALSE)) == NULL) \
4460 return MMSYSERR_INVALHANDLE; \
4461 return MMDRV_Message(wmld,WIDM_##XX,0L,0L,TRUE); \
4463 UINT16 WINAPI waveIn##xx##16(HWAVEIN16 hWaveIn16) \
4464 {return waveIn##xx(hWaveIn16);}
4466 WAVEIN_SHORTCUT_0(Reset, RESET)
4467 WAVEIN_SHORTCUT_0(Start, START)
4468 WAVEIN_SHORTCUT_0(Stop, STOP)
4469 #undef WAVEIN_SHORTCUT_0
4471 /**************************************************************************
4472 * waveInGetPosition [WINMM.152]
4474 UINT WINAPI waveInGetPosition(HWAVEIN hWaveIn, LPMMTIME lpTime,
4475 UINT uSize)
4477 LPWINE_MLD wmld;
4479 TRACE("(%04X, %p, %u);\n", hWaveIn, lpTime, uSize);
4481 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
4482 return MMSYSERR_INVALHANDLE;
4484 return MMDRV_Message(wmld, WIDM_GETPOS, (DWORD)lpTime, uSize, TRUE);
4487 /**************************************************************************
4488 * waveInGetPosition [MMSYSTEM.512]
4490 UINT16 WINAPI waveInGetPosition16(HWAVEIN16 hWaveIn, LPMMTIME16 lpTime,
4491 UINT16 uSize)
4493 UINT ret;
4494 MMTIME mmt;
4496 mmt.wType = lpTime->wType;
4497 ret = waveInGetPosition(hWaveIn, &mmt, sizeof(mmt));
4498 MMSYSTEM_MMTIME32to16(lpTime, &mmt);
4499 return ret;
4502 /**************************************************************************
4503 * waveInGetID [WINMM.150]
4505 UINT WINAPI waveInGetID(HWAVEIN hWaveIn, UINT* lpuDeviceID)
4507 LPWINE_MLD wmld;
4509 TRACE("(%04X, %p);\n", hWaveIn, lpuDeviceID);
4511 if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
4513 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
4514 return MMSYSERR_INVALHANDLE;
4516 *lpuDeviceID = wmld->uDeviceID;
4517 return MMSYSERR_NOERROR;
4520 /**************************************************************************
4521 * waveInGetID [MMSYSTEM.513]
4523 UINT16 WINAPI waveInGetID16(HWAVEIN16 hWaveIn, UINT16* lpuDeviceID)
4525 LPWINE_MLD wmld;
4527 TRACE("(%04X, %p);\n", hWaveIn, lpuDeviceID);
4529 if (lpuDeviceID == NULL) return MMSYSERR_INVALHANDLE;
4531 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
4532 return MMSYSERR_INVALHANDLE;
4534 *lpuDeviceID = wmld->uDeviceID;
4535 return MMSYSERR_NOERROR;
4538 /**************************************************************************
4539 * waveInMessage [WINMM.153]
4541 DWORD WINAPI waveInMessage(HWAVEIN hWaveIn, UINT uMessage,
4542 DWORD dwParam1, DWORD dwParam2)
4544 LPWINE_MLD wmld;
4546 TRACE("(%04x, %u, %ld, %ld)\n", hWaveIn, uMessage, dwParam1, dwParam2);
4548 /* from M$ KB */
4549 if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER))
4550 return MMSYSERR_INVALPARAM;
4552 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
4553 return MMSYSERR_INVALHANDLE;
4555 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
4558 /**************************************************************************
4559 * waveInMessage [MMSYSTEM.514]
4561 DWORD WINAPI waveInMessage16(HWAVEIN16 hWaveIn, UINT16 uMessage,
4562 DWORD dwParam1, DWORD dwParam2)
4564 LPWINE_MLD wmld;
4566 TRACE("(%04x, %u, %ld, %ld)\n", hWaveIn, uMessage, dwParam1, dwParam2);
4568 /* from M$ KB */
4569 if (uMessage < DRVM_IOCTL || (uMessage >= DRVM_IOCTL_LAST && uMessage < DRVM_MAPPER))
4570 return MMSYSERR_INVALPARAM;
4572 if ((wmld = MMDRV_Get(hWaveIn, MMDRV_WAVEIN, FALSE)) == NULL)
4573 return MMSYSERR_INVALHANDLE;
4575 return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2, TRUE);
4578 /**************************************************************************
4579 * DrvOpen [MMSYSTEM.1100]
4581 HDRVR16 WINAPI DrvOpen(LPSTR lpDriverName, LPSTR lpSectionName, LPARAM lParam)
4583 TRACE("('%s','%s', %08lX);\n", lpDriverName, lpSectionName, lParam);
4585 return OpenDriver16(lpDriverName, lpSectionName, lParam);
4588 /**************************************************************************
4589 * DrvClose [MMSYSTEM.1101]
4591 LRESULT WINAPI DrvClose(HDRVR16 hDrv, LPARAM lParam1, LPARAM lParam2)
4593 TRACE("(%04X, %08lX, %08lX);\n", hDrv, lParam1, lParam2);
4595 return CloseDriver16(hDrv, lParam1, lParam2);
4598 /**************************************************************************
4599 * DrvSendMessage [MMSYSTEM.1102]
4601 LRESULT WINAPI DrvSendMessage(HDRVR16 hDrv, WORD msg, LPARAM lParam1,
4602 LPARAM lParam2)
4604 return SendDriverMessage(hDrv, msg, lParam1, lParam2);
4607 /**************************************************************************
4608 * DrvGetModuleHandle [MMSYSTEM.1103]
4610 HANDLE16 WINAPI DrvGetModuleHandle16(HDRVR16 hDrv)
4612 return GetDriverModuleHandle16(hDrv);
4615 /**************************************************************************
4616 * DrvDefDriverProc [MMSYSTEM.1104]
4618 LRESULT WINAPI DrvDefDriverProc(DWORD dwDriverID, HDRVR16 hDrv, WORD wMsg,
4619 DWORD dwParam1, DWORD dwParam2)
4621 /* FIXME : any mapping from 32 to 16 bit structure ? */
4622 return DefDriverProc16(dwDriverID, hDrv, wMsg, dwParam1, dwParam2);
4625 /**************************************************************************
4626 * DefDriverProc [WINMM.5]
4628 LRESULT WINAPI DefDriverProc(DWORD dwDriverIdentifier, HDRVR hDrv,
4629 UINT Msg, LPARAM lParam1, LPARAM lParam2)
4631 switch (Msg) {
4632 case DRV_LOAD:
4633 case DRV_FREE:
4634 case DRV_ENABLE:
4635 case DRV_DISABLE:
4636 return 1;
4637 case DRV_INSTALL:
4638 case DRV_REMOVE:
4639 return DRV_SUCCESS;
4640 default:
4641 return 0;
4645 /*#define USE_MM_TSK_WINE*/
4647 /**************************************************************************
4648 * mmTaskCreate [MMSYSTEM.900]
4650 * Creates a 16 bit MM task. It's entry point is lpFunc, and it should be
4651 * called upon creation with dwPmt as parameter.
4653 HINSTANCE16 WINAPI mmTaskCreate16(SEGPTR spProc, HINSTANCE16 *lphMmTask, DWORD dwPmt)
4655 DWORD showCmd = 0x40002;
4656 LPSTR cmdline;
4657 WORD sel1, sel2;
4658 LOADPARAMS16* lp;
4659 HINSTANCE16 ret;
4660 HINSTANCE16 handle;
4662 TRACE("(%08lx, %p, %08lx);\n", spProc, lphMmTask, dwPmt);
4663 /* This to work requires NE modules to be started with a binary command line
4664 * which is not currently the case. A patch exists but has never been committed.
4665 * A workaround would be to integrate code for mmtask.tsk into Wine, but
4666 * this requires tremendous work (starting with patching tools/build to
4667 * create NE executables (and not only DLLs) for builtins modules.
4668 * EP 99/04/25
4670 FIXME("This is currently broken. It will fail\n");
4672 cmdline = (LPSTR)HeapAlloc(GetProcessHeap(), 0, 0x0d);
4673 cmdline[0] = 0x0d;
4674 *(LPDWORD)(cmdline + 1) = (DWORD)spProc;
4675 *(LPDWORD)(cmdline + 5) = dwPmt;
4676 *(LPDWORD)(cmdline + 9) = 0;
4678 sel1 = SELECTOR_AllocBlock(cmdline, 0x0d, SEGMENT_DATA, FALSE, FALSE);
4679 sel2 = SELECTOR_AllocBlock(&showCmd, sizeof(showCmd),
4680 SEGMENT_DATA, FALSE, FALSE);
4682 lp = (LOADPARAMS16*)HeapAlloc(GetProcessHeap(), 0, sizeof(LOADPARAMS16));
4683 lp->hEnvironment = 0;
4684 lp->cmdLine = PTR_SEG_OFF_TO_SEGPTR(sel1, 0);
4685 lp->showCmd = PTR_SEG_OFF_TO_SEGPTR(sel2, 0);
4686 lp->reserved = 0;
4688 #ifndef USE_MM_TSK_WINE
4689 handle = LoadModule16("c:\\windows\\system\\mmtask.tsk", lp);
4690 #else
4691 handle = LoadModule16("mmtask.tsk", lp);
4692 #endif
4693 if (handle < 32) {
4694 ret = (handle) ? 1 : 2;
4695 handle = 0;
4696 } else {
4697 ret = 0;
4699 if (lphMmTask)
4700 *lphMmTask = handle;
4702 UnMapLS(PTR_SEG_OFF_TO_SEGPTR(sel2, 0));
4703 UnMapLS(PTR_SEG_OFF_TO_SEGPTR(sel1, 0));
4705 HeapFree(GetProcessHeap(), 0, lp);
4706 HeapFree(GetProcessHeap(), 0, cmdline);
4708 TRACE("=> 0x%04x/%d\n", handle, ret);
4709 return ret;
4712 #ifdef USE_MM_TSK_WINE
4713 /* C equivalent to mmtask.tsk binary content */
4714 void mmTaskEntryPoint16(LPSTR cmdLine, WORD di, WORD si)
4716 int len = cmdLine[0x80];
4718 if (len / 2 == 6) {
4719 void (*fpProc)(DWORD) = (void (*)(DWORD))PTR_SEG_TO_LIN(*((DWORD*)(cmdLine + 1)));
4720 DWORD dwPmt = *((DWORD*)(cmdLine + 5));
4722 #if 0
4723 InitTask16(); /* fixme: pmts / from context ? */
4724 InitApp(di);
4725 #endif
4726 if (SetMessageQueue16(0x40)) {
4727 WaitEvent16(0);
4728 if (HIWORD(fpProc)) {
4729 OldYield16();
4730 /* EPP StackEnter16(); */
4731 (fpProc)(dwPmt);
4735 OldYield16();
4736 OldYield16();
4737 OldYield16();
4738 ExitProcess(0);
4740 #endif
4742 /**************************************************************************
4743 * mmTaskBlock [MMSYSTEM.902]
4745 void WINAPI mmTaskBlock16(HINSTANCE16 WINE_UNUSED hInst)
4747 MSG msg;
4749 do {
4750 GetMessageA(&msg, 0, 0, 0);
4751 if (msg.hwnd) {
4752 TranslateMessage(&msg);
4753 DispatchMessageA(&msg);
4755 } while (msg.message < 0x3A0);
4758 /**************************************************************************
4759 * mmTaskSignal [MMSYSTEM.903]
4761 LRESULT WINAPI mmTaskSignal16(HTASK16 ht)
4763 TRACE("(%04x);\n", ht);
4764 return Callout.PostAppMessage16(ht, WM_USER, 0, 0);
4767 /**************************************************************************
4768 * mmTaskYield16 [MMSYSTEM.905]
4770 void WINAPI mmTaskYield16(void)
4772 MSG msg;
4774 if (PeekMessageA(&msg, 0, 0, 0, 0)) {
4775 Yield16();
4779 DWORD WINAPI GetProcessFlags(DWORD);
4781 /**************************************************************************
4782 * mmThreadCreate [MMSYSTEM.1120]
4784 * undocumented
4785 * Creates a MM thread, calling fpThreadAddr(dwPmt).
4786 * dwFlags:
4787 * bit.0 set means create a 16 bit task instead of thread calling a 16 bit proc
4788 * bit.1 set means to open a VxD for this thread (unsupported)
4790 LRESULT WINAPI mmThreadCreate16(FARPROC16 fpThreadAddr, LPHANDLE lpHndl, DWORD dwPmt, DWORD dwFlags)
4792 HANDLE16 hndl;
4793 LRESULT ret;
4795 TRACE("(%p, %p, %08lx, %08lx)!\n", fpThreadAddr, lpHndl, dwPmt, dwFlags);
4797 hndl = GlobalAlloc16(sizeof(WINE_MMTHREAD), GMEM_SHARE|GMEM_ZEROINIT);
4799 if (hndl == 0) {
4800 ret = 2;
4801 } else {
4802 WINE_MMTHREAD* lpMMThd = (WINE_MMTHREAD*)PTR_SEG_OFF_TO_LIN(hndl, 0);
4804 #if 0
4805 /* force mmtask routines even if mmthread is required */
4806 /* this will work only if the patch about binary cmd line and NE tasks
4807 * is committed
4809 dwFlags |= 1;
4810 #endif
4812 lpMMThd->dwSignature = WINE_MMTHREAD_CREATED;
4813 lpMMThd->dwCounter = 0;
4814 lpMMThd->hThread = 0;
4815 lpMMThd->dwThreadID = 0;
4816 lpMMThd->fpThread = fpThreadAddr;
4817 lpMMThd->dwThreadPmt = dwPmt;
4818 lpMMThd->dwSignalCount = 0;
4819 lpMMThd->hEvent = 0;
4820 lpMMThd->hVxD = 0;
4821 lpMMThd->dwStatus = 0;
4822 lpMMThd->dwFlags = dwFlags;
4823 lpMMThd->hTask = 0;
4825 if ((dwFlags & 1) == 0 && (GetProcessFlags(GetCurrentThreadId()) & 8) == 0) {
4826 lpMMThd->hEvent = CreateEventA(0, 0, 1, 0);
4828 TRACE("Let's go crazy... trying new MM thread. lpMMThd=%p\n", lpMMThd);
4829 if (lpMMThd->dwFlags & 2) {
4830 /* as long as we don't support MM VxD in wine, we don't need
4831 * to care about this flag
4833 /* FIXME("Don't know how to properly open VxD handles\n"); */
4834 /* lpMMThd->hVxD = OpenVxDHandle(lpMMThd->hEvent); */
4837 lpMMThd->hThread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)WINE_mmThreadEntryPoint,
4838 (LPVOID)(DWORD)hndl, CREATE_SUSPENDED, &lpMMThd->dwThreadID);
4839 if (lpMMThd->hThread == 0) {
4840 WARN("Couldn't create thread\n");
4841 /* clean-up(VxDhandle...); devicedirectio... */
4842 if (lpMMThd->hEvent != 0)
4843 CloseHandle(lpMMThd->hEvent);
4844 ret = 2;
4845 } else {
4846 TRACE("Got a nice thread hndl=0x%04x id=0x%08lx\n", lpMMThd->hThread, lpMMThd->dwThreadID);
4847 ret = 0;
4849 } else {
4850 /* get WINE_mmThreadEntryPoint()
4851 * 2047 is its ordinal in mmsystem.spec
4853 FARPROC16 fp = GetProcAddress16(GetModuleHandle16("MMSYSTEM"), (SEGPTR)2047);
4855 TRACE("farproc seg=0x%08lx lin=%p\n", (DWORD)fp, PTR_SEG_TO_LIN(fp));
4857 ret = (fp == 0) ? 2 : mmTaskCreate16((DWORD)fp, 0, hndl);
4860 if (ret == 0) {
4861 if (lpMMThd->hThread && !ResumeThread(lpMMThd->hThread))
4862 WARN("Couldn't resume thread\n");
4864 while (lpMMThd->dwStatus != 0x10) { /* test also HIWORD of dwStatus */
4865 UserYield16();
4870 if (ret != 0) {
4871 GlobalFree16(hndl);
4872 hndl = 0;
4875 if (lpHndl)
4876 *lpHndl = hndl;
4878 TRACE("ok => %ld\n", ret);
4879 return ret;
4882 /**************************************************************************
4883 * mmThreadSignal [MMSYSTEM.1121]
4885 void WINAPI mmThreadSignal16(HANDLE16 hndl)
4887 TRACE("(%04x)!\n", hndl);
4889 if (hndl) {
4890 WINE_MMTHREAD* lpMMThd = (WINE_MMTHREAD*)PTR_SEG_OFF_TO_LIN(hndl, 0);
4892 lpMMThd->dwCounter++;
4893 if (lpMMThd->hThread != 0) {
4894 InterlockedIncrement(&lpMMThd->dwSignalCount);
4895 SetEvent(lpMMThd->hEvent);
4896 } else {
4897 mmTaskSignal16(lpMMThd->hTask);
4899 lpMMThd->dwCounter--;
4903 /**************************************************************************
4904 * MMSYSTEM_ThreadBlock [internal]
4906 static void MMSYSTEM_ThreadBlock(WINE_MMTHREAD* lpMMThd)
4908 MSG msg;
4909 DWORD ret;
4911 if (lpMMThd->dwThreadID != GetCurrentThreadId())
4912 ERR("Not called by thread itself\n");
4914 for (;;) {
4915 ResetEvent(lpMMThd->hEvent);
4916 if (InterlockedDecrement(&lpMMThd->dwSignalCount) >= 0)
4917 break;
4918 InterlockedIncrement(&lpMMThd->dwSignalCount);
4920 TRACE("S1\n");
4922 ret = MsgWaitForMultipleObjects(1, &lpMMThd->hEvent, FALSE, INFINITE, QS_ALLINPUT);
4923 switch (ret) {
4924 case WAIT_OBJECT_0: /* Event */
4925 TRACE("S2.1\n");
4926 break;
4927 case WAIT_OBJECT_0 + 1: /* Msg */
4928 TRACE("S2.2\n");
4929 if (Callout.PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) {
4930 Callout.TranslateMessage(&msg);
4931 Callout.DispatchMessageA(&msg);
4933 break;
4934 default:
4935 WARN("S2.x unsupported ret val 0x%08lx\n", ret);
4937 TRACE("S3\n");
4941 /**************************************************************************
4942 * mmThreadBlock [MMSYSTEM.1122]
4944 void WINAPI mmThreadBlock16(HANDLE16 hndl)
4946 TRACE("(%04x)!\n", hndl);
4948 if (hndl) {
4949 WINE_MMTHREAD* lpMMThd = (WINE_MMTHREAD*)PTR_SEG_OFF_TO_LIN(hndl, 0);
4951 if (lpMMThd->hThread != 0) {
4952 SYSLEVEL_ReleaseWin16Lock();
4953 MMSYSTEM_ThreadBlock(lpMMThd);
4954 SYSLEVEL_RestoreWin16Lock();
4955 } else {
4956 mmTaskBlock16(lpMMThd->hTask);
4959 TRACE("done\n");
4962 /**************************************************************************
4963 * mmThreadIsCurrent [MMSYSTEM.1123]
4965 BOOL16 WINAPI mmThreadIsCurrent16(HANDLE16 hndl)
4967 BOOL16 ret = FALSE;
4969 TRACE("(%04x)!\n", hndl);
4971 if (hndl && mmThreadIsValid16(hndl)) {
4972 WINE_MMTHREAD* lpMMThd = (WINE_MMTHREAD*)PTR_SEG_OFF_TO_LIN(hndl, 0);
4973 ret = (GetCurrentThreadId() == lpMMThd->dwThreadID);
4975 TRACE("=> %d\n", ret);
4976 return ret;
4979 /**************************************************************************
4980 * mmThreadIsValid [MMSYSTEM.1124]
4982 BOOL16 WINAPI mmThreadIsValid16(HANDLE16 hndl)
4984 BOOL16 ret = FALSE;
4986 TRACE("(%04x)!\n", hndl);
4988 if (hndl) {
4989 WINE_MMTHREAD* lpMMThd = (WINE_MMTHREAD*)PTR_SEG_OFF_TO_LIN(hndl, 0);
4991 if (!IsBadWritePtr(lpMMThd, sizeof(WINE_MMTHREAD)) &&
4992 lpMMThd->dwSignature == WINE_MMTHREAD_CREATED &&
4993 IsTask16(lpMMThd->hTask)) {
4994 lpMMThd->dwCounter++;
4995 if (lpMMThd->hThread != 0) {
4996 DWORD dwThreadRet;
4997 if (GetExitCodeThread(lpMMThd->hThread, &dwThreadRet) &&
4998 dwThreadRet == STATUS_PENDING) {
4999 ret = TRUE;
5001 } else {
5002 ret = TRUE;
5004 lpMMThd->dwCounter--;
5007 TRACE("=> %d\n", ret);
5008 return ret;
5011 /**************************************************************************
5012 * mmThreadGetTask [MMSYSTEM.1125]
5014 HANDLE16 WINAPI mmThreadGetTask16(HANDLE16 hndl)
5016 HANDLE16 ret = 0;
5018 TRACE("(%04x)\n", hndl);
5020 if (mmThreadIsValid16(hndl)) {
5021 WINE_MMTHREAD* lpMMThd = (WINE_MMTHREAD*)PTR_SEG_OFF_TO_LIN(hndl, 0);
5022 ret = lpMMThd->hTask;
5024 return ret;
5027 /* ### start build ### */
5028 extern LONG CALLBACK MMSYSTEM_CallTo16_long_l (FARPROC16,LONG);
5029 /* ### stop build ### */
5031 /**************************************************************************
5032 * mmThreadGetTask [internal]
5034 void WINAPI WINE_mmThreadEntryPoint(DWORD _pmt)
5036 HANDLE16 hndl = (HANDLE16)_pmt;
5037 WINE_MMTHREAD* lpMMThd = (WINE_MMTHREAD*)PTR_SEG_OFF_TO_LIN(hndl, 0);
5039 TRACE("(%04x %p)\n", hndl, lpMMThd);
5041 lpMMThd->hTask = LOWORD(GetCurrentTask());
5042 TRACE("[10-%08x] setting hTask to 0x%08x\n", lpMMThd->hThread, lpMMThd->hTask);
5043 lpMMThd->dwStatus = 0x10;
5044 MMSYSTEM_ThreadBlock(lpMMThd);
5045 TRACE("[20-%08x]\n", lpMMThd->hThread);
5046 lpMMThd->dwStatus = 0x20;
5047 if (lpMMThd->fpThread) {
5048 MMSYSTEM_CallTo16_long_l(lpMMThd->fpThread, lpMMThd->dwThreadPmt);
5050 lpMMThd->dwStatus = 0x30;
5051 TRACE("[30-%08x]\n", lpMMThd->hThread);
5052 while (lpMMThd->dwCounter) {
5053 Sleep(1);
5054 /* Yield16();*/
5056 TRACE("[XX-%08x]\n", lpMMThd->hThread);
5057 /* paranoia */
5058 lpMMThd->dwSignature = WINE_MMTHREAD_DELETED;
5059 /* close lpMMThread->hVxD directio */
5060 if (lpMMThd->hEvent)
5061 CloseHandle(lpMMThd->hEvent);
5062 GlobalFree16(hndl);
5063 TRACE("done\n");
5066 typedef BOOL16 (WINAPI *MMCPLCALLBACK)(HWND, LPCSTR, LPCSTR, LPCSTR);
5068 /**************************************************************************
5069 * mmShowMMCPLPropertySheet [MMSYSTEM.1150]
5071 BOOL16 WINAPI mmShowMMCPLPropertySheet16(HWND hWnd, LPCSTR lpStrDevice,
5072 LPCSTR lpStrTab, LPCSTR lpStrTitle)
5074 HANDLE hndl;
5075 BOOL16 ret = FALSE;
5077 TRACE("(%04x \"%s\" \"%s\" \"%s\")\n", hWnd, lpStrDevice, lpStrTab, lpStrTitle);
5079 hndl = LoadLibraryA("MMSYS.CPL");
5080 if (hndl != 0) {
5081 MMCPLCALLBACK fp = (MMCPLCALLBACK)GetProcAddress(hndl, "ShowMMCPLPropertySheet");
5082 if (fp != NULL) {
5083 SYSLEVEL_ReleaseWin16Lock();
5084 ret = (fp)(hWnd, lpStrDevice, lpStrTab, lpStrTitle);
5085 SYSLEVEL_RestoreWin16Lock();
5087 FreeLibrary(hndl);
5090 return ret;
5093 /**************************************************************************
5094 * StackEnter & StackLeave [MMSYSTEM.32][MMSYSTEM.33]
5096 void WINAPI StackEnterLeave16(void)
5098 #ifdef __i386__
5099 /* mmsystem.dll from Win 95 does only this: so does Wine */
5100 __asm__("stc");
5101 #endif
5104 /**************************************************************************
5105 * WMMMIDIRUNONCE [MMSYSTEM.8]
5107 void WINAPI WMMMidiRunOnce16(void)
5109 FIXME("(), stub!\n");