Collection of tools useful for audio production
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.

1173 lines
49KB

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