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.

2452 lines
82KB

  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2019 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 "CarlaEngineInternal.hpp"
  22. #include "CarlaPlugin.hpp"
  23. #include "CarlaBackendUtils.hpp"
  24. #include "CarlaBase64Utils.hpp"
  25. #include "CarlaBinaryUtils.hpp"
  26. #include "CarlaMathUtils.hpp"
  27. #include "CarlaStateUtils.hpp"
  28. #include "CarlaExternalUI.hpp"
  29. #include "CarlaHost.h"
  30. #include "CarlaNative.hpp"
  31. #include "CarlaNativePlugin.h"
  32. #if defined(USING_JUCE) && ! (defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN))
  33. # if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
  34. # pragma GCC diagnostic push
  35. # pragma GCC diagnostic ignored "-Wconversion"
  36. # pragma GCC diagnostic ignored "-Weffc++"
  37. # pragma GCC diagnostic ignored "-Wsign-conversion"
  38. # pragma GCC diagnostic ignored "-Wundef"
  39. # pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
  40. # endif
  41. # include "AppConfig.h"
  42. # include "juce_events/juce_events.h"
  43. # define USE_JUCE_MESSAGE_THREAD
  44. # if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
  45. # pragma GCC diagnostic pop
  46. # endif
  47. #endif
  48. #include "water/files/File.h"
  49. #include "water/streams/MemoryOutputStream.h"
  50. #include "water/xml/XmlDocument.h"
  51. #include "water/xml/XmlElement.h"
  52. using water::File;
  53. using water::MemoryOutputStream;
  54. using water::String;
  55. using water::XmlDocument;
  56. using water::XmlElement;
  57. CARLA_BACKEND_START_NAMESPACE
  58. // -----------------------------------------------------------------------
  59. #ifdef USE_JUCE_MESSAGE_THREAD
  60. static int numScopedInitInstances = 0;
  61. class SharedJuceMessageThread : public juce::Thread
  62. {
  63. public:
  64. SharedJuceMessageThread()
  65. : juce::Thread ("SharedJuceMessageThread"),
  66. initialised (false) {}
  67. ~SharedJuceMessageThread()
  68. {
  69. CARLA_SAFE_ASSERT(numScopedInitInstances == 0);
  70. // in case something fails
  71. juce::MessageManager::getInstance()->stopDispatchLoop();
  72. waitForThreadToExit (5000);
  73. }
  74. void incRef()
  75. {
  76. if (numScopedInitInstances++ == 0)
  77. {
  78. startThread (7);
  79. while (! initialised)
  80. juce::Thread::sleep (1);
  81. }
  82. }
  83. void decRef()
  84. {
  85. if (--numScopedInitInstances == 0)
  86. {
  87. juce::MessageManager::getInstance()->stopDispatchLoop();
  88. waitForThreadToExit (5000);
  89. }
  90. }
  91. protected:
  92. void run() override
  93. {
  94. const juce::ScopedJuceInitialiser_GUI juceInitialiser;
  95. juce::MessageManager::getInstance()->setCurrentThreadAsMessageThread();
  96. initialised = true;
  97. juce::MessageManager::getInstance()->runDispatchLoop();
  98. }
  99. private:
  100. volatile bool initialised;
  101. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SharedJuceMessageThread);
  102. };
  103. #endif
  104. // -----------------------------------------------------------------------
  105. class CarlaEngineNativeUI : public CarlaExternalUI
  106. {
  107. public:
  108. CarlaEngineNativeUI(CarlaEngine* const engine)
  109. : fEngine(engine)
  110. {
  111. carla_debug("CarlaEngineNativeUI::CarlaEngineNativeUI(%p)", engine);
  112. }
  113. ~CarlaEngineNativeUI() noexcept override
  114. {
  115. carla_debug("CarlaEngineNativeUI::~CarlaEngineNativeUI()");
  116. }
  117. protected:
  118. bool msgReceived(const char* const msg) noexcept override
  119. {
  120. if (CarlaExternalUI::msgReceived(msg))
  121. return true;
  122. bool ok = true;
  123. if (std::strcmp(msg, "set_engine_option") == 0)
  124. {
  125. uint32_t option;
  126. int32_t value;
  127. const char* valueStr = nullptr;
  128. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(option), true);
  129. CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(value), true);
  130. readNextLineAsString(valueStr); // can be null
  131. try {
  132. fEngine->setOption(static_cast<EngineOption>(option), value, valueStr);
  133. } CARLA_SAFE_EXCEPTION("setOption");
  134. if (valueStr != nullptr)
  135. delete[] valueStr;
  136. }
  137. else if (std::strcmp(msg, "cancel_engine_action") == 0)
  138. {
  139. fEngine->setActionCanceled(true);
  140. }
  141. else if (std::strcmp(msg, "load_file") == 0)
  142. {
  143. const char* filename;
  144. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename), true);
  145. try {
  146. ok = fEngine->loadFile(filename);
  147. } CARLA_SAFE_EXCEPTION("loadFile");
  148. delete[] filename;
  149. }
  150. else if (std::strcmp(msg, "load_project") == 0)
  151. {
  152. const char* filename;
  153. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename), true);
  154. try {
  155. ok = fEngine->loadProject(filename, true);
  156. } CARLA_SAFE_EXCEPTION("loadProject");
  157. delete[] filename;
  158. }
  159. else if (std::strcmp(msg, "save_project") == 0)
  160. {
  161. const char* filename;
  162. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename), true);
  163. try {
  164. ok = fEngine->saveProject(filename, true);
  165. } CARLA_SAFE_EXCEPTION("saveProject");
  166. delete[] filename;
  167. }
  168. else if (std::strcmp(msg, "clear_project_filename") == 0)
  169. {
  170. fEngine->clearCurrentProjectFilename();
  171. }
  172. else if (std::strcmp(msg, "patchbay_connect") == 0)
  173. {
  174. uint32_t groupA, portA, groupB, portB;
  175. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(groupA), true);
  176. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(portA), true);
  177. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(groupB), true);
  178. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(portB), true);
  179. try {
  180. ok = fEngine->patchbayConnect(groupA, portA, groupB, portB);
  181. } CARLA_SAFE_EXCEPTION("patchbayConnect");
  182. }
  183. else if (std::strcmp(msg, "patchbay_disconnect") == 0)
  184. {
  185. uint32_t connectionId;
  186. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(connectionId), true);
  187. try {
  188. ok = fEngine->patchbayDisconnect(connectionId);
  189. } CARLA_SAFE_EXCEPTION("patchbayDisconnect");
  190. }
  191. else if (std::strcmp(msg, "patchbay_refresh") == 0)
  192. {
  193. try {
  194. ok = fEngine->patchbayRefresh(false);
  195. } CARLA_SAFE_EXCEPTION("patchbayRefresh");
  196. }
  197. else if (std::strcmp(msg, "transport_play") == 0)
  198. {
  199. fEngine->transportPlay();
  200. }
  201. else if (std::strcmp(msg, "transport_pause") == 0)
  202. {
  203. fEngine->transportPause();
  204. }
  205. else if (std::strcmp(msg, "transport_bpm") == 0)
  206. {
  207. double bpm;
  208. CARLA_SAFE_ASSERT_RETURN(readNextLineAsDouble(bpm), true);
  209. fEngine->transportBPM(bpm);
  210. }
  211. else if (std::strcmp(msg, "transport_relocate") == 0)
  212. {
  213. uint64_t frame;
  214. CARLA_SAFE_ASSERT_RETURN(readNextLineAsULong(frame), true);
  215. fEngine->transportRelocate(frame);
  216. }
  217. else if (std::strcmp(msg, "add_plugin") == 0)
  218. {
  219. uint32_t btype, ptype;
  220. const char* filename = nullptr;
  221. const char* name;
  222. const char* label;
  223. int64_t uniqueId;
  224. uint options;
  225. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(btype), true);
  226. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(ptype), true);
  227. readNextLineAsString(filename); // can be null
  228. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(name), true);
  229. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(label), true);
  230. CARLA_SAFE_ASSERT_RETURN(readNextLineAsLong(uniqueId), true);
  231. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(options), true);
  232. if (filename != nullptr && std::strcmp(filename, "(null)") == 0)
  233. {
  234. delete[] filename;
  235. filename = nullptr;
  236. }
  237. if (std::strcmp(name, "(null)") == 0)
  238. {
  239. delete[] name;
  240. name = nullptr;
  241. }
  242. ok = fEngine->addPlugin(static_cast<BinaryType>(btype), static_cast<PluginType>(ptype),
  243. filename, name, label, uniqueId, nullptr, options);
  244. if (filename != nullptr)
  245. delete[] filename;
  246. if (name != nullptr)
  247. delete[] name;
  248. delete[] label;
  249. }
  250. else if (std::strcmp(msg, "remove_plugin") == 0)
  251. {
  252. uint32_t pluginId;
  253. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  254. ok = fEngine->removePlugin(pluginId);
  255. }
  256. else if (std::strcmp(msg, "remove_all_plugins") == 0)
  257. {
  258. ok = fEngine->removeAllPlugins();
  259. }
  260. else if (std::strcmp(msg, "rename_plugin") == 0)
  261. {
  262. uint32_t pluginId;
  263. const char* newName;
  264. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  265. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(newName), true);
  266. // TODO
  267. /*const char* name =*/ fEngine->renamePlugin(pluginId, newName);
  268. delete[] newName;
  269. }
  270. else if (std::strcmp(msg, "clone_plugin") == 0)
  271. {
  272. uint32_t pluginId;
  273. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  274. ok = fEngine->clonePlugin(pluginId);
  275. }
  276. else if (std::strcmp(msg, "replace_plugin") == 0)
  277. {
  278. uint32_t pluginId;
  279. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  280. ok = fEngine->replacePlugin(pluginId);
  281. }
  282. else if (std::strcmp(msg, "switch_plugins") == 0)
  283. {
  284. uint32_t pluginIdA, pluginIdB;
  285. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginIdA), true);
  286. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginIdB), true);
  287. ok = fEngine->switchPlugins(pluginIdA, pluginIdB);
  288. }
  289. else if (std::strcmp(msg, "load_plugin_state") == 0)
  290. {
  291. uint32_t pluginId;
  292. const char* filename;
  293. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  294. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename), true);
  295. if (CarlaPlugin* const plugin = fEngine->getPlugin(pluginId))
  296. plugin->loadStateFromFile(filename);
  297. delete[] filename;
  298. }
  299. else if (std::strcmp(msg, "save_plugin_state") == 0)
  300. {
  301. uint32_t pluginId;
  302. const char* filename;
  303. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  304. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename), true);
  305. if (CarlaPlugin* const plugin = fEngine->getPlugin(pluginId))
  306. plugin->saveStateToFile(filename);
  307. delete[] filename;
  308. }
  309. else if (std::strcmp(msg, "set_option") == 0)
  310. {
  311. uint32_t pluginId, option;
  312. bool yesNo;
  313. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  314. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(option), true);
  315. CARLA_SAFE_ASSERT_RETURN(readNextLineAsBool(yesNo), true);
  316. if (CarlaPlugin* const plugin = fEngine->getPlugin(pluginId))
  317. plugin->setOption(option, yesNo, false);
  318. }
  319. else if (std::strcmp(msg, "set_active") == 0)
  320. {
  321. uint32_t pluginId;
  322. bool onOff;
  323. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  324. CARLA_SAFE_ASSERT_RETURN(readNextLineAsBool(onOff), true);
  325. if (CarlaPlugin* const plugin = fEngine->getPlugin(pluginId))
  326. plugin->setActive(onOff, true, false);
  327. }
  328. else if (std::strcmp(msg, "set_drywet") == 0)
  329. {
  330. uint32_t pluginId;
  331. float value;
  332. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  333. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(value), true);
  334. if (CarlaPlugin* const plugin = fEngine->getPlugin(pluginId))
  335. plugin->setDryWet(value, true, false);
  336. }
  337. else if (std::strcmp(msg, "set_volume") == 0)
  338. {
  339. uint32_t pluginId;
  340. float value;
  341. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  342. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(value), true);
  343. if (CarlaPlugin* const plugin = fEngine->getPlugin(pluginId))
  344. plugin->setVolume(value, true, false);
  345. }
  346. else if (std::strcmp(msg, "set_balance_left") == 0)
  347. {
  348. uint32_t pluginId;
  349. float value;
  350. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  351. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(value), true);
  352. if (CarlaPlugin* const plugin = fEngine->getPlugin(pluginId))
  353. plugin->setBalanceLeft(value, true, false);
  354. }
  355. else if (std::strcmp(msg, "set_balance_right") == 0)
  356. {
  357. uint32_t pluginId;
  358. float value;
  359. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  360. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(value), true);
  361. if (CarlaPlugin* const plugin = fEngine->getPlugin(pluginId))
  362. plugin->setBalanceRight(value, true, false);
  363. }
  364. else if (std::strcmp(msg, "set_panning") == 0)
  365. {
  366. uint32_t pluginId;
  367. float value;
  368. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  369. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(value), true);
  370. if (CarlaPlugin* const plugin = fEngine->getPlugin(pluginId))
  371. plugin->setPanning(value, true, false);
  372. }
  373. else if (std::strcmp(msg, "set_ctrl_channel") == 0)
  374. {
  375. uint32_t pluginId;
  376. int32_t channel;
  377. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  378. CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(channel), true);
  379. CARLA_SAFE_ASSERT_RETURN(channel >= -1 && channel < MAX_MIDI_CHANNELS, true);
  380. if (CarlaPlugin* const plugin = fEngine->getPlugin(pluginId))
  381. plugin->setCtrlChannel(int8_t(channel), true, false);
  382. }
  383. else if (std::strcmp(msg, "set_parameter_value") == 0)
  384. {
  385. uint32_t pluginId, parameterId;
  386. float value;
  387. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  388. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(parameterId), true);
  389. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(value), true);
  390. if (CarlaPlugin* const plugin = fEngine->getPlugin(pluginId))
  391. plugin->setParameterValue(parameterId, value, true, true, false);
  392. }
  393. else if (std::strcmp(msg, "set_parameter_midi_channel") == 0)
  394. {
  395. uint32_t pluginId, parameterId, channel;
  396. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  397. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(parameterId), true);
  398. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(channel), true);
  399. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS, true);
  400. if (CarlaPlugin* const plugin = fEngine->getPlugin(pluginId))
  401. plugin->setParameterMidiChannel(parameterId, static_cast<uint8_t>(channel), true, false);
  402. }
  403. else if (std::strcmp(msg, "set_parameter_midi_cc") == 0)
  404. {
  405. uint32_t pluginId, parameterId;
  406. int32_t cc;
  407. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  408. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(parameterId), true);
  409. CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(cc), true);
  410. CARLA_SAFE_ASSERT_RETURN(cc >= -1 && cc < MAX_MIDI_CONTROL, true);
  411. if (CarlaPlugin* const plugin = fEngine->getPlugin(pluginId))
  412. plugin->setParameterMidiCC(parameterId, static_cast<int16_t>(cc), true, false);
  413. }
  414. else if (std::strcmp(msg, "set_program") == 0)
  415. {
  416. uint32_t pluginId;
  417. int32_t index;
  418. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  419. CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(index), true);
  420. if (CarlaPlugin* const plugin = fEngine->getPlugin(pluginId))
  421. {
  422. plugin->setProgram(index, true, true, false);
  423. _updateParamValues(plugin, pluginId);
  424. }
  425. }
  426. else if (std::strcmp(msg, "set_midi_program") == 0)
  427. {
  428. uint32_t pluginId;
  429. int32_t index;
  430. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  431. CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(index), true);
  432. if (CarlaPlugin* const plugin = fEngine->getPlugin(pluginId))
  433. {
  434. plugin->setMidiProgram(index, true, true, false);
  435. _updateParamValues(plugin, pluginId);
  436. }
  437. }
  438. else if (std::strcmp(msg, "set_custom_data") == 0)
  439. {
  440. uint32_t pluginId;
  441. const char* type;
  442. const char* key;
  443. const char* value;
  444. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  445. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(type), true);
  446. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(key), true);
  447. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(value), true);
  448. if (CarlaPlugin* const plugin = fEngine->getPlugin(pluginId))
  449. plugin->setCustomData(type, key, value, true);
  450. delete[] type;
  451. delete[] key;
  452. delete[] value;
  453. }
  454. else if (std::strcmp(msg, "set_chunk_data") == 0)
  455. {
  456. uint32_t pluginId;
  457. const char* cdata;
  458. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  459. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(cdata), true);
  460. if (CarlaPlugin* const plugin = fEngine->getPlugin(pluginId))
  461. {
  462. std::vector<uint8_t> chunk(carla_getChunkFromBase64String(cdata));
  463. #ifdef CARLA_PROPER_CPP11_SUPPORT
  464. plugin->setChunkData(chunk.data(), chunk.size());
  465. #else
  466. plugin->setChunkData(&chunk.front(), chunk.size());
  467. #endif
  468. }
  469. delete[] cdata;
  470. }
  471. else if (std::strcmp(msg, "prepare_for_save") == 0)
  472. {
  473. uint32_t pluginId;
  474. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  475. if (CarlaPlugin* const plugin = fEngine->getPlugin(pluginId))
  476. plugin->prepareForSave();
  477. }
  478. else if (std::strcmp(msg, "reset_parameters") == 0)
  479. {
  480. uint32_t pluginId;
  481. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  482. if (CarlaPlugin* const plugin = fEngine->getPlugin(pluginId))
  483. plugin->resetParameters();
  484. }
  485. else if (std::strcmp(msg, "randomize_parameters") == 0)
  486. {
  487. uint32_t pluginId;
  488. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  489. if (CarlaPlugin* const plugin = fEngine->getPlugin(pluginId))
  490. plugin->randomizeParameters();
  491. }
  492. else if (std::strcmp(msg, "send_midi_note") == 0)
  493. {
  494. uint32_t pluginId, channel, note, velocity;
  495. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  496. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(channel), true);
  497. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(note), true);
  498. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(velocity), true);
  499. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS, true);
  500. CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_VALUE, true);
  501. CARLA_SAFE_ASSERT_RETURN(velocity < MAX_MIDI_VALUE, true);
  502. if (CarlaPlugin* const plugin = fEngine->getPlugin(pluginId))
  503. plugin->sendMidiSingleNote(static_cast<uint8_t>(channel), static_cast<uint8_t>(note), static_cast<uint8_t>(velocity), true, true, false);
  504. }
  505. else if (std::strcmp(msg, "show_custom_ui") == 0)
  506. {
  507. uint32_t pluginId;
  508. bool yesNo;
  509. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true);
  510. CARLA_SAFE_ASSERT_RETURN(readNextLineAsBool(yesNo), true);
  511. if (CarlaPlugin* const plugin = fEngine->getPlugin(pluginId))
  512. plugin->showCustomUI(yesNo);
  513. }
  514. else
  515. {
  516. carla_stderr("CarlaEngineNativeUI::msgReceived : %s", msg);
  517. return false;
  518. }
  519. if (! ok)
  520. {
  521. const CarlaMutexLocker cml(getPipeLock());
  522. if (writeMessage("error\n", 6) && writeAndFixMessage(fEngine->getLastError()))
  523. flushMessages();
  524. }
  525. return true;
  526. }
  527. private:
  528. CarlaEngine* const fEngine;
  529. void _updateParamValues(CarlaPlugin* const plugin, const uint32_t pluginId) const noexcept
  530. {
  531. for (uint32_t i=0, count=plugin->getParameterCount(); i<count; ++i)
  532. fEngine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
  533. pluginId, static_cast<int>(i), 0, plugin->getParameterValue(i), nullptr);
  534. }
  535. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineNativeUI)
  536. };
  537. // -----------------------------------------------------------------------
  538. class CarlaEngineNative : public CarlaEngine
  539. {
  540. public:
  541. CarlaEngineNative(const NativeHostDescriptor* const host, const bool isPatchbay, const bool withMidiOut,
  542. const uint32_t inChan = 2, uint32_t outChan = 2)
  543. : CarlaEngine(),
  544. pHost(host),
  545. #ifdef USE_JUCE_MESSAGE_THREAD
  546. // if not running inside Carla, we will have to run event loop ourselves
  547. kNeedsJuceMsgThread(host->dispatcher(pHost->handle,
  548. NATIVE_HOST_OPCODE_INTERNAL_PLUGIN, 0, 0, nullptr, 0.0f) == 0),
  549. fJuceMsgThread(),
  550. #endif
  551. kIsPatchbay(isPatchbay),
  552. kHasMidiOut(withMidiOut),
  553. fIsActive(false),
  554. fIsRunning(false),
  555. fUiServer(this),
  556. fOptionsForced(false)
  557. {
  558. carla_debug("CarlaEngineNative::CarlaEngineNative()");
  559. #ifdef USE_JUCE_MESSAGE_THREAD
  560. if (kNeedsJuceMsgThread)
  561. fJuceMsgThread->incRef();
  562. #endif
  563. pData->bufferSize = pHost->get_buffer_size(pHost->handle);
  564. pData->sampleRate = pHost->get_sample_rate(pHost->handle);
  565. pData->initTime(nullptr);
  566. if (outChan == 0)
  567. outChan = inChan;
  568. // set-up engine
  569. if (kIsPatchbay)
  570. {
  571. pData->options.processMode = ENGINE_PROCESS_MODE_PATCHBAY;
  572. pData->options.transportMode = ENGINE_TRANSPORT_MODE_PLUGIN;
  573. pData->options.forceStereo = false;
  574. pData->options.preferPluginBridges = false;
  575. pData->options.preferUiBridges = false;
  576. init("Carla-Patchbay");
  577. pData->graph.create(inChan, outChan);
  578. }
  579. else
  580. {
  581. CARLA_SAFE_ASSERT(inChan == 2);
  582. CARLA_SAFE_ASSERT(outChan == 2);
  583. pData->options.processMode = ENGINE_PROCESS_MODE_CONTINUOUS_RACK;
  584. pData->options.transportMode = ENGINE_TRANSPORT_MODE_PLUGIN;
  585. pData->options.forceStereo = true;
  586. pData->options.preferPluginBridges = false;
  587. pData->options.preferUiBridges = false;
  588. init("Carla-Rack");
  589. pData->graph.create(0, 0); // FIXME?
  590. }
  591. if (pData->options.resourceDir != nullptr)
  592. delete[] pData->options.resourceDir;
  593. if (pData->options.binaryDir != nullptr)
  594. delete[] pData->options.binaryDir;
  595. pData->options.resourceDir = carla_strdup(pHost->resourceDir);
  596. pData->options.binaryDir = carla_strdup(carla_get_library_folder());
  597. setCallback(_ui_server_callback, this);
  598. setFileCallback(_ui_file_callback, this);
  599. }
  600. ~CarlaEngineNative() override
  601. {
  602. CARLA_SAFE_ASSERT(! fIsActive);
  603. carla_debug("CarlaEngineNative::~CarlaEngineNative() - START");
  604. pData->aboutToClose = true;
  605. fIsRunning = false;
  606. removeAllPlugins();
  607. //runPendingRtEvents();
  608. close();
  609. pData->graph.destroy();
  610. #ifdef USE_JUCE_MESSAGE_THREAD
  611. if (kNeedsJuceMsgThread)
  612. fJuceMsgThread->decRef();
  613. #endif
  614. carla_debug("CarlaEngineNative::~CarlaEngineNative() - END");
  615. }
  616. protected:
  617. // -------------------------------------
  618. // CarlaEngine virtual calls
  619. bool init(const char* const clientName) override
  620. {
  621. carla_debug("CarlaEngineNative::init(\"%s\")", clientName);
  622. fIsRunning = true;
  623. if (! pData->init(clientName))
  624. {
  625. close();
  626. setLastError("Failed to init internal data");
  627. return false;
  628. }
  629. pData->bufferSize = pHost->get_buffer_size(pHost->handle);
  630. pData->sampleRate = pHost->get_sample_rate(pHost->handle);
  631. return true;
  632. }
  633. bool close() override
  634. {
  635. fIsRunning = false;
  636. CarlaEngine::close();
  637. return true;
  638. }
  639. bool isRunning() const noexcept override
  640. {
  641. return fIsRunning;
  642. }
  643. bool isOffline() const noexcept override
  644. {
  645. return pHost->is_offline(pHost->handle);
  646. }
  647. bool usesConstantBufferSize() const noexcept override
  648. {
  649. // TODO LV2 hosts can report this, till then we allow this
  650. return true;
  651. }
  652. EngineType getType() const noexcept override
  653. {
  654. return kEngineTypePlugin;
  655. }
  656. const char* getCurrentDriverName() const noexcept override
  657. {
  658. return "Plugin";
  659. }
  660. void callback(const EngineCallbackOpcode action, const uint pluginId, const int value1, const int value2, const float value3, const char* const valueStr) noexcept override
  661. {
  662. CarlaEngine::callback(action, pluginId, value1, value2, value3, valueStr);
  663. if (action == ENGINE_CALLBACK_IDLE && ! pData->aboutToClose)
  664. pHost->dispatcher(pHost->handle, NATIVE_HOST_OPCODE_HOST_IDLE, 0, 0, nullptr, 0.0f);
  665. }
  666. // -------------------------------------------------------------------
  667. const char* renamePlugin(const uint id, const char* const newName) override
  668. {
  669. if (const char* const retName = CarlaEngine::renamePlugin(id, newName))
  670. {
  671. uiServerCallback(ENGINE_CALLBACK_PLUGIN_RENAMED, id, 0, 0, 0.0f, retName);
  672. return retName;
  673. }
  674. return nullptr;
  675. }
  676. // -------------------------------------------------------------------
  677. void bufferSizeChanged(const uint32_t newBufferSize)
  678. {
  679. if (pData->bufferSize == newBufferSize)
  680. return;
  681. {
  682. const CarlaMutexLocker cml(fUiServer.getPipeLock());
  683. if (fUiServer.writeAndFixMessage("buffer-size"))
  684. {
  685. char tmpBuf[STR_MAX];
  686. carla_zeroChars(tmpBuf, STR_MAX);
  687. std::sprintf(tmpBuf, "%i\n", newBufferSize);
  688. if (fUiServer.writeMessage(tmpBuf))
  689. fUiServer.flushMessages();
  690. }
  691. }
  692. pData->bufferSize = newBufferSize;
  693. CarlaEngine::bufferSizeChanged(newBufferSize);
  694. }
  695. void sampleRateChanged(const double newSampleRate)
  696. {
  697. if (carla_isEqual(pData->sampleRate, newSampleRate))
  698. return;
  699. {
  700. const CarlaMutexLocker cml(fUiServer.getPipeLock());
  701. if (fUiServer.writeAndFixMessage("sample-rate"))
  702. {
  703. char tmpBuf[STR_MAX];
  704. carla_zeroChars(tmpBuf, STR_MAX);
  705. {
  706. const CarlaScopedLocale csl;
  707. std::sprintf(tmpBuf, "%f\n", newSampleRate);
  708. }
  709. if (fUiServer.writeMessage(tmpBuf))
  710. fUiServer.flushMessages();
  711. }
  712. }
  713. pData->sampleRate = newSampleRate;
  714. CarlaEngine::sampleRateChanged(newSampleRate);
  715. }
  716. // -------------------------------------------------------------------
  717. void uiServerSendPluginInfo(CarlaPlugin* const plugin)
  718. {
  719. char tmpBuf[STR_MAX];
  720. carla_zeroChars(tmpBuf, STR_MAX);
  721. const CarlaMutexLocker cml(fUiServer.getPipeLock());
  722. const uint pluginId(plugin->getId());
  723. std::sprintf(tmpBuf, "PLUGIN_INFO_%i\n", pluginId);
  724. if (! fUiServer.writeMessage(tmpBuf))
  725. return;
  726. std::sprintf(tmpBuf, "%i:%i:%i:" P_INT64 ":%i:%i\n", plugin->getType(), plugin->getCategory(), plugin->getHints(), plugin->getUniqueId(), plugin->getOptionsAvailable(), plugin->getOptionsEnabled());
  727. if (! fUiServer.writeMessage(tmpBuf))
  728. return;
  729. if (const char* const filename = plugin->getFilename())
  730. {
  731. std::sprintf(tmpBuf, "%s", filename);
  732. if (! fUiServer.writeAndFixMessage(tmpBuf))
  733. return;
  734. }
  735. else
  736. {
  737. if (! fUiServer.writeMessage("\n"))
  738. return;
  739. }
  740. if (const char* const name = plugin->getName())
  741. {
  742. std::sprintf(tmpBuf, "%s", name);
  743. if (! fUiServer.writeAndFixMessage(tmpBuf))
  744. return;
  745. }
  746. else
  747. {
  748. if (! fUiServer.writeMessage("\n"))
  749. return;
  750. }
  751. if (const char* const iconName = plugin->getIconName())
  752. {
  753. std::sprintf(tmpBuf, "%s", iconName);
  754. if (! fUiServer.writeAndFixMessage(tmpBuf))
  755. return;
  756. }
  757. else
  758. {
  759. if (! fUiServer.writeMessage("\n"))
  760. return;
  761. }
  762. plugin->getRealName(tmpBuf);
  763. if (! fUiServer.writeAndFixMessage(tmpBuf))
  764. return;
  765. plugin->getLabel(tmpBuf);
  766. if (! fUiServer.writeAndFixMessage(tmpBuf))
  767. return;
  768. plugin->getMaker(tmpBuf);
  769. if (! fUiServer.writeAndFixMessage(tmpBuf))
  770. return;
  771. plugin->getCopyright(tmpBuf);
  772. if (! fUiServer.writeAndFixMessage(tmpBuf))
  773. return;
  774. std::sprintf(tmpBuf, "AUDIO_COUNT_%i:%i:%i\n", pluginId, plugin->getAudioInCount(), plugin->getAudioOutCount());
  775. if (! fUiServer.writeMessage(tmpBuf))
  776. return;
  777. std::sprintf(tmpBuf, "MIDI_COUNT_%i:%i:%i\n", pluginId, plugin->getMidiInCount(), plugin->getMidiOutCount());
  778. if (! fUiServer.writeMessage(tmpBuf))
  779. return;
  780. fUiServer.flushMessages();
  781. }
  782. void uiServerSendPluginParameters(CarlaPlugin* const plugin)
  783. {
  784. char tmpBuf[STR_MAX];
  785. carla_zeroChars(tmpBuf, STR_MAX);
  786. const CarlaMutexLocker cml(fUiServer.getPipeLock());
  787. const CarlaScopedLocale csl;
  788. const uint pluginId(plugin->getId());
  789. for (int32_t i=PARAMETER_ACTIVE; i>PARAMETER_MAX; --i)
  790. {
  791. std::sprintf(tmpBuf, "PARAMVAL_%i:%i\n", pluginId, i);
  792. if (! fUiServer.writeMessage(tmpBuf))
  793. return;
  794. std::sprintf(tmpBuf, "%f\n", static_cast<double>(plugin->getInternalParameterValue(i)));
  795. if (! fUiServer.writeMessage(tmpBuf))
  796. return;
  797. fUiServer.flushMessages();
  798. }
  799. uint32_t ins, outs, count;
  800. plugin->getParameterCountInfo(ins, outs);
  801. count = plugin->getParameterCount();
  802. std::sprintf(tmpBuf, "PARAMETER_COUNT_%i:%i:%i:%i\n", pluginId, ins, outs, count);
  803. if (! fUiServer.writeMessage(tmpBuf))
  804. return;
  805. for (uint32_t i=0; i<count; ++i)
  806. {
  807. const ParameterData& paramData(plugin->getParameterData(i));
  808. const ParameterRanges& paramRanges(plugin->getParameterRanges(i));
  809. std::sprintf(tmpBuf, "PARAMETER_DATA_%i:%i\n", pluginId, i);
  810. if (! fUiServer.writeMessage(tmpBuf))
  811. return;
  812. std::sprintf(tmpBuf, "%i:%i:%i:%i\n", paramData.type, paramData.hints, paramData.midiChannel, paramData.midiCC);
  813. if (! fUiServer.writeMessage(tmpBuf))
  814. return;
  815. plugin->getParameterName(i, tmpBuf);
  816. if (! fUiServer.writeAndFixMessage(tmpBuf))
  817. return;
  818. plugin->getParameterUnit(i, tmpBuf);
  819. if (! fUiServer.writeAndFixMessage(tmpBuf))
  820. return;
  821. std::sprintf(tmpBuf, "PARAMETER_RANGES_%i:%i\n", pluginId, i);
  822. if (! fUiServer.writeMessage(tmpBuf))
  823. return;
  824. std::sprintf(tmpBuf, "%f:%f:%f:%f:%f:%f\n",
  825. static_cast<double>(paramRanges.def),
  826. static_cast<double>(paramRanges.min),
  827. static_cast<double>(paramRanges.max),
  828. static_cast<double>(paramRanges.step),
  829. static_cast<double>(paramRanges.stepSmall),
  830. static_cast<double>(paramRanges.stepLarge));
  831. if (! fUiServer.writeMessage(tmpBuf))
  832. return;
  833. std::sprintf(tmpBuf, "PARAMVAL_%i:%i\n", pluginId, i);
  834. if (! fUiServer.writeMessage(tmpBuf))
  835. return;
  836. std::sprintf(tmpBuf, "%f\n", static_cast<double>(plugin->getParameterValue(i)));
  837. if (! fUiServer.writeMessage(tmpBuf))
  838. return;
  839. }
  840. fUiServer.flushMessages();
  841. }
  842. void uiServerSendPluginPrograms(CarlaPlugin* const plugin)
  843. {
  844. char tmpBuf[STR_MAX];
  845. carla_zeroChars(tmpBuf, STR_MAX);
  846. const CarlaMutexLocker cml(fUiServer.getPipeLock());
  847. const uint pluginId(plugin->getId());
  848. uint32_t count = plugin->getProgramCount();
  849. std::sprintf(tmpBuf, "PROGRAM_COUNT_%i:%i:%i\n", pluginId, count, plugin->getCurrentProgram());
  850. if (! fUiServer.writeMessage(tmpBuf))
  851. return;
  852. for (uint32_t i=0; i<count; ++i)
  853. {
  854. std::sprintf(tmpBuf, "PROGRAM_NAME_%i:%i\n", pluginId, i);
  855. if (! fUiServer.writeMessage(tmpBuf))
  856. return;
  857. plugin->getProgramName(i, tmpBuf);
  858. if (! fUiServer.writeAndFixMessage(tmpBuf))
  859. return;
  860. }
  861. fUiServer.flushMessages();
  862. count = plugin->getMidiProgramCount();
  863. std::sprintf(tmpBuf, "MIDI_PROGRAM_COUNT_%i:%i:%i\n", pluginId, count, plugin->getCurrentMidiProgram());
  864. if (! fUiServer.writeMessage(tmpBuf))
  865. return;
  866. for (uint32_t i=0; i<count; ++i)
  867. {
  868. std::sprintf(tmpBuf, "MIDI_PROGRAM_DATA_%i:%i\n", pluginId, i);
  869. if (! fUiServer.writeMessage(tmpBuf))
  870. return;
  871. const MidiProgramData& mpData(plugin->getMidiProgramData(i));
  872. std::sprintf(tmpBuf, "%i:%i\n", mpData.bank, mpData.program);
  873. if (! fUiServer.writeMessage(tmpBuf))
  874. return;
  875. std::sprintf(tmpBuf, "%s", mpData.name);
  876. if (! fUiServer.writeAndFixMessage(tmpBuf))
  877. return;
  878. }
  879. fUiServer.flushMessages();
  880. }
  881. void uiServerSendPluginProperties(CarlaPlugin* const plugin)
  882. {
  883. char tmpBuf[STR_MAX];
  884. carla_zeroChars(tmpBuf, STR_MAX);
  885. const CarlaMutexLocker cml(fUiServer.getPipeLock());
  886. const uint pluginId(plugin->getId());
  887. uint32_t count = plugin->getCustomDataCount();
  888. std::sprintf(tmpBuf, "CUSTOM_DATA_COUNT_%i:%i\n", pluginId, count);
  889. if (! fUiServer.writeMessage(tmpBuf))
  890. return;
  891. for (uint32_t i=0; i<count; ++i)
  892. {
  893. const CustomData& customData(plugin->getCustomData(i));
  894. CARLA_SAFE_ASSERT_CONTINUE(customData.isValid());
  895. if (std::strcmp(customData.type, CUSTOM_DATA_TYPE_PROPERTY) != 0)
  896. continue;
  897. std::sprintf(tmpBuf, "CUSTOM_DATA_%i:%i\n", pluginId, i);
  898. if (! fUiServer.writeMessage(tmpBuf))
  899. return;
  900. if (! fUiServer.writeAndFixMessage(customData.type))
  901. return;
  902. if (! fUiServer.writeAndFixMessage(customData.key))
  903. return;
  904. if (! fUiServer.writeAndFixMessage(customData.value))
  905. return;
  906. }
  907. fUiServer.flushMessages();
  908. }
  909. void uiServerCallback(const EngineCallbackOpcode action, const uint pluginId, const int value1, const int value2, const float value3, const char* const valueStr)
  910. {
  911. if (! fIsRunning)
  912. return;
  913. if (! fUiServer.isPipeRunning())
  914. return;
  915. CarlaPlugin* plugin;
  916. switch (action)
  917. {
  918. case ENGINE_CALLBACK_UPDATE:
  919. plugin = getPlugin(pluginId);
  920. if (plugin != nullptr && plugin->isEnabled())
  921. {
  922. CARLA_SAFE_ASSERT_BREAK(plugin->getId() == pluginId);
  923. uiServerSendPluginProperties(plugin);
  924. }
  925. break;
  926. case ENGINE_CALLBACK_RELOAD_INFO:
  927. plugin = getPlugin(pluginId);
  928. if (plugin != nullptr && plugin->isEnabled())
  929. {
  930. CARLA_SAFE_ASSERT_BREAK(plugin->getId() == pluginId);
  931. uiServerSendPluginInfo(plugin);
  932. }
  933. break;
  934. case ENGINE_CALLBACK_RELOAD_PARAMETERS:
  935. plugin = getPlugin(pluginId);
  936. if (plugin != nullptr && plugin->isEnabled())
  937. {
  938. CARLA_SAFE_ASSERT_BREAK(plugin->getId() == pluginId);
  939. uiServerSendPluginParameters(plugin);
  940. }
  941. break;
  942. case ENGINE_CALLBACK_RELOAD_PROGRAMS:
  943. plugin = getPlugin(pluginId);
  944. if (plugin != nullptr && plugin->isEnabled())
  945. {
  946. CARLA_SAFE_ASSERT_BREAK(plugin->getId() == pluginId);
  947. uiServerSendPluginPrograms(plugin);
  948. }
  949. break;
  950. case ENGINE_CALLBACK_RELOAD_ALL:
  951. case ENGINE_CALLBACK_PLUGIN_ADDED:
  952. plugin = getPlugin(pluginId);
  953. if (plugin != nullptr && plugin->isEnabled())
  954. {
  955. CARLA_SAFE_ASSERT_BREAK(plugin->getId() == pluginId);
  956. uiServerSendPluginInfo(plugin);
  957. uiServerSendPluginParameters(plugin);
  958. uiServerSendPluginPrograms(plugin);
  959. uiServerSendPluginProperties(plugin);
  960. }
  961. break;
  962. default:
  963. break;
  964. }
  965. char tmpBuf[STR_MAX];
  966. carla_zeroChars(tmpBuf, STR_MAX);
  967. const CarlaMutexLocker cml(fUiServer.getPipeLock());
  968. std::sprintf(tmpBuf, "ENGINE_CALLBACK_%i\n", int(action));
  969. if (! fUiServer.writeMessage(tmpBuf))
  970. return;
  971. std::sprintf(tmpBuf, "%u\n", pluginId);
  972. if (! fUiServer.writeMessage(tmpBuf))
  973. return;
  974. std::sprintf(tmpBuf, "%i\n", value1);
  975. if (! fUiServer.writeMessage(tmpBuf))
  976. return;
  977. std::sprintf(tmpBuf, "%i\n", value2);
  978. if (! fUiServer.writeMessage(tmpBuf))
  979. return;
  980. {
  981. const CarlaScopedLocale csl;
  982. std::sprintf(tmpBuf, "%f\n", static_cast<double>(value3));
  983. }
  984. if (! fUiServer.writeMessage(tmpBuf))
  985. return;
  986. if (! fUiServer.writeAndFixMessage(valueStr != nullptr ? valueStr : ""))
  987. return;
  988. fUiServer.flushMessages();
  989. }
  990. const char* uiFileCallback(FileCallbackOpcode action, bool isDir, const char* title, const char* filter)
  991. {
  992. switch (action)
  993. {
  994. case FILE_CALLBACK_DEBUG:
  995. return nullptr;
  996. case FILE_CALLBACK_OPEN:
  997. return pHost->ui_open_file(pHost->handle, isDir, title, filter);
  998. case FILE_CALLBACK_SAVE:
  999. return pHost->ui_save_file(pHost->handle, isDir, title, filter);
  1000. }
  1001. return nullptr;
  1002. }
  1003. void uiServerInfo()
  1004. {
  1005. CARLA_SAFE_ASSERT_RETURN(fIsRunning,);
  1006. CARLA_SAFE_ASSERT_RETURN(fUiServer.isPipeRunning(),);
  1007. char tmpBuf[STR_MAX];
  1008. carla_zeroChars(tmpBuf, STR_MAX);
  1009. const CarlaMutexLocker cml(fUiServer.getPipeLock());
  1010. #if defined(HAVE_LIBLO) && !defined(BUILD_BRIDGE)
  1011. if (! fUiServer.writeAndFixMessage("osc-urls"))
  1012. return;
  1013. if (! fUiServer.writeAndFixMessage(pData->osc.getServerPathTCP()))
  1014. return;
  1015. if (! fUiServer.writeAndFixMessage(pData->osc.getServerPathUDP()))
  1016. return;
  1017. #endif
  1018. if (! fUiServer.writeAndFixMessage("max-plugin-number"))
  1019. return;
  1020. std::sprintf(tmpBuf, "%i\n", pData->maxPluginNumber);
  1021. if (! fUiServer.writeMessage(tmpBuf))
  1022. return;
  1023. if (! fUiServer.writeAndFixMessage("buffer-size"))
  1024. return;
  1025. std::sprintf(tmpBuf, "%i\n", pData->bufferSize);
  1026. if (! fUiServer.writeMessage(tmpBuf))
  1027. return;
  1028. if (! fUiServer.writeAndFixMessage("sample-rate"))
  1029. return;
  1030. {
  1031. const CarlaScopedLocale csl;
  1032. std::sprintf(tmpBuf, "%f\n", pData->sampleRate);
  1033. }
  1034. if (! fUiServer.writeMessage(tmpBuf))
  1035. return;
  1036. fUiServer.flushMessages();
  1037. }
  1038. void uiServerOptions()
  1039. {
  1040. CARLA_SAFE_ASSERT_RETURN(fIsRunning,);
  1041. CARLA_SAFE_ASSERT_RETURN(fUiServer.isPipeRunning(),);
  1042. char tmpBuf[STR_MAX];
  1043. carla_zeroChars(tmpBuf, STR_MAX);
  1044. const EngineOptions& options(pData->options);
  1045. const CarlaMutexLocker cml(fUiServer.getPipeLock());
  1046. const char* const optionsForcedStr(fOptionsForced ? "true\n" : "false\n");
  1047. const std::size_t optionsForcedStrSize(fOptionsForced ? 5 : 6);
  1048. std::sprintf(tmpBuf, "ENGINE_OPTION_%i\n", ENGINE_OPTION_PROCESS_MODE);
  1049. if (! fUiServer.writeMessage(tmpBuf))
  1050. return;
  1051. if (! fUiServer.writeMessage(optionsForcedStr, optionsForcedStrSize))
  1052. return;
  1053. std::sprintf(tmpBuf, "%i\n", options.processMode);
  1054. if (! fUiServer.writeMessage(tmpBuf))
  1055. return;
  1056. fUiServer.flushMessages();
  1057. std::sprintf(tmpBuf, "ENGINE_OPTION_%i\n", ENGINE_OPTION_TRANSPORT_MODE);
  1058. if (! fUiServer.writeMessage(tmpBuf))
  1059. return;
  1060. if (! fUiServer.writeMessage(optionsForcedStr, optionsForcedStrSize))
  1061. return;
  1062. std::sprintf(tmpBuf, "%i\n", options.transportMode);
  1063. if (! fUiServer.writeMessage(tmpBuf))
  1064. return;
  1065. fUiServer.flushMessages();
  1066. std::sprintf(tmpBuf, "ENGINE_OPTION_%i\n", ENGINE_OPTION_FORCE_STEREO);
  1067. if (! fUiServer.writeMessage(tmpBuf))
  1068. return;
  1069. if (! fUiServer.writeMessage(optionsForcedStr, optionsForcedStrSize))
  1070. return;
  1071. if (! fUiServer.writeMessage(options.forceStereo ? "true\n" : "false\n"))
  1072. return;
  1073. fUiServer.flushMessages();
  1074. std::sprintf(tmpBuf, "ENGINE_OPTION_%i\n", ENGINE_OPTION_PREFER_PLUGIN_BRIDGES);
  1075. if (! fUiServer.writeMessage(tmpBuf))
  1076. return;
  1077. if (! fUiServer.writeMessage(optionsForcedStr, optionsForcedStrSize))
  1078. return;
  1079. if (! fUiServer.writeMessage(options.preferPluginBridges ? "true\n" : "false\n"))
  1080. return;
  1081. fUiServer.flushMessages();
  1082. std::sprintf(tmpBuf, "ENGINE_OPTION_%i\n", ENGINE_OPTION_PREFER_UI_BRIDGES);
  1083. if (! fUiServer.writeMessage(tmpBuf))
  1084. return;
  1085. if (! fUiServer.writeMessage(optionsForcedStr, optionsForcedStrSize))
  1086. return;
  1087. if (! fUiServer.writeMessage(options.preferUiBridges ? "true\n" : "false\n"))
  1088. return;
  1089. fUiServer.flushMessages();
  1090. std::sprintf(tmpBuf, "ENGINE_OPTION_%i\n", ENGINE_OPTION_UIS_ALWAYS_ON_TOP);
  1091. if (! fUiServer.writeMessage(tmpBuf))
  1092. return;
  1093. if (! fUiServer.writeMessage(optionsForcedStr, optionsForcedStrSize))
  1094. return;
  1095. if (! fUiServer.writeMessage(options.uisAlwaysOnTop ? "true\n" : "false\n"))
  1096. return;
  1097. fUiServer.flushMessages();
  1098. std::sprintf(tmpBuf, "ENGINE_OPTION_%i\n", ENGINE_OPTION_MAX_PARAMETERS);
  1099. if (! fUiServer.writeMessage(tmpBuf))
  1100. return;
  1101. if (! fUiServer.writeMessage(optionsForcedStr, optionsForcedStrSize))
  1102. return;
  1103. std::sprintf(tmpBuf, "%i\n", options.maxParameters);
  1104. if (! fUiServer.writeMessage(tmpBuf))
  1105. return;
  1106. fUiServer.flushMessages();
  1107. std::sprintf(tmpBuf, "ENGINE_OPTION_%i\n", ENGINE_OPTION_UI_BRIDGES_TIMEOUT);
  1108. if (! fUiServer.writeMessage(tmpBuf))
  1109. return;
  1110. if (! fUiServer.writeMessage(optionsForcedStr, optionsForcedStrSize))
  1111. return;
  1112. std::sprintf(tmpBuf, "%i\n", options.uiBridgesTimeout);
  1113. if (! fUiServer.writeMessage(tmpBuf))
  1114. return;
  1115. fUiServer.flushMessages();
  1116. std::sprintf(tmpBuf, "ENGINE_OPTION_%i\n", ENGINE_OPTION_PATH_BINARIES);
  1117. if (! fUiServer.writeMessage(tmpBuf))
  1118. return;
  1119. if (! fUiServer.writeMessage("true\n", 5))
  1120. return;
  1121. std::sprintf(tmpBuf, "%s\n", options.binaryDir);
  1122. if (! fUiServer.writeMessage(tmpBuf))
  1123. return;
  1124. fUiServer.flushMessages();
  1125. std::sprintf(tmpBuf, "ENGINE_OPTION_%i\n", ENGINE_OPTION_PATH_RESOURCES);
  1126. if (! fUiServer.writeMessage(tmpBuf))
  1127. return;
  1128. if (! fUiServer.writeMessage("true\n", 5))
  1129. return;
  1130. std::sprintf(tmpBuf, "%s\n", options.resourceDir);
  1131. if (! fUiServer.writeMessage(tmpBuf))
  1132. return;
  1133. fUiServer.flushMessages();
  1134. }
  1135. // -------------------------------------------------------------------
  1136. // Plugin parameter calls
  1137. uint32_t getParameterCount() const
  1138. {
  1139. if (CarlaPlugin* const plugin = _getFirstPlugin())
  1140. return plugin->getParameterCount();
  1141. return 0;
  1142. }
  1143. const NativeParameter* getParameterInfo(const uint32_t index) const
  1144. {
  1145. if (CarlaPlugin* const plugin = _getFirstPlugin())
  1146. {
  1147. if (index < plugin->getParameterCount())
  1148. {
  1149. static NativeParameter param;
  1150. static char strBufName[STR_MAX+1];
  1151. static char strBufUnit[STR_MAX+1];
  1152. const ParameterData& paramData(plugin->getParameterData(index));
  1153. const ParameterRanges& paramRanges(plugin->getParameterRanges(index));
  1154. plugin->getParameterName(index, strBufName);
  1155. plugin->getParameterUnit(index, strBufUnit);
  1156. uint hints = 0x0;
  1157. if (paramData.hints & PARAMETER_IS_BOOLEAN)
  1158. hints |= NATIVE_PARAMETER_IS_BOOLEAN;
  1159. if (paramData.hints & PARAMETER_IS_INTEGER)
  1160. hints |= NATIVE_PARAMETER_IS_INTEGER;
  1161. if (paramData.hints & PARAMETER_IS_LOGARITHMIC)
  1162. hints |= NATIVE_PARAMETER_IS_LOGARITHMIC;
  1163. if (paramData.hints & PARAMETER_IS_AUTOMABLE)
  1164. hints |= NATIVE_PARAMETER_IS_AUTOMABLE;
  1165. if (paramData.hints & PARAMETER_USES_SAMPLERATE)
  1166. hints |= NATIVE_PARAMETER_USES_SAMPLE_RATE;
  1167. if (paramData.hints & PARAMETER_USES_SCALEPOINTS)
  1168. hints |= NATIVE_PARAMETER_USES_SCALEPOINTS;
  1169. if (paramData.type == PARAMETER_INPUT || paramData.type == PARAMETER_OUTPUT)
  1170. {
  1171. if (paramData.hints & PARAMETER_IS_ENABLED)
  1172. hints |= NATIVE_PARAMETER_IS_ENABLED;
  1173. if (paramData.type == PARAMETER_OUTPUT)
  1174. hints |= NATIVE_PARAMETER_IS_OUTPUT;
  1175. }
  1176. param.hints = static_cast<NativeParameterHints>(hints);
  1177. param.name = strBufName;
  1178. param.unit = strBufUnit;
  1179. param.ranges.def = paramRanges.def;
  1180. param.ranges.min = paramRanges.min;
  1181. param.ranges.max = paramRanges.max;
  1182. param.ranges.step = paramRanges.step;
  1183. param.ranges.stepSmall = paramRanges.stepSmall;
  1184. param.ranges.stepLarge = paramRanges.stepLarge;
  1185. param.scalePointCount = 0; // TODO
  1186. param.scalePoints = nullptr;
  1187. return &param;
  1188. }
  1189. }
  1190. return nullptr;
  1191. }
  1192. float getParameterValue(const uint32_t index) const
  1193. {
  1194. if (CarlaPlugin* const plugin = _getFirstPlugin())
  1195. {
  1196. if (index < plugin->getParameterCount())
  1197. return plugin->getParameterValue(index);
  1198. }
  1199. return 0.0f;
  1200. }
  1201. // -------------------------------------------------------------------
  1202. // Plugin midi-program calls
  1203. uint32_t getMidiProgramCount() const
  1204. {
  1205. if (CarlaPlugin* const plugin = _getFirstPlugin())
  1206. return plugin->getMidiProgramCount();
  1207. return 0;
  1208. }
  1209. const NativeMidiProgram* getMidiProgramInfo(const uint32_t index) const
  1210. {
  1211. if (CarlaPlugin* const plugin = _getFirstPlugin())
  1212. {
  1213. if (index < plugin->getMidiProgramCount())
  1214. {
  1215. static NativeMidiProgram midiProg;
  1216. {
  1217. const MidiProgramData& midiProgData(plugin->getMidiProgramData(index));
  1218. midiProg.bank = midiProgData.bank;
  1219. midiProg.program = midiProgData.program;
  1220. midiProg.name = midiProgData.name;
  1221. }
  1222. return &midiProg;
  1223. }
  1224. }
  1225. return nullptr;
  1226. }
  1227. // -------------------------------------------------------------------
  1228. // Plugin state calls
  1229. void setParameterValue(const uint32_t index, const float value)
  1230. {
  1231. if (CarlaPlugin* const plugin = _getFirstPlugin())
  1232. {
  1233. if (index < plugin->getParameterCount())
  1234. plugin->setParameterValue(index, value, false, false, false);
  1235. }
  1236. }
  1237. void setMidiProgram(const uint8_t, const uint32_t bank, const uint32_t program)
  1238. {
  1239. if (CarlaPlugin* const plugin = _getFirstPlugin())
  1240. plugin->setMidiProgramById(bank, program, false, false, false);
  1241. }
  1242. // -------------------------------------------------------------------
  1243. // Plugin process calls
  1244. void activate()
  1245. {
  1246. #if 0
  1247. for (uint i=0; i < pData->curPluginCount; ++i)
  1248. {
  1249. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1250. if (plugin == nullptr || ! plugin->isEnabled())
  1251. continue;
  1252. plugin->setActive(true, true, false);
  1253. }
  1254. #endif
  1255. fIsActive = true;
  1256. }
  1257. void deactivate()
  1258. {
  1259. fIsActive = false;
  1260. #if 0
  1261. for (uint i=0; i < pData->curPluginCount; ++i)
  1262. {
  1263. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1264. if (plugin == nullptr || ! plugin->isEnabled())
  1265. continue;
  1266. plugin->setActive(false, true, false);
  1267. }
  1268. #endif
  1269. // just in case
  1270. //runPendingRtEvents();
  1271. }
  1272. void process(float** const inBuffer, float** const outBuffer, const uint32_t frames,
  1273. const NativeMidiEvent* const midiEvents, const uint32_t midiEventCount)
  1274. {
  1275. const PendingRtEventsRunner prt(this, frames);
  1276. // ---------------------------------------------------------------
  1277. // Time Info
  1278. const NativeTimeInfo* const timeInfo(pHost->get_time_info(pHost->handle));
  1279. pData->timeInfo.playing = timeInfo->playing;
  1280. pData->timeInfo.frame = timeInfo->frame;
  1281. pData->timeInfo.usecs = timeInfo->usecs;
  1282. pData->timeInfo.bbt.valid = timeInfo->bbt.valid;
  1283. if (timeInfo->bbt.valid)
  1284. {
  1285. pData->timeInfo.bbt.bar = timeInfo->bbt.bar;
  1286. pData->timeInfo.bbt.beat = timeInfo->bbt.beat;
  1287. pData->timeInfo.bbt.tick = timeInfo->bbt.tick;
  1288. pData->timeInfo.bbt.barStartTick = timeInfo->bbt.barStartTick;
  1289. pData->timeInfo.bbt.beatsPerBar = timeInfo->bbt.beatsPerBar;
  1290. pData->timeInfo.bbt.beatType = timeInfo->bbt.beatType;
  1291. pData->timeInfo.bbt.ticksPerBeat = timeInfo->bbt.ticksPerBeat;
  1292. pData->timeInfo.bbt.beatsPerMinute = timeInfo->bbt.beatsPerMinute;
  1293. }
  1294. // ---------------------------------------------------------------
  1295. // Do nothing if no plugins and rack mode
  1296. if (pData->curPluginCount == 0 && ! kIsPatchbay)
  1297. {
  1298. if (outBuffer[0] != inBuffer[0])
  1299. carla_copyFloats(outBuffer[0], inBuffer[0], frames);
  1300. if (outBuffer[1] != inBuffer[1])
  1301. carla_copyFloats(outBuffer[1], inBuffer[1], frames);
  1302. for (uint32_t i=0; i < midiEventCount; ++i)
  1303. {
  1304. if (! pHost->write_midi_event(pHost->handle, &midiEvents[i]))
  1305. break;
  1306. }
  1307. return;
  1308. }
  1309. // ---------------------------------------------------------------
  1310. // initialize events
  1311. carla_zeroStructs(pData->events.in, kMaxEngineEventInternalCount);
  1312. carla_zeroStructs(pData->events.out, kMaxEngineEventInternalCount);
  1313. // ---------------------------------------------------------------
  1314. // events input (before processing)
  1315. {
  1316. uint32_t engineEventIndex = 0;
  1317. for (uint32_t i=0; i < midiEventCount && engineEventIndex < kMaxEngineEventInternalCount; ++i)
  1318. {
  1319. const NativeMidiEvent& midiEvent(midiEvents[i]);
  1320. EngineEvent& engineEvent(pData->events.in[engineEventIndex++]);
  1321. engineEvent.time = midiEvent.time;
  1322. engineEvent.fillFromMidiData(midiEvent.size, midiEvent.data, 0);
  1323. if (engineEventIndex >= kMaxEngineEventInternalCount)
  1324. break;
  1325. }
  1326. }
  1327. if (kIsPatchbay)
  1328. {
  1329. // -----------------------------------------------------------
  1330. // process
  1331. pData->graph.process(pData, inBuffer, outBuffer, frames);
  1332. }
  1333. else
  1334. {
  1335. // -----------------------------------------------------------
  1336. // create audio buffers
  1337. const float* inBuf[2] = { inBuffer[0], inBuffer[1] };
  1338. /* */ float* outBuf[2] = { outBuffer[0], outBuffer[1] };
  1339. // -----------------------------------------------------------
  1340. // process
  1341. pData->graph.processRack(pData, inBuf, outBuf, frames);
  1342. }
  1343. // ---------------------------------------------------------------
  1344. // events output (after processing)
  1345. carla_zeroStructs(pData->events.in, kMaxEngineEventInternalCount);
  1346. if (kHasMidiOut)
  1347. {
  1348. NativeMidiEvent midiEvent;
  1349. for (uint32_t i=0; i < kMaxEngineEventInternalCount; ++i)
  1350. {
  1351. const EngineEvent& engineEvent(pData->events.out[i]);
  1352. if (engineEvent.type == kEngineEventTypeNull)
  1353. break;
  1354. carla_zeroStruct(midiEvent);
  1355. midiEvent.time = engineEvent.time;
  1356. /**/ if (engineEvent.type == kEngineEventTypeControl)
  1357. {
  1358. midiEvent.port = 0;
  1359. midiEvent.size = engineEvent.ctrl.convertToMidiData(engineEvent.channel, midiEvent.data);
  1360. }
  1361. else if (engineEvent.type == kEngineEventTypeMidi)
  1362. {
  1363. if (engineEvent.midi.size > 4)
  1364. continue;
  1365. midiEvent.port = engineEvent.midi.port;
  1366. midiEvent.size = engineEvent.midi.size;
  1367. midiEvent.data[0] = static_cast<uint8_t>(engineEvent.midi.data[0] | (engineEvent.channel & MIDI_CHANNEL_BIT));
  1368. for (uint8_t j=1; j < midiEvent.size; ++j)
  1369. midiEvent.data[j] = engineEvent.midi.data[j];
  1370. }
  1371. else
  1372. {
  1373. continue;
  1374. }
  1375. if (midiEvent.size > 0)
  1376. pHost->write_midi_event(pHost->handle, &midiEvent);
  1377. }
  1378. }
  1379. }
  1380. // -------------------------------------------------------------------
  1381. // Plugin UI calls
  1382. void uiShow(const bool show)
  1383. {
  1384. if (show)
  1385. {
  1386. if (fUiServer.isPipeRunning())
  1387. {
  1388. fUiServer.writeFocusMessage();
  1389. return;
  1390. }
  1391. CarlaString path(pHost->resourceDir);
  1392. if (kIsPatchbay)
  1393. path += CARLA_OS_SEP_STR "carla-plugin-patchbay";
  1394. else
  1395. path += CARLA_OS_SEP_STR "carla-plugin";
  1396. #ifdef CARLA_OS_WIN
  1397. path += ".exe";
  1398. #endif
  1399. carla_stdout("Trying to start carla-plugin using \"%s\"", path.buffer());
  1400. fUiServer.setData(path, pData->sampleRate, pHost->uiName);
  1401. if (! fUiServer.startPipeServer(false))
  1402. {
  1403. pHost->dispatcher(pHost->handle, NATIVE_HOST_OPCODE_UI_UNAVAILABLE, 0, 0, nullptr, 0.0f);
  1404. return;
  1405. }
  1406. uiServerInfo();
  1407. uiServerOptions();
  1408. uiServerCallback(ENGINE_CALLBACK_ENGINE_STARTED, 0,
  1409. pData->options.processMode, pData->options.transportMode,
  1410. static_cast<float>(pData->sampleRate), "Plugin");
  1411. fUiServer.writeShowMessage();
  1412. for (uint i=0; i < pData->curPluginCount; ++i)
  1413. {
  1414. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1415. if (plugin != nullptr && plugin->isEnabled())
  1416. {
  1417. uiServerCallback(ENGINE_CALLBACK_PLUGIN_ADDED, i, 0, 0, 0.0f, plugin->getName());
  1418. }
  1419. }
  1420. if (kIsPatchbay)
  1421. patchbayRefresh(false);
  1422. }
  1423. else
  1424. {
  1425. fUiServer.stopPipeServer(2000);
  1426. // hide all custom uis
  1427. for (uint i=0; i < pData->curPluginCount; ++i)
  1428. {
  1429. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1430. if (plugin != nullptr && plugin->isEnabled())
  1431. {
  1432. if (plugin->getHints() & PLUGIN_HAS_CUSTOM_UI)
  1433. {
  1434. try {
  1435. plugin->showCustomUI(false);
  1436. } CARLA_SAFE_EXCEPTION_CONTINUE("Plugin showCustomUI (hide)");
  1437. }
  1438. }
  1439. }
  1440. }
  1441. }
  1442. void uiIdle()
  1443. {
  1444. for (uint i=0; i < pData->curPluginCount; ++i)
  1445. {
  1446. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1447. if (plugin != nullptr && plugin->isEnabled())
  1448. {
  1449. const uint hints(plugin->getHints());
  1450. if ((hints & PLUGIN_HAS_CUSTOM_UI) != 0 && (hints & PLUGIN_NEEDS_UI_MAIN_THREAD) != 0)
  1451. {
  1452. try {
  1453. plugin->uiIdle();
  1454. } CARLA_SAFE_EXCEPTION_CONTINUE("Plugin uiIdle");
  1455. }
  1456. }
  1457. }
  1458. idlePipe();
  1459. switch (fUiServer.getAndResetUiState())
  1460. {
  1461. case CarlaExternalUI::UiNone:
  1462. case CarlaExternalUI::UiShow:
  1463. break;
  1464. case CarlaExternalUI::UiCrashed:
  1465. pHost->dispatcher(pHost->handle, NATIVE_HOST_OPCODE_UI_UNAVAILABLE, 0, 0, nullptr, 0.0f);
  1466. break;
  1467. case CarlaExternalUI::UiHide:
  1468. pHost->ui_closed(pHost->handle);
  1469. fUiServer.stopPipeServer(1000);
  1470. break;
  1471. }
  1472. }
  1473. void idlePipe()
  1474. {
  1475. if (! fUiServer.isPipeRunning())
  1476. return;
  1477. fUiServer.idlePipe();
  1478. char tmpBuf[STR_MAX];
  1479. carla_zeroChars(tmpBuf, STR_MAX);
  1480. const CarlaMutexLocker cml(fUiServer.getPipeLock());
  1481. const CarlaScopedLocale csl;
  1482. const EngineTimeInfo& timeInfo(pData->timeInfo);
  1483. // send transport
  1484. if (! fUiServer.writeAndFixMessage("transport"))
  1485. return;
  1486. if (! fUiServer.writeMessage(timeInfo.playing ? "true\n" : "false\n"))
  1487. return;
  1488. if (timeInfo.bbt.valid)
  1489. {
  1490. std::sprintf(tmpBuf, P_UINT64 ":%i:%i:%i\n",
  1491. timeInfo.frame, timeInfo.bbt.bar, timeInfo.bbt.beat, static_cast<int>(timeInfo.bbt.tick + 0.5));
  1492. if (! fUiServer.writeMessage(tmpBuf))
  1493. return;
  1494. std::sprintf(tmpBuf, "%f\n", timeInfo.bbt.beatsPerMinute);
  1495. if (! fUiServer.writeMessage(tmpBuf))
  1496. return;
  1497. }
  1498. else
  1499. {
  1500. std::sprintf(tmpBuf, P_UINT64 ":0:0:0\n", timeInfo.frame);
  1501. if (! fUiServer.writeMessage(tmpBuf))
  1502. return;
  1503. if (! fUiServer.writeMessage("0.0\n"))
  1504. return;
  1505. }
  1506. fUiServer.flushMessages();
  1507. // send peaks and param outputs for all plugins
  1508. for (uint i=0; i < pData->curPluginCount; ++i)
  1509. {
  1510. const EnginePluginData& plugData(pData->plugins[i]);
  1511. const CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1512. std::sprintf(tmpBuf, "PEAKS_%i\n", i);
  1513. if (! fUiServer.writeMessage(tmpBuf))
  1514. return;
  1515. std::sprintf(tmpBuf, "%f:%f:%f:%f\n",
  1516. static_cast<double>(plugData.peaks[0]),
  1517. static_cast<double>(plugData.peaks[1]),
  1518. static_cast<double>(plugData.peaks[2]),
  1519. static_cast<double>(plugData.peaks[3]));
  1520. if (! fUiServer.writeMessage(tmpBuf))
  1521. return;
  1522. fUiServer.flushMessages();
  1523. for (uint32_t j=0, count=plugin->getParameterCount(); j < count; ++j)
  1524. {
  1525. if (! plugin->isParameterOutput(j))
  1526. continue;
  1527. std::sprintf(tmpBuf, "PARAMVAL_%i:%i\n", i, j);
  1528. if (! fUiServer.writeMessage(tmpBuf))
  1529. return;
  1530. std::sprintf(tmpBuf, "%f\n", static_cast<double>(plugin->getParameterValue(j)));
  1531. if (! fUiServer.writeMessage(tmpBuf))
  1532. return;
  1533. fUiServer.flushMessages();
  1534. }
  1535. }
  1536. }
  1537. // -------------------------------------------------------------------
  1538. // Plugin state calls
  1539. char* getState() const
  1540. {
  1541. MemoryOutputStream out;
  1542. saveProjectInternal(out);
  1543. return strdup(out.toString().toRawUTF8());
  1544. }
  1545. void setState(const char* const data)
  1546. {
  1547. // remove all plugins from UI side
  1548. for (uint i=0, count=pData->curPluginCount; i < count; ++i)
  1549. CarlaEngine::callback(ENGINE_CALLBACK_PLUGIN_REMOVED, count-i-1, 0, 0, 0.0f, nullptr);
  1550. // remove all plugins from backend, no lock
  1551. fIsRunning = false;
  1552. removeAllPlugins();
  1553. fIsRunning = true;
  1554. // stopped during removeAllPlugins()
  1555. if (! pData->thread.isThreadRunning())
  1556. pData->thread.startThread();
  1557. fOptionsForced = true;
  1558. const String state(data);
  1559. XmlDocument xml(state);
  1560. loadProjectInternal(xml);
  1561. }
  1562. // -------------------------------------------------------------------
  1563. public:
  1564. #define handlePtr ((CarlaEngineNative*)handle)
  1565. static NativePluginHandle _instantiateRack(const NativeHostDescriptor* host)
  1566. {
  1567. return new CarlaEngineNative(host, false, true);
  1568. }
  1569. static NativePluginHandle _instantiateRackNoMidiOut(const NativeHostDescriptor* host)
  1570. {
  1571. return new CarlaEngineNative(host, false, false);
  1572. }
  1573. static NativePluginHandle _instantiatePatchbay(const NativeHostDescriptor* host)
  1574. {
  1575. return new CarlaEngineNative(host, true, true);
  1576. }
  1577. static NativePluginHandle _instantiatePatchbay3s(const NativeHostDescriptor* host)
  1578. {
  1579. return new CarlaEngineNative(host, true, true, 3, 2);
  1580. }
  1581. static NativePluginHandle _instantiatePatchbay16(const NativeHostDescriptor* host)
  1582. {
  1583. return new CarlaEngineNative(host, true, true, 16, 16);
  1584. }
  1585. static NativePluginHandle _instantiatePatchbay32(const NativeHostDescriptor* host)
  1586. {
  1587. return new CarlaEngineNative(host, true, true, 32, 32);
  1588. }
  1589. static void _cleanup(NativePluginHandle handle)
  1590. {
  1591. delete handlePtr;
  1592. }
  1593. static uint32_t _get_parameter_count(NativePluginHandle handle)
  1594. {
  1595. return handlePtr->getParameterCount();
  1596. }
  1597. static const NativeParameter* _get_parameter_info(NativePluginHandle handle, uint32_t index)
  1598. {
  1599. return handlePtr->getParameterInfo(index);
  1600. }
  1601. static float _get_parameter_value(NativePluginHandle handle, uint32_t index)
  1602. {
  1603. return handlePtr->getParameterValue(index);
  1604. }
  1605. static uint32_t _get_midi_program_count(NativePluginHandle handle)
  1606. {
  1607. return handlePtr->getMidiProgramCount();
  1608. }
  1609. static const NativeMidiProgram* _get_midi_program_info(NativePluginHandle handle, uint32_t index)
  1610. {
  1611. return handlePtr->getMidiProgramInfo(index);
  1612. }
  1613. static void _set_parameter_value(NativePluginHandle handle, uint32_t index, float value)
  1614. {
  1615. handlePtr->setParameterValue(index, value);
  1616. }
  1617. static void _set_midi_program(NativePluginHandle handle, uint8_t channel, uint32_t bank, uint32_t program)
  1618. {
  1619. handlePtr->setMidiProgram(channel, bank, program);
  1620. }
  1621. static void _ui_show(NativePluginHandle handle, bool show)
  1622. {
  1623. handlePtr->uiShow(show);
  1624. }
  1625. static void _ui_idle(NativePluginHandle handle)
  1626. {
  1627. handlePtr->uiIdle();
  1628. }
  1629. static void _activate(NativePluginHandle handle)
  1630. {
  1631. handlePtr->activate();
  1632. }
  1633. static void _deactivate(NativePluginHandle handle)
  1634. {
  1635. handlePtr->deactivate();
  1636. }
  1637. static void _process(NativePluginHandle handle, float** inBuffer, float** outBuffer, const uint32_t frames, const NativeMidiEvent* midiEvents, uint32_t midiEventCount)
  1638. {
  1639. handlePtr->process(inBuffer, outBuffer, frames, midiEvents, midiEventCount);
  1640. }
  1641. static char* _get_state(NativePluginHandle handle)
  1642. {
  1643. return handlePtr->getState();
  1644. }
  1645. static void _set_state(NativePluginHandle handle, const char* data)
  1646. {
  1647. handlePtr->setState(data);
  1648. }
  1649. static intptr_t _dispatcher(NativePluginHandle handle, NativePluginDispatcherOpcode opcode, int32_t index, intptr_t value, void* ptr, float opt)
  1650. {
  1651. switch(opcode)
  1652. {
  1653. case NATIVE_PLUGIN_OPCODE_NULL:
  1654. return 0;
  1655. case NATIVE_PLUGIN_OPCODE_BUFFER_SIZE_CHANGED:
  1656. CARLA_SAFE_ASSERT_RETURN(value > 0, 0);
  1657. handlePtr->bufferSizeChanged(static_cast<uint32_t>(value));
  1658. return 0;
  1659. case NATIVE_PLUGIN_OPCODE_SAMPLE_RATE_CHANGED:
  1660. CARLA_SAFE_ASSERT_RETURN(opt > 0.0f, 0);
  1661. handlePtr->sampleRateChanged(static_cast<double>(opt));
  1662. return 0;
  1663. case NATIVE_PLUGIN_OPCODE_OFFLINE_CHANGED:
  1664. handlePtr->offlineModeChanged(value != 0);
  1665. return 0;
  1666. case NATIVE_PLUGIN_OPCODE_UI_NAME_CHANGED:
  1667. //handlePtr->uiNameChanged(static_cast<const char*>(ptr));
  1668. return 0;
  1669. case NATIVE_PLUGIN_OPCODE_GET_INTERNAL_HANDLE: {
  1670. CarlaEngineNative* const engine = handlePtr;
  1671. return (intptr_t)(CarlaEngine*)engine;
  1672. }
  1673. }
  1674. return 0;
  1675. // unused
  1676. (void)index;
  1677. (void)ptr;
  1678. }
  1679. // -------------------------------------------------------------------
  1680. static void _ui_server_callback(void* handle, EngineCallbackOpcode action, uint pluginId, int value1, int value2, float value3, const char* valueStr)
  1681. {
  1682. handlePtr->uiServerCallback(action, pluginId, value1, value2, value3, valueStr);
  1683. }
  1684. static const char* _ui_file_callback(void* handle, FileCallbackOpcode action, bool isDir, const char* title, const char* filter)
  1685. {
  1686. return handlePtr->uiFileCallback(action, isDir, title, filter);
  1687. }
  1688. // -------------------------------------------------------------------
  1689. #undef handlePtr
  1690. private:
  1691. const NativeHostDescriptor* const pHost;
  1692. #ifdef USE_JUCE_MESSAGE_THREAD
  1693. const bool kNeedsJuceMsgThread;
  1694. const juce::SharedResourcePointer<SharedJuceMessageThread> fJuceMsgThread;
  1695. #endif
  1696. const bool kIsPatchbay; // rack if false
  1697. const bool kHasMidiOut;
  1698. bool fIsActive, fIsRunning;
  1699. CarlaEngineNativeUI fUiServer;
  1700. bool fOptionsForced;
  1701. CarlaPlugin* _getFirstPlugin() const noexcept
  1702. {
  1703. if (pData->curPluginCount == 0 || pData->plugins == nullptr)
  1704. return nullptr;
  1705. CarlaPlugin* const plugin(pData->plugins[0].plugin);
  1706. if (plugin == nullptr || ! plugin->isEnabled())
  1707. return nullptr;
  1708. return pData->plugins[0].plugin;
  1709. }
  1710. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineNative)
  1711. };
  1712. // -----------------------------------------------------------------------
  1713. static const NativePluginDescriptor carlaRackDesc = {
  1714. /* category */ NATIVE_PLUGIN_CATEGORY_OTHER,
  1715. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_SYNTH
  1716. |NATIVE_PLUGIN_HAS_UI
  1717. |NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
  1718. |NATIVE_PLUGIN_USES_STATE
  1719. |NATIVE_PLUGIN_USES_TIME),
  1720. /* supports */ static_cast<NativePluginSupports>(NATIVE_PLUGIN_SUPPORTS_EVERYTHING),
  1721. /* audioIns */ 2,
  1722. /* audioOuts */ 2,
  1723. /* midiIns */ 1,
  1724. /* midiOuts */ 1,
  1725. /* paramIns */ 0,
  1726. /* paramOuts */ 0,
  1727. /* name */ "Carla-Rack",
  1728. /* label */ "carlarack",
  1729. /* maker */ "falkTX",
  1730. /* copyright */ "GNU GPL v2+",
  1731. CarlaEngineNative::_instantiateRack,
  1732. CarlaEngineNative::_cleanup,
  1733. CarlaEngineNative::_get_parameter_count,
  1734. CarlaEngineNative::_get_parameter_info,
  1735. CarlaEngineNative::_get_parameter_value,
  1736. CarlaEngineNative::_get_midi_program_count,
  1737. CarlaEngineNative::_get_midi_program_info,
  1738. CarlaEngineNative::_set_parameter_value,
  1739. CarlaEngineNative::_set_midi_program,
  1740. /* _set_custom_data */ nullptr,
  1741. CarlaEngineNative::_ui_show,
  1742. CarlaEngineNative::_ui_idle,
  1743. /* _ui_set_parameter_value */ nullptr,
  1744. /* _ui_set_midi_program */ nullptr,
  1745. /* _ui_set_custom_data */ nullptr,
  1746. CarlaEngineNative::_activate,
  1747. CarlaEngineNative::_deactivate,
  1748. CarlaEngineNative::_process,
  1749. CarlaEngineNative::_get_state,
  1750. CarlaEngineNative::_set_state,
  1751. CarlaEngineNative::_dispatcher
  1752. };
  1753. static const NativePluginDescriptor carlaRackNoMidiOutDesc = {
  1754. /* category */ NATIVE_PLUGIN_CATEGORY_OTHER,
  1755. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_SYNTH
  1756. |NATIVE_PLUGIN_HAS_UI
  1757. |NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
  1758. |NATIVE_PLUGIN_USES_STATE
  1759. |NATIVE_PLUGIN_USES_TIME),
  1760. /* supports */ static_cast<NativePluginSupports>(NATIVE_PLUGIN_SUPPORTS_EVERYTHING),
  1761. /* audioIns */ 2,
  1762. /* audioOuts */ 2,
  1763. /* midiIns */ 1,
  1764. /* midiOuts */ 0,
  1765. /* paramIns */ 0,
  1766. /* paramOuts */ 0,
  1767. /* name */ "Carla-Rack (no midi out)",
  1768. /* label */ "carlarack-nomidiout",
  1769. /* maker */ "falkTX",
  1770. /* copyright */ "GNU GPL v2+",
  1771. CarlaEngineNative::_instantiateRackNoMidiOut,
  1772. CarlaEngineNative::_cleanup,
  1773. CarlaEngineNative::_get_parameter_count,
  1774. CarlaEngineNative::_get_parameter_info,
  1775. CarlaEngineNative::_get_parameter_value,
  1776. CarlaEngineNative::_get_midi_program_count,
  1777. CarlaEngineNative::_get_midi_program_info,
  1778. CarlaEngineNative::_set_parameter_value,
  1779. CarlaEngineNative::_set_midi_program,
  1780. /* _set_custom_data */ nullptr,
  1781. CarlaEngineNative::_ui_show,
  1782. CarlaEngineNative::_ui_idle,
  1783. /* _ui_set_parameter_value */ nullptr,
  1784. /* _ui_set_midi_program */ nullptr,
  1785. /* _ui_set_custom_data */ nullptr,
  1786. CarlaEngineNative::_activate,
  1787. CarlaEngineNative::_deactivate,
  1788. CarlaEngineNative::_process,
  1789. CarlaEngineNative::_get_state,
  1790. CarlaEngineNative::_set_state,
  1791. CarlaEngineNative::_dispatcher
  1792. };
  1793. static const NativePluginDescriptor carlaPatchbayDesc = {
  1794. /* category */ NATIVE_PLUGIN_CATEGORY_OTHER,
  1795. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_SYNTH
  1796. |NATIVE_PLUGIN_HAS_UI
  1797. |NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
  1798. |NATIVE_PLUGIN_USES_STATE
  1799. |NATIVE_PLUGIN_USES_TIME),
  1800. /* supports */ static_cast<NativePluginSupports>(NATIVE_PLUGIN_SUPPORTS_EVERYTHING),
  1801. /* audioIns */ 2,
  1802. /* audioOuts */ 2,
  1803. /* midiIns */ 1,
  1804. /* midiOuts */ 1,
  1805. /* paramIns */ 0,
  1806. /* paramOuts */ 0,
  1807. /* name */ "Carla-Patchbay",
  1808. /* label */ "carlapatchbay",
  1809. /* maker */ "falkTX",
  1810. /* copyright */ "GNU GPL v2+",
  1811. CarlaEngineNative::_instantiatePatchbay,
  1812. CarlaEngineNative::_cleanup,
  1813. CarlaEngineNative::_get_parameter_count,
  1814. CarlaEngineNative::_get_parameter_info,
  1815. CarlaEngineNative::_get_parameter_value,
  1816. CarlaEngineNative::_get_midi_program_count,
  1817. CarlaEngineNative::_get_midi_program_info,
  1818. CarlaEngineNative::_set_parameter_value,
  1819. CarlaEngineNative::_set_midi_program,
  1820. /* _set_custom_data */ nullptr,
  1821. CarlaEngineNative::_ui_show,
  1822. CarlaEngineNative::_ui_idle,
  1823. /* _ui_set_parameter_value */ nullptr,
  1824. /* _ui_set_midi_program */ nullptr,
  1825. /* _ui_set_custom_data */ nullptr,
  1826. CarlaEngineNative::_activate,
  1827. CarlaEngineNative::_deactivate,
  1828. CarlaEngineNative::_process,
  1829. CarlaEngineNative::_get_state,
  1830. CarlaEngineNative::_set_state,
  1831. CarlaEngineNative::_dispatcher
  1832. };
  1833. static const NativePluginDescriptor carlaPatchbay3sDesc = {
  1834. /* category */ NATIVE_PLUGIN_CATEGORY_OTHER,
  1835. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_SYNTH
  1836. |NATIVE_PLUGIN_HAS_UI
  1837. |NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
  1838. |NATIVE_PLUGIN_USES_STATE
  1839. |NATIVE_PLUGIN_USES_TIME),
  1840. /* supports */ static_cast<NativePluginSupports>(NATIVE_PLUGIN_SUPPORTS_EVERYTHING),
  1841. /* audioIns */ 3,
  1842. /* audioOuts */ 2,
  1843. /* midiIns */ 1,
  1844. /* midiOuts */ 1,
  1845. /* paramIns */ 0,
  1846. /* paramOuts */ 0,
  1847. /* name */ "Carla-Patchbay (sidechain)",
  1848. /* label */ "carlapatchbay3s",
  1849. /* maker */ "falkTX",
  1850. /* copyright */ "GNU GPL v2+",
  1851. CarlaEngineNative::_instantiatePatchbay3s,
  1852. CarlaEngineNative::_cleanup,
  1853. CarlaEngineNative::_get_parameter_count,
  1854. CarlaEngineNative::_get_parameter_info,
  1855. CarlaEngineNative::_get_parameter_value,
  1856. CarlaEngineNative::_get_midi_program_count,
  1857. CarlaEngineNative::_get_midi_program_info,
  1858. CarlaEngineNative::_set_parameter_value,
  1859. CarlaEngineNative::_set_midi_program,
  1860. /* _set_custom_data */ nullptr,
  1861. CarlaEngineNative::_ui_show,
  1862. CarlaEngineNative::_ui_idle,
  1863. /* _ui_set_parameter_value */ nullptr,
  1864. /* _ui_set_midi_program */ nullptr,
  1865. /* _ui_set_custom_data */ nullptr,
  1866. CarlaEngineNative::_activate,
  1867. CarlaEngineNative::_deactivate,
  1868. CarlaEngineNative::_process,
  1869. CarlaEngineNative::_get_state,
  1870. CarlaEngineNative::_set_state,
  1871. CarlaEngineNative::_dispatcher
  1872. };
  1873. static const NativePluginDescriptor carlaPatchbay16Desc = {
  1874. /* category */ NATIVE_PLUGIN_CATEGORY_OTHER,
  1875. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_SYNTH
  1876. |NATIVE_PLUGIN_HAS_UI
  1877. |NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
  1878. |NATIVE_PLUGIN_USES_STATE
  1879. |NATIVE_PLUGIN_USES_TIME),
  1880. /* supports */ static_cast<NativePluginSupports>(NATIVE_PLUGIN_SUPPORTS_EVERYTHING),
  1881. /* audioIns */ 16,
  1882. /* audioOuts */ 16,
  1883. /* midiIns */ 1,
  1884. /* midiOuts */ 1,
  1885. /* paramIns */ 0,
  1886. /* paramOuts */ 0,
  1887. /* name */ "Carla-Patchbay (16chan)",
  1888. /* label */ "carlapatchbay16",
  1889. /* maker */ "falkTX",
  1890. /* copyright */ "GNU GPL v2+",
  1891. CarlaEngineNative::_instantiatePatchbay16,
  1892. CarlaEngineNative::_cleanup,
  1893. CarlaEngineNative::_get_parameter_count,
  1894. CarlaEngineNative::_get_parameter_info,
  1895. CarlaEngineNative::_get_parameter_value,
  1896. CarlaEngineNative::_get_midi_program_count,
  1897. CarlaEngineNative::_get_midi_program_info,
  1898. CarlaEngineNative::_set_parameter_value,
  1899. CarlaEngineNative::_set_midi_program,
  1900. /* _set_custom_data */ nullptr,
  1901. CarlaEngineNative::_ui_show,
  1902. CarlaEngineNative::_ui_idle,
  1903. /* _ui_set_parameter_value */ nullptr,
  1904. /* _ui_set_midi_program */ nullptr,
  1905. /* _ui_set_custom_data */ nullptr,
  1906. CarlaEngineNative::_activate,
  1907. CarlaEngineNative::_deactivate,
  1908. CarlaEngineNative::_process,
  1909. CarlaEngineNative::_get_state,
  1910. CarlaEngineNative::_set_state,
  1911. CarlaEngineNative::_dispatcher
  1912. };
  1913. static const NativePluginDescriptor carlaPatchbay32Desc = {
  1914. /* category */ NATIVE_PLUGIN_CATEGORY_OTHER,
  1915. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_SYNTH
  1916. |NATIVE_PLUGIN_HAS_UI
  1917. |NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
  1918. |NATIVE_PLUGIN_USES_STATE
  1919. |NATIVE_PLUGIN_USES_TIME),
  1920. /* supports */ static_cast<NativePluginSupports>(NATIVE_PLUGIN_SUPPORTS_EVERYTHING),
  1921. /* audioIns */ 32,
  1922. /* audioOuts */ 32,
  1923. /* midiIns */ 1,
  1924. /* midiOuts */ 1,
  1925. /* paramIns */ 0,
  1926. /* paramOuts */ 0,
  1927. /* name */ "Carla-Patchbay (32chan)",
  1928. /* label */ "carlapatchbay32",
  1929. /* maker */ "falkTX",
  1930. /* copyright */ "GNU GPL v2+",
  1931. CarlaEngineNative::_instantiatePatchbay32,
  1932. CarlaEngineNative::_cleanup,
  1933. CarlaEngineNative::_get_parameter_count,
  1934. CarlaEngineNative::_get_parameter_info,
  1935. CarlaEngineNative::_get_parameter_value,
  1936. CarlaEngineNative::_get_midi_program_count,
  1937. CarlaEngineNative::_get_midi_program_info,
  1938. CarlaEngineNative::_set_parameter_value,
  1939. CarlaEngineNative::_set_midi_program,
  1940. /* _set_custom_data */ nullptr,
  1941. CarlaEngineNative::_ui_show,
  1942. CarlaEngineNative::_ui_idle,
  1943. /* _ui_set_parameter_value */ nullptr,
  1944. /* _ui_set_midi_program */ nullptr,
  1945. /* _ui_set_custom_data */ nullptr,
  1946. CarlaEngineNative::_activate,
  1947. CarlaEngineNative::_deactivate,
  1948. CarlaEngineNative::_process,
  1949. CarlaEngineNative::_get_state,
  1950. CarlaEngineNative::_set_state,
  1951. CarlaEngineNative::_dispatcher
  1952. };
  1953. CARLA_BACKEND_END_NAMESPACE
  1954. // -----------------------------------------------------------------------
  1955. CARLA_EXPORT
  1956. void carla_register_native_plugin_carla();
  1957. void carla_register_native_plugin_carla()
  1958. {
  1959. CARLA_BACKEND_USE_NAMESPACE;
  1960. carla_register_native_plugin(&carlaRackDesc);
  1961. carla_register_native_plugin(&carlaRackNoMidiOutDesc);
  1962. carla_register_native_plugin(&carlaPatchbayDesc);
  1963. carla_register_native_plugin(&carlaPatchbay3sDesc);
  1964. carla_register_native_plugin(&carlaPatchbay16Desc);
  1965. carla_register_native_plugin(&carlaPatchbay32Desc);
  1966. }
  1967. // -----------------------------------------------------------------------
  1968. const NativePluginDescriptor* carla_get_native_rack_plugin()
  1969. {
  1970. CARLA_BACKEND_USE_NAMESPACE;
  1971. return &carlaRackDesc;
  1972. }
  1973. const NativePluginDescriptor* carla_get_native_patchbay_plugin()
  1974. {
  1975. CARLA_BACKEND_USE_NAMESPACE;
  1976. return &carlaPatchbayDesc;
  1977. }
  1978. const NativePluginDescriptor* carla_get_native_patchbay16_plugin()
  1979. {
  1980. CARLA_BACKEND_USE_NAMESPACE;
  1981. return &carlaPatchbay16Desc;
  1982. }
  1983. const NativePluginDescriptor* carla_get_native_patchbay32_plugin()
  1984. {
  1985. CARLA_BACKEND_USE_NAMESPACE;
  1986. return &carlaPatchbay32Desc;
  1987. }
  1988. // -----------------------------------------------------------------------
  1989. // Extra stuff for linking purposes
  1990. #ifdef CARLA_PLUGIN_EXPORT
  1991. CARLA_BACKEND_START_NAMESPACE
  1992. CarlaEngine* CarlaEngine::newJack() { return nullptr; }
  1993. # ifdef USING_JUCE
  1994. CarlaEngine* CarlaEngine::newJuce(const AudioApi) { return nullptr; }
  1995. uint CarlaEngine::getJuceApiCount() { return 0; }
  1996. const char* CarlaEngine::getJuceApiName(const uint) { return nullptr; }
  1997. const char* const* CarlaEngine::getJuceApiDeviceNames(const uint) { return nullptr; }
  1998. const EngineDriverDeviceInfo* CarlaEngine::getJuceDeviceInfo(const uint, const char* const) { return nullptr; }
  1999. # else
  2000. CarlaEngine* CarlaEngine::newRtAudio(const AudioApi) { return nullptr; }
  2001. uint CarlaEngine::getRtAudioApiCount() { return 0; }
  2002. const char* CarlaEngine::getRtAudioApiName(const uint) { return nullptr; }
  2003. const char* const* CarlaEngine::getRtAudioApiDeviceNames(const uint) { return nullptr; }
  2004. const EngineDriverDeviceInfo* CarlaEngine::getRtAudioDeviceInfo(const uint, const char* const) { return nullptr; }
  2005. # endif
  2006. CARLA_BACKEND_END_NAMESPACE
  2007. #define CARLA_PLUGIN_UI_CLASS_PREFIX EngineNative
  2008. #include "CarlaHostCommon.cpp"
  2009. #include "CarlaPluginUI.cpp"
  2010. #include "CarlaDssiUtils.cpp"
  2011. #include "CarlaMacUtils.cpp"
  2012. #include "CarlaPatchbayUtils.cpp"
  2013. #include "CarlaPipeUtils.cpp"
  2014. #include "CarlaStateUtils.cpp"
  2015. #endif
  2016. // -----------------------------------------------------------------------