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.

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