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.

1231 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 modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * 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 COPYING file
  16. */
  17. #ifndef __CARLA_LV2_UTILS_HPP__
  18. #define __CARLA_LV2_UTILS_HPP__
  19. #include "carla_utils.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. };
  327. // -----------------------------------------------------
  328. // Our LV2 World class object
  329. extern Lv2WorldClass lv2World;
  330. // -----------------------------------------------------
  331. // Create new RDF object (using lilv)
  332. static inline
  333. const LV2_RDF_Descriptor* lv2_rdf_new(const LV2_URI uri)
  334. {
  335. CARLA_ASSERT(uri);
  336. if (! uri)
  337. {
  338. qWarning("lv2_rdf_new() - Invalid uri");
  339. return nullptr;
  340. }
  341. const LilvPlugin* const cPlugin(lv2World.getPlugin(uri));
  342. if (! cPlugin)
  343. {
  344. // Error already set in getPlugin()
  345. return nullptr;
  346. }
  347. LV2_RDF_Descriptor* const rdfDescriptor = new LV2_RDF_Descriptor;
  348. Lilv::Plugin lilvPlugin(lv2World.getPlugin(uri));
  349. // --------------------------------------------------
  350. // Set Plugin Type
  351. {
  352. Lilv::Nodes typeNodes(lilvPlugin.get_value(lv2World.rdf_type));
  353. if (typeNodes.size() > 0)
  354. {
  355. if (typeNodes.contains(lv2World.class_allpass))
  356. rdfDescriptor->Type[0] |= LV2_PLUGIN_ALLPASS;
  357. if (typeNodes.contains(lv2World.class_amplifier))
  358. rdfDescriptor->Type[0] |= LV2_PLUGIN_AMPLIFIER;
  359. if (typeNodes.contains(lv2World.class_analyzer))
  360. rdfDescriptor->Type[1] |= LV2_PLUGIN_ANALYSER;
  361. if (typeNodes.contains(lv2World.class_bandpass))
  362. rdfDescriptor->Type[0] |= LV2_PLUGIN_BANDPASS;
  363. if (typeNodes.contains(lv2World.class_chorus))
  364. rdfDescriptor->Type[1] |= LV2_PLUGIN_CHORUS;
  365. if (typeNodes.contains(lv2World.class_comb))
  366. rdfDescriptor->Type[1] |= LV2_PLUGIN_COMB;
  367. if (typeNodes.contains(lv2World.class_compressor))
  368. rdfDescriptor->Type[0] |= LV2_PLUGIN_COMPRESSOR;
  369. if (typeNodes.contains(lv2World.class_constant))
  370. rdfDescriptor->Type[1] |= LV2_PLUGIN_CONSTANT;
  371. if (typeNodes.contains(lv2World.class_converter))
  372. rdfDescriptor->Type[1] |= LV2_PLUGIN_CONVERTER;
  373. if (typeNodes.contains(lv2World.class_delay))
  374. rdfDescriptor->Type[0] |= LV2_PLUGIN_DELAY;
  375. if (typeNodes.contains(lv2World.class_distortion))
  376. rdfDescriptor->Type[0] |= LV2_PLUGIN_DISTORTION;
  377. if (typeNodes.contains(lv2World.class_dynamics))
  378. rdfDescriptor->Type[0] |= LV2_PLUGIN_DYNAMICS;
  379. if (typeNodes.contains(lv2World.class_eq))
  380. rdfDescriptor->Type[0] |= LV2_PLUGIN_EQ;
  381. if (typeNodes.contains(lv2World.class_envelope))
  382. rdfDescriptor->Type[0] |= LV2_PLUGIN_ENVELOPE;
  383. if (typeNodes.contains(lv2World.class_expander))
  384. rdfDescriptor->Type[0] |= LV2_PLUGIN_EXPANDER;
  385. if (typeNodes.contains(lv2World.class_filter))
  386. rdfDescriptor->Type[0] |= LV2_PLUGIN_FILTER;
  387. if (typeNodes.contains(lv2World.class_flanger))
  388. rdfDescriptor->Type[1] |= LV2_PLUGIN_FLANGER;
  389. if (typeNodes.contains(lv2World.class_function))
  390. rdfDescriptor->Type[1] |= LV2_PLUGIN_FUNCTION;
  391. if (typeNodes.contains(lv2World.class_gate))
  392. rdfDescriptor->Type[0] |= LV2_PLUGIN_GATE;
  393. if (typeNodes.contains(lv2World.class_generator))
  394. rdfDescriptor->Type[1] |= LV2_PLUGIN_GENERATOR;
  395. if (typeNodes.contains(lv2World.class_highpass))
  396. rdfDescriptor->Type[0] |= LV2_PLUGIN_HIGHPASS;
  397. if (typeNodes.contains(lv2World.class_instrument))
  398. rdfDescriptor->Type[1] |= LV2_PLUGIN_INSTRUMENT;
  399. if (typeNodes.contains(lv2World.class_limiter))
  400. rdfDescriptor->Type[0] |= LV2_PLUGIN_LIMITER;
  401. if (typeNodes.contains(lv2World.class_lowpass))
  402. rdfDescriptor->Type[0] |= LV2_PLUGIN_LOWPASS;
  403. if (typeNodes.contains(lv2World.class_mixer))
  404. rdfDescriptor->Type[1] |= LV2_PLUGIN_MIXER;
  405. if (typeNodes.contains(lv2World.class_modulator))
  406. rdfDescriptor->Type[1] |= LV2_PLUGIN_MODULATOR;
  407. if (typeNodes.contains(lv2World.class_multiEQ))
  408. rdfDescriptor->Type[0] |= LV2_PLUGIN_MULTI_EQ;
  409. if (typeNodes.contains(lv2World.class_oscillator))
  410. rdfDescriptor->Type[1] |= LV2_PLUGIN_OSCILLATOR;
  411. if (typeNodes.contains(lv2World.class_paraEQ))
  412. rdfDescriptor->Type[0] |= LV2_PLUGIN_PARA_EQ;
  413. if (typeNodes.contains(lv2World.class_phaser))
  414. rdfDescriptor->Type[1] |= LV2_PLUGIN_PHASER;
  415. if (typeNodes.contains(lv2World.class_pitch))
  416. rdfDescriptor->Type[1] |= LV2_PLUGIN_PITCH;
  417. if (typeNodes.contains(lv2World.class_reverb))
  418. rdfDescriptor->Type[0] |= LV2_PLUGIN_REVERB;
  419. if (typeNodes.contains(lv2World.class_simulator))
  420. rdfDescriptor->Type[0] |= LV2_PLUGIN_SIMULATOR;
  421. if (typeNodes.contains(lv2World.class_spatial))
  422. rdfDescriptor->Type[1] |= LV2_PLUGIN_SPATIAL;
  423. if (typeNodes.contains(lv2World.class_spectral))
  424. rdfDescriptor->Type[1] |= LV2_PLUGIN_SPECTRAL;
  425. if (typeNodes.contains(lv2World.class_utility))
  426. rdfDescriptor->Type[1] |= LV2_PLUGIN_UTILITY;
  427. if (typeNodes.contains(lv2World.class_waveshaper))
  428. rdfDescriptor->Type[0] |= LV2_PLUGIN_WAVESHAPER;
  429. }
  430. }
  431. // --------------------------------------------------
  432. // Set Plugin Information
  433. {
  434. rdfDescriptor->URI = strdup(uri);
  435. if (const char* const name = lilvPlugin.get_name().as_string())
  436. rdfDescriptor->Name = strdup(name);
  437. if (const char* const author = lilvPlugin.get_author_name().as_string())
  438. rdfDescriptor->Author = strdup(author);
  439. if (const char* const binary = lilvPlugin.get_library_uri().as_string())
  440. rdfDescriptor->Binary = strdup(lilv_uri_to_path(binary));
  441. if (const char* const bundle = lilvPlugin.get_bundle_uri().as_string())
  442. rdfDescriptor->Bundle = strdup(lilv_uri_to_path(bundle));
  443. Lilv::Nodes licenseNodes(lilvPlugin.get_value(lv2World.doap_license));
  444. if (licenseNodes.size() > 0)
  445. {
  446. if (const char* const license = licenseNodes.get_first().as_string())
  447. rdfDescriptor->License = strdup(license);
  448. }
  449. }
  450. // --------------------------------------------------
  451. // Set Plugin UniqueID
  452. {
  453. Lilv::Nodes replaceNodes(lilvPlugin.get_value(lv2World.dct_replaces));
  454. if (replaceNodes.size() > 0)
  455. {
  456. Lilv::Node replaceNode(replaceNodes.get_first());
  457. if (replaceNode.is_uri())
  458. {
  459. const QString replaceURI(replaceNode.as_uri());
  460. if (replaceURI.startsWith("urn:"))
  461. {
  462. const QString replaceId(replaceURI.split(":").last());
  463. bool ok;
  464. ulong uniqueId = replaceId.toULong(&ok);
  465. if (ok && uniqueId != 0)
  466. rdfDescriptor->UniqueID = uniqueId;
  467. }
  468. }
  469. }
  470. }
  471. // --------------------------------------------------
  472. // Set Plugin Ports
  473. if (lilvPlugin.get_num_ports() > 0)
  474. {
  475. rdfDescriptor->PortCount = lilvPlugin.get_num_ports();
  476. rdfDescriptor->Ports = new LV2_RDF_Port[rdfDescriptor->PortCount];
  477. for (uint32_t j = 0; j < rdfDescriptor->PortCount; j++)
  478. {
  479. Lilv::Port lilvPort(lilvPlugin.get_port_by_index(j));
  480. LV2_RDF_Port* const rdfPort = &rdfDescriptor->Ports[j];
  481. // --------------------------------------
  482. // Set Port Information
  483. {
  484. if (const char* const name = Lilv::Node(lilvPort.get_name()).as_string())
  485. rdfPort->Name = strdup(name);
  486. if (const char* const symbol = Lilv::Node(lilvPort.get_symbol()).as_string())
  487. rdfPort->Symbol = strdup(symbol);
  488. }
  489. // --------------------------------------
  490. // Set Port Mode and Type
  491. {
  492. // Input or Output
  493. if (lilvPort.is_a(lv2World.port_input))
  494. rdfPort->Types |= LV2_PORT_INPUT;
  495. else if (lilvPort.is_a(lv2World.port_output))
  496. rdfPort->Types |= LV2_PORT_OUTPUT;
  497. else
  498. qWarning("lv2_rdf_new(\"%s\") - port '%s' is not input or output", uri, rdfPort->Name);
  499. // Data Type
  500. if (lilvPort.is_a(lv2World.port_control))
  501. rdfPort->Types |= LV2_PORT_CONTROL;
  502. else if (lilvPort.is_a(lv2World.port_audio))
  503. rdfPort->Types |= LV2_PORT_AUDIO;
  504. else if (lilvPort.is_a(lv2World.port_cv))
  505. rdfPort->Types |= LV2_PORT_CV;
  506. else if (lilvPort.is_a(lv2World.port_atom))
  507. {
  508. rdfPort->Types |= LV2_PORT_ATOM;
  509. Lilv::Nodes bufferTypeNodes(lilvPort.get_value(lv2World.atom_bufferType));
  510. if (bufferTypeNodes.contains(lv2World.atom_sequence))
  511. rdfPort->Types |= LV2_PORT_ATOM_SEQUENCE;
  512. else
  513. qWarning("lv2_rdf_new(\"%s\") - port '%s' uses an unknown atom buffer type", uri, rdfPort->Name);
  514. Lilv::Nodes supportNodes(lilvPort.get_value(lv2World.atom_supports));
  515. if (supportNodes.contains(lv2World.midi_event))
  516. rdfPort->Types |= LV2_PORT_DATA_MIDI_EVENT;
  517. if (supportNodes.contains(lv2World.patch_message))
  518. rdfPort->Types |= LV2_PORT_DATA_PATCH_MESSAGE;
  519. if (! (supportNodes.contains(lv2World.midi_event) || supportNodes.contains(lv2World.patch_message)))
  520. qWarning("lv2_rdf_new(\"%s\") - port '%s' is of atom type but doesn't support MIDI or messages", uri, rdfPort->Name);
  521. }
  522. else if (lilvPort.is_a(lv2World.port_event))
  523. {
  524. rdfPort->Types |= LV2_PORT_EVENT;
  525. if (lilvPort.supports_event(lv2World.midi_event))
  526. rdfPort->Types |= LV2_PORT_DATA_MIDI_EVENT;
  527. else
  528. qWarning("lv2_rdf_new(\"%s\") - port '%s' is of event type but doesn't support MIDI", uri, rdfPort->Name);
  529. }
  530. else if (lilvPort.is_a(lv2World.port_midi))
  531. {
  532. rdfPort->Types |= LV2_PORT_MIDI_LL;
  533. rdfPort->Types |= LV2_PORT_DATA_MIDI_EVENT;
  534. }
  535. else
  536. qWarning("lv2_rdf_new(\"%s\") - port '%s' is of unkown data type", uri, rdfPort->Name);
  537. }
  538. // --------------------------------------
  539. // Set Port Properties
  540. {
  541. if (lilvPort.has_property(lv2World.pprop_optional))
  542. rdfPort->Properties |= LV2_PORT_OPTIONAL;
  543. if (lilvPort.has_property(lv2World.pprop_enumeration))
  544. rdfPort->Properties |= LV2_PORT_ENUMERATION;
  545. if (lilvPort.has_property(lv2World.pprop_integer))
  546. rdfPort->Properties |= LV2_PORT_INTEGER;
  547. if (lilvPort.has_property(lv2World.pprop_sampleRate))
  548. rdfPort->Properties |= LV2_PORT_SAMPLE_RATE;
  549. if (lilvPort.has_property(lv2World.pprop_toggled))
  550. rdfPort->Properties |= LV2_PORT_TOGGLED;
  551. if (lilvPort.has_property(lv2World.pprop_artifacts))
  552. rdfPort->Properties |= LV2_PORT_CAUSES_ARTIFACTS;
  553. if (lilvPort.has_property(lv2World.pprop_continuousCV))
  554. rdfPort->Properties |= LV2_PORT_CONTINUOUS_CV;
  555. if (lilvPort.has_property(lv2World.pprop_discreteCV))
  556. rdfPort->Properties |= LV2_PORT_DISCRETE_CV;
  557. if (lilvPort.has_property(lv2World.pprop_expensive))
  558. rdfPort->Properties |= LV2_PORT_EXPENSIVE;
  559. if (lilvPort.has_property(lv2World.pprop_strictBounds))
  560. rdfPort->Properties |= LV2_PORT_STRICT_BOUNDS;
  561. if (lilvPort.has_property(lv2World.pprop_logarithmic))
  562. rdfPort->Properties |= LV2_PORT_LOGARITHMIC;
  563. if (lilvPort.has_property(lv2World.pprop_notAutomatic))
  564. rdfPort->Properties |= LV2_PORT_NOT_AUTOMATIC;
  565. if (lilvPort.has_property(lv2World.pprop_notOnGUI))
  566. rdfPort->Properties |= LV2_PORT_NOT_ON_GUI;
  567. if (lilvPort.has_property(lv2World.pprop_trigger))
  568. rdfPort->Properties |= LV2_PORT_TRIGGER;
  569. if (lilvPort.has_property(lv2World.reportsLatency))
  570. rdfPort->Designation = LV2_PORT_DESIGNATION_LATENCY;
  571. }
  572. // --------------------------------------
  573. // Set Port Designation
  574. {
  575. Lilv::Nodes designationNodes(lilvPort.get_value(lv2World.designation));
  576. if (designationNodes.size() > 0)
  577. {
  578. if (const char* const designation = designationNodes.get_first().as_string())
  579. {
  580. if (strcmp(designation, LV2_CORE__freeWheeling) == 0)
  581. rdfPort->Designation = LV2_PORT_DESIGNATION_FREEWHEELING;
  582. else if (strcmp(designation, LV2_CORE__latency) == 0)
  583. rdfPort->Designation = LV2_PORT_DESIGNATION_LATENCY;
  584. else if (strcmp(designation, LV2_PARAMETERS__sampleRate) == 0)
  585. rdfPort->Designation = LV2_PORT_DESIGNATION_SAMPLE_RATE;
  586. else if (strcmp(designation, LV2_TIME__bar) == 0)
  587. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BAR;
  588. else if (strcmp(designation, LV2_TIME__barBeat) == 0)
  589. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BAR_BEAT;
  590. else if (strcmp(designation, LV2_TIME__beat) == 0)
  591. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEAT;
  592. else if (strcmp(designation, LV2_TIME__beatUnit) == 0)
  593. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEAT_UNIT;
  594. else if (strcmp(designation, LV2_TIME__beatsPerBar) == 0)
  595. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEATS_PER_BAR;
  596. else if (strcmp(designation, LV2_TIME__beatsPerMinute) == 0)
  597. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEATS_PER_MINUTE;
  598. else if (strcmp(designation, LV2_TIME__frame) == 0)
  599. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_FRAME;
  600. else if (strcmp(designation, LV2_TIME__framesPerSecond) == 0)
  601. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_FRAMES_PER_SECOND;
  602. else if (strcmp(designation, LV2_TIME__position) == 0)
  603. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_POSITION;
  604. else if (strcmp(designation, LV2_TIME__speed) == 0)
  605. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_SPEED;
  606. else if (strncmp(designation, LV2_PARAMETERS_PREFIX, strlen(LV2_PARAMETERS_PREFIX)) == 0)
  607. pass();
  608. else if (strncmp(designation, LV2_PORT_GROUPS_PREFIX, strlen(LV2_PORT_GROUPS_PREFIX)) == 0)
  609. pass();
  610. else
  611. qWarning("lv2_rdf_new(\"%s\") - got unknown port designation '%s'", uri, designation);
  612. }
  613. }
  614. }
  615. // --------------------------------------
  616. // Set Port MIDI Map
  617. {
  618. Lilv::Nodes midiMapNodes(lilvPort.get_value(lv2World.mm_defaultControl));
  619. if (midiMapNodes.size() > 0)
  620. {
  621. Lilv::Node midiMapNode(midiMapNodes.get_first());
  622. if (midiMapNode.is_blank())
  623. {
  624. Lilv::Nodes midiMapTypeNodes(lv2World.find_nodes(midiMapNode, lv2World.mm_controlType, nullptr));
  625. Lilv::Nodes midiMapNumberNodes(lv2World.find_nodes(midiMapNode, lv2World.mm_controlNumber, nullptr));
  626. if (midiMapTypeNodes.size() == 1 && midiMapNumberNodes.size() == 1)
  627. {
  628. if (const char* const midiMapType = midiMapTypeNodes.get_first().as_string())
  629. {
  630. if (strcmp(midiMapType, LV2_MIDI_Map__CC) == 0)
  631. rdfPort->MidiMap.Type = LV2_PORT_MIDI_MAP_CC;
  632. else if (strcmp(midiMapType, LV2_MIDI_Map__NRPN) == 0)
  633. rdfPort->MidiMap.Type = LV2_PORT_MIDI_MAP_NRPN;
  634. else
  635. qWarning("lv2_rdf_new(\"%s\") - got unknown port Midi-Map type '%s'", uri, midiMapType);
  636. rdfPort->MidiMap.Number = midiMapNumberNodes.get_first().as_int();
  637. }
  638. }
  639. }
  640. }
  641. // TODO - check using new official MIDI API too
  642. }
  643. // --------------------------------------
  644. // Set Port Points
  645. {
  646. Lilv::Nodes valueNodes(lilvPort.get_value(lv2World.value_default));
  647. if (valueNodes.size() > 0)
  648. {
  649. rdfPort->Points.Hints |= LV2_PORT_POINT_DEFAULT;
  650. rdfPort->Points.Default = valueNodes.get_first().as_float();
  651. }
  652. valueNodes = lilvPort.get_value(lv2World.value_minimum);
  653. if (valueNodes.size() > 0)
  654. {
  655. rdfPort->Points.Hints |= LV2_PORT_POINT_MINIMUM;
  656. rdfPort->Points.Minimum = valueNodes.get_first().as_float();
  657. }
  658. valueNodes = lilvPort.get_value(lv2World.value_maximum);
  659. if (valueNodes.size() > 0)
  660. {
  661. rdfPort->Points.Hints |= LV2_PORT_POINT_MAXIMUM;
  662. rdfPort->Points.Maximum = valueNodes.get_first().as_float();
  663. }
  664. }
  665. // --------------------------------------
  666. // Set Port Unit
  667. {
  668. Lilv::Nodes unitUnitNodes(lilvPort.get_value(lv2World.unit_unit));
  669. if (unitUnitNodes.size() > 0)
  670. {
  671. if (const char* const unitUnit = unitUnitNodes.get_first().as_uri())
  672. {
  673. rdfPort->Unit.Hints |= LV2_PORT_UNIT_UNIT;
  674. if (strcmp(unitUnit, LV2_UNITS__bar) == 0)
  675. rdfPort->Unit.Unit = LV2_PORT_UNIT_BAR;
  676. else if (strcmp(unitUnit, LV2_UNITS__beat) == 0)
  677. rdfPort->Unit.Unit = LV2_PORT_UNIT_BEAT;
  678. else if (strcmp(unitUnit, LV2_UNITS__bpm) == 0)
  679. rdfPort->Unit.Unit = LV2_PORT_UNIT_BPM;
  680. else if (strcmp(unitUnit, LV2_UNITS__cent) == 0)
  681. rdfPort->Unit.Unit = LV2_PORT_UNIT_CENT;
  682. else if (strcmp(unitUnit, LV2_UNITS__cm) == 0)
  683. rdfPort->Unit.Unit = LV2_PORT_UNIT_CM;
  684. else if (strcmp(unitUnit, LV2_UNITS__coef) == 0)
  685. rdfPort->Unit.Unit = LV2_PORT_UNIT_COEF;
  686. else if (strcmp(unitUnit, LV2_UNITS__db) == 0)
  687. rdfPort->Unit.Unit = LV2_PORT_UNIT_DB;
  688. else if (strcmp(unitUnit, LV2_UNITS__degree) == 0)
  689. rdfPort->Unit.Unit = LV2_PORT_UNIT_DEGREE;
  690. else if (strcmp(unitUnit, LV2_UNITS__frame) == 0)
  691. rdfPort->Unit.Unit = LV2_PORT_UNIT_FRAME;
  692. else if (strcmp(unitUnit, LV2_UNITS__hz) == 0)
  693. rdfPort->Unit.Unit = LV2_PORT_UNIT_HZ;
  694. else if (strcmp(unitUnit, LV2_UNITS__inch) == 0)
  695. rdfPort->Unit.Unit = LV2_PORT_UNIT_INCH;
  696. else if (strcmp(unitUnit, LV2_UNITS__khz) == 0)
  697. rdfPort->Unit.Unit = LV2_PORT_UNIT_KHZ;
  698. else if (strcmp(unitUnit, LV2_UNITS__km) == 0)
  699. rdfPort->Unit.Unit = LV2_PORT_UNIT_KM;
  700. else if (strcmp(unitUnit, LV2_UNITS__m) == 0)
  701. rdfPort->Unit.Unit = LV2_PORT_UNIT_M;
  702. else if (strcmp(unitUnit, LV2_UNITS__mhz) == 0)
  703. rdfPort->Unit.Unit = LV2_PORT_UNIT_MHZ;
  704. else if (strcmp(unitUnit, LV2_UNITS__midiNote) == 0)
  705. rdfPort->Unit.Unit = LV2_PORT_UNIT_MIDINOTE;
  706. else if (strcmp(unitUnit, LV2_UNITS__mile) == 0)
  707. rdfPort->Unit.Unit = LV2_PORT_UNIT_MILE;
  708. else if (strcmp(unitUnit, LV2_UNITS__min) == 0)
  709. rdfPort->Unit.Unit = LV2_PORT_UNIT_MIN;
  710. else if (strcmp(unitUnit, LV2_UNITS__mm) == 0)
  711. rdfPort->Unit.Unit = LV2_PORT_UNIT_MM;
  712. else if (strcmp(unitUnit, LV2_UNITS__ms) == 0)
  713. rdfPort->Unit.Unit = LV2_PORT_UNIT_MS;
  714. else if (strcmp(unitUnit, LV2_UNITS__oct) == 0)
  715. rdfPort->Unit.Unit = LV2_PORT_UNIT_OCT;
  716. else if (strcmp(unitUnit, LV2_UNITS__pc) == 0)
  717. rdfPort->Unit.Unit = LV2_PORT_UNIT_PC;
  718. else if (strcmp(unitUnit, LV2_UNITS__s) == 0)
  719. rdfPort->Unit.Unit = LV2_PORT_UNIT_S;
  720. else if (strcmp(unitUnit, LV2_UNITS__semitone12TET) == 0)
  721. rdfPort->Unit.Unit = LV2_PORT_UNIT_SEMITONE;
  722. else
  723. qWarning("lv2_rdf_new(\"%s\") - got unknown unit type '%s'", uri, unitUnit);
  724. }
  725. }
  726. Lilv::Nodes unitNameNodes(lilvPort.get_value(lv2World.unit_name));
  727. if (unitNameNodes.size() > 0)
  728. {
  729. if (const char* const unitName = unitNameNodes.get_first().as_string())
  730. {
  731. rdfPort->Unit.Hints |= LV2_PORT_UNIT_NAME;
  732. rdfPort->Unit.Name = strdup(unitName);
  733. }
  734. }
  735. Lilv::Nodes unitRenderNodes(lilvPort.get_value(lv2World.unit_render));
  736. if (unitRenderNodes.size() > 0)
  737. {
  738. if (const char* const unitRender = unitRenderNodes.get_first().as_string())
  739. {
  740. rdfPort->Unit.Hints |= LV2_PORT_UNIT_RENDER;
  741. rdfPort->Unit.Render = strdup(unitRender);
  742. }
  743. }
  744. Lilv::Nodes unitSymbolNodes(lilvPort.get_value(lv2World.unit_symbol));
  745. if (unitSymbolNodes.size() > 0)
  746. {
  747. if (const char* const unitSymbol = unitSymbolNodes.get_first().as_string())
  748. {
  749. rdfPort->Unit.Hints |= LV2_PORT_UNIT_SYMBOL;
  750. rdfPort->Unit.Symbol = strdup(unitSymbol);
  751. }
  752. }
  753. }
  754. // --------------------------------------
  755. // Set Port Scale Points
  756. Lilv::ScalePoints lilvScalePoints(lilvPort.get_scale_points());
  757. if (lilvScalePoints.size() > 0)
  758. {
  759. rdfPort->ScalePointCount = lilvScalePoints.size();
  760. rdfPort->ScalePoints = new LV2_RDF_PortScalePoint[rdfPort->ScalePointCount];
  761. uint32_t h = 0;
  762. LILV_FOREACH(scale_points, j, lilvScalePoints)
  763. {
  764. Lilv::ScalePoint lilvScalePoint(lilvScalePoints.get(j));
  765. LV2_RDF_PortScalePoint* const rdfScalePoint = &rdfPort->ScalePoints[h++];
  766. if (const char* const label = Lilv::Node(lilvScalePoint.get_label()).as_string())
  767. rdfScalePoint->Label = strdup(label);
  768. rdfScalePoint->Value = Lilv::Node(lilvScalePoint.get_value()).as_float();
  769. }
  770. }
  771. }
  772. }
  773. // --------------------------------------------------
  774. // Set Plugin Presets
  775. {
  776. Lilv::Nodes presetNodes(lilvPlugin.get_related(lv2World.preset_preset));
  777. if (presetNodes.size() > 0)
  778. {
  779. // create a list of preset URIs (for checking appliesTo, sorting and unique-ness)
  780. QStringList presetListURIs;
  781. LILV_FOREACH(nodes, j, presetNodes)
  782. {
  783. Lilv::Node presetNode(presetNodes.get(j));
  784. // FIXME - check appliesTo
  785. QString presetURI(presetNode.as_uri());
  786. if (! presetListURIs.contains(presetURI))
  787. presetListURIs.append(presetURI);
  788. }
  789. presetListURIs.sort();
  790. // create presets with unique URIs
  791. rdfDescriptor->PresetCount = presetListURIs.count();
  792. rdfDescriptor->Presets = new LV2_RDF_Preset[rdfDescriptor->PresetCount];
  793. // set preset data
  794. LILV_FOREACH(nodes, j, presetNodes)
  795. {
  796. Lilv::Node presetNode(presetNodes.get(j));
  797. if (lv2World.load_resource(presetNode) == -1)
  798. continue;
  799. if (const char* const presetURI = presetNode.as_uri())
  800. {
  801. int32_t index = presetListURIs.indexOf(QString(presetURI));
  802. if (index < 0)
  803. continue;
  804. LV2_RDF_Preset* const rdfPreset = &rdfDescriptor->Presets[index];
  805. // --------------------------------------
  806. // Set Preset Information
  807. {
  808. rdfPreset->URI = strdup(presetURI);
  809. Lilv::Nodes presetLabelNodes(lv2World.find_nodes(presetNode, lv2World.rdfs_label, nullptr));
  810. if (presetLabelNodes.size() > 0)
  811. {
  812. if (const char* const label = presetLabelNodes.get_first().as_string())
  813. rdfPreset->Label = strdup(label);
  814. }
  815. }
  816. }
  817. }
  818. }
  819. }
  820. // --------------------------------------------------
  821. // Set Plugin Features
  822. {
  823. Lilv::Nodes lilvFeatureNodes(lilvPlugin.get_supported_features());
  824. if (lilvFeatureNodes.size() > 0)
  825. {
  826. Lilv::Nodes lilvFeatureNodesR(lilvPlugin.get_required_features());
  827. rdfDescriptor->FeatureCount = lilvFeatureNodes.size();
  828. rdfDescriptor->Features = new LV2_RDF_Feature[rdfDescriptor->FeatureCount];
  829. uint32_t h = 0;
  830. LILV_FOREACH(nodes, j, lilvFeatureNodes)
  831. {
  832. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(j));
  833. LV2_RDF_Feature* const rdfFeature = &rdfDescriptor->Features[h++];
  834. rdfFeature->Type = lilvFeatureNodesR.contains(lilvFeatureNode) ? LV2_FEATURE_REQUIRED : LV2_FEATURE_OPTIONAL;
  835. if (const char* const featureURI = lilvFeatureNode.as_uri())
  836. rdfFeature->URI = strdup(featureURI);
  837. }
  838. }
  839. }
  840. // --------------------------------------------------
  841. // Set Plugin Extensions
  842. {
  843. Lilv::Nodes lilvExtensionDataNodes(lilvPlugin.get_extension_data());
  844. if (lilvExtensionDataNodes.size() > 0)
  845. {
  846. rdfDescriptor->ExtensionCount = lilvExtensionDataNodes.size();
  847. rdfDescriptor->Extensions = new LV2_URI[rdfDescriptor->ExtensionCount];
  848. uint32_t h = 0;
  849. LILV_FOREACH(nodes, j, lilvExtensionDataNodes)
  850. {
  851. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(j));
  852. LV2_URI* const rdfExtension = &rdfDescriptor->Extensions[h++];
  853. if (const char* const extURI = lilvExtensionDataNode.as_uri())
  854. *rdfExtension = strdup(extURI);
  855. }
  856. }
  857. }
  858. // --------------------------------------------------
  859. // Set Plugin UIs
  860. {
  861. Lilv::UIs lilvUIs(lilvPlugin.get_uis());
  862. if (lilvUIs.size() > 0)
  863. {
  864. rdfDescriptor->UICount = lilvUIs.size();
  865. rdfDescriptor->UIs = new LV2_RDF_UI[rdfDescriptor->UICount];
  866. uint32_t h = 0;
  867. LILV_FOREACH(uis, j, lilvUIs)
  868. {
  869. Lilv::UI lilvUI(lilvUIs.get(j));
  870. LV2_RDF_UI* const rdfUI = &rdfDescriptor->UIs[h++];
  871. // --------------------------------------
  872. // Set UI Type
  873. if (const char* const uiType = lilvUI.get_uri().as_uri())
  874. {
  875. // FIXME - uiType is probably wrong
  876. rdfUI->Type.URI = strdup(uiType);
  877. if (lilvUI.is_a(lv2World.ui_gtk2))
  878. rdfUI->Type.Value = LV2_UI_GTK2;
  879. else if (lilvUI.is_a(lv2World.ui_gtk3))
  880. rdfUI->Type.Value = LV2_UI_GTK3;
  881. else if (lilvUI.is_a(lv2World.ui_qt4))
  882. rdfUI->Type.Value = LV2_UI_QT4;
  883. else if (lilvUI.is_a(lv2World.ui_qt5))
  884. rdfUI->Type.Value = LV2_UI_QT5;
  885. else if (lilvUI.is_a(lv2World.ui_cocoa))
  886. rdfUI->Type.Value = LV2_UI_COCOA;
  887. else if (lilvUI.is_a(lv2World.ui_windows))
  888. rdfUI->Type.Value = LV2_UI_WINDOWS;
  889. else if (lilvUI.is_a(lv2World.ui_x11))
  890. rdfUI->Type.Value = LV2_UI_X11;
  891. else if (lilvUI.is_a(lv2World.ui_external))
  892. rdfUI->Type.Value = LV2_UI_EXTERNAL;
  893. else if (lilvUI.is_a(lv2World.ui_externalOld))
  894. rdfUI->Type.Value = LV2_UI_OLD_EXTERNAL;
  895. else
  896. qWarning("lv2_rdf_new(\"%s\") - got unknown UI type '%s'", uri, uiType);
  897. }
  898. // --------------------------------------
  899. // Set UI Information
  900. {
  901. if (const char* const uiURI = lilvUI.get_uri().as_uri())
  902. rdfUI->URI = strdup(uiURI);
  903. if (const char* const uiBinary = lilvUI.get_binary_uri().as_string())
  904. rdfUI->Binary = strdup(lilv_uri_to_path(uiBinary));
  905. if (const char* const uiBundle = lilvUI.get_bundle_uri().as_string())
  906. rdfUI->Bundle = strdup(lilv_uri_to_path(uiBundle));
  907. }
  908. // --------------------------------------
  909. // Set UI Features
  910. {
  911. Lilv::Nodes lilvFeatureNodes(lilvUI.get_supported_features());
  912. if (lilvFeatureNodes.size() > 0)
  913. {
  914. Lilv::Nodes lilvFeatureNodesR(lilvUI.get_required_features());
  915. rdfUI->FeatureCount = lilvFeatureNodes.size();
  916. rdfUI->Features = new LV2_RDF_Feature[rdfUI->FeatureCount];
  917. uint32_t x = 0;
  918. LILV_FOREACH(nodes, k, lilvFeatureNodes)
  919. {
  920. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(k));
  921. LV2_RDF_Feature* const rdfFeature = &rdfUI->Features[x++];
  922. rdfFeature->Type = lilvFeatureNodesR.contains(lilvFeatureNode) ? LV2_FEATURE_REQUIRED : LV2_FEATURE_OPTIONAL;
  923. rdfFeature->URI = strdup(lilvFeatureNode.as_uri());
  924. // TODO: char check
  925. }
  926. }
  927. }
  928. // --------------------------------------
  929. // Set UI Extensions
  930. {
  931. Lilv::Nodes lilvExtensionDataNodes(lilvUI.get_extension_data());
  932. if (lilvExtensionDataNodes.size() > 0)
  933. {
  934. rdfUI->ExtensionCount = lilvExtensionDataNodes.size();
  935. rdfUI->Extensions = new LV2_URI[rdfUI->ExtensionCount];
  936. uint32_t x = 0;
  937. LILV_FOREACH(nodes, k, lilvExtensionDataNodes)
  938. {
  939. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(k));
  940. LV2_URI* const rdfExtension = &rdfUI->Extensions[x++];
  941. *rdfExtension = strdup(lilvExtensionDataNode.as_uri());
  942. // TODO: char check
  943. }
  944. }
  945. }
  946. }
  947. }
  948. }
  949. return rdfDescriptor;
  950. }
  951. // -------------------------------------------------
  952. // Check if we support a plugin port
  953. static inline
  954. bool is_lv2_port_supported(const LV2_Property types)
  955. {
  956. if (LV2_IS_PORT_CONTROL(types))
  957. return true;
  958. if (LV2_IS_PORT_AUDIO(types))
  959. return true;
  960. if (LV2_IS_PORT_ATOM_SEQUENCE(types))
  961. return true;
  962. if (LV2_IS_PORT_CV(types))
  963. return true; // TODO
  964. if (LV2_IS_PORT_EVENT(types))
  965. return true;
  966. if (LV2_IS_PORT_MIDI_LL(types))
  967. return true;
  968. return false;
  969. }
  970. // -------------------------------------------------
  971. // Check if we support a plugin feature
  972. static inline
  973. bool is_lv2_feature_supported(const LV2_URI uri)
  974. {
  975. if (strcmp(uri, LV2_CORE__hardRTCapable) == 0)
  976. return true;
  977. if (strcmp(uri, LV2_CORE__inPlaceBroken) == 0)
  978. return true;
  979. if (strcmp(uri, LV2_CORE__isLive) == 0)
  980. return true;
  981. if (strcmp(uri, LV2_BUF_SIZE__boundedBlockLength) == 0)
  982. return true;
  983. if (strcmp(uri, LV2_BUF_SIZE__fixedBlockLength) == 0)
  984. return true;
  985. if (strcmp(uri, LV2_BUF_SIZE__powerOf2BlockLength) == 0)
  986. return true;
  987. if (strcmp(uri, LV2_EVENT_URI) == 0)
  988. return true;
  989. if (strcmp(uri, LV2_LOG__log) == 0)
  990. return true;
  991. if (strcmp(uri, LV2_OPTIONS__options) == 0)
  992. return true;
  993. if (strcmp(uri, LV2_PROGRAMS__Host) == 0)
  994. return true;
  995. if (strcmp(uri, LV2_RTSAFE_MEMORY_POOL__Pool) == 0)
  996. return true;
  997. if (strcmp(uri, LV2_STATE__makePath) == 0)
  998. return true;
  999. if (strcmp(uri, LV2_STATE__mapPath) == 0)
  1000. return true;
  1001. if (strcmp(uri, LV2_PORT_PROPS__supportsStrictBounds) == 0)
  1002. return true;
  1003. if (strcmp(uri, LV2_URI_MAP_URI) == 0)
  1004. return true;
  1005. if (strcmp(uri, LV2_URID__map) == 0)
  1006. return true;
  1007. if (strcmp(uri, LV2_URID__unmap) == 0)
  1008. return true;
  1009. if (strcmp(uri, LV2_WORKER__schedule) == 0)
  1010. return true;
  1011. return false;
  1012. }
  1013. // -------------------------------------------------
  1014. // Check if we support a plugin or UI feature
  1015. static inline
  1016. bool is_lv2_ui_feature_supported(const LV2_URI uri)
  1017. {
  1018. if (is_lv2_feature_supported(uri))
  1019. return true;
  1020. if (strcmp(uri, LV2_DATA_ACCESS_URI) == 0)
  1021. return true;
  1022. if (strcmp(uri, LV2_INSTANCE_ACCESS_URI) == 0)
  1023. return true;
  1024. if (strcmp(uri, LV2_UI__fixedSize) == 0)
  1025. return true;
  1026. if (strcmp(uri, LV2_UI__makeResident) == 0)
  1027. return true;
  1028. if (strcmp(uri, LV2_UI__noUserResize) == 0)
  1029. return true;
  1030. if (strcmp(uri, LV2_UI__parent) == 0)
  1031. return true;
  1032. if (strcmp(uri, LV2_UI__portMap) == 0)
  1033. return true;
  1034. if (strcmp(uri, LV2_UI__portSubscribe) == 0)
  1035. return false; // TODO
  1036. if (strcmp(uri, LV2_UI__resize) == 0)
  1037. return true;
  1038. if (strcmp(uri, LV2_UI__touch) == 0)
  1039. return false; // TODO
  1040. if (strcmp(uri, LV2_EXTERNAL_UI__Widget) == 0)
  1041. return true;
  1042. if (strcmp(uri, LV2_EXTERNAL_UI_DEPRECATED_URI) == 0)
  1043. return true;
  1044. return false;
  1045. }
  1046. // -------------------------------------------------
  1047. #endif // __CARLA_LV2_UTILS_HPP__