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.

1990 lines
71KB

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