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.

2398 lines
86KB

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