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

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