diff options
author | Chris Xiong <chirs241097@gmail.com> | 2017-02-09 16:04:43 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2017-02-09 16:04:43 +0800 |
commit | 620aad63042e0f397ea6691fe92ac40fcc6b6fed (patch) | |
tree | b36a0f0c00ffba03bfed9513a360b7ecf442e720 /core | |
parent | 1976c49f835267d33ef88bd3fc20d18363e12c0b (diff) | |
download | QMidiPlayer-620aad63042e0f397ea6691fe92ac40fcc6b6fed.tar.xz |
Add extra midi formats support via the file reader API.
Fix note counting.
Diffstat (limited to 'core')
-rw-r--r-- | core/qmpmidiplay.cpp | 2 | ||||
-rw-r--r-- | core/qmpmidiplay.hpp | 4 | ||||
-rw-r--r-- | core/qmpmidiread.cpp | 16 |
3 files changed, 18 insertions, 4 deletions
diff --git a/core/qmpmidiplay.cpp b/core/qmpmidiplay.cpp index d5df23c..76c7d16 100644 --- a/core/qmpmidiplay.cpp +++ b/core/qmpmidiplay.cpp @@ -321,7 +321,7 @@ void CMidiPlayer::playerPanic(bool reset) } bool CMidiPlayer::playerLoadFile(const char* fn) { - midiReaders->readFile(fn);notes=0; + notes=0;midiReaders->readFile(fn); if(!midiReaders->isValid())return false; divs=midiReaders->getDivision(); for(int i=0;i<16;++i)if(fileReadFinishCB[i]) diff --git a/core/qmpmidiplay.hpp b/core/qmpmidiplay.hpp index b911844..ebc62d6 100644 --- a/core/qmpmidiplay.hpp +++ b/core/qmpmidiplay.hpp @@ -38,8 +38,9 @@ class CMidiFileReaderCollection{ std::vector<std::pair<IMidiFileReader*,std::string>> readers; CMidiFile* file; uint32_t maxtk; - void destructFile(CMidiFile*& f); IMidiFileReader* currentReader; + void destructFile(CMidiFile*& f); + void dumpFile(); public: CMidiFileReaderCollection(); ~CMidiFileReaderCollection(); @@ -59,6 +60,7 @@ public: }; class CMidiPlayer { + friend class CMidiFileReaderCollection; private: CMidiFileReaderCollection *midiReaders; uint32_t stamps[101],notes; diff --git a/core/qmpmidiread.cpp b/core/qmpmidiread.cpp index b36fffc..92573d2 100644 --- a/core/qmpmidiread.cpp +++ b/core/qmpmidiread.cpp @@ -12,7 +12,6 @@ const char* GM1SysX={"\xF0\x7E\x7F\x09\x01\xF7"}; const char* GM2SysX={"\xF0\x7E\x7F\x09\x03\xF7"}; const char* GSSysEx={"\xF0\x41\x10\x42\x12\x40\x00\x7F\x00\x41\xF7"}; const char* XGSysEx={"\xF0\x43\x10\x4C\x00\x00\x7E\x00\xF7"}; -bool cmp(SEvent a,SEvent b){return a.time-b.time?a.time<b.time:a.iid<b.iid;} void CSMFReader::error(int fatal,const char* format,...) { va_list ap; @@ -240,7 +239,7 @@ CMidiFile* CSMFReader::readFile(const char* fn) chunkReader(1); for(uint32_t i=0;i<trk;i+=chunkReader(0)); fclose(f);f=NULL; - std::sort(ret->eventList.begin(),ret->eventList.end(),cmp); + std::sort(ret->eventList.begin(),ret->eventList.end()); } catch(std::runtime_error&){fprintf(stderr,"E: %s is not a supported file.\n",fn);ret->valid=0;fclose(f);f=NULL;} return ret; @@ -270,6 +269,18 @@ void CMidiFileReaderCollection::destructFile(CMidiFile*& f) delete f; f=NULL; } +void CMidiFileReaderCollection::dumpFile() +{ + if(!file)return; + std::vector<SEvent> &eventList=file->eventList; + for(uint32_t i=0;i<eventList.size();++i) + if(eventList[i].str.length()) + printf("type %x #%d @%d p1 %d p2 %d str %s\n",eventList[i].type, + eventList[i].iid,eventList[i].time,eventList[i].p1,eventList[i].p2,eventList[i].str.c_str()); + else + printf("type %x #%d @%d p1 %d p2 %d\n",eventList[i].type, + eventList[i].iid,eventList[i].time,eventList[i].p1,eventList[i].p2); +} CMidiFileReaderCollection::CMidiFileReaderCollection() { file=NULL;readers.clear();currentReader=NULL; @@ -301,6 +312,7 @@ void CMidiFileReaderCollection::readFile(const char* fn) for(unsigned i=0;i<readers.size();++i) { currentReader=readers[i].first; + CMidiPlayer::getInstance()->notes=0; CMidiFile* t=readers[i].first->readFile(fn); if(t->valid){file=t;break;} else destructFile(t); |