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.

2431 lines
87KB

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