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.

2915 lines
102KB

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