diff options
author | Chris Xiong <chirs241097@gmail.com> | 2016-01-14 21:47:06 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2016-01-14 21:47:06 +0800 |
commit | 1e1036e705b20ea407bbb922e40c0f44147b3691 (patch) | |
tree | fe0d5560c3c44be62de50b8e433b81da0a135f70 /qmpmidiread.cpp | |
parent | fab7ae34311b9bbb001c98baafa4b1a99aa3c18f (diff) | |
download | QMidiPlayer-1e1036e705b20ea407bbb922e40c0f44147b3691.tar.xz |
Innocent Treasure. (WTF)
Diffstat (limited to 'qmpmidiread.cpp')
-rw-r--r-- | qmpmidiread.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/qmpmidiread.cpp b/qmpmidiread.cpp index c9fff34..f09f9e0 100644 --- a/qmpmidiread.cpp +++ b/qmpmidiread.cpp @@ -18,7 +18,7 @@ void CMidiFile::error(int fatal,const char* format,...) va_list ap; va_start(ap,format);vfprintf(stderr,format,ap);va_end(ap); fprintf(stderr," at %#lx\n",ftell(f)); - if(fatal)exit(2); + if(fatal)throw 2; } uint32_t CMidiFile::readSW() { @@ -215,13 +215,17 @@ CMidiFile::CMidiFile(const char* fn) { if(title)delete[] title; if(copyright)delete[] copyright; - title=copyright=NULL;notes=0;std=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)); - printf("%d note(s)\n",notes); - fclose(f); - std::sort(eventList,eventList+eventc,cmp); + title=copyright=NULL;notes=0;std=0;valid=1; + try + { + if(!(f=fopen(fn,"rb")))throw (fprintf(stderr,"E: file %s doesn't exist!\n",fn),2); + chunkReader(1); + for(uint32_t i=0;i<trk;i+=chunkReader(0)); + printf("%d note(s)\n",notes); + fclose(f); + std::sort(eventList,eventList+eventc,cmp); + } + catch(int){fprintf(stderr,"E: %s is not a supported file.\n",fn);valid=0;} } CMidiFile::~CMidiFile() { @@ -233,5 +237,6 @@ uint32_t CMidiFile::getEventCount(){return eventc;} uint32_t CMidiFile::getDivision(){return divs;} uint32_t CMidiFile::getNoteCount(){return notes;} uint32_t CMidiFile::getStandard(){return std;} +bool CMidiFile::isValid(){return valid;} const char* CMidiFile::getTitle(){return title;} const char* CMidiFile::getCopyright(){return copyright;} |