Store files to load and their offset and defer loading
Better behavior when using a file multiple times with different offsets.
This commit is contained in:
parent
6b1a7cd259
commit
da942c9244
1 changed files with 9 additions and 4 deletions
|
|
@ -581,6 +581,8 @@ void Synth::Impl::finalizeSfzLoad()
|
|||
size_t currentRegionIndex = 0;
|
||||
size_t currentRegionCount = layers_.size();
|
||||
|
||||
absl::flat_hash_map<sfz::FileId, int64_t> filesToLoad;
|
||||
|
||||
auto removeCurrentRegion = [this, ¤tRegionIndex, ¤tRegionCount]() {
|
||||
const Region& region = layers_[currentRegionIndex]->getRegion();
|
||||
DBG("Removing the region with sample " << *region.sampleId);
|
||||
|
|
@ -679,10 +681,8 @@ void Synth::Impl::finalizeSfzLoad()
|
|||
return Default::offsetMod.bounds.clamp(sumOffsetCC);
|
||||
}();
|
||||
|
||||
if (!filePool.preloadFile(*region.sampleId, maxOffset)) {
|
||||
removeCurrentRegion();
|
||||
continue;
|
||||
}
|
||||
auto& toLoad = filesToLoad[*region.sampleId];
|
||||
toLoad = max(toLoad, maxOffset);
|
||||
}
|
||||
else if (!region.isGenerator()) {
|
||||
if (!wavePool.createFileWave(filePool, std::string(region.sampleId->filename()))) {
|
||||
|
|
@ -763,6 +763,11 @@ void Synth::Impl::finalizeSfzLoad()
|
|||
|
||||
++currentRegionIndex;
|
||||
}
|
||||
|
||||
for (const auto& toLoad: filesToLoad) {
|
||||
filePool.preloadFile(toLoad.first, toLoad.second);
|
||||
}
|
||||
|
||||
if (currentRegionCount < layers_.size()) {
|
||||
DBG("Removing " << (layers_.size() - currentRegionCount)
|
||||
<< " out of " << layers_.size() << " regions");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue