-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmidifile.h
207 lines (186 loc) · 6.24 KB
/
midifile.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#ifndef _MIDIFILE_H
#define _MIDIFILE_H
#include <stdint.h>
#include "midiinfo.h" /* enumerations and constants for GM */
/*
* midiFile.c - Header file for Steevs MIDI Library
* Version 1.4
*
* AUTHOR: Steven Goodwin ([email protected])
* Copyright 1998-2010, Steven Goodwin.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License,or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
** All functions start with one of the following prefixes:
** midiFile* For non-GM features that relate to the file, and have
** no use once the file has been created, i.e. CreateFile
** or SetTrack (those data is embedded into the file, but
** not explicitly stored)
** midiSong* For operations that work across the song, i.e. SetTempo
** midiTrack* For operations on a specific track, i.e. AddNoteOn
*/
/*
** Types because we're dealing with files, and need to be careful
*/
typedef unsigned char BYTE;
typedef uint16_t WORD;
typedef uint32_t DWORD;
typedef int BOOL;
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
/*
** MIDI Constants
*/
#define MIDI_PPQN_DEFAULT 384
#define MIDI_VERSION_DEFAULT 1
/*
** MIDI Limits
*/
#define MAX_MIDI_TRACKS 256
#define MAX_TRACK_POLYPHONY 64
/*
** MIDI structures, accessibly externably
*/
typedef void MIDI_FILE;
typedef struct {
tMIDI_MSG iType;
DWORD dt; /* delta time */
DWORD dwAbsPos;
DWORD iMsgSize;
BOOL bImpliedMsg;
tMIDI_MSG iImpliedMsg;
/* Raw data chunk */
BYTE *data; /* dynamic data block */
DWORD data_sz;
union {
struct {
int iNote;
int iChannel;
int iVolume;
} NoteOn;
struct {
int iNote;
int iChannel;
} NoteOff;
struct {
int iNote;
int iChannel;
int iPressure;
} NoteKeyPressure;
struct {
int iChannel;
tMIDI_CC iControl;
int iParam;
} NoteParameter;
struct {
int iChannel;
int iProgram;
} ChangeProgram;
struct {
int iChannel;
int iPressure;
} ChangePressure;
struct {
int iChannel;
int iPitch;
} PitchWheel;
struct {
tMIDI_META iType;
union {
int iMIDIPort;
int iSequenceNumber;
struct {
BYTE *pData;
} Text;
struct {
int iBPM;
} Tempo;
struct {
int iHours, iMins;
int iSecs, iFrames,iFF;
} SMPTE;
struct {
int iKey;
} KeySig;
struct {
int iNom, iDenom;
} TimeSig;
struct {
BYTE *pData;
int iSize;
} Sequencer;
} Data;
} MetaEvent;
struct {
BYTE *pData;
int iSize;
} SysEx;
} MsgData;
/* State information - Please treat these as private*/
tMIDI_MSG iLastMsgType;
BYTE iLastMsgChnl;
} MIDI_MSG;
/*
** midiFile* Prototypes
*/
MIDI_FILE *midiFileCreate(const char *pFilename, BOOL bOverwriteIfExists);
int midiFileSetTracksDefaultChannel(MIDI_FILE *pMF, int iTrack, int iChannel);
int midiFileGetTracksDefaultChannel(const MIDI_FILE *pMF, int iTrack);
BOOL midiFileFlushTrack(MIDI_FILE *pMF, int iTrack, BOOL bFlushToEnd, DWORD dwEndTimePos);
BOOL midiFileSyncTracks(MIDI_FILE *pMF, int iTrack1, int iTrack2);
int midiFileSetPPQN(MIDI_FILE *pMF, int PPQN);
int midiFileGetPPQN(const MIDI_FILE *pMF);
int midiFileSetVersion(MIDI_FILE *pMF, int iVersion);
int midiFileGetVersion(const MIDI_FILE *pMF);
MIDI_FILE *midiFileOpen(const char *pFilename);
BOOL midiFileClose(MIDI_FILE *pMF);
/*
** midiSong* Prototypes
*/
BOOL midiSongAddSMPTEOffset(MIDI_FILE *pMF, int iTrack, int iHours, int iMins, int iSecs, int iFrames, int iFFrames);
BOOL midiSongAddSimpleTimeSig(MIDI_FILE *pMF, int iTrack, int iNom, int iDenom);
BOOL midiSongAddTimeSig(MIDI_FILE *pMF, int iTrack, int iNom, int iDenom, int iClockInMetroTick, int iNotated32nds);
BOOL midiSongAddKeySig(MIDI_FILE *pMF, int iTrack, tMIDI_KEYSIG iKey);
BOOL midiSongAddTempo(MIDI_FILE *pMF, int iTrack, int iTempo);
BOOL midiSongAddMIDIPort(MIDI_FILE *pMF, int iTrack, int iPort);
BOOL midiSongAddEndSequence(MIDI_FILE *pMF, int iTrack);
/*
** midiTrack* Prototypes
*/
BOOL midiTrackAddRaw(MIDI_FILE *pMF, int iTrack, int iDataSize, const BYTE *pData, BOOL bMovePtr, int iDeltaTime);
BOOL midiTrackIncTime(MIDI_FILE *pMF, int iTrack, int iDeltaTime, BOOL bOverridePPQN);
BOOL midiTrackAddText(MIDI_FILE *pMF, int iTrack, tMIDI_TEXT iType, const char *pTxt);
BOOL midiTrackAddMsg(MIDI_FILE *pMF, int iTrack, tMIDI_MSG iMsg, int iParam1, int iParam2);
BOOL midiTrackSetKeyPressure(MIDI_FILE *pMF, int iTrack, int iNote, int iAftertouch);
BOOL midiTrackAddControlChange(MIDI_FILE *pMF, int iTrack, tMIDI_CC iCCType, int iParam);
BOOL midiTrackAddProgramChange(MIDI_FILE *pMF, int iTrack, int iInstrPatch);
BOOL midiTrackChangeKeyPressure(MIDI_FILE *pMF, int iTrack, int iDeltaPressure);
BOOL midiTrackSetPitchWheel(MIDI_FILE *pMF, int iTrack, int iWheelPos);
BOOL midiTrackAddNote(MIDI_FILE *pMF, int iTrack, int iNote, int iLength, int iVol, BOOL bAutoInc, BOOL bOverrideLength);
BOOL midiTrackAddRest(MIDI_FILE *pMF, int iTrack, int iLength, BOOL bOverridePPQN);
BOOL midiTrackGetEndPos(MIDI_FILE *pMF, int iTrack);
/*
** midiRead* Prototypes
*/
int midiReadGetNumTracks(const MIDI_FILE *pMF);
BOOL midiReadGetNextMessage(const MIDI_FILE *pMF, int iTrack, MIDI_MSG *pMsg);
void midiReadInitMessage(MIDI_MSG *pMsg);
void midiReadFreeMessage(MIDI_MSG *pMsg);
#endif /* _MIDIFILE_H */