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.

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