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.

2127 lines
75KB

  1. /*
  2. * Carla Standalone
  3. * Copyright (C) 2011-2019 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 "CarlaEngine.hpp"
  22. #include "CarlaPlugin.hpp"
  23. #include "CarlaBackendUtils.hpp"
  24. #include "CarlaBase64Utils.hpp"
  25. #ifdef CARLA_OS_UNIX
  26. # include "CarlaLibUtils.hpp"
  27. #endif
  28. #ifdef BUILD_BRIDGE
  29. # include "water/files/File.h"
  30. #else
  31. # include "CarlaLogThread.hpp"
  32. #endif
  33. #ifdef USING_JUCE
  34. # if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
  35. # pragma GCC diagnostic push
  36. # pragma GCC diagnostic ignored "-Wconversion"
  37. # pragma GCC diagnostic ignored "-Weffc++"
  38. # pragma GCC diagnostic ignored "-Wsign-conversion"
  39. # pragma GCC diagnostic ignored "-Wundef"
  40. # endif
  41. # include "AppConfig.h"
  42. # include "juce_events/juce_events.h"
  43. # if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
  44. # pragma GCC diagnostic pop
  45. # endif
  46. #endif
  47. #define CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(cond, msg, ret) \
  48. if (! (cond)) { \
  49. carla_stderr2("%s: " msg, __FUNCTION__); \
  50. gStandalone.lastError = msg; \
  51. return ret; \
  52. }
  53. namespace CB = CarlaBackend;
  54. using CB::EngineOptions;
  55. // --------------------------------------------------------------------------------------------------------------------
  56. // Single, standalone engine
  57. struct CarlaBackendStandalone {
  58. CarlaEngine* engine;
  59. EngineCallbackFunc engineCallback;
  60. void* engineCallbackPtr;
  61. #ifndef BUILD_BRIDGE
  62. EngineOptions engineOptions;
  63. CarlaLogThread logThread;
  64. bool logThreadEnabled;
  65. #endif
  66. FileCallbackFunc fileCallback;
  67. void* fileCallbackPtr;
  68. CarlaString lastError;
  69. CarlaBackendStandalone() noexcept
  70. : engine(nullptr),
  71. engineCallback(nullptr),
  72. engineCallbackPtr(nullptr),
  73. #ifndef BUILD_BRIDGE
  74. engineOptions(),
  75. logThread(),
  76. logThreadEnabled(false),
  77. #endif
  78. fileCallback(nullptr),
  79. fileCallbackPtr(nullptr),
  80. lastError() {}
  81. ~CarlaBackendStandalone() noexcept
  82. {
  83. CARLA_SAFE_ASSERT(engine == nullptr);
  84. }
  85. CARLA_PREVENT_HEAP_ALLOCATION
  86. CARLA_DECLARE_NON_COPY_STRUCT(CarlaBackendStandalone)
  87. };
  88. CarlaBackendStandalone gStandalone;
  89. #ifdef CARLA_OS_UNIX
  90. // --------------------------------------------------------------------------------------------------------------------
  91. // Thread-safe fftw
  92. typedef void (*void_func)(void);
  93. class ThreadSafeFFTW
  94. {
  95. public:
  96. struct Deinitializer {
  97. Deinitializer(ThreadSafeFFTW& s)
  98. : tsfftw(s) {}
  99. ~Deinitializer()
  100. {
  101. tsfftw.deinit();
  102. }
  103. ThreadSafeFFTW& tsfftw;
  104. };
  105. ThreadSafeFFTW()
  106. : initialized(false),
  107. libfftw3(nullptr),
  108. libfftw3f(nullptr),
  109. libfftw3l(nullptr),
  110. libfftw3q(nullptr) {}
  111. ~ThreadSafeFFTW()
  112. {
  113. CARLA_SAFE_ASSERT(libfftw3 == nullptr);
  114. }
  115. void init()
  116. {
  117. if (initialized)
  118. return;
  119. initialized = true;
  120. if ((libfftw3 = lib_open("libfftw3_threads.so.3")) != nullptr)
  121. if (const void_func func = lib_symbol<void_func>(libfftw3, "fftw_make_planner_thread_safe"))
  122. func();
  123. if ((libfftw3f = lib_open("libfftw3f_threads.so.3")) != nullptr)
  124. if (const void_func func = lib_symbol<void_func>(libfftw3f, "fftwf_make_planner_thread_safe"))
  125. func();
  126. if ((libfftw3l = lib_open("libfftw3l_threads.so.3")) != nullptr)
  127. if (const void_func func = lib_symbol<void_func>(libfftw3l, "fftwl_make_planner_thread_safe"))
  128. func();
  129. if ((libfftw3q = lib_open("libfftw3q_threads.so.3")) != nullptr)
  130. if (const void_func func = lib_symbol<void_func>(libfftw3q, "fftwq_make_planner_thread_safe"))
  131. func();
  132. }
  133. void deinit()
  134. {
  135. if (! initialized)
  136. return;
  137. initialized = false;
  138. if (libfftw3 != nullptr)
  139. {
  140. lib_close(libfftw3);
  141. libfftw3 = nullptr;
  142. }
  143. if (libfftw3f != nullptr)
  144. {
  145. lib_close(libfftw3f);
  146. libfftw3f = nullptr;
  147. }
  148. if (libfftw3l != nullptr)
  149. {
  150. lib_close(libfftw3l);
  151. libfftw3l = nullptr;
  152. }
  153. if (libfftw3q != nullptr)
  154. {
  155. lib_close(libfftw3q);
  156. libfftw3q = nullptr;
  157. }
  158. }
  159. private:
  160. bool initialized;
  161. lib_t libfftw3;
  162. lib_t libfftw3f;
  163. lib_t libfftw3l;
  164. lib_t libfftw3q;
  165. CARLA_DECLARE_NON_COPY_CLASS(ThreadSafeFFTW)
  166. };
  167. static ThreadSafeFFTW sThreadSafeFFTW;
  168. #endif
  169. // --------------------------------------------------------------------------------------------------------------------
  170. // API
  171. #define CARLA_COMMON_NEED_CHECKSTRINGPTR
  172. #include "CarlaHostCommon.cpp"
  173. #undef CARLA_COMMON_NEED_CHECKSTRINGPTR
  174. // --------------------------------------------------------------------------------------------------------------------
  175. uint carla_get_engine_driver_count()
  176. {
  177. carla_debug("carla_get_engine_driver_count()");
  178. return CarlaEngine::getDriverCount();
  179. }
  180. const char* carla_get_engine_driver_name(uint index)
  181. {
  182. carla_debug("carla_get_engine_driver_name(%i)", index);
  183. return CarlaEngine::getDriverName(index);
  184. }
  185. const char* const* carla_get_engine_driver_device_names(uint index)
  186. {
  187. carla_debug("carla_get_engine_driver_device_names(%i)", index);
  188. return CarlaEngine::getDriverDeviceNames(index);
  189. }
  190. const EngineDriverDeviceInfo* carla_get_engine_driver_device_info(uint index, const char* name)
  191. {
  192. CARLA_SAFE_ASSERT_RETURN(name != nullptr, nullptr);
  193. static EngineDriverDeviceInfo retDevInfo;
  194. static const uint32_t nullBufferSizes[] = { 0 };
  195. static const double nullSampleRates[] = { 0.0 };
  196. carla_debug("carla_get_engine_driver_device_info(%i, \"%s\")", index, name);
  197. if (const EngineDriverDeviceInfo* const devInfo = CarlaEngine::getDriverDeviceInfo(index, name))
  198. {
  199. retDevInfo.hints = devInfo->hints;
  200. retDevInfo.bufferSizes = (devInfo->bufferSizes != nullptr) ? devInfo->bufferSizes : nullBufferSizes;
  201. retDevInfo.sampleRates = (devInfo->sampleRates != nullptr) ? devInfo->sampleRates : nullSampleRates;
  202. }
  203. else
  204. {
  205. retDevInfo.hints = 0x0;
  206. retDevInfo.bufferSizes = nullBufferSizes;
  207. retDevInfo.sampleRates = nullSampleRates;
  208. }
  209. return &retDevInfo;
  210. }
  211. // --------------------------------------------------------------------------------------------------------------------
  212. CarlaEngine* carla_get_engine()
  213. {
  214. carla_debug("carla_get_engine()");
  215. return gStandalone.engine;
  216. }
  217. // --------------------------------------------------------------------------------------------------------------------
  218. static void carla_engine_init_common(CarlaEngine* const engine)
  219. {
  220. engine->setCallback(gStandalone.engineCallback, gStandalone.engineCallbackPtr);
  221. engine->setFileCallback(gStandalone.fileCallback, gStandalone.fileCallbackPtr);
  222. #ifdef BUILD_BRIDGE
  223. using water::File;
  224. File waterBinaryDir(File::getSpecialLocation(File::currentExecutableFile).getParentDirectory());
  225. /*
  226. if (const char* const uisAlwaysOnTop = std::getenv("ENGINE_OPTION_FORCE_STEREO"))
  227. engine->setOption(CB::ENGINE_OPTION_FORCE_STEREO, (std::strcmp(uisAlwaysOnTop, "true") == 0) ? 1 : 0, nullptr);
  228. if (const char* const uisAlwaysOnTop = std::getenv("ENGINE_OPTION_PREFER_PLUGIN_BRIDGES"))
  229. engine->setOption(CB::ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, (std::strcmp(uisAlwaysOnTop, "true") == 0) ? 1 : 0, nullptr);
  230. if (const char* const uisAlwaysOnTop = std::getenv("ENGINE_OPTION_PREFER_UI_BRIDGES"))
  231. engine->setOption(CB::ENGINE_OPTION_PREFER_UI_BRIDGES, (std::strcmp(uisAlwaysOnTop, "true") == 0) ? 1 : 0, nullptr);
  232. */
  233. if (const char* const uisAlwaysOnTop = std::getenv("ENGINE_OPTION_UIS_ALWAYS_ON_TOP"))
  234. engine->setOption(CB::ENGINE_OPTION_UIS_ALWAYS_ON_TOP, (std::strcmp(uisAlwaysOnTop, "true") == 0) ? 1 : 0, nullptr);
  235. if (const char* const maxParameters = std::getenv("ENGINE_OPTION_MAX_PARAMETERS"))
  236. engine->setOption(CB::ENGINE_OPTION_MAX_PARAMETERS, std::atoi(maxParameters), nullptr);
  237. if (const char* const uiBridgesTimeout = std::getenv("ENGINE_OPTION_UI_BRIDGES_TIMEOUT"))
  238. engine->setOption(CB::ENGINE_OPTION_UI_BRIDGES_TIMEOUT, std::atoi(uiBridgesTimeout), nullptr);
  239. if (const char* const pathLADSPA = std::getenv("ENGINE_OPTION_PLUGIN_PATH_LADSPA"))
  240. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_LADSPA, pathLADSPA);
  241. if (const char* const pathDSSI = std::getenv("ENGINE_OPTION_PLUGIN_PATH_DSSI"))
  242. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_DSSI, pathDSSI);
  243. if (const char* const pathLV2 = std::getenv("ENGINE_OPTION_PLUGIN_PATH_LV2"))
  244. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_LV2, pathLV2);
  245. if (const char* const pathVST2 = std::getenv("ENGINE_OPTION_PLUGIN_PATH_VST2"))
  246. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_VST2, pathVST2);
  247. if (const char* const pathVST3 = std::getenv("ENGINE_OPTION_PLUGIN_PATH_VST3"))
  248. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_VST3, pathVST3);
  249. if (const char* const pathSF2 = std::getenv("ENGINE_OPTION_PLUGIN_PATH_SF2"))
  250. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_SF2, pathSF2);
  251. if (const char* const pathSFZ = std::getenv("ENGINE_OPTION_PLUGIN_PATH_SFZ"))
  252. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_SFZ, pathSFZ);
  253. if (const char* const binaryDir = std::getenv("ENGINE_OPTION_PATH_BINARIES"))
  254. engine->setOption(CB::ENGINE_OPTION_PATH_BINARIES, 0, binaryDir);
  255. else
  256. engine->setOption(CB::ENGINE_OPTION_PATH_BINARIES, 0, waterBinaryDir.getFullPathName().toRawUTF8());
  257. if (const char* const resourceDir = std::getenv("ENGINE_OPTION_PATH_RESOURCES"))
  258. engine->setOption(CB::ENGINE_OPTION_PATH_RESOURCES, 0, resourceDir);
  259. else
  260. engine->setOption(CB::ENGINE_OPTION_PATH_RESOURCES, 0, waterBinaryDir.getChildFile("resources").getFullPathName().toRawUTF8());
  261. if (const char* const preventBadBehaviour = std::getenv("ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR"))
  262. engine->setOption(CB::ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR, (std::strcmp(preventBadBehaviour, "true") == 0) ? 1 : 0, nullptr);
  263. if (const char* const frontendWinId = std::getenv("ENGINE_OPTION_FRONTEND_WIN_ID"))
  264. engine->setOption(CB::ENGINE_OPTION_FRONTEND_WIN_ID, 0, frontendWinId);
  265. #else
  266. engine->setOption(CB::ENGINE_OPTION_FORCE_STEREO, gStandalone.engineOptions.forceStereo ? 1 : 0, nullptr);
  267. engine->setOption(CB::ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, gStandalone.engineOptions.preferPluginBridges ? 1 : 0, nullptr);
  268. engine->setOption(CB::ENGINE_OPTION_PREFER_UI_BRIDGES, gStandalone.engineOptions.preferUiBridges ? 1 : 0, nullptr);
  269. engine->setOption(CB::ENGINE_OPTION_UIS_ALWAYS_ON_TOP, gStandalone.engineOptions.uisAlwaysOnTop ? 1 : 0, nullptr);
  270. engine->setOption(CB::ENGINE_OPTION_MAX_PARAMETERS, static_cast<int>(gStandalone.engineOptions.maxParameters), nullptr);
  271. engine->setOption(CB::ENGINE_OPTION_UI_BRIDGES_TIMEOUT, static_cast<int>(gStandalone.engineOptions.uiBridgesTimeout), nullptr);
  272. engine->setOption(CB::ENGINE_OPTION_AUDIO_BUFFER_SIZE, static_cast<int>(gStandalone.engineOptions.audioBufferSize), nullptr);
  273. engine->setOption(CB::ENGINE_OPTION_AUDIO_SAMPLE_RATE, static_cast<int>(gStandalone.engineOptions.audioSampleRate), nullptr);
  274. engine->setOption(CB::ENGINE_OPTION_AUDIO_TRIPLE_BUFFER, gStandalone.engineOptions.audioTripleBuffer ? 1 : 0, nullptr);
  275. if (gStandalone.engineOptions.audioDevice != nullptr)
  276. engine->setOption(CB::ENGINE_OPTION_AUDIO_DEVICE, 0, gStandalone.engineOptions.audioDevice);
  277. engine->setOption(CB::ENGINE_OPTION_OSC_ENABLED, gStandalone.engineOptions.oscEnabled, nullptr);
  278. engine->setOption(CB::ENGINE_OPTION_OSC_PORT_TCP, gStandalone.engineOptions.oscPortTCP, nullptr);
  279. engine->setOption(CB::ENGINE_OPTION_OSC_PORT_UDP, gStandalone.engineOptions.oscPortUDP, nullptr);
  280. if (gStandalone.engineOptions.pathLADSPA != nullptr)
  281. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_LADSPA, gStandalone.engineOptions.pathLADSPA);
  282. if (gStandalone.engineOptions.pathDSSI != nullptr)
  283. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_DSSI, gStandalone.engineOptions.pathDSSI);
  284. if (gStandalone.engineOptions.pathLV2 != nullptr)
  285. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_LV2, gStandalone.engineOptions.pathLV2);
  286. if (gStandalone.engineOptions.pathVST2 != nullptr)
  287. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_VST2, gStandalone.engineOptions.pathVST2);
  288. if (gStandalone.engineOptions.pathVST3 != nullptr)
  289. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_VST3, gStandalone.engineOptions.pathVST3);
  290. if (gStandalone.engineOptions.pathSF2 != nullptr)
  291. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_SF2, gStandalone.engineOptions.pathSF2);
  292. if (gStandalone.engineOptions.pathSFZ != nullptr)
  293. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_SFZ, gStandalone.engineOptions.pathSFZ);
  294. if (gStandalone.engineOptions.binaryDir != nullptr && gStandalone.engineOptions.binaryDir[0] != '\0')
  295. engine->setOption(CB::ENGINE_OPTION_PATH_BINARIES, 0, gStandalone.engineOptions.binaryDir);
  296. if (gStandalone.engineOptions.resourceDir != nullptr && gStandalone.engineOptions.resourceDir[0] != '\0')
  297. engine->setOption(CB::ENGINE_OPTION_PATH_RESOURCES, 0, gStandalone.engineOptions.resourceDir);
  298. engine->setOption(CB::ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR, gStandalone.engineOptions.preventBadBehaviour ? 1 : 0, nullptr);
  299. if (gStandalone.engineOptions.frontendWinId != 0)
  300. {
  301. char strBuf[STR_MAX+1];
  302. strBuf[STR_MAX] = '\0';
  303. std::snprintf(strBuf, STR_MAX, P_UINTPTR, gStandalone.engineOptions.frontendWinId);
  304. engine->setOption(CB::ENGINE_OPTION_FRONTEND_WIN_ID, 0, strBuf);
  305. }
  306. else
  307. {
  308. engine->setOption(CB::ENGINE_OPTION_FRONTEND_WIN_ID, 0, "0");
  309. }
  310. # ifndef CARLA_OS_WIN
  311. if (gStandalone.engineOptions.wine.executable != nullptr && gStandalone.engineOptions.wine.executable[0] != '\0')
  312. engine->setOption(CB::ENGINE_OPTION_WINE_EXECUTABLE, 0, gStandalone.engineOptions.wine.executable);
  313. engine->setOption(CB::ENGINE_OPTION_WINE_AUTO_PREFIX, gStandalone.engineOptions.wine.autoPrefix ? 1 : 0, nullptr);
  314. if (gStandalone.engineOptions.wine.fallbackPrefix != nullptr && gStandalone.engineOptions.wine.fallbackPrefix[0] != '\0')
  315. engine->setOption(CB::ENGINE_OPTION_WINE_FALLBACK_PREFIX, 0, gStandalone.engineOptions.wine.fallbackPrefix);
  316. engine->setOption(CB::ENGINE_OPTION_WINE_RT_PRIO_ENABLED, gStandalone.engineOptions.wine.rtPrio ? 1 : 0, nullptr);
  317. engine->setOption(CB::ENGINE_OPTION_WINE_BASE_RT_PRIO, gStandalone.engineOptions.wine.baseRtPrio, nullptr);
  318. engine->setOption(CB::ENGINE_OPTION_WINE_SERVER_RT_PRIO, gStandalone.engineOptions.wine.serverRtPrio, nullptr);
  319. # endif
  320. #endif
  321. }
  322. bool carla_engine_init(const char* driverName, const char* clientName)
  323. {
  324. CARLA_SAFE_ASSERT_RETURN(driverName != nullptr && driverName[0] != '\0', false);
  325. CARLA_SAFE_ASSERT_RETURN(clientName != nullptr && clientName[0] != '\0', false);
  326. carla_debug("carla_engine_init(\"%s\", \"%s\")", driverName, clientName);
  327. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(gStandalone.engine == nullptr, "Engine is already initialized", false);
  328. #ifdef CARLA_OS_WIN
  329. carla_setenv("WINEASIO_CLIENT_NAME", clientName);
  330. #endif
  331. #ifdef USING_JUCE
  332. juce::initialiseJuce_GUI();
  333. #endif
  334. CarlaEngine* const engine = CarlaEngine::newDriverByName(driverName);
  335. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(engine != nullptr, "The seleted audio driver is not available", false);
  336. gStandalone.engine = engine;
  337. #ifdef BUILD_BRIDGE
  338. engine->setOption(CB::ENGINE_OPTION_PROCESS_MODE, CB::ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS, nullptr);
  339. engine->setOption(CB::ENGINE_OPTION_TRANSPORT_MODE, CB::ENGINE_TRANSPORT_MODE_JACK, nullptr);
  340. engine->setOption(CB::ENGINE_OPTION_FORCE_STEREO, false, nullptr);
  341. engine->setOption(CB::ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, false, nullptr);
  342. engine->setOption(CB::ENGINE_OPTION_PREFER_UI_BRIDGES, false, nullptr);
  343. #else
  344. engine->setOption(CB::ENGINE_OPTION_PROCESS_MODE, static_cast<int>(gStandalone.engineOptions.processMode), nullptr);
  345. engine->setOption(CB::ENGINE_OPTION_TRANSPORT_MODE, static_cast<int>(gStandalone.engineOptions.transportMode), gStandalone.engineOptions.transportExtra);
  346. #endif
  347. carla_engine_init_common(engine);
  348. if (engine->init(clientName))
  349. {
  350. #ifndef BUILD_BRIDGE
  351. if (gStandalone.logThreadEnabled && std::getenv("CARLA_LOGS_DISABLED") == nullptr)
  352. gStandalone.logThread.init();
  353. #endif
  354. #ifdef CARLA_OS_UNIX
  355. sThreadSafeFFTW.init();
  356. #endif
  357. gStandalone.lastError = "No error";
  358. return true;
  359. }
  360. else
  361. {
  362. gStandalone.lastError = engine->getLastError();
  363. gStandalone.engine = nullptr;
  364. delete engine;
  365. #ifdef USING_JUCE
  366. juce::shutdownJuce_GUI();
  367. #endif
  368. return false;
  369. }
  370. }
  371. #ifdef BUILD_BRIDGE
  372. bool carla_engine_init_bridge(const char audioBaseName[6+1], const char rtClientBaseName[6+1], const char nonRtClientBaseName[6+1],
  373. const char nonRtServerBaseName[6+1], const char* clientName)
  374. {
  375. CARLA_SAFE_ASSERT_RETURN(audioBaseName != nullptr && audioBaseName[0] != '\0', false);
  376. CARLA_SAFE_ASSERT_RETURN(rtClientBaseName != nullptr && rtClientBaseName[0] != '\0', false);
  377. CARLA_SAFE_ASSERT_RETURN(nonRtClientBaseName != nullptr && nonRtClientBaseName[0] != '\0', false);
  378. CARLA_SAFE_ASSERT_RETURN(nonRtServerBaseName != nullptr && nonRtServerBaseName[0] != '\0', false);
  379. CARLA_SAFE_ASSERT_RETURN(clientName != nullptr && clientName[0] != '\0', false);
  380. carla_debug("carla_engine_init_bridge(\"%s\", \"%s\", \"%s\", \"%s\", \"%s\")", audioBaseName, rtClientBaseName, nonRtClientBaseName, nonRtServerBaseName, clientName);
  381. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(gStandalone.engine == nullptr, "Engine is already initialized", false);
  382. ScopedPointer<CarlaEngine> engine(CarlaEngine::newBridge(audioBaseName,
  383. rtClientBaseName,
  384. nonRtClientBaseName,
  385. nonRtServerBaseName));
  386. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(engine != nullptr, "The seleted audio driver is not available", false);
  387. engine->setOption(CB::ENGINE_OPTION_PROCESS_MODE, CB::ENGINE_PROCESS_MODE_BRIDGE, nullptr);
  388. engine->setOption(CB::ENGINE_OPTION_TRANSPORT_MODE, CB::ENGINE_TRANSPORT_MODE_BRIDGE, nullptr);
  389. carla_engine_init_common(engine);
  390. if (engine->init(clientName))
  391. {
  392. gStandalone.lastError = "No error";
  393. gStandalone.engine = engine.release();
  394. return true;
  395. }
  396. else
  397. {
  398. gStandalone.lastError = engine->getLastError();
  399. return false;
  400. }
  401. }
  402. #endif
  403. bool carla_engine_close()
  404. {
  405. carla_debug("carla_engine_close()");
  406. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(gStandalone.engine != nullptr, "Engine is not initialized", false);
  407. #ifdef CARLA_OS_UNIX
  408. const ThreadSafeFFTW::Deinitializer tsfftwde(sThreadSafeFFTW);
  409. #endif
  410. ScopedPointer<CarlaEngine> engine(gStandalone.engine);
  411. gStandalone.engine = nullptr;
  412. engine->setAboutToClose();
  413. engine->removeAllPlugins();
  414. const bool closed = engine->close();
  415. if (! closed)
  416. gStandalone.lastError = engine->getLastError();
  417. #ifndef BUILD_BRIDGE
  418. gStandalone.logThread.stop();
  419. # ifdef USING_JUCE
  420. juce::shutdownJuce_GUI();
  421. # endif
  422. #endif
  423. return closed;
  424. }
  425. void carla_engine_idle()
  426. {
  427. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  428. gStandalone.engine->idle();
  429. #if defined(USING_JUCE) && !(defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN))
  430. const juce::MessageManager* const msgMgr(juce::MessageManager::getInstanceWithoutCreating());
  431. CARLA_SAFE_ASSERT_RETURN(msgMgr != nullptr,);
  432. for (; msgMgr->dispatchNextMessageOnSystemQueue(true);) {}
  433. #endif
  434. }
  435. bool carla_is_engine_running()
  436. {
  437. return (gStandalone.engine != nullptr && gStandalone.engine->isRunning());
  438. }
  439. const CarlaRuntimeEngineInfo* carla_get_runtime_engine_info()
  440. {
  441. static CarlaRuntimeEngineInfo retInfo;
  442. // reset
  443. retInfo.load = 0.0f;
  444. retInfo.xruns = 0;
  445. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &retInfo);
  446. retInfo.load = gStandalone.engine->getDSPLoad();
  447. retInfo.xruns = gStandalone.engine->getTotalXruns();
  448. return &retInfo;
  449. }
  450. void carla_clear_engine_xruns()
  451. {
  452. if (gStandalone.engine != nullptr)
  453. gStandalone.engine->clearXruns();
  454. }
  455. void carla_cancel_engine_action()
  456. {
  457. if (gStandalone.engine != nullptr)
  458. gStandalone.engine->setActionCanceled(true);
  459. }
  460. bool carla_set_engine_about_to_close()
  461. {
  462. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, true);
  463. carla_debug("carla_set_engine_about_to_close()");
  464. return gStandalone.engine->setAboutToClose();
  465. }
  466. void carla_set_engine_callback(EngineCallbackFunc func, void* ptr)
  467. {
  468. carla_debug("carla_set_engine_callback(%p, %p)", func, ptr);
  469. gStandalone.engineCallback = func;
  470. gStandalone.engineCallbackPtr = ptr;
  471. #ifndef BUILD_BRIDGE
  472. gStandalone.logThread.setCallback(func, ptr);
  473. #endif
  474. if (gStandalone.engine != nullptr)
  475. gStandalone.engine->setCallback(func, ptr);
  476. }
  477. #ifndef BUILD_BRIDGE
  478. void carla_set_engine_option(EngineOption option, int value, const char* valueStr)
  479. {
  480. carla_debug("carla_set_engine_option(%i:%s, %i, \"%s\")", option, CB::EngineOption2Str(option), value, valueStr);
  481. switch (option)
  482. {
  483. case CB::ENGINE_OPTION_DEBUG:
  484. break;
  485. case CB::ENGINE_OPTION_PROCESS_MODE:
  486. CARLA_SAFE_ASSERT_RETURN(value >= CB::ENGINE_PROCESS_MODE_SINGLE_CLIENT && value < CB::ENGINE_PROCESS_MODE_BRIDGE,);
  487. gStandalone.engineOptions.processMode = static_cast<CB::EngineProcessMode>(value);
  488. break;
  489. case CB::ENGINE_OPTION_TRANSPORT_MODE:
  490. CARLA_SAFE_ASSERT_RETURN(value >= CB::ENGINE_TRANSPORT_MODE_DISABLED && value <= CB::ENGINE_TRANSPORT_MODE_BRIDGE,);
  491. if (value != CB::ENGINE_TRANSPORT_MODE_JACK)
  492. {
  493. // jack transport cannot be disabled in multi-client
  494. if (gStandalone.engineCallback != nullptr)
  495. gStandalone.engineCallback(gStandalone.engineCallbackPtr,
  496. CB::ENGINE_CALLBACK_TRANSPORT_MODE_CHANGED,
  497. 0,
  498. CB::ENGINE_TRANSPORT_MODE_JACK,
  499. 0, 0, 0.0f,
  500. gStandalone.engineOptions.transportExtra);
  501. CARLA_SAFE_ASSERT_RETURN(gStandalone.engineOptions.processMode != CB::ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS,);
  502. }
  503. gStandalone.engineOptions.transportMode = static_cast<CB::EngineTransportMode>(value);
  504. delete[] gStandalone.engineOptions.transportExtra;
  505. if (value != CB::ENGINE_TRANSPORT_MODE_DISABLED && valueStr != nullptr)
  506. gStandalone.engineOptions.transportExtra = carla_strdup_safe(valueStr);
  507. else
  508. gStandalone.engineOptions.transportExtra = nullptr;
  509. break;
  510. case CB::ENGINE_OPTION_FORCE_STEREO:
  511. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  512. gStandalone.engineOptions.forceStereo = (value != 0);
  513. break;
  514. case CB::ENGINE_OPTION_PREFER_PLUGIN_BRIDGES:
  515. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  516. gStandalone.engineOptions.preferPluginBridges = (value != 0);
  517. break;
  518. case CB::ENGINE_OPTION_PREFER_UI_BRIDGES:
  519. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  520. gStandalone.engineOptions.preferUiBridges = (value != 0);
  521. break;
  522. case CB::ENGINE_OPTION_UIS_ALWAYS_ON_TOP:
  523. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  524. gStandalone.engineOptions.uisAlwaysOnTop = (value != 0);
  525. break;
  526. case CB::ENGINE_OPTION_MAX_PARAMETERS:
  527. CARLA_SAFE_ASSERT_RETURN(value >= 0,);
  528. gStandalone.engineOptions.maxParameters = static_cast<uint>(value);
  529. break;
  530. case CB::ENGINE_OPTION_UI_BRIDGES_TIMEOUT:
  531. CARLA_SAFE_ASSERT_RETURN(value >= 0,);
  532. gStandalone.engineOptions.uiBridgesTimeout = static_cast<uint>(value);
  533. break;
  534. case CB::ENGINE_OPTION_AUDIO_BUFFER_SIZE:
  535. CARLA_SAFE_ASSERT_RETURN(value >= 8,);
  536. gStandalone.engineOptions.audioBufferSize = static_cast<uint>(value);
  537. break;
  538. case CB::ENGINE_OPTION_AUDIO_SAMPLE_RATE:
  539. CARLA_SAFE_ASSERT_RETURN(value >= 22050,);
  540. gStandalone.engineOptions.audioSampleRate = static_cast<uint>(value);
  541. break;
  542. case CB::ENGINE_OPTION_AUDIO_TRIPLE_BUFFER:
  543. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  544. gStandalone.engineOptions.audioTripleBuffer = (value != 0);
  545. break;
  546. case CB::ENGINE_OPTION_AUDIO_DEVICE:
  547. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr,);
  548. if (gStandalone.engineOptions.audioDevice != nullptr)
  549. delete[] gStandalone.engineOptions.audioDevice;
  550. gStandalone.engineOptions.audioDevice = carla_strdup_safe(valueStr);
  551. break;
  552. case CB::ENGINE_OPTION_OSC_ENABLED:
  553. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  554. gStandalone.engineOptions.oscEnabled = (value != 0);
  555. break;
  556. case CB::ENGINE_OPTION_OSC_PORT_TCP:
  557. CARLA_SAFE_ASSERT_RETURN(value <= 0 || value >= 1024,);
  558. gStandalone.engineOptions.oscPortTCP = value;
  559. break;
  560. case CB::ENGINE_OPTION_OSC_PORT_UDP:
  561. CARLA_SAFE_ASSERT_RETURN(value <= 0 || value >= 1024,);
  562. gStandalone.engineOptions.oscPortUDP = value;
  563. break;
  564. case CB::ENGINE_OPTION_PLUGIN_PATH:
  565. CARLA_SAFE_ASSERT_RETURN(value > CB::PLUGIN_NONE,);
  566. CARLA_SAFE_ASSERT_RETURN(value <= CB::PLUGIN_SFZ,);
  567. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr,);
  568. switch (value)
  569. {
  570. case CB::PLUGIN_LADSPA:
  571. if (gStandalone.engineOptions.pathLADSPA != nullptr)
  572. delete[] gStandalone.engineOptions.pathLADSPA;
  573. gStandalone.engineOptions.pathLADSPA = carla_strdup_safe(valueStr);
  574. break;
  575. case CB::PLUGIN_DSSI:
  576. if (gStandalone.engineOptions.pathDSSI != nullptr)
  577. delete[] gStandalone.engineOptions.pathDSSI;
  578. gStandalone.engineOptions.pathDSSI = carla_strdup_safe(valueStr);
  579. break;
  580. case CB::PLUGIN_LV2:
  581. if (gStandalone.engineOptions.pathLV2 != nullptr)
  582. delete[] gStandalone.engineOptions.pathLV2;
  583. gStandalone.engineOptions.pathLV2 = carla_strdup_safe(valueStr);
  584. break;
  585. case CB::PLUGIN_VST2:
  586. if (gStandalone.engineOptions.pathVST2 != nullptr)
  587. delete[] gStandalone.engineOptions.pathVST2;
  588. gStandalone.engineOptions.pathVST2 = carla_strdup_safe(valueStr);
  589. break;
  590. case CB::PLUGIN_VST3:
  591. if (gStandalone.engineOptions.pathVST3 != nullptr)
  592. delete[] gStandalone.engineOptions.pathVST3;
  593. gStandalone.engineOptions.pathVST3 = carla_strdup_safe(valueStr);
  594. break;
  595. case CB::PLUGIN_SF2:
  596. if (gStandalone.engineOptions.pathSF2 != nullptr)
  597. delete[] gStandalone.engineOptions.pathSF2;
  598. gStandalone.engineOptions.pathSF2 = carla_strdup_safe(valueStr);
  599. break;
  600. case CB::PLUGIN_SFZ:
  601. if (gStandalone.engineOptions.pathSFZ != nullptr)
  602. delete[] gStandalone.engineOptions.pathSFZ;
  603. gStandalone.engineOptions.pathSFZ = carla_strdup_safe(valueStr);
  604. break;
  605. }
  606. break;
  607. case CB::ENGINE_OPTION_PATH_BINARIES:
  608. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  609. if (gStandalone.engineOptions.binaryDir != nullptr)
  610. delete[] gStandalone.engineOptions.binaryDir;
  611. gStandalone.engineOptions.binaryDir = carla_strdup_safe(valueStr);
  612. break;
  613. case CB::ENGINE_OPTION_PATH_RESOURCES:
  614. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  615. if (gStandalone.engineOptions.resourceDir != nullptr)
  616. delete[] gStandalone.engineOptions.resourceDir;
  617. gStandalone.engineOptions.resourceDir = carla_strdup_safe(valueStr);
  618. break;
  619. case CB::ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR:
  620. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  621. gStandalone.engineOptions.preventBadBehaviour = (value != 0);
  622. break;
  623. case CB::ENGINE_OPTION_FRONTEND_WIN_ID: {
  624. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  625. const long long winId(std::strtoll(valueStr, nullptr, 16));
  626. CARLA_SAFE_ASSERT_RETURN(winId >= 0,);
  627. gStandalone.engineOptions.frontendWinId = static_cast<uintptr_t>(winId);
  628. } break;
  629. #ifndef CARLA_OS_WIN
  630. case CB::ENGINE_OPTION_WINE_EXECUTABLE:
  631. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  632. if (gStandalone.engineOptions.wine.executable != nullptr)
  633. delete[] gStandalone.engineOptions.wine.executable;
  634. gStandalone.engineOptions.wine.executable = carla_strdup_safe(valueStr);
  635. break;
  636. case CB::ENGINE_OPTION_WINE_AUTO_PREFIX:
  637. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  638. gStandalone.engineOptions.wine.autoPrefix = (value != 0);
  639. break;
  640. case CB::ENGINE_OPTION_WINE_FALLBACK_PREFIX:
  641. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  642. if (gStandalone.engineOptions.wine.fallbackPrefix != nullptr)
  643. delete[] gStandalone.engineOptions.wine.fallbackPrefix;
  644. gStandalone.engineOptions.wine.fallbackPrefix = carla_strdup_safe(valueStr);
  645. break;
  646. case CB::ENGINE_OPTION_WINE_RT_PRIO_ENABLED:
  647. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  648. gStandalone.engineOptions.wine.rtPrio = (value != 0);
  649. break;
  650. case CB::ENGINE_OPTION_WINE_BASE_RT_PRIO:
  651. CARLA_SAFE_ASSERT_RETURN(value >= 1 && value <= 89,);
  652. gStandalone.engineOptions.wine.baseRtPrio = value;
  653. break;
  654. case CB::ENGINE_OPTION_WINE_SERVER_RT_PRIO:
  655. CARLA_SAFE_ASSERT_RETURN(value >= 1 && value <= 99,);
  656. gStandalone.engineOptions.wine.serverRtPrio = value;
  657. break;
  658. #endif
  659. case CB::ENGINE_OPTION_DEBUG_CONSOLE_OUTPUT:
  660. gStandalone.logThreadEnabled = (value != 0);
  661. break;
  662. }
  663. if (gStandalone.engine != nullptr)
  664. gStandalone.engine->setOption(option, value, valueStr);
  665. }
  666. #endif
  667. void carla_set_file_callback(FileCallbackFunc func, void* ptr)
  668. {
  669. carla_debug("carla_set_file_callback(%p, %p)", func, ptr);
  670. gStandalone.fileCallback = func;
  671. gStandalone.fileCallbackPtr = ptr;
  672. if (gStandalone.engine != nullptr)
  673. gStandalone.engine->setFileCallback(func, ptr);
  674. }
  675. // --------------------------------------------------------------------------------------------------------------------
  676. bool carla_load_file(const char* filename)
  677. {
  678. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  679. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(gStandalone.engine != nullptr, "Engine is not initialized", false);
  680. carla_debug("carla_load_file(\"%s\")", filename);
  681. return gStandalone.engine->loadFile(filename);
  682. }
  683. bool carla_load_project(const char* filename)
  684. {
  685. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  686. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(gStandalone.engine != nullptr, "Engine is not initialized", false);
  687. carla_debug("carla_load_project(\"%s\")", filename);
  688. return gStandalone.engine->loadProject(filename, true);
  689. }
  690. bool carla_save_project(const char* filename)
  691. {
  692. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  693. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(gStandalone.engine != nullptr, "Engine is not initialized", false);
  694. carla_debug("carla_save_project(\"%s\")", filename);
  695. return gStandalone.engine->saveProject(filename, true);
  696. }
  697. #ifndef BUILD_BRIDGE
  698. void carla_clear_project_filename()
  699. {
  700. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  701. carla_debug("carla_clear_project_filename()");
  702. gStandalone.engine->clearCurrentProjectFilename();
  703. }
  704. // --------------------------------------------------------------------------------------------------------------------
  705. bool carla_patchbay_connect(bool external, uint groupIdA, uint portIdA, uint groupIdB, uint portIdB)
  706. {
  707. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(gStandalone.engine != nullptr, "Engine is not initialized", false);
  708. carla_debug("carla_patchbay_connect(%s, %u, %u, %u, %u)",
  709. bool2str(external), groupIdA, portIdA, groupIdB, portIdB);
  710. return gStandalone.engine->patchbayConnect(external, groupIdA, portIdA, groupIdB, portIdB);
  711. }
  712. bool carla_patchbay_disconnect(bool external, uint connectionId)
  713. {
  714. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(gStandalone.engine != nullptr, "Engine is not initialized", false);
  715. carla_debug("carla_patchbay_disconnect(%s, %i)", bool2str(external), connectionId);
  716. return gStandalone.engine->patchbayDisconnect(external, connectionId);
  717. }
  718. bool carla_patchbay_refresh(bool external)
  719. {
  720. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(gStandalone.engine != nullptr, "Engine is not initialized", false);
  721. carla_debug("carla_patchbay_refresh(%s)", bool2str(external));
  722. return gStandalone.engine->patchbayRefresh(true, false, external);
  723. }
  724. // --------------------------------------------------------------------------------------------------------------------
  725. void carla_transport_play()
  726. {
  727. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr && gStandalone.engine->isRunning(),);
  728. carla_debug("carla_transport_play()");
  729. gStandalone.engine->transportPlay();
  730. }
  731. void carla_transport_pause()
  732. {
  733. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr && gStandalone.engine->isRunning(),);
  734. carla_debug("carla_transport_pause()");
  735. gStandalone.engine->transportPause();
  736. }
  737. void carla_transport_bpm(double bpm)
  738. {
  739. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr && gStandalone.engine->isRunning(),);
  740. carla_debug("carla_transport_bpm(%f)", bpm);
  741. gStandalone.engine->transportBPM(bpm);
  742. }
  743. void carla_transport_relocate(uint64_t frame)
  744. {
  745. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr && gStandalone.engine->isRunning(),);
  746. carla_debug("carla_transport_relocate(%i)", frame);
  747. gStandalone.engine->transportRelocate(frame);
  748. }
  749. uint64_t carla_get_current_transport_frame()
  750. {
  751. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr && gStandalone.engine->isRunning(), 0);
  752. return gStandalone.engine->getTimeInfo().frame;
  753. }
  754. const CarlaTransportInfo* carla_get_transport_info()
  755. {
  756. static CarlaTransportInfo retTransInfo;
  757. retTransInfo.clear();
  758. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr && gStandalone.engine->isRunning(), &retTransInfo);
  759. const CB::EngineTimeInfo& timeInfo(gStandalone.engine->getTimeInfo());
  760. retTransInfo.playing = timeInfo.playing;
  761. retTransInfo.frame = timeInfo.frame;
  762. if (timeInfo.bbt.valid)
  763. {
  764. retTransInfo.bar = timeInfo.bbt.bar;
  765. retTransInfo.beat = timeInfo.bbt.beat;
  766. retTransInfo.tick = static_cast<int32_t>(timeInfo.bbt.tick + 0.5);
  767. retTransInfo.bpm = timeInfo.bbt.beatsPerMinute;
  768. }
  769. return &retTransInfo;
  770. }
  771. #endif
  772. // --------------------------------------------------------------------------------------------------------------------
  773. uint32_t carla_get_current_plugin_count()
  774. {
  775. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0);
  776. carla_debug("carla_get_current_plugin_count()");
  777. return gStandalone.engine->getCurrentPluginCount();
  778. }
  779. uint32_t carla_get_max_plugin_number()
  780. {
  781. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0);
  782. carla_debug("carla_get_max_plugin_number()");
  783. return gStandalone.engine->getMaxPluginNumber();
  784. }
  785. // --------------------------------------------------------------------------------------------------------------------
  786. bool carla_add_plugin(BinaryType btype, PluginType ptype,
  787. const char* filename, const char* name, const char* label, int64_t uniqueId,
  788. const void* extraPtr, uint options)
  789. {
  790. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(gStandalone.engine != nullptr, "Engine is not initialized", false);
  791. carla_debug("carla_add_plugin(%i:%s, %i:%s, \"%s\", \"%s\", \"%s\", " P_INT64 ", %p, %u)",
  792. btype, CB::BinaryType2Str(btype),
  793. ptype, CB::PluginType2Str(ptype),
  794. filename, name, label, uniqueId, extraPtr, options);
  795. return gStandalone.engine->addPlugin(btype, ptype, filename, name, label, uniqueId, extraPtr, options);
  796. }
  797. bool carla_remove_plugin(uint pluginId)
  798. {
  799. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(gStandalone.engine != nullptr, "Engine is not initialized", false);
  800. carla_debug("carla_remove_plugin(%i)", pluginId);
  801. return gStandalone.engine->removePlugin(pluginId);
  802. }
  803. bool carla_remove_all_plugins()
  804. {
  805. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(gStandalone.engine != nullptr, "Engine is not initialized", false);
  806. carla_debug("carla_remove_all_plugins()");
  807. return gStandalone.engine->removeAllPlugins();
  808. }
  809. #ifndef BUILD_BRIDGE
  810. const char* carla_rename_plugin(uint pluginId, const char* newName)
  811. {
  812. CARLA_SAFE_ASSERT_RETURN(newName != nullptr && newName[0] != '\0', nullptr);
  813. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(gStandalone.engine != nullptr, "Engine is not initialized", nullptr);
  814. carla_debug("carla_rename_plugin(%i, \"%s\")", pluginId, newName);
  815. return gStandalone.engine->renamePlugin(pluginId, newName);
  816. }
  817. bool carla_clone_plugin(uint pluginId)
  818. {
  819. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(gStandalone.engine != nullptr, "Engine is not initialized", false);
  820. carla_debug("carla_clone_plugin(%i)", pluginId);
  821. return gStandalone.engine->clonePlugin(pluginId);
  822. }
  823. bool carla_replace_plugin(uint pluginId)
  824. {
  825. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(gStandalone.engine != nullptr, "Engine is not initialized", false);
  826. carla_debug("carla_replace_plugin(%i)", pluginId);
  827. return gStandalone.engine->replacePlugin(pluginId);
  828. }
  829. bool carla_switch_plugins(uint pluginIdA, uint pluginIdB)
  830. {
  831. CARLA_SAFE_ASSERT_RETURN(pluginIdA != pluginIdB, false);
  832. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(gStandalone.engine != nullptr, "Engine is not initialized", false);
  833. carla_debug("carla_switch_plugins(%i, %i)", pluginIdA, pluginIdB);
  834. return gStandalone.engine->switchPlugins(pluginIdA, pluginIdB);
  835. }
  836. #endif
  837. // --------------------------------------------------------------------------------------------------------------------
  838. bool carla_load_plugin_state(uint pluginId, const char* filename)
  839. {
  840. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  841. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(gStandalone.engine != nullptr
  842. && gStandalone.engine->isRunning(), "Engine is not running", false);
  843. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  844. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(plugin != nullptr, "could not find requested plugin", false);
  845. carla_debug("carla_load_plugin_state(%i, \"%s\")", pluginId, filename);
  846. return plugin->loadStateFromFile(filename);
  847. }
  848. bool carla_save_plugin_state(uint pluginId, const char* filename)
  849. {
  850. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  851. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(gStandalone.engine != nullptr, "Engine is not initialized", false);
  852. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  853. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(plugin != nullptr, "could not find requested plugin", false);
  854. carla_debug("carla_save_plugin_state(%i, \"%s\")", pluginId, filename);
  855. return plugin->saveStateToFile(filename);
  856. }
  857. bool carla_export_plugin_lv2(uint pluginId, const char* lv2path)
  858. {
  859. CARLA_SAFE_ASSERT_RETURN(lv2path != nullptr && lv2path[0] != '\0', false);
  860. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(gStandalone.engine != nullptr, "Engine is not initialized", false);
  861. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  862. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(plugin != nullptr, "could not find requested plugin", false);
  863. carla_debug("carla_export_plugin_lv2(%i, \"%s\")", pluginId, lv2path);
  864. return plugin->exportAsLV2(lv2path);
  865. }
  866. // --------------------------------------------------------------------------------------------------------------------
  867. const CarlaPluginInfo* carla_get_plugin_info(uint pluginId)
  868. {
  869. static CarlaPluginInfo retInfo;
  870. // reset
  871. retInfo.type = CB::PLUGIN_NONE;
  872. retInfo.category = CB::PLUGIN_CATEGORY_NONE;
  873. retInfo.hints = 0x0;
  874. retInfo.optionsAvailable = 0x0;
  875. retInfo.optionsEnabled = 0x0;
  876. retInfo.filename = gNullCharPtr;
  877. retInfo.name = gNullCharPtr;
  878. retInfo.iconName = gNullCharPtr;
  879. retInfo.uniqueId = 0;
  880. // cleanup
  881. if (retInfo.label != gNullCharPtr)
  882. {
  883. delete[] retInfo.label;
  884. retInfo.label = gNullCharPtr;
  885. }
  886. if (retInfo.maker != gNullCharPtr)
  887. {
  888. delete[] retInfo.maker;
  889. retInfo.maker = gNullCharPtr;
  890. }
  891. if (retInfo.copyright != gNullCharPtr)
  892. {
  893. delete[] retInfo.copyright;
  894. retInfo.copyright = gNullCharPtr;
  895. }
  896. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &retInfo);
  897. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  898. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr, &retInfo);
  899. carla_debug("carla_get_plugin_info(%i)", pluginId);
  900. char strBuf[STR_MAX+1];
  901. retInfo.type = plugin->getType();
  902. retInfo.category = plugin->getCategory();
  903. retInfo.hints = plugin->getHints();
  904. retInfo.filename = plugin->getFilename();
  905. retInfo.name = plugin->getName();
  906. retInfo.iconName = plugin->getIconName();
  907. retInfo.uniqueId = plugin->getUniqueId();
  908. retInfo.optionsAvailable = plugin->getOptionsAvailable();
  909. retInfo.optionsEnabled = plugin->getOptionsEnabled();
  910. carla_zeroChars(strBuf, STR_MAX+1);
  911. plugin->getLabel(strBuf);
  912. retInfo.label = carla_strdup_safe(strBuf);
  913. carla_zeroChars(strBuf, STR_MAX+1);
  914. plugin->getMaker(strBuf);
  915. retInfo.maker = carla_strdup_safe(strBuf);
  916. carla_zeroChars(strBuf, STR_MAX+1);
  917. plugin->getCopyright(strBuf);
  918. retInfo.copyright = carla_strdup_safe(strBuf);
  919. checkStringPtr(retInfo.filename);
  920. checkStringPtr(retInfo.name);
  921. checkStringPtr(retInfo.iconName);
  922. checkStringPtr(retInfo.label);
  923. checkStringPtr(retInfo.maker);
  924. checkStringPtr(retInfo.copyright);
  925. return &retInfo;
  926. }
  927. const CarlaPortCountInfo* carla_get_audio_port_count_info(uint pluginId)
  928. {
  929. static CarlaPortCountInfo retInfo;
  930. carla_zeroStruct(retInfo);
  931. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &retInfo);
  932. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  933. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr, &retInfo);
  934. carla_debug("carla_get_audio_port_count_info(%i)", pluginId);
  935. retInfo.ins = plugin->getAudioInCount();
  936. retInfo.outs = plugin->getAudioOutCount();
  937. return &retInfo;
  938. }
  939. const CarlaPortCountInfo* carla_get_midi_port_count_info(uint pluginId)
  940. {
  941. static CarlaPortCountInfo retInfo;
  942. carla_zeroStruct(retInfo);
  943. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &retInfo);
  944. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  945. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr, &retInfo);
  946. carla_debug("carla_get_midi_port_count_info(%i)", pluginId);
  947. retInfo.ins = plugin->getMidiInCount();
  948. retInfo.outs = plugin->getMidiOutCount();
  949. return &retInfo;
  950. }
  951. const CarlaPortCountInfo* carla_get_parameter_count_info(uint pluginId)
  952. {
  953. static CarlaPortCountInfo retInfo;
  954. carla_zeroStruct(retInfo);
  955. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &retInfo);
  956. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  957. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr, &retInfo);
  958. carla_debug("carla_get_parameter_count_info(%i)", pluginId);
  959. plugin->getParameterCountInfo(retInfo.ins, retInfo.outs);
  960. return &retInfo;
  961. }
  962. const CarlaParameterInfo* carla_get_parameter_info(uint pluginId, uint32_t parameterId)
  963. {
  964. static CarlaParameterInfo retInfo;
  965. // reset
  966. retInfo.scalePointCount = 0;
  967. // cleanup
  968. if (retInfo.name != gNullCharPtr)
  969. {
  970. delete[] retInfo.name;
  971. retInfo.name = gNullCharPtr;
  972. }
  973. if (retInfo.symbol != gNullCharPtr)
  974. {
  975. delete[] retInfo.symbol;
  976. retInfo.symbol = gNullCharPtr;
  977. }
  978. if (retInfo.unit != gNullCharPtr)
  979. {
  980. delete[] retInfo.unit;
  981. retInfo.unit = gNullCharPtr;
  982. }
  983. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &retInfo);
  984. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  985. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr, &retInfo);
  986. carla_debug("carla_get_parameter_info(%i, %i)", pluginId, parameterId);
  987. char strBuf[STR_MAX+1];
  988. retInfo.scalePointCount = plugin->getParameterScalePointCount(parameterId);
  989. carla_zeroChars(strBuf, STR_MAX+1);
  990. plugin->getParameterName(parameterId, strBuf);
  991. retInfo.name = carla_strdup_safe(strBuf);
  992. carla_zeroChars(strBuf, STR_MAX+1);
  993. plugin->getParameterSymbol(parameterId, strBuf);
  994. retInfo.symbol = carla_strdup_safe(strBuf);
  995. carla_zeroChars(strBuf, STR_MAX+1);
  996. plugin->getParameterUnit(parameterId, strBuf);
  997. retInfo.unit = carla_strdup_safe(strBuf);
  998. checkStringPtr(retInfo.name);
  999. checkStringPtr(retInfo.symbol);
  1000. checkStringPtr(retInfo.unit);
  1001. return &retInfo;
  1002. }
  1003. const CarlaScalePointInfo* carla_get_parameter_scalepoint_info(uint pluginId, uint32_t parameterId, uint32_t scalePointId)
  1004. {
  1005. CARLA_ASSERT(gStandalone.engine != nullptr);
  1006. static CarlaScalePointInfo retInfo;
  1007. // reset
  1008. retInfo.value = 0.0f;
  1009. // cleanup
  1010. if (retInfo.label != gNullCharPtr)
  1011. {
  1012. delete[] retInfo.label;
  1013. retInfo.label = gNullCharPtr;
  1014. }
  1015. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &retInfo);
  1016. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1017. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr, &retInfo);
  1018. carla_debug("carla_get_parameter_scalepoint_info(%i, %i, %i)", pluginId, parameterId, scalePointId);
  1019. char strBuf[STR_MAX+1];
  1020. retInfo.value = plugin->getParameterScalePointValue(parameterId, scalePointId);
  1021. carla_zeroChars(strBuf, STR_MAX+1);
  1022. plugin->getParameterScalePointLabel(parameterId, scalePointId, strBuf);
  1023. retInfo.label = carla_strdup_safe(strBuf);
  1024. checkStringPtr(retInfo.label);
  1025. return &retInfo;
  1026. }
  1027. // --------------------------------------------------------------------------------------------------------------------
  1028. const ParameterData* carla_get_parameter_data(uint pluginId, uint32_t parameterId)
  1029. {
  1030. static ParameterData retParamData;
  1031. // reset
  1032. retParamData.type = CB::PARAMETER_UNKNOWN;
  1033. retParamData.hints = 0x0;
  1034. retParamData.index = CB::PARAMETER_NULL;
  1035. retParamData.rindex = -1;
  1036. retParamData.midiCC = -1;
  1037. retParamData.midiChannel = 0;
  1038. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &retParamData);
  1039. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1040. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr, &retParamData);
  1041. carla_debug("carla_get_parameter_data(%i, %i)", pluginId, parameterId);
  1042. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), &retParamData);
  1043. const ParameterData& pluginParamData(plugin->getParameterData(parameterId));
  1044. retParamData.type = pluginParamData.type;
  1045. retParamData.hints = pluginParamData.hints;
  1046. retParamData.index = pluginParamData.index;
  1047. retParamData.rindex = pluginParamData.rindex;
  1048. retParamData.midiCC = pluginParamData.midiCC;
  1049. retParamData.midiChannel = pluginParamData.midiChannel;
  1050. return &plugin->getParameterData(parameterId);
  1051. }
  1052. const ParameterRanges* carla_get_parameter_ranges(uint pluginId, uint32_t parameterId)
  1053. {
  1054. static ParameterRanges retParamRanges;
  1055. // reset
  1056. retParamRanges.def = 0.0f;
  1057. retParamRanges.min = 0.0f;
  1058. retParamRanges.max = 1.0f;
  1059. retParamRanges.step = 0.01f;
  1060. retParamRanges.stepSmall = 0.0001f;
  1061. retParamRanges.stepLarge = 0.1f;
  1062. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &retParamRanges);
  1063. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1064. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr, &retParamRanges);
  1065. carla_debug("carla_get_parameter_ranges(%i, %i)", pluginId, parameterId);
  1066. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), &retParamRanges);
  1067. const ParameterRanges& pluginParamRanges(plugin->getParameterRanges(parameterId));
  1068. retParamRanges.def = pluginParamRanges.def;
  1069. retParamRanges.min = pluginParamRanges.min;
  1070. retParamRanges.max = pluginParamRanges.max;
  1071. retParamRanges.step = pluginParamRanges.step;
  1072. retParamRanges.stepSmall = pluginParamRanges.stepSmall;
  1073. retParamRanges.stepLarge = pluginParamRanges.stepLarge;
  1074. return &pluginParamRanges;
  1075. }
  1076. const MidiProgramData* carla_get_midi_program_data(uint pluginId, uint32_t midiProgramId)
  1077. {
  1078. static MidiProgramData retMidiProgData = { 0, 0, gNullCharPtr };
  1079. // reset
  1080. retMidiProgData.bank = 0;
  1081. retMidiProgData.program = 0;
  1082. if (retMidiProgData.name != gNullCharPtr)
  1083. {
  1084. delete[] retMidiProgData.name;
  1085. retMidiProgData.name = gNullCharPtr;
  1086. }
  1087. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &retMidiProgData);
  1088. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1089. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr, &retMidiProgData);
  1090. carla_debug("carla_get_midi_program_data(%i, %i)", pluginId, midiProgramId);
  1091. CARLA_SAFE_ASSERT_RETURN(midiProgramId < plugin->getMidiProgramCount(), &retMidiProgData);
  1092. const MidiProgramData& pluginMidiProgData(plugin->getMidiProgramData(midiProgramId));
  1093. retMidiProgData.bank = pluginMidiProgData.bank;
  1094. retMidiProgData.program = pluginMidiProgData.program;
  1095. if (pluginMidiProgData.name != nullptr)
  1096. {
  1097. retMidiProgData.name = carla_strdup_safe(pluginMidiProgData.name);
  1098. checkStringPtr(retMidiProgData.name);
  1099. }
  1100. else
  1101. {
  1102. retMidiProgData.name = gNullCharPtr;
  1103. }
  1104. return &retMidiProgData;
  1105. }
  1106. const CustomData* carla_get_custom_data(uint pluginId, uint32_t customDataId)
  1107. {
  1108. static CustomData retCustomData = { gNullCharPtr, gNullCharPtr, gNullCharPtr };
  1109. // reset
  1110. if (retCustomData.type != gNullCharPtr)
  1111. {
  1112. delete[] retCustomData.type;
  1113. retCustomData.type = gNullCharPtr;
  1114. }
  1115. if (retCustomData.key != gNullCharPtr)
  1116. {
  1117. delete[] retCustomData.key;
  1118. retCustomData.key = gNullCharPtr;
  1119. }
  1120. if (retCustomData.value != gNullCharPtr)
  1121. {
  1122. delete[] retCustomData.value;
  1123. retCustomData.value = gNullCharPtr;
  1124. }
  1125. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &retCustomData);
  1126. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1127. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr, &retCustomData);
  1128. carla_debug("carla_get_custom_data(%i, %i)", pluginId, customDataId);
  1129. CARLA_SAFE_ASSERT_RETURN(customDataId < plugin->getCustomDataCount(), &retCustomData)
  1130. const CustomData& pluginCustomData(plugin->getCustomData(customDataId));
  1131. retCustomData.type = carla_strdup_safe(pluginCustomData.type);
  1132. retCustomData.key = carla_strdup_safe(pluginCustomData.key);
  1133. retCustomData.value = carla_strdup_safe(pluginCustomData.value);
  1134. checkStringPtr(retCustomData.type);
  1135. checkStringPtr(retCustomData.key);
  1136. checkStringPtr(retCustomData.value);
  1137. return &retCustomData;
  1138. }
  1139. const char* carla_get_custom_data_value(uint pluginId, const char* type, const char* key)
  1140. {
  1141. CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0', gNullCharPtr);
  1142. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0', gNullCharPtr);
  1143. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, gNullCharPtr);
  1144. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1145. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr, gNullCharPtr);
  1146. carla_debug("carla_get_custom_data_value(%i, %s, %s)", pluginId, type, key);
  1147. const uint32_t count = plugin->getCustomDataCount();
  1148. if (count == 0)
  1149. return gNullCharPtr;
  1150. static CarlaString customDataValue;
  1151. for (uint32_t i=0; i<count; ++i)
  1152. {
  1153. const CustomData& pluginCustomData(plugin->getCustomData(i));
  1154. if (std::strcmp(pluginCustomData.type, type) != 0)
  1155. continue;
  1156. if (std::strcmp(pluginCustomData.key, key) != 0)
  1157. continue;
  1158. customDataValue = pluginCustomData.value;
  1159. return customDataValue.buffer();
  1160. }
  1161. return gNullCharPtr;
  1162. }
  1163. const char* carla_get_chunk_data(uint pluginId)
  1164. {
  1165. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, gNullCharPtr);
  1166. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1167. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr, gNullCharPtr);
  1168. carla_debug("carla_get_chunk_data(%i)", pluginId);
  1169. CARLA_SAFE_ASSERT_RETURN(plugin->getOptionsEnabled() & CB::PLUGIN_OPTION_USE_CHUNKS, gNullCharPtr);
  1170. void* data = nullptr;
  1171. const std::size_t dataSize(plugin->getChunkData(&data));
  1172. CARLA_SAFE_ASSERT_RETURN(data != nullptr && dataSize > 0, gNullCharPtr);
  1173. static CarlaString chunkData;
  1174. chunkData = CarlaString::asBase64(data, static_cast<std::size_t>(dataSize));
  1175. return chunkData.buffer();
  1176. }
  1177. // --------------------------------------------------------------------------------------------------------------------
  1178. uint32_t carla_get_parameter_count(uint pluginId)
  1179. {
  1180. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0);
  1181. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1182. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr, 0);
  1183. carla_debug("carla_get_parameter_count(%i)", pluginId);
  1184. return plugin->getParameterCount();
  1185. }
  1186. uint32_t carla_get_program_count(uint pluginId)
  1187. {
  1188. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0);
  1189. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1190. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr, 0);
  1191. carla_debug("carla_get_program_count(%i)", pluginId);
  1192. return plugin->getProgramCount();
  1193. }
  1194. uint32_t carla_get_midi_program_count(uint pluginId)
  1195. {
  1196. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0);
  1197. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1198. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr, 0);
  1199. carla_debug("carla_get_midi_program_count(%i)", pluginId);
  1200. return plugin->getMidiProgramCount();
  1201. }
  1202. uint32_t carla_get_custom_data_count(uint pluginId)
  1203. {
  1204. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0);
  1205. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1206. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr, 0);
  1207. carla_debug("carla_get_custom_data_count(%i)", pluginId);
  1208. return plugin->getCustomDataCount();
  1209. }
  1210. // --------------------------------------------------------------------------------------------------------------------
  1211. const char* carla_get_parameter_text(uint pluginId, uint32_t parameterId)
  1212. {
  1213. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, gNullCharPtr);
  1214. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1215. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr, gNullCharPtr);
  1216. carla_debug("carla_get_parameter_text(%i, %i)", pluginId, parameterId);
  1217. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), gNullCharPtr);
  1218. static char textBuf[STR_MAX+1];
  1219. carla_zeroChars(textBuf, STR_MAX+1);
  1220. plugin->getParameterText(parameterId, textBuf);
  1221. return textBuf;
  1222. }
  1223. const char* carla_get_program_name(uint pluginId, uint32_t programId)
  1224. {
  1225. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, nullptr);
  1226. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1227. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr, gNullCharPtr);
  1228. carla_debug("carla_get_program_name(%i, %i)", pluginId, programId);
  1229. CARLA_SAFE_ASSERT_RETURN(programId < plugin->getProgramCount(), gNullCharPtr);
  1230. static char programName[STR_MAX+1];
  1231. carla_zeroChars(programName, STR_MAX+1);
  1232. plugin->getProgramName(programId, programName);
  1233. return programName;
  1234. }
  1235. const char* carla_get_midi_program_name(uint pluginId, uint32_t midiProgramId)
  1236. {
  1237. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, gNullCharPtr);
  1238. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1239. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr, gNullCharPtr);
  1240. carla_debug("carla_get_midi_program_name(%i, %i)", pluginId, midiProgramId);
  1241. CARLA_SAFE_ASSERT_RETURN(midiProgramId < plugin->getMidiProgramCount(), gNullCharPtr);
  1242. static char midiProgramName[STR_MAX+1];
  1243. carla_zeroChars(midiProgramName, STR_MAX+1);
  1244. plugin->getMidiProgramName(midiProgramId, midiProgramName);
  1245. return midiProgramName;
  1246. }
  1247. const char* carla_get_real_plugin_name(uint pluginId)
  1248. {
  1249. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, gNullCharPtr);
  1250. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1251. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr, gNullCharPtr);
  1252. carla_debug("carla_get_real_plugin_name(%i)", pluginId);
  1253. static char realPluginName[STR_MAX+1];
  1254. carla_zeroChars(realPluginName, STR_MAX+1);
  1255. plugin->getRealName(realPluginName);
  1256. return realPluginName;
  1257. }
  1258. // --------------------------------------------------------------------------------------------------------------------
  1259. int32_t carla_get_current_program_index(uint pluginId)
  1260. {
  1261. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, -1);
  1262. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1263. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr, -1);
  1264. carla_debug("carla_get_current_program_index(%i)", pluginId);
  1265. return plugin->getCurrentProgram();
  1266. }
  1267. int32_t carla_get_current_midi_program_index(uint pluginId)
  1268. {
  1269. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, -1);
  1270. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1271. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr, -1);
  1272. carla_debug("carla_get_current_midi_program_index(%i)", pluginId);
  1273. return plugin->getCurrentMidiProgram();
  1274. }
  1275. // --------------------------------------------------------------------------------------------------------------------
  1276. float carla_get_default_parameter_value(uint pluginId, uint32_t parameterId)
  1277. {
  1278. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0.0f);
  1279. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1280. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr, 0.0f);
  1281. carla_debug("carla_get_default_parameter_value(%i, %i)", pluginId, parameterId);
  1282. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), 0.0f);
  1283. return plugin->getParameterRanges(parameterId).def;
  1284. }
  1285. float carla_get_current_parameter_value(uint pluginId, uint32_t parameterId)
  1286. {
  1287. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0.0f);
  1288. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1289. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr, 0.0f);
  1290. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), 0.0f);
  1291. return plugin->getParameterValue(parameterId);
  1292. }
  1293. float carla_get_internal_parameter_value(uint pluginId, int32_t parameterId)
  1294. {
  1295. #ifdef BUILD_BRIDGE
  1296. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0.0f);
  1297. #else
  1298. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, (parameterId == CB::PARAMETER_CTRL_CHANNEL) ? -1.0f : 0.0f);
  1299. #endif
  1300. CARLA_SAFE_ASSERT_RETURN(parameterId != CB::PARAMETER_NULL && parameterId > CB::PARAMETER_MAX, 0.0f);
  1301. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1302. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr, 0.0f);
  1303. carla_debug("carla_get_internal_parameter_value(%i, %i)", pluginId, parameterId);
  1304. return plugin->getInternalParameterValue(parameterId);
  1305. }
  1306. // --------------------------------------------------------------------------------------------------------------------
  1307. const float* carla_get_peak_values(uint pluginId)
  1308. {
  1309. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, nullptr);
  1310. return gStandalone.engine->getPeaks(pluginId);
  1311. }
  1312. float carla_get_input_peak_value(uint pluginId, bool isLeft)
  1313. {
  1314. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0.0f);
  1315. return gStandalone.engine->getInputPeak(pluginId, isLeft);
  1316. }
  1317. float carla_get_output_peak_value(uint pluginId, bool isLeft)
  1318. {
  1319. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0.0f);
  1320. return gStandalone.engine->getOutputPeak(pluginId, isLeft);
  1321. }
  1322. // --------------------------------------------------------------------------------------------------------------------
  1323. CARLA_BACKEND_START_NAMESPACE
  1324. // defined in CarlaPluginLV2.cpp
  1325. void* carla_render_inline_display_lv2(CarlaPlugin* plugin, int width, int height);
  1326. CARLA_BACKEND_END_NAMESPACE
  1327. CarlaInlineDisplayImageSurface* carla_render_inline_display(uint pluginId, int width, int height)
  1328. {
  1329. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, nullptr);
  1330. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1331. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr, nullptr);
  1332. carla_debug("carla_render_inline_display(%i, %i, %i)", pluginId, width, height);
  1333. CARLA_SAFE_ASSERT_RETURN(plugin->getType() == CB::PLUGIN_LV2, nullptr);
  1334. return (CarlaInlineDisplayImageSurface*)CB::carla_render_inline_display_lv2(plugin, width, height);
  1335. }
  1336. // --------------------------------------------------------------------------------------------------------------------
  1337. void carla_set_active(uint pluginId, bool onOff)
  1338. {
  1339. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1340. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1341. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
  1342. carla_debug("carla_set_active(%i, %s)", pluginId, bool2str(onOff));
  1343. return plugin->setActive(onOff, true, false);
  1344. }
  1345. #ifndef BUILD_BRIDGE
  1346. void carla_set_drywet(uint pluginId, float value)
  1347. {
  1348. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1349. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1350. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
  1351. carla_debug("carla_set_drywet(%i, %f)", pluginId, value);
  1352. return plugin->setDryWet(value, true, false);
  1353. }
  1354. void carla_set_volume(uint pluginId, float value)
  1355. {
  1356. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1357. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1358. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
  1359. carla_debug("carla_set_volume(%i, %f)", pluginId, value);
  1360. return plugin->setVolume(value, true, false);
  1361. }
  1362. void carla_set_balance_left(uint pluginId, float value)
  1363. {
  1364. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1365. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1366. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
  1367. carla_debug("carla_set_balance_left(%i, %f)", pluginId, value);
  1368. return plugin->setBalanceLeft(value, true, false);
  1369. }
  1370. void carla_set_balance_right(uint pluginId, float value)
  1371. {
  1372. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1373. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1374. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
  1375. carla_debug("carla_set_balance_right(%i, %f)", pluginId, value);
  1376. return plugin->setBalanceRight(value, true, false);
  1377. }
  1378. void carla_set_panning(uint pluginId, float value)
  1379. {
  1380. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1381. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1382. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
  1383. carla_debug("carla_set_panning(%i, %f)", pluginId, value);
  1384. return plugin->setPanning(value, true, false);
  1385. }
  1386. void carla_set_ctrl_channel(uint pluginId, int8_t channel)
  1387. {
  1388. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1389. CARLA_SAFE_ASSERT_RETURN(channel >= -1 && channel < MAX_MIDI_CHANNELS,);
  1390. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1391. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
  1392. carla_debug("carla_set_ctrl_channel(%i, %i)", pluginId, channel);
  1393. return plugin->setCtrlChannel(channel, true, false);
  1394. }
  1395. #endif
  1396. void carla_set_option(uint pluginId, uint option, bool yesNo)
  1397. {
  1398. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1399. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1400. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
  1401. carla_debug("carla_set_option(%i, %i, %s)", pluginId, option, bool2str(yesNo));
  1402. return plugin->setOption(option, yesNo, false);
  1403. }
  1404. // --------------------------------------------------------------------------------------------------------------------
  1405. void carla_set_parameter_value(uint pluginId, uint32_t parameterId, float value)
  1406. {
  1407. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1408. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1409. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
  1410. carla_debug("carla_set_parameter_value(%i, %i, %f)", pluginId, parameterId, value);
  1411. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(),);
  1412. return plugin->setParameterValue(parameterId, value, true, true, false);
  1413. }
  1414. #ifndef BUILD_BRIDGE
  1415. void carla_set_parameter_midi_channel(uint pluginId, uint32_t parameterId, uint8_t channel)
  1416. {
  1417. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1418. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  1419. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1420. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
  1421. carla_debug("carla_set_parameter_midi_channel(%i, %i, %i)", pluginId, parameterId, channel);
  1422. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(),);
  1423. return plugin->setParameterMidiChannel(parameterId, channel, true, false);
  1424. }
  1425. void carla_set_parameter_midi_cc(uint pluginId, uint32_t parameterId, int16_t cc)
  1426. {
  1427. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1428. CARLA_SAFE_ASSERT_RETURN(cc >= -1 && cc < MAX_MIDI_CONTROL,);
  1429. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1430. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
  1431. carla_debug("carla_set_parameter_midi_cc(%i, %i, %i)", pluginId, parameterId, cc);
  1432. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(),);
  1433. return plugin->setParameterMidiCC(parameterId, cc, true, false);
  1434. }
  1435. #endif
  1436. // --------------------------------------------------------------------------------------------------------------------
  1437. void carla_set_program(uint pluginId, uint32_t programId)
  1438. {
  1439. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1440. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1441. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
  1442. carla_debug("carla_set_program(%i, %i)", pluginId, programId);
  1443. CARLA_SAFE_ASSERT_RETURN(programId < plugin->getProgramCount(),);
  1444. return plugin->setProgram(static_cast<int32_t>(programId), true, true, false);
  1445. }
  1446. void carla_set_midi_program(uint pluginId, uint32_t midiProgramId)
  1447. {
  1448. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1449. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1450. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
  1451. carla_debug("carla_set_midi_program(%i, %i)", pluginId, midiProgramId);
  1452. CARLA_SAFE_ASSERT_RETURN(midiProgramId < plugin->getMidiProgramCount(),);
  1453. return plugin->setMidiProgram(static_cast<int32_t>(midiProgramId), true, true, false);
  1454. }
  1455. // --------------------------------------------------------------------------------------------------------------------
  1456. void carla_set_custom_data(uint pluginId, const char* type, const char* key, const char* value)
  1457. {
  1458. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1459. CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0',);
  1460. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
  1461. CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
  1462. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1463. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
  1464. carla_debug("carla_set_custom_data(%i, \"%s\", \"%s\", \"%s\")", pluginId, type, key, value);
  1465. return plugin->setCustomData(type, key, value, true);
  1466. }
  1467. void carla_set_chunk_data(uint pluginId, const char* chunkData)
  1468. {
  1469. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1470. CARLA_SAFE_ASSERT_RETURN(chunkData != nullptr && chunkData[0] != '\0',);
  1471. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1472. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
  1473. carla_debug("carla_set_chunk_data(%i, \"%s\")", pluginId, chunkData);
  1474. CARLA_SAFE_ASSERT_RETURN(plugin->getOptionsEnabled() & CB::PLUGIN_OPTION_USE_CHUNKS,);
  1475. std::vector<uint8_t> chunk(carla_getChunkFromBase64String(chunkData));
  1476. #ifdef CARLA_PROPER_CPP11_SUPPORT
  1477. return plugin->setChunkData(chunk.data(), chunk.size());
  1478. #else
  1479. return plugin->setChunkData(&chunk.front(), chunk.size());
  1480. #endif
  1481. }
  1482. // --------------------------------------------------------------------------------------------------------------------
  1483. void carla_prepare_for_save(uint pluginId)
  1484. {
  1485. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1486. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1487. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
  1488. carla_debug("carla_prepare_for_save(%i)", pluginId);
  1489. return plugin->prepareForSave();
  1490. }
  1491. void carla_reset_parameters(uint pluginId)
  1492. {
  1493. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1494. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1495. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
  1496. carla_debug("carla_reset_parameters(%i)", pluginId);
  1497. return plugin->resetParameters();
  1498. }
  1499. void carla_randomize_parameters(uint pluginId)
  1500. {
  1501. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1502. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1503. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
  1504. carla_debug("carla_randomize_parameters(%i)", pluginId);
  1505. return plugin->randomizeParameters();
  1506. }
  1507. #ifndef BUILD_BRIDGE
  1508. void carla_send_midi_note(uint pluginId, uint8_t channel, uint8_t note, uint8_t velocity)
  1509. {
  1510. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr && gStandalone.engine->isRunning(),);
  1511. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1512. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
  1513. carla_debug("carla_send_midi_note(%i, %i, %i, %i)", pluginId, channel, note, velocity);
  1514. return plugin->sendMidiSingleNote(channel, note, velocity, true, true, false);
  1515. }
  1516. #endif
  1517. void carla_show_custom_ui(uint pluginId, bool yesNo)
  1518. {
  1519. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
  1520. CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
  1521. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
  1522. carla_debug("carla_show_custom_ui(%i, %s)", pluginId, bool2str(yesNo));
  1523. return plugin->showCustomUI(yesNo);
  1524. }
  1525. // --------------------------------------------------------------------------------------------------------------------
  1526. uint32_t carla_get_buffer_size()
  1527. {
  1528. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0);
  1529. carla_debug("carla_get_buffer_size()");
  1530. return gStandalone.engine->getBufferSize();
  1531. }
  1532. double carla_get_sample_rate()
  1533. {
  1534. CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0.0);
  1535. carla_debug("carla_get_sample_rate()");
  1536. return gStandalone.engine->getSampleRate();
  1537. }
  1538. // --------------------------------------------------------------------------------------------------------------------
  1539. const char* carla_get_last_error()
  1540. {
  1541. carla_debug("carla_get_last_error()");
  1542. if (gStandalone.engine != nullptr)
  1543. return gStandalone.engine->getLastError();
  1544. return gStandalone.lastError;
  1545. }
  1546. const char* carla_get_host_osc_url_tcp()
  1547. {
  1548. carla_debug("carla_get_host_osc_url_tcp()");
  1549. #if defined(HAVE_LIBLO) && !defined(BUILD_BRIDGE)
  1550. if (gStandalone.engine == nullptr)
  1551. {
  1552. carla_stderr2("carla_get_host_osc_url_tcp() failed, engine is not running");
  1553. gStandalone.lastError = "Engine is not running";
  1554. return gNullCharPtr;
  1555. }
  1556. const char* const path = gStandalone.engine->getOscServerPathTCP();
  1557. if (path != nullptr && path[0] != '\0')
  1558. return path;
  1559. static const char* const notAvailable = "OSC TCP port not available";
  1560. return notAvailable;
  1561. #else
  1562. return gNullCharPtr;
  1563. #endif
  1564. }
  1565. const char* carla_get_host_osc_url_udp()
  1566. {
  1567. carla_debug("carla_get_host_osc_url_udp()");
  1568. #if defined(HAVE_LIBLO) && !defined(BUILD_BRIDGE)
  1569. if (gStandalone.engine == nullptr)
  1570. {
  1571. carla_stderr2("carla_get_host_osc_url_udp() failed, engine is not running");
  1572. gStandalone.lastError = "Engine is not running";
  1573. return gNullCharPtr;
  1574. }
  1575. const char* const path = gStandalone.engine->getOscServerPathUDP();
  1576. if (path != nullptr && path[0] != '\0')
  1577. return path;
  1578. static const char* const notAvailable = "OSC UDP port not available";
  1579. return notAvailable;
  1580. #else
  1581. return gNullCharPtr;
  1582. #endif
  1583. }
  1584. // --------------------------------------------------------------------------------------------------------------------
  1585. #define CARLA_PLUGIN_UI_CLASS_PREFIX Standalone
  1586. #include "CarlaPluginUI.cpp"
  1587. #undef CARLA_PLUGIN_UI_CLASS_PREFIX
  1588. #include "CarlaDssiUtils.cpp"
  1589. #include "CarlaMacUtils.cpp"
  1590. #include "CarlaPatchbayUtils.cpp"
  1591. #include "CarlaPipeUtils.cpp"
  1592. #include "CarlaStateUtils.cpp"
  1593. // --------------------------------------------------------------------------------------------------------------------