diff --git a/sfizz/FilePool.cpp b/sfizz/FilePool.cpp index 7b94c791..0e1c31a2 100644 --- a/sfizz/FilePool.cpp +++ b/sfizz/FilePool.cpp @@ -48,7 +48,7 @@ std::unique_ptr> readFromFile(SndfileHandle& sndFile, int numFram return returnedBuffer; } -absl::optional sfz::FilePool::getFileInformation(absl::string_view filename, uint32_t offset) noexcept +absl::optional sfz::FilePool::getFileInformation(const std::string& filename, uint32_t offset) noexcept { std::filesystem::path file { rootDirectory / filename }; if (!std::filesystem::exists(file)) @@ -102,7 +102,7 @@ absl::optional sfz::FilePool::getFileInformation return returnedValue; } -void sfz::FilePool::enqueueLoading(Voice* voice, absl::string_view sample, int numFrames, unsigned ticket) noexcept +void sfz::FilePool::enqueueLoading(Voice* voice, const std::string* sample, int numFrames, unsigned ticket) noexcept { if (!loadingQueue.try_enqueue({ voice, sample, numFrames, ticket })) { DBG("Problem enqueuing a file read for file " << sample); @@ -122,10 +122,15 @@ void sfz::FilePool::loadingThread() noexcept continue; } - DBG("Background loading of: " << fileToLoad.sample); - std::filesystem::path file { rootDirectory / fileToLoad.sample }; + if (fileToLoad.sample == nullptr) { + DBG("Background thread error: sample is null."); + continue; + } + + DBG("Background loading of: " << *fileToLoad.sample); + std::filesystem::path file { rootDirectory / *fileToLoad.sample }; if (!std::filesystem::exists(file)) { - DBG("Background thread: no file " << fileToLoad.sample << " exists."); + DBG("Background thread: no file " << *fileToLoad.sample << " exists."); continue; } diff --git a/sfizz/FilePool.h b/sfizz/FilePool.h index 15c599ed..fb30c353 100644 --- a/sfizz/FilePool.h +++ b/sfizz/FilePool.h @@ -56,14 +56,14 @@ public: double sampleRate { config::defaultSampleRate }; std::shared_ptr> preloadedData; }; - absl::optional getFileInformation(absl::string_view filename, uint32_t offset) noexcept; - void enqueueLoading(Voice* voice, absl::string_view sample, int numFrames, unsigned ticket) noexcept; + absl::optional getFileInformation(const std::string& filename, uint32_t offset) noexcept; + void enqueueLoading(Voice* voice, const std::string* sample, int numFrames, unsigned ticket) noexcept; void clear(); private: std::filesystem::path rootDirectory; struct FileLoadingInformation { Voice* voice; - absl::string_view sample; + const std::string* sample; int numFrames; unsigned ticket; }; diff --git a/sfizz/Synth.cpp b/sfizz/Synth.cpp index d4851d4b..8ed2729a 100644 --- a/sfizz/Synth.cpp +++ b/sfizz/Synth.cpp @@ -151,7 +151,8 @@ void sfz::Synth::handleControlOpcodes(const std::vector& members) break; case hash("Default_path"): [[fallthrough]]; case hash("default_path"): { - auto newPath = std::filesystem::path(member.value); + auto stringPath = std::string(member.value.begin(), member.value.end()); + auto newPath = std::filesystem::path(stringPath); if (std::filesystem::exists(newPath)) rootDirectory = newPath; break; @@ -349,7 +350,7 @@ void sfz::Synth::noteOn(int delay, int channel, int noteNumber, uint8_t velocity voice->startVoice(region, delay, channel, noteNumber, velocity, Voice::TriggerType::NoteOn); if (!region->isGenerator()) { voice->expectFileData(fileTicket); - filePool.enqueueLoading(voice, region->sample, region->trueSampleEnd(), fileTicket++); + filePool.enqueueLoading(voice, ®ion->sample, region->trueSampleEnd(), fileTicket++); } } } @@ -377,7 +378,7 @@ void sfz::Synth::noteOff(int delay, int channel, int noteNumber, uint8_t velocit voice->startVoice(region, delay, channel, noteNumber, replacedVelocity, Voice::TriggerType::NoteOff); if (!region->isGenerator()) { voice->expectFileData(fileTicket); - filePool.enqueueLoading(voice, region->sample, region->trueSampleEnd(), fileTicket++); + filePool.enqueueLoading(voice, ®ion->sample, region->trueSampleEnd(), fileTicket++); } } } @@ -402,7 +403,7 @@ void sfz::Synth::cc(int delay, int channel, int ccNumber, uint8_t ccValue) noexc voice->startVoice(region, delay, channel, ccNumber, ccValue, Voice::TriggerType::CC); if (!region->isGenerator()) { voice->expectFileData(fileTicket); - filePool.enqueueLoading(voice, region->sample, region->trueSampleEnd(), fileTicket++); + filePool.enqueueLoading(voice, ®ion->sample, region->trueSampleEnd(), fileTicket++); } } }