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.

2083 lines
73KB

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