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.

2287 lines
85KB

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