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.

1584 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 (const char* const name = lilvPlugin.get_name().as_string())
  510. rdfDescriptor->Name = carla_strdup(name);
  511. if (const char* const author = lilvPlugin.get_author_name().as_string())
  512. rdfDescriptor->Author = carla_strdup(author);
  513. if (const char* const binary = lilvPlugin.get_library_uri().as_string())
  514. rdfDescriptor->Binary = carla_strdup_free(lilv_file_uri_parse(binary, nullptr));
  515. if (const char* const bundle = lilvPlugin.get_bundle_uri().as_string())
  516. rdfDescriptor->Bundle = carla_strdup_free(lilv_file_uri_parse(bundle, nullptr));
  517. Lilv::Nodes licenseNodes(lilvPlugin.get_value(lv2World.doap_license));
  518. if (licenseNodes.size() > 0)
  519. {
  520. if (const char* const license = licenseNodes.get_first().as_string())
  521. rdfDescriptor->License = carla_strdup(license);
  522. }
  523. lilv_nodes_free(const_cast<LilvNodes*>(licenseNodes.me));
  524. }
  525. // -------------------------------------------------------------------
  526. // Set Plugin UniqueID
  527. {
  528. Lilv::Nodes replaceNodes(lilvPlugin.get_value(lv2World.dct_replaces));
  529. if (replaceNodes.size() > 0)
  530. {
  531. Lilv::Node replaceNode(replaceNodes.get_first());
  532. if (replaceNode.is_uri())
  533. {
  534. #ifdef USE_QT
  535. const QString replaceURI(replaceNode.as_uri());
  536. if (replaceURI.startsWith("urn:"))
  537. {
  538. const QString replaceId(replaceURI.split(":").last());
  539. bool ok;
  540. const ulong uniqueId(replaceId.toULong(&ok));
  541. if (ok && uniqueId != 0)
  542. rdfDescriptor->UniqueID = uniqueId;
  543. }
  544. #else
  545. const juce::String replaceURI(replaceNode.as_uri());
  546. if (replaceURI.startsWith("urn:"))
  547. {
  548. const int uniqueId(replaceURI.getTrailingIntValue());
  549. if (uniqueId > 0)
  550. rdfDescriptor->UniqueID = static_cast<ulong>(uniqueId);
  551. }
  552. #endif
  553. }
  554. }
  555. lilv_nodes_free(const_cast<LilvNodes*>(replaceNodes.me));
  556. }
  557. // -------------------------------------------------------------------
  558. // Set Plugin Ports
  559. if (lilvPlugin.get_num_ports() > 0)
  560. {
  561. rdfDescriptor->PortCount = lilvPlugin.get_num_ports();
  562. rdfDescriptor->Ports = new LV2_RDF_Port[rdfDescriptor->PortCount];
  563. for (uint32_t i = 0; i < rdfDescriptor->PortCount; ++i)
  564. {
  565. Lilv::Port lilvPort(lilvPlugin.get_port_by_index(i));
  566. LV2_RDF_Port* const rdfPort(&rdfDescriptor->Ports[i]);
  567. // -----------------------------------------------------------
  568. // Set Port Information
  569. {
  570. if (const char* const name = Lilv::Node(lilvPort.get_name()).as_string())
  571. rdfPort->Name = carla_strdup(name);
  572. if (const char* const symbol = Lilv::Node(lilvPort.get_symbol()).as_string())
  573. rdfPort->Symbol = carla_strdup(symbol);
  574. }
  575. // -----------------------------------------------------------
  576. // Set Port Mode and Type
  577. {
  578. // Input or Output
  579. /**/ if (lilvPort.is_a(lv2World.port_input))
  580. rdfPort->Types |= LV2_PORT_INPUT;
  581. else if (lilvPort.is_a(lv2World.port_output))
  582. rdfPort->Types |= LV2_PORT_OUTPUT;
  583. else
  584. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is not input or output", uri, rdfPort->Name);
  585. // Data Type
  586. /**/ if (lilvPort.is_a(lv2World.port_control))
  587. {
  588. rdfPort->Types |= LV2_PORT_CONTROL;
  589. }
  590. else if (lilvPort.is_a(lv2World.port_audio))
  591. {
  592. rdfPort->Types |= LV2_PORT_AUDIO;
  593. }
  594. else if (lilvPort.is_a(lv2World.port_cv))
  595. {
  596. rdfPort->Types |= LV2_PORT_CV;
  597. }
  598. else if (lilvPort.is_a(lv2World.port_atom))
  599. {
  600. rdfPort->Types |= LV2_PORT_ATOM;
  601. Lilv::Nodes bufferTypeNodes(lilvPort.get_value(lv2World.atom_bufferType));
  602. for (LilvIter* it = lilv_nodes_begin(bufferTypeNodes.me); ! lilv_nodes_is_end(bufferTypeNodes.me, it); it = lilv_nodes_next(bufferTypeNodes.me, it))
  603. {
  604. const Lilv::Node node(lilv_nodes_get(bufferTypeNodes.me, it));
  605. CARLA_SAFE_ASSERT_CONTINUE(node.is_uri());
  606. if (node.equals(lv2World.atom_sequence))
  607. rdfPort->Types |= LV2_PORT_ATOM_SEQUENCE;
  608. else
  609. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses an unknown atom buffer type '%s'", uri, rdfPort->Name, node.as_uri());
  610. }
  611. Lilv::Nodes supportNodes(lilvPort.get_value(lv2World.atom_supports));
  612. for (LilvIter* it = lilv_nodes_begin(supportNodes.me); ! lilv_nodes_is_end(supportNodes.me, it); it = lilv_nodes_next(supportNodes.me, it))
  613. {
  614. const Lilv::Node node(lilv_nodes_get(supportNodes.me, it));
  615. CARLA_SAFE_ASSERT_CONTINUE(node.is_uri());
  616. /**/ if (node.equals(lv2World.midi_event))
  617. rdfPort->Types |= LV2_PORT_DATA_MIDI_EVENT;
  618. else if (node.equals(lv2World.patch_message))
  619. rdfPort->Types |= LV2_PORT_DATA_PATCH_MESSAGE;
  620. else if (node.equals(lv2World.time_position))
  621. rdfPort->Types |= LV2_PORT_DATA_TIME_POSITION;
  622. #if 0
  623. // something new we don't support yet?
  624. else if (std::strstr(node.as_uri(), "lv2plug.in/") != nullptr)
  625. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is of atom type but has unsupported data '%s'", uri, rdfPort->Name, node.as_uri());
  626. #endif
  627. }
  628. lilv_nodes_free(const_cast<LilvNodes*>(bufferTypeNodes.me));
  629. lilv_nodes_free(const_cast<LilvNodes*>(supportNodes.me));
  630. }
  631. else if (lilvPort.is_a(lv2World.port_event))
  632. {
  633. rdfPort->Types |= LV2_PORT_EVENT;
  634. bool supported = false;
  635. if (lilvPort.supports_event(lv2World.midi_event))
  636. {
  637. rdfPort->Types |= LV2_PORT_DATA_MIDI_EVENT;
  638. supported = true;
  639. }
  640. if (lilvPort.supports_event(lv2World.patch_message))
  641. {
  642. rdfPort->Types |= LV2_PORT_DATA_PATCH_MESSAGE;
  643. supported = true;
  644. }
  645. if (lilvPort.supports_event(lv2World.time_position))
  646. {
  647. rdfPort->Types |= LV2_PORT_DATA_TIME_POSITION;
  648. supported = true;
  649. }
  650. if (! supported)
  651. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is of event type but has unsupported data", uri, rdfPort->Name);
  652. }
  653. else if (lilvPort.is_a(lv2World.port_midi))
  654. {
  655. rdfPort->Types |= LV2_PORT_MIDI_LL;
  656. rdfPort->Types |= LV2_PORT_DATA_MIDI_EVENT;
  657. }
  658. else
  659. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is of unkown data type", uri, rdfPort->Name);
  660. }
  661. // -----------------------------------------------------------
  662. // Set Port Properties
  663. {
  664. if (lilvPort.has_property(lv2World.pprop_optional))
  665. rdfPort->Properties |= LV2_PORT_OPTIONAL;
  666. if (lilvPort.has_property(lv2World.pprop_enumeration))
  667. rdfPort->Properties |= LV2_PORT_ENUMERATION;
  668. if (lilvPort.has_property(lv2World.pprop_integer))
  669. rdfPort->Properties |= LV2_PORT_INTEGER;
  670. if (lilvPort.has_property(lv2World.pprop_sampleRate))
  671. rdfPort->Properties |= LV2_PORT_SAMPLE_RATE;
  672. if (lilvPort.has_property(lv2World.pprop_toggled))
  673. rdfPort->Properties |= LV2_PORT_TOGGLED;
  674. if (lilvPort.has_property(lv2World.pprop_artifacts))
  675. rdfPort->Properties |= LV2_PORT_CAUSES_ARTIFACTS;
  676. if (lilvPort.has_property(lv2World.pprop_continuousCV))
  677. rdfPort->Properties |= LV2_PORT_CONTINUOUS_CV;
  678. if (lilvPort.has_property(lv2World.pprop_discreteCV))
  679. rdfPort->Properties |= LV2_PORT_DISCRETE_CV;
  680. if (lilvPort.has_property(lv2World.pprop_expensive))
  681. rdfPort->Properties |= LV2_PORT_EXPENSIVE;
  682. if (lilvPort.has_property(lv2World.pprop_strictBounds))
  683. rdfPort->Properties |= LV2_PORT_STRICT_BOUNDS;
  684. if (lilvPort.has_property(lv2World.pprop_logarithmic))
  685. rdfPort->Properties |= LV2_PORT_LOGARITHMIC;
  686. if (lilvPort.has_property(lv2World.pprop_notAutomatic))
  687. rdfPort->Properties |= LV2_PORT_NOT_AUTOMATIC;
  688. if (lilvPort.has_property(lv2World.pprop_notOnGUI))
  689. rdfPort->Properties |= LV2_PORT_NOT_ON_GUI;
  690. if (lilvPort.has_property(lv2World.pprop_trigger))
  691. rdfPort->Properties |= LV2_PORT_TRIGGER;
  692. if (lilvPort.has_property(lv2World.pprop_nonAutomable))
  693. rdfPort->Properties |= LV2_PORT_NON_AUTOMABLE;
  694. if (lilvPort.has_property(lv2World.reportsLatency))
  695. rdfPort->Designation = LV2_PORT_DESIGNATION_LATENCY;
  696. // no port properties set, check if using old/invalid ones
  697. if (rdfPort->Properties == 0x0)
  698. {
  699. const Lilv::Node oldPropArtifacts(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#causesArtifacts"));
  700. const Lilv::Node oldPropContinuousCV(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#continuousCV"));
  701. const Lilv::Node oldPropDiscreteCV(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#discreteCV"));
  702. const Lilv::Node oldPropExpensive(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#expensive"));
  703. const Lilv::Node oldPropStrictBounds(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#hasStrictBounds"));
  704. const Lilv::Node oldPropLogarithmic(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#logarithmic"));
  705. const Lilv::Node oldPropNotAutomatic(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#notAutomatic"));
  706. const Lilv::Node oldPropNotOnGUI(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#notOnGUI"));
  707. const Lilv::Node oldPropTrigger(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#trigger"));
  708. if (lilvPort.has_property(oldPropArtifacts))
  709. {
  710. rdfPort->Properties |= LV2_PORT_CAUSES_ARTIFACTS;
  711. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'causesArtifacts'", uri, rdfPort->Name);
  712. }
  713. if (lilvPort.has_property(oldPropContinuousCV))
  714. {
  715. rdfPort->Properties |= LV2_PORT_CONTINUOUS_CV;
  716. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'continuousCV'", uri, rdfPort->Name);
  717. }
  718. if (lilvPort.has_property(oldPropDiscreteCV))
  719. {
  720. rdfPort->Properties |= LV2_PORT_DISCRETE_CV;
  721. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'discreteCV'", uri, rdfPort->Name);
  722. }
  723. if (lilvPort.has_property(oldPropExpensive))
  724. {
  725. rdfPort->Properties |= LV2_PORT_EXPENSIVE;
  726. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'expensive'", uri, rdfPort->Name);
  727. }
  728. if (lilvPort.has_property(oldPropStrictBounds))
  729. {
  730. rdfPort->Properties |= LV2_PORT_STRICT_BOUNDS;
  731. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'hasStrictBounds'", uri, rdfPort->Name);
  732. }
  733. if (lilvPort.has_property(oldPropLogarithmic))
  734. {
  735. rdfPort->Properties |= LV2_PORT_LOGARITHMIC;
  736. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'logarithmic'", uri, rdfPort->Name);
  737. }
  738. if (lilvPort.has_property(oldPropNotAutomatic))
  739. {
  740. rdfPort->Properties |= LV2_PORT_NOT_AUTOMATIC;
  741. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'notAutomatic'", uri, rdfPort->Name);
  742. }
  743. if (lilvPort.has_property(oldPropNotOnGUI))
  744. {
  745. rdfPort->Properties |= LV2_PORT_NOT_ON_GUI;
  746. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'notOnGUI'", uri, rdfPort->Name);
  747. }
  748. if (lilvPort.has_property(oldPropTrigger))
  749. {
  750. rdfPort->Properties |= LV2_PORT_TRIGGER;
  751. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'trigger'", uri, rdfPort->Name);
  752. }
  753. }
  754. }
  755. // -----------------------------------------------------------
  756. // Set Port Designation
  757. {
  758. if (LilvNode* const designationNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.designation.me))
  759. {
  760. if (const char* const designation = lilv_node_as_string(designationNode))
  761. {
  762. /**/ if (std::strcmp(designation, LV2_CORE__control) == 0)
  763. rdfPort->Designation = LV2_PORT_DESIGNATION_CONTROL;
  764. else if (std::strcmp(designation, LV2_CORE__freeWheeling) == 0)
  765. rdfPort->Designation = LV2_PORT_DESIGNATION_FREEWHEELING;
  766. else if (std::strcmp(designation, LV2_CORE__latency) == 0)
  767. rdfPort->Designation = LV2_PORT_DESIGNATION_LATENCY;
  768. else if (std::strcmp(designation, LV2_PARAMETERS__sampleRate) == 0)
  769. rdfPort->Designation = LV2_PORT_DESIGNATION_SAMPLE_RATE;
  770. else if (std::strcmp(designation, LV2_TIME__bar) == 0)
  771. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BAR;
  772. else if (std::strcmp(designation, LV2_TIME__barBeat) == 0)
  773. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BAR_BEAT;
  774. else if (std::strcmp(designation, LV2_TIME__beat) == 0)
  775. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEAT;
  776. else if (std::strcmp(designation, LV2_TIME__beatUnit) == 0)
  777. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEAT_UNIT;
  778. else if (std::strcmp(designation, LV2_TIME__beatsPerBar) == 0)
  779. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEATS_PER_BAR;
  780. else if (std::strcmp(designation, LV2_TIME__beatsPerMinute) == 0)
  781. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEATS_PER_MINUTE;
  782. else if (std::strcmp(designation, LV2_TIME__frame) == 0)
  783. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_FRAME;
  784. else if (std::strcmp(designation, LV2_TIME__framesPerSecond) == 0)
  785. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_FRAMES_PER_SECOND;
  786. else if (std::strcmp(designation, LV2_TIME__speed) == 0)
  787. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_SPEED;
  788. else if (std::strcmp(designation, LV2_KXSTUDIO_PROPERTIES__TimePositionTicksPerBeat) == 0)
  789. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_TICKS_PER_BEAT;
  790. else if (std::strncmp(designation, LV2_PARAMETERS_PREFIX, std::strlen(LV2_PARAMETERS_PREFIX)) == 0)
  791. pass();
  792. else if (std::strncmp(designation, LV2_PORT_GROUPS_PREFIX, std::strlen(LV2_PORT_GROUPS_PREFIX)) == 0)
  793. pass();
  794. else
  795. carla_stderr("lv2_rdf_new(\"%s\") - got unknown port designation '%s'", uri, designation);
  796. }
  797. lilv_node_free(designationNode);
  798. }
  799. }
  800. // -----------------------------------------------------------
  801. // Set Port MIDI Map
  802. {
  803. if (LilvNode* const midiMapNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.mm_defaultControl.me))
  804. {
  805. if (lilv_node_is_blank(midiMapNode))
  806. {
  807. Lilv::Nodes midiMapTypeNodes(lv2World.find_nodes(midiMapNode, lv2World.mm_controlType, nullptr));
  808. Lilv::Nodes midiMapNumberNodes(lv2World.find_nodes(midiMapNode, lv2World.mm_controlNumber, nullptr));
  809. if (midiMapTypeNodes.size() == 1 && midiMapNumberNodes.size() == 1)
  810. {
  811. if (const char* const midiMapType = midiMapTypeNodes.get_first().as_string())
  812. {
  813. /**/ if (std::strcmp(midiMapType, LV2_MIDI_Map__CC) == 0)
  814. rdfPort->MidiMap.Type = LV2_PORT_MIDI_MAP_CC;
  815. else if (std::strcmp(midiMapType, LV2_MIDI_Map__NRPN) == 0)
  816. rdfPort->MidiMap.Type = LV2_PORT_MIDI_MAP_NRPN;
  817. else
  818. carla_stderr("lv2_rdf_new(\"%s\") - got unknown port Midi-Map type '%s'", uri, midiMapType);
  819. rdfPort->MidiMap.Number = static_cast<uint32_t>(midiMapNumberNodes.get_first().as_int());
  820. }
  821. }
  822. lilv_nodes_free(const_cast<LilvNodes*>(midiMapTypeNodes.me));
  823. lilv_nodes_free(const_cast<LilvNodes*>(midiMapNumberNodes.me));
  824. }
  825. lilv_node_free(midiMapNode);
  826. }
  827. // TODO - also check using new official MIDI API too
  828. }
  829. // -----------------------------------------------------------
  830. // Set Port Points
  831. {
  832. if (LilvNode* const defNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.value_default.me))
  833. {
  834. rdfPort->Points.Hints |= LV2_PORT_POINT_DEFAULT;
  835. rdfPort->Points.Default = lilv_node_as_float(defNode);
  836. lilv_node_free(defNode);
  837. }
  838. if (LilvNode* const minNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.value_minimum.me))
  839. {
  840. rdfPort->Points.Hints |= LV2_PORT_POINT_MINIMUM;
  841. rdfPort->Points.Minimum = lilv_node_as_float(minNode);
  842. lilv_node_free(minNode);
  843. }
  844. if (LilvNode* const maxNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.value_maximum.me))
  845. {
  846. rdfPort->Points.Hints |= LV2_PORT_POINT_MAXIMUM;
  847. rdfPort->Points.Maximum = lilv_node_as_float(maxNode);
  848. lilv_node_free(maxNode);
  849. }
  850. }
  851. // -----------------------------------------------------------
  852. // Set Port Unit
  853. {
  854. if (LilvNode* const unitUnitNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.unit_unit.me))
  855. {
  856. if (lilv_node_is_uri(unitUnitNode))
  857. {
  858. if (const char* const unitUnit = lilv_node_as_uri(unitUnitNode))
  859. {
  860. rdfPort->Unit.Hints |= LV2_PORT_UNIT_UNIT;
  861. /**/ if (std::strcmp(unitUnit, LV2_UNITS__bar) == 0)
  862. rdfPort->Unit.Unit = LV2_PORT_UNIT_BAR;
  863. else if (std::strcmp(unitUnit, LV2_UNITS__beat) == 0)
  864. rdfPort->Unit.Unit = LV2_PORT_UNIT_BEAT;
  865. else if (std::strcmp(unitUnit, LV2_UNITS__bpm) == 0)
  866. rdfPort->Unit.Unit = LV2_PORT_UNIT_BPM;
  867. else if (std::strcmp(unitUnit, LV2_UNITS__cent) == 0)
  868. rdfPort->Unit.Unit = LV2_PORT_UNIT_CENT;
  869. else if (std::strcmp(unitUnit, LV2_UNITS__cm) == 0)
  870. rdfPort->Unit.Unit = LV2_PORT_UNIT_CM;
  871. else if (std::strcmp(unitUnit, LV2_UNITS__coef) == 0)
  872. rdfPort->Unit.Unit = LV2_PORT_UNIT_COEF;
  873. else if (std::strcmp(unitUnit, LV2_UNITS__db) == 0)
  874. rdfPort->Unit.Unit = LV2_PORT_UNIT_DB;
  875. else if (std::strcmp(unitUnit, LV2_UNITS__degree) == 0)
  876. rdfPort->Unit.Unit = LV2_PORT_UNIT_DEGREE;
  877. else if (std::strcmp(unitUnit, LV2_UNITS__frame) == 0)
  878. rdfPort->Unit.Unit = LV2_PORT_UNIT_FRAME;
  879. else if (std::strcmp(unitUnit, LV2_UNITS__hz) == 0)
  880. rdfPort->Unit.Unit = LV2_PORT_UNIT_HZ;
  881. else if (std::strcmp(unitUnit, LV2_UNITS__inch) == 0)
  882. rdfPort->Unit.Unit = LV2_PORT_UNIT_INCH;
  883. else if (std::strcmp(unitUnit, LV2_UNITS__khz) == 0)
  884. rdfPort->Unit.Unit = LV2_PORT_UNIT_KHZ;
  885. else if (std::strcmp(unitUnit, LV2_UNITS__km) == 0)
  886. rdfPort->Unit.Unit = LV2_PORT_UNIT_KM;
  887. else if (std::strcmp(unitUnit, LV2_UNITS__m) == 0)
  888. rdfPort->Unit.Unit = LV2_PORT_UNIT_M;
  889. else if (std::strcmp(unitUnit, LV2_UNITS__mhz) == 0)
  890. rdfPort->Unit.Unit = LV2_PORT_UNIT_MHZ;
  891. else if (std::strcmp(unitUnit, LV2_UNITS__midiNote) == 0)
  892. rdfPort->Unit.Unit = LV2_PORT_UNIT_MIDINOTE;
  893. else if (std::strcmp(unitUnit, LV2_UNITS__mile) == 0)
  894. rdfPort->Unit.Unit = LV2_PORT_UNIT_MILE;
  895. else if (std::strcmp(unitUnit, LV2_UNITS__min) == 0)
  896. rdfPort->Unit.Unit = LV2_PORT_UNIT_MIN;
  897. else if (std::strcmp(unitUnit, LV2_UNITS__mm) == 0)
  898. rdfPort->Unit.Unit = LV2_PORT_UNIT_MM;
  899. else if (std::strcmp(unitUnit, LV2_UNITS__ms) == 0)
  900. rdfPort->Unit.Unit = LV2_PORT_UNIT_MS;
  901. else if (std::strcmp(unitUnit, LV2_UNITS__oct) == 0)
  902. rdfPort->Unit.Unit = LV2_PORT_UNIT_OCT;
  903. else if (std::strcmp(unitUnit, LV2_UNITS__pc) == 0)
  904. rdfPort->Unit.Unit = LV2_PORT_UNIT_PC;
  905. else if (std::strcmp(unitUnit, LV2_UNITS__s) == 0)
  906. rdfPort->Unit.Unit = LV2_PORT_UNIT_S;
  907. else if (std::strcmp(unitUnit, LV2_UNITS__semitone12TET) == 0)
  908. rdfPort->Unit.Unit = LV2_PORT_UNIT_SEMITONE;
  909. else
  910. carla_stderr("lv2_rdf_new(\"%s\") - got unknown unit unit '%s'", uri, unitUnit);
  911. }
  912. }
  913. if (LilvNode* const unitNameNode = lilv_world_get(lv2World.me, unitUnitNode, lv2World.unit_name.me, nullptr))
  914. {
  915. if (const char* const unitName = lilv_node_as_string(unitNameNode))
  916. {
  917. rdfPort->Unit.Hints |= LV2_PORT_UNIT_NAME;
  918. rdfPort->Unit.Name = carla_strdup(unitName);
  919. }
  920. lilv_node_free(unitNameNode);
  921. }
  922. if (LilvNode* const unitRenderNode = lilv_world_get(lv2World.me, unitUnitNode, lv2World.unit_render.me, nullptr))
  923. {
  924. if (const char* const unitRender = lilv_node_as_string(unitRenderNode))
  925. {
  926. rdfPort->Unit.Hints |= LV2_PORT_UNIT_RENDER;
  927. rdfPort->Unit.Render = carla_strdup(unitRender);
  928. }
  929. lilv_node_free(unitRenderNode);
  930. }
  931. if (LilvNode* const unitSymbolNode = lilv_world_get(lv2World.me, unitUnitNode, lv2World.unit_symbol.me, nullptr))
  932. {
  933. if (const char* const unitSymbol = lilv_node_as_string(unitSymbolNode))
  934. {
  935. rdfPort->Unit.Hints |= LV2_PORT_UNIT_SYMBOL;
  936. rdfPort->Unit.Symbol = carla_strdup(unitSymbol);
  937. }
  938. lilv_node_free(unitSymbolNode);
  939. }
  940. lilv_node_free(unitUnitNode);
  941. }
  942. }
  943. // -----------------------------------------------------------
  944. // Set Port Minimum Size
  945. {
  946. if (LilvNode* const minimumSizeNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.rz_minSize.me))
  947. {
  948. const int minimumSize(lilv_node_as_int(minimumSizeNode));
  949. if (minimumSize > 0)
  950. rdfPort->MinimumSize = static_cast<uint32_t>(minimumSize);
  951. else
  952. carla_safe_assert_int("minimumSize > 0", __FILE__, __LINE__, minimumSize);
  953. lilv_node_free(minimumSizeNode);
  954. }
  955. }
  956. // -----------------------------------------------------------
  957. // Set Port Scale Points
  958. {
  959. Lilv::ScalePoints lilvScalePoints(lilvPort.get_scale_points());
  960. if (lilvScalePoints.size() > 0)
  961. {
  962. rdfPort->ScalePointCount = lilvScalePoints.size();
  963. rdfPort->ScalePoints = new LV2_RDF_PortScalePoint[rdfPort->ScalePointCount];
  964. uint32_t h = 0;
  965. LILV_FOREACH(scale_points, it, lilvScalePoints)
  966. {
  967. CARLA_SAFE_ASSERT_BREAK(h < rdfPort->ScalePointCount);
  968. Lilv::ScalePoint lilvScalePoint(lilvScalePoints.get(it));
  969. LV2_RDF_PortScalePoint* const rdfScalePoint(&rdfPort->ScalePoints[h++]);
  970. if (const char* const label = Lilv::Node(lilvScalePoint.get_label()).as_string())
  971. rdfScalePoint->Label = carla_strdup(label);
  972. rdfScalePoint->Value = Lilv::Node(lilvScalePoint.get_value()).as_float();
  973. }
  974. }
  975. lilv_nodes_free(const_cast<LilvNodes*>(lilvScalePoints.me));
  976. }
  977. }
  978. }
  979. // -------------------------------------------------------------------
  980. // Set Plugin Presets
  981. if (loadPresets)
  982. {
  983. Lilv::Nodes presetNodes(lilvPlugin.get_related(lv2World.preset_preset));
  984. if (presetNodes.size() > 0)
  985. {
  986. // create a list of preset URIs (for sorting and unique-ness)
  987. #ifdef USE_QT
  988. QStringList presetListURIs;
  989. LILV_FOREACH(nodes, it, presetNodes)
  990. {
  991. Lilv::Node presetNode(presetNodes.get(it));
  992. QString presetURI(presetNode.as_uri());
  993. if (! (presetURI.trimmed().isEmpty() || presetListURIs.contains(presetURI)))
  994. presetListURIs.append(presetURI);
  995. }
  996. presetListURIs.sort();
  997. rdfDescriptor->PresetCount = static_cast<uint32_t>(presetListURIs.count());
  998. #else
  999. juce::StringArray presetListURIs;
  1000. LILV_FOREACH(nodes, it, presetNodes)
  1001. {
  1002. Lilv::Node presetNode(presetNodes.get(it));
  1003. juce::String presetURI(presetNode.as_uri());
  1004. if (presetURI.trim().isNotEmpty())
  1005. presetListURIs.addIfNotAlreadyThere(presetURI);
  1006. }
  1007. presetListURIs.sortNatural();
  1008. rdfDescriptor->PresetCount = static_cast<uint32_t>(presetListURIs.size());
  1009. #endif
  1010. // create presets with unique URIs
  1011. rdfDescriptor->Presets = new LV2_RDF_Preset[rdfDescriptor->PresetCount];
  1012. // set preset data
  1013. LILV_FOREACH(nodes, it, presetNodes)
  1014. {
  1015. Lilv::Node presetNode(presetNodes.get(it));
  1016. const char* const presetURI(presetNode.as_uri());
  1017. CARLA_SAFE_ASSERT_CONTINUE(presetURI != nullptr && presetURI[0] != '\0');
  1018. // try to find label without loading the preset resource first
  1019. Lilv::Nodes presetLabelNodes(lv2World.find_nodes(presetNode, lv2World.rdfs_label, nullptr));
  1020. // failed, try loading resource
  1021. if (presetLabelNodes.size() == 0)
  1022. {
  1023. // if loading resource fails, skip this preset
  1024. if (lv2World.load_resource(presetNode) == -1)
  1025. continue;
  1026. // ok, let's try again
  1027. presetLabelNodes = lv2World.find_nodes(presetNode, lv2World.rdfs_label, nullptr);
  1028. }
  1029. if (presetLabelNodes.size() > 0)
  1030. {
  1031. #ifdef USE_QT
  1032. const int index(presetListURIs.indexOf(QString(presetURI)));
  1033. #else
  1034. const int index(presetListURIs.indexOf(juce::String(presetURI)));
  1035. #endif
  1036. CARLA_SAFE_ASSERT_CONTINUE(index >= 0 && index < static_cast<int>(rdfDescriptor->PresetCount));
  1037. LV2_RDF_Preset* const rdfPreset(&rdfDescriptor->Presets[index]);
  1038. // ---------------------------------------------------
  1039. // Set Preset Information
  1040. rdfPreset->URI = carla_strdup(presetURI);
  1041. Lilv::Nodes presetLabelNodes(lv2World.find_nodes(presetNode, lv2World.rdfs_label, nullptr));
  1042. if (presetLabelNodes.size() > 0)
  1043. {
  1044. if (const char* const label = presetLabelNodes.get_first().as_string())
  1045. rdfPreset->Label = carla_strdup(label);
  1046. }
  1047. lilv_nodes_free(const_cast<LilvNodes*>(presetLabelNodes.me));
  1048. }
  1049. }
  1050. }
  1051. lilv_nodes_free(const_cast<LilvNodes*>(presetNodes.me));
  1052. }
  1053. // -------------------------------------------------------------------
  1054. // Set Plugin Features
  1055. {
  1056. Lilv::Nodes lilvFeatureNodes(lilvPlugin.get_supported_features());
  1057. if (lilvFeatureNodes.size() > 0)
  1058. {
  1059. Lilv::Nodes lilvFeatureNodesR(lilvPlugin.get_required_features());
  1060. rdfDescriptor->FeatureCount = lilvFeatureNodes.size();
  1061. rdfDescriptor->Features = new LV2_RDF_Feature[rdfDescriptor->FeatureCount];
  1062. uint32_t h = 0;
  1063. LILV_FOREACH(nodes, it, lilvFeatureNodes)
  1064. {
  1065. CARLA_SAFE_ASSERT_BREAK(h < rdfDescriptor->FeatureCount);
  1066. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(it));
  1067. LV2_RDF_Feature* const rdfFeature(&rdfDescriptor->Features[h++]);
  1068. rdfFeature->Required = lilvFeatureNodesR.contains(lilvFeatureNode);
  1069. if (const char* const featureURI = lilvFeatureNode.as_uri())
  1070. rdfFeature->URI = carla_strdup(featureURI);
  1071. else
  1072. rdfFeature->URI = nullptr;
  1073. }
  1074. lilv_nodes_free(const_cast<LilvNodes*>(lilvFeatureNodesR.me));
  1075. }
  1076. lilv_nodes_free(const_cast<LilvNodes*>(lilvFeatureNodes.me));
  1077. }
  1078. // -------------------------------------------------------------------
  1079. // Set Plugin Extensions
  1080. {
  1081. Lilv::Nodes lilvExtensionDataNodes(lilvPlugin.get_extension_data());
  1082. if (lilvExtensionDataNodes.size() > 0)
  1083. {
  1084. rdfDescriptor->ExtensionCount = lilvExtensionDataNodes.size();
  1085. rdfDescriptor->Extensions = new LV2_URI[rdfDescriptor->ExtensionCount];
  1086. uint32_t h = 0;
  1087. LILV_FOREACH(nodes, it, lilvExtensionDataNodes)
  1088. {
  1089. CARLA_SAFE_ASSERT_BREAK(h < rdfDescriptor->ExtensionCount);
  1090. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(it));
  1091. LV2_URI* const rdfExtension(&rdfDescriptor->Extensions[h++]);
  1092. if (lilvExtensionDataNode.is_uri())
  1093. {
  1094. if (const char* const extURI = lilvExtensionDataNode.as_uri())
  1095. {
  1096. *rdfExtension = carla_strdup(extURI);
  1097. continue;
  1098. }
  1099. }
  1100. *rdfExtension = nullptr;
  1101. }
  1102. for (uint32_t x=h; x < rdfDescriptor->ExtensionCount; ++x)
  1103. rdfDescriptor->Extensions[x] = nullptr;
  1104. }
  1105. lilv_nodes_free(const_cast<LilvNodes*>(lilvExtensionDataNodes.me));
  1106. }
  1107. // -------------------------------------------------------------------
  1108. // Set Plugin UIs
  1109. {
  1110. const bool hasMODGui(lilvPlugin.get_modgui_resources_directory().as_uri() != nullptr);
  1111. Lilv::UIs lilvUIs(lilvPlugin.get_uis());
  1112. if (lilvUIs.size() > 0 || hasMODGui)
  1113. {
  1114. rdfDescriptor->UICount = lilvUIs.size() + (hasMODGui ? 1 : 0);
  1115. rdfDescriptor->UIs = new LV2_RDF_UI[rdfDescriptor->UICount];
  1116. uint32_t h = 0;
  1117. LILV_FOREACH(uis, it, lilvUIs)
  1118. {
  1119. CARLA_SAFE_ASSERT_BREAK(h < rdfDescriptor->UICount);
  1120. Lilv::UI lilvUI(lilvUIs.get(it));
  1121. LV2_RDF_UI* const rdfUI(&rdfDescriptor->UIs[h++]);
  1122. // -------------------------------------------------------
  1123. // Set UI Type
  1124. /**/ if (lilvUI.is_a(lv2World.ui_gtk2))
  1125. rdfUI->Type = LV2_UI_GTK2;
  1126. else if (lilvUI.is_a(lv2World.ui_gtk3))
  1127. rdfUI->Type = LV2_UI_GTK3;
  1128. else if (lilvUI.is_a(lv2World.ui_qt4))
  1129. rdfUI->Type = LV2_UI_QT4;
  1130. else if (lilvUI.is_a(lv2World.ui_qt5))
  1131. rdfUI->Type = LV2_UI_QT5;
  1132. else if (lilvUI.is_a(lv2World.ui_cocoa))
  1133. rdfUI->Type = LV2_UI_COCOA;
  1134. else if (lilvUI.is_a(lv2World.ui_windows))
  1135. rdfUI->Type = LV2_UI_WINDOWS;
  1136. else if (lilvUI.is_a(lv2World.ui_x11))
  1137. rdfUI->Type = LV2_UI_X11;
  1138. else if (lilvUI.is_a(lv2World.ui_external))
  1139. rdfUI->Type = LV2_UI_EXTERNAL;
  1140. else if (lilvUI.is_a(lv2World.ui_externalOld))
  1141. rdfUI->Type = LV2_UI_OLD_EXTERNAL;
  1142. else if (lilvUI.is_a(lv2World.ui_externalOld2))
  1143. pass();
  1144. else
  1145. carla_stderr("lv2_rdf_new(\"%s\") - UI '%s' is of unknown type", uri, lilvUI.get_uri().as_uri());
  1146. // -------------------------------------------------------
  1147. // Set UI Information
  1148. {
  1149. if (const char* const uiURI = lilvUI.get_uri().as_uri())
  1150. rdfUI->URI = carla_strdup(uiURI);
  1151. if (const char* const uiBinary = lilvUI.get_binary_uri().as_string())
  1152. rdfUI->Binary = carla_strdup_free(lilv_file_uri_parse(uiBinary, nullptr));
  1153. if (const char* const uiBundle = lilvUI.get_bundle_uri().as_string())
  1154. rdfUI->Bundle = carla_strdup_free(lilv_file_uri_parse(uiBundle, nullptr));
  1155. }
  1156. // -------------------------------------------------------
  1157. // Set UI Features
  1158. {
  1159. Lilv::Nodes lilvFeatureNodes(lilvUI.get_supported_features());
  1160. if (lilvFeatureNodes.size() > 0)
  1161. {
  1162. Lilv::Nodes lilvFeatureNodesR(lilvUI.get_required_features());
  1163. rdfUI->FeatureCount = lilvFeatureNodes.size();
  1164. rdfUI->Features = new LV2_RDF_Feature[rdfUI->FeatureCount];
  1165. uint32_t h2 = 0;
  1166. LILV_FOREACH(nodes, it2, lilvFeatureNodes)
  1167. {
  1168. CARLA_SAFE_ASSERT_BREAK(h2 < rdfUI->FeatureCount);
  1169. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(it2));
  1170. LV2_RDF_Feature* const rdfFeature(&rdfUI->Features[h2++]);
  1171. rdfFeature->Required = lilvFeatureNodesR.contains(lilvFeatureNode);
  1172. if (const char* const featureURI = lilvFeatureNode.as_uri())
  1173. rdfFeature->URI = carla_strdup(featureURI);
  1174. else
  1175. rdfFeature->URI = nullptr;
  1176. }
  1177. lilv_nodes_free(const_cast<LilvNodes*>(lilvFeatureNodesR.me));
  1178. }
  1179. lilv_nodes_free(const_cast<LilvNodes*>(lilvFeatureNodes.me));
  1180. }
  1181. // -------------------------------------------------------
  1182. // Set UI Extensions
  1183. {
  1184. Lilv::Nodes lilvExtensionDataNodes(lilvUI.get_extension_data());
  1185. if (lilvExtensionDataNodes.size() > 0)
  1186. {
  1187. rdfUI->ExtensionCount = lilvExtensionDataNodes.size();
  1188. rdfUI->Extensions = new LV2_URI[rdfUI->ExtensionCount];
  1189. uint32_t h2 = 0;
  1190. LILV_FOREACH(nodes, it2, lilvExtensionDataNodes)
  1191. {
  1192. CARLA_SAFE_ASSERT_BREAK(h2 < rdfUI->ExtensionCount);
  1193. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(it2));
  1194. LV2_URI* const rdfExtension(&rdfUI->Extensions[h2++]);
  1195. if (lilvExtensionDataNode.is_uri())
  1196. {
  1197. if (const char* const extURI = lilvExtensionDataNode.as_uri())
  1198. {
  1199. *rdfExtension = carla_strdup(extURI);
  1200. continue;
  1201. }
  1202. }
  1203. *rdfExtension = nullptr;
  1204. }
  1205. for (uint32_t x2=h2; x2 < rdfUI->ExtensionCount; ++x2)
  1206. rdfUI->Extensions[x2] = nullptr;
  1207. }
  1208. lilv_nodes_free(const_cast<LilvNodes*>(lilvExtensionDataNodes.me));
  1209. }
  1210. }
  1211. for (; hasMODGui;)
  1212. {
  1213. CARLA_SAFE_ASSERT_BREAK(h == rdfDescriptor->UICount-1);
  1214. LV2_RDF_UI* const rdfUI(&rdfDescriptor->UIs[h++]);
  1215. // -------------------------------------------------------
  1216. // Set UI Type
  1217. rdfUI->Type = LV2_UI_MOD;
  1218. // -------------------------------------------------------
  1219. // Set UI Information
  1220. if (const char* const resDir = lilvPlugin.get_modgui_resources_directory().as_uri())
  1221. rdfUI->URI = carla_strdup_free(lilv_file_uri_parse(resDir, nullptr));
  1222. if (rdfDescriptor->Bundle != nullptr)
  1223. rdfUI->Bundle = carla_strdup(rdfDescriptor->Bundle);
  1224. break;
  1225. }
  1226. }
  1227. lilv_nodes_free(const_cast<LilvNodes*>(lilvUIs.me));
  1228. }
  1229. return rdfDescriptor;
  1230. }
  1231. // -----------------------------------------------------------------------
  1232. // Check if we support a plugin port
  1233. static inline
  1234. bool is_lv2_port_supported(const LV2_Property types) noexcept
  1235. {
  1236. if (LV2_IS_PORT_CONTROL(types))
  1237. return true;
  1238. if (LV2_IS_PORT_AUDIO(types))
  1239. return true;
  1240. if (LV2_IS_PORT_CV(types))
  1241. return true;
  1242. if (LV2_IS_PORT_ATOM_SEQUENCE(types))
  1243. return true;
  1244. if (LV2_IS_PORT_EVENT(types))
  1245. return true;
  1246. if (LV2_IS_PORT_MIDI_LL(types))
  1247. return true;
  1248. return false;
  1249. }
  1250. // -----------------------------------------------------------------------
  1251. // Check if we support a plugin feature
  1252. static inline
  1253. bool is_lv2_feature_supported(const LV2_URI uri) noexcept
  1254. {
  1255. CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0', false);
  1256. if (std::strcmp(uri, LV2_BUF_SIZE__boundedBlockLength) == 0)
  1257. return true;
  1258. if (std::strcmp(uri, LV2_BUF_SIZE__fixedBlockLength) == 0)
  1259. return true;
  1260. if (std::strcmp(uri, LV2_BUF_SIZE__powerOf2BlockLength) == 0)
  1261. return true;
  1262. if (std::strcmp(uri, LV2_CORE__hardRTCapable) == 0)
  1263. return true;
  1264. if (std::strcmp(uri, LV2_CORE__inPlaceBroken) == 0)
  1265. return true;
  1266. if (std::strcmp(uri, LV2_CORE__isLive) == 0)
  1267. return true;
  1268. if (std::strcmp(uri, LV2_EVENT_URI) == 0)
  1269. return true;
  1270. if (std::strcmp(uri, LV2_LOG__log) == 0)
  1271. return true;
  1272. if (std::strcmp(uri, LV2_OPTIONS__options) == 0)
  1273. return true;
  1274. if (std::strcmp(uri, LV2_PROGRAMS__Host) == 0)
  1275. return true;
  1276. if (std::strcmp(uri, LV2_RESIZE_PORT__resize) == 0)
  1277. return true;
  1278. if (std::strcmp(uri, LV2_RTSAFE_MEMORY_POOL__Pool) == 0)
  1279. return true;
  1280. if (std::strcmp(uri, LV2_RTSAFE_MEMORY_POOL_DEPRECATED_URI) == 0)
  1281. return true;
  1282. if (std::strcmp(uri, LV2_STATE__makePath) == 0)
  1283. return true;
  1284. if (std::strcmp(uri, LV2_STATE__mapPath) == 0)
  1285. return true;
  1286. if (std::strcmp(uri, LV2_PORT_PROPS__supportsStrictBounds) == 0)
  1287. return true;
  1288. if (std::strcmp(uri, LV2_URI_MAP_URI) == 0)
  1289. return true;
  1290. if (std::strcmp(uri, LV2_URID__map) == 0)
  1291. return true;
  1292. if (std::strcmp(uri, LV2_URID__unmap) == 0)
  1293. return true;
  1294. if (std::strcmp(uri, LV2_WORKER__schedule) == 0)
  1295. return true;
  1296. return false;
  1297. }
  1298. // -----------------------------------------------------------------------
  1299. // Check if we support a plugin or UI feature
  1300. static inline
  1301. bool is_lv2_ui_feature_supported(const LV2_URI uri) noexcept
  1302. {
  1303. CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0', false);
  1304. if (is_lv2_feature_supported(uri))
  1305. return true;
  1306. #ifndef BUILD_BRIDGE_UI
  1307. if (std::strcmp(uri, LV2_DATA_ACCESS_URI) == 0)
  1308. return true;
  1309. if (std::strcmp(uri, LV2_INSTANCE_ACCESS_URI) == 0)
  1310. return true;
  1311. #endif
  1312. if (std::strcmp(uri, LV2_UI__fixedSize) == 0)
  1313. return true;
  1314. if (std::strcmp(uri, LV2_UI__idleInterface) == 0)
  1315. return true;
  1316. if (std::strcmp(uri, LV2_UI__makeResident) == 0)
  1317. return true;
  1318. if (std::strcmp(uri, LV2_UI__makeSONameResident) == 0)
  1319. return true;
  1320. if (std::strcmp(uri, LV2_UI__noUserResize) == 0)
  1321. return true;
  1322. if (std::strcmp(uri, LV2_UI__parent) == 0)
  1323. return true;
  1324. if (std::strcmp(uri, LV2_UI__portMap) == 0)
  1325. return true;
  1326. if (std::strcmp(uri, LV2_UI__portSubscribe) == 0)
  1327. return true;
  1328. if (std::strcmp(uri, LV2_UI__resize) == 0)
  1329. return true;
  1330. if (std::strcmp(uri, LV2_UI__touch) == 0)
  1331. return true;
  1332. if (std::strcmp(uri, LV2_EXTERNAL_UI__Widget) == 0)
  1333. return true;
  1334. if (std::strcmp(uri, LV2_EXTERNAL_UI_DEPRECATED_URI) == 0)
  1335. return true;
  1336. return false;
  1337. }
  1338. // -----------------------------------------------------------------------
  1339. #endif // CARLA_LV2_UTILS_HPP_INCLUDED