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.

1859 lines
67KB

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