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.

1537 lines
61KB

  1. /*
  2. * Carla common LV2 code
  3. * Copyright (C) 2011-2012 Filipe Coelho <falktx@gmail.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_INCLUDES_H
  18. #define CARLA_LV2_INCLUDES_H
  19. // TODO - presets state
  20. #include "lv2/lv2.h"
  21. #include "lv2/atom.h"
  22. #include "lv2/atom-forge.h"
  23. #include "lv2/atom-util.h"
  24. #include "lv2/buf-size.h"
  25. #include "lv2/data-access.h"
  26. // dynmanifest
  27. #include "lv2/event.h"
  28. #include "lv2/event-helpers.h"
  29. #include "lv2/instance-access.h"
  30. #include "lv2/log.h"
  31. #include "lv2/midi.h"
  32. #include "lv2/options.h"
  33. #include "lv2/parameters.h"
  34. #include "lv2/patch.h"
  35. #include "lv2/port-groups.h"
  36. #include "lv2/port-props.h"
  37. #include "lv2/presets.h"
  38. // resize-port
  39. #include "lv2/state.h"
  40. #include "lv2/time.h"
  41. #include "lv2/ui.h"
  42. #include "lv2/units.h"
  43. #include "lv2/uri-map.h"
  44. #include "lv2/urid.h"
  45. #include "lv2/worker.h"
  46. #include "lv2/lv2-miditype.h"
  47. #include "lv2/lv2-midifunctions.h"
  48. #include "lv2/lv2_external_ui.h"
  49. #include "lv2/lv2_programs.h"
  50. #include "lv2_rdf.h"
  51. #include "lilv/lilvmm.hpp"
  52. #include "sratom/sratom.h"
  53. #include <QtCore/QMap>
  54. #include <QtCore/QString>
  55. #include <QtCore/QStringList>
  56. // ------------------------------------------------------------------------------------------------
  57. #define NS_dct "http://purl.org/dc/terms/"
  58. #define NS_doap "http://usefulinc.com/ns/doap#"
  59. #define NS_rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  60. #define NS_rdfs "http://www.w3.org/2000/01/rdf-schema#"
  61. #define NS_llmm "http://ll-plugins.nongnu.org/lv2/ext/midimap#"
  62. #define LV2_MIDI_Map__CC "http://ll-plugins.nongnu.org/lv2/namespace#CC"
  63. #define LV2_MIDI_Map__NRPN "http://ll-plugins.nongnu.org/lv2/namespace#NRPN"
  64. #define LV2_MIDI_LL__MidiPort "http://ll-plugins.nongnu.org/lv2/ext/MidiPort"
  65. #define LV2_UI__makeResident LV2_UI_PREFIX "makeResident"
  66. class Lv2WorldClass : public Lilv::World
  67. {
  68. public:
  69. Lv2WorldClass() : Lilv::World(),
  70. port (new_uri(LV2_CORE__port)),
  71. symbol (new_uri(LV2_CORE__symbol)),
  72. designation (new_uri(LV2_CORE__designation)),
  73. freewheeling (new_uri(LV2_CORE__freeWheeling)),
  74. reportsLatency (new_uri(LV2_CORE__reportsLatency)),
  75. class_allpass (new_uri(LV2_CORE__AllpassPlugin)),
  76. class_amplifier (new_uri(LV2_CORE__AmplifierPlugin)),
  77. class_analyzer (new_uri(LV2_CORE__AnalyserPlugin)),
  78. class_bandpass (new_uri(LV2_CORE__BandpassPlugin)),
  79. class_chorus (new_uri(LV2_CORE__ChorusPlugin)),
  80. class_comb (new_uri(LV2_CORE__CombPlugin)),
  81. class_compressor (new_uri(LV2_CORE__CompressorPlugin)),
  82. class_constant (new_uri(LV2_CORE__ConstantPlugin)),
  83. class_converter (new_uri(LV2_CORE__ConverterPlugin)),
  84. class_delay (new_uri(LV2_CORE__DelayPlugin)),
  85. class_distortion (new_uri(LV2_CORE__DistortionPlugin)),
  86. class_dynamics (new_uri(LV2_CORE__DynamicsPlugin)),
  87. class_eq (new_uri(LV2_CORE__EQPlugin)),
  88. class_expander (new_uri(LV2_CORE__ExpanderPlugin)),
  89. class_filter (new_uri(LV2_CORE__FilterPlugin)),
  90. class_flanger (new_uri(LV2_CORE__FlangerPlugin)),
  91. class_function (new_uri(LV2_CORE__FunctionPlugin)),
  92. class_gate (new_uri(LV2_CORE__GatePlugin)),
  93. class_generator (new_uri(LV2_CORE__GeneratorPlugin)),
  94. class_highpass (new_uri(LV2_CORE__HighpassPlugin)),
  95. class_instrument (new_uri(LV2_CORE__InstrumentPlugin)),
  96. class_limiter (new_uri(LV2_CORE__LimiterPlugin)),
  97. class_lowpass (new_uri(LV2_CORE__LowpassPlugin)),
  98. class_mixer (new_uri(LV2_CORE__MixerPlugin)),
  99. class_modulator (new_uri(LV2_CORE__ModulatorPlugin)),
  100. class_multi_eq (new_uri(LV2_CORE__MultiEQPlugin)),
  101. class_oscillator (new_uri(LV2_CORE__OscillatorPlugin)),
  102. class_para_eq (new_uri(LV2_CORE__ParaEQPlugin)),
  103. class_phaser (new_uri(LV2_CORE__PhaserPlugin)),
  104. class_pitch (new_uri(LV2_CORE__PitchPlugin)),
  105. class_reverb (new_uri(LV2_CORE__ReverbPlugin)),
  106. class_simulator (new_uri(LV2_CORE__SimulatorPlugin)),
  107. class_spatial (new_uri(LV2_CORE__SpatialPlugin)),
  108. class_spectral (new_uri(LV2_CORE__SpectralPlugin)),
  109. class_utility (new_uri(LV2_CORE__UtilityPlugin)),
  110. class_waveshaper (new_uri(LV2_CORE__WaveshaperPlugin)),
  111. port_input (new_uri(LV2_CORE__InputPort)),
  112. port_output (new_uri(LV2_CORE__OutputPort)),
  113. port_control (new_uri(LV2_CORE__ControlPort)),
  114. port_audio (new_uri(LV2_CORE__AudioPort)),
  115. port_cv (new_uri(LV2_CORE__CVPort)),
  116. port_atom (new_uri(LV2_ATOM__AtomPort)),
  117. port_event (new_uri(LV2_EVENT__EventPort)),
  118. port_midi_ll (new_uri(LV2_MIDI_LL__MidiPort)),
  119. pprop_optional (new_uri(LV2_CORE__connectionOptional)),
  120. pprop_enumeration (new_uri(LV2_CORE__enumeration)),
  121. pprop_integer (new_uri(LV2_CORE__integer)),
  122. pprop_sample_rate (new_uri(LV2_CORE__sampleRate)),
  123. pprop_toggled (new_uri(LV2_CORE__toggled)),
  124. pprop_artifacts (new_uri(LV2_PORT_PROPS__causesArtifacts)),
  125. pprop_continuous_cv (new_uri(LV2_PORT_PROPS__continuousCV)),
  126. pprop_discrete_cv (new_uri(LV2_PORT_PROPS__discreteCV)),
  127. pprop_expensive (new_uri(LV2_PORT_PROPS__expensive)),
  128. pprop_strict_bounds (new_uri(LV2_PORT_PROPS__hasStrictBounds)),
  129. pprop_logarithmic (new_uri(LV2_PORT_PROPS__logarithmic)),
  130. pprop_not_automatic (new_uri(LV2_PORT_PROPS__notAutomatic)),
  131. pprop_not_on_gui (new_uri(LV2_PORT_PROPS__notOnGUI)),
  132. pprop_trigger (new_uri(LV2_PORT_PROPS__trigger)),
  133. unit_unit (new_uri(LV2_UNITS__unit)),
  134. unit_name (new_uri(LV2_UNITS__name)),
  135. unit_render (new_uri(LV2_UNITS__render)),
  136. unit_symbol (new_uri(LV2_UNITS__symbol)),
  137. ui_gtk2 (new_uri(LV2_UI__GtkUI)),
  138. ui_gtk3 (new_uri(LV2_UI__Gtk3UI)),
  139. ui_qt4 (new_uri(LV2_UI__Qt4UI)),
  140. ui_cocoa (new_uri(LV2_UI__CocoaUI)),
  141. ui_windows (new_uri(LV2_UI__WindowsUI)),
  142. ui_x11 (new_uri(LV2_UI__X11UI)),
  143. ui_external (new_uri(LV2_EXTERNAL_UI__Widget)),
  144. ui_external_old (new_uri(LV2_EXTERNAL_UI_DEPRECATED_URI)),
  145. preset_preset (new_uri(LV2_PRESETS__Preset)),
  146. preset_value (new_uri(LV2_PRESETS__value)),
  147. state_state (new_uri(LV2_STATE__state)),
  148. value_default (new_uri(LV2_CORE__default)),
  149. value_minimum (new_uri(LV2_CORE__minimum)),
  150. value_maximum (new_uri(LV2_CORE__maximum)),
  151. atom_sequence (new_uri(LV2_ATOM__Sequence)),
  152. atom_buffer_type (new_uri(LV2_ATOM__bufferType)),
  153. atom_supports (new_uri(LV2_ATOM__supports)),
  154. midi_event (new_uri(LV2_MIDI__MidiEvent)),
  155. patch_message (new_uri(LV2_PATCH__Message)),
  156. mm_default_control (new_uri(NS_llmm "defaultMidiController")),
  157. mm_control_type (new_uri(NS_llmm "controllerType")),
  158. mm_control_number (new_uri(NS_llmm "controllerNumber")),
  159. dct_replaces (new_uri(NS_dct "replaces")),
  160. doap_license (new_uri(NS_doap "license")),
  161. rdf_type (new_uri(NS_rdf "type")),
  162. rdfs_label (new_uri(NS_rdfs "label"))
  163. {
  164. needInit = true;
  165. }
  166. // Base Types
  167. Lilv::Node port;
  168. Lilv::Node symbol;
  169. Lilv::Node designation;
  170. Lilv::Node freewheeling;
  171. Lilv::Node reportsLatency;
  172. // Plugin Types
  173. Lilv::Node class_allpass;
  174. Lilv::Node class_amplifier;
  175. Lilv::Node class_analyzer;
  176. Lilv::Node class_bandpass;
  177. Lilv::Node class_chorus;
  178. Lilv::Node class_comb;
  179. Lilv::Node class_compressor;
  180. Lilv::Node class_constant;
  181. Lilv::Node class_converter;
  182. Lilv::Node class_delay;
  183. Lilv::Node class_distortion;
  184. Lilv::Node class_dynamics;
  185. Lilv::Node class_eq;
  186. Lilv::Node class_expander;
  187. Lilv::Node class_filter;
  188. Lilv::Node class_flanger;
  189. Lilv::Node class_function;
  190. Lilv::Node class_gate;
  191. Lilv::Node class_generator;
  192. Lilv::Node class_highpass;
  193. Lilv::Node class_instrument;
  194. Lilv::Node class_limiter;
  195. Lilv::Node class_lowpass;
  196. Lilv::Node class_mixer;
  197. Lilv::Node class_modulator;
  198. Lilv::Node class_multi_eq;
  199. Lilv::Node class_oscillator;
  200. Lilv::Node class_para_eq;
  201. Lilv::Node class_phaser;
  202. Lilv::Node class_pitch;
  203. Lilv::Node class_reverb;
  204. Lilv::Node class_simulator;
  205. Lilv::Node class_spatial;
  206. Lilv::Node class_spectral;
  207. Lilv::Node class_utility;
  208. Lilv::Node class_waveshaper;
  209. // Port Types
  210. Lilv::Node port_input;
  211. Lilv::Node port_output;
  212. Lilv::Node port_control;
  213. Lilv::Node port_audio;
  214. Lilv::Node port_cv;
  215. Lilv::Node port_atom;
  216. Lilv::Node port_event;
  217. Lilv::Node port_midi_ll;
  218. // Port Properties
  219. Lilv::Node pprop_optional;
  220. Lilv::Node pprop_enumeration;
  221. Lilv::Node pprop_integer;
  222. Lilv::Node pprop_sample_rate;
  223. Lilv::Node pprop_toggled;
  224. Lilv::Node pprop_artifacts;
  225. Lilv::Node pprop_continuous_cv;
  226. Lilv::Node pprop_discrete_cv;
  227. Lilv::Node pprop_expensive;
  228. Lilv::Node pprop_strict_bounds;
  229. Lilv::Node pprop_logarithmic;
  230. Lilv::Node pprop_not_automatic;
  231. Lilv::Node pprop_not_on_gui;
  232. Lilv::Node pprop_trigger;
  233. // Unit Hints
  234. Lilv::Node unit_unit;
  235. Lilv::Node unit_name;
  236. Lilv::Node unit_render;
  237. Lilv::Node unit_symbol;
  238. // UI Types
  239. Lilv::Node ui_gtk2;
  240. Lilv::Node ui_gtk3;
  241. Lilv::Node ui_qt4;
  242. Lilv::Node ui_cocoa;
  243. Lilv::Node ui_windows;
  244. Lilv::Node ui_x11;
  245. Lilv::Node ui_external;
  246. Lilv::Node ui_external_old;
  247. // Misc
  248. Lilv::Node preset_preset;
  249. Lilv::Node preset_value;
  250. Lilv::Node state_state;
  251. Lilv::Node value_default;
  252. Lilv::Node value_minimum;
  253. Lilv::Node value_maximum;
  254. Lilv::Node atom_sequence;
  255. Lilv::Node atom_buffer_type;
  256. Lilv::Node atom_supports;
  257. // Event Data/Types
  258. Lilv::Node midi_event;
  259. Lilv::Node patch_message;
  260. // MIDI CC
  261. Lilv::Node mm_default_control;
  262. Lilv::Node mm_control_type;
  263. Lilv::Node mm_control_number;
  264. // Other
  265. Lilv::Node dct_replaces;
  266. Lilv::Node doap_license;
  267. Lilv::Node rdf_type;
  268. Lilv::Node rdfs_label;
  269. void init()
  270. {
  271. if (! needInit)
  272. return;
  273. load_all();
  274. needInit = false;
  275. }
  276. private:
  277. bool needInit;
  278. };
  279. static Lv2WorldClass Lv2World;
  280. // ------------------------------------------------------------------------------------------------
  281. // Create new RDF object
  282. static inline
  283. const LV2_RDF_Descriptor* lv2_rdf_new(const LV2_URI URI)
  284. {
  285. Q_ASSERT(URI);
  286. Lv2World.init();
  287. Lilv::Plugins lilvPlugins = Lv2World.get_all_plugins();
  288. LILV_FOREACH(plugins, i, lilvPlugins)
  289. {
  290. Lilv::Plugin lilvPlugin(lilvPlugins.get(i));
  291. if (strcmp(lilvPlugin.get_uri().as_string(), URI) != 0)
  292. continue;
  293. LV2_RDF_Descriptor* const rdf_descriptor = new LV2_RDF_Descriptor;
  294. // --------------------------------------------------
  295. // Set Plugin Type
  296. {
  297. Lilv::Nodes typeNodes(lilvPlugin.get_value(Lv2World.rdf_type));
  298. if (typeNodes.size() > 0)
  299. {
  300. if (typeNodes.contains(Lv2World.class_allpass))
  301. rdf_descriptor->Type |= LV2_CLASS_ALLPASS;
  302. if (typeNodes.contains(Lv2World.class_amplifier))
  303. rdf_descriptor->Type |= LV2_CLASS_AMPLIFIER;
  304. if (typeNodes.contains(Lv2World.class_analyzer))
  305. rdf_descriptor->Type |= LV2_CLASS_ANALYSER;
  306. if (typeNodes.contains(Lv2World.class_bandpass))
  307. rdf_descriptor->Type |= LV2_CLASS_BANDPASS;
  308. if (typeNodes.contains(Lv2World.class_chorus))
  309. rdf_descriptor->Type |= LV2_CLASS_CHORUS;
  310. if (typeNodes.contains(Lv2World.class_comb))
  311. rdf_descriptor->Type |= LV2_CLASS_COMB;
  312. if (typeNodes.contains(Lv2World.class_compressor))
  313. rdf_descriptor->Type |= LV2_CLASS_COMPRESSOR;
  314. if (typeNodes.contains(Lv2World.class_constant))
  315. rdf_descriptor->Type |= LV2_CLASS_CONSTANT;
  316. if (typeNodes.contains(Lv2World.class_converter))
  317. rdf_descriptor->Type |= LV2_CLASS_CONVERTER;
  318. if (typeNodes.contains(Lv2World.class_delay))
  319. rdf_descriptor->Type |= LV2_CLASS_DELAY;
  320. if (typeNodes.contains(Lv2World.class_distortion))
  321. rdf_descriptor->Type |= LV2_CLASS_DISTORTION;
  322. if (typeNodes.contains(Lv2World.class_dynamics))
  323. rdf_descriptor->Type |= LV2_CLASS_DYNAMICS;
  324. if (typeNodes.contains(Lv2World.class_eq))
  325. rdf_descriptor->Type |= LV2_CLASS_EQ;
  326. if (typeNodes.contains(Lv2World.class_expander))
  327. rdf_descriptor->Type |= LV2_CLASS_EXPANDER;
  328. if (typeNodes.contains(Lv2World.class_filter))
  329. rdf_descriptor->Type |= LV2_CLASS_FILTER;
  330. if (typeNodes.contains(Lv2World.class_flanger))
  331. rdf_descriptor->Type |= LV2_CLASS_FLANGER;
  332. if (typeNodes.contains(Lv2World.class_function))
  333. rdf_descriptor->Type |= LV2_CLASS_FUNCTION;
  334. if (typeNodes.contains(Lv2World.class_gate))
  335. rdf_descriptor->Type |= LV2_CLASS_GATE;
  336. if (typeNodes.contains(Lv2World.class_generator))
  337. rdf_descriptor->Type |= LV2_CLASS_GENERATOR;
  338. if (typeNodes.contains(Lv2World.class_highpass))
  339. rdf_descriptor->Type |= LV2_CLASS_HIGHPASS;
  340. if (typeNodes.contains(Lv2World.class_instrument))
  341. rdf_descriptor->Type |= LV2_CLASS_INSTRUMENT;
  342. if (typeNodes.contains(Lv2World.class_limiter))
  343. rdf_descriptor->Type |= LV2_CLASS_LIMITER;
  344. if (typeNodes.contains(Lv2World.class_lowpass))
  345. rdf_descriptor->Type |= LV2_CLASS_LOWPASS;
  346. if (typeNodes.contains(Lv2World.class_mixer))
  347. rdf_descriptor->Type |= LV2_CLASS_MIXER;
  348. if (typeNodes.contains(Lv2World.class_modulator))
  349. rdf_descriptor->Type |= LV2_CLASS_MODULATOR;
  350. if (typeNodes.contains(Lv2World.class_multi_eq))
  351. rdf_descriptor->Type |= LV2_CLASS_MULTI_EQ;
  352. if (typeNodes.contains(Lv2World.class_oscillator))
  353. rdf_descriptor->Type |= LV2_CLASS_OSCILLATOR;
  354. if (typeNodes.contains(Lv2World.class_para_eq))
  355. rdf_descriptor->Type |= LV2_CLASS_PARA_EQ;
  356. if (typeNodes.contains(Lv2World.class_phaser))
  357. rdf_descriptor->Type |= LV2_CLASS_PHASER;
  358. if (typeNodes.contains(Lv2World.class_pitch))
  359. rdf_descriptor->Type |= LV2_CLASS_PITCH;
  360. if (typeNodes.contains(Lv2World.class_reverb))
  361. rdf_descriptor->Type |= LV2_CLASS_REVERB;
  362. if (typeNodes.contains(Lv2World.class_simulator))
  363. rdf_descriptor->Type |= LV2_CLASS_SIMULATOR;
  364. if (typeNodes.contains(Lv2World.class_spatial))
  365. rdf_descriptor->Type |= LV2_CLASS_SPATIAL;
  366. if (typeNodes.contains(Lv2World.class_spectral))
  367. rdf_descriptor->Type |= LV2_CLASS_SPECTRAL;
  368. if (typeNodes.contains(Lv2World.class_utility))
  369. rdf_descriptor->Type |= LV2_CLASS_UTILITY;
  370. if (typeNodes.contains(Lv2World.class_waveshaper))
  371. rdf_descriptor->Type |= LV2_CLASS_WAVESHAPER;
  372. }
  373. }
  374. // --------------------------------------------------
  375. // Set Plugin Information
  376. {
  377. rdf_descriptor->URI = strdup(URI);
  378. rdf_descriptor->Binary = strdup(lilv_uri_to_path(lilvPlugin.get_library_uri().as_string()));
  379. rdf_descriptor->Bundle = strdup(lilv_uri_to_path(lilvPlugin.get_bundle_uri().as_string()));
  380. if (lilvPlugin.get_name())
  381. rdf_descriptor->Name = strdup(lilvPlugin.get_name().as_string());
  382. if (lilvPlugin.get_author_name())
  383. rdf_descriptor->Author = strdup(lilvPlugin.get_author_name().as_string());
  384. Lilv::Nodes licenseNodes(lilvPlugin.get_value(Lv2World.doap_license));
  385. if (licenseNodes.size() > 0)
  386. rdf_descriptor->License = strdup(licenseNodes.get_first().as_string());
  387. }
  388. // --------------------------------------------------
  389. // Set Plugin UniqueID
  390. {
  391. Lilv::Nodes replaceNodes(lilvPlugin.get_value(Lv2World.dct_replaces));
  392. if (replaceNodes.size() > 0)
  393. {
  394. Lilv::Node replaceNode(replaceNodes.get_first());
  395. if (replaceNode.is_uri())
  396. {
  397. const QString replaceURI(replaceNode.as_uri());
  398. if (replaceURI.startsWith("urn:"))
  399. {
  400. const QString replaceId(replaceURI.split(":").last());
  401. bool ok;
  402. long uniqueId = replaceId.toLong(&ok);
  403. if (ok && uniqueId > 0)
  404. rdf_descriptor->UniqueID = uniqueId;
  405. }
  406. }
  407. }
  408. }
  409. // --------------------------------------------------
  410. // Set Plugin Ports
  411. if (lilvPlugin.get_num_ports() > 0)
  412. {
  413. rdf_descriptor->PortCount = lilvPlugin.get_num_ports();
  414. rdf_descriptor->Ports = new LV2_RDF_Port[rdf_descriptor->PortCount];
  415. for (uint32_t j = 0; j < rdf_descriptor->PortCount; j++)
  416. {
  417. Lilv::Port lilvPort(lilvPlugin.get_port_by_index(j));
  418. LV2_RDF_Port* const rdf_port = &rdf_descriptor->Ports[j];
  419. // --------------------------------------
  420. // Set Port Type
  421. {
  422. if (lilvPort.is_a(Lv2World.port_input))
  423. rdf_port->Type |= LV2_PORT_INPUT;
  424. if (lilvPort.is_a(Lv2World.port_output))
  425. rdf_port->Type |= LV2_PORT_OUTPUT;
  426. if (lilvPort.is_a(Lv2World.port_control))
  427. rdf_port->Type |= LV2_PORT_CONTROL;
  428. if (lilvPort.is_a(Lv2World.port_audio))
  429. rdf_port->Type |= LV2_PORT_AUDIO;
  430. if (lilvPort.is_a(Lv2World.port_cv))
  431. rdf_port->Type |= LV2_PORT_CV;
  432. if (lilvPort.is_a(Lv2World.port_atom))
  433. {
  434. rdf_port->Type |= LV2_PORT_ATOM;
  435. Lilv::Nodes bufferTypeNodes(lilvPort.get_value(Lv2World.atom_buffer_type));
  436. if (bufferTypeNodes.contains(Lv2World.atom_sequence))
  437. rdf_port->Type |= LV2_PORT_ATOM_SEQUENCE;
  438. Lilv::Nodes supportNodes(lilvPort.get_value(Lv2World.atom_supports));
  439. if (supportNodes.contains(Lv2World.midi_event))
  440. rdf_port->Type |= LV2_PORT_SUPPORTS_MIDI_EVENT;
  441. if (supportNodes.contains(Lv2World.patch_message))
  442. rdf_port->Type |= LV2_PORT_SUPPORTS_PATCH_MESSAGE;
  443. }
  444. if (lilvPort.is_a(Lv2World.port_event))
  445. {
  446. rdf_port->Type |= LV2_PORT_EVENT;
  447. if (lilvPort.supports_event(Lv2World.midi_event))
  448. rdf_port->Type |= LV2_PORT_SUPPORTS_MIDI_EVENT;
  449. }
  450. if (lilvPort.is_a(Lv2World.port_midi_ll))
  451. {
  452. rdf_port->Type |= LV2_PORT_MIDI_LL;
  453. rdf_port->Type |= LV2_PORT_SUPPORTS_MIDI_EVENT;
  454. }
  455. }
  456. // --------------------------------------
  457. // Set Port Properties
  458. {
  459. if (lilvPort.has_property(Lv2World.pprop_optional))
  460. rdf_port->Properties = LV2_PORT_OPTIONAL;
  461. if (lilvPort.has_property(Lv2World.pprop_enumeration))
  462. rdf_port->Properties = LV2_PORT_ENUMERATION;
  463. if (lilvPort.has_property(Lv2World.pprop_integer))
  464. rdf_port->Properties = LV2_PORT_INTEGER;
  465. if (lilvPort.has_property(Lv2World.pprop_sample_rate))
  466. rdf_port->Properties = LV2_PORT_SAMPLE_RATE;
  467. if (lilvPort.has_property(Lv2World.pprop_toggled))
  468. rdf_port->Properties = LV2_PORT_TOGGLED;
  469. if (lilvPort.has_property(Lv2World.pprop_artifacts))
  470. rdf_port->Properties = LV2_PORT_CAUSES_ARTIFACTS;
  471. if (lilvPort.has_property(Lv2World.pprop_continuous_cv))
  472. rdf_port->Properties = LV2_PORT_CONTINUOUS_CV;
  473. if (lilvPort.has_property(Lv2World.pprop_discrete_cv))
  474. rdf_port->Properties = LV2_PORT_DISCRETE_CV;
  475. if (lilvPort.has_property(Lv2World.pprop_expensive))
  476. rdf_port->Properties = LV2_PORT_EXPENSIVE;
  477. if (lilvPort.has_property(Lv2World.pprop_strict_bounds))
  478. rdf_port->Properties = LV2_PORT_STRICT_BOUNDS;
  479. if (lilvPort.has_property(Lv2World.pprop_logarithmic))
  480. rdf_port->Properties = LV2_PORT_LOGARITHMIC;
  481. if (lilvPort.has_property(Lv2World.pprop_not_automatic))
  482. rdf_port->Properties = LV2_PORT_NOT_AUTOMATIC;
  483. if (lilvPort.has_property(Lv2World.pprop_not_on_gui))
  484. rdf_port->Properties = LV2_PORT_NOT_ON_GUI;
  485. if (lilvPort.has_property(Lv2World.pprop_trigger))
  486. rdf_port->Properties = LV2_PORT_TRIGGER;
  487. if (lilvPort.has_property(Lv2World.reportsLatency))
  488. rdf_port->Designation = LV2_PORT_DESIGNATION_LATENCY;
  489. }
  490. // --------------------------------------
  491. // Set Port Designation
  492. {
  493. Lilv::Nodes designationNodes(lilvPort.get_value(Lv2World.designation));
  494. if (designationNodes.size() > 0)
  495. {
  496. const char* const designation = designationNodes.get_first().as_string();
  497. if (strcmp(designation, LV2_CORE__freeWheeling) == 0)
  498. rdf_port->Designation = LV2_PORT_DESIGNATION_FREEWHEELING;
  499. else if (strcmp(designation, LV2_CORE__latency) == 0)
  500. rdf_port->Designation = LV2_PORT_DESIGNATION_LATENCY;
  501. else if (strcmp(designation, LV2_PARAMETERS__sampleRate) == 0)
  502. rdf_port->Designation = LV2_PORT_DESIGNATION_SAMPLE_RATE;
  503. else if (strcmp(designation, LV2_TIME__bar) == 0)
  504. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BAR;
  505. else if (strcmp(designation, LV2_TIME__barBeat) == 0)
  506. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BAR_BEAT;
  507. else if (strcmp(designation, LV2_TIME__beat) == 0)
  508. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BEAT;
  509. else if (strcmp(designation, LV2_TIME__beatUnit) == 0)
  510. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BEAT_UNIT;
  511. else if (strcmp(designation, LV2_TIME__beatsPerBar) == 0)
  512. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BEATS_PER_BAR;
  513. else if (strcmp(designation, LV2_TIME__beatsPerMinute) == 0)
  514. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BEATS_PER_MINUTE;
  515. else if (strcmp(designation, LV2_TIME__frame) == 0)
  516. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_FRAME;
  517. else if (strcmp(designation, LV2_TIME__framesPerSecond) == 0)
  518. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_FRAMES_PER_SECOND;
  519. else if (strcmp(designation, LV2_TIME__position) == 0)
  520. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_POSITION;
  521. else if (strcmp(designation, LV2_TIME__speed) == 0)
  522. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_SPEED;
  523. else if (strncmp(designation, LV2_PARAMETERS_PREFIX, strlen(LV2_PARAMETERS_PREFIX)) == 0)
  524. pass();
  525. else if (strncmp(designation, LV2_PORT_GROUPS_PREFIX, strlen(LV2_PORT_GROUPS_PREFIX)) == 0)
  526. pass();
  527. else
  528. qWarning("lv2_rdf_new(\"%s\") - got unknown Port Designation '%s'", URI, designation);
  529. }
  530. }
  531. // --------------------------------------
  532. // Set Port Information
  533. {
  534. rdf_port->Name = strdup(Lilv::Node(lilvPort.get_name()).as_string());
  535. rdf_port->Symbol = strdup(Lilv::Node(lilvPort.get_symbol()).as_string());
  536. }
  537. // --------------------------------------
  538. // Set Port MIDI Map
  539. {
  540. Lilv::Nodes midiMapNodes(lilvPort.get_value(Lv2World.mm_default_control));
  541. if (midiMapNodes.size() > 0)
  542. {
  543. Lilv::Node midiMapNode(midiMapNodes.get_first());
  544. if (midiMapNode.is_blank())
  545. {
  546. Lilv::Nodes midiMapTypeNodes(Lv2World.find_nodes(midiMapNode, Lv2World.mm_control_type, nullptr));
  547. Lilv::Nodes midiMapNumberNodes(Lv2World.find_nodes(midiMapNode, Lv2World.mm_control_number, nullptr));
  548. if (midiMapTypeNodes.size() == 1 && midiMapNumberNodes.size() == 1)
  549. {
  550. const char* const midiMapType = midiMapTypeNodes.get_first().as_string();
  551. if (strcmp(midiMapType, LV2_MIDI_Map__CC) == 0)
  552. rdf_port->MidiMap.Type = LV2_PORT_MIDI_MAP_CC;
  553. else if (strcmp(midiMapType, LV2_MIDI_Map__NRPN) == 0)
  554. rdf_port->MidiMap.Type = LV2_PORT_MIDI_MAP_NRPN;
  555. else
  556. qWarning("lv2_rdf_new(\"%s\") - got unknown Port Midi Map type '%s'", URI, midiMapType);
  557. rdf_port->MidiMap.Number = midiMapNumberNodes.get_first().as_int();
  558. }
  559. }
  560. }
  561. }
  562. // --------------------------------------
  563. // Set Port Points
  564. {
  565. Lilv::Nodes valueNodes(lilvPort.get_value(Lv2World.value_default));
  566. if (valueNodes.size() > 0)
  567. {
  568. rdf_port->Points.Hints |= LV2_PORT_POINT_DEFAULT;
  569. rdf_port->Points.Default = valueNodes.get_first().as_float();
  570. }
  571. valueNodes = lilvPort.get_value(Lv2World.value_minimum);
  572. if (valueNodes.size() > 0)
  573. {
  574. rdf_port->Points.Hints |= LV2_PORT_POINT_MINIMUM;
  575. rdf_port->Points.Minimum = valueNodes.get_first().as_float();
  576. }
  577. valueNodes = lilvPort.get_value(Lv2World.value_maximum);
  578. if (valueNodes.size() > 0)
  579. {
  580. rdf_port->Points.Hints |= LV2_PORT_POINT_MAXIMUM;
  581. rdf_port->Points.Maximum = valueNodes.get_first().as_float();
  582. }
  583. }
  584. // --------------------------------------
  585. // Set Port Unit
  586. {
  587. Lilv::Nodes unitTypeNodes(lilvPort.get_value(Lv2World.unit_unit));
  588. if (unitTypeNodes.size() > 0)
  589. {
  590. rdf_port->Unit.Hints |= LV2_PORT_UNIT;
  591. const char* const unitType = unitTypeNodes.get_first().as_uri();
  592. if (strcmp(unitType, LV2_UNITS__bar) == 0)
  593. rdf_port->Unit.Type = LV2_UNIT_BAR;
  594. else if (strcmp(unitType, LV2_UNITS__beat) == 0)
  595. rdf_port->Unit.Type = LV2_UNIT_BEAT;
  596. else if (strcmp(unitType, LV2_UNITS__bpm) == 0)
  597. rdf_port->Unit.Type = LV2_UNIT_BPM;
  598. else if (strcmp(unitType, LV2_UNITS__cent) == 0)
  599. rdf_port->Unit.Type = LV2_UNIT_CENT;
  600. else if (strcmp(unitType, LV2_UNITS__cm) == 0)
  601. rdf_port->Unit.Type = LV2_UNIT_CM;
  602. else if (strcmp(unitType, LV2_UNITS__coef) == 0)
  603. rdf_port->Unit.Type = LV2_UNIT_COEF;
  604. else if (strcmp(unitType, LV2_UNITS__db) == 0)
  605. rdf_port->Unit.Type = LV2_UNIT_DB;
  606. else if (strcmp(unitType, LV2_UNITS__degree) == 0)
  607. rdf_port->Unit.Type = LV2_UNIT_DEGREE;
  608. else if (strcmp(unitType, LV2_UNITS__frame) == 0)
  609. rdf_port->Unit.Type = LV2_UNIT_FRAME;
  610. else if (strcmp(unitType, LV2_UNITS__hz) == 0)
  611. rdf_port->Unit.Type = LV2_UNIT_HZ;
  612. else if (strcmp(unitType, LV2_UNITS__inch) == 0)
  613. rdf_port->Unit.Type = LV2_UNIT_INCH;
  614. else if (strcmp(unitType, LV2_UNITS__khz) == 0)
  615. rdf_port->Unit.Type = LV2_UNIT_KHZ;
  616. else if (strcmp(unitType, LV2_UNITS__km) == 0)
  617. rdf_port->Unit.Type = LV2_UNIT_KM;
  618. else if (strcmp(unitType, LV2_UNITS__m) == 0)
  619. rdf_port->Unit.Type = LV2_UNIT_M;
  620. else if (strcmp(unitType, LV2_UNITS__mhz) == 0)
  621. rdf_port->Unit.Type = LV2_UNIT_MHZ;
  622. else if (strcmp(unitType, LV2_UNITS__midiNote) == 0)
  623. rdf_port->Unit.Type = LV2_UNIT_MIDINOTE;
  624. else if (strcmp(unitType, LV2_UNITS__mile) == 0)
  625. rdf_port->Unit.Type = LV2_UNIT_MILE;
  626. else if (strcmp(unitType, LV2_UNITS__min) == 0)
  627. rdf_port->Unit.Type = LV2_UNIT_MIN;
  628. else if (strcmp(unitType, LV2_UNITS__mm) == 0)
  629. rdf_port->Unit.Type = LV2_UNIT_MM;
  630. else if (strcmp(unitType, LV2_UNITS__ms) == 0)
  631. rdf_port->Unit.Type = LV2_UNIT_MS;
  632. else if (strcmp(unitType, LV2_UNITS__oct) == 0)
  633. rdf_port->Unit.Type = LV2_UNIT_OCT;
  634. else if (strcmp(unitType, LV2_UNITS__pc) == 0)
  635. rdf_port->Unit.Type = LV2_UNIT_PC;
  636. else if (strcmp(unitType, LV2_UNITS__s) == 0)
  637. rdf_port->Unit.Type = LV2_UNIT_S;
  638. else if (strcmp(unitType, LV2_UNITS__semitone12TET) == 0)
  639. rdf_port->Unit.Type = LV2_UNIT_SEMITONE;
  640. else
  641. qWarning("lv2_rdf_new(\"%s\") - got unknown Unit type '%s'", URI, unitType);
  642. }
  643. Lilv::Nodes unitNameNodes(lilvPort.get_value(Lv2World.unit_name));
  644. if (unitNameNodes.size() > 0)
  645. {
  646. rdf_port->Unit.Hints |= LV2_PORT_UNIT_NAME;
  647. rdf_port->Unit.Name = strdup(unitNameNodes.get_first().as_string());
  648. }
  649. Lilv::Nodes unitRenderNodes(lilvPort.get_value(Lv2World.unit_render));
  650. if (unitRenderNodes.size() > 0)
  651. {
  652. rdf_port->Unit.Hints |= LV2_PORT_UNIT_RENDER;
  653. rdf_port->Unit.Render = strdup(unitRenderNodes.get_first().as_string());
  654. }
  655. Lilv::Nodes unitSymbolNodes(lilvPort.get_value(Lv2World.unit_symbol));
  656. if (unitSymbolNodes.size() > 0)
  657. {
  658. rdf_port->Unit.Hints |= LV2_PORT_UNIT_SYMBOL;
  659. rdf_port->Unit.Symbol = strdup(unitSymbolNodes.get_first().as_string());
  660. }
  661. }
  662. // --------------------------------------
  663. // Set Port Scale Points
  664. Lilv::ScalePoints lilvScalePoints(lilvPort.get_scale_points());
  665. if (lilvScalePoints.size() > 0)
  666. {
  667. rdf_port->ScalePointCount = lilvScalePoints.size();
  668. rdf_port->ScalePoints = new LV2_RDF_PortScalePoint[rdf_port->ScalePointCount];
  669. uint32_t h = 0;
  670. LILV_FOREACH(scale_points, j, lilvScalePoints)
  671. {
  672. Lilv::ScalePoint lilvScalePoint(lilvScalePoints.get(j));
  673. LV2_RDF_PortScalePoint* const rdf_scalePoint = &rdf_port->ScalePoints[h++];
  674. rdf_scalePoint->Label = strdup(Lilv::Node(lilvScalePoint.get_label()).as_string());
  675. rdf_scalePoint->Value = Lilv::Node(lilvScalePoint.get_value()).as_float();
  676. }
  677. }
  678. }
  679. }
  680. #if 0
  681. // --------------------------------------------------
  682. // Set Plugin Presets (TODO)
  683. {
  684. Lilv::Nodes presetNodes(lilvPlugin.get_related(Lv2World.preset_preset));
  685. if (presetNodes.size() > 0)
  686. {
  687. // create a list of preset URIs (for checking appliesTo, sorting and uniqueness)
  688. QStringList presetListURIs;
  689. LILV_FOREACH(nodes, j, presetNodes)
  690. {
  691. Lilv::Node presetNode(presetNodes.get(j));
  692. // FIXME - check appliesTo
  693. QString presetURI(presetNode.as_uri());
  694. if (! presetListURIs.contains(presetURI))
  695. presetListURIs.append(presetURI);
  696. }
  697. presetListURIs.sort();
  698. // create presets with unique URIs
  699. rdf_descriptor->PresetCount = presetListURIs.count();
  700. rdf_descriptor->Presets = new LV2_RDF_Preset[rdf_descriptor->PresetCount];
  701. // set preset data
  702. LILV_FOREACH(nodes, j, presetNodes)
  703. {
  704. Lilv::Node presetNode(presetNodes.get(j));
  705. Lv2World.load_resource(presetNode);
  706. LV2_URI presetURI = presetNode.as_uri();
  707. int32_t index = presetListURIs.indexOf(QString(presetURI));
  708. if (index < 0)
  709. continue;
  710. LV2_RDF_Preset* const rdf_preset = &rdf_descriptor->Presets[index];
  711. // --------------------------------------
  712. // Set Preset Information
  713. {
  714. rdf_preset->URI = strdup(presetURI);
  715. Lilv::Nodes presetLabelNodes(Lv2World.find_nodes(presetNode, Lv2World.rdfs_label, nullptr));
  716. if (presetLabelNodes.size() > 0)
  717. rdf_preset->Label = strdup(presetLabelNodes.get_first().as_string());
  718. }
  719. // --------------------------------------
  720. // Set Preset Ports
  721. {
  722. Lilv::Nodes presetPortNodes(Lv2World.find_nodes(presetNode, Lv2World.port, nullptr));
  723. if (presetPortNodes.size() > 0)
  724. {
  725. rdf_preset->PortCount = presetPortNodes.size();
  726. rdf_preset->Ports = new LV2_RDF_PresetPort[rdf_preset->PortCount];
  727. uint32_t h = 0;
  728. LILV_FOREACH(nodes, k, presetPortNodes)
  729. {
  730. Lilv::Node presetPortNode(presetPortNodes.get(k));
  731. Lilv::Nodes presetPortSymbolNodes(Lv2World.find_nodes(presetPortNode, Lv2World.symbol, nullptr));
  732. Lilv::Nodes presetPortValueNodes(Lv2World.find_nodes(presetPortNode, Lv2World.preset_value, nullptr));
  733. if (presetPortSymbolNodes.size() == 1 && presetPortValueNodes.size() == 1)
  734. {
  735. LV2_RDF_PresetPort* const rdf_presetPort = &rdf_preset->Ports[h++];
  736. rdf_presetPort->Symbol = strdup(presetPortSymbolNodes.get_first().as_string());
  737. rdf_presetPort->Value = presetPortValueNodes.get_first().as_float();
  738. }
  739. }
  740. }
  741. }
  742. // --------------------------------------
  743. // Set Preset States
  744. {
  745. Lilv::Nodes presetStateNodes(Lv2World.find_nodes(presetNode, Lv2World.state_state, nullptr));
  746. if (presetStateNodes.size() > 0)
  747. {
  748. rdf_preset->StateCount = presetStateNodes.size();
  749. rdf_preset->States = new LV2_RDF_PresetState[rdf_preset->StateCount];
  750. uint32_t h = 0;
  751. LILV_FOREACH(nodes, k, presetStateNodes)
  752. {
  753. Lilv::Node presetStateNode(presetStateNodes.get(k));
  754. if (presetStateNode.is_blank())
  755. {
  756. // TODO
  757. LV2_RDF_PresetState* const rdf_presetState = &rdf_preset->States[h++];
  758. rdf_presetState->Type = LV2_PRESET_STATE_NULL;
  759. rdf_presetState->Key = nullptr;
  760. }
  761. }
  762. }
  763. }
  764. }
  765. }
  766. }
  767. #endif
  768. // --------------------------------------------------
  769. // Set Plugin Features
  770. {
  771. Lilv::Nodes lilvFeatureNodes(lilvPlugin.get_supported_features());
  772. if (lilvFeatureNodes.size() > 0)
  773. {
  774. Lilv::Nodes lilvFeatureNodesR(lilvPlugin.get_required_features());
  775. rdf_descriptor->FeatureCount = lilvFeatureNodes.size();
  776. rdf_descriptor->Features = new LV2_RDF_Feature[rdf_descriptor->FeatureCount];
  777. uint32_t h = 0;
  778. LILV_FOREACH(nodes, j, lilvFeatureNodes)
  779. {
  780. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(j));
  781. LV2_RDF_Feature* const rdf_feature = &rdf_descriptor->Features[h++];
  782. rdf_feature->Type = lilvFeatureNodesR.contains(lilvFeatureNode) ? LV2_FEATURE_REQUIRED : LV2_FEATURE_OPTIONAL;
  783. rdf_feature->URI = strdup(lilvFeatureNode.as_uri());
  784. }
  785. }
  786. }
  787. // --------------------------------------------------
  788. // Set Plugin Extensions
  789. {
  790. Lilv::Nodes lilvExtensionDataNodes(lilvPlugin.get_extension_data());
  791. if (lilvExtensionDataNodes.size() > 0)
  792. {
  793. rdf_descriptor->ExtensionCount = lilvExtensionDataNodes.size();
  794. rdf_descriptor->Extensions = new LV2_URI[rdf_descriptor->ExtensionCount];
  795. uint32_t h = 0;
  796. LILV_FOREACH(nodes, j, lilvExtensionDataNodes)
  797. {
  798. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(j));
  799. LV2_URI* const rdf_extension = &rdf_descriptor->Extensions[h++];
  800. *rdf_extension = strdup(lilvExtensionDataNode.as_uri());
  801. }
  802. }
  803. }
  804. // --------------------------------------------------
  805. // Set Plugin UIs
  806. {
  807. Lilv::UIs lilvUIs(lilvPlugin.get_uis());
  808. if (lilvUIs.size() > 0)
  809. {
  810. rdf_descriptor->UICount = lilvUIs.size();
  811. rdf_descriptor->UIs = new LV2_RDF_UI[rdf_descriptor->UICount];
  812. uint32_t h = 0;
  813. LILV_FOREACH(uis, j, lilvUIs)
  814. {
  815. Lilv::UI lilvUI(lilvUIs.get(j));
  816. LV2_RDF_UI* const rdf_ui = &rdf_descriptor->UIs[h++];
  817. // --------------------------------------
  818. // Set UI Type
  819. {
  820. if (lilvUI.is_a(Lv2World.ui_gtk2))
  821. rdf_ui->Type = LV2_UI_GTK2;
  822. else if (lilvUI.is_a(Lv2World.ui_gtk3))
  823. rdf_ui->Type = LV2_UI_GTK3;
  824. else if (lilvUI.is_a(Lv2World.ui_qt4))
  825. rdf_ui->Type = LV2_UI_QT4;
  826. else if (lilvUI.is_a(Lv2World.ui_cocoa))
  827. rdf_ui->Type = LV2_UI_COCOA;
  828. else if (lilvUI.is_a(Lv2World.ui_windows))
  829. rdf_ui->Type = LV2_UI_WINDOWS;
  830. else if (lilvUI.is_a(Lv2World.ui_x11))
  831. rdf_ui->Type = LV2_UI_X11;
  832. else if (lilvUI.is_a(Lv2World.ui_external))
  833. rdf_ui->Type = LV2_UI_EXTERNAL;
  834. else if (lilvUI.is_a(Lv2World.ui_external_old))
  835. rdf_ui->Type = LV2_UI_OLD_EXTERNAL;
  836. else
  837. qWarning("lv2_rdf_new(\"%s\") - got unknown UI type '%s'", URI, lilvUI.get_uri().as_uri());
  838. }
  839. // --------------------------------------
  840. // Set UI Information
  841. {
  842. rdf_ui->URI = strdup(lilvUI.get_uri().as_uri());
  843. rdf_ui->Binary = strdup(lilv_uri_to_path(lilvUI.get_binary_uri().as_string()));
  844. rdf_ui->Bundle = strdup(lilv_uri_to_path(lilvUI.get_bundle_uri().as_string()));
  845. }
  846. // --------------------------------------
  847. // Set UI Features
  848. {
  849. Lilv::Nodes lilvFeatureNodes(lilvUI.get_supported_features());
  850. if (lilvFeatureNodes.size() > 0)
  851. {
  852. Lilv::Nodes lilvFeatureNodesR(lilvUI.get_required_features());
  853. rdf_ui->FeatureCount = lilvFeatureNodes.size();
  854. rdf_ui->Features = new LV2_RDF_Feature[rdf_ui->FeatureCount];
  855. uint32_t x = 0;
  856. LILV_FOREACH(nodes, k, lilvFeatureNodes)
  857. {
  858. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(k));
  859. LV2_RDF_Feature* const rdf_feature = &rdf_ui->Features[x++];
  860. rdf_feature->Type = lilvFeatureNodesR.contains(lilvFeatureNode) ? LV2_FEATURE_REQUIRED : LV2_FEATURE_OPTIONAL;
  861. rdf_feature->URI = strdup(lilvFeatureNode.as_uri());
  862. }
  863. }
  864. }
  865. // --------------------------------------
  866. // Set UI Extensions
  867. {
  868. Lilv::Nodes lilvExtensionDataNodes(lilvUI.get_extension_data());
  869. if (lilvExtensionDataNodes.size() > 0)
  870. {
  871. rdf_ui->ExtensionCount = lilvExtensionDataNodes.size();
  872. rdf_ui->Extensions = new LV2_URI[rdf_ui->ExtensionCount];
  873. uint32_t x = 0;
  874. LILV_FOREACH(nodes, k, lilvExtensionDataNodes)
  875. {
  876. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(k));
  877. LV2_URI* const rdf_extension = &rdf_ui->Extensions[x++];
  878. *rdf_extension = strdup(lilvExtensionDataNode.as_uri());
  879. }
  880. }
  881. }
  882. }
  883. }
  884. }
  885. return rdf_descriptor;
  886. }
  887. return nullptr;
  888. }
  889. // Copy RDF object
  890. static inline
  891. const LV2_RDF_Descriptor* lv2_rdf_dup(const LV2_RDF_Descriptor* const rdf_descriptor)
  892. {
  893. Q_ASSERT(rdf_descriptor);
  894. LV2_RDF_Descriptor* const new_descriptor = new LV2_RDF_Descriptor;
  895. new_descriptor->Type = rdf_descriptor->Type;
  896. new_descriptor->UniqueID = rdf_descriptor->UniqueID;
  897. new_descriptor->PortCount = rdf_descriptor->PortCount;
  898. new_descriptor->PresetCount = rdf_descriptor->PresetCount;
  899. new_descriptor->FeatureCount = rdf_descriptor->FeatureCount;
  900. new_descriptor->ExtensionCount = rdf_descriptor->ExtensionCount;
  901. new_descriptor->UICount = rdf_descriptor->UICount;
  902. if (rdf_descriptor->URI)
  903. new_descriptor->URI = strdup(rdf_descriptor->URI);
  904. if (rdf_descriptor->Name)
  905. new_descriptor->Name = strdup(rdf_descriptor->Name);
  906. if (rdf_descriptor->Author)
  907. new_descriptor->Author = strdup(rdf_descriptor->Author);
  908. if (rdf_descriptor->License)
  909. new_descriptor->License = strdup(rdf_descriptor->License);
  910. if (rdf_descriptor->Binary)
  911. new_descriptor->Binary = strdup(rdf_descriptor->Binary);
  912. if (rdf_descriptor->Bundle)
  913. new_descriptor->Bundle = strdup(rdf_descriptor->Bundle);
  914. // Ports
  915. if (new_descriptor->PortCount > 0)
  916. {
  917. new_descriptor->Ports = new LV2_RDF_Port[new_descriptor->PortCount];
  918. for (uint32_t i=0; i < new_descriptor->PortCount; i++)
  919. {
  920. LV2_RDF_Port* const Port = &new_descriptor->Ports[i];
  921. Port->Type = rdf_descriptor->Ports[i].Type;
  922. Port->Properties = rdf_descriptor->Ports[i].Properties;
  923. Port->Designation = rdf_descriptor->Ports[i].Designation;
  924. Port->MidiMap.Type = rdf_descriptor->Ports[i].MidiMap.Type;
  925. Port->MidiMap.Number = rdf_descriptor->Ports[i].MidiMap.Number;
  926. Port->Points.Hints = rdf_descriptor->Ports[i].Points.Hints;
  927. Port->Points.Default = rdf_descriptor->Ports[i].Points.Default;
  928. Port->Points.Minimum = rdf_descriptor->Ports[i].Points.Minimum;
  929. Port->Points.Maximum = rdf_descriptor->Ports[i].Points.Maximum;
  930. Port->Unit.Type = rdf_descriptor->Ports[i].Unit.Type;
  931. Port->Unit.Hints = rdf_descriptor->Ports[i].Unit.Hints;
  932. Port->ScalePointCount = rdf_descriptor->Ports[i].ScalePointCount;
  933. if (rdf_descriptor->Ports[i].Name)
  934. Port->Name = strdup(rdf_descriptor->Ports[i].Name);
  935. if (rdf_descriptor->Ports[i].Symbol)
  936. Port->Symbol = strdup(rdf_descriptor->Ports[i].Symbol);
  937. if (rdf_descriptor->Ports[i].Unit.Name)
  938. Port->Unit.Name = strdup(rdf_descriptor->Ports[i].Unit.Name);
  939. if (rdf_descriptor->Ports[i].Unit.Render)
  940. Port->Unit.Render = strdup(rdf_descriptor->Ports[i].Unit.Render);
  941. if (rdf_descriptor->Ports[i].Unit.Symbol)
  942. Port->Unit.Symbol = strdup(rdf_descriptor->Ports[i].Unit.Symbol);
  943. if (Port->ScalePointCount > 0)
  944. {
  945. Port->ScalePoints = new LV2_RDF_PortScalePoint[Port->ScalePointCount];
  946. for (uint32_t j=0; j < Port->ScalePointCount; j++)
  947. {
  948. Port->ScalePoints[j].Value = rdf_descriptor->Ports[i].ScalePoints[j].Value;
  949. if (rdf_descriptor->Ports[i].ScalePoints[j].Label)
  950. Port->ScalePoints[j].Label = strdup(rdf_descriptor->Ports[i].ScalePoints[j].Label);
  951. }
  952. }
  953. }
  954. }
  955. #if 0
  956. // Presets
  957. if (new_descriptor->PresetCount > 0)
  958. {
  959. new_descriptor->Presets = new LV2_RDF_Preset[new_descriptor->PresetCount];
  960. for (uint32_t i=0; i < new_descriptor->PresetCount; i++)
  961. {
  962. LV2_RDF_Preset* const Preset = &new_descriptor->Presets[i];
  963. Preset->PortCount = rdf_descriptor->Presets[i].PortCount;
  964. Preset->StateCount = rdf_descriptor->Presets[i].StateCount;
  965. if (rdf_descriptor->Presets[i].URI)
  966. Preset->URI = strdup(rdf_descriptor->Presets[i].URI);
  967. if (rdf_descriptor->Presets[i].Label)
  968. Preset->Label = strdup(rdf_descriptor->Presets[i].Label);
  969. // Ports
  970. if (Preset->PortCount > 0)
  971. {
  972. Preset->Ports = new LV2_RDF_PresetPort[Preset->PortCount];
  973. for (uint32_t j=0; j < Preset->PortCount; j++)
  974. {
  975. Preset->Ports[j].Value = rdf_descriptor->Presets[i].Ports[j].Value;
  976. if (rdf_descriptor->Presets[i].Ports[j].Symbol)
  977. Preset->Ports[j].Symbol = strdup(rdf_descriptor->Presets[i].Ports[j].Symbol);
  978. }
  979. }
  980. // States
  981. if (Preset->StateCount > 0)
  982. {
  983. Preset->States = new LV2_RDF_PresetState[Preset->StateCount];
  984. for (uint32_t j=0; j < Preset->StateCount; j++)
  985. {
  986. Preset->States[j].Type = rdf_descriptor->Presets[i].States[j].Type;
  987. if (rdf_descriptor->Presets[i].States[j].Key)
  988. Preset->States[j].Key = strdup(rdf_descriptor->Presets[i].States[j].Key);
  989. // TODO - copy value
  990. }
  991. }
  992. }
  993. }
  994. #endif
  995. // Features
  996. if (new_descriptor->FeatureCount > 0)
  997. {
  998. new_descriptor->Features = new LV2_RDF_Feature[new_descriptor->FeatureCount];
  999. for (uint32_t i=0; i < new_descriptor->FeatureCount; i++)
  1000. {
  1001. new_descriptor->Features[i].Type = rdf_descriptor->Features[i].Type;
  1002. if (rdf_descriptor->Features[i].URI)
  1003. new_descriptor->Features[i].URI = strdup(rdf_descriptor->Features[i].URI);
  1004. }
  1005. }
  1006. // Extensions
  1007. if (new_descriptor->ExtensionCount > 0)
  1008. {
  1009. new_descriptor->Extensions = new LV2_URI[new_descriptor->ExtensionCount];
  1010. for (uint32_t i=0; i < new_descriptor->ExtensionCount; i++)
  1011. {
  1012. if (rdf_descriptor->Extensions[i])
  1013. new_descriptor->Extensions[i] = strdup(rdf_descriptor->Extensions[i]);
  1014. }
  1015. }
  1016. // UIs
  1017. if (new_descriptor->UICount > 0)
  1018. {
  1019. new_descriptor->UIs = new LV2_RDF_UI[new_descriptor->UICount];
  1020. for (uint32_t i=0; i < new_descriptor->UICount; i++)
  1021. {
  1022. LV2_RDF_UI* const UI = &new_descriptor->UIs[i];
  1023. UI->Type = rdf_descriptor->UIs[i].Type;
  1024. UI->FeatureCount = rdf_descriptor->UIs[i].FeatureCount;
  1025. UI->ExtensionCount = rdf_descriptor->UIs[i].ExtensionCount;
  1026. if (rdf_descriptor->UIs[i].URI)
  1027. UI->URI = strdup(rdf_descriptor->UIs[i].URI);
  1028. if (rdf_descriptor->UIs[i].Binary)
  1029. UI->Binary = strdup(rdf_descriptor->UIs[i].Binary);
  1030. if (rdf_descriptor->UIs[i].Bundle)
  1031. UI->Bundle = strdup(rdf_descriptor->UIs[i].Bundle);
  1032. // UI Features
  1033. if (UI->FeatureCount > 0)
  1034. {
  1035. UI->Features = new LV2_RDF_Feature[UI->FeatureCount];
  1036. for (uint32_t j=0; j < UI->FeatureCount; j++)
  1037. {
  1038. UI->Features[j].Type = rdf_descriptor->UIs[i].Features[j].Type;
  1039. if (rdf_descriptor->UIs[i].Features[j].URI)
  1040. UI->Features[j].URI = strdup(rdf_descriptor->UIs[i].Features[j].URI);
  1041. }
  1042. }
  1043. // UI Extensions
  1044. if (UI->ExtensionCount > 0)
  1045. {
  1046. UI->Extensions = new LV2_URI[UI->ExtensionCount];
  1047. for (uint32_t j=0; j < UI->ExtensionCount; j++)
  1048. {
  1049. if (rdf_descriptor->UIs[i].Extensions[j])
  1050. UI->Extensions[j] = strdup(rdf_descriptor->UIs[i].Extensions[j]);
  1051. }
  1052. }
  1053. }
  1054. }
  1055. return new_descriptor;
  1056. }
  1057. // Delete object
  1058. static inline
  1059. void lv2_rdf_free(const LV2_RDF_Descriptor* const rdf_descriptor)
  1060. {
  1061. if (rdf_descriptor->URI)
  1062. free((void*)rdf_descriptor->URI);
  1063. if (rdf_descriptor->Name)
  1064. free((void*)rdf_descriptor->Name);
  1065. if (rdf_descriptor->Author)
  1066. free((void*)rdf_descriptor->Author);
  1067. if (rdf_descriptor->License)
  1068. free((void*)rdf_descriptor->License);
  1069. if (rdf_descriptor->Binary)
  1070. free((void*)rdf_descriptor->Binary);
  1071. if (rdf_descriptor->Bundle)
  1072. free((void*)rdf_descriptor->Bundle);
  1073. if (rdf_descriptor->PortCount > 0)
  1074. {
  1075. for (uint32_t i=0; i < rdf_descriptor->PortCount; i++)
  1076. {
  1077. const LV2_RDF_Port* const Port = &rdf_descriptor->Ports[i];
  1078. if (Port->Name)
  1079. free((void*)Port->Name);
  1080. if (Port->Symbol)
  1081. free((void*)Port->Symbol);
  1082. if (Port->Unit.Name)
  1083. free((void*)Port->Unit.Name);
  1084. if (Port->Unit.Render)
  1085. free((void*)Port->Unit.Render);
  1086. if (Port->Unit.Symbol)
  1087. free((void*)Port->Unit.Symbol);
  1088. if (Port->ScalePointCount > 0)
  1089. {
  1090. for (uint32_t j=0; j < Port->ScalePointCount; j++)
  1091. {
  1092. const LV2_RDF_PortScalePoint* const PortScalePoint = &Port->ScalePoints[j];
  1093. if (PortScalePoint->Label)
  1094. free((void*)PortScalePoint->Label);
  1095. }
  1096. delete[] Port->ScalePoints;
  1097. }
  1098. }
  1099. delete[] rdf_descriptor->Ports;
  1100. }
  1101. #if 0
  1102. if (rdf_descriptor->PresetCount > 0)
  1103. {
  1104. for (uint32_t i=0; i < rdf_descriptor->PresetCount; i++)
  1105. {
  1106. const LV2_RDF_Preset* const Preset = &rdf_descriptor->Presets[i];
  1107. if (Preset->URI)
  1108. free((void*)Preset->URI);
  1109. if (Preset->Label)
  1110. free((void*)Preset->Label);
  1111. if (Preset->PortCount > 0)
  1112. {
  1113. for (uint32_t j=0; j < Preset->PortCount; j++)
  1114. {
  1115. const LV2_RDF_PresetPort* const PresetPort = &Preset->Ports[j];
  1116. if (PresetPort->Symbol)
  1117. free((void*)PresetPort->Symbol);
  1118. }
  1119. delete[] Preset->Ports;
  1120. }
  1121. if (Preset->StateCount > 0)
  1122. {
  1123. for (uint32_t j=0; j < Preset->StateCount; j++)
  1124. {
  1125. const LV2_RDF_PresetState* const PresetState = &Preset->States[j];
  1126. if (PresetState->Key)
  1127. free((void*)PresetState->Key);
  1128. // TODO - delete value
  1129. }
  1130. delete[] Preset->States;
  1131. }
  1132. }
  1133. delete[] rdf_descriptor->Presets;
  1134. }
  1135. #endif
  1136. if (rdf_descriptor->FeatureCount > 0)
  1137. {
  1138. for (uint32_t i=0; i < rdf_descriptor->FeatureCount; i++)
  1139. {
  1140. const LV2_RDF_Feature* const Feature = &rdf_descriptor->Features[i];
  1141. if (Feature->URI)
  1142. free((void*)Feature->URI);
  1143. }
  1144. delete[] rdf_descriptor->Features;
  1145. }
  1146. if (rdf_descriptor->ExtensionCount > 0)
  1147. {
  1148. for (uint32_t i=0; i < rdf_descriptor->ExtensionCount; i++)
  1149. {
  1150. const LV2_URI Extension = rdf_descriptor->Extensions[i];
  1151. if (Extension)
  1152. free((void*)Extension);
  1153. }
  1154. delete[] rdf_descriptor->Extensions;
  1155. }
  1156. if (rdf_descriptor->UICount > 0)
  1157. {
  1158. for (uint32_t i=0; i < rdf_descriptor->UICount; i++)
  1159. {
  1160. const LV2_RDF_UI* const UI = &rdf_descriptor->UIs[i];
  1161. if (UI->URI)
  1162. free((void*)UI->URI);
  1163. if (UI->Binary)
  1164. free((void*)UI->Binary);
  1165. if (UI->Bundle)
  1166. free((void*)UI->Bundle);
  1167. if (UI->FeatureCount > 0)
  1168. {
  1169. for (uint32_t j=0; j < UI->FeatureCount; j++)
  1170. {
  1171. const LV2_RDF_Feature* const Feature = &UI->Features[j];
  1172. if (Feature->URI)
  1173. free((void*)Feature->URI);
  1174. }
  1175. delete[] UI->Features;
  1176. }
  1177. if (UI->ExtensionCount > 0)
  1178. {
  1179. for (uint32_t j=0; j < UI->ExtensionCount; j++)
  1180. {
  1181. const LV2_URI Extension = UI->Extensions[j];
  1182. if (Extension)
  1183. free((void*)Extension);
  1184. }
  1185. delete[] UI->Extensions;
  1186. }
  1187. }
  1188. delete[] rdf_descriptor->UIs;
  1189. }
  1190. delete rdf_descriptor;
  1191. }
  1192. // ------------------------------------------------------------------------------------------------
  1193. static inline
  1194. bool is_lv2_feature_supported(const LV2_URI uri)
  1195. {
  1196. if (strcmp(uri, LV2_CORE__hardRTCapable) == 0)
  1197. return true;
  1198. if (strcmp(uri, LV2_CORE__inPlaceBroken) == 0)
  1199. return true;
  1200. if (strcmp(uri, LV2_CORE__isLive) == 0)
  1201. return true;
  1202. if (strcmp(uri, LV2_EVENT_URI) == 0)
  1203. return true;
  1204. if (strcmp(uri, LV2_LOG__log) == 0)
  1205. return true;
  1206. if (strcmp(uri, LV2_OPTIONS__options) == 0)
  1207. return true;
  1208. if (strcmp(uri, LV2_PROGRAMS__Host) == 0)
  1209. return true;
  1210. if (strcmp(uri, LV2_STATE__makePath) == 0)
  1211. return true;
  1212. if (strcmp(uri, LV2_STATE__mapPath) == 0)
  1213. return true;
  1214. if (strcmp(uri, LV2_PORT_PROPS__supportsStrictBounds) == 0)
  1215. return true;
  1216. if (strcmp(uri, LV2_URI_MAP_URI) == 0)
  1217. return true;
  1218. if (strcmp(uri, LV2_URID__map) == 0)
  1219. return true;
  1220. if (strcmp(uri, LV2_URID__unmap) == 0)
  1221. return true;
  1222. if (strcmp(uri, LV2_WORKER__schedule) == 0)
  1223. return true;
  1224. return false;
  1225. }
  1226. static inline
  1227. bool is_lv2_ui_feature_supported(const LV2_URI uri)
  1228. {
  1229. if (is_lv2_feature_supported(uri))
  1230. return true;
  1231. if (strcmp(uri, LV2_DATA_ACCESS_URI) == 0)
  1232. return true;
  1233. if (strcmp(uri, LV2_INSTANCE_ACCESS_URI) == 0)
  1234. return true;
  1235. if (strcmp(uri, LV2_UI__fixedSize) == 0)
  1236. return true;
  1237. if (strcmp(uri, LV2_UI__makeResident) == 0)
  1238. return true;
  1239. if (strcmp(uri, LV2_UI__noUserResize) == 0)
  1240. return true;
  1241. if (strcmp(uri, LV2_UI__parent) == 0)
  1242. return true;
  1243. if (strcmp(uri, LV2_UI__portMap) == 0)
  1244. return true;
  1245. if (strcmp(uri, LV2_UI__portSubscribe) == 0)
  1246. return false; // TODO
  1247. if (strcmp(uri, LV2_UI__resize) == 0)
  1248. return true;
  1249. if (strcmp(uri, LV2_UI__touch) == 0)
  1250. return false; // TODO
  1251. if (strcmp(uri, LV2_EXTERNAL_UI__Widget) == 0)
  1252. return true;
  1253. if (strcmp(uri, LV2_EXTERNAL_UI_DEPRECATED_URI) == 0)
  1254. return true;
  1255. return false;
  1256. }
  1257. static inline
  1258. LV2_URI get_lv2_ui_uri(const LV2_Property type)
  1259. {
  1260. switch (type)
  1261. {
  1262. case LV2_UI_GTK2:
  1263. return LV2_UI__GtkUI;
  1264. case LV2_UI_GTK3:
  1265. return LV2_UI__Gtk3UI;
  1266. case LV2_UI_QT4:
  1267. return LV2_UI__Qt4UI;
  1268. case LV2_UI_COCOA:
  1269. return LV2_UI__CocoaUI;
  1270. case LV2_UI_WINDOWS:
  1271. return LV2_UI__WindowsUI;
  1272. case LV2_UI_X11:
  1273. return LV2_UI__X11UI;
  1274. case LV2_UI_EXTERNAL:
  1275. return LV2_EXTERNAL_UI__Widget;
  1276. case LV2_UI_OLD_EXTERNAL:
  1277. return LV2_EXTERNAL_UI_DEPRECATED_URI;
  1278. default:
  1279. return "UI URI type not supported";
  1280. }
  1281. }
  1282. #endif // CARLA_LV2_INCLUDES_H