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.

1233 lines
49KB

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