00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __MIDIReader__
00025 #define __MIDIReader__
00026
00027 #include <stdio.h>
00028 #include "MIDIDataTypes.hxx"
00029 #include "MIDIChunkType.hxx"
00030
00031 namespace MIDI
00032 {
00033 class Song;
00034
00035 class Reader
00036
00037
00038 {
00039 private:
00040 FILE* mFile;
00041 int mCnt;
00042 public:
00043 Reader(const char* filename)
00044 {
00045 mFile = fopen(filename,"rb");
00046 }
00047 bool Ok(void)
00048 {
00049 return mFile!=NULL;
00050 }
00051 Byte GetByte(void)
00052 {
00053 mCnt++;
00054 return fgetc(mFile);
00055 }
00056 unsigned int GetInt(void)
00057 {
00058 unsigned int val;
00059
00060 val = GetByte();
00061 val <<=8;
00062 val |= GetByte();
00063 val <<=8;
00064 val |= GetByte();
00065 val <<=8;
00066 val |= GetByte();
00067
00068 return val;
00069 }
00070 unsigned short GetShort(void)
00071 {
00072 unsigned short val;
00073
00074 val = GetByte();
00075 val <<= 8;
00076 val |= GetByte();
00077
00078 return val;
00079 }
00080
00081 ChunkType GetChunkType(void)
00082 {
00083 Byte bytes[4];
00084 for (int i=0;i<4;i++) bytes[i] = GetByte();
00085 return ChunkType(bytes);
00086 }
00087
00088 unsigned int GetVarLength(void)
00089 {
00090
00091 unsigned int ret = 0;
00092 Byte tmp;
00093
00094 tmp = GetByte();
00095 ret = tmp&0x7F;
00096 while (tmp&0x80)
00097 {
00098 tmp = GetByte();
00099 ret <<= 7;
00100 ret |= (tmp&0x7F);
00101 }
00102 return ret;
00103 }
00104
00105 class Error
00106 {
00107 public:
00108 const char* mStr;
00109 Error(const char* str):mStr(str) { printf(str); }
00110 };
00111
00112 void Read(Song& s);
00113 };
00114
00115 }
00116
00117 #endif
00118