#119 Refresh available LV2 plugins whenever an LV2 plugin is installed.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"socket_server_port": 8080,
|
||||
"socket_server_port": 80,
|
||||
"socket_server_address": "*",
|
||||
"debug": true,
|
||||
"max_upload_size": 536870912,
|
||||
|
||||
+17
-5
@@ -511,7 +511,7 @@ const AppThemed = withStyles(appStyles)(class extends ResizeResponsiveComponent<
|
||||
}
|
||||
|
||||
private unmountListener(e: Event) {
|
||||
if ((!this.model_.reloadRequested) && this.model_.state.get() === State.Ready && !this.model_.isAndroidHosted()) {
|
||||
if (this.model_.state.get() === State.Ready && !this.model_.isAndroidHosted()) {
|
||||
e.preventDefault();
|
||||
(e as any).returnValue = "Are you sure you want to leave this page?";
|
||||
return "Are you sure you want to leave this page?";
|
||||
@@ -608,8 +608,7 @@ setDisplayState(newState: State): void {
|
||||
displayState: newState,
|
||||
canFullScreen: supportsFullScreen() && !this.model_.isAndroidHosted()
|
||||
});
|
||||
if(newState === State.Ready)
|
||||
{
|
||||
if (newState === State.Ready) {
|
||||
if (this.model_.isOnboarding()) {
|
||||
this.handleDisplayOnboarding();
|
||||
}
|
||||
@@ -656,6 +655,16 @@ handleReload() {
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
getReloadingMessage(): string {
|
||||
switch (this.state.displayState) {
|
||||
case State.ApplyingChanges:
|
||||
return "Applying\u00A0changes...";
|
||||
case State.ReloadingPlugins:
|
||||
return "Reloading\u00A0plugins...";
|
||||
default:
|
||||
return "Reconnecting...";
|
||||
}
|
||||
}
|
||||
render() {
|
||||
|
||||
const { classes } = this.props;
|
||||
@@ -887,7 +896,10 @@ render() {
|
||||
{this.state.showStatusMonitor && (<JackStatusView />)}
|
||||
|
||||
<div className={classes.errorContent} style={{
|
||||
display: (this.state.displayState === State.Reconnecting || this.state.displayState === State.ApplyingChanges)
|
||||
display: (
|
||||
this.state.displayState === State.Reconnecting
|
||||
|| this.state.displayState === State.ApplyingChanges
|
||||
|| this.state.displayState === State.ReloadingPlugins)
|
||||
? "block" : "none"
|
||||
}}
|
||||
>
|
||||
@@ -898,7 +910,7 @@ render() {
|
||||
<CircularProgress color="inherit" className={classes.loadingBoxItem} />
|
||||
</div>
|
||||
<Typography noWrap variant="body2" className={classes.progressText}>
|
||||
{this.state.displayState === State.ApplyingChanges ? "Applying\u00A0changes..." : "Reconnecting..."}
|
||||
{this.getReloadingMessage()}
|
||||
</Typography>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -42,6 +42,7 @@ import SearchFilter from './SearchFilter';
|
||||
import { FixedSizeGrid } from 'react-window';
|
||||
import AutoSizer from 'react-virtualized-auto-sizer';
|
||||
import StarBorderIcon from '@mui/icons-material/StarBorder';
|
||||
import StarIcon from '@mui/icons-material/Star';
|
||||
import { createStyles, Theme } from '@mui/material/styles';
|
||||
import { WithStyles, withStyles } from '@mui/styles';
|
||||
import FilterListIcon from '@mui/icons-material/FilterList';
|
||||
@@ -172,8 +173,9 @@ type PluginGridState = {
|
||||
grid_cell_width: number,
|
||||
grid_cell_columns: number,
|
||||
minimumItemWidth: number,
|
||||
favoritesList: FavoritesList
|
||||
gridItems: UiPlugin[];
|
||||
favoritesList: FavoritesList,
|
||||
uiPlugins: UiPlugin[]
|
||||
//gridItems: UiPlugin[];
|
||||
|
||||
|
||||
}
|
||||
@@ -207,7 +209,7 @@ export const LoadPluginDialog =
|
||||
grid_cell_columns: this.getCellColumns(window.innerWidth),
|
||||
minimumItemWidth: props.minimumItemWidth ? props.minimumItemWidth : 220,
|
||||
favoritesList: this.model.favorites.get(),
|
||||
gridItems: this.getFilteredPlugins("", filterType_, this.model.favorites.get())
|
||||
uiPlugins: this.model.ui_plugins.get()
|
||||
|
||||
};
|
||||
|
||||
@@ -217,11 +219,12 @@ export const LoadPluginDialog =
|
||||
this.handleSearchStringReady = this.handleSearchStringReady.bind(this);
|
||||
this.handleKeyPress = this.handleKeyPress.bind(this);
|
||||
this.handleFavoritesChanged = this.handleFavoritesChanged.bind(this);
|
||||
this.handlePluginsChanged = this.handlePluginsChanged.bind(this);
|
||||
|
||||
this.requestScrollTo();
|
||||
}
|
||||
|
||||
nominal_column_width: number = 250;
|
||||
nominal_column_width: number = 350;
|
||||
margin_reserve: number = 30;
|
||||
|
||||
getCellColumns(width: number) {
|
||||
@@ -280,23 +283,31 @@ export const LoadPluginDialog =
|
||||
this.setState(
|
||||
{
|
||||
favoritesList: favorites,
|
||||
gridItems: this.getFilteredPlugins(null, null, favorites)
|
||||
});
|
||||
}
|
||||
handlePluginsChanged(plugins: UiPlugin[]) {
|
||||
this.setState(
|
||||
{
|
||||
uiPlugins: plugins
|
||||
}
|
||||
);
|
||||
}
|
||||
componentDidMount() {
|
||||
super.componentDidMount();
|
||||
this.updateWindowSize();
|
||||
window.addEventListener('resize', this.updateWindowSize);
|
||||
|
||||
this.model.favorites.addOnChangedHandler(this.handleFavoritesChanged);
|
||||
let favorites = this.model.favorites.get();
|
||||
this.model.ui_plugins.addOnChangedHandler(this.handlePluginsChanged);
|
||||
|
||||
this.setState({
|
||||
favoritesList: favorites,
|
||||
gridItems: this.getFilteredPlugins(null, null, favorites)
|
||||
favoritesList: this.model.favorites.get(),
|
||||
uiPlugins: this.model.ui_plugins.get()
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
componentWillUnmount() {
|
||||
this.model.ui_plugins.removeOnChangedHandler(this.handlePluginsChanged);
|
||||
this.model.favorites.removeOnChangedHandler(this.handleFavoritesChanged);
|
||||
super.componentWillUnmount();
|
||||
window.removeEventListener('resize', this.updateWindowSize);
|
||||
@@ -310,7 +321,6 @@ export const LoadPluginDialog =
|
||||
this.setState({
|
||||
search_string: "",
|
||||
search_collapsed: true,
|
||||
gridItems: this.getFilteredPlugins("", null, null)
|
||||
});
|
||||
}
|
||||
this.requestScrollTo();
|
||||
@@ -331,7 +341,6 @@ export const LoadPluginDialog =
|
||||
this.requestScrollTo();
|
||||
this.setState({
|
||||
filterType: filterValue,
|
||||
gridItems: this.getFilteredPlugins(null, filterValue, null)
|
||||
});
|
||||
}
|
||||
onClearFilter(): void {
|
||||
@@ -340,8 +349,7 @@ export const LoadPluginDialog =
|
||||
if (this.state.filterType !== value) {
|
||||
this.requestScrollTo();
|
||||
this.setState({
|
||||
filterType: value,
|
||||
gridItems: this.getFilteredPlugins(null, value, null)
|
||||
filterType: value
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -480,7 +488,7 @@ export const LoadPluginDialog =
|
||||
return result;
|
||||
|
||||
}
|
||||
getFilteredPlugins(searchString: string | null, filterType: PluginType | null, favoritesList: FavoritesList | null): UiPlugin[] {
|
||||
getFilteredPlugins(plugins: UiPlugin[], searchString: string | null, filterType: PluginType | null, favoritesList: FavoritesList | null): UiPlugin[] {
|
||||
try {
|
||||
if (searchString === null) {
|
||||
searchString = this.state.search_string;
|
||||
@@ -491,7 +499,6 @@ export const LoadPluginDialog =
|
||||
if (favoritesList === null) {
|
||||
favoritesList = this.state.favoritesList;
|
||||
}
|
||||
let plugins = this.model.ui_plugins.get();
|
||||
|
||||
let results: { score: number; plugin: UiPlugin }[] = [];
|
||||
let searchFilter = new SearchFilter(searchString);
|
||||
@@ -544,12 +551,14 @@ export const LoadPluginDialog =
|
||||
this.scrollToRequested = true;
|
||||
}
|
||||
|
||||
private cachedGridItems: UiPlugin[] = []; // retained for the scrollTo callback.
|
||||
|
||||
handleScrollToCallback(element: FixedSizeGrid): void {
|
||||
if (element) {
|
||||
if (this.scrollToRequested) {
|
||||
this.scrollToRequested = false;
|
||||
let position = -1;
|
||||
let gridItems = this.state.gridItems;
|
||||
let gridItems = this.cachedGridItems;
|
||||
for (let i = 0; i < gridItems.length; ++i) {
|
||||
if (this.state.selected_uri === gridItems[i].uri) {
|
||||
position = i;
|
||||
@@ -568,8 +577,7 @@ export const LoadPluginDialog =
|
||||
if (this.changedSearchString !== undefined) {
|
||||
this.requestScrollTo();
|
||||
this.setState({
|
||||
search_string: this.changedSearchString,
|
||||
gridItems: this.getFilteredPlugins(this.changedSearchString, null, null)
|
||||
search_string: this.changedSearchString
|
||||
});
|
||||
this.changedSearchString = undefined;
|
||||
}
|
||||
@@ -588,9 +596,8 @@ export const LoadPluginDialog =
|
||||
2000);
|
||||
|
||||
}
|
||||
renderItem(row: number, column: number): React.ReactNode {
|
||||
renderItem(gridItems: UiPlugin[], row: number, column: number): React.ReactNode {
|
||||
let item: number = (row) * this.gridColumnCount + (column);
|
||||
let gridItems = this.state.gridItems;
|
||||
if (item >= gridItems.length) {
|
||||
return (<div />);
|
||||
}
|
||||
@@ -621,7 +628,7 @@ export const LoadPluginDialog =
|
||||
{
|
||||
isFavorite && (
|
||||
<div style={{ flex: "0 0 auto" }}>
|
||||
<StarBorderIcon sx={{ color: "#C80", fontSize: 16, marginRight: "2px" }} />
|
||||
<StarIcon sx={{ color: "#C80", fontSize: 16, marginRight: "2px" }} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -647,6 +654,7 @@ export const LoadPluginDialog =
|
||||
}
|
||||
gridColumnCount: number = 1;
|
||||
|
||||
|
||||
render() {
|
||||
const { classes } = this.props;
|
||||
|
||||
@@ -701,8 +709,7 @@ export const LoadPluginDialog =
|
||||
this.requestScrollTo();
|
||||
this.setState({
|
||||
search_collapsed: true,
|
||||
search_string: "",
|
||||
gridItems: this.getFilteredPlugins("", null, null)
|
||||
search_string: ""
|
||||
});
|
||||
|
||||
} else {
|
||||
@@ -718,8 +725,7 @@ export const LoadPluginDialog =
|
||||
this.requestScrollTo();
|
||||
this.setState({
|
||||
search_collapsed: true,
|
||||
search_string: "",
|
||||
gridItems: this.getFilteredPlugins("", null, null)
|
||||
search_string: ""
|
||||
});
|
||||
|
||||
} else {
|
||||
@@ -764,7 +770,9 @@ export const LoadPluginDialog =
|
||||
}
|
||||
let width = arg.width ?? 1;
|
||||
let height = arg.height ?? 1;
|
||||
let gridItems = this.state.gridItems;
|
||||
let gridItems = this.getFilteredPlugins(
|
||||
this.state.uiPlugins, this.state.search_string, this.state.filterType, this.state.favoritesList);
|
||||
this.cachedGridItems = gridItems;
|
||||
|
||||
let scrollRef = (grid: FixedSizeGrid) => { this.handleScrollToCallback(grid); }
|
||||
|
||||
@@ -793,7 +801,7 @@ export const LoadPluginDialog =
|
||||
{(arg: { columnIndex: number, rowIndex: number, style: CSSProperties }) => (
|
||||
<div style={arg.style} >
|
||||
{
|
||||
this.renderItem(arg.rowIndex, arg.columnIndex)
|
||||
this.renderItem(gridItems, arg.rowIndex, arg.columnIndex)
|
||||
}
|
||||
</div>
|
||||
)}
|
||||
@@ -837,11 +845,15 @@ export const LoadPluginDialog =
|
||||
color: isFavorite ? "#F80" : "#CCC", display: (this.state.selected_uri ? "block" : "block"),
|
||||
position: "relative"
|
||||
}}>
|
||||
{
|
||||
this.state.selected_uri !== "uri://two-play/pipedal/pedalboard#Empty" && (
|
||||
<IconButton color="inherit" aria-label="Set as favorite"
|
||||
onClick={() => { this.setFavorite(this.state.selected_uri, !isFavorite); }}
|
||||
>
|
||||
<StarBorderIcon />
|
||||
</IconButton>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div className={classes.bottom} style={{ height: 64 }}>
|
||||
|
||||
+38
-19
@@ -48,7 +48,14 @@ export enum State {
|
||||
Error,
|
||||
Background,
|
||||
Reconnecting,
|
||||
ApplyingChanges
|
||||
ApplyingChanges,
|
||||
ReloadingPlugins
|
||||
};
|
||||
|
||||
export enum ReconnectReason {
|
||||
Disconnected,
|
||||
LoadingSettings,
|
||||
ReloadingPlugins,
|
||||
};
|
||||
|
||||
export type ControlValueChangedHandler = (key: string, value: number) => void;
|
||||
@@ -356,6 +363,7 @@ export class PiPedalModel //implements PiPedalModel
|
||||
lv2Path: string = "";
|
||||
webSocket?: PiPedalSocket;
|
||||
|
||||
|
||||
ui_plugins: ObservableProperty<UiPlugin[]>
|
||||
= new ObservableProperty<UiPlugin[]>([]);
|
||||
state: ObservableProperty<State> = new ObservableProperty<State>(State.Loading);
|
||||
@@ -426,13 +434,20 @@ export class PiPedalModel //implements PiPedalModel
|
||||
onSocketReconnecting(retry: number, maxRetries: number): void {
|
||||
if (this.visibilityState.get() === VisibilityState.Hidden) return;
|
||||
//if (retry !== 0) {
|
||||
if (this.restartExpected) {
|
||||
this.setState(State.ApplyingChanges);
|
||||
this.restartExpected = false;
|
||||
} else {
|
||||
switch (this.reconnectReason)
|
||||
{
|
||||
case ReconnectReason.Disconnected:
|
||||
default:
|
||||
this.setState(State.Reconnecting);
|
||||
break;
|
||||
case ReconnectReason.LoadingSettings:
|
||||
this.setState(State.ApplyingChanges);
|
||||
break;
|
||||
case ReconnectReason.ReloadingPlugins:
|
||||
this.setState(State.ReloadingPlugins);
|
||||
break;
|
||||
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
@@ -602,9 +617,16 @@ export class PiPedalModel //implements PiPedalModel
|
||||
{
|
||||
this.showAlert(body as string);
|
||||
|
||||
} else {
|
||||
throw new PiPedalStateError("Unrecognized message received from server: " + message);
|
||||
}
|
||||
else if (message = "onLv2PluginsChanging")
|
||||
{
|
||||
this.onLv2PluginsChanging();
|
||||
}
|
||||
}
|
||||
onLv2PluginsChanging() : void {
|
||||
this.reconnectReason = ReconnectReason.ReloadingPlugins;
|
||||
// this.webSocket?.reconnect(); // let the server do it for us.
|
||||
|
||||
}
|
||||
setError(message: string): void {
|
||||
this.errorMessage.set(message);
|
||||
@@ -630,6 +652,11 @@ export class PiPedalModel //implements PiPedalModel
|
||||
}
|
||||
|
||||
|
||||
private reconnectReason: ReconnectReason = ReconnectReason.Disconnected;
|
||||
|
||||
isReloading(): boolean {
|
||||
return this.state.get() !== State.Ready;
|
||||
}
|
||||
|
||||
getWebSocket(): PiPedalSocket {
|
||||
if (this.webSocket === undefined) {
|
||||
@@ -654,7 +681,7 @@ export class PiPedalModel //implements PiPedalModel
|
||||
this.androidHost?.setDisconnected(false);
|
||||
}
|
||||
|
||||
this.restartExpected = false;
|
||||
this.reconnectReason = ReconnectReason.Disconnected;
|
||||
if (this.visibilityState.get() === VisibilityState.Hidden) return;
|
||||
|
||||
// reload state, but not configuration.
|
||||
@@ -1689,15 +1716,9 @@ export class PiPedalModel //implements PiPedalModel
|
||||
this.alertMessage.set(message);
|
||||
}
|
||||
|
||||
restartExpected: boolean = false;
|
||||
|
||||
expectRestart() {
|
||||
this.restartExpected = true;
|
||||
|
||||
|
||||
}
|
||||
setJackSettings(jackSettings: JackChannelSelection): void {
|
||||
this.expectRestart();
|
||||
this.reconnectReason = ReconnectReason.LoadingSettings;
|
||||
this.webSocket?.send("setJackSettings", jackSettings);
|
||||
}
|
||||
|
||||
@@ -2423,7 +2444,7 @@ export class PiPedalModel //implements PiPedalModel
|
||||
resolve();
|
||||
|
||||
});
|
||||
this.restartExpected = true;
|
||||
this.reconnectReason = ReconnectReason.LoadingSettings;
|
||||
this.webSocket?.reconnect(); // close immediately, and wait for recoonnect.
|
||||
return result;
|
||||
}
|
||||
@@ -2619,10 +2640,8 @@ export class PiPedalModel //implements PiPedalModel
|
||||
}
|
||||
}
|
||||
|
||||
reloadRequested: boolean = false;
|
||||
|
||||
reloadPage() {
|
||||
this.reloadRequested = true;
|
||||
// eslint-disable-next-line no-restricted-globals
|
||||
let url = window.location.href.split('#')[0];
|
||||
window.location.href = url;
|
||||
|
||||
@@ -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};
|
||||
};
|
||||
}
|
||||
+63
-30
@@ -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();
|
||||
@@ -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,16 +1821,16 @@ void PiPedalModel::DeleteMidiListeners(int64_t clientId)
|
||||
audioHost->SetListenForMidiEvent(midiEventListeners.size() != 0);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
if (item == nullptr)
|
||||
return;
|
||||
atom_object atomObject{atomValue};
|
||||
|
||||
PedalboardItem::PropertyMap &properties = item->PatchProperties();
|
||||
@@ -1924,7 +1928,7 @@ 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);
|
||||
@@ -2072,16 +2076,13 @@ std::string PiPedalModel::CreateNewSampleDirectory(const std::string&relativePat
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex);
|
||||
return storage.CreateNewSampleDirectory(relativePath, 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)
|
||||
{
|
||||
return storage.UploadUserFile(directory, patchProperty, filename, stream, contentLength);
|
||||
@@ -2100,15 +2101,14 @@ void PiPedalModel::CheckForResourceInitialization(Pedalboard &pedalboard)
|
||||
{
|
||||
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.
|
||||
@@ -2139,3 +2139,36 @@ 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:
|
||||
|
||||
|
||||
+27
-42
@@ -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());
|
||||
@@ -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.
|
||||
}
|
||||
}
|
||||
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.
|
||||
@@ -368,21 +366,6 @@ 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);
|
||||
|
||||
@@ -401,6 +384,8 @@ int main(int argc, char *argv[])
|
||||
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
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
- revise docs to remove direct reference of RPI 4 (index.html)
|
||||
- change icons on gallery in index.html
|
||||
- provide direct link to docs on both landing pages.
|
||||
- feature: redo ./makepackage so that it runs without sudo.
|
||||
- Bug: text Cursor hovering over the breadcrumb bar in file property dialog.
|
||||
- Bug: Turning off wifi-direct sould re-enable NetworkManager.
|
||||
|
||||
Reference in New Issue
Block a user