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.

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