From: <sv...@op...> - 2024-12-10 17:23:14
|
Author: sagamusix Date: Tue Dec 10 18:23:04 2024 New Revision: 22504 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=22504 Log: [Imp] Allow FileReader::ReadArray<type, size> to work with plain C arrays, like the other overload does. [Ref] Make use of this change in TCB loader. [Mod] TCB: Import default portamento values for old files. This is a pure guess, as the only file in old format that I have doesn't even use portamento. Modified: trunk/OpenMPT/soundlib/Load_tcb.cpp trunk/OpenMPT/src/mpt/io_read/filereader.hpp Modified: trunk/OpenMPT/soundlib/Load_tcb.cpp ============================================================================== --- trunk/OpenMPT/soundlib/Load_tcb.cpp Tue Dec 10 11:14:19 2024 (r22503) +++ trunk/OpenMPT/soundlib/Load_tcb.cpp Tue Dec 10 18:23:04 2024 (r22504) @@ -92,8 +92,6 @@ const bool newFormat = fileHeader.IsNewFormat(); bool useAmigaFreqs = false; - std::array<char[8], 16> instrNames{}; - std::array<int16be, 16> specialValues{}; if(newFormat) { uint16 amigaFreqs = file.ReadUint16BE(); @@ -101,9 +99,17 @@ return false; useAmigaFreqs = amigaFreqs != 0; } - file.ReadStruct(instrNames); + const auto instrNames = file.ReadArray<char[8], 16>(); + std::array<int16be, 16> specialValues{}; if(newFormat) + { file.ReadStruct(specialValues); + } else + { + // A pure guess, the only old-format file I found doesn't even use these... + static constexpr std::array<int16, 16> defaultSpecialValues{0, 10, 30, 50, 70, 90, -10, -30, -50, -70, -90, 0, 0, 0, 0, 0}; + std::copy(defaultSpecialValues.begin(), defaultSpecialValues.end(), specialValues.begin()); + } m_nMinPeriod = useAmigaFreqs ? 113 * 4 : 92 * 4; m_nMaxPeriod = useAmigaFreqs ? 856 * 4 : 694 * 4; @@ -161,24 +167,24 @@ m_nSamples = 16; for(SAMPLEINDEX smp = 1; smp <= 16; smp++) { - ModSample &mptSample = Samples[smp]; - mptSample.Initialize(MOD_TYPE_MOD); - mptSample.nVolume = std::min(sampleHeaders1.ReadUint8(), uint8(127)) * 2; + ModSample &mptSmp = Samples[smp]; + mptSmp.Initialize(MOD_TYPE_MOD); + mptSmp.nVolume = std::min(sampleHeaders1.ReadUint8(), uint8(127)) * 2; sampleHeaders1.Skip(1); // Empty value according to docs - mptSample.nLoopStart = sampleHeaders1.ReadUint16BE(); + mptSmp.nLoopStart = sampleHeaders1.ReadUint16BE(); uint32 offset = sampleHeaders2.ReadUint32BE(); - mptSample.nLength = sampleHeaders2.ReadUint32BE(); - if(mptSample.nLoopStart && mptSample.nLoopStart < mptSample.nLength) + mptSmp.nLength = sampleHeaders2.ReadUint32BE(); + if(mptSmp.nLoopStart && mptSmp.nLoopStart < mptSmp.nLength) { - mptSample.nLoopEnd = mptSample.nLength; - mptSample.nLoopStart = mptSample.nLength - mptSample.nLoopStart; - mptSample.uFlags.set(CHN_LOOP); + mptSmp.nLoopEnd = mptSmp.nLength; + mptSmp.nLoopStart = mptSmp.nLength - mptSmp.nLoopStart; + mptSmp.uFlags.set(CHN_LOOP); } if(!useAmigaFreqs) - mptSample.nFineTune = 5 * 16; + mptSmp.nFineTune = 5 * 16; - if((loadFlags & loadSampleData) && file.Seek(sampleStart + offset)) - sampleIO.ReadSample(mptSample, file); + if((loadFlags & loadSampleData) && mptSmp.nLength > 1 && file.Seek(sampleStart + offset)) + sampleIO.ReadSample(mptSmp, file); m_szNames[smp] = mpt::String::ReadBuf(mpt::String::spacePadded, instrNames[smp - 1]); } Modified: trunk/OpenMPT/src/mpt/io_read/filereader.hpp ============================================================================== --- trunk/OpenMPT/src/mpt/io_read/filereader.hpp Tue Dec 10 11:14:19 2024 (r22503) +++ trunk/OpenMPT/src/mpt/io_read/filereader.hpp Tue Dec 10 18:23:04 2024 (r22504) @@ -267,7 +267,7 @@ bool ReadArray(TFileCursor & f, std::array<T, destSize> & destArray) { static_assert(mpt::is_binary_safe<T>::value); if (!f.CanRead(sizeof(destArray))) { - destArray.fill(T{}); + mpt::reset(destArray); return false; } f.ReadRaw(mpt::as_raw_memory(destArray)); |