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

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