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.

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