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.

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