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.

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