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.

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