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.

1495 lines
63KB

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