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.

1180 lines
49KB

  1. /*
  2. * Carla LV2 utils
  3. * Copyright (C) 2011-2013 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the COPYING file
  16. */
  17. // TODO - presets handling
  18. #include "lv2/lv2.h"
  19. #include "lv2/atom.h"
  20. #include "lv2/atom-forge.h"
  21. #include "lv2/atom-util.h"
  22. #include "lv2/buf-size.h"
  23. #include "lv2/data-access.h"
  24. // dynmanifest
  25. #include "lv2/event.h"
  26. #include "lv2/event-helpers.h"
  27. #include "lv2/instance-access.h"
  28. #include "lv2/log.h"
  29. #include "lv2/midi.h"
  30. #include "lv2/options.h"
  31. #include "lv2/parameters.h"
  32. #include "lv2/patch.h"
  33. #include "lv2/port-groups.h"
  34. #include "lv2/port-props.h"
  35. #include "lv2/presets.h"
  36. // resize-port
  37. #include "lv2/state.h"
  38. #include "lv2/time.h"
  39. #include "lv2/ui.h"
  40. #include "lv2/units.h"
  41. #include "lv2/uri-map.h"
  42. #include "lv2/urid.h"
  43. #include "lv2/worker.h"
  44. #include "lv2/lv2-miditype.h"
  45. #include "lv2/lv2-midifunctions.h"
  46. #include "lv2/lv2_external_ui.h"
  47. #include "lv2/lv2_programs.h"
  48. #include "lv2/lv2_rtmempool.h"
  49. #include "lv2_rdf.hpp"
  50. #include "lilv/lilvmm.hpp"
  51. #include "sratom/sratom.h"
  52. //#include "carla_defines.hpp"
  53. #include <QtCore/QMap>
  54. #include <QtCore/QStringList>
  55. // ------------------------------------------------------------------------------------------------
  56. #define NS_dct "http://purl.org/dc/terms/"
  57. #define NS_doap "http://usefulinc.com/ns/doap#"
  58. #define NS_rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  59. #define NS_rdfs "http://www.w3.org/2000/01/rdf-schema#"
  60. #define NS_llmm "http://ll-plugins.nongnu.org/lv2/ext/midimap#"
  61. #define LV2_MIDI_Map__CC "http://ll-plugins.nongnu.org/lv2/namespace#CC"
  62. #define LV2_MIDI_Map__NRPN "http://ll-plugins.nongnu.org/lv2/namespace#NRPN"
  63. #define LV2_MIDI_LL__MidiPort "http://ll-plugins.nongnu.org/lv2/ext/MidiPort"
  64. #define LV2_UI__Qt5UI LV2_UI_PREFIX "Qt5UI"
  65. #define LV2_UI__makeResident LV2_UI_PREFIX "makeResident"
  66. // ------------------------------------------------------------------------------------------------
  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_name;
  151. Lilv::Node unit_render;
  152. Lilv::Node unit_symbol;
  153. Lilv::Node unit_unit;
  154. // UI Types
  155. Lilv::Node ui_gtk2;
  156. Lilv::Node ui_gtk3;
  157. Lilv::Node ui_qt4;
  158. Lilv::Node ui_qt5;
  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 atom_bufferType;
  166. Lilv::Node atom_sequence;
  167. Lilv::Node atom_supports;
  168. Lilv::Node preset_preset;
  169. Lilv::Node state_state;
  170. Lilv::Node value_default;
  171. Lilv::Node value_minimum;
  172. Lilv::Node value_maximum;
  173. // Port 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_name (new_uri(LV2_UNITS__name)),
  252. unit_render (new_uri(LV2_UNITS__render)),
  253. unit_symbol (new_uri(LV2_UNITS__symbol)),
  254. unit_unit (new_uri(LV2_UNITS__unit)),
  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_qt5 (new_uri(LV2_UI__Qt5UI)),
  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. atom_bufferType (new_uri(LV2_ATOM__bufferType)),
  265. atom_sequence (new_uri(LV2_ATOM__Sequence)),
  266. atom_supports (new_uri(LV2_ATOM__supports)),
  267. preset_preset (new_uri(LV2_PRESETS__Preset)),
  268. state_state (new_uri(LV2_STATE__state)),
  269. value_default (new_uri(LV2_CORE__default)),
  270. value_minimum (new_uri(LV2_CORE__minimum)),
  271. value_maximum (new_uri(LV2_CORE__maximum)),
  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. if (! uri)
  302. return nullptr;
  303. Lilv::Plugins lilvPlugins = lv2World.get_all_plugins();
  304. LILV_FOREACH(plugins, i, lilvPlugins)
  305. {
  306. Lilv::Plugin lilvPlugin(lilvPlugins.get(i));
  307. if (strcmp(lilvPlugin.get_uri().as_string(), uri))
  308. continue;
  309. LV2_RDF_Descriptor* const rdfDescriptor = new LV2_RDF_Descriptor;
  310. // --------------------------------------------------
  311. // Set Plugin Type
  312. {
  313. Lilv::Nodes typeNodes(lilvPlugin.get_value(lv2World.rdf_type));
  314. if (typeNodes.size() > 0)
  315. {
  316. #if 0
  317. if (typeNodes.contains(lv2World.class_allpass))
  318. rdfDescriptor->Type |= LV2_PLUGIN_ALLPASS;
  319. if (typeNodes.contains(lv2World.class_amplifier))
  320. rdfDescriptor->Type |= LV2_PLUGIN_AMPLIFIER;
  321. if (typeNodes.contains(lv2World.class_analyzer))
  322. rdfDescriptor->Type |= LV2_PLUGIN_ANALYSER;
  323. if (typeNodes.contains(lv2World.class_bandpass))
  324. rdfDescriptor->Type |= LV2_PLUGIN_BANDPASS;
  325. if (typeNodes.contains(lv2World.class_chorus))
  326. rdfDescriptor->Type |= LV2_PLUGIN_CHORUS;
  327. if (typeNodes.contains(lv2World.class_comb))
  328. rdfDescriptor->Type |= LV2_PLUGIN_COMB;
  329. if (typeNodes.contains(lv2World.class_compressor))
  330. rdfDescriptor->Type |= LV2_PLUGIN_COMPRESSOR;
  331. if (typeNodes.contains(lv2World.class_constant))
  332. rdfDescriptor->Type |= LV2_PLUGIN_CONSTANT;
  333. if (typeNodes.contains(lv2World.class_converter))
  334. rdfDescriptor->Type |= LV2_PLUGIN_CONVERTER;
  335. if (typeNodes.contains(lv2World.class_delay))
  336. rdfDescriptor->Type |= LV2_PLUGIN_DELAY;
  337. if (typeNodes.contains(lv2World.class_distortion))
  338. rdfDescriptor->Type |= LV2_PLUGIN_DISTORTION;
  339. if (typeNodes.contains(lv2World.class_dynamics))
  340. rdfDescriptor->Type |= LV2_PLUGIN_DYNAMICS;
  341. if (typeNodes.contains(lv2World.class_eq))
  342. rdfDescriptor->Type |= LV2_PLUGIN_EQ;
  343. if (typeNodes.contains(lv2World.class_expander))
  344. rdfDescriptor->Type |= LV2_PLUGIN_EXPANDER;
  345. if (typeNodes.contains(lv2World.class_filter))
  346. rdfDescriptor->Type |= LV2_PLUGIN_FILTER;
  347. if (typeNodes.contains(lv2World.class_flanger))
  348. rdfDescriptor->Type |= LV2_PLUGIN_FLANGER;
  349. if (typeNodes.contains(lv2World.class_function))
  350. rdfDescriptor->Type |= LV2_PLUGIN_FUNCTION;
  351. if (typeNodes.contains(lv2World.class_gate))
  352. rdfDescriptor->Type |= LV2_PLUGIN_GATE;
  353. if (typeNodes.contains(lv2World.class_generator))
  354. rdfDescriptor->Type |= LV2_PLUGIN_GENERATOR;
  355. if (typeNodes.contains(lv2World.class_highpass))
  356. rdfDescriptor->Type |= LV2_PLUGIN_HIGHPASS;
  357. if (typeNodes.contains(lv2World.class_instrument))
  358. rdfDescriptor->Type |= LV2_PLUGIN_INSTRUMENT;
  359. if (typeNodes.contains(lv2World.class_limiter))
  360. rdfDescriptor->Type |= LV2_PLUGIN_LIMITER;
  361. if (typeNodes.contains(lv2World.class_lowpass))
  362. rdfDescriptor->Type |= LV2_PLUGIN_LOWPASS;
  363. if (typeNodes.contains(lv2World.class_mixer))
  364. rdfDescriptor->Type |= LV2_PLUGIN_MIXER;
  365. if (typeNodes.contains(lv2World.class_modulator))
  366. rdfDescriptor->Type |= LV2_PLUGIN_MODULATOR;
  367. if (typeNodes.contains(lv2World.class_multiEQ))
  368. rdfDescriptor->Type |= LV2_PLUGIN_MULTI_EQ;
  369. if (typeNodes.contains(lv2World.class_oscillator))
  370. rdfDescriptor->Type |= LV2_PLUGIN_OSCILLATOR;
  371. if (typeNodes.contains(lv2World.class_paraEQ))
  372. rdfDescriptor->Type |= LV2_PLUGIN_PARA_EQ;
  373. if (typeNodes.contains(lv2World.class_phaser))
  374. rdfDescriptor->Type |= LV2_PLUGIN_PHASER;
  375. if (typeNodes.contains(lv2World.class_pitch))
  376. rdfDescriptor->Type |= LV2_PLUGIN_PITCH;
  377. if (typeNodes.contains(lv2World.class_reverb))
  378. rdfDescriptor->Type |= LV2_PLUGIN_REVERB;
  379. if (typeNodes.contains(lv2World.class_simulator))
  380. rdfDescriptor->Type |= LV2_PLUGIN_SIMULATOR;
  381. if (typeNodes.contains(lv2World.class_spatial))
  382. rdfDescriptor->Type |= LV2_PLUGIN_SPATIAL;
  383. if (typeNodes.contains(lv2World.class_spectral))
  384. rdfDescriptor->Type |= LV2_PLUGIN_SPECTRAL;
  385. if (typeNodes.contains(lv2World.class_utility))
  386. rdfDescriptor->Type |= LV2_PLUGIN_UTILITY;
  387. if (typeNodes.contains(lv2World.class_waveshaper))
  388. rdfDescriptor->Type |= LV2_PLUGIN_WAVESHAPER;
  389. #endif
  390. }
  391. }
  392. // --------------------------------------------------
  393. // Set Plugin Information
  394. {
  395. rdfDescriptor->URI = strdup(uri);
  396. rdfDescriptor->Binary = strdup(lilv_uri_to_path(lilvPlugin.get_library_uri().as_string()));
  397. rdfDescriptor->Bundle = strdup(lilv_uri_to_path(lilvPlugin.get_bundle_uri().as_string()));
  398. if (lilvPlugin.get_name())
  399. rdfDescriptor->Name = strdup(lilvPlugin.get_name().as_string());
  400. if (lilvPlugin.get_author_name())
  401. rdfDescriptor->Author = strdup(lilvPlugin.get_author_name().as_string());
  402. Lilv::Nodes licenseNodes(lilvPlugin.get_value(lv2World.doap_license));
  403. if (licenseNodes.size() > 0)
  404. rdfDescriptor->License = strdup(licenseNodes.get_first().as_string());
  405. }
  406. // --------------------------------------------------
  407. // Set Plugin UniqueID
  408. {
  409. Lilv::Nodes replaceNodes(lilvPlugin.get_value(lv2World.dct_replaces));
  410. if (replaceNodes.size() > 0)
  411. {
  412. Lilv::Node replaceNode(replaceNodes.get_first());
  413. if (replaceNode.is_uri())
  414. {
  415. const QString replaceURI(replaceNode.as_uri());
  416. if (replaceURI.startsWith("urn:"))
  417. {
  418. const QString replaceId(replaceURI.split(":").last());
  419. bool ok;
  420. long uniqueId = replaceId.toLong(&ok);
  421. if (ok && uniqueId > 0)
  422. rdfDescriptor->UniqueID = uniqueId;
  423. }
  424. }
  425. }
  426. }
  427. // --------------------------------------------------
  428. // Set Plugin Ports
  429. if (lilvPlugin.get_num_ports() > 0)
  430. {
  431. rdfDescriptor->PortCount = lilvPlugin.get_num_ports();
  432. rdfDescriptor->Ports = new LV2_RDF_Port[rdfDescriptor->PortCount];
  433. for (uint32_t j = 0; j < rdfDescriptor->PortCount; j++)
  434. {
  435. Lilv::Port lilvPort(lilvPlugin.get_port_by_index(j));
  436. LV2_RDF_Port* const rdf_port = &rdfDescriptor->Ports[j];
  437. // --------------------------------------
  438. // Set Port Information (first)
  439. {
  440. rdf_port->Name = strdup(Lilv::Node(lilvPort.get_name()).as_string());
  441. rdf_port->Symbol = strdup(Lilv::Node(lilvPort.get_symbol()).as_string());
  442. }
  443. // --------------------------------------
  444. // Set Port Mode and Type
  445. {
  446. #if 0
  447. // Mode
  448. if (lilvPort.is_a(lv2World.port_input))
  449. rdf_port->Type |= LV2_PORT_INPUT;
  450. else if (lilvPort.is_a(lv2World.port_output))
  451. rdf_port->Type |= LV2_PORT_OUTPUT;
  452. else
  453. qWarning("lv2_rdf_new(\"%s\") - port '%s' is not input or output", uri, rdf_port->Name);
  454. // Type
  455. if (lilvPort.is_a(lv2World.port_control))
  456. rdf_port->Type |= LV2_PORT_CONTROL;
  457. else if (lilvPort.is_a(lv2World.port_audio))
  458. rdf_port->Type |= LV2_PORT_AUDIO;
  459. else if (lilvPort.is_a(lv2World.port_cv))
  460. rdf_port->Type |= LV2_PORT_CV;
  461. else if (lilvPort.is_a(lv2World.port_atom))
  462. {
  463. rdf_port->Type |= LV2_PORT_ATOM;
  464. Lilv::Nodes bufferTypeNodes(lilvPort.get_value(lv2World.atom_bufferType));
  465. if (bufferTypeNodes.contains(lv2World.atom_Sequence))
  466. rdf_port->Type |= LV2_PORT_ATOM_SEQUENCE;
  467. Lilv::Nodes supportNodes(lilvPort.get_value(lv2World.atom_supports));
  468. if (supportNodes.contains(lv2World.midi_event))
  469. rdf_port->Type |= LV2_PORT_DATA_MIDI_EVENT;
  470. if (supportNodes.contains(lv2World.patch_message))
  471. rdf_port->Type |= LV2_PORT_DATA_PATCH_MESSAGE;
  472. }
  473. else if (lilvPort.is_a(lv2World.port_event))
  474. {
  475. rdf_port->Type |= LV2_PORT_EVENT;
  476. if (lilvPort.supports_event(lv2World.midi_event))
  477. rdf_port->Type |= LV2_PORT_SUPPORTS_MIDI_EVENT;
  478. }
  479. else if (lilvPort.is_a(lv2World.port_midi))
  480. {
  481. rdf_port->Type |= LV2_PORT_MIDI_LL;
  482. rdf_port->Type |= LV2_PORT_SUPPORTS_MIDI_EVENT;
  483. }
  484. else
  485. #endif
  486. qWarning("lv2_rdf_new(\"%s\") - port '%s' is of unkown type", uri, rdf_port->Name);
  487. }
  488. // --------------------------------------
  489. // Set Port Properties
  490. {
  491. if (lilvPort.has_property(lv2World.pprop_optional))
  492. rdf_port->Properties = LV2_PORT_OPTIONAL;
  493. if (lilvPort.has_property(lv2World.pprop_enumeration))
  494. rdf_port->Properties = LV2_PORT_ENUMERATION;
  495. if (lilvPort.has_property(lv2World.pprop_integer))
  496. rdf_port->Properties = LV2_PORT_INTEGER;
  497. if (lilvPort.has_property(lv2World.pprop_sampleRate))
  498. rdf_port->Properties = LV2_PORT_SAMPLE_RATE;
  499. if (lilvPort.has_property(lv2World.pprop_toggled))
  500. rdf_port->Properties = LV2_PORT_TOGGLED;
  501. if (lilvPort.has_property(lv2World.pprop_artifacts))
  502. rdf_port->Properties = LV2_PORT_CAUSES_ARTIFACTS;
  503. if (lilvPort.has_property(lv2World.pprop_continuousCV))
  504. rdf_port->Properties = LV2_PORT_CONTINUOUS_CV;
  505. if (lilvPort.has_property(lv2World.pprop_discreteCV))
  506. rdf_port->Properties = LV2_PORT_DISCRETE_CV;
  507. if (lilvPort.has_property(lv2World.pprop_expensive))
  508. rdf_port->Properties = LV2_PORT_EXPENSIVE;
  509. if (lilvPort.has_property(lv2World.pprop_strictBounds))
  510. rdf_port->Properties = LV2_PORT_STRICT_BOUNDS;
  511. if (lilvPort.has_property(lv2World.pprop_logarithmic))
  512. rdf_port->Properties = LV2_PORT_LOGARITHMIC;
  513. if (lilvPort.has_property(lv2World.pprop_notAutomatic))
  514. rdf_port->Properties = LV2_PORT_NOT_AUTOMATIC;
  515. if (lilvPort.has_property(lv2World.pprop_notOnGUI))
  516. rdf_port->Properties = LV2_PORT_NOT_ON_GUI;
  517. if (lilvPort.has_property(lv2World.pprop_trigger))
  518. rdf_port->Properties = LV2_PORT_TRIGGER;
  519. if (lilvPort.has_property(lv2World.reportsLatency))
  520. rdf_port->Designation = LV2_PORT_DESIGNATION_LATENCY;
  521. }
  522. // --------------------------------------
  523. // Set Port Designation
  524. {
  525. Lilv::Nodes designationNodes(lilvPort.get_value(lv2World.designation));
  526. if (designationNodes.size() > 0)
  527. {
  528. const char* const designation = designationNodes.get_first().as_string();
  529. if (strcmp(designation, LV2_CORE__freeWheeling) == 0)
  530. rdf_port->Designation = LV2_PORT_DESIGNATION_FREEWHEELING;
  531. else if (strcmp(designation, LV2_CORE__latency) == 0)
  532. rdf_port->Designation = LV2_PORT_DESIGNATION_LATENCY;
  533. else if (strcmp(designation, LV2_PARAMETERS__sampleRate) == 0)
  534. rdf_port->Designation = LV2_PORT_DESIGNATION_SAMPLE_RATE;
  535. else if (strcmp(designation, LV2_TIME__bar) == 0)
  536. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BAR;
  537. else if (strcmp(designation, LV2_TIME__barBeat) == 0)
  538. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BAR_BEAT;
  539. else if (strcmp(designation, LV2_TIME__beat) == 0)
  540. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BEAT;
  541. else if (strcmp(designation, LV2_TIME__beatUnit) == 0)
  542. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BEAT_UNIT;
  543. else if (strcmp(designation, LV2_TIME__beatsPerBar) == 0)
  544. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BEATS_PER_BAR;
  545. else if (strcmp(designation, LV2_TIME__beatsPerMinute) == 0)
  546. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BEATS_PER_MINUTE;
  547. else if (strcmp(designation, LV2_TIME__frame) == 0)
  548. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_FRAME;
  549. else if (strcmp(designation, LV2_TIME__framesPerSecond) == 0)
  550. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_FRAMES_PER_SECOND;
  551. else if (strcmp(designation, LV2_TIME__position) == 0)
  552. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_POSITION;
  553. else if (strcmp(designation, LV2_TIME__speed) == 0)
  554. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_SPEED;
  555. else if (strncmp(designation, LV2_PARAMETERS_PREFIX, strlen(LV2_PARAMETERS_PREFIX)) == 0)
  556. pass();
  557. else if (strncmp(designation, LV2_PORT_GROUPS_PREFIX, strlen(LV2_PORT_GROUPS_PREFIX)) == 0)
  558. pass();
  559. else
  560. qWarning("lv2_rdf_new(\"%s\") - got unknown Port Designation '%s'", uri, designation);
  561. }
  562. }
  563. // --------------------------------------
  564. // Set Port MIDI Map
  565. {
  566. Lilv::Nodes midiMapNodes(lilvPort.get_value(lv2World.mm_defaultControl));
  567. if (midiMapNodes.size() > 0)
  568. {
  569. Lilv::Node midiMapNode(midiMapNodes.get_first());
  570. if (midiMapNode.is_blank())
  571. {
  572. Lilv::Nodes midiMapTypeNodes(lv2World.find_nodes(midiMapNode, lv2World.mm_controlType, nullptr));
  573. Lilv::Nodes midiMapNumberNodes(lv2World.find_nodes(midiMapNode, lv2World.mm_controlNumber, nullptr));
  574. if (midiMapTypeNodes.size() == 1 && midiMapNumberNodes.size() == 1)
  575. {
  576. const char* const midiMapType = midiMapTypeNodes.get_first().as_string();
  577. if (strcmp(midiMapType, LV2_MIDI_Map__CC) == 0)
  578. rdf_port->MidiMap.Type = LV2_PORT_MIDI_MAP_CC;
  579. else if (strcmp(midiMapType, LV2_MIDI_Map__NRPN) == 0)
  580. rdf_port->MidiMap.Type = LV2_PORT_MIDI_MAP_NRPN;
  581. else
  582. qWarning("lv2_rdf_new(\"%s\") - got unknown Port Midi Map type '%s'", uri, midiMapType);
  583. rdf_port->MidiMap.Number = midiMapNumberNodes.get_first().as_int();
  584. }
  585. }
  586. }
  587. }
  588. // --------------------------------------
  589. // Set Port Points
  590. {
  591. Lilv::Nodes valueNodes(lilvPort.get_value(lv2World.value_default));
  592. if (valueNodes.size() > 0)
  593. {
  594. rdf_port->Points.Hints |= LV2_PORT_POINT_DEFAULT;
  595. rdf_port->Points.Default = valueNodes.get_first().as_float();
  596. }
  597. valueNodes = lilvPort.get_value(lv2World.value_minimum);
  598. if (valueNodes.size() > 0)
  599. {
  600. rdf_port->Points.Hints |= LV2_PORT_POINT_MINIMUM;
  601. rdf_port->Points.Minimum = valueNodes.get_first().as_float();
  602. }
  603. valueNodes = lilvPort.get_value(lv2World.value_maximum);
  604. if (valueNodes.size() > 0)
  605. {
  606. rdf_port->Points.Hints |= LV2_PORT_POINT_MAXIMUM;
  607. rdf_port->Points.Maximum = valueNodes.get_first().as_float();
  608. }
  609. }
  610. // --------------------------------------
  611. // Set Port Unit
  612. {
  613. Lilv::Nodes unitTypeNodes(lilvPort.get_value(lv2World.unit_unit));
  614. if (unitTypeNodes.size() > 0)
  615. {
  616. rdf_port->Unit.Hints |= LV2_PORT_UNIT_UNIT;
  617. const char* const unitType = unitTypeNodes.get_first().as_uri();
  618. if (strcmp(unitType, LV2_UNITS__bar) == 0)
  619. rdf_port->Unit.Unit = LV2_PORT_UNIT_BAR;
  620. else if (strcmp(unitType, LV2_UNITS__beat) == 0)
  621. rdf_port->Unit.Unit = LV2_PORT_UNIT_BEAT;
  622. else if (strcmp(unitType, LV2_UNITS__bpm) == 0)
  623. rdf_port->Unit.Unit = LV2_PORT_UNIT_BPM;
  624. else if (strcmp(unitType, LV2_UNITS__cent) == 0)
  625. rdf_port->Unit.Unit = LV2_PORT_UNIT_CENT;
  626. else if (strcmp(unitType, LV2_UNITS__cm) == 0)
  627. rdf_port->Unit.Unit = LV2_PORT_UNIT_CM;
  628. else if (strcmp(unitType, LV2_UNITS__coef) == 0)
  629. rdf_port->Unit.Unit = LV2_PORT_UNIT_COEF;
  630. else if (strcmp(unitType, LV2_UNITS__db) == 0)
  631. rdf_port->Unit.Unit = LV2_PORT_UNIT_DB;
  632. else if (strcmp(unitType, LV2_UNITS__degree) == 0)
  633. rdf_port->Unit.Unit = LV2_PORT_UNIT_DEGREE;
  634. else if (strcmp(unitType, LV2_UNITS__frame) == 0)
  635. rdf_port->Unit.Unit = LV2_PORT_UNIT_FRAME;
  636. else if (strcmp(unitType, LV2_UNITS__hz) == 0)
  637. rdf_port->Unit.Unit = LV2_PORT_UNIT_HZ;
  638. else if (strcmp(unitType, LV2_UNITS__inch) == 0)
  639. rdf_port->Unit.Unit = LV2_PORT_UNIT_INCH;
  640. else if (strcmp(unitType, LV2_UNITS__khz) == 0)
  641. rdf_port->Unit.Unit = LV2_PORT_UNIT_KHZ;
  642. else if (strcmp(unitType, LV2_UNITS__km) == 0)
  643. rdf_port->Unit.Unit = LV2_PORT_UNIT_KM;
  644. else if (strcmp(unitType, LV2_UNITS__m) == 0)
  645. rdf_port->Unit.Unit = LV2_PORT_UNIT_M;
  646. else if (strcmp(unitType, LV2_UNITS__mhz) == 0)
  647. rdf_port->Unit.Unit = LV2_PORT_UNIT_MHZ;
  648. else if (strcmp(unitType, LV2_UNITS__midiNote) == 0)
  649. rdf_port->Unit.Unit = LV2_PORT_UNIT_MIDINOTE;
  650. else if (strcmp(unitType, LV2_UNITS__mile) == 0)
  651. rdf_port->Unit.Unit = LV2_PORT_UNIT_MILE;
  652. else if (strcmp(unitType, LV2_UNITS__min) == 0)
  653. rdf_port->Unit.Unit = LV2_PORT_UNIT_MIN;
  654. else if (strcmp(unitType, LV2_UNITS__mm) == 0)
  655. rdf_port->Unit.Unit = LV2_PORT_UNIT_MM;
  656. else if (strcmp(unitType, LV2_UNITS__ms) == 0)
  657. rdf_port->Unit.Unit = LV2_PORT_UNIT_MS;
  658. else if (strcmp(unitType, LV2_UNITS__oct) == 0)
  659. rdf_port->Unit.Unit = LV2_PORT_UNIT_OCT;
  660. else if (strcmp(unitType, LV2_UNITS__pc) == 0)
  661. rdf_port->Unit.Unit = LV2_PORT_UNIT_PC;
  662. else if (strcmp(unitType, LV2_UNITS__s) == 0)
  663. rdf_port->Unit.Unit = LV2_PORT_UNIT_S;
  664. else if (strcmp(unitType, LV2_UNITS__semitone12TET) == 0)
  665. rdf_port->Unit.Unit = LV2_PORT_UNIT_SEMITONE;
  666. else
  667. qWarning("lv2_rdf_new(\"%s\") - got unknown Unit type '%s'", uri, unitType);
  668. }
  669. Lilv::Nodes unitNameNodes(lilvPort.get_value(lv2World.unit_name));
  670. if (unitNameNodes.size() > 0)
  671. {
  672. rdf_port->Unit.Hints |= LV2_PORT_UNIT_NAME;
  673. rdf_port->Unit.Name = strdup(unitNameNodes.get_first().as_string());
  674. }
  675. Lilv::Nodes unitRenderNodes(lilvPort.get_value(lv2World.unit_render));
  676. if (unitRenderNodes.size() > 0)
  677. {
  678. rdf_port->Unit.Hints |= LV2_PORT_UNIT_RENDER;
  679. rdf_port->Unit.Render = strdup(unitRenderNodes.get_first().as_string());
  680. }
  681. Lilv::Nodes unitSymbolNodes(lilvPort.get_value(lv2World.unit_symbol));
  682. if (unitSymbolNodes.size() > 0)
  683. {
  684. rdf_port->Unit.Hints |= LV2_PORT_UNIT_SYMBOL;
  685. rdf_port->Unit.Symbol = strdup(unitSymbolNodes.get_first().as_string());
  686. }
  687. }
  688. // --------------------------------------
  689. // Set Port Scale Points
  690. Lilv::ScalePoints lilvScalePoints(lilvPort.get_scale_points());
  691. if (lilvScalePoints.size() > 0)
  692. {
  693. rdf_port->ScalePointCount = lilvScalePoints.size();
  694. rdf_port->ScalePoints = new LV2_RDF_PortScalePoint[rdf_port->ScalePointCount];
  695. uint32_t h = 0;
  696. LILV_FOREACH(scale_points, j, lilvScalePoints)
  697. {
  698. Lilv::ScalePoint lilvScalePoint(lilvScalePoints.get(j));
  699. LV2_RDF_PortScalePoint* const rdf_scalePoint = &rdf_port->ScalePoints[h++];
  700. rdf_scalePoint->Label = strdup(Lilv::Node(lilvScalePoint.get_label()).as_string());
  701. rdf_scalePoint->Value = Lilv::Node(lilvScalePoint.get_value()).as_float();
  702. }
  703. }
  704. }
  705. }
  706. #if 0
  707. // --------------------------------------------------
  708. // Set Plugin Presets (TODO)
  709. {
  710. Lilv::Nodes presetNodes(lilvPlugin.get_related(lv2World.preset_preset));
  711. if (presetNodes.size() > 0)
  712. {
  713. // create a list of preset URIs (for checking appliesTo, sorting and uniqueness)
  714. QStringList presetListURIs;
  715. LILV_FOREACH(nodes, j, presetNodes)
  716. {
  717. Lilv::Node presetNode(presetNodes.get(j));
  718. // FIXME - check appliesTo
  719. QString presetURI(presetNode.as_uri());
  720. if (! presetListURIs.contains(presetURI))
  721. presetListURIs.append(presetURI);
  722. }
  723. presetListURIs.sort();
  724. // create presets with unique URIs
  725. rdfDescriptor->PresetCount = presetListURIs.count();
  726. rdfDescriptor->Presets = new LV2_RDF_Preset[rdfDescriptor->PresetCount];
  727. // set preset data
  728. LILV_FOREACH(nodes, j, presetNodes)
  729. {
  730. Lilv::Node presetNode(presetNodes.get(j));
  731. lv2World.load_resource(presetNode);
  732. LV2_URI presetURI = presetNode.as_uri();
  733. int32_t index = presetListURIs.indexOf(QString(presetURI));
  734. if (index < 0)
  735. continue;
  736. LV2_RDF_Preset* const rdf_preset = &rdfDescriptor->Presets[index];
  737. // --------------------------------------
  738. // Set Preset Information
  739. {
  740. rdf_preset->URI = strdup(presetURI);
  741. Lilv::Nodes presetLabelNodes(lv2World.find_nodes(presetNode, lv2World.rdfs_label, nullptr));
  742. if (presetLabelNodes.size() > 0)
  743. rdf_preset->Label = strdup(presetLabelNodes.get_first().as_string());
  744. }
  745. // --------------------------------------
  746. // Set Preset Ports
  747. {
  748. Lilv::Nodes presetPortNodes(lv2World.find_nodes(presetNode, lv2World.port, nullptr));
  749. if (presetPortNodes.size() > 0)
  750. {
  751. rdf_preset->PortCount = presetPortNodes.size();
  752. rdf_preset->Ports = new LV2_RDF_PresetPort[rdf_preset->PortCount];
  753. uint32_t h = 0;
  754. LILV_FOREACH(nodes, k, presetPortNodes)
  755. {
  756. Lilv::Node presetPortNode(presetPortNodes.get(k));
  757. Lilv::Nodes presetPortSymbolNodes(lv2World.find_nodes(presetPortNode, lv2World.symbol, nullptr));
  758. Lilv::Nodes presetPortValueNodes(lv2World.find_nodes(presetPortNode, lv2World.preset_value, nullptr));
  759. if (presetPortSymbolNodes.size() == 1 && presetPortValueNodes.size() == 1)
  760. {
  761. LV2_RDF_PresetPort* const rdf_presetPort = &rdf_preset->Ports[h++];
  762. rdf_presetPort->Symbol = strdup(presetPortSymbolNodes.get_first().as_string());
  763. rdf_presetPort->Value = presetPortValueNodes.get_first().as_float();
  764. }
  765. }
  766. }
  767. }
  768. // --------------------------------------
  769. // Set Preset States
  770. {
  771. Lilv::Nodes presetStateNodes(lv2World.find_nodes(presetNode, lv2World.state_state, nullptr));
  772. if (presetStateNodes.size() > 0)
  773. {
  774. rdf_preset->StateCount = presetStateNodes.size();
  775. rdf_preset->States = new LV2_RDF_PresetState[rdf_preset->StateCount];
  776. uint32_t h = 0;
  777. LILV_FOREACH(nodes, k, presetStateNodes)
  778. {
  779. Lilv::Node presetStateNode(presetStateNodes.get(k));
  780. if (presetStateNode.is_blank())
  781. {
  782. // TODO
  783. LV2_RDF_PresetState* const rdf_presetState = &rdf_preset->States[h++];
  784. rdf_presetState->Type = LV2_PRESET_STATE_NULL;
  785. rdf_presetState->Key = nullptr;
  786. }
  787. }
  788. }
  789. }
  790. }
  791. }
  792. }
  793. #endif
  794. // --------------------------------------------------
  795. // Set Plugin Features
  796. {
  797. Lilv::Nodes lilvFeatureNodes(lilvPlugin.get_supported_features());
  798. if (lilvFeatureNodes.size() > 0)
  799. {
  800. Lilv::Nodes lilvFeatureNodesR(lilvPlugin.get_required_features());
  801. rdfDescriptor->FeatureCount = lilvFeatureNodes.size();
  802. rdfDescriptor->Features = new LV2_RDF_Feature[rdfDescriptor->FeatureCount];
  803. uint32_t h = 0;
  804. LILV_FOREACH(nodes, j, lilvFeatureNodes)
  805. {
  806. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(j));
  807. LV2_RDF_Feature* const rdf_feature = &rdfDescriptor->Features[h++];
  808. rdf_feature->Type = lilvFeatureNodesR.contains(lilvFeatureNode) ? LV2_FEATURE_REQUIRED : LV2_FEATURE_OPTIONAL;
  809. rdf_feature->URI = strdup(lilvFeatureNode.as_uri());
  810. }
  811. }
  812. }
  813. // --------------------------------------------------
  814. // Set Plugin Extensions
  815. {
  816. Lilv::Nodes lilvExtensionDataNodes(lilvPlugin.get_extension_data());
  817. if (lilvExtensionDataNodes.size() > 0)
  818. {
  819. rdfDescriptor->ExtensionCount = lilvExtensionDataNodes.size();
  820. rdfDescriptor->Extensions = new LV2_URI[rdfDescriptor->ExtensionCount];
  821. uint32_t h = 0;
  822. LILV_FOREACH(nodes, j, lilvExtensionDataNodes)
  823. {
  824. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(j));
  825. LV2_URI* const rdf_extension = &rdfDescriptor->Extensions[h++];
  826. *rdf_extension = strdup(lilvExtensionDataNode.as_uri());
  827. }
  828. }
  829. }
  830. // --------------------------------------------------
  831. // Set Plugin UIs
  832. {
  833. Lilv::UIs lilvUIs(lilvPlugin.get_uis());
  834. if (lilvUIs.size() > 0)
  835. {
  836. rdfDescriptor->UICount = lilvUIs.size();
  837. rdfDescriptor->UIs = new LV2_RDF_UI[rdfDescriptor->UICount];
  838. uint32_t h = 0;
  839. LILV_FOREACH(uis, j, lilvUIs)
  840. {
  841. Lilv::UI lilvUI(lilvUIs.get(j));
  842. LV2_RDF_UI* const rdf_ui = &rdfDescriptor->UIs[h++];
  843. // --------------------------------------
  844. // Set UI Type
  845. {
  846. #if 0
  847. if (lilvUI.is_a(lv2World.ui_gtk2))
  848. rdf_ui->Type = LV2_UI_GTK2;
  849. else if (lilvUI.is_a(lv2World.ui_gtk3))
  850. rdf_ui->Type = LV2_UI_GTK3;
  851. else if (lilvUI.is_a(lv2World.ui_qt4))
  852. rdf_ui->Type = LV2_UI_QT4;
  853. else if (lilvUI.is_a(lv2World.ui_cocoa))
  854. rdf_ui->Type = LV2_UI_COCOA;
  855. else if (lilvUI.is_a(lv2World.ui_windows))
  856. rdf_ui->Type = LV2_UI_WINDOWS;
  857. else if (lilvUI.is_a(lv2World.ui_x11))
  858. rdf_ui->Type = LV2_UI_X11;
  859. else if (lilvUI.is_a(lv2World.ui_external))
  860. rdf_ui->Type = LV2_UI_EXTERNAL;
  861. else if (lilvUI.is_a(lv2World.ui_externalOld))
  862. rdf_ui->Type = LV2_UI_OLD_EXTERNAL;
  863. else
  864. #endif
  865. qWarning("lv2_rdf_new(\"%s\") - got unknown UI type for '%s'", uri, lilvUI.get_uri().as_uri());
  866. }
  867. // --------------------------------------
  868. // Set UI Information
  869. {
  870. rdf_ui->URI = strdup(lilvUI.get_uri().as_uri());
  871. rdf_ui->Binary = strdup(lilv_uri_to_path(lilvUI.get_binary_uri().as_string()));
  872. rdf_ui->Bundle = strdup(lilv_uri_to_path(lilvUI.get_bundle_uri().as_string()));
  873. }
  874. // --------------------------------------
  875. // Set UI Features
  876. {
  877. Lilv::Nodes lilvFeatureNodes(lilvUI.get_supported_features());
  878. if (lilvFeatureNodes.size() > 0)
  879. {
  880. Lilv::Nodes lilvFeatureNodesR(lilvUI.get_required_features());
  881. rdf_ui->FeatureCount = lilvFeatureNodes.size();
  882. rdf_ui->Features = new LV2_RDF_Feature[rdf_ui->FeatureCount];
  883. uint32_t x = 0;
  884. LILV_FOREACH(nodes, k, lilvFeatureNodes)
  885. {
  886. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(k));
  887. LV2_RDF_Feature* const rdf_feature = &rdf_ui->Features[x++];
  888. rdf_feature->Type = lilvFeatureNodesR.contains(lilvFeatureNode) ? LV2_FEATURE_REQUIRED : LV2_FEATURE_OPTIONAL;
  889. rdf_feature->URI = strdup(lilvFeatureNode.as_uri());
  890. }
  891. }
  892. }
  893. // --------------------------------------
  894. // Set UI Extensions
  895. {
  896. Lilv::Nodes lilvExtensionDataNodes(lilvUI.get_extension_data());
  897. if (lilvExtensionDataNodes.size() > 0)
  898. {
  899. rdf_ui->ExtensionCount = lilvExtensionDataNodes.size();
  900. rdf_ui->Extensions = new LV2_URI[rdf_ui->ExtensionCount];
  901. uint32_t x = 0;
  902. LILV_FOREACH(nodes, k, lilvExtensionDataNodes)
  903. {
  904. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(k));
  905. LV2_URI* const rdf_extension = &rdf_ui->Extensions[x++];
  906. *rdf_extension = strdup(lilvExtensionDataNode.as_uri());
  907. }
  908. }
  909. }
  910. }
  911. }
  912. }
  913. return rdfDescriptor;
  914. }
  915. return nullptr;
  916. }
  917. // ------------------------------------------------------------------------------------------------
  918. static inline
  919. bool is_lv2_feature_supported(const LV2_URI uri)
  920. {
  921. if (strcmp(uri, LV2_CORE__hardRTCapable) == 0)
  922. return true;
  923. if (strcmp(uri, LV2_CORE__inPlaceBroken) == 0)
  924. return true;
  925. if (strcmp(uri, LV2_CORE__isLive) == 0)
  926. return true;
  927. if (strcmp(uri, LV2_EVENT_URI) == 0)
  928. return true;
  929. if (strcmp(uri, LV2_LOG__log) == 0)
  930. return true;
  931. if (strcmp(uri, LV2_OPTIONS__options) == 0)
  932. return true;
  933. if (strcmp(uri, LV2_PROGRAMS__Host) == 0)
  934. return true;
  935. if (strcmp(uri, LV2_RTSAFE_MEMORY_POOL__Pool) == 0)
  936. return true;
  937. if (strcmp(uri, LV2_STATE__makePath) == 0)
  938. return true;
  939. if (strcmp(uri, LV2_STATE__mapPath) == 0)
  940. return true;
  941. if (strcmp(uri, LV2_PORT_PROPS__supportsStrictBounds) == 0)
  942. return true;
  943. if (strcmp(uri, LV2_URI_MAP_URI) == 0)
  944. return true;
  945. if (strcmp(uri, LV2_URID__map) == 0)
  946. return true;
  947. if (strcmp(uri, LV2_URID__unmap) == 0)
  948. return true;
  949. if (strcmp(uri, LV2_WORKER__schedule) == 0)
  950. return true;
  951. return false;
  952. }
  953. static inline
  954. bool is_lv2_ui_feature_supported(const LV2_URI uri)
  955. {
  956. if (is_lv2_feature_supported(uri))
  957. return true;
  958. if (strcmp(uri, LV2_DATA_ACCESS_URI) == 0)
  959. return true;
  960. if (strcmp(uri, LV2_INSTANCE_ACCESS_URI) == 0)
  961. return true;
  962. if (strcmp(uri, LV2_UI__fixedSize) == 0)
  963. return true;
  964. if (strcmp(uri, LV2_UI__makeResident) == 0)
  965. return true;
  966. if (strcmp(uri, LV2_UI__noUserResize) == 0)
  967. return true;
  968. if (strcmp(uri, LV2_UI__parent) == 0)
  969. return true;
  970. if (strcmp(uri, LV2_UI__portMap) == 0)
  971. return true;
  972. if (strcmp(uri, LV2_UI__portSubscribe) == 0)
  973. return false; // TODO
  974. if (strcmp(uri, LV2_UI__resize) == 0)
  975. return true;
  976. if (strcmp(uri, LV2_UI__touch) == 0)
  977. return false; // TODO
  978. if (strcmp(uri, LV2_EXTERNAL_UI__Widget) == 0)
  979. return true;
  980. if (strcmp(uri, LV2_EXTERNAL_UI_DEPRECATED_URI) == 0)
  981. return true;
  982. return false;
  983. }
  984. static inline
  985. LV2_URI get_lv2_ui_uri(const LV2_Property type)
  986. {
  987. switch (type)
  988. {
  989. case LV2_UI_GTK2:
  990. return LV2_UI__GtkUI;
  991. case LV2_UI_GTK3:
  992. return LV2_UI__Gtk3UI;
  993. case LV2_UI_QT4:
  994. return LV2_UI__Qt4UI;
  995. case LV2_UI_COCOA:
  996. return LV2_UI__CocoaUI;
  997. case LV2_UI_WINDOWS:
  998. return LV2_UI__WindowsUI;
  999. case LV2_UI_X11:
  1000. return LV2_UI__X11UI;
  1001. case LV2_UI_EXTERNAL:
  1002. return LV2_EXTERNAL_UI__Widget;
  1003. case LV2_UI_OLD_EXTERNAL:
  1004. return LV2_EXTERNAL_UI_DEPRECATED_URI;
  1005. default:
  1006. return "UI URI type not supported";
  1007. }
  1008. }