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

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