Skip to content

Commit 5cd21ad

Browse files
committed
Make list ofplugins and cache
1 parent fc3ba1a commit 5cd21ad

18 files changed

+2174
-74
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Dependencies
2+
3+
JACK, Nodejs, lilv (https://github.com/moddevices/lilvlib), jack-tools

__pycache__/lilv.cpython-36.pyc

60.1 KB
Binary file not shown.

app.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ const Keyboard = require("./keyboard");
55
const Jack = require("./jack_client");
66
const ModHost = require("./modhost_client");
77
const { settings } = require("./settings");
8+
const LV2 = require("./lv2");
9+
const { lv2ls, pluginInfo, grep, listAllPlugins } = require("./lv2");
10+
const { pluginsUriByName } = require("./store");
811

9-
// const welcomeScreen = blessed.screen({});
10-
// welcomeScreen.render();
1112
const program = blessed.program();
1213

1314
// Create a screen object.
@@ -18,6 +19,9 @@ const screen = blessed.screen({
1819
try {
1920
const mainGrid = Layout.setUpLayout(screen);
2021
Keyboard.registerKeyboardShortcuts(screen, mainGrid);
22+
LV2.init();
23+
console.log(pluginsUriByName.keys());
24+
2125
Jack.init();
2226
ModHost.init();
2327
} catch (error) {

jack_client.js

+32-27
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
var shell = require("shelljs");
21
var { removeNewLines } = require("./string_utils");
3-
4-
const status = {
5-
DSP_LOAD: 0,
6-
SAMPLE_RATE: "-----",
7-
JACK_STATUS: "-----",
8-
};
2+
let { jack } = require("./store");
93

104
function init() {
115
if (isJackServerRunning()) {
@@ -16,39 +10,50 @@ function init() {
1610

1711
function poll() {
1812
if (isJackServerRunning()) {
19-
getSampleRate();
13+
updateStatus();
2014
} else {
2115
throw "JACK IS NOT RUNNING";
2216
}
2317
}
2418

19+
function updateStatus() {
20+
jack.SAMPLE_RATE = getSampleRate();
21+
jack.JACK_STATUS = getJackStatus();
22+
}
23+
24+
/**
25+
* Check whether or not the JACK server is running in the system. Uses jack_wait
26+
* @returns Returns True if JACK server is running.
27+
*/
2528
function isJackServerRunning() {
26-
const isJackRunning = shell.exec("jack_wait --check", { silent: true });
27-
status.JACK_STATUS = removeNewLines(isJackRunning.stdout);
28-
return isJackRunning.stdout.startsWith("running");
29+
const cp = require("child_process");
30+
const isJackRunning = cp.execSync("jack_wait --check", { encoding: "utf8" });
31+
return isJackRunning.startsWith("running");
2932
}
3033

31-
// Start Polling CPU usage.
32-
function startPollingCpuLoad() {
33-
const cpuLoad = shell.exec("jack_cpu_load", { silent: true });
34-
cpuLoad.stdout.on("data", function (data) {
35-
status.DSP_LOAD = data;
36-
});
34+
/**
35+
* Get Jack Status as returned from jack_wait --check.
36+
* @returns Returns "Running" "Not Running"
37+
*/
38+
function getJackStatus() {
39+
const cp = require("child_process");
40+
const isJackRunning = cp.execSync("jack_wait --check", { encoding: "utf8" });
41+
return removeNewLines(isJackRunning) === "running"
42+
? "Running"
43+
: "Not Running";
3744
}
3845

39-
// Start Polling CPU usage.
46+
/**
47+
* Get sample rate of Jack Server. Uses jack_samplerate.
48+
* @returns JACK current sample rate.
49+
*/
4050
function getSampleRate() {
41-
const jack_samplerate = shell.exec(
42-
"jack_samplerate",
43-
{ silent: true },
44-
(code, stdout, stderr) => {
45-
status.SAMPLE_RATE = stdout.replace(/(\r\n|\n|\r)/gm, "");
46-
}
47-
);
51+
const cp = require("child_process");
52+
let jack_samplerate = cp.execSync("jack_samplerate", { encoding: "utf8" });
53+
jack_samplerate = jack_samplerate.replace(/(\r\n|\n|\r)/gm, "");
54+
return jack_samplerate;
4855
}
4956

5057
exports.isJackServerRunning = isJackServerRunning;
51-
exports.startPollingCpuLoad = startPollingCpuLoad;
52-
exports.status = status;
5358
exports.init = init;
5459
exports.poll = poll;

layout.js

+20-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const blessed = require("blessed");
22
const contrib = require("blessed-contrib");
33
const Jack = require("./jack_client");
44
const { settings } = require("./settings");
5-
const { modHostProcess } = require("./modhost_client");
5+
const { jack, modHost, modHostStatusEnum } = require("./store");
66

77
const defaultWidgetStyle = {
88
focus: {
@@ -13,7 +13,7 @@ const defaultWidgetStyle = {
1313

1414
let focusIndex = 0;
1515
var mainScreen;
16-
var jackStatusWidget, modHostStatusWidget;
16+
var jackStatusWidget, modHostStatusWidget, logWidget;
1717

1818
function setUpLayout(screen) {
1919
var grid = new contrib.grid({ rows: 12, cols: 12, screen: screen });
@@ -61,19 +61,17 @@ function setUpLayout(screen) {
6161
}
6262

6363
function updateLayoutData() {
64-
// statusSampleRateWidget.content = Jack.status.SAMPLE_RATE;
65-
6664
jackStatusWidget.content = `
67-
JACK Status: ${Jack.status.JACK_STATUS}
68-
Sample Rate: ${Jack.status.SAMPLE_RATE}
69-
DSP Load: ${Jack.status.DSP_LOAD} %
65+
JACK Status: ${jack.JACK_STATUS}
66+
Sample Rate: ${jack.SAMPLE_RATE}
67+
DSP Load: ${jack.DSP_LOAD} %
7068
`;
7169

7270
modHostStatusWidget.content = `
73-
mod-host Status: ${modHostProcess.STATUS}
74-
mod-host PID: ${modHostProcess.PID}
75-
mod-host Port: ${modHostProcess.PORT}
76-
mod-host FB Port: ${modHostProcess.FEEDBACK_PORT}
71+
mod-host Status: ${modHost.STATUS}
72+
mod-host PID: ${modHost.PID}
73+
mod-host Port: ${modHost.PORT}
74+
mod-host FB Port: ${modHost.FEEDBACK_PORT}
7775
`;
7876
}
7977

@@ -95,6 +93,7 @@ function focusPrev() {
9593
}
9694
focus();
9795
mainScreen.children[focusIndex].focusable === false ? focusPrev() : focus();
96+
logWidget.log(msg);
9897
}
9998

10099
function focus() {
@@ -103,11 +102,19 @@ function focus() {
103102
}
104103

105104
function wlog(msg) {
106-
logWidget.log(msg);
105+
if (logWidget) {
106+
logWidget.log(msg);
107+
} else {
108+
console.log(msg);
109+
}
107110
}
108111

109112
function wlogError(msg) {
110-
logWidget.log(`{red-fg}${msg}{/}`);
113+
if (logWidget) {
114+
logWidget.log(`{red-fg}${msg}{/}`);
115+
} else {
116+
console.log(msg);
117+
}
111118
}
112119

113120
exports.setUpLayout = setUpLayout;

lv2.js

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
const { tabbedTreeToJSON, stringToTrimmedArray } = require("./string_utils");
2+
const { wlogError, wlog } = require("./layout");
3+
const { pluginsUriByName, saveCache, loadCache } = require("./store");
4+
const { settings } = require("./settings");
5+
6+
/**
7+
* Initialize: Scan for plugins and setup store (cache)
8+
*
9+
*/
10+
function init() {
11+
if (!settings.SCAN_PLUGINS) {
12+
console.log("Loading plugins cache...");
13+
loadCache(pluginsUriByName, "pluginsUriByName");
14+
return;
15+
}
16+
17+
console.log("Building plugins cache, please wait...");
18+
try {
19+
const names = lv2ls(true);
20+
const uris = lv2ls(false);
21+
names.forEach((name, index) => {
22+
pluginsUriByName.set(name, uris[index]);
23+
});
24+
saveCache(pluginsUriByName, "pluginsUriByName");
25+
} catch (error) {
26+
wlog(error);
27+
}
28+
}
29+
30+
/**
31+
* Gets all plugins Names AND Uris
32+
*
33+
* @returns An array of objects with name, uris as properties.
34+
*/
35+
function listAllPlugins() {
36+
let arr = [];
37+
try {
38+
const names = lv2ls(true);
39+
const uris = lv2ls(false);
40+
41+
names.forEach((name, index) => {
42+
let obj = {};
43+
obj.name = name;
44+
obj.uri = uris[index];
45+
arr.push(obj);
46+
});
47+
return arr;
48+
} catch (error) {
49+
wlog(error);
50+
return error;
51+
}
52+
}
53+
54+
/**
55+
* List all lv2 plugins available on the system.
56+
* @param {boolean} [names=false] Show names instead of URIS
57+
* @returns Returns an array with all plugins URIs/Names available on the system
58+
*/
59+
function lv2ls(names = false) {
60+
const cp = require("child_process");
61+
const param = names ? "-n" : "";
62+
try {
63+
const result = cp.execSync(`lv2ls ${param}`, { encoding: "utf8" });
64+
return stringToTrimmedArray(result);
65+
} catch (error) {
66+
wlog(error);
67+
return error;
68+
}
69+
}
70+
71+
/**
72+
* Grep LV2 plugin by uris, filtered by regex.
73+
*
74+
* @param {string} [regex="."] Regex to query plugins. By default it will return all plugins available.
75+
* @returns Returns an array with the plugins found filtered by the regex.
76+
*/
77+
function grep(regex = ".") {
78+
const cp = require("child_process");
79+
try {
80+
const result = cp.execSync(
81+
`python3 -m jackaudiotools.lv2.lv2_grep ${regex}`,
82+
{
83+
cwd: "./py",
84+
encoding: "utf8",
85+
}
86+
);
87+
return stringToTrimmedArray(result);
88+
} catch (error) {
89+
wlog(error);
90+
return error;
91+
}
92+
}
93+
94+
/**
95+
* Get detailed information about a plugin.
96+
* @param {*} uri URI of the plugin.
97+
* @returns Returns a JSON object with the plugin's LV2 properties.
98+
*/
99+
function pluginInfo(uri) {
100+
const cp = require("child_process");
101+
102+
try {
103+
const result = cp.execSync(
104+
`python3 -m jackaudiotools.lv2.plugin_info ${uri}`,
105+
{
106+
cwd: "./py",
107+
encoding: "utf8",
108+
}
109+
);
110+
return JSON.parse(result);
111+
} catch (error) {
112+
wlogError(`Plugin ${uri} could not be loaded.`);
113+
return error;
114+
}
115+
}
116+
117+
exports.lv2ls = lv2ls;
118+
exports.grep = grep;
119+
exports.pluginInfo = pluginInfo;
120+
exports.listAllPlugins = listAllPlugins;
121+
exports.init = init;

0 commit comments

Comments
 (0)