Use a custom SFZ path set in user configuration
This commit is contained in:
parent
0acbce5274
commit
0cb1b67bfa
3 changed files with 57 additions and 27 deletions
|
|
@ -6,10 +6,10 @@
|
|||
|
||||
#include "SfizzFileScan.h"
|
||||
#include "SfizzForeignPaths.h"
|
||||
#include "SfizzSettings.h"
|
||||
#include "NativeHelpers.h"
|
||||
#include <absl/strings/ascii.h>
|
||||
#include <absl/algorithm/container.h>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
// wait at least this much before refreshing the file rescan
|
||||
|
|
@ -63,7 +63,7 @@ void SfzFileScan::refreshScan(bool force)
|
|||
|
||||
FileTrieBuilder builder;
|
||||
|
||||
for (const fs::path& dirPath : SfizzPaths::sfzDefaultPaths()) {
|
||||
for (const fs::path& dirPath : SfizzPaths::getSfzSearchPaths()) {
|
||||
std::error_code ec;
|
||||
const fs::directory_options dirOpts =
|
||||
fs::directory_options::skip_permission_denied;
|
||||
|
|
@ -183,36 +183,52 @@ const fs::path& SfzFileScan::electBestMatch(const fs::path& path, absl::Span<con
|
|||
|
||||
namespace SfizzPaths {
|
||||
|
||||
absl::Span<const fs::path> sfzDefaultPaths()
|
||||
std::vector<fs::path> getSfzSearchPaths()
|
||||
{
|
||||
static const auto paths = []() -> std::vector<fs::path> {
|
||||
std::vector<fs::path> paths;
|
||||
paths.reserve(8);
|
||||
auto addPath = [&paths](const fs::path& newPath) {
|
||||
if (absl::c_find(paths, newPath) == paths.end())
|
||||
paths.push_back(newPath);
|
||||
};
|
||||
std::vector<fs::path> paths;
|
||||
paths.reserve(8);
|
||||
auto addPath = [&paths](const fs::path& newPath) {
|
||||
if (absl::c_find(paths, newPath) == paths.end())
|
||||
paths.push_back(newPath);
|
||||
};
|
||||
|
||||
addPath(getUserDocumentsDirectory() / "SFZ instruments");
|
||||
absl::optional<fs::path> configDefaultPath = getSfzConfigDefaultPath();
|
||||
fs::path fallbackDefaultPath = getSfzFallbackDefaultPath();
|
||||
|
||||
for (const fs::path& foreign : {
|
||||
getAriaPathSetting("user_files_dir"),
|
||||
getAriaPathSetting("Converted_path") })
|
||||
if (!foreign.empty() && foreign.is_absolute())
|
||||
addPath(foreign);
|
||||
if (configDefaultPath)
|
||||
addPath(*configDefaultPath);
|
||||
addPath(fallbackDefaultPath);
|
||||
|
||||
paths.shrink_to_fit();
|
||||
return paths;
|
||||
}();
|
||||
for (const fs::path& foreign : {
|
||||
getAriaPathSetting("user_files_dir"),
|
||||
getAriaPathSetting("Converted_path") })
|
||||
if (!foreign.empty() && foreign.is_absolute())
|
||||
addPath(foreign);
|
||||
|
||||
paths.shrink_to_fit();
|
||||
return paths;
|
||||
}
|
||||
|
||||
void createSfzDefaultPaths()
|
||||
absl::optional<fs::path> getSfzConfigDefaultPath()
|
||||
{
|
||||
for (const fs::path& path : sfzDefaultPaths()) {
|
||||
std::error_code ec;
|
||||
fs::create_directory(path, ec);
|
||||
}
|
||||
SfizzSettings settings;
|
||||
fs::path path = fs::u8path(settings.load_or("user_files_dir", {}));
|
||||
if (path.empty() || !path.is_absolute())
|
||||
return {};
|
||||
return std::move(path);
|
||||
}
|
||||
|
||||
void setSfzConfigDefaultPath(const fs::path& path)
|
||||
{
|
||||
if (path.empty() || !path.is_absolute())
|
||||
return;
|
||||
SfizzSettings settings;
|
||||
settings.store("user_files_dir", path.u8string());
|
||||
}
|
||||
|
||||
fs::path getSfzFallbackDefaultPath()
|
||||
{
|
||||
return getUserDocumentsDirectory() / "SFZ instruments";
|
||||
}
|
||||
|
||||
} // namespace SfizzPaths
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include <absl/types/optional.h>
|
||||
#include <ghc/fs_std.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <unordered_map>
|
||||
#include <mutex>
|
||||
|
|
@ -35,6 +36,8 @@ private:
|
|||
};
|
||||
|
||||
namespace SfizzPaths {
|
||||
absl::Span<const fs::path> sfzDefaultPaths();
|
||||
void createSfzDefaultPaths();
|
||||
std::vector<fs::path> getSfzSearchPaths();
|
||||
absl::optional<fs::path> getSfzConfigDefaultPath();
|
||||
void setSfzConfigDefaultPath(const fs::path& path);
|
||||
fs::path getSfzFallbackDefaultPath();
|
||||
} // namespace SfizzPaths
|
||||
|
|
|
|||
|
|
@ -38,7 +38,18 @@ SfizzVstProcessor::SfizzVstProcessor()
|
|||
{
|
||||
setControllerClass(SfizzVstController::cid);
|
||||
|
||||
SfizzPaths::createSfzDefaultPaths();
|
||||
// ensure the SFZ path exists:
|
||||
// the one specified in the configuration, otherwise the fallback
|
||||
absl::optional<fs::path> configDefaultPath = SfizzPaths::getSfzConfigDefaultPath();
|
||||
if (configDefaultPath) {
|
||||
std::error_code ec;
|
||||
fs::create_directory(*configDefaultPath, ec);
|
||||
}
|
||||
else {
|
||||
fs::path fallbackDefaultPath = SfizzPaths::getSfzFallbackDefaultPath();
|
||||
std::error_code ec;
|
||||
fs::create_directory(fallbackDefaultPath, ec);
|
||||
}
|
||||
}
|
||||
|
||||
SfizzVstProcessor::~SfizzVstProcessor()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue