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);
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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