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.

CarlaLv2Utils.hpp 66KB

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