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.

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