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.

3230 lines
133KB

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