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.

524 lines
18 KiB

  1. /**********************************************************************
  2. Copyright (c) 1992-1999 Microsoft Corporation
  3. midimap.h
  4. DESCRIPTION:
  5. Main private include file for the MIDI mapper.
  6. *********************************************************************/
  7. #ifndef _MIDIMAP_
  8. #define _MIDIMAP_
  9. //
  10. // The following macro defines a CODE based pointer to data, which
  11. // is used for constants that do not need to be placed in the read/write
  12. // DATA segment.
  13. //
  14. #ifdef WIN32
  15. #define __based(a)
  16. #endif
  17. #ifdef WIN32
  18. #define BCODE
  19. #define BSTACK
  20. #else
  21. #define BCODE __based(__segname("_CODE"))
  22. #define BSTACK __based(__segname("_STACK"))
  23. #endif
  24. #include <mmsysp.h>
  25. // Defines Win95 stuff not supported in NT 4.0
  26. // Remove as soon as it is supported
  27. #include "mmcompat.h"
  28. //
  29. // Macro definitions
  30. //
  31. #ifdef DEBUG
  32. #define PRIVATE
  33. #else
  34. #define PRIVATE static
  35. #endif
  36. #ifndef ARRAYSIZE
  37. #define ARRAYSIZE(a) (sizeof((a))/sizeof((a)[0]))
  38. #endif
  39. #define DEF_TRANS_SIZE 512
  40. #define DEF_CHAN_PER_INST 8
  41. #define FNLOCAL NEAR PASCAL
  42. #define FNGLOBAL FAR PASCAL
  43. //#define FNEXPORT FAR PASCAL __export
  44. #define FNEXPORT FAR PASCAL
  45. #define VERSION_MINOR 0x01
  46. #define VERSION_MAJOR 0x04
  47. #define MMAPPER_VERSION ((DWORD)(WORD)((BYTE)VERSION_MINOR | (((WORD)(BYTE)VERSION_MAJOR) << 8)))
  48. // Indices 3,4,5 into LPMIDIHDR->dwReserved[] are reserved for MIDI mapper
  49. //
  50. #define MH_MAPINST 3 // Mapper instance owning this header
  51. #define MH_SHADOW 4 // Cross links between parent/child
  52. #define MH_SHADOWEE 4 // shadow headers
  53. #define MH_LMREFCNT 5 // Long message reference count
  54. #define MAX_CHANNELS 16
  55. #define ALL_CHANNELS (0xFFFF) // Channel mask
  56. #define DRUM_CHANNEL 9
  57. #define MAX_CHAN_TYPES 2
  58. #define IDX_CHAN_GEN 0
  59. #define IDX_CHAN_DRUM 1
  60. #define CB_MAXDRIVER 64
  61. #define CB_MAXSCHEME 64
  62. #define CB_MAXINSTR 64
  63. #define CB_MAXALIAS 64
  64. #define CB_MAXDEVKEY 64
  65. #define CB_MAXPATH 256
  66. #define CB_MAXDEFINITION (256+64+2) // file<instrument>
  67. #define NO_DEVICEID ((UINT)-2)
  68. #define MSG_STATUS(dw) ((BYTE)((dw) & 0xFF))
  69. #define MSG_PARM1(dw) ((BYTE)(((dw) >> 8) & 0xFF))
  70. #define MSG_PARM2(dw) ((BYTE)(((dw) >> 16) & 0xFF))
  71. #define MSG_PACK1(bs,b1) ((DWORD)((((DWORD)(b1)) << 8) | ((DWORD)(bs))))
  72. #define MSG_PACK2(bs,b1,b2) ((DWORD)((((DWORD)(b2)) << 16) | (((DWORD)(b1)) << 8) | ((DWORD)(bs))))
  73. #define IS_REAL_TIME(b) ((b) > 0xF7)
  74. #define IS_STATUS(b) ((b) & 0x80)
  75. #define MSG_EVENT(b) ((b) & 0xF0)
  76. #define MSG_CHAN(b) ((b) & 0x0F)
  77. #define MIDI_NOTEOFF ((BYTE)0x80)
  78. #define MIDI_NOTEON ((BYTE)0x90)
  79. #define MIDI_POLYPRESSURE ((BYTE)0xA0)
  80. #define MIDI_CONTROLCHANGE ((BYTE)0xB0)
  81. #define MIDI_PROGRAMCHANGE ((BYTE)0xC0)
  82. #define MIDI_CHANPRESSURE ((BYTE)0xD0)
  83. #define MIDI_PITCHBEND ((BYTE)0xE0)
  84. #define MIDI_SYSEX ((BYTE)0xF0)
  85. #define MIDI_QFRAME ((BYTE)0xF1)
  86. #define MIDI_SONGPOINTER ((BYTE)0xF2)
  87. #define MIDI_SONGSELECT ((BYTE)0xF3)
  88. #define MIDI_F4 ((BYTE)0xF4)
  89. #define MIDI_F5 ((BYTE)0xF5)
  90. #define MIDI_TUNEREQUEST ((BYTE)0xF6)
  91. #define MIDI_SYSEXEND ((BYTE)0xF7)
  92. #define MIDI_TIMINGCLOCK ((BYTE)0xF8)
  93. #define MIDI_F9 ((BYTE)0xF9)
  94. #define MIDI_START ((BYTE)0xFA)
  95. #define MIDI_CONTINUE ((BYTE)0xFB)
  96. #define MIDI_STOP ((BYTE)0xFC)
  97. #define MIDI_FD ((BYTE)0xFD)
  98. #define MIDI_ACTIVESENSING ((BYTE)0xFE)
  99. #define MIDI_META ((BYTE)0xFF)
  100. #define DWORD_ROUND(x) (((x)+3L)&~3L)
  101. // Global flags in gwFlags
  102. //
  103. #define GF_ENABLED 0x0001
  104. #define GF_CONFIGERR 0x0002
  105. #define GF_NEEDRUNONCE 0x0004
  106. #define GF_DONERUNONCE 0x0008
  107. #define GF_DEVSOPENED 0x0010
  108. #define GF_RECONFIGURE 0x0020
  109. #define GF_INRUNONCE 0x0040
  110. #define GF_ALLOWVOLUME 0x0080
  111. #define GF_ALLOWCACHE 0x0100
  112. #define GF_KILLTHREAD 0x0200
  113. #define SET_ENABLED {gwFlags |= GF_ENABLED;}
  114. #define CLR_ENABLED {gwFlags &=~GF_ENABLED;}
  115. #define IS_ENABLED (gwFlags & GF_ENABLED)
  116. #define SET_CONFIGERR {gwFlags |= GF_CONFIGERR;}
  117. #define CLR_CONFIGERR {gwFlags &=~GF_CONFIGERR;}
  118. #define IS_CONFIGERR (gwFlags & GF_CONFIGERR)
  119. #define SET_NEEDRUNONCE {gwFlags |= GF_NEEDRUNONCE;}
  120. #define CLR_NEEDRUNONCE {gwFlags &=~GF_NEEDRUNONCE;}
  121. #define IS_NEEDRUNONCE (gwFlags & GF_NEEDRUNONCE)
  122. #define SET_DONERUNONCE {gwFlags |= GF_DONERUNONCE;}
  123. #define CLR_DONERUNONCE {gwFlags &=~GF_DONERUNONCE;}
  124. #define IS_DONERUNONCE (gwFlags & GF_DONERUNONCE)
  125. #define SET_DEVSOPENED {gwFlags |= GF_DEVSOPENED;}
  126. #define CLR_DEVSOPENED {gwFlags &=~GF_DEVSOPENED;}
  127. #define IS_DEVSOPENED (gwFlags & GF_DEVSOPENED)
  128. #define SET_RECONFIGURE {gwFlags |= GF_RECONFIGURE;}
  129. #define CLR_RECONFIGURE {gwFlags &=~GF_RECONFIGURE;}
  130. #define IS_RECONFIGURE (gwFlags & GF_RECONFIGURE)
  131. #define SET_INRUNONCE {gwFlags |= GF_INRUNONCE;}
  132. #define CLR_INRUNONCE {gwFlags &=~GF_INRUNONCE;}
  133. #define IS_INRUNONCE (gwFlags & GF_INRUNONCE)
  134. #define SET_ALLOWVOLUME {gwFlags |= GF_ALLOWVOLUME;}
  135. #define CLR_ALLOWVOLUME {gwFlags &=~GF_ALLOWVOLUME;}
  136. #define IS_ALLOWVOLUME (gwFlags & GF_ALLOWVOLUME)
  137. #define SET_ALLOWCACHE {gwFlags |= GF_ALLOWCACHE;}
  138. #define CLR_ALLOWCACHE {gwFlags &=~GF_ALLOWCACHE;}
  139. #define IS_ALLOWCACHE (gwFlags & GF_ALLOWCACHE)
  140. #define SET_KILLTHREAD {gwFlags |= GF_KILLTHREAD;}
  141. #define CLR_KILLTHREAD {gwFlags &=~GF_KILLTHREAD;}
  142. #define IS_KILLTHREAD (gwFlags & GF_KILLTHREAD)
  143. //=========================== Typedef's=====================================
  144. //
  145. typedef struct tagQUEUE NEAR *PQUEUE;
  146. typedef struct tagQUEUEELE NEAR *PQUEUEELE;
  147. typedef struct tagCHANINIT NEAR *PCHANINIT;
  148. typedef struct tagCHANNEL NEAR *PCHANNEL;
  149. typedef struct tagPORT NEAR *PPORT;
  150. typedef struct tagINSTRUMENT NEAR *PINSTRUMENT;
  151. typedef struct tagINSTPORT NEAR *PINSTPORT;
  152. typedef struct tagINSTANCE NEAR *PINSTANCE;
  153. typedef struct tagCOOKSYNCOBJ NEAR *PCOOKSYNCOBJ;
  154. typedef struct tagQUEUE
  155. {
  156. CRITICAL_SECTION cs;
  157. PQUEUEELE pqeFront;
  158. PQUEUEELE pqeRear;
  159. DWORD cEle;
  160. } QUEUE;
  161. #define QueueIsEmpty(q) (NULL == (q)->pqeFront)
  162. #define QueueCount(q) ((q)->cEle)
  163. typedef struct tagQUEUEELE
  164. {
  165. PQUEUEELE pqePrev;
  166. PQUEUEELE pqeNext;
  167. UINT uPriority;
  168. } QUEUEELE;
  169. typedef struct tagCHANINIT
  170. {
  171. DWORD cbInit;
  172. PBYTE pbInit;
  173. } CHANINIT;
  174. // Flags for this channel which indicate what type of channel it is
  175. // and whether or not it's allocated.
  176. //
  177. #define CHAN_F_OPEN (0x0001)
  178. #define CHAN_F_ALLOCATED (0x0002)
  179. #define CHAN_F_DRUM (0x0004)
  180. #define CHAN_F_GENERAL (0x0008)
  181. #define CHAN_F_MUTED (0x0010)
  182. typedef struct tagCHANNEL
  183. {
  184. // QUEUEELE q; // !!! MUST BE FIRST !!!
  185. PPORT pport;
  186. WORD fwChannel;
  187. UINT uChannel; // This physical channel #
  188. PINSTRUMENT pinstrument; // -> IDF describing this channel
  189. PBYTE pbPatchMap; // In use patch map
  190. PBYTE pbKeyMap; // In use key map
  191. DWORD dwStreamID; // Stream ID if cooked
  192. } CHANNEL;
  193. #define PORT_F_REMOVE (0x0001)
  194. #define PORT_F_HASDRUMCHANNEL (0x0002)
  195. #define PORT_F_OPENFAILED (0x0004)
  196. #define PORT_F_RESET (0x0008)
  197. #define PORT_F_GENERICINSTR (0x0010)
  198. typedef struct tagPORT
  199. {
  200. PPORT pNext;
  201. UINT cRef;
  202. WORD fwPort;
  203. WORD wChannelMask;
  204. UINT uDeviceID;
  205. HMIDIOUT hmidi;
  206. } PORT;
  207. #define IDF_F_GENERICINSTR (0x80000000L)
  208. typedef struct tagINSTRUMENT
  209. {
  210. PINSTRUMENT pNext;
  211. LPTSTR pstrFilename; // Filename of IDF
  212. LPTSTR pstrInstrument; // Instrument name from IDF
  213. UINT cRef; // # ports which are using this IDF
  214. DWORD fdwInstrument;
  215. DWORD dwGeneralMask;
  216. DWORD dwDrumMask;
  217. PBYTE pbPatchMap; // -> 128 bytes of patch map
  218. PBYTE pbDrumKeyMap; // -> 128 bytes of key map
  219. PBYTE pbGeneralKeyMap; // -> 128 bytes of key map
  220. CHANINIT rgChanInit[MAX_CHANNELS];
  221. } INSTRUMENT;
  222. #define INST_F_TIMEDIV (0x0001) // Instance has received MIDIPROP_TIMEDIV
  223. #define INST_F_TEMPO (0x0002) // Instance has received MIDIPROP_TEMPO
  224. #define INST_F_IOCTL (0x0004) // IOCTL open
  225. typedef struct tagINSTANCE
  226. {
  227. PINSTANCE pNext;
  228. // stuff we need to save so we can do callbacks
  229. //
  230. HMIDI hmidi; // MMSYSTEM's handle
  231. DWORD_PTR dwCallback; // Callback address
  232. DWORD_PTR dwInstance; // User instance data
  233. DWORD fdwOpen; // Describe the callback & open mode
  234. QUEUE qCookedHdrs; // Cooked headers pending to be sent
  235. WORD fwInstance; // Instance flags
  236. BYTE bRunningStatus; // Need to track running status
  237. // Translation Buffer
  238. CRITICAL_SECTION csTrans; // Critical Section for Translation buffer
  239. LPBYTE pTranslate; // Buffer For Translating MODM_LONGDATA messages
  240. DWORD cbTransSize; // Current Translation buffer size
  241. } INSTANCE;
  242. #if 0
  243. typedef struct tagCOOKINSTANCE
  244. {
  245. INSTANCE inst; // Common instance data
  246. UINT cInstPort; // # ports in use on instance
  247. INSTPORT rginstport[MAX_CHANNELS];
  248. DWORD dwTimeDiv; // MIDIPROP_TIMEDIV
  249. DWORD dwTempo; // MIDIPROP_TEMPO
  250. } COOKINSTANCE;
  251. #endif
  252. typedef struct tagCOOKSYNCOBJ
  253. {
  254. QUEUEELE q; // !!! MUST BE FIRST !!!
  255. LPMIDIHDR lpmh; // First of our shadow headers
  256. LPMIDIHDR lpmhUser; // Original user header
  257. PINSTANCE pinstance; // Owning pinstance
  258. UINT cLPMH; // # allocated
  259. UINT cSync; // # outstanding
  260. } COOKSYNCOBJ;
  261. typedef struct tagSHADOWBLOCK
  262. {
  263. LPMIDIHDR lpmhShadow;
  264. DWORD cRefCnt;
  265. DWORD dwBufferLength;
  266. } SHADOWBLOCK, *PSHADOWBLOCK;
  267. #define DRV_GETMAPPERSTATUS (DRV_USER+3)
  268. #define DRV_REGISTERDEBUGCB (DRV_USER+4)
  269. #define DRV_GETNEXTLOGENTRY (DRV_USER+5)
  270. typedef struct tagMAPPERSTATUS
  271. {
  272. DWORD cbStruct;
  273. #ifndef WIN32
  274. __segment DS;
  275. #endif
  276. HINSTANCE ghinst;
  277. WORD gwFlags;
  278. WORD gwConfigWhere;
  279. PCHANNEL* pgapChannel;
  280. PPORT gpportList;
  281. PINSTANCE gpinstanceList;
  282. PINSTRUMENT gpinstrumentList;
  283. LPTSTR lpszVersion;
  284. } MAPPERSTATUS,
  285. FAR *LPMAPPERSTATUS;
  286. //=========================== Globals ======================================
  287. //
  288. extern PCHANNEL gapChannel[];
  289. extern WORD gwFlags;
  290. extern WORD gwConfigWhere;
  291. extern UINT gcPorts;
  292. extern HINSTANCE ghinst;
  293. extern PPORT gpportList;
  294. extern PINSTANCE gpinstanceList;
  295. extern PINSTANCE gpIoctlInstance;
  296. extern PINSTRUMENT gpinstrumentList;
  297. extern QUEUE gqFreeSyncObjs;
  298. extern HMIDISTRM ghMidiStrm;
  299. extern DWORD gdwVolume;
  300. //=========================== Prototypes ===================================
  301. //
  302. extern BOOL FNGLOBAL UpdateInstruments( // config.c
  303. BOOL fFromCPL,
  304. DWORD fdwUpdate);
  305. extern BOOL FNGLOBAL Configure( // config.c
  306. DWORD fdwUpdate);
  307. extern BOOL FNLOCAL AddPort( // config.c
  308. UINT uDeviceID,
  309. UINT uPorts,
  310. PSTR szSysIniEntry);
  311. extern void FNGLOBAL SyncDeviceIDs( // config.c
  312. void);
  313. extern LPIDFHEADER FNLOCAL ReadHeaderChunk( // file.c
  314. HMMIO hmmio,
  315. LPMMCKINFO pchkParent);
  316. extern LPIDFINSTCAPS FNLOCAL ReadCapsChunk( // file.c
  317. HMMIO hmmio,
  318. LPMMCKINFO pchkParent);
  319. extern LPIDFCHANNELHDR FNLOCAL ReadChannelChunk( // file.c
  320. HMMIO hmmio,
  321. LPMMCKINFO pchkParent,
  322. LPIDFCHANNELINFO BSTACK rglpChanInfo[]);
  323. extern LPIDFPATCHMAPHDR FNLOCAL ReadPatchMapChunk( // file.c
  324. HMMIO hmmio,
  325. LPMMCKINFO pchkParent);
  326. extern void FNLOCAL ReadKeyMapChunk( // file.c
  327. HMMIO hmmio,
  328. LPMMCKINFO pchkParent,
  329. LPIDFKEYMAP BSTACK rglpIDFkeymap[]);
  330. extern void CALLBACK _loadds modmCallback( // modfix.c
  331. HMIDIOUT hmo,
  332. WORD wmsg,
  333. DWORD_PTR dwInstance,
  334. DWORD_PTR dwParam1,
  335. DWORD_PTR dwParam2);
  336. #define MSE_F_SENDEVENT (0x0000L)
  337. #define MSE_F_RETURNEVENT (0x0001L)
  338. extern DWORD FNGLOBAL MapSingleEvent( // modfix.c
  339. PINSTANCE pinstance,
  340. DWORD dwData,
  341. DWORD fdwFlags,
  342. DWORD BSTACK * pdwStreamID);
  343. extern DWORD FNLOCAL modLongMsg( // modfix.c
  344. PINSTANCE pinstance,
  345. LPMIDIHDR lpmh);
  346. extern MMRESULT FNGLOBAL MapCookedBuffer( // cookmap.c
  347. PINSTANCE pinstance,
  348. LPMIDIHDR lpmh);
  349. extern DWORD FNGLOBAL modGetDevCaps( // modmsg.c
  350. LPMIDIOUTCAPS pmoc,
  351. DWORD cbmoc);
  352. extern DWORD FNGLOBAL modOpen( // modmsg.c
  353. PDWORD_PTR lpdwInstance,
  354. LPMIDIOPENDESC lpmidiopendesc,
  355. DWORD fdwOpen);
  356. extern BOOL FNGLOBAL CanChannelBeDrum( // modmsg.c
  357. PQUEUEELE pqe);
  358. extern DWORD FNGLOBAL modClose( // modmsg.c
  359. PINSTANCE pinstance);
  360. extern DWORD FNGLOBAL modPrepare(
  361. LPMIDIHDR lpmh); // modmsg.c
  362. extern DWORD FNGLOBAL modUnprepare( // modmsg.c
  363. LPMIDIHDR lpmh);
  364. extern DWORD FNGLOBAL modGetPosition( // modmsg.c
  365. PINSTANCE pinstance,
  366. LPMMTIME lpmmt,
  367. DWORD cbmmt);
  368. extern DWORD FNGLOBAL modSetVolume( // modmsg.c
  369. DWORD dwVolume);
  370. extern void FNGLOBAL QueueInit( // queue.c
  371. PQUEUE pq);
  372. extern void FNGLOBAL QueueCleanup( // queue.c
  373. PQUEUE pq);
  374. extern void FNGLOBAL QueuePut( // queue.c
  375. PQUEUE pq,
  376. PQUEUEELE pqe,
  377. UINT uPriority);
  378. extern PQUEUEELE FNGLOBAL QueueGet( // queue.c
  379. PQUEUE pq);
  380. extern BOOL FNGLOBAL QueueRemove( // queue.c
  381. PQUEUE pq,
  382. PQUEUEELE pqe);
  383. typedef BOOL (FNGLOBAL *FNFILTER)(PQUEUEELE);
  384. extern PQUEUEELE FNGLOBAL QueueGetFilter( // queue.c
  385. PQUEUE pq,
  386. FNFILTER fnf);
  387. extern void FNGLOBAL LockMapperData( // locks.c
  388. void);
  389. extern void FNGLOBAL UnlockMapperData( // locks.c
  390. void);
  391. extern void FNGLOBAL LockPackedMapper( // locks.c
  392. void);
  393. extern void FNGLOBAL UnlockPackedMapper( // locks.c
  394. void);
  395. extern void FNGLOBAL LockCookedMapper( // locks.c
  396. void);
  397. extern void FNGLOBAL UnlockCookedMapper( // locks.c
  398. void);
  399. extern void FNGLOBAL mdev_Free( // mididev.c
  400. void);
  401. extern BOOL FNGLOBAL mdev_Init( // mididev.c
  402. void);
  403. UINT FNGLOBAL mdev_GetDeviceID( // mididev.c
  404. LPTSTR pszAlias);
  405. BOOL FNGLOBAL mdev_GetAlias( // mididev.c
  406. UINT uDeviceID,
  407. LPTSTR pszBuffer,
  408. UINT cchSize);
  409. BOOL FNGLOBAL mdev_NewDrivers( // mididev.c
  410. void);
  411. // Translation buffer stuff for MODM_LONGDATA
  412. BOOL FNGLOBAL InitTransBuffer (PINSTANCE pinstance);
  413. BOOL FNGLOBAL CleanupTransBuffer (PINSTANCE pinstance);
  414. LPBYTE FNGLOBAL AccessTransBuffer (PINSTANCE pinstance);
  415. void FNGLOBAL ReleaseTransBuffer (PINSTANCE pinstance);
  416. BOOL FNGLOBAL GrowTransBuffer (PINSTANCE pinstance, DWORD cbNewSize);
  417. #endif