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.

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