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.

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