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.

3056 lines
107KB

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