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.

2796 lines
112KB

  1. /*
  2. * Carla LV2 utils
  3. * Copyright (C) 2011-2019 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. #include "lilv/config/lilv_config.h"
  68. // enable -Wdocumentation again
  69. #if defined(__clang__) && (__clang_major__ * 100 + __clang_minor__) > 300
  70. # pragma clang diagnostic pop
  71. #endif
  72. #include "lv2_rdf.hpp"
  73. #ifdef USE_QT
  74. # include <QtCore/QStringList>
  75. #else
  76. # include "water/text/StringArray.h"
  77. #endif
  78. // used for scalepoint sorting
  79. #include <map>
  80. typedef std::map<double,const LilvScalePoint*> LilvScalePointMap;
  81. // --------------------------------------------------------------------------------------------------------------------
  82. // Define namespaces and missing prefixes
  83. #define NS_dct "http://purl.org/dc/terms/"
  84. #define NS_doap "http://usefulinc.com/ns/doap#"
  85. #define NS_rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  86. #define NS_rdfs "http://www.w3.org/2000/01/rdf-schema#"
  87. #define NS_llmm "http://ll-plugins.nongnu.org/lv2/ext/midimap#"
  88. #define NS_devp "http://lv2plug.in/ns/dev/extportinfo#"
  89. #define LV2_MIDI_Map__CC "http://ll-plugins.nongnu.org/lv2/namespace#CC"
  90. #define LV2_MIDI_Map__NRPN "http://ll-plugins.nongnu.org/lv2/namespace#NRPN"
  91. #define LV2_MIDI_LL__MidiPort "http://ll-plugins.nongnu.org/lv2/ext/MidiPort"
  92. #define LV2_UI__makeResident LV2_UI_PREFIX "makeResident"
  93. #define LV2_UI__makeSONameResident LV2_UI_PREFIX "makeSONameResident"
  94. // TODO: update LV2 headers once again
  95. #define LV2_CORE__Parameter LV2_CORE_PREFIX "Parameter" ///< http://lv2plug.in/ns/lv2core#Parameter
  96. #define LV2_CORE__enabled LV2_CORE_PREFIX "enabled" ///< http://lv2plug.in/ns/lv2core#enabled
  97. // --------------------------------------------------------------------------------------------------------------------
  98. // Custom Atom types
  99. struct LV2_Atom_MidiEvent {
  100. LV2_Atom atom; /**< Atom header. */
  101. uint8_t data[4]; /**< MIDI data (body). */
  102. };
  103. static inline
  104. uint32_t lv2_atom_total_size(const LV2_Atom_MidiEvent& midiEv)
  105. {
  106. return static_cast<uint32_t>(sizeof(LV2_Atom)) + midiEv.atom.size;
  107. }
  108. // ---------------------------------------------------------------------------------------------------------------------
  109. // -Weffc++ compat ext widget
  110. extern "C" {
  111. typedef struct _LV2_External_UI_Widget_Compat {
  112. void (*run )(struct _LV2_External_UI_Widget_Compat*);
  113. void (*show)(struct _LV2_External_UI_Widget_Compat*);
  114. void (*hide)(struct _LV2_External_UI_Widget_Compat*);
  115. _LV2_External_UI_Widget_Compat() noexcept
  116. : run(nullptr), show(nullptr), hide(nullptr) {}
  117. } LV2_External_UI_Widget_Compat;
  118. }
  119. // --------------------------------------------------------------------------------------------------------------------
  120. // Our LV2 World class
  121. class Lv2WorldClass : public Lilv::World
  122. {
  123. public:
  124. // Base Types
  125. Lilv::Node port;
  126. Lilv::Node symbol;
  127. Lilv::Node designation;
  128. Lilv::Node freeWheeling;
  129. Lilv::Node reportsLatency;
  130. // Plugin Types
  131. Lilv::Node class_allpass;
  132. Lilv::Node class_amplifier;
  133. Lilv::Node class_analyzer;
  134. Lilv::Node class_bandpass;
  135. Lilv::Node class_chorus;
  136. Lilv::Node class_comb;
  137. Lilv::Node class_compressor;
  138. Lilv::Node class_constant;
  139. Lilv::Node class_converter;
  140. Lilv::Node class_delay;
  141. Lilv::Node class_distortion;
  142. Lilv::Node class_dynamics;
  143. Lilv::Node class_eq;
  144. Lilv::Node class_envelope;
  145. Lilv::Node class_expander;
  146. Lilv::Node class_filter;
  147. Lilv::Node class_flanger;
  148. Lilv::Node class_function;
  149. Lilv::Node class_gate;
  150. Lilv::Node class_generator;
  151. Lilv::Node class_highpass;
  152. Lilv::Node class_instrument;
  153. Lilv::Node class_limiter;
  154. Lilv::Node class_lowpass;
  155. Lilv::Node class_mixer;
  156. Lilv::Node class_modulator;
  157. Lilv::Node class_multiEQ;
  158. Lilv::Node class_oscillator;
  159. Lilv::Node class_paraEQ;
  160. Lilv::Node class_phaser;
  161. Lilv::Node class_pitch;
  162. Lilv::Node class_reverb;
  163. Lilv::Node class_simulator;
  164. Lilv::Node class_spatial;
  165. Lilv::Node class_spectral;
  166. Lilv::Node class_utility;
  167. Lilv::Node class_waveshaper;
  168. // Port Types
  169. Lilv::Node port_input;
  170. Lilv::Node port_output;
  171. Lilv::Node port_control;
  172. Lilv::Node port_audio;
  173. Lilv::Node port_cv;
  174. Lilv::Node port_atom;
  175. Lilv::Node port_event;
  176. Lilv::Node port_midi;
  177. // Port Properties
  178. Lilv::Node pprop_optional;
  179. Lilv::Node pprop_enumeration;
  180. Lilv::Node pprop_integer;
  181. Lilv::Node pprop_sampleRate;
  182. Lilv::Node pprop_toggled;
  183. Lilv::Node pprop_artifacts;
  184. Lilv::Node pprop_continuousCV;
  185. Lilv::Node pprop_discreteCV;
  186. Lilv::Node pprop_expensive;
  187. Lilv::Node pprop_strictBounds;
  188. Lilv::Node pprop_logarithmic;
  189. Lilv::Node pprop_notAutomatic;
  190. Lilv::Node pprop_notOnGUI;
  191. Lilv::Node pprop_trigger;
  192. Lilv::Node pprop_nonAutomable;
  193. // Unit Hints
  194. Lilv::Node unit_name;
  195. Lilv::Node unit_render;
  196. Lilv::Node unit_symbol;
  197. Lilv::Node unit_unit;
  198. // UI Types
  199. Lilv::Node ui_gtk2;
  200. Lilv::Node ui_gtk3;
  201. Lilv::Node ui_qt4;
  202. Lilv::Node ui_qt5;
  203. Lilv::Node ui_cocoa;
  204. Lilv::Node ui_windows;
  205. Lilv::Node ui_x11;
  206. Lilv::Node ui_external;
  207. Lilv::Node ui_externalOld;
  208. Lilv::Node ui_externalOld2;
  209. // Misc
  210. Lilv::Node atom_bufferType;
  211. Lilv::Node atom_sequence;
  212. Lilv::Node atom_supports;
  213. Lilv::Node patch_writable;
  214. Lilv::Node parameter;
  215. Lilv::Node preset_preset;
  216. Lilv::Node state_state;
  217. Lilv::Node ui_portIndex;
  218. Lilv::Node ui_portNotif;
  219. Lilv::Node ui_protocol;
  220. Lilv::Node value_default;
  221. Lilv::Node value_minimum;
  222. Lilv::Node value_maximum;
  223. Lilv::Node rz_asLargeAs;
  224. Lilv::Node rz_minSize;
  225. // Port Data Types
  226. Lilv::Node midi_event;
  227. Lilv::Node patch_message;
  228. Lilv::Node time_position;
  229. // MIDI CC
  230. Lilv::Node mm_defaultControl;
  231. Lilv::Node mm_controlType;
  232. Lilv::Node mm_controlNumber;
  233. // Other
  234. Lilv::Node dct_replaces;
  235. Lilv::Node doap_license;
  236. Lilv::Node rdf_type;
  237. Lilv::Node rdfs_comment;
  238. Lilv::Node rdfs_label;
  239. Lilv::Node rdfs_range;
  240. bool needsInit;
  241. const LilvPlugins* allPlugins;
  242. const LilvPlugin** cachedPlugins;
  243. uint pluginCount;
  244. // ----------------------------------------------------------------------------------------------------------------
  245. Lv2WorldClass()
  246. : Lilv::World(),
  247. port (new_uri(LV2_CORE__port)),
  248. symbol (new_uri(LV2_CORE__symbol)),
  249. designation (new_uri(LV2_CORE__designation)),
  250. freeWheeling (new_uri(LV2_CORE__freeWheeling)),
  251. reportsLatency (new_uri(LV2_CORE__reportsLatency)),
  252. class_allpass (new_uri(LV2_CORE__AllpassPlugin)),
  253. class_amplifier (new_uri(LV2_CORE__AmplifierPlugin)),
  254. class_analyzer (new_uri(LV2_CORE__AnalyserPlugin)),
  255. class_bandpass (new_uri(LV2_CORE__BandpassPlugin)),
  256. class_chorus (new_uri(LV2_CORE__ChorusPlugin)),
  257. class_comb (new_uri(LV2_CORE__CombPlugin)),
  258. class_compressor (new_uri(LV2_CORE__CompressorPlugin)),
  259. class_constant (new_uri(LV2_CORE__ConstantPlugin)),
  260. class_converter (new_uri(LV2_CORE__ConverterPlugin)),
  261. class_delay (new_uri(LV2_CORE__DelayPlugin)),
  262. class_distortion (new_uri(LV2_CORE__DistortionPlugin)),
  263. class_dynamics (new_uri(LV2_CORE__DynamicsPlugin)),
  264. class_eq (new_uri(LV2_CORE__EQPlugin)),
  265. class_envelope (new_uri(LV2_CORE__EnvelopePlugin)),
  266. class_expander (new_uri(LV2_CORE__ExpanderPlugin)),
  267. class_filter (new_uri(LV2_CORE__FilterPlugin)),
  268. class_flanger (new_uri(LV2_CORE__FlangerPlugin)),
  269. class_function (new_uri(LV2_CORE__FunctionPlugin)),
  270. class_gate (new_uri(LV2_CORE__GatePlugin)),
  271. class_generator (new_uri(LV2_CORE__GeneratorPlugin)),
  272. class_highpass (new_uri(LV2_CORE__HighpassPlugin)),
  273. class_instrument (new_uri(LV2_CORE__InstrumentPlugin)),
  274. class_limiter (new_uri(LV2_CORE__LimiterPlugin)),
  275. class_lowpass (new_uri(LV2_CORE__LowpassPlugin)),
  276. class_mixer (new_uri(LV2_CORE__MixerPlugin)),
  277. class_modulator (new_uri(LV2_CORE__ModulatorPlugin)),
  278. class_multiEQ (new_uri(LV2_CORE__MultiEQPlugin)),
  279. class_oscillator (new_uri(LV2_CORE__OscillatorPlugin)),
  280. class_paraEQ (new_uri(LV2_CORE__ParaEQPlugin)),
  281. class_phaser (new_uri(LV2_CORE__PhaserPlugin)),
  282. class_pitch (new_uri(LV2_CORE__PitchPlugin)),
  283. class_reverb (new_uri(LV2_CORE__ReverbPlugin)),
  284. class_simulator (new_uri(LV2_CORE__SimulatorPlugin)),
  285. class_spatial (new_uri(LV2_CORE__SpatialPlugin)),
  286. class_spectral (new_uri(LV2_CORE__SpectralPlugin)),
  287. class_utility (new_uri(LV2_CORE__UtilityPlugin)),
  288. class_waveshaper (new_uri(LV2_CORE__WaveshaperPlugin)),
  289. port_input (new_uri(LV2_CORE__InputPort)),
  290. port_output (new_uri(LV2_CORE__OutputPort)),
  291. port_control (new_uri(LV2_CORE__ControlPort)),
  292. port_audio (new_uri(LV2_CORE__AudioPort)),
  293. port_cv (new_uri(LV2_CORE__CVPort)),
  294. port_atom (new_uri(LV2_ATOM__AtomPort)),
  295. port_event (new_uri(LV2_EVENT__EventPort)),
  296. port_midi (new_uri(LV2_MIDI_LL__MidiPort)),
  297. pprop_optional (new_uri(LV2_CORE__connectionOptional)),
  298. pprop_enumeration (new_uri(LV2_CORE__enumeration)),
  299. pprop_integer (new_uri(LV2_CORE__integer)),
  300. pprop_sampleRate (new_uri(LV2_CORE__sampleRate)),
  301. pprop_toggled (new_uri(LV2_CORE__toggled)),
  302. pprop_artifacts (new_uri(LV2_PORT_PROPS__causesArtifacts)),
  303. pprop_continuousCV (new_uri(LV2_PORT_PROPS__continuousCV)),
  304. pprop_discreteCV (new_uri(LV2_PORT_PROPS__discreteCV)),
  305. pprop_expensive (new_uri(LV2_PORT_PROPS__expensive)),
  306. pprop_strictBounds (new_uri(LV2_PORT_PROPS__hasStrictBounds)),
  307. pprop_logarithmic (new_uri(LV2_PORT_PROPS__logarithmic)),
  308. pprop_notAutomatic (new_uri(LV2_PORT_PROPS__notAutomatic)),
  309. pprop_notOnGUI (new_uri(LV2_PORT_PROPS__notOnGUI)),
  310. pprop_trigger (new_uri(LV2_PORT_PROPS__trigger)),
  311. pprop_nonAutomable (new_uri(LV2_KXSTUDIO_PROPERTIES__NonAutomable)),
  312. unit_name (new_uri(LV2_UNITS__name)),
  313. unit_render (new_uri(LV2_UNITS__render)),
  314. unit_symbol (new_uri(LV2_UNITS__symbol)),
  315. unit_unit (new_uri(LV2_UNITS__unit)),
  316. ui_gtk2 (new_uri(LV2_UI__GtkUI)),
  317. ui_gtk3 (new_uri(LV2_UI__Gtk3UI)),
  318. ui_qt4 (new_uri(LV2_UI__Qt4UI)),
  319. ui_qt5 (new_uri(LV2_UI__Qt5UI)),
  320. ui_cocoa (new_uri(LV2_UI__CocoaUI)),
  321. ui_windows (new_uri(LV2_UI__WindowsUI)),
  322. ui_x11 (new_uri(LV2_UI__X11UI)),
  323. ui_external (new_uri(LV2_EXTERNAL_UI__Widget)),
  324. ui_externalOld (new_uri(LV2_EXTERNAL_UI_DEPRECATED_URI)),
  325. ui_externalOld2 (new_uri("http://nedko.arnaudov.name/lv2/external_ui/")),
  326. atom_bufferType (new_uri(LV2_ATOM__bufferType)),
  327. atom_sequence (new_uri(LV2_ATOM__Sequence)),
  328. atom_supports (new_uri(LV2_ATOM__supports)),
  329. patch_writable (new_uri(LV2_PATCH__writable)),
  330. parameter (new_uri(LV2_CORE__Parameter)),
  331. preset_preset (new_uri(LV2_PRESETS__Preset)),
  332. state_state (new_uri(LV2_STATE__state)),
  333. ui_portIndex (new_uri(LV2_UI__portIndex)),
  334. ui_portNotif (new_uri(LV2_UI__portNotification)),
  335. ui_protocol (new_uri(LV2_UI__protocol)),
  336. value_default (new_uri(LV2_CORE__default)),
  337. value_minimum (new_uri(LV2_CORE__minimum)),
  338. value_maximum (new_uri(LV2_CORE__maximum)),
  339. rz_asLargeAs (new_uri(LV2_RESIZE_PORT__asLargeAs)),
  340. rz_minSize (new_uri(LV2_RESIZE_PORT__minimumSize)),
  341. midi_event (new_uri(LV2_MIDI__MidiEvent)),
  342. patch_message (new_uri(LV2_PATCH__Message)),
  343. time_position (new_uri(LV2_TIME__Position)),
  344. mm_defaultControl (new_uri(NS_llmm "defaultMidiController")),
  345. mm_controlType (new_uri(NS_llmm "controllerType")),
  346. mm_controlNumber (new_uri(NS_llmm "controllerNumber")),
  347. dct_replaces (new_uri(NS_dct "replaces")),
  348. doap_license (new_uri(NS_doap "license")),
  349. rdf_type (new_uri(NS_rdf "type")),
  350. rdfs_comment (new_uri(NS_rdfs "comment")),
  351. rdfs_label (new_uri(NS_rdfs "label")),
  352. rdfs_range (new_uri(NS_rdfs "range")),
  353. needsInit(true),
  354. allPlugins(nullptr),
  355. cachedPlugins(nullptr),
  356. pluginCount(0) {}
  357. ~Lv2WorldClass() override
  358. {
  359. pluginCount = 0;
  360. allPlugins = nullptr;
  361. if (cachedPlugins != nullptr)
  362. {
  363. delete[] cachedPlugins;
  364. cachedPlugins = nullptr;
  365. }
  366. }
  367. // FIXME - remove this
  368. static Lv2WorldClass& getInstance()
  369. {
  370. static Lv2WorldClass lv2World;
  371. return lv2World;
  372. }
  373. void initIfNeeded(const char* LV2_PATH)
  374. {
  375. if (LV2_PATH == nullptr || LV2_PATH[0] == '\0')
  376. {
  377. static const char* const DEFAULT_LV2_PATH = LILV_DEFAULT_LV2_PATH;
  378. LV2_PATH = DEFAULT_LV2_PATH;
  379. }
  380. if (! needsInit)
  381. return;
  382. needsInit = false;
  383. Lilv::World::load_all(LV2_PATH);
  384. allPlugins = lilv_world_get_all_plugins(this->me);
  385. CARLA_SAFE_ASSERT_RETURN(allPlugins != nullptr,);
  386. if ((pluginCount = lilv_plugins_size(allPlugins)))
  387. {
  388. cachedPlugins = new const LilvPlugin*[pluginCount+1];
  389. carla_zeroPointers(cachedPlugins, pluginCount+1);
  390. int i = 0;
  391. for (LilvIter* it = lilv_plugins_begin(allPlugins); ! lilv_plugins_is_end(allPlugins, it); it = lilv_plugins_next(allPlugins, it))
  392. cachedPlugins[i++] = lilv_plugins_get(allPlugins, it);
  393. }
  394. }
  395. void load_bundle(const char* const bundle)
  396. {
  397. CARLA_SAFE_ASSERT_RETURN(bundle != nullptr && bundle[0] != '\0',);
  398. CARLA_SAFE_ASSERT_RETURN(needsInit,);
  399. needsInit = false;
  400. Lilv::World::load_bundle(Lilv::Node(new_uri(bundle)));
  401. allPlugins = lilv_world_get_all_plugins(this->me);
  402. CARLA_SAFE_ASSERT_RETURN(allPlugins != nullptr,);
  403. if ((pluginCount = lilv_plugins_size(allPlugins)))
  404. {
  405. cachedPlugins = new const LilvPlugin*[pluginCount+1];
  406. carla_zeroPointers(cachedPlugins, pluginCount+1);
  407. int i = 0;
  408. for (LilvIter* it = lilv_plugins_begin(allPlugins); ! lilv_plugins_is_end(allPlugins, it); it = lilv_plugins_next(allPlugins, it))
  409. cachedPlugins[i++] = lilv_plugins_get(allPlugins, it);
  410. }
  411. }
  412. uint getPluginCount() const
  413. {
  414. CARLA_SAFE_ASSERT_RETURN(! needsInit, 0);
  415. return pluginCount;
  416. }
  417. const LilvPlugin* getPluginFromIndex(const uint index) const
  418. {
  419. CARLA_SAFE_ASSERT_RETURN(! needsInit, nullptr);
  420. CARLA_SAFE_ASSERT_RETURN(cachedPlugins != nullptr, nullptr);
  421. CARLA_SAFE_ASSERT_RETURN(index < pluginCount, nullptr);
  422. return cachedPlugins[index];
  423. }
  424. const LilvPlugin* getPluginFromURI(const LV2_URI uri) const
  425. {
  426. CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0', nullptr);
  427. CARLA_SAFE_ASSERT_RETURN(! needsInit, nullptr);
  428. CARLA_SAFE_ASSERT_RETURN(allPlugins != nullptr, nullptr);
  429. LilvNode* const uriNode(lilv_new_uri(this->me, uri));
  430. CARLA_SAFE_ASSERT_RETURN(uriNode != nullptr, nullptr);
  431. const LilvPlugin* const cPlugin(lilv_plugins_get_by_uri(allPlugins, uriNode));
  432. lilv_node_free(uriNode);
  433. return cPlugin;
  434. }
  435. LilvState* getStateFromURI(const LV2_URI uri, const LV2_URID_Map* const uridMap) const
  436. {
  437. CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0', nullptr);
  438. CARLA_SAFE_ASSERT_RETURN(uridMap != nullptr, nullptr);
  439. CARLA_SAFE_ASSERT_RETURN(! needsInit, nullptr);
  440. LilvNode* const uriNode(lilv_new_uri(this->me, uri));
  441. CARLA_SAFE_ASSERT_RETURN(uriNode != nullptr, nullptr);
  442. CARLA_SAFE_ASSERT(lilv_world_load_resource(this->me, uriNode) >= 0);
  443. LilvState* const cState(lilv_state_new_from_world(this->me, uridMap, uriNode));
  444. lilv_node_free(uriNode);
  445. return cState;
  446. }
  447. CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION
  448. CARLA_DECLARE_NON_COPY_STRUCT(Lv2WorldClass)
  449. };
  450. // --------------------------------------------------------------------------------------------------------------------
  451. // Our LV2 Plugin base class
  452. #if defined(__clang__)
  453. # pragma clang diagnostic push
  454. # pragma clang diagnostic ignored "-Weffc++"
  455. # pragma clang diagnostic ignored "-Wnon-virtual-dtor"
  456. #elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
  457. # pragma GCC diagnostic push
  458. # pragma GCC diagnostic ignored "-Weffc++"
  459. # pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
  460. #endif
  461. template<class TimeInfoStruct>
  462. class Lv2PluginBaseClass : public LV2_External_UI_Widget_Compat
  463. {
  464. #if defined(__clang__)
  465. # pragma clang diagnostic pop
  466. #elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
  467. # pragma GCC diagnostic pop
  468. #endif
  469. public:
  470. Lv2PluginBaseClass(const double sampleRate, const LV2_Feature* const* const features)
  471. : fIsActive(false),
  472. fIsOffline(false),
  473. fUsingNominal(false),
  474. fBufferSize(0),
  475. fSampleRate(sampleRate),
  476. fUridMap(nullptr),
  477. fWorker(nullptr),
  478. fTimeInfo(),
  479. fLastPositionData(),
  480. fPorts(),
  481. fURIs(),
  482. fUI()
  483. {
  484. run = extui_run;
  485. show = extui_show;
  486. hide = extui_hide;
  487. if (fSampleRate < 1.0)
  488. {
  489. carla_stderr("Host doesn't provide a valid sample rate");
  490. return;
  491. }
  492. const LV2_Options_Option* options = nullptr;
  493. const LV2_URID_Map* uridMap = nullptr;
  494. const LV2_URID_Unmap* uridUnmap = nullptr;
  495. const LV2_Worker_Schedule* worker = nullptr;
  496. for (int i=0; features[i] != nullptr; ++i)
  497. {
  498. /**/ if (std::strcmp(features[i]->URI, LV2_OPTIONS__options) == 0)
  499. options = (const LV2_Options_Option*)features[i]->data;
  500. else if (std::strcmp(features[i]->URI, LV2_URID__map) == 0)
  501. uridMap = (const LV2_URID_Map*)features[i]->data;
  502. else if (std::strcmp(features[i]->URI, LV2_URID__unmap) == 0)
  503. uridUnmap = (const LV2_URID_Unmap*)features[i]->data;
  504. else if (std::strcmp(features[i]->URI, LV2_WORKER__schedule) == 0)
  505. worker = (const LV2_Worker_Schedule*)features[i]->data;
  506. }
  507. if (options == nullptr || uridMap == nullptr)
  508. {
  509. carla_stderr("Host doesn't provide option and urid-map features");
  510. return;
  511. }
  512. for (int i=0; options[i].key != 0; ++i)
  513. {
  514. if (uridUnmap != nullptr) {
  515. carla_debug("Host option %i:\"%s\"", i, uridUnmap->unmap(uridUnmap->handle, options[i].key));
  516. }
  517. if (options[i].key == uridMap->map(uridMap->handle, LV2_BUF_SIZE__nominalBlockLength))
  518. {
  519. if (options[i].type == uridMap->map(uridMap->handle, LV2_ATOM__Int))
  520. {
  521. const int32_t value(*(const int32_t*)options[i].value);
  522. CARLA_SAFE_ASSERT_CONTINUE(value > 0);
  523. fBufferSize = static_cast<uint32_t>(value);
  524. fUsingNominal = true;
  525. }
  526. else
  527. {
  528. carla_stderr("Host provides nominalBlockLength but has wrong value type");
  529. }
  530. break;
  531. }
  532. if (options[i].key == uridMap->map(uridMap->handle, LV2_BUF_SIZE__maxBlockLength))
  533. {
  534. if (options[i].type == uridMap->map(uridMap->handle, LV2_ATOM__Int))
  535. {
  536. const int32_t value(*(const int32_t*)options[i].value);
  537. CARLA_SAFE_ASSERT_CONTINUE(value > 0);
  538. fBufferSize = static_cast<uint32_t>(value);
  539. }
  540. else
  541. {
  542. carla_stderr("Host provides maxBlockLength but has wrong value type");
  543. }
  544. // no break, continue in case host supports nominalBlockLength
  545. }
  546. }
  547. if (fBufferSize == 0)
  548. {
  549. carla_stderr("Host doesn't provide buffer-size feature");
  550. //return;
  551. // as testing, continue for now
  552. fBufferSize = 1024;
  553. }
  554. fUridMap = uridMap;
  555. fURIs.map(uridMap);
  556. fWorker = worker;
  557. clearTimeData();
  558. }
  559. virtual ~Lv2PluginBaseClass() {}
  560. bool loadedInProperHost() const noexcept
  561. {
  562. return fUridMap != nullptr && fBufferSize != 0;
  563. }
  564. // ----------------------------------------------------------------------------------------------------------------
  565. void lv2_connect_port(const uint32_t port, void* const dataLocation) noexcept
  566. {
  567. fPorts.connectPort(port, dataLocation);
  568. }
  569. bool lv2_pre_run(const uint32_t frames)
  570. {
  571. CARLA_SAFE_ASSERT_RETURN(fIsActive, false);
  572. fIsOffline = (fPorts.freewheel != nullptr && *fPorts.freewheel >= 0.5f);
  573. // cache midi events and time information first
  574. if (fPorts.usesTime)
  575. {
  576. LV2_ATOM_SEQUENCE_FOREACH(fPorts.eventsIn[0], event)
  577. {
  578. if (event == nullptr)
  579. continue;
  580. if (event->body.type != fURIs.atomBlank && event->body.type != fURIs.atomObject)
  581. continue;
  582. const LV2_Atom_Object* const obj((const LV2_Atom_Object*)&event->body);
  583. if (obj->body.otype != fURIs.timePos)
  584. continue;
  585. LV2_Atom* bar = nullptr;
  586. LV2_Atom* barBeat = nullptr;
  587. LV2_Atom* beatUnit = nullptr;
  588. LV2_Atom* beatsPerBar = nullptr;
  589. LV2_Atom* beatsPerMinute = nullptr;
  590. LV2_Atom* frame = nullptr;
  591. LV2_Atom* speed = nullptr;
  592. LV2_Atom* ticksPerBeat = nullptr;
  593. lv2_atom_object_get(obj,
  594. fURIs.timeBar, &bar,
  595. fURIs.timeBarBeat, &barBeat,
  596. fURIs.timeBeatUnit, &beatUnit,
  597. fURIs.timeBeatsPerBar, &beatsPerBar,
  598. fURIs.timeBeatsPerMinute, &beatsPerMinute,
  599. fURIs.timeFrame, &frame,
  600. fURIs.timeSpeed, &speed,
  601. fURIs.timeTicksPerBeat, &ticksPerBeat,
  602. 0);
  603. // need to handle this first as other values depend on it
  604. if (ticksPerBeat != nullptr)
  605. {
  606. double ticksPerBeatValue = -1.0;
  607. /**/ if (ticksPerBeat->type == fURIs.atomDouble)
  608. ticksPerBeatValue = ((LV2_Atom_Double*)ticksPerBeat)->body;
  609. else if (ticksPerBeat->type == fURIs.atomFloat)
  610. ticksPerBeatValue = ((LV2_Atom_Float*)ticksPerBeat)->body;
  611. else if (ticksPerBeat->type == fURIs.atomInt)
  612. ticksPerBeatValue = static_cast<double>(((LV2_Atom_Int*)ticksPerBeat)->body);
  613. else if (ticksPerBeat->type == fURIs.atomLong)
  614. ticksPerBeatValue = static_cast<double>(((LV2_Atom_Long*)ticksPerBeat)->body);
  615. else
  616. carla_stderr("Unknown lv2 ticksPerBeat value type");
  617. if (ticksPerBeatValue > 0.0)
  618. fTimeInfo.bbt.ticksPerBeat = fLastPositionData.ticksPerBeat = ticksPerBeatValue;
  619. else
  620. carla_stderr("Invalid lv2 ticksPerBeat value");
  621. }
  622. // same
  623. if (speed != nullptr)
  624. {
  625. /**/ if (speed->type == fURIs.atomDouble)
  626. fLastPositionData.speed = ((LV2_Atom_Double*)speed)->body;
  627. else if (speed->type == fURIs.atomFloat)
  628. fLastPositionData.speed = ((LV2_Atom_Float*)speed)->body;
  629. else if (speed->type == fURIs.atomInt)
  630. fLastPositionData.speed = static_cast<double>(((LV2_Atom_Int*)speed)->body);
  631. else if (speed->type == fURIs.atomLong)
  632. fLastPositionData.speed = static_cast<double>(((LV2_Atom_Long*)speed)->body);
  633. else
  634. carla_stderr("Unknown lv2 speed value type");
  635. fTimeInfo.playing = carla_isNotZero(fLastPositionData.speed);
  636. if (fTimeInfo.playing && fLastPositionData.beatsPerMinute > 0.0)
  637. {
  638. fTimeInfo.bbt.beatsPerMinute = fLastPositionData.beatsPerMinute*
  639. std::abs(fLastPositionData.speed);
  640. }
  641. }
  642. if (bar != nullptr)
  643. {
  644. int64_t barValue = -1;
  645. /**/ if (bar->type == fURIs.atomDouble)
  646. barValue = static_cast<int64_t>(((LV2_Atom_Double*)bar)->body);
  647. else if (bar->type == fURIs.atomFloat)
  648. barValue = static_cast<int64_t>(((LV2_Atom_Float*)bar)->body);
  649. else if (bar->type == fURIs.atomInt)
  650. barValue = ((LV2_Atom_Int*)bar)->body;
  651. else if (bar->type == fURIs.atomLong)
  652. barValue = ((LV2_Atom_Long*)bar)->body;
  653. else
  654. carla_stderr("Unknown lv2 bar value type");
  655. if (barValue >= 0 && barValue < INT32_MAX)
  656. {
  657. fLastPositionData.bar = static_cast<int32_t>(barValue);
  658. fLastPositionData.bar_f = static_cast<float>(barValue);
  659. fTimeInfo.bbt.bar = fLastPositionData.bar + 1;
  660. }
  661. else
  662. {
  663. carla_stderr("Invalid lv2 bar value");
  664. }
  665. }
  666. if (barBeat != nullptr)
  667. {
  668. double barBeatValue = -1.0;
  669. /**/ if (barBeat->type == fURIs.atomDouble)
  670. barBeatValue = ((LV2_Atom_Double*)barBeat)->body;
  671. else if (barBeat->type == fURIs.atomFloat)
  672. barBeatValue = ((LV2_Atom_Float*)barBeat)->body;
  673. else if (barBeat->type == fURIs.atomInt)
  674. barBeatValue = static_cast<float>(((LV2_Atom_Int*)barBeat)->body);
  675. else if (barBeat->type == fURIs.atomLong)
  676. barBeatValue = static_cast<float>(((LV2_Atom_Long*)barBeat)->body);
  677. else
  678. carla_stderr("Unknown lv2 barBeat value type");
  679. if (barBeatValue >= 0.0)
  680. {
  681. fLastPositionData.barBeat = static_cast<float>(barBeatValue);
  682. const double rest = std::fmod(barBeatValue, 1.0);
  683. fTimeInfo.bbt.beat = static_cast<int32_t>(barBeatValue-rest+1.0);
  684. fTimeInfo.bbt.tick = static_cast<int32_t>(rest*fTimeInfo.bbt.ticksPerBeat+0.5);
  685. }
  686. else
  687. {
  688. carla_stderr("Invalid lv2 barBeat value");
  689. }
  690. }
  691. if (beatUnit != nullptr)
  692. {
  693. int64_t beatUnitValue = -1;
  694. /**/ if (beatUnit->type == fURIs.atomDouble)
  695. beatUnitValue = static_cast<int64_t>(((LV2_Atom_Double*)beatUnit)->body);
  696. else if (beatUnit->type == fURIs.atomFloat)
  697. beatUnitValue = static_cast<int64_t>(((LV2_Atom_Float*)beatUnit)->body);
  698. else if (beatUnit->type == fURIs.atomInt)
  699. beatUnitValue = ((LV2_Atom_Int*)beatUnit)->body;
  700. else if (beatUnit->type == fURIs.atomLong)
  701. beatUnitValue = ((LV2_Atom_Long*)beatUnit)->body;
  702. else
  703. carla_stderr("Unknown lv2 beatUnit value type");
  704. if (beatUnitValue > 0 && beatUnitValue < UINT32_MAX)
  705. {
  706. fLastPositionData.beatUnit = static_cast<uint32_t>(beatUnitValue);
  707. fTimeInfo.bbt.beatType = static_cast<float>(beatUnitValue);
  708. }
  709. else
  710. {
  711. carla_stderr("Invalid lv2 beatUnit value");
  712. }
  713. }
  714. if (beatsPerBar != nullptr)
  715. {
  716. float beatsPerBarValue = -1.0f;
  717. /**/ if (beatsPerBar->type == fURIs.atomDouble)
  718. beatsPerBarValue = static_cast<float>(((LV2_Atom_Double*)beatsPerBar)->body);
  719. else if (beatsPerBar->type == fURIs.atomFloat)
  720. beatsPerBarValue = ((LV2_Atom_Float*)beatsPerBar)->body;
  721. else if (beatsPerBar->type == fURIs.atomInt)
  722. beatsPerBarValue = static_cast<float>(((LV2_Atom_Int*)beatsPerBar)->body);
  723. else if (beatsPerBar->type == fURIs.atomLong)
  724. beatsPerBarValue = static_cast<float>(((LV2_Atom_Long*)beatsPerBar)->body);
  725. else
  726. carla_stderr("Unknown lv2 beatsPerBar value type");
  727. if (beatsPerBarValue > 0.0f)
  728. fTimeInfo.bbt.beatsPerBar = fLastPositionData.beatsPerBar = beatsPerBarValue;
  729. else
  730. carla_stderr("Invalid lv2 beatsPerBar value");
  731. }
  732. if (beatsPerMinute != nullptr)
  733. {
  734. double beatsPerMinuteValue = -1.0;
  735. /**/ if (beatsPerMinute->type == fURIs.atomDouble)
  736. beatsPerMinuteValue = ((LV2_Atom_Double*)beatsPerMinute)->body;
  737. else if (beatsPerMinute->type == fURIs.atomFloat)
  738. beatsPerMinuteValue = ((LV2_Atom_Float*)beatsPerMinute)->body;
  739. else if (beatsPerMinute->type == fURIs.atomInt)
  740. beatsPerMinuteValue = static_cast<double>(((LV2_Atom_Int*)beatsPerMinute)->body);
  741. else if (beatsPerMinute->type == fURIs.atomLong)
  742. beatsPerMinuteValue = static_cast<double>(((LV2_Atom_Long*)beatsPerMinute)->body);
  743. else
  744. carla_stderr("Unknown lv2 beatsPerMinute value type");
  745. if (beatsPerMinuteValue >= 12.0 && beatsPerMinuteValue <= 999.0)
  746. {
  747. fTimeInfo.bbt.beatsPerMinute = fLastPositionData.beatsPerMinute = beatsPerMinuteValue;
  748. if (carla_isNotZero(fLastPositionData.speed))
  749. fTimeInfo.bbt.beatsPerMinute *= std::abs(fLastPositionData.speed);
  750. }
  751. else
  752. {
  753. carla_stderr("Invalid lv2 beatsPerMinute value");
  754. }
  755. }
  756. if (frame != nullptr)
  757. {
  758. int64_t frameValue = -1;
  759. /**/ if (frame->type == fURIs.atomDouble)
  760. frameValue = static_cast<int64_t>(((LV2_Atom_Double*)frame)->body);
  761. else if (frame->type == fURIs.atomFloat)
  762. frameValue = static_cast<int64_t>(((LV2_Atom_Float*)frame)->body);
  763. else if (frame->type == fURIs.atomInt)
  764. frameValue = ((LV2_Atom_Int*)frame)->body;
  765. else if (frame->type == fURIs.atomLong)
  766. frameValue = ((LV2_Atom_Long*)frame)->body;
  767. else
  768. carla_stderr("Unknown lv2 frame value type");
  769. if (frameValue >= 0)
  770. fTimeInfo.frame = fLastPositionData.frame = static_cast<uint64_t>(frameValue);
  771. else
  772. carla_stderr("Invalid lv2 frame value");
  773. }
  774. fTimeInfo.bbt.barStartTick = static_cast<double>(fTimeInfo.bbt.ticksPerBeat) *
  775. static_cast<double>(fTimeInfo.bbt.beatsPerBar) *
  776. (fTimeInfo.bbt.bar-1);
  777. fTimeInfo.bbt.valid = (fLastPositionData.beatsPerMinute > 0.0 &&
  778. fLastPositionData.beatUnit > 0 &&
  779. fLastPositionData.beatsPerBar > 0.0f);
  780. }
  781. }
  782. // Check for updated parameters
  783. float curValue;
  784. for (uint32_t i=0; i < fPorts.numParams; ++i)
  785. {
  786. if (fPorts.paramsOut[i])
  787. continue;
  788. CARLA_SAFE_ASSERT_CONTINUE(fPorts.paramsPtr[i] != nullptr)
  789. curValue = *fPorts.paramsPtr[i];
  790. if (carla_isEqual(fPorts.paramsLast[i], curValue))
  791. continue;
  792. fPorts.paramsLast[i] = curValue;
  793. handleParameterValueChanged(i, curValue);
  794. }
  795. if (frames == 0)
  796. return false;
  797. // init midi out data
  798. if (fPorts.numMidiOuts > 0 || fPorts.hasUI)
  799. {
  800. for (uint32_t i=0; i<fPorts.numMidiOuts; ++i)
  801. {
  802. LV2_Atom_Sequence* const seq(fPorts.eventsOut[i]);
  803. CARLA_SAFE_ASSERT_CONTINUE(seq != nullptr);
  804. fPorts.eventsOutData[i].capacity = seq->atom.size;
  805. fPorts.eventsOutData[i].offset = 0;
  806. seq->atom.size = sizeof(LV2_Atom_Sequence_Body);
  807. seq->atom.type = fURIs.atomSequence;
  808. seq->body.unit = 0;
  809. seq->body.pad = 0;
  810. }
  811. }
  812. return true;
  813. }
  814. void lv2_post_run(const uint32_t frames)
  815. {
  816. // update timePos for next callback
  817. if (carla_isZero(fLastPositionData.speed))
  818. return;
  819. if (fLastPositionData.speed > 0.0)
  820. {
  821. // playing forwards
  822. fLastPositionData.frame += frames;
  823. }
  824. else
  825. {
  826. // playing backwards
  827. if (frames >= fLastPositionData.frame)
  828. fLastPositionData.frame = 0;
  829. else
  830. fLastPositionData.frame -= frames;
  831. }
  832. fTimeInfo.frame = fLastPositionData.frame;
  833. if (fTimeInfo.bbt.valid)
  834. {
  835. const double beatsPerMinute = fLastPositionData.beatsPerMinute * fLastPositionData.speed;
  836. const double framesPerBeat = 60.0 * fSampleRate / beatsPerMinute;
  837. const double addedBarBeats = double(frames) / framesPerBeat;
  838. if (fLastPositionData.barBeat >= 0.0f)
  839. {
  840. fLastPositionData.barBeat = std::fmod(fLastPositionData.barBeat+static_cast<float>(addedBarBeats),
  841. fLastPositionData.beatsPerBar);
  842. const double rest = std::fmod(fLastPositionData.barBeat, 1.0f);
  843. fTimeInfo.bbt.beat = static_cast<int32_t>(static_cast<double>(fLastPositionData.barBeat)-rest+1.0);
  844. fTimeInfo.bbt.tick = static_cast<int32_t>(rest*fTimeInfo.bbt.ticksPerBeat+0.5);
  845. if (fLastPositionData.bar_f >= 0.0f)
  846. {
  847. fLastPositionData.bar_f += std::floor((fLastPositionData.barBeat+static_cast<float>(addedBarBeats))/
  848. fLastPositionData.beatsPerBar);
  849. if (fLastPositionData.bar_f <= 0.0f)
  850. {
  851. fLastPositionData.bar = 0;
  852. fLastPositionData.bar_f = 0.0f;
  853. }
  854. else
  855. {
  856. fLastPositionData.bar = static_cast<int32_t>(fLastPositionData.bar_f+0.5f);
  857. }
  858. fTimeInfo.bbt.bar = fLastPositionData.bar + 1;
  859. fTimeInfo.bbt.barStartTick = static_cast<double>(fTimeInfo.bbt.ticksPerBeat) *
  860. static_cast<double>(fTimeInfo.bbt.beatsPerBar) *
  861. (fTimeInfo.bbt.bar-1);
  862. }
  863. }
  864. }
  865. }
  866. // ----------------------------------------------------------------------------------------------------------------
  867. uint32_t lv2_get_options(LV2_Options_Option* const /*options*/) const
  868. {
  869. // currently unused
  870. return LV2_OPTIONS_SUCCESS;
  871. }
  872. uint32_t lv2_set_options(const LV2_Options_Option* const options)
  873. {
  874. for (int i=0; options[i].key != 0; ++i)
  875. {
  876. if (options[i].key == fUridMap->map(fUridMap->handle, LV2_BUF_SIZE__nominalBlockLength))
  877. {
  878. if (options[i].type == fURIs.atomInt)
  879. {
  880. const int32_t value(*(const int32_t*)options[i].value);
  881. CARLA_SAFE_ASSERT_CONTINUE(value > 0);
  882. const uint32_t newBufferSize = static_cast<uint32_t>(value);
  883. if (fBufferSize != newBufferSize)
  884. {
  885. fBufferSize = newBufferSize;
  886. handleBufferSizeChanged(newBufferSize);
  887. }
  888. }
  889. else
  890. {
  891. carla_stderr("Host changed nominalBlockLength but with wrong value type");
  892. }
  893. }
  894. else if (options[i].key == fUridMap->map(fUridMap->handle, LV2_BUF_SIZE__maxBlockLength) && ! fUsingNominal)
  895. {
  896. if (options[i].type == fURIs.atomInt)
  897. {
  898. const int32_t value(*(const int32_t*)options[i].value);
  899. CARLA_SAFE_ASSERT_CONTINUE(value > 0);
  900. const uint32_t newBufferSize = static_cast<uint32_t>(value);
  901. if (fBufferSize != newBufferSize)
  902. {
  903. fBufferSize = newBufferSize;
  904. handleBufferSizeChanged(newBufferSize);
  905. }
  906. }
  907. else
  908. {
  909. carla_stderr("Host changed maxBlockLength but with wrong value type");
  910. }
  911. }
  912. else if (options[i].key == fUridMap->map(fUridMap->handle, LV2_PARAMETERS__sampleRate))
  913. {
  914. if (options[i].type == fURIs.atomFloat)
  915. {
  916. const double value(*(const float*)options[i].value);
  917. CARLA_SAFE_ASSERT_CONTINUE(value > 0.0);
  918. if (carla_isNotEqual(fSampleRate, value))
  919. {
  920. fSampleRate = value;
  921. handleSampleRateChanged(value);
  922. }
  923. }
  924. else
  925. {
  926. carla_stderr("Host changed sampleRate but with wrong value type");
  927. }
  928. }
  929. }
  930. return LV2_OPTIONS_SUCCESS;
  931. }
  932. // ----------------------------------------------------------------------------------------------------------------
  933. int lv2ui_idle() const
  934. {
  935. if (! fUI.isVisible)
  936. return 1;
  937. handleUiRun();
  938. return 0;
  939. }
  940. int lv2ui_show()
  941. {
  942. handleUiShow();
  943. return 0;
  944. }
  945. int lv2ui_hide()
  946. {
  947. handleUiHide();
  948. return 0;
  949. }
  950. void lv2ui_cleanup()
  951. {
  952. if (fUI.isVisible)
  953. handleUiHide();
  954. fUI.host = nullptr;
  955. fUI.writeFunction = nullptr;
  956. fUI.controller = nullptr;
  957. }
  958. // ----------------------------------------------------------------------------------------------------------------
  959. protected:
  960. virtual void handleUiRun() const = 0;
  961. virtual void handleUiShow() = 0;
  962. virtual void handleUiHide() = 0;
  963. virtual void handleParameterValueChanged(const uint32_t index, const float value) = 0;
  964. virtual void handleBufferSizeChanged(const uint32_t bufferSize) = 0;
  965. virtual void handleSampleRateChanged(const double sampleRate) = 0;
  966. void resetTimeInfo() noexcept
  967. {
  968. clearTimeData();
  969. // hosts may not send all values, resulting on some invalid data
  970. fTimeInfo.bbt.bar = 1;
  971. fTimeInfo.bbt.beat = 1;
  972. fTimeInfo.bbt.beatsPerBar = 4;
  973. fTimeInfo.bbt.beatType = 4;
  974. fTimeInfo.bbt.ticksPerBeat = fLastPositionData.ticksPerBeat = 960.0;
  975. fTimeInfo.bbt.beatsPerMinute = fLastPositionData.beatsPerMinute = 120.0;
  976. }
  977. // LV2 host data
  978. bool fIsActive : 1;
  979. bool fIsOffline : 1;
  980. bool fUsingNominal : 1;
  981. uint32_t fBufferSize;
  982. double fSampleRate;
  983. // LV2 host features
  984. const LV2_URID_Map* fUridMap;
  985. const LV2_Worker_Schedule* fWorker;
  986. // Time info stuff
  987. TimeInfoStruct fTimeInfo;
  988. struct Lv2PositionData {
  989. int32_t bar;
  990. float bar_f;
  991. float barBeat;
  992. uint32_t beatUnit;
  993. float beatsPerBar;
  994. double beatsPerMinute;
  995. uint64_t frame;
  996. double speed;
  997. double ticksPerBeat;
  998. Lv2PositionData()
  999. : bar(-1),
  1000. bar_f(-1.0f),
  1001. barBeat(-1.0f),
  1002. beatUnit(0),
  1003. beatsPerBar(0.0f),
  1004. beatsPerMinute(-1.0),
  1005. frame(0),
  1006. speed(0.0),
  1007. ticksPerBeat(-1.0) {}
  1008. void clear()
  1009. {
  1010. bar = -1;
  1011. bar_f = -1.0f;
  1012. barBeat = -1.0f;
  1013. beatUnit = 0;
  1014. beatsPerBar = 0.0f;
  1015. beatsPerMinute = -1.0;
  1016. frame = 0;
  1017. speed = 0.0;
  1018. ticksPerBeat = -1.0;
  1019. }
  1020. } fLastPositionData;
  1021. // Port stuff
  1022. struct Ports {
  1023. // need to save current state
  1024. struct EventsOutData {
  1025. uint32_t capacity;
  1026. uint32_t offset;
  1027. EventsOutData()
  1028. : capacity(0),
  1029. offset(0) {}
  1030. };
  1031. // store port info
  1032. uint32_t indexOffset;
  1033. uint32_t numAudioIns;
  1034. uint32_t numAudioOuts;
  1035. uint32_t numMidiIns;
  1036. uint32_t numMidiOuts;
  1037. uint32_t numParams;
  1038. bool hasUI;
  1039. bool usesTime;
  1040. // port buffers
  1041. const LV2_Atom_Sequence** eventsIn;
  1042. /* */ LV2_Atom_Sequence** eventsOut;
  1043. /* */ EventsOutData* eventsOutData;
  1044. const float** audioIns;
  1045. /* */ float** audioOuts;
  1046. /* */ float* freewheel;
  1047. // cached parameter values
  1048. float* paramsLast;
  1049. float** paramsPtr;
  1050. bool* paramsOut;
  1051. Ports()
  1052. : indexOffset(0),
  1053. numAudioIns(0),
  1054. numAudioOuts(0),
  1055. numMidiIns(0),
  1056. numMidiOuts(0),
  1057. numParams(0),
  1058. hasUI(false),
  1059. usesTime(false),
  1060. eventsIn(nullptr),
  1061. eventsOut(nullptr),
  1062. eventsOutData(nullptr),
  1063. audioIns(nullptr),
  1064. audioOuts(nullptr),
  1065. freewheel(nullptr),
  1066. paramsLast(nullptr),
  1067. paramsPtr(nullptr),
  1068. paramsOut(nullptr) {}
  1069. ~Ports()
  1070. {
  1071. if (eventsIn != nullptr)
  1072. {
  1073. delete[] eventsIn;
  1074. eventsIn = nullptr;
  1075. }
  1076. if (eventsOut != nullptr)
  1077. {
  1078. delete[] eventsOut;
  1079. eventsOut = nullptr;
  1080. }
  1081. if (eventsOutData != nullptr)
  1082. {
  1083. delete[] eventsOutData;
  1084. eventsOutData = nullptr;
  1085. }
  1086. if (audioIns != nullptr)
  1087. {
  1088. delete[] audioIns;
  1089. audioIns = nullptr;
  1090. }
  1091. if (audioOuts != nullptr)
  1092. {
  1093. delete[] audioOuts;
  1094. audioOuts = nullptr;
  1095. }
  1096. if (paramsLast != nullptr)
  1097. {
  1098. delete[] paramsLast;
  1099. paramsLast = nullptr;
  1100. }
  1101. if (paramsPtr != nullptr)
  1102. {
  1103. delete[] paramsPtr;
  1104. paramsPtr = nullptr;
  1105. }
  1106. if (paramsOut != nullptr)
  1107. {
  1108. delete[] paramsOut;
  1109. paramsOut = nullptr;
  1110. }
  1111. }
  1112. // NOTE: assumes num* has been filled by parent class
  1113. void init()
  1114. {
  1115. if (numMidiIns > 0)
  1116. {
  1117. eventsIn = new const LV2_Atom_Sequence*[numMidiIns];
  1118. for (uint32_t i=0; i < numMidiIns; ++i)
  1119. eventsIn[i] = nullptr;
  1120. }
  1121. else if (usesTime || hasUI)
  1122. {
  1123. eventsIn = new const LV2_Atom_Sequence*[1];
  1124. eventsIn[0] = nullptr;
  1125. }
  1126. if (numMidiOuts > 0)
  1127. {
  1128. eventsOut = new LV2_Atom_Sequence*[numMidiOuts];
  1129. eventsOutData = new EventsOutData[numMidiOuts];
  1130. for (uint32_t i=0; i < numMidiOuts; ++i)
  1131. eventsOut[i] = nullptr;
  1132. }
  1133. else if (hasUI)
  1134. {
  1135. eventsOut = new LV2_Atom_Sequence*[1];
  1136. eventsOut[0] = nullptr;
  1137. }
  1138. if (numAudioIns > 0)
  1139. {
  1140. audioIns = new const float*[numAudioIns];
  1141. for (uint32_t i=0; i < numAudioIns; ++i)
  1142. audioIns[i] = nullptr;
  1143. }
  1144. if (numAudioOuts > 0)
  1145. {
  1146. audioOuts = new float*[numAudioOuts];
  1147. for (uint32_t i=0; i < numAudioOuts; ++i)
  1148. audioOuts[i] = nullptr;
  1149. }
  1150. if (numParams > 0)
  1151. {
  1152. paramsLast = new float[numParams];
  1153. paramsPtr = new float*[numParams];
  1154. paramsOut = new bool[numParams];
  1155. carla_zeroFloats(paramsLast, numParams);
  1156. carla_zeroPointers(paramsPtr, numParams);
  1157. carla_zeroStructs(paramsOut, numParams);
  1158. // NOTE: need to be filled in by the parent class
  1159. }
  1160. indexOffset = numAudioIns + numAudioOuts;
  1161. // 1 event port for time or ui if no midi input is used
  1162. indexOffset += numMidiIns > 0 ? numMidiIns : ((usesTime || hasUI) ? 1 : 0);
  1163. // 1 event port for ui if no midi output is used
  1164. indexOffset += numMidiOuts > 0 ? numMidiOuts : (hasUI ? 1 : 0);
  1165. // 1 extra for freewheel port
  1166. indexOffset += 1;
  1167. }
  1168. void connectPort(const uint32_t port, void* const dataLocation)
  1169. {
  1170. uint32_t index = 0;
  1171. if (numMidiIns > 0 || usesTime || hasUI)
  1172. {
  1173. if (port == index++)
  1174. {
  1175. eventsIn[0] = (LV2_Atom_Sequence*)dataLocation;
  1176. return;
  1177. }
  1178. }
  1179. for (uint32_t i=1; i < numMidiIns; ++i)
  1180. {
  1181. if (port == index++)
  1182. {
  1183. eventsIn[i] = (LV2_Atom_Sequence*)dataLocation;
  1184. return;
  1185. }
  1186. }
  1187. if (numMidiOuts > 0 || hasUI)
  1188. {
  1189. if (port == index++)
  1190. {
  1191. eventsOut[0] = (LV2_Atom_Sequence*)dataLocation;
  1192. return;
  1193. }
  1194. }
  1195. for (uint32_t i=1; i < numMidiOuts; ++i)
  1196. {
  1197. if (port == index++)
  1198. {
  1199. eventsOut[i] = (LV2_Atom_Sequence*)dataLocation;
  1200. return;
  1201. }
  1202. }
  1203. if (port == index++)
  1204. {
  1205. freewheel = (float*)dataLocation;
  1206. return;
  1207. }
  1208. for (uint32_t i=0; i < numAudioIns; ++i)
  1209. {
  1210. if (port == index++)
  1211. {
  1212. audioIns[i] = (float*)dataLocation;
  1213. return;
  1214. }
  1215. }
  1216. for (uint32_t i=0; i < numAudioOuts; ++i)
  1217. {
  1218. if (port == index++)
  1219. {
  1220. audioOuts[i] = (float*)dataLocation;
  1221. return;
  1222. }
  1223. }
  1224. for (uint32_t i=0; i < numParams; ++i)
  1225. {
  1226. if (port == index++)
  1227. {
  1228. paramsPtr[i] = (float*)dataLocation;
  1229. return;
  1230. }
  1231. }
  1232. }
  1233. CARLA_DECLARE_NON_COPY_STRUCT(Ports);
  1234. } fPorts;
  1235. // Rest of host<->plugin support
  1236. struct URIDs {
  1237. LV2_URID atomBlank;
  1238. LV2_URID atomObject;
  1239. LV2_URID atomDouble;
  1240. LV2_URID atomFloat;
  1241. LV2_URID atomInt;
  1242. LV2_URID atomLong;
  1243. LV2_URID atomSequence;
  1244. LV2_URID atomString;
  1245. LV2_URID midiEvent;
  1246. LV2_URID timePos;
  1247. LV2_URID timeBar;
  1248. LV2_URID timeBarBeat;
  1249. LV2_URID timeBeatsPerBar;
  1250. LV2_URID timeBeatsPerMinute;
  1251. LV2_URID timeBeatUnit;
  1252. LV2_URID timeFrame;
  1253. LV2_URID timeSpeed;
  1254. LV2_URID timeTicksPerBeat;
  1255. LV2_URID uiEvents;
  1256. URIDs()
  1257. : atomBlank(0),
  1258. atomObject(0),
  1259. atomDouble(0),
  1260. atomFloat(0),
  1261. atomInt(0),
  1262. atomLong(0),
  1263. atomSequence(0),
  1264. atomString(0),
  1265. midiEvent(0),
  1266. timePos(0),
  1267. timeBar(0),
  1268. timeBarBeat(0),
  1269. timeBeatsPerBar(0),
  1270. timeBeatsPerMinute(0),
  1271. timeBeatUnit(0),
  1272. timeFrame(0),
  1273. timeSpeed(0),
  1274. timeTicksPerBeat(0),
  1275. uiEvents(0) {}
  1276. void map(const LV2_URID_Map* const uridMap)
  1277. {
  1278. atomBlank = uridMap->map(uridMap->handle, LV2_ATOM__Blank);
  1279. atomObject = uridMap->map(uridMap->handle, LV2_ATOM__Object);
  1280. atomDouble = uridMap->map(uridMap->handle, LV2_ATOM__Double);
  1281. atomFloat = uridMap->map(uridMap->handle, LV2_ATOM__Float);
  1282. atomInt = uridMap->map(uridMap->handle, LV2_ATOM__Int);
  1283. atomLong = uridMap->map(uridMap->handle, LV2_ATOM__Long);
  1284. atomSequence = uridMap->map(uridMap->handle, LV2_ATOM__Sequence);
  1285. atomString = uridMap->map(uridMap->handle, LV2_ATOM__String);
  1286. midiEvent = uridMap->map(uridMap->handle, LV2_MIDI__MidiEvent);
  1287. timePos = uridMap->map(uridMap->handle, LV2_TIME__Position);
  1288. timeBar = uridMap->map(uridMap->handle, LV2_TIME__bar);
  1289. timeBarBeat = uridMap->map(uridMap->handle, LV2_TIME__barBeat);
  1290. timeBeatUnit = uridMap->map(uridMap->handle, LV2_TIME__beatUnit);
  1291. timeFrame = uridMap->map(uridMap->handle, LV2_TIME__frame);
  1292. timeSpeed = uridMap->map(uridMap->handle, LV2_TIME__speed);
  1293. timeBeatsPerBar = uridMap->map(uridMap->handle, LV2_TIME__beatsPerBar);
  1294. timeBeatsPerMinute = uridMap->map(uridMap->handle, LV2_TIME__beatsPerMinute);
  1295. timeTicksPerBeat = uridMap->map(uridMap->handle, LV2_KXSTUDIO_PROPERTIES__TimePositionTicksPerBeat);
  1296. uiEvents = uridMap->map(uridMap->handle, "urn:carla:transmitEv");
  1297. }
  1298. } fURIs;
  1299. struct UI {
  1300. const LV2_External_UI_Host* host;
  1301. LV2UI_Write_Function writeFunction;
  1302. LV2UI_Controller controller;
  1303. bool isVisible;
  1304. UI()
  1305. : host(nullptr),
  1306. writeFunction(nullptr),
  1307. controller(nullptr),
  1308. isVisible(false) {}
  1309. } fUI;
  1310. private:
  1311. // ----------------------------------------------------------------------------------------------------------------
  1312. #define handlePtr ((Lv2PluginBaseClass*)handle)
  1313. static void extui_run(LV2_External_UI_Widget_Compat* handle)
  1314. {
  1315. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  1316. handlePtr->handleUiRun();
  1317. }
  1318. static void extui_show(LV2_External_UI_Widget_Compat* handle)
  1319. {
  1320. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  1321. carla_debug("extui_show(%p)", handle);
  1322. handlePtr->handleUiShow();
  1323. }
  1324. static void extui_hide(LV2_External_UI_Widget_Compat* handle)
  1325. {
  1326. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  1327. carla_debug("extui_hide(%p)", handle);
  1328. handlePtr->handleUiHide();
  1329. }
  1330. #undef handlePtr
  1331. // ----------------------------------------------------------------------------------------------------------------
  1332. void clearTimeData() noexcept;
  1333. // ----------------------------------------------------------------------------------------------------------------
  1334. CARLA_DECLARE_NON_COPY_STRUCT(Lv2PluginBaseClass)
  1335. };
  1336. // --------------------------------------------------------------------------------------------------------------------
  1337. // Create new RDF object (using lilv)
  1338. static inline
  1339. const LV2_RDF_Descriptor* lv2_rdf_new(const LV2_URI uri, const bool loadPresets)
  1340. {
  1341. CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0', nullptr);
  1342. Lv2WorldClass& lv2World(Lv2WorldClass::getInstance());
  1343. const LilvPlugin* const cPlugin(lv2World.getPluginFromURI(uri));
  1344. CARLA_SAFE_ASSERT_RETURN(cPlugin != nullptr, nullptr);
  1345. Lilv::Plugin lilvPlugin(cPlugin);
  1346. LV2_RDF_Descriptor* const rdfDescriptor(new LV2_RDF_Descriptor());
  1347. // ----------------------------------------------------------------------------------------------------------------
  1348. // Set Plugin Type
  1349. {
  1350. Lilv::Nodes typeNodes(lilvPlugin.get_value(lv2World.rdf_type));
  1351. if (typeNodes.size() > 0)
  1352. {
  1353. if (typeNodes.contains(lv2World.class_allpass))
  1354. rdfDescriptor->Type[0] |= LV2_PLUGIN_ALLPASS;
  1355. if (typeNodes.contains(lv2World.class_amplifier))
  1356. rdfDescriptor->Type[0] |= LV2_PLUGIN_AMPLIFIER;
  1357. if (typeNodes.contains(lv2World.class_analyzer))
  1358. rdfDescriptor->Type[1] |= LV2_PLUGIN_ANALYSER;
  1359. if (typeNodes.contains(lv2World.class_bandpass))
  1360. rdfDescriptor->Type[0] |= LV2_PLUGIN_BANDPASS;
  1361. if (typeNodes.contains(lv2World.class_chorus))
  1362. rdfDescriptor->Type[1] |= LV2_PLUGIN_CHORUS;
  1363. if (typeNodes.contains(lv2World.class_comb))
  1364. rdfDescriptor->Type[1] |= LV2_PLUGIN_COMB;
  1365. if (typeNodes.contains(lv2World.class_compressor))
  1366. rdfDescriptor->Type[0] |= LV2_PLUGIN_COMPRESSOR;
  1367. if (typeNodes.contains(lv2World.class_constant))
  1368. rdfDescriptor->Type[1] |= LV2_PLUGIN_CONSTANT;
  1369. if (typeNodes.contains(lv2World.class_converter))
  1370. rdfDescriptor->Type[1] |= LV2_PLUGIN_CONVERTER;
  1371. if (typeNodes.contains(lv2World.class_delay))
  1372. rdfDescriptor->Type[0] |= LV2_PLUGIN_DELAY;
  1373. if (typeNodes.contains(lv2World.class_distortion))
  1374. rdfDescriptor->Type[0] |= LV2_PLUGIN_DISTORTION;
  1375. if (typeNodes.contains(lv2World.class_dynamics))
  1376. rdfDescriptor->Type[0] |= LV2_PLUGIN_DYNAMICS;
  1377. if (typeNodes.contains(lv2World.class_eq))
  1378. rdfDescriptor->Type[0] |= LV2_PLUGIN_EQ;
  1379. if (typeNodes.contains(lv2World.class_envelope))
  1380. rdfDescriptor->Type[0] |= LV2_PLUGIN_ENVELOPE;
  1381. if (typeNodes.contains(lv2World.class_expander))
  1382. rdfDescriptor->Type[0] |= LV2_PLUGIN_EXPANDER;
  1383. if (typeNodes.contains(lv2World.class_filter))
  1384. rdfDescriptor->Type[0] |= LV2_PLUGIN_FILTER;
  1385. if (typeNodes.contains(lv2World.class_flanger))
  1386. rdfDescriptor->Type[1] |= LV2_PLUGIN_FLANGER;
  1387. if (typeNodes.contains(lv2World.class_function))
  1388. rdfDescriptor->Type[1] |= LV2_PLUGIN_FUNCTION;
  1389. if (typeNodes.contains(lv2World.class_gate))
  1390. rdfDescriptor->Type[0] |= LV2_PLUGIN_GATE;
  1391. if (typeNodes.contains(lv2World.class_generator))
  1392. rdfDescriptor->Type[1] |= LV2_PLUGIN_GENERATOR;
  1393. if (typeNodes.contains(lv2World.class_highpass))
  1394. rdfDescriptor->Type[0] |= LV2_PLUGIN_HIGHPASS;
  1395. if (typeNodes.contains(lv2World.class_instrument))
  1396. rdfDescriptor->Type[1] |= LV2_PLUGIN_INSTRUMENT;
  1397. if (typeNodes.contains(lv2World.class_limiter))
  1398. rdfDescriptor->Type[0] |= LV2_PLUGIN_LIMITER;
  1399. if (typeNodes.contains(lv2World.class_lowpass))
  1400. rdfDescriptor->Type[0] |= LV2_PLUGIN_LOWPASS;
  1401. if (typeNodes.contains(lv2World.class_mixer))
  1402. rdfDescriptor->Type[1] |= LV2_PLUGIN_MIXER;
  1403. if (typeNodes.contains(lv2World.class_modulator))
  1404. rdfDescriptor->Type[1] |= LV2_PLUGIN_MODULATOR;
  1405. if (typeNodes.contains(lv2World.class_multiEQ))
  1406. rdfDescriptor->Type[0] |= LV2_PLUGIN_MULTI_EQ;
  1407. if (typeNodes.contains(lv2World.class_oscillator))
  1408. rdfDescriptor->Type[1] |= LV2_PLUGIN_OSCILLATOR;
  1409. if (typeNodes.contains(lv2World.class_paraEQ))
  1410. rdfDescriptor->Type[0] |= LV2_PLUGIN_PARA_EQ;
  1411. if (typeNodes.contains(lv2World.class_phaser))
  1412. rdfDescriptor->Type[1] |= LV2_PLUGIN_PHASER;
  1413. if (typeNodes.contains(lv2World.class_pitch))
  1414. rdfDescriptor->Type[1] |= LV2_PLUGIN_PITCH;
  1415. if (typeNodes.contains(lv2World.class_reverb))
  1416. rdfDescriptor->Type[0] |= LV2_PLUGIN_REVERB;
  1417. if (typeNodes.contains(lv2World.class_simulator))
  1418. rdfDescriptor->Type[0] |= LV2_PLUGIN_SIMULATOR;
  1419. if (typeNodes.contains(lv2World.class_spatial))
  1420. rdfDescriptor->Type[1] |= LV2_PLUGIN_SPATIAL;
  1421. if (typeNodes.contains(lv2World.class_spectral))
  1422. rdfDescriptor->Type[1] |= LV2_PLUGIN_SPECTRAL;
  1423. if (typeNodes.contains(lv2World.class_utility))
  1424. rdfDescriptor->Type[1] |= LV2_PLUGIN_UTILITY;
  1425. if (typeNodes.contains(lv2World.class_waveshaper))
  1426. rdfDescriptor->Type[0] |= LV2_PLUGIN_WAVESHAPER;
  1427. }
  1428. lilv_nodes_free(const_cast<LilvNodes*>(typeNodes.me));
  1429. }
  1430. // ----------------------------------------------------------------------------------------------------------------
  1431. // Set Plugin Information
  1432. {
  1433. rdfDescriptor->URI = carla_strdup(uri);
  1434. if (LilvNode* const nameNode = lilv_plugin_get_name(lilvPlugin.me))
  1435. {
  1436. if (const char* const name = lilv_node_as_string(nameNode))
  1437. rdfDescriptor->Name = carla_strdup(name);
  1438. lilv_node_free(nameNode);
  1439. }
  1440. if (const char* const author = lilvPlugin.get_author_name().as_string())
  1441. rdfDescriptor->Author = carla_strdup(author);
  1442. if (const char* const binary = lilvPlugin.get_library_uri().as_string())
  1443. rdfDescriptor->Binary = carla_strdup_free(lilv_file_uri_parse(binary, nullptr));
  1444. if (const char* const bundle = lilvPlugin.get_bundle_uri().as_string())
  1445. rdfDescriptor->Bundle = carla_strdup_free(lilv_file_uri_parse(bundle, nullptr));
  1446. Lilv::Nodes licenseNodes(lilvPlugin.get_value(lv2World.doap_license));
  1447. if (licenseNodes.size() > 0)
  1448. {
  1449. if (const char* const license = licenseNodes.get_first().as_string())
  1450. rdfDescriptor->License = carla_strdup(license);
  1451. }
  1452. lilv_nodes_free(const_cast<LilvNodes*>(licenseNodes.me));
  1453. }
  1454. // ----------------------------------------------------------------------------------------------------------------
  1455. // Set Plugin UniqueID
  1456. {
  1457. Lilv::Nodes replaceNodes(lilvPlugin.get_value(lv2World.dct_replaces));
  1458. if (replaceNodes.size() > 0)
  1459. {
  1460. Lilv::Node replaceNode(replaceNodes.get_first());
  1461. if (replaceNode.is_uri())
  1462. {
  1463. #ifdef USE_QT
  1464. const QString replaceURI(replaceNode.as_uri());
  1465. if (replaceURI.startsWith("urn:"))
  1466. {
  1467. const QString replaceId(replaceURI.split(":").last());
  1468. bool ok;
  1469. const ulong uniqueId(replaceId.toULong(&ok));
  1470. if (ok && uniqueId != 0)
  1471. rdfDescriptor->UniqueID = uniqueId;
  1472. }
  1473. #else
  1474. const water::String replaceURI(replaceNode.as_uri());
  1475. if (replaceURI.startsWith("urn:"))
  1476. {
  1477. const int uniqueId(replaceURI.getTrailingIntValue());
  1478. if (uniqueId > 0)
  1479. rdfDescriptor->UniqueID = static_cast<ulong>(uniqueId);
  1480. }
  1481. #endif
  1482. }
  1483. }
  1484. lilv_nodes_free(const_cast<LilvNodes*>(replaceNodes.me));
  1485. }
  1486. // ----------------------------------------------------------------------------------------------------------------
  1487. // Set Plugin Ports
  1488. if (const uint numPorts = lilvPlugin.get_num_ports())
  1489. {
  1490. rdfDescriptor->PortCount = numPorts;
  1491. rdfDescriptor->Ports = new LV2_RDF_Port[numPorts];
  1492. for (uint i = 0; i < numPorts; ++i)
  1493. {
  1494. Lilv::Port lilvPort(lilvPlugin.get_port_by_index(i));
  1495. LV2_RDF_Port* const rdfPort(&rdfDescriptor->Ports[i]);
  1496. // --------------------------------------------------------------------------------------------------------
  1497. // Set Port Information
  1498. {
  1499. if (LilvNode* const nameNode = lilv_port_get_name(lilvPlugin.me, lilvPort.me))
  1500. {
  1501. if (const char* const name = lilv_node_as_string(nameNode))
  1502. rdfPort->Name = carla_strdup(name);
  1503. lilv_node_free(nameNode);
  1504. }
  1505. if (const char* const symbol = lilv_node_as_string(lilvPort.get_symbol()))
  1506. rdfPort->Symbol = carla_strdup(symbol);
  1507. }
  1508. // --------------------------------------------------------------------------------------------------------
  1509. // Set Port Mode and Type
  1510. {
  1511. // Input or Output
  1512. /**/ if (lilvPort.is_a(lv2World.port_input))
  1513. rdfPort->Types |= LV2_PORT_INPUT;
  1514. else if (lilvPort.is_a(lv2World.port_output))
  1515. rdfPort->Types |= LV2_PORT_OUTPUT;
  1516. else
  1517. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is not input or output", uri, rdfPort->Name);
  1518. // Data Type
  1519. /**/ if (lilvPort.is_a(lv2World.port_control))
  1520. {
  1521. rdfPort->Types |= LV2_PORT_CONTROL;
  1522. }
  1523. else if (lilvPort.is_a(lv2World.port_audio))
  1524. {
  1525. rdfPort->Types |= LV2_PORT_AUDIO;
  1526. }
  1527. else if (lilvPort.is_a(lv2World.port_cv))
  1528. {
  1529. rdfPort->Types |= LV2_PORT_CV;
  1530. }
  1531. else if (lilvPort.is_a(lv2World.port_atom))
  1532. {
  1533. rdfPort->Types |= LV2_PORT_ATOM;
  1534. Lilv::Nodes bufferTypeNodes(lilvPort.get_value(lv2World.atom_bufferType));
  1535. for (LilvIter* it = lilv_nodes_begin(bufferTypeNodes.me); ! lilv_nodes_is_end(bufferTypeNodes.me, it); it = lilv_nodes_next(bufferTypeNodes.me, it))
  1536. {
  1537. const Lilv::Node node(lilv_nodes_get(bufferTypeNodes.me, it));
  1538. CARLA_SAFE_ASSERT_CONTINUE(node.is_uri());
  1539. if (node.equals(lv2World.atom_sequence))
  1540. rdfPort->Types |= LV2_PORT_ATOM_SEQUENCE;
  1541. else
  1542. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses an unknown atom buffer type '%s'", uri, rdfPort->Name, node.as_uri());
  1543. }
  1544. Lilv::Nodes supportNodes(lilvPort.get_value(lv2World.atom_supports));
  1545. for (LilvIter* it = lilv_nodes_begin(supportNodes.me); ! lilv_nodes_is_end(supportNodes.me, it); it = lilv_nodes_next(supportNodes.me, it))
  1546. {
  1547. const Lilv::Node node(lilv_nodes_get(supportNodes.me, it));
  1548. CARLA_SAFE_ASSERT_CONTINUE(node.is_uri());
  1549. /**/ if (node.equals(lv2World.midi_event))
  1550. rdfPort->Types |= LV2_PORT_DATA_MIDI_EVENT;
  1551. else if (node.equals(lv2World.patch_message))
  1552. rdfPort->Types |= LV2_PORT_DATA_PATCH_MESSAGE;
  1553. else if (node.equals(lv2World.time_position))
  1554. rdfPort->Types |= LV2_PORT_DATA_TIME_POSITION;
  1555. #if 0
  1556. // something new we don't support yet?
  1557. else if (std::strstr(node.as_uri(), "lv2plug.in/") != nullptr)
  1558. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is of atom type but has unsupported data '%s'", uri, rdfPort->Name, node.as_uri());
  1559. #endif
  1560. }
  1561. lilv_nodes_free(const_cast<LilvNodes*>(bufferTypeNodes.me));
  1562. lilv_nodes_free(const_cast<LilvNodes*>(supportNodes.me));
  1563. }
  1564. else if (lilvPort.is_a(lv2World.port_event))
  1565. {
  1566. rdfPort->Types |= LV2_PORT_EVENT;
  1567. bool supported = false;
  1568. if (lilvPort.supports_event(lv2World.midi_event))
  1569. {
  1570. rdfPort->Types |= LV2_PORT_DATA_MIDI_EVENT;
  1571. supported = true;
  1572. }
  1573. if (lilvPort.supports_event(lv2World.patch_message))
  1574. {
  1575. rdfPort->Types |= LV2_PORT_DATA_PATCH_MESSAGE;
  1576. supported = true;
  1577. }
  1578. if (lilvPort.supports_event(lv2World.time_position))
  1579. {
  1580. rdfPort->Types |= LV2_PORT_DATA_TIME_POSITION;
  1581. supported = true;
  1582. }
  1583. if (! supported)
  1584. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is of event type but has unsupported data", uri, rdfPort->Name);
  1585. }
  1586. else if (lilvPort.is_a(lv2World.port_midi))
  1587. {
  1588. rdfPort->Types |= LV2_PORT_MIDI_LL;
  1589. rdfPort->Types |= LV2_PORT_DATA_MIDI_EVENT;
  1590. }
  1591. else
  1592. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' is of unkown data type", uri, rdfPort->Name);
  1593. }
  1594. // --------------------------------------------------------------------------------------------------------
  1595. // Set Port Properties
  1596. {
  1597. if (lilvPort.has_property(lv2World.pprop_optional))
  1598. rdfPort->Properties |= LV2_PORT_OPTIONAL;
  1599. if (lilvPort.has_property(lv2World.pprop_enumeration))
  1600. rdfPort->Properties |= LV2_PORT_ENUMERATION;
  1601. if (lilvPort.has_property(lv2World.pprop_integer))
  1602. rdfPort->Properties |= LV2_PORT_INTEGER;
  1603. if (lilvPort.has_property(lv2World.pprop_sampleRate))
  1604. rdfPort->Properties |= LV2_PORT_SAMPLE_RATE;
  1605. if (lilvPort.has_property(lv2World.pprop_toggled))
  1606. rdfPort->Properties |= LV2_PORT_TOGGLED;
  1607. if (lilvPort.has_property(lv2World.pprop_artifacts))
  1608. rdfPort->Properties |= LV2_PORT_CAUSES_ARTIFACTS;
  1609. if (lilvPort.has_property(lv2World.pprop_continuousCV))
  1610. rdfPort->Properties |= LV2_PORT_CONTINUOUS_CV;
  1611. if (lilvPort.has_property(lv2World.pprop_discreteCV))
  1612. rdfPort->Properties |= LV2_PORT_DISCRETE_CV;
  1613. if (lilvPort.has_property(lv2World.pprop_expensive))
  1614. rdfPort->Properties |= LV2_PORT_EXPENSIVE;
  1615. if (lilvPort.has_property(lv2World.pprop_strictBounds))
  1616. rdfPort->Properties |= LV2_PORT_STRICT_BOUNDS;
  1617. if (lilvPort.has_property(lv2World.pprop_logarithmic))
  1618. rdfPort->Properties |= LV2_PORT_LOGARITHMIC;
  1619. if (lilvPort.has_property(lv2World.pprop_notAutomatic))
  1620. rdfPort->Properties |= LV2_PORT_NOT_AUTOMATIC;
  1621. if (lilvPort.has_property(lv2World.pprop_notOnGUI))
  1622. rdfPort->Properties |= LV2_PORT_NOT_ON_GUI;
  1623. if (lilvPort.has_property(lv2World.pprop_trigger))
  1624. rdfPort->Properties |= LV2_PORT_TRIGGER;
  1625. if (lilvPort.has_property(lv2World.pprop_nonAutomable))
  1626. rdfPort->Properties |= LV2_PORT_NON_AUTOMABLE;
  1627. if (lilvPort.has_property(lv2World.reportsLatency))
  1628. rdfPort->Designation = LV2_PORT_DESIGNATION_LATENCY;
  1629. // no port properties set, check if using old/invalid ones
  1630. if (rdfPort->Properties == 0x0)
  1631. {
  1632. const Lilv::Node oldPropArtifacts(lv2World.new_uri(NS_devp "causesArtifacts"));
  1633. const Lilv::Node oldPropContinuousCV(lv2World.new_uri(NS_devp "continuousCV"));
  1634. const Lilv::Node oldPropDiscreteCV(lv2World.new_uri(NS_devp "discreteCV"));
  1635. const Lilv::Node oldPropExpensive(lv2World.new_uri(NS_devp "expensive"));
  1636. const Lilv::Node oldPropStrictBounds(lv2World.new_uri(NS_devp "hasStrictBounds"));
  1637. const Lilv::Node oldPropLogarithmic(lv2World.new_uri(NS_devp "logarithmic"));
  1638. const Lilv::Node oldPropNotAutomatic(lv2World.new_uri(NS_devp "notAutomatic"));
  1639. const Lilv::Node oldPropNotOnGUI(lv2World.new_uri(NS_devp "notOnGUI"));
  1640. const Lilv::Node oldPropTrigger(lv2World.new_uri(NS_devp "trigger"));
  1641. if (lilvPort.has_property(oldPropArtifacts))
  1642. {
  1643. rdfPort->Properties |= LV2_PORT_CAUSES_ARTIFACTS;
  1644. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'causesArtifacts'", uri, rdfPort->Name);
  1645. }
  1646. if (lilvPort.has_property(oldPropContinuousCV))
  1647. {
  1648. rdfPort->Properties |= LV2_PORT_CONTINUOUS_CV;
  1649. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'continuousCV'", uri, rdfPort->Name);
  1650. }
  1651. if (lilvPort.has_property(oldPropDiscreteCV))
  1652. {
  1653. rdfPort->Properties |= LV2_PORT_DISCRETE_CV;
  1654. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'discreteCV'", uri, rdfPort->Name);
  1655. }
  1656. if (lilvPort.has_property(oldPropExpensive))
  1657. {
  1658. rdfPort->Properties |= LV2_PORT_EXPENSIVE;
  1659. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'expensive'", uri, rdfPort->Name);
  1660. }
  1661. if (lilvPort.has_property(oldPropStrictBounds))
  1662. {
  1663. rdfPort->Properties |= LV2_PORT_STRICT_BOUNDS;
  1664. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'hasStrictBounds'", uri, rdfPort->Name);
  1665. }
  1666. if (lilvPort.has_property(oldPropLogarithmic))
  1667. {
  1668. rdfPort->Properties |= LV2_PORT_LOGARITHMIC;
  1669. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'logarithmic'", uri, rdfPort->Name);
  1670. }
  1671. if (lilvPort.has_property(oldPropNotAutomatic))
  1672. {
  1673. rdfPort->Properties |= LV2_PORT_NOT_AUTOMATIC;
  1674. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'notAutomatic'", uri, rdfPort->Name);
  1675. }
  1676. if (lilvPort.has_property(oldPropNotOnGUI))
  1677. {
  1678. rdfPort->Properties |= LV2_PORT_NOT_ON_GUI;
  1679. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'notOnGUI'", uri, rdfPort->Name);
  1680. }
  1681. if (lilvPort.has_property(oldPropTrigger))
  1682. {
  1683. rdfPort->Properties |= LV2_PORT_TRIGGER;
  1684. carla_stderr("lv2_rdf_new(\"%s\") - port '%s' uses old/invalid LV2 property for 'trigger'", uri, rdfPort->Name);
  1685. }
  1686. }
  1687. }
  1688. // --------------------------------------------------------------------------------------------------------
  1689. // Set Port Designation
  1690. {
  1691. if (LilvNode* const designationNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.designation.me))
  1692. {
  1693. if (const char* const designation = lilv_node_as_string(designationNode))
  1694. {
  1695. /**/ if (std::strcmp(designation, LV2_CORE__control) == 0)
  1696. rdfPort->Designation = LV2_PORT_DESIGNATION_CONTROL;
  1697. else if (std::strcmp(designation, LV2_CORE__enabled) == 0)
  1698. rdfPort->Designation = LV2_PORT_DESIGNATION_ENABLED;
  1699. else if (std::strcmp(designation, LV2_CORE__freeWheeling) == 0)
  1700. rdfPort->Designation = LV2_PORT_DESIGNATION_FREEWHEELING;
  1701. else if (std::strcmp(designation, LV2_CORE__latency) == 0)
  1702. rdfPort->Designation = LV2_PORT_DESIGNATION_LATENCY;
  1703. else if (std::strcmp(designation, LV2_PARAMETERS__sampleRate) == 0)
  1704. rdfPort->Designation = LV2_PORT_DESIGNATION_SAMPLE_RATE;
  1705. else if (std::strcmp(designation, LV2_TIME__bar) == 0)
  1706. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BAR;
  1707. else if (std::strcmp(designation, LV2_TIME__barBeat) == 0)
  1708. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BAR_BEAT;
  1709. else if (std::strcmp(designation, LV2_TIME__beat) == 0)
  1710. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEAT;
  1711. else if (std::strcmp(designation, LV2_TIME__beatUnit) == 0)
  1712. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEAT_UNIT;
  1713. else if (std::strcmp(designation, LV2_TIME__beatsPerBar) == 0)
  1714. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEATS_PER_BAR;
  1715. else if (std::strcmp(designation, LV2_TIME__beatsPerMinute) == 0)
  1716. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_BEATS_PER_MINUTE;
  1717. else if (std::strcmp(designation, LV2_TIME__frame) == 0)
  1718. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_FRAME;
  1719. else if (std::strcmp(designation, LV2_TIME__framesPerSecond) == 0)
  1720. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_FRAMES_PER_SECOND;
  1721. else if (std::strcmp(designation, LV2_TIME__speed) == 0)
  1722. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_SPEED;
  1723. else if (std::strcmp(designation, LV2_KXSTUDIO_PROPERTIES__TimePositionTicksPerBeat) == 0)
  1724. rdfPort->Designation = LV2_PORT_DESIGNATION_TIME_TICKS_PER_BEAT;
  1725. else if (std::strncmp(designation, LV2_PARAMETERS_PREFIX, std::strlen(LV2_PARAMETERS_PREFIX)) == 0)
  1726. pass();
  1727. else if (std::strncmp(designation, LV2_PORT_GROUPS_PREFIX, std::strlen(LV2_PORT_GROUPS_PREFIX)) == 0)
  1728. pass();
  1729. else
  1730. carla_stderr("lv2_rdf_new(\"%s\") - got unknown port designation '%s'", uri, designation);
  1731. }
  1732. lilv_node_free(designationNode);
  1733. }
  1734. }
  1735. // --------------------------------------------------------------------------------------------------------
  1736. // Set Port MIDI Map
  1737. {
  1738. if (LilvNode* const midiMapNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.mm_defaultControl.me))
  1739. {
  1740. if (lilv_node_is_blank(midiMapNode))
  1741. {
  1742. Lilv::Nodes midiMapTypeNodes(lv2World.find_nodes(midiMapNode, lv2World.mm_controlType, nullptr));
  1743. Lilv::Nodes midiMapNumberNodes(lv2World.find_nodes(midiMapNode, lv2World.mm_controlNumber, nullptr));
  1744. if (midiMapTypeNodes.size() == 1 && midiMapNumberNodes.size() == 1)
  1745. {
  1746. if (const char* const midiMapType = midiMapTypeNodes.get_first().as_string())
  1747. {
  1748. /**/ if (std::strcmp(midiMapType, LV2_MIDI_Map__CC) == 0)
  1749. rdfPort->MidiMap.Type = LV2_PORT_MIDI_MAP_CC;
  1750. else if (std::strcmp(midiMapType, LV2_MIDI_Map__NRPN) == 0)
  1751. rdfPort->MidiMap.Type = LV2_PORT_MIDI_MAP_NRPN;
  1752. else
  1753. carla_stderr("lv2_rdf_new(\"%s\") - got unknown port Midi-Map type '%s'", uri, midiMapType);
  1754. rdfPort->MidiMap.Number = static_cast<uint32_t>(midiMapNumberNodes.get_first().as_int());
  1755. }
  1756. }
  1757. lilv_nodes_free(const_cast<LilvNodes*>(midiMapTypeNodes.me));
  1758. lilv_nodes_free(const_cast<LilvNodes*>(midiMapNumberNodes.me));
  1759. }
  1760. lilv_node_free(midiMapNode);
  1761. }
  1762. // TODO - also check using new official MIDI API too
  1763. }
  1764. // --------------------------------------------------------------------------------------------------------
  1765. // Set Port Points
  1766. {
  1767. if (LilvNode* const defNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.value_default.me))
  1768. {
  1769. rdfPort->Points.Hints |= LV2_PORT_POINT_DEFAULT;
  1770. rdfPort->Points.Default = lilv_node_as_float(defNode);
  1771. lilv_node_free(defNode);
  1772. }
  1773. if (LilvNode* const minNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.value_minimum.me))
  1774. {
  1775. rdfPort->Points.Hints |= LV2_PORT_POINT_MINIMUM;
  1776. rdfPort->Points.Minimum = lilv_node_as_float(minNode);
  1777. lilv_node_free(minNode);
  1778. }
  1779. if (LilvNode* const maxNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.value_maximum.me))
  1780. {
  1781. rdfPort->Points.Hints |= LV2_PORT_POINT_MAXIMUM;
  1782. rdfPort->Points.Maximum = lilv_node_as_float(maxNode);
  1783. lilv_node_free(maxNode);
  1784. }
  1785. }
  1786. // --------------------------------------------------------------------------------------------------------
  1787. // Set Port Unit
  1788. {
  1789. if (LilvNode* const unitUnitNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.unit_unit.me))
  1790. {
  1791. if (lilv_node_is_uri(unitUnitNode))
  1792. {
  1793. if (const char* const unitUnit = lilv_node_as_uri(unitUnitNode))
  1794. {
  1795. rdfPort->Unit.Hints |= LV2_PORT_UNIT_UNIT;
  1796. /**/ if (std::strcmp(unitUnit, LV2_UNITS__bar) == 0)
  1797. rdfPort->Unit.Unit = LV2_PORT_UNIT_BAR;
  1798. else if (std::strcmp(unitUnit, LV2_UNITS__beat) == 0)
  1799. rdfPort->Unit.Unit = LV2_PORT_UNIT_BEAT;
  1800. else if (std::strcmp(unitUnit, LV2_UNITS__bpm) == 0)
  1801. rdfPort->Unit.Unit = LV2_PORT_UNIT_BPM;
  1802. else if (std::strcmp(unitUnit, LV2_UNITS__cent) == 0)
  1803. rdfPort->Unit.Unit = LV2_PORT_UNIT_CENT;
  1804. else if (std::strcmp(unitUnit, LV2_UNITS__cm) == 0)
  1805. rdfPort->Unit.Unit = LV2_PORT_UNIT_CM;
  1806. else if (std::strcmp(unitUnit, LV2_UNITS__coef) == 0)
  1807. rdfPort->Unit.Unit = LV2_PORT_UNIT_COEF;
  1808. else if (std::strcmp(unitUnit, LV2_UNITS__db) == 0)
  1809. rdfPort->Unit.Unit = LV2_PORT_UNIT_DB;
  1810. else if (std::strcmp(unitUnit, LV2_UNITS__degree) == 0)
  1811. rdfPort->Unit.Unit = LV2_PORT_UNIT_DEGREE;
  1812. else if (std::strcmp(unitUnit, LV2_UNITS__frame) == 0)
  1813. rdfPort->Unit.Unit = LV2_PORT_UNIT_FRAME;
  1814. else if (std::strcmp(unitUnit, LV2_UNITS__hz) == 0)
  1815. rdfPort->Unit.Unit = LV2_PORT_UNIT_HZ;
  1816. else if (std::strcmp(unitUnit, LV2_UNITS__inch) == 0)
  1817. rdfPort->Unit.Unit = LV2_PORT_UNIT_INCH;
  1818. else if (std::strcmp(unitUnit, LV2_UNITS__khz) == 0)
  1819. rdfPort->Unit.Unit = LV2_PORT_UNIT_KHZ;
  1820. else if (std::strcmp(unitUnit, LV2_UNITS__km) == 0)
  1821. rdfPort->Unit.Unit = LV2_PORT_UNIT_KM;
  1822. else if (std::strcmp(unitUnit, LV2_UNITS__m) == 0)
  1823. rdfPort->Unit.Unit = LV2_PORT_UNIT_M;
  1824. else if (std::strcmp(unitUnit, LV2_UNITS__mhz) == 0)
  1825. rdfPort->Unit.Unit = LV2_PORT_UNIT_MHZ;
  1826. else if (std::strcmp(unitUnit, LV2_UNITS__midiNote) == 0)
  1827. rdfPort->Unit.Unit = LV2_PORT_UNIT_MIDINOTE;
  1828. else if (std::strcmp(unitUnit, LV2_UNITS__mile) == 0)
  1829. rdfPort->Unit.Unit = LV2_PORT_UNIT_MILE;
  1830. else if (std::strcmp(unitUnit, LV2_UNITS__min) == 0)
  1831. rdfPort->Unit.Unit = LV2_PORT_UNIT_MIN;
  1832. else if (std::strcmp(unitUnit, LV2_UNITS__mm) == 0)
  1833. rdfPort->Unit.Unit = LV2_PORT_UNIT_MM;
  1834. else if (std::strcmp(unitUnit, LV2_UNITS__ms) == 0)
  1835. rdfPort->Unit.Unit = LV2_PORT_UNIT_MS;
  1836. else if (std::strcmp(unitUnit, LV2_UNITS__oct) == 0)
  1837. rdfPort->Unit.Unit = LV2_PORT_UNIT_OCT;
  1838. else if (std::strcmp(unitUnit, LV2_UNITS__pc) == 0)
  1839. rdfPort->Unit.Unit = LV2_PORT_UNIT_PC;
  1840. else if (std::strcmp(unitUnit, LV2_UNITS__s) == 0)
  1841. rdfPort->Unit.Unit = LV2_PORT_UNIT_S;
  1842. else if (std::strcmp(unitUnit, LV2_UNITS__semitone12TET) == 0)
  1843. rdfPort->Unit.Unit = LV2_PORT_UNIT_SEMITONE;
  1844. else
  1845. carla_stderr("lv2_rdf_new(\"%s\") - got unknown unit unit '%s'", uri, unitUnit);
  1846. }
  1847. }
  1848. if (LilvNode* const unitNameNode = lilv_world_get(lv2World.me, unitUnitNode, lv2World.unit_name.me, nullptr))
  1849. {
  1850. if (const char* const unitName = lilv_node_as_string(unitNameNode))
  1851. {
  1852. rdfPort->Unit.Hints |= LV2_PORT_UNIT_NAME;
  1853. rdfPort->Unit.Name = carla_strdup(unitName);
  1854. }
  1855. lilv_node_free(unitNameNode);
  1856. }
  1857. if (LilvNode* const unitRenderNode = lilv_world_get(lv2World.me, unitUnitNode, lv2World.unit_render.me, nullptr))
  1858. {
  1859. if (const char* const unitRender = lilv_node_as_string(unitRenderNode))
  1860. {
  1861. rdfPort->Unit.Hints |= LV2_PORT_UNIT_RENDER;
  1862. rdfPort->Unit.Render = carla_strdup(unitRender);
  1863. }
  1864. lilv_node_free(unitRenderNode);
  1865. }
  1866. if (LilvNode* const unitSymbolNode = lilv_world_get(lv2World.me, unitUnitNode, lv2World.unit_symbol.me, nullptr))
  1867. {
  1868. if (const char* const unitSymbol = lilv_node_as_string(unitSymbolNode))
  1869. {
  1870. rdfPort->Unit.Hints |= LV2_PORT_UNIT_SYMBOL;
  1871. rdfPort->Unit.Symbol = carla_strdup(unitSymbol);
  1872. }
  1873. lilv_node_free(unitSymbolNode);
  1874. }
  1875. lilv_node_free(unitUnitNode);
  1876. }
  1877. }
  1878. // --------------------------------------------------------------------------------------------------------
  1879. // Set Port Minimum Size
  1880. {
  1881. if (LilvNode* const minimumSizeNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.rz_minSize.me))
  1882. {
  1883. const int minimumSize(lilv_node_as_int(minimumSizeNode));
  1884. if (minimumSize > 0)
  1885. rdfPort->MinimumSize = static_cast<uint32_t>(minimumSize);
  1886. else
  1887. carla_safe_assert_int("minimumSize > 0", __FILE__, __LINE__, minimumSize);
  1888. lilv_node_free(minimumSizeNode);
  1889. }
  1890. }
  1891. // --------------------------------------------------------------------------------------------------------
  1892. // Set Port Scale Points
  1893. {
  1894. Lilv::ScalePoints lilvScalePoints(lilvPort.get_scale_points());
  1895. if (const uint numScalePoints = lilvScalePoints.size())
  1896. {
  1897. rdfPort->ScalePointCount = numScalePoints;
  1898. rdfPort->ScalePoints = new LV2_RDF_PortScalePoint[numScalePoints];
  1899. // get all scalepoints and sort them by value
  1900. LilvScalePointMap sortedpoints;
  1901. LILV_FOREACH(scale_points, it, lilvScalePoints)
  1902. {
  1903. Lilv::ScalePoint lilvScalePoint(lilvScalePoints.get(it));
  1904. CARLA_SAFE_ASSERT_CONTINUE(lilvScalePoint.get_label() != nullptr);
  1905. if (const LilvNode* const valuenode = lilvScalePoint.get_value())
  1906. {
  1907. const double valueid = lilv_node_as_float(valuenode);
  1908. sortedpoints[valueid] = lilvScalePoint.me;
  1909. }
  1910. }
  1911. // now safe to store, sorted by using std::map
  1912. uint h = 0;
  1913. for (LilvScalePointMap::iterator it=sortedpoints.begin(), end=sortedpoints.end(); it != end; ++it)
  1914. {
  1915. CARLA_SAFE_ASSERT_BREAK(h < numScalePoints);
  1916. LV2_RDF_PortScalePoint* const rdfScalePoint(&rdfPort->ScalePoints[h++]);
  1917. const LilvScalePoint* const scalepoint = it->second;
  1918. const LilvNode* const xlabel = lilv_scale_point_get_label(scalepoint);
  1919. const LilvNode* const xvalue = lilv_scale_point_get_value(scalepoint);
  1920. rdfScalePoint->Label = carla_strdup(lilv_node_as_string(xlabel));
  1921. rdfScalePoint->Value = lilv_node_as_float(xvalue);
  1922. }
  1923. }
  1924. lilv_nodes_free(const_cast<LilvNodes*>(lilvScalePoints.me));
  1925. }
  1926. }
  1927. }
  1928. // ----------------------------------------------------------------------------------------------------------------
  1929. // Set Plugin Parameters
  1930. {
  1931. Lilv::Nodes patchWritableNodes(lilvPlugin.get_value(lv2World.patch_writable));
  1932. if (const uint numParameters = patchWritableNodes.size())
  1933. {
  1934. rdfDescriptor->ParameterCount = numParameters;
  1935. rdfDescriptor->Parameters = new LV2_RDF_Parameter[numParameters];
  1936. uint h = 0;
  1937. LILV_FOREACH(nodes, it, patchWritableNodes)
  1938. {
  1939. CARLA_SAFE_ASSERT_BREAK(h < numParameters);
  1940. Lilv::Node patchWritableNode(patchWritableNodes.get(it));
  1941. LV2_RDF_Parameter* const rdfParam(&rdfDescriptor->Parameters[h++]);
  1942. CARLA_SAFE_ASSERT_CONTINUE(patchWritableNode.is_uri());
  1943. rdfParam->URI = carla_strdup(patchWritableNode.as_uri());
  1944. if (LilvNode* const label = lilv_world_get(lv2World.me, patchWritableNode,
  1945. lv2World.rdfs_range.me, nullptr))
  1946. {
  1947. rdfParam->Range = carla_strdup(lilv_node_as_string(label));
  1948. }
  1949. if (LilvNode* const label = lilv_world_get(lv2World.me, patchWritableNode,
  1950. lv2World.rdfs_label.me, nullptr))
  1951. {
  1952. rdfParam->Label = carla_strdup(lilv_node_as_string(label));
  1953. }
  1954. if (LilvNode* const comment = lilv_world_get(lv2World.me, patchWritableNode,
  1955. lv2World.rdfs_comment.me, nullptr))
  1956. {
  1957. rdfParam->Comment = carla_strdup(lilv_node_as_string(comment));
  1958. }
  1959. // TODO: MidiMap, Points, Unit;
  1960. }
  1961. }
  1962. lilv_nodes_free(const_cast<LilvNodes*>(patchWritableNodes.me));
  1963. }
  1964. // ----------------------------------------------------------------------------------------------------------------
  1965. // Set Plugin Presets
  1966. if (loadPresets)
  1967. {
  1968. Lilv::Nodes presetNodes(lilvPlugin.get_related(lv2World.preset_preset));
  1969. if (presetNodes.size() > 0)
  1970. {
  1971. // create a list of preset URIs (for sorting and unique-ness)
  1972. #ifdef USE_QT
  1973. QStringList presetListURIs;
  1974. LILV_FOREACH(nodes, it, presetNodes)
  1975. {
  1976. Lilv::Node presetNode(presetNodes.get(it));
  1977. QString presetURI(presetNode.as_uri());
  1978. if (! (presetURI.trimmed().isEmpty() || presetListURIs.contains(presetURI)))
  1979. presetListURIs.append(presetURI);
  1980. }
  1981. presetListURIs.sort();
  1982. rdfDescriptor->PresetCount = static_cast<uint32_t>(presetListURIs.count());
  1983. #else
  1984. water::StringArray presetListURIs;
  1985. LILV_FOREACH(nodes, it, presetNodes)
  1986. {
  1987. Lilv::Node presetNode(presetNodes.get(it));
  1988. water::String presetURI(presetNode.as_uri());
  1989. if (presetURI.trim().isNotEmpty())
  1990. presetListURIs.addIfNotAlreadyThere(presetURI);
  1991. }
  1992. presetListURIs.sortNatural();
  1993. rdfDescriptor->PresetCount = static_cast<uint32_t>(presetListURIs.size());
  1994. #endif
  1995. // create presets with unique URIs
  1996. rdfDescriptor->Presets = new LV2_RDF_Preset[rdfDescriptor->PresetCount];
  1997. // set preset data
  1998. LILV_FOREACH(nodes, it, presetNodes)
  1999. {
  2000. Lilv::Node presetNode(presetNodes.get(it));
  2001. const char* const presetURI(presetNode.as_uri());
  2002. CARLA_SAFE_ASSERT_CONTINUE(presetURI != nullptr && presetURI[0] != '\0');
  2003. // try to find label without loading the preset resource first
  2004. Lilv::Nodes presetLabelNodes(lv2World.find_nodes(presetNode, lv2World.rdfs_label, nullptr));
  2005. // failed, try loading resource
  2006. if (presetLabelNodes.size() == 0)
  2007. {
  2008. // if loading resource fails, skip this preset
  2009. if (lv2World.load_resource(presetNode) == -1)
  2010. continue;
  2011. // ok, let's try again
  2012. presetLabelNodes = lv2World.find_nodes(presetNode, lv2World.rdfs_label, nullptr);
  2013. }
  2014. if (presetLabelNodes.size() > 0)
  2015. {
  2016. #ifdef USE_QT
  2017. const int index(presetListURIs.indexOf(QString(presetURI)));
  2018. #else
  2019. const int index(presetListURIs.indexOf(water::String(presetURI)));
  2020. #endif
  2021. CARLA_SAFE_ASSERT_CONTINUE(index >= 0 && index < static_cast<int>(rdfDescriptor->PresetCount));
  2022. LV2_RDF_Preset* const rdfPreset(&rdfDescriptor->Presets[index]);
  2023. // ---------------------------------------------------
  2024. // Set Preset Information
  2025. rdfPreset->URI = carla_strdup(presetURI);
  2026. if (const char* const label = presetLabelNodes.get_first().as_string())
  2027. rdfPreset->Label = carla_strdup(label);
  2028. lilv_nodes_free(const_cast<LilvNodes*>(presetLabelNodes.me));
  2029. }
  2030. }
  2031. }
  2032. lilv_nodes_free(const_cast<LilvNodes*>(presetNodes.me));
  2033. }
  2034. // ----------------------------------------------------------------------------------------------------------------
  2035. // Set Plugin Features
  2036. {
  2037. Lilv::Nodes lilvFeatureNodes(lilvPlugin.get_supported_features());
  2038. if (const uint numFeatures = lilvFeatureNodes.size())
  2039. {
  2040. Lilv::Nodes lilvFeatureNodesR(lilvPlugin.get_required_features());
  2041. rdfDescriptor->FeatureCount = numFeatures;
  2042. rdfDescriptor->Features = new LV2_RDF_Feature[numFeatures];
  2043. uint h = 0;
  2044. LILV_FOREACH(nodes, it, lilvFeatureNodes)
  2045. {
  2046. CARLA_SAFE_ASSERT_BREAK(h < numFeatures);
  2047. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(it));
  2048. LV2_RDF_Feature* const rdfFeature(&rdfDescriptor->Features[h++]);
  2049. rdfFeature->Required = lilvFeatureNodesR.contains(lilvFeatureNode);
  2050. if (const char* const featureURI = lilvFeatureNode.as_uri())
  2051. rdfFeature->URI = carla_strdup(featureURI);
  2052. else
  2053. rdfFeature->URI = nullptr;
  2054. }
  2055. lilv_nodes_free(const_cast<LilvNodes*>(lilvFeatureNodesR.me));
  2056. }
  2057. lilv_nodes_free(const_cast<LilvNodes*>(lilvFeatureNodes.me));
  2058. }
  2059. // ----------------------------------------------------------------------------------------------------------------
  2060. // Set Plugin Extensions
  2061. {
  2062. Lilv::Nodes lilvExtensionDataNodes(lilvPlugin.get_extension_data());
  2063. if (const uint numExtensions = lilvExtensionDataNodes.size())
  2064. {
  2065. rdfDescriptor->ExtensionCount = numExtensions;
  2066. rdfDescriptor->Extensions = new LV2_URI[numExtensions];
  2067. uint h = 0;
  2068. LILV_FOREACH(nodes, it, lilvExtensionDataNodes)
  2069. {
  2070. CARLA_SAFE_ASSERT_BREAK(h < numExtensions);
  2071. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(it));
  2072. LV2_URI* const rdfExtension(&rdfDescriptor->Extensions[h++]);
  2073. if (lilvExtensionDataNode.is_uri())
  2074. {
  2075. if (const char* const extURI = lilvExtensionDataNode.as_uri())
  2076. {
  2077. *rdfExtension = carla_strdup(extURI);
  2078. continue;
  2079. }
  2080. }
  2081. *rdfExtension = nullptr;
  2082. }
  2083. for (uint32_t x=h; x < rdfDescriptor->ExtensionCount; ++x)
  2084. rdfDescriptor->Extensions[x] = nullptr;
  2085. }
  2086. lilv_nodes_free(const_cast<LilvNodes*>(lilvExtensionDataNodes.me));
  2087. }
  2088. // ----------------------------------------------------------------------------------------------------------------
  2089. // Set Plugin UIs
  2090. {
  2091. Lilv::UIs lilvUIs(lilvPlugin.get_uis());
  2092. if (const uint numUIs = lilvUIs.size())
  2093. {
  2094. rdfDescriptor->UICount = numUIs;
  2095. rdfDescriptor->UIs = new LV2_RDF_UI[numUIs];
  2096. uint h = 0;
  2097. LILV_FOREACH(uis, it, lilvUIs)
  2098. {
  2099. CARLA_SAFE_ASSERT_BREAK(h < numUIs);
  2100. Lilv::UI lilvUI(lilvUIs.get(it));
  2101. LV2_RDF_UI* const rdfUI(&rdfDescriptor->UIs[h++]);
  2102. lv2World.load_resource(lilvUI.get_uri());
  2103. // ----------------------------------------------------------------------------------------------------
  2104. // Set UI Type
  2105. /**/ if (lilvUI.is_a(lv2World.ui_gtk2))
  2106. rdfUI->Type = LV2_UI_GTK2;
  2107. else if (lilvUI.is_a(lv2World.ui_gtk3))
  2108. rdfUI->Type = LV2_UI_GTK3;
  2109. else if (lilvUI.is_a(lv2World.ui_qt4))
  2110. rdfUI->Type = LV2_UI_QT4;
  2111. else if (lilvUI.is_a(lv2World.ui_qt5))
  2112. rdfUI->Type = LV2_UI_QT5;
  2113. else if (lilvUI.is_a(lv2World.ui_cocoa))
  2114. rdfUI->Type = LV2_UI_COCOA;
  2115. else if (lilvUI.is_a(lv2World.ui_windows))
  2116. rdfUI->Type = LV2_UI_WINDOWS;
  2117. else if (lilvUI.is_a(lv2World.ui_x11))
  2118. rdfUI->Type = LV2_UI_X11;
  2119. else if (lilvUI.is_a(lv2World.ui_external))
  2120. rdfUI->Type = LV2_UI_EXTERNAL;
  2121. else if (lilvUI.is_a(lv2World.ui_externalOld))
  2122. rdfUI->Type = LV2_UI_OLD_EXTERNAL;
  2123. else if (lilvUI.is_a(lv2World.ui_externalOld2))
  2124. pass();
  2125. else
  2126. carla_stderr("lv2_rdf_new(\"%s\") - UI '%s' is of unknown type", uri, lilvUI.get_uri().as_uri());
  2127. // ----------------------------------------------------------------------------------------------------
  2128. // Set UI Information
  2129. {
  2130. if (const char* const uiURI = lilvUI.get_uri().as_uri())
  2131. rdfUI->URI = carla_strdup(uiURI);
  2132. if (const char* const uiBinary = lilvUI.get_binary_uri().as_string())
  2133. rdfUI->Binary = carla_strdup_free(lilv_file_uri_parse(uiBinary, nullptr));
  2134. if (const char* const uiBundle = lilvUI.get_bundle_uri().as_string())
  2135. rdfUI->Bundle = carla_strdup_free(lilv_file_uri_parse(uiBundle, nullptr));
  2136. }
  2137. // ----------------------------------------------------------------------------------------------------
  2138. // Set UI Features
  2139. {
  2140. Lilv::Nodes lilvFeatureNodes(lilvUI.get_supported_features());
  2141. if (const uint numFeatures = lilvFeatureNodes.size())
  2142. {
  2143. Lilv::Nodes lilvFeatureNodesR(lilvUI.get_required_features());
  2144. rdfUI->FeatureCount = numFeatures;
  2145. rdfUI->Features = new LV2_RDF_Feature[numFeatures];
  2146. uint h2 = 0;
  2147. LILV_FOREACH(nodes, it2, lilvFeatureNodes)
  2148. {
  2149. CARLA_SAFE_ASSERT_BREAK(h2 < numFeatures);
  2150. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(it2));
  2151. LV2_RDF_Feature* const rdfFeature(&rdfUI->Features[h2++]);
  2152. rdfFeature->Required = lilvFeatureNodesR.contains(lilvFeatureNode);
  2153. if (const char* const featureURI = lilvFeatureNode.as_uri())
  2154. rdfFeature->URI = carla_strdup(featureURI);
  2155. else
  2156. rdfFeature->URI = nullptr;
  2157. }
  2158. lilv_nodes_free(const_cast<LilvNodes*>(lilvFeatureNodesR.me));
  2159. }
  2160. lilv_nodes_free(const_cast<LilvNodes*>(lilvFeatureNodes.me));
  2161. }
  2162. // ----------------------------------------------------------------------------------------------------
  2163. // Set UI Extensions
  2164. {
  2165. Lilv::Nodes lilvExtensionDataNodes(lilvUI.get_extension_data());
  2166. if (const uint numExtensions = lilvExtensionDataNodes.size() > 0)
  2167. {
  2168. rdfUI->ExtensionCount = numExtensions;
  2169. rdfUI->Extensions = new LV2_URI[numExtensions];
  2170. uint h2 = 0;
  2171. LILV_FOREACH(nodes, it2, lilvExtensionDataNodes)
  2172. {
  2173. CARLA_SAFE_ASSERT_BREAK(h2 < numExtensions);
  2174. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(it2));
  2175. LV2_URI* const rdfExtension(&rdfUI->Extensions[h2++]);
  2176. if (lilvExtensionDataNode.is_uri())
  2177. {
  2178. if (const char* const extURI = lilvExtensionDataNode.as_uri())
  2179. {
  2180. *rdfExtension = carla_strdup(extURI);
  2181. continue;
  2182. }
  2183. }
  2184. *rdfExtension = nullptr;
  2185. }
  2186. for (uint x2=h2; x2 < rdfUI->ExtensionCount; ++x2)
  2187. rdfUI->Extensions[x2] = nullptr;
  2188. }
  2189. lilv_nodes_free(const_cast<LilvNodes*>(lilvExtensionDataNodes.me));
  2190. }
  2191. // ----------------------------------------------------------------------------------------------------
  2192. // Set UI Port Notifications
  2193. {
  2194. Lilv::Nodes portNotifNodes(lv2World.find_nodes(lilvUI.get_uri(), lv2World.ui_portNotif.me, nullptr));
  2195. if (const uint portNotifCount = portNotifNodes.size())
  2196. {
  2197. rdfUI->PortNotificationCount = portNotifCount;
  2198. rdfUI->PortNotifications = new LV2_RDF_UI_PortNotification[portNotifCount];
  2199. uint h2 = 0;
  2200. LILV_FOREACH(nodes, it2, portNotifNodes)
  2201. {
  2202. CARLA_SAFE_ASSERT_BREAK(h2 < portNotifCount);
  2203. Lilv::Node portNotifNode(portNotifNodes.get(it2));
  2204. LV2_RDF_UI_PortNotification* const rdfPortNotif(&rdfUI->PortNotifications[h2++]);
  2205. LilvNode* const protocolNode = lilv_world_get(lv2World.me, portNotifNode,
  2206. lv2World.ui_protocol.me, nullptr);
  2207. if (protocolNode != nullptr)
  2208. {
  2209. CARLA_SAFE_ASSERT_CONTINUE(lilv_node_is_uri(protocolNode));
  2210. const char* const protocol = lilv_node_as_uri(protocolNode);
  2211. CARLA_SAFE_ASSERT_CONTINUE(protocol != nullptr && protocol[0] != '\0');
  2212. /**/ if (std::strcmp(protocol, LV2_UI__floatProtocol) == 0)
  2213. rdfPortNotif->Protocol = LV2_UI_PORT_PROTOCOL_FLOAT;
  2214. else if (std::strcmp(protocol, LV2_UI__peakProtocol) == 0)
  2215. rdfPortNotif->Protocol = LV2_UI_PORT_PROTOCOL_PEAK;
  2216. }
  2217. else
  2218. {
  2219. rdfPortNotif->Protocol = LV2_UI_PORT_PROTOCOL_FLOAT;
  2220. }
  2221. /**/ if (LilvNode* const symbolNode = lilv_world_get(lv2World.me, portNotifNode,
  2222. lv2World.symbol.me, nullptr))
  2223. {
  2224. CARLA_SAFE_ASSERT_CONTINUE(lilv_node_is_string(symbolNode));
  2225. const char* const symbol = lilv_node_as_string(symbolNode);
  2226. CARLA_SAFE_ASSERT_CONTINUE(symbol != nullptr && symbol[0] != '\0');
  2227. rdfPortNotif->Symbol = carla_strdup(symbol);
  2228. lilv_node_free(symbolNode);
  2229. }
  2230. else if (LilvNode* const indexNode = lilv_world_get(lv2World.me, portNotifNode,
  2231. lv2World.ui_portIndex.me, nullptr))
  2232. {
  2233. CARLA_SAFE_ASSERT_CONTINUE(lilv_node_is_int(indexNode));
  2234. const int index = lilv_node_as_int(indexNode);
  2235. CARLA_SAFE_ASSERT_CONTINUE(index >= 0);
  2236. rdfPortNotif->Index = static_cast<uint32_t>(index);
  2237. lilv_node_free(indexNode);
  2238. }
  2239. lilv_node_free(protocolNode);
  2240. }
  2241. }
  2242. lilv_nodes_free(const_cast<LilvNodes*>(portNotifNodes.me));
  2243. }
  2244. }
  2245. }
  2246. lilv_nodes_free(const_cast<LilvNodes*>(lilvUIs.me));
  2247. }
  2248. return rdfDescriptor;
  2249. }
  2250. // --------------------------------------------------------------------------------------------------------------------
  2251. // Check if we support a plugin port
  2252. static inline
  2253. bool is_lv2_port_supported(const LV2_Property types) noexcept
  2254. {
  2255. if (LV2_IS_PORT_CONTROL(types))
  2256. return true;
  2257. if (LV2_IS_PORT_AUDIO(types))
  2258. return true;
  2259. if (LV2_IS_PORT_CV(types))
  2260. return true;
  2261. if (LV2_IS_PORT_ATOM_SEQUENCE(types))
  2262. return true;
  2263. if (LV2_IS_PORT_EVENT(types))
  2264. return true;
  2265. if (LV2_IS_PORT_MIDI_LL(types))
  2266. return true;
  2267. return false;
  2268. }
  2269. // --------------------------------------------------------------------------------------------------------------------
  2270. // Check if we support a plugin feature
  2271. static inline
  2272. bool is_lv2_feature_supported(const LV2_URI uri) noexcept
  2273. {
  2274. CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0', false);
  2275. if (std::strcmp(uri, LV2_BUF_SIZE__boundedBlockLength) == 0)
  2276. return true;
  2277. if (std::strcmp(uri, LV2_BUF_SIZE__fixedBlockLength) == 0)
  2278. return true;
  2279. if (std::strcmp(uri, LV2_BUF_SIZE__powerOf2BlockLength) == 0)
  2280. return true;
  2281. if (std::strcmp(uri, LV2_CORE__hardRTCapable) == 0)
  2282. return true;
  2283. if (std::strcmp(uri, LV2_CORE__inPlaceBroken) == 0)
  2284. return true;
  2285. if (std::strcmp(uri, LV2_CORE__isLive) == 0)
  2286. return true;
  2287. if (std::strcmp(uri, LV2_EVENT_URI) == 0)
  2288. return true;
  2289. if (std::strcmp(uri, LV2_LOG__log) == 0)
  2290. return true;
  2291. if (std::strcmp(uri, LV2_OPTIONS__options) == 0)
  2292. return true;
  2293. if (std::strcmp(uri, LV2_PROGRAMS__Host) == 0)
  2294. return true;
  2295. if (std::strcmp(uri, LV2_RESIZE_PORT__resize) == 0)
  2296. return true;
  2297. if (std::strcmp(uri, LV2_RTSAFE_MEMORY_POOL__Pool) == 0)
  2298. return true;
  2299. if (std::strcmp(uri, LV2_RTSAFE_MEMORY_POOL_DEPRECATED_URI) == 0)
  2300. return true;
  2301. if (std::strcmp(uri, LV2_STATE__loadDefaultState) == 0)
  2302. return true;
  2303. if (std::strcmp(uri, LV2_STATE__makePath) == 0)
  2304. return true;
  2305. if (std::strcmp(uri, LV2_STATE__mapPath) == 0)
  2306. return true;
  2307. if (std::strcmp(uri, LV2_PORT_PROPS__supportsStrictBounds) == 0)
  2308. return true;
  2309. if (std::strcmp(uri, LV2_URI_MAP_URI) == 0)
  2310. return true;
  2311. if (std::strcmp(uri, LV2_URID__map) == 0)
  2312. return true;
  2313. if (std::strcmp(uri, LV2_URID__unmap) == 0)
  2314. return true;
  2315. if (std::strcmp(uri, LV2_WORKER__schedule) == 0)
  2316. return true;
  2317. return false;
  2318. }
  2319. // --------------------------------------------------------------------------------------------------------------------
  2320. // Check if we support a plugin or UI feature
  2321. static inline
  2322. bool is_lv2_ui_feature_supported(const LV2_URI uri) noexcept
  2323. {
  2324. CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0', false);
  2325. if (is_lv2_feature_supported(uri))
  2326. return true;
  2327. #ifndef BUILD_BRIDGE_UI
  2328. if (std::strcmp(uri, LV2_DATA_ACCESS_URI) == 0)
  2329. return true;
  2330. if (std::strcmp(uri, LV2_INSTANCE_ACCESS_URI) == 0)
  2331. return true;
  2332. #endif
  2333. if (std::strcmp(uri, LV2_UI__fixedSize) == 0)
  2334. return true;
  2335. if (std::strcmp(uri, LV2_UI__idleInterface) == 0)
  2336. return true;
  2337. if (std::strcmp(uri, LV2_UI__makeResident) == 0)
  2338. return true;
  2339. if (std::strcmp(uri, LV2_UI__makeSONameResident) == 0)
  2340. return true;
  2341. if (std::strcmp(uri, LV2_UI__noUserResize) == 0)
  2342. return true;
  2343. if (std::strcmp(uri, LV2_UI__parent) == 0)
  2344. return true;
  2345. if (std::strcmp(uri, LV2_UI__portMap) == 0)
  2346. return true;
  2347. if (std::strcmp(uri, LV2_UI__portSubscribe) == 0)
  2348. return true;
  2349. if (std::strcmp(uri, LV2_UI__resize) == 0)
  2350. return true;
  2351. if (std::strcmp(uri, LV2_UI__touch) == 0)
  2352. return true;
  2353. if (std::strcmp(uri, LV2_EXTERNAL_UI__Widget) == 0)
  2354. return true;
  2355. if (std::strcmp(uri, LV2_EXTERNAL_UI_DEPRECATED_URI) == 0)
  2356. return true;
  2357. return false;
  2358. }
  2359. // --------------------------------------------------------------------------------------------------------------------
  2360. #endif // CARLA_LV2_UTILS_HPP_INCLUDED