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.

1403 lines
59KB

  1. /*
  2. * Carla LV2 utils
  3. * Copyright (C) 2011-2014 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #ifndef CARLA_LV2_UTILS_HPP_INCLUDED
  18. #define CARLA_LV2_UTILS_HPP_INCLUDED
  19. #include "CarlaUtils.hpp"
  20. #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. #include "lv2/resize-port.h"
  42. #include "lv2/state.h"
  43. #include "lv2/time.h"
  44. #include "lv2/ui.h"
  45. #include "lv2/units.h"
  46. #include "lv2/uri-map.h"
  47. #include "lv2/urid.h"
  48. #include "lv2/worker.h"
  49. #include "lv2/lv2-miditype.h"
  50. #include "lv2/lv2-midifunctions.h"
  51. #include "lv2/lv2_external_ui.h"
  52. #include "lv2/lv2_programs.h"
  53. #include "lv2/lv2_rtmempool.h"
  54. #include "lv2_rdf.hpp"
  55. #include "lilv/lilvmm.hpp"
  56. #include "sratom/sratom.h"
  57. #include <QtCore/QStringList>
  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_UI__Qt5UI LV2_UI_PREFIX "Qt5UI"
  69. #define LV2_UI__makeResident LV2_UI_PREFIX "makeResident"
  70. // -----------------------------------------------------------------------
  71. // Custom Atom types
  72. struct LV2_Atom_MidiEvent {
  73. LV2_Atom_Event event;
  74. uint8_t data[4];
  75. };
  76. // -----------------------------------------------------------------------
  77. // Our LV2 World class
  78. class Lv2WorldClass : public Lilv::World
  79. {
  80. public:
  81. // Base Types
  82. Lilv::Node port;
  83. Lilv::Node symbol;
  84. Lilv::Node designation;
  85. Lilv::Node freeWheeling;
  86. Lilv::Node reportsLatency;
  87. // Plugin Types
  88. Lilv::Node class_allpass;
  89. Lilv::Node class_amplifier;
  90. Lilv::Node class_analyzer;
  91. Lilv::Node class_bandpass;
  92. Lilv::Node class_chorus;
  93. Lilv::Node class_comb;
  94. Lilv::Node class_compressor;
  95. Lilv::Node class_constant;
  96. Lilv::Node class_converter;
  97. Lilv::Node class_delay;
  98. Lilv::Node class_distortion;
  99. Lilv::Node class_dynamics;
  100. Lilv::Node class_eq;
  101. Lilv::Node class_envelope;
  102. Lilv::Node class_expander;
  103. Lilv::Node class_filter;
  104. Lilv::Node class_flanger;
  105. Lilv::Node class_function;
  106. Lilv::Node class_gate;
  107. Lilv::Node class_generator;
  108. Lilv::Node class_highpass;
  109. Lilv::Node class_instrument;
  110. Lilv::Node class_limiter;
  111. Lilv::Node class_lowpass;
  112. Lilv::Node class_mixer;
  113. Lilv::Node class_modulator;
  114. Lilv::Node class_multiEQ;
  115. Lilv::Node class_oscillator;
  116. Lilv::Node class_paraEQ;
  117. Lilv::Node class_phaser;
  118. Lilv::Node class_pitch;
  119. Lilv::Node class_reverb;
  120. Lilv::Node class_simulator;
  121. Lilv::Node class_spatial;
  122. Lilv::Node class_spectral;
  123. Lilv::Node class_utility;
  124. Lilv::Node class_waveshaper;
  125. // Port Types
  126. Lilv::Node port_input;
  127. Lilv::Node port_output;
  128. Lilv::Node port_control;
  129. Lilv::Node port_audio;
  130. Lilv::Node port_cv;
  131. Lilv::Node port_atom;
  132. Lilv::Node port_event;
  133. Lilv::Node port_midi;
  134. // Port Properties
  135. Lilv::Node pprop_optional;
  136. Lilv::Node pprop_enumeration;
  137. Lilv::Node pprop_integer;
  138. Lilv::Node pprop_sampleRate;
  139. Lilv::Node pprop_toggled;
  140. Lilv::Node pprop_artifacts;
  141. Lilv::Node pprop_continuousCV;
  142. Lilv::Node pprop_discreteCV;
  143. Lilv::Node pprop_expensive;
  144. Lilv::Node pprop_strictBounds;
  145. Lilv::Node pprop_logarithmic;
  146. Lilv::Node pprop_notAutomatic;
  147. Lilv::Node pprop_notOnGUI;
  148. Lilv::Node pprop_trigger;
  149. // Unit Hints
  150. Lilv::Node unit_name;
  151. Lilv::Node unit_render;
  152. Lilv::Node unit_symbol;
  153. Lilv::Node unit_unit;
  154. // UI Types
  155. Lilv::Node ui_gtk2;
  156. Lilv::Node ui_gtk3;
  157. Lilv::Node ui_qt4;
  158. Lilv::Node ui_qt5;
  159. Lilv::Node ui_cocoa;
  160. Lilv::Node ui_windows;
  161. Lilv::Node ui_x11;
  162. Lilv::Node ui_external;
  163. Lilv::Node ui_externalOld;
  164. Lilv::Node ui_externalOld2;
  165. // Misc
  166. Lilv::Node atom_bufferType;
  167. Lilv::Node atom_sequence;
  168. Lilv::Node atom_supports;
  169. Lilv::Node preset_preset;
  170. Lilv::Node state_state;
  171. Lilv::Node value_default;
  172. Lilv::Node value_minimum;
  173. Lilv::Node value_maximum;
  174. Lilv::Node rz_asLargeAs;
  175. Lilv::Node rz_minSize;
  176. // Port Data Types
  177. Lilv::Node midi_event;
  178. Lilv::Node patch_message;
  179. Lilv::Node time_position;
  180. // MIDI CC
  181. Lilv::Node mm_defaultControl;
  182. Lilv::Node mm_controlType;
  183. Lilv::Node mm_controlNumber;
  184. // Other
  185. Lilv::Node dct_replaces;
  186. Lilv::Node doap_license;
  187. Lilv::Node rdf_type;
  188. Lilv::Node rdfs_label;
  189. bool needsInit;
  190. // -------------------------------------------------------------------
  191. Lv2WorldClass()
  192. : Lilv::World(),
  193. port (new_uri(LV2_CORE__port)),
  194. symbol (new_uri(LV2_CORE__symbol)),
  195. designation (new_uri(LV2_CORE__designation)),
  196. freeWheeling (new_uri(LV2_CORE__freeWheeling)),
  197. reportsLatency (new_uri(LV2_CORE__reportsLatency)),
  198. class_allpass (new_uri(LV2_CORE__AllpassPlugin)),
  199. class_amplifier (new_uri(LV2_CORE__AmplifierPlugin)),
  200. class_analyzer (new_uri(LV2_CORE__AnalyserPlugin)),
  201. class_bandpass (new_uri(LV2_CORE__BandpassPlugin)),
  202. class_chorus (new_uri(LV2_CORE__ChorusPlugin)),
  203. class_comb (new_uri(LV2_CORE__CombPlugin)),
  204. class_compressor (new_uri(LV2_CORE__CompressorPlugin)),
  205. class_constant (new_uri(LV2_CORE__ConstantPlugin)),
  206. class_converter (new_uri(LV2_CORE__ConverterPlugin)),
  207. class_delay (new_uri(LV2_CORE__DelayPlugin)),
  208. class_distortion (new_uri(LV2_CORE__DistortionPlugin)),
  209. class_dynamics (new_uri(LV2_CORE__DynamicsPlugin)),
  210. class_eq (new_uri(LV2_CORE__EQPlugin)),
  211. class_envelope (new_uri(LV2_CORE__EnvelopePlugin)),
  212. class_expander (new_uri(LV2_CORE__ExpanderPlugin)),
  213. class_filter (new_uri(LV2_CORE__FilterPlugin)),
  214. class_flanger (new_uri(LV2_CORE__FlangerPlugin)),
  215. class_function (new_uri(LV2_CORE__FunctionPlugin)),
  216. class_gate (new_uri(LV2_CORE__GatePlugin)),
  217. class_generator (new_uri(LV2_CORE__GeneratorPlugin)),
  218. class_highpass (new_uri(LV2_CORE__HighpassPlugin)),
  219. class_instrument (new_uri(LV2_CORE__InstrumentPlugin)),
  220. class_limiter (new_uri(LV2_CORE__LimiterPlugin)),
  221. class_lowpass (new_uri(LV2_CORE__LowpassPlugin)),
  222. class_mixer (new_uri(LV2_CORE__MixerPlugin)),
  223. class_modulator (new_uri(LV2_CORE__ModulatorPlugin)),
  224. class_multiEQ (new_uri(LV2_CORE__MultiEQPlugin)),
  225. class_oscillator (new_uri(LV2_CORE__OscillatorPlugin)),
  226. class_paraEQ (new_uri(LV2_CORE__ParaEQPlugin)),
  227. class_phaser (new_uri(LV2_CORE__PhaserPlugin)),
  228. class_pitch (new_uri(LV2_CORE__PitchPlugin)),
  229. class_reverb (new_uri(LV2_CORE__ReverbPlugin)),
  230. class_simulator (new_uri(LV2_CORE__SimulatorPlugin)),
  231. class_spatial (new_uri(LV2_CORE__SpatialPlugin)),
  232. class_spectral (new_uri(LV2_CORE__SpectralPlugin)),
  233. class_utility (new_uri(LV2_CORE__UtilityPlugin)),
  234. class_waveshaper (new_uri(LV2_CORE__WaveshaperPlugin)),
  235. port_input (new_uri(LV2_CORE__InputPort)),
  236. port_output (new_uri(LV2_CORE__OutputPort)),
  237. port_control (new_uri(LV2_CORE__ControlPort)),
  238. port_audio (new_uri(LV2_CORE__AudioPort)),
  239. port_cv (new_uri(LV2_CORE__CVPort)),
  240. port_atom (new_uri(LV2_ATOM__AtomPort)),
  241. port_event (new_uri(LV2_EVENT__EventPort)),
  242. port_midi (new_uri(LV2_MIDI_LL__MidiPort)),
  243. pprop_optional (new_uri(LV2_CORE__connectionOptional)),
  244. pprop_enumeration (new_uri(LV2_CORE__enumeration)),
  245. pprop_integer (new_uri(LV2_CORE__integer)),
  246. pprop_sampleRate (new_uri(LV2_CORE__sampleRate)),
  247. pprop_toggled (new_uri(LV2_CORE__toggled)),
  248. pprop_artifacts (new_uri(LV2_PORT_PROPS__causesArtifacts)),
  249. pprop_continuousCV (new_uri(LV2_PORT_PROPS__continuousCV)),
  250. pprop_discreteCV (new_uri(LV2_PORT_PROPS__discreteCV)),
  251. pprop_expensive (new_uri(LV2_PORT_PROPS__expensive)),
  252. pprop_strictBounds (new_uri(LV2_PORT_PROPS__hasStrictBounds)),
  253. pprop_logarithmic (new_uri(LV2_PORT_PROPS__logarithmic)),
  254. pprop_notAutomatic (new_uri(LV2_PORT_PROPS__notAutomatic)),
  255. pprop_notOnGUI (new_uri(LV2_PORT_PROPS__notOnGUI)),
  256. pprop_trigger (new_uri(LV2_PORT_PROPS__trigger)),
  257. unit_name (new_uri(LV2_UNITS__name)),
  258. unit_render (new_uri(LV2_UNITS__render)),
  259. unit_symbol (new_uri(LV2_UNITS__symbol)),
  260. unit_unit (new_uri(LV2_UNITS__unit)),
  261. ui_gtk2 (new_uri(LV2_UI__GtkUI)),
  262. ui_gtk3 (new_uri(LV2_UI__Gtk3UI)),
  263. ui_qt4 (new_uri(LV2_UI__Qt4UI)),
  264. ui_qt5 (new_uri(LV2_UI__Qt5UI)),
  265. ui_cocoa (new_uri(LV2_UI__CocoaUI)),
  266. ui_windows (new_uri(LV2_UI__WindowsUI)),
  267. ui_x11 (new_uri(LV2_UI__X11UI)),
  268. ui_external (new_uri(LV2_EXTERNAL_UI__Widget)),
  269. ui_externalOld (new_uri(LV2_EXTERNAL_UI_DEPRECATED_URI)),
  270. ui_externalOld2 (new_uri("http://nedko.arnaudov.name/lv2/external_ui/")),
  271. atom_bufferType (new_uri(LV2_ATOM__bufferType)),
  272. atom_sequence (new_uri(LV2_ATOM__Sequence)),
  273. atom_supports (new_uri(LV2_ATOM__supports)),
  274. preset_preset (new_uri(LV2_PRESETS__Preset)),
  275. state_state (new_uri(LV2_STATE__state)),
  276. value_default (new_uri(LV2_CORE__default)),
  277. value_minimum (new_uri(LV2_CORE__minimum)),
  278. value_maximum (new_uri(LV2_CORE__maximum)),
  279. rz_asLargeAs (new_uri(LV2_RESIZE_PORT__asLargeAs)),
  280. rz_minSize (new_uri(LV2_RESIZE_PORT__minimumSize)),
  281. midi_event (new_uri(LV2_MIDI__MidiEvent)),
  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. needsInit(true)
  292. {
  293. }
  294. static Lv2WorldClass& getInstance()
  295. {
  296. static Lv2WorldClass lv2World;
  297. return lv2World;
  298. }
  299. void init()
  300. {
  301. if (! needsInit)
  302. return;
  303. needsInit = false;
  304. Lilv::World::load_all();
  305. }
  306. const LilvPlugin* getPlugin(const LV2_URI uri) const
  307. {
  308. CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0', nullptr);
  309. const LilvPlugins* const cPlugins(lilv_world_get_all_plugins(this->me));
  310. if (cPlugins == nullptr)
  311. {
  312. carla_stderr("Lv2WorldClass::getPlugin(\"%s\") - Failed to get plugins from world", uri);
  313. return nullptr;
  314. }
  315. LilvNode* const uriNode(Lilv::World::new_uri(uri));
  316. if (uriNode == nullptr)
  317. {
  318. carla_stderr("Lv2WorldClass::getPlugin(\"%s\") - Failed to get node from uri", uri);
  319. return nullptr;
  320. }
  321. const LilvPlugin* const cPlugin(lilv_plugins_get_by_uri(cPlugins, uriNode));
  322. lilv_node_free(uriNode);
  323. if (cPlugin == nullptr)
  324. {
  325. carla_stderr("Lv2WorldClass::getPlugin(\"%s\") - Failed to get plugin", uri);
  326. return nullptr;
  327. }
  328. return cPlugin;
  329. }
  330. const LilvState* getState(const LV2_URI uri, const LV2_URID_Map* const uridMap) const
  331. {
  332. CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0', nullptr);
  333. CARLA_SAFE_ASSERT_RETURN(uridMap != nullptr, nullptr);
  334. LilvNode* const uriNode(Lilv::World::new_uri(uri));
  335. if (uriNode == nullptr)
  336. {
  337. carla_stderr("Lv2WorldClass::getState(\"%s\", %p) - Failed to get node from uri", uri, uridMap);
  338. return nullptr;
  339. }
  340. const LilvState* const cState(lilv_state_new_from_world(this->me, uridMap, uriNode));
  341. lilv_node_free(uriNode);
  342. if (cState == nullptr)
  343. {
  344. carla_stderr("Lv2WorldClass::getState(\"%s\", %p) - Failed to get state", uri, uridMap);
  345. return nullptr;
  346. }
  347. return cState;
  348. }
  349. CARLA_PREVENT_HEAP_ALLOCATION
  350. };
  351. // -----------------------------------------------------------------------
  352. // Create new RDF object (using lilv)
  353. static inline
  354. const LV2_RDF_Descriptor* lv2_rdf_new(const LV2_URI uri, const bool doInit)
  355. {
  356. CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0', nullptr);
  357. Lv2WorldClass& lv2World(Lv2WorldClass::getInstance());
  358. if (doInit)
  359. lv2World.init();
  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 QString replaceURI(replaceNode.as_uri());
  479. if (replaceURI.startsWith("urn:"))
  480. {
  481. const QString replaceId(replaceURI.split(":").last());
  482. bool ok;
  483. const ulong uniqueId(replaceId.toULong(&ok));
  484. if (ok && uniqueId != 0)
  485. rdfDescriptor->UniqueID = uniqueId;
  486. }
  487. }
  488. }
  489. }
  490. // -------------------------------------------------------------------
  491. // Set Plugin Ports
  492. if (lilvPlugin.get_num_ports() > 0)
  493. {
  494. rdfDescriptor->PortCount = lilvPlugin.get_num_ports();
  495. rdfDescriptor->Ports = new LV2_RDF_Port[rdfDescriptor->PortCount];
  496. for (uint32_t i = 0; i < rdfDescriptor->PortCount; ++i)
  497. {
  498. Lilv::Port lilvPort(lilvPlugin.get_port_by_index(i));
  499. LV2_RDF_Port* const rdfPort(&rdfDescriptor->Ports[i]);
  500. // -----------------------------------------------------------
  501. // Set Port Information
  502. {
  503. if (const char* const name = Lilv::Node(lilvPort.get_name()).as_string())
  504. rdfPort->Name = carla_strdup(name);
  505. if (const char* const symbol = Lilv::Node(lilvPort.get_symbol()).as_string())
  506. rdfPort->Symbol = carla_strdup(symbol);
  507. }
  508. // -----------------------------------------------------------
  509. // Set Port Mode and Type
  510. {
  511. // Input or Output
  512. if (lilvPort.is_a(lv2World.port_input))
  513. rdfPort->Types |= LV2_PORT_INPUT;
  514. else if (lilvPort.is_a(lv2World.port_output))
  515. rdfPort->Types |= LV2_PORT_OUTPUT;
  516. else
  517. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is not input or output", uri, rdfPort->Name);
  518. // Data Type
  519. if (lilvPort.is_a(lv2World.port_control))
  520. {
  521. rdfPort->Types |= LV2_PORT_CONTROL;
  522. }
  523. else if (lilvPort.is_a(lv2World.port_audio))
  524. {
  525. rdfPort->Types |= LV2_PORT_AUDIO;
  526. }
  527. else if (lilvPort.is_a(lv2World.port_cv))
  528. {
  529. rdfPort->Types |= LV2_PORT_CV;
  530. }
  531. else if (lilvPort.is_a(lv2World.port_atom))
  532. {
  533. rdfPort->Types |= LV2_PORT_ATOM;
  534. Lilv::Nodes bufferTypeNodes(lilvPort.get_value(lv2World.atom_bufferType));
  535. for (LilvIter* it = lilv_nodes_begin(bufferTypeNodes.me); ! lilv_nodes_is_end(bufferTypeNodes.me, it); it = lilv_nodes_next(bufferTypeNodes.me, it))
  536. {
  537. const Lilv::Node node(lilv_nodes_get(bufferTypeNodes.me, it));
  538. CARLA_SAFE_ASSERT_CONTINUE(node.is_uri());
  539. if (node.equals(lv2World.atom_sequence))
  540. rdfPort->Types |= LV2_PORT_ATOM_SEQUENCE;
  541. else
  542. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses an unknown atom buffer type '%s'", uri, rdfPort->Name, node.as_uri());
  543. }
  544. Lilv::Nodes supportNodes(lilvPort.get_value(lv2World.atom_supports));
  545. for (LilvIter* it = lilv_nodes_begin(supportNodes.me); ! lilv_nodes_is_end(supportNodes.me, it); it = lilv_nodes_next(supportNodes.me, it))
  546. {
  547. const Lilv::Node node(lilv_nodes_get(supportNodes.me, it));
  548. CARLA_SAFE_ASSERT_CONTINUE(node.is_uri());
  549. if (node.equals(lv2World.midi_event))
  550. rdfPort->Types |= LV2_PORT_DATA_MIDI_EVENT;
  551. else if (node.equals(lv2World.patch_message))
  552. rdfPort->Types |= LV2_PORT_DATA_PATCH_MESSAGE;
  553. else if (node.equals(lv2World.time_position))
  554. rdfPort->Types |= LV2_PORT_DATA_TIME_POSITION;
  555. // something new we don't support yet?
  556. else if (std::strstr(node.as_uri(), "lv2plug.in/") != nullptr)
  557. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is of atom type but has unsupported data '%s'", uri, rdfPort->Name, node.as_uri());
  558. }
  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 unit '%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 Minimum Size
  866. {
  867. Lilv::Nodes minimumSizeNodes(lilvPort.get_value(lv2World.rz_minSize));
  868. if (minimumSizeNodes.size() > 0)
  869. {
  870. const int minimumSize(minimumSizeNodes.get_first().as_int());
  871. if (minimumSize > 0)
  872. rdfPort->MinimumSize = static_cast<uint32_t>(minimumSize);
  873. else
  874. carla_safe_assert_int("minimumSize > 0", __FILE__, __LINE__, minimumSize);
  875. }
  876. }
  877. // -----------------------------------------------------------
  878. // Set Port Scale Points
  879. Lilv::ScalePoints lilvScalePoints(lilvPort.get_scale_points());
  880. if (lilvScalePoints.size() > 0)
  881. {
  882. rdfPort->ScalePointCount = lilvScalePoints.size();
  883. rdfPort->ScalePoints = new LV2_RDF_PortScalePoint[rdfPort->ScalePointCount];
  884. uint32_t h = 0;
  885. LILV_FOREACH(scale_points, it, lilvScalePoints)
  886. {
  887. CARLA_SAFE_ASSERT_BREAK(h < rdfPort->ScalePointCount);
  888. Lilv::ScalePoint lilvScalePoint(lilvScalePoints.get(it));
  889. LV2_RDF_PortScalePoint* const rdfScalePoint(&rdfPort->ScalePoints[h++]);
  890. if (const char* const label = Lilv::Node(lilvScalePoint.get_label()).as_string())
  891. rdfScalePoint->Label = carla_strdup(label);
  892. rdfScalePoint->Value = Lilv::Node(lilvScalePoint.get_value()).as_float();
  893. }
  894. }
  895. }
  896. }
  897. // -------------------------------------------------------------------
  898. // Set Plugin Presets
  899. if (doInit)
  900. {
  901. Lilv::Nodes presetNodes(lilvPlugin.get_related(lv2World.preset_preset));
  902. if (presetNodes.size() > 0)
  903. {
  904. // create a list of preset URIs (for checking appliesTo, sorting and unique-ness)
  905. QStringList presetListURIs;
  906. LILV_FOREACH(nodes, it, presetNodes)
  907. {
  908. Lilv::Node presetNode(presetNodes.get(it));
  909. // FIXME - check appliesTo?
  910. QString presetURI(presetNode.as_uri());
  911. if (! (presetURI.trimmed().isEmpty() || presetListURIs.contains(presetURI)))
  912. presetListURIs.append(presetURI);
  913. }
  914. presetListURIs.sort();
  915. // create presets with unique URIs
  916. rdfDescriptor->PresetCount = static_cast<uint32_t>(presetListURIs.count());
  917. rdfDescriptor->Presets = new LV2_RDF_Preset[rdfDescriptor->PresetCount];
  918. // set preset data
  919. LILV_FOREACH(nodes, it, presetNodes)
  920. {
  921. Lilv::Node presetNode(presetNodes.get(it));
  922. if (lv2World.load_resource(presetNode) == -1)
  923. continue;
  924. if (const char* const presetURI = presetNode.as_uri())
  925. {
  926. const int index(presetListURIs.indexOf(QString(presetURI)));
  927. CARLA_SAFE_ASSERT_CONTINUE(index >= 0);
  928. LV2_RDF_Preset* const rdfPreset(&rdfDescriptor->Presets[index]);
  929. // ---------------------------------------------------
  930. // Set Preset Information
  931. {
  932. rdfPreset->URI = carla_strdup(presetURI);
  933. Lilv::Nodes presetLabelNodes(lv2World.find_nodes(presetNode, lv2World.rdfs_label, nullptr));
  934. if (presetLabelNodes.size() > 0)
  935. {
  936. if (const char* const label = presetLabelNodes.get_first().as_string())
  937. rdfPreset->Label = carla_strdup(label);
  938. }
  939. }
  940. }
  941. }
  942. }
  943. }
  944. // -------------------------------------------------------------------
  945. // Set Plugin Features
  946. {
  947. Lilv::Nodes lilvFeatureNodes(lilvPlugin.get_supported_features());
  948. if (lilvFeatureNodes.size() > 0)
  949. {
  950. Lilv::Nodes lilvFeatureNodesR(lilvPlugin.get_required_features());
  951. rdfDescriptor->FeatureCount = lilvFeatureNodes.size();
  952. rdfDescriptor->Features = new LV2_RDF_Feature[rdfDescriptor->FeatureCount];
  953. uint32_t h = 0;
  954. LILV_FOREACH(nodes, it, lilvFeatureNodes)
  955. {
  956. CARLA_SAFE_ASSERT_BREAK(h < rdfDescriptor->FeatureCount);
  957. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(it));
  958. LV2_RDF_Feature* const rdfFeature(&rdfDescriptor->Features[h++]);
  959. rdfFeature->Type = lilvFeatureNodesR.contains(lilvFeatureNode) ? LV2_FEATURE_REQUIRED : LV2_FEATURE_OPTIONAL;
  960. if (const char* const featureURI = lilvFeatureNode.as_uri())
  961. rdfFeature->URI = carla_strdup(featureURI);
  962. else
  963. rdfFeature->URI = nullptr;
  964. }
  965. }
  966. }
  967. // -------------------------------------------------------------------
  968. // Set Plugin Extensions
  969. {
  970. Lilv::Nodes lilvExtensionDataNodes(lilvPlugin.get_extension_data());
  971. if (lilvExtensionDataNodes.size() > 0)
  972. {
  973. rdfDescriptor->ExtensionCount = lilvExtensionDataNodes.size();
  974. rdfDescriptor->Extensions = new LV2_URI[rdfDescriptor->ExtensionCount];
  975. uint32_t h = 0;
  976. LILV_FOREACH(nodes, it, lilvExtensionDataNodes)
  977. {
  978. CARLA_SAFE_ASSERT_BREAK(h < rdfDescriptor->ExtensionCount);
  979. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(it));
  980. LV2_URI* const rdfExtension(&rdfDescriptor->Extensions[h++]);
  981. if (lilvExtensionDataNode.is_uri())
  982. {
  983. if (const char* const extURI = lilvExtensionDataNode.as_uri())
  984. {
  985. *rdfExtension = carla_strdup(extURI);
  986. continue;
  987. }
  988. }
  989. *rdfExtension = nullptr;
  990. }
  991. }
  992. }
  993. // -------------------------------------------------------------------
  994. // Set Plugin UIs
  995. {
  996. Lilv::UIs lilvUIs(lilvPlugin.get_uis());
  997. if (lilvUIs.size() > 0)
  998. {
  999. rdfDescriptor->UICount = lilvUIs.size();
  1000. rdfDescriptor->UIs = new LV2_RDF_UI[rdfDescriptor->UICount];
  1001. uint32_t h = 0;
  1002. LILV_FOREACH(uis, it, lilvUIs)
  1003. {
  1004. CARLA_SAFE_ASSERT_BREAK(h < rdfDescriptor->UICount);
  1005. Lilv::UI lilvUI(lilvUIs.get(it));
  1006. LV2_RDF_UI* const rdfUI(&rdfDescriptor->UIs[h++]);
  1007. // -------------------------------------------------------
  1008. // Set UI Type
  1009. if (lilvUI.is_a(lv2World.ui_gtk2))
  1010. rdfUI->Type = LV2_UI_GTK2;
  1011. else if (lilvUI.is_a(lv2World.ui_gtk3))
  1012. rdfUI->Type = LV2_UI_GTK3;
  1013. else if (lilvUI.is_a(lv2World.ui_qt4))
  1014. rdfUI->Type = LV2_UI_QT4;
  1015. else if (lilvUI.is_a(lv2World.ui_qt5))
  1016. rdfUI->Type = LV2_UI_QT5;
  1017. else if (lilvUI.is_a(lv2World.ui_cocoa))
  1018. rdfUI->Type = LV2_UI_COCOA;
  1019. else if (lilvUI.is_a(lv2World.ui_windows))
  1020. rdfUI->Type = LV2_UI_WINDOWS;
  1021. else if (lilvUI.is_a(lv2World.ui_x11))
  1022. rdfUI->Type = LV2_UI_X11;
  1023. else if (lilvUI.is_a(lv2World.ui_external))
  1024. rdfUI->Type = LV2_UI_EXTERNAL;
  1025. else if (lilvUI.is_a(lv2World.ui_externalOld))
  1026. rdfUI->Type = LV2_UI_OLD_EXTERNAL;
  1027. else if (lilvUI.is_a(lv2World.ui_externalOld2))
  1028. pass();
  1029. else
  1030. carla_stderr("lv2_rdf_new(\"%s\") - UI '%s' is of unknown type", uri, lilvUI.get_uri().as_uri());
  1031. // -------------------------------------------------------
  1032. // Set UI Information
  1033. {
  1034. if (const char* const uiURI = lilvUI.get_uri().as_uri())
  1035. rdfUI->URI = carla_strdup(uiURI);
  1036. if (const char* const uiBinary = lilvUI.get_binary_uri().as_string())
  1037. rdfUI->Binary = carla_strdup(lilv_uri_to_path(uiBinary));
  1038. if (const char* const uiBundle = lilvUI.get_bundle_uri().as_string())
  1039. rdfUI->Bundle = carla_strdup(lilv_uri_to_path(uiBundle));
  1040. }
  1041. // -------------------------------------------------------
  1042. // Set UI Features
  1043. {
  1044. Lilv::Nodes lilvFeatureNodes(lilvUI.get_supported_features());
  1045. if (lilvFeatureNodes.size() > 0)
  1046. {
  1047. Lilv::Nodes lilvFeatureNodesR(lilvUI.get_required_features());
  1048. rdfUI->FeatureCount = lilvFeatureNodes.size();
  1049. rdfUI->Features = new LV2_RDF_Feature[rdfUI->FeatureCount];
  1050. uint32_t h2 = 0;
  1051. LILV_FOREACH(nodes, it2, lilvFeatureNodes)
  1052. {
  1053. CARLA_SAFE_ASSERT_BREAK(h2 < rdfUI->FeatureCount);
  1054. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(it2));
  1055. LV2_RDF_Feature* const rdfFeature(&rdfUI->Features[h2++]);
  1056. rdfFeature->Type = lilvFeatureNodesR.contains(lilvFeatureNode) ? LV2_FEATURE_REQUIRED : LV2_FEATURE_OPTIONAL;
  1057. if (const char* const featureURI = lilvFeatureNode.as_uri())
  1058. rdfFeature->URI = carla_strdup(featureURI);
  1059. else
  1060. rdfFeature->URI = nullptr;
  1061. }
  1062. }
  1063. }
  1064. // -------------------------------------------------------
  1065. // Set UI Extensions
  1066. {
  1067. Lilv::Nodes lilvExtensionDataNodes(lilvUI.get_extension_data());
  1068. if (lilvExtensionDataNodes.size() > 0)
  1069. {
  1070. rdfUI->ExtensionCount = lilvExtensionDataNodes.size();
  1071. rdfUI->Extensions = new LV2_URI[rdfUI->ExtensionCount];
  1072. uint32_t h2 = 0;
  1073. LILV_FOREACH(nodes, it2, lilvExtensionDataNodes)
  1074. {
  1075. CARLA_SAFE_ASSERT_BREAK(h2 < rdfUI->ExtensionCount);
  1076. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(it));
  1077. LV2_URI* const rdfExtension(&rdfUI->Extensions[h2++]);
  1078. if (lilvExtensionDataNode.is_uri())
  1079. {
  1080. if (const char* const extURI = lilvExtensionDataNode.as_uri())
  1081. {
  1082. *rdfExtension = carla_strdup(extURI);
  1083. continue;
  1084. }
  1085. }
  1086. *rdfExtension = nullptr;
  1087. }
  1088. }
  1089. }
  1090. }
  1091. }
  1092. }
  1093. return rdfDescriptor;
  1094. }
  1095. // -----------------------------------------------------------------------
  1096. // Check if we support a plugin port
  1097. static inline
  1098. bool is_lv2_port_supported(const LV2_Property types) noexcept
  1099. {
  1100. if (LV2_IS_PORT_CONTROL(types))
  1101. return true;
  1102. if (LV2_IS_PORT_AUDIO(types))
  1103. return true;
  1104. if (LV2_IS_PORT_CV(types))
  1105. return true;
  1106. if (LV2_IS_PORT_ATOM_SEQUENCE(types))
  1107. return true;
  1108. if (LV2_IS_PORT_EVENT(types))
  1109. return true;
  1110. if (LV2_IS_PORT_MIDI_LL(types))
  1111. return true;
  1112. return false;
  1113. }
  1114. // -----------------------------------------------------------------------
  1115. // Check if we support a plugin feature
  1116. static inline
  1117. bool is_lv2_feature_supported(const LV2_URI uri) noexcept
  1118. {
  1119. CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0', false);
  1120. if (std::strcmp(uri, LV2_BUF_SIZE__boundedBlockLength) == 0)
  1121. return true;
  1122. if (std::strcmp(uri, LV2_BUF_SIZE__fixedBlockLength) == 0)
  1123. return true;
  1124. if (std::strcmp(uri, LV2_BUF_SIZE__powerOf2BlockLength) == 0)
  1125. return true;
  1126. if (std::strcmp(uri, LV2_CORE__hardRTCapable) == 0)
  1127. return true;
  1128. if (std::strcmp(uri, LV2_CORE__inPlaceBroken) == 0)
  1129. return true;
  1130. if (std::strcmp(uri, LV2_CORE__isLive) == 0)
  1131. return true;
  1132. if (std::strcmp(uri, LV2_EVENT_URI) == 0)
  1133. return true;
  1134. if (std::strcmp(uri, LV2_LOG__log) == 0)
  1135. return true;
  1136. if (std::strcmp(uri, LV2_OPTIONS__options) == 0)
  1137. return true;
  1138. if (std::strcmp(uri, LV2_PROGRAMS__Host) == 0)
  1139. return true;
  1140. if (std::strcmp(uri, LV2_RESIZE_PORT__resize) == 0)
  1141. return true;
  1142. if (std::strcmp(uri, LV2_RTSAFE_MEMORY_POOL__Pool) == 0)
  1143. return true;
  1144. if (std::strcmp(uri, LV2_RTSAFE_MEMORY_POOL_DEPRECATED_URI) == 0)
  1145. return true;
  1146. if (std::strcmp(uri, LV2_STATE__makePath) == 0)
  1147. return true;
  1148. if (std::strcmp(uri, LV2_STATE__mapPath) == 0)
  1149. return true;
  1150. if (std::strcmp(uri, LV2_PORT_PROPS__supportsStrictBounds) == 0)
  1151. return true;
  1152. if (std::strcmp(uri, LV2_URI_MAP_URI) == 0)
  1153. return true;
  1154. if (std::strcmp(uri, LV2_URID__map) == 0)
  1155. return true;
  1156. if (std::strcmp(uri, LV2_URID__unmap) == 0)
  1157. return true;
  1158. if (std::strcmp(uri, LV2_WORKER__schedule) == 0)
  1159. return true;
  1160. return false;
  1161. }
  1162. // -----------------------------------------------------------------------
  1163. // Check if we support a plugin or UI feature
  1164. static inline
  1165. bool is_lv2_ui_feature_supported(const LV2_URI uri) noexcept
  1166. {
  1167. CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0', false);
  1168. if (is_lv2_feature_supported(uri))
  1169. return true;
  1170. #ifndef BRIDGE_LV2
  1171. if (std::strcmp(uri, LV2_DATA_ACCESS_URI) == 0)
  1172. return true;
  1173. if (std::strcmp(uri, LV2_INSTANCE_ACCESS_URI) == 0)
  1174. return true;
  1175. #endif
  1176. if (std::strcmp(uri, LV2_UI__fixedSize) == 0)
  1177. return true;
  1178. if (std::strcmp(uri, LV2_UI__idleInterface) == 0)
  1179. return true;
  1180. if (std::strcmp(uri, LV2_UI__makeResident) == 0)
  1181. return true;
  1182. if (std::strcmp(uri, LV2_UI__noUserResize) == 0)
  1183. return true;
  1184. if (std::strcmp(uri, LV2_UI__parent) == 0)
  1185. return true;
  1186. if (std::strcmp(uri, LV2_UI__portMap) == 0)
  1187. return true;
  1188. if (std::strcmp(uri, LV2_UI__portSubscribe) == 0)
  1189. return true;
  1190. if (std::strcmp(uri, LV2_UI__resize) == 0)
  1191. return true;
  1192. if (std::strcmp(uri, LV2_UI__touch) == 0)
  1193. return true;
  1194. if (std::strcmp(uri, LV2_EXTERNAL_UI__Widget) == 0)
  1195. return true;
  1196. if (std::strcmp(uri, LV2_EXTERNAL_UI_DEPRECATED_URI) == 0)
  1197. return true;
  1198. return false;
  1199. }
  1200. // -----------------------------------------------------------------------
  1201. #endif // CARLA_LV2_UTILS_HPP_INCLUDED