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.

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