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 currentRegionIndex = 0;
|
||||||
size_t currentRegionCount = layers_.size();
|
size_t currentRegionCount = layers_.size();
|
||||||
|
|
||||||
|
absl::flat_hash_map<sfz::FileId, int64_t> filesToLoad;
|
||||||
|
|
||||||
auto removeCurrentRegion = [this, ¤tRegionIndex, ¤tRegionCount]() {
|
auto removeCurrentRegion = [this, ¤tRegionIndex, ¤tRegionCount]() {
|
||||||
const Region& region = layers_[currentRegionIndex]->getRegion();
|
const Region& region = layers_[currentRegionIndex]->getRegion();
|
||||||
DBG("Removing the region with sample " << *region.sampleId);
|
DBG("Removing the region with sample " << *region.sampleId);
|
||||||
|
|
@ -679,10 +681,8 @@ void Synth::Impl::finalizeSfzLoad()
|
||||||
return Default::offsetMod.bounds.clamp(sumOffsetCC);
|
return Default::offsetMod.bounds.clamp(sumOffsetCC);
|
||||||
}();
|
}();
|
||||||
|
|
||||||
if (!filePool.preloadFile(*region.sampleId, maxOffset)) {
|
auto& toLoad = filesToLoad[*region.sampleId];
|
||||||
removeCurrentRegion();
|
toLoad = max(toLoad, maxOffset);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (!region.isGenerator()) {
|
else if (!region.isGenerator()) {
|
||||||
if (!wavePool.createFileWave(filePool, std::string(region.sampleId->filename()))) {
|
if (!wavePool.createFileWave(filePool, std::string(region.sampleId->filename()))) {
|
||||||
|
|
@ -763,6 +763,11 @@ void Synth::Impl::finalizeSfzLoad()
|
||||||
|
|
||||||
++currentRegionIndex;
|
++currentRegionIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const auto& toLoad: filesToLoad) {
|
||||||
|
filePool.preloadFile(toLoad.first, toLoad.second);
|
||||||
|
}
|
||||||
|
|
||||||
if (currentRegionCount < layers_.size()) {
|
if (currentRegionCount < layers_.size()) {
|
||||||
DBG("Removing " << (layers_.size() - currentRegionCount)
|
DBG("Removing " << (layers_.size() - currentRegionCount)
|
||||||
<< " out of " << layers_.size() << " regions");
|
<< " out of " << layers_.size() << " regions");
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue