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.

1529 lines
60KB

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