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.

1344 lines
56KB

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