The Synth now prepares the region and handles the filepool

This commit is contained in:
paul 2019-08-04 22:54:00 +02:00
parent 1b81997c57
commit a964cc64c5
3 changed files with 34 additions and 37 deletions

View file

@ -243,49 +243,33 @@ bool sfz::Region::parseOpcode(const Opcode& opcode)
return true; 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 bool sfz::Region::isSwitchedOn() const noexcept
{ {
return false; 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; 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; return false;
} }
bool sfz::Region::registerCC(int channel, int ccNumber, uint8_t ccValue) bool sfz::Region::registerCC(int, int, uint8_t)
{ {
return false; 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)
{ {
} }

View file

@ -12,8 +12,7 @@ namespace sfz
{ {
struct Region struct Region
{ {
Region() = delete; Region() = default;
Region(FilePool& pool): filePool(pool) {}
Region(const Region&) = default; Region(const Region&) = default;
~Region() = default; ~Region() = default;
@ -113,7 +112,5 @@ struct Region
double sampleRate { config::defaultSampleRate }; double sampleRate { config::defaultSampleRate };
int numChannels { 1 }; int numChannels { 1 };
std::shared_ptr<StereoBuffer<float>> preloadedData { nullptr }; std::shared_ptr<StereoBuffer<float>> preloadedData { nullptr };
private:
FilePool& filePool;
}; };
} // namespace sfz } // namespace sfz

View file

@ -44,7 +44,7 @@ void sfz::Synth::callback(std::string_view header, std::vector<Opcode> members)
void sfz::Synth::buildRegion(const std::vector<Opcode>& regionOpcodes) void sfz::Synth::buildRegion(const std::vector<Opcode>& regionOpcodes)
{ {
auto lastRegion = std::make_shared<Region>(filePool); auto lastRegion = std::make_shared<Region>();
auto parseOpcodes = [&](const auto& opcodes) { auto parseOpcodes = [&](const auto& opcodes) {
for (auto& opcode: opcodes) for (auto& opcode: opcodes)
@ -122,25 +122,41 @@ bool sfz::Synth::loadSfzFile(const std::filesystem::path& filename)
return false; return false;
filePool.setRootDirectory(this->rootDirectory); filePool.setRootDirectory(this->rootDirectory);
auto lastRegion = regions.end() - 1; auto lastRegion = regions.end() - 1;
auto currentRegion = regions.begin(); auto currentRegion = regions.begin();
while (currentRegion <= lastRegion) 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); std::iter_swap(currentRegion, lastRegion);
lastRegion--; lastRegion--;
continue;
} }
else
{ region->sampleEnd = std::min(region->sampleEnd, fileInformation->end);
for (auto note = (*currentRegion)->keyRange.getStart(); note <= (*currentRegion)->keyRange.getEnd(); note++) region->loopRange.shrinkIfSmaller(fileInformation->loopBegin, fileInformation->loopEnd);
noteActivationLists[note].push_back(*currentRegion); region->preloadedData = fileInformation->preloadedData;
for (auto cc = (*currentRegion)->keyRange.getStart(); cc <= (*currentRegion)->keyRange.getEnd(); cc++)
ccActivationLists[cc].push_back(*currentRegion); for (auto note = region->keyRange.getStart(); note <= region->keyRange.getEnd(); note++)
currentRegion++; 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."); DBG("Removed " << regions.size() - std::distance(regions.begin(), lastRegion) - 1 << " out of " << regions.size() << " regions.");
regions.resize(std::distance(regions.begin(), lastRegion) + 1); regions.resize(std::distance(regions.begin(), lastRegion) + 1);
return parserReturned; return parserReturned;