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.

1615 lines
68KB

  1. /*
  2. * Carla LV2 utils
  3. * Copyright (C) 2011-2017 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 doc/GPL.txt file.
  16. */
  17. #ifndef CARLA_LV2_UTILS_HPP_INCLUDED
  18. #define CARLA_LV2_UTILS_HPP_INCLUDED
  19. #include "CarlaUtils.hpp"
  20. #ifndef nullptr
  21. # undef NULL
  22. # define NULL nullptr
  23. #endif
  24. // disable -Wdocumentation for LV2 headers
  25. #if defined(__clang__) && (__clang_major__ * 100 + __clang_minor__) > 300
  26. # pragma clang diagnostic push
  27. # pragma clang diagnostic ignored "-Wdocumentation"
  28. #endif
  29. #include "lv2/lv2.h"
  30. #include "lv2/atom.h"
  31. #include "lv2/atom-forge.h"
  32. #include "lv2/atom-helpers.h"
  33. #include "lv2/atom-util.h"
  34. #include "lv2/buf-size.h"
  35. #include "lv2/data-access.h"
  36. // dynmanifest
  37. #include "lv2/event.h"
  38. #include "lv2/event-helpers.h"
  39. #include "lv2/instance-access.h"
  40. #include "lv2/log.h"
  41. // logger
  42. #include "lv2/midi.h"
  43. // morph
  44. #include "lv2/options.h"
  45. #include "lv2/parameters.h"
  46. #include "lv2/patch.h"
  47. #include "lv2/port-groups.h"
  48. #include "lv2/port-props.h"
  49. #include "lv2/presets.h"
  50. #include "lv2/resize-port.h"
  51. #include "lv2/state.h"
  52. #include "lv2/time.h"
  53. #include "lv2/ui.h"
  54. #include "lv2/units.h"
  55. #include "lv2/uri-map.h"
  56. #include "lv2/urid.h"
  57. #include "lv2/worker.h"
  58. #include "lv2/lv2-miditype.h"
  59. #include "lv2/lv2-midifunctions.h"
  60. #include "lv2/lv2_external_ui.h"
  61. #include "lv2/lv2_kxstudio_properties.h"
  62. #include "lv2/lv2_programs.h"
  63. #include "lv2/lv2_rtmempool.h"
  64. #include "lilv/lilvmm.hpp"
  65. #include "sratom/sratom.h"
  66. // enable -Wdocumentation again
  67. #if defined(__clang__) && (__clang_major__ * 100 + __clang_minor__) > 300
  68. # pragma clang diagnostic pop
  69. #endif
  70. #include "lv2_rdf.hpp"
  71. #ifdef USE_QT
  72. # include <QtCore/QStringList>
  73. #else
  74. # include "AppConfig.h"
  75. # include "juce_core/juce_core.h"
  76. #endif
  77. // used for scalepoint sorting
  78. #include <map>
  79. typedef std::map<double,const LilvScalePoint*> LilvScalePointMap;
  80. // -----------------------------------------------------------------------
  81. // Define namespaces and missing prefixes
  82. #define NS_dct "http://purl.org/dc/terms/"
  83. #define NS_doap "http://usefulinc.com/ns/doap#"
  84. #define NS_rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  85. #define NS_rdfs "http://www.w3.org/2000/01/rdf-schema#"
  86. #define NS_llmm "http://ll-plugins.nongnu.org/lv2/ext/midimap#"
  87. #define NS_mod "http://moddevices.com/ns/modgui#"
  88. #define LV2_MIDI_Map__CC "http://ll-plugins.nongnu.org/lv2/namespace#CC"
  89. #define LV2_MIDI_Map__NRPN "http://ll-plugins.nongnu.org/lv2/namespace#NRPN"
  90. #define LV2_MIDI_LL__MidiPort "http://ll-plugins.nongnu.org/lv2/ext/MidiPort"
  91. #define LV2_UI__makeResident LV2_UI_PREFIX "makeResident"
  92. #define LV2_UI__makeSONameResident LV2_UI_PREFIX "makeSONameResident"
  93. // -----------------------------------------------------------------------
  94. // Custom Atom types
  95. struct LV2_Atom_MidiEvent {
  96. LV2_Atom atom; /**< Atom header. */
  97. uint8_t data[4]; /**< MIDI data (body). */
  98. };
  99. static inline
  100. uint32_t lv2_atom_total_size(const LV2_Atom_MidiEvent& midiEv)
  101. {
  102. return static_cast<uint32_t>(sizeof(LV2_Atom)) + midiEv.atom.size;
  103. }
  104. // -----------------------------------------------------------------------
  105. // Our LV2 World class
  106. class Lv2WorldClass : public Lilv::World
  107. {
  108. public:
  109. // Base Types
  110. Lilv::Node port;
  111. Lilv::Node symbol;
  112. Lilv::Node designation;
  113. Lilv::Node freeWheeling;
  114. Lilv::Node reportsLatency;
  115. // Plugin Types
  116. Lilv::Node class_allpass;
  117. Lilv::Node class_amplifier;
  118. Lilv::Node class_analyzer;
  119. Lilv::Node class_bandpass;
  120. Lilv::Node class_chorus;
  121. Lilv::Node class_comb;
  122. Lilv::Node class_compressor;
  123. Lilv::Node class_constant;
  124. Lilv::Node class_converter;
  125. Lilv::Node class_delay;
  126. Lilv::Node class_distortion;
  127. Lilv::Node class_dynamics;
  128. Lilv::Node class_eq;
  129. Lilv::Node class_envelope;
  130. Lilv::Node class_expander;
  131. Lilv::Node class_filter;
  132. Lilv::Node class_flanger;
  133. Lilv::Node class_function;
  134. Lilv::Node class_gate;
  135. Lilv::Node class_generator;
  136. Lilv::Node class_highpass;
  137. Lilv::Node class_instrument;
  138. Lilv::Node class_limiter;
  139. Lilv::Node class_lowpass;
  140. Lilv::Node class_mixer;
  141. Lilv::Node class_modulator;
  142. Lilv::Node class_multiEQ;
  143. Lilv::Node class_oscillator;
  144. Lilv::Node class_paraEQ;
  145. Lilv::Node class_phaser;
  146. Lilv::Node class_pitch;
  147. Lilv::Node class_reverb;
  148. Lilv::Node class_simulator;
  149. Lilv::Node class_spatial;
  150. Lilv::Node class_spectral;
  151. Lilv::Node class_utility;
  152. Lilv::Node class_waveshaper;
  153. // Port Types
  154. Lilv::Node port_input;
  155. Lilv::Node port_output;
  156. Lilv::Node port_control;
  157. Lilv::Node port_audio;
  158. Lilv::Node port_cv;
  159. Lilv::Node port_atom;
  160. Lilv::Node port_event;
  161. Lilv::Node port_midi;
  162. // Port Properties
  163. Lilv::Node pprop_optional;
  164. Lilv::Node pprop_enumeration;
  165. Lilv::Node pprop_integer;
  166. Lilv::Node pprop_sampleRate;
  167. Lilv::Node pprop_toggled;
  168. Lilv::Node pprop_artifacts;
  169. Lilv::Node pprop_continuousCV;
  170. Lilv::Node pprop_discreteCV;
  171. Lilv::Node pprop_expensive;
  172. Lilv::Node pprop_strictBounds;
  173. Lilv::Node pprop_logarithmic;
  174. Lilv::Node pprop_notAutomatic;
  175. Lilv::Node pprop_notOnGUI;
  176. Lilv::Node pprop_trigger;
  177. Lilv::Node pprop_nonAutomable;
  178. // Unit Hints
  179. Lilv::Node unit_name;
  180. Lilv::Node unit_render;
  181. Lilv::Node unit_symbol;
  182. Lilv::Node unit_unit;
  183. // UI Types
  184. Lilv::Node ui_gtk2;
  185. Lilv::Node ui_gtk3;
  186. Lilv::Node ui_qt4;
  187. Lilv::Node ui_qt5;
  188. Lilv::Node ui_cocoa;
  189. Lilv::Node ui_windows;
  190. Lilv::Node ui_x11;
  191. Lilv::Node ui_external;
  192. Lilv::Node ui_externalOld;
  193. Lilv::Node ui_externalOld2;
  194. // Misc
  195. Lilv::Node atom_bufferType;
  196. Lilv::Node atom_sequence;
  197. Lilv::Node atom_supports;
  198. Lilv::Node preset_preset;
  199. Lilv::Node state_state;
  200. Lilv::Node value_default;
  201. Lilv::Node value_minimum;
  202. Lilv::Node value_maximum;
  203. Lilv::Node rz_asLargeAs;
  204. Lilv::Node rz_minSize;
  205. // Port Data Types
  206. Lilv::Node midi_event;
  207. Lilv::Node patch_message;
  208. Lilv::Node time_position;
  209. // MIDI CC
  210. Lilv::Node mm_defaultControl;
  211. Lilv::Node mm_controlType;
  212. Lilv::Node mm_controlNumber;
  213. // Other
  214. Lilv::Node dct_replaces;
  215. Lilv::Node doap_license;
  216. Lilv::Node rdf_type;
  217. Lilv::Node rdfs_label;
  218. bool needsInit;
  219. const LilvPlugins* allPlugins;
  220. const LilvPlugin** cachedPlugins;
  221. uint pluginCount;
  222. // -------------------------------------------------------------------
  223. Lv2WorldClass()
  224. : Lilv::World(),
  225. port (new_uri(LV2_CORE__port)),
  226. symbol (new_uri(LV2_CORE__symbol)),
  227. designation (new_uri(LV2_CORE__designation)),
  228. freeWheeling (new_uri(LV2_CORE__freeWheeling)),
  229. reportsLatency (new_uri(LV2_CORE__reportsLatency)),
  230. class_allpass (new_uri(LV2_CORE__AllpassPlugin)),
  231. class_amplifier (new_uri(LV2_CORE__AmplifierPlugin)),
  232. class_analyzer (new_uri(LV2_CORE__AnalyserPlugin)),
  233. class_bandpass (new_uri(LV2_CORE__BandpassPlugin)),
  234. class_chorus (new_uri(LV2_CORE__ChorusPlugin)),
  235. class_comb (new_uri(LV2_CORE__CombPlugin)),
  236. class_compressor (new_uri(LV2_CORE__CompressorPlugin)),
  237. class_constant (new_uri(LV2_CORE__ConstantPlugin)),
  238. class_converter (new_uri(LV2_CORE__ConverterPlugin)),
  239. class_delay (new_uri(LV2_CORE__DelayPlugin)),
  240. class_distortion (new_uri(LV2_CORE__DistortionPlugin)),
  241. class_dynamics (new_uri(LV2_CORE__DynamicsPlugin)),
  242. class_eq (new_uri(LV2_CORE__EQPlugin)),
  243. class_envelope (new_uri(LV2_CORE__EnvelopePlugin)),
  244. class_expander (new_uri(LV2_CORE__ExpanderPlugin)),
  245. class_filter (new_uri(LV2_CORE__FilterPlugin)),
  246. class_flanger (new_uri(LV2_CORE__FlangerPlugin)),
  247. class_function (new_uri(LV2_CORE__FunctionPlugin)),
  248. class_gate (new_uri(LV2_CORE__GatePlugin)),
  249. class_generator (new_uri(LV2_CORE__GeneratorPlugin)),
  250. class_highpass (new_uri(LV2_CORE__HighpassPlugin)),
  251. class_instrument (new_uri(LV2_CORE__InstrumentPlugin)),
  252. class_limiter (new_uri(LV2_CORE__LimiterPlugin)),
  253. class_lowpass (new_uri(LV2_CORE__LowpassPlugin)),
  254. class_mixer (new_uri(LV2_CORE__MixerPlugin)),
  255. class_modulator (new_uri(LV2_CORE__ModulatorPlugin)),
  256. class_multiEQ (new_uri(LV2_CORE__MultiEQPlugin)),
  257. class_oscillator (new_uri(LV2_CORE__OscillatorPlugin)),
  258. class_paraEQ (new_uri(LV2_CORE__ParaEQPlugin)),
  259. class_phaser (new_uri(LV2_CORE__PhaserPlugin)),
  260. class_pitch (new_uri(LV2_CORE__PitchPlugin)),
  261. class_reverb (new_uri(LV2_CORE__ReverbPlugin)),
  262. class_simulator (new_uri(LV2_CORE__SimulatorPlugin)),
  263. class_spatial (new_uri(LV2_CORE__SpatialPlugin)),
  264. class_spectral (new_uri(LV2_CORE__SpectralPlugin)),
  265. class_utility (new_uri(LV2_CORE__UtilityPlugin)),
  266. class_waveshaper (new_uri(LV2_CORE__WaveshaperPlugin)),
  267. port_input (new_uri(LV2_CORE__InputPort)),
  268. port_output (new_uri(LV2_CORE__OutputPort)),
  269. port_control (new_uri(LV2_CORE__ControlPort)),
  270. port_audio (new_uri(LV2_CORE__AudioPort)),
  271. port_cv (new_uri(LV2_CORE__CVPort)),
  272. port_atom (new_uri(LV2_ATOM__AtomPort)),
  273. port_event (new_uri(LV2_EVENT__EventPort)),
  274. port_midi (new_uri(LV2_MIDI_LL__MidiPort)),
  275. pprop_optional (new_uri(LV2_CORE__connectionOptional)),
  276. pprop_enumeration (new_uri(LV2_CORE__enumeration)),
  277. pprop_integer (new_uri(LV2_CORE__integer)),
  278. pprop_sampleRate (new_uri(LV2_CORE__sampleRate)),
  279. pprop_toggled (new_uri(LV2_CORE__toggled)),
  280. pprop_artifacts (new_uri(LV2_PORT_PROPS__causesArtifacts)),
  281. pprop_continuousCV (new_uri(LV2_PORT_PROPS__continuousCV)),
  282. pprop_discreteCV (new_uri(LV2_PORT_PROPS__discreteCV)),
  283. pprop_expensive (new_uri(LV2_PORT_PROPS__expensive)),
  284. pprop_strictBounds (new_uri(LV2_PORT_PROPS__hasStrictBounds)),
  285. pprop_logarithmic (new_uri(LV2_PORT_PROPS__logarithmic)),
  286. pprop_notAutomatic (new_uri(LV2_PORT_PROPS__notAutomatic)),
  287. pprop_notOnGUI (new_uri(LV2_PORT_PROPS__notOnGUI)),
  288. pprop_trigger (new_uri(LV2_PORT_PROPS__trigger)),
  289. pprop_nonAutomable (new_uri(LV2_KXSTUDIO_PROPERTIES__NonAutomable)),
  290. unit_name (new_uri(LV2_UNITS__name)),
  291. unit_render (new_uri(LV2_UNITS__render)),
  292. unit_symbol (new_uri(LV2_UNITS__symbol)),
  293. unit_unit (new_uri(LV2_UNITS__unit)),
  294. ui_gtk2 (new_uri(LV2_UI__GtkUI)),
  295. ui_gtk3 (new_uri(LV2_UI__Gtk3UI)),
  296. ui_qt4 (new_uri(LV2_UI__Qt4UI)),
  297. ui_qt5 (new_uri(LV2_UI__Qt5UI)),
  298. ui_cocoa (new_uri(LV2_UI__CocoaUI)),
  299. ui_windows (new_uri(LV2_UI__WindowsUI)),
  300. ui_x11 (new_uri(LV2_UI__X11UI)),
  301. ui_external (new_uri(LV2_EXTERNAL_UI__Widget)),
  302. ui_externalOld (new_uri(LV2_EXTERNAL_UI_DEPRECATED_URI)),
  303. ui_externalOld2 (new_uri("http://nedko.arnaudov.name/lv2/external_ui/")),
  304. atom_bufferType (new_uri(LV2_ATOM__bufferType)),
  305. atom_sequence (new_uri(LV2_ATOM__Sequence)),
  306. atom_supports (new_uri(LV2_ATOM__supports)),
  307. preset_preset (new_uri(LV2_PRESETS__Preset)),
  308. state_state (new_uri(LV2_STATE__state)),
  309. value_default (new_uri(LV2_CORE__default)),
  310. value_minimum (new_uri(LV2_CORE__minimum)),
  311. value_maximum (new_uri(LV2_CORE__maximum)),
  312. rz_asLargeAs (new_uri(LV2_RESIZE_PORT__asLargeAs)),
  313. rz_minSize (new_uri(LV2_RESIZE_PORT__minimumSize)),
  314. midi_event (new_uri(LV2_MIDI__MidiEvent)),
  315. patch_message (new_uri(LV2_PATCH__Message)),
  316. time_position (new_uri(LV2_TIME__Position)),
  317. mm_defaultControl (new_uri(NS_llmm "defaultMidiController")),
  318. mm_controlType (new_uri(NS_llmm "controllerType")),
  319. mm_controlNumber (new_uri(NS_llmm "controllerNumber")),
  320. dct_replaces (new_uri(NS_dct "replaces")),
  321. doap_license (new_uri(NS_doap "license")),
  322. rdf_type (new_uri(NS_rdf "type")),
  323. rdfs_label (new_uri(NS_rdfs "label")),
  324. needsInit(true),
  325. allPlugins(nullptr),
  326. cachedPlugins(nullptr),
  327. pluginCount(0) {}
  328. ~Lv2WorldClass() override
  329. {
  330. pluginCount = 0;
  331. allPlugins = nullptr;
  332. if (cachedPlugins != nullptr)
  333. {
  334. delete[] cachedPlugins;
  335. cachedPlugins = nullptr;
  336. }
  337. }
  338. // FIXME - remove this
  339. static Lv2WorldClass& getInstance()
  340. {
  341. static Lv2WorldClass lv2World;
  342. return lv2World;
  343. }
  344. void initIfNeeded(const char* const LV2_PATH)
  345. {
  346. CARLA_SAFE_ASSERT_RETURN(LV2_PATH != nullptr,);
  347. if (! needsInit)
  348. return;
  349. needsInit = false;
  350. Lilv::World::load_all(LV2_PATH);
  351. allPlugins = lilv_world_get_all_plugins(this->me);
  352. CARLA_SAFE_ASSERT_RETURN(allPlugins != nullptr,);
  353. if ((pluginCount = lilv_plugins_size(allPlugins)))
  354. {
  355. cachedPlugins = new const LilvPlugin*[pluginCount+1];
  356. carla_zeroPointers(cachedPlugins, pluginCount+1);
  357. int i = 0;
  358. for (LilvIter* it = lilv_plugins_begin(allPlugins); ! lilv_plugins_is_end(allPlugins, it); it = lilv_plugins_next(allPlugins, it))
  359. cachedPlugins[i++] = lilv_plugins_get(allPlugins, it);
  360. }
  361. }
  362. void load_bundle(const char* const bundle)
  363. {
  364. CARLA_SAFE_ASSERT_RETURN(bundle != nullptr && bundle[0] != '\0',);
  365. CARLA_SAFE_ASSERT_RETURN(needsInit,);
  366. needsInit = false;
  367. Lilv::World::load_bundle(Lilv::Node(new_uri(bundle)));
  368. allPlugins = lilv_world_get_all_plugins(this->me);
  369. CARLA_SAFE_ASSERT_RETURN(allPlugins != nullptr,);
  370. if ((pluginCount = lilv_plugins_size(allPlugins)))
  371. {
  372. cachedPlugins = new const LilvPlugin*[pluginCount+1];
  373. carla_zeroPointers(cachedPlugins, pluginCount+1);
  374. int i = 0;
  375. for (LilvIter* it = lilv_plugins_begin(allPlugins); ! lilv_plugins_is_end(allPlugins, it); it = lilv_plugins_next(allPlugins, it))
  376. cachedPlugins[i++] = lilv_plugins_get(allPlugins, it);
  377. }
  378. }
  379. uint getPluginCount() const
  380. {
  381. CARLA_SAFE_ASSERT_RETURN(! needsInit, 0);
  382. return pluginCount;
  383. }
  384. const LilvPlugin* getPluginFromIndex(const uint index) const
  385. {
  386. CARLA_SAFE_ASSERT_RETURN(! needsInit, nullptr);
  387. CARLA_SAFE_ASSERT_RETURN(cachedPlugins != nullptr, nullptr);
  388. CARLA_SAFE_ASSERT_RETURN(index < pluginCount, nullptr);
  389. return cachedPlugins[index];
  390. }
  391. const LilvPlugin* getPluginFromURI(const LV2_URI uri) const
  392. {
  393. CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0', nullptr);
  394. CARLA_SAFE_ASSERT_RETURN(! needsInit, nullptr);
  395. CARLA_SAFE_ASSERT_RETURN(allPlugins != nullptr, nullptr);
  396. LilvNode* const uriNode(lilv_new_uri(this->me, uri));
  397. CARLA_SAFE_ASSERT_RETURN(uriNode != nullptr, nullptr);
  398. const LilvPlugin* const cPlugin(lilv_plugins_get_by_uri(allPlugins, uriNode));
  399. lilv_node_free(uriNode);
  400. return cPlugin;
  401. }
  402. LilvState* getStateFromURI(const LV2_URI uri, const LV2_URID_Map* const uridMap) const
  403. {
  404. CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0', nullptr);
  405. CARLA_SAFE_ASSERT_RETURN(uridMap != nullptr, nullptr);
  406. CARLA_SAFE_ASSERT_RETURN(! needsInit, nullptr);
  407. LilvNode* const uriNode(lilv_new_uri(this->me, uri));
  408. CARLA_SAFE_ASSERT_RETURN(uriNode != nullptr, nullptr);
  409. CARLA_SAFE_ASSERT(lilv_world_load_resource(this->me, uriNode) >= 0);
  410. LilvState* const cState(lilv_state_new_from_world(this->me, uridMap, uriNode));
  411. lilv_node_free(uriNode);
  412. return cState;
  413. }
  414. CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION
  415. CARLA_DECLARE_NON_COPY_STRUCT(Lv2WorldClass)
  416. };
  417. // -----------------------------------------------------------------------
  418. // Create new RDF object (using lilv)
  419. static inline
  420. const LV2_RDF_Descriptor* lv2_rdf_new(const LV2_URI uri, const bool loadPresets)
  421. {
  422. CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0', nullptr);
  423. Lv2WorldClass& lv2World(Lv2WorldClass::getInstance());
  424. const LilvPlugin* const cPlugin(lv2World.getPluginFromURI(uri));
  425. CARLA_SAFE_ASSERT_RETURN(cPlugin != nullptr, nullptr);
  426. Lilv::Plugin lilvPlugin(cPlugin);
  427. LV2_RDF_Descriptor* const rdfDescriptor(new LV2_RDF_Descriptor());
  428. // -------------------------------------------------------------------
  429. // Set Plugin Type
  430. {
  431. Lilv::Nodes typeNodes(lilvPlugin.get_value(lv2World.rdf_type));
  432. if (typeNodes.size() > 0)
  433. {
  434. if (typeNodes.contains(lv2World.class_allpass))
  435. rdfDescriptor->Type[0] |= LV2_PLUGIN_ALLPASS;
  436. if (typeNodes.contains(lv2World.class_amplifier))
  437. rdfDescriptor->Type[0] |= LV2_PLUGIN_AMPLIFIER;
  438. if (typeNodes.contains(lv2World.class_analyzer))
  439. rdfDescriptor->Type[1] |= LV2_PLUGIN_ANALYSER;
  440. if (typeNodes.contains(lv2World.class_bandpass))
  441. rdfDescriptor->Type[0] |= LV2_PLUGIN_BANDPASS;
  442. if (typeNodes.contains(lv2World.class_chorus))
  443. rdfDescriptor->Type[1] |= LV2_PLUGIN_CHORUS;
  444. if (typeNodes.contains(lv2World.class_comb))
  445. rdfDescriptor->Type[1] |= LV2_PLUGIN_COMB;
  446. if (typeNodes.contains(lv2World.class_compressor))
  447. rdfDescriptor->Type[0] |= LV2_PLUGIN_COMPRESSOR;
  448. if (typeNodes.contains(lv2World.class_constant))
  449. rdfDescriptor->Type[1] |= LV2_PLUGIN_CONSTANT;
  450. if (typeNodes.contains(lv2World.class_converter))
  451. rdfDescriptor->Type[1] |= LV2_PLUGIN_CONVERTER;
  452. if (typeNodes.contains(lv2World.class_delay))
  453. rdfDescriptor->Type[0] |= LV2_PLUGIN_DELAY;
  454. if (typeNodes.contains(lv2World.class_distortion))
  455. rdfDescriptor->Type[0] |= LV2_PLUGIN_DISTORTION;
  456. if (typeNodes.contains(lv2World.class_dynamics))
  457. rdfDescriptor->Type[0] |= LV2_PLUGIN_DYNAMICS;
  458. if (typeNodes.contains(lv2World.class_eq))
  459. rdfDescriptor->Type[0] |= LV2_PLUGIN_EQ;
  460. if (typeNodes.contains(lv2World.class_envelope))
  461. rdfDescriptor->Type[0] |= LV2_PLUGIN_ENVELOPE;
  462. if (typeNodes.contains(lv2World.class_expander))
  463. rdfDescriptor->Type[0] |= LV2_PLUGIN_EXPANDER;
  464. if (typeNodes.contains(lv2World.class_filter))
  465. rdfDescriptor->Type[0] |= LV2_PLUGIN_FILTER;
  466. if (typeNodes.contains(lv2World.class_flanger))
  467. rdfDescriptor->Type[1] |= LV2_PLUGIN_FLANGER;
  468. if (typeNodes.contains(lv2World.class_function))
  469. rdfDescriptor->Type[1] |= LV2_PLUGIN_FUNCTION;
  470. if (typeNodes.contains(lv2World.class_gate))
  471. rdfDescriptor->Type[0] |= LV2_PLUGIN_GATE;
  472. if (typeNodes.contains(lv2World.class_generator))
  473. rdfDescriptor->Type[1] |= LV2_PLUGIN_GENERATOR;
  474. if (typeNodes.contains(lv2World.class_highpass))
  475. rdfDescriptor->Type[0] |= LV2_PLUGIN_HIGHPASS;
  476. if (typeNodes.contains(lv2World.class_instrument))
  477. rdfDescriptor->Type[1] |= LV2_PLUGIN_INSTRUMENT;
  478. if (typeNodes.contains(lv2World.class_limiter))
  479. rdfDescriptor->Type[0] |= LV2_PLUGIN_LIMITER;
  480. if (typeNodes.contains(lv2World.class_lowpass))
  481. rdfDescriptor->Type[0] |= LV2_PLUGIN_LOWPASS;
  482. if (typeNodes.contains(lv2World.class_mixer))
  483. rdfDescriptor->Type[1] |= LV2_PLUGIN_MIXER;
  484. if (typeNodes.contains(lv2World.class_modulator))
  485. rdfDescriptor->Type[1] |= LV2_PLUGIN_MODULATOR;
  486. if (typeNodes.contains(lv2World.class_multiEQ))
  487. rdfDescriptor->Type[0] |= LV2_PLUGIN_MULTI_EQ;
  488. if (typeNodes.contains(lv2World.class_oscillator))
  489. rdfDescriptor->Type[1] |= LV2_PLUGIN_OSCILLATOR;
  490. if (typeNodes.contains(lv2World.class_paraEQ))
  491. rdfDescriptor->Type[0] |= LV2_PLUGIN_PARA_EQ;
  492. if (typeNodes.contains(lv2World.class_phaser))
  493. rdfDescriptor->Type[1] |= LV2_PLUGIN_PHASER;
  494. if (typeNodes.contains(lv2World.class_pitch))
  495. rdfDescriptor->Type[1] |= LV2_PLUGIN_PITCH;
  496. if (typeNodes.contains(lv2World.class_reverb))
  497. rdfDescriptor->Type[0] |= LV2_PLUGIN_REVERB;
  498. if (typeNodes.contains(lv2World.class_simulator))
  499. rdfDescriptor->Type[0] |= LV2_PLUGIN_SIMULATOR;
  500. if (typeNodes.contains(lv2World.class_spatial))
  501. rdfDescriptor->Type[1] |= LV2_PLUGIN_SPATIAL;
  502. if (typeNodes.contains(lv2World.class_spectral))
  503. rdfDescriptor->Type[1] |= LV2_PLUGIN_SPECTRAL;
  504. if (typeNodes.contains(lv2World.class_utility))
  505. rdfDescriptor->Type[1] |= LV2_PLUGIN_UTILITY;
  506. if (typeNodes.contains(lv2World.class_waveshaper))
  507. rdfDescriptor->Type[0] |= LV2_PLUGIN_WAVESHAPER;
  508. }
  509. lilv_nodes_free(const_cast<LilvNodes*>(typeNodes.me));
  510. }
  511. // -------------------------------------------------------------------
  512. // Set Plugin Information
  513. {
  514. rdfDescriptor->URI = carla_strdup(uri);
  515. if (LilvNode* const nameNode = lilv_plugin_get_name(lilvPlugin.me))
  516. {
  517. if (const char* const name = lilv_node_as_string(nameNode))
  518. rdfDescriptor->Name = carla_strdup(name);
  519. lilv_node_free(nameNode);
  520. }
  521. if (const char* const author = lilvPlugin.get_author_name().as_string())
  522. rdfDescriptor->Author = carla_strdup(author);
  523. if (const char* const binary = lilvPlugin.get_library_uri().as_string())
  524. rdfDescriptor->Binary = carla_strdup_free(lilv_file_uri_parse(binary, nullptr));
  525. if (const char* const bundle = lilvPlugin.get_bundle_uri().as_string())
  526. rdfDescriptor->Bundle = carla_strdup_free(lilv_file_uri_parse(bundle, nullptr));
  527. Lilv::Nodes licenseNodes(lilvPlugin.get_value(lv2World.doap_license));
  528. if (licenseNodes.size() > 0)
  529. {
  530. if (const char* const license = licenseNodes.get_first().as_string())
  531. rdfDescriptor->License = carla_strdup(license);
  532. }
  533. lilv_nodes_free(const_cast<LilvNodes*>(licenseNodes.me));
  534. }
  535. // -------------------------------------------------------------------
  536. // Set Plugin UniqueID
  537. {
  538. Lilv::Nodes replaceNodes(lilvPlugin.get_value(lv2World.dct_replaces));
  539. if (replaceNodes.size() > 0)
  540. {
  541. Lilv::Node replaceNode(replaceNodes.get_first());
  542. if (replaceNode.is_uri())
  543. {
  544. #ifdef USE_QT
  545. const QString replaceURI(replaceNode.as_uri());
  546. if (replaceURI.startsWith("urn:"))
  547. {
  548. const QString replaceId(replaceURI.split(":").last());
  549. bool ok;
  550. const ulong uniqueId(replaceId.toULong(&ok));
  551. if (ok && uniqueId != 0)
  552. rdfDescriptor->UniqueID = uniqueId;
  553. }
  554. #else
  555. const juce::String replaceURI(replaceNode.as_uri());
  556. if (replaceURI.startsWith("urn:"))
  557. {
  558. const int uniqueId(replaceURI.getTrailingIntValue());
  559. if (uniqueId > 0)
  560. rdfDescriptor->UniqueID = static_cast<ulong>(uniqueId);
  561. }
  562. #endif
  563. }
  564. }
  565. lilv_nodes_free(const_cast<LilvNodes*>(replaceNodes.me));
  566. }
  567. // -------------------------------------------------------------------
  568. // Set Plugin Ports
  569. if (lilvPlugin.get_num_ports() > 0)
  570. {
  571. rdfDescriptor->PortCount = lilvPlugin.get_num_ports();
  572. rdfDescriptor->Ports = new LV2_RDF_Port[rdfDescriptor->PortCount];
  573. for (uint32_t i = 0; i < rdfDescriptor->PortCount; ++i)
  574. {
  575. Lilv::Port lilvPort(lilvPlugin.get_port_by_index(i));
  576. LV2_RDF_Port* const rdfPort(&rdfDescriptor->Ports[i]);
  577. // -----------------------------------------------------------
  578. // Set Port Information
  579. {
  580. if (LilvNode* const nameNode = lilv_port_get_name(lilvPlugin.me, lilvPort.me))
  581. {
  582. if (const char* const name = lilv_node_as_string(nameNode))
  583. rdfPort->Name = carla_strdup(name);
  584. lilv_node_free(nameNode);
  585. }
  586. if (const char* const symbol = lilv_node_as_string(lilvPort.get_symbol()))
  587. rdfPort->Symbol = carla_strdup(symbol);
  588. }
  589. // -----------------------------------------------------------
  590. // Set Port Mode and Type
  591. {
  592. // Input or Output
  593. /**/ if (lilvPort.is_a(lv2World.port_input))
  594. rdfPort->Types |= LV2_PORT_INPUT;
  595. else if (lilvPort.is_a(lv2World.port_output))
  596. rdfPort->Types |= LV2_PORT_OUTPUT;
  597. else
  598. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is not input or output", uri, rdfPort->Name);
  599. // Data Type
  600. /**/ if (lilvPort.is_a(lv2World.port_control))
  601. {
  602. rdfPort->Types |= LV2_PORT_CONTROL;
  603. }
  604. else if (lilvPort.is_a(lv2World.port_audio))
  605. {
  606. rdfPort->Types |= LV2_PORT_AUDIO;
  607. }
  608. else if (lilvPort.is_a(lv2World.port_cv))
  609. {
  610. rdfPort->Types |= LV2_PORT_CV;
  611. }
  612. else if (lilvPort.is_a(lv2World.port_atom))
  613. {
  614. rdfPort->Types |= LV2_PORT_ATOM;
  615. Lilv::Nodes bufferTypeNodes(lilvPort.get_value(lv2World.atom_bufferType));
  616. for (LilvIter* it = lilv_nodes_begin(bufferTypeNodes.me); ! lilv_nodes_is_end(bufferTypeNodes.me, it); it = lilv_nodes_next(bufferTypeNodes.me, it))
  617. {
  618. const Lilv::Node node(lilv_nodes_get(bufferTypeNodes.me, it));
  619. CARLA_SAFE_ASSERT_CONTINUE(node.is_uri());
  620. if (node.equals(lv2World.atom_sequence))
  621. rdfPort->Types |= LV2_PORT_ATOM_SEQUENCE;
  622. else
  623. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses an unknown atom buffer type '%s'", uri, rdfPort->Name, node.as_uri());
  624. }
  625. Lilv::Nodes supportNodes(lilvPort.get_value(lv2World.atom_supports));
  626. for (LilvIter* it = lilv_nodes_begin(supportNodes.me); ! lilv_nodes_is_end(supportNodes.me, it); it = lilv_nodes_next(supportNodes.me, it))
  627. {
  628. const Lilv::Node node(lilv_nodes_get(supportNodes.me, it));
  629. CARLA_SAFE_ASSERT_CONTINUE(node.is_uri());
  630. /**/ if (node.equals(lv2World.midi_event))
  631. rdfPort->Types |= LV2_PORT_DATA_MIDI_EVENT;
  632. else if (node.equals(lv2World.patch_message))
  633. rdfPort->Types |= LV2_PORT_DATA_PATCH_MESSAGE;
  634. else if (node.equals(lv2World.time_position))
  635. rdfPort->Types |= LV2_PORT_DATA_TIME_POSITION;
  636. #if 0
  637. // something new we don't support yet?
  638. else if (std::strstr(node.as_uri(), "lv2plug.in/") != nullptr)
  639. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is of atom type but has unsupported data '%s'", uri, rdfPort->Name, node.as_uri());
  640. #endif
  641. }
  642. lilv_nodes_free(const_cast<LilvNodes*>(bufferTypeNodes.me));
  643. lilv_nodes_free(const_cast<LilvNodes*>(supportNodes.me));
  644. }
  645. else if (lilvPort.is_a(lv2World.port_event))
  646. {
  647. rdfPort->Types |= LV2_PORT_EVENT;
  648. bool supported = false;
  649. if (lilvPort.supports_event(lv2World.midi_event))
  650. {
  651. rdfPort->Types |= LV2_PORT_DATA_MIDI_EVENT;
  652. supported = true;
  653. }
  654. if (lilvPort.supports_event(lv2World.patch_message))
  655. {
  656. rdfPort->Types |= LV2_PORT_DATA_PATCH_MESSAGE;
  657. supported = true;
  658. }
  659. if (lilvPort.supports_event(lv2World.time_position))
  660. {
  661. rdfPort->Types |= LV2_PORT_DATA_TIME_POSITION;
  662. supported = true;
  663. }
  664. if (! supported)
  665. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is of event type but has unsupported data", uri, rdfPort->Name);
  666. }
  667. else if (lilvPort.is_a(lv2World.port_midi))
  668. {
  669. rdfPort->Types |= LV2_PORT_MIDI_LL;
  670. rdfPort->Types |= LV2_PORT_DATA_MIDI_EVENT;
  671. }
  672. else
  673. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is of unkown data type", uri, rdfPort->Name);
  674. }
  675. // -----------------------------------------------------------
  676. // Set Port Properties
  677. {
  678. if (lilvPort.has_property(lv2World.pprop_optional))
  679. rdfPort->Properties |= LV2_PORT_OPTIONAL;
  680. if (lilvPort.has_property(lv2World.pprop_enumeration))
  681. rdfPort->Properties |= LV2_PORT_ENUMERATION;
  682. if (lilvPort.has_property(lv2World.pprop_integer))
  683. rdfPort->Properties |= LV2_PORT_INTEGER;
  684. if (lilvPort.has_property(lv2World.pprop_sampleRate))
  685. rdfPort->Properties |= LV2_PORT_SAMPLE_RATE;
  686. if (lilvPort.has_property(lv2World.pprop_toggled))
  687. rdfPort->Properties |= LV2_PORT_TOGGLED;
  688. if (lilvPort.has_property(lv2World.pprop_artifacts))
  689. rdfPort->Properties |= LV2_PORT_CAUSES_ARTIFACTS;
  690. if (lilvPort.has_property(lv2World.pprop_continuousCV))
  691. rdfPort->Properties |= LV2_PORT_CONTINUOUS_CV;
  692. if (lilvPort.has_property(lv2World.pprop_discreteCV))
  693. rdfPort->Properties |= LV2_PORT_DISCRETE_CV;
  694. if (lilvPort.has_property(lv2World.pprop_expensive))
  695. rdfPort->Properties |= LV2_PORT_EXPENSIVE;
  696. if (lilvPort.has_property(lv2World.pprop_strictBounds))
  697. rdfPort->Properties |= LV2_PORT_STRICT_BOUNDS;
  698. if (lilvPort.has_property(lv2World.pprop_logarithmic))
  699. rdfPort->Properties |= LV2_PORT_LOGARITHMIC;
  700. if (lilvPort.has_property(lv2World.pprop_notAutomatic))
  701. rdfPort->Properties |= LV2_PORT_NOT_AUTOMATIC;
  702. if (lilvPort.has_property(lv2World.pprop_notOnGUI))
  703. rdfPort->Properties |= LV2_PORT_NOT_ON_GUI;
  704. if (lilvPort.has_property(lv2World.pprop_trigger))
  705. rdfPort->Properties |= LV2_PORT_TRIGGER;
  706. if (lilvPort.has_property(lv2World.pprop_nonAutomable))
  707. rdfPort->Properties |= LV2_PORT_NON_AUTOMABLE;
  708. if (lilvPort.has_property(lv2World.reportsLatency))
  709. rdfPort->Designation = LV2_PORT_DESIGNATION_LATENCY;
  710. // no port properties set, check if using old/invalid ones
  711. if (rdfPort->Properties == 0x0)
  712. {
  713. const Lilv::Node oldPropArtifacts(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#causesArtifacts"));
  714. const Lilv::Node oldPropContinuousCV(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#continuousCV"));
  715. const Lilv::Node oldPropDiscreteCV(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#discreteCV"));
  716. const Lilv::Node oldPropExpensive(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#expensive"));
  717. const Lilv::Node oldPropStrictBounds(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#hasStrictBounds"));
  718. const Lilv::Node oldPropLogarithmic(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#logarithmic"));
  719. const Lilv::Node oldPropNotAutomatic(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#notAutomatic"));
  720. const Lilv::Node oldPropNotOnGUI(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#notOnGUI"));
  721. const Lilv::Node oldPropTrigger(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#trigger"));
  722. if (lilvPort.has_property(oldPropArtifacts))
  723. {
  724. rdfPort->Properties |= LV2_PORT_CAUSES_ARTIFACTS;
  725. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'causesArtifacts'", uri, rdfPort->Name);
  726. }
  727. if (lilvPort.has_property(oldPropContinuousCV))
  728. {
  729. rdfPort->Properties |= LV2_PORT_CONTINUOUS_CV;
  730. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'continuousCV'", uri, rdfPort->Name);
  731. }
  732. if (lilvPort.has_property(oldPropDiscreteCV))
  733. {
  734. rdfPort->Properties |= LV2_PORT_DISCRETE_CV;
  735. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'discreteCV'", uri, rdfPort->Name);
  736. }
  737. if (lilvPort.has_property(oldPropExpensive))
  738. {
  739. rdfPort->Properties |= LV2_PORT_EXPENSIVE;
  740. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'expensive'", uri, rdfPort->Name);
  741. }
  742. if (lilvPort.has_property(oldPropStrictBounds))
  743. {
  744. rdfPort->Properties |= LV2_PORT_STRICT_BOUNDS;
  745. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'hasStrictBounds'", uri, rdfPort->Name);
  746. }
  747. if (lilvPort.has_property(oldPropLogarithmic))
  748. {
  749. rdfPort->Properties |= LV2_PORT_LOGARITHMIC;
  750. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'logarithmic'", uri, rdfPort->Name);
  751. }
  752. if (lilvPort.has_property(oldPropNotAutomatic))
  753. {
  754. rdfPort->Properties |= LV2_PORT_NOT_AUTOMATIC;
  755. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'notAutomatic'", uri, rdfPort->Name);
  756. }
  757. if (lilvPort.has_property(oldPropNotOnGUI))
  758. {
  759. rdfPort->Properties |= LV2_PORT_NOT_ON_GUI;
  760. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'notOnGUI'", uri, rdfPort->Name);
  761. }
  762. if (lilvPort.has_property(oldPropTrigger))
  763. {
  764. rdfPort->Properties |= LV2_PORT_TRIGGER;
  765. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'trigger'", uri, rdfPort->Name);
  766. }
  767. }
  768. }
  769. // -----------------------------------------------------------
  770. // Set Port Designation
  771. {
  772. if (LilvNode* const designationNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.designation.me))
  773. {
  774. if (const char* const designation = lilv_node_as_string(designationNode))
  775. {
  776. /**/ if (std::strcmp(designation, LV2_CORE__control) == 0)
  777. rdfPort->Designation = LV2_PORT_DESIGNATION_CONTROL;
  778. else if (std::strcmp(designation, LV2_CORE__freeWheeling) == 0)
  779. rdfPort->Designation = LV2_PORT_DESIGNATION_FREEWHEELING;
  780. else if (std::strcmp(designation, LV2_CORE__latency) == 0)
  781. rdfPort->Designation = LV2_PORT_DESIGNATION_LATENCY;
  782. else if (std::strcmp(designation, LV2_PARAMETERS__sampleRate) == 0)
  783. rdfPort->Designation = LV2_PORT_DESIGNATION_SAMPLE_RATE;
  784. else if (std::strcmp(designation, LV2_TIME__bar) == 0)
  785. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BAR;
  786. else if (std::strcmp(designation, LV2_TIME__barBeat) == 0)
  787. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BAR_BEAT;
  788. else if (std::strcmp(designation, LV2_TIME__beat) == 0)
  789. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEAT;
  790. else if (std::strcmp(designation, LV2_TIME__beatUnit) == 0)
  791. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEAT_UNIT;
  792. else if (std::strcmp(designation, LV2_TIME__beatsPerBar) == 0)
  793. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEATS_PER_BAR;
  794. else if (std::strcmp(designation, LV2_TIME__beatsPerMinute) == 0)
  795. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEATS_PER_MINUTE;
  796. else if (std::strcmp(designation, LV2_TIME__frame) == 0)
  797. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_FRAME;
  798. else if (std::strcmp(designation, LV2_TIME__framesPerSecond) == 0)
  799. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_FRAMES_PER_SECOND;
  800. else if (std::strcmp(designation, LV2_TIME__speed) == 0)
  801. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_SPEED;
  802. else if (std::strcmp(designation, LV2_KXSTUDIO_PROPERTIES__TimePositionTicksPerBeat) == 0)
  803. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_TICKS_PER_BEAT;
  804. else if (std::strncmp(designation, LV2_PARAMETERS_PREFIX, std::strlen(LV2_PARAMETERS_PREFIX)) == 0)
  805. pass();
  806. else if (std::strncmp(designation, LV2_PORT_GROUPS_PREFIX, std::strlen(LV2_PORT_GROUPS_PREFIX)) == 0)
  807. pass();
  808. else
  809. carla_stderr("lv2_rdf_new(\"%s\") - got unknown port designation '%s'", uri, designation);
  810. }
  811. lilv_node_free(designationNode);
  812. }
  813. }
  814. // -----------------------------------------------------------
  815. // Set Port MIDI Map
  816. {
  817. if (LilvNode* const midiMapNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.mm_defaultControl.me))
  818. {
  819. if (lilv_node_is_blank(midiMapNode))
  820. {
  821. Lilv::Nodes midiMapTypeNodes(lv2World.find_nodes(midiMapNode, lv2World.mm_controlType, nullptr));
  822. Lilv::Nodes midiMapNumberNodes(lv2World.find_nodes(midiMapNode, lv2World.mm_controlNumber, nullptr));
  823. if (midiMapTypeNodes.size() == 1 && midiMapNumberNodes.size() == 1)
  824. {
  825. if (const char* const midiMapType = midiMapTypeNodes.get_first().as_string())
  826. {
  827. /**/ if (std::strcmp(midiMapType, LV2_MIDI_Map__CC) == 0)
  828. rdfPort->MidiMap.Type = LV2_PORT_MIDI_MAP_CC;
  829. else if (std::strcmp(midiMapType, LV2_MIDI_Map__NRPN) == 0)
  830. rdfPort->MidiMap.Type = LV2_PORT_MIDI_MAP_NRPN;
  831. else
  832. carla_stderr("lv2_rdf_new(\"%s\") - got unknown port Midi-Map type '%s'", uri, midiMapType);
  833. rdfPort->MidiMap.Number = static_cast<uint32_t>(midiMapNumberNodes.get_first().as_int());
  834. }
  835. }
  836. lilv_nodes_free(const_cast<LilvNodes*>(midiMapTypeNodes.me));
  837. lilv_nodes_free(const_cast<LilvNodes*>(midiMapNumberNodes.me));
  838. }
  839. lilv_node_free(midiMapNode);
  840. }
  841. // TODO - also check using new official MIDI API too
  842. }
  843. // -----------------------------------------------------------
  844. // Set Port Points
  845. {
  846. if (LilvNode* const defNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.value_default.me))
  847. {
  848. rdfPort->Points.Hints |= LV2_PORT_POINT_DEFAULT;
  849. rdfPort->Points.Default = lilv_node_as_float(defNode);
  850. lilv_node_free(defNode);
  851. }
  852. if (LilvNode* const minNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.value_minimum.me))
  853. {
  854. rdfPort->Points.Hints |= LV2_PORT_POINT_MINIMUM;
  855. rdfPort->Points.Minimum = lilv_node_as_float(minNode);
  856. lilv_node_free(minNode);
  857. }
  858. if (LilvNode* const maxNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.value_maximum.me))
  859. {
  860. rdfPort->Points.Hints |= LV2_PORT_POINT_MAXIMUM;
  861. rdfPort->Points.Maximum = lilv_node_as_float(maxNode);
  862. lilv_node_free(maxNode);
  863. }
  864. }
  865. // -----------------------------------------------------------
  866. // Set Port Unit
  867. {
  868. if (LilvNode* const unitUnitNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.unit_unit.me))
  869. {
  870. if (lilv_node_is_uri(unitUnitNode))
  871. {
  872. if (const char* const unitUnit = lilv_node_as_uri(unitUnitNode))
  873. {
  874. rdfPort->Unit.Hints |= LV2_PORT_UNIT_UNIT;
  875. /**/ if (std::strcmp(unitUnit, LV2_UNITS__bar) == 0)
  876. rdfPort->Unit.Unit = LV2_PORT_UNIT_BAR;
  877. else if (std::strcmp(unitUnit, LV2_UNITS__beat) == 0)
  878. rdfPort->Unit.Unit = LV2_PORT_UNIT_BEAT;
  879. else if (std::strcmp(unitUnit, LV2_UNITS__bpm) == 0)
  880. rdfPort->Unit.Unit = LV2_PORT_UNIT_BPM;
  881. else if (std::strcmp(unitUnit, LV2_UNITS__cent) == 0)
  882. rdfPort->Unit.Unit = LV2_PORT_UNIT_CENT;
  883. else if (std::strcmp(unitUnit, LV2_UNITS__cm) == 0)
  884. rdfPort->Unit.Unit = LV2_PORT_UNIT_CM;
  885. else if (std::strcmp(unitUnit, LV2_UNITS__coef) == 0)
  886. rdfPort->Unit.Unit = LV2_PORT_UNIT_COEF;
  887. else if (std::strcmp(unitUnit, LV2_UNITS__db) == 0)
  888. rdfPort->Unit.Unit = LV2_PORT_UNIT_DB;
  889. else if (std::strcmp(unitUnit, LV2_UNITS__degree) == 0)
  890. rdfPort->Unit.Unit = LV2_PORT_UNIT_DEGREE;
  891. else if (std::strcmp(unitUnit, LV2_UNITS__frame) == 0)
  892. rdfPort->Unit.Unit = LV2_PORT_UNIT_FRAME;
  893. else if (std::strcmp(unitUnit, LV2_UNITS__hz) == 0)
  894. rdfPort->Unit.Unit = LV2_PORT_UNIT_HZ;
  895. else if (std::strcmp(unitUnit, LV2_UNITS__inch) == 0)
  896. rdfPort->Unit.Unit = LV2_PORT_UNIT_INCH;
  897. else if (std::strcmp(unitUnit, LV2_UNITS__khz) == 0)
  898. rdfPort->Unit.Unit = LV2_PORT_UNIT_KHZ;
  899. else if (std::strcmp(unitUnit, LV2_UNITS__km) == 0)
  900. rdfPort->Unit.Unit = LV2_PORT_UNIT_KM;
  901. else if (std::strcmp(unitUnit, LV2_UNITS__m) == 0)
  902. rdfPort->Unit.Unit = LV2_PORT_UNIT_M;
  903. else if (std::strcmp(unitUnit, LV2_UNITS__mhz) == 0)
  904. rdfPort->Unit.Unit = LV2_PORT_UNIT_MHZ;
  905. else if (std::strcmp(unitUnit, LV2_UNITS__midiNote) == 0)
  906. rdfPort->Unit.Unit = LV2_PORT_UNIT_MIDINOTE;
  907. else if (std::strcmp(unitUnit, LV2_UNITS__mile) == 0)
  908. rdfPort->Unit.Unit = LV2_PORT_UNIT_MILE;
  909. else if (std::strcmp(unitUnit, LV2_UNITS__min) == 0)
  910. rdfPort->Unit.Unit = LV2_PORT_UNIT_MIN;
  911. else if (std::strcmp(unitUnit, LV2_UNITS__mm) == 0)
  912. rdfPort->Unit.Unit = LV2_PORT_UNIT_MM;
  913. else if (std::strcmp(unitUnit, LV2_UNITS__ms) == 0)
  914. rdfPort->Unit.Unit = LV2_PORT_UNIT_MS;
  915. else if (std::strcmp(unitUnit, LV2_UNITS__oct) == 0)
  916. rdfPort->Unit.Unit = LV2_PORT_UNIT_OCT;
  917. else if (std::strcmp(unitUnit, LV2_UNITS__pc) == 0)
  918. rdfPort->Unit.Unit = LV2_PORT_UNIT_PC;
  919. else if (std::strcmp(unitUnit, LV2_UNITS__s) == 0)
  920. rdfPort->Unit.Unit = LV2_PORT_UNIT_S;
  921. else if (std::strcmp(unitUnit, LV2_UNITS__semitone12TET) == 0)
  922. rdfPort->Unit.Unit = LV2_PORT_UNIT_SEMITONE;
  923. else
  924. carla_stderr("lv2_rdf_new(\"%s\") - got unknown unit unit '%s'", uri, unitUnit);
  925. }
  926. }
  927. if (LilvNode* const unitNameNode = lilv_world_get(lv2World.me, unitUnitNode, lv2World.unit_name.me, nullptr))
  928. {
  929. if (const char* const unitName = lilv_node_as_string(unitNameNode))
  930. {
  931. rdfPort->Unit.Hints |= LV2_PORT_UNIT_NAME;
  932. rdfPort->Unit.Name = carla_strdup(unitName);
  933. }
  934. lilv_node_free(unitNameNode);
  935. }
  936. if (LilvNode* const unitRenderNode = lilv_world_get(lv2World.me, unitUnitNode, lv2World.unit_render.me, nullptr))
  937. {
  938. if (const char* const unitRender = lilv_node_as_string(unitRenderNode))
  939. {
  940. rdfPort->Unit.Hints |= LV2_PORT_UNIT_RENDER;
  941. rdfPort->Unit.Render = carla_strdup(unitRender);
  942. }
  943. lilv_node_free(unitRenderNode);
  944. }
  945. if (LilvNode* const unitSymbolNode = lilv_world_get(lv2World.me, unitUnitNode, lv2World.unit_symbol.me, nullptr))
  946. {
  947. if (const char* const unitSymbol = lilv_node_as_string(unitSymbolNode))
  948. {
  949. rdfPort->Unit.Hints |= LV2_PORT_UNIT_SYMBOL;
  950. rdfPort->Unit.Symbol = carla_strdup(unitSymbol);
  951. }
  952. lilv_node_free(unitSymbolNode);
  953. }
  954. lilv_node_free(unitUnitNode);
  955. }
  956. }
  957. // -----------------------------------------------------------
  958. // Set Port Minimum Size
  959. {
  960. if (LilvNode* const minimumSizeNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.rz_minSize.me))
  961. {
  962. const int minimumSize(lilv_node_as_int(minimumSizeNode));
  963. if (minimumSize > 0)
  964. rdfPort->MinimumSize = static_cast<uint32_t>(minimumSize);
  965. else
  966. carla_safe_assert_int("minimumSize > 0", __FILE__, __LINE__, minimumSize);
  967. lilv_node_free(minimumSizeNode);
  968. }
  969. }
  970. // -----------------------------------------------------------
  971. // Set Port Scale Points
  972. {
  973. Lilv::ScalePoints lilvScalePoints(lilvPort.get_scale_points());
  974. if (lilvScalePoints.size() > 0)
  975. {
  976. rdfPort->ScalePointCount = lilvScalePoints.size();
  977. rdfPort->ScalePoints = new LV2_RDF_PortScalePoint[rdfPort->ScalePointCount];
  978. // get all scalepoints and sort them by value
  979. LilvScalePointMap sortedpoints;
  980. LILV_FOREACH(scale_points, it, lilvScalePoints)
  981. {
  982. Lilv::ScalePoint lilvScalePoint(lilvScalePoints.get(it));
  983. CARLA_SAFE_ASSERT_CONTINUE(lilvScalePoint.get_label() != nullptr);
  984. if (const LilvNode* const valuenode = lilvScalePoint.get_value())
  985. {
  986. const double valueid = lilv_node_as_float(valuenode);
  987. sortedpoints[valueid] = lilvScalePoint.me;
  988. }
  989. }
  990. // now safe to store, sorted by using std::map
  991. uint32_t h = 0;
  992. for (LilvScalePointMap::iterator it=sortedpoints.begin(), end=sortedpoints.end(); it != end; ++it)
  993. {
  994. CARLA_SAFE_ASSERT_BREAK(h < rdfPort->ScalePointCount);
  995. LV2_RDF_PortScalePoint* const rdfScalePoint(&rdfPort->ScalePoints[h++]);
  996. const LilvScalePoint* const scalepoint = it->second;
  997. const LilvNode* const xlabel = lilv_scale_point_get_label(scalepoint);
  998. const LilvNode* const xvalue = lilv_scale_point_get_value(scalepoint);
  999. rdfScalePoint->Label = carla_strdup(lilv_node_as_string(xlabel));
  1000. rdfScalePoint->Value = lilv_node_as_float(xvalue);
  1001. }
  1002. }
  1003. lilv_nodes_free(const_cast<LilvNodes*>(lilvScalePoints.me));
  1004. }
  1005. }
  1006. }
  1007. // -------------------------------------------------------------------
  1008. // Set Plugin Presets
  1009. if (loadPresets)
  1010. {
  1011. Lilv::Nodes presetNodes(lilvPlugin.get_related(lv2World.preset_preset));
  1012. if (presetNodes.size() > 0)
  1013. {
  1014. // create a list of preset URIs (for sorting and unique-ness)
  1015. #ifdef USE_QT
  1016. QStringList presetListURIs;
  1017. LILV_FOREACH(nodes, it, presetNodes)
  1018. {
  1019. Lilv::Node presetNode(presetNodes.get(it));
  1020. QString presetURI(presetNode.as_uri());
  1021. if (! (presetURI.trimmed().isEmpty() || presetListURIs.contains(presetURI)))
  1022. presetListURIs.append(presetURI);
  1023. }
  1024. presetListURIs.sort();
  1025. rdfDescriptor->PresetCount = static_cast<uint32_t>(presetListURIs.count());
  1026. #else
  1027. juce::StringArray presetListURIs;
  1028. LILV_FOREACH(nodes, it, presetNodes)
  1029. {
  1030. Lilv::Node presetNode(presetNodes.get(it));
  1031. juce::String presetURI(presetNode.as_uri());
  1032. if (presetURI.trim().isNotEmpty())
  1033. presetListURIs.addIfNotAlreadyThere(presetURI);
  1034. }
  1035. presetListURIs.sortNatural();
  1036. rdfDescriptor->PresetCount = static_cast<uint32_t>(presetListURIs.size());
  1037. #endif
  1038. // create presets with unique URIs
  1039. rdfDescriptor->Presets = new LV2_RDF_Preset[rdfDescriptor->PresetCount];
  1040. // set preset data
  1041. LILV_FOREACH(nodes, it, presetNodes)
  1042. {
  1043. Lilv::Node presetNode(presetNodes.get(it));
  1044. const char* const presetURI(presetNode.as_uri());
  1045. CARLA_SAFE_ASSERT_CONTINUE(presetURI != nullptr && presetURI[0] != '\0');
  1046. // try to find label without loading the preset resource first
  1047. Lilv::Nodes presetLabelNodes(lv2World.find_nodes(presetNode, lv2World.rdfs_label, nullptr));
  1048. // failed, try loading resource
  1049. if (presetLabelNodes.size() == 0)
  1050. {
  1051. // if loading resource fails, skip this preset
  1052. if (lv2World.load_resource(presetNode) == -1)
  1053. continue;
  1054. // ok, let's try again
  1055. presetLabelNodes = lv2World.find_nodes(presetNode, lv2World.rdfs_label, nullptr);
  1056. }
  1057. if (presetLabelNodes.size() > 0)
  1058. {
  1059. #ifdef USE_QT
  1060. const int index(presetListURIs.indexOf(QString(presetURI)));
  1061. #else
  1062. const int index(presetListURIs.indexOf(juce::String(presetURI)));
  1063. #endif
  1064. CARLA_SAFE_ASSERT_CONTINUE(index >= 0 && index < static_cast<int>(rdfDescriptor->PresetCount));
  1065. LV2_RDF_Preset* const rdfPreset(&rdfDescriptor->Presets[index]);
  1066. // ---------------------------------------------------
  1067. // Set Preset Information
  1068. rdfPreset->URI = carla_strdup(presetURI);
  1069. if (const char* const label = presetLabelNodes.get_first().as_string())
  1070. rdfPreset->Label = carla_strdup(label);
  1071. lilv_nodes_free(const_cast<LilvNodes*>(presetLabelNodes.me));
  1072. }
  1073. }
  1074. }
  1075. lilv_nodes_free(const_cast<LilvNodes*>(presetNodes.me));
  1076. }
  1077. // -------------------------------------------------------------------
  1078. // Set Plugin Features
  1079. {
  1080. Lilv::Nodes lilvFeatureNodes(lilvPlugin.get_supported_features());
  1081. if (lilvFeatureNodes.size() > 0)
  1082. {
  1083. Lilv::Nodes lilvFeatureNodesR(lilvPlugin.get_required_features());
  1084. rdfDescriptor->FeatureCount = lilvFeatureNodes.size();
  1085. rdfDescriptor->Features = new LV2_RDF_Feature[rdfDescriptor->FeatureCount];
  1086. uint32_t h = 0;
  1087. LILV_FOREACH(nodes, it, lilvFeatureNodes)
  1088. {
  1089. CARLA_SAFE_ASSERT_BREAK(h < rdfDescriptor->FeatureCount);
  1090. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(it));
  1091. LV2_RDF_Feature* const rdfFeature(&rdfDescriptor->Features[h++]);
  1092. rdfFeature->Required = lilvFeatureNodesR.contains(lilvFeatureNode);
  1093. if (const char* const featureURI = lilvFeatureNode.as_uri())
  1094. rdfFeature->URI = carla_strdup(featureURI);
  1095. else
  1096. rdfFeature->URI = nullptr;
  1097. }
  1098. lilv_nodes_free(const_cast<LilvNodes*>(lilvFeatureNodesR.me));
  1099. }
  1100. lilv_nodes_free(const_cast<LilvNodes*>(lilvFeatureNodes.me));
  1101. }
  1102. // -------------------------------------------------------------------
  1103. // Set Plugin Extensions
  1104. {
  1105. Lilv::Nodes lilvExtensionDataNodes(lilvPlugin.get_extension_data());
  1106. if (lilvExtensionDataNodes.size() > 0)
  1107. {
  1108. rdfDescriptor->ExtensionCount = lilvExtensionDataNodes.size();
  1109. rdfDescriptor->Extensions = new LV2_URI[rdfDescriptor->ExtensionCount];
  1110. uint32_t h = 0;
  1111. LILV_FOREACH(nodes, it, lilvExtensionDataNodes)
  1112. {
  1113. CARLA_SAFE_ASSERT_BREAK(h < rdfDescriptor->ExtensionCount);
  1114. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(it));
  1115. LV2_URI* const rdfExtension(&rdfDescriptor->Extensions[h++]);
  1116. if (lilvExtensionDataNode.is_uri())
  1117. {
  1118. if (const char* const extURI = lilvExtensionDataNode.as_uri())
  1119. {
  1120. *rdfExtension = carla_strdup(extURI);
  1121. continue;
  1122. }
  1123. }
  1124. *rdfExtension = nullptr;
  1125. }
  1126. for (uint32_t x=h; x < rdfDescriptor->ExtensionCount; ++x)
  1127. rdfDescriptor->Extensions[x] = nullptr;
  1128. }
  1129. lilv_nodes_free(const_cast<LilvNodes*>(lilvExtensionDataNodes.me));
  1130. }
  1131. // -------------------------------------------------------------------
  1132. // Set Plugin UIs
  1133. {
  1134. const bool hasMODGui(lilvPlugin.get_modgui_resources_directory().as_uri() != nullptr);
  1135. Lilv::UIs lilvUIs(lilvPlugin.get_uis());
  1136. if (lilvUIs.size() > 0 || hasMODGui)
  1137. {
  1138. rdfDescriptor->UICount = lilvUIs.size() + (hasMODGui ? 1 : 0);
  1139. rdfDescriptor->UIs = new LV2_RDF_UI[rdfDescriptor->UICount];
  1140. uint32_t h = 0;
  1141. LILV_FOREACH(uis, it, lilvUIs)
  1142. {
  1143. CARLA_SAFE_ASSERT_BREAK(h < rdfDescriptor->UICount);
  1144. Lilv::UI lilvUI(lilvUIs.get(it));
  1145. LV2_RDF_UI* const rdfUI(&rdfDescriptor->UIs[h++]);
  1146. // -------------------------------------------------------
  1147. // Set UI Type
  1148. /**/ if (lilvUI.is_a(lv2World.ui_gtk2))
  1149. rdfUI->Type = LV2_UI_GTK2;
  1150. else if (lilvUI.is_a(lv2World.ui_gtk3))
  1151. rdfUI->Type = LV2_UI_GTK3;
  1152. else if (lilvUI.is_a(lv2World.ui_qt4))
  1153. rdfUI->Type = LV2_UI_QT4;
  1154. else if (lilvUI.is_a(lv2World.ui_qt5))
  1155. rdfUI->Type = LV2_UI_QT5;
  1156. else if (lilvUI.is_a(lv2World.ui_cocoa))
  1157. rdfUI->Type = LV2_UI_COCOA;
  1158. else if (lilvUI.is_a(lv2World.ui_windows))
  1159. rdfUI->Type = LV2_UI_WINDOWS;
  1160. else if (lilvUI.is_a(lv2World.ui_x11))
  1161. rdfUI->Type = LV2_UI_X11;
  1162. else if (lilvUI.is_a(lv2World.ui_external))
  1163. rdfUI->Type = LV2_UI_EXTERNAL;
  1164. else if (lilvUI.is_a(lv2World.ui_externalOld))
  1165. rdfUI->Type = LV2_UI_OLD_EXTERNAL;
  1166. else if (lilvUI.is_a(lv2World.ui_externalOld2))
  1167. pass();
  1168. else
  1169. carla_stderr("lv2_rdf_new(\"%s\") - UI '%s' is of unknown type", uri, lilvUI.get_uri().as_uri());
  1170. // -------------------------------------------------------
  1171. // Set UI Information
  1172. {
  1173. if (const char* const uiURI = lilvUI.get_uri().as_uri())
  1174. rdfUI->URI = carla_strdup(uiURI);
  1175. if (const char* const uiBinary = lilvUI.get_binary_uri().as_string())
  1176. rdfUI->Binary = carla_strdup_free(lilv_file_uri_parse(uiBinary, nullptr));
  1177. if (const char* const uiBundle = lilvUI.get_bundle_uri().as_string())
  1178. rdfUI->Bundle = carla_strdup_free(lilv_file_uri_parse(uiBundle, nullptr));
  1179. }
  1180. // -------------------------------------------------------
  1181. // Set UI Features
  1182. {
  1183. Lilv::Nodes lilvFeatureNodes(lilvUI.get_supported_features());
  1184. if (lilvFeatureNodes.size() > 0)
  1185. {
  1186. Lilv::Nodes lilvFeatureNodesR(lilvUI.get_required_features());
  1187. rdfUI->FeatureCount = lilvFeatureNodes.size();
  1188. rdfUI->Features = new LV2_RDF_Feature[rdfUI->FeatureCount];
  1189. uint32_t h2 = 0;
  1190. LILV_FOREACH(nodes, it2, lilvFeatureNodes)
  1191. {
  1192. CARLA_SAFE_ASSERT_BREAK(h2 < rdfUI->FeatureCount);
  1193. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(it2));
  1194. LV2_RDF_Feature* const rdfFeature(&rdfUI->Features[h2++]);
  1195. rdfFeature->Required = lilvFeatureNodesR.contains(lilvFeatureNode);
  1196. if (const char* const featureURI = lilvFeatureNode.as_uri())
  1197. rdfFeature->URI = carla_strdup(featureURI);
  1198. else
  1199. rdfFeature->URI = nullptr;
  1200. }
  1201. lilv_nodes_free(const_cast<LilvNodes*>(lilvFeatureNodesR.me));
  1202. }
  1203. lilv_nodes_free(const_cast<LilvNodes*>(lilvFeatureNodes.me));
  1204. }
  1205. // -------------------------------------------------------
  1206. // Set UI Extensions
  1207. {
  1208. Lilv::Nodes lilvExtensionDataNodes(lilvUI.get_extension_data());
  1209. if (lilvExtensionDataNodes.size() > 0)
  1210. {
  1211. rdfUI->ExtensionCount = lilvExtensionDataNodes.size();
  1212. rdfUI->Extensions = new LV2_URI[rdfUI->ExtensionCount];
  1213. uint32_t h2 = 0;
  1214. LILV_FOREACH(nodes, it2, lilvExtensionDataNodes)
  1215. {
  1216. CARLA_SAFE_ASSERT_BREAK(h2 < rdfUI->ExtensionCount);
  1217. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(it2));
  1218. LV2_URI* const rdfExtension(&rdfUI->Extensions[h2++]);
  1219. if (lilvExtensionDataNode.is_uri())
  1220. {
  1221. if (const char* const extURI = lilvExtensionDataNode.as_uri())
  1222. {
  1223. *rdfExtension = carla_strdup(extURI);
  1224. continue;
  1225. }
  1226. }
  1227. *rdfExtension = nullptr;
  1228. }
  1229. for (uint32_t x2=h2; x2 < rdfUI->ExtensionCount; ++x2)
  1230. rdfUI->Extensions[x2] = nullptr;
  1231. }
  1232. lilv_nodes_free(const_cast<LilvNodes*>(lilvExtensionDataNodes.me));
  1233. }
  1234. }
  1235. for (; hasMODGui;)
  1236. {
  1237. CARLA_SAFE_ASSERT_BREAK(h == rdfDescriptor->UICount-1);
  1238. LV2_RDF_UI* const rdfUI(&rdfDescriptor->UIs[h++]);
  1239. // -------------------------------------------------------
  1240. // Set UI Type
  1241. rdfUI->Type = LV2_UI_MOD;
  1242. // -------------------------------------------------------
  1243. // Set UI Information
  1244. if (const char* const resDir = lilvPlugin.get_modgui_resources_directory().as_uri())
  1245. rdfUI->URI = carla_strdup_free(lilv_file_uri_parse(resDir, nullptr));
  1246. if (rdfDescriptor->Bundle != nullptr)
  1247. rdfUI->Bundle = carla_strdup(rdfDescriptor->Bundle);
  1248. break;
  1249. }
  1250. }
  1251. lilv_nodes_free(const_cast<LilvNodes*>(lilvUIs.me));
  1252. }
  1253. return rdfDescriptor;
  1254. }
  1255. // -----------------------------------------------------------------------
  1256. // Check if we support a plugin port
  1257. static inline
  1258. bool is_lv2_port_supported(const LV2_Property types) noexcept
  1259. {
  1260. if (LV2_IS_PORT_CONTROL(types))
  1261. return true;
  1262. if (LV2_IS_PORT_AUDIO(types))
  1263. return true;
  1264. if (LV2_IS_PORT_CV(types))
  1265. return true;
  1266. if (LV2_IS_PORT_ATOM_SEQUENCE(types))
  1267. return true;
  1268. if (LV2_IS_PORT_EVENT(types))
  1269. return true;
  1270. if (LV2_IS_PORT_MIDI_LL(types))
  1271. return true;
  1272. return false;
  1273. }
  1274. // -----------------------------------------------------------------------
  1275. // Check if we support a plugin feature
  1276. static inline
  1277. bool is_lv2_feature_supported(const LV2_URI uri) noexcept
  1278. {
  1279. CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0', false);
  1280. if (std::strcmp(uri, LV2_BUF_SIZE__boundedBlockLength) == 0)
  1281. return true;
  1282. if (std::strcmp(uri, LV2_BUF_SIZE__fixedBlockLength) == 0)
  1283. return true;
  1284. if (std::strcmp(uri, LV2_BUF_SIZE__powerOf2BlockLength) == 0)
  1285. return true;
  1286. if (std::strcmp(uri, LV2_CORE__hardRTCapable) == 0)
  1287. return true;
  1288. if (std::strcmp(uri, LV2_CORE__inPlaceBroken) == 0)
  1289. return true;
  1290. if (std::strcmp(uri, LV2_CORE__isLive) == 0)
  1291. return true;
  1292. if (std::strcmp(uri, LV2_EVENT_URI) == 0)
  1293. return true;
  1294. if (std::strcmp(uri, LV2_LOG__log) == 0)
  1295. return true;
  1296. if (std::strcmp(uri, LV2_OPTIONS__options) == 0)
  1297. return true;
  1298. if (std::strcmp(uri, LV2_PROGRAMS__Host) == 0)
  1299. return true;
  1300. if (std::strcmp(uri, LV2_RESIZE_PORT__resize) == 0)
  1301. return true;
  1302. if (std::strcmp(uri, LV2_RTSAFE_MEMORY_POOL__Pool) == 0)
  1303. return true;
  1304. if (std::strcmp(uri, LV2_RTSAFE_MEMORY_POOL_DEPRECATED_URI) == 0)
  1305. return true;
  1306. if (std::strcmp(uri, LV2_STATE__loadDefaultState) == 0)
  1307. return true;
  1308. if (std::strcmp(uri, LV2_STATE__makePath) == 0)
  1309. return true;
  1310. if (std::strcmp(uri, LV2_STATE__mapPath) == 0)
  1311. return true;
  1312. if (std::strcmp(uri, LV2_PORT_PROPS__supportsStrictBounds) == 0)
  1313. return true;
  1314. if (std::strcmp(uri, LV2_URI_MAP_URI) == 0)
  1315. return true;
  1316. if (std::strcmp(uri, LV2_URID__map) == 0)
  1317. return true;
  1318. if (std::strcmp(uri, LV2_URID__unmap) == 0)
  1319. return true;
  1320. if (std::strcmp(uri, LV2_WORKER__schedule) == 0)
  1321. return true;
  1322. return false;
  1323. }
  1324. // -----------------------------------------------------------------------
  1325. // Check if we support a plugin or UI feature
  1326. static inline
  1327. bool is_lv2_ui_feature_supported(const LV2_URI uri) noexcept
  1328. {
  1329. CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0', false);
  1330. if (is_lv2_feature_supported(uri))
  1331. return true;
  1332. #ifndef BUILD_BRIDGE_UI
  1333. if (std::strcmp(uri, LV2_DATA_ACCESS_URI) == 0)
  1334. return true;
  1335. if (std::strcmp(uri, LV2_INSTANCE_ACCESS_URI) == 0)
  1336. return true;
  1337. #endif
  1338. if (std::strcmp(uri, LV2_UI__fixedSize) == 0)
  1339. return true;
  1340. if (std::strcmp(uri, LV2_UI__idleInterface) == 0)
  1341. return true;
  1342. if (std::strcmp(uri, LV2_UI__makeResident) == 0)
  1343. return true;
  1344. if (std::strcmp(uri, LV2_UI__makeSONameResident) == 0)
  1345. return true;
  1346. if (std::strcmp(uri, LV2_UI__noUserResize) == 0)
  1347. return true;
  1348. if (std::strcmp(uri, LV2_UI__parent) == 0)
  1349. return true;
  1350. if (std::strcmp(uri, LV2_UI__portMap) == 0)
  1351. return true;
  1352. if (std::strcmp(uri, LV2_UI__portSubscribe) == 0)
  1353. return true;
  1354. if (std::strcmp(uri, LV2_UI__resize) == 0)
  1355. return true;
  1356. if (std::strcmp(uri, LV2_UI__touch) == 0)
  1357. return true;
  1358. if (std::strcmp(uri, LV2_EXTERNAL_UI__Widget) == 0)
  1359. return true;
  1360. if (std::strcmp(uri, LV2_EXTERNAL_UI_DEPRECATED_URI) == 0)
  1361. return true;
  1362. return false;
  1363. }
  1364. // -----------------------------------------------------------------------
  1365. #endif // CARLA_LV2_UTILS_HPP_INCLUDED