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.

2281 lines
77KB

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