From: <sag...@us...> - 2014-07-01 00:31:26
|
Revision: 4182 http://sourceforge.net/p/modplug/code/4182 Author: saga-games Date: 2014-07-01 00:31:16 +0000 (Tue, 01 Jul 2014) Log Message: ----------- [Imp] Pattern tab: Deleting and inserting items in the order list automatically adjusts playback, sequence override and play lock positions. [Ref] Unify code for deleting order list or sample selection ranges in MPTrackUtil.h [Mod] OpenMPT: Version is now 1.23.04.04 Modified Paths: -------------- trunk/OpenMPT/common/versionNumber.h trunk/OpenMPT/mptrack/Ctrl_pat.cpp trunk/OpenMPT/mptrack/Ctrl_seq.cpp trunk/OpenMPT/mptrack/MPTrackUtil.h trunk/OpenMPT/mptrack/View_smp.cpp Modified: trunk/OpenMPT/common/versionNumber.h =================================================================== --- trunk/OpenMPT/common/versionNumber.h 2014-06-30 23:56:14 UTC (rev 4181) +++ trunk/OpenMPT/common/versionNumber.h 2014-07-01 00:31:16 UTC (rev 4182) @@ -19,7 +19,7 @@ #define VER_MAJORMAJOR 1 #define VER_MAJOR 23 #define VER_MINOR 04 -#define VER_MINORMINOR 03 +#define VER_MINORMINOR 04 //Version string. For example "1.17.02.28" #define MPT_VERSION_STR VER_STRINGIZE(VER_MAJORMAJOR) "." VER_STRINGIZE(VER_MAJOR) "." VER_STRINGIZE(VER_MINOR) "." VER_STRINGIZE(VER_MINORMINOR) Modified: trunk/OpenMPT/mptrack/Ctrl_pat.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_pat.cpp 2014-06-30 23:56:14 UTC (rev 4181) +++ trunk/OpenMPT/mptrack/Ctrl_pat.cpp 2014-07-01 00:31:16 UTC (rev 4182) @@ -888,11 +888,21 @@ } success = true; - } } if(success) { + Util::InsertItem(selection.firstOrd, selection.lastOrd, m_sndFile.m_PlayState.m_nNextOrder); + if(m_sndFile.m_PlayState.m_nSeqOverride != ORDERINDEX_INVALID) + { + Util::InsertItem(selection.firstOrd, selection.lastOrd, m_sndFile.m_PlayState.m_nSeqOverride); + } + // Adjust order lock position + if(m_sndFile.m_lockOrderStart != ORDERINDEX_INVALID) + { + Util::InsertRange(selection.firstOrd, selection.lastOrd, m_sndFile.m_lockOrderStart, m_sndFile.m_lockOrderEnd); + } + m_OrderList.InvalidateRect(NULL, FALSE); m_OrderList.SetCurSel(insertWhere); Modified: trunk/OpenMPT/mptrack/Ctrl_seq.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_seq.cpp 2014-06-30 23:56:14 UTC (rev 4181) +++ trunk/OpenMPT/mptrack/Ctrl_seq.cpp 2014-07-01 00:31:16 UTC (rev 4182) @@ -1144,6 +1144,18 @@ sndFile.Order[insertEnd + i + 1] = sndFile.Order[insertEnd - insertCount + i]; } } + + Util::InsertItem(selection.firstOrd, selection.lastOrd, sndFile.m_PlayState.m_nNextOrder); + if(sndFile.m_PlayState.m_nSeqOverride != ORDERINDEX_INVALID) + { + Util::InsertItem(selection.firstOrd, selection.lastOrd, sndFile.m_PlayState.m_nSeqOverride); + } + // Adjust order lock position + if(sndFile.m_lockOrderStart != ORDERINDEX_INVALID) + { + Util::InsertRange(selection.firstOrd, selection.lastOrd, sndFile.m_lockOrderStart, sndFile.m_lockOrderEnd); + } + m_nScrollPos = std::min(ORDERINDEX(insertEnd + 1), sndFile.Order.GetLastIndex()); if(insertCount > 0) m_nScrollPos2nd = std::min(ORDERINDEX(m_nScrollPos + insertCount), sndFile.Order.GetLastIndex()); @@ -1170,7 +1182,7 @@ const OrdSelection selection = GetCurSel(true); ORDERINDEX insertPos = selection.firstOrd; - if(sndFile.Order[selection.firstOrd] != sndFile.Order.GetInvalidPatIndex()) + if(sndFile.Order[insertPos] != sndFile.Order.GetInvalidPatIndex()) { // If we're not inserting on a stop (---) index, we move on by one position. insertPos++; @@ -1180,13 +1192,24 @@ if(sndFile.Order.GetLength() < sndFile.GetModSpecifications().ordersMax) sndFile.Order.Append(); } - for(int j = sndFile.Order.GetLastIndex(); j > selection.firstOrd; j--) + for(int j = sndFile.Order.GetLastIndex(); j > insertPos; j--) sndFile.Order[j] = sndFile.Order[j - 1]; } sndFile.Order[insertPos] = sndFile.Order.GetIgnoreIndex(); + Util::InsertItem(insertPos, insertPos, sndFile.m_PlayState.m_nNextOrder); + if(sndFile.m_PlayState.m_nSeqOverride != ORDERINDEX_INVALID) + { + Util::InsertItem(insertPos, insertPos, sndFile.m_PlayState.m_nSeqOverride); + } + // Adjust order lock position + if(sndFile.m_lockOrderStart != ORDERINDEX_INVALID) + { + Util::InsertRange(insertPos, insertPos, sndFile.m_lockOrderStart, sndFile.m_lockOrderEnd); + } + InvalidateRect(NULL, FALSE); m_pModDoc.SetModified(); m_pModDoc.UpdateAllViews(NULL, HINT_MODSEQUENCE, this); @@ -1216,10 +1239,17 @@ InvalidateRect(NULL, FALSE); m_pModDoc.UpdateAllViews(NULL, HINT_MODSEQUENCE, this); - if(sndFile.m_PlayState.m_nCurrentOrder > selection.lastOrd) + Util::DeleteItem(selection.firstOrd, selection.lastOrd, sndFile.m_PlayState.m_nNextOrder); + if(sndFile.m_PlayState.m_nSeqOverride != ORDERINDEX_INVALID) { - sndFile.m_PlayState.m_nNextOrder -= selection.GetSelCount(); + Util::DeleteItem(selection.firstOrd, selection.lastOrd, sndFile.m_PlayState.m_nSeqOverride); } + + // Adjust order lock position + if(sndFile.m_lockOrderStart != ORDERINDEX_INVALID) + { + Util::DeleteRange(selection.firstOrd, selection.lastOrd, sndFile.m_lockOrderStart, sndFile.m_lockOrderEnd); + } } Modified: trunk/OpenMPT/mptrack/MPTrackUtil.h =================================================================== --- trunk/OpenMPT/mptrack/MPTrackUtil.h 2014-06-30 23:56:14 UTC (rev 4181) +++ trunk/OpenMPT/mptrack/MPTrackUtil.h 2014-07-01 00:31:16 UTC (rev 4182) @@ -29,5 +29,73 @@ }} // namespace Util::sdOs +namespace Util +{ + // Insert a range of items [insStart, insEnd], and possibly shift item fix to the left. + template<typename T> + void InsertItem(const T insStart, const T insEnd, T &fix) + { + ASSERT(insEnd >= insStart); + if(fix >= insStart) + { + fix += (insEnd - insStart + 1); + } + } + // Insert a range of items [insStart, insEnd], and possibly shift items in range [fixStart, fixEnd] to the right. + template<typename T> + void InsertRange(const T insStart, const T insEnd, T &fixStart, T &fixEnd) + { + ASSERT(insEnd >= insStart); + const T insLength = insEnd - insStart + 1; + if(fixStart >= insEnd) + { + fixStart += insLength; + } + if(fixEnd >= insEnd) + { + fixEnd += insLength; + } + } + + // Delete a range of items [delStart, delEnd], and possibly shift item fix to the left. + template<typename T> + void DeleteItem(const T delStart, const T delEnd, T &fix) + { + ASSERT(delEnd >= delStart); + if(fix > delEnd) + { + fix -= (delEnd - delStart + 1); + } + } + + // Delete a range of items [delStart, delEnd], and possibly shift items in range [fixStart, fixEnd] to the left. + template<typename T> + void DeleteRange(const T delStart, const T delEnd, T &fixStart, T &fixEnd) + { + ASSERT(delEnd >= delStart); + const T delLength = delEnd - delStart + 1; + if(delStart < fixStart && delEnd < fixStart) + { + // cut part is before loop start + fixStart -= delLength; + fixEnd -= delLength; + } else if(delStart < fixStart && delEnd < fixEnd) + { + // cut part is partly before loop start + fixStart = delStart; + fixEnd -= delLength; + } else if(delStart >= fixStart && delEnd < fixEnd) + { + // cut part is in the loop + fixEnd -= delLength; + } else if(delStart >= fixStart && delStart < fixEnd && delEnd > fixEnd) + { + // cut part is partly before loop end + fixEnd = delStart; + } + } +} + + OPENMPT_NAMESPACE_END Modified: trunk/OpenMPT/mptrack/View_smp.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_smp.cpp 2014-06-30 23:56:14 UTC (rev 4181) +++ trunk/OpenMPT/mptrack/View_smp.cpp 2014-07-01 00:31:16 UTC (rev 4182) @@ -1973,27 +1973,9 @@ void CViewSample::AdjustLoopPoints(SmpLength &loopStart, SmpLength &loopEnd, SmpLength length) const //-------------------------------------------------------------------------------------------------- { - if(m_dwBeginSel < loopStart && m_dwEndSel < loopStart) - { - // cut part is before loop start - loopStart -= m_dwEndSel - m_dwBeginSel; - loopEnd -= m_dwEndSel - m_dwBeginSel; - } else if(m_dwBeginSel < loopStart && m_dwEndSel < loopEnd) - { - // cut part is partly before loop start - loopStart = m_dwBeginSel; - loopEnd -= m_dwEndSel - m_dwBeginSel; - } else if(m_dwBeginSel >= loopStart && m_dwEndSel < loopEnd) - { - // cut part is in the loop - loopEnd -= m_dwEndSel - m_dwBeginSel; - } else if(m_dwBeginSel >= loopStart && m_dwBeginSel < loopEnd && m_dwEndSel > loopEnd) - { - // cut part is partly before loop end - loopEnd = m_dwBeginSel; - } - - if(loopEnd > length) loopEnd = length; + const SmpLength selLength = m_dwEndSel - m_dwBeginSel; + Util::DeleteRange(m_dwBeginSel, m_dwEndSel - 1, loopStart, loopEnd); + LimitMax(loopEnd, length); if(loopStart + 4 >= loopEnd) { loopStart = loopEnd = 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |