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.

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