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. {
  273. needInit = false;
  274. load_all();
  275. }
  276. }
  277. private:
  278. bool needInit;
  279. };
  280. static Lv2WorldClass Lv2World;
  281. // ------------------------------------------------------------------------------------------------
  282. // Create new RDF object
  283. static inline
  284. const LV2_RDF_Descriptor* lv2_rdf_new(const LV2_URI URI)
  285. {
  286. Q_ASSERT(URI);
  287. Lv2World.init();
  288. Lilv::Plugins lilvPlugins = Lv2World.get_all_plugins();
  289. LILV_FOREACH(plugins, i, lilvPlugins)
  290. {
  291. Lilv::Plugin lilvPlugin(lilvPlugins.get(i));
  292. if (strcmp(lilvPlugin.get_uri().as_string(), URI) != 0)
  293. continue;
  294. LV2_RDF_Descriptor* const rdf_descriptor = new LV2_RDF_Descriptor;
  295. // --------------------------------------------------
  296. // Set Plugin Type
  297. {
  298. Lilv::Nodes typeNodes(lilvPlugin.get_value(Lv2World.rdf_type));
  299. if (typeNodes.size() > 0)
  300. {
  301. if (typeNodes.contains(Lv2World.class_allpass))
  302. rdf_descriptor->Type |= LV2_CLASS_ALLPASS;
  303. if (typeNodes.contains(Lv2World.class_amplifier))
  304. rdf_descriptor->Type |= LV2_CLASS_AMPLIFIER;
  305. if (typeNodes.contains(Lv2World.class_analyzer))
  306. rdf_descriptor->Type |= LV2_CLASS_ANALYSER;
  307. if (typeNodes.contains(Lv2World.class_bandpass))
  308. rdf_descriptor->Type |= LV2_CLASS_BANDPASS;
  309. if (typeNodes.contains(Lv2World.class_chorus))
  310. rdf_descriptor->Type |= LV2_CLASS_CHORUS;
  311. if (typeNodes.contains(Lv2World.class_comb))
  312. rdf_descriptor->Type |= LV2_CLASS_COMB;
  313. if (typeNodes.contains(Lv2World.class_compressor))
  314. rdf_descriptor->Type |= LV2_CLASS_COMPRESSOR;
  315. if (typeNodes.contains(Lv2World.class_constant))
  316. rdf_descriptor->Type |= LV2_CLASS_CONSTANT;
  317. if (typeNodes.contains(Lv2World.class_converter))
  318. rdf_descriptor->Type |= LV2_CLASS_CONVERTER;
  319. if (typeNodes.contains(Lv2World.class_delay))
  320. rdf_descriptor->Type |= LV2_CLASS_DELAY;
  321. if (typeNodes.contains(Lv2World.class_distortion))
  322. rdf_descriptor->Type |= LV2_CLASS_DISTORTION;
  323. if (typeNodes.contains(Lv2World.class_dynamics))
  324. rdf_descriptor->Type |= LV2_CLASS_DYNAMICS;
  325. if (typeNodes.contains(Lv2World.class_eq))
  326. rdf_descriptor->Type |= LV2_CLASS_EQ;
  327. if (typeNodes.contains(Lv2World.class_expander))
  328. rdf_descriptor->Type |= LV2_CLASS_EXPANDER;
  329. if (typeNodes.contains(Lv2World.class_filter))
  330. rdf_descriptor->Type |= LV2_CLASS_FILTER;
  331. if (typeNodes.contains(Lv2World.class_flanger))
  332. rdf_descriptor->Type |= LV2_CLASS_FLANGER;
  333. if (typeNodes.contains(Lv2World.class_function))
  334. rdf_descriptor->Type |= LV2_CLASS_FUNCTION;
  335. if (typeNodes.contains(Lv2World.class_gate))
  336. rdf_descriptor->Type |= LV2_CLASS_GATE;
  337. if (typeNodes.contains(Lv2World.class_generator))
  338. rdf_descriptor->Type |= LV2_CLASS_GENERATOR;
  339. if (typeNodes.contains(Lv2World.class_highpass))
  340. rdf_descriptor->Type |= LV2_CLASS_HIGHPASS;
  341. if (typeNodes.contains(Lv2World.class_instrument))
  342. rdf_descriptor->Type |= LV2_CLASS_INSTRUMENT;
  343. if (typeNodes.contains(Lv2World.class_limiter))
  344. rdf_descriptor->Type |= LV2_CLASS_LIMITER;
  345. if (typeNodes.contains(Lv2World.class_lowpass))
  346. rdf_descriptor->Type |= LV2_CLASS_LOWPASS;
  347. if (typeNodes.contains(Lv2World.class_mixer))
  348. rdf_descriptor->Type |= LV2_CLASS_MIXER;
  349. if (typeNodes.contains(Lv2World.class_modulator))
  350. rdf_descriptor->Type |= LV2_CLASS_MODULATOR;
  351. if (typeNodes.contains(Lv2World.class_multi_eq))
  352. rdf_descriptor->Type |= LV2_CLASS_MULTI_EQ;
  353. if (typeNodes.contains(Lv2World.class_oscillator))
  354. rdf_descriptor->Type |= LV2_CLASS_OSCILLATOR;
  355. if (typeNodes.contains(Lv2World.class_para_eq))
  356. rdf_descriptor->Type |= LV2_CLASS_PARA_EQ;
  357. if (typeNodes.contains(Lv2World.class_phaser))
  358. rdf_descriptor->Type |= LV2_CLASS_PHASER;
  359. if (typeNodes.contains(Lv2World.class_pitch))
  360. rdf_descriptor->Type |= LV2_CLASS_PITCH;
  361. if (typeNodes.contains(Lv2World.class_reverb))
  362. rdf_descriptor->Type |= LV2_CLASS_REVERB;
  363. if (typeNodes.contains(Lv2World.class_simulator))
  364. rdf_descriptor->Type |= LV2_CLASS_SIMULATOR;
  365. if (typeNodes.contains(Lv2World.class_spatial))
  366. rdf_descriptor->Type |= LV2_CLASS_SPATIAL;
  367. if (typeNodes.contains(Lv2World.class_spectral))
  368. rdf_descriptor->Type |= LV2_CLASS_SPECTRAL;
  369. if (typeNodes.contains(Lv2World.class_utility))
  370. rdf_descriptor->Type |= LV2_CLASS_UTILITY;
  371. if (typeNodes.contains(Lv2World.class_waveshaper))
  372. rdf_descriptor->Type |= LV2_CLASS_WAVESHAPER;
  373. }
  374. }
  375. // --------------------------------------------------
  376. // Set Plugin Information
  377. {
  378. rdf_descriptor->URI = strdup(URI);
  379. rdf_descriptor->Binary = strdup(lilv_uri_to_path(lilvPlugin.get_library_uri().as_string()));
  380. rdf_descriptor->Bundle = strdup(lilv_uri_to_path(lilvPlugin.get_bundle_uri().as_string()));
  381. if (lilvPlugin.get_name())
  382. rdf_descriptor->Name = strdup(lilvPlugin.get_name().as_string());
  383. if (lilvPlugin.get_author_name())
  384. rdf_descriptor->Author = strdup(lilvPlugin.get_author_name().as_string());
  385. Lilv::Nodes licenseNodes(lilvPlugin.get_value(Lv2World.doap_license));
  386. if (licenseNodes.size() > 0)
  387. rdf_descriptor->License = strdup(licenseNodes.get_first().as_string());
  388. }
  389. // --------------------------------------------------
  390. // Set Plugin UniqueID
  391. {
  392. Lilv::Nodes replaceNodes(lilvPlugin.get_value(Lv2World.dct_replaces));
  393. if (replaceNodes.size() > 0)
  394. {
  395. Lilv::Node replaceNode(replaceNodes.get_first());
  396. if (replaceNode.is_uri())
  397. {
  398. const QString replaceURI(replaceNode.as_uri());
  399. if (replaceURI.startsWith("urn:"))
  400. {
  401. const QString replaceId(replaceURI.split(":").last());
  402. bool ok;
  403. long uniqueId = replaceId.toLong(&ok);
  404. if (ok && uniqueId > 0)
  405. rdf_descriptor->UniqueID = uniqueId;
  406. }
  407. }
  408. }
  409. }
  410. // --------------------------------------------------
  411. // Set Plugin Ports
  412. if (lilvPlugin.get_num_ports() > 0)
  413. {
  414. rdf_descriptor->PortCount = lilvPlugin.get_num_ports();
  415. rdf_descriptor->Ports = new LV2_RDF_Port[rdf_descriptor->PortCount];
  416. for (uint32_t j = 0; j < rdf_descriptor->PortCount; j++)
  417. {
  418. Lilv::Port lilvPort(lilvPlugin.get_port_by_index(j));
  419. LV2_RDF_Port* const rdf_port = &rdf_descriptor->Ports[j];
  420. // --------------------------------------
  421. // Set Port Type
  422. {
  423. if (lilvPort.is_a(Lv2World.port_input))
  424. rdf_port->Type |= LV2_PORT_INPUT;
  425. if (lilvPort.is_a(Lv2World.port_output))
  426. rdf_port->Type |= LV2_PORT_OUTPUT;
  427. if (lilvPort.is_a(Lv2World.port_control))
  428. rdf_port->Type |= LV2_PORT_CONTROL;
  429. if (lilvPort.is_a(Lv2World.port_audio))
  430. rdf_port->Type |= LV2_PORT_AUDIO;
  431. if (lilvPort.is_a(Lv2World.port_cv))
  432. rdf_port->Type |= LV2_PORT_CV;
  433. if (lilvPort.is_a(Lv2World.port_atom))
  434. {
  435. rdf_port->Type |= LV2_PORT_ATOM;
  436. Lilv::Nodes bufferTypeNodes(lilvPort.get_value(Lv2World.atom_buffer_type));
  437. if (bufferTypeNodes.contains(Lv2World.atom_sequence))
  438. rdf_port->Type |= LV2_PORT_ATOM_SEQUENCE;
  439. Lilv::Nodes supportNodes(lilvPort.get_value(Lv2World.atom_supports));
  440. if (supportNodes.contains(Lv2World.midi_event))
  441. rdf_port->Type |= LV2_PORT_SUPPORTS_MIDI_EVENT;
  442. if (supportNodes.contains(Lv2World.patch_message))
  443. rdf_port->Type |= LV2_PORT_SUPPORTS_PATCH_MESSAGE;
  444. }
  445. if (lilvPort.is_a(Lv2World.port_event))
  446. {
  447. rdf_port->Type |= LV2_PORT_EVENT;
  448. if (lilvPort.supports_event(Lv2World.midi_event))
  449. rdf_port->Type |= LV2_PORT_SUPPORTS_MIDI_EVENT;
  450. }
  451. if (lilvPort.is_a(Lv2World.port_midi_ll))
  452. {
  453. rdf_port->Type |= LV2_PORT_MIDI_LL;
  454. rdf_port->Type |= LV2_PORT_SUPPORTS_MIDI_EVENT;
  455. }
  456. }
  457. // --------------------------------------
  458. // Set Port Properties
  459. {
  460. if (lilvPort.has_property(Lv2World.pprop_optional))
  461. rdf_port->Properties = LV2_PORT_OPTIONAL;
  462. if (lilvPort.has_property(Lv2World.pprop_enumeration))
  463. rdf_port->Properties = LV2_PORT_ENUMERATION;
  464. if (lilvPort.has_property(Lv2World.pprop_integer))
  465. rdf_port->Properties = LV2_PORT_INTEGER;
  466. if (lilvPort.has_property(Lv2World.pprop_sample_rate))
  467. rdf_port->Properties = LV2_PORT_SAMPLE_RATE;
  468. if (lilvPort.has_property(Lv2World.pprop_toggled))
  469. rdf_port->Properties = LV2_PORT_TOGGLED;
  470. if (lilvPort.has_property(Lv2World.pprop_artifacts))
  471. rdf_port->Properties = LV2_PORT_CAUSES_ARTIFACTS;
  472. if (lilvPort.has_property(Lv2World.pprop_continuous_cv))
  473. rdf_port->Properties = LV2_PORT_CONTINUOUS_CV;
  474. if (lilvPort.has_property(Lv2World.pprop_discrete_cv))
  475. rdf_port->Properties = LV2_PORT_DISCRETE_CV;
  476. if (lilvPort.has_property(Lv2World.pprop_expensive))
  477. rdf_port->Properties = LV2_PORT_EXPENSIVE;
  478. if (lilvPort.has_property(Lv2World.pprop_strict_bounds))
  479. rdf_port->Properties = LV2_PORT_STRICT_BOUNDS;
  480. if (lilvPort.has_property(Lv2World.pprop_logarithmic))
  481. rdf_port->Properties = LV2_PORT_LOGARITHMIC;
  482. if (lilvPort.has_property(Lv2World.pprop_not_automatic))
  483. rdf_port->Properties = LV2_PORT_NOT_AUTOMATIC;
  484. if (lilvPort.has_property(Lv2World.pprop_not_on_gui))
  485. rdf_port->Properties = LV2_PORT_NOT_ON_GUI;
  486. if (lilvPort.has_property(Lv2World.pprop_trigger))
  487. rdf_port->Properties = LV2_PORT_TRIGGER;
  488. if (lilvPort.has_property(Lv2World.reportsLatency))
  489. rdf_port->Designation = LV2_PORT_DESIGNATION_LATENCY;
  490. }
  491. // --------------------------------------
  492. // Set Port Designation
  493. {
  494. Lilv::Nodes designationNodes(lilvPort.get_value(Lv2World.designation));
  495. if (designationNodes.size() > 0)
  496. {
  497. const char* const designation = designationNodes.get_first().as_string();
  498. if (strcmp(designation, LV2_CORE__freeWheeling) == 0)
  499. rdf_port->Designation = LV2_PORT_DESIGNATION_FREEWHEELING;
  500. else if (strcmp(designation, LV2_CORE__latency) == 0)
  501. rdf_port->Designation = LV2_PORT_DESIGNATION_LATENCY;
  502. else if (strcmp(designation, LV2_PARAMETERS__sampleRate) == 0)
  503. rdf_port->Designation = LV2_PORT_DESIGNATION_SAMPLE_RATE;
  504. else if (strcmp(designation, LV2_TIME__bar) == 0)
  505. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BAR;
  506. else if (strcmp(designation, LV2_TIME__barBeat) == 0)
  507. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BAR_BEAT;
  508. else if (strcmp(designation, LV2_TIME__beat) == 0)
  509. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BEAT;
  510. else if (strcmp(designation, LV2_TIME__beatUnit) == 0)
  511. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BEAT_UNIT;
  512. else if (strcmp(designation, LV2_TIME__beatsPerBar) == 0)
  513. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BEATS_PER_BAR;
  514. else if (strcmp(designation, LV2_TIME__beatsPerMinute) == 0)
  515. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_BEATS_PER_MINUTE;
  516. else if (strcmp(designation, LV2_TIME__frame) == 0)
  517. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_FRAME;
  518. else if (strcmp(designation, LV2_TIME__framesPerSecond) == 0)
  519. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_FRAMES_PER_SECOND;
  520. else if (strcmp(designation, LV2_TIME__position) == 0)
  521. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_POSITION;
  522. else if (strcmp(designation, LV2_TIME__speed) == 0)
  523. rdf_port->Designation = LV2_PORT_DESIGNATION_TIME_SPEED;
  524. else if (strncmp(designation, LV2_PARAMETERS_PREFIX, strlen(LV2_PARAMETERS_PREFIX)) == 0)
  525. pass();
  526. else if (strncmp(designation, LV2_PORT_GROUPS_PREFIX, strlen(LV2_PORT_GROUPS_PREFIX)) == 0)
  527. pass();
  528. else
  529. qWarning("lv2_rdf_new(\"%s\") - got unknown Port Designation '%s'", URI, designation);
  530. }
  531. }
  532. // --------------------------------------
  533. // Set Port Information
  534. {
  535. rdf_port->Name = strdup(Lilv::Node(lilvPort.get_name()).as_string());
  536. rdf_port->Symbol = strdup(Lilv::Node(lilvPort.get_symbol()).as_string());
  537. }
  538. // --------------------------------------
  539. // Set Port MIDI Map
  540. {
  541. Lilv::Nodes midiMapNodes(lilvPort.get_value(Lv2World.mm_default_control));
  542. if (midiMapNodes.size() > 0)
  543. {
  544. Lilv::Node midiMapNode(midiMapNodes.get_first());
  545. if (midiMapNode.is_blank())
  546. {
  547. Lilv::Nodes midiMapTypeNodes(Lv2World.find_nodes(midiMapNode, Lv2World.mm_control_type, nullptr));
  548. Lilv::Nodes midiMapNumberNodes(Lv2World.find_nodes(midiMapNode, Lv2World.mm_control_number, nullptr));
  549. if (midiMapTypeNodes.size() == 1 && midiMapNumberNodes.size() == 1)
  550. {
  551. const char* const midiMapType = midiMapTypeNodes.get_first().as_string();
  552. if (strcmp(midiMapType, LV2_MIDI_Map__CC) == 0)
  553. rdf_port->MidiMap.Type = LV2_PORT_MIDI_MAP_CC;
  554. else if (strcmp(midiMapType, LV2_MIDI_Map__NRPN) == 0)
  555. rdf_port->MidiMap.Type = LV2_PORT_MIDI_MAP_NRPN;
  556. else
  557. qWarning("lv2_rdf_new(\"%s\") - got unknown Port Midi Map type '%s'", URI, midiMapType);
  558. rdf_port->MidiMap.Number = midiMapNumberNodes.get_first().as_int();
  559. }
  560. }
  561. }
  562. }
  563. // --------------------------------------
  564. // Set Port Points
  565. {
  566. Lilv::Nodes valueNodes(lilvPort.get_value(Lv2World.value_default));
  567. if (valueNodes.size() > 0)
  568. {
  569. rdf_port->Points.Hints |= LV2_PORT_POINT_DEFAULT;
  570. rdf_port->Points.Default = valueNodes.get_first().as_float();
  571. }
  572. valueNodes = lilvPort.get_value(Lv2World.value_minimum);
  573. if (valueNodes.size() > 0)
  574. {
  575. rdf_port->Points.Hints |= LV2_PORT_POINT_MINIMUM;
  576. rdf_port->Points.Minimum = valueNodes.get_first().as_float();
  577. }
  578. valueNodes = lilvPort.get_value(Lv2World.value_maximum);
  579. if (valueNodes.size() > 0)
  580. {
  581. rdf_port->Points.Hints |= LV2_PORT_POINT_MAXIMUM;
  582. rdf_port->Points.Maximum = valueNodes.get_first().as_float();
  583. }
  584. }
  585. // --------------------------------------
  586. // Set Port Unit
  587. {
  588. Lilv::Nodes unitTypeNodes(lilvPort.get_value(Lv2World.unit_unit));
  589. if (unitTypeNodes.size() > 0)
  590. {
  591. rdf_port->Unit.Hints |= LV2_PORT_UNIT;
  592. const char* const unitType = unitTypeNodes.get_first().as_uri();
  593. if (strcmp(unitType, LV2_UNITS__bar) == 0)
  594. rdf_port->Unit.Type = LV2_UNIT_BAR;
  595. else if (strcmp(unitType, LV2_UNITS__beat) == 0)
  596. rdf_port->Unit.Type = LV2_UNIT_BEAT;
  597. else if (strcmp(unitType, LV2_UNITS__bpm) == 0)
  598. rdf_port->Unit.Type = LV2_UNIT_BPM;
  599. else if (strcmp(unitType, LV2_UNITS__cent) == 0)
  600. rdf_port->Unit.Type = LV2_UNIT_CENT;
  601. else if (strcmp(unitType, LV2_UNITS__cm) == 0)
  602. rdf_port->Unit.Type = LV2_UNIT_CM;
  603. else if (strcmp(unitType, LV2_UNITS__coef) == 0)
  604. rdf_port->Unit.Type = LV2_UNIT_COEF;
  605. else if (strcmp(unitType, LV2_UNITS__db) == 0)
  606. rdf_port->Unit.Type = LV2_UNIT_DB;
  607. else if (strcmp(unitType, LV2_UNITS__degree) == 0)
  608. rdf_port->Unit.Type = LV2_UNIT_DEGREE;
  609. else if (strcmp(unitType, LV2_UNITS__frame) == 0)
  610. rdf_port->Unit.Type = LV2_UNIT_FRAME;
  611. else if (strcmp(unitType, LV2_UNITS__hz) == 0)
  612. rdf_port->Unit.Type = LV2_UNIT_HZ;
  613. else if (strcmp(unitType, LV2_UNITS__inch) == 0)
  614. rdf_port->Unit.Type = LV2_UNIT_INCH;
  615. else if (strcmp(unitType, LV2_UNITS__khz) == 0)
  616. rdf_port->Unit.Type = LV2_UNIT_KHZ;
  617. else if (strcmp(unitType, LV2_UNITS__km) == 0)
  618. rdf_port->Unit.Type = LV2_UNIT_KM;
  619. else if (strcmp(unitType, LV2_UNITS__m) == 0)
  620. rdf_port->Unit.Type = LV2_UNIT_M;
  621. else if (strcmp(unitType, LV2_UNITS__mhz) == 0)
  622. rdf_port->Unit.Type = LV2_UNIT_MHZ;
  623. else if (strcmp(unitType, LV2_UNITS__midiNote) == 0)
  624. rdf_port->Unit.Type = LV2_UNIT_MIDINOTE;
  625. else if (strcmp(unitType, LV2_UNITS__mile) == 0)
  626. rdf_port->Unit.Type = LV2_UNIT_MILE;
  627. else if (strcmp(unitType, LV2_UNITS__min) == 0)
  628. rdf_port->Unit.Type = LV2_UNIT_MIN;
  629. else if (strcmp(unitType, LV2_UNITS__mm) == 0)
  630. rdf_port->Unit.Type = LV2_UNIT_MM;
  631. else if (strcmp(unitType, LV2_UNITS__ms) == 0)
  632. rdf_port->Unit.Type = LV2_UNIT_MS;
  633. else if (strcmp(unitType, LV2_UNITS__oct) == 0)
  634. rdf_port->Unit.Type = LV2_UNIT_OCT;
  635. else if (strcmp(unitType, LV2_UNITS__pc) == 0)
  636. rdf_port->Unit.Type = LV2_UNIT_PC;
  637. else if (strcmp(unitType, LV2_UNITS__s) == 0)
  638. rdf_port->Unit.Type = LV2_UNIT_S;
  639. else if (strcmp(unitType, LV2_UNITS__semitone12TET) == 0)
  640. rdf_port->Unit.Type = LV2_UNIT_SEMITONE;
  641. else
  642. qWarning("lv2_rdf_new(\"%s\") - got unknown Unit type '%s'", URI, unitType);
  643. }
  644. Lilv::Nodes unitNameNodes(lilvPort.get_value(Lv2World.unit_name));
  645. if (unitNameNodes.size() > 0)
  646. {
  647. rdf_port->Unit.Hints |= LV2_PORT_UNIT_NAME;
  648. rdf_port->Unit.Name = strdup(unitNameNodes.get_first().as_string());
  649. }
  650. Lilv::Nodes unitRenderNodes(lilvPort.get_value(Lv2World.unit_render));
  651. if (unitRenderNodes.size() > 0)
  652. {
  653. rdf_port->Unit.Hints |= LV2_PORT_UNIT_RENDER;
  654. rdf_port->Unit.Render = strdup(unitRenderNodes.get_first().as_string());
  655. }
  656. Lilv::Nodes unitSymbolNodes(lilvPort.get_value(Lv2World.unit_symbol));
  657. if (unitSymbolNodes.size() > 0)
  658. {
  659. rdf_port->Unit.Hints |= LV2_PORT_UNIT_SYMBOL;
  660. rdf_port->Unit.Symbol = strdup(unitSymbolNodes.get_first().as_string());
  661. }
  662. }
  663. // --------------------------------------
  664. // Set Port Scale Points
  665. Lilv::ScalePoints lilvScalePoints(lilvPort.get_scale_points());
  666. if (lilvScalePoints.size() > 0)
  667. {
  668. rdf_port->ScalePointCount = lilvScalePoints.size();
  669. rdf_port->ScalePoints = new LV2_RDF_PortScalePoint[rdf_port->ScalePointCount];
  670. uint32_t h = 0;
  671. LILV_FOREACH(scale_points, j, lilvScalePoints)
  672. {
  673. Lilv::ScalePoint lilvScalePoint(lilvScalePoints.get(j));
  674. LV2_RDF_PortScalePoint* const rdf_scalePoint = &rdf_port->ScalePoints[h++];
  675. rdf_scalePoint->Label = strdup(Lilv::Node(lilvScalePoint.get_label()).as_string());
  676. rdf_scalePoint->Value = Lilv::Node(lilvScalePoint.get_value()).as_float();
  677. }
  678. }
  679. }
  680. }
  681. #if 0
  682. // --------------------------------------------------
  683. // Set Plugin Presets (TODO)
  684. {
  685. Lilv::Nodes presetNodes(lilvPlugin.get_related(Lv2World.preset_preset));
  686. if (presetNodes.size() > 0)
  687. {
  688. // create a list of preset URIs (for checking appliesTo, sorting and uniqueness)
  689. QStringList presetListURIs;
  690. LILV_FOREACH(nodes, j, presetNodes)
  691. {
  692. Lilv::Node presetNode(presetNodes.get(j));
  693. // FIXME - check appliesTo
  694. QString presetURI(presetNode.as_uri());
  695. if (! presetListURIs.contains(presetURI))
  696. presetListURIs.append(presetURI);
  697. }
  698. presetListURIs.sort();
  699. // create presets with unique URIs
  700. rdf_descriptor->PresetCount = presetListURIs.count();
  701. rdf_descriptor->Presets = new LV2_RDF_Preset[rdf_descriptor->PresetCount];
  702. // set preset data
  703. LILV_FOREACH(nodes, j, presetNodes)
  704. {
  705. Lilv::Node presetNode(presetNodes.get(j));
  706. Lv2World.load_resource(presetNode);
  707. LV2_URI presetURI = presetNode.as_uri();
  708. int32_t index = presetListURIs.indexOf(QString(presetURI));
  709. if (index < 0)
  710. continue;
  711. LV2_RDF_Preset* const rdf_preset = &rdf_descriptor->Presets[index];
  712. // --------------------------------------
  713. // Set Preset Information
  714. {
  715. rdf_preset->URI = strdup(presetURI);
  716. Lilv::Nodes presetLabelNodes(Lv2World.find_nodes(presetNode, Lv2World.rdfs_label, nullptr));
  717. if (presetLabelNodes.size() > 0)
  718. rdf_preset->Label = strdup(presetLabelNodes.get_first().as_string());
  719. }
  720. // --------------------------------------
  721. // Set Preset Ports
  722. {
  723. Lilv::Nodes presetPortNodes(Lv2World.find_nodes(presetNode, Lv2World.port, nullptr));
  724. if (presetPortNodes.size() > 0)
  725. {
  726. rdf_preset->PortCount = presetPortNodes.size();
  727. rdf_preset->Ports = new LV2_RDF_PresetPort[rdf_preset->PortCount];
  728. uint32_t h = 0;
  729. LILV_FOREACH(nodes, k, presetPortNodes)
  730. {
  731. Lilv::Node presetPortNode(presetPortNodes.get(k));
  732. Lilv::Nodes presetPortSymbolNodes(Lv2World.find_nodes(presetPortNode, Lv2World.symbol, nullptr));
  733. Lilv::Nodes presetPortValueNodes(Lv2World.find_nodes(presetPortNode, Lv2World.preset_value, nullptr));
  734. if (presetPortSymbolNodes.size() == 1 && presetPortValueNodes.size() == 1)
  735. {
  736. LV2_RDF_PresetPort* const rdf_presetPort = &rdf_preset->Ports[h++];
  737. rdf_presetPort->Symbol = strdup(presetPortSymbolNodes.get_first().as_string());
  738. rdf_presetPort->Value = presetPortValueNodes.get_first().as_float();
  739. }
  740. }
  741. }
  742. }
  743. // --------------------------------------
  744. // Set Preset States
  745. {
  746. Lilv::Nodes presetStateNodes(Lv2World.find_nodes(presetNode, Lv2World.state_state, nullptr));
  747. if (presetStateNodes.size() > 0)
  748. {
  749. rdf_preset->StateCount = presetStateNodes.size();
  750. rdf_preset->States = new LV2_RDF_PresetState[rdf_preset->StateCount];
  751. uint32_t h = 0;
  752. LILV_FOREACH(nodes, k, presetStateNodes)
  753. {
  754. Lilv::Node presetStateNode(presetStateNodes.get(k));
  755. if (presetStateNode.is_blank())
  756. {
  757. // TODO
  758. LV2_RDF_PresetState* const rdf_presetState = &rdf_preset->States[h++];
  759. rdf_presetState->Type = LV2_PRESET_STATE_NULL;
  760. rdf_presetState->Key = nullptr;
  761. }
  762. }
  763. }
  764. }
  765. }
  766. }
  767. }
  768. #endif
  769. // --------------------------------------------------
  770. // Set Plugin Features
  771. {
  772. Lilv::Nodes lilvFeatureNodes(lilvPlugin.get_supported_features());
  773. if (lilvFeatureNodes.size() > 0)
  774. {
  775. Lilv::Nodes lilvFeatureNodesR(lilvPlugin.get_required_features());
  776. rdf_descriptor->FeatureCount = lilvFeatureNodes.size();
  777. rdf_descriptor->Features = new LV2_RDF_Feature[rdf_descriptor->FeatureCount];
  778. uint32_t h = 0;
  779. LILV_FOREACH(nodes, j, lilvFeatureNodes)
  780. {
  781. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(j));
  782. LV2_RDF_Feature* const rdf_feature = &rdf_descriptor->Features[h++];
  783. rdf_feature->Type = lilvFeatureNodesR.contains(lilvFeatureNode) ? LV2_FEATURE_REQUIRED : LV2_FEATURE_OPTIONAL;
  784. rdf_feature->URI = strdup(lilvFeatureNode.as_uri());
  785. }
  786. }
  787. }
  788. // --------------------------------------------------
  789. // Set Plugin Extensions
  790. {
  791. Lilv::Nodes lilvExtensionDataNodes(lilvPlugin.get_extension_data());
  792. if (lilvExtensionDataNodes.size() > 0)
  793. {
  794. rdf_descriptor->ExtensionCount = lilvExtensionDataNodes.size();
  795. rdf_descriptor->Extensions = new LV2_URI[rdf_descriptor->ExtensionCount];
  796. uint32_t h = 0;
  797. LILV_FOREACH(nodes, j, lilvExtensionDataNodes)
  798. {
  799. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(j));
  800. LV2_URI* const rdf_extension = &rdf_descriptor->Extensions[h++];
  801. *rdf_extension = strdup(lilvExtensionDataNode.as_uri());
  802. }
  803. }
  804. }
  805. // --------------------------------------------------
  806. // Set Plugin UIs
  807. {
  808. Lilv::UIs lilvUIs(lilvPlugin.get_uis());
  809. if (lilvUIs.size() > 0)
  810. {
  811. rdf_descriptor->UICount = lilvUIs.size();
  812. rdf_descriptor->UIs = new LV2_RDF_UI[rdf_descriptor->UICount];
  813. uint32_t h = 0;
  814. LILV_FOREACH(uis, j, lilvUIs)
  815. {
  816. Lilv::UI lilvUI(lilvUIs.get(j));
  817. LV2_RDF_UI* const rdf_ui = &rdf_descriptor->UIs[h++];
  818. // --------------------------------------
  819. // Set UI Type
  820. {
  821. if (lilvUI.is_a(Lv2World.ui_gtk2))
  822. rdf_ui->Type = LV2_UI_GTK2;
  823. else if (lilvUI.is_a(Lv2World.ui_gtk3))
  824. rdf_ui->Type = LV2_UI_GTK3;
  825. else if (lilvUI.is_a(Lv2World.ui_qt4))
  826. rdf_ui->Type = LV2_UI_QT4;
  827. else if (lilvUI.is_a(Lv2World.ui_cocoa))
  828. rdf_ui->Type = LV2_UI_COCOA;
  829. else if (lilvUI.is_a(Lv2World.ui_windows))
  830. rdf_ui->Type = LV2_UI_WINDOWS;
  831. else if (lilvUI.is_a(Lv2World.ui_x11))
  832. rdf_ui->Type = LV2_UI_X11;
  833. else if (lilvUI.is_a(Lv2World.ui_external))
  834. rdf_ui->Type = LV2_UI_EXTERNAL;
  835. else if (lilvUI.is_a(Lv2World.ui_external_old))
  836. rdf_ui->Type = LV2_UI_OLD_EXTERNAL;
  837. else
  838. qWarning("lv2_rdf_new(\"%s\") - got unknown UI type '%s'", URI, lilvUI.get_uri().as_uri());
  839. }
  840. // --------------------------------------
  841. // Set UI Information
  842. {
  843. rdf_ui->URI = strdup(lilvUI.get_uri().as_uri());
  844. rdf_ui->Binary = strdup(lilv_uri_to_path(lilvUI.get_binary_uri().as_string()));
  845. rdf_ui->Bundle = strdup(lilv_uri_to_path(lilvUI.get_bundle_uri().as_string()));
  846. }
  847. // --------------------------------------
  848. // Set UI Features
  849. {
  850. Lilv::Nodes lilvFeatureNodes(lilvUI.get_supported_features());
  851. if (lilvFeatureNodes.size() > 0)
  852. {
  853. Lilv::Nodes lilvFeatureNodesR(lilvUI.get_required_features());
  854. rdf_ui->FeatureCount = lilvFeatureNodes.size();
  855. rdf_ui->Features = new LV2_RDF_Feature[rdf_ui->FeatureCount];
  856. uint32_t x = 0;
  857. LILV_FOREACH(nodes, k, lilvFeatureNodes)
  858. {
  859. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(k));
  860. LV2_RDF_Feature* const rdf_feature = &rdf_ui->Features[x++];
  861. rdf_feature->Type = lilvFeatureNodesR.contains(lilvFeatureNode) ? LV2_FEATURE_REQUIRED : LV2_FEATURE_OPTIONAL;
  862. rdf_feature->URI = strdup(lilvFeatureNode.as_uri());
  863. }
  864. }
  865. }
  866. // --------------------------------------
  867. // Set UI Extensions
  868. {
  869. Lilv::Nodes lilvExtensionDataNodes(lilvUI.get_extension_data());
  870. if (lilvExtensionDataNodes.size() > 0)
  871. {
  872. rdf_ui->ExtensionCount = lilvExtensionDataNodes.size();
  873. rdf_ui->Extensions = new LV2_URI[rdf_ui->ExtensionCount];
  874. uint32_t x = 0;
  875. LILV_FOREACH(nodes, k, lilvExtensionDataNodes)
  876. {
  877. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(k));
  878. LV2_URI* const rdf_extension = &rdf_ui->Extensions[x++];
  879. *rdf_extension = strdup(lilvExtensionDataNode.as_uri());
  880. }
  881. }
  882. }
  883. }
  884. }
  885. }
  886. return rdf_descriptor;
  887. }
  888. return nullptr;
  889. }
  890. // Copy RDF object
  891. static inline
  892. const LV2_RDF_Descriptor* lv2_rdf_dup(const LV2_RDF_Descriptor* const rdf_descriptor)
  893. {
  894. Q_ASSERT(rdf_descriptor);
  895. LV2_RDF_Descriptor* const new_descriptor = new LV2_RDF_Descriptor;
  896. new_descriptor->Type = rdf_descriptor->Type;
  897. new_descriptor->UniqueID = rdf_descriptor->UniqueID;
  898. new_descriptor->PortCount = rdf_descriptor->PortCount;
  899. new_descriptor->PresetCount = rdf_descriptor->PresetCount;
  900. new_descriptor->FeatureCount = rdf_descriptor->FeatureCount;
  901. new_descriptor->ExtensionCount = rdf_descriptor->ExtensionCount;
  902. new_descriptor->UICount = rdf_descriptor->UICount;
  903. if (rdf_descriptor->URI)
  904. new_descriptor->URI = strdup(rdf_descriptor->URI);
  905. if (rdf_descriptor->Name)
  906. new_descriptor->Name = strdup(rdf_descriptor->Name);
  907. if (rdf_descriptor->Author)
  908. new_descriptor->Author = strdup(rdf_descriptor->Author);
  909. if (rdf_descriptor->License)
  910. new_descriptor->License = strdup(rdf_descriptor->License);
  911. if (rdf_descriptor->Binary)
  912. new_descriptor->Binary = strdup(rdf_descriptor->Binary);
  913. if (rdf_descriptor->Bundle)
  914. new_descriptor->Bundle = strdup(rdf_descriptor->Bundle);
  915. // Ports
  916. if (new_descriptor->PortCount > 0)
  917. {
  918. new_descriptor->Ports = new LV2_RDF_Port[new_descriptor->PortCount];
  919. for (uint32_t i=0; i < new_descriptor->PortCount; i++)
  920. {
  921. LV2_RDF_Port* const Port = &new_descriptor->Ports[i];
  922. Port->Type = rdf_descriptor->Ports[i].Type;
  923. Port->Properties = rdf_descriptor->Ports[i].Properties;
  924. Port->Designation = rdf_descriptor->Ports[i].Designation;
  925. Port->MidiMap.Type = rdf_descriptor->Ports[i].MidiMap.Type;
  926. Port->MidiMap.Number = rdf_descriptor->Ports[i].MidiMap.Number;
  927. Port->Points.Hints = rdf_descriptor->Ports[i].Points.Hints;
  928. Port->Points.Default = rdf_descriptor->Ports[i].Points.Default;
  929. Port->Points.Minimum = rdf_descriptor->Ports[i].Points.Minimum;
  930. Port->Points.Maximum = rdf_descriptor->Ports[i].Points.Maximum;
  931. Port->Unit.Type = rdf_descriptor->Ports[i].Unit.Type;
  932. Port->Unit.Hints = rdf_descriptor->Ports[i].Unit.Hints;
  933. Port->ScalePointCount = rdf_descriptor->Ports[i].ScalePointCount;
  934. if (rdf_descriptor->Ports[i].Name)
  935. Port->Name = strdup(rdf_descriptor->Ports[i].Name);
  936. if (rdf_descriptor->Ports[i].Symbol)
  937. Port->Symbol = strdup(rdf_descriptor->Ports[i].Symbol);
  938. if (rdf_descriptor->Ports[i].Unit.Name)
  939. Port->Unit.Name = strdup(rdf_descriptor->Ports[i].Unit.Name);
  940. if (rdf_descriptor->Ports[i].Unit.Render)
  941. Port->Unit.Render = strdup(rdf_descriptor->Ports[i].Unit.Render);
  942. if (rdf_descriptor->Ports[i].Unit.Symbol)
  943. Port->Unit.Symbol = strdup(rdf_descriptor->Ports[i].Unit.Symbol);
  944. if (Port->ScalePointCount > 0)
  945. {
  946. Port->ScalePoints = new LV2_RDF_PortScalePoint[Port->ScalePointCount];
  947. for (uint32_t j=0; j < Port->ScalePointCount; j++)
  948. {
  949. Port->ScalePoints[j].Value = rdf_descriptor->Ports[i].ScalePoints[j].Value;
  950. if (rdf_descriptor->Ports[i].ScalePoints[j].Label)
  951. Port->ScalePoints[j].Label = strdup(rdf_descriptor->Ports[i].ScalePoints[j].Label);
  952. }
  953. }
  954. }
  955. }
  956. #if 0
  957. // Presets
  958. if (new_descriptor->PresetCount > 0)
  959. {
  960. new_descriptor->Presets = new LV2_RDF_Preset[new_descriptor->PresetCount];
  961. for (uint32_t i=0; i < new_descriptor->PresetCount; i++)
  962. {
  963. LV2_RDF_Preset* const Preset = &new_descriptor->Presets[i];
  964. Preset->PortCount = rdf_descriptor->Presets[i].PortCount;
  965. Preset->StateCount = rdf_descriptor->Presets[i].StateCount;
  966. if (rdf_descriptor->Presets[i].URI)
  967. Preset->URI = strdup(rdf_descriptor->Presets[i].URI);
  968. if (rdf_descriptor->Presets[i].Label)
  969. Preset->Label = strdup(rdf_descriptor->Presets[i].Label);
  970. // Ports
  971. if (Preset->PortCount > 0)
  972. {
  973. Preset->Ports = new LV2_RDF_PresetPort[Preset->PortCount];
  974. for (uint32_t j=0; j < Preset->PortCount; j++)
  975. {
  976. Preset->Ports[j].Value = rdf_descriptor->Presets[i].Ports[j].Value;
  977. if (rdf_descriptor->Presets[i].Ports[j].Symbol)
  978. Preset->Ports[j].Symbol = strdup(rdf_descriptor->Presets[i].Ports[j].Symbol);
  979. }
  980. }
  981. // States
  982. if (Preset->StateCount > 0)
  983. {
  984. Preset->States = new LV2_RDF_PresetState[Preset->StateCount];
  985. for (uint32_t j=0; j < Preset->StateCount; j++)
  986. {
  987. Preset->States[j].Type = rdf_descriptor->Presets[i].States[j].Type;
  988. if (rdf_descriptor->Presets[i].States[j].Key)
  989. Preset->States[j].Key = strdup(rdf_descriptor->Presets[i].States[j].Key);
  990. // TODO - copy value
  991. }
  992. }
  993. }
  994. }
  995. #endif
  996. // Features
  997. if (new_descriptor->FeatureCount > 0)
  998. {
  999. new_descriptor->Features = new LV2_RDF_Feature[new_descriptor->FeatureCount];
  1000. for (uint32_t i=0; i < new_descriptor->FeatureCount; i++)
  1001. {
  1002. new_descriptor->Features[i].Type = rdf_descriptor->Features[i].Type;
  1003. if (rdf_descriptor->Features[i].URI)
  1004. new_descriptor->Features[i].URI = strdup(rdf_descriptor->Features[i].URI);
  1005. }
  1006. }
  1007. // Extensions
  1008. if (new_descriptor->ExtensionCount > 0)
  1009. {
  1010. new_descriptor->Extensions = new LV2_URI[new_descriptor->ExtensionCount];
  1011. for (uint32_t i=0; i < new_descriptor->ExtensionCount; i++)
  1012. {
  1013. if (rdf_descriptor->Extensions[i])
  1014. new_descriptor->Extensions[i] = strdup(rdf_descriptor->Extensions[i]);
  1015. }
  1016. }
  1017. // UIs
  1018. if (new_descriptor->UICount > 0)
  1019. {
  1020. new_descriptor->UIs = new LV2_RDF_UI[new_descriptor->UICount];
  1021. for (uint32_t i=0; i < new_descriptor->UICount; i++)
  1022. {
  1023. LV2_RDF_UI* const UI = &new_descriptor->UIs[i];
  1024. UI->Type = rdf_descriptor->UIs[i].Type;
  1025. UI->FeatureCount = rdf_descriptor->UIs[i].FeatureCount;
  1026. UI->ExtensionCount = rdf_descriptor->UIs[i].ExtensionCount;
  1027. if (rdf_descriptor->UIs[i].URI)
  1028. UI->URI = strdup(rdf_descriptor->UIs[i].URI);
  1029. if (rdf_descriptor->UIs[i].Binary)
  1030. UI->Binary = strdup(rdf_descriptor->UIs[i].Binary);
  1031. if (rdf_descriptor->UIs[i].Bundle)
  1032. UI->Bundle = strdup(rdf_descriptor->UIs[i].Bundle);
  1033. // UI Features
  1034. if (UI->FeatureCount > 0)
  1035. {
  1036. UI->Features = new LV2_RDF_Feature[UI->FeatureCount];
  1037. for (uint32_t j=0; j < UI->FeatureCount; j++)
  1038. {
  1039. UI->Features[j].Type = rdf_descriptor->UIs[i].Features[j].Type;
  1040. if (rdf_descriptor->UIs[i].Features[j].URI)
  1041. UI->Features[j].URI = strdup(rdf_descriptor->UIs[i].Features[j].URI);
  1042. }
  1043. }
  1044. // UI Extensions
  1045. if (UI->ExtensionCount > 0)
  1046. {
  1047. UI->Extensions = new LV2_URI[UI->ExtensionCount];
  1048. for (uint32_t j=0; j < UI->ExtensionCount; j++)
  1049. {
  1050. if (rdf_descriptor->UIs[i].Extensions[j])
  1051. UI->Extensions[j] = strdup(rdf_descriptor->UIs[i].Extensions[j]);
  1052. }
  1053. }
  1054. }
  1055. }
  1056. return new_descriptor;
  1057. }
  1058. // Delete object
  1059. static inline
  1060. void lv2_rdf_free(const LV2_RDF_Descriptor* const rdf_descriptor)
  1061. {
  1062. if (rdf_descriptor->URI)
  1063. free((void*)rdf_descriptor->URI);
  1064. if (rdf_descriptor->Name)
  1065. free((void*)rdf_descriptor->Name);
  1066. if (rdf_descriptor->Author)
  1067. free((void*)rdf_descriptor->Author);
  1068. if (rdf_descriptor->License)
  1069. free((void*)rdf_descriptor->License);
  1070. if (rdf_descriptor->Binary)
  1071. free((void*)rdf_descriptor->Binary);
  1072. if (rdf_descriptor->Bundle)
  1073. free((void*)rdf_descriptor->Bundle);
  1074. if (rdf_descriptor->PortCount > 0)
  1075. {
  1076. for (uint32_t i=0; i < rdf_descriptor->PortCount; i++)
  1077. {
  1078. const LV2_RDF_Port* const Port = &rdf_descriptor->Ports[i];
  1079. if (Port->Name)
  1080. free((void*)Port->Name);
  1081. if (Port->Symbol)
  1082. free((void*)Port->Symbol);
  1083. if (Port->Unit.Name)
  1084. free((void*)Port->Unit.Name);
  1085. if (Port->Unit.Render)
  1086. free((void*)Port->Unit.Render);
  1087. if (Port->Unit.Symbol)
  1088. free((void*)Port->Unit.Symbol);
  1089. if (Port->ScalePointCount > 0)
  1090. {
  1091. for (uint32_t j=0; j < Port->ScalePointCount; j++)
  1092. {
  1093. const LV2_RDF_PortScalePoint* const PortScalePoint = &Port->ScalePoints[j];
  1094. if (PortScalePoint->Label)
  1095. free((void*)PortScalePoint->Label);
  1096. }
  1097. delete[] Port->ScalePoints;
  1098. }
  1099. }
  1100. delete[] rdf_descriptor->Ports;
  1101. }
  1102. #if 0
  1103. if (rdf_descriptor->PresetCount > 0)
  1104. {
  1105. for (uint32_t i=0; i < rdf_descriptor->PresetCount; i++)
  1106. {
  1107. const LV2_RDF_Preset* const Preset = &rdf_descriptor->Presets[i];
  1108. if (Preset->URI)
  1109. free((void*)Preset->URI);
  1110. if (Preset->Label)
  1111. free((void*)Preset->Label);
  1112. if (Preset->PortCount > 0)
  1113. {
  1114. for (uint32_t j=0; j < Preset->PortCount; j++)
  1115. {
  1116. const LV2_RDF_PresetPort* const PresetPort = &Preset->Ports[j];
  1117. if (PresetPort->Symbol)
  1118. free((void*)PresetPort->Symbol);
  1119. }
  1120. delete[] Preset->Ports;
  1121. }
  1122. if (Preset->StateCount > 0)
  1123. {
  1124. for (uint32_t j=0; j < Preset->StateCount; j++)
  1125. {
  1126. const LV2_RDF_PresetState* const PresetState = &Preset->States[j];
  1127. if (PresetState->Key)
  1128. free((void*)PresetState->Key);
  1129. // TODO - delete value
  1130. }
  1131. delete[] Preset->States;
  1132. }
  1133. }
  1134. delete[] rdf_descriptor->Presets;
  1135. }
  1136. #endif
  1137. if (rdf_descriptor->FeatureCount > 0)
  1138. {
  1139. for (uint32_t i=0; i < rdf_descriptor->FeatureCount; i++)
  1140. {
  1141. const LV2_RDF_Feature* const Feature = &rdf_descriptor->Features[i];
  1142. if (Feature->URI)
  1143. free((void*)Feature->URI);
  1144. }
  1145. delete[] rdf_descriptor->Features;
  1146. }
  1147. if (rdf_descriptor->ExtensionCount > 0)
  1148. {
  1149. for (uint32_t i=0; i < rdf_descriptor->ExtensionCount; i++)
  1150. {
  1151. const LV2_URI Extension = rdf_descriptor->Extensions[i];
  1152. if (Extension)
  1153. free((void*)Extension);
  1154. }
  1155. delete[] rdf_descriptor->Extensions;
  1156. }
  1157. if (rdf_descriptor->UICount > 0)
  1158. {
  1159. for (uint32_t i=0; i < rdf_descriptor->UICount; i++)
  1160. {
  1161. const LV2_RDF_UI* const UI = &rdf_descriptor->UIs[i];
  1162. if (UI->URI)
  1163. free((void*)UI->URI);
  1164. if (UI->Binary)
  1165. free((void*)UI->Binary);
  1166. if (UI->Bundle)
  1167. free((void*)UI->Bundle);
  1168. if (UI->FeatureCount > 0)
  1169. {
  1170. for (uint32_t j=0; j < UI->FeatureCount; j++)
  1171. {
  1172. const LV2_RDF_Feature* const Feature = &UI->Features[j];
  1173. if (Feature->URI)
  1174. free((void*)Feature->URI);
  1175. }
  1176. delete[] UI->Features;
  1177. }
  1178. if (UI->ExtensionCount > 0)
  1179. {
  1180. for (uint32_t j=0; j < UI->ExtensionCount; j++)
  1181. {
  1182. const LV2_URI Extension = UI->Extensions[j];
  1183. if (Extension)
  1184. free((void*)Extension);
  1185. }
  1186. delete[] UI->Extensions;
  1187. }
  1188. }
  1189. delete[] rdf_descriptor->UIs;
  1190. }
  1191. delete rdf_descriptor;
  1192. }
  1193. // ------------------------------------------------------------------------------------------------
  1194. static inline
  1195. bool is_lv2_feature_supported(const LV2_URI uri)
  1196. {
  1197. if (strcmp(uri, LV2_CORE__hardRTCapable) == 0)
  1198. return true;
  1199. if (strcmp(uri, LV2_CORE__inPlaceBroken) == 0)
  1200. return true;
  1201. if (strcmp(uri, LV2_CORE__isLive) == 0)
  1202. return true;
  1203. if (strcmp(uri, LV2_EVENT_URI) == 0)
  1204. return true;
  1205. if (strcmp(uri, LV2_LOG__log) == 0)
  1206. return true;
  1207. if (strcmp(uri, LV2_OPTIONS__options) == 0)
  1208. return true;
  1209. if (strcmp(uri, LV2_PROGRAMS__Host) == 0)
  1210. return true;
  1211. if (strcmp(uri, LV2_STATE__makePath) == 0)
  1212. return true;
  1213. if (strcmp(uri, LV2_STATE__mapPath) == 0)
  1214. return true;
  1215. if (strcmp(uri, LV2_PORT_PROPS__supportsStrictBounds) == 0)
  1216. return true;
  1217. if (strcmp(uri, LV2_URI_MAP_URI) == 0)
  1218. return true;
  1219. if (strcmp(uri, LV2_URID__map) == 0)
  1220. return true;
  1221. if (strcmp(uri, LV2_URID__unmap) == 0)
  1222. return true;
  1223. if (strcmp(uri, LV2_WORKER__schedule) == 0)
  1224. return true;
  1225. return false;
  1226. }
  1227. static inline
  1228. bool is_lv2_ui_feature_supported(const LV2_URI uri)
  1229. {
  1230. if (is_lv2_feature_supported(uri))
  1231. return true;
  1232. if (strcmp(uri, LV2_DATA_ACCESS_URI) == 0)
  1233. return true;
  1234. if (strcmp(uri, LV2_INSTANCE_ACCESS_URI) == 0)
  1235. return true;
  1236. if (strcmp(uri, LV2_UI__fixedSize) == 0)
  1237. return true;
  1238. if (strcmp(uri, LV2_UI__makeResident) == 0)
  1239. return true;
  1240. if (strcmp(uri, LV2_UI__noUserResize) == 0)
  1241. return true;
  1242. if (strcmp(uri, LV2_UI__parent) == 0)
  1243. return true;
  1244. if (strcmp(uri, LV2_UI__portMap) == 0)
  1245. return true;
  1246. if (strcmp(uri, LV2_UI__portSubscribe) == 0)
  1247. return false; // TODO
  1248. if (strcmp(uri, LV2_UI__resize) == 0)
  1249. return true;
  1250. if (strcmp(uri, LV2_UI__touch) == 0)
  1251. return false; // TODO
  1252. if (strcmp(uri, LV2_EXTERNAL_UI__Widget) == 0)
  1253. return true;
  1254. if (strcmp(uri, LV2_EXTERNAL_UI_DEPRECATED_URI) == 0)
  1255. return true;
  1256. return false;
  1257. }
  1258. static inline
  1259. LV2_URI get_lv2_ui_uri(const LV2_Property type)
  1260. {
  1261. switch (type)
  1262. {
  1263. case LV2_UI_GTK2:
  1264. return LV2_UI__GtkUI;
  1265. case LV2_UI_GTK3:
  1266. return LV2_UI__Gtk3UI;
  1267. case LV2_UI_QT4:
  1268. return LV2_UI__Qt4UI;
  1269. case LV2_UI_COCOA:
  1270. return LV2_UI__CocoaUI;
  1271. case LV2_UI_WINDOWS:
  1272. return LV2_UI__WindowsUI;
  1273. case LV2_UI_X11:
  1274. return LV2_UI__X11UI;
  1275. case LV2_UI_EXTERNAL:
  1276. return LV2_EXTERNAL_UI__Widget;
  1277. case LV2_UI_OLD_EXTERNAL:
  1278. return LV2_EXTERNAL_UI_DEPRECATED_URI;
  1279. default:
  1280. return "UI URI type not supported";
  1281. }
  1282. }
  1283. #endif // CARLA_LV2_INCLUDES_H