Plugin favorites

Fixes #40
This commit is contained in:
Robin Davies
2022-03-18 22:30:47 -04:00
parent 6359c1a7fa
commit 34b665ded5
12 changed files with 242 additions and 23 deletions
+3 -3
View File
@@ -378,7 +378,7 @@ void InstallJackService()
// deploy the systemd service file
std::map<std::string, std::string> map; // nothing to customize.
WriteTemplateFile(map, std::filesystem::path("/etc/pipedal/templateJack.service"), GetServiceFileName(JACK_SERVICE));
WriteTemplateFile(map, std::filesystem::path("/etc/pipedal/config/templateJack.service"), GetServiceFileName(JACK_SERVICE));
MaybeStartJackService();
}
@@ -554,7 +554,7 @@ void Install(const std::filesystem::path &programPrefix, const std::string endpo
map["COMMAND"] = s.str();
}
WriteTemplateFile(map, std::filesystem::path("/etc/pipedal/template.service"), GetServiceFileName(NATIVE_SERVICE));
WriteTemplateFile(map, std::filesystem::path("/etc/pipedal/config/template.service"), GetServiceFileName(NATIVE_SERVICE));
map["DESCRIPTION"] = "PiPedal Shutdown Service";
{
@@ -566,7 +566,7 @@ void Install(const std::filesystem::path &programPrefix, const std::string endpo
map["COMMAND"] = s.str();
}
WriteTemplateFile(map, std::filesystem::path("/etc/pipedal/templateShutdown.service"), GetServiceFileName(ADMIN_SERVICE));
WriteTemplateFile(map, std::filesystem::path("/etc/pipedal/config/templateAdmin.service"), GetServiceFileName(ADMIN_SERVICE));
sysExec(SYSTEMCTL_BIN " daemon-reload");
+27 -1
View File
@@ -111,7 +111,8 @@ PiPedalModel::~PiPedalModel()
void PiPedalModel::LoadLv2PluginInfo(const PiPedalConfiguration&configuration)
{
storage.SetDataRoot(configuration.GetLocalStoragePath().c_str());
storage.SetConfigRoot(configuration.GetDocRoot());
storage.SetDataRoot(configuration.GetLocalStoragePath());
storage.Initialize();
// Not all Lv2 directories have the lv2 base declarations. Load a full set of plugin classes generated on a default /usr/local/lib/lv2 directory.
@@ -1316,3 +1317,28 @@ const std::filesystem::path& PiPedalModel::GetWebRoot() const
{
return webRoot;
}
std::map<std::string,bool> PiPedalModel::GetFavorites() const
{
std::lock_guard<std::recursive_mutex> guard(const_cast<std::recursive_mutex&>(mutex));
return storage.GetFavorites();
}
void PiPedalModel::SetFavorites(const std::map<std::string,bool> &favorites)
{
std::lock_guard<std::recursive_mutex> guard(mutex);
storage.SetFavorites(favorites);
// take a snapshot incase a client unsusbscribes in the notification handler (in which case the mutex won't protect us)
std::vector<IPiPedalModelSubscriber*> t;
t.reserve(this->subscribers.size());
for (size_t i = 0; i < subscribers.size(); ++i)
{
t.push_back(this->subscribers[i]);
}
for (size_t i = 0; i < t.size(); ++i)
{
t[i]->OnFavoritesChanged(favorites);
}
}
+4
View File
@@ -59,6 +59,7 @@ public:
virtual void OnNotifyAtomOutput(int64_t clientModel,uint64_t instanceId,const std::string&atomType, const std::string&atomJson) = 0;
virtual void OnWifiConfigSettingsChanged(const WifiConfigSettings&wifiConfigSettings) = 0;
virtual void OnGovernorSettingsChanged(const std::string &governor) = 0;
virtual void OnFavoritesChanged(const std::map<std::string,bool> &favorites) = 0;
virtual void Close() = 0;
};
@@ -235,6 +236,9 @@ public:
std::vector<AlsaDeviceInfo> GetAlsaDevices();
const std::filesystem::path& GetWebRoot() const;
std::map<std::string,bool> GetFavorites() const;
void SetFavorites(const std::map<std::string,bool> &favorites);
};
} // namespace pipedal.
+15 -1
View File
@@ -1098,7 +1098,7 @@ public:
[this, subscriptionHandle_](const bool &result)
{
this->portMonitorAck(subscriptionHandle_); // please can we have some more.
// (....complexity not worth the effort. :-( )
},
[](const std::exception &e)
{
@@ -1169,6 +1169,16 @@ public:
{
this->Reply(replyTo, "imageList", imageList);
} else if (message == "getFavorites")
{
std::map<std::string,bool> favorites = this->model.GetFavorites();
this->Reply(replyTo,"getFavorites",favorites);
} else if (message == "setFavorites")
{
std::map<std::string,bool> favorites;
pReader->read(&favorites);
this->model.SetFavorites(favorites);
}
else
{
@@ -1243,6 +1253,10 @@ protected:
}
public:
virtual void OnFavoritesChanged(const std::map<std::string,bool> &favorites)
{
Send("onFavoritesChanged",favorites);
}
virtual void OnChannelSelectionChanged(int64_t clientId, const JackChannelSelection &channelSelection)
{
ChannelSelectionChangedBody body;
+39 -2
View File
@@ -36,6 +36,7 @@ const char *BANKS_FILENAME = "index.banks";
Storage::Storage()
{
SetConfigRoot("~/var/Config");
SetDataRoot("~/var/PiPedal");
}
@@ -127,7 +128,7 @@ std::string Storage::SafeEncodeName(const std::string &name)
return s.str();
}
std::filesystem::path ResolveHomePath(std::filesystem::path path)
std::filesystem::path ResolveHomePath(const std::filesystem::path& path)
{
if (path.begin() == path.end())
return path;
@@ -156,7 +157,12 @@ std::filesystem::path ResolveHomePath(std::filesystem::path path)
}
return result;
}
void Storage::SetDataRoot(const char *path)
void Storage::SetConfigRoot(const std::filesystem::path& path)
{
this->configRoot = ResolveHomePath(path);
}
void Storage::SetDataRoot(const std::filesystem::path& path)
{
this->dataRoot = ResolveHomePath(path);
}
@@ -1186,6 +1192,37 @@ uint64_t Storage::CopyPluginPreset(const std::string&pluginUri,uint64_t presetId
}
std::map<std::string,bool> Storage::GetFavorites() const
{
std::map<std::string,bool> result;
std::filesystem::path fileName = this->dataRoot / "favorites.json";
if (!std::filesystem::exists(fileName))
{
fileName = this->configRoot / "defaultFavorites.json";
}
std::ifstream f;
f.open(fileName);
if (f.is_open())
{
json_reader reader(f);
reader.read(&result);
}
return result;
}
void Storage::SetFavorites(const std::map<std::string,bool>&favorites) {
std::filesystem::path fileName = this->dataRoot / "favorites.json";
std::ofstream f;
f.open(fileName);
if (f.is_open())
{
json_writer writer(f);
writer.write(favorites);
}
}
JSON_MAP_BEGIN(CurrentPreset)
JSON_MAP_REFERENCE(CurrentPreset,modified)
+7 -1
View File
@@ -26,6 +26,7 @@
#include "Banks.hpp"
#include "JackConfiguration.hpp"
#include "WifiConfigSettings.hpp"
#include <map>
namespace pipedal {
@@ -44,6 +45,7 @@ public:
class Storage {
private:
std::filesystem::path dataRoot;
std::filesystem::path configRoot;
BankIndex bankIndex;
BankFile currentBank;
PluginPresetIndex pluginPresetIndex;
@@ -78,7 +80,8 @@ public:
void Initialize();
void CreateBank(const std::string & name);
void SetDataRoot(const char*path);
void SetDataRoot(const std::filesystem::path& path);
void SetConfigRoot(const std::filesystem::path& path);
std::vector<std::string> GetPedalBoards();
@@ -140,6 +143,9 @@ public:
void UpdatePluginPresets(const PluginUiPresets &pluginPresets);
uint64_t CopyPluginPreset(const std::string&pluginUri,uint64_t presetId);
std::map<std::string,bool> GetFavorites() const;
void SetFavorites(const std::map<std::string,bool>&favorites);
};
+12
View File
@@ -0,0 +1,12 @@
{
"http://two-play.com/plugins/toob-cab-sim": true,
"http://two-play.com/plugins/toob-chorus": true,
"http://two-play.com/plugins/toob-delay": true,
"http://two-play.com/plugins/toob-freeverb": true,
"http://two-play.com/plugins/toob-input_stage": true,
"http://two-play.com/plugins/toob-ml": true,
"http://two-play.com/plugins/toob-power-stage-2": true,
"http://two-play.com/plugins/toob-spectrum": true,
"http://two-play.com/plugins/toob-tone-stack": true,
"http://two-play.com/plugins/toob-tuner": true
}