From 1976c49f835267d33ef88bd3fc20d18363e12c0b Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Wed, 8 Feb 2017 23:45:18 +0800 Subject: Add API version verification. This breaks compatibility with old versions of plugins. Add RIFF MIDI support to the SMF reader. Documentation. --- core/qmpmidiread.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'core/qmpmidiread.cpp') diff --git a/core/qmpmidiread.cpp b/core/qmpmidiread.cpp index 4ac2ac8..b36fffc 100644 --- a/core/qmpmidiread.cpp +++ b/core/qmpmidiread.cpp @@ -203,10 +203,21 @@ void CSMFReader::headerChunkReader() int CSMFReader::chunkReader(int hdrXp) { char hdr[6]; - if(!fgets(hdr,5,f))error(1,"E: Unexpected EOF."); + fread(hdr,1,4,f); + if(feof(f))error(1,"E: Unexpected EOF."); if(hdrXp) + { + if(!strncmp(hdr,"RIFF",4)) + { + fseek(f,4,SEEK_CUR); + fread(hdr,1,4,f); + if(strncmp(hdr,"RMID",4)){error(1,"E: Wrong file type in RIFF container.");throw std::runtime_error("Wrong file type in RIFF container");} + fseek(f,8,SEEK_CUR); + fread(hdr,1,4,f); + } if(strncmp(hdr,"MThd",4)){error(1,"E: Wrong MIDI header.");throw std::runtime_error("Wrong MIDI header");} else return headerChunkReader(),0; + } else if(strncmp(hdr,"MTrk",4)) { -- cgit v1.2.3