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

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