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.

2171 lines
70KB

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