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.

2418 lines
79KB

  1. /*
  2. * Carla Standalone
  3. * Copyright (C) 2011-2013 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. // TODO:
  18. // Check carla_stderr2("Engine is not running"); <= prepend func name and args
  19. #include "CarlaHost.h"
  20. #include "CarlaMIDI.h"
  21. #include "CarlaNative.h"
  22. #include "CarlaEngine.hpp"
  23. #include "CarlaPlugin.hpp"
  24. #include "CarlaBackendUtils.hpp"
  25. #include "CarlaOscUtils.hpp"
  26. #include "CarlaThread.hpp"
  27. #include <QtCore/QByteArray>
  28. #ifdef BUILD_BRIDGE
  29. # undef HAVE_JUCE_UI
  30. #endif
  31. #ifdef HAVE_JUCE_UI
  32. # include "juce_gui_basics.h"
  33. using juce::initialiseJuce_GUI;
  34. using juce::shutdownJuce_GUI;
  35. using juce::MessageManager;
  36. using juce::Thread;
  37. #endif
  38. namespace CB = CarlaBackend;
  39. using CB::EngineOptions;
  40. // -------------------------------------------------------------------------------------------------------------------
  41. // Juce Message Thread
  42. #if defined(HAVE_JUCE_UI) && defined(CARLA_OS_LINUX)
  43. class JuceMessageThread : public Thread
  44. {
  45. public:
  46. JuceMessageThread()
  47. : Thread("JuceMessageThread"),
  48. fInitialised(false)
  49. {
  50. }
  51. ~JuceMessageThread() override
  52. {
  53. stop();
  54. }
  55. void start()
  56. {
  57. CARLA_SAFE_ASSERT_RETURN(! fInitialised,);
  58. fInitialised = false;
  59. startThread(7);
  60. while (! fInitialised)
  61. sleep(1);
  62. }
  63. void stop()
  64. {
  65. signalThreadShouldExit();
  66. waitForThreadToExit(5000);
  67. }
  68. protected:
  69. void run() override
  70. {
  71. MessageManager* const msgMgr(MessageManager::getInstance());
  72. CARLA_SAFE_ASSERT_RETURN(msgMgr != nullptr,);
  73. msgMgr->setCurrentThreadAsMessageThread();
  74. fInitialised = true;
  75. while ((! threadShouldExit()) && MessageManager::getInstance()->runDispatchLoopUntil(250))
  76. {}
  77. fInitialised = false;
  78. }
  79. private:
  80. volatile bool fInitialised;
  81. CARLA_DECLARE_NON_COPY_CLASS(JuceMessageThread)
  82. };
  83. #endif // defined(HAVE_JUCE_UI) && defined(CARLA_OS_LINUX)
  84. // -------------------------------------------------------------------------------------------------------------------
  85. // Single, standalone engine
  86. struct CarlaBackendStandalone {
  87. CarlaEngine* engine;
  88. EngineCallbackFunc engineCallback;
  89. void* engineCallbackPtr;
  90. EngineOptions engineOptions;
  91. FileCallbackFunc fileCallback;
  92. void* fileCallbackPtr;
  93. CarlaString lastError;
  94. #if defined(HAVE_JUCE_UI) && defined(CARLA_OS_LINUX)
  95. JuceMessageThread juceMsgThread;
  96. #endif
  97. CarlaBackendStandalone()
  98. : engine(nullptr),
  99. engineCallback(nullptr),
  100. engineCallbackPtr(nullptr),
  101. fileCallback(nullptr),
  102. fileCallbackPtr(nullptr)
  103. {
  104. #ifdef BUILD_BRIDGE
  105. engineOptions.processMode = CB::ENGINE_PROCESS_MODE_BRIDGE;
  106. engineOptions.transportMode = CB::ENGINE_TRANSPORT_MODE_BRIDGE;
  107. engineOptions.forceStereo = false;
  108. engineOptions.preferPluginBridges = false;
  109. engineOptions.preferUiBridges = false;
  110. #else
  111. if (std::getenv("LADISH_APP_NAME") != nullptr || std::getenv("NSM_URL") != nullptr)
  112. return;
  113. CarlaThread::setCurrentThreadName("Carla");
  114. #endif
  115. }
  116. ~CarlaBackendStandalone()
  117. {
  118. CARLA_SAFE_ASSERT(engine == nullptr);
  119. #ifdef HAVE_JUCE_UI
  120. CARLA_SAFE_ASSERT(MessageManager::getInstanceWithoutCreating() == nullptr);
  121. #endif
  122. }
  123. #ifdef HAVE_JUCE_UI
  124. void init()
  125. {
  126. JUCE_AUTORELEASEPOOL
  127. {
  128. initialiseJuce_GUI();
  129. # ifdef CARLA_OS_LINUX
  130. juceMsgThread.start();
  131. # else
  132. if (MessageManager* const msgMgr = MessageManager::getInstance())
  133. msgMgr->setCurrentThreadAsMessageThread();
  134. # endif
  135. }
  136. }
  137. void close()
  138. {
  139. JUCE_AUTORELEASEPOOL
  140. {
  141. # ifdef CARLA_OS_LINUX
  142. juceMsgThread.stop();
  143. # else
  144. MessageManager::deleteInstance();
  145. # endif
  146. shutdownJuce_GUI();
  147. }
  148. }
  149. # ifndef CARLA_OS_LINUX
  150. void idle()
  151. {
  152. JUCE_AUTORELEASEPOOL
  153. {
  154. if (MessageManager* const msgMgr = MessageManager::getInstanceWithoutCreating())
  155. msgMgr->runDispatchLoopUntil(5);
  156. }
  157. }
  158. # endif
  159. #endif
  160. CARLA_PREVENT_HEAP_ALLOCATION
  161. CARLA_DECLARE_NON_COPY_STRUCT(CarlaBackendStandalone)
  162. };
  163. static CarlaBackendStandalone gStandalone;
  164. // -------------------------------------------------------------------------------------------------------------------
  165. // NSM support
  166. #define NSM_API_VERSION_MAJOR 1
  167. #define NSM_API_VERSION_MINOR 2
  168. //#define NSM_CLIENT_FEATURES ":switch:optional-gui:"
  169. #define NSM_CLIENT_FEATURES ":switch:"
  170. class CarlaNSM
  171. {
  172. public:
  173. CarlaNSM() noexcept
  174. : fOscServer(nullptr),
  175. fHasBroadcast(false),
  176. fHasShowHideUI(false) {}
  177. ~CarlaNSM()
  178. {
  179. if (fOscServer != nullptr)
  180. {
  181. lo_server_del_method(fOscServer, "/reply", "ssss");
  182. lo_server_del_method(fOscServer, "/nsm/client/open", "sss");
  183. lo_server_del_method(fOscServer, "/nsm/client/save", "");
  184. //lo_server_del_method(fOscServer, "/nsm/client/show_optional_gui", "");
  185. //lo_server_del_method(fOscServer, "/nsm/client/hide_optional_gui", "");
  186. lo_server_free(fOscServer);
  187. fOscServer = nullptr;
  188. }
  189. }
  190. void announce(const int pid, const char* const initName)
  191. {
  192. const char* const NSM_URL(std::getenv("NSM_URL"));
  193. if (NSM_URL == nullptr)
  194. return;
  195. const lo_address addr = lo_address_new_from_url(NSM_URL);
  196. if (addr == nullptr)
  197. return;
  198. const int proto = lo_address_get_protocol(addr);
  199. if (fOscServer == nullptr)
  200. {
  201. // create new OSC server
  202. fOscServer = lo_server_new_with_proto(nullptr, proto, _error_handler);
  203. // register message handlers and start OSC thread
  204. lo_server_add_method(fOscServer, "/reply", "ssss", _reply_handler, this);
  205. lo_server_add_method(fOscServer, "/nsm/client/open", "sss", _open_handler, this);
  206. lo_server_add_method(fOscServer, "/nsm/client/save", "", _save_handler, this);
  207. //lo_server_add_method(fOscServer, "/nsm/client/show_optional_gui", "", _show_gui_handler, this);
  208. //lo_server_add_method(fOscServer, "/nsm/client/hide_optional_gui", "", _hide_gui_handler, this);
  209. // /nsm/client/session_is_loaded
  210. }
  211. #ifndef BUILD_ANSI_TEST
  212. lo_send_from(addr, fOscServer, LO_TT_IMMEDIATE, "/nsm/server/announce", "sssiii",
  213. "Carla", NSM_CLIENT_FEATURES, initName, NSM_API_VERSION_MAJOR, NSM_API_VERSION_MINOR, pid);
  214. #endif
  215. lo_address_free(addr);
  216. }
  217. void idle() noexcept
  218. {
  219. if (fOscServer == nullptr)
  220. return;
  221. for (;;)
  222. {
  223. try {
  224. if (lo_server_recv_noblock(fOscServer, 0) == 0)
  225. break;
  226. }
  227. CARLA_SAFE_EXCEPTION_CONTINUE("NSM OSC idle")
  228. }
  229. }
  230. protected:
  231. int handleReply(const char* const path, const char* const types, lo_arg** const argv, const int argc, const lo_message msg)
  232. {
  233. carla_debug("CarlaNSM::handleReply(%s, %i, %p, %s, %p)", path, argc, argv, types, msg);
  234. const char* const method = &argv[0]->s;
  235. const char* const message = &argv[1]->s;
  236. const char* const smName = &argv[2]->s;
  237. const char* const features = &argv[3]->s;
  238. CARLA_SAFE_ASSERT_RETURN(std::strcmp(method, "/nsm/server/announce") == 0, 0);
  239. fHasBroadcast = std::strstr(features, ":broadcast:") != nullptr;
  240. fHasShowHideUI = std::strstr(features, ":optional-gui:") != nullptr;
  241. carla_stdout("'%s' started: %s", smName, message);
  242. // TODO: send callback, disable open+save etc
  243. return 0;
  244. #ifndef DEBUG
  245. // unused
  246. (void)path; (void)types; (void)argc; (void)msg;
  247. #endif
  248. }
  249. int handleOpen(const char* const path, const char* const types, lo_arg** const argv, const int argc, const lo_message msg)
  250. {
  251. CARLA_SAFE_ASSERT_RETURN(fOscServer != nullptr, 0);
  252. carla_debug("CarlaNSM::handleOpen(\"%s\", \"%s\", %p, %i, %p)", path, types, argv, argc, msg);
  253. const char* const projectPath = &argv[0]->s;
  254. //const char* const displayName = &argv[1]->s;
  255. const char* const clientId = &argv[2]->s;
  256. if (! carla_is_engine_running())
  257. {
  258. gStandalone.engineOptions.processMode = CB::ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS;
  259. gStandalone.engineOptions.transportMode = CB::ENGINE_TRANSPORT_MODE_JACK;
  260. carla_engine_init("JACK", clientId);
  261. }
  262. else
  263. {
  264. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0);
  265. for (uint i=0, count=gStandalone.engine->getCurrentPluginCount(); i < count; ++i)
  266. gStandalone.engine->removePlugin(i);
  267. }
  268. fClientId = clientId;
  269. fProjectPath = projectPath;
  270. fProjectPath += ".carxp";
  271. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0);
  272. gStandalone.engine->loadProject(fProjectPath);
  273. #ifndef BUILD_ANSI_TEST
  274. lo_send_from(lo_message_get_source(msg), fOscServer, LO_TT_IMMEDIATE, "/reply", "ss", "/nsm/client/open", "OK");
  275. #endif
  276. #if 0
  277. if (fHasBroadcast)
  278. {
  279. char* const url = lo_server_get_url(fOscServer);
  280. lo_send(lo_message_get_source(msg), "/nsm/server/broadcast", "sssss",
  281. "/non/hello", url, "Carla", CARLA_VERSION_STRING, clientId);
  282. //lo_send_from(lo_message_get_source(msg), fOscServer, LO_TT_IMMEDIATE, "/nsm/server/broadcast", "sssss"
  283. // "/non/hello", url, "Carla", CARLA_VERSION_STRING, clientId);
  284. lo_send(lo_message_get_source(msg), "/signal/created", "ssfff", "/path/somewhere", true ? "in" : "out", 0.0f, 1.0f, 0.5f);
  285. std::free(url);
  286. carla_stdout("Broadcast sent!");
  287. }
  288. else
  289. carla_stdout("Broadcast NOT NOT NOT sent!");
  290. #endif
  291. return 0;
  292. #ifndef DEBUG
  293. // unused
  294. (void)path; (void)types; (void)argc; (void)msg;
  295. #endif
  296. }
  297. int handleSave(const char* const path, const char* const types, lo_arg** const argv, const int argc, const lo_message msg)
  298. {
  299. CARLA_SAFE_ASSERT_RETURN(fOscServer != nullptr, 0);
  300. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0);
  301. CARLA_SAFE_ASSERT_RETURN(fProjectPath.isNotEmpty(), 0);
  302. carla_debug("CarlaNSM::handleSave(\"%s\", \"%s\", %p, %i, %p)", path, types, argv, argc, msg);
  303. gStandalone.engine->saveProject(fProjectPath);
  304. #ifndef BUILD_ANSI_TEST
  305. lo_send_from(lo_message_get_source(msg), fOscServer, LO_TT_IMMEDIATE, "/reply", "ss", "/nsm/client/save", "OK");
  306. #endif
  307. return 0;
  308. #ifndef DEBUG
  309. // unused
  310. (void)path; (void)types; (void)argv; (void)argc; (void)msg;
  311. #endif
  312. }
  313. #if 0
  314. int handleShowHideGui(const lo_message msg, const bool show)
  315. {
  316. CARLA_SAFE_ASSERT_RETURN(fOscServer != nullptr, 0);
  317. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0);
  318. //CARLA_SAFE_ASSERT_RETURN(gStandalone.frontendWinId != 0, 0);
  319. carla_debug("CarlaNSM::handleShowHideGui(%s)", bool2str(show));
  320. #ifndef BUILD_ANSI_TEST
  321. lo_send_from(lo_message_get_source(msg), fOscServer, LO_TT_IMMEDIATE, show ? "/nsm/client/gui_is_shown" : "/nsm/client/gui_is_hidden", "");
  322. #endif
  323. return 0;
  324. }
  325. #endif
  326. private:
  327. lo_server fOscServer;
  328. CarlaString fClientId;
  329. CarlaString fProjectPath;
  330. bool fHasBroadcast;
  331. bool fHasShowHideUI;
  332. #define handlePtr ((CarlaNSM*)data)
  333. static void _error_handler(int num, const char* msg, const char* path)
  334. {
  335. carla_stderr2("CarlaNSM::_error_handler(%i, \"%s\", \"%s\")", num, msg, path);
  336. }
  337. static int _reply_handler(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg, void* data)
  338. {
  339. return handlePtr->handleReply(path, types, argv, argc, msg);
  340. }
  341. static int _open_handler(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg, void* data)
  342. {
  343. return handlePtr->handleOpen(path, types, argv, argc, msg);
  344. }
  345. static int _save_handler(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg, void* data)
  346. {
  347. return handlePtr->handleSave(path, types, argv, argc, msg);
  348. }
  349. #if 0
  350. static int _show_gui_handler(const char*, const char*, lo_arg**, int, lo_message, void* data)
  351. {
  352. return handlePtr->handleShowHideGui(true);
  353. }
  354. static int _hide_gui_handler(const char*, const char*, lo_arg**, int, lo_message, void* data)
  355. {
  356. return handlePtr->handleShowHideGui(false);
  357. }
  358. #endif
  359. #undef handlePtr
  360. CARLA_PREVENT_HEAP_ALLOCATION
  361. CARLA_DECLARE_NON_COPY_CLASS(CarlaNSM)
  362. };
  363. static CarlaNSM gNSM;
  364. // -------------------------------------------------------------------------------------------------------------------
  365. // Always return a valid string ptr
  366. static const char* const gNullCharPtr = "";
  367. static void checkStringPtr(const char*& charPtr)
  368. {
  369. if (charPtr == nullptr)
  370. charPtr = gNullCharPtr;
  371. }
  372. // -------------------------------------------------------------------------------------------------------------------
  373. // Constructors
  374. _CarlaPluginInfo::_CarlaPluginInfo() noexcept
  375. : type(CB::PLUGIN_NONE),
  376. category(CB::PLUGIN_CATEGORY_NONE),
  377. hints(0x0),
  378. optionsAvailable(0x0),
  379. optionsEnabled(0x0),
  380. filename(gNullCharPtr),
  381. name(gNullCharPtr),
  382. label(gNullCharPtr),
  383. maker(gNullCharPtr),
  384. copyright(gNullCharPtr),
  385. iconName(gNullCharPtr),
  386. uniqueId(0) {}
  387. _CarlaPluginInfo::~_CarlaPluginInfo() noexcept
  388. {
  389. if (label != gNullCharPtr)
  390. delete[] label;
  391. if (maker != gNullCharPtr)
  392. delete[] maker;
  393. if (copyright != gNullCharPtr)
  394. delete[] copyright;
  395. }
  396. _CarlaNativePluginInfo::_CarlaNativePluginInfo() noexcept
  397. : category(CB::PLUGIN_CATEGORY_NONE),
  398. hints(0x0),
  399. audioIns(0),
  400. audioOuts(0),
  401. midiIns(0),
  402. midiOuts(0),
  403. parameterIns(0),
  404. parameterOuts(0),
  405. name(gNullCharPtr),
  406. label(gNullCharPtr),
  407. maker(gNullCharPtr),
  408. copyright(gNullCharPtr) {}
  409. _CarlaParameterInfo::_CarlaParameterInfo() noexcept
  410. : name(gNullCharPtr),
  411. symbol(gNullCharPtr),
  412. unit(gNullCharPtr),
  413. scalePointCount(0) {}
  414. _CarlaParameterInfo::~_CarlaParameterInfo() noexcept
  415. {
  416. if (name != gNullCharPtr)
  417. delete[] name;
  418. if (symbol != gNullCharPtr)
  419. delete[] symbol;
  420. if (unit != gNullCharPtr)
  421. delete[] unit;
  422. }
  423. _CarlaScalePointInfo::_CarlaScalePointInfo() noexcept
  424. : value(0.0f),
  425. label(gNullCharPtr) {}
  426. _CarlaScalePointInfo::~_CarlaScalePointInfo() noexcept
  427. {
  428. if (label != gNullCharPtr)
  429. delete[] label;
  430. }
  431. _CarlaTransportInfo::_CarlaTransportInfo() noexcept
  432. : playing(false),
  433. frame(0),
  434. bar(0),
  435. beat(0),
  436. tick(0),
  437. bpm(0.0) {}
  438. // -------------------------------------------------------------------------------------------------------------------
  439. // API
  440. const char* carla_get_complete_license_text()
  441. {
  442. carla_debug("carla_get_complete_license_text()");
  443. static CarlaString retText;
  444. if (retText.isEmpty())
  445. {
  446. CarlaString text1, text2, text3, text4, text5;
  447. text1 += "<p>This current Carla build is using the following features and 3rd-party code:</p>";
  448. text1 += "<ul>";
  449. // Plugin formats
  450. #ifdef WANT_LADSPA
  451. text2 += "<li>LADSPA plugin support, http://www.ladspa.org/</li>";
  452. #endif
  453. #ifdef WANT_DSSI
  454. text2 += "<li>DSSI plugin support, http://dssi.sourceforge.net/</li>";
  455. #endif
  456. #ifdef WANT_LV2
  457. text2 += "<li>LV2 plugin support, http://lv2plug.in/</li>";
  458. #endif
  459. #ifdef WANT_VST
  460. # ifdef VESTIGE_HEADER
  461. text2 += "<li>VST plugin support, using VeSTige header by Javier Serrano Polo</li>";
  462. # else
  463. text2 += "<li>VST plugin support, using official VST SDK 2.4 (trademark of Steinberg Media Technologies GmbH)</li>";
  464. # endif
  465. #endif
  466. #ifdef WANT_AU
  467. text2 += "<li>AU plugin support</li>"; // FIXME
  468. #endif
  469. // Sample kit libraries
  470. #ifdef WANT_FLUIDSYNTH
  471. text2 += "<li>FluidSynth library for SF2 support, http://www.fluidsynth.org/</li>";
  472. #endif
  473. #ifdef WANT_LINUXSAMPLER
  474. text2 += "<li>LinuxSampler library for GIG and SFZ support*, http://www.linuxsampler.org/</li>";
  475. #endif
  476. #ifdef WANT_NATIVE
  477. // Internal plugins
  478. # ifdef HAVE_OPENGL
  479. text3 += "<li>DISTRHO Mini-Series plugin code, based on LOSER-dev suite by Michael Gruhn</li>";
  480. # endif
  481. text3 += "<li>NekoFilter plugin code, based on lv2fil by Nedko Arnaudov and Fons Adriaensen</li>";
  482. //text1 += "<li>SunVox library file support, http://www.warmplace.ru/soft/sunvox/</li>"; // unfinished
  483. # ifdef WANT_AUDIOFILE
  484. text3 += "<li>AudioDecoder library for Audio file support, by Robin Gareus</li>";
  485. # endif
  486. # ifdef WANT_MIDIFILE
  487. text3 += "<li>LibSMF library for MIDI file support, http://libsmf.sourceforge.net/</li>";
  488. # endif
  489. # ifdef WANT_ZYNADDSUBFX
  490. text3 += "<li>ZynAddSubFX plugin code, http://zynaddsubfx.sf.net/</li>";
  491. # ifdef WANT_ZYNADDSUBFX_UI
  492. text3 += "<li>ZynAddSubFX UI using NTK, http://non.tuxfamily.org/wiki/NTK</li>";
  493. # endif
  494. # endif
  495. #endif
  496. // misc libs
  497. text4 += "<li>liblo library for OSC support, http://liblo.sourceforge.net/</li>";
  498. #ifdef WANT_LV2
  499. text4 += "<li>serd, sord, sratom and lilv libraries for LV2 discovery, http://drobilla.net/software/lilv/</li>";
  500. #endif
  501. text4 += "<li>RtAudio+RtMidi libraries for extra Audio and MIDI support, http://www.music.mcgill.ca/~gary/rtaudio/</li>";
  502. // end
  503. text4 += "</ul>";
  504. // code snippets
  505. text5 += "<p>Additionally, Carla uses code snippets from the following projects:</p>";
  506. text5 += "<ul>";
  507. text5 += "<li>Pointer and data leak utils from JUCE, http://www.rawmaterialsoftware.com/juce.php</li>";
  508. text5 += "<li>Shared memory utils from dssi-vst, http://www.breakfastquay.com/dssi-vst/</li>";
  509. text5 += "<li>Real-time memory pool, by Nedko Arnaudov</li>";
  510. text5 += "</ul>";
  511. #ifdef WANT_LINUXSAMPLER
  512. // LinuxSampler GPL exception
  513. text5 += "<p>(*) Using LinuxSampler code in commercial hardware or software products is not allowed without prior written authorization by the authors.</p>";
  514. #endif
  515. retText = text1 + text2 + text3 + text4 + text5;
  516. }
  517. return retText;
  518. }
  519. const char* carla_get_supported_file_extensions()
  520. {
  521. carla_debug("carla_get_supported_file_extensions()");
  522. static CarlaString retText;
  523. if (retText.isEmpty())
  524. {
  525. // Base types
  526. retText += "*.carxp;*.carxs";
  527. // Sample kits
  528. #ifdef WANT_FLUIDSYNTH
  529. retText += ";*.sf2";
  530. #endif
  531. #ifdef WANT_LINUXSAMPLER
  532. retText += ";*.gig;*.sfz";
  533. #endif
  534. // Files provided by internal plugins
  535. #ifdef WANT_AUDIOFILE
  536. retText += ";*.aiff;*.flac;*.oga;*.ogg;*.w64;*.wav";
  537. # ifdef HAVE_FFMPEG
  538. retText += ";*.3g2;*.3gp;*.aac;*.ac3;*.amr;*.ape;*.mp2;*.mp3;*.mpc;*.wma";
  539. # endif
  540. #endif
  541. #ifdef WANT_MIDIFILE
  542. retText += ";*.mid;*.midi";
  543. #endif
  544. // Plugin presets
  545. #ifdef WANT_ZYNADDSUBFX
  546. retText += ";*.xmz;*.xiz";
  547. #endif
  548. }
  549. return retText;
  550. }
  551. // -------------------------------------------------------------------------------------------------------------------
  552. unsigned int carla_get_engine_driver_count()
  553. {
  554. carla_debug("carla_get_engine_driver_count()");
  555. return CarlaEngine::getDriverCount();
  556. }
  557. const char* carla_get_engine_driver_name(unsigned int index)
  558. {
  559. carla_debug("carla_get_engine_driver_name(%i)", index);
  560. return CarlaEngine::getDriverName(index);
  561. }
  562. const char* const* carla_get_engine_driver_device_names(unsigned int index)
  563. {
  564. carla_debug("carla_get_engine_driver_device_names(%i)", index);
  565. return CarlaEngine::getDriverDeviceNames(index);
  566. }
  567. const EngineDriverDeviceInfo* carla_get_engine_driver_device_info(unsigned int index, const char* name)
  568. {
  569. CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0', nullptr);
  570. carla_debug("carla_get_engine_driver_device_info(%i, \"%s\")", index, name);
  571. if (const EngineDriverDeviceInfo* const ret = CarlaEngine::getDriverDeviceInfo(index, name))
  572. {
  573. static EngineDriverDeviceInfo devInfo;
  574. static const uint32_t nullBufferSizes[] = { 0 };
  575. static const double nullSampleRates[] = { 0.0 };
  576. devInfo.hints = ret->hints;
  577. devInfo.bufferSizes = (ret->bufferSizes != nullptr) ? ret->bufferSizes : nullBufferSizes;
  578. devInfo.sampleRates = (ret->sampleRates != nullptr) ? ret->sampleRates : nullSampleRates;
  579. return &devInfo;
  580. }
  581. return nullptr;
  582. }
  583. // -------------------------------------------------------------------------------------------------------------------
  584. unsigned int carla_get_internal_plugin_count()
  585. {
  586. carla_debug("carla_get_internal_plugin_count()");
  587. #ifdef WANT_NATIVE
  588. return static_cast<unsigned int>(CarlaPlugin::getNativePluginCount());
  589. #else
  590. return 0;
  591. #endif
  592. }
  593. const CarlaNativePluginInfo* carla_get_internal_plugin_info(unsigned int index)
  594. {
  595. carla_debug("carla_get_internal_plugin_info(%i)", index);
  596. #ifdef WANT_NATIVE
  597. static CarlaNativePluginInfo info;
  598. const NativePluginDescriptor* const nativePlugin(CarlaPlugin::getNativePluginDescriptor(index));
  599. // as internal plugin, this must never fail
  600. CARLA_SAFE_ASSERT_RETURN(nativePlugin != nullptr, nullptr);
  601. info.category = static_cast<CB::PluginCategory>(nativePlugin->category);
  602. info.hints = 0x0;
  603. if (nativePlugin->hints & ::PLUGIN_IS_RTSAFE)
  604. info.hints |= CB::PLUGIN_IS_RTSAFE;
  605. if (nativePlugin->hints & ::PLUGIN_IS_SYNTH)
  606. info.hints |= CB::PLUGIN_IS_SYNTH;
  607. if (nativePlugin->hints & ::PLUGIN_HAS_UI)
  608. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  609. if (nativePlugin->hints & ::PLUGIN_NEEDS_FIXED_BUFFERS)
  610. info.hints |= CB::PLUGIN_NEEDS_FIXED_BUFFERS;
  611. if (nativePlugin->hints & ::PLUGIN_NEEDS_SINGLE_THREAD)
  612. info.hints |= CB::PLUGIN_NEEDS_SINGLE_THREAD;
  613. info.audioIns = nativePlugin->audioIns;
  614. info.audioOuts = nativePlugin->audioOuts;
  615. info.midiIns = nativePlugin->midiIns;
  616. info.midiOuts = nativePlugin->midiOuts;
  617. info.parameterIns = nativePlugin->paramIns;
  618. info.parameterOuts = nativePlugin->paramOuts;
  619. info.name = nativePlugin->name;
  620. info.label = nativePlugin->label;
  621. info.maker = nativePlugin->maker;
  622. info.copyright = nativePlugin->copyright;
  623. checkStringPtr(info.name);
  624. checkStringPtr(info.label);
  625. checkStringPtr(info.maker);
  626. checkStringPtr(info.copyright);
  627. return &info;
  628. #else
  629. return nullptr;
  630. // unused
  631. (void)index;
  632. #endif
  633. }
  634. // -------------------------------------------------------------------------------------------------------------------
  635. const CarlaEngine* carla_get_engine()
  636. {
  637. carla_debug("carla_get_engine()");
  638. return gStandalone.engine;
  639. }
  640. // -------------------------------------------------------------------------------------------------------------------
  641. bool carla_engine_init(const char* driverName, const char* clientName)
  642. {
  643. CARLA_SAFE_ASSERT_RETURN(driverName != nullptr && driverName[0] != '\0', false);
  644. CARLA_SAFE_ASSERT_RETURN(clientName != nullptr && clientName[0] != '\0', false);
  645. carla_debug("carla_engine_init(\"%s\", \"%s\")", driverName, clientName);
  646. if (gStandalone.engine != nullptr)
  647. {
  648. carla_stderr2("Engine is already running");
  649. gStandalone.lastError = "Engine is already running";
  650. return false;
  651. }
  652. #ifdef CARLA_OS_WIN
  653. carla_setenv("WINEASIO_CLIENT_NAME", clientName);
  654. #endif
  655. // TODO: make this an option, put somewhere else
  656. if (std::getenv("WINE_RT") == nullptr)
  657. {
  658. carla_setenv("WINE_RT", "15");
  659. carla_setenv("WINE_SVR_RT", "10");
  660. }
  661. gStandalone.engine = CarlaEngine::newDriverByName(driverName);
  662. if (gStandalone.engine == nullptr)
  663. {
  664. carla_stderr2("The seleted audio driver is not available");
  665. gStandalone.lastError = "The seleted audio driver is not available";
  666. return false;
  667. }
  668. gStandalone.engine->setCallback(gStandalone.engineCallback, gStandalone.engineCallbackPtr);
  669. gStandalone.engine->setFileCallback(gStandalone.fileCallback, gStandalone.fileCallbackPtr);
  670. #ifdef BUILD_BRIDGE
  671. gStandalone.engine->setOption(CB::ENGINE_OPTION_PROCESS_MODE, CB::ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS, nullptr);
  672. gStandalone.engine->setOption(CB::ENGINE_OPTION_TRANSPORT_MODE, CB::ENGINE_TRANSPORT_MODE_JACK, nullptr);
  673. #else
  674. gStandalone.engine->setOption(CB::ENGINE_OPTION_PROCESS_MODE, static_cast<int>(gStandalone.engineOptions.processMode), nullptr);
  675. gStandalone.engine->setOption(CB::ENGINE_OPTION_TRANSPORT_MODE, static_cast<int>(gStandalone.engineOptions.transportMode), nullptr);
  676. #endif
  677. gStandalone.engine->setOption(CB::ENGINE_OPTION_FORCE_STEREO, gStandalone.engineOptions.forceStereo ? 1 : 0, nullptr);
  678. gStandalone.engine->setOption(CB::ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, gStandalone.engineOptions.preferPluginBridges ? 1 : 0, nullptr);
  679. gStandalone.engine->setOption(CB::ENGINE_OPTION_PREFER_UI_BRIDGES, gStandalone.engineOptions.preferUiBridges ? 1 : 0, nullptr);
  680. gStandalone.engine->setOption(CB::ENGINE_OPTION_UIS_ALWAYS_ON_TOP, gStandalone.engineOptions.uisAlwaysOnTop ? 1 : 0, nullptr);
  681. gStandalone.engine->setOption(CB::ENGINE_OPTION_MAX_PARAMETERS, static_cast<int>(gStandalone.engineOptions.maxParameters), nullptr);
  682. gStandalone.engine->setOption(CB::ENGINE_OPTION_UI_BRIDGES_TIMEOUT, static_cast<int>(gStandalone.engineOptions.uiBridgesTimeout), nullptr);
  683. gStandalone.engine->setOption(CB::ENGINE_OPTION_AUDIO_NUM_PERIODS, static_cast<int>(gStandalone.engineOptions.audioNumPeriods), nullptr);
  684. gStandalone.engine->setOption(CB::ENGINE_OPTION_AUDIO_BUFFER_SIZE, static_cast<int>(gStandalone.engineOptions.audioBufferSize), nullptr);
  685. gStandalone.engine->setOption(CB::ENGINE_OPTION_AUDIO_SAMPLE_RATE, static_cast<int>(gStandalone.engineOptions.audioSampleRate), nullptr);
  686. if (gStandalone.engineOptions.audioDevice != nullptr)
  687. gStandalone.engine->setOption(CB::ENGINE_OPTION_AUDIO_DEVICE, 0, gStandalone.engineOptions.audioDevice);
  688. if (gStandalone.engineOptions.binaryDir != nullptr && gStandalone.engineOptions.binaryDir[0] != '\0')
  689. gStandalone.engine->setOption(CB::ENGINE_OPTION_PATH_BINARIES, 0, gStandalone.engineOptions.binaryDir);
  690. if (gStandalone.engineOptions.resourceDir != nullptr && gStandalone.engineOptions.resourceDir[0] != '\0')
  691. gStandalone.engine->setOption(CB::ENGINE_OPTION_PATH_RESOURCES, 0, gStandalone.engineOptions.resourceDir);
  692. if (gStandalone.engineOptions.frontendWinId != 0)
  693. {
  694. char strBuf[STR_MAX+1];
  695. std::sprintf(strBuf, P_UINTPTR, gStandalone.engineOptions.frontendWinId);
  696. gStandalone.engine->setOption(CB::ENGINE_OPTION_FRONTEND_WIN_ID, 0, strBuf);
  697. }
  698. else
  699. gStandalone.engine->setOption(CB::ENGINE_OPTION_FRONTEND_WIN_ID, 0, "0");
  700. if (gStandalone.engine->init(clientName))
  701. {
  702. gStandalone.lastError = "No error";
  703. #ifdef HAVE_JUCE_UI
  704. gStandalone.init();
  705. #endif
  706. return true;
  707. }
  708. else
  709. {
  710. gStandalone.lastError = gStandalone.engine->getLastError();
  711. delete gStandalone.engine;
  712. gStandalone.engine = nullptr;
  713. return false;
  714. }
  715. }
  716. #ifdef BUILD_BRIDGE
  717. bool carla_engine_init_bridge(const char audioBaseName[6+1], const char controlBaseName[6+1], const char timeBaseName[6+1], const char* clientName)
  718. {
  719. CARLA_SAFE_ASSERT_RETURN(audioBaseName != nullptr && audioBaseName[0] != '\0', false);
  720. CARLA_SAFE_ASSERT_RETURN(controlBaseName != nullptr && controlBaseName[0] != '\0', false);
  721. CARLA_SAFE_ASSERT_RETURN(timeBaseName != nullptr && timeBaseName[0] != '\0', false);
  722. CARLA_SAFE_ASSERT_RETURN(clientName != nullptr && clientName[0] != '\0', false);
  723. carla_debug("carla_engine_init_bridge(\"%s\", \"%s\", \"%s\", \"%s\")", audioBaseName, controlBaseName, timeBaseName, clientName);
  724. if (gStandalone.engine != nullptr)
  725. {
  726. carla_stderr2("Engine is already running");
  727. gStandalone.lastError = "Engine is already running";
  728. return false;
  729. }
  730. gStandalone.engine = CarlaEngine::newBridge(audioBaseName, controlBaseName, timeBaseName);
  731. if (gStandalone.engine == nullptr)
  732. {
  733. carla_stderr2("The seleted audio driver is not available!");
  734. gStandalone.lastError = "The seleted audio driver is not available!";
  735. return false;
  736. }
  737. gStandalone.engine->setCallback(gStandalone.engineCallback, gStandalone.engineCallbackPtr);
  738. gStandalone.engine->setFileCallback(gStandalone.fileCallback, gStandalone.fileCallbackPtr);
  739. // forced options for bridge mode
  740. gStandalone.engine->setOption(CB::ENGINE_OPTION_PROCESS_MODE, CB::ENGINE_PROCESS_MODE_BRIDGE, nullptr);
  741. gStandalone.engine->setOption(CB::ENGINE_OPTION_TRANSPORT_MODE, CB::ENGINE_TRANSPORT_MODE_BRIDGE, nullptr);
  742. gStandalone.engine->setOption(CB::ENGINE_OPTION_FORCE_STEREO, false, nullptr);
  743. gStandalone.engine->setOption(CB::ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, false, nullptr);
  744. gStandalone.engine->setOption(CB::ENGINE_OPTION_PREFER_UI_BRIDGES, false, nullptr);
  745. if (const char* const uisAlwaysOnTop = std::getenv("ENGINE_OPTION_UIS_ALWAYS_ON_TOP"))
  746. gStandalone.engine->setOption(CB::ENGINE_OPTION_UIS_ALWAYS_ON_TOP, (std::strcmp(uisAlwaysOnTop, "true") == 0) ? 1 : 0, nullptr);
  747. if (const char* const maxParameters = std::getenv("ENGINE_OPTION_MAX_PARAMETERS"))
  748. gStandalone.engine->setOption(CB::ENGINE_OPTION_MAX_PARAMETERS, std::atoi(maxParameters), nullptr);
  749. if (const char* const uiBridgesTimeout = std::getenv("ENGINE_OPTION_UI_BRIDGES_TIMEOUT"))
  750. gStandalone.engine->setOption(CB::ENGINE_OPTION_UI_BRIDGES_TIMEOUT, std::atoi(uiBridgesTimeout), nullptr);
  751. if (const char* const binaryDir = std::getenv("ENGINE_OPTION_PATH_BINARIES"))
  752. gStandalone.engine->setOption(CB::ENGINE_OPTION_PATH_BINARIES, 0, binaryDir);
  753. if (const char* const resourceDir = std::getenv("ENGINE_OPTION_PATH_RESOURCES"))
  754. gStandalone.engine->setOption(CB::ENGINE_OPTION_PATH_RESOURCES, 0, resourceDir);
  755. if (const char* const frontendWinId = std::getenv("ENGINE_OPTION_FRONTEND_WIN_ID"))
  756. gStandalone.engine->setOption(CB::ENGINE_OPTION_FRONTEND_WIN_ID, 0, frontendWinId);
  757. if (gStandalone.engine->init(clientName))
  758. {
  759. gStandalone.lastError = "No error";
  760. #ifdef HAVE_JUCE_UI
  761. gStandalone.init();
  762. #endif
  763. return true;
  764. }
  765. else
  766. {
  767. gStandalone.lastError = gStandalone.engine->getLastError();
  768. delete gStandalone.engine;
  769. gStandalone.engine = nullptr;
  770. return false;
  771. }
  772. }
  773. #endif
  774. bool carla_engine_close()
  775. {
  776. carla_debug("carla_engine_close()");
  777. if (gStandalone.engine == nullptr)
  778. {
  779. carla_stderr2("Engine is not running");
  780. gStandalone.lastError = "Engine is not running";
  781. return false;
  782. }
  783. gStandalone.engine->setAboutToClose();
  784. gStandalone.engine->removeAllPlugins();
  785. const bool closed(gStandalone.engine->close());
  786. if (! closed)
  787. gStandalone.lastError = gStandalone.engine->getLastError();
  788. #ifdef HAVE_JUCE_UI
  789. gStandalone.close();
  790. #endif
  791. delete gStandalone.engine;
  792. gStandalone.engine = nullptr;
  793. return closed;
  794. }
  795. void carla_engine_idle()
  796. {
  797. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  798. gNSM.idle();
  799. #if defined(HAVE_JUCE_UI) && ! defined(CARLA_OS_LINUX)
  800. gStandalone.idle();
  801. #endif
  802. gStandalone.engine->idle();
  803. }
  804. bool carla_is_engine_running()
  805. {
  806. return (gStandalone.engine != nullptr && gStandalone.engine->isRunning());
  807. }
  808. void carla_set_engine_about_to_close()
  809. {
  810. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  811. carla_debug("carla_set_engine_about_to_close()");
  812. gStandalone.engine->setAboutToClose();
  813. }
  814. void carla_set_engine_callback(EngineCallbackFunc func, void* ptr)
  815. {
  816. carla_debug("carla_set_engine_callback(%p, %p)", func, ptr);
  817. gStandalone.engineCallback = func;
  818. gStandalone.engineCallbackPtr = ptr;
  819. if (gStandalone.engine != nullptr)
  820. gStandalone.engine->setCallback(func, ptr);
  821. //#ifdef WANT_LOGS
  822. // gLogThread.setCallback(func, ptr);
  823. //#endif
  824. }
  825. #ifndef BUILD_BRIDGE
  826. void carla_set_engine_option(EngineOption option, int value, const char* valueStr)
  827. {
  828. carla_debug("carla_set_engine_option(%i:%s, %i, \"%s\")", option, CB::EngineOption2Str(option), value, valueStr);
  829. switch (option)
  830. {
  831. case CB::ENGINE_OPTION_DEBUG:
  832. break;
  833. case CB::ENGINE_OPTION_PROCESS_MODE:
  834. CARLA_SAFE_ASSERT_RETURN(value >= CB::ENGINE_PROCESS_MODE_SINGLE_CLIENT && value < CB::ENGINE_PROCESS_MODE_BRIDGE,);
  835. gStandalone.engineOptions.processMode = static_cast<CB::EngineProcessMode>(value);
  836. break;
  837. case CB::ENGINE_OPTION_TRANSPORT_MODE:
  838. CARLA_SAFE_ASSERT_RETURN(value >= CB::ENGINE_TRANSPORT_MODE_INTERNAL && value < CB::ENGINE_TRANSPORT_MODE_BRIDGE,);
  839. gStandalone.engineOptions.transportMode = static_cast<CB::EngineTransportMode>(value);
  840. break;
  841. case CB::ENGINE_OPTION_FORCE_STEREO:
  842. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  843. gStandalone.engineOptions.forceStereo = (value != 0);
  844. break;
  845. case CB::ENGINE_OPTION_PREFER_PLUGIN_BRIDGES:
  846. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  847. gStandalone.engineOptions.preferPluginBridges = (value != 0);
  848. break;
  849. case CB::ENGINE_OPTION_PREFER_UI_BRIDGES:
  850. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  851. gStandalone.engineOptions.preferUiBridges = (value != 0);
  852. break;
  853. case CB::ENGINE_OPTION_UIS_ALWAYS_ON_TOP:
  854. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  855. gStandalone.engineOptions.uisAlwaysOnTop = (value != 0);
  856. break;
  857. case CB::ENGINE_OPTION_MAX_PARAMETERS:
  858. CARLA_SAFE_ASSERT_RETURN(value >= 0,);
  859. gStandalone.engineOptions.maxParameters = static_cast<unsigned int>(value);
  860. break;
  861. case CB::ENGINE_OPTION_UI_BRIDGES_TIMEOUT:
  862. CARLA_SAFE_ASSERT_RETURN(value >= 0,);
  863. gStandalone.engineOptions.uiBridgesTimeout = static_cast<unsigned int>(value);
  864. break;
  865. case CB::ENGINE_OPTION_AUDIO_NUM_PERIODS:
  866. CARLA_SAFE_ASSERT_RETURN(value >= 2 && value <= 3,);
  867. gStandalone.engineOptions.audioNumPeriods = static_cast<unsigned int>(value);
  868. break;
  869. case CB::ENGINE_OPTION_AUDIO_BUFFER_SIZE:
  870. CARLA_SAFE_ASSERT_RETURN(value >= 8,);
  871. gStandalone.engineOptions.audioBufferSize = static_cast<unsigned int>(value);
  872. break;
  873. case CB::ENGINE_OPTION_AUDIO_SAMPLE_RATE:
  874. CARLA_SAFE_ASSERT_RETURN(value >= 22050,);
  875. gStandalone.engineOptions.audioSampleRate = static_cast<unsigned int>(value);
  876. break;
  877. case CB::ENGINE_OPTION_AUDIO_DEVICE:
  878. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr,);
  879. if (gStandalone.engineOptions.audioDevice != nullptr)
  880. delete[] gStandalone.engineOptions.audioDevice;
  881. gStandalone.engineOptions.audioDevice = carla_strdup(valueStr);
  882. break;
  883. case CB:: ENGINE_OPTION_NSM_INIT:
  884. CARLA_SAFE_ASSERT_RETURN(value != 0,);
  885. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  886. gNSM.announce(value, valueStr);
  887. break;
  888. case CB::ENGINE_OPTION_PATH_BINARIES:
  889. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  890. if (gStandalone.engineOptions.binaryDir != nullptr)
  891. delete[] gStandalone.engineOptions.binaryDir;
  892. gStandalone.engineOptions.binaryDir = carla_strdup(valueStr);
  893. break;
  894. case CB::ENGINE_OPTION_PATH_RESOURCES:
  895. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  896. if (gStandalone.engineOptions.resourceDir != nullptr)
  897. delete[] gStandalone.engineOptions.resourceDir;
  898. gStandalone.engineOptions.resourceDir = carla_strdup(valueStr);
  899. break;
  900. case CB::ENGINE_OPTION_FRONTEND_WIN_ID:
  901. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  902. const long long winId(std::strtoll(valueStr, nullptr, 16));
  903. CARLA_SAFE_ASSERT_RETURN(winId >= 0,);
  904. gStandalone.engineOptions.frontendWinId = static_cast<uintptr_t>(winId);
  905. break;
  906. }
  907. if (gStandalone.engine != nullptr)
  908. gStandalone.engine->setOption(option, value, valueStr);
  909. }
  910. #endif
  911. void carla_set_file_callback(FileCallbackFunc func, void* ptr)
  912. {
  913. carla_debug("carla_set_file_callback(%p, %p)", func, ptr);
  914. gStandalone.fileCallback = func;
  915. gStandalone.fileCallbackPtr = ptr;
  916. if (gStandalone.engine != nullptr)
  917. gStandalone.engine->setFileCallback(func, ptr);
  918. }
  919. // -------------------------------------------------------------------------------------------------------------------
  920. bool carla_load_file(const char* filename)
  921. {
  922. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  923. carla_debug("carla_load_file(\"%s\")", filename);
  924. if (gStandalone.engine != nullptr)
  925. return gStandalone.engine->loadFile(filename);
  926. carla_stderr2("Engine is not running");
  927. gStandalone.lastError = "Engine is not running";
  928. return false;
  929. }
  930. bool carla_load_project(const char* filename)
  931. {
  932. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  933. carla_debug("carla_load_project(\"%s\")", filename);
  934. if (gStandalone.engine != nullptr)
  935. return gStandalone.engine->loadProject(filename);
  936. carla_stderr2("Engine is not running");
  937. gStandalone.lastError = "Engine is not running";
  938. return false;
  939. }
  940. bool carla_save_project(const char* filename)
  941. {
  942. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  943. carla_debug("carla_save_project(\"%s\")", filename);
  944. if (gStandalone.engine != nullptr)
  945. return gStandalone.engine->saveProject(filename);
  946. carla_stderr2("Engine was never initiated");
  947. gStandalone.lastError = "Engine was never initiated";
  948. return false;
  949. }
  950. #ifndef BUILD_BRIDGE
  951. // -------------------------------------------------------------------------------------------------------------------
  952. bool carla_patchbay_connect(uint groupIdA, uint portIdA, uint groupIdB, uint portIdB)
  953. {
  954. carla_debug("carla_patchbay_connect(%u, %u, %u, %u)", groupIdA, portIdA, groupIdB, portIdB);
  955. if (gStandalone.engine != nullptr)
  956. return gStandalone.engine->patchbayConnect(groupIdA, portIdA, groupIdB, portIdB);
  957. carla_stderr2("Engine is not running");
  958. gStandalone.lastError = "Engine is not running";
  959. return false;
  960. }
  961. bool carla_patchbay_disconnect(uint connectionId)
  962. {
  963. carla_debug("carla_patchbay_disconnect(%i)", connectionId);
  964. if (gStandalone.engine != nullptr)
  965. return gStandalone.engine->patchbayDisconnect(connectionId);
  966. carla_stderr2("Engine is not running");
  967. gStandalone.lastError = "Engine is not running";
  968. return false;
  969. }
  970. bool carla_patchbay_refresh()
  971. {
  972. carla_debug("carla_patchbay_refresh()");
  973. if (gStandalone.engine != nullptr)
  974. return gStandalone.engine->patchbayRefresh();
  975. carla_stderr2("Engine is not running");
  976. gStandalone.lastError = "Engine is not running";
  977. return false;
  978. }
  979. #endif
  980. // -------------------------------------------------------------------------------------------------------------------
  981. void carla_transport_play()
  982. {
  983. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr && gStandalone.engine->isRunning(),);
  984. carla_debug("carla_transport_play()");
  985. gStandalone.engine->transportPlay();
  986. }
  987. void carla_transport_pause()
  988. {
  989. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr && gStandalone.engine->isRunning(),);
  990. carla_debug("carla_transport_pause()");
  991. gStandalone.engine->transportPause();
  992. }
  993. void carla_transport_relocate(uint64_t frame)
  994. {
  995. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr && gStandalone.engine->isRunning(),);
  996. carla_debug("carla_transport_relocate(%i)", frame);
  997. gStandalone.engine->transportRelocate(frame);
  998. }
  999. uint64_t carla_get_current_transport_frame()
  1000. {
  1001. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr && gStandalone.engine->isRunning(), 0);
  1002. const CB::EngineTimeInfo& timeInfo(gStandalone.engine->getTimeInfo());
  1003. return timeInfo.frame;
  1004. }
  1005. const CarlaTransportInfo* carla_get_transport_info()
  1006. {
  1007. static CarlaTransportInfo retInfo;
  1008. // reset
  1009. retInfo.playing = false;
  1010. retInfo.frame = 0;
  1011. retInfo.bar = 0;
  1012. retInfo.beat = 0;
  1013. retInfo.tick = 0;
  1014. retInfo.bpm = 0.0;
  1015. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr && gStandalone.engine->isRunning(), &retInfo);
  1016. const CB::EngineTimeInfo& timeInfo(gStandalone.engine->getTimeInfo());
  1017. retInfo.playing = timeInfo.playing;
  1018. retInfo.frame = timeInfo.frame;
  1019. if (timeInfo.valid & CB::EngineTimeInfo::kValidBBT)
  1020. {
  1021. retInfo.bar = timeInfo.bbt.bar;
  1022. retInfo.beat = timeInfo.bbt.beat;
  1023. retInfo.tick = timeInfo.bbt.tick;
  1024. retInfo.bpm = timeInfo.bbt.beatsPerMinute;
  1025. }
  1026. return &retInfo;
  1027. }
  1028. // -------------------------------------------------------------------------------------------------------------------
  1029. bool carla_add_plugin(BinaryType btype, PluginType ptype, const char* filename, const char* name, const char* label, int64_t uniqueId, const void* extraPtr)
  1030. {
  1031. CARLA_SAFE_ASSERT_RETURN(label != nullptr /*&& label[0] != '\0'*/, false);
  1032. carla_debug("carla_add_plugin(%i:%s, %i:%s, \"%s\", \"%s\", \"%s\", " P_INT64 ", %p)", btype, CB::BinaryType2Str(btype), ptype, CB::PluginType2Str(ptype), filename, name, label, uniqueId, extraPtr);
  1033. if (gStandalone.engine != nullptr)
  1034. return gStandalone.engine->addPlugin(btype, ptype, filename, name, label, uniqueId, extraPtr);
  1035. carla_stderr2("Engine is not running");
  1036. gStandalone.lastError = "Engine is not running";
  1037. return false;
  1038. }
  1039. bool carla_remove_plugin(uint pluginId)
  1040. {
  1041. carla_debug("carla_remove_plugin(%i)", pluginId);
  1042. if (gStandalone.engine != nullptr)
  1043. return gStandalone.engine->removePlugin(pluginId);
  1044. carla_stderr2("Engine is not running");
  1045. gStandalone.lastError = "Engine is not running";
  1046. return false;
  1047. }
  1048. bool carla_remove_all_plugins()
  1049. {
  1050. carla_debug("carla_remove_all_plugins()");
  1051. if (gStandalone.engine != nullptr)
  1052. return gStandalone.engine->removeAllPlugins();
  1053. carla_stderr2("Engine is not running");
  1054. gStandalone.lastError = "Engine is not running";
  1055. return false;
  1056. }
  1057. const char* carla_rename_plugin(uint pluginId, const char* newName)
  1058. {
  1059. CARLA_SAFE_ASSERT_RETURN(newName != nullptr && newName[0] != '\0', nullptr);
  1060. carla_debug("carla_rename_plugin(%i, \"%s\")", pluginId, newName);
  1061. if (gStandalone.engine != nullptr)
  1062. return gStandalone.engine->renamePlugin(pluginId, newName);
  1063. carla_stderr2("Engine is not running");
  1064. gStandalone.lastError = "Engine is not running";
  1065. return nullptr;
  1066. }
  1067. bool carla_clone_plugin(uint pluginId)
  1068. {
  1069. carla_debug("carla_clone_plugin(%i)", pluginId);
  1070. if (gStandalone.engine != nullptr)
  1071. return gStandalone.engine->clonePlugin(pluginId);
  1072. carla_stderr2("Engine is not running");
  1073. gStandalone.lastError = "Engine is not running";
  1074. return false;
  1075. }
  1076. bool carla_replace_plugin(uint pluginId)
  1077. {
  1078. carla_debug("carla_replace_plugin(%i)", pluginId);
  1079. if (gStandalone.engine != nullptr)
  1080. return gStandalone.engine->replacePlugin(pluginId);
  1081. carla_stderr2("Engine is not running");
  1082. gStandalone.lastError = "Engine is not running";
  1083. return false;
  1084. }
  1085. bool carla_switch_plugins(uint pluginIdA, uint pluginIdB)
  1086. {
  1087. CARLA_SAFE_ASSERT_RETURN(pluginIdA != pluginIdB, false);
  1088. carla_debug("carla_switch_plugins(%i, %i)", pluginIdA, pluginIdB);
  1089. if (gStandalone.engine != nullptr)
  1090. return gStandalone.engine->switchPlugins(pluginIdA, pluginIdB);
  1091. carla_stderr2("Engine is not running");
  1092. gStandalone.lastError = "Engine is not running";
  1093. return false;
  1094. }
  1095. // -------------------------------------------------------------------------------------------------------------------
  1096. bool carla_load_plugin_state(uint pluginId, const char* filename)
  1097. {
  1098. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  1099. carla_debug("carla_load_plugin_state(%i, \"%s\")", pluginId, filename);
  1100. if (gStandalone.engine == nullptr || ! gStandalone.engine->isRunning())
  1101. {
  1102. carla_stderr2("Engine is not running");
  1103. gStandalone.lastError = "Engine is not running";
  1104. return false;
  1105. }
  1106. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1107. return plugin->loadStateFromFile(filename);
  1108. carla_stderr2("carla_load_plugin_state(%i, \"%s\") - could not find plugin", pluginId, filename);
  1109. return false;
  1110. }
  1111. bool carla_save_plugin_state(uint pluginId, const char* filename)
  1112. {
  1113. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  1114. carla_debug("carla_save_plugin_state(%i, \"%s\")", pluginId, filename);
  1115. if (gStandalone.engine == nullptr)
  1116. {
  1117. carla_stderr2("Engine is not running");
  1118. gStandalone.lastError = "Engine is not running";
  1119. return false;
  1120. }
  1121. // allow to save even if engine isn't running
  1122. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1123. return plugin->saveStateToFile(filename);
  1124. carla_stderr2("carla_save_plugin_state(%i, \"%s\") - could not find plugin", pluginId, filename);
  1125. return false;
  1126. }
  1127. // -------------------------------------------------------------------------------------------------------------------
  1128. const CarlaPluginInfo* carla_get_plugin_info(uint pluginId)
  1129. {
  1130. carla_debug("carla_get_plugin_info(%i)", pluginId);
  1131. static CarlaPluginInfo info;
  1132. // reset
  1133. info.type = CB::PLUGIN_NONE;
  1134. info.category = CB::PLUGIN_CATEGORY_NONE;
  1135. info.hints = 0x0;
  1136. info.optionsAvailable = 0x0;
  1137. info.optionsEnabled = 0x0;
  1138. info.filename = gNullCharPtr;
  1139. info.name = gNullCharPtr;
  1140. info.iconName = gNullCharPtr;
  1141. info.uniqueId = 0;
  1142. // cleanup
  1143. if (info.label != gNullCharPtr)
  1144. {
  1145. delete[] info.label;
  1146. info.label = gNullCharPtr;
  1147. }
  1148. if (info.maker != gNullCharPtr)
  1149. {
  1150. delete[] info.maker;
  1151. info.maker = gNullCharPtr;
  1152. }
  1153. if (info.copyright != gNullCharPtr)
  1154. {
  1155. delete[] info.copyright;
  1156. info.copyright = gNullCharPtr;
  1157. }
  1158. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &info);
  1159. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1160. {
  1161. char strBufLabel[STR_MAX+1];
  1162. char strBufMaker[STR_MAX+1];
  1163. char strBufCopyright[STR_MAX+1];
  1164. carla_zeroChar(strBufLabel, STR_MAX+1);
  1165. carla_zeroChar(strBufMaker, STR_MAX+1);
  1166. carla_zeroChar(strBufCopyright, STR_MAX+1);
  1167. info.type = plugin->getType();
  1168. info.category = plugin->getCategory();
  1169. info.hints = plugin->getHints();
  1170. info.filename = plugin->getFilename();
  1171. info.name = plugin->getName();
  1172. info.iconName = plugin->getIconName();
  1173. info.uniqueId = plugin->getUniqueId();
  1174. info.optionsAvailable = plugin->getOptionsAvailable();
  1175. info.optionsEnabled = plugin->getOptionsEnabled();
  1176. plugin->getLabel(strBufLabel);
  1177. info.label = carla_strdup(strBufLabel);
  1178. plugin->getMaker(strBufMaker);
  1179. info.maker = carla_strdup(strBufMaker);
  1180. plugin->getCopyright(strBufCopyright);
  1181. info.copyright = carla_strdup(strBufCopyright);
  1182. checkStringPtr(info.filename);
  1183. checkStringPtr(info.name);
  1184. checkStringPtr(info.iconName);
  1185. return &info;
  1186. }
  1187. carla_stderr2("carla_get_plugin_info(%i) - could not find plugin", pluginId);
  1188. return &info;
  1189. }
  1190. const CarlaPortCountInfo* carla_get_audio_port_count_info(uint pluginId)
  1191. {
  1192. carla_debug("carla_get_audio_port_count_info(%i)", pluginId);
  1193. static CarlaPortCountInfo info;
  1194. // reset
  1195. info.ins = 0;
  1196. info.outs = 0;
  1197. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &info);
  1198. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1199. {
  1200. info.ins = plugin->getAudioInCount();
  1201. info.outs = plugin->getAudioOutCount();
  1202. return &info;
  1203. }
  1204. carla_stderr2("carla_get_audio_port_count_info(%i) - could not find plugin", pluginId);
  1205. return &info;
  1206. }
  1207. const CarlaPortCountInfo* carla_get_midi_port_count_info(uint pluginId)
  1208. {
  1209. carla_debug("carla_get_midi_port_count_info(%i)", pluginId);
  1210. static CarlaPortCountInfo info;
  1211. // reset
  1212. info.ins = 0;
  1213. info.outs = 0;
  1214. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &info);
  1215. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1216. {
  1217. info.ins = plugin->getMidiInCount();
  1218. info.outs = plugin->getMidiOutCount();
  1219. return &info;
  1220. }
  1221. carla_stderr2("carla_get_midi_port_count_info(%i) - could not find plugin", pluginId);
  1222. return &info;
  1223. }
  1224. const CarlaPortCountInfo* carla_get_parameter_count_info(uint pluginId)
  1225. {
  1226. carla_debug("carla_get_parameter_count_info(%i)", pluginId);
  1227. static CarlaPortCountInfo info;
  1228. // reset
  1229. info.ins = 0;
  1230. info.outs = 0;
  1231. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &info);
  1232. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1233. {
  1234. plugin->getParameterCountInfo(info.ins, info.outs);
  1235. return &info;
  1236. }
  1237. carla_stderr2("carla_get_parameter_count_info(%i) - could not find plugin", pluginId);
  1238. return &info;
  1239. }
  1240. const CarlaParameterInfo* carla_get_parameter_info(uint pluginId, uint32_t parameterId)
  1241. {
  1242. carla_debug("carla_get_parameter_info(%i, %i)", pluginId, parameterId);
  1243. static CarlaParameterInfo info;
  1244. // reset
  1245. info.scalePointCount = 0;
  1246. // cleanup
  1247. if (info.name != gNullCharPtr)
  1248. {
  1249. delete[] info.name;
  1250. info.name = gNullCharPtr;
  1251. }
  1252. if (info.symbol != gNullCharPtr)
  1253. {
  1254. delete[] info.symbol;
  1255. info.symbol = gNullCharPtr;
  1256. }
  1257. if (info.unit != gNullCharPtr)
  1258. {
  1259. delete[] info.unit;
  1260. info.unit = gNullCharPtr;
  1261. }
  1262. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &info);
  1263. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1264. {
  1265. if (parameterId < plugin->getParameterCount())
  1266. {
  1267. char strBufName[STR_MAX+1];
  1268. char strBufSymbol[STR_MAX+1];
  1269. char strBufUnit[STR_MAX+1];
  1270. carla_zeroChar(strBufName, STR_MAX+1);
  1271. carla_zeroChar(strBufSymbol, STR_MAX+1);
  1272. carla_zeroChar(strBufUnit, STR_MAX+1);
  1273. info.scalePointCount = plugin->getParameterScalePointCount(parameterId);
  1274. plugin->getParameterName(parameterId, strBufName);
  1275. info.name = carla_strdup(strBufName);
  1276. plugin->getParameterSymbol(parameterId, strBufSymbol);
  1277. info.symbol = carla_strdup(strBufSymbol);
  1278. plugin->getParameterUnit(parameterId, strBufUnit);
  1279. info.unit = carla_strdup(strBufUnit);
  1280. }
  1281. else
  1282. carla_stderr2("carla_get_parameter_info(%i, %i) - parameterId out of bounds", pluginId, parameterId);
  1283. return &info;
  1284. }
  1285. carla_stderr2("carla_get_parameter_info(%i, %i) - could not find plugin", pluginId, parameterId);
  1286. return &info;
  1287. }
  1288. const CarlaScalePointInfo* carla_get_parameter_scalepoint_info(uint pluginId, uint32_t parameterId, uint32_t scalePointId)
  1289. {
  1290. carla_debug("carla_get_parameter_scalepoint_info(%i, %i, %i)", pluginId, parameterId, scalePointId);
  1291. CARLA_ASSERT(gStandalone.engine != nullptr);
  1292. static CarlaScalePointInfo info;
  1293. // reset
  1294. info.value = 0.0f;
  1295. // cleanup
  1296. if (info.label != gNullCharPtr)
  1297. {
  1298. delete[] info.label;
  1299. info.label = gNullCharPtr;
  1300. }
  1301. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &info);
  1302. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1303. {
  1304. if (parameterId < plugin->getParameterCount())
  1305. {
  1306. if (scalePointId < plugin->getParameterScalePointCount(parameterId))
  1307. {
  1308. char strBufLabel[STR_MAX+1];
  1309. carla_zeroChar(strBufLabel, STR_MAX+1);
  1310. info.value = plugin->getParameterScalePointValue(parameterId, scalePointId);
  1311. plugin->getParameterScalePointLabel(parameterId, scalePointId, strBufLabel);
  1312. info.label = carla_strdup(strBufLabel);
  1313. }
  1314. else
  1315. carla_stderr2("carla_get_parameter_scalepoint_info(%i, %i, %i) - scalePointId out of bounds", pluginId, parameterId, scalePointId);
  1316. }
  1317. else
  1318. carla_stderr2("carla_get_parameter_scalepoint_info(%i, %i, %i) - parameterId out of bounds", pluginId, parameterId, scalePointId);
  1319. return &info;
  1320. }
  1321. carla_stderr2("carla_get_parameter_scalepoint_info(%i, %i, %i) - could not find plugin", pluginId, parameterId, scalePointId);
  1322. return &info;
  1323. }
  1324. // -------------------------------------------------------------------------------------------------------------------
  1325. const ParameterData* carla_get_parameter_data(uint pluginId, uint32_t parameterId)
  1326. {
  1327. carla_debug("carla_get_parameter_data(%i, %i)", pluginId, parameterId);
  1328. static const ParameterData fallbackParameterData = { CB::PARAMETER_UNKNOWN, 0x0, CB::PARAMETER_NULL, -1, -1, 0 };
  1329. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &fallbackParameterData);
  1330. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1331. {
  1332. if (parameterId < plugin->getParameterCount())
  1333. return &plugin->getParameterData(parameterId);
  1334. carla_stderr2("carla_get_parameter_data(%i, %i) - parameterId out of bounds", pluginId, parameterId);
  1335. return &fallbackParameterData;
  1336. }
  1337. carla_stderr2("carla_get_parameter_data(%i, %i) - could not find plugin", pluginId, parameterId);
  1338. return &fallbackParameterData;
  1339. }
  1340. const ParameterRanges* carla_get_parameter_ranges(uint pluginId, uint32_t parameterId)
  1341. {
  1342. carla_debug("carla_get_parameter_ranges(%i, %i)", pluginId, parameterId);
  1343. static const ParameterRanges fallbackParamRanges = { 0.0f, 0.0f, 1.0f, 0.01f, 0.0001f, 0.1f };
  1344. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &fallbackParamRanges);
  1345. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1346. {
  1347. if (parameterId < plugin->getParameterCount())
  1348. return &plugin->getParameterRanges(parameterId);
  1349. carla_stderr2("carla_get_parameter_ranges(%i, %i) - parameterId out of bounds", pluginId, parameterId);
  1350. return &fallbackParamRanges;
  1351. }
  1352. carla_stderr2("carla_get_parameter_ranges(%i, %i) - could not find plugin", pluginId, parameterId);
  1353. return &fallbackParamRanges;
  1354. }
  1355. const MidiProgramData* carla_get_midi_program_data(uint pluginId, uint32_t midiProgramId)
  1356. {
  1357. carla_debug("carla_get_midi_program_data(%i, %i)", pluginId, midiProgramId);
  1358. static MidiProgramData midiProgData;
  1359. // reset
  1360. midiProgData.bank = 0;
  1361. midiProgData.program = 0;
  1362. midiProgData.name = gNullCharPtr;
  1363. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &midiProgData);
  1364. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1365. {
  1366. if (midiProgramId < plugin->getMidiProgramCount())
  1367. {
  1368. const MidiProgramData& ret(plugin->getMidiProgramData(midiProgramId));
  1369. carla_copyStruct<MidiProgramData>(midiProgData, ret);
  1370. checkStringPtr(midiProgData.name);
  1371. return &midiProgData;
  1372. }
  1373. carla_stderr2("carla_get_midi_program_data(%i, %i) - midiProgramId out of bounds", pluginId, midiProgramId);
  1374. return &midiProgData;
  1375. }
  1376. carla_stderr2("carla_get_midi_program_data(%i, %i) - could not find plugin", pluginId, midiProgramId);
  1377. return &midiProgData;
  1378. }
  1379. const CustomData* carla_get_custom_data(uint pluginId, uint32_t customDataId)
  1380. {
  1381. carla_debug("carla_get_custom_data(%i, %i)", pluginId, customDataId);
  1382. static CustomData customData;
  1383. // reset
  1384. customData.type = gNullCharPtr;
  1385. customData.key = gNullCharPtr;
  1386. customData.value = gNullCharPtr;
  1387. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &customData);
  1388. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1389. {
  1390. if (customDataId < plugin->getCustomDataCount())
  1391. {
  1392. const CustomData& ret(plugin->getCustomData(customDataId));
  1393. carla_copyStruct<CustomData>(customData, ret);
  1394. checkStringPtr(customData.type);
  1395. checkStringPtr(customData.key);
  1396. checkStringPtr(customData.value);
  1397. return &customData;
  1398. }
  1399. carla_stderr2("carla_get_custom_data(%i, %i) - customDataId out of bounds", pluginId, customDataId);
  1400. return &customData;
  1401. }
  1402. carla_stderr2("carla_get_custom_data(%i, %i) - could not find plugin", pluginId, customDataId);
  1403. return &customData;
  1404. }
  1405. const char* carla_get_chunk_data(uint pluginId)
  1406. {
  1407. carla_debug("carla_get_chunk_data(%i)", pluginId);
  1408. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, nullptr);
  1409. static CarlaString chunkData;
  1410. // cleanup
  1411. chunkData.clear();
  1412. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1413. {
  1414. if (plugin->getOptionsEnabled() & CB::PLUGIN_OPTION_USE_CHUNKS)
  1415. {
  1416. void* data = nullptr;
  1417. const int32_t dataSize(plugin->getChunkData(&data));
  1418. if (data != nullptr && dataSize > 0)
  1419. {
  1420. chunkData = QByteArray((char*)data, dataSize).toBase64().constData();
  1421. return chunkData;
  1422. }
  1423. else
  1424. carla_stderr2("carla_get_chunk_data(%i) - got invalid chunk data", pluginId);
  1425. }
  1426. else
  1427. carla_stderr2("carla_get_chunk_data(%i) - plugin does not use chunks", pluginId);
  1428. return nullptr;
  1429. }
  1430. carla_stderr2("carla_get_chunk_data(%i) - could not find plugin", pluginId);
  1431. return nullptr;
  1432. }
  1433. // -------------------------------------------------------------------------------------------------------------------
  1434. uint32_t carla_get_parameter_count(uint pluginId)
  1435. {
  1436. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0);
  1437. carla_debug("carla_get_parameter_count(%i)", pluginId);
  1438. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1439. return plugin->getParameterCount();
  1440. carla_stderr2("carla_get_parameter_count(%i) - could not find plugin", pluginId);
  1441. return 0;
  1442. }
  1443. uint32_t carla_get_program_count(uint pluginId)
  1444. {
  1445. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0);
  1446. carla_debug("carla_get_program_count(%i)", pluginId);
  1447. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1448. return plugin->getProgramCount();
  1449. carla_stderr2("carla_get_program_count(%i) - could not find plugin", pluginId);
  1450. return 0;
  1451. }
  1452. uint32_t carla_get_midi_program_count(uint pluginId)
  1453. {
  1454. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0);
  1455. carla_debug("carla_get_midi_program_count(%i)", pluginId);
  1456. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1457. return plugin->getMidiProgramCount();
  1458. carla_stderr2("carla_get_midi_program_count(%i) - could not find plugin", pluginId);
  1459. return 0;
  1460. }
  1461. uint32_t carla_get_custom_data_count(uint pluginId)
  1462. {
  1463. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0);
  1464. carla_debug("carla_get_custom_data_count(%i)", pluginId);
  1465. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1466. return plugin->getCustomDataCount();
  1467. carla_stderr2("carla_get_custom_data_count(%i) - could not find plugin", pluginId);
  1468. return 0;
  1469. }
  1470. // -------------------------------------------------------------------------------------------------------------------
  1471. const char* carla_get_parameter_text(uint pluginId, uint32_t parameterId)
  1472. {
  1473. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, nullptr);
  1474. carla_debug("carla_get_parameter_text(%i, %i)", pluginId, parameterId);
  1475. static char textBuf[STR_MAX+1];
  1476. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1477. {
  1478. if (parameterId < plugin->getParameterCount())
  1479. {
  1480. carla_zeroChar(textBuf, STR_MAX+1);
  1481. plugin->getParameterText(parameterId, textBuf);
  1482. return textBuf;
  1483. }
  1484. carla_stderr2("carla_get_parameter_text(%i, %i) - parameterId out of bounds", pluginId, parameterId);
  1485. return nullptr;
  1486. }
  1487. carla_stderr2("carla_get_parameter_text(%i, %i) - could not find plugin", pluginId, parameterId);
  1488. return nullptr;
  1489. }
  1490. const char* carla_get_program_name(uint pluginId, uint32_t programId)
  1491. {
  1492. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, nullptr);
  1493. carla_debug("carla_get_program_name(%i, %i)", pluginId, programId);
  1494. static char programName[STR_MAX+1];
  1495. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1496. {
  1497. if (programId < plugin->getProgramCount())
  1498. {
  1499. carla_zeroChar(programName, STR_MAX+1);
  1500. plugin->getProgramName(programId, programName);
  1501. return programName;
  1502. }
  1503. carla_stderr2("carla_get_program_name(%i, %i) - programId out of bounds", pluginId, programId);
  1504. return nullptr;
  1505. }
  1506. carla_stderr2("carla_get_program_name(%i, %i) - could not find plugin", pluginId, programId);
  1507. return nullptr;
  1508. }
  1509. const char* carla_get_midi_program_name(uint pluginId, uint32_t midiProgramId)
  1510. {
  1511. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, nullptr);
  1512. carla_debug("carla_get_midi_program_name(%i, %i)", pluginId, midiProgramId);
  1513. static char midiProgramName[STR_MAX+1];
  1514. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1515. {
  1516. if (midiProgramId < plugin->getMidiProgramCount())
  1517. {
  1518. carla_zeroChar(midiProgramName, STR_MAX+1);
  1519. plugin->getMidiProgramName(midiProgramId, midiProgramName);
  1520. return midiProgramName;
  1521. }
  1522. carla_stderr2("carla_get_midi_program_name(%i, %i) - midiProgramId out of bounds", pluginId, midiProgramId);
  1523. return nullptr;
  1524. }
  1525. carla_stderr2("carla_get_midi_program_name(%i, %i) - could not find plugin", pluginId, midiProgramId);
  1526. return nullptr;
  1527. }
  1528. const char* carla_get_real_plugin_name(uint pluginId)
  1529. {
  1530. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, nullptr);
  1531. carla_debug("carla_get_real_plugin_name(%i)", pluginId);
  1532. static char realPluginName[STR_MAX+1];
  1533. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1534. {
  1535. carla_zeroChar(realPluginName, STR_MAX+1);
  1536. plugin->getRealName(realPluginName);
  1537. return realPluginName;
  1538. }
  1539. carla_stderr2("carla_get_real_plugin_name(%i) - could not find plugin", pluginId);
  1540. return nullptr;
  1541. }
  1542. // -------------------------------------------------------------------------------------------------------------------
  1543. int32_t carla_get_current_program_index(uint pluginId)
  1544. {
  1545. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, -1);
  1546. carla_debug("carla_get_current_program_index(%i)", pluginId);
  1547. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1548. return plugin->getCurrentProgram();
  1549. carla_stderr2("carla_get_current_program_index(%i) - could not find plugin", pluginId);
  1550. return -1;
  1551. }
  1552. int32_t carla_get_current_midi_program_index(uint pluginId)
  1553. {
  1554. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, -1);
  1555. carla_debug("carla_get_current_midi_program_index(%i)", pluginId);
  1556. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1557. return plugin->getCurrentMidiProgram();
  1558. carla_stderr2("carla_get_current_midi_program_index(%i) - could not find plugin", pluginId);
  1559. return -1;
  1560. }
  1561. // -------------------------------------------------------------------------------------------------------------------
  1562. float carla_get_default_parameter_value(uint pluginId, uint32_t parameterId)
  1563. {
  1564. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0.0f);
  1565. carla_debug("carla_get_default_parameter_value(%i, %i)", pluginId, parameterId);
  1566. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1567. {
  1568. if (parameterId < plugin->getParameterCount())
  1569. return plugin->getParameterRanges(parameterId).def;
  1570. carla_stderr2("carla_get_default_parameter_value(%i, %i) - parameterId out of bounds", pluginId, parameterId);
  1571. return 0.0f;
  1572. }
  1573. carla_stderr2("carla_get_default_parameter_value(%i, %i) - could not find plugin", pluginId, parameterId);
  1574. return 0.0f;
  1575. }
  1576. float carla_get_current_parameter_value(uint pluginId, uint32_t parameterId)
  1577. {
  1578. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0.0f);
  1579. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1580. {
  1581. if (parameterId < plugin->getParameterCount())
  1582. return plugin->getParameterValue(parameterId);
  1583. carla_stderr2("carla_get_current_parameter_value(%i, %i) - parameterId out of bounds", pluginId, parameterId);
  1584. return 0.0f;
  1585. }
  1586. carla_stderr2("carla_get_current_parameter_value(%i, %i) - could not find plugin", pluginId, parameterId);
  1587. return 0.0f;
  1588. }
  1589. float carla_get_internal_parameter_value(uint pluginId, int32_t parameterId)
  1590. {
  1591. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0.0f);
  1592. CARLA_SAFE_ASSERT_RETURN(parameterId != CB::PARAMETER_NULL && parameterId > CB::PARAMETER_MAX, 0.0f);
  1593. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1594. return plugin->getInternalParameterValue(parameterId);
  1595. carla_stderr2("carla_get_internal_parameter_value(%i, %i) - could not find plugin", pluginId, parameterId);
  1596. return 0.0f;
  1597. }
  1598. // -------------------------------------------------------------------------------------------------------------------
  1599. float carla_get_input_peak_value(uint pluginId, bool isLeft)
  1600. {
  1601. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0.0f);
  1602. return gStandalone.engine->getInputPeak(pluginId, isLeft);
  1603. }
  1604. float carla_get_output_peak_value(uint pluginId, bool isLeft)
  1605. {
  1606. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0.0f);
  1607. return gStandalone.engine->getOutputPeak(pluginId, isLeft);
  1608. }
  1609. // -------------------------------------------------------------------------------------------------------------------
  1610. void carla_set_option(uint pluginId, uint option, bool yesNo)
  1611. {
  1612. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1613. carla_debug("carla_set_option(%i, %i, %s)", pluginId, option, bool2str(yesNo));
  1614. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1615. return plugin->setOption(option, yesNo);
  1616. carla_stderr2("carla_set_option(%i, %i, %s) - could not find plugin", pluginId, option, bool2str(yesNo));
  1617. }
  1618. void carla_set_active(uint pluginId, bool onOff)
  1619. {
  1620. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1621. carla_debug("carla_set_active(%i, %s)", pluginId, bool2str(onOff));
  1622. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1623. return plugin->setActive(onOff, true, false);
  1624. carla_stderr2("carla_set_active(%i, %s) - could not find plugin", pluginId, bool2str(onOff));
  1625. }
  1626. #ifndef BUILD_BRIDGE
  1627. void carla_set_drywet(uint pluginId, float value)
  1628. {
  1629. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1630. carla_debug("carla_set_drywet(%i, %f)", pluginId, value);
  1631. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1632. return plugin->setDryWet(value, true, false);
  1633. carla_stderr2("carla_set_drywet(%i, %f) - could not find plugin", pluginId, value);
  1634. }
  1635. void carla_set_volume(uint pluginId, float value)
  1636. {
  1637. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1638. carla_debug("carla_set_volume(%i, %f)", pluginId, value);
  1639. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1640. return plugin->setVolume(value, true, false);
  1641. carla_stderr2("carla_set_volume(%i, %f) - could not find plugin", pluginId, value);
  1642. }
  1643. void carla_set_balance_left(uint pluginId, float value)
  1644. {
  1645. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1646. carla_debug("carla_set_balance_left(%i, %f)", pluginId, value);
  1647. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1648. return plugin->setBalanceLeft(value, true, false);
  1649. carla_stderr2("carla_set_balance_left(%i, %f) - could not find plugin", pluginId, value);
  1650. }
  1651. void carla_set_balance_right(uint pluginId, float value)
  1652. {
  1653. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1654. carla_debug("carla_set_balance_right(%i, %f)", pluginId, value);
  1655. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1656. return plugin->setBalanceRight(value, true, false);
  1657. carla_stderr2("carla_set_balance_right(%i, %f) - could not find plugin", pluginId, value);
  1658. }
  1659. void carla_set_panning(uint pluginId, float value)
  1660. {
  1661. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1662. carla_debug("carla_set_panning(%i, %f)", pluginId, value);
  1663. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1664. return plugin->setPanning(value, true, false);
  1665. carla_stderr2("carla_set_panning(%i, %f) - could not find plugin", pluginId, value);
  1666. }
  1667. #endif
  1668. void carla_set_ctrl_channel(uint pluginId, int8_t channel)
  1669. {
  1670. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1671. carla_debug("carla_set_ctrl_channel(%i, %i)", pluginId, channel);
  1672. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1673. return plugin->setCtrlChannel(channel, true, false);
  1674. carla_stderr2("carla_set_ctrl_channel(%i, %i) - could not find plugin", pluginId, channel);
  1675. }
  1676. // -------------------------------------------------------------------------------------------------------------------
  1677. void carla_set_parameter_value(uint pluginId, uint32_t parameterId, float value)
  1678. {
  1679. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1680. carla_debug("carla_set_parameter_value(%i, %i, %f)", pluginId, parameterId, value);
  1681. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1682. {
  1683. if (parameterId < plugin->getParameterCount())
  1684. return plugin->setParameterValue(parameterId, value, true, true, false);
  1685. carla_stderr2("carla_set_parameter_value(%i, %i, %f) - parameterId out of bounds", pluginId, parameterId, value);
  1686. return;
  1687. }
  1688. carla_stderr2("carla_set_parameter_value(%i, %i, %f) - could not find plugin", pluginId, parameterId, value);
  1689. }
  1690. #ifndef BUILD_BRIDGE
  1691. void carla_set_parameter_midi_channel(uint pluginId, uint32_t parameterId, uint8_t channel)
  1692. {
  1693. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1694. CARLA_SAFE_ASSERT_RETURN(channel >= MAX_MIDI_CHANNELS,);
  1695. carla_debug("carla_set_parameter_midi_channel(%i, %i, %i)", pluginId, parameterId, channel);
  1696. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1697. {
  1698. if (parameterId < plugin->getParameterCount())
  1699. return plugin->setParameterMidiChannel(parameterId, channel, true, false);
  1700. carla_stderr2("carla_set_parameter_midi_channel(%i, %i, %i) - parameterId out of bounds", pluginId, parameterId, channel);
  1701. return;
  1702. }
  1703. carla_stderr2("carla_set_parameter_midi_channel(%i, %i, %i) - could not find plugin", pluginId, parameterId, channel);
  1704. }
  1705. void carla_set_parameter_midi_cc(uint pluginId, uint32_t parameterId, int16_t cc)
  1706. {
  1707. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1708. CARLA_SAFE_ASSERT_RETURN(cc >= -1 && cc <= 0x5F,);
  1709. carla_debug("carla_set_parameter_midi_cc(%i, %i, %i)", pluginId, parameterId, cc);
  1710. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1711. {
  1712. if (parameterId < plugin->getParameterCount())
  1713. return plugin->setParameterMidiCC(parameterId, cc, true, false);
  1714. carla_stderr2("carla_set_parameter_midi_cc(%i, %i, %i) - parameterId out of bounds", pluginId, parameterId, cc);
  1715. return;
  1716. }
  1717. carla_stderr2("carla_set_parameter_midi_cc(%i, %i, %i) - could not find plugin", pluginId, parameterId, cc);
  1718. }
  1719. #endif
  1720. // -------------------------------------------------------------------------------------------------------------------
  1721. void carla_set_program(uint pluginId, uint32_t programId)
  1722. {
  1723. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1724. carla_debug("carla_set_program(%i, %i)", pluginId, programId);
  1725. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1726. {
  1727. if (programId < plugin->getProgramCount())
  1728. return plugin->setProgram(static_cast<int32_t>(programId), true, true, false);
  1729. carla_stderr2("carla_set_program(%i, %i) - programId out of bounds", pluginId, programId);
  1730. return;
  1731. }
  1732. carla_stderr2("carla_set_program(%i, %i) - could not find plugin", pluginId, programId);
  1733. }
  1734. void carla_set_midi_program(uint pluginId, uint32_t midiProgramId)
  1735. {
  1736. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1737. carla_debug("carla_set_midi_program(%i, %i)", pluginId, midiProgramId);
  1738. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1739. {
  1740. if (midiProgramId < plugin->getMidiProgramCount())
  1741. return plugin->setMidiProgram(static_cast<int32_t>(midiProgramId), true, true, false);
  1742. carla_stderr2("carla_set_midi_program(%i, %i) - midiProgramId out of bounds", pluginId, midiProgramId);
  1743. return;
  1744. }
  1745. carla_stderr2("carla_set_midi_program(%i, %i) - could not find plugin", pluginId, midiProgramId);
  1746. }
  1747. // -------------------------------------------------------------------------------------------------------------------
  1748. void carla_set_custom_data(uint pluginId, const char* type, const char* key, const char* value)
  1749. {
  1750. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1751. CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0',);
  1752. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
  1753. CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
  1754. carla_debug("carla_set_custom_data(%i, \"%s\", \"%s\", \"%s\")", pluginId, type, key, value);
  1755. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1756. return plugin->setCustomData(type, key, value, true);
  1757. carla_stderr2("carla_set_custom_data(%i, \"%s\", \"%s\", \"%s\") - could not find plugin", pluginId, type, key, value);
  1758. }
  1759. void carla_set_chunk_data(uint pluginId, const char* chunkData)
  1760. {
  1761. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1762. CARLA_SAFE_ASSERT_RETURN(chunkData != nullptr && chunkData[0] != '\0',);
  1763. carla_debug("carla_set_chunk_data(%i, \"%s\")", pluginId, chunkData);
  1764. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1765. {
  1766. if (plugin->getOptionsEnabled() & CB::PLUGIN_OPTION_USE_CHUNKS)
  1767. return plugin->setChunkData(chunkData);
  1768. carla_stderr2("carla_set_chunk_data(%i, \"%s\") - plugin does not use chunks", pluginId, chunkData);
  1769. return;
  1770. }
  1771. carla_stderr2("carla_set_chunk_data(%i, \"%s\") - could not find plugin", pluginId, chunkData);
  1772. }
  1773. // -------------------------------------------------------------------------------------------------------------------
  1774. void carla_prepare_for_save(uint pluginId)
  1775. {
  1776. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1777. carla_debug("carla_prepare_for_save(%i)", pluginId);
  1778. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1779. return plugin->prepareForSave();
  1780. carla_stderr2("carla_prepare_for_save(%i) - could not find plugin", pluginId);
  1781. }
  1782. void carla_reset_parameters(uint pluginId)
  1783. {
  1784. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1785. carla_debug("carla_reset_parameters(%i)", pluginId);
  1786. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1787. return plugin->resetParameters();
  1788. carla_stderr2("carla_reset_parameters(%i) - could not find plugin", pluginId);
  1789. }
  1790. void carla_randomize_parameters(uint pluginId)
  1791. {
  1792. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1793. carla_debug("carla_randomize_parameters(%i)", pluginId);
  1794. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1795. return plugin->randomizeParameters();
  1796. carla_stderr2("carla_randomize_parameters(%i) - could not find plugin", pluginId);
  1797. }
  1798. #ifndef BUILD_BRIDGE
  1799. void carla_send_midi_note(uint pluginId, uint8_t channel, uint8_t note, uint8_t velocity)
  1800. {
  1801. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr && gStandalone.engine->isRunning(),);
  1802. carla_debug("carla_send_midi_note(%i, %i, %i, %i)", pluginId, channel, note, velocity);
  1803. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1804. return plugin->sendMidiSingleNote(channel, note, velocity, true, true, false);
  1805. carla_stderr2("carla_send_midi_note(%i, %i, %i, %i) - could not find plugin", pluginId, channel, note, velocity);
  1806. }
  1807. #endif
  1808. void carla_show_custom_ui(uint pluginId, bool yesNo)
  1809. {
  1810. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1811. carla_debug("carla_show_custom_ui(%i, %s)", pluginId, bool2str(yesNo));
  1812. if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
  1813. return plugin->showCustomUI(yesNo);
  1814. carla_stderr2("carla_show_custom_ui(%i, %s) - could not find plugin", pluginId, bool2str(yesNo));
  1815. }
  1816. // -------------------------------------------------------------------------------------------------------------------
  1817. uint32_t carla_get_buffer_size()
  1818. {
  1819. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0);
  1820. carla_debug("carla_get_buffer_size()");
  1821. return gStandalone.engine->getBufferSize();
  1822. }
  1823. double carla_get_sample_rate()
  1824. {
  1825. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0.0);
  1826. carla_debug("carla_get_sample_rate()");
  1827. return gStandalone.engine->getSampleRate();
  1828. }
  1829. // -------------------------------------------------------------------------------------------------------------------
  1830. const char* carla_get_last_error()
  1831. {
  1832. carla_debug("carla_get_last_error()");
  1833. if (gStandalone.engine != nullptr)
  1834. return gStandalone.engine->getLastError();
  1835. return gStandalone.lastError;
  1836. }
  1837. const char* carla_get_host_osc_url_tcp()
  1838. {
  1839. carla_debug("carla_get_host_osc_url_tcp()");
  1840. if (gStandalone.engine == nullptr)
  1841. {
  1842. carla_stderr2("Engine is not running");
  1843. gStandalone.lastError = "Engine is not running";
  1844. return nullptr;
  1845. }
  1846. return gStandalone.engine->getOscServerPathTCP();
  1847. }
  1848. const char* carla_get_host_osc_url_udp()
  1849. {
  1850. carla_debug("carla_get_host_osc_url_udp()");
  1851. if (gStandalone.engine == nullptr)
  1852. {
  1853. carla_stderr2("Engine is not running");
  1854. gStandalone.lastError = "Engine is not running";
  1855. return nullptr;
  1856. }
  1857. return gStandalone.engine->getOscServerPathUDP();
  1858. }
  1859. // -------------------------------------------------------------------------------------------------------------------
  1860. #ifdef WANT_DSSI
  1861. # include "CarlaDssiUtils.cpp"
  1862. #endif
  1863. #include "CarlaStateUtils.cpp"
  1864. #if 0
  1865. int main(int argc, char* argv[])
  1866. {
  1867. return 0;
  1868. }
  1869. #endif
  1870. // -------------------------------------------------------------------------------------------------------------------