Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

438 lines
12KB

  1. /*
  2. Copyright 2007-2011 David Robillard <http://drobilla.net>
  3. Permission to use, copy, modify, and/or distribute this software for any
  4. purpose with or without fee is hereby granted, provided that the above
  5. copyright notice and this permission notice appear in all copies.
  6. THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  7. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  8. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  9. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  10. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  11. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  12. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  13. */
  14. #include <float.h>
  15. #include <math.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include "lv2/lv2plug.in/ns/ext/port-groups/port-groups.h"
  20. #include "lv2/lv2plug.in/ns/ext/presets/presets.h"
  21. #include "lv2/lv2plug.in/ns/ext/event/event.h"
  22. #include "lilv/lilv.h"
  23. #include "lilv_config.h"
  24. #ifdef _MSC_VER
  25. # define isnan _isnan
  26. #endif
  27. LilvNode* applies_to_pred = NULL;
  28. LilvNode* control_class = NULL;
  29. LilvNode* event_class = NULL;
  30. LilvNode* group_pred = NULL;
  31. LilvNode* label_pred = NULL;
  32. LilvNode* preset_class = NULL;
  33. LilvNode* designation_pred = NULL;
  34. LilvNode* supports_event_pred = NULL;
  35. static void
  36. print_port(const LilvPlugin* p,
  37. uint32_t index,
  38. float* mins,
  39. float* maxes,
  40. float* defaults)
  41. {
  42. const LilvPort* port = lilv_plugin_get_port_by_index(p, index);
  43. printf("\n\tPort %d:\n", index);
  44. if (!port) {
  45. printf("\t\tERROR: Illegal/nonexistent port\n");
  46. return;
  47. }
  48. bool first = true;
  49. const LilvNodes* classes = lilv_port_get_classes(p, port);
  50. printf("\t\tType: ");
  51. LILV_FOREACH(nodes, i, classes) {
  52. const LilvNode* value = lilv_nodes_get(classes, i);
  53. if (!first) {
  54. printf("\n\t\t ");
  55. }
  56. printf("%s", lilv_node_as_uri(value));
  57. first = false;
  58. }
  59. if (lilv_port_is_a(p, port, event_class)) {
  60. LilvNodes* supported = lilv_port_get_value(
  61. p, port, supports_event_pred);
  62. if (lilv_nodes_size(supported) > 0) {
  63. printf("\n\t\tSupported events:\n");
  64. LILV_FOREACH(nodes, i, supported) {
  65. const LilvNode* value = lilv_nodes_get(supported, i);
  66. printf("\t\t\t%s\n", lilv_node_as_uri(value));
  67. }
  68. }
  69. lilv_nodes_free(supported);
  70. }
  71. LilvScalePoints* points = lilv_port_get_scale_points(p, port);
  72. if (points)
  73. printf("\n\t\tScale Points:\n");
  74. LILV_FOREACH(scale_points, i, points) {
  75. const LilvScalePoint* point = lilv_scale_points_get(points, i);
  76. printf("\t\t\t%s = \"%s\"\n",
  77. lilv_node_as_string(lilv_scale_point_get_value(point)),
  78. lilv_node_as_string(lilv_scale_point_get_label(point)));
  79. }
  80. lilv_scale_points_free(points);
  81. const LilvNode* sym = lilv_port_get_symbol(p, port);
  82. printf("\n\t\tSymbol: %s\n", lilv_node_as_string(sym));
  83. LilvNode* name = lilv_port_get_name(p, port);
  84. printf("\t\tName: %s\n", lilv_node_as_string(name));
  85. lilv_node_free(name);
  86. LilvNodes* groups = lilv_port_get_value(p, port, group_pred);
  87. if (lilv_nodes_size(groups) > 0) {
  88. printf("\t\tGroup: %s\n",
  89. lilv_node_as_string(lilv_nodes_get_first(groups)));
  90. }
  91. lilv_nodes_free(groups);
  92. LilvNodes* designations = lilv_port_get_value(p, port, designation_pred);
  93. if (lilv_nodes_size(designations) > 0) {
  94. printf("\t\tDesignation: %s\n",
  95. lilv_node_as_string(lilv_nodes_get_first(designations)));
  96. }
  97. lilv_nodes_free(designations);
  98. if (lilv_port_is_a(p, port, control_class)) {
  99. if (!isnan(mins[index]))
  100. printf("\t\tMinimum: %f\n", mins[index]);
  101. if (!isnan(mins[index]))
  102. printf("\t\tMaximum: %f\n", maxes[index]);
  103. if (!isnan(mins[index]))
  104. printf("\t\tDefault: %f\n", defaults[index]);
  105. }
  106. LilvNodes* properties = lilv_port_get_properties(p, port);
  107. if (lilv_nodes_size(properties) > 0)
  108. printf("\t\tProperties: ");
  109. first = true;
  110. LILV_FOREACH(nodes, i, properties) {
  111. if (!first) {
  112. printf("\t\t ");
  113. }
  114. printf("%s\n", lilv_node_as_uri(lilv_nodes_get(properties, i)));
  115. first = false;
  116. }
  117. if (lilv_nodes_size(properties) > 0)
  118. printf("\n");
  119. lilv_nodes_free(properties);
  120. }
  121. static void
  122. print_plugin(LilvWorld* world,
  123. const LilvPlugin* p)
  124. {
  125. LilvNode* val = NULL;
  126. printf("%s\n\n", lilv_node_as_uri(lilv_plugin_get_uri(p)));
  127. val = lilv_plugin_get_name(p);
  128. if (val) {
  129. printf("\tName: %s\n", lilv_node_as_string(val));
  130. lilv_node_free(val);
  131. }
  132. const LilvPluginClass* pclass = lilv_plugin_get_class(p);
  133. const LilvNode* class_label = lilv_plugin_class_get_label(pclass);
  134. if (class_label) {
  135. printf("\tClass: %s\n", lilv_node_as_string(class_label));
  136. }
  137. val = lilv_plugin_get_author_name(p);
  138. if (val) {
  139. printf("\tAuthor: %s\n", lilv_node_as_string(val));
  140. lilv_node_free(val);
  141. }
  142. val = lilv_plugin_get_author_email(p);
  143. if (val) {
  144. printf("\tAuthor Email: %s\n", lilv_node_as_uri(val));
  145. lilv_node_free(val);
  146. }
  147. val = lilv_plugin_get_author_homepage(p);
  148. if (val) {
  149. printf("\tAuthor Homepage: %s\n", lilv_node_as_uri(val));
  150. lilv_node_free(val);
  151. }
  152. if (lilv_plugin_has_latency(p)) {
  153. uint32_t latency_port = lilv_plugin_get_latency_port_index(p);
  154. printf("\tHas latency: yes, reported by port %d\n", latency_port);
  155. } else {
  156. printf("\tHas latency: no\n");
  157. }
  158. printf("\tBundle: %s\n",
  159. lilv_node_as_uri(lilv_plugin_get_bundle_uri(p)));
  160. const LilvNode* binary_uri = lilv_plugin_get_library_uri(p);
  161. if (binary_uri) {
  162. printf("\tBinary: %s\n",
  163. lilv_node_as_uri(lilv_plugin_get_library_uri(p)));
  164. }
  165. LilvUIs* uis = lilv_plugin_get_uis(p);
  166. if (lilv_nodes_size(uis) > 0) {
  167. printf("\tUIs:\n");
  168. LILV_FOREACH(uis, i, uis) {
  169. const LilvUI* ui = lilv_uis_get(uis, i);
  170. printf("\t\t%s\n", lilv_node_as_uri(lilv_ui_get_uri(ui)));
  171. const char* binary = lilv_node_as_uri(lilv_ui_get_binary_uri(ui));
  172. const LilvNodes* types = lilv_ui_get_classes(ui);
  173. LILV_FOREACH(nodes, t, types) {
  174. printf("\t\t\tClass: %s\n",
  175. lilv_node_as_uri(lilv_nodes_get(types, t)));
  176. }
  177. if (binary)
  178. printf("\t\t\tBinary: %s\n", binary);
  179. printf("\t\t\tBundle: %s\n",
  180. lilv_node_as_uri(lilv_ui_get_bundle_uri(ui)));
  181. }
  182. }
  183. lilv_uis_free(uis);
  184. printf("\tData URIs: ");
  185. const LilvNodes* data_uris = lilv_plugin_get_data_uris(p);
  186. bool first = true;
  187. LILV_FOREACH(nodes, i, data_uris) {
  188. if (!first) {
  189. printf("\n\t ");
  190. }
  191. printf("%s", lilv_node_as_uri(lilv_nodes_get(data_uris, i)));
  192. first = false;
  193. }
  194. printf("\n");
  195. /* Required Features */
  196. LilvNodes* features = lilv_plugin_get_required_features(p);
  197. if (features)
  198. printf("\tRequired Features: ");
  199. first = true;
  200. LILV_FOREACH(nodes, i, features) {
  201. if (!first) {
  202. printf("\n\t ");
  203. }
  204. printf("%s", lilv_node_as_uri(lilv_nodes_get(features, i)));
  205. first = false;
  206. }
  207. if (features)
  208. printf("\n");
  209. lilv_nodes_free(features);
  210. /* Optional Features */
  211. features = lilv_plugin_get_optional_features(p);
  212. if (features)
  213. printf("\tOptional Features: ");
  214. first = true;
  215. LILV_FOREACH(nodes, i, features) {
  216. if (!first) {
  217. printf("\n\t ");
  218. }
  219. printf("%s", lilv_node_as_uri(lilv_nodes_get(features, i)));
  220. first = false;
  221. }
  222. if (features)
  223. printf("\n");
  224. lilv_nodes_free(features);
  225. /* Extension Data */
  226. LilvNodes* data = lilv_plugin_get_extension_data(p);
  227. if (data)
  228. printf("\tExtension Data: ");
  229. first = true;
  230. LILV_FOREACH(nodes, i, data) {
  231. if (!first) {
  232. printf("\n\t ");
  233. }
  234. printf("%s", lilv_node_as_uri(lilv_nodes_get(data, i)));
  235. first = false;
  236. }
  237. if (data)
  238. printf("\n");
  239. lilv_nodes_free(data);
  240. /* Presets */
  241. LilvNodes* presets = lilv_plugin_get_related(p, preset_class);
  242. if (presets)
  243. printf("\tPresets: \n");
  244. LILV_FOREACH(nodes, i, presets) {
  245. const LilvNode* preset = lilv_nodes_get(presets, i);
  246. lilv_world_load_resource(world, preset);
  247. LilvNodes* titles = lilv_world_find_nodes(
  248. world, preset, label_pred, NULL);
  249. if (titles) {
  250. const LilvNode* title = lilv_nodes_get_first(titles);
  251. printf("\t %s\n", lilv_node_as_string(title));
  252. lilv_nodes_free(titles);
  253. } else {
  254. fprintf(stderr, "Preset <%s> has no rdfs:label\n",
  255. lilv_node_as_string(lilv_nodes_get(presets, i)));
  256. }
  257. }
  258. lilv_nodes_free(presets);
  259. /* Ports */
  260. const uint32_t num_ports = lilv_plugin_get_num_ports(p);
  261. float* mins = (float*)calloc(num_ports, sizeof(float));
  262. float* maxes = (float*)calloc(num_ports, sizeof(float));
  263. float* defaults = (float*)calloc(num_ports, sizeof(float));
  264. lilv_plugin_get_port_ranges_float(p, mins, maxes, defaults);
  265. for (uint32_t i = 0; i < num_ports; ++i)
  266. print_port(p, i, mins, maxes, defaults);
  267. free(mins);
  268. free(maxes);
  269. free(defaults);
  270. }
  271. static void
  272. print_version(void)
  273. {
  274. printf(
  275. "lv2info (lilv) " LILV_VERSION "\n"
  276. "Copyright 2007-2011 David Robillard <http://drobilla.net>\n"
  277. "License: <http://www.opensource.org/licenses/isc-license>\n"
  278. "This is free software: you are free to change and redistribute it.\n"
  279. "There is NO WARRANTY, to the extent permitted by law.\n");
  280. }
  281. static void
  282. print_usage(void)
  283. {
  284. printf(
  285. "Usage: lv2info [OPTION]... PLUGIN_URI\n"
  286. "Print information about an installed LV2 plugin.\n\n"
  287. " -p FILE Write Turtle description of plugin to FILE\n"
  288. " -m FILE Add record of plugin to manifest FILE\n"
  289. " --help Display this help and exit\n"
  290. " --version Display version information and exit\n\n"
  291. "For -p and -m, Turtle files are appended to (not overwritten),\n"
  292. "and @prefix directives are only written if the file was empty.\n"
  293. "This allows several plugins to be added to a single file.\n");
  294. }
  295. int
  296. main(int argc, char** argv)
  297. {
  298. if (argc == 1) {
  299. print_usage();
  300. return 1;
  301. }
  302. const char* plugin_file = NULL;
  303. const char* manifest_file = NULL;
  304. const char* plugin_uri = NULL;
  305. for (int i = 1; i < argc; ++i) {
  306. if (!strcmp(argv[i], "--version")) {
  307. print_version();
  308. return 0;
  309. } else if (!strcmp(argv[i], "--help")) {
  310. print_usage();
  311. return 0;
  312. } else if (!strcmp(argv[i], "-p")) {
  313. plugin_file = argv[++i];
  314. } else if (!strcmp(argv[i], "-m")) {
  315. manifest_file = argv[++i];
  316. } else if (argv[i][0] == '-') {
  317. print_usage();
  318. return 1;
  319. } else if (i == argc - 1) {
  320. plugin_uri = argv[i];
  321. }
  322. }
  323. int ret = 0;
  324. LilvWorld* world = lilv_world_new();
  325. lilv_world_load_all(world);
  326. LilvNode* uri = lilv_new_uri(world, plugin_uri);
  327. if (!uri) {
  328. fprintf(stderr, "Invalid plugin URI\n");
  329. lilv_world_free(world);
  330. return 1;
  331. }
  332. applies_to_pred = lilv_new_uri(world, LV2_CORE__appliesTo);
  333. control_class = lilv_new_uri(world, LILV_URI_CONTROL_PORT);
  334. event_class = lilv_new_uri(world, LILV_URI_EVENT_PORT);
  335. group_pred = lilv_new_uri(world, LV2_PORT_GROUPS__group);
  336. label_pred = lilv_new_uri(world, LILV_NS_RDFS "label");
  337. preset_class = lilv_new_uri(world, LV2_PRESETS__Preset);
  338. designation_pred = lilv_new_uri(world, LV2_CORE__designation);
  339. supports_event_pred = lilv_new_uri(world, LV2_EVENT__supportsEvent);
  340. const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
  341. const LilvPlugin* p = lilv_plugins_get_by_uri(plugins, uri);
  342. if (p && plugin_file) {
  343. LilvNode* base = lilv_new_uri(world, plugin_file);
  344. FILE* plugin_fd = fopen(plugin_file, "a");
  345. lilv_plugin_write_description(world, p, base, plugin_fd);
  346. fclose(plugin_fd);
  347. if (manifest_file) {
  348. FILE* manifest_fd = fopen(manifest_file, "a");
  349. lilv_plugin_write_manifest_entry(
  350. world, p, base, manifest_fd, plugin_file);
  351. fclose(manifest_fd);
  352. }
  353. lilv_node_free(base);
  354. } else if (p) {
  355. print_plugin(world, p);
  356. } else {
  357. fprintf(stderr, "Plugin not found.\n");
  358. }
  359. ret = (p != NULL ? 0 : -1);
  360. lilv_node_free(uri);
  361. lilv_node_free(supports_event_pred);
  362. lilv_node_free(designation_pred);
  363. lilv_node_free(preset_class);
  364. lilv_node_free(label_pred);
  365. lilv_node_free(group_pred);
  366. lilv_node_free(event_class);
  367. lilv_node_free(control_class);
  368. lilv_node_free(applies_to_pred);
  369. lilv_world_free(world);
  370. return ret;
  371. }