00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef MK__midifile_H___
00021 #define MK__midifile_H___
00022
00023 #import <Foundation/Foundation.h>
00024
00025
00026 #define MK_MIDIMAGIC ((int)1297377380) // "MThd"
00027
00028
00029
00030
00031
00032
00033
00034 #define MKMIDI_DEFAULTQUANTASIZE (1000)
00035
00036 typedef enum MKMIDIMetaEvent {
00037
00038 MKMIDI_sequenceNumber = 0,
00039
00040
00041
00042 MKMIDI_text = 1,
00043 MKMIDI_copyright = 2,
00044 MKMIDI_sequenceOrTrackName = 3,
00045 MKMIDI_instrumentName = 4,
00046 MKMIDI_lyric = 5,
00047 MKMIDI_marker = 6,
00048 MKMIDI_cuePoint = 7,
00049
00050
00051
00052
00053
00054
00055 MKMIDI_trackChange,
00056
00057
00058
00059
00060
00061 MKMIDI_tempoChange,
00062
00063
00064
00065 MKMIDI_smpteOffset,
00066
00067
00068
00069 MKMIDI_timeSig,
00070
00071 MKMIDI_keySig
00072
00073 } MKMIDIMetaevent;
00074
00075 typedef struct _midiFileInStruct {
00076 double tempo;
00077 double timeScale;
00078 int currentTrack;
00079 int currentTime;
00080 int currentOffset;
00081 int division;
00082 short format;
00083 int quantaSize;
00084 unsigned char runningStatus;
00085 NSMutableData *midiStream;
00086 int curBufSize;
00087
00088 int quanta;
00089 BOOL metaeventFlag;
00090 int nData;
00091 unsigned char *data;
00092 BOOL evaluateTempo;
00093 unsigned int streamPos;
00094 } MKMIDIFileIn;
00095
00096 typedef struct _midiFileOutStruct {
00097 double tempo;
00098 double timeScale;
00099 int currentTrack;
00100 int division;
00101 int currentCount;
00102 int lastTime;
00103 NSMutableData *midiStream;
00104 int quantaSize;
00105 BOOL evaluateTempo;
00106 } MKMIDIFileOut;
00107
00112 extern MKMIDIFileIn *MKMIDIFileBeginReading(NSMutableData *fileData, BOOL evaluateTempo);
00113
00114 extern void MKMIDIFileEndReading(MKMIDIFileIn *p);
00115
00122 extern int MKMIDIFileReadPreamble(MKMIDIFileIn *p, int *level, int *track_count);
00123
00130 extern int MKMIDIFileReadEvent(MKMIDIFileIn *p);
00131
00139 MKMIDIFileOut *MKMIDIFileBeginWriting(NSMutableData *midiStream, int level, NSString *sequenceName, BOOL evaluateTempo);
00140
00144 extern int MKMIDIFileEndWriting(MKMIDIFileOut *p);
00145
00150 extern int MKMIDIFileBeginWritingTrack(MKMIDIFileOut *p, NSString *trackName);
00151
00156 extern int MKMIDIFileEndWritingTrack(MKMIDIFileOut *p, int quanta);
00157
00158 extern int MKMIDIFileWriteTempo(MKMIDIFileOut *p, int quanta, double beatsPerMinute);
00159
00160 extern int MKMIDIFileWriteEvent(MKMIDIFileOut *p, int quanta, int ndata, unsigned char *bytes);
00161
00165 extern int MKMIDIFileWriteSysExcl(MKMIDIFileOut *p, int quanta, int ndata, unsigned char *bytes);
00166
00170 extern int MKMIDIFileWriteSig(MKMIDIFileOut *p, int quanta, short metaevent, unsigned data);
00171
00172 extern int MKMIDIFileWriteText(MKMIDIFileOut *p, int quanta, short metaevent, NSString *data);
00173
00174 extern int MKMIDIFileWriteSMPTEoffset(MKMIDIFileOut *p,
00175 unsigned char hr,
00176 unsigned char min,
00177 unsigned char sec,
00178 unsigned char ff,
00179 unsigned char fr);
00180
00181 int MKMIDIFileWriteSequenceNumber(MKMIDIFileOut *p, int data);
00182
00183 #endif