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.

2013 lines
65KB

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