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.

1179 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_PLUGIN_ALLPASS;
  317. if (typeNodes.contains(lv2World.class_amplifier))
  318. rdfDescriptor->Type |= LV2_PLUGIN_AMPLIFIER;
  319. if (typeNodes.contains(lv2World.class_analyzer))
  320. rdfDescriptor->Type |= LV2_PLUGIN_ANALYSER;
  321. if (typeNodes.contains(lv2World.class_bandpass))
  322. rdfDescriptor->Type |= LV2_PLUGIN_BANDPASS;
  323. if (typeNodes.contains(lv2World.class_chorus))
  324. rdfDescriptor->Type |= LV2_PLUGIN_CHORUS;
  325. if (typeNodes.contains(lv2World.class_comb))
  326. rdfDescriptor->Type |= LV2_PLUGIN_COMB;
  327. if (typeNodes.contains(lv2World.class_compressor))
  328. rdfDescriptor->Type |= LV2_PLUGIN_COMPRESSOR;
  329. if (typeNodes.contains(lv2World.class_constant))
  330. rdfDescriptor->Type |= LV2_PLUGIN_CONSTANT;
  331. if (typeNodes.contains(lv2World.class_converter))
  332. rdfDescriptor->Type |= LV2_PLUGIN_CONVERTER;
  333. if (typeNodes.contains(lv2World.class_delay))
  334. rdfDescriptor->Type |= LV2_PLUGIN_DELAY;
  335. if (typeNodes.contains(lv2World.class_distortion))
  336. rdfDescriptor->Type |= LV2_PLUGIN_DISTORTION;
  337. if (typeNodes.contains(lv2World.class_dynamics))
  338. rdfDescriptor->Type |= LV2_PLUGIN_DYNAMICS;
  339. if (typeNodes.contains(lv2World.class_eq))
  340. rdfDescriptor->Type |= LV2_PLUGIN_EQ;
  341. if (typeNodes.contains(lv2World.class_expander))
  342. rdfDescriptor->Type |= LV2_PLUGIN_EXPANDER;
  343. if (typeNodes.contains(lv2World.class_filter))
  344. rdfDescriptor->Type |= LV2_PLUGIN_FILTER;
  345. if (typeNodes.contains(lv2World.class_flanger))
  346. rdfDescriptor->Type |= LV2_PLUGIN_FLANGER;
  347. if (typeNodes.contains(lv2World.class_function))
  348. rdfDescriptor->Type |= LV2_PLUGIN_FUNCTION;
  349. if (typeNodes.contains(lv2World.class_gate))
  350. rdfDescriptor->Type |= LV2_PLUGIN_GATE;
  351. if (typeNodes.contains(lv2World.class_generator))
  352. rdfDescriptor->Type |= LV2_PLUGIN_GENERATOR;
  353. if (typeNodes.contains(lv2World.class_highpass))
  354. rdfDescriptor->Type |= LV2_PLUGIN_HIGHPASS;
  355. if (typeNodes.contains(lv2World.class_instrument))
  356. rdfDescriptor->Type |= LV2_PLUGIN_INSTRUMENT;
  357. if (typeNodes.contains(lv2World.class_limiter))
  358. rdfDescriptor->Type |= LV2_PLUGIN_LIMITER;
  359. if (typeNodes.contains(lv2World.class_lowpass))
  360. rdfDescriptor->Type |= LV2_PLUGIN_LOWPASS;
  361. if (typeNodes.contains(lv2World.class_mixer))
  362. rdfDescriptor->Type |= LV2_PLUGIN_MIXER;
  363. if (typeNodes.contains(lv2World.class_modulator))
  364. rdfDescriptor->Type |= LV2_PLUGIN_MODULATOR;
  365. if (typeNodes.contains(lv2World.class_multiEQ))
  366. rdfDescriptor->Type |= LV2_PLUGIN_MULTI_EQ;
  367. if (typeNodes.contains(lv2World.class_oscillator))
  368. rdfDescriptor->Type |= LV2_PLUGIN_OSCILLATOR;
  369. if (typeNodes.contains(lv2World.class_paraEQ))
  370. rdfDescriptor->Type |= LV2_PLUGIN_PARA_EQ;
  371. if (typeNodes.contains(lv2World.class_phaser))
  372. rdfDescriptor->Type |= LV2_PLUGIN_PHASER;
  373. if (typeNodes.contains(lv2World.class_pitch))
  374. rdfDescriptor->Type |= LV2_PLUGIN_PITCH;
  375. if (typeNodes.contains(lv2World.class_reverb))
  376. rdfDescriptor->Type |= LV2_PLUGIN_REVERB;
  377. if (typeNodes.contains(lv2World.class_simulator))
  378. rdfDescriptor->Type |= LV2_PLUGIN_SIMULATOR;
  379. if (typeNodes.contains(lv2World.class_spatial))
  380. rdfDescriptor->Type |= LV2_PLUGIN_SPATIAL;
  381. if (typeNodes.contains(lv2World.class_spectral))
  382. rdfDescriptor->Type |= LV2_PLUGIN_SPECTRAL;
  383. if (typeNodes.contains(lv2World.class_utility))
  384. rdfDescriptor->Type |= LV2_PLUGIN_UTILITY;
  385. if (typeNodes.contains(lv2World.class_waveshaper))
  386. rdfDescriptor->Type |= LV2_PLUGIN_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. #if 0
  444. // Mode
  445. if (lilvPort.is_a(lv2World.port_input))
  446. rdf_port->Type |= LV2_PORT_INPUT;
  447. else if (lilvPort.is_a(lv2World.port_output))
  448. rdf_port->Type |= LV2_PORT_OUTPUT;
  449. else
  450. qWarning("lv2_rdf_new(\"%s\") - port '%s' is not input or output", uri, rdf_port->Name);
  451. // Type
  452. if (lilvPort.is_a(lv2World.port_control))
  453. rdf_port->Type |= LV2_PORT_CONTROL;
  454. else if (lilvPort.is_a(lv2World.port_audio))
  455. rdf_port->Type |= LV2_PORT_AUDIO;
  456. else if (lilvPort.is_a(lv2World.port_cv))
  457. rdf_port->Type |= LV2_PORT_CV;
  458. else if (lilvPort.is_a(lv2World.port_atom))
  459. {
  460. rdf_port->Type |= LV2_PORT_ATOM;
  461. Lilv::Nodes bufferTypeNodes(lilvPort.get_value(lv2World.atom_bufferType));
  462. if (bufferTypeNodes.contains(lv2World.atom_Sequence))
  463. rdf_port->Type |= LV2_PORT_ATOM_SEQUENCE;
  464. Lilv::Nodes supportNodes(lilvPort.get_value(lv2World.atom_supports));
  465. if (supportNodes.contains(lv2World.midi_event))
  466. rdf_port->Type |= LV2_PORT_DATA_MIDI_EVENT;
  467. if (supportNodes.contains(lv2World.patch_message))
  468. rdf_port->Type |= LV2_PORT_DATA_PATCH_MESSAGE;
  469. }
  470. else if (lilvPort.is_a(lv2World.port_event))
  471. {
  472. rdf_port->Type |= LV2_PORT_EVENT;
  473. if (lilvPort.supports_event(lv2World.midi_event))
  474. rdf_port->Type |= LV2_PORT_SUPPORTS_MIDI_EVENT;
  475. }
  476. else if (lilvPort.is_a(lv2World.port_midi))
  477. {
  478. rdf_port->Type |= LV2_PORT_MIDI_LL;
  479. rdf_port->Type |= LV2_PORT_SUPPORTS_MIDI_EVENT;
  480. }
  481. else
  482. #endif
  483. qWarning("lv2_rdf_new(\"%s\") - port '%s' is of unkown type", uri, rdf_port->Name);
  484. }
  485. // --------------------------------------
  486. // Set Port Properties
  487. {
  488. if (lilvPort.has_property(lv2World.pprop_optional))
  489. rdf_port->Properties = LV2_PORT_OPTIONAL;
  490. if (lilvPort.has_property(lv2World.pprop_enumeration))
  491. rdf_port->Properties = LV2_PORT_ENUMERATION;
  492. if (lilvPort.has_property(lv2World.pprop_integer))
  493. rdf_port->Properties = LV2_PORT_INTEGER;
  494. if (lilvPort.has_property(lv2World.pprop_sampleRate))
  495. rdf_port->Properties = LV2_PORT_SAMPLE_RATE;
  496. if (lilvPort.has_property(lv2World.pprop_toggled))
  497. rdf_port->Properties = LV2_PORT_TOGGLED;
  498. if (lilvPort.has_property(lv2World.pprop_artifacts))
  499. rdf_port->Properties = LV2_PORT_CAUSES_ARTIFACTS;
  500. if (lilvPort.has_property(lv2World.pprop_continuousCV))
  501. rdf_port->Properties = LV2_PORT_CONTINUOUS_CV;
  502. if (lilvPort.has_property(lv2World.pprop_discreteCV))
  503. rdf_port->Properties = LV2_PORT_DISCRETE_CV;
  504. if (lilvPort.has_property(lv2World.pprop_expensive))
  505. rdf_port->Properties = LV2_PORT_EXPENSIVE;
  506. if (lilvPort.has_property(lv2World.pprop_strictBounds))
  507. rdf_port->Properties = LV2_PORT_STRICT_BOUNDS;
  508. if (lilvPort.has_property(lv2World.pprop_logarithmic))
  509. rdf_port->Properties = LV2_PORT_LOGARITHMIC;
  510. if (lilvPort.has_property(lv2World.pprop_notAutomatic))
  511. rdf_port->Properties = LV2_PORT_NOT_AUTOMATIC;
  512. if (lilvPort.has_property(lv2World.pprop_notOnGUI))
  513. rdf_port->Properties = LV2_PORT_NOT_ON_GUI;
  514. if (lilvPort.has_property(lv2World.pprop_trigger))
  515. rdf_port->Properties = LV2_PORT_TRIGGER;
  516. if (lilvPort.has_property(lv2World.reportsLatency))
  517. rdf_port->Designation = LV2_PORT_DESIGNATION_LATENCY;
  518. }
  519. // --------------------------------------
  520. // Set Port Designation
  521. {
  522. Lilv::Nodes designationNodes(lilvPort.get_value(lv2World.designation));
  523. if (designationNodes.size() > 0)
  524. {
  525. const char* const designation = designationNodes.get_first().as_string();
  526. if (strcmp(designation, LV2_CORE__freeWheeling) == 0)
  527. rdf_port->Designation = LV2_PORT_DESIGNATION_FREEWHEELING;
  528. else if (strcmp(designation, LV2_CORE__latency) == 0)
  529. rdf_port->Designation = LV2_PORT_DESIGNATION_LATENCY;
  530. else if (strcmp(designation, LV2_PARAMETERS__sampleRate) == 0)
  531. rdf_port->Designation = LV2_PORT_DESIGNATION_SAMPLE_RATE;
  532. else if (strcmp(designation, LV2_TIME__bar) == 0)
  533. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BAR;
  534. else if (strcmp(designation, LV2_TIME__barBeat) == 0)
  535. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BAR_BEAT;
  536. else if (strcmp(designation, LV2_TIME__beat) == 0)
  537. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BEAT;
  538. else if (strcmp(designation, LV2_TIME__beatUnit) == 0)
  539. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BEAT_UNIT;
  540. else if (strcmp(designation, LV2_TIME__beatsPerBar) == 0)
  541. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BEATS_PER_BAR;
  542. else if (strcmp(designation, LV2_TIME__beatsPerMinute) == 0)
  543. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BEATS_PER_MINUTE;
  544. else if (strcmp(designation, LV2_TIME__frame) == 0)
  545. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_FRAME;
  546. else if (strcmp(designation, LV2_TIME__framesPerSecond) == 0)
  547. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_FRAMES_PER_SECOND;
  548. else if (strcmp(designation, LV2_TIME__position) == 0)
  549. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_POSITION;
  550. else if (strcmp(designation, LV2_TIME__speed) == 0)
  551. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_SPEED;
  552. else if (strncmp(designation, LV2_PARAMETERS_PREFIX, strlen(LV2_PARAMETERS_PREFIX)) == 0)
  553. pass();
  554. else if (strncmp(designation, LV2_PORT_GROUPS_PREFIX, strlen(LV2_PORT_GROUPS_PREFIX)) == 0)
  555. pass();
  556. else
  557. qWarning("lv2_rdf_new(\"%s\") - got unknown Port Designation '%s'", uri, designation);
  558. }
  559. }
  560. // --------------------------------------
  561. // Set Port MIDI Map
  562. {
  563. Lilv::Nodes midiMapNodes(lilvPort.get_value(lv2World.mm_defaultControl));
  564. if (midiMapNodes.size() > 0)
  565. {
  566. Lilv::Node midiMapNode(midiMapNodes.get_first());
  567. if (midiMapNode.is_blank())
  568. {
  569. Lilv::Nodes midiMapTypeNodes(lv2World.find_nodes(midiMapNode, lv2World.mm_controlType, nullptr));
  570. Lilv::Nodes midiMapNumberNodes(lv2World.find_nodes(midiMapNode, lv2World.mm_controlNumber, nullptr));
  571. if (midiMapTypeNodes.size() == 1 && midiMapNumberNodes.size() == 1)
  572. {
  573. const char* const midiMapType = midiMapTypeNodes.get_first().as_string();
  574. if (strcmp(midiMapType, LV2_MIDI_Map__CC) == 0)
  575. rdf_port->MidiMap.Type = LV2_PORT_MIDI_MAP_CC;
  576. else if (strcmp(midiMapType, LV2_MIDI_Map__NRPN) == 0)
  577. rdf_port->MidiMap.Type = LV2_PORT_MIDI_MAP_NRPN;
  578. else
  579. qWarning("lv2_rdf_new(\"%s\") - got unknown Port Midi Map type '%s'", uri, midiMapType);
  580. rdf_port->MidiMap.Number = midiMapNumberNodes.get_first().as_int();
  581. }
  582. }
  583. }
  584. }
  585. // --------------------------------------
  586. // Set Port Points
  587. {
  588. Lilv::Nodes valueNodes(lilvPort.get_value(lv2World.value_default));
  589. if (valueNodes.size() > 0)
  590. {
  591. rdf_port->Points.Hints |= LV2_PORT_POINT_DEFAULT;
  592. rdf_port->Points.Default = valueNodes.get_first().as_float();
  593. }
  594. valueNodes = lilvPort.get_value(lv2World.value_minimum);
  595. if (valueNodes.size() > 0)
  596. {
  597. rdf_port->Points.Hints |= LV2_PORT_POINT_MINIMUM;
  598. rdf_port->Points.Minimum = valueNodes.get_first().as_float();
  599. }
  600. valueNodes = lilvPort.get_value(lv2World.value_maximum);
  601. if (valueNodes.size() > 0)
  602. {
  603. rdf_port->Points.Hints |= LV2_PORT_POINT_MAXIMUM;
  604. rdf_port->Points.Maximum = valueNodes.get_first().as_float();
  605. }
  606. }
  607. // --------------------------------------
  608. // Set Port Unit
  609. {
  610. Lilv::Nodes unitTypeNodes(lilvPort.get_value(lv2World.unit_unit));
  611. if (unitTypeNodes.size() > 0)
  612. {
  613. rdf_port->Unit.Hints |= LV2_PORT_UNIT_UNIT;
  614. const char* const unitType = unitTypeNodes.get_first().as_uri();
  615. if (strcmp(unitType, LV2_UNITS__bar) == 0)
  616. rdf_port->Unit.Unit = LV2_PORT_UNIT_BAR;
  617. else if (strcmp(unitType, LV2_UNITS__beat) == 0)
  618. rdf_port->Unit.Unit = LV2_PORT_UNIT_BEAT;
  619. else if (strcmp(unitType, LV2_UNITS__bpm) == 0)
  620. rdf_port->Unit.Unit = LV2_PORT_UNIT_BPM;
  621. else if (strcmp(unitType, LV2_UNITS__cent) == 0)
  622. rdf_port->Unit.Unit = LV2_PORT_UNIT_CENT;
  623. else if (strcmp(unitType, LV2_UNITS__cm) == 0)
  624. rdf_port->Unit.Unit = LV2_PORT_UNIT_CM;
  625. else if (strcmp(unitType, LV2_UNITS__coef) == 0)
  626. rdf_port->Unit.Unit = LV2_PORT_UNIT_COEF;
  627. else if (strcmp(unitType, LV2_UNITS__db) == 0)
  628. rdf_port->Unit.Unit = LV2_PORT_UNIT_DB;
  629. else if (strcmp(unitType, LV2_UNITS__degree) == 0)
  630. rdf_port->Unit.Unit = LV2_PORT_UNIT_DEGREE;
  631. else if (strcmp(unitType, LV2_UNITS__frame) == 0)
  632. rdf_port->Unit.Unit = LV2_PORT_UNIT_FRAME;
  633. else if (strcmp(unitType, LV2_UNITS__hz) == 0)
  634. rdf_port->Unit.Unit = LV2_PORT_UNIT_HZ;
  635. else if (strcmp(unitType, LV2_UNITS__inch) == 0)
  636. rdf_port->Unit.Unit = LV2_PORT_UNIT_INCH;
  637. else if (strcmp(unitType, LV2_UNITS__khz) == 0)
  638. rdf_port->Unit.Unit = LV2_PORT_UNIT_KHZ;
  639. else if (strcmp(unitType, LV2_UNITS__km) == 0)
  640. rdf_port->Unit.Unit = LV2_PORT_UNIT_KM;
  641. else if (strcmp(unitType, LV2_UNITS__m) == 0)
  642. rdf_port->Unit.Unit = LV2_PORT_UNIT_M;
  643. else if (strcmp(unitType, LV2_UNITS__mhz) == 0)
  644. rdf_port->Unit.Unit = LV2_PORT_UNIT_MHZ;
  645. else if (strcmp(unitType, LV2_UNITS__midiNote) == 0)
  646. rdf_port->Unit.Unit = LV2_PORT_UNIT_MIDINOTE;
  647. else if (strcmp(unitType, LV2_UNITS__mile) == 0)
  648. rdf_port->Unit.Unit = LV2_PORT_UNIT_MILE;
  649. else if (strcmp(unitType, LV2_UNITS__min) == 0)
  650. rdf_port->Unit.Unit = LV2_PORT_UNIT_MIN;
  651. else if (strcmp(unitType, LV2_UNITS__mm) == 0)
  652. rdf_port->Unit.Unit = LV2_PORT_UNIT_MM;
  653. else if (strcmp(unitType, LV2_UNITS__ms) == 0)
  654. rdf_port->Unit.Unit = LV2_PORT_UNIT_MS;
  655. else if (strcmp(unitType, LV2_UNITS__oct) == 0)
  656. rdf_port->Unit.Unit = LV2_PORT_UNIT_OCT;
  657. else if (strcmp(unitType, LV2_UNITS__pc) == 0)
  658. rdf_port->Unit.Unit = LV2_PORT_UNIT_PC;
  659. else if (strcmp(unitType, LV2_UNITS__s) == 0)
  660. rdf_port->Unit.Unit = LV2_PORT_UNIT_S;
  661. else if (strcmp(unitType, LV2_UNITS__semitone12TET) == 0)
  662. rdf_port->Unit.Unit = LV2_PORT_UNIT_SEMITONE;
  663. else
  664. qWarning("lv2_rdf_new(\"%s\") - got unknown Unit type '%s'", uri, unitType);
  665. }
  666. Lilv::Nodes unitNameNodes(lilvPort.get_value(lv2World.unit_name));
  667. if (unitNameNodes.size() > 0)
  668. {
  669. rdf_port->Unit.Hints |= LV2_PORT_UNIT_NAME;
  670. rdf_port->Unit.Name = strdup(unitNameNodes.get_first().as_string());
  671. }
  672. Lilv::Nodes unitRenderNodes(lilvPort.get_value(lv2World.unit_render));
  673. if (unitRenderNodes.size() > 0)
  674. {
  675. rdf_port->Unit.Hints |= LV2_PORT_UNIT_RENDER;
  676. rdf_port->Unit.Render = strdup(unitRenderNodes.get_first().as_string());
  677. }
  678. Lilv::Nodes unitSymbolNodes(lilvPort.get_value(lv2World.unit_symbol));
  679. if (unitSymbolNodes.size() > 0)
  680. {
  681. rdf_port->Unit.Hints |= LV2_PORT_UNIT_SYMBOL;
  682. rdf_port->Unit.Symbol = strdup(unitSymbolNodes.get_first().as_string());
  683. }
  684. }
  685. // --------------------------------------
  686. // Set Port Scale Points
  687. Lilv::ScalePoints lilvScalePoints(lilvPort.get_scale_points());
  688. if (lilvScalePoints.size() > 0)
  689. {
  690. rdf_port->ScalePointCount = lilvScalePoints.size();
  691. rdf_port->ScalePoints = new LV2_RDF_PortScalePoint[rdf_port->ScalePointCount];
  692. uint32_t h = 0;
  693. LILV_FOREACH(scale_points, j, lilvScalePoints)
  694. {
  695. Lilv::ScalePoint lilvScalePoint(lilvScalePoints.get(j));
  696. LV2_RDF_PortScalePoint* const rdf_scalePoint = &rdf_port->ScalePoints[h++];
  697. rdf_scalePoint->Label = strdup(Lilv::Node(lilvScalePoint.get_label()).as_string());
  698. rdf_scalePoint->Value = Lilv::Node(lilvScalePoint.get_value()).as_float();
  699. }
  700. }
  701. }
  702. }
  703. #if 0
  704. // --------------------------------------------------
  705. // Set Plugin Presets (TODO)
  706. {
  707. Lilv::Nodes presetNodes(lilvPlugin.get_related(lv2World.preset_preset));
  708. if (presetNodes.size() > 0)
  709. {
  710. // create a list of preset URIs (for checking appliesTo, sorting and uniqueness)
  711. QStringList presetListURIs;
  712. LILV_FOREACH(nodes, j, presetNodes)
  713. {
  714. Lilv::Node presetNode(presetNodes.get(j));
  715. // FIXME - check appliesTo
  716. QString presetURI(presetNode.as_uri());
  717. if (! presetListURIs.contains(presetURI))
  718. presetListURIs.append(presetURI);
  719. }
  720. presetListURIs.sort();
  721. // create presets with unique URIs
  722. rdfDescriptor->PresetCount = presetListURIs.count();
  723. rdfDescriptor->Presets = new LV2_RDF_Preset[rdfDescriptor->PresetCount];
  724. // set preset data
  725. LILV_FOREACH(nodes, j, presetNodes)
  726. {
  727. Lilv::Node presetNode(presetNodes.get(j));
  728. lv2World.load_resource(presetNode);
  729. LV2_URI presetURI = presetNode.as_uri();
  730. int32_t index = presetListURIs.indexOf(QString(presetURI));
  731. if (index < 0)
  732. continue;
  733. LV2_RDF_Preset* const rdf_preset = &rdfDescriptor->Presets[index];
  734. // --------------------------------------
  735. // Set Preset Information
  736. {
  737. rdf_preset->URI = strdup(presetURI);
  738. Lilv::Nodes presetLabelNodes(lv2World.find_nodes(presetNode, lv2World.rdfs_label, nullptr));
  739. if (presetLabelNodes.size() > 0)
  740. rdf_preset->Label = strdup(presetLabelNodes.get_first().as_string());
  741. }
  742. // --------------------------------------
  743. // Set Preset Ports
  744. {
  745. Lilv::Nodes presetPortNodes(lv2World.find_nodes(presetNode, lv2World.port, nullptr));
  746. if (presetPortNodes.size() > 0)
  747. {
  748. rdf_preset->PortCount = presetPortNodes.size();
  749. rdf_preset->Ports = new LV2_RDF_PresetPort[rdf_preset->PortCount];
  750. uint32_t h = 0;
  751. LILV_FOREACH(nodes, k, presetPortNodes)
  752. {
  753. Lilv::Node presetPortNode(presetPortNodes.get(k));
  754. Lilv::Nodes presetPortSymbolNodes(lv2World.find_nodes(presetPortNode, lv2World.symbol, nullptr));
  755. Lilv::Nodes presetPortValueNodes(lv2World.find_nodes(presetPortNode, lv2World.preset_value, nullptr));
  756. if (presetPortSymbolNodes.size() == 1 && presetPortValueNodes.size() == 1)
  757. {
  758. LV2_RDF_PresetPort* const rdf_presetPort = &rdf_preset->Ports[h++];
  759. rdf_presetPort->Symbol = strdup(presetPortSymbolNodes.get_first().as_string());
  760. rdf_presetPort->Value = presetPortValueNodes.get_first().as_float();
  761. }
  762. }
  763. }
  764. }
  765. // --------------------------------------
  766. // Set Preset States
  767. {
  768. Lilv::Nodes presetStateNodes(lv2World.find_nodes(presetNode, lv2World.state_state, nullptr));
  769. if (presetStateNodes.size() > 0)
  770. {
  771. rdf_preset->StateCount = presetStateNodes.size();
  772. rdf_preset->States = new LV2_RDF_PresetState[rdf_preset->StateCount];
  773. uint32_t h = 0;
  774. LILV_FOREACH(nodes, k, presetStateNodes)
  775. {
  776. Lilv::Node presetStateNode(presetStateNodes.get(k));
  777. if (presetStateNode.is_blank())
  778. {
  779. // TODO
  780. LV2_RDF_PresetState* const rdf_presetState = &rdf_preset->States[h++];
  781. rdf_presetState->Type = LV2_PRESET_STATE_NULL;
  782. rdf_presetState->Key = nullptr;
  783. }
  784. }
  785. }
  786. }
  787. }
  788. }
  789. }
  790. #endif
  791. // --------------------------------------------------
  792. // Set Plugin Features
  793. {
  794. Lilv::Nodes lilvFeatureNodes(lilvPlugin.get_supported_features());
  795. if (lilvFeatureNodes.size() > 0)
  796. {
  797. Lilv::Nodes lilvFeatureNodesR(lilvPlugin.get_required_features());
  798. rdfDescriptor->FeatureCount = lilvFeatureNodes.size();
  799. rdfDescriptor->Features = new LV2_RDF_Feature[rdfDescriptor->FeatureCount];
  800. uint32_t h = 0;
  801. LILV_FOREACH(nodes, j, lilvFeatureNodes)
  802. {
  803. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(j));
  804. LV2_RDF_Feature* const rdf_feature = &rdfDescriptor->Features[h++];
  805. rdf_feature->Type = lilvFeatureNodesR.contains(lilvFeatureNode) ? LV2_FEATURE_REQUIRED : LV2_FEATURE_OPTIONAL;
  806. rdf_feature->URI = strdup(lilvFeatureNode.as_uri());
  807. }
  808. }
  809. }
  810. // --------------------------------------------------
  811. // Set Plugin Extensions
  812. {
  813. Lilv::Nodes lilvExtensionDataNodes(lilvPlugin.get_extension_data());
  814. if (lilvExtensionDataNodes.size() > 0)
  815. {
  816. rdfDescriptor->ExtensionCount = lilvExtensionDataNodes.size();
  817. rdfDescriptor->Extensions = new LV2_URI[rdfDescriptor->ExtensionCount];
  818. uint32_t h = 0;
  819. LILV_FOREACH(nodes, j, lilvExtensionDataNodes)
  820. {
  821. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(j));
  822. LV2_URI* const rdf_extension = &rdfDescriptor->Extensions[h++];
  823. *rdf_extension = strdup(lilvExtensionDataNode.as_uri());
  824. }
  825. }
  826. }
  827. // --------------------------------------------------
  828. // Set Plugin UIs
  829. {
  830. Lilv::UIs lilvUIs(lilvPlugin.get_uis());
  831. if (lilvUIs.size() > 0)
  832. {
  833. rdfDescriptor->UICount = lilvUIs.size();
  834. rdfDescriptor->UIs = new LV2_RDF_UI[rdfDescriptor->UICount];
  835. uint32_t h = 0;
  836. LILV_FOREACH(uis, j, lilvUIs)
  837. {
  838. Lilv::UI lilvUI(lilvUIs.get(j));
  839. LV2_RDF_UI* const rdf_ui = &rdfDescriptor->UIs[h++];
  840. // --------------------------------------
  841. // Set UI Type
  842. {
  843. #if 0
  844. if (lilvUI.is_a(lv2World.ui_gtk2))
  845. rdf_ui->Type = LV2_UI_GTK2;
  846. else if (lilvUI.is_a(lv2World.ui_gtk3))
  847. rdf_ui->Type = LV2_UI_GTK3;
  848. else if (lilvUI.is_a(lv2World.ui_qt4))
  849. rdf_ui->Type = LV2_UI_QT4;
  850. else if (lilvUI.is_a(lv2World.ui_cocoa))
  851. rdf_ui->Type = LV2_UI_COCOA;
  852. else if (lilvUI.is_a(lv2World.ui_windows))
  853. rdf_ui->Type = LV2_UI_WINDOWS;
  854. else if (lilvUI.is_a(lv2World.ui_x11))
  855. rdf_ui->Type = LV2_UI_X11;
  856. else if (lilvUI.is_a(lv2World.ui_external))
  857. rdf_ui->Type = LV2_UI_EXTERNAL;
  858. else if (lilvUI.is_a(lv2World.ui_externalOld))
  859. rdf_ui->Type = LV2_UI_OLD_EXTERNAL;
  860. else
  861. #endif
  862. qWarning("lv2_rdf_new(\"%s\") - got unknown UI type for '%s'", uri, lilvUI.get_uri().as_uri());
  863. }
  864. // --------------------------------------
  865. // Set UI Information
  866. {
  867. rdf_ui->URI = strdup(lilvUI.get_uri().as_uri());
  868. rdf_ui->Binary = strdup(lilv_uri_to_path(lilvUI.get_binary_uri().as_string()));
  869. rdf_ui->Bundle = strdup(lilv_uri_to_path(lilvUI.get_bundle_uri().as_string()));
  870. }
  871. // --------------------------------------
  872. // Set UI Features
  873. {
  874. Lilv::Nodes lilvFeatureNodes(lilvUI.get_supported_features());
  875. if (lilvFeatureNodes.size() > 0)
  876. {
  877. Lilv::Nodes lilvFeatureNodesR(lilvUI.get_required_features());
  878. rdf_ui->FeatureCount = lilvFeatureNodes.size();
  879. rdf_ui->Features = new LV2_RDF_Feature[rdf_ui->FeatureCount];
  880. uint32_t x = 0;
  881. LILV_FOREACH(nodes, k, lilvFeatureNodes)
  882. {
  883. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(k));
  884. LV2_RDF_Feature* const rdf_feature = &rdf_ui->Features[x++];
  885. rdf_feature->Type = lilvFeatureNodesR.contains(lilvFeatureNode) ? LV2_FEATURE_REQUIRED : LV2_FEATURE_OPTIONAL;
  886. rdf_feature->URI = strdup(lilvFeatureNode.as_uri());
  887. }
  888. }
  889. }
  890. // --------------------------------------
  891. // Set UI Extensions
  892. {
  893. Lilv::Nodes lilvExtensionDataNodes(lilvUI.get_extension_data());
  894. if (lilvExtensionDataNodes.size() > 0)
  895. {
  896. rdf_ui->ExtensionCount = lilvExtensionDataNodes.size();
  897. rdf_ui->Extensions = new LV2_URI[rdf_ui->ExtensionCount];
  898. uint32_t x = 0;
  899. LILV_FOREACH(nodes, k, lilvExtensionDataNodes)
  900. {
  901. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(k));
  902. LV2_URI* const rdf_extension = &rdf_ui->Extensions[x++];
  903. *rdf_extension = strdup(lilvExtensionDataNode.as_uri());
  904. }
  905. }
  906. }
  907. }
  908. }
  909. }
  910. return rdfDescriptor;
  911. }
  912. return nullptr;
  913. }
  914. // ------------------------------------------------------------------------------------------------
  915. static inline
  916. bool is_lv2_feature_supported(const LV2_URI uri)
  917. {
  918. if (strcmp(uri, LV2_CORE__hardRTCapable) == 0)
  919. return true;
  920. if (strcmp(uri, LV2_CORE__inPlaceBroken) == 0)
  921. return true;
  922. if (strcmp(uri, LV2_CORE__isLive) == 0)
  923. return true;
  924. if (strcmp(uri, LV2_EVENT_URI) == 0)
  925. return true;
  926. if (strcmp(uri, LV2_LOG__log) == 0)
  927. return true;
  928. if (strcmp(uri, LV2_OPTIONS__options) == 0)
  929. return true;
  930. if (strcmp(uri, LV2_PROGRAMS__Host) == 0)
  931. return true;
  932. if (strcmp(uri, LV2_RTSAFE_MEMORY_POOL__Pool) == 0)
  933. return true;
  934. if (strcmp(uri, LV2_STATE__makePath) == 0)
  935. return true;
  936. if (strcmp(uri, LV2_STATE__mapPath) == 0)
  937. return true;
  938. if (strcmp(uri, LV2_PORT_PROPS__supportsStrictBounds) == 0)
  939. return true;
  940. if (strcmp(uri, LV2_URI_MAP_URI) == 0)
  941. return true;
  942. if (strcmp(uri, LV2_URID__map) == 0)
  943. return true;
  944. if (strcmp(uri, LV2_URID__unmap) == 0)
  945. return true;
  946. if (strcmp(uri, LV2_WORKER__schedule) == 0)
  947. return true;
  948. return false;
  949. }
  950. static inline
  951. bool is_lv2_ui_feature_supported(const LV2_URI uri)
  952. {
  953. if (is_lv2_feature_supported(uri))
  954. return true;
  955. if (strcmp(uri, LV2_DATA_ACCESS_URI) == 0)
  956. return true;
  957. if (strcmp(uri, LV2_INSTANCE_ACCESS_URI) == 0)
  958. return true;
  959. if (strcmp(uri, LV2_UI__fixedSize) == 0)
  960. return true;
  961. if (strcmp(uri, LV2_UI__makeResident) == 0)
  962. return true;
  963. if (strcmp(uri, LV2_UI__noUserResize) == 0)
  964. return true;
  965. if (strcmp(uri, LV2_UI__parent) == 0)
  966. return true;
  967. if (strcmp(uri, LV2_UI__portMap) == 0)
  968. return true;
  969. if (strcmp(uri, LV2_UI__portSubscribe) == 0)
  970. return false; // TODO
  971. if (strcmp(uri, LV2_UI__resize) == 0)
  972. return true;
  973. if (strcmp(uri, LV2_UI__touch) == 0)
  974. return false; // TODO
  975. if (strcmp(uri, LV2_EXTERNAL_UI__Widget) == 0)
  976. return true;
  977. if (strcmp(uri, LV2_EXTERNAL_UI_DEPRECATED_URI) == 0)
  978. return true;
  979. return false;
  980. }
  981. static inline
  982. LV2_URI get_lv2_ui_uri(const LV2_Property type)
  983. {
  984. switch (type)
  985. {
  986. case LV2_UI_GTK2:
  987. return LV2_UI__GtkUI;
  988. case LV2_UI_GTK3:
  989. return LV2_UI__Gtk3UI;
  990. case LV2_UI_QT4:
  991. return LV2_UI__Qt4UI;
  992. case LV2_UI_COCOA:
  993. return LV2_UI__CocoaUI;
  994. case LV2_UI_WINDOWS:
  995. return LV2_UI__WindowsUI;
  996. case LV2_UI_X11:
  997. return LV2_UI__X11UI;
  998. case LV2_UI_EXTERNAL:
  999. return LV2_EXTERNAL_UI__Widget;
  1000. case LV2_UI_OLD_EXTERNAL:
  1001. return LV2_EXTERNAL_UI_DEPRECATED_URI;
  1002. default:
  1003. return "UI URI type not supported";
  1004. }
  1005. }
  1006. #endif // CARLA_LV2_UTILS_HPP