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.

1844 lines
66KB

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