aboutsummaryrefslogtreecommitdiff
path: root/qmpmidiread.cpp
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2016-01-14 21:47:06 +0800
committerGravatar Chris Xiong <chirs241097@gmail.com> 2016-01-14 21:47:06 +0800
commit1e1036e705b20ea407bbb922e40c0f44147b3691 (patch)
treefe0d5560c3c44be62de50b8e433b81da0a135f70 /qmpmidiread.cpp
parentfab7ae34311b9bbb001c98baafa4b1a99aa3c18f (diff)
downloadQMidiPlayer-1e1036e705b20ea407bbb922e40c0f44147b3691.tar.xz
Innocent Treasure. (WTF)
Diffstat (limited to 'qmpmidiread.cpp')
-rw-r--r--qmpmidiread.cpp21
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;}