diff --git a/src/sfizz/Region.cpp b/src/sfizz/Region.cpp index 2d232429..08d5be05 100644 --- a/src/sfizz/Region.cpp +++ b/src/sfizz/Region.cpp @@ -29,6 +29,7 @@ #include "StringViewHelpers.h" #include "MidiState.h" #include "absl/strings/str_replace.h" +#include "absl/strings/str_cat.h" #include bool sfz::Region::parseOpcode(const Opcode& opcode) @@ -42,7 +43,7 @@ bool sfz::Region::parseOpcode(const Opcode& opcode) switch (hash(opcode.opcode)) { // Sound source: sample playback case hash("sample"): - sample = absl::StrReplaceAll(trim(opcode.value), { { "\\", "/" } }); + sample = absl::StrCat(defaultPath, absl::StrReplaceAll(trim(opcode.value), { { "\\", "/" } })); break; case hash("delay"): setValueFromOpcode(opcode, delay, Default::delayRange); diff --git a/src/sfizz/Region.h b/src/sfizz/Region.h index f42b2213..441acb09 100644 --- a/src/sfizz/Region.h +++ b/src/sfizz/Region.h @@ -29,6 +29,7 @@ #include "Opcode.h" #include "AudioBuffer.h" #include "MidiState.h" +#include "absl/strings/str_cat.h" #include #include #include @@ -49,9 +50,12 @@ namespace sfz { * */ struct Region { - Region(const MidiState& midiState) - : midiState(midiState) + Region(const MidiState& midiState, std::string defaultPath = "") + : midiState(midiState), defaultPath(std::move(defaultPath)) { + if (!this->defaultPath.empty() && this->defaultPath.back() != '/') + absl::StrAppend(&this->defaultPath, "/"); + ccSwitched.set(); } Region(const Region&) = default; @@ -320,6 +324,7 @@ private: bool bpmSwitched { true }; bool aftertouchSwitched { true }; std::bitset<128> ccSwitched; + std::string defaultPath { "" }; int activeNotesInRange { -1 }; int sequenceCounter { 0 }; diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index 8d5d7295..81cdf979 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -94,7 +94,7 @@ void sfz::Synth::callback(absl::string_view header, const std::vector& m void sfz::Synth::buildRegion(const std::vector& regionOpcodes) { - auto lastRegion = std::make_unique(midiState); + auto lastRegion = std::make_unique(midiState, defaultPath); auto parseOpcodes = [&](const auto& opcodes) { for (auto& opcode : opcodes) { @@ -179,11 +179,10 @@ void sfz::Synth::handleControlOpcodes(const std::vector& members) case hash("Default_path"): [[fallthrough]]; case hash("default_path"): { - const auto stringPath = absl::StrReplaceAll(trim(member.value), { { "\\", "/" } }); - const auto newPath = originalDirectory / fs::path(stringPath); - if (fs::exists(newPath)) { - DBG("Changing default sample path to " << stringPath); - defaultPath = newPath; + const auto newPath = absl::StrReplaceAll(trim(member.value), { { "\\", "/" } }); + if (fs::exists(originalDirectory / newPath)) { + DBG("Changing default sample path to " << newPath); + defaultPath = std::move(newPath); } break; } @@ -220,7 +219,6 @@ bool sfz::Synth::loadSfzFile(const fs::path& filename) } clear(); - defaultPath = filename.parent_path(); auto parserReturned = sfz::Parser::loadSfzFile(filename); if (!parserReturned) return false; @@ -228,7 +226,7 @@ bool sfz::Synth::loadSfzFile(const fs::path& filename) if (regions.empty()) return false; - resources.filePool.setRootDirectory(this->defaultPath); + resources.filePool.setRootDirectory(this->originalDirectory); auto lastRegion = regions.end() - 1; auto currentRegion = regions.begin(); diff --git a/src/sfizz/Synth.h b/src/sfizz/Synth.h index f3840343..bda482c3 100644 --- a/src/sfizz/Synth.h +++ b/src/sfizz/Synth.h @@ -445,7 +445,7 @@ private: MidiState midiState; // default_path - fs::path defaultPath { }; + std::string defaultPath { "" }; LEAK_DETECTOR(Synth); };