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.

3044 lines
106KB

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