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.

369 lines
13 KiB

  1. /*******************************Module*Header*********************************
  2. * Module Name: mmseqi.h
  3. *
  4. * MultiMedia Systems MIDI Sequencer DLL Internal prototypes and data struct's
  5. *
  6. * Created: 4/10/90
  7. * Author: GREGSI
  8. *
  9. * History:
  10. *
  11. * Copyright (c) 1985-1998 Microsoft Corporation
  12. *
  13. \****************************************************************************/
  14. /*****************************************************************************
  15. *
  16. * Constants
  17. *
  18. ****************************************************************************/
  19. //#define SEQDEBUG 1
  20. // max. tracks allowed in a sequence
  21. #define MAXTRACKS 100
  22. // MIDI real time data:
  23. #define SysExCode 257
  24. #define MetaEventCode 258
  25. #define METAEVENT 0XFF
  26. #define SYSEX 0XF0
  27. #define SYSEXF7 0XF7
  28. #define PROGRAMCHANGE 0xC0
  29. // packet codes: these are flags
  30. #define LASTPACKET 0X1
  31. #define FIRSTPACKET 0X2
  32. // META EVENT TYPES
  33. #define ENDOFTRACK 0X2F
  34. #define TEMPOCHANGE 0X51
  35. #define SMPTEOFFSET 0X54
  36. #define TIMESIG 0X58
  37. #define SEQSTAMP 0X7F
  38. // PORT TYPES
  39. #define TRACKPORT 0
  40. #define OUTPORT 1
  41. #define CONTROLPORT 2
  42. #define METAPORT 3
  43. /* fileStatus codes */
  44. #define NoErr 256
  45. #define EndOfStream 257
  46. #define AllTracksEmpty 258
  47. #define OnlyBlockedTracks 259
  48. #define AtLimit 260
  49. #define InSysEx 261
  50. /* Blocking types */
  51. #define not_blocked 0
  52. // these imply that you're blocked on input (waiting for free input buffer)
  53. #define between_msg_out 270
  54. #define in_rewind_1 271
  55. #define in_rewind_2 272
  56. #define in_ScanEarlyMetas 273
  57. #define in_Normal_Meta 274
  58. #define in_SysEx 275
  59. #define in_Seek_Tick 276
  60. #define in_Seek_Meta 277
  61. #define in_SkipBytes_Seek 278
  62. #define in_SkipBytes_ScanEM 279
  63. #define in_SkipBytes_Play 280
  64. /* Generic types -- used temporarily at a low level */
  65. #define on_input 350
  66. // End of blocking types.
  67. #define NAMELENGTH 32
  68. /*
  69. codes to pass to SendAllEventB4 (called in normal course of playing, and
  70. by song pointer code for chase-lock)
  71. */
  72. #define MODE_SEEK_TICKS 1
  73. #define MODE_PLAYING 2
  74. #define MODE_SILENT 3
  75. #define MODE_SCANEM 4
  76. // Code to hold in seq->SeekTickToBe when there is no seek pending
  77. #define NotInUse ((DWORD)-1L)
  78. /* delta-time escapes ("legal" deltas only use 28 bits) */
  79. #define MAXDelta 0X8FFFFFFF
  80. #define TrackEmpty 0X8FFFFFFE
  81. #define MHDR_LASTBUFF 2
  82. extern UINT MINPERIOD;
  83. typedef int FileStatus; // this not thoroughly defined
  84. /*****************************************************************************
  85. *
  86. * Data Stuctures & Typedefs
  87. *
  88. ****************************************************************************/
  89. /* USED FOR BYTE MANIPULATION OF MIDI DWORDS */
  90. typedef struct fbm // 32 bit -- passed in lparam
  91. {
  92. BYTE status; // (order may change for optimization)
  93. BYTE byte2;
  94. BYTE byte3;
  95. BYTE time;
  96. } FourByteMIDI;
  97. typedef union
  98. {
  99. DWORD wordMsg;
  100. FourByteMIDI byteMsg;
  101. } ShortMIDI;
  102. /* USED TO HOLD LONG MIDI (SYSEX) INFORMATION */
  103. // size of data buffer
  104. #define LONGBUFFSIZE 0x100
  105. // number of buffers in array (held in seq struct)
  106. #define NUMSYSEXHDRS 2
  107. #define pSEQ(h) ((NPSEQ)(h))
  108. #define hSEQ(p) ((HMIDISEQ)(p))
  109. typedef struct lm // ptr to this passed in lparam
  110. {
  111. MIDIHDR midihdr; // embedded midihdr struct
  112. BYTE data[LONGBUFFSIZE];
  113. } LongMIDI;
  114. typedef LongMIDI NEAR * NPLONGMIDI;
  115. /* USED FOR KEEPING TRACK OF CERTAIN EVENTS (META/KEY/PATCH) */
  116. typedef struct // bit vector of booleans
  117. {
  118. WORD filter[8]; // yields 128 booleans
  119. } BitVector128;
  120. /* DATA STRUCTURES TO HOLD CONTENTS OF META EVENT READ IN */
  121. typedef struct
  122. {
  123. BYTE hour;
  124. BYTE minute;
  125. BYTE second;
  126. BYTE frame;
  127. BYTE fractionalFrame;
  128. } SMPTEType;
  129. typedef struct
  130. {
  131. int numerator;
  132. int denominator;
  133. int midiClocksMetro;
  134. int thirtySecondQuarter;
  135. } TimeSigType;
  136. /* TEMPO MAP ELEMENT (for list of tempo changes to facilitate ms <-> beat
  137. conversion) */
  138. typedef struct tag_TempoMapElement
  139. {
  140. DWORD dwMs;
  141. DWORD dwTicks;
  142. DWORD dwTempo;
  143. } TempoMapElement;
  144. typedef TempoMapElement *NPTEMPOMAPELEMENT;
  145. typedef struct t1
  146. {
  147. LPBYTE currentPtr; //points at current byte in stream
  148. LPBYTE endPtr; //points at last byte in buffer
  149. LPBYTE previousPtr; //points at beginning of previous message
  150. LPMIDISEQHDR hdrList; // list of track data headers
  151. } TLevel1;
  152. /* SEQUENCE TRACK DATA STRUCTURE */
  153. typedef struct trk
  154. {
  155. int blockedOn; // how blocked, if at all?
  156. LONG delta; // time in ticks 'till next event fired
  157. DWORD length; // length of this track in ticks
  158. BYTE lastStatus; // used for running status
  159. ShortMIDI shortMIDIData; // staging area for next event
  160. LONG sysExRemLength; // remaining length when sysex pending
  161. TLevel1 inPort; // low level data pertaining to file
  162. BOOL endOfTrack; // whether track is at end of its data
  163. int iTrackNum; // track number (0-based)
  164. DWORD_PTR dwCallback; // address of callback routine in mciseq
  165. // used to return buffer to it (so it
  166. // can be refilled and received again)
  167. DWORD_PTR dwInstance; // mciseq's private instance information
  168. // (usually contains file handle...)
  169. DWORD dwBytesLeftToSkip;
  170. } TRACK;
  171. typedef TRACK NEAR *NPTRACK;
  172. typedef struct trackarray_tag
  173. {
  174. NPTRACK trkArr[];
  175. } TRACKARRAY;
  176. typedef TRACKARRAY NEAR * NPTRACKARRAY;
  177. // fwFlags:
  178. #define LEGALFILE 0x0001 // Is a legal MIDI file
  179. #define GENERALMSMIDI 0x0002 // Is an MS General MIDI file
  180. typedef struct seq_tag
  181. {
  182. int divType; // PPQN, SMPTE24, SMPTE25, SMPTE30,
  183. // or SMPTE30Drop
  184. int resolution; // if SMPTE, ticks/frame, if MIDI,
  185. // ticks/q-note
  186. BOOL playing; // whether sequence playing or not
  187. DWORD playTo; // what tick to play to, if not end
  188. // (used for mci_play_to command)
  189. DWORD length; // length of sequence in ticks
  190. BOOL readyToPlay; // whether sequence is set up to play
  191. DWORD currentTick; // where we are rel. to beginning of song
  192. DWORD nextExactTime; // system time (ms) that next event
  193. // *should* occur at
  194. BOOL withinMsgOut; // true iff in middle of sending a message
  195. DWORD seekTicks; // temp for seektick or song ptr operation
  196. DWORD tempo; // tempo of sequence in ticks per Usec.
  197. MMTIME smpteOffset; // absolute smpte time of start of seq.
  198. // from meta event, or user)
  199. TimeSigType timeSignature; // current time signature of piece (can
  200. // change)
  201. ListHandle trackList; // track list handle
  202. NPTRACK nextEventTrack; // track that next event resides in
  203. NPTRACK firstTrack; // track holding tempos, smpte offset...
  204. char Name[NAMELENGTH]; // name of the sequence
  205. // sync-related stuff below
  206. DWORD nextSyncEventTick; // global tick at which the next sync
  207. // event is expected
  208. WORD slaveOf; // what you're slave of (mtc, clock,
  209. // file, or nothing)
  210. WORD masterOf; // what you're slave of (mtc, clock,
  211. // or nothing)
  212. BOOL waitingForSync; // tells if currently 'blocked' waiting
  213. // for a sync pulse
  214. // BitVector128 extMetaFilter; // for each meta type, whether to send it.
  215. // (unused for now)
  216. BitVector128 intMetaFilter; // for each meta type, whether it
  217. // affects seq.
  218. DWORD dwTimerParam; // used after timer interrupt to remember
  219. // how many ticks elapsed
  220. UINT wTimerID; // handle to timer (used to cancel
  221. // next interrupt.
  222. HMIDIOUT hMIDIOut; // handle to midi output driver
  223. HANDLE hStream; // handle to stream
  224. UINT wCBMessage; // message type that notify is for
  225. ListHandle tempoMapList; // list of tempo map items for
  226. // ms <-> ppqn conversion.
  227. BOOL bSetPeriod; // whether timer period is currently
  228. // set or not.
  229. PATCHARRAY patchArray; // arrays to keep track of which
  230. // patches used
  231. KEYARRAY drumKeyArray; // array for drum cacheing
  232. BitVector128 keyOnBitVect[16]; // arrays to keep track of which
  233. // patches used
  234. BOOL bSending; // currently in sendevent loop
  235. // (used to prevent reentrancy)
  236. BOOL bTimerEntered; // (used to prevent timer reentrancy)
  237. #ifdef DEBUG
  238. DWORD dwDebug; // debug signature (for detecting bogus
  239. // seq ptr)
  240. #endif
  241. NPTRACKARRAY npTrkArr; // pointer to track array
  242. // (used for routing incoming trk data)
  243. UINT wNumTrks; // number of tracks
  244. LongMIDI longMIDI[NUMSYSEXHDRS + 1]; // list of long midi buffers
  245. BYTE bSysExBlock; // whether blocked waiting for long buff
  246. BYTE bSendingSysEx; // whether in mid sysex out
  247. UINT fwFlags; // various flags
  248. } SEQ;
  249. typedef SEQ NEAR *NPSEQ;
  250. /****************************************************************************
  251. *
  252. * Prototypes
  253. *
  254. ***************************************************************************/
  255. // MMSEQ.C
  256. PRIVATE VOID NEAR PASCAL SeekTicks(NPSEQ npSeq);
  257. PUBLIC UINT NEAR PASCAL GetInfo(NPSEQ npSeq, LPMIDISEQINFO lpInfo);
  258. PUBLIC UINT NEAR PASCAL CreateSequence(LPMIDISEQOPENDESC lpOpen,
  259. LPHMIDISEQ lphMIDISeq);
  260. PUBLIC VOID NEAR PASCAL FillInDelta(NPTRACK npTrack);
  261. PUBLIC UINT NEAR PASCAL Play(NPSEQ npSeq, DWORD dwPlayTo);
  262. PUBLIC VOID NEAR PASCAL Stop(NPSEQ npSeq);
  263. PUBLIC UINT NEAR PASCAL TimerIntRoutine(NPSEQ npSeq, LONG elapsedTick);
  264. PUBLIC VOID NEAR PASCAL SetBlockedTracksTo(NPSEQ npSeq,
  265. int fromState, int toState);
  266. PUBLIC VOID NEAR PASCAL ResetToBeginning(NPSEQ npSeq) ;
  267. PUBLIC BOOL NEAR PASCAL HandleMetaEvent(NPSEQ npSeq, NPTRACK npTrack,
  268. UINT wMode);
  269. PUBLIC BOOL NEAR PASCAL ScanEarlyMetas(NPSEQ npSeq, NPTRACK npTrack,
  270. DWORD dwUntil);
  271. PUBLIC FileStatus NEAR PASCAL SendAllEventsB4(NPSEQ npSeq,
  272. LONG elapsedTick, int mode);
  273. PUBLIC FileStatus NEAR PASCAL GetNextEvent(NPSEQ npSeq);
  274. PUBLIC VOID NEAR PASCAL FillInNextTrack(NPTRACK npTrack);
  275. PUBLIC UINT NEAR PASCAL SendPatchCache(NPSEQ npSeq, BOOL cache);
  276. PUBLIC VOID NEAR PASCAL SendSysEx(NPSEQ npSeq);
  277. PUBLIC VOID NEAR PASCAL SkipBytes(NPTRACK npTrack, LONG length);
  278. // UTIL.C
  279. PUBLIC VOID NEAR PASCAL seqCallback(NPTRACK npTrack, UINT msg,
  280. DWORD_PTR dw1, DWORD_PTR dw2);
  281. PUBLIC BYTE NEAR PASCAL LookByte(NPTRACK npTrack);
  282. PUBLIC BYTE NEAR PASCAL GetByte(NPTRACK npTrack);
  283. PUBLIC VOID NEAR PASCAL MarkLocation(NPTRACK npTrack);
  284. PUBLIC VOID NEAR PASCAL ResetLocation(NPTRACK npTrack);
  285. PUBLIC VOID NEAR PASCAL RewindToStart(NPSEQ npSeq, NPTRACK npTrack);
  286. PUBLIC BOOL NEAR PASCAL AllTracksUnblocked(NPSEQ npSeq);
  287. PUBLIC VOID FAR PASCAL _LOADDS OneShotTimer(UINT wId, UINT msg, DWORD_PTR dwUser,
  288. DWORD_PTR dwTime, DWORD_PTR dw2);
  289. PUBLIC UINT NEAR PASCAL SetTimerCallback(NPSEQ npSeq, UINT msInterval,
  290. DWORD elapsedTicks);
  291. PUBLIC VOID NEAR PASCAL DestroyTimer(NPSEQ npSeq);
  292. PUBLIC VOID NEAR PASCAL SendLongMIDI(NPSEQ npSeq,
  293. LongMIDI FAR *pLongMIDIData);
  294. PUBLIC UINT NEAR PASCAL NewTrackData(NPSEQ npSeq, LPMIDISEQHDR msgHdr);
  295. PUBLIC NPLONGMIDI NEAR PASCAL GetSysExBuffer(NPSEQ npSeq);
  296. // CRIT.ASM
  297. extern FAR PASCAL EnterCrit(void);
  298. extern FAR PASCAL LeaveCrit(void);
  299. // CALLBACK.C
  300. PUBLIC VOID FAR PASCAL _LOADDS MIDICallback(HMIDIOUT hMIDIOut, UINT wMsg,
  301. DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2);
  302. PUBLIC VOID FAR PASCAL NotifyCallback(HANDLE hStream);