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.

2716 lines
109KB

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