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.

CarlaEngineNative.cpp 106KB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043
  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2022 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #include "CarlaDefines.h"
  18. #ifdef BUILD_BRIDGE_ALTERNATIVE_ARCH
  19. # error This file should not be compiled if building alternative-arch bridges
  20. #endif
  21. #ifdef CARLA_OS_WASM
  22. # define CARLA_ENGINE_WITHOUT_UI
  23. #endif
  24. #include "CarlaEngineInit.hpp"
  25. #include "CarlaEngineInternal.hpp"
  26. #include "CarlaPlugin.hpp"
  27. #include "CarlaBackendUtils.hpp"
  28. #include "CarlaBase64Utils.hpp"
  29. #include "CarlaBinaryUtils.hpp"
  30. #include "CarlaMathUtils.hpp"
  31. #include "CarlaStateUtils.hpp"
  32. #include "CarlaExternalUI.hpp"
  33. #include "CarlaHost.h"
  34. #include "CarlaNative.hpp"
  35. #include "CarlaNativePlugin.h"
  36. #include "water/files/File.h"
  37. #include "water/streams/MemoryOutputStream.h"
  38. #include "water/xml/XmlDocument.h"
  39. #include "water/xml/XmlElement.h"
  40. #ifdef USING_JUCE
  41. # include "carla_juce/carla_juce.h"
  42. #endif
  43. using water::File;
  44. using water::MemoryOutputStream;
  45. using water::String;
  46. using water::XmlDocument;
  47. using water::XmlElement;
  48. CARLA_BACKEND_START_NAMESPACE
  49. static const uint32_t kNumInParams = 100;
  50. static const uint32_t kNumOutParams = 10;
  51. static const uint16_t kUiWidth = 1024;
  52. static const uint16_t kUiHeight = 712;
  53. // -----------------------------------------------------------------------
  54. #ifndef CARLA_ENGINE_WITHOUT_UI
  55. class CarlaEngineNative;
  56. class CarlaEngineNativeUI : public CarlaExternalUI
  57. {
  58. public:
  59. CarlaEngineNativeUI(CarlaEngineNative* const engine)
  60. : fEngine(engine)
  61. {
  62. carla_debug("CarlaEngineNativeUI::CarlaEngineNativeUI(%p)", engine);
  63. }
  64. ~CarlaEngineNativeUI() noexcept override
  65. {
  66. carla_debug("CarlaEngineNativeUI::~CarlaEngineNativeUI()");
  67. }
  68. protected:
  69. bool msgReceived(const char* const msg) noexcept override;
  70. private:
  71. CarlaEngineNative* const fEngine;
  72. void _updateParamValues(const CarlaPluginPtr& plugin,
  73. uint32_t pluginId,
  74. bool sendCallback, bool sendPluginHost) const noexcept;
  75. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineNativeUI)
  76. };
  77. #endif
  78. // -----------------------------------------------------------------------
  79. class CarlaEngineNative : public CarlaEngine
  80. {
  81. public:
  82. CarlaEngineNative(const NativeHostDescriptor* const host, const bool isPatchbay, const bool withMidiOut,
  83. const uint32_t inChan = 2, uint32_t outChan = 2,
  84. const uint32_t cvIns = 0, const uint32_t cvOuts = 0)
  85. : CarlaEngine(),
  86. pHost(host),
  87. #ifdef USE_REFCOUNTER_JUCE_MESSAGE_MANAGER
  88. // if not running inside Carla, we will have to run event loop ourselves
  89. kNeedsJuceEvents(host->dispatcher(pHost->handle,
  90. NATIVE_HOST_OPCODE_INTERNAL_PLUGIN, 0, 0, nullptr, 0.0f) == 0),
  91. fJuceMsgMgr(),
  92. fJuceMsgMutex(),
  93. #endif
  94. kIsPatchbay(isPatchbay),
  95. kHasMidiOut(withMidiOut),
  96. fIsActive(false),
  97. fIsRunning(false),
  98. fUsesEmbed(false),
  99. #ifndef CARLA_ENGINE_WITHOUT_UI
  100. fUiServer(this),
  101. fLastScaleFactor(1.0f),
  102. #endif
  103. fLastProjectFolder(),
  104. fPluginDeleterMutex(),
  105. fOptionsForced(false)
  106. {
  107. carla_debug("CarlaEngineNative::CarlaEngineNative()");
  108. carla_zeroFloats(fParameters, kNumInParams+kNumOutParams);
  109. #ifdef USE_REFCOUNTER_JUCE_MESSAGE_MANAGER
  110. if (kNeedsJuceEvents)
  111. fJuceMsgMgr.incRef();
  112. #endif
  113. pData->bufferSize = pHost->get_buffer_size(pHost->handle);
  114. pData->sampleRate = pHost->get_sample_rate(pHost->handle);
  115. pData->initTime(nullptr);
  116. #ifndef BUILD_BRIDGE
  117. // Forced OSC setup when running as plugin
  118. pData->options.oscEnabled = true;
  119. pData->options.oscPortTCP = -1;
  120. pData->options.oscPortUDP = 0;
  121. #endif
  122. if (outChan == 0)
  123. outChan = inChan;
  124. // set-up engine
  125. if (kIsPatchbay)
  126. {
  127. pData->options.processMode = ENGINE_PROCESS_MODE_PATCHBAY;
  128. pData->options.transportMode = ENGINE_TRANSPORT_MODE_PLUGIN;
  129. pData->options.forceStereo = false;
  130. pData->options.preferPluginBridges = false;
  131. pData->options.preferUiBridges = false;
  132. init("Carla-Patchbay");
  133. pData->graph.create(inChan, outChan, cvIns, cvOuts);
  134. }
  135. else
  136. {
  137. CARLA_SAFE_ASSERT(inChan == 2);
  138. CARLA_SAFE_ASSERT(outChan == 2);
  139. pData->options.processMode = ENGINE_PROCESS_MODE_CONTINUOUS_RACK;
  140. pData->options.transportMode = ENGINE_TRANSPORT_MODE_PLUGIN;
  141. pData->options.forceStereo = true;
  142. pData->options.preferPluginBridges = false;
  143. pData->options.preferUiBridges = false;
  144. init("Carla-Rack");
  145. pData->graph.create(0, 0, 0, 0); // FIXME?
  146. }
  147. if (pData->options.resourceDir != nullptr)
  148. delete[] pData->options.resourceDir;
  149. if (pData->options.binaryDir != nullptr)
  150. delete[] pData->options.binaryDir;
  151. const water::String binaryDir(File(File::getSpecialLocation(File::currentExecutableFile).getParentDirectory()).getFullPathName());
  152. pData->options.resourceDir = carla_strdup(pHost->resourceDir);
  153. pData->options.binaryDir = carla_strdup(binaryDir.toRawUTF8());
  154. }
  155. ~CarlaEngineNative() override
  156. {
  157. CARLA_SAFE_ASSERT(! fIsActive);
  158. carla_debug("CarlaEngineNative::~CarlaEngineNative() - START");
  159. pData->aboutToClose = true;
  160. fIsRunning = false;
  161. {
  162. #ifdef USE_REFCOUNTER_JUCE_MESSAGE_MANAGER
  163. const ScopedJuceMessageThreadRunner sjmtr(*this, true);
  164. #endif
  165. removeAllPlugins();
  166. //runPendingRtEvents();
  167. close();
  168. pData->graph.destroy();
  169. }
  170. #ifdef USE_REFCOUNTER_JUCE_MESSAGE_MANAGER
  171. if (kNeedsJuceEvents)
  172. fJuceMsgMgr.decRef();
  173. #endif
  174. carla_debug("CarlaEngineNative::~CarlaEngineNative() - END");
  175. }
  176. // -------------------------------------
  177. // CarlaEngine virtual calls
  178. bool init(const char* const clientName) override
  179. {
  180. carla_debug("CarlaEngineNative::init(\"%s\")", clientName);
  181. fIsRunning = true;
  182. if (! pData->init(clientName))
  183. {
  184. close();
  185. setLastError("Failed to init internal data");
  186. return false;
  187. }
  188. pData->bufferSize = pHost->get_buffer_size(pHost->handle);
  189. pData->sampleRate = pHost->get_sample_rate(pHost->handle);
  190. return true;
  191. }
  192. bool close() override
  193. {
  194. fIsRunning = false;
  195. CarlaEngine::close();
  196. return true;
  197. }
  198. bool isRunning() const noexcept override
  199. {
  200. return fIsRunning;
  201. }
  202. bool isOffline() const noexcept override
  203. {
  204. return pHost->is_offline(pHost->handle);
  205. }
  206. bool usesConstantBufferSize() const noexcept override
  207. {
  208. // TODO LV2 hosts can report this, till then we allow this
  209. return true;
  210. }
  211. EngineType getType() const noexcept override
  212. {
  213. return kEngineTypePlugin;
  214. }
  215. const char* getCurrentDriverName() const noexcept override
  216. {
  217. return "Plugin";
  218. }
  219. const char* getCurrentProjectFolder() const noexcept override
  220. {
  221. CARLA_SAFE_ASSERT_RETURN(pHost != nullptr, nullptr);
  222. static char filetype[] = "carla\0";
  223. try {
  224. return (const char*)(uintptr_t)pHost->dispatcher(pHost->handle,
  225. NATIVE_HOST_OPCODE_GET_FILE_PATH,
  226. 0, 0,
  227. (void*)filetype,
  228. 0.0f);
  229. } CARLA_SAFE_EXCEPTION_RETURN("get_file_path", nullptr);
  230. }
  231. void callback(const bool sendHost, const bool sendOsc,
  232. const EngineCallbackOpcode action, const uint pluginId,
  233. const int value1, const int value2, const int value3,
  234. const float valuef, const char* const valueStr) noexcept override
  235. {
  236. CarlaEngine::callback(sendHost, sendOsc, action, pluginId, value1, value2, value3, valuef, valueStr);
  237. #ifndef CARLA_ENGINE_WITHOUT_UI
  238. if (sendHost)
  239. uiServerCallback(action, pluginId, value1, value2, value3, valuef, valueStr);
  240. #endif
  241. switch (action)
  242. {
  243. case ENGINE_CALLBACK_IDLE:
  244. if (! pData->aboutToClose)
  245. pHost->dispatcher(pHost->handle, NATIVE_HOST_OPCODE_HOST_IDLE, 0, 0, nullptr, 0.0f);
  246. break;
  247. case ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED:
  248. if (sendHost && value1 >= 0)
  249. {
  250. uint32_t rindex = static_cast<uint32_t>(value1);
  251. if (_getRealIndexForPluginParameter(pluginId, rindex))
  252. {
  253. fParameters[rindex] = valuef;
  254. #ifndef CARLA_ENGINE_WITHOUT_UI
  255. if (fUsesEmbed || fUiServer.isPipeRunning())
  256. {
  257. pHost->ui_parameter_changed(pHost->handle, rindex, valuef);
  258. }
  259. else
  260. #endif
  261. {
  262. static uint last_pluginId = pluginId;
  263. static int last_value1 = value1;
  264. static bool init = true;
  265. if (init || last_pluginId != pluginId || last_value1 != value1)
  266. {
  267. init = false;
  268. last_pluginId = pluginId;
  269. last_value1 = value1;
  270. carla_stdout("Plugin with id %d triggered parameter %d update while UI is hidden",
  271. pluginId, value1);
  272. }
  273. }
  274. }
  275. }
  276. break;
  277. default:
  278. break;
  279. }
  280. }
  281. const char* runFileCallback(FileCallbackOpcode action,
  282. bool isDir, const char* title, const char* filter) noexcept override
  283. {
  284. switch (action)
  285. {
  286. case FILE_CALLBACK_DEBUG:
  287. return nullptr;
  288. case FILE_CALLBACK_OPEN:
  289. return pHost->ui_open_file(pHost->handle, isDir, title, filter);
  290. case FILE_CALLBACK_SAVE:
  291. return pHost->ui_save_file(pHost->handle, isDir, title, filter);
  292. }
  293. return nullptr;
  294. }
  295. // -------------------------------------------------------------------
  296. void touchPluginParameter(const uint id, const uint32_t parameterId, const bool touch) noexcept override
  297. {
  298. setParameterTouchFromUI(id, parameterId, touch);
  299. }
  300. // -------------------------------------------------------------------
  301. void setParameterValueFromUI(const uint32_t pluginId, const uint32_t index, const float value)
  302. {
  303. uint32_t rindex = index;
  304. if (_getRealIndexForPluginParameter(pluginId, rindex))
  305. {
  306. fParameters[rindex] = value;
  307. pHost->ui_parameter_changed(pHost->handle, rindex, value);
  308. }
  309. }
  310. void setParameterTouchFromUI(const uint32_t pluginId, const uint32_t index, const bool touch)
  311. {
  312. uint32_t rindex = index;
  313. if (_getRealIndexForPluginParameter(pluginId, rindex))
  314. {
  315. pHost->dispatcher(pHost->handle,
  316. NATIVE_HOST_OPCODE_UI_TOUCH_PARAMETER,
  317. static_cast<int32_t>(rindex),
  318. touch ? 1 : 0,
  319. nullptr, 0.0f);
  320. }
  321. }
  322. void reloadFromUI()
  323. {
  324. carla_zeroFloats(fParameters, kNumInParams+kNumOutParams);
  325. pHost->dispatcher(pHost->handle, NATIVE_HOST_OPCODE_RELOAD_PARAMETERS, 0, 0, nullptr, 0.0f);
  326. }
  327. protected:
  328. // -------------------------------------------------------------------
  329. void bufferSizeChanged(const uint32_t newBufferSize)
  330. {
  331. if (pData->bufferSize == newBufferSize)
  332. return;
  333. #ifndef CARLA_ENGINE_WITHOUT_UI
  334. {
  335. const CarlaMutexLocker cml(fUiServer.getPipeLock());
  336. if (fUiServer.writeMessage("buffer-size\n"))
  337. {
  338. char tmpBuf[STR_MAX+1];
  339. carla_zeroChars(tmpBuf, STR_MAX+1);
  340. std::snprintf(tmpBuf, STR_MAX, "%i\n", newBufferSize);
  341. if (fUiServer.writeMessage(tmpBuf))
  342. fUiServer.flushMessages();
  343. }
  344. }
  345. #endif
  346. pData->bufferSize = newBufferSize;
  347. CarlaEngine::bufferSizeChanged(newBufferSize);
  348. }
  349. void sampleRateChanged(const double newSampleRate)
  350. {
  351. if (carla_isEqual(pData->sampleRate, newSampleRate))
  352. return;
  353. #ifndef CARLA_ENGINE_WITHOUT_UI
  354. {
  355. const CarlaMutexLocker cml(fUiServer.getPipeLock());
  356. if (fUiServer.writeMessage("sample-rate\n"))
  357. {
  358. char tmpBuf[STR_MAX+1];
  359. carla_zeroChars(tmpBuf, STR_MAX+1);
  360. {
  361. const CarlaScopedLocale csl;
  362. std::snprintf(tmpBuf, STR_MAX, "%.12g\n", newSampleRate);
  363. }
  364. if (fUiServer.writeMessage(tmpBuf))
  365. fUiServer.flushMessages();
  366. }
  367. }
  368. #endif
  369. pData->sampleRate = newSampleRate;
  370. CarlaEngine::sampleRateChanged(newSampleRate);
  371. }
  372. #ifndef CARLA_ENGINE_WITHOUT_UI
  373. // -------------------------------------------------------------------
  374. void uiServerSendPluginInfo(const CarlaPluginPtr& plugin)
  375. {
  376. char tmpBuf[STR_MAX+1];
  377. carla_zeroChars(tmpBuf, STR_MAX+1);
  378. const CarlaMutexLocker cml(fUiServer.getPipeLock());
  379. const uint pluginId(plugin->getId());
  380. std::snprintf(tmpBuf, STR_MAX, "PLUGIN_INFO_%i\n", pluginId);
  381. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  382. std::snprintf(tmpBuf, STR_MAX, "%i:%i:%i:" P_INT64 ":%i:%i\n",
  383. plugin->getType(), plugin->getCategory(),
  384. plugin->getHints(), plugin->getUniqueId(),
  385. plugin->getOptionsAvailable(), plugin->getOptionsEnabled());
  386. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  387. if (const char* const filename = plugin->getFilename())
  388. {
  389. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeAndFixMessage(filename),);
  390. }
  391. else
  392. {
  393. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeEmptyMessage(),);
  394. }
  395. if (const char* const name = plugin->getName())
  396. {
  397. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeAndFixMessage(name),);
  398. }
  399. else
  400. {
  401. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeEmptyMessage(),);
  402. }
  403. if (const char* const iconName = plugin->getIconName())
  404. {
  405. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeAndFixMessage(iconName),);
  406. }
  407. else
  408. {
  409. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeEmptyMessage(),);
  410. }
  411. if (plugin->getRealName(tmpBuf)) {
  412. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeAndFixMessage(tmpBuf),);
  413. } else {
  414. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeEmptyMessage(),);
  415. }
  416. if (plugin->getLabel(tmpBuf)) {
  417. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeAndFixMessage(tmpBuf),);
  418. } else {
  419. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeEmptyMessage(),);
  420. }
  421. if (plugin->getMaker(tmpBuf)) {
  422. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeAndFixMessage(tmpBuf),);
  423. } else {
  424. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeEmptyMessage(),);
  425. }
  426. if (plugin->getCopyright(tmpBuf)) {
  427. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeAndFixMessage(tmpBuf),);
  428. } else {
  429. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeEmptyMessage(),);
  430. }
  431. std::snprintf(tmpBuf, STR_MAX, "AUDIO_COUNT_%i:%i:%i\n",
  432. pluginId, plugin->getAudioInCount(), plugin->getAudioOutCount());
  433. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  434. std::snprintf(tmpBuf, STR_MAX, "MIDI_COUNT_%i:%i:%i\n",
  435. pluginId, plugin->getMidiInCount(), plugin->getMidiOutCount());
  436. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  437. fUiServer.flushMessages();
  438. }
  439. void uiServerSendPluginParameters(const CarlaPluginPtr& plugin)
  440. {
  441. char tmpBuf[STR_MAX+1];
  442. carla_zeroChars(tmpBuf, STR_MAX+1);
  443. const CarlaMutexLocker cml(fUiServer.getPipeLock());
  444. const CarlaScopedLocale csl;
  445. const uint pluginId(plugin->getId());
  446. for (int32_t i=PARAMETER_ACTIVE; i>PARAMETER_MAX; --i)
  447. {
  448. std::snprintf(tmpBuf, STR_MAX, "PARAMVAL_%u:%i\n", pluginId, i);
  449. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  450. std::snprintf(tmpBuf, STR_MAX, "%.12g\n", static_cast<double>(plugin->getInternalParameterValue(i)));
  451. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  452. fUiServer.flushMessages();
  453. }
  454. uint32_t ins, outs, count;
  455. plugin->getParameterCountInfo(ins, outs);
  456. count = plugin->getParameterCount();
  457. std::snprintf(tmpBuf, STR_MAX, "PARAMETER_COUNT_%i:%i:%i:%i\n", pluginId, ins, outs, count);
  458. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  459. for (uint32_t i=0; i<count; ++i)
  460. {
  461. const ParameterData& paramData(plugin->getParameterData(i));
  462. const ParameterRanges& paramRanges(plugin->getParameterRanges(i));
  463. std::snprintf(tmpBuf, STR_MAX, "PARAMETER_DATA_%i:%i\n", pluginId, i);
  464. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  465. std::snprintf(tmpBuf, STR_MAX, "%i:%i:%i:%i\n", paramData.type, paramData.hints,
  466. paramData.mappedControlIndex, paramData.midiChannel);
  467. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  468. std::snprintf(tmpBuf, STR_MAX, "%.12g:%.12g\n", static_cast<double>(paramData.mappedMinimum),
  469. static_cast<double>(paramData.mappedMaximum));
  470. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  471. if (plugin->getParameterName(i, tmpBuf)) {
  472. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeAndFixMessage(tmpBuf),);
  473. } else {
  474. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeEmptyMessage(),);
  475. }
  476. if (plugin->getParameterUnit(i, tmpBuf)) {
  477. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeAndFixMessage(tmpBuf),);
  478. } else {
  479. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeEmptyMessage(),);
  480. }
  481. if (plugin->getParameterComment(i, tmpBuf)) {
  482. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeAndFixMessage(tmpBuf),);
  483. } else {
  484. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeEmptyMessage(),);
  485. }
  486. if (plugin->getParameterGroupName(i, tmpBuf)) {
  487. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeAndFixMessage(tmpBuf),);
  488. } else {
  489. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeEmptyMessage(),);
  490. }
  491. std::snprintf(tmpBuf, STR_MAX, "PARAMETER_RANGES_%i:%i\n", pluginId, i);
  492. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  493. std::snprintf(tmpBuf, STR_MAX, "%.12g:%.12g:%.12g:%.12g:%.12g:%.12g\n",
  494. static_cast<double>(paramRanges.def),
  495. static_cast<double>(paramRanges.min),
  496. static_cast<double>(paramRanges.max),
  497. static_cast<double>(paramRanges.step),
  498. static_cast<double>(paramRanges.stepSmall),
  499. static_cast<double>(paramRanges.stepLarge));
  500. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  501. std::snprintf(tmpBuf, STR_MAX, "PARAMVAL_%u:%u\n", pluginId, i);
  502. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  503. std::snprintf(tmpBuf, STR_MAX, "%.12g\n", static_cast<double>(plugin->getParameterValue(i)));
  504. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  505. }
  506. fUiServer.flushMessages();
  507. }
  508. void uiServerSendPluginPrograms(const CarlaPluginPtr& plugin)
  509. {
  510. char tmpBuf[STR_MAX+1];
  511. carla_zeroChars(tmpBuf, STR_MAX+1);
  512. const CarlaMutexLocker cml(fUiServer.getPipeLock());
  513. const uint pluginId(plugin->getId());
  514. uint32_t count = plugin->getProgramCount();
  515. std::snprintf(tmpBuf, STR_MAX, "PROGRAM_COUNT_%i:%i:%i\n", pluginId, count, plugin->getCurrentProgram());
  516. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  517. for (uint32_t i=0; i<count; ++i)
  518. {
  519. std::snprintf(tmpBuf, STR_MAX, "PROGRAM_NAME_%i:%i\n", pluginId, i);
  520. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  521. if (plugin->getProgramName(i, tmpBuf)) {
  522. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeAndFixMessage(tmpBuf),);
  523. } else {
  524. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeEmptyMessage(),);
  525. }
  526. }
  527. fUiServer.flushMessages();
  528. count = plugin->getMidiProgramCount();
  529. std::snprintf(tmpBuf, STR_MAX, "MIDI_PROGRAM_COUNT_%i:%i:%i\n",
  530. pluginId, count, plugin->getCurrentMidiProgram());
  531. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  532. for (uint32_t i=0; i<count; ++i)
  533. {
  534. std::snprintf(tmpBuf, STR_MAX, "MIDI_PROGRAM_DATA_%i:%i\n", pluginId, i);
  535. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  536. const MidiProgramData& mpData(plugin->getMidiProgramData(i));
  537. std::snprintf(tmpBuf, STR_MAX, "%i:%i\n", mpData.bank, mpData.program);
  538. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  539. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeAndFixMessage(mpData.name),);
  540. }
  541. fUiServer.flushMessages();
  542. }
  543. void uiServerSendPluginProperties(const CarlaPluginPtr& plugin)
  544. {
  545. char tmpBuf[STR_MAX+1];
  546. carla_zeroChars(tmpBuf, STR_MAX+1);
  547. const CarlaMutexLocker cml(fUiServer.getPipeLock());
  548. const uint pluginId(plugin->getId());
  549. uint32_t count = plugin->getCustomDataCount();
  550. std::snprintf(tmpBuf, STR_MAX, "CUSTOM_DATA_COUNT_%i:%i\n", pluginId, count);
  551. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  552. for (uint32_t i=0; i<count; ++i)
  553. {
  554. const CustomData& customData(plugin->getCustomData(i));
  555. CARLA_SAFE_ASSERT_CONTINUE(customData.isValid());
  556. if (std::strcmp(customData.type, CUSTOM_DATA_TYPE_PROPERTY) != 0)
  557. continue;
  558. std::snprintf(tmpBuf, STR_MAX, "CUSTOM_DATA_%i:%i\n", pluginId, i);
  559. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  560. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeAndFixMessage(customData.type),);
  561. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeAndFixMessage(customData.key),);
  562. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeAndFixMessage(customData.value),);
  563. }
  564. fUiServer.flushMessages();
  565. }
  566. void uiServerCallback(const EngineCallbackOpcode action, const uint pluginId,
  567. const int value1, const int value2, const int value3,
  568. const float valuef, const char* const valueStr)
  569. {
  570. if (! fIsRunning)
  571. return;
  572. if (! fUiServer.isPipeRunning())
  573. return;
  574. switch (action)
  575. {
  576. case ENGINE_CALLBACK_UPDATE:
  577. if (const CarlaPluginPtr plugin = getPlugin(pluginId))
  578. {
  579. if (plugin->isEnabled())
  580. {
  581. CARLA_SAFE_ASSERT_BREAK(plugin->getId() == pluginId);
  582. uiServerSendPluginProperties(plugin);
  583. }
  584. }
  585. break;
  586. case ENGINE_CALLBACK_RELOAD_INFO:
  587. if (const CarlaPluginPtr plugin = getPlugin(pluginId))
  588. {
  589. if (plugin->isEnabled())
  590. {
  591. CARLA_SAFE_ASSERT_BREAK(plugin->getId() == pluginId);
  592. uiServerSendPluginInfo(plugin);
  593. }
  594. }
  595. break;
  596. case ENGINE_CALLBACK_RELOAD_PARAMETERS:
  597. if (const CarlaPluginPtr plugin = getPlugin(pluginId))
  598. {
  599. if (plugin->isEnabled())
  600. {
  601. CARLA_SAFE_ASSERT_BREAK(plugin->getId() == pluginId);
  602. uiServerSendPluginParameters(plugin);
  603. }
  604. }
  605. break;
  606. case ENGINE_CALLBACK_RELOAD_PROGRAMS:
  607. if (const CarlaPluginPtr plugin = getPlugin(pluginId))
  608. {
  609. if (plugin->isEnabled())
  610. {
  611. CARLA_SAFE_ASSERT_BREAK(plugin->getId() == pluginId);
  612. uiServerSendPluginPrograms(plugin);
  613. }
  614. }
  615. break;
  616. case ENGINE_CALLBACK_RELOAD_ALL:
  617. case ENGINE_CALLBACK_PLUGIN_ADDED:
  618. case ENGINE_CALLBACK_PLUGIN_RENAMED:
  619. if (const CarlaPluginPtr plugin = getPlugin(pluginId))
  620. {
  621. if (plugin->isEnabled())
  622. {
  623. CARLA_SAFE_ASSERT_BREAK(plugin->getId() == pluginId);
  624. uiServerSendPluginInfo(plugin);
  625. uiServerSendPluginParameters(plugin);
  626. uiServerSendPluginPrograms(plugin);
  627. uiServerSendPluginProperties(plugin);
  628. }
  629. }
  630. break;
  631. default:
  632. break;
  633. }
  634. char tmpBuf[STR_MAX+1];
  635. carla_zeroChars(tmpBuf, STR_MAX+1);
  636. const CarlaMutexLocker cml(fUiServer.getPipeLock());
  637. std::snprintf(tmpBuf, STR_MAX, "ENGINE_CALLBACK_%i\n", int(action));
  638. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  639. std::snprintf(tmpBuf, STR_MAX, "%u\n", pluginId);
  640. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  641. std::snprintf(tmpBuf, STR_MAX, "%i\n", value1);
  642. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  643. std::snprintf(tmpBuf, STR_MAX, "%i\n", value2);
  644. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  645. std::snprintf(tmpBuf, STR_MAX, "%i\n", value3);
  646. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  647. {
  648. const CarlaScopedLocale csl;
  649. std::snprintf(tmpBuf, STR_MAX, "%.12g\n", static_cast<double>(valuef));
  650. }
  651. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  652. if (valueStr != nullptr) {
  653. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeAndFixMessage(valueStr),);
  654. } else {
  655. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeEmptyMessage(),);
  656. }
  657. fUiServer.flushMessages();
  658. }
  659. void uiServerInfo()
  660. {
  661. CARLA_SAFE_ASSERT_RETURN(fIsRunning,);
  662. CARLA_SAFE_ASSERT_RETURN(fUiServer.isPipeRunning(),);
  663. char tmpBuf[STR_MAX+1];
  664. carla_zeroChars(tmpBuf, STR_MAX+1);
  665. const CarlaMutexLocker cml(fUiServer.getPipeLock());
  666. #if defined(HAVE_LIBLO) && !defined(BUILD_BRIDGE)
  667. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage("osc-urls\n"),);
  668. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeAndFixMessage(pData->osc.getServerPathTCP()),);
  669. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeAndFixMessage(pData->osc.getServerPathUDP()),);
  670. #endif
  671. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage("max-plugin-number\n"),);
  672. std::snprintf(tmpBuf, STR_MAX, "%i\n", pData->maxPluginNumber);
  673. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  674. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage("buffer-size\n"),);
  675. std::snprintf(tmpBuf, STR_MAX, "%i\n", pData->bufferSize);
  676. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  677. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage("sample-rate\n"),);
  678. {
  679. const CarlaScopedLocale csl;
  680. std::snprintf(tmpBuf, STR_MAX, "%.12g\n", pData->sampleRate);
  681. }
  682. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  683. fUiServer.flushMessages();
  684. }
  685. void uiServerOptions()
  686. {
  687. CARLA_SAFE_ASSERT_RETURN(fIsRunning,);
  688. CARLA_SAFE_ASSERT_RETURN(fUiServer.isPipeRunning(),);
  689. char tmpBuf[STR_MAX+1];
  690. carla_zeroChars(tmpBuf, STR_MAX+1);
  691. const EngineOptions& options(pData->options);
  692. const CarlaMutexLocker cml(fUiServer.getPipeLock());
  693. const char* const optionsForcedStr(fOptionsForced ? "true\n" : "false\n");
  694. const std::size_t optionsForcedStrSize(fOptionsForced ? 5 : 6);
  695. std::snprintf(tmpBuf, STR_MAX, "ENGINE_OPTION_%i\n", ENGINE_OPTION_PROCESS_MODE);
  696. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  697. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(optionsForcedStr, optionsForcedStrSize),);
  698. std::snprintf(tmpBuf, STR_MAX, "%i\n", options.processMode);
  699. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  700. fUiServer.flushMessages();
  701. std::snprintf(tmpBuf, STR_MAX, "ENGINE_OPTION_%i\n", ENGINE_OPTION_TRANSPORT_MODE);
  702. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  703. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(optionsForcedStr, optionsForcedStrSize),);
  704. std::snprintf(tmpBuf, STR_MAX, "%i\n", options.transportMode);
  705. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  706. fUiServer.flushMessages();
  707. std::snprintf(tmpBuf, STR_MAX, "ENGINE_OPTION_%i\n", ENGINE_OPTION_FORCE_STEREO);
  708. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  709. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(optionsForcedStr, optionsForcedStrSize),);
  710. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(options.forceStereo ? "true\n" : "false\n"),);
  711. fUiServer.flushMessages();
  712. std::snprintf(tmpBuf, STR_MAX, "ENGINE_OPTION_%i\n", ENGINE_OPTION_PREFER_PLUGIN_BRIDGES);
  713. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  714. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(optionsForcedStr, optionsForcedStrSize),);
  715. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(options.preferPluginBridges ? "true\n" : "false\n"),);
  716. fUiServer.flushMessages();
  717. std::snprintf(tmpBuf, STR_MAX, "ENGINE_OPTION_%i\n", ENGINE_OPTION_PREFER_UI_BRIDGES);
  718. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  719. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(optionsForcedStr, optionsForcedStrSize),);
  720. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(options.preferUiBridges ? "true\n" : "false\n"),);
  721. fUiServer.flushMessages();
  722. std::snprintf(tmpBuf, STR_MAX, "ENGINE_OPTION_%i\n", ENGINE_OPTION_UIS_ALWAYS_ON_TOP);
  723. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  724. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(optionsForcedStr, optionsForcedStrSize),);
  725. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(options.uisAlwaysOnTop ? "true\n" : "false\n"),);
  726. fUiServer.flushMessages();
  727. std::snprintf(tmpBuf, STR_MAX, "ENGINE_OPTION_%i\n", ENGINE_OPTION_MAX_PARAMETERS);
  728. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  729. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(optionsForcedStr, optionsForcedStrSize),);
  730. std::snprintf(tmpBuf, STR_MAX, "%i\n", options.maxParameters);
  731. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  732. fUiServer.flushMessages();
  733. std::snprintf(tmpBuf, STR_MAX, "ENGINE_OPTION_%i\n", ENGINE_OPTION_UI_BRIDGES_TIMEOUT);
  734. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  735. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(optionsForcedStr, optionsForcedStrSize),);
  736. std::snprintf(tmpBuf, STR_MAX, "%i\n", options.uiBridgesTimeout);
  737. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  738. fUiServer.flushMessages();
  739. std::snprintf(tmpBuf, STR_MAX, "ENGINE_OPTION_%i\n", ENGINE_OPTION_PATH_BINARIES);
  740. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  741. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage("true\n", 5),);
  742. std::snprintf(tmpBuf, STR_MAX, "%s\n", options.binaryDir);
  743. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  744. fUiServer.flushMessages();
  745. std::snprintf(tmpBuf, STR_MAX, "ENGINE_OPTION_%i\n", ENGINE_OPTION_PATH_RESOURCES);
  746. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  747. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage("true\n", 5),);
  748. std::snprintf(tmpBuf, STR_MAX, "%s\n", options.resourceDir);
  749. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  750. fUiServer.flushMessages();
  751. }
  752. #endif
  753. // -------------------------------------------------------------------
  754. // Plugin parameter calls
  755. uint32_t getParameterCount() const
  756. {
  757. return kNumInParams + kNumOutParams;
  758. }
  759. const NativeParameter* getParameterInfo(const uint32_t index) const
  760. {
  761. static NativeParameter param;
  762. static char strBufName[STR_MAX+1];
  763. static char strBufUnit[STR_MAX+1];
  764. static char strBufComment[STR_MAX+1];
  765. static char strBufGroupName[STR_MAX+1];
  766. carla_zeroChars(strBufName, STR_MAX+1);
  767. carla_zeroChars(strBufUnit, STR_MAX+1);
  768. carla_zeroChars(strBufComment, STR_MAX+1);
  769. carla_zeroChars(strBufGroupName, STR_MAX+1);
  770. uint32_t rindex = index;
  771. if (const CarlaPluginPtr plugin = _getPluginForParameterIndex(rindex))
  772. {
  773. const ParameterData& paramData(plugin->getParameterData(rindex));
  774. const ParameterRanges& paramRanges(plugin->getParameterRanges(rindex));
  775. if (! plugin->getParameterName(rindex, strBufName))
  776. strBufName[0] = '\0';
  777. if (! plugin->getParameterUnit(rindex, strBufUnit))
  778. strBufUnit[0] = '\0';
  779. if (! plugin->getParameterComment(rindex, strBufComment))
  780. strBufComment[0] = '\0';
  781. if (! plugin->getParameterGroupName(rindex, strBufGroupName))
  782. std::snprintf(strBufGroupName, STR_MAX, "%u:%s", plugin->getId(), plugin->getName());
  783. uint hints = 0x0;
  784. if (paramData.hints & PARAMETER_IS_BOOLEAN)
  785. hints |= NATIVE_PARAMETER_IS_BOOLEAN;
  786. if (paramData.hints & PARAMETER_IS_INTEGER)
  787. hints |= NATIVE_PARAMETER_IS_INTEGER;
  788. if (paramData.hints & PARAMETER_IS_LOGARITHMIC)
  789. hints |= NATIVE_PARAMETER_IS_LOGARITHMIC;
  790. if (paramData.hints & PARAMETER_IS_AUTOMATABLE)
  791. hints |= NATIVE_PARAMETER_IS_AUTOMATABLE;
  792. if (paramData.hints & PARAMETER_USES_SAMPLERATE)
  793. hints |= NATIVE_PARAMETER_USES_SAMPLE_RATE;
  794. if (paramData.hints & PARAMETER_USES_SCALEPOINTS)
  795. hints |= NATIVE_PARAMETER_USES_SCALEPOINTS;
  796. if (paramData.type == PARAMETER_INPUT || paramData.type == PARAMETER_OUTPUT)
  797. {
  798. if (paramData.hints & PARAMETER_IS_ENABLED)
  799. hints |= NATIVE_PARAMETER_IS_ENABLED;
  800. if (paramData.type == PARAMETER_OUTPUT)
  801. hints |= NATIVE_PARAMETER_IS_OUTPUT;
  802. }
  803. param.hints = static_cast<NativeParameterHints>(hints);
  804. param.name = strBufName;
  805. param.unit = strBufUnit;
  806. param.comment = strBufComment;
  807. param.groupName = strBufGroupName;
  808. param.ranges.def = paramRanges.def;
  809. param.ranges.min = paramRanges.min;
  810. param.ranges.max = paramRanges.max;
  811. param.ranges.step = paramRanges.step;
  812. param.ranges.stepSmall = paramRanges.stepSmall;
  813. param.ranges.stepLarge = paramRanges.stepLarge;
  814. param.scalePointCount = 0; // TODO
  815. param.scalePoints = nullptr;
  816. return &param;
  817. }
  818. param.hints = index < kNumInParams ? static_cast<NativeParameterHints>(0x0) : NATIVE_PARAMETER_IS_OUTPUT;
  819. param.name = "Unused";
  820. param.unit = "";
  821. param.ranges.def = 0.0f;
  822. param.ranges.min = 0.0f;
  823. param.ranges.max = 1.0f;
  824. param.ranges.step = 0.01f;
  825. param.ranges.stepSmall = 0.001f;
  826. param.ranges.stepLarge = 0.1f;
  827. param.scalePointCount = 0;
  828. param.scalePoints = nullptr;
  829. return &param;
  830. }
  831. float getParameterValue(const uint32_t index) const
  832. {
  833. uint32_t rindex = index;
  834. if (const CarlaPluginPtr plugin = _getPluginForParameterIndex(rindex))
  835. return plugin->getParameterValue(rindex);
  836. return fParameters[index];
  837. }
  838. // -------------------------------------------------------------------
  839. // Plugin state calls
  840. void setParameterValue(const uint32_t index, const float value)
  841. {
  842. uint32_t rindex = index;
  843. if (const CarlaPluginPtr plugin = _getPluginForParameterIndex(rindex))
  844. plugin->setParameterValueRT(rindex, value, 0, false);
  845. fParameters[index] = value;
  846. }
  847. // -------------------------------------------------------------------
  848. // Plugin process calls
  849. void activate()
  850. {
  851. #if 0
  852. for (uint i=0; i < pData->curPluginCount; ++i)
  853. {
  854. CarlaPluginPtr plugin = pData->plugins[i].plugin;
  855. if (plugin == nullptr || ! plugin->isEnabled())
  856. continue;
  857. plugin->setActive(true, true, false);
  858. }
  859. #endif
  860. fIsActive = true;
  861. }
  862. void deactivate()
  863. {
  864. fIsActive = false;
  865. #if 0
  866. for (uint i=0; i < pData->curPluginCount; ++i)
  867. {
  868. CarlaPluginPtr plugin = pData->plugins[i].plugin;
  869. if (plugin == nullptr || ! plugin->isEnabled())
  870. continue;
  871. plugin->setActive(false, true, false);
  872. }
  873. #endif
  874. // just in case
  875. //runPendingRtEvents();
  876. }
  877. void process(const float* const* const inBuffer, float** const outBuffer, const uint32_t frames,
  878. const NativeMidiEvent* const midiEvents, const uint32_t midiEventCount)
  879. {
  880. if (frames > pData->bufferSize)
  881. {
  882. carla_stderr2("Host is calling process with too high number of frames! %u vs %u",
  883. frames, pData->bufferSize);
  884. deactivate();
  885. bufferSizeChanged(frames);
  886. activate();
  887. }
  888. const PendingRtEventsRunner prt(this, frames, true);
  889. // ---------------------------------------------------------------
  890. // Time Info
  891. const NativeTimeInfo* const timeInfo(pHost->get_time_info(pHost->handle));
  892. pData->timeInfo.playing = timeInfo->playing;
  893. pData->timeInfo.frame = timeInfo->frame;
  894. pData->timeInfo.usecs = timeInfo->usecs;
  895. pData->timeInfo.bbt.valid = timeInfo->bbt.valid;
  896. if (timeInfo->bbt.valid)
  897. {
  898. pData->timeInfo.bbt.bar = timeInfo->bbt.bar;
  899. pData->timeInfo.bbt.beat = timeInfo->bbt.beat;
  900. pData->timeInfo.bbt.tick = timeInfo->bbt.tick;
  901. pData->timeInfo.bbt.barStartTick = timeInfo->bbt.barStartTick;
  902. pData->timeInfo.bbt.beatsPerBar = timeInfo->bbt.beatsPerBar;
  903. pData->timeInfo.bbt.beatType = timeInfo->bbt.beatType;
  904. pData->timeInfo.bbt.ticksPerBeat = timeInfo->bbt.ticksPerBeat;
  905. pData->timeInfo.bbt.beatsPerMinute = timeInfo->bbt.beatsPerMinute;
  906. }
  907. // ---------------------------------------------------------------
  908. // Do nothing if no plugins and rack mode
  909. if (pData->curPluginCount == 0 && ! kIsPatchbay)
  910. {
  911. if (outBuffer[0] != inBuffer[0])
  912. carla_copyFloats(outBuffer[0], inBuffer[0], frames);
  913. if (outBuffer[1] != inBuffer[1])
  914. carla_copyFloats(outBuffer[1], inBuffer[1], frames);
  915. for (uint32_t i=0; i < midiEventCount; ++i)
  916. {
  917. if (! pHost->write_midi_event(pHost->handle, &midiEvents[i]))
  918. break;
  919. }
  920. return;
  921. }
  922. // ---------------------------------------------------------------
  923. // initialize events
  924. carla_zeroStructs(pData->events.in, kMaxEngineEventInternalCount);
  925. carla_zeroStructs(pData->events.out, kMaxEngineEventInternalCount);
  926. // ---------------------------------------------------------------
  927. // events input (before processing)
  928. {
  929. uint32_t engineEventIndex = 0;
  930. for (uint32_t i=0; i < midiEventCount && engineEventIndex < kMaxEngineEventInternalCount; ++i)
  931. {
  932. const NativeMidiEvent& midiEvent(midiEvents[i]);
  933. EngineEvent& engineEvent(pData->events.in[engineEventIndex++]);
  934. engineEvent.time = midiEvent.time;
  935. engineEvent.fillFromMidiData(midiEvent.size, midiEvent.data, 0);
  936. if (engineEventIndex >= kMaxEngineEventInternalCount)
  937. break;
  938. }
  939. }
  940. if (kIsPatchbay)
  941. {
  942. // -----------------------------------------------------------
  943. // process
  944. pData->graph.process(pData, inBuffer, outBuffer, frames);
  945. }
  946. else
  947. {
  948. // -----------------------------------------------------------
  949. // create audio buffers
  950. const float* inBuf[2] = { inBuffer[0], inBuffer[1] };
  951. /* */ float* outBuf[2] = { outBuffer[0], outBuffer[1] };
  952. // -----------------------------------------------------------
  953. // process
  954. pData->graph.processRack(pData, inBuf, outBuf, frames);
  955. }
  956. // ---------------------------------------------------------------
  957. // events output (after processing)
  958. carla_zeroStructs(pData->events.in, kMaxEngineEventInternalCount);
  959. if (kHasMidiOut)
  960. {
  961. NativeMidiEvent midiEvent;
  962. for (uint32_t i=0; i < kMaxEngineEventInternalCount; ++i)
  963. {
  964. const EngineEvent& engineEvent(pData->events.out[i]);
  965. if (engineEvent.type == kEngineEventTypeNull)
  966. break;
  967. carla_zeroStruct(midiEvent);
  968. midiEvent.time = engineEvent.time;
  969. /**/ if (engineEvent.type == kEngineEventTypeControl)
  970. {
  971. midiEvent.port = 0;
  972. midiEvent.size = engineEvent.ctrl.convertToMidiData(engineEvent.channel, midiEvent.data);
  973. }
  974. else if (engineEvent.type == kEngineEventTypeMidi)
  975. {
  976. if (engineEvent.midi.size > 4)
  977. continue;
  978. midiEvent.port = engineEvent.midi.port;
  979. midiEvent.size = engineEvent.midi.size;
  980. midiEvent.data[0] = static_cast<uint8_t>(engineEvent.midi.data[0] | (engineEvent.channel & MIDI_CHANNEL_BIT));
  981. for (uint8_t j=1; j < midiEvent.size; ++j)
  982. midiEvent.data[j] = engineEvent.midi.data[j];
  983. }
  984. else
  985. {
  986. continue;
  987. }
  988. if (midiEvent.size > 0)
  989. pHost->write_midi_event(pHost->handle, &midiEvent);
  990. }
  991. }
  992. }
  993. // -------------------------------------------------------------------
  994. // Plugin UI calls
  995. #ifndef CARLA_ENGINE_WITHOUT_UI
  996. void uiShow(const bool show)
  997. {
  998. if (show)
  999. {
  1000. if (fUiServer.isPipeRunning())
  1001. {
  1002. fUiServer.writeFocusMessage();
  1003. return;
  1004. }
  1005. CarlaString path(pHost->resourceDir);
  1006. if (kIsPatchbay)
  1007. path += CARLA_OS_SEP_STR "carla-plugin-patchbay";
  1008. else
  1009. path += CARLA_OS_SEP_STR "carla-plugin";
  1010. #ifdef CARLA_OS_WIN
  1011. path += ".exe";
  1012. #endif
  1013. carla_stdout("Trying to start carla-plugin using \"%s\"", path.buffer());
  1014. fUiServer.setData(path, pData->sampleRate, pHost->uiName);
  1015. if (! fUiServer.startPipeServer(false))
  1016. {
  1017. pHost->dispatcher(pHost->handle, NATIVE_HOST_OPCODE_UI_UNAVAILABLE, 0, 0, nullptr, 0.0f);
  1018. return;
  1019. }
  1020. uiServerInfo();
  1021. uiServerOptions();
  1022. uiServerCallback(ENGINE_CALLBACK_ENGINE_STARTED,
  1023. pData->curPluginCount,
  1024. pData->options.processMode,
  1025. pData->options.transportMode,
  1026. static_cast<int>(pData->bufferSize),
  1027. static_cast<float>(pData->sampleRate),
  1028. "Plugin");
  1029. fUiServer.writeShowMessage();
  1030. for (uint i=0; i < pData->curPluginCount; ++i)
  1031. {
  1032. if (const CarlaPluginPtr plugin = pData->plugins[i].plugin)
  1033. if (plugin->isEnabled())
  1034. uiServerCallback(ENGINE_CALLBACK_PLUGIN_ADDED, i, plugin->getType(),
  1035. 0, 0, 0.0f,
  1036. plugin->getName());
  1037. }
  1038. if (kIsPatchbay)
  1039. patchbayRefresh(true, false, false);
  1040. }
  1041. else
  1042. {
  1043. fUiServer.stopPipeServer(2000);
  1044. // hide all custom uis
  1045. for (uint i=0; i < pData->curPluginCount; ++i)
  1046. {
  1047. if (const CarlaPluginPtr plugin = pData->plugins[i].plugin)
  1048. {
  1049. if (plugin->isEnabled())
  1050. {
  1051. if (plugin->getHints() & PLUGIN_HAS_CUSTOM_UI)
  1052. {
  1053. try {
  1054. plugin->showCustomUI(false);
  1055. } CARLA_SAFE_EXCEPTION_CONTINUE("Plugin showCustomUI (hide)");
  1056. }
  1057. }
  1058. }
  1059. }
  1060. }
  1061. }
  1062. void uiIdle()
  1063. {
  1064. #ifdef USE_REFCOUNTER_JUCE_MESSAGE_MANAGER
  1065. const ScopedJuceMessageThreadRunner sjmtr(*this, false);
  1066. if (kNeedsJuceEvents && ! sjmtr.wasLocked)
  1067. return;
  1068. #endif
  1069. for (uint i=0; i < pData->curPluginCount; ++i)
  1070. {
  1071. if (const CarlaPluginPtr plugin = pData->plugins[i].plugin)
  1072. {
  1073. if (plugin->isEnabled())
  1074. {
  1075. const uint hints = plugin->getHints();
  1076. if ((hints & PLUGIN_HAS_CUSTOM_UI) != 0 && (hints & PLUGIN_NEEDS_UI_MAIN_THREAD) != 0)
  1077. {
  1078. try {
  1079. plugin->uiIdle();
  1080. } CARLA_SAFE_EXCEPTION_CONTINUE("Plugin uiIdle");
  1081. }
  1082. }
  1083. }
  1084. }
  1085. idlePipe();
  1086. switch (fUiServer.getAndResetUiState())
  1087. {
  1088. case CarlaExternalUI::UiNone:
  1089. case CarlaExternalUI::UiShow:
  1090. break;
  1091. case CarlaExternalUI::UiCrashed:
  1092. pHost->dispatcher(pHost->handle, NATIVE_HOST_OPCODE_UI_UNAVAILABLE, 0, 0, nullptr, 0.0f);
  1093. break;
  1094. case CarlaExternalUI::UiHide:
  1095. pHost->ui_closed(pHost->handle);
  1096. fUiServer.stopPipeServer(1000);
  1097. break;
  1098. }
  1099. if (carla_isNotEqual(fLastScaleFactor, pData->options.uiScale))
  1100. {
  1101. fLastScaleFactor = pData->options.uiScale;
  1102. pHost->dispatcher(pHost->handle,
  1103. NATIVE_HOST_OPCODE_UI_RESIZE,
  1104. static_cast<int>(kUiWidth * fLastScaleFactor + 0.5f),
  1105. static_cast<int>(kUiHeight * fLastScaleFactor + 0.5f),
  1106. nullptr, 0.0f);
  1107. }
  1108. {
  1109. const CarlaMutexLocker cml(fPluginDeleterMutex);
  1110. pData->deletePluginsAsNeeded();
  1111. }
  1112. }
  1113. void uiSetParameterValue(const uint32_t index, const float value)
  1114. {
  1115. uint32_t rindex = index;
  1116. if (const CarlaPluginPtr plugin = _getPluginForParameterIndex(rindex))
  1117. {
  1118. if (plugin->getHints() & PLUGIN_HAS_CUSTOM_UI)
  1119. plugin->uiParameterChange(rindex, value);
  1120. if (index >= kNumInParams || ! fUiServer.isPipeRunning())
  1121. return;
  1122. uiServerCallback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
  1123. plugin->getId(),
  1124. static_cast<int>(rindex),
  1125. 0, 0,
  1126. value,
  1127. nullptr);
  1128. }
  1129. }
  1130. void idlePipe()
  1131. {
  1132. if (! fUiServer.isPipeRunning())
  1133. return;
  1134. fUiServer.idlePipe();
  1135. if (! fUiServer.isPipeRunning())
  1136. return;
  1137. char tmpBuf[STR_MAX+1];
  1138. carla_zeroChars(tmpBuf, STR_MAX+1);
  1139. const CarlaMutexLocker cml(fUiServer.getPipeLock());
  1140. const CarlaScopedLocale csl;
  1141. const EngineTimeInfo& timeInfo(pData->timeInfo);
  1142. // ------------------------------------------------------------------------------------------------------------
  1143. // send engine info
  1144. std::snprintf(tmpBuf, STR_MAX, "%.12g:0\n", static_cast<double>(getDSPLoad()));
  1145. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage("runtime-info\n"),);
  1146. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  1147. fUiServer.flushMessages();
  1148. if (const char* const projFolder = getCurrentProjectFolder())
  1149. {
  1150. if (fLastProjectFolder != projFolder)
  1151. {
  1152. carla_stdout("Project folder changed to %s", projFolder);
  1153. fLastProjectFolder = projFolder;
  1154. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage("project-folder\n"),);
  1155. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeAndFixMessage(projFolder),);
  1156. fUiServer.flushMessages();
  1157. }
  1158. }
  1159. // ------------------------------------------------------------------------------------------------------------
  1160. // send transport
  1161. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage("transport\n"),);
  1162. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(timeInfo.playing ? "true\n" : "false\n"),);
  1163. if (timeInfo.bbt.valid)
  1164. {
  1165. std::snprintf(tmpBuf, STR_MAX, P_UINT64 ":%i:%i:%i\n", timeInfo.frame,
  1166. timeInfo.bbt.bar,
  1167. timeInfo.bbt.beat,
  1168. static_cast<int>(timeInfo.bbt.tick + 0.5));
  1169. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  1170. std::snprintf(tmpBuf, STR_MAX, "%.12g\n", timeInfo.bbt.beatsPerMinute);
  1171. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  1172. }
  1173. else
  1174. {
  1175. std::snprintf(tmpBuf, STR_MAX, P_UINT64 ":0:0:0\n", timeInfo.frame);
  1176. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  1177. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage("0.0\n"),);
  1178. }
  1179. fUiServer.flushMessages();
  1180. // ------------------------------------------------------------------------------------------------------------
  1181. // send peaks and param outputs for all plugins
  1182. for (uint i=0; i < pData->curPluginCount; ++i)
  1183. {
  1184. const EnginePluginData& plugData(pData->plugins[i]);
  1185. const CarlaPluginPtr plugin = pData->plugins[i].plugin;
  1186. std::snprintf(tmpBuf, STR_MAX, "PEAKS_%i\n", i);
  1187. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  1188. std::snprintf(tmpBuf, STR_MAX, "%.12g:%.12g:%.12g:%.12g\n",
  1189. static_cast<double>(plugData.peaks[0]),
  1190. static_cast<double>(plugData.peaks[1]),
  1191. static_cast<double>(plugData.peaks[2]),
  1192. static_cast<double>(plugData.peaks[3]));
  1193. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  1194. fUiServer.flushMessages();
  1195. for (uint32_t j=0, count=plugin->getParameterCount(); j < count; ++j)
  1196. {
  1197. if (! plugin->isParameterOutput(j))
  1198. continue;
  1199. std::snprintf(tmpBuf, STR_MAX, "PARAMVAL_%u:%u\n", i, j);
  1200. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  1201. std::snprintf(tmpBuf, STR_MAX, "%.12g\n", static_cast<double>(plugin->getParameterValue(j)));
  1202. CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),);
  1203. fUiServer.flushMessages();
  1204. }
  1205. }
  1206. }
  1207. #endif
  1208. // -------------------------------------------------------------------
  1209. // Plugin state calls
  1210. char* getState() const
  1211. {
  1212. MemoryOutputStream out;
  1213. saveProjectInternal(out);
  1214. return strdup(out.toString().toRawUTF8());
  1215. }
  1216. void setState(const char* const data)
  1217. {
  1218. #ifdef USE_REFCOUNTER_JUCE_MESSAGE_MANAGER
  1219. const ScopedJuceMessageThreadRunner sjmtr(*this, true);
  1220. #endif
  1221. // remove all plugins from UI side
  1222. for (uint i=0, count=pData->curPluginCount; i < count; ++i)
  1223. CarlaEngine::callback(true, true, ENGINE_CALLBACK_PLUGIN_REMOVED, count-i-1, 0, 0, 0, 0.0f, nullptr);
  1224. // remove all plugins from backend, no lock
  1225. fIsRunning = false;
  1226. removeAllPlugins();
  1227. fIsRunning = true;
  1228. {
  1229. const CarlaMutexLocker cml(fPluginDeleterMutex);
  1230. pData->deletePluginsAsNeeded();
  1231. }
  1232. // stopped during removeAllPlugins()
  1233. if (! pData->runner.isRunnerActive())
  1234. pData->runner.start();
  1235. fOptionsForced = true;
  1236. const String state(data);
  1237. XmlDocument xml(state);
  1238. loadProjectInternal(xml, true);
  1239. reloadFromUI();
  1240. }
  1241. // -------------------------------------------------------------------
  1242. public:
  1243. #define handlePtr ((CarlaEngineNative*)handle)
  1244. static NativePluginHandle _instantiateRack(const NativeHostDescriptor* host)
  1245. {
  1246. return new CarlaEngineNative(host, false, true);
  1247. }
  1248. static NativePluginHandle _instantiateRackNoMidiOut(const NativeHostDescriptor* host)
  1249. {
  1250. return new CarlaEngineNative(host, false, false);
  1251. }
  1252. static NativePluginHandle _instantiatePatchbay(const NativeHostDescriptor* host)
  1253. {
  1254. return new CarlaEngineNative(host, true, true);
  1255. }
  1256. static NativePluginHandle _instantiatePatchbay3s(const NativeHostDescriptor* host)
  1257. {
  1258. return new CarlaEngineNative(host, true, true, 3, 2);
  1259. }
  1260. static NativePluginHandle _instantiatePatchbay16(const NativeHostDescriptor* host)
  1261. {
  1262. return new CarlaEngineNative(host, true, true, 16, 16);
  1263. }
  1264. static NativePluginHandle _instantiatePatchbay32(const NativeHostDescriptor* host)
  1265. {
  1266. return new CarlaEngineNative(host, true, true, 32, 32);
  1267. }
  1268. static NativePluginHandle _instantiatePatchbay64(const NativeHostDescriptor* host)
  1269. {
  1270. return new CarlaEngineNative(host, true, true, 64, 64);
  1271. }
  1272. static NativePluginHandle _instantiatePatchbayCV(const NativeHostDescriptor* host)
  1273. {
  1274. return new CarlaEngineNative(host, true, true, 2, 2, 5, 5);
  1275. }
  1276. static NativePluginHandle _instantiatePatchbayCV8(const NativeHostDescriptor* host)
  1277. {
  1278. return new CarlaEngineNative(host, true, true, 2, 2, 8, 8);
  1279. }
  1280. static NativePluginHandle _instantiatePatchbayCV32(const NativeHostDescriptor* host)
  1281. {
  1282. return new CarlaEngineNative(host, true, true, 64, 64, 32, 32);
  1283. }
  1284. static void _cleanup(NativePluginHandle handle)
  1285. {
  1286. delete handlePtr;
  1287. }
  1288. static uint32_t _get_parameter_count(NativePluginHandle handle)
  1289. {
  1290. return handlePtr->getParameterCount();
  1291. }
  1292. static const NativeParameter* _get_parameter_info(NativePluginHandle handle, uint32_t index)
  1293. {
  1294. return handlePtr->getParameterInfo(index);
  1295. }
  1296. static float _get_parameter_value(NativePluginHandle handle, uint32_t index)
  1297. {
  1298. return handlePtr->getParameterValue(index);
  1299. }
  1300. static void _set_parameter_value(NativePluginHandle handle, uint32_t index, float value)
  1301. {
  1302. handlePtr->setParameterValue(index, value);
  1303. }
  1304. #ifndef CARLA_ENGINE_WITHOUT_UI
  1305. static void _ui_show(NativePluginHandle handle, bool show)
  1306. {
  1307. handlePtr->uiShow(show);
  1308. }
  1309. static void _ui_idle(NativePluginHandle handle)
  1310. {
  1311. handlePtr->uiIdle();
  1312. }
  1313. static void _ui_set_parameter_value(NativePluginHandle handle, uint32_t index, float value)
  1314. {
  1315. handlePtr->uiSetParameterValue(index, value);
  1316. }
  1317. #endif
  1318. static void _activate(NativePluginHandle handle)
  1319. {
  1320. handlePtr->activate();
  1321. }
  1322. static void _deactivate(NativePluginHandle handle)
  1323. {
  1324. handlePtr->deactivate();
  1325. }
  1326. // FIXME for v3.0, use const for the input buffer
  1327. static void _process(NativePluginHandle handle,
  1328. float** inBuffer, float** outBuffer, const uint32_t frames,
  1329. const NativeMidiEvent* midiEvents, uint32_t midiEventCount)
  1330. {
  1331. handlePtr->process(inBuffer, outBuffer, frames, midiEvents, midiEventCount);
  1332. }
  1333. static char* _get_state(NativePluginHandle handle)
  1334. {
  1335. return handlePtr->getState();
  1336. }
  1337. static void _set_state(NativePluginHandle handle, const char* data)
  1338. {
  1339. handlePtr->setState(data);
  1340. }
  1341. static intptr_t _dispatcher(NativePluginHandle handle,
  1342. NativePluginDispatcherOpcode opcode,
  1343. int32_t index, intptr_t value, void* ptr, float opt)
  1344. {
  1345. switch(opcode)
  1346. {
  1347. case NATIVE_PLUGIN_OPCODE_NULL:
  1348. return 0;
  1349. case NATIVE_PLUGIN_OPCODE_BUFFER_SIZE_CHANGED:
  1350. CARLA_SAFE_ASSERT_RETURN(value > 0, 0);
  1351. handlePtr->bufferSizeChanged(static_cast<uint32_t>(value));
  1352. return 0;
  1353. case NATIVE_PLUGIN_OPCODE_SAMPLE_RATE_CHANGED:
  1354. CARLA_SAFE_ASSERT_RETURN(opt > 0.0f, 0);
  1355. handlePtr->sampleRateChanged(static_cast<double>(opt));
  1356. return 0;
  1357. case NATIVE_PLUGIN_OPCODE_OFFLINE_CHANGED:
  1358. handlePtr->offlineModeChanged(value != 0);
  1359. return 0;
  1360. case NATIVE_PLUGIN_OPCODE_UI_NAME_CHANGED:
  1361. //handlePtr->uiNameChanged(static_cast<const char*>(ptr));
  1362. return 0;
  1363. case NATIVE_PLUGIN_OPCODE_GET_INTERNAL_HANDLE: {
  1364. CarlaEngineNative* const engine = handlePtr;
  1365. return (intptr_t)(CarlaEngine*)engine;
  1366. }
  1367. case NATIVE_PLUGIN_OPCODE_IDLE:
  1368. //handlePtr->idle();
  1369. return 0;
  1370. case NATIVE_PLUGIN_OPCODE_UI_MIDI_EVENT:
  1371. return 0;
  1372. case NATIVE_PLUGIN_OPCODE_HOST_USES_EMBED:
  1373. handlePtr->fUsesEmbed = true;
  1374. return 0;
  1375. }
  1376. return 0;
  1377. // unused
  1378. (void)index;
  1379. (void)ptr;
  1380. }
  1381. // -------------------------------------------------------------------
  1382. #undef handlePtr
  1383. private:
  1384. const NativeHostDescriptor* const pHost;
  1385. #ifdef USE_REFCOUNTER_JUCE_MESSAGE_MANAGER
  1386. const bool kNeedsJuceEvents;
  1387. const CarlaJUCE::ReferenceCountedJuceMessageMessager fJuceMsgMgr;
  1388. CarlaMutex fJuceMsgMutex;
  1389. struct ScopedJuceMessageThreadRunner {
  1390. const CarlaMutexTryLocker cmtl;
  1391. const bool wasLocked;
  1392. ScopedJuceMessageThreadRunner(CarlaEngineNative& self, const bool forceLock) noexcept
  1393. : cmtl(self.fJuceMsgMutex, forceLock),
  1394. wasLocked(cmtl.wasLocked())
  1395. {
  1396. if (! self.kNeedsJuceEvents)
  1397. return;
  1398. if (! wasLocked)
  1399. return;
  1400. CarlaJUCE::setMessageManagerForThisThread();
  1401. }
  1402. ~ScopedJuceMessageThreadRunner()
  1403. {
  1404. CarlaJUCE::dispatchMessageManagerMessages();
  1405. }
  1406. CARLA_DECLARE_NON_COPYABLE(ScopedJuceMessageThreadRunner)
  1407. };
  1408. #endif
  1409. const bool kIsPatchbay; // rack if false
  1410. const bool kHasMidiOut;
  1411. bool fIsActive, fIsRunning, fUsesEmbed;
  1412. #ifndef CARLA_ENGINE_WITHOUT_UI
  1413. CarlaEngineNativeUI fUiServer;
  1414. float fLastScaleFactor;
  1415. #endif
  1416. float fParameters[kNumInParams+kNumOutParams];
  1417. CarlaString fLastProjectFolder;
  1418. CarlaMutex fPluginDeleterMutex;
  1419. bool fOptionsForced;
  1420. CarlaPluginPtr _getPluginForParameterIndex(uint32_t& index) const noexcept
  1421. {
  1422. if (pData->curPluginCount == 0 || pData->plugins == nullptr)
  1423. return nullptr;
  1424. for (uint32_t i=0; i<pData->curPluginCount; ++i)
  1425. {
  1426. const CarlaPluginPtr plugin = pData->plugins[i].plugin;
  1427. if (plugin.get() == nullptr || ! plugin->isEnabled())
  1428. break;
  1429. if (const uint32_t paramCount = plugin->getParameterCount())
  1430. {
  1431. if (index >= paramCount)
  1432. {
  1433. index -= paramCount;
  1434. continue;
  1435. }
  1436. return plugin;
  1437. }
  1438. }
  1439. return nullptr;
  1440. }
  1441. bool _getRealIndexForPluginParameter(const uint32_t pluginId, uint32_t& rindex) const noexcept
  1442. {
  1443. if (pData->curPluginCount == 0 || pluginId >= pData->curPluginCount || pData->plugins == nullptr)
  1444. return false;
  1445. for (uint32_t i=0; i<pluginId; ++i)
  1446. {
  1447. const CarlaPluginPtr plugin = pData->plugins[i].plugin;
  1448. if (plugin.get() == nullptr || ! plugin->isEnabled())
  1449. return false;
  1450. rindex += plugin->getParameterCount();
  1451. }
  1452. if (rindex >= kNumInParams)
  1453. return false;
  1454. return true;
  1455. }
  1456. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineNative)
  1457. };
  1458. // -----------------------------------------------------------------------
  1459. #ifndef CARLA_ENGINE_WITHOUT_UI
  1460. bool CarlaEngineNativeUI::msgReceived(const char* const msg) noexcept
  1461. {
  1462. if (CarlaExternalUI::msgReceived(msg))
  1463. return true;
  1464. bool ok = true;
  1465. if (std::strcmp(msg, "set_engine_option") == 0)
  1466. {
  1467. uint32_t option;
  1468. int32_t value;
  1469. const char* valueStr = nullptr;
  1470. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(option), true);
  1471. CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(value), true);
  1472. readNextLineAsString(valueStr, false); // can be null
  1473. try {
  1474. fEngine->setOption(static_cast<EngineOption>(option), value, valueStr);
  1475. } CARLA_SAFE_EXCEPTION("setOption");
  1476. }
  1477. else if (std::strcmp(msg, "clear_engine_xruns") == 0)
  1478. {
  1479. fEngine->clearXruns();
  1480. }
  1481. else if (std::strcmp(msg, "cancel_engine_action") == 0)
  1482. {
  1483. fEngine->setActionCanceled(true);
  1484. }
  1485. else if (std::strcmp(msg, "load_file") == 0)
  1486. {
  1487. const char* filename;
  1488. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename, false), true);
  1489. try {
  1490. ok = fEngine->loadFile(filename);
  1491. } CARLA_SAFE_EXCEPTION("loadFile");
  1492. fEngine->reloadFromUI();
  1493. }
  1494. else if (std::strcmp(msg, "load_project") == 0)
  1495. {
  1496. const char* filename;
  1497. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename, false), true);
  1498. try {
  1499. ok = fEngine->loadProject(filename, true);
  1500. } CARLA_SAFE_EXCEPTION("loadProject");
  1501. fEngine->reloadFromUI();
  1502. }
  1503. else if (std::strcmp(msg, "save_project") == 0)
  1504. {
  1505. const char* filename;
  1506. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename, false), true);
  1507. try {
  1508. ok = fEngine->saveProject(filename, true);
  1509. } CARLA_SAFE_EXCEPTION("saveProject");
  1510. }
  1511. else if (std::strcmp(msg, "clear_project_filename") == 0)
  1512. {
  1513. fEngine->clearCurrentProjectFilename();
  1514. }
  1515. else if (std::strcmp(msg, "patchbay_connect") == 0)
  1516. {
  1517. bool external;
  1518. uint32_t groupA, portA, groupB, portB;
  1519. CARLA_SAFE_ASSERT_RETURN(readNextLineAsBool(external), true);
  1520. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(groupA), true);
  1521. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(portA), true);
  1522. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(groupB), true);
  1523. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(portB), true);
  1524. try {
  1525. ok = fEngine->patchbayConnect(external, groupA, portA, groupB, portB);
  1526. } CARLA_SAFE_EXCEPTION("patchbayConnect");
  1527. }
  1528. else if (std::strcmp(msg, "patchbay_disconnect") == 0)
  1529. {
  1530. bool external;
  1531. uint32_t connectionId;
  1532. CARLA_SAFE_ASSERT_RETURN(readNextLineAsBool(external), true);
  1533. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(connectionId), true);
  1534. try {
  1535. ok = fEngine->patchbayDisconnect(external, connectionId);
  1536. } CARLA_SAFE_EXCEPTION("patchbayDisconnect");
  1537. }
  1538. else if (std::strcmp(msg, "patchbay_set_group_pos") == 0)
  1539. {
  1540. bool external;
  1541. uint32_t groupId;
  1542. int x1, y1, x2, y2;
  1543. CARLA_SAFE_ASSERT_RETURN(readNextLineAsBool(external), true);
  1544. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(groupId), true);
  1545. CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(x1), true);
  1546. CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(y1), true);
  1547. CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(x2), true);
  1548. CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(y2), true);
  1549. try {
  1550. ok = fEngine->patchbaySetGroupPos(false, true, external, groupId, x1, y1, x2, y2);
  1551. } CARLA_SAFE_EXCEPTION("patchbaySetGroupPos");
  1552. }
  1553. else if (std::strcmp(msg, "patchbay_refresh") == 0)
  1554. {
  1555. bool external;
  1556. CARLA_SAFE_ASSERT_RETURN(readNextLineAsBool(external), true);
  1557. try {
  1558. ok = fEngine->patchbayRefresh(true, false, external);
  1559. } CARLA_SAFE_EXCEPTION("patchbayRefresh");
  1560. }
  1561. else if (std::strcmp(msg, "transport_play") == 0)
  1562. {
  1563. fEngine->transportPlay();
  1564. }
  1565. else if (std::strcmp(msg, "transport_pause") == 0)
  1566. {
  1567. fEngine->transportPause();
  1568. }
  1569. else if (std::strcmp(msg, "transport_bpm") == 0)
  1570. {
  1571. double bpm;
  1572. CARLA_SAFE_ASSERT_RETURN(readNextLineAsDouble(bpm), true);
  1573. fEngine->transportBPM(bpm);
  1574. }
  1575. else if (std::strcmp(msg, "transport_relocate") == 0)
  1576. {
  1577. uint64_t frame;
  1578. CARLA_SAFE_ASSERT_RETURN(readNextLineAsULong(frame), true);
  1579. fEngine->transportRelocate(frame);
  1580. }
  1581. else if (std::strcmp(msg, "add_plugin") == 0)
  1582. {
  1583. uint32_t btype, ptype;
  1584. const char* filename = nullptr;
  1585. const char* name;
  1586. const char* label;
  1587. int64_t uniqueId;
  1588. uint options;
  1589. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(btype), true);
  1590. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(ptype), true);
  1591. readNextLineAsString(filename, true); // can be null
  1592. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(name, true), true);
  1593. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(label, true), true);
  1594. CARLA_SAFE_ASSERT_RETURN(readNextLineAsLong(uniqueId), true);
  1595. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(options), true);
  1596. if (filename != nullptr && std::strcmp(filename, "(null)") == 0)
  1597. {
  1598. delete[] filename;
  1599. filename = nullptr;
  1600. }
  1601. if (std::strcmp(name, "(null)") == 0)
  1602. {
  1603. delete[] name;
  1604. name = nullptr;
  1605. }
  1606. ok = fEngine->addPlugin(static_cast<BinaryType>(btype), static_cast<PluginType>(ptype),
  1607. filename, name, label, uniqueId, nullptr, options);
  1608. if (filename != nullptr)
  1609. delete[] filename;
  1610. if (name != nullptr)
  1611. delete[] name;
  1612. delete[] label;
  1613. fEngine->reloadFromUI();
  1614. }
  1615. else if (std::strcmp(msg, "remove_plugin") == 0)
  1616. {
  1617. uint32_t pluginId;
  1618. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1619. ok = fEngine->removePlugin(pluginId);
  1620. fEngine->reloadFromUI();
  1621. }
  1622. else if (std::strcmp(msg, "remove_all_plugins") == 0)
  1623. {
  1624. ok = fEngine->removeAllPlugins();
  1625. fEngine->reloadFromUI();
  1626. }
  1627. else if (std::strcmp(msg, "rename_plugin") == 0)
  1628. {
  1629. uint32_t pluginId;
  1630. const char* newName;
  1631. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1632. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(newName, false), true);
  1633. ok = fEngine->renamePlugin(pluginId, newName);
  1634. }
  1635. else if (std::strcmp(msg, "clone_plugin") == 0)
  1636. {
  1637. uint32_t pluginId;
  1638. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1639. ok = fEngine->clonePlugin(pluginId);
  1640. fEngine->reloadFromUI();
  1641. }
  1642. else if (std::strcmp(msg, "replace_plugin") == 0)
  1643. {
  1644. uint32_t pluginId;
  1645. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1646. ok = fEngine->replacePlugin(pluginId);
  1647. }
  1648. else if (std::strcmp(msg, "switch_plugins") == 0)
  1649. {
  1650. uint32_t pluginIdA, pluginIdB;
  1651. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginIdA), true);
  1652. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginIdB), true);
  1653. ok = fEngine->switchPlugins(pluginIdA, pluginIdB);
  1654. fEngine->reloadFromUI();
  1655. }
  1656. else if (std::strcmp(msg, "load_plugin_state") == 0)
  1657. {
  1658. uint32_t pluginId;
  1659. const char* filename;
  1660. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1661. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename, false), true);
  1662. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1663. {
  1664. plugin->loadStateFromFile(filename);
  1665. _updateParamValues(plugin, pluginId, false, true);
  1666. }
  1667. }
  1668. else if (std::strcmp(msg, "save_plugin_state") == 0)
  1669. {
  1670. uint32_t pluginId;
  1671. const char* filename;
  1672. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1673. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename, false), true);
  1674. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1675. plugin->saveStateToFile(filename);
  1676. }
  1677. else if (std::strcmp(msg, "set_option") == 0)
  1678. {
  1679. uint32_t pluginId, option;
  1680. bool yesNo;
  1681. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1682. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(option), true);
  1683. CARLA_SAFE_ASSERT_RETURN(readNextLineAsBool(yesNo), true);
  1684. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1685. plugin->setOption(option, yesNo, false);
  1686. }
  1687. else if (std::strcmp(msg, "set_active") == 0)
  1688. {
  1689. uint32_t pluginId;
  1690. bool onOff;
  1691. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1692. CARLA_SAFE_ASSERT_RETURN(readNextLineAsBool(onOff), true);
  1693. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1694. plugin->setActive(onOff, true, false);
  1695. }
  1696. else if (std::strcmp(msg, "set_drywet") == 0)
  1697. {
  1698. uint32_t pluginId;
  1699. float value;
  1700. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1701. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(value), true);
  1702. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1703. plugin->setDryWet(value, true, false);
  1704. }
  1705. else if (std::strcmp(msg, "set_volume") == 0)
  1706. {
  1707. uint32_t pluginId;
  1708. float value;
  1709. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1710. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(value), true);
  1711. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1712. plugin->setVolume(value, true, false);
  1713. }
  1714. else if (std::strcmp(msg, "set_balance_left") == 0)
  1715. {
  1716. uint32_t pluginId;
  1717. float value;
  1718. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1719. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(value), true);
  1720. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1721. plugin->setBalanceLeft(value, true, false);
  1722. }
  1723. else if (std::strcmp(msg, "set_balance_right") == 0)
  1724. {
  1725. uint32_t pluginId;
  1726. float value;
  1727. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1728. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(value), true);
  1729. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1730. plugin->setBalanceRight(value, true, false);
  1731. }
  1732. else if (std::strcmp(msg, "set_panning") == 0)
  1733. {
  1734. uint32_t pluginId;
  1735. float value;
  1736. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1737. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(value), true);
  1738. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1739. plugin->setPanning(value, true, false);
  1740. }
  1741. else if (std::strcmp(msg, "set_ctrl_channel") == 0)
  1742. {
  1743. uint32_t pluginId;
  1744. int32_t channel;
  1745. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1746. CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(channel), true);
  1747. CARLA_SAFE_ASSERT_RETURN(channel >= -1 && channel < MAX_MIDI_CHANNELS, true);
  1748. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1749. plugin->setCtrlChannel(int8_t(channel), true, false);
  1750. }
  1751. else if (std::strcmp(msg, "set_parameter_value") == 0)
  1752. {
  1753. uint32_t pluginId, parameterId;
  1754. float value;
  1755. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1756. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(parameterId), true);
  1757. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(value), true);
  1758. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1759. {
  1760. plugin->setParameterValue(parameterId, value, true, true, false);
  1761. fEngine->setParameterValueFromUI(pluginId, parameterId, value);
  1762. }
  1763. }
  1764. else if (std::strcmp(msg, "set_parameter_midi_channel") == 0)
  1765. {
  1766. uint32_t pluginId, parameterId, channel;
  1767. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1768. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(parameterId), true);
  1769. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(channel), true);
  1770. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS, true);
  1771. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1772. plugin->setParameterMidiChannel(parameterId, static_cast<uint8_t>(channel), true, false);
  1773. }
  1774. else if (std::strcmp(msg, "set_parameter_mapped_control_index") == 0)
  1775. {
  1776. uint32_t pluginId, parameterId;
  1777. int32_t ctrl;
  1778. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1779. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(parameterId), true);
  1780. CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(ctrl), true);
  1781. CARLA_SAFE_ASSERT_RETURN(ctrl >= CONTROL_INDEX_NONE && ctrl <= CONTROL_INDEX_MAX_ALLOWED, true);
  1782. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1783. plugin->setParameterMappedControlIndex(parameterId, static_cast<int16_t>(ctrl), true, false, true);
  1784. }
  1785. else if (std::strcmp(msg, "set_parameter_mapped_range") == 0)
  1786. {
  1787. uint32_t pluginId, parameterId;
  1788. float minimum, maximum;
  1789. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1790. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(parameterId), true);
  1791. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(minimum), true);
  1792. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(maximum), true);
  1793. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1794. plugin->setParameterMappedRange(parameterId, minimum, maximum, true, false);
  1795. }
  1796. else if (std::strcmp(msg, "set_parameter_touch") == 0)
  1797. {
  1798. uint32_t pluginId, parameterId;
  1799. bool touching;
  1800. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1801. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(parameterId), true);
  1802. CARLA_SAFE_ASSERT_RETURN(readNextLineAsBool(touching), true);
  1803. if (fEngine->getPlugin(pluginId))
  1804. fEngine->setParameterTouchFromUI(pluginId, parameterId, touching);
  1805. }
  1806. else if (std::strcmp(msg, "set_program") == 0)
  1807. {
  1808. uint32_t pluginId;
  1809. int32_t index;
  1810. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1811. CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(index), true);
  1812. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1813. {
  1814. plugin->setProgram(index, true, true, false);
  1815. _updateParamValues(plugin, pluginId, true, true);
  1816. }
  1817. }
  1818. else if (std::strcmp(msg, "set_midi_program") == 0)
  1819. {
  1820. uint32_t pluginId;
  1821. int32_t index;
  1822. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1823. CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(index), true);
  1824. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1825. {
  1826. plugin->setMidiProgram(index, true, true, false);
  1827. _updateParamValues(plugin, pluginId, true, true);
  1828. }
  1829. }
  1830. else if (std::strcmp(msg, "set_custom_data") == 0)
  1831. {
  1832. uint32_t pluginId;
  1833. const char* type;
  1834. const char* key;
  1835. const char* value;
  1836. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1837. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(type, true), true);
  1838. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(key, true), true);
  1839. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(value, false), true);
  1840. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1841. plugin->setCustomData(type, key, value, true);
  1842. delete[] type;
  1843. delete[] key;
  1844. }
  1845. else if (std::strcmp(msg, "set_chunk_data") == 0)
  1846. {
  1847. uint32_t pluginId;
  1848. const char* cdata;
  1849. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1850. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(cdata, false), true);
  1851. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1852. {
  1853. std::vector<uint8_t> chunk(carla_getChunkFromBase64String(cdata));
  1854. #ifdef CARLA_PROPER_CPP11_SUPPORT
  1855. plugin->setChunkData(chunk.data(), chunk.size());
  1856. #else
  1857. plugin->setChunkData(&chunk.front(), chunk.size());
  1858. #endif
  1859. _updateParamValues(plugin, pluginId, false, true);
  1860. }
  1861. }
  1862. else if (std::strcmp(msg, "prepare_for_save") == 0)
  1863. {
  1864. uint32_t pluginId;
  1865. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1866. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1867. plugin->prepareForSave(false);
  1868. }
  1869. else if (std::strcmp(msg, "reset_parameters") == 0)
  1870. {
  1871. uint32_t pluginId;
  1872. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1873. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1874. {
  1875. plugin->resetParameters();
  1876. _updateParamValues(plugin, pluginId, false, true);
  1877. }
  1878. }
  1879. else if (std::strcmp(msg, "randomize_parameters") == 0)
  1880. {
  1881. uint32_t pluginId;
  1882. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1883. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1884. {
  1885. plugin->randomizeParameters();
  1886. _updateParamValues(plugin, pluginId, false, true);
  1887. }
  1888. }
  1889. else if (std::strcmp(msg, "send_midi_note") == 0)
  1890. {
  1891. uint32_t pluginId, channel, note, velocity;
  1892. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1893. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(channel), true);
  1894. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(note), true);
  1895. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(velocity), true);
  1896. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS, true);
  1897. CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_VALUE, true);
  1898. CARLA_SAFE_ASSERT_RETURN(velocity < MAX_MIDI_VALUE, true);
  1899. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1900. plugin->sendMidiSingleNote(static_cast<uint8_t>(channel), static_cast<uint8_t>(note), static_cast<uint8_t>(velocity), true, true, false);
  1901. }
  1902. else if (std::strcmp(msg, "show_custom_ui") == 0)
  1903. {
  1904. uint32_t pluginId;
  1905. bool yesNo;
  1906. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1907. CARLA_SAFE_ASSERT_RETURN(readNextLineAsBool(yesNo), true);
  1908. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1909. plugin->showCustomUI(yesNo);
  1910. }
  1911. else
  1912. {
  1913. carla_stderr("CarlaEngineNativeUI::msgReceived : %s", msg);
  1914. return false;
  1915. }
  1916. if (! ok)
  1917. {
  1918. const CarlaMutexLocker cml(getPipeLock());
  1919. if (writeMessage("error\n", 6) && writeAndFixMessage(fEngine->getLastError()))
  1920. flushMessages();
  1921. }
  1922. return true;
  1923. }
  1924. void CarlaEngineNativeUI::_updateParamValues(const CarlaPluginPtr& plugin,
  1925. const uint32_t pluginId,
  1926. const bool sendCallback, const bool sendPluginHost) const noexcept
  1927. {
  1928. float value;
  1929. for (uint32_t i=0, count=plugin->getParameterCount(); i<count; ++i) {
  1930. value = plugin->getParameterValue(i);
  1931. if (sendCallback) {
  1932. fEngine->callback(true, true,
  1933. ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
  1934. pluginId,
  1935. static_cast<int>(i),
  1936. 0, 0,
  1937. value,
  1938. nullptr);
  1939. }
  1940. if (sendPluginHost) {
  1941. carla_stdout("_updateParamValues");
  1942. fEngine->setParameterValueFromUI(pluginId, i, value);
  1943. }
  1944. }
  1945. }
  1946. #endif
  1947. // -----------------------------------------------------------------------
  1948. static const NativePluginDescriptor carlaRackDesc = {
  1949. /* category */ NATIVE_PLUGIN_CATEGORY_OTHER,
  1950. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_SYNTH
  1951. |NATIVE_PLUGIN_HAS_UI
  1952. |NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
  1953. |NATIVE_PLUGIN_USES_STATE
  1954. |NATIVE_PLUGIN_USES_TIME
  1955. |NATIVE_PLUGIN_USES_UI_SIZE),
  1956. /* supports */ static_cast<NativePluginSupports>(NATIVE_PLUGIN_SUPPORTS_EVERYTHING),
  1957. /* audioIns */ 2,
  1958. /* audioOuts */ 2,
  1959. /* midiIns */ 1,
  1960. /* midiOuts */ 1,
  1961. /* paramIns */ kNumInParams,
  1962. /* paramOuts */ kNumOutParams,
  1963. /* name */ "Carla-Rack",
  1964. /* label */ "carlarack",
  1965. /* maker */ "falkTX",
  1966. /* copyright */ "GNU GPL v2+",
  1967. CarlaEngineNative::_instantiateRack,
  1968. CarlaEngineNative::_cleanup,
  1969. CarlaEngineNative::_get_parameter_count,
  1970. CarlaEngineNative::_get_parameter_info,
  1971. CarlaEngineNative::_get_parameter_value,
  1972. /* _get_midi_program_count */ nullptr,
  1973. /* _get_midi_program_info */ nullptr,
  1974. CarlaEngineNative::_set_parameter_value,
  1975. /* _set_midi_program */ nullptr,
  1976. /* _set_custom_data */ nullptr,
  1977. #ifndef CARLA_ENGINE_WITHOUT_UI
  1978. CarlaEngineNative::_ui_show,
  1979. CarlaEngineNative::_ui_idle,
  1980. CarlaEngineNative::_ui_set_parameter_value,
  1981. #else
  1982. nullptr, nullptr, nullptr,
  1983. #endif
  1984. /* _ui_set_midi_program */ nullptr,
  1985. /* _ui_set_custom_data */ nullptr,
  1986. CarlaEngineNative::_activate,
  1987. CarlaEngineNative::_deactivate,
  1988. CarlaEngineNative::_process,
  1989. CarlaEngineNative::_get_state,
  1990. CarlaEngineNative::_set_state,
  1991. CarlaEngineNative::_dispatcher,
  1992. /* _render_inline_dsplay */ nullptr,
  1993. /* cvIns */ 0,
  1994. /* cvOuts */ 0,
  1995. /* _get_buffer_port_name */ nullptr,
  1996. /* _get_buffer_port_range */ nullptr,
  1997. /* ui_width */ kUiWidth,
  1998. /* ui_height */ kUiHeight
  1999. };
  2000. static const NativePluginDescriptor carlaRackNoMidiOutDesc = {
  2001. /* category */ NATIVE_PLUGIN_CATEGORY_OTHER,
  2002. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_SYNTH
  2003. |NATIVE_PLUGIN_HAS_UI
  2004. |NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
  2005. |NATIVE_PLUGIN_USES_STATE
  2006. |NATIVE_PLUGIN_USES_TIME
  2007. |NATIVE_PLUGIN_USES_UI_SIZE),
  2008. /* supports */ static_cast<NativePluginSupports>(NATIVE_PLUGIN_SUPPORTS_EVERYTHING),
  2009. /* audioIns */ 2,
  2010. /* audioOuts */ 2,
  2011. /* midiIns */ 1,
  2012. /* midiOuts */ 0,
  2013. /* paramIns */ kNumInParams,
  2014. /* paramOuts */ kNumOutParams,
  2015. /* name */ "Carla-Rack (no midi out)",
  2016. /* label */ "carlarack-nomidiout",
  2017. /* maker */ "falkTX",
  2018. /* copyright */ "GNU GPL v2+",
  2019. CarlaEngineNative::_instantiateRackNoMidiOut,
  2020. CarlaEngineNative::_cleanup,
  2021. CarlaEngineNative::_get_parameter_count,
  2022. CarlaEngineNative::_get_parameter_info,
  2023. CarlaEngineNative::_get_parameter_value,
  2024. /* _get_midi_program_count */ nullptr,
  2025. /* _get_midi_program_info */ nullptr,
  2026. CarlaEngineNative::_set_parameter_value,
  2027. /* _set_midi_program */ nullptr,
  2028. /* _set_custom_data */ nullptr,
  2029. #ifndef CARLA_ENGINE_WITHOUT_UI
  2030. CarlaEngineNative::_ui_show,
  2031. CarlaEngineNative::_ui_idle,
  2032. CarlaEngineNative::_ui_set_parameter_value,
  2033. #else
  2034. nullptr, nullptr, nullptr,
  2035. #endif
  2036. /* _ui_set_midi_program */ nullptr,
  2037. /* _ui_set_custom_data */ nullptr,
  2038. CarlaEngineNative::_activate,
  2039. CarlaEngineNative::_deactivate,
  2040. CarlaEngineNative::_process,
  2041. CarlaEngineNative::_get_state,
  2042. CarlaEngineNative::_set_state,
  2043. CarlaEngineNative::_dispatcher,
  2044. /* _render_inline_dsplay */ nullptr,
  2045. /* cvIns */ 0,
  2046. /* cvOuts */ 0,
  2047. /* _get_buffer_port_name */ nullptr,
  2048. /* _get_buffer_port_range */ nullptr,
  2049. /* ui_width */ kUiWidth,
  2050. /* ui_height */ kUiHeight
  2051. };
  2052. static const NativePluginDescriptor carlaPatchbayDesc = {
  2053. /* category */ NATIVE_PLUGIN_CATEGORY_OTHER,
  2054. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_SYNTH
  2055. |NATIVE_PLUGIN_HAS_UI
  2056. |NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
  2057. |NATIVE_PLUGIN_USES_STATE
  2058. |NATIVE_PLUGIN_USES_TIME
  2059. |NATIVE_PLUGIN_USES_UI_SIZE),
  2060. /* supports */ static_cast<NativePluginSupports>(NATIVE_PLUGIN_SUPPORTS_EVERYTHING),
  2061. /* audioIns */ 2,
  2062. /* audioOuts */ 2,
  2063. /* midiIns */ 1,
  2064. /* midiOuts */ 1,
  2065. /* paramIns */ kNumInParams,
  2066. /* paramOuts */ kNumOutParams,
  2067. /* name */ "Carla-Patchbay",
  2068. /* label */ "carlapatchbay",
  2069. /* maker */ "falkTX",
  2070. /* copyright */ "GNU GPL v2+",
  2071. CarlaEngineNative::_instantiatePatchbay,
  2072. CarlaEngineNative::_cleanup,
  2073. CarlaEngineNative::_get_parameter_count,
  2074. CarlaEngineNative::_get_parameter_info,
  2075. CarlaEngineNative::_get_parameter_value,
  2076. /* _get_midi_program_count */ nullptr,
  2077. /* _get_midi_program_info */ nullptr,
  2078. CarlaEngineNative::_set_parameter_value,
  2079. /* _set_midi_program */ nullptr,
  2080. /* _set_custom_data */ nullptr,
  2081. #ifndef CARLA_ENGINE_WITHOUT_UI
  2082. CarlaEngineNative::_ui_show,
  2083. CarlaEngineNative::_ui_idle,
  2084. CarlaEngineNative::_ui_set_parameter_value,
  2085. #else
  2086. nullptr, nullptr, nullptr,
  2087. #endif
  2088. /* _ui_set_midi_program */ nullptr,
  2089. /* _ui_set_custom_data */ nullptr,
  2090. CarlaEngineNative::_activate,
  2091. CarlaEngineNative::_deactivate,
  2092. CarlaEngineNative::_process,
  2093. CarlaEngineNative::_get_state,
  2094. CarlaEngineNative::_set_state,
  2095. CarlaEngineNative::_dispatcher,
  2096. /* _render_inline_dsplay */ nullptr,
  2097. /* cvIns */ 0,
  2098. /* cvOuts */ 0,
  2099. /* _get_buffer_port_name */ nullptr,
  2100. /* _get_buffer_port_range */ nullptr,
  2101. /* ui_width */ kUiWidth,
  2102. /* ui_height */ kUiHeight
  2103. };
  2104. static const NativePluginDescriptor carlaPatchbay3sDesc = {
  2105. /* category */ NATIVE_PLUGIN_CATEGORY_OTHER,
  2106. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_SYNTH
  2107. |NATIVE_PLUGIN_HAS_UI
  2108. |NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
  2109. |NATIVE_PLUGIN_USES_STATE
  2110. |NATIVE_PLUGIN_USES_TIME
  2111. |NATIVE_PLUGIN_USES_UI_SIZE),
  2112. /* supports */ static_cast<NativePluginSupports>(NATIVE_PLUGIN_SUPPORTS_EVERYTHING),
  2113. /* audioIns */ 3,
  2114. /* audioOuts */ 2,
  2115. /* midiIns */ 1,
  2116. /* midiOuts */ 1,
  2117. /* paramIns */ kNumInParams,
  2118. /* paramOuts */ kNumOutParams,
  2119. /* name */ "Carla-Patchbay (sidechain)",
  2120. /* label */ "carlapatchbay3s",
  2121. /* maker */ "falkTX",
  2122. /* copyright */ "GNU GPL v2+",
  2123. CarlaEngineNative::_instantiatePatchbay3s,
  2124. CarlaEngineNative::_cleanup,
  2125. CarlaEngineNative::_get_parameter_count,
  2126. CarlaEngineNative::_get_parameter_info,
  2127. CarlaEngineNative::_get_parameter_value,
  2128. /* _get_midi_program_count */ nullptr,
  2129. /* _get_midi_program_info */ nullptr,
  2130. CarlaEngineNative::_set_parameter_value,
  2131. /* _set_midi_program */ nullptr,
  2132. /* _set_custom_data */ nullptr,
  2133. #ifndef CARLA_ENGINE_WITHOUT_UI
  2134. CarlaEngineNative::_ui_show,
  2135. CarlaEngineNative::_ui_idle,
  2136. CarlaEngineNative::_ui_set_parameter_value,
  2137. #else
  2138. nullptr, nullptr, nullptr,
  2139. #endif
  2140. /* _ui_set_midi_program */ nullptr,
  2141. /* _ui_set_custom_data */ nullptr,
  2142. CarlaEngineNative::_activate,
  2143. CarlaEngineNative::_deactivate,
  2144. CarlaEngineNative::_process,
  2145. CarlaEngineNative::_get_state,
  2146. CarlaEngineNative::_set_state,
  2147. CarlaEngineNative::_dispatcher,
  2148. /* _render_inline_dsplay */ nullptr,
  2149. /* cvIns */ 0,
  2150. /* cvOuts */ 0,
  2151. /* _get_buffer_port_name */ nullptr,
  2152. /* _get_buffer_port_range */ nullptr,
  2153. /* ui_width */ kUiWidth,
  2154. /* ui_height */ kUiHeight
  2155. };
  2156. static const NativePluginDescriptor carlaPatchbay16Desc = {
  2157. /* category */ NATIVE_PLUGIN_CATEGORY_OTHER,
  2158. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_SYNTH
  2159. |NATIVE_PLUGIN_HAS_UI
  2160. |NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
  2161. |NATIVE_PLUGIN_USES_STATE
  2162. |NATIVE_PLUGIN_USES_TIME
  2163. |NATIVE_PLUGIN_USES_UI_SIZE),
  2164. /* supports */ static_cast<NativePluginSupports>(NATIVE_PLUGIN_SUPPORTS_EVERYTHING),
  2165. /* audioIns */ 16,
  2166. /* audioOuts */ 16,
  2167. /* midiIns */ 1,
  2168. /* midiOuts */ 1,
  2169. /* paramIns */ kNumInParams,
  2170. /* paramOuts */ kNumOutParams,
  2171. /* name */ "Carla-Patchbay (16chan)",
  2172. /* label */ "carlapatchbay16",
  2173. /* maker */ "falkTX",
  2174. /* copyright */ "GNU GPL v2+",
  2175. CarlaEngineNative::_instantiatePatchbay16,
  2176. CarlaEngineNative::_cleanup,
  2177. CarlaEngineNative::_get_parameter_count,
  2178. CarlaEngineNative::_get_parameter_info,
  2179. CarlaEngineNative::_get_parameter_value,
  2180. /* _get_midi_program_count */ nullptr,
  2181. /* _get_midi_program_info */ nullptr,
  2182. CarlaEngineNative::_set_parameter_value,
  2183. /* _set_midi_program */ nullptr,
  2184. /* _set_custom_data */ nullptr,
  2185. #ifndef CARLA_ENGINE_WITHOUT_UI
  2186. CarlaEngineNative::_ui_show,
  2187. CarlaEngineNative::_ui_idle,
  2188. CarlaEngineNative::_ui_set_parameter_value,
  2189. #else
  2190. nullptr, nullptr, nullptr,
  2191. #endif
  2192. /* _ui_set_midi_program */ nullptr,
  2193. /* _ui_set_custom_data */ nullptr,
  2194. CarlaEngineNative::_activate,
  2195. CarlaEngineNative::_deactivate,
  2196. CarlaEngineNative::_process,
  2197. CarlaEngineNative::_get_state,
  2198. CarlaEngineNative::_set_state,
  2199. CarlaEngineNative::_dispatcher,
  2200. /* _render_inline_dsplay */ nullptr,
  2201. /* cvIns */ 0,
  2202. /* cvOuts */ 0,
  2203. /* _get_buffer_port_name */ nullptr,
  2204. /* _get_buffer_port_range */ nullptr,
  2205. /* ui_width */ kUiWidth,
  2206. /* ui_height */ kUiHeight
  2207. };
  2208. static const NativePluginDescriptor carlaPatchbay32Desc = {
  2209. /* category */ NATIVE_PLUGIN_CATEGORY_OTHER,
  2210. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_SYNTH
  2211. |NATIVE_PLUGIN_HAS_UI
  2212. |NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
  2213. |NATIVE_PLUGIN_USES_STATE
  2214. |NATIVE_PLUGIN_USES_TIME
  2215. |NATIVE_PLUGIN_USES_UI_SIZE),
  2216. /* supports */ static_cast<NativePluginSupports>(NATIVE_PLUGIN_SUPPORTS_EVERYTHING),
  2217. /* audioIns */ 32,
  2218. /* audioOuts */ 32,
  2219. /* midiIns */ 1,
  2220. /* midiOuts */ 1,
  2221. /* paramIns */ kNumInParams,
  2222. /* paramOuts */ kNumOutParams,
  2223. /* name */ "Carla-Patchbay (32chan)",
  2224. /* label */ "carlapatchbay32",
  2225. /* maker */ "falkTX",
  2226. /* copyright */ "GNU GPL v2+",
  2227. CarlaEngineNative::_instantiatePatchbay32,
  2228. CarlaEngineNative::_cleanup,
  2229. CarlaEngineNative::_get_parameter_count,
  2230. CarlaEngineNative::_get_parameter_info,
  2231. CarlaEngineNative::_get_parameter_value,
  2232. /* _get_midi_program_count */ nullptr,
  2233. /* _get_midi_program_info */ nullptr,
  2234. CarlaEngineNative::_set_parameter_value,
  2235. /* _set_midi_program */ nullptr,
  2236. /* _set_custom_data */ nullptr,
  2237. #ifndef CARLA_ENGINE_WITHOUT_UI
  2238. CarlaEngineNative::_ui_show,
  2239. CarlaEngineNative::_ui_idle,
  2240. CarlaEngineNative::_ui_set_parameter_value,
  2241. #else
  2242. nullptr, nullptr, nullptr,
  2243. #endif
  2244. /* _ui_set_midi_program */ nullptr,
  2245. /* _ui_set_custom_data */ nullptr,
  2246. CarlaEngineNative::_activate,
  2247. CarlaEngineNative::_deactivate,
  2248. CarlaEngineNative::_process,
  2249. CarlaEngineNative::_get_state,
  2250. CarlaEngineNative::_set_state,
  2251. CarlaEngineNative::_dispatcher,
  2252. /* _render_inline_dsplay */ nullptr,
  2253. /* cvIns */ 0,
  2254. /* cvOuts */ 0,
  2255. /* _get_buffer_port_name */ nullptr,
  2256. /* _get_buffer_port_range */ nullptr,
  2257. /* ui_width */ kUiWidth,
  2258. /* ui_height */ kUiHeight
  2259. };
  2260. static const NativePluginDescriptor carlaPatchbay64Desc = {
  2261. /* category */ NATIVE_PLUGIN_CATEGORY_OTHER,
  2262. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_SYNTH
  2263. |NATIVE_PLUGIN_HAS_UI
  2264. |NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
  2265. |NATIVE_PLUGIN_USES_STATE
  2266. |NATIVE_PLUGIN_USES_TIME
  2267. |NATIVE_PLUGIN_USES_UI_SIZE),
  2268. /* supports */ static_cast<NativePluginSupports>(NATIVE_PLUGIN_SUPPORTS_EVERYTHING),
  2269. /* audioIns */ 64,
  2270. /* audioOuts */ 64,
  2271. /* midiIns */ 1,
  2272. /* midiOuts */ 1,
  2273. /* paramIns */ kNumInParams,
  2274. /* paramOuts */ kNumOutParams,
  2275. /* name */ "Carla-Patchbay (64chan)",
  2276. /* label */ "carlapatchbay64",
  2277. /* maker */ "falkTX",
  2278. /* copyright */ "GNU GPL v2+",
  2279. CarlaEngineNative::_instantiatePatchbay64,
  2280. CarlaEngineNative::_cleanup,
  2281. CarlaEngineNative::_get_parameter_count,
  2282. CarlaEngineNative::_get_parameter_info,
  2283. CarlaEngineNative::_get_parameter_value,
  2284. /* _get_midi_program_count */ nullptr,
  2285. /* _get_midi_program_info */ nullptr,
  2286. CarlaEngineNative::_set_parameter_value,
  2287. /* _set_midi_program */ nullptr,
  2288. /* _set_custom_data */ nullptr,
  2289. #ifndef CARLA_ENGINE_WITHOUT_UI
  2290. CarlaEngineNative::_ui_show,
  2291. CarlaEngineNative::_ui_idle,
  2292. CarlaEngineNative::_ui_set_parameter_value,
  2293. #else
  2294. nullptr, nullptr, nullptr,
  2295. #endif
  2296. /* _ui_set_midi_program */ nullptr,
  2297. /* _ui_set_custom_data */ nullptr,
  2298. CarlaEngineNative::_activate,
  2299. CarlaEngineNative::_deactivate,
  2300. CarlaEngineNative::_process,
  2301. CarlaEngineNative::_get_state,
  2302. CarlaEngineNative::_set_state,
  2303. CarlaEngineNative::_dispatcher,
  2304. /* _render_inline_dsplay */ nullptr,
  2305. /* cvIns */ 0,
  2306. /* cvOuts */ 0,
  2307. /* _get_buffer_port_name */ nullptr,
  2308. /* _get_buffer_port_range */ nullptr,
  2309. /* ui_width */ kUiWidth,
  2310. /* ui_height */ kUiHeight
  2311. };
  2312. static const NativePluginDescriptor carlaPatchbayCVDesc = {
  2313. /* category */ NATIVE_PLUGIN_CATEGORY_OTHER,
  2314. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_SYNTH
  2315. |NATIVE_PLUGIN_HAS_UI
  2316. |NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
  2317. |NATIVE_PLUGIN_USES_CONTROL_VOLTAGE
  2318. |NATIVE_PLUGIN_USES_STATE
  2319. |NATIVE_PLUGIN_USES_TIME
  2320. |NATIVE_PLUGIN_USES_UI_SIZE),
  2321. /* supports */ static_cast<NativePluginSupports>(NATIVE_PLUGIN_SUPPORTS_EVERYTHING),
  2322. /* audioIns */ 2,
  2323. /* audioOuts */ 2,
  2324. /* midiIns */ 1,
  2325. /* midiOuts */ 1,
  2326. /* paramIns */ kNumInParams,
  2327. /* paramOuts */ kNumOutParams,
  2328. /* name */ "Carla-Patchbay (CV)",
  2329. /* label */ "carlapatchbaycv",
  2330. /* maker */ "falkTX",
  2331. /* copyright */ "GNU GPL v2+",
  2332. CarlaEngineNative::_instantiatePatchbayCV,
  2333. CarlaEngineNative::_cleanup,
  2334. CarlaEngineNative::_get_parameter_count,
  2335. CarlaEngineNative::_get_parameter_info,
  2336. CarlaEngineNative::_get_parameter_value,
  2337. /* _get_midi_program_count */ nullptr,
  2338. /* _get_midi_program_info */ nullptr,
  2339. CarlaEngineNative::_set_parameter_value,
  2340. /* _set_midi_program */ nullptr,
  2341. /* _set_custom_data */ nullptr,
  2342. #ifndef CARLA_ENGINE_WITHOUT_UI
  2343. CarlaEngineNative::_ui_show,
  2344. CarlaEngineNative::_ui_idle,
  2345. CarlaEngineNative::_ui_set_parameter_value,
  2346. #else
  2347. nullptr, nullptr, nullptr,
  2348. #endif
  2349. /* _ui_set_midi_program */ nullptr,
  2350. /* _ui_set_custom_data */ nullptr,
  2351. CarlaEngineNative::_activate,
  2352. CarlaEngineNative::_deactivate,
  2353. CarlaEngineNative::_process,
  2354. CarlaEngineNative::_get_state,
  2355. CarlaEngineNative::_set_state,
  2356. CarlaEngineNative::_dispatcher,
  2357. /* _render_inline_dsplay */ nullptr,
  2358. /* cvIns */ 5,
  2359. /* cvOuts */ 5,
  2360. /* _get_buffer_port_name */ nullptr,
  2361. /* _get_buffer_port_range */ nullptr,
  2362. /* ui_width */ kUiWidth,
  2363. /* ui_height */ kUiHeight
  2364. };
  2365. static const NativePluginDescriptor carlaPatchbayCV8Desc = {
  2366. /* category */ NATIVE_PLUGIN_CATEGORY_OTHER,
  2367. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_SYNTH
  2368. |NATIVE_PLUGIN_HAS_UI
  2369. |NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
  2370. |NATIVE_PLUGIN_USES_CONTROL_VOLTAGE
  2371. |NATIVE_PLUGIN_USES_STATE
  2372. |NATIVE_PLUGIN_USES_TIME
  2373. |NATIVE_PLUGIN_USES_UI_SIZE),
  2374. /* supports */ static_cast<NativePluginSupports>(NATIVE_PLUGIN_SUPPORTS_EVERYTHING),
  2375. /* audioIns */ 2,
  2376. /* audioOuts */ 2,
  2377. /* midiIns */ 1,
  2378. /* midiOuts */ 1,
  2379. /* paramIns */ kNumInParams,
  2380. /* paramOuts */ kNumOutParams,
  2381. /* name */ "Carla-Patchbay (CV8)",
  2382. /* label */ "carlapatchbaycv",
  2383. /* maker */ "falkTX",
  2384. /* copyright */ "GNU GPL v2+",
  2385. CarlaEngineNative::_instantiatePatchbayCV8,
  2386. CarlaEngineNative::_cleanup,
  2387. CarlaEngineNative::_get_parameter_count,
  2388. CarlaEngineNative::_get_parameter_info,
  2389. CarlaEngineNative::_get_parameter_value,
  2390. /* _get_midi_program_count */ nullptr,
  2391. /* _get_midi_program_info */ nullptr,
  2392. CarlaEngineNative::_set_parameter_value,
  2393. /* _set_midi_program */ nullptr,
  2394. /* _set_custom_data */ nullptr,
  2395. #ifndef CARLA_ENGINE_WITHOUT_UI
  2396. CarlaEngineNative::_ui_show,
  2397. CarlaEngineNative::_ui_idle,
  2398. CarlaEngineNative::_ui_set_parameter_value,
  2399. #else
  2400. nullptr, nullptr, nullptr,
  2401. #endif
  2402. /* _ui_set_midi_program */ nullptr,
  2403. /* _ui_set_custom_data */ nullptr,
  2404. CarlaEngineNative::_activate,
  2405. CarlaEngineNative::_deactivate,
  2406. CarlaEngineNative::_process,
  2407. CarlaEngineNative::_get_state,
  2408. CarlaEngineNative::_set_state,
  2409. CarlaEngineNative::_dispatcher,
  2410. /* _render_inline_dsplay */ nullptr,
  2411. /* cvIns */ 8,
  2412. /* cvOuts */ 8,
  2413. /* _get_buffer_port_name */ nullptr,
  2414. /* _get_buffer_port_range */ nullptr,
  2415. /* ui_width */ kUiWidth,
  2416. /* ui_height */ kUiHeight
  2417. };
  2418. static const NativePluginDescriptor carlaPatchbayCV32Desc = {
  2419. /* category */ NATIVE_PLUGIN_CATEGORY_OTHER,
  2420. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_SYNTH
  2421. |NATIVE_PLUGIN_HAS_UI
  2422. |NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
  2423. |NATIVE_PLUGIN_USES_CONTROL_VOLTAGE
  2424. |NATIVE_PLUGIN_USES_STATE
  2425. |NATIVE_PLUGIN_USES_TIME
  2426. |NATIVE_PLUGIN_USES_UI_SIZE),
  2427. /* supports */ static_cast<NativePluginSupports>(NATIVE_PLUGIN_SUPPORTS_EVERYTHING),
  2428. /* audioIns */ 64,
  2429. /* audioOuts */ 64,
  2430. /* midiIns */ 1,
  2431. /* midiOuts */ 1,
  2432. /* paramIns */ kNumInParams,
  2433. /* paramOuts */ kNumOutParams,
  2434. /* name */ "Carla-Patchbay (CV32)",
  2435. /* label */ "carlapatchbaycv",
  2436. /* maker */ "falkTX",
  2437. /* copyright */ "GNU GPL v2+",
  2438. CarlaEngineNative::_instantiatePatchbayCV32,
  2439. CarlaEngineNative::_cleanup,
  2440. CarlaEngineNative::_get_parameter_count,
  2441. CarlaEngineNative::_get_parameter_info,
  2442. CarlaEngineNative::_get_parameter_value,
  2443. /* _get_midi_program_count */ nullptr,
  2444. /* _get_midi_program_info */ nullptr,
  2445. CarlaEngineNative::_set_parameter_value,
  2446. /* _set_midi_program */ nullptr,
  2447. /* _set_custom_data */ nullptr,
  2448. #ifndef CARLA_ENGINE_WITHOUT_UI
  2449. CarlaEngineNative::_ui_show,
  2450. CarlaEngineNative::_ui_idle,
  2451. CarlaEngineNative::_ui_set_parameter_value,
  2452. #else
  2453. nullptr, nullptr, nullptr,
  2454. #endif
  2455. /* _ui_set_midi_program */ nullptr,
  2456. /* _ui_set_custom_data */ nullptr,
  2457. CarlaEngineNative::_activate,
  2458. CarlaEngineNative::_deactivate,
  2459. CarlaEngineNative::_process,
  2460. CarlaEngineNative::_get_state,
  2461. CarlaEngineNative::_set_state,
  2462. CarlaEngineNative::_dispatcher,
  2463. /* _render_inline_dsplay */ nullptr,
  2464. /* cvIns */ 32,
  2465. /* cvOuts */ 32,
  2466. /* _get_buffer_port_name */ nullptr,
  2467. /* _get_buffer_port_range */ nullptr,
  2468. /* ui_width */ kUiWidth,
  2469. /* ui_height */ kUiHeight
  2470. };
  2471. CARLA_BACKEND_END_NAMESPACE
  2472. // -----------------------------------------------------------------------
  2473. CARLA_API_EXPORT
  2474. void carla_register_native_plugin_carla();
  2475. void carla_register_native_plugin_carla()
  2476. {
  2477. CARLA_BACKEND_USE_NAMESPACE;
  2478. carla_register_native_plugin(&carlaRackDesc);
  2479. carla_register_native_plugin(&carlaRackNoMidiOutDesc);
  2480. carla_register_native_plugin(&carlaPatchbayDesc);
  2481. carla_register_native_plugin(&carlaPatchbay3sDesc);
  2482. carla_register_native_plugin(&carlaPatchbay16Desc);
  2483. carla_register_native_plugin(&carlaPatchbay32Desc);
  2484. carla_register_native_plugin(&carlaPatchbay64Desc);
  2485. carla_register_native_plugin(&carlaPatchbayCVDesc);
  2486. }
  2487. // -----------------------------------------------------------------------
  2488. const NativePluginDescriptor* carla_get_native_rack_plugin()
  2489. {
  2490. CARLA_BACKEND_USE_NAMESPACE;
  2491. return &carlaRackDesc;
  2492. }
  2493. const NativePluginDescriptor* carla_get_native_patchbay_plugin()
  2494. {
  2495. CARLA_BACKEND_USE_NAMESPACE;
  2496. return &carlaPatchbayDesc;
  2497. }
  2498. const NativePluginDescriptor* carla_get_native_patchbay16_plugin()
  2499. {
  2500. CARLA_BACKEND_USE_NAMESPACE;
  2501. return &carlaPatchbay16Desc;
  2502. }
  2503. const NativePluginDescriptor* carla_get_native_patchbay32_plugin()
  2504. {
  2505. CARLA_BACKEND_USE_NAMESPACE;
  2506. return &carlaPatchbay32Desc;
  2507. }
  2508. const NativePluginDescriptor* carla_get_native_patchbay64_plugin()
  2509. {
  2510. CARLA_BACKEND_USE_NAMESPACE;
  2511. return &carlaPatchbay64Desc;
  2512. }
  2513. const NativePluginDescriptor* carla_get_native_patchbay_cv_plugin()
  2514. {
  2515. CARLA_BACKEND_USE_NAMESPACE;
  2516. return &carlaPatchbayCVDesc;
  2517. }
  2518. const NativePluginDescriptor* carla_get_native_patchbay_cv8_plugin()
  2519. {
  2520. CARLA_BACKEND_USE_NAMESPACE;
  2521. return &carlaPatchbayCV8Desc;
  2522. }
  2523. const NativePluginDescriptor* carla_get_native_patchbay_cv32_plugin()
  2524. {
  2525. CARLA_BACKEND_USE_NAMESPACE;
  2526. return &carlaPatchbayCV32Desc;
  2527. }
  2528. // -----------------------------------------------------------------------
  2529. // Extra stuff for linking purposes
  2530. #ifdef CARLA_PLUGIN_BUILD
  2531. CARLA_BACKEND_START_NAMESPACE
  2532. namespace EngineInit {
  2533. CarlaEngine* newJack() { return nullptr; }
  2534. #ifdef USING_JUCE_AUDIO_DEVICES
  2535. CarlaEngine* newJuce(const AudioApi) { return nullptr; }
  2536. uint getJuceApiCount() { return 0; }
  2537. const char* getJuceApiName(const uint) { return nullptr; }
  2538. const char* const* getJuceApiDeviceNames(const uint) { return nullptr; }
  2539. const EngineDriverDeviceInfo* getJuceDeviceInfo(const uint, const char* const) { return nullptr; }
  2540. bool showJuceDeviceControlPanel(const uint, const char* const) { return false; }
  2541. #endif
  2542. #ifdef USING_RTAUDIO
  2543. CarlaEngine* newRtAudio(const AudioApi) { return nullptr; }
  2544. uint getRtAudioApiCount() { return 0; }
  2545. const char* getRtAudioApiName(const uint) { return nullptr; }
  2546. const char* const* getRtAudioApiDeviceNames(const uint) { return nullptr; }
  2547. const EngineDriverDeviceInfo* getRtAudioDeviceInfo(const uint, const char* const) { return nullptr; }
  2548. #endif
  2549. #ifdef HAVE_SDL
  2550. CarlaEngine* newSDL() { return nullptr; }
  2551. const char* const* getSDLDeviceNames() { return nullptr; }
  2552. #endif
  2553. }
  2554. CARLA_BACKEND_END_NAMESPACE
  2555. #define CARLA_PLUGIN_UI_CLASS_PREFIX Plugin
  2556. #include "CarlaPluginUI.cpp"
  2557. # undef CARLA_PLUGIN_UI_CLASS_PREFIX
  2558. #include "CarlaDssiUtils.cpp"
  2559. #include "CarlaMacUtils.cpp"
  2560. #include "CarlaPatchbayUtils.cpp"
  2561. #include "CarlaPipeUtils.cpp"
  2562. #include "CarlaProcessUtils.cpp"
  2563. #include "CarlaStateUtils.cpp"
  2564. #endif /* CARLA_PLUGIN_BUILD */
  2565. // -----------------------------------------------------------------------