2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
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
10 * $Logfile: /Freespace2/code/Sound/midiseq.h $
15 * Header file with MIDI parsing constants and data structures
18 * Revision 1.2 2002/06/09 04:41:13 relnev
19 * added copyright header
21 * Revision 1.1.1.1 2002/05/03 03:28:12 root
25 * 2 10/07/98 10:54a Dave
28 * 1 10/07/98 10:51a Dave
30 * 1 4/28/97 4:45p John
31 * Initial version of ripping sound & movie out of OsAPI.
33 * 4 2/10/97 9:26a Lawrance
35 * 3 1/31/97 2:40p Lawrance
36 * MIDI playback working
41 #ifndef __MIDIBASE_H__
42 #define __MIDIBASE_H__
45 // MIDI file constants
48 #define MThd 0x6468544D // Start of file
49 #define MTrk 0x6B72544D // Start of track
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
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)
65 #define MIDI_META_MARKER ((BYTE)0x06) // Marker META event
66 #define NUM_CHANNELS 16
68 #define MIDICTRL_VOLUME ((BYTE)0x07)
69 #define MIDICTRL_VOLUME_LSB ((BYTE)0x27)
70 #define MIDICTRL_PAN ((BYTE)0x0A)
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)
77 // Macros for swapping hi/lo-endian data
79 #define WORDSWAP(w) (((w) >> 8) | \
80 (((w) << 8) & 0xFF00))
82 #define DWORDSWAP(dw) (((dw) >> 24) | \
83 (((dw) >> 8) & 0x0000FF00) | \
84 (((dw) << 8) & 0x00FF0000) | \
85 (((dw) << 24) & 0xFF000000))
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
93 // These structures are stored in MIDI files; they need to be byte aligned.
97 // Chunk header. dwTag is either MTrk or MThd.
102 DWORD dwChunkLength; // Length (hi-lo)
105 // Contents of MThd chunk.
108 WORD wFormat; // Format (hi-lo)
109 WORD wTrackCount; // # tracks (hi-lo)
110 WORD wTimeDivision; // Time division (hi-lo)
113 #pragma pack() // End of need for byte-aligned structures
116 // Temporary event structure which stores event data until we're ready to
117 // dump it into a stream buffer
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;
127 #define ITS_F_ENDOFTRK 0x00000001
129 // Description of a track open for read
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
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
145 // int in_song[MAX_SONGS];
147 } INTRACKSTATE, *PINTRACKSTATE;
149 // Description of the input MIDI file
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;
160 #endif /* __MIDIBASE_H__ */