Corrected the default path logic

This commit is contained in:
Paul Ferrand 2019-12-15 17:48:12 +01:00
parent 55f1fa2c42
commit 4916b94fc3
4 changed files with 16 additions and 12 deletions

View file

@ -29,6 +29,7 @@
#include "StringViewHelpers.h"
#include "MidiState.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/str_cat.h"
#include <random>
bool sfz::Region::parseOpcode(const Opcode& opcode)
@ -42,7 +43,7 @@ bool sfz::Region::parseOpcode(const Opcode& opcode)
switch (hash(opcode.opcode)) {
// Sound source: sample playback
case hash("sample"):
sample = absl::StrReplaceAll(trim(opcode.value), { { "\\", "/" } });
sample = absl::StrCat(defaultPath, absl::StrReplaceAll(trim(opcode.value), { { "\\", "/" } }));
break;
case hash("delay"):
setValueFromOpcode(opcode, delay, Default::delayRange);

View file

@ -29,6 +29,7 @@
#include "Opcode.h"
#include "AudioBuffer.h"
#include "MidiState.h"
#include "absl/strings/str_cat.h"
#include <bitset>
#include <absl/types/optional.h>
#include <random>
@ -49,9 +50,12 @@ namespace sfz {
*
*/
struct Region {
Region(const MidiState& midiState)
: midiState(midiState)
Region(const MidiState& midiState, std::string defaultPath = "")
: midiState(midiState), defaultPath(std::move(defaultPath))
{
if (!this->defaultPath.empty() && this->defaultPath.back() != '/')
absl::StrAppend(&this->defaultPath, "/");
ccSwitched.set();
}
Region(const Region&) = default;
@ -320,6 +324,7 @@ private:
bool bpmSwitched { true };
bool aftertouchSwitched { true };
std::bitset<128> ccSwitched;
std::string defaultPath { "" };
int activeNotesInRange { -1 };
int sequenceCounter { 0 };

View file

@ -94,7 +94,7 @@ void sfz::Synth::callback(absl::string_view header, const std::vector<Opcode>& m
void sfz::Synth::buildRegion(const std::vector<Opcode>& regionOpcodes)
{
auto lastRegion = std::make_unique<Region>(midiState);
auto lastRegion = std::make_unique<Region>(midiState, defaultPath);
auto parseOpcodes = [&](const auto& opcodes) {
for (auto& opcode : opcodes) {
@ -179,11 +179,10 @@ void sfz::Synth::handleControlOpcodes(const std::vector<Opcode>& members)
case hash("Default_path"):
[[fallthrough]];
case hash("default_path"): {
const auto stringPath = absl::StrReplaceAll(trim(member.value), { { "\\", "/" } });
const auto newPath = originalDirectory / fs::path(stringPath);
if (fs::exists(newPath)) {
DBG("Changing default sample path to " << stringPath);
defaultPath = newPath;
const auto newPath = absl::StrReplaceAll(trim(member.value), { { "\\", "/" } });
if (fs::exists(originalDirectory / newPath)) {
DBG("Changing default sample path to " << newPath);
defaultPath = std::move(newPath);
}
break;
}
@ -220,7 +219,6 @@ bool sfz::Synth::loadSfzFile(const fs::path& filename)
}
clear();
defaultPath = filename.parent_path();
auto parserReturned = sfz::Parser::loadSfzFile(filename);
if (!parserReturned)
return false;
@ -228,7 +226,7 @@ bool sfz::Synth::loadSfzFile(const fs::path& filename)
if (regions.empty())
return false;
resources.filePool.setRootDirectory(this->defaultPath);
resources.filePool.setRootDirectory(this->originalDirectory);
auto lastRegion = regions.end() - 1;
auto currentRegion = regions.begin();

View file

@ -445,7 +445,7 @@ private:
MidiState midiState;
// default_path
fs::path defaultPath { };
std::string defaultPath { "" };
LEAK_DETECTOR(Synth);
};