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

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