diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index 4103f388..f947331f 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -192,8 +192,6 @@ void sfz::Synth::buildRegion(const std::vector& regionOpcodes) void sfz::Synth::clear() { - const std::lock_guard disableCallback { callbackGuard }; - // Clear the background queues before removing everyone resources.filePool.waitForBackgroundLoading(); @@ -473,10 +471,10 @@ void sfz::Synth::handleEffectOpcodes(const std::vector& rawMembers) bool sfz::Synth::loadSfzFile(const fs::path& file) { - clear(); - const std::lock_guard disableCallback { callbackGuard }; + clear(); + std::error_code ec; fs::path realFile = fs::canonical(file, ec); @@ -494,9 +492,10 @@ bool sfz::Synth::loadSfzFile(const fs::path& file) bool sfz::Synth::loadSfzString(const fs::path& path, absl::string_view text) { + const std::lock_guard disableCallback { callbackGuard }; + clear(); - const std::lock_guard disableCallback { callbackGuard }; parser.parseString(path, text); if (parser.getErrorCount() > 0) return false; diff --git a/src/sfizz/Synth.h b/src/sfizz/Synth.h index 350e98bf..d1db8a93 100644 --- a/src/sfizz/Synth.h +++ b/src/sfizz/Synth.h @@ -683,6 +683,7 @@ private: * @brief Remove all regions, resets all voices and clears everything * to bring back the synth in its original state. * + * The callback mutex should be taken to call this function. */ void clear();