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.

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