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.

2203 lines
70KB

  1. /*
  2. * Carla Standalone
  3. * Copyright (C) 2011-2013 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 GPL.txt file
  16. */
  17. #include "CarlaStandalone.hpp"
  18. #include "CarlaBackendUtils.hpp"
  19. #include "CarlaOscUtils.hpp"
  20. #include "CarlaEngine.hpp"
  21. #include "CarlaPlugin.hpp"
  22. #include "CarlaMIDI.h"
  23. #include "CarlaNative.h"
  24. #ifndef BUILD_BRIDGE
  25. # include "CarlaStyle.hpp"
  26. #endif
  27. #include <QtCore/QSettings>
  28. #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
  29. # include <QtWidgets/QApplication>
  30. #else
  31. # include <QtGui/QApplication>
  32. #endif
  33. using CarlaBackend::CarlaEngine;
  34. using CarlaBackend::CarlaPlugin;
  35. using CarlaBackend::CallbackFunc;
  36. using CarlaBackend::EngineOptions;
  37. using CarlaBackend::EngineTimeInfo;
  38. // -------------------------------------------------------------------------------------------------------------------
  39. // Single, standalone engine
  40. struct CarlaBackendStandalone {
  41. CallbackFunc callback;
  42. void* callbackPtr;
  43. CarlaEngine* engine;
  44. CarlaString lastError;
  45. CarlaString procName;
  46. EngineOptions options;
  47. QApplication* app;
  48. bool needsInit;
  49. CarlaBackendStandalone()
  50. : callback(nullptr),
  51. callbackPtr(nullptr),
  52. engine(nullptr),
  53. app(qApp),
  54. needsInit(app == nullptr)
  55. {
  56. #ifndef BUILD_BRIDGE
  57. if (app != nullptr)
  58. {
  59. QSettings settings;
  60. if (settings.value("Main/UseProTheme", true).toBool())
  61. {
  62. CarlaStyle* const style(new CarlaStyle());
  63. app->setStyle(style);
  64. style->ready(app);
  65. QString color(settings.value("Main/ProThemeColor", "Black").toString());
  66. if (color == "Blue")
  67. style->setColorScheme(CarlaStyle::COLOR_BLUE);
  68. else if (color == "System")
  69. pass(); //style->setColorScheme(CarlaStyle::COLOR_SYSTEM);
  70. else
  71. style->setColorScheme(CarlaStyle::COLOR_BLACK);
  72. }
  73. }
  74. #endif
  75. }
  76. ~CarlaBackendStandalone()
  77. {
  78. CARLA_ASSERT(engine == nullptr);
  79. }
  80. void init()
  81. {
  82. if (! needsInit)
  83. return;
  84. if (app != nullptr)
  85. return;
  86. static int argc = 0;
  87. static char** argv = nullptr;
  88. app = new QApplication(argc, argv, true);
  89. }
  90. void close()
  91. {
  92. if (! needsInit)
  93. return;
  94. if (app == nullptr)
  95. return;
  96. app->quit();
  97. app->processEvents();
  98. delete app;
  99. app = nullptr;
  100. }
  101. CARLA_DECLARE_NON_COPY_STRUCT_WITH_LEAK_DETECTOR(CarlaBackendStandalone)
  102. } standalone;
  103. // -------------------------------------------------------------------------------------------------------------------
  104. // API
  105. const char* carla_get_extended_license_text()
  106. {
  107. carla_debug("carla_get_extended_license_text()");
  108. static CarlaString retText;
  109. if (retText.isEmpty())
  110. {
  111. CarlaString text1, text2;
  112. text1 += "<p>This current Carla build is using the following features and 3rd-party code:</p>";
  113. text1 += "<ul>";
  114. // Plugin formats
  115. #ifdef WANT_LADSPA
  116. text1 += "<li>LADSPA plugin support, http://www.ladspa.org/</li>";
  117. #endif
  118. #ifdef WANT_DSSI
  119. text1 += "<li>DSSI plugin support, http://dssi.sourceforge.net/</li>";
  120. #endif
  121. #ifdef WANT_LV2
  122. text1 += "<li>LV2 plugin support, http://lv2plug.in/</li>";
  123. #endif
  124. #ifdef WANT_VST
  125. # ifdef VESTIGE_HEADER
  126. text1 += "<li>VST plugin support, using VeSTige header by Javier Serrano Polo</li>";
  127. # else
  128. text1 += "<li>VST plugin support, using official VST SDK 2.4 (trademark of Steinberg Media Technologies GmbH)</li>";
  129. # endif
  130. #endif
  131. // Sample kit libraries
  132. #ifdef WANT_FLUIDSYNTH
  133. text1 += "<li>FluidSynth library for SF2 support, http://www.fluidsynth.org/</li>";
  134. #endif
  135. #ifdef WANT_LINUXSAMPLER
  136. text1 += "<li>LinuxSampler library for GIG and SFZ support*, http://www.linuxsampler.org/</li>";
  137. #endif
  138. // Internal plugins
  139. #ifdef WANT_OPENGL
  140. text1 += "<li>DISTRHO Mini-Series plugin code, based on LOSER-dev suite by Michael Gruhn</li>";
  141. #endif
  142. text1 += "<li>NekoFilter plugin code, based on lv2fil by Nedko Arnaudov and Fons Adriaensen</li>";
  143. text1 += "<li>SunVox library file support, http://www.warmplace.ru/soft/sunvox/</li>";
  144. #ifdef WANT_AUDIOFILE
  145. text1 += "<li>AudioDecoder library for Audio file support, by Robin Gareus</li>";
  146. #endif
  147. #ifdef WANT_MIDIFILE
  148. text1 += "<li>LibSMF library for MIDI file support, http://libsmf.sourceforge.net/</li>";
  149. #endif
  150. #ifdef WANT_ZYNADDSUBFX
  151. text1 += "<li>ZynAddSubFX plugin code, http://zynaddsubfx.sf.net/</li>";
  152. # ifdef WANT_ZYNADDSUBFX_UI
  153. text1 += "<li>ZynAddSubFX UI using NTK, http://non.tuxfamily.org/wiki/NTK</li>";
  154. # endif
  155. #endif
  156. // misc libs
  157. text1 += "<li>liblo library for OSC support, http://liblo.sourceforge.net/</li>";
  158. #ifdef WANT_LV2
  159. text1 += "<li>serd, sord, sratom and lilv libraries for LV2 discovery, http://drobilla.net/software/lilv/</li>";
  160. #endif
  161. #ifdef WANT_RTAUDIO
  162. text1 += "<li>RtAudio+RtMidi libraries for extra Audio and MIDI support, http://www.music.mcgill.ca/~gary/rtaudio/</li>";
  163. #endif
  164. text1 += "</ul>";
  165. // code snippets
  166. text2 += "<p>Additionally, Carla uses code snippets from the following projects:</p>";
  167. text2 += "<ul>";
  168. text2 += "<li>Pointer and data leak utils from JUCE, http://www.rawmaterialsoftware.com/juce.php</li>";
  169. text2 += "<li>Shared memory utils from dssi-vst, http://www.breakfastquay.com/dssi-vst/</li>";
  170. text2 += "<li>Real-time memory pool, by Nedko Arnaudov</li>";
  171. text2 += "</ul>";
  172. // LinuxSampler GPL exception
  173. #ifdef WANT_LINUXSAMPLER
  174. text2 += "<p>(*) Using LinuxSampler code in commercial hardware or software products is not allowed without prior written authorization by the authors.</p>";
  175. #endif
  176. retText += text1;
  177. retText += text2;
  178. }
  179. return retText;
  180. }
  181. const char* carla_get_supported_file_types()
  182. {
  183. carla_debug("carla_get_supported_file_types()");
  184. static CarlaString retText;
  185. if (retText.isEmpty())
  186. {
  187. // Base types
  188. retText += "*.carxp;*.carxs";
  189. // Sample kits
  190. #ifdef WANT_FLUIDSYNTH
  191. retText += ";*.sf2";
  192. #endif
  193. #ifdef WANT_LINUXSAMPLER
  194. retText += ";*.gig;*.sfz";
  195. #endif
  196. // Files provided by internal plugins
  197. #ifdef WANT_AUDIOFILE
  198. retText += "*.3g2;*.3gp;*.aac;*.ac3;*.aiff;*.amr;*.ape;*.flac;*.mp2;*.mp3;*.mpc;*.oga;*.ogg;*.w64;*.wav;*.wma;";
  199. #endif
  200. #ifdef WANT_MIDIFILE
  201. retText += ";*.mid;*.midi";
  202. #endif
  203. // Plugin presets
  204. #ifdef WANT_ZYNADDSUBFX
  205. retText += ";*.xmz";
  206. #endif
  207. }
  208. return retText;
  209. }
  210. // -------------------------------------------------------------------------------------------------------------------
  211. unsigned int carla_get_engine_driver_count()
  212. {
  213. carla_debug("carla_get_engine_driver_count()");
  214. return CarlaEngine::getDriverCount();
  215. }
  216. const char* carla_get_engine_driver_name(unsigned int index)
  217. {
  218. carla_debug("carla_get_engine_driver_name(%i)", index);
  219. return CarlaEngine::getDriverName(index);
  220. }
  221. const void* carla_get_engine_driver_options(unsigned int index)
  222. {
  223. carla_debug("carla_get_engine_driver_options(%i)", index);
  224. return nullptr;
  225. // unused
  226. (void)index;
  227. }
  228. // -------------------------------------------------------------------------------------------------------------------
  229. unsigned int carla_get_internal_plugin_count()
  230. {
  231. carla_debug("carla_get_internal_plugin_count()");
  232. #ifdef WANT_NATIVE
  233. return static_cast<unsigned int>(CarlaPlugin::getNativePluginCount());
  234. #endif
  235. return 0;
  236. }
  237. const CarlaNativePluginInfo* carla_get_internal_plugin_info(unsigned int internalPluginId)
  238. {
  239. carla_debug("carla_get_internal_plugin_info(%i)", internalPluginId);
  240. static CarlaNativePluginInfo info;
  241. #ifdef WANT_NATIVE
  242. const PluginDescriptor* const nativePlugin(CarlaPlugin::getNativePluginDescriptor(internalPluginId));
  243. // as internal plugin, this must never fail
  244. CARLA_ASSERT(nativePlugin != nullptr);
  245. if (nativePlugin == nullptr)
  246. return nullptr;
  247. info.category = static_cast<CarlaPluginCategory>(nativePlugin->category);
  248. info.hints = 0x0;
  249. if (nativePlugin->hints & PLUGIN_IS_RTSAFE)
  250. info.hints |= CarlaBackend::PLUGIN_IS_RTSAFE;
  251. if (nativePlugin->hints & PLUGIN_IS_SYNTH)
  252. info.hints |= CarlaBackend::PLUGIN_IS_SYNTH;
  253. if (nativePlugin->hints & PLUGIN_HAS_GUI)
  254. info.hints |= CarlaBackend::PLUGIN_HAS_GUI;
  255. if (nativePlugin->hints & PLUGIN_USES_SINGLE_THREAD)
  256. info.hints |= CarlaBackend::PLUGIN_HAS_SINGLE_THREAD;
  257. info.audioIns = nativePlugin->audioIns;
  258. info.audioOuts = nativePlugin->audioOuts;
  259. info.midiIns = nativePlugin->midiIns;
  260. info.midiOuts = nativePlugin->midiOuts;
  261. info.parameterIns = nativePlugin->parameterIns;
  262. info.parameterOuts = nativePlugin->parameterOuts;
  263. info.name = nativePlugin->name;
  264. info.label = nativePlugin->label;
  265. info.maker = nativePlugin->maker;
  266. info.copyright = nativePlugin->copyright;
  267. #endif
  268. return &info;
  269. #ifndef WANT_NATIVE
  270. // unused
  271. (void)internalPluginId;
  272. #endif
  273. }
  274. // -------------------------------------------------------------------------------------------------------------------
  275. bool carla_engine_init(const char* driverName, const char* clientName)
  276. {
  277. carla_debug("carla_engine_init(\"%s\", \"%s\")", driverName, clientName);
  278. CARLA_ASSERT(standalone.engine == nullptr);
  279. CARLA_ASSERT(driverName != nullptr);
  280. CARLA_ASSERT(clientName != nullptr);
  281. if (standalone.engine != nullptr)
  282. {
  283. standalone.lastError = "Engine is already running";
  284. return false;
  285. }
  286. standalone.engine = CarlaEngine::newDriverByName(driverName);
  287. if (standalone.engine == nullptr)
  288. {
  289. standalone.lastError = "The seleted audio driver is not available!";
  290. return false;
  291. }
  292. #ifndef Q_OS_WIN
  293. // TODO: make this an option, put somewhere else
  294. if (getenv("WINE_RT") == nullptr)
  295. {
  296. carla_setenv("WINE_RT", "15");
  297. carla_setenv("WINE_SVR_RT", "10");
  298. }
  299. #endif
  300. if (standalone.callback != nullptr)
  301. standalone.engine->setCallback(standalone.callback, nullptr);
  302. #ifndef BUILD_BRIDGE
  303. standalone.engine->setOption(CarlaBackend::OPTION_PROCESS_MODE, static_cast<int>(standalone.options.processMode), nullptr);
  304. # if 0 // disabled for now
  305. standalone.engine->setOption(CarlaBackend::OPTION_TRANSPORT_MODE, static_cast<int>(standalone.options.transportMode), nullptr);
  306. # endif
  307. standalone.engine->setOption(CarlaBackend::OPTION_FORCE_STEREO, standalone.options.forceStereo ? 1 : 0, nullptr);
  308. standalone.engine->setOption(CarlaBackend::OPTION_PREFER_PLUGIN_BRIDGES, standalone.options.preferPluginBridges ? 1 : 0, nullptr);
  309. standalone.engine->setOption(CarlaBackend::OPTION_PREFER_UI_BRIDGES, standalone.options.preferUiBridges ? 1 : 0, nullptr);
  310. # ifdef WANT_DSSI
  311. standalone.engine->setOption(CarlaBackend::OPTION_USE_DSSI_VST_CHUNKS, standalone.options.useDssiVstChunks ? 1 : 0, nullptr);
  312. # endif
  313. standalone.engine->setOption(CarlaBackend::OPTION_MAX_PARAMETERS, static_cast<int>(standalone.options.maxParameters), nullptr);
  314. standalone.engine->setOption(CarlaBackend::OPTION_PREFERRED_BUFFER_SIZE, static_cast<int>(standalone.options.preferredBufferSize), nullptr);
  315. standalone.engine->setOption(CarlaBackend::OPTION_PREFERRED_SAMPLE_RATE, static_cast<int>(standalone.options.preferredSampleRate), nullptr);
  316. standalone.engine->setOption(CarlaBackend::OPTION_OSC_UI_TIMEOUT, static_cast<int>(standalone.options.oscUiTimeout), nullptr);
  317. standalone.engine->setOption(CarlaBackend::OPTION_PATH_BRIDGE_NATIVE, 0, (const char*)standalone.options.bridge_native);
  318. standalone.engine->setOption(CarlaBackend::OPTION_PATH_BRIDGE_POSIX32, 0, (const char*)standalone.options.bridge_posix32);
  319. standalone.engine->setOption(CarlaBackend::OPTION_PATH_BRIDGE_POSIX64, 0, (const char*)standalone.options.bridge_posix64);
  320. standalone.engine->setOption(CarlaBackend::OPTION_PATH_BRIDGE_WIN32, 0, (const char*)standalone.options.bridge_win32);
  321. standalone.engine->setOption(CarlaBackend::OPTION_PATH_BRIDGE_WIN64, 0, (const char*)standalone.options.bridge_win64);
  322. # ifdef WANT_LV2
  323. standalone.engine->setOption(CarlaBackend::OPTION_PATH_BRIDGE_LV2_GTK2, 0, (const char*)standalone.options.bridge_lv2Gtk2);
  324. standalone.engine->setOption(CarlaBackend::OPTION_PATH_BRIDGE_LV2_GTK3, 0, (const char*)standalone.options.bridge_lv2Gtk3);
  325. standalone.engine->setOption(CarlaBackend::OPTION_PATH_BRIDGE_LV2_QT4, 0, (const char*)standalone.options.bridge_lv2Qt4);
  326. standalone.engine->setOption(CarlaBackend::OPTION_PATH_BRIDGE_LV2_QT5, 0, (const char*)standalone.options.bridge_lv2Qt5);
  327. standalone.engine->setOption(CarlaBackend::OPTION_PATH_BRIDGE_LV2_COCOA, 0, (const char*)standalone.options.bridge_lv2Cocoa);
  328. standalone.engine->setOption(CarlaBackend::OPTION_PATH_BRIDGE_LV2_WINDOWS, 0, (const char*)standalone.options.bridge_lv2Win);
  329. standalone.engine->setOption(CarlaBackend::OPTION_PATH_BRIDGE_LV2_X11, 0, (const char*)standalone.options.bridge_lv2X11);
  330. # endif
  331. # ifdef WANT_VST
  332. standalone.engine->setOption(CarlaBackend::OPTION_PATH_BRIDGE_VST_COCOA, 0, (const char*)standalone.options.bridge_vstCocoa);
  333. standalone.engine->setOption(CarlaBackend::OPTION_PATH_BRIDGE_VST_HWND, 0, (const char*)standalone.options.bridge_vstHWND);
  334. standalone.engine->setOption(CarlaBackend::OPTION_PATH_BRIDGE_VST_X11, 0, (const char*)standalone.options.bridge_vstX11);
  335. # endif
  336. if (standalone.procName.isNotEmpty())
  337. standalone.engine->setOption(CarlaBackend::OPTION_PROCESS_NAME, 0, (const char*)standalone.procName);
  338. #endif
  339. if (standalone.engine->init(clientName))
  340. {
  341. standalone.lastError = "no error";
  342. standalone.init();
  343. return true;
  344. }
  345. else
  346. {
  347. standalone.lastError = standalone.engine->getLastError();
  348. delete standalone.engine;
  349. standalone.engine = nullptr;
  350. return false;
  351. }
  352. }
  353. bool carla_engine_close()
  354. {
  355. carla_debug("carla_engine_close()");
  356. CARLA_ASSERT(standalone.engine != nullptr);
  357. if (standalone.engine == nullptr)
  358. {
  359. standalone.lastError = "Engine is not started";
  360. return false;
  361. }
  362. standalone.engine->setAboutToClose();
  363. standalone.engine->removeAllPlugins();
  364. const bool closed(standalone.engine->close());
  365. if (! closed)
  366. standalone.lastError = standalone.engine->getLastError();
  367. delete standalone.engine;
  368. standalone.engine = nullptr;
  369. standalone.close();
  370. return closed;
  371. }
  372. void carla_engine_idle()
  373. {
  374. CARLA_ASSERT(standalone.engine != nullptr);
  375. if (standalone.needsInit && standalone.app != nullptr)
  376. standalone.app->processEvents();
  377. if (standalone.engine != nullptr)
  378. standalone.engine->idle();
  379. }
  380. bool carla_is_engine_running()
  381. {
  382. carla_debug("carla_is_engine_running()");
  383. return (standalone.engine != nullptr && standalone.engine->isRunning());
  384. }
  385. void carla_set_engine_about_to_close()
  386. {
  387. carla_debug("carla_set_engine_about_to_close()");
  388. CARLA_ASSERT(standalone.engine != nullptr);
  389. if (standalone.engine != nullptr)
  390. standalone.engine->setAboutToClose();
  391. }
  392. void carla_set_engine_callback(CarlaCallbackFunc func, void* ptr)
  393. {
  394. carla_debug("carla_set_engine_callback(%p)", func);
  395. standalone.callback = func;
  396. standalone.callbackPtr = ptr;
  397. if (standalone.engine != nullptr)
  398. standalone.engine->setCallback(func, ptr);
  399. }
  400. void carla_set_engine_option(CarlaOptionsType option, int value, const char* valueStr)
  401. {
  402. carla_debug("carla_set_engine_option(%s, %i, \"%s\")", CarlaBackend::OptionsType2Str(option), value, valueStr);
  403. switch (option)
  404. {
  405. case CarlaBackend::OPTION_PROCESS_NAME:
  406. standalone.procName = valueStr;
  407. break;
  408. case CarlaBackend::OPTION_PROCESS_MODE:
  409. if (value < CarlaBackend::PROCESS_MODE_SINGLE_CLIENT || value > CarlaBackend::PROCESS_MODE_PATCHBAY)
  410. return carla_stderr2("carla_set_engine_option(OPTION_PROCESS_MODE, %i, \"%s\") - invalid value", value, valueStr);
  411. standalone.options.processMode = static_cast<CarlaBackend::ProcessMode>(value);
  412. break;
  413. case CarlaBackend::OPTION_TRANSPORT_MODE:
  414. #if 0 // disabled for now
  415. if (value < CarlaBackend::TRANSPORT_MODE_INTERNAL || value > CarlaBackend::TRANSPORT_MODE_JACK)
  416. return carla_stderr2("carla_set_engine_option(OPTION_TRANSPORT_MODE, %i, \"%s\") - invalid value", value, valueStr);
  417. standalone.options.transportMode = static_cast<CarlaBackend::TransportMode>(value);
  418. #endif
  419. break;
  420. case CarlaBackend::OPTION_FORCE_STEREO:
  421. standalone.options.forceStereo = (value != 0);
  422. break;
  423. case CarlaBackend::OPTION_PREFER_PLUGIN_BRIDGES:
  424. standalone.options.preferPluginBridges = (value != 0);
  425. break;
  426. case CarlaBackend::OPTION_PREFER_UI_BRIDGES:
  427. standalone.options.preferUiBridges = (value != 0);
  428. break;
  429. #ifdef WANT_DSSI
  430. case CarlaBackend::OPTION_USE_DSSI_VST_CHUNKS:
  431. standalone.options.useDssiVstChunks = (value != 0);
  432. break;
  433. #endif
  434. case CarlaBackend::OPTION_MAX_PARAMETERS:
  435. if (value <= 0)
  436. return carla_stderr2("carla_set_engine_option(OPTION_MAX_PARAMETERS, %i, \"%s\") - invalid value", value, valueStr);
  437. standalone.options.maxParameters = static_cast<unsigned int>(value);
  438. break;
  439. case CarlaBackend::OPTION_OSC_UI_TIMEOUT:
  440. if (value <= 0)
  441. return carla_stderr2("carla_set_engine_option(OPTION_OSC_UI_TIMEOUT, %i, \"%s\") - invalid value", value, valueStr);
  442. standalone.options.oscUiTimeout = static_cast<unsigned int>(value);
  443. break;
  444. case CarlaBackend::OPTION_PREFERRED_BUFFER_SIZE:
  445. if (value <= 0)
  446. return carla_stderr2("carla_set_engine_option(OPTION_PREFERRED_BUFFER_SIZE, %i, \"%s\") - invalid value", value, valueStr);
  447. standalone.options.preferredBufferSize = static_cast<unsigned int>(value);
  448. break;
  449. case CarlaBackend::OPTION_PREFERRED_SAMPLE_RATE:
  450. if (value <= 0)
  451. return carla_stderr2("carla_set_engine_option(OPTION_PREFERRED_SAMPLE_RATE, %i, \"%s\") - invalid value", value, valueStr);
  452. standalone.options.preferredSampleRate = static_cast<unsigned int>(value);
  453. break;
  454. #ifndef BUILD_BRIDGE
  455. case CarlaBackend::OPTION_PATH_BRIDGE_NATIVE:
  456. standalone.options.bridge_native = valueStr;
  457. break;
  458. case CarlaBackend::OPTION_PATH_BRIDGE_POSIX32:
  459. standalone.options.bridge_posix32 = valueStr;
  460. break;
  461. case CarlaBackend::OPTION_PATH_BRIDGE_POSIX64:
  462. standalone.options.bridge_posix64 = valueStr;
  463. break;
  464. case CarlaBackend::OPTION_PATH_BRIDGE_WIN32:
  465. standalone.options.bridge_win32 = valueStr;
  466. break;
  467. case CarlaBackend::OPTION_PATH_BRIDGE_WIN64:
  468. standalone.options.bridge_win64 = valueStr;
  469. break;
  470. #endif
  471. #ifdef WANT_LV2
  472. case CarlaBackend::OPTION_PATH_BRIDGE_LV2_GTK2:
  473. standalone.options.bridge_lv2Gtk2 = valueStr;
  474. break;
  475. case CarlaBackend::OPTION_PATH_BRIDGE_LV2_GTK3:
  476. standalone.options.bridge_lv2Gtk3 = valueStr;
  477. break;
  478. case CarlaBackend::OPTION_PATH_BRIDGE_LV2_QT4:
  479. standalone.options.bridge_lv2Qt4 = valueStr;
  480. break;
  481. case CarlaBackend::OPTION_PATH_BRIDGE_LV2_QT5:
  482. standalone.options.bridge_lv2Qt5 = valueStr;
  483. break;
  484. case CarlaBackend::OPTION_PATH_BRIDGE_LV2_COCOA:
  485. standalone.options.bridge_lv2Cocoa = valueStr;
  486. break;
  487. case CarlaBackend::OPTION_PATH_BRIDGE_LV2_WINDOWS:
  488. standalone.options.bridge_lv2Win = valueStr;
  489. break;
  490. case CarlaBackend::OPTION_PATH_BRIDGE_LV2_X11:
  491. standalone.options.bridge_lv2X11 = valueStr;
  492. break;
  493. #endif
  494. #ifdef WANT_VST
  495. case CarlaBackend::OPTION_PATH_BRIDGE_VST_COCOA:
  496. standalone.options.bridge_vstCocoa = valueStr;
  497. break;
  498. case CarlaBackend::OPTION_PATH_BRIDGE_VST_HWND:
  499. standalone.options.bridge_vstHWND = valueStr;
  500. break;
  501. case CarlaBackend::OPTION_PATH_BRIDGE_VST_X11:
  502. standalone.options.bridge_vstX11 = valueStr;
  503. break;
  504. #endif
  505. }
  506. if (standalone.engine != nullptr)
  507. standalone.engine->setOption(option, value, valueStr);
  508. }
  509. // -------------------------------------------------------------------------------------------------------------------
  510. bool carla_load_filename(const char* filename)
  511. {
  512. carla_debug("carla_load_filename(\"%s\")", filename);
  513. CARLA_ASSERT(standalone.engine != nullptr);
  514. CARLA_ASSERT(filename != nullptr);
  515. if (standalone.engine != nullptr && standalone.engine->isRunning())
  516. return standalone.engine->loadFilename(filename);
  517. standalone.lastError = "Engine is not started";
  518. return false;
  519. }
  520. bool carla_load_project(const char* filename)
  521. {
  522. carla_debug("carla_load_project(\"%s\")", filename);
  523. CARLA_ASSERT(standalone.engine != nullptr);
  524. CARLA_ASSERT(filename != nullptr);
  525. if (standalone.engine != nullptr && standalone.engine->isRunning())
  526. return standalone.engine->loadProject(filename);
  527. standalone.lastError = "Engine is not started";
  528. return false;
  529. }
  530. bool carla_save_project(const char* filename)
  531. {
  532. carla_debug("carla_save_project(\"%s\")", filename);
  533. CARLA_ASSERT(standalone.engine != nullptr);
  534. CARLA_ASSERT(filename != nullptr);
  535. if (standalone.engine != nullptr) // allow to save even if engine stopped
  536. return standalone.engine->saveProject(filename);
  537. standalone.lastError = "Engine is not started";
  538. return false;
  539. }
  540. // -------------------------------------------------------------------------------------------------------------------
  541. bool carla_patchbay_connect(int portA, int portB)
  542. {
  543. carla_debug("carla_patchbay_connect(%i, %i)", portA, portB);
  544. CARLA_ASSERT(standalone.engine != nullptr);
  545. if (standalone.engine != nullptr && standalone.engine->isRunning())
  546. return standalone.engine->patchbayConnect(portA, portB);
  547. standalone.lastError = "Engine is not started";
  548. return false;
  549. }
  550. bool carla_patchbay_disconnect(int connectionId)
  551. {
  552. carla_debug("carla_patchbay_disconnect(%i)", connectionId);
  553. CARLA_ASSERT(standalone.engine != nullptr);
  554. if (standalone.engine != nullptr && standalone.engine->isRunning())
  555. return standalone.engine->patchbayDisconnect(connectionId);
  556. standalone.lastError = "Engine is not started";
  557. return false;
  558. }
  559. void carla_patchbay_refresh()
  560. {
  561. carla_debug("carla_patchbay_refresh()");
  562. CARLA_ASSERT(standalone.engine != nullptr);
  563. if (standalone.engine != nullptr && standalone.engine->isRunning())
  564. standalone.engine->patchbayRefresh();
  565. }
  566. // -------------------------------------------------------------------------------------------------------------------
  567. void carla_transport_play()
  568. {
  569. carla_debug("carla_transport_play()");
  570. CARLA_ASSERT(standalone.engine != nullptr);
  571. if (standalone.engine != nullptr && standalone.engine->isRunning())
  572. standalone.engine->transportPlay();
  573. }
  574. void carla_transport_pause()
  575. {
  576. carla_debug("carla_transport_pause()");
  577. CARLA_ASSERT(standalone.engine != nullptr);
  578. if (standalone.engine != nullptr && standalone.engine->isRunning())
  579. standalone.engine->transportPause();
  580. }
  581. void carla_transport_relocate(uint32_t frames)
  582. {
  583. carla_debug("carla_transport_relocate(%i)", frames);
  584. CARLA_ASSERT(standalone.engine != nullptr);
  585. if (standalone.engine != nullptr && standalone.engine->isRunning())
  586. standalone.engine->transportRelocate(frames);
  587. }
  588. uint32_t carla_get_current_transport_frame()
  589. {
  590. CARLA_ASSERT(standalone.engine != nullptr);
  591. if (standalone.engine != nullptr)
  592. {
  593. const EngineTimeInfo& timeInfo(standalone.engine->getTimeInfo());
  594. return timeInfo.frame;
  595. }
  596. return 0;
  597. }
  598. const CarlaTransportInfo* carla_get_transport_info()
  599. {
  600. CARLA_ASSERT(standalone.engine != nullptr);
  601. static CarlaTransportInfo info;
  602. if (standalone.engine != nullptr)
  603. {
  604. const EngineTimeInfo& timeInfo(standalone.engine->getTimeInfo());
  605. info.playing = timeInfo.playing;
  606. info.frame = timeInfo.frame;
  607. if (timeInfo.valid & timeInfo.ValidBBT)
  608. {
  609. info.bar = timeInfo.bbt.bar;
  610. info.beat = timeInfo.bbt.beat;
  611. info.tick = timeInfo.bbt.tick;
  612. info.bpm = timeInfo.bbt.beatsPerMinute;
  613. }
  614. else
  615. {
  616. info.bar = 0;
  617. info.beat = 0;
  618. info.tick = 0;
  619. info.bpm = 0.0;
  620. }
  621. }
  622. else
  623. {
  624. info.playing = false;
  625. info.frame = 0;
  626. info.bar = 0;
  627. info.beat = 0;
  628. info.tick = 0;
  629. info.bpm = 0.0;
  630. }
  631. return &info;
  632. }
  633. // -------------------------------------------------------------------------------------------------------------------
  634. bool carla_add_plugin(CarlaBinaryType btype, CarlaPluginType ptype, const char* filename, const char* const name, const char* label, const void* extraStuff)
  635. {
  636. carla_debug("carla_add_plugin(%s, %s, \"%s\", \"%s\", \"%s\", %p)", CarlaBackend::BinaryType2Str(btype), CarlaBackend::PluginType2Str(ptype), filename, name, label, extraStuff);
  637. CARLA_ASSERT(standalone.engine != nullptr);
  638. if (standalone.engine != nullptr && standalone.engine->isRunning())
  639. return standalone.engine->addPlugin(btype, ptype, filename, name, label, extraStuff);
  640. standalone.lastError = "Engine is not started";
  641. return false;
  642. }
  643. bool carla_remove_plugin(unsigned int pluginId)
  644. {
  645. carla_debug("carla_remove_plugin(%i)", pluginId);
  646. CARLA_ASSERT(standalone.engine != nullptr);
  647. if (standalone.engine != nullptr && standalone.engine->isRunning())
  648. return standalone.engine->removePlugin(pluginId);
  649. standalone.lastError = "Engine is not started";
  650. return false;
  651. }
  652. void carla_remove_all_plugins()
  653. {
  654. carla_debug("carla_remove_all_plugins()");
  655. CARLA_ASSERT(standalone.engine != nullptr);
  656. if (standalone.engine != nullptr && standalone.engine->isRunning())
  657. standalone.engine->removeAllPlugins();
  658. }
  659. const char* carla_rename_plugin(unsigned int pluginId, const char* newName)
  660. {
  661. carla_debug("carla_rename_plugin(%i, \"%s\")", pluginId, newName);
  662. CARLA_ASSERT(standalone.engine != nullptr);
  663. if (standalone.engine != nullptr && standalone.engine->isRunning())
  664. return standalone.engine->renamePlugin(pluginId, newName);
  665. standalone.lastError = "Engine is not started";
  666. return nullptr;
  667. }
  668. bool carla_clone_plugin(unsigned int pluginId)
  669. {
  670. carla_debug("carla_clone_plugin(%i)", pluginId);
  671. CARLA_ASSERT(standalone.engine != nullptr);
  672. if (standalone.engine != nullptr && standalone.engine->isRunning())
  673. return standalone.engine->clonePlugin(pluginId);
  674. standalone.lastError = "Engine is not started";
  675. return false;
  676. }
  677. bool carla_replace_plugin(unsigned int pluginId)
  678. {
  679. carla_debug("carla_replace_plugin(%i)", pluginId);
  680. CARLA_ASSERT(standalone.engine != nullptr);
  681. if (standalone.engine != nullptr && standalone.engine->isRunning())
  682. return standalone.engine->replacePlugin(pluginId);
  683. standalone.lastError = "Engine is not started";
  684. return false;
  685. }
  686. bool carla_switch_plugins(unsigned int pluginIdA, unsigned int pluginIdB)
  687. {
  688. carla_debug("carla_switch_plugins(%i, %i)", pluginIdA, pluginIdB);
  689. CARLA_ASSERT(standalone.engine != nullptr);
  690. if (standalone.engine != nullptr && standalone.engine->isRunning())
  691. return standalone.engine->switchPlugins(pluginIdA, pluginIdB);
  692. standalone.lastError = "Engine is not started";
  693. return false;
  694. }
  695. // -------------------------------------------------------------------------------------------------------------------
  696. bool carla_load_plugin_state(unsigned int pluginId, const char* filename)
  697. {
  698. carla_debug("carla_load_plugin_state(%i, \"%s\")", pluginId, filename);
  699. CARLA_ASSERT(standalone.engine != nullptr);
  700. if (standalone.engine == nullptr || ! standalone.engine->isRunning())
  701. {
  702. standalone.lastError = "Engine is not started";
  703. return false;
  704. }
  705. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  706. return plugin->loadStateFromFile(filename);
  707. carla_stderr2("carla_load_plugin_state(%i, \"%s\") - could not find plugin", pluginId, filename);
  708. return false;
  709. }
  710. bool carla_save_plugin_state(unsigned int pluginId, const char* filename)
  711. {
  712. carla_debug("carla_save_plugin_state(%i, \"%s\")", pluginId, filename);
  713. CARLA_ASSERT(standalone.engine != nullptr);
  714. if (standalone.engine == nullptr)
  715. {
  716. standalone.lastError = "Engine is not started";
  717. return false;
  718. }
  719. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  720. return plugin->saveStateToFile(filename);
  721. carla_stderr2("carla_save_plugin_state(%i, \"%s\") - could not find plugin", pluginId, filename);
  722. return false;
  723. }
  724. // -------------------------------------------------------------------------------------------------------------------
  725. const CarlaPluginInfo* carla_get_plugin_info(unsigned int pluginId)
  726. {
  727. carla_debug("carla_get_plugin_info(%i)", pluginId);
  728. CARLA_ASSERT(standalone.engine != nullptr);
  729. static CarlaPluginInfo info;
  730. // reset
  731. info.type = CarlaBackend::PLUGIN_NONE;
  732. info.category = CarlaBackend::PLUGIN_CATEGORY_NONE;
  733. info.hints = 0x0;
  734. info.hints = 0x0;
  735. info.binary = nullptr;
  736. info.name = nullptr;
  737. info.uniqueId = 0;
  738. info.latency = 0;
  739. info.optionsAvailable = 0x0;
  740. info.optionsEnabled = 0x0;
  741. // cleanup
  742. if (info.label != nullptr)
  743. {
  744. delete[] info.label;
  745. info.label = nullptr;
  746. }
  747. if (info.maker != nullptr)
  748. {
  749. delete[] info.maker;
  750. info.maker = nullptr;
  751. }
  752. if (info.copyright != nullptr)
  753. {
  754. delete[] info.copyright;
  755. info.copyright = nullptr;
  756. }
  757. if (standalone.engine == nullptr)
  758. return &info;
  759. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  760. {
  761. char strBufLabel[STR_MAX+1] = { '\0' };
  762. char strBufMaker[STR_MAX+1] = { '\0' };
  763. char strBufCopyright[STR_MAX+1] = { '\0' };
  764. info.type = plugin->type();
  765. info.category = plugin->category();
  766. info.hints = plugin->hints();
  767. info.binary = plugin->filename();
  768. info.name = plugin->name();
  769. info.uniqueId = plugin->uniqueId();
  770. info.latency = plugin->latency();
  771. info.optionsAvailable = plugin->availableOptions();
  772. info.optionsEnabled = plugin->options();
  773. plugin->getLabel(strBufLabel);
  774. info.label = carla_strdup(strBufLabel);
  775. plugin->getMaker(strBufMaker);
  776. info.maker = carla_strdup(strBufMaker);
  777. plugin->getCopyright(strBufCopyright);
  778. info.copyright = carla_strdup(strBufCopyright);
  779. return &info;
  780. }
  781. carla_stderr2("carla_get_plugin_info(%i) - could not find plugin", pluginId);
  782. return &info;
  783. }
  784. const CarlaPortCountInfo* carla_get_audio_port_count_info(unsigned int pluginId)
  785. {
  786. carla_debug("carla_get_audio_port_count_info(%i)", pluginId);
  787. CARLA_ASSERT(standalone.engine != nullptr);
  788. static CarlaPortCountInfo info;
  789. // reset
  790. info.ins = 0;
  791. info.outs = 0;
  792. info.total = 0;
  793. if (standalone.engine == nullptr)
  794. return &info;
  795. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  796. {
  797. info.ins = plugin->audioInCount();
  798. info.outs = plugin->audioOutCount();
  799. info.total = info.ins + info.outs;
  800. return &info;
  801. }
  802. carla_stderr2("carla_get_audio_port_count_info(%i) - could not find plugin", pluginId);
  803. return &info;
  804. }
  805. const CarlaPortCountInfo* carla_get_midi_port_count_info(unsigned int pluginId)
  806. {
  807. carla_debug("carla_get_midi_port_count_info(%i)", pluginId);
  808. CARLA_ASSERT(standalone.engine != nullptr);
  809. static CarlaPortCountInfo info;
  810. // reset
  811. info.ins = 0;
  812. info.outs = 0;
  813. info.total = 0;
  814. if (standalone.engine == nullptr)
  815. return &info;
  816. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  817. {
  818. info.ins = plugin->midiInCount();
  819. info.outs = plugin->midiOutCount();
  820. info.total = info.ins + info.outs;
  821. return &info;
  822. }
  823. carla_stderr2("carla_get_midi_port_count_info(%i) - could not find plugin", pluginId);
  824. return &info;
  825. }
  826. const CarlaPortCountInfo* carla_get_parameter_count_info(unsigned int pluginId)
  827. {
  828. carla_debug("carla_get_parameter_count_info(%i)", pluginId);
  829. CARLA_ASSERT(standalone.engine != nullptr);
  830. static CarlaPortCountInfo info;
  831. // reset
  832. info.ins = 0;
  833. info.outs = 0;
  834. info.total = 0;
  835. if (standalone.engine == nullptr)
  836. return &info;
  837. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  838. {
  839. plugin->getParameterCountInfo(&info.ins, &info.outs, &info.total);
  840. return &info;
  841. }
  842. carla_stderr2("carla_get_parameter_count_info(%i) - could not find plugin", pluginId);
  843. return &info;
  844. }
  845. const CarlaParameterInfo* carla_get_parameter_info(unsigned int pluginId, uint32_t parameterId)
  846. {
  847. carla_debug("carla_get_parameter_info(%i, %i)", pluginId, parameterId);
  848. CARLA_ASSERT(standalone.engine != nullptr);
  849. static CarlaParameterInfo info;
  850. // reset
  851. info.scalePointCount = 0;
  852. // cleanup
  853. if (info.name != nullptr)
  854. {
  855. delete[] info.name;
  856. info.name = nullptr;
  857. }
  858. if (info.symbol != nullptr)
  859. {
  860. delete[] info.symbol;
  861. info.symbol = nullptr;
  862. }
  863. if (info.unit != nullptr)
  864. {
  865. delete[] info.unit;
  866. info.unit = nullptr;
  867. }
  868. if (standalone.engine == nullptr)
  869. return &info;
  870. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  871. {
  872. if (parameterId < plugin->parameterCount())
  873. {
  874. char strBufName[STR_MAX+1] = { '\0' };
  875. char strBufSymbol[STR_MAX+1] = { '\0' };
  876. char strBufUnit[STR_MAX+1] = { '\0' };
  877. info.scalePointCount = plugin->parameterScalePointCount(parameterId);
  878. plugin->getParameterName(parameterId, strBufName);
  879. info.name = carla_strdup(strBufName);
  880. plugin->getParameterSymbol(parameterId, strBufSymbol);
  881. info.symbol = carla_strdup(strBufSymbol);
  882. plugin->getParameterUnit(parameterId, strBufUnit);
  883. info.unit = carla_strdup(strBufUnit);
  884. }
  885. else
  886. carla_stderr2("carla_get_parameter_info(%i, %i) - parameterId out of bounds", pluginId, parameterId);
  887. return &info;
  888. }
  889. carla_stderr2("carla_get_parameter_info(%i, %i) - could not find plugin", pluginId, parameterId);
  890. return &info;
  891. }
  892. const CarlaScalePointInfo* carla_get_parameter_scalepoint_info(unsigned int pluginId, uint32_t parameterId, uint32_t scalePointId)
  893. {
  894. carla_debug("carla_get_parameter_scalepoint_info(%i, %i, %i)", pluginId, parameterId, scalePointId);
  895. CARLA_ASSERT(standalone.engine != nullptr);
  896. static CarlaScalePointInfo info;
  897. // reset
  898. info.value = 0.0f;
  899. // cleanup
  900. if (info.label != nullptr)
  901. {
  902. delete[] info.label;
  903. info.label = nullptr;
  904. }
  905. if (standalone.engine == nullptr)
  906. return &info;
  907. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  908. {
  909. if (parameterId < plugin->parameterCount())
  910. {
  911. if (scalePointId < plugin->parameterScalePointCount(parameterId))
  912. {
  913. char strBufLabel[STR_MAX+1] = { '\0' };
  914. info.value = plugin->getParameterScalePointValue(parameterId, scalePointId);
  915. plugin->getParameterScalePointLabel(parameterId, scalePointId, strBufLabel);
  916. info.label = carla_strdup(strBufLabel);
  917. }
  918. else
  919. carla_stderr2("carla_get_parameter_scalepoint_info(%i, %i, %i) - scalePointId out of bounds", pluginId, parameterId, scalePointId);
  920. }
  921. else
  922. carla_stderr2("carla_get_parameter_scalepoint_info(%i, %i, %i) - parameterId out of bounds", pluginId, parameterId, scalePointId);
  923. return &info;
  924. }
  925. carla_stderr2("carla_get_parameter_scalepoint_info(%i, %i, %i) - could not find plugin", pluginId, parameterId, scalePointId);
  926. return &info;
  927. }
  928. // -------------------------------------------------------------------------------------------------------------------
  929. const CarlaParameterData* carla_get_parameter_data(unsigned int pluginId, uint32_t parameterId)
  930. {
  931. carla_debug("carla_get_parameter_data(%i, %i)", pluginId, parameterId);
  932. CARLA_ASSERT(standalone.engine != nullptr);
  933. static CarlaParameterData data;
  934. if (standalone.engine == nullptr)
  935. return &data;
  936. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  937. {
  938. if (parameterId < plugin->parameterCount())
  939. return &plugin->parameterData(parameterId);
  940. carla_stderr2("carla_get_parameter_data(%i, %i) - parameterId out of bounds", pluginId, parameterId);
  941. return &data;
  942. }
  943. carla_stderr2("carla_get_parameter_data(%i, %i) - could not find plugin", pluginId, parameterId);
  944. return &data;
  945. }
  946. const CarlaParameterRanges* carla_get_parameter_ranges(unsigned int pluginId, uint32_t parameterId)
  947. {
  948. carla_debug("carla_get_parameter_ranges(%i, %i)", pluginId, parameterId);
  949. CARLA_ASSERT(standalone.engine != nullptr);
  950. static CarlaParameterRanges ranges;
  951. if (standalone.engine == nullptr)
  952. return &ranges;
  953. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  954. {
  955. if (parameterId < plugin->parameterCount())
  956. return &plugin->parameterRanges(parameterId);
  957. carla_stderr2("carla_get_parameter_ranges(%i, %i) - parameterId out of bounds", pluginId, parameterId);
  958. return &ranges;
  959. }
  960. carla_stderr2("carla_get_parameter_ranges(%i, %i) - could not find plugin", pluginId, parameterId);
  961. return &ranges;
  962. }
  963. const CarlaMidiProgramData* carla_get_midi_program_data(unsigned int pluginId, uint32_t midiProgramId)
  964. {
  965. carla_debug("carla_get_midi_program_data(%i, %i)", pluginId, midiProgramId);
  966. CARLA_ASSERT(standalone.engine != nullptr);
  967. static CarlaMidiProgramData data;
  968. if (standalone.engine == nullptr)
  969. return &data;
  970. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  971. {
  972. if (midiProgramId < plugin->midiProgramCount())
  973. return &plugin->midiProgramData(midiProgramId);
  974. carla_stderr2("carla_get_midi_program_data(%i, %i) - midiProgramId out of bounds", pluginId, midiProgramId);
  975. return &data;
  976. }
  977. carla_stderr2("carla_get_midi_program_data(%i, %i) - could not find plugin", pluginId, midiProgramId);
  978. return &data;
  979. }
  980. const CarlaCustomData* carla_get_custom_data(unsigned int pluginId, uint32_t customDataId)
  981. {
  982. carla_debug("carla_get_custom_data(%i, %i)", pluginId, customDataId);
  983. CARLA_ASSERT(standalone.engine != nullptr);
  984. static CarlaCustomData data;
  985. if (standalone.engine == nullptr)
  986. return &data;
  987. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  988. {
  989. if (customDataId < plugin->customDataCount())
  990. return &plugin->customData(customDataId);
  991. carla_stderr2("carla_get_custom_data(%i, %i) - customDataId out of bounds", pluginId, customDataId);
  992. return &data;
  993. }
  994. carla_stderr2("carla_get_custom_data(%i, %i) - could not find plugin", pluginId, customDataId);
  995. return &data;
  996. }
  997. const char* carla_get_chunk_data(unsigned int pluginId)
  998. {
  999. carla_debug("carla_get_chunk_data(%i)", pluginId);
  1000. CARLA_ASSERT(standalone.engine != nullptr);
  1001. if (standalone.engine == nullptr)
  1002. return nullptr;
  1003. static CarlaString chunkData;
  1004. // cleanup
  1005. chunkData.clear();
  1006. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1007. {
  1008. if (plugin->options() & CarlaBackend::PLUGIN_OPTION_USE_CHUNKS)
  1009. {
  1010. void* data = nullptr;
  1011. const int32_t dataSize = plugin->chunkData(&data);
  1012. if (data != nullptr && dataSize > 0)
  1013. {
  1014. QByteArray chunk(QByteArray((char*)data, dataSize).toBase64());
  1015. chunkData = chunk.constData();
  1016. return (const char*)chunkData;
  1017. }
  1018. else
  1019. carla_stderr2("carla_get_chunk_data(%i) - got invalid chunk data", pluginId);
  1020. }
  1021. else
  1022. carla_stderr2("carla_get_chunk_data(%i) - plugin does not support chunks", pluginId);
  1023. return nullptr;
  1024. }
  1025. carla_stderr2("carla_get_chunk_data(%i) - could not find plugin", pluginId);
  1026. return nullptr;
  1027. }
  1028. // -------------------------------------------------------------------------------------------------------------------
  1029. uint32_t carla_get_parameter_count(unsigned int pluginId)
  1030. {
  1031. carla_debug("carla_get_parameter_count(%i)", pluginId);
  1032. CARLA_ASSERT(standalone.engine != nullptr);
  1033. if (standalone.engine == nullptr)
  1034. return 0;
  1035. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1036. return plugin->parameterCount();
  1037. carla_stderr2("carla_get_parameter_count(%i) - could not find plugin", pluginId);
  1038. return 0;
  1039. }
  1040. uint32_t carla_get_program_count(unsigned int pluginId)
  1041. {
  1042. carla_debug("carla_get_program_count(%i)", pluginId);
  1043. CARLA_ASSERT(standalone.engine != nullptr);
  1044. if (standalone.engine == nullptr)
  1045. return 0;
  1046. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1047. return plugin->programCount();
  1048. carla_stderr2("carla_get_program_count(%i) - could not find plugin", pluginId);
  1049. return 0;
  1050. }
  1051. uint32_t carla_get_midi_program_count(unsigned int pluginId)
  1052. {
  1053. carla_debug("carla_get_midi_program_count(%i)", pluginId);
  1054. CARLA_ASSERT(standalone.engine != nullptr);
  1055. if (standalone.engine == nullptr)
  1056. return 0;
  1057. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1058. return plugin->midiProgramCount();
  1059. carla_stderr2("carla_get_midi_program_count(%i) - could not find plugin", pluginId);
  1060. return 0;
  1061. }
  1062. uint32_t carla_get_custom_data_count(unsigned int pluginId)
  1063. {
  1064. carla_debug("carla_get_custom_data_count(%i)", pluginId);
  1065. CARLA_ASSERT(standalone.engine != nullptr);
  1066. if (standalone.engine == nullptr)
  1067. return 0;
  1068. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1069. return plugin->customDataCount();
  1070. carla_stderr2("carla_get_custom_data_count(%i) - could not find plugin", pluginId);
  1071. return 0;
  1072. }
  1073. // -------------------------------------------------------------------------------------------------------------------
  1074. const char* carla_get_parameter_text(unsigned int pluginId, uint32_t parameterId)
  1075. {
  1076. carla_debug("carla_get_parameter_text(%i, %i)", pluginId, parameterId);
  1077. CARLA_ASSERT(standalone.engine != nullptr);
  1078. if (standalone.engine == nullptr)
  1079. return nullptr;
  1080. static char textBuf[STR_MAX+1];
  1081. carla_fill<char>(textBuf, STR_MAX+1, '\0');
  1082. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1083. {
  1084. if (parameterId < plugin->parameterCount())
  1085. {
  1086. plugin->getParameterText(parameterId, textBuf);
  1087. return textBuf;
  1088. }
  1089. carla_stderr2("carla_get_parameter_text(%i, %i) - parameterId out of bounds", pluginId, parameterId);
  1090. return nullptr;
  1091. }
  1092. carla_stderr2("carla_get_parameter_text(%i, %i) - could not find plugin", pluginId, parameterId);
  1093. return nullptr;
  1094. }
  1095. const char* carla_get_program_name(unsigned int pluginId, uint32_t programId)
  1096. {
  1097. carla_debug("carla_get_program_name(%i, %i)", pluginId, programId);
  1098. CARLA_ASSERT(standalone.engine != nullptr);
  1099. if (standalone.engine == nullptr)
  1100. return nullptr;
  1101. static char programName[STR_MAX+1];
  1102. carla_fill<char>(programName, STR_MAX+1, '\0');
  1103. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1104. {
  1105. if (programId < plugin->programCount())
  1106. {
  1107. plugin->getProgramName(programId, programName);
  1108. return programName;
  1109. }
  1110. carla_stderr2("carla_get_program_name(%i, %i) - programId out of bounds", pluginId, programId);
  1111. return nullptr;
  1112. }
  1113. carla_stderr2("carla_get_program_name(%i, %i) - could not find plugin", pluginId, programId);
  1114. return nullptr;
  1115. }
  1116. const char* carla_get_midi_program_name(unsigned int pluginId, uint32_t midiProgramId)
  1117. {
  1118. carla_debug("carla_get_midi_program_name(%i, %i)", pluginId, midiProgramId);
  1119. CARLA_ASSERT(standalone.engine != nullptr);
  1120. if (standalone.engine == nullptr)
  1121. return nullptr;
  1122. static char midiProgramName[STR_MAX+1];
  1123. carla_fill<char>(midiProgramName, STR_MAX+1, '\0');
  1124. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1125. {
  1126. if (midiProgramId < plugin->midiProgramCount())
  1127. {
  1128. plugin->getMidiProgramName(midiProgramId, midiProgramName);
  1129. return midiProgramName;
  1130. }
  1131. carla_stderr2("carla_get_midi_program_name(%i, %i) - midiProgramId out of bounds", pluginId, midiProgramId);
  1132. return nullptr;
  1133. }
  1134. carla_stderr2("carla_get_midi_program_name(%i, %i) - could not find plugin", pluginId, midiProgramId);
  1135. return nullptr;
  1136. }
  1137. const char* carla_get_real_plugin_name(unsigned int pluginId)
  1138. {
  1139. carla_debug("carla_get_real_plugin_name(%i)", pluginId);
  1140. CARLA_ASSERT(standalone.engine != nullptr);
  1141. if (standalone.engine == nullptr)
  1142. return nullptr;
  1143. static char realPluginName[STR_MAX+1];
  1144. carla_fill<char>(realPluginName, STR_MAX+1, '\0');
  1145. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1146. {
  1147. plugin->getRealName(realPluginName);
  1148. return realPluginName;
  1149. }
  1150. carla_stderr2("carla_get_real_plugin_name(%i) - could not find plugin", pluginId);
  1151. return nullptr;
  1152. }
  1153. // -------------------------------------------------------------------------------------------------------------------
  1154. int32_t carla_get_current_program_index(unsigned int pluginId)
  1155. {
  1156. carla_debug("carla_get_current_program_index(%i)", pluginId);
  1157. CARLA_ASSERT(standalone.engine != nullptr);
  1158. if (standalone.engine == nullptr)
  1159. return -1;
  1160. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1161. return plugin->currentProgram();
  1162. carla_stderr2("carla_get_current_program_index(%i) - could not find plugin", pluginId);
  1163. return -1;
  1164. }
  1165. int32_t carla_get_current_midi_program_index(unsigned int pluginId)
  1166. {
  1167. carla_debug("carla_get_current_midi_program_index(%i)", pluginId);
  1168. CARLA_ASSERT(standalone.engine != nullptr);
  1169. if (standalone.engine == nullptr)
  1170. return -1;
  1171. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1172. return plugin->currentMidiProgram();
  1173. carla_stderr2("carla_get_current_midi_program_index(%i) - could not find plugin", pluginId);
  1174. return -1;
  1175. }
  1176. // -------------------------------------------------------------------------------------------------------------------
  1177. float carla_get_default_parameter_value(unsigned int pluginId, uint32_t parameterId)
  1178. {
  1179. carla_debug("carla_get_default_parameter_value(%i, %i)", pluginId, parameterId);
  1180. CARLA_ASSERT(standalone.engine != nullptr);
  1181. if (standalone.engine == nullptr)
  1182. return 0.0f;
  1183. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1184. {
  1185. if (parameterId < plugin->parameterCount())
  1186. return plugin->parameterRanges(parameterId).def;
  1187. carla_stderr2("carla_get_default_parameter_value(%i, %i) - parameterId out of bounds", pluginId, parameterId);
  1188. return 0.0f;
  1189. }
  1190. carla_stderr2("carla_get_default_parameter_value(%i, %i) - could not find plugin", pluginId, parameterId);
  1191. return 0.0f;
  1192. }
  1193. float carla_get_current_parameter_value(unsigned int pluginId, uint32_t parameterId)
  1194. {
  1195. carla_debug("carla_get_current_parameter_value(%i, %i)", pluginId, parameterId);
  1196. CARLA_ASSERT(standalone.engine != nullptr);
  1197. if (standalone.engine == nullptr)
  1198. return 0.0f;
  1199. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1200. {
  1201. if (parameterId < plugin->parameterCount())
  1202. return plugin->getParameterValue(parameterId);
  1203. carla_stderr2("carla_get_current_parameter_value(%i, %i) - parameterId out of bounds", pluginId, parameterId);
  1204. return 0.0f;
  1205. }
  1206. carla_stderr2("carla_get_current_parameter_value(%i, %i) - could not find plugin", pluginId, parameterId);
  1207. return 0.0f;
  1208. }
  1209. // -------------------------------------------------------------------------------------------------------------------
  1210. float carla_get_input_peak_value(unsigned int pluginId, unsigned short portId)
  1211. {
  1212. CARLA_ASSERT(standalone.engine != nullptr);
  1213. CARLA_ASSERT(portId == 1 || portId == 2);
  1214. if (standalone.engine == nullptr)
  1215. return 0.0f;
  1216. return standalone.engine->getInputPeak(pluginId, portId);
  1217. }
  1218. float carla_get_output_peak_value(unsigned int pluginId, unsigned short portId)
  1219. {
  1220. CARLA_ASSERT(standalone.engine != nullptr);
  1221. CARLA_ASSERT(portId == 1 || portId == 2);
  1222. if (standalone.engine == nullptr)
  1223. return 0.0f;
  1224. return standalone.engine->getOutputPeak(pluginId, portId);
  1225. }
  1226. // -------------------------------------------------------------------------------------------------------------------
  1227. void carla_set_option(unsigned int pluginId, unsigned int option, bool yesNo)
  1228. {
  1229. carla_debug("carla_set_option(%i, %i, %s)", pluginId, option, bool2str(yesNo));
  1230. CARLA_ASSERT(standalone.engine != nullptr);
  1231. if (standalone.engine == nullptr)
  1232. return;
  1233. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1234. return plugin->setOption(option, yesNo);
  1235. carla_stderr2("carla_set_option(%i, %i, %s) - could not find plugin", pluginId, option, bool2str(yesNo));
  1236. }
  1237. void carla_set_active(unsigned int pluginId, bool onOff)
  1238. {
  1239. carla_debug("carla_set_active(%i, %s)", pluginId, bool2str(onOff));
  1240. CARLA_ASSERT(standalone.engine != nullptr);
  1241. if (standalone.engine == nullptr)
  1242. return;
  1243. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1244. return plugin->setActive(onOff, true, false);
  1245. carla_stderr2("carla_set_active(%i, %s) - could not find plugin", pluginId, bool2str(onOff));
  1246. }
  1247. void carla_set_drywet(unsigned int pluginId, float value)
  1248. {
  1249. carla_debug("carla_set_drywet(%i, %f)", pluginId, value);
  1250. CARLA_ASSERT(standalone.engine != nullptr);
  1251. if (standalone.engine == nullptr)
  1252. return;
  1253. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1254. return plugin->setDryWet(value, true, false);
  1255. carla_stderr2("carla_set_drywet(%i, %f) - could not find plugin", pluginId, value);
  1256. }
  1257. void carla_set_volume(unsigned int pluginId, float value)
  1258. {
  1259. carla_debug("carla_set_volume(%i, %f)", pluginId, value);
  1260. CARLA_ASSERT(standalone.engine != nullptr);
  1261. if (standalone.engine == nullptr)
  1262. return;
  1263. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1264. return plugin->setVolume(value, true, false);
  1265. carla_stderr2("carla_set_volume(%i, %f) - could not find plugin", pluginId, value);
  1266. }
  1267. void carla_set_balance_left(unsigned int pluginId, float value)
  1268. {
  1269. carla_debug("carla_set_balance_left(%i, %f)", pluginId, value);
  1270. CARLA_ASSERT(standalone.engine != nullptr);
  1271. if (standalone.engine == nullptr)
  1272. return;
  1273. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1274. return plugin->setBalanceLeft(value, true, false);
  1275. carla_stderr2("carla_set_balance_left(%i, %f) - could not find plugin", pluginId, value);
  1276. }
  1277. void carla_set_balance_right(unsigned int pluginId, float value)
  1278. {
  1279. carla_debug("carla_set_balance_right(%i, %f)", pluginId, value);
  1280. CARLA_ASSERT(standalone.engine != nullptr);
  1281. if (standalone.engine == nullptr)
  1282. return;
  1283. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1284. return plugin->setBalanceRight(value, true, false);
  1285. carla_stderr2("carla_set_balance_right(%i, %f) - could not find plugin", pluginId, value);
  1286. }
  1287. void carla_set_panning(unsigned int pluginId, float value)
  1288. {
  1289. carla_debug("carla_set_panning(%i, %f)", pluginId, value);
  1290. CARLA_ASSERT(standalone.engine != nullptr);
  1291. if (standalone.engine == nullptr)
  1292. return;
  1293. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1294. return plugin->setPanning(value, true, false);
  1295. carla_stderr2("carla_set_panning(%i, %f) - could not find plugin", pluginId, value);
  1296. }
  1297. void carla_set_ctrl_channel(unsigned int pluginId, int8_t channel)
  1298. {
  1299. carla_debug("carla_set_ctrl_channel(%i, %i)", pluginId, channel);
  1300. CARLA_ASSERT(standalone.engine != nullptr);
  1301. if (standalone.engine == nullptr)
  1302. return;
  1303. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1304. return plugin->setCtrlChannel(channel, true, false);
  1305. carla_stderr2("carla_set_ctrl_channel(%i, %i) - could not find plugin", pluginId, channel);
  1306. }
  1307. // -------------------------------------------------------------------------------------------------------------------
  1308. void carla_set_parameter_value(unsigned int pluginId, uint32_t parameterId, float value)
  1309. {
  1310. carla_debug("carla_set_parameter_value(%i, %i, %f)", pluginId, parameterId, value);
  1311. CARLA_ASSERT(standalone.engine != nullptr);
  1312. if (standalone.engine == nullptr)
  1313. return;
  1314. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1315. {
  1316. if (parameterId < plugin->parameterCount())
  1317. return plugin->setParameterValue(parameterId, value, true, true, false);
  1318. carla_stderr2("carla_set_parameter_value(%i, %i, %f) - parameterId out of bounds", pluginId, parameterId, value);
  1319. return;
  1320. }
  1321. carla_stderr2("carla_set_parameter_value(%i, %i, %f) - could not find plugin", pluginId, parameterId, value);
  1322. }
  1323. void carla_set_parameter_midi_channel(unsigned int pluginId, uint32_t parameterId, uint8_t channel)
  1324. {
  1325. carla_debug("carla_set_parameter_midi_channel(%i, %i, %i)", pluginId, parameterId, channel);
  1326. CARLA_ASSERT(standalone.engine != nullptr);
  1327. CARLA_ASSERT(channel < MAX_MIDI_CHANNELS);
  1328. if (channel >= MAX_MIDI_CHANNELS)
  1329. {
  1330. carla_stderr2("carla_set_parameter_midi_channel(%i, %i, %i) - invalid channel number", pluginId, parameterId, channel);
  1331. return;
  1332. }
  1333. if (standalone.engine == nullptr)
  1334. return;
  1335. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1336. {
  1337. if (parameterId < plugin->parameterCount())
  1338. return plugin->setParameterMidiChannel(parameterId, channel, true, false);
  1339. carla_stderr2("carla_set_parameter_midi_channel(%i, %i, %i) - parameterId out of bounds", pluginId, parameterId, channel);
  1340. return;
  1341. }
  1342. carla_stderr2("carla_set_parameter_midi_channel(%i, %i, %i) - could not find plugin", pluginId, parameterId, channel);
  1343. }
  1344. void carla_set_parameter_midi_cc(unsigned int pluginId, uint32_t parameterId, int16_t cc)
  1345. {
  1346. carla_debug("carla_set_parameter_midi_cc(%i, %i, %i)", pluginId, parameterId, cc);
  1347. CARLA_ASSERT(standalone.engine != nullptr);
  1348. CARLA_ASSERT(cc >= -1 && cc <= 0x5F);
  1349. if (cc < -1)
  1350. {
  1351. cc = -1;
  1352. }
  1353. else if (cc > 0x5F) // 95
  1354. {
  1355. carla_stderr2("carla_set_parameter_midi_cc(%i, %i, %i) - invalid cc number", pluginId, parameterId, cc);
  1356. return;
  1357. }
  1358. if (standalone.engine == nullptr)
  1359. return;
  1360. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1361. {
  1362. if (parameterId < plugin->parameterCount())
  1363. return plugin->setParameterMidiCC(parameterId, cc, true, false);
  1364. carla_stderr2("carla_set_parameter_midi_cc(%i, %i, %i) - parameterId out of bounds", pluginId, parameterId, cc);
  1365. return;
  1366. }
  1367. carla_stderr2("carla_set_parameter_midi_cc(%i, %i, %i) - could not find plugin", pluginId, parameterId, cc);
  1368. }
  1369. // -------------------------------------------------------------------------------------------------------------------
  1370. void carla_set_program(unsigned int pluginId, uint32_t programId)
  1371. {
  1372. carla_debug("carla_set_program(%i, %i)", pluginId, programId);
  1373. CARLA_ASSERT(standalone.engine != nullptr);
  1374. if (standalone.engine == nullptr)
  1375. return;
  1376. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1377. {
  1378. if (programId < plugin->programCount())
  1379. return plugin->setProgram(static_cast<int32_t>(programId), true, true, false);
  1380. carla_stderr2("carla_set_program(%i, %i) - programId out of bounds", pluginId, programId);
  1381. return;
  1382. }
  1383. carla_stderr2("carla_set_program(%i, %i) - could not find plugin", pluginId, programId);
  1384. }
  1385. void carla_set_midi_program(unsigned int pluginId, uint32_t midiProgramId)
  1386. {
  1387. carla_debug("carla_set_midi_program(%i, %i)", pluginId, midiProgramId);
  1388. CARLA_ASSERT(standalone.engine != nullptr);
  1389. if (standalone.engine == nullptr)
  1390. return;
  1391. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1392. {
  1393. if (midiProgramId < plugin->midiProgramCount())
  1394. return plugin->setMidiProgram(static_cast<int32_t>(midiProgramId), true, true, false);
  1395. carla_stderr2("carla_set_midi_program(%i, %i) - midiProgramId out of bounds", pluginId, midiProgramId);
  1396. return;
  1397. }
  1398. carla_stderr2("carla_set_midi_program(%i, %i) - could not find plugin", pluginId, midiProgramId);
  1399. }
  1400. // -------------------------------------------------------------------------------------------------------------------
  1401. void carla_set_custom_data(unsigned int pluginId, const char* type, const char* key, const char* value)
  1402. {
  1403. carla_debug("carla_set_custom_data(%i, \"%s\", \"%s\", \"%s\")", pluginId, type, key, value);
  1404. CARLA_ASSERT(standalone.engine != nullptr);
  1405. if (standalone.engine == nullptr)
  1406. return;
  1407. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1408. return plugin->setCustomData(type, key, value, true);
  1409. carla_stderr2("carla_set_custom_data(%i, \"%s\", \"%s\", \"%s\") - could not find plugin", pluginId, type, key, value);
  1410. }
  1411. void carla_set_chunk_data(unsigned int pluginId, const char* chunkData)
  1412. {
  1413. carla_debug("carla_set_chunk_data(%i, \"%s\")", pluginId, chunkData);
  1414. CARLA_ASSERT(standalone.engine != nullptr);
  1415. if (standalone.engine == nullptr)
  1416. return;
  1417. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1418. {
  1419. if (plugin->options() & CarlaBackend::PLUGIN_OPTION_USE_CHUNKS)
  1420. return plugin->setChunkData(chunkData);
  1421. carla_stderr2("carla_set_chunk_data(%i, \"%s\") - plugin does not support chunks", pluginId, chunkData);
  1422. return;
  1423. }
  1424. carla_stderr2("carla_set_chunk_data(%i, \"%s\") - could not find plugin", pluginId, chunkData);
  1425. }
  1426. // -------------------------------------------------------------------------------------------------------------------
  1427. void carla_prepare_for_save(unsigned int pluginId)
  1428. {
  1429. carla_debug("carla_prepare_for_save(%i)", pluginId);
  1430. CARLA_ASSERT(standalone.engine != nullptr);
  1431. if (standalone.engine == nullptr)
  1432. return;
  1433. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1434. return plugin->prepareForSave();
  1435. carla_stderr2("carla_prepare_for_save(%i) - could not find plugin", pluginId);
  1436. }
  1437. void carla_send_midi_note(unsigned int pluginId, uint8_t channel, uint8_t note, uint8_t velocity)
  1438. {
  1439. carla_debug("carla_send_midi_note(%i, %i, %i, %i)", pluginId, channel, note, velocity);
  1440. CARLA_ASSERT(standalone.engine != nullptr);
  1441. if (standalone.engine == nullptr || ! standalone.engine->isRunning())
  1442. return;
  1443. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1444. return plugin->sendMidiSingleNote(channel, note, velocity, true, true, false);
  1445. carla_stderr2("carla_send_midi_note(%i, %i, %i, %i) - could not find plugin", pluginId, channel, note, velocity);
  1446. }
  1447. void carla_show_gui(unsigned int pluginId, bool yesno)
  1448. {
  1449. carla_debug("carla_show_gui(%i, %s)", pluginId, bool2str(yesno));
  1450. CARLA_ASSERT(standalone.engine != nullptr);
  1451. if (standalone.engine == nullptr)
  1452. return;
  1453. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1454. return plugin->showGui(yesno);
  1455. carla_stderr2("carla_show_gui(%i, %s) - could not find plugin", pluginId, bool2str(yesno));
  1456. }
  1457. // -------------------------------------------------------------------------------------------------------------------
  1458. uint32_t carla_get_buffer_size()
  1459. {
  1460. carla_debug("carla_get_buffer_size()");
  1461. CARLA_ASSERT(standalone.engine != nullptr);
  1462. if (standalone.engine == nullptr)
  1463. return 0;
  1464. return standalone.engine->getBufferSize();
  1465. }
  1466. double carla_get_sample_rate()
  1467. {
  1468. carla_debug("carla_get_sample_rate()");
  1469. CARLA_ASSERT(standalone.engine != nullptr);
  1470. if (standalone.engine == nullptr)
  1471. return 0.0;
  1472. return standalone.engine->getSampleRate();
  1473. }
  1474. // -------------------------------------------------------------------------------------------------------------------
  1475. const char* carla_get_last_error()
  1476. {
  1477. carla_debug("carla_get_last_error()");
  1478. if (standalone.engine != nullptr)
  1479. return standalone.engine->getLastError();
  1480. return standalone.lastError;
  1481. }
  1482. const char* carla_get_host_osc_url()
  1483. {
  1484. carla_debug("carla_get_host_osc_url()");
  1485. CARLA_ASSERT(standalone.engine != nullptr);
  1486. if (standalone.engine == nullptr)
  1487. {
  1488. standalone.lastError = "Engine is not started";
  1489. return nullptr;
  1490. }
  1491. return standalone.engine->getOscServerPathTCP();
  1492. }
  1493. // -------------------------------------------------------------------------------------------------------------------
  1494. #define NSM_API_VERSION_MAJOR 1
  1495. #define NSM_API_VERSION_MINOR 2
  1496. class CarlaNSM
  1497. {
  1498. public:
  1499. CarlaNSM()
  1500. : fServerThread(nullptr),
  1501. fReplyAddr(nullptr),
  1502. fIsOpened(false),
  1503. fIsSaved(false)
  1504. {
  1505. }
  1506. ~CarlaNSM()
  1507. {
  1508. if (fReplyAddr != nullptr)
  1509. lo_address_free(fReplyAddr);
  1510. if (fServerThread != nullptr)
  1511. {
  1512. lo_server_thread_stop(fServerThread);
  1513. lo_server_thread_del_method(fServerThread, "/reply", "ssss");
  1514. lo_server_thread_del_method(fServerThread, "/nsm/client/open", "sss");
  1515. lo_server_thread_del_method(fServerThread, "/nsm/client/save", "");
  1516. lo_server_thread_free(fServerThread);
  1517. }
  1518. }
  1519. void announce(const char* const url, const int pid)
  1520. {
  1521. lo_address const addr = lo_address_new_from_url(url);
  1522. if (addr == nullptr)
  1523. return;
  1524. const int proto = lo_address_get_protocol(addr);
  1525. if (fServerThread == nullptr)
  1526. {
  1527. // create new OSC thread
  1528. fServerThread = lo_server_thread_new_with_proto(nullptr, proto, error_handler);
  1529. // register message handlers and start OSC thread
  1530. lo_server_thread_add_method(fServerThread, "/reply", "ssss", _reply_handler, this);
  1531. lo_server_thread_add_method(fServerThread, "/nsm/client/open", "sss", _open_handler, this);
  1532. lo_server_thread_add_method(fServerThread, "/nsm/client/save", "", _save_handler, this);
  1533. lo_server_thread_start(fServerThread);
  1534. }
  1535. lo_send_from(addr, lo_server_thread_get_server(fServerThread), LO_TT_IMMEDIATE, "/nsm/server/announce", "sssiii",
  1536. "Carla", ":switch:", "carla", NSM_API_VERSION_MAJOR, NSM_API_VERSION_MINOR, pid);
  1537. lo_address_free(addr);
  1538. }
  1539. void replyOpen()
  1540. {
  1541. fIsOpened = true;
  1542. }
  1543. void replySave()
  1544. {
  1545. fIsSaved = true;
  1546. }
  1547. protected:
  1548. int handleReply(const char* const path, const char* const types, lo_arg** const argv, const int argc, const lo_message msg)
  1549. {
  1550. carla_debug("CarlaNSM::handleReply(%s, %i, %p, %s, %p)", path, argc, argv, types, msg);
  1551. if (fReplyAddr != nullptr)
  1552. lo_address_free(fReplyAddr);
  1553. fIsOpened = false;
  1554. fIsSaved = false;
  1555. char* const url = lo_address_get_url(lo_message_get_source(msg));
  1556. fReplyAddr = lo_address_new_from_url(url);
  1557. std::free(url);
  1558. const char* const method = &argv[0]->s;
  1559. const char* const smName = &argv[2]->s;
  1560. if (std::strcmp(method, "/nsm/server/announce") == 0 && standalone.callback != nullptr)
  1561. standalone.callback(standalone.callbackPtr, CarlaBackend::CALLBACK_NSM_ANNOUNCE, 0, 0, 0, 0.0f, smName);
  1562. return 0;
  1563. #ifndef DEBUG
  1564. // unused
  1565. (void)path;
  1566. (void)types;
  1567. (void)argc;
  1568. #endif
  1569. }
  1570. int handleOpen(const char* const path, const char* const types, lo_arg** const argv, const int argc, const lo_message msg)
  1571. {
  1572. carla_debug("CarlaNSM::handleOpen(\"%s\", \"%s\", %p, %i, %p)", path, types, argv, argc, msg);
  1573. if (standalone.callback == nullptr)
  1574. return 1;
  1575. if (fServerThread == nullptr)
  1576. return 1;
  1577. if (fReplyAddr == nullptr)
  1578. return 1;
  1579. const char* const projectPath = &argv[0]->s;
  1580. const char* const clientId = &argv[2]->s;
  1581. char data[std::strlen(projectPath)+std::strlen(clientId)+2];
  1582. std::strcpy(data, projectPath);
  1583. std::strcat(data, ":");
  1584. std::strcat(data, clientId);
  1585. standalone.callback(nullptr, CarlaBackend::CALLBACK_NSM_OPEN, 0, 0, 0, 0.0f, data);
  1586. for (int i=0; i < 30 && ! fIsOpened; i++)
  1587. carla_msleep(100);
  1588. if (fIsOpened)
  1589. lo_send_from(fReplyAddr, lo_server_thread_get_server(fServerThread), LO_TT_IMMEDIATE, "/reply", "ss", "/nsm/client/open", "OK");
  1590. return 0;
  1591. #ifndef DEBUG
  1592. // unused
  1593. (void)path;
  1594. (void)types;
  1595. (void)argc;
  1596. (void)msg;
  1597. #endif
  1598. }
  1599. int handleSave(const char* const path, const char* const types, lo_arg** const argv, const int argc, const lo_message msg)
  1600. {
  1601. carla_debug("CarlaNSM::handleSave(\"%s\", \"%s\", %p, %i, %p)", path, types, argv, argc, msg);
  1602. if (standalone.callback == nullptr)
  1603. return 1;
  1604. if (fServerThread == nullptr)
  1605. return 1;
  1606. if (fReplyAddr == nullptr)
  1607. return 1;
  1608. standalone.callback(nullptr, CarlaBackend::CALLBACK_NSM_SAVE, 0, 0, 0, 0.0f, nullptr);
  1609. for (int i=0; i < 30 && ! fIsSaved; i++)
  1610. carla_msleep(100);
  1611. if (fIsSaved)
  1612. lo_send_from(fReplyAddr, lo_server_thread_get_server(fServerThread), LO_TT_IMMEDIATE, "/reply", "ss", "/nsm/client/save", "OK");
  1613. return 0;
  1614. #ifndef DEBUG
  1615. // unused
  1616. (void)path;
  1617. (void)types;
  1618. (void)argv;
  1619. (void)argc;
  1620. (void)msg;
  1621. #endif
  1622. }
  1623. private:
  1624. lo_server_thread fServerThread;
  1625. lo_address fReplyAddr;
  1626. bool fIsOpened;
  1627. bool fIsSaved;
  1628. #define handlePtr ((CarlaNSM*)data)
  1629. static int _reply_handler(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg, void* data)
  1630. {
  1631. return handlePtr->handleReply(path, types, argv, argc, msg);
  1632. }
  1633. static int _open_handler(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg, void* data)
  1634. {
  1635. return handlePtr->handleOpen(path, types, argv, argc, msg);
  1636. }
  1637. static int _save_handler(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg, void* data)
  1638. {
  1639. return handlePtr->handleSave(path, types, argv, argc, msg);
  1640. }
  1641. #undef handlePtr
  1642. static void error_handler(int num, const char* msg, const char* path)
  1643. {
  1644. carla_stderr2("CarlaNSM::error_handler(%i, \"%s\", \"%s\")", num, msg, path);
  1645. }
  1646. };
  1647. static CarlaNSM gCarlaNSM;
  1648. void carla_nsm_announce(const char* url, int pid)
  1649. {
  1650. gCarlaNSM.announce(url, pid);
  1651. }
  1652. void carla_nsm_reply_open()
  1653. {
  1654. gCarlaNSM.replyOpen();
  1655. }
  1656. void carla_nsm_reply_save()
  1657. {
  1658. gCarlaNSM.replySave();
  1659. }
  1660. // -------------------------------------------------------------------------------------------------------------------
  1661. #ifdef BUILD_BRIDGE
  1662. CarlaEngine* carla_get_standalone_engine()
  1663. {
  1664. return standalone.engine;
  1665. }
  1666. bool carla_engine_init_bridge(const char* audioBaseName, const char* controlBaseName, const char* clientName)
  1667. {
  1668. carla_debug("carla_engine_init_bridge(\"%s\", \"%s\", \"%s\")", audioBaseName, controlBaseName, clientName);
  1669. CARLA_ASSERT(standalone.engine == nullptr);
  1670. CARLA_ASSERT(audioBaseName != nullptr);
  1671. CARLA_ASSERT(controlBaseName != nullptr);
  1672. CARLA_ASSERT(clientName != nullptr);
  1673. standalone.engine = CarlaEngine::newBridge(audioBaseName, controlBaseName);
  1674. if (standalone.engine == nullptr)
  1675. {
  1676. standalone.lastError = "The seleted audio driver is not available!";
  1677. return false;
  1678. }
  1679. if (standalone.callback != nullptr)
  1680. standalone.engine->setCallback(standalone.callback, nullptr);
  1681. standalone.engine->setOption(CarlaBackend::OPTION_PROCESS_MODE, CarlaBackend::PROCESS_MODE_BRIDGE, nullptr);
  1682. standalone.engine->setOption(CarlaBackend::OPTION_TRANSPORT_MODE, CarlaBackend::TRANSPORT_MODE_BRIDGE, nullptr);
  1683. standalone.engine->setOption(CarlaBackend::OPTION_PREFER_PLUGIN_BRIDGES, false, nullptr);
  1684. standalone.engine->setOption(CarlaBackend::OPTION_PREFER_UI_BRIDGES, false, nullptr);
  1685. // TODO - read from environment
  1686. #ifndef BUILD_BRIDGE
  1687. standalone.engine->setOption(CarlaBackend::OPTION_FORCE_STEREO, standalone.options.forceStereo ? 1 : 0, nullptr);
  1688. # ifdef WANT_DSSI
  1689. standalone.engine->setOption(CarlaBackend::OPTION_USE_DSSI_VST_CHUNKS, standalone.options.useDssiVstChunks ? 1 : 0, nullptr);
  1690. # endif
  1691. standalone.engine->setOption(CarlaBackend::OPTION_MAX_PARAMETERS, static_cast<int>(standalone.options.maxParameters), nullptr);
  1692. #endif
  1693. const bool initiated = standalone.engine->init(clientName);
  1694. if (initiated)
  1695. {
  1696. standalone.lastError = "no error";
  1697. standalone.init();
  1698. }
  1699. else
  1700. {
  1701. standalone.lastError = standalone.engine->getLastError();
  1702. delete standalone.engine;
  1703. standalone.engine = nullptr;
  1704. }
  1705. return initiated;
  1706. }
  1707. #endif