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.

1859 lines
61KB

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