]> icculus.org git repositories - btb/d2x.git/blob - unused/win95/midifile.h
This commit was generated by cvs2svn to compensate for changes in r5,
[btb/d2x.git] / unused / win95 / midifile.h
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14
15
16 #ifndef _MIDIFILE_H
17 #define _MIDIFILE_H
18
19 #include "global.h" 
20
21 typedef DWORD SMFRESULT;
22 typedef DWORD TICKS;
23 typedef TICKS FAR *PTICKS;
24 typedef BYTE HUGE *HPBYTE;
25
26 #define MAX_TICKS           ((TICKS)0xFFFFFFFFL)
27
28 #define SMF_SUCCESS         (0L)
29 #define SMF_INVALID_FILE    (1L)
30 #define SMF_NO_MEMORY       (2L)
31 #define SMF_OPEN_FAILED     (3L)
32 #define SMF_INVALID_TRACK   (4L)
33 #define SMF_META_PENDING    (5L)
34 #define SMF_ALREADY_OPEN    (6L)
35 #define SMF_END_OF_TRACK    (7L)
36 #define SMF_NO_META         (8L)
37 #define SMF_INVALID_PARM    (9L)
38 #define SMF_INVALID_BUFFER  (10L)
39 #define SMF_END_OF_FILE     (11L)
40 #define SMF_REACHED_TKMAX   (12L)
41
42 DECLARE_HANDLE(HSMF);
43
44 typedef struct tag_smfopenstruct
45 {
46     LPSTR               pstrName;
47     DWORD               dwTimeDivision;
48     HSMF                hSmf;
49 }   SMFOPENFILESTRUCT,
50     FAR *PSMFOPENFILESTRUCT;
51
52 extern SMFRESULT FNLOCAL smfOpenFile(
53     BYTE *data, UINT length, HSMF *pph);
54
55 extern SMFRESULT FNLOCAL smfCloseFile(
56     HSMF                hsmf);
57
58 typedef struct tag_smffileinfo
59 {
60     DWORD               dwTracks;
61     DWORD               dwFormat;
62     DWORD               dwTimeDivision;
63     TICKS               tkLength;
64 }   SMFFILEINFO,
65     FAR *PSMFFILEINFO;
66
67 extern SMFRESULT FNLOCAL smfGetFileInfo(
68     HSMF                hsmf,
69     PSMFFILEINFO        psfi);
70
71 extern DWORD FNLOCAL smfTicksToMillisecs(
72     HSMF                hsmf,
73     TICKS               tkOffset);
74
75 extern DWORD FNLOCAL smfMillisecsToTicks(
76     HSMF                hsmf,
77     DWORD               msOffset);
78
79 extern SMFRESULT FNLOCAL smfReadEvents(
80     HSMF                hsmf,
81     LPMIDIHDR           lpmh,
82     TICKS               tkMax);
83
84 extern SMFRESULT FNLOCAL smfSeek(
85     HSMF                hsmf,
86     TICKS               tkPosition,
87     LPMIDIHDR           lpmh);
88
89 extern DWORD FNLOCAL smfGetStateMaxSize(
90     void);
91
92 /* Buffer described by LPMIDIHDR is in polymsg format, except that it
93 ** can contain meta-events (which will be ignored during playback by
94 ** the current system). This means we can use the pack functions, etc.
95 */
96 #define PMSG_META       ((BYTE)0xC0)
97
98
99
100
101 /*****************************************************************************/
102 /*****************************************************************************/
103
104
105 /* Handle structure for HSMF
106 */ 
107
108 #define SMF_TF_EOT          0x00000001L
109 #define SMF_TF_INVALID      0x00000002L
110
111 typedef struct tag_tempomapentry
112 {
113     TICKS           tkTempo;           
114     DWORD           msBase;            
115     DWORD           dwTempo;           
116 }   TEMPOMAPENTRY,
117     *PTEMPOMAPENTRY;
118
119 typedef struct tag_smf *PSMF;
120
121 typedef struct tag_track
122 {
123     PSMF            pSmf;
124
125     DWORD           idxTrack;          
126     
127     TICKS           tkPosition;        
128     DWORD           cbLeft;            
129     HPBYTE          hpbImage;          
130     BYTE            bRunningStatus;    
131     
132     DWORD           fdwTrack;          
133
134     struct
135     {
136         TICKS       tkLength;
137         DWORD       cbLength;
138     }
139     smti;                              
140
141 }   TRACK,
142     *PTRACK;
143
144 #define SMF_F_EOF               0x00000001L
145 #define SMF_F_INSERTSYSEX       0x00000002L
146
147 #define C_TEMPO_MAP_CHK     16
148 typedef struct tag_smf
149 {
150     char            szName[128];
151     HPBYTE          hpbImage;
152     DWORD           cbImage;
153     HTASK           htask;
154
155     TICKS           tkPosition;
156     TICKS           tkLength;
157     DWORD           dwFormat;
158     DWORD           dwTracks;
159     DWORD           dwTimeDivision;
160     DWORD           fdwSMF;
161
162     DWORD           cTempoMap;
163     DWORD           cTempoMapAlloc;
164     HLOCAL          hTempoMap;
165     PTEMPOMAPENTRY  pTempoMap;
166
167     DWORD           dwPendingUserEvent;
168     DWORD           cbPendingUserEvent;
169     HPBYTE          hpbPendingUserEvent;
170     
171     TRACK           rTracks[];
172 }   SMF;
173
174 typedef struct tagEVENT
175 {
176     TICKS           tkDelta;           
177     BYTE            abEvent[3];        
178                                        
179                                        
180                                        
181     DWORD           cbParm;            
182     HPBYTE          hpbParm;           
183 }   EVENT,
184     BSTACK *SPEVENT;
185
186 #define EVENT_TYPE(event)       ((event).abEvent[0])
187 #define EVENT_CH_B1(event)      ((event).abEvent[1])
188 #define EVENT_CH_B2(event)      ((event).abEvent[2])
189
190 #define EVENT_META_TYPE(event)  ((event).abEvent[1])
191
192 SMFRESULT FNLOCAL smfBuildFileIndex(
193     PSMF BSTACK *       ppsmf);
194
195 DWORD FNLOCAL smfGetVDword(
196     HPBYTE              hpbImage,
197     DWORD               dwLeft,                                
198     DWORD BSTACK *      pdw);
199
200 SMFRESULT FNLOCAL smfGetNextEvent(
201     PSMF                psmf,
202     SPEVENT             pevent,
203     TICKS               tkMax);
204
205 /*
206 ** Useful macros when dealing with hi-lo format integers
207 */
208 #define DWORDSWAP(dw) \
209     ((((dw)>>24)&0x000000FFL)|\
210     (((dw)>>8)&0x0000FF00L)|\
211     (((dw)<<8)&0x00FF0000L)|\
212     (((dw)<<24)&0xFF000000L))
213
214 #define WORDSWAP(w) \
215     ((((w)>>8)&0x00FF)|\
216     (((w)<<8)&0xFF00))
217
218 #define FOURCC_RMID     mmioFOURCC('R','M','I','D')
219 #define FOURCC_data     mmioFOURCC('d','a','t','a')
220 #define FOURCC_MThd     mmioFOURCC('M','T','h','d')
221 #define FOURCC_MTrk     mmioFOURCC('M','T','r','k')
222
223 typedef struct tag_chunkhdr
224 {
225     FOURCC  fourccType;
226     DWORD   dwLength;
227 }   CHUNKHDR,
228     *PCHUNKHDR;
229
230 #pragma pack(1) // override cl32 default packing, to match disk file.
231 typedef struct tag_filehdr
232 {
233     WORD    wFormat;
234     WORD    wTracks;
235     WORD    wDivision;
236 }   FILEHDR,
237     *PFILEHDR;
238 #pragma pack()
239
240 /* NOTE: This is arbitrary and only used if there is a tempo map but no
241 ** entry at tick 0.
242 */
243 #define MIDI_DEFAULT_TEMPO      (500000L)
244
245 #define MIDI_MSG                ((BYTE)0x80)
246 #define MIDI_NOTEOFF            ((BYTE)0x80)
247 #define MIDI_NOTEON             ((BYTE)0x90)
248 #define MIDI_POLYPRESSURE       ((BYTE)0xA0)
249 #define MIDI_CONTROLCHANGE      ((BYTE)0xB0)
250 #define MIDI_PROGRAMCHANGE      ((BYTE)0xC0)
251 #define MIDI_CHANPRESSURE       ((BYTE)0xD0)
252 #define MIDI_PITCHBEND          ((BYTE)0xE0)
253 #define MIDI_META               ((BYTE)0xFF)
254 #define MIDI_SYSEX              ((BYTE)0xF0)
255 #define MIDI_SYSEXEND           ((BYTE)0xF7)
256
257 #define MIDI_META_TRACKNAME     ((BYTE)0x03)
258 #define MIDI_META_EOT           ((BYTE)0x2F)
259 #define MIDI_META_TEMPO         ((BYTE)0x51)
260 #define MIDI_META_TIMESIG       ((BYTE)0x58)
261 #define MIDI_META_KEYSIG        ((BYTE)0x59)
262 #define MIDI_META_SEQSPECIFIC   ((BYTE)0x7F)
263
264
265
266
267 #endif