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.

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