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.

CarlaPlugin.cpp 91KB

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
11 years ago
11 years ago
11 years ago
11 years ago
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
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
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
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
11 years ago
11 years ago
9 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
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
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
10 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
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
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
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
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
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755
  1. /*
  2. * Carla Plugin
  3. * Copyright (C) 2011-2023 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. #include "CarlaPluginInternal.hpp"
  18. #include "CarlaEngine.hpp"
  19. #include "CarlaBackendUtils.hpp"
  20. #include "CarlaBase64Utils.hpp"
  21. #include "CarlaMathUtils.hpp"
  22. #include "CarlaMIDI.h"
  23. #include "CarlaPluginUI.hpp"
  24. #include "CarlaScopeUtils.hpp"
  25. #include "CarlaStringList.hpp"
  26. #include <ctime>
  27. #include "water/files/File.h"
  28. #include "water/streams/MemoryOutputStream.h"
  29. #include "water/xml/XmlDocument.h"
  30. #include "water/xml/XmlElement.h"
  31. using water::CharPointer_UTF8;
  32. using water::File;
  33. using water::MemoryOutputStream;
  34. using water::Result;
  35. using water::String;
  36. using water::XmlDocument;
  37. using water::XmlElement;
  38. CARLA_BACKEND_START_NAMESPACE
  39. // -------------------------------------------------------------------------------------------------------------------
  40. // Fallback data
  41. static const ParameterData kParameterDataNull = { PARAMETER_UNKNOWN, 0x0, PARAMETER_NULL, -1, 0, CONTROL_INDEX_NONE, 0.0f, 1.0f, 0x0 };
  42. static const ParameterRanges kParameterRangesNull = { 0.0f, 0.0f, 1.0f, 0.01f, 0.0001f, 0.1f };
  43. static const MidiProgramData kMidiProgramDataNull = { 0, 0, nullptr };
  44. static const CustomData kCustomDataFallback = { nullptr, nullptr, nullptr };
  45. static /* */ CustomData kCustomDataFallbackNC = { nullptr, nullptr, nullptr };
  46. static const PluginPostRtEvent kPluginPostRtEventFallback = { kPluginPostRtEventNull, false, {} };
  47. // -------------------------------------------------------------------------------------------------------------------
  48. // ParamSymbol struct, needed for CarlaPlugin::loadStateSave()
  49. struct ParamSymbol {
  50. int32_t index;
  51. const char* symbol;
  52. ParamSymbol(const uint32_t i, const char* const s)
  53. : index(static_cast<int32_t>(i)),
  54. symbol(carla_strdup(s)) {}
  55. ~ParamSymbol() noexcept
  56. {
  57. CARLA_SAFE_ASSERT_RETURN(symbol != nullptr,)
  58. delete[] symbol;
  59. symbol = nullptr;
  60. }
  61. #ifdef CARLA_PROPER_CPP11_SUPPORT
  62. ParamSymbol() = delete;
  63. CARLA_DECLARE_NON_COPYABLE(ParamSymbol)
  64. #endif
  65. };
  66. // -------------------------------------------------------------------------------------------------------------------
  67. // Constructor and destructor
  68. CarlaPlugin::CarlaPlugin(CarlaEngine* const engine, const uint id)
  69. : pData(new ProtectedData(engine, id))
  70. {
  71. CARLA_SAFE_ASSERT_RETURN(engine != nullptr,);
  72. CARLA_SAFE_ASSERT(id < engine->getMaxPluginNumber());
  73. carla_debug("CarlaPlugin::CarlaPlugin(%p, %i)", engine, id);
  74. switch (engine->getProccessMode())
  75. {
  76. case ENGINE_PROCESS_MODE_SINGLE_CLIENT:
  77. case ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS:
  78. CARLA_SAFE_ASSERT(id < MAX_DEFAULT_PLUGINS);
  79. break;
  80. case ENGINE_PROCESS_MODE_CONTINUOUS_RACK:
  81. CARLA_SAFE_ASSERT(id < MAX_RACK_PLUGINS);
  82. break;
  83. case ENGINE_PROCESS_MODE_PATCHBAY:
  84. CARLA_SAFE_ASSERT(id < MAX_PATCHBAY_PLUGINS);
  85. break;
  86. case ENGINE_PROCESS_MODE_BRIDGE:
  87. CARLA_SAFE_ASSERT(id == 0);
  88. break;
  89. }
  90. }
  91. CarlaPlugin::~CarlaPlugin()
  92. {
  93. carla_debug("CarlaPlugin::~CarlaPlugin()");
  94. delete pData;
  95. }
  96. // -------------------------------------------------------------------
  97. // Information (base)
  98. uint CarlaPlugin::getId() const noexcept
  99. {
  100. return pData->id;
  101. }
  102. uint CarlaPlugin::getHints() const noexcept
  103. {
  104. return pData->hints;
  105. }
  106. uint CarlaPlugin::getOptionsEnabled() const noexcept
  107. {
  108. return pData->options;
  109. }
  110. bool CarlaPlugin::isEnabled() const noexcept
  111. {
  112. return pData->enabled;
  113. }
  114. const char* CarlaPlugin::getName() const noexcept
  115. {
  116. return pData->name;
  117. }
  118. const char* CarlaPlugin::getFilename() const noexcept
  119. {
  120. return pData->filename;
  121. }
  122. const char* CarlaPlugin::getIconName() const noexcept
  123. {
  124. return pData->iconName;
  125. }
  126. PluginCategory CarlaPlugin::getCategory() const noexcept
  127. {
  128. return getPluginCategoryFromName(pData->name);
  129. }
  130. int64_t CarlaPlugin::getUniqueId() const noexcept
  131. {
  132. return 0;
  133. }
  134. uint32_t CarlaPlugin::getLatencyInFrames() const noexcept
  135. {
  136. return 0;
  137. }
  138. // -------------------------------------------------------------------
  139. // Information (count)
  140. uint32_t CarlaPlugin::getAudioInCount() const noexcept
  141. {
  142. return pData->audioIn.count;
  143. }
  144. uint32_t CarlaPlugin::getAudioOutCount() const noexcept
  145. {
  146. return pData->audioOut.count;
  147. }
  148. uint32_t CarlaPlugin::getCVInCount() const noexcept
  149. {
  150. return pData->cvIn.count;
  151. }
  152. uint32_t CarlaPlugin::getCVOutCount() const noexcept
  153. {
  154. return pData->cvOut.count;
  155. }
  156. uint32_t CarlaPlugin::getMidiInCount() const noexcept
  157. {
  158. return (pData->extraHints & PLUGIN_EXTRA_HINT_HAS_MIDI_IN) ? 1 : 0;
  159. }
  160. uint32_t CarlaPlugin::getMidiOutCount() const noexcept
  161. {
  162. return (pData->extraHints & PLUGIN_EXTRA_HINT_HAS_MIDI_OUT) ? 1 : 0;
  163. }
  164. uint32_t CarlaPlugin::getParameterCount() const noexcept
  165. {
  166. return pData->param.count;
  167. }
  168. uint32_t CarlaPlugin::getParameterScalePointCount(const uint32_t parameterId) const noexcept
  169. {
  170. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, 0);
  171. return 0;
  172. }
  173. uint32_t CarlaPlugin::getProgramCount() const noexcept
  174. {
  175. return pData->prog.count;
  176. }
  177. uint32_t CarlaPlugin::getMidiProgramCount() const noexcept
  178. {
  179. return pData->midiprog.count;
  180. }
  181. uint32_t CarlaPlugin::getCustomDataCount() const noexcept
  182. {
  183. return static_cast<uint32_t>(pData->custom.count());
  184. }
  185. // -------------------------------------------------------------------
  186. // Information (current data)
  187. int32_t CarlaPlugin::getCurrentProgram() const noexcept
  188. {
  189. return pData->prog.current;
  190. }
  191. int32_t CarlaPlugin::getCurrentMidiProgram() const noexcept
  192. {
  193. return pData->midiprog.current;
  194. }
  195. uint CarlaPlugin::getAudioPortHints(bool, uint32_t) const noexcept
  196. {
  197. return 0x0;
  198. }
  199. const ParameterData& CarlaPlugin::getParameterData(const uint32_t parameterId) const noexcept
  200. {
  201. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, kParameterDataNull);
  202. return pData->param.data[parameterId];
  203. }
  204. const ParameterRanges& CarlaPlugin::getParameterRanges(const uint32_t parameterId) const noexcept
  205. {
  206. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, kParameterRangesNull);
  207. return pData->param.ranges[parameterId];
  208. }
  209. bool CarlaPlugin::isParameterOutput(const uint32_t parameterId) const noexcept
  210. {
  211. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, false);
  212. return (pData->param.data[parameterId].type == PARAMETER_OUTPUT);
  213. }
  214. const MidiProgramData& CarlaPlugin::getMidiProgramData(const uint32_t index) const noexcept
  215. {
  216. CARLA_SAFE_ASSERT_RETURN(index < pData->midiprog.count, kMidiProgramDataNull);
  217. return pData->midiprog.data[index];
  218. }
  219. const CustomData& CarlaPlugin::getCustomData(const uint32_t index) const noexcept
  220. {
  221. return pData->custom.getAt(index, kCustomDataFallback);
  222. }
  223. std::size_t CarlaPlugin::getChunkData(void** const dataPtr) noexcept
  224. {
  225. CARLA_SAFE_ASSERT_RETURN(dataPtr != nullptr, 0);
  226. CARLA_SAFE_ASSERT(false); // this should never happen
  227. return 0;
  228. }
  229. // -------------------------------------------------------------------
  230. // Information (per-plugin data)
  231. uint CarlaPlugin::getOptionsAvailable() const noexcept
  232. {
  233. CARLA_SAFE_ASSERT(false); // this should never happen
  234. return 0x0;
  235. }
  236. float CarlaPlugin::getParameterValue(const uint32_t parameterId) const noexcept
  237. {
  238. CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), 0.0f);
  239. CARLA_SAFE_ASSERT(false); // this should never happen
  240. return 0.0f;
  241. }
  242. float CarlaPlugin::getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId) const noexcept
  243. {
  244. CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), 0.0f);
  245. CARLA_SAFE_ASSERT_RETURN(scalePointId < getParameterScalePointCount(parameterId), 0.0f);
  246. CARLA_SAFE_ASSERT(false); // this should never happen
  247. return 0.0f;
  248. }
  249. bool CarlaPlugin::getLabel(char* const strBuf) const noexcept
  250. {
  251. strBuf[0] = '\0';
  252. return false;
  253. }
  254. bool CarlaPlugin::getMaker(char* const strBuf) const noexcept
  255. {
  256. strBuf[0] = '\0';
  257. return false;
  258. }
  259. bool CarlaPlugin::getCopyright(char* const strBuf) const noexcept
  260. {
  261. strBuf[0] = '\0';
  262. return false;
  263. }
  264. bool CarlaPlugin::getRealName(char* const strBuf) const noexcept
  265. {
  266. strBuf[0] = '\0';
  267. return false;
  268. }
  269. bool CarlaPlugin::getParameterName(const uint32_t parameterId, char* const strBuf) const noexcept
  270. {
  271. CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), false);
  272. CARLA_SAFE_ASSERT(false); // this should never happen
  273. strBuf[0] = '\0';
  274. return false;
  275. }
  276. bool CarlaPlugin::getParameterSymbol(const uint32_t parameterId, char* const strBuf) const noexcept
  277. {
  278. CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), false);
  279. strBuf[0] = '\0';
  280. return false;
  281. }
  282. bool CarlaPlugin::getParameterText(const uint32_t parameterId, char* const strBuf) noexcept
  283. {
  284. CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), false);
  285. CARLA_SAFE_ASSERT(false); // this should never happen
  286. strBuf[0] = '\0';
  287. return false;
  288. }
  289. bool CarlaPlugin::getParameterUnit(const uint32_t parameterId, char* const strBuf) const noexcept
  290. {
  291. CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), false);
  292. strBuf[0] = '\0';
  293. return false;
  294. }
  295. bool CarlaPlugin::getParameterComment(const uint32_t parameterId, char* const strBuf) const noexcept
  296. {
  297. CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), false);
  298. strBuf[0] = '\0';
  299. return false;
  300. }
  301. bool CarlaPlugin::getParameterGroupName(const uint32_t parameterId, char* const strBuf) const noexcept
  302. {
  303. CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), false);
  304. strBuf[0] = '\0';
  305. return false;
  306. }
  307. bool CarlaPlugin::getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf) const noexcept
  308. {
  309. CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), false);
  310. CARLA_SAFE_ASSERT_RETURN(scalePointId < getParameterScalePointCount(parameterId), false);
  311. CARLA_SAFE_ASSERT(false); // this should never happen
  312. strBuf[0] = '\0';
  313. return false;
  314. }
  315. float CarlaPlugin::getInternalParameterValue(const int32_t parameterId) const noexcept
  316. {
  317. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  318. CARLA_SAFE_ASSERT_RETURN(parameterId != PARAMETER_NULL && parameterId > PARAMETER_MAX, 0.0f);
  319. switch (parameterId)
  320. {
  321. case PARAMETER_ACTIVE:
  322. return pData->active;
  323. case PARAMETER_CTRL_CHANNEL:
  324. return pData->ctrlChannel;
  325. case PARAMETER_DRYWET:
  326. return pData->postProc.dryWet;
  327. case PARAMETER_VOLUME:
  328. return pData->postProc.volume;
  329. case PARAMETER_BALANCE_LEFT:
  330. return pData->postProc.balanceLeft;
  331. case PARAMETER_BALANCE_RIGHT:
  332. return pData->postProc.balanceRight;
  333. case PARAMETER_PANNING:
  334. return pData->postProc.panning;
  335. };
  336. #endif
  337. CARLA_SAFE_ASSERT_RETURN(parameterId >= 0, 0.0f);
  338. return getParameterValue(static_cast<uint32_t>(parameterId));
  339. }
  340. bool CarlaPlugin::getProgramName(const uint32_t index, char* const strBuf) const noexcept
  341. {
  342. CARLA_SAFE_ASSERT_RETURN(index < pData->prog.count, false);
  343. CARLA_SAFE_ASSERT_RETURN(pData->prog.names[index] != nullptr, false);
  344. std::strncpy(strBuf, pData->prog.names[index], STR_MAX);
  345. return true;
  346. }
  347. bool CarlaPlugin::getMidiProgramName(const uint32_t index, char* const strBuf) const noexcept
  348. {
  349. CARLA_SAFE_ASSERT_RETURN(index < pData->midiprog.count, false);
  350. CARLA_SAFE_ASSERT_RETURN(pData->midiprog.data[index].name != nullptr, false);
  351. std::strncpy(strBuf, pData->midiprog.data[index].name, STR_MAX);
  352. return true;
  353. }
  354. void CarlaPlugin::getParameterCountInfo(uint32_t& ins, uint32_t& outs) const noexcept
  355. {
  356. ins = 0;
  357. outs = 0;
  358. for (uint32_t i=0; i < pData->param.count; ++i)
  359. {
  360. if (pData->param.data[i].type == PARAMETER_INPUT)
  361. ++ins;
  362. else if (pData->param.data[i].type == PARAMETER_OUTPUT)
  363. ++outs;
  364. }
  365. }
  366. // -------------------------------------------------------------------
  367. // Set data (state)
  368. void CarlaPlugin::prepareForSave(bool)
  369. {
  370. }
  371. void CarlaPlugin::resetParameters() noexcept
  372. {
  373. for (uint i=0; i < pData->param.count; ++i)
  374. {
  375. const ParameterData& paramData(pData->param.data[i]);
  376. const ParameterRanges& paramRanges(pData->param.ranges[i]);
  377. if (paramData.type != PARAMETER_INPUT)
  378. continue;
  379. if ((paramData.hints & PARAMETER_IS_ENABLED) == 0)
  380. continue;
  381. setParameterValue(i, paramRanges.def, true, true, true);
  382. }
  383. }
  384. void CarlaPlugin::randomizeParameters() noexcept
  385. {
  386. float value, random;
  387. char strBuf[STR_MAX+1];
  388. strBuf[STR_MAX] = '\0';
  389. std::srand(static_cast<uint>(std::time(nullptr)));
  390. for (uint i=0; i < pData->param.count; ++i)
  391. {
  392. const ParameterData& paramData(pData->param.data[i]);
  393. if (paramData.type != PARAMETER_INPUT)
  394. continue;
  395. if ((paramData.hints & PARAMETER_IS_ENABLED) == 0)
  396. continue;
  397. if (! getParameterName(i, strBuf))
  398. strBuf[0] = '\0';
  399. if (std::strstr(strBuf, "olume") != nullptr)
  400. continue;
  401. if (std::strstr(strBuf, "Master") != nullptr)
  402. continue;
  403. const ParameterRanges& paramRanges(pData->param.ranges[i]);
  404. if (paramData.hints & PARAMETER_IS_BOOLEAN)
  405. {
  406. random = static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX);
  407. value = random > 0.5f ? paramRanges.max : paramRanges.min;
  408. }
  409. else
  410. {
  411. random = static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX);
  412. value = random * (paramRanges.max - paramRanges.min) + paramRanges.min;
  413. if (paramData.hints & PARAMETER_IS_INTEGER)
  414. value = std::rint(value);
  415. }
  416. setParameterValue(i, value, true, true, true);
  417. }
  418. }
  419. const CarlaStateSave& CarlaPlugin::getStateSave(const bool callPrepareForSave)
  420. {
  421. pData->stateSave.clear();
  422. if (callPrepareForSave)
  423. {
  424. pData->stateSave.temporary = true;
  425. prepareForSave(true);
  426. }
  427. const PluginType pluginType = getType();
  428. char strBuf[STR_MAX+1];
  429. carla_zeroChars(strBuf, STR_MAX+1);
  430. // ---------------------------------------------------------------
  431. // Basic info
  432. if (! getLabel(strBuf))
  433. strBuf[0] = '\0';
  434. pData->stateSave.type = carla_strdup(getPluginTypeAsString(pluginType));
  435. pData->stateSave.name = carla_strdup(pData->name);
  436. pData->stateSave.label = carla_strdup(strBuf);
  437. pData->stateSave.uniqueId = getUniqueId();
  438. // #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  439. pData->stateSave.options = pData->options;
  440. // #endif
  441. if (pData->filename != nullptr)
  442. pData->stateSave.binary = carla_strdup(pData->filename);
  443. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  444. // ---------------------------------------------------------------
  445. // Internals
  446. pData->stateSave.active = pData->active;
  447. pData->stateSave.dryWet = pData->postProc.dryWet;
  448. pData->stateSave.volume = pData->postProc.volume;
  449. pData->stateSave.balanceLeft = pData->postProc.balanceLeft;
  450. pData->stateSave.balanceRight = pData->postProc.balanceRight;
  451. pData->stateSave.panning = pData->postProc.panning;
  452. pData->stateSave.ctrlChannel = pData->ctrlChannel;
  453. #endif
  454. if (pData->hints & PLUGIN_IS_BRIDGE)
  455. waitForBridgeSaveSignal();
  456. // ---------------------------------------------------------------
  457. // Chunk
  458. bool usingChunk = false;
  459. if (pData->options & PLUGIN_OPTION_USE_CHUNKS)
  460. {
  461. void* data = nullptr;
  462. const std::size_t dataSize = getChunkData(&data);
  463. if (data != nullptr && dataSize > 0)
  464. {
  465. pData->stateSave.chunk = CarlaString::asBase64(data, dataSize).dup();
  466. if (pluginType != PLUGIN_INTERNAL && pluginType != PLUGIN_JSFX)
  467. usingChunk = true;
  468. }
  469. }
  470. // ---------------------------------------------------------------
  471. // Current Program
  472. if (pData->prog.current >= 0 && pluginType != PLUGIN_LV2)
  473. {
  474. pData->stateSave.currentProgramIndex = pData->prog.current;
  475. pData->stateSave.currentProgramName = carla_strdup(pData->prog.names[pData->prog.current]);
  476. }
  477. // ---------------------------------------------------------------
  478. // Current MIDI Program
  479. if (pData->midiprog.current >= 0 && pluginType != PLUGIN_LV2 && pluginType != PLUGIN_SF2)
  480. {
  481. const MidiProgramData& mpData(pData->midiprog.getCurrent());
  482. pData->stateSave.currentMidiBank = static_cast<int32_t>(mpData.bank);
  483. pData->stateSave.currentMidiProgram = static_cast<int32_t>(mpData.program);
  484. }
  485. // ---------------------------------------------------------------
  486. // Parameters
  487. const float sampleRate = static_cast<float>(pData->engine->getSampleRate());
  488. for (uint32_t i=0; i < pData->param.count; ++i)
  489. {
  490. const ParameterData& paramData(pData->param.data[i]);
  491. if ((paramData.hints & PARAMETER_IS_ENABLED) == 0)
  492. continue;
  493. if (paramData.hints & PARAMETER_IS_NOT_SAVED)
  494. continue;
  495. const bool dummy = paramData.type != PARAMETER_INPUT || usingChunk;
  496. if (dummy && paramData.mappedControlIndex <= CONTROL_INDEX_NONE)
  497. continue;
  498. CarlaStateSave::Parameter* const stateParameter(new CarlaStateSave::Parameter());
  499. stateParameter->dummy = dummy;
  500. stateParameter->index = paramData.index;
  501. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  502. if (paramData.mappedControlIndex != CONTROL_INDEX_MIDI_LEARN)
  503. {
  504. stateParameter->mappedControlIndex = paramData.mappedControlIndex;
  505. stateParameter->midiChannel = paramData.midiChannel;
  506. if (paramData.hints & PARAMETER_MAPPED_RANGES_SET)
  507. {
  508. stateParameter->mappedMinimum = paramData.mappedMinimum;
  509. stateParameter->mappedMaximum = paramData.mappedMaximum;
  510. stateParameter->mappedRangeValid = true;
  511. if (paramData.hints & PARAMETER_USES_SAMPLERATE)
  512. {
  513. stateParameter->mappedMinimum /= sampleRate;
  514. stateParameter->mappedMaximum /= sampleRate;
  515. }
  516. }
  517. }
  518. #endif
  519. if (! getParameterName(i, strBuf))
  520. strBuf[0] = '\0';
  521. stateParameter->name = carla_strdup(strBuf);
  522. if (! getParameterSymbol(i, strBuf))
  523. strBuf[0] = '\0';
  524. stateParameter->symbol = carla_strdup(strBuf);;
  525. if (! dummy)
  526. {
  527. stateParameter->value = getParameterValue(i);
  528. if (paramData.hints & PARAMETER_USES_SAMPLERATE)
  529. stateParameter->value /= sampleRate;
  530. }
  531. pData->stateSave.parameters.append(stateParameter);
  532. }
  533. // ---------------------------------------------------------------
  534. // Custom Data
  535. for (LinkedList<CustomData>::Itenerator it = pData->custom.begin2(); it.valid(); it.next())
  536. {
  537. const CustomData& cData(it.getValue(kCustomDataFallback));
  538. CARLA_SAFE_ASSERT_CONTINUE(cData.isValid());
  539. CarlaStateSave::CustomData* stateCustomData(new CarlaStateSave::CustomData());
  540. stateCustomData->type = carla_strdup(cData.type);
  541. stateCustomData->key = carla_strdup(cData.key);
  542. stateCustomData->value = carla_strdup(cData.value);
  543. pData->stateSave.customData.append(stateCustomData);
  544. }
  545. return pData->stateSave;
  546. }
  547. void CarlaPlugin::loadStateSave(const CarlaStateSave& stateSave)
  548. {
  549. const bool usesMultiProgs = pData->hints & PLUGIN_USES_MULTI_PROGS;
  550. const PluginType pluginType = getType();
  551. char strBuf[STR_MAX+1];
  552. carla_zeroChars(strBuf, STR_MAX+1);
  553. // ---------------------------------------------------------------
  554. // Part 1 - PRE-set custom data (only those which reload programs)
  555. for (CarlaStateSave::CustomDataItenerator it = stateSave.customData.begin2(); it.valid(); it.next())
  556. {
  557. const CarlaStateSave::CustomData* const stateCustomData(it.getValue(nullptr));
  558. CARLA_SAFE_ASSERT_CONTINUE(stateCustomData != nullptr);
  559. CARLA_SAFE_ASSERT_CONTINUE(stateCustomData->isValid());
  560. const char* const key(stateCustomData->key);
  561. /**/ if (pluginType == PLUGIN_DSSI && (std::strcmp (key, "reloadprograms") == 0 ||
  562. std::strcmp (key, "load" ) == 0 ||
  563. std::strncmp(key, "patches", 7) == 0 ))
  564. pass();
  565. else if (usesMultiProgs && std::strcmp(key, "midiPrograms") == 0)
  566. pass();
  567. else
  568. continue;
  569. setCustomData(stateCustomData->type, key, stateCustomData->value, true);
  570. }
  571. // ---------------------------------------------------------------
  572. // Part 2 - set program
  573. if (stateSave.currentProgramIndex >= 0 && stateSave.currentProgramName != nullptr)
  574. {
  575. int32_t programId = -1;
  576. // index < count
  577. if (stateSave.currentProgramIndex < static_cast<int32_t>(pData->prog.count))
  578. {
  579. programId = stateSave.currentProgramIndex;
  580. }
  581. // index not valid, try to find by name
  582. else
  583. {
  584. for (uint32_t i=0; i < pData->prog.count; ++i)
  585. {
  586. if (getProgramName(i, strBuf) && std::strcmp(stateSave.currentProgramName, strBuf) == 0)
  587. {
  588. programId = static_cast<int32_t>(i);
  589. break;
  590. }
  591. }
  592. }
  593. // set program now, if valid
  594. if (programId >= 0)
  595. setProgram(programId, true, true, true);
  596. }
  597. // ---------------------------------------------------------------
  598. // Part 3 - set midi program
  599. if (stateSave.currentMidiBank >= 0 && stateSave.currentMidiProgram >= 0 && ! usesMultiProgs)
  600. setMidiProgramById(static_cast<uint32_t>(stateSave.currentMidiBank), static_cast<uint32_t>(stateSave.currentMidiProgram), true, true, true);
  601. // ---------------------------------------------------------------
  602. // Part 4a - get plugin parameter symbols
  603. LinkedList<ParamSymbol*> paramSymbols;
  604. if (pluginType == PLUGIN_LADSPA || pluginType == PLUGIN_LV2 || pluginType == PLUGIN_CLAP)
  605. {
  606. for (uint32_t i=0; i < pData->param.count; ++i)
  607. {
  608. if (pData->param.data[i].hints & PARAMETER_IS_NOT_SAVED)
  609. continue;
  610. if (getParameterSymbol(i, strBuf))
  611. {
  612. ParamSymbol* const paramSymbol(new ParamSymbol(i, strBuf));
  613. paramSymbols.append(paramSymbol);
  614. }
  615. }
  616. }
  617. // ---------------------------------------------------------------
  618. // Part 4b - set parameter values (carefully)
  619. const float sampleRate = static_cast<float>(pData->engine->getSampleRate());
  620. for (CarlaStateSave::ParameterItenerator it = stateSave.parameters.begin2(); it.valid(); it.next())
  621. {
  622. CarlaStateSave::Parameter* const stateParameter(it.getValue(nullptr));
  623. CARLA_SAFE_ASSERT_CONTINUE(stateParameter != nullptr);
  624. int32_t index = -1;
  625. if (pluginType == PLUGIN_LADSPA)
  626. {
  627. // Try to set by symbol, otherwise use index
  628. if (stateParameter->symbol != nullptr && stateParameter->symbol[0] != '\0')
  629. {
  630. for (LinkedList<ParamSymbol*>::Itenerator it2 = paramSymbols.begin2(); it2.valid(); it2.next())
  631. {
  632. ParamSymbol* const paramSymbol(it2.getValue(nullptr));
  633. CARLA_SAFE_ASSERT_CONTINUE(paramSymbol != nullptr);
  634. CARLA_SAFE_ASSERT_CONTINUE(paramSymbol->symbol != nullptr);
  635. if (std::strcmp(stateParameter->symbol, paramSymbol->symbol) == 0)
  636. {
  637. index = paramSymbol->index;
  638. break;
  639. }
  640. }
  641. if (index == -1)
  642. index = stateParameter->index;
  643. }
  644. else
  645. {
  646. index = stateParameter->index;
  647. }
  648. }
  649. else if (pluginType == PLUGIN_LV2 || pluginType == PLUGIN_CLAP)
  650. {
  651. // Symbol only
  652. if (stateParameter->symbol != nullptr && stateParameter->symbol[0] != '\0')
  653. {
  654. for (LinkedList<ParamSymbol*>::Itenerator it2 = paramSymbols.begin2(); it2.valid(); it2.next())
  655. {
  656. ParamSymbol* const paramSymbol(it2.getValue(nullptr));
  657. CARLA_SAFE_ASSERT_CONTINUE(paramSymbol != nullptr);
  658. CARLA_SAFE_ASSERT_CONTINUE(paramSymbol->symbol != nullptr);
  659. if (std::strcmp(stateParameter->symbol, paramSymbol->symbol) == 0)
  660. {
  661. index = paramSymbol->index;
  662. break;
  663. }
  664. }
  665. if (index == -1)
  666. {
  667. if (pluginType == PLUGIN_LV2)
  668. carla_stderr("Failed to find LV2 parameter symbol '%s' for '%s'",
  669. stateParameter->symbol, pData->name);
  670. else
  671. carla_stderr("Failed to find CLAP parameter id '%s' for '%s'",
  672. stateParameter->symbol, pData->name);
  673. }
  674. }
  675. else
  676. {
  677. if (pluginType == PLUGIN_LV2)
  678. carla_stderr("LV2 Plugin parameter '%s' has no symbol", stateParameter->name);
  679. else
  680. carla_stderr("CLAP Plugin parameter '%s' has no id", stateParameter->name);
  681. }
  682. }
  683. else
  684. {
  685. // Index only
  686. index = stateParameter->index;
  687. }
  688. // Now set parameter
  689. if (index >= 0 && index < static_cast<int32_t>(pData->param.count))
  690. {
  691. //CARLA_SAFE_ASSERT(stateParameter->isInput == (pData
  692. if (! stateParameter->dummy)
  693. {
  694. if (pData->param.data[index].hints & PARAMETER_USES_SAMPLERATE)
  695. stateParameter->value *= sampleRate;
  696. setParameterValue(static_cast<uint32_t>(index), stateParameter->value, true, true, true);
  697. }
  698. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  699. if (stateParameter->mappedRangeValid)
  700. {
  701. if (pData->param.data[index].hints & PARAMETER_USES_SAMPLERATE)
  702. {
  703. stateParameter->mappedMinimum *= sampleRate;
  704. stateParameter->mappedMaximum *= sampleRate;
  705. }
  706. setParameterMappedRange(static_cast<uint32_t>(index),
  707. stateParameter->mappedMinimum,
  708. stateParameter->mappedMaximum, true, true);
  709. }
  710. setParameterMappedControlIndex(static_cast<uint32_t>(index),
  711. stateParameter->mappedControlIndex, true, true, false);
  712. setParameterMidiChannel(static_cast<uint32_t>(index), stateParameter->midiChannel, true, true);
  713. #endif
  714. }
  715. else
  716. carla_stderr("Could not set parameter '%s' value for '%s'",
  717. stateParameter->name, pData->name);
  718. }
  719. // ---------------------------------------------------------------
  720. // Part 4c - clear
  721. for (LinkedList<ParamSymbol*>::Itenerator it = paramSymbols.begin2(); it.valid(); it.next())
  722. {
  723. ParamSymbol* const paramSymbol(it.getValue(nullptr));
  724. delete paramSymbol;
  725. }
  726. paramSymbols.clear();
  727. // ---------------------------------------------------------------
  728. // Part 5 - set custom data
  729. for (CarlaStateSave::CustomDataItenerator it = stateSave.customData.begin2(); it.valid(); it.next())
  730. {
  731. const CarlaStateSave::CustomData* const stateCustomData(it.getValue(nullptr));
  732. CARLA_SAFE_ASSERT_CONTINUE(stateCustomData != nullptr);
  733. CARLA_SAFE_ASSERT_CONTINUE(stateCustomData->isValid());
  734. const char* const key(stateCustomData->key);
  735. if (pluginType == PLUGIN_DSSI && (std::strcmp (key, "reloadprograms") == 0 ||
  736. std::strcmp (key, "load" ) == 0 ||
  737. std::strncmp(key, "patches", 7) == 0 ))
  738. continue;
  739. if (usesMultiProgs && std::strcmp(key, "midiPrograms") == 0)
  740. continue;
  741. setCustomData(stateCustomData->type, key, stateCustomData->value, true);
  742. }
  743. // ---------------------------------------------------------------
  744. // Part 5x - set lv2 state
  745. if (pluginType == PLUGIN_LV2)
  746. {
  747. for (LinkedList<CustomData>::Itenerator it = pData->custom.begin2(); it.valid(); it.next())
  748. {
  749. const CustomData& customData(it.getValue(kCustomDataFallback));
  750. CARLA_SAFE_ASSERT_CONTINUE(customData.isValid());
  751. if (std::strcmp(customData.type, CUSTOM_DATA_TYPE_PROPERTY) == 0)
  752. continue;
  753. restoreLV2State(stateSave.temporary);
  754. break;
  755. }
  756. }
  757. // ---------------------------------------------------------------
  758. // Part 6 - set chunk
  759. if (stateSave.chunk != nullptr && (pData->options & PLUGIN_OPTION_USE_CHUNKS) != 0)
  760. {
  761. std::vector<uint8_t> chunk(carla_getChunkFromBase64String(stateSave.chunk));
  762. #ifdef CARLA_PROPER_CPP11_SUPPORT
  763. setChunkData(chunk.data(), chunk.size());
  764. #else
  765. setChunkData(&chunk.front(), chunk.size());
  766. #endif
  767. }
  768. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  769. // ---------------------------------------------------------------
  770. // Part 6 - set internal stuff
  771. const uint availOptions = getOptionsAvailable();
  772. for (uint i=0; i<10; ++i) // FIXME - get this value somehow...
  773. {
  774. const uint option(1u << i);
  775. if (availOptions & option)
  776. setOption(option, (stateSave.options & option) != 0, true);
  777. }
  778. setDryWet(stateSave.dryWet, true, true);
  779. setVolume(stateSave.volume, true, true);
  780. setBalanceLeft(stateSave.balanceLeft, true, true);
  781. setBalanceRight(stateSave.balanceRight, true, true);
  782. setPanning(stateSave.panning, true, true);
  783. setCtrlChannel(stateSave.ctrlChannel, true, true);
  784. setActive(stateSave.active, true, true);
  785. if (! pData->engine->isLoadingProject())
  786. pData->engine->callback(true, true, ENGINE_CALLBACK_UPDATE, pData->id, 0, 0, 0, 0.0f, nullptr);
  787. #endif
  788. }
  789. bool CarlaPlugin::saveStateToFile(const char* const filename)
  790. {
  791. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  792. carla_debug("CarlaPlugin::saveStateToFile(\"%s\")", filename);
  793. MemoryOutputStream out, streamState;
  794. getStateSave().dumpToMemoryStream(streamState);
  795. out << "<?xml version='1.0' encoding='UTF-8'?>\n";
  796. out << "<!DOCTYPE CARLA-PRESET>\n";
  797. out << "<CARLA-PRESET VERSION='2.0'>\n";
  798. out << streamState;
  799. out << "</CARLA-PRESET>\n";
  800. const String jfilename = String(CharPointer_UTF8(filename));
  801. File file(jfilename);
  802. if (file.replaceWithData(out.getData(), out.getDataSize()))
  803. return true;
  804. pData->engine->setLastError("Failed to write file");
  805. return false;
  806. }
  807. bool CarlaPlugin::loadStateFromFile(const char* const filename)
  808. {
  809. // TODO set errors
  810. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  811. carla_debug("CarlaPlugin::loadStateFromFile(\"%s\")", filename);
  812. const String jfilename = String(CharPointer_UTF8(filename));
  813. File file(jfilename);
  814. CARLA_SAFE_ASSERT_RETURN(file.existsAsFile(), false);
  815. XmlDocument xml(file);
  816. CarlaScopedPointer<XmlElement> xmlElement(xml.getDocumentElement(true));
  817. CARLA_SAFE_ASSERT_RETURN(xmlElement != nullptr, false);
  818. CARLA_SAFE_ASSERT_RETURN(xmlElement->getTagName().equalsIgnoreCase("carla-preset"), false);
  819. // completely load file
  820. xmlElement = xml.getDocumentElement(false);
  821. CARLA_SAFE_ASSERT_RETURN(xmlElement != nullptr, false);
  822. if (pData->stateSave.fillFromXmlElement(xmlElement))
  823. {
  824. loadStateSave(pData->stateSave);
  825. return true;
  826. }
  827. return false;
  828. }
  829. #ifndef CARLA_PLUGIN_ONLY_BRIDGE
  830. bool CarlaPlugin::exportAsLV2(const char* const lv2path)
  831. {
  832. CARLA_SAFE_ASSERT_RETURN(lv2path != nullptr && lv2path[0] != '\0', false);
  833. carla_debug("CarlaPlugin::exportAsLV2(\"%s\")", lv2path);
  834. CarlaString bundlepath(lv2path);
  835. if (! bundlepath.endsWith(".lv2"))
  836. bundlepath += ".lv2";
  837. const File bundlefolder(bundlepath.buffer());
  838. if (bundlefolder.existsAsFile())
  839. {
  840. pData->engine->setLastError("Requested filename already exists as file, use a folder instead");
  841. return false;
  842. }
  843. if (! bundlefolder.exists())
  844. {
  845. const Result res(bundlefolder.createDirectory());
  846. if (res.failed())
  847. {
  848. pData->engine->setLastError(res.getErrorMessage().c_str());
  849. return false;
  850. }
  851. }
  852. CarlaString symbol(pData->name);
  853. symbol.toBasic();
  854. {
  855. const CarlaString pluginFilename(bundlepath + CARLA_OS_SEP_STR + symbol + ".xml");
  856. if (! saveStateToFile(pluginFilename))
  857. return false;
  858. }
  859. {
  860. MemoryOutputStream manifestStream;
  861. manifestStream << "@prefix lv2: <http://lv2plug.in/ns/lv2core#> .\n";
  862. manifestStream << "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n";
  863. manifestStream << "@prefix ui: <http://lv2plug.in/ns/extensions/ui#> .\n";
  864. manifestStream << "\n";
  865. manifestStream << "<" << symbol.buffer() << ".ttl>\n";
  866. manifestStream << " a lv2:Plugin ;\n";
  867. manifestStream << " lv2:binary <" << symbol.buffer() << CARLA_LIB_EXT "> ;\n";
  868. manifestStream << " rdfs:seeAlso <" << symbol.buffer() << ".ttl> .\n";
  869. manifestStream << "\n";
  870. manifestStream << "<ext-ui>\n";
  871. manifestStream << " a <http://kxstudio.sf.net/ns/lv2ext/external-ui#Widget> ;\n";
  872. manifestStream << " ui:binary <" << symbol.buffer() << CARLA_LIB_EXT "> ;\n";
  873. manifestStream << " lv2:extensionData <http://lv2plug.in/ns/extensions/ui#idleInterface> ,\n";
  874. manifestStream << " <http://lv2plug.in/ns/extensions/ui#showInterface> ;\n";
  875. manifestStream << " lv2:requiredFeature <http://lv2plug.in/ns/ext/instance-access> .\n";
  876. manifestStream << "\n";
  877. const CarlaString manifestFilename(bundlepath + CARLA_OS_SEP_STR "manifest.ttl");
  878. const File manifestFile(manifestFilename.buffer());
  879. if (! manifestFile.replaceWithData(manifestStream.getData(), manifestStream.getDataSize()))
  880. {
  881. pData->engine->setLastError("Failed to write manifest.ttl file");
  882. return false;
  883. }
  884. }
  885. {
  886. MemoryOutputStream mainStream;
  887. mainStream << "@prefix atom: <http://lv2plug.in/ns/ext/atom#> .\n";
  888. mainStream << "@prefix doap: <http://usefulinc.com/ns/doap#> .\n";
  889. mainStream << "@prefix foaf: <http://xmlns.com/foaf/0.1/> .\n";
  890. mainStream << "@prefix lv2: <http://lv2plug.in/ns/lv2core#> .\n";
  891. mainStream << "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n";
  892. mainStream << "@prefix ui: <http://lv2plug.in/ns/extensions/ui#> .\n";
  893. mainStream << "\n";
  894. mainStream << "<>\n";
  895. mainStream << " a lv2:Plugin ;\n";
  896. mainStream << "\n";
  897. mainStream << " lv2:requiredFeature <http://lv2plug.in/ns/ext/buf-size#boundedBlockLength> ,\n";
  898. mainStream << " <http://lv2plug.in/ns/ext/options#options> ,\n";
  899. mainStream << " <http://lv2plug.in/ns/ext/urid#map> ;\n";
  900. mainStream << "\n";
  901. if (pData->hints & PLUGIN_HAS_CUSTOM_UI)
  902. {
  903. mainStream << " ui:ui <ext-ui> ;\n";
  904. mainStream << "\n";
  905. }
  906. const uint32_t midiIns = getMidiInCount();
  907. const uint32_t midiOuts = getMidiOutCount();
  908. int portIndex = 0;
  909. if (midiIns > 0)
  910. {
  911. mainStream << " lv2:port [\n";
  912. mainStream << " a lv2:InputPort, atom:AtomPort ;\n";
  913. mainStream << " lv2:index 0 ;\n";
  914. mainStream << " lv2:symbol \"clv2_events_in\" ;\n";
  915. mainStream << " lv2:name \"Events Input\" ;\n";
  916. mainStream << " atom:bufferType atom:Sequence ;\n";
  917. mainStream << " atom:supports <http://lv2plug.in/ns/ext/midi#MidiEvent> ,\n";
  918. mainStream << " <http://lv2plug.in/ns/ext/time#Position> ;\n";
  919. mainStream << " ] ;\n";
  920. ++portIndex;
  921. for (uint32_t i=1; i<midiIns; ++i)
  922. {
  923. const String portIndexNum(portIndex++);
  924. const String portIndexLabel(portIndex);
  925. mainStream << " lv2:port [\n";
  926. mainStream << " a lv2:InputPort, atom:AtomPort ;\n";
  927. mainStream << " lv2:index " << portIndexNum << " ;\n";
  928. mainStream << " lv2:symbol \"clv2_midi_in_" << portIndexLabel << "\" ;\n";
  929. mainStream << " lv2:name \"MIDI Input " << portIndexLabel << "\" ;\n";
  930. mainStream << " ] ;\n";
  931. }
  932. }
  933. else
  934. {
  935. mainStream << " lv2:port [\n";
  936. mainStream << " a lv2:InputPort, atom:AtomPort ;\n";
  937. mainStream << " lv2:index 0 ;\n";
  938. mainStream << " lv2:symbol \"clv2_time_info\" ;\n";
  939. mainStream << " lv2:name \"Time Info\" ;\n";
  940. mainStream << " atom:bufferType atom:Sequence ;\n";
  941. mainStream << " atom:supports <http://lv2plug.in/ns/ext/time#Position> ;\n";
  942. mainStream << " ] ;\n";
  943. ++portIndex;
  944. }
  945. for (uint32_t i=0; i<midiOuts; ++i)
  946. {
  947. const String portIndexNum(portIndex++);
  948. const String portIndexLabel(portIndex);
  949. mainStream << " lv2:port [\n";
  950. mainStream << " a lv2:InputPort, atom:AtomPort ;\n";
  951. mainStream << " lv2:index " << portIndexNum << " ;\n";
  952. mainStream << " lv2:symbol \"clv2_midi_out_" << portIndexLabel << "\" ;\n";
  953. mainStream << " lv2:name \"MIDI Output " << portIndexLabel << "\" ;\n";
  954. mainStream << " atom:bufferType atom:Sequence ;\n";
  955. mainStream << " atom:supports <http://lv2plug.in/ns/ext/midi#MidiEvent> ;\n";
  956. mainStream << " ] ;\n";
  957. }
  958. mainStream << " lv2:port [\n";
  959. mainStream << " a lv2:InputPort, lv2:ControlPort ;\n";
  960. mainStream << " lv2:index " << String(portIndex++) << " ;\n";
  961. mainStream << " lv2:name \"freewheel\" ;\n";
  962. mainStream << " lv2:symbol \"clv2_freewheel\" ;\n";
  963. mainStream << " lv2:default 0 ;\n";
  964. mainStream << " lv2:minimum 0 ;\n";
  965. mainStream << " lv2:maximum 1 ;\n";
  966. mainStream << " lv2:designation lv2:freeWheeling ;\n";
  967. mainStream << " lv2:portProperty lv2:toggled , lv2:integer ;\n";
  968. mainStream << " lv2:portProperty <http://lv2plug.in/ns/ext/port-props#notOnGUI> ;\n";
  969. mainStream << " ] ;\n";
  970. for (uint32_t i=0; i<pData->audioIn.count; ++i)
  971. {
  972. const String portIndexNum(portIndex++);
  973. const String portIndexLabel(i+1);
  974. mainStream << " lv2:port [\n";
  975. mainStream << " a lv2:InputPort, lv2:AudioPort ;\n";
  976. mainStream << " lv2:index " << portIndexNum << " ;\n";
  977. mainStream << " lv2:symbol \"clv2_audio_in_" << portIndexLabel << "\" ;\n";
  978. mainStream << " lv2:name \"Audio Input " << portIndexLabel << "\" ;\n";
  979. mainStream << " ] ;\n";
  980. }
  981. for (uint32_t i=0; i<pData->audioOut.count; ++i)
  982. {
  983. const String portIndexNum(portIndex++);
  984. const String portIndexLabel(i+1);
  985. mainStream << " lv2:port [\n";
  986. mainStream << " a lv2:OutputPort, lv2:AudioPort ;\n";
  987. mainStream << " lv2:index " << portIndexNum << " ;\n";
  988. mainStream << " lv2:symbol \"clv2_audio_out_" << portIndexLabel << "\" ;\n";
  989. mainStream << " lv2:name \"Audio Output " << portIndexLabel << "\" ;\n";
  990. mainStream << " ] ;\n";
  991. }
  992. CarlaStringList uniqueSymbolNames;
  993. char strBufName[STR_MAX+1];
  994. char strBufSymbol[STR_MAX+1];
  995. carla_zeroChars(strBufName, STR_MAX+1);
  996. carla_zeroChars(strBufSymbol, STR_MAX+1);
  997. for (uint32_t i=0; i<pData->param.count; ++i)
  998. {
  999. const ParameterData& paramData(pData->param.data[i]);
  1000. const ParameterRanges& paramRanges(pData->param.ranges[i]);
  1001. const String portIndexNum(portIndex++);
  1002. mainStream << " lv2:port [\n";
  1003. if (paramData.type == PARAMETER_INPUT)
  1004. mainStream << " a lv2:InputPort, lv2:ControlPort ;\n";
  1005. else
  1006. mainStream << " a lv2:OutputPort, lv2:ControlPort ;\n";
  1007. if (paramData.hints & PARAMETER_IS_BOOLEAN)
  1008. mainStream << " lv2:portProperty lv2:toggled ;\n";
  1009. if (paramData.hints & PARAMETER_IS_INTEGER)
  1010. mainStream << " lv2:portProperty lv2:integer ;\n";
  1011. // TODO logarithmic, enabled (not on gui), automatable, samplerate, scalepoints
  1012. if (! getParameterName(i, strBufName))
  1013. strBufName[0] = '\0';
  1014. if (! getParameterSymbol(i, strBufSymbol))
  1015. strBufSymbol[0] = '\0';
  1016. if (strBufSymbol[0] == '\0')
  1017. {
  1018. CarlaString s(strBufName);
  1019. s.toBasic();
  1020. std::memcpy(strBufSymbol, s.buffer(), s.length()+1);
  1021. if (strBufSymbol[0] >= '0' && strBufSymbol[0] <= '9')
  1022. {
  1023. const size_t len(std::strlen(strBufSymbol));
  1024. std::memmove(strBufSymbol+1, strBufSymbol, len);
  1025. strBufSymbol[0] = '_';
  1026. strBufSymbol[len+1] = '\0';
  1027. }
  1028. }
  1029. if (uniqueSymbolNames.contains(strBufSymbol))
  1030. std::snprintf(strBufSymbol, STR_MAX, "clv2_param_%d", i+1);
  1031. mainStream << " lv2:index " << portIndexNum << " ;\n";
  1032. mainStream << " lv2:symbol \"" << strBufSymbol << "\" ;\n";
  1033. mainStream << " lv2:name \"\"\"" << strBufName << "\"\"\" ;\n";
  1034. mainStream << " lv2:default " << String(paramRanges.def) << " ;\n";
  1035. mainStream << " lv2:minimum " << String(paramRanges.min) << " ;\n";
  1036. mainStream << " lv2:maximum " << String(paramRanges.max) << " ;\n";
  1037. // TODO midiCC, midiChannel
  1038. mainStream << " ] ;\n";
  1039. }
  1040. char strBuf[STR_MAX+1];
  1041. carla_zeroChars(strBuf, STR_MAX+1);
  1042. if (! getMaker(strBuf))
  1043. strBuf[0] = '\0';
  1044. mainStream << " rdfs:comment \"Plugin generated using Carla LV2 export.\" ;\n";
  1045. mainStream << " doap:name \"\"\"" << getName() << "\"\"\" ;\n";
  1046. mainStream << " doap:maintainer [ foaf:name \"\"\"" << strBuf << "\"\"\" ] .\n";
  1047. mainStream << "\n";
  1048. const CarlaString mainFilename(bundlepath + CARLA_OS_SEP_STR + symbol + ".ttl");
  1049. const File mainFile(mainFilename.buffer());
  1050. if (! mainFile.replaceWithData(mainStream.getData(), mainStream.getDataSize()))
  1051. {
  1052. pData->engine->setLastError("Failed to write main plugin ttl file");
  1053. return false;
  1054. }
  1055. }
  1056. const CarlaString binaryFilename(bundlepath + CARLA_OS_SEP_STR + symbol + CARLA_LIB_EXT);
  1057. const File binaryFileSource(File::getSpecialLocation(File::currentExecutableFile).getSiblingFile("carla-bridge-lv2" CARLA_LIB_EXT));
  1058. const File binaryFileTarget(binaryFilename.buffer());
  1059. const EngineOptions& opts(pData->engine->getOptions());
  1060. const CarlaString binFolderTarget(bundlepath + CARLA_OS_SEP_STR + "bin");
  1061. const CarlaString resFolderTarget(bundlepath + CARLA_OS_SEP_STR + "res");
  1062. if (! binaryFileSource.copyFileTo(binaryFileTarget))
  1063. {
  1064. pData->engine->setLastError("Failed to copy plugin binary");
  1065. return false;
  1066. }
  1067. #ifdef CARLA_OS_WIN
  1068. File(opts.resourceDir).copyDirectoryTo(File(resFolderTarget.buffer()));
  1069. // Copying all the binaries is pointless, just go through the expected needed bits
  1070. const File binFolder1(opts.binaryDir);
  1071. const File binFolder2(binFolderTarget.buffer());
  1072. binFolder2.createDirectory();
  1073. static const char* files[] = {
  1074. "carla-bridge-native.exe",
  1075. "carla-bridge-win32.exe",
  1076. "carla-discovery-win32.exe",
  1077. "carla-discovery-win64.exe",
  1078. "libcarla_utils.dll"
  1079. };
  1080. for (int i=0; i<5; ++i)
  1081. binFolder1.getChildFile(files[i]).copyFileTo(binFolder2.getChildFile(files[i]));;
  1082. #else
  1083. File(opts.binaryDir).createSymbolicLink(File(binFolderTarget.buffer()), true);
  1084. File(opts.resourceDir).createSymbolicLink(File(resFolderTarget.buffer()), true);
  1085. #endif
  1086. return true;
  1087. }
  1088. #endif
  1089. // -------------------------------------------------------------------
  1090. // Set data (internal stuff)
  1091. void CarlaPlugin::setId(const uint newId) noexcept
  1092. {
  1093. pData->id = newId;
  1094. }
  1095. void CarlaPlugin::setName(const char* const newName)
  1096. {
  1097. CARLA_SAFE_ASSERT_RETURN(newName != nullptr && newName[0] != '\0',);
  1098. if (pData->name != nullptr)
  1099. delete[] pData->name;
  1100. pData->name = carla_strdup(newName);
  1101. }
  1102. void CarlaPlugin::setOption(const uint option, const bool yesNo, const bool sendCallback)
  1103. {
  1104. CARLA_SAFE_ASSERT_UINT2_RETURN(getOptionsAvailable() & option, getOptionsAvailable(), option,);
  1105. if (yesNo)
  1106. pData->options |= option;
  1107. else
  1108. pData->options &= ~option;
  1109. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1110. if (sendCallback)
  1111. pData->engine->callback(true, true,
  1112. ENGINE_CALLBACK_OPTION_CHANGED,
  1113. pData->id,
  1114. static_cast<int>(option),
  1115. yesNo ? 1 : 0,
  1116. 0, 0.0f, nullptr);
  1117. #else
  1118. // unused
  1119. return; (void)sendCallback;
  1120. #endif
  1121. }
  1122. void CarlaPlugin::setEnabled(const bool yesNo) noexcept
  1123. {
  1124. if (pData->enabled == yesNo)
  1125. return;
  1126. pData->masterMutex.lock();
  1127. pData->enabled = yesNo;
  1128. if (yesNo && ! pData->client->isActive())
  1129. pData->client->activate();
  1130. pData->masterMutex.unlock();
  1131. }
  1132. void CarlaPlugin::setActive(const bool active, const bool sendOsc, const bool sendCallback) noexcept
  1133. {
  1134. if (pData->engineBridged) {
  1135. CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
  1136. } else if (pData->enginePlugin) {
  1137. // nothing here
  1138. } else {
  1139. CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
  1140. }
  1141. if (pData->active == active)
  1142. return;
  1143. {
  1144. const ScopedSingleProcessLocker spl(this, true);
  1145. if (active)
  1146. activate();
  1147. else
  1148. deactivate();
  1149. }
  1150. pData->active = active;
  1151. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1152. const float value = active ? 1.0f : 0.0f;
  1153. pData->engine->callback(sendCallback, sendOsc,
  1154. ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
  1155. pData->id,
  1156. PARAMETER_ACTIVE,
  1157. 0, 0,
  1158. value,
  1159. nullptr);
  1160. #endif
  1161. }
  1162. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1163. void CarlaPlugin::setDryWet(const float value, const bool sendOsc, const bool sendCallback) noexcept
  1164. {
  1165. if (pData->engineBridged) {
  1166. CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
  1167. } else {
  1168. CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
  1169. }
  1170. CARLA_SAFE_ASSERT(value >= 0.0f && value <= 1.0f);
  1171. const float fixedValue(carla_fixedValue<float>(0.0f, 1.0f, value));
  1172. if (carla_isEqual(pData->postProc.dryWet, fixedValue))
  1173. return;
  1174. pData->postProc.dryWet = fixedValue;
  1175. pData->engine->callback(sendCallback, sendOsc,
  1176. ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
  1177. pData->id,
  1178. PARAMETER_DRYWET,
  1179. 0, 0,
  1180. fixedValue,
  1181. nullptr);
  1182. }
  1183. void CarlaPlugin::setVolume(const float value, const bool sendOsc, const bool sendCallback) noexcept
  1184. {
  1185. if (pData->engineBridged) {
  1186. CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
  1187. } else {
  1188. CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
  1189. }
  1190. CARLA_SAFE_ASSERT(value >= 0.0f && value <= 1.27f);
  1191. const float fixedValue(carla_fixedValue<float>(0.0f, 1.27f, value));
  1192. if (carla_isEqual(pData->postProc.volume, fixedValue))
  1193. return;
  1194. pData->postProc.volume = fixedValue;
  1195. pData->engine->callback(sendCallback, sendOsc,
  1196. ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
  1197. pData->id,
  1198. PARAMETER_VOLUME,
  1199. 0, 0,
  1200. fixedValue,
  1201. nullptr);
  1202. }
  1203. void CarlaPlugin::setBalanceLeft(const float value, const bool sendOsc, const bool sendCallback) noexcept
  1204. {
  1205. if (pData->engineBridged) {
  1206. CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
  1207. } else {
  1208. CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
  1209. }
  1210. CARLA_SAFE_ASSERT(value >= -1.0f && value <= 1.0f);
  1211. const float fixedValue(carla_fixedValue<float>(-1.0f, 1.0f, value));
  1212. if (carla_isEqual(pData->postProc.balanceLeft, fixedValue))
  1213. return;
  1214. pData->postProc.balanceLeft = fixedValue;
  1215. pData->engine->callback(sendCallback, sendOsc,
  1216. ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
  1217. pData->id,
  1218. PARAMETER_BALANCE_LEFT,
  1219. 0, 0,
  1220. fixedValue,
  1221. nullptr);
  1222. }
  1223. void CarlaPlugin::setBalanceRight(const float value, const bool sendOsc, const bool sendCallback) noexcept
  1224. {
  1225. if (pData->engineBridged) {
  1226. CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
  1227. } else {
  1228. CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
  1229. }
  1230. CARLA_SAFE_ASSERT(value >= -1.0f && value <= 1.0f);
  1231. const float fixedValue(carla_fixedValue<float>(-1.0f, 1.0f, value));
  1232. if (carla_isEqual(pData->postProc.balanceRight, fixedValue))
  1233. return;
  1234. pData->postProc.balanceRight = fixedValue;
  1235. pData->engine->callback(sendCallback, sendOsc,
  1236. ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
  1237. pData->id,
  1238. PARAMETER_BALANCE_RIGHT,
  1239. 0, 0,
  1240. fixedValue,
  1241. nullptr);
  1242. }
  1243. void CarlaPlugin::setPanning(const float value, const bool sendOsc, const bool sendCallback) noexcept
  1244. {
  1245. if (pData->engineBridged) {
  1246. CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
  1247. } else {
  1248. CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
  1249. }
  1250. CARLA_SAFE_ASSERT(value >= -1.0f && value <= 1.0f);
  1251. const float fixedValue(carla_fixedValue<float>(-1.0f, 1.0f, value));
  1252. if (carla_isEqual(pData->postProc.panning, fixedValue))
  1253. return;
  1254. pData->postProc.panning = fixedValue;
  1255. pData->engine->callback(sendCallback, sendOsc,
  1256. ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
  1257. pData->id,
  1258. PARAMETER_PANNING,
  1259. 0, 0,
  1260. fixedValue,
  1261. nullptr);
  1262. }
  1263. void CarlaPlugin::setDryWetRT(const float value, const bool sendCallbackLater) noexcept
  1264. {
  1265. CARLA_SAFE_ASSERT(value >= 0.0f && value <= 1.0f);
  1266. const float fixedValue(carla_fixedValue<float>(0.0f, 1.0f, value));
  1267. if (carla_isEqual(pData->postProc.dryWet, fixedValue))
  1268. return;
  1269. pData->postProc.dryWet = fixedValue;
  1270. pData->postponeParameterChangeRtEvent(sendCallbackLater, PARAMETER_DRYWET, fixedValue);
  1271. }
  1272. void CarlaPlugin::setVolumeRT(const float value, const bool sendCallbackLater) noexcept
  1273. {
  1274. CARLA_SAFE_ASSERT(value >= 0.0f && value <= 1.27f);
  1275. const float fixedValue(carla_fixedValue<float>(0.0f, 1.27f, value));
  1276. if (carla_isEqual(pData->postProc.volume, fixedValue))
  1277. return;
  1278. pData->postProc.volume = fixedValue;
  1279. pData->postponeParameterChangeRtEvent(sendCallbackLater, PARAMETER_VOLUME, fixedValue);
  1280. }
  1281. void CarlaPlugin::setBalanceLeftRT(const float value, const bool sendCallbackLater) noexcept
  1282. {
  1283. CARLA_SAFE_ASSERT(value >= -1.0f && value <= 1.0f);
  1284. const float fixedValue(carla_fixedValue<float>(-1.0f, 1.0f, value));
  1285. if (carla_isEqual(pData->postProc.balanceLeft, fixedValue))
  1286. return;
  1287. pData->postProc.balanceLeft = fixedValue;
  1288. pData->postponeParameterChangeRtEvent(sendCallbackLater, PARAMETER_BALANCE_LEFT, fixedValue);
  1289. }
  1290. void CarlaPlugin::setBalanceRightRT(const float value, const bool sendCallbackLater) noexcept
  1291. {
  1292. CARLA_SAFE_ASSERT(value >= -1.0f && value <= 1.0f);
  1293. const float fixedValue(carla_fixedValue<float>(-1.0f, 1.0f, value));
  1294. if (carla_isEqual(pData->postProc.balanceRight, fixedValue))
  1295. return;
  1296. pData->postProc.balanceRight = fixedValue;
  1297. pData->postponeParameterChangeRtEvent(sendCallbackLater, PARAMETER_BALANCE_RIGHT, fixedValue);
  1298. }
  1299. void CarlaPlugin::setPanningRT(const float value, const bool sendCallbackLater) noexcept
  1300. {
  1301. CARLA_SAFE_ASSERT(value >= -1.0f && value <= 1.0f);
  1302. const float fixedValue(carla_fixedValue<float>(-1.0f, 1.0f, value));
  1303. if (carla_isEqual(pData->postProc.panning, fixedValue))
  1304. return;
  1305. pData->postProc.panning = fixedValue;
  1306. pData->postponeParameterChangeRtEvent(sendCallbackLater, PARAMETER_PANNING, fixedValue);
  1307. }
  1308. #endif // ! BUILD_BRIDGE_ALTERNATIVE_ARCH
  1309. void CarlaPlugin::setCtrlChannel(const int8_t channel, const bool sendOsc, const bool sendCallback) noexcept
  1310. {
  1311. if (pData->engineBridged) {
  1312. CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
  1313. } else {
  1314. CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
  1315. }
  1316. CARLA_SAFE_ASSERT_RETURN(channel >= -1 && channel < MAX_MIDI_CHANNELS,);
  1317. if (pData->ctrlChannel == channel)
  1318. return;
  1319. pData->ctrlChannel = channel;
  1320. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1321. const float channelf = static_cast<float>(channel);
  1322. pData->engine->callback(sendCallback, sendOsc,
  1323. ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
  1324. pData->id,
  1325. PARAMETER_CTRL_CHANNEL,
  1326. 0, 0,
  1327. channelf, nullptr);
  1328. #endif
  1329. }
  1330. // -------------------------------------------------------------------
  1331. // Set data (plugin-specific stuff)
  1332. void CarlaPlugin::setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept
  1333. {
  1334. if (pData->engineBridged) {
  1335. // NOTE: some LV2 plugins feedback messages to UI on purpose
  1336. CARLA_SAFE_ASSERT_RETURN(getType() == PLUGIN_LV2 || !sendGui,);
  1337. } else if (pData->enginePlugin) {
  1338. // nothing here
  1339. } else {
  1340. CARLA_SAFE_ASSERT_RETURN(sendGui || sendOsc || sendCallback,); // never call this from RT
  1341. }
  1342. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,);
  1343. if (sendGui && (pData->hints & PLUGIN_HAS_CUSTOM_UI) != 0)
  1344. uiParameterChange(parameterId, value);
  1345. pData->engine->callback(sendCallback, sendOsc,
  1346. ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
  1347. pData->id,
  1348. static_cast<int>(parameterId),
  1349. 0, 0,
  1350. value,
  1351. nullptr);
  1352. }
  1353. void CarlaPlugin::setParameterValueRT(const uint32_t parameterId, const float value, uint32_t, const bool sendCallbackLater) noexcept
  1354. {
  1355. pData->postponeParameterChangeRtEvent(sendCallbackLater, static_cast<int32_t>(parameterId), value);
  1356. }
  1357. void CarlaPlugin::setParameterValueByRealIndex(const int32_t rindex, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept
  1358. {
  1359. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1360. CARLA_SAFE_ASSERT_RETURN(rindex > PARAMETER_MAX && rindex != PARAMETER_NULL,);
  1361. switch (rindex)
  1362. {
  1363. case PARAMETER_ACTIVE:
  1364. return setActive((value > 0.0f), sendOsc, sendCallback);
  1365. case PARAMETER_CTRL_CHANNEL:
  1366. return setCtrlChannel(int8_t(value), sendOsc, sendCallback);
  1367. case PARAMETER_DRYWET:
  1368. return setDryWet(value, sendOsc, sendCallback);
  1369. case PARAMETER_VOLUME:
  1370. return setVolume(value, sendOsc, sendCallback);
  1371. case PARAMETER_BALANCE_LEFT:
  1372. return setBalanceLeft(value, sendOsc, sendCallback);
  1373. case PARAMETER_BALANCE_RIGHT:
  1374. return setBalanceRight(value, sendOsc, sendCallback);
  1375. case PARAMETER_PANNING:
  1376. return setPanning(value, sendOsc, sendCallback);
  1377. }
  1378. #endif
  1379. CARLA_SAFE_ASSERT_RETURN(rindex >= 0,);
  1380. for (uint32_t i=0; i < pData->param.count; ++i)
  1381. {
  1382. if (pData->param.data[i].rindex == rindex)
  1383. {
  1384. //if (carla_isNotEqual(getParameterValue(i), value))
  1385. setParameterValue(i, value, sendGui, sendOsc, sendCallback);
  1386. break;
  1387. }
  1388. }
  1389. }
  1390. void CarlaPlugin::setParameterMidiChannel(const uint32_t parameterId, const uint8_t channel, const bool sendOsc, const bool sendCallback) noexcept
  1391. {
  1392. if (pData->engineBridged) {
  1393. CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
  1394. } else {
  1395. CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
  1396. }
  1397. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,);
  1398. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  1399. if (pData->param.data[parameterId].midiChannel == channel)
  1400. return;
  1401. pData->param.data[parameterId].midiChannel = channel;
  1402. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1403. pData->engine->callback(sendCallback, sendOsc,
  1404. ENGINE_CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED,
  1405. pData->id,
  1406. static_cast<int>(parameterId),
  1407. channel,
  1408. 0, 0.0f, nullptr);
  1409. #endif
  1410. }
  1411. void CarlaPlugin::setParameterMappedControlIndex(const uint32_t parameterId, const int16_t index,
  1412. const bool sendOsc, const bool sendCallback,
  1413. const bool reconfigureNow) noexcept
  1414. {
  1415. if (pData->engineBridged) {
  1416. CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
  1417. } else {
  1418. CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
  1419. }
  1420. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,);
  1421. CARLA_SAFE_ASSERT_RETURN(index >= CONTROL_INDEX_NONE && index <= CONTROL_INDEX_MAX_ALLOWED,);
  1422. ParameterData& paramData(pData->param.data[parameterId]);
  1423. if (paramData.mappedControlIndex == index)
  1424. return;
  1425. const ParameterRanges& paramRanges(pData->param.ranges[parameterId]);
  1426. if ((paramData.hints & PARAMETER_MAPPED_RANGES_SET) == 0x0)
  1427. setParameterMappedRange(parameterId, paramRanges.min, paramRanges.max, true, true);
  1428. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1429. char strBuf[STR_MAX+1];
  1430. carla_zeroChars(strBuf, STR_MAX+1);
  1431. if (! getParameterName(parameterId, strBuf))
  1432. std::snprintf(strBuf, STR_MAX, "Param %u", parameterId);
  1433. const uint portNameSize = pData->engine->getMaxPortNameSize();
  1434. if (portNameSize < STR_MAX)
  1435. strBuf[portNameSize] = '\0';
  1436. // was learning something else before, stop that first
  1437. if (pData->midiLearnParameterIndex >= 0 && pData->midiLearnParameterIndex != static_cast<int32_t>(parameterId))
  1438. {
  1439. const int32_t oldParameterId = pData->midiLearnParameterIndex;
  1440. pData->midiLearnParameterIndex = -1;
  1441. CARLA_SAFE_ASSERT_RETURN(oldParameterId < static_cast<int32_t>(pData->param.count),);
  1442. pData->param.data[oldParameterId].mappedControlIndex = CONTROL_INDEX_NONE;
  1443. pData->engine->callback(true, true,
  1444. ENGINE_CALLBACK_PARAMETER_MAPPED_CONTROL_INDEX_CHANGED,
  1445. pData->id,
  1446. oldParameterId,
  1447. CONTROL_INDEX_NONE,
  1448. 0, 0.0f, nullptr);
  1449. }
  1450. // mapping new parameter to CV
  1451. if (index == CONTROL_INDEX_CV)
  1452. {
  1453. CARLA_SAFE_ASSERT_RETURN(pData->event.cvSourcePorts != nullptr,);
  1454. CARLA_SAFE_ASSERT_RETURN(paramData.type == PARAMETER_INPUT,);
  1455. CARLA_SAFE_ASSERT_RETURN(paramData.hints & PARAMETER_CAN_BE_CV_CONTROLLED,);
  1456. CarlaEngineCVPort* const cvPort =
  1457. (CarlaEngineCVPort*)pData->client->addPort(kEnginePortTypeCV, strBuf, true, parameterId);
  1458. cvPort->setRange(paramData.mappedMinimum, paramData.mappedMaximum);
  1459. pData->event.cvSourcePorts->addCVSource(cvPort, parameterId, reconfigureNow);
  1460. }
  1461. // unmapping from CV
  1462. else if (paramData.mappedControlIndex == CONTROL_INDEX_CV)
  1463. {
  1464. CARLA_SAFE_ASSERT_RETURN(pData->event.cvSourcePorts != nullptr,);
  1465. CARLA_SAFE_ASSERT(pData->client->removePort(kEnginePortTypeCV, strBuf, true));
  1466. CARLA_SAFE_ASSERT(pData->event.cvSourcePorts->removeCVSource(parameterId));
  1467. }
  1468. // mapping to something new
  1469. else if (paramData.mappedControlIndex == CONTROL_INDEX_NONE)
  1470. {
  1471. // when doing MIDI CC mapping, ensure ranges are within bounds
  1472. if (paramData.mappedMinimum < paramRanges.min || paramData.mappedMaximum > paramRanges.max)
  1473. setParameterMappedRange(parameterId,
  1474. std::max(paramData.mappedMinimum, paramRanges.min),
  1475. std::min(paramData.mappedMaximum, paramRanges.max),
  1476. true, true);
  1477. }
  1478. #endif
  1479. paramData.mappedControlIndex = index;
  1480. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1481. if (index == CONTROL_INDEX_MIDI_LEARN)
  1482. pData->midiLearnParameterIndex = static_cast<int32_t>(parameterId);
  1483. else
  1484. pData->midiLearnParameterIndex = -1;
  1485. pData->engine->callback(sendCallback, sendOsc,
  1486. ENGINE_CALLBACK_PARAMETER_MAPPED_CONTROL_INDEX_CHANGED,
  1487. pData->id,
  1488. static_cast<int>(parameterId),
  1489. index,
  1490. 0, 0.0f, nullptr);
  1491. #else
  1492. return;
  1493. // unused
  1494. (void)reconfigureNow;
  1495. #endif
  1496. }
  1497. void CarlaPlugin::setParameterMappedRange(const uint32_t parameterId, const float minimum, const float maximum,
  1498. const bool sendOsc, const bool sendCallback) noexcept
  1499. {
  1500. if (pData->engineBridged) {
  1501. CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
  1502. } else {
  1503. CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
  1504. }
  1505. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,);
  1506. ParameterData& paramData(pData->param.data[parameterId]);
  1507. if (carla_isEqual(paramData.mappedMinimum, minimum) &&
  1508. carla_isEqual(paramData.mappedMaximum, maximum) &&
  1509. (paramData.hints & PARAMETER_MAPPED_RANGES_SET) != 0x0)
  1510. return;
  1511. if (paramData.mappedControlIndex != CONTROL_INDEX_NONE && paramData.mappedControlIndex != CONTROL_INDEX_CV)
  1512. {
  1513. const ParameterRanges& paramRanges(pData->param.ranges[parameterId]);
  1514. CARLA_SAFE_ASSERT_RETURN(minimum >= paramRanges.min,);
  1515. CARLA_SAFE_ASSERT_RETURN(maximum <= paramRanges.max,);
  1516. }
  1517. paramData.hints |= PARAMETER_MAPPED_RANGES_SET;
  1518. paramData.mappedMinimum = minimum;
  1519. paramData.mappedMaximum = maximum;
  1520. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1521. if (pData->event.cvSourcePorts != nullptr && paramData.mappedControlIndex == CONTROL_INDEX_CV)
  1522. pData->event.cvSourcePorts->setCVSourceRange(parameterId, minimum, maximum);
  1523. char strBuf[STR_MAX+1];
  1524. carla_zeroChars(strBuf, STR_MAX+1);
  1525. std::snprintf(strBuf, STR_MAX, "%.12g:%.12g", static_cast<double>(minimum), static_cast<double>(maximum));
  1526. pData->engine->callback(sendCallback, sendOsc,
  1527. ENGINE_CALLBACK_PARAMETER_MAPPED_RANGE_CHANGED,
  1528. pData->id,
  1529. static_cast<int>(parameterId),
  1530. 0, 0, 0.0f,
  1531. strBuf);
  1532. #endif
  1533. }
  1534. void CarlaPlugin::setCustomData(const char* const type, const char* const key, const char* const value, const bool)
  1535. {
  1536. CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0',);
  1537. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
  1538. CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
  1539. // Ignore some keys
  1540. if (std::strcmp(type, CUSTOM_DATA_TYPE_STRING) == 0)
  1541. {
  1542. const PluginType ptype = getType();
  1543. if ((ptype == PLUGIN_INTERNAL && std::strncmp(key, "CarlaAlternateFile", 18) == 0) ||
  1544. (ptype == PLUGIN_DSSI && std::strcmp (key, "guiVisible") == 0) ||
  1545. (ptype == PLUGIN_LV2 && std::strncmp(key, "OSC:", 4) == 0))
  1546. return;
  1547. }
  1548. // Check if we already have this key
  1549. for (LinkedList<CustomData>::Itenerator it = pData->custom.begin2(); it.valid(); it.next())
  1550. {
  1551. CustomData& customData(it.getValue(kCustomDataFallbackNC));
  1552. CARLA_SAFE_ASSERT_CONTINUE(customData.isValid());
  1553. if (std::strcmp(customData.key, key) == 0)
  1554. {
  1555. if (customData.value != nullptr)
  1556. delete[] customData.value;
  1557. customData.value = carla_strdup(value);
  1558. return;
  1559. }
  1560. }
  1561. // Otherwise store it
  1562. CustomData customData;
  1563. customData.type = carla_strdup(type);
  1564. customData.key = carla_strdup(key);
  1565. customData.value = carla_strdup(value);
  1566. pData->custom.append(customData);
  1567. }
  1568. void CarlaPlugin::setChunkData(const void* const data, const std::size_t dataSize)
  1569. {
  1570. CARLA_SAFE_ASSERT_RETURN(data != nullptr,);
  1571. CARLA_SAFE_ASSERT_RETURN(dataSize > 0,);
  1572. CARLA_SAFE_ASSERT(false); // this should never happen
  1573. }
  1574. void CarlaPlugin::setProgram(const int32_t index,
  1575. const bool sendGui, const bool sendOsc, const bool sendCallback, const bool) noexcept
  1576. {
  1577. CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast<int32_t>(pData->prog.count),);
  1578. pData->prog.current = index;
  1579. pData->engine->callback(sendCallback, sendOsc,
  1580. ENGINE_CALLBACK_PROGRAM_CHANGED,
  1581. pData->id,
  1582. index,
  1583. 0, 0, 0.0f, nullptr);
  1584. // Change default parameter values
  1585. if (index >= 0)
  1586. {
  1587. if (sendGui && (pData->hints & PLUGIN_HAS_CUSTOM_UI) != 0)
  1588. uiProgramChange(static_cast<uint32_t>(index));
  1589. switch (getType())
  1590. {
  1591. case PLUGIN_SF2:
  1592. case PLUGIN_SFZ:
  1593. break;
  1594. default:
  1595. pData->updateParameterValues(this, sendCallback, sendOsc, true);
  1596. break;
  1597. }
  1598. }
  1599. }
  1600. void CarlaPlugin::setMidiProgram(const int32_t index,
  1601. const bool sendGui, const bool sendOsc, const bool sendCallback, const bool) noexcept
  1602. {
  1603. CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast<int32_t>(pData->midiprog.count),);
  1604. pData->midiprog.current = index;
  1605. pData->engine->callback(sendCallback, sendOsc,
  1606. ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED,
  1607. pData->id,
  1608. index,
  1609. 0, 0, 0.0f, nullptr);
  1610. // Change default parameter values
  1611. if (index >= 0)
  1612. {
  1613. if (sendGui && (pData->hints & PLUGIN_HAS_CUSTOM_UI) != 0)
  1614. uiMidiProgramChange(static_cast<uint32_t>(index));
  1615. switch (getType())
  1616. {
  1617. case PLUGIN_SF2:
  1618. case PLUGIN_SFZ:
  1619. break;
  1620. default:
  1621. pData->updateParameterValues(this, sendCallback, sendOsc, true);
  1622. break;
  1623. }
  1624. }
  1625. }
  1626. void CarlaPlugin::setMidiProgramById(const uint32_t bank, const uint32_t program, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept
  1627. {
  1628. for (uint32_t i=0; i < pData->midiprog.count; ++i)
  1629. {
  1630. if (pData->midiprog.data[i].bank == bank && pData->midiprog.data[i].program == program)
  1631. return setMidiProgram(static_cast<int32_t>(i), sendGui, sendOsc, sendCallback);
  1632. }
  1633. }
  1634. void CarlaPlugin::setProgramRT(const uint32_t uindex, const bool sendCallbackLater) noexcept
  1635. {
  1636. CARLA_SAFE_ASSERT_RETURN(uindex < pData->prog.count,);
  1637. const int32_t index = static_cast<int32_t>(uindex);
  1638. pData->prog.current = index;
  1639. // Change default parameter values
  1640. switch (getType())
  1641. {
  1642. case PLUGIN_SF2:
  1643. case PLUGIN_SFZ:
  1644. break;
  1645. default:
  1646. pData->updateDefaultParameterValues(this);
  1647. break;
  1648. }
  1649. pData->postponeProgramChangeRtEvent(sendCallbackLater, uindex);
  1650. }
  1651. void CarlaPlugin::setMidiProgramRT(const uint32_t uindex, const bool sendCallbackLater) noexcept
  1652. {
  1653. CARLA_SAFE_ASSERT_RETURN(uindex < pData->midiprog.count,);
  1654. const int32_t index = static_cast<int32_t>(uindex);
  1655. pData->midiprog.current = index;
  1656. // Change default parameter values
  1657. switch (getType())
  1658. {
  1659. case PLUGIN_SF2:
  1660. case PLUGIN_SFZ:
  1661. break;
  1662. default:
  1663. pData->updateDefaultParameterValues(this);
  1664. break;
  1665. }
  1666. pData->postponeMidiProgramChangeRtEvent(sendCallbackLater, uindex);
  1667. }
  1668. // -------------------------------------------------------------------
  1669. // Plugin state
  1670. void CarlaPlugin::reloadPrograms(const bool)
  1671. {
  1672. }
  1673. // -------------------------------------------------------------------
  1674. // Plugin processing
  1675. void CarlaPlugin::activate() noexcept
  1676. {
  1677. CARLA_SAFE_ASSERT(! pData->active);
  1678. }
  1679. void CarlaPlugin::deactivate() noexcept
  1680. {
  1681. CARLA_SAFE_ASSERT(pData->active);
  1682. }
  1683. void CarlaPlugin::bufferSizeChanged(const uint32_t newBufferSize)
  1684. {
  1685. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1686. delete[] pData->postProc.extraBuffer;
  1687. pData->postProc.extraBuffer = new float[newBufferSize];
  1688. #else
  1689. // unused
  1690. (void)newBufferSize;
  1691. #endif
  1692. }
  1693. void CarlaPlugin::sampleRateChanged(const double)
  1694. {
  1695. }
  1696. void CarlaPlugin::offlineModeChanged(const bool)
  1697. {
  1698. }
  1699. // -------------------------------------------------------------------
  1700. // Misc
  1701. void CarlaPlugin::idle()
  1702. {
  1703. if (! pData->enabled)
  1704. return;
  1705. const bool hasUI = pData->hints & PLUGIN_HAS_CUSTOM_UI;
  1706. const bool needsUiMainThread = pData->hints & PLUGIN_NEEDS_UI_MAIN_THREAD;
  1707. const uint32_t latency = getLatencyInFrames();
  1708. if (pData->latency.frames != latency)
  1709. {
  1710. carla_stdout("latency changed to %i samples", latency);
  1711. const ScopedSingleProcessLocker sspl(this, true);
  1712. pData->client->setLatency(latency);
  1713. #ifndef BUILD_BRIDGE
  1714. pData->latency.recreateBuffers(pData->latency.channels, latency);
  1715. #else
  1716. pData->latency.frames = latency;
  1717. #endif
  1718. }
  1719. ProtectedData::PostRtEvents::Access rtEvents(pData->postRtEvents);
  1720. if (rtEvents.isEmpty())
  1721. return;
  1722. for (RtLinkedList<PluginPostRtEvent>::Itenerator it = rtEvents.getDataIterator(); it.valid(); it.next())
  1723. {
  1724. const PluginPostRtEvent& event(it.getValue(kPluginPostRtEventFallback));
  1725. CARLA_SAFE_ASSERT_CONTINUE(event.type != kPluginPostRtEventNull);
  1726. switch (event.type)
  1727. {
  1728. case kPluginPostRtEventNull: {
  1729. } break;
  1730. case kPluginPostRtEventParameterChange: {
  1731. // Update UI
  1732. if (event.parameter.index >= 0 && hasUI)
  1733. {
  1734. if (needsUiMainThread)
  1735. pData->postUiEvents.append(event);
  1736. else
  1737. uiParameterChange(static_cast<uint32_t>(event.parameter.index), event.parameter.value);
  1738. }
  1739. if (event.sendCallback)
  1740. {
  1741. // Update Host
  1742. pData->engine->callback(true, true,
  1743. ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
  1744. pData->id,
  1745. event.parameter.index,
  1746. 0, 0,
  1747. event.parameter.value,
  1748. nullptr);
  1749. }
  1750. } break;
  1751. case kPluginPostRtEventProgramChange: {
  1752. // Update UI
  1753. if (hasUI)
  1754. {
  1755. if (needsUiMainThread)
  1756. pData->postUiEvents.append(event);
  1757. else
  1758. uiProgramChange(event.program.index);
  1759. }
  1760. // Update param values
  1761. for (uint32_t j=0; j < pData->param.count; ++j)
  1762. {
  1763. const float paramDefault(pData->param.ranges[j].def);
  1764. const float paramValue(getParameterValue(j));
  1765. pData->engine->callback(true, true,
  1766. ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
  1767. pData->id,
  1768. static_cast<int>(j),
  1769. 0, 0,
  1770. paramValue,
  1771. nullptr);
  1772. pData->engine->callback(true, true,
  1773. ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED,
  1774. pData->id,
  1775. static_cast<int>(j),
  1776. 0, 0,
  1777. paramDefault,
  1778. nullptr);
  1779. }
  1780. if (event.sendCallback)
  1781. {
  1782. // Update Host
  1783. pData->engine->callback(true, true,
  1784. ENGINE_CALLBACK_PROGRAM_CHANGED,
  1785. pData->id,
  1786. static_cast<int>(event.program.index),
  1787. 0, 0, 0.0f, nullptr);
  1788. }
  1789. } break;
  1790. case kPluginPostRtEventMidiProgramChange: {
  1791. // Update UI
  1792. if (hasUI)
  1793. {
  1794. if (needsUiMainThread)
  1795. pData->postUiEvents.append(event);
  1796. else
  1797. uiMidiProgramChange(event.program.index);
  1798. }
  1799. // Update param values
  1800. for (uint32_t j=0; j < pData->param.count; ++j)
  1801. {
  1802. const float paramDefault(pData->param.ranges[j].def);
  1803. const float paramValue(getParameterValue(j));
  1804. pData->engine->callback(true, true,
  1805. ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
  1806. pData->id,
  1807. static_cast<int>(j),
  1808. 0, 0,
  1809. paramValue,
  1810. nullptr);
  1811. pData->engine->callback(true, true,
  1812. ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED,
  1813. pData->id,
  1814. static_cast<int>(j),
  1815. 0, 0,
  1816. paramDefault,
  1817. nullptr);
  1818. }
  1819. if (event.sendCallback)
  1820. {
  1821. // Update Host
  1822. pData->engine->callback(true, true,
  1823. ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED,
  1824. pData->id,
  1825. static_cast<int>(event.program.index),
  1826. 0, 0, 0.0f, nullptr);
  1827. }
  1828. } break;
  1829. case kPluginPostRtEventNoteOn: {
  1830. CARLA_SAFE_ASSERT_BREAK(event.note.channel < MAX_MIDI_CHANNELS);
  1831. CARLA_SAFE_ASSERT_BREAK(event.note.note < MAX_MIDI_NOTE);
  1832. CARLA_SAFE_ASSERT_BREAK(event.note.velocity < MAX_MIDI_VALUE);
  1833. // Update UI
  1834. if (hasUI)
  1835. {
  1836. if (needsUiMainThread)
  1837. pData->postUiEvents.append(event);
  1838. else
  1839. uiNoteOn(event.note.channel, event.note.note, event.note.velocity);
  1840. }
  1841. if (event.sendCallback)
  1842. {
  1843. // Update Host
  1844. pData->engine->callback(true, true,
  1845. ENGINE_CALLBACK_NOTE_ON,
  1846. pData->id,
  1847. static_cast<int>(event.note.channel),
  1848. static_cast<int>(event.note.note),
  1849. static_cast<int>(event.note.velocity),
  1850. 0.0f, nullptr);
  1851. }
  1852. } break;
  1853. case kPluginPostRtEventNoteOff: {
  1854. CARLA_SAFE_ASSERT_BREAK(event.note.channel < MAX_MIDI_CHANNELS);
  1855. CARLA_SAFE_ASSERT_BREAK(event.note.note < MAX_MIDI_NOTE);
  1856. // Update UI
  1857. if (hasUI)
  1858. {
  1859. if (needsUiMainThread)
  1860. pData->postUiEvents.append(event);
  1861. else
  1862. uiNoteOff(event.note.channel, event.note.note);
  1863. }
  1864. if (event.sendCallback)
  1865. {
  1866. // Update Host
  1867. pData->engine->callback(true, true,
  1868. ENGINE_CALLBACK_NOTE_OFF,
  1869. pData->id,
  1870. static_cast<int>(event.note.channel),
  1871. static_cast<int>(event.note.note),
  1872. 0, 0.0f, nullptr);
  1873. }
  1874. } break;
  1875. case kPluginPostRtEventMidiLearn: {
  1876. CARLA_SAFE_ASSERT_BREAK(event.midiLearn.cc < MAX_MIDI_VALUE);
  1877. CARLA_SAFE_ASSERT_BREAK(event.midiLearn.channel < MAX_MIDI_CHANNELS);
  1878. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1879. if (event.sendCallback)
  1880. {
  1881. pData->engine->callback(true, true,
  1882. ENGINE_CALLBACK_PARAMETER_MAPPED_CONTROL_INDEX_CHANGED,
  1883. pData->id,
  1884. static_cast<int>(event.midiLearn.parameter),
  1885. static_cast<int>(event.midiLearn.cc),
  1886. 0, 0.0f, nullptr);
  1887. pData->engine->callback(true, true,
  1888. ENGINE_CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED,
  1889. pData->id,
  1890. static_cast<int>(event.midiLearn.parameter),
  1891. static_cast<int>(event.midiLearn.channel),
  1892. 0, 0.0f, nullptr);
  1893. }
  1894. #endif
  1895. } break;
  1896. }
  1897. }
  1898. }
  1899. bool CarlaPlugin::tryLock(const bool forcedOffline) noexcept
  1900. {
  1901. if (forcedOffline)
  1902. {
  1903. #ifndef STOAT_TEST_BUILD
  1904. pData->masterMutex.lock();
  1905. return true;
  1906. #endif
  1907. }
  1908. return pData->masterMutex.tryLock();
  1909. }
  1910. void CarlaPlugin::unlock() noexcept
  1911. {
  1912. pData->masterMutex.unlock();
  1913. }
  1914. // -------------------------------------------------------------------
  1915. // Plugin buffers
  1916. void CarlaPlugin::initBuffers() const noexcept
  1917. {
  1918. pData->audioIn.initBuffers();
  1919. pData->audioOut.initBuffers();
  1920. pData->cvIn.initBuffers();
  1921. pData->cvOut.initBuffers();
  1922. pData->event.initBuffers();
  1923. }
  1924. void CarlaPlugin::clearBuffers() noexcept
  1925. {
  1926. pData->clearBuffers();
  1927. }
  1928. // -------------------------------------------------------------------
  1929. // OSC stuff
  1930. // FIXME
  1931. void CarlaPlugin::handleOscMessage(const char* const, const int, const void* const, const char* const, const lo_message)
  1932. {
  1933. // do nothing
  1934. }
  1935. // -------------------------------------------------------------------
  1936. // MIDI events
  1937. void CarlaPlugin::sendMidiSingleNote(const uint8_t channel, const uint8_t note, const uint8_t velo, const bool sendGui, const bool sendOsc, const bool sendCallback)
  1938. {
  1939. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  1940. CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
  1941. CARLA_SAFE_ASSERT_RETURN(velo < MAX_MIDI_VALUE,);
  1942. if (! pData->active)
  1943. return;
  1944. ExternalMidiNote extNote;
  1945. extNote.channel = static_cast<int8_t>(channel);
  1946. extNote.note = note;
  1947. extNote.velo = velo;
  1948. pData->extNotes.appendNonRT(extNote);
  1949. if (sendGui && (pData->hints & PLUGIN_HAS_CUSTOM_UI) != 0)
  1950. {
  1951. if (velo > 0)
  1952. uiNoteOn(channel, note, velo);
  1953. else
  1954. uiNoteOff(channel, note);
  1955. }
  1956. pData->engine->callback(sendCallback, sendOsc,
  1957. (velo > 0) ? ENGINE_CALLBACK_NOTE_ON : ENGINE_CALLBACK_NOTE_OFF,
  1958. pData->id,
  1959. channel,
  1960. note,
  1961. velo,
  1962. 0.0f, nullptr);
  1963. }
  1964. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1965. void CarlaPlugin::postponeRtAllNotesOff()
  1966. {
  1967. if (pData->ctrlChannel < 0 || pData->ctrlChannel >= MAX_MIDI_CHANNELS)
  1968. return;
  1969. PluginPostRtEvent postEvent = { kPluginPostRtEventNoteOff, true, {} };
  1970. postEvent.note.channel = static_cast<uint8_t>(pData->ctrlChannel);
  1971. for (uint8_t i=0; i < MAX_MIDI_NOTE; ++i)
  1972. {
  1973. postEvent.note.note = i;
  1974. pData->postRtEvents.appendRT(postEvent);
  1975. }
  1976. }
  1977. #endif
  1978. // -------------------------------------------------------------------
  1979. // UI Stuff
  1980. void CarlaPlugin::setCustomUITitle(const char* const title) noexcept
  1981. {
  1982. pData->uiTitle = title;
  1983. }
  1984. void CarlaPlugin::showCustomUI(const bool yesNo)
  1985. {
  1986. if (yesNo) {
  1987. CARLA_SAFE_ASSERT(false);
  1988. }
  1989. }
  1990. void* CarlaPlugin::embedCustomUI(void*)
  1991. {
  1992. return nullptr;
  1993. }
  1994. void CarlaPlugin::uiIdle()
  1995. {
  1996. if (pData->hints & PLUGIN_NEEDS_UI_MAIN_THREAD)
  1997. {
  1998. // Update parameter outputs
  1999. for (uint32_t i=0; i < pData->param.count; ++i)
  2000. {
  2001. if (pData->param.data[i].type == PARAMETER_OUTPUT)
  2002. uiParameterChange(i, getParameterValue(i));
  2003. }
  2004. const CarlaMutexLocker sl(pData->postUiEvents.mutex);
  2005. for (LinkedList<PluginPostRtEvent>::Itenerator it = pData->postUiEvents.data.begin2(); it.valid(); it.next())
  2006. {
  2007. const PluginPostRtEvent& event(it.getValue(kPluginPostRtEventFallback));
  2008. CARLA_SAFE_ASSERT_CONTINUE(event.type != kPluginPostRtEventNull);
  2009. switch (event.type)
  2010. {
  2011. case kPluginPostRtEventNull:
  2012. case kPluginPostRtEventMidiLearn:
  2013. break;
  2014. case kPluginPostRtEventParameterChange:
  2015. uiParameterChange(static_cast<uint32_t>(event.parameter.index), event.parameter.value);
  2016. break;
  2017. case kPluginPostRtEventProgramChange:
  2018. uiProgramChange(event.program.index);
  2019. break;
  2020. case kPluginPostRtEventMidiProgramChange:
  2021. uiMidiProgramChange(event.program.index);
  2022. break;
  2023. case kPluginPostRtEventNoteOn:
  2024. uiNoteOn(event.note.channel, event.note.note, event.note.velocity);
  2025. break;
  2026. case kPluginPostRtEventNoteOff:
  2027. uiNoteOff(event.note.channel, event.note.note);
  2028. break;
  2029. }
  2030. }
  2031. pData->postUiEvents.data.clear();
  2032. }
  2033. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  2034. if (pData->transientTryCounter == 0)
  2035. return;
  2036. if (++pData->transientTryCounter % 10 != 0)
  2037. return;
  2038. if (pData->transientTryCounter >= 200)
  2039. return;
  2040. carla_stdout("Trying to get window...");
  2041. CarlaString uiTitle;
  2042. if (pData->uiTitle.isNotEmpty())
  2043. {
  2044. uiTitle = pData->uiTitle;
  2045. }
  2046. else
  2047. {
  2048. uiTitle = pData->name;
  2049. uiTitle += " (GUI)";
  2050. }
  2051. if (CarlaPluginUI::tryTransientWinIdMatch(getUiBridgeProcessId(), uiTitle,
  2052. pData->engine->getOptions().frontendWinId, pData->transientFirstTry))
  2053. {
  2054. pData->transientTryCounter = 0;
  2055. pData->transientFirstTry = false;
  2056. }
  2057. #endif
  2058. }
  2059. void CarlaPlugin::uiParameterChange(const uint32_t index, const float value) noexcept
  2060. {
  2061. CARLA_SAFE_ASSERT_RETURN(index < getParameterCount(),);
  2062. return;
  2063. // unused
  2064. (void)value;
  2065. }
  2066. void CarlaPlugin::uiProgramChange(const uint32_t index) noexcept
  2067. {
  2068. CARLA_SAFE_ASSERT_RETURN(index < getProgramCount(),);
  2069. }
  2070. void CarlaPlugin::uiMidiProgramChange(const uint32_t index) noexcept
  2071. {
  2072. CARLA_SAFE_ASSERT_RETURN(index < getMidiProgramCount(),);
  2073. }
  2074. void CarlaPlugin::uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo) noexcept
  2075. {
  2076. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  2077. CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
  2078. CARLA_SAFE_ASSERT_RETURN(velo > 0 && velo < MAX_MIDI_VALUE,);
  2079. }
  2080. void CarlaPlugin::uiNoteOff(const uint8_t channel, const uint8_t note) noexcept
  2081. {
  2082. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  2083. CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
  2084. }
  2085. CarlaEngine* CarlaPlugin::getEngine() const noexcept
  2086. {
  2087. return pData->engine;
  2088. }
  2089. CarlaEngineClient* CarlaPlugin::getEngineClient() const noexcept
  2090. {
  2091. return pData->client;
  2092. }
  2093. CarlaEngineAudioPort* CarlaPlugin::getAudioInPort(const uint32_t index) const noexcept
  2094. {
  2095. return pData->audioIn.ports[index].port;
  2096. }
  2097. CarlaEngineAudioPort* CarlaPlugin::getAudioOutPort(const uint32_t index) const noexcept
  2098. {
  2099. return pData->audioOut.ports[index].port;
  2100. }
  2101. CarlaEngineCVPort* CarlaPlugin::getCVInPort(const uint32_t index) const noexcept
  2102. {
  2103. return pData->cvIn.ports[index].port;
  2104. }
  2105. CarlaEngineCVPort* CarlaPlugin::getCVOutPort(const uint32_t index) const noexcept
  2106. {
  2107. return pData->cvOut.ports[index].port;
  2108. }
  2109. CarlaEngineEventPort* CarlaPlugin::getDefaultEventInPort() const noexcept
  2110. {
  2111. return pData->event.portIn;
  2112. }
  2113. CarlaEngineEventPort* CarlaPlugin::getDefaultEventOutPort() const noexcept
  2114. {
  2115. return pData->event.portOut;
  2116. }
  2117. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  2118. void CarlaPlugin::checkForMidiLearn(EngineEvent& event) noexcept
  2119. {
  2120. if (pData->midiLearnParameterIndex < 0)
  2121. return;
  2122. if (event.ctrl.param == MIDI_CONTROL_BANK_SELECT || event.ctrl.param == MIDI_CONTROL_BANK_SELECT__LSB)
  2123. return;
  2124. if (event.ctrl.param >= MAX_MIDI_CONTROL)
  2125. return;
  2126. const uint32_t parameterId = static_cast<uint32_t>(pData->midiLearnParameterIndex);
  2127. CARLA_SAFE_ASSERT_UINT2_RETURN(parameterId < pData->param.count, parameterId, pData->param.count,);
  2128. ParameterData& paramData(pData->param.data[parameterId]);
  2129. CARLA_SAFE_ASSERT_INT_RETURN(paramData.mappedControlIndex == CONTROL_INDEX_MIDI_LEARN,
  2130. paramData.mappedControlIndex,);
  2131. event.ctrl.handled = true;
  2132. paramData.mappedControlIndex = static_cast<int16_t>(event.ctrl.param);
  2133. paramData.midiChannel = event.channel;
  2134. pData->postponeMidiLearnRtEvent(true, parameterId, static_cast<uint8_t>(event.ctrl.param), event.channel);
  2135. pData->midiLearnParameterIndex = -1;
  2136. }
  2137. #endif
  2138. void* CarlaPlugin::getNativeHandle() const noexcept
  2139. {
  2140. return nullptr;
  2141. }
  2142. const void* CarlaPlugin::getNativeDescriptor() const noexcept
  2143. {
  2144. return nullptr;
  2145. }
  2146. uintptr_t CarlaPlugin::getUiBridgeProcessId() const noexcept
  2147. {
  2148. return 0;
  2149. }
  2150. // -------------------------------------------------------------------
  2151. uint32_t CarlaPlugin::getPatchbayNodeId() const noexcept
  2152. {
  2153. return pData->nodeId;
  2154. }
  2155. void CarlaPlugin::setPatchbayNodeId(const uint32_t nodeId) noexcept
  2156. {
  2157. pData->nodeId = nodeId;
  2158. }
  2159. // -------------------------------------------------------------------
  2160. void CarlaPlugin::cloneLV2Files(const CarlaPlugin&)
  2161. {
  2162. carla_stderr2("Warning: cloneLV2Files() called for non-implemented type");
  2163. }
  2164. void CarlaPlugin::restoreLV2State(const bool temporary) noexcept
  2165. {
  2166. carla_stderr2("Warning: restoreLV2State(%s) called for non-implemented type", bool2str(temporary));
  2167. }
  2168. void CarlaPlugin::prepareForDeletion() noexcept
  2169. {
  2170. carla_debug("CarlaPlugin::prepareForDeletion");
  2171. const CarlaMutexLocker cml(pData->masterMutex);
  2172. pData->client->deactivate(true);
  2173. }
  2174. void CarlaPlugin::waitForBridgeSaveSignal() noexcept
  2175. {
  2176. }
  2177. // -------------------------------------------------------------------
  2178. // Scoped Disabler
  2179. CarlaPlugin::ScopedDisabler::ScopedDisabler(CarlaPlugin* const plugin) noexcept
  2180. : fPlugin(plugin),
  2181. fWasEnabled(false)
  2182. {
  2183. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
  2184. CARLA_SAFE_ASSERT_RETURN(plugin->pData != nullptr,);
  2185. CARLA_SAFE_ASSERT_RETURN(plugin->pData->client != nullptr,);
  2186. carla_debug("CarlaPlugin::ScopedDisabler(%p)", plugin);
  2187. plugin->pData->masterMutex.lock();
  2188. if (plugin->pData->enabled)
  2189. {
  2190. fWasEnabled = true;
  2191. plugin->pData->enabled = false;
  2192. if (plugin->pData->client->isActive())
  2193. plugin->pData->client->deactivate(false);
  2194. }
  2195. }
  2196. CarlaPlugin::ScopedDisabler::~ScopedDisabler() noexcept
  2197. {
  2198. CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
  2199. CARLA_SAFE_ASSERT_RETURN(fPlugin->pData != nullptr,);
  2200. CARLA_SAFE_ASSERT_RETURN(fPlugin->pData->client != nullptr,);
  2201. carla_debug("CarlaPlugin::~ScopedDisabler()");
  2202. if (fWasEnabled)
  2203. {
  2204. fPlugin->pData->enabled = true;
  2205. fPlugin->pData->client->activate();
  2206. }
  2207. fPlugin->pData->masterMutex.unlock();
  2208. }
  2209. // -------------------------------------------------------------------
  2210. // Scoped Process Locker
  2211. CarlaPlugin::ScopedSingleProcessLocker::ScopedSingleProcessLocker(CarlaPlugin* const plugin, const bool block) noexcept
  2212. : fPlugin(plugin),
  2213. fBlock(block)
  2214. {
  2215. CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
  2216. CARLA_SAFE_ASSERT_RETURN(fPlugin->pData != nullptr,);
  2217. carla_debug("CarlaPlugin::ScopedSingleProcessLocker(%p, %s)", plugin, bool2str(block));
  2218. if (! fBlock)
  2219. return;
  2220. plugin->pData->singleMutex.lock();
  2221. }
  2222. CarlaPlugin::ScopedSingleProcessLocker::~ScopedSingleProcessLocker() noexcept
  2223. {
  2224. CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
  2225. CARLA_SAFE_ASSERT_RETURN(fPlugin->pData != nullptr,);
  2226. carla_debug("CarlaPlugin::~ScopedSingleProcessLocker()");
  2227. if (! fBlock)
  2228. return;
  2229. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  2230. if (fPlugin->pData->singleMutex.wasTryLockCalled())
  2231. fPlugin->pData->needsReset = true;
  2232. #endif
  2233. fPlugin->pData->singleMutex.unlock();
  2234. }
  2235. // -------------------------------------------------------------------
  2236. CARLA_BACKEND_END_NAMESPACE