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.

1997 lines
70KB

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