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.

2272 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.engineOptions.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. if (shandle.engineOptions.clientNamePrefix != nullptr)
  703. delete[] shandle.engineOptions.clientNamePrefix;
  704. shandle.engineOptions.clientNamePrefix = valueStr != nullptr && valueStr[0] != '\0'
  705. ? carla_strdup_safe(valueStr)
  706. : nullptr;
  707. break;
  708. }
  709. }
  710. if (handle->engine != nullptr)
  711. handle->engine->setOption(option, value, valueStr);
  712. }
  713. #endif // BUILD_BRIDGE
  714. void carla_set_file_callback(CarlaHostHandle handle, FileCallbackFunc func, void* ptr)
  715. {
  716. carla_debug("carla_set_file_callback(%p, %p, %p)", handle, func, ptr);
  717. if (handle->isStandalone)
  718. {
  719. CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
  720. shandle.fileCallback = func;
  721. shandle.fileCallbackPtr = ptr;
  722. }
  723. if (handle->engine != nullptr)
  724. handle->engine->setFileCallback(func, ptr);
  725. }
  726. // --------------------------------------------------------------------------------------------------------------------
  727. bool carla_load_file(CarlaHostHandle handle, const char* filename)
  728. {
  729. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  730. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  731. carla_debug("carla_load_file(%p, \"%s\")", handle, filename);
  732. return handle->engine->loadFile(filename);
  733. }
  734. bool carla_load_project(CarlaHostHandle handle, const char* filename)
  735. {
  736. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  737. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  738. carla_debug("carla_load_project(%p, \"%s\")", handle, filename);
  739. return handle->engine->loadProject(filename, true);
  740. }
  741. bool carla_save_project(CarlaHostHandle handle, const char* filename)
  742. {
  743. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  744. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  745. carla_debug("carla_save_project(%p, \"%s\")", handle, filename);
  746. return handle->engine->saveProject(filename, true);
  747. }
  748. #ifndef BUILD_BRIDGE
  749. const char* carla_get_current_project_folder(CarlaHostHandle handle)
  750. {
  751. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  752. carla_debug("carla_get_current_project_folder(%p)", handle);
  753. if (const char* const ret = handle->engine->getCurrentProjectFolder())
  754. return ret;
  755. return gNullCharPtr;
  756. }
  757. const char* carla_get_current_project_filename(CarlaHostHandle handle)
  758. {
  759. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->isStandalone, gNullCharPtr);
  760. carla_debug("carla_get_current_project_filename(%p)", handle);
  761. if (const char* const ret = handle->engine->getCurrentProjectFilename())
  762. return ret;
  763. return gNullCharPtr;
  764. }
  765. void carla_clear_project_filename(CarlaHostHandle handle)
  766. {
  767. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  768. carla_debug("carla_clear_project_filename(%p)", handle);
  769. handle->engine->clearCurrentProjectFilename();
  770. }
  771. // --------------------------------------------------------------------------------------------------------------------
  772. bool carla_patchbay_connect(CarlaHostHandle handle, bool external, uint groupIdA, uint portIdA, uint groupIdB, uint portIdB)
  773. {
  774. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  775. carla_debug("carla_patchbay_connect(%p, %s, %u, %u, %u, %u)",
  776. handle, bool2str(external), groupIdA, portIdA, groupIdB, portIdB);
  777. return handle->engine->patchbayConnect(external, groupIdA, portIdA, groupIdB, portIdB);
  778. }
  779. bool carla_patchbay_disconnect(CarlaHostHandle handle, bool external, uint connectionId)
  780. {
  781. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  782. carla_debug("carla_patchbay_disconnect(%p, %s, %i)", handle, bool2str(external), connectionId);
  783. return handle->engine->patchbayDisconnect(external, connectionId);
  784. }
  785. bool carla_patchbay_set_group_pos(CarlaHostHandle handle, bool external, uint groupId, int x1, int y1, int x2, int y2)
  786. {
  787. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr && handle->engine->isRunning(),
  788. "Engine is not running", false);
  789. carla_debug("carla_patchbay_set_group_pos(%p, %s, %u, %i, %i, %i, %i)",
  790. handle, bool2str(external), groupId, x1, y1, x2, y2);
  791. if (handle->engine->isAboutToClose())
  792. return true;
  793. return handle->engine->patchbaySetGroupPos(false, true, external, groupId, x1, y1, x2, y2);
  794. }
  795. bool carla_patchbay_refresh(CarlaHostHandle handle, bool external)
  796. {
  797. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  798. carla_debug("carla_patchbay_refresh(%p, %s)", handle, bool2str(external));
  799. return handle->engine->patchbayRefresh(true, false, external);
  800. }
  801. // --------------------------------------------------------------------------------------------------------------------
  802. void carla_transport_play(CarlaHostHandle handle)
  803. {
  804. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(),);
  805. carla_debug("carla_transport_play(%p)", handle);
  806. handle->engine->transportPlay();
  807. }
  808. void carla_transport_pause(CarlaHostHandle handle)
  809. {
  810. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(),);
  811. carla_debug("carla_transport_pause(%p)", handle);
  812. handle->engine->transportPause();
  813. }
  814. void carla_transport_bpm(CarlaHostHandle handle, double bpm)
  815. {
  816. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(),);
  817. carla_debug("carla_transport_bpm(%p, %f)", handle, bpm);
  818. handle->engine->transportBPM(bpm);
  819. }
  820. void carla_transport_relocate(CarlaHostHandle handle, uint64_t frame)
  821. {
  822. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(),);
  823. carla_debug("carla_transport_relocate(%p, %i)", handle, frame);
  824. handle->engine->transportRelocate(frame);
  825. }
  826. uint64_t carla_get_current_transport_frame(CarlaHostHandle handle)
  827. {
  828. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(), 0);
  829. return handle->engine->getTimeInfo().frame;
  830. }
  831. const CarlaTransportInfo* carla_get_transport_info(CarlaHostHandle handle)
  832. {
  833. static CarlaTransportInfo retTransInfo;
  834. retTransInfo.clear();
  835. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(), &retTransInfo);
  836. const CB::EngineTimeInfo& timeInfo(handle->engine->getTimeInfo());
  837. retTransInfo.playing = timeInfo.playing;
  838. retTransInfo.frame = timeInfo.frame;
  839. if (timeInfo.bbt.valid)
  840. {
  841. retTransInfo.bar = timeInfo.bbt.bar;
  842. retTransInfo.beat = timeInfo.bbt.beat;
  843. retTransInfo.tick = static_cast<int32_t>(timeInfo.bbt.tick + 0.5);
  844. retTransInfo.bpm = timeInfo.bbt.beatsPerMinute;
  845. }
  846. return &retTransInfo;
  847. }
  848. #endif
  849. // --------------------------------------------------------------------------------------------------------------------
  850. uint32_t carla_get_current_plugin_count(CarlaHostHandle handle)
  851. {
  852. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  853. carla_debug("carla_get_current_plugin_count(%p)", handle);
  854. return handle->engine->getCurrentPluginCount();
  855. }
  856. uint32_t carla_get_max_plugin_number(CarlaHostHandle handle)
  857. {
  858. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  859. carla_debug("carla_get_max_plugin_number(%p)", handle);
  860. return handle->engine->getMaxPluginNumber();
  861. }
  862. // --------------------------------------------------------------------------------------------------------------------
  863. bool carla_add_plugin(CarlaHostHandle handle,
  864. BinaryType btype, PluginType ptype,
  865. const char* filename, const char* name, const char* label, int64_t uniqueId,
  866. const void* extraPtr, uint options)
  867. {
  868. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  869. carla_debug("carla_add_plugin(%p, %i:%s, %i:%s, \"%s\", \"%s\", \"%s\", " P_INT64 ", %p, %u)",
  870. handle,
  871. btype, CB::BinaryType2Str(btype),
  872. ptype, CB::PluginType2Str(ptype),
  873. filename, name, label, uniqueId, extraPtr, options);
  874. return handle->engine->addPlugin(btype, ptype, filename, name, label, uniqueId, extraPtr, options);
  875. }
  876. bool carla_remove_plugin(CarlaHostHandle handle, uint pluginId)
  877. {
  878. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  879. carla_debug("carla_remove_plugin(%p, %i)", handle, pluginId);
  880. return handle->engine->removePlugin(pluginId);
  881. }
  882. bool carla_remove_all_plugins(CarlaHostHandle handle)
  883. {
  884. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  885. carla_debug("carla_remove_all_plugins(%p)", handle);
  886. return handle->engine->removeAllPlugins();
  887. }
  888. #ifndef BUILD_BRIDGE
  889. bool carla_rename_plugin(CarlaHostHandle handle, uint pluginId, const char* newName)
  890. {
  891. CARLA_SAFE_ASSERT_RETURN(newName != nullptr && newName[0] != '\0', false);
  892. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  893. carla_debug("carla_rename_plugin(%p, %i, \"%s\")", handle, pluginId, newName);
  894. return handle->engine->renamePlugin(pluginId, newName);
  895. }
  896. bool carla_clone_plugin(CarlaHostHandle handle, uint pluginId)
  897. {
  898. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  899. carla_debug("carla_clone_plugin(%p, %i)", handle, pluginId);
  900. return handle->engine->clonePlugin(pluginId);
  901. }
  902. bool carla_replace_plugin(CarlaHostHandle handle, uint pluginId)
  903. {
  904. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  905. carla_debug("carla_replace_plugin(%p, %i)", handle, pluginId);
  906. return handle->engine->replacePlugin(pluginId);
  907. }
  908. bool carla_switch_plugins(CarlaHostHandle handle, uint pluginIdA, uint pluginIdB)
  909. {
  910. CARLA_SAFE_ASSERT_RETURN(pluginIdA != pluginIdB, false);
  911. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  912. carla_debug("carla_switch_plugins(%p, %i, %i)", handle, pluginIdA, pluginIdB);
  913. return handle->engine->switchPlugins(pluginIdA, pluginIdB);
  914. }
  915. #endif
  916. // --------------------------------------------------------------------------------------------------------------------
  917. bool carla_load_plugin_state(CarlaHostHandle handle, uint pluginId, const char* filename)
  918. {
  919. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  920. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr
  921. && handle->engine->isRunning(), "Engine is not running", false);
  922. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  923. return plugin->loadStateFromFile(filename);
  924. return false;
  925. }
  926. bool carla_save_plugin_state(CarlaHostHandle handle, uint pluginId, const char* filename)
  927. {
  928. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[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->saveStateToFile(filename);
  932. return false;
  933. }
  934. bool carla_export_plugin_lv2(CarlaHostHandle handle, uint pluginId, const char* lv2path)
  935. {
  936. CARLA_SAFE_ASSERT_RETURN(lv2path != nullptr && lv2path[0] != '\0', false);
  937. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  938. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  939. return plugin->exportAsLV2(lv2path);
  940. return false;
  941. }
  942. // --------------------------------------------------------------------------------------------------------------------
  943. const CarlaPluginInfo* carla_get_plugin_info(CarlaHostHandle handle, uint pluginId)
  944. {
  945. static CarlaPluginInfo retInfo;
  946. // reset
  947. retInfo.type = CB::PLUGIN_NONE;
  948. retInfo.category = CB::PLUGIN_CATEGORY_NONE;
  949. retInfo.hints = 0x0;
  950. retInfo.optionsAvailable = 0x0;
  951. retInfo.optionsEnabled = 0x0;
  952. retInfo.filename = gNullCharPtr;
  953. retInfo.name = gNullCharPtr;
  954. retInfo.iconName = gNullCharPtr;
  955. retInfo.uniqueId = 0;
  956. // cleanup
  957. if (retInfo.label != gNullCharPtr)
  958. {
  959. delete[] retInfo.label;
  960. retInfo.label = gNullCharPtr;
  961. }
  962. if (retInfo.maker != gNullCharPtr)
  963. {
  964. delete[] retInfo.maker;
  965. retInfo.maker = gNullCharPtr;
  966. }
  967. if (retInfo.copyright != gNullCharPtr)
  968. {
  969. delete[] retInfo.copyright;
  970. retInfo.copyright = gNullCharPtr;
  971. }
  972. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
  973. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  974. {
  975. char strBuf[STR_MAX+1];
  976. carla_zeroChars(strBuf, STR_MAX+1);
  977. retInfo.type = plugin->getType();
  978. retInfo.category = plugin->getCategory();
  979. retInfo.hints = plugin->getHints();
  980. retInfo.filename = plugin->getFilename();
  981. retInfo.name = plugin->getName();
  982. retInfo.iconName = plugin->getIconName();
  983. retInfo.uniqueId = plugin->getUniqueId();
  984. retInfo.optionsAvailable = plugin->getOptionsAvailable();
  985. retInfo.optionsEnabled = plugin->getOptionsEnabled();
  986. if (plugin->getLabel(strBuf))
  987. retInfo.label = carla_strdup_safe(strBuf);
  988. if (plugin->getMaker(strBuf))
  989. retInfo.maker = carla_strdup_safe(strBuf);
  990. if (plugin->getCopyright(strBuf))
  991. retInfo.copyright = carla_strdup_safe(strBuf);
  992. checkStringPtr(retInfo.filename);
  993. checkStringPtr(retInfo.name);
  994. checkStringPtr(retInfo.iconName);
  995. checkStringPtr(retInfo.label);
  996. checkStringPtr(retInfo.maker);
  997. checkStringPtr(retInfo.copyright);
  998. }
  999. return &retInfo;
  1000. }
  1001. const CarlaPortCountInfo* carla_get_audio_port_count_info(CarlaHostHandle handle, uint pluginId)
  1002. {
  1003. static CarlaPortCountInfo retInfo;
  1004. carla_zeroStruct(retInfo);
  1005. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
  1006. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1007. {
  1008. retInfo.ins = plugin->getAudioInCount();
  1009. retInfo.outs = plugin->getAudioOutCount();
  1010. }
  1011. return &retInfo;
  1012. }
  1013. const CarlaPortCountInfo* carla_get_midi_port_count_info(CarlaHostHandle handle, uint pluginId)
  1014. {
  1015. static CarlaPortCountInfo retInfo;
  1016. carla_zeroStruct(retInfo);
  1017. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
  1018. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1019. {
  1020. retInfo.ins = plugin->getMidiInCount();
  1021. retInfo.outs = plugin->getMidiOutCount();
  1022. }
  1023. return &retInfo;
  1024. }
  1025. const CarlaPortCountInfo* carla_get_parameter_count_info(CarlaHostHandle handle, uint pluginId)
  1026. {
  1027. static CarlaPortCountInfo retInfo;
  1028. carla_zeroStruct(retInfo);
  1029. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
  1030. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1031. plugin->getParameterCountInfo(retInfo.ins, retInfo.outs);
  1032. return &retInfo;
  1033. }
  1034. const CarlaParameterInfo* carla_get_parameter_info(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1035. {
  1036. static CarlaParameterInfo retInfo(gNullCharPtr);
  1037. // reset
  1038. retInfo.scalePointCount = 0;
  1039. // cleanup
  1040. if (retInfo.name != gNullCharPtr)
  1041. {
  1042. delete[] retInfo.name;
  1043. retInfo.name = gNullCharPtr;
  1044. }
  1045. if (retInfo.symbol != gNullCharPtr)
  1046. {
  1047. delete[] retInfo.symbol;
  1048. retInfo.symbol = gNullCharPtr;
  1049. }
  1050. if (retInfo.unit != gNullCharPtr)
  1051. {
  1052. delete[] retInfo.unit;
  1053. retInfo.unit = gNullCharPtr;
  1054. }
  1055. if (retInfo.comment != gNullCharPtr)
  1056. {
  1057. delete[] retInfo.comment;
  1058. retInfo.comment = gNullCharPtr;
  1059. }
  1060. if (retInfo.groupName != gNullCharPtr)
  1061. {
  1062. delete[] retInfo.groupName;
  1063. retInfo.groupName = gNullCharPtr;
  1064. }
  1065. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
  1066. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1067. {
  1068. char strBuf[STR_MAX+1];
  1069. carla_zeroChars(strBuf, STR_MAX+1);
  1070. retInfo.scalePointCount = plugin->getParameterScalePointCount(parameterId);
  1071. if (plugin->getParameterName(parameterId, strBuf))
  1072. {
  1073. retInfo.name = carla_strdup_safe(strBuf);
  1074. carla_zeroChars(strBuf, STR_MAX+1);
  1075. }
  1076. if (plugin->getParameterSymbol(parameterId, strBuf))
  1077. {
  1078. retInfo.symbol = carla_strdup_safe(strBuf);
  1079. carla_zeroChars(strBuf, STR_MAX+1);
  1080. }
  1081. if (plugin->getParameterUnit(parameterId, strBuf))
  1082. {
  1083. retInfo.unit = carla_strdup_safe(strBuf);
  1084. carla_zeroChars(strBuf, STR_MAX+1);
  1085. }
  1086. if (plugin->getParameterComment(parameterId, strBuf))
  1087. {
  1088. retInfo.comment = carla_strdup_safe(strBuf);
  1089. carla_zeroChars(strBuf, STR_MAX+1);
  1090. }
  1091. if (plugin->getParameterGroupName(parameterId, strBuf))
  1092. {
  1093. retInfo.groupName = carla_strdup_safe(strBuf);
  1094. carla_zeroChars(strBuf, STR_MAX+1);
  1095. }
  1096. checkStringPtr(retInfo.name);
  1097. checkStringPtr(retInfo.symbol);
  1098. checkStringPtr(retInfo.unit);
  1099. checkStringPtr(retInfo.comment);
  1100. checkStringPtr(retInfo.groupName);
  1101. }
  1102. return &retInfo;
  1103. }
  1104. const CarlaScalePointInfo* carla_get_parameter_scalepoint_info(CarlaHostHandle handle,
  1105. uint pluginId,
  1106. uint32_t parameterId,
  1107. uint32_t scalePointId)
  1108. {
  1109. CARLA_ASSERT(handle->engine != nullptr);
  1110. static CarlaScalePointInfo retInfo;
  1111. // reset
  1112. retInfo.value = 0.0f;
  1113. // cleanup
  1114. if (retInfo.label != gNullCharPtr)
  1115. {
  1116. delete[] retInfo.label;
  1117. retInfo.label = gNullCharPtr;
  1118. }
  1119. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
  1120. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1121. {
  1122. char strBuf[STR_MAX+1];
  1123. retInfo.value = plugin->getParameterScalePointValue(parameterId, scalePointId);
  1124. carla_zeroChars(strBuf, STR_MAX+1);
  1125. if (plugin->getParameterScalePointLabel(parameterId, scalePointId, strBuf))
  1126. retInfo.label = carla_strdup_safe(strBuf);
  1127. checkStringPtr(retInfo.label);
  1128. }
  1129. return &retInfo;
  1130. }
  1131. // --------------------------------------------------------------------------------------------------------------------
  1132. const ParameterData* carla_get_parameter_data(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1133. {
  1134. static ParameterData retParamData;
  1135. // reset
  1136. retParamData.type = CB::PARAMETER_UNKNOWN;
  1137. retParamData.hints = 0x0;
  1138. retParamData.index = CB::PARAMETER_NULL;
  1139. retParamData.rindex = -1;
  1140. retParamData.midiChannel = 0;
  1141. retParamData.mappedControlIndex = CB::CONTROL_INDEX_NONE;
  1142. retParamData.mappedMinimum = 0.0f;
  1143. retParamData.mappedMaximum = 0.0f;
  1144. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retParamData);
  1145. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1146. {
  1147. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), &retParamData);
  1148. const ParameterData& pluginParamData(plugin->getParameterData(parameterId));
  1149. retParamData.type = pluginParamData.type;
  1150. retParamData.hints = pluginParamData.hints;
  1151. retParamData.index = pluginParamData.index;
  1152. retParamData.rindex = pluginParamData.rindex;
  1153. retParamData.midiChannel = pluginParamData.midiChannel;
  1154. retParamData.mappedControlIndex = pluginParamData.mappedControlIndex;
  1155. retParamData.mappedMinimum = pluginParamData.mappedMinimum;
  1156. retParamData.mappedMaximum = pluginParamData.mappedMaximum;
  1157. }
  1158. return &retParamData;
  1159. }
  1160. const ParameterRanges* carla_get_parameter_ranges(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1161. {
  1162. static ParameterRanges retParamRanges;
  1163. // reset
  1164. retParamRanges.def = 0.0f;
  1165. retParamRanges.min = 0.0f;
  1166. retParamRanges.max = 1.0f;
  1167. retParamRanges.step = 0.01f;
  1168. retParamRanges.stepSmall = 0.0001f;
  1169. retParamRanges.stepLarge = 0.1f;
  1170. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retParamRanges);
  1171. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1172. {
  1173. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), &retParamRanges);
  1174. const ParameterRanges& pluginParamRanges(plugin->getParameterRanges(parameterId));
  1175. retParamRanges.def = pluginParamRanges.def;
  1176. retParamRanges.min = pluginParamRanges.min;
  1177. retParamRanges.max = pluginParamRanges.max;
  1178. retParamRanges.step = pluginParamRanges.step;
  1179. retParamRanges.stepSmall = pluginParamRanges.stepSmall;
  1180. retParamRanges.stepLarge = pluginParamRanges.stepLarge;
  1181. }
  1182. return &retParamRanges;
  1183. }
  1184. const MidiProgramData* carla_get_midi_program_data(CarlaHostHandle handle, uint pluginId, uint32_t midiProgramId)
  1185. {
  1186. static MidiProgramData retMidiProgData = { 0, 0, gNullCharPtr };
  1187. // reset
  1188. retMidiProgData.bank = 0;
  1189. retMidiProgData.program = 0;
  1190. if (retMidiProgData.name != gNullCharPtr)
  1191. {
  1192. delete[] retMidiProgData.name;
  1193. retMidiProgData.name = gNullCharPtr;
  1194. }
  1195. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retMidiProgData);
  1196. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1197. {
  1198. CARLA_SAFE_ASSERT_RETURN(midiProgramId < plugin->getMidiProgramCount(), &retMidiProgData);
  1199. const MidiProgramData& pluginMidiProgData(plugin->getMidiProgramData(midiProgramId));
  1200. retMidiProgData.bank = pluginMidiProgData.bank;
  1201. retMidiProgData.program = pluginMidiProgData.program;
  1202. if (pluginMidiProgData.name != nullptr)
  1203. {
  1204. retMidiProgData.name = carla_strdup_safe(pluginMidiProgData.name);
  1205. checkStringPtr(retMidiProgData.name);
  1206. }
  1207. else
  1208. {
  1209. retMidiProgData.name = gNullCharPtr;
  1210. }
  1211. }
  1212. return &retMidiProgData;
  1213. }
  1214. const CustomData* carla_get_custom_data(CarlaHostHandle handle, uint pluginId, uint32_t customDataId)
  1215. {
  1216. static CustomData retCustomData = { gNullCharPtr, gNullCharPtr, gNullCharPtr };
  1217. // reset
  1218. if (retCustomData.type != gNullCharPtr)
  1219. {
  1220. delete[] retCustomData.type;
  1221. retCustomData.type = gNullCharPtr;
  1222. }
  1223. if (retCustomData.key != gNullCharPtr)
  1224. {
  1225. delete[] retCustomData.key;
  1226. retCustomData.key = gNullCharPtr;
  1227. }
  1228. if (retCustomData.value != gNullCharPtr)
  1229. {
  1230. delete[] retCustomData.value;
  1231. retCustomData.value = gNullCharPtr;
  1232. }
  1233. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retCustomData);
  1234. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1235. {
  1236. CARLA_SAFE_ASSERT_RETURN(customDataId < plugin->getCustomDataCount(), &retCustomData)
  1237. const CustomData& pluginCustomData(plugin->getCustomData(customDataId));
  1238. retCustomData.type = carla_strdup_safe(pluginCustomData.type);
  1239. retCustomData.key = carla_strdup_safe(pluginCustomData.key);
  1240. retCustomData.value = carla_strdup_safe(pluginCustomData.value);
  1241. checkStringPtr(retCustomData.type);
  1242. checkStringPtr(retCustomData.key);
  1243. checkStringPtr(retCustomData.value);
  1244. }
  1245. return &retCustomData;
  1246. }
  1247. const char* carla_get_custom_data_value(CarlaHostHandle handle, uint pluginId, const char* type, const char* key)
  1248. {
  1249. CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0', gNullCharPtr);
  1250. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0', gNullCharPtr);
  1251. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  1252. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1253. {
  1254. const uint32_t count = plugin->getCustomDataCount();
  1255. if (count == 0)
  1256. return gNullCharPtr;
  1257. static CarlaString customDataValue;
  1258. for (uint32_t i=0; i<count; ++i)
  1259. {
  1260. const CustomData& pluginCustomData(plugin->getCustomData(i));
  1261. if (std::strcmp(pluginCustomData.type, type) != 0)
  1262. continue;
  1263. if (std::strcmp(pluginCustomData.key, key) != 0)
  1264. continue;
  1265. customDataValue = pluginCustomData.value;
  1266. return customDataValue.buffer();
  1267. }
  1268. }
  1269. return gNullCharPtr;
  1270. }
  1271. const char* carla_get_chunk_data(CarlaHostHandle handle, uint pluginId)
  1272. {
  1273. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  1274. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1275. {
  1276. CARLA_SAFE_ASSERT_RETURN(plugin->getOptionsEnabled() & CB::PLUGIN_OPTION_USE_CHUNKS, gNullCharPtr);
  1277. void* data = nullptr;
  1278. const std::size_t dataSize(plugin->getChunkData(&data));
  1279. CARLA_SAFE_ASSERT_RETURN(data != nullptr && dataSize > 0, gNullCharPtr);
  1280. static CarlaString chunkData;
  1281. chunkData = CarlaString::asBase64(data, static_cast<std::size_t>(dataSize));
  1282. return chunkData.buffer();
  1283. }
  1284. return gNullCharPtr;
  1285. }
  1286. // --------------------------------------------------------------------------------------------------------------------
  1287. uint32_t carla_get_parameter_count(CarlaHostHandle handle, uint pluginId)
  1288. {
  1289. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1290. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1291. return plugin->getParameterCount();
  1292. return 0;
  1293. }
  1294. uint32_t carla_get_program_count(CarlaHostHandle handle, uint pluginId)
  1295. {
  1296. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1297. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1298. return plugin->getProgramCount();
  1299. return 0;
  1300. }
  1301. uint32_t carla_get_midi_program_count(CarlaHostHandle handle, uint pluginId)
  1302. {
  1303. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1304. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1305. return plugin->getMidiProgramCount();
  1306. return 0;
  1307. }
  1308. uint32_t carla_get_custom_data_count(CarlaHostHandle handle, uint pluginId)
  1309. {
  1310. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1311. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1312. return plugin->getCustomDataCount();
  1313. return 0;
  1314. }
  1315. // --------------------------------------------------------------------------------------------------------------------
  1316. const char* carla_get_parameter_text(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1317. {
  1318. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  1319. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1320. {
  1321. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), gNullCharPtr);
  1322. static char textBuf[STR_MAX+1];
  1323. carla_zeroChars(textBuf, STR_MAX+1);
  1324. if (! plugin->getParameterText(parameterId, textBuf))
  1325. textBuf[0] = '\0';
  1326. return textBuf;
  1327. }
  1328. return gNullCharPtr;
  1329. }
  1330. const char* carla_get_program_name(CarlaHostHandle handle, uint pluginId, uint32_t programId)
  1331. {
  1332. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, nullptr);
  1333. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1334. {
  1335. CARLA_SAFE_ASSERT_RETURN(programId < plugin->getProgramCount(), gNullCharPtr);
  1336. static char programName[STR_MAX+1];
  1337. carla_zeroChars(programName, STR_MAX+1);
  1338. if (! plugin->getProgramName(programId, programName))
  1339. programName[0] = '\0';
  1340. return programName;
  1341. }
  1342. return gNullCharPtr;
  1343. }
  1344. const char* carla_get_midi_program_name(CarlaHostHandle handle, uint pluginId, uint32_t midiProgramId)
  1345. {
  1346. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  1347. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1348. {
  1349. CARLA_SAFE_ASSERT_RETURN(midiProgramId < plugin->getMidiProgramCount(), gNullCharPtr);
  1350. static char midiProgramName[STR_MAX+1];
  1351. carla_zeroChars(midiProgramName, STR_MAX+1);
  1352. if (! plugin->getMidiProgramName(midiProgramId, midiProgramName))
  1353. midiProgramName[0] = '\0';
  1354. return midiProgramName;
  1355. }
  1356. return gNullCharPtr;
  1357. }
  1358. const char* carla_get_real_plugin_name(CarlaHostHandle handle, uint pluginId)
  1359. {
  1360. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  1361. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1362. {
  1363. static char realPluginName[STR_MAX+1];
  1364. carla_zeroChars(realPluginName, STR_MAX+1);
  1365. if (! plugin->getRealName(realPluginName))
  1366. realPluginName[0] = '\0';
  1367. return realPluginName;
  1368. }
  1369. return gNullCharPtr;
  1370. }
  1371. // --------------------------------------------------------------------------------------------------------------------
  1372. int32_t carla_get_current_program_index(CarlaHostHandle handle, uint pluginId)
  1373. {
  1374. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, -1);
  1375. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1376. return plugin->getCurrentProgram();
  1377. return -1;
  1378. }
  1379. int32_t carla_get_current_midi_program_index(CarlaHostHandle handle, uint pluginId)
  1380. {
  1381. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, -1);
  1382. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1383. return plugin->getCurrentMidiProgram();
  1384. return -1;
  1385. }
  1386. // --------------------------------------------------------------------------------------------------------------------
  1387. float carla_get_default_parameter_value(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1388. {
  1389. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
  1390. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1391. {
  1392. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), 0.0f);
  1393. return plugin->getParameterRanges(parameterId).def;
  1394. }
  1395. return 0.0f;
  1396. }
  1397. float carla_get_current_parameter_value(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1398. {
  1399. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
  1400. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1401. {
  1402. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), 0.0f);
  1403. return plugin->getParameterValue(parameterId);
  1404. }
  1405. return 0.0f;
  1406. }
  1407. float carla_get_internal_parameter_value(CarlaHostHandle handle, uint pluginId, int32_t parameterId)
  1408. {
  1409. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1410. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, (parameterId == CB::PARAMETER_CTRL_CHANNEL) ? -1.0f : 0.0f);
  1411. #else
  1412. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
  1413. #endif
  1414. CARLA_SAFE_ASSERT_RETURN(parameterId != CB::PARAMETER_NULL && parameterId > CB::PARAMETER_MAX, 0.0f);
  1415. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1416. return plugin->getInternalParameterValue(parameterId);
  1417. return 0.0f;
  1418. }
  1419. // --------------------------------------------------------------------------------------------------------------------
  1420. const float* carla_get_peak_values(CarlaHostHandle handle, uint pluginId)
  1421. {
  1422. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, nullptr);
  1423. return handle->engine->getPeaks(pluginId);
  1424. }
  1425. float carla_get_input_peak_value(CarlaHostHandle handle, uint pluginId, bool isLeft)
  1426. {
  1427. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
  1428. return handle->engine->getInputPeak(pluginId, isLeft);
  1429. }
  1430. float carla_get_output_peak_value(CarlaHostHandle handle, uint pluginId, bool isLeft)
  1431. {
  1432. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
  1433. return handle->engine->getOutputPeak(pluginId, isLeft);
  1434. }
  1435. // --------------------------------------------------------------------------------------------------------------------
  1436. CARLA_BACKEND_START_NAMESPACE
  1437. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1438. // defined in CarlaPluginInternal.cpp
  1439. const void* carla_render_inline_display_internal(const CarlaPluginPtr& plugin, uint32_t width, uint32_t height);
  1440. #endif
  1441. // defined in CarlaPluginLV2.cpp
  1442. const void* carla_render_inline_display_lv2(const CarlaPluginPtr& plugin, uint32_t width, uint32_t height);
  1443. CARLA_BACKEND_END_NAMESPACE
  1444. const CarlaInlineDisplayImageSurface* carla_render_inline_display(CarlaHostHandle handle,
  1445. uint pluginId,
  1446. uint32_t width, uint32_t height)
  1447. {
  1448. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(), nullptr);
  1449. if (handle->engine->isAboutToClose())
  1450. return nullptr;
  1451. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1452. {
  1453. switch (plugin->getType())
  1454. {
  1455. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1456. case CB::PLUGIN_INTERNAL:
  1457. return (const CarlaInlineDisplayImageSurface*)CB::carla_render_inline_display_internal(plugin, width, height);
  1458. #endif
  1459. case CB::PLUGIN_LV2:
  1460. return (const CarlaInlineDisplayImageSurface*)CB::carla_render_inline_display_lv2(plugin, width, height);
  1461. default:
  1462. return nullptr;
  1463. }
  1464. }
  1465. return nullptr;
  1466. }
  1467. // --------------------------------------------------------------------------------------------------------------------
  1468. void carla_set_active(CarlaHostHandle handle, uint pluginId, bool onOff)
  1469. {
  1470. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1471. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1472. plugin->setActive(onOff, true, false);
  1473. }
  1474. #ifndef BUILD_BRIDGE
  1475. void carla_set_drywet(CarlaHostHandle handle, uint pluginId, float value)
  1476. {
  1477. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1478. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1479. plugin->setDryWet(value, true, false);
  1480. }
  1481. void carla_set_volume(CarlaHostHandle handle, uint pluginId, float value)
  1482. {
  1483. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1484. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1485. plugin->setVolume(value, true, false);
  1486. }
  1487. void carla_set_balance_left(CarlaHostHandle handle, uint pluginId, float value)
  1488. {
  1489. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1490. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1491. plugin->setBalanceLeft(value, true, false);
  1492. }
  1493. void carla_set_balance_right(CarlaHostHandle handle, uint pluginId, float value)
  1494. {
  1495. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1496. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1497. plugin->setBalanceRight(value, true, false);
  1498. }
  1499. void carla_set_panning(CarlaHostHandle handle, uint pluginId, float value)
  1500. {
  1501. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1502. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1503. plugin->setPanning(value, true, false);
  1504. }
  1505. void carla_set_ctrl_channel(CarlaHostHandle handle, uint pluginId, int8_t channel)
  1506. {
  1507. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1508. CARLA_SAFE_ASSERT_RETURN(channel >= -1 && channel < MAX_MIDI_CHANNELS,);
  1509. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1510. plugin->setCtrlChannel(channel, true, false);
  1511. }
  1512. #endif
  1513. void carla_set_option(CarlaHostHandle handle, uint pluginId, uint option, bool yesNo)
  1514. {
  1515. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1516. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1517. plugin->setOption(option, yesNo, false);
  1518. }
  1519. // --------------------------------------------------------------------------------------------------------------------
  1520. void carla_set_parameter_value(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, float value)
  1521. {
  1522. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1523. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1524. {
  1525. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(),);
  1526. plugin->setParameterValue(parameterId, value, true, true, false);
  1527. }
  1528. }
  1529. #ifndef BUILD_BRIDGE
  1530. void carla_set_parameter_midi_channel(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, uint8_t channel)
  1531. {
  1532. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1533. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  1534. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1535. {
  1536. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(),);
  1537. plugin->setParameterMidiChannel(parameterId, channel, true, false);
  1538. }
  1539. }
  1540. void carla_set_parameter_mapped_control_index(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, int16_t index)
  1541. {
  1542. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1543. CARLA_SAFE_ASSERT_RETURN(index >= CB::CONTROL_INDEX_NONE && index <= CB::CONTROL_INDEX_MAX_ALLOWED,);
  1544. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1545. {
  1546. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(),);
  1547. plugin->setParameterMappedControlIndex(parameterId, index, true, false);
  1548. }
  1549. }
  1550. void carla_set_parameter_mapped_range(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, float minimum, float maximum)
  1551. {
  1552. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1553. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1554. {
  1555. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(),);
  1556. plugin->setParameterMappedRange(parameterId, minimum, maximum, true, false);
  1557. }
  1558. }
  1559. void carla_set_parameter_touch(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, bool touch)
  1560. {
  1561. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1562. carla_debug("carla_set_parameter_touch(%p, %i, %i, %s)", handle, pluginId, parameterId, bool2str(touch));
  1563. return handle->engine->touchPluginParameter(pluginId, parameterId, touch);
  1564. }
  1565. #endif
  1566. // --------------------------------------------------------------------------------------------------------------------
  1567. void carla_set_program(CarlaHostHandle handle, uint pluginId, uint32_t programId)
  1568. {
  1569. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1570. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1571. {
  1572. CARLA_SAFE_ASSERT_RETURN(programId < plugin->getProgramCount(),);
  1573. plugin->setProgram(static_cast<int32_t>(programId), true, true, false);
  1574. }
  1575. }
  1576. void carla_set_midi_program(CarlaHostHandle handle, uint pluginId, uint32_t midiProgramId)
  1577. {
  1578. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1579. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1580. {
  1581. CARLA_SAFE_ASSERT_RETURN(midiProgramId < plugin->getMidiProgramCount(),);
  1582. plugin->setMidiProgram(static_cast<int32_t>(midiProgramId), true, true, false);
  1583. }
  1584. }
  1585. // --------------------------------------------------------------------------------------------------------------------
  1586. void carla_set_custom_data(CarlaHostHandle handle, uint pluginId, const char* type, const char* key, const char* value)
  1587. {
  1588. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1589. CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0',);
  1590. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
  1591. CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
  1592. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1593. plugin->setCustomData(type, key, value, true);
  1594. }
  1595. void carla_set_chunk_data(CarlaHostHandle handle, uint pluginId, const char* chunkData)
  1596. {
  1597. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1598. CARLA_SAFE_ASSERT_RETURN(chunkData != nullptr && chunkData[0] != '\0',);
  1599. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1600. {
  1601. CARLA_SAFE_ASSERT_RETURN(plugin->getOptionsEnabled() & CB::PLUGIN_OPTION_USE_CHUNKS,);
  1602. std::vector<uint8_t> chunk(carla_getChunkFromBase64String(chunkData));
  1603. #ifdef CARLA_PROPER_CPP11_SUPPORT
  1604. plugin->setChunkData(chunk.data(), chunk.size());
  1605. #else
  1606. plugin->setChunkData(&chunk.front(), chunk.size());
  1607. #endif
  1608. }
  1609. }
  1610. // --------------------------------------------------------------------------------------------------------------------
  1611. void carla_prepare_for_save(CarlaHostHandle handle, uint pluginId)
  1612. {
  1613. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1614. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1615. plugin->prepareForSave();
  1616. }
  1617. void carla_reset_parameters(CarlaHostHandle handle, uint pluginId)
  1618. {
  1619. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1620. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1621. plugin->resetParameters();
  1622. }
  1623. void carla_randomize_parameters(CarlaHostHandle handle, uint pluginId)
  1624. {
  1625. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1626. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1627. plugin->randomizeParameters();
  1628. }
  1629. #ifndef BUILD_BRIDGE
  1630. void carla_send_midi_note(CarlaHostHandle handle, uint pluginId, uint8_t channel, uint8_t note, uint8_t velocity)
  1631. {
  1632. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(),);
  1633. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1634. plugin->sendMidiSingleNote(channel, note, velocity, true, true, false);
  1635. }
  1636. #endif
  1637. void carla_set_custom_ui_title(CarlaHostHandle handle, uint pluginId, const char* title)
  1638. {
  1639. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1640. CARLA_SAFE_ASSERT_RETURN(title != nullptr,);
  1641. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1642. plugin->setCustomUITitle(title);
  1643. }
  1644. void carla_show_custom_ui(CarlaHostHandle handle, uint pluginId, bool yesNo)
  1645. {
  1646. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1647. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1648. plugin->showCustomUI(yesNo);
  1649. }
  1650. // --------------------------------------------------------------------------------------------------------------------
  1651. uint32_t carla_get_buffer_size(CarlaHostHandle handle)
  1652. {
  1653. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1654. carla_debug("carla_get_buffer_size(%p)", handle);
  1655. return handle->engine->getBufferSize();
  1656. }
  1657. double carla_get_sample_rate(CarlaHostHandle handle)
  1658. {
  1659. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0);
  1660. carla_debug("carla_get_sample_rate(%p)", handle);
  1661. return handle->engine->getSampleRate();
  1662. }
  1663. // --------------------------------------------------------------------------------------------------------------------
  1664. const char* carla_get_last_error(CarlaHostHandle handle)
  1665. {
  1666. carla_debug("carla_get_last_error(%p)", handle);
  1667. if (handle->engine != nullptr)
  1668. return handle->engine->getLastError();
  1669. return handle->isStandalone
  1670. ? ((CarlaHostStandalone*)handle)->lastError.buffer()
  1671. : gNullCharPtr;
  1672. }
  1673. const char* carla_get_host_osc_url_tcp(CarlaHostHandle handle)
  1674. {
  1675. carla_debug("carla_get_host_osc_url_tcp(%p)", handle);
  1676. #if defined(HAVE_LIBLO) && !defined(BUILD_BRIDGE)
  1677. if (handle->engine == nullptr)
  1678. {
  1679. carla_stderr2("carla_get_host_osc_url_tcp() failed, engine is not running");
  1680. if (handle->isStandalone)
  1681. ((CarlaHostStandalone*)handle)->lastError = "Engine is not running";
  1682. return gNullCharPtr;
  1683. }
  1684. const char* const path = handle->engine->getOscServerPathTCP();
  1685. if (path != nullptr && path[0] != '\0')
  1686. return path;
  1687. static const char* const notAvailable = "(OSC TCP port not available)";
  1688. return notAvailable;
  1689. #else
  1690. return gNullCharPtr;
  1691. // unused
  1692. (void)handle;
  1693. #endif
  1694. }
  1695. const char* carla_get_host_osc_url_udp(CarlaHostHandle handle)
  1696. {
  1697. carla_debug("carla_get_host_osc_url_udp(%p)", handle);
  1698. #if defined(HAVE_LIBLO) && !defined(BUILD_BRIDGE)
  1699. if (handle->engine == nullptr)
  1700. {
  1701. carla_stderr2("carla_get_host_osc_url_udp() failed, engine is not running");
  1702. if (handle->isStandalone)
  1703. ((CarlaHostStandalone*)handle)->lastError = "Engine is not running";
  1704. return gNullCharPtr;
  1705. }
  1706. const char* const path = handle->engine->getOscServerPathUDP();
  1707. if (path != nullptr && path[0] != '\0')
  1708. return path;
  1709. static const char* const notAvailable = "(OSC UDP port not available)";
  1710. return notAvailable;
  1711. #else
  1712. return gNullCharPtr;
  1713. // unused
  1714. (void)handle;
  1715. #endif
  1716. }
  1717. // --------------------------------------------------------------------------------------------------------------------
  1718. #define CARLA_PLUGIN_UI_CLASS_PREFIX Standalone
  1719. #include "CarlaPluginUI.cpp"
  1720. #undef CARLA_PLUGIN_UI_CLASS_PREFIX
  1721. #include "CarlaDssiUtils.cpp"
  1722. #include "CarlaMacUtils.cpp"
  1723. #include "CarlaPatchbayUtils.cpp"
  1724. #include "CarlaPipeUtils.cpp"
  1725. #include "CarlaProcessUtils.cpp"
  1726. #include "CarlaStateUtils.cpp"
  1727. // --------------------------------------------------------------------------------------------------------------------