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.

2036 lines
66KB

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