]> icculus.org git repositories - taylor/freespace2.git/blob - include/midiseq.h
Initial revision
[taylor/freespace2.git] / include / midiseq.h
1 /*
2  * $Logfile: /Freespace2/code/Sound/midiseq.h $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * Header file with MIDI parsing constants and data structures
8  *
9  * $Log$
10  * Revision 1.1  2002/05/03 03:28:12  root
11  * Initial revision
12  *
13  * 
14  * 2     10/07/98 10:54a Dave
15  * Initial checkin.
16  * 
17  * 1     10/07/98 10:51a Dave
18  * 
19  * 1     4/28/97 4:45p John
20  * Initial version of ripping sound & movie out of OsAPI.
21  * 
22  * 4     2/10/97 9:26a Lawrance
23  * 
24  * 3     1/31/97 2:40p Lawrance
25  * MIDI playback working
26  *
27  * $NoKeywords: $
28  */
29
30 #ifndef __MIDIBASE_H__
31 #define __MIDIBASE_H__
32
33
34 // MIDI file constants
35 //
36
37 #define MThd        0x6468544D      // Start of file
38 #define MTrk        0x6B72544D      // Start of track
39
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
45
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)
53
54 #define MIDI_META_MARKER                ((BYTE)0x06)        // Marker META event
55 #define NUM_CHANNELS    16
56
57 #define MIDICTRL_VOLUME     ((BYTE)0x07)
58 #define MIDICTRL_VOLUME_LSB ((BYTE)0x27)
59 #define MIDICTRL_PAN        ((BYTE)0x0A)
60
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)
65
66 // Macros for swapping hi/lo-endian data
67 //
68 #define WORDSWAP(w) (((w) >> 8) | \
69             (((w) << 8) & 0xFF00))
70
71 #define DWORDSWAP(dw)   (((dw) >> 24) |         \
72             (((dw) >> 8) & 0x0000FF00) |    \
73             (((dw) << 8) & 0x00FF0000) |    \
74             (((dw) << 24) & 0xFF000000))
75
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
79
80 #define FILEOFF DWORD
81             
82 // These structures are stored in MIDI files; they need to be byte aligned.
83 //
84 #pragma pack(1)
85
86 // Chunk header. dwTag is either MTrk or MThd.
87 //
88 typedef struct
89 {
90     DWORD   dwTag;                           // Type
91     DWORD   dwChunkLength;      // Length (hi-lo)
92 } MIDICHUNK;
93
94 // Contents of MThd chunk.
95 typedef struct
96 {
97     WORD    wFormat;                                    // Format (hi-lo)
98     WORD    wTrackCount;                        // # tracks (hi-lo)
99     WORD    wTimeDivision;                      // Time division (hi-lo)
100 } MIDIFILEHDR;
101
102 #pragma pack() // End of need for byte-aligned structures
103
104
105 // Temporary event structure which stores event data until we're ready to
106 // dump it into a stream buffer
107 //
108 typedef struct
109 {
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;
115
116 #define ITS_F_ENDOFTRK  0x00000001
117
118 // Description of a track open for read
119 //
120 typedef struct
121 {
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
129
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
133
134 //    int       in_song[MAX_SONGS];
135          
136 } INTRACKSTATE, *PINTRACKSTATE;
137
138 // Description of the input MIDI file
139 //
140 typedef struct
141 {
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;
148
149 #endif /* __MIDIBASE_H__ */
150