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 {
|
struct Region {
|
||||||
Region(const MidiState& midiState, std::string defaultPath = "")
|
Region(const MidiState& midiState, absl::string_view defaultPath = "")
|
||||||
: midiState(midiState), defaultPath(std::move(defaultPath))
|
: midiState(midiState), defaultPath(std::move(defaultPath))
|
||||||
{
|
{
|
||||||
if (!this->defaultPath.empty() && this->defaultPath.back() != '/')
|
|
||||||
absl::StrAppend(&this->defaultPath, "/");
|
|
||||||
|
|
||||||
ccSwitched.set();
|
ccSwitched.set();
|
||||||
}
|
}
|
||||||
Region(const Region&) = default;
|
Region(const Region&) = default;
|
||||||
|
|
@ -325,7 +322,7 @@ private:
|
||||||
bool aftertouchSwitched { true };
|
bool aftertouchSwitched { true };
|
||||||
std::bitset<config::numCCs> ccSwitched;
|
std::bitset<config::numCCs> ccSwitched;
|
||||||
bool triggerOnCC { false };
|
bool triggerOnCC { false };
|
||||||
std::string defaultPath { "" };
|
absl::string_view defaultPath { "" };
|
||||||
|
|
||||||
int activeNotesInRange { -1 };
|
int activeNotesInRange { -1 };
|
||||||
int sequenceCounter { 0 };
|
int sequenceCounter { 0 };
|
||||||
|
|
|
||||||
|
|
@ -181,14 +181,10 @@ void sfz::Synth::handleControlOpcodes(const std::vector<Opcode>& members)
|
||||||
break;
|
break;
|
||||||
case hash("Default_path"):
|
case hash("Default_path"):
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
case hash("default_path"): {
|
case hash("default_path"):
|
||||||
auto newPath = absl::StrReplaceAll(trim(member.value), { { "\\", "/" } });
|
defaultPath = absl::StrReplaceAll(trim(member.value), { { "\\", "/" } });
|
||||||
if (fs::exists(originalDirectory / newPath)) {
|
DBG("Changing default sample path to " << defaultPath);
|
||||||
DBG("Changing default sample path to " << newPath);
|
|
||||||
defaultPath = std::move(newPath);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
// Unsupported control opcode
|
// Unsupported control opcode
|
||||||
DBG("Unsupported control opcode: " << member.opcode);
|
DBG("Unsupported control opcode: " << member.opcode);
|
||||||
|
|
|
||||||
|
|
@ -330,18 +330,17 @@ TEST_CASE("[Files] Default path")
|
||||||
{
|
{
|
||||||
sfz::Synth synth;
|
sfz::Synth synth;
|
||||||
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/default_path.sfz");
|
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(0)->sample == R"(DefaultPath/SubPath1/sample1.wav)");
|
||||||
REQUIRE(synth.getRegionView(1)->sample == R"(DefaultPath/SubPath2/sample2.wav)");
|
REQUIRE(synth.getRegionView(1)->sample == R"(DefaultPath/SubPath2/sample2.wav)");
|
||||||
REQUIRE(synth.getRegionView(2)->sample == R"(DefaultPath/SubPath1/sample1.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")
|
TEST_CASE("[Files] Default path reset when calling loadSfzFile again")
|
||||||
{
|
{
|
||||||
sfz::Synth synth;
|
sfz::Synth synth;
|
||||||
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/default_path.sfz");
|
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");
|
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/default_path_reset.sfz");
|
||||||
REQUIRE(synth.getNumRegions() == 1);
|
REQUIRE(synth.getNumRegions() == 1);
|
||||||
REQUIRE(synth.getRegionView(0)->sample == R"(DefaultPath/SubPath2/sample2.wav)");
|
REQUIRE(synth.getRegionView(0)->sample == R"(DefaultPath/SubPath2/sample2.wav)");
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,7 @@
|
||||||
<region> sample=DefaultPath/SubPath1/sample1.wav
|
<region> sample=DefaultPath/SubPath1/sample1.wav
|
||||||
|
|
||||||
<control> default_path=DefaultPath\SubPath2
|
<control> default_path=DefaultPath\SubPath2\
|
||||||
<region> sample=sample2.wav
|
<region> sample=sample2.wav
|
||||||
|
|
||||||
<control> default_path=DefaultPath/SubPath1
|
<control> default_path=DefaultPath/SubPath1/sample
|
||||||
<region> sample=sample1.wav
|
<region> sample=1.wav
|
||||||
|
|
||||||
<control> default_path=DefaultPath/SubPath2/
|
|
||||||
<region> sample=sample2.wav
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue