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.

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