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.

2973 lines
105KB

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