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.

2976 lines
104KB

  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_AUTOMATABLE)
  817. hints |= NATIVE_PARAMETER_IS_AUTOMATABLE;
  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 NativePluginHandle _instantiatePatchbayCV8(const NativeHostDescriptor* host)
  1299. {
  1300. return new CarlaEngineNative(host, true, true, 2, 2, 8, 8);
  1301. }
  1302. static void _cleanup(NativePluginHandle handle)
  1303. {
  1304. delete handlePtr;
  1305. }
  1306. static uint32_t _get_parameter_count(NativePluginHandle handle)
  1307. {
  1308. return handlePtr->getParameterCount();
  1309. }
  1310. static const NativeParameter* _get_parameter_info(NativePluginHandle handle, uint32_t index)
  1311. {
  1312. return handlePtr->getParameterInfo(index);
  1313. }
  1314. static float _get_parameter_value(NativePluginHandle handle, uint32_t index)
  1315. {
  1316. return handlePtr->getParameterValue(index);
  1317. }
  1318. static void _set_parameter_value(NativePluginHandle handle, uint32_t index, float value)
  1319. {
  1320. handlePtr->setParameterValue(index, value);
  1321. }
  1322. static void _ui_show(NativePluginHandle handle, bool show)
  1323. {
  1324. handlePtr->uiShow(show);
  1325. }
  1326. static void _ui_idle(NativePluginHandle handle)
  1327. {
  1328. handlePtr->uiIdle();
  1329. }
  1330. static void _ui_set_parameter_value(NativePluginHandle handle, uint32_t index, float value)
  1331. {
  1332. handlePtr->uiSetParameterValue(index, value);
  1333. }
  1334. static void _activate(NativePluginHandle handle)
  1335. {
  1336. handlePtr->activate();
  1337. }
  1338. static void _deactivate(NativePluginHandle handle)
  1339. {
  1340. handlePtr->deactivate();
  1341. }
  1342. // FIXME for v3.0, use const for the input buffer
  1343. static void _process(NativePluginHandle handle,
  1344. float** inBuffer, float** outBuffer, const uint32_t frames,
  1345. const NativeMidiEvent* midiEvents, uint32_t midiEventCount)
  1346. {
  1347. handlePtr->process(inBuffer, outBuffer, frames, midiEvents, midiEventCount);
  1348. }
  1349. static char* _get_state(NativePluginHandle handle)
  1350. {
  1351. return handlePtr->getState();
  1352. }
  1353. static void _set_state(NativePluginHandle handle, const char* data)
  1354. {
  1355. handlePtr->setState(data);
  1356. }
  1357. static intptr_t _dispatcher(NativePluginHandle handle,
  1358. NativePluginDispatcherOpcode opcode,
  1359. int32_t index, intptr_t value, void* ptr, float opt)
  1360. {
  1361. switch(opcode)
  1362. {
  1363. case NATIVE_PLUGIN_OPCODE_NULL:
  1364. return 0;
  1365. case NATIVE_PLUGIN_OPCODE_BUFFER_SIZE_CHANGED:
  1366. CARLA_SAFE_ASSERT_RETURN(value > 0, 0);
  1367. handlePtr->bufferSizeChanged(static_cast<uint32_t>(value));
  1368. return 0;
  1369. case NATIVE_PLUGIN_OPCODE_SAMPLE_RATE_CHANGED:
  1370. CARLA_SAFE_ASSERT_RETURN(opt > 0.0f, 0);
  1371. handlePtr->sampleRateChanged(static_cast<double>(opt));
  1372. return 0;
  1373. case NATIVE_PLUGIN_OPCODE_OFFLINE_CHANGED:
  1374. handlePtr->offlineModeChanged(value != 0);
  1375. return 0;
  1376. case NATIVE_PLUGIN_OPCODE_UI_NAME_CHANGED:
  1377. //handlePtr->uiNameChanged(static_cast<const char*>(ptr));
  1378. return 0;
  1379. case NATIVE_PLUGIN_OPCODE_GET_INTERNAL_HANDLE: {
  1380. CarlaEngineNative* const engine = handlePtr;
  1381. return (intptr_t)(CarlaEngine*)engine;
  1382. }
  1383. case NATIVE_PLUGIN_OPCODE_IDLE:
  1384. //handlePtr->idle();
  1385. return 0;
  1386. case NATIVE_PLUGIN_OPCODE_UI_MIDI_EVENT:
  1387. return 0;
  1388. case NATIVE_PLUGIN_OPCODE_HOST_USES_EMBED:
  1389. handlePtr->fUsesEmbed = true;
  1390. return 0;
  1391. }
  1392. return 0;
  1393. // unused
  1394. (void)index;
  1395. (void)ptr;
  1396. }
  1397. // -------------------------------------------------------------------
  1398. #undef handlePtr
  1399. private:
  1400. const NativeHostDescriptor* const pHost;
  1401. #ifdef USE_REFCOUNTER_JUCE_MESSAGE_MANAGER
  1402. const bool kNeedsJuceEvents;
  1403. const juce::SharedResourcePointer<ReferenceCountedJuceMessageMessager> fJuceMsgMgr;
  1404. CarlaMutex fJuceMsgMutex;
  1405. struct ScopedJuceMessageThreadRunner {
  1406. const CarlaMutexTryLocker cmtl;
  1407. const bool wasLocked;
  1408. juce::MessageManager* msgMgr;
  1409. ScopedJuceMessageThreadRunner(CarlaEngineNative& self, const bool forceLock) noexcept
  1410. : cmtl(self.fJuceMsgMutex, forceLock),
  1411. wasLocked(cmtl.wasLocked()),
  1412. msgMgr(nullptr)
  1413. {
  1414. if (! self.kNeedsJuceEvents)
  1415. return;
  1416. if (! wasLocked)
  1417. return;
  1418. juce::MessageManager* const msgMgr2 = juce::MessageManager::getInstanceWithoutCreating();
  1419. CARLA_SAFE_ASSERT_RETURN(msgMgr2 != nullptr,);
  1420. if (! msgMgr2->isThisTheMessageThread())
  1421. {
  1422. try {
  1423. msgMgr2->setCurrentThreadAsMessageThread();
  1424. } CARLA_SAFE_EXCEPTION_RETURN("setCurrentThreadAsMessageThread",);
  1425. }
  1426. msgMgr = msgMgr2;
  1427. }
  1428. ~ScopedJuceMessageThreadRunner()
  1429. {
  1430. if (msgMgr == nullptr)
  1431. return;
  1432. const juce::MessageManagerLock mml;
  1433. for (; msgMgr->dispatchNextMessageOnSystemQueue(true);) {}
  1434. }
  1435. CARLA_DECLARE_NON_COPY_STRUCT(ScopedJuceMessageThreadRunner)
  1436. };
  1437. #endif
  1438. const bool kIsPatchbay; // rack if false
  1439. const bool kHasMidiOut;
  1440. bool fIsActive, fIsRunning, fUsesEmbed;
  1441. CarlaEngineNativeUI fUiServer;
  1442. float fParameters[kNumInParams+kNumOutParams];
  1443. float fLastScaleFactor;
  1444. CarlaString fLastProjectFolder;
  1445. CarlaMutex fPluginDeleterMutex;
  1446. bool fOptionsForced;
  1447. CarlaPluginPtr _getPluginForParameterIndex(uint32_t& index) const noexcept
  1448. {
  1449. if (pData->curPluginCount == 0 || pData->plugins == nullptr)
  1450. return nullptr;
  1451. for (uint32_t i=0; i<pData->curPluginCount; ++i)
  1452. {
  1453. const CarlaPluginPtr plugin = pData->plugins[i].plugin;
  1454. if (plugin.get() == nullptr || ! plugin->isEnabled())
  1455. break;
  1456. if (const uint32_t paramCount = plugin->getParameterCount())
  1457. {
  1458. if (index >= paramCount)
  1459. {
  1460. index -= paramCount;
  1461. continue;
  1462. }
  1463. return plugin;
  1464. }
  1465. }
  1466. return nullptr;
  1467. }
  1468. bool _getRealIndexForPluginParameter(const uint32_t pluginId, uint32_t& rindex) const noexcept
  1469. {
  1470. if (pData->curPluginCount == 0 || pluginId >= pData->curPluginCount || pData->plugins == nullptr)
  1471. return false;
  1472. for (uint32_t i=0; i<pluginId; ++i)
  1473. {
  1474. const CarlaPluginPtr plugin = pData->plugins[i].plugin;
  1475. if (plugin.get() == nullptr || ! plugin->isEnabled())
  1476. return false;
  1477. rindex += plugin->getParameterCount();
  1478. }
  1479. if (rindex >= kNumInParams)
  1480. return false;
  1481. return true;
  1482. }
  1483. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineNative)
  1484. };
  1485. // -----------------------------------------------------------------------
  1486. bool CarlaEngineNativeUI::msgReceived(const char* const msg) noexcept
  1487. {
  1488. if (CarlaExternalUI::msgReceived(msg))
  1489. return true;
  1490. bool ok = true;
  1491. if (std::strcmp(msg, "set_engine_option") == 0)
  1492. {
  1493. uint32_t option;
  1494. int32_t value;
  1495. const char* valueStr = nullptr;
  1496. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(option), true);
  1497. CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(value), true);
  1498. readNextLineAsString(valueStr, false); // can be null
  1499. try {
  1500. fEngine->setOption(static_cast<EngineOption>(option), value, valueStr);
  1501. } CARLA_SAFE_EXCEPTION("setOption");
  1502. }
  1503. else if (std::strcmp(msg, "clear_engine_xruns") == 0)
  1504. {
  1505. fEngine->clearXruns();
  1506. }
  1507. else if (std::strcmp(msg, "cancel_engine_action") == 0)
  1508. {
  1509. fEngine->setActionCanceled(true);
  1510. }
  1511. else if (std::strcmp(msg, "load_file") == 0)
  1512. {
  1513. const char* filename;
  1514. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename, false), true);
  1515. try {
  1516. ok = fEngine->loadFile(filename);
  1517. } CARLA_SAFE_EXCEPTION("loadFile");
  1518. fEngine->reloadFromUI();
  1519. }
  1520. else if (std::strcmp(msg, "load_project") == 0)
  1521. {
  1522. const char* filename;
  1523. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename, false), true);
  1524. try {
  1525. ok = fEngine->loadProject(filename, true);
  1526. } CARLA_SAFE_EXCEPTION("loadProject");
  1527. fEngine->reloadFromUI();
  1528. }
  1529. else if (std::strcmp(msg, "save_project") == 0)
  1530. {
  1531. const char* filename;
  1532. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename, false), true);
  1533. try {
  1534. ok = fEngine->saveProject(filename, true);
  1535. } CARLA_SAFE_EXCEPTION("saveProject");
  1536. }
  1537. else if (std::strcmp(msg, "clear_project_filename") == 0)
  1538. {
  1539. fEngine->clearCurrentProjectFilename();
  1540. }
  1541. else if (std::strcmp(msg, "patchbay_connect") == 0)
  1542. {
  1543. bool external;
  1544. uint32_t groupA, portA, groupB, portB;
  1545. CARLA_SAFE_ASSERT_RETURN(readNextLineAsBool(external), true);
  1546. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(groupA), true);
  1547. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(portA), true);
  1548. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(groupB), true);
  1549. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(portB), true);
  1550. try {
  1551. ok = fEngine->patchbayConnect(external, groupA, portA, groupB, portB);
  1552. } CARLA_SAFE_EXCEPTION("patchbayConnect");
  1553. }
  1554. else if (std::strcmp(msg, "patchbay_disconnect") == 0)
  1555. {
  1556. bool external;
  1557. uint32_t connectionId;
  1558. CARLA_SAFE_ASSERT_RETURN(readNextLineAsBool(external), true);
  1559. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(connectionId), true);
  1560. try {
  1561. ok = fEngine->patchbayDisconnect(external, connectionId);
  1562. } CARLA_SAFE_EXCEPTION("patchbayDisconnect");
  1563. }
  1564. else if (std::strcmp(msg, "patchbay_set_group_pos") == 0)
  1565. {
  1566. bool external;
  1567. uint32_t groupId;
  1568. int x1, y1, x2, y2;
  1569. CARLA_SAFE_ASSERT_RETURN(readNextLineAsBool(external), true);
  1570. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(groupId), true);
  1571. CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(x1), true);
  1572. CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(y1), true);
  1573. CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(x2), true);
  1574. CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(y2), true);
  1575. try {
  1576. ok = fEngine->patchbaySetGroupPos(false, true, external, groupId, x1, y1, x2, y2);
  1577. } CARLA_SAFE_EXCEPTION("patchbaySetGroupPos");
  1578. }
  1579. else if (std::strcmp(msg, "patchbay_refresh") == 0)
  1580. {
  1581. bool external;
  1582. CARLA_SAFE_ASSERT_RETURN(readNextLineAsBool(external), true);
  1583. try {
  1584. ok = fEngine->patchbayRefresh(true, false, external);
  1585. } CARLA_SAFE_EXCEPTION("patchbayRefresh");
  1586. }
  1587. else if (std::strcmp(msg, "transport_play") == 0)
  1588. {
  1589. fEngine->transportPlay();
  1590. }
  1591. else if (std::strcmp(msg, "transport_pause") == 0)
  1592. {
  1593. fEngine->transportPause();
  1594. }
  1595. else if (std::strcmp(msg, "transport_bpm") == 0)
  1596. {
  1597. double bpm;
  1598. CARLA_SAFE_ASSERT_RETURN(readNextLineAsDouble(bpm), true);
  1599. fEngine->transportBPM(bpm);
  1600. }
  1601. else if (std::strcmp(msg, "transport_relocate") == 0)
  1602. {
  1603. uint64_t frame;
  1604. CARLA_SAFE_ASSERT_RETURN(readNextLineAsULong(frame), true);
  1605. fEngine->transportRelocate(frame);
  1606. }
  1607. else if (std::strcmp(msg, "add_plugin") == 0)
  1608. {
  1609. uint32_t btype, ptype;
  1610. const char* filename = nullptr;
  1611. const char* name;
  1612. const char* label;
  1613. int64_t uniqueId;
  1614. uint options;
  1615. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(btype), true);
  1616. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(ptype), true);
  1617. readNextLineAsString(filename, true); // can be null
  1618. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(name, true), true);
  1619. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(label, true), true);
  1620. CARLA_SAFE_ASSERT_RETURN(readNextLineAsLong(uniqueId), true);
  1621. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(options), true);
  1622. if (filename != nullptr && std::strcmp(filename, "(null)") == 0)
  1623. {
  1624. delete[] filename;
  1625. filename = nullptr;
  1626. }
  1627. if (std::strcmp(name, "(null)") == 0)
  1628. {
  1629. delete[] name;
  1630. name = nullptr;
  1631. }
  1632. ok = fEngine->addPlugin(static_cast<BinaryType>(btype), static_cast<PluginType>(ptype),
  1633. filename, name, label, uniqueId, nullptr, options);
  1634. if (filename != nullptr)
  1635. delete[] filename;
  1636. if (name != nullptr)
  1637. delete[] name;
  1638. delete[] label;
  1639. fEngine->reloadFromUI();
  1640. }
  1641. else if (std::strcmp(msg, "remove_plugin") == 0)
  1642. {
  1643. uint32_t pluginId;
  1644. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1645. ok = fEngine->removePlugin(pluginId);
  1646. fEngine->reloadFromUI();
  1647. }
  1648. else if (std::strcmp(msg, "remove_all_plugins") == 0)
  1649. {
  1650. ok = fEngine->removeAllPlugins();
  1651. fEngine->reloadFromUI();
  1652. }
  1653. else if (std::strcmp(msg, "rename_plugin") == 0)
  1654. {
  1655. uint32_t pluginId;
  1656. const char* newName;
  1657. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1658. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(newName, false), true);
  1659. ok = fEngine->renamePlugin(pluginId, newName);
  1660. }
  1661. else if (std::strcmp(msg, "clone_plugin") == 0)
  1662. {
  1663. uint32_t pluginId;
  1664. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1665. ok = fEngine->clonePlugin(pluginId);
  1666. fEngine->reloadFromUI();
  1667. }
  1668. else if (std::strcmp(msg, "replace_plugin") == 0)
  1669. {
  1670. uint32_t pluginId;
  1671. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1672. ok = fEngine->replacePlugin(pluginId);
  1673. }
  1674. else if (std::strcmp(msg, "switch_plugins") == 0)
  1675. {
  1676. uint32_t pluginIdA, pluginIdB;
  1677. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginIdA), true);
  1678. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginIdB), true);
  1679. ok = fEngine->switchPlugins(pluginIdA, pluginIdB);
  1680. fEngine->reloadFromUI();
  1681. }
  1682. else if (std::strcmp(msg, "load_plugin_state") == 0)
  1683. {
  1684. uint32_t pluginId;
  1685. const char* filename;
  1686. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1687. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename, false), true);
  1688. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1689. {
  1690. plugin->loadStateFromFile(filename);
  1691. _updateParamValues(plugin, pluginId, false, true);
  1692. }
  1693. }
  1694. else if (std::strcmp(msg, "save_plugin_state") == 0)
  1695. {
  1696. uint32_t pluginId;
  1697. const char* filename;
  1698. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1699. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename, false), true);
  1700. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1701. plugin->saveStateToFile(filename);
  1702. }
  1703. else if (std::strcmp(msg, "set_option") == 0)
  1704. {
  1705. uint32_t pluginId, option;
  1706. bool yesNo;
  1707. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1708. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(option), true);
  1709. CARLA_SAFE_ASSERT_RETURN(readNextLineAsBool(yesNo), true);
  1710. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1711. plugin->setOption(option, yesNo, false);
  1712. }
  1713. else if (std::strcmp(msg, "set_active") == 0)
  1714. {
  1715. uint32_t pluginId;
  1716. bool onOff;
  1717. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1718. CARLA_SAFE_ASSERT_RETURN(readNextLineAsBool(onOff), true);
  1719. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1720. plugin->setActive(onOff, true, false);
  1721. }
  1722. else if (std::strcmp(msg, "set_drywet") == 0)
  1723. {
  1724. uint32_t pluginId;
  1725. float value;
  1726. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1727. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(value), true);
  1728. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1729. plugin->setDryWet(value, true, false);
  1730. }
  1731. else if (std::strcmp(msg, "set_volume") == 0)
  1732. {
  1733. uint32_t pluginId;
  1734. float value;
  1735. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1736. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(value), true);
  1737. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1738. plugin->setVolume(value, true, false);
  1739. }
  1740. else if (std::strcmp(msg, "set_balance_left") == 0)
  1741. {
  1742. uint32_t pluginId;
  1743. float value;
  1744. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1745. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(value), true);
  1746. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1747. plugin->setBalanceLeft(value, true, false);
  1748. }
  1749. else if (std::strcmp(msg, "set_balance_right") == 0)
  1750. {
  1751. uint32_t pluginId;
  1752. float value;
  1753. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1754. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(value), true);
  1755. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1756. plugin->setBalanceRight(value, true, false);
  1757. }
  1758. else if (std::strcmp(msg, "set_panning") == 0)
  1759. {
  1760. uint32_t pluginId;
  1761. float value;
  1762. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1763. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(value), true);
  1764. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1765. plugin->setPanning(value, true, false);
  1766. }
  1767. else if (std::strcmp(msg, "set_ctrl_channel") == 0)
  1768. {
  1769. uint32_t pluginId;
  1770. int32_t channel;
  1771. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1772. CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(channel), true);
  1773. CARLA_SAFE_ASSERT_RETURN(channel >= -1 && channel < MAX_MIDI_CHANNELS, true);
  1774. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1775. plugin->setCtrlChannel(int8_t(channel), true, false);
  1776. }
  1777. else if (std::strcmp(msg, "set_parameter_value") == 0)
  1778. {
  1779. uint32_t pluginId, parameterId;
  1780. float value;
  1781. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1782. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(parameterId), true);
  1783. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(value), true);
  1784. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1785. {
  1786. plugin->setParameterValue(parameterId, value, true, true, false);
  1787. fEngine->setParameterValueFromUI(pluginId, parameterId, value);
  1788. }
  1789. }
  1790. else if (std::strcmp(msg, "set_parameter_midi_channel") == 0)
  1791. {
  1792. uint32_t pluginId, parameterId, channel;
  1793. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1794. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(parameterId), true);
  1795. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(channel), true);
  1796. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS, true);
  1797. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1798. plugin->setParameterMidiChannel(parameterId, static_cast<uint8_t>(channel), true, false);
  1799. }
  1800. else if (std::strcmp(msg, "set_parameter_mapped_control_index") == 0)
  1801. {
  1802. uint32_t pluginId, parameterId;
  1803. int32_t ctrl;
  1804. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1805. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(parameterId), true);
  1806. CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(ctrl), true);
  1807. CARLA_SAFE_ASSERT_RETURN(ctrl >= CONTROL_INDEX_NONE && ctrl <= CONTROL_INDEX_MAX_ALLOWED, true);
  1808. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1809. plugin->setParameterMappedControlIndex(parameterId, static_cast<int16_t>(ctrl), true, false, true);
  1810. }
  1811. else if (std::strcmp(msg, "set_parameter_mapped_range") == 0)
  1812. {
  1813. uint32_t pluginId, parameterId;
  1814. float minimum, maximum;
  1815. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1816. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(parameterId), true);
  1817. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(minimum), true);
  1818. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(maximum), true);
  1819. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1820. plugin->setParameterMappedRange(parameterId, minimum, maximum, true, false);
  1821. }
  1822. else if (std::strcmp(msg, "set_parameter_touch") == 0)
  1823. {
  1824. uint32_t pluginId, parameterId;
  1825. bool touching;
  1826. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1827. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(parameterId), true);
  1828. CARLA_SAFE_ASSERT_RETURN(readNextLineAsBool(touching), true);
  1829. if (fEngine->getPlugin(pluginId))
  1830. fEngine->setParameterTouchFromUI(pluginId, parameterId, touching);
  1831. }
  1832. else if (std::strcmp(msg, "set_program") == 0)
  1833. {
  1834. uint32_t pluginId;
  1835. int32_t index;
  1836. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1837. CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(index), true);
  1838. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1839. {
  1840. plugin->setProgram(index, true, true, false);
  1841. _updateParamValues(plugin, pluginId, true, true);
  1842. }
  1843. }
  1844. else if (std::strcmp(msg, "set_midi_program") == 0)
  1845. {
  1846. uint32_t pluginId;
  1847. int32_t index;
  1848. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1849. CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(index), true);
  1850. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1851. {
  1852. plugin->setMidiProgram(index, true, true, false);
  1853. _updateParamValues(plugin, pluginId, true, true);
  1854. }
  1855. }
  1856. else if (std::strcmp(msg, "set_custom_data") == 0)
  1857. {
  1858. uint32_t pluginId;
  1859. const char* type;
  1860. const char* key;
  1861. const char* value;
  1862. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1863. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(type, true), true);
  1864. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(key, true), true);
  1865. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(value, false), true);
  1866. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1867. plugin->setCustomData(type, key, value, true);
  1868. delete[] type;
  1869. delete[] key;
  1870. }
  1871. else if (std::strcmp(msg, "set_chunk_data") == 0)
  1872. {
  1873. uint32_t pluginId;
  1874. const char* cdata;
  1875. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1876. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(cdata, false), true);
  1877. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1878. {
  1879. std::vector<uint8_t> chunk(carla_getChunkFromBase64String(cdata));
  1880. #ifdef CARLA_PROPER_CPP11_SUPPORT
  1881. plugin->setChunkData(chunk.data(), chunk.size());
  1882. #else
  1883. plugin->setChunkData(&chunk.front(), chunk.size());
  1884. #endif
  1885. _updateParamValues(plugin, pluginId, false, true);
  1886. }
  1887. }
  1888. else if (std::strcmp(msg, "prepare_for_save") == 0)
  1889. {
  1890. uint32_t pluginId;
  1891. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1892. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1893. plugin->prepareForSave(false);
  1894. }
  1895. else if (std::strcmp(msg, "reset_parameters") == 0)
  1896. {
  1897. uint32_t pluginId;
  1898. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1899. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1900. {
  1901. plugin->resetParameters();
  1902. _updateParamValues(plugin, pluginId, false, true);
  1903. }
  1904. }
  1905. else if (std::strcmp(msg, "randomize_parameters") == 0)
  1906. {
  1907. uint32_t pluginId;
  1908. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1909. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1910. {
  1911. plugin->randomizeParameters();
  1912. _updateParamValues(plugin, pluginId, false, true);
  1913. }
  1914. }
  1915. else if (std::strcmp(msg, "send_midi_note") == 0)
  1916. {
  1917. uint32_t pluginId, channel, note, velocity;
  1918. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1919. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(channel), true);
  1920. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(note), true);
  1921. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(velocity), true);
  1922. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS, true);
  1923. CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_VALUE, true);
  1924. CARLA_SAFE_ASSERT_RETURN(velocity < MAX_MIDI_VALUE, true);
  1925. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1926. plugin->sendMidiSingleNote(static_cast<uint8_t>(channel), static_cast<uint8_t>(note), static_cast<uint8_t>(velocity), true, true, false);
  1927. }
  1928. else if (std::strcmp(msg, "show_custom_ui") == 0)
  1929. {
  1930. uint32_t pluginId;
  1931. bool yesNo;
  1932. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  1933. CARLA_SAFE_ASSERT_RETURN(readNextLineAsBool(yesNo), true);
  1934. if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId))
  1935. plugin->showCustomUI(yesNo);
  1936. }
  1937. else
  1938. {
  1939. carla_stderr("CarlaEngineNativeUI::msgReceived : %s", msg);
  1940. return false;
  1941. }
  1942. if (! ok)
  1943. {
  1944. const CarlaMutexLocker cml(getPipeLock());
  1945. if (writeMessage("error\n", 6) && writeAndFixMessage(fEngine->getLastError()))
  1946. flushMessages();
  1947. }
  1948. return true;
  1949. }
  1950. void CarlaEngineNativeUI::_updateParamValues(const CarlaPluginPtr& plugin,
  1951. const uint32_t pluginId,
  1952. const bool sendCallback, const bool sendPluginHost) const noexcept
  1953. {
  1954. float value;
  1955. for (uint32_t i=0, count=plugin->getParameterCount(); i<count; ++i) {
  1956. value = plugin->getParameterValue(i);
  1957. if (sendCallback) {
  1958. fEngine->callback(true, true,
  1959. ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
  1960. pluginId,
  1961. static_cast<int>(i),
  1962. 0, 0,
  1963. value,
  1964. nullptr);
  1965. }
  1966. if (sendPluginHost) {
  1967. carla_stdout("_updateParamValues");
  1968. fEngine->setParameterValueFromUI(pluginId, i, value);
  1969. }
  1970. }
  1971. }
  1972. // -----------------------------------------------------------------------
  1973. static const NativePluginDescriptor carlaRackDesc = {
  1974. /* category */ NATIVE_PLUGIN_CATEGORY_OTHER,
  1975. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_SYNTH
  1976. |NATIVE_PLUGIN_HAS_UI
  1977. |NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
  1978. |NATIVE_PLUGIN_USES_STATE
  1979. |NATIVE_PLUGIN_USES_TIME
  1980. |NATIVE_PLUGIN_USES_UI_SIZE),
  1981. /* supports */ static_cast<NativePluginSupports>(NATIVE_PLUGIN_SUPPORTS_EVERYTHING),
  1982. /* audioIns */ 2,
  1983. /* audioOuts */ 2,
  1984. /* midiIns */ 1,
  1985. /* midiOuts */ 1,
  1986. /* paramIns */ kNumInParams,
  1987. /* paramOuts */ kNumOutParams,
  1988. /* name */ "Carla-Rack",
  1989. /* label */ "carlarack",
  1990. /* maker */ "falkTX",
  1991. /* copyright */ "GNU GPL v2+",
  1992. CarlaEngineNative::_instantiateRack,
  1993. CarlaEngineNative::_cleanup,
  1994. CarlaEngineNative::_get_parameter_count,
  1995. CarlaEngineNative::_get_parameter_info,
  1996. CarlaEngineNative::_get_parameter_value,
  1997. /* _get_midi_program_count */ nullptr,
  1998. /* _get_midi_program_info */ nullptr,
  1999. CarlaEngineNative::_set_parameter_value,
  2000. /* _set_midi_program */ nullptr,
  2001. /* _set_custom_data */ nullptr,
  2002. CarlaEngineNative::_ui_show,
  2003. CarlaEngineNative::_ui_idle,
  2004. CarlaEngineNative::_ui_set_parameter_value,
  2005. /* _ui_set_midi_program */ nullptr,
  2006. /* _ui_set_custom_data */ nullptr,
  2007. CarlaEngineNative::_activate,
  2008. CarlaEngineNative::_deactivate,
  2009. CarlaEngineNative::_process,
  2010. CarlaEngineNative::_get_state,
  2011. CarlaEngineNative::_set_state,
  2012. CarlaEngineNative::_dispatcher,
  2013. /* _render_inline_dsplay */ nullptr,
  2014. /* cvIns */ 0,
  2015. /* cvOuts */ 0,
  2016. /* _get_buffer_port_name */ nullptr,
  2017. /* _get_buffer_port_range */ nullptr,
  2018. /* ui_width */ kUiWidth,
  2019. /* ui_height */ kUiHeight
  2020. };
  2021. static const NativePluginDescriptor carlaRackNoMidiOutDesc = {
  2022. /* category */ NATIVE_PLUGIN_CATEGORY_OTHER,
  2023. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_SYNTH
  2024. |NATIVE_PLUGIN_HAS_UI
  2025. |NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
  2026. |NATIVE_PLUGIN_USES_STATE
  2027. |NATIVE_PLUGIN_USES_TIME
  2028. |NATIVE_PLUGIN_USES_UI_SIZE),
  2029. /* supports */ static_cast<NativePluginSupports>(NATIVE_PLUGIN_SUPPORTS_EVERYTHING),
  2030. /* audioIns */ 2,
  2031. /* audioOuts */ 2,
  2032. /* midiIns */ 1,
  2033. /* midiOuts */ 0,
  2034. /* paramIns */ kNumInParams,
  2035. /* paramOuts */ kNumOutParams,
  2036. /* name */ "Carla-Rack (no midi out)",
  2037. /* label */ "carlarack-nomidiout",
  2038. /* maker */ "falkTX",
  2039. /* copyright */ "GNU GPL v2+",
  2040. CarlaEngineNative::_instantiateRackNoMidiOut,
  2041. CarlaEngineNative::_cleanup,
  2042. CarlaEngineNative::_get_parameter_count,
  2043. CarlaEngineNative::_get_parameter_info,
  2044. CarlaEngineNative::_get_parameter_value,
  2045. /* _get_midi_program_count */ nullptr,
  2046. /* _get_midi_program_info */ nullptr,
  2047. CarlaEngineNative::_set_parameter_value,
  2048. /* _set_midi_program */ nullptr,
  2049. /* _set_custom_data */ nullptr,
  2050. CarlaEngineNative::_ui_show,
  2051. CarlaEngineNative::_ui_idle,
  2052. CarlaEngineNative::_ui_set_parameter_value,
  2053. /* _ui_set_midi_program */ nullptr,
  2054. /* _ui_set_custom_data */ nullptr,
  2055. CarlaEngineNative::_activate,
  2056. CarlaEngineNative::_deactivate,
  2057. CarlaEngineNative::_process,
  2058. CarlaEngineNative::_get_state,
  2059. CarlaEngineNative::_set_state,
  2060. CarlaEngineNative::_dispatcher,
  2061. /* _render_inline_dsplay */ nullptr,
  2062. /* cvIns */ 0,
  2063. /* cvOuts */ 0,
  2064. /* _get_buffer_port_name */ nullptr,
  2065. /* _get_buffer_port_range */ nullptr,
  2066. /* ui_width */ kUiWidth,
  2067. /* ui_height */ kUiHeight
  2068. };
  2069. static const NativePluginDescriptor carlaPatchbayDesc = {
  2070. /* category */ NATIVE_PLUGIN_CATEGORY_OTHER,
  2071. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_SYNTH
  2072. |NATIVE_PLUGIN_HAS_UI
  2073. |NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
  2074. |NATIVE_PLUGIN_USES_STATE
  2075. |NATIVE_PLUGIN_USES_TIME
  2076. |NATIVE_PLUGIN_USES_UI_SIZE),
  2077. /* supports */ static_cast<NativePluginSupports>(NATIVE_PLUGIN_SUPPORTS_EVERYTHING),
  2078. /* audioIns */ 2,
  2079. /* audioOuts */ 2,
  2080. /* midiIns */ 1,
  2081. /* midiOuts */ 1,
  2082. /* paramIns */ kNumInParams,
  2083. /* paramOuts */ kNumOutParams,
  2084. /* name */ "Carla-Patchbay",
  2085. /* label */ "carlapatchbay",
  2086. /* maker */ "falkTX",
  2087. /* copyright */ "GNU GPL v2+",
  2088. CarlaEngineNative::_instantiatePatchbay,
  2089. CarlaEngineNative::_cleanup,
  2090. CarlaEngineNative::_get_parameter_count,
  2091. CarlaEngineNative::_get_parameter_info,
  2092. CarlaEngineNative::_get_parameter_value,
  2093. /* _get_midi_program_count */ nullptr,
  2094. /* _get_midi_program_info */ nullptr,
  2095. CarlaEngineNative::_set_parameter_value,
  2096. /* _set_midi_program */ nullptr,
  2097. /* _set_custom_data */ nullptr,
  2098. CarlaEngineNative::_ui_show,
  2099. CarlaEngineNative::_ui_idle,
  2100. CarlaEngineNative::_ui_set_parameter_value,
  2101. /* _ui_set_midi_program */ nullptr,
  2102. /* _ui_set_custom_data */ nullptr,
  2103. CarlaEngineNative::_activate,
  2104. CarlaEngineNative::_deactivate,
  2105. CarlaEngineNative::_process,
  2106. CarlaEngineNative::_get_state,
  2107. CarlaEngineNative::_set_state,
  2108. CarlaEngineNative::_dispatcher,
  2109. /* _render_inline_dsplay */ nullptr,
  2110. /* cvIns */ 0,
  2111. /* cvOuts */ 0,
  2112. /* _get_buffer_port_name */ nullptr,
  2113. /* _get_buffer_port_range */ nullptr,
  2114. /* ui_width */ kUiWidth,
  2115. /* ui_height */ kUiHeight
  2116. };
  2117. static const NativePluginDescriptor carlaPatchbay3sDesc = {
  2118. /* category */ NATIVE_PLUGIN_CATEGORY_OTHER,
  2119. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_SYNTH
  2120. |NATIVE_PLUGIN_HAS_UI
  2121. |NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
  2122. |NATIVE_PLUGIN_USES_STATE
  2123. |NATIVE_PLUGIN_USES_TIME
  2124. |NATIVE_PLUGIN_USES_UI_SIZE),
  2125. /* supports */ static_cast<NativePluginSupports>(NATIVE_PLUGIN_SUPPORTS_EVERYTHING),
  2126. /* audioIns */ 3,
  2127. /* audioOuts */ 2,
  2128. /* midiIns */ 1,
  2129. /* midiOuts */ 1,
  2130. /* paramIns */ kNumInParams,
  2131. /* paramOuts */ kNumOutParams,
  2132. /* name */ "Carla-Patchbay (sidechain)",
  2133. /* label */ "carlapatchbay3s",
  2134. /* maker */ "falkTX",
  2135. /* copyright */ "GNU GPL v2+",
  2136. CarlaEngineNative::_instantiatePatchbay3s,
  2137. CarlaEngineNative::_cleanup,
  2138. CarlaEngineNative::_get_parameter_count,
  2139. CarlaEngineNative::_get_parameter_info,
  2140. CarlaEngineNative::_get_parameter_value,
  2141. /* _get_midi_program_count */ nullptr,
  2142. /* _get_midi_program_info */ nullptr,
  2143. CarlaEngineNative::_set_parameter_value,
  2144. /* _set_midi_program */ nullptr,
  2145. /* _set_custom_data */ nullptr,
  2146. CarlaEngineNative::_ui_show,
  2147. CarlaEngineNative::_ui_idle,
  2148. CarlaEngineNative::_ui_set_parameter_value,
  2149. /* _ui_set_midi_program */ nullptr,
  2150. /* _ui_set_custom_data */ nullptr,
  2151. CarlaEngineNative::_activate,
  2152. CarlaEngineNative::_deactivate,
  2153. CarlaEngineNative::_process,
  2154. CarlaEngineNative::_get_state,
  2155. CarlaEngineNative::_set_state,
  2156. CarlaEngineNative::_dispatcher,
  2157. /* _render_inline_dsplay */ nullptr,
  2158. /* cvIns */ 0,
  2159. /* cvOuts */ 0,
  2160. /* _get_buffer_port_name */ nullptr,
  2161. /* _get_buffer_port_range */ nullptr,
  2162. /* ui_width */ kUiWidth,
  2163. /* ui_height */ kUiHeight
  2164. };
  2165. static const NativePluginDescriptor carlaPatchbay16Desc = {
  2166. /* category */ NATIVE_PLUGIN_CATEGORY_OTHER,
  2167. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_SYNTH
  2168. |NATIVE_PLUGIN_HAS_UI
  2169. |NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
  2170. |NATIVE_PLUGIN_USES_STATE
  2171. |NATIVE_PLUGIN_USES_TIME
  2172. |NATIVE_PLUGIN_USES_UI_SIZE),
  2173. /* supports */ static_cast<NativePluginSupports>(NATIVE_PLUGIN_SUPPORTS_EVERYTHING),
  2174. /* audioIns */ 16,
  2175. /* audioOuts */ 16,
  2176. /* midiIns */ 1,
  2177. /* midiOuts */ 1,
  2178. /* paramIns */ kNumInParams,
  2179. /* paramOuts */ kNumOutParams,
  2180. /* name */ "Carla-Patchbay (16chan)",
  2181. /* label */ "carlapatchbay16",
  2182. /* maker */ "falkTX",
  2183. /* copyright */ "GNU GPL v2+",
  2184. CarlaEngineNative::_instantiatePatchbay16,
  2185. CarlaEngineNative::_cleanup,
  2186. CarlaEngineNative::_get_parameter_count,
  2187. CarlaEngineNative::_get_parameter_info,
  2188. CarlaEngineNative::_get_parameter_value,
  2189. /* _get_midi_program_count */ nullptr,
  2190. /* _get_midi_program_info */ nullptr,
  2191. CarlaEngineNative::_set_parameter_value,
  2192. /* _set_midi_program */ nullptr,
  2193. /* _set_custom_data */ nullptr,
  2194. CarlaEngineNative::_ui_show,
  2195. CarlaEngineNative::_ui_idle,
  2196. CarlaEngineNative::_ui_set_parameter_value,
  2197. /* _ui_set_midi_program */ nullptr,
  2198. /* _ui_set_custom_data */ nullptr,
  2199. CarlaEngineNative::_activate,
  2200. CarlaEngineNative::_deactivate,
  2201. CarlaEngineNative::_process,
  2202. CarlaEngineNative::_get_state,
  2203. CarlaEngineNative::_set_state,
  2204. CarlaEngineNative::_dispatcher,
  2205. /* _render_inline_dsplay */ nullptr,
  2206. /* cvIns */ 0,
  2207. /* cvOuts */ 0,
  2208. /* _get_buffer_port_name */ nullptr,
  2209. /* _get_buffer_port_range */ nullptr,
  2210. /* ui_width */ kUiWidth,
  2211. /* ui_height */ kUiHeight
  2212. };
  2213. static const NativePluginDescriptor carlaPatchbay32Desc = {
  2214. /* category */ NATIVE_PLUGIN_CATEGORY_OTHER,
  2215. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_SYNTH
  2216. |NATIVE_PLUGIN_HAS_UI
  2217. |NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
  2218. |NATIVE_PLUGIN_USES_STATE
  2219. |NATIVE_PLUGIN_USES_TIME
  2220. |NATIVE_PLUGIN_USES_UI_SIZE),
  2221. /* supports */ static_cast<NativePluginSupports>(NATIVE_PLUGIN_SUPPORTS_EVERYTHING),
  2222. /* audioIns */ 32,
  2223. /* audioOuts */ 32,
  2224. /* midiIns */ 1,
  2225. /* midiOuts */ 1,
  2226. /* paramIns */ kNumInParams,
  2227. /* paramOuts */ kNumOutParams,
  2228. /* name */ "Carla-Patchbay (32chan)",
  2229. /* label */ "carlapatchbay32",
  2230. /* maker */ "falkTX",
  2231. /* copyright */ "GNU GPL v2+",
  2232. CarlaEngineNative::_instantiatePatchbay32,
  2233. CarlaEngineNative::_cleanup,
  2234. CarlaEngineNative::_get_parameter_count,
  2235. CarlaEngineNative::_get_parameter_info,
  2236. CarlaEngineNative::_get_parameter_value,
  2237. /* _get_midi_program_count */ nullptr,
  2238. /* _get_midi_program_info */ nullptr,
  2239. CarlaEngineNative::_set_parameter_value,
  2240. /* _set_midi_program */ nullptr,
  2241. /* _set_custom_data */ nullptr,
  2242. CarlaEngineNative::_ui_show,
  2243. CarlaEngineNative::_ui_idle,
  2244. CarlaEngineNative::_ui_set_parameter_value,
  2245. /* _ui_set_midi_program */ nullptr,
  2246. /* _ui_set_custom_data */ nullptr,
  2247. CarlaEngineNative::_activate,
  2248. CarlaEngineNative::_deactivate,
  2249. CarlaEngineNative::_process,
  2250. CarlaEngineNative::_get_state,
  2251. CarlaEngineNative::_set_state,
  2252. CarlaEngineNative::_dispatcher,
  2253. /* _render_inline_dsplay */ nullptr,
  2254. /* cvIns */ 0,
  2255. /* cvOuts */ 0,
  2256. /* _get_buffer_port_name */ nullptr,
  2257. /* _get_buffer_port_range */ nullptr,
  2258. /* ui_width */ kUiWidth,
  2259. /* ui_height */ kUiHeight
  2260. };
  2261. static const NativePluginDescriptor carlaPatchbay64Desc = {
  2262. /* category */ NATIVE_PLUGIN_CATEGORY_OTHER,
  2263. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_SYNTH
  2264. |NATIVE_PLUGIN_HAS_UI
  2265. |NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
  2266. |NATIVE_PLUGIN_USES_STATE
  2267. |NATIVE_PLUGIN_USES_TIME
  2268. |NATIVE_PLUGIN_USES_UI_SIZE),
  2269. /* supports */ static_cast<NativePluginSupports>(NATIVE_PLUGIN_SUPPORTS_EVERYTHING),
  2270. /* audioIns */ 64,
  2271. /* audioOuts */ 64,
  2272. /* midiIns */ 1,
  2273. /* midiOuts */ 1,
  2274. /* paramIns */ kNumInParams,
  2275. /* paramOuts */ kNumOutParams,
  2276. /* name */ "Carla-Patchbay (64chan)",
  2277. /* label */ "carlapatchbay64",
  2278. /* maker */ "falkTX",
  2279. /* copyright */ "GNU GPL v2+",
  2280. CarlaEngineNative::_instantiatePatchbay64,
  2281. CarlaEngineNative::_cleanup,
  2282. CarlaEngineNative::_get_parameter_count,
  2283. CarlaEngineNative::_get_parameter_info,
  2284. CarlaEngineNative::_get_parameter_value,
  2285. /* _get_midi_program_count */ nullptr,
  2286. /* _get_midi_program_info */ nullptr,
  2287. CarlaEngineNative::_set_parameter_value,
  2288. /* _set_midi_program */ nullptr,
  2289. /* _set_custom_data */ nullptr,
  2290. CarlaEngineNative::_ui_show,
  2291. CarlaEngineNative::_ui_idle,
  2292. CarlaEngineNative::_ui_set_parameter_value,
  2293. /* _ui_set_midi_program */ nullptr,
  2294. /* _ui_set_custom_data */ nullptr,
  2295. CarlaEngineNative::_activate,
  2296. CarlaEngineNative::_deactivate,
  2297. CarlaEngineNative::_process,
  2298. CarlaEngineNative::_get_state,
  2299. CarlaEngineNative::_set_state,
  2300. CarlaEngineNative::_dispatcher,
  2301. /* _render_inline_dsplay */ nullptr,
  2302. /* cvIns */ 0,
  2303. /* cvOuts */ 0,
  2304. /* _get_buffer_port_name */ nullptr,
  2305. /* _get_buffer_port_range */ nullptr,
  2306. /* ui_width */ kUiWidth,
  2307. /* ui_height */ kUiHeight
  2308. };
  2309. static const NativePluginDescriptor carlaPatchbayCVDesc = {
  2310. /* category */ NATIVE_PLUGIN_CATEGORY_OTHER,
  2311. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_SYNTH
  2312. |NATIVE_PLUGIN_HAS_UI
  2313. |NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
  2314. |NATIVE_PLUGIN_USES_CONTROL_VOLTAGE
  2315. |NATIVE_PLUGIN_USES_STATE
  2316. |NATIVE_PLUGIN_USES_TIME
  2317. |NATIVE_PLUGIN_USES_UI_SIZE),
  2318. /* supports */ static_cast<NativePluginSupports>(NATIVE_PLUGIN_SUPPORTS_EVERYTHING),
  2319. /* audioIns */ 2,
  2320. /* audioOuts */ 2,
  2321. /* midiIns */ 1,
  2322. /* midiOuts */ 1,
  2323. /* paramIns */ kNumInParams,
  2324. /* paramOuts */ kNumOutParams,
  2325. /* name */ "Carla-Patchbay (CV)",
  2326. /* label */ "carlapatchbaycv",
  2327. /* maker */ "falkTX",
  2328. /* copyright */ "GNU GPL v2+",
  2329. CarlaEngineNative::_instantiatePatchbayCV,
  2330. CarlaEngineNative::_cleanup,
  2331. CarlaEngineNative::_get_parameter_count,
  2332. CarlaEngineNative::_get_parameter_info,
  2333. CarlaEngineNative::_get_parameter_value,
  2334. /* _get_midi_program_count */ nullptr,
  2335. /* _get_midi_program_info */ nullptr,
  2336. CarlaEngineNative::_set_parameter_value,
  2337. /* _set_midi_program */ nullptr,
  2338. /* _set_custom_data */ nullptr,
  2339. CarlaEngineNative::_ui_show,
  2340. CarlaEngineNative::_ui_idle,
  2341. CarlaEngineNative::_ui_set_parameter_value,
  2342. /* _ui_set_midi_program */ nullptr,
  2343. /* _ui_set_custom_data */ nullptr,
  2344. CarlaEngineNative::_activate,
  2345. CarlaEngineNative::_deactivate,
  2346. CarlaEngineNative::_process,
  2347. CarlaEngineNative::_get_state,
  2348. CarlaEngineNative::_set_state,
  2349. CarlaEngineNative::_dispatcher,
  2350. /* _render_inline_dsplay */ nullptr,
  2351. /* cvIns */ 5,
  2352. /* cvOuts */ 5,
  2353. /* _get_buffer_port_name */ nullptr,
  2354. /* _get_buffer_port_range */ nullptr,
  2355. /* ui_width */ kUiWidth,
  2356. /* ui_height */ kUiHeight
  2357. };
  2358. static const NativePluginDescriptor carlaPatchbayCV8Desc = {
  2359. /* category */ NATIVE_PLUGIN_CATEGORY_OTHER,
  2360. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_SYNTH
  2361. |NATIVE_PLUGIN_HAS_UI
  2362. |NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
  2363. |NATIVE_PLUGIN_USES_CONTROL_VOLTAGE
  2364. |NATIVE_PLUGIN_USES_STATE
  2365. |NATIVE_PLUGIN_USES_TIME
  2366. |NATIVE_PLUGIN_USES_UI_SIZE),
  2367. /* supports */ static_cast<NativePluginSupports>(NATIVE_PLUGIN_SUPPORTS_EVERYTHING),
  2368. /* audioIns */ 2,
  2369. /* audioOuts */ 2,
  2370. /* midiIns */ 1,
  2371. /* midiOuts */ 1,
  2372. /* paramIns */ kNumInParams,
  2373. /* paramOuts */ kNumOutParams,
  2374. /* name */ "Carla-Patchbay (CV8)",
  2375. /* label */ "carlapatchbaycv",
  2376. /* maker */ "falkTX",
  2377. /* copyright */ "GNU GPL v2+",
  2378. CarlaEngineNative::_instantiatePatchbayCV8,
  2379. CarlaEngineNative::_cleanup,
  2380. CarlaEngineNative::_get_parameter_count,
  2381. CarlaEngineNative::_get_parameter_info,
  2382. CarlaEngineNative::_get_parameter_value,
  2383. /* _get_midi_program_count */ nullptr,
  2384. /* _get_midi_program_info */ nullptr,
  2385. CarlaEngineNative::_set_parameter_value,
  2386. /* _set_midi_program */ nullptr,
  2387. /* _set_custom_data */ nullptr,
  2388. CarlaEngineNative::_ui_show,
  2389. CarlaEngineNative::_ui_idle,
  2390. CarlaEngineNative::_ui_set_parameter_value,
  2391. /* _ui_set_midi_program */ nullptr,
  2392. /* _ui_set_custom_data */ nullptr,
  2393. CarlaEngineNative::_activate,
  2394. CarlaEngineNative::_deactivate,
  2395. CarlaEngineNative::_process,
  2396. CarlaEngineNative::_get_state,
  2397. CarlaEngineNative::_set_state,
  2398. CarlaEngineNative::_dispatcher,
  2399. /* _render_inline_dsplay */ nullptr,
  2400. /* cvIns */ 8,
  2401. /* cvOuts */ 8,
  2402. /* _get_buffer_port_name */ nullptr,
  2403. /* _get_buffer_port_range */ nullptr,
  2404. /* ui_width */ kUiWidth,
  2405. /* ui_height */ kUiHeight
  2406. };
  2407. CARLA_BACKEND_END_NAMESPACE
  2408. // -----------------------------------------------------------------------
  2409. CARLA_EXPORT
  2410. void carla_register_native_plugin_carla();
  2411. void carla_register_native_plugin_carla()
  2412. {
  2413. CARLA_BACKEND_USE_NAMESPACE;
  2414. carla_register_native_plugin(&carlaRackDesc);
  2415. carla_register_native_plugin(&carlaRackNoMidiOutDesc);
  2416. carla_register_native_plugin(&carlaPatchbayDesc);
  2417. carla_register_native_plugin(&carlaPatchbay3sDesc);
  2418. carla_register_native_plugin(&carlaPatchbay16Desc);
  2419. carla_register_native_plugin(&carlaPatchbay32Desc);
  2420. carla_register_native_plugin(&carlaPatchbay64Desc);
  2421. carla_register_native_plugin(&carlaPatchbayCVDesc);
  2422. }
  2423. // -----------------------------------------------------------------------
  2424. const NativePluginDescriptor* carla_get_native_rack_plugin()
  2425. {
  2426. CARLA_BACKEND_USE_NAMESPACE;
  2427. return &carlaRackDesc;
  2428. }
  2429. const NativePluginDescriptor* carla_get_native_patchbay_plugin()
  2430. {
  2431. CARLA_BACKEND_USE_NAMESPACE;
  2432. return &carlaPatchbayDesc;
  2433. }
  2434. const NativePluginDescriptor* carla_get_native_patchbay16_plugin()
  2435. {
  2436. CARLA_BACKEND_USE_NAMESPACE;
  2437. return &carlaPatchbay16Desc;
  2438. }
  2439. const NativePluginDescriptor* carla_get_native_patchbay32_plugin()
  2440. {
  2441. CARLA_BACKEND_USE_NAMESPACE;
  2442. return &carlaPatchbay32Desc;
  2443. }
  2444. const NativePluginDescriptor* carla_get_native_patchbay64_plugin()
  2445. {
  2446. CARLA_BACKEND_USE_NAMESPACE;
  2447. return &carlaPatchbay64Desc;
  2448. }
  2449. const NativePluginDescriptor* carla_get_native_patchbay_cv_plugin()
  2450. {
  2451. CARLA_BACKEND_USE_NAMESPACE;
  2452. return &carlaPatchbayCVDesc;
  2453. }
  2454. const NativePluginDescriptor* carla_get_native_patchbay_cv8_plugin()
  2455. {
  2456. CARLA_BACKEND_USE_NAMESPACE;
  2457. return &carlaPatchbayCV8Desc;
  2458. }
  2459. // -----------------------------------------------------------------------
  2460. // Extra stuff for linking purposes
  2461. #ifdef CARLA_PLUGIN_EXPORT
  2462. CARLA_BACKEND_START_NAMESPACE
  2463. namespace EngineInit {
  2464. CarlaEngine* newJack() { return nullptr; }
  2465. #ifdef USING_JUCE_AUDIO_DEVICES
  2466. CarlaEngine* newJuce(const AudioApi) { return nullptr; }
  2467. uint getJuceApiCount() { return 0; }
  2468. const char* getJuceApiName(const uint) { return nullptr; }
  2469. const char* const* getJuceApiDeviceNames(const uint) { return nullptr; }
  2470. const EngineDriverDeviceInfo* getJuceDeviceInfo(const uint, const char* const) { return nullptr; }
  2471. bool showJuceDeviceControlPanel(const uint, const char* const) { return false; }
  2472. #endif
  2473. #ifdef USING_RTAUDIO
  2474. CarlaEngine* newRtAudio(const AudioApi) { return nullptr; }
  2475. uint getRtAudioApiCount() { return 0; }
  2476. const char* getRtAudioApiName(const uint) { return nullptr; }
  2477. const char* const* getRtAudioApiDeviceNames(const uint) { return nullptr; }
  2478. const EngineDriverDeviceInfo* getRtAudioDeviceInfo(const uint, const char* const) { return nullptr; }
  2479. #endif
  2480. }
  2481. CARLA_BACKEND_END_NAMESPACE
  2482. #define CARLA_PLUGIN_UI_CLASS_PREFIX Plugin
  2483. #include "CarlaPluginUI.cpp"
  2484. # undef CARLA_PLUGIN_UI_CLASS_PREFIX
  2485. #include "CarlaDssiUtils.cpp"
  2486. #include "CarlaMacUtils.cpp"
  2487. #include "CarlaPatchbayUtils.cpp"
  2488. #include "CarlaPipeUtils.cpp"
  2489. #include "CarlaProcessUtils.cpp"
  2490. #include "CarlaStateUtils.cpp"
  2491. #endif /* CARLA_PLUGIN_EXPORT */
  2492. // -----------------------------------------------------------------------