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

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