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.

2417 lines
80KB

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