aboutsummaryrefslogtreecommitdiff
path: root/qmpmidiread.cpp
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2016-01-01 23:54:06 +0800
committerGravatar Chris Xiong <chirs241097@gmail.com> 2016-01-01 23:54:06 +0800
commitd418712c981d9854fa6429d65773368ca63b8dac (patch)
tree48eb1f25753a1734a3d7cf5d8303e7936c4844f3 /qmpmidiread.cpp
parent3db127ce64eadb54568e218124744a1de713667e (diff)
downloadQMidiPlayer-d418712c981d9854fa6429d65773368ca63b8dac.tar.xz
Strawberry Crisis. (WTF)
Diffstat (limited to 'qmpmidiread.cpp')
-rw-r--r--qmpmidiread.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/qmpmidiread.cpp b/qmpmidiread.cpp
index 0d9a7bc..8f7ad28 100644
--- a/qmpmidiread.cpp
+++ b/qmpmidiread.cpp
@@ -181,27 +181,29 @@ void CMidiFile::headerChunkReader()
if(divs&0x8000)error(1,"E: SMTPE format is not supported.");
for(;byteread<chnklen;++byteread){fgetc(f);}
}
-void CMidiFile::chunkReader(int hdrXp)
+int CMidiFile::chunkReader(int hdrXp)
{
char hdr[6];
if(!fgets(hdr,5,f))error(1,"E: Unexpected EOF.");
if(hdrXp)
- if(strncmp(hdr,"MThd",4))error(1,"E: Wrong MIDI header.");
- else headerChunkReader();
+ if(strncmp(hdr,"MThd",4)){error(1,"E: Wrong MIDI header.");throw;}
+ else return headerChunkReader(),0;
else
if(strncmp(hdr,"MTrk",4))
{
error(0,"W: Wrong track chunk header. Ignoring the whole chunk.");
- for(int chnklen=readDW();chnklen>0;--chnklen)fgetc(f);
+ for(int chnklen=readDW();chnklen>0;--chnklen)fgetc(f);return 0;
}
- else trackChunkReader();
+ else return trackChunkReader(),1;
}
CMidiFile::CMidiFile(const char* fn)
{
- title=copyright=NULL;
+ if(title)delete[] title;
+ if(copyright)delete[] copyright;
+ title=copyright=NULL;notes=0;
if(!(f=fopen(fn,"rb")))exit((printf("E: file %s doesn't exist!\n",fn),2));
chunkReader(1);
- for(uint32_t i=0;i<trk;++i)chunkReader(0);
+ for(uint32_t i=0;i<trk;i+=chunkReader(0));
printf("%d note(s)\n",notes);
fclose(f);
std::sort(eventList,eventList+eventc,cmp);
@@ -214,5 +216,6 @@ CMidiFile::~CMidiFile()
const SEvent* CMidiFile::getEvent(uint32_t id){return id<eventc?eventList[id]:NULL;}
uint32_t CMidiFile::getEventCount(){return eventc;}
uint32_t CMidiFile::getDivision(){return divs;}
+uint32_t CMidiFile::getNoteCount(){return notes;}
const char* CMidiFile::getTitle(){return title;}
const char* CMidiFile::getCopyright(){return copyright;}