2 * $Logfile: /Freespace2/code/Sound/midiseq.h $
7 * Header file with MIDI parsing constants and data structures
10 * Revision 1.1 2002/05/03 03:28:12 root
14 * 2 10/07/98 10:54a Dave
17 * 1 10/07/98 10:51a Dave
19 * 1 4/28/97 4:45p John
20 * Initial version of ripping sound & movie out of OsAPI.
22 * 4 2/10/97 9:26a Lawrance
24 * 3 1/31/97 2:40p Lawrance
25 * MIDI playback working
30 #ifndef __MIDIBASE_H__
31 #define __MIDIBASE_H__
34 // MIDI file constants
37 #define MThd 0x6468544D // Start of file
38 #define MTrk 0x6B72544D // Start of track
40 #define MIDI_SYSEX ((BYTE)0xF0) // SysEx begin
41 #define MIDI_SYSEXEND ((BYTE)0xF7) // SysEx begin
42 #define MIDI_META ((BYTE)0xFF) // Meta event begin
43 #define MIDI_META_TEMPO ((BYTE)0x51) // Tempo change
44 #define MIDI_META_EOT ((BYTE)0x2F) // End-of-track
46 #define MIDI_NOTEOFF ((BYTE)0x80) // + note + velocity
47 #define MIDI_NOTEON ((BYTE)0x90) // + note + velocity
48 #define MIDI_POLYPRESS ((BYTE)0xA0) // + pressure (2 bytes)
49 #define MIDI_CTRLCHANGE ((BYTE)0xB0) // + ctrlr + value
50 #define MIDI_PRGMCHANGE ((BYTE)0xC0) // + new patch
51 #define MIDI_CHANPRESS ((BYTE)0xD0) // + pressure (1 byte)
52 #define MIDI_PITCHBEND ((BYTE)0xE0) // + pitch bend (2 bytes)
54 #define MIDI_META_MARKER ((BYTE)0x06) // Marker META event
55 #define NUM_CHANNELS 16
57 #define MIDICTRL_VOLUME ((BYTE)0x07)
58 #define MIDICTRL_VOLUME_LSB ((BYTE)0x27)
59 #define MIDICTRL_PAN ((BYTE)0x0A)
61 #define MIDIEVENT_CHANNEL(dw) (dw & 0x0000000F)
62 #define MIDIEVENT_TYPE(dw) (dw & 0x000000F0)
63 #define MIDIEVENT_DATA1(dw) ((dw & 0x0000FF00) >> 8)
64 #define MIDIEVENT_VOLUME(dw) ((dw & 0x007F0000) >> 16)
66 // Macros for swapping hi/lo-endian data
68 #define WORDSWAP(w) (((w) >> 8) | \
69 (((w) << 8) & 0xFF00))
71 #define DWORDSWAP(dw) (((dw) >> 24) | \
72 (((dw) >> 8) & 0x0000FF00) | \
73 (((dw) << 8) & 0x00FF0000) | \
74 (((dw) << 24) & 0xFF000000))
76 // Make a little distinction here so the various structure members are a bit
77 // more clearly labelled -- we have offsets and byte counts to keep track of
78 // that deal with both in-memory buffers and the file on disk
82 // These structures are stored in MIDI files; they need to be byte aligned.
86 // Chunk header. dwTag is either MTrk or MThd.
91 DWORD dwChunkLength; // Length (hi-lo)
94 // Contents of MThd chunk.
97 WORD wFormat; // Format (hi-lo)
98 WORD wTrackCount; // # tracks (hi-lo)
99 WORD wTimeDivision; // Time division (hi-lo)
102 #pragma pack() // End of need for byte-aligned structures
105 // Temporary event structure which stores event data until we're ready to
106 // dump it into a stream buffer
110 DWORD tkEvent; // Absolute time of event
111 BYTE byShortData[4]; // Event type and parameters if channel msg
112 DWORD dwEventLength; // Length of data which follows if meta or sysex
113 LPBYTE pLongData; // -> Event data if applicable
114 } TEMPEVENT, *PTEMPEVENT;
116 #define ITS_F_ENDOFTRK 0x00000001
118 // Description of a track open for read
122 DWORD fdwTrack; // Track status
123 DWORD dwTrackLength; // Total bytes in track
124 DWORD dwLeftInBuffer; // Bytes left unread in track buffer
125 LPBYTE pTrackStart; // -> start of track data buffer
126 LPBYTE pTrackCurrent; // -> next byte to read in buffer
127 DWORD tkNextEventDue; // Absolute time of next event in track
128 BYTE byRunningStatus;// Running status from last channel msg
130 FILEOFF foTrackStart; // Start of track -- used for walking the file
131 FILEOFF foNextReadStart;// File offset of next read from disk
132 DWORD dwLeftOnDisk; // Bytes left unread on disk
134 // int in_song[MAX_SONGS];
136 } INTRACKSTATE, *PINTRACKSTATE;
138 // Description of the input MIDI file
142 DWORD cbFileLength; // Total bytes in file
143 DWORD dwTimeDivision; // Original time division
144 DWORD dwFormat; // Original format
145 DWORD dwTrackCount; // Track count (specifies pitsTracks size)
146 INTRACKSTATE *pitsTracks; // -> array of tracks in this file
147 } INFILESTATE, *PINFILESTATE;
149 #endif /* __MIDIBASE_H__ */