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 64KB

11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
11 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
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
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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515
  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 LV2_MIDI_Map__CC "http://ll-plugins.nongnu.org/lv2/namespace#CC"
  84. #define LV2_MIDI_Map__NRPN "http://ll-plugins.nongnu.org/lv2/namespace#NRPN"
  85. #define LV2_MIDI_LL__MidiPort "http://ll-plugins.nongnu.org/lv2/ext/MidiPort"
  86. #define LV2_UI__Qt5UI LV2_UI_PREFIX "Qt5UI"
  87. #define LV2_UI__makeResident LV2_UI_PREFIX "makeResident"
  88. // -----------------------------------------------------------------------
  89. // Custom Atom types
  90. struct LV2_Atom_MidiEvent {
  91. LV2_Atom atom; /**< Atom header. */
  92. uint8_t data[4]; /**< MIDI data (body). */
  93. };
  94. static inline
  95. uint32_t lv2_atom_total_size(const LV2_Atom_MidiEvent& midiEv)
  96. {
  97. return static_cast<uint32_t>(sizeof(LV2_Atom)) + midiEv.atom.size;
  98. }
  99. // -----------------------------------------------------------------------
  100. // Our LV2 World class
  101. class Lv2WorldClass : public Lilv::World
  102. {
  103. public:
  104. // Base Types
  105. Lilv::Node port;
  106. Lilv::Node symbol;
  107. Lilv::Node designation;
  108. Lilv::Node freeWheeling;
  109. Lilv::Node reportsLatency;
  110. // Plugin Types
  111. Lilv::Node class_allpass;
  112. Lilv::Node class_amplifier;
  113. Lilv::Node class_analyzer;
  114. Lilv::Node class_bandpass;
  115. Lilv::Node class_chorus;
  116. Lilv::Node class_comb;
  117. Lilv::Node class_compressor;
  118. Lilv::Node class_constant;
  119. Lilv::Node class_converter;
  120. Lilv::Node class_delay;
  121. Lilv::Node class_distortion;
  122. Lilv::Node class_dynamics;
  123. Lilv::Node class_eq;
  124. Lilv::Node class_envelope;
  125. Lilv::Node class_expander;
  126. Lilv::Node class_filter;
  127. Lilv::Node class_flanger;
  128. Lilv::Node class_function;
  129. Lilv::Node class_gate;
  130. Lilv::Node class_generator;
  131. Lilv::Node class_highpass;
  132. Lilv::Node class_instrument;
  133. Lilv::Node class_limiter;
  134. Lilv::Node class_lowpass;
  135. Lilv::Node class_mixer;
  136. Lilv::Node class_modulator;
  137. Lilv::Node class_multiEQ;
  138. Lilv::Node class_oscillator;
  139. Lilv::Node class_paraEQ;
  140. Lilv::Node class_phaser;
  141. Lilv::Node class_pitch;
  142. Lilv::Node class_reverb;
  143. Lilv::Node class_simulator;
  144. Lilv::Node class_spatial;
  145. Lilv::Node class_spectral;
  146. Lilv::Node class_utility;
  147. Lilv::Node class_waveshaper;
  148. // Port Types
  149. Lilv::Node port_input;
  150. Lilv::Node port_output;
  151. Lilv::Node port_control;
  152. Lilv::Node port_audio;
  153. Lilv::Node port_cv;
  154. Lilv::Node port_atom;
  155. Lilv::Node port_event;
  156. Lilv::Node port_midi;
  157. // Port Properties
  158. Lilv::Node pprop_optional;
  159. Lilv::Node pprop_enumeration;
  160. Lilv::Node pprop_integer;
  161. Lilv::Node pprop_sampleRate;
  162. Lilv::Node pprop_toggled;
  163. Lilv::Node pprop_artifacts;
  164. Lilv::Node pprop_continuousCV;
  165. Lilv::Node pprop_discreteCV;
  166. Lilv::Node pprop_expensive;
  167. Lilv::Node pprop_strictBounds;
  168. Lilv::Node pprop_logarithmic;
  169. Lilv::Node pprop_notAutomatic;
  170. Lilv::Node pprop_notOnGUI;
  171. Lilv::Node pprop_trigger;
  172. Lilv::Node pprop_nonAutomable;
  173. // Unit Hints
  174. Lilv::Node unit_name;
  175. Lilv::Node unit_render;
  176. Lilv::Node unit_symbol;
  177. Lilv::Node unit_unit;
  178. // UI Types
  179. Lilv::Node ui_gtk2;
  180. Lilv::Node ui_gtk3;
  181. Lilv::Node ui_qt4;
  182. Lilv::Node ui_qt5;
  183. Lilv::Node ui_cocoa;
  184. Lilv::Node ui_windows;
  185. Lilv::Node ui_x11;
  186. Lilv::Node ui_external;
  187. Lilv::Node ui_externalOld;
  188. Lilv::Node ui_externalOld2;
  189. // Misc
  190. Lilv::Node atom_bufferType;
  191. Lilv::Node atom_sequence;
  192. Lilv::Node atom_supports;
  193. Lilv::Node preset_preset;
  194. Lilv::Node state_state;
  195. Lilv::Node value_default;
  196. Lilv::Node value_minimum;
  197. Lilv::Node value_maximum;
  198. Lilv::Node rz_asLargeAs;
  199. Lilv::Node rz_minSize;
  200. // Port Data Types
  201. Lilv::Node midi_event;
  202. Lilv::Node patch_message;
  203. Lilv::Node time_position;
  204. // MIDI CC
  205. Lilv::Node mm_defaultControl;
  206. Lilv::Node mm_controlType;
  207. Lilv::Node mm_controlNumber;
  208. // Other
  209. Lilv::Node dct_replaces;
  210. Lilv::Node doap_license;
  211. Lilv::Node rdf_type;
  212. Lilv::Node rdfs_label;
  213. bool needsInit;
  214. // -------------------------------------------------------------------
  215. Lv2WorldClass()
  216. : Lilv::World(),
  217. port (new_uri(LV2_CORE__port)),
  218. symbol (new_uri(LV2_CORE__symbol)),
  219. designation (new_uri(LV2_CORE__designation)),
  220. freeWheeling (new_uri(LV2_CORE__freeWheeling)),
  221. reportsLatency (new_uri(LV2_CORE__reportsLatency)),
  222. class_allpass (new_uri(LV2_CORE__AllpassPlugin)),
  223. class_amplifier (new_uri(LV2_CORE__AmplifierPlugin)),
  224. class_analyzer (new_uri(LV2_CORE__AnalyserPlugin)),
  225. class_bandpass (new_uri(LV2_CORE__BandpassPlugin)),
  226. class_chorus (new_uri(LV2_CORE__ChorusPlugin)),
  227. class_comb (new_uri(LV2_CORE__CombPlugin)),
  228. class_compressor (new_uri(LV2_CORE__CompressorPlugin)),
  229. class_constant (new_uri(LV2_CORE__ConstantPlugin)),
  230. class_converter (new_uri(LV2_CORE__ConverterPlugin)),
  231. class_delay (new_uri(LV2_CORE__DelayPlugin)),
  232. class_distortion (new_uri(LV2_CORE__DistortionPlugin)),
  233. class_dynamics (new_uri(LV2_CORE__DynamicsPlugin)),
  234. class_eq (new_uri(LV2_CORE__EQPlugin)),
  235. class_envelope (new_uri(LV2_CORE__EnvelopePlugin)),
  236. class_expander (new_uri(LV2_CORE__ExpanderPlugin)),
  237. class_filter (new_uri(LV2_CORE__FilterPlugin)),
  238. class_flanger (new_uri(LV2_CORE__FlangerPlugin)),
  239. class_function (new_uri(LV2_CORE__FunctionPlugin)),
  240. class_gate (new_uri(LV2_CORE__GatePlugin)),
  241. class_generator (new_uri(LV2_CORE__GeneratorPlugin)),
  242. class_highpass (new_uri(LV2_CORE__HighpassPlugin)),
  243. class_instrument (new_uri(LV2_CORE__InstrumentPlugin)),
  244. class_limiter (new_uri(LV2_CORE__LimiterPlugin)),
  245. class_lowpass (new_uri(LV2_CORE__LowpassPlugin)),
  246. class_mixer (new_uri(LV2_CORE__MixerPlugin)),
  247. class_modulator (new_uri(LV2_CORE__ModulatorPlugin)),
  248. class_multiEQ (new_uri(LV2_CORE__MultiEQPlugin)),
  249. class_oscillator (new_uri(LV2_CORE__OscillatorPlugin)),
  250. class_paraEQ (new_uri(LV2_CORE__ParaEQPlugin)),
  251. class_phaser (new_uri(LV2_CORE__PhaserPlugin)),
  252. class_pitch (new_uri(LV2_CORE__PitchPlugin)),
  253. class_reverb (new_uri(LV2_CORE__ReverbPlugin)),
  254. class_simulator (new_uri(LV2_CORE__SimulatorPlugin)),
  255. class_spatial (new_uri(LV2_CORE__SpatialPlugin)),
  256. class_spectral (new_uri(LV2_CORE__SpectralPlugin)),
  257. class_utility (new_uri(LV2_CORE__UtilityPlugin)),
  258. class_waveshaper (new_uri(LV2_CORE__WaveshaperPlugin)),
  259. port_input (new_uri(LV2_CORE__InputPort)),
  260. port_output (new_uri(LV2_CORE__OutputPort)),
  261. port_control (new_uri(LV2_CORE__ControlPort)),
  262. port_audio (new_uri(LV2_CORE__AudioPort)),
  263. port_cv (new_uri(LV2_CORE__CVPort)),
  264. port_atom (new_uri(LV2_ATOM__AtomPort)),
  265. port_event (new_uri(LV2_EVENT__EventPort)),
  266. port_midi (new_uri(LV2_MIDI_LL__MidiPort)),
  267. pprop_optional (new_uri(LV2_CORE__connectionOptional)),
  268. pprop_enumeration (new_uri(LV2_CORE__enumeration)),
  269. pprop_integer (new_uri(LV2_CORE__integer)),
  270. pprop_sampleRate (new_uri(LV2_CORE__sampleRate)),
  271. pprop_toggled (new_uri(LV2_CORE__toggled)),
  272. pprop_artifacts (new_uri(LV2_PORT_PROPS__causesArtifacts)),
  273. pprop_continuousCV (new_uri(LV2_PORT_PROPS__continuousCV)),
  274. pprop_discreteCV (new_uri(LV2_PORT_PROPS__discreteCV)),
  275. pprop_expensive (new_uri(LV2_PORT_PROPS__expensive)),
  276. pprop_strictBounds (new_uri(LV2_PORT_PROPS__hasStrictBounds)),
  277. pprop_logarithmic (new_uri(LV2_PORT_PROPS__logarithmic)),
  278. pprop_notAutomatic (new_uri(LV2_PORT_PROPS__notAutomatic)),
  279. pprop_notOnGUI (new_uri(LV2_PORT_PROPS__notOnGUI)),
  280. pprop_trigger (new_uri(LV2_PORT_PROPS__trigger)),
  281. pprop_nonAutomable (new_uri(LV2_KXSTUDIO_PROPERTIES__NonAutomable)),
  282. unit_name (new_uri(LV2_UNITS__name)),
  283. unit_render (new_uri(LV2_UNITS__render)),
  284. unit_symbol (new_uri(LV2_UNITS__symbol)),
  285. unit_unit (new_uri(LV2_UNITS__unit)),
  286. ui_gtk2 (new_uri(LV2_UI__GtkUI)),
  287. ui_gtk3 (new_uri(LV2_UI__Gtk3UI)),
  288. ui_qt4 (new_uri(LV2_UI__Qt4UI)),
  289. ui_qt5 (new_uri(LV2_UI__Qt5UI)),
  290. ui_cocoa (new_uri(LV2_UI__CocoaUI)),
  291. ui_windows (new_uri(LV2_UI__WindowsUI)),
  292. ui_x11 (new_uri(LV2_UI__X11UI)),
  293. ui_external (new_uri(LV2_EXTERNAL_UI__Widget)),
  294. ui_externalOld (new_uri(LV2_EXTERNAL_UI_DEPRECATED_URI)),
  295. ui_externalOld2 (new_uri("http://nedko.arnaudov.name/lv2/external_ui/")),
  296. atom_bufferType (new_uri(LV2_ATOM__bufferType)),
  297. atom_sequence (new_uri(LV2_ATOM__Sequence)),
  298. atom_supports (new_uri(LV2_ATOM__supports)),
  299. preset_preset (new_uri(LV2_PRESETS__Preset)),
  300. state_state (new_uri(LV2_STATE__state)),
  301. value_default (new_uri(LV2_CORE__default)),
  302. value_minimum (new_uri(LV2_CORE__minimum)),
  303. value_maximum (new_uri(LV2_CORE__maximum)),
  304. rz_asLargeAs (new_uri(LV2_RESIZE_PORT__asLargeAs)),
  305. rz_minSize (new_uri(LV2_RESIZE_PORT__minimumSize)),
  306. midi_event (new_uri(LV2_MIDI__MidiEvent)),
  307. patch_message (new_uri(LV2_PATCH__Message)),
  308. time_position (new_uri(LV2_TIME__Position)),
  309. mm_defaultControl (new_uri(NS_llmm "defaultMidiController")),
  310. mm_controlType (new_uri(NS_llmm "controllerType")),
  311. mm_controlNumber (new_uri(NS_llmm "controllerNumber")),
  312. dct_replaces (new_uri(NS_dct "replaces")),
  313. doap_license (new_uri(NS_doap "license")),
  314. rdf_type (new_uri(NS_rdf "type")),
  315. rdfs_label (new_uri(NS_rdfs "label")),
  316. needsInit(true)
  317. {
  318. }
  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 && LV2_PATH[0] != '\0',);
  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(lilv_uri_to_path(binary));
  488. if (const char* const bundle = lilvPlugin.get_bundle_uri().as_string())
  489. rdfDescriptor->Bundle = carla_strdup(lilv_uri_to_path(bundle));
  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. static const Lilv::Node oldPropArtifacts(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#causesArtifacts"));
  673. static const Lilv::Node oldPropContinuousCV(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#continuousCV"));
  674. static const Lilv::Node oldPropDiscreteCV(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#discreteCV"));
  675. static const Lilv::Node oldPropExpensive(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#expensive"));
  676. static const Lilv::Node oldPropStrictBounds(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#hasStrictBounds"));
  677. static const Lilv::Node oldPropLogarithmic(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#logarithmic"));
  678. static const Lilv::Node oldPropNotAutomatic(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#notAutomatic"));
  679. static const Lilv::Node oldPropNotOnGUI(lv2World.new_uri("http://lv2plug.in/ns/dev/extportinfo#notOnGUI"));
  680. static 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. lilv_node_free(unitUnitNode);
  887. }
  888. // FIXME
  889. if (LilvNode* const unitNameNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.unit_name.me))
  890. {
  891. if (const char* const unitName = lilv_node_as_string(unitNameNode))
  892. {
  893. rdfPort->Unit.Hints |= LV2_PORT_UNIT_NAME;
  894. rdfPort->Unit.Name = carla_strdup(unitName);
  895. }
  896. lilv_node_free(unitNameNode);
  897. }
  898. if (LilvNode* const unitRenderNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.unit_render.me))
  899. {
  900. if (const char* const unitRender = lilv_node_as_string(unitRenderNode))
  901. {
  902. rdfPort->Unit.Hints |= LV2_PORT_UNIT_RENDER;
  903. rdfPort->Unit.Render = carla_strdup(unitRender);
  904. }
  905. lilv_node_free(unitRenderNode);
  906. }
  907. if (LilvNode* const unitSymbolNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.unit_symbol.me))
  908. {
  909. if (const char* const unitSymbol = lilv_node_as_string(unitSymbolNode))
  910. {
  911. rdfPort->Unit.Hints |= LV2_PORT_UNIT_SYMBOL;
  912. rdfPort->Unit.Symbol = carla_strdup(unitSymbol);
  913. }
  914. lilv_node_free(unitSymbolNode);
  915. }
  916. }
  917. // -----------------------------------------------------------
  918. // Set Port Minimum Size
  919. {
  920. if (LilvNode* const minimumSizeNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.rz_minSize.me))
  921. {
  922. const int minimumSize(lilv_node_as_int(minimumSizeNode));
  923. if (minimumSize > 0)
  924. rdfPort->MinimumSize = static_cast<uint32_t>(minimumSize);
  925. else
  926. carla_safe_assert_int("minimumSize > 0", __FILE__, __LINE__, minimumSize);
  927. lilv_node_free(minimumSizeNode);
  928. }
  929. }
  930. // -----------------------------------------------------------
  931. // Set Port Scale Points
  932. {
  933. Lilv::ScalePoints lilvScalePoints(lilvPort.get_scale_points());
  934. if (lilvScalePoints.size() > 0)
  935. {
  936. rdfPort->ScalePointCount = lilvScalePoints.size();
  937. rdfPort->ScalePoints = new LV2_RDF_PortScalePoint[rdfPort->ScalePointCount];
  938. uint32_t h = 0;
  939. LILV_FOREACH(scale_points, it, lilvScalePoints)
  940. {
  941. CARLA_SAFE_ASSERT_BREAK(h < rdfPort->ScalePointCount);
  942. Lilv::ScalePoint lilvScalePoint(lilvScalePoints.get(it));
  943. LV2_RDF_PortScalePoint* const rdfScalePoint(&rdfPort->ScalePoints[h++]);
  944. if (const char* const label = Lilv::Node(lilvScalePoint.get_label()).as_string())
  945. rdfScalePoint->Label = carla_strdup(label);
  946. rdfScalePoint->Value = Lilv::Node(lilvScalePoint.get_value()).as_float();
  947. }
  948. }
  949. lilv_nodes_free(const_cast<LilvNodes*>(lilvScalePoints.me));
  950. }
  951. }
  952. }
  953. // -------------------------------------------------------------------
  954. // Set Plugin Presets
  955. if (loadPresets)
  956. {
  957. Lilv::Nodes presetNodes(lilvPlugin.get_related(lv2World.preset_preset));
  958. if (presetNodes.size() > 0)
  959. {
  960. // create a list of preset URIs (for checking appliesTo, sorting and unique-ness)
  961. // FIXME - check appliesTo?
  962. #ifdef USE_QT
  963. QStringList presetListURIs;
  964. LILV_FOREACH(nodes, it, presetNodes)
  965. {
  966. Lilv::Node presetNode(presetNodes.get(it));
  967. QString presetURI(presetNode.as_uri());
  968. if (! (presetURI.trimmed().isEmpty() || presetListURIs.contains(presetURI)))
  969. presetListURIs.append(presetURI);
  970. }
  971. presetListURIs.sort();
  972. rdfDescriptor->PresetCount = static_cast<uint32_t>(presetListURIs.count());
  973. #else
  974. juce::StringArray presetListURIs;
  975. LILV_FOREACH(nodes, it, presetNodes)
  976. {
  977. Lilv::Node presetNode(presetNodes.get(it));
  978. juce::String presetURI(presetNode.as_uri());
  979. if (presetURI.trim().isNotEmpty())
  980. presetListURIs.addIfNotAlreadyThere(presetURI);
  981. }
  982. presetListURIs.sortNatural();
  983. rdfDescriptor->PresetCount = static_cast<uint32_t>(presetListURIs.size());
  984. #endif
  985. // create presets with unique URIs
  986. rdfDescriptor->Presets = new LV2_RDF_Preset[rdfDescriptor->PresetCount];
  987. // set preset data
  988. LILV_FOREACH(nodes, it, presetNodes)
  989. {
  990. Lilv::Node presetNode(presetNodes.get(it));
  991. if (lv2World.load_resource(presetNode) == -1)
  992. continue;
  993. if (const char* const presetURI = presetNode.as_uri())
  994. {
  995. #ifdef USE_QT
  996. const int index(presetListURIs.indexOf(QString(presetURI)));
  997. #else
  998. const int index(presetListURIs.indexOf(juce::String(presetURI)));
  999. #endif
  1000. CARLA_SAFE_ASSERT_CONTINUE(index >= 0);
  1001. LV2_RDF_Preset* const rdfPreset(&rdfDescriptor->Presets[index]);
  1002. // ---------------------------------------------------
  1003. // Set Preset Information
  1004. {
  1005. rdfPreset->URI = carla_strdup(presetURI);
  1006. Lilv::Nodes presetLabelNodes(lv2World.find_nodes(presetNode, lv2World.rdfs_label, nullptr));
  1007. if (presetLabelNodes.size() > 0)
  1008. {
  1009. if (const char* const label = presetLabelNodes.get_first().as_string())
  1010. rdfPreset->Label = carla_strdup(label);
  1011. }
  1012. lilv_nodes_free(const_cast<LilvNodes*>(presetLabelNodes.me));
  1013. }
  1014. }
  1015. }
  1016. }
  1017. lilv_nodes_free(const_cast<LilvNodes*>(presetNodes.me));
  1018. }
  1019. // -------------------------------------------------------------------
  1020. // Set Plugin Features
  1021. {
  1022. Lilv::Nodes lilvFeatureNodes(lilvPlugin.get_supported_features());
  1023. if (lilvFeatureNodes.size() > 0)
  1024. {
  1025. Lilv::Nodes lilvFeatureNodesR(lilvPlugin.get_required_features());
  1026. rdfDescriptor->FeatureCount = lilvFeatureNodes.size();
  1027. rdfDescriptor->Features = new LV2_RDF_Feature[rdfDescriptor->FeatureCount];
  1028. uint32_t h = 0;
  1029. LILV_FOREACH(nodes, it, lilvFeatureNodes)
  1030. {
  1031. CARLA_SAFE_ASSERT_BREAK(h < rdfDescriptor->FeatureCount);
  1032. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(it));
  1033. LV2_RDF_Feature* const rdfFeature(&rdfDescriptor->Features[h++]);
  1034. rdfFeature->Type = lilvFeatureNodesR.contains(lilvFeatureNode) ? LV2_FEATURE_REQUIRED : LV2_FEATURE_OPTIONAL;
  1035. if (const char* const featureURI = lilvFeatureNode.as_uri())
  1036. rdfFeature->URI = carla_strdup(featureURI);
  1037. else
  1038. rdfFeature->URI = nullptr;
  1039. }
  1040. lilv_nodes_free(const_cast<LilvNodes*>(lilvFeatureNodesR.me));
  1041. }
  1042. lilv_nodes_free(const_cast<LilvNodes*>(lilvFeatureNodes.me));
  1043. }
  1044. // -------------------------------------------------------------------
  1045. // Set Plugin Extensions
  1046. {
  1047. Lilv::Nodes lilvExtensionDataNodes(lilvPlugin.get_extension_data());
  1048. if (lilvExtensionDataNodes.size() > 0)
  1049. {
  1050. rdfDescriptor->ExtensionCount = lilvExtensionDataNodes.size();
  1051. rdfDescriptor->Extensions = new LV2_URI[rdfDescriptor->ExtensionCount];
  1052. uint32_t h = 0;
  1053. LILV_FOREACH(nodes, it, lilvExtensionDataNodes)
  1054. {
  1055. CARLA_SAFE_ASSERT_BREAK(h < rdfDescriptor->ExtensionCount);
  1056. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(it));
  1057. LV2_URI* const rdfExtension(&rdfDescriptor->Extensions[h++]);
  1058. if (lilvExtensionDataNode.is_uri())
  1059. {
  1060. if (const char* const extURI = lilvExtensionDataNode.as_uri())
  1061. {
  1062. *rdfExtension = carla_strdup(extURI);
  1063. continue;
  1064. }
  1065. }
  1066. *rdfExtension = nullptr;
  1067. }
  1068. for (uint32_t x=h; x < rdfDescriptor->ExtensionCount; ++x)
  1069. rdfDescriptor->Extensions[x] = nullptr;
  1070. }
  1071. lilv_nodes_free(const_cast<LilvNodes*>(lilvExtensionDataNodes.me));
  1072. }
  1073. // -------------------------------------------------------------------
  1074. // Set Plugin UIs
  1075. {
  1076. Lilv::UIs lilvUIs(lilvPlugin.get_uis());
  1077. if (lilvUIs.size() > 0)
  1078. {
  1079. rdfDescriptor->UICount = lilvUIs.size();
  1080. rdfDescriptor->UIs = new LV2_RDF_UI[rdfDescriptor->UICount];
  1081. uint32_t h = 0;
  1082. LILV_FOREACH(uis, it, lilvUIs)
  1083. {
  1084. CARLA_SAFE_ASSERT_BREAK(h < rdfDescriptor->UICount);
  1085. Lilv::UI lilvUI(lilvUIs.get(it));
  1086. LV2_RDF_UI* const rdfUI(&rdfDescriptor->UIs[h++]);
  1087. // -------------------------------------------------------
  1088. // Set UI Type
  1089. /**/ if (lilvUI.is_a(lv2World.ui_gtk2))
  1090. rdfUI->Type = LV2_UI_GTK2;
  1091. else if (lilvUI.is_a(lv2World.ui_gtk3))
  1092. rdfUI->Type = LV2_UI_GTK3;
  1093. else if (lilvUI.is_a(lv2World.ui_qt4))
  1094. rdfUI->Type = LV2_UI_QT4;
  1095. else if (lilvUI.is_a(lv2World.ui_qt5))
  1096. rdfUI->Type = LV2_UI_QT5;
  1097. else if (lilvUI.is_a(lv2World.ui_cocoa))
  1098. rdfUI->Type = LV2_UI_COCOA;
  1099. else if (lilvUI.is_a(lv2World.ui_windows))
  1100. rdfUI->Type = LV2_UI_WINDOWS;
  1101. else if (lilvUI.is_a(lv2World.ui_x11))
  1102. rdfUI->Type = LV2_UI_X11;
  1103. else if (lilvUI.is_a(lv2World.ui_external))
  1104. rdfUI->Type = LV2_UI_EXTERNAL;
  1105. else if (lilvUI.is_a(lv2World.ui_externalOld))
  1106. rdfUI->Type = LV2_UI_OLD_EXTERNAL;
  1107. else if (lilvUI.is_a(lv2World.ui_externalOld2))
  1108. pass();
  1109. else
  1110. carla_stderr("lv2_rdf_new(\"%s\") - UI '%s' is of unknown type", uri, lilvUI.get_uri().as_uri());
  1111. // -------------------------------------------------------
  1112. // Set UI Information
  1113. {
  1114. if (const char* const uiURI = lilvUI.get_uri().as_uri())
  1115. rdfUI->URI = carla_strdup(uiURI);
  1116. if (const char* const uiBinary = lilvUI.get_binary_uri().as_string())
  1117. rdfUI->Binary = carla_strdup(lilv_uri_to_path(uiBinary));
  1118. if (const char* const uiBundle = lilvUI.get_bundle_uri().as_string())
  1119. rdfUI->Bundle = carla_strdup(lilv_uri_to_path(uiBundle));
  1120. }
  1121. // -------------------------------------------------------
  1122. // Set UI Features
  1123. {
  1124. Lilv::Nodes lilvFeatureNodes(lilvUI.get_supported_features());
  1125. if (lilvFeatureNodes.size() > 0)
  1126. {
  1127. Lilv::Nodes lilvFeatureNodesR(lilvUI.get_required_features());
  1128. rdfUI->FeatureCount = lilvFeatureNodes.size();
  1129. rdfUI->Features = new LV2_RDF_Feature[rdfUI->FeatureCount];
  1130. uint32_t h2 = 0;
  1131. LILV_FOREACH(nodes, it2, lilvFeatureNodes)
  1132. {
  1133. CARLA_SAFE_ASSERT_BREAK(h2 < rdfUI->FeatureCount);
  1134. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(it2));
  1135. LV2_RDF_Feature* const rdfFeature(&rdfUI->Features[h2++]);
  1136. rdfFeature->Type = lilvFeatureNodesR.contains(lilvFeatureNode) ? LV2_FEATURE_REQUIRED : LV2_FEATURE_OPTIONAL;
  1137. if (const char* const featureURI = lilvFeatureNode.as_uri())
  1138. rdfFeature->URI = carla_strdup(featureURI);
  1139. else
  1140. rdfFeature->URI = nullptr;
  1141. }
  1142. lilv_nodes_free(const_cast<LilvNodes*>(lilvFeatureNodesR.me));
  1143. }
  1144. lilv_nodes_free(const_cast<LilvNodes*>(lilvFeatureNodes.me));
  1145. }
  1146. // -------------------------------------------------------
  1147. // Set UI Extensions
  1148. {
  1149. Lilv::Nodes lilvExtensionDataNodes(lilvUI.get_extension_data());
  1150. if (lilvExtensionDataNodes.size() > 0)
  1151. {
  1152. rdfUI->ExtensionCount = lilvExtensionDataNodes.size();
  1153. rdfUI->Extensions = new LV2_URI[rdfUI->ExtensionCount];
  1154. uint32_t h2 = 0;
  1155. LILV_FOREACH(nodes, it2, lilvExtensionDataNodes)
  1156. {
  1157. CARLA_SAFE_ASSERT_BREAK(h2 < rdfUI->ExtensionCount);
  1158. Lilv::Node lilvExtensionDataNode(lilvExtensionDataNodes.get(it2));
  1159. LV2_URI* const rdfExtension(&rdfUI->Extensions[h2++]);
  1160. if (lilvExtensionDataNode.is_uri())
  1161. {
  1162. if (const char* const extURI = lilvExtensionDataNode.as_uri())
  1163. {
  1164. *rdfExtension = carla_strdup(extURI);
  1165. continue;
  1166. }
  1167. }
  1168. *rdfExtension = nullptr;
  1169. }
  1170. for (uint32_t x2=h2; x2 < rdfUI->ExtensionCount; ++x2)
  1171. rdfUI->Extensions[x2] = nullptr;
  1172. }
  1173. lilv_nodes_free(const_cast<LilvNodes*>(lilvExtensionDataNodes.me));
  1174. }
  1175. }
  1176. }
  1177. lilv_nodes_free(const_cast<LilvNodes*>(lilvUIs.me));
  1178. }
  1179. return rdfDescriptor;
  1180. }
  1181. // -----------------------------------------------------------------------
  1182. // Check if we support a plugin port
  1183. static inline
  1184. bool is_lv2_port_supported(const LV2_Property types) noexcept
  1185. {
  1186. if (LV2_IS_PORT_CONTROL(types))
  1187. return true;
  1188. if (LV2_IS_PORT_AUDIO(types))
  1189. return true;
  1190. if (LV2_IS_PORT_CV(types))
  1191. return true;
  1192. if (LV2_IS_PORT_ATOM_SEQUENCE(types))
  1193. return true;
  1194. if (LV2_IS_PORT_EVENT(types))
  1195. return true;
  1196. if (LV2_IS_PORT_MIDI_LL(types))
  1197. return true;
  1198. return false;
  1199. }
  1200. // -----------------------------------------------------------------------
  1201. // Check if we support a plugin feature
  1202. static inline
  1203. bool is_lv2_feature_supported(const LV2_URI uri) noexcept
  1204. {
  1205. CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0', false);
  1206. if (std::strcmp(uri, LV2_BUF_SIZE__boundedBlockLength) == 0)
  1207. return true;
  1208. if (std::strcmp(uri, LV2_BUF_SIZE__fixedBlockLength) == 0)
  1209. return true;
  1210. if (std::strcmp(uri, LV2_BUF_SIZE__powerOf2BlockLength) == 0)
  1211. return true;
  1212. if (std::strcmp(uri, LV2_CORE__hardRTCapable) == 0)
  1213. return true;
  1214. if (std::strcmp(uri, LV2_CORE__inPlaceBroken) == 0)
  1215. return true;
  1216. if (std::strcmp(uri, LV2_CORE__isLive) == 0)
  1217. return true;
  1218. if (std::strcmp(uri, LV2_EVENT_URI) == 0)
  1219. return true;
  1220. if (std::strcmp(uri, LV2_LOG__log) == 0)
  1221. return true;
  1222. if (std::strcmp(uri, LV2_OPTIONS__options) == 0)
  1223. return true;
  1224. if (std::strcmp(uri, LV2_PROGRAMS__Host) == 0)
  1225. return true;
  1226. if (std::strcmp(uri, LV2_RESIZE_PORT__resize) == 0)
  1227. return true;
  1228. if (std::strcmp(uri, LV2_RTSAFE_MEMORY_POOL__Pool) == 0)
  1229. return true;
  1230. if (std::strcmp(uri, LV2_RTSAFE_MEMORY_POOL_DEPRECATED_URI) == 0)
  1231. return true;
  1232. if (std::strcmp(uri, LV2_STATE__makePath) == 0)
  1233. return true;
  1234. if (std::strcmp(uri, LV2_STATE__mapPath) == 0)
  1235. return true;
  1236. if (std::strcmp(uri, LV2_PORT_PROPS__supportsStrictBounds) == 0)
  1237. return true;
  1238. if (std::strcmp(uri, LV2_URI_MAP_URI) == 0)
  1239. return true;
  1240. if (std::strcmp(uri, LV2_URID__map) == 0)
  1241. return true;
  1242. if (std::strcmp(uri, LV2_URID__unmap) == 0)
  1243. return true;
  1244. if (std::strcmp(uri, LV2_WORKER__schedule) == 0)
  1245. return true;
  1246. return false;
  1247. }
  1248. // -----------------------------------------------------------------------
  1249. // Check if we support a plugin or UI feature
  1250. static inline
  1251. bool is_lv2_ui_feature_supported(const LV2_URI uri) noexcept
  1252. {
  1253. CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0', false);
  1254. if (is_lv2_feature_supported(uri))
  1255. return true;
  1256. #ifndef BRIDGE_LV2
  1257. if (std::strcmp(uri, LV2_DATA_ACCESS_URI) == 0)
  1258. return true;
  1259. if (std::strcmp(uri, LV2_INSTANCE_ACCESS_URI) == 0)
  1260. return true;
  1261. #endif
  1262. if (std::strcmp(uri, LV2_UI__fixedSize) == 0)
  1263. return true;
  1264. if (std::strcmp(uri, LV2_UI__idleInterface) == 0)
  1265. return true;
  1266. if (std::strcmp(uri, LV2_UI__makeResident) == 0)
  1267. return true;
  1268. if (std::strcmp(uri, LV2_UI__noUserResize) == 0)
  1269. return true;
  1270. if (std::strcmp(uri, LV2_UI__parent) == 0)
  1271. return true;
  1272. if (std::strcmp(uri, LV2_UI__portMap) == 0)
  1273. return true;
  1274. if (std::strcmp(uri, LV2_UI__portSubscribe) == 0)
  1275. return true;
  1276. if (std::strcmp(uri, LV2_UI__resize) == 0)
  1277. return true;
  1278. if (std::strcmp(uri, LV2_UI__touch) == 0)
  1279. return true;
  1280. if (std::strcmp(uri, LV2_EXTERNAL_UI__Widget) == 0)
  1281. return true;
  1282. if (std::strcmp(uri, LV2_EXTERNAL_UI_DEPRECATED_URI) == 0)
  1283. return true;
  1284. return false;
  1285. }
  1286. // -----------------------------------------------------------------------
  1287. #endif // CARLA_LV2_UTILS_HPP_INCLUDED