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.

1262 lines
51KB

  1. /*
  2. * Carla LV2 utils
  3. * Copyright (C) 2011-2013 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the GPL.txt file
  16. */
  17. #ifndef __CARLA_LV2_UTILS_HPP__
  18. #define __CARLA_LV2_UTILS_HPP__
  19. #include "CarlaJuceUtils.hpp"
  20. #include "lv2/lv2.h"
  21. #include "lv2/atom.h"
  22. #include "lv2/atom-forge.h"
  23. #include "lv2/atom-helpers.h"
  24. #include "lv2/atom-util.h"
  25. #include "lv2/buf-size.h"
  26. #include "lv2/data-access.h"
  27. // dynmanifest
  28. #include "lv2/event.h"
  29. #include "lv2/event-helpers.h"
  30. #include "lv2/instance-access.h"
  31. #include "lv2/log.h"
  32. // logger
  33. #include "lv2/midi.h"
  34. // morph
  35. #include "lv2/options.h"
  36. #include "lv2/parameters.h"
  37. #include "lv2/patch.h"
  38. #include "lv2/port-groups.h"
  39. #include "lv2/port-props.h"
  40. #include "lv2/presets.h"
  41. // resize-port
  42. #include "lv2/state.h"
  43. #include "lv2/time.h"
  44. #include "lv2/ui.h"
  45. #include "lv2/units.h"
  46. #include "lv2/uri-map.h"
  47. #include "lv2/urid.h"
  48. #include "lv2/worker.h"
  49. #include "lv2/lv2-miditype.h"
  50. #include "lv2/lv2-midifunctions.h"
  51. #include "lv2/lv2_external_ui.h"
  52. #include "lv2/lv2_programs.h"
  53. #include "lv2/lv2_rtmempool.h"
  54. #include "lv2_rdf.hpp"
  55. #include "lilv/lilvmm.hpp"
  56. #include "sratom/sratom.h"
  57. #include <QtCore/QMap>
  58. #include <QtCore/QStringList>
  59. // -------------------------------------------------
  60. // Define namespaces and missing prefixes
  61. #define NS_dct "http://purl.org/dc/terms/"
  62. #define NS_doap "http://usefulinc.com/ns/doap#"
  63. #define NS_rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  64. #define NS_rdfs "http://www.w3.org/2000/01/rdf-schema#"
  65. #define NS_llmm "http://ll-plugins.nongnu.org/lv2/ext/midimap#"
  66. #define LV2_MIDI_Map__CC "http://ll-plugins.nongnu.org/lv2/namespace#CC"
  67. #define LV2_MIDI_Map__NRPN "http://ll-plugins.nongnu.org/lv2/namespace#NRPN"
  68. #define LV2_MIDI_LL__MidiPort "http://ll-plugins.nongnu.org/lv2/ext/MidiPort"
  69. #define LV2_UI__Qt5UI LV2_UI_PREFIX "Qt5UI"
  70. #define LV2_UI__idle LV2_UI_PREFIX "idle"
  71. #define LV2_UI__makeResident LV2_UI_PREFIX "makeResident"
  72. // -------------------------------------------------
  73. // Custom Atom types
  74. struct LV2_Atom_MidiEvent {
  75. LV2_Atom_Event event;
  76. uint8_t data[4];
  77. };
  78. // -------------------------------------------------
  79. // Our LV2 World class
  80. class Lv2WorldClass : public Lilv::World
  81. {
  82. public:
  83. // Base Types
  84. Lilv::Node port;
  85. Lilv::Node symbol;
  86. Lilv::Node designation;
  87. Lilv::Node freeWheeling;
  88. Lilv::Node reportsLatency;
  89. // Plugin Types
  90. Lilv::Node class_allpass;
  91. Lilv::Node class_amplifier;
  92. Lilv::Node class_analyzer;
  93. Lilv::Node class_bandpass;
  94. Lilv::Node class_chorus;
  95. Lilv::Node class_comb;
  96. Lilv::Node class_compressor;
  97. Lilv::Node class_constant;
  98. Lilv::Node class_converter;
  99. Lilv::Node class_delay;
  100. Lilv::Node class_distortion;
  101. Lilv::Node class_dynamics;
  102. Lilv::Node class_eq;
  103. Lilv::Node class_envelope;
  104. Lilv::Node class_expander;
  105. Lilv::Node class_filter;
  106. Lilv::Node class_flanger;
  107. Lilv::Node class_function;
  108. Lilv::Node class_gate;
  109. Lilv::Node class_generator;
  110. Lilv::Node class_highpass;
  111. Lilv::Node class_instrument;
  112. Lilv::Node class_limiter;
  113. Lilv::Node class_lowpass;
  114. Lilv::Node class_mixer;
  115. Lilv::Node class_modulator;
  116. Lilv::Node class_multiEQ;
  117. Lilv::Node class_oscillator;
  118. Lilv::Node class_paraEQ;
  119. Lilv::Node class_phaser;
  120. Lilv::Node class_pitch;
  121. Lilv::Node class_reverb;
  122. Lilv::Node class_simulator;
  123. Lilv::Node class_spatial;
  124. Lilv::Node class_spectral;
  125. Lilv::Node class_utility;
  126. Lilv::Node class_waveshaper;
  127. // Port Types
  128. Lilv::Node port_input;
  129. Lilv::Node port_output;
  130. Lilv::Node port_control;
  131. Lilv::Node port_audio;
  132. Lilv::Node port_cv;
  133. Lilv::Node port_atom;
  134. Lilv::Node port_event;
  135. Lilv::Node port_midi;
  136. // Port Properties
  137. Lilv::Node pprop_optional;
  138. Lilv::Node pprop_enumeration;
  139. Lilv::Node pprop_integer;
  140. Lilv::Node pprop_sampleRate;
  141. Lilv::Node pprop_toggled;
  142. Lilv::Node pprop_artifacts;
  143. Lilv::Node pprop_continuousCV;
  144. Lilv::Node pprop_discreteCV;
  145. Lilv::Node pprop_expensive;
  146. Lilv::Node pprop_strictBounds;
  147. Lilv::Node pprop_logarithmic;
  148. Lilv::Node pprop_notAutomatic;
  149. Lilv::Node pprop_notOnGUI;
  150. Lilv::Node pprop_trigger;
  151. // Unit Hints
  152. Lilv::Node unit_name;
  153. Lilv::Node unit_render;
  154. Lilv::Node unit_symbol;
  155. Lilv::Node unit_unit;
  156. // UI Types
  157. Lilv::Node ui_gtk2;
  158. Lilv::Node ui_gtk3;
  159. Lilv::Node ui_qt4;
  160. Lilv::Node ui_qt5;
  161. Lilv::Node ui_cocoa;
  162. Lilv::Node ui_windows;
  163. Lilv::Node ui_x11;
  164. Lilv::Node ui_external;
  165. Lilv::Node ui_externalOld;
  166. // Misc
  167. Lilv::Node atom_bufferType;
  168. Lilv::Node atom_sequence;
  169. Lilv::Node atom_supports;
  170. Lilv::Node preset_preset;
  171. Lilv::Node state_state;
  172. Lilv::Node value_default;
  173. Lilv::Node value_minimum;
  174. Lilv::Node value_maximum;
  175. // Port Data Types
  176. Lilv::Node midi_event;
  177. Lilv::Node patch_message;
  178. Lilv::Node time_position;
  179. // MIDI CC
  180. Lilv::Node mm_defaultControl;
  181. Lilv::Node mm_controlType;
  182. Lilv::Node mm_controlNumber;
  183. // Other
  184. Lilv::Node dct_replaces;
  185. Lilv::Node doap_license;
  186. Lilv::Node rdf_type;
  187. Lilv::Node rdfs_label;
  188. // -------------------------------------------------
  189. Lv2WorldClass()
  190. : Lilv::World(),
  191. port (new_uri(LV2_CORE__port)),
  192. symbol (new_uri(LV2_CORE__symbol)),
  193. designation (new_uri(LV2_CORE__designation)),
  194. freeWheeling (new_uri(LV2_CORE__freeWheeling)),
  195. reportsLatency (new_uri(LV2_CORE__reportsLatency)),
  196. class_allpass (new_uri(LV2_CORE__AllpassPlugin)),
  197. class_amplifier (new_uri(LV2_CORE__AmplifierPlugin)),
  198. class_analyzer (new_uri(LV2_CORE__AnalyserPlugin)),
  199. class_bandpass (new_uri(LV2_CORE__BandpassPlugin)),
  200. class_chorus (new_uri(LV2_CORE__ChorusPlugin)),
  201. class_comb (new_uri(LV2_CORE__CombPlugin)),
  202. class_compressor (new_uri(LV2_CORE__CompressorPlugin)),
  203. class_constant (new_uri(LV2_CORE__ConstantPlugin)),
  204. class_converter (new_uri(LV2_CORE__ConverterPlugin)),
  205. class_delay (new_uri(LV2_CORE__DelayPlugin)),
  206. class_distortion (new_uri(LV2_CORE__DistortionPlugin)),
  207. class_dynamics (new_uri(LV2_CORE__DynamicsPlugin)),
  208. class_eq (new_uri(LV2_CORE__EQPlugin)),
  209. class_envelope (new_uri(LV2_CORE__EnvelopePlugin)),
  210. class_expander (new_uri(LV2_CORE__ExpanderPlugin)),
  211. class_filter (new_uri(LV2_CORE__FilterPlugin)),
  212. class_flanger (new_uri(LV2_CORE__FlangerPlugin)),
  213. class_function (new_uri(LV2_CORE__FunctionPlugin)),
  214. class_gate (new_uri(LV2_CORE__GatePlugin)),
  215. class_generator (new_uri(LV2_CORE__GeneratorPlugin)),
  216. class_highpass (new_uri(LV2_CORE__HighpassPlugin)),
  217. class_instrument (new_uri(LV2_CORE__InstrumentPlugin)),
  218. class_limiter (new_uri(LV2_CORE__LimiterPlugin)),
  219. class_lowpass (new_uri(LV2_CORE__LowpassPlugin)),
  220. class_mixer (new_uri(LV2_CORE__MixerPlugin)),
  221. class_modulator (new_uri(LV2_CORE__ModulatorPlugin)),
  222. class_multiEQ (new_uri(LV2_CORE__MultiEQPlugin)),
  223. class_oscillator (new_uri(LV2_CORE__OscillatorPlugin)),
  224. class_paraEQ (new_uri(LV2_CORE__ParaEQPlugin)),
  225. class_phaser (new_uri(LV2_CORE__PhaserPlugin)),
  226. class_pitch (new_uri(LV2_CORE__PitchPlugin)),
  227. class_reverb (new_uri(LV2_CORE__ReverbPlugin)),
  228. class_simulator (new_uri(LV2_CORE__SimulatorPlugin)),
  229. class_spatial (new_uri(LV2_CORE__SpatialPlugin)),
  230. class_spectral (new_uri(LV2_CORE__SpectralPlugin)),
  231. class_utility (new_uri(LV2_CORE__UtilityPlugin)),
  232. class_waveshaper (new_uri(LV2_CORE__WaveshaperPlugin)),
  233. port_input (new_uri(LV2_CORE__InputPort)),
  234. port_output (new_uri(LV2_CORE__OutputPort)),
  235. port_control (new_uri(LV2_CORE__ControlPort)),
  236. port_audio (new_uri(LV2_CORE__AudioPort)),
  237. port_cv (new_uri(LV2_CORE__CVPort)),
  238. port_atom (new_uri(LV2_ATOM__AtomPort)),
  239. port_event (new_uri(LV2_EVENT__EventPort)),
  240. port_midi (new_uri(LV2_MIDI_LL__MidiPort)),
  241. pprop_optional (new_uri(LV2_CORE__connectionOptional)),
  242. pprop_enumeration (new_uri(LV2_CORE__enumeration)),
  243. pprop_integer (new_uri(LV2_CORE__integer)),
  244. pprop_sampleRate (new_uri(LV2_CORE__sampleRate)),
  245. pprop_toggled (new_uri(LV2_CORE__toggled)),
  246. pprop_artifacts (new_uri(LV2_PORT_PROPS__causesArtifacts)),
  247. pprop_continuousCV (new_uri(LV2_PORT_PROPS__continuousCV)),
  248. pprop_discreteCV (new_uri(LV2_PORT_PROPS__discreteCV)),
  249. pprop_expensive (new_uri(LV2_PORT_PROPS__expensive)),
  250. pprop_strictBounds (new_uri(LV2_PORT_PROPS__hasStrictBounds)),
  251. pprop_logarithmic (new_uri(LV2_PORT_PROPS__logarithmic)),
  252. pprop_notAutomatic (new_uri(LV2_PORT_PROPS__notAutomatic)),
  253. pprop_notOnGUI (new_uri(LV2_PORT_PROPS__notOnGUI)),
  254. pprop_trigger (new_uri(LV2_PORT_PROPS__trigger)),
  255. unit_name (new_uri(LV2_UNITS__name)),
  256. unit_render (new_uri(LV2_UNITS__render)),
  257. unit_symbol (new_uri(LV2_UNITS__symbol)),
  258. unit_unit (new_uri(LV2_UNITS__unit)),
  259. ui_gtk2 (new_uri(LV2_UI__GtkUI)),
  260. ui_gtk3 (new_uri(LV2_UI__Gtk3UI)),
  261. ui_qt4 (new_uri(LV2_UI__Qt4UI)),
  262. ui_qt5 (new_uri(LV2_UI__Qt5UI)),
  263. ui_cocoa (new_uri(LV2_UI__CocoaUI)),
  264. ui_windows (new_uri(LV2_UI__WindowsUI)),
  265. ui_x11 (new_uri(LV2_UI__X11UI)),
  266. ui_external (new_uri(LV2_EXTERNAL_UI__Widget)),
  267. ui_externalOld (new_uri(LV2_EXTERNAL_UI_DEPRECATED_URI)),
  268. atom_bufferType (new_uri(LV2_ATOM__bufferType)),
  269. atom_sequence (new_uri(LV2_ATOM__Sequence)),
  270. atom_supports (new_uri(LV2_ATOM__supports)),
  271. preset_preset (new_uri(LV2_PRESETS__Preset)),
  272. state_state (new_uri(LV2_STATE__state)),
  273. value_default (new_uri(LV2_CORE__default)),
  274. value_minimum (new_uri(LV2_CORE__minimum)),
  275. value_maximum (new_uri(LV2_CORE__maximum)),
  276. midi_event (new_uri(LV2_MIDI__MidiEvent)),
  277. patch_message (new_uri(LV2_PATCH__Message)),
  278. time_position (new_uri(LV2_TIME__Position)),
  279. mm_defaultControl (new_uri(NS_llmm "defaultMidiController")),
  280. mm_controlType (new_uri(NS_llmm "controllerType")),
  281. mm_controlNumber (new_uri(NS_llmm "controllerNumber")),
  282. dct_replaces (new_uri(NS_dct "replaces")),
  283. doap_license (new_uri(NS_doap "license")),
  284. rdf_type (new_uri(NS_rdf "type")),
  285. rdfs_label (new_uri(NS_rdfs "label"))
  286. {
  287. needInit = true;
  288. }
  289. void init()
  290. {
  291. if (! needInit)
  292. return;
  293. needInit = false;
  294. Lilv::World::load_all();
  295. }
  296. const LilvPlugin* getPlugin(const LV2_URI uri)
  297. {
  298. CARLA_ASSERT(uri != nullptr);
  299. static const Lilv::Plugins lilvPlugins(Lilv::World::get_all_plugins());
  300. LilvNode* const uriNode(Lilv::World::new_uri(uri));
  301. if (uriNode == nullptr)
  302. {
  303. carla_stderr("Lv2WorldClass::getPlugin(\"%s\") - Failed to get node from uri", uri);
  304. return nullptr;
  305. }
  306. if (const LilvPlugin* const cPlugin = lilv_plugins_get_by_uri(lilvPlugins.me, uriNode))
  307. {
  308. lilv_node_free(uriNode);
  309. return cPlugin;
  310. }
  311. else
  312. {
  313. carla_stderr("Lv2WorldClass::getPlugin(\"%s\") - Failed to get plugin", uri);
  314. lilv_node_free(uriNode);
  315. return nullptr;
  316. }
  317. }
  318. private:
  319. bool needInit;
  320. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Lv2WorldClass)
  321. };
  322. // -----------------------------------------------------
  323. // Our LV2 World class object
  324. extern Lv2WorldClass gLv2World;
  325. // -----------------------------------------------------
  326. // Create new RDF object (using lilv)
  327. static inline
  328. const LV2_RDF_Descriptor* lv2_rdf_new(const LV2_URI uri)
  329. {
  330. CARLA_ASSERT(uri != nullptr);
  331. if (uri == nullptr)
  332. {
  333. carla_stderr("lv2_rdf_new() - Invalid uri");
  334. return nullptr;
  335. }
  336. const LilvPlugin* const cPlugin(gLv2World.getPlugin(uri));
  337. if (cPlugin == nullptr)
  338. {
  339. // Error already printed in getPlugin()
  340. return nullptr;
  341. }
  342. Lilv::Plugin lilvPlugin(cPlugin);
  343. LV2_RDF_Descriptor* const rdfDescriptor(new LV2_RDF_Descriptor());
  344. // --------------------------------------------------
  345. // Set Plugin Type
  346. {
  347. Lilv::Nodes typeNodes(lilvPlugin.get_value(gLv2World.rdf_type));
  348. if (typeNodes.size() > 0)
  349. {
  350. if (typeNodes.contains(gLv2World.class_allpass))
  351. rdfDescriptor->Type[0] |= LV2_PLUGIN_ALLPASS;
  352. if (typeNodes.contains(gLv2World.class_amplifier))
  353. rdfDescriptor->Type[0] |= LV2_PLUGIN_AMPLIFIER;
  354. if (typeNodes.contains(gLv2World.class_analyzer))
  355. rdfDescriptor->Type[1] |= LV2_PLUGIN_ANALYSER;
  356. if (typeNodes.contains(gLv2World.class_bandpass))
  357. rdfDescriptor->Type[0] |= LV2_PLUGIN_BANDPASS;
  358. if (typeNodes.contains(gLv2World.class_chorus))
  359. rdfDescriptor->Type[1] |= LV2_PLUGIN_CHORUS;
  360. if (typeNodes.contains(gLv2World.class_comb))
  361. rdfDescriptor->Type[1] |= LV2_PLUGIN_COMB;
  362. if (typeNodes.contains(gLv2World.class_compressor))
  363. rdfDescriptor->Type[0] |= LV2_PLUGIN_COMPRESSOR;
  364. if (typeNodes.contains(gLv2World.class_constant))
  365. rdfDescriptor->Type[1] |= LV2_PLUGIN_CONSTANT;
  366. if (typeNodes.contains(gLv2World.class_converter))
  367. rdfDescriptor->Type[1] |= LV2_PLUGIN_CONVERTER;
  368. if (typeNodes.contains(gLv2World.class_delay))
  369. rdfDescriptor->Type[0] |= LV2_PLUGIN_DELAY;
  370. if (typeNodes.contains(gLv2World.class_distortion))
  371. rdfDescriptor->Type[0] |= LV2_PLUGIN_DISTORTION;
  372. if (typeNodes.contains(gLv2World.class_dynamics))
  373. rdfDescriptor->Type[0] |= LV2_PLUGIN_DYNAMICS;
  374. if (typeNodes.contains(gLv2World.class_eq))
  375. rdfDescriptor->Type[0] |= LV2_PLUGIN_EQ;
  376. if (typeNodes.contains(gLv2World.class_envelope))
  377. rdfDescriptor->Type[0] |= LV2_PLUGIN_ENVELOPE;
  378. if (typeNodes.contains(gLv2World.class_expander))
  379. rdfDescriptor->Type[0] |= LV2_PLUGIN_EXPANDER;
  380. if (typeNodes.contains(gLv2World.class_filter))
  381. rdfDescriptor->Type[0] |= LV2_PLUGIN_FILTER;
  382. if (typeNodes.contains(gLv2World.class_flanger))
  383. rdfDescriptor->Type[1] |= LV2_PLUGIN_FLANGER;
  384. if (typeNodes.contains(gLv2World.class_function))
  385. rdfDescriptor->Type[1] |= LV2_PLUGIN_FUNCTION;
  386. if (typeNodes.contains(gLv2World.class_gate))
  387. rdfDescriptor->Type[0] |= LV2_PLUGIN_GATE;
  388. if (typeNodes.contains(gLv2World.class_generator))
  389. rdfDescriptor->Type[1] |= LV2_PLUGIN_GENERATOR;
  390. if (typeNodes.contains(gLv2World.class_highpass))
  391. rdfDescriptor->Type[0] |= LV2_PLUGIN_HIGHPASS;
  392. if (typeNodes.contains(gLv2World.class_instrument))
  393. rdfDescriptor->Type[1] |= LV2_PLUGIN_INSTRUMENT;
  394. if (typeNodes.contains(gLv2World.class_limiter))
  395. rdfDescriptor->Type[0] |= LV2_PLUGIN_LIMITER;
  396. if (typeNodes.contains(gLv2World.class_lowpass))
  397. rdfDescriptor->Type[0] |= LV2_PLUGIN_LOWPASS;
  398. if (typeNodes.contains(gLv2World.class_mixer))
  399. rdfDescriptor->Type[1] |= LV2_PLUGIN_MIXER;
  400. if (typeNodes.contains(gLv2World.class_modulator))
  401. rdfDescriptor->Type[1] |= LV2_PLUGIN_MODULATOR;
  402. if (typeNodes.contains(gLv2World.class_multiEQ))
  403. rdfDescriptor->Type[0] |= LV2_PLUGIN_MULTI_EQ;
  404. if (typeNodes.contains(gLv2World.class_oscillator))
  405. rdfDescriptor->Type[1] |= LV2_PLUGIN_OSCILLATOR;
  406. if (typeNodes.contains(gLv2World.class_paraEQ))
  407. rdfDescriptor->Type[0] |= LV2_PLUGIN_PARA_EQ;
  408. if (typeNodes.contains(gLv2World.class_phaser))
  409. rdfDescriptor->Type[1] |= LV2_PLUGIN_PHASER;
  410. if (typeNodes.contains(gLv2World.class_pitch))
  411. rdfDescriptor->Type[1] |= LV2_PLUGIN_PITCH;
  412. if (typeNodes.contains(gLv2World.class_reverb))
  413. rdfDescriptor->Type[0] |= LV2_PLUGIN_REVERB;
  414. if (typeNodes.contains(gLv2World.class_simulator))
  415. rdfDescriptor->Type[0] |= LV2_PLUGIN_SIMULATOR;
  416. if (typeNodes.contains(gLv2World.class_spatial))
  417. rdfDescriptor->Type[1] |= LV2_PLUGIN_SPATIAL;
  418. if (typeNodes.contains(gLv2World.class_spectral))
  419. rdfDescriptor->Type[1] |= LV2_PLUGIN_SPECTRAL;
  420. if (typeNodes.contains(gLv2World.class_utility))
  421. rdfDescriptor->Type[1] |= LV2_PLUGIN_UTILITY;
  422. if (typeNodes.contains(gLv2World.class_waveshaper))
  423. rdfDescriptor->Type[0] |= LV2_PLUGIN_WAVESHAPER;
  424. }
  425. }
  426. // --------------------------------------------------
  427. // Set Plugin Information
  428. {
  429. rdfDescriptor->URI = carla_strdup(uri);
  430. if (const char* const name = lilvPlugin.get_name().as_string())
  431. rdfDescriptor->Name = carla_strdup(name);
  432. if (const char* const author = lilvPlugin.get_author_name().as_string())
  433. rdfDescriptor->Author = carla_strdup(author);
  434. if (const char* const binary = lilvPlugin.get_library_uri().as_string())
  435. rdfDescriptor->Binary = carla_strdup(lilv_uri_to_path(binary));
  436. if (const char* const bundle = lilvPlugin.get_bundle_uri().as_string())
  437. rdfDescriptor->Bundle = carla_strdup(lilv_uri_to_path(bundle));
  438. Lilv::Nodes licenseNodes(lilvPlugin.get_value(gLv2World.doap_license));
  439. if (licenseNodes.size() > 0)
  440. {
  441. if (const char* const license = licenseNodes.get_first().as_string())
  442. rdfDescriptor->License = carla_strdup(license);
  443. }
  444. }
  445. // --------------------------------------------------
  446. // Set Plugin UniqueID
  447. {
  448. Lilv::Nodes replaceNodes(lilvPlugin.get_value(gLv2World.dct_replaces));
  449. if (replaceNodes.size() > 0)
  450. {
  451. Lilv::Node replaceNode(replaceNodes.get_first());
  452. if (replaceNode.is_uri())
  453. {
  454. const QString replaceURI(replaceNode.as_uri());
  455. if (replaceURI.startsWith("urn:"))
  456. {
  457. const QString replaceId(replaceURI.split(":").last());
  458. bool ok;
  459. ulong uniqueId = replaceId.toULong(&ok);
  460. if (ok && uniqueId != 0)
  461. rdfDescriptor->UniqueID = uniqueId;
  462. }
  463. }
  464. }
  465. }
  466. // --------------------------------------------------
  467. // Set Plugin Ports
  468. if (lilvPlugin.get_num_ports() > 0)
  469. {
  470. rdfDescriptor->PortCount = lilvPlugin.get_num_ports();
  471. rdfDescriptor->Ports = new LV2_RDF_Port[rdfDescriptor->PortCount];
  472. for (uint32_t j = 0; j < rdfDescriptor->PortCount; j++)
  473. {
  474. Lilv::Port lilvPort(lilvPlugin.get_port_by_index(j));
  475. LV2_RDF_Port* const rdfPort = &rdfDescriptor->Ports[j];
  476. // --------------------------------------
  477. // Set Port Information
  478. {
  479. if (const char* const name = Lilv::Node(lilvPort.get_name()).as_string())
  480. rdfPort->Name = carla_strdup(name);
  481. if (const char* const symbol = Lilv::Node(lilvPort.get_symbol()).as_string())
  482. rdfPort->Symbol = carla_strdup(symbol);
  483. }
  484. // --------------------------------------
  485. // Set Port Mode and Type
  486. {
  487. // Input or Output
  488. if (lilvPort.is_a(gLv2World.port_input))
  489. rdfPort->Types |= LV2_PORT_INPUT;
  490. else if (lilvPort.is_a(gLv2World.port_output))
  491. rdfPort->Types |= LV2_PORT_OUTPUT;
  492. else
  493. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is not input or output", uri, rdfPort->Name);
  494. // Data Type
  495. if (lilvPort.is_a(gLv2World.port_control))
  496. rdfPort->Types |= LV2_PORT_CONTROL;
  497. else if (lilvPort.is_a(gLv2World.port_audio))
  498. rdfPort->Types |= LV2_PORT_AUDIO;
  499. else if (lilvPort.is_a(gLv2World.port_cv))
  500. rdfPort->Types |= LV2_PORT_CV;
  501. else if (lilvPort.is_a(gLv2World.port_atom))
  502. {
  503. rdfPort->Types |= LV2_PORT_ATOM;
  504. Lilv::Nodes bufferTypeNodes(lilvPort.get_value(gLv2World.atom_bufferType));
  505. if (bufferTypeNodes.contains(gLv2World.atom_sequence))
  506. rdfPort->Types |= LV2_PORT_ATOM_SEQUENCE;
  507. else
  508. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses an unknown atom buffer type", uri, rdfPort->Name);
  509. Lilv::Nodes supportNodes(lilvPort.get_value(gLv2World.atom_supports));
  510. bool supported = false;
  511. if (supportNodes.contains(gLv2World.midi_event))
  512. {
  513. rdfPort->Types |= LV2_PORT_DATA_MIDI_EVENT;
  514. supported = true;
  515. }
  516. if (supportNodes.contains(gLv2World.patch_message))
  517. {
  518. rdfPort->Types |= LV2_PORT_DATA_PATCH_MESSAGE;
  519. supported = true;
  520. }
  521. if (supportNodes.contains(gLv2World.time_position))
  522. {
  523. rdfPort->Types |= LV2_PORT_DATA_TIME_POSITION;
  524. supported = true;
  525. }
  526. if (! supported)
  527. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is of atom type but has unsupported data", uri, rdfPort->Name);
  528. }
  529. else if (lilvPort.is_a(gLv2World.port_event))
  530. {
  531. rdfPort->Types |= LV2_PORT_EVENT;
  532. bool supported = false;
  533. if (lilvPort.supports_event(gLv2World.midi_event))
  534. {
  535. rdfPort->Types |= LV2_PORT_DATA_MIDI_EVENT;
  536. supported = true;
  537. }
  538. if (lilvPort.supports_event(gLv2World.patch_message))
  539. {
  540. rdfPort->Types |= LV2_PORT_DATA_PATCH_MESSAGE;
  541. supported = true;
  542. }
  543. if (lilvPort.supports_event(gLv2World.time_position))
  544. {
  545. rdfPort->Types |= LV2_PORT_DATA_TIME_POSITION;
  546. supported = true;
  547. }
  548. if (! supported)
  549. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is of event type but has unsupported data", uri, rdfPort->Name);
  550. }
  551. else if (lilvPort.is_a(gLv2World.port_midi))
  552. {
  553. rdfPort->Types |= LV2_PORT_MIDI_LL;
  554. rdfPort->Types |= LV2_PORT_DATA_MIDI_EVENT;
  555. }
  556. else
  557. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is of unkown data type", uri, rdfPort->Name);
  558. }
  559. // --------------------------------------
  560. // Set Port Properties
  561. {
  562. if (lilvPort.has_property(gLv2World.pprop_optional))
  563. rdfPort->Properties |= LV2_PORT_OPTIONAL;
  564. if (lilvPort.has_property(gLv2World.pprop_enumeration))
  565. rdfPort->Properties |= LV2_PORT_ENUMERATION;
  566. if (lilvPort.has_property(gLv2World.pprop_integer))
  567. rdfPort->Properties |= LV2_PORT_INTEGER;
  568. if (lilvPort.has_property(gLv2World.pprop_sampleRate))
  569. rdfPort->Properties |= LV2_PORT_SAMPLE_RATE;
  570. if (lilvPort.has_property(gLv2World.pprop_toggled))
  571. rdfPort->Properties |= LV2_PORT_TOGGLED;
  572. if (lilvPort.has_property(gLv2World.pprop_artifacts))
  573. rdfPort->Properties |= LV2_PORT_CAUSES_ARTIFACTS;
  574. if (lilvPort.has_property(gLv2World.pprop_continuousCV))
  575. rdfPort->Properties |= LV2_PORT_CONTINUOUS_CV;
  576. if (lilvPort.has_property(gLv2World.pprop_discreteCV))
  577. rdfPort->Properties |= LV2_PORT_DISCRETE_CV;
  578. if (lilvPort.has_property(gLv2World.pprop_expensive))
  579. rdfPort->Properties |= LV2_PORT_EXPENSIVE;
  580. if (lilvPort.has_property(gLv2World.pprop_strictBounds))
  581. rdfPort->Properties |= LV2_PORT_STRICT_BOUNDS;
  582. if (lilvPort.has_property(gLv2World.pprop_logarithmic))
  583. rdfPort->Properties |= LV2_PORT_LOGARITHMIC;
  584. if (lilvPort.has_property(gLv2World.pprop_notAutomatic))
  585. rdfPort->Properties |= LV2_PORT_NOT_AUTOMATIC;
  586. if (lilvPort.has_property(gLv2World.pprop_notOnGUI))
  587. rdfPort->Properties |= LV2_PORT_NOT_ON_GUI;
  588. if (lilvPort.has_property(gLv2World.pprop_trigger))
  589. rdfPort->Properties |= LV2_PORT_TRIGGER;
  590. if (lilvPort.has_property(gLv2World.reportsLatency))
  591. rdfPort->Designation = LV2_PORT_DESIGNATION_LATENCY;
  592. }
  593. // --------------------------------------
  594. // Set Port Designation
  595. {
  596. Lilv::Nodes designationNodes(lilvPort.get_value(gLv2World.designation));
  597. if (designationNodes.size() > 0)
  598. {
  599. if (const char* const designation = designationNodes.get_first().as_string())
  600. {
  601. if (std::strcmp(designation, LV2_CORE__control) == 0)
  602. rdfPort->Designation = LV2_PORT_DESIGNATION_CONTROL;
  603. else if (std::strcmp(designation, LV2_CORE__freeWheeling) == 0)
  604. rdfPort->Designation = LV2_PORT_DESIGNATION_FREEWHEELING;
  605. else if (std::strcmp(designation, LV2_CORE__latency) == 0)
  606. rdfPort->Designation = LV2_PORT_DESIGNATION_LATENCY;
  607. else if (std::strcmp(designation, LV2_PARAMETERS__sampleRate) == 0)
  608. rdfPort->Designation = LV2_PORT_DESIGNATION_SAMPLE_RATE;
  609. else if (std::strcmp(designation, LV2_TIME__bar) == 0)
  610. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BAR;
  611. else if (std::strcmp(designation, LV2_TIME__barBeat) == 0)
  612. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BAR_BEAT;
  613. else if (std::strcmp(designation, LV2_TIME__beat) == 0)
  614. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEAT;
  615. else if (std::strcmp(designation, LV2_TIME__beatUnit) == 0)
  616. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEAT_UNIT;
  617. else if (std::strcmp(designation, LV2_TIME__beatsPerBar) == 0)
  618. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEATS_PER_BAR;
  619. else if (std::strcmp(designation, LV2_TIME__beatsPerMinute) == 0)
  620. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEATS_PER_MINUTE;
  621. else if (std::strcmp(designation, LV2_TIME__frame) == 0)
  622. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_FRAME;
  623. else if (std::strcmp(designation, LV2_TIME__framesPerSecond) == 0)
  624. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_FRAMES_PER_SECOND;
  625. else if (std::strcmp(designation, LV2_TIME__speed) == 0)
  626. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_SPEED;
  627. else if (std::strncmp(designation, LV2_PARAMETERS_PREFIX, std::strlen(LV2_PARAMETERS_PREFIX)) == 0)
  628. pass();
  629. else if (std::strncmp(designation, LV2_PORT_GROUPS_PREFIX, std::strlen(LV2_PORT_GROUPS_PREFIX)) == 0)
  630. pass();
  631. else
  632. carla_stderr("lv2_rdf_new(\"%s\") - got unknown port designation '%s'", uri, designation);
  633. }
  634. }
  635. }
  636. // --------------------------------------
  637. // Set Port MIDI Map
  638. {
  639. Lilv::Nodes midiMapNodes(lilvPort.get_value(gLv2World.mm_defaultControl));
  640. if (midiMapNodes.size() > 0)
  641. {
  642. Lilv::Node midiMapNode(midiMapNodes.get_first());
  643. if (midiMapNode.is_blank())
  644. {
  645. Lilv::Nodes midiMapTypeNodes(gLv2World.find_nodes(midiMapNode, gLv2World.mm_controlType, nullptr));
  646. Lilv::Nodes midiMapNumberNodes(gLv2World.find_nodes(midiMapNode, gLv2World.mm_controlNumber, nullptr));
  647. if (midiMapTypeNodes.size() == 1 && midiMapNumberNodes.size() == 1)
  648. {
  649. if (const char* const midiMapType = midiMapTypeNodes.get_first().as_string())
  650. {
  651. if (std::strcmp(midiMapType, LV2_MIDI_Map__CC) == 0)
  652. rdfPort->MidiMap.Type = LV2_PORT_MIDI_MAP_CC;
  653. else if (std::strcmp(midiMapType, LV2_MIDI_Map__NRPN) == 0)
  654. rdfPort->MidiMap.Type = LV2_PORT_MIDI_MAP_NRPN;
  655. else
  656. carla_stderr("lv2_rdf_new(\"%s\") - got unknown port Midi-Map type '%s'", uri, midiMapType);
  657. rdfPort->MidiMap.Number = static_cast<uint32_t>(midiMapNumberNodes.get_first().as_int());
  658. }
  659. }
  660. }
  661. }
  662. // TODO - also check using new official MIDI API too
  663. }
  664. // --------------------------------------
  665. // Set Port Points
  666. {
  667. Lilv::Nodes valueNodes(lilvPort.get_value(gLv2World.value_default));
  668. if (valueNodes.size() > 0)
  669. {
  670. rdfPort->Points.Hints |= LV2_PORT_POINT_DEFAULT;
  671. rdfPort->Points.Default = valueNodes.get_first().as_float();
  672. }
  673. valueNodes = lilvPort.get_value(gLv2World.value_minimum);
  674. if (valueNodes.size() > 0)
  675. {
  676. rdfPort->Points.Hints |= LV2_PORT_POINT_MINIMUM;
  677. rdfPort->Points.Minimum = valueNodes.get_first().as_float();
  678. }
  679. valueNodes = lilvPort.get_value(gLv2World.value_maximum);
  680. if (valueNodes.size() > 0)
  681. {
  682. rdfPort->Points.Hints |= LV2_PORT_POINT_MAXIMUM;
  683. rdfPort->Points.Maximum = valueNodes.get_first().as_float();
  684. }
  685. }
  686. // --------------------------------------
  687. // Set Port Unit
  688. {
  689. Lilv::Nodes unitUnitNodes(lilvPort.get_value(gLv2World.unit_unit));
  690. if (unitUnitNodes.size() > 0)
  691. {
  692. if (const char* const unitUnit = unitUnitNodes.get_first().as_uri())
  693. {
  694. rdfPort->Unit.Hints |= LV2_PORT_UNIT_UNIT;
  695. if (std::strcmp(unitUnit, LV2_UNITS__bar) == 0)
  696. rdfPort->Unit.Unit = LV2_PORT_UNIT_BAR;
  697. else if (std::strcmp(unitUnit, LV2_UNITS__beat) == 0)
  698. rdfPort->Unit.Unit = LV2_PORT_UNIT_BEAT;
  699. else if (std::strcmp(unitUnit, LV2_UNITS__bpm) == 0)
  700. rdfPort->Unit.Unit = LV2_PORT_UNIT_BPM;
  701. else if (std::strcmp(unitUnit, LV2_UNITS__cent) == 0)
  702. rdfPort->Unit.Unit = LV2_PORT_UNIT_CENT;
  703. else if (std::strcmp(unitUnit, LV2_UNITS__cm) == 0)
  704. rdfPort->Unit.Unit = LV2_PORT_UNIT_CM;
  705. else if (std::strcmp(unitUnit, LV2_UNITS__coef) == 0)
  706. rdfPort->Unit.Unit = LV2_PORT_UNIT_COEF;
  707. else if (std::strcmp(unitUnit, LV2_UNITS__db) == 0)
  708. rdfPort->Unit.Unit = LV2_PORT_UNIT_DB;
  709. else if (std::strcmp(unitUnit, LV2_UNITS__degree) == 0)
  710. rdfPort->Unit.Unit = LV2_PORT_UNIT_DEGREE;
  711. else if (std::strcmp(unitUnit, LV2_UNITS__frame) == 0)
  712. rdfPort->Unit.Unit = LV2_PORT_UNIT_FRAME;
  713. else if (std::strcmp(unitUnit, LV2_UNITS__hz) == 0)
  714. rdfPort->Unit.Unit = LV2_PORT_UNIT_HZ;
  715. else if (std::strcmp(unitUnit, LV2_UNITS__inch) == 0)
  716. rdfPort->Unit.Unit = LV2_PORT_UNIT_INCH;
  717. else if (std::strcmp(unitUnit, LV2_UNITS__khz) == 0)
  718. rdfPort->Unit.Unit = LV2_PORT_UNIT_KHZ;
  719. else if (std::strcmp(unitUnit, LV2_UNITS__km) == 0)
  720. rdfPort->Unit.Unit = LV2_PORT_UNIT_KM;
  721. else if (std::strcmp(unitUnit, LV2_UNITS__m) == 0)
  722. rdfPort->Unit.Unit = LV2_PORT_UNIT_M;
  723. else if (std::strcmp(unitUnit, LV2_UNITS__mhz) == 0)
  724. rdfPort->Unit.Unit = LV2_PORT_UNIT_MHZ;
  725. else if (std::strcmp(unitUnit, LV2_UNITS__midiNote) == 0)
  726. rdfPort->Unit.Unit = LV2_PORT_UNIT_MIDINOTE;
  727. else if (std::strcmp(unitUnit, LV2_UNITS__mile) == 0)
  728. rdfPort->Unit.Unit = LV2_PORT_UNIT_MILE;
  729. else if (std::strcmp(unitUnit, LV2_UNITS__min) == 0)
  730. rdfPort->Unit.Unit = LV2_PORT_UNIT_MIN;
  731. else if (std::strcmp(unitUnit, LV2_UNITS__mm) == 0)
  732. rdfPort->Unit.Unit = LV2_PORT_UNIT_MM;
  733. else if (std::strcmp(unitUnit, LV2_UNITS__ms) == 0)
  734. rdfPort->Unit.Unit = LV2_PORT_UNIT_MS;
  735. else if (std::strcmp(unitUnit, LV2_UNITS__oct) == 0)
  736. rdfPort->Unit.Unit = LV2_PORT_UNIT_OCT;
  737. else if (std::strcmp(unitUnit, LV2_UNITS__pc) == 0)
  738. rdfPort->Unit.Unit = LV2_PORT_UNIT_PC;
  739. else if (std::strcmp(unitUnit, LV2_UNITS__s) == 0)
  740. rdfPort->Unit.Unit = LV2_PORT_UNIT_S;
  741. else if (std::strcmp(unitUnit, LV2_UNITS__semitone12TET) == 0)
  742. rdfPort->Unit.Unit = LV2_PORT_UNIT_SEMITONE;
  743. else
  744. carla_stderr("lv2_rdf_new(\"%s\") - got unknown unit type '%s'", uri, unitUnit);
  745. }
  746. }
  747. Lilv::Nodes unitNameNodes(lilvPort.get_value(gLv2World.unit_name));
  748. if (unitNameNodes.size() > 0)
  749. {
  750. if (const char* const unitName = unitNameNodes.get_first().as_string())
  751. {
  752. rdfPort->Unit.Hints |= LV2_PORT_UNIT_NAME;
  753. rdfPort->Unit.Name = carla_strdup(unitName);
  754. }
  755. }
  756. Lilv::Nodes unitRenderNodes(lilvPort.get_value(gLv2World.unit_render));
  757. if (unitRenderNodes.size() > 0)
  758. {
  759. if (const char* const unitRender = unitRenderNodes.get_first().as_string())
  760. {
  761. rdfPort->Unit.Hints |= LV2_PORT_UNIT_RENDER;
  762. rdfPort->Unit.Render = carla_strdup(unitRender);
  763. }
  764. }
  765. Lilv::Nodes unitSymbolNodes(lilvPort.get_value(gLv2World.unit_symbol));
  766. if (unitSymbolNodes.size() > 0)
  767. {
  768. if (const char* const unitSymbol = unitSymbolNodes.get_first().as_string())
  769. {
  770. rdfPort->Unit.Hints |= LV2_PORT_UNIT_SYMBOL;
  771. rdfPort->Unit.Symbol = carla_strdup(unitSymbol);
  772. }
  773. }
  774. }
  775. // --------------------------------------
  776. // Set Port Scale Points
  777. Lilv::ScalePoints lilvScalePoints(lilvPort.get_scale_points());
  778. if (lilvScalePoints.size() > 0)
  779. {
  780. rdfPort->ScalePointCount = lilvScalePoints.size();
  781. rdfPort->ScalePoints = new LV2_RDF_PortScalePoint[rdfPort->ScalePointCount];
  782. uint32_t h = 0;
  783. LILV_FOREACH(scale_points, j, lilvScalePoints)
  784. {
  785. Lilv::ScalePoint lilvScalePoint(lilvScalePoints.get(j));
  786. LV2_RDF_PortScalePoint* const rdfScalePoint = &rdfPort->ScalePoints[h++];
  787. if (const char* const label = Lilv::Node(lilvScalePoint.get_label()).as_string())
  788. rdfScalePoint->Label = carla_strdup(label);
  789. rdfScalePoint->Value = Lilv::Node(lilvScalePoint.get_value()).as_float();
  790. }
  791. }
  792. }
  793. }
  794. // --------------------------------------------------
  795. // Set Plugin Presets
  796. {
  797. Lilv::Nodes presetNodes(lilvPlugin.get_related(gLv2World.preset_preset));
  798. if (presetNodes.size() > 0)
  799. {
  800. // create a list of preset URIs (for checking appliesTo, sorting and unique-ness)
  801. QStringList presetListURIs;
  802. LILV_FOREACH(nodes, j, presetNodes)
  803. {
  804. Lilv::Node presetNode(presetNodes.get(j));
  805. // FIXME - check appliesTo
  806. QString presetURI(presetNode.as_uri());
  807. if (! presetListURIs.contains(presetURI))
  808. presetListURIs.append(presetURI);
  809. }
  810. presetListURIs.sort();
  811. // create presets with unique URIs
  812. rdfDescriptor->PresetCount = static_cast<uint32_t>(presetListURIs.count());
  813. rdfDescriptor->Presets = new LV2_RDF_Preset[rdfDescriptor->PresetCount];
  814. // set preset data
  815. LILV_FOREACH(nodes, j, presetNodes)
  816. {
  817. Lilv::Node presetNode(presetNodes.get(j));
  818. if (gLv2World.load_resource(presetNode) == -1)
  819. continue;
  820. if (const char* const presetURI = presetNode.as_uri())
  821. {
  822. int32_t index = presetListURIs.indexOf(QString(presetURI));
  823. if (index < 0)
  824. continue;
  825. LV2_RDF_Preset* const rdfPreset = &rdfDescriptor->Presets[index];
  826. // --------------------------------------
  827. // Set Preset Information
  828. {
  829. rdfPreset->URI = carla_strdup(presetURI);
  830. Lilv::Nodes presetLabelNodes(gLv2World.find_nodes(presetNode, gLv2World.rdfs_label, nullptr));
  831. if (presetLabelNodes.size() > 0)
  832. {
  833. if (const char* const label = presetLabelNodes.get_first().as_string())
  834. rdfPreset->Label = carla_strdup(label);
  835. }
  836. }
  837. }
  838. }
  839. }
  840. }
  841. // --------------------------------------------------
  842. // Set Plugin Features
  843. {
  844. Lilv::Nodes lilvFeatureNodes(lilvPlugin.get_supported_features());
  845. if (lilvFeatureNodes.size() > 0)
  846. {
  847. Lilv::Nodes lilvFeatureNodesR(lilvPlugin.get_required_features());
  848. rdfDescriptor->FeatureCount = lilvFeatureNodes.size();
  849. rdfDescriptor->Features = new LV2_RDF_Feature[rdfDescriptor->FeatureCount];
  850. uint32_t h = 0;
  851. LILV_FOREACH(nodes, j, lilvFeatureNodes)
  852. {
  853. CARLA_ASSERT(h < rdfDescriptor->FeatureCount);
  854. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(j));
  855. LV2_RDF_Feature* const rdfFeature = &rdfDescriptor->Features[h++];
  856. rdfFeature->Type = lilvFeatureNodesR.contains(lilvFeatureNode) ? LV2_FEATURE_REQUIRED : LV2_FEATURE_OPTIONAL;
  857. if (const char* const featureURI = lilvFeatureNode.as_uri())
  858. rdfFeature->URI = carla_strdup(featureURI);
  859. }
  860. }
  861. }
  862. // --------------------------------------------------
  863. // Set Plugin Extensions
  864. {
  865. Lilv::Nodes lilvExtensionDataNodes(lilvPlugin.get_extension_data());
  866. if (lilvExtensionDataNodes.size() > 0)
  867. {
  868. rdfDescriptor->ExtensionCount = lilvExtensionDataNodes.size();
  869. rdfDescriptor->Extensions = new LV2_URI[rdfDescriptor->ExtensionCount];
  870. uint32_t h = 0;
  871. LILV_FOREACH(nodes, j, lilvExtensionDataNodes)
  872. {
  873. CARLA_ASSERT(h < rdfDescriptor->ExtensionCount);
  874. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(j));
  875. LV2_URI* const rdfExtension = &rdfDescriptor->Extensions[h++];
  876. if (const char* const extURI = lilvExtensionDataNode.as_uri())
  877. *rdfExtension = carla_strdup(extURI);
  878. }
  879. }
  880. }
  881. // --------------------------------------------------
  882. // Set Plugin UIs
  883. {
  884. Lilv::UIs lilvUIs(lilvPlugin.get_uis());
  885. if (lilvUIs.size() > 0)
  886. {
  887. rdfDescriptor->UICount = lilvUIs.size();
  888. rdfDescriptor->UIs = new LV2_RDF_UI[rdfDescriptor->UICount];
  889. uint32_t h = 0;
  890. LILV_FOREACH(uis, j, lilvUIs)
  891. {
  892. CARLA_ASSERT(h < rdfDescriptor->UICount);
  893. Lilv::UI lilvUI(lilvUIs.get(j));
  894. LV2_RDF_UI* const rdfUI = &rdfDescriptor->UIs[h++];
  895. // --------------------------------------
  896. // Set UI Type
  897. if (lilvUI.is_a(gLv2World.ui_gtk2))
  898. rdfUI->Type = LV2_UI_GTK2;
  899. else if (lilvUI.is_a(gLv2World.ui_gtk3))
  900. rdfUI->Type = LV2_UI_GTK3;
  901. else if (lilvUI.is_a(gLv2World.ui_qt4))
  902. rdfUI->Type = LV2_UI_QT4;
  903. else if (lilvUI.is_a(gLv2World.ui_qt5))
  904. rdfUI->Type = LV2_UI_QT5;
  905. else if (lilvUI.is_a(gLv2World.ui_cocoa))
  906. rdfUI->Type = LV2_UI_COCOA;
  907. else if (lilvUI.is_a(gLv2World.ui_windows))
  908. rdfUI->Type = LV2_UI_WINDOWS;
  909. else if (lilvUI.is_a(gLv2World.ui_x11))
  910. rdfUI->Type = LV2_UI_X11;
  911. else if (lilvUI.is_a(gLv2World.ui_external))
  912. rdfUI->Type = LV2_UI_EXTERNAL;
  913. else if (lilvUI.is_a(gLv2World.ui_externalOld))
  914. rdfUI->Type = LV2_UI_OLD_EXTERNAL;
  915. else
  916. carla_stderr("lv2_rdf_new(\"%s\") - UI '%s' is of unknown type", uri, lilvUI.get_uri().as_uri());
  917. // --------------------------------------
  918. // Set UI Information
  919. {
  920. if (const char* const uiURI = lilvUI.get_uri().as_uri())
  921. rdfUI->URI = carla_strdup(uiURI);
  922. if (const char* const uiBinary = lilvUI.get_binary_uri().as_string())
  923. rdfUI->Binary = carla_strdup(lilv_uri_to_path(uiBinary));
  924. if (const char* const uiBundle = lilvUI.get_bundle_uri().as_string())
  925. rdfUI->Bundle = carla_strdup(lilv_uri_to_path(uiBundle));
  926. }
  927. // --------------------------------------
  928. // Set UI Features
  929. {
  930. Lilv::Nodes lilvFeatureNodes(lilvUI.get_supported_features());
  931. if (lilvFeatureNodes.size() > 0)
  932. {
  933. Lilv::Nodes lilvFeatureNodesR(lilvUI.get_required_features());
  934. rdfUI->FeatureCount = lilvFeatureNodes.size();
  935. rdfUI->Features = new LV2_RDF_Feature[rdfUI->FeatureCount];
  936. uint32_t x = 0;
  937. LILV_FOREACH(nodes, k, lilvFeatureNodes)
  938. {
  939. CARLA_ASSERT(x < rdfUI->FeatureCount);
  940. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(k));
  941. LV2_RDF_Feature* const rdfFeature = &rdfUI->Features[x++];
  942. rdfFeature->Type = lilvFeatureNodesR.contains(lilvFeatureNode) ? LV2_FEATURE_REQUIRED : LV2_FEATURE_OPTIONAL;
  943. if (const char* const featureURI = lilvFeatureNode.as_uri())
  944. rdfFeature->URI = carla_strdup(featureURI);
  945. }
  946. }
  947. }
  948. // --------------------------------------
  949. // Set UI Extensions
  950. {
  951. Lilv::Nodes lilvExtensionDataNodes(lilvUI.get_extension_data());
  952. if (lilvExtensionDataNodes.size() > 0)
  953. {
  954. rdfUI->ExtensionCount = lilvExtensionDataNodes.size();
  955. rdfUI->Extensions = new LV2_URI[rdfUI->ExtensionCount];
  956. uint32_t x = 0;
  957. LILV_FOREACH(nodes, k, lilvExtensionDataNodes)
  958. {
  959. CARLA_ASSERT(x < rdfUI->ExtensionCount);
  960. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(k));
  961. LV2_URI* const rdfExtension = &rdfUI->Extensions[x++];
  962. if (const char* const extURI = lilvExtensionDataNode.as_uri())
  963. *rdfExtension = carla_strdup(extURI);
  964. }
  965. }
  966. }
  967. }
  968. }
  969. }
  970. return rdfDescriptor;
  971. }
  972. // -------------------------------------------------
  973. // Check if we support a plugin port
  974. static inline
  975. bool is_lv2_port_supported(const LV2_Property types)
  976. {
  977. if (LV2_IS_PORT_CONTROL(types))
  978. return true;
  979. if (LV2_IS_PORT_AUDIO(types))
  980. return true;
  981. if (LV2_IS_PORT_ATOM_SEQUENCE(types))
  982. return true;
  983. if (LV2_IS_PORT_CV(types))
  984. return false; // TODO
  985. if (LV2_IS_PORT_EVENT(types))
  986. return true;
  987. if (LV2_IS_PORT_MIDI_LL(types))
  988. return true;
  989. return false;
  990. }
  991. // -------------------------------------------------
  992. // Check if we support a plugin feature
  993. static inline
  994. bool is_lv2_feature_supported(const LV2_URI uri)
  995. {
  996. CARLA_ASSERT(uri != nullptr);
  997. if (uri == nullptr)
  998. return false;
  999. if (std::strcmp(uri, LV2_CORE__hardRTCapable) == 0)
  1000. return true;
  1001. if (std::strcmp(uri, LV2_CORE__inPlaceBroken) == 0)
  1002. return true;
  1003. if (std::strcmp(uri, LV2_CORE__isLive) == 0)
  1004. return true;
  1005. if (std::strcmp(uri, LV2_BUF_SIZE__boundedBlockLength) == 0)
  1006. return true;
  1007. if (std::strcmp(uri, LV2_BUF_SIZE__fixedBlockLength) == 0)
  1008. return true;
  1009. if (std::strcmp(uri, LV2_BUF_SIZE__powerOf2BlockLength) == 0)
  1010. return true;
  1011. if (std::strcmp(uri, LV2_EVENT_URI) == 0)
  1012. return true;
  1013. if (std::strcmp(uri, LV2_LOG__log) == 0)
  1014. return true;
  1015. if (std::strcmp(uri, LV2_OPTIONS__options) == 0)
  1016. return true;
  1017. if (std::strcmp(uri, LV2_PROGRAMS__Host) == 0)
  1018. return true;
  1019. if (std::strcmp(uri, LV2_RTSAFE_MEMORY_POOL__Pool) == 0)
  1020. return true;
  1021. if (std::strcmp(uri, LV2_STATE__makePath) == 0)
  1022. return true;
  1023. if (std::strcmp(uri, LV2_STATE__mapPath) == 0)
  1024. return true;
  1025. if (std::strcmp(uri, LV2_PORT_PROPS__supportsStrictBounds) == 0)
  1026. return true;
  1027. if (std::strcmp(uri, LV2_URI_MAP_URI) == 0)
  1028. return true;
  1029. if (std::strcmp(uri, LV2_URID__map) == 0)
  1030. return true;
  1031. if (std::strcmp(uri, LV2_URID__unmap) == 0)
  1032. return true;
  1033. if (std::strcmp(uri, LV2_WORKER__schedule) == 0)
  1034. return false; // TODO
  1035. return false;
  1036. }
  1037. // -------------------------------------------------
  1038. // Check if we support a plugin or UI feature
  1039. static inline
  1040. bool is_lv2_ui_feature_supported(const LV2_URI uri)
  1041. {
  1042. CARLA_ASSERT(uri != nullptr);
  1043. if (uri == nullptr)
  1044. return false;
  1045. if (is_lv2_feature_supported(uri))
  1046. return true;
  1047. if (std::strcmp(uri, LV2_DATA_ACCESS_URI) == 0)
  1048. return true;
  1049. if (std::strcmp(uri, LV2_INSTANCE_ACCESS_URI) == 0)
  1050. return true;
  1051. if (std::strcmp(uri, LV2_UI__idle) == 0)
  1052. return true;
  1053. if (std::strcmp(uri, LV2_UI__fixedSize) == 0)
  1054. return true;
  1055. if (std::strcmp(uri, LV2_UI__makeResident) == 0)
  1056. return true;
  1057. if (std::strcmp(uri, LV2_UI__noUserResize) == 0)
  1058. return true;
  1059. if (std::strcmp(uri, LV2_UI__parent) == 0)
  1060. return true;
  1061. if (std::strcmp(uri, LV2_UI__portMap) == 0)
  1062. return true;
  1063. if (std::strcmp(uri, LV2_UI__portSubscribe) == 0)
  1064. return false; // TODO
  1065. if (std::strcmp(uri, LV2_UI__resize) == 0)
  1066. return true;
  1067. if (std::strcmp(uri, LV2_UI__touch) == 0)
  1068. return false; // TODO
  1069. if (std::strcmp(uri, LV2_EXTERNAL_UI__Widget) == 0)
  1070. return true;
  1071. if (std::strcmp(uri, LV2_EXTERNAL_UI_DEPRECATED_URI) == 0)
  1072. return true;
  1073. return false;
  1074. }
  1075. // -------------------------------------------------
  1076. #endif // __CARLA_LV2_UTILS_HPP__