Mercurial > hg > forks > bilotrip-mj12
comparison src/midifile.h @ 34:a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 05 Aug 2013 20:51:20 +0300 |
parents | 785057719d9b |
children | 1db62040204e |
comparison
equal
deleted
inserted
replaced
33:de2ee75a142f | 34:a14cc6c5d7ef |
---|---|
1 #ifndef _MIDIFILE_H | 1 #ifndef _MIDIFILE_H |
2 #define _MIDIFILE_H | 2 #define _MIDIFILE_H |
3 | 3 |
4 #include "midiinfo.h" /* enumerations and constants for GM */ | 4 #include "midiinfo.h" /* enumerations and constants for GM */ |
5 #include "mtypes.h" | |
6 | |
5 | 7 |
6 /* | 8 /* |
7 * midiFile.c - Header file for Steevs MIDI Library | 9 * midiFile.c - Header file for Steevs MIDI Library |
8 * Version 1.4 | 10 * Version 1.4 |
9 * | 11 * |
23 * You should have received a copy of the GNU General Public License | 25 * You should have received a copy of the GNU General Public License |
24 * along with this program; if not, write to the Free Software | 26 * along with this program; if not, write to the Free Software |
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
26 */ | 28 */ |
27 | 29 |
28 /* | 30 /* |
29 ** All functions start with one of the following prefixes: | 31 ** All functions start with one of the following prefixes: |
30 ** midiFile* For non-GM features that relate to the file, and have | 32 ** midiFile* For non-GM features that relate to the file, and have |
31 ** no use once the file has been created, i.e. CreateFile | 33 ** no use once the file has been created, i.e. CreateFile |
32 ** or SetTrack (those data is embedded into the file, but | 34 ** or SetTrack (those data is embedded into the file, but |
33 ** not explicitly stored) | 35 ** not explicitly stored) |
34 ** midiSong* For operations that work across the song, i.e. SetTempo | 36 ** midiSong* For operations that work across the song, i.e. SetTempo |
35 ** midiTrack* For operations on a specific track, i.e. AddNoteOn | 37 ** midiTrack* For operations on a specific track, i.e. AddNoteOn |
36 */ | 38 */ |
37 | 39 |
38 /* | 40 /* |
39 ** Types because we're dealing with files, and need to be careful | |
40 */ | |
41 #ifndef XXX | |
42 typedef unsigned char BYTE; | |
43 typedef unsigned short WORD; | |
44 typedef unsigned long DWORD; | |
45 #endif | |
46 | |
47 typedef int BOOL; | |
48 #ifndef TRUE | |
49 #define TRUE 1 | |
50 #endif | |
51 #ifndef FALSE | |
52 #define FALSE 0 | |
53 #endif | |
54 | |
55 | |
56 /* | |
57 ** MIDI Constants | 41 ** MIDI Constants |
58 */ | 42 */ |
59 #define MIDI_PPQN_DEFAULT 384 | 43 #define MIDI_PPQN_DEFAULT 384 |
60 #define MIDI_VERSION_DEFAULT 1 | 44 #define MIDI_VERSION_DEFAULT 1 |
61 | 45 |
66 #define MAX_TRACK_POLYPHONY 64 | 50 #define MAX_TRACK_POLYPHONY 64 |
67 | 51 |
68 /* | 52 /* |
69 ** MIDI structures, accessibly externably | 53 ** MIDI structures, accessibly externably |
70 */ | 54 */ |
71 typedef void MIDI_FILE; | 55 typedef void MIDI_FILE; |
72 typedef struct { | 56 typedef struct |
73 tMIDI_MSG iType; | 57 { |
74 | 58 tMIDI_MSG iType; |
75 DWORD dt; /* delta time */ | 59 |
76 DWORD dwAbsPos; | 60 Uint32 dt; /* delta time */ |
77 DWORD iMsgSize; | 61 Uint32 dwAbsPos; |
78 | 62 Uint32 iMsgSize; |
79 BOOL bImpliedMsg; | 63 |
80 tMIDI_MSG iImpliedMsg; | 64 BOOL bImpliedMsg; |
81 | 65 tMIDI_MSG iImpliedMsg; |
82 /* Raw data chunk */ | 66 |
83 BYTE *data; /* dynamic data block */ | 67 /* Raw data chunk */ |
84 DWORD data_sz; | 68 Uint8 *data; /* dynamic data block */ |
85 | 69 Uint32 data_sz; |
86 union { | 70 |
87 struct { | 71 union |
88 int iNote; | 72 { |
89 int iChannel; | 73 struct |
90 int iVolume; | 74 { |
91 } NoteOn; | 75 int iNote; |
92 struct { | 76 int iChannel; |
93 int iNote; | 77 int iVolume; |
94 int iChannel; | 78 } NoteOn; |
95 } NoteOff; | 79 struct |
96 struct { | 80 { |
97 int iNote; | 81 int iNote; |
98 int iChannel; | 82 int iChannel; |
99 int iPressure; | 83 } NoteOff; |
100 } NoteKeyPressure; | 84 struct |
101 struct { | 85 { |
102 int iChannel; | 86 int iNote; |
103 tMIDI_CC iControl; | 87 int iChannel; |
104 int iParam; | 88 int iPressure; |
105 } NoteParameter; | 89 } NoteKeyPressure; |
106 struct { | 90 struct |
107 int iChannel; | 91 { |
108 int iProgram; | 92 int iChannel; |
109 } ChangeProgram; | 93 tMIDI_CC iControl; |
110 struct { | 94 int iParam; |
111 int iChannel; | 95 } NoteParameter; |
112 int iPressure; | 96 struct |
113 } ChangePressure; | 97 { |
114 struct { | 98 int iChannel; |
115 int iChannel; | 99 int iProgram; |
116 int iPitch; | 100 } ChangeProgram; |
117 } PitchWheel; | 101 struct |
118 struct { | 102 { |
119 tMIDI_META iType; | 103 int iChannel; |
120 union { | 104 int iPressure; |
121 int iMIDIPort; | 105 } ChangePressure; |
122 int iSequenceNumber; | 106 struct |
123 struct { | 107 { |
124 BYTE *pData; | 108 int iChannel; |
125 } Text; | 109 int iPitch; |
126 struct { | 110 } PitchWheel; |
127 int iBPM; | 111 struct |
128 } Tempo; | 112 { |
129 struct { | 113 tMIDI_META iType; |
130 int iHours, iMins; | 114 union |
131 int iSecs, iFrames,iFF; | 115 { |
132 } SMPTE; | 116 int iMIDIPort; |
133 struct { | 117 int iSequenceNumber; |
134 tMIDI_KEYSIG iKey; | 118 struct |
135 } KeySig; | 119 { |
136 struct { | 120 Uint8 *pData; |
137 int iNom, iDenom; | 121 } Text; |
138 } TimeSig; | 122 struct |
139 struct { | 123 { |
140 BYTE *pData; | 124 int iBPM; |
141 int iSize; | 125 } Tempo; |
142 } Sequencer; | 126 struct |
143 } Data; | 127 { |
144 } MetaEvent; | 128 int iHours, iMins; |
145 struct { | 129 int iSecs, iFrames, iFF; |
146 BYTE *pData; | 130 } SMPTE; |
147 int iSize; | 131 struct |
148 } SysEx; | 132 { |
149 } MsgData; | 133 tMIDI_KEYSIG iKey; |
150 | 134 } KeySig; |
151 /* State information - Please treat these as private*/ | 135 struct |
152 tMIDI_MSG iLastMsgType; | 136 { |
153 BYTE iLastMsgChnl; | 137 int iNom, iDenom; |
154 | 138 } TimeSig; |
155 } MIDI_MSG; | 139 struct |
140 { | |
141 Uint8 *pData; | |
142 int iSize; | |
143 } Sequencer; | |
144 } Data; | |
145 } MetaEvent; | |
146 struct | |
147 { | |
148 Uint8 *pData; | |
149 int iSize; | |
150 } SysEx; | |
151 } MsgData; | |
152 | |
153 /* State information - Please treat these as private */ | |
154 tMIDI_MSG iLastMsgType; | |
155 Uint8 iLastMsgChnl; | |
156 | |
157 } MIDI_MSG; | |
158 | |
156 | 159 |
157 /* | 160 /* |
158 ** midiFile* Prototypes | 161 ** midiFile* Prototypes |
159 */ | 162 */ |
160 MIDI_FILE *midiFileCreate(const char *pFilename, BOOL bOverwriteIfExists); | 163 MIDI_FILE *midiFileCreate(const char *pFilename, BOOL bOverwriteIfExists); |
161 int midiFileSetTracksDefaultChannel(MIDI_FILE *pMF, int iTrack, int iChannel); | 164 int midiFileSetTracksDefaultChannel(MIDI_FILE *pMF, int iTrack, |
162 int midiFileGetTracksDefaultChannel(const MIDI_FILE *pMF, int iTrack); | 165 int iChannel); |
163 BOOL midiFileFlushTrack(MIDI_FILE *pMF, int iTrack, BOOL bFlushToEnd, DWORD dwEndTimePos); | 166 int midiFileGetTracksDefaultChannel(const MIDI_FILE *pMF, int iTrack); |
164 BOOL midiFileSyncTracks(MIDI_FILE *pMF, int iTrack1, int iTrack2); | 167 BOOL midiFileFlushTrack(MIDI_FILE *pMF, int iTrack, BOOL bFlushToEnd, |
165 int midiFileSetPPQN(MIDI_FILE *pMF, int PPQN); | 168 Uint32 dwEndTimePos); |
166 int midiFileGetPPQN(const MIDI_FILE *pMF); | 169 BOOL midiFileSyncTracks(MIDI_FILE *pMF, int iTrack1, int iTrack2); |
167 int midiFileSetVersion(MIDI_FILE *pMF, int iVersion); | 170 int midiFileSetPPQN(MIDI_FILE *pMF, int PPQN); |
168 int midiFileGetVersion(const MIDI_FILE *pMF); | 171 int midiFileGetPPQN(const MIDI_FILE *pMF); |
169 MIDI_FILE *midiFileOpen(const char *pFilename); | 172 int midiFileSetVersion(MIDI_FILE *pMF, int iVersion); |
170 BOOL midiFileClose(MIDI_FILE *pMF); | 173 int midiFileGetVersion(const MIDI_FILE *pMF); |
174 MIDI_FILE *midiFileOpen(const char *pFilename); | |
175 BOOL midiFileClose(MIDI_FILE *pMF); | |
171 | 176 |
172 /* | 177 /* |
173 ** midiSong* Prototypes | 178 ** midiSong* Prototypes |
174 */ | 179 */ |
175 BOOL midiSongAddSMPTEOffset(MIDI_FILE *pMF, int iTrack, int iHours, int iMins, int iSecs, int iFrames, int iFFrames); | 180 BOOL midiSongAddSMPTEOffset(MIDI_FILE *pMF, int iTrack, int iHours, |
176 BOOL midiSongAddSimpleTimeSig(MIDI_FILE *pMF, int iTrack, int iNom, int iDenom); | 181 int iMins, int iSecs, int iFrames, int iFFrames); |
177 BOOL midiSongAddTimeSig(MIDI_FILE *pMF, int iTrack, int iNom, int iDenom, int iClockInMetroTick, int iNotated32nds); | 182 BOOL midiSongAddSimpleTimeSig(MIDI_FILE *pMF, int iTrack, int iNom, |
178 BOOL midiSongAddKeySig(MIDI_FILE *pMF, int iTrack, tMIDI_KEYSIG iKey); | 183 int iDenom); |
179 BOOL midiSongAddTempo(MIDI_FILE *pMF, int iTrack, int iTempo); | 184 BOOL midiSongAddTimeSig(MIDI_FILE *pMF, int iTrack, int iNom, int iDenom, |
180 BOOL midiSongAddMIDIPort(MIDI_FILE *pMF, int iTrack, int iPort); | 185 int iClockInMetroTick, int iNotated32nds); |
181 BOOL midiSongAddEndSequence(MIDI_FILE *pMF, int iTrack); | 186 BOOL midiSongAddKeySig(MIDI_FILE *pMF, int iTrack, tMIDI_KEYSIG iKey); |
187 BOOL midiSongAddTempo(MIDI_FILE *pMF, int iTrack, int iTempo); | |
188 BOOL midiSongAddMIDIPort(MIDI_FILE *pMF, int iTrack, int iPort); | |
189 BOOL midiSongAddEndSequence(MIDI_FILE *pMF, int iTrack); | |
182 | 190 |
183 /* | 191 /* |
184 ** midiTrack* Prototypes | 192 ** midiTrack* Prototypes |
185 */ | 193 */ |
186 BOOL midiTrackAddRaw(MIDI_FILE *pMF, int iTrack, int iDataSize, const BYTE *pData, BOOL bMovePtr, int iDeltaTime); | 194 BOOL midiTrackAddRaw(MIDI_FILE *pMF, int iTrack, int iDataSize, |
187 BOOL midiTrackIncTime(MIDI_FILE *pMF, int iTrack, int iDeltaTime, BOOL bOverridePPQN); | 195 const Uint8 * pData, BOOL bMovePtr, int iDeltaTime); |
188 BOOL midiTrackAddText(MIDI_FILE *pMF, int iTrack, tMIDI_TEXT iType, const char *pTxt); | 196 BOOL midiTrackIncTime(MIDI_FILE *pMF, int iTrack, int iDeltaTime, |
189 BOOL midiTrackAddMsg(MIDI_FILE *pMF, int iTrack, tMIDI_MSG iMsg, int iParam1, int iParam2); | 197 BOOL bOverridePPQN); |
190 BOOL midiTrackSetKeyPressure(MIDI_FILE *pMF, int iTrack, int iNote, int iAftertouch); | 198 BOOL midiTrackAddText(MIDI_FILE *pMF, int iTrack, tMIDI_TEXT iType, |
191 BOOL midiTrackAddControlChange(MIDI_FILE *pMF, int iTrack, tMIDI_CC iCCType, int iParam); | 199 const char *pTxt); |
192 BOOL midiTrackAddProgramChange(MIDI_FILE *pMF, int iTrack, int iInstrPatch); | 200 BOOL midiTrackAddMsg(MIDI_FILE *pMF, int iTrack, tMIDI_MSG iMsg, int iParam1, |
193 BOOL midiTrackChangeKeyPressure(MIDI_FILE *pMF, int iTrack, int iDeltaPressure); | 201 int iParam2); |
194 BOOL midiTrackSetPitchWheel(MIDI_FILE *pMF, int iTrack, int iWheelPos); | 202 BOOL midiTrackSetKeyPressure(MIDI_FILE *pMF, int iTrack, int iNote, |
195 BOOL midiTrackAddNote(MIDI_FILE *pMF, int iTrack, int iNote, int iLength, int iVol, BOOL bAutoInc, BOOL bOverrideLength); | 203 int iAftertouch); |
196 BOOL midiTrackAddRest(MIDI_FILE *pMF, int iTrack, int iLength, BOOL bOverridePPQN); | 204 BOOL midiTrackAddControlChange(MIDI_FILE *pMF, int iTrack, tMIDI_CC iCCType, |
197 BOOL midiTrackGetEndPos(MIDI_FILE *pMF, int iTrack); | 205 int iParam); |
206 BOOL midiTrackAddProgramChange(MIDI_FILE *pMF, int iTrack, int iInstrPatch); | |
207 BOOL midiTrackChangeKeyPressure(MIDI_FILE *pMF, int iTrack, | |
208 int iDeltaPressure); | |
209 BOOL midiTrackSetPitchWheel(MIDI_FILE *pMF, int iTrack, int iWheelPos); | |
210 BOOL midiTrackAddNote(MIDI_FILE *pMF, int iTrack, int iNote, int iLength, | |
211 int iVol, BOOL bAutoInc, BOOL bOverrideLength); | |
212 BOOL midiTrackAddRest(MIDI_FILE *pMF, int iTrack, int iLength, | |
213 BOOL bOverridePPQN); | |
214 BOOL midiTrackGetEndPos(MIDI_FILE *pMF, int iTrack); | |
198 | 215 |
199 /* | 216 /* |
200 ** midiRead* Prototypes | 217 ** midiRead* Prototypes |
201 */ | 218 */ |
202 int midiReadGetNumTracks(const MIDI_FILE *pMF); | 219 int midiReadGetNumTracks(const MIDI_FILE *pMF); |
203 BOOL midiReadGetNextMessage(const MIDI_FILE *pMF, int iTrack, MIDI_MSG *pMsg); | 220 BOOL midiReadGetNextMessage(const MIDI_FILE *pMF, int iTrack, |
204 void midiReadInitMessage(MIDI_MSG *pMsg); | 221 MIDI_MSG * pMsg); |
205 void midiReadFreeMessage(MIDI_MSG *pMsg); | 222 void midiReadInitMessage(MIDI_MSG * pMsg); |
223 void midiReadFreeMessage(MIDI_MSG * pMsg); | |
206 | 224 |
207 | 225 |
208 #endif /* _MIDIFILE_H */ | 226 #endif /* _MIDIFILE_H */ |
209 |