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.

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