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.

1594 lines
67KB

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