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.

2046 lines
70KB

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