Leaked source code of windows server 2003
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.

128 lines
3.7 KiB

  1. /**********************************************************************
  2. Copyright (c) 1992-1998 Microsoft Corporation
  3. cookmap.c
  4. DESCRIPTION:
  5. Non-fixed code for doing cooked-mode output mapping.
  6. HISTORY:
  7. 03/04/94 [jimge] created.
  8. *********************************************************************/
  9. #include "preclude.h"
  10. #include <windows.h>
  11. #include <windowsx.h>
  12. #include <mmsystem.h>
  13. #include <mmddk.h>
  14. #include "idf.h"
  15. #include <memory.h>
  16. #include "midimap.h"
  17. #include "debug.h"
  18. /***************************************************************************
  19. @doc internal
  20. @api int | MapCookedBuffer | Perform output mapping of a polymsg buffer.
  21. @parm PINSTANCE | pinstance | Instance owning the polymsg buffer.
  22. @parm LPMIDIHDR | lpmh | The buffer to map.
  23. @comm
  24. Map this buffer (which may allocate more channels to us).
  25. Build array of used ports and physical channels used on each port.
  26. Acquire shadow buffers and a sync object and set them up.
  27. Queue the sync object and send it if there isn't anything playing.
  28. @rdesc | MMSYSERR_xxx.
  29. ***************************************************************************/
  30. #define SKIP_BYTES(x,s) \
  31. { \
  32. if (cbBuffer < (x)) \
  33. { \
  34. DPF(1, TEXT ("MapCookedBuffer: ran off end of polymsg buffer in parse! %ls"), (LPTSTR)(s)); \
  35. mmRet = MMSYSERR_INVALPARAM; \
  36. goto CLEANUP; \
  37. } \
  38. ((LPBYTE)lpdwBuffer) += (x); \
  39. cbBuffer -= (x); \
  40. }
  41. MMRESULT FNGLOBAL MapCookedBuffer(
  42. PINSTANCE pinstance,
  43. LPMIDIHDR lpmhParent)
  44. {
  45. LPDWORD lpdwBuffer;
  46. DWORD cbBuffer;
  47. BYTE bEventType;
  48. DWORD dwEvent;
  49. DWORD dwStreamID = 0;
  50. MMRESULT mmRet;
  51. LPMIDIHDR lpmh;
  52. PSHADOWBLOCK psb;
  53. mmRet = MMSYSERR_NOERROR;
  54. psb = (PSHADOWBLOCK)(UINT_PTR)lpmhParent->dwReserved[MH_SHADOW];
  55. lpmh = psb->lpmhShadow;
  56. DPF(2, TEXT ("Map: pinstance %04X lpmh %p"), (WORD)pinstance, lpmh);
  57. lpmh->reserved = lpmhParent->reserved;
  58. lpmh->dwBytesRecorded = lpmhParent->dwBytesRecorded;
  59. lpmh->dwReserved[MH_MAPINST] = (DWORD_PTR)pinstance;
  60. // In-place map the buffer. Run through it, mapping all of the
  61. // short events.
  62. //
  63. lpdwBuffer = (LPDWORD)lpmh->lpData;
  64. cbBuffer = lpmh->dwBytesRecorded;
  65. while (cbBuffer)
  66. {
  67. SKIP_BYTES(sizeof(DWORD), TEXT ("d-time"));
  68. if (cbBuffer < 2*sizeof(DWORD))
  69. return MMSYSERR_INVALPARAM;
  70. bEventType = MEVT_EVENTTYPE(lpdwBuffer[1]);
  71. dwEvent = MEVT_EVENTPARM(lpdwBuffer[1]);
  72. if (bEventType == MEVT_SHORTMSG)
  73. {
  74. dwEvent = MapSingleEvent(pinstance,
  75. dwEvent,
  76. MSE_F_RETURNEVENT,
  77. (DWORD BSTACK *)&dwStreamID);
  78. lpdwBuffer[0] = dwStreamID;
  79. lpdwBuffer[1] = dwEvent;
  80. }
  81. SKIP_BYTES(sizeof(DWORD), TEXT ("stream-id"));
  82. SKIP_BYTES(sizeof(DWORD), TEXT ("event type"));
  83. if (bEventType & (MEVT_F_LONG >> 24))
  84. {
  85. dwEvent = (dwEvent+3)&~3;
  86. SKIP_BYTES(dwEvent, TEXT ("long event data"));
  87. }
  88. }
  89. mmRet = midiStreamOut(ghMidiStrm, lpmh, sizeof(MIDIHDR));
  90. CLEANUP:
  91. return mmRet;
  92. }