From: <sv...@op...> - 2024-07-29 14:02:27
|
Author: sagamusix Date: Mon Jul 29 16:02:12 2024 New Revision: 21302 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=21302 Log: Merged revision(s) 21301 from trunk/OpenMPT: [Imp] Mod Conversion: Enable sustain loop on last point when converting a volume envelope from XM that has no loops set (https://bugs.openmpt.org/view.php?id=1805). ........ Modified: branches/OpenMPT-1.31/ (props changed) branches/OpenMPT-1.31/soundlib/ModInstrument.cpp branches/OpenMPT-1.31/soundlib/ModInstrument.h Modified: branches/OpenMPT-1.31/soundlib/ModInstrument.cpp ============================================================================== --- branches/OpenMPT-1.31/soundlib/ModInstrument.cpp Mon Jul 29 16:00:25 2024 (r21301) +++ branches/OpenMPT-1.31/soundlib/ModInstrument.cpp Mon Jul 29 16:02:12 2024 (r21302) @@ -41,6 +41,12 @@ // So we have to disable the sustain loop if it was behind the normal loop. dwFlags.reset(ENV_SUSTAIN); } + if(!dwFlags.test_all(ENV_LOOP | ENV_SUSTAIN)) + { + // XM has no automatic fade-out behaviour at the end of the envelope. + dwFlags.set(ENV_SUSTAIN); + nSustainStart = nSustainEnd = LastPoint(); + } // XM -> IT / MPTM: Shorten loop by one tick by inserting bogus point if(nLoopEnd > nLoopStart && dwFlags[ENV_LOOP] && nLoopEnd < size()) @@ -73,11 +79,11 @@ if(empty()) return 0; - uint32 pt = size() - 1u; + uint32 pt = LastPoint(); const int32 ENV_PRECISION = 1 << 16; // Checking where current 'tick' is relative to the envelope points. - for(uint32 i = 0; i < size() - 1u; i++) + for(uint32 i = 0; i < LastPoint(); i++) { if (position <= at(i).tick) { @@ -129,12 +135,12 @@ it->tick = std::max(it->tick, (it - 1)->tick); LimitMax(it->value, maxValue); } - LimitMax(nLoopEnd, static_cast<decltype(nLoopEnd)>(size() - 1)); + LimitMax(nLoopEnd, LastPoint()); LimitMax(nLoopStart, nLoopEnd); - LimitMax(nSustainEnd, static_cast<decltype(nSustainEnd)>(size() - 1)); + LimitMax(nSustainEnd, LastPoint()); LimitMax(nSustainStart, nSustainEnd); if(nReleaseNode != ENV_RELEASE_NODE_UNSET) - LimitMax(nReleaseNode, static_cast<decltype(nReleaseNode)>(size() - 1)); + LimitMax(nReleaseNode, LastPoint()); } else { nLoopStart = 0; Modified: branches/OpenMPT-1.31/soundlib/ModInstrument.h ============================================================================== --- branches/OpenMPT-1.31/soundlib/ModInstrument.h Mon Jul 29 16:00:25 2024 (r21301) +++ branches/OpenMPT-1.31/soundlib/ModInstrument.h Mon Jul 29 16:02:12 2024 (r21302) @@ -61,6 +61,8 @@ uint32 size() const { return static_cast<uint32>(std::vector<EnvelopeNode>::size()); } + uint8 LastPoint() const { return static_cast<uint8>(std::max(size(), uint32(1)) - 1); } + using std::vector<EnvelopeNode>::push_back; void push_back(EnvelopeNode::tick_t tick, EnvelopeNode::value_t value) { emplace_back(tick, value); } }; |