From: <sv...@op...> - 2024-03-03 16:11:49
|
Author: sagamusix Date: Sun Mar 3 17:11:37 2024 New Revision: 20220 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=20220 Log: [Imp/Fix] Limit insertion of multiple patterns so that patterns at the end of the sequence no longer disappear when reaching the format limit. Modified: trunk/OpenMPT/soundlib/ModSequence.cpp trunk/OpenMPT/soundlib/ModSequence.h Modified: trunk/OpenMPT/soundlib/ModSequence.cpp ============================================================================== --- trunk/OpenMPT/soundlib/ModSequence.cpp Sun Mar 3 16:44:06 2024 (r20219) +++ trunk/OpenMPT/soundlib/ModSequence.cpp Sun Mar 3 17:11:37 2024 (r20220) @@ -101,6 +101,17 @@ } +ORDERINDEX ModSequence::GetRemainingCapacity() const noexcept +{ + const auto &specs = m_sndFile.GetModSpecifications(); + const ORDERINDEX length = GetLengthTailTrimmed(); + if(length >= specs.ordersMax) + return 0; + else + return specs.ordersMax - length; +} + + ORDERINDEX ModSequence::GetNextOrderIgnoringSkips(const ORDERINDEX start) const noexcept { if(empty()) @@ -186,10 +197,10 @@ ORDERINDEX ModSequence::insert(ORDERINDEX pos, ORDERINDEX count, PATTERNINDEX fill) { const auto ordersMax = m_sndFile.GetModSpecifications().ordersMax; + // 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()); if(pos >= ordersMax || GetLengthTailTrimmed() >= ordersMax || count == 0) return 0; - // Limit number of orders to be inserted so that we don't exceed the format limit. - LimitMax(count, static_cast<ORDERINDEX>(ordersMax - pos)); reserve(std::max(pos, GetLength()) + count); // Inserting past the end of the container? if(pos > size()) Modified: trunk/OpenMPT/soundlib/ModSequence.h ============================================================================== --- trunk/OpenMPT/soundlib/ModSequence.h Sun Mar 3 16:44:06 2024 (r20219) +++ trunk/OpenMPT/soundlib/ModSequence.h Sun Mar 3 17:11:37 2024 (r20220) @@ -48,6 +48,8 @@ ORDERINDEX GetLengthTailTrimmed() const noexcept; // 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() const noexcept; // Replaces order list with 'newSize' copies of 'pat'. void assign(ORDERINDEX newSize, PATTERNINDEX pat); |