Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1019 lines
28 KiB

  1. /****************************************************************************
  2. *
  3. * sbtest.c
  4. *
  5. * Copyright (c) 1991 Microsoft Corporation. All Rights Reserved.
  6. *
  7. ***************************************************************************/
  8. #include <windows.h>
  9. #include <mmsystem.h>
  10. #include "wincom.h"
  11. #include "sbtest.h"
  12. #include <commdlg.h>
  13. /****************************************************************************
  14. *
  15. * public data
  16. *
  17. ***************************************************************************/
  18. HANDLE ghInst; // global instance handle
  19. char szAppName[10]; // app name
  20. HWND hPrintfWnd; // printf child window
  21. HWND hwndVolumeDlg;
  22. int fDebug;
  23. BYTE bChannel = 0;
  24. UINT wLoops = IDM_LOOPOFF;
  25. HMIDIOUT hMidiOut = NULL;
  26. char ach[256];
  27. OPENFILENAME ofn;
  28. char szFname[MAXFILENAME];
  29. BOOL AuxNotSupported;
  30. BOOL SetAux;
  31. /****************************************************************************
  32. *
  33. * local data
  34. *
  35. ***************************************************************************/
  36. static HMIDIIN hMidiIn = NULL;
  37. static int iProfiler;
  38. int FAR PASCAL VolumeDlgProc(HWND, unsigned, UINT, LONG);
  39. /****************************************************************************
  40. *
  41. * internal function prototypes
  42. *
  43. ***************************************************************************/
  44. static void GetInfo(void);
  45. static void CommandMsg(HWND hWnd, UINT wParam, LONG lParam);
  46. /***************************************************************************
  47. get and show device info
  48. ***************************************************************************/
  49. static void GetInfo(void)
  50. {
  51. WAVEOUTCAPS wc;
  52. WAVEINCAPS wic;
  53. MIDIOUTCAPS mc;
  54. MIDIINCAPS mic;
  55. AUXCAPS ac;
  56. UINT wDevs, wDevice;
  57. char acherr[80];
  58. UINT wErr;
  59. wDevs = waveInGetNumDevs();
  60. if (wDevs > 32)
  61. wDevs = 0;
  62. sprintf(ach, "\n%u Wave Input Devices\n", wDevs);
  63. dbgOut;
  64. for (wDevice = 0; wDevice < wDevs; wDevice++) {
  65. sprintf(ach, "Wave input device %u: ", wDevice);
  66. dbgOut;
  67. wErr = waveInGetDevCaps(wDevice, &wic, sizeof(wic));
  68. if (!wErr) {
  69. sprintf(ach, "Mid:%u, Pid:%u, %s", wic.wMid, wic.wPid, (LPSTR) wic.szPname);
  70. dbgOut;
  71. sprintf(ach, "\nFormats:%8.8lXH", wic.dwFormats);
  72. dbgOut;
  73. sprintf(ach, ", channels:%4.4XH\n", wic.wChannels);
  74. dbgOut;
  75. }
  76. else {
  77. sprintf(ach, " Error Getting Wave Input Capabilities\n");
  78. dbgOut;
  79. waveInGetErrorText(wErr, acherr, sizeof(acherr));
  80. sprintf(ach, " Error: %s\n", (LPSTR) acherr);
  81. dbgOut;
  82. }
  83. }
  84. wDevs = waveOutGetNumDevs();
  85. if (wDevs > 32)
  86. wDevs = 0;
  87. sprintf(ach, "\n%u Wave Output Devices\n", wDevs);
  88. for (wDevice = 0; wDevice < wDevs; wDevice++) {
  89. sprintf(ach, "Wave output device %u: ", wDevice);
  90. wErr = waveOutGetDevCaps(wDevice, &wc, sizeof(wc));
  91. if (!wErr) {
  92. sprintf(ach, "Mid:%u, Pid:%u, %s", wc.wMid, wc.wPid, (LPSTR) wc.szPname);
  93. dbgOut;
  94. sprintf(ach, "\nFormats:%8.8lXH\n", wc.dwFormats);
  95. dbgOut;
  96. }
  97. else {
  98. sprintf(ach, " Error Getting Wave Output Capabilities\n");
  99. dbgOut;
  100. waveOutGetErrorText(wErr, acherr, sizeof(acherr));
  101. sprintf(ach, " Error: %s\n", (LPSTR) acherr);
  102. dbgOut;
  103. }
  104. }
  105. wDevs = midiInGetNumDevs();
  106. if (wDevs > 32)
  107. wDevs = 0;
  108. sprintf(ach, "\n%u MIDI Input Devices\n", wDevs);
  109. for (wDevice = 0; wDevice < wDevs; wDevice++) {
  110. sprintf(ach, "MIDI input device %u: ", wDevice);
  111. wErr = midiInGetDevCaps(wDevice, &mic, sizeof(mic));
  112. if (!wErr) {
  113. sprintf(ach, "Mid:%u, Pid:%u, %s\n", mic.wMid, mic.wPid, (LPSTR) mic.szPname);
  114. dbgOut;
  115. }
  116. else {
  117. sprintf(ach, " Error Getting MIDI Input Capabilities\n");
  118. dbgOut;
  119. midiInGetErrorText(wErr, acherr, sizeof(acherr));
  120. sprintf(ach, " Error: %s\n", (LPSTR) acherr);
  121. dbgOut;
  122. }
  123. }
  124. wDevs = midiOutGetNumDevs();
  125. if (wDevs > 32)
  126. wDevs = 0;
  127. sprintf(ach, "\n%u MIDI Output Devices\n", wDevs);
  128. dbgOut;
  129. for (wDevice = 0; wDevice < wDevs; wDevice++) {
  130. sprintf(ach, "MIDI output device %u: ", wDevice);
  131. wErr = midiOutGetDevCaps(wDevice, &mc, sizeof(mc));
  132. if (!wErr) {
  133. sprintf(ach, "Mid:%u, Pid:%u, %s", mc.wMid, mc.wPid, (LPSTR) mc.szPname);
  134. dbgOut;
  135. sprintf(ach, "\nTechnology:%4.4XH", mc.wTechnology);
  136. dbgOut;
  137. sprintf(ach, ", voices:%4.4XH", mc.wVoices);
  138. dbgOut;
  139. sprintf(ach, ", notes:%4.4XH\n", mc.wNotes);
  140. dbgOut;
  141. }
  142. else {
  143. sprintf(ach, " Error Getting MIDI Output Capabilities\n");
  144. dbgOut;
  145. midiOutGetErrorText(wErr, acherr, sizeof(acherr));
  146. sprintf(ach, " Error: %s\n", (LPSTR) acherr);
  147. dbgOut;
  148. }
  149. }
  150. sprintf(ach, "MIDI output device %u: ", MIDIMAPPER);
  151. wErr = midiOutGetDevCaps(MIDIMAPPER, &mc, sizeof(mc));
  152. if (!wErr) {
  153. sprintf(ach, "Mid:%u, Pid:%u, %s", mc.wMid, mc.wPid, (LPSTR) mc.szPname);
  154. dbgOut;
  155. sprintf(ach, "\nTechnology:%4.4XH", mc.wTechnology);
  156. dbgOut;
  157. sprintf(ach, ", voices:%4.4XH", mc.wVoices);
  158. dbgOut;
  159. sprintf(ach, ", notes:%4.4XH\n", mc.wNotes);
  160. dbgOut;
  161. }
  162. else {
  163. sprintf(ach, " Error Getting MIDI Output Capabilities\n");
  164. dbgOut;
  165. midiOutGetErrorText(wErr, acherr, sizeof(acherr));
  166. sprintf(ach, " Error: %s\n", (LPSTR) acherr);
  167. dbgOut;
  168. }
  169. wDevs = auxGetNumDevs();
  170. if (wDevs > 32)
  171. wDevs = 0;
  172. sprintf(ach, "\n%u Auxiliary Output Devices\n", wDevs);
  173. dbgOut;
  174. for (wDevice = 0; wDevice < wDevs; wDevice++) {
  175. sprintf(ach, "Auxiliary output device %u: ", wDevice);
  176. dbgOut;
  177. wErr = auxGetDevCaps(wDevice, &ac, sizeof(ac));
  178. if (!wErr) {
  179. sprintf(ach, "Mid:%u, Pid:%u, %s", ac.wMid, ac.wPid, (LPSTR) ac.szPname);
  180. dbgOut;
  181. sprintf(ach, "\nTechnology:%4.4XH", ac.wTechnology);
  182. dbgOut;
  183. sprintf(ach, ", Support:%4.4XH", ac.dwSupport);
  184. dbgOut;
  185. }
  186. else {
  187. sprintf(ach, " Error Getting Auxiliary Output Capabilities\n");
  188. dbgOut;
  189. }
  190. }
  191. }
  192. /***************** Main entry point routine *************************/
  193. int __cdecl main(int argc, char **argv)
  194. {
  195. MSG msg;
  196. /* fill in non-variant fields of OPENFILENAME struct. */
  197. ofn.lStructSize = sizeof(OPENFILENAME);
  198. ofn.hwndOwner = hMainWnd;
  199. ofn.lpstrFilter = NULL;
  200. ofn.lpstrCustomFilter = NULL;
  201. ofn.nMaxCustFilter = 0;
  202. ofn.nFilterIndex = 1;
  203. ofn.lpstrFile = szFname;
  204. ofn.nMaxFile = MAXFILENAME;
  205. ofn.lpstrInitialDir = NULL;
  206. ofn.lpstrFileTitle = NULL;
  207. ofn.nMaxFileTitle = 0;
  208. ofn.lpstrTitle = NULL;
  209. ofn.lpstrDefExt = "WAV";
  210. ofn.Flags = 0;
  211. ghInst = GetModuleHandle(NULL); // save our instance handle
  212. // medClientInit();
  213. LoadString(ghInst, IDS_APPNAME, szAppName, sizeof(szAppName));
  214. if (! InitFirstInstance(ghInst)) {
  215. return 1;
  216. }
  217. if (!InitEveryInstance(ghInst, SW_SHOWDEFAULT))
  218. return 1;
  219. // check for messages from Windows and process them
  220. // if no messages, perform some idle function
  221. do {
  222. if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
  223. // got a message to process
  224. if (msg.message == WM_QUIT) break;
  225. if (!TranslateAccelerator(hMainWnd, hAccTable, &msg)) {
  226. TranslateMessage(&msg);
  227. DispatchMessage(&msg);
  228. }
  229. }
  230. else {
  231. if (hPosWnd)
  232. ShowPos();
  233. else
  234. WaitMessage();
  235. }
  236. } while (1);
  237. // medClientExit();
  238. return (msg.wParam);
  239. }
  240. /************* main window message handler ******************************/
  241. long FAR PASCAL MainWndProc(HWND hWnd, unsigned message, UINT wParam, LONG lParam)
  242. {
  243. PAINTSTRUCT ps; // paint structure
  244. WAVEOUTCAPS wc;
  245. AUXCAPS ac;
  246. // process any messages we want
  247. switch (message) {
  248. case WM_CREATE:
  249. InitMenus(hWnd);
  250. hPrintfWnd = wpfCreateWindow(hWnd,
  251. ghInst,
  252. "",
  253. WS_CHILD | WS_VISIBLE | WS_VSCROLL,
  254. 0, 0, 0, 0,
  255. 100,
  256. 0);
  257. sprintf(ach, "Wave and MIDI device driver test app.\n");
  258. dbgOut;
  259. waveOutGetDevCaps( 0, &wc, sizeof(wc) );
  260. EnableMenuItem( GetMenu( hWnd ),
  261. IDM_VOLUME,
  262. wc.dwSupport & WAVECAPS_VOLUME
  263. ? MF_ENABLED : MF_GRAYED );
  264. if ( !(wc.dwSupport & WAVECAPS_VOLUME) ) {
  265. hwndVolumeDlg = (HWND)1;
  266. }
  267. memset(&ac, 0, sizeof(ac));
  268. auxGetDevCaps( 0, &ac, sizeof(ac) );
  269. EnableMenuItem( GetMenu( hWnd ),
  270. IDM_AUX_VOLUME,
  271. ac.dwSupport & AUXCAPS_VOLUME
  272. ? MF_ENABLED : MF_GRAYED );
  273. if ( !(wc.dwSupport & WAVECAPS_VOLUME) ) {
  274. AuxNotSupported = 1;
  275. }
  276. #if 0
  277. {
  278. HMENU hMenu;
  279. iProfiler = ProfInsChk();
  280. switch (iProfiler) {
  281. case 1:
  282. sprintf(ach, "Profiler installed for real/286p modes\n");
  283. dbgOut;
  284. break;
  285. case 2:
  286. sprintf(ach, "Profiler installed for real/286p/386p modes\n");
  287. dbgOut;
  288. break;
  289. default:
  290. sprintf(ach, "Profiler not installed\n");
  291. dbgOut;
  292. iProfiler = 0;
  293. hMenu = GetMenu(hWnd);
  294. EnableMenuItem(hMenu, IDM_PROFSTART, MF_GRAYED);
  295. break;
  296. }
  297. }
  298. #endif
  299. break;
  300. case WM_SIZE:
  301. MoveWindow(hPrintfWnd, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
  302. break;
  303. case WM_COMMAND:
  304. // process menu messages
  305. CommandMsg(hWnd, wParam, lParam);
  306. break;
  307. case WM_PAINT:
  308. BeginPaint(hWnd, &ps);
  309. EndPaint(hWnd, &ps);
  310. break;
  311. case WM_DESTROY:
  312. if (hMidiOut)
  313. midiOutClose(hMidiOut);
  314. if (hMidiIn)
  315. midiInClose(hMidiIn);
  316. if (hWaveOut) {
  317. waveOutReset(hWaveOut);
  318. waveOutClose(hWaveOut);
  319. }
  320. if (hWaveIn) {
  321. waveInReset(hWaveIn);
  322. waveInClose(hWaveIn);
  323. }
  324. PostQuitMessage(0);
  325. break;
  326. case MM_WIM_CLOSE:
  327. sprintf(ach, " MM_WIM_CLOSE: %04X %08lX\n",wParam,lParam);
  328. dbgOut;
  329. break;
  330. case MM_WIM_DATA:
  331. sprintf(ach, " MM_WIM_DATA: %04X %08lX\n",wParam,lParam);
  332. dbgOut;
  333. //
  334. // Get more data if possible
  335. //
  336. dwRecorded += ((LPWAVEHDR)lParam)->dwBytesRecorded;
  337. if (hWaveIn &&
  338. (dwDataSize - (lpRecordBuf - (LPSTR)((LPWAVEHDR)lParam)->lpData))
  339. >= dwBlockSize) {
  340. UINT wRet;
  341. char acherr[80];
  342. ((LPWAVEHDR)lParam)->lpData += dwBlockSize;
  343. wRet = waveInAddBuffer(hWaveIn, (LPWAVEHDR)lParam, sizeof(WAVEHDR));
  344. if (wRet) {
  345. waveInGetErrorText(wRet, acherr, sizeof(acherr));
  346. sprintf(ach, "\nwaveInAddBuffer: %s", (LPSTR) acherr);
  347. dbgOut;
  348. }
  349. }
  350. break;
  351. case MM_WIM_OPEN:
  352. sprintf(ach, " MM_WIM_OPEN: %04X %08lX\n",wParam,lParam);
  353. dbgOut;
  354. break;
  355. case MM_WOM_OPEN:
  356. sprintf(ach, " MM_WOM_OPEN: %04X %08lX\n",wParam,lParam);
  357. dbgOut;
  358. break;
  359. case MM_WOM_CLOSE:
  360. sprintf(ach, " MM_WOM_CLOSE: %04X %08lX\n",wParam,lParam);
  361. dbgOut;
  362. if (hWaveOut != (HWAVEOUT)wParam) {
  363. sprintf(ach, " MM_WOM_CLOSE: ACK! wParam doesn't match hWaveOut!!!!\n");
  364. return 0L;
  365. }
  366. iWaveOut = 0;
  367. hWaveOut = NULL;
  368. break;
  369. case MM_WOM_DONE:
  370. sprintf(ach, " MM_WOM_DONE: %04X %08lX\n",wParam,lParam);
  371. dbgOut;
  372. if (hWaveOut != (HWAVEOUT)wParam) {
  373. sprintf(ach, " MM_WOM_DONE: ACK! wParam doesn't match hWaveOut!!!!\n");
  374. return 0L;
  375. }
  376. //
  377. // the wave block is done playing, we need to let the driver unprepare
  378. // it and free the memory it used.
  379. //
  380. // wParam = hWaveOut
  381. // lParam = lpWaveHdr
  382. //
  383. waveOutUnprepareHeader((HWAVEOUT)wParam, (LPWAVEHDR)lParam, sizeof(WAVEHDR));
  384. // GlobalUnlock(lParam);
  385. // LocalFree(lParam);
  386. GlobalFree( (HANDLE)lParam );
  387. //
  388. // if we have no more outstanding blocks free the wave device.
  389. //
  390. if (--iWaveOut == 0) {
  391. sprintf(ach, " MM_WOM_DONE: Releasing the wave device\n");
  392. waveOutClose(hWaveOut);
  393. }
  394. break;
  395. case MM_MIM_OPEN:
  396. sprintf(ach, " MM_MIM_OPEN: %04X %08lX\n",wParam,lParam);
  397. dbgOut;
  398. break;
  399. case MM_MIM_CLOSE:
  400. sprintf(ach, " MM_MIM_CLOSE: %04X %08lX\n",wParam,lParam);
  401. dbgOut;
  402. break;
  403. case MM_MIM_DATA:
  404. sprintf(ach, " MM_MIM_DATA: %04X %08lX\n",wParam,lParam);
  405. dbgOut;
  406. break;
  407. case MM_MIM_LONGDATA:
  408. sprintf(ach, " MM_MIM_LONGDATA: %04X %08lX\n",wParam,lParam);
  409. dbgOut;
  410. break;
  411. case MM_MIM_ERROR:
  412. sprintf(ach, " MM_MIM_ERROR: %04X %08lX\n",wParam,lParam);
  413. dbgOut;
  414. break;
  415. case MM_MIM_LONGERROR:
  416. sprintf(ach, " MM_MIM_LONGERROR: %04X %08lX\n",wParam,lParam);
  417. dbgOut;
  418. break;
  419. case MM_MOM_OPEN:
  420. sprintf(ach, " MM_MOM_OPEN: %04X %08lX\n",wParam,lParam);
  421. dbgOut;
  422. break;
  423. case MM_MOM_CLOSE:
  424. sprintf(ach, " MM_MOM_CLOSE: %04X %08lX\n",wParam,lParam);
  425. dbgOut;
  426. break;
  427. case MM_MOM_DONE:
  428. sprintf(ach, " MM_MOM_DONE: %04X %08lX\n",wParam,lParam);
  429. dbgOut;
  430. break;
  431. case WM_INITMENU:
  432. EnableMenuItem((HWND)wParam, IDM_LOOPBREAK , hWaveOut ? MF_ENABLED : MF_GRAYED);
  433. EnableMenuItem((HWND)wParam, IDM_RESET , hWaveOut ? MF_ENABLED : MF_GRAYED);
  434. EnableMenuItem((HWND)wParam, IDM_PAUSE , hWaveOut ? MF_ENABLED : MF_GRAYED);
  435. EnableMenuItem((HWND)wParam, IDM_RESUME , hWaveOut ? MF_ENABLED : MF_GRAYED);
  436. EnableMenuItem((HWND)wParam, IDM_VOLUME, hwndVolumeDlg ? MF_GRAYED : MF_ENABLED);
  437. EnableMenuItem((HWND)wParam, IDM_AUX_VOLUME, AuxNotSupported ? MF_GRAYED : MF_ENABLED);
  438. break;
  439. }
  440. return DefWindowProc(hWnd, message, wParam, lParam);
  441. }
  442. static void CommandMsg(HWND hWnd, UINT wParam, LONG lParam)
  443. {
  444. int i;
  445. HMENU hMenu;
  446. BYTE acherr[80];
  447. UINT wErr;
  448. UINT wPortNum;
  449. SHORTMSG sm;
  450. switch (wParam) {
  451. case IDM_SNDPLAYSOUND:
  452. case IDM_PLAYWAVE:
  453. // GetProfileString(szAppName, "wavpath", "", szPath, sizeof(szPath));
  454. // if (lstrlen(szPath)) {
  455. // DosChangeDir(szPath);
  456. // }
  457. // i = OpenFileDialog(hMainWnd,
  458. // "Open file",
  459. // "*.WAV",
  460. // DLGOPEN_MUSTEXIST | DLGOPEN_OPEN,
  461. // szFname,
  462. // sizeof(szFname));
  463. // if (i == DLG_MISSINGFILE) {
  464. // sbtestError"Illegal filename");
  465. // }
  466. // else if (i == DLG_CANCEL) {
  467. // // user pressed cancel
  468. // }
  469. // else {
  470. // }
  471. if (GetOpenFileName(&ofn)) {
  472. // valid file name
  473. if (wParam == IDM_SNDPLAYSOUND) {
  474. if (wLoops == IDM_LOOPOFF)
  475. sndPlaySound(ofn.lpstrFile, SND_ASYNC);
  476. else
  477. sndPlaySound(ofn.lpstrFile, SND_ASYNC|SND_LOOP);
  478. }
  479. else {
  480. PlayFile(ofn.lpstrFile);
  481. }
  482. }
  483. break;
  484. case IDM_LOOPOFF:
  485. case IDM_LOOP2:
  486. case IDM_LOOP100:
  487. wLoops = wParam;
  488. hMenu = GetMenu(hWnd);
  489. CheckMenuItem(hMenu, IDM_LOOPOFF, MF_UNCHECKED);
  490. CheckMenuItem(hMenu, IDM_LOOP2, MF_UNCHECKED);
  491. CheckMenuItem(hMenu, IDM_LOOP100, MF_UNCHECKED);
  492. CheckMenuItem(hMenu, wParam, MF_CHECKED);
  493. if (wParam != IDM_LOOP100) {
  494. if (hWaveOut) {
  495. waveOutBreakLoop(hWaveOut);
  496. }
  497. }
  498. break;
  499. case IDM_LOOPBREAK:
  500. if (hWaveOut) {
  501. waveOutBreakLoop(hWaveOut);
  502. }
  503. break;
  504. case IDM_POSITION:
  505. if (hPosWnd == NULL) {
  506. CreatePosition(hWnd);
  507. }
  508. else {
  509. DestroyWindow(hPosWnd);
  510. hPosWnd = NULL;
  511. }
  512. break;
  513. case IDM_RESET:
  514. if (hWaveOut)
  515. waveOutReset(hWaveOut);
  516. break;
  517. case IDM_PAUSE:
  518. if (hWaveOut)
  519. waveOutPause(hWaveOut);
  520. break;
  521. case IDM_RESUME:
  522. if (hWaveOut)
  523. waveOutRestart(hWaveOut);
  524. break;
  525. case IDM_RECORD:
  526. Record(hWnd);
  527. break;
  528. case IDM_AUX_VOLUME:
  529. SetAux = TRUE;
  530. hwndVolumeDlg = CreateDialog(ghInst, "Volume", hWnd, (DLGPROC)VolumeDlgProc);
  531. SetWindowPos( hwndVolumeDlg, (HWND)-1, 0,0,0,0, SWP_NOSIZE | SWP_NOMOVE |
  532. SWP_NOZORDER | SWP_SHOWWINDOW );
  533. break;
  534. case IDM_VOLUME:
  535. SetAux = FALSE;
  536. hwndVolumeDlg = CreateDialog(ghInst, "Volume", hWnd, (DLGPROC)VolumeDlgProc);
  537. SetWindowPos( hwndVolumeDlg, (HWND)-1, 0,0,0,0, SWP_NOSIZE | SWP_NOMOVE |
  538. SWP_NOZORDER | SWP_SHOWWINDOW );
  539. break;
  540. case IDM_I0:
  541. case IDM_I1:
  542. case IDM_I2:
  543. case IDM_I3:
  544. case IDM_I4:
  545. case IDM_I5:
  546. case IDM_I6:
  547. case IDM_I7:
  548. case IDM_I8:
  549. case IDM_I9:
  550. case IDM_I10:
  551. case IDM_I11:
  552. case IDM_I12:
  553. case IDM_I13:
  554. case IDM_I14:
  555. case IDM_I15:
  556. hMenu = GetMenu(hWnd);
  557. for (i = IDM_I0; i <= IDM_I15; i++) {
  558. CheckMenuItem(hMenu, i, MF_UNCHECKED);
  559. }
  560. CheckMenuItem(hMenu, wParam, MF_CHECKED);
  561. EnableMenuItem(hMenu, IDM_STARTMIDIIN, MF_GRAYED);
  562. EnableMenuItem(hMenu, IDM_STOPMIDIIN, MF_GRAYED);
  563. if (hMidiIn) {
  564. midiInClose(hMidiIn);
  565. hMidiIn = NULL;
  566. }
  567. wPortNum = wParam - IDM_I0;
  568. if (wPortNum != 0) {
  569. // NOTE!!! we must PAGE-LOCK our CODE and DATA segment!!!!
  570. // The FIXED segment attribute is ignored for applications
  571. //
  572. // Callbacks *must* be in FIXED code segments of DLLs *not* APPS
  573. //
  574. // *********** THIS APP IS TOTALY WRONG! *************
  575. // ******************* DONT COPY THIS CODE! **********************
  576. // #define GetDS() HIWORD((DWORD)((LPSTR)&hMidiIn))
  577. // GlobalPageLock(GetDS());
  578. wErr = midiInOpen(&hMidiIn, wPortNum - 1, (DWORD)SBMidiInCallback,
  579. (DWORD)hMidiOut, CALLBACK_FUNCTION);
  580. if (wErr) {
  581. sprintf(ach, " Error opening MIDI Input\n");
  582. dbgOut;
  583. midiInGetErrorText(wErr, acherr, sizeof(acherr));
  584. sprintf(ach, " Error: %s\n", (LPSTR) acherr);
  585. dbgOut;
  586. hMidiIn = NULL;
  587. CheckMenuItem(hMenu, wParam, MF_UNCHECKED);
  588. CheckMenuItem(hMenu, IDM_I0, MF_CHECKED);
  589. }
  590. else
  591. EnableMenuItem(hMenu, IDM_STARTMIDIIN, MF_ENABLED);
  592. }
  593. break;
  594. case IDM_STARTMIDIIN:
  595. if (hMidiIn) {
  596. hMenu = GetMenu(hWnd);
  597. EnableMenuItem(hMenu, IDM_STARTMIDIIN, MF_GRAYED);
  598. EnableMenuItem(hMenu, IDM_STOPMIDIIN, MF_ENABLED);
  599. midiInStart(hMidiIn);
  600. }
  601. break;
  602. case IDM_STOPMIDIIN:
  603. if (hMidiIn) {
  604. hMenu = GetMenu(hWnd);
  605. EnableMenuItem(hMenu, IDM_STOPMIDIIN, MF_GRAYED);
  606. EnableMenuItem(hMenu, IDM_STARTMIDIIN, MF_ENABLED);
  607. midiInStop(hMidiIn);
  608. }
  609. break;
  610. case IDM_D0:
  611. case IDM_D1:
  612. case IDM_D2:
  613. case IDM_D3:
  614. case IDM_D4:
  615. case IDM_D5:
  616. case IDM_D6:
  617. case IDM_D7:
  618. case IDM_D8:
  619. case IDM_D9:
  620. case IDM_D10:
  621. case IDM_D11:
  622. case IDM_D12:
  623. case IDM_D13:
  624. case IDM_D14:
  625. case IDM_D15:
  626. hMenu = GetMenu(hWnd);
  627. for (i = IDM_D0; i <= IDM_D15; i++) {
  628. CheckMenuItem(hMenu, i, MF_UNCHECKED);
  629. }
  630. CheckMenuItem(hMenu, wParam, MF_CHECKED);
  631. if (hMidiOut) {
  632. midiOutClose(hMidiOut);
  633. hMidiOut = NULL;
  634. }
  635. if (wParam == IDM_D0 + LASTPORT)
  636. wPortNum = MIDIMAPPER; // open mapper if chose last item
  637. else
  638. wPortNum = wParam - IDM_D0 - 1;
  639. if (wParam != IDM_D0) {
  640. wErr = midiOutOpen(&hMidiOut, wPortNum, (DWORD)hWnd, 0L, 0L);
  641. if (wErr) {
  642. sprintf(ach, " Error opening MIDI Output\n");
  643. dbgOut;
  644. midiOutGetErrorText(wErr, acherr, sizeof(acherr));
  645. sprintf(ach, " Error: %s\n", (LPSTR) acherr);
  646. dbgOut;
  647. hMidiOut = NULL;
  648. }
  649. else { // send patch change
  650. sm.b[0] = (BYTE) 0xC0 + bChannel;
  651. sm.b[1] = bInstrument;
  652. midiOutShortMsg(hMidiOut, sm.dw);
  653. }
  654. }
  655. break;
  656. case IDM_C0:
  657. case IDM_C1:
  658. case IDM_C2:
  659. case IDM_C3:
  660. case IDM_C4:
  661. case IDM_C5:
  662. case IDM_C6:
  663. case IDM_C7:
  664. case IDM_C8:
  665. case IDM_C9:
  666. case IDM_C10:
  667. case IDM_C11:
  668. case IDM_C12:
  669. case IDM_C13:
  670. case IDM_C14:
  671. case IDM_C15:
  672. hMenu = GetMenu(hWnd);
  673. for (i = IDM_C0; i <= IDM_C15; i++) {
  674. CheckMenuItem(hMenu, i, MF_UNCHECKED);
  675. }
  676. CheckMenuItem(hMenu, wParam, MF_CHECKED);
  677. bChannel = (BYTE)(wParam - IDM_C0);
  678. break;
  679. case IDM_KEYBOARD:
  680. if (hKeyWnd == NULL) {
  681. CreateKeyboard(hWnd);
  682. }
  683. else {
  684. DestroyWindow(hKeyWnd);
  685. hKeyWnd = NULL;
  686. }
  687. break;
  688. case IDM_INSTRUMENT:
  689. if (hInstWnd == NULL) {
  690. CreateInstrument(hWnd);
  691. }
  692. else {
  693. DestroyWindow(hInstWnd);
  694. hInstWnd = NULL;
  695. }
  696. break;
  697. case IDM_DUMPPATCH:
  698. hMenu = GetMenu(hWnd);
  699. if (ISBITSET(fDebug, DEBUG_PATCH))
  700. RESETBIT(fDebug, DEBUG_PATCH);
  701. else
  702. SETBIT(fDebug, DEBUG_PATCH);
  703. CheckMenuItem(hMenu, wParam,
  704. ISBITSET(fDebug, DEBUG_PATCH) ? MF_CHECKED : MF_UNCHECKED);
  705. break;
  706. case IDM_DUMPNOTES:
  707. hMenu = GetMenu(hWnd);
  708. if (ISBITSET(fDebug, DEBUG_NOTE))
  709. RESETBIT(fDebug, DEBUG_NOTE);
  710. else
  711. SETBIT(fDebug, DEBUG_NOTE);
  712. CheckMenuItem(hMenu, wParam,
  713. ISBITSET(fDebug, DEBUG_NOTE) ? MF_CHECKED : MF_UNCHECKED);
  714. break;
  715. case IDM_RIP:
  716. //
  717. // send total stuff to mmsystem APIs
  718. //
  719. waveOutPrepareHeader((HWAVEOUT)1, NULL, sizeof(WAVEHDR));
  720. waveOutClose(NULL);
  721. midiInPrepareHeader(0, (LPMIDIHDR)-1l, 4);
  722. midiOutClose((HMIDIOUT)(-1));
  723. break;
  724. case IDM_GETINFO:
  725. GetInfo();
  726. break;
  727. case IDM_WAVEOPTIONS:
  728. WaveOptions(hWnd);
  729. break;
  730. case IDM_MIDIOPTIONS:
  731. MidiOptions(hWnd);
  732. break;
  733. case IDM_ABOUT:
  734. About(hWnd);
  735. break;
  736. case IDM_EXIT:
  737. PostMessage(hWnd, WM_CLOSE, 0, 0l);
  738. break;
  739. #if 0
  740. case IDM_PROFSTART:
  741. if (iProfiler) {
  742. GetProfileString(szAppName, "profpath", "", szPath, sizeof(szPath));
  743. if (lstrlen(szPath)) {
  744. DosChangeDir(szPath);
  745. }
  746. ProfStart();
  747. sprintf(ach, "\nProfiler started. Files in %s", (LPSTR) szPath);
  748. dbgOut;
  749. EnableMenuItem(hMenu, IDM_PROFSTART, MF_GRAYED);
  750. EnableMenuItem(hMenu, IDM_PROFSTOP, MF_ENABLED);
  751. }
  752. break;
  753. case IDM_PROFSTOP:
  754. if (iProfiler) {
  755. ProfStop();
  756. ProfFlush();
  757. sprintf(ach, "\nProfiler stopped");
  758. dbgOut;
  759. EnableMenuItem(hMenu, IDM_PROFSTART, MF_ENABLED);
  760. EnableMenuItem(hMenu, IDM_PROFSTOP, MF_GRAYED);
  761. }
  762. break;
  763. #endif
  764. default:
  765. break;
  766. }
  767. }
  768. int FAR PASCAL VolumeDlgProc(HWND hwnd, unsigned msg, UINT wParam, LONG lParam )
  769. {
  770. static HWND hwndScrollbar;
  771. static int iScrollPos;
  772. DWORD dwVolumeLevel;
  773. DWORD dwNewVolumeLevel;
  774. WORD wVolumeLeft;
  775. WORD wVolumeRight;
  776. WORD ret;
  777. switch (msg) {
  778. case WM_INITDIALOG:
  779. /*
  780. * What is the current volume setting ?
  781. */
  782. (SetAux ? auxGetVolume : waveOutGetVolume)( 0, &dwVolumeLevel );
  783. /*
  784. * Take the average of the left and right volume settings
  785. */
  786. wVolumeLeft = LOWORD( dwVolumeLevel );
  787. wVolumeRight = HIWORD( dwVolumeLevel );
  788. iScrollPos = ( wVolumeLeft + wVolumeRight ) >> 9;
  789. /*
  790. * Set the scroll bar and level indicator
  791. */
  792. hwndScrollbar = GetDlgItem( hwnd, 105 ); /* 105 is the scroll bar */
  793. SetScrollRange( hwndScrollbar, SB_CTL, 0, 255, FALSE );
  794. SetScrollPos( hwndScrollbar, SB_CTL, iScrollPos, TRUE );
  795. SetDlgItemInt( hwnd, 104, iScrollPos << 8, FALSE );
  796. break;
  797. case WM_HSCROLL:
  798. switch ( LOWORD( wParam ) ) {
  799. case SB_BOTTOM:
  800. iScrollPos = 0;
  801. break;
  802. case SB_TOP:
  803. iScrollPos = 255;
  804. break;
  805. case SB_LINEUP:
  806. iScrollPos--;
  807. break;
  808. case SB_LINEDOWN:
  809. iScrollPos++;
  810. break;
  811. case SB_PAGEDOWN:
  812. iScrollPos += 16;
  813. break;
  814. case SB_PAGEUP:
  815. iScrollPos -= 16;
  816. break;
  817. case SB_THUMBPOSITION:
  818. case SB_THUMBTRACK:
  819. iScrollPos = HIWORD( wParam );
  820. break;
  821. }
  822. /*
  823. * Make sure that the new setting is within the correct volume
  824. * range
  825. */
  826. if ( iScrollPos > 255 ) {
  827. iScrollPos = 255;
  828. }
  829. if ( iScrollPos < 0 ) {
  830. iScrollPos = 0;
  831. }
  832. /*
  833. * Update the scrollbar position and value indicator
  834. */
  835. SetScrollPos( hwndScrollbar, SB_CTL, iScrollPos, TRUE );
  836. SetDlgItemInt( hwnd, 104, iScrollPos << 8, FALSE );
  837. /*
  838. * Set the volume on the device and make sure that the
  839. * volume has been set correctly.
  840. */
  841. dwVolumeLevel = MAKELONG( iScrollPos << 8, iScrollPos << 8 );
  842. if ( 0 != (ret =
  843. (SetAux ? auxSetVolume : waveOutSetVolume)( 0, dwVolumeLevel ) ) ) {
  844. sprintf( ach, "\n waveOutSetVolume %8X ret = %d ",
  845. dwVolumeLevel, ret );
  846. dbgOut;
  847. }
  848. else {
  849. (SetAux ? auxGetVolume : waveOutGetVolume)( 0, &dwNewVolumeLevel );
  850. if ( dwNewVolumeLevel != dwVolumeLevel) {
  851. sprintf( ach, "\n New volume not set correctly" );
  852. dbgOut;
  853. }
  854. }
  855. break;
  856. case WM_COMMAND:
  857. DestroyWindow( hwnd );
  858. hwndVolumeDlg = (HWND)NULL;
  859. break;
  860. default:
  861. return FALSE;
  862. break;
  863. }
  864. return TRUE;
  865. }