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

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