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.

2405 lines
86KB

  1. /*
  2. * Carla Standalone
  3. * Copyright (C) 2011-2021 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 CarlaBackend::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. const ParameterData* carla_get_parameter_data(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1226. {
  1227. static ParameterData retParamData;
  1228. // reset
  1229. retParamData.type = CB::PARAMETER_UNKNOWN;
  1230. retParamData.hints = 0x0;
  1231. retParamData.index = CB::PARAMETER_NULL;
  1232. retParamData.rindex = -1;
  1233. retParamData.midiChannel = 0;
  1234. retParamData.mappedControlIndex = CB::CONTROL_INDEX_NONE;
  1235. retParamData.mappedMinimum = 0.0f;
  1236. retParamData.mappedMaximum = 0.0f;
  1237. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retParamData);
  1238. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1239. {
  1240. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), &retParamData);
  1241. const ParameterData& pluginParamData(plugin->getParameterData(parameterId));
  1242. retParamData.type = pluginParamData.type;
  1243. retParamData.hints = pluginParamData.hints;
  1244. retParamData.index = pluginParamData.index;
  1245. retParamData.rindex = pluginParamData.rindex;
  1246. retParamData.midiChannel = pluginParamData.midiChannel;
  1247. retParamData.mappedControlIndex = pluginParamData.mappedControlIndex;
  1248. retParamData.mappedMinimum = pluginParamData.mappedMinimum;
  1249. retParamData.mappedMaximum = pluginParamData.mappedMaximum;
  1250. }
  1251. return &retParamData;
  1252. }
  1253. const ParameterRanges* carla_get_parameter_ranges(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1254. {
  1255. static ParameterRanges retParamRanges;
  1256. // reset
  1257. retParamRanges.def = 0.0f;
  1258. retParamRanges.min = 0.0f;
  1259. retParamRanges.max = 1.0f;
  1260. retParamRanges.step = 0.01f;
  1261. retParamRanges.stepSmall = 0.0001f;
  1262. retParamRanges.stepLarge = 0.1f;
  1263. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retParamRanges);
  1264. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1265. {
  1266. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), &retParamRanges);
  1267. const ParameterRanges& pluginParamRanges(plugin->getParameterRanges(parameterId));
  1268. retParamRanges.def = pluginParamRanges.def;
  1269. retParamRanges.min = pluginParamRanges.min;
  1270. retParamRanges.max = pluginParamRanges.max;
  1271. retParamRanges.step = pluginParamRanges.step;
  1272. retParamRanges.stepSmall = pluginParamRanges.stepSmall;
  1273. retParamRanges.stepLarge = pluginParamRanges.stepLarge;
  1274. }
  1275. return &retParamRanges;
  1276. }
  1277. const MidiProgramData* carla_get_midi_program_data(CarlaHostHandle handle, uint pluginId, uint32_t midiProgramId)
  1278. {
  1279. static MidiProgramData retMidiProgData = { 0, 0, gNullCharPtr };
  1280. // reset
  1281. retMidiProgData.bank = 0;
  1282. retMidiProgData.program = 0;
  1283. if (retMidiProgData.name != gNullCharPtr)
  1284. {
  1285. delete[] retMidiProgData.name;
  1286. retMidiProgData.name = gNullCharPtr;
  1287. }
  1288. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retMidiProgData);
  1289. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1290. {
  1291. CARLA_SAFE_ASSERT_RETURN(midiProgramId < plugin->getMidiProgramCount(), &retMidiProgData);
  1292. const MidiProgramData& pluginMidiProgData(plugin->getMidiProgramData(midiProgramId));
  1293. retMidiProgData.bank = pluginMidiProgData.bank;
  1294. retMidiProgData.program = pluginMidiProgData.program;
  1295. if (pluginMidiProgData.name != nullptr)
  1296. {
  1297. retMidiProgData.name = carla_strdup_safe(pluginMidiProgData.name);
  1298. checkStringPtr(retMidiProgData.name);
  1299. }
  1300. else
  1301. {
  1302. retMidiProgData.name = gNullCharPtr;
  1303. }
  1304. }
  1305. return &retMidiProgData;
  1306. }
  1307. const CustomData* carla_get_custom_data(CarlaHostHandle handle, uint pluginId, uint32_t customDataId)
  1308. {
  1309. static CustomData retCustomData = { gNullCharPtr, gNullCharPtr, gNullCharPtr };
  1310. // reset
  1311. if (retCustomData.type != gNullCharPtr)
  1312. {
  1313. delete[] retCustomData.type;
  1314. retCustomData.type = gNullCharPtr;
  1315. }
  1316. if (retCustomData.key != gNullCharPtr)
  1317. {
  1318. delete[] retCustomData.key;
  1319. retCustomData.key = gNullCharPtr;
  1320. }
  1321. if (retCustomData.value != gNullCharPtr)
  1322. {
  1323. delete[] retCustomData.value;
  1324. retCustomData.value = gNullCharPtr;
  1325. }
  1326. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retCustomData);
  1327. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1328. {
  1329. CARLA_SAFE_ASSERT_RETURN(customDataId < plugin->getCustomDataCount(), &retCustomData)
  1330. const CustomData& pluginCustomData(plugin->getCustomData(customDataId));
  1331. retCustomData.type = carla_strdup_safe(pluginCustomData.type);
  1332. retCustomData.key = carla_strdup_safe(pluginCustomData.key);
  1333. retCustomData.value = carla_strdup_safe(pluginCustomData.value);
  1334. checkStringPtr(retCustomData.type);
  1335. checkStringPtr(retCustomData.key);
  1336. checkStringPtr(retCustomData.value);
  1337. }
  1338. return &retCustomData;
  1339. }
  1340. const char* carla_get_custom_data_value(CarlaHostHandle handle, uint pluginId, const char* type, const char* key)
  1341. {
  1342. CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0', gNullCharPtr);
  1343. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0', gNullCharPtr);
  1344. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  1345. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1346. {
  1347. const uint32_t count = plugin->getCustomDataCount();
  1348. if (count == 0)
  1349. return gNullCharPtr;
  1350. static CarlaString customDataValue;
  1351. for (uint32_t i=0; i<count; ++i)
  1352. {
  1353. const CustomData& pluginCustomData(plugin->getCustomData(i));
  1354. if (std::strcmp(pluginCustomData.type, type) != 0)
  1355. continue;
  1356. if (std::strcmp(pluginCustomData.key, key) != 0)
  1357. continue;
  1358. customDataValue = pluginCustomData.value;
  1359. return customDataValue.buffer();
  1360. }
  1361. }
  1362. return gNullCharPtr;
  1363. }
  1364. const char* carla_get_chunk_data(CarlaHostHandle handle, uint pluginId)
  1365. {
  1366. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  1367. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1368. {
  1369. CARLA_SAFE_ASSERT_RETURN(plugin->getOptionsEnabled() & CB::PLUGIN_OPTION_USE_CHUNKS, gNullCharPtr);
  1370. void* data = nullptr;
  1371. const std::size_t dataSize(plugin->getChunkData(&data));
  1372. CARLA_SAFE_ASSERT_RETURN(data != nullptr && dataSize > 0, gNullCharPtr);
  1373. static CarlaString chunkData;
  1374. chunkData = CarlaString::asBase64(data, static_cast<std::size_t>(dataSize));
  1375. return chunkData.buffer();
  1376. }
  1377. return gNullCharPtr;
  1378. }
  1379. // --------------------------------------------------------------------------------------------------------------------
  1380. uint32_t carla_get_parameter_count(CarlaHostHandle handle, uint pluginId)
  1381. {
  1382. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1383. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1384. return plugin->getParameterCount();
  1385. return 0;
  1386. }
  1387. uint32_t carla_get_program_count(CarlaHostHandle handle, uint pluginId)
  1388. {
  1389. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1390. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1391. return plugin->getProgramCount();
  1392. return 0;
  1393. }
  1394. uint32_t carla_get_midi_program_count(CarlaHostHandle handle, uint pluginId)
  1395. {
  1396. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1397. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1398. return plugin->getMidiProgramCount();
  1399. return 0;
  1400. }
  1401. uint32_t carla_get_custom_data_count(CarlaHostHandle handle, uint pluginId)
  1402. {
  1403. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1404. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1405. return plugin->getCustomDataCount();
  1406. return 0;
  1407. }
  1408. // --------------------------------------------------------------------------------------------------------------------
  1409. const char* carla_get_parameter_text(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1410. {
  1411. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  1412. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1413. {
  1414. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), gNullCharPtr);
  1415. static char textBuf[STR_MAX+1];
  1416. carla_zeroChars(textBuf, STR_MAX+1);
  1417. if (! plugin->getParameterText(parameterId, textBuf))
  1418. textBuf[0] = '\0';
  1419. return textBuf;
  1420. }
  1421. return gNullCharPtr;
  1422. }
  1423. const char* carla_get_program_name(CarlaHostHandle handle, uint pluginId, uint32_t programId)
  1424. {
  1425. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, nullptr);
  1426. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1427. {
  1428. CARLA_SAFE_ASSERT_RETURN(programId < plugin->getProgramCount(), gNullCharPtr);
  1429. static char programName[STR_MAX+1];
  1430. carla_zeroChars(programName, STR_MAX+1);
  1431. if (! plugin->getProgramName(programId, programName))
  1432. programName[0] = '\0';
  1433. return programName;
  1434. }
  1435. return gNullCharPtr;
  1436. }
  1437. const char* carla_get_midi_program_name(CarlaHostHandle handle, uint pluginId, uint32_t midiProgramId)
  1438. {
  1439. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  1440. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1441. {
  1442. CARLA_SAFE_ASSERT_RETURN(midiProgramId < plugin->getMidiProgramCount(), gNullCharPtr);
  1443. static char midiProgramName[STR_MAX+1];
  1444. carla_zeroChars(midiProgramName, STR_MAX+1);
  1445. if (! plugin->getMidiProgramName(midiProgramId, midiProgramName))
  1446. midiProgramName[0] = '\0';
  1447. return midiProgramName;
  1448. }
  1449. return gNullCharPtr;
  1450. }
  1451. const char* carla_get_real_plugin_name(CarlaHostHandle handle, uint pluginId)
  1452. {
  1453. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  1454. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1455. {
  1456. static char realPluginName[STR_MAX+1];
  1457. carla_zeroChars(realPluginName, STR_MAX+1);
  1458. if (! plugin->getRealName(realPluginName))
  1459. realPluginName[0] = '\0';
  1460. return realPluginName;
  1461. }
  1462. return gNullCharPtr;
  1463. }
  1464. // --------------------------------------------------------------------------------------------------------------------
  1465. int32_t carla_get_current_program_index(CarlaHostHandle handle, uint pluginId)
  1466. {
  1467. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, -1);
  1468. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1469. return plugin->getCurrentProgram();
  1470. return -1;
  1471. }
  1472. int32_t carla_get_current_midi_program_index(CarlaHostHandle handle, uint pluginId)
  1473. {
  1474. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, -1);
  1475. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1476. return plugin->getCurrentMidiProgram();
  1477. return -1;
  1478. }
  1479. // --------------------------------------------------------------------------------------------------------------------
  1480. float carla_get_default_parameter_value(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1481. {
  1482. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
  1483. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1484. {
  1485. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), 0.0f);
  1486. return plugin->getParameterRanges(parameterId).def;
  1487. }
  1488. return 0.0f;
  1489. }
  1490. float carla_get_current_parameter_value(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1491. {
  1492. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
  1493. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1494. {
  1495. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), 0.0f);
  1496. return plugin->getParameterValue(parameterId);
  1497. }
  1498. return 0.0f;
  1499. }
  1500. float carla_get_internal_parameter_value(CarlaHostHandle handle, uint pluginId, int32_t parameterId)
  1501. {
  1502. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1503. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, (parameterId == CB::PARAMETER_CTRL_CHANNEL) ? -1.0f : 0.0f);
  1504. #else
  1505. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
  1506. #endif
  1507. CARLA_SAFE_ASSERT_RETURN(parameterId != CB::PARAMETER_NULL && parameterId > CB::PARAMETER_MAX, 0.0f);
  1508. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1509. return plugin->getInternalParameterValue(parameterId);
  1510. return 0.0f;
  1511. }
  1512. // --------------------------------------------------------------------------------------------------------------------
  1513. uint32_t carla_get_plugin_latency(CarlaHostHandle handle, uint pluginId)
  1514. {
  1515. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1516. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1517. return plugin->getLatencyInFrames();
  1518. return 0;
  1519. }
  1520. // --------------------------------------------------------------------------------------------------------------------
  1521. const float* carla_get_peak_values(CarlaHostHandle handle, uint pluginId)
  1522. {
  1523. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, nullptr);
  1524. return handle->engine->getPeaks(pluginId);
  1525. }
  1526. float carla_get_input_peak_value(CarlaHostHandle handle, uint pluginId, bool isLeft)
  1527. {
  1528. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
  1529. return handle->engine->getInputPeak(pluginId, isLeft);
  1530. }
  1531. float carla_get_output_peak_value(CarlaHostHandle handle, uint pluginId, bool isLeft)
  1532. {
  1533. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
  1534. return handle->engine->getOutputPeak(pluginId, isLeft);
  1535. }
  1536. // --------------------------------------------------------------------------------------------------------------------
  1537. CARLA_BACKEND_START_NAMESPACE
  1538. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1539. // defined in CarlaPluginInternal.cpp
  1540. const void* carla_render_inline_display_internal(const CarlaPluginPtr& plugin, uint32_t width, uint32_t height);
  1541. #endif
  1542. // defined in CarlaPluginLV2.cpp
  1543. const void* carla_render_inline_display_lv2(const CarlaPluginPtr& plugin, uint32_t width, uint32_t height);
  1544. CARLA_BACKEND_END_NAMESPACE
  1545. const CarlaInlineDisplayImageSurface* carla_render_inline_display(CarlaHostHandle handle,
  1546. uint pluginId,
  1547. uint32_t width, uint32_t height)
  1548. {
  1549. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(), nullptr);
  1550. if (handle->engine->isAboutToClose())
  1551. return nullptr;
  1552. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1553. {
  1554. switch (plugin->getType())
  1555. {
  1556. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1557. case CB::PLUGIN_INTERNAL:
  1558. return (const CarlaInlineDisplayImageSurface*)CB::carla_render_inline_display_internal(plugin, width, height);
  1559. #endif
  1560. case CB::PLUGIN_LV2:
  1561. return (const CarlaInlineDisplayImageSurface*)CB::carla_render_inline_display_lv2(plugin, width, height);
  1562. default:
  1563. return nullptr;
  1564. }
  1565. }
  1566. return nullptr;
  1567. }
  1568. // --------------------------------------------------------------------------------------------------------------------
  1569. void carla_set_active(CarlaHostHandle handle, uint pluginId, bool onOff)
  1570. {
  1571. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1572. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1573. plugin->setActive(onOff, true, false);
  1574. }
  1575. #ifndef BUILD_BRIDGE
  1576. void carla_set_drywet(CarlaHostHandle handle, uint pluginId, float value)
  1577. {
  1578. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1579. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1580. plugin->setDryWet(value, true, false);
  1581. }
  1582. void carla_set_volume(CarlaHostHandle handle, uint pluginId, float value)
  1583. {
  1584. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1585. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1586. plugin->setVolume(value, true, false);
  1587. }
  1588. void carla_set_balance_left(CarlaHostHandle handle, uint pluginId, float value)
  1589. {
  1590. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1591. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1592. plugin->setBalanceLeft(value, true, false);
  1593. }
  1594. void carla_set_balance_right(CarlaHostHandle handle, uint pluginId, float value)
  1595. {
  1596. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1597. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1598. plugin->setBalanceRight(value, true, false);
  1599. }
  1600. void carla_set_panning(CarlaHostHandle handle, uint pluginId, float value)
  1601. {
  1602. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1603. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1604. plugin->setPanning(value, true, false);
  1605. }
  1606. void carla_set_ctrl_channel(CarlaHostHandle handle, uint pluginId, int8_t channel)
  1607. {
  1608. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1609. CARLA_SAFE_ASSERT_RETURN(channel >= -1 && channel < MAX_MIDI_CHANNELS,);
  1610. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1611. plugin->setCtrlChannel(channel, true, false);
  1612. }
  1613. #endif
  1614. void carla_set_option(CarlaHostHandle handle, uint pluginId, uint option, bool yesNo)
  1615. {
  1616. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1617. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1618. plugin->setOption(option, yesNo, false);
  1619. }
  1620. // --------------------------------------------------------------------------------------------------------------------
  1621. void carla_set_parameter_value(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, float value)
  1622. {
  1623. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1624. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1625. {
  1626. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(),);
  1627. plugin->setParameterValue(parameterId, value, true, true, false);
  1628. }
  1629. }
  1630. #ifndef BUILD_BRIDGE
  1631. void carla_set_parameter_midi_channel(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, uint8_t channel)
  1632. {
  1633. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1634. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  1635. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1636. {
  1637. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(),);
  1638. plugin->setParameterMidiChannel(parameterId, channel, true, false);
  1639. }
  1640. }
  1641. void carla_set_parameter_mapped_control_index(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, int16_t index)
  1642. {
  1643. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1644. CARLA_SAFE_ASSERT_RETURN(index >= CB::CONTROL_INDEX_NONE && index <= CB::CONTROL_INDEX_MAX_ALLOWED,);
  1645. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1646. {
  1647. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(),);
  1648. plugin->setParameterMappedControlIndex(parameterId, index, true, false, true);
  1649. }
  1650. }
  1651. void carla_set_parameter_mapped_range(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, float minimum, float maximum)
  1652. {
  1653. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1654. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1655. {
  1656. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(),);
  1657. plugin->setParameterMappedRange(parameterId, minimum, maximum, true, false);
  1658. }
  1659. }
  1660. void carla_set_parameter_touch(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, bool touch)
  1661. {
  1662. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1663. carla_debug("carla_set_parameter_touch(%p, %i, %i, %s)", handle, pluginId, parameterId, bool2str(touch));
  1664. return handle->engine->touchPluginParameter(pluginId, parameterId, touch);
  1665. }
  1666. #endif
  1667. // --------------------------------------------------------------------------------------------------------------------
  1668. void carla_set_program(CarlaHostHandle handle, uint pluginId, uint32_t programId)
  1669. {
  1670. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1671. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1672. {
  1673. CARLA_SAFE_ASSERT_RETURN(programId < plugin->getProgramCount(),);
  1674. plugin->setProgram(static_cast<int32_t>(programId), true, true, false);
  1675. }
  1676. }
  1677. void carla_set_midi_program(CarlaHostHandle handle, uint pluginId, uint32_t midiProgramId)
  1678. {
  1679. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1680. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1681. {
  1682. CARLA_SAFE_ASSERT_RETURN(midiProgramId < plugin->getMidiProgramCount(),);
  1683. plugin->setMidiProgram(static_cast<int32_t>(midiProgramId), true, true, false);
  1684. }
  1685. }
  1686. // --------------------------------------------------------------------------------------------------------------------
  1687. void carla_set_custom_data(CarlaHostHandle handle, uint pluginId, const char* type, const char* key, const char* value)
  1688. {
  1689. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1690. CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0',);
  1691. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
  1692. CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
  1693. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1694. plugin->setCustomData(type, key, value, true);
  1695. }
  1696. void carla_set_chunk_data(CarlaHostHandle handle, uint pluginId, const char* chunkData)
  1697. {
  1698. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1699. CARLA_SAFE_ASSERT_RETURN(chunkData != nullptr && chunkData[0] != '\0',);
  1700. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1701. {
  1702. CARLA_SAFE_ASSERT_RETURN(plugin->getOptionsEnabled() & CB::PLUGIN_OPTION_USE_CHUNKS,);
  1703. std::vector<uint8_t> chunk(carla_getChunkFromBase64String(chunkData));
  1704. #ifdef CARLA_PROPER_CPP11_SUPPORT
  1705. plugin->setChunkData(chunk.data(), chunk.size());
  1706. #else
  1707. plugin->setChunkData(&chunk.front(), chunk.size());
  1708. #endif
  1709. }
  1710. }
  1711. // --------------------------------------------------------------------------------------------------------------------
  1712. void carla_prepare_for_save(CarlaHostHandle handle, uint pluginId)
  1713. {
  1714. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1715. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1716. plugin->prepareForSave(false);
  1717. }
  1718. void carla_reset_parameters(CarlaHostHandle handle, uint pluginId)
  1719. {
  1720. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1721. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1722. plugin->resetParameters();
  1723. }
  1724. void carla_randomize_parameters(CarlaHostHandle handle, uint pluginId)
  1725. {
  1726. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1727. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1728. plugin->randomizeParameters();
  1729. }
  1730. #ifndef BUILD_BRIDGE
  1731. void carla_send_midi_note(CarlaHostHandle handle, uint pluginId, uint8_t channel, uint8_t note, uint8_t velocity)
  1732. {
  1733. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(),);
  1734. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1735. plugin->sendMidiSingleNote(channel, note, velocity, true, true, false);
  1736. }
  1737. #endif
  1738. void carla_set_custom_ui_title(CarlaHostHandle handle, uint pluginId, const char* title)
  1739. {
  1740. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1741. CARLA_SAFE_ASSERT_RETURN(title != nullptr,);
  1742. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1743. plugin->setCustomUITitle(title);
  1744. }
  1745. void carla_show_custom_ui(CarlaHostHandle handle, uint pluginId, bool yesNo)
  1746. {
  1747. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1748. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1749. plugin->showCustomUI(yesNo);
  1750. }
  1751. void* carla_embed_custom_ui(CarlaHostHandle handle, uint pluginId, void* ptr)
  1752. {
  1753. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, nullptr);
  1754. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1755. return plugin->embedCustomUI(ptr);
  1756. return nullptr;
  1757. }
  1758. // --------------------------------------------------------------------------------------------------------------------
  1759. uint32_t carla_get_buffer_size(CarlaHostHandle handle)
  1760. {
  1761. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1762. carla_debug("carla_get_buffer_size(%p)", handle);
  1763. return handle->engine->getBufferSize();
  1764. }
  1765. double carla_get_sample_rate(CarlaHostHandle handle)
  1766. {
  1767. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0);
  1768. carla_debug("carla_get_sample_rate(%p)", handle);
  1769. return handle->engine->getSampleRate();
  1770. }
  1771. // --------------------------------------------------------------------------------------------------------------------
  1772. const char* carla_get_last_error(CarlaHostHandle handle)
  1773. {
  1774. carla_debug("carla_get_last_error(%p)", handle);
  1775. if (handle->engine != nullptr)
  1776. return handle->engine->getLastError();
  1777. return handle->isStandalone
  1778. ? ((CarlaHostStandalone*)handle)->lastError.buffer()
  1779. : gNullCharPtr;
  1780. }
  1781. const char* carla_get_host_osc_url_tcp(CarlaHostHandle handle)
  1782. {
  1783. carla_debug("carla_get_host_osc_url_tcp(%p)", handle);
  1784. #if defined(HAVE_LIBLO) && !defined(BUILD_BRIDGE)
  1785. if (handle->engine == nullptr)
  1786. {
  1787. carla_stderr2("carla_get_host_osc_url_tcp() failed, engine is not running");
  1788. if (handle->isStandalone)
  1789. ((CarlaHostStandalone*)handle)->lastError = "Engine is not running";
  1790. return gNullCharPtr;
  1791. }
  1792. const char* const path = handle->engine->getOscServerPathTCP();
  1793. if (path != nullptr && path[0] != '\0')
  1794. return path;
  1795. static const char* const notAvailable = "(OSC TCP port not available)";
  1796. return notAvailable;
  1797. #else
  1798. return "(OSC support not available in this build)";
  1799. // unused
  1800. (void)handle;
  1801. #endif
  1802. }
  1803. const char* carla_get_host_osc_url_udp(CarlaHostHandle handle)
  1804. {
  1805. carla_debug("carla_get_host_osc_url_udp(%p)", handle);
  1806. #if defined(HAVE_LIBLO) && !defined(BUILD_BRIDGE)
  1807. if (handle->engine == nullptr)
  1808. {
  1809. carla_stderr2("carla_get_host_osc_url_udp() failed, engine is not running");
  1810. if (handle->isStandalone)
  1811. ((CarlaHostStandalone*)handle)->lastError = "Engine is not running";
  1812. return gNullCharPtr;
  1813. }
  1814. const char* const path = handle->engine->getOscServerPathUDP();
  1815. if (path != nullptr && path[0] != '\0')
  1816. return path;
  1817. static const char* const notAvailable = "(OSC UDP port not available)";
  1818. return notAvailable;
  1819. #else
  1820. return "(OSC support not available in this build)";
  1821. // unused
  1822. (void)handle;
  1823. #endif
  1824. }
  1825. // --------------------------------------------------------------------------------------------------------------------
  1826. #ifndef CARLA_PLUGIN_EXPORT
  1827. # define CARLA_PLUGIN_UI_CLASS_PREFIX Standalone
  1828. # include "CarlaPluginUI.cpp"
  1829. # undef CARLA_PLUGIN_UI_CLASS_PREFIX
  1830. # include "CarlaDssiUtils.cpp"
  1831. # include "CarlaMacUtils.cpp"
  1832. # include "CarlaPatchbayUtils.cpp"
  1833. # include "CarlaPipeUtils.cpp"
  1834. # include "CarlaProcessUtils.cpp"
  1835. # include "CarlaStateUtils.cpp"
  1836. # include "utils/Information.cpp"
  1837. # include "utils/Windows.cpp"
  1838. #endif /* CARLA_PLUGIN_EXPORT */
  1839. // --------------------------------------------------------------------------------------------------------------------