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.

2237 lines
79KB

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