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.

2178 lines
75KB

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