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

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