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.

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