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.

1355 lines
57KB

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