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.

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