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