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.

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