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.

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