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.

1555 lines
61KB

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