String view and filesystem are not happy neighbors
This commit is contained in:
parent
695ec6ed54
commit
a913556389
3 changed files with 18 additions and 12 deletions
|
|
@ -48,7 +48,7 @@ std::unique_ptr<AudioBuffer<T>> readFromFile(SndfileHandle& sndFile, int numFram
|
||||||
return std::move(returnedBuffer);
|
return std::move(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 };
|
std::filesystem::path file { rootDirectory / filename };
|
||||||
if (!std::filesystem::exists(file))
|
if (!std::filesystem::exists(file))
|
||||||
|
|
@ -102,7 +102,7 @@ absl::optional<sfz::FilePool::FileInformation> sfz::FilePool::getFileInformation
|
||||||
return returnedValue;
|
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 })) {
|
if (!loadingQueue.try_enqueue({ voice, sample, numFrames, ticket })) {
|
||||||
DBG("Problem enqueuing a file read for file " << sample);
|
DBG("Problem enqueuing a file read for file " << sample);
|
||||||
|
|
@ -122,10 +122,15 @@ void sfz::FilePool::loadingThread() noexcept
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
DBG("Background loading of: " << fileToLoad.sample);
|
if (fileToLoad.sample == nullptr) {
|
||||||
std::filesystem::path file { rootDirectory / fileToLoad.sample };
|
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)) {
|
if (!std::filesystem::exists(file)) {
|
||||||
DBG("Background thread: no file " << fileToLoad.sample << " exists.");
|
DBG("Background thread: no file " << *fileToLoad.sample << " exists.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,14 +60,14 @@ public:
|
||||||
double sampleRate { config::defaultSampleRate };
|
double sampleRate { config::defaultSampleRate };
|
||||||
std::shared_ptr<AudioBuffer<float>> preloadedData;
|
std::shared_ptr<AudioBuffer<float>> preloadedData;
|
||||||
};
|
};
|
||||||
absl::optional<FileInformation> getFileInformation(absl::string_view filename, uint32_t offset) noexcept;
|
absl::optional<FileInformation> getFileInformation(const std::string& filename, uint32_t offset) noexcept;
|
||||||
void enqueueLoading(Voice* voice, absl::string_view sample, int numFrames, unsigned ticket) noexcept;
|
void enqueueLoading(Voice* voice, const std::string* sample, int numFrames, unsigned ticket) noexcept;
|
||||||
void clear();
|
void clear();
|
||||||
private:
|
private:
|
||||||
std::filesystem::path rootDirectory;
|
std::filesystem::path rootDirectory;
|
||||||
struct FileLoadingInformation {
|
struct FileLoadingInformation {
|
||||||
Voice* voice;
|
Voice* voice;
|
||||||
absl::string_view sample;
|
const std::string* sample;
|
||||||
int numFrames;
|
int numFrames;
|
||||||
unsigned ticket;
|
unsigned ticket;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,8 @@ void sfz::Synth::handleControlOpcodes(const std::vector<Opcode>& members)
|
||||||
break;
|
break;
|
||||||
case hash("Default_path"): [[fallthrough]];
|
case hash("Default_path"): [[fallthrough]];
|
||||||
case hash("default_path"): {
|
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))
|
if (std::filesystem::exists(newPath))
|
||||||
rootDirectory = newPath;
|
rootDirectory = newPath;
|
||||||
break;
|
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);
|
voice->startVoice(region, delay, channel, noteNumber, velocity, Voice::TriggerType::NoteOn);
|
||||||
if (!region->isGenerator()) {
|
if (!region->isGenerator()) {
|
||||||
voice->expectFileData(fileTicket);
|
voice->expectFileData(fileTicket);
|
||||||
filePool.enqueueLoading(voice, region->sample, region->trueSampleEnd(), fileTicket++);
|
filePool.enqueueLoading(voice, ®ion->sample, region->trueSampleEnd(), fileTicket++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -374,7 +375,7 @@ void sfz::Synth::noteOff(int delay, int channel, int noteNumber, uint8_t velocit
|
||||||
voice->startVoice(region, delay, channel, noteNumber, replacedVelocity, Voice::TriggerType::NoteOff);
|
voice->startVoice(region, delay, channel, noteNumber, replacedVelocity, Voice::TriggerType::NoteOff);
|
||||||
if (!region->isGenerator()) {
|
if (!region->isGenerator()) {
|
||||||
voice->expectFileData(fileTicket);
|
voice->expectFileData(fileTicket);
|
||||||
filePool.enqueueLoading(voice, region->sample, region->trueSampleEnd(), fileTicket++);
|
filePool.enqueueLoading(voice, ®ion->sample, region->trueSampleEnd(), fileTicket++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -399,7 +400,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);
|
voice->startVoice(region, delay, channel, ccNumber, ccValue, Voice::TriggerType::CC);
|
||||||
if (!region->isGenerator()) {
|
if (!region->isGenerator()) {
|
||||||
voice->expectFileData(fileTicket);
|
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