#119 Refresh available LV2 plugins whenever an LV2 plugin is installed.
This commit is contained in:
@@ -132,6 +132,7 @@ else()
|
||||
endif()
|
||||
|
||||
set (PIPEDAL_SOURCES
|
||||
Lv2PluginChangeMonitor.cpp Lv2PluginChangeMonitor.hpp
|
||||
WebServerConfig.cpp WebServerConfig.hpp
|
||||
Locale.hpp Locale.cpp
|
||||
Finally.hpp
|
||||
|
||||
+4
-6
@@ -39,18 +39,16 @@ std::string timeTag()
|
||||
|
||||
using namespace std::chrono;
|
||||
|
||||
auto t = std::chrono::system_clock::now()- timeZero;
|
||||
auto now = std::chrono::system_clock::now();
|
||||
std::time_t now_c = std::chrono::system_clock::to_time_t(now);
|
||||
|
||||
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) % 1000;
|
||||
|
||||
auto hours_ = duration_cast<hours>(t).count() % 24;
|
||||
auto minutes_ = duration_cast<minutes>(t).count() % 60;
|
||||
auto seconds_ = duration_cast<seconds>(t).count() % 60;
|
||||
auto milliseconds_ = duration_cast<milliseconds>(t).count() % 1000;
|
||||
|
||||
std::stringstream s;
|
||||
|
||||
using namespace std;
|
||||
s << setfill('0') << setw(2) << hours_ << ':' << setw(2) << minutes_ << ':' << setw(2) << seconds_ << "." << setw(3) << milliseconds_ << " ";
|
||||
s << std::put_time(std::localtime(&now_c), "%Y-%m-%d %H:%M:%S") << "." << std::setw(3) << std::setfill('0') << milliseconds.count() << " ";
|
||||
return s.str();
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
// Copyright (c) 2024 Robin Davies
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
// this software and associated documentation files (the "Software"), to deal in
|
||||
// the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
#include "Lv2PluginChangeMonitor.hpp"
|
||||
#include "Lv2Log.hpp"
|
||||
#include <sys/inotify.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <Finally.hpp>
|
||||
#include <chrono>
|
||||
#include <sys/eventfd.h>
|
||||
#include "PiPedalModel.hpp"
|
||||
|
||||
using namespace pipedal;
|
||||
|
||||
Lv2PluginChangeMonitor::Lv2PluginChangeMonitor(PiPedalModel&model)
|
||||
:model(model)
|
||||
{
|
||||
shutdown_eventfd = eventfd(0, 0);
|
||||
monitorThread = std::make_unique<std::thread>([this]() { ThreadProc();});
|
||||
}
|
||||
|
||||
void Lv2PluginChangeMonitor::Shutdown()
|
||||
{
|
||||
if (monitorThread)
|
||||
{
|
||||
terminateThread = true;
|
||||
monitorThread->join();
|
||||
monitorThread = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Lv2PluginChangeMonitor::~Lv2PluginChangeMonitor()
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
void Lv2PluginChangeMonitor::ThreadProc()
|
||||
{
|
||||
using clock = std::chrono::steady_clock;
|
||||
|
||||
int inotify_fd = inotify_init();
|
||||
if (inotify_fd == -1) {
|
||||
Lv2Log::error("Failed to initialize inotify");
|
||||
return;
|
||||
}
|
||||
|
||||
Finally f1 ([inotify_fd]() {
|
||||
close(inotify_fd);
|
||||
|
||||
});
|
||||
// Add the directory to the inotify watch list
|
||||
int watch_descriptor = inotify_add_watch(inotify_fd, "/usr/lib/lv2", IN_MODIFY | IN_CREATE | IN_DELETE);
|
||||
if (watch_descriptor == -1) {
|
||||
Lv2Log::error("Failed to add directory to inotify watch list");
|
||||
return;
|
||||
}
|
||||
Finally f2([inotify_fd,watch_descriptor]() {
|
||||
inotify_rm_watch(inotify_fd, watch_descriptor);
|
||||
});
|
||||
|
||||
bool updating = false;
|
||||
clock::time_point updateTime;
|
||||
|
||||
// Monitor for file system events
|
||||
while (true) {
|
||||
struct pollfd pfds[2] = {
|
||||
{.fd = inotify_fd, .events = POLLIN},
|
||||
{.fd = shutdown_eventfd, .events = POLLIN}
|
||||
};
|
||||
int ret = poll(pfds, 2,500); // infinite wait
|
||||
if (ret == -1) {
|
||||
Lv2Log::error("Error in poll()");
|
||||
break;
|
||||
}
|
||||
if (ret == 0)
|
||||
{
|
||||
// timeout.
|
||||
if (updating && clock::now() >= updateTime)
|
||||
{
|
||||
updating = false;
|
||||
model.OnLv2PluginsChanged();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (pfds[1].revents & POLLIN) {
|
||||
// Shutdown event received
|
||||
break;
|
||||
}
|
||||
|
||||
char buffer[4096];
|
||||
ssize_t num_bytes = read(inotify_fd, buffer, sizeof(buffer));
|
||||
if (num_bytes == -1) {
|
||||
Lv2Log::error("Error reading from inotify");
|
||||
break;
|
||||
}
|
||||
|
||||
size_t i = 0;
|
||||
bool updated = false;
|
||||
while (i < static_cast<size_t>(num_bytes)) {
|
||||
struct inotify_event* event = reinterpret_cast<struct inotify_event*>(&buffer[i]);
|
||||
if (event->len > 0) {
|
||||
if (event->mask & IN_MODIFY) {
|
||||
updated = true;
|
||||
} else if (event->mask & IN_CREATE) {
|
||||
updated = true;
|
||||
} else if (event->mask & IN_DELETE) {
|
||||
updated = true;
|
||||
}
|
||||
}
|
||||
i += sizeof(struct inotify_event) + event->len;
|
||||
}
|
||||
if (updated)
|
||||
{
|
||||
updating = true;
|
||||
updateTime = clock::now() + std::chrono::duration_cast<clock::duration>(std::chrono::seconds(5));
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) 2024 Robin Davies
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
// this software and associated documentation files (the "Software"), to deal in
|
||||
// the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
|
||||
namespace pipedal
|
||||
{
|
||||
class PiPedalModel;
|
||||
class Lv2PluginChangeMonitor {
|
||||
public:
|
||||
Lv2PluginChangeMonitor(PiPedalModel&model);
|
||||
~Lv2PluginChangeMonitor();
|
||||
void Shutdown();
|
||||
private:
|
||||
void ThreadProc();
|
||||
|
||||
int shutdown_eventfd;
|
||||
bool isClosed = false;
|
||||
PiPedalModel&model;
|
||||
std::unique_ptr<std::thread> monitorThread;
|
||||
std::atomic<bool> terminateThread {false};
|
||||
};
|
||||
}
|
||||
+85
-52
@@ -18,6 +18,7 @@
|
||||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
#include "pch.h"
|
||||
#include <future>
|
||||
#include "ServiceConfiguration.hpp"
|
||||
#include "AudioConfig.hpp"
|
||||
#include "ConfigUtil.hpp"
|
||||
@@ -33,6 +34,7 @@
|
||||
#include "RingBufferReader.hpp"
|
||||
#include "PiPedalUI.hpp"
|
||||
#include "atom_object.hpp"
|
||||
#include "Lv2PluginChangeMonitor.hpp"
|
||||
|
||||
#ifndef NO_MLOCK
|
||||
#include <sys/mman.h>
|
||||
@@ -61,8 +63,8 @@ static std::string BytesToHex(const std::vector<uint8_t> &bytes)
|
||||
}
|
||||
|
||||
PiPedalModel::PiPedalModel()
|
||||
: lv2Host(),
|
||||
atomConverter(lv2Host.GetMapFeature())
|
||||
: pluginHost(),
|
||||
atomConverter(pluginHost.GetMapFeature())
|
||||
{
|
||||
this->pedalboard = Pedalboard::MakeDefault();
|
||||
#if JACK_HOST
|
||||
@@ -98,6 +100,7 @@ void PiPedalModel::Close()
|
||||
|
||||
PiPedalModel::~PiPedalModel()
|
||||
{
|
||||
pluginChangeMonitor = nullptr;
|
||||
try
|
||||
{
|
||||
adminClient.UnmonitorGovernor();
|
||||
@@ -133,12 +136,14 @@ PiPedalModel::~PiPedalModel()
|
||||
|
||||
void PiPedalModel::Init(const PiPedalConfiguration &configuration)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex); // prevent callbacks while we're initializing.
|
||||
|
||||
this->configuration = configuration;
|
||||
lv2Host.SetConfiguration(configuration);
|
||||
pluginHost.SetConfiguration(configuration);
|
||||
storage.SetConfigRoot(configuration.GetDocRoot());
|
||||
storage.SetDataRoot(configuration.GetLocalStoragePath());
|
||||
storage.Initialize();
|
||||
lv2Host.SetPluginStoragePath(storage.GetPluginUploadDirectory());
|
||||
pluginHost.SetPluginStoragePath(storage.GetPluginUploadDirectory());
|
||||
|
||||
this->systemMidiBindings = storage.GetSystemMidiBindings();
|
||||
|
||||
@@ -157,7 +162,7 @@ void PiPedalModel::LoadLv2PluginInfo()
|
||||
{
|
||||
if (!std::filesystem::exists(pluginClassesPath))
|
||||
throw PiPedalException("File not found.");
|
||||
lv2Host.LoadPluginClassesFromJson(pluginClassesPath);
|
||||
pluginHost.LoadPluginClassesFromJson(pluginClassesPath);
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
@@ -166,18 +171,19 @@ void PiPedalModel::LoadLv2PluginInfo()
|
||||
throw PiPedalException(s.str().c_str());
|
||||
}
|
||||
|
||||
lv2Host.Load(configuration.GetLv2Path().c_str());
|
||||
pluginChangeMonitor = std::make_unique<Lv2PluginChangeMonitor>(*this);
|
||||
pluginHost.Load(configuration.GetLv2Path().c_str());
|
||||
|
||||
// Copy all presets out of Lilv data to json files
|
||||
// so that we can close lilv while we're actually
|
||||
// running.
|
||||
for (const auto &plugin : lv2Host.GetPlugins())
|
||||
for (const auto &plugin : pluginHost.GetPlugins())
|
||||
{
|
||||
if (plugin->has_factory_presets())
|
||||
{
|
||||
if (!storage.HasPluginPresets(plugin->uri()))
|
||||
{
|
||||
PluginPresets pluginPresets = lv2Host.GetFactoryPluginPresets(plugin->uri());
|
||||
PluginPresets pluginPresets = pluginHost.GetFactoryPluginPresets(plugin->uri());
|
||||
storage.SavePluginPresets(plugin->uri(), pluginPresets);
|
||||
}
|
||||
}
|
||||
@@ -191,7 +197,7 @@ void PiPedalModel::Load()
|
||||
|
||||
adminClient.MonitorGovernor(storage.GetGovernorSettings());
|
||||
|
||||
// lv2Host.Load(configuration.GetLv2Path().c_str());
|
||||
// pluginHost.Load(configuration.GetLv2Path().c_str());
|
||||
|
||||
this->pedalboard = storage.GetCurrentPreset(); // the current *saved* preset.
|
||||
|
||||
@@ -211,7 +217,7 @@ void PiPedalModel::Load()
|
||||
}
|
||||
UpdateDefaults(&this->pedalboard);
|
||||
|
||||
std::unique_ptr<AudioHost> p{AudioHost::CreateInstance(lv2Host.asIHost())};
|
||||
std::unique_ptr<AudioHost> p{AudioHost::CreateInstance(pluginHost.asIHost())};
|
||||
this->audioHost = std::move(p);
|
||||
|
||||
this->audioHost->SetNotificationCallbacks(this);
|
||||
@@ -270,7 +276,7 @@ void PiPedalModel::Load()
|
||||
JackChannelSelection selection = storage.GetJackChannelSelection(jackConfiguration);
|
||||
selection = selection.RemoveInvalidChannels(jackConfiguration);
|
||||
|
||||
this->lv2Host.OnConfigurationChanged(jackConfiguration, selection);
|
||||
this->pluginHost.OnConfigurationChanged(jackConfiguration, selection);
|
||||
try
|
||||
{
|
||||
audioHost->Open(this->jackServerSettings, selection);
|
||||
@@ -380,7 +386,6 @@ void PiPedalModel::OnNotifyMaybeLv2StateChanged(uint64_t instanceId)
|
||||
|
||||
item->stateUpdateCount(item->stateUpdateCount() + 1);
|
||||
|
||||
|
||||
IPiPedalModelSubscriber **t = new IPiPedalModelSubscriber *[this->subscribers.size()];
|
||||
|
||||
Lv2PluginState newState = item->lv2State();
|
||||
@@ -392,7 +397,7 @@ void PiPedalModel::OnNotifyMaybeLv2StateChanged(uint64_t instanceId)
|
||||
{
|
||||
for (size_t i = 0; i < n; ++i)
|
||||
{
|
||||
t[i]->OnLv2StateChanged(instanceId,newState);
|
||||
t[i]->OnLv2StateChanged(instanceId, newState);
|
||||
}
|
||||
}
|
||||
delete[] t;
|
||||
@@ -1151,7 +1156,6 @@ void PiPedalModel::RestartAudio()
|
||||
|
||||
// do a complete reload.
|
||||
|
||||
|
||||
this->audioHost->SetPedalboard(nullptr);
|
||||
|
||||
this->jackConfiguration.AlsaInitialize(this->jackServerSettings);
|
||||
@@ -1183,7 +1187,7 @@ void PiPedalModel::RestartAudio()
|
||||
}
|
||||
this->audioHost->Open(this->jackServerSettings, channelSelection);
|
||||
|
||||
this->lv2Host.OnConfigurationChanged(jackConfiguration, channelSelection);
|
||||
this->pluginHost.OnConfigurationChanged(jackConfiguration, channelSelection);
|
||||
|
||||
std::vector<std::string> errorMessages;
|
||||
|
||||
@@ -1205,7 +1209,7 @@ void PiPedalModel::SetJackChannelSelection(int64_t clientId, const JackChannelSe
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex); // copy atomically.
|
||||
this->storage.SetJackChannelSelection(channelSelection);
|
||||
|
||||
this->lv2Host.OnConfigurationChanged(jackConfiguration, channelSelection);
|
||||
this->pluginHost.OnConfigurationChanged(jackConfiguration, channelSelection);
|
||||
}
|
||||
|
||||
RestartAudio(); // no lock to avoid mutex deadlock when reader thread is sending notifications..
|
||||
@@ -1283,7 +1287,7 @@ void PiPedalModel::OnNotifyMidiValueChanged(int64_t instanceId, int portIndex, f
|
||||
}
|
||||
else
|
||||
{
|
||||
pPluginInfo = lv2Host.GetPluginInfo(item->uri());
|
||||
pPluginInfo = pluginHost.GetPluginInfo(item->uri());
|
||||
}
|
||||
if (pPluginInfo)
|
||||
{
|
||||
@@ -1475,7 +1479,7 @@ void PiPedalModel::SendSetPatchProperty(
|
||||
}
|
||||
}};
|
||||
|
||||
LV2_URID urid = this->lv2Host.GetLv2Urid(propertyUri.c_str());
|
||||
LV2_URID urid = this->pluginHost.GetLv2Urid(propertyUri.c_str());
|
||||
|
||||
RealtimePatchPropertyRequest *request = new RealtimePatchPropertyRequest(
|
||||
onRequestComplete,
|
||||
@@ -1536,7 +1540,7 @@ void PiPedalModel::SendGetPatchProperty(
|
||||
}
|
||||
}};
|
||||
|
||||
LV2_URID urid = this->lv2Host.GetLv2Urid(uri.c_str());
|
||||
LV2_URID urid = this->pluginHost.GetLv2Urid(uri.c_str());
|
||||
RealtimePatchPropertyRequest *request = new RealtimePatchPropertyRequest(
|
||||
onRequestComplete,
|
||||
clientId, instanceId, urid, onSuccess, onError);
|
||||
@@ -1669,7 +1673,7 @@ void PiPedalModel::SetJackServerSettings(const JackServerSettings &jackServerSet
|
||||
FireJackConfigurationChanged(this->jackConfiguration);
|
||||
|
||||
// restart the pedalboard on a new instance.
|
||||
std::shared_ptr<Lv2Pedalboard> lv2Pedalboard{this->lv2Host.CreateLv2Pedalboard(this->pedalboard)};
|
||||
std::shared_ptr<Lv2Pedalboard> lv2Pedalboard{this->pluginHost.CreateLv2Pedalboard(this->pedalboard)};
|
||||
this->lv2Pedalboard = lv2Pedalboard;
|
||||
|
||||
audioHost->SetPedalboard(lv2Pedalboard);
|
||||
@@ -1684,7 +1688,7 @@ void PiPedalModel::SetJackServerSettings(const JackServerSettings &jackServerSet
|
||||
|
||||
void PiPedalModel::UpdateDefaults(PedalboardItem *pedalboardItem)
|
||||
{
|
||||
std::shared_ptr<Lv2PluginInfo> pPlugin = lv2Host.GetPluginInfo(pedalboardItem->uri());
|
||||
std::shared_ptr<Lv2PluginInfo> pPlugin = pluginHost.GetPluginInfo(pedalboardItem->uri());
|
||||
if (!pPlugin)
|
||||
{
|
||||
if (pedalboardItem->uri() == SPLIT_PEDALBOARD_ITEM_URI)
|
||||
@@ -1817,19 +1821,19 @@ void PiPedalModel::DeleteMidiListeners(int64_t clientId)
|
||||
audioHost->SetListenForMidiEvent(midiEventListeners.size() != 0);
|
||||
}
|
||||
|
||||
|
||||
void PiPedalModel::OnPatchSetReply(uint64_t instanceId, LV2_URID patchSetProperty, const LV2_Atom*atomValue)
|
||||
void PiPedalModel::OnPatchSetReply(uint64_t instanceId, LV2_URID patchSetProperty, const LV2_Atom *atomValue)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex);
|
||||
|
||||
std::string propertyUri = lv2Host.GetMapFeature().UridToString(patchSetProperty);
|
||||
std::string propertyUri = pluginHost.GetMapFeature().UridToString(patchSetProperty);
|
||||
|
||||
{
|
||||
PedalboardItem *item = pedalboard.GetItem((int64_t)instanceId);
|
||||
if (item == nullptr) return;
|
||||
atom_object atomObject { atomValue };
|
||||
|
||||
PedalboardItem::PropertyMap& properties = item->PatchProperties();
|
||||
if (item == nullptr)
|
||||
return;
|
||||
atom_object atomObject{atomValue};
|
||||
|
||||
PedalboardItem::PropertyMap &properties = item->PatchProperties();
|
||||
if (properties.contains(propertyUri))
|
||||
{
|
||||
if (properties[propertyUri] == atomObject)
|
||||
@@ -1924,25 +1928,25 @@ void PiPedalModel::MonitorPatchProperty(int64_t clientId, int64_t clientHandle,
|
||||
LV2_URID propertyUrid = 0;
|
||||
if (propertyUri.length() != 0)
|
||||
{
|
||||
propertyUrid = lv2Host.GetMapFeature().GetUrid(propertyUri.c_str());
|
||||
propertyUrid = pluginHost.GetMapFeature().GetUrid(propertyUri.c_str());
|
||||
}
|
||||
AtomOutputListener listener{clientId, clientHandle, instanceId, propertyUrid};
|
||||
atomOutputListeners.push_back(listener);
|
||||
audioHost->SetListenForAtomOutput(true);
|
||||
|
||||
PedalboardItem*item = this->pedalboard.GetItem(instanceId );
|
||||
PedalboardItem *item = this->pedalboard.GetItem(instanceId);
|
||||
if (item)
|
||||
{
|
||||
auto& map = item->PatchProperties();
|
||||
auto &map = item->PatchProperties();
|
||||
if (map.contains(propertyUri))
|
||||
{
|
||||
const auto&value = map[propertyUri];
|
||||
const auto &value = map[propertyUri];
|
||||
std::string json = this->audioHost->AtomToJson(value.get());
|
||||
for (auto &subscriber: this->subscribers)
|
||||
for (auto &subscriber : this->subscribers)
|
||||
{
|
||||
if (subscriber->GetClientId() == clientId)
|
||||
{
|
||||
subscriber->OnNotifyPatchProperty(clientHandle,instanceId,propertyUri,json);
|
||||
subscriber->OnNotifyPatchProperty(clientHandle, instanceId, propertyUri, json);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2040,11 +2044,11 @@ std::vector<std::string> PiPedalModel::GetFileList(const UiFileProperty &filePro
|
||||
return std::vector<std::string>(); // don't disclose to users what the problem is.
|
||||
}
|
||||
}
|
||||
std::vector<FileEntry> PiPedalModel::GetFileList2(const std::string &relativePath,const UiFileProperty &fileProperty)
|
||||
std::vector<FileEntry> PiPedalModel::GetFileList2(const std::string &relativePath, const UiFileProperty &fileProperty)
|
||||
{
|
||||
try
|
||||
{
|
||||
return this->storage.GetFileList2(relativePath,fileProperty);
|
||||
return this->storage.GetFileList2(relativePath, fileProperty);
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
@@ -2054,12 +2058,12 @@ std::vector<FileEntry> PiPedalModel::GetFileList2(const std::string &relativePat
|
||||
}
|
||||
|
||||
std::string PiPedalModel::RenameFilePropertyFile(
|
||||
const std::string&oldRelativePath,
|
||||
const std::string&newRelativePath,
|
||||
const UiFileProperty&uiFileProperty)
|
||||
const std::string &oldRelativePath,
|
||||
const std::string &newRelativePath,
|
||||
const UiFileProperty &uiFileProperty)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex);
|
||||
return storage.RenameFilePropertyFile(oldRelativePath,newRelativePath,uiFileProperty);
|
||||
return storage.RenameFilePropertyFile(oldRelativePath, newRelativePath, uiFileProperty);
|
||||
}
|
||||
|
||||
void PiPedalModel::DeleteSampleFile(const std::filesystem::path &fileName)
|
||||
@@ -2068,23 +2072,20 @@ void PiPedalModel::DeleteSampleFile(const std::filesystem::path &fileName)
|
||||
storage.DeleteSampleFile(fileName);
|
||||
}
|
||||
|
||||
std::string PiPedalModel::CreateNewSampleDirectory(const std::string&relativePath, const UiFileProperty&uiFileProperty)
|
||||
std::string PiPedalModel::CreateNewSampleDirectory(const std::string &relativePath, const UiFileProperty &uiFileProperty)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex);
|
||||
return storage.CreateNewSampleDirectory(relativePath, uiFileProperty);
|
||||
|
||||
}
|
||||
FilePropertyDirectoryTree::ptr PiPedalModel::GetFilePropertydirectoryTree(const UiFileProperty&uiFileProperty)
|
||||
FilePropertyDirectoryTree::ptr PiPedalModel::GetFilePropertydirectoryTree(const UiFileProperty &uiFileProperty)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex);
|
||||
return storage.GetFilePropertydirectoryTree(uiFileProperty);
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::string PiPedalModel::UploadUserFile(const std::string &directory, const std::string &patchProperty, const std::string &filename, std::istream&stream, size_t contentLength)
|
||||
std::string PiPedalModel::UploadUserFile(const std::string &directory, const std::string &patchProperty, const std::string &filename, std::istream &stream, size_t contentLength)
|
||||
{
|
||||
return storage.UploadUserFile(directory, patchProperty, filename, stream,contentLength);
|
||||
return storage.UploadUserFile(directory, patchProperty, filename, stream, contentLength);
|
||||
}
|
||||
|
||||
uint64_t PiPedalModel::CreateNewPreset()
|
||||
@@ -2096,19 +2097,18 @@ uint64_t PiPedalModel::CreateNewPreset()
|
||||
|
||||
void PiPedalModel::CheckForResourceInitialization(Pedalboard &pedalboard)
|
||||
{
|
||||
for (auto item: pedalboard.GetAllPlugins())
|
||||
for (auto item : pedalboard.GetAllPlugins())
|
||||
{
|
||||
if (!item->isSplit())
|
||||
{
|
||||
lv2Host.CheckForResourceInitialization(item->uri(),storage.GetPluginUploadDirectory());
|
||||
pluginHost.CheckForResourceInitialization(item->uri(), storage.GetPluginUploadDirectory());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
bool PiPedalModel::LoadCurrentPedalboard()
|
||||
{
|
||||
Lv2PedalboardErrorList errorMessages;
|
||||
std::shared_ptr<Lv2Pedalboard> lv2Pedalboard{this->lv2Host.CreateLv2Pedalboard(this->pedalboard, errorMessages)};
|
||||
std::shared_ptr<Lv2Pedalboard> lv2Pedalboard{this->pluginHost.CreateLv2Pedalboard(this->pedalboard, errorMessages)};
|
||||
this->lv2Pedalboard = lv2Pedalboard;
|
||||
|
||||
// apply the error messages to the lv2Pedalboard.
|
||||
@@ -2138,4 +2138,37 @@ void PiPedalModel::OnNotifyLv2RealtimeError(int64_t instanceId, const std::strin
|
||||
std::filesystem::path PiPedalModel::GetPluginUploadDirectory() const
|
||||
{
|
||||
return storage.GetPluginUploadDirectory();
|
||||
}
|
||||
}
|
||||
|
||||
void PiPedalModel::OnLv2PluginsChanged()
|
||||
{
|
||||
Lv2Log::info("Lv2 plugins have changed. Reloading plugins.");
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex);
|
||||
{
|
||||
// Notify clients.
|
||||
size_t n = subscribers.size();
|
||||
IPiPedalModelSubscriber **t = new IPiPedalModelSubscriber *[n];
|
||||
for (size_t i = 0; i < n; ++i)
|
||||
{
|
||||
t[i] = this->subscribers[i];
|
||||
}
|
||||
for (size_t i = 0; i < n; ++i)
|
||||
{
|
||||
t[i]->OnLv2PluginsChanging();
|
||||
}
|
||||
delete[] t;
|
||||
}
|
||||
std::thread(
|
||||
[this]()
|
||||
{
|
||||
// wait for the message to propagate. It would be better to use some kind of flush()
|
||||
// operation, but it's not clear how to do that with asyncio.
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
||||
restartListener();
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
void PiPedalModel::SetRestartListener(std::function<void(void)> &&listener)
|
||||
{
|
||||
this->restartListener = std::move(listener);
|
||||
}
|
||||
|
||||
+10
-4
@@ -46,6 +46,7 @@ namespace pipedal
|
||||
|
||||
struct RealtimeMidiProgramRequest;
|
||||
struct RealtimeNextMidiProgramRequest;
|
||||
class Lv2PluginChangeMonitor;
|
||||
|
||||
class IPiPedalModelSubscriber
|
||||
{
|
||||
@@ -78,12 +79,16 @@ namespace pipedal
|
||||
virtual void OnSystemMidiBindingsChanged(const std::vector<MidiBinding>&bindings) = 0;
|
||||
//virtual void OnPatchPropertyChanged(int64_t clientId, int64_t instanceId,const std::string& propertyUri,const json_variant& value) = 0;
|
||||
virtual void OnErrorMessage(const std::string&message) = 0;
|
||||
virtual void OnLv2PluginsChanging() = 0;
|
||||
virtual void Close() = 0;
|
||||
};
|
||||
|
||||
class PiPedalModel : private IAudioHostCallbacks
|
||||
{
|
||||
private:
|
||||
std::function<void(void)> restartListener;
|
||||
|
||||
std::unique_ptr<Lv2PluginChangeMonitor> pluginChangeMonitor;
|
||||
|
||||
std::unique_ptr<std::jthread> pingThread;
|
||||
|
||||
@@ -123,8 +128,8 @@ namespace pipedal
|
||||
std::vector<AtomOutputListener> atomOutputListeners;
|
||||
|
||||
JackServerSettings jackServerSettings;
|
||||
PluginHost lv2Host;
|
||||
AtomConverter atomConverter; // must be AFTER lv2Host!
|
||||
PluginHost pluginHost;
|
||||
AtomConverter atomConverter; // must be AFTER pluginHost!
|
||||
|
||||
Pedalboard pedalboard;
|
||||
Storage storage;
|
||||
@@ -146,7 +151,6 @@ namespace pipedal
|
||||
|
||||
void UpdateDefaults(PedalboardItem *pedalboardItem);
|
||||
void UpdateDefaults(Pedalboard *pedalboard);
|
||||
|
||||
class VuSubscription
|
||||
{
|
||||
public:
|
||||
@@ -199,6 +203,8 @@ namespace pipedal
|
||||
std::filesystem::path GetPluginUploadDirectory() const;
|
||||
void Close();
|
||||
|
||||
void SetRestartListener(std::function<void(void)> &&listener);
|
||||
void OnLv2PluginsChanged();
|
||||
void SetOnboarding(bool value);
|
||||
|
||||
void UpdateDnsSd();
|
||||
@@ -210,7 +216,7 @@ namespace pipedal
|
||||
void LoadLv2PluginInfo();
|
||||
void Load();
|
||||
|
||||
const PluginHost &GetLv2Host() const { return lv2Host; }
|
||||
const PluginHost &GetLv2Host() const { return pluginHost; }
|
||||
Pedalboard GetCurrentPedalboardCopy()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> guard(mutex);
|
||||
|
||||
@@ -1587,6 +1587,12 @@ private:
|
||||
Send("onLv2StateChanged",message);
|
||||
|
||||
}
|
||||
|
||||
virtual void OnLv2PluginsChanging() override {
|
||||
Send("onLv2PluginsChanging",true);
|
||||
Flush();
|
||||
}
|
||||
|
||||
virtual void OnErrorMessage(const std::string&message)
|
||||
{
|
||||
Send("onErrorMessage",message);
|
||||
@@ -1778,6 +1784,9 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
void Flush() {
|
||||
|
||||
}
|
||||
int outstandingNotifyAtomOutputs = 0;
|
||||
|
||||
class PendingNotifyAtomOutput
|
||||
|
||||
@@ -1470,6 +1470,7 @@ void PluginHost::CheckForResourceInitialization(const std::string &pluginUri,con
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// void PiPedalHostLogError(const std::string &error)
|
||||
// {
|
||||
// Lv2Log::error("%s",error.c_str());
|
||||
|
||||
@@ -813,6 +813,7 @@ namespace pipedal
|
||||
public:
|
||||
virtual MapFeature &GetMapFeature() { return this->mapFeature; }
|
||||
void CheckForResourceInitialization(const std::string& pluginUri,const std::filesystem::path& pluginUploadDirectory);
|
||||
void ReloadPlugins();
|
||||
|
||||
private:
|
||||
|
||||
|
||||
+33
-48
@@ -47,19 +47,13 @@
|
||||
|
||||
#include <systemd/sd-daemon.h>
|
||||
|
||||
|
||||
using namespace pipedal;
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __ARM_ARCH_ISA_A64
|
||||
#define AARCH64
|
||||
#endif
|
||||
|
||||
|
||||
sem_t signalSemaphore;
|
||||
|
||||
bool HasAlsaDevice(const std::vector<AlsaDeviceInfo> devices, const std::string &deviceId)
|
||||
{
|
||||
for (auto &device : devices)
|
||||
@@ -77,21 +71,16 @@ public:
|
||||
std::string message(int ev) const { return "error message"; }
|
||||
};
|
||||
|
||||
static volatile bool g_SigBreak = false;
|
||||
std::atomic<bool> ga_SigBreak { false };
|
||||
static std::atomic<bool> g_SigBreak = false;
|
||||
static std::atomic<bool> g_restart = false;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (!g_SigBreak)
|
||||
{
|
||||
g_SigBreak = true;
|
||||
sem_post(&signalSemaphore);
|
||||
}
|
||||
// we're using sig_wait. No need to do anything.
|
||||
}
|
||||
|
||||
void throwSystemError(int error)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static bool isJackServiceRunning()
|
||||
@@ -104,8 +93,6 @@ static bool isJackServiceRunning()
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
sem_init(&signalSemaphore, 0, 0);
|
||||
|
||||
|
||||
#ifndef WIN32
|
||||
umask(002); // newly created files in /var/pipedal get 775-ish permissions, which improves debugging/live-service interaction.
|
||||
@@ -176,7 +163,6 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
SetThreadName("main");
|
||||
|
||||
|
||||
std::filesystem::path doc_root = parser.Arguments()[0];
|
||||
std::filesystem::path web_root = doc_root;
|
||||
if (parser.Arguments().size() >= 2)
|
||||
@@ -194,7 +180,7 @@ int main(int argc, char *argv[])
|
||||
std::stringstream s;
|
||||
s << "Unable to read configuration from '" << (doc_root / "config.json") << "'. (" << e.what() << ")";
|
||||
Lv2Log::error(s.str());
|
||||
return EXIT_FAILURE;
|
||||
return EXIT_SUCCESS; // indicate to systemd that we don't want a restart.
|
||||
}
|
||||
|
||||
Lv2Log::log_level(configuration.GetLogLevel());
|
||||
@@ -214,7 +200,7 @@ int main(int argc, char *argv[])
|
||||
auto const threads = std::max<int>(1, configuration.GetThreads());
|
||||
|
||||
server = WebServer::create(
|
||||
address, port, web_root.c_str(), threads,configuration.GetMaxUploadSize());
|
||||
address, port, web_root.c_str(), threads, configuration.GetMaxUploadSize());
|
||||
|
||||
Lv2Log::info("Document root: %s Threads: %d", doc_root.c_str(), (int)threads);
|
||||
|
||||
@@ -225,7 +211,7 @@ int main(int argc, char *argv[])
|
||||
std::stringstream s;
|
||||
s << "Fatal error: " << e.what() << std::endl;
|
||||
Lv2Log::error(s.str());
|
||||
return EXIT_FAILURE;
|
||||
return EXIT_SUCCESS; // indiate to systemd that we don't want a restart.
|
||||
}
|
||||
|
||||
try
|
||||
@@ -233,15 +219,25 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
auto locale = Locale::GetInstance();
|
||||
Lv2Log::info(SS("Locale: " << locale->CurrentLocale()));
|
||||
try {
|
||||
try
|
||||
{
|
||||
auto collator = locale->GetCollator();
|
||||
} catch (std::exception&e)
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
Lv2Log::error(e.what());
|
||||
return EXIT_SUCCESS; //tell systemd not to auto-restart.
|
||||
return EXIT_SUCCESS; // tell systemd not to auto-restart.
|
||||
}
|
||||
}
|
||||
PiPedalModel model;
|
||||
|
||||
model.SetRestartListener(
|
||||
[]()
|
||||
{
|
||||
g_restart = true;
|
||||
raise(SIGTERM); // throws an exception under gdb, but correctly restarts the service when running live.
|
||||
});
|
||||
|
||||
model.Init(configuration);
|
||||
|
||||
// Get heavy IO out of the way before letting dependent (Jack/ALSA) services run.
|
||||
@@ -254,10 +250,8 @@ int main(int argc, char *argv[])
|
||||
(unsigned long)getpid());
|
||||
}
|
||||
|
||||
|
||||
auto serverSettings = model.GetJackServerSettings();
|
||||
|
||||
|
||||
{
|
||||
// Wait for selected audio device to be initialized.
|
||||
// It may take some time for ALSA to publish all available devices when rebooting.
|
||||
@@ -270,7 +264,8 @@ int main(int argc, char *argv[])
|
||||
if (HasAlsaDevice(devices, serverSettings.GetAlsaInputDevice()))
|
||||
{
|
||||
Lv2Log::info(SS("Found ALSA device " << serverSettings.GetAlsaInputDevice() << "."));
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
@@ -292,13 +287,16 @@ int main(int argc, char *argv[])
|
||||
if (found)
|
||||
{
|
||||
Lv2Log::info(SS("Found ALSA device " << serverSettings.GetAlsaInputDevice() << "."));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
Lv2Log::info(SS("ALSA device " << serverSettings.GetAlsaInputDevice() << " not found."));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
Lv2Log::info("No ALSA device selected.");
|
||||
|
||||
}
|
||||
|
||||
// pre-cache device info before we let audio services run.
|
||||
@@ -360,7 +358,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
server->AddSocketFactory(pipedalSocketFactory);
|
||||
|
||||
ConfigureWebServer(*server,model,port,configuration.GetMaxUploadSize());
|
||||
ConfigureWebServer(*server, model, port, configuration.GetMaxUploadSize());
|
||||
{
|
||||
server->RunInBackground(-1);
|
||||
|
||||
@@ -368,24 +366,9 @@ int main(int argc, char *argv[])
|
||||
model.UpdateDnsSd(); // now that the server is running, publish a DNS-SD announcement.
|
||||
SetThreadName("main");
|
||||
|
||||
// AARCH64 sem_wait pins CPU 100%.
|
||||
// static_assert(std::atomic<bool>::is_always_lock_free);
|
||||
|
||||
// while (true)
|
||||
// {
|
||||
// auto sigBreak = ga_SigBreak.load();
|
||||
// if (sigBreak)
|
||||
// {
|
||||
// break;
|
||||
// }
|
||||
// std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
|
||||
// }
|
||||
|
||||
|
||||
{
|
||||
sigwait(&sigSet,&sig);
|
||||
|
||||
sigwait(&sigSet, &sig);
|
||||
|
||||
if (systemd)
|
||||
{
|
||||
sd_notify(0, "STOPPING=1");
|
||||
@@ -395,12 +378,14 @@ int main(int argc, char *argv[])
|
||||
|
||||
Lv2Log::info("Closing audio session.");
|
||||
model.Close();
|
||||
|
||||
|
||||
Lv2Log::info("Stopping web server.");
|
||||
server->ShutDown(5000);
|
||||
server->Join();
|
||||
|
||||
Lv2Log::info("Shutdown complete.");
|
||||
|
||||
if (g_restart) return EXIT_FAILURE; // indicate to systemd that we want a restart.
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
|
||||
@@ -16,7 +16,7 @@ User=pipedal_d
|
||||
Group=pipedal_d
|
||||
Restart=always
|
||||
TimeoutStartSec=60
|
||||
RestartSec=25
|
||||
RestartSec=5
|
||||
TimeoutStopSec=15
|
||||
|
||||
WorkingDirectory=/var/pipedal
|
||||
|
||||
Reference in New Issue
Block a user