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.

2305 lines
78KB

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