From: <sag...@us...> - 2011-11-03 21:15:16
|
Revision: 1131 http://modplug.svn.sourceforge.net/modplug/?rev=1131&view=rev Author: saga-games Date: 2011-11-03 21:15:10 +0000 (Thu, 03 Nov 2011) Log Message: ----------- [Imp] When loading replacing an existing instrument, the replacing / deleting of the previously assigned samples could not be undone. [Fix] Sample length calculation for sample optimizer in cleanup dialog was wrong for samples that only have a sustain loop. [Mod] OpenMPT: Version is now 1.20.00.51 Modified Paths: -------------- trunk/OpenMPT/mptrack/CleanupSong.cpp trunk/OpenMPT/mptrack/version.h trunk/OpenMPT/soundlib/Sampleio.cpp trunk/OpenMPT/soundlib/Sndfile.cpp Modified: trunk/OpenMPT/mptrack/CleanupSong.cpp =================================================================== --- trunk/OpenMPT/mptrack/CleanupSong.cpp 2011-10-31 21:26:59 UTC (rev 1130) +++ trunk/OpenMPT/mptrack/CleanupSong.cpp 2011-11-03 21:15:10 UTC (rev 1131) @@ -523,9 +523,9 @@ vector<bool> samplesUsed(pSndFile->GetNumSamples() + 1, true); BeginWaitCursor(); - for (SAMPLEINDEX nSmp = pSndFile->GetNumSamples(); nSmp >= 1; nSmp--) if (pSndFile->GetSample(nSmp).pSample) + for(SAMPLEINDEX nSmp = pSndFile->GetNumSamples(); nSmp >= 1; nSmp--) if (pSndFile->GetSample(nSmp).pSample) { - if (!pSndFile->IsSampleUsed(nSmp)) + if(!pSndFile->IsSampleUsed(nSmp)) { samplesUsed[nSmp] = false; m_pModDoc->GetSampleUndo().PrepareUndo(nSmp, sundo_delete); @@ -533,38 +533,38 @@ } SAMPLEINDEX nRemoved; - { - CriticalSection cs; - nRemoved = pSndFile->RemoveSelectedSamples(samplesUsed); - } + nRemoved = pSndFile->RemoveSelectedSamples(samplesUsed); - SAMPLEINDEX nExt = pSndFile->DetectUnusedSamples(samplesUsed); + const SAMPLEINDEX unusedInsSamples = pSndFile->DetectUnusedSamples(samplesUsed); EndWaitCursor(); - if (nExt && !((pSndFile->GetType() == MOD_TYPE_IT) && (pSndFile->m_dwSongFlags & SONG_ITPROJECT))) - { //We don't remove an instrument's unused samples in an ITP. + if(unusedInsSamples && !((pSndFile->GetType() == MOD_TYPE_IT) && (pSndFile->m_dwSongFlags & SONG_ITPROJECT))) + { + // We don't remove an instrument's unused samples in an ITP. wsprintf(s, "OpenMPT detected %d sample%s referenced by an instrument,\n" - "but not used in the song. Do you want to remove them?", nExt, (nExt == 1) ? "" : "s"); - if (Reporting::Confirm(s, "Sample Cleanup") == cnfYes) + "but not used in the song. Do you want to remove them?", unusedInsSamples, (unusedInsSamples == 1) ? "" : "s"); + if(Reporting::Confirm(s, "Sample Cleanup") == cnfYes) { - CriticalSection cs; - for (SAMPLEINDEX nSmp = 1; nSmp <= pSndFile->GetNumSamples(); nSmp++) + nRemoved += pSndFile->RemoveSelectedSamples(samplesUsed); + // Reduce the number of sample slots if possible. + for(SAMPLEINDEX nSmp = pSndFile->GetNumSamples(); nSmp >= 1; nSmp--) { - if ((!samplesUsed[nSmp]) && (pSndFile->GetSample(nSmp).pSample)) + if(samplesUsed[nSmp]) { - m_pModDoc->GetSampleUndo().PrepareUndo(nSmp, sundo_delete); - pSndFile->DestroySample(nSmp); - if ((nSmp == pSndFile->m_nSamples) && (nSmp > 1)) pSndFile->m_nSamples--; - nRemoved++; - m_pModDoc->GetSampleUndo().ClearUndo(nSmp); + pSndFile->m_nSamples = nSmp; + break; } } - wsprintf(s, "%d unused sample%s removed\n" , nRemoved, (nRemoved == 1) ? "" : "s"); - m_pModDoc->AddToLog(s); - return true; } } + + if(nRemoved > 0) + { + wsprintf(s, "%d unused sample%s removed\n" , nRemoved, (nRemoved == 1) ? "" : "s"); + m_pModDoc->AddToLog(s); + } + return (nRemoved > 0); } @@ -611,11 +611,13 @@ if(sample.uFlags & CHN_LOOP) { loopLength = sample.nLoopEnd; + + // Sustain loop is played before normal loop, and it can actually be located after the normal loop. + if(sample.uFlags & CHN_SUSTAINLOOP) + { + loopLength = max(sample.nLoopEnd, sample.nSustainEnd); + } } - if(sample.uFlags & CHN_SUSTAINLOOP) - { - loopLength = max(sample.nLoopEnd, sample.nSustainEnd); - } if (sample.nLength > loopLength + 2) { Modified: trunk/OpenMPT/mptrack/version.h =================================================================== --- trunk/OpenMPT/mptrack/version.h 2011-10-31 21:26:59 UTC (rev 1130) +++ trunk/OpenMPT/mptrack/version.h 2011-11-03 21:15:10 UTC (rev 1131) @@ -15,7 +15,7 @@ #define VER_MAJORMAJOR 1 #define VER_MAJOR 20 #define VER_MINOR 00 -#define VER_MINORMINOR 50 +#define VER_MINORMINOR 51 //Creates version number from version parts that appears in version string. //For example MAKE_VERSION_NUMERIC(1,17,02,28) gives version number of Modified: trunk/OpenMPT/soundlib/Sampleio.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sampleio.cpp 2011-10-31 21:26:59 UTC (rev 1130) +++ trunk/OpenMPT/soundlib/Sampleio.cpp 2011-11-03 21:15:10 UTC (rev 1131) @@ -151,35 +151,36 @@ bool CSoundFile::RemoveInstrumentSamples(INSTRUMENTINDEX nInstr) //-------------------------------------------------------------- { - vector<bool> sampleused(GetNumSamples() + 1, false); + if(Instruments[nInstr] == nullptr) + { + return false; + } - if (Instruments[nInstr]) + vector<bool> keepSamples(GetNumSamples() + 1, true); + + const MODINSTRUMENT *p = Instruments[nInstr]; + + // Check which samples are used by the instrument we are going to nuke. + for(size_t r = 0; r < CountOf(p->Keyboard); r++) { - MODINSTRUMENT *p = Instruments[nInstr]; - for (UINT r=0; r<128; r++) + SAMPLEINDEX n = p->Keyboard[r]; + if (n <= GetNumSamples()) keepSamples[n] = false; + } + + // Check if any of those samples are referenced by other instruments as well, in which case we want to keep them of course. + for(INSTRUMENTINDEX nIns = 1; nIns <= GetNumInstruments(); nIns++) if (Instruments[nIns] != nullptr && nIns != nInstr) + { + p = Instruments[nIns]; + for(size_t r = 0; r < CountOf(p->Keyboard); r++) { - UINT n = p->Keyboard[r]; - if (n <= GetNumSamples()) sampleused[n] = true; + SAMPLEINDEX n = p->Keyboard[r]; + if (n <= GetNumSamples()) keepSamples[n] = true; } - for (INSTRUMENTINDEX nIns = 1; nIns < MAX_INSTRUMENTS; nIns++) if ((Instruments[nIns]) && (nIns != nInstr)) - { - p = Instruments[nIns]; - for (UINT r=0; r<128; r++) - { - UINT n = p->Keyboard[r]; - if (n <= GetNumSamples()) sampleused[n] = false; - } - } - for (SAMPLEINDEX nSmp = 1; nSmp <= GetNumSamples(); nSmp++) if (sampleused[nSmp]) - { - CriticalSection cs; + } - DestroySample(nSmp); - strcpy(m_szNames[nSmp], ""); - } - return true; - } - return false; + // Now nuke the selected samples. + RemoveSelectedSamples(keepSamples); + return true; } //////////////////////////////////////////////////////////////////////////////// Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2011-10-31 21:26:59 UTC (rev 1130) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2011-11-03 21:15:10 UTC (rev 1131) @@ -2591,13 +2591,24 @@ { return 0; } + SAMPLEINDEX nRemoved = 0; for(SAMPLEINDEX nSmp = (SAMPLEINDEX)min(GetNumSamples(), keepSamples.size() - 1); nSmp >= 1; nSmp--) { if(!keepSamples[nSmp]) { + CriticalSection cs; + +#ifdef MODPLUG_TRACKER + if(GetpModDoc()) + { + GetpModDoc()->GetSampleUndo().PrepareUndo(nSmp, sundo_replace); + } +#endif // MODPLUG_TRACKER + if(DestroySample(nSmp)) { + strcpy(m_szNames[nSmp], ""); nRemoved++; } if((nSmp == GetNumSamples()) && (nSmp > 1)) m_nSamples--; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |