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.

1379 lines
58KB

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