From 3dc3e8a9fec1caddb02018c809a18d138b9b5684 Mon Sep 17 00:00:00 2001 From: Johannes Schultz Date: Sun, 1 Dec 2024 11:41:22 +0000 Subject: [PATCH] Merged revision(s) 22056, 22377 from trunk/OpenMPT: [Imp] Warn when Startrekker AM companion file for synthesized instruments is most likely missing. ........ [Imp] Allow Startrekker AM external sample check to also work for libopenmpt. ........ Merged revision(s) 22377 from trunk/OpenMPT: [Imp] Allow Startrekker AM external sample check to also work for libopenmpt. ........ git-svn-id: https://source.openmpt.org/svn/openmpt/branches/OpenMPT-1.28@22385 56274372-70c3-4bfc-bfc3-4c3a0b034d27 --- soundlib/Load_mod.cpp | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/soundlib/Load_mod.cpp b/soundlib/Load_mod.cpp index 29d39579995..649b67b2ea3 100644 --- a/soundlib/Load_mod.cpp +++ b/soundlib/Load_mod.cpp @@ -984,6 +984,7 @@ bool CSoundFile::ReadMOD(FileReader &file, ModLoadingFlags loadFlags) // Reading patterns Patterns.ResizeArray(numPatterns); + std::bitset<32> referencedSamples; for(PATTERNINDEX pat = 0; pat < numPatterns; pat++) { ModCommand *rowBase = nullptr; @@ -1091,6 +1092,8 @@ bool CSoundFile::ReadMOD(FileReader &file, ModLoadingFlags loadFlags) if(m.instr != 0) { lastInstrument[chn] = m.instr; + if(isStartrekker) + referencedSamples.set(m.instr & 0x1F); } } if(hasSpeedOnRow && hasTempoOnRow) definitelyCIA = true; @@ -1212,7 +1215,7 @@ bool CSoundFile::ReadMOD(FileReader &file, ModLoadingFlags loadFlags) m_nInstruments = 31; #endif - for(SAMPLEINDEX smp = 1; smp <= m_nInstruments; smp++) + for(SAMPLEINDEX smp = 1; smp <= GetNumInstruments(); smp++) { // For Startrekker AM synthesis, we need instrument envelopes. ModInstrument *ins = AllocateInstrument(smp, smp); @@ -1233,6 +1236,33 @@ bool CSoundFile::ReadMOD(FileReader &file, ModLoadingFlags loadFlags) amData.Skip(120 - sizeof(AMInstrument)); } } +#endif // MPT_EXTERNAL_SAMPLES || MPT_BUILD_FUZZER + + if((loadFlags & loadSampleData) && isStartrekker && !m_nInstruments) + { + uint8 emptySampleReferences = 0; + for(SAMPLEINDEX smp = 1; smp <= 31; smp++) + { + if(referencedSamples[smp] && !Samples[smp].nLength) + { + if(++emptySampleReferences > 1) + { +#ifdef MPT_EXTERNAL_SAMPLES + mpt::ustring filenameHint; + if(file.GetOptionalFileName()) + { + const auto filename = file.GetOptionalFileName()->GetFilename().ToUnicode(); + filenameHint = mpt::format(U_(" ({}.nt or {}.as)"))(filename, filename); + } + AddToLog(LogWarning, mpt::format(U_("This Startrekker AM file is most likely missing its companion file{}. Synthesized instruments will not play."))(filenameHint)); +#else + AddToLog(LogWarning, U_("This appears to be a Startrekker AM file with external synthesizes instruments. External instruments are currently not supported.")); +#endif // MPT_EXTERNAL_SAMPLES + break; + } + } + } + } #endif // MPT_EXTERNAL_SAMPLES || MPT_BUILD_FUZZER // Fix VBlank MODs. Arbitrary threshold: 8 minutes (enough for "frame of mind" by Dascon...).