Factory Presets, sorting of LICENSE.MD and README.md files.
This commit is contained in:
Vendored
+1
-1
@@ -170,7 +170,7 @@
|
||||
"cSpell.ignoreWords": [
|
||||
"nammodel"
|
||||
],
|
||||
"cSpell.enabled": true,
|
||||
"cSpell.enabled": false,
|
||||
|
||||
// Disable all automatic completion suggestions - only show when Ctrl+Space is pressed
|
||||
"editor.quickSuggestions": {
|
||||
|
||||
@@ -37,24 +37,6 @@ using namespace pipedal::implementation;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
|
||||
namespace pipedal::implementation {
|
||||
class BrowserFilesVersionInfo
|
||||
{
|
||||
public:
|
||||
bool Load(std::filesystem::path &path);
|
||||
void Save(std::filesystem::path &path);
|
||||
const std::vector<std::string> &InstalledFiles() const;
|
||||
bool IsInstalled(const std::string &file) const;
|
||||
void AddFile(const std::string &file);
|
||||
uint32_t Version() const;
|
||||
void Version(uint32_t value);
|
||||
|
||||
private:
|
||||
uint32_t version = 0;
|
||||
std::vector<std::string> installedFiles;
|
||||
std::unordered_set<std::string> installedFileMap;
|
||||
};
|
||||
};
|
||||
|
||||
inline uint32_t BrowserFilesVersionInfo::Version() const { return version; }
|
||||
inline void BrowserFilesVersionInfo::Version(uint32_t value) { version = value; }
|
||||
@@ -75,7 +57,7 @@ void BrowserFilesVersionInfo::AddFile(const std::string &file)
|
||||
}
|
||||
}
|
||||
|
||||
bool BrowserFilesVersionInfo::Load(std::filesystem::path &path)
|
||||
bool BrowserFilesVersionInfo::Load(const std::filesystem::path &path)
|
||||
{
|
||||
std::ifstream f{path};
|
||||
if (!f.is_open())
|
||||
@@ -102,7 +84,7 @@ FileBrowserFilesFeature::FileBrowserFilesFeature()
|
||||
feature.URI = LV2_FILEBROWSER__files;
|
||||
feature.data = &(this->featureData);
|
||||
}
|
||||
void BrowserFilesVersionInfo::Save(std::filesystem::path &path)
|
||||
void BrowserFilesVersionInfo::Save(const std::filesystem::path &path)
|
||||
{
|
||||
pipedal::ofstream_synced f{path};
|
||||
if (!f.is_open())
|
||||
|
||||
@@ -30,16 +30,35 @@
|
||||
#include <lv2/log/logger.h>
|
||||
#include <mutex>
|
||||
#include <filesystem>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
|
||||
|
||||
|
||||
namespace pipedal {
|
||||
namespace pipedal
|
||||
{
|
||||
// Private forward declaration
|
||||
namespace implementation {
|
||||
class BrowserFilesVersionInfo;
|
||||
namespace implementation
|
||||
{
|
||||
class BrowserFilesVersionInfo
|
||||
{
|
||||
public:
|
||||
bool Load(const std::filesystem::path &path);
|
||||
void Save(const std::filesystem::path &path);
|
||||
const std::vector<std::string> &InstalledFiles() const;
|
||||
bool IsInstalled(const std::string &file) const;
|
||||
void AddFile(const std::string &file);
|
||||
uint32_t Version() const;
|
||||
void Version(uint32_t value);
|
||||
|
||||
private:
|
||||
uint32_t version = 0;
|
||||
std::vector<std::string> installedFiles;
|
||||
std::unordered_set<std::string> installedFileMap;
|
||||
};
|
||||
};
|
||||
|
||||
class FileBrowserFilesFeature {
|
||||
class FileBrowserFilesFeature
|
||||
{
|
||||
public:
|
||||
FileBrowserFilesFeature();
|
||||
void Initialize(
|
||||
@@ -48,6 +67,7 @@ namespace pipedal {
|
||||
const std::string &bundleDirectory,
|
||||
const std::string &browserDirectory);
|
||||
const LV2_Feature *GetFeature() { return &feature; }
|
||||
|
||||
private:
|
||||
static void MakeDirectoryMap(const std::filesystem::path &rootBrowserDirectory);
|
||||
|
||||
@@ -55,7 +75,6 @@ namespace pipedal {
|
||||
static std::mutex g_DirectoryMap_mutex;
|
||||
static std::unique_ptr<WellKnownDirectoryMap> g_wellKnownDirectoryMap;
|
||||
|
||||
|
||||
LV2_Feature feature;
|
||||
const LV2_URID_Map *lv2Map = nullptr;
|
||||
LV2_Log_Logger lv2Logger = {nullptr, 0, 0, 0, 0};
|
||||
@@ -67,7 +86,6 @@ namespace pipedal {
|
||||
|
||||
std::map<std::string, std::string> wellKnownPaths;
|
||||
|
||||
|
||||
static char *FN_get_upload_path(LV2_FileBrowser_Files_Handle handle, const char *fileBrowserDirectory);
|
||||
static char *FN_map_path(LV2_FileBrowser_Files_Handle handle, const char *path, const char *resourcePathBase, const char *fileBrowserDirectory);
|
||||
static void FN_free_path(LV2_FileBrowser_Files_Handle handle, char *path);
|
||||
@@ -85,7 +103,6 @@ namespace pipedal {
|
||||
implementation::BrowserFilesVersionInfo &versionInfo,
|
||||
const std::filesystem::path &rootResourcePath,
|
||||
const std::filesystem::path &resourcePath,
|
||||
const std::filesystem::path& browserPath
|
||||
);
|
||||
const std::filesystem::path &browserPath);
|
||||
};
|
||||
}
|
||||
+135
-12
@@ -41,6 +41,7 @@
|
||||
#include "AudioFiles.hpp"
|
||||
#include "Utf8Utils.hpp"
|
||||
#include "AtomConverter.hpp"
|
||||
#include "FileBrowserFilesFeature.hpp"
|
||||
|
||||
using namespace pipedal;
|
||||
namespace fs = std::filesystem;
|
||||
@@ -222,23 +223,122 @@ static void CopyDirectory(const std::filesystem::path &source, const std::filesy
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Storage::MaybeCopyDefaultPresets()
|
||||
{
|
||||
auto presetsDirectory = this->GetPresetsDirectory();
|
||||
auto presetsDirectory = this->GetPresetsDirectory();
|
||||
auto presetsConfigDirectory = this->configRoot / "default_presets" / "presets";
|
||||
|
||||
if (!std::filesystem::exists(presetsDirectory / "index.banks"))
|
||||
{
|
||||
CopyDirectory(this->configRoot / "default_presets" / "presets",
|
||||
presetsDirectory);
|
||||
fs::copy(presetsConfigDirectory / "index.banks", presetsDirectory / "index.banks");
|
||||
fs::copy(presetsConfigDirectory / "Default+Bank.bank", presetsDirectory / "Default+Bank.bank");
|
||||
}
|
||||
}
|
||||
void Storage::UpgradeFactoryPresets()
|
||||
{
|
||||
auto presetsDirectory = this->GetPresetsDirectory();
|
||||
auto presetsConfigDirectory = this->configRoot / "default_presets" / "presets";
|
||||
|
||||
using namespace ::pipedal::implementation;
|
||||
|
||||
BrowserFilesVersionInfo defaultConfigPresetsVersion;
|
||||
fs::path defaultConfigPresetsVersionFile = presetsConfigDirectory / "banks.versionInfo";
|
||||
defaultConfigPresetsVersion.Load(defaultConfigPresetsVersionFile);
|
||||
|
||||
BrowserFilesVersionInfo presetsVersion;
|
||||
fs::path defaultPresetsVersionFile = presetsDirectory / "banks.versionInfo";
|
||||
presetsVersion.Load(defaultPresetsVersionFile);
|
||||
|
||||
// Maybe install or upgrade factory presets.
|
||||
if (defaultConfigPresetsVersion.Version() > presetsVersion.Version() || defaultConfigPresetsVersion.Version() == 0)
|
||||
{
|
||||
|
||||
std::string name = "Factory Presets";
|
||||
BankFile newFactoryPresets;
|
||||
{
|
||||
fs::path defaultBankPath = presetsConfigDirectory / "Default+Bank.bank";
|
||||
try
|
||||
{
|
||||
std::ifstream is(defaultBankPath);
|
||||
json_reader reader(is);
|
||||
reader.read(&newFactoryPresets);
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
Lv2Log::error(SS("Failed to isntall factory presets. Can't read " << defaultBankPath << "."));
|
||||
}
|
||||
}
|
||||
newFactoryPresets.name("Factory Presets");
|
||||
|
||||
BankIndexEntry *existingEntry = bankIndex.getEntryByName(name);
|
||||
if (existingEntry == nullptr)
|
||||
{
|
||||
BankFile bankFile;
|
||||
bankFile.name(name);
|
||||
|
||||
for (auto &presetEntry : newFactoryPresets.presets())
|
||||
{
|
||||
bankFile.addPreset(presetEntry->preset(), -1);
|
||||
}
|
||||
|
||||
// Obsolete: TooB effects now have correct preset declarations.
|
||||
// auto pluginDirectory = this->GetPluginPresetsDirectory();
|
||||
// if (!std::filesystem::exists(pluginDirectory / "index.json"))
|
||||
// {
|
||||
// CopyDirectory(this->configRoot / "default_presets" / "plugin_presets",
|
||||
// pluginDirectory);
|
||||
// }
|
||||
int64_t instanceId = bankFile.presets()[0]->instanceId();
|
||||
bankFile.selectedPreset(instanceId);
|
||||
SaveBankFile(name, bankFile);
|
||||
this->bankIndex.addBank(-1, name);
|
||||
this->SaveBankIndex();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
// either use the current bank (if the factory bank is selected), or create a new one.
|
||||
BankFile bankFile;
|
||||
bankFile.name(name);
|
||||
BankFile *pFactoryPresetsBank = nullptr;
|
||||
bool usingCurrentBank = false;
|
||||
if (bankIndex.selectedBank() == existingEntry->instanceId())
|
||||
{
|
||||
usingCurrentBank = true;
|
||||
pFactoryPresetsBank = &(this->currentBank);
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadBankFile(name, &bankFile);
|
||||
pFactoryPresetsBank = &bankFile;
|
||||
}
|
||||
// index existing presets.
|
||||
std::unordered_map<std::string, size_t> nameToPositionIndex;
|
||||
for (size_t i = 0; i < pFactoryPresetsBank->presets().size(); ++i)
|
||||
{
|
||||
auto &preset = pFactoryPresetsBank->presets()[i];
|
||||
nameToPositionIndex[preset->preset().name()] = i;
|
||||
}
|
||||
|
||||
// merge new presets into the existing ones (overwriting as neccessary)
|
||||
for (auto &newPresetEntry : newFactoryPresets.presets())
|
||||
{
|
||||
const std::string name = newPresetEntry->preset().name();
|
||||
|
||||
auto f = nameToPositionIndex.find(name);
|
||||
if (f != nameToPositionIndex.end())
|
||||
{
|
||||
size_t postition = f->second;
|
||||
// overwrite the existing entry.
|
||||
pFactoryPresetsBank->presets()[postition]->preset(newPresetEntry->preset());
|
||||
}
|
||||
else
|
||||
{
|
||||
pFactoryPresetsBank->addPreset(newPresetEntry->preset());
|
||||
}
|
||||
}
|
||||
SaveBankFile(name, *pFactoryPresetsBank);
|
||||
|
||||
presetsVersion.Version(defaultConfigPresetsVersion.Version());
|
||||
presetsVersion.Save(defaultPresetsVersionFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
void Storage::Initialize()
|
||||
{
|
||||
@@ -269,6 +369,7 @@ void Storage::Initialize()
|
||||
LoadWifiConfigSettings();
|
||||
LoadWifiDirectConfigSettings();
|
||||
LoadUserSettings();
|
||||
UpgradeFactoryPresets();
|
||||
}
|
||||
|
||||
void Storage::LoadBank(int64_t instanceId)
|
||||
@@ -1248,7 +1349,6 @@ void Storage::SetPluginPresetIndexVersion(uint64_t version)
|
||||
this->pluginPresetIndex.version_ = version;
|
||||
SavePluginPresetIndex();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool Storage::HasPluginPresets(const std::string &pluginUri) const
|
||||
@@ -1503,8 +1603,7 @@ uint64_t Storage::SavePluginPreset(
|
||||
|
||||
uint64_t Storage::SavePluginPreset(
|
||||
const std::string &pluginUri,
|
||||
PluginPreset &pluginPreset
|
||||
)
|
||||
PluginPreset &pluginPreset)
|
||||
{
|
||||
auto presets = GetPluginPresets(pluginUri);
|
||||
uint64_t result = -1;
|
||||
@@ -1797,6 +1896,17 @@ static bool ensureNoDotDot(const std::filesystem::path &path)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool isInfoFile(const FileEntry &l)
|
||||
{
|
||||
if (l.displayName_.starts_with("LICENSE"))
|
||||
return true;
|
||||
if (l.displayName_.starts_with("README"))
|
||||
return true;
|
||||
if (l.displayName_.find(".md") == l.displayName_.length() - 3)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static void AddFilesToResult(
|
||||
FileRequestResult &result,
|
||||
const ModFileTypes::ModDirectory *modDirectoryInfo, // yyx
|
||||
@@ -1862,6 +1972,12 @@ static void AddFilesToResult(
|
||||
{
|
||||
return l.isDirectory_ > r.isDirectory_;
|
||||
}
|
||||
bool lIsInfoFile = isInfoFile(l);
|
||||
bool rIsInfoFile = isInfoFile(r);
|
||||
if (lIsInfoFile != rIsInfoFile)
|
||||
{
|
||||
return lIsInfoFile > rIsInfoFile;
|
||||
}
|
||||
return collator->Compare(l.displayName_,r.displayName_) < 0; });
|
||||
}
|
||||
|
||||
@@ -1931,6 +2047,13 @@ static void AddTracksToResult(
|
||||
{
|
||||
return l.isDirectory_ > r.isDirectory_;
|
||||
}
|
||||
bool lIsInfoFile = isInfoFile(l);
|
||||
bool rIsInfoFile = isInfoFile(r);
|
||||
if (lIsInfoFile != rIsInfoFile)
|
||||
{
|
||||
return lIsInfoFile < rIsInfoFile;
|
||||
}
|
||||
|
||||
return collator->Compare(l.displayName_, r.displayName_) < 0;
|
||||
});
|
||||
// Add audio files.
|
||||
|
||||
+1
-3
@@ -66,8 +66,6 @@ struct PluginPresetValues {
|
||||
};
|
||||
|
||||
|
||||
// controls user-defined storage. Implmentation hidden to allow to later migration to a database (perhaps)
|
||||
|
||||
class Storage {
|
||||
private:
|
||||
std::filesystem::path dataRoot;
|
||||
@@ -81,7 +79,7 @@ private:
|
||||
|
||||
private:
|
||||
void FillSampleDirectoryTree(FilePropertyDirectoryTree*node, const std::filesystem::path&directory) const;
|
||||
|
||||
void UpgradeFactoryPresets();
|
||||
void MaybeCopyDefaultPresets();
|
||||
static std::string SafeEncodeName(const std::string& name);
|
||||
static std::string SafeDecodeName(const std::string& name);
|
||||
|
||||
Reference in New Issue
Block a user