Corrected the default path logic
This commit is contained in:
parent
55f1fa2c42
commit
4916b94fc3
4 changed files with 16 additions and 12 deletions
|
|
@ -29,6 +29,7 @@
|
||||||
#include "StringViewHelpers.h"
|
#include "StringViewHelpers.h"
|
||||||
#include "MidiState.h"
|
#include "MidiState.h"
|
||||||
#include "absl/strings/str_replace.h"
|
#include "absl/strings/str_replace.h"
|
||||||
|
#include "absl/strings/str_cat.h"
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
bool sfz::Region::parseOpcode(const Opcode& opcode)
|
bool sfz::Region::parseOpcode(const Opcode& opcode)
|
||||||
|
|
@ -42,7 +43,7 @@ bool sfz::Region::parseOpcode(const Opcode& opcode)
|
||||||
switch (hash(opcode.opcode)) {
|
switch (hash(opcode.opcode)) {
|
||||||
// Sound source: sample playback
|
// Sound source: sample playback
|
||||||
case hash("sample"):
|
case hash("sample"):
|
||||||
sample = absl::StrReplaceAll(trim(opcode.value), { { "\\", "/" } });
|
sample = absl::StrCat(defaultPath, absl::StrReplaceAll(trim(opcode.value), { { "\\", "/" } }));
|
||||||
break;
|
break;
|
||||||
case hash("delay"):
|
case hash("delay"):
|
||||||
setValueFromOpcode(opcode, delay, Default::delayRange);
|
setValueFromOpcode(opcode, delay, Default::delayRange);
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@
|
||||||
#include "Opcode.h"
|
#include "Opcode.h"
|
||||||
#include "AudioBuffer.h"
|
#include "AudioBuffer.h"
|
||||||
#include "MidiState.h"
|
#include "MidiState.h"
|
||||||
|
#include "absl/strings/str_cat.h"
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <absl/types/optional.h>
|
#include <absl/types/optional.h>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
@ -49,9 +50,12 @@ namespace sfz {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
struct Region {
|
struct Region {
|
||||||
Region(const MidiState& midiState)
|
Region(const MidiState& midiState, std::string defaultPath = "")
|
||||||
: midiState(midiState)
|
: 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;
|
||||||
|
|
@ -320,6 +324,7 @@ private:
|
||||||
bool bpmSwitched { true };
|
bool bpmSwitched { true };
|
||||||
bool aftertouchSwitched { true };
|
bool aftertouchSwitched { true };
|
||||||
std::bitset<128> ccSwitched;
|
std::bitset<128> ccSwitched;
|
||||||
|
std::string defaultPath { "" };
|
||||||
|
|
||||||
int activeNotesInRange { -1 };
|
int activeNotesInRange { -1 };
|
||||||
int sequenceCounter { 0 };
|
int sequenceCounter { 0 };
|
||||||
|
|
|
||||||
|
|
@ -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)
|
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) {
|
auto parseOpcodes = [&](const auto& opcodes) {
|
||||||
for (auto& opcode : opcodes) {
|
for (auto& opcode : opcodes) {
|
||||||
|
|
@ -179,11 +179,10 @@ void sfz::Synth::handleControlOpcodes(const std::vector<Opcode>& members)
|
||||||
case hash("Default_path"):
|
case hash("Default_path"):
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
case hash("default_path"): {
|
case hash("default_path"): {
|
||||||
const auto stringPath = absl::StrReplaceAll(trim(member.value), { { "\\", "/" } });
|
const auto newPath = absl::StrReplaceAll(trim(member.value), { { "\\", "/" } });
|
||||||
const auto newPath = originalDirectory / fs::path(stringPath);
|
if (fs::exists(originalDirectory / newPath)) {
|
||||||
if (fs::exists(newPath)) {
|
DBG("Changing default sample path to " << newPath);
|
||||||
DBG("Changing default sample path to " << stringPath);
|
defaultPath = std::move(newPath);
|
||||||
defaultPath = newPath;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -220,7 +219,6 @@ bool sfz::Synth::loadSfzFile(const fs::path& filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
defaultPath = filename.parent_path();
|
|
||||||
auto parserReturned = sfz::Parser::loadSfzFile(filename);
|
auto parserReturned = sfz::Parser::loadSfzFile(filename);
|
||||||
if (!parserReturned)
|
if (!parserReturned)
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -228,7 +226,7 @@ bool sfz::Synth::loadSfzFile(const fs::path& filename)
|
||||||
if (regions.empty())
|
if (regions.empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
resources.filePool.setRootDirectory(this->defaultPath);
|
resources.filePool.setRootDirectory(this->originalDirectory);
|
||||||
|
|
||||||
auto lastRegion = regions.end() - 1;
|
auto lastRegion = regions.end() - 1;
|
||||||
auto currentRegion = regions.begin();
|
auto currentRegion = regions.begin();
|
||||||
|
|
|
||||||
|
|
@ -445,7 +445,7 @@ private:
|
||||||
MidiState midiState;
|
MidiState midiState;
|
||||||
|
|
||||||
// default_path
|
// default_path
|
||||||
fs::path defaultPath { };
|
std::string defaultPath { "" };
|
||||||
|
|
||||||
LEAK_DETECTOR(Synth);
|
LEAK_DETECTOR(Synth);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue