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.

1620 lines
68KB

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