Change default_path to handle partial paths
This commit is contained in:
parent
68bf0b132d
commit
8d2be44c57
5 changed files with 16 additions and 27 deletions
|
|
@ -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<config::numCCs> ccSwitched;
|
||||
bool triggerOnCC { false };
|
||||
std::string defaultPath { "" };
|
||||
absl::string_view defaultPath { "" };
|
||||
|
||||
int activeNotesInRange { -1 };
|
||||
int sequenceCounter { 0 };
|
||||
|
|
|
|||
|
|
@ -181,14 +181,10 @@ void sfz::Synth::handleControlOpcodes(const std::vector<Opcode>& 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);
|
||||
|
|
|
|||
|
|
@ -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)");
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
<region> sample=DefaultPath/SubPath1/sample1.wav
|
||||
|
||||
<control> default_path=DefaultPath\SubPath2
|
||||
<control> default_path=DefaultPath\SubPath2\
|
||||
<region> sample=sample2.wav
|
||||
|
||||
<control> default_path=DefaultPath/SubPath1
|
||||
<region> sample=sample1.wav
|
||||
|
||||
<control> default_path=DefaultPath/SubPath2/
|
||||
<region> sample=sample2.wav
|
||||
<control> default_path=DefaultPath/SubPath1/sample
|
||||
<region> sample=1.wav
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue