-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlv2.js
114 lines (104 loc) · 2.7 KB
/
lv2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
* This module handles lv2 interaction: scanninj plugins and getting info about ports, controls. etc.
* @module lv2
*/
const { settings } = require("../settings");
const { existsSync } = require("fs");
const store = require("./store");
const path = require("path");
const Layout = require("./layout");
/**
* Initialize: Scan for plugins and setup store (cache)
*
*/
function init() {
if (
existsSync(path.join(__dirname, "pluginCatalog.json")) &&
!store.app.SETTINGS.SCAN_PLUGINS
) {
console.log("Loading plugins cache...");
store.loadCache();
} else {
buildPluginCache();
}
store.setCategoryFilter("");
}
/**
* Scans the system for installed plugins, and save a database in memory and disk.
*/
function buildPluginCache() {
store.wlog("Building plugins cache, this might take a while, please wait...");
try {
// const names = lv2ls(true);
const plugins = grep();
store.pluginCatalog.length = 0;
store.pluginCatalog.push(...plugins);
plugins.forEach((plugin, index) => {
plugin.categories.forEach((cat) => {
if (!store.pluginCategories.includes(cat)) {
store.pluginCategories.push(cat);
}
});
});
store.saveCache();
} catch (error) {
store.wlog(error);
}
}
/**
* Grep LV2 plugin by uris, filtered by regex.
*
* @param {string} [regex="."] Regex to query plugins. By default it will return all plugins available.
* @returns Returns an array with the plugins found filtered by the regex.
*/
function grep(regex = ".") {
const cp = require("child_process");
try {
const result = cp.execSync(
`python3 ./py/calvo_cli_tools/lv2/grep.py -c --json ${regex}`,
{
encoding: "utf8",
}
);
return JSON.parse(result);
} catch (error) {
store.wlog(error);
return error;
}
}
/**
* Find a plugin by its name on the catalog.
*
* @param {*} pluginName The name to search for.
*/
function getPluginByName(pluginName) {
const result = store.pluginCatalog.filter(
(plugin) => plugin.name === pluginName
);
return result ? result[0] : null;
}
/**
* Get detailed information about a plugin.
* @param {*} uri URI of the plugin.
* @returns Returns a JSON object with the plugin's LV2 properties.
*/
function pluginInfo(uri) {
const cp = require("child_process");
try {
const result = cp.execSync(
`python3 -m calvo_cli_tools.lv2.plugin_info ${uri}`,
{
cwd: "./py",
encoding: "utf8",
}
);
return JSON.parse(result);
} catch (error) {
store.wlogError(`Plugin ${uri} could not be loaded.`);
throw error;
}
}
exports.grep = grep;
exports.pluginInfo = pluginInfo;
exports.init = init;
exports.getPluginByName = getPluginByName;