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.

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