From: <sag...@us...> - 2014-10-26 21:31:55
|
Revision: 4507 http://sourceforge.net/p/modplug/code/4507 Author: saga-games Date: 2014-10-26 21:31:40 +0000 (Sun, 26 Oct 2014) Log Message: ----------- [Fix] Tree view: Duplicating samples was broken since OpenMPT 1.23.01.00 [Fix] Rearranging samples no longer messes up the undo buffer. Modified Paths: -------------- trunk/OpenMPT/mptrack/Modedit.cpp trunk/OpenMPT/mptrack/Undo.cpp trunk/OpenMPT/mptrack/Undo.h Modified: trunk/OpenMPT/mptrack/Modedit.cpp =================================================================== --- trunk/OpenMPT/mptrack/Modedit.cpp 2014-10-26 15:43:26 UTC (rev 4506) +++ trunk/OpenMPT/mptrack/Modedit.cpp 2014-10-26 21:31:40 UTC (rev 4507) @@ -284,14 +284,6 @@ const SAMPLEINDEX oldNumSamples = m_SndFile.GetNumSamples(), newNumSamples = static_cast<SAMPLEINDEX>(newOrder.size()); - for(SAMPLEINDEX i = 0; i < std::min(newNumSamples, oldNumSamples); i++) - { - if(newOrder[i] != i + 1) - { - GetSampleUndo().PrepareUndo(i + 1, sundo_replace, "Rearrange"); - } - } - std::vector<int> sampleCount(oldNumSamples + 1, 0); std::vector<ModSample> sampleHeaders(oldNumSamples + 1); std::vector<SAMPLEINDEX> newIndex(oldNumSamples + 1, 0); // One of the new indexes for the old sample @@ -305,7 +297,7 @@ { sampleCount[origSlot]++; sampleHeaders[origSlot] = m_SndFile.GetSample(origSlot); - newIndex[origSlot] = i + 1; + if(!newIndex[origSlot]) newIndex[origSlot] = i + 1; } } @@ -315,6 +307,7 @@ if(sampleCount[i] == 0) { m_SndFile.DestroySample(i); + GetSampleUndo().ClearUndo(i); } sampleNames[i] = m_SndFile.m_szNames[i]; samplePaths[i] = m_SndFile.GetSamplePath(i); @@ -344,7 +337,7 @@ target.pSample = ModSample::AllocateSample(target.nLength, target.GetBytesPerSample()); if(target.pSample != nullptr) { - memcpy(target.pSample, sampleHeaders[origSlot].pSample, target.GetBytesPerSample()); + memcpy(target.pSample, sampleHeaders[origSlot].pSample, target.GetSampleSizeInBytes()); target.PrecomputeLoops(m_SndFile, false); } else { @@ -363,6 +356,8 @@ } } + GetSampleUndo().RearrangeSamples(newIndex); + for(CHANNELINDEX c = 0; c < CountOf(m_SndFile.m_PlayState.Chn); c++) { ModChannel &chn = m_SndFile.m_PlayState.Chn[c]; Modified: trunk/OpenMPT/mptrack/Undo.cpp =================================================================== --- trunk/OpenMPT/mptrack/Undo.cpp 2014-10-26 15:43:26 UTC (rev 4506) +++ trunk/OpenMPT/mptrack/Undo.cpp 2014-10-26 21:31:40 UTC (rev 4507) @@ -350,7 +350,7 @@ if(changeStart > oldSample.nLength || changeStart > changeEnd) { // Something is surely screwed up. - ASSERT(false); + MPT_ASSERT(false); return false; } @@ -393,7 +393,7 @@ break; default: - ASSERT(false); // whoops, what's this? someone forgot to implement it, some code is obviously missing here! + MPT_ASSERT(false); // whoops, what's this? someone forgot to implement it, some code is obviously missing here! return false; } @@ -471,7 +471,7 @@ case sundo_insert: // delete inserted data - ASSERT(changeLen == sample.nLength - undo.OldSample.nLength); + MPT_ASSERT(changeLen == sample.nLength - undo.OldSample.nLength); memcpy(pCurrentSample + undo.changeStart * bytesPerSample, pCurrentSample + undo.changeEnd * bytesPerSample, (sample.nLength - undo.changeEnd) * bytesPerSample); // also clean the sample end memset(pCurrentSample + undo.OldSample.nLength * bytesPerSample, 0, (sample.nLength - undo.OldSample.nLength) * bytesPerSample); @@ -501,7 +501,7 @@ break; default: - ASSERT(false); // whoops, what's this? someone forgot to implement it, some code is obviously missing here! + MPT_ASSERT(false); // whoops, what's this? someone forgot to implement it, some code is obviously missing here! return false; } @@ -582,6 +582,33 @@ } +// Update undo buffer when using rearrange sample functionality +void CSampleUndo::RearrangeSamples(undobuf_t &buffer, const std::vector<SAMPLEINDEX> &newIndex) +//--------------------------------------------------------------------------------------------- +{ + undobuf_t newBuf(modDoc.GetNumSamples()); + + for(SAMPLEINDEX smp = 1; smp < newIndex.size(); smp++) + { + MPT_ASSERT(newIndex[smp] <= modDoc.GetNumSamples()); + if(newIndex[smp] > 0 && newIndex[smp] <= modDoc.GetNumSamples() && smp <= buffer.size()) + { + newBuf[newIndex[smp] - 1] = buffer[smp - 1]; + } + } +#ifdef _DEBUG + for(size_t i = 0; i < buffer.size(); i++) + { + if(newIndex[i + 1] != 0) + MPT_ASSERT(newBuf[newIndex[i + 1] - 1].size() == buffer[i].size()); + else + MPT_ASSERT(buffer[i].empty()); + } +#endif + buffer = newBuf; +} + + // Return total amount of bytes used by the sample undo buffer. size_t CSampleUndo::GetBufferCapacity(const undobuf_t &buffer) const //------------------------------------------------------------------ Modified: trunk/OpenMPT/mptrack/Undo.h =================================================================== --- trunk/OpenMPT/mptrack/Undo.h 2014-10-26 15:43:26 UTC (rev 4506) +++ trunk/OpenMPT/mptrack/Undo.h 2014-10-26 21:31:40 UTC (rev 4507) @@ -148,6 +148,7 @@ bool SampleBufferExists(const undobuf_t &buffer, const SAMPLEINDEX smp) const; void RestrictBufferSize(undobuf_t &buffer, size_t &capacity); size_t GetBufferCapacity(const undobuf_t &buffer) const; + void RearrangeSamples(undobuf_t &buffer, const std::vector<SAMPLEINDEX> &newIndex); bool PrepareBuffer(undobuf_t &buffer, const SAMPLEINDEX smp, sampleUndoTypes changeType, const char *description, SmpLength changeStart, SmpLength changeEnd); bool Undo(undobuf_t &fromBuf, undobuf_t &toBuf, const SAMPLEINDEX smp); @@ -166,6 +167,7 @@ const char *GetUndoName(const SAMPLEINDEX smp) const; const char *GetRedoName(const SAMPLEINDEX smp) const; void RestrictBufferSize(); + void RearrangeSamples(const std::vector<SAMPLEINDEX> &newIndex) { RearrangeSamples(UndoBuffer, newIndex); RearrangeSamples(RedoBuffer, newIndex); } CSampleUndo(CModDoc &parent) : modDoc(parent) { } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |