From: <sag...@us...> - 2013-04-27 23:45:27
|
Revision: 1989 http://sourceforge.net/p/modplug/code/1989 Author: saga-games Date: 2013-04-27 23:45:18 +0000 (Sat, 27 Apr 2013) Log Message: ----------- [Ref] Add a "loadFlags" parameter to every loader, to optional not load patterns or samples or to just check the header for validity. [Imp] Don't load patterns from file when previewing samples / instruments from modules in the tree view. Modified Paths: -------------- trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/mptrack/View_tre.cpp trunk/OpenMPT/soundlib/LOAD_AMF.CPP trunk/OpenMPT/soundlib/LOAD_DBM.CPP trunk/OpenMPT/soundlib/LOAD_DMF.CPP trunk/OpenMPT/soundlib/LOAD_DSM.CPP trunk/OpenMPT/soundlib/Load_669.cpp trunk/OpenMPT/soundlib/Load_ams.cpp trunk/OpenMPT/soundlib/Load_digi.cpp trunk/OpenMPT/soundlib/Load_far.cpp trunk/OpenMPT/soundlib/Load_gdm.cpp trunk/OpenMPT/soundlib/Load_imf.cpp trunk/OpenMPT/soundlib/Load_it.cpp trunk/OpenMPT/soundlib/Load_itp.cpp trunk/OpenMPT/soundlib/Load_mdl.cpp trunk/OpenMPT/soundlib/Load_med.cpp trunk/OpenMPT/soundlib/Load_mid.cpp trunk/OpenMPT/soundlib/Load_mo3.cpp trunk/OpenMPT/soundlib/Load_mod.cpp trunk/OpenMPT/soundlib/Load_mt2.cpp trunk/OpenMPT/soundlib/Load_mtm.cpp trunk/OpenMPT/soundlib/Load_okt.cpp trunk/OpenMPT/soundlib/Load_psm.cpp trunk/OpenMPT/soundlib/Load_ptm.cpp trunk/OpenMPT/soundlib/Load_s3m.cpp trunk/OpenMPT/soundlib/Load_stm.cpp trunk/OpenMPT/soundlib/Load_ult.cpp trunk/OpenMPT/soundlib/Load_umx.cpp trunk/OpenMPT/soundlib/Load_wav.cpp trunk/OpenMPT/soundlib/Load_xm.cpp trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/soundlib/Sndfile.h trunk/OpenMPT/soundlib/load_j2b.cpp Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -1634,7 +1634,7 @@ //---------------------------- { m_WaveFile.Destroy(); - m_WaveFile.Create(FileReader(), nullptr); + m_WaveFile.Create(FileReader()); // Avoid global volume ramping when trying samples in the treeview. m_WaveFile.m_nDefaultGlobalVolume = m_WaveFile.m_nGlobalVolume = MAX_GLOBAL_VOLUME; m_WaveFile.SetMixLevels(mixLevels_117RC3); Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -169,7 +169,7 @@ { if (!CDocument::OnNewDocument()) return FALSE; - m_SndFile.Create(FileReader(), this); + m_SndFile.Create(FileReader(), CSoundFile::loadCompleteModule, this); m_SndFile.ChangeModTypeTo(CTrackApp::GetDefaultDocType()); if(CTrackApp::IsProject()) @@ -214,7 +214,7 @@ LPBYTE lpStream = f.Lock(); if (lpStream) { - m_SndFile.Create(FileReader(lpStream, dwLen), this); + m_SndFile.Create(FileReader(lpStream, dwLen), CSoundFile::loadCompleteModule, this); f.Unlock(); } } Modified: trunk/OpenMPT/mptrack/View_tre.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_tre.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/mptrack/View_tre.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -275,7 +275,7 @@ } if(m_SongFile != nullptr) { - m_SongFile->Create(FileReader(lpStream, dwLen), nullptr); + m_SongFile->Create(FileReader(lpStream, dwLen), CSoundFile::loadNoPatternData, nullptr); // Destroy some stuff that we're not going to use anyway. m_SongFile->Patterns.DestroyPatterns(); m_SongFile->songMessage.clear(); Modified: trunk/OpenMPT/soundlib/LOAD_AMF.CPP =================================================================== --- trunk/OpenMPT/soundlib/LOAD_AMF.CPP 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/LOAD_AMF.CPP 2013-04-27 23:45:18 UTC (rev 1989) @@ -100,8 +100,8 @@ #endif -bool CSoundFile::ReadAMF_Asylum(FileReader &file) -//----------------------------------------------- +bool CSoundFile::ReadAMF_Asylum(FileReader &file, ModLoadingFlags loadFlags) +//-------------------------------------------------------------------------- { file.Rewind(); @@ -112,6 +112,9 @@ || file.BytesLeft() < 256 + 64 * sizeof(AsylumSampleHeader) + 64 * 4 * 8 * fileHeader.numPatterns) { return false; + } else if(loadFlags == onlyVerifyHeader) + { + return true; } InitializeGlobals(); @@ -143,7 +146,7 @@ // Read Patterns for(PATTERNINDEX pat = 0; pat < fileHeader.numPatterns; pat++) { - if(Patterns.Insert(pat, 64)) + if(!(loadFlags & loadPatternData) || Patterns.Insert(pat, 64)) { file.Skip(64 * 4 * 8); continue; @@ -167,19 +170,22 @@ } } - // Read Sample Data - const SampleIO sampleIO( - SampleIO::_8bit, - SampleIO::mono, - SampleIO::littleEndian, - SampleIO::signedPCM); + if(loadFlags & loadSampleData) + { + // Read Sample Data + const SampleIO sampleIO( + SampleIO::_8bit, + SampleIO::mono, + SampleIO::littleEndian, + SampleIO::signedPCM); - for(SAMPLEINDEX smp = 1; smp <= GetNumSamples(); smp++) - { - sampleIO.ReadSample(Samples[smp], file); + for(SAMPLEINDEX smp = 1; smp <= GetNumSamples(); smp++) + { + sampleIO.ReadSample(Samples[smp], file); + } } + return true; - } @@ -355,8 +361,8 @@ } -bool CSoundFile::ReadAMF_DSMI(FileReader &file) -//--------------------------------------------- +bool CSoundFile::ReadAMF_DSMI(FileReader &file, ModLoadingFlags loadFlags) +//------------------------------------------------------------------------ { file.Rewind(); @@ -367,6 +373,9 @@ || ((fileHeader.numChannels < 1 || fileHeader.numChannels > 32) && fileHeader.version >= 10)) { return false; + } else if(loadFlags == onlyVerifyHeader) + { + return true; } InitializeGlobals(); @@ -520,31 +529,39 @@ trackData[i] = file.GetChunk(trackSize * 3); } - // Read Sample Data - const SampleIO sampleIO( - SampleIO::_8bit, - SampleIO::mono, - SampleIO::littleEndian, - SampleIO::unsignedPCM); + if(loadFlags & loadSampleData) + { + // Read Sample Data + const SampleIO sampleIO( + SampleIO::_8bit, + SampleIO::mono, + SampleIO::littleEndian, + SampleIO::unsignedPCM); - // Why is all of this sample loading business so dumb in AMF? - // Surely there must be some great idea behind it which isn't handled here (re-using the same sample data for different sample slots maybe?) - for(uint32 seekPos = 1; seekPos <= maxSamplePos; seekPos++) - { - for(SAMPLEINDEX smp = 0; smp < GetNumSamples(); smp++) + // Why is all of this sample loading business so dumb in AMF? + // Surely there must be some great idea behind it which isn't handled here (re-using the same sample data for different sample slots maybe?) + for(uint32 seekPos = 1; seekPos <= maxSamplePos; seekPos++) { - if(seekPos == samplePos[smp]) + for(SAMPLEINDEX smp = 0; smp < GetNumSamples(); smp++) { - sampleIO.ReadSample(Samples[smp + 1], file); + if(seekPos == samplePos[smp]) + { + sampleIO.ReadSample(Samples[smp + 1], file); + break; + } + } + if(!file.BytesLeft()) + { break; } } - if(!file.BytesLeft()) - { - break; - } } + if(!(loadFlags & loadPatternData)) + { + return true; + } + // Create the patterns from the list of tracks for(PATTERNINDEX pat = 0; pat < fileHeader.numOrders; pat++) { Modified: trunk/OpenMPT/soundlib/LOAD_DBM.CPP =================================================================== --- trunk/OpenMPT/soundlib/LOAD_DBM.CPP 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/LOAD_DBM.CPP 2013-04-27 23:45:18 UTC (rev 1989) @@ -196,8 +196,8 @@ } -bool CSoundFile::ReadDBM(const BYTE *lpStream, const DWORD dwMemLength) -//--------------------------------------------------------------------- +bool CSoundFile::ReadDBM(const BYTE *lpStream, const DWORD dwMemLength, ModLoadingFlags loadFlags) +//------------------------------------------------------------------------------------------------ { const DBMFileHeader *pfh = (DBMFileHeader *)lpStream; DWORD dwMemPos; @@ -209,7 +209,10 @@ || (pfh->info_id != DBM_ID_INFO) || (pfh->info_len != DBM_INFOLEN)) return false; dwMemPos = sizeof(DBMFileHeader); nOrders = BigEndianW(pfh->orders); - if (dwMemPos + 2 * nOrders + 8*3 >= dwMemLength) return false; + if (dwMemPos + 2 * nOrders + 8*3 >= dwMemLength) + return false; + else if(loadFlags == onlyVerifyHeader) + return true; InitializeGlobals(); InitializeChannels(); @@ -340,7 +343,7 @@ } } else // Packed Pattern Data - if (chunk_id == DBM_ID_PATT) + if (chunk_id == DBM_ID_PATT && (loadFlags & loadPatternData)) { if (nPatterns > MAX_PATTERNS) nPatterns = MAX_PATTERNS; for(PATTERNINDEX iPat = 0; iPat < nPatterns; iPat++) @@ -456,7 +459,7 @@ } } else // Reading Sample Data - if (chunk_id == DBM_ID_SMPL) + if (chunk_id == DBM_ID_SMPL && (loadFlags & loadSampleData)) { if (nSamples >= MAX_SAMPLES) nSamples = MAX_SAMPLES-1; m_nSamples = nSamples; Modified: trunk/OpenMPT/soundlib/LOAD_DMF.CPP =================================================================== --- trunk/OpenMPT/soundlib/LOAD_DMF.CPP 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/LOAD_DMF.CPP 2013-04-27 23:45:18 UTC (rev 1989) @@ -954,8 +954,8 @@ } -bool CSoundFile::ReadDMF(FileReader &file) -//---------------------------------------- +bool CSoundFile::ReadDMF(FileReader &file, ModLoadingFlags loadFlags) +//------------------------------------------------------------------- { DMFFileHeader fileHeader; file.Rewind(); @@ -964,6 +964,9 @@ || !fileHeader.version || fileHeader.version > 10) { return false; + } else if(loadFlags == onlyVerifyHeader) + { + return true; } InitializeGlobals(); @@ -1004,7 +1007,7 @@ // Read patterns chunk = chunks.GetChunk(DMFChunk::idPATT); - if(chunk.IsValid()) + if(chunk.IsValid() && (loadFlags & loadPatternData)) { DMFPatterns patHeader; chunk.ReadConvertEndianness(patHeader); @@ -1076,7 +1079,7 @@ // Now read the sample data from the data chunk FileReader sampleData = sampleDataChunk.GetChunk(sampleDataChunk.ReadUint32LE()); - if(sampleData.IsValid()) + if(sampleData.IsValid() && (loadFlags & loadSampleData)) { SampleIO( sample.uFlags[CHN_16BIT] ? SampleIO::_16bit : SampleIO::_8bit, Modified: trunk/OpenMPT/soundlib/LOAD_DSM.CPP =================================================================== --- trunk/OpenMPT/soundlib/LOAD_DSM.CPP 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/LOAD_DSM.CPP 2013-04-27 23:45:18 UTC (rev 1989) @@ -1,7 +1,7 @@ /* * Load_dsm.cpp * ------------ - * Purpose: DSIK Internal Format (DSM) module loader + * Purpose: Digisound Interface Kit (DSIK) Internal Format (DSM) module loader * Notes : (currently none) * Authors: Olivier Lapicque * OpenMPT Devs @@ -100,8 +100,8 @@ #endif -bool CSoundFile::ReadDSM(const LPCBYTE lpStream, const DWORD dwMemLength) -//----------------------------------------------------------------------- +bool CSoundFile::ReadDSM(const LPCBYTE lpStream, const DWORD dwMemLength, ModLoadingFlags loadFlags) +//-------------------------------------------------------------------------------------------------- { DSMFILEHEADER *pfh = (DSMFILEHEADER *)lpStream; DSMSONG *psong; @@ -112,7 +112,13 @@ if ((!lpStream) || (dwMemLength < 1024) || (pfh->id_RIFF != DSMID_RIFF) || (pfh->riff_len + 8 > dwMemLength) || (pfh->riff_len < 1024) || (pfh->id_DSMF != DSMID_DSMF) || (pfh->id_SONG != DSMID_SONG) - || (pfh->song_len > dwMemLength)) return false; + || (pfh->song_len > dwMemLength)) + { + return false; + } else if(loadFlags == onlyVerifyHeader) + { + return true; + } psong = (DSMSONG *)(lpStream + sizeof(DSMFILEHEADER)); dwMemPos = sizeof(DSMFILEHEADER) + pfh->song_len; @@ -149,7 +155,7 @@ DSMPATT *ppatt = (DSMPATT *)(lpStream + dwMemPos); DSMSAMPLE *pSmp = (DSMSAMPLE *)(lpStream+dwMemPos); // Reading Patterns - if (ppatt->id_PATT == DSMID_PATT) + if (ppatt->id_PATT == DSMID_PATT && (loadFlags & loadPatternData)) { dwMemPos += 8; if (dwMemPos + ppatt->patt_len >= dwMemLength) break; @@ -249,13 +255,16 @@ sample.nVolume = (WORD)(pSmp->volume << 2); if (sample.nVolume > 256) sample.nVolume = 256; - FileReader chunk(lpStream + dwPos, dwMemLength - dwPos); - SampleIO( - SampleIO::_8bit, - SampleIO::mono, - SampleIO::littleEndian, - (pSmp->flags & 2) ? SampleIO::signedPCM : SampleIO::unsignedPCM) - .ReadSample(sample, chunk); + if(loadFlags & loadSampleData) + { + FileReader chunk(lpStream + dwPos, dwMemLength - dwPos); + SampleIO( + SampleIO::_8bit, + SampleIO::mono, + SampleIO::littleEndian, + (pSmp->flags & 2) ? SampleIO::signedPCM : SampleIO::unsignedPCM) + .ReadSample(sample, chunk); + } nSmp++; } else Modified: trunk/OpenMPT/soundlib/Load_669.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_669.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/Load_669.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -87,8 +87,8 @@ #endif -bool CSoundFile::Read669(FileReader &file) -//---------------------------------------- +bool CSoundFile::Read669(FileReader &file, ModLoadingFlags loadFlags) +//------------------------------------------------------------------- { _669FileHeader fileHeader; @@ -100,6 +100,9 @@ || fileHeader.patterns > 128) { return false; + } else if(loadFlags == onlyVerifyHeader) + { + return true; } //bool has669Ext = fileHeader.sig == _669FileHeader::magic669Ext; @@ -145,7 +148,7 @@ // Reading Patterns for(PATTERNINDEX pat = 0; pat < fileHeader.patterns; pat++) { - if(Patterns.Insert(pat, 64)) + if(!(loadFlags & loadPatternData) || Patterns.Insert(pat, 64)) { file.Skip(64 * 8 * 3); continue; @@ -265,16 +268,20 @@ Patterns[pat].WriteEffect(EffectWriter(CMD_SPEED, fileHeader.tempoList[pat]).Retry(EffectWriter::rmTryNextRow)); } - // Reading Samples - const SampleIO sampleIO( - SampleIO::_8bit, - SampleIO::mono, - SampleIO::littleEndian, - SampleIO::unsignedPCM); + if(loadFlags & loadSampleData) + { + // Reading Samples + const SampleIO sampleIO( + SampleIO::_8bit, + SampleIO::mono, + SampleIO::littleEndian, + SampleIO::unsignedPCM); - for(SAMPLEINDEX n = 1; n <= m_nSamples; n++) - { - sampleIO.ReadSample(Samples[n], file); + for(SAMPLEINDEX n = 1; n <= m_nSamples; n++) + { + sampleIO.ReadSample(Samples[n], file); + } } + return true; } \ No newline at end of file Modified: trunk/OpenMPT/soundlib/Load_ams.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_ams.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/Load_ams.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -377,8 +377,8 @@ #endif -bool CSoundFile::ReadAMS(FileReader &file) -//---------------------------------------- +bool CSoundFile::ReadAMS(FileReader &file, ModLoadingFlags loadFlags) +//------------------------------------------------------------------- { file.Rewind(); @@ -390,6 +390,9 @@ || fileHeader.versionHigh != 0x01) { return false; + } else if(loadFlags == onlyVerifyHeader) + { + return true; } InitializeGlobals(); @@ -480,19 +483,26 @@ uint32 patLength = file.ReadUint32LE(); FileReader patternChunk = file.GetChunk(patLength); - ReadAMSPattern(Patterns[pat], false, patternChunk, *this); + if(loadFlags & loadPatternData) + { + ReadAMSPattern(Patterns[pat], false, patternChunk, *this); + } } - // Read Samples - for(SAMPLEINDEX smp = 1; smp <= GetNumSamples(); smp++) + if(loadFlags & loadSampleData) { - SampleIO( - (Samples[smp].uFlags & CHN_16BIT) ? SampleIO::_16bit : SampleIO::_8bit, - SampleIO::mono, - SampleIO::littleEndian, - packSample[smp - 1] ? SampleIO::AMS : SampleIO::signedPCM) - .ReadSample(Samples[smp], file); + // Read Samples + for(SAMPLEINDEX smp = 1; smp <= GetNumSamples(); smp++) + { + SampleIO( + (Samples[smp].uFlags & CHN_16BIT) ? SampleIO::_16bit : SampleIO::_8bit, + SampleIO::mono, + SampleIO::littleEndian, + packSample[smp - 1] ? SampleIO::AMS : SampleIO::signedPCM) + .ReadSample(Samples[smp], file); + } } + return true; } @@ -726,8 +736,8 @@ #endif -bool CSoundFile::ReadAMS2(FileReader &file) -//----------------------------------------- +bool CSoundFile::ReadAMS2(FileReader &file, ModLoadingFlags loadFlags) +//-------------------------------------------------------------------- { file.Rewind(); @@ -737,6 +747,9 @@ || !file.ReadConvertEndianness(fileHeader)) { return false; + } else if(loadFlags == onlyVerifyHeader) + { + return true; } uint16 headerFlags; @@ -913,22 +926,30 @@ uint32 patLength = file.ReadUint32LE(); FileReader patternChunk = file.GetChunk(patLength); - const ROWINDEX numRows = patternChunk.ReadUint8() + 1; - // We don't need to know the number of channels or commands. - patternChunk.Skip(1); - - if(Patterns.Insert(pat, numRows)) + if(loadFlags & loadPatternData) { - continue; - } + const ROWINDEX numRows = patternChunk.ReadUint8() + 1; + // We don't need to know the number of channels or commands. + patternChunk.Skip(1); - char patternName[11]; - ReadAMSString(patternName, patternChunk); - Patterns[pat].SetName(patternName); + if(Patterns.Insert(pat, numRows)) + { + continue; + } - ReadAMSPattern(Patterns[pat], true, patternChunk, *this); + char patternName[11]; + ReadAMSString(patternName, patternChunk); + Patterns[pat].SetName(patternName); + + ReadAMSPattern(Patterns[pat], true, patternChunk, *this); + } } + if(!(loadFlags & loadSampleData)) + { + return true; + } + // Read Samples for(SAMPLEINDEX smp = 0; smp < GetNumSamples(); smp++) { Modified: trunk/OpenMPT/soundlib/Load_digi.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_digi.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/Load_digi.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -90,8 +90,8 @@ } -bool CSoundFile::ReadDIGI(FileReader &file) -//----------------------------------------- +bool CSoundFile::ReadDIGI(FileReader &file, ModLoadingFlags loadFlags) +//-------------------------------------------------------------------- { file.Rewind(); @@ -103,6 +103,9 @@ || fileHeader.lastOrdIndex > 127) { return false; + } else if(loadFlags == onlyVerifyHeader) + { + return true; } // Globals @@ -143,14 +146,22 @@ for(PATTERNINDEX pat = 0; pat <= fileHeader.lastPatIndex; pat++) { - if(Patterns.Insert(pat, 64)) + FileReader patternChunk; + if(fileHeader.packEnable) { - break; + patternChunk = file.GetChunk(file.ReadUint16BE()); + } else + { + patternChunk = file.GetChunk(4 * 64 * GetNumChannels()); } + if(!(loadFlags & loadPatternData) || Patterns.Insert(pat, 64)) + { + continue; + } + if(fileHeader.packEnable) { - FileReader patternChunk = file.GetChunk(file.ReadUint16BE()); std::vector<uint8> eventMask; patternChunk.ReadVector(eventMask, 64); @@ -175,22 +186,25 @@ { for(ROWINDEX row = 0; row < 64; row++) { - ReadDIGIPatternEntry(file, *Patterns[pat].GetpModCommand(row, chn), *this); + ReadDIGIPatternEntry(patternChunk, *Patterns[pat].GetpModCommand(row, chn), *this); } } } } - // Reading Samples - const SampleIO sampleIO( - SampleIO::_8bit, - SampleIO::mono, - SampleIO::bigEndian, - SampleIO::signedPCM); + if(loadFlags & loadSampleData) + { + // Reading Samples + const SampleIO sampleIO( + SampleIO::_8bit, + SampleIO::mono, + SampleIO::bigEndian, + SampleIO::signedPCM); - for(SAMPLEINDEX smp = 1; smp <= 31; smp++) - { - sampleIO.ReadSample(Samples[smp], file); + for(SAMPLEINDEX smp = 1; smp <= 31; smp++) + { + sampleIO.ReadSample(Samples[smp], file); + } } return true; Modified: trunk/OpenMPT/soundlib/Load_far.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_far.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/Load_far.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -132,8 +132,8 @@ #endif -bool CSoundFile::ReadFAR(FileReader &file) -//---------------------------------------- +bool CSoundFile::ReadFAR(FileReader &file, ModLoadingFlags loadFlags) +//------------------------------------------------------------------- { file.Rewind(); @@ -144,6 +144,9 @@ || file.GetLength() < static_cast<size_t>(fileHeader.headerLength)) { return false; + } else + { + return true; } // Globals @@ -215,7 +218,7 @@ // Calculate pattern length in rows (every event is 4 bytes, and we have 16 channels) ROWINDEX numRows = (orderHeader.patternSize[pat] - 2) / (16 * 4); - if(!numRows || numRows > MAX_PATTERN_ROWS || Patterns.Insert(pat, numRows)) + if(!(loadFlags & loadPatternData) || !numRows || numRows > MAX_PATTERN_ROWS || Patterns.Insert(pat, numRows)) { continue; } @@ -284,6 +287,11 @@ Patterns[pat].WriteEffect(EffectWriter(CMD_PATTERNBREAK, 0).Row(breakRow).Retry(EffectWriter::rmTryNextRow)); } + if(!(loadFlags & loadSampleData)) + { + return true; + } + // Read samples uint8 sampleMap[8]; // Sample usage bitset file.ReadArray(sampleMap); Modified: trunk/OpenMPT/soundlib/Load_gdm.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_gdm.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/Load_gdm.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -130,8 +130,8 @@ #endif -bool CSoundFile::ReadGDM(FileReader &file) -//---------------------------------------- +bool CSoundFile::ReadGDM(FileReader &file, ModLoadingFlags loadFlags) +//------------------------------------------------------------------- { file.Rewind(); @@ -151,6 +151,9 @@ || fileHeader.originalFormat == 0) { return false; + } else if(loadFlags == onlyVerifyHeader) + { + return true; } InitializeGlobals(); @@ -267,7 +270,7 @@ } // Read sample data - if(file.Seek(fileHeader.sampleDataOffset)) + if((loadFlags & loadSampleData) && file.Seek(fileHeader.sampleDataOffset)) { for(SAMPLEINDEX smp = 1; smp <= GetNumSamples(); smp++) { @@ -304,9 +307,9 @@ } FileReader chunk = file.GetChunk(patternLength - 2); - if(!chunk.IsValid() || Patterns.Insert(pat, 64)) + if(!(loadFlags & loadPatternData) || !chunk.IsValid() || Patterns.Insert(pat, 64)) { - break; + continue; } enum Modified: trunk/OpenMPT/soundlib/Load_imf.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_imf.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/Load_imf.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -393,8 +393,8 @@ } } -bool CSoundFile::ReadIMF(FileReader &file) -//---------------------------------------- +bool CSoundFile::ReadIMF(FileReader &file, ModLoadingFlags loadFlags) +//------------------------------------------------------------------- { IMFFileHeader fileHeader; file.Rewind(); @@ -404,12 +404,11 @@ return false; } - InitializeGlobals(); // Read channel configuration std::bitset<32> ignoreChannels; // bit set for each channel that's completely disabled - m_nChannels = 0; - for(CHANNELINDEX chn = 0; chn < 32; chn++) + uint8 detectedChannels = 0; + for(uint8 chn = 0; chn < 32; chn++) { ChnSettings[chn].Reset(); ChnSettings[chn].nPan = fileHeader.channels[chn].panning * 256 / 255; @@ -420,11 +419,11 @@ switch(fileHeader.channels[chn].status) { case 0: // enabled; don't worry about it - m_nChannels = chn + 1; + detectedChannels = chn + 1; break; case 1: // mute ChnSettings[chn].dwFlags = CHN_MUTE; - m_nChannels = chn + 1; + detectedChannels = chn + 1; break; case 2: // disabled ChnSettings[chn].dwFlags = CHN_MUTE; @@ -435,8 +434,17 @@ return false; } } - if(!m_nChannels) return false; + if(!detectedChannels) + { + return false; + } else if(loadFlags == onlyVerifyHeader) + { + return true; + } + InitializeGlobals(); + m_nChannels = detectedChannels; + //From mikmod: work around an Orpheus bug if(fileHeader.channels[0].status == 0) { @@ -474,7 +482,7 @@ const uint16 length = file.ReadUint16LE(), numRows = file.ReadUint16LE(); FileReader patternChunk = file.GetChunk(length - 4); - if(Patterns.Insert(pat, numRows)) + if(!(loadFlags & loadPatternData) || Patterns.Insert(pat, numRows)) { continue; } @@ -602,12 +610,15 @@ if(sampleHeader.length) { FileReader sampleChunk = file.GetChunk(sampleHeader.length); - SampleIO( - sample.uFlags[CHN_16BIT] ? SampleIO::_16bit : SampleIO::_8bit, - SampleIO::mono, - SampleIO::littleEndian, - SampleIO::signedPCM) - .ReadSample(sample, sampleChunk); + if(loadFlags & loadSampleData) + { + SampleIO( + sample.uFlags[CHN_16BIT] ? SampleIO::_16bit : SampleIO::_8bit, + SampleIO::mono, + SampleIO::littleEndian, + SampleIO::signedPCM) + .ReadSample(sample, sampleChunk); + } } } firstSample += instrumentHeader.smpNum; Modified: trunk/OpenMPT/soundlib/Load_it.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_it.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/Load_it.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -278,8 +278,8 @@ } -bool CSoundFile::ReadIT(FileReader &file) -//--------------------------------------- +bool CSoundFile::ReadIT(FileReader &file, ModLoadingFlags loadFlags) +//------------------------------------------------------------------ { file.Rewind(); @@ -291,6 +291,9 @@ || !file.CanRead(fileHeader.ordnum + (fileHeader.insnum + fileHeader.smpnum + fileHeader.patnum) * 4)) { return false; + } else if(loadFlags == onlyVerifyHeader) + { + return true; } InitializeGlobals(); @@ -629,7 +632,7 @@ StringFixer::ReadString<StringFixer::spacePadded>(m_szNames[i + 1], sampleHeader.name); - if(file.Seek(sampleOffset)) + if((loadFlags & loadSampleData) && file.Seek(sampleOffset)) { sampleHeader.GetSampleFormat(fileHeader.cwtv).ReadSample(Samples[i + 1], file); lastSampleOffset = std::max(lastSampleOffset, file.GetPosition()); @@ -669,7 +672,7 @@ // Checking for number of used channels, which is not explicitely specified in the file. for(PATTERNINDEX pat = 0; pat < numPats; pat++) { - if(patPos[pat] == 0 || !file.Seek(patPos[pat])) + if(!(loadFlags & loadPatternData) || patPos[pat] == 0 || !file.Seek(patPos[pat])) continue; uint16 len = file.ReadUint16LE(); Modified: trunk/OpenMPT/soundlib/Load_itp.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_itp.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/Load_itp.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -35,8 +35,8 @@ } -bool CSoundFile::ReadITProject(FileReader &file) -//---------------------------------------------- +bool CSoundFile::ReadITProject(FileReader &file, ModLoadingFlags loadFlags) +//------------------------------------------------------------------------- { #ifndef MODPLUG_TRACKER return false; @@ -55,6 +55,9 @@ || !ReadITPString(m_szNames[0], file)) // Song name { return false; + } else if(loadFlags == onlyVerifyHeader) + { + return true; } InitializeGlobals(); @@ -147,7 +150,7 @@ FileReader patternChunk = file.GetChunk(numRows * size * GetNumChannels()); // Allocate pattern - if(numRows == 0 || numRows > MAX_PATTERN_ROWS || Patterns.Insert(pat, numRows)) + if(!(loadFlags & loadPatternData) || numRows == 0 || numRows > MAX_PATTERN_ROWS || Patterns.Insert(pat, numRows)) { pattNames.Skip(patNameLen); continue; Modified: trunk/OpenMPT/soundlib/Load_mdl.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_mdl.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/Load_mdl.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -284,8 +284,8 @@ -bool CSoundFile::ReadMDL(const BYTE *lpStream, const DWORD dwMemLength) -//--------------------------------------------------------------------- +bool CSoundFile::ReadMDL(const BYTE *lpStream, const DWORD dwMemLength, ModLoadingFlags loadFlags) +//------------------------------------------------------------------------------------------------ { DWORD dwMemPos, dwPos, blocklen, dwTrackPos; const MDLFileHeader *pmsh = (const MDLFileHeader *)lpStream; @@ -303,6 +303,7 @@ if ((!lpStream) || (dwMemLength < 1024)) return false; if ((pmsh->id != 0x4C444D44) || ((pmsh->version & 0xF0) > 0x10)) return false; + else if(loadFlags == onlyVerifyHeader) return true; #ifdef MDL_LOG Log("MDL v%d.%d\n", pmsh->version>>4, pmsh->version&0x0f); #endif @@ -595,6 +596,10 @@ #ifdef MDL_LOG Log("sample data: %d bytes\n", blocklen); #endif + if(!(loadFlags & loadSampleData)) + { + break; + } dwPos = dwMemPos; for (i=1; i<=m_nSamples; i++) if ((Samples[i].nLength) && (!Samples[i].pSample) && (smpinfo[i] != 3) && (dwPos < dwMemLength)) { @@ -631,7 +636,7 @@ dwMemPos += blocklen; } // Unpack Patterns - if ((dwTrackPos) && (npatterns) && (m_nChannels) && (ntracks)) + if((loadFlags & loadPatternData) && (dwTrackPos) && (npatterns) && (m_nChannels) && (ntracks)) { for (UINT ipat=0; ipat<npatterns; ipat++) { Modified: trunk/OpenMPT/soundlib/Load_med.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_med.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/Load_med.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -499,8 +499,8 @@ } -bool CSoundFile::ReadMed(const BYTE *lpStream, const DWORD dwMemLength) -//--------------------------------------------------------------------- +bool CSoundFile::ReadMed(const BYTE *lpStream, const DWORD dwMemLength, ModLoadingFlags loadFlags) +//------------------------------------------------------------------------------------------------ { const MEDMODULEHEADER *pmmh; const MMD0SONGHEADER *pmsh; @@ -520,6 +520,7 @@ if ((dwSong >= dwMemLength) || (dwSong + sizeof(MMD0SONGHEADER) >= dwMemLength)) return false; version = (signed char)((pmmh->id >> 24) & 0xFF); if ((version < '0') || (version > '3')) return false; + else if(loadFlags == onlyVerifyHeader) return true; #ifdef MED_LOG Log("\nLoading MMD%c module (flags=0x%02X)...\n", version, BigEndian(pmmh->mmdflags)); Log(" modlen = %d\n", BigEndian(pmmh->modlen)); @@ -544,6 +545,9 @@ InitializeGlobals(); InitializeChannels(); + // Setup channel pan positions and volume + SetupMODPanning(true); + m_nType = MOD_TYPE_MED; m_nSamplePreAmp = 32; dwBlockArr = BigEndian(pmmh->blockarr); @@ -652,7 +656,7 @@ sample.RelativeTone = pmsh->sample[iSHdr].strans; sample.nPan = 128; if (sample.nLoopEnd <= 2) sample.nLoopEnd = 0; - if (sample.nLoopEnd) sample.uFlags |= CHN_LOOP; + if (sample.nLoopEnd) sample.uFlags.set(CHN_LOOP); } // Common Flags m_SongFlags.set(SONG_FASTVOLSLIDES, !(pmsh->flags & 0x20)); @@ -830,10 +834,17 @@ } } Samples[iSmp + 1].nLength = len; - FileReader chunk(psdata, dwMemLength - dwPos - 6); - sampleIO.ReadSample(Samples[iSmp + 1], chunk); + if(loadFlags & loadSampleData) + { + FileReader chunk(psdata, dwMemLength - dwPos - 6); + sampleIO.ReadSample(Samples[iSmp + 1], chunk); + } } // Reading patterns (blocks) + if(!(loadFlags & loadPatternData)) + { + return true; + } if (wNumBlocks > MAX_PATTERNS) wNumBlocks = MAX_PATTERNS; if ((!dwBlockArr) || (dwBlockArr > dwMemLength - 4*wNumBlocks)) return true; pdwTable = (LPDWORD)(lpStream + dwBlockArr); @@ -942,8 +953,6 @@ } } } - // Setup channel pan positions and volume - SetupMODPanning(true); return true; } Modified: trunk/OpenMPT/soundlib/Load_mid.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_mid.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/Load_mid.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -473,8 +473,8 @@ #define MIDIGLOBAL_XGSYSTEMON 0x0200 -bool CSoundFile::ReadMID(const BYTE *lpStream, DWORD dwMemLength) -//--------------------------------------------------------------- +bool CSoundFile::ReadMID(const BYTE *lpStream, DWORD dwMemLength, ModLoadingFlags loadFlags) +//------------------------------------------------------------------------------------------ { const MIDIFILEHEADER *pmfh = (const MIDIFILEHEADER *)lpStream; const MIDITRACKHEADER *pmth; @@ -529,6 +529,7 @@ pmth = (MIDITRACKHEADER *)(lpStream+dwMemPos); tracks = BigEndianW(pmfh->wTrks); if ((pmth->id != 0x6B72544D) || (!tracks)) return false; + else if(loadFlags == onlyVerifyHeader) return true; miditracks.resize(tracks); // Reading File... Modified: trunk/OpenMPT/soundlib/Load_mo3.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_mo3.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/Load_mo3.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -16,21 +16,24 @@ #endif // MODPLUG_TRACKER -bool CSoundFile::ReadMO3(FileReader &file) -//---------------------------------------- +bool CSoundFile::ReadMO3(FileReader &file, ModLoadingFlags loadFlags) +//------------------------------------------------------------------- { file.Rewind(); const void *stream = file.GetRawData(); int length = file.GetLength(); // No valid MO3 file (magic bytes: "MO3") - if(file.GetLength() < 8 || !file.ReadMagic("MO3")) + if(!file.CanRead(8) || !file.ReadMagic("MO3")) { return false; + } else if(loadFlags == onlyVerifyHeader) + { + return true; } #ifdef NO_MO3 - // As of April 2012, the format revision is 5; Versions > 31 are unlikely to exist in the next few years, + // As of April 2013, the format revision is 5; Versions > 31 are unlikely to exist in the next few years, // so we will just ignore those if there's no UNMO3 library to tell us if the file is valid or not // (avoid log entry with .MOD files that have a song name starting with "MO3". if(file.ReadUint8() > 31) @@ -79,12 +82,12 @@ { FileReader unpackedFile(stream, length); - result = ReadXM(unpackedFile) - || ReadIT(unpackedFile) - || ReadS3M(unpackedFile) - || ReadMTM(unpackedFile) - || ReadMod(unpackedFile) - || ReadM15(unpackedFile); + result = ReadXM(unpackedFile, loadFlags) + || ReadIT(unpackedFile, loadFlags) + || ReadS3M(unpackedFile, loadFlags) + || ReadMTM(unpackedFile, loadFlags) + || ReadMod(unpackedFile, loadFlags) + || ReadM15(unpackedFile, loadFlags); } UNMO3_Free(stream); Modified: trunk/OpenMPT/soundlib/Load_mod.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_mod.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/Load_mod.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -474,8 +474,8 @@ } -bool CSoundFile::ReadMod(FileReader &file) -//---------------------------------------- +bool CSoundFile::ReadMod(FileReader &file, ModLoadingFlags loadFlags) +//------------------------------------------------------------------- { char magic[4]; if(!file.Seek(1080) || !file.ReadArray(magic)) @@ -520,6 +520,10 @@ { return false; } + if(loadFlags == onlyVerifyHeader) + { + return true; + } LimitMax(m_nChannels, MAX_BASECHANNELS); @@ -625,17 +629,19 @@ if((pat % 2u) == 0) { // Only create "even" patterns for FLT8 files - if(Patterns.Insert(pat / 2, 64)) + if(!(loadFlags & loadPatternData) || Patterns.Insert(pat / 2, 64)) { - break; + file.Skip(readChannels * 64 * 4); + continue; } } actualPattern /= 2; } else { - if(Patterns.Insert(pat, 64)) + if(!(loadFlags & loadPatternData) || Patterns.Insert(pat, 64)) { - break; + file.Skip(readChannels * 64 * 4); + continue; } } @@ -689,9 +695,12 @@ } // Reading samples - for(SAMPLEINDEX smp = 1; smp <= 31; smp++) + if(loadFlags & loadSampleData) { - MODSampleHeader::GetSampleFormat().ReadSample(Samples[smp], file); + for(SAMPLEINDEX smp = 1; smp <= 31; smp++) + { + MODSampleHeader::GetSampleFormat().ReadSample(Samples[smp], file); + } } // Fix VBlank MODs. Arbitrary threshold: 10 minutes. @@ -741,8 +750,8 @@ } -bool CSoundFile::ReadM15(FileReader &file) -//---------------------------------------- +bool CSoundFile::ReadM15(FileReader &file, ModLoadingFlags loadFlags) +//------------------------------------------------------------------- { file.Rewind(); @@ -840,6 +849,11 @@ return false; } + if(loadFlags == onlyVerifyHeader) + { + return true; + } + // Now we can be pretty sure that this is a valid Soundtracker file. Set up default song settings. m_nType = MOD_TYPE_MOD; m_nChannels = 4; @@ -934,9 +948,10 @@ // Reading patterns for(PATTERNINDEX pat = 0; pat < numPatterns; pat++) { - if(Patterns.Insert(pat, 64)) + if(!(loadFlags & loadPatternData) || Patterns.Insert(pat, 64)) { - break; + file.Skip(64 * 4 * 4); + continue; } for(ROWINDEX row = 0; row < 64; row++) @@ -1016,15 +1031,18 @@ } // Reading samples - for(SAMPLEINDEX smp = 1; smp <= 15; smp++) + if(loadFlags & loadSampleData) { - // Looped samples in (Ultimate) Soundtracker seem to ignore all sample data before the actual loop start. - // This avoids the clicks in the first sample of pretend.mod by Karsten Obarski. - file.Skip(Samples[smp].nLoopStart); - Samples[smp].nLength -= Samples[smp].nLoopStart; - Samples[smp].nLoopEnd -= Samples[smp].nLoopStart; - Samples[smp].nLoopStart = 0; - MODSampleHeader::GetSampleFormat().ReadSample(Samples[smp], file); + for(SAMPLEINDEX smp = 1; smp <= 15; smp++) + { + // Looped samples in (Ultimate) Soundtracker seem to ignore all sample data before the actual loop start. + // This avoids the clicks in the first sample of pretend.mod by Karsten Obarski. + file.Skip(Samples[smp].nLoopStart); + Samples[smp].nLength -= Samples[smp].nLoopStart; + Samples[smp].nLoopEnd -= Samples[smp].nLoopStart; + Samples[smp].nLoopStart = 0; + MODSampleHeader::GetSampleFormat().ReadSample(Samples[smp], file); + } } return true; Modified: trunk/OpenMPT/soundlib/Load_mt2.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_mt2.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/Load_mt2.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -216,8 +216,8 @@ } -bool CSoundFile::ReadMT2(LPCBYTE lpStream, DWORD dwMemLength) -//----------------------------------------------------------- +bool CSoundFile::ReadMT2(LPCBYTE lpStream, DWORD dwMemLength, ModLoadingFlags loadFlags) +//-------------------------------------------------------------------------------------- { MT2FILEHEADER *pfh = (MT2FILEHEADER *)lpStream; DWORD dwMemPos, dwDrumDataPos, dwExtraDataPos; @@ -229,7 +229,13 @@ if ((!lpStream) || (dwMemLength < sizeof(MT2FILEHEADER)) || (pfh->dwMT20 != 0x3032544D) || (pfh->wVersion < 0x0200) || (pfh->wVersion >= 0x0300) - || (pfh->wChannels < 1) || (pfh->wChannels > MAX_BASECHANNELS)) return false; + || (pfh->wChannels < 1) || (pfh->wChannels > MAX_BASECHANNELS)) + { + return false; + } else if(loadFlags == onlyVerifyHeader) + { + return true; + } pdd = NULL; InitializeGlobals(); @@ -314,7 +320,7 @@ dwMemPos += 6; if (dwMemPos + wDataLen > dwMemLength) break; UINT nLines = pmp->wLines; - if ((iPat < MAX_PATTERNS) && (nLines > 0) && (nLines <= MAX_PATTERN_ROWS)) + if ((iPat < MAX_PATTERNS) && (nLines > 0) && (nLines <= MAX_PATTERN_ROWS) && (loadFlags & loadPatternData)) { #ifdef MT2DEBUG Log("Pattern #%d @%04X: %d lines, %d bytes\n", iPat, dwMemPos-6, nLines, pmp->wDataLen); @@ -614,6 +620,10 @@ #ifdef MT2DEBUG Log("Loading sample data at offset 0x%08X\n", dwMemPos); #endif + if(!(loadFlags & loadSampleData)) + { + return true; + } for (UINT iData=0; iData<256; iData++) if ((iData < m_nSamples) && (SampleMap[iData])) { MT2SAMPLE *pms = SampleMap[iData]; Modified: trunk/OpenMPT/soundlib/Load_mtm.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_mtm.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/Load_mtm.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -97,8 +97,8 @@ #endif -bool CSoundFile::ReadMTM(FileReader &file) -//---------------------------------------- +bool CSoundFile::ReadMTM(FileReader &file, ModLoadingFlags loadFlags) +//------------------------------------------------------------------- { file.Rewind(); MTMFileHeader fileHeader; @@ -113,6 +113,9 @@ || file.BytesLeft() < sizeof(MTMSampleHeader) * fileHeader.numSamples + 128 + 192 * fileHeader.numTracks + 64 * (fileHeader.lastPattern + 1) + fileHeader.commentSize) { return false; + } else if(loadFlags == onlyVerifyHeader) + { + return true; } InitializeGlobals(); @@ -147,7 +150,7 @@ for(PATTERNINDEX pat = 0; pat <= fileHeader.lastPattern; pat++) { - if(Patterns.Insert(pat, rowsPerPat)) + if(!(loadFlags & loadPatternData) || Patterns.Insert(pat, rowsPerPat)) { break; } @@ -195,14 +198,17 @@ } // Reading Samples - for(SAMPLEINDEX smp = 1; smp <= GetNumSamples(); smp++) + if(loadFlags & loadSampleData) { - SampleIO( - Samples[smp].uFlags[CHN_16BIT] ? SampleIO::_16bit : SampleIO::_8bit, - SampleIO::mono, - SampleIO::littleEndian, - SampleIO::unsignedPCM) - .ReadSample(Samples[smp], file); + for(SAMPLEINDEX smp = 1; smp <= GetNumSamples(); smp++) + { + SampleIO( + Samples[smp].uFlags[CHN_16BIT] ? SampleIO::_16bit : SampleIO::_8bit, + SampleIO::mono, + SampleIO::littleEndian, + SampleIO::unsignedPCM) + .ReadSample(Samples[smp], file); + } } m_nMinPeriod = 64; Modified: trunk/OpenMPT/soundlib/Load_okt.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_okt.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/Load_okt.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -279,8 +279,8 @@ } -bool CSoundFile::ReadOKT(FileReader &file) -//---------------------------------------- +bool CSoundFile::ReadOKT(FileReader &file, ModLoadingFlags loadFlags) +//------------------------------------------------------------------- { file.Rewind(); if(!file.ReadMagic("OKTASONG")) @@ -332,6 +332,11 @@ ChnSettings[m_nChannels].Reset(); ChnSettings[m_nChannels++].nPan = (((nChn & 3) == 1) || ((nChn & 3) == 2)) ? 0xC0 : 0x40; } + + if(loadFlags == onlyVerifyHeader) + { + return true; + } break; case OktIffChunk::idSAMP: @@ -404,19 +409,22 @@ } // Read patterns - for(PATTERNINDEX nPat = 0; nPat < patternChunks.size(); nPat++) + if(loadFlags & loadPatternData) { - if(patternChunks[nPat].GetLength() > 0) - ReadOKTPattern(patternChunks[nPat], nPat, *this); - else - Patterns.Insert(nPat, 64); // invent empty pattern + for(PATTERNINDEX nPat = 0; nPat < patternChunks.size(); nPat++) + { + if(patternChunks[nPat].GetLength() > 0) + ReadOKTPattern(patternChunks[nPat], nPat, *this); + else + Patterns.Insert(nPat, 64); // invent empty pattern + } } // Read samples size_t nFileSmp = 0; for(SAMPLEINDEX nSmp = 1; nSmp < m_nSamples; nSmp++) { - if(nFileSmp >= sampleChunks.size()) + if(nFileSmp >= sampleChunks.size() || !(loadFlags & loadSampleData)) break; ModSample &mptSample = Samples[nSmp]; Modified: trunk/OpenMPT/soundlib/Load_psm.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_psm.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/Load_psm.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -266,8 +266,8 @@ } -bool CSoundFile::ReadPSM(FileReader &file) -//---------------------------------------- +bool CSoundFile::ReadPSM(FileReader &file, ModLoadingFlags loadFlags) +//------------------------------------------------------------------- { file.Rewind(); PSMFileHeader fileHeader; @@ -284,6 +284,9 @@ || fileHeader.fileInfoID != PSMFileHeader::magicFILE) // "FILE" { return false; + } else if(loadFlags == onlyVerifyHeader) + { + return true; } // Yep, this seems to be a valid file. @@ -589,46 +592,49 @@ subsongs.push_back(subsong); } - // // DSMP - Samples - vector<FileReader> sampleChunks = chunks.GetAllChunks(PSMChunk::idDSMP); - for(vector<FileReader>::iterator sampleIter = sampleChunks.begin(); sampleIter != sampleChunks.end(); sampleIter++) + // DSMP - Samples + if(loadFlags & loadSampleData) { - FileReader chunk(*sampleIter); - if(!newFormat) + vector<FileReader> sampleChunks = chunks.GetAllChunks(PSMChunk::idDSMP); + for(vector<FileReader>::iterator sampleIter = sampleChunks.begin(); sampleIter != sampleChunks.end(); sampleIter++) { - // Original header - PSMOldSampleHeader sampleHeader; - if(!chunk.ReadConvertEndianness(sampleHeader)) + FileReader chunk(*sampleIter); + if(!newFormat) { - continue; - } + // Original header + PSMOldSampleHeader sampleHeader; + if(!chunk.ReadConvertEndianness(sampleHeader)) + { + continue; + } - SAMPLEINDEX smp = static_cast<SAMPLEINDEX>(sampleHeader.sampleNumber + 1); - if(smp < MAX_SAMPLES) - { - m_nSamples = MAX(m_nSamples, smp); - StringFixer::ReadString<StringFixer::nullTerminated>(m_szNames[smp], sampleHeader.sampleName); + SAMPLEINDEX smp = static_cast<SAMPLEINDEX>(sampleHeader.sampleNumber + 1); + if(smp < MAX_SAMPLES) + { + m_nSamples = MAX(m_nSamples, smp); + StringFixer::ReadString<StringFixer::nullTerminated>(m_szNames[smp], sampleHeader.sampleName); - sampleHeader.ConvertToMPT(Samples[smp]); - sampleHeader.GetSampleFormat().ReadSample(Samples[smp], chunk); - } - } else - { - // Sinaria uses a slightly different sample header - PSMNewSampleHeader sampleHeader; - if(!chunk.ReadConvertEndianness(sampleHeader)) + sampleHeader.ConvertToMPT(Samples[smp]); + sampleHeader.GetSampleFormat().ReadSample(Samples[smp], chunk); + } + } else { - continue; - } + // Sinaria uses a slightly different sample header + PSMNewSampleHeader sampleHeader; + if(!chunk.ReadConvertEndianness(sampleHeader)) + { + continue; + } - SAMPLEINDEX smp = static_cast<SAMPLEINDEX>(sampleHeader.sampleNumber + 1); - if(smp < MAX_SAMPLES) - { - m_nSamples = MAX(m_nSamples, smp); - StringFixer::ReadString<StringFixer::nullTerminated>(m_szNames[smp], sampleHeader.sampleName); + SAMPLEINDEX smp = static_cast<SAMPLEINDEX>(sampleHeader.sampleNumber + 1); + if(smp < MAX_SAMPLES) + { + m_nSamples = MAX(m_nSamples, smp); + StringFixer::ReadString<StringFixer::nullTerminated>(m_szNames[smp], sampleHeader.sampleName); - sampleHeader.ConvertToMPT(Samples[smp]); - sampleHeader.GetSampleFormat().ReadSample(Samples[smp], chunk); + sampleHeader.ConvertToMPT(Samples[smp]); + sampleHeader.GetSampleFormat().ReadSample(Samples[smp], chunk); + } } } } @@ -645,6 +651,11 @@ ChnSettings[chn].dwFlags.set(CHN_SURROUND, subsongs[0].channelSurround[chn]); } + if(!(loadFlags & loadPatternData)) + { + return true; + } + // Now that we know the number of channels, we can go through all the patterns. // This is a bit stupid since we will even read duplicate patterns twice, but hey, we do this just once... so who cares? PATTERNINDEX pat = 0; @@ -1122,18 +1133,15 @@ #endif -bool CSoundFile::ReadPSM16(FileReader &file) -//------------------------------------------ +bool CSoundFile::ReadPSM16(FileReader &file, ModLoadingFlags loadFlags) +//--------------------------------------------------------------------- { file.Rewind(); + + // Is it a valid PSM16 file? PSM16FileHeader fileHeader; - if(!file.ReadConvertEndianness(fileHeader)) - { - return false; - } - - // Check header - if(fileHeader.formatID != PSM16FileHeader::magicPSM_ // "PSM\xFE" + if(!file.ReadConvertEndianness(fileHeader) + || fileHeader.formatID != PSM16FileHeader::magicPSM_ // "PSM\xFE" || fileHeader.lineEnd != 0x1A || (fileHeader.formatVersion != 0x10 && fileHeader.formatVersion != 0x01) // why is this sometimes 0x01? || fileHeader.patternVersion != 0 // 255ch pattern version not supported (did anyone use this?) @@ -1141,6 +1149,9 @@ || std::max(fileHeader.numChannelsPlay, fileHeader.numChannelsReal) == 0) { return false; + } else if(loadFlags == onlyVerifyHeader) + { + return true; } // Seems to be valid! @@ -1200,6 +1211,10 @@ } // Read patterns + if(!(loadFlags & loadPatternData)) + { + return true; + } if(fileHeader.patOffset > 4 && file.Seek(fileHeader.patOffset - 4) && file.ReadUint32LE() == PSM16FileHeader::idPPAT) { for(PATTERNINDEX pat = 0; pat < fileHeader.numPatterns; pat++) Modified: trunk/OpenMPT/soundlib/Load_ptm.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_ptm.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/Load_ptm.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -64,8 +64,8 @@ #endif -bool CSoundFile::ReadPTM(const BYTE *lpStream, const DWORD dwMemLength) -//--------------------------------------------------------------------- +bool CSoundFile::ReadPTM(const BYTE *lpStream, const DWORD dwMemLength, ModLoadingFlags loadFlags) +//------------------------------------------------------------------------------------------------ { if(lpStream == nullptr || dwMemLength < sizeof(PTMFILEHEADER)) return false; @@ -91,7 +91,13 @@ || (pfh.norders > 256) || (!pfh.norders) || (!pfh.nsamples) || (pfh.nsamples > 255) || (!pfh.npatterns) || (pfh.npatterns > 128) - || (sizeof(PTMFILEHEADER) + pfh.nsamples * sizeof(PTMSAMPLE) >= dwMemLength)) return false; + || (sizeof(PTMFILEHEADER) + pfh.nsamples * sizeof(PTMSAMPLE) >= dwMemLength)) + { + return false; + } else if(loadFlags == onlyVerifyHeader) + { + return true; + } StringFixer::ReadString<StringFixer::maybeNullTerminated>(m_szNames[0], pfh.songname); @@ -144,7 +150,7 @@ sample.nLoopStart /= 2; sample.nLoopEnd /= 2; } - if(sample.nLength && samplepos && samplepos < dwMemLength) + if(sample.nLength && samplepos && samplepos < dwMemLength && (loadFlags & loadSampleData)) { FileReader chunk(lpStream + samplepos, dwMemLength - samplepos); sampleIO.ReadSample(sample, chunk); @@ -152,6 +158,10 @@ } } // Reading Patterns + if(!(loadFlags && loadPatternData)) + { + return true; + } for (UINT ipat=0; ipat<pfh.npatterns; ipat++) { dwMemPos = ((UINT)pfh.patseg[ipat]) << 4; Modified: trunk/OpenMPT/soundlib/Load_s3m.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_s3m.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/Load_s3m.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -424,23 +424,23 @@ }; -bool CSoundFile::ReadS3M(FileReader &file) -//---------------------------------------- +bool CSoundFile::ReadS3M(FileReader &file, ModLoadingFlags loadFlags) +//------------------------------------------------------------------- { file.Rewind(); + // Is it a valid S3M file? S3MFileHeader fileHeader; - if(!file.ReadConvertEndianness(fileHeader) || !file.CanRead(fileHeader.ordNum + (fileHeader.smpNum + fileHeader.patNum) * 2)) - { - return false; - } - - // Is it a valid S3M file? - if(fileHeader.magic != S3MFileHeader::idSCRM + if(!file.ReadConvertEndianness(fileHeader) + || !file.CanRead(fileHeader.ordNum + (fileHeader.smpNum + fileHeader.patNum) * 2) + || fileHeader.magic != S3MFileHeader::idSCRM || fileHeader.fileType != S3MFileHeader::idS3MType || (fileHeader.formatVersion != S3MFileHeader::oldVersion && fileHeader.formatVersion != S3MFileHeader::newVersion)) { return false; + } else if(loadFlags == onlyVerifyHeader) + { + return true; } InitializeGlobals(); @@ -598,7 +598,7 @@ const uint32 sampleOffset = (sampleHeader.dataPointer[1] << 4) | (sampleHeader.dataPointer[2] << 12) | (sampleHeader.dataPointer[0] << 20); - if(sampleHeader.length != 0 && file.Seek(sampleOffset)) + if((loadFlags & loadSampleData) && sampleHeader.length != 0 && file.Seek(sampleOffset)) { sampleHeader.GetSampleFormat((fileHeader.formatVersion == S3MFileHeader::oldVersion)).ReadSample(Samples[smp + 1], file); } @@ -620,6 +620,10 @@ int zxxCountRight = 0, zxxCountLeft = 0; // Reading patterns + if(!(loadFlags & loadPatternData)) + { + return true; + } const PATTERNINDEX readPatterns = MIN(fileHeader.patNum, MAX_PATTERNS); for(PATTERNINDEX pat = 0; pat < readPatterns; pat++) { Modified: trunk/OpenMPT/soundlib/Load_stm.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_stm.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/Load_stm.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -112,8 +112,8 @@ #endif -bool CSoundFile::ReadSTM(FileReader &file) -//---------------------------------------- +bool CSoundFile::ReadSTM(FileReader &file, ModLoadingFlags loadFlags) +//------------------------------------------------------------------- { file.Rewind(); @@ -125,6 +125,9 @@ && _strnicmp(fileHeader.trackername, "BMOD2STM", 8))) { return false; + } else if(loadFlags == onlyVerifyHeader) + { + return true; } StringFixer::ReadString<StringFixer::maybeNullTerminated>(m_szNames[0], fileHeader.songname); @@ -171,8 +174,9 @@ { STMPatternEntry patternData[64 * 4]; - if(Patterns.Insert(pat, 64) || !file.ReadArray(patternData)) + if(!(loadFlags & loadPatternData) || Patterns.Insert(pat, 64) || !file.ReadArray(patternData)) { + file.Skip(sizeof(patternData)); continue; } @@ -272,27 +276,31 @@ } // Reading Samples - const SampleIO sampleIO( - SampleIO::_8bit, - SampleIO::mono, - SampleIO::littleEndian, - SampleIO::signedPCM); + if(loadFlags & loadSampleData) + { + const SampleIO sampleIO( + SampleIO::_8bit, + SampleIO::mono, + SampleIO::littleEndian, + SampleIO::signedPCM); - for(SAMPLEINDEX smp = 1; smp <= 31; smp++) - { - ModSample &sample = Samples[smp]; - if(sample.nLength) + for(SAMPLEINDEX smp = 1; smp <= 31; smp++) { - //size_t sampleOffset = fileHeader.samples[smp - 1].offset << 4; - //if(sampleOffset > sizeof(STMPatternEntry) && sampleOffset < file.GetLength()) - //{ - // file.Seek(sampleOffset); - //} else + ModSample &sample = Samples[smp]; + if(sample.nLength) { - file.Seek((file.GetPosition() + 15) & (~15)); + //size_t sampleOffset = fileHeader.samples[smp - 1].offset << 4; + //if(sampleOffset > sizeof(STMPatternEntry) && sampleOffset < file.GetLength()) + //{ + // file.Seek(sampleOffset); + //} else + { + file.Seek((file.GetPosition() + 15) & (~15)); + } + sampleIO.ReadSample(sample, file); } - sampleIO.ReadSample(sample, file); } } + return true; } Modified: trunk/OpenMPT/soundlib/Load_ult.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_ult.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/Load_ult.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -374,8 +374,8 @@ }; -bool CSoundFile::ReadUlt(FileReader &file) -//---------------------------------------- +bool CSoundFile::ReadUlt(FileReader &file, ModLoadingFlags loadFlags) +//------------------------------------------------------------------- { file.Rewind(); UltFileHeader fileHeader; @@ -387,6 +387,9 @@ || memcmp(fileHeader.signature, "MAS_UTrack_V00", sizeof(fileHeader.signature)) != 0) { return false; + } else if(loadFlags == onlyVerifyHeader) + { + return true; } InitializeGlobals(); @@ -476,14 +479,17 @@ // Post-fix some effects. Patterns.ForEachModCommand(PostFixUltCommands(GetNumChannels())); - for(SAMPLEINDEX smp = 1; smp <= GetNumSamples(); smp++) + if(loadFlags & loadSampleData) { - SampleIO( - Samples[smp].uFlags[CHN_16BIT] ? SampleIO::_16bit : SampleIO::_8bit, - SampleIO::mono, - SampleIO::littleEndian, - SampleIO::signedPCM) - .ReadSample(Samples[smp], file); + for(SAMPLEINDEX smp = 1; smp <= GetNumSamples(); smp++) + { + SampleIO( + Samples[smp].uFlags[CHN_16BIT] ? SampleIO::_16bit : SampleIO::_8bit, + SampleIO::mono, + SampleIO::littleEndian, + SampleIO::signedPCM) + .ReadSample(Samples[smp], file); + } } return true; } \ No newline at end of file Modified: trunk/OpenMPT/soundlib/Load_umx.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_umx.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/Load_umx.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -159,8 +159,8 @@ } -bool CSoundFile::ReadUMX(FileReader &file) -//---------------------------------------- +bool CSoundFile::ReadUMX(FileReader &file, ModLoadingFlags loadFlags) +//------------------------------------------------------------------- { file.Rewind(); UMXFileHeader fileHeader; @@ -229,6 +229,9 @@ if(!isMusic && !isSound) { continue; + } else if(loadFlags == onlyVerifyHeader) + { + return true; } FileReader chunk = file.GetChunk(objOffset, objSize); @@ -275,15 +278,15 @@ if(isMusic) { // Read as module - if(ReadIT(fileChunk) - || ReadXM(fileChunk) - || ReadS3M(fileChunk) - || ReadWav(fileChunk) - || ReadSTM(fileChunk) - || Read669(fileChunk) - || ReadFAR(fileChunk) - || ReadMod(fileChunk) - || ReadM15(fileChunk)) + if(ReadIT(fileChunk, loadFlags) + || ReadXM(fileChunk, loadFlags) + || ReadS3M(fileChunk, loadFlags) + || ReadWav(fileChunk, loadFlags) + || ReadSTM(fileChunk, loadFlags) + || Read669(fileChunk, loadFlags) + || ReadFAR(fileChunk, loadFlags) + || ReadMod(fileChunk, loadFlags) + || ReadM15(fileChunk, loadFlags)) { return true; } Modified: trunk/OpenMPT/soundlib/Load_wav.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_wav.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/Load_wav.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -40,8 +40,8 @@ } -bool CSoundFile::ReadWav(FileReader &file) -//---------------------------------------- +bool CSoundFile::ReadWav(FileReader &file, ModLoadingFlags loadFlags) +//------------------------------------------------------------------- { WAVReader wavFile(file); @@ -53,6 +53,9 @@ || (wavFile.GetSampleFormat() != WAVFormatChunk::fmtPCM && wavFile.GetSampleFormat() != WAVFormatChunk::fmtFloat)) { return false; + } else if(loadFlags == onlyVerifyHeader) + { + return true; } InitializeGlobals(); Modified: trunk/OpenMPT/soundlib/Load_xm.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_xm.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/Load_xm.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -247,8 +247,8 @@ }; -bool CSoundFile::ReadXM(FileReader &file) -//--------------------------------------- +bool CSoundFile::ReadXM(FileReader &file, ModLoadingFlags loadFlags) +//------------------------------------------------------------------ { file.Rewind(); @@ -260,6 +260,9 @@ || !file.CanRead(fileHeader.orders)) { return false; + } else if(loadFlags == onlyVerifyHeader) + { + return true; } InitializeGlobals(); Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2013-04-27 23:06:51 UTC (rev 1988) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2013-04-27 23:45:18 UTC (rev 1989) @@ -509,13 +509,13 @@ #ifdef MODPLUG_TRACKER -BOOL CSoundFile::Create(FileReader filereader, CModDoc *pModDoc) -//-------------------------------------------------------------- +BOOL CSoundFile::Create(FileReader file, ModLoadingFlags loadFlags, CModDoc *pModDoc) +//----------------------------------... [truncated message content] |