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.

1287 lines
51KB

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