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.

1174 lines
49KB

  1. /*
  2. * Carla LV2 utils
  3. * Copyright (C) 2011-2013 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * 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 COPYING file
  16. */
  17. #ifndef __CARLA_LV2_UTILS_HPP__
  18. #define __CARLA_LV2_UTILS_HPP__
  19. #include "carla_utils.hpp"
  20. // TODO - presets handling
  21. #include "lv2/lv2.h"
  22. #include "lv2/atom.h"
  23. #include "lv2/atom-forge.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. #include "lv2/midi.h"
  33. #include "lv2/options.h"
  34. #include "lv2/parameters.h"
  35. #include "lv2/patch.h"
  36. #include "lv2/port-groups.h"
  37. #include "lv2/port-props.h"
  38. #include "lv2/presets.h"
  39. // resize-port
  40. #include "lv2/state.h"
  41. #include "lv2/time.h"
  42. #include "lv2/ui.h"
  43. #include "lv2/units.h"
  44. #include "lv2/uri-map.h"
  45. #include "lv2/urid.h"
  46. #include "lv2/worker.h"
  47. #include "lv2/lv2-miditype.h"
  48. #include "lv2/lv2-midifunctions.h"
  49. #include "lv2/lv2_external_ui.h"
  50. #include "lv2/lv2_programs.h"
  51. #include "lv2/lv2_rtmempool.h"
  52. #include "lv2_rdf.hpp"
  53. #include "lilv/lilvmm.hpp"
  54. #include "sratom/sratom.h"
  55. #include <QtCore/QMap>
  56. #include <QtCore/QStringList>
  57. // -------------------------------------------------
  58. // Define namespaces and missing prefixes
  59. #define NS_dct "http://purl.org/dc/terms/"
  60. #define NS_doap "http://usefulinc.com/ns/doap#"
  61. #define NS_rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  62. #define NS_rdfs "http://www.w3.org/2000/01/rdf-schema#"
  63. #define NS_llmm "http://ll-plugins.nongnu.org/lv2/ext/midimap#"
  64. #define LV2_MIDI_Map__CC "http://ll-plugins.nongnu.org/lv2/namespace#CC"
  65. #define LV2_MIDI_Map__NRPN "http://ll-plugins.nongnu.org/lv2/namespace#NRPN"
  66. #define LV2_MIDI_LL__MidiPort "http://ll-plugins.nongnu.org/lv2/ext/MidiPort"
  67. #define LV2_UI__Qt5UI LV2_UI_PREFIX "Qt5UI"
  68. #define LV2_UI__makeResident LV2_UI_PREFIX "makeResident"
  69. // -------------------------------------------------
  70. // Custom Atom types
  71. struct LV2_Atom_MidiEvent {
  72. LV2_Atom_Event event;
  73. uint8_t data[3];
  74. };
  75. // FIXME ?
  76. struct LV2_Atom_Worker_Body {
  77. uint32_t size;
  78. const void* data;
  79. };
  80. struct LV2_Atom_Worker {
  81. LV2_Atom atom;
  82. LV2_Atom_Worker_Body body;
  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_expander;
  110. Lilv::Node class_filter;
  111. Lilv::Node class_flanger;
  112. Lilv::Node class_function;
  113. Lilv::Node class_gate;
  114. Lilv::Node class_generator;
  115. Lilv::Node class_highpass;
  116. Lilv::Node class_instrument;
  117. Lilv::Node class_limiter;
  118. Lilv::Node class_lowpass;
  119. Lilv::Node class_mixer;
  120. Lilv::Node class_modulator;
  121. Lilv::Node class_multiEQ;
  122. Lilv::Node class_oscillator;
  123. Lilv::Node class_paraEQ;
  124. Lilv::Node class_phaser;
  125. Lilv::Node class_pitch;
  126. Lilv::Node class_reverb;
  127. Lilv::Node class_simulator;
  128. Lilv::Node class_spatial;
  129. Lilv::Node class_spectral;
  130. Lilv::Node class_utility;
  131. Lilv::Node class_waveshaper;
  132. // Port Types
  133. Lilv::Node port_input;
  134. Lilv::Node port_output;
  135. Lilv::Node port_control;
  136. Lilv::Node port_audio;
  137. Lilv::Node port_cv;
  138. Lilv::Node port_atom;
  139. Lilv::Node port_event;
  140. Lilv::Node port_midi;
  141. // Port Properties
  142. Lilv::Node pprop_optional;
  143. Lilv::Node pprop_enumeration;
  144. Lilv::Node pprop_integer;
  145. Lilv::Node pprop_sampleRate;
  146. Lilv::Node pprop_toggled;
  147. Lilv::Node pprop_artifacts;
  148. Lilv::Node pprop_continuousCV;
  149. Lilv::Node pprop_discreteCV;
  150. Lilv::Node pprop_expensive;
  151. Lilv::Node pprop_strictBounds;
  152. Lilv::Node pprop_logarithmic;
  153. Lilv::Node pprop_notAutomatic;
  154. Lilv::Node pprop_notOnGUI;
  155. Lilv::Node pprop_trigger;
  156. // Unit Hints
  157. Lilv::Node unit_name;
  158. Lilv::Node unit_render;
  159. Lilv::Node unit_symbol;
  160. Lilv::Node unit_unit;
  161. // UI Types
  162. Lilv::Node ui_gtk2;
  163. Lilv::Node ui_gtk3;
  164. Lilv::Node ui_qt4;
  165. Lilv::Node ui_qt5;
  166. Lilv::Node ui_cocoa;
  167. Lilv::Node ui_windows;
  168. Lilv::Node ui_x11;
  169. Lilv::Node ui_external;
  170. Lilv::Node ui_externalOld;
  171. // Misc
  172. Lilv::Node atom_bufferType;
  173. Lilv::Node atom_sequence;
  174. Lilv::Node atom_supports;
  175. Lilv::Node preset_preset;
  176. Lilv::Node state_state;
  177. Lilv::Node value_default;
  178. Lilv::Node value_minimum;
  179. Lilv::Node value_maximum;
  180. // Port Data Types
  181. Lilv::Node midi_event;
  182. Lilv::Node patch_message;
  183. // MIDI CC
  184. Lilv::Node mm_defaultControl;
  185. Lilv::Node mm_controlType;
  186. Lilv::Node mm_controlNumber;
  187. // Other
  188. Lilv::Node dct_replaces;
  189. Lilv::Node doap_license;
  190. Lilv::Node rdf_type;
  191. Lilv::Node rdfs_label;
  192. // ----------------------------------------------------------
  193. Lv2WorldClass()
  194. : Lilv::World(),
  195. port (new_uri(LV2_CORE__port)),
  196. symbol (new_uri(LV2_CORE__symbol)),
  197. designation (new_uri(LV2_CORE__designation)),
  198. freeWheeling (new_uri(LV2_CORE__freeWheeling)),
  199. reportsLatency (new_uri(LV2_CORE__reportsLatency)),
  200. class_allpass (new_uri(LV2_CORE__AllpassPlugin)),
  201. class_amplifier (new_uri(LV2_CORE__AmplifierPlugin)),
  202. class_analyzer (new_uri(LV2_CORE__AnalyserPlugin)),
  203. class_bandpass (new_uri(LV2_CORE__BandpassPlugin)),
  204. class_chorus (new_uri(LV2_CORE__ChorusPlugin)),
  205. class_comb (new_uri(LV2_CORE__CombPlugin)),
  206. class_compressor (new_uri(LV2_CORE__CompressorPlugin)),
  207. class_constant (new_uri(LV2_CORE__ConstantPlugin)),
  208. class_converter (new_uri(LV2_CORE__ConverterPlugin)),
  209. class_delay (new_uri(LV2_CORE__DelayPlugin)),
  210. class_distortion (new_uri(LV2_CORE__DistortionPlugin)),
  211. class_dynamics (new_uri(LV2_CORE__DynamicsPlugin)),
  212. class_eq (new_uri(LV2_CORE__EQPlugin)),
  213. class_expander (new_uri(LV2_CORE__ExpanderPlugin)),
  214. class_filter (new_uri(LV2_CORE__FilterPlugin)),
  215. class_flanger (new_uri(LV2_CORE__FlangerPlugin)),
  216. class_function (new_uri(LV2_CORE__FunctionPlugin)),
  217. class_gate (new_uri(LV2_CORE__GatePlugin)),
  218. class_generator (new_uri(LV2_CORE__GeneratorPlugin)),
  219. class_highpass (new_uri(LV2_CORE__HighpassPlugin)),
  220. class_instrument (new_uri(LV2_CORE__InstrumentPlugin)),
  221. class_limiter (new_uri(LV2_CORE__LimiterPlugin)),
  222. class_lowpass (new_uri(LV2_CORE__LowpassPlugin)),
  223. class_mixer (new_uri(LV2_CORE__MixerPlugin)),
  224. class_modulator (new_uri(LV2_CORE__ModulatorPlugin)),
  225. class_multiEQ (new_uri(LV2_CORE__MultiEQPlugin)),
  226. class_oscillator (new_uri(LV2_CORE__OscillatorPlugin)),
  227. class_paraEQ (new_uri(LV2_CORE__ParaEQPlugin)),
  228. class_phaser (new_uri(LV2_CORE__PhaserPlugin)),
  229. class_pitch (new_uri(LV2_CORE__PitchPlugin)),
  230. class_reverb (new_uri(LV2_CORE__ReverbPlugin)),
  231. class_simulator (new_uri(LV2_CORE__SimulatorPlugin)),
  232. class_spatial (new_uri(LV2_CORE__SpatialPlugin)),
  233. class_spectral (new_uri(LV2_CORE__SpectralPlugin)),
  234. class_utility (new_uri(LV2_CORE__UtilityPlugin)),
  235. class_waveshaper (new_uri(LV2_CORE__WaveshaperPlugin)),
  236. port_input (new_uri(LV2_CORE__InputPort)),
  237. port_output (new_uri(LV2_CORE__OutputPort)),
  238. port_control (new_uri(LV2_CORE__ControlPort)),
  239. port_audio (new_uri(LV2_CORE__AudioPort)),
  240. port_cv (new_uri(LV2_CORE__CVPort)),
  241. port_atom (new_uri(LV2_ATOM__AtomPort)),
  242. port_event (new_uri(LV2_EVENT__EventPort)),
  243. port_midi (new_uri(LV2_MIDI_LL__MidiPort)),
  244. pprop_optional (new_uri(LV2_CORE__connectionOptional)),
  245. pprop_enumeration (new_uri(LV2_CORE__enumeration)),
  246. pprop_integer (new_uri(LV2_CORE__integer)),
  247. pprop_sampleRate (new_uri(LV2_CORE__sampleRate)),
  248. pprop_toggled (new_uri(LV2_CORE__toggled)),
  249. pprop_artifacts (new_uri(LV2_PORT_PROPS__causesArtifacts)),
  250. pprop_continuousCV (new_uri(LV2_PORT_PROPS__continuousCV)),
  251. pprop_discreteCV (new_uri(LV2_PORT_PROPS__discreteCV)),
  252. pprop_expensive (new_uri(LV2_PORT_PROPS__expensive)),
  253. pprop_strictBounds (new_uri(LV2_PORT_PROPS__hasStrictBounds)),
  254. pprop_logarithmic (new_uri(LV2_PORT_PROPS__logarithmic)),
  255. pprop_notAutomatic (new_uri(LV2_PORT_PROPS__notAutomatic)),
  256. pprop_notOnGUI (new_uri(LV2_PORT_PROPS__notOnGUI)),
  257. pprop_trigger (new_uri(LV2_PORT_PROPS__trigger)),
  258. unit_name (new_uri(LV2_UNITS__name)),
  259. unit_render (new_uri(LV2_UNITS__render)),
  260. unit_symbol (new_uri(LV2_UNITS__symbol)),
  261. unit_unit (new_uri(LV2_UNITS__unit)),
  262. ui_gtk2 (new_uri(LV2_UI__GtkUI)),
  263. ui_gtk3 (new_uri(LV2_UI__Gtk3UI)),
  264. ui_qt4 (new_uri(LV2_UI__Qt4UI)),
  265. ui_qt5 (new_uri(LV2_UI__Qt5UI)),
  266. ui_cocoa (new_uri(LV2_UI__CocoaUI)),
  267. ui_windows (new_uri(LV2_UI__WindowsUI)),
  268. ui_x11 (new_uri(LV2_UI__X11UI)),
  269. ui_external (new_uri(LV2_EXTERNAL_UI__Widget)),
  270. ui_externalOld (new_uri(LV2_EXTERNAL_UI_DEPRECATED_URI)),
  271. atom_bufferType (new_uri(LV2_ATOM__bufferType)),
  272. atom_sequence (new_uri(LV2_ATOM__Sequence)),
  273. atom_supports (new_uri(LV2_ATOM__supports)),
  274. preset_preset (new_uri(LV2_PRESETS__Preset)),
  275. state_state (new_uri(LV2_STATE__state)),
  276. value_default (new_uri(LV2_CORE__default)),
  277. value_minimum (new_uri(LV2_CORE__minimum)),
  278. value_maximum (new_uri(LV2_CORE__maximum)),
  279. midi_event (new_uri(LV2_MIDI__MidiEvent)),
  280. patch_message (new_uri(LV2_PATCH__Message)),
  281. mm_defaultControl (new_uri(NS_llmm "defaultMidiController")),
  282. mm_controlType (new_uri(NS_llmm "controllerType")),
  283. mm_controlNumber (new_uri(NS_llmm "controllerNumber")),
  284. dct_replaces (new_uri(NS_dct "replaces")),
  285. doap_license (new_uri(NS_doap "license")),
  286. rdf_type (new_uri(NS_rdf "type")),
  287. rdfs_label (new_uri(NS_rdfs "label"))
  288. {
  289. needInit = true;
  290. }
  291. void init()
  292. {
  293. if (! needInit)
  294. return;
  295. needInit = false;
  296. Lilv::World::load_all();
  297. }
  298. private:
  299. bool needInit;
  300. };
  301. // -------------------------------------------------
  302. // Our LV2 World class object
  303. extern Lv2WorldClass lv2World;
  304. // -------------------------------------------------
  305. // Create new RDF object (using lilv)
  306. static inline
  307. const LV2_RDF_Descriptor* lv2_rdf_new(const LV2_URI uri)
  308. {
  309. CARLA_ASSERT(uri);
  310. if (! uri)
  311. return nullptr;
  312. Lilv::Plugins lilvPlugins = lv2World.get_all_plugins();
  313. LILV_FOREACH(plugins, i, lilvPlugins)
  314. {
  315. Lilv::Plugin lilvPlugin(lilvPlugins.get(i));
  316. if (strcmp(lilvPlugin.get_uri().as_string(), uri))
  317. continue;
  318. LV2_RDF_Descriptor* const rdfDescriptor = new LV2_RDF_Descriptor;
  319. // --------------------------------------------------
  320. // Set Plugin Type
  321. {
  322. Lilv::Nodes typeNodes(lilvPlugin.get_value(lv2World.rdf_type));
  323. if (typeNodes.size() > 0)
  324. {
  325. #if 0
  326. if (typeNodes.contains(lv2World.class_allpass))
  327. rdfDescriptor->Type |= LV2_PLUGIN_ALLPASS;
  328. if (typeNodes.contains(lv2World.class_amplifier))
  329. rdfDescriptor->Type |= LV2_PLUGIN_AMPLIFIER;
  330. if (typeNodes.contains(lv2World.class_analyzer))
  331. rdfDescriptor->Type |= LV2_PLUGIN_ANALYSER;
  332. if (typeNodes.contains(lv2World.class_bandpass))
  333. rdfDescriptor->Type |= LV2_PLUGIN_BANDPASS;
  334. if (typeNodes.contains(lv2World.class_chorus))
  335. rdfDescriptor->Type |= LV2_PLUGIN_CHORUS;
  336. if (typeNodes.contains(lv2World.class_comb))
  337. rdfDescriptor->Type |= LV2_PLUGIN_COMB;
  338. if (typeNodes.contains(lv2World.class_compressor))
  339. rdfDescriptor->Type |= LV2_PLUGIN_COMPRESSOR;
  340. if (typeNodes.contains(lv2World.class_constant))
  341. rdfDescriptor->Type |= LV2_PLUGIN_CONSTANT;
  342. if (typeNodes.contains(lv2World.class_converter))
  343. rdfDescriptor->Type |= LV2_PLUGIN_CONVERTER;
  344. if (typeNodes.contains(lv2World.class_delay))
  345. rdfDescriptor->Type |= LV2_PLUGIN_DELAY;
  346. if (typeNodes.contains(lv2World.class_distortion))
  347. rdfDescriptor->Type |= LV2_PLUGIN_DISTORTION;
  348. if (typeNodes.contains(lv2World.class_dynamics))
  349. rdfDescriptor->Type |= LV2_PLUGIN_DYNAMICS;
  350. if (typeNodes.contains(lv2World.class_eq))
  351. rdfDescriptor->Type |= LV2_PLUGIN_EQ;
  352. if (typeNodes.contains(lv2World.class_expander))
  353. rdfDescriptor->Type |= LV2_PLUGIN_EXPANDER;
  354. if (typeNodes.contains(lv2World.class_filter))
  355. rdfDescriptor->Type |= LV2_PLUGIN_FILTER;
  356. if (typeNodes.contains(lv2World.class_flanger))
  357. rdfDescriptor->Type |= LV2_PLUGIN_FLANGER;
  358. if (typeNodes.contains(lv2World.class_function))
  359. rdfDescriptor->Type |= LV2_PLUGIN_FUNCTION;
  360. if (typeNodes.contains(lv2World.class_gate))
  361. rdfDescriptor->Type |= LV2_PLUGIN_GATE;
  362. if (typeNodes.contains(lv2World.class_generator))
  363. rdfDescriptor->Type |= LV2_PLUGIN_GENERATOR;
  364. if (typeNodes.contains(lv2World.class_highpass))
  365. rdfDescriptor->Type |= LV2_PLUGIN_HIGHPASS;
  366. if (typeNodes.contains(lv2World.class_instrument))
  367. rdfDescriptor->Type |= LV2_PLUGIN_INSTRUMENT;
  368. if (typeNodes.contains(lv2World.class_limiter))
  369. rdfDescriptor->Type |= LV2_PLUGIN_LIMITER;
  370. if (typeNodes.contains(lv2World.class_lowpass))
  371. rdfDescriptor->Type |= LV2_PLUGIN_LOWPASS;
  372. if (typeNodes.contains(lv2World.class_mixer))
  373. rdfDescriptor->Type |= LV2_PLUGIN_MIXER;
  374. if (typeNodes.contains(lv2World.class_modulator))
  375. rdfDescriptor->Type |= LV2_PLUGIN_MODULATOR;
  376. if (typeNodes.contains(lv2World.class_multiEQ))
  377. rdfDescriptor->Type |= LV2_PLUGIN_MULTI_EQ;
  378. if (typeNodes.contains(lv2World.class_oscillator))
  379. rdfDescriptor->Type |= LV2_PLUGIN_OSCILLATOR;
  380. if (typeNodes.contains(lv2World.class_paraEQ))
  381. rdfDescriptor->Type |= LV2_PLUGIN_PARA_EQ;
  382. if (typeNodes.contains(lv2World.class_phaser))
  383. rdfDescriptor->Type |= LV2_PLUGIN_PHASER;
  384. if (typeNodes.contains(lv2World.class_pitch))
  385. rdfDescriptor->Type |= LV2_PLUGIN_PITCH;
  386. if (typeNodes.contains(lv2World.class_reverb))
  387. rdfDescriptor->Type |= LV2_PLUGIN_REVERB;
  388. if (typeNodes.contains(lv2World.class_simulator))
  389. rdfDescriptor->Type |= LV2_PLUGIN_SIMULATOR;
  390. if (typeNodes.contains(lv2World.class_spatial))
  391. rdfDescriptor->Type |= LV2_PLUGIN_SPATIAL;
  392. if (typeNodes.contains(lv2World.class_spectral))
  393. rdfDescriptor->Type |= LV2_PLUGIN_SPECTRAL;
  394. if (typeNodes.contains(lv2World.class_utility))
  395. rdfDescriptor->Type |= LV2_PLUGIN_UTILITY;
  396. if (typeNodes.contains(lv2World.class_waveshaper))
  397. rdfDescriptor->Type |= LV2_PLUGIN_WAVESHAPER;
  398. #endif
  399. }
  400. }
  401. // --------------------------------------------------
  402. // Set Plugin Information
  403. {
  404. rdfDescriptor->URI = strdup(uri);
  405. rdfDescriptor->Binary = strdup(lilv_uri_to_path(lilvPlugin.get_library_uri().as_string()));
  406. rdfDescriptor->Bundle = strdup(lilv_uri_to_path(lilvPlugin.get_bundle_uri().as_string()));
  407. if (lilvPlugin.get_name())
  408. rdfDescriptor->Name = strdup(lilvPlugin.get_name().as_string());
  409. if (lilvPlugin.get_author_name())
  410. rdfDescriptor->Author = strdup(lilvPlugin.get_author_name().as_string());
  411. Lilv::Nodes licenseNodes(lilvPlugin.get_value(lv2World.doap_license));
  412. if (licenseNodes.size() > 0)
  413. rdfDescriptor->License = strdup(licenseNodes.get_first().as_string());
  414. }
  415. // --------------------------------------------------
  416. // Set Plugin UniqueID
  417. {
  418. Lilv::Nodes replaceNodes(lilvPlugin.get_value(lv2World.dct_replaces));
  419. if (replaceNodes.size() > 0)
  420. {
  421. Lilv::Node replaceNode(replaceNodes.get_first());
  422. if (replaceNode.is_uri())
  423. {
  424. const QString replaceURI(replaceNode.as_uri());
  425. if (replaceURI.startsWith("urn:"))
  426. {
  427. const QString replaceId(replaceURI.split(":").last());
  428. bool ok;
  429. long uniqueId = replaceId.toLong(&ok);
  430. if (ok && uniqueId > 0)
  431. rdfDescriptor->UniqueID = uniqueId;
  432. }
  433. }
  434. }
  435. }
  436. // --------------------------------------------------
  437. // Set Plugin Ports
  438. if (lilvPlugin.get_num_ports() > 0)
  439. {
  440. rdfDescriptor->PortCount = lilvPlugin.get_num_ports();
  441. rdfDescriptor->Ports = new LV2_RDF_Port[rdfDescriptor->PortCount];
  442. for (uint32_t j = 0; j < rdfDescriptor->PortCount; j++)
  443. {
  444. Lilv::Port lilvPort(lilvPlugin.get_port_by_index(j));
  445. LV2_RDF_Port* const rdf_port = &rdfDescriptor->Ports[j];
  446. // --------------------------------------
  447. // Set Port Information (first)
  448. {
  449. rdf_port->Name = strdup(Lilv::Node(lilvPort.get_name()).as_string());
  450. rdf_port->Symbol = strdup(Lilv::Node(lilvPort.get_symbol()).as_string());
  451. }
  452. // --------------------------------------
  453. // Set Port Mode and Type
  454. {
  455. #if 0
  456. // Mode
  457. if (lilvPort.is_a(lv2World.port_input))
  458. rdf_port->Type |= LV2_PORT_INPUT;
  459. else if (lilvPort.is_a(lv2World.port_output))
  460. rdf_port->Type |= LV2_PORT_OUTPUT;
  461. else
  462. qWarning("lv2_rdf_new(\"%s\") - port '%s' is not input or output", uri, rdf_port->Name);
  463. // Type
  464. if (lilvPort.is_a(lv2World.port_control))
  465. rdf_port->Type |= LV2_PORT_CONTROL;
  466. else if (lilvPort.is_a(lv2World.port_audio))
  467. rdf_port->Type |= LV2_PORT_AUDIO;
  468. else if (lilvPort.is_a(lv2World.port_cv))
  469. rdf_port->Type |= LV2_PORT_CV;
  470. else if (lilvPort.is_a(lv2World.port_atom))
  471. {
  472. rdf_port->Type |= LV2_PORT_ATOM;
  473. Lilv::Nodes bufferTypeNodes(lilvPort.get_value(lv2World.atom_bufferType));
  474. if (bufferTypeNodes.contains(lv2World.atom_Sequence))
  475. rdf_port->Type |= LV2_PORT_ATOM_SEQUENCE;
  476. Lilv::Nodes supportNodes(lilvPort.get_value(lv2World.atom_supports));
  477. if (supportNodes.contains(lv2World.midi_event))
  478. rdf_port->Type |= LV2_PORT_DATA_MIDI_EVENT;
  479. if (supportNodes.contains(lv2World.patch_message))
  480. rdf_port->Type |= LV2_PORT_DATA_PATCH_MESSAGE;
  481. }
  482. else if (lilvPort.is_a(lv2World.port_event))
  483. {
  484. rdf_port->Type |= LV2_PORT_EVENT;
  485. if (lilvPort.supports_event(lv2World.midi_event))
  486. rdf_port->Type |= LV2_PORT_SUPPORTS_MIDI_EVENT;
  487. }
  488. else if (lilvPort.is_a(lv2World.port_midi))
  489. {
  490. rdf_port->Type |= LV2_PORT_MIDI_LL;
  491. rdf_port->Type |= LV2_PORT_SUPPORTS_MIDI_EVENT;
  492. }
  493. else
  494. #endif
  495. qWarning("lv2_rdf_new(\"%s\") - port '%s' is of unkown type", uri, rdf_port->Name);
  496. }
  497. // --------------------------------------
  498. // Set Port Properties
  499. {
  500. if (lilvPort.has_property(lv2World.pprop_optional))
  501. rdf_port->Properties = LV2_PORT_OPTIONAL;
  502. if (lilvPort.has_property(lv2World.pprop_enumeration))
  503. rdf_port->Properties = LV2_PORT_ENUMERATION;
  504. if (lilvPort.has_property(lv2World.pprop_integer))
  505. rdf_port->Properties = LV2_PORT_INTEGER;
  506. if (lilvPort.has_property(lv2World.pprop_sampleRate))
  507. rdf_port->Properties = LV2_PORT_SAMPLE_RATE;
  508. if (lilvPort.has_property(lv2World.pprop_toggled))
  509. rdf_port->Properties = LV2_PORT_TOGGLED;
  510. if (lilvPort.has_property(lv2World.pprop_artifacts))
  511. rdf_port->Properties = LV2_PORT_CAUSES_ARTIFACTS;
  512. if (lilvPort.has_property(lv2World.pprop_continuousCV))
  513. rdf_port->Properties = LV2_PORT_CONTINUOUS_CV;
  514. if (lilvPort.has_property(lv2World.pprop_discreteCV))
  515. rdf_port->Properties = LV2_PORT_DISCRETE_CV;
  516. if (lilvPort.has_property(lv2World.pprop_expensive))
  517. rdf_port->Properties = LV2_PORT_EXPENSIVE;
  518. if (lilvPort.has_property(lv2World.pprop_strictBounds))
  519. rdf_port->Properties = LV2_PORT_STRICT_BOUNDS;
  520. if (lilvPort.has_property(lv2World.pprop_logarithmic))
  521. rdf_port->Properties = LV2_PORT_LOGARITHMIC;
  522. if (lilvPort.has_property(lv2World.pprop_notAutomatic))
  523. rdf_port->Properties = LV2_PORT_NOT_AUTOMATIC;
  524. if (lilvPort.has_property(lv2World.pprop_notOnGUI))
  525. rdf_port->Properties = LV2_PORT_NOT_ON_GUI;
  526. if (lilvPort.has_property(lv2World.pprop_trigger))
  527. rdf_port->Properties = LV2_PORT_TRIGGER;
  528. if (lilvPort.has_property(lv2World.reportsLatency))
  529. rdf_port->Designation = LV2_PORT_DESIGNATION_LATENCY;
  530. }
  531. // --------------------------------------
  532. // Set Port Designation
  533. {
  534. Lilv::Nodes designationNodes(lilvPort.get_value(lv2World.designation));
  535. if (designationNodes.size() > 0)
  536. {
  537. const char* const designation = designationNodes.get_first().as_string();
  538. if (strcmp(designation, LV2_CORE__freeWheeling) == 0)
  539. rdf_port->Designation = LV2_PORT_DESIGNATION_FREEWHEELING;
  540. else if (strcmp(designation, LV2_CORE__latency) == 0)
  541. rdf_port->Designation = LV2_PORT_DESIGNATION_LATENCY;
  542. else if (strcmp(designation, LV2_PARAMETERS__sampleRate) == 0)
  543. rdf_port->Designation = LV2_PORT_DESIGNATION_SAMPLE_RATE;
  544. else if (strcmp(designation, LV2_TIME__bar) == 0)
  545. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BAR;
  546. else if (strcmp(designation, LV2_TIME__barBeat) == 0)
  547. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BAR_BEAT;
  548. else if (strcmp(designation, LV2_TIME__beat) == 0)
  549. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BEAT;
  550. else if (strcmp(designation, LV2_TIME__beatUnit) == 0)
  551. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BEAT_UNIT;
  552. else if (strcmp(designation, LV2_TIME__beatsPerBar) == 0)
  553. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BEATS_PER_BAR;
  554. else if (strcmp(designation, LV2_TIME__beatsPerMinute) == 0)
  555. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BEATS_PER_MINUTE;
  556. else if (strcmp(designation, LV2_TIME__frame) == 0)
  557. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_FRAME;
  558. else if (strcmp(designation, LV2_TIME__framesPerSecond) == 0)
  559. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_FRAMES_PER_SECOND;
  560. else if (strcmp(designation, LV2_TIME__position) == 0)
  561. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_POSITION;
  562. else if (strcmp(designation, LV2_TIME__speed) == 0)
  563. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_SPEED;
  564. else if (strncmp(designation, LV2_PARAMETERS_PREFIX, strlen(LV2_PARAMETERS_PREFIX)) == 0)
  565. pass();
  566. else if (strncmp(designation, LV2_PORT_GROUPS_PREFIX, strlen(LV2_PORT_GROUPS_PREFIX)) == 0)
  567. pass();
  568. else
  569. qWarning("lv2_rdf_new(\"%s\") - got unknown Port Designation '%s'", uri, designation);
  570. }
  571. }
  572. // --------------------------------------
  573. // Set Port MIDI Map
  574. {
  575. Lilv::Nodes midiMapNodes(lilvPort.get_value(lv2World.mm_defaultControl));
  576. if (midiMapNodes.size() > 0)
  577. {
  578. Lilv::Node midiMapNode(midiMapNodes.get_first());
  579. if (midiMapNode.is_blank())
  580. {
  581. Lilv::Nodes midiMapTypeNodes(lv2World.find_nodes(midiMapNode, lv2World.mm_controlType, nullptr));
  582. Lilv::Nodes midiMapNumberNodes(lv2World.find_nodes(midiMapNode, lv2World.mm_controlNumber, nullptr));
  583. if (midiMapTypeNodes.size() == 1 && midiMapNumberNodes.size() == 1)
  584. {
  585. const char* const midiMapType = midiMapTypeNodes.get_first().as_string();
  586. if (strcmp(midiMapType, LV2_MIDI_Map__CC) == 0)
  587. rdf_port->MidiMap.Type = LV2_PORT_MIDI_MAP_CC;
  588. else if (strcmp(midiMapType, LV2_MIDI_Map__NRPN) == 0)
  589. rdf_port->MidiMap.Type = LV2_PORT_MIDI_MAP_NRPN;
  590. else
  591. qWarning("lv2_rdf_new(\"%s\") - got unknown Port Midi Map type '%s'", uri, midiMapType);
  592. rdf_port->MidiMap.Number = midiMapNumberNodes.get_first().as_int();
  593. }
  594. }
  595. }
  596. }
  597. // --------------------------------------
  598. // Set Port Points
  599. {
  600. Lilv::Nodes valueNodes(lilvPort.get_value(lv2World.value_default));
  601. if (valueNodes.size() > 0)
  602. {
  603. rdf_port->Points.Hints |= LV2_PORT_POINT_DEFAULT;
  604. rdf_port->Points.Default = valueNodes.get_first().as_float();
  605. }
  606. valueNodes = lilvPort.get_value(lv2World.value_minimum);
  607. if (valueNodes.size() > 0)
  608. {
  609. rdf_port->Points.Hints |= LV2_PORT_POINT_MINIMUM;
  610. rdf_port->Points.Minimum = valueNodes.get_first().as_float();
  611. }
  612. valueNodes = lilvPort.get_value(lv2World.value_maximum);
  613. if (valueNodes.size() > 0)
  614. {
  615. rdf_port->Points.Hints |= LV2_PORT_POINT_MAXIMUM;
  616. rdf_port->Points.Maximum = valueNodes.get_first().as_float();
  617. }
  618. }
  619. // --------------------------------------
  620. // Set Port Unit
  621. {
  622. Lilv::Nodes unitTypeNodes(lilvPort.get_value(lv2World.unit_unit));
  623. if (unitTypeNodes.size() > 0)
  624. {
  625. rdf_port->Unit.Hints |= LV2_PORT_UNIT_UNIT;
  626. const char* const unitType = unitTypeNodes.get_first().as_uri();
  627. if (strcmp(unitType, LV2_UNITS__bar) == 0)
  628. rdf_port->Unit.Unit = LV2_PORT_UNIT_BAR;
  629. else if (strcmp(unitType, LV2_UNITS__beat) == 0)
  630. rdf_port->Unit.Unit = LV2_PORT_UNIT_BEAT;
  631. else if (strcmp(unitType, LV2_UNITS__bpm) == 0)
  632. rdf_port->Unit.Unit = LV2_PORT_UNIT_BPM;
  633. else if (strcmp(unitType, LV2_UNITS__cent) == 0)
  634. rdf_port->Unit.Unit = LV2_PORT_UNIT_CENT;
  635. else if (strcmp(unitType, LV2_UNITS__cm) == 0)
  636. rdf_port->Unit.Unit = LV2_PORT_UNIT_CM;
  637. else if (strcmp(unitType, LV2_UNITS__coef) == 0)
  638. rdf_port->Unit.Unit = LV2_PORT_UNIT_COEF;
  639. else if (strcmp(unitType, LV2_UNITS__db) == 0)
  640. rdf_port->Unit.Unit = LV2_PORT_UNIT_DB;
  641. else if (strcmp(unitType, LV2_UNITS__degree) == 0)
  642. rdf_port->Unit.Unit = LV2_PORT_UNIT_DEGREE;
  643. else if (strcmp(unitType, LV2_UNITS__frame) == 0)
  644. rdf_port->Unit.Unit = LV2_PORT_UNIT_FRAME;
  645. else if (strcmp(unitType, LV2_UNITS__hz) == 0)
  646. rdf_port->Unit.Unit = LV2_PORT_UNIT_HZ;
  647. else if (strcmp(unitType, LV2_UNITS__inch) == 0)
  648. rdf_port->Unit.Unit = LV2_PORT_UNIT_INCH;
  649. else if (strcmp(unitType, LV2_UNITS__khz) == 0)
  650. rdf_port->Unit.Unit = LV2_PORT_UNIT_KHZ;
  651. else if (strcmp(unitType, LV2_UNITS__km) == 0)
  652. rdf_port->Unit.Unit = LV2_PORT_UNIT_KM;
  653. else if (strcmp(unitType, LV2_UNITS__m) == 0)
  654. rdf_port->Unit.Unit = LV2_PORT_UNIT_M;
  655. else if (strcmp(unitType, LV2_UNITS__mhz) == 0)
  656. rdf_port->Unit.Unit = LV2_PORT_UNIT_MHZ;
  657. else if (strcmp(unitType, LV2_UNITS__midiNote) == 0)
  658. rdf_port->Unit.Unit = LV2_PORT_UNIT_MIDINOTE;
  659. else if (strcmp(unitType, LV2_UNITS__mile) == 0)
  660. rdf_port->Unit.Unit = LV2_PORT_UNIT_MILE;
  661. else if (strcmp(unitType, LV2_UNITS__min) == 0)
  662. rdf_port->Unit.Unit = LV2_PORT_UNIT_MIN;
  663. else if (strcmp(unitType, LV2_UNITS__mm) == 0)
  664. rdf_port->Unit.Unit = LV2_PORT_UNIT_MM;
  665. else if (strcmp(unitType, LV2_UNITS__ms) == 0)
  666. rdf_port->Unit.Unit = LV2_PORT_UNIT_MS;
  667. else if (strcmp(unitType, LV2_UNITS__oct) == 0)
  668. rdf_port->Unit.Unit = LV2_PORT_UNIT_OCT;
  669. else if (strcmp(unitType, LV2_UNITS__pc) == 0)
  670. rdf_port->Unit.Unit = LV2_PORT_UNIT_PC;
  671. else if (strcmp(unitType, LV2_UNITS__s) == 0)
  672. rdf_port->Unit.Unit = LV2_PORT_UNIT_S;
  673. else if (strcmp(unitType, LV2_UNITS__semitone12TET) == 0)
  674. rdf_port->Unit.Unit = LV2_PORT_UNIT_SEMITONE;
  675. else
  676. qWarning("lv2_rdf_new(\"%s\") - got unknown Unit type '%s'", uri, unitType);
  677. }
  678. Lilv::Nodes unitNameNodes(lilvPort.get_value(lv2World.unit_name));
  679. if (unitNameNodes.size() > 0)
  680. {
  681. rdf_port->Unit.Hints |= LV2_PORT_UNIT_NAME;
  682. rdf_port->Unit.Name = strdup(unitNameNodes.get_first().as_string());
  683. }
  684. Lilv::Nodes unitRenderNodes(lilvPort.get_value(lv2World.unit_render));
  685. if (unitRenderNodes.size() > 0)
  686. {
  687. rdf_port->Unit.Hints |= LV2_PORT_UNIT_RENDER;
  688. rdf_port->Unit.Render = strdup(unitRenderNodes.get_first().as_string());
  689. }
  690. Lilv::Nodes unitSymbolNodes(lilvPort.get_value(lv2World.unit_symbol));
  691. if (unitSymbolNodes.size() > 0)
  692. {
  693. rdf_port->Unit.Hints |= LV2_PORT_UNIT_SYMBOL;
  694. rdf_port->Unit.Symbol = strdup(unitSymbolNodes.get_first().as_string());
  695. }
  696. }
  697. // --------------------------------------
  698. // Set Port Scale Points
  699. Lilv::ScalePoints lilvScalePoints(lilvPort.get_scale_points());
  700. if (lilvScalePoints.size() > 0)
  701. {
  702. rdf_port->ScalePointCount = lilvScalePoints.size();
  703. rdf_port->ScalePoints = new LV2_RDF_PortScalePoint[rdf_port->ScalePointCount];
  704. uint32_t h = 0;
  705. LILV_FOREACH(scale_points, j, lilvScalePoints)
  706. {
  707. Lilv::ScalePoint lilvScalePoint(lilvScalePoints.get(j));
  708. LV2_RDF_PortScalePoint* const rdf_scalePoint = &rdf_port->ScalePoints[h++];
  709. rdf_scalePoint->Label = strdup(Lilv::Node(lilvScalePoint.get_label()).as_string());
  710. rdf_scalePoint->Value = Lilv::Node(lilvScalePoint.get_value()).as_float();
  711. }
  712. }
  713. }
  714. }
  715. #if 0
  716. // --------------------------------------------------
  717. // Set Plugin Presets (TODO)
  718. {
  719. Lilv::Nodes presetNodes(lilvPlugin.get_related(lv2World.preset_preset));
  720. if (presetNodes.size() > 0)
  721. {
  722. // create a list of preset URIs (for checking appliesTo, sorting and uniqueness)
  723. QStringList presetListURIs;
  724. LILV_FOREACH(nodes, j, presetNodes)
  725. {
  726. Lilv::Node presetNode(presetNodes.get(j));
  727. // FIXME - check appliesTo
  728. QString presetURI(presetNode.as_uri());
  729. if (! presetListURIs.contains(presetURI))
  730. presetListURIs.append(presetURI);
  731. }
  732. presetListURIs.sort();
  733. // create presets with unique URIs
  734. rdfDescriptor->PresetCount = presetListURIs.count();
  735. rdfDescriptor->Presets = new LV2_RDF_Preset[rdfDescriptor->PresetCount];
  736. // set preset data
  737. LILV_FOREACH(nodes, j, presetNodes)
  738. {
  739. Lilv::Node presetNode(presetNodes.get(j));
  740. lv2World.load_resource(presetNode);
  741. LV2_URI presetURI = presetNode.as_uri();
  742. int32_t index = presetListURIs.indexOf(QString(presetURI));
  743. if (index < 0)
  744. continue;
  745. LV2_RDF_Preset* const rdf_preset = &rdfDescriptor->Presets[index];
  746. // --------------------------------------
  747. // Set Preset Information
  748. {
  749. rdf_preset->URI = strdup(presetURI);
  750. Lilv::Nodes presetLabelNodes(lv2World.find_nodes(presetNode, lv2World.rdfs_label, nullptr));
  751. if (presetLabelNodes.size() > 0)
  752. rdf_preset->Label = strdup(presetLabelNodes.get_first().as_string());
  753. }
  754. // --------------------------------------
  755. // Set Preset Ports
  756. {
  757. Lilv::Nodes presetPortNodes(lv2World.find_nodes(presetNode, lv2World.port, nullptr));
  758. if (presetPortNodes.size() > 0)
  759. {
  760. rdf_preset->PortCount = presetPortNodes.size();
  761. rdf_preset->Ports = new LV2_RDF_PresetPort[rdf_preset->PortCount];
  762. uint32_t h = 0;
  763. LILV_FOREACH(nodes, k, presetPortNodes)
  764. {
  765. Lilv::Node presetPortNode(presetPortNodes.get(k));
  766. Lilv::Nodes presetPortSymbolNodes(lv2World.find_nodes(presetPortNode, lv2World.symbol, nullptr));
  767. Lilv::Nodes presetPortValueNodes(lv2World.find_nodes(presetPortNode, lv2World.preset_value, nullptr));
  768. if (presetPortSymbolNodes.size() == 1 && presetPortValueNodes.size() == 1)
  769. {
  770. LV2_RDF_PresetPort* const rdf_presetPort = &rdf_preset->Ports[h++];
  771. rdf_presetPort->Symbol = strdup(presetPortSymbolNodes.get_first().as_string());
  772. rdf_presetPort->Value = presetPortValueNodes.get_first().as_float();
  773. }
  774. }
  775. }
  776. }
  777. // --------------------------------------
  778. // Set Preset States
  779. {
  780. Lilv::Nodes presetStateNodes(lv2World.find_nodes(presetNode, lv2World.state_state, nullptr));
  781. if (presetStateNodes.size() > 0)
  782. {
  783. rdf_preset->StateCount = presetStateNodes.size();
  784. rdf_preset->States = new LV2_RDF_PresetState[rdf_preset->StateCount];
  785. uint32_t h = 0;
  786. LILV_FOREACH(nodes, k, presetStateNodes)
  787. {
  788. Lilv::Node presetStateNode(presetStateNodes.get(k));
  789. if (presetStateNode.is_blank())
  790. {
  791. // TODO
  792. LV2_RDF_PresetState* const rdf_presetState = &rdf_preset->States[h++];
  793. rdf_presetState->Type = LV2_PRESET_STATE_NULL;
  794. rdf_presetState->Key = nullptr;
  795. }
  796. }
  797. }
  798. }
  799. }
  800. }
  801. }
  802. #endif
  803. // --------------------------------------------------
  804. // Set Plugin Features
  805. {
  806. Lilv::Nodes lilvFeatureNodes(lilvPlugin.get_supported_features());
  807. if (lilvFeatureNodes.size() > 0)
  808. {
  809. Lilv::Nodes lilvFeatureNodesR(lilvPlugin.get_required_features());
  810. rdfDescriptor->FeatureCount = lilvFeatureNodes.size();
  811. rdfDescriptor->Features = new LV2_RDF_Feature[rdfDescriptor->FeatureCount];
  812. uint32_t h = 0;
  813. LILV_FOREACH(nodes, j, lilvFeatureNodes)
  814. {
  815. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(j));
  816. LV2_RDF_Feature* const rdf_feature = &rdfDescriptor->Features[h++];
  817. rdf_feature->Type = lilvFeatureNodesR.contains(lilvFeatureNode) ? LV2_FEATURE_REQUIRED : LV2_FEATURE_OPTIONAL;
  818. rdf_feature->URI = strdup(lilvFeatureNode.as_uri());
  819. }
  820. }
  821. }
  822. // --------------------------------------------------
  823. // Set Plugin Extensions
  824. {
  825. Lilv::Nodes lilvExtensionDataNodes(lilvPlugin.get_extension_data());
  826. if (lilvExtensionDataNodes.size() > 0)
  827. {
  828. rdfDescriptor->ExtensionCount = lilvExtensionDataNodes.size();
  829. rdfDescriptor->Extensions = new LV2_URI[rdfDescriptor->ExtensionCount];
  830. uint32_t h = 0;
  831. LILV_FOREACH(nodes, j, lilvExtensionDataNodes)
  832. {
  833. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(j));
  834. LV2_URI* const rdf_extension = &rdfDescriptor->Extensions[h++];
  835. *rdf_extension = strdup(lilvExtensionDataNode.as_uri());
  836. }
  837. }
  838. }
  839. // --------------------------------------------------
  840. // Set Plugin UIs
  841. {
  842. Lilv::UIs lilvUIs(lilvPlugin.get_uis());
  843. if (lilvUIs.size() > 0)
  844. {
  845. rdfDescriptor->UICount = lilvUIs.size();
  846. rdfDescriptor->UIs = new LV2_RDF_UI[rdfDescriptor->UICount];
  847. uint32_t h = 0;
  848. LILV_FOREACH(uis, j, lilvUIs)
  849. {
  850. Lilv::UI lilvUI(lilvUIs.get(j));
  851. LV2_RDF_UI* const rdf_ui = &rdfDescriptor->UIs[h++];
  852. // --------------------------------------
  853. // Set UI Type
  854. {
  855. #if 0
  856. if (lilvUI.is_a(lv2World.ui_gtk2))
  857. rdf_ui->Type = LV2_UI_GTK2;
  858. else if (lilvUI.is_a(lv2World.ui_gtk3))
  859. rdf_ui->Type = LV2_UI_GTK3;
  860. else if (lilvUI.is_a(lv2World.ui_qt4))
  861. rdf_ui->Type = LV2_UI_QT4;
  862. else if (lilvUI.is_a(lv2World.ui_cocoa))
  863. rdf_ui->Type = LV2_UI_COCOA;
  864. else if (lilvUI.is_a(lv2World.ui_windows))
  865. rdf_ui->Type = LV2_UI_WINDOWS;
  866. else if (lilvUI.is_a(lv2World.ui_x11))
  867. rdf_ui->Type = LV2_UI_X11;
  868. else if (lilvUI.is_a(lv2World.ui_external))
  869. rdf_ui->Type = LV2_UI_EXTERNAL;
  870. else if (lilvUI.is_a(lv2World.ui_externalOld))
  871. rdf_ui->Type = LV2_UI_OLD_EXTERNAL;
  872. else
  873. #endif
  874. qWarning("lv2_rdf_new(\"%s\") - got unknown UI type for '%s'", uri, lilvUI.get_uri().as_uri());
  875. }
  876. // --------------------------------------
  877. // Set UI Information
  878. {
  879. rdf_ui->URI = strdup(lilvUI.get_uri().as_uri());
  880. rdf_ui->Binary = strdup(lilv_uri_to_path(lilvUI.get_binary_uri().as_string()));
  881. rdf_ui->Bundle = strdup(lilv_uri_to_path(lilvUI.get_bundle_uri().as_string()));
  882. }
  883. // --------------------------------------
  884. // Set UI Features
  885. {
  886. Lilv::Nodes lilvFeatureNodes(lilvUI.get_supported_features());
  887. if (lilvFeatureNodes.size() > 0)
  888. {
  889. Lilv::Nodes lilvFeatureNodesR(lilvUI.get_required_features());
  890. rdf_ui->FeatureCount = lilvFeatureNodes.size();
  891. rdf_ui->Features = new LV2_RDF_Feature[rdf_ui->FeatureCount];
  892. uint32_t x = 0;
  893. LILV_FOREACH(nodes, k, lilvFeatureNodes)
  894. {
  895. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(k));
  896. LV2_RDF_Feature* const rdf_feature = &rdf_ui->Features[x++];
  897. rdf_feature->Type = lilvFeatureNodesR.contains(lilvFeatureNode) ? LV2_FEATURE_REQUIRED : LV2_FEATURE_OPTIONAL;
  898. rdf_feature->URI = strdup(lilvFeatureNode.as_uri());
  899. }
  900. }
  901. }
  902. // --------------------------------------
  903. // Set UI Extensions
  904. {
  905. Lilv::Nodes lilvExtensionDataNodes(lilvUI.get_extension_data());
  906. if (lilvExtensionDataNodes.size() > 0)
  907. {
  908. rdf_ui->ExtensionCount = lilvExtensionDataNodes.size();
  909. rdf_ui->Extensions = new LV2_URI[rdf_ui->ExtensionCount];
  910. uint32_t x = 0;
  911. LILV_FOREACH(nodes, k, lilvExtensionDataNodes)
  912. {
  913. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(k));
  914. LV2_URI* const rdf_extension = &rdf_ui->Extensions[x++];
  915. *rdf_extension = strdup(lilvExtensionDataNode.as_uri());
  916. }
  917. }
  918. }
  919. }
  920. }
  921. }
  922. return rdfDescriptor;
  923. }
  924. return nullptr;
  925. }
  926. // -------------------------------------------------
  927. // Check if we support a plugin feature
  928. static inline
  929. bool is_lv2_feature_supported(const LV2_URI uri)
  930. {
  931. if (strcmp(uri, LV2_CORE__hardRTCapable) == 0)
  932. return true;
  933. if (strcmp(uri, LV2_CORE__inPlaceBroken) == 0)
  934. return true;
  935. if (strcmp(uri, LV2_CORE__isLive) == 0)
  936. return true;
  937. if (strcmp(uri, LV2_EVENT_URI) == 0)
  938. return true;
  939. if (strcmp(uri, LV2_LOG__log) == 0)
  940. return true;
  941. if (strcmp(uri, LV2_OPTIONS__options) == 0)
  942. return true;
  943. if (strcmp(uri, LV2_PROGRAMS__Host) == 0)
  944. return true;
  945. if (strcmp(uri, LV2_RTSAFE_MEMORY_POOL__Pool) == 0)
  946. return true;
  947. if (strcmp(uri, LV2_STATE__makePath) == 0)
  948. return true;
  949. if (strcmp(uri, LV2_STATE__mapPath) == 0)
  950. return true;
  951. if (strcmp(uri, LV2_PORT_PROPS__supportsStrictBounds) == 0)
  952. return true;
  953. if (strcmp(uri, LV2_URI_MAP_URI) == 0)
  954. return true;
  955. if (strcmp(uri, LV2_URID__map) == 0)
  956. return true;
  957. if (strcmp(uri, LV2_URID__unmap) == 0)
  958. return true;
  959. if (strcmp(uri, LV2_WORKER__schedule) == 0)
  960. return true;
  961. return false;
  962. }
  963. // -------------------------------------------------
  964. // Check if we support a plugin or UI feature
  965. static inline
  966. bool is_lv2_ui_feature_supported(const LV2_URI uri)
  967. {
  968. if (is_lv2_feature_supported(uri))
  969. return true;
  970. if (strcmp(uri, LV2_DATA_ACCESS_URI) == 0)
  971. return true;
  972. if (strcmp(uri, LV2_INSTANCE_ACCESS_URI) == 0)
  973. return true;
  974. if (strcmp(uri, LV2_UI__fixedSize) == 0)
  975. return true;
  976. if (strcmp(uri, LV2_UI__makeResident) == 0)
  977. return true;
  978. if (strcmp(uri, LV2_UI__noUserResize) == 0)
  979. return true;
  980. if (strcmp(uri, LV2_UI__parent) == 0)
  981. return true;
  982. if (strcmp(uri, LV2_UI__portMap) == 0)
  983. return true;
  984. if (strcmp(uri, LV2_UI__portSubscribe) == 0)
  985. return false; // TODO
  986. if (strcmp(uri, LV2_UI__resize) == 0)
  987. return true;
  988. if (strcmp(uri, LV2_UI__touch) == 0)
  989. return false; // TODO
  990. if (strcmp(uri, LV2_EXTERNAL_UI__Widget) == 0)
  991. return true;
  992. if (strcmp(uri, LV2_EXTERNAL_UI_DEPRECATED_URI) == 0)
  993. return true;
  994. return false;
  995. }
  996. // -------------------------------------------------
  997. #endif // __CARLA_LV2_UTILS_HPP__