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.

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