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.

1591 lines
67KB

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