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.

1995 lines
65KB

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