Fixes to handling of path properties in presets.
This commit is contained in:
+64
-10
@@ -40,6 +40,7 @@
|
||||
#include "util.hpp"
|
||||
#include "AudioFiles.hpp"
|
||||
#include "Utf8Utils.hpp"
|
||||
#include "AtomConverter.hpp"
|
||||
|
||||
using namespace pipedal;
|
||||
namespace fs = std::filesystem;
|
||||
@@ -189,6 +190,7 @@ void Storage::SetConfigRoot(const std::filesystem::path &path)
|
||||
void Storage::SetDataRoot(const std::filesystem::path &path)
|
||||
{
|
||||
this->dataRoot = ResolveHomePath(path);
|
||||
this->dataRoot__audio_uploads = dataRoot / "audio_uploads";
|
||||
}
|
||||
|
||||
const std::filesystem::path &Storage::GetConfigRoot()
|
||||
@@ -302,9 +304,9 @@ std::filesystem::path Storage::GetPluginPresetsDirectory() const
|
||||
{
|
||||
return this->dataRoot / "plugin_presets";
|
||||
}
|
||||
std::filesystem::path Storage::GetPluginUploadDirectory() const
|
||||
const std::filesystem::path &Storage::GetPluginUploadDirectory() const
|
||||
{
|
||||
return this->dataRoot / "audio_uploads";
|
||||
return dataRoot__audio_uploads;
|
||||
}
|
||||
|
||||
std::filesystem::path Storage::GetCurrentPresetPath() const
|
||||
@@ -1409,6 +1411,10 @@ PluginPresetValues Storage::GetPluginPresetValues(const std::string &pluginUri,
|
||||
{
|
||||
result.controls.push_back(ControlValue(valuePair.first.c_str(), valuePair.second));
|
||||
}
|
||||
for (const auto&pair: preset.pathProperties_)
|
||||
{
|
||||
result.pathProperties[pair.first] = pair.second;
|
||||
}
|
||||
result.state = preset.state_;
|
||||
result.lilvPresetUri = preset.lilvPresetUri_;
|
||||
return result;
|
||||
@@ -1417,6 +1423,31 @@ PluginPresetValues Storage::GetPluginPresetValues(const std::string &pluginUri,
|
||||
throw PiPedalException("Plugin preset not found.");
|
||||
}
|
||||
|
||||
void Storage::ToAbstractPaths(PluginPreset &pluginPreset)
|
||||
{
|
||||
if (pluginPreset.pathProperties_.size() != 0)
|
||||
{
|
||||
std::map<std::string, std::string> newPathProperties;
|
||||
for (const auto &pair : pluginPreset.pathProperties_)
|
||||
{
|
||||
newPathProperties[pair.first] = this->ToAbstractPathJson(pair.second);
|
||||
}
|
||||
pluginPreset.pathProperties_ = newPathProperties;
|
||||
}
|
||||
}
|
||||
void Storage::FromAbstractPaths(PluginPreset &pluginPreset)
|
||||
{
|
||||
if (pluginPreset.pathProperties_.size() != 0)
|
||||
{
|
||||
std::map<std::string, std::string> newPathProperties;
|
||||
for (const auto &pair : pluginPreset.pathProperties_)
|
||||
{
|
||||
newPathProperties[pair.first] = this->FromAbstractPathJson(pair.second);
|
||||
}
|
||||
pluginPreset.pathProperties_ = newPathProperties;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t Storage::SavePluginPreset(
|
||||
const std::string &name,
|
||||
const PedalboardItem &pedalboardItem)
|
||||
@@ -1425,6 +1456,7 @@ uint64_t Storage::SavePluginPreset(
|
||||
auto presets = GetPluginPresets(pluginUri);
|
||||
uint64_t result = -1;
|
||||
bool existing = false;
|
||||
|
||||
for (size_t i = 0; i < presets.presets_.size(); ++i)
|
||||
{
|
||||
auto &preset = presets.presets_[i];
|
||||
@@ -1432,6 +1464,8 @@ uint64_t Storage::SavePluginPreset(
|
||||
{
|
||||
existing = true;
|
||||
result = preset.instanceId_;
|
||||
PluginPreset pluginPreset{preset.instanceId_, preset.label_, pedalboardItem};
|
||||
|
||||
presets.presets_[i] = PluginPreset(preset.instanceId_, preset.label_, pedalboardItem);
|
||||
break;
|
||||
}
|
||||
@@ -1439,10 +1473,12 @@ uint64_t Storage::SavePluginPreset(
|
||||
if (!existing)
|
||||
{
|
||||
result = presets.nextInstanceId_++;
|
||||
presets.presets_.push_back(
|
||||
PluginPreset(result,
|
||||
name,
|
||||
pedalboardItem));
|
||||
auto preset = PluginPreset(
|
||||
result,
|
||||
name,
|
||||
pedalboardItem);
|
||||
ToAbstractPaths(preset);
|
||||
presets.presets_.push_back(preset);
|
||||
}
|
||||
this->SavePluginPresets(pluginUri, presets);
|
||||
return result;
|
||||
@@ -1451,9 +1487,8 @@ uint64_t Storage::SavePluginPreset(
|
||||
uint64_t Storage::SavePluginPreset(
|
||||
const std::string &pluginUri,
|
||||
const std::string &name,
|
||||
float inputVolume,
|
||||
float outputVolume,
|
||||
const std::map<std::string, float> &values,
|
||||
const std::map<std::string,std::string> &pathProperties,
|
||||
const Lv2PluginState &lv2State)
|
||||
{
|
||||
auto presets = GetPluginPresets(pluginUri);
|
||||
@@ -1466,6 +1501,7 @@ uint64_t Storage::SavePluginPreset(
|
||||
{
|
||||
existing = true;
|
||||
preset.controlValues_ = values;
|
||||
preset.pathProperties_ = pathProperties;
|
||||
preset.state_ = lv2State;
|
||||
|
||||
result = preset.instanceId_;
|
||||
@@ -1480,6 +1516,7 @@ uint64_t Storage::SavePluginPreset(
|
||||
result,
|
||||
name,
|
||||
values,
|
||||
pathProperties,
|
||||
lv2State));
|
||||
}
|
||||
this->SavePluginPresets(pluginUri, presets);
|
||||
@@ -1533,7 +1570,7 @@ uint64_t Storage::CopyPluginPreset(const std::string &pluginUri, uint64_t preset
|
||||
size_t pos = presets.Find(presetId);
|
||||
if (pos == -1)
|
||||
{
|
||||
throw PiPedalException("Perset not found.");
|
||||
throw PiPedalException("Preset not found.");
|
||||
}
|
||||
PluginPreset t = presets.presets_[pos];
|
||||
t.instanceId_ = presets.nextInstanceId_++;
|
||||
@@ -1922,7 +1959,7 @@ static void AddTracksToResult(
|
||||
FileRequestResult Storage::GetModFileList2(const std::string &relativePath, const UiFileProperty &fileProperty)
|
||||
{
|
||||
FileRequestResult result;
|
||||
fs::path uploadsDirectory = GetPluginUploadDirectory();
|
||||
const fs::path &uploadsDirectory = GetPluginUploadDirectory();
|
||||
|
||||
if (relativePath.empty())
|
||||
{
|
||||
@@ -2651,6 +2688,23 @@ std::string Storage::GetTone3000Auth() const
|
||||
return tone3000Auth;
|
||||
}
|
||||
|
||||
std::string Storage::ToAbstractPathJson(const std::string &pathJson)
|
||||
{
|
||||
json_variant v = json_variant::parse(pathJson);
|
||||
|
||||
v = AtomConverter::AbstractPath(v,GetPluginUploadDirectory().string());
|
||||
|
||||
return v.to_string();
|
||||
}
|
||||
std::string Storage::FromAbstractPathJson(const std::string &pathJson)
|
||||
{
|
||||
json_variant v = json_variant::parse(pathJson);
|
||||
|
||||
v = AtomConverter::MapPath(v,GetPluginUploadDirectory().string());
|
||||
|
||||
return v.to_string();
|
||||
}
|
||||
|
||||
JSON_MAP_BEGIN(UserSettings)
|
||||
JSON_MAP_REFERENCE(UserSettings, governor)
|
||||
JSON_MAP_REFERENCE(UserSettings, showStatusMonitor)
|
||||
|
||||
Reference in New Issue
Block a user