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.

2372 lines
84KB

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