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

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