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.

2285 lines
82KB

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