home *** CD-ROM | disk | FTP | other *** search
/ NEXT Generation 27 / NEXT27.iso / pc / demos / emperor / dx3.exe / SDK / SAMPLES / MSTREAM / MIDSTUFF.H < prev    next >
C/C++ Source or Header  |  1996-08-28  |  5KB  |  139 lines

  1. /*==========================================================================
  2.  *
  3.  *  Copyright (C) 1995-1996 Microsoft Corporation. All Rights Reserved.
  4.  *
  5.  *  File:   midstuff.h
  6.  *  Content:    MIDI structures and definitions used by the MSTREAM sample
  7.  *              application in converting a MID file to a MIDI stream for
  8.  *              playback using the midiStream API.
  9.  *
  10.  ***************************************************************************/
  11. #ifndef __MIDSTUFF_H__
  12. #define __MIDSTUFF_H__
  13.  
  14. // MIDI file constants
  15. //
  16. #define MThd        0x6468544D      // Start of file
  17. #define MTrk        0x6B72544D      // Start of track
  18.  
  19. #define MIDI_SYSEX  ((BYTE)0xF0)        // SysEx begin
  20. #define MIDI_SYSEXEND   ((BYTE)0xF7)        // SysEx begin
  21. #define MIDI_META   ((BYTE)0xFF)        // Meta event begin
  22. #define MIDI_META_TEMPO ((BYTE)0x51)        // Tempo change
  23. #define MIDI_META_EOT   ((BYTE)0x2F)        // End-of-track
  24.  
  25. #define MIDI_NOTEOFF    ((BYTE)0x80)        // + note + velocity
  26. #define MIDI_NOTEON ((BYTE)0x90)        // + note + velocity
  27. #define MIDI_POLYPRESS  ((BYTE)0xA0)        // + pressure (2 bytes)
  28. #define MIDI_CTRLCHANGE ((BYTE)0xB0)        // + ctrlr + value
  29. #define MIDI_PRGMCHANGE ((BYTE)0xC0)        // + new patch
  30. #define MIDI_CHANPRESS  ((BYTE)0xD0)        // + pressure (1 byte)
  31. #define MIDI_PITCHBEND  ((BYTE)0xE0)        // + pitch bend (2 bytes)
  32.  
  33. #define NUM_CHANNELS    16
  34.  
  35. #define MIDICTRL_VOLUME     ((BYTE)0x07)
  36. #define MIDICTRL_VOLUME_LSB ((BYTE)0x27)
  37. #define MIDICTRL_PAN        ((BYTE)0x0A)
  38.  
  39. #define MIDIEVENT_CHANNEL(dw)   (dw & 0x0000000F)
  40. #define MIDIEVENT_TYPE(dw)  (dw & 0x000000F0)
  41. #define MIDIEVENT_DATA1(dw) ((dw & 0x0000FF00) >> 8)
  42. #define MIDIEVENT_VOLUME(dw)    ((dw & 0x007F0000) >> 16)
  43.  
  44. // Macros for swapping hi/lo-endian data
  45. //
  46. #define WORDSWAP(w) (((w) >> 8) | \
  47.             (((w) << 8) & 0xFF00))
  48.  
  49. #define DWORDSWAP(dw)   (((dw) >> 24) |         \
  50.             (((dw) >> 8) & 0x0000FF00) |    \
  51.             (((dw) << 8) & 0x00FF0000) |    \
  52.             (((dw) << 24) & 0xFF000000))
  53.  
  54. // In debug builds, TRACKERR will show us where the parser died
  55. //
  56. #ifdef DEBUG
  57. #define TRACKERR(p,sz) ShowTrackError(p,sz);
  58. #else
  59. #define TRACKERR(p,sz)
  60. #endif
  61.  
  62.  
  63. // Make a little distinction here so the various structure members are a bit
  64. // more clearly labelled -- we have offsets and byte counts to keep track of
  65. // that deal with both in-memory buffers and the file on disk
  66.  
  67. #define FILEOFF DWORD
  68.             
  69.  
  70. // These structures are stored in MIDI files; they need to be byte aligned.
  71. //
  72. #pragma pack(1)
  73.  
  74. // Chunk header. dwTag is either MTrk or MThd.
  75. //
  76. typedef struct
  77. {
  78.     DWORD   dwTag;          // Type
  79.     DWORD   dwChunkLength;      // Length (hi-lo)
  80. } MIDICHUNK;
  81.  
  82. // Contents of MThd chunk.
  83. typedef struct
  84. {
  85.     WORD    wFormat;        // Format (hi-lo)
  86.     WORD    wTrackCount;        // # tracks (hi-lo)
  87.     WORD    wTimeDivision;      // Time division (hi-lo)
  88. } MIDIFILEHDR;
  89.  
  90. #pragma pack() // End of need for byte-aligned structures
  91.  
  92.  
  93. // Temporary event structure which stores event data until we're ready to
  94. // dump it into a stream buffer
  95. //
  96. typedef struct
  97. {
  98.     DWORD   tkEvent;    // Absolute time of event
  99.     BYTE    byShortData[4]; // Event type and parameters if channel msg
  100.     DWORD   dwEventLength;  // Length of data which follows if meta or sysex
  101.     LPBYTE  pLongData;  // -> Event data if applicable
  102. } TEMPEVENT, *PTEMPEVENT;
  103.  
  104. #define ITS_F_ENDOFTRK  0x00000001
  105.  
  106. // Description of a track open for read
  107. //
  108. typedef struct
  109. {
  110.     DWORD   fdwTrack;   // Track status
  111.     DWORD   dwTrackLength;  // Total bytes in track
  112.     DWORD   dwLeftInBuffer; // Bytes left unread in track buffer
  113.     LPBYTE  pTrackStart;    // -> start of track data buffer
  114.     LPBYTE  pTrackCurrent;  // -> next byte to read in buffer
  115.     DWORD   tkNextEventDue; // Absolute time of next event in track
  116.     BYTE    byRunningStatus;// Running status from last channel msg
  117.  
  118.     FILEOFF foTrackStart;   // Start of track -- used for walking the file
  119.     FILEOFF foNextReadStart;// File offset of next read from disk
  120.     DWORD   dwLeftOnDisk;   // Bytes left unread on disk
  121. #ifdef DEBUG
  122.     DWORD   nTrack;     // # of this track for debugging
  123. #endif
  124. } INTRACKSTATE, *PINTRACKSTATE;
  125.  
  126. // Description of the input MIDI file
  127. //
  128. typedef struct
  129. {
  130.     DWORD   cbFileLength;       // Total bytes in file
  131.     DWORD   dwTimeDivision;     // Original time division
  132.     DWORD   dwFormat;       // Original format
  133.     DWORD   dwTrackCount;       // Track count (specifies pitsTracks size)
  134.     INTRACKSTATE *pitsTracks;       // -> array of tracks in this file
  135. } INFILESTATE, *PINFILESTATE;
  136.  
  137. #endif
  138.  
  139.