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.

1918 lines
68KB

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