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

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