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.

2108 lines
68KB

  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. // -------------------------------------------------------------------------------------------------------------------
  458. void carla_transport_play()
  459. {
  460. carla_debug("carla_transport_play()");
  461. CARLA_ASSERT(standalone.engine != nullptr);
  462. if (standalone.engine != nullptr)
  463. return standalone.engine->transportPlay();
  464. }
  465. void carla_transport_pause()
  466. {
  467. carla_debug("carla_transport_pause()");
  468. CARLA_ASSERT(standalone.engine != nullptr);
  469. if (standalone.engine != nullptr)
  470. return standalone.engine->transportPause();
  471. }
  472. void carla_transport_relocate(uint32_t frames)
  473. {
  474. carla_debug("carla_transport_relocate(%i)", frames);
  475. CARLA_ASSERT(standalone.engine != nullptr);
  476. if (standalone.engine != nullptr)
  477. return standalone.engine->transportRelocate(frames);
  478. }
  479. // -------------------------------------------------------------------------------------------------------------------
  480. bool carla_add_plugin(CarlaBackend::BinaryType btype, CarlaBackend::PluginType ptype, const char* filename, const char* const name, const char* label, const void* extraStuff)
  481. {
  482. carla_debug("carla_add_plugin(%s, %s, \"%s\", \"%s\", \"%s\", %p)", CarlaBackend::BinaryType2Str(btype), CarlaBackend::PluginType2Str(ptype), filename, name, label, extraStuff);
  483. CARLA_ASSERT(standalone.engine != nullptr);
  484. if (standalone.engine != nullptr && standalone.engine->isRunning())
  485. return standalone.engine->addPlugin(btype, ptype, filename, name, label, extraStuff);
  486. standalone.lastError = "Engine is not started";
  487. return false;
  488. }
  489. bool carla_remove_plugin(unsigned int pluginId)
  490. {
  491. carla_debug("carla_remove_plugin(%i)", pluginId);
  492. CARLA_ASSERT(standalone.engine != nullptr);
  493. if (standalone.engine != nullptr && standalone.engine->isRunning())
  494. return standalone.engine->removePlugin(pluginId);
  495. standalone.lastError = "Engine is not started";
  496. return false;
  497. }
  498. void carla_remove_all_plugins()
  499. {
  500. carla_debug("carla_remove_all_plugins()");
  501. CARLA_ASSERT(standalone.engine != nullptr);
  502. if (standalone.engine != nullptr && standalone.engine->isRunning())
  503. standalone.engine->removeAllPlugins();
  504. }
  505. bool carla_load_plugin_state(unsigned int pluginId, const char* filename)
  506. {
  507. carla_debug("carla_load_plugin_state(%i, \"%s\")", pluginId, filename);
  508. CARLA_ASSERT(standalone.engine != nullptr);
  509. if (standalone.engine == nullptr)
  510. return false;
  511. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  512. return plugin->loadStateFromFile(filename);
  513. carla_stderr2("carla_load_plugin_state(%i, \"%s\") - could not find plugin", pluginId, filename);
  514. return false;
  515. }
  516. bool carla_save_plugin_state(unsigned int pluginId, const char* filename)
  517. {
  518. carla_debug("carla_save_plugin_state(%i, \"%s\")", pluginId, filename);
  519. CARLA_ASSERT(standalone.engine != nullptr);
  520. if (standalone.engine == nullptr)
  521. return false;
  522. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  523. return plugin->saveStateToFile(filename);
  524. carla_stderr2("carla_save_plugin_state(%i, \"%s\") - could not find plugin", pluginId, filename);
  525. return false;
  526. }
  527. // -------------------------------------------------------------------------------------------------------------------
  528. const CarlaPluginInfo* carla_get_plugin_info(unsigned int pluginId)
  529. {
  530. carla_debug("carla_get_plugin_info(%i)", pluginId);
  531. CARLA_ASSERT(standalone.engine != nullptr);
  532. static CarlaPluginInfo info;
  533. // reset
  534. info.type = CarlaBackend::PLUGIN_NONE;
  535. info.category = CarlaBackend::PLUGIN_CATEGORY_NONE;
  536. info.hints = 0x0;
  537. info.hints = 0x0;
  538. info.binary = nullptr;
  539. info.name = nullptr;
  540. info.uniqueId = 0;
  541. info.latency = 0;
  542. info.optionsAvailable = 0x0;
  543. info.optionsEnabled = 0x0;
  544. // cleanup
  545. if (info.label != nullptr)
  546. {
  547. delete[] info.label;
  548. info.label = nullptr;
  549. }
  550. if (info.maker != nullptr)
  551. {
  552. delete[] info.maker;
  553. info.maker = nullptr;
  554. }
  555. if (info.copyright != nullptr)
  556. {
  557. delete[] info.copyright;
  558. info.copyright = nullptr;
  559. }
  560. if (standalone.engine == nullptr)
  561. return &info;
  562. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  563. {
  564. char strBufLabel[STR_MAX] = { 0 };
  565. char strBufMaker[STR_MAX] = { 0 };
  566. char strBufCopyright[STR_MAX] = { 0 };
  567. info.type = plugin->type();
  568. info.category = plugin->category();
  569. info.hints = plugin->hints();
  570. info.binary = plugin->filename();
  571. info.name = plugin->name();
  572. info.uniqueId = plugin->uniqueId();
  573. info.latency = plugin->latency();
  574. info.optionsAvailable = plugin->availableOptions();
  575. info.optionsEnabled = plugin->options();
  576. plugin->getLabel(strBufLabel);
  577. info.label = carla_strdup(strBufLabel);
  578. plugin->getMaker(strBufMaker);
  579. info.maker = carla_strdup(strBufMaker);
  580. plugin->getCopyright(strBufCopyright);
  581. info.copyright = carla_strdup(strBufCopyright);
  582. return &info;
  583. }
  584. carla_stderr2("carla_get_plugin_info(%i) - could not find plugin", pluginId);
  585. return &info;
  586. }
  587. const CarlaPortCountInfo* carla_get_audio_port_count_info(unsigned int pluginId)
  588. {
  589. carla_debug("carla_get_audio_port_count_info(%i)", pluginId);
  590. CARLA_ASSERT(standalone.engine != nullptr);
  591. static CarlaPortCountInfo info;
  592. // reset
  593. info.ins = 0;
  594. info.outs = 0;
  595. info.total = 0;
  596. if (standalone.engine == nullptr)
  597. return &info;
  598. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  599. {
  600. info.ins = plugin->audioInCount();
  601. info.outs = plugin->audioOutCount();
  602. info.total = info.ins + info.outs;
  603. return &info;
  604. }
  605. carla_stderr2("carla_get_audio_port_count_info(%i) - could not find plugin", pluginId);
  606. return &info;
  607. }
  608. const CarlaPortCountInfo* carla_get_midi_port_count_info(unsigned int pluginId)
  609. {
  610. carla_debug("carla_get_midi_port_count_info(%i)", pluginId);
  611. CARLA_ASSERT(standalone.engine != nullptr);
  612. static CarlaPortCountInfo info;
  613. // reset
  614. info.ins = 0;
  615. info.outs = 0;
  616. info.total = 0;
  617. if (standalone.engine == nullptr)
  618. return &info;
  619. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  620. {
  621. info.ins = plugin->midiInCount();
  622. info.outs = plugin->midiOutCount();
  623. info.total = info.ins + info.outs;
  624. return &info;
  625. }
  626. carla_stderr2("carla_get_midi_port_count_info(%i) - could not find plugin", pluginId);
  627. return &info;
  628. }
  629. const CarlaPortCountInfo* carla_get_parameter_count_info(unsigned int pluginId)
  630. {
  631. carla_debug("carla_get_parameter_count_info(%i)", pluginId);
  632. CARLA_ASSERT(standalone.engine != nullptr);
  633. static CarlaPortCountInfo info;
  634. // reset
  635. info.ins = 0;
  636. info.outs = 0;
  637. info.total = 0;
  638. if (standalone.engine == nullptr)
  639. return &info;
  640. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  641. {
  642. plugin->getParameterCountInfo(&info.ins, &info.outs, &info.total);
  643. return &info;
  644. }
  645. carla_stderr2("carla_get_parameter_count_info(%i) - could not find plugin", pluginId);
  646. return &info;
  647. }
  648. const CarlaParameterInfo* carla_get_parameter_info(unsigned int pluginId, uint32_t parameterId)
  649. {
  650. carla_debug("carla_get_parameter_info(%i, %i)", pluginId, parameterId);
  651. CARLA_ASSERT(standalone.engine != nullptr);
  652. static CarlaParameterInfo info;
  653. // reset
  654. info.scalePointCount = 0;
  655. // cleanup
  656. if (info.name != nullptr)
  657. {
  658. delete[] info.name;
  659. info.name = nullptr;
  660. }
  661. if (info.symbol != nullptr)
  662. {
  663. delete[] info.symbol;
  664. info.symbol = nullptr;
  665. }
  666. if (info.unit != nullptr)
  667. {
  668. delete[] info.unit;
  669. info.unit = nullptr;
  670. }
  671. if (standalone.engine == nullptr)
  672. return &info;
  673. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  674. {
  675. if (parameterId < plugin->parameterCount())
  676. {
  677. char strBufName[STR_MAX] = { 0 };
  678. char strBufSymbol[STR_MAX] = { 0 };
  679. char strBufUnit[STR_MAX] = { 0 };
  680. info.scalePointCount = plugin->parameterScalePointCount(parameterId);
  681. plugin->getParameterName(parameterId, strBufName);
  682. info.name = carla_strdup(strBufName);
  683. plugin->getParameterSymbol(parameterId, strBufSymbol);
  684. info.symbol = carla_strdup(strBufSymbol);
  685. plugin->getParameterUnit(parameterId, strBufUnit);
  686. info.unit = carla_strdup(strBufUnit);
  687. }
  688. else
  689. carla_stderr2("carla_get_parameter_info(%i, %i) - parameterId out of bounds", pluginId, parameterId);
  690. return &info;
  691. }
  692. carla_stderr2("carla_get_parameter_info(%i, %i) - could not find plugin", pluginId, parameterId);
  693. return &info;
  694. }
  695. const CarlaScalePointInfo* carla_get_parameter_scalepoint_info(unsigned int pluginId, uint32_t parameterId, uint32_t scalePointId)
  696. {
  697. carla_debug("carla_get_parameter_scalepoint_info(%i, %i, %i)", pluginId, parameterId, scalePointId);
  698. CARLA_ASSERT(standalone.engine != nullptr);
  699. static CarlaScalePointInfo info;
  700. // reset
  701. info.value = 0.0f;
  702. // cleanup
  703. if (info.label != nullptr)
  704. {
  705. delete[] info.label;
  706. info.label = nullptr;
  707. }
  708. if (standalone.engine == nullptr)
  709. return &info;
  710. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  711. {
  712. if (parameterId < plugin->parameterCount())
  713. {
  714. if (scalePointId < plugin->parameterScalePointCount(parameterId))
  715. {
  716. char strBufLabel[STR_MAX] = { 0 };
  717. info.value = plugin->getParameterScalePointValue(parameterId, scalePointId);
  718. plugin->getParameterScalePointLabel(parameterId, scalePointId, strBufLabel);
  719. info.label = carla_strdup(strBufLabel);
  720. }
  721. else
  722. carla_stderr2("carla_get_parameter_scalepoint_info(%i, %i, %i) - scalePointId out of bounds", pluginId, parameterId, scalePointId);
  723. }
  724. else
  725. carla_stderr2("carla_get_parameter_scalepoint_info(%i, %i, %i) - parameterId out of bounds", pluginId, parameterId, scalePointId);
  726. return &info;
  727. }
  728. carla_stderr2("carla_get_parameter_scalepoint_info(%i, %i, %i) - could not find plugin", pluginId, parameterId, scalePointId);
  729. return &info;
  730. }
  731. // -------------------------------------------------------------------------------------------------------------------
  732. const CarlaBackend::ParameterData* carla_get_parameter_data(unsigned int pluginId, uint32_t parameterId)
  733. {
  734. carla_debug("carla_get_parameter_data(%i, %i)", pluginId, parameterId);
  735. CARLA_ASSERT(standalone.engine != nullptr);
  736. static CarlaBackend::ParameterData data;
  737. if (standalone.engine == nullptr)
  738. return &data;
  739. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  740. {
  741. if (parameterId < plugin->parameterCount())
  742. return &plugin->parameterData(parameterId);
  743. carla_stderr2("carla_get_parameter_data(%i, %i) - parameterId out of bounds", pluginId, parameterId);
  744. return &data;
  745. }
  746. carla_stderr2("carla_get_parameter_data(%i, %i) - could not find plugin", pluginId, parameterId);
  747. return &data;
  748. }
  749. const CarlaBackend::ParameterRanges* carla_get_parameter_ranges(unsigned int pluginId, uint32_t parameterId)
  750. {
  751. carla_debug("carla_get_parameter_ranges(%i, %i)", pluginId, parameterId);
  752. CARLA_ASSERT(standalone.engine != nullptr);
  753. static CarlaBackend::ParameterRanges ranges;
  754. if (standalone.engine == nullptr)
  755. return &ranges;
  756. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  757. {
  758. if (parameterId < plugin->parameterCount())
  759. return &plugin->parameterRanges(parameterId);
  760. carla_stderr2("carla_get_parameter_ranges(%i, %i) - parameterId out of bounds", pluginId, parameterId);
  761. return &ranges;
  762. }
  763. carla_stderr2("carla_get_parameter_ranges(%i, %i) - could not find plugin", pluginId, parameterId);
  764. return &ranges;
  765. }
  766. const CarlaBackend::MidiProgramData* carla_get_midi_program_data(unsigned int pluginId, uint32_t midiProgramId)
  767. {
  768. carla_debug("carla_get_midi_program_data(%i, %i)", pluginId, midiProgramId);
  769. CARLA_ASSERT(standalone.engine != nullptr);
  770. static CarlaBackend::MidiProgramData data;
  771. if (standalone.engine == nullptr)
  772. return &data;
  773. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  774. {
  775. if (midiProgramId < plugin->midiProgramCount())
  776. return &plugin->midiProgramData(midiProgramId);
  777. carla_stderr2("carla_get_midi_program_data(%i, %i) - midiProgramId out of bounds", pluginId, midiProgramId);
  778. return &data;
  779. }
  780. carla_stderr2("carla_get_midi_program_data(%i, %i) - could not find plugin", pluginId, midiProgramId);
  781. return &data;
  782. }
  783. const CarlaBackend::CustomData* carla_get_custom_data(unsigned int pluginId, uint32_t customDataId)
  784. {
  785. carla_debug("carla_get_custom_data(%i, %i)", pluginId, customDataId);
  786. CARLA_ASSERT(standalone.engine != nullptr);
  787. static CarlaBackend::CustomData data;
  788. if (standalone.engine == nullptr)
  789. return &data;
  790. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  791. {
  792. if (customDataId < plugin->customDataCount())
  793. return &plugin->customData(customDataId);
  794. carla_stderr2("carla_get_custom_data(%i, %i) - customDataId out of bounds", pluginId, customDataId);
  795. return &data;
  796. }
  797. carla_stderr2("carla_get_custom_data(%i, %i) - could not find plugin", pluginId, customDataId);
  798. return &data;
  799. }
  800. const char* carla_get_chunk_data(unsigned int pluginId)
  801. {
  802. carla_debug("carla_get_chunk_data(%i)", pluginId);
  803. CARLA_ASSERT(standalone.engine != nullptr);
  804. if (standalone.engine == nullptr)
  805. return nullptr;
  806. static CarlaString chunkData;
  807. // cleanup
  808. chunkData.clear();
  809. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  810. {
  811. if (plugin->options() & CarlaBackend::PLUGIN_OPTION_USE_CHUNKS)
  812. {
  813. void* data = nullptr;
  814. const int32_t dataSize = plugin->chunkData(&data);
  815. if (data != nullptr && dataSize >= 4)
  816. {
  817. chunkData.importBinaryAsBase64((const uint8_t*)data, static_cast<size_t>(dataSize));
  818. return (const char*)chunkData;
  819. }
  820. else
  821. carla_stderr2("carla_get_chunk_data(%i) - got invalid chunk data", pluginId);
  822. }
  823. else
  824. carla_stderr2("carla_get_chunk_data(%i) - plugin does not support chunks", pluginId);
  825. return nullptr;
  826. }
  827. carla_stderr2("carla_get_chunk_data(%i) - could not find plugin", pluginId);
  828. return nullptr;
  829. }
  830. // -------------------------------------------------------------------------------------------------------------------
  831. uint32_t carla_get_parameter_count(unsigned int pluginId)
  832. {
  833. carla_debug("carla_get_parameter_count(%i)", pluginId);
  834. CARLA_ASSERT(standalone.engine != nullptr);
  835. if (standalone.engine == nullptr)
  836. return 0;
  837. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  838. return plugin->parameterCount();
  839. carla_stderr2("carla_get_parameter_count(%i) - could not find plugin", pluginId);
  840. return 0;
  841. }
  842. uint32_t carla_get_program_count(unsigned int pluginId)
  843. {
  844. carla_debug("carla_get_program_count(%i)", pluginId);
  845. CARLA_ASSERT(standalone.engine != nullptr);
  846. if (standalone.engine == nullptr)
  847. return 0;
  848. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  849. return plugin->programCount();
  850. carla_stderr2("carla_get_program_count(%i) - could not find plugin", pluginId);
  851. return 0;
  852. }
  853. uint32_t carla_get_midi_program_count(unsigned int pluginId)
  854. {
  855. carla_debug("carla_get_midi_program_count(%i)", pluginId);
  856. CARLA_ASSERT(standalone.engine != nullptr);
  857. if (standalone.engine == nullptr)
  858. return 0;
  859. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  860. return plugin->midiProgramCount();
  861. carla_stderr2("carla_get_midi_program_count(%i) - could not find plugin", pluginId);
  862. return 0;
  863. }
  864. uint32_t carla_get_custom_data_count(unsigned int pluginId)
  865. {
  866. carla_debug("carla_get_custom_data_count(%i)", pluginId);
  867. CARLA_ASSERT(standalone.engine != nullptr);
  868. if (standalone.engine == nullptr)
  869. return 0;
  870. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  871. return plugin->customDataCount();
  872. carla_stderr2("carla_get_custom_data_count(%i) - could not find plugin", pluginId);
  873. return 0;
  874. }
  875. // -------------------------------------------------------------------------------------------------------------------
  876. const char* carla_get_parameter_text(unsigned int pluginId, uint32_t parameterId)
  877. {
  878. carla_debug("carla_get_parameter_text(%i, %i)", pluginId, parameterId);
  879. CARLA_ASSERT(standalone.engine != nullptr);
  880. if (standalone.engine == nullptr)
  881. return nullptr;
  882. static char textBuf[STR_MAX];
  883. carla_zeroMem(textBuf, sizeof(char)*STR_MAX);
  884. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  885. {
  886. if (parameterId < plugin->parameterCount())
  887. {
  888. plugin->getParameterText(parameterId, textBuf);
  889. return textBuf;
  890. }
  891. carla_stderr2("carla_get_parameter_text(%i, %i) - parameterId out of bounds", pluginId, parameterId);
  892. return nullptr;
  893. }
  894. carla_stderr2("carla_get_parameter_text(%i, %i) - could not find plugin", pluginId, parameterId);
  895. return nullptr;
  896. }
  897. const char* carla_get_program_name(unsigned int pluginId, uint32_t programId)
  898. {
  899. carla_debug("carla_get_program_name(%i, %i)", pluginId, programId);
  900. CARLA_ASSERT(standalone.engine != nullptr);
  901. if (standalone.engine == nullptr)
  902. return nullptr;
  903. static char programName[STR_MAX];
  904. carla_zeroMem(programName, sizeof(char)*STR_MAX);
  905. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  906. {
  907. if (programId < plugin->programCount())
  908. {
  909. plugin->getProgramName(programId, programName);
  910. return programName;
  911. }
  912. carla_stderr2("carla_get_program_name(%i, %i) - programId out of bounds", pluginId, programId);
  913. return nullptr;
  914. }
  915. carla_stderr2("carla_get_program_name(%i, %i) - could not find plugin", pluginId, programId);
  916. return nullptr;
  917. }
  918. const char* carla_get_midi_program_name(unsigned int pluginId, uint32_t midiProgramId)
  919. {
  920. carla_debug("carla_get_midi_program_name(%i, %i)", pluginId, midiProgramId);
  921. CARLA_ASSERT(standalone.engine != nullptr);
  922. if (standalone.engine == nullptr)
  923. return nullptr;
  924. static char midiProgramName[STR_MAX];
  925. carla_zeroMem(midiProgramName, sizeof(char)*STR_MAX);
  926. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  927. {
  928. if (midiProgramId < plugin->midiProgramCount())
  929. {
  930. plugin->getMidiProgramName(midiProgramId, midiProgramName);
  931. return midiProgramName;
  932. }
  933. carla_stderr2("carla_get_midi_program_name(%i, %i) - midiProgramId out of bounds", pluginId, midiProgramId);
  934. return nullptr;
  935. }
  936. carla_stderr2("carla_get_midi_program_name(%i, %i) - could not find plugin", pluginId, midiProgramId);
  937. return nullptr;
  938. }
  939. const char* carla_get_real_plugin_name(unsigned int pluginId)
  940. {
  941. carla_debug("carla_get_real_plugin_name(%i)", pluginId);
  942. CARLA_ASSERT(standalone.engine != nullptr);
  943. if (standalone.engine == nullptr)
  944. return nullptr;
  945. static char realPluginName[STR_MAX];
  946. carla_zeroMem(realPluginName, sizeof(char)*STR_MAX);
  947. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  948. {
  949. plugin->getRealName(realPluginName);
  950. return realPluginName;
  951. }
  952. carla_stderr2("carla_get_real_plugin_name(%i) - could not find plugin", pluginId);
  953. return nullptr;
  954. }
  955. // -------------------------------------------------------------------------------------------------------------------
  956. int32_t carla_get_current_program_index(unsigned int pluginId)
  957. {
  958. carla_debug("carla_get_current_program_index(%i)", pluginId);
  959. CARLA_ASSERT(standalone.engine != nullptr);
  960. if (standalone.engine == nullptr)
  961. return -1;
  962. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  963. return plugin->currentProgram();
  964. carla_stderr2("carla_get_current_program_index(%i) - could not find plugin", pluginId);
  965. return -1;
  966. }
  967. int32_t carla_get_current_midi_program_index(unsigned int pluginId)
  968. {
  969. carla_debug("carla_get_current_midi_program_index(%i)", pluginId);
  970. CARLA_ASSERT(standalone.engine != nullptr);
  971. if (standalone.engine == nullptr)
  972. return -1;
  973. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  974. return plugin->currentMidiProgram();
  975. carla_stderr2("carla_get_current_midi_program_index(%i) - could not find plugin", pluginId);
  976. return -1;
  977. }
  978. // -------------------------------------------------------------------------------------------------------------------
  979. float carla_get_default_parameter_value(unsigned int pluginId, uint32_t parameterId)
  980. {
  981. carla_debug("carla_get_default_parameter_value(%i, %i)", pluginId, parameterId);
  982. CARLA_ASSERT(standalone.engine != nullptr);
  983. if (standalone.engine == nullptr)
  984. return 0.0f;
  985. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  986. {
  987. if (parameterId < plugin->parameterCount())
  988. return plugin->parameterRanges(parameterId).def;
  989. carla_stderr2("carla_get_default_parameter_value(%i, %i) - parameterId out of bounds", pluginId, parameterId);
  990. return 0.0f;
  991. }
  992. carla_stderr2("carla_get_default_parameter_value(%i, %i) - could not find plugin", pluginId, parameterId);
  993. return 0.0f;
  994. }
  995. float carla_get_current_parameter_value(unsigned int pluginId, uint32_t parameterId)
  996. {
  997. carla_debug("carla_get_current_parameter_value(%i, %i)", pluginId, parameterId);
  998. CARLA_ASSERT(standalone.engine != nullptr);
  999. if (standalone.engine == nullptr)
  1000. return 0.0f;
  1001. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1002. {
  1003. if (parameterId < plugin->parameterCount())
  1004. return plugin->getParameterValue(parameterId);
  1005. carla_stderr2("carla_get_current_parameter_value(%i, %i) - parameterId out of bounds", pluginId, parameterId);
  1006. return 0.0f;
  1007. }
  1008. carla_stderr2("carla_get_current_parameter_value(%i, %i) - could not find plugin", pluginId, parameterId);
  1009. return 0.0f;
  1010. }
  1011. // -------------------------------------------------------------------------------------------------------------------
  1012. float carla_get_input_peak_value(unsigned int pluginId, unsigned short portId)
  1013. {
  1014. CARLA_ASSERT(standalone.engine != nullptr);
  1015. CARLA_ASSERT(portId == 1 || portId == 2);
  1016. if (standalone.engine == nullptr)
  1017. return 0.0f;
  1018. if (pluginId >= standalone.engine->currentPluginCount())
  1019. {
  1020. carla_stderr2("carla_get_input_peak_value(%i, %i) - invalid plugin value", pluginId, portId);
  1021. return 0.0f;
  1022. }
  1023. if (portId == 1 || portId == 2)
  1024. return standalone.engine->getInputPeak(pluginId, portId);
  1025. carla_stderr2("carla_get_input_peak_value(%i, %i) - invalid port value", pluginId, portId);
  1026. return 0.0f;
  1027. }
  1028. float carla_get_output_peak_value(unsigned int pluginId, unsigned short portId)
  1029. {
  1030. CARLA_ASSERT(standalone.engine != nullptr);
  1031. CARLA_ASSERT(portId == 1 || portId == 2);
  1032. if (standalone.engine == nullptr)
  1033. return 0.0f;
  1034. if (pluginId >= standalone.engine->currentPluginCount())
  1035. {
  1036. carla_stderr2("carla_get_input_peak_value(%i, %i) - invalid plugin value", pluginId, portId);
  1037. return 0.0f;
  1038. }
  1039. if (portId == 1 || portId == 2)
  1040. return standalone.engine->getOutputPeak(pluginId, portId);
  1041. carla_stderr2("carla_get_output_peak_value(%i, %i) - invalid port value", pluginId, portId);
  1042. return 0.0f;
  1043. }
  1044. // -------------------------------------------------------------------------------------------------------------------
  1045. void carla_set_option(unsigned int pluginId, unsigned int option, bool yesNo)
  1046. {
  1047. carla_debug("carla_set_option(%i, %i, %s)", pluginId, option, bool2str(yesNo));
  1048. CARLA_ASSERT(standalone.engine != nullptr);
  1049. if (standalone.engine == nullptr)
  1050. return;
  1051. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1052. return plugin->setOption(option, yesNo);
  1053. carla_stderr2("carla_set_option(%i, %i, %s) - could not find plugin", pluginId, option, bool2str(yesNo));
  1054. }
  1055. void carla_set_active(unsigned int pluginId, bool onOff)
  1056. {
  1057. carla_debug("carla_set_active(%i, %s)", pluginId, bool2str(onOff));
  1058. CARLA_ASSERT(standalone.engine != nullptr);
  1059. if (standalone.engine == nullptr)
  1060. return;
  1061. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1062. return plugin->setActive(onOff, true, false);
  1063. carla_stderr2("carla_set_active(%i, %s) - could not find plugin", pluginId, bool2str(onOff));
  1064. }
  1065. void carla_set_drywet(unsigned int pluginId, float value)
  1066. {
  1067. carla_debug("carla_set_drywet(%i, %f)", pluginId, value);
  1068. CARLA_ASSERT(standalone.engine != nullptr);
  1069. if (standalone.engine == nullptr)
  1070. return;
  1071. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1072. return plugin->setDryWet(value, true, false);
  1073. carla_stderr2("carla_set_drywet(%i, %f) - could not find plugin", pluginId, value);
  1074. }
  1075. void carla_set_volume(unsigned int pluginId, float value)
  1076. {
  1077. carla_debug("carla_set_volume(%i, %f)", pluginId, value);
  1078. CARLA_ASSERT(standalone.engine != nullptr);
  1079. if (standalone.engine == nullptr)
  1080. return;
  1081. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1082. return plugin->setVolume(value, true, false);
  1083. carla_stderr2("carla_set_volume(%i, %f) - could not find plugin", pluginId, value);
  1084. }
  1085. void carla_set_balance_left(unsigned int pluginId, float value)
  1086. {
  1087. carla_debug("carla_set_balance_left(%i, %f)", pluginId, value);
  1088. CARLA_ASSERT(standalone.engine != nullptr);
  1089. if (standalone.engine == nullptr)
  1090. return;
  1091. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1092. return plugin->setBalanceLeft(value, true, false);
  1093. carla_stderr2("carla_set_balance_left(%i, %f) - could not find plugin", pluginId, value);
  1094. }
  1095. void carla_set_balance_right(unsigned int pluginId, float value)
  1096. {
  1097. carla_debug("carla_set_balance_right(%i, %f)", pluginId, value);
  1098. CARLA_ASSERT(standalone.engine != nullptr);
  1099. if (standalone.engine == nullptr)
  1100. return;
  1101. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1102. return plugin->setBalanceRight(value, true, false);
  1103. carla_stderr2("carla_set_balance_right(%i, %f) - could not find plugin", pluginId, value);
  1104. }
  1105. void carla_set_panning(unsigned int pluginId, float value)
  1106. {
  1107. carla_debug("carla_set_panning(%i, %f)", pluginId, value);
  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->setPanning(value, true, false);
  1113. carla_stderr2("carla_set_panning(%i, %f) - could not find plugin", pluginId, value);
  1114. }
  1115. void carla_set_ctrl_channel(unsigned int pluginId, int8_t channel)
  1116. {
  1117. carla_debug("carla_set_ctrl_channel(%i, %i)", pluginId, channel);
  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->setCtrlChannel(channel, true, false);
  1123. carla_stderr2("carla_set_ctrl_channel(%i, %i) - could not find plugin", pluginId, channel);
  1124. }
  1125. // -------------------------------------------------------------------------------------------------------------------
  1126. void carla_set_parameter_value(unsigned int pluginId, uint32_t parameterId, float value)
  1127. {
  1128. carla_debug("carla_set_parameter_value(%i, %i, %f)", pluginId, parameterId, value);
  1129. CARLA_ASSERT(standalone.engine != nullptr);
  1130. if (standalone.engine == nullptr)
  1131. return;
  1132. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1133. {
  1134. if (parameterId < plugin->parameterCount())
  1135. return plugin->setParameterValue(parameterId, value, true, true, false);
  1136. carla_stderr2("carla_set_parameter_value(%i, %i, %f) - parameterId out of bounds", pluginId, parameterId, value);
  1137. return;
  1138. }
  1139. carla_stderr2("carla_set_parameter_value(%i, %i, %f) - could not find plugin", pluginId, parameterId, value);
  1140. }
  1141. void carla_set_parameter_midi_channel(unsigned int pluginId, uint32_t parameterId, uint8_t channel)
  1142. {
  1143. carla_debug("carla_set_parameter_midi_channel(%i, %i, %i)", pluginId, parameterId, channel);
  1144. CARLA_ASSERT(standalone.engine != nullptr);
  1145. CARLA_ASSERT(channel < MAX_MIDI_CHANNELS);
  1146. if (channel >= MAX_MIDI_CHANNELS)
  1147. {
  1148. carla_stderr2("carla_set_parameter_midi_channel(%i, %i, %i) - invalid channel number", pluginId, parameterId, channel);
  1149. return;
  1150. }
  1151. if (standalone.engine == nullptr)
  1152. return;
  1153. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1154. {
  1155. if (parameterId < plugin->parameterCount())
  1156. return plugin->setParameterMidiChannel(parameterId, channel, true, false);
  1157. carla_stderr2("carla_set_parameter_midi_channel(%i, %i, %i) - parameterId out of bounds", pluginId, parameterId, channel);
  1158. return;
  1159. }
  1160. carla_stderr2("carla_set_parameter_midi_channel(%i, %i, %i) - could not find plugin", pluginId, parameterId, channel);
  1161. }
  1162. void carla_set_parameter_midi_cc(unsigned int pluginId, uint32_t parameterId, int16_t cc)
  1163. {
  1164. carla_debug("carla_set_parameter_midi_cc(%i, %i, %i)", pluginId, parameterId, cc);
  1165. CARLA_ASSERT(standalone.engine != nullptr);
  1166. CARLA_ASSERT(cc >= -1 && cc <= 0x5F);
  1167. if (cc < -1)
  1168. {
  1169. cc = -1;
  1170. }
  1171. else if (cc > 0x5F) // 95
  1172. {
  1173. carla_stderr2("carla_set_parameter_midi_cc(%i, %i, %i) - invalid cc number", pluginId, parameterId, cc);
  1174. return;
  1175. }
  1176. if (standalone.engine == nullptr)
  1177. return;
  1178. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1179. {
  1180. if (parameterId < plugin->parameterCount())
  1181. return plugin->setParameterMidiCC(parameterId, cc, true, false);
  1182. carla_stderr2("carla_set_parameter_midi_cc(%i, %i, %i) - parameterId out of bounds", pluginId, parameterId, cc);
  1183. return;
  1184. }
  1185. carla_stderr2("carla_set_parameter_midi_cc(%i, %i, %i) - could not find plugin", pluginId, parameterId, cc);
  1186. }
  1187. void carla_set_program(unsigned int pluginId, uint32_t programId)
  1188. {
  1189. carla_debug("carla_set_program(%i, %i)", pluginId, programId);
  1190. CARLA_ASSERT(standalone.engine != nullptr);
  1191. if (standalone.engine == nullptr)
  1192. return;
  1193. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1194. {
  1195. if (programId < plugin->programCount())
  1196. return plugin->setProgram(static_cast<int32_t>(programId), true, true, false);
  1197. carla_stderr2("carla_set_program(%i, %i) - programId out of bounds", pluginId, programId);
  1198. return;
  1199. }
  1200. carla_stderr2("carla_set_program(%i, %i) - could not find plugin", pluginId, programId);
  1201. }
  1202. void carla_set_midi_program(unsigned int pluginId, uint32_t midiProgramId)
  1203. {
  1204. carla_debug("carla_set_midi_program(%i, %i)", pluginId, midiProgramId);
  1205. CARLA_ASSERT(standalone.engine != nullptr);
  1206. if (standalone.engine == nullptr)
  1207. return;
  1208. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1209. {
  1210. if (midiProgramId < plugin->midiProgramCount())
  1211. return plugin->setMidiProgram(static_cast<int32_t>(midiProgramId), true, true, false);
  1212. carla_stderr2("carla_set_midi_program(%i, %i) - midiProgramId out of bounds", pluginId, midiProgramId);
  1213. return;
  1214. }
  1215. carla_stderr2("carla_set_midi_program(%i, %i) - could not find plugin", pluginId, midiProgramId);
  1216. }
  1217. // -------------------------------------------------------------------------------------------------------------------
  1218. void carla_set_custom_data(unsigned int pluginId, const char* type, const char* key, const char* value)
  1219. {
  1220. carla_debug("carla_set_custom_data(%i, \"%s\", \"%s\", \"%s\")", pluginId, type, key, value);
  1221. CARLA_ASSERT(standalone.engine != nullptr);
  1222. if (standalone.engine == nullptr)
  1223. return;
  1224. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1225. return plugin->setCustomData(type, key, value, true);
  1226. carla_stderr2("carla_set_custom_data(%i, \"%s\", \"%s\", \"%s\") - could not find plugin", pluginId, type, key, value);
  1227. }
  1228. void carla_set_chunk_data(unsigned int pluginId, const char* chunkData)
  1229. {
  1230. carla_debug("carla_set_chunk_data(%i, \"%s\")", pluginId, chunkData);
  1231. CARLA_ASSERT(standalone.engine != nullptr);
  1232. if (standalone.engine == nullptr)
  1233. return;
  1234. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1235. {
  1236. if (plugin->options() & CarlaBackend::PLUGIN_OPTION_USE_CHUNKS)
  1237. return plugin->setChunkData(chunkData);
  1238. carla_stderr2("carla_set_chunk_data(%i, \"%s\") - plugin does not support chunks", pluginId, chunkData);
  1239. return;
  1240. }
  1241. carla_stderr2("carla_set_chunk_data(%i, \"%s\") - could not find plugin", pluginId, chunkData);
  1242. }
  1243. // -------------------------------------------------------------------------------------------------------------------
  1244. void carla_prepare_for_save(unsigned int pluginId)
  1245. {
  1246. carla_debug("carla_prepare_for_save(%i)", pluginId);
  1247. CARLA_ASSERT(standalone.engine != nullptr);
  1248. if (standalone.engine == nullptr)
  1249. return;
  1250. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1251. return plugin->prepareForSave();
  1252. carla_stderr2("carla_prepare_for_save(%i) - could not find plugin", pluginId);
  1253. }
  1254. void carla_send_midi_note(unsigned int pluginId, uint8_t channel, uint8_t note, uint8_t velocity)
  1255. {
  1256. carla_debug("carla_send_midi_note(%i, %i, %i, %i)", pluginId, channel, note, velocity);
  1257. CARLA_ASSERT(standalone.engine != nullptr);
  1258. if (standalone.engine == nullptr || ! standalone.engine->isRunning())
  1259. return;
  1260. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1261. return plugin->sendMidiSingleNote(channel, note, velocity, true, true, false);
  1262. carla_stderr2("carla_send_midi_note(%i, %i, %i, %i) - could not find plugin", pluginId, channel, note, velocity);
  1263. }
  1264. void carla_show_gui(unsigned int pluginId, bool yesno)
  1265. {
  1266. carla_debug("carla_show_gui(%i, %s)", pluginId, bool2str(yesno));
  1267. CARLA_ASSERT(standalone.engine != nullptr);
  1268. if (standalone.engine == nullptr)
  1269. return;
  1270. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1271. return plugin->showGui(yesno);
  1272. carla_stderr2("carla_show_gui(%i, %s) - could not find plugin", pluginId, bool2str(yesno));
  1273. }
  1274. // -------------------------------------------------------------------------------------------------------------------
  1275. uint32_t carla_get_buffer_size()
  1276. {
  1277. carla_debug("carla_get_buffer_size()");
  1278. CARLA_ASSERT(standalone.engine != nullptr);
  1279. if (standalone.engine == nullptr)
  1280. return 0;
  1281. return standalone.engine->getBufferSize();
  1282. }
  1283. double carla_get_sample_rate()
  1284. {
  1285. carla_debug("carla_get_sample_rate()");
  1286. CARLA_ASSERT(standalone.engine != nullptr);
  1287. if (standalone.engine == nullptr)
  1288. return 0.0;
  1289. return standalone.engine->getSampleRate();
  1290. }
  1291. // -------------------------------------------------------------------------------------------------------------------
  1292. const char* carla_get_last_error()
  1293. {
  1294. carla_debug("carla_get_last_error()");
  1295. if (standalone.engine != nullptr)
  1296. return standalone.engine->getLastError();
  1297. return standalone.lastError;
  1298. }
  1299. const char* carla_get_host_osc_url()
  1300. {
  1301. carla_debug("carla_get_host_osc_url()");
  1302. CARLA_ASSERT(standalone.engine != nullptr);
  1303. if (standalone.engine == nullptr)
  1304. return nullptr;
  1305. return standalone.engine->getOscServerPathTCP();
  1306. }
  1307. #if 0
  1308. // -------------------------------------------------------------------------------------------------------------------
  1309. #define NSM_API_VERSION_MAJOR 1
  1310. #define NSM_API_VERSION_MINOR 0
  1311. class CarlaNSM
  1312. {
  1313. public:
  1314. CarlaNSM()
  1315. {
  1316. m_controlAddr = nullptr;
  1317. m_serverThread = nullptr;
  1318. m_isOpened = false;
  1319. m_isSaved = false;
  1320. }
  1321. ~CarlaNSM()
  1322. {
  1323. if (m_controlAddr)
  1324. lo_address_free(m_controlAddr);
  1325. if (m_serverThread)
  1326. {
  1327. lo_server_thread_stop(m_serverThread);
  1328. lo_server_thread_del_method(m_serverThread, "/reply", "ssss");
  1329. lo_server_thread_del_method(m_serverThread, "/nsm/client/open", "sss");
  1330. lo_server_thread_del_method(m_serverThread, "/nsm/client/save", "");
  1331. lo_server_thread_free(m_serverThread);
  1332. }
  1333. }
  1334. void announce(const char* const url, const int pid)
  1335. {
  1336. lo_address addr = lo_address_new_from_url(url);
  1337. int proto = lo_address_get_protocol(addr);
  1338. if (! m_serverThread)
  1339. {
  1340. // create new OSC thread
  1341. m_serverThread = lo_server_thread_new_with_proto(nullptr, proto, error_handler);
  1342. // register message handlers and start OSC thread
  1343. lo_server_thread_add_method(m_serverThread, "/reply", "ssss", _reply_handler, this);
  1344. lo_server_thread_add_method(m_serverThread, "/nsm/client/open", "sss", _nsm_open_handler, this);
  1345. lo_server_thread_add_method(m_serverThread, "/nsm/client/save", "", _nsm_save_handler, this);
  1346. lo_server_thread_start(m_serverThread);
  1347. }
  1348. lo_send_from(addr, lo_server_thread_get_server(m_serverThread), LO_TT_IMMEDIATE, "/nsm/server/announce", "sssiii",
  1349. "Carla", ":switch:", "carla", NSM_API_VERSION_MAJOR, NSM_API_VERSION_MINOR, pid);
  1350. lo_address_free(addr);
  1351. }
  1352. void replyOpen()
  1353. {
  1354. m_isOpened = true;
  1355. }
  1356. void replySave()
  1357. {
  1358. m_isSaved = true;
  1359. }
  1360. protected:
  1361. int reply_handler(const char* const path, const char* const types, lo_arg** const argv, const int argc, const lo_message msg)
  1362. {
  1363. carla_debug("CarlaNSM::reply_handler(%s, %i, %p, %s, %p)", path, argc, argv, types, msg);
  1364. m_controlAddr = lo_address_new_from_url(lo_address_get_url(lo_message_get_source(msg)));
  1365. const char* const method = &argv[0]->s;
  1366. if (std::strcmp(method, "/nsm/server/announce") == 0 && standalone.callback)
  1367. standalone.callback(nullptr, CarlaBackend::CALLBACK_NSM_ANNOUNCE, 0, 0, 0, 0.0, nullptr); // FIXME?
  1368. return 0;
  1369. }
  1370. int nsm_open_handler(const char* const path, const char* const types, lo_arg** const argv, const int argc, const lo_message msg)
  1371. {
  1372. carla_debug("CarlaNSM::nsm_open_handler(\"%s\", \"%s\", %p, %i, %p)", path, types, argv, argc, msg);
  1373. if (! standalone.callback)
  1374. return 1;
  1375. const char* const projectPath = &argv[0]->s;
  1376. const char* const clientId = &argv[2]->s;
  1377. standalone.callback(nullptr, CarlaBackend::CALLBACK_NSM_OPEN1, 0, 0, 0, 0.0, clientId);
  1378. standalone.callback(nullptr, CarlaBackend::CALLBACK_NSM_OPEN2, 0, 0, 0, 0.0, projectPath);
  1379. for (int i=0; i < 30 && ! m_isOpened; i++)
  1380. carla_msleep(100);
  1381. if (m_controlAddr)
  1382. lo_send_from(m_controlAddr, lo_server_thread_get_server(m_serverThread), LO_TT_IMMEDIATE, "/reply", "ss", "/nsm/client/open", "OK");
  1383. return 0;
  1384. }
  1385. int nsm_save_handler(const char* const path, const char* const types, lo_arg** const argv, const int argc, const lo_message msg)
  1386. {
  1387. carla_debug("CarlaNSM::nsm_save_handler(\"%s\", \"%s\", %p, %i, %p)", path, types, argv, argc, msg);
  1388. if (! standalone.callback)
  1389. return 1;
  1390. standalone.callback(nullptr, CarlaBackend::CALLBACK_NSM_SAVE, 0, 0, 0, 0.0, nullptr);
  1391. for (int i=0; i < 30 && ! m_isSaved; i++)
  1392. carla_msleep(100);
  1393. if (m_controlAddr)
  1394. lo_send_from(m_controlAddr, lo_server_thread_get_server(m_serverThread), LO_TT_IMMEDIATE, "/reply", "ss", "/nsm/client/save", "OK");
  1395. return 0;
  1396. }
  1397. private:
  1398. lo_address m_controlAddr;
  1399. lo_server_thread m_serverThread;
  1400. bool m_isOpened, m_isSaved;
  1401. 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)
  1402. {
  1403. CARLA_ASSERT(data);
  1404. CarlaNSM* const _this_ = (CarlaNSM*)data;
  1405. return _this_->reply_handler(path, types, argv, argc, msg);
  1406. }
  1407. 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)
  1408. {
  1409. CARLA_ASSERT(data);
  1410. CarlaNSM* const _this_ = (CarlaNSM*)data;
  1411. return _this_->nsm_open_handler(path, types, argv, argc, msg);
  1412. }
  1413. 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)
  1414. {
  1415. CARLA_ASSERT(data);
  1416. CarlaNSM* const _this_ = (CarlaNSM*)data;
  1417. return _this_->nsm_save_handler(path, types, argv, argc, msg);
  1418. }
  1419. static void error_handler(const int num, const char* const msg, const char* const path)
  1420. {
  1421. carla_stderr2("CarlaNSM::error_handler(%i, \"%s\", \"%s\")", num, msg, path);
  1422. }
  1423. };
  1424. static CarlaNSM carlaNSM;
  1425. void carla_nsm_announce(const char* url, int pid)
  1426. {
  1427. carlaNSM.announce(url, pid);
  1428. }
  1429. void carla_nsm_reply_open()
  1430. {
  1431. carlaNSM.replyOpen();
  1432. }
  1433. void carla_nsm_reply_save()
  1434. {
  1435. carlaNSM.replySave();
  1436. }
  1437. #endif
  1438. // -------------------------------------------------------------------------------------------------------------------
  1439. #ifdef BUILD_BRIDGE
  1440. bool carla_engine_init_bridge(const char* audioBaseName, const char* controlBaseName, const char* clientName)
  1441. {
  1442. carla_debug("carla_engine_init_bridge(\"%s\", \"%s\", \"%s\")", audioBaseName, controlBaseName, clientName);
  1443. CARLA_ASSERT(standalone.engine == nullptr);
  1444. CARLA_ASSERT(audioBaseName != nullptr);
  1445. CARLA_ASSERT(controlBaseName != nullptr);
  1446. CARLA_ASSERT(clientName != nullptr);
  1447. standalone.engine = CarlaEngine::newBridge(audioBaseName, controlBaseName);
  1448. if (standalone.engine == nullptr)
  1449. {
  1450. standalone.lastError = "The seleted audio driver is not available!";
  1451. return false;
  1452. }
  1453. if (standalone.callback != nullptr)
  1454. standalone.engine->setCallback(standalone.callback, nullptr);
  1455. standalone.engine->setOption(CarlaBackend::OPTION_PROCESS_MODE, CarlaBackend::PROCESS_MODE_BRIDGE, nullptr);
  1456. standalone.engine->setOption(CarlaBackend::OPTION_TRANSPORT_MODE, CarlaBackend::TRANSPORT_MODE_BRIDGE, nullptr);
  1457. standalone.engine->setOption(CarlaBackend::OPTION_PREFER_PLUGIN_BRIDGES, false, nullptr);
  1458. standalone.engine->setOption(CarlaBackend::OPTION_PREFER_UI_BRIDGES, false, nullptr);
  1459. // TODO - read from environment
  1460. #ifndef BUILD_BRIDGE
  1461. standalone.engine->setOption(CarlaBackend::OPTION_FORCE_STEREO, standalone.options.forceStereo ? 1 : 0, nullptr);
  1462. # ifdef WANT_DSSI
  1463. standalone.engine->setOption(CarlaBackend::OPTION_USE_DSSI_VST_CHUNKS, standalone.options.useDssiVstChunks ? 1 : 0, nullptr);
  1464. # endif
  1465. standalone.engine->setOption(CarlaBackend::OPTION_MAX_PARAMETERS, static_cast<int>(standalone.options.maxParameters), nullptr);
  1466. #endif
  1467. const bool initiated = standalone.engine->init(clientName);
  1468. if (initiated)
  1469. {
  1470. standalone.lastError = "no error";
  1471. standalone.init();
  1472. }
  1473. else
  1474. {
  1475. standalone.lastError = standalone.engine->getLastError();
  1476. delete standalone.engine;
  1477. standalone.engine = nullptr;
  1478. }
  1479. return initiated;
  1480. }
  1481. CarlaEngine* carla_get_standalone_engine()
  1482. {
  1483. return standalone.engine;
  1484. }
  1485. #endif
  1486. // -------------------------------------------------------------------------------------------------------------------
  1487. #if 0
  1488. //def QTCREATOR_TEST
  1489. #include <QtGui/QApplication>
  1490. #include <QtGui/QDialog>
  1491. QDialog* vstGui = nullptr;
  1492. void main_callback(void* ptr, CarlaBackend::CallbackType action, unsigned int pluginId, int value1, int value2, double value3)
  1493. {
  1494. switch (action)
  1495. {
  1496. case CarlaBackend::CALLBACK_SHOW_GUI:
  1497. if (vstGui && ! value1)
  1498. vstGui->close();
  1499. break;
  1500. case CarlaBackend::CALLBACK_RESIZE_GUI:
  1501. vstGui->setFixedSize(value1, value2);
  1502. break;
  1503. default:
  1504. break;
  1505. }
  1506. Q_UNUSED(ptr);
  1507. Q_UNUSED(pluginId);
  1508. Q_UNUSED(value3);
  1509. }
  1510. void run_tests_standalone(short idMax)
  1511. {
  1512. for (short id = 0; id <= idMax; id++)
  1513. {
  1514. carla_debug("------------------- TEST @%i: non-parameter calls --------------------", id);
  1515. get_plugin_info(id);
  1516. get_audio_port_count_info(id);
  1517. get_midi_port_count_info(id);
  1518. get_parameter_count_info(id);
  1519. get_gui_info(id);
  1520. get_chunk_data(id);
  1521. get_parameter_count(id);
  1522. get_program_count(id);
  1523. get_midi_program_count(id);
  1524. get_custom_data_count(id);
  1525. get_real_plugin_name(id);
  1526. get_current_program_index(id);
  1527. get_current_midi_program_index(id);
  1528. carla_debug("------------------- TEST @%i: parameter calls [-1] --------------------", id);
  1529. get_parameter_info(id, -1);
  1530. get_parameter_scalepoint_info(id, -1, -1);
  1531. get_parameter_data(id, -1);
  1532. get_parameter_ranges(id, -1);
  1533. get_midi_program_data(id, -1);
  1534. get_custom_data(id, -1);
  1535. get_parameter_text(id, -1);
  1536. get_program_name(id, -1);
  1537. get_midi_program_name(id, -1);
  1538. get_default_parameter_value(id, -1);
  1539. get_current_parameter_value(id, -1);
  1540. get_input_peak_value(id, -1);
  1541. get_output_peak_value(id, -1);
  1542. carla_debug("------------------- TEST @%i: parameter calls [0] --------------------", id);
  1543. get_parameter_info(id, 0);
  1544. get_parameter_scalepoint_info(id, 0, -1);
  1545. get_parameter_scalepoint_info(id, 0, 0);
  1546. get_parameter_data(id, 0);
  1547. get_parameter_ranges(id, 0);
  1548. get_midi_program_data(id, 0);
  1549. get_custom_data(id, 0);
  1550. get_parameter_text(id, 0);
  1551. get_program_name(id, 0);
  1552. get_midi_program_name(id, 0);
  1553. get_default_parameter_value(id, 0);
  1554. get_current_parameter_value(id, 0);
  1555. get_input_peak_value(id, 0);
  1556. get_input_peak_value(id, 1);
  1557. get_input_peak_value(id, 2);
  1558. get_output_peak_value(id, 0);
  1559. get_output_peak_value(id, 1);
  1560. get_output_peak_value(id, 2);
  1561. carla_debug("------------------- TEST @%i: set extra data --------------------", id);
  1562. set_custom_data(id, CarlaBackend::CUSTOM_DATA_STRING, "", "");
  1563. set_chunk_data(id, nullptr);
  1564. set_gui_container(id, (uintptr_t)1);
  1565. carla_debug("------------------- TEST @%i: gui stuff --------------------", id);
  1566. show_gui(id, false);
  1567. show_gui(id, true);
  1568. show_gui(id, true);
  1569. idle_guis();
  1570. idle_guis();
  1571. idle_guis();
  1572. carla_debug("------------------- TEST @%i: other --------------------", id);
  1573. send_midi_note(id, 15, 127, 127);
  1574. send_midi_note(id, 0, 0, 0);
  1575. prepare_for_save(id);
  1576. prepare_for_save(id);
  1577. prepare_for_save(id);
  1578. }
  1579. }
  1580. int main(int argc, char* argv[])
  1581. {
  1582. using namespace CarlaBackend;
  1583. // Qt app
  1584. QApplication app(argc, argv);
  1585. // Qt gui (for vst)
  1586. vstGui = new QDialog(nullptr);
  1587. // set callback and options
  1588. set_callback_function(main_callback);
  1589. set_option(OPTION_PREFER_UI_BRIDGES, 0, nullptr);
  1590. //set_option(OPTION_PROCESS_MODE, PROCESS_MODE_CONTINUOUS_RACK, nullptr);
  1591. // start engine
  1592. if (! engine_init("JACK", "carla_demo"))
  1593. {
  1594. carla_stderr2("failed to start backend engine, reason:\n%s", get_last_error());
  1595. delete vstGui;
  1596. return 1;
  1597. }
  1598. short id_ladspa = add_plugin(BINARY_NATIVE, PLUGIN_LADSPA, "/usr/lib/ladspa/LEET_eqbw2x2.so", "LADSPA plug name, test long name - "
  1599. "------- name ------------ name2 ----------- name3 ------------ name4 ------------ name5 ---------- name6", "leet_equalizer_bw2x2", nullptr);
  1600. 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");
  1601. short id_native = add_plugin(BINARY_NATIVE, PLUGIN_INTERNAL, "", "ZynHere", "zynaddsubfx", nullptr);
  1602. //short id_lv2 = add_plugin(BINARY_NATIVE, PLUGIN_LV2, "FILENAME", "HAHA name!!!", "http://studionumbersix.com/foo/lv2/yc20", nullptr);
  1603. //short id_vst = add_plugin(BINARY_NATIVE, PLUGIN_LV2, "FILENAME", "HAHA name!!!", "http://studionumbersix.com/foo/lv2/yc20", nullptr);
  1604. if (id_ladspa < 0 || id_dssi < 0 || id_native < 0)
  1605. {
  1606. carla_stderr2("failed to start load plugins, reason:\n%s", get_last_error());
  1607. delete vstGui;
  1608. return 1;
  1609. }
  1610. //const GuiInfo* const guiInfo = get_gui_info(id);
  1611. //if (guiInfo->type == CarlaBackend::GUI_INTERNAL_QT4 || guiInfo->type == CarlaBackend::GUI_INTERNAL_X11)
  1612. //{
  1613. // set_gui_data(id, 0, (uintptr_t)gui);
  1614. //gui->show();
  1615. //}
  1616. // activate
  1617. set_active(id_ladspa, true);
  1618. set_active(id_dssi, true);
  1619. set_active(id_native, true);
  1620. // start guis
  1621. show_gui(id_dssi, true);
  1622. carla_sleep(1);
  1623. // do tests
  1624. run_tests_standalone(id_dssi+1);
  1625. // lock
  1626. app.exec();
  1627. delete vstGui;
  1628. vstGui = nullptr;
  1629. remove_plugin(id_ladspa);
  1630. remove_plugin(id_dssi);
  1631. remove_plugin(id_native);
  1632. engine_close();
  1633. return 0;
  1634. }
  1635. #endif