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.

1903 lines
68KB

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