diff --git a/src/sfizz/Parser.cpp b/src/sfizz/Parser.cpp index 5d2c643e..cd1db80a 100644 --- a/src/sfizz/Parser.cpp +++ b/src/sfizz/Parser.cpp @@ -43,11 +43,11 @@ void removeCommentOnLine(absl::string_view& line) bool sfz::Parser::loadSfzFile(const fs::path& file) { - const auto sfzFile = file.is_absolute() ? file : defaultPath / file; + const auto sfzFile = file.is_absolute() ? file : originalDirectory / file; if (!fs::exists(sfzFile)) return false; - defaultPath = file.parent_path(); + originalDirectory = file.parent_path(); std::vector lines; readSfzFile(file, lines); @@ -105,7 +105,7 @@ void sfz::Parser::readSfzFile(const fs::path& fileName, std::vector if (std::regex_search(tmpView.begin(), tmpView.end(), includeMatch, sfz::Regexes::includes)) { auto includePath = includeMatch.str(1); std::replace(includePath.begin(), includePath.end(), '\\', '/'); - const auto newFile = defaultPath / includePath; + const auto newFile = originalDirectory / includePath; auto alreadyIncluded = std::find(includedFiles.begin(), includedFiles.end(), newFile); if (fs::exists(newFile)) { if (alreadyIncluded == includedFiles.end()) { diff --git a/src/sfizz/Parser.h b/src/sfizz/Parser.h index cb767582..222fd153 100644 --- a/src/sfizz/Parser.h +++ b/src/sfizz/Parser.h @@ -40,7 +40,7 @@ public: void enableRecursiveIncludeGuard() { recursiveIncludeGuard = true; } protected: virtual void callback(absl::string_view header, const std::vector& members) = 0; - fs::path defaultPath { fs::current_path() }; + fs::path originalDirectory { fs::current_path() }; private: bool recursiveIncludeGuard { false }; std::map defines; diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index 3ddcef11..57a17e75 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -189,7 +189,7 @@ void sfz::Synth::handleControlOpcodes(const std::vector& members) [[fallthrough]]; case hash("default_path"): { const auto stringPath = absl::StrReplaceAll(trim(member.value), { { "\\", "/" } }); - const auto newPath = defaultPath / fs::path(stringPath); + const auto newPath = originalDirectory / fs::path(stringPath); if (fs::exists(newPath)) { DBG("Changing default sample path to " << stringPath); defaultPath = newPath; @@ -229,6 +229,7 @@ bool sfz::Synth::loadSfzFile(const fs::path& filename) } clear(); + defaultPath = filename.parent_path(); auto parserReturned = sfz::Parser::loadSfzFile(filename); if (!parserReturned) return false; diff --git a/src/sfizz/Synth.h b/src/sfizz/Synth.h index 9aa8b6d9..7db4a65c 100644 --- a/src/sfizz/Synth.h +++ b/src/sfizz/Synth.h @@ -446,6 +446,9 @@ private: Resources resources; MidiState midiState; + // default_path + fs::path defaultPath { }; + LEAK_DETECTOR(Synth); };