From a964cc64c5dc46f87df012c671500f65ee87bb0c Mon Sep 17 00:00:00 2001 From: paul Date: Sun, 4 Aug 2019 22:54:00 +0200 Subject: [PATCH] The Synth now prepares the region and handles the filepool --- sources/Region.cpp | 28 ++++++---------------------- sources/Region.h | 5 +---- sources/Synth.cpp | 38 +++++++++++++++++++++++++++----------- 3 files changed, 34 insertions(+), 37 deletions(-) diff --git a/sources/Region.cpp b/sources/Region.cpp index f7c7532d..1b2adba5 100644 --- a/sources/Region.cpp +++ b/sources/Region.cpp @@ -243,49 +243,33 @@ bool sfz::Region::parseOpcode(const Opcode& opcode) return true; } -bool sfz::Region::prepare() -{ - if (isGenerator()) - return true; - - auto fileInformation = filePool.getFileInformation(sample); - if (!fileInformation) - return false; - - DBG("Sample " << sample << " information: " << fileInformation->end << "(" << fileInformation->loopBegin << "->" << fileInformation->loopEnd << ")"); - sampleEnd = std::min(sampleEnd, fileInformation->end); - loopRange.shrinkIfSmaller(fileInformation->loopBegin, fileInformation->loopEnd); - preloadedData = fileInformation->preloadedData; - return true; -} - bool sfz::Region::isSwitchedOn() const noexcept { return false; } -bool sfz::Region::registerNoteOn(int channel, int noteNumber, uint8_t velocity, float randValue) +bool sfz::Region::registerNoteOn(int, int, uint8_t, float) { return false; } -bool sfz::Region::registerNoteOff(int channel, int noteNumber, uint8_t velocity, float randValue) +bool sfz::Region::registerNoteOff(int, int, uint8_t, float) { return false; } -bool sfz::Region::registerCC(int channel, int ccNumber, uint8_t ccValue) +bool sfz::Region::registerCC(int, int, uint8_t) { return false; } -void sfz::Region::registerPitchWheel(int channel, int pitch) +void sfz::Region::registerPitchWheel(int, int) { } -void sfz::Region::registerAftertouch(int channel, uint8_t aftertouch) +void sfz::Region::registerAftertouch(int, uint8_t) { } -void sfz::Region::registerTempo(float secondsPerQuarter) +void sfz::Region::registerTempo(float) { } \ No newline at end of file diff --git a/sources/Region.h b/sources/Region.h index 6967a640..690bbf9f 100644 --- a/sources/Region.h +++ b/sources/Region.h @@ -12,8 +12,7 @@ namespace sfz { struct Region { - Region() = delete; - Region(FilePool& pool): filePool(pool) {} + Region() = default; Region(const Region&) = default; ~Region() = default; @@ -113,7 +112,5 @@ struct Region double sampleRate { config::defaultSampleRate }; int numChannels { 1 }; std::shared_ptr> preloadedData { nullptr }; -private: - FilePool& filePool; }; } // namespace sfz \ No newline at end of file diff --git a/sources/Synth.cpp b/sources/Synth.cpp index 0ffb60fd..c74176ad 100644 --- a/sources/Synth.cpp +++ b/sources/Synth.cpp @@ -44,7 +44,7 @@ void sfz::Synth::callback(std::string_view header, std::vector members) void sfz::Synth::buildRegion(const std::vector& regionOpcodes) { - auto lastRegion = std::make_shared(filePool); + auto lastRegion = std::make_shared(); auto parseOpcodes = [&](const auto& opcodes) { for (auto& opcode: opcodes) @@ -122,25 +122,41 @@ bool sfz::Synth::loadSfzFile(const std::filesystem::path& filename) return false; filePool.setRootDirectory(this->rootDirectory); + auto lastRegion = regions.end() - 1; auto currentRegion = regions.begin(); while (currentRegion <= lastRegion) { - if (! (*currentRegion)->prepare() ) + auto region = *currentRegion; + + if (region->isGenerator()) { - DBG("Removing the region with sample " << (*currentRegion)->sample); + currentRegion++; + continue; + } + + auto fileInformation = filePool.getFileInformation(region->sample); + if (!fileInformation) + { + DBG("Removing the region with sample " << region->sample); std::iter_swap(currentRegion, lastRegion); lastRegion--; + continue; } - else - { - for (auto note = (*currentRegion)->keyRange.getStart(); note <= (*currentRegion)->keyRange.getEnd(); note++) - noteActivationLists[note].push_back(*currentRegion); - for (auto cc = (*currentRegion)->keyRange.getStart(); cc <= (*currentRegion)->keyRange.getEnd(); cc++) - ccActivationLists[cc].push_back(*currentRegion); - currentRegion++; - } + + region->sampleEnd = std::min(region->sampleEnd, fileInformation->end); + region->loopRange.shrinkIfSmaller(fileInformation->loopBegin, fileInformation->loopEnd); + region->preloadedData = fileInformation->preloadedData; + + for (auto note = region->keyRange.getStart(); note <= region->keyRange.getEnd(); note++) + noteActivationLists[note].push_back(*currentRegion); + + for (auto cc = region->keyRange.getStart(); cc <= region->keyRange.getEnd(); cc++) + ccActivationLists[cc].push_back(*currentRegion); + + currentRegion++; } + DBG("Removed " << regions.size() - std::distance(regions.begin(), lastRegion) - 1 << " out of " << regions.size() << " regions."); regions.resize(std::distance(regions.begin(), lastRegion) + 1); return parserReturned;