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.

1850 lines
60KB

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