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.

2301 lines
86KB

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