diff --git a/src/sfizz/Region.h b/src/sfizz/Region.h index c8b55262..6c7a3653 100644 --- a/src/sfizz/Region.h +++ b/src/sfizz/Region.h @@ -50,12 +50,9 @@ namespace sfz { * */ struct Region { - Region(const MidiState& midiState, std::string defaultPath = "") + Region(const MidiState& midiState, absl::string_view defaultPath = "") : midiState(midiState), defaultPath(std::move(defaultPath)) { - if (!this->defaultPath.empty() && this->defaultPath.back() != '/') - absl::StrAppend(&this->defaultPath, "/"); - ccSwitched.set(); } Region(const Region&) = default; @@ -325,7 +322,7 @@ private: bool aftertouchSwitched { true }; std::bitset ccSwitched; bool triggerOnCC { false }; - std::string defaultPath { "" }; + absl::string_view defaultPath { "" }; int activeNotesInRange { -1 }; int sequenceCounter { 0 }; diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index 03365421..c809270e 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -181,14 +181,10 @@ void sfz::Synth::handleControlOpcodes(const std::vector& members) break; case hash("Default_path"): [[fallthrough]]; - case hash("default_path"): { - auto newPath = absl::StrReplaceAll(trim(member.value), { { "\\", "/" } }); - if (fs::exists(originalDirectory / newPath)) { - DBG("Changing default sample path to " << newPath); - defaultPath = std::move(newPath); - } + case hash("default_path"): + defaultPath = absl::StrReplaceAll(trim(member.value), { { "\\", "/" } }); + DBG("Changing default sample path to " << defaultPath); break; - } default: // Unsupported control opcode DBG("Unsupported control opcode: " << member.opcode); @@ -423,7 +419,7 @@ void sfz::Synth::noteOff(int delay, int channel, int noteNumber, uint8_t velocit // auto replacedVelocity = (velocity == 0 ? sfz::getNoteVelocity(noteNumber) : velocity); auto replacedVelocity = midiState.getNoteVelocity(channel, noteNumber); auto randValue = randNoteDistribution(Random::randomGenerator); - + for (auto& voice : voices) voice->registerNoteOff(delay, channel, noteNumber, replacedVelocity); @@ -452,7 +448,7 @@ void sfz::Synth::cc(int delay, int channel, int ccNumber, uint8_t ccValue) noexc return; } - midiState.ccEvent(channel, ccNumber, ccValue); + midiState.ccEvent(channel, ccNumber, ccValue); for (auto& voice : voices) voice->registerCC(delay, channel, ccNumber, ccValue); @@ -628,4 +624,4 @@ void sfz::Synth::resetAllControllers(int delay, int channel) noexcept for (int cc = 0; cc < config::numCCs; ++cc) region->registerCC(channel, cc, 0); } -} \ No newline at end of file +} diff --git a/src/sfizz/Synth.h b/src/sfizz/Synth.h index f65ac479..3fc5a3ed 100644 --- a/src/sfizz/Synth.h +++ b/src/sfizz/Synth.h @@ -361,10 +361,10 @@ protected: private: /** * @brief Reset all CCs; to be used on CC 121 - * + * * @param delay the delay for the controller reset * @param channel the channel on which to reset the controller - * + * */ void resetAllControllers(int delay, int channel) noexcept; diff --git a/tests/FilesT.cpp b/tests/FilesT.cpp index 1a0e3179..cd2bb267 100644 --- a/tests/FilesT.cpp +++ b/tests/FilesT.cpp @@ -330,18 +330,17 @@ TEST_CASE("[Files] Default path") { sfz::Synth synth; synth.loadSfzFile(fs::current_path() / "tests/TestFiles/default_path.sfz"); - REQUIRE(synth.getNumRegions() == 4); + REQUIRE(synth.getNumRegions() == 3); REQUIRE(synth.getRegionView(0)->sample == R"(DefaultPath/SubPath1/sample1.wav)"); REQUIRE(synth.getRegionView(1)->sample == R"(DefaultPath/SubPath2/sample2.wav)"); REQUIRE(synth.getRegionView(2)->sample == R"(DefaultPath/SubPath1/sample1.wav)"); - REQUIRE(synth.getRegionView(3)->sample == R"(DefaultPath/SubPath2/sample2.wav)"); } TEST_CASE("[Files] Default path reset when calling loadSfzFile again") { sfz::Synth synth; synth.loadSfzFile(fs::current_path() / "tests/TestFiles/default_path.sfz"); - REQUIRE(synth.getNumRegions() == 4); + REQUIRE(synth.getNumRegions() == 3); synth.loadSfzFile(fs::current_path() / "tests/TestFiles/default_path_reset.sfz"); REQUIRE(synth.getNumRegions() == 1); REQUIRE(synth.getRegionView(0)->sample == R"(DefaultPath/SubPath2/sample2.wav)"); @@ -364,4 +363,4 @@ TEST_CASE("[Files] Set CC applies properly to all channels") REQUIRE(synth.getMidiState().getCCValue(channel, 142) == 63); REQUIRE(synth.getMidiState().getCCValue(channel, 61) == 122); } -} \ No newline at end of file +} diff --git a/tests/TestFiles/default_path.sfz b/tests/TestFiles/default_path.sfz index 87a400b7..d77c61ea 100644 --- a/tests/TestFiles/default_path.sfz +++ b/tests/TestFiles/default_path.sfz @@ -1,10 +1,7 @@ sample=DefaultPath/SubPath1/sample1.wav - default_path=DefaultPath\SubPath2 + default_path=DefaultPath\SubPath2\ sample=sample2.wav - default_path=DefaultPath/SubPath1 - sample=sample1.wav - - default_path=DefaultPath/SubPath2/ - sample=sample2.wav \ No newline at end of file + default_path=DefaultPath/SubPath1/sample + sample=1.wav