Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2410 lines
86KB

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