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.

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