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.

1300 lines
52KB

  1. /*
  2. * Carla LV2 utils
  3. * Copyright (C) 2011-2013 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 GPL.txt file
  16. */
  17. #ifndef __CARLA_LV2_UTILS_HPP__
  18. #define __CARLA_LV2_UTILS_HPP__
  19. #include "CarlaJuceUtils.hpp"
  20. #include "lv2/lv2.h"
  21. #include "lv2/atom.h"
  22. #include "lv2/atom-forge.h"
  23. #include "lv2/atom-helpers.h"
  24. #include "lv2/atom-util.h"
  25. #include "lv2/buf-size.h"
  26. #include "lv2/data-access.h"
  27. // dynmanifest
  28. #include "lv2/event.h"
  29. #include "lv2/event-helpers.h"
  30. #include "lv2/instance-access.h"
  31. #include "lv2/log.h"
  32. // logger
  33. #include "lv2/midi.h"
  34. // morph
  35. #include "lv2/options.h"
  36. #include "lv2/parameters.h"
  37. #include "lv2/patch.h"
  38. #include "lv2/port-groups.h"
  39. #include "lv2/port-props.h"
  40. #include "lv2/presets.h"
  41. // resize-port
  42. #include "lv2/state.h"
  43. #include "lv2/time.h"
  44. #include "lv2/ui.h"
  45. #include "lv2/units.h"
  46. #include "lv2/uri-map.h"
  47. #include "lv2/urid.h"
  48. #include "lv2/worker.h"
  49. #include "lv2/lv2-miditype.h"
  50. #include "lv2/lv2-midifunctions.h"
  51. #include "lv2/lv2_external_ui.h"
  52. #include "lv2/lv2_programs.h"
  53. #include "lv2/lv2_rtmempool.h"
  54. #include "lv2_rdf.hpp"
  55. #include "lilv/lilvmm.hpp"
  56. #include "sratom/sratom.h"
  57. #include <QtCore/QMap>
  58. #include <QtCore/QStringList>
  59. // -------------------------------------------------
  60. // Define namespaces and missing prefixes
  61. #define NS_dct "http://purl.org/dc/terms/"
  62. #define NS_doap "http://usefulinc.com/ns/doap#"
  63. #define NS_rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  64. #define NS_rdfs "http://www.w3.org/2000/01/rdf-schema#"
  65. #define NS_llmm "http://ll-plugins.nongnu.org/lv2/ext/midimap#"
  66. #define LV2_MIDI_Map__CC "http://ll-plugins.nongnu.org/lv2/namespace#CC"
  67. #define LV2_MIDI_Map__NRPN "http://ll-plugins.nongnu.org/lv2/namespace#NRPN"
  68. #define LV2_MIDI_LL__MidiPort "http://ll-plugins.nongnu.org/lv2/ext/MidiPort"
  69. #define LV2_UI__Qt5UI LV2_UI_PREFIX "Qt5UI"
  70. #define LV2_UI__idle LV2_UI_PREFIX "idle"
  71. #define LV2_UI__makeResident LV2_UI_PREFIX "makeResident"
  72. // -------------------------------------------------
  73. // Non-void versions
  74. #define LV2NV_ATOM_CONTENTS(type, atom) \
  75. ((uint8_t*)(atom) + sizeof(type))
  76. #define LV2NV_ATOM_CONTENTS_CONST(type, atom) \
  77. ((const uint8_t*)(atom) + sizeof(type))
  78. #define LV2NV_ATOM_BODY(atom) LV2NV_ATOM_CONTENTS(LV2_Atom, atom)
  79. #define LV2NV_ATOM_BODY_CONST(atom) LV2NV_ATOM_CONTENTS_CONST(LV2_Atom, atom)
  80. // -------------------------------------------------
  81. // Custom Atom types
  82. struct LV2_Atom_MidiEvent {
  83. LV2_Atom_Event event;
  84. uint8_t data[4];
  85. };
  86. // -------------------------------------------------
  87. // Our LV2 World class
  88. class Lv2WorldClass : public Lilv::World
  89. {
  90. public:
  91. // Base Types
  92. Lilv::Node port;
  93. Lilv::Node symbol;
  94. Lilv::Node designation;
  95. Lilv::Node freeWheeling;
  96. Lilv::Node reportsLatency;
  97. // Plugin Types
  98. Lilv::Node class_allpass;
  99. Lilv::Node class_amplifier;
  100. Lilv::Node class_analyzer;
  101. Lilv::Node class_bandpass;
  102. Lilv::Node class_chorus;
  103. Lilv::Node class_comb;
  104. Lilv::Node class_compressor;
  105. Lilv::Node class_constant;
  106. Lilv::Node class_converter;
  107. Lilv::Node class_delay;
  108. Lilv::Node class_distortion;
  109. Lilv::Node class_dynamics;
  110. Lilv::Node class_eq;
  111. Lilv::Node class_envelope;
  112. Lilv::Node class_expander;
  113. Lilv::Node class_filter;
  114. Lilv::Node class_flanger;
  115. Lilv::Node class_function;
  116. Lilv::Node class_gate;
  117. Lilv::Node class_generator;
  118. Lilv::Node class_highpass;
  119. Lilv::Node class_instrument;
  120. Lilv::Node class_limiter;
  121. Lilv::Node class_lowpass;
  122. Lilv::Node class_mixer;
  123. Lilv::Node class_modulator;
  124. Lilv::Node class_multiEQ;
  125. Lilv::Node class_oscillator;
  126. Lilv::Node class_paraEQ;
  127. Lilv::Node class_phaser;
  128. Lilv::Node class_pitch;
  129. Lilv::Node class_reverb;
  130. Lilv::Node class_simulator;
  131. Lilv::Node class_spatial;
  132. Lilv::Node class_spectral;
  133. Lilv::Node class_utility;
  134. Lilv::Node class_waveshaper;
  135. // Port Types
  136. Lilv::Node port_input;
  137. Lilv::Node port_output;
  138. Lilv::Node port_control;
  139. Lilv::Node port_audio;
  140. Lilv::Node port_cv;
  141. Lilv::Node port_atom;
  142. Lilv::Node port_event;
  143. Lilv::Node port_midi;
  144. // Port Properties
  145. Lilv::Node pprop_optional;
  146. Lilv::Node pprop_enumeration;
  147. Lilv::Node pprop_integer;
  148. Lilv::Node pprop_sampleRate;
  149. Lilv::Node pprop_toggled;
  150. Lilv::Node pprop_artifacts;
  151. Lilv::Node pprop_continuousCV;
  152. Lilv::Node pprop_discreteCV;
  153. Lilv::Node pprop_expensive;
  154. Lilv::Node pprop_strictBounds;
  155. Lilv::Node pprop_logarithmic;
  156. Lilv::Node pprop_notAutomatic;
  157. Lilv::Node pprop_notOnGUI;
  158. Lilv::Node pprop_trigger;
  159. // Unit Hints
  160. Lilv::Node unit_name;
  161. Lilv::Node unit_render;
  162. Lilv::Node unit_symbol;
  163. Lilv::Node unit_unit;
  164. // UI Types
  165. Lilv::Node ui_gtk2;
  166. Lilv::Node ui_gtk3;
  167. Lilv::Node ui_qt4;
  168. Lilv::Node ui_qt5;
  169. Lilv::Node ui_cocoa;
  170. Lilv::Node ui_windows;
  171. Lilv::Node ui_x11;
  172. Lilv::Node ui_external;
  173. Lilv::Node ui_externalOld;
  174. // Misc
  175. Lilv::Node atom_bufferType;
  176. Lilv::Node atom_sequence;
  177. Lilv::Node atom_supports;
  178. Lilv::Node preset_preset;
  179. Lilv::Node state_state;
  180. Lilv::Node value_default;
  181. Lilv::Node value_minimum;
  182. Lilv::Node value_maximum;
  183. // Port Data Types
  184. Lilv::Node midi_event;
  185. Lilv::Node patch_message;
  186. Lilv::Node time_position;
  187. // MIDI CC
  188. Lilv::Node mm_defaultControl;
  189. Lilv::Node mm_controlType;
  190. Lilv::Node mm_controlNumber;
  191. // Other
  192. Lilv::Node dct_replaces;
  193. Lilv::Node doap_license;
  194. Lilv::Node rdf_type;
  195. Lilv::Node rdfs_label;
  196. // -------------------------------------------------
  197. Lv2WorldClass()
  198. : Lilv::World(),
  199. port (new_uri(LV2_CORE__port)),
  200. symbol (new_uri(LV2_CORE__symbol)),
  201. designation (new_uri(LV2_CORE__designation)),
  202. freeWheeling (new_uri(LV2_CORE__freeWheeling)),
  203. reportsLatency (new_uri(LV2_CORE__reportsLatency)),
  204. class_allpass (new_uri(LV2_CORE__AllpassPlugin)),
  205. class_amplifier (new_uri(LV2_CORE__AmplifierPlugin)),
  206. class_analyzer (new_uri(LV2_CORE__AnalyserPlugin)),
  207. class_bandpass (new_uri(LV2_CORE__BandpassPlugin)),
  208. class_chorus (new_uri(LV2_CORE__ChorusPlugin)),
  209. class_comb (new_uri(LV2_CORE__CombPlugin)),
  210. class_compressor (new_uri(LV2_CORE__CompressorPlugin)),
  211. class_constant (new_uri(LV2_CORE__ConstantPlugin)),
  212. class_converter (new_uri(LV2_CORE__ConverterPlugin)),
  213. class_delay (new_uri(LV2_CORE__DelayPlugin)),
  214. class_distortion (new_uri(LV2_CORE__DistortionPlugin)),
  215. class_dynamics (new_uri(LV2_CORE__DynamicsPlugin)),
  216. class_eq (new_uri(LV2_CORE__EQPlugin)),
  217. class_envelope (new_uri(LV2_CORE__EnvelopePlugin)),
  218. class_expander (new_uri(LV2_CORE__ExpanderPlugin)),
  219. class_filter (new_uri(LV2_CORE__FilterPlugin)),
  220. class_flanger (new_uri(LV2_CORE__FlangerPlugin)),
  221. class_function (new_uri(LV2_CORE__FunctionPlugin)),
  222. class_gate (new_uri(LV2_CORE__GatePlugin)),
  223. class_generator (new_uri(LV2_CORE__GeneratorPlugin)),
  224. class_highpass (new_uri(LV2_CORE__HighpassPlugin)),
  225. class_instrument (new_uri(LV2_CORE__InstrumentPlugin)),
  226. class_limiter (new_uri(LV2_CORE__LimiterPlugin)),
  227. class_lowpass (new_uri(LV2_CORE__LowpassPlugin)),
  228. class_mixer (new_uri(LV2_CORE__MixerPlugin)),
  229. class_modulator (new_uri(LV2_CORE__ModulatorPlugin)),
  230. class_multiEQ (new_uri(LV2_CORE__MultiEQPlugin)),
  231. class_oscillator (new_uri(LV2_CORE__OscillatorPlugin)),
  232. class_paraEQ (new_uri(LV2_CORE__ParaEQPlugin)),
  233. class_phaser (new_uri(LV2_CORE__PhaserPlugin)),
  234. class_pitch (new_uri(LV2_CORE__PitchPlugin)),
  235. class_reverb (new_uri(LV2_CORE__ReverbPlugin)),
  236. class_simulator (new_uri(LV2_CORE__SimulatorPlugin)),
  237. class_spatial (new_uri(LV2_CORE__SpatialPlugin)),
  238. class_spectral (new_uri(LV2_CORE__SpectralPlugin)),
  239. class_utility (new_uri(LV2_CORE__UtilityPlugin)),
  240. class_waveshaper (new_uri(LV2_CORE__WaveshaperPlugin)),
  241. port_input (new_uri(LV2_CORE__InputPort)),
  242. port_output (new_uri(LV2_CORE__OutputPort)),
  243. port_control (new_uri(LV2_CORE__ControlPort)),
  244. port_audio (new_uri(LV2_CORE__AudioPort)),
  245. port_cv (new_uri(LV2_CORE__CVPort)),
  246. port_atom (new_uri(LV2_ATOM__AtomPort)),
  247. port_event (new_uri(LV2_EVENT__EventPort)),
  248. port_midi (new_uri(LV2_MIDI_LL__MidiPort)),
  249. pprop_optional (new_uri(LV2_CORE__connectionOptional)),
  250. pprop_enumeration (new_uri(LV2_CORE__enumeration)),
  251. pprop_integer (new_uri(LV2_CORE__integer)),
  252. pprop_sampleRate (new_uri(LV2_CORE__sampleRate)),
  253. pprop_toggled (new_uri(LV2_CORE__toggled)),
  254. pprop_artifacts (new_uri(LV2_PORT_PROPS__causesArtifacts)),
  255. pprop_continuousCV (new_uri(LV2_PORT_PROPS__continuousCV)),
  256. pprop_discreteCV (new_uri(LV2_PORT_PROPS__discreteCV)),
  257. pprop_expensive (new_uri(LV2_PORT_PROPS__expensive)),
  258. pprop_strictBounds (new_uri(LV2_PORT_PROPS__hasStrictBounds)),
  259. pprop_logarithmic (new_uri(LV2_PORT_PROPS__logarithmic)),
  260. pprop_notAutomatic (new_uri(LV2_PORT_PROPS__notAutomatic)),
  261. pprop_notOnGUI (new_uri(LV2_PORT_PROPS__notOnGUI)),
  262. pprop_trigger (new_uri(LV2_PORT_PROPS__trigger)),
  263. unit_name (new_uri(LV2_UNITS__name)),
  264. unit_render (new_uri(LV2_UNITS__render)),
  265. unit_symbol (new_uri(LV2_UNITS__symbol)),
  266. unit_unit (new_uri(LV2_UNITS__unit)),
  267. ui_gtk2 (new_uri(LV2_UI__GtkUI)),
  268. ui_gtk3 (new_uri(LV2_UI__Gtk3UI)),
  269. ui_qt4 (new_uri(LV2_UI__Qt4UI)),
  270. ui_qt5 (new_uri(LV2_UI__Qt5UI)),
  271. ui_cocoa (new_uri(LV2_UI__CocoaUI)),
  272. ui_windows (new_uri(LV2_UI__WindowsUI)),
  273. ui_x11 (new_uri(LV2_UI__X11UI)),
  274. ui_external (new_uri(LV2_EXTERNAL_UI__Widget)),
  275. ui_externalOld (new_uri(LV2_EXTERNAL_UI_DEPRECATED_URI)),
  276. atom_bufferType (new_uri(LV2_ATOM__bufferType)),
  277. atom_sequence (new_uri(LV2_ATOM__Sequence)),
  278. atom_supports (new_uri(LV2_ATOM__supports)),
  279. preset_preset (new_uri(LV2_PRESETS__Preset)),
  280. state_state (new_uri(LV2_STATE__state)),
  281. value_default (new_uri(LV2_CORE__default)),
  282. value_minimum (new_uri(LV2_CORE__minimum)),
  283. value_maximum (new_uri(LV2_CORE__maximum)),
  284. midi_event (new_uri(LV2_MIDI__MidiEvent)),
  285. patch_message (new_uri(LV2_PATCH__Message)),
  286. time_position (new_uri(LV2_TIME__Position)),
  287. mm_defaultControl (new_uri(NS_llmm "defaultMidiController")),
  288. mm_controlType (new_uri(NS_llmm "controllerType")),
  289. mm_controlNumber (new_uri(NS_llmm "controllerNumber")),
  290. dct_replaces (new_uri(NS_dct "replaces")),
  291. doap_license (new_uri(NS_doap "license")),
  292. rdf_type (new_uri(NS_rdf "type")),
  293. rdfs_label (new_uri(NS_rdfs "label"))
  294. {
  295. needInit = true;
  296. }
  297. void init()
  298. {
  299. if (! needInit)
  300. return;
  301. needInit = false;
  302. Lilv::World::load_all();
  303. }
  304. const LilvPlugin* getPlugin(const LV2_URI uri)
  305. {
  306. CARLA_ASSERT(uri != nullptr);
  307. static const Lilv::Plugins lilvPlugins(Lilv::World::get_all_plugins());
  308. LilvNode* const uriNode(Lilv::World::new_uri(uri));
  309. if (uriNode == nullptr)
  310. {
  311. carla_stderr("Lv2WorldClass::getPlugin(\"%s\") - Failed to get node from uri", uri);
  312. return nullptr;
  313. }
  314. if (const LilvPlugin* const cPlugin = lilv_plugins_get_by_uri(lilvPlugins.me, uriNode))
  315. {
  316. lilv_node_free(uriNode);
  317. return cPlugin;
  318. }
  319. else
  320. {
  321. carla_stderr("Lv2WorldClass::getPlugin(\"%s\") - Failed to get plugin", uri);
  322. lilv_node_free(uriNode);
  323. return nullptr;
  324. }
  325. }
  326. const LilvState* getState(const LV2_URI uri, LV2_URID_Map* const uridMap)
  327. {
  328. CARLA_ASSERT(uri != nullptr);
  329. LilvNode* const uriNode(Lilv::World::new_uri(uri));
  330. if (uriNode == nullptr)
  331. {
  332. carla_stderr("Lv2WorldClass::getState(\"%s\", %p) - Failed to get node from uri", uri, uridMap);
  333. return nullptr;
  334. }
  335. if (const LilvState* state = lilv_state_new_from_world(this->me, uridMap, uriNode))
  336. {
  337. lilv_node_free(uriNode);
  338. return state;
  339. }
  340. else
  341. {
  342. carla_stderr("Lv2WorldClass::getState(\"%s\", %p) - Failed to get state", uri, uridMap);
  343. lilv_node_free(uriNode);
  344. return nullptr;
  345. }
  346. }
  347. private:
  348. bool needInit;
  349. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Lv2WorldClass)
  350. };
  351. // -----------------------------------------------------
  352. // Our LV2 World class object
  353. extern Lv2WorldClass gLv2World;
  354. // -----------------------------------------------------
  355. // Create new RDF object (using lilv)
  356. static inline
  357. const LV2_RDF_Descriptor* lv2_rdf_new(const LV2_URI uri)
  358. {
  359. CARLA_ASSERT(uri != nullptr);
  360. if (uri == nullptr)
  361. {
  362. carla_stderr("lv2_rdf_new() - Invalid uri");
  363. return nullptr;
  364. }
  365. const LilvPlugin* const cPlugin(gLv2World.getPlugin(uri));
  366. if (cPlugin == nullptr)
  367. {
  368. // Error already printed in getPlugin()
  369. return nullptr;
  370. }
  371. Lilv::Plugin lilvPlugin(cPlugin);
  372. LV2_RDF_Descriptor* const rdfDescriptor(new LV2_RDF_Descriptor());
  373. // --------------------------------------------------
  374. // Set Plugin Type
  375. {
  376. Lilv::Nodes typeNodes(lilvPlugin.get_value(gLv2World.rdf_type));
  377. if (typeNodes.size() > 0)
  378. {
  379. if (typeNodes.contains(gLv2World.class_allpass))
  380. rdfDescriptor->Type[0] |= LV2_PLUGIN_ALLPASS;
  381. if (typeNodes.contains(gLv2World.class_amplifier))
  382. rdfDescriptor->Type[0] |= LV2_PLUGIN_AMPLIFIER;
  383. if (typeNodes.contains(gLv2World.class_analyzer))
  384. rdfDescriptor->Type[1] |= LV2_PLUGIN_ANALYSER;
  385. if (typeNodes.contains(gLv2World.class_bandpass))
  386. rdfDescriptor->Type[0] |= LV2_PLUGIN_BANDPASS;
  387. if (typeNodes.contains(gLv2World.class_chorus))
  388. rdfDescriptor->Type[1] |= LV2_PLUGIN_CHORUS;
  389. if (typeNodes.contains(gLv2World.class_comb))
  390. rdfDescriptor->Type[1] |= LV2_PLUGIN_COMB;
  391. if (typeNodes.contains(gLv2World.class_compressor))
  392. rdfDescriptor->Type[0] |= LV2_PLUGIN_COMPRESSOR;
  393. if (typeNodes.contains(gLv2World.class_constant))
  394. rdfDescriptor->Type[1] |= LV2_PLUGIN_CONSTANT;
  395. if (typeNodes.contains(gLv2World.class_converter))
  396. rdfDescriptor->Type[1] |= LV2_PLUGIN_CONVERTER;
  397. if (typeNodes.contains(gLv2World.class_delay))
  398. rdfDescriptor->Type[0] |= LV2_PLUGIN_DELAY;
  399. if (typeNodes.contains(gLv2World.class_distortion))
  400. rdfDescriptor->Type[0] |= LV2_PLUGIN_DISTORTION;
  401. if (typeNodes.contains(gLv2World.class_dynamics))
  402. rdfDescriptor->Type[0] |= LV2_PLUGIN_DYNAMICS;
  403. if (typeNodes.contains(gLv2World.class_eq))
  404. rdfDescriptor->Type[0] |= LV2_PLUGIN_EQ;
  405. if (typeNodes.contains(gLv2World.class_envelope))
  406. rdfDescriptor->Type[0] |= LV2_PLUGIN_ENVELOPE;
  407. if (typeNodes.contains(gLv2World.class_expander))
  408. rdfDescriptor->Type[0] |= LV2_PLUGIN_EXPANDER;
  409. if (typeNodes.contains(gLv2World.class_filter))
  410. rdfDescriptor->Type[0] |= LV2_PLUGIN_FILTER;
  411. if (typeNodes.contains(gLv2World.class_flanger))
  412. rdfDescriptor->Type[1] |= LV2_PLUGIN_FLANGER;
  413. if (typeNodes.contains(gLv2World.class_function))
  414. rdfDescriptor->Type[1] |= LV2_PLUGIN_FUNCTION;
  415. if (typeNodes.contains(gLv2World.class_gate))
  416. rdfDescriptor->Type[0] |= LV2_PLUGIN_GATE;
  417. if (typeNodes.contains(gLv2World.class_generator))
  418. rdfDescriptor->Type[1] |= LV2_PLUGIN_GENERATOR;
  419. if (typeNodes.contains(gLv2World.class_highpass))
  420. rdfDescriptor->Type[0] |= LV2_PLUGIN_HIGHPASS;
  421. if (typeNodes.contains(gLv2World.class_instrument))
  422. rdfDescriptor->Type[1] |= LV2_PLUGIN_INSTRUMENT;
  423. if (typeNodes.contains(gLv2World.class_limiter))
  424. rdfDescriptor->Type[0] |= LV2_PLUGIN_LIMITER;
  425. if (typeNodes.contains(gLv2World.class_lowpass))
  426. rdfDescriptor->Type[0] |= LV2_PLUGIN_LOWPASS;
  427. if (typeNodes.contains(gLv2World.class_mixer))
  428. rdfDescriptor->Type[1] |= LV2_PLUGIN_MIXER;
  429. if (typeNodes.contains(gLv2World.class_modulator))
  430. rdfDescriptor->Type[1] |= LV2_PLUGIN_MODULATOR;
  431. if (typeNodes.contains(gLv2World.class_multiEQ))
  432. rdfDescriptor->Type[0] |= LV2_PLUGIN_MULTI_EQ;
  433. if (typeNodes.contains(gLv2World.class_oscillator))
  434. rdfDescriptor->Type[1] |= LV2_PLUGIN_OSCILLATOR;
  435. if (typeNodes.contains(gLv2World.class_paraEQ))
  436. rdfDescriptor->Type[0] |= LV2_PLUGIN_PARA_EQ;
  437. if (typeNodes.contains(gLv2World.class_phaser))
  438. rdfDescriptor->Type[1] |= LV2_PLUGIN_PHASER;
  439. if (typeNodes.contains(gLv2World.class_pitch))
  440. rdfDescriptor->Type[1] |= LV2_PLUGIN_PITCH;
  441. if (typeNodes.contains(gLv2World.class_reverb))
  442. rdfDescriptor->Type[0] |= LV2_PLUGIN_REVERB;
  443. if (typeNodes.contains(gLv2World.class_simulator))
  444. rdfDescriptor->Type[0] |= LV2_PLUGIN_SIMULATOR;
  445. if (typeNodes.contains(gLv2World.class_spatial))
  446. rdfDescriptor->Type[1] |= LV2_PLUGIN_SPATIAL;
  447. if (typeNodes.contains(gLv2World.class_spectral))
  448. rdfDescriptor->Type[1] |= LV2_PLUGIN_SPECTRAL;
  449. if (typeNodes.contains(gLv2World.class_utility))
  450. rdfDescriptor->Type[1] |= LV2_PLUGIN_UTILITY;
  451. if (typeNodes.contains(gLv2World.class_waveshaper))
  452. rdfDescriptor->Type[0] |= LV2_PLUGIN_WAVESHAPER;
  453. }
  454. }
  455. // --------------------------------------------------
  456. // Set Plugin Information
  457. {
  458. rdfDescriptor->URI = carla_strdup(uri);
  459. if (const char* const name = lilvPlugin.get_name().as_string())
  460. rdfDescriptor->Name = carla_strdup(name);
  461. if (const char* const author = lilvPlugin.get_author_name().as_string())
  462. rdfDescriptor->Author = carla_strdup(author);
  463. if (const char* const binary = lilvPlugin.get_library_uri().as_string())
  464. rdfDescriptor->Binary = carla_strdup(lilv_uri_to_path(binary));
  465. if (const char* const bundle = lilvPlugin.get_bundle_uri().as_string())
  466. rdfDescriptor->Bundle = carla_strdup(lilv_uri_to_path(bundle));
  467. Lilv::Nodes licenseNodes(lilvPlugin.get_value(gLv2World.doap_license));
  468. if (licenseNodes.size() > 0)
  469. {
  470. if (const char* const license = licenseNodes.get_first().as_string())
  471. rdfDescriptor->License = carla_strdup(license);
  472. }
  473. }
  474. // --------------------------------------------------
  475. // Set Plugin UniqueID
  476. {
  477. Lilv::Nodes replaceNodes(lilvPlugin.get_value(gLv2World.dct_replaces));
  478. if (replaceNodes.size() > 0)
  479. {
  480. Lilv::Node replaceNode(replaceNodes.get_first());
  481. if (replaceNode.is_uri())
  482. {
  483. const QString replaceURI(replaceNode.as_uri());
  484. if (replaceURI.startsWith("urn:"))
  485. {
  486. const QString replaceId(replaceURI.split(":").last());
  487. bool ok;
  488. ulong uniqueId = replaceId.toULong(&ok);
  489. if (ok && uniqueId != 0)
  490. rdfDescriptor->UniqueID = uniqueId;
  491. }
  492. }
  493. }
  494. }
  495. // --------------------------------------------------
  496. // Set Plugin Ports
  497. if (lilvPlugin.get_num_ports() > 0)
  498. {
  499. rdfDescriptor->PortCount = lilvPlugin.get_num_ports();
  500. rdfDescriptor->Ports = new LV2_RDF_Port[rdfDescriptor->PortCount];
  501. for (uint32_t j = 0; j < rdfDescriptor->PortCount; ++j)
  502. {
  503. Lilv::Port lilvPort(lilvPlugin.get_port_by_index(j));
  504. LV2_RDF_Port* const rdfPort = &rdfDescriptor->Ports[j];
  505. // --------------------------------------
  506. // Set Port Information
  507. {
  508. if (const char* const name = Lilv::Node(lilvPort.get_name()).as_string())
  509. rdfPort->Name = carla_strdup(name);
  510. if (const char* const symbol = Lilv::Node(lilvPort.get_symbol()).as_string())
  511. rdfPort->Symbol = carla_strdup(symbol);
  512. }
  513. // --------------------------------------
  514. // Set Port Mode and Type
  515. {
  516. // Input or Output
  517. if (lilvPort.is_a(gLv2World.port_input))
  518. rdfPort->Types |= LV2_PORT_INPUT;
  519. else if (lilvPort.is_a(gLv2World.port_output))
  520. rdfPort->Types |= LV2_PORT_OUTPUT;
  521. else
  522. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is not input or output", uri, rdfPort->Name);
  523. // Data Type
  524. if (lilvPort.is_a(gLv2World.port_control))
  525. rdfPort->Types |= LV2_PORT_CONTROL;
  526. else if (lilvPort.is_a(gLv2World.port_audio))
  527. rdfPort->Types |= LV2_PORT_AUDIO;
  528. else if (lilvPort.is_a(gLv2World.port_cv))
  529. rdfPort->Types |= LV2_PORT_CV;
  530. else if (lilvPort.is_a(gLv2World.port_atom))
  531. {
  532. rdfPort->Types |= LV2_PORT_ATOM;
  533. Lilv::Nodes bufferTypeNodes(lilvPort.get_value(gLv2World.atom_bufferType));
  534. if (bufferTypeNodes.contains(gLv2World.atom_sequence))
  535. rdfPort->Types |= LV2_PORT_ATOM_SEQUENCE;
  536. else
  537. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses an unknown atom buffer type", uri, rdfPort->Name);
  538. Lilv::Nodes supportNodes(lilvPort.get_value(gLv2World.atom_supports));
  539. bool supported = false;
  540. if (supportNodes.contains(gLv2World.midi_event))
  541. {
  542. rdfPort->Types |= LV2_PORT_DATA_MIDI_EVENT;
  543. supported = true;
  544. }
  545. if (supportNodes.contains(gLv2World.patch_message))
  546. {
  547. rdfPort->Types |= LV2_PORT_DATA_PATCH_MESSAGE;
  548. supported = true;
  549. }
  550. if (supportNodes.contains(gLv2World.time_position))
  551. {
  552. rdfPort->Types |= LV2_PORT_DATA_TIME_POSITION;
  553. supported = true;
  554. }
  555. if (! supported)
  556. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is of atom type but has unsupported data", uri, rdfPort->Name);
  557. }
  558. else if (lilvPort.is_a(gLv2World.port_event))
  559. {
  560. rdfPort->Types |= LV2_PORT_EVENT;
  561. bool supported = false;
  562. if (lilvPort.supports_event(gLv2World.midi_event))
  563. {
  564. rdfPort->Types |= LV2_PORT_DATA_MIDI_EVENT;
  565. supported = true;
  566. }
  567. if (lilvPort.supports_event(gLv2World.patch_message))
  568. {
  569. rdfPort->Types |= LV2_PORT_DATA_PATCH_MESSAGE;
  570. supported = true;
  571. }
  572. if (lilvPort.supports_event(gLv2World.time_position))
  573. {
  574. rdfPort->Types |= LV2_PORT_DATA_TIME_POSITION;
  575. supported = true;
  576. }
  577. if (! supported)
  578. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is of event type but has unsupported data", uri, rdfPort->Name);
  579. }
  580. else if (lilvPort.is_a(gLv2World.port_midi))
  581. {
  582. rdfPort->Types |= LV2_PORT_MIDI_LL;
  583. rdfPort->Types |= LV2_PORT_DATA_MIDI_EVENT;
  584. }
  585. else
  586. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is of unkown data type", uri, rdfPort->Name);
  587. }
  588. // --------------------------------------
  589. // Set Port Properties
  590. {
  591. if (lilvPort.has_property(gLv2World.pprop_optional))
  592. rdfPort->Properties |= LV2_PORT_OPTIONAL;
  593. if (lilvPort.has_property(gLv2World.pprop_enumeration))
  594. rdfPort->Properties |= LV2_PORT_ENUMERATION;
  595. if (lilvPort.has_property(gLv2World.pprop_integer))
  596. rdfPort->Properties |= LV2_PORT_INTEGER;
  597. if (lilvPort.has_property(gLv2World.pprop_sampleRate))
  598. rdfPort->Properties |= LV2_PORT_SAMPLE_RATE;
  599. if (lilvPort.has_property(gLv2World.pprop_toggled))
  600. rdfPort->Properties |= LV2_PORT_TOGGLED;
  601. if (lilvPort.has_property(gLv2World.pprop_artifacts))
  602. rdfPort->Properties |= LV2_PORT_CAUSES_ARTIFACTS;
  603. if (lilvPort.has_property(gLv2World.pprop_continuousCV))
  604. rdfPort->Properties |= LV2_PORT_CONTINUOUS_CV;
  605. if (lilvPort.has_property(gLv2World.pprop_discreteCV))
  606. rdfPort->Properties |= LV2_PORT_DISCRETE_CV;
  607. if (lilvPort.has_property(gLv2World.pprop_expensive))
  608. rdfPort->Properties |= LV2_PORT_EXPENSIVE;
  609. if (lilvPort.has_property(gLv2World.pprop_strictBounds))
  610. rdfPort->Properties |= LV2_PORT_STRICT_BOUNDS;
  611. if (lilvPort.has_property(gLv2World.pprop_logarithmic))
  612. rdfPort->Properties |= LV2_PORT_LOGARITHMIC;
  613. if (lilvPort.has_property(gLv2World.pprop_notAutomatic))
  614. rdfPort->Properties |= LV2_PORT_NOT_AUTOMATIC;
  615. if (lilvPort.has_property(gLv2World.pprop_notOnGUI))
  616. rdfPort->Properties |= LV2_PORT_NOT_ON_GUI;
  617. if (lilvPort.has_property(gLv2World.pprop_trigger))
  618. rdfPort->Properties |= LV2_PORT_TRIGGER;
  619. if (lilvPort.has_property(gLv2World.reportsLatency))
  620. rdfPort->Designation = LV2_PORT_DESIGNATION_LATENCY;
  621. }
  622. // --------------------------------------
  623. // Set Port Designation
  624. {
  625. Lilv::Nodes designationNodes(lilvPort.get_value(gLv2World.designation));
  626. if (designationNodes.size() > 0)
  627. {
  628. if (const char* const designation = designationNodes.get_first().as_string())
  629. {
  630. if (std::strcmp(designation, LV2_CORE__control) == 0)
  631. rdfPort->Designation = LV2_PORT_DESIGNATION_CONTROL;
  632. else if (std::strcmp(designation, LV2_CORE__freeWheeling) == 0)
  633. rdfPort->Designation = LV2_PORT_DESIGNATION_FREEWHEELING;
  634. else if (std::strcmp(designation, LV2_CORE__latency) == 0)
  635. rdfPort->Designation = LV2_PORT_DESIGNATION_LATENCY;
  636. else if (std::strcmp(designation, LV2_PARAMETERS__sampleRate) == 0)
  637. rdfPort->Designation = LV2_PORT_DESIGNATION_SAMPLE_RATE;
  638. else if (std::strcmp(designation, LV2_TIME__bar) == 0)
  639. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BAR;
  640. else if (std::strcmp(designation, LV2_TIME__barBeat) == 0)
  641. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BAR_BEAT;
  642. else if (std::strcmp(designation, LV2_TIME__beat) == 0)
  643. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEAT;
  644. else if (std::strcmp(designation, LV2_TIME__beatUnit) == 0)
  645. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEAT_UNIT;
  646. else if (std::strcmp(designation, LV2_TIME__beatsPerBar) == 0)
  647. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEATS_PER_BAR;
  648. else if (std::strcmp(designation, LV2_TIME__beatsPerMinute) == 0)
  649. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEATS_PER_MINUTE;
  650. else if (std::strcmp(designation, LV2_TIME__frame) == 0)
  651. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_FRAME;
  652. else if (std::strcmp(designation, LV2_TIME__framesPerSecond) == 0)
  653. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_FRAMES_PER_SECOND;
  654. else if (std::strcmp(designation, LV2_TIME__speed) == 0)
  655. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_SPEED;
  656. else if (std::strncmp(designation, LV2_PARAMETERS_PREFIX, std::strlen(LV2_PARAMETERS_PREFIX)) == 0)
  657. pass();
  658. else if (std::strncmp(designation, LV2_PORT_GROUPS_PREFIX, std::strlen(LV2_PORT_GROUPS_PREFIX)) == 0)
  659. pass();
  660. else
  661. carla_stderr("lv2_rdf_new(\"%s\") - got unknown port designation '%s'", uri, designation);
  662. }
  663. }
  664. }
  665. // --------------------------------------
  666. // Set Port MIDI Map
  667. {
  668. Lilv::Nodes midiMapNodes(lilvPort.get_value(gLv2World.mm_defaultControl));
  669. if (midiMapNodes.size() > 0)
  670. {
  671. Lilv::Node midiMapNode(midiMapNodes.get_first());
  672. if (midiMapNode.is_blank())
  673. {
  674. Lilv::Nodes midiMapTypeNodes(gLv2World.find_nodes(midiMapNode, gLv2World.mm_controlType, nullptr));
  675. Lilv::Nodes midiMapNumberNodes(gLv2World.find_nodes(midiMapNode, gLv2World.mm_controlNumber, nullptr));
  676. if (midiMapTypeNodes.size() == 1 && midiMapNumberNodes.size() == 1)
  677. {
  678. if (const char* const midiMapType = midiMapTypeNodes.get_first().as_string())
  679. {
  680. if (std::strcmp(midiMapType, LV2_MIDI_Map__CC) == 0)
  681. rdfPort->MidiMap.Type = LV2_PORT_MIDI_MAP_CC;
  682. else if (std::strcmp(midiMapType, LV2_MIDI_Map__NRPN) == 0)
  683. rdfPort->MidiMap.Type = LV2_PORT_MIDI_MAP_NRPN;
  684. else
  685. carla_stderr("lv2_rdf_new(\"%s\") - got unknown port Midi-Map type '%s'", uri, midiMapType);
  686. rdfPort->MidiMap.Number = static_cast<uint32_t>(midiMapNumberNodes.get_first().as_int());
  687. }
  688. }
  689. }
  690. }
  691. // TODO - also check using new official MIDI API too
  692. }
  693. // --------------------------------------
  694. // Set Port Points
  695. {
  696. Lilv::Nodes valueNodes(lilvPort.get_value(gLv2World.value_default));
  697. if (valueNodes.size() > 0)
  698. {
  699. rdfPort->Points.Hints |= LV2_PORT_POINT_DEFAULT;
  700. rdfPort->Points.Default = valueNodes.get_first().as_float();
  701. }
  702. valueNodes = lilvPort.get_value(gLv2World.value_minimum);
  703. if (valueNodes.size() > 0)
  704. {
  705. rdfPort->Points.Hints |= LV2_PORT_POINT_MINIMUM;
  706. rdfPort->Points.Minimum = valueNodes.get_first().as_float();
  707. }
  708. valueNodes = lilvPort.get_value(gLv2World.value_maximum);
  709. if (valueNodes.size() > 0)
  710. {
  711. rdfPort->Points.Hints |= LV2_PORT_POINT_MAXIMUM;
  712. rdfPort->Points.Maximum = valueNodes.get_first().as_float();
  713. }
  714. }
  715. // --------------------------------------
  716. // Set Port Unit
  717. {
  718. Lilv::Nodes unitUnitNodes(lilvPort.get_value(gLv2World.unit_unit));
  719. if (unitUnitNodes.size() > 0)
  720. {
  721. if (const char* const unitUnit = unitUnitNodes.get_first().as_uri())
  722. {
  723. rdfPort->Unit.Hints |= LV2_PORT_UNIT_UNIT;
  724. if (std::strcmp(unitUnit, LV2_UNITS__bar) == 0)
  725. rdfPort->Unit.Unit = LV2_PORT_UNIT_BAR;
  726. else if (std::strcmp(unitUnit, LV2_UNITS__beat) == 0)
  727. rdfPort->Unit.Unit = LV2_PORT_UNIT_BEAT;
  728. else if (std::strcmp(unitUnit, LV2_UNITS__bpm) == 0)
  729. rdfPort->Unit.Unit = LV2_PORT_UNIT_BPM;
  730. else if (std::strcmp(unitUnit, LV2_UNITS__cent) == 0)
  731. rdfPort->Unit.Unit = LV2_PORT_UNIT_CENT;
  732. else if (std::strcmp(unitUnit, LV2_UNITS__cm) == 0)
  733. rdfPort->Unit.Unit = LV2_PORT_UNIT_CM;
  734. else if (std::strcmp(unitUnit, LV2_UNITS__coef) == 0)
  735. rdfPort->Unit.Unit = LV2_PORT_UNIT_COEF;
  736. else if (std::strcmp(unitUnit, LV2_UNITS__db) == 0)
  737. rdfPort->Unit.Unit = LV2_PORT_UNIT_DB;
  738. else if (std::strcmp(unitUnit, LV2_UNITS__degree) == 0)
  739. rdfPort->Unit.Unit = LV2_PORT_UNIT_DEGREE;
  740. else if (std::strcmp(unitUnit, LV2_UNITS__frame) == 0)
  741. rdfPort->Unit.Unit = LV2_PORT_UNIT_FRAME;
  742. else if (std::strcmp(unitUnit, LV2_UNITS__hz) == 0)
  743. rdfPort->Unit.Unit = LV2_PORT_UNIT_HZ;
  744. else if (std::strcmp(unitUnit, LV2_UNITS__inch) == 0)
  745. rdfPort->Unit.Unit = LV2_PORT_UNIT_INCH;
  746. else if (std::strcmp(unitUnit, LV2_UNITS__khz) == 0)
  747. rdfPort->Unit.Unit = LV2_PORT_UNIT_KHZ;
  748. else if (std::strcmp(unitUnit, LV2_UNITS__km) == 0)
  749. rdfPort->Unit.Unit = LV2_PORT_UNIT_KM;
  750. else if (std::strcmp(unitUnit, LV2_UNITS__m) == 0)
  751. rdfPort->Unit.Unit = LV2_PORT_UNIT_M;
  752. else if (std::strcmp(unitUnit, LV2_UNITS__mhz) == 0)
  753. rdfPort->Unit.Unit = LV2_PORT_UNIT_MHZ;
  754. else if (std::strcmp(unitUnit, LV2_UNITS__midiNote) == 0)
  755. rdfPort->Unit.Unit = LV2_PORT_UNIT_MIDINOTE;
  756. else if (std::strcmp(unitUnit, LV2_UNITS__mile) == 0)
  757. rdfPort->Unit.Unit = LV2_PORT_UNIT_MILE;
  758. else if (std::strcmp(unitUnit, LV2_UNITS__min) == 0)
  759. rdfPort->Unit.Unit = LV2_PORT_UNIT_MIN;
  760. else if (std::strcmp(unitUnit, LV2_UNITS__mm) == 0)
  761. rdfPort->Unit.Unit = LV2_PORT_UNIT_MM;
  762. else if (std::strcmp(unitUnit, LV2_UNITS__ms) == 0)
  763. rdfPort->Unit.Unit = LV2_PORT_UNIT_MS;
  764. else if (std::strcmp(unitUnit, LV2_UNITS__oct) == 0)
  765. rdfPort->Unit.Unit = LV2_PORT_UNIT_OCT;
  766. else if (std::strcmp(unitUnit, LV2_UNITS__pc) == 0)
  767. rdfPort->Unit.Unit = LV2_PORT_UNIT_PC;
  768. else if (std::strcmp(unitUnit, LV2_UNITS__s) == 0)
  769. rdfPort->Unit.Unit = LV2_PORT_UNIT_S;
  770. else if (std::strcmp(unitUnit, LV2_UNITS__semitone12TET) == 0)
  771. rdfPort->Unit.Unit = LV2_PORT_UNIT_SEMITONE;
  772. else
  773. carla_stderr("lv2_rdf_new(\"%s\") - got unknown unit type '%s'", uri, unitUnit);
  774. }
  775. }
  776. Lilv::Nodes unitNameNodes(lilvPort.get_value(gLv2World.unit_name));
  777. if (unitNameNodes.size() > 0)
  778. {
  779. if (const char* const unitName = unitNameNodes.get_first().as_string())
  780. {
  781. rdfPort->Unit.Hints |= LV2_PORT_UNIT_NAME;
  782. rdfPort->Unit.Name = carla_strdup(unitName);
  783. }
  784. }
  785. Lilv::Nodes unitRenderNodes(lilvPort.get_value(gLv2World.unit_render));
  786. if (unitRenderNodes.size() > 0)
  787. {
  788. if (const char* const unitRender = unitRenderNodes.get_first().as_string())
  789. {
  790. rdfPort->Unit.Hints |= LV2_PORT_UNIT_RENDER;
  791. rdfPort->Unit.Render = carla_strdup(unitRender);
  792. }
  793. }
  794. Lilv::Nodes unitSymbolNodes(lilvPort.get_value(gLv2World.unit_symbol));
  795. if (unitSymbolNodes.size() > 0)
  796. {
  797. if (const char* const unitSymbol = unitSymbolNodes.get_first().as_string())
  798. {
  799. rdfPort->Unit.Hints |= LV2_PORT_UNIT_SYMBOL;
  800. rdfPort->Unit.Symbol = carla_strdup(unitSymbol);
  801. }
  802. }
  803. }
  804. // --------------------------------------
  805. // Set Port Scale Points
  806. Lilv::ScalePoints lilvScalePoints(lilvPort.get_scale_points());
  807. if (lilvScalePoints.size() > 0)
  808. {
  809. rdfPort->ScalePointCount = lilvScalePoints.size();
  810. rdfPort->ScalePoints = new LV2_RDF_PortScalePoint[rdfPort->ScalePointCount];
  811. uint32_t h = 0;
  812. LILV_FOREACH(scale_points, j, lilvScalePoints)
  813. {
  814. Lilv::ScalePoint lilvScalePoint(lilvScalePoints.get(j));
  815. LV2_RDF_PortScalePoint* const rdfScalePoint = &rdfPort->ScalePoints[h++];
  816. if (const char* const label = Lilv::Node(lilvScalePoint.get_label()).as_string())
  817. rdfScalePoint->Label = carla_strdup(label);
  818. rdfScalePoint->Value = Lilv::Node(lilvScalePoint.get_value()).as_float();
  819. }
  820. }
  821. }
  822. }
  823. // --------------------------------------------------
  824. // Set Plugin Presets
  825. {
  826. Lilv::Nodes presetNodes(lilvPlugin.get_related(gLv2World.preset_preset));
  827. if (presetNodes.size() > 0)
  828. {
  829. // create a list of preset URIs (for checking appliesTo, sorting and unique-ness)
  830. QStringList presetListURIs;
  831. LILV_FOREACH(nodes, j, presetNodes)
  832. {
  833. Lilv::Node presetNode(presetNodes.get(j));
  834. // FIXME - check appliesTo
  835. QString presetURI(presetNode.as_uri());
  836. if (! presetListURIs.contains(presetURI))
  837. presetListURIs.append(presetURI);
  838. }
  839. presetListURIs.sort();
  840. // create presets with unique URIs
  841. rdfDescriptor->PresetCount = static_cast<uint32_t>(presetListURIs.count());
  842. rdfDescriptor->Presets = new LV2_RDF_Preset[rdfDescriptor->PresetCount];
  843. // set preset data
  844. LILV_FOREACH(nodes, j, presetNodes)
  845. {
  846. Lilv::Node presetNode(presetNodes.get(j));
  847. if (gLv2World.load_resource(presetNode) == -1)
  848. continue;
  849. if (const char* const presetURI = presetNode.as_uri())
  850. {
  851. int32_t index = presetListURIs.indexOf(QString(presetURI));
  852. if (index < 0)
  853. continue;
  854. LV2_RDF_Preset* const rdfPreset = &rdfDescriptor->Presets[index];
  855. // --------------------------------------
  856. // Set Preset Information
  857. {
  858. rdfPreset->URI = carla_strdup(presetURI);
  859. Lilv::Nodes presetLabelNodes(gLv2World.find_nodes(presetNode, gLv2World.rdfs_label, nullptr));
  860. if (presetLabelNodes.size() > 0)
  861. {
  862. if (const char* const label = presetLabelNodes.get_first().as_string())
  863. rdfPreset->Label = carla_strdup(label);
  864. }
  865. }
  866. }
  867. }
  868. }
  869. }
  870. // --------------------------------------------------
  871. // Set Plugin Features
  872. {
  873. Lilv::Nodes lilvFeatureNodes(lilvPlugin.get_supported_features());
  874. if (lilvFeatureNodes.size() > 0)
  875. {
  876. Lilv::Nodes lilvFeatureNodesR(lilvPlugin.get_required_features());
  877. rdfDescriptor->FeatureCount = lilvFeatureNodes.size();
  878. rdfDescriptor->Features = new LV2_RDF_Feature[rdfDescriptor->FeatureCount];
  879. uint32_t h = 0;
  880. LILV_FOREACH(nodes, j, lilvFeatureNodes)
  881. {
  882. CARLA_ASSERT(h < rdfDescriptor->FeatureCount);
  883. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(j));
  884. LV2_RDF_Feature* const rdfFeature = &rdfDescriptor->Features[h++];
  885. rdfFeature->Type = lilvFeatureNodesR.contains(lilvFeatureNode) ? LV2_FEATURE_REQUIRED : LV2_FEATURE_OPTIONAL;
  886. if (const char* const featureURI = lilvFeatureNode.as_uri())
  887. rdfFeature->URI = carla_strdup(featureURI);
  888. }
  889. }
  890. }
  891. // --------------------------------------------------
  892. // Set Plugin Extensions
  893. {
  894. Lilv::Nodes lilvExtensionDataNodes(lilvPlugin.get_extension_data());
  895. if (lilvExtensionDataNodes.size() > 0)
  896. {
  897. rdfDescriptor->ExtensionCount = lilvExtensionDataNodes.size();
  898. rdfDescriptor->Extensions = new LV2_URI[rdfDescriptor->ExtensionCount];
  899. uint32_t h = 0;
  900. LILV_FOREACH(nodes, j, lilvExtensionDataNodes)
  901. {
  902. CARLA_ASSERT(h < rdfDescriptor->ExtensionCount);
  903. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(j));
  904. LV2_URI* const rdfExtension = &rdfDescriptor->Extensions[h++];
  905. if (const char* const extURI = lilvExtensionDataNode.as_uri())
  906. *rdfExtension = carla_strdup(extURI);
  907. }
  908. }
  909. }
  910. // --------------------------------------------------
  911. // Set Plugin UIs
  912. {
  913. Lilv::UIs lilvUIs(lilvPlugin.get_uis());
  914. if (lilvUIs.size() > 0)
  915. {
  916. rdfDescriptor->UICount = lilvUIs.size();
  917. rdfDescriptor->UIs = new LV2_RDF_UI[rdfDescriptor->UICount];
  918. uint32_t h = 0;
  919. LILV_FOREACH(uis, j, lilvUIs)
  920. {
  921. CARLA_ASSERT(h < rdfDescriptor->UICount);
  922. Lilv::UI lilvUI(lilvUIs.get(j));
  923. LV2_RDF_UI* const rdfUI = &rdfDescriptor->UIs[h++];
  924. // --------------------------------------
  925. // Set UI Type
  926. if (lilvUI.is_a(gLv2World.ui_gtk2))
  927. rdfUI->Type = LV2_UI_GTK2;
  928. else if (lilvUI.is_a(gLv2World.ui_gtk3))
  929. rdfUI->Type = LV2_UI_GTK3;
  930. else if (lilvUI.is_a(gLv2World.ui_qt4))
  931. rdfUI->Type = LV2_UI_QT4;
  932. else if (lilvUI.is_a(gLv2World.ui_qt5))
  933. rdfUI->Type = LV2_UI_QT5;
  934. else if (lilvUI.is_a(gLv2World.ui_cocoa))
  935. rdfUI->Type = LV2_UI_COCOA;
  936. else if (lilvUI.is_a(gLv2World.ui_windows))
  937. rdfUI->Type = LV2_UI_WINDOWS;
  938. else if (lilvUI.is_a(gLv2World.ui_x11))
  939. rdfUI->Type = LV2_UI_X11;
  940. else if (lilvUI.is_a(gLv2World.ui_external))
  941. rdfUI->Type = LV2_UI_EXTERNAL;
  942. else if (lilvUI.is_a(gLv2World.ui_externalOld))
  943. rdfUI->Type = LV2_UI_OLD_EXTERNAL;
  944. else
  945. carla_stderr("lv2_rdf_new(\"%s\") - UI '%s' is of unknown type", uri, lilvUI.get_uri().as_uri());
  946. // --------------------------------------
  947. // Set UI Information
  948. {
  949. if (const char* const uiURI = lilvUI.get_uri().as_uri())
  950. rdfUI->URI = carla_strdup(uiURI);
  951. if (const char* const uiBinary = lilvUI.get_binary_uri().as_string())
  952. rdfUI->Binary = carla_strdup(lilv_uri_to_path(uiBinary));
  953. if (const char* const uiBundle = lilvUI.get_bundle_uri().as_string())
  954. rdfUI->Bundle = carla_strdup(lilv_uri_to_path(uiBundle));
  955. }
  956. // --------------------------------------
  957. // Set UI Features
  958. {
  959. Lilv::Nodes lilvFeatureNodes(lilvUI.get_supported_features());
  960. if (lilvFeatureNodes.size() > 0)
  961. {
  962. Lilv::Nodes lilvFeatureNodesR(lilvUI.get_required_features());
  963. rdfUI->FeatureCount = lilvFeatureNodes.size();
  964. rdfUI->Features = new LV2_RDF_Feature[rdfUI->FeatureCount];
  965. uint32_t x = 0;
  966. LILV_FOREACH(nodes, k, lilvFeatureNodes)
  967. {
  968. CARLA_ASSERT(x < rdfUI->FeatureCount);
  969. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(k));
  970. LV2_RDF_Feature* const rdfFeature = &rdfUI->Features[x++];
  971. rdfFeature->Type = lilvFeatureNodesR.contains(lilvFeatureNode) ? LV2_FEATURE_REQUIRED : LV2_FEATURE_OPTIONAL;
  972. if (const char* const featureURI = lilvFeatureNode.as_uri())
  973. rdfFeature->URI = carla_strdup(featureURI);
  974. }
  975. }
  976. }
  977. // --------------------------------------
  978. // Set UI Extensions
  979. {
  980. Lilv::Nodes lilvExtensionDataNodes(lilvUI.get_extension_data());
  981. if (lilvExtensionDataNodes.size() > 0)
  982. {
  983. rdfUI->ExtensionCount = lilvExtensionDataNodes.size();
  984. rdfUI->Extensions = new LV2_URI[rdfUI->ExtensionCount];
  985. uint32_t x = 0;
  986. LILV_FOREACH(nodes, k, lilvExtensionDataNodes)
  987. {
  988. CARLA_ASSERT(x < rdfUI->ExtensionCount);
  989. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(k));
  990. LV2_URI* const rdfExtension = &rdfUI->Extensions[x++];
  991. if (const char* const extURI = lilvExtensionDataNode.as_uri())
  992. *rdfExtension = carla_strdup(extURI);
  993. }
  994. }
  995. }
  996. }
  997. }
  998. }
  999. return rdfDescriptor;
  1000. }
  1001. // -------------------------------------------------
  1002. // Check if we support a plugin port
  1003. static inline
  1004. bool is_lv2_port_supported(const LV2_Property types)
  1005. {
  1006. if (LV2_IS_PORT_CONTROL(types))
  1007. return true;
  1008. if (LV2_IS_PORT_AUDIO(types))
  1009. return true;
  1010. if (LV2_IS_PORT_ATOM_SEQUENCE(types))
  1011. return true;
  1012. if (LV2_IS_PORT_CV(types))
  1013. return false; // TODO
  1014. if (LV2_IS_PORT_EVENT(types))
  1015. return true;
  1016. if (LV2_IS_PORT_MIDI_LL(types))
  1017. return true;
  1018. return false;
  1019. }
  1020. // -------------------------------------------------
  1021. // Check if we support a plugin feature
  1022. static inline
  1023. bool is_lv2_feature_supported(const LV2_URI uri)
  1024. {
  1025. CARLA_ASSERT(uri != nullptr);
  1026. if (uri == nullptr)
  1027. return false;
  1028. if (std::strcmp(uri, LV2_CORE__hardRTCapable) == 0)
  1029. return true;
  1030. if (std::strcmp(uri, LV2_CORE__inPlaceBroken) == 0)
  1031. return true;
  1032. if (std::strcmp(uri, LV2_CORE__isLive) == 0)
  1033. return true;
  1034. if (std::strcmp(uri, LV2_BUF_SIZE__boundedBlockLength) == 0)
  1035. return true;
  1036. if (std::strcmp(uri, LV2_BUF_SIZE__fixedBlockLength) == 0)
  1037. return true;
  1038. if (std::strcmp(uri, LV2_BUF_SIZE__powerOf2BlockLength) == 0)
  1039. return true;
  1040. if (std::strcmp(uri, LV2_EVENT_URI) == 0)
  1041. return true;
  1042. if (std::strcmp(uri, LV2_LOG__log) == 0)
  1043. return true;
  1044. if (std::strcmp(uri, LV2_OPTIONS__options) == 0)
  1045. return true;
  1046. if (std::strcmp(uri, LV2_PROGRAMS__Host) == 0)
  1047. return true;
  1048. if (std::strcmp(uri, LV2_RTSAFE_MEMORY_POOL__Pool) == 0)
  1049. return true;
  1050. if (std::strcmp(uri, LV2_STATE__makePath) == 0)
  1051. return true;
  1052. if (std::strcmp(uri, LV2_STATE__mapPath) == 0)
  1053. return true;
  1054. if (std::strcmp(uri, LV2_PORT_PROPS__supportsStrictBounds) == 0)
  1055. return true;
  1056. if (std::strcmp(uri, LV2_URI_MAP_URI) == 0)
  1057. return true;
  1058. if (std::strcmp(uri, LV2_URID__map) == 0)
  1059. return true;
  1060. if (std::strcmp(uri, LV2_URID__unmap) == 0)
  1061. return true;
  1062. if (std::strcmp(uri, LV2_WORKER__schedule) == 0)
  1063. return true;
  1064. return false;
  1065. }
  1066. // -------------------------------------------------
  1067. // Check if we support a plugin or UI feature
  1068. static inline
  1069. bool is_lv2_ui_feature_supported(const LV2_URI uri)
  1070. {
  1071. CARLA_ASSERT(uri != nullptr);
  1072. if (uri == nullptr)
  1073. return false;
  1074. if (is_lv2_feature_supported(uri))
  1075. return true;
  1076. if (std::strcmp(uri, LV2_DATA_ACCESS_URI) == 0)
  1077. return true;
  1078. if (std::strcmp(uri, LV2_INSTANCE_ACCESS_URI) == 0)
  1079. return true;
  1080. if (std::strcmp(uri, LV2_UI__idle) == 0)
  1081. return true;
  1082. if (std::strcmp(uri, LV2_UI__fixedSize) == 0)
  1083. return true;
  1084. if (std::strcmp(uri, LV2_UI__makeResident) == 0)
  1085. return true;
  1086. if (std::strcmp(uri, LV2_UI__noUserResize) == 0)
  1087. return true;
  1088. if (std::strcmp(uri, LV2_UI__parent) == 0)
  1089. return true;
  1090. if (std::strcmp(uri, LV2_UI__portMap) == 0)
  1091. return true;
  1092. if (std::strcmp(uri, LV2_UI__portSubscribe) == 0)
  1093. return true;
  1094. if (std::strcmp(uri, LV2_UI__resize) == 0)
  1095. return true;
  1096. if (std::strcmp(uri, LV2_UI__touch) == 0)
  1097. return true;
  1098. if (std::strcmp(uri, LV2_EXTERNAL_UI__Widget) == 0)
  1099. return true;
  1100. if (std::strcmp(uri, LV2_EXTERNAL_UI_DEPRECATED_URI) == 0)
  1101. return true;
  1102. return false;
  1103. }
  1104. // -------------------------------------------------
  1105. #endif // __CARLA_LV2_UTILS_HPP__