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.

2261 lines
81KB

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