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.

2410 lines
86KB

  1. /*
  2. * Carla Standalone
  3. * Copyright (C) 2011-2022 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 "CarlaHostImpl.hpp"
  20. #include "CarlaMIDI.h"
  21. #include "CarlaEngineInit.hpp"
  22. #include "CarlaPlugin.hpp"
  23. #include "CarlaBackendUtils.hpp"
  24. #include "CarlaBase64Utils.hpp"
  25. #include "ThreadSafeFFTW.hpp"
  26. #ifndef BUILD_BRIDGE
  27. # include "CarlaLogThread.hpp"
  28. #endif
  29. #include "water/files/File.h"
  30. #ifdef USING_JUCE
  31. # include "carla_juce/carla_juce.h"
  32. #endif
  33. #define CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(cond, msg, ret) \
  34. if (! (cond)) { \
  35. carla_stderr2("%s: " msg, __FUNCTION__); \
  36. if (handle->isStandalone) \
  37. ((CarlaHostStandalone*)handle)->lastError = msg; \
  38. return ret; \
  39. }
  40. // -------------------------------------------------------------------------------------------------------------------
  41. // Always return a valid string ptr for standalone functions
  42. static const char* const gNullCharPtr = "";
  43. static void checkStringPtr(const char*& charPtr) noexcept
  44. {
  45. if (charPtr == nullptr)
  46. charPtr = gNullCharPtr;
  47. }
  48. // -------------------------------------------------------------------------------------------------------------------
  49. // Constructors
  50. _CarlaPluginInfo::_CarlaPluginInfo() noexcept
  51. : type(CB::PLUGIN_NONE),
  52. category(CB::PLUGIN_CATEGORY_NONE),
  53. hints(0x0),
  54. optionsAvailable(0x0),
  55. optionsEnabled(0x0),
  56. filename(gNullCharPtr),
  57. name(gNullCharPtr),
  58. label(gNullCharPtr),
  59. maker(gNullCharPtr),
  60. copyright(gNullCharPtr),
  61. iconName(gNullCharPtr),
  62. uniqueId(0) {}
  63. _CarlaPluginInfo::~_CarlaPluginInfo() noexcept
  64. {
  65. if (label != gNullCharPtr)
  66. delete[] label;
  67. if (maker != gNullCharPtr)
  68. delete[] maker;
  69. if (copyright != gNullCharPtr)
  70. delete[] copyright;
  71. }
  72. _CarlaParameterInfo::_CarlaParameterInfo() noexcept
  73. : name(gNullCharPtr),
  74. symbol(gNullCharPtr),
  75. unit(gNullCharPtr),
  76. comment(gNullCharPtr),
  77. groupName(gNullCharPtr),
  78. scalePointCount(0) {}
  79. _CarlaParameterInfo::~_CarlaParameterInfo() noexcept
  80. {
  81. if (name != gNullCharPtr)
  82. delete[] name;
  83. if (symbol != gNullCharPtr)
  84. delete[] symbol;
  85. if (unit != gNullCharPtr)
  86. delete[] unit;
  87. if (comment != gNullCharPtr)
  88. delete[] comment;
  89. if (groupName != gNullCharPtr)
  90. delete[] groupName;
  91. }
  92. _CarlaScalePointInfo::_CarlaScalePointInfo() noexcept
  93. : value(0.0f),
  94. label(gNullCharPtr) {}
  95. _CarlaScalePointInfo::~_CarlaScalePointInfo() noexcept
  96. {
  97. if (label != gNullCharPtr)
  98. delete[] label;
  99. }
  100. _CarlaTransportInfo::_CarlaTransportInfo() noexcept
  101. : playing(false),
  102. frame(0),
  103. bar(0),
  104. beat(0),
  105. tick(0),
  106. bpm(0.0) {}
  107. void _CarlaTransportInfo::clear() noexcept
  108. {
  109. playing = false;
  110. frame = 0;
  111. bar = 0;
  112. beat = 0;
  113. tick = 0;
  114. bpm = 0.0;
  115. }
  116. // --------------------------------------------------------------------------------------------------------------------
  117. using CARLA_BACKEND_NAMESPACE::CarlaPluginPtr;
  118. // --------------------------------------------------------------------------------------------------------------------
  119. uint carla_get_engine_driver_count()
  120. {
  121. carla_debug("carla_get_engine_driver_count()");
  122. return CarlaEngine::getDriverCount();
  123. }
  124. const char* carla_get_engine_driver_name(uint index)
  125. {
  126. carla_debug("carla_get_engine_driver_name(%i)", index);
  127. return CarlaEngine::getDriverName(index);
  128. }
  129. const char* const* carla_get_engine_driver_device_names(uint index)
  130. {
  131. carla_debug("carla_get_engine_driver_device_names(%i)", index);
  132. return CarlaEngine::getDriverDeviceNames(index);
  133. }
  134. const EngineDriverDeviceInfo* carla_get_engine_driver_device_info(uint index, const char* name)
  135. {
  136. CARLA_SAFE_ASSERT_RETURN(name != nullptr, nullptr);
  137. static EngineDriverDeviceInfo retDevInfo;
  138. static const uint32_t nullBufferSizes[] = { 0 };
  139. static const double nullSampleRates[] = { 0.0 };
  140. carla_debug("carla_get_engine_driver_device_info(%i, \"%s\")", index, name);
  141. if (const EngineDriverDeviceInfo* const devInfo = CarlaEngine::getDriverDeviceInfo(index, name))
  142. {
  143. retDevInfo.hints = devInfo->hints;
  144. retDevInfo.bufferSizes = (devInfo->bufferSizes != nullptr) ? devInfo->bufferSizes : nullBufferSizes;
  145. retDevInfo.sampleRates = (devInfo->sampleRates != nullptr) ? devInfo->sampleRates : nullSampleRates;
  146. }
  147. else
  148. {
  149. retDevInfo.hints = 0x0;
  150. retDevInfo.bufferSizes = nullBufferSizes;
  151. retDevInfo.sampleRates = nullSampleRates;
  152. }
  153. return &retDevInfo;
  154. }
  155. bool carla_show_engine_driver_device_control_panel(uint index, const char* name)
  156. {
  157. return CarlaEngine::showDriverDeviceControlPanel(index, name);
  158. }
  159. // --------------------------------------------------------------------------------------------------------------------
  160. CarlaHostHandle carla_standalone_host_init(void)
  161. {
  162. #ifdef CARLA_OS_UNIX
  163. static const ThreadSafeFFTW sThreadSafeFFTW;
  164. #endif
  165. static CarlaHostStandalone gStandalone;
  166. return &gStandalone;
  167. }
  168. CarlaEngine* carla_get_engine_from_handle(CarlaHostHandle handle)
  169. {
  170. carla_debug("carla_get_engine(%p)", handle);
  171. return handle->engine;
  172. }
  173. // --------------------------------------------------------------------------------------------------------------------
  174. static void carla_engine_init_common(const CarlaHostStandalone& standalone, CarlaEngine* const engine)
  175. {
  176. engine->setCallback(standalone.engineCallback, standalone.engineCallbackPtr);
  177. engine->setFileCallback(standalone.fileCallback, standalone.fileCallbackPtr);
  178. using water::File;
  179. const File waterBinaryDir(File::getSpecialLocation(File::currentExecutableFile).getParentDirectory());
  180. #ifdef BUILD_BRIDGE
  181. /*
  182. if (const char* const forceStereo = std::getenv("ENGINE_OPTION_FORCE_STEREO"))
  183. engine->setOption(CB::ENGINE_OPTION_FORCE_STEREO, (std::strcmp(forceStereo, "true") == 0) ? 1 : 0, nullptr);
  184. if (const char* const preferPluginBridges = std::getenv("ENGINE_OPTION_PREFER_PLUGIN_BRIDGES"))
  185. engine->setOption(CB::ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, (std::strcmp(preferPluginBridges, "true") == 0) ? 1 : 0, nullptr);
  186. if (const char* const preferUiBridges = std::getenv("ENGINE_OPTION_PREFER_UI_BRIDGES"))
  187. engine->setOption(CB::ENGINE_OPTION_PREFER_UI_BRIDGES, (std::strcmp(preferUiBridges, "true") == 0) ? 1 : 0, nullptr);
  188. */
  189. if (const char* const uisAlwaysOnTop = std::getenv("ENGINE_OPTION_UIS_ALWAYS_ON_TOP"))
  190. engine->setOption(CB::ENGINE_OPTION_UIS_ALWAYS_ON_TOP, (std::strcmp(uisAlwaysOnTop, "true") == 0) ? 1 : 0, nullptr);
  191. if (const char* const maxParameters = std::getenv("ENGINE_OPTION_MAX_PARAMETERS"))
  192. engine->setOption(CB::ENGINE_OPTION_MAX_PARAMETERS, std::atoi(maxParameters), nullptr);
  193. if (const char* const resetXruns = std::getenv("ENGINE_OPTION_RESET_XRUNS"))
  194. engine->setOption(CB::ENGINE_OPTION_RESET_XRUNS, (std::strcmp(resetXruns, "true") == 0) ? 1 : 0, nullptr);
  195. if (const char* const uiBridgesTimeout = std::getenv("ENGINE_OPTION_UI_BRIDGES_TIMEOUT"))
  196. engine->setOption(CB::ENGINE_OPTION_UI_BRIDGES_TIMEOUT, std::atoi(uiBridgesTimeout), nullptr);
  197. if (const char* const pathAudio = std::getenv("ENGINE_OPTION_FILE_PATH_AUDIO"))
  198. engine->setOption(CB::ENGINE_OPTION_FILE_PATH, CB::FILE_AUDIO, pathAudio);
  199. if (const char* const pathMIDI = std::getenv("ENGINE_OPTION_FILE_PATH_MIDI"))
  200. engine->setOption(CB::ENGINE_OPTION_FILE_PATH, CB::FILE_MIDI, pathMIDI);
  201. if (const char* const pathLADSPA = std::getenv("ENGINE_OPTION_PLUGIN_PATH_LADSPA"))
  202. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_LADSPA, pathLADSPA);
  203. if (const char* const pathDSSI = std::getenv("ENGINE_OPTION_PLUGIN_PATH_DSSI"))
  204. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_DSSI, pathDSSI);
  205. if (const char* const pathLV2 = std::getenv("ENGINE_OPTION_PLUGIN_PATH_LV2"))
  206. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_LV2, pathLV2);
  207. if (const char* const pathVST2 = std::getenv("ENGINE_OPTION_PLUGIN_PATH_VST2"))
  208. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_VST2, pathVST2);
  209. if (const char* const pathVST3 = std::getenv("ENGINE_OPTION_PLUGIN_PATH_VST3"))
  210. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_VST3, pathVST3);
  211. if (const char* const pathSF2 = std::getenv("ENGINE_OPTION_PLUGIN_PATH_SF2"))
  212. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_SF2, pathSF2);
  213. if (const char* const pathSFZ = std::getenv("ENGINE_OPTION_PLUGIN_PATH_SFZ"))
  214. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_SFZ, pathSFZ);
  215. if (const char* const pathJSFX = std::getenv("ENGINE_OPTION_PLUGIN_PATH_JSFX"))
  216. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_JSFX, pathJSFX);
  217. if (const char* const binaryDir = std::getenv("ENGINE_OPTION_PATH_BINARIES"))
  218. engine->setOption(CB::ENGINE_OPTION_PATH_BINARIES, 0, binaryDir);
  219. else
  220. engine->setOption(CB::ENGINE_OPTION_PATH_BINARIES, 0, waterBinaryDir.getFullPathName().toRawUTF8());
  221. if (const char* const resourceDir = std::getenv("ENGINE_OPTION_PATH_RESOURCES"))
  222. engine->setOption(CB::ENGINE_OPTION_PATH_RESOURCES, 0, resourceDir);
  223. else
  224. engine->setOption(CB::ENGINE_OPTION_PATH_RESOURCES, 0, waterBinaryDir.getChildFile("resources").getFullPathName().toRawUTF8());
  225. if (const char* const preventBadBehaviour = std::getenv("ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR"))
  226. engine->setOption(CB::ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR, (std::strcmp(preventBadBehaviour, "true") == 0) ? 1 : 0, nullptr);
  227. if (const char* const frontendWinId = std::getenv("ENGINE_OPTION_FRONTEND_WIN_ID"))
  228. engine->setOption(CB::ENGINE_OPTION_FRONTEND_WIN_ID, 0, frontendWinId);
  229. #else
  230. engine->setOption(CB::ENGINE_OPTION_FORCE_STEREO, standalone.engineOptions.forceStereo ? 1 : 0, nullptr);
  231. engine->setOption(CB::ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, standalone.engineOptions.preferPluginBridges ? 1 : 0, nullptr);
  232. engine->setOption(CB::ENGINE_OPTION_PREFER_UI_BRIDGES, standalone.engineOptions.preferUiBridges ? 1 : 0, nullptr);
  233. engine->setOption(CB::ENGINE_OPTION_UIS_ALWAYS_ON_TOP, standalone.engineOptions.uisAlwaysOnTop ? 1 : 0, nullptr);
  234. engine->setOption(CB::ENGINE_OPTION_MAX_PARAMETERS, static_cast<int>(standalone.engineOptions.maxParameters), nullptr);
  235. engine->setOption(CB::ENGINE_OPTION_RESET_XRUNS, standalone.engineOptions.resetXruns ? 1 : 0, nullptr);
  236. engine->setOption(CB::ENGINE_OPTION_UI_BRIDGES_TIMEOUT, static_cast<int>(standalone.engineOptions.uiBridgesTimeout), nullptr);
  237. engine->setOption(CB::ENGINE_OPTION_AUDIO_BUFFER_SIZE, static_cast<int>(standalone.engineOptions.audioBufferSize), nullptr);
  238. engine->setOption(CB::ENGINE_OPTION_AUDIO_SAMPLE_RATE, static_cast<int>(standalone.engineOptions.audioSampleRate), nullptr);
  239. engine->setOption(CB::ENGINE_OPTION_AUDIO_TRIPLE_BUFFER, standalone.engineOptions.audioTripleBuffer ? 1 : 0, nullptr);
  240. if (standalone.engineOptions.audioDriver != nullptr)
  241. engine->setOption(CB::ENGINE_OPTION_AUDIO_DRIVER, 0, standalone.engineOptions.audioDriver);
  242. if (standalone.engineOptions.audioDevice != nullptr)
  243. engine->setOption(CB::ENGINE_OPTION_AUDIO_DEVICE, 0, standalone.engineOptions.audioDevice);
  244. engine->setOption(CB::ENGINE_OPTION_OSC_ENABLED, standalone.engineOptions.oscEnabled, nullptr);
  245. engine->setOption(CB::ENGINE_OPTION_OSC_PORT_TCP, standalone.engineOptions.oscPortTCP, nullptr);
  246. engine->setOption(CB::ENGINE_OPTION_OSC_PORT_UDP, standalone.engineOptions.oscPortUDP, nullptr);
  247. if (standalone.engineOptions.pathAudio != nullptr)
  248. engine->setOption(CB::ENGINE_OPTION_FILE_PATH, CB::FILE_AUDIO, standalone.engineOptions.pathAudio);
  249. if (standalone.engineOptions.pathMIDI != nullptr)
  250. engine->setOption(CB::ENGINE_OPTION_FILE_PATH, CB::FILE_MIDI, standalone.engineOptions.pathMIDI);
  251. if (standalone.engineOptions.pathLADSPA != nullptr)
  252. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_LADSPA, standalone.engineOptions.pathLADSPA);
  253. if (standalone.engineOptions.pathDSSI != nullptr)
  254. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_DSSI, standalone.engineOptions.pathDSSI);
  255. if (standalone.engineOptions.pathLV2 != nullptr)
  256. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_LV2, standalone.engineOptions.pathLV2);
  257. if (standalone.engineOptions.pathVST2 != nullptr)
  258. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_VST2, standalone.engineOptions.pathVST2);
  259. if (standalone.engineOptions.pathVST3 != nullptr)
  260. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_VST3, standalone.engineOptions.pathVST3);
  261. if (standalone.engineOptions.pathSF2 != nullptr)
  262. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_SF2, standalone.engineOptions.pathSF2);
  263. if (standalone.engineOptions.pathSFZ != nullptr)
  264. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_SFZ, standalone.engineOptions.pathSFZ);
  265. if (standalone.engineOptions.pathJSFX != nullptr)
  266. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_JSFX, standalone.engineOptions.pathJSFX);
  267. if (standalone.engineOptions.binaryDir != nullptr && standalone.engineOptions.binaryDir[0] != '\0')
  268. engine->setOption(CB::ENGINE_OPTION_PATH_BINARIES, 0, standalone.engineOptions.binaryDir);
  269. else
  270. engine->setOption(CB::ENGINE_OPTION_PATH_BINARIES, 0, waterBinaryDir.getFullPathName().toRawUTF8());
  271. if (standalone.engineOptions.resourceDir != nullptr && standalone.engineOptions.resourceDir[0] != '\0')
  272. engine->setOption(CB::ENGINE_OPTION_PATH_RESOURCES, 0, standalone.engineOptions.resourceDir);
  273. engine->setOption(CB::ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR, standalone.engineOptions.preventBadBehaviour ? 1 : 0, nullptr);
  274. engine->setOption(CB::ENGINE_OPTION_FRONTEND_BACKGROUND_COLOR, static_cast<int>(standalone.engineOptions.bgColor), nullptr);
  275. engine->setOption(CB::ENGINE_OPTION_FRONTEND_FOREGROUND_COLOR, static_cast<int>(standalone.engineOptions.fgColor), nullptr);
  276. engine->setOption(CB::ENGINE_OPTION_FRONTEND_UI_SCALE, static_cast<int>(standalone.engineOptions.uiScale * 1000.0f), nullptr);
  277. if (standalone.engineOptions.frontendWinId != 0)
  278. {
  279. char strBuf[STR_MAX+1];
  280. strBuf[STR_MAX] = '\0';
  281. std::snprintf(strBuf, STR_MAX, P_UINTPTR, standalone.engineOptions.frontendWinId);
  282. engine->setOption(CB::ENGINE_OPTION_FRONTEND_WIN_ID, 0, strBuf);
  283. }
  284. else
  285. {
  286. engine->setOption(CB::ENGINE_OPTION_FRONTEND_WIN_ID, 0, "0");
  287. }
  288. # ifndef CARLA_OS_WIN
  289. if (standalone.engineOptions.wine.executable != nullptr && standalone.engineOptions.wine.executable[0] != '\0')
  290. engine->setOption(CB::ENGINE_OPTION_WINE_EXECUTABLE, 0, standalone.engineOptions.wine.executable);
  291. engine->setOption(CB::ENGINE_OPTION_WINE_AUTO_PREFIX, standalone.engineOptions.wine.autoPrefix ? 1 : 0, nullptr);
  292. if (standalone.engineOptions.wine.fallbackPrefix != nullptr && standalone.engineOptions.wine.fallbackPrefix[0] != '\0')
  293. engine->setOption(CB::ENGINE_OPTION_WINE_FALLBACK_PREFIX, 0, standalone.engineOptions.wine.fallbackPrefix);
  294. engine->setOption(CB::ENGINE_OPTION_WINE_RT_PRIO_ENABLED, standalone.engineOptions.wine.rtPrio ? 1 : 0, nullptr);
  295. engine->setOption(CB::ENGINE_OPTION_WINE_BASE_RT_PRIO, standalone.engineOptions.wine.baseRtPrio, nullptr);
  296. engine->setOption(CB::ENGINE_OPTION_WINE_SERVER_RT_PRIO, standalone.engineOptions.wine.serverRtPrio, nullptr);
  297. # endif
  298. engine->setOption(CB::ENGINE_OPTION_CLIENT_NAME_PREFIX, 0, standalone.engineOptions.clientNamePrefix);
  299. engine->setOption(CB::ENGINE_OPTION_PLUGINS_ARE_STANDALONE, standalone.engineOptions.pluginsAreStandalone, nullptr);
  300. #endif // BUILD_BRIDGE
  301. }
  302. bool carla_engine_init(CarlaHostHandle handle, const char* driverName, const char* clientName)
  303. {
  304. CARLA_SAFE_ASSERT_RETURN(driverName != nullptr && driverName[0] != '\0', false);
  305. CARLA_SAFE_ASSERT_RETURN(clientName != nullptr && clientName[0] != '\0', false);
  306. carla_debug("carla_engine_init(%p, \"%s\", \"%s\")", handle, driverName, clientName);
  307. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->isStandalone, "Must be a standalone host handle", false);
  308. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine == nullptr, "Engine is already initialized", false);
  309. #ifdef CARLA_OS_WIN
  310. carla_setenv("WINEASIO_CLIENT_NAME", clientName);
  311. #endif
  312. #ifdef USING_JUCE
  313. CarlaJUCE::initialiseJuce_GUI();
  314. #endif
  315. CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
  316. CarlaEngine* const engine = CarlaEngine::newDriverByName(driverName);
  317. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(engine != nullptr, "The selected audio driver is not available", false);
  318. shandle.engine = engine;
  319. #ifdef BUILD_BRIDGE
  320. if (std::getenv("CARLA_BRIDGE_DUMMY") != nullptr)
  321. {
  322. // engine->setOption(CB::ENGINE_OPTION_PROCESS_MODE, CB::ENGINE_PROCESS_MODE_PATCHBAY, nullptr);
  323. engine->setOption(CB::ENGINE_OPTION_PROCESS_MODE, CB::ENGINE_PROCESS_MODE_CONTINUOUS_RACK, nullptr);
  324. engine->setOption(CB::ENGINE_OPTION_TRANSPORT_MODE, CB::ENGINE_TRANSPORT_MODE_INTERNAL, nullptr);
  325. engine->setOption(CB::ENGINE_OPTION_AUDIO_BUFFER_SIZE, 4096, nullptr);
  326. engine->setOption(CB::ENGINE_OPTION_AUDIO_SAMPLE_RATE, 48000, nullptr);
  327. }
  328. else
  329. {
  330. engine->setOption(CB::ENGINE_OPTION_PROCESS_MODE, CB::ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS, nullptr);
  331. engine->setOption(CB::ENGINE_OPTION_TRANSPORT_MODE, CB::ENGINE_TRANSPORT_MODE_JACK, nullptr);
  332. }
  333. engine->setOption(CB::ENGINE_OPTION_FORCE_STEREO, false, nullptr);
  334. engine->setOption(CB::ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, false, nullptr);
  335. engine->setOption(CB::ENGINE_OPTION_PREFER_UI_BRIDGES, false, nullptr);
  336. #else
  337. engine->setOption(CB::ENGINE_OPTION_PROCESS_MODE, static_cast<int>(shandle.engineOptions.processMode), nullptr);
  338. engine->setOption(CB::ENGINE_OPTION_TRANSPORT_MODE, static_cast<int>(shandle.engineOptions.transportMode), shandle.engineOptions.transportExtra);
  339. #endif
  340. carla_engine_init_common(shandle, engine);
  341. if (engine->init(clientName))
  342. {
  343. #ifndef BUILD_BRIDGE
  344. if (shandle.logThreadEnabled && std::getenv("CARLA_LOGS_DISABLED") == nullptr)
  345. shandle.logThread.init();
  346. #endif
  347. shandle.lastError = "No error";
  348. return true;
  349. }
  350. else
  351. {
  352. shandle.lastError = engine->getLastError();
  353. shandle.engine = nullptr;
  354. delete engine;
  355. #ifdef USING_JUCE
  356. CarlaJUCE::shutdownJuce_GUI();
  357. #endif
  358. return false;
  359. }
  360. }
  361. #ifdef BUILD_BRIDGE
  362. bool carla_engine_init_bridge(CarlaHostHandle handle,
  363. const char audioBaseName[6+1],
  364. const char rtClientBaseName[6+1],
  365. const char nonRtClientBaseName[6+1],
  366. const char nonRtServerBaseName[6+1],
  367. const char* const clientName)
  368. {
  369. CARLA_SAFE_ASSERT_RETURN(audioBaseName != nullptr && audioBaseName[0] != '\0', false);
  370. CARLA_SAFE_ASSERT_RETURN(rtClientBaseName != nullptr && rtClientBaseName[0] != '\0', false);
  371. CARLA_SAFE_ASSERT_RETURN(nonRtClientBaseName != nullptr && nonRtClientBaseName[0] != '\0', false);
  372. CARLA_SAFE_ASSERT_RETURN(nonRtServerBaseName != nullptr && nonRtServerBaseName[0] != '\0', false);
  373. CARLA_SAFE_ASSERT_RETURN(clientName != nullptr && clientName[0] != '\0', false);
  374. carla_debug("carla_engine_init_bridge(%p, \"%s\", \"%s\", \"%s\", \"%s\", \"%s\")",
  375. handle, audioBaseName, rtClientBaseName, nonRtClientBaseName, nonRtServerBaseName, clientName);
  376. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->isStandalone, "Must be a standalone host handle", false);
  377. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine == nullptr, "Engine is already initialized", false);
  378. CarlaScopedPointer<CarlaEngine> engine(CB::EngineInit::newBridge(audioBaseName,
  379. rtClientBaseName,
  380. nonRtClientBaseName,
  381. nonRtServerBaseName));
  382. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(engine != nullptr, "The selected audio driver is not available", false);
  383. engine->setOption(CB::ENGINE_OPTION_PROCESS_MODE, CB::ENGINE_PROCESS_MODE_BRIDGE, nullptr);
  384. engine->setOption(CB::ENGINE_OPTION_TRANSPORT_MODE, CB::ENGINE_TRANSPORT_MODE_BRIDGE, nullptr);
  385. CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
  386. carla_engine_init_common(shandle, engine);
  387. if (engine->init(clientName))
  388. {
  389. shandle.lastError = "No error";
  390. shandle.engine = engine.release();
  391. return true;
  392. }
  393. else
  394. {
  395. shandle.lastError = engine->getLastError();
  396. return false;
  397. }
  398. }
  399. #endif
  400. bool carla_engine_close(CarlaHostHandle handle)
  401. {
  402. carla_debug("carla_engine_close(%p)", handle);
  403. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->isStandalone, "Must be a standalone host handle", false);
  404. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  405. CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
  406. CarlaEngine* const engine = shandle.engine;
  407. engine->setAboutToClose();
  408. engine->removeAllPlugins();
  409. const bool closed = engine->close();
  410. if (! closed)
  411. shandle.lastError = engine->getLastError();
  412. #ifndef BUILD_BRIDGE
  413. shandle.logThread.stop();
  414. #endif
  415. shandle.engine = nullptr;
  416. delete engine;
  417. #ifdef USING_JUCE
  418. CarlaJUCE::shutdownJuce_GUI();
  419. #endif
  420. return closed;
  421. }
  422. void carla_engine_idle(CarlaHostHandle handle)
  423. {
  424. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->isStandalone,);
  425. handle->engine->idle();
  426. #ifdef USING_JUCE
  427. if (handle->isStandalone)
  428. CarlaJUCE::idleJuce_GUI();
  429. #endif
  430. }
  431. bool carla_is_engine_running(CarlaHostHandle handle)
  432. {
  433. return (handle->engine != nullptr && handle->engine->isRunning());
  434. }
  435. const CarlaRuntimeEngineInfo* carla_get_runtime_engine_info(CarlaHostHandle handle)
  436. {
  437. static CarlaRuntimeEngineInfo retInfo;
  438. // reset
  439. retInfo.load = 0.0f;
  440. retInfo.xruns = 0;
  441. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
  442. retInfo.load = handle->engine->getDSPLoad();
  443. retInfo.xruns = handle->engine->getTotalXruns();
  444. return &retInfo;
  445. }
  446. #ifndef BUILD_BRIDGE
  447. const CarlaRuntimeEngineDriverDeviceInfo* carla_get_runtime_engine_driver_device_info(CarlaHostHandle handle)
  448. {
  449. static CarlaRuntimeEngineDriverDeviceInfo retInfo;
  450. // reset
  451. retInfo.name = gNullCharPtr;
  452. retInfo.hints = 0x0;
  453. retInfo.bufferSize = 0;
  454. retInfo.bufferSizes = nullptr;
  455. retInfo.sampleRate = 0.0;
  456. retInfo.sampleRates = nullptr;
  457. const char* audioDriver;
  458. const char* audioDevice;
  459. if (CarlaEngine* const engine = handle->engine)
  460. {
  461. audioDriver = engine->getCurrentDriverName();
  462. audioDevice = engine->getOptions().audioDevice;
  463. retInfo.bufferSize = engine->getBufferSize();
  464. retInfo.sampleRate = engine->getSampleRate();
  465. }
  466. else if (handle->isStandalone)
  467. {
  468. CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
  469. audioDriver = shandle.engineOptions.audioDriver;
  470. audioDevice = shandle.engineOptions.audioDevice;
  471. retInfo.bufferSize = shandle.engineOptions.audioBufferSize;
  472. retInfo.sampleRate = shandle.engineOptions.audioSampleRate;
  473. }
  474. else
  475. {
  476. return &retInfo;
  477. }
  478. CARLA_SAFE_ASSERT_RETURN(audioDriver != nullptr, &retInfo);
  479. CARLA_SAFE_ASSERT_RETURN(audioDevice != nullptr, &retInfo);
  480. uint index = 0;
  481. uint count = CarlaEngine::getDriverCount();
  482. for (; index<count; ++index)
  483. {
  484. const char* const testDriverName = CarlaEngine::getDriverName(index);
  485. CARLA_SAFE_ASSERT_CONTINUE(testDriverName != nullptr);
  486. if (std::strcmp(testDriverName, audioDriver) == 0)
  487. break;
  488. }
  489. CARLA_SAFE_ASSERT_RETURN(index != count, &retInfo);
  490. const EngineDriverDeviceInfo* const devInfo = CarlaEngine::getDriverDeviceInfo(index, audioDevice);
  491. CARLA_SAFE_ASSERT_RETURN(devInfo != nullptr, &retInfo);
  492. retInfo.name = audioDevice;
  493. retInfo.hints = devInfo->hints;
  494. retInfo.bufferSizes = devInfo->bufferSizes;
  495. retInfo.sampleRates = devInfo->sampleRates;
  496. return &retInfo;
  497. }
  498. bool carla_set_engine_buffer_size_and_sample_rate(CarlaHostHandle handle, uint bufferSize, double sampleRate)
  499. {
  500. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, false);
  501. carla_debug("carla_set_engine_buffer_size_and_sample_rate(%p, %u, %f)", handle, bufferSize, sampleRate);
  502. return handle->engine->setBufferSizeAndSampleRate(bufferSize, sampleRate);
  503. }
  504. bool carla_show_engine_device_control_panel(CarlaHostHandle handle)
  505. {
  506. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, false);
  507. carla_debug("carla_show_engine_device_control_panel(%p)", handle);
  508. return handle->engine->showDeviceControlPanel();
  509. }
  510. #endif // BUILD_BRIDGE
  511. void carla_clear_engine_xruns(CarlaHostHandle handle)
  512. {
  513. if (handle->engine != nullptr)
  514. handle->engine->clearXruns();
  515. }
  516. void carla_cancel_engine_action(CarlaHostHandle handle)
  517. {
  518. if (handle->engine != nullptr)
  519. handle->engine->setActionCanceled(true);
  520. }
  521. bool carla_set_engine_about_to_close(CarlaHostHandle handle)
  522. {
  523. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, true);
  524. carla_debug("carla_set_engine_about_to_close(%p)", handle);
  525. return handle->engine->setAboutToClose();
  526. }
  527. void carla_set_engine_callback(CarlaHostHandle handle, EngineCallbackFunc func, void* ptr)
  528. {
  529. carla_debug("carla_set_engine_callback(%p, %p, %p)", handle, func, ptr);
  530. if (handle->isStandalone)
  531. {
  532. CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
  533. shandle.engineCallback = func;
  534. shandle.engineCallbackPtr = ptr;
  535. #ifndef BUILD_BRIDGE
  536. shandle.logThread.setCallback(func, ptr);
  537. #endif
  538. }
  539. if (handle->engine != nullptr)
  540. handle->engine->setCallback(func, ptr);
  541. }
  542. void carla_set_engine_option(CarlaHostHandle handle, EngineOption option, int value, const char* valueStr)
  543. {
  544. carla_debug("carla_set_engine_option(%p, %i:%s, %i, \"%s\")",
  545. handle, option, CB::EngineOption2Str(option), value, valueStr);
  546. if (handle->isStandalone)
  547. {
  548. CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
  549. switch (option)
  550. {
  551. case CB::ENGINE_OPTION_DEBUG:
  552. break;
  553. case CB::ENGINE_OPTION_PROCESS_MODE:
  554. CARLA_SAFE_ASSERT_RETURN(value >= CB::ENGINE_PROCESS_MODE_SINGLE_CLIENT && value < CB::ENGINE_PROCESS_MODE_BRIDGE,);
  555. shandle.engineOptions.processMode = static_cast<CB::EngineProcessMode>(value);
  556. break;
  557. case CB::ENGINE_OPTION_TRANSPORT_MODE:
  558. CARLA_SAFE_ASSERT_RETURN(value >= CB::ENGINE_TRANSPORT_MODE_DISABLED && value <= CB::ENGINE_TRANSPORT_MODE_BRIDGE,);
  559. // jack transport cannot be disabled in multi-client
  560. if (shandle.engineOptions.processMode == CB::ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS
  561. && value != CB::ENGINE_TRANSPORT_MODE_JACK)
  562. {
  563. shandle.engineOptions.transportMode = CB::ENGINE_TRANSPORT_MODE_JACK;
  564. if (shandle.engineCallback != nullptr)
  565. shandle.engineCallback(shandle.engineCallbackPtr,
  566. CB::ENGINE_CALLBACK_TRANSPORT_MODE_CHANGED,
  567. 0,
  568. CB::ENGINE_TRANSPORT_MODE_JACK,
  569. 0, 0, 0.0f,
  570. shandle.engineOptions.transportExtra);
  571. }
  572. else
  573. {
  574. shandle.engineOptions.transportMode = static_cast<CB::EngineTransportMode>(value);
  575. }
  576. delete[] shandle.engineOptions.transportExtra;
  577. if (value != CB::ENGINE_TRANSPORT_MODE_DISABLED && valueStr != nullptr)
  578. shandle.engineOptions.transportExtra = carla_strdup_safe(valueStr);
  579. else
  580. shandle.engineOptions.transportExtra = nullptr;
  581. break;
  582. case CB::ENGINE_OPTION_FORCE_STEREO:
  583. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  584. shandle.engineOptions.forceStereo = (value != 0);
  585. break;
  586. case CB::ENGINE_OPTION_PREFER_PLUGIN_BRIDGES:
  587. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  588. shandle.engineOptions.preferPluginBridges = (value != 0);
  589. break;
  590. case CB::ENGINE_OPTION_PREFER_UI_BRIDGES:
  591. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  592. shandle.engineOptions.preferUiBridges = (value != 0);
  593. break;
  594. case CB::ENGINE_OPTION_UIS_ALWAYS_ON_TOP:
  595. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  596. shandle.engineOptions.uisAlwaysOnTop = (value != 0);
  597. break;
  598. case CB::ENGINE_OPTION_MAX_PARAMETERS:
  599. CARLA_SAFE_ASSERT_RETURN(value >= 0,);
  600. shandle.engineOptions.maxParameters = static_cast<uint>(value);
  601. break;
  602. case CB::ENGINE_OPTION_RESET_XRUNS:
  603. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  604. shandle.engineOptions.resetXruns = (value != 0);
  605. break;
  606. case CB::ENGINE_OPTION_UI_BRIDGES_TIMEOUT:
  607. CARLA_SAFE_ASSERT_RETURN(value >= 0,);
  608. shandle.engineOptions.uiBridgesTimeout = static_cast<uint>(value);
  609. break;
  610. case CB::ENGINE_OPTION_AUDIO_BUFFER_SIZE:
  611. CARLA_SAFE_ASSERT_RETURN(value >= 8,);
  612. shandle.engineOptions.audioBufferSize = static_cast<uint>(value);
  613. break;
  614. case CB::ENGINE_OPTION_AUDIO_SAMPLE_RATE:
  615. CARLA_SAFE_ASSERT_RETURN(value >= 22050,);
  616. shandle.engineOptions.audioSampleRate = static_cast<uint>(value);
  617. break;
  618. case CB::ENGINE_OPTION_AUDIO_TRIPLE_BUFFER:
  619. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  620. shandle.engineOptions.audioTripleBuffer = (value != 0);
  621. break;
  622. case CB::ENGINE_OPTION_AUDIO_DRIVER:
  623. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr,);
  624. if (shandle.engineOptions.audioDriver != nullptr)
  625. delete[] shandle.engineOptions.audioDriver;
  626. shandle.engineOptions.audioDriver = carla_strdup_safe(valueStr);
  627. break;
  628. case CB::ENGINE_OPTION_AUDIO_DEVICE:
  629. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr,);
  630. if (shandle.engineOptions.audioDevice != nullptr)
  631. delete[] shandle.engineOptions.audioDevice;
  632. shandle.engineOptions.audioDevice = carla_strdup_safe(valueStr);
  633. break;
  634. #ifndef BUILD_BRIDGE
  635. case CB::ENGINE_OPTION_OSC_ENABLED:
  636. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  637. shandle.engineOptions.oscEnabled = (value != 0);
  638. break;
  639. case CB::ENGINE_OPTION_OSC_PORT_TCP:
  640. CARLA_SAFE_ASSERT_RETURN(value <= 0 || value >= 1024,);
  641. shandle.engineOptions.oscPortTCP = value;
  642. break;
  643. case CB::ENGINE_OPTION_OSC_PORT_UDP:
  644. CARLA_SAFE_ASSERT_RETURN(value <= 0 || value >= 1024,);
  645. shandle.engineOptions.oscPortUDP = value;
  646. break;
  647. #endif
  648. case CB::ENGINE_OPTION_FILE_PATH:
  649. CARLA_SAFE_ASSERT_RETURN(value > CB::FILE_NONE,);
  650. CARLA_SAFE_ASSERT_RETURN(value <= CB::FILE_MIDI,);
  651. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr,);
  652. switch (value)
  653. {
  654. case CB::FILE_AUDIO:
  655. if (shandle.engineOptions.pathAudio != nullptr)
  656. delete[] shandle.engineOptions.pathAudio;
  657. shandle.engineOptions.pathAudio = carla_strdup_safe(valueStr);
  658. break;
  659. case CB::FILE_MIDI:
  660. if (shandle.engineOptions.pathMIDI != nullptr)
  661. delete[] shandle.engineOptions.pathMIDI;
  662. shandle.engineOptions.pathMIDI = carla_strdup_safe(valueStr);
  663. break;
  664. }
  665. break;
  666. case CB::ENGINE_OPTION_PLUGIN_PATH:
  667. CARLA_SAFE_ASSERT_RETURN(value > CB::PLUGIN_NONE,);
  668. CARLA_SAFE_ASSERT_RETURN(value <= CB::PLUGIN_JSFX,);
  669. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr,);
  670. switch (value)
  671. {
  672. case CB::PLUGIN_LADSPA:
  673. if (shandle.engineOptions.pathLADSPA != nullptr)
  674. delete[] shandle.engineOptions.pathLADSPA;
  675. shandle.engineOptions.pathLADSPA = carla_strdup_safe(valueStr);
  676. break;
  677. case CB::PLUGIN_DSSI:
  678. if (shandle.engineOptions.pathDSSI != nullptr)
  679. delete[] shandle.engineOptions.pathDSSI;
  680. shandle.engineOptions.pathDSSI = carla_strdup_safe(valueStr);
  681. break;
  682. case CB::PLUGIN_LV2:
  683. if (shandle.engineOptions.pathLV2 != nullptr)
  684. delete[] shandle.engineOptions.pathLV2;
  685. shandle.engineOptions.pathLV2 = carla_strdup_safe(valueStr);
  686. break;
  687. case CB::PLUGIN_VST2:
  688. if (shandle.engineOptions.pathVST2 != nullptr)
  689. delete[] shandle.engineOptions.pathVST2;
  690. shandle.engineOptions.pathVST2 = carla_strdup_safe(valueStr);
  691. break;
  692. case CB::PLUGIN_VST3:
  693. if (shandle.engineOptions.pathVST3 != nullptr)
  694. delete[] shandle.engineOptions.pathVST3;
  695. shandle.engineOptions.pathVST3 = carla_strdup_safe(valueStr);
  696. break;
  697. case CB::PLUGIN_SF2:
  698. if (shandle.engineOptions.pathSF2 != nullptr)
  699. delete[] shandle.engineOptions.pathSF2;
  700. shandle.engineOptions.pathSF2 = carla_strdup_safe(valueStr);
  701. break;
  702. case CB::PLUGIN_SFZ:
  703. if (shandle.engineOptions.pathSFZ != nullptr)
  704. delete[] shandle.engineOptions.pathSFZ;
  705. shandle.engineOptions.pathSFZ = carla_strdup_safe(valueStr);
  706. break;
  707. case CB::PLUGIN_JSFX:
  708. if (shandle.engineOptions.pathJSFX != nullptr)
  709. delete[] shandle.engineOptions.pathJSFX;
  710. shandle.engineOptions.pathJSFX = carla_strdup_safe(valueStr);
  711. break;
  712. }
  713. break;
  714. case CB::ENGINE_OPTION_PATH_BINARIES:
  715. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  716. if (shandle.engineOptions.binaryDir != nullptr)
  717. delete[] shandle.engineOptions.binaryDir;
  718. shandle.engineOptions.binaryDir = carla_strdup_safe(valueStr);
  719. break;
  720. case CB::ENGINE_OPTION_PATH_RESOURCES:
  721. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  722. if (shandle.engineOptions.resourceDir != nullptr)
  723. delete[] shandle.engineOptions.resourceDir;
  724. shandle.engineOptions.resourceDir = carla_strdup_safe(valueStr);
  725. break;
  726. case CB::ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR:
  727. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  728. shandle.engineOptions.preventBadBehaviour = (value != 0);
  729. break;
  730. case CB::ENGINE_OPTION_FRONTEND_BACKGROUND_COLOR:
  731. shandle.engineOptions.bgColor = static_cast<uint>(value);
  732. break;
  733. case CB::ENGINE_OPTION_FRONTEND_FOREGROUND_COLOR:
  734. shandle.engineOptions.fgColor = static_cast<uint>(value);
  735. break;
  736. case CB::ENGINE_OPTION_FRONTEND_UI_SCALE:
  737. CARLA_SAFE_ASSERT_RETURN(value > 0,);
  738. shandle.engineOptions.uiScale = static_cast<float>(value) / 1000;
  739. break;
  740. case CB::ENGINE_OPTION_FRONTEND_WIN_ID: {
  741. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  742. const long long winId(std::strtoll(valueStr, nullptr, 16));
  743. CARLA_SAFE_ASSERT_RETURN(winId >= 0,);
  744. shandle.engineOptions.frontendWinId = static_cast<uintptr_t>(winId);
  745. } break;
  746. #if !defined(BUILD_BRIDGE_ALTERNATIVE_ARCH) && !defined(CARLA_OS_WIN)
  747. case CB::ENGINE_OPTION_WINE_EXECUTABLE:
  748. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  749. if (shandle.engineOptions.wine.executable != nullptr)
  750. delete[] shandle.engineOptions.wine.executable;
  751. shandle.engineOptions.wine.executable = carla_strdup_safe(valueStr);
  752. break;
  753. case CB::ENGINE_OPTION_WINE_AUTO_PREFIX:
  754. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  755. shandle.engineOptions.wine.autoPrefix = (value != 0);
  756. break;
  757. case CB::ENGINE_OPTION_WINE_FALLBACK_PREFIX:
  758. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  759. if (shandle.engineOptions.wine.fallbackPrefix != nullptr)
  760. delete[] shandle.engineOptions.wine.fallbackPrefix;
  761. shandle.engineOptions.wine.fallbackPrefix = carla_strdup_safe(valueStr);
  762. break;
  763. case CB::ENGINE_OPTION_WINE_RT_PRIO_ENABLED:
  764. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  765. shandle.engineOptions.wine.rtPrio = (value != 0);
  766. break;
  767. case CB::ENGINE_OPTION_WINE_BASE_RT_PRIO:
  768. CARLA_SAFE_ASSERT_RETURN(value >= 1 && value <= 89,);
  769. shandle.engineOptions.wine.baseRtPrio = value;
  770. break;
  771. case CB::ENGINE_OPTION_WINE_SERVER_RT_PRIO:
  772. CARLA_SAFE_ASSERT_RETURN(value >= 1 && value <= 99,);
  773. shandle.engineOptions.wine.serverRtPrio = value;
  774. break;
  775. #endif
  776. #ifndef BUILD_BRIDGE
  777. case CB::ENGINE_OPTION_DEBUG_CONSOLE_OUTPUT:
  778. shandle.logThreadEnabled = (value != 0);
  779. break;
  780. #endif
  781. case CB::ENGINE_OPTION_CLIENT_NAME_PREFIX:
  782. if (shandle.engineOptions.clientNamePrefix != nullptr)
  783. delete[] shandle.engineOptions.clientNamePrefix;
  784. shandle.engineOptions.clientNamePrefix = valueStr != nullptr && valueStr[0] != '\0'
  785. ? carla_strdup_safe(valueStr)
  786. : nullptr;
  787. break;
  788. case CB::ENGINE_OPTION_PLUGINS_ARE_STANDALONE:
  789. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  790. shandle.engineOptions.pluginsAreStandalone = (value != 0);
  791. break;
  792. }
  793. }
  794. if (handle->engine != nullptr)
  795. handle->engine->setOption(option, value, valueStr);
  796. }
  797. void carla_set_file_callback(CarlaHostHandle handle, FileCallbackFunc func, void* ptr)
  798. {
  799. carla_debug("carla_set_file_callback(%p, %p, %p)", handle, func, ptr);
  800. if (handle->isStandalone)
  801. {
  802. CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
  803. shandle.fileCallback = func;
  804. shandle.fileCallbackPtr = ptr;
  805. }
  806. if (handle->engine != nullptr)
  807. handle->engine->setFileCallback(func, ptr);
  808. }
  809. // --------------------------------------------------------------------------------------------------------------------
  810. bool carla_load_file(CarlaHostHandle handle, const char* filename)
  811. {
  812. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  813. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  814. carla_debug("carla_load_file(%p, \"%s\")", handle, filename);
  815. return handle->engine->loadFile(filename);
  816. }
  817. bool carla_load_project(CarlaHostHandle handle, const char* filename)
  818. {
  819. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  820. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  821. carla_debug("carla_load_project(%p, \"%s\")", handle, filename);
  822. return handle->engine->loadProject(filename, true);
  823. }
  824. bool carla_save_project(CarlaHostHandle handle, const char* filename)
  825. {
  826. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  827. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  828. carla_debug("carla_save_project(%p, \"%s\")", handle, filename);
  829. return handle->engine->saveProject(filename, true);
  830. }
  831. #ifndef BUILD_BRIDGE
  832. const char* carla_get_current_project_folder(CarlaHostHandle handle)
  833. {
  834. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  835. carla_debug("carla_get_current_project_folder(%p)", handle);
  836. if (const char* const ret = handle->engine->getCurrentProjectFolder())
  837. return ret;
  838. return gNullCharPtr;
  839. }
  840. const char* carla_get_current_project_filename(CarlaHostHandle handle)
  841. {
  842. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->isStandalone, gNullCharPtr);
  843. carla_debug("carla_get_current_project_filename(%p)", handle);
  844. if (const char* const ret = handle->engine->getCurrentProjectFilename())
  845. return ret;
  846. return gNullCharPtr;
  847. }
  848. void carla_clear_project_filename(CarlaHostHandle handle)
  849. {
  850. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  851. carla_debug("carla_clear_project_filename(%p)", handle);
  852. handle->engine->clearCurrentProjectFilename();
  853. }
  854. // --------------------------------------------------------------------------------------------------------------------
  855. bool carla_patchbay_connect(CarlaHostHandle handle, bool external, uint groupIdA, uint portIdA, uint groupIdB, uint portIdB)
  856. {
  857. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  858. carla_debug("carla_patchbay_connect(%p, %s, %u, %u, %u, %u)",
  859. handle, bool2str(external), groupIdA, portIdA, groupIdB, portIdB);
  860. return handle->engine->patchbayConnect(external, groupIdA, portIdA, groupIdB, portIdB);
  861. }
  862. bool carla_patchbay_disconnect(CarlaHostHandle handle, bool external, uint connectionId)
  863. {
  864. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  865. carla_debug("carla_patchbay_disconnect(%p, %s, %i)", handle, bool2str(external), connectionId);
  866. return handle->engine->patchbayDisconnect(external, connectionId);
  867. }
  868. bool carla_patchbay_set_group_pos(CarlaHostHandle handle, bool external, uint groupId, int x1, int y1, int x2, int y2)
  869. {
  870. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr && handle->engine->isRunning(),
  871. "Engine is not running", false);
  872. carla_debug("carla_patchbay_set_group_pos(%p, %s, %u, %i, %i, %i, %i)",
  873. handle, bool2str(external), groupId, x1, y1, x2, y2);
  874. if (handle->engine->isAboutToClose())
  875. return true;
  876. return handle->engine->patchbaySetGroupPos(false, true, external, groupId, x1, y1, x2, y2);
  877. }
  878. bool carla_patchbay_refresh(CarlaHostHandle handle, bool external)
  879. {
  880. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  881. carla_debug("carla_patchbay_refresh(%p, %s)", handle, bool2str(external));
  882. return handle->engine->patchbayRefresh(true, false, external);
  883. }
  884. // --------------------------------------------------------------------------------------------------------------------
  885. void carla_transport_play(CarlaHostHandle handle)
  886. {
  887. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(),);
  888. carla_debug("carla_transport_play(%p)", handle);
  889. handle->engine->transportPlay();
  890. }
  891. void carla_transport_pause(CarlaHostHandle handle)
  892. {
  893. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(),);
  894. carla_debug("carla_transport_pause(%p)", handle);
  895. handle->engine->transportPause();
  896. }
  897. void carla_transport_bpm(CarlaHostHandle handle, double bpm)
  898. {
  899. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(),);
  900. carla_debug("carla_transport_bpm(%p, %f)", handle, bpm);
  901. handle->engine->transportBPM(bpm);
  902. }
  903. void carla_transport_relocate(CarlaHostHandle handle, uint64_t frame)
  904. {
  905. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(),);
  906. carla_debug("carla_transport_relocate(%p, %i)", handle, frame);
  907. handle->engine->transportRelocate(frame);
  908. }
  909. uint64_t carla_get_current_transport_frame(CarlaHostHandle handle)
  910. {
  911. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(), 0);
  912. return handle->engine->getTimeInfo().frame;
  913. }
  914. const CarlaTransportInfo* carla_get_transport_info(CarlaHostHandle handle)
  915. {
  916. static CarlaTransportInfo retTransInfo;
  917. retTransInfo.clear();
  918. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(), &retTransInfo);
  919. const CB::EngineTimeInfo& timeInfo(handle->engine->getTimeInfo());
  920. retTransInfo.playing = timeInfo.playing;
  921. retTransInfo.frame = timeInfo.frame;
  922. if (timeInfo.bbt.valid)
  923. {
  924. retTransInfo.bar = timeInfo.bbt.bar;
  925. retTransInfo.beat = timeInfo.bbt.beat;
  926. retTransInfo.tick = static_cast<int32_t>(timeInfo.bbt.tick + 0.5);
  927. retTransInfo.bpm = timeInfo.bbt.beatsPerMinute;
  928. }
  929. return &retTransInfo;
  930. }
  931. #endif
  932. // --------------------------------------------------------------------------------------------------------------------
  933. uint32_t carla_get_current_plugin_count(CarlaHostHandle handle)
  934. {
  935. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  936. carla_debug("carla_get_current_plugin_count(%p)", handle);
  937. return handle->engine->getCurrentPluginCount();
  938. }
  939. uint32_t carla_get_max_plugin_number(CarlaHostHandle handle)
  940. {
  941. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  942. carla_debug("carla_get_max_plugin_number(%p)", handle);
  943. return handle->engine->getMaxPluginNumber();
  944. }
  945. // --------------------------------------------------------------------------------------------------------------------
  946. bool carla_add_plugin(CarlaHostHandle handle,
  947. BinaryType btype, PluginType ptype,
  948. const char* filename, const char* name, const char* label, int64_t uniqueId,
  949. const void* extraPtr, uint options)
  950. {
  951. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  952. carla_debug("carla_add_plugin(%p, %i:%s, %i:%s, \"%s\", \"%s\", \"%s\", " P_INT64 ", %p, %u)",
  953. handle,
  954. btype, CB::BinaryType2Str(btype),
  955. ptype, CB::PluginType2Str(ptype),
  956. filename, name, label, uniqueId, extraPtr, options);
  957. return handle->engine->addPlugin(btype, ptype, filename, name, label, uniqueId, extraPtr, options);
  958. }
  959. bool carla_remove_plugin(CarlaHostHandle handle, uint pluginId)
  960. {
  961. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  962. carla_debug("carla_remove_plugin(%p, %i)", handle, pluginId);
  963. return handle->engine->removePlugin(pluginId);
  964. }
  965. bool carla_remove_all_plugins(CarlaHostHandle handle)
  966. {
  967. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  968. carla_debug("carla_remove_all_plugins(%p)", handle);
  969. return handle->engine->removeAllPlugins();
  970. }
  971. #ifndef BUILD_BRIDGE
  972. bool carla_rename_plugin(CarlaHostHandle handle, uint pluginId, const char* newName)
  973. {
  974. CARLA_SAFE_ASSERT_RETURN(newName != nullptr && newName[0] != '\0', false);
  975. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  976. carla_debug("carla_rename_plugin(%p, %i, \"%s\")", handle, pluginId, newName);
  977. return handle->engine->renamePlugin(pluginId, newName);
  978. }
  979. bool carla_clone_plugin(CarlaHostHandle handle, uint pluginId)
  980. {
  981. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  982. carla_debug("carla_clone_plugin(%p, %i)", handle, pluginId);
  983. return handle->engine->clonePlugin(pluginId);
  984. }
  985. bool carla_replace_plugin(CarlaHostHandle handle, uint pluginId)
  986. {
  987. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  988. carla_debug("carla_replace_plugin(%p, %i)", handle, pluginId);
  989. return handle->engine->replacePlugin(pluginId);
  990. }
  991. bool carla_switch_plugins(CarlaHostHandle handle, uint pluginIdA, uint pluginIdB)
  992. {
  993. CARLA_SAFE_ASSERT_RETURN(pluginIdA != pluginIdB, false);
  994. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  995. carla_debug("carla_switch_plugins(%p, %i, %i)", handle, pluginIdA, pluginIdB);
  996. return handle->engine->switchPlugins(pluginIdA, pluginIdB);
  997. }
  998. #endif
  999. // --------------------------------------------------------------------------------------------------------------------
  1000. bool carla_load_plugin_state(CarlaHostHandle handle, uint pluginId, const char* filename)
  1001. {
  1002. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  1003. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr
  1004. && handle->engine->isRunning(), "Engine is not running", false);
  1005. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1006. return plugin->loadStateFromFile(filename);
  1007. return false;
  1008. }
  1009. bool carla_save_plugin_state(CarlaHostHandle handle, uint pluginId, const char* filename)
  1010. {
  1011. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  1012. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  1013. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1014. return plugin->saveStateToFile(filename);
  1015. return false;
  1016. }
  1017. bool carla_export_plugin_lv2(CarlaHostHandle handle, uint pluginId, const char* lv2path)
  1018. {
  1019. CARLA_SAFE_ASSERT_RETURN(lv2path != nullptr && lv2path[0] != '\0', false);
  1020. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  1021. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1022. return plugin->exportAsLV2(lv2path);
  1023. return false;
  1024. }
  1025. // --------------------------------------------------------------------------------------------------------------------
  1026. const CarlaPluginInfo* carla_get_plugin_info(CarlaHostHandle handle, uint pluginId)
  1027. {
  1028. static CarlaPluginInfo retInfo;
  1029. // reset
  1030. retInfo.type = CB::PLUGIN_NONE;
  1031. retInfo.category = CB::PLUGIN_CATEGORY_NONE;
  1032. retInfo.hints = 0x0;
  1033. retInfo.optionsAvailable = 0x0;
  1034. retInfo.optionsEnabled = 0x0;
  1035. retInfo.filename = gNullCharPtr;
  1036. retInfo.name = gNullCharPtr;
  1037. retInfo.iconName = gNullCharPtr;
  1038. retInfo.uniqueId = 0;
  1039. // cleanup
  1040. if (retInfo.label != gNullCharPtr)
  1041. {
  1042. delete[] retInfo.label;
  1043. retInfo.label = gNullCharPtr;
  1044. }
  1045. if (retInfo.maker != gNullCharPtr)
  1046. {
  1047. delete[] retInfo.maker;
  1048. retInfo.maker = gNullCharPtr;
  1049. }
  1050. if (retInfo.copyright != gNullCharPtr)
  1051. {
  1052. delete[] retInfo.copyright;
  1053. retInfo.copyright = gNullCharPtr;
  1054. }
  1055. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
  1056. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1057. {
  1058. char strBuf[STR_MAX+1];
  1059. carla_zeroChars(strBuf, STR_MAX+1);
  1060. retInfo.type = plugin->getType();
  1061. retInfo.category = plugin->getCategory();
  1062. retInfo.hints = plugin->getHints();
  1063. retInfo.filename = plugin->getFilename();
  1064. retInfo.name = plugin->getName();
  1065. retInfo.iconName = plugin->getIconName();
  1066. retInfo.uniqueId = plugin->getUniqueId();
  1067. retInfo.optionsAvailable = plugin->getOptionsAvailable();
  1068. retInfo.optionsEnabled = plugin->getOptionsEnabled();
  1069. if (plugin->getLabel(strBuf))
  1070. retInfo.label = carla_strdup_safe(strBuf);
  1071. if (plugin->getMaker(strBuf))
  1072. retInfo.maker = carla_strdup_safe(strBuf);
  1073. if (plugin->getCopyright(strBuf))
  1074. retInfo.copyright = carla_strdup_safe(strBuf);
  1075. checkStringPtr(retInfo.filename);
  1076. checkStringPtr(retInfo.name);
  1077. checkStringPtr(retInfo.iconName);
  1078. checkStringPtr(retInfo.label);
  1079. checkStringPtr(retInfo.maker);
  1080. checkStringPtr(retInfo.copyright);
  1081. }
  1082. return &retInfo;
  1083. }
  1084. const CarlaPortCountInfo* carla_get_audio_port_count_info(CarlaHostHandle handle, uint pluginId)
  1085. {
  1086. static CarlaPortCountInfo retInfo;
  1087. carla_zeroStruct(retInfo);
  1088. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
  1089. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1090. {
  1091. retInfo.ins = plugin->getAudioInCount();
  1092. retInfo.outs = plugin->getAudioOutCount();
  1093. }
  1094. return &retInfo;
  1095. }
  1096. const CarlaPortCountInfo* carla_get_midi_port_count_info(CarlaHostHandle handle, uint pluginId)
  1097. {
  1098. static CarlaPortCountInfo retInfo;
  1099. carla_zeroStruct(retInfo);
  1100. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
  1101. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1102. {
  1103. retInfo.ins = plugin->getMidiInCount();
  1104. retInfo.outs = plugin->getMidiOutCount();
  1105. }
  1106. return &retInfo;
  1107. }
  1108. const CarlaPortCountInfo* carla_get_parameter_count_info(CarlaHostHandle handle, uint pluginId)
  1109. {
  1110. static CarlaPortCountInfo retInfo;
  1111. carla_zeroStruct(retInfo);
  1112. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
  1113. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1114. plugin->getParameterCountInfo(retInfo.ins, retInfo.outs);
  1115. return &retInfo;
  1116. }
  1117. const CarlaParameterInfo* carla_get_parameter_info(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1118. {
  1119. static CarlaParameterInfo retInfo;
  1120. // reset
  1121. retInfo.scalePointCount = 0;
  1122. // cleanup
  1123. if (retInfo.name != gNullCharPtr)
  1124. {
  1125. delete[] retInfo.name;
  1126. retInfo.name = gNullCharPtr;
  1127. }
  1128. if (retInfo.symbol != gNullCharPtr)
  1129. {
  1130. delete[] retInfo.symbol;
  1131. retInfo.symbol = gNullCharPtr;
  1132. }
  1133. if (retInfo.unit != gNullCharPtr)
  1134. {
  1135. delete[] retInfo.unit;
  1136. retInfo.unit = gNullCharPtr;
  1137. }
  1138. if (retInfo.comment != gNullCharPtr)
  1139. {
  1140. delete[] retInfo.comment;
  1141. retInfo.comment = gNullCharPtr;
  1142. }
  1143. if (retInfo.groupName != gNullCharPtr)
  1144. {
  1145. delete[] retInfo.groupName;
  1146. retInfo.groupName = gNullCharPtr;
  1147. }
  1148. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
  1149. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1150. {
  1151. char strBuf[STR_MAX+1];
  1152. carla_zeroChars(strBuf, STR_MAX+1);
  1153. retInfo.scalePointCount = plugin->getParameterScalePointCount(parameterId);
  1154. if (plugin->getParameterName(parameterId, strBuf))
  1155. {
  1156. retInfo.name = carla_strdup_safe(strBuf);
  1157. carla_zeroChars(strBuf, STR_MAX+1);
  1158. }
  1159. if (plugin->getParameterSymbol(parameterId, strBuf))
  1160. {
  1161. retInfo.symbol = carla_strdup_safe(strBuf);
  1162. carla_zeroChars(strBuf, STR_MAX+1);
  1163. }
  1164. if (plugin->getParameterUnit(parameterId, strBuf))
  1165. {
  1166. retInfo.unit = carla_strdup_safe(strBuf);
  1167. carla_zeroChars(strBuf, STR_MAX+1);
  1168. }
  1169. if (plugin->getParameterComment(parameterId, strBuf))
  1170. {
  1171. retInfo.comment = carla_strdup_safe(strBuf);
  1172. carla_zeroChars(strBuf, STR_MAX+1);
  1173. }
  1174. if (plugin->getParameterGroupName(parameterId, strBuf))
  1175. {
  1176. retInfo.groupName = carla_strdup_safe(strBuf);
  1177. carla_zeroChars(strBuf, STR_MAX+1);
  1178. }
  1179. checkStringPtr(retInfo.name);
  1180. checkStringPtr(retInfo.symbol);
  1181. checkStringPtr(retInfo.unit);
  1182. checkStringPtr(retInfo.comment);
  1183. checkStringPtr(retInfo.groupName);
  1184. }
  1185. return &retInfo;
  1186. }
  1187. const CarlaScalePointInfo* carla_get_parameter_scalepoint_info(CarlaHostHandle handle,
  1188. uint pluginId,
  1189. uint32_t parameterId,
  1190. uint32_t scalePointId)
  1191. {
  1192. CARLA_ASSERT(handle->engine != nullptr);
  1193. static CarlaScalePointInfo retInfo;
  1194. // reset
  1195. retInfo.value = 0.0f;
  1196. // cleanup
  1197. if (retInfo.label != gNullCharPtr)
  1198. {
  1199. delete[] retInfo.label;
  1200. retInfo.label = gNullCharPtr;
  1201. }
  1202. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
  1203. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1204. {
  1205. char strBuf[STR_MAX+1];
  1206. retInfo.value = plugin->getParameterScalePointValue(parameterId, scalePointId);
  1207. carla_zeroChars(strBuf, STR_MAX+1);
  1208. if (plugin->getParameterScalePointLabel(parameterId, scalePointId, strBuf))
  1209. retInfo.label = carla_strdup_safe(strBuf);
  1210. checkStringPtr(retInfo.label);
  1211. }
  1212. return &retInfo;
  1213. }
  1214. // --------------------------------------------------------------------------------------------------------------------
  1215. uint carla_get_audio_port_hints(CarlaHostHandle handle, uint pluginId, bool isOutput, uint32_t portIndex)
  1216. {
  1217. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0x0);
  1218. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1219. {
  1220. CARLA_SAFE_ASSERT_RETURN(portIndex < (isOutput ? plugin->getAudioOutCount() : plugin->getAudioInCount()), 0x0);
  1221. return plugin->getAudioPortHints(isOutput, portIndex);
  1222. }
  1223. return 0x0;
  1224. }
  1225. // --------------------------------------------------------------------------------------------------------------------
  1226. const ParameterData* carla_get_parameter_data(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1227. {
  1228. static ParameterData retParamData;
  1229. // reset
  1230. retParamData.type = CB::PARAMETER_UNKNOWN;
  1231. retParamData.hints = 0x0;
  1232. retParamData.index = CB::PARAMETER_NULL;
  1233. retParamData.rindex = -1;
  1234. retParamData.midiChannel = 0;
  1235. retParamData.mappedControlIndex = CB::CONTROL_INDEX_NONE;
  1236. retParamData.mappedMinimum = 0.0f;
  1237. retParamData.mappedMaximum = 0.0f;
  1238. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retParamData);
  1239. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1240. {
  1241. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), &retParamData);
  1242. const ParameterData& pluginParamData(plugin->getParameterData(parameterId));
  1243. retParamData.type = pluginParamData.type;
  1244. retParamData.hints = pluginParamData.hints;
  1245. retParamData.index = pluginParamData.index;
  1246. retParamData.rindex = pluginParamData.rindex;
  1247. retParamData.midiChannel = pluginParamData.midiChannel;
  1248. retParamData.mappedControlIndex = pluginParamData.mappedControlIndex;
  1249. retParamData.mappedMinimum = pluginParamData.mappedMinimum;
  1250. retParamData.mappedMaximum = pluginParamData.mappedMaximum;
  1251. }
  1252. return &retParamData;
  1253. }
  1254. const ParameterRanges* carla_get_parameter_ranges(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1255. {
  1256. static ParameterRanges retParamRanges;
  1257. // reset
  1258. retParamRanges.def = 0.0f;
  1259. retParamRanges.min = 0.0f;
  1260. retParamRanges.max = 1.0f;
  1261. retParamRanges.step = 0.01f;
  1262. retParamRanges.stepSmall = 0.0001f;
  1263. retParamRanges.stepLarge = 0.1f;
  1264. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retParamRanges);
  1265. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1266. {
  1267. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), &retParamRanges);
  1268. const ParameterRanges& pluginParamRanges(plugin->getParameterRanges(parameterId));
  1269. retParamRanges.def = pluginParamRanges.def;
  1270. retParamRanges.min = pluginParamRanges.min;
  1271. retParamRanges.max = pluginParamRanges.max;
  1272. retParamRanges.step = pluginParamRanges.step;
  1273. retParamRanges.stepSmall = pluginParamRanges.stepSmall;
  1274. retParamRanges.stepLarge = pluginParamRanges.stepLarge;
  1275. }
  1276. return &retParamRanges;
  1277. }
  1278. const MidiProgramData* carla_get_midi_program_data(CarlaHostHandle handle, uint pluginId, uint32_t midiProgramId)
  1279. {
  1280. static MidiProgramData retMidiProgData = { 0, 0, gNullCharPtr };
  1281. // reset
  1282. retMidiProgData.bank = 0;
  1283. retMidiProgData.program = 0;
  1284. if (retMidiProgData.name != gNullCharPtr)
  1285. {
  1286. delete[] retMidiProgData.name;
  1287. retMidiProgData.name = gNullCharPtr;
  1288. }
  1289. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retMidiProgData);
  1290. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1291. {
  1292. CARLA_SAFE_ASSERT_RETURN(midiProgramId < plugin->getMidiProgramCount(), &retMidiProgData);
  1293. const MidiProgramData& pluginMidiProgData(plugin->getMidiProgramData(midiProgramId));
  1294. retMidiProgData.bank = pluginMidiProgData.bank;
  1295. retMidiProgData.program = pluginMidiProgData.program;
  1296. if (pluginMidiProgData.name != nullptr)
  1297. {
  1298. retMidiProgData.name = carla_strdup_safe(pluginMidiProgData.name);
  1299. checkStringPtr(retMidiProgData.name);
  1300. }
  1301. else
  1302. {
  1303. retMidiProgData.name = gNullCharPtr;
  1304. }
  1305. }
  1306. return &retMidiProgData;
  1307. }
  1308. const CustomData* carla_get_custom_data(CarlaHostHandle handle, uint pluginId, uint32_t customDataId)
  1309. {
  1310. static CustomData retCustomData = { gNullCharPtr, gNullCharPtr, gNullCharPtr };
  1311. // reset
  1312. if (retCustomData.type != gNullCharPtr)
  1313. {
  1314. delete[] retCustomData.type;
  1315. retCustomData.type = gNullCharPtr;
  1316. }
  1317. if (retCustomData.key != gNullCharPtr)
  1318. {
  1319. delete[] retCustomData.key;
  1320. retCustomData.key = gNullCharPtr;
  1321. }
  1322. if (retCustomData.value != gNullCharPtr)
  1323. {
  1324. delete[] retCustomData.value;
  1325. retCustomData.value = gNullCharPtr;
  1326. }
  1327. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retCustomData);
  1328. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1329. {
  1330. CARLA_SAFE_ASSERT_RETURN(customDataId < plugin->getCustomDataCount(), &retCustomData)
  1331. const CustomData& pluginCustomData(plugin->getCustomData(customDataId));
  1332. retCustomData.type = carla_strdup_safe(pluginCustomData.type);
  1333. retCustomData.key = carla_strdup_safe(pluginCustomData.key);
  1334. retCustomData.value = carla_strdup_safe(pluginCustomData.value);
  1335. checkStringPtr(retCustomData.type);
  1336. checkStringPtr(retCustomData.key);
  1337. checkStringPtr(retCustomData.value);
  1338. }
  1339. return &retCustomData;
  1340. }
  1341. const char* carla_get_custom_data_value(CarlaHostHandle handle, uint pluginId, const char* type, const char* key)
  1342. {
  1343. CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0', gNullCharPtr);
  1344. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0', gNullCharPtr);
  1345. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  1346. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1347. {
  1348. const uint32_t count = plugin->getCustomDataCount();
  1349. if (count == 0)
  1350. return gNullCharPtr;
  1351. static CarlaString customDataValue;
  1352. for (uint32_t i=0; i<count; ++i)
  1353. {
  1354. const CustomData& pluginCustomData(plugin->getCustomData(i));
  1355. if (std::strcmp(pluginCustomData.type, type) != 0)
  1356. continue;
  1357. if (std::strcmp(pluginCustomData.key, key) != 0)
  1358. continue;
  1359. customDataValue = pluginCustomData.value;
  1360. return customDataValue.buffer();
  1361. }
  1362. }
  1363. return gNullCharPtr;
  1364. }
  1365. const char* carla_get_chunk_data(CarlaHostHandle handle, uint pluginId)
  1366. {
  1367. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  1368. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1369. {
  1370. CARLA_SAFE_ASSERT_RETURN(plugin->getOptionsEnabled() & CB::PLUGIN_OPTION_USE_CHUNKS, gNullCharPtr);
  1371. void* data = nullptr;
  1372. const std::size_t dataSize(plugin->getChunkData(&data));
  1373. CARLA_SAFE_ASSERT_RETURN(data != nullptr && dataSize > 0, gNullCharPtr);
  1374. static CarlaString chunkData;
  1375. chunkData = CarlaString::asBase64(data, static_cast<std::size_t>(dataSize));
  1376. return chunkData.buffer();
  1377. }
  1378. return gNullCharPtr;
  1379. }
  1380. // --------------------------------------------------------------------------------------------------------------------
  1381. uint32_t carla_get_parameter_count(CarlaHostHandle handle, uint pluginId)
  1382. {
  1383. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1384. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1385. return plugin->getParameterCount();
  1386. return 0;
  1387. }
  1388. uint32_t carla_get_program_count(CarlaHostHandle handle, uint pluginId)
  1389. {
  1390. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1391. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1392. return plugin->getProgramCount();
  1393. return 0;
  1394. }
  1395. uint32_t carla_get_midi_program_count(CarlaHostHandle handle, uint pluginId)
  1396. {
  1397. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1398. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1399. return plugin->getMidiProgramCount();
  1400. return 0;
  1401. }
  1402. uint32_t carla_get_custom_data_count(CarlaHostHandle handle, uint pluginId)
  1403. {
  1404. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1405. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1406. return plugin->getCustomDataCount();
  1407. return 0;
  1408. }
  1409. // --------------------------------------------------------------------------------------------------------------------
  1410. const char* carla_get_parameter_text(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1411. {
  1412. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  1413. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1414. {
  1415. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), gNullCharPtr);
  1416. static char textBuf[STR_MAX+1];
  1417. carla_zeroChars(textBuf, STR_MAX+1);
  1418. if (! plugin->getParameterText(parameterId, textBuf))
  1419. textBuf[0] = '\0';
  1420. return textBuf;
  1421. }
  1422. return gNullCharPtr;
  1423. }
  1424. const char* carla_get_program_name(CarlaHostHandle handle, uint pluginId, uint32_t programId)
  1425. {
  1426. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, nullptr);
  1427. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1428. {
  1429. CARLA_SAFE_ASSERT_RETURN(programId < plugin->getProgramCount(), gNullCharPtr);
  1430. static char programName[STR_MAX+1];
  1431. carla_zeroChars(programName, STR_MAX+1);
  1432. if (! plugin->getProgramName(programId, programName))
  1433. programName[0] = '\0';
  1434. return programName;
  1435. }
  1436. return gNullCharPtr;
  1437. }
  1438. const char* carla_get_midi_program_name(CarlaHostHandle handle, uint pluginId, uint32_t midiProgramId)
  1439. {
  1440. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  1441. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1442. {
  1443. CARLA_SAFE_ASSERT_RETURN(midiProgramId < plugin->getMidiProgramCount(), gNullCharPtr);
  1444. static char midiProgramName[STR_MAX+1];
  1445. carla_zeroChars(midiProgramName, STR_MAX+1);
  1446. if (! plugin->getMidiProgramName(midiProgramId, midiProgramName))
  1447. midiProgramName[0] = '\0';
  1448. return midiProgramName;
  1449. }
  1450. return gNullCharPtr;
  1451. }
  1452. const char* carla_get_real_plugin_name(CarlaHostHandle handle, uint pluginId)
  1453. {
  1454. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  1455. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1456. {
  1457. static char realPluginName[STR_MAX+1];
  1458. carla_zeroChars(realPluginName, STR_MAX+1);
  1459. if (! plugin->getRealName(realPluginName))
  1460. realPluginName[0] = '\0';
  1461. return realPluginName;
  1462. }
  1463. return gNullCharPtr;
  1464. }
  1465. // --------------------------------------------------------------------------------------------------------------------
  1466. int32_t carla_get_current_program_index(CarlaHostHandle handle, uint pluginId)
  1467. {
  1468. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, -1);
  1469. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1470. return plugin->getCurrentProgram();
  1471. return -1;
  1472. }
  1473. int32_t carla_get_current_midi_program_index(CarlaHostHandle handle, uint pluginId)
  1474. {
  1475. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, -1);
  1476. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1477. return plugin->getCurrentMidiProgram();
  1478. return -1;
  1479. }
  1480. // --------------------------------------------------------------------------------------------------------------------
  1481. float carla_get_default_parameter_value(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1482. {
  1483. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
  1484. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1485. {
  1486. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), 0.0f);
  1487. return plugin->getParameterRanges(parameterId).def;
  1488. }
  1489. return 0.0f;
  1490. }
  1491. float carla_get_current_parameter_value(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1492. {
  1493. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
  1494. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1495. {
  1496. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), 0.0f);
  1497. return plugin->getParameterValue(parameterId);
  1498. }
  1499. return 0.0f;
  1500. }
  1501. float carla_get_internal_parameter_value(CarlaHostHandle handle, uint pluginId, int32_t parameterId)
  1502. {
  1503. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1504. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, (parameterId == CB::PARAMETER_CTRL_CHANNEL) ? -1.0f : 0.0f);
  1505. #else
  1506. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
  1507. #endif
  1508. CARLA_SAFE_ASSERT_RETURN(parameterId != CB::PARAMETER_NULL && parameterId > CB::PARAMETER_MAX, 0.0f);
  1509. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1510. return plugin->getInternalParameterValue(parameterId);
  1511. return 0.0f;
  1512. }
  1513. // --------------------------------------------------------------------------------------------------------------------
  1514. uint32_t carla_get_plugin_latency(CarlaHostHandle handle, uint pluginId)
  1515. {
  1516. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1517. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1518. return plugin->getLatencyInFrames();
  1519. return 0;
  1520. }
  1521. // --------------------------------------------------------------------------------------------------------------------
  1522. const float* carla_get_peak_values(CarlaHostHandle handle, uint pluginId)
  1523. {
  1524. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, nullptr);
  1525. return handle->engine->getPeaks(pluginId);
  1526. }
  1527. float carla_get_input_peak_value(CarlaHostHandle handle, uint pluginId, bool isLeft)
  1528. {
  1529. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
  1530. return handle->engine->getInputPeak(pluginId, isLeft);
  1531. }
  1532. float carla_get_output_peak_value(CarlaHostHandle handle, uint pluginId, bool isLeft)
  1533. {
  1534. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
  1535. return handle->engine->getOutputPeak(pluginId, isLeft);
  1536. }
  1537. // --------------------------------------------------------------------------------------------------------------------
  1538. CARLA_BACKEND_START_NAMESPACE
  1539. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1540. // defined in CarlaPluginInternal.cpp
  1541. const void* carla_render_inline_display_internal(const CarlaPluginPtr& plugin, uint32_t width, uint32_t height);
  1542. #endif
  1543. // defined in CarlaPluginLV2.cpp
  1544. const void* carla_render_inline_display_lv2(const CarlaPluginPtr& plugin, uint32_t width, uint32_t height);
  1545. CARLA_BACKEND_END_NAMESPACE
  1546. const CarlaInlineDisplayImageSurface* carla_render_inline_display(CarlaHostHandle handle,
  1547. uint pluginId,
  1548. uint32_t width, uint32_t height)
  1549. {
  1550. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(), nullptr);
  1551. if (handle->engine->isAboutToClose())
  1552. return nullptr;
  1553. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1554. {
  1555. switch (plugin->getType())
  1556. {
  1557. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1558. case CB::PLUGIN_INTERNAL:
  1559. return (const CarlaInlineDisplayImageSurface*)CB::carla_render_inline_display_internal(plugin, width, height);
  1560. #endif
  1561. case CB::PLUGIN_LV2:
  1562. return (const CarlaInlineDisplayImageSurface*)CB::carla_render_inline_display_lv2(plugin, width, height);
  1563. default:
  1564. return nullptr;
  1565. }
  1566. }
  1567. return nullptr;
  1568. }
  1569. // --------------------------------------------------------------------------------------------------------------------
  1570. void carla_set_active(CarlaHostHandle handle, uint pluginId, bool onOff)
  1571. {
  1572. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1573. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1574. plugin->setActive(onOff, true, false);
  1575. }
  1576. #ifndef BUILD_BRIDGE
  1577. void carla_set_drywet(CarlaHostHandle handle, uint pluginId, float value)
  1578. {
  1579. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1580. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1581. plugin->setDryWet(value, true, false);
  1582. }
  1583. void carla_set_volume(CarlaHostHandle handle, uint pluginId, float value)
  1584. {
  1585. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1586. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1587. plugin->setVolume(value, true, false);
  1588. }
  1589. void carla_set_balance_left(CarlaHostHandle handle, uint pluginId, float value)
  1590. {
  1591. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1592. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1593. plugin->setBalanceLeft(value, true, false);
  1594. }
  1595. void carla_set_balance_right(CarlaHostHandle handle, uint pluginId, float value)
  1596. {
  1597. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1598. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1599. plugin->setBalanceRight(value, true, false);
  1600. }
  1601. void carla_set_panning(CarlaHostHandle handle, uint pluginId, float value)
  1602. {
  1603. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1604. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1605. plugin->setPanning(value, true, false);
  1606. }
  1607. void carla_set_ctrl_channel(CarlaHostHandle handle, uint pluginId, int8_t channel)
  1608. {
  1609. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1610. CARLA_SAFE_ASSERT_RETURN(channel >= -1 && channel < MAX_MIDI_CHANNELS,);
  1611. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1612. plugin->setCtrlChannel(channel, true, false);
  1613. }
  1614. #endif
  1615. void carla_set_option(CarlaHostHandle handle, uint pluginId, uint option, bool yesNo)
  1616. {
  1617. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1618. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1619. plugin->setOption(option, yesNo, false);
  1620. }
  1621. // --------------------------------------------------------------------------------------------------------------------
  1622. void carla_set_parameter_value(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, float value)
  1623. {
  1624. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1625. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1626. {
  1627. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(),);
  1628. plugin->setParameterValue(parameterId, value, true, true, false);
  1629. }
  1630. }
  1631. #ifndef BUILD_BRIDGE
  1632. void carla_set_parameter_midi_channel(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, uint8_t channel)
  1633. {
  1634. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1635. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  1636. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1637. {
  1638. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(),);
  1639. plugin->setParameterMidiChannel(parameterId, channel, true, false);
  1640. }
  1641. }
  1642. void carla_set_parameter_mapped_control_index(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, int16_t index)
  1643. {
  1644. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1645. CARLA_SAFE_ASSERT_RETURN(index >= CB::CONTROL_INDEX_NONE && index <= CB::CONTROL_INDEX_MAX_ALLOWED,);
  1646. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1647. {
  1648. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(),);
  1649. plugin->setParameterMappedControlIndex(parameterId, index, true, false, true);
  1650. }
  1651. }
  1652. void carla_set_parameter_mapped_range(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, float minimum, float maximum)
  1653. {
  1654. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1655. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1656. {
  1657. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(),);
  1658. plugin->setParameterMappedRange(parameterId, minimum, maximum, true, false);
  1659. }
  1660. }
  1661. void carla_set_parameter_touch(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, bool touch)
  1662. {
  1663. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1664. carla_debug("carla_set_parameter_touch(%p, %i, %i, %s)", handle, pluginId, parameterId, bool2str(touch));
  1665. return handle->engine->touchPluginParameter(pluginId, parameterId, touch);
  1666. }
  1667. #endif
  1668. // --------------------------------------------------------------------------------------------------------------------
  1669. void carla_set_program(CarlaHostHandle handle, uint pluginId, uint32_t programId)
  1670. {
  1671. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1672. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1673. {
  1674. CARLA_SAFE_ASSERT_RETURN(programId < plugin->getProgramCount(),);
  1675. plugin->setProgram(static_cast<int32_t>(programId), true, true, false);
  1676. }
  1677. }
  1678. void carla_set_midi_program(CarlaHostHandle handle, uint pluginId, uint32_t midiProgramId)
  1679. {
  1680. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1681. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1682. {
  1683. CARLA_SAFE_ASSERT_RETURN(midiProgramId < plugin->getMidiProgramCount(),);
  1684. plugin->setMidiProgram(static_cast<int32_t>(midiProgramId), true, true, false);
  1685. }
  1686. }
  1687. // --------------------------------------------------------------------------------------------------------------------
  1688. void carla_set_custom_data(CarlaHostHandle handle, uint pluginId, const char* type, const char* key, const char* value)
  1689. {
  1690. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1691. CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0',);
  1692. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
  1693. CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
  1694. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1695. plugin->setCustomData(type, key, value, true);
  1696. }
  1697. void carla_set_chunk_data(CarlaHostHandle handle, uint pluginId, const char* chunkData)
  1698. {
  1699. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1700. CARLA_SAFE_ASSERT_RETURN(chunkData != nullptr && chunkData[0] != '\0',);
  1701. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1702. {
  1703. CARLA_SAFE_ASSERT_RETURN(plugin->getOptionsEnabled() & CB::PLUGIN_OPTION_USE_CHUNKS,);
  1704. std::vector<uint8_t> chunk(carla_getChunkFromBase64String(chunkData));
  1705. #ifdef CARLA_PROPER_CPP11_SUPPORT
  1706. plugin->setChunkData(chunk.data(), chunk.size());
  1707. #else
  1708. plugin->setChunkData(&chunk.front(), chunk.size());
  1709. #endif
  1710. }
  1711. }
  1712. // --------------------------------------------------------------------------------------------------------------------
  1713. void carla_prepare_for_save(CarlaHostHandle handle, uint pluginId)
  1714. {
  1715. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1716. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1717. plugin->prepareForSave(false);
  1718. }
  1719. void carla_reset_parameters(CarlaHostHandle handle, uint pluginId)
  1720. {
  1721. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1722. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1723. plugin->resetParameters();
  1724. }
  1725. void carla_randomize_parameters(CarlaHostHandle handle, uint pluginId)
  1726. {
  1727. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1728. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1729. plugin->randomizeParameters();
  1730. }
  1731. #ifndef BUILD_BRIDGE
  1732. void carla_send_midi_note(CarlaHostHandle handle, uint pluginId, uint8_t channel, uint8_t note, uint8_t velocity)
  1733. {
  1734. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(),);
  1735. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1736. plugin->sendMidiSingleNote(channel, note, velocity, true, true, false);
  1737. }
  1738. #endif
  1739. void carla_set_custom_ui_title(CarlaHostHandle handle, uint pluginId, const char* title)
  1740. {
  1741. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1742. CARLA_SAFE_ASSERT_RETURN(title != nullptr,);
  1743. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1744. plugin->setCustomUITitle(title);
  1745. }
  1746. void carla_show_custom_ui(CarlaHostHandle handle, uint pluginId, bool yesNo)
  1747. {
  1748. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1749. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1750. plugin->showCustomUI(yesNo);
  1751. }
  1752. void* carla_embed_custom_ui(CarlaHostHandle handle, uint pluginId, void* ptr)
  1753. {
  1754. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, nullptr);
  1755. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1756. return plugin->embedCustomUI(ptr);
  1757. return nullptr;
  1758. }
  1759. // --------------------------------------------------------------------------------------------------------------------
  1760. uint32_t carla_get_buffer_size(CarlaHostHandle handle)
  1761. {
  1762. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1763. carla_debug("carla_get_buffer_size(%p)", handle);
  1764. return handle->engine->getBufferSize();
  1765. }
  1766. double carla_get_sample_rate(CarlaHostHandle handle)
  1767. {
  1768. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0);
  1769. carla_debug("carla_get_sample_rate(%p)", handle);
  1770. return handle->engine->getSampleRate();
  1771. }
  1772. // --------------------------------------------------------------------------------------------------------------------
  1773. const char* carla_get_last_error(CarlaHostHandle handle)
  1774. {
  1775. carla_debug("carla_get_last_error(%p)", handle);
  1776. if (handle->engine != nullptr)
  1777. return handle->engine->getLastError();
  1778. return handle->isStandalone
  1779. ? ((CarlaHostStandalone*)handle)->lastError.buffer()
  1780. : gNullCharPtr;
  1781. }
  1782. const char* carla_get_host_osc_url_tcp(CarlaHostHandle handle)
  1783. {
  1784. carla_debug("carla_get_host_osc_url_tcp(%p)", handle);
  1785. #if defined(HAVE_LIBLO) && !defined(BUILD_BRIDGE)
  1786. if (handle->engine == nullptr)
  1787. {
  1788. carla_stderr2("carla_get_host_osc_url_tcp() failed, engine is not running");
  1789. if (handle->isStandalone)
  1790. ((CarlaHostStandalone*)handle)->lastError = "Engine is not running";
  1791. return gNullCharPtr;
  1792. }
  1793. const char* const path = handle->engine->getOscServerPathTCP();
  1794. if (path != nullptr && path[0] != '\0')
  1795. return path;
  1796. static const char* const notAvailable = "(OSC TCP port not available)";
  1797. return notAvailable;
  1798. #else
  1799. return "(OSC support not available in this build)";
  1800. // unused
  1801. (void)handle;
  1802. #endif
  1803. }
  1804. const char* carla_get_host_osc_url_udp(CarlaHostHandle handle)
  1805. {
  1806. carla_debug("carla_get_host_osc_url_udp(%p)", handle);
  1807. #if defined(HAVE_LIBLO) && !defined(BUILD_BRIDGE)
  1808. if (handle->engine == nullptr)
  1809. {
  1810. carla_stderr2("carla_get_host_osc_url_udp() failed, engine is not running");
  1811. if (handle->isStandalone)
  1812. ((CarlaHostStandalone*)handle)->lastError = "Engine is not running";
  1813. return gNullCharPtr;
  1814. }
  1815. const char* const path = handle->engine->getOscServerPathUDP();
  1816. if (path != nullptr && path[0] != '\0')
  1817. return path;
  1818. static const char* const notAvailable = "(OSC UDP port not available)";
  1819. return notAvailable;
  1820. #else
  1821. return "(OSC support not available in this build)";
  1822. // unused
  1823. (void)handle;
  1824. #endif
  1825. }
  1826. // --------------------------------------------------------------------------------------------------------------------
  1827. #ifndef CARLA_PLUGIN_BUILD
  1828. # define CARLA_PLUGIN_UI_CLASS_PREFIX Standalone
  1829. # include "CarlaPluginUI.cpp"
  1830. # undef CARLA_PLUGIN_UI_CLASS_PREFIX
  1831. # include "CarlaDssiUtils.cpp"
  1832. # include "CarlaMacUtils.cpp"
  1833. # include "CarlaPatchbayUtils.cpp"
  1834. # include "CarlaPipeUtils.cpp"
  1835. # include "CarlaProcessUtils.cpp"
  1836. # include "CarlaStateUtils.cpp"
  1837. # include "utils/Information.cpp"
  1838. # include "utils/Windows.cpp"
  1839. #endif /* CARLA_PLUGIN_BUILD */
  1840. // --------------------------------------------------------------------------------------------------------------------