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.

2434 lines
84KB

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