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.

1544 lines
61KB

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