From: <sv...@op...> - 2024-06-02 15:10:43
|
Author: sagamusix Date: Sun Jun 2 17:10:31 2024 New Revision: 20909 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=20909 Log: [Fix] FTM: Allow order list to grow larger than 128 items (MOD limit) when evaluating pattern loops. Modified: trunk/OpenMPT/soundlib/Load_ftm.cpp trunk/OpenMPT/soundlib/ModSequence.cpp trunk/OpenMPT/soundlib/ModSequence.h Modified: trunk/OpenMPT/soundlib/Load_ftm.cpp ============================================================================== --- trunk/OpenMPT/soundlib/Load_ftm.cpp Sun Jun 2 16:50:19 2024 (r20908) +++ trunk/OpenMPT/soundlib/Load_ftm.cpp Sun Jun 2 17:10:31 2024 (r20909) @@ -448,7 +448,7 @@ const std::vector<PATTERNINDEX> ordersToCopy(Order().begin() + start, Order().begin() + ord + 1); for(uint8 rep = 1; rep < loopStart[activeLoops].second && canAddMore; rep++) { - if(ORDERINDEX inserted = Order().insert(ord + 1, mpt::as_span(ordersToCopy)); inserted == ordersToCopy.size()) + if(ORDERINDEX inserted = Order().insert(ord + 1, mpt::as_span(ordersToCopy), false); inserted == ordersToCopy.size()) ordersInserted += inserted; else canAddMore = false; Modified: trunk/OpenMPT/soundlib/ModSequence.cpp ============================================================================== --- trunk/OpenMPT/soundlib/ModSequence.cpp Sun Jun 2 16:50:19 2024 (r20908) +++ trunk/OpenMPT/soundlib/ModSequence.cpp Sun Jun 2 17:10:31 2024 (r20909) @@ -112,16 +112,16 @@ } -ORDERINDEX ModSequence::GetRemainingCapacity(ORDERINDEX startingFrom) const noexcept +ORDERINDEX ModSequence::GetRemainingCapacity(ORDERINDEX startingFrom, bool enforceFormatLimits) const noexcept { - const auto &specs = m_sndFile.GetModSpecifications(); + const ORDERINDEX ordersMax = enforceFormatLimits ? m_sndFile.GetModSpecifications().ordersMax : MAX_ORDERS; ORDERINDEX length = GetLengthTailTrimmed(); if(startingFrom != ORDERINDEX_INVALID && startingFrom > length) length = startingFrom; - if(length >= specs.ordersMax) + if(length >= ordersMax) return 0; else - return specs.ordersMax - length; + return ordersMax - length; } @@ -219,11 +219,11 @@ } -ORDERINDEX ModSequence::insert(ORDERINDEX pos, ORDERINDEX count, PATTERNINDEX fill) +ORDERINDEX ModSequence::insert(ORDERINDEX pos, ORDERINDEX count, PATTERNINDEX fill, bool enforceFormatLimits) { - const auto ordersMax = m_sndFile.GetModSpecifications().ordersMax; + const ORDERINDEX ordersMax = enforceFormatLimits ? m_sndFile.GetModSpecifications().ordersMax : MAX_ORDERS; // Limit number of orders to be inserted so that we don't exceed the format limit or drop items at the end of the order list. - LimitMax(count, GetRemainingCapacity(pos)); + LimitMax(count, GetRemainingCapacity(pos, enforceFormatLimits)); if(pos >= ordersMax || GetLengthTailTrimmed() >= ordersMax || count == 0) return 0; reserve(std::max(pos, GetLength()) + count); @@ -238,10 +238,10 @@ } -ORDERINDEX ModSequence::insert(ORDERINDEX pos, const mpt::span<const PATTERNINDEX> orders) +ORDERINDEX ModSequence::insert(ORDERINDEX pos, const mpt::span<const PATTERNINDEX> orders, bool enforceFormatLimits) { MPT_ASSERT(reinterpret_cast<uintptr_t>(orders.data()) < reinterpret_cast<uintptr_t>(data()) || reinterpret_cast<uintptr_t>(orders.data()) > reinterpret_cast<uintptr_t>(data() + size())); - ORDERINDEX count = insert(pos, mpt::saturate_cast<ORDERINDEX>(orders.size())); + ORDERINDEX count = insert(pos, mpt::saturate_cast<ORDERINDEX>(orders.size()), 0, enforceFormatLimits); std::copy(orders.begin(), orders.begin() + count, begin() + pos); return count; } Modified: trunk/OpenMPT/soundlib/ModSequence.h ============================================================================== --- trunk/OpenMPT/soundlib/ModSequence.h Sun Jun 2 16:50:19 2024 (r20908) +++ trunk/OpenMPT/soundlib/ModSequence.h Sun Jun 2 17:10:31 2024 (r20909) @@ -51,7 +51,7 @@ // Returns length of sequence stopping counting on first '---' (or at the end of sequence). ORDERINDEX GetLengthFirstEmpty() const noexcept; // Returns amount of patterns that can be added at the end of the order list before reaching the current format's limits. - ORDERINDEX GetRemainingCapacity(ORDERINDEX startingFrom = ORDERINDEX_INVALID) const noexcept; + ORDERINDEX GetRemainingCapacity(ORDERINDEX startingFrom = ORDERINDEX_INVALID, bool enforceFormatLimits = true) const noexcept; // Replaces order list with 'newSize' copies of 'pat'. void assign(ORDERINDEX newSize, PATTERNINDEX pat); @@ -59,9 +59,9 @@ // Inserts 'count' orders starting from 'pos' using 'fill' as the pattern index for all inserted orders. // Sequence will automatically grow if needed and if it can't grow enough, some tail orders will be discarded. // Return: Number of orders inserted (up to 'count' many). - ORDERINDEX insert(ORDERINDEX pos, ORDERINDEX count) { return insert(pos, count, GetInvalidPatIndex()); } - ORDERINDEX insert(ORDERINDEX pos, ORDERINDEX count, PATTERNINDEX fill); - ORDERINDEX insert(ORDERINDEX pos, const mpt::span<const PATTERNINDEX> orders); + ORDERINDEX insert(ORDERINDEX pos, ORDERINDEX count) { return insert(pos, count, GetInvalidPatIndex(), true); } + ORDERINDEX insert(ORDERINDEX pos, ORDERINDEX count, PATTERNINDEX fill, bool enforceFormatLimits = true); + ORDERINDEX insert(ORDERINDEX pos, const mpt::span<const PATTERNINDEX> orders, bool enforceFormatLimits = true); void push_back() { push_back(GetInvalidPatIndex()); } void push_back(PATTERNINDEX pat) { if(GetLength() < MAX_ORDERS) std::vector<PATTERNINDEX>::push_back(pat); } |