From: <sag...@us...> - 2013-02-13 15:19:53
|
Revision: 1525 http://sourceforge.net/p/modplug/code/1525 Author: saga-games Date: 2013-02-13 15:19:42 +0000 (Wed, 13 Feb 2013) Log Message: ----------- [Imp] Improved sample slot allocation behaviour when reading samples as instruments. [Mod] Several smaller changes in sample loaders (e.g. removed some critical sections and shortened some others). Modified Paths: -------------- trunk/OpenMPT/mptrack/Ctrl_ins.cpp trunk/OpenMPT/mptrack/Ctrl_smp.cpp trunk/OpenMPT/mptrack/View_smp.cpp trunk/OpenMPT/soundlib/SampleFormats.cpp trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/soundlib/Sndfile.h Modified: trunk/OpenMPT/mptrack/Ctrl_ins.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_ins.cpp 2013-02-13 00:33:57 UTC (rev 1524) +++ trunk/OpenMPT/mptrack/Ctrl_ins.cpp 2013-02-13 15:19:42 UTC (rev 1525) @@ -1454,8 +1454,6 @@ bOk = FALSE; if (lpFile) { - CriticalSection cs; - if (!m_pSndFile->GetNumInstruments()) { bFirst = TRUE; Modified: trunk/OpenMPT/mptrack/Ctrl_smp.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_smp.cpp 2013-02-13 00:33:57 UTC (rev 1524) +++ trunk/OpenMPT/mptrack/Ctrl_smp.cpp 2013-02-13 15:19:42 UTC (rev 1525) @@ -765,7 +765,6 @@ if (!lpFile) goto OpenError; { - CriticalSection cs; m_pModDoc->GetSampleUndo().PrepareUndo(m_nSample, sundo_replace); bOk = m_pSndFile->ReadSampleFromFile(m_nSample, lpFile, len); } @@ -786,9 +785,7 @@ BeginWaitCursor(); ModSample &sample = m_pSndFile->GetSample(m_nSample); - CriticalSection cs; - - m_pSndFile->DestroySample(m_nSample); + m_pSndFile->DestroySampleThreadsafe(m_nSample); sample.nLength = len; SampleIO sampleIO( @@ -887,10 +884,7 @@ BeginWaitCursor(); - CriticalSection cs; - m_pModDoc->GetSampleUndo().PrepareUndo(m_nSample, sundo_replace); - m_pSndFile->DestroySample(m_nSample); m_pSndFile->ReadSampleFromSong(m_nSample, pSndFile, nSample); ModSample &sample = m_pSndFile->GetSample(m_nSample); if ((m_pSndFile->GetType() & MOD_TYPE_XM) && (!(sample.uFlags & CHN_PANNING))) @@ -899,7 +893,6 @@ sample.uFlags |= CHN_PANNING; } - cs.Leave(); EndWaitCursor(); m_pModDoc->UpdateAllViews(NULL, (m_nSample << HINT_SHIFT_SMP) | HINT_SAMPLEDATA | HINT_SAMPLEINFO | HINT_SMPNAMES, NULL); Modified: trunk/OpenMPT/mptrack/View_smp.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_smp.cpp 2013-02-13 00:33:57 UTC (rev 1524) +++ trunk/OpenMPT/mptrack/View_smp.cpp 2013-02-13 15:19:42 UTC (rev 1525) @@ -1795,9 +1795,7 @@ if (Reporting::Confirm("Remove this sample?", "Remove Sample", true) != cnfYes) return; pModDoc->GetSampleUndo().PrepareUndo(m_nSample, sundo_replace); - CriticalSection cs; - pSndFile->DestroySample(m_nSample); - cs.Leave(); + pSndFile->DestroySampleThreadsafe(m_nSample); dwUpdateFlags |= HINT_SMPNAMES; } else @@ -1988,15 +1986,10 @@ CSoundFile *pSndFile = pModDoc->GetSoundFile(); DWORD dwMemSize = GlobalSize(hCpy); - CriticalSection cs; - ModSample &sample = pSndFile->GetSample(m_nSample); memcpy(s, pSndFile->m_szNames[m_nSample], 32); memcpy(s2, sample.filename, 22); - pSndFile->DestroySample(m_nSample); - sample.nLength = 0; - sample.pSample = 0; pSndFile->ReadSampleFromFile(m_nSample, p, dwMemSize); if (!pSndFile->m_szNames[m_nSample][0]) { @@ -2007,8 +2000,6 @@ memcpy(sample.filename, s2, 22); } - cs.Leave(); - GlobalUnlock(hCpy); SetCurSel(0, 0); pModDoc->AdjustEndOfSample(m_nSample); Modified: trunk/OpenMPT/soundlib/SampleFormats.cpp =================================================================== --- trunk/OpenMPT/soundlib/SampleFormats.cpp 2013-02-13 00:33:57 UTC (rev 1524) +++ trunk/OpenMPT/soundlib/SampleFormats.cpp 2013-02-13 15:19:42 UTC (rev 1525) @@ -43,6 +43,11 @@ { return false; } + + if(nSample > GetNumSamples()) + { + m_nSamples = nSample; + } return true; } @@ -57,7 +62,8 @@ && (!ReadITIInstrument(nInstr, file)) // Generic read && (!ReadSampleAsInstrument(nInstr, lpMemFile, dwFileLength))) return false; - if (nInstr > m_nInstruments) m_nInstruments = nInstr; + + if(nInstr > GetNumInstruments()) m_nInstruments = nInstr; return true; } @@ -106,16 +112,6 @@ Instruments[nInstr] = pIns; ReadSampleFromFile(nSample, lpMemFile, dwFileLength); - - if(nSample > GetNumSamples()) - { - m_nSamples = nSample; - } - if(nInstr > GetNumInstruments()) - { - m_nInstruments = nInstr; - } - return true; } return false; @@ -285,8 +281,7 @@ return false; } - CriticalSection cs; - DestroySample(targetSample); + DestroySampleThreadsafe(targetSample); const ModSample &sourceSmp = pSrcSong->GetSample(sourceSample); @@ -330,8 +325,7 @@ return false; } - CriticalSection cs; - DestroySample(nSample); + DestroySampleThreadsafe(nSample); strcpy(m_szNames[nSample], ""); ModSample &sample = Samples[nSample]; sample.Initialize(); @@ -726,9 +720,8 @@ || (phdr->version[3] != 0) || (phdr->id[9] != 0) || (phdr->instrum < 1) || (!phdr->samples) || (!pinshdr->layers)) return false; - CriticalSection cs; - DestroySample(nSample); - PatchToSample(this, nSample, lpStream+dwMemPos, dwMemLength-dwMemPos); + DestroySampleThreadsafe(nSample); + PatchToSample(this, nSample, lpStream + dwMemPos, dwMemLength - dwMemPos); if (pinshdr->name[0] > ' ') { memcpy(m_szNames[nSample], pinshdr->name, 16); @@ -890,8 +883,7 @@ || (pss->id != 0x01) || (((DWORD)pss->offset << 4) >= dwFileLength) || (pss->scrs != 0x53524353)) return false; - CriticalSection cs; - DestroySample(nSample); + DestroySampleThreadsafe(nSample); dwMemPos = pss->offset << 4; sample.Initialize(); @@ -1124,8 +1116,7 @@ // Gotta skip 'em all! file.Skip(sizeof(XMSample) * (fileHeader.numSamples - 1)); - CriticalSection cs; - DestroySample(nSample); + DestroySampleThreadsafe(nSample); ModSample &mptSample = Samples[nSample]; sampleHeader.ConvertToMPT(mptSample); @@ -1391,9 +1382,8 @@ soundChunk.Skip(sampleHeader.offset); - CriticalSection cs; ModSample &mptSample = Samples[nSample]; - DestroySample(nSample); + DestroySampleThreadsafe(nSample); mptSample.Initialize(); mptSample.nLength = sampleInfo.numSampleFrames; mptSample.nC5Speed = sampleInfo.GetSampleRate(); @@ -1487,8 +1477,7 @@ { return false; } - CriticalSection cs; - DestroySample(nSample); + DestroySampleThreadsafe(nSample); file.Seek(sampleHeader.ConvertToMPT(Samples[nSample])); StringFixer::ReadString<StringFixer::spacePaddedNull>(m_szNames[nSample], sampleHeader.name); @@ -1790,8 +1779,7 @@ || (pfh->dw8SVX != IFFID_8SVX) || (BigEndian(pfh->dwSize) >= dwFileLength) || (pvh->dwVHDR != IFFID_VHDR) || (BigEndian(pvh->dwSize) >= dwFileLength)) return false; - CriticalSection cs; - DestroySample(nSample); + DestroySampleThreadsafe(nSample); // Default values sample.Initialize(); sample.nLoopStart = BigEndian(pvh->oneShotHiSamples); @@ -1967,13 +1955,16 @@ static void metadata_cb(const FLAC__StreamDecoder *, const FLAC__StreamMetadata *metadata, void *client_data) { FLACDecoder &client = *static_cast<FLACDecoder *>(client_data); + if(client.sample > client.sndFile.GetNumSamples()) + { + client.sndFile.m_nSamples = client.sample; + } ModSample &sample = client.sndFile.GetSample(client.sample); if(metadata->type == FLAC__METADATA_TYPE_STREAMINFO && metadata->data.stream_info.total_samples != 0) { // Init sample information - CriticalSection cs; - client.sndFile.DestroySample(client.sample); + client.sndFile.DestroySampleThreadsafe(client.sample); strcpy(client.sndFile.m_szNames[client.sample], ""); sample.Initialize(); sample.uFlags.set(CHN_16BIT, metadata->data.stream_info.bits_per_sample > 8); @@ -2321,8 +2312,8 @@ return false; } - CriticalSection cs; - DestroySample(sample); + DestroySampleThreadsafe(sample); + strcpy(m_szNames[sample], ""); Samples[sample].Initialize(); Samples[sample].nLength = length; Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2013-02-13 00:33:57 UTC (rev 1524) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2013-02-13 15:19:42 UTC (rev 1525) @@ -1547,6 +1547,14 @@ } +bool CSoundFile::DestroySampleThreadsafe(SAMPLEINDEX nSample) +//----------------------------------------------------------- +{ + CriticalSection cs; + return DestroySample(nSample); +} + + void CSoundFile::DeleteStaticdata() //--------------------------------- { @@ -1828,8 +1836,9 @@ for(SAMPLEINDEX i = start; i <= GetModSpecifications().samplesMax; i++) { // When loading into an instrument, ignore non-empty sample names. Else, only use this slot if the sample name is empty or we're in second pass. - if(i > GetNumSamples() - || (Samples[i].pSample == nullptr && (!m_szNames[i][0] || passes == 1 || targetInstrument != INSTRUMENTINDEX_INVALID))) + if((i > GetNumSamples() && passes == 1) + || (Samples[i].pSample == nullptr && (!m_szNames[i][0] || passes == 1 || targetInstrument != INSTRUMENTINDEX_INVALID)) + || (targetInstrument != INSTRUMENTINDEX_INVALID && IsSampleReferencedByInstrument(i, targetInstrument))) // Not empty, but already used by this instrument. { // Empty slot, so it's a good candidate already. Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2013-02-13 00:33:57 UTC (rev 1524) +++ trunk/OpenMPT/soundlib/Sndfile.h 2013-02-13 15:19:42 UTC (rev 1525) @@ -606,6 +606,7 @@ public: bool DestroySample(SAMPLEINDEX nSample); + bool DestroySampleThreadsafe(SAMPLEINDEX nSample); // Find an unused sample slot. If it is going to be assigned to an instrument, targetInstrument should be specified. // SAMPLEINDEX_INVLAID is returned if no free sample slot could be found. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |