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