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.

2117 lines
69KB

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