String view and filesystem are not happy neighbors
This commit is contained in:
parent
a610f6dc24
commit
849ee0e4a1
3 changed files with 18 additions and 12 deletions
|
|
@ -48,7 +48,7 @@ std::unique_ptr<AudioBuffer<T>> readFromFile(SndfileHandle& sndFile, int numFram
|
|||
return returnedBuffer;
|
||||
}
|
||||
|
||||
absl::optional<sfz::FilePool::FileInformation> sfz::FilePool::getFileInformation(absl::string_view filename, uint32_t offset) noexcept
|
||||
absl::optional<sfz::FilePool::FileInformation> 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::FileInformation> 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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,14 +56,14 @@ public:
|
|||
double sampleRate { config::defaultSampleRate };
|
||||
std::shared_ptr<AudioBuffer<float>> preloadedData;
|
||||
};
|
||||
absl::optional<FileInformation> getFileInformation(absl::string_view filename, uint32_t offset) noexcept;
|
||||
void enqueueLoading(Voice* voice, absl::string_view sample, int numFrames, unsigned ticket) noexcept;
|
||||
absl::optional<FileInformation> 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;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -151,7 +151,8 @@ void sfz::Synth::handleControlOpcodes(const std::vector<Opcode>& 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++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue