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.

2401 lines
86KB

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