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.

1587 lines
67KB

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