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.

1941 lines
63KB

  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_transport_play()
  394. {
  395. carla_debug("carla_transport_play()");
  396. CARLA_ASSERT(standalone.engine != nullptr);
  397. if (standalone.engine != nullptr)
  398. return standalone.engine->transportPlay();
  399. }
  400. void carla_transport_pause()
  401. {
  402. carla_debug("carla_transport_pause()");
  403. CARLA_ASSERT(standalone.engine != nullptr);
  404. if (standalone.engine != nullptr)
  405. return standalone.engine->transportPause();
  406. }
  407. void carla_transport_relocate(uint32_t frames)
  408. {
  409. carla_debug("carla_transport_relocate(%i)", frames);
  410. CARLA_ASSERT(standalone.engine != nullptr);
  411. if (standalone.engine != nullptr)
  412. return standalone.engine->transportRelocate(frames);
  413. }
  414. // -------------------------------------------------------------------------------------------------------------------
  415. bool carla_add_plugin(CarlaBackend::BinaryType btype, CarlaBackend::PluginType ptype, const char* filename, const char* const name, const char* label, const void* extraStuff)
  416. {
  417. carla_debug("carla_add_plugin(%s, %s, \"%s\", \"%s\", \"%s\", %p)", CarlaBackend::BinaryType2Str(btype), CarlaBackend::PluginType2Str(ptype), filename, name, label, extraStuff);
  418. CARLA_ASSERT(standalone.engine != nullptr);
  419. if (standalone.engine != nullptr && standalone.engine->isRunning())
  420. return standalone.engine->addPlugin(btype, ptype, filename, name, label, extraStuff);
  421. standalone.lastError = "Engine is not started";
  422. return false;
  423. }
  424. bool carla_remove_plugin(unsigned int pluginId)
  425. {
  426. carla_debug("carla_remove_plugin(%i)", pluginId);
  427. CARLA_ASSERT(standalone.engine != nullptr);
  428. if (standalone.engine != nullptr && standalone.engine->isRunning())
  429. return standalone.engine->removePlugin(pluginId);
  430. standalone.lastError = "Engine is not started";
  431. return false;
  432. }
  433. void carla_remove_all_plugins()
  434. {
  435. carla_debug("carla_remove_all_plugins()");
  436. CARLA_ASSERT(standalone.engine != nullptr);
  437. if (standalone.engine != nullptr && standalone.engine->isRunning())
  438. standalone.engine->removeAllPlugins();
  439. }
  440. // -------------------------------------------------------------------------------------------------------------------
  441. const CarlaPluginInfo* carla_get_plugin_info(unsigned int pluginId)
  442. {
  443. carla_debug("carla_get_plugin_info(%i)", pluginId);
  444. CARLA_ASSERT(standalone.engine != nullptr);
  445. static CarlaPluginInfo info;
  446. // reset
  447. info.type = CarlaBackend::PLUGIN_NONE;
  448. info.category = CarlaBackend::PLUGIN_CATEGORY_NONE;
  449. info.hints = 0x0;
  450. info.hints = 0x0;
  451. info.binary = nullptr;
  452. info.name = nullptr;
  453. info.uniqueId = 0;
  454. info.latency = 0;
  455. info.optionsAvailable = 0x0;
  456. info.optionsEnabled = 0x0;
  457. // cleanup
  458. if (info.label != nullptr)
  459. {
  460. delete[] info.label;
  461. info.label = nullptr;
  462. }
  463. if (info.maker != nullptr)
  464. {
  465. delete[] info.maker;
  466. info.maker = nullptr;
  467. }
  468. if (info.copyright != nullptr)
  469. {
  470. delete[] info.copyright;
  471. info.copyright = nullptr;
  472. }
  473. if (standalone.engine == nullptr)
  474. return &info;
  475. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  476. {
  477. char strBufLabel[STR_MAX] = { 0 };
  478. char strBufMaker[STR_MAX] = { 0 };
  479. char strBufCopyright[STR_MAX] = { 0 };
  480. info.type = plugin->type();
  481. info.category = plugin->category();
  482. info.hints = plugin->hints();
  483. info.binary = plugin->filename();
  484. info.name = plugin->name();
  485. info.uniqueId = plugin->uniqueId();
  486. info.latency = plugin->latency();
  487. info.optionsAvailable = plugin->availableOptions();
  488. info.optionsEnabled = plugin->options();
  489. plugin->getLabel(strBufLabel);
  490. info.label = carla_strdup(strBufLabel);
  491. plugin->getMaker(strBufMaker);
  492. info.maker = carla_strdup(strBufMaker);
  493. plugin->getCopyright(strBufCopyright);
  494. info.copyright = carla_strdup(strBufCopyright);
  495. return &info;
  496. }
  497. carla_stderr2("carla_get_plugin_info(%i) - could not find plugin", pluginId);
  498. return &info;
  499. }
  500. const CarlaPortCountInfo* carla_get_audio_port_count_info(unsigned int pluginId)
  501. {
  502. carla_debug("carla_get_audio_port_count_info(%i)", pluginId);
  503. CARLA_ASSERT(standalone.engine != nullptr);
  504. static CarlaPortCountInfo info;
  505. // reset
  506. info.ins = 0;
  507. info.outs = 0;
  508. info.total = 0;
  509. if (standalone.engine == nullptr)
  510. return &info;
  511. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  512. {
  513. info.ins = plugin->audioInCount();
  514. info.outs = plugin->audioOutCount();
  515. info.total = info.ins + info.outs;
  516. return &info;
  517. }
  518. carla_stderr2("carla_get_audio_port_count_info(%i) - could not find plugin", pluginId);
  519. return &info;
  520. }
  521. const CarlaPortCountInfo* carla_get_midi_port_count_info(unsigned int pluginId)
  522. {
  523. carla_debug("carla_get_midi_port_count_info(%i)", pluginId);
  524. CARLA_ASSERT(standalone.engine != nullptr);
  525. static CarlaPortCountInfo info;
  526. // reset
  527. info.ins = 0;
  528. info.outs = 0;
  529. info.total = 0;
  530. if (standalone.engine == nullptr)
  531. return &info;
  532. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  533. {
  534. info.ins = plugin->midiInCount();
  535. info.outs = plugin->midiOutCount();
  536. info.total = info.ins + info.outs;
  537. return &info;
  538. }
  539. carla_stderr2("carla_get_midi_port_count_info(%i) - could not find plugin", pluginId);
  540. return &info;
  541. }
  542. const CarlaPortCountInfo* carla_get_parameter_count_info(unsigned int pluginId)
  543. {
  544. carla_debug("carla_get_parameter_count_info(%i)", pluginId);
  545. CARLA_ASSERT(standalone.engine != nullptr);
  546. static CarlaPortCountInfo info;
  547. // reset
  548. info.ins = 0;
  549. info.outs = 0;
  550. info.total = 0;
  551. if (standalone.engine == nullptr)
  552. return &info;
  553. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  554. {
  555. plugin->getParameterCountInfo(&info.ins, &info.outs, &info.total);
  556. return &info;
  557. }
  558. carla_stderr2("carla_get_parameter_count_info(%i) - could not find plugin", pluginId);
  559. return &info;
  560. }
  561. const CarlaParameterInfo* carla_get_parameter_info(unsigned int pluginId, uint32_t parameterId)
  562. {
  563. carla_debug("carla_get_parameter_info(%i, %i)", pluginId, parameterId);
  564. CARLA_ASSERT(standalone.engine != nullptr);
  565. static CarlaParameterInfo info;
  566. // reset
  567. info.scalePointCount = 0;
  568. // cleanup
  569. if (info.name != nullptr)
  570. {
  571. delete[] info.name;
  572. info.name = nullptr;
  573. }
  574. if (info.symbol != nullptr)
  575. {
  576. delete[] info.symbol;
  577. info.symbol = nullptr;
  578. }
  579. if (info.unit != nullptr)
  580. {
  581. delete[] info.unit;
  582. info.unit = nullptr;
  583. }
  584. if (standalone.engine == nullptr)
  585. return &info;
  586. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  587. {
  588. if (parameterId < plugin->parameterCount())
  589. {
  590. char strBufName[STR_MAX] = { 0 };
  591. char strBufSymbol[STR_MAX] = { 0 };
  592. char strBufUnit[STR_MAX] = { 0 };
  593. info.scalePointCount = plugin->parameterScalePointCount(parameterId);
  594. plugin->getParameterName(parameterId, strBufName);
  595. info.name = carla_strdup(strBufName);
  596. plugin->getParameterSymbol(parameterId, strBufSymbol);
  597. info.symbol = carla_strdup(strBufSymbol);
  598. plugin->getParameterUnit(parameterId, strBufUnit);
  599. info.unit = carla_strdup(strBufUnit);
  600. }
  601. else
  602. carla_stderr2("carla_get_parameter_info(%i, %i) - parameterId out of bounds", pluginId, parameterId);
  603. return &info;
  604. }
  605. carla_stderr2("carla_get_parameter_info(%i, %i) - could not find plugin", pluginId, parameterId);
  606. return &info;
  607. }
  608. const CarlaScalePointInfo* carla_get_parameter_scalepoint_info(unsigned int pluginId, uint32_t parameterId, uint32_t scalePointId)
  609. {
  610. carla_debug("carla_get_parameter_scalepoint_info(%i, %i, %i)", pluginId, parameterId, scalePointId);
  611. CARLA_ASSERT(standalone.engine != nullptr);
  612. static CarlaScalePointInfo info;
  613. // reset
  614. info.value = 0.0f;
  615. // cleanup
  616. if (info.label != nullptr)
  617. {
  618. delete[] info.label;
  619. info.label = 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. if (scalePointId < plugin->parameterScalePointCount(parameterId))
  628. {
  629. char strBufLabel[STR_MAX] = { 0 };
  630. info.value = plugin->getParameterScalePointValue(parameterId, scalePointId);
  631. plugin->getParameterScalePointLabel(parameterId, scalePointId, strBufLabel);
  632. info.label = carla_strdup(strBufLabel);
  633. }
  634. else
  635. carla_stderr2("carla_get_parameter_scalepoint_info(%i, %i, %i) - scalePointId out of bounds", pluginId, parameterId, scalePointId);
  636. }
  637. else
  638. carla_stderr2("carla_get_parameter_scalepoint_info(%i, %i, %i) - parameterId out of bounds", pluginId, parameterId, scalePointId);
  639. return &info;
  640. }
  641. carla_stderr2("carla_get_parameter_scalepoint_info(%i, %i, %i) - could not find plugin", pluginId, parameterId, scalePointId);
  642. return &info;
  643. }
  644. // -------------------------------------------------------------------------------------------------------------------
  645. const CarlaBackend::ParameterData* carla_get_parameter_data(unsigned int pluginId, uint32_t parameterId)
  646. {
  647. carla_debug("carla_get_parameter_data(%i, %i)", pluginId, parameterId);
  648. CARLA_ASSERT(standalone.engine != nullptr);
  649. static CarlaBackend::ParameterData data;
  650. if (standalone.engine == nullptr)
  651. return &data;
  652. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  653. {
  654. if (parameterId < plugin->parameterCount())
  655. return &plugin->parameterData(parameterId);
  656. carla_stderr2("carla_get_parameter_data(%i, %i) - parameterId out of bounds", pluginId, parameterId);
  657. return &data;
  658. }
  659. carla_stderr2("carla_get_parameter_data(%i, %i) - could not find plugin", pluginId, parameterId);
  660. return &data;
  661. }
  662. const CarlaBackend::ParameterRanges* carla_get_parameter_ranges(unsigned int pluginId, uint32_t parameterId)
  663. {
  664. carla_debug("carla_get_parameter_ranges(%i, %i)", pluginId, parameterId);
  665. CARLA_ASSERT(standalone.engine != nullptr);
  666. static CarlaBackend::ParameterRanges ranges;
  667. if (standalone.engine == nullptr)
  668. return &ranges;
  669. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  670. {
  671. if (parameterId < plugin->parameterCount())
  672. return &plugin->parameterRanges(parameterId);
  673. carla_stderr2("carla_get_parameter_ranges(%i, %i) - parameterId out of bounds", pluginId, parameterId);
  674. return &ranges;
  675. }
  676. carla_stderr2("carla_get_parameter_ranges(%i, %i) - could not find plugin", pluginId, parameterId);
  677. return &ranges;
  678. }
  679. const CarlaBackend::MidiProgramData* carla_get_midi_program_data(unsigned int pluginId, uint32_t midiProgramId)
  680. {
  681. carla_debug("carla_get_midi_program_data(%i, %i)", pluginId, midiProgramId);
  682. CARLA_ASSERT(standalone.engine != nullptr);
  683. static CarlaBackend::MidiProgramData data;
  684. if (standalone.engine == nullptr)
  685. return &data;
  686. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  687. {
  688. if (midiProgramId < plugin->midiProgramCount())
  689. return &plugin->midiProgramData(midiProgramId);
  690. carla_stderr2("carla_get_midi_program_data(%i, %i) - midiProgramId out of bounds", pluginId, midiProgramId);
  691. return &data;
  692. }
  693. carla_stderr2("carla_get_midi_program_data(%i, %i) - could not find plugin", pluginId, midiProgramId);
  694. return &data;
  695. }
  696. const CarlaBackend::CustomData* carla_get_custom_data(unsigned int pluginId, uint32_t customDataId)
  697. {
  698. carla_debug("carla_get_custom_data(%i, %i)", pluginId, customDataId);
  699. CARLA_ASSERT(standalone.engine != nullptr);
  700. static CarlaBackend::CustomData data;
  701. if (standalone.engine == nullptr)
  702. return &data;
  703. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  704. {
  705. if (customDataId < plugin->customDataCount())
  706. return &plugin->customData(customDataId);
  707. carla_stderr2("carla_get_custom_data(%i, %i) - customDataId out of bounds", pluginId, customDataId);
  708. return &data;
  709. }
  710. carla_stderr2("carla_get_custom_data(%i, %i) - could not find plugin", pluginId, customDataId);
  711. return &data;
  712. }
  713. const char* carla_get_chunk_data(unsigned int pluginId)
  714. {
  715. carla_debug("carla_get_chunk_data(%i)", pluginId);
  716. CARLA_ASSERT(standalone.engine != nullptr);
  717. if (standalone.engine == nullptr)
  718. return nullptr;
  719. static CarlaString chunkData;
  720. // cleanup
  721. chunkData.clear();
  722. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  723. {
  724. if (plugin->options() & CarlaBackend::PLUGIN_OPTION_USE_CHUNKS)
  725. {
  726. void* data = nullptr;
  727. const int32_t dataSize = plugin->chunkData(&data);
  728. if (data != nullptr && dataSize >= 4)
  729. {
  730. chunkData.importBinaryAsBase64((const uint8_t*)data, static_cast<size_t>(dataSize));
  731. return (const char*)chunkData;
  732. }
  733. else
  734. carla_stderr2("carla_get_chunk_data(%i) - got invalid chunk data", pluginId);
  735. }
  736. else
  737. carla_stderr2("carla_get_chunk_data(%i) - plugin does not support chunks", pluginId);
  738. return nullptr;
  739. }
  740. carla_stderr2("carla_get_chunk_data(%i) - could not find plugin", pluginId);
  741. return nullptr;
  742. }
  743. // -------------------------------------------------------------------------------------------------------------------
  744. uint32_t carla_get_parameter_count(unsigned int pluginId)
  745. {
  746. carla_debug("carla_get_parameter_count(%i)", pluginId);
  747. CARLA_ASSERT(standalone.engine != nullptr);
  748. if (standalone.engine == nullptr)
  749. return 0;
  750. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  751. return plugin->parameterCount();
  752. carla_stderr2("carla_get_parameter_count(%i) - could not find plugin", pluginId);
  753. return 0;
  754. }
  755. uint32_t carla_get_program_count(unsigned int pluginId)
  756. {
  757. carla_debug("carla_get_program_count(%i)", pluginId);
  758. CARLA_ASSERT(standalone.engine != nullptr);
  759. if (standalone.engine == nullptr)
  760. return 0;
  761. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  762. return plugin->programCount();
  763. carla_stderr2("carla_get_program_count(%i) - could not find plugin", pluginId);
  764. return 0;
  765. }
  766. uint32_t carla_get_midi_program_count(unsigned int pluginId)
  767. {
  768. carla_debug("carla_get_midi_program_count(%i)", pluginId);
  769. CARLA_ASSERT(standalone.engine != nullptr);
  770. if (standalone.engine == nullptr)
  771. return 0;
  772. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  773. return plugin->midiProgramCount();
  774. carla_stderr2("carla_get_midi_program_count(%i) - could not find plugin", pluginId);
  775. return 0;
  776. }
  777. uint32_t carla_get_custom_data_count(unsigned int pluginId)
  778. {
  779. carla_debug("carla_get_custom_data_count(%i)", pluginId);
  780. CARLA_ASSERT(standalone.engine != nullptr);
  781. if (standalone.engine == nullptr)
  782. return 0;
  783. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  784. return plugin->customDataCount();
  785. carla_stderr2("carla_get_custom_data_count(%i) - could not find plugin", pluginId);
  786. return 0;
  787. }
  788. // -------------------------------------------------------------------------------------------------------------------
  789. const char* carla_get_parameter_text(unsigned int pluginId, uint32_t parameterId)
  790. {
  791. carla_debug("carla_get_parameter_text(%i, %i)", pluginId, parameterId);
  792. CARLA_ASSERT(standalone.engine != nullptr);
  793. if (standalone.engine == nullptr)
  794. return nullptr;
  795. static char textBuf[STR_MAX];
  796. carla_zeroMem(textBuf, sizeof(char)*STR_MAX);
  797. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  798. {
  799. if (parameterId < plugin->parameterCount())
  800. {
  801. plugin->getParameterText(parameterId, textBuf);
  802. return textBuf;
  803. }
  804. carla_stderr2("carla_get_parameter_text(%i, %i) - parameterId out of bounds", pluginId, parameterId);
  805. return nullptr;
  806. }
  807. carla_stderr2("carla_get_parameter_text(%i, %i) - could not find plugin", pluginId, parameterId);
  808. return nullptr;
  809. }
  810. const char* carla_get_program_name(unsigned int pluginId, uint32_t programId)
  811. {
  812. carla_debug("carla_get_program_name(%i, %i)", pluginId, programId);
  813. CARLA_ASSERT(standalone.engine != nullptr);
  814. if (standalone.engine == nullptr)
  815. return nullptr;
  816. static char programName[STR_MAX];
  817. carla_zeroMem(programName, sizeof(char)*STR_MAX);
  818. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  819. {
  820. if (programId < plugin->programCount())
  821. {
  822. plugin->getProgramName(programId, programName);
  823. return programName;
  824. }
  825. carla_stderr2("carla_get_program_name(%i, %i) - programId out of bounds", pluginId, programId);
  826. return nullptr;
  827. }
  828. carla_stderr2("carla_get_program_name(%i, %i) - could not find plugin", pluginId, programId);
  829. return nullptr;
  830. }
  831. const char* carla_get_midi_program_name(unsigned int pluginId, uint32_t midiProgramId)
  832. {
  833. carla_debug("carla_get_midi_program_name(%i, %i)", pluginId, midiProgramId);
  834. CARLA_ASSERT(standalone.engine != nullptr);
  835. if (standalone.engine == nullptr)
  836. return nullptr;
  837. static char midiProgramName[STR_MAX];
  838. carla_zeroMem(midiProgramName, sizeof(char)*STR_MAX);
  839. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  840. {
  841. if (midiProgramId < plugin->midiProgramCount())
  842. {
  843. plugin->getMidiProgramName(midiProgramId, midiProgramName);
  844. return midiProgramName;
  845. }
  846. carla_stderr2("carla_get_midi_program_name(%i, %i) - midiProgramId out of bounds", pluginId, midiProgramId);
  847. return nullptr;
  848. }
  849. carla_stderr2("carla_get_midi_program_name(%i, %i) - could not find plugin", pluginId, midiProgramId);
  850. return nullptr;
  851. }
  852. const char* carla_get_real_plugin_name(unsigned int pluginId)
  853. {
  854. carla_debug("carla_get_real_plugin_name(%i)", pluginId);
  855. CARLA_ASSERT(standalone.engine != nullptr);
  856. if (standalone.engine == nullptr)
  857. return nullptr;
  858. static char realPluginName[STR_MAX];
  859. carla_zeroMem(realPluginName, sizeof(char)*STR_MAX);
  860. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  861. {
  862. plugin->getRealName(realPluginName);
  863. return realPluginName;
  864. }
  865. carla_stderr2("carla_get_real_plugin_name(%i) - could not find plugin", pluginId);
  866. return nullptr;
  867. }
  868. // -------------------------------------------------------------------------------------------------------------------
  869. int32_t carla_get_current_program_index(unsigned int pluginId)
  870. {
  871. carla_debug("carla_get_current_program_index(%i)", pluginId);
  872. CARLA_ASSERT(standalone.engine != nullptr);
  873. if (standalone.engine == nullptr)
  874. return -1;
  875. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  876. return plugin->currentProgram();
  877. carla_stderr2("carla_get_current_program_index(%i) - could not find plugin", pluginId);
  878. return -1;
  879. }
  880. int32_t carla_get_current_midi_program_index(unsigned int pluginId)
  881. {
  882. carla_debug("carla_get_current_midi_program_index(%i)", pluginId);
  883. CARLA_ASSERT(standalone.engine != nullptr);
  884. if (standalone.engine == nullptr)
  885. return -1;
  886. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  887. return plugin->currentMidiProgram();
  888. carla_stderr2("carla_get_current_midi_program_index(%i) - could not find plugin", pluginId);
  889. return -1;
  890. }
  891. // -------------------------------------------------------------------------------------------------------------------
  892. float carla_get_default_parameter_value(unsigned int pluginId, uint32_t parameterId)
  893. {
  894. carla_debug("carla_get_default_parameter_value(%i, %i)", pluginId, parameterId);
  895. CARLA_ASSERT(standalone.engine != nullptr);
  896. if (standalone.engine == nullptr)
  897. return 0.0f;
  898. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  899. {
  900. if (parameterId < plugin->parameterCount())
  901. return plugin->parameterRanges(parameterId).def;
  902. carla_stderr2("carla_get_default_parameter_value(%i, %i) - parameterId out of bounds", pluginId, parameterId);
  903. return 0.0f;
  904. }
  905. carla_stderr2("carla_get_default_parameter_value(%i, %i) - could not find plugin", pluginId, parameterId);
  906. return 0.0f;
  907. }
  908. float carla_get_current_parameter_value(unsigned int pluginId, uint32_t parameterId)
  909. {
  910. carla_debug("carla_get_current_parameter_value(%i, %i)", pluginId, parameterId);
  911. CARLA_ASSERT(standalone.engine != nullptr);
  912. if (standalone.engine == nullptr)
  913. return 0.0f;
  914. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  915. {
  916. if (parameterId < plugin->parameterCount())
  917. return plugin->getParameterValue(parameterId);
  918. carla_stderr2("carla_get_current_parameter_value(%i, %i) - parameterId out of bounds", pluginId, parameterId);
  919. return 0.0f;
  920. }
  921. carla_stderr2("carla_get_current_parameter_value(%i, %i) - could not find plugin", pluginId, parameterId);
  922. return 0.0f;
  923. }
  924. // -------------------------------------------------------------------------------------------------------------------
  925. float carla_get_input_peak_value(unsigned int pluginId, unsigned short portId)
  926. {
  927. CARLA_ASSERT(standalone.engine != nullptr);
  928. CARLA_ASSERT(portId == 1 || portId == 2);
  929. if (standalone.engine == nullptr)
  930. return 0.0f;
  931. if (pluginId >= standalone.engine->currentPluginCount())
  932. {
  933. carla_stderr2("carla_get_input_peak_value(%i, %i) - invalid plugin value", pluginId, portId);
  934. return 0.0f;
  935. }
  936. if (portId == 1 || portId == 2)
  937. return standalone.engine->getInputPeak(pluginId, portId);
  938. carla_stderr2("carla_get_input_peak_value(%i, %i) - invalid port value", pluginId, portId);
  939. return 0.0f;
  940. }
  941. float carla_get_output_peak_value(unsigned int pluginId, unsigned short portId)
  942. {
  943. CARLA_ASSERT(standalone.engine != nullptr);
  944. CARLA_ASSERT(portId == 1 || portId == 2);
  945. if (standalone.engine == nullptr)
  946. return 0.0f;
  947. if (pluginId >= standalone.engine->currentPluginCount())
  948. {
  949. carla_stderr2("carla_get_input_peak_value(%i, %i) - invalid plugin value", pluginId, portId);
  950. return 0.0f;
  951. }
  952. if (portId == 1 || portId == 2)
  953. return standalone.engine->getOutputPeak(pluginId, portId);
  954. carla_stderr2("carla_get_output_peak_value(%i, %i) - invalid port value", pluginId, portId);
  955. return 0.0f;
  956. }
  957. // -------------------------------------------------------------------------------------------------------------------
  958. void carla_set_option(unsigned int pluginId, unsigned int option, bool yesNo)
  959. {
  960. carla_debug("carla_set_option(%i, %i, %s)", pluginId, option, bool2str(yesNo));
  961. CARLA_ASSERT(standalone.engine != nullptr);
  962. if (standalone.engine == nullptr)
  963. return;
  964. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  965. return plugin->setOption(option, yesNo);
  966. carla_stderr2("carla_set_option(%i, %i, %s) - could not find plugin", pluginId, option, bool2str(yesNo));
  967. }
  968. void carla_set_active(unsigned int pluginId, bool onOff)
  969. {
  970. carla_debug("carla_set_active(%i, %s)", pluginId, bool2str(onOff));
  971. CARLA_ASSERT(standalone.engine != nullptr);
  972. if (standalone.engine == nullptr)
  973. return;
  974. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  975. return plugin->setActive(onOff, true, false);
  976. carla_stderr2("carla_set_active(%i, %s) - could not find plugin", pluginId, bool2str(onOff));
  977. }
  978. void carla_set_drywet(unsigned int pluginId, float value)
  979. {
  980. carla_debug("carla_set_drywet(%i, %f)", pluginId, value);
  981. CARLA_ASSERT(standalone.engine != nullptr);
  982. if (standalone.engine == nullptr)
  983. return;
  984. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  985. return plugin->setDryWet(value, true, false);
  986. carla_stderr2("carla_set_drywet(%i, %f) - could not find plugin", pluginId, value);
  987. }
  988. void carla_set_volume(unsigned int pluginId, float value)
  989. {
  990. carla_debug("carla_set_volume(%i, %f)", pluginId, value);
  991. CARLA_ASSERT(standalone.engine != nullptr);
  992. if (standalone.engine == nullptr)
  993. return;
  994. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  995. return plugin->setVolume(value, true, false);
  996. carla_stderr2("carla_set_volume(%i, %f) - could not find plugin", pluginId, value);
  997. }
  998. void carla_set_balance_left(unsigned int pluginId, float value)
  999. {
  1000. carla_debug("carla_set_balance_left(%i, %f)", pluginId, value);
  1001. CARLA_ASSERT(standalone.engine != nullptr);
  1002. if (standalone.engine == nullptr)
  1003. return;
  1004. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1005. return plugin->setBalanceLeft(value, true, false);
  1006. carla_stderr2("carla_set_balance_left(%i, %f) - could not find plugin", pluginId, value);
  1007. }
  1008. void carla_set_balance_right(unsigned int pluginId, float value)
  1009. {
  1010. carla_debug("carla_set_balance_right(%i, %f)", pluginId, value);
  1011. CARLA_ASSERT(standalone.engine != nullptr);
  1012. if (standalone.engine == nullptr)
  1013. return;
  1014. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1015. return plugin->setBalanceRight(value, true, false);
  1016. carla_stderr2("carla_set_balance_right(%i, %f) - could not find plugin", pluginId, value);
  1017. }
  1018. void carla_set_panning(unsigned int pluginId, float value)
  1019. {
  1020. carla_debug("carla_set_panning(%i, %f)", pluginId, value);
  1021. CARLA_ASSERT(standalone.engine != nullptr);
  1022. if (standalone.engine == nullptr)
  1023. return;
  1024. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1025. return plugin->setPanning(value, true, false);
  1026. carla_stderr2("carla_set_panning(%i, %f) - could not find plugin", pluginId, value);
  1027. }
  1028. void carla_set_ctrl_channel(unsigned int pluginId, int8_t channel)
  1029. {
  1030. carla_debug("carla_set_ctrl_channel(%i, %i)", pluginId, channel);
  1031. CARLA_ASSERT(standalone.engine != nullptr);
  1032. if (standalone.engine == nullptr)
  1033. return;
  1034. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1035. return plugin->setCtrlChannel(channel, true, false);
  1036. carla_stderr2("carla_set_ctrl_channel(%i, %i) - could not find plugin", pluginId, channel);
  1037. }
  1038. // -------------------------------------------------------------------------------------------------------------------
  1039. void carla_set_parameter_value(unsigned int pluginId, uint32_t parameterId, float value)
  1040. {
  1041. carla_debug("carla_set_parameter_value(%i, %i, %f)", pluginId, parameterId, value);
  1042. CARLA_ASSERT(standalone.engine != nullptr);
  1043. if (standalone.engine == nullptr)
  1044. return;
  1045. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1046. {
  1047. if (parameterId < plugin->parameterCount())
  1048. return plugin->setParameterValue(parameterId, value, true, true, false);
  1049. carla_stderr2("carla_set_parameter_value(%i, %i, %f) - parameterId out of bounds", pluginId, parameterId, value);
  1050. return;
  1051. }
  1052. carla_stderr2("carla_set_parameter_value(%i, %i, %f) - could not find plugin", pluginId, parameterId, value);
  1053. }
  1054. void carla_set_parameter_midi_channel(unsigned int pluginId, uint32_t parameterId, uint8_t channel)
  1055. {
  1056. carla_debug("carla_set_parameter_midi_channel(%i, %i, %i)", pluginId, parameterId, channel);
  1057. CARLA_ASSERT(standalone.engine != nullptr);
  1058. CARLA_ASSERT(channel < MAX_MIDI_CHANNELS);
  1059. if (channel >= MAX_MIDI_CHANNELS)
  1060. {
  1061. carla_stderr2("carla_set_parameter_midi_channel(%i, %i, %i) - invalid channel number", pluginId, parameterId, channel);
  1062. return;
  1063. }
  1064. if (standalone.engine == nullptr)
  1065. return;
  1066. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1067. {
  1068. if (parameterId < plugin->parameterCount())
  1069. return plugin->setParameterMidiChannel(parameterId, channel, true, false);
  1070. carla_stderr2("carla_set_parameter_midi_channel(%i, %i, %i) - parameterId out of bounds", pluginId, parameterId, channel);
  1071. return;
  1072. }
  1073. carla_stderr2("carla_set_parameter_midi_channel(%i, %i, %i) - could not find plugin", pluginId, parameterId, channel);
  1074. }
  1075. void carla_set_parameter_midi_cc(unsigned int pluginId, uint32_t parameterId, int16_t cc)
  1076. {
  1077. carla_debug("carla_set_parameter_midi_cc(%i, %i, %i)", pluginId, parameterId, cc);
  1078. CARLA_ASSERT(standalone.engine != nullptr);
  1079. CARLA_ASSERT(cc >= -1 && cc <= 0x5F);
  1080. if (cc < -1)
  1081. {
  1082. cc = -1;
  1083. }
  1084. else if (cc > 0x5F) // 95
  1085. {
  1086. carla_stderr2("carla_set_parameter_midi_cc(%i, %i, %i) - invalid cc number", pluginId, parameterId, cc);
  1087. return;
  1088. }
  1089. if (standalone.engine == nullptr)
  1090. return;
  1091. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1092. {
  1093. if (parameterId < plugin->parameterCount())
  1094. return plugin->setParameterMidiCC(parameterId, cc, true, false);
  1095. carla_stderr2("carla_set_parameter_midi_cc(%i, %i, %i) - parameterId out of bounds", pluginId, parameterId, cc);
  1096. return;
  1097. }
  1098. carla_stderr2("carla_set_parameter_midi_cc(%i, %i, %i) - could not find plugin", pluginId, parameterId, cc);
  1099. }
  1100. void carla_set_program(unsigned int pluginId, uint32_t programId)
  1101. {
  1102. carla_debug("carla_set_program(%i, %i)", pluginId, programId);
  1103. CARLA_ASSERT(standalone.engine != nullptr);
  1104. if (standalone.engine == nullptr)
  1105. return;
  1106. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1107. {
  1108. if (programId < plugin->programCount())
  1109. return plugin->setProgram(static_cast<int32_t>(programId), true, true, false);
  1110. carla_stderr2("carla_set_program(%i, %i) - programId out of bounds", pluginId, programId);
  1111. return;
  1112. }
  1113. carla_stderr2("carla_set_program(%i, %i) - could not find plugin", pluginId, programId);
  1114. }
  1115. void carla_set_midi_program(unsigned int pluginId, uint32_t midiProgramId)
  1116. {
  1117. carla_debug("carla_set_midi_program(%i, %i)", pluginId, midiProgramId);
  1118. CARLA_ASSERT(standalone.engine != nullptr);
  1119. if (standalone.engine == nullptr)
  1120. return;
  1121. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1122. {
  1123. if (midiProgramId < plugin->midiProgramCount())
  1124. return plugin->setMidiProgram(static_cast<int32_t>(midiProgramId), true, true, false);
  1125. carla_stderr2("carla_set_midi_program(%i, %i) - midiProgramId out of bounds", pluginId, midiProgramId);
  1126. return;
  1127. }
  1128. carla_stderr2("carla_set_midi_program(%i, %i) - could not find plugin", pluginId, midiProgramId);
  1129. }
  1130. // -------------------------------------------------------------------------------------------------------------------
  1131. void carla_set_custom_data(unsigned int pluginId, const char* type, const char* key, const char* value)
  1132. {
  1133. carla_debug("carla_set_custom_data(%i, \"%s\", \"%s\", \"%s\")", pluginId, type, key, value);
  1134. CARLA_ASSERT(standalone.engine != nullptr);
  1135. if (standalone.engine == nullptr)
  1136. return;
  1137. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1138. return plugin->setCustomData(type, key, value, true);
  1139. carla_stderr2("carla_set_custom_data(%i, \"%s\", \"%s\", \"%s\") - could not find plugin", pluginId, type, key, value);
  1140. }
  1141. void carla_set_chunk_data(unsigned int pluginId, const char* chunkData)
  1142. {
  1143. carla_debug("carla_set_chunk_data(%i, \"%s\")", pluginId, chunkData);
  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 (plugin->options() & CarlaBackend::PLUGIN_OPTION_USE_CHUNKS)
  1150. return plugin->setChunkData(chunkData);
  1151. carla_stderr2("carla_set_chunk_data(%i, \"%s\") - plugin does not support chunks", pluginId, chunkData);
  1152. return;
  1153. }
  1154. carla_stderr2("carla_set_chunk_data(%i, \"%s\") - could not find plugin", pluginId, chunkData);
  1155. }
  1156. // -------------------------------------------------------------------------------------------------------------------
  1157. void carla_prepare_for_save(unsigned int pluginId)
  1158. {
  1159. carla_debug("carla_prepare_for_save(%i)", pluginId);
  1160. CARLA_ASSERT(standalone.engine != nullptr);
  1161. if (standalone.engine == nullptr)
  1162. return;
  1163. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1164. return plugin->prepareForSave();
  1165. carla_stderr2("carla_prepare_for_save(%i) - could not find plugin", pluginId);
  1166. }
  1167. void carla_send_midi_note(unsigned int pluginId, uint8_t channel, uint8_t note, uint8_t velocity)
  1168. {
  1169. carla_debug("carla_send_midi_note(%i, %i, %i, %i)", pluginId, channel, note, velocity);
  1170. CARLA_ASSERT(standalone.engine != nullptr);
  1171. if (standalone.engine == nullptr || ! standalone.engine->isRunning())
  1172. return;
  1173. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1174. return plugin->sendMidiSingleNote(channel, note, velocity, true, true, false);
  1175. carla_stderr2("carla_send_midi_note(%i, %i, %i, %i) - could not find plugin", pluginId, channel, note, velocity);
  1176. }
  1177. void carla_show_gui(unsigned int pluginId, bool yesno)
  1178. {
  1179. carla_debug("carla_show_gui(%i, %s)", pluginId, bool2str(yesno));
  1180. CARLA_ASSERT(standalone.engine != nullptr);
  1181. if (standalone.engine == nullptr)
  1182. return;
  1183. if (CarlaPlugin* const plugin = standalone.engine->getPlugin(pluginId))
  1184. return plugin->showGui(yesno);
  1185. carla_stderr2("carla_show_gui(%i, %s) - could not find plugin", pluginId, bool2str(yesno));
  1186. }
  1187. // -------------------------------------------------------------------------------------------------------------------
  1188. uint32_t carla_get_buffer_size()
  1189. {
  1190. carla_debug("carla_get_buffer_size()");
  1191. CARLA_ASSERT(standalone.engine != nullptr);
  1192. if (standalone.engine == nullptr)
  1193. return 0;
  1194. return standalone.engine->getBufferSize();
  1195. }
  1196. double carla_get_sample_rate()
  1197. {
  1198. carla_debug("carla_get_sample_rate()");
  1199. CARLA_ASSERT(standalone.engine != nullptr);
  1200. if (standalone.engine == nullptr)
  1201. return 0.0;
  1202. return standalone.engine->getSampleRate();
  1203. }
  1204. // -------------------------------------------------------------------------------------------------------------------
  1205. const char* carla_get_last_error()
  1206. {
  1207. carla_debug("carla_get_last_error()");
  1208. if (standalone.engine != nullptr)
  1209. return standalone.engine->getLastError();
  1210. return standalone.lastError;
  1211. }
  1212. const char* carla_get_host_osc_url()
  1213. {
  1214. carla_debug("carla_get_host_osc_url()");
  1215. CARLA_ASSERT(standalone.engine != nullptr);
  1216. if (standalone.engine == nullptr)
  1217. return nullptr;
  1218. return standalone.engine->getOscServerPathTCP();
  1219. }
  1220. #if 0
  1221. // -------------------------------------------------------------------------------------------------------------------
  1222. #define NSM_API_VERSION_MAJOR 1
  1223. #define NSM_API_VERSION_MINOR 0
  1224. class CarlaNSM
  1225. {
  1226. public:
  1227. CarlaNSM()
  1228. {
  1229. m_controlAddr = nullptr;
  1230. m_serverThread = nullptr;
  1231. m_isOpened = false;
  1232. m_isSaved = false;
  1233. }
  1234. ~CarlaNSM()
  1235. {
  1236. if (m_controlAddr)
  1237. lo_address_free(m_controlAddr);
  1238. if (m_serverThread)
  1239. {
  1240. lo_server_thread_stop(m_serverThread);
  1241. lo_server_thread_del_method(m_serverThread, "/reply", "ssss");
  1242. lo_server_thread_del_method(m_serverThread, "/nsm/client/open", "sss");
  1243. lo_server_thread_del_method(m_serverThread, "/nsm/client/save", "");
  1244. lo_server_thread_free(m_serverThread);
  1245. }
  1246. }
  1247. void announce(const char* const url, const int pid)
  1248. {
  1249. lo_address addr = lo_address_new_from_url(url);
  1250. int proto = lo_address_get_protocol(addr);
  1251. if (! m_serverThread)
  1252. {
  1253. // create new OSC thread
  1254. m_serverThread = lo_server_thread_new_with_proto(nullptr, proto, error_handler);
  1255. // register message handlers and start OSC thread
  1256. lo_server_thread_add_method(m_serverThread, "/reply", "ssss", _reply_handler, this);
  1257. lo_server_thread_add_method(m_serverThread, "/nsm/client/open", "sss", _nsm_open_handler, this);
  1258. lo_server_thread_add_method(m_serverThread, "/nsm/client/save", "", _nsm_save_handler, this);
  1259. lo_server_thread_start(m_serverThread);
  1260. }
  1261. lo_send_from(addr, lo_server_thread_get_server(m_serverThread), LO_TT_IMMEDIATE, "/nsm/server/announce", "sssiii",
  1262. "Carla", ":switch:", "carla", NSM_API_VERSION_MAJOR, NSM_API_VERSION_MINOR, pid);
  1263. lo_address_free(addr);
  1264. }
  1265. void replyOpen()
  1266. {
  1267. m_isOpened = true;
  1268. }
  1269. void replySave()
  1270. {
  1271. m_isSaved = true;
  1272. }
  1273. protected:
  1274. int reply_handler(const char* const path, const char* const types, lo_arg** const argv, const int argc, const lo_message msg)
  1275. {
  1276. carla_debug("CarlaNSM::reply_handler(%s, %i, %p, %s, %p)", path, argc, argv, types, msg);
  1277. m_controlAddr = lo_address_new_from_url(lo_address_get_url(lo_message_get_source(msg)));
  1278. const char* const method = &argv[0]->s;
  1279. if (std::strcmp(method, "/nsm/server/announce") == 0 && standalone.callback)
  1280. standalone.callback(nullptr, CarlaBackend::CALLBACK_NSM_ANNOUNCE, 0, 0, 0, 0.0, nullptr); // FIXME?
  1281. return 0;
  1282. }
  1283. int nsm_open_handler(const char* const path, const char* const types, lo_arg** const argv, const int argc, const lo_message msg)
  1284. {
  1285. carla_debug("CarlaNSM::nsm_open_handler(\"%s\", \"%s\", %p, %i, %p)", path, types, argv, argc, msg);
  1286. if (! standalone.callback)
  1287. return 1;
  1288. const char* const projectPath = &argv[0]->s;
  1289. const char* const clientId = &argv[2]->s;
  1290. standalone.callback(nullptr, CarlaBackend::CALLBACK_NSM_OPEN1, 0, 0, 0, 0.0, clientId);
  1291. standalone.callback(nullptr, CarlaBackend::CALLBACK_NSM_OPEN2, 0, 0, 0, 0.0, projectPath);
  1292. for (int i=0; i < 30 && ! m_isOpened; i++)
  1293. carla_msleep(100);
  1294. if (m_controlAddr)
  1295. lo_send_from(m_controlAddr, lo_server_thread_get_server(m_serverThread), LO_TT_IMMEDIATE, "/reply", "ss", "/nsm/client/open", "OK");
  1296. return 0;
  1297. }
  1298. int nsm_save_handler(const char* const path, const char* const types, lo_arg** const argv, const int argc, const lo_message msg)
  1299. {
  1300. carla_debug("CarlaNSM::nsm_save_handler(\"%s\", \"%s\", %p, %i, %p)", path, types, argv, argc, msg);
  1301. if (! standalone.callback)
  1302. return 1;
  1303. standalone.callback(nullptr, CarlaBackend::CALLBACK_NSM_SAVE, 0, 0, 0, 0.0, nullptr);
  1304. for (int i=0; i < 30 && ! m_isSaved; i++)
  1305. carla_msleep(100);
  1306. if (m_controlAddr)
  1307. lo_send_from(m_controlAddr, lo_server_thread_get_server(m_serverThread), LO_TT_IMMEDIATE, "/reply", "ss", "/nsm/client/save", "OK");
  1308. return 0;
  1309. }
  1310. private:
  1311. lo_address m_controlAddr;
  1312. lo_server_thread m_serverThread;
  1313. bool m_isOpened, m_isSaved;
  1314. 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)
  1315. {
  1316. CARLA_ASSERT(data);
  1317. CarlaNSM* const _this_ = (CarlaNSM*)data;
  1318. return _this_->reply_handler(path, types, argv, argc, msg);
  1319. }
  1320. 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)
  1321. {
  1322. CARLA_ASSERT(data);
  1323. CarlaNSM* const _this_ = (CarlaNSM*)data;
  1324. return _this_->nsm_open_handler(path, types, argv, argc, msg);
  1325. }
  1326. 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)
  1327. {
  1328. CARLA_ASSERT(data);
  1329. CarlaNSM* const _this_ = (CarlaNSM*)data;
  1330. return _this_->nsm_save_handler(path, types, argv, argc, msg);
  1331. }
  1332. static void error_handler(const int num, const char* const msg, const char* const path)
  1333. {
  1334. carla_stderr2("CarlaNSM::error_handler(%i, \"%s\", \"%s\")", num, msg, path);
  1335. }
  1336. };
  1337. static CarlaNSM carlaNSM;
  1338. void carla_nsm_announce(const char* url, int pid)
  1339. {
  1340. carlaNSM.announce(url, pid);
  1341. }
  1342. void carla_nsm_reply_open()
  1343. {
  1344. carlaNSM.replyOpen();
  1345. }
  1346. void carla_nsm_reply_save()
  1347. {
  1348. carlaNSM.replySave();
  1349. }
  1350. #endif
  1351. // -------------------------------------------------------------------------------------------------------------------
  1352. #if 0
  1353. //def QTCREATOR_TEST
  1354. #include <QtGui/QApplication>
  1355. #include <QtGui/QDialog>
  1356. QDialog* vstGui = nullptr;
  1357. void main_callback(void* ptr, CarlaBackend::CallbackType action, unsigned int pluginId, int value1, int value2, double value3)
  1358. {
  1359. switch (action)
  1360. {
  1361. case CarlaBackend::CALLBACK_SHOW_GUI:
  1362. if (vstGui && ! value1)
  1363. vstGui->close();
  1364. break;
  1365. case CarlaBackend::CALLBACK_RESIZE_GUI:
  1366. vstGui->setFixedSize(value1, value2);
  1367. break;
  1368. default:
  1369. break;
  1370. }
  1371. Q_UNUSED(ptr);
  1372. Q_UNUSED(pluginId);
  1373. Q_UNUSED(value3);
  1374. }
  1375. void run_tests_standalone(short idMax)
  1376. {
  1377. for (short id = 0; id <= idMax; id++)
  1378. {
  1379. carla_debug("------------------- TEST @%i: non-parameter calls --------------------", id);
  1380. get_plugin_info(id);
  1381. get_audio_port_count_info(id);
  1382. get_midi_port_count_info(id);
  1383. get_parameter_count_info(id);
  1384. get_gui_info(id);
  1385. get_chunk_data(id);
  1386. get_parameter_count(id);
  1387. get_program_count(id);
  1388. get_midi_program_count(id);
  1389. get_custom_data_count(id);
  1390. get_real_plugin_name(id);
  1391. get_current_program_index(id);
  1392. get_current_midi_program_index(id);
  1393. carla_debug("------------------- TEST @%i: parameter calls [-1] --------------------", id);
  1394. get_parameter_info(id, -1);
  1395. get_parameter_scalepoint_info(id, -1, -1);
  1396. get_parameter_data(id, -1);
  1397. get_parameter_ranges(id, -1);
  1398. get_midi_program_data(id, -1);
  1399. get_custom_data(id, -1);
  1400. get_parameter_text(id, -1);
  1401. get_program_name(id, -1);
  1402. get_midi_program_name(id, -1);
  1403. get_default_parameter_value(id, -1);
  1404. get_current_parameter_value(id, -1);
  1405. get_input_peak_value(id, -1);
  1406. get_output_peak_value(id, -1);
  1407. carla_debug("------------------- TEST @%i: parameter calls [0] --------------------", id);
  1408. get_parameter_info(id, 0);
  1409. get_parameter_scalepoint_info(id, 0, -1);
  1410. get_parameter_scalepoint_info(id, 0, 0);
  1411. get_parameter_data(id, 0);
  1412. get_parameter_ranges(id, 0);
  1413. get_midi_program_data(id, 0);
  1414. get_custom_data(id, 0);
  1415. get_parameter_text(id, 0);
  1416. get_program_name(id, 0);
  1417. get_midi_program_name(id, 0);
  1418. get_default_parameter_value(id, 0);
  1419. get_current_parameter_value(id, 0);
  1420. get_input_peak_value(id, 0);
  1421. get_input_peak_value(id, 1);
  1422. get_input_peak_value(id, 2);
  1423. get_output_peak_value(id, 0);
  1424. get_output_peak_value(id, 1);
  1425. get_output_peak_value(id, 2);
  1426. carla_debug("------------------- TEST @%i: set extra data --------------------", id);
  1427. set_custom_data(id, CarlaBackend::CUSTOM_DATA_STRING, "", "");
  1428. set_chunk_data(id, nullptr);
  1429. set_gui_container(id, (uintptr_t)1);
  1430. carla_debug("------------------- TEST @%i: gui stuff --------------------", id);
  1431. show_gui(id, false);
  1432. show_gui(id, true);
  1433. show_gui(id, true);
  1434. idle_guis();
  1435. idle_guis();
  1436. idle_guis();
  1437. carla_debug("------------------- TEST @%i: other --------------------", id);
  1438. send_midi_note(id, 15, 127, 127);
  1439. send_midi_note(id, 0, 0, 0);
  1440. prepare_for_save(id);
  1441. prepare_for_save(id);
  1442. prepare_for_save(id);
  1443. }
  1444. }
  1445. int main(int argc, char* argv[])
  1446. {
  1447. using namespace CarlaBackend;
  1448. // Qt app
  1449. QApplication app(argc, argv);
  1450. // Qt gui (for vst)
  1451. vstGui = new QDialog(nullptr);
  1452. // set callback and options
  1453. set_callback_function(main_callback);
  1454. set_option(OPTION_PREFER_UI_BRIDGES, 0, nullptr);
  1455. //set_option(OPTION_PROCESS_MODE, PROCESS_MODE_CONTINUOUS_RACK, nullptr);
  1456. // start engine
  1457. if (! engine_init("JACK", "carla_demo"))
  1458. {
  1459. carla_stderr2("failed to start backend engine, reason:\n%s", get_last_error());
  1460. delete vstGui;
  1461. return 1;
  1462. }
  1463. short id_ladspa = add_plugin(BINARY_NATIVE, PLUGIN_LADSPA, "/usr/lib/ladspa/LEET_eqbw2x2.so", "LADSPA plug name, test long name - "
  1464. "------- name ------------ name2 ----------- name3 ------------ name4 ------------ name5 ---------- name6", "leet_equalizer_bw2x2", nullptr);
  1465. 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");
  1466. short id_native = add_plugin(BINARY_NATIVE, PLUGIN_INTERNAL, "", "ZynHere", "zynaddsubfx", nullptr);
  1467. //short id_lv2 = add_plugin(BINARY_NATIVE, PLUGIN_LV2, "FILENAME", "HAHA name!!!", "http://studionumbersix.com/foo/lv2/yc20", nullptr);
  1468. //short id_vst = add_plugin(BINARY_NATIVE, PLUGIN_LV2, "FILENAME", "HAHA name!!!", "http://studionumbersix.com/foo/lv2/yc20", nullptr);
  1469. if (id_ladspa < 0 || id_dssi < 0 || id_native < 0)
  1470. {
  1471. carla_stderr2("failed to start load plugins, reason:\n%s", get_last_error());
  1472. delete vstGui;
  1473. return 1;
  1474. }
  1475. //const GuiInfo* const guiInfo = get_gui_info(id);
  1476. //if (guiInfo->type == CarlaBackend::GUI_INTERNAL_QT4 || guiInfo->type == CarlaBackend::GUI_INTERNAL_X11)
  1477. //{
  1478. // set_gui_data(id, 0, (uintptr_t)gui);
  1479. //gui->show();
  1480. //}
  1481. // activate
  1482. set_active(id_ladspa, true);
  1483. set_active(id_dssi, true);
  1484. set_active(id_native, true);
  1485. // start guis
  1486. show_gui(id_dssi, true);
  1487. carla_sleep(1);
  1488. // do tests
  1489. run_tests_standalone(id_dssi+1);
  1490. // lock
  1491. app.exec();
  1492. delete vstGui;
  1493. vstGui = nullptr;
  1494. remove_plugin(id_ladspa);
  1495. remove_plugin(id_dssi);
  1496. remove_plugin(id_native);
  1497. engine_close();
  1498. return 0;
  1499. }
  1500. #endif