Audio plugin host https://kx.studio/carla
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.

1831 lines
77KB

  1. /*
  2. * Carla LV2 utils
  3. * Copyright (C) 2011-2017 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or 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 doc/GPL.txt file.
  16. */
  17. #ifndef CARLA_LV2_UTILS_HPP_INCLUDED
  18. #define CARLA_LV2_UTILS_HPP_INCLUDED
  19. #include "CarlaMathUtils.hpp"
  20. #ifndef nullptr
  21. # undef NULL
  22. # define NULL nullptr
  23. #endif
  24. // disable -Wdocumentation for LV2 headers
  25. #if defined(__clang__) && (__clang_major__ * 100 + __clang_minor__) > 300
  26. # pragma clang diagnostic push
  27. # pragma clang diagnostic ignored "-Wdocumentation"
  28. #endif
  29. #include "lv2/lv2.h"
  30. #include "lv2/atom.h"
  31. #include "lv2/atom-forge.h"
  32. #include "lv2/atom-helpers.h"
  33. #include "lv2/atom-util.h"
  34. #include "lv2/buf-size.h"
  35. #include "lv2/data-access.h"
  36. // dynmanifest
  37. #include "lv2/event.h"
  38. #include "lv2/event-helpers.h"
  39. #include "lv2/inline-display.h"
  40. #include "lv2/instance-access.h"
  41. #include "lv2/log.h"
  42. // logger
  43. #include "lv2/midi.h"
  44. // morph
  45. #include "lv2/options.h"
  46. #include "lv2/parameters.h"
  47. #include "lv2/patch.h"
  48. #include "lv2/port-groups.h"
  49. #include "lv2/port-props.h"
  50. #include "lv2/presets.h"
  51. #include "lv2/resize-port.h"
  52. #include "lv2/state.h"
  53. #include "lv2/time.h"
  54. #include "lv2/ui.h"
  55. #include "lv2/units.h"
  56. #include "lv2/uri-map.h"
  57. #include "lv2/urid.h"
  58. #include "lv2/worker.h"
  59. #include "lv2/lv2-miditype.h"
  60. #include "lv2/lv2-midifunctions.h"
  61. #include "lv2/lv2_external_ui.h"
  62. #include "lv2/lv2_kxstudio_properties.h"
  63. #include "lv2/lv2_programs.h"
  64. #include "lv2/lv2_rtmempool.h"
  65. #include "lilv/lilvmm.hpp"
  66. #include "sratom/sratom.h"
  67. // enable -Wdocumentation again
  68. #if defined(__clang__) && (__clang_major__ * 100 + __clang_minor__) > 300
  69. # pragma clang diagnostic pop
  70. #endif
  71. #include "lv2_rdf.hpp"
  72. #ifdef USE_QT
  73. # include <QtCore/QStringList>
  74. #else
  75. # include "water/text/StringArray.h"
  76. #endif
  77. // used for scalepoint sorting
  78. #include <map>
  79. typedef std::map<double,const LilvScalePoint*> LilvScalePointMap;
  80. // --------------------------------------------------------------------------------------------------------------------
  81. // Define namespaces and missing prefixes
  82. #define NS_dct "http://purl.org/dc/terms/"
  83. #define NS_doap "http://usefulinc.com/ns/doap#"
  84. #define NS_rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  85. #define NS_rdfs "http://www.w3.org/2000/01/rdf-schema#"
  86. #define NS_llmm "http://ll-plugins.nongnu.org/lv2/ext/midimap#"
  87. #define LV2_MIDI_Map__CC "http://ll-plugins.nongnu.org/lv2/namespace#CC"
  88. #define LV2_MIDI_Map__NRPN "http://ll-plugins.nongnu.org/lv2/namespace#NRPN"
  89. #define LV2_MIDI_LL__MidiPort "http://ll-plugins.nongnu.org/lv2/ext/MidiPort"
  90. #define LV2_UI__makeResident LV2_UI_PREFIX "makeResident"
  91. #define LV2_UI__makeSONameResident LV2_UI_PREFIX "makeSONameResident"
  92. // TODO: update LV2 headers once again
  93. #define LV2_CORE__enabled LV2_CORE_PREFIX "enabled" ///< http://lv2plug.in/ns/lv2core#enabled
  94. // --------------------------------------------------------------------------------------------------------------------
  95. // Custom Atom types
  96. struct LV2_Atom_MidiEvent {
  97. LV2_Atom atom; /**< Atom header. */
  98. uint8_t data[4]; /**< MIDI data (body). */
  99. };
  100. static inline
  101. uint32_t lv2_atom_total_size(const LV2_Atom_MidiEvent& midiEv)
  102. {
  103. return static_cast<uint32_t>(sizeof(LV2_Atom)) + midiEv.atom.size;
  104. }
  105. // ---------------------------------------------------------------------------------------------------------------------
  106. // -Weffc++ compat ext widget
  107. extern "C" {
  108. typedef struct _LV2_External_UI_Widget_Compat {
  109. void (*run )(struct _LV2_External_UI_Widget_Compat*);
  110. void (*show)(struct _LV2_External_UI_Widget_Compat*);
  111. void (*hide)(struct _LV2_External_UI_Widget_Compat*);
  112. _LV2_External_UI_Widget_Compat() noexcept
  113. : run(nullptr), show(nullptr), hide(nullptr) {}
  114. } LV2_External_UI_Widget_Compat;
  115. }
  116. // --------------------------------------------------------------------------------------------------------------------
  117. // Our LV2 World class
  118. class Lv2WorldClass : public Lilv::World
  119. {
  120. public:
  121. // Base Types
  122. Lilv::Node port;
  123. Lilv::Node symbol;
  124. Lilv::Node designation;
  125. Lilv::Node freeWheeling;
  126. Lilv::Node reportsLatency;
  127. // Plugin Types
  128. Lilv::Node class_allpass;
  129. Lilv::Node class_amplifier;
  130. Lilv::Node class_analyzer;
  131. Lilv::Node class_bandpass;
  132. Lilv::Node class_chorus;
  133. Lilv::Node class_comb;
  134. Lilv::Node class_compressor;
  135. Lilv::Node class_constant;
  136. Lilv::Node class_converter;
  137. Lilv::Node class_delay;
  138. Lilv::Node class_distortion;
  139. Lilv::Node class_dynamics;
  140. Lilv::Node class_eq;
  141. Lilv::Node class_envelope;
  142. Lilv::Node class_expander;
  143. Lilv::Node class_filter;
  144. Lilv::Node class_flanger;
  145. Lilv::Node class_function;
  146. Lilv::Node class_gate;
  147. Lilv::Node class_generator;
  148. Lilv::Node class_highpass;
  149. Lilv::Node class_instrument;
  150. Lilv::Node class_limiter;
  151. Lilv::Node class_lowpass;
  152. Lilv::Node class_mixer;
  153. Lilv::Node class_modulator;
  154. Lilv::Node class_multiEQ;
  155. Lilv::Node class_oscillator;
  156. Lilv::Node class_paraEQ;
  157. Lilv::Node class_phaser;
  158. Lilv::Node class_pitch;
  159. Lilv::Node class_reverb;
  160. Lilv::Node class_simulator;
  161. Lilv::Node class_spatial;
  162. Lilv::Node class_spectral;
  163. Lilv::Node class_utility;
  164. Lilv::Node class_waveshaper;
  165. // Port Types
  166. Lilv::Node port_input;
  167. Lilv::Node port_output;
  168. Lilv::Node port_control;
  169. Lilv::Node port_audio;
  170. Lilv::Node port_cv;
  171. Lilv::Node port_atom;
  172. Lilv::Node port_event;
  173. Lilv::Node port_midi;
  174. // Port Properties
  175. Lilv::Node pprop_optional;
  176. Lilv::Node pprop_enumeration;
  177. Lilv::Node pprop_integer;
  178. Lilv::Node pprop_sampleRate;
  179. Lilv::Node pprop_toggled;
  180. Lilv::Node pprop_artifacts;
  181. Lilv::Node pprop_continuousCV;
  182. Lilv::Node pprop_discreteCV;
  183. Lilv::Node pprop_expensive;
  184. Lilv::Node pprop_strictBounds;
  185. Lilv::Node pprop_logarithmic;
  186. Lilv::Node pprop_notAutomatic;
  187. Lilv::Node pprop_notOnGUI;
  188. Lilv::Node pprop_trigger;
  189. Lilv::Node pprop_nonAutomable;
  190. // Unit Hints
  191. Lilv::Node unit_name;
  192. Lilv::Node unit_render;
  193. Lilv::Node unit_symbol;
  194. Lilv::Node unit_unit;
  195. // UI Types
  196. Lilv::Node ui_gtk2;
  197. Lilv::Node ui_gtk3;
  198. Lilv::Node ui_qt4;
  199. Lilv::Node ui_qt5;
  200. Lilv::Node ui_cocoa;
  201. Lilv::Node ui_windows;
  202. Lilv::Node ui_x11;
  203. Lilv::Node ui_external;
  204. Lilv::Node ui_externalOld;
  205. Lilv::Node ui_externalOld2;
  206. // Misc
  207. Lilv::Node atom_bufferType;
  208. Lilv::Node atom_sequence;
  209. Lilv::Node atom_supports;
  210. Lilv::Node preset_preset;
  211. Lilv::Node state_state;
  212. Lilv::Node value_default;
  213. Lilv::Node value_minimum;
  214. Lilv::Node value_maximum;
  215. Lilv::Node rz_asLargeAs;
  216. Lilv::Node rz_minSize;
  217. // Port Data Types
  218. Lilv::Node midi_event;
  219. Lilv::Node patch_message;
  220. Lilv::Node time_position;
  221. // MIDI CC
  222. Lilv::Node mm_defaultControl;
  223. Lilv::Node mm_controlType;
  224. Lilv::Node mm_controlNumber;
  225. // Other
  226. Lilv::Node dct_replaces;
  227. Lilv::Node doap_license;
  228. Lilv::Node rdf_type;
  229. Lilv::Node rdfs_label;
  230. bool needsInit;
  231. const LilvPlugins* allPlugins;
  232. const LilvPlugin** cachedPlugins;
  233. uint pluginCount;
  234. // ----------------------------------------------------------------------------------------------------------------
  235. Lv2WorldClass()
  236. : Lilv::World(),
  237. port (new_uri(LV2_CORE__port)),
  238. symbol (new_uri(LV2_CORE__symbol)),
  239. designation (new_uri(LV2_CORE__designation)),
  240. freeWheeling (new_uri(LV2_CORE__freeWheeling)),
  241. reportsLatency (new_uri(LV2_CORE__reportsLatency)),
  242. class_allpass (new_uri(LV2_CORE__AllpassPlugin)),
  243. class_amplifier (new_uri(LV2_CORE__AmplifierPlugin)),
  244. class_analyzer (new_uri(LV2_CORE__AnalyserPlugin)),
  245. class_bandpass (new_uri(LV2_CORE__BandpassPlugin)),
  246. class_chorus (new_uri(LV2_CORE__ChorusPlugin)),
  247. class_comb (new_uri(LV2_CORE__CombPlugin)),
  248. class_compressor (new_uri(LV2_CORE__CompressorPlugin)),
  249. class_constant (new_uri(LV2_CORE__ConstantPlugin)),
  250. class_converter (new_uri(LV2_CORE__ConverterPlugin)),
  251. class_delay (new_uri(LV2_CORE__DelayPlugin)),
  252. class_distortion (new_uri(LV2_CORE__DistortionPlugin)),
  253. class_dynamics (new_uri(LV2_CORE__DynamicsPlugin)),
  254. class_eq (new_uri(LV2_CORE__EQPlugin)),
  255. class_envelope (new_uri(LV2_CORE__EnvelopePlugin)),
  256. class_expander (new_uri(LV2_CORE__ExpanderPlugin)),
  257. class_filter (new_uri(LV2_CORE__FilterPlugin)),
  258. class_flanger (new_uri(LV2_CORE__FlangerPlugin)),
  259. class_function (new_uri(LV2_CORE__FunctionPlugin)),
  260. class_gate (new_uri(LV2_CORE__GatePlugin)),
  261. class_generator (new_uri(LV2_CORE__GeneratorPlugin)),
  262. class_highpass (new_uri(LV2_CORE__HighpassPlugin)),
  263. class_instrument (new_uri(LV2_CORE__InstrumentPlugin)),
  264. class_limiter (new_uri(LV2_CORE__LimiterPlugin)),
  265. class_lowpass (new_uri(LV2_CORE__LowpassPlugin)),
  266. class_mixer (new_uri(LV2_CORE__MixerPlugin)),
  267. class_modulator (new_uri(LV2_CORE__ModulatorPlugin)),
  268. class_multiEQ (new_uri(LV2_CORE__MultiEQPlugin)),
  269. class_oscillator (new_uri(LV2_CORE__OscillatorPlugin)),
  270. class_paraEQ (new_uri(LV2_CORE__ParaEQPlugin)),
  271. class_phaser (new_uri(LV2_CORE__PhaserPlugin)),
  272. class_pitch (new_uri(LV2_CORE__PitchPlugin)),
  273. class_reverb (new_uri(LV2_CORE__ReverbPlugin)),
  274. class_simulator (new_uri(LV2_CORE__SimulatorPlugin)),
  275. class_spatial (new_uri(LV2_CORE__SpatialPlugin)),
  276. class_spectral (new_uri(LV2_CORE__SpectralPlugin)),
  277. class_utility (new_uri(LV2_CORE__UtilityPlugin)),
  278. class_waveshaper (new_uri(LV2_CORE__WaveshaperPlugin)),
  279. port_input (new_uri(LV2_CORE__InputPort)),
  280. port_output (new_uri(LV2_CORE__OutputPort)),
  281. port_control (new_uri(LV2_CORE__ControlPort)),
  282. port_audio (new_uri(LV2_CORE__AudioPort)),
  283. port_cv (new_uri(LV2_CORE__CVPort)),
  284. port_atom (new_uri(LV2_ATOM__AtomPort)),
  285. port_event (new_uri(LV2_EVENT__EventPort)),
  286. port_midi (new_uri(LV2_MIDI_LL__MidiPort)),
  287. pprop_optional (new_uri(LV2_CORE__connectionOptional)),
  288. pprop_enumeration (new_uri(LV2_CORE__enumeration)),
  289. pprop_integer (new_uri(LV2_CORE__integer)),
  290. pprop_sampleRate (new_uri(LV2_CORE__sampleRate)),
  291. pprop_toggled (new_uri(LV2_CORE__toggled)),
  292. pprop_artifacts (new_uri(LV2_PORT_PROPS__causesArtifacts)),
  293. pprop_continuousCV (new_uri(LV2_PORT_PROPS__continuousCV)),
  294. pprop_discreteCV (new_uri(LV2_PORT_PROPS__discreteCV)),
  295. pprop_expensive (new_uri(LV2_PORT_PROPS__expensive)),
  296. pprop_strictBounds (new_uri(LV2_PORT_PROPS__hasStrictBounds)),
  297. pprop_logarithmic (new_uri(LV2_PORT_PROPS__logarithmic)),
  298. pprop_notAutomatic (new_uri(LV2_PORT_PROPS__notAutomatic)),
  299. pprop_notOnGUI (new_uri(LV2_PORT_PROPS__notOnGUI)),
  300. pprop_trigger (new_uri(LV2_PORT_PROPS__trigger)),
  301. pprop_nonAutomable (new_uri(LV2_KXSTUDIO_PROPERTIES__NonAutomable)),
  302. unit_name (new_uri(LV2_UNITS__name)),
  303. unit_render (new_uri(LV2_UNITS__render)),
  304. unit_symbol (new_uri(LV2_UNITS__symbol)),
  305. unit_unit (new_uri(LV2_UNITS__unit)),
  306. ui_gtk2 (new_uri(LV2_UI__GtkUI)),
  307. ui_gtk3 (new_uri(LV2_UI__Gtk3UI)),
  308. ui_qt4 (new_uri(LV2_UI__Qt4UI)),
  309. ui_qt5 (new_uri(LV2_UI__Qt5UI)),
  310. ui_cocoa (new_uri(LV2_UI__CocoaUI)),
  311. ui_windows (new_uri(LV2_UI__WindowsUI)),
  312. ui_x11 (new_uri(LV2_UI__X11UI)),
  313. ui_external (new_uri(LV2_EXTERNAL_UI__Widget)),
  314. ui_externalOld (new_uri(LV2_EXTERNAL_UI_DEPRECATED_URI)),
  315. ui_externalOld2 (new_uri("http://nedko.arnaudov.name/lv2/external_ui/")),
  316. atom_bufferType (new_uri(LV2_ATOM__bufferType)),
  317. atom_sequence (new_uri(LV2_ATOM__Sequence)),
  318. atom_supports (new_uri(LV2_ATOM__supports)),
  319. preset_preset (new_uri(LV2_PRESETS__Preset)),
  320. state_state (new_uri(LV2_STATE__state)),
  321. value_default (new_uri(LV2_CORE__default)),
  322. value_minimum (new_uri(LV2_CORE__minimum)),
  323. value_maximum (new_uri(LV2_CORE__maximum)),
  324. rz_asLargeAs (new_uri(LV2_RESIZE_PORT__asLargeAs)),
  325. rz_minSize (new_uri(LV2_RESIZE_PORT__minimumSize)),
  326. midi_event (new_uri(LV2_MIDI__MidiEvent)),
  327. patch_message (new_uri(LV2_PATCH__Message)),
  328. time_position (new_uri(LV2_TIME__Position)),
  329. mm_defaultControl (new_uri(NS_llmm "defaultMidiController")),
  330. mm_controlType (new_uri(NS_llmm "controllerType")),
  331. mm_controlNumber (new_uri(NS_llmm "controllerNumber")),
  332. dct_replaces (new_uri(NS_dct "replaces")),
  333. doap_license (new_uri(NS_doap "license")),
  334. rdf_type (new_uri(NS_rdf "type")),
  335. rdfs_label (new_uri(NS_rdfs "label")),
  336. needsInit(true),
  337. allPlugins(nullptr),
  338. cachedPlugins(nullptr),
  339. pluginCount(0) {}
  340. ~Lv2WorldClass() override
  341. {
  342. pluginCount = 0;
  343. allPlugins = nullptr;
  344. if (cachedPlugins != nullptr)
  345. {
  346. delete[] cachedPlugins;
  347. cachedPlugins = nullptr;
  348. }
  349. }
  350. // FIXME - remove this
  351. static Lv2WorldClass& getInstance()
  352. {
  353. static Lv2WorldClass lv2World;
  354. return lv2World;
  355. }
  356. void initIfNeeded(const char* const LV2_PATH)
  357. {
  358. CARLA_SAFE_ASSERT_RETURN(LV2_PATH != nullptr,);
  359. if (! needsInit)
  360. return;
  361. needsInit = false;
  362. Lilv::World::load_all(LV2_PATH);
  363. allPlugins = lilv_world_get_all_plugins(this->me);
  364. CARLA_SAFE_ASSERT_RETURN(allPlugins != nullptr,);
  365. if ((pluginCount = lilv_plugins_size(allPlugins)))
  366. {
  367. cachedPlugins = new const LilvPlugin*[pluginCount+1];
  368. carla_zeroPointers(cachedPlugins, pluginCount+1);
  369. int i = 0;
  370. for (LilvIter* it = lilv_plugins_begin(allPlugins); ! lilv_plugins_is_end(allPlugins, it); it = lilv_plugins_next(allPlugins, it))
  371. cachedPlugins[i++] = lilv_plugins_get(allPlugins, it);
  372. }
  373. }
  374. void load_bundle(const char* const bundle)
  375. {
  376. CARLA_SAFE_ASSERT_RETURN(bundle != nullptr && bundle[0] != '\0',);
  377. CARLA_SAFE_ASSERT_RETURN(needsInit,);
  378. needsInit = false;
  379. Lilv::World::load_bundle(Lilv::Node(new_uri(bundle)));
  380. allPlugins = lilv_world_get_all_plugins(this->me);
  381. CARLA_SAFE_ASSERT_RETURN(allPlugins != nullptr,);
  382. if ((pluginCount = lilv_plugins_size(allPlugins)))
  383. {
  384. cachedPlugins = new const LilvPlugin*[pluginCount+1];
  385. carla_zeroPointers(cachedPlugins, pluginCount+1);
  386. int i = 0;
  387. for (LilvIter* it = lilv_plugins_begin(allPlugins); ! lilv_plugins_is_end(allPlugins, it); it = lilv_plugins_next(allPlugins, it))
  388. cachedPlugins[i++] = lilv_plugins_get(allPlugins, it);
  389. }
  390. }
  391. uint getPluginCount() const
  392. {
  393. CARLA_SAFE_ASSERT_RETURN(! needsInit, 0);
  394. return pluginCount;
  395. }
  396. const LilvPlugin* getPluginFromIndex(const uint index) const
  397. {
  398. CARLA_SAFE_ASSERT_RETURN(! needsInit, nullptr);
  399. CARLA_SAFE_ASSERT_RETURN(cachedPlugins != nullptr, nullptr);
  400. CARLA_SAFE_ASSERT_RETURN(index < pluginCount, nullptr);
  401. return cachedPlugins[index];
  402. }
  403. const LilvPlugin* getPluginFromURI(const LV2_URI uri) const
  404. {
  405. CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0', nullptr);
  406. CARLA_SAFE_ASSERT_RETURN(! needsInit, nullptr);
  407. CARLA_SAFE_ASSERT_RETURN(allPlugins != nullptr, nullptr);
  408. LilvNode* const uriNode(lilv_new_uri(this->me, uri));
  409. CARLA_SAFE_ASSERT_RETURN(uriNode != nullptr, nullptr);
  410. const LilvPlugin* const cPlugin(lilv_plugins_get_by_uri(allPlugins, uriNode));
  411. lilv_node_free(uriNode);
  412. return cPlugin;
  413. }
  414. LilvState* getStateFromURI(const LV2_URI uri, const LV2_URID_Map* const uridMap) const
  415. {
  416. CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0', nullptr);
  417. CARLA_SAFE_ASSERT_RETURN(uridMap != nullptr, nullptr);
  418. CARLA_SAFE_ASSERT_RETURN(! needsInit, nullptr);
  419. LilvNode* const uriNode(lilv_new_uri(this->me, uri));
  420. CARLA_SAFE_ASSERT_RETURN(uriNode != nullptr, nullptr);
  421. CARLA_SAFE_ASSERT(lilv_world_load_resource(this->me, uriNode) >= 0);
  422. LilvState* const cState(lilv_state_new_from_world(this->me, uridMap, uriNode));
  423. lilv_node_free(uriNode);
  424. return cState;
  425. }
  426. CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION
  427. CARLA_DECLARE_NON_COPY_STRUCT(Lv2WorldClass)
  428. };
  429. // --------------------------------------------------------------------------------------------------------------------
  430. // Our LV2 Plugin base class
  431. #if defined(__clang__)
  432. # pragma clang diagnostic push
  433. # pragma clang diagnostic ignored "-Weffc++"
  434. #elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
  435. # pragma GCC diagnostic push
  436. # pragma GCC diagnostic ignored "-Weffc++"
  437. #endif
  438. class Lv2PluginBaseClass : public LV2_External_UI_Widget_Compat
  439. {
  440. #if defined(__clang__)
  441. # pragma clang diagnostic pop
  442. #elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
  443. # pragma GCC diagnostic pop
  444. #endif
  445. public:
  446. Lv2PluginBaseClass(const double sampleRate, const LV2_Feature* const* const features)
  447. : fIsOffline(false),
  448. fBufferSize(0),
  449. fSampleRate(sampleRate),
  450. fUsingNominal(false),
  451. fUridMap(nullptr)
  452. {
  453. run = extui_run;
  454. show = extui_show;
  455. hide = extui_hide;
  456. if (fSampleRate < 1.0)
  457. {
  458. carla_stderr("Host doesn't provide a valid sample rate");
  459. return;
  460. }
  461. const LV2_Options_Option* options = nullptr;
  462. const LV2_URID_Map* uridMap = nullptr;
  463. const LV2_URID_Unmap* uridUnmap = nullptr;
  464. for (int i=0; features[i] != nullptr; ++i)
  465. {
  466. if (std::strcmp(features[i]->URI, LV2_OPTIONS__options) == 0)
  467. options = (const LV2_Options_Option*)features[i]->data;
  468. else if (std::strcmp(features[i]->URI, LV2_URID__map) == 0)
  469. uridMap = (const LV2_URID_Map*)features[i]->data;
  470. else if (std::strcmp(features[i]->URI, LV2_URID__unmap) == 0)
  471. uridUnmap = (const LV2_URID_Unmap*)features[i]->data;
  472. }
  473. if (options == nullptr || uridMap == nullptr)
  474. {
  475. carla_stderr("Host doesn't provide option or urid-map features");
  476. return;
  477. }
  478. for (int i=0; options[i].key != 0; ++i)
  479. {
  480. if (uridUnmap != nullptr) {
  481. carla_debug("Host option %i:\"%s\"", i, uridUnmap->unmap(uridUnmap->handle, options[i].key));
  482. }
  483. if (options[i].key == uridMap->map(uridMap->handle, LV2_BUF_SIZE__nominalBlockLength))
  484. {
  485. if (options[i].type == uridMap->map(uridMap->handle, LV2_ATOM__Int))
  486. {
  487. const int value(*(const int*)options[i].value);
  488. CARLA_SAFE_ASSERT_CONTINUE(value > 0);
  489. fBufferSize = static_cast<uint32_t>(value);
  490. fUsingNominal = true;
  491. }
  492. else
  493. {
  494. carla_stderr("Host provides nominalBlockLength but has wrong value type");
  495. }
  496. break;
  497. }
  498. if (options[i].key == uridMap->map(uridMap->handle, LV2_BUF_SIZE__maxBlockLength))
  499. {
  500. if (options[i].type == uridMap->map(uridMap->handle, LV2_ATOM__Int))
  501. {
  502. const int value(*(const int*)options[i].value);
  503. CARLA_SAFE_ASSERT_CONTINUE(value > 0);
  504. fBufferSize = static_cast<uint32_t>(value);
  505. }
  506. else
  507. {
  508. carla_stderr("Host provides maxBlockLength but has wrong value type");
  509. }
  510. // no break, continue in case host supports nominalBlockLength
  511. }
  512. }
  513. if (fBufferSize == 0)
  514. {
  515. carla_stderr("Host doesn't provide buffer-size feature");
  516. //return;
  517. // as testing, continue for now
  518. fBufferSize = 1024;
  519. }
  520. fUridMap = uridMap;
  521. fURIs.map(uridMap);
  522. }
  523. virtual ~Lv2PluginBaseClass()
  524. {
  525. }
  526. bool loadedInProperHost() const noexcept
  527. {
  528. return fUridMap != nullptr && fBufferSize != 0;
  529. }
  530. protected:
  531. virtual void handleUiRun() const = 0;
  532. virtual void handleUiShow() = 0;
  533. virtual void handleUiHide() = 0;
  534. // LV2 host data
  535. bool fIsOffline;
  536. uint32_t fBufferSize;
  537. double fSampleRate;
  538. bool fUsingNominal;
  539. // LV2 host features
  540. const LV2_URID_Map* fUridMap;
  541. struct URIDs {
  542. LV2_URID atomBlank;
  543. LV2_URID atomObject;
  544. LV2_URID atomDouble;
  545. LV2_URID atomFloat;
  546. LV2_URID atomInt;
  547. LV2_URID atomLong;
  548. LV2_URID atomSequence;
  549. LV2_URID atomString;
  550. LV2_URID midiEvent;
  551. LV2_URID timePos;
  552. LV2_URID timeBar;
  553. LV2_URID timeBarBeat;
  554. LV2_URID timeBeatsPerBar;
  555. LV2_URID timeBeatsPerMinute;
  556. LV2_URID timeBeatUnit;
  557. LV2_URID timeFrame;
  558. LV2_URID timeSpeed;
  559. LV2_URID timeTicksPerBeat;
  560. URIDs()
  561. : atomBlank(0),
  562. atomObject(0),
  563. atomDouble(0),
  564. atomFloat(0),
  565. atomInt(0),
  566. atomLong(0),
  567. atomSequence(0),
  568. atomString(0),
  569. midiEvent(0),
  570. timePos(0),
  571. timeBar(0),
  572. timeBarBeat(0),
  573. timeBeatsPerBar(0),
  574. timeBeatsPerMinute(0),
  575. timeBeatUnit(0),
  576. timeFrame(0),
  577. timeSpeed(0),
  578. timeTicksPerBeat(0) {}
  579. void map(const LV2_URID_Map* const uridMap)
  580. {
  581. atomBlank = uridMap->map(uridMap->handle, LV2_ATOM__Blank);
  582. atomObject = uridMap->map(uridMap->handle, LV2_ATOM__Object);
  583. atomDouble = uridMap->map(uridMap->handle, LV2_ATOM__Double);
  584. atomFloat = uridMap->map(uridMap->handle, LV2_ATOM__Float);
  585. atomInt = uridMap->map(uridMap->handle, LV2_ATOM__Int);
  586. atomLong = uridMap->map(uridMap->handle, LV2_ATOM__Long);
  587. atomSequence = uridMap->map(uridMap->handle, LV2_ATOM__Sequence);
  588. atomString = uridMap->map(uridMap->handle, LV2_ATOM__String);
  589. midiEvent = uridMap->map(uridMap->handle, LV2_MIDI__MidiEvent);
  590. timePos = uridMap->map(uridMap->handle, LV2_TIME__Position);
  591. timeBar = uridMap->map(uridMap->handle, LV2_TIME__bar);
  592. timeBarBeat = uridMap->map(uridMap->handle, LV2_TIME__barBeat);
  593. timeBeatUnit = uridMap->map(uridMap->handle, LV2_TIME__beatUnit);
  594. timeFrame = uridMap->map(uridMap->handle, LV2_TIME__frame);
  595. timeSpeed = uridMap->map(uridMap->handle, LV2_TIME__speed);
  596. timeBeatsPerBar = uridMap->map(uridMap->handle, LV2_TIME__beatsPerBar);
  597. timeBeatsPerMinute = uridMap->map(uridMap->handle, LV2_TIME__beatsPerMinute);
  598. timeTicksPerBeat = uridMap->map(uridMap->handle, LV2_KXSTUDIO_PROPERTIES__TimePositionTicksPerBeat);
  599. }
  600. } fURIs;
  601. private:
  602. // ----------------------------------------------------------------------------------------------------------------
  603. #define handlePtr ((Lv2PluginBaseClass*)handle)
  604. static void extui_run(LV2_External_UI_Widget_Compat* handle)
  605. {
  606. handlePtr->handleUiRun();
  607. }
  608. static void extui_show(LV2_External_UI_Widget_Compat* handle)
  609. {
  610. handlePtr->handleUiShow();
  611. }
  612. static void extui_hide(LV2_External_UI_Widget_Compat* handle)
  613. {
  614. handlePtr->handleUiHide();
  615. }
  616. #undef handlePtr
  617. // ----------------------------------------------------------------------------------------------------------------
  618. CARLA_DECLARE_NON_COPY_STRUCT(Lv2PluginBaseClass)
  619. };
  620. // --------------------------------------------------------------------------------------------------------------------
  621. // Create new RDF object (using lilv)
  622. static inline
  623. const LV2_RDF_Descriptor* lv2_rdf_new(const LV2_URI uri, const bool loadPresets)
  624. {
  625. CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0', nullptr);
  626. Lv2WorldClass& lv2World(Lv2WorldClass::getInstance());
  627. const LilvPlugin* const cPlugin(lv2World.getPluginFromURI(uri));
  628. CARLA_SAFE_ASSERT_RETURN(cPlugin != nullptr, nullptr);
  629. Lilv::Plugin lilvPlugin(cPlugin);
  630. LV2_RDF_Descriptor* const rdfDescriptor(new LV2_RDF_Descriptor());
  631. // ----------------------------------------------------------------------------------------------------------------
  632. // Set Plugin Type
  633. {
  634. Lilv::Nodes typeNodes(lilvPlugin.get_value(lv2World.rdf_type));
  635. if (typeNodes.size() > 0)
  636. {
  637. if (typeNodes.contains(lv2World.class_allpass))
  638. rdfDescriptor->Type[0] |= LV2_PLUGIN_ALLPASS;
  639. if (typeNodes.contains(lv2World.class_amplifier))
  640. rdfDescriptor->Type[0] |= LV2_PLUGIN_AMPLIFIER;
  641. if (typeNodes.contains(lv2World.class_analyzer))
  642. rdfDescriptor->Type[1] |= LV2_PLUGIN_ANALYSER;
  643. if (typeNodes.contains(lv2World.class_bandpass))
  644. rdfDescriptor->Type[0] |= LV2_PLUGIN_BANDPASS;
  645. if (typeNodes.contains(lv2World.class_chorus))
  646. rdfDescriptor->Type[1] |= LV2_PLUGIN_CHORUS;
  647. if (typeNodes.contains(lv2World.class_comb))
  648. rdfDescriptor->Type[1] |= LV2_PLUGIN_COMB;
  649. if (typeNodes.contains(lv2World.class_compressor))
  650. rdfDescriptor->Type[0] |= LV2_PLUGIN_COMPRESSOR;
  651. if (typeNodes.contains(lv2World.class_constant))
  652. rdfDescriptor->Type[1] |= LV2_PLUGIN_CONSTANT;
  653. if (typeNodes.contains(lv2World.class_converter))
  654. rdfDescriptor->Type[1] |= LV2_PLUGIN_CONVERTER;
  655. if (typeNodes.contains(lv2World.class_delay))
  656. rdfDescriptor->Type[0] |= LV2_PLUGIN_DELAY;
  657. if (typeNodes.contains(lv2World.class_distortion))
  658. rdfDescriptor->Type[0] |= LV2_PLUGIN_DISTORTION;
  659. if (typeNodes.contains(lv2World.class_dynamics))
  660. rdfDescriptor->Type[0] |= LV2_PLUGIN_DYNAMICS;
  661. if (typeNodes.contains(lv2World.class_eq))
  662. rdfDescriptor->Type[0] |= LV2_PLUGIN_EQ;
  663. if (typeNodes.contains(lv2World.class_envelope))
  664. rdfDescriptor->Type[0] |= LV2_PLUGIN_ENVELOPE;
  665. if (typeNodes.contains(lv2World.class_expander))
  666. rdfDescriptor->Type[0] |= LV2_PLUGIN_EXPANDER;
  667. if (typeNodes.contains(lv2World.class_filter))
  668. rdfDescriptor->Type[0] |= LV2_PLUGIN_FILTER;
  669. if (typeNodes.contains(lv2World.class_flanger))
  670. rdfDescriptor->Type[1] |= LV2_PLUGIN_FLANGER;
  671. if (typeNodes.contains(lv2World.class_function))
  672. rdfDescriptor->Type[1] |= LV2_PLUGIN_FUNCTION;
  673. if (typeNodes.contains(lv2World.class_gate))
  674. rdfDescriptor->Type[0] |= LV2_PLUGIN_GATE;
  675. if (typeNodes.contains(lv2World.class_generator))
  676. rdfDescriptor->Type[1] |= LV2_PLUGIN_GENERATOR;
  677. if (typeNodes.contains(lv2World.class_highpass))
  678. rdfDescriptor->Type[0] |= LV2_PLUGIN_HIGHPASS;
  679. if (typeNodes.contains(lv2World.class_instrument))
  680. rdfDescriptor->Type[1] |= LV2_PLUGIN_INSTRUMENT;
  681. if (typeNodes.contains(lv2World.class_limiter))
  682. rdfDescriptor->Type[0] |= LV2_PLUGIN_LIMITER;
  683. if (typeNodes.contains(lv2World.class_lowpass))
  684. rdfDescriptor->Type[0] |= LV2_PLUGIN_LOWPASS;
  685. if (typeNodes.contains(lv2World.class_mixer))
  686. rdfDescriptor->Type[1] |= LV2_PLUGIN_MIXER;
  687. if (typeNodes.contains(lv2World.class_modulator))
  688. rdfDescriptor->Type[1] |= LV2_PLUGIN_MODULATOR;
  689. if (typeNodes.contains(lv2World.class_multiEQ))
  690. rdfDescriptor->Type[0] |= LV2_PLUGIN_MULTI_EQ;
  691. if (typeNodes.contains(lv2World.class_oscillator))
  692. rdfDescriptor->Type[1] |= LV2_PLUGIN_OSCILLATOR;
  693. if (typeNodes.contains(lv2World.class_paraEQ))
  694. rdfDescriptor->Type[0] |= LV2_PLUGIN_PARA_EQ;
  695. if (typeNodes.contains(lv2World.class_phaser))
  696. rdfDescriptor->Type[1] |= LV2_PLUGIN_PHASER;
  697. if (typeNodes.contains(lv2World.class_pitch))
  698. rdfDescriptor->Type[1] |= LV2_PLUGIN_PITCH;
  699. if (typeNodes.contains(lv2World.class_reverb))
  700. rdfDescriptor->Type[0] |= LV2_PLUGIN_REVERB;
  701. if (typeNodes.contains(lv2World.class_simulator))
  702. rdfDescriptor->Type[0] |= LV2_PLUGIN_SIMULATOR;
  703. if (typeNodes.contains(lv2World.class_spatial))
  704. rdfDescriptor->Type[1] |= LV2_PLUGIN_SPATIAL;
  705. if (typeNodes.contains(lv2World.class_spectral))
  706. rdfDescriptor->Type[1] |= LV2_PLUGIN_SPECTRAL;
  707. if (typeNodes.contains(lv2World.class_utility))
  708. rdfDescriptor->Type[1] |= LV2_PLUGIN_UTILITY;
  709. if (typeNodes.contains(lv2World.class_waveshaper))
  710. rdfDescriptor->Type[0] |= LV2_PLUGIN_WAVESHAPER;
  711. }
  712. lilv_nodes_free(const_cast<LilvNodes*>(typeNodes.me));
  713. }
  714. // ----------------------------------------------------------------------------------------------------------------
  715. // Set Plugin Information
  716. {
  717. rdfDescriptor->URI = carla_strdup(uri);
  718. if (LilvNode* const nameNode = lilv_plugin_get_name(lilvPlugin.me))
  719. {
  720. if (const char* const name = lilv_node_as_string(nameNode))
  721. rdfDescriptor->Name = carla_strdup(name);
  722. lilv_node_free(nameNode);
  723. }
  724. if (const char* const author = lilvPlugin.get_author_name().as_string())
  725. rdfDescriptor->Author = carla_strdup(author);
  726. if (const char* const binary = lilvPlugin.get_library_uri().as_string())
  727. rdfDescriptor->Binary = carla_strdup_free(lilv_file_uri_parse(binary, nullptr));
  728. if (const char* const bundle = lilvPlugin.get_bundle_uri().as_string())
  729. rdfDescriptor->Bundle = carla_strdup_free(lilv_file_uri_parse(bundle, nullptr));
  730. Lilv::Nodes licenseNodes(lilvPlugin.get_value(lv2World.doap_license));
  731. if (licenseNodes.size() > 0)
  732. {
  733. if (const char* const license = licenseNodes.get_first().as_string())
  734. rdfDescriptor->License = carla_strdup(license);
  735. }
  736. lilv_nodes_free(const_cast<LilvNodes*>(licenseNodes.me));
  737. }
  738. // ----------------------------------------------------------------------------------------------------------------
  739. // Set Plugin UniqueID
  740. {
  741. Lilv::Nodes replaceNodes(lilvPlugin.get_value(lv2World.dct_replaces));
  742. if (replaceNodes.size() > 0)
  743. {
  744. Lilv::Node replaceNode(replaceNodes.get_first());
  745. if (replaceNode.is_uri())
  746. {
  747. #ifdef USE_QT
  748. const QString replaceURI(replaceNode.as_uri());
  749. if (replaceURI.startsWith("urn:"))
  750. {
  751. const QString replaceId(replaceURI.split(":").last());
  752. bool ok;
  753. const ulong uniqueId(replaceId.toULong(&ok));
  754. if (ok && uniqueId != 0)
  755. rdfDescriptor->UniqueID = uniqueId;
  756. }
  757. #else
  758. const water::String replaceURI(replaceNode.as_uri());
  759. if (replaceURI.startsWith("urn:"))
  760. {
  761. const int uniqueId(replaceURI.getTrailingIntValue());
  762. if (uniqueId > 0)
  763. rdfDescriptor->UniqueID = static_cast<ulong>(uniqueId);
  764. }
  765. #endif
  766. }
  767. }
  768. lilv_nodes_free(const_cast<LilvNodes*>(replaceNodes.me));
  769. }
  770. // ----------------------------------------------------------------------------------------------------------------
  771. // Set Plugin Ports
  772. if (lilvPlugin.get_num_ports() > 0)
  773. {
  774. rdfDescriptor->PortCount = lilvPlugin.get_num_ports();
  775. rdfDescriptor->Ports = new LV2_RDF_Port[rdfDescriptor->PortCount];
  776. for (uint32_t i = 0; i < rdfDescriptor->PortCount; ++i)
  777. {
  778. Lilv::Port lilvPort(lilvPlugin.get_port_by_index(i));
  779. LV2_RDF_Port* const rdfPort(&rdfDescriptor->Ports[i]);
  780. // --------------------------------------------------------------------------------------------------------
  781. // Set Port Information
  782. {
  783. if (LilvNode* const nameNode = lilv_port_get_name(lilvPlugin.me, lilvPort.me))
  784. {
  785. if (const char* const name = lilv_node_as_string(nameNode))
  786. rdfPort->Name = carla_strdup(name);
  787. lilv_node_free(nameNode);
  788. }
  789. if (const char* const symbol = lilv_node_as_string(lilvPort.get_symbol()))
  790. rdfPort->Symbol = carla_strdup(symbol);
  791. }
  792. // --------------------------------------------------------------------------------------------------------
  793. // Set Port Mode and Type
  794. {
  795. // Input or Output
  796. /**/ if (lilvPort.is_a(lv2World.port_input))
  797. rdfPort->Types |= LV2_PORT_INPUT;
  798. else if (lilvPort.is_a(lv2World.port_output))
  799. rdfPort->Types |= LV2_PORT_OUTPUT;
  800. else
  801. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is not input or output", uri, rdfPort->Name);
  802. // Data Type
  803. /**/ if (lilvPort.is_a(lv2World.port_control))
  804. {
  805. rdfPort->Types |= LV2_PORT_CONTROL;
  806. }
  807. else if (lilvPort.is_a(lv2World.port_audio))
  808. {
  809. rdfPort->Types |= LV2_PORT_AUDIO;
  810. }
  811. else if (lilvPort.is_a(lv2World.port_cv))
  812. {
  813. rdfPort->Types |= LV2_PORT_CV;
  814. }
  815. else if (lilvPort.is_a(lv2World.port_atom))
  816. {
  817. rdfPort->Types |= LV2_PORT_ATOM;
  818. Lilv::Nodes bufferTypeNodes(lilvPort.get_value(lv2World.atom_bufferType));
  819. for (LilvIter* it = lilv_nodes_begin(bufferTypeNodes.me); ! lilv_nodes_is_end(bufferTypeNodes.me, it); it = lilv_nodes_next(bufferTypeNodes.me, it))
  820. {
  821. const Lilv::Node node(lilv_nodes_get(bufferTypeNodes.me, it));
  822. CARLA_SAFE_ASSERT_CONTINUE(node.is_uri());
  823. if (node.equals(lv2World.atom_sequence))
  824. rdfPort->Types |= LV2_PORT_ATOM_SEQUENCE;
  825. else
  826. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses an unknown atom buffer type '%s'", uri, rdfPort->Name, node.as_uri());
  827. }
  828. Lilv::Nodes supportNodes(lilvPort.get_value(lv2World.atom_supports));
  829. for (LilvIter* it = lilv_nodes_begin(supportNodes.me); ! lilv_nodes_is_end(supportNodes.me, it); it = lilv_nodes_next(supportNodes.me, it))
  830. {
  831. const Lilv::Node node(lilv_nodes_get(supportNodes.me, it));
  832. CARLA_SAFE_ASSERT_CONTINUE(node.is_uri());
  833. /**/ if (node.equals(lv2World.midi_event))
  834. rdfPort->Types |= LV2_PORT_DATA_MIDI_EVENT;
  835. else if (node.equals(lv2World.patch_message))
  836. rdfPort->Types |= LV2_PORT_DATA_PATCH_MESSAGE;
  837. else if (node.equals(lv2World.time_position))
  838. rdfPort->Types |= LV2_PORT_DATA_TIME_POSITION;
  839. #if 0
  840. // something new we don't support yet?
  841. else if (std::strstr(node.as_uri(), "lv2plug.in/") != nullptr)
  842. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is of atom type but has unsupported data '%s'", uri, rdfPort->Name, node.as_uri());
  843. #endif
  844. }
  845. lilv_nodes_free(const_cast<LilvNodes*>(bufferTypeNodes.me));
  846. lilv_nodes_free(const_cast<LilvNodes*>(supportNodes.me));
  847. }
  848. else if (lilvPort.is_a(lv2World.port_event))
  849. {
  850. rdfPort->Types |= LV2_PORT_EVENT;
  851. bool supported = false;
  852. if (lilvPort.supports_event(lv2World.midi_event))
  853. {
  854. rdfPort->Types |= LV2_PORT_DATA_MIDI_EVENT;
  855. supported = true;
  856. }
  857. if (lilvPort.supports_event(lv2World.patch_message))
  858. {
  859. rdfPort->Types |= LV2_PORT_DATA_PATCH_MESSAGE;
  860. supported = true;
  861. }
  862. if (lilvPort.supports_event(lv2World.time_position))
  863. {
  864. rdfPort->Types |= LV2_PORT_DATA_TIME_POSITION;
  865. supported = true;
  866. }
  867. if (! supported)
  868. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is of event type but has unsupported data", uri, rdfPort->Name);
  869. }
  870. else if (lilvPort.is_a(lv2World.port_midi))
  871. {
  872. rdfPort->Types |= LV2_PORT_MIDI_LL;
  873. rdfPort->Types |= LV2_PORT_DATA_MIDI_EVENT;
  874. }
  875. else
  876. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is of unkown data type", uri, rdfPort->Name);
  877. }
  878. // --------------------------------------------------------------------------------------------------------
  879. // Set Port Properties
  880. {
  881. if (lilvPort.has_property(lv2World.pprop_optional))
  882. rdfPort->Properties |= LV2_PORT_OPTIONAL;
  883. if (lilvPort.has_property(lv2World.pprop_enumeration))
  884. rdfPort->Properties |= LV2_PORT_ENUMERATION;
  885. if (lilvPort.has_property(lv2World.pprop_integer))
  886. rdfPort->Properties |= LV2_PORT_INTEGER;
  887. if (lilvPort.has_property(lv2World.pprop_sampleRate))
  888. rdfPort->Properties |= LV2_PORT_SAMPLE_RATE;
  889. if (lilvPort.has_property(lv2World.pprop_toggled))
  890. rdfPort->Properties |= LV2_PORT_TOGGLED;
  891. if (lilvPort.has_property(lv2World.pprop_artifacts))
  892. rdfPort->Properties |= LV2_PORT_CAUSES_ARTIFACTS;
  893. if (lilvPort.has_property(lv2World.pprop_continuousCV))
  894. rdfPort->Properties |= LV2_PORT_CONTINUOUS_CV;
  895. if (lilvPort.has_property(lv2World.pprop_discreteCV))
  896. rdfPort->Properties |= LV2_PORT_DISCRETE_CV;
  897. if (lilvPort.has_property(lv2World.pprop_expensive))
  898. rdfPort->Properties |= LV2_PORT_EXPENSIVE;
  899. if (lilvPort.has_property(lv2World.pprop_strictBounds))
  900. rdfPort->Properties |= LV2_PORT_STRICT_BOUNDS;
  901. if (lilvPort.has_property(lv2World.pprop_logarithmic))
  902. rdfPort->Properties |= LV2_PORT_LOGARITHMIC;
  903. if (lilvPort.has_property(lv2World.pprop_notAutomatic))
  904. rdfPort->Properties |= LV2_PORT_NOT_AUTOMATIC;
  905. if (lilvPort.has_property(lv2World.pprop_notOnGUI))
  906. rdfPort->Properties |= LV2_PORT_NOT_ON_GUI;
  907. if (lilvPort.has_property(lv2World.pprop_trigger))
  908. rdfPort->Properties |= LV2_PORT_TRIGGER;
  909. if (lilvPort.has_property(lv2World.pprop_nonAutomable))
  910. rdfPort->Properties |= LV2_PORT_NON_AUTOMABLE;
  911. if (lilvPort.has_property(lv2World.reportsLatency))
  912. rdfPort->Designation = LV2_PORT_DESIGNATION_LATENCY;
  913. // no port properties set, check if using old/invalid ones
  914. if (rdfPort->Properties == 0x0)
  915. {
  916. const Lilv::Node oldPropArtifacts(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#causesArtifacts"));
  917. const Lilv::Node oldPropContinuousCV(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#continuousCV"));
  918. const Lilv::Node oldPropDiscreteCV(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#discreteCV"));
  919. const Lilv::Node oldPropExpensive(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#expensive"));
  920. const Lilv::Node oldPropStrictBounds(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#hasStrictBounds"));
  921. const Lilv::Node oldPropLogarithmic(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#logarithmic"));
  922. const Lilv::Node oldPropNotAutomatic(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#notAutomatic"));
  923. const Lilv::Node oldPropNotOnGUI(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#notOnGUI"));
  924. const Lilv::Node oldPropTrigger(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#trigger"));
  925. if (lilvPort.has_property(oldPropArtifacts))
  926. {
  927. rdfPort->Properties |= LV2_PORT_CAUSES_ARTIFACTS;
  928. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'causesArtifacts'", uri, rdfPort->Name);
  929. }
  930. if (lilvPort.has_property(oldPropContinuousCV))
  931. {
  932. rdfPort->Properties |= LV2_PORT_CONTINUOUS_CV;
  933. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'continuousCV'", uri, rdfPort->Name);
  934. }
  935. if (lilvPort.has_property(oldPropDiscreteCV))
  936. {
  937. rdfPort->Properties |= LV2_PORT_DISCRETE_CV;
  938. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'discreteCV'", uri, rdfPort->Name);
  939. }
  940. if (lilvPort.has_property(oldPropExpensive))
  941. {
  942. rdfPort->Properties |= LV2_PORT_EXPENSIVE;
  943. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'expensive'", uri, rdfPort->Name);
  944. }
  945. if (lilvPort.has_property(oldPropStrictBounds))
  946. {
  947. rdfPort->Properties |= LV2_PORT_STRICT_BOUNDS;
  948. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'hasStrictBounds'", uri, rdfPort->Name);
  949. }
  950. if (lilvPort.has_property(oldPropLogarithmic))
  951. {
  952. rdfPort->Properties |= LV2_PORT_LOGARITHMIC;
  953. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'logarithmic'", uri, rdfPort->Name);
  954. }
  955. if (lilvPort.has_property(oldPropNotAutomatic))
  956. {
  957. rdfPort->Properties |= LV2_PORT_NOT_AUTOMATIC;
  958. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'notAutomatic'", uri, rdfPort->Name);
  959. }
  960. if (lilvPort.has_property(oldPropNotOnGUI))
  961. {
  962. rdfPort->Properties |= LV2_PORT_NOT_ON_GUI;
  963. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'notOnGUI'", uri, rdfPort->Name);
  964. }
  965. if (lilvPort.has_property(oldPropTrigger))
  966. {
  967. rdfPort->Properties |= LV2_PORT_TRIGGER;
  968. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'trigger'", uri, rdfPort->Name);
  969. }
  970. }
  971. }
  972. // --------------------------------------------------------------------------------------------------------
  973. // Set Port Designation
  974. {
  975. if (LilvNode* const designationNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.designation.me))
  976. {
  977. if (const char* const designation = lilv_node_as_string(designationNode))
  978. {
  979. /**/ if (std::strcmp(designation, LV2_CORE__control) == 0)
  980. rdfPort->Designation = LV2_PORT_DESIGNATION_CONTROL;
  981. else if (std::strcmp(designation, LV2_CORE__enabled) == 0)
  982. rdfPort->Designation = LV2_PORT_DESIGNATION_ENABLED;
  983. else if (std::strcmp(designation, LV2_CORE__freeWheeling) == 0)
  984. rdfPort->Designation = LV2_PORT_DESIGNATION_FREEWHEELING;
  985. else if (std::strcmp(designation, LV2_CORE__latency) == 0)
  986. rdfPort->Designation = LV2_PORT_DESIGNATION_LATENCY;
  987. else if (std::strcmp(designation, LV2_PARAMETERS__sampleRate) == 0)
  988. rdfPort->Designation = LV2_PORT_DESIGNATION_SAMPLE_RATE;
  989. else if (std::strcmp(designation, LV2_TIME__bar) == 0)
  990. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BAR;
  991. else if (std::strcmp(designation, LV2_TIME__barBeat) == 0)
  992. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BAR_BEAT;
  993. else if (std::strcmp(designation, LV2_TIME__beat) == 0)
  994. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEAT;
  995. else if (std::strcmp(designation, LV2_TIME__beatUnit) == 0)
  996. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEAT_UNIT;
  997. else if (std::strcmp(designation, LV2_TIME__beatsPerBar) == 0)
  998. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEATS_PER_BAR;
  999. else if (std::strcmp(designation, LV2_TIME__beatsPerMinute) == 0)
  1000. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEATS_PER_MINUTE;
  1001. else if (std::strcmp(designation, LV2_TIME__frame) == 0)
  1002. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_FRAME;
  1003. else if (std::strcmp(designation, LV2_TIME__framesPerSecond) == 0)
  1004. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_FRAMES_PER_SECOND;
  1005. else if (std::strcmp(designation, LV2_TIME__speed) == 0)
  1006. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_SPEED;
  1007. else if (std::strcmp(designation, LV2_KXSTUDIO_PROPERTIES__TimePositionTicksPerBeat) == 0)
  1008. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_TICKS_PER_BEAT;
  1009. else if (std::strncmp(designation, LV2_PARAMETERS_PREFIX, std::strlen(LV2_PARAMETERS_PREFIX)) == 0)
  1010. pass();
  1011. else if (std::strncmp(designation, LV2_PORT_GROUPS_PREFIX, std::strlen(LV2_PORT_GROUPS_PREFIX)) == 0)
  1012. pass();
  1013. else
  1014. carla_stderr("lv2_rdf_new(\"%s\") - got unknown port designation '%s'", uri, designation);
  1015. }
  1016. lilv_node_free(designationNode);
  1017. }
  1018. }
  1019. // --------------------------------------------------------------------------------------------------------
  1020. // Set Port MIDI Map
  1021. {
  1022. if (LilvNode* const midiMapNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.mm_defaultControl.me))
  1023. {
  1024. if (lilv_node_is_blank(midiMapNode))
  1025. {
  1026. Lilv::Nodes midiMapTypeNodes(lv2World.find_nodes(midiMapNode, lv2World.mm_controlType, nullptr));
  1027. Lilv::Nodes midiMapNumberNodes(lv2World.find_nodes(midiMapNode, lv2World.mm_controlNumber, nullptr));
  1028. if (midiMapTypeNodes.size() == 1 && midiMapNumberNodes.size() == 1)
  1029. {
  1030. if (const char* const midiMapType = midiMapTypeNodes.get_first().as_string())
  1031. {
  1032. /**/ if (std::strcmp(midiMapType, LV2_MIDI_Map__CC) == 0)
  1033. rdfPort->MidiMap.Type = LV2_PORT_MIDI_MAP_CC;
  1034. else if (std::strcmp(midiMapType, LV2_MIDI_Map__NRPN) == 0)
  1035. rdfPort->MidiMap.Type = LV2_PORT_MIDI_MAP_NRPN;
  1036. else
  1037. carla_stderr("lv2_rdf_new(\"%s\") - got unknown port Midi-Map type '%s'", uri, midiMapType);
  1038. rdfPort->MidiMap.Number = static_cast<uint32_t>(midiMapNumberNodes.get_first().as_int());
  1039. }
  1040. }
  1041. lilv_nodes_free(const_cast<LilvNodes*>(midiMapTypeNodes.me));
  1042. lilv_nodes_free(const_cast<LilvNodes*>(midiMapNumberNodes.me));
  1043. }
  1044. lilv_node_free(midiMapNode);
  1045. }
  1046. // TODO - also check using new official MIDI API too
  1047. }
  1048. // --------------------------------------------------------------------------------------------------------
  1049. // Set Port Points
  1050. {
  1051. if (LilvNode* const defNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.value_default.me))
  1052. {
  1053. rdfPort->Points.Hints |= LV2_PORT_POINT_DEFAULT;
  1054. rdfPort->Points.Default = lilv_node_as_float(defNode);
  1055. lilv_node_free(defNode);
  1056. }
  1057. if (LilvNode* const minNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.value_minimum.me))
  1058. {
  1059. rdfPort->Points.Hints |= LV2_PORT_POINT_MINIMUM;
  1060. rdfPort->Points.Minimum = lilv_node_as_float(minNode);
  1061. lilv_node_free(minNode);
  1062. }
  1063. if (LilvNode* const maxNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.value_maximum.me))
  1064. {
  1065. rdfPort->Points.Hints |= LV2_PORT_POINT_MAXIMUM;
  1066. rdfPort->Points.Maximum = lilv_node_as_float(maxNode);
  1067. lilv_node_free(maxNode);
  1068. }
  1069. }
  1070. // --------------------------------------------------------------------------------------------------------
  1071. // Set Port Unit
  1072. {
  1073. if (LilvNode* const unitUnitNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.unit_unit.me))
  1074. {
  1075. if (lilv_node_is_uri(unitUnitNode))
  1076. {
  1077. if (const char* const unitUnit = lilv_node_as_uri(unitUnitNode))
  1078. {
  1079. rdfPort->Unit.Hints |= LV2_PORT_UNIT_UNIT;
  1080. /**/ if (std::strcmp(unitUnit, LV2_UNITS__bar) == 0)
  1081. rdfPort->Unit.Unit = LV2_PORT_UNIT_BAR;
  1082. else if (std::strcmp(unitUnit, LV2_UNITS__beat) == 0)
  1083. rdfPort->Unit.Unit = LV2_PORT_UNIT_BEAT;
  1084. else if (std::strcmp(unitUnit, LV2_UNITS__bpm) == 0)
  1085. rdfPort->Unit.Unit = LV2_PORT_UNIT_BPM;
  1086. else if (std::strcmp(unitUnit, LV2_UNITS__cent) == 0)
  1087. rdfPort->Unit.Unit = LV2_PORT_UNIT_CENT;
  1088. else if (std::strcmp(unitUnit, LV2_UNITS__cm) == 0)
  1089. rdfPort->Unit.Unit = LV2_PORT_UNIT_CM;
  1090. else if (std::strcmp(unitUnit, LV2_UNITS__coef) == 0)
  1091. rdfPort->Unit.Unit = LV2_PORT_UNIT_COEF;
  1092. else if (std::strcmp(unitUnit, LV2_UNITS__db) == 0)
  1093. rdfPort->Unit.Unit = LV2_PORT_UNIT_DB;
  1094. else if (std::strcmp(unitUnit, LV2_UNITS__degree) == 0)
  1095. rdfPort->Unit.Unit = LV2_PORT_UNIT_DEGREE;
  1096. else if (std::strcmp(unitUnit, LV2_UNITS__frame) == 0)
  1097. rdfPort->Unit.Unit = LV2_PORT_UNIT_FRAME;
  1098. else if (std::strcmp(unitUnit, LV2_UNITS__hz) == 0)
  1099. rdfPort->Unit.Unit = LV2_PORT_UNIT_HZ;
  1100. else if (std::strcmp(unitUnit, LV2_UNITS__inch) == 0)
  1101. rdfPort->Unit.Unit = LV2_PORT_UNIT_INCH;
  1102. else if (std::strcmp(unitUnit, LV2_UNITS__khz) == 0)
  1103. rdfPort->Unit.Unit = LV2_PORT_UNIT_KHZ;
  1104. else if (std::strcmp(unitUnit, LV2_UNITS__km) == 0)
  1105. rdfPort->Unit.Unit = LV2_PORT_UNIT_KM;
  1106. else if (std::strcmp(unitUnit, LV2_UNITS__m) == 0)
  1107. rdfPort->Unit.Unit = LV2_PORT_UNIT_M;
  1108. else if (std::strcmp(unitUnit, LV2_UNITS__mhz) == 0)
  1109. rdfPort->Unit.Unit = LV2_PORT_UNIT_MHZ;
  1110. else if (std::strcmp(unitUnit, LV2_UNITS__midiNote) == 0)
  1111. rdfPort->Unit.Unit = LV2_PORT_UNIT_MIDINOTE;
  1112. else if (std::strcmp(unitUnit, LV2_UNITS__mile) == 0)
  1113. rdfPort->Unit.Unit = LV2_PORT_UNIT_MILE;
  1114. else if (std::strcmp(unitUnit, LV2_UNITS__min) == 0)
  1115. rdfPort->Unit.Unit = LV2_PORT_UNIT_MIN;
  1116. else if (std::strcmp(unitUnit, LV2_UNITS__mm) == 0)
  1117. rdfPort->Unit.Unit = LV2_PORT_UNIT_MM;
  1118. else if (std::strcmp(unitUnit, LV2_UNITS__ms) == 0)
  1119. rdfPort->Unit.Unit = LV2_PORT_UNIT_MS;
  1120. else if (std::strcmp(unitUnit, LV2_UNITS__oct) == 0)
  1121. rdfPort->Unit.Unit = LV2_PORT_UNIT_OCT;
  1122. else if (std::strcmp(unitUnit, LV2_UNITS__pc) == 0)
  1123. rdfPort->Unit.Unit = LV2_PORT_UNIT_PC;
  1124. else if (std::strcmp(unitUnit, LV2_UNITS__s) == 0)
  1125. rdfPort->Unit.Unit = LV2_PORT_UNIT_S;
  1126. else if (std::strcmp(unitUnit, LV2_UNITS__semitone12TET) == 0)
  1127. rdfPort->Unit.Unit = LV2_PORT_UNIT_SEMITONE;
  1128. else
  1129. carla_stderr("lv2_rdf_new(\"%s\") - got unknown unit unit '%s'", uri, unitUnit);
  1130. }
  1131. }
  1132. if (LilvNode* const unitNameNode = lilv_world_get(lv2World.me, unitUnitNode, lv2World.unit_name.me, nullptr))
  1133. {
  1134. if (const char* const unitName = lilv_node_as_string(unitNameNode))
  1135. {
  1136. rdfPort->Unit.Hints |= LV2_PORT_UNIT_NAME;
  1137. rdfPort->Unit.Name = carla_strdup(unitName);
  1138. }
  1139. lilv_node_free(unitNameNode);
  1140. }
  1141. if (LilvNode* const unitRenderNode = lilv_world_get(lv2World.me, unitUnitNode, lv2World.unit_render.me, nullptr))
  1142. {
  1143. if (const char* const unitRender = lilv_node_as_string(unitRenderNode))
  1144. {
  1145. rdfPort->Unit.Hints |= LV2_PORT_UNIT_RENDER;
  1146. rdfPort->Unit.Render = carla_strdup(unitRender);
  1147. }
  1148. lilv_node_free(unitRenderNode);
  1149. }
  1150. if (LilvNode* const unitSymbolNode = lilv_world_get(lv2World.me, unitUnitNode, lv2World.unit_symbol.me, nullptr))
  1151. {
  1152. if (const char* const unitSymbol = lilv_node_as_string(unitSymbolNode))
  1153. {
  1154. rdfPort->Unit.Hints |= LV2_PORT_UNIT_SYMBOL;
  1155. rdfPort->Unit.Symbol = carla_strdup(unitSymbol);
  1156. }
  1157. lilv_node_free(unitSymbolNode);
  1158. }
  1159. lilv_node_free(unitUnitNode);
  1160. }
  1161. }
  1162. // --------------------------------------------------------------------------------------------------------
  1163. // Set Port Minimum Size
  1164. {
  1165. if (LilvNode* const minimumSizeNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.rz_minSize.me))
  1166. {
  1167. const int minimumSize(lilv_node_as_int(minimumSizeNode));
  1168. if (minimumSize > 0)
  1169. rdfPort->MinimumSize = static_cast<uint32_t>(minimumSize);
  1170. else
  1171. carla_safe_assert_int("minimumSize > 0", __FILE__, __LINE__, minimumSize);
  1172. lilv_node_free(minimumSizeNode);
  1173. }
  1174. }
  1175. // --------------------------------------------------------------------------------------------------------
  1176. // Set Port Scale Points
  1177. {
  1178. Lilv::ScalePoints lilvScalePoints(lilvPort.get_scale_points());
  1179. if (lilvScalePoints.size() > 0)
  1180. {
  1181. rdfPort->ScalePointCount = lilvScalePoints.size();
  1182. rdfPort->ScalePoints = new LV2_RDF_PortScalePoint[rdfPort->ScalePointCount];
  1183. // get all scalepoints and sort them by value
  1184. LilvScalePointMap sortedpoints;
  1185. LILV_FOREACH(scale_points, it, lilvScalePoints)
  1186. {
  1187. Lilv::ScalePoint lilvScalePoint(lilvScalePoints.get(it));
  1188. CARLA_SAFE_ASSERT_CONTINUE(lilvScalePoint.get_label() != nullptr);
  1189. if (const LilvNode* const valuenode = lilvScalePoint.get_value())
  1190. {
  1191. const double valueid = lilv_node_as_float(valuenode);
  1192. sortedpoints[valueid] = lilvScalePoint.me;
  1193. }
  1194. }
  1195. // now safe to store, sorted by using std::map
  1196. uint32_t h = 0;
  1197. for (LilvScalePointMap::iterator it=sortedpoints.begin(), end=sortedpoints.end(); it != end; ++it)
  1198. {
  1199. CARLA_SAFE_ASSERT_BREAK(h < rdfPort->ScalePointCount);
  1200. LV2_RDF_PortScalePoint* const rdfScalePoint(&rdfPort->ScalePoints[h++]);
  1201. const LilvScalePoint* const scalepoint = it->second;
  1202. const LilvNode* const xlabel = lilv_scale_point_get_label(scalepoint);
  1203. const LilvNode* const xvalue = lilv_scale_point_get_value(scalepoint);
  1204. rdfScalePoint->Label = carla_strdup(lilv_node_as_string(xlabel));
  1205. rdfScalePoint->Value = lilv_node_as_float(xvalue);
  1206. }
  1207. }
  1208. lilv_nodes_free(const_cast<LilvNodes*>(lilvScalePoints.me));
  1209. }
  1210. }
  1211. }
  1212. // ----------------------------------------------------------------------------------------------------------------
  1213. // Set Plugin Presets
  1214. if (loadPresets)
  1215. {
  1216. Lilv::Nodes presetNodes(lilvPlugin.get_related(lv2World.preset_preset));
  1217. if (presetNodes.size() > 0)
  1218. {
  1219. // create a list of preset URIs (for sorting and unique-ness)
  1220. #ifdef USE_QT
  1221. QStringList presetListURIs;
  1222. LILV_FOREACH(nodes, it, presetNodes)
  1223. {
  1224. Lilv::Node presetNode(presetNodes.get(it));
  1225. QString presetURI(presetNode.as_uri());
  1226. if (! (presetURI.trimmed().isEmpty() || presetListURIs.contains(presetURI)))
  1227. presetListURIs.append(presetURI);
  1228. }
  1229. presetListURIs.sort();
  1230. rdfDescriptor->PresetCount = static_cast<uint32_t>(presetListURIs.count());
  1231. #else
  1232. water::StringArray presetListURIs;
  1233. LILV_FOREACH(nodes, it, presetNodes)
  1234. {
  1235. Lilv::Node presetNode(presetNodes.get(it));
  1236. water::String presetURI(presetNode.as_uri());
  1237. if (presetURI.trim().isNotEmpty())
  1238. presetListURIs.addIfNotAlreadyThere(presetURI);
  1239. }
  1240. presetListURIs.sortNatural();
  1241. rdfDescriptor->PresetCount = static_cast<uint32_t>(presetListURIs.size());
  1242. #endif
  1243. // create presets with unique URIs
  1244. rdfDescriptor->Presets = new LV2_RDF_Preset[rdfDescriptor->PresetCount];
  1245. // set preset data
  1246. LILV_FOREACH(nodes, it, presetNodes)
  1247. {
  1248. Lilv::Node presetNode(presetNodes.get(it));
  1249. const char* const presetURI(presetNode.as_uri());
  1250. CARLA_SAFE_ASSERT_CONTINUE(presetURI != nullptr && presetURI[0] != '\0');
  1251. // try to find label without loading the preset resource first
  1252. Lilv::Nodes presetLabelNodes(lv2World.find_nodes(presetNode, lv2World.rdfs_label, nullptr));
  1253. // failed, try loading resource
  1254. if (presetLabelNodes.size() == 0)
  1255. {
  1256. // if loading resource fails, skip this preset
  1257. if (lv2World.load_resource(presetNode) == -1)
  1258. continue;
  1259. // ok, let's try again
  1260. presetLabelNodes = lv2World.find_nodes(presetNode, lv2World.rdfs_label, nullptr);
  1261. }
  1262. if (presetLabelNodes.size() > 0)
  1263. {
  1264. #ifdef USE_QT
  1265. const int index(presetListURIs.indexOf(QString(presetURI)));
  1266. #else
  1267. const int index(presetListURIs.indexOf(water::String(presetURI)));
  1268. #endif
  1269. CARLA_SAFE_ASSERT_CONTINUE(index >= 0 && index < static_cast<int>(rdfDescriptor->PresetCount));
  1270. LV2_RDF_Preset* const rdfPreset(&rdfDescriptor->Presets[index]);
  1271. // ---------------------------------------------------
  1272. // Set Preset Information
  1273. rdfPreset->URI = carla_strdup(presetURI);
  1274. if (const char* const label = presetLabelNodes.get_first().as_string())
  1275. rdfPreset->Label = carla_strdup(label);
  1276. lilv_nodes_free(const_cast<LilvNodes*>(presetLabelNodes.me));
  1277. }
  1278. }
  1279. }
  1280. lilv_nodes_free(const_cast<LilvNodes*>(presetNodes.me));
  1281. }
  1282. // ----------------------------------------------------------------------------------------------------------------
  1283. // Set Plugin Features
  1284. {
  1285. Lilv::Nodes lilvFeatureNodes(lilvPlugin.get_supported_features());
  1286. if (lilvFeatureNodes.size() > 0)
  1287. {
  1288. Lilv::Nodes lilvFeatureNodesR(lilvPlugin.get_required_features());
  1289. rdfDescriptor->FeatureCount = lilvFeatureNodes.size();
  1290. rdfDescriptor->Features = new LV2_RDF_Feature[rdfDescriptor->FeatureCount];
  1291. uint32_t h = 0;
  1292. LILV_FOREACH(nodes, it, lilvFeatureNodes)
  1293. {
  1294. CARLA_SAFE_ASSERT_BREAK(h < rdfDescriptor->FeatureCount);
  1295. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(it));
  1296. LV2_RDF_Feature* const rdfFeature(&rdfDescriptor->Features[h++]);
  1297. rdfFeature->Required = lilvFeatureNodesR.contains(lilvFeatureNode);
  1298. if (const char* const featureURI = lilvFeatureNode.as_uri())
  1299. rdfFeature->URI = carla_strdup(featureURI);
  1300. else
  1301. rdfFeature->URI = nullptr;
  1302. }
  1303. lilv_nodes_free(const_cast<LilvNodes*>(lilvFeatureNodesR.me));
  1304. }
  1305. lilv_nodes_free(const_cast<LilvNodes*>(lilvFeatureNodes.me));
  1306. }
  1307. // ----------------------------------------------------------------------------------------------------------------
  1308. // Set Plugin Extensions
  1309. {
  1310. Lilv::Nodes lilvExtensionDataNodes(lilvPlugin.get_extension_data());
  1311. if (lilvExtensionDataNodes.size() > 0)
  1312. {
  1313. rdfDescriptor->ExtensionCount = lilvExtensionDataNodes.size();
  1314. rdfDescriptor->Extensions = new LV2_URI[rdfDescriptor->ExtensionCount];
  1315. uint32_t h = 0;
  1316. LILV_FOREACH(nodes, it, lilvExtensionDataNodes)
  1317. {
  1318. CARLA_SAFE_ASSERT_BREAK(h < rdfDescriptor->ExtensionCount);
  1319. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(it));
  1320. LV2_URI* const rdfExtension(&rdfDescriptor->Extensions[h++]);
  1321. if (lilvExtensionDataNode.is_uri())
  1322. {
  1323. if (const char* const extURI = lilvExtensionDataNode.as_uri())
  1324. {
  1325. *rdfExtension = carla_strdup(extURI);
  1326. continue;
  1327. }
  1328. }
  1329. *rdfExtension = nullptr;
  1330. }
  1331. for (uint32_t x=h; x < rdfDescriptor->ExtensionCount; ++x)
  1332. rdfDescriptor->Extensions[x] = nullptr;
  1333. }
  1334. lilv_nodes_free(const_cast<LilvNodes*>(lilvExtensionDataNodes.me));
  1335. }
  1336. // ----------------------------------------------------------------------------------------------------------------
  1337. // Set Plugin UIs
  1338. {
  1339. Lilv::UIs lilvUIs(lilvPlugin.get_uis());
  1340. if (lilvUIs.size() > 0)
  1341. {
  1342. rdfDescriptor->UICount = lilvUIs.size();
  1343. rdfDescriptor->UIs = new LV2_RDF_UI[rdfDescriptor->UICount];
  1344. uint32_t h = 0;
  1345. LILV_FOREACH(uis, it, lilvUIs)
  1346. {
  1347. CARLA_SAFE_ASSERT_BREAK(h < rdfDescriptor->UICount);
  1348. Lilv::UI lilvUI(lilvUIs.get(it));
  1349. LV2_RDF_UI* const rdfUI(&rdfDescriptor->UIs[h++]);
  1350. // ----------------------------------------------------------------------------------------------------
  1351. // Set UI Type
  1352. /**/ if (lilvUI.is_a(lv2World.ui_gtk2))
  1353. rdfUI->Type = LV2_UI_GTK2;
  1354. else if (lilvUI.is_a(lv2World.ui_gtk3))
  1355. rdfUI->Type = LV2_UI_GTK3;
  1356. else if (lilvUI.is_a(lv2World.ui_qt4))
  1357. rdfUI->Type = LV2_UI_QT4;
  1358. else if (lilvUI.is_a(lv2World.ui_qt5))
  1359. rdfUI->Type = LV2_UI_QT5;
  1360. else if (lilvUI.is_a(lv2World.ui_cocoa))
  1361. rdfUI->Type = LV2_UI_COCOA;
  1362. else if (lilvUI.is_a(lv2World.ui_windows))
  1363. rdfUI->Type = LV2_UI_WINDOWS;
  1364. else if (lilvUI.is_a(lv2World.ui_x11))
  1365. rdfUI->Type = LV2_UI_X11;
  1366. else if (lilvUI.is_a(lv2World.ui_external))
  1367. rdfUI->Type = LV2_UI_EXTERNAL;
  1368. else if (lilvUI.is_a(lv2World.ui_externalOld))
  1369. rdfUI->Type = LV2_UI_OLD_EXTERNAL;
  1370. else if (lilvUI.is_a(lv2World.ui_externalOld2))
  1371. pass();
  1372. else
  1373. carla_stderr("lv2_rdf_new(\"%s\") - UI '%s' is of unknown type", uri, lilvUI.get_uri().as_uri());
  1374. // ----------------------------------------------------------------------------------------------------
  1375. // Set UI Information
  1376. {
  1377. if (const char* const uiURI = lilvUI.get_uri().as_uri())
  1378. rdfUI->URI = carla_strdup(uiURI);
  1379. if (const char* const uiBinary = lilvUI.get_binary_uri().as_string())
  1380. rdfUI->Binary = carla_strdup_free(lilv_file_uri_parse(uiBinary, nullptr));
  1381. if (const char* const uiBundle = lilvUI.get_bundle_uri().as_string())
  1382. rdfUI->Bundle = carla_strdup_free(lilv_file_uri_parse(uiBundle, nullptr));
  1383. }
  1384. // ----------------------------------------------------------------------------------------------------
  1385. // Set UI Features
  1386. {
  1387. Lilv::Nodes lilvFeatureNodes(lilvUI.get_supported_features());
  1388. if (lilvFeatureNodes.size() > 0)
  1389. {
  1390. Lilv::Nodes lilvFeatureNodesR(lilvUI.get_required_features());
  1391. rdfUI->FeatureCount = lilvFeatureNodes.size();
  1392. rdfUI->Features = new LV2_RDF_Feature[rdfUI->FeatureCount];
  1393. uint32_t h2 = 0;
  1394. LILV_FOREACH(nodes, it2, lilvFeatureNodes)
  1395. {
  1396. CARLA_SAFE_ASSERT_BREAK(h2 < rdfUI->FeatureCount);
  1397. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(it2));
  1398. LV2_RDF_Feature* const rdfFeature(&rdfUI->Features[h2++]);
  1399. rdfFeature->Required = lilvFeatureNodesR.contains(lilvFeatureNode);
  1400. if (const char* const featureURI = lilvFeatureNode.as_uri())
  1401. rdfFeature->URI = carla_strdup(featureURI);
  1402. else
  1403. rdfFeature->URI = nullptr;
  1404. }
  1405. lilv_nodes_free(const_cast<LilvNodes*>(lilvFeatureNodesR.me));
  1406. }
  1407. lilv_nodes_free(const_cast<LilvNodes*>(lilvFeatureNodes.me));
  1408. }
  1409. // ----------------------------------------------------------------------------------------------------
  1410. // Set UI Extensions
  1411. {
  1412. Lilv::Nodes lilvExtensionDataNodes(lilvUI.get_extension_data());
  1413. if (lilvExtensionDataNodes.size() > 0)
  1414. {
  1415. rdfUI->ExtensionCount = lilvExtensionDataNodes.size();
  1416. rdfUI->Extensions = new LV2_URI[rdfUI->ExtensionCount];
  1417. uint32_t h2 = 0;
  1418. LILV_FOREACH(nodes, it2, lilvExtensionDataNodes)
  1419. {
  1420. CARLA_SAFE_ASSERT_BREAK(h2 < rdfUI->ExtensionCount);
  1421. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(it2));
  1422. LV2_URI* const rdfExtension(&rdfUI->Extensions[h2++]);
  1423. if (lilvExtensionDataNode.is_uri())
  1424. {
  1425. if (const char* const extURI = lilvExtensionDataNode.as_uri())
  1426. {
  1427. *rdfExtension = carla_strdup(extURI);
  1428. continue;
  1429. }
  1430. }
  1431. *rdfExtension = nullptr;
  1432. }
  1433. for (uint32_t x2=h2; x2 < rdfUI->ExtensionCount; ++x2)
  1434. rdfUI->Extensions[x2] = nullptr;
  1435. }
  1436. lilv_nodes_free(const_cast<LilvNodes*>(lilvExtensionDataNodes.me));
  1437. }
  1438. }
  1439. }
  1440. lilv_nodes_free(const_cast<LilvNodes*>(lilvUIs.me));
  1441. }
  1442. return rdfDescriptor;
  1443. }
  1444. // --------------------------------------------------------------------------------------------------------------------
  1445. // Check if we support a plugin port
  1446. static inline
  1447. bool is_lv2_port_supported(const LV2_Property types) noexcept
  1448. {
  1449. if (LV2_IS_PORT_CONTROL(types))
  1450. return true;
  1451. if (LV2_IS_PORT_AUDIO(types))
  1452. return true;
  1453. if (LV2_IS_PORT_CV(types))
  1454. return true;
  1455. if (LV2_IS_PORT_ATOM_SEQUENCE(types))
  1456. return true;
  1457. if (LV2_IS_PORT_EVENT(types))
  1458. return true;
  1459. if (LV2_IS_PORT_MIDI_LL(types))
  1460. return true;
  1461. return false;
  1462. }
  1463. // --------------------------------------------------------------------------------------------------------------------
  1464. // Check if we support a plugin feature
  1465. static inline
  1466. bool is_lv2_feature_supported(const LV2_URI uri) noexcept
  1467. {
  1468. CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0', false);
  1469. if (std::strcmp(uri, LV2_BUF_SIZE__boundedBlockLength) == 0)
  1470. return true;
  1471. if (std::strcmp(uri, LV2_BUF_SIZE__fixedBlockLength) == 0)
  1472. return true;
  1473. if (std::strcmp(uri, LV2_BUF_SIZE__powerOf2BlockLength) == 0)
  1474. return true;
  1475. if (std::strcmp(uri, LV2_CORE__hardRTCapable) == 0)
  1476. return true;
  1477. if (std::strcmp(uri, LV2_CORE__inPlaceBroken) == 0)
  1478. return true;
  1479. if (std::strcmp(uri, LV2_CORE__isLive) == 0)
  1480. return true;
  1481. if (std::strcmp(uri, LV2_EVENT_URI) == 0)
  1482. return true;
  1483. if (std::strcmp(uri, LV2_LOG__log) == 0)
  1484. return true;
  1485. if (std::strcmp(uri, LV2_OPTIONS__options) == 0)
  1486. return true;
  1487. if (std::strcmp(uri, LV2_PROGRAMS__Host) == 0)
  1488. return true;
  1489. if (std::strcmp(uri, LV2_RESIZE_PORT__resize) == 0)
  1490. return true;
  1491. if (std::strcmp(uri, LV2_RTSAFE_MEMORY_POOL__Pool) == 0)
  1492. return true;
  1493. if (std::strcmp(uri, LV2_RTSAFE_MEMORY_POOL_DEPRECATED_URI) == 0)
  1494. return true;
  1495. if (std::strcmp(uri, LV2_STATE__loadDefaultState) == 0)
  1496. return true;
  1497. if (std::strcmp(uri, LV2_STATE__makePath) == 0)
  1498. return true;
  1499. if (std::strcmp(uri, LV2_STATE__mapPath) == 0)
  1500. return true;
  1501. if (std::strcmp(uri, LV2_PORT_PROPS__supportsStrictBounds) == 0)
  1502. return true;
  1503. if (std::strcmp(uri, LV2_URI_MAP_URI) == 0)
  1504. return true;
  1505. if (std::strcmp(uri, LV2_URID__map) == 0)
  1506. return true;
  1507. if (std::strcmp(uri, LV2_URID__unmap) == 0)
  1508. return true;
  1509. if (std::strcmp(uri, LV2_WORKER__schedule) == 0)
  1510. return true;
  1511. return false;
  1512. }
  1513. // --------------------------------------------------------------------------------------------------------------------
  1514. // Check if we support a plugin or UI feature
  1515. static inline
  1516. bool is_lv2_ui_feature_supported(const LV2_URI uri) noexcept
  1517. {
  1518. CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0', false);
  1519. if (is_lv2_feature_supported(uri))
  1520. return true;
  1521. #ifndef BUILD_BRIDGE_UI
  1522. if (std::strcmp(uri, LV2_DATA_ACCESS_URI) == 0)
  1523. return true;
  1524. if (std::strcmp(uri, LV2_INSTANCE_ACCESS_URI) == 0)
  1525. return true;
  1526. #endif
  1527. if (std::strcmp(uri, LV2_UI__fixedSize) == 0)
  1528. return true;
  1529. if (std::strcmp(uri, LV2_UI__idleInterface) == 0)
  1530. return true;
  1531. if (std::strcmp(uri, LV2_UI__makeResident) == 0)
  1532. return true;
  1533. if (std::strcmp(uri, LV2_UI__makeSONameResident) == 0)
  1534. return true;
  1535. if (std::strcmp(uri, LV2_UI__noUserResize) == 0)
  1536. return true;
  1537. if (std::strcmp(uri, LV2_UI__parent) == 0)
  1538. return true;
  1539. if (std::strcmp(uri, LV2_UI__portMap) == 0)
  1540. return true;
  1541. if (std::strcmp(uri, LV2_UI__portSubscribe) == 0)
  1542. return true;
  1543. if (std::strcmp(uri, LV2_UI__resize) == 0)
  1544. return true;
  1545. if (std::strcmp(uri, LV2_UI__touch) == 0)
  1546. return true;
  1547. if (std::strcmp(uri, LV2_EXTERNAL_UI__Widget) == 0)
  1548. return true;
  1549. if (std::strcmp(uri, LV2_EXTERNAL_UI_DEPRECATED_URI) == 0)
  1550. return true;
  1551. return false;
  1552. }
  1553. // --------------------------------------------------------------------------------------------------------------------
  1554. #endif // CARLA_LV2_UTILS_HPP_INCLUDED