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

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