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 "SfizzFileScan.h"
|
||||||
#include "SfizzForeignPaths.h"
|
#include "SfizzForeignPaths.h"
|
||||||
|
#include "SfizzSettings.h"
|
||||||
#include "NativeHelpers.h"
|
#include "NativeHelpers.h"
|
||||||
#include <absl/strings/ascii.h>
|
#include <absl/strings/ascii.h>
|
||||||
#include <absl/algorithm/container.h>
|
#include <absl/algorithm/container.h>
|
||||||
#include <vector>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
// wait at least this much before refreshing the file rescan
|
// wait at least this much before refreshing the file rescan
|
||||||
|
|
@ -63,7 +63,7 @@ void SfzFileScan::refreshScan(bool force)
|
||||||
|
|
||||||
FileTrieBuilder builder;
|
FileTrieBuilder builder;
|
||||||
|
|
||||||
for (const fs::path& dirPath : SfizzPaths::sfzDefaultPaths()) {
|
for (const fs::path& dirPath : SfizzPaths::getSfzSearchPaths()) {
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
const fs::directory_options dirOpts =
|
const fs::directory_options dirOpts =
|
||||||
fs::directory_options::skip_permission_denied;
|
fs::directory_options::skip_permission_denied;
|
||||||
|
|
@ -183,36 +183,52 @@ const fs::path& SfzFileScan::electBestMatch(const fs::path& path, absl::Span<con
|
||||||
|
|
||||||
namespace SfizzPaths {
|
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;
|
||||||
std::vector<fs::path> paths;
|
paths.reserve(8);
|
||||||
paths.reserve(8);
|
auto addPath = [&paths](const fs::path& newPath) {
|
||||||
auto addPath = [&paths](const fs::path& newPath) {
|
if (absl::c_find(paths, newPath) == paths.end())
|
||||||
if (absl::c_find(paths, newPath) == paths.end())
|
paths.push_back(newPath);
|
||||||
paths.push_back(newPath);
|
};
|
||||||
};
|
|
||||||
|
|
||||||
addPath(getUserDocumentsDirectory() / "SFZ instruments");
|
absl::optional<fs::path> configDefaultPath = getSfzConfigDefaultPath();
|
||||||
|
fs::path fallbackDefaultPath = getSfzFallbackDefaultPath();
|
||||||
|
|
||||||
for (const fs::path& foreign : {
|
if (configDefaultPath)
|
||||||
getAriaPathSetting("user_files_dir"),
|
addPath(*configDefaultPath);
|
||||||
getAriaPathSetting("Converted_path") })
|
addPath(fallbackDefaultPath);
|
||||||
if (!foreign.empty() && foreign.is_absolute())
|
|
||||||
addPath(foreign);
|
|
||||||
|
|
||||||
paths.shrink_to_fit();
|
for (const fs::path& foreign : {
|
||||||
return paths;
|
getAriaPathSetting("user_files_dir"),
|
||||||
}();
|
getAriaPathSetting("Converted_path") })
|
||||||
|
if (!foreign.empty() && foreign.is_absolute())
|
||||||
|
addPath(foreign);
|
||||||
|
|
||||||
|
paths.shrink_to_fit();
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
void createSfzDefaultPaths()
|
absl::optional<fs::path> getSfzConfigDefaultPath()
|
||||||
{
|
{
|
||||||
for (const fs::path& path : sfzDefaultPaths()) {
|
SfizzSettings settings;
|
||||||
std::error_code ec;
|
fs::path path = fs::u8path(settings.load_or("user_files_dir", {}));
|
||||||
fs::create_directory(path, ec);
|
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
|
} // namespace SfizzPaths
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
#include <absl/types/optional.h>
|
#include <absl/types/optional.h>
|
||||||
#include <ghc/fs_std.hpp>
|
#include <ghc/fs_std.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
@ -35,6 +36,8 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace SfizzPaths {
|
namespace SfizzPaths {
|
||||||
absl::Span<const fs::path> sfzDefaultPaths();
|
std::vector<fs::path> getSfzSearchPaths();
|
||||||
void createSfzDefaultPaths();
|
absl::optional<fs::path> getSfzConfigDefaultPath();
|
||||||
|
void setSfzConfigDefaultPath(const fs::path& path);
|
||||||
|
fs::path getSfzFallbackDefaultPath();
|
||||||
} // namespace SfizzPaths
|
} // namespace SfizzPaths
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,18 @@ SfizzVstProcessor::SfizzVstProcessor()
|
||||||
{
|
{
|
||||||
setControllerClass(SfizzVstController::cid);
|
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()
|
SfizzVstProcessor::~SfizzVstProcessor()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue