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.

2104 lines
72KB

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