Merge pull request #1030 from paulfd/filepool-loaded-files
Make loadedFiles behave like preloadedFiles
This commit is contained in:
commit
ec439d2034
1 changed files with 15 additions and 1 deletions
|
|
@ -339,6 +339,9 @@ void sfz::FilePool::resetPreloadCallCounts() noexcept
|
||||||
{
|
{
|
||||||
for (auto& preloadedFile: preloadedFiles)
|
for (auto& preloadedFile: preloadedFiles)
|
||||||
preloadedFile.second.preloadCallCount = 0;
|
preloadedFile.second.preloadCallCount = 0;
|
||||||
|
|
||||||
|
for (auto& loadedFile: loadedFiles)
|
||||||
|
loadedFile.second.preloadCallCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sfz::FilePool::removeUnusedPreloadedData() noexcept
|
void sfz::FilePool::removeUnusedPreloadedData() noexcept
|
||||||
|
|
@ -350,6 +353,14 @@ void sfz::FilePool::removeUnusedPreloadedData() noexcept
|
||||||
preloadedFiles.erase(copyIt);
|
preloadedFiles.erase(copyIt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto it = loadedFiles.begin(), end = loadedFiles.end(); it != end; ) {
|
||||||
|
auto copyIt = it++;
|
||||||
|
if (copyIt->second.preloadCallCount == 0) {
|
||||||
|
DBG("[sfizz] Removing unused loaded data: " << copyIt->first.filename());
|
||||||
|
preloadedFiles.erase(copyIt);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sfz::FileDataHolder sfz::FilePool::loadFile(const FileId& fileId) noexcept
|
sfz::FileDataHolder sfz::FilePool::loadFile(const FileId& fileId) noexcept
|
||||||
|
|
@ -364,14 +375,16 @@ sfz::FileDataHolder sfz::FilePool::loadFile(const FileId& fileId) noexcept
|
||||||
const auto frames = static_cast<uint32_t>(reader->frames());
|
const auto frames = static_cast<uint32_t>(reader->frames());
|
||||||
const auto existingFile = loadedFiles.find(fileId);
|
const auto existingFile = loadedFiles.find(fileId);
|
||||||
if (existingFile != loadedFiles.end()) {
|
if (existingFile != loadedFiles.end()) {
|
||||||
|
existingFile->second.preloadCallCount++;
|
||||||
return { &existingFile->second };
|
return { &existingFile->second };
|
||||||
} else {
|
} else {
|
||||||
fileInformation->sampleRate = static_cast<double>(reader->sampleRate());
|
fileInformation->sampleRate = static_cast<double>(reader->sampleRate());
|
||||||
auto insertedPair = preloadedFiles.insert_or_assign(fileId, {
|
auto insertedPair = loadedFiles.insert_or_assign(fileId, {
|
||||||
readFromFile(*reader, frames),
|
readFromFile(*reader, frames),
|
||||||
*fileInformation
|
*fileInformation
|
||||||
});
|
});
|
||||||
insertedPair.first->second.status = FileData::Status::Preloaded;
|
insertedPair.first->second.status = FileData::Status::Preloaded;
|
||||||
|
insertedPair.first->second.preloadCallCount++;
|
||||||
return { &insertedPair.first->second };
|
return { &insertedPair.first->second };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -474,6 +487,7 @@ void sfz::FilePool::clear()
|
||||||
garbageToCollect.clear();
|
garbageToCollect.clear();
|
||||||
lastUsedFiles.clear();
|
lastUsedFiles.clear();
|
||||||
preloadedFiles.clear();
|
preloadedFiles.clear();
|
||||||
|
loadedFiles.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t sfz::FilePool::getPreloadSize() const noexcept
|
uint32_t sfz::FilePool::getPreloadSize() const noexcept
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue