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.

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