]> icculus.org git repositories - taylor/freespace2.git/blob - include/midiseq.h
added copyright header
[taylor/freespace2.git] / include / midiseq.h
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell 
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/Sound/midiseq.h $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * Header file with MIDI parsing constants and data structures
16  *
17  * $Log$
18  * Revision 1.2  2002/06/09 04:41:13  relnev
19  * added copyright header
20  *
21  * Revision 1.1.1.1  2002/05/03 03:28:12  root
22  * Initial import.
23  *
24  * 
25  * 2     10/07/98 10:54a Dave
26  * Initial checkin.
27  * 
28  * 1     10/07/98 10:51a Dave
29  * 
30  * 1     4/28/97 4:45p John
31  * Initial version of ripping sound & movie out of OsAPI.
32  * 
33  * 4     2/10/97 9:26a Lawrance
34  * 
35  * 3     1/31/97 2:40p Lawrance
36  * MIDI playback working
37  *
38  * $NoKeywords: $
39  */
40
41 #ifndef __MIDIBASE_H__
42 #define __MIDIBASE_H__
43
44
45 // MIDI file constants
46 //
47
48 #define MThd        0x6468544D      // Start of file
49 #define MTrk        0x6B72544D      // Start of track
50
51 #define MIDI_SYSEX              ((BYTE)0xF0)        // SysEx begin
52 #define MIDI_SYSEXEND   ((BYTE)0xF7)        // SysEx begin
53 #define MIDI_META                       ((BYTE)0xFF)        // Meta event begin
54 #define MIDI_META_TEMPO ((BYTE)0x51)        // Tempo change
55 #define MIDI_META_EOT   ((BYTE)0x2F)        // End-of-track
56
57 #define MIDI_NOTEOFF    ((BYTE)0x80)        // + note + velocity
58 #define MIDI_NOTEON             ((BYTE)0x90)        // + note + velocity
59 #define MIDI_POLYPRESS  ((BYTE)0xA0)        // + pressure (2 bytes)
60 #define MIDI_CTRLCHANGE ((BYTE)0xB0)        // + ctrlr + value
61 #define MIDI_PRGMCHANGE ((BYTE)0xC0)        // + new patch
62 #define MIDI_CHANPRESS  ((BYTE)0xD0)        // + pressure (1 byte)
63 #define MIDI_PITCHBEND  ((BYTE)0xE0)        // + pitch bend (2 bytes)
64
65 #define MIDI_META_MARKER                ((BYTE)0x06)        // Marker META event
66 #define NUM_CHANNELS    16
67
68 #define MIDICTRL_VOLUME     ((BYTE)0x07)
69 #define MIDICTRL_VOLUME_LSB ((BYTE)0x27)
70 #define MIDICTRL_PAN        ((BYTE)0x0A)
71
72 #define MIDIEVENT_CHANNEL(dw)           (dw & 0x0000000F)
73 #define MIDIEVENT_TYPE(dw)                      (dw & 0x000000F0)
74 #define MIDIEVENT_DATA1(dw)             ((dw & 0x0000FF00) >> 8)
75 #define MIDIEVENT_VOLUME(dw)            ((dw & 0x007F0000) >> 16)
76
77 // Macros for swapping hi/lo-endian data
78 //
79 #define WORDSWAP(w) (((w) >> 8) | \
80             (((w) << 8) & 0xFF00))
81
82 #define DWORDSWAP(dw)   (((dw) >> 24) |         \
83             (((dw) >> 8) & 0x0000FF00) |    \
84             (((dw) << 8) & 0x00FF0000) |    \
85             (((dw) << 24) & 0xFF000000))
86
87 // Make a little distinction here so the various structure members are a bit
88 // more clearly labelled -- we have offsets and byte counts to keep track of
89 // that deal with both in-memory buffers and the file on disk
90
91 #define FILEOFF DWORD
92             
93 // These structures are stored in MIDI files; they need to be byte aligned.
94 //
95 #pragma pack(1)
96
97 // Chunk header. dwTag is either MTrk or MThd.
98 //
99 typedef struct
100 {
101     DWORD   dwTag;                           // Type
102     DWORD   dwChunkLength;      // Length (hi-lo)
103 } MIDICHUNK;
104
105 // Contents of MThd chunk.
106 typedef struct
107 {
108     WORD    wFormat;                                    // Format (hi-lo)
109     WORD    wTrackCount;                        // # tracks (hi-lo)
110     WORD    wTimeDivision;                      // Time division (hi-lo)
111 } MIDIFILEHDR;
112
113 #pragma pack() // End of need for byte-aligned structures
114
115
116 // Temporary event structure which stores event data until we're ready to
117 // dump it into a stream buffer
118 //
119 typedef struct
120 {
121     DWORD   tkEvent;                            // Absolute time of event
122     BYTE    byShortData[4];     // Event type and parameters if channel msg
123     DWORD   dwEventLength;              // Length of data which follows if meta or sysex
124     LPBYTE  pLongData;                  // -> Event data if applicable
125 } TEMPEVENT, *PTEMPEVENT;
126
127 #define ITS_F_ENDOFTRK  0x00000001
128
129 // Description of a track open for read
130 //
131 typedef struct
132 {
133     DWORD   fdwTrack;   // Track status
134     DWORD   dwTrackLength;  // Total bytes in track
135     DWORD   dwLeftInBuffer; // Bytes left unread in track buffer
136     LPBYTE  pTrackStart;    // -> start of track data buffer
137     LPBYTE  pTrackCurrent;  // -> next byte to read in buffer
138     DWORD   tkNextEventDue; // Absolute time of next event in track
139     BYTE    byRunningStatus;// Running status from last channel msg
140
141     FILEOFF foTrackStart;   // Start of track -- used for walking the file
142     FILEOFF foNextReadStart;// File offset of next read from disk
143     DWORD   dwLeftOnDisk;   // Bytes left unread on disk
144
145 //    int       in_song[MAX_SONGS];
146          
147 } INTRACKSTATE, *PINTRACKSTATE;
148
149 // Description of the input MIDI file
150 //
151 typedef struct
152 {
153     DWORD   cbFileLength;       // Total bytes in file
154     DWORD   dwTimeDivision;     // Original time division
155     DWORD   dwFormat;       // Original format
156     DWORD   dwTrackCount;       // Track count (specifies pitsTracks size)
157     INTRACKSTATE *pitsTracks;       // -> array of tracks in this file
158 } INFILESTATE, *PINFILESTATE;
159
160 #endif /* __MIDIBASE_H__ */
161