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.

1354 lines
56KB

  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. };
  353. // -----------------------------------------------------------------------
  354. // Create new RDF object (using lilv)
  355. static inline
  356. const LV2_RDF_Descriptor* lv2_rdf_new(const LV2_URI uri, const bool fillPresets)
  357. {
  358. CARLA_SAFE_ASSERT_RETURN(uri != nullptr, nullptr);
  359. Lv2WorldClass& lv2World(Lv2WorldClass::getInstance());
  360. const LilvPlugin* const cPlugin(lv2World.getPlugin(uri));
  361. if (cPlugin == nullptr)
  362. {
  363. // Error already printed in getPlugin()
  364. return nullptr;
  365. }
  366. Lilv::Plugin lilvPlugin(cPlugin);
  367. LV2_RDF_Descriptor* const rdfDescriptor(new LV2_RDF_Descriptor());
  368. // -------------------------------------------------------------------
  369. // Set Plugin Type
  370. {
  371. Lilv::Nodes typeNodes(lilvPlugin.get_value(lv2World.rdf_type));
  372. if (typeNodes.size() > 0)
  373. {
  374. if (typeNodes.contains(lv2World.class_allpass))
  375. rdfDescriptor->Type[0] |= LV2_PLUGIN_ALLPASS;
  376. if (typeNodes.contains(lv2World.class_amplifier))
  377. rdfDescriptor->Type[0] |= LV2_PLUGIN_AMPLIFIER;
  378. if (typeNodes.contains(lv2World.class_analyzer))
  379. rdfDescriptor->Type[1] |= LV2_PLUGIN_ANALYSER;
  380. if (typeNodes.contains(lv2World.class_bandpass))
  381. rdfDescriptor->Type[0] |= LV2_PLUGIN_BANDPASS;
  382. if (typeNodes.contains(lv2World.class_chorus))
  383. rdfDescriptor->Type[1] |= LV2_PLUGIN_CHORUS;
  384. if (typeNodes.contains(lv2World.class_comb))
  385. rdfDescriptor->Type[1] |= LV2_PLUGIN_COMB;
  386. if (typeNodes.contains(lv2World.class_compressor))
  387. rdfDescriptor->Type[0] |= LV2_PLUGIN_COMPRESSOR;
  388. if (typeNodes.contains(lv2World.class_constant))
  389. rdfDescriptor->Type[1] |= LV2_PLUGIN_CONSTANT;
  390. if (typeNodes.contains(lv2World.class_converter))
  391. rdfDescriptor->Type[1] |= LV2_PLUGIN_CONVERTER;
  392. if (typeNodes.contains(lv2World.class_delay))
  393. rdfDescriptor->Type[0] |= LV2_PLUGIN_DELAY;
  394. if (typeNodes.contains(lv2World.class_distortion))
  395. rdfDescriptor->Type[0] |= LV2_PLUGIN_DISTORTION;
  396. if (typeNodes.contains(lv2World.class_dynamics))
  397. rdfDescriptor->Type[0] |= LV2_PLUGIN_DYNAMICS;
  398. if (typeNodes.contains(lv2World.class_eq))
  399. rdfDescriptor->Type[0] |= LV2_PLUGIN_EQ;
  400. if (typeNodes.contains(lv2World.class_envelope))
  401. rdfDescriptor->Type[0] |= LV2_PLUGIN_ENVELOPE;
  402. if (typeNodes.contains(lv2World.class_expander))
  403. rdfDescriptor->Type[0] |= LV2_PLUGIN_EXPANDER;
  404. if (typeNodes.contains(lv2World.class_filter))
  405. rdfDescriptor->Type[0] |= LV2_PLUGIN_FILTER;
  406. if (typeNodes.contains(lv2World.class_flanger))
  407. rdfDescriptor->Type[1] |= LV2_PLUGIN_FLANGER;
  408. if (typeNodes.contains(lv2World.class_function))
  409. rdfDescriptor->Type[1] |= LV2_PLUGIN_FUNCTION;
  410. if (typeNodes.contains(lv2World.class_gate))
  411. rdfDescriptor->Type[0] |= LV2_PLUGIN_GATE;
  412. if (typeNodes.contains(lv2World.class_generator))
  413. rdfDescriptor->Type[1] |= LV2_PLUGIN_GENERATOR;
  414. if (typeNodes.contains(lv2World.class_highpass))
  415. rdfDescriptor->Type[0] |= LV2_PLUGIN_HIGHPASS;
  416. if (typeNodes.contains(lv2World.class_instrument))
  417. rdfDescriptor->Type[1] |= LV2_PLUGIN_INSTRUMENT;
  418. if (typeNodes.contains(lv2World.class_limiter))
  419. rdfDescriptor->Type[0] |= LV2_PLUGIN_LIMITER;
  420. if (typeNodes.contains(lv2World.class_lowpass))
  421. rdfDescriptor->Type[0] |= LV2_PLUGIN_LOWPASS;
  422. if (typeNodes.contains(lv2World.class_mixer))
  423. rdfDescriptor->Type[1] |= LV2_PLUGIN_MIXER;
  424. if (typeNodes.contains(lv2World.class_modulator))
  425. rdfDescriptor->Type[1] |= LV2_PLUGIN_MODULATOR;
  426. if (typeNodes.contains(lv2World.class_multiEQ))
  427. rdfDescriptor->Type[0] |= LV2_PLUGIN_MULTI_EQ;
  428. if (typeNodes.contains(lv2World.class_oscillator))
  429. rdfDescriptor->Type[1] |= LV2_PLUGIN_OSCILLATOR;
  430. if (typeNodes.contains(lv2World.class_paraEQ))
  431. rdfDescriptor->Type[0] |= LV2_PLUGIN_PARA_EQ;
  432. if (typeNodes.contains(lv2World.class_phaser))
  433. rdfDescriptor->Type[1] |= LV2_PLUGIN_PHASER;
  434. if (typeNodes.contains(lv2World.class_pitch))
  435. rdfDescriptor->Type[1] |= LV2_PLUGIN_PITCH;
  436. if (typeNodes.contains(lv2World.class_reverb))
  437. rdfDescriptor->Type[0] |= LV2_PLUGIN_REVERB;
  438. if (typeNodes.contains(lv2World.class_simulator))
  439. rdfDescriptor->Type[0] |= LV2_PLUGIN_SIMULATOR;
  440. if (typeNodes.contains(lv2World.class_spatial))
  441. rdfDescriptor->Type[1] |= LV2_PLUGIN_SPATIAL;
  442. if (typeNodes.contains(lv2World.class_spectral))
  443. rdfDescriptor->Type[1] |= LV2_PLUGIN_SPECTRAL;
  444. if (typeNodes.contains(lv2World.class_utility))
  445. rdfDescriptor->Type[1] |= LV2_PLUGIN_UTILITY;
  446. if (typeNodes.contains(lv2World.class_waveshaper))
  447. rdfDescriptor->Type[0] |= LV2_PLUGIN_WAVESHAPER;
  448. }
  449. }
  450. // -------------------------------------------------------------------
  451. // Set Plugin Information
  452. {
  453. rdfDescriptor->URI = carla_strdup(uri);
  454. if (const char* const name = lilvPlugin.get_name().as_string())
  455. rdfDescriptor->Name = carla_strdup(name);
  456. if (const char* const author = lilvPlugin.get_author_name().as_string())
  457. rdfDescriptor->Author = carla_strdup(author);
  458. if (const char* const binary = lilvPlugin.get_library_uri().as_string())
  459. rdfDescriptor->Binary = carla_strdup(lilv_uri_to_path(binary));
  460. if (const char* const bundle = lilvPlugin.get_bundle_uri().as_string())
  461. rdfDescriptor->Bundle = carla_strdup(lilv_uri_to_path(bundle));
  462. Lilv::Nodes licenseNodes(lilvPlugin.get_value(lv2World.doap_license));
  463. if (licenseNodes.size() > 0)
  464. {
  465. if (const char* const license = licenseNodes.get_first().as_string())
  466. rdfDescriptor->License = carla_strdup(license);
  467. }
  468. }
  469. // -------------------------------------------------------------------
  470. // Set Plugin UniqueID
  471. {
  472. Lilv::Nodes replaceNodes(lilvPlugin.get_value(lv2World.dct_replaces));
  473. if (replaceNodes.size() > 0)
  474. {
  475. Lilv::Node replaceNode(replaceNodes.get_first());
  476. if (replaceNode.is_uri())
  477. {
  478. const juce::String replaceURI(replaceNode.as_uri());
  479. if (replaceURI.startsWith("urn:"))
  480. {
  481. if (int uniqueId = replaceURI.getTrailingIntValue())
  482. rdfDescriptor->UniqueID = (unsigned long)uniqueId;
  483. }
  484. }
  485. }
  486. }
  487. // -------------------------------------------------------------------
  488. // Set Plugin Ports
  489. if (lilvPlugin.get_num_ports() > 0)
  490. {
  491. rdfDescriptor->PortCount = lilvPlugin.get_num_ports();
  492. rdfDescriptor->Ports = new LV2_RDF_Port[rdfDescriptor->PortCount];
  493. for (uint32_t j = 0; j < rdfDescriptor->PortCount; ++j)
  494. {
  495. Lilv::Port lilvPort(lilvPlugin.get_port_by_index(j));
  496. LV2_RDF_Port* const rdfPort(&rdfDescriptor->Ports[j]);
  497. // -----------------------------------------------------------
  498. // Set Port Information
  499. {
  500. if (const char* const name = Lilv::Node(lilvPort.get_name()).as_string())
  501. rdfPort->Name = carla_strdup(name);
  502. if (const char* const symbol = Lilv::Node(lilvPort.get_symbol()).as_string())
  503. rdfPort->Symbol = carla_strdup(symbol);
  504. }
  505. // -----------------------------------------------------------
  506. // Set Port Mode and Type
  507. {
  508. // Input or Output
  509. if (lilvPort.is_a(lv2World.port_input))
  510. rdfPort->Types |= LV2_PORT_INPUT;
  511. else if (lilvPort.is_a(lv2World.port_output))
  512. rdfPort->Types |= LV2_PORT_OUTPUT;
  513. else
  514. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is not input or output", uri, rdfPort->Name);
  515. // Data Type
  516. if (lilvPort.is_a(lv2World.port_control))
  517. {
  518. rdfPort->Types |= LV2_PORT_CONTROL;
  519. }
  520. else if (lilvPort.is_a(lv2World.port_audio))
  521. {
  522. rdfPort->Types |= LV2_PORT_AUDIO;
  523. }
  524. else if (lilvPort.is_a(lv2World.port_cv))
  525. {
  526. rdfPort->Types |= LV2_PORT_CV;
  527. }
  528. else if (lilvPort.is_a(lv2World.port_atom))
  529. {
  530. rdfPort->Types |= LV2_PORT_ATOM;
  531. Lilv::Nodes bufferTypeNodes(lilvPort.get_value(lv2World.atom_bufferType));
  532. if (bufferTypeNodes.contains(lv2World.atom_sequence))
  533. rdfPort->Types |= LV2_PORT_ATOM_SEQUENCE;
  534. else
  535. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses an unknown atom buffer type", uri, rdfPort->Name);
  536. Lilv::Nodes supportNodes(lilvPort.get_value(lv2World.atom_supports));
  537. bool supported = false;
  538. if (supportNodes.contains(lv2World.midi_event))
  539. {
  540. rdfPort->Types |= LV2_PORT_DATA_MIDI_EVENT;
  541. supported = true;
  542. }
  543. if (supportNodes.contains(lv2World.patch_message))
  544. {
  545. rdfPort->Types |= LV2_PORT_DATA_PATCH_MESSAGE;
  546. supported = true;
  547. }
  548. if (supportNodes.contains(lv2World.time_position))
  549. {
  550. rdfPort->Types |= LV2_PORT_DATA_TIME_POSITION;
  551. supported = true;
  552. }
  553. if (! supported)
  554. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is of atom type but has unsupported data", uri, rdfPort->Name);
  555. }
  556. else if (lilvPort.is_a(lv2World.port_event))
  557. {
  558. rdfPort->Types |= LV2_PORT_EVENT;
  559. bool supported = false;
  560. if (lilvPort.supports_event(lv2World.midi_event))
  561. {
  562. rdfPort->Types |= LV2_PORT_DATA_MIDI_EVENT;
  563. supported = true;
  564. }
  565. if (lilvPort.supports_event(lv2World.patch_message))
  566. {
  567. rdfPort->Types |= LV2_PORT_DATA_PATCH_MESSAGE;
  568. supported = true;
  569. }
  570. if (lilvPort.supports_event(lv2World.time_position))
  571. {
  572. rdfPort->Types |= LV2_PORT_DATA_TIME_POSITION;
  573. supported = true;
  574. }
  575. if (! supported)
  576. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is of event type but has unsupported data", uri, rdfPort->Name);
  577. }
  578. else if (lilvPort.is_a(lv2World.port_midi))
  579. {
  580. rdfPort->Types |= LV2_PORT_MIDI_LL;
  581. rdfPort->Types |= LV2_PORT_DATA_MIDI_EVENT;
  582. }
  583. else
  584. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is of unkown data type", uri, rdfPort->Name);
  585. }
  586. // -----------------------------------------------------------
  587. // Set Port Properties
  588. {
  589. if (lilvPort.has_property(lv2World.pprop_optional))
  590. rdfPort->Properties |= LV2_PORT_OPTIONAL;
  591. if (lilvPort.has_property(lv2World.pprop_enumeration))
  592. rdfPort->Properties |= LV2_PORT_ENUMERATION;
  593. if (lilvPort.has_property(lv2World.pprop_integer))
  594. rdfPort->Properties |= LV2_PORT_INTEGER;
  595. if (lilvPort.has_property(lv2World.pprop_sampleRate))
  596. rdfPort->Properties |= LV2_PORT_SAMPLE_RATE;
  597. if (lilvPort.has_property(lv2World.pprop_toggled))
  598. rdfPort->Properties |= LV2_PORT_TOGGLED;
  599. if (lilvPort.has_property(lv2World.pprop_artifacts))
  600. rdfPort->Properties |= LV2_PORT_CAUSES_ARTIFACTS;
  601. if (lilvPort.has_property(lv2World.pprop_continuousCV))
  602. rdfPort->Properties |= LV2_PORT_CONTINUOUS_CV;
  603. if (lilvPort.has_property(lv2World.pprop_discreteCV))
  604. rdfPort->Properties |= LV2_PORT_DISCRETE_CV;
  605. if (lilvPort.has_property(lv2World.pprop_expensive))
  606. rdfPort->Properties |= LV2_PORT_EXPENSIVE;
  607. if (lilvPort.has_property(lv2World.pprop_strictBounds))
  608. rdfPort->Properties |= LV2_PORT_STRICT_BOUNDS;
  609. if (lilvPort.has_property(lv2World.pprop_logarithmic))
  610. rdfPort->Properties |= LV2_PORT_LOGARITHMIC;
  611. if (lilvPort.has_property(lv2World.pprop_notAutomatic))
  612. rdfPort->Properties |= LV2_PORT_NOT_AUTOMATIC;
  613. if (lilvPort.has_property(lv2World.pprop_notOnGUI))
  614. rdfPort->Properties |= LV2_PORT_NOT_ON_GUI;
  615. if (lilvPort.has_property(lv2World.pprop_trigger))
  616. rdfPort->Properties |= LV2_PORT_TRIGGER;
  617. if (lilvPort.has_property(lv2World.reportsLatency))
  618. rdfPort->Designation = LV2_PORT_DESIGNATION_LATENCY;
  619. // no port properties set, check if using old/invalid ones
  620. if (rdfPort->Properties == 0x0)
  621. {
  622. static const Lilv::Node oldPropArtifacts(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#causesArtifacts"));
  623. static const Lilv::Node oldPropContinuousCV(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#continuousCV"));
  624. static const Lilv::Node oldPropDiscreteCV(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#discreteCV"));
  625. static const Lilv::Node oldPropExpensive(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#expensive"));
  626. static const Lilv::Node oldPropStrictBounds(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#hasStrictBounds"));
  627. static const Lilv::Node oldPropLogarithmic(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#logarithmic"));
  628. static const Lilv::Node oldPropNotAutomatic(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#notAutomatic"));
  629. static const Lilv::Node oldPropNotOnGUI(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#notOnGUI"));
  630. static const Lilv::Node oldPropTrigger(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#trigger"));
  631. if (lilvPort.has_property(oldPropArtifacts))
  632. {
  633. rdfPort->Properties |= LV2_PORT_CAUSES_ARTIFACTS;
  634. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'causesArtifacts'", uri, rdfPort->Name);
  635. }
  636. if (lilvPort.has_property(oldPropContinuousCV))
  637. {
  638. rdfPort->Properties |= LV2_PORT_CONTINUOUS_CV;
  639. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'continuousCV'", uri, rdfPort->Name);
  640. }
  641. if (lilvPort.has_property(oldPropDiscreteCV))
  642. {
  643. rdfPort->Properties |= LV2_PORT_DISCRETE_CV;
  644. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'discreteCV'", uri, rdfPort->Name);
  645. }
  646. if (lilvPort.has_property(oldPropExpensive))
  647. {
  648. rdfPort->Properties |= LV2_PORT_EXPENSIVE;
  649. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'expensive'", uri, rdfPort->Name);
  650. }
  651. if (lilvPort.has_property(oldPropStrictBounds))
  652. {
  653. rdfPort->Properties |= LV2_PORT_STRICT_BOUNDS;
  654. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'hasStrictBounds'", uri, rdfPort->Name);
  655. }
  656. if (lilvPort.has_property(oldPropLogarithmic))
  657. {
  658. rdfPort->Properties |= LV2_PORT_LOGARITHMIC;
  659. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'logarithmic'", uri, rdfPort->Name);
  660. }
  661. if (lilvPort.has_property(oldPropNotAutomatic))
  662. {
  663. rdfPort->Properties |= LV2_PORT_NOT_AUTOMATIC;
  664. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'notAutomatic'", uri, rdfPort->Name);
  665. }
  666. if (lilvPort.has_property(oldPropNotOnGUI))
  667. {
  668. rdfPort->Properties |= LV2_PORT_NOT_ON_GUI;
  669. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'notOnGUI'", uri, rdfPort->Name);
  670. }
  671. if (lilvPort.has_property(oldPropTrigger))
  672. {
  673. rdfPort->Properties |= LV2_PORT_TRIGGER;
  674. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'trigger'", uri, rdfPort->Name);
  675. }
  676. }
  677. }
  678. // -----------------------------------------------------------
  679. // Set Port Designation
  680. {
  681. Lilv::Nodes designationNodes(lilvPort.get_value(lv2World.designation));
  682. if (designationNodes.size() > 0)
  683. {
  684. if (const char* const designation = designationNodes.get_first().as_string())
  685. {
  686. if (std::strcmp(designation, LV2_CORE__control) == 0)
  687. rdfPort->Designation = LV2_PORT_DESIGNATION_CONTROL;
  688. else if (std::strcmp(designation, LV2_CORE__freeWheeling) == 0)
  689. rdfPort->Designation = LV2_PORT_DESIGNATION_FREEWHEELING;
  690. else if (std::strcmp(designation, LV2_CORE__latency) == 0)
  691. rdfPort->Designation = LV2_PORT_DESIGNATION_LATENCY;
  692. else if (std::strcmp(designation, LV2_PARAMETERS__sampleRate) == 0)
  693. rdfPort->Designation = LV2_PORT_DESIGNATION_SAMPLE_RATE;
  694. else if (std::strcmp(designation, LV2_TIME__bar) == 0)
  695. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BAR;
  696. else if (std::strcmp(designation, LV2_TIME__barBeat) == 0)
  697. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BAR_BEAT;
  698. else if (std::strcmp(designation, LV2_TIME__beat) == 0)
  699. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEAT;
  700. else if (std::strcmp(designation, LV2_TIME__beatUnit) == 0)
  701. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEAT_UNIT;
  702. else if (std::strcmp(designation, LV2_TIME__beatsPerBar) == 0)
  703. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEATS_PER_BAR;
  704. else if (std::strcmp(designation, LV2_TIME__beatsPerMinute) == 0)
  705. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEATS_PER_MINUTE;
  706. else if (std::strcmp(designation, LV2_TIME__frame) == 0)
  707. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_FRAME;
  708. else if (std::strcmp(designation, LV2_TIME__framesPerSecond) == 0)
  709. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_FRAMES_PER_SECOND;
  710. else if (std::strcmp(designation, LV2_TIME__speed) == 0)
  711. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_SPEED;
  712. else if (std::strncmp(designation, LV2_PARAMETERS_PREFIX, std::strlen(LV2_PARAMETERS_PREFIX)) == 0)
  713. pass();
  714. else if (std::strncmp(designation, LV2_PORT_GROUPS_PREFIX, std::strlen(LV2_PORT_GROUPS_PREFIX)) == 0)
  715. pass();
  716. else
  717. carla_stderr("lv2_rdf_new(\"%s\") - got unknown port designation '%s'", uri, designation);
  718. }
  719. }
  720. }
  721. // -----------------------------------------------------------
  722. // Set Port MIDI Map
  723. {
  724. Lilv::Nodes midiMapNodes(lilvPort.get_value(lv2World.mm_defaultControl));
  725. if (midiMapNodes.size() > 0)
  726. {
  727. Lilv::Node midiMapNode(midiMapNodes.get_first());
  728. if (midiMapNode.is_blank())
  729. {
  730. Lilv::Nodes midiMapTypeNodes(lv2World.find_nodes(midiMapNode, lv2World.mm_controlType, nullptr));
  731. Lilv::Nodes midiMapNumberNodes(lv2World.find_nodes(midiMapNode, lv2World.mm_controlNumber, nullptr));
  732. if (midiMapTypeNodes.size() == 1 && midiMapNumberNodes.size() == 1)
  733. {
  734. if (const char* const midiMapType = midiMapTypeNodes.get_first().as_string())
  735. {
  736. if (std::strcmp(midiMapType, LV2_MIDI_Map__CC) == 0)
  737. rdfPort->MidiMap.Type = LV2_PORT_MIDI_MAP_CC;
  738. else if (std::strcmp(midiMapType, LV2_MIDI_Map__NRPN) == 0)
  739. rdfPort->MidiMap.Type = LV2_PORT_MIDI_MAP_NRPN;
  740. else
  741. carla_stderr("lv2_rdf_new(\"%s\") - got unknown port Midi-Map type '%s'", uri, midiMapType);
  742. rdfPort->MidiMap.Number = static_cast<uint32_t>(midiMapNumberNodes.get_first().as_int());
  743. }
  744. }
  745. }
  746. }
  747. // TODO - also check using new official MIDI API too
  748. }
  749. // -----------------------------------------------------------
  750. // Set Port Points
  751. {
  752. Lilv::Nodes valueNodes(lilvPort.get_value(lv2World.value_default));
  753. if (valueNodes.size() > 0)
  754. {
  755. rdfPort->Points.Hints |= LV2_PORT_POINT_DEFAULT;
  756. rdfPort->Points.Default = valueNodes.get_first().as_float();
  757. }
  758. valueNodes = lilvPort.get_value(lv2World.value_minimum);
  759. if (valueNodes.size() > 0)
  760. {
  761. rdfPort->Points.Hints |= LV2_PORT_POINT_MINIMUM;
  762. rdfPort->Points.Minimum = valueNodes.get_first().as_float();
  763. }
  764. valueNodes = lilvPort.get_value(lv2World.value_maximum);
  765. if (valueNodes.size() > 0)
  766. {
  767. rdfPort->Points.Hints |= LV2_PORT_POINT_MAXIMUM;
  768. rdfPort->Points.Maximum = valueNodes.get_first().as_float();
  769. }
  770. }
  771. // -----------------------------------------------------------
  772. // Set Port Unit
  773. {
  774. Lilv::Nodes unitUnitNodes(lilvPort.get_value(lv2World.unit_unit));
  775. if (unitUnitNodes.size() > 0)
  776. {
  777. if (const char* const unitUnit = unitUnitNodes.get_first().as_uri())
  778. {
  779. rdfPort->Unit.Hints |= LV2_PORT_UNIT_UNIT;
  780. if (std::strcmp(unitUnit, LV2_UNITS__bar) == 0)
  781. rdfPort->Unit.Unit = LV2_PORT_UNIT_BAR;
  782. else if (std::strcmp(unitUnit, LV2_UNITS__beat) == 0)
  783. rdfPort->Unit.Unit = LV2_PORT_UNIT_BEAT;
  784. else if (std::strcmp(unitUnit, LV2_UNITS__bpm) == 0)
  785. rdfPort->Unit.Unit = LV2_PORT_UNIT_BPM;
  786. else if (std::strcmp(unitUnit, LV2_UNITS__cent) == 0)
  787. rdfPort->Unit.Unit = LV2_PORT_UNIT_CENT;
  788. else if (std::strcmp(unitUnit, LV2_UNITS__cm) == 0)
  789. rdfPort->Unit.Unit = LV2_PORT_UNIT_CM;
  790. else if (std::strcmp(unitUnit, LV2_UNITS__coef) == 0)
  791. rdfPort->Unit.Unit = LV2_PORT_UNIT_COEF;
  792. else if (std::strcmp(unitUnit, LV2_UNITS__db) == 0)
  793. rdfPort->Unit.Unit = LV2_PORT_UNIT_DB;
  794. else if (std::strcmp(unitUnit, LV2_UNITS__degree) == 0)
  795. rdfPort->Unit.Unit = LV2_PORT_UNIT_DEGREE;
  796. else if (std::strcmp(unitUnit, LV2_UNITS__frame) == 0)
  797. rdfPort->Unit.Unit = LV2_PORT_UNIT_FRAME;
  798. else if (std::strcmp(unitUnit, LV2_UNITS__hz) == 0)
  799. rdfPort->Unit.Unit = LV2_PORT_UNIT_HZ;
  800. else if (std::strcmp(unitUnit, LV2_UNITS__inch) == 0)
  801. rdfPort->Unit.Unit = LV2_PORT_UNIT_INCH;
  802. else if (std::strcmp(unitUnit, LV2_UNITS__khz) == 0)
  803. rdfPort->Unit.Unit = LV2_PORT_UNIT_KHZ;
  804. else if (std::strcmp(unitUnit, LV2_UNITS__km) == 0)
  805. rdfPort->Unit.Unit = LV2_PORT_UNIT_KM;
  806. else if (std::strcmp(unitUnit, LV2_UNITS__m) == 0)
  807. rdfPort->Unit.Unit = LV2_PORT_UNIT_M;
  808. else if (std::strcmp(unitUnit, LV2_UNITS__mhz) == 0)
  809. rdfPort->Unit.Unit = LV2_PORT_UNIT_MHZ;
  810. else if (std::strcmp(unitUnit, LV2_UNITS__midiNote) == 0)
  811. rdfPort->Unit.Unit = LV2_PORT_UNIT_MIDINOTE;
  812. else if (std::strcmp(unitUnit, LV2_UNITS__mile) == 0)
  813. rdfPort->Unit.Unit = LV2_PORT_UNIT_MILE;
  814. else if (std::strcmp(unitUnit, LV2_UNITS__min) == 0)
  815. rdfPort->Unit.Unit = LV2_PORT_UNIT_MIN;
  816. else if (std::strcmp(unitUnit, LV2_UNITS__mm) == 0)
  817. rdfPort->Unit.Unit = LV2_PORT_UNIT_MM;
  818. else if (std::strcmp(unitUnit, LV2_UNITS__ms) == 0)
  819. rdfPort->Unit.Unit = LV2_PORT_UNIT_MS;
  820. else if (std::strcmp(unitUnit, LV2_UNITS__oct) == 0)
  821. rdfPort->Unit.Unit = LV2_PORT_UNIT_OCT;
  822. else if (std::strcmp(unitUnit, LV2_UNITS__pc) == 0)
  823. rdfPort->Unit.Unit = LV2_PORT_UNIT_PC;
  824. else if (std::strcmp(unitUnit, LV2_UNITS__s) == 0)
  825. rdfPort->Unit.Unit = LV2_PORT_UNIT_S;
  826. else if (std::strcmp(unitUnit, LV2_UNITS__semitone12TET) == 0)
  827. rdfPort->Unit.Unit = LV2_PORT_UNIT_SEMITONE;
  828. else
  829. carla_stderr("lv2_rdf_new(\"%s\") - got unknown unit type '%s'", uri, unitUnit);
  830. }
  831. }
  832. Lilv::Nodes unitNameNodes(lilvPort.get_value(lv2World.unit_name));
  833. if (unitNameNodes.size() > 0)
  834. {
  835. if (const char* const unitName = unitNameNodes.get_first().as_string())
  836. {
  837. rdfPort->Unit.Hints |= LV2_PORT_UNIT_NAME;
  838. rdfPort->Unit.Name = carla_strdup(unitName);
  839. }
  840. }
  841. Lilv::Nodes unitRenderNodes(lilvPort.get_value(lv2World.unit_render));
  842. if (unitRenderNodes.size() > 0)
  843. {
  844. if (const char* const unitRender = unitRenderNodes.get_first().as_string())
  845. {
  846. rdfPort->Unit.Hints |= LV2_PORT_UNIT_RENDER;
  847. rdfPort->Unit.Render = carla_strdup(unitRender);
  848. }
  849. }
  850. Lilv::Nodes unitSymbolNodes(lilvPort.get_value(lv2World.unit_symbol));
  851. if (unitSymbolNodes.size() > 0)
  852. {
  853. if (const char* const unitSymbol = unitSymbolNodes.get_first().as_string())
  854. {
  855. rdfPort->Unit.Hints |= LV2_PORT_UNIT_SYMBOL;
  856. rdfPort->Unit.Symbol = carla_strdup(unitSymbol);
  857. }
  858. }
  859. }
  860. // -----------------------------------------------------------
  861. // Set Port Scale Points
  862. Lilv::ScalePoints lilvScalePoints(lilvPort.get_scale_points());
  863. if (lilvScalePoints.size() > 0)
  864. {
  865. rdfPort->ScalePointCount = lilvScalePoints.size();
  866. rdfPort->ScalePoints = new LV2_RDF_PortScalePoint[rdfPort->ScalePointCount];
  867. uint32_t h = 0;
  868. LILV_FOREACH(scale_points, j, lilvScalePoints)
  869. {
  870. CARLA_ASSERT(h < rdfPort->ScalePointCount);
  871. Lilv::ScalePoint lilvScalePoint(lilvScalePoints.get(j));
  872. LV2_RDF_PortScalePoint* const rdfScalePoint(&rdfPort->ScalePoints[h++]);
  873. if (const char* const label = Lilv::Node(lilvScalePoint.get_label()).as_string())
  874. rdfScalePoint->Label = carla_strdup(label);
  875. rdfScalePoint->Value = Lilv::Node(lilvScalePoint.get_value()).as_float();
  876. }
  877. }
  878. }
  879. }
  880. // -------------------------------------------------------------------
  881. // Set Plugin Presets
  882. if (fillPresets)
  883. {
  884. Lilv::Nodes presetNodes(lilvPlugin.get_related(lv2World.preset_preset));
  885. if (presetNodes.size() > 0)
  886. {
  887. // create a list of preset URIs (for checking appliesTo, sorting and unique-ness)
  888. juce::StringArray presetListURIs;
  889. LILV_FOREACH(nodes, j, presetNodes)
  890. {
  891. Lilv::Node presetNode(presetNodes.get(j));
  892. // FIXME - check appliesTo?
  893. juce::String presetURI(presetNode.as_uri());
  894. if (presetURI.trim().isNotEmpty())
  895. presetListURIs.addIfNotAlreadyThere(presetURI);
  896. }
  897. presetListURIs.sort(false);
  898. // create presets with unique URIs
  899. rdfDescriptor->PresetCount = static_cast<uint32_t>(presetListURIs.size());
  900. rdfDescriptor->Presets = new LV2_RDF_Preset[rdfDescriptor->PresetCount];
  901. // set preset data
  902. LILV_FOREACH(nodes, j, presetNodes)
  903. {
  904. Lilv::Node presetNode(presetNodes.get(j));
  905. if (lv2World.load_resource(presetNode) == -1)
  906. continue;
  907. if (const char* const presetURI = presetNode.as_uri())
  908. {
  909. const int index(presetListURIs.indexOf(juce::String(presetURI)));
  910. CARLA_SAFE_ASSERT_CONTINUE(index >= 0);
  911. LV2_RDF_Preset* const rdfPreset(&rdfDescriptor->Presets[index]);
  912. // ---------------------------------------------------
  913. // Set Preset Information
  914. {
  915. rdfPreset->URI = carla_strdup(presetURI);
  916. Lilv::Nodes presetLabelNodes(lv2World.find_nodes(presetNode, lv2World.rdfs_label, nullptr));
  917. if (presetLabelNodes.size() > 0)
  918. {
  919. if (const char* const label = presetLabelNodes.get_first().as_string())
  920. rdfPreset->Label = carla_strdup(label);
  921. }
  922. }
  923. }
  924. }
  925. }
  926. }
  927. // -------------------------------------------------------------------
  928. // Set Plugin Features
  929. {
  930. Lilv::Nodes lilvFeatureNodes(lilvPlugin.get_supported_features());
  931. if (lilvFeatureNodes.size() > 0)
  932. {
  933. Lilv::Nodes lilvFeatureNodesR(lilvPlugin.get_required_features());
  934. rdfDescriptor->FeatureCount = lilvFeatureNodes.size();
  935. rdfDescriptor->Features = new LV2_RDF_Feature[rdfDescriptor->FeatureCount];
  936. uint32_t h = 0;
  937. LILV_FOREACH(nodes, j, lilvFeatureNodes)
  938. {
  939. CARLA_ASSERT(h < rdfDescriptor->FeatureCount);
  940. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(j));
  941. LV2_RDF_Feature* const rdfFeature(&rdfDescriptor->Features[h++]);
  942. rdfFeature->Type = lilvFeatureNodesR.contains(lilvFeatureNode) ? LV2_FEATURE_REQUIRED : LV2_FEATURE_OPTIONAL;
  943. if (const char* const featureURI = lilvFeatureNode.as_uri())
  944. rdfFeature->URI = carla_strdup(featureURI);
  945. }
  946. }
  947. }
  948. // -------------------------------------------------------------------
  949. // Set Plugin Extensions
  950. {
  951. Lilv::Nodes lilvExtensionDataNodes(lilvPlugin.get_extension_data());
  952. if (lilvExtensionDataNodes.size() > 0)
  953. {
  954. rdfDescriptor->ExtensionCount = lilvExtensionDataNodes.size();
  955. rdfDescriptor->Extensions = new LV2_URI[rdfDescriptor->ExtensionCount];
  956. uint32_t h = 0;
  957. LILV_FOREACH(nodes, j, lilvExtensionDataNodes)
  958. {
  959. CARLA_ASSERT(h < rdfDescriptor->ExtensionCount);
  960. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(j));
  961. LV2_URI* const rdfExtension(&rdfDescriptor->Extensions[h++]);
  962. if (const char* const extURI = lilvExtensionDataNode.as_uri())
  963. *rdfExtension = carla_strdup(extURI);
  964. }
  965. }
  966. }
  967. // -------------------------------------------------------------------
  968. // Set Plugin UIs
  969. {
  970. Lilv::UIs lilvUIs(lilvPlugin.get_uis());
  971. if (lilvUIs.size() > 0)
  972. {
  973. rdfDescriptor->UICount = lilvUIs.size();
  974. rdfDescriptor->UIs = new LV2_RDF_UI[rdfDescriptor->UICount];
  975. uint32_t h = 0;
  976. LILV_FOREACH(uis, j, lilvUIs)
  977. {
  978. CARLA_ASSERT(h < rdfDescriptor->UICount);
  979. Lilv::UI lilvUI(lilvUIs.get(j));
  980. LV2_RDF_UI* const rdfUI(&rdfDescriptor->UIs[h++]);
  981. // -------------------------------------------------------
  982. // Set UI Type
  983. if (lilvUI.is_a(lv2World.ui_gtk2))
  984. rdfUI->Type = LV2_UI_GTK2;
  985. else if (lilvUI.is_a(lv2World.ui_gtk3))
  986. rdfUI->Type = LV2_UI_GTK3;
  987. else if (lilvUI.is_a(lv2World.ui_qt4))
  988. rdfUI->Type = LV2_UI_QT4;
  989. else if (lilvUI.is_a(lv2World.ui_qt5))
  990. rdfUI->Type = LV2_UI_QT5;
  991. else if (lilvUI.is_a(lv2World.ui_cocoa))
  992. rdfUI->Type = LV2_UI_COCOA;
  993. else if (lilvUI.is_a(lv2World.ui_windows))
  994. rdfUI->Type = LV2_UI_WINDOWS;
  995. else if (lilvUI.is_a(lv2World.ui_x11))
  996. rdfUI->Type = LV2_UI_X11;
  997. else if (lilvUI.is_a(lv2World.ui_external))
  998. rdfUI->Type = LV2_UI_EXTERNAL;
  999. else if (lilvUI.is_a(lv2World.ui_externalOld))
  1000. rdfUI->Type = LV2_UI_OLD_EXTERNAL;
  1001. else
  1002. carla_stderr("lv2_rdf_new(\"%s\") - UI '%s' is of unknown type", uri, lilvUI.get_uri().as_uri());
  1003. // -------------------------------------------------------
  1004. // Set UI Information
  1005. {
  1006. if (const char* const uiURI = lilvUI.get_uri().as_uri())
  1007. rdfUI->URI = carla_strdup(uiURI);
  1008. if (const char* const uiBinary = lilvUI.get_binary_uri().as_string())
  1009. rdfUI->Binary = carla_strdup(lilv_uri_to_path(uiBinary));
  1010. if (const char* const uiBundle = lilvUI.get_bundle_uri().as_string())
  1011. rdfUI->Bundle = carla_strdup(lilv_uri_to_path(uiBundle));
  1012. }
  1013. // -------------------------------------------------------
  1014. // Set UI Features
  1015. {
  1016. Lilv::Nodes lilvFeatureNodes(lilvUI.get_supported_features());
  1017. if (lilvFeatureNodes.size() > 0)
  1018. {
  1019. Lilv::Nodes lilvFeatureNodesR(lilvUI.get_required_features());
  1020. rdfUI->FeatureCount = lilvFeatureNodes.size();
  1021. rdfUI->Features = new LV2_RDF_Feature[rdfUI->FeatureCount];
  1022. uint32_t x = 0;
  1023. LILV_FOREACH(nodes, k, lilvFeatureNodes)
  1024. {
  1025. CARLA_ASSERT(x < rdfUI->FeatureCount);
  1026. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(k));
  1027. LV2_RDF_Feature* const rdfFeature(&rdfUI->Features[x++]);
  1028. rdfFeature->Type = lilvFeatureNodesR.contains(lilvFeatureNode) ? LV2_FEATURE_REQUIRED : LV2_FEATURE_OPTIONAL;
  1029. if (const char* const featureURI = lilvFeatureNode.as_uri())
  1030. rdfFeature->URI = carla_strdup(featureURI);
  1031. }
  1032. }
  1033. }
  1034. // -------------------------------------------------------
  1035. // Set UI Extensions
  1036. {
  1037. Lilv::Nodes lilvExtensionDataNodes(lilvUI.get_extension_data());
  1038. if (lilvExtensionDataNodes.size() > 0)
  1039. {
  1040. rdfUI->ExtensionCount = lilvExtensionDataNodes.size();
  1041. rdfUI->Extensions = new LV2_URI[rdfUI->ExtensionCount];
  1042. uint32_t x = 0;
  1043. LILV_FOREACH(nodes, k, lilvExtensionDataNodes)
  1044. {
  1045. CARLA_ASSERT(x < rdfUI->ExtensionCount);
  1046. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(k));
  1047. LV2_URI* const rdfExtension(&rdfUI->Extensions[x++]);
  1048. if (const char* const extURI = lilvExtensionDataNode.as_uri())
  1049. *rdfExtension = carla_strdup(extURI);
  1050. }
  1051. }
  1052. }
  1053. }
  1054. }
  1055. }
  1056. return rdfDescriptor;
  1057. }
  1058. // -----------------------------------------------------------------------
  1059. // Check if we support a plugin port
  1060. static inline
  1061. bool is_lv2_port_supported(const LV2_Property types)
  1062. {
  1063. if (LV2_IS_PORT_CONTROL(types))
  1064. return true;
  1065. if (LV2_IS_PORT_AUDIO(types))
  1066. return true;
  1067. if (LV2_IS_PORT_ATOM_SEQUENCE(types))
  1068. return true;
  1069. if (LV2_IS_PORT_CV(types))
  1070. return true;
  1071. if (LV2_IS_PORT_EVENT(types))
  1072. return true;
  1073. if (LV2_IS_PORT_MIDI_LL(types))
  1074. return true;
  1075. return false;
  1076. }
  1077. // -----------------------------------------------------------------------
  1078. // Check if we support a plugin feature
  1079. static inline
  1080. bool is_lv2_feature_supported(const LV2_URI uri)
  1081. {
  1082. CARLA_SAFE_ASSERT_RETURN(uri != nullptr, false);
  1083. #ifndef BRIDGE_LV2
  1084. if (std::strcmp(uri, LV2_CORE__hardRTCapable) == 0)
  1085. return true;
  1086. if (std::strcmp(uri, LV2_CORE__inPlaceBroken) == 0)
  1087. return true;
  1088. if (std::strcmp(uri, LV2_CORE__isLive) == 0)
  1089. return true;
  1090. if (std::strcmp(uri, LV2_BUF_SIZE__boundedBlockLength) == 0)
  1091. return true;
  1092. if (std::strcmp(uri, LV2_BUF_SIZE__fixedBlockLength) == 0)
  1093. return true;
  1094. if (std::strcmp(uri, LV2_BUF_SIZE__powerOf2BlockLength) == 0)
  1095. return true;
  1096. if (std::strcmp(uri, LV2_EVENT_URI) == 0)
  1097. return true;
  1098. #endif
  1099. if (std::strcmp(uri, LV2_LOG__log) == 0)
  1100. return true;
  1101. if (std::strcmp(uri, LV2_OPTIONS__options) == 0)
  1102. return true;
  1103. if (std::strcmp(uri, LV2_PROGRAMS__Host) == 0)
  1104. return true;
  1105. #ifndef BRIDGE_LV2
  1106. if (std::strcmp(uri, LV2_RTSAFE_MEMORY_POOL__Pool) == 0)
  1107. return true;
  1108. #endif
  1109. if (std::strcmp(uri, LV2_STATE__makePath) == 0)
  1110. return true;
  1111. if (std::strcmp(uri, LV2_STATE__mapPath) == 0)
  1112. return true;
  1113. #ifndef BRIDGE_LV2
  1114. if (std::strcmp(uri, LV2_PORT_PROPS__supportsStrictBounds) == 0)
  1115. return true;
  1116. #endif
  1117. if (std::strcmp(uri, LV2_URI_MAP_URI) == 0)
  1118. return true;
  1119. if (std::strcmp(uri, LV2_URID__map) == 0)
  1120. return true;
  1121. if (std::strcmp(uri, LV2_URID__unmap) == 0)
  1122. return true;
  1123. #ifndef BRIDGE_LV2
  1124. if (std::strcmp(uri, LV2_WORKER__schedule) == 0)
  1125. return false; // TODO
  1126. #endif
  1127. return false;
  1128. }
  1129. // -----------------------------------------------------------------------
  1130. // Check if we support a plugin or UI feature
  1131. static inline
  1132. bool is_lv2_ui_feature_supported(const LV2_URI uri)
  1133. {
  1134. CARLA_SAFE_ASSERT_RETURN(uri != nullptr, false);
  1135. if (is_lv2_feature_supported(uri))
  1136. return true;
  1137. #ifndef BRIDGE_LV2
  1138. if (std::strcmp(uri, LV2_DATA_ACCESS_URI) == 0)
  1139. return true;
  1140. if (std::strcmp(uri, LV2_INSTANCE_ACCESS_URI) == 0)
  1141. return true;
  1142. #endif
  1143. if (std::strcmp(uri, LV2_UI__fixedSize) == 0)
  1144. return true;
  1145. if (std::strcmp(uri, LV2_UI__idle) == 0)
  1146. return true;
  1147. if (std::strcmp(uri, LV2_UI__makeResident) == 0)
  1148. return true;
  1149. if (std::strcmp(uri, LV2_UI__noUserResize) == 0)
  1150. return true;
  1151. if (std::strcmp(uri, LV2_UI__parent) == 0)
  1152. return true;
  1153. if (std::strcmp(uri, LV2_UI__portMap) == 0)
  1154. return true;
  1155. if (std::strcmp(uri, LV2_UI__portSubscribe) == 0)
  1156. return true;
  1157. if (std::strcmp(uri, LV2_UI__resize) == 0)
  1158. return true;
  1159. if (std::strcmp(uri, LV2_UI__touch) == 0)
  1160. return true;
  1161. if (std::strcmp(uri, LV2_EXTERNAL_UI__Widget) == 0)
  1162. return true;
  1163. if (std::strcmp(uri, LV2_EXTERNAL_UI_DEPRECATED_URI) == 0)
  1164. return true;
  1165. return false;
  1166. }
  1167. // -----------------------------------------------------------------------
  1168. #endif // CARLA_LV2_UTILS_HPP_INCLUDED