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.

2421 lines
86KB

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