Corrected a bug with default_path

Generators should ignore the default_path
This commit is contained in:
Paul Ferrand 2019-12-16 00:00:58 +01:00
parent 92254e8c98
commit dc879a8a07
3 changed files with 20 additions and 1 deletions

View file

@ -43,7 +43,16 @@ bool sfz::Region::parseOpcode(const Opcode& opcode)
switch (hash(opcode.opcode)) {
// Sound source: sample playback
case hash("sample"):
sample = absl::StrCat(defaultPath, absl::StrReplaceAll(trim(opcode.value), { { "\\", "/" } }));
{
const auto trimmedSample = trim(opcode.value);
if (trimmedSample.empty())
break;
if (trimmedSample[0] == '*')
sample = std::string(trimmedSample);
else
sample = absl::StrCat(defaultPath, absl::StrReplaceAll(trim(opcode.value), { { "\\", "/" } }));
}
break;
case hash("delay"):
setValueFromOpcode(opcode, delay, Default::delayRange);

View file

@ -380,4 +380,12 @@ TEST_CASE("[Files] Default path reset when calling loadSfzFile again")
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)");
}
TEST_CASE("[Files] Default path is ignored for generators")
{
sfz::Synth synth;
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/default_path_generator.sfz");
REQUIRE(synth.getNumRegions() == 1);
REQUIRE(synth.getRegionView(0)->sample == R"(*sine)");
}

View file

@ -0,0 +1,2 @@
<control> default_path=DefaultPath/SubPath1
<region> sample=*sine