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.

2308 lines
86KB

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